SETGROUPS(2)
π SETGROUPS(2) π
okay bestie, we're in the System Calls Manual today and the vibe is group access lists. yes this is a <sys/...> girlie. yes she's a syscall. let's get into it π«Ά
β¨ NAME β¨
setgroups β set the group access list. that's it, that's the whole job π
π LIBRARY π
Standard C Library (libc, -lc). the classic. the moment. π
π¦ SYNOPSIS π¦
#include <sys/param.h>
#include <unistd.h>
int
setgroups(int ngroups, const gid_t *gidset);
πΈ DESCRIPTION πΈ
so the setgroups() system call sets the group access list of the current user process according to the array gidset. like, it rewrites the whole group situation. slay.
the ngroups argument tells you how many entries are in that array β and bestie, it must be no more than {NGROUPS_MAX}+1. no cap. don't test it. π
only the super-user may set a new group list. that's the rule. no super-user, no group list. periodt.
now this next part is important, so lean in π§:
the first entry of the group array β gidset[0] β is used as the effective group-ID for the process. it's the main character. π
but here's the tea: that entry gets over-written when a setgid program is run. π so to avoid losing access to the privileges of that gidset[0] entry, you should duplicate it later in the group array. by convention, this happens because the group value indicated in the password file also appears in /etc/group. so the group value in the password file gets placed in gidset[0], and then that same value gets added a second time when the /etc/group file is scanned to create the group set. iconic behaviour honestly.
β RETURN VALUES β
- the
setgroups()function returns the value0if successful π - otherwise the value
-1is returned and the global variableerrnois set to indicate the error π
π ERRORS π
the setgroups() system call will fail if:
[EPERM]β the caller is not the super-user. sorry babe, you don't have the range π[EINVAL]β the number specified in thengroupsargument is larger than the{NGROUPS_MAX}+1limit. too many groups, bestie. chill.[EFAULT]β the address specified forgidsetis outside the process address space. that pointer is literally not real π
π₯ SEE ALSO π₯
the squad π«Ά go read them, iykyk.
π HISTORY π
the setgroups() system call appeared in 4.2BSD. a true vintage queen. π
and that's the page!! this was Debian's version, dated January 19, 2018 β yes it's from SETGROUPS(2), yes she ate, no notes πβ¨ bye bestie, go set some groups (if you're root) π
π¦ 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) 1983, 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