Page 1 of 1

root launch

Posted: Sun Oct 20, 2024 10:30 am
by rndrei
How do I know if a program is running as an administrator, superuser?

Re: root launch

Posted: Sun Oct 20, 2024 12:27 pm
by NicTheQuick
There are four function you can use to get real and effective user and group IDs:

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()
Here's an example output:
$ ./tmp/showuserid
Real user ID: 1000
Effective user ID: 1000
Real group ID: 1000
Effective group ID: 1000
$ sudo ./tmp/showuserid
[sudo] Passwort für nicolas:
Real user ID: 0
Effective user ID: 0
Real group ID: 0
Effective group ID: 0
And if the executable owner is root and the setuid bit is set it can look like this:
$ 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
In this case you can differentiate between the user that executed the program and the one who is the owner of the executable.
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.

Re: root launch

Posted: Sun Oct 20, 2024 2:12 pm
by rndrei
Just what you need, thank you!