SETREGID(2)

πŸ’– SETREGID β€” set real and effective group ID πŸ’–

okay bestie, we're in the setregid(2) page, and it lives in section 2 of the System Calls Manual, so get comfy 🫢


✨ LIBRARY ✨

Standard C Library (libc, -lc) β€” she's a libc girlie, no cap πŸŽ€


🌸 SYNOPSIS 🌸

#include <unistd.h>

int
setregid(gid_t rgid, gid_t egid);

πŸ’… DESCRIPTION πŸ’…

So here's the tea: the real and effective group ID's of the current process get set to the arguments. That's the whole vibe. πŸ¦‹

And the way that if the real group ID is changed, the saved group ID also gets changed to the new value of the effective group ID. like they're matching, periodt.

Unprivileged users may change the real group ID to the effective group ID and vice-versa β€” that swap is allowed, bestie πŸ”„ only the super-user may make other changes. so if you're not root, don't even try it, it's giving EPERM.

Supplying a value of -1 for either the real or effective group ID forces the system to substitute the current ID in place of the -1 argument. lowkey a "keep it as is" cheat code ✨

🚨 history lesson that's also a warning: the setregid() system call was intended to allow swapping the real and effective group IDs in set-group-ID programs to temporarily relinquish the set-group-ID value. But β€” and I cannot stress this enough β€” this system call did not work correctly. 😭 its purpose is now better served by the use of the setegid(2) system call. so, like, use that one instead, fr fr.

When setting the real and effective group IDs to the same value, the standard setgid() system call is preferred. that's the move, that's the main character call πŸ‘‘


⭐ RETURN VALUES ⭐

The setregid() function returns the value 0 if successful 😌 otherwise the value -1 is returned and the global variable errno is set to indicate the error. classic. she tells you what went wrong through errno, so go read it πŸ’€


πŸ”₯ ERRORS πŸ”₯

  • [EPERM] β€” The current process is not the super-user and a change other than changing the effective group-id to the real group-id was specified. translation: you're not root and you tried to do something spicy πŸ™ˆ

🌈 SEE ALSO 🌈

getgid(2), issetugid(2), setegid(2), setgid(2), setuid(2) β€” go read the whole friend group, iykyk 🫢


πŸŽ€ HISTORY πŸŽ€

The setregid() system call appeared in 4.2BSD. an icon, an absolute legend, even if she's a lil broken πŸ’œ


and that's the whole page, bestie!! this one came from the Debian fam, dated April 16, 1994, and it's filed under SETREGID(2) βœ¨πŸ’– stay safe out there, use setegid(2), and don't forget your errno check πŸŒΈπŸ’…

πŸ“¦ where this page comes from