num = getuid()
num = getgid()
num = geteuid()
num = getegid()
var = getuser([user])
var = getgroup([group])
t/f = setuid([uid[,gid]])
The getuid() and geteuid() functions return the logged in or effective user id numbers, respectively. The getgid() and getegid() do the same with the real and effective group id numbers. If passed a user id number, the getuser() function returns a string with the name of that user. If given a name string it returns the id number of that user. The getgroup() function does the same, for a group name or number. If no argument is given, getuser() and getgroup() return the name of the logged in user or group.
The setuid() function allows a root user process to drop its privileges by setting the user and/or group to a non-zero value. The real, effective and saved user and group id's are all set to the specified values, so root privileges can not be regained. If the effective and real user are both root, any valid user and group number may be specified. Since this is effectively logging in the new user, the secondary group list is also re-initialized. If the program is SUID root and only the effective user is zero, only the real (logged in) user and group may be specified. If the uid and/or gid are omitted, or zero, the real user or group id will be used as default values. Returns true if successful, otherwise a null.
Security note: Although they may be linked from elsewhere, SUID root programs must be hard linked in either /sbin or /usr/sbin and both program and directory must be owned and writable only by root. Otherwise, the program will be immediately terminated. Thus, ordinary users cannot switch to any other user, except to root, using a properly authorized SUID program approved by the system administrator.