]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
useradd: Do not reset non-existent data in {last,fail}log
authorDavid Kalnischkies <david@kalnischkies.de>
Wed, 24 Aug 2022 11:21:01 +0000 (13:21 +0200)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Wed, 31 Aug 2022 14:13:46 +0000 (16:13 +0200)
useradd does not create the files if they don't exist, but if they exist
it will reset user data even if the data did not exist before creating
a hole and an explicitly zero'd data point resulting (especially for
high UIDs) in a lot of zeros ending up in containers and tarballs.

src/useradd.c

index 6eaeb5336c516a29cb12cbbac8efb8a9cd33b454..39a744ee071c818368fe5292391f0a5aca3f9907 100644 (file)
@@ -1996,8 +1996,9 @@ static void faillog_reset (uid_t uid)
        struct faillog fl;
        int fd;
        off_t offset_uid = (off_t) (sizeof fl) * uid;
+       struct stat st;
 
-       if (access (FAILLOG_FILE, F_OK) != 0) {
+       if (stat (FAILLOG_FILE, &st) != 0 || st.st_size <= offset_uid) {
                return;
        }
 
@@ -2033,8 +2034,9 @@ static void lastlog_reset (uid_t uid)
        int fd;
        off_t offset_uid = (off_t) (sizeof ll) * uid;
        uid_t max_uid;
+       struct stat st;
 
-       if (access (LASTLOG_FILE, F_OK) != 0) {
+       if (stat (LASTLOG_FILE, &st) != 0 || st.st_size <= offset_uid) {
                return;
        }