xref: /freebsd/usr.sbin/syslogd/syslogd_cap.h (revision 61a29eca550b80d179934a7198c41ad4d255f81c)
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 
4896468787SJake Freeland #include "syslogd.h"
4996468787SJake Freeland 
50*61a29ecaSJake Freeland /*
51*61a29ecaSJake Freeland  * Information used to verify filed integrity when executing outside of the
52*61a29ecaSJake Freeland  * security sandbox.
53*61a29ecaSJake Freeland  */
54*61a29ecaSJake Freeland struct cap_filed {
55*61a29ecaSJake Freeland 	size_t idx;
56*61a29ecaSJake Freeland 	char pipe_cmd[MAXPATHLEN];
57*61a29ecaSJake Freeland 	SLIST_ENTRY(cap_filed) next;
58*61a29ecaSJake Freeland };
59*61a29ecaSJake Freeland extern SLIST_HEAD(cfiled_list, cap_filed) cfiled_head;
60*61a29ecaSJake Freeland 
61*61a29ecaSJake Freeland int cap_p_open(cap_channel_t *, size_t, const char *, int *);
622567168dSJake Freeland nvlist_t *cap_readconfigfile(cap_channel_t *, const char *);
63*61a29ecaSJake Freeland const char *cap_ttymsg(cap_channel_t *, struct iovec *, int, const char *, int);
64*61a29ecaSJake Freeland void cap_wallmsg(cap_channel_t *, const struct filed *, struct iovec *,
65*61a29ecaSJake Freeland     const int);
66*61a29ecaSJake Freeland 
67*61a29ecaSJake Freeland int casper_p_open(nvlist_t *, nvlist_t *);
682567168dSJake Freeland int casper_readconfigfile(nvlist_t *, nvlist_t *);
69*61a29ecaSJake Freeland int casper_ttymsg(nvlist_t *, nvlist_t *);
70*61a29ecaSJake Freeland int casper_wallmsg(nvlist_t *);
712567168dSJake Freeland 
722567168dSJake Freeland nvlist_t *filed_to_nvlist(const struct filed *);
732567168dSJake Freeland nvlist_t *prop_filter_to_nvlist(const struct prop_filter *pfilter);
742567168dSJake Freeland 
752567168dSJake Freeland struct filed *nvlist_to_filed(const nvlist_t *);
762567168dSJake Freeland struct prop_filter *nvlist_to_prop_filter(const nvlist_t *nvl_prop_filter);
772567168dSJake Freeland 
782567168dSJake Freeland #else /* !WITH_CASPER */
792567168dSJake Freeland 
80*61a29ecaSJake Freeland #define	cap_p_open(chan, f_idx, prog, rpd) \
81*61a29ecaSJake Freeland 	p_open(prog, rpd)
822567168dSJake Freeland #define	cap_readconfigfile(chan, cf) \
832567168dSJake Freeland 	readconfigfile(cf)
84*61a29ecaSJake Freeland #define	cap_ttymsg(chan, iov, iovcnt, line, tmout) \
85*61a29ecaSJake Freeland 	ttymsg(iov, iovcnt, line, tmout)
86*61a29ecaSJake Freeland #define	cap_wallmsg(chan, f, iov, iovcnt) \
87*61a29ecaSJake Freeland 	wallmsg(f, iov, iovcnt)
882567168dSJake Freeland 
8996468787SJake Freeland #endif /* WITH_CASPER */
9096468787SJake Freeland 
9196468787SJake Freeland #endif /* !_SYSLOGD_CAP_H_ */
92