1296047Soshogbo/*- 2296047Soshogbo * Copyright (c) 2012-2013 The FreeBSD Foundation 3296047Soshogbo * Copyright (c) 2015 Mariusz Zaborski <oshogbo@FreeBSD.org> 4296047Soshogbo * All rights reserved. 5296047Soshogbo * 6296047Soshogbo * This software was developed by Pawel Jakub Dawidek under sponsorship from 7296047Soshogbo * the FreeBSD Foundation. 8296047Soshogbo * 9296047Soshogbo * Redistribution and use in source and binary forms, with or without 10296047Soshogbo * modification, are permitted provided that the following conditions 11296047Soshogbo * are met: 12296047Soshogbo * 1. Redistributions of source code must retain the above copyright 13296047Soshogbo * notice, this list of conditions and the following disclaimer. 14296047Soshogbo * 2. Redistributions in binary form must reproduce the above copyright 15296047Soshogbo * notice, this list of conditions and the following disclaimer in the 16296047Soshogbo * documentation and/or other materials provided with the distribution. 17296047Soshogbo * 18296047Soshogbo * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 19296047Soshogbo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20296047Soshogbo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21296047Soshogbo * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 22296047Soshogbo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23296047Soshogbo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24296047Soshogbo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25296047Soshogbo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26296047Soshogbo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27296047Soshogbo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28296047Soshogbo * SUCH DAMAGE. 29296047Soshogbo * 30296047Soshogbo * $FreeBSD$ 31296047Soshogbo */ 32296047Soshogbo 33296047Soshogbo#ifndef _LIBCASPER_H_ 34296047Soshogbo#define _LIBCASPER_H_ 35296047Soshogbo 36296047Soshogbo#include <sys/types.h> 37296047Soshogbo 38296047Soshogbo#ifndef _NVLIST_T_DECLARED 39296047Soshogbo#define _NVLIST_T_DECLARED 40296047Soshogbostruct nvlist; 41296047Soshogbo 42296047Soshogbotypedef struct nvlist nvlist_t; 43296047Soshogbo#endif 44296047Soshogbo 45296047Soshogbo#ifndef _CAP_CHANNEL_T_DECLARED 46296047Soshogbo#define _CAP_CHANNEL_T_DECLARED 47296047Soshogbostruct cap_channel; 48296047Soshogbo 49296047Soshogbotypedef struct cap_channel cap_channel_t; 50296047Soshogbo#endif 51296047Soshogbo 52296047Soshogbo/* 53296047Soshogbo * The functions opens unrestricted communication channel to Casper. 54296047Soshogbo */ 55296047Soshogbocap_channel_t *cap_init(void); 56296047Soshogbo 57296047Soshogbo/* 58296047Soshogbo * The functions to communicate with service. 59296047Soshogbo */ 60296047Soshogbocap_channel_t *cap_service_open(const cap_channel_t *chan, const char *name); 61296047Soshogboint cap_service_limit(const cap_channel_t *chan, 62296047Soshogbo const char * const *names, size_t nnames); 63296047Soshogbo 64296047Soshogbo/* 65296047Soshogbo * The function creates cap_channel_t based on the given socket. 66296047Soshogbo */ 67296047Soshogbocap_channel_t *cap_wrap(int sock); 68296047Soshogbo 69296047Soshogbo/* 70296047Soshogbo * The function returns communication socket and frees cap_channel_t. 71296047Soshogbo */ 72296047Soshogboint cap_unwrap(cap_channel_t *chan); 73296047Soshogbo 74296047Soshogbo/* 75296047Soshogbo * The function clones the given capability. 76296047Soshogbo */ 77296047Soshogbocap_channel_t *cap_clone(const cap_channel_t *chan); 78296047Soshogbo 79296047Soshogbo/* 80296047Soshogbo * The function closes the given capability. 81296047Soshogbo */ 82296047Soshogbovoid cap_close(cap_channel_t *chan); 83296047Soshogbo 84296047Soshogbo/* 85296047Soshogbo * The function returns socket descriptor associated with the given 86296047Soshogbo * cap_channel_t for use with select(2)/kqueue(2)/etc. 87296047Soshogbo */ 88296047Soshogboint cap_sock(const cap_channel_t *chan); 89296047Soshogbo 90296047Soshogbo/* 91296047Soshogbo * The function limits the given capability. 92296047Soshogbo * It always destroys 'limits' on return. 93296047Soshogbo */ 94296047Soshogboint cap_limit_set(const cap_channel_t *chan, nvlist_t *limits); 95296047Soshogbo 96296047Soshogbo/* 97296047Soshogbo * The function returns current limits of the given capability. 98296047Soshogbo */ 99296047Soshogboint cap_limit_get(const cap_channel_t *chan, nvlist_t **limitsp); 100296047Soshogbo 101296047Soshogbo/* 102296047Soshogbo * Function sends nvlist over the given capability. 103296047Soshogbo */ 104296047Soshogboint cap_send_nvlist(const cap_channel_t *chan, const nvlist_t *nvl); 105296047Soshogbo/* 106296047Soshogbo * Function receives nvlist over the given capability. 107296047Soshogbo */ 108296047Soshogbonvlist_t *cap_recv_nvlist(const cap_channel_t *chan, int flags); 109296047Soshogbo/* 110296047Soshogbo * Function sends the given nvlist, destroys it and receives new nvlist in 111296047Soshogbo * response over the given capability. 112296047Soshogbo */ 113296047Soshogbonvlist_t *cap_xfer_nvlist(const cap_channel_t *chan, nvlist_t *nvl, int flags); 114296047Soshogbo 115296047Soshogbo#endif /* !_LIBCASPER_H_ */ 116