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...