1/*-
2 * Copyright (c) 2005 Andrey Simonenko
3 * Copyright (c) 2016 Maksym Sobolyev <sobomax@FreeBSD.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28struct uc_cfg {
29	int	sock_type;
30	const char *sock_type_str;
31	bool	debug;
32	const char *proc_name;
33	int	sync_fd[2][2];
34	int	serv_sock_fd;
35	bool	server_flag;
36	bool	send_data_flag;
37	struct sockaddr_un serv_addr_sun;
38	bool	send_array_flag;
39	pid_t	client_pid;
40	struct {
41		char	*buf_send;
42		char	*buf_recv;
43		size_t	buf_size;
44		u_int	msg_num;
45	} ipc_msg;
46	struct {
47		uid_t	uid;
48		uid_t	euid;
49		gid_t	gid;
50		gid_t	egid;
51		gid_t	*gid_arr;
52		int	gid_num;
53	} proc_cred;
54};
55
56extern struct uc_cfg uc_cfg;
57
58int uc_check_msghdr(const struct msghdr *msghdr, size_t size);
59int uc_check_cmsghdr(const struct cmsghdr *cmsghdr, int type, size_t size);
60void uc_output(const char *format, ...) __printflike(1, 2);
61void uc_logmsgx(const char *format, ...) __printflike(1, 2);
62void uc_dbgmsg(const char *format, ...) __printflike(1, 2);
63void uc_logmsg(const char *format, ...) __printflike(1, 2);
64void uc_vlogmsgx(const char *format, va_list ap);
65int uc_message_recv(int fd, struct msghdr *msghdr);
66int uc_message_send(int fd, const struct msghdr *msghdr);
67int uc_message_sendn(int fd, struct msghdr *msghdr);
68void uc_msghdr_init_server(struct msghdr *msghdr, struct iovec *iov,
69    void *cmsg_data, size_t cmsg_size);
70void uc_msghdr_init_client(struct msghdr *msghdr, struct iovec *iov,
71    void *cmsg_data, size_t cmsg_size, int type, size_t arr_size);
72int uc_socket_create(void);
73int uc_socket_accept(int listenfd);
74int uc_socket_close(int fd);
75int uc_socket_connect(int fd);
76int uc_sync_recv(void);
77int uc_sync_send(void);
78int uc_client_fork(void);
79void uc_client_exit(int rv);
80int uc_client_wait(void);
81int uc_check_groups(const char *gid_arr_str, const gid_t *gid_arr,
82    const char *gid_num_str, int gid_num, bool all_gids);
83int uc_check_scm_creds_cmsgcred(struct cmsghdr *cmsghdr);
84int uc_check_scm_creds_sockcred(struct cmsghdr *cmsghdr);
85