summaryrefslogtreecommitdiffstats
path: root/login-utils
diff options
context:
space:
mode:
authorKarel Zak2012-11-07 15:20:39 +0100
committerKarel Zak2012-11-07 15:20:39 +0100
commit360e088738aa792bf6c52e777d64b5163b45362a (patch)
treeff0101636e089d2f39d4d0aac968d903df3ae345 /login-utils
parentlsblk: fix and update man page about --scsi (diff)
downloadkernel-qcow2-util-linux-360e088738aa792bf6c52e777d64b5163b45362a.tar.gz
kernel-qcow2-util-linux-360e088738aa792bf6c52e777d64b5163b45362a.tar.xz
kernel-qcow2-util-linux-360e088738aa792bf6c52e777d64b5163b45362a.zip
su: fix "COMMAND not specified" error
# su su: COMMAND not specified This error message make sense for "runuser -u <user> <command>" only. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=872787 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'login-utils')
-rw-r--r--login-utils/su-common.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/login-utils/su-common.c b/login-utils/su-common.c
index 1fa76c820..5abdc840b 100644
--- a/login-utils/su-common.c
+++ b/login-utils/su-common.c
@@ -761,19 +761,28 @@ su_main (int argc, char **argv, int mode)
++optind;
}
- /* if not "-u <user>" specified then fallback to classic su(1) */
- if (!runuser_user && optind < argc)
- new_user = argv[optind++];
- else {
- /* runuser -u <command> */
- new_user = runuser_user;
- if (shell || fast_startup || command || simulate_login) {
- errx(EXIT_FAILURE,
+ switch (su_mode) {
+ case RUNUSER_MODE:
+ if (runuser_user) {
+ /* runuser -u <user> <command> */
+ new_user = runuser_user;
+ if (shell || fast_startup || command || simulate_login) {
+ errx(EXIT_FAILURE,
_("options --{shell,fast,command,session-command,login} and "
"--user are mutually exclusive."));
+ }
+ if (optind == argc)
+ errx(EXIT_FAILURE, _("COMMAND not specified."));
+
+ break;
}
- if (optind == argc)
- errx(EXIT_FAILURE, _("COMMAND not specified."));
+ /* fallthrough if -u <user> is not specified, then follow
+ * traditional su(1) behavior
+ */
+ case SU_MODE:
+ if (optind < argc)
+ new_user = argv[optind++];
+ break;
}
if ((num_supp_groups || use_gid) && restricted)