PDA

View Full Version : QProcess, communicate with 'su' command



Mystical Groovy
20th October 2009, 00:56
Hey all,

i created a dialog(similar to kdesu) that asks for root's password before running my application. my idea was simple:
i connect my ok btn in a new slot and the "su" command process is executed.


checkRootPWDproc = new QProcess(this);
checkRootPWDproc->start("su");

checkRootPWDproc->write(rootpwd);
checkRootPWDproc->closeWriteChannel();

connect( checkRootPWDproc, SIGNAL(finished(int,QProcess::ExitStatus)),this,SL OT(checkRootPWDprocFinished()));

where rootpwd = tha root password that user entered in my qlineedit box at the dialog.

in the "checkRootPWDprocFinished()" slot the idea is to do some error checking and check if root password is correct blah blah blah but for completing the qprocess side of thinks ive just wrote a simple "exit(1)" :)

so with the above code the thing i want to do is when the su command is executed, it prompts for a password, so i use the write() function to write the user-given password and then close the writechannel and w8 for the command to finish.

the application compiles ok but when i enter the root pwd and press "ok" that application does nothing! (it doesnt even terminate as it supposed to be with 'exit(1);')...

so.. please help :)

wysota
20th October 2009, 01:10
As far as I remember su accesses the terminal directly, so writing to its stdin won't do anything, it simply doesn't read it.

Mystical Groovy
20th October 2009, 11:53
ok.. how can i do this? it must be a method to write to "su" right?...

wysota
20th October 2009, 11:57
KDE is Open Source, you know :)

In essence most if not all modern Linux distros use PAM for authentication so you can probably use libpam somehow to obtain your goal.

Mystical Groovy
20th October 2009, 13:28
hey and thx for your answer...

basically I dont want to get into PAM and just use 'su' with qprocess to do it.
is there any other simple way to do it using QProcess?

Steven
20th October 2009, 13:34
You do understand that when the commmand completes and the process finishes that all the priviledges gained for that process will be lost? Ie, they will not apply to your process.

To obtain the priviledges for the running app you have to use PAM.

Mystical Groovy
20th October 2009, 13:40
god ofcourse.. im so stupid sometimes :(

ook ill read about PAM. thank you all xD