summaryrefslogtreecommitdiff
path: root/monitor_fdpass.c
diff options
context:
space:
mode:
authorKevin Steves <stevesk@pobox.com>2002-03-22 19:32:53 +0000
committerKevin Steves <stevesk@pobox.com>2002-03-22 19:32:53 +0000
commit1adb12077974ba849984df5fd81e3c1bca327a25 (patch)
treec11f2f7d4f56d5551da0b9e6864ecc73b506da57 /monitor_fdpass.c
parent4846f4ab6989c20db4375440948266b742fa7a1f (diff)
downloadopenssh-git-1adb12077974ba849984df5fd81e3c1bca327a25.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.c30
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
}