On Wed, Apr 02, 2014 at 10:23:48AM +0100, Peter Stephenson wrote:
On Tue, 01 Apr 2014 16:22:39 -0500 Erik Johnson <palehose@xxxxxxxxx> wrote:When using "su - username" to change users, zsh is not properly setting the LOGNAME environment variable on FreeBSD. Example below. erik@virtubsd:~% zsh --version zsh 5.0.2 (amd64-portbld-freebsd9.1) erik@virtubsd:~% su - root Password: virtubsd# echo $LOGNAME erikFrom the code, it looks like this would only happen if getlogin() is returning the wrong thing, i.e. "erik", or it's not returning anything and the shell is having to guess and doing so wrongly. Although that doesn't seem very likely it's hard to see another way this can happen within the shell. Presumably python -c 'import os; print os.getlogin()' prints "root"? It might also be useful to start the shell with the "-x" option to check all the initialisation scripts. I'm not sure you can do that with su without some fiddling but you could put "set -x" temporarily at the top of /etc/zshenv. pws
Python os.getlogin() does indeed show "erik" instead of "root". So this may just be a difference between glibc and BSD libc. Either way, it "just works" in bash, sh, csh, tcsh, and ksh, as can be seen below, so I believe there is an argument for making it work properly in FreeBSD as well, or at the very least adding some wording to the zshparam manpage which makes this difference in behavior clear. erik@virtubsd:~% sudo chpass -s /bin/sh root Password: chpass: user information updated # erik@virtubsd:~% su - Password: # python2 -c 'import getpass; print getpass.getuser()' root # ^D% # erik@virtubsd:~% sudo chpass -s /usr/local/bin/bash root chpass: user information updated [root@virtubsd ~]# python2 -c 'import getpass; print getpass.getuser()' root [root@virtubsd ~]# logout erik@virtubsd:~% sudo chpass -s /bin/tcsh root chpass: user information updated erik@virtubsd:~% su - Password: virtubsd# python2 -c 'import getpass; print getpass.getuser()' root virtubsd# logout erik@virtubsd:~% sudo chpass -s /usr/local/bin/ksh93 root Password: chpass: user information updated erik@virtubsd:~% su - Password: # python2 -c 'import getpass; print getpass.getuser()' root # ^D erik@virtubsd:~% sudo chpass -s /usr/local/bin/zsh root chpass: user information updated erik@virtubsd:~% su - Password: virtubsd# python2 -c 'import getpass; print getpass.getuser()' erik -- -Erik "For me, it is far better to grasp the universe as it really is than to persist in delusion, however satisfying and reassuring." --Carl Sagan
Attachment:
pgpsxBayBK7q_.pgp
Description: PGP signature