dcavalca / rpms / util-linux

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