Main index | Section 3 | Options |
#include <libcasper.h>
#include <casper/cap_sysctl.h>
CAP_SYSCTL_READ allow reads of the sysctl variable CAP_SYSCTL_WRITE allow writes of the sysctl variable CAP_SYSCTL_RDWR allow reads and writes of the sysctl variable CAP_RECURSIVE permit access to any child of the sysctl variable
The cap_sysctl_limit_name() function adds the sysctl identified by name to the limit list, and cap_sysctl_limit_mib() function adds the sysctl identified by mibp to the limit list. The access rights for the sysctl are specified in the flags parameter; at least one of CAP_SYSCTL_READ, CAP_SYSCTL_WRITE and CAP_SYSCTL_RDWR must be specified. cap_sysctl_limit() applies a set of sysctl limits to the capability, denying access to sysctl variables not belonging to the set. It consumes the limit handle. After either success or failure, the user must not access the handle again.
Once a set of limits is applied, subsequent calls to cap_sysctl_limit() will fail unless the new set is a subset of the current set.
cap_sysctlnametomib() will succeed so long as the named sysctl variable is present in the limit set, regardless of its access rights. When a sysctl variable name is added to a limit set, its MIB identifier is automatically added to the set.
cap_channel_t *capcas, *capsysctl; const char *name = "kern.trap_enotcap"; void *limit; size_t size; bool value;/* 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.sysctl service. */ capsysctl = cap_service_open(capcas, "system.sysctl"); if (capsysctl == NULL) err(1, "Unable to open system.sysctl service");
/* Close Casper capability, we don't need it anymore. */ cap_close(capcas);
/* Create limit for one MIB with read access only. */ limit = cap_sysctl_limit_init(capsysctl); (void)cap_sysctl_limit_name(limit, name, CAP_SYSCTL_READ);
/* Limit system.sysctl. */ if (cap_sysctl_limit(limit) < 0) err(1, "Unable to set limits");
/* Fetch value. */ size = sizeof(value); if (cap_sysctlbyname(capsysctl, name, &value, &size, NULL, 0) < 0) err(1, "Unable to get value of sysctl");
printf("The value of %s is %d. , name, value);
cap_close(capsysctl);
This manual page was written by Mariusz Zaborski <Mt oshogbo@FreeBSD.org>.
CAP_SYSCTL (3) | December 1, 2022 |
Main index | Section 3 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
“ | The Unix phenomenon is scary. It doesn't go away. | ” |
— Steve Ballmer |