From owner-freebsd-questions@FreeBSD.ORG Fri Oct 31 19:17:14 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D372F106567C for ; Fri, 31 Oct 2008 19:17:14 +0000 (UTC) (envelope-from cswiger@mac.com) Received: from asmtpout013.mac.com (asmtpout013.mac.com [17.148.16.88]) by mx1.freebsd.org (Postfix) with ESMTP id C0EF48FC22 for ; Fri, 31 Oct 2008 19:17:14 +0000 (UTC) (envelope-from cswiger@mac.com) MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes Received: from cswiger1.apple.com ([17.227.140.124]) by asmtp013.mac.com (Sun Java(tm) System Messaging Server 6.3-7.03 (built Aug 7 2008; 32bit)) with ESMTPSA id <0K9M006LWAWCM970@asmtp013.mac.com> for freebsd-questions@freebsd.org; Fri, 31 Oct 2008 12:17:01 -0700 (PDT) Message-id: <198CF2A0-D783-4B64-AC34-DAAA3B8E8DD7@mac.com> From: Chuck Swiger To: =?ISO-8859-1?Q?Fr=E9d=E9ric_Perrin?= In-reply-to: <86mygklilz.fsf@chameau.maisel.enst-bretagne.fr> Content-transfer-encoding: quoted-printable Date: Fri, 31 Oct 2008 12:17:00 -0700 References: <86mygklilz.fsf@chameau.maisel.enst-bretagne.fr> X-Mailer: Apple Mail (2.929.2) Cc: freebsd-questions@freebsd.org Subject: Re: Behaviour of su(1) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Oct 2008 19:17:14 -0000 Hi-- On Oct 31, 2008, at 11:33 AM, Fr=E9d=E9ric Perrin wrote: > When I =AB su - =BB to root (after being logged in as my normal user), = the > LOGNAME env variable is still set to my previous user, as in : > > ,---- > | fred@chameau:~% /usr/bin/su -l > | Password: > | root@chameau:~# echo $USER - $LOGNAME > | root - fred > `---- > > As far as I can tell, this contradicts the fine manual that says : > > ,---- > | -l Simulate a full login. The environment is discarded =20 > except for > | HOME, SHELL, PATH, TERM, and USER. > `---- > > So I would have expected LOGNAME to be either empty or set by some =20 > shell > startup script to be root. So, why is LOGNAME still equal to my =20 > previous > user ? (and where is it set ? =AB grep -r LOGNAME /etc =BB doesn't = turn up > anything...) When you "su -l" it invokes /usr/bin/login, which per "man login" sets =20= up up $LOGNAME: The login utility enters information into the environment (see environ(7)) specifying the user's home directory (HOME), command =20= inter- preter (SHELL), search path (PATH), terminal type (TERM) and =20 user name (both LOGNAME and USER). I believe it looks up the actual username from the wtmp record =20 associated with your open tty, so $USER corresponds to the effective =20 userid, but $LOGNAME corresponds to the actual username used to login, =20= aka your "real userid"...? Regards, --=20 -Chuck