dcavalca / rpms / util-linux

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