uc_cfg
if (uc_cfg.sock_type == SOCK_STREAM) {
if (uc_cfg.sock_type == SOCK_STREAM && fd2 >= 0)
for (i = 1; i <= uc_cfg.ipc_msg.msg_num; ++i) {
if (i > uc_cfg.ipc_msg.msg_num)
if (uc_cfg.sock_type == SOCK_STREAM && fd2 >= 0)
if (uc_cfg.sock_type == SOCK_STREAM) {
if (i > uc_cfg.ipc_msg.msg_num)
if (uc_cfg.sock_type == SOCK_STREAM && fd2 >= 0)
cmsg1_size = CMSG_SPACE(SOCKCREDSIZE(uc_cfg.proc_cred.gid_num));
if (uc_cfg.sock_type == SOCK_STREAM) {
for (i = 1; i <= uc_cfg.ipc_msg.msg_num; ++i) {
if (i == 1 || uc_cfg.sock_type == SOCK_DGRAM) {
if (xucred->cr_uid != uc_cfg.proc_cred.euid) {
(u_long)xucred->cr_uid, (u_long)uc_cfg.proc_cred.euid);
if (xucred->cr_groups[0] != uc_cfg.proc_cred.egid) {
(u_long)xucred->cr_groups[0], (u_long)uc_cfg.proc_cred.egid);
if (uc_cfg.sock_type == SOCK_STREAM) {
for (i = 1; i <= uc_cfg.ipc_msg.msg_num; ++i) {
if (i > 1 && uc_cfg.sock_type == SOCK_STREAM) {
if (i > uc_cfg.ipc_msg.msg_num)
if (uc_cfg.sock_type == SOCK_STREAM && fd2 >= 0)
cmsg_size = CMSG_SPACE(SOCKCREDSIZE(uc_cfg.proc_cred.gid_num));
if (uc_cfg.debug) {
fd = socket(PF_LOCAL, uc_cfg.sock_type, 0);
uc_logmsg("socket_create: socket(PF_LOCAL, %s, 0)", uc_cfg.sock_type_str);
if (uc_cfg.server_flag)
uc_cfg.serv_sock_fd = fd;
if (uc_cfg.server_flag) {
if (bind(fd, (struct sockaddr *)&uc_cfg.serv_addr_sun,
uc_cfg.serv_addr_sun.sun_len) < 0) {
uc_cfg.serv_addr_sun.sun_path);
if (uc_cfg.sock_type == SOCK_STREAM) {
if (uc_cfg.server_flag)
if (unlink(uc_cfg.serv_addr_sun.sun_path) < 0)
uc_cfg.serv_addr_sun.sun_path);
if (uc_cfg.server_flag && fd == uc_cfg.serv_sock_fd)
if (unlink(uc_cfg.serv_addr_sun.sun_path) < 0) {
uc_cfg.serv_addr_sun.sun_path);
if (connect(fd, (struct sockaddr *)&uc_cfg.serv_addr_sun,
uc_cfg.serv_addr_sun.sun_len) < 0) {
uc_logmsg("socket_connect: connect(%s)", uc_cfg.serv_addr_sun.sun_path);
fd = uc_cfg.sync_fd[uc_cfg.server_flag ? SYNC_SERVER : SYNC_CLIENT][SYNC_RECV];
fd = uc_cfg.sync_fd[uc_cfg.server_flag ? SYNC_CLIENT : SYNC_SERVER][SYNC_SEND];
if (!uc_cfg.send_data_flag)
for (i = 1; i <= uc_cfg.ipc_msg.msg_num; ++i) {
if (!uc_cfg.send_data_flag)
if (memcmp(uc_cfg.ipc_msg.buf_recv, uc_cfg.ipc_msg.buf_send, size) != 0) {
if (uc_cfg.send_data_flag) {
iov->iov_base = uc_cfg.server_flag ?
uc_cfg.ipc_msg.buf_recv : uc_cfg.ipc_msg.buf_send;
iov->iov_len = uc_cfg.ipc_msg.buf_size;
if (uc_cfg.send_array_flag)
msghdr->msg_controllen = uc_cfg.send_array_flag ?
cmsghdr->cmsg_len = CMSG_LEN(uc_cfg.send_array_flag ? arr_size : 0);
if (pipe(uc_cfg.sync_fd[SYNC_SERVER]) < 0 ||
pipe(uc_cfg.sync_fd[SYNC_CLIENT]) < 0) {
uc_cfg.client_pid = fork();
if (uc_cfg.client_pid == (pid_t)-1) {
if (uc_cfg.client_pid == 0) {
uc_cfg.proc_name = "CLIENT";
uc_cfg.server_flag = false;
fd1 = uc_cfg.sync_fd[SYNC_SERVER][SYNC_RECV];
fd2 = uc_cfg.sync_fd[SYNC_CLIENT][SYNC_SEND];
fd1 = uc_cfg.sync_fd[SYNC_SERVER][SYNC_SEND];
fd2 = uc_cfg.sync_fd[SYNC_CLIENT][SYNC_RECV];
return (uc_cfg.client_pid != 0);
if (close(uc_cfg.sync_fd[SYNC_SERVER][SYNC_SEND]) < 0 ||
close(uc_cfg.sync_fd[SYNC_CLIENT][SYNC_RECV]) < 0) {
if (close(uc_cfg.sync_fd[SYNC_SERVER][SYNC_RECV]) < 0 ||
close(uc_cfg.sync_fd[SYNC_CLIENT][SYNC_SEND]) < 0) {
pid = waitpid(uc_cfg.client_pid, &status, 0);
if (gid_num != uc_cfg.proc_cred.gid_num) {
uc_cfg.proc_cred.gid_num);
if (gid_num > uc_cfg.proc_cred.gid_num) {
uc_cfg.proc_cred.gid_num);
if (memcmp(gid_arr, uc_cfg.proc_cred.gid_arr,
if (gid_arr[i] != uc_cfg.proc_cred.gid_arr[i]) {
(u_long)uc_cfg.proc_cred.gid_arr[i]);
if (cmcred->cmcred_pid != uc_cfg.client_pid) {
(long)cmcred->cmcred_pid, (long)uc_cfg.client_pid);
if (cmcred->cmcred_uid != uc_cfg.proc_cred.uid) {
(u_long)cmcred->cmcred_uid, (u_long)uc_cfg.proc_cred.uid);
if (cmcred->cmcred_euid != uc_cfg.proc_cred.euid) {
(u_long)cmcred->cmcred_euid, (u_long)uc_cfg.proc_cred.euid);
if (cmcred->cmcred_gid != uc_cfg.proc_cred.gid) {
(u_long)cmcred->cmcred_gid, (u_long)uc_cfg.proc_cred.gid);
if (cmcred->cmcred_groups[0] != uc_cfg.proc_cred.egid) {
(u_long)cmcred->cmcred_groups[0], (u_long)uc_cfg.proc_cred.egid);
SOCKCREDSIZE(uc_cfg.proc_cred.gid_num)) < 0)
if (sc->sc_uid != uc_cfg.proc_cred.uid) {
(u_long)sc->sc_uid, (u_long)uc_cfg.proc_cred.uid);
if (sc->sc_euid != uc_cfg.proc_cred.euid) {
(u_long)sc->sc_euid, (u_long)uc_cfg.proc_cred.euid);
if (sc->sc_gid != uc_cfg.proc_cred.gid) {
(u_long)sc->sc_gid, (u_long)uc_cfg.proc_cred.gid);
if (sc->sc_egid != uc_cfg.proc_cred.egid) {
(u_long)sc->sc_egid, (u_long)uc_cfg.proc_cred.egid);
if (sc->sc_ngroups != uc_cfg.proc_cred.gid_num) {
sc->sc_ngroups, uc_cfg.proc_cred.gid_num);
uc_output("%s: %s\n", uc_cfg.proc_name, buf);
uc_output("%s: %s: %s\n", uc_cfg.proc_name, buf,
uc_output("%s: %s\n", uc_cfg.proc_name, buf);
extern struct uc_cfg uc_cfg;
struct uc_cfg uc_cfg;
uc_cfg.sock_type = type;
uc_cfg.sock_type_str = "SOCK_STREAM";
uc_cfg.sock_type_str = "SOCK_DGRAM";
uc_output("Running tests for %s sockets:\n", uc_cfg.sock_type_str);
uc_cfg.proc_name = "SERVER";
if (uc_cfg.ipc_msg.buf_size == 0)
uc_cfg.ipc_msg.buf_send = uc_cfg.ipc_msg.buf_recv = NULL;
uc_cfg.ipc_msg.buf_send = malloc(uc_cfg.ipc_msg.buf_size);
uc_cfg.ipc_msg.buf_recv = malloc(uc_cfg.ipc_msg.buf_size);
if (uc_cfg.ipc_msg.buf_send == NULL || uc_cfg.ipc_msg.buf_recv == NULL) {
for (idx = 0; idx < uc_cfg.ipc_msg.buf_size; ++idx)
uc_cfg.ipc_msg.buf_send[idx] = (char)idx;
uc_cfg.proc_cred.uid = getuid();
uc_cfg.proc_cred.euid = geteuid();
uc_cfg.proc_cred.gid = getgid();
uc_cfg.proc_cred.egid = getegid();
uc_cfg.proc_cred.gid_num = getgroups(0, (gid_t *)NULL);
if (uc_cfg.proc_cred.gid_num < 0) {
uc_cfg.proc_cred.gid_arr = malloc(uc_cfg.proc_cred.gid_num *
sizeof(*uc_cfg.proc_cred.gid_arr));
if (uc_cfg.proc_cred.gid_arr == NULL) {
if (getgroups(uc_cfg.proc_cred.gid_num, uc_cfg.proc_cred.gid_arr) < 0) {
memset(&uc_cfg.serv_addr_sun, 0, sizeof(uc_cfg.serv_addr_sun));
rv = snprintf(uc_cfg.serv_addr_sun.sun_path, sizeof(uc_cfg.serv_addr_sun.sun_path),
"%s/%s", work_dir, uc_cfg.proc_name);
if ((size_t)rv >= sizeof(uc_cfg.serv_addr_sun.sun_path)) {
uc_cfg.serv_addr_sun.sun_family = PF_LOCAL;
uc_cfg.serv_addr_sun.sun_len = SUN_LEN(&uc_cfg.serv_addr_sun);
memset(&uc_cfg, '\0', sizeof(uc_cfg));
uc_cfg.debug = false;
uc_cfg.server_flag = true;
uc_cfg.send_data_flag = true;
uc_cfg.send_array_flag = true;
uc_cfg.ipc_msg.buf_size = IPC_MSG_SIZE_DEF;
uc_cfg.ipc_msg.msg_num = IPC_MSG_NUM_DEF;
uc_cfg.debug = true;
uc_cfg.ipc_msg.msg_num = strtonum(optarg, 1,
uc_cfg.ipc_msg.buf_size = strtonum(optarg, 0,
uc_cfg.send_data_flag = false;
uc_cfg.send_array_flag = false;