Closed ghost closed 11 years ago
Please consider this patch to make the script more reliable:
1109a1110
NAME=
whoami
1113c1114< <---->if [ ! "$LOGNAME" == "root" ]; then
<---->if [ ! "$NAME" == "root" ]; then 1115c1116
< <----><------><------>echo "$LOGNAME (as user)"
<----><------><------>echo "$NAME (as user)" 1118c1119
< <----><------><------>echo "$LOGNAME (non-root)"
<----><------><------>echo "$NAME (non-root)"
sry. that is better:
1109a1110
NAME=
whoami
1113c1114< if [ ! "$LOGNAME" == "root" ]; then
if [ ! "$NAME" == "root" ]; then
1115c1116
< echo "$LOGNAME (as user)"
echo "$NAME (as user)"
1118c1119
< echo "$LOGNAME (non-root)"
echo "$NAME (non-root)"
LGNAME=whoami
I don't understand. I am getting this on Gentoo
~» su -c 'echo $LOGNAME'
Password:
root
And the same on a 10.04 Ubuntu system. Can you check whether you are getting root as the answer on Arch? It would be quite strange if Arch is not setting this variable to root. According to the wiki it is a really old unix construct.
EDIT Be careful with those quotes I used - please use only single quotes and not double quotes.
Can you also let me know what output you get for this command on Arch? Then we can perhaps make a different patch.
su -c 'echo $UID'
It gives me 0.
su -c 'echo $LOGNAME'
gives me my user name. Not root.
Thanks for the replies. After some thought, I think I will take your advice and just change LOGNAME
. I have emailed upstream morlenxus, so hopefully he will also implement this change.
Fixed in cdad61f
see manual for SU !
man su
For backward compatibility su defaults to not change the current directory and to only set the environment variables HOME and SHELL (plus USER and LOGNAME IF THE TARGET USER IS NOT ROOT)
last line is an explanation.
Hi, there!
Please change the script. It's broken by initial design.
It won't run by sued user. It's a wrong idea to check original login name.
On Archlinux variable $LOGNAME is giving original name after doing su.
So the whoami is the only right working command.