]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib: replace `USER_NAME_MAX_LENGTH` macro
authorIker Pedrosa <ipedrosa@redhat.com>
Wed, 19 Jul 2023 10:05:09 +0000 (12:05 +0200)
committerSerge Hallyn <serge@hallyn.com>
Wed, 2 Aug 2023 15:13:28 +0000 (10:13 -0500)
Replace it by `sysconf(_SC_LOGIN_NAME_MAX)`, which is the maximum
username length supported by the kernel.

Resolves: https://github.com/shadow-maint/shadow/issues/674

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
lib/defines.h
libmisc/chkname.c
src/login.c

index efaddd00bae9cd44a915f2a3e233ac5965255bff..b289a72dfff8ae722658c6c7584fce1520f101db 100644 (file)
@@ -232,10 +232,6 @@ static inline void memzero(void *ptr, size_t size)
 # define format_attr(type, index, check)
 #endif
 
-/* Maximum length of usernames */
-#include <utmp.h>
-#define USER_NAME_MAX_LENGTH (sizeof (((struct utmp *)NULL)->ut_user))
-
 /* Maximum length of passwd entry */
 #define PASSWD_ENTRY_MAX_LENGTH 32768
 
index e31ee8c9471e4aec3818119c5578475e25e5073c..2b83361b82bdeaa62d895a60e8d3a250a64eefe5 100644 (file)
@@ -75,10 +75,9 @@ static bool is_valid_name (const char *name)
 bool is_valid_user_name (const char *name)
 {
        /*
-        * User names are limited by whatever utmp can
-        * handle.
+        * User names length are limited by the kernel
         */
-       if (strlen (name) > USER_NAME_MAX_LENGTH) {
+       if (strlen (name) > sysconf(_SC_LOGIN_NAME_MAX)) {
                return false;
        }
 
index 22deddd9aa2a8e549e152159eb77f9b1e104fe9f..b712cf445e806eef20acec42fead92c6685e1a8d 100644 (file)
@@ -572,10 +572,11 @@ int main (int argc, char **argv)
        }
 #ifdef RLOGIN
        if (rflg) {
+               size_t max_size = sysconf(_SC_LOGIN_NAME_MAX);
                assert (NULL == username);
-               username = XMALLOC(USER_NAME_MAX_LENGTH + 1, char);
-               username[USER_NAME_MAX_LENGTH] = '\0';
-               if (do_rlogin (hostname, username, USER_NAME_MAX_LENGTH, term, sizeof term)) {
+               username = XMALLOC(max_size + 1, char);
+               username[max_size] = '\0';
+               if (do_rlogin (hostname, username, max_size, term, sizeof term)) {
                        preauth_flag = true;
                } else {
                        free (username);
@@ -884,14 +885,15 @@ int main (int argc, char **argv)
 
                failed = false; /* haven't failed authentication yet */
                if (NULL == username) { /* need to get a login id */
+                       size_t max_size = sysconf(_SC_LOGIN_NAME_MAX);
                        if (subroot) {
                                closelog ();
                                exit (1);
                        }
                        preauth_flag = false;
-                       username = XMALLOC(USER_NAME_MAX_LENGTH + 1, char);
-                       username[USER_NAME_MAX_LENGTH] = '\0';
-                       login_prompt (username, USER_NAME_MAX_LENGTH);
+                       username = XMALLOC(max_size + 1, char);
+                       username[max_size] = '\0';
+                       login_prompt (username, max_size);
 
                        if ('\0' == username[0]) {
                                /* Prompt for a new login */