]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
usermod: Create shadow entry with -e 0 or -f 0
authorTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 11 Mar 2026 20:15:10 +0000 (21:15 +0100)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Thu, 12 Mar 2026 22:15:31 +0000 (23:15 +0100)
If -e 0 or -f 0 are supplied but no shadow entry exists, these flags are
silently ignored. Internally, the supplied values (0) are compared with
static long values which are initially 0 as well. If they are identical,
usermod drops the flags.

This does not match usermod's manual page, which states that a missing
shadow entry is created. This is also true for any other valid command
line values, e.g. -e 1 or -f 1.

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
src/usermod.c

index 194f6145f0d1e57623d620cafe77e17b01deffac..2c4651f1b77b6c6df8d61f46ed4c5d513a8eb9cb 100644 (file)
@@ -97,6 +97,9 @@
 
 #define VALID(s)  (!strpbrk(s, ":\n"))
 
+/* invalid shadow time indicating missing entry */
+#define MISSING_TIME   -2
+
 /*
  * Structures
  */
@@ -127,10 +130,10 @@ static const char *user_selinux = "";
 static const char *user_selinux_range = NULL;
 #endif                         /* WITH_SELINUX */
 static char *user_newshell;
-static long user_expire;
-static long user_newexpire;
-static long user_inactive;
-static long user_newinactive;
+static long user_expire = MISSING_TIME;
+static long user_newexpire = MISSING_TIME;
+static long user_inactive = MISSING_TIME;
+static long user_newinactive = MISSING_TIME;
 static long sys_ngroups;
 static char **user_groups;     /* NULL-terminated list */