xref: /freebsd/tools/regression/sockets/unix_cmsg/uc_common.h (revision ebacd8013fe5f7fdf9f6a5b286f6680dd2891036)
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 
30 struct 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 
58 extern struct uc_cfg uc_cfg;
59 
60 int uc_check_msghdr(const struct msghdr *msghdr, size_t size);
61 int uc_check_cmsghdr(const struct cmsghdr *cmsghdr, int type, size_t size);
62 void uc_output(const char *format, ...) __printflike(1, 2);
63 void uc_logmsgx(const char *format, ...) __printflike(1, 2);
64 void uc_dbgmsg(const char *format, ...) __printflike(1, 2);
65 void uc_logmsg(const char *format, ...) __printflike(1, 2);
66 void uc_vlogmsgx(const char *format, va_list ap);
67 int uc_message_recv(int fd, struct msghdr *msghdr);
68 int uc_message_send(int fd, const struct msghdr *msghdr);
69 int uc_message_sendn(int fd, struct msghdr *msghdr);
70 void uc_msghdr_init_server(struct msghdr *msghdr, struct iovec *iov,
71     void *cmsg_data, size_t cmsg_size);
72 void uc_msghdr_init_client(struct msghdr *msghdr, struct iovec *iov,
73     void *cmsg_data, size_t cmsg_size, int type, size_t arr_size);
74 int uc_socket_create(void);
75 int uc_socket_accept(int listenfd);
76 int uc_socket_close(int fd);
77 int uc_socket_connect(int fd);
78 int uc_sync_recv(void);
79 int uc_sync_send(void);
80 int uc_client_fork(void);
81 void uc_client_exit(int rv);
82 int uc_client_wait(void);
83 int 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);
85 int uc_check_scm_creds_cmsgcred(struct cmsghdr *cmsghdr);
86 int uc_check_scm_creds_sockcred(struct cmsghdr *cmsghdr);
87