Index: stable/12/lib/libc/capability/cap_rights_init.3 =================================================================== --- stable/12/lib/libc/capability/cap_rights_init.3 (revision 364016) +++ stable/12/lib/libc/capability/cap_rights_init.3 (revision 364017) @@ -1,241 +1,253 @@ .\" .\" Copyright (c) 2013 The FreeBSD Foundation .\" All rights reserved. .\" .\" This documentation was written by Pawel Jakub Dawidek under sponsorship .\" from the FreeBSD Foundation. .\" .\" 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 AUTHOR 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 AUTHOR 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 March 27, 2014 +.Dd May 5, 2020 .Dt CAP_RIGHTS_INIT 3 .Os .Sh NAME .Nm cap_rights_init , .Nm cap_rights_set , .Nm cap_rights_clear , .Nm cap_rights_is_set , .Nm cap_rights_is_valid , .Nm cap_rights_merge , .Nm cap_rights_remove , .Nm cap_rights_contains .Nd manage cap_rights_t structure .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In sys/capsicum.h .Ft cap_rights_t * .Fn cap_rights_init "cap_rights_t *rights" "..." .Ft cap_rights_t * .Fn cap_rights_set "cap_rights_t *rights" "..." .Ft cap_rights_t * .Fn cap_rights_clear "cap_rights_t *rights" "..." .Ft bool .Fn cap_rights_is_set "const cap_rights_t *rights" "..." .Ft bool .Fn cap_rights_is_valid "const cap_rights_t *rights" .Ft cap_rights_t * .Fn cap_rights_merge "cap_rights_t *dst" "const cap_rights_t *src" .Ft cap_rights_t * .Fn cap_rights_remove "cap_rights_t *dst" "const cap_rights_t *src" .Ft bool .Fn cap_rights_contains "const cap_rights_t *big" "const cap_rights_t *little" .Sh DESCRIPTION The functions documented here allow to manage the .Vt cap_rights_t structure. .Pp Capability rights should be separated with comma when passed to the .Fn cap_rights_init , .Fn cap_rights_set , .Fn cap_rights_clear and .Fn cap_rights_is_set functions. For example: .Bd -literal cap_rights_set(&rights, CAP_READ, CAP_WRITE, CAP_FSTAT, CAP_SEEK); .Ed .Pp The complete list of the capability rights can be found in the .Xr rights 4 manual page. .Pp The .Fn cap_rights_init function initialize provided .Vt cap_rights_t structure. Only properly initialized structure can be passed to the remaining functions. For convenience the structure can be filled with capability rights instead of calling the .Fn cap_rights_set function later. For even more convenience pointer to the given structure is returned, so it can be directly passed to .Xr cap_rights_limit 2 : .Bd -literal cap_rights_t rights; if (cap_rights_limit(fd, cap_rights_init(&rights, CAP_READ, CAP_WRITE)) < 0) err(1, "Unable to limit capability rights"); .Ed .Pp The .Fn cap_rights_set function adds the given capability rights to the given .Vt cap_rights_t structure. .Pp The .Fn cap_rights_clear function removes the given capability rights from the given .Vt cap_rights_t structure. .Pp The .Fn cap_rights_is_set function checks if all the given capability rights are set for the given .Vt cap_rights_t structure. .Pp The .Fn cap_rights_is_valid function verifies if the given .Vt cap_rights_t structure is valid. .Pp The .Fn cap_rights_merge function merges all capability rights present in the .Fa src structure into the .Fa dst structure. .Pp The .Fn cap_rights_remove function removes all capability rights present in the .Fa src structure from the .Fa dst structure. .Pp The .Fn cap_rights_contains function checks if the .Fa big structure contains all capability rights present in the .Fa little structure. .Sh RETURN VALUES The functions never fail. In case an invalid capability right or an invalid .Vt cap_rights_t structure is given as an argument, the program will be aborted. .Pp The .Fn cap_rights_init , .Fn cap_rights_set and .Fn cap_rights_clear functions return pointer to the .Vt cap_rights_t structure given in the .Fa rights argument. .Pp The .Fn cap_rights_merge and .Fn cap_rights_remove functions return pointer to the .Vt cap_rights_t structure given in the .Fa dst argument. .Pp The .Fn cap_rights_is_set returns .Va true if all the given capability rights are set in the .Fa rights argument. .Pp The .Fn cap_rights_is_valid function performs various checks to see if the given .Vt cap_rights_t structure is valid and returns .Va true if it is. .Pp The .Fn cap_rights_contains function returns .Va true if all capability rights set in the .Fa little structure are also present in the .Fa big structure. .Sh EXAMPLES The following example demonstrates how to prepare a .Vt cap_rights_t structure to be passed to the .Xr cap_rights_limit 2 system call. .Bd -literal cap_rights_t rights; int fd; fd = open("/tmp/foo", O_RDWR); if (fd < 0) err(1, "open() failed"); cap_rights_init(&rights, CAP_FSTAT, CAP_READ); if (allow_write_and_seek) cap_rights_set(&rights, CAP_WRITE, CAP_SEEK); if (dont_allow_seek) cap_rights_clear(&rights, CAP_SEEK); if (cap_rights_limit(fd, &rights) < 0 && errno != ENOSYS) err(1, "cap_rights_limit() failed"); .Ed .Sh SEE ALSO .Xr cap_rights_limit 2 , .Xr open 2 , .Xr capsicum 4 , .Xr rights 4 .Sh HISTORY +The functions +.Fn cap_rights_init , +.Fn cap_rights_set , +.Fn cap_rights_clear , +.Fn cap_rights_is_set , +.Fn cap_rights_is_valid , +.Fn cap_rights_merge , +.Fn cap_rights_remove +and +.Fn cap_rights_contains +first appeared in +.Fx 8.3 . Support for capabilities and capabilities mode was developed as part of the .Tn TrustedBSD Project. .Sh AUTHORS This family of functions was created by .An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net under sponsorship from the FreeBSD Foundation. Index: stable/12/lib/libc/gen/cap_rights_get.3 =================================================================== --- stable/12/lib/libc/gen/cap_rights_get.3 (revision 364016) +++ stable/12/lib/libc/gen/cap_rights_get.3 (revision 364017) @@ -1,119 +1,123 @@ .\" .\" Copyright (c) 2013 The FreeBSD Foundation .\" All rights reserved. .\" .\" This documentation was written by Pawel Jakub Dawidek under sponsorship .\" from the FreeBSD Foundation. .\" .\" 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 AUTHOR 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 AUTHOR 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 March 27, 2014 +.Dd May 5, 2020 .Dt CAP_RIGHTS_GET 3 .Os .Sh NAME .Nm cap_rights_get .Nd obtain capability rights .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In sys/capsicum.h .Ft int .Fn cap_rights_get "int fd" "cap_rights_t *rights" .Sh DESCRIPTION The .Nm cap_rights_get function allows to obtain current capability rights for the given descriptor. The function will fill the .Fa rights argument with all capability rights if they were not limited or capability rights configured during the last successful call of .Xr cap_rights_limit 2 on the given descriptor. .Pp The .Fa rights argument can be inspected using .Xr cap_rights_init 3 family of functions. .Pp The complete list of the capability rights can be found in the .Xr rights 4 manual page. .Sh RETURN VALUES .Rv -std .Sh EXAMPLES The following example demonstrates how to limit file descriptor capability rights and how to obtain them. .Bd -literal cap_rights_t setrights, getrights; int fd; memset(&setrights, 0, sizeof(setrights)); memset(&getrights, 0, sizeof(getrights)); fd = open("/tmp/foo", O_RDONLY); if (fd < 0) err(1, "open() failed"); cap_rights_init(&setrights, CAP_FSTAT, CAP_READ); if (cap_rights_limit(fd, &setrights) < 0 && errno != ENOSYS) err(1, "cap_rights_limit() failed"); if (cap_rights_get(fd, &getrights) < 0 && errno != ENOSYS) err(1, "cap_rights_get() failed"); assert(memcmp(&setrights, &getrights, sizeof(setrights)) == 0); .Ed .Sh ERRORS .Fn cap_rights_get succeeds unless: .Bl -tag -width Er .It Bq Er EBADF The .Fa fd argument is not a valid active descriptor. .It Bq Er EFAULT The .Fa rights argument points at an invalid address. .El .Sh SEE ALSO .Xr cap_rights_limit 2 , .Xr errno 2 , .Xr open 2 , .Xr assert 3 , .Xr cap_rights_init 3 , .Xr err 3 , .Xr memcmp 3 , .Xr memset 3 , .Xr capsicum 4 , .Xr rights 4 .Sh HISTORY +The +.Fn cap_rights_get +function first appeared in +.Fx 9.2 . Support for capabilities and capabilities mode was developed as part of the .Tn TrustedBSD Project. .Sh AUTHORS This function was created by .An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net under sponsorship of the FreeBSD Foundation. Index: stable/12/lib/libc/gen/cap_sandboxed.3 =================================================================== --- stable/12/lib/libc/gen/cap_sandboxed.3 (revision 364016) +++ stable/12/lib/libc/gen/cap_sandboxed.3 (revision 364017) @@ -1,71 +1,76 @@ .\" .\" Copyright (c) 2012 The FreeBSD Foundation .\" All rights reserved. .\" .\" This documentation was written by Pawel Jakub Dawidek under sponsorship .\" from the FreeBSD Foundation. .\" .\" 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 AUTHOR 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 AUTHOR 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 March 27, 2014 +.Dd May 5, 2020 .Dt CAP_SANDBOXED 3 .Os .Sh NAME .Nm cap_sandboxed .Nd Check if in a capability mode sandbox .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In sys/capsicum.h .In stdbool.h .Ft bool .Fn cap_sandboxed "void" .Sh DESCRIPTION .Fn cap_sandboxed returns .Va true if the process is in a capability mode sandbox or .Va false if it is not. This function is a more handy alternative to the .Xr cap_getmode 2 system call as it always succeeds, so there is no need for error checking. If the support for capability mode is not compiled into the kernel, .Fn cap_sandboxed will always return .Va false . .Sh RETURN VALUES Function .Fn cap_sandboxed is always successful and will return either .Va true or .Va false . .Sh SEE ALSO .Xr cap_enter 2 , .Xr capsicum 4 +.Sh HISTORY +The +.Fn cap_sandboxed +function first appeared in +.Fx 9.2 . .Sh AUTHORS This function was implemented and manual page was written by .An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net under sponsorship of the FreeBSD Foundation. Index: stable/12/lib/libc/sys/cap_enter.2 =================================================================== --- stable/12/lib/libc/sys/cap_enter.2 (revision 364016) +++ stable/12/lib/libc/sys/cap_enter.2 (revision 364017) @@ -1,160 +1,164 @@ .\" .\" Copyright (c) 2008-2009 Robert N. M. Watson .\" All rights reserved. .\" .\" This software was developed at the University of Cambridge Computer .\" Laboratory with support from a grant from Google, Inc. .\" .\" 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 AUTHOR 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 AUTHOR 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 23, 2017 +.Dd May 5, 2020 .Dt CAP_ENTER 2 .Os .Sh NAME .Nm cap_enter , .Nm cap_getmode .Nd Capability mode system calls .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In sys/capsicum.h .Ft int .Fn cap_enter "void" .Ft int .Fn cap_getmode "u_int *modep" .Sh DESCRIPTION .Fn cap_enter places the current process into capability mode, a mode of execution in which processes may only issue system calls operating on file descriptors or reading limited global system state. Access to global name spaces, such as file system or IPC name spaces, is prevented. If the process is already in a capability mode sandbox, the system call is a no-op. Future process descendants created with .Xr fork 2 or .Xr pdfork 2 will be placed in capability mode from inception. .Pp When combined with .Xr cap_rights_limit 2 , .Xr cap_ioctls_limit 2 , .Xr cap_fcntls_limit 2 , .Fn cap_enter may be used to create kernel-enforced sandboxes in which appropriately-crafted applications or application components may be run. .Pp .Fn cap_getmode returns a flag indicating whether or not the process is in a capability mode sandbox. .Sh RUN-TIME SETTINGS If the .Dv kern.trap_enotcap sysctl MIB is set to a non-zero value, then for any process executing in a capability mode sandbox, any syscall which results in either an .Er ENOTCAPABLE or .Er ECAPMODE error also generates the synchronous .Dv SIGTRAP signal to the thread on the syscall return. On signal delivery, the .Va si_errno member of the .Fa siginfo signal handler parameter is set to the syscall error value, and the .Va si_code member is set to .Dv TRAP_CAP . .Pp See also the .Dv PROC_TRAPCAP_CTL and .Dv PROC_TRAPCAP_STATUS operations of the .Xr procctl 2 function for similar per-process functionality. .Sh CAVEAT Creating effective process sandboxes is a tricky process that involves identifying the least possible rights required by the process and then passing those rights into the process in a safe manner. Consumers of .Fn cap_enter should also be aware of other inherited rights, such as access to VM resources, memory contents, and other process properties that should be considered. It is advisable to use .Xr fexecve 2 to create a runtime environment inside the sandbox that has as few implicitly acquired rights as possible. .Sh RETURN VALUES .Rv -std cap_enter cap_getmode .Pp When the process is in capability mode, .Fn cap_getmode sets the flag to a non-zero value. A zero value means the process is not in capability mode. .Sh ERRORS The .Fn cap_enter and .Fn cap_getmode system calls will fail if: .Bl -tag -width Er .It Bq Er ENOSYS The kernel is compiled without: .Pp .Cd "options CAPABILITY_MODE" .El .Pp The .Fn cap_getmode system call may also return the following error: .Bl -tag -width Er .It Bq Er EFAULT Pointer .Fa modep points outside the process's allocated address space. .El .Sh SEE ALSO .Xr cap_fcntls_limit 2 , .Xr cap_ioctls_limit 2 , .Xr cap_rights_limit 2 , .Xr fexecve 2 , .Xr procctl 2 , .Xr cap_sandboxed 3 , .Xr capsicum 4 , .Xr sysctl 9 .Sh HISTORY +The +.Fn cap_getmode +system call first appeared in +.Fx 8.3 . Support for capabilities and capabilities mode was developed as part of the .Tn TrustedBSD Project. .Sh AUTHORS These functions and the capability facility were created by .An "Robert N. M. Watson" at the University of Cambridge Computer Laboratory with support from a grant from Google, Inc. Index: stable/12/lib/libc/sys/cap_fcntls_limit.2 =================================================================== --- stable/12/lib/libc/sys/cap_fcntls_limit.2 (revision 364016) +++ stable/12/lib/libc/sys/cap_fcntls_limit.2 (revision 364017) @@ -1,126 +1,132 @@ .\" .\" Copyright (c) 2012 The FreeBSD Foundation .\" All rights reserved. .\" .\" This documentation was written by Pawel Jakub Dawidek under sponsorship .\" the FreeBSD Foundation. .\" .\" 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 AUTHOR 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 AUTHOR 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 March 27, 2014 +.Dd May 5, 2020 .Dt CAP_FCNTLS_LIMIT 2 .Os .Sh NAME .Nm cap_fcntls_limit , .Nm cap_fcntls_get .Nd manage allowed fcntl commands .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In sys/capsicum.h .Ft int .Fn cap_fcntls_limit "int fd" "uint32_t fcntlrights" .Ft int .Fn cap_fcntls_get "int fd" "uint32_t *fcntlrightsp" .Sh DESCRIPTION If a file descriptor is granted the .Dv CAP_FCNTL capability right, the list of allowed .Xr fcntl 2 commands can be selectively reduced (but never expanded) with the .Fn cap_fcntls_limit system call. .Pp A bitmask of allowed fcntls commands for a given file descriptor can be obtained with the .Fn cap_fcntls_get system call. .Sh FLAGS The following flags may be specified in the .Fa fcntlrights argument or returned in the .Fa fcntlrightsp argument: .Bl -tag -width CAP_FCNTL_GETOWN .It Dv CAP_FCNTL_GETFL Permit .Dv F_GETFL command. .It Dv CAP_FCNTL_SETFL Permit .Dv F_SETFL command. .It Dv CAP_FCNTL_GETOWN Permit .Dv F_GETOWN command. .It Dv CAP_FCNTL_SETOWN Permit .Dv F_SETOWN command. .El .Sh RETURN VALUES .Rv -std .Sh ERRORS .Fn cap_fcntls_limit succeeds unless: .Bl -tag -width Er .It Bq Er EBADF The .Fa fd argument is not a valid descriptor. .It Bq Er EINVAL An invalid flag has been passed in .Fa fcntlrights . .It Bq Er ENOTCAPABLE .Fa fcntlrights would expand the list of allowed .Xr fcntl 2 commands. .El .Pp .Fn cap_fcntls_get succeeds unless: .Bl -tag -width Er .It Bq Er EBADF The .Fa fd argument is not a valid descriptor. .It Bq Er EFAULT The .Fa fcntlrightsp argument points at an invalid address. .El .Sh SEE ALSO .Xr cap_ioctls_limit 2 , .Xr cap_rights_limit 2 , .Xr fcntl 2 .Sh HISTORY +The +.Fn cap_fcntls_get +and +.Fn cap_fcntls_limit +system calls first appeared in +.Fx 8.3 . Support for capabilities and capabilities mode was developed as part of the .Tn TrustedBSD Project. .Sh AUTHORS This function was created by .An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net under sponsorship of the FreeBSD Foundation. Index: stable/12/lib/libc/sys/cap_ioctls_limit.2 =================================================================== --- stable/12/lib/libc/sys/cap_ioctls_limit.2 (revision 364016) +++ stable/12/lib/libc/sys/cap_ioctls_limit.2 (revision 364017) @@ -1,159 +1,165 @@ .\" .\" Copyright (c) 2012 The FreeBSD Foundation .\" All rights reserved. .\" .\" This documentation was written by Pawel Jakub Dawidek under sponsorship .\" the FreeBSD Foundation. .\" .\" 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 AUTHOR 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 AUTHOR 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 March 6, 2015 +.Dd May 5, 2020 .Dt CAP_IOCTLS_LIMIT 2 .Os .Sh NAME .Nm cap_ioctls_limit , .Nm cap_ioctls_get .Nd manage allowed ioctl commands .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In sys/capsicum.h .Ft int .Fn cap_ioctls_limit "int fd" "const unsigned long *cmds" "size_t ncmds" .Ft ssize_t .Fn cap_ioctls_get "int fd" "unsigned long *cmds" "size_t maxcmds" .Sh DESCRIPTION If a file descriptor is granted the .Dv CAP_IOCTL capability right, the list of allowed .Xr ioctl 2 commands can be selectively reduced (but never expanded) with the .Fn cap_ioctls_limit system call. The .Fa cmds argument is an array of .Xr ioctl 2 commands and the .Fa ncmds argument specifies the number of elements in the array. There can be up to .Va 256 elements in the array. Including an element that has been previously revoked will generate an error. After a successful call only those listed in the array may be used. .Pp The list of allowed ioctl commands for a given file descriptor can be obtained with the .Fn cap_ioctls_get system call. The .Fa cmds argument points at memory that can hold up to .Fa maxcmds values. The function populates the provided buffer with up to .Fa maxcmds elements, but always returns the total number of ioctl commands allowed for the given file descriptor. The total number of ioctls commands for the given file descriptor can be obtained by passing .Dv NULL as the .Fa cmds argument and .Va 0 as the .Fa maxcmds argument. If all ioctl commands are allowed .Dv ( CAP_IOCTL capability right is assigned to the file descriptor and the .Fn cap_ioctls_limit system call was never called for this file descriptor), the .Fn cap_ioctls_get system call will return .Dv CAP_IOCTLS_ALL and will not modify the buffer pointed to by the .Fa cmds argument. .Sh RETURN VALUES .Rv -std cap_ioctls_limit .Pp The .Fn cap_ioctls_get function, if successful, returns the total number of allowed ioctl commands or the value .Dv CAP_IOCTLS_ALL if all ioctls commands are allowed. On failure the value .Va -1 is returned and the global variable errno is set to indicate the error. .Sh ERRORS .Fn cap_ioctls_limit succeeds unless: .Bl -tag -width Er .It Bq Er EBADF The .Fa fd argument is not a valid descriptor. .It Bq Er EFAULT The .Fa cmds argument points at an invalid address. .It Bq Er EINVAL The .Fa ncmds argument is greater than .Va 256 . .It Bq Er ENOTCAPABLE .Fa cmds would expand the list of allowed .Xr ioctl 2 commands. .El .Pp .Fn cap_ioctls_get succeeds unless: .Bl -tag -width Er .It Bq Er EBADF The .Fa fd argument is not a valid descriptor. .It Bq Er EFAULT The .Fa cmds argument points at invalid address. .El .Sh SEE ALSO .Xr cap_fcntls_limit 2 , .Xr cap_rights_limit 2 , .Xr ioctl 2 .Sh HISTORY +The +.Fn cap_ioctls_get +and +.Fn cap_ioctls_limit +system calls first appeared in +.Fx 8.3 . Support for capabilities and capabilities mode was developed as part of the .Tn TrustedBSD Project. .Sh AUTHORS This function was created by .An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net under sponsorship of the FreeBSD Foundation. Index: stable/12/lib/libc/sys/cap_rights_limit.2 =================================================================== --- stable/12/lib/libc/sys/cap_rights_limit.2 (revision 364016) +++ stable/12/lib/libc/sys/cap_rights_limit.2 (revision 364017) @@ -1,157 +1,161 @@ .\" .\" Copyright (c) 2008-2010 Robert N. M. Watson .\" Copyright (c) 2012-2013 The FreeBSD Foundation .\" All rights reserved. .\" .\" This software was developed at the University of Cambridge Computer .\" Laboratory with support from a grant from Google, Inc. .\" .\" Portions of this documentation were written by Pawel Jakub Dawidek .\" under sponsorship from the FreeBSD Foundation. .\" .\" 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 AUTHOR 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 AUTHOR 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 March 27, 2014 +.Dd May 5, 2020 .Dt CAP_RIGHTS_LIMIT 2 .Os .Sh NAME .Nm cap_rights_limit .Nd limit capability rights .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In sys/capsicum.h .Ft int .Fn cap_rights_limit "int fd" "const cap_rights_t *rights" .Sh DESCRIPTION When a file descriptor is created by a function such as .Xr accept 2 , .Xr accept4 2 , .Xr fhopen 2 , .Xr kqueue 2 , .Xr mq_open 2 , .Xr open 2 , .Xr openat 2 , .Xr pdfork 2 , .Xr pipe 2 , .Xr shm_open 2 , .Xr socket 2 or .Xr socketpair 2 , it is assigned all capability rights. Those rights can be reduced (but never expanded) by using the .Fn cap_rights_limit system call. Once capability rights are reduced, operations on the file descriptor will be limited to those permitted by .Fa rights . .Pp The .Fa rights argument should be prepared using .Xr cap_rights_init 3 family of functions. .Pp Capability rights assigned to a file descriptor can be obtained with the .Xr cap_rights_get 3 function. .Pp The complete list of the capability rights can be found in the .Xr rights 4 manual page. .Sh RETURN VALUES .Rv -std .Sh EXAMPLES The following example demonstrates how to limit file descriptor capability rights to allow reading only. .Bd -literal cap_rights_t setrights; char buf[1]; int fd; fd = open("/tmp/foo", O_RDWR); if (fd < 0) err(1, "open() failed"); if (cap_enter() < 0) err(1, "cap_enter() failed"); cap_rights_init(&setrights, CAP_READ); if (cap_rights_limit(fd, &setrights) < 0) err(1, "cap_rights_limit() failed"); buf[0] = 'X'; if (write(fd, buf, sizeof(buf)) > 0) errx(1, "write() succeeded!"); if (read(fd, buf, sizeof(buf)) < 0) err(1, "read() failed"); .Ed .Sh ERRORS .Fn cap_rights_limit succeeds unless: .Bl -tag -width Er .It Bq Er EBADF The .Fa fd argument is not a valid active descriptor. .It Bq Er EINVAL An invalid right has been requested in .Fa rights . .It Bq Er ENOTCAPABLE The .Fa rights argument contains capability rights not present for the given file descriptor. Capability rights list can only be reduced, never expanded. .El .Sh SEE ALSO .Xr accept 2 , .Xr accept4 2 , .Xr cap_enter 2 , .Xr fhopen 2 , .Xr kqueue 2 , .Xr mq_open 2 , .Xr open 2 , .Xr openat 2 , .Xr pdfork 2 , .Xr pipe 2 , .Xr read 2 , .Xr shm_open 2 , .Xr socket 2 , .Xr socketpair 2 , .Xr write 2 , .Xr cap_rights_get 3 , .Xr cap_rights_init 3 , .Xr err 3 , .Xr capsicum 4 , .Xr rights 4 .Sh HISTORY +The +.Fn cap_rights_limit +function first appeared in +.Fx 8.3 . Support for capabilities and capabilities mode was developed as part of the .Tn TrustedBSD Project. .Sh AUTHORS This function was created by .An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net under sponsorship of the FreeBSD Foundation. Index: stable/12/lib/libcasper/libcasper/libcasper.3 =================================================================== --- stable/12/lib/libcasper/libcasper/libcasper.3 (revision 364016) +++ stable/12/lib/libcasper/libcasper/libcasper.3 (revision 364017) @@ -1,284 +1,289 @@ .\" Copyright (c) 2013 The FreeBSD Foundation .\" Copyright (c) 2018 Mariusz Zaborski .\" All rights reserved. .\" .\" This documentation was written by Pawel Jakub Dawidek under sponsorship .\" from the FreeBSD Foundation. .\" .\" 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 November 5, 2018 +.Dd May 5, 2020 .Dt LIBCASPER 3 .Os .Sh NAME .Nm cap_init , .Nm cap_wrap , .Nm cap_unwrap , .Nm cap_sock , .Nm cap_clone , .Nm cap_close , .Nm cap_limit_get , .Nm cap_limit_set , .Nm cap_send_nvlist , .Nm cap_recv_nvlist , .Nm cap_xfer_nvlist , .Nm cap_service_open .Nd "library for handling application capabilities" .Sh LIBRARY .Lb libcasper .Sh SYNOPSIS .Fd #define WITH_CASPER .In sys/nv.h .In libcasper.h .Ft "cap_channel_t *" .Fn cap_init "void" .Ft "cap_channel_t *" .Fn cap_wrap "int sock" "int flags" .Ft "int" .Fn cap_unwrap "cap_channel_t *chan" "int *flags" .Ft "int" .Fn cap_sock "const cap_channel_t *chan" .Ft "cap_channel_t *" .Fn cap_clone "const cap_channel_t *chan" .Ft "void" .Fn cap_close "cap_channel_t *chan" .Ft "int" .Fn cap_limit_get "const cap_channel_t *chan" "nvlist_t **limitsp" .Ft "int" .Fn cap_limit_set "const cap_channel_t *chan" "nvlist_t *limits" .Ft "int" .Fn cap_send_nvlist "const cap_channel_t *chan" "const nvlist_t *nvl" .Ft "nvlist_t *" .Fn cap_recv_nvlist "const cap_channel_t *chan" .Ft "nvlist_t *" .Fn cap_xfer_nvlist "const cap_channel_t *chan" "nvlist_t *nvl" .Ft "cap_channel_t *" .Fn cap_service_open "const cap_channel_t *chan" "const char *name" .Sh DESCRIPTION The .Nm libcasper library allows to manage application capabilities through the casper process. .Pp The application capability (represented by the .Vt cap_channel_t type) is a communication channel between the caller and the casper process daemon or an instance of one of its services. A capability to the casper process obtained with the .Fn cap_init function allows to create capabilities to casper's services via the .Fn cap_service_open function. .Pp The .Fn cap_init function opens capability to the casper process. .Pp The .Fn cap_wrap function creates .Vt cap_channel_t based on the given socket. The function is used when capability is inherited through .Xr execve 2 or send over .Xr unix 4 domain socket as a regular file descriptor and has to be represented as .Vt cap_channel_t again. The .Fa flags argument defines the channel behavior. The supported flags are: .Bl -ohang -offset indent .It CASPER_NO_UNIQ The communication between process and casper uses no unique version of nvlist. .El .Pp The .Fn cap_unwrap function is the opposite of the .Fn cap_wrap function. It frees the .Vt cap_channel_t structure and returns .Xr unix 4 domain socket associated with it. .Pp The .Fn cap_clone function clones the given capability. .Pp The .Fn cap_close function closes the given capability. .Pp The .Fn cap_sock function returns .Xr unix 4 domain socket descriptor associated with the given capability for use with system calls like .Xr kevent 2 , .Xr poll 2 and .Xr select 2 . .Pp The .Fn cap_limit_get function stores current limits of the given capability in the .Fa limitsp argument. If the function return .Va 0 and .Dv NULL is stored in .Fa limitsp it means there are no limits set. .Pp The .Fn cap_limit_set function sets limits for the given capability. The limits are provided as a .Xr nvlist 9 . The exact format depends on the service the capability represents. .Fn cap_limit_set frees the limits regardless of whether the operation succeeds or fails. .Pp The .Fn cap_send_nvlist function sends the given .Xr nvlist 9 over the given capability. This is low level interface to communicate with casper services. Most services should provide higher level API. .Pp The .Fn cap_recv_nvlist function receives the given .Xr nvlist 9 over the given capability. .Pp The .Fn cap_xfer_nvlist function sends the given .Xr nvlist 9 , destroys it and receives new .Xr nvlist 9 in response over the given capability. It does not matter if the function succeeds or fails, the .Xr nvlist 9 given for sending will always be destroyed once the function returns. .Pp The .Fn cap_service_open function opens casper service of the given name through casper capability obtained via the .Fn cap_init function. The function returns capability that provides access to opened service. Casper supports the following services in the base system: .Bl -tag -width "system.random" -compact -offset indent .Pp .It system.dns provides DNS libc compatible API .It system.grp provides .Xr getgrent 3 compatible API .It system.pwd provides .Xr getpwent 3 compatible API .It system.random allows to obtain entropy from .Pa /dev/random .It system.sysctl provides .Xr sysctlbyname 3 compatible API .It system.syslog provides .Xr syslog 3 compatible API .Sh RETURN VALUES The .Fn cap_clone , .Fn cap_init , .Fn cap_recv_nvlist , .Fn cap_service_open , .Fn cap_wrap and .Fn cap_xfer_nvlist functions return .Dv NULL and set the .Va errno variable on failure. .Pp The .Fn cap_limit_get , .Fn cap_limit_set and .Fn cap_send_nvlist functions return .Dv -1 and set the .Va errno variable on failure. .Pp The .Fn cap_close , .Fn cap_sock and .Fn cap_unwrap functions always succeed. .Sh SEE ALSO .Xr errno 2 , .Xr execve 2 , .Xr kevent 2 , .Xr poll 2 , .Xr select 2 , .Xr cap_dns 3 , .Xr cap_grp 3 , .Xr cap_pwd 3 , .Xr cap_random 3 , .Xr cap_sysctl 3 , .Xr cap_syslog 3 , .Xr libcasper_service 3 , .Xr capsicum 4 , .Xr unix 4 , .Xr nv 9 +.Sh HISTORY +The +.Nm libcasper +library first appeared in +.Fx 10.3 . .Sh AUTHORS The .Nm libcasper library was implemented by .An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net under sponsorship from the FreeBSD Foundation. The .Nm libcasper new architecture was implemented by .An Mariusz Zaborski Aq Mt oshogbo@FreeBSD.org . Index: stable/12/lib/libcasper/libcasper/libcasper_service.3 =================================================================== --- stable/12/lib/libcasper/libcasper/libcasper_service.3 (revision 364016) +++ stable/12/lib/libcasper/libcasper/libcasper_service.3 (revision 364017) @@ -1,116 +1,121 @@ .\" Copyright (c) 2018 Mariusz Zaborski .\" 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 June 23, 2018 +.Dd May 5, 2020 .Dt LIBCASPER 3 .Os .Sh NAME .Nm CREATE_SERVICE .Nd "casper service declaration macro" .Sh LIBRARY .Lb libcasper .Sh SYNOPSIS .In sys/nv.h .In libcasper.h .In libcasper_service.h .Bd -literal typedef int service_limit_func_t(const nvlist_t *, const nvlist_t *); typedef int service_command_func_t(const char *, const nvlist_t *, nvlist_t *, nvlist_t *); .Ed .Fn CREATE_SERVICE "name" "limit_func" "command_func" "flags" .Sh DESCRIPTION The .Nm CREATE_SERVICE macro to create a new Casper service. The .Fa name is a string containing the service name, which will be used in the .Xr cap_service_open 3 , function to identify it. .Pp The .Fa limit_func is a function of type .Li service_limit_func_t . The first argument of the function contains .Xr nvlist 9 , old service limits and second one the new limits. If the services wasn't limited the old limits will be set to .Dv NULL . This function should not allow to extend service limits and only limit it further. The .Fa command_func is a function of type .Li service_command_func_t . First argument is the name of the command that should be executed. The first .Xr nvlist 9 contains the current limits. Next one contains a .Xr nvlist 9 with current request. The last one contains an output .Xr nvlist 9 which contains the response from Casper. .Pp The .Fa flags argument defines limits of the service. The supported flags are: .Bl -ohang -offset indent .It CASPER_SERVICE_STDIO The Casper service has access to the stdio descriptors from the process it was spawned from. .It CASPER_SERVICE_FD The Casper service has access to all descriptors besides stdio descriptors from the process it was spawned from. .It CASPER_SERVICE_NO_UNIQ_LIMITS The whole Casper communication is using .Xr nvlist 9 with .Xr NVLIST_NO_UNIQ 9 flag. .El .Sh SEE ALSO .Xr cap_enter 2 , .Xr libcasper 3 , .Xr capsicum 4 , .Xr nv 9 +.Sh HISTORY +The +.Nm libcasper +library first appeared in +.Fx 10.3 . .Sh AUTHORS The .Nm libcasper library was implemented by .An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net under sponsorship from the FreeBSD Foundation. The .Nm libcasper new architecture was implemented by .An Mariusz Zaborski Aq Mt oshogbo@FreeBSD.org . Index: stable/12/lib/libcasper/services/cap_dns/cap_dns.3 =================================================================== --- stable/12/lib/libcasper/services/cap_dns/cap_dns.3 (revision 364016) +++ stable/12/lib/libcasper/services/cap_dns/cap_dns.3 (revision 364017) @@ -1,209 +1,214 @@ .\" Copyright (c) 2018 Mariusz Zaborski .\" 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 April 18, 2020 +.Dd May 5, 2020 .Dt CAP_DNS 3 .Os .Sh NAME .Nm cap_gethostbyname , .Nm cap_gethostbyname2 , .Nm cap_gethostbyaddr , .Nm cap_getnameinfo , .Nm cap_dns_type_limit , .Nm cap_dns_family_limit .Nd "library for getting network host entry in capability mode" .Sh LIBRARY .Lb libcap_dns .Sh SYNOPSIS .In sys/nv.h .In libcasper.h .In casper/cap_dns.h .Ft "struct hostent *" .Fn cap_gethostbyname "const cap_channel_t *chan" "const char *name" .Ft "struct hostent *" .Fn cap_gethostbyname2 "const cap_channel_t *chan" "const char *name" "int af" .Ft "struct hostent *" .Fn cap_gethostbyaddr "const cap_channel_t *chan" "const void *addr" "socklen_t len" "int af" .Ft "int" .Fn cap_getnameinfo "const cap_channel_t *chan" "const void *name" "int namelen" .Ft "int" .Fn cap_dns_type_limit "cap_channel_t *chan" "const char * const *types" "size_t ntypes" .Ft "int" .Fn cap_dns_family_limit "const cap_channel_t *chan" "const int *families" "size_t nfamilies" .Sh DESCRIPTION The functions .Fn cap_gethostbyname , .Fn cap_gethostbyname2 , .Fn cep_gethostbyaddr and .Fn cap_getnameinfo are respectively equivalent to .Xr gethostbyname 3 , .Xr gethostbyname2 3 , .Xr gethostbyaddr 3 and .Xr getnameinfo 3 except that the connection to the .Nm system.dns service needs to be provided. .Pp The .Fn cap_dns_type_limit function limits the functions allowed in the service. The .Fa types variable can be set to .Dv ADDR2NAME or .Dv NAME2ADDR . See the .Sx LIMITS section for more details. The .Fa ntpyes variable contains the number of .Fa types provided. .Pp The .Fn cap_dns_family_limit functions allows to limit address families. For details see .Sx LIMITS . The .Fa nfamilies variable contains the number of .Fa families provided. .Sh LIMITS The preferred way of setting limits is to use the .Fn cap_dns_type_limit and .Fn cap_dns_family_limit functions, but the limits of service can be set also using .Xr cap_limit_set 3 . The .Xr nvlist 9 for that function can contain the following values and types: .Bl -ohang -offset indent .It type ( NV_TYPE_STRING ) The .Va type can have two values: .Dv ADDR2NAME or .Dv NAME2ADDR . The .Dv ADDR means that reverse DNS lookups are allowed with .Fn cap_getnameinfo and .Fn cap_gethostbyaddr functions. In case when .Va type is set to .Dv NAME the name resolution is allowed with .Fn cap_getaddrinfo , .Fn cap_gethostbyname , and .Fn cap_gethostbyname2 functions. .It family ( NV_TYPE_NUMBER ) The .Va family limits service to one of the address families (e.g. .Dv AF_INET , AF_INET6 , etc.). .Sh EXAMPLES The following example first opens a capability to casper and then uses this capability to create the .Nm system.dns casper service and uses it to resolve an IP address. .Bd -literal cap_channel_t *capcas, *capdns; const char *typelimit = "ADDR"; int familylimit; const char *ipstr = "127.0.0.1"; struct in_addr ip; struct hostent *hp; /* 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.dns service. */ capdns = cap_service_open(capcas, "system.dns"); if (capdns == NULL) err(1, "Unable to open system.dns service"); /* Close Casper capability, we don't need it anymore. */ cap_close(capcas); /* Limit system.dns to reverse DNS lookups. */ if (cap_dns_type_limit(capdns, &typelimit, 1) < 0) err(1, "Unable to limit access to the system.dns service"); /* Limit system.dns to reserve IPv4 addresses */ familylimit = AF_INET; if (cap_dns_family_limit(capdns, &familylimit, 1) < 0) err(1, "Unable to limit access to the system.dns service"); /* Convert IP address in C-string to in_addr. */ if (!inet_aton(ipstr, &ip)) errx(1, "Unable to parse IP address %s.", ipstr); /* Find hostname for the given IP address. */ hp = cap_gethostbyaddr(capdns, (const void *)&ip, sizeof(ip), AF_INET); if (hp == NULL) errx(1, "No name associated with %s.", ipstr); printf("Name associated with %s is %s.\\n", ipstr, hp->h_name); .Ed .Sh SEE ALSO .Xr cap_enter 2 , .Xr err 3 , .Xr gethostbyaddr 3 , .Xr gethostbyname 3 , .Xr gethostbyname2 3 , .Xr getnameinfo 3 , .Xr capsicum 4 , .Xr nv 9 +.Sh HISTORY +The +.Nm cap_dns +service first appeared in +.Fx 10.3 . .Sh AUTHORS The .Nm cap_dns service was implemented by .An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net under sponsorship from the FreeBSD Foundation. .Pp This manual page was written by .An Mariusz Zaborski Aq Mt oshogbo@FreeBSD.org . Index: stable/12/lib/libcasper/services/cap_grp/cap_grp.3 =================================================================== --- stable/12/lib/libcasper/services/cap_grp/cap_grp.3 (revision 364016) +++ stable/12/lib/libcasper/services/cap_grp/cap_grp.3 (revision 364017) @@ -1,228 +1,233 @@ .\" Copyright (c) 2018 Mariusz Zaborski .\" 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 March 18, 2018 +.Dd May 5, 2020 .Dt CAP_GRP 3 .Os .Sh NAME .Nm cap_getgrent , .Nm cap_getgrnam , .Nm cap_getgrgid , .Nm cap_getgrent_r , .Nm cap_getgrnam_r , .Nm cap_getgrgid_r , .Nm cap_setgroupent , .Nm cap_setgrent , .Nm cap_endgrent , .Nm cap_grp_limit_cmds , .Nm cap_grp_limit_fields , .Nm cap_grp_limit_groups .Nd "library for group database operations in capability mode" .Sh LIBRARY .Lb libcap_grp .Sh SYNOPSIS .In sys/nv.h .In libcasper.h .In casper/cap_grp.h .Ft "struct group *" .Fn cap_getgrent "cap_channel_t *chan" .Ft "struct group *" .Fn cap_getgrnam "cap_channel_t *chan" "const char *name" .Ft "struct group *" .Fn cap_getgrgid "cap_channel_t *chan" "gid_t gid" .Ft "int" .Fn cap_getgrent_r "cap_channel_t *chan" "struct group *grp" "char *buffer" "size_t bufsize" "struct group **result" .Ft "int" .Fn cap_getgrnam_r "cap_channel_t *chan" "const char *name" "struct group *grp" "char *buffer" "size_t bufsize" "struct group **result" .Ft int .Fn cap_getgrgid_r "cap_channel_t *chan" "gid_t gid" "struct group *grp" "char *buffer" "size_t bufsize" "struct group **result" .Ft int .Fn cap_setgroupent "cap_channel_t *chan" "int stayopen" .Ft int .Fn cap_setgrent "cap_channel_t *chan" .Ft void .Fn cap_endgrent "cap_channel_t *chan" .Ft int .Fn cap_grp_limit_cmds "cap_channel_t *chan" "const char * const *cmds" "size_t ncmds" .Ft int .Fn cap_grp_limit_fields "cap_channel_t *chan" "const char * const *fields" "size_t nfields" .Ft int .Fn cap_grp_limit_groups "cap_channel_t *chan" "const char * const *names" "size_t nnames" "const gid_t *gids" "size_t ngids" .Sh DESCRIPTION The functions .Fn cap_getgrent , .Fn cap_getgrnam , .Fn cap_getgrgid , .Fn cap_getgrent_r , .Fn cap_getgrnam_r , .Fn cap_getgrgid_r , .Fn cap_setgroupent , .Fn cap_setgrent , and .Fn cap_endgrent are respectively equivalent to .Xr getgrent 3 , .Xr getgrnam 3 , .Xr getgrgid 3 , .Xr getgrent_r 3 , .Xr getgrnam_r 3 , .Xr getgrgid_r 3 , .Xr setgroupent 3 , .Xr setgrent 3 , and .Xr endgrent 3 except that the connection to the .Nm system.grp service needs to be provided. .Pp The .Fn cap_grp_limit_cmds function limits the functions allowed in the service. The .Fa cmds variable can be set to .Dv getgrent , .Dv getgrnam , .Dv getgrgid , .Dv getgrent_r , .Dv getgrnam_r , .Dv getgrgid_r , .Dv setgroupent , .Dv setgrent , or .Dv endgrent which will allow to use the function associated with the name. The .Fa ncmds variable contains the number of .Fa cmds provided. .Pp The .Fn cap_grp_limit_fields function allows limit fields returned in the structure .Vt group . The .Fa fields variable can be set to .Dv gr_name .Dv gr_passwd .Dv gr_gid or .Dv gr_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. The .Fa nfields variable contains the number of .Fa fields provided. .Pp The .Fn cap_grp_limit_groups function allows to limit access to groups. The .Fa names variable allows to limit groups by name and the .Fa gids variable by the group number. The .Fa nnames and .Fa ngids variables provide numbers of limited names and gids. .Sh EXAMPLES The following example first opens a capability to casper and then uses this capability to create the .Nm system.grp casper service and uses it to get a group name. .Bd -literal 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); .Ed .Sh SEE ALSO .Xr cap_enter 2 , .Xr endgrent 3 , .Xr err 3 , .Xr getgrent 3 , .Xr getgrent_r 3 , .Xr getgrgid 3 , .Xr getgrgid_r 3 , .Xr getgrnam 3 , .Xr getgrnam_r 3 , .Xr setgrent 3 , .Xr setgroupent 3 , .Xr capsicum 4 , .Xr nv 9 +.Sh HISTORY +The +.Nm cap_grp +service first appeared in +.Fx 10.3 . .Sh AUTHORS The .Nm cap_grp service was implemented by .An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net under sponsorship from the FreeBSD Foundation. .Pp This manual page was written by .An Mariusz Zaborski Aq Mt oshogbo@FreeBSD.org . Index: stable/12/lib/libcasper/services/cap_pwd/cap_pwd.3 =================================================================== --- stable/12/lib/libcasper/services/cap_pwd/cap_pwd.3 (revision 364016) +++ stable/12/lib/libcasper/services/cap_pwd/cap_pwd.3 (revision 364017) @@ -1,234 +1,239 @@ .\" Copyright (c) 2018 Mariusz Zaborski .\" 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 June 20, 2018 +.Dd May 5, 2020 .Dt CAP_PWD 3 .Os .Sh NAME .Nm cap_getpwent , .Nm cap_getpwnam , .Nm cap_getpwuid , .Nm cap_getpwent_r , .Nm cap_getpwnam_r , .Nm cap_getpwuid_r , .Nm cap_setpassent , .Nm cap_setpwent , .Nm cap_endpwent , .Nm cap_pwd_limit_cmds , .Nm cap_pwd_limit_fields , .Nm cap_pwd_limit_users .Nd "library for password database operations in capability mode" .Sh LIBRARY .Lb libcap_pwd .Sh SYNOPSIS .In libcasper.h .In casper/cap_pwd.h .Ft struct passwd * .Fn cap_getpwent "cap_channel_t *chan" .Ft struct passwd * .Fn cap_getpwnam "cap_channel_t *chan" "const char *login" .Ft struct passwd * .Fn cap_getpwuid "cap_channel_t *chan" "uid_t uid" .Ft int .Fn cap_getpwent_r "cap_channel_t *chan" "struct passwd *pwd" "char *buffer" "size_t bufsize" "struct passwd **result" .Ft int .Fn cap_getpwnam_r "cap_channel_t *chan" "const char *name" "struct passwd *pwd" "char *buffer" "size_t bufsize" "struct passwd **result" .Ft int .Fn cap_getpwuid_r "cap_channel_t *chan" "uid_t uid" "struct passwd *pwd" "char *buffer" "size_t bufsize" "struct passwd **result" .Ft int .Fn cap_setpassent "cap_channel_t *chan" "int stayopen" .Ft void .Fn cap_setpwent "cap_channel_t *chan" .Ft void .Fn cap_endpwent "cap_channel_t *chan" .Ft int .Fn cap_pwd_limit_cmds "cap_channel_t *chan" "const char * const *cmds" "size_t ncmds" .Ft int .Fn cap_pwd_limit_fields "cap_channel_t *chan" "const char * const *fields" "size_t nfields" .Ft int .Fn cap_pwd_limit_users "cap_channel_t *chan" "const char * const *names" "size_t nnames" "uid_t *uids" "size_t nuids" .Sh DESCRIPTION The functions .Fn cap_getpwent , .Fn cap_getpwnam , .Fn cap_getpwuid , .Fn cap_getpwent_r , .Fn cap_getpwnam_r , .Fn cap_getpwuid_r , .Fn cap_setpassent , .Fn cap_setpwent , and .Fn cap_endpwent are respectively equivalent to .Xr getpwent 3 , .Xr getpwnam 3 , .Xr getpwuid 3 , .Xr getpwent_r 3 , .Xr getpwnam_r 3 , .Xr getpwuid_r 3 , .Xr setpassent 3 , .Xr setpwent 3 , and .Xr cap_endpwent 3 except that the connection to the .Nm system.pwd service needs to be provided. .Pp The .Fn cap_pwd_limit_cmds function limits the functions allowed in the service. The .Fa cmds variable can be set to .Dv getpwent , .Dv getpwnam , .Dv getpwuid , .Dv getpwent_r , .Dv getpwnam_r , .Dv getpwuid_r , .Dv setpassent , .Dv setpwent , or .Dv endpwent which will allow to use the function associated with the name. The .Fa ncmds variable contains the number of .Fa cmds provided. .Pp The .Fn cap_pwd_limit_fields function allows limit fields returned in the structure .Vt passwd . The .Fa fields variable can be set to .Dv pw_name , .Dv pw_passwd , .Dv pw_uid , .Dv pw_gid , .Dv pw_change , .Dv pw_class , .Dv pw_gecos , .Dv pw_dir , .Dv pw_shell , .Dv pw_expire or .Dv pw_fields 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. The .Fa nfields variable contains the number of .Fa fields provided. .Pp The .Fn cap_pwd_limit_users function allows to limit access to users. The .Fa names variable allows to limit users by name and the .Fa uids variable by the user number. The .Fa nnames and .Fa nuids variables provide numbers of limited names and uids. .Sh EXAMPLES The following example first opens a capability to casper and then uses this capability to create the .Nm system.pwd casper service and uses it to get a user name. .Bd -literal cap_channel_t *capcas, *cappwd; const char *cmds[] = { "getpwuid" }; const char *fields[] = { "pw_name" }; uid_t uid[] = { 1 }; struct passwd *passwd; /* 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.pwd service. */ cappwd = cap_service_open(capcas, "system.pwd"); if (cappwd == NULL) err(1, "Unable to open system.pwd service"); /* Close Casper capability, we don't need it anymore. */ cap_close(capcas); /* Limit service to one single function. */ if (cap_pwd_limit_cmds(cappwd, cmds, nitems(cmds))) err(1, "Unable to limit access to system.pwd service"); /* Limit service to one field as we only need name of the user. */ if (cap_pwd_limit_fields(cappwd, fields, nitems(fields))) err(1, "Unable to limit access to system.pwd service"); /* Limit service to one uid. */ if (cap_pwd_limit_users(cappwd, NULL, 0, uid, nitems(uid))) err(1, "Unable to limit access to system.pwd service"); passwd = cap_getpwuid(cappwd, uid[0]); if (passwd == NULL) err(1, "Unable to get name of user"); printf("UID %d is associated with name %s.\\n", uid[0], passwd->pw_name); cap_close(cappwd); .Ed .Sh SEE ALSO .Xr cap_enter 2 , .Xr endpwent 3 , .Xr err 3 , .Xr getpwent 3 , .Xr getpwent_r 3 , .Xr getpwnam 3 , .Xr getpwnam_r 3 , .Xr getpwuid 3 , .Xr getpwuid_r 3 , .Xr setpassent 3 , .Xr setpwent 3 , .Xr capsicum 4 , .Xr nv 9 +.Sh HISTORY +The +.Nm cap_pwd +service first appeared in +.Fx 10.3 . .Sh AUTHORS The .Nm cap_pwd service was implemented by .An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net under sponsorship from the FreeBSD Foundation. .Pp This manual page was written by .An Mariusz Zaborski Aq Mt oshogbo@FreeBSD.org . Index: stable/12/lib/libcasper/services/cap_sysctl/cap_sysctl.3 =================================================================== --- stable/12/lib/libcasper/services/cap_sysctl/cap_sysctl.3 (revision 364016) +++ stable/12/lib/libcasper/services/cap_sysctl/cap_sysctl.3 (revision 364017) @@ -1,143 +1,148 @@ .\" Copyright (c) 2018 Mariusz Zaborski .\" 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 March 18, 2018 +.Dd May 5, 2020 .Dt CAP_SYSCTL 3 .Os .Sh NAME .Nm cap_sysctlbyname .Nd "library for getting or setting system information in capability mode" .Sh LIBRARY .Lb libcap_sysctl .Sh SYNOPSIS .In sys/nv.h .In libcasper.h .In casper/cap_sysctl.h .Ft int .Fn cap_sysctlbyname "cap_channel_t *chan" " const char *name" " void *oldp" " size_t *oldlenp" " const void *newp" " size_t newlen" .Sh DESCRIPTION The function .Fn cap_sysctlbyname is equivalent to .Xr sysctlbyname 3 except that the connection to the .Nm system.sysctl service needs to be provided. .Sh LIMITS The service can be limited using .Xr cap_limit_set 3 function. The .Xr nvlist 9 for that function can contain the following values and types: .Bl -ohang -offset indent .It ( NV_TYPE_NUMBER ) The name of the element with type number will be treated as the limited sysctl. The value of the element will describe the access rights for given sysctl. There are four different rights .Dv CAP_SYSCTL_READ , .Dv CAP_SYSCTL_WRITE , .Dv CAP_SYSCTL_RDWR , and .Dv CAP_SYSCTL_RECURSIVE . The .Dv CAP_SYSCTL_READ flag allows to fetch the value of a given sysctl. The .Dv CAP_SYSCTL_WIRTE flag allows to override the value of a given sysctl. The .Dv CAP_SYSCTL_RDWR is combination of the .Dv CAP_SYSCTL_WIRTE and .Dv CAP_SYSCTL_READ and allows to read and write the value of a given sysctl. The .Dv CAP_SYSCTL_RECURSIVE allows access to all children of a given sysctl. This right must be combined with at least one other right. .Sh EXAMPLES The following example first opens a capability to casper and then uses this capability to create the .Nm system.sysctl casper service and uses it to get the value of .Dv kern.trap_enotcap . .Bd -literal cap_channel_t *capcas, *capsysctl; const char *name = "kern.trap_enotcap"; nvlist_t *limits; int value; size_t size; /* 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. */ limits = nvlist_create(0); nvlist_add_number(limits, name, CAP_SYSCTL_READ); /* Limit system.sysctl. */ if (cap_limit_set(capsysctl, limits) < 0) err(1, "Unable to set limits"); /* Fetch 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.\\n", name, value); cap_close(capsysctl); .Ed .Sh SEE ALSO .Xr cap_enter 2 , .Xr err 3 , .Xr sysctlbyname 3 , .Xr capsicum 4 , .Xr nv 9 +.Sh HISTORY +The +.Nm cap_sysctl +service first appeared in +.Fx 10.3 . .Sh AUTHORS The .Nm cap_sysctl service was implemented by .An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net under sponsorship from the FreeBSD Foundation. .Pp This manual page was written by .An Mariusz Zaborski Aq Mt oshogbo@FreeBSD.org . Index: stable/12/lib/libcasper/services/cap_syslog/cap_syslog.3 =================================================================== --- stable/12/lib/libcasper/services/cap_syslog/cap_syslog.3 (revision 364016) +++ stable/12/lib/libcasper/services/cap_syslog/cap_syslog.3 (revision 364017) @@ -1,107 +1,112 @@ .\" Copyright (c) 2018 Mariusz Zaborski .\" 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 January 27, 2018 +.Dd May 5, 2020 .Dt CAP_SYSLOG 3 .Os .Sh NAME .Nm cap_syslog .Nm cap_vsyslog .Nm cap_openlog .Nm cap_closelog .Nm cap_setlogmask .Nd "library for syslog in capability mode" .Sh LIBRARY .Lb libcap_syslog .Sh SYNOPSIS .In libcasper.h .In casper/cap_syslog.h .Ft void .Fn cap_syslog "cap_channel_t *chan" "int pri" "const char *fmt" "..." .Ft void .Fn cap_vsyslog "cap_channel_t *chan" "int priority" "const char *fmt" "va_list ap" .Ft void .Fn cap_openlog "cap_channel_t *chan" "const char *ident" "int logopt" "int facility" .Ft void .Fn cap_closelog "cap_channel_t *chan" .Ft int .Fn cap_setlogmask "cap_channel_t *chan" "int maskpri" .Sh DESCRIPTION The functions .Fn cap_syslog .Fn cap_vsyslog .Fn cap_openlog .Fn cap_closelog .Fn cap_setlogmask are respectively equivalent to .Xr syslog 3 , .Xr vsyslog 3 , .Xr openlog 3 , .Xr closelog 3 , .Xr setlogmask 3 except that the connection to the .Nm system.syslog 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.syslog casper service to log messages. .Bd -literal cap_channel_t *capcas, *capsyslog; /* 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.syslog service. */ capsyslog = cap_service_open(capcas, "system.syslog"); if (capsyslog == NULL) err(1, "Unable to open system.syslog service"); /* Close Casper capability, we don't need it anymore. */ cap_close(capcas); /* Let's log something. */ cap_syslog(capsyslog, LOG_NOTICE, "System logs from capability mode."); .Ed .Sh SEE ALSO .Xr cap_enter 2 , .Xr closelog 3 , .Xr err 3 , .Xr openlog 3 , .Xr setlogmask 3 .Xr syslog 3 , .Xr vsyslog 3 , .Xr capsicum 4 , .Xr nv 9 +.Sh HISTORY +The +.Nm cap_syslog +service first appeared in +.Fx 10.3 . .Sh AUTHORS .An Mariusz Zaborski Aq Mt oshogbo@FreeBSD.org Index: stable/12 =================================================================== --- stable/12 (revision 364016) +++ stable/12 (revision 364017) Property changes on: stable/12 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r362230