PDA

View Full Version : Linux sudo and QT Gui Application. How to write a callback handler with QT?



Kevin Hoang
13th October 2010, 04:40
I have a QT Gui Program run on Linux at KDE environment. My program must be run as root or sudo permission to check hardware information (such as read /dev/sda) or turn power off, etc. And, some tasks in my program cannot be done with root account due to security problem.

So I want my program run as user account with sudo permission set on that account, each time the program require permission, it show a dialogBox to enter the password and continue.

How may I do this on QT? How to write a callback handler with QT?

tbscope
13th October 2010, 04:44
That is not easy. Are you sure sudo takes input from external processes? I think that's a security issue.

However, you can edit the sudoers config file and make it so that certain users do not have to enter a password (also a security issue of course).

Kevin Hoang
13th October 2010, 04:53
That is not easy. Are you sure sudo takes input from external processes? I think that's a security issue.

However, you can edit the sudoers config file and make it so that certain users do not have to enter a password (also a security issue of course).

I have configured as you said, but it does not success in a GUI program.
I want users MUST enter a password to continue due to security requires.

tbscope
13th October 2010, 05:37
You can use the -A or -S option, see the sudo manual

Kevin Hoang
13th October 2010, 06:18
You can use the -A or -S option, see the sudo manual

do you mean this command: echo password | sudo -S ?

This only works if I run program in terminal, else no terminal to echo the password. And, sudo -A command require a sudo ask pass program.

squidge
13th October 2010, 13:28
You should ask the user for the password and provide it to the PAM library which will authenticate your process and give SU priviledges.

KDE also has a library for authentication so your application can request SU.

Both methods of beyond the scope of this forum.

Kevin Hoang
14th October 2010, 13:19
You should ask the user for the password and provide it to the PAM library which will authenticate your process and give SU priviledges.

KDE also has a library for authentication so your application can request SU.

Both methods of beyond the scope of this forum.

Can you help me an example how to use PAM in this case?