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