summaryrefslogtreecommitdiff
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
parent4846f4ab6989c20db4375440948266b742fa7a1f (diff)
- (stevesk) [monitor_fdpass.c] support for access rights style file
descriptor passing
-rw-r--r--ChangeLog4
-rw-r--r--monitor_fdpass.c30
2 files changed, 29 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 81259c8e4..236b00753 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,8 @@
2 - (stevesk) HAVE_ACCRIGHTS_IN_MSGHDR configure support 2 - (stevesk) HAVE_ACCRIGHTS_IN_MSGHDR configure support
3 - (stevesk) [monitor.c monitor_wrap.c] #ifdef HAVE_PW_CLASS_IN_PASSWD 3 - (stevesk) [monitor.c monitor_wrap.c] #ifdef HAVE_PW_CLASS_IN_PASSWD
4 - (stevesk) configure and cpp __FUNCTION__ gymnastics to handle nielsisms 4 - (stevesk) configure and cpp __FUNCTION__ gymnastics to handle nielsisms
5 - (stevesk) [monitor_fdpass.c] support for access rights style file
6 descriptor passing
5 7
620020321 820020321
7 - (bal) OpenBSD CVS Sync 9 - (bal) OpenBSD CVS Sync
@@ -7996,4 +7998,4 @@
7996 - Wrote replacements for strlcpy and mkdtemp 7998 - Wrote replacements for strlcpy and mkdtemp
7997 - Released 1.0pre1 7999 - Released 1.0pre1
7998 8000
7999$Id: ChangeLog,v 1.1969 2002/03/22 18:19:53 stevesk Exp $ 8001$Id: ChangeLog,v 1.1970 2002/03/22 19:32:53 stevesk Exp $
diff --git a/monitor_fdpass.c b/monitor_fdpass.c
index 7785535bb..fd55a2776 100644
--- a/monitor_fdpass.c
+++ b/monitor_fdpass.c
@@ -35,12 +35,18 @@ void
35mm_send_fd(int socket, int fd) 35mm_send_fd(int socket, int fd)
36{ 36{
37 struct msghdr msg; 37 struct msghdr msg;
38 char tmp[CMSG_SPACE(sizeof(int))];
39 struct cmsghdr *cmsg;
40 struct iovec vec; 38 struct iovec vec;
41 char ch; 39 char ch;
40#ifndef HAVE_ACCRIGHTS_IN_MSGHDR
41 char tmp[CMSG_SPACE(sizeof(int))];
42 struct cmsghdr *cmsg;
43#endif
42 44
43 memset(&msg, 0, sizeof(msg)); 45 memset(&msg, 0, sizeof(msg));
46#ifdef HAVE_ACCRIGHTS_IN_MSGHDR
47 msg.msg_accrights = (caddr_t)&fd;
48 msg.msg_accrightslen = sizeof(fd);
49#else
44 msg.msg_control = (caddr_t)tmp; 50 msg.msg_control = (caddr_t)tmp;
45 msg.msg_controllen = CMSG_LEN(sizeof(int)); 51 msg.msg_controllen = CMSG_LEN(sizeof(int));
46 cmsg = CMSG_FIRSTHDR(&msg); 52 cmsg = CMSG_FIRSTHDR(&msg);
@@ -48,6 +54,7 @@ mm_send_fd(int socket, int fd)
48 cmsg->cmsg_level = SOL_SOCKET; 54 cmsg->cmsg_level = SOL_SOCKET;
49 cmsg->cmsg_type = SCM_RIGHTS; 55 cmsg->cmsg_type = SCM_RIGHTS;
50 *(int *)CMSG_DATA(cmsg) = fd; 56 *(int *)CMSG_DATA(cmsg) = fd;
57#endif
51 58
52 vec.iov_base = &ch; 59 vec.iov_base = &ch;
53 vec.iov_len = 1; 60 vec.iov_len = 1;
@@ -62,25 +69,40 @@ int
62mm_receive_fd(int socket) 69mm_receive_fd(int socket)
63{ 70{
64 struct msghdr msg; 71 struct msghdr msg;
65 char tmp[CMSG_SPACE(sizeof(int))];
66 struct cmsghdr *cmsg;
67 struct iovec vec; 72 struct iovec vec;
68 char ch; 73 char ch;
74#ifndef HAVE_ACCRIGHTS_IN_MSGHDR
75 char tmp[CMSG_SPACE(sizeof(int))];
76 struct cmsghdr *cmsg;
77#else
78 int fd;
79#endif
69 80
70 memset(&msg, 0, sizeof(msg)); 81 memset(&msg, 0, sizeof(msg));
71 vec.iov_base = &ch; 82 vec.iov_base = &ch;
72 vec.iov_len = 1; 83 vec.iov_len = 1;
73 msg.msg_iov = &vec; 84 msg.msg_iov = &vec;
74 msg.msg_iovlen = 1; 85 msg.msg_iovlen = 1;
86#ifdef HAVE_ACCRIGHTS_IN_MSGHDR
87 msg.msg_accrights = (caddr_t)&fd;
88 msg.msg_accrightslen = sizeof(fd);
89#else
75 msg.msg_control = tmp; 90 msg.msg_control = tmp;
76 msg.msg_controllen = sizeof(tmp); 91 msg.msg_controllen = sizeof(tmp);
92#endif
77 93
78 if (recvmsg(socket, &msg, 0) == -1) 94 if (recvmsg(socket, &msg, 0) == -1)
79 fatal("%s: recvmsg", __FUNCTION__); 95 fatal("%s: recvmsg", __FUNCTION__);
80 96
97#ifdef HAVE_ACCRIGHTS_IN_MSGHDR
98 if (msg.msg_accrightslen != sizeof(fd))
99 fatal("%s: no fd", __FUNCTION__);
100 return fd;
101#else
81 cmsg = CMSG_FIRSTHDR(&msg); 102 cmsg = CMSG_FIRSTHDR(&msg);
82 if (cmsg->cmsg_type != SCM_RIGHTS) 103 if (cmsg->cmsg_type != SCM_RIGHTS)
83 fatal("%s: expected type %d got %d", __FUNCTION__, 104 fatal("%s: expected type %d got %d", __FUNCTION__,
84 SCM_RIGHTS, cmsg->cmsg_type); 105 SCM_RIGHTS, cmsg->cmsg_type);
85 return (*(int *)CMSG_DATA(cmsg)); 106 return (*(int *)CMSG_DATA(cmsg));
107#endif
86} 108}