[Mono-bugs] [Bug 653564] New: Erroneous value returned by Environment.UserName when running as root with su
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Mon Nov 15 05:36:00 EST 2010
https://bugzilla.novell.com/show_bug.cgi?id=653564
https://bugzilla.novell.com/show_bug.cgi?id=653564#c0
Summary: Erroneous value returned by Environment.UserName when
running as root with su
Classification: Mono
Product: Mono: Class Libraries
Version: 2.8.x
Platform: All
OS/Version: openSUSE 11.3
Status: NEW
Severity: Major
Priority: P5 - None
Component: CORLIB
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: djechelon at fastwebnet.it
QAContact: mono-bugs at lists.ximian.com
Found By: ---
Blocker: ---
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; it; rv:1.9.2.12)
Gecko/20101026 SUSE/3.6.12-1.2 Firefox/3.6.12
Hello,
I wanted to implement a simple root check in C# for console programs.
I tried to get the System.Environment.UserName value, but I found that it
doesn't always return what I expect when running the program after privileges
elevation (the recommended practice instead than logging in as root in the
first place)
If I run the program logging with elevated privileges using sudo, I get the
correct value, but if I first perform su and then run the program, I get my
regular user's name.
Reproducible: Always
Steps to Reproduce:
Play with the following code:
public static void Main (string[] args)
{
Console.WriteLine ("I am: {0}",Environment.UserName);
}
Actual Results:
djechelon at MONSTR:~/Mono/Hello/Whoami/bin/Debug> mono Whoami.exe
I am: djechelon #CORRECT
djechelon at MONSTR:~/Mono/Hello/Whoami/bin/Debug> sudo mono Whoami.exe
root's password:
I am: root #CORRECT
djechelon at MONSTR:~/Mono/Hello/Whoami/bin/Debug> su
Password:
MONSTR:/home/djechelon/Mono/Hello/Whoami/bin/Debug # mono Whoami.exe
I am: djechelon #WRONG
Expected Results:
djechelon in the first run, root in the others
A possible workaround may involve the usage of whoami command with Process
class
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the mono-bugs
mailing list