169 lines
4.2 KiB
HTML
169 lines
4.2 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of SETGID</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>SETGID</H1>
|
|
Section: Linux Programmer's Manual (2)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
setgid - set group identity
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>></B>
|
|
|
|
<BR>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/unistd.h">unistd.h</A>></B>
|
|
|
|
<P>
|
|
|
|
<B>int setgid(gid_t </B><I>gid</I><B>);</B>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
<B>setgid</B>()
|
|
|
|
sets the effective group ID of the calling process.
|
|
If the calling process is privileged (more precisely: has the
|
|
<B>CAP_SETGID</B>
|
|
|
|
capability in its user namespace),
|
|
the real GID and saved set-group-ID are also set.
|
|
<P>
|
|
|
|
Under Linux,
|
|
<B>setgid</B>()
|
|
|
|
is implemented like the POSIX version with the
|
|
<B>_POSIX_SAVED_IDS</B>
|
|
|
|
feature.
|
|
This allows a set-group-ID program that is not set-user-ID-root
|
|
to drop all of its group
|
|
privileges, do some un-privileged work, and then reengage the original
|
|
effective group ID in a secure manner.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success, zero is returned.
|
|
On error, -1 is returned, and
|
|
<I>errno</I>
|
|
|
|
is set appropriately.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="1"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
The group ID specified in
|
|
<I>gid</I>
|
|
|
|
is not valid in this user namespace.
|
|
<DT id="2"><B>EPERM</B>
|
|
|
|
<DD>
|
|
The calling process is not privileged (does not have the
|
|
<B>CAP_SETGID</B> capability in its user namespace), and
|
|
<I>gid</I>
|
|
|
|
does not match the real group ID or saved set-group-ID of
|
|
the calling process.
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2001, POSIX.1-2008, SVr4.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
The original Linux
|
|
<B>setgid</B>()
|
|
|
|
system call supported only 16-bit group IDs.
|
|
Subsequently, Linux 2.4 added
|
|
<B>setgid32</B>()
|
|
|
|
supporting 32-bit IDs.
|
|
The glibc
|
|
<B>setgid</B>()
|
|
|
|
wrapper function transparently deals with the variation across kernel versions.
|
|
|
|
<A NAME="lbAI"> </A>
|
|
<H3>C library/kernel differences</H3>
|
|
|
|
At the kernel level, user IDs and group IDs are a per-thread attribute.
|
|
However, POSIX requires that all threads in a process
|
|
share the same credentials.
|
|
The NPTL threading implementation handles the POSIX requirements by
|
|
providing wrapper functions for
|
|
the various system calls that change process UIDs and GIDs.
|
|
These wrapper functions (including the one for
|
|
<B>setgid</B>())
|
|
|
|
employ a signal-based technique to ensure
|
|
that when one thread changes credentials,
|
|
all of the other threads in the process also change their credentials.
|
|
For details, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+nptl">nptl</A></B>(7).
|
|
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+getgid">getgid</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+setegid">setegid</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+setregid">setregid</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+capabilities">capabilities</A></B>(7),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+credentials">credentials</A></B>(7),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+user_namespaces">user_namespaces</A></B>(7)
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="3"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="4"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="5"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="6"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="7"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="8"><A HREF="#lbAG">CONFORMING TO</A><DD>
|
|
<DT id="9"><A HREF="#lbAH">NOTES</A><DD>
|
|
<DL>
|
|
<DT id="10"><A HREF="#lbAI">C library/kernel differences</A><DD>
|
|
</DL>
|
|
<DT id="11"><A HREF="#lbAJ">SEE ALSO</A><DD>
|
|
<DT id="12"><A HREF="#lbAK">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:34 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|