Hi all,
I am able to obtain the username from the environment variables with this code; Unfortunately it can be changed easily to misrepresent the logged in user.
?win32
Function getUserEnvName$()
Return getenv_("username")
End Function
?linux
Function getUserEnvName$()
Return getenv_("USER")
End Function
?
print "USERNAME: "+getUserEnvName()
Under Windows you can get the logged in user with a simple API call:
Local advapi32:Int = loadLibraryA( "advapi32.dll" )
Global __GetUserName:Int( ..
lpBuffer: Byte Ptr, ..
lpnSize: Byte Ptr ..
) "Win32" = GetProcAddress( advapi32, "GetUserNameA" )
Function getUserName$()
Local username:Byte[256]
Global size:Int = 256
If Not __GetUserName Then Return ""
If __GetUserName( username, Varptr( size ) ) Then
Return String.fromCString( username )
End If
Return ""
End Function
Print "USERNAME: " + getUserName()
... and I have found a Linux API getuid(), but I get a segmentation fault when I attempt to use it.
Any pointers on what I have missed?
Import "getuid.linux.c"
Extern "c"
Function getuid_$()
End Extern
Function getUserName$()
Return getuid_()
End Function
Print "USERNAME: " + getUserName()
getuid.linuc.c
#include <brl.mod/blitz.mod/blitz.h>
#include <sys/types.h>
#include <unistd.h>
BBString *getuid_( void ){
return bbStringFromUTF8String( getuid() );
}
|