cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame SOURCES/0060-nologin-silently-ignore-well-known-shell-command-lin.patch

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