Util-Linux Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] nologin: Prevent error from su -c
@ 2019-10-09 23:08 Stanislav Brabec
  2019-10-11  8:11 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: Stanislav Brabec @ 2019-10-09 23:08 UTC (permalink / raw)
  To: util-linux

"su -c" can pass "-c" to nologin. It causes ugly error:

su -c "echo OK" - man
-nologin: invalid option -- 'c'
Try '-nologin --help' for more information.

Accept -c to prevent this error.

Signed-off-by: Josef Cejka <jcejka@suse.com>
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
---
 login-utils/nologin.8 | 11 +++++++++--
 login-utils/nologin.c |  9 +++++++--
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/login-utils/nologin.8 b/login-utils/nologin.8
index ee5948443..9389a86c6 100644
--- a/login-utils/nologin.8
+++ b/login-utils/nologin.8
@@ -18,9 +18,16 @@ The exit code returned by
 is always 1.
 .PP
 .SH OPTIONS
-.IP "\fB\-h, \-\-help\fP"
+
+
+.TP
+.IP "\fB\-c\fR, \fB\-\-command\fR \fIcommand\fR"
+Ignored. For compatibility with
+.I su -c "command" - user
+that would cause error otherwise.
+.IP "\fB\-h\fR, \fB\-\-help\fR"
 Display help text and exit.
-.IP "\fB-V, \-\-version"
+.IP "\fB-V\fR, \fB\-\-version\fR"
 Display version information and exit.
 .SH NOTES
 .B nologin
diff --git a/login-utils/nologin.c b/login-utils/nologin.c
index 14a091715..2fc1cd3cf 100644
--- a/login-utils/nologin.c
+++ b/login-utils/nologin.c
@@ -30,7 +30,8 @@ static void __attribute__((__noreturn__)) usage(void)
 	fputs(_("Politely refuse a login.\n"), out);
 
 	fputs(USAGE_OPTIONS, out);
-	printf(USAGE_HELP_OPTIONS(16));
+	fputs(_(" -c, --command <command>  does nothing (for compatibility with su -c)\n"), out);
+	printf(USAGE_HELP_OPTIONS(26));
 
 	printf(USAGE_MAN_TAIL("nologin(8)"));
 	exit(EXIT_FAILURE);
@@ -41,6 +42,7 @@ int main(int argc, char *argv[])
 	int c, fd = -1;
 	struct stat st;
 	static const struct option longopts[] = {
+		{ "command", required_argument, NULL, 'c' },
 		{ "help",    0, NULL, 'h' },
 		{ "version", 0, NULL, 'V' },
 		{ NULL, 0, NULL, 0 }
@@ -50,8 +52,11 @@ int main(int argc, char *argv[])
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
 
-	while ((c = getopt_long(argc, argv, "hV", longopts, NULL)) != -1) {
+	while ((c = getopt_long(argc, argv, "c:hV", longopts, NULL)) != -1) {
 		switch (c) {
+		case 'c':
+			/* Ignore the command, just don't print unknown option error. */
+			break;
 		case 'h':
 			usage();
 		case 'V':
-- 
2.23.0

-- 
Best Regards / S pozdravem,

Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o.                         e-mail: sbrabec@suse.com
Křižíkova 148/34 (Corso IIa)                    tel: +420 284 084 060
186 00 Praha 8-Karlín                          fax:  +420 284 084 001
Czech Republic                                    http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] nologin: Prevent error from su -c
  2019-10-09 23:08 [PATCH] nologin: Prevent error from su -c Stanislav Brabec
@ 2019-10-11  8:11 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2019-10-11  8:11 UTC (permalink / raw)
  To: Stanislav Brabec; +Cc: util-linux

On Thu, Oct 10, 2019 at 01:08:25AM +0200, Stanislav Brabec wrote:
>  login-utils/nologin.8 | 11 +++++++++--
>  login-utils/nologin.c |  9 +++++++--
>  2 files changed, 16 insertions(+), 4 deletions(-)

Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-09 23:08 [PATCH] nologin: Prevent error from su -c Stanislav Brabec
2019-10-11  8:11 ` Karel Zak

Util-Linux Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/util-linux/0 util-linux/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 util-linux util-linux/ https://lore.kernel.org/util-linux \
		util-linux@vger.kernel.org
	public-inbox-index util-linux

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.util-linux


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git