Changeset View
Changeset View
Standalone View
Standalone View
lib/libcasper/services/cap_jail/cap_jail.3
- This file was added.
.\" Copyright (c) 2018 Stefan Grundmann | |||||
.\" All rights reserved. | |||||
.\" | |||||
.\" Redistribution and use in source and binary forms, with or without | |||||
.\" modification, are permitted provided that the following conditions | |||||
.\" are met: | |||||
.\" 1. Redistributions of source code must retain the above copyright | |||||
.\" notice, this list of conditions and the following disclaimer. | |||||
.\" 2. Redistributions in binary form must reproduce the above copyright | |||||
.\" notice, this list of conditions and the following disclaimer in the | |||||
.\" documentation and/or other materials provided with the distribution. | |||||
.\" | |||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND | |||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE | |||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
.\" SUCH DAMAGE. | |||||
.\" | |||||
.\" $FreeBSD$ | |||||
.\" | |||||
.Dd May 11, 2018 | |||||
.Dt CAP_JAIL 3 | |||||
.Os | |||||
.Sh NAME | |||||
.Nm cap_jail | |||||
.Nd "library for getting jail information in capability mode" | |||||
.Sh LIBRARY | |||||
.Lb libcap_jail | |||||
.Sh SYNOPSIS | |||||
.In sys/uio.h | |||||
.In libcasper.h | |||||
.In casper/cap_jail.h | |||||
.Ft int | |||||
.Fn cap_jail_get "cap_channel_t *chan" " struct iovec *iov" " u_int niov" " int flags" | |||||
.Sh DESCRIPTION | |||||
The function | |||||
.Fn cap_jail_get | |||||
is equivalent to | |||||
.Xr jail_get 2 | |||||
except that the connection to the | |||||
.Nm system.jail | |||||
service needs to be provided. | |||||
.Sh EXAMPLES | |||||
The following example first opens a capability to casper and then uses this | |||||
capability to create the | |||||
.Nm system.jail | |||||
casper service and uses it to get the | |||||
.Dv jid | |||||
and | |||||
.Dv name | |||||
of the first jail | |||||
.Bd -literal | |||||
cap_channel_t *capcas, *capjail; | |||||
struct iovec iov[4]; | |||||
char name[256]; | |||||
int jid; | |||||
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.jail service. */ | |||||
capjail = cap_service_open(capcas, "system.jail"); | |||||
if (capjail == NULL) | |||||
err(1, "Unable to open system.jail service"); | |||||
/* Close Casper capability, we don't need it anymore. */ | |||||
cap_close(capcas); | |||||
/* prepare iovs */ | |||||
jid = 0; | |||||
iov[0].iov_base = __DECONST(char *, "lastjid"); | |||||
iov[0].iov_len = strlen(iov[0].iov_base) + 1; | |||||
iov[1].iov_base = &jid; | |||||
iov[1].iov_len = sizeof(jid); | |||||
iov[2].iov_base = __DECONST(char *, "name"); | |||||
iov[2].iov_len = strlen(iov[2].iov_base) + 1; | |||||
iov[3].iov_base = name; | |||||
iov[3].iov_len = sizeof(name); | |||||
/* Fetch values */ | |||||
jid = cap_jail_get(capjail, iov, 4, 0); | |||||
if (jid < 0 && errno != ENOENT) | |||||
err(1, "Unable to get jail information"); | |||||
if (jid > 0) | |||||
printf("jid = %d name = %s\\n", jid, name); | |||||
else | |||||
printf("no jails\\n"); | |||||
cap_close(capjail); | |||||
.Ed | |||||
.Sh SEE ALSO | |||||
.Xr cap_enter 2 , | |||||
.Xr jail_get 2 , | |||||
.Xr capsicum 4 , | |||||
.Sh AUTHORS | |||||
The | |||||
.Nm cap_jail | |||||
service and this manual page were written by | |||||
.An Stefan Grundmann |