[rhel7-branch 1/1] More descriptive message on invalid username
by dashea
From: Karel Valek <kvalek(a)redhat.com>
Also checks against directory names in root (/) dir and
Checks against invalid chars as well as digits on start
Resolves: rhbz#1259284
Signed-off-by: Karel Valek <kvalek(a)redhat.com>
---
pyanaconda/ui/tui/spokes/__init__.py | 16 ++++++++--------
pyanaconda/users.py | 17 +++++++++++++++++
2 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/pyanaconda/ui/tui/spokes/__init__.py b/pyanaconda/ui/tui/spokes/__init__.py
index 61f4486..e6baf31 100644
--- a/pyanaconda/ui/tui/spokes/__init__.py
+++ b/pyanaconda/ui/tui/spokes/__init__.py
@@ -21,7 +21,7 @@
from pyanaconda.ui.tui import simpleline as tui
from pyanaconda.ui.tui.tuiobject import TUIObject, YesNoDialog
from pyanaconda.ui.common import Spoke, StandaloneSpoke, NormalSpoke
-from pyanaconda.users import validatePassword, cryptPassword
+from pyanaconda.users import validatePassword, cryptPassword, check_name
import re
from collections import namedtuple
from pyanaconda.iutil import setdeepattr, getdeepattr
@@ -98,11 +98,7 @@ class NormalTUISpoke(TUISpoke, NormalSpoke):
# Inherit abstract methods from NormalTUISpoke
# pylint: disable=abstract-method
class EditTUIDialog(NormalTUISpoke):
- """Spoke/dialog used to read new value of textual or password data
-
- To override the wrong input message set the wrong_input_message attribute
- to a translated string.
- """
+ """Spoke/dialog used to read new value of textual or password data"""
title = N_("New value")
PASSWORD = re.compile(".*")
@@ -184,17 +180,21 @@ def prompt(self, entry = None):
return _("Enter new value for '%s' and press enter\n") % entry.title
def input(self, entry, key):
- if entry.aux.match(key):
+ valid, err_msg = check_name(key)
+ if entry.aux.match(key) and valid:
self.value = key
self.close()
return True
else:
+ self.wrong_input_message = err_msg
if self.wrong_input_message:
print(self.wrong_input_message)
else:
- print(_("You have provided an invalid value\n"))
+ print(_("You have provided an invalid user name: %s\n"
+ "Tip: Keep your user name shorter than 32 characters and do not use spaces.\n") % key)
return NormalTUISpoke.input(self, entry, key)
+
class OneShotEditTUIDialog(EditTUIDialog):
"""The same as EditTUIDialog, but closes automatically after
the value is read
diff --git a/pyanaconda/users.py b/pyanaconda/users.py
index f53e705..731bcd3 100644
--- a/pyanaconda/users.py
+++ b/pyanaconda/users.py
@@ -27,7 +27,9 @@
import pwquality
from pyanaconda.iutil import strip_accents
from pyanaconda.constants import PASSWORD_MIN_LEN
+
from pyanaconda.errors import errorHandler, PasswordCryptError, ERROR_RAISE
+import re
import logging
log = logging.getLogger("anaconda")
@@ -166,6 +168,21 @@ def validatePassword(pw, user="root", settings=None, minlen=None):
return (valid, strength, message)
+def check_name(in_name):
+ ign_cond = {r"^[\d]": "User name cannot start with a digit: ",
+ r"[^A-Za-z0-9\s]": "User name cannot contain any non-alphanumerical character: "}
+
+ for sys_name in os.listdir("/") + ["root", "home", "daemon", "system"]:
+ if in_name in sys_name:
+ return (False, "Username is reserved for system: %s" % sys_name)
+
+ for cond in ign_cond:
+ match = re.search(cond, in_name)
+ if match:
+ return (False, ign_cond[cond] + "'%s'" % match.group())
+
+ return (True, None)
+
def guess_username(fullname):
fullname = fullname.split()
--
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/e1bf4e3270b3e32aaeeb8bc696...
7 years, 11 months
[rhel7-branch 2/2] Only try to restart payload in the Anaconda
environment
by dashea
From: Martin Kolman <mkolman(a)redhat.com>
Outside of the Anaconda environment, such as in Initial setup,
there might be no payload to restart. This might lead to a crash
and/or confusing error messages in logs.
Related: rhbz#1270354
---
pyanaconda/ui/gui/spokes/network.py | 11 +++++++----
pyanaconda/ui/tui/spokes/network.py | 10 ++++++----
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/pyanaconda/ui/gui/spokes/network.py b/pyanaconda/ui/gui/spokes/network.py
index 052a375..893cb36 100644
--- a/pyanaconda/ui/gui/spokes/network.py
+++ b/pyanaconda/ui/gui/spokes/network.py
@@ -1497,10 +1497,13 @@ def apply(self):
log.debug("network: apply ksdata %s", self.data.network)
if self.networking_changed:
- log.debug("network spoke (apply) refresh payload")
- from pyanaconda.packaging import payloadMgr
- payloadMgr.restartThread(self.storage, self.data, self.payload, self.instclass,
- fallback=not anaconda_flags.automatedInstall)
+ if ANACONDA_ENVIRON in anaconda_flags.environs:
+ log.debug("network spoke (apply) refresh payload")
+ from pyanaconda.packaging import payloadMgr
+ payloadMgr.restartThread(self.storage, self.data, self.payload, self.instclass,
+ fallback=not anaconda_flags.automatedInstall)
+ else:
+ log.debug("network spoke (apply), payload refresh skipped (running outside of installation environment)")
self.networking_changed = False
else:
log.debug("network spoke (apply), no changes detected")
diff --git a/pyanaconda/ui/tui/spokes/network.py b/pyanaconda/ui/tui/spokes/network.py
index 6d0ac65..bdd4ff0 100644
--- a/pyanaconda/ui/tui/spokes/network.py
+++ b/pyanaconda/ui/tui/spokes/network.py
@@ -21,7 +21,7 @@
#
-from pyanaconda.flags import can_touch_runtime_system
+from pyanaconda.flags import can_touch_runtime_system, flags
from pyanaconda.ui.categories.system import SystemCategory
from pyanaconda.ui.tui.spokes import EditTUISpoke, OneShotEditTUIDialog
from pyanaconda.ui.tui.spokes import EditTUISpokeEntry as Entry
@@ -33,6 +33,7 @@
from pyanaconda.regexes import IPV4_PATTERN_WITHOUT_ANCHORS, IPV4_NETMASK_WITHOUT_ANCHORS
from pyanaconda.constants_text import INPUT_PROCESSED
+from pyanaconda.constants import ANACONDA_ENVIRON
import logging
log = logging.getLogger("anaconda")
@@ -244,9 +245,10 @@ def apply(self):
if self._apply:
self._apply = False
- from pyanaconda.packaging import payloadMgr
- payloadMgr.restartThread(self.storage, self.data, self.payload,
- self.instclass, checkmount=False)
+ if ANACONDA_ENVIRON in flags.environs:
+ from pyanaconda.packaging import payloadMgr
+ payloadMgr.restartThread(self.storage, self.data, self.payload,
+ self.instclass, checkmount=False)
def _update_network_data(self):
hostname = self.data.network.hostname
--
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/b0d7b3b29149ceb07fac6fa2f3...
7 years, 11 months
[rhel7-branch 1/2] Make current runtime environment identifiers
available via
flags
by dashea
From: Martin Kolman <mkolman(a)redhat.com>
This makes the identifier easily accessible to Anaconda & addons
in case they want to change their behavior based on the current
runtime environment.
Related: rhbz#1270354
---
pyanaconda/flags.py | 4 +++-
pyanaconda/ui/common.py | 3 ---
pyanaconda/ui/gui/hubs/__init__.py | 2 +-
3 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/pyanaconda/flags.py b/pyanaconda/flags.py
index d647239..8a97f95 100644
--- a/pyanaconda/flags.py
+++ b/pyanaconda/flags.py
@@ -20,7 +20,7 @@
import selinux
import shlex
import glob
-from pyanaconda.constants import SELINUX_DEFAULT, CMDLINE_APPEND
+from pyanaconda.constants import SELINUX_DEFAULT, CMDLINE_APPEND, ANACONDA_ENVIRON
from collections import OrderedDict
import logging
@@ -76,6 +76,8 @@ def __init__(self, read_cmdline=True):
self.nosave_logs = False
# single language options
self.singlelang = False
+ # current runtime environments
+ self.environs = [ANACONDA_ENVIRON]
# parse the boot commandline
self.cmdline = BootArgs()
# Lock it down: no more creating new flags!
diff --git a/pyanaconda/ui/common.py b/pyanaconda/ui/common.py
index e4f994e..39e7bb3 100644
--- a/pyanaconda/ui/common.py
+++ b/pyanaconda/ui/common.py
@@ -495,9 +495,6 @@ def __init__(self, storage, payload, instclass):
self.paths = {}
self._spokes = {}
- # spokes for which environments this hub should collect?
- self._environs = [ANACONDA_ENVIRON]
-
@abstractproperty
def data(self):
pass
diff --git a/pyanaconda/ui/gui/hubs/__init__.py b/pyanaconda/ui/gui/hubs/__init__.py
index 2563300..4aaab17 100644
--- a/pyanaconda/ui/gui/hubs/__init__.py
+++ b/pyanaconda/ui/gui/hubs/__init__.py
@@ -114,7 +114,7 @@ def _createBox(self):
selectors = []
for spokeClass in sorted(cats_and_spokes[c], key=lambda s: s.title):
# Check if this spoke is to be shown in the supported environments
- if not any(spokeClass.should_run(environ, self.data) for environ in self._environs):
+ if not any(spokeClass.should_run(environ, self.data) for environ in flags.environs):
continue
# Create the new spoke and populate its UI with whatever data.
--
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/443f356c38f20847d3a31bf096...
7 years, 11 months
Updated: [rhinstaller/anaconda/pulls/652 rhel7-branch] Don't try to
do payload reset in Initial Setup
by dashea
At the moment the network spoke tries to trigger a payload reset when network settings are changed even if running inside of Initial Setup. This is of course wrong, as there is no payload instance in Initial Setup, which can trigger a lot of various issues (crashes, weird log messages, etc.).
The first patch adds the environs flag so that spokes can easily check the environment at runtime. It also gets rid of the old _environs hub property.
The second patch then uses the environs flag to only trigger the payload reset when the network spoke is run from inside of Anaconda.
--
To view this pull request on github, visit https://github.com/rhinstaller/anaconda/pull/652
7 years, 11 months