From: Masatake YAMATO Date: Wed, 20 Jul 2022 01:43:02 +0000 (+0900) Subject: useradd: make the option specstr passed to getopt_long extensible X-Git-Tag: 4.12~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb96d3f84d0e1ee8f987a92eb4ea973b8c20a9c2;p=thirdparty%2Fshadow.git useradd: make the option specstr passed to getopt_long extensible 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 --- diff --git a/src/useradd.c b/src/useradd.c index 9e99892bd..b999e0c4b 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -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':