Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 6 Sep 1995 19:16:08 -0500 (CDT)
From:      peter@taronga.com (Peter da Silva)
To:        jkh@time.cdrom.com
Cc:        hackers@freebsd.org
Subject:   Patches to "su" to restore "su user -c cmd"
Message-ID:  <199509070016.TAA02805@bonkers.taronga.com>

next in thread | raw e-mail | index | archive | help
I write:
> > In 1.1.5.1, the command "su" passed extra arguments to the shell. In 2.0.5,
> > this is disabled. Howcome? I have several scripts that need to start various
> > programs as particular users, so I've been using "su user -c command". What
> > is the recommended alternative?

Jordan writes:
> I commented on this just the other day.  What we need is `-c' to come
> back is what we need.

Here it is:

This is based on the 2.0.5 code. I compared the 1.1.5 code and the NetBSD
code.

The NetBSD/1.1.5.1 code, based on Net/2 I assume, was dated 1988:

 * Copyright (c) 1988 The Regents of the University of California.
 * All rights reserved.

There are minor differences between the two. It looks like the NetBSD
code depends on argv[-1] being there if you call "su -fm" which expands
into "_su -m -f". 

The 2.0.5 code seems to be based on 4.4:

 * Copyright (c) 1988, 1993, 1994
 *      The Regents of the University of California.  All rights reserved.

Changes forthwith, including a new man page:

*** su.1.ORIG	Wed Sep  6 19:09:12 1995
--- su.1	Wed Sep  6 19:08:06 1995
***************
*** 40,46 ****
  .Sh SYNOPSIS
  .Nm su
  .Op Fl Kflm
! .Op Ar login
  .Sh DESCRIPTION
  .Nm Su
  requests the Kerberos password for
--- 40,46 ----
  .Sh SYNOPSIS
  .Nm su
  .Op Fl Kflm
! .Op Ar login Op args
  .Sh DESCRIPTION
  .Nm Su
  requests the Kerberos password for
***************
*** 49,55 ****
  .Dq Ar login Ns .root ,
  if no login is provided), and switches to
  that user and group ID after obtaining a Kerberos ticket granting ticket.
! A shell is then executed.
  .Nm Su
  will resort to the local password file to find the password for
  .Ar login
--- 49,56 ----
  .Dq Ar login Ns .root ,
  if no login is provided), and switches to
  that user and group ID after obtaining a Kerberos ticket granting ticket.
! A shell is then executed, and any additional command line arguments after
! the login name are passed to this shell.
  .Nm Su
  will resort to the local password file to find the password for
  .Ar login
*** su.c.ORIG	Tue May 30 01:34:18 1995
--- su.c	Wed Sep  6 18:57:44 1995
***************
*** 82,98 ****
  {
  	extern char **environ;
  	struct passwd *pwd;
! 	char *p, **g, *user, *shell, *username, *cleanenv[20], *nargv[4], **np;
  	struct group *gr;
  	uid_t ruid;
  	int asme, ch, asthem, fastlogin, prio;
  	enum { UNSET, YES, NO } iscsh = UNSET;
  	char shellbuf[MAXPATHLEN];
  
- 	np = &nargv[3];
- 	*np-- = NULL;
  	asme = asthem = fastlogin = 0;
! 	while ((ch = getopt(argc, argv, ARGSTR)) != EOF)
  		switch((char)ch) {
  #ifdef KERBEROS
  		case 'K':
--- 82,98 ----
  {
  	extern char **environ;
  	struct passwd *pwd;
! 	char *p, **g, *user, *shell, *username, *cleanenv[20], **np;
  	struct group *gr;
  	uid_t ruid;
  	int asme, ch, asthem, fastlogin, prio;
  	enum { UNSET, YES, NO } iscsh = UNSET;
  	char shellbuf[MAXPATHLEN];
+ 	char **nargv;
+ 	int i;
  
  	asme = asthem = fastlogin = 0;
! 	while ((ch = getopt(argc, argv, ARGSTR)) != EOF) {
  		switch((char)ch) {
  #ifdef KERBEROS
  		case 'K':
***************
*** 117,123 ****
--- 117,144 ----
  			    ARGSTR);
  			exit(1);
  		}
+ 	}
  	argv += optind;
+ 	argc -= optind;
+ 
+ 	/* get target login information, default to root */
+ 	if (argc) {
+ 		user = *argv++;
+ 		--argc;
+ 	} else {
+ 		user = "root";
+ 	}
+ 
+ 	/* copy args */
+ 	nargv = malloc((sizeof *nargv) * (argc + 4));
+ 	if(!nargv) {
+ 		perror("su: malloc");
+ 		exit(1);
+ 	}
+ 
+ 	for(i = 0; i <= argc; i++)
+ 		nargv[i+3] = argv[i];
+ 	np = &nargv[2];
  
  	errno = 0;
  	prio = getpriority(PRIO_PROCESS, 0);
***************
*** 145,152 ****
  			iscsh = NO;
  		}
  
- 	/* 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);
--- 166,171 ----



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199509070016.TAA02805>