Results 1 to 7 of 7

Thread: QProcess, communicate with 'su' command

  1. #1
    Join Date
    Sep 2008
    Posts
    43
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Exclamation QProcess, communicate with 'su' command

    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.
    Qt Code:
    1. checkRootPWDproc = new QProcess(this);
    2. checkRootPWDproc->start("su");
    3.  
    4. checkRootPWDproc->write(rootpwd);
    5. checkRootPWDproc->closeWriteChannel();
    6.  
    7. connect( checkRootPWDproc, SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(checkRootPWDprocFinished()));
    To copy to clipboard, switch view to plain text mode 
    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QProcess, communicate with 'su' command

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2008
    Posts
    43
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProcess, communicate with 'su' command

    ok.. how can i do this? it must be a method to write to "su" right?...

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QProcess, communicate with 'su' command

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2008
    Posts
    43
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProcess, communicate with 'su' command

    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?

  6. #6
    Join Date
    Oct 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QProcess, communicate with 'su' command

    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.

  7. #7
    Join Date
    Sep 2008
    Posts
    43
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProcess, communicate with 'su' command

    god ofcourse.. im so stupid sometimes

    ook ill read about PAM. thank you all xD

Similar Threads

  1. QProcess and the command line
    By auba in forum Qt Programming
    Replies: 17
    Last Post: 27th May 2009, 10:39
  2. Replies: 0
    Last Post: 28th February 2009, 23:18
  3. System Command QProcess
    By jd in forum Qt Programming
    Replies: 7
    Last Post: 10th February 2009, 17:36
  4. how to use cat command in QProcess
    By renjithmamman in forum Qt Programming
    Replies: 4
    Last Post: 27th January 2006, 18:46
  5. QProcess in a QThread
    By chombium in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2006, 15:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.