PDA

View Full Version : Finding user permissions



doggrant
19th October 2009, 16:47
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

wysota
20th October 2009, 00:06
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).

squidge
20th October 2009, 08:06
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.

doggrant
20th October 2009, 15:55
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

wysota
20th October 2009, 16:59
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().

doggrant
22nd October 2009, 14:56
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 :)

squidge
22nd October 2009, 19:05
Couldn't you just try and execute the file and if you get an error you obviously didn't have permission?