From: Iker Pedrosa Date: Wed, 19 Jul 2023 10:05:09 +0000 (+0200) Subject: lib: replace `USER_NAME_MAX_LENGTH` macro X-Git-Tag: 4.14.0-rc1~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3b7cc053872c;p=thirdparty%2Fshadow.git lib: replace `USER_NAME_MAX_LENGTH` macro 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 --- diff --git a/lib/defines.h b/lib/defines.h index efaddd00b..b289a72df 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -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 -#define USER_NAME_MAX_LENGTH (sizeof (((struct utmp *)NULL)->ut_user)) - /* Maximum length of passwd entry */ #define PASSWD_ENTRY_MAX_LENGTH 32768 diff --git a/libmisc/chkname.c b/libmisc/chkname.c index e31ee8c94..2b83361b8 100644 --- a/libmisc/chkname.c +++ b/libmisc/chkname.c @@ -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; } diff --git a/src/login.c b/src/login.c index 22deddd9a..b712cf445 100644 --- a/src/login.c +++ b/src/login.c @@ -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 */