]> granicus.if.org Git - shadow/commitdiff
* lib/defines.h: Define USER_NAME_MAX_LENGTH, based on utmp and
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Wed, 22 Apr 2009 20:42:48 +0000 (20:42 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Wed, 22 Apr 2009 20:42:48 +0000 (20:42 +0000)
default to 32.
* libmisc/chkname.c: Use USER_NAME_MAX_LENGTH.
* src/login.c: Use USER_NAME_MAX_LENGTH instead of the default 32.
username also needs to be bigger than USER_NAME_MAX_LENGTH because
it has to be nul-terminated.

ChangeLog
lib/defines.h
libmisc/chkname.c
src/login.c

index d34a429c0a24bbd0cc0cf33cfc34321a8640ff5c..112cbe433b0207fb66f70c7f72ec05de6978a4fa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2009-04-22  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * lib/defines.h: Define USER_NAME_MAX_LENGTH, based on utmp and
+       default to 32.
+       * libmisc/chkname.c: Use USER_NAME_MAX_LENGTH.
+       * src/login.c: Use USER_NAME_MAX_LENGTH instead of the default 32.
+       username also needs to be bigger than USER_NAME_MAX_LENGTH because
+       it has to be nul-terminated.
+
 2009-04-22  Nicolas François  <nicolas.francois@centraliens.net>
 
        * src/login.c: Use xmalloc() instead of malloc().
index 9a81e83256f419841e4f7eab52ed242d0dee316d..9fb706b6b40fce02052b1f03f835f4aa56c36da7 100644 (file)
@@ -356,4 +356,19 @@ extern char *strerror ();
 #define MAX(x,y) (((x) > (y)) ? (x) : (y))
 #endif
 
+/* Maximum length of usernames */
+#ifdef HAVE_UTMPX_H
+# define USER_NAME_MAX_LENGTH (sizeof (((struct utmpx *)NULL)->ut_user))
+#else
+# ifdef HAVE_STRUCT_UTMP_UT_USER
+#  define USER_NAME_MAX_LENGTH (sizeof (((struct utmp *)NULL)->ut_user))
+# else
+#  ifdef HAVE_STRUCT_UTMP_UT_NAME
+#   define USER_NAME_MAX_LENGTH (sizeof (((struct utmp *)NULL)->ut_name))
+#  else
+#   define USER_NAME_MAX_LENGTH 32
+#  endif
+# endif
+#endif
+
 #endif                         /* _DEFINES_H_ */
index 67c4e3eb06b992c4832ae52c358ea044498cf7c6..428acc1133d1c2703e91091b421a05dc852e21cf 100644 (file)
@@ -77,17 +77,11 @@ static bool is_valid_name (const char *name)
 
 bool is_valid_user_name (const char *name)
 {
-#if HAVE_UTMPX_H
-       struct utmpx ut;
-#else
-       struct utmp ut;
-#endif
-
        /*
         * User names are limited by whatever utmp can
         * handle.
         */
-       if (strlen (name) > sizeof (ut.ut_user)) {
+       if (strlen (name) > USER_NAME_MAX_LENGTH) {
                return false;
        }
 
index 9aa6fcd0a1f5f734b335ecd8ba2379d537607228..1fc69a0720a0925d4fc2a46fe599b6ca4fa0c724 100644 (file)
@@ -610,8 +610,9 @@ int main (int argc, char **argv)
        }
 #ifdef RLOGIN
        if (rflg) {
-               username = xmalloc (32 * sizeof (char));
-               if (do_rlogin (hostname, username, 32, term, sizeof term)) {
+               username = xmalloc (USER_NAME_MAX_LENGTH + 1);
+               username[USER_NAME_MAX_LENGTH] = '\0';
+               if (do_rlogin (hostname, username, USER_NAME_MAX_LENGTH, term, sizeof term)) {
                        preauth_flag = true;
                } else {
                        free (username);
@@ -920,8 +921,9 @@ int main (int argc, char **argv)
                                exit (1);
                        }
                        preauth_flag = false;
-                       username = xmalloc (32);
-                       login_prompt (_("\n%s login: "), username, 32);
+                       username = xmalloc (USER_NAME_MAX_LENGTH + 1);
+                       username[USER_NAME_MAX_LENGTH] = '\0';
+                       login_prompt (_("\n%s login: "), username, USER_NAME_MAX_LENGTH);
 
                        if ('\0' == username) {
                                /* Prompt for a new login */