SETRESUID(2)

✨ SETRESUID(2) ✨

okay bestie, so this one lives in the System Calls Manual and it's all about getresgid, getresuid, setresgid and setresuid β€” aka getting or setting your real, effective and saved user or group ID. yes it's four functions in one page, they're a package deal, we love a bundle πŸ’…


πŸ“š LIBRARY

Standard C Library (libc, -lc)

link it, love it, that's the vibe 🫢


🌸 SYNOPSIS

#include <sys/types.h>
#include <unistd.h>

int
getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid);

int
getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);

int
setresgid(gid_t rgid, gid_t egid, gid_t sgid);

int
setresuid(uid_t ruid, uid_t euid, uid_t suid);

πŸ’– DESCRIPTION

So the setresuid() system call sets the real, effective and saved user IDs of the current process. and its sibling setresgid()? same energy but for the real, effective and saved group IDs. slay, symmetrical queen πŸ‘‘

Privileged processes can set these IDs to literally any values they want, no questions asked β€” main character privileges fr fr. Unprivileged processes though? they're on a leash: each of the new IDs must match one of the current IDs. that's the rule, no cap.

Passing -1 as an argument means "leave this one alone bestie" β€” that corresponding value stays unchanged. iconic behaviour honestly πŸ™ˆ

And on the flip side, getresgid() and getresuid() retrieve the real, effective and saved group and user IDs of the current process, respectively. they're the readers, the setters set, the getters get, it's giving balance ✨


πŸ”₯ RETURN VALUES

If everything goes great: you get 0. clean. flawless. ate.

If it does NOT go great: you get -1 and the global variable errno gets set to tell you exactly what went wrong. πŸ’€


πŸŽ€ ERRORS

  • [EPERM] β€” the calling process was not privileged and tried to change one or more IDs to a value that wasn't the current real ID, the current effective ID, nor the current saved ID. so rude of it to even try 😭
  • [EFAULT] β€” an address passed to getresgid() or getresuid() was invalid. bad pointer, bad vibes, blocked 🚫

πŸ‘€ SEE ALSO

getegid(2), geteuid(2), getgid(2), getuid(2), issetugid(2), setgid(2), setregid(2), setreuid(2), setuid(2)

the whole ID-adjacent friend group, go say hi πŸ¦‹


🌈 HISTORY

These functions first appeared in HP-UX. old money, honestly πŸ‘‘


okay that's the whole page bestie, go forth and set your IDs responsibly 🫢 periodt πŸ’–βœ¨

this one's from the Debian crew, dated February 7, 2015 β€” mwah, thank you for your service, SETRESUID(2) forever πŸ’…πŸŒΈ
πŸ“¦ where this page comes from