diff --git a/lib/libc/net/nscachedcli.c b/lib/libc/net/nscachedcli.c index 9e462b8dc39d..53f69dda7fbb 100644 --- a/lib/libc/net/nscachedcli.c +++ b/lib/libc/net/nscachedcli.c @@ -144,29 +144,27 @@ safe_read(struct cached_connection_ *connection, void *data, size_t data_size) static int send_credentials(struct cached_connection_ *connection, int type) { + union { + struct cmsghdr hdr; + char pad[CMSG_SPACE(sizeof(struct cmsgcred))]; + } cmsg; + struct msghdr mhdr; + struct iovec iov; struct kevent eventlist; int nevents; ssize_t result; int res; - struct msghdr cred_hdr; - struct iovec iov; - - struct { - struct cmsghdr hdr; - char cred[CMSG_SPACE(sizeof(struct cmsgcred))]; - } cmsg; - memset(&cmsg, 0, sizeof(cmsg)); - cmsg.hdr.cmsg_len = CMSG_LEN(sizeof(struct cmsgcred)); + cmsg.hdr.cmsg_len = CMSG_LEN(sizeof(struct cmsgcred)); cmsg.hdr.cmsg_level = SOL_SOCKET; cmsg.hdr.cmsg_type = SCM_CREDS; - memset(&cred_hdr, 0, sizeof(struct msghdr)); - cred_hdr.msg_iov = &iov; - cred_hdr.msg_iovlen = 1; - cred_hdr.msg_control = (caddr_t)&cmsg; - cred_hdr.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred)); + memset(&mhdr, 0, sizeof(mhdr)); + mhdr.msg_iov = &iov; + mhdr.msg_iovlen = 1; + mhdr.msg_control = &cmsg; + mhdr.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred)); iov.iov_base = &type; iov.iov_len = sizeof(int); @@ -178,8 +176,8 @@ send_credentials(struct cached_connection_ *connection, int type) nevents = _kevent(connection->write_queue, NULL, 0, &eventlist, 1, NULL); if (nevents == 1 && eventlist.filter == EVFILT_WRITE) { - result = (_sendmsg(connection->sockfd, &cred_hdr, - MSG_NOSIGNAL) == -1) ? -1 : 0; + result = _sendmsg(connection->sockfd, &mhdr, + MSG_NOSIGNAL) == -1 ? -1 : 0; EV_SET(&eventlist, connection->sockfd, EVFILT_WRITE, EV_ADD, 0, 0, NULL); _kevent(connection->write_queue, &eventlist, 1, NULL, 0, NULL); diff --git a/usr.sbin/nscd/nscdcli.c b/usr.sbin/nscd/nscdcli.c index 4cbcd79c9fe7..326acfae7dea 100644 --- a/usr.sbin/nscd/nscdcli.c +++ b/usr.sbin/nscd/nscdcli.c @@ -130,44 +130,41 @@ safe_read(struct nscd_connection_ *connection, void *data, size_t data_size) static int send_credentials(struct nscd_connection_ *connection, int type) { + union { + struct cmsghdr hdr; + char pad[CMSG_SPACE(sizeof(struct cmsgcred))]; + } cmsg; + struct msghdr mhdr; + struct iovec iov; struct kevent eventlist; int nevents; ssize_t result; int res; - struct msghdr cred_hdr; - struct iovec iov; - - union { - struct cmsghdr hdr; - char cred[CMSG_SPACE(sizeof(struct cmsgcred))]; - } cmsg; - TRACE_IN(send_credentials); memset(&cmsg, 0, sizeof(cmsg)); cmsg.hdr.cmsg_len = CMSG_LEN(sizeof(struct cmsgcred)); cmsg.hdr.cmsg_level = SOL_SOCKET; cmsg.hdr.cmsg_type = SCM_CREDS; - memset(&cred_hdr, 0, sizeof(struct msghdr)); - cred_hdr.msg_iov = &iov; - cred_hdr.msg_iovlen = 1; - cred_hdr.msg_control = &cmsg; - cred_hdr.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred)); + memset(&mhdr, 0, sizeof(mhdr)); + mhdr.msg_iov = &iov; + mhdr.msg_iovlen = 1; + mhdr.msg_control = &cmsg; + mhdr.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred)); iov.iov_base = &type; iov.iov_len = sizeof(int); EV_SET(&eventlist, connection->sockfd, EVFILT_WRITE, EV_ADD, - NOTE_LOWAT, sizeof(int), NULL); + NOTE_LOWAT, sizeof(int), NULL); res = kevent(connection->write_queue, &eventlist, 1, NULL, 0, NULL); nevents = kevent(connection->write_queue, NULL, 0, &eventlist, 1, NULL); if ((nevents == 1) && (eventlist.filter == EVFILT_WRITE)) { - result = (sendmsg(connection->sockfd, &cred_hdr, 0) == -1) ? -1 - : 0; + result = sendmsg(connection->sockfd, &mhdr, 0) == -1 ? -1 : 0; EV_SET(&eventlist, connection->sockfd, EVFILT_WRITE, EV_ADD, - 0, 0, NULL); + 0, 0, NULL); kevent(connection->write_queue, &eventlist, 1, NULL, 0, NULL); TRACE_OUT(send_credentials); return (result); diff --git a/usr.sbin/nscd/query.c b/usr.sbin/nscd/query.c index db7992b32c58..a7737c0ea9aa 100644 --- a/usr.sbin/nscd/query.c +++ b/usr.sbin/nscd/query.c @@ -155,38 +155,37 @@ clear_config_entry_part(struct configuration_entry *config_entry, static int on_query_startup(struct query_state *qstate) { - struct msghdr cred_hdr; - struct iovec iov; + union { + struct cmsghdr hdr; + char pad[CMSG_SPACE(sizeof(struct cmsgcred))]; + } cmsg; + struct msghdr mhdr; + struct iovec iov; struct cmsgcred *cred; int elem_type; - union { - struct cmsghdr hdr; - char cred[CMSG_SPACE(sizeof(struct cmsgcred))]; - } cmsg; - TRACE_IN(on_query_startup); assert(qstate != NULL); - memset(&cred_hdr, 0, sizeof(struct msghdr)); - cred_hdr.msg_iov = &iov; - cred_hdr.msg_iovlen = 1; - cred_hdr.msg_control = &cmsg; - cred_hdr.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred)); + memset(&mhdr, 0, sizeof(mhdr)); + mhdr.msg_iov = &iov; + mhdr.msg_iovlen = 1; + mhdr.msg_control = &cmsg; + mhdr.msg_controllen = sizeof(cmsg); - memset(&iov, 0, sizeof(struct iovec)); + memset(&iov, 0, sizeof(iov)); iov.iov_base = &elem_type; - iov.iov_len = sizeof(int); + iov.iov_len = sizeof(elem_type); - if (recvmsg(qstate->sockfd, &cred_hdr, 0) == -1) { + if (recvmsg(qstate->sockfd, &mhdr, 0) == -1) { TRACE_OUT(on_query_startup); return (-1); } - if (cred_hdr.msg_controllen < CMSG_LEN(sizeof(struct cmsgcred)) - || cmsg.hdr.cmsg_len < CMSG_LEN(sizeof(struct cmsgcred)) - || cmsg.hdr.cmsg_level != SOL_SOCKET - || cmsg.hdr.cmsg_type != SCM_CREDS) { + if (mhdr.msg_controllen != CMSG_SPACE(sizeof(struct cmsgcred)) || + cmsg.hdr.cmsg_len != CMSG_LEN(sizeof(struct cmsgcred)) || + cmsg.hdr.cmsg_level != SOL_SOCKET || + cmsg.hdr.cmsg_type != SCM_CREDS) { TRACE_OUT(on_query_startup); return (-1); } @@ -206,9 +205,9 @@ on_query_startup(struct query_state *qstate) return (-1); #else if ((elem_type != CET_READ_REQUEST) && - (elem_type != CET_MP_READ_SESSION_REQUEST) && - (elem_type != CET_WRITE_REQUEST) && - (elem_type != CET_MP_WRITE_SESSION_REQUEST)) { + (elem_type != CET_MP_READ_SESSION_REQUEST) && + (elem_type != CET_WRITE_REQUEST) && + (elem_type != CET_MP_WRITE_SESSION_REQUEST)) { TRACE_OUT(on_query_startup); return (-1); }