This section describes the functions for altering the group IDs (real and effective) of a process. To use these facilities, you must include the header files `sys/types.h' and `unistd.h'.
If the process is not privileged, then newgid must either be equal to the real group ID or the saved group ID. In this case, setgid
sets only the effective group ID and not the real group ID.
The return values and error conditions for setgid
are the same as those for setuid
.
-1
, it means not to change the real group ID; likewise if egid is -1
, it means not to change the effective group ID.
The setregid
function is provided for compatibility with 4.3 BSD Unix, which does not support saved IDs. You can use this function to swap the effective and real group IDs of the process. (Privileged processes are not limited to this usage.) If saved IDs are supported, you should use that feature instead of using this function. See Enable/Disable Setuid.
The return values and error conditions for setregid
are the same as those for setreuid
.
The GNU system also lets privileged processes change their supplementary group IDs. To use setgroups
or initgroups
, your programs should include the header file `grp.h'.
This function returns 0
if successful and -1
on error. The following errno
error conditions are defined for this function:
EPERM
initgroups
function effectively calls setgroups
to set the process's supplementary group IDs to be the normal default for the user name user. The group ID gid is also included.