man-pages/man2/seteuid.2.html
2021-03-31 01:06:50 +01:00

242 lines
5.4 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of SETEUID</TITLE>
</HEAD><BODY>
<H1>SETEUID</H1>
Section: Linux Programmer's Manual (2)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
seteuid, setegid - set effective user or group ID
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>&gt;</B>
<BR>
<B>#include &lt;<A HREF="file:///usr/include/unistd.h">unistd.h</A>&gt;</B>
<P>
<B>int seteuid(uid_t </B><I>euid</I><B>);</B>
<BR>
<B>int setegid(gid_t </B><I>egid</I><B>);</B>
<P>
Feature Test Macro Requirements for glibc (see
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
<P>
<B>seteuid</B>(),
<B>setegid</B>():
<DL COMPACT><DT id="1"><DD>
_POSIX_C_SOURCE&nbsp;&gt;=&nbsp;200112L
<BR>&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;/*&nbsp;Glibc&nbsp;versions&nbsp;&lt;=&nbsp;2.19:&nbsp;*/&nbsp;_BSD_SOURCE
</DL>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<B>seteuid</B>()
sets the effective user ID of the calling process.
Unprivileged processes may only set the effective user ID to the
real user ID, the effective user ID or the saved set-user-ID.
<P>
Precisely the same holds for
<B>setegid</B>()
with &quot;group&quot; instead of &quot;user&quot;.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success, zero is returned.
On error, -1 is returned, and
<I>errno</I>
is set appropriately.
<P>
<I>Note</I>:
there are cases where
<B>seteuid</B>()
can fail even when the caller is UID 0;
it is a grave security error to omit checking for a failure return from
<B>seteuid</B>().
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="2"><B>EINVAL</B>
<DD>
The target user or group ID is not valid in this user namespace.
<DT id="3"><B>EPERM</B>
<DD>
In the case of
<B>seteuid</B>():
the calling process is not privileged (does not have the
<B>CAP_SETUID</B>
capability in its user namespace) and
<I>euid</I>
does not match the current real user ID, current effective user ID,
or current saved set-user-ID.
<DT id="4"><DD>
In the case of
<B>setegid</B>():
the calling process is not privileged (does not have the
<B>CAP_SETGID</B>
capability in its user namespace) and
<I>egid</I>
does not match the current real group ID, current effective group ID,
or current saved set-group-ID.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>CONFORMING TO</H2>
POSIX.1-2001, POSIX.1-2008, 4.3BSD.
<A NAME="lbAH">&nbsp;</A>
<H2>NOTES</H2>
Setting the effective user (group) ID to the
saved set-user-ID (saved set-group-ID) is
possible since Linux 1.1.37 (1.1.38).
On an arbitrary system one should check
<B>_POSIX_SAVED_IDS</B>.
<P>
Under glibc 2.0,
<B>seteuid(</B><I>euid</I><B>)</B>
is equivalent to
<B>setreuid(-1,</B><I> euid</I><B>)</B>
and hence may change the saved set-user-ID.
Under glibc 2.1 and later, it is equivalent to
<B>setresuid(-1,</B><I> euid</I><B>, -1)</B>
and hence does not change the saved set-user-ID.
Analogous remarks hold for
<B>setegid</B>(),
with the difference that the change in implementation from
<B>setregid(-1,</B><I> egid</I><B>)</B>
to
<B>setresgid(-1,</B><I> egid</I><B>, -1)</B>
occurred in glibc 2.2 or 2.3 (depending on the hardware architecture).
<P>
According to POSIX.1,
<B>seteuid</B>()
(<B>setegid</B>())
need not permit
<I>euid</I>
(<I>egid</I>)
to be the same value as the current effective user (group) ID,
and some implementations do not permit this.
<A NAME="lbAI">&nbsp;</A>
<H3>C library/kernel differences</H3>
On Linux,
<B>seteuid</B>()
and
<B>setegid</B>()
are implemented as library functions that call, respectively,
<B><A HREF="/cgi-bin/man/man2html?2+setreuid">setreuid</A></B>(2)
and
<B><A HREF="/cgi-bin/man/man2html?2+setregid">setregid</A></B>(2).
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+geteuid">geteuid</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+setresuid">setresuid</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+setreuid">setreuid</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+setuid">setuid</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">&nbsp;</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">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="5"><A HREF="#lbAB">NAME</A><DD>
<DT id="6"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="7"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="8"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="9"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="10"><A HREF="#lbAG">CONFORMING TO</A><DD>
<DT id="11"><A HREF="#lbAH">NOTES</A><DD>
<DL>
<DT id="12"><A HREF="#lbAI">C library/kernel differences</A><DD>
</DL>
<DT id="13"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="14"><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>