Blame SOURCES/shadow-4.6-goodname.patch

9a10ea
diff -up shadow-4.6/libmisc/chkname.c.goodname shadow-4.6/libmisc/chkname.c
9a10ea
--- shadow-4.6/libmisc/chkname.c.goodname	2020-10-23 12:50:47.202529031 +0200
9a10ea
+++ shadow-4.6/libmisc/chkname.c	2020-10-23 12:54:54.604692559 +0200
9a10ea
@@ -49,25 +49,44 @@
4fb1b2
 static bool is_valid_name (const char *name)
9a10ea
 {
4fb1b2
 	/*
4fb1b2
-	 * User/group names must match [a-z_][a-z0-9_-]*[$]
4fb1b2
-	 */
4fb1b2
-	if (('\0' == *name) ||
4fb1b2
-	    !((('a' <= *name) && ('z' >= *name)) || ('_' == *name))) {
4fb1b2
+         * User/group names must match gnu e-regex:
4fb1b2
+         *    [a-zA-Z0-9_.][a-zA-Z0-9_.-]{0,30}[a-zA-Z0-9_.$-]?
4fb1b2
+         *
4fb1b2
+         * as a non-POSIX, extension, allow "$" as the last char for
4fb1b2
+         * sake of Samba 3.x "add machine script"
4fb1b2
+         *
4fb1b2
+         * Also do not allow fully numeric names or just "." or "..".
4fb1b2
+         */
4fb1b2
+	int numeric;
4fb1b2
+
4fb1b2
+	if ('\0' == *name ||
4fb1b2
+	    ('.' == *name && (('.' == name[1] && '\0' == name[2]) ||
4fb1b2
+			      '\0' == name[1])) ||
4fb1b2
+	    !((*name >= 'a' && *name <= 'z') ||
4fb1b2
+	      (*name >= 'A' && *name <= 'Z') ||
4fb1b2
+	      (*name >= '0' && *name <= '9') ||
4fb1b2
+	      *name == '_' ||
4fb1b2
+	      *name == '.')) {
4fb1b2
 		return false;
4fb1b2
 	}
4fb1b2
 
4fb1b2
+	numeric = isdigit(*name);
4fb1b2
+
4fb1b2
 	while ('\0' != *++name) {
4fb1b2
-		if (!(( ('a' <= *name) && ('z' >= *name) ) ||
4fb1b2
-		      ( ('0' <= *name) && ('9' >= *name) ) ||
4fb1b2
-		      ('_' == *name) ||
4fb1b2
-		      ('-' == *name) ||
4fb1b2
-		      ( ('$' == *name) && ('\0' == *(name + 1)) )
4fb1b2
+		if (!((*name >= 'a' && *name <= 'z') ||
4fb1b2
+		      (*name >= 'A' && *name <= 'Z') ||
4fb1b2
+		      (*name >= '0' && *name <= '9') ||
4fb1b2
+		      *name == '_' ||
4fb1b2
+		      *name == '.' ||
4fb1b2
+		      *name == '-' ||
4fb1b2
+		      (*name == '$' && name[1] == '\0')
4fb1b2
 		     )) {
4fb1b2
 			return false;
4fb1b2
 		}
4fb1b2
+		numeric &= isdigit(*name);
4fb1b2
 	}
4fb1b2
 
4fb1b2
-	return true;
4fb1b2
+	return !numeric;
4fb1b2
 }
4fb1b2
 
4fb1b2
 bool is_valid_user_name (const char *name)
9a10ea
diff -up shadow-4.6/man/groupadd.8.xml.goodname shadow-4.6/man/groupadd.8.xml
9a10ea
--- shadow-4.6/man/groupadd.8.xml.goodname	2018-04-29 18:42:37.000000000 +0200
9a10ea
+++ shadow-4.6/man/groupadd.8.xml	2020-10-23 12:50:47.202529031 +0200
9a10ea
@@ -273,10 +273,14 @@
4fb1b2
    <refsect1 id='caveats'>
4fb1b2
      <title>CAVEATS</title>
4fb1b2
      <para>
4fb1b2
-       Groupnames must start with a lower case letter or an underscore,
4fb1b2
-       followed by lower case letters, digits, underscores, or dashes.
4fb1b2
-       They can end with a dollar sign.
4fb1b2
-       In regular expression terms: [a-z_][a-z0-9_-]*[$]?
9a10ea
+       Groupnames may begin with lower and upper case letters, digits,
9a10ea
+       underscores, or periods. They may continue with all the aforementioned
9a10ea
+       characters, or dashes. Finally, they can end with a dollar sign.
4fb1b2
+
9a10ea
+       Fully numeric groupnames and groupnames containing only . or .. are
9a10ea
+       disallowed.
4fb1b2
+
4fb1b2
+       In regular expression terms: [a-zA-Z0-9_.][a-zA-Z0-9_.-]*[$]?
4fb1b2
      </para>
4fb1b2
      <para>
4fb1b2
        Groupnames may only be up to &GROUP_NAME_MAX_LENGTH; characters long.
9a10ea
diff -up shadow-4.6/man/useradd.8.xml.goodname shadow-4.6/man/useradd.8.xml
9a10ea
--- shadow-4.6/man/useradd.8.xml.goodname	2018-04-29 18:42:37.000000000 +0200
9a10ea
+++ shadow-4.6/man/useradd.8.xml	2020-10-23 12:50:47.202529031 +0200
9a10ea
@@ -650,10 +650,16 @@
4fb1b2
     </para>
4fb1b2
 
4fb1b2
     <para>
4fb1b2
-      Usernames must start with a lower case letter or an underscore,
4fb1b2
-      followed by lower case letters, digits, underscores, or dashes.
4fb1b2
-      They can end with a dollar sign.
4fb1b2
-      In regular expression terms: [a-z_][a-z0-9_-]*[$]?
9a10ea
+      Usernames may begin with lower and upper case letters, digits,
9a10ea
+      underscores, or periods. They may continue with all the aforementioned
9a10ea
+      characters, or dashes. Finally, they can end with a dollar sign.
4fb1b2
+
9a10ea
+      Fully numeric usernames and usernames containing only . or .. are
9a10ea
+      disallowed. It is not recommended to use usernames beginning
4fb1b2
+      with . character as their home directories will be hidden in
4fb1b2
+      the <command>ls</command> output.
4fb1b2
+
4fb1b2
+      In regular expression terms: [a-zA-Z0-9_.][a-zA-Z0-9_.-]*[$]?
4fb1b2
     </para>
4fb1b2
     <para>
4fb1b2
       Usernames may only be up to 32 characters long.