Skip to content

Commit

Permalink
lib/chkname.c: Support unlimited user name lengths
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
stoeckmann authored and hallyn committed Feb 4, 2024
1 parent 403a2e3 commit 6a1f45d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/chkname.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#ident "$Id$"

#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include "defines.h"
#include "chkname.h"

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6a1f45d

Please sign in to comment.