2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2012-2013 The FreeBSD Foundation
5 * Copyright (c) 2015-2017 Mariusz Zaborski <oshogbo@FreeBSD.org>
8 * This software was developed by Pawel Jakub Dawidek under sponsorship from
9 * the FreeBSD Foundation.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 #include <sys/types.h>
48 #ifndef _NVLIST_T_DECLARED
49 #define _NVLIST_T_DECLARED
52 typedef struct nvlist nvlist_t;
55 #ifndef _CAP_CHANNEL_T_DECLARED
56 #define _CAP_CHANNEL_T_DECLARED
60 typedef struct cap_channel cap_channel_t;
61 #define CASPER_SUPPORT (1)
66 typedef struct cap_channel cap_channel_t;
67 #define CASPER_SUPPORT (0)
68 #endif /* ! WITH_CASPER */
69 #endif /* ! _CAP_CHANNEL_T_DECLARED */
72 * The functions opens unrestricted communication channel to Casper.
75 cap_channel_t *cap_init(void);
77 static inline cap_channel_t *
82 chan = malloc(sizeof(*chan));
91 * The functions to communicate with service.
94 cap_channel_t *cap_service_open(const cap_channel_t *chan, const char *name);
95 int cap_service_limit(const cap_channel_t *chan,
96 const char * const *names, size_t nnames);
98 #define cap_service_open(chan, name) (cap_init())
99 #define cap_service_limit(chan, names, nnames) (0)
103 * The function creates cap_channel_t based on the given socket.
106 cap_channel_t *cap_wrap(int sock);
108 static inline cap_channel_t *
122 * The function returns communication socket and frees cap_channel_t.
125 int cap_unwrap(cap_channel_t *chan);
128 cap_unwrap(cap_channel_t *chan)
139 * The function clones the given capability.
142 cap_channel_t *cap_clone(const cap_channel_t *chan);
144 static inline cap_channel_t *
145 cap_clone(const cap_channel_t *chan)
147 cap_channel_t *newchan;
149 newchan = cap_init();
150 if (newchan == NULL) {
154 if (chan->cch_fd == -1) {
155 newchan->cch_fd = -1;
157 newchan->cch_fd = dup(chan->cch_fd);
158 if (newchan->cch_fd < 0) {
169 * The function closes the given capability.
172 void cap_close(cap_channel_t *chan);
175 cap_close(cap_channel_t *chan)
178 if (chan->cch_fd >= 0) {
186 * The function returns socket descriptor associated with the given
187 * cap_channel_t for use with select(2)/kqueue(2)/etc.
190 int cap_sock(const cap_channel_t *chan);
192 #define cap_sock(chan) (chan->cch_fd)
196 * The function limits the given capability.
197 * It always destroys 'limits' on return.
200 int cap_limit_set(const cap_channel_t *chan, nvlist_t *limits);
202 #define cap_limit_set(chan, limits) (0)
206 * The function returns current limits of the given capability.
209 int cap_limit_get(const cap_channel_t *chan, nvlist_t **limitsp);
212 cap_limit_get(const cap_channel_t *chan __unused, nvlist_t **limitsp)
215 *limitsp = nvlist_create(0);
221 * Function sends nvlist over the given capability.
224 int cap_send_nvlist(const cap_channel_t *chan, const nvlist_t *nvl);
226 #define cap_send_nvlist(chan, nvl) (0)
230 * Function receives nvlist over the given capability.
233 nvlist_t *cap_recv_nvlist(const cap_channel_t *chan, int flags);
235 #define cap_recv_nvlist(chan, flags) (0)
239 * Function sends the given nvlist, destroys it and receives new nvlist in
240 * response over the given capability.
243 nvlist_t *cap_xfer_nvlist(const cap_channel_t *chan, nvlist_t *nvl, int flags);
245 static inline nvlist_t *
246 cap_xfer_nvlist(const cap_channel_t *chan __unused, nvlist_t *nvl, int flags)
250 return (nvlist_create(flags));
254 #endif /* !_LIBCASPER_H_ */