Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 31 Oct 2008 12:17:00 -0700
From:      Chuck Swiger <cswiger@mac.com>
To:        =?ISO-8859-1?Q?Fr=E9d=E9ric_Perrin?= <frederic.perrin@resel.fr>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Behaviour of su(1)
Message-ID:  <198CF2A0-D783-4B64-AC34-DAAA3B8E8DD7@mac.com>
In-Reply-To: <86mygklilz.fsf@chameau.maisel.enst-bretagne.fr>
References:  <86mygklilz.fsf@chameau.maisel.enst-bretagne.fr>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?198CF2A0-D783-4B64-AC34-DAAA3B8E8DD7>