Results 1 to 7 of 7

Thread: Finding user permissions

  1. #1
    Join Date
    Jun 2009
    Posts
    66
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Finding user permissions

    Hi All,

    Does anyone know of any QT class which could be used to find out what permissions the user running the program has (ie, are they an Administrator in Windows, or Root user on Linux).

    If not a QT class, does anyone know how you would do this pragmatically on either OS's.

    cheers,

    David

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

    Default Re: Finding user permissions

    Linux is easy, just call getuid() and/or geteuid(). "0" means the user is root (or that the application is suid root in the second case).
    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 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Finding user permissions

    I know Windows stores the user id in an environment variable, but you shouldn't depend on it for security reasons since it can be overwritten by any application.

  4. #4
    Join Date
    Jun 2009
    Posts
    66
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Finding user permissions

    Hey wysota,

    Thanks for that info on linux. What if the software is installed in a user's home directory, so they have privileges to run it, but aren't root. Any idea what to do then?

    David

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

    Default Re: Finding user permissions

    What do you need that information for? If the software is executing (as you want to do something from within the program), the user obviously has rights to execute it... For arbitrary files there is QFileInfo::isExecutable().
    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.


  6. #6
    Join Date
    Jun 2009
    Posts
    66
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Finding user permissions

    I don't need it in linux and solaris anymore. What i wanted was to know whether i had permission to execute a given file from within my program, depending on who i was logged in as, and where I was. On Windows I always needed to be Admin user.

    All is good now

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

    Default Re: Finding user permissions

    Couldn't you just try and execute the file and if you get an error you obviously didn't have permission?

Similar Threads

  1. Logging Qt User Actions
    By Frank J. Lhota in forum Qt Programming
    Replies: 14
    Last Post: 30th May 2014, 22:36
  2. qmake DESTDIR permissions behavior (Unix)
    By wdezell in forum Qt Tools
    Replies: 3
    Last Post: 9th March 2009, 15:59
  3. Replies: 2
    Last Post: 27th November 2008, 11:16
  4. Replies: 3
    Last Post: 11th September 2008, 21:08
  5. linking user space and kernel space programs with qmake
    By zielchri in forum Qt Programming
    Replies: 9
    Last Post: 9th March 2006, 00:11

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.