Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Admin privileges for script [duplicate]

how can i check admin-privileges for my script during running?

like image 457
Max Frai Avatar asked May 24 '26 23:05

Max Frai


2 Answers

The concept of "admin-privileges" in our day of fine grained privilege control is becoming hard to define. If you are running on unix with "traditional" access control model, getting the effective user id (available in os module) and checking that against root (0) could be what you are looking for. If you know accessing a file on the system requires the privileges you want your script to have, you can use the os.access() to check if you are privileged enough.

Unfortunately there is no easy nor portable method to give. You need to find out or define the security model used, what system provided APIs are available to query and set privileges and try to locate (or possibly implement yourself) the appropriate python modules that can be used to access the API.

The classic question, why do you need to find out? What if your script tries to do what it needs to do and "just" catches and properly handles failures?

like image 145
Marko Teiste Avatar answered May 27 '26 12:05

Marko Teiste


On Unix you can check whether you are root using the os.getuid function:

os.getuid() == 0 and "root" or "not root"
like image 35
Stephan202 Avatar answered May 27 '26 11:05

Stephan202



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!