1 .\" Copyright (c) 2018 Mariusz Zaborski <oshogbo@FreeBSD.org>
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .Nd "library for getting or setting system information in capability mode"
38 .In casper/cap_sysctl.h
40 .Fn cap_sysctlbyname "cap_channel_t *chan" " const char *name" " void *oldp" " size_t *oldlenp" " const void *newp" " size_t newlen"
46 except that the connection to the
48 service needs to be provided.
50 The service can be limited using
55 for that function can contain the following values and types:
56 .Bl -ohang -offset indent
57 .It ( NV_TYPE_NUMBER )
58 The name of the element with type number will be treated as the limited sysctl.
59 The value of the element will describe the access rights for given sysctl.
60 There are four different rights
62 .Dv CAP_SYSCTL_WRITE ,
65 .Dv CAP_SYSCTL_RECURSIVE .
68 flag allows to fetch the value of a given sysctl.
71 flag allows to override the value of a given sysctl.
78 and allows to read and write the value of a given sysctl.
80 .Dv CAP_SYSCTL_RECURSIVE
81 allows access to all children of a given sysctl.
82 This right must be combined with at least one other right.
84 The following example first opens a capability to casper and then uses this
85 capability to create the
87 casper service and uses it to get the value of
88 .Dv kern.trap_enotcap .
90 cap_channel_t *capcas, *capsysctl;
91 const char *name = "kern.trap_enotcap";
96 /* Open capability to Casper. */
99 err(1, "Unable to contact Casper");
101 /* Enter capability mode sandbox. */
102 if (cap_enter() < 0 && errno != ENOSYS)
103 err(1, "Unable to enter capability mode");
105 /* Use Casper capability to create capability to the system.sysctl service. */
106 capsysctl = cap_service_open(capcas, "system.sysctl");
107 if (capsysctl == NULL)
108 err(1, "Unable to open system.sysctl service");
110 /* Close Casper capability, we don't need it anymore. */
113 /* Create limit for one MIB with read access only. */
114 limits = nvlist_create(0);
115 nvlist_add_number(limits, name, CAP_SYSCTL_READ);
117 /* Limit system.sysctl. */
118 if (cap_limit_set(capsysctl, limits) < 0)
119 err(1, "Unable to set limits");
122 if (cap_sysctlbyname(capsysctl, name, &value, &size, NULL, 0) < 0)
123 err(1, "Unable to get value of sysctl");
125 printf("The value of %s is %d.\\n", name, value);
127 cap_close(capsysctl);
138 service first appeared in
143 service was implemented by
144 .An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net
145 under sponsorship from the FreeBSD Foundation.
147 This manual page was written by
148 .An Mariusz Zaborski Aq Mt oshogbo@FreeBSD.org .