Results 1 to 8 of 8

Thread: Acquire root privileges for QFile

  1. #1
    Join Date
    Feb 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Acquire root privileges for QFile

    I'm using QFile to read/write /dev/cpu/X/msr, however ring0 is required. QFile is being called from a separate QThread.

    Is there a way to escalate either QFile to root privileges, or maybe start a QThread as root?

    I can run the entire application as root using sudo or gksudo, however this is not desired since not all situations require read/write to msr.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Acquire root privileges for QFile

    If it is Linux that you are referring to then you could read the capabilities man page as a way to give you program 'limited' superuser abilities.

  3. #3
    Join Date
    Feb 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Acquire root privileges for QFile

    Quote Originally Posted by ChrisW67 View Post
    If it is Linux that you are referring to then you could read the capabilities man page as a way to give you program 'limited' superuser abilities.
    Thanks for the suggestion. Doesn't this require the application to be executed with superuser privileges already?

    I modified my QT Creator run script to include 'sudo' so that the application is run as superuser, however the debugger does not attach to it (since it tries to attach to 'sudo', and rightfully so.) Short of running QT Creator as root, is there at least any way I can debug a root application?

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

    Default Re: Acquire root privileges for QFile

    The best way would be to get your application to use PAM, then you can request root privileges. If you are using KDE or Gnome, then they typically have there own method of doing this that pops up a nice window asking the user to enter their password.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Acquire root privileges for QFile

    I have not done this in anger but I don't think you should not need to run the whole application as root. You will need to use setpcap as root to attach allowable capabilities to the executable file and your file system(s) have to support storing these also. The whole topic of capabilities in Linux seems a bit murky.

    Another approach would be to write a separate process that can be spun-off using sudo (without password) or marked setuid (or even setgid) to do just the privileged writing on your behalf either as a daemon or a one-off execution. You need to be very careful of abuse though.

  6. #6
    Join Date
    Feb 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Acquire root privileges for QFile

    I messed around with attaching capabilities using setpcap this morning, however none of them would 'take' unless the app was run as root to begin with. After reading more about the capability stuff, it looks like it's a way to trim down root applications so they can be allowed to do only what they need to as root, and not with every single perk that comes along with running as root. If this is true, it still requires the application to be executed as root (maybe someone familiar with this can correct me!)

    I've never used PAM, how well does QT integrate with it?

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Acquire root privileges for QFile

    You should be able to access PAM from any C/C++ code: Qt does not interface to PAM in any way I can see. Exactly which PAM module is going to fix this problem for you is a mystery to me: perhaps squidge knows?

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

    Default Re: Acquire root privileges for QFile

    I was thinking of starting the application as a standard user and then using PAM to request the root password and request privilege escalation. It's entirely possible that I'm mixing my words and/or talking crap. I just remember doing it somehow

Similar Threads

  1. Installing Qt without root privileges
    By mpele in forum Installation and Deployment
    Replies: 2
    Last Post: 13th August 2009, 09:49
  2. Running an application with root privileges at Linux
    By prykHetQuo in forum Qt Programming
    Replies: 5
    Last Post: 25th January 2009, 12:35
  3. Nokia to acquire Trolltech
    By GreyGeek in forum General Discussion
    Replies: 14
    Last Post: 18th June 2008, 19:58
  4. Installing and running Qt4 without root privileges
    By sunil.thaha in forum Installation and Deployment
    Replies: 1
    Last Post: 10th October 2007, 14:04
  5. Dynamically getting root privileges for an app
    By fullmetalcoder in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2007, 10:26

Tags for this Thread

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.