]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
useradd: make the option specstr passed to getopt_long extensible
authorMasatake YAMATO <yamato@redhat.com>
Wed, 20 Jul 2022 01:43:02 +0000 (10:43 +0900)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Mon, 1 Aug 2022 13:45:10 +0000 (15:45 +0200)
It was hard to extend the option specification string passed to
getopt_long as the third argument.

The origian code had a branch with WITH_SELINUX ifdef condition. If
one wants to add one more option char with another ifdef condition
like ENABLE_SUBIDS to the spec, the one must enumerate the specs for
all combinations of the conditions:

*  WITH_SELINUX &&  ENABLE_SUBIDS
*  WITH_SELINUX && !ENABLE_SUBIDS
* !WITH_SELINUX &&  ENABLE_SUBIDS
* !WITH_SELINUX && !ENABLE_SUBIDS

With this change, you can append an option char to the spec.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
src/useradd.c

index 9e99892bdf2066fc79dd132772d84fb538db1b16..b999e0c4b05ef48f0885fac2f914220af550dfb5 100644 (file)
@@ -1218,11 +1218,11 @@ static void process_flags (int argc, char **argv)
                        {NULL, 0, NULL, '\0'}
                };
                while ((c = getopt_long (argc, argv,
+                                        "b:c:d:De:f:g:G:hk:K:lmMNop:rR:P:s:u:U"
 #ifdef WITH_SELINUX
-                                        "b:c:d:De:f:g:G:hk:K:lmMNop:rR:P:s:u:UZ:",
-#else                          /* !WITH_SELINUX */
-                                        "b:c:d:De:f:g:G:hk:K:lmMNop:rR:P:s:u:U",
-#endif                         /* !WITH_SELINUX */
+                                        "Z:"
+#endif                         /* WITH_SELINUX */
+                                        "",
                                         long_options, NULL)) != -1) {
                        switch (c) {
                        case 'b':