dcavalca / rpms / util-linux

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