]> granicus.if.org Git - shadow/commitdiff
* libmisc/failure.h, libmisc/failure.c, src/login.c: Added
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Mon, 20 Apr 2009 11:37:41 +0000 (11:37 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Mon, 20 Apr 2009 11:37:41 +0000 (11:37 +0000)
username as first parameter of failtmp to avoid issues with
non-null terminated ut_user, unavailability of ut_user, incomplete
username (that should not happen currently).

libmisc/failure.c
libmisc/failure.h
src/login.c

index 5afc439acefa70d23119f3bf183242026cf4324f..0579dfd1475287f8c4b4508120b16aa0e3854934 100644 (file)
@@ -288,7 +288,7 @@ void failprint (const struct faillog *fail)
  *     maintains a record of all login failures.
  */
 
-void failtmp (
+void failtmp (const char *username,
 #ifdef HAVE_UTMPX_H
                     const struct utmpx *failent
 #else
@@ -320,13 +320,9 @@ void failtmp (
 
        fd = open (ftmp, O_WRONLY | O_APPEND);
        if (-1 == fd) {
-               char ut_user[sizeof failent->ut_user];
-               (void) strncpy (&ut_user[0], failent->ut_user, sizeof ut_user);
-               ut_user[sizeof ut_user - 1] = '\0';
-
                SYSLOG ((LOG_WARN,
                         "Can't append failure of user %s to %s.",
-                        ut_user, ftmp));
+                        username, ftmp));
                return;
        }
 
@@ -336,13 +332,9 @@ void failtmp (
 
        if (   (write (fd, (const void *) failent, sizeof *failent) != (ssize_t) sizeof *failent)
            || (close (fd) != 0)) {
-               char ut_user[sizeof failent->ut_user];
-               (void) strncpy (&ut_user[0], failent->ut_user, sizeof ut_user);
-               ut_user[sizeof ut_user - 1] = '\0';
-
                SYSLOG ((LOG_WARN,
                         "Can't append failure of user %s to %s.",
-                        ut_user, ftmp));
+                        username, ftmp));
                (void) close (fd);
        }
 }
index 859bda47052a40475b9f7c29c88103158db4e7d1..c7bebcffd4edbf3742eaaec54379217557e7a980 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1990 - 1994, Julianne Frances Haugh
  * Copyright (c) 1997 - 2000, Marek Michałkiewicz
  * Copyright (c) 2005       , Tomasz Kłoczko
- * Copyright (c) 2008       , Nicolas François
+ * Copyright (c) 2008 - 2009, Nicolas François
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -75,9 +75,9 @@ extern void failprint (const struct faillog *);
  *     maintains a record of all login failures.
  */
 #ifdef HAVE_UTMPX_H
-extern void failtmp (const struct utmpx *);
+extern void failtmp (const char *username, const struct utmpx *);
 #else
-extern void failtmp (const struct utmp *);
+extern void failtmp (const char *username, const struct utmp *);
 #endif
 
 #endif
index 30f6aab25837ae0f81ede4d0d6ab95f1a8967b69..699549acd635c216dfb1053e3a37cbb819af3777 100644 (file)
@@ -997,7 +997,7 @@ int main (int argc, char **argv)
                        strncpy (failent.ut_user, failent_user,
                                 sizeof (failent.ut_user));
                        failent.ut_type = USER_PROCESS;
-                       failtmp (&failent);
+                       failtmp (failent_user, &failent);
                }
 
                retries--;