*BSD News Article 24688


Return to BSD News archive

Newsgroups: comp.os.386bsd.questions
Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!agate!headwall.Stanford.EDU!kithrup.com!sef
From: sef@kithrup.com (Sean Eric Fagan)
Subject: Re: "su" for one command
Organization: Kithrup Enterprises, Ltd.
References: <2dkb8a$hoq@sylvester.cc.utexas.edu> <JKH.93Dec3011102@whisker.lotus.ie> <CHH55F.8KI@twwells.com>
Message-ID: <CHH9tF.FJt@kithrup.com>
Date: Fri, 3 Dec 1993 21:17:25 GMT
Lines: 85

In article <CHH55F.8KI@twwells.com> bill@twwells.com (T. William Wells) writes:
>Speaking as an irked user who was bitten by the very same gotcha:
>Improvements I can understand, but just dropping a feature? Why?
>Please don't cite POSIX. That may be a reason but it is certainly
>no excuse! Any reason to not retrofit the old behavior on the new
>su? If it's not happening somewhere else, I'll probably do it
>myself.

I'm not sure why it was done, and I don't know where my .2 is, so I can't
look at it.

To execute a single command as another user via su, you can do:

	echo command args | su user

Or you can apply these patches to su; they pass all arguments after the
user to the shell, thus allowing "su user -c foo" to work.

*** su.c.~1~	Tue Feb 25 09:55:04 1992
--- su.c	Sat Mar 27 22:43:31 1993
***************
*** 64,69 ****
--- 64,75 ----
  #define	ARGSTR	"-flm"
  #endif
  
+ #ifdef CRYPT
+ extern char *crypt();
+ #else
+ # define crypt(a,b) (a)
+ #endif
+ 
  main(argc, argv)
  	int argc;
  	char **argv;
***************
*** 76,87 ****
  	uid_t ruid, getuid();
  	int asme, ch, asthem, fastlogin, prio;
  	enum { UNSET, YES, NO } iscsh = UNSET;
! 	char *user, *shell, *username, *cleanenv[2], *nargv[4], **np;
  	char shellbuf[MAXPATHLEN];
! 	char *crypt(), *getpass(), *getenv(), *getlogin(), *ontty();
  
- 	np = &nargv[3];
- 	*np-- = NULL;
  	asme = asthem = fastlogin = 0;
  	while ((ch = getopt(argc, argv, ARGSTR)) != EOF)
  		switch((char)ch) {
--- 82,91 ----
  	uid_t ruid, getuid();
  	int asme, ch, asthem, fastlogin, prio;
  	enum { UNSET, YES, NO } iscsh = UNSET;
! 	char *user, *shell, *username, *cleanenv[2], **np;
  	char shellbuf[MAXPATHLEN];
! 	char *getpass(), *getenv(), *getlogin(), *ontty();
  
  	asme = asthem = fastlogin = 0;
  	while ((ch = getopt(argc, argv, ARGSTR)) != EOF)
  		switch((char)ch) {
***************
*** 138,143 ****
--- 142,149 ----
  
  	/* get target login information, default to root */
  	user = *argv ? *argv : "root";
+ 	np = *argv ? argv : argv-1;
+ 
  	if ((pwd = getpwnam(user)) == NULL) {
  		fprintf(stderr, "su: unknown login %s\n", user);
  		exit(1);
***************
*** 163,173 ****
  		/* if target requires a password, verify it */
  		if (*pwd->pw_passwd) {
  			p = getpass("Password:");
- #ifdef DES
  			if (strcmp(pwd->pw_passwd, crypt(p, pwd->pw_passwd))) {
- #else
- 			if (strcmp(pwd->pw_passwd, p)) {
- #endif
  				fprintf(stderr, "Sorry\n");
  				syslog(LOG_AUTH|LOG_WARNING,
  					"BAD SU %s to %s%s", username,
--- 169,175 ----