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