]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
nologin: Prevent error from su -c
authorStanislav Brabec <sbrabec@suse.cz>
Wed, 9 Oct 2019 23:08:25 +0000 (01:08 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 11 Oct 2019 08:08:03 +0000 (10:08 +0200)
"su -c" can pass "-c" to nologin. It causes ugly error:

su -c "echo OK" - man
-nologin: invalid option -- 'c'
Try '-nologin --help' for more information.

Accept -c to prevent this error.

Signed-off-by: Josef Cejka <jcejka@suse.com>
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
login-utils/nologin.8
login-utils/nologin.c

index ee59484430291aa647fc119d1f698abe1b8183c2..9389a86c662186e3728e9ccd23445689eef1842f 100644 (file)
@@ -18,9 +18,16 @@ The exit code returned by
 is always 1.
 .PP
 .SH OPTIONS
-.IP "\fB\-h, \-\-help\fP"
+
+
+.TP
+.IP "\fB\-c\fR, \fB\-\-command\fR \fIcommand\fR"
+Ignored. For compatibility with
+.I su -c "command" - user
+that would cause error otherwise.
+.IP "\fB\-h\fR, \fB\-\-help\fR"
 Display help text and exit.
-.IP "\fB-V, \-\-version"
+.IP "\fB-V\fR, \fB\-\-version\fR"
 Display version information and exit.
 .SH NOTES
 .B nologin
index 14a091715e14fee51835c20531188d0ceb6a0e43..c0010fc3d696b05f395caaf975f4b2a6b8d30b9a 100644 (file)
@@ -30,7 +30,8 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_("Politely refuse a login.\n"), out);
 
        fputs(USAGE_OPTIONS, out);
-       printf(USAGE_HELP_OPTIONS(16));
+       fputs(_(" -c, --command <command>  does nothing (for compatibility with su -c)\n"), out);
+       printf(USAGE_HELP_OPTIONS(26));
 
        printf(USAGE_MAN_TAIL("nologin(8)"));
        exit(EXIT_FAILURE);
@@ -41,6 +42,7 @@ int main(int argc, char *argv[])
        int c, fd = -1;
        struct stat st;
        static const struct option longopts[] = {
+               { "command", required_argument, NULL, 'c' },
                { "help",    0, NULL, 'h' },
                { "version", 0, NULL, 'V' },
                { NULL, 0, NULL, 0 }
@@ -50,8 +52,11 @@ int main(int argc, char *argv[])
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
 
-       while ((c = getopt_long(argc, argv, "hV", longopts, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "c:hV", longopts, NULL)) != -1) {
                switch (c) {
+               case 'c':
+                       /* Ignore the command, just don't print unknown option error. */
+                       break;
                case 'h':
                        usage();
                case 'V':