CAP_GRP(3)
π¦ CAP_GRP(3) β group database operations in capability mode, bestie β¨
okay so this is CAP_GRP(3) from the Library Functions Manual, and itβs literally your guide to doing group database stuff while living that capability-mode life. itβs giving βI need group info but make it sandboxedβ π
β¨ NAME β¨
cap_getgrent, cap_getgrnam, cap_getgrgid, cap_getgrent_r, cap_getgrnam_r, cap_getgrgid_r, cap_setgroupent, cap_setgrent, cap_endgrent, cap_grp_limit_cmds, cap_grp_limit_fields, cap_grp_limit_groups β library for group database operations in capability mode π
π LIBRARY π
library βlibcap_grpβ
πΈ SYNOPSIS πΈ
#include <sys/nv.h>
#include <libcasper.h>
#include <casper/cap_grp.h>
struct group *
cap_getgrent(cap_channel_t *chan);
struct group *
cap_getgrnam(cap_channel_t *chan, const char *name);
struct group *
cap_getgrgid(cap_channel_t *chan, gid_t gid);
int
cap_getgrent_r(cap_channel_t *chan, struct group *grp, char *buffer,
size_t bufsize, struct group **result);
int
cap_getgrnam_r(cap_channel_t *chan, const char *name, struct group *grp,
char *buffer, size_t bufsize, struct group **result);
int
cap_getgrgid_r(cap_channel_t *chan, gid_t gid, struct group *grp,
char *buffer, size_t bufsize, struct group **result);
int
cap_setgroupent(cap_channel_t *chan, int stayopen);
int
cap_setgrent(cap_channel_t *chan);
void
cap_endgrent(cap_channel_t *chan);
int
cap_grp_limit_cmds(cap_channel_t *chan, const char * const *cmds,
size_t ncmds);
int
cap_grp_limit_fields(cap_channel_t *chan, const char * const *fields,
size_t nfields);
int
cap_grp_limit_groups(cap_channel_t *chan, const char * const *names,
size_t nnames, const gid_t *gids, size_t ngids);
π DESCRIPTION π
bestie, the glow-up here is simple: cap_getgrent(), cap_getgrnam(), cap_getgrgid(), cap_getgrent_r(), cap_getgrnam_r(), cap_getgrgid_r(), cap_setgroupent(), cap_setgrent(), and cap_endgrent() are respectively equivalent to getgrent(3), getgrnam(3), getgrgid(3), getgrent_r(3), getgrnam_r(3), getgrgid_r(3), setgroupent(3), setgrent(3), and endgrent(3) β except that the connection to the system.grp service needs to be provided. periodt π«Ά
cap_grp_limit_cmds()β this one limits the functions allowed in the service. thecmdsvariable can be set togetgrent,getgrnam,getgrgid,getgrent_r,getgrnam_r,getgrgid_r,setgroupent,setgrent, orendgrent, which will allow you to use the function associated with the name. thencmdsvariable contains the number ofcmdsprovided. πcap_grp_limit_fields()β this lets you limit fields returned in thestruct group. thefieldsvariable can be set togr_name,gr_passwd,gr_gid, orgr_mem. the field which was set as the limit will be returned, while the rest of the values not set this way will have default values. thenfieldsvariable contains the number of fields provided. πΈcap_grp_limit_groups()β this one lets you limit access to groups. thenamesvariable allows limiting groups by name, and thegidsvariable allows limiting by the group number. thennamesandngidsvariables provide numbers of limited names and gids. π
and listen: all of these functions are reentrant but not thread-safe. that is, they may be called from separate threads only with different cap_channel_t arguments or with synchronization. no cap, donβt ignore that part π
π§ EXAMPLES π§
the following example first opens a capability to casper and then uses this capability to create the system.grp casper service and uses it to get a group name. itβs iconic, honestly:
cap_channel_t *capcas, *capgrp;
const char *cmds[] = { "getgrgid" };
const char *fields[] = { "gr_name" };
const gid_t gid[] = { 1 };
struct group *group;
/* Open capability to Casper. */
capcas = cap_init();
if (capcas == NULL)
err(1, "Unable to contact Casper");
/* Enter capability mode sandbox. */
if (cap_enter() < 0 && errno != ENOSYS)
err(1, "Unable to enter capability mode");
/* Use Casper capability to create capability to the system.grp service. */
capgrp = cap_service_open(capcas, "system.grp");
if (capgrp == NULL)
err(1, "Unable to open system.grp service");
/* Close Casper capability, we don't need it anymore. */
cap_close(capcas);
/* Limit service to one single function. */
if (cap_grp_limit_cmds(capgrp, cmds, nitems(cmds)))
err(1, "Unable to limit access to system.grp service");
/* Limit service to one field as we only need name of the group. */
if (cap_grp_limit_fields(capgrp, fields, nitems(fields)))
err(1, "Unable to limit access to system.grp service");
/* Limit service to one gid. */
if (cap_grp_limit_groups(capgrp, NULL, 0, gid, nitems(gid)))
err(1, "Unable to limit access to system.grp service");
group = cap_getgrgid(capgrp, gid[0]);
if (group == NULL)
err(1, "Unable to get name of group");
printf("GID %d is associated with name %s.\n", gid[0], group->gr_name);
cap_close(capgrp);
π₯ SEE ALSO π₯
cap_enter(2)endgrent(3)err(3)getgrent(3)getgrent_r(3)getgrgid(3)getgrgid_r(3)getgrnam(3)getgrnam_r(3)setgrent(3)setgroupent(3)capsicum(4)nv(9)
π HISTORY π
the cap_grp service first appeared in FreeBSD 10.3. throwback era π«
π AUTHORS π
the cap_grp service was implemented by Pawel Jakub Dawidek <pawel@dawidek.net> under sponsorship from the FreeBSD Foundation.
this manual page was written by Mariusz Zaborski <oshogbo@FreeBSD.org>.
Debian source, December 6, 2023, CAP_GRP(3) β thatβs the footer info bestie, mwah πβ¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2018 Mariusz Zaborski <oshogbo@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms