LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   super user privileges check for a normal user in bash script (http://www.linuxquestions.org/questions/programming-9/super-user-privileges-check-for-a-normal-user-in-bash-script-659695/)

freeindy 08-01-2008 05:28 AM

super user privileges check for a normal user in bash script
 
Hi,

I want to check if a normal user has super user privileges. For example, I run a script as user bond:

Code:

bond $ ./run.sh
in my run.sh I want to find out if bond has super user privileges, i.e he/she can run sudo command.

Is it possible? Consider I can't read /etc/sudoers file. I don't wan't to ask for password and then fail. I just want to say:
"You don't have sudo privileges... aborting"

Thanks,
Indy

jcookeman 08-01-2008 06:03 AM

No you cannot do this. The problem is that anyone CAN run the sudo command, but until authentication it is not known what privileges they have. What you can do is grab the password and run a `CMD_LIST=$(echo $PASSWD | sudo -L -S)` and process the output and/or exit code to determine if they have necessary rights.

freeindy 08-01-2008 07:08 AM

ok.

that's a bummer, but not much one can do. Thanks jcookeman

Indy


All times are GMT -5. The time now is 12:06 AM.