Be generally bit more strict about user names.
Signed-off-by: Vratislav Podzimek <vpodzime(a)redhat.com>
---
pyanaconda/ui/gui/spokes/user.py | 11 +++++++++--
pyanaconda/ui/tui/spokes/user.py | 4 ++--
pyanaconda/users.py | 5 +++++
3 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/pyanaconda/ui/gui/spokes/user.py b/pyanaconda/ui/gui/spokes/user.py
index d2abbaa..5686eff 100644
--- a/pyanaconda/ui/gui/spokes/user.py
+++ b/pyanaconda/ui/gui/spokes/user.py
@@ -22,7 +22,7 @@
from gi.repository import Gtk
from pyanaconda.i18n import _, N_
-from pyanaconda.users import cryptPassword, validatePassword, guess_username
+from pyanaconda.users import cryptPassword, validatePassword, guess_username,
USERNAME_VALID
from pwquality import PWQError
from pyanaconda.ui.gui.spokes import NormalSpoke
@@ -461,12 +461,19 @@ class UserSpoke(FirstbootSpokeMixIn, NormalSpoke):
self.admin.set_active(self._wheel.name in self._user.groups)
def on_back_clicked(self, button):
+ username = self.username.get_text()
+ # if an invalid username was given, that's the biggest issue
+ if username and not USERNAME_VALID.match(username):
+ self.clear_info()
+ self.set_warning(_("Invalid username given"))
+ self.username.grab_focus()
+ self.window.show_all()
# Return if:
# - no user is requested (empty username)
# - no password is required
# - password is set by kickstart and password text entry is empty
# - password is set by dialog and _validatePassword returns True
- if not self.username.get_text() or \
+ elif not username or \
not self.usepassword.get_active() or \
(self.pw.get_text() == "" and \
self.pw.get_text() == self.confirm.get_text() and \
diff --git a/pyanaconda/ui/tui/spokes/user.py b/pyanaconda/ui/tui/spokes/user.py
index 72efaec..2d2c7ac 100644
--- a/pyanaconda/ui/tui/spokes/user.py
+++ b/pyanaconda/ui/tui/spokes/user.py
@@ -24,7 +24,7 @@ from pyanaconda.ui.tui.spokes import EditTUISpokeEntry as Entry
from pyanaconda.ui.common import FirstbootSpokeMixIn
from pyanaconda.ui.tui.simpleline import TextWidget
from pyanaconda.ui.tui import YesNoDialog
-from pyanaconda.users import guess_username
+from pyanaconda.users import guess_username, USERNAME_VALID
from pyanaconda.i18n import _
from pykickstart.constants import FIRSTBOOT_RECONFIG
from pyanaconda.constants import ANACONDA_ENVIRON, FIRSTBOOT_ENVIRON
@@ -40,7 +40,7 @@ class UserSpoke(FirstbootSpokeMixIn, EditTUISpoke):
edit_fields = [
Entry("Create user", "_create", EditTUISpoke.CHECK, True),
Entry("Fullname", "gecos", re.compile("^[^:]*$"),
lambda self,args: args._create),
- Entry("Username", "name",
re.compile("^[a-z0-9_]+$"), lambda self,args: args._create),
+ Entry("Username", "name", USERNAME_VALID, lambda self,args:
args._create),
Entry("Use password", "_use_password", EditTUISpoke.CHECK,
lambda self,args: args._create),
Entry("Password", "_password", EditTUISpoke.PASSWORD, lambda
self,args: args._use_password and args._create),
Entry("Administrator", "_admin", EditTUISpoke.CHECK, lambda
self,args: args._create),
diff --git a/pyanaconda/users.py b/pyanaconda/users.py
index b47e760..6070fd0 100644
--- a/pyanaconda/users.py
+++ b/pyanaconda/users.py
@@ -28,6 +28,7 @@ import os
import os.path
import iutil
import pwquality
+import re
from pyanaconda.constants import ROOT_PATH
from pyanaconda.iutil import strip_accents
from pyanaconda.i18n import _
@@ -35,6 +36,10 @@ from pyanaconda.i18n import _
import logging
log = logging.getLogger("anaconda")
+_USERNAME_BASE =
r'[a-z0-9._](([a-z0-9._-]{0,2})|([a-z0-9._-]{3}(?<!root))|([a-z0-9._-]{4,31})|([a-z0-9._-]{,30}\$))'
+
+USERNAME_VALID = re.compile(r'^' + _USERNAME_BASE + '$')
+
def createLuserConf(instPath, algoname='sha512'):
""" Writes a libuser.conf for instPath.
--
1.8.4.2