From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26092 invoked from network); 16 Jun 1998 06:18:12 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 16 Jun 1998 06:18:12 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id CAA24835; Tue, 16 Jun 1998 02:13:58 -0400 (EDT) Resent-Date: Tue, 16 Jun 1998 02:13:58 -0400 (EDT) From: "Bart Schaefer" Message-Id: <980615231456.ZM7697@candle.brasslantern.com> Date: Mon, 15 Jun 1998 23:14:56 -0700 In-Reply-To: <199806151358.PAA13243@helena.mi.uni-erlangen.de> Comments: In reply to Martin Aumueller "Wrong emulation mode if exec'd by su" (Jun 15, 3:58pm) References: <199806151358.PAA13243@helena.mi.uni-erlangen.de> <199806151428.PAA10680@taos.demon.co.uk> <980615085238.ZM4667@candle.brasslantern.com> In-Reply-To: <980615085238.ZM4667@candle.brasslantern.com> Comments: In reply to "Bart Schaefer" "Re: Wrong emulation mode if exec'd by su" (Jun 15, 8:52am) X-Mailer: Z-Mail (5.0.0 30July97) To: zsh-workers@math.gatech.edu Subject: Re: Wrong emulation mode if exec'd by su Cc: aumuelle@mi.uni-erlangen.de MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"VYv953.0.-36.bqWXr"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/4127 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu On Jun 15, 3:58pm, Martin Aumueller wrote: } Subject: Wrong emulation mode if exec'd by su } } I have a problem with zsh-3.1.4: If I su - to an account the zsh sees } "su" as executable name -- starting with 's' -- and thus switches to } Bourne shell emulation mode, not the behaviour desired by me. I have } solved this problem by testing the full executable names against "sh", } "csh" and "ksh" with strcmp and now it works as I expect it. On Jun 15, 8:52am, Bart Schaefer wrote: } Subject: Re: Wrong emulation mode if exec'd by su } } However, the fix in the patch is the wrong one. Rather than looking for } every possible shell name in argv[0], the right thing would be to look } for "su" in argv[0], before testing the first letter for emulation, and } in that case do the emulation test on the value of $SHELL rather than on } argv[0]. Here's the promised patch. This avoids changing emulate() at all; rather, it checks argv[0] against "su" in main() before deciding what to pass to emulate(), and if it matches then it uses zgetenv("SHELL") instead. Note that different implementations of "su" work differently; as far as I know they all run the target user's login shell on "su -", but some otherwise keep the calling user's current $SHELL and change only the uid, whereas others always run the shell of the target user. There's some extra code in here to failsafe in case $SHELL is not set or is empty, or in case it is set to (some path ending in) "su" (in which case we emulate sh). Tested by running ARGV0=su ./zsh. Index: Src/main.c =================================================================== --- main.c 1998/06/01 17:08:44 1.1.1.1 +++ main.c 1998/06/16 05:52:59 @@ -45,12 +45,24 @@ for (t = argv; *t; *t = metafy(*t, -1, META_ALLOC), t++); - if (!(zsh_name = strrchr(argv[0], '/'))) - zsh_name = argv[0]; - else - zsh_name++; - if (*zsh_name == '-') - zsh_name++; + zsh_name = argv[0]; + do { + char *arg0 = zsh_name; + if (!(zsh_name = strrchr(arg0, '/'))) + zsh_name = arg0; + else + zsh_name++; + if (*zsh_name == '-') + zsh_name++; + if (strcmp(zsh_name, "su") == 0) { + char *sh = zgetenv("SHELL"); + if (sh && *sh && arg0 != sh) + zsh_name = sh; + else + break; + } else + break; + } while (zsh_name); fdtable_size = OPEN_MAX; fdtable = zcalloc(fdtable_size); -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com