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 πŸ“œ: the setreuid() 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 the seteuid(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 0 if successful ✨ (slay, we love a zero)
  • otherwise the value -1 is returned and the global variable errno is 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 at seteuid(2). and if both IDs are going to the same value, just use setuid(). 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