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 * $FreeBSD$
28 */
29
30struct uc_cfg {
31	int	sock_type;
32	const char *sock_type_str;
33	bool	debug;
34	const char *proc_name;
35	int	sync_fd[2][2];
36	int	serv_sock_fd;
37	bool	server_flag;
38	bool	send_data_flag;
39	struct sockaddr_un serv_addr_sun;
40	bool	send_array_flag;
41	pid_t	client_pid;
42	struct {
43		char	*buf_send;
44		char	*buf_recv;
45		size_t	buf_size;
46		u_int	msg_num;
47	} ipc_msg;
48	struct {
49		uid_t	uid;
50		uid_t	euid;
51		gid_t	gid;
52		gid_t	egid;
53		gid_t	*gid_arr;
54		int	gid_num;
55	} proc_cred;
56};
57
58extern struct uc_cfg uc_cfg;
59
60int uc_check_msghdr(const struct msghdr *msghdr, size_t size);
61int uc_check_cmsghdr(const struct cmsghdr *cmsghdr, int type, size_t size);
62void uc_output(const char *format, ...) __printflike(1, 2);
63void uc_logmsgx(const char *format, ...) __printflike(1, 2);
64void uc_dbgmsg(const char *format, ...) __printflike(1, 2);
65void uc_logmsg(const char *format, ...) __printflike(1, 2);
66void uc_vlogmsgx(const char *format, va_list ap);
67int uc_message_recv(int fd, struct msghdr *msghdr);
68int uc_message_send(int fd, const struct msghdr *msghdr);
69int uc_message_sendn(int fd, struct msghdr *msghdr);
70void uc_msghdr_init_server(struct msghdr *msghdr, struct iovec *iov,
71    void *cmsg_data, size_t cmsg_size);
72void uc_msghdr_init_client(struct msghdr *msghdr, struct iovec *iov,
73    void *cmsg_data, size_t cmsg_size, int type, size_t arr_size);
74int uc_socket_create(void);
75int uc_socket_accept(int listenfd);
76int uc_socket_close(int fd);
77int uc_socket_connect(int fd);
78int uc_sync_recv(void);
79int uc_sync_send(void);
80int uc_client_fork(void);
81void uc_client_exit(int rv);
82int uc_client_wait(void);
83int uc_check_groups(const char *gid_arr_str, const gid_t *gid_arr,
84    const char *gid_num_str, int gid_num, bool all_gids);
85int uc_check_scm_creds_cmsgcred(struct cmsghdr *cmsghdr);
86int uc_check_scm_creds_sockcred(struct cmsghdr *cmsghdr);
87