]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/chkname.c: Support unlimited user name lengths
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 3 Feb 2024 00:10:22 +0000 (01:10 +0100)
committerSerge Hallyn <serge@hallyn.com>
Sun, 4 Feb 2024 23:03:12 +0000 (17:03 -0600)
If the system does not have a user name length limit, support it
accordingly. If the system has no _SC_LOGIN_NAME_MAX, use
LOGIN_NAME_MAX constant instead.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
lib/chkname.c

index 1c596349623cd2f1b3dace797e48e6b2ef849dc0..40069932c4e76716250a7213de766ea90c315b6d 100644 (file)
@@ -20,6 +20,8 @@
 #ident "$Id$"
 
 #include <ctype.h>
+#include <errno.h>
+#include <limits.h>
 #include "defines.h"
 #include "chkname.h"
 
@@ -74,13 +76,16 @@ static bool is_valid_name (const char *name)
 
 bool is_valid_user_name (const char *name)
 {
-       size_t  maxlen;
+       long  maxlen;
 
        /*
         * User names length are limited by the kernel
         */
+       errno = 0;
        maxlen = sysconf(_SC_LOGIN_NAME_MAX);
-       if (strlen(name) >= maxlen)
+       if (maxlen == -1 && errno != 0)
+               maxlen = LOGIN_NAME_MAX;
+       if (maxlen != -1 && strlen(name) >= (size_t)maxlen)
                return false;
 
        return is_valid_name (name);