diff options
author | stevesk <stevesk> | 2002-03-22 19:32:53 +0000 |
---|---|---|
committer | stevesk <stevesk> | 2002-03-22 19:32:53 +0000 |
commit | 58d7a794f3c285e44248001269247053ce211ff3 (patch) | |
tree | a3fdb926ba790ee7b1b2d1c96f53da280a7a86e6 /monitor_fdpass.c | |
parent | 48c14ded29ba1f716de40b2ade627d694b5d846a (diff) | |
download | openssh-58d7a794f3c285e44248001269247053ce211ff3.tar.gz |
- (stevesk) [monitor_fdpass.c] support for access rights style file
descriptor passing
Diffstat (limited to 'monitor_fdpass.c')
-rw-r--r-- | monitor_fdpass.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/monitor_fdpass.c b/monitor_fdpass.c index 7785535b..fd55a277 100644 --- a/monitor_fdpass.c +++ b/monitor_fdpass.c @@ -35,12 +35,18 @@ void mm_send_fd(int socket, int fd) { struct msghdr msg; - char tmp[CMSG_SPACE(sizeof(int))]; - struct cmsghdr *cmsg; struct iovec vec; char ch; +#ifndef HAVE_ACCRIGHTS_IN_MSGHDR + char tmp[CMSG_SPACE(sizeof(int))]; + struct cmsghdr *cmsg; +#endif memset(&msg, 0, sizeof(msg)); +#ifdef HAVE_ACCRIGHTS_IN_MSGHDR + msg.msg_accrights = (caddr_t)&fd; + msg.msg_accrightslen = sizeof(fd); +#else msg.msg_control = (caddr_t)tmp; msg.msg_controllen = CMSG_LEN(sizeof(int)); cmsg = CMSG_FIRSTHDR(&msg); @@ -48,6 +54,7 @@ mm_send_fd(int socket, int fd) cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_type = SCM_RIGHTS; *(int *)CMSG_DATA(cmsg) = fd; +#endif vec.iov_base = &ch; vec.iov_len = 1; @@ -62,25 +69,40 @@ int mm_receive_fd(int socket) { struct msghdr msg; - char tmp[CMSG_SPACE(sizeof(int))]; - struct cmsghdr *cmsg; struct iovec vec; char ch; +#ifndef HAVE_ACCRIGHTS_IN_MSGHDR + char tmp[CMSG_SPACE(sizeof(int))]; + struct cmsghdr *cmsg; +#else + int fd; +#endif memset(&msg, 0, sizeof(msg)); vec.iov_base = &ch; vec.iov_len = 1; msg.msg_iov = &vec; msg.msg_iovlen = 1; +#ifdef HAVE_ACCRIGHTS_IN_MSGHDR + msg.msg_accrights = (caddr_t)&fd; + msg.msg_accrightslen = sizeof(fd); +#else msg.msg_control = tmp; msg.msg_controllen = sizeof(tmp); +#endif if (recvmsg(socket, &msg, 0) == -1) fatal("%s: recvmsg", __FUNCTION__); +#ifdef HAVE_ACCRIGHTS_IN_MSGHDR + if (msg.msg_accrightslen != sizeof(fd)) + fatal("%s: no fd", __FUNCTION__); + return fd; +#else cmsg = CMSG_FIRSTHDR(&msg); if (cmsg->cmsg_type != SCM_RIGHTS) fatal("%s: expected type %d got %d", __FUNCTION__, SCM_RIGHTS, cmsg->cmsg_type); return (*(int *)CMSG_DATA(cmsg)); +#endif } |