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