How do you programmatically (in a C program) query the real and effective UIDs /GIDs? Here are the system calls to do so:
#include <unistd.h>#include <sys/types.h>uid_t getuid(void);uid_t geteuid(void);gid_t getgid(void);gid_t getegid(void);
This is pretty straightforward:
- getuid(2) returns the real UID; geteuid(2) returns the effective UID
- getgid(2) returns the real GID; getegid(2) returns the effective GID
- uid_t and gid_t are glibc typedefs for an unsigned integer
Here is a neat tip to figure out the typedef for any given data type: you will need to know the header file that contains the definition. Just do this:
$ echo | gcc -E -xc -include 'sys/types.h' - | grep uid_t
typedef unsigned int __uid_t; ...