Results 1 to 8 of 8

Thread: Escalating Privileges

  1. #1
    manekineko Guest

    Red face Escalating Privileges

    I'm asking in another thread on how to setup my application to catch and handle mailto links clicked through a browser or elsewhere in the system.

    Presumably, whatever the answer is to that is going to require system level access, which would mean a UAC dialog pop up on Vista/Windows 7 or the equivalent on Linux and OSX. What's the best way to setup an application to request a privilege escalation?

    Overall, there's no reason for my email program to always be running as administrator, and in fact that'd obviously be a horrible idea. However, when a dialog box pops up asking whether the user wants to set it as the default email program, I'm guessing it would be necessary at that time to escalate privileges. How can this be done?

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

    Default Re: Escalating Privileges

    I think on Linux you have to deal with PolicyKit or some equivalent. And you can always use some IPC mechanism to communicate with a process that has the required privileges to fill the job for you.
    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. The following user says thank you to wysota for this useful post:


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

    Default Re: Escalating Privileges

    Have you read the official documentation yet?

    http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

  5. The following user says thank you to squidge for this useful post:


  6. #4
    manekineko Guest

    Default

    Quote Originally Posted by fatjuicymole View Post
    Have you read the official documentation yet?

    http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx
    Well, that's for setting the start menu link, not the mailto handler, but I get your point.

    I was really hoping there would be a cross platform way to do these tasks, but it looks like for both of these I'm going to have to use a lot of #ifdefs and searching through platform specific documentation.

    Quote Originally Posted by wysota View Post
    I think on Linux you have to deal with PolicyKit or some equivalent. And you can always use some IPC mechanism to communicate with a process that has the required privileges to fill the job for you.
    When you say communicate with a process that has the required privileges, is this normally handled by having a second executable that is somehow marked as requiring privilege escalation that is called whenever escalation is needed to perform the escalated task?
    Last edited by wysota; 13th November 2009 at 11:17.

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

    Default Re: Escalating Privileges

    Quote Originally Posted by manekineko View Post
    When you say communicate with a process that has the required privileges, is this normally handled by having a second executable that is somehow marked as requiring privilege escalation that is called whenever escalation is needed to perform the escalated task?
    There has to be a process with required privileges (like running as root or some other user that has required rights) that you order to do some task for you. I think that is also how PolicyKit works. In Unix world there is no way to grant any rights to an already running process, you can only revoke them.
    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.


  8. The following user says thank you to wysota for this useful post:


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

    Default Re: Escalating Privileges

    Quote Originally Posted by manekineko View Post
    Well, that's for setting the start menu link, not the mailto handler, but I get your point.
    Once your in the start menu, you are registered as the default application. Therefore it will include the mailto: handler, as that just uses the default application.

  10. #7
    manekineko Guest

    Default Re: Escalating Privileges

    I've been peering at the Windows documentation out there, and I cannot believe how difficult it is to escalate within a program.

    It seems like I have two choices:
    1) Use COM objects (I don't even really know what those are) and somehow integrate them into my QT program (if even possible), which can spawn a new process that's running at elevated privileges.
    2) Create a second QT executable, and somehow (not sure if this is even possible) bundle a manifest file inside of it, or if that's not possible, sit a manifest file next to it in the same directory. This manifest file will mark the executable as requiring elevated privileges, and I'll call this second executable using a new QProcess.

    The first option sounds preferable, as it avoids detracting from the user experience by dumping unnecessary extra files all over the program directory, but it sounds much harder. The second option sounds real ugly, but it'll get the job done.

    Does this sound about right? Has anyone here ever actually made a QT program compatible with UAC who can share how they did it with me?

    Thanks in advance.

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

    Default Re: Escalating Privileges

    Create a second QT executable, and somehow (not sure if this is even possible) bundle a manifest file inside of it, or if that's not possible, sit a manifest file next to it in the same directory. This manifest file will mark the executable as requiring elevated privileges, and I'll call this second executable using a new QProcess.
    I have some good news, and some not so good.
    • Yes, bundling a manifest requesting elevate privileges is possible. I do it for a program that grabs a hardware ID (Vista fakes the MAC address for user accounts).
    • Spawning the program requesting elevation is hit-and-miss

    The second point needs explanation. In my testing the unprivileged program could launch the privileged one if the user was a Vista administrator and could obtain an admin credential. If the user is a Vista unprivileged user then the attempt to execute the executable that requests escalation would silently fail regardless of the fact that the user could manually run it and be prompted for escalation. I also found that it mattered which method you used to launch the app: shell execute vs CreateProcess (although I cannot remember which worked best). In the end I opted to direct the user to manually run the program.

    Another approach for you might be to install a Windows service running with elevated privileges and talk to that from user-land to have your will done. This is how many background update processes are done I expect.

  12. The following user says thank you to ChrisW67 for this useful post:


Similar Threads

  1. Installing Qt without root privileges
    By mpele in forum Installation and Deployment
    Replies: 2
    Last Post: 13th August 2009, 10:49
  2. Running an application with root privileges at Linux
    By prykHetQuo in forum Qt Programming
    Replies: 5
    Last Post: 25th January 2009, 13:35
  3. Installing and running Qt4 without root privileges
    By sunil.thaha in forum Installation and Deployment
    Replies: 1
    Last Post: 10th October 2007, 15:04
  4. Dynamically getting root privileges for an app
    By fullmetalcoder in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2007, 11:26

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
  •  
Qt is a trademark of The Qt Company.