Subject: su -d ?
To: None <tech-userlevel@netbsd.org>
From: Julio Merino <jmmv@menta.net>
List: tech-userlevel
Date: 04/26/2003 20:46:39
Hi all,

dsl@ suggested a -d option for the su command, that could behave as -l
but leaving the new shell in the same directory where su was called
(i.e., avoid switching to user's home directory).
I found it interesting, so here is a patch to do it:

Index: su.1
===================================================================
RCS file: /cvsroot/src/usr.bin/su/su.1,v
retrieving revision 1.30
diff -u -u -r1.30 su.1
--- su.1	2003/04/24 12:19:06	1.30
+++ su.1	2003/04/26 18:38:13
@@ -40,7 +40,7 @@
 .Nd substitute user identity
 .Sh SYNOPSIS
 .Nm
-.Op Fl Kflm
+.Op Fl Kdflm
 .Op Fl c Ar login-class
 .Op Ar login Op Ar "shell arguments"
 .Sh DESCRIPTION
@@ -100,6 +100,10 @@
 See
 .Xr login.conf 5
 for details.
+.It Fl d
+Same as
+.Fl l ,
+but does not change the current directory.
 .It Fl f
 If the invoked shell is
 .Xr csh 1 ,
Index: su.c
===================================================================
RCS file: /cvsroot/src/usr.bin/su/su.c,v
retrieving revision 1.53
diff -u -u -r1.53 su.c
--- su.c	2003/04/25 08:04:14	1.53
+++ su.c	2003/04/26 18:38:16
@@ -90,12 +90,12 @@
 
 #if defined(KERBEROS) || defined(KERBEROS5)
 
-#define	ARGSTRX	"-Kflm"
+#define	ARGSTRX	"-Kdflm"
 
 int use_kerberos = 1;
 
 #else
-#define	ARGSTRX	"-flm"
+#define	ARGSTRX	"-dflm"
 #endif
 
 #ifndef	SUGROUP
@@ -127,7 +127,7 @@
 	struct timeval tp;
 #endif
 	uid_t ruid;
-	int asme, ch, asthem, fastlogin, prio;
+	int asme, ch, asthem, fastlogin, prio, gohome;
 	enum { UNSET, YES, NO } iscsh = UNSET;
 	char *user, *shell, *avshell, *username, **np;
 	char *userpass, *class;
@@ -138,6 +138,7 @@
 #endif
 
 	asme = asthem = fastlogin = 0;
+	gohome = 1;
 	shell = class = NULL;
 	while ((ch = getopt(argc, argv, ARGSTR)) != -1)
 		switch((char)ch) {
@@ -151,6 +152,11 @@
 			class = optarg;
 			break;
 #endif
+		case 'd':
+			asme = 0;
+			asthem = 1;
+			gohome = 0;
+			break;
 		case 'f':
 			fastlogin = 1;
 			break;
@@ -340,7 +346,7 @@
 #endif
 			if (p)
 				(void)setenv("TERM", p, 1);
-			if (chdir(pwd->pw_dir) < 0)
+			if (gohome && chdir(pwd->pw_dir) < 0)
 				errx(1, "no directory");
 		} 
 
Any objection to do this?

Thanks.

-- 
Julio M. Merino Vidal <jmmv@menta.net>
The NetBSD Project - http://www.NetBSD.org/