Page 1 of 1

Is User a member of administrators group

Posted: Mon Dec 08, 2014 11:38 pm
by danielheth
is there a way to tell if the user running my program is an administrator or not? On windows i simply call IsUserAdmin_(), but looking for the linux equivalent...

Re: Is User a member of administrators group

Posted: Tue Dec 09, 2014 9:25 am
by idle
Not sure but you could try to write a file to a directory that requires root access

Code: Select all

Procedure IsUserAdmin_()
  Protected rand.l,file.s 
  rand = Random($FFFFFF)
  file.s = MD5Fingerprint(@rand,4) 
  
  If CreateFile(0,"/etc/"+file) 
    CloseFile(0) 
    DeleteFile("/etc/"+file)
    ProcedureReturn 1 
  EndIf 
EndProcedure 

Debug IsUserAdmin_()

Re: Is User a member of administrators group

Posted: Tue Dec 09, 2014 9:40 am
by Vera
Hi,
this might be what you're looking for:

Code: Select all

Debug "group-id of current user: " +Str(getgid_())
Source: Shows group-id of current user
Please see Oma's http://www.chabba.de/LinuxAPI.html /Misc for more


@idle ~ I like solutions like yours :-)

greets ~ Vera

Re: Is User a member of administrators group

Posted: Tue Dec 09, 2014 2:41 pm
by Shardik
danielheth wrote:On windows i simply call IsUserAdmin_(), but looking for the linux equivalent...
The equivalent in Linux is getuid_() or geteuid_():
http://www.purebasic.fr/english/viewtop ... 64&start=1
http://www.purebasic.fr/german/viewtopi ... 39&start=3