PDA

View Full Version : How to run command that need root privileges?



leon.vitanos
June 20th, 2011, 05:39 PM
Hi! I run a simple command at c++ like this:


if(system("COMMAND HERE`"))
cerr << "Error while trying to use command 'COMMAND' into the specified folder! Check folder's permissions etc.\n";But how to run a command that needs root privileges?
Probably i should show an Authentication Dialog like this:


pkexec echoI don't know.. :???:

leon.vitanos
June 20th, 2011, 06:47 PM
Ok i found it.. It is gksudo! :D

Petrolea
June 20th, 2011, 10:32 PM
Ok i found it.. It is gksudo! :D

If you want it to execute the program as root all by itself, without a password prompt you could echo the password and use a pipe to transfer it to your program.

lavinog
June 21st, 2011, 07:14 AM
If you want it to execute the program as root all by itself, without a password prompt you could echo the password and use a pipe to transfer it to your program.

That is generally a bad idea.
Even if the program gets compiled, you can usually extract strings.

Also, root passwords should be changed every now and then, which would mean that you would have to keep your application up to date...to do that you need to keep the source code available...in plain text :eek: