su equivalent
Hi,
I want to write a program that should be run only as root. However, I don't want it to exit if the program sees that its uid != 0.
This is similar to running things under "kdesu" for example. My (console) program should determine if its not running as root. Then it prompts the user for the root password, and finally elevates to root permissions.
I'm confused regarding how to do this. Essentially I want to do "su -c my_algorithm" in my program. My basic question is:
1) What is the accepted way to ask the user for the root password? (getpass() ?)
2) Now that I have the password, how to I verify that its the proper password?
3) How do I change my permissions to root? (I can't simply do a setuid(0) right?)
Thanks in advance :-)
~Raj
|