]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/chkname.[ch]: login_name_max_size(): Add function
authorAlejandro Colomar <alx@kernel.org>
Fri, 10 May 2024 23:34:05 +0000 (01:34 +0200)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Tue, 21 May 2024 11:26:41 +0000 (13:26 +0200)
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>
lib/chkname.c
lib/chkname.h

index eedf5db111d1cc0a95b2be2bd79bd7bd6d923326..995562fa1412c507cf2883e37183c95d3245d90c 100644 (file)
 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);
index 6d545b3f7950d9626513bd504e6d897771e45456..4306a8a2c7055b5ef7c2d2a8bcec9d7632a5c2b7 100644 (file)
 #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);