]> granicus.if.org Git - shadow/commitdiff
* src/useradd.c: If the faillog file exist, warn in case of
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sun, 15 Jun 2008 22:25:51 +0000 (22:25 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sun, 15 Jun 2008 22:25:51 +0000 (22:25 +0000)
failure when open(), lssek(), write() or close() fails when the
new user's faillog entry is reset.
* src/useradd.c: Ditto for the lastlog entry.

ChangeLog
src/useradd.c

index e2f4f1d0e2c15a1f178c9e171b98cb8c5585134b..187ffacdacd281cfaa7087ac0dacc4b3069f25c7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-06-16  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * src/useradd.c: If the faillog file exist, warn in case of
+       failure when open(), lssek(), write() or close() fails when the
+       new user's faillog entry is reset.
+       * src/useradd.c: Ditto for the lastlog entry.
+
 2008-06-15  Nicolas François  <nicolas.francois@centraliens.net>
 
        * libmisc/limits.c: Add brackets and parenthesis.
index 3ba64eb7f097f3e5c37490c5e92e224e6adbfc53..acc5ffc0d8ee312356fdeba8d6ecb3678087338a 100644 (file)
@@ -1403,13 +1403,22 @@ static void faillog_reset (uid_t uid)
 {
        struct faillog fl;
        int fd;
+       off_t offset_uid = (off_t) (sizeof fl) * uid;
+
+       if (access (FAILLOG_FILE, F_OK) != 0) {
+               return;
+       }
+
+       memzero (&fl, sizeof (fl));
 
        fd = open (FAILLOG_FILE, O_RDWR);
-       if (fd >= 0) {
-               memzero (&fl, sizeof (fl));
-               lseek (fd, (off_t) sizeof (fl) * uid, SEEK_SET);
-               write (fd, &fl, sizeof (fl));
-               close (fd);
+       if (   (-1 == fd)
+           || (lseek (fd, offset_uid, SEEK_SET) != offset_uid)
+           || (write (fd, &fl, sizeof (fl)) != (ssize_t) sizeof (fl))
+           || (close (fd) != 0)) {
+               fprintf (stderr,
+                        _("%s: failed to reset the faillog entry of UID %lu: %s\n"),
+                        Prog, (unsigned long) uid, strerror(errno));
        }
 }
 
@@ -1417,13 +1426,22 @@ static void lastlog_reset (uid_t uid)
 {
        struct lastlog ll;
        int fd;
+       off_t offset_uid = (off_t) (sizeof ll) * uid;
+
+       if (access (LASTLOG_FILE, F_OK) != 0) {
+               return;
+       }
+
+       memzero (&ll, sizeof (ll));
 
        fd = open (LASTLOG_FILE, O_RDWR);
-       if (fd >= 0) {
-               memzero (&ll, sizeof (ll));
-               lseek (fd, (off_t) sizeof (ll) * uid, SEEK_SET);
-               write (fd, &ll, sizeof (ll));
-               close (fd);
+       if (   (-1 == fd)
+           || (lseek (fd, offset_uid, SEEK_SET) != offset_uid)
+           || (write (fd, &ll, sizeof (ll)) != (ssize_t) sizeof (ll))
+           || (close (fd) != 0)) {
+               fprintf (stderr,
+                        _("%s: failed to reset the lastlog entry of UID %lu: %s\n"),
+                        Prog, (unsigned long) uid, strerror(errno));
        }
 }