dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
6eff72
From bfa7d299f8a497a835bc250bd765094ee06b8a01 Mon Sep 17 00:00:00 2001
6eff72
From: Sami Kerola <kerolasa@iki.fi>
6eff72
Date: Sun, 17 Nov 2019 08:33:04 +0000
6eff72
Subject: [PATCH 60/63] nologin: silently ignore well known shell command-line
6eff72
 options
6eff72
6eff72
nologin is typically used in /etc/passwd as a shell replacement.  Hence it
6eff72
is reasonable to ignore well known command-line options silently to avoid
6eff72
unwanted ugly error messages.
6eff72
6eff72
Addresses: https://github.com/karelzak/util-linux/issues/895
6eff72
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1922299
6eff72
Upstream: http://github.com/karelzak/util-linux/commit/beb61b07c20ab902fec883a4bd087c45d2742dea
6eff72
Requested-by: Lennart Poettering <lennart@poettering.net>
6eff72
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
6eff72
---
6eff72
 login-utils/nologin.8 | 32 ++++++++++++++++++++++++--------
6eff72
 login-utils/nologin.c | 33 ++++++++++++++++++++++++++++-----
6eff72
 2 files changed, 52 insertions(+), 13 deletions(-)
6eff72
6eff72
diff --git a/login-utils/nologin.8 b/login-utils/nologin.8
6eff72
index 9389a86c6..d3882e2b1 100644
6eff72
--- a/login-utils/nologin.8
6eff72
+++ b/login-utils/nologin.8
6eff72
@@ -1,4 +1,4 @@
6eff72
-.TH NOLOGIN 8 "September 2013" "util-linux" "System Administration"
6eff72
+.TH NOLOGIN 8 "November 2019" "util-linux" "System Administration"
6eff72
 .SH NAME
6eff72
 nologin \- politely refuse a login
6eff72
 .SH SYNOPSIS
6eff72
@@ -18,13 +18,29 @@ The exit code returned by
6eff72
 is always 1.
6eff72
 .PP
6eff72
 .SH OPTIONS
6eff72
-
6eff72
-
6eff72
-.TP
6eff72
-.IP "\fB\-c\fR, \fB\-\-command\fR \fIcommand\fR"
6eff72
-Ignored. For compatibility with
6eff72
-.I su -c "command" - user
6eff72
-that would cause error otherwise.
6eff72
+\fB\-c\fR, \fB\-\-command\fR \fIcommand\fR
6eff72
+.br
6eff72
+\fB\-\-init-file\fR
6eff72
+.br
6eff72
+\fB\-i\fR \fB\-\-interactive\fR
6eff72
+.br
6eff72
+\fB\-\-init-file\fR \fIfile\fR
6eff72
+.br
6eff72
+\fB\-i\fR, \fB\-\-interactive\fR
6eff72
+.br
6eff72
+\fB\-l\fR, \fB\-\-login\fR
6eff72
+.br
6eff72
+\fB\-\-noprofile\fR
6eff72
+.br
6eff72
+\fB\-\-norc\fR
6eff72
+.br
6eff72
+\fB\-\-posix\fR
6eff72
+.br
6eff72
+\fB\-\-rcfile\fR \fIfile\fR
6eff72
+.br
6eff72
+\fB\-r\fR, \fB\-\-restricted\fR
6eff72
+.IP
6eff72
+These shell command-line options are ignored to avoid nologin error.
6eff72
 .IP "\fB\-h\fR, \fB\-\-help\fR"
6eff72
 Display help text and exit.
6eff72
 .IP "\fB-V\fR, \fB\-\-version\fR"
6eff72
diff --git a/login-utils/nologin.c b/login-utils/nologin.c
6eff72
index 293f568c1..567a9a2ca 100644
6eff72
--- a/login-utils/nologin.c
6eff72
+++ b/login-utils/nologin.c
6eff72
@@ -41,10 +41,25 @@ int main(int argc, char *argv[])
6eff72
 {
6eff72
 	int c, fd = -1;
6eff72
 	struct stat st;
6eff72
+	enum {
6eff72
+		OPT_INIT_FILE = CHAR_MAX + 1,
6eff72
+		OPT_NOPROFILE,
6eff72
+		OPT_NORC,
6eff72
+		OPT_POSIX,
6eff72
+		OPT_RCFILE
6eff72
+	};
6eff72
 	static const struct option longopts[] = {
6eff72
-		{ "command", required_argument, NULL, 'c' },
6eff72
-		{ "help",    0, NULL, 'h' },
6eff72
-		{ "version", 0, NULL, 'V' },
6eff72
+		{ "command",     required_argument, NULL, 'c'           },
6eff72
+		{ "init-file",   required_argument, NULL, OPT_INIT_FILE },
6eff72
+		{ "interactive", no_argument,       NULL, 'i'           },
6eff72
+		{ "login",       no_argument,       NULL, 'l'           },
6eff72
+		{ "noprofile",   no_argument,       NULL, OPT_NOPROFILE },
6eff72
+		{ "norc",        no_argument,       NULL, OPT_NORC      },
6eff72
+		{ "posix",       no_argument,       NULL, OPT_POSIX     },
6eff72
+		{ "rcfile",      required_argument, NULL, OPT_RCFILE    },
6eff72
+		{ "restricted",  no_argument,       NULL, 'r'           },
6eff72
+		{ "help",        no_argument,       NULL, 'h'           },
6eff72
+		{ "version",     no_argument,       NULL, 'V'           },
6eff72
 		{ NULL, 0, NULL, 0 }
6eff72
 	};
6eff72
 
6eff72
@@ -52,10 +67,18 @@ int main(int argc, char *argv[])
6eff72
 	bindtextdomain(PACKAGE, LOCALEDIR);
6eff72
 	textdomain(PACKAGE);
6eff72
 
6eff72
-	while ((c = getopt_long(argc, argv, "c:hV", longopts, NULL)) != -1) {
6eff72
+	while ((c = getopt_long(argc, argv, "c:ilrhV", longopts, NULL)) != -1) {
6eff72
 		switch (c) {
6eff72
 		case 'c':
6eff72
-			/* Ignore the command, just don't print unknown option error. */
6eff72
+		case OPT_INIT_FILE:
6eff72
+		case 'i':
6eff72
+		case 'l':
6eff72
+		case OPT_NOPROFILE:
6eff72
+		case OPT_NORC:
6eff72
+		case OPT_POSIX:
6eff72
+		case OPT_RCFILE:
6eff72
+		case 'r':
6eff72
+			/* Ignore well known shell command-line options */
6eff72
 			break;
6eff72
 		case 'h':
6eff72
 			usage();
6eff72
-- 
6eff72
2.31.1
6eff72