cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
be81ba
From ae227f0eb3500b49fb78623f51ec9bd4366346ef Mon Sep 17 00:00:00 2001
be81ba
From: Stanislav Brabec <sbrabec@suse.cz>
be81ba
Date: Thu, 10 Oct 2019 01:08:25 +0200
be81ba
Subject: [PATCH 59/63] nologin: Prevent error from su -c
be81ba
be81ba
"su -c" can pass "-c" to nologin. It causes ugly error:
be81ba
be81ba
su -c "echo OK" - man
be81ba
-nologin: invalid option -- 'c'
be81ba
Try '-nologin --help' for more information.
be81ba
be81ba
Accept -c to prevent this error.
be81ba
be81ba
Upstream: http://github.com/karelzak/util-linux/commit/a174eefb41a2ce8b467bb7e1546953c8bd1223dd
be81ba
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1922299
be81ba
Signed-off-by: Josef Cejka <jcejka@suse.com>
be81ba
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
be81ba
---
be81ba
 login-utils/nologin.8 | 11 +++++++++--
be81ba
 login-utils/nologin.c |  9 +++++++--
be81ba
 2 files changed, 16 insertions(+), 4 deletions(-)
be81ba
be81ba
diff --git a/login-utils/nologin.8 b/login-utils/nologin.8
be81ba
index ee5948443..9389a86c6 100644
be81ba
--- a/login-utils/nologin.8
be81ba
+++ b/login-utils/nologin.8
be81ba
@@ -18,9 +18,16 @@ The exit code returned by
be81ba
 is always 1.
be81ba
 .PP
be81ba
 .SH OPTIONS
be81ba
-.IP "\fB\-h, \-\-help\fP"
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
+.IP "\fB\-h\fR, \fB\-\-help\fR"
be81ba
 Display help text and exit.
be81ba
-.IP "\fB-V, \-\-version"
be81ba
+.IP "\fB-V\fR, \fB\-\-version\fR"
be81ba
 Display version information and exit.
be81ba
 .SH NOTES
be81ba
 .B nologin
be81ba
diff --git a/login-utils/nologin.c b/login-utils/nologin.c
be81ba
index b0b6a721c..293f568c1 100644
be81ba
--- a/login-utils/nologin.c
be81ba
+++ b/login-utils/nologin.c
be81ba
@@ -30,7 +30,8 @@ static void __attribute__((__noreturn__)) usage(void)
be81ba
 	fputs(_("Politely refuse a login.\n"), out);
be81ba
 
be81ba
 	fputs(USAGE_OPTIONS, out);
be81ba
-	printf(USAGE_HELP_OPTIONS(16));
be81ba
+	fputs(_(" -c, --command <command>  does nothing (for compatibility with su -c)\n"), out);
be81ba
+	printf(USAGE_HELP_OPTIONS(26));
be81ba
 
be81ba
 	printf(USAGE_MAN_TAIL("nologin(8)"));
be81ba
 	exit(EXIT_FAILURE);
be81ba
@@ -41,6 +42,7 @@ int main(int argc, char *argv[])
be81ba
 	int c, fd = -1;
be81ba
 	struct stat st;
be81ba
 	static const struct option longopts[] = {
be81ba
+		{ "command", required_argument, NULL, 'c' },
be81ba
 		{ "help",    0, NULL, 'h' },
be81ba
 		{ "version", 0, NULL, 'V' },
be81ba
 		{ NULL, 0, NULL, 0 }
be81ba
@@ -50,8 +52,11 @@ int main(int argc, char *argv[])
be81ba
 	bindtextdomain(PACKAGE, LOCALEDIR);
be81ba
 	textdomain(PACKAGE);
be81ba
 
be81ba
-	while ((c = getopt_long(argc, argv, "hV", longopts, NULL)) != -1) {
be81ba
+	while ((c = getopt_long(argc, argv, "c:hV", longopts, NULL)) != -1) {
be81ba
 		switch (c) {
be81ba
+		case 'c':
be81ba
+			/* Ignore the command, just don't print unknown option error. */
be81ba
+			break;
be81ba
 		case 'h':
be81ba
 			usage();
be81ba
 			break;
be81ba
-- 
be81ba
2.31.1
be81ba