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 <tobias@stoeckmann.org>
#ident "$Id$"
#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
#include "defines.h"
#include "chkname.h"
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);