Results 1 to 7 of 7

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

  1. #1
    Join Date
    Mar 2010
    Posts
    68
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Linux sudo and QT Gui Application. How to write a callback handler with QT?

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Linux sudo and QT Gui Application. How to write a callback handler with QT?

    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).

  3. #3
    Join Date
    Mar 2010
    Posts
    68
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Linux sudo and QT Gui Application. How to write a callback handler with QT?

    Quote Originally Posted by tbscope View Post
    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Linux sudo and QT Gui Application. How to write a callback handler with QT?

    You can use the -A or -S option, see the sudo manual

  5. #5
    Join Date
    Mar 2010
    Posts
    68
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Linux sudo and QT Gui Application. How to write a callback handler with QT?

    Quote Originally Posted by tbscope View Post
    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.
    Last edited by Kevin Hoang; 13th October 2010 at 06:59.

  6. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Linux sudo and QT Gui Application. How to write a callback handler with QT?

    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.

  7. #7
    Join Date
    Mar 2010
    Posts
    68
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Linux sudo and QT Gui Application. How to write a callback handler with QT?

    Quote Originally Posted by squidge View Post
    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?

Similar Threads

  1. QProcess::start() failed when application runs from sudo
    By alenyashka in forum Qt Programming
    Replies: 3
    Last Post: 22nd June 2010, 06:35
  2. Qt4 Gui application cannot write to file
    By flair-kun in forum Qt Programming
    Replies: 4
    Last Post: 19th December 2009, 09:21
  3. How to write correctly an event handler
    By franco.amato in forum Qt Programming
    Replies: 10
    Last Post: 3rd December 2009, 07:52
  4. Replies: 1
    Last Post: 13th November 2009, 18:40
  5. cleanup handler on application close
    By err23 in forum Qt Programming
    Replies: 3
    Last Post: 16th August 2006, 10:56

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.