308 lines
7.5 KiB
HTML
308 lines
7.5 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of SETREUID</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>SETREUID</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"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
setreuid, setregid - set real and/or effective user or group ID
|
|
<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 setreuid(uid_t </B><I>ruid</I><B>, uid_t </B><I>euid</I><B>);</B>
|
|
|
|
<BR>
|
|
|
|
<B>int setregid(gid_t </B><I>rgid</I><B>, 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>setreuid</B>(),
|
|
|
|
<B>setregid</B>():
|
|
|
|
<DL COMPACT><DT id="1"><DD>
|
|
|
|
_XOPEN_SOURCE >= 500
|
|
|
|
<BR> || /* Since glibc 2.19: */ _DEFAULT_SOURCE
|
|
<BR> || /* Glibc versions <= 2.19: */ _BSD_SOURCE
|
|
|
|
</DL>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
<B>setreuid</B>()
|
|
|
|
sets real and effective user IDs of the calling process.
|
|
<P>
|
|
|
|
Supplying a value of -1 for either the real or effective user ID forces
|
|
the system to leave that ID unchanged.
|
|
<P>
|
|
|
|
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>
|
|
|
|
Unprivileged users may only set the real user ID to
|
|
the real user ID or the effective user ID.
|
|
<P>
|
|
|
|
If the real user ID is set (i.e.,
|
|
<I>ruid</I>
|
|
|
|
is not -1) or the effective user ID is set to a value
|
|
not equal to the previous real user ID,
|
|
the saved set-user-ID will be set to the new effective user ID.
|
|
<P>
|
|
|
|
Completely analogously,
|
|
<B>setregid</B>()
|
|
|
|
sets real and effective group ID's of the calling process,
|
|
and all of the above holds with "group" instead of "user".
|
|
<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.
|
|
<P>
|
|
|
|
<I>Note</I>:
|
|
|
|
there are cases where
|
|
<B>setreuid</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>setreuid</B>().
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="2"><B>EAGAIN</B>
|
|
|
|
<DD>
|
|
The call would change the caller's real UID (i.e.,
|
|
<I>ruid</I>
|
|
|
|
does not match the caller's real UID),
|
|
but there was a temporary failure allocating the
|
|
necessary kernel data structures.
|
|
<DT id="3"><B>EAGAIN</B>
|
|
|
|
<DD>
|
|
<I>ruid</I>
|
|
|
|
does not match the caller's real UID and this call would
|
|
bring the number of processes belonging to the real user ID
|
|
<I>ruid</I>
|
|
|
|
over the caller's
|
|
<B>RLIMIT_NPROC</B>
|
|
|
|
resource limit.
|
|
Since Linux 3.1, this error case no longer occurs
|
|
(but robust applications should check for this error);
|
|
see the description of
|
|
<B>EAGAIN</B>
|
|
|
|
in
|
|
<B><A HREF="/cgi-bin/man/man2html?2+execve">execve</A></B>(2).
|
|
|
|
<DT id="4"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
One or more of the target user or group IDs
|
|
is not valid in this user namespace.
|
|
<DT id="5"><B>EPERM</B>
|
|
|
|
<DD>
|
|
The calling process is not privileged
|
|
(on Linux, does not have the necessary capability in its user namespace:
|
|
<B>CAP_SETUID</B>
|
|
|
|
in the case of
|
|
<B>setreuid</B>(),
|
|
|
|
or
|
|
<B>CAP_SETGID</B>
|
|
|
|
in the case of
|
|
<B>setregid</B>())
|
|
|
|
and a change other than (i)
|
|
swapping the effective user (group) ID with the real user (group) ID,
|
|
or (ii) setting one to the value of the other or (iii) setting the
|
|
effective user (group) ID to the value of the
|
|
saved set-user-ID (saved set-group-ID) was specified.
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2001, POSIX.1-2008, 4.3BSD
|
|
(<B>setreuid</B>()
|
|
|
|
and
|
|
<B>setregid</B>()
|
|
|
|
first appeared in 4.2BSD).
|
|
<A NAME="lbAH"> </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).
|
|
<P>
|
|
|
|
POSIX.1 does not specify all of the UID changes that Linux permits
|
|
for an unprivileged process.
|
|
For
|
|
<B>setreuid</B>(),
|
|
|
|
the effective user ID can be made the same as the
|
|
real user ID or the saved set-user-ID,
|
|
and it is unspecified whether unprivileged processes may set the
|
|
real user ID to the real user ID, the effective user ID, or the
|
|
saved set-user-ID.
|
|
For
|
|
<B>setregid</B>(),
|
|
|
|
the real group ID can be changed to the value of the saved set-group-ID,
|
|
and the effective group ID can be changed to the value of
|
|
the real group ID or the saved set-group-ID.
|
|
The precise details of what ID changes are permitted vary
|
|
across implementations.
|
|
<P>
|
|
|
|
POSIX.1 makes no specification about the effect of these calls
|
|
on the saved set-user-ID and saved set-group-ID.
|
|
<P>
|
|
|
|
The original Linux
|
|
<B>setreuid</B>()
|
|
|
|
and
|
|
<B>setregid</B>()
|
|
|
|
system calls supported only 16-bit user and group IDs.
|
|
Subsequently, Linux 2.4 added
|
|
<B>setreuid32</B>()
|
|
|
|
and
|
|
<B>setregid32</B>(),
|
|
|
|
supporting 32-bit IDs.
|
|
The glibc
|
|
<B>setreuid</B>()
|
|
|
|
and
|
|
<B>setregid</B>()
|
|
|
|
wrapper functions transparently deal with the variations 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 those for
|
|
<B>setreuid</B>()
|
|
|
|
and
|
|
<B>setregid</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+getuid">getuid</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+seteuid">seteuid</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+setgid">setgid</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+setresuid">setresuid</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"> </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="6"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="7"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="8"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="9"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="10"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="11"><A HREF="#lbAG">CONFORMING TO</A><DD>
|
|
<DT id="12"><A HREF="#lbAH">NOTES</A><DD>
|
|
<DL>
|
|
<DT id="13"><A HREF="#lbAI">C library/kernel differences</A><DD>
|
|
</DL>
|
|
<DT id="14"><A HREF="#lbAJ">SEE ALSO</A><DD>
|
|
<DT id="15"><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>
|