The pythonic way equal to "whoami"

T

TheSaint

Hello,
I was trying to find out whose the program launcher, but os.environ['USER']
returns the user whom owns the desktop environment, regardless the program
is called by root.
I'd like to know it, so the program will run with the right privileges.

Is there any standard function on python, that will do it?
 
K

Kushal Kumaran

Hello,
I was trying to find out whose the program launcher, but os.environ['USER']
returns the user whom owns the desktop environment, regardless the program
is called by root.
I'd like to know it, so the program will run with the right privileges.

Is there any standard function on python, that will do it?

os.geteuid

You should consider using the access control mechanisms provided by
your OS to do this, though. If your program is readable by
unauthorized users, they can simply make a copy, and change as
desired.
 
T

TheSaint

Kushal said:
os.geteuid
This return 0 for *root* . I don't know if it's a standard for all distro.
Mine is Archlinux.
I'd just like to avoid error caused by wrong access by user
 
C

Christopher Head

This return 0 for *root* . I don't know if it's a standard for all
distro. Mine is Archlinux.
I'd just like to avoid error caused by wrong access by user

It is. Until Linux capabilities, EUID==0 used to be special-cased in the
kernel as being the test for binding to network ports <1024, bypassing
filesystem access control, changing the system time, and so on. Since
Linux caps, it's theoretically possible to use a different UID, but for
compatibility and convenience, as well as because PID 1 (/sbin/init) is
still invoked by the kernel as UID 0, everyone still does that.

Chris
 
N

Nobody

This return 0 for *root* . I don't know if it's a standard for all distro.

UID 0 is the "superuser". The name "root" is conventional, but it's the
EUID (effective UID) which is used in permission checks; the kernel
doesn't care about names.
 
T

TheSaint

Christopher said:
It is. Until Linux capabilities, EUID==0 used to be special-cased in the
kernel

Thank you all, I got a good learning *and* something to rememeber.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,891
Members
47,423
Latest member
henerygril

Latest Threads

Top