]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Make the sp_lstchg shadow field reproducible (re. #71)
authorChris Lamb <chris@chris-lamb.co.uk>
Wed, 2 Jan 2019 18:06:16 +0000 (18:06 +0000)
committerChris Lamb <chris@chris-lamb.co.uk>
Sun, 31 Mar 2019 15:00:01 +0000 (16:00 +0100)
From <https://github.com/shadow-maint/shadow/pull/71>:

```
The third field in the /etc/shadow file (sp_lstchg) contains the date of
the last password change expressed as the number of days since Jan 1, 1970.
As this is a relative time, creating a user today will result in:

username:17238:0:99999:7:::
whilst creating the same user tomorrow will result in:

username:17239:0:99999:7:::
This has an impact for the Reproducible Builds[0] project where we aim to
be independent of as many elements the build environment as possible,
including the current date.

This patch changes the behaviour to use the SOURCE_DATE_EPOCH[1]
environment variable (instead of Jan 1, 1970) if valid.
```

This updated PR adds some missing calls to gettime (). This was originally
filed by Johannes Schauer in Debian as #917773 [2].

[0] https://reproducible-builds.org/
[1] https://reproducible-builds.org/specs/source-date-epoch/
[2] https://bugs.debian.org/917773

libmisc/pwd2spwd.c
src/pwck.c
src/pwconv.c

index c1b9b29ac873ac11c731446a6625443251594d92..6799dd50d490c1c144cdc9a8c29ca0785b924b54 100644 (file)
@@ -40,7 +40,6 @@
 #include "prototypes.h"
 #include "defines.h"
 #include <pwd.h>
-extern time_t time (time_t *);
 
 /*
  * pwd_to_spwd - create entries for new spwd structure
@@ -66,7 +65,7 @@ struct spwd *pwd_to_spwd (const struct passwd *pw)
                 */
                sp.sp_min = 0;
                sp.sp_max = (10000L * DAY) / SCALE;
-               sp.sp_lstchg = (long) time ((time_t *) 0) / SCALE;
+               sp.sp_lstchg = (long) gettime () / SCALE;
                if (0 == sp.sp_lstchg) {
                        /* Better disable aging than requiring a password
                         * change */
index 0ffb711efb13d7021b42d9671fd5fd0dc8ad85fa..f70071b125003c8c70e365825eea5e2524d5f38a 100644 (file)
@@ -609,7 +609,7 @@ static void check_pw_file (int *errors, bool *changed)
                                        sp.sp_inact  = -1;
                                        sp.sp_expire = -1;
                                        sp.sp_flag   = SHADOW_SP_FLAG_UNSET;
-                                       sp.sp_lstchg = (long) time ((time_t *) 0) / SCALE;
+                                       sp.sp_lstchg = (long) gettime () / SCALE;
                                        if (0 == sp.sp_lstchg) {
                                                /* Better disable aging than
                                                 * requiring a password change
index 9c69fa131d8e34a3a1c7069a22e22e0cd31ecf53..f932f266c59cb18f3eb78fc4260f4bf40423b808 100644 (file)
@@ -267,7 +267,7 @@ int main (int argc, char **argv)
                        spent.sp_flag   = SHADOW_SP_FLAG_UNSET;
                }
                spent.sp_pwdp = pw->pw_passwd;
-               spent.sp_lstchg = (long) time ((time_t *) 0) / SCALE;
+               spent.sp_lstchg = (long) gettime () / SCALE;
                if (0 == spent.sp_lstchg) {
                        /* Better disable aging than requiring a password
                         * change */