From ab753cc4ce9260ef1e1b7868e358fd77a8eb5b6a Mon Sep 17 00:00:00 2001 From: jmmv Date: Sun, 27 Apr 2003 08:46:25 +0000 Subject: [PATCH] Implement the `-d' option, which behaves as `-l' but does not change the current directory. Idea suggested by dsl@ in source-changes. --- usr.bin/su/su.1 | 10 +++++++--- usr.bin/su/su.c | 18 ++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/usr.bin/su/su.1 b/usr.bin/su/su.1 index c2d01714de59..89b6ec5c3767 100644 --- a/usr.bin/su/su.1 +++ b/usr.bin/su/su.1 @@ -30,9 +30,9 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)su.1 8.2 (Berkeley) 4/18/94 -.\" $NetBSD: su.1,v 1.30 2003/04/24 12:19:06 wiz Exp $ +.\" $NetBSD: su.1,v 1.31 2003/04/27 08:46:25 jmmv Exp $ .\" -.Dd April 20, 2003 +.Dd April 27, 2003 .Dt SU 1 .Os .Sh NAME @@ -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 @@ You may only override the default class if you're already root. 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 , diff --git a/usr.bin/su/su.c b/usr.bin/su/su.c index fe7c115036d9..22e97f5825be 100644 --- a/usr.bin/su/su.c +++ b/usr.bin/su/su.c @@ -1,4 +1,4 @@ -/* $NetBSD: su.c,v 1.53 2003/04/25 08:04:14 mycroft Exp $ */ +/* $NetBSD: su.c,v 1.54 2003/04/27 08:46:26 jmmv Exp $ */ /* * Copyright (c) 1988 The Regents of the University of California. @@ -44,7 +44,7 @@ __COPYRIGHT( #if 0 static char sccsid[] = "@(#)su.c 8.3 (Berkeley) 4/2/94";*/ #else -__RCSID("$NetBSD: su.c,v 1.53 2003/04/25 08:04:14 mycroft Exp $"); +__RCSID("$NetBSD: su.c,v 1.54 2003/04/27 08:46:26 jmmv Exp $"); #endif #endif /* not lint */ @@ -90,12 +90,12 @@ static int kerberos5 __P((char *, char *, int)); #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 @@ main(argc, argv) 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 @@ main(argc, argv) #endif asme = asthem = fastlogin = 0; + gohome = 1; shell = class = NULL; while ((ch = getopt(argc, argv, ARGSTR)) != -1) switch((char)ch) { @@ -151,6 +152,11 @@ main(argc, argv) class = optarg; break; #endif + case 'd': + asme = 0; + asthem = 1; + gohome = 0; + break; case 'f': fastlogin = 1; break; @@ -340,7 +346,7 @@ badlogin: #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"); }