xref: /freebsd/usr.sbin/syslogd/syslogd_cap.h (revision 897240c7d666744137da6125feabf3c3a5522ada)
196468787SJake Freeland /*-
296468787SJake Freeland  * SPDX-License-Identifier: BSD-2-Clause
396468787SJake Freeland  *
496468787SJake Freeland  * Copyright (c) 2023 The FreeBSD Foundation
596468787SJake Freeland  *
696468787SJake Freeland  * This software was developed by Jake Freeland <jfree@FreeBSD.org>
796468787SJake Freeland  * under sponsorship from the FreeBSD Foundation.
896468787SJake Freeland  *
996468787SJake Freeland  * Redistribution and use in source and binary forms, with or without
1096468787SJake Freeland  * modification, are permitted provided that the following conditions
1196468787SJake Freeland  * are met:
1296468787SJake Freeland  * 1. Redistributions of source code must retain the above copyright
1396468787SJake Freeland  *    notice, this list of conditions and the following disclaimer.
1496468787SJake Freeland  * 2. Redistributions in binary form must reproduce the above copyright
1596468787SJake Freeland  *    notice, this list of conditions and the following disclaimer in the
1696468787SJake Freeland  *    documentation and/or other materials provided with the distribution.
1796468787SJake Freeland  *
1896468787SJake Freeland  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1996468787SJake Freeland  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2096468787SJake Freeland  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2196468787SJake Freeland  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2296468787SJake Freeland  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2396468787SJake Freeland  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2496468787SJake Freeland  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2596468787SJake Freeland  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2696468787SJake Freeland  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2796468787SJake Freeland  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2896468787SJake Freeland  * SUCH DAMAGE.
2996468787SJake Freeland  */
3096468787SJake Freeland 
3196468787SJake Freeland #ifndef _SYSLOGD_CAP_H_
3296468787SJake Freeland #define _SYSLOGD_CAP_H_
3396468787SJake Freeland 
3496468787SJake Freeland #include <sys/nv.h>
3596468787SJake Freeland 
3696468787SJake Freeland #include <libcasper.h>
3796468787SJake Freeland 
3896468787SJake Freeland #include <casper/cap_net.h>
3996468787SJake Freeland 
4096468787SJake Freeland #ifdef WITH_CASPER
4196468787SJake Freeland 
4296468787SJake Freeland #include <sys/capsicum.h>
4396468787SJake Freeland #include <sys/dnv.h>
4496468787SJake Freeland 
4596468787SJake Freeland #include <capsicum_helpers.h>
4696468787SJake Freeland #include <libcasper_service.h>
4796468787SJake Freeland 
48*897240c7SJake Freeland #include <casper/cap_net.h>
49*897240c7SJake Freeland 
5096468787SJake Freeland #include "syslogd.h"
5196468787SJake Freeland 
5261a29ecaSJake Freeland /*
5361a29ecaSJake Freeland  * Information used to verify filed integrity when executing outside of the
5461a29ecaSJake Freeland  * security sandbox.
5561a29ecaSJake Freeland  */
5661a29ecaSJake Freeland struct cap_filed {
5761a29ecaSJake Freeland 	size_t idx;
5861a29ecaSJake Freeland 	char pipe_cmd[MAXPATHLEN];
5961a29ecaSJake Freeland 	SLIST_ENTRY(cap_filed) next;
6061a29ecaSJake Freeland };
6161a29ecaSJake Freeland extern SLIST_HEAD(cfiled_list, cap_filed) cfiled_head;
6261a29ecaSJake Freeland 
6361a29ecaSJake Freeland int cap_p_open(cap_channel_t *, size_t, const char *, int *);
642567168dSJake Freeland nvlist_t *cap_readconfigfile(cap_channel_t *, const char *);
6561a29ecaSJake Freeland const char *cap_ttymsg(cap_channel_t *, struct iovec *, int, const char *, int);
6661a29ecaSJake Freeland void cap_wallmsg(cap_channel_t *, const struct filed *, struct iovec *,
6761a29ecaSJake Freeland     const int);
6861a29ecaSJake Freeland 
6961a29ecaSJake Freeland int casper_p_open(nvlist_t *, nvlist_t *);
702567168dSJake Freeland int casper_readconfigfile(nvlist_t *, nvlist_t *);
7161a29ecaSJake Freeland int casper_ttymsg(nvlist_t *, nvlist_t *);
7261a29ecaSJake Freeland int casper_wallmsg(nvlist_t *);
732567168dSJake Freeland 
742567168dSJake Freeland nvlist_t *filed_to_nvlist(const struct filed *);
752567168dSJake Freeland nvlist_t *prop_filter_to_nvlist(const struct prop_filter *pfilter);
762567168dSJake Freeland 
772567168dSJake Freeland struct filed *nvlist_to_filed(const nvlist_t *);
782567168dSJake Freeland struct prop_filter *nvlist_to_prop_filter(const nvlist_t *nvl_prop_filter);
792567168dSJake Freeland 
802567168dSJake Freeland #else /* !WITH_CASPER */
812567168dSJake Freeland 
8261a29ecaSJake Freeland #define	cap_p_open(chan, f_idx, prog, rpd) \
8361a29ecaSJake Freeland 	p_open(prog, rpd)
842567168dSJake Freeland #define	cap_readconfigfile(chan, cf) \
852567168dSJake Freeland 	readconfigfile(cf)
8661a29ecaSJake Freeland #define	cap_ttymsg(chan, iov, iovcnt, line, tmout) \
8761a29ecaSJake Freeland 	ttymsg(iov, iovcnt, line, tmout)
8861a29ecaSJake Freeland #define	cap_wallmsg(chan, f, iov, iovcnt) \
8961a29ecaSJake Freeland 	wallmsg(f, iov, iovcnt)
902567168dSJake Freeland 
9196468787SJake Freeland #endif /* WITH_CASPER */
9296468787SJake Freeland 
9396468787SJake Freeland #endif /* !_SYSLOGD_CAP_H_ */
94