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