]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
nologin: silently ignore well known shell command-line options
authorSami Kerola <kerolasa@iki.fi>
Sun, 17 Nov 2019 08:33:04 +0000 (08:33 +0000)
committerSami Kerola <kerolasa@iki.fi>
Sun, 17 Nov 2019 08:33:04 +0000 (08:33 +0000)
nologin is typically used in /etc/passwd as a shell replacement.  Hence it
is reasonable to ignore well known command-line options silently to avoid
unwanted ugly error messages.

Addresses: https://github.com/karelzak/util-linux/issues/895
Requested-by: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
login-utils/nologin.8
login-utils/nologin.c

index 9389a86c662186e3728e9ccd23445689eef1842f..d3882e2b1d3e0ed6fdf926f176a1af1b74f43762 100644 (file)
@@ -1,4 +1,4 @@
-.TH NOLOGIN 8 "September 2013" "util-linux" "System Administration"
+.TH NOLOGIN 8 "November 2019" "util-linux" "System Administration"
 .SH NAME
 nologin \- politely refuse a login
 .SH SYNOPSIS
@@ -18,13 +18,29 @@ The exit code returned by
 is always 1.
 .PP
 .SH OPTIONS
-
-
-.TP
-.IP "\fB\-c\fR, \fB\-\-command\fR \fIcommand\fR"
-Ignored. For compatibility with
-.I su -c "command" - user
-that would cause error otherwise.
+\fB\-c\fR, \fB\-\-command\fR \fIcommand\fR
+.br
+\fB\-\-init-file\fR
+.br
+\fB\-i\fR \fB\-\-interactive\fR
+.br
+\fB\-\-init-file\fR \fIfile\fR
+.br
+\fB\-i\fR, \fB\-\-interactive\fR
+.br
+\fB\-l\fR, \fB\-\-login\fR
+.br
+\fB\-\-noprofile\fR
+.br
+\fB\-\-norc\fR
+.br
+\fB\-\-posix\fR
+.br
+\fB\-\-rcfile\fR \fIfile\fR
+.br
+\fB\-r\fR, \fB\-\-restricted\fR
+.IP
+These shell command-line options are ignored to avoid nologin error.
 .IP "\fB\-h\fR, \fB\-\-help\fR"
 Display help text and exit.
 .IP "\fB-V\fR, \fB\-\-version\fR"
index c0010fc3d696b05f395caaf975f4b2a6b8d30b9a..f38a3aab022d4774378e07e33a3f9ba69dc9ab9a 100644 (file)
@@ -41,10 +41,25 @@ int main(int argc, char *argv[])
 {
        int c, fd = -1;
        struct stat st;
+       enum {
+               OPT_INIT_FILE = CHAR_MAX + 1,
+               OPT_NOPROFILE,
+               OPT_NORC,
+               OPT_POSIX,
+               OPT_RCFILE
+       };
        static const struct option longopts[] = {
-               { "command", required_argument, NULL, 'c' },
-               { "help",    0, NULL, 'h' },
-               { "version", 0, NULL, 'V' },
+               { "command",     required_argument, NULL, 'c'           },
+               { "init-file",   required_argument, NULL, OPT_INIT_FILE },
+               { "interactive", no_argument,       NULL, 'i'           },
+               { "login",       no_argument,       NULL, 'l'           },
+               { "noprofile",   no_argument,       NULL, OPT_NOPROFILE },
+               { "norc",        no_argument,       NULL, OPT_NORC      },
+               { "posix",       no_argument,       NULL, OPT_POSIX     },
+               { "rcfile",      required_argument, NULL, OPT_RCFILE    },
+               { "restricted",  no_argument,       NULL, 'r'           },
+               { "help",        no_argument,       NULL, 'h'           },
+               { "version",     no_argument,       NULL, 'V'           },
                { NULL, 0, NULL, 0 }
        };
 
@@ -52,10 +67,18 @@ int main(int argc, char *argv[])
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
 
-       while ((c = getopt_long(argc, argv, "c:hV", longopts, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "c:ilrhV", longopts, NULL)) != -1) {
                switch (c) {
                case 'c':
-                       /* Ignore the command, just don't print unknown option error. */
+               case OPT_INIT_FILE:
+               case 'i':
+               case 'l':
+               case OPT_NOPROFILE:
+               case OPT_NORC:
+               case OPT_POSIX:
+               case OPT_RCFILE:
+               case 'r':
+                       /* Ignore well known shell command-line options */
                        break;
                case 'h':
                        usage();