Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to make a C++ program on Ubuntu that checks if a user can shutdown the PC, and, if so, shut it down for him.

So, I'm thinking about getting the user ID, and then, checking if, or if not, he has the rights to shut down the computer.

However, I really don't know what is the critera in Ubuntu that says if a user has such a right ... do you happen to know what this is ?

Thanks !

share|improve this question

1 Answer 1

up vote 0 down vote accepted

I think I've found the solution to my problem, so now I'm posting it.

Testing admin privileges can be done like so :

uid_t uid = getuid(), euid = geteuid();
if(uid < 0 || uid != euid) {
    // Can stop or reboot system
} else {
    // Cannot stop nor reboot system
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.