COHERENT manpages
This page displays the COHERENT manpage for setgid() [Set group id and user id].
List of available manpages
Index
setgid() -- System Call (libc)
Set group id and user id
#include <unistd.h>
int setgid(id) int id;
The group identifier is the number that identifies the user group that
``owns'' a given file. File /etc/group establishes the set of groups that
your COHERENT system recognizes. (For details on how this file is laid
out, see the Lexicon entry for group). When a file is executable, the
executing process inherits its group identifier (and thus, its group-level
permissions) from the file in which it resides on disk. For example, the
program troff resides in file /bin/troff. This file is ``owned'' by group
bin; thus, when you execute troff, its group-level permissions are those of
group bin.
The group identifier comes in three forms:
real This is the group identifier of the user who is running the process.
effective
This is the group identifier that determines the access rights of the
process. These rights are the same as those of the real group
identifier unless they have been altered by executing a file whose
setgid bit is set. For example, the program troff does not have the
setgid bit set; thus, when you execute troff, the group permissions of
the troff process remain those of your group, not those of the group
bin. On the other hand, the program /usr/lib/uucp/uucico does have the
setgid bit set; thus, when you invoke uucico, the uucico process uses
the permissions of uucico's group (that is, of group uucp), instead of
your group.
saved effective
This permits a process to step back and forth between its real and
effective group identifiers. If you return from an effective group
identifier to your real one, the system saves the previously effective
identifier so you can revert to it if need be.
The system call setgid() lets you set the real and effective group
identifiers of the calling process to the group identifier gid. The
behavior of setgid() varies depending upon the following:
1. If setgid() is invoked by a user whose effective user identifier is that
of the superuser root, setgid() sets the real, effective, and saved
effective group identifiers to gid.
2. If setgid() is invoked by a user whose real group identifier is the same
as gid, setgid() sets the effective group identifier to gid.
3. If setgid() is invoked by a user whose saved effective group identifier
is same as gid, setgid() sets the effective group identifier to gid.
If all goes well, setgid() returns zero. If a problem arises, it returns
-1.
See Also
execution,
getuid(),
libc,
login,
setuid(),
unistd.h
POSIX Standard, §4.2.2



