diff options
Diffstat (limited to 'usr.bin/su')
| -rw-r--r-- | usr.bin/su/Makefile | 21 | ||||
| -rw-r--r-- | usr.bin/su/su.1 | 4 | ||||
| -rw-r--r-- | usr.bin/su/su.c | 75 |
3 files changed, 62 insertions, 38 deletions
diff --git a/usr.bin/su/Makefile b/usr.bin/su/Makefile index f86450c37c64..cdd63aa9050a 100644 --- a/usr.bin/su/Makefile +++ b/usr.bin/su/Makefile @@ -1,14 +1,19 @@ -# @(#)Makefile 5.5 (Berkeley) 5/11/90 - - -.if exists(/usr/lib/libcrypt.a) -#CFLAGS+=-DKERBEROS -DPADD+= ${LIBCRYPT} #${LIBKRB} -LDADD+= -lcrypt #-lkrb -.endif +# $Id: Makefile,v 1.8 1994/06/23 05:46:59 jkh Exp $ +# From: @(#)Makefile 5.5 (Berkeley) 5/11/90 PROG= su BINOWN= root BINMODE=4555 +.if exists(${DESTDIR}/usr/lib/libcrypt.a) +DPADD+= ${LIBCRYPT} +LDADD+= -lcrypt +.endif + +.if exists(${DESTDIR}/usr/lib/libkrb.a) +DPADD+= ${LIBKRB} ${LIBDES} +LDADD+= -lkrb -ldes +CFLAGS+= -DKERBEROS +.endif + .include <bsd.prog.mk> diff --git a/usr.bin/su/su.1 b/usr.bin/su/su.1 index e0de965bd1e4..5f80e085db38 100644 --- a/usr.bin/su/su.1 +++ b/usr.bin/su/su.1 @@ -41,7 +41,6 @@ .Nm su .Op Fl Kflm .Op Ar login -.Op Ar -c cmd .Sh DESCRIPTION .Nm Su requests the Kerberos password for @@ -120,9 +119,6 @@ and the caller's real uid is non-zero, .Nm su will fail. -.It Fl "c cmd" -Execute command as the nominated user. The user's shell is invoked -to execute the command. It is assumed that the shell supports a -c switch. .El .Pp The diff --git a/usr.bin/su/su.c b/usr.bin/su/su.c index 76648e65cb1d..fb24c15a549a 100644 --- a/usr.bin/su/su.c +++ b/usr.bin/su/su.c @@ -51,6 +51,7 @@ static char sccsid[] = "@(#)su.c 5.26 (Berkeley) 7/6/91"; #include <string.h> #include <unistd.h> #include <paths.h> +#include <stdlib.h> #ifdef KERBEROS #include <kerberosIV/des.h> @@ -76,39 +77,57 @@ main(argc, argv) uid_t ruid, getuid(); int asme, ch, asthem, fastlogin, prio; enum { UNSET, YES, NO } iscsh = UNSET; - char *user, *shell, *username, *cleanenv[20], *nargv[4], **np; + char *user, *shell, *username, *cleanenv[20], **nargv, **np; char shellbuf[MAXPATHLEN]; char avshellbuf[MAXPATHLEN]; char *crypt(), *getpass(), *getenv(), *getlogin(), *ontty(); + int i; - np = &nargv[3]; - *np-- = NULL; asme = asthem = fastlogin = 0; - while ((ch = getopt(argc, argv, ARGSTR)) != EOF) - switch((char)ch) { + + user = "root"; + while ( optind < argc ) + if ((ch = getopt(argc, argv, ARGSTR)) != EOF) + switch((char)ch) { #ifdef KERBEROS - case 'K': - use_kerberos = 0; - break; + case 'K': + use_kerberos = 0; + break; #endif - case 'f': - fastlogin = 1; - break; - case '-': - case 'l': - asme = 0; - asthem = 1; - break; - case 'm': - asme = 1; - asthem = 0; + case 'f': + fastlogin = 1; + break; + case '-': + case 'l': + asme = 0; + asthem = 1; + break; + case 'm': + asme = 1; + asthem = 0; + break; + case '?': + default: + (void)fprintf(stderr, "usage: su [%s] [login]\n", + ARGSTR); + exit(1); + } + else + { + user = argv[optind++]; break; - case '?': - default: - (void)fprintf(stderr, "usage: su [%s] [login]\n", - ARGSTR); - exit(1); } + + if ((nargv = malloc (sizeof (char *) * (argc + 4))) == NULL) { + (void)fprintf(stderr, "su: alloc failure\n" ); + exit(1); + } + + nargv[argc + 3] = NULL; + for (i = argc; i >= optind; i--) + nargv[i + 3] = argv[i]; + np = &nargv[i + 3]; + argv += optind; errno = 0; @@ -128,7 +147,12 @@ main(argc, argv) fprintf(stderr, "su: who are you?\n"); exit(1); } - username = strdup(pwd->pw_name); + if ((username = strdup(pwd->pw_name)) == NULL ) { + (void)fprintf(stderr, "su: alloc failure\n" ); + exit(1); + } + + if (asme) if (pwd->pw_shell && *pwd->pw_shell) shell = strcpy(shellbuf, pwd->pw_shell); @@ -138,7 +162,6 @@ main(argc, argv) } /* get target login information, default to root */ - user = *argv ? *argv : "root"; if ((pwd = getpwnam(user)) == NULL) { fprintf(stderr, "su: unknown login %s\n", user); exit(1); |
