Quellcode durchsuchen

installer: validate user login name based on useradd(8) rules

fixes #256
classabbyamp vor 2 Jahren
Ursprung
Commit
df59fd5a53
1 geänderte Dateien mit 12 neuen und 4 gelöschten Zeilen
  1. 12 4
      installer.sh.in

+ 12 - 4
installer.sh.in

@@ -665,16 +665,24 @@ set_rootpassword() {
 menu_useraccount() {
     local _firstpass _secondpass _desc _again
     local _groups _status _group _checklist
-    local _preset
+    local _preset _userlogin
 
     while true; do
         _preset=$(get_option USERLOGIN)
         [ -z "$_preset" ] && _preset="void"
         DIALOG --inputbox "Enter a primary login name:" ${INPUTSIZE} "$_preset"
         if [ $? -eq 0 ]; then
-            set_option USERLOGIN "$(cat $ANSWER)"
-            USERLOGIN_DONE=1
-            break
+            _userlogin="$(cat $ANSWER)"
+            # based on useradd(8) § Caveats
+            if [ "${#_userlogin}" -le 32 ] && [[ "${_userlogin}" =~ ^[a-z_][a-z0-9_-]*[$]?$ ]]; then
+                set_option USERLOGIN "${_userlogin}"
+                USERLOGIN_DONE=1
+                break
+            else
+                INFOBOX "Invalid login name! Please try again." 6 60
+                unset _userlogin
+                sleep 2 && clear && continue
+            fi
         else
             return
         fi