SETREUID(2)
π SETREUID(2) β the setreuid system call, from the System Calls Manual π
okay bestie, sit down, hydrate, because we're talking about user IDs and honestly? it's giving identity crisis but make it kernel-level. this one lives in section 2 of the manual (that's the system calls girlies), and yes it's a whole vibe.
β¨ NAME β¨
setreuid β set real and effective user ID's π«Ά
π LIBRARY π
Standard C Library (libc, -lc) β yeah she's in libc, we been knew π
πΈ SYNOPSIS πΈ
#include <unistd.h>
int
setreuid(uid_t ruid, uid_t euid);
two args, both uid_t, returns an int, no notes, she's simple like that β¨
π« DESCRIPTION π«
so here's the tea π: the real and effective user IDs of the current process get set according to the arguments you pass in. that's it, that's the whole job.
if ruid or euid is -1, the system is like "say less" and just fills in the current uid for you. cute. very "i got you bestie" of it.
now the permissions part, listen up π β unprivileged users may change the real user ID to the effective user ID and vice-versa. that's the swap. that's the whole allowed move. only the super-user may make other changes. periodt.
and here's a lil detail people always forget π β if the real user ID is changed (i.e. ruid is not -1) or the effective user ID is changed to something other than the real user ID, then the saved user ID will be set to the effective user ID. keep that in your notes fr fr.
historical lore drop π: thesetreuid()system call has been used to swap the real and effective user IDs in set-user-ID programs to temporarily relinquish the set-user-ID value. but bestieβ¦ this purpose is now better served by the use of theseteuid(2)system call. so like, upgrade your code, i'm begging π
and one more thing: when you're setting the real and effective user IDs to the same value, the standard setuid() system call is preferred. yes, the plain one. don't be extra, setuid() ate and left no crumbs π
π RETURN VALUES π
- returns the value
0if successful β¨ (slay, we love a zero) - otherwise the value
-1is returned and the global variableerrnois set to indicate the error π (it's giving something went wrong and she's telling you why)
π¨ ERRORS π¨
[EPERM]β the current process is not the super-user and a change other than changing the effective user-id to the real user-id was specified. basically: you're not the super-user and you tried something spicy πΆοΈ and the kernel said no. respectfully.
π¦ SEE ALSO π¦
go read the whole friend group, they're all connected iykyk π₯
β HISTORY β
the setreuid() system call appeared in 4.2BSD. ancient. iconic. still here. the main character energy is unmatched π
reminder bestie: this is a system call, so it's not playing around. if you're unprivileged, you get the swap and nothing else. if you want to drop privileges temporarily in a set-user-ID program, go look atseteuid(2). and if both IDs are going to the same value, just usesetuid(). no cap π
and that's the page, babe π§ this one came from the Debian crew, dated February 8, 2001, and it's been living rent-free in section 2 ever since. love that for her. mwah π«Άπ
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1980, 1991, 1993, 1994 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms