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 <ipedrosa@redhat.com>
This commit is contained in:
Iker Pedrosa
2023-07-19 12:05:09 +02:00
committed by Serge Hallyn
parent fb8f44d73f
commit 3b7cc05387
3 changed files with 10 additions and 13 deletions

View 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

View 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;
}

View 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 */