summaryrefslogtreecommitdiffstats
path: root/usr.bin/su
diff options
context:
space:
mode:
authorjoerg <joerg@FreeBSD.org>1995-09-06 12:38:53 +0000
committerjoerg <joerg@FreeBSD.org>1995-09-06 12:38:53 +0000
commit6ff265052fcdab1ec8582476b13b536c8a849f0b (patch)
tree4959342e196638f9d1e660ae155c75b34ac11a00 /usr.bin/su
parentf7089aa4c2860ffcb56a968fd5214c29ebbc8e26 (diff)
downloadFreeBSD-src-6ff265052fcdab1ec8582476b13b536c8a849f0b.zip
FreeBSD-src-6ff265052fcdab1ec8582476b13b536c8a849f0b.tar.gz
Bring Barry Morris' changes from FreeBSD 1.1.5.1 back: pass arguments
to the target login's shell. This allows for "su -c". Do it right this time and also explain this behaviour in the man page. :) Obtained from: bsm's work in FreeBSD 1.1.5.1
Diffstat (limited to 'usr.bin/su')
-rw-r--r--usr.bin/su/su.129
-rw-r--r--usr.bin/su/su.c30
2 files changed, 50 insertions, 9 deletions
diff --git a/usr.bin/su/su.1 b/usr.bin/su/su.1
index ea9edcf..d4abfd0 100644
--- a/usr.bin/su/su.1
+++ b/usr.bin/su/su.1
@@ -31,6 +31,7 @@
.\"
.\" @(#)su.1 8.2 (Berkeley) 4/18/94
.\"
+.\" this is for hilit19's braindeadness: "
.Dd April 18, 1994
.Dt SU 1
.Os
@@ -40,7 +41,7 @@
.Sh SYNOPSIS
.Nm su
.Op Fl Kflm
-.Op Ar login
+.Op Ar login Op Ar args
.Sh DESCRIPTION
.Nm Su
requests the Kerberos password for
@@ -128,6 +129,17 @@ and
options are mutually exclusive; the last one specified
overrides any previous ones.
.Pp
+If the optional
+.Ar args
+are provided on the command line, they are passed to the login shell of
+the target login. This allows it to pass arbitrary commands via
+the
+.Fl c
+option as understood by most shells. Note that
+.Fl c
+usually expects a single argument only; you have to quote it when
+passing multiple words.
+.Pp
Only users in group 0 (normally
.Dq wheel )
can
@@ -165,6 +177,21 @@ The user ID is always the effective ID (the target user ID) after an
.Nm su
unless the user ID is 0 (root).
.El
+.Sh EXAMPLES
+.Bl -tag -width 5n -compact
+.It Li "su man -c catman"
+Runs the command
+.Li catman
+as user
+.Li man .
+You will be asked for man's password unless your real UID is 0.
+.It Li "su man -c 'catman /usr/share/man /usr/local/man /usr/X11R6/man'"
+Same as above, but the target command constitutes of more than a
+single word.
+.It Li "su -l foo"
+Pretend a login for user
+.Li foo .
+.El
.Sh HISTORY
A
.Nm
diff --git a/usr.bin/su/su.c b/usr.bin/su/su.c
index b3eb587..e8afb37 100644
--- a/usr.bin/su/su.c
+++ b/usr.bin/su/su.c
@@ -86,20 +86,20 @@ main(argc, argv)
char *targetpass;
int iswheelsu;
#endif /* WHEELSU */
- char *p, **g, *user, *shell, *username, *cleanenv[20], *nargv[4], **np;
+ char *p, **g, *user, *shell, *username, *cleanenv[20], **nargv, **np;
struct group *gr;
uid_t ruid;
- int asme, ch, asthem, fastlogin, prio;
+ int asme, ch, asthem, fastlogin, prio, i;
enum { UNSET, YES, NO } iscsh = UNSET;
char shellbuf[MAXPATHLEN];
- np = &nargv[3];
- *np-- = NULL;
#ifdef WHEELSU
iswheelsu =
#endif /* WHEELSU */
asme = asthem = fastlogin = 0;
- while ((ch = getopt(argc, argv, ARGSTR)) != EOF)
+ user = "root";
+ while(optind < argc)
+ if((ch = getopt(argc, argv, ARGSTR)) != EOF)
switch((char)ch) {
#ifdef KERBEROS
case 'K':
@@ -121,9 +121,24 @@ main(argc, argv)
case '?':
default:
(void)fprintf(stderr, "usage: su [%s] [login]\n",
- ARGSTR);
+ ARGSTR);
exit(1);
- }
+ }
+ else
+ {
+ user = argv[optind++];
+ break;
+ }
+
+ if((nargv = malloc (sizeof (char *) * (argc + 4))) == NULL) {
+ errx(1, "malloc failure");
+ }
+
+ nargv[argc + 3] = NULL;
+ for (i = argc; i >= optind; i--)
+ nargv[i + 3] = argv[i];
+ np = &nargv[i + 3];
+
argv += optind;
errno = 0;
@@ -153,7 +168,6 @@ main(argc, argv)
}
/* get target login information, default to root */
- user = *argv ? *argv : "root";
if ((pwd = getpwnam(user)) == NULL) {
errx(1, "unknown login: %s", user);
}
OpenPOWER on IntegriCloud