mirror of
https://github.com/shadow-maint/shadow.git
synced 2026-01-26 14:03:17 +00:00
lib/chkname.[ch]: login_name_max_size(): Add function
It encapsulates some logic that we may want to reuse elsewhere. Link: <https://github.com/shadow-maint/shadow/pull/989> Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
parent
27e467a61a
commit
99df9d746e
@ -33,6 +33,20 @@
|
||||
int allow_bad_names = false;
|
||||
|
||||
|
||||
size_t
|
||||
login_name_max_size(void)
|
||||
{
|
||||
long conf;
|
||||
|
||||
errno = 0;
|
||||
conf = sysconf(_SC_LOGIN_NAME_MAX);
|
||||
if (conf == -1 && errno != 0)
|
||||
return LOGIN_NAME_MAX;
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
||||
|
||||
static bool is_valid_name (const char *name)
|
||||
{
|
||||
if (allow_bad_names) {
|
||||
@ -84,18 +98,7 @@ static bool is_valid_name (const char *name)
|
||||
bool
|
||||
is_valid_user_name(const char *name)
|
||||
{
|
||||
long conf;
|
||||
size_t maxsize;
|
||||
|
||||
errno = 0;
|
||||
conf = sysconf(_SC_LOGIN_NAME_MAX);
|
||||
|
||||
if (conf == -1 && errno != 0)
|
||||
maxsize = LOGIN_NAME_MAX;
|
||||
else
|
||||
maxsize = conf;
|
||||
|
||||
if (strlen(name) >= maxsize)
|
||||
if (strlen(name) >= login_name_max_size())
|
||||
return false;
|
||||
|
||||
return is_valid_name(name);
|
||||
|
||||
@ -24,8 +24,10 @@
|
||||
#include <config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
extern size_t login_name_max_size(void);
|
||||
extern bool is_valid_user_name (const char *name);
|
||||
extern bool is_valid_group_name (const char *name);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user