root launch
root launch
How do I know if a program is running as an administrator, superuser?
- NicTheQuick
- Addict
- Posts: 1519
- Joined: Sun Jun 22, 2003 7:43 pm
- Location: Germany, Saarbrücken
- Contact:
Re: root launch
There are four function you can use to get real and effective user and group IDs:
Here's an example output:
You can use `setuid_(uid)` to switch between the user with id 0 and 1000 (in this case), depending on what you want to do.
Code: Select all
OpenConsole()
PrintN("Real user ID: " + Str(getuid_()))
PrintN("Effective user ID: " + Str(geteuid_()))
PrintN("Real group ID: " + Str(getgid_()))
PrintN("Effective group ID: " + Str(getegid_()))
CloseConsole()
$ ./tmp/showuserid
Real user ID: 1000
Effective user ID: 1000
Real group ID: 1000
Effective group ID: 1000
And if the executable owner is root and the setuid bit is set it can look like this:$ sudo ./tmp/showuserid
[sudo] Passwort für nicolas:
Real user ID: 0
Effective user ID: 0
Real group ID: 0
Effective group ID: 0
In this case you can differentiate between the user that executed the program and the one who is the owner of the executable.$ sudo chown root:root tmp/showuserid
$ sudo chmod +s ./tmp/showuserid
$ ./tmp/showuserid
Real user ID: 1000
Effective user ID: 0
Real group ID: 1000
Effective group ID: 0
You can use `setuid_(uid)` to switch between the user with id 0 and 1000 (in this case), depending on what you want to do.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Re: root launch
Just what you need, thank you!