diff options
Diffstat (limited to 'monitor_fdpass.c')
-rw-r--r-- | monitor_fdpass.c | 56 |
1 files changed, 36 insertions, 20 deletions
diff --git a/monitor_fdpass.c b/monitor_fdpass.c index 9f8e9cd55..a572302e8 100644 --- a/monitor_fdpass.c +++ b/monitor_fdpass.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: monitor_fdpass.c,v 1.12 2006/08/03 03:34:42 deraadt Exp $ */ | 1 | /* $OpenBSD: monitor_fdpass.c,v 1.13 2007/09/04 03:21:03 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright 2001 Niels Provos <provos@citi.umich.edu> | 3 | * Copyright 2001 Niels Provos <provos@citi.umich.edu> |
4 | * All rights reserved. | 4 | * All rights reserved. |
@@ -40,7 +40,7 @@ | |||
40 | #include "log.h" | 40 | #include "log.h" |
41 | #include "monitor_fdpass.h" | 41 | #include "monitor_fdpass.h" |
42 | 42 | ||
43 | void | 43 | int |
44 | mm_send_fd(int sock, int fd) | 44 | mm_send_fd(int sock, int fd) |
45 | { | 45 | { |
46 | #if defined(HAVE_SENDMSG) && (defined(HAVE_ACCRIGHTS_IN_MSGHDR) || defined(HAVE_CONTROL_IN_MSGHDR)) | 46 | #if defined(HAVE_SENDMSG) && (defined(HAVE_ACCRIGHTS_IN_MSGHDR) || defined(HAVE_CONTROL_IN_MSGHDR)) |
@@ -72,15 +72,21 @@ mm_send_fd(int sock, int fd) | |||
72 | msg.msg_iov = &vec; | 72 | msg.msg_iov = &vec; |
73 | msg.msg_iovlen = 1; | 73 | msg.msg_iovlen = 1; |
74 | 74 | ||
75 | if ((n = sendmsg(sock, &msg, 0)) == -1) | 75 | if ((n = sendmsg(sock, &msg, 0)) == -1) { |
76 | fatal("%s: sendmsg(%d): %s", __func__, fd, | 76 | error("%s: sendmsg(%d): %s", __func__, fd, |
77 | strerror(errno)); | 77 | strerror(errno)); |
78 | if (n != 1) | 78 | return -1; |
79 | fatal("%s: sendmsg: expected sent 1 got %ld", | 79 | } |
80 | |||
81 | if (n != 1) { | ||
82 | error("%s: sendmsg: expected sent 1 got %ld", | ||
80 | __func__, (long)n); | 83 | __func__, (long)n); |
84 | return -1; | ||
85 | } | ||
86 | return 0; | ||
81 | #else | 87 | #else |
82 | fatal("%s: UsePrivilegeSeparation=yes not supported", | 88 | error("%s: file descriptor passing not supported", __func__); |
83 | __func__); | 89 | return -1; |
84 | #endif | 90 | #endif |
85 | } | 91 | } |
86 | 92 | ||
@@ -111,29 +117,39 @@ mm_receive_fd(int sock) | |||
111 | msg.msg_controllen = sizeof(tmp); | 117 | msg.msg_controllen = sizeof(tmp); |
112 | #endif | 118 | #endif |
113 | 119 | ||
114 | if ((n = recvmsg(sock, &msg, 0)) == -1) | 120 | if ((n = recvmsg(sock, &msg, 0)) == -1) { |
115 | fatal("%s: recvmsg: %s", __func__, strerror(errno)); | 121 | error("%s: recvmsg: %s", __func__, strerror(errno)); |
116 | if (n != 1) | 122 | return -1; |
117 | fatal("%s: recvmsg: expected received 1 got %ld", | 123 | } |
124 | if (n != 1) { | ||
125 | error("%s: recvmsg: expected received 1 got %ld", | ||
118 | __func__, (long)n); | 126 | __func__, (long)n); |
127 | return -1; | ||
128 | } | ||
119 | 129 | ||
120 | #ifdef HAVE_ACCRIGHTS_IN_MSGHDR | 130 | #ifdef HAVE_ACCRIGHTS_IN_MSGHDR |
121 | if (msg.msg_accrightslen != sizeof(fd)) | 131 | if (msg.msg_accrightslen != sizeof(fd)) { |
122 | fatal("%s: no fd", __func__); | 132 | error("%s: no fd", __func__); |
133 | return -1; | ||
134 | } | ||
123 | #else | 135 | #else |
124 | cmsg = CMSG_FIRSTHDR(&msg); | 136 | cmsg = CMSG_FIRSTHDR(&msg); |
125 | if (cmsg == NULL) | 137 | if (cmsg == NULL) { |
126 | fatal("%s: no message header", __func__); | 138 | error("%s: no message header", __func__); |
139 | return -1; | ||
140 | } | ||
127 | #ifndef BROKEN_CMSG_TYPE | 141 | #ifndef BROKEN_CMSG_TYPE |
128 | if (cmsg->cmsg_type != SCM_RIGHTS) | 142 | if (cmsg->cmsg_type != SCM_RIGHTS) { |
129 | fatal("%s: expected type %d got %d", __func__, | 143 | error("%s: expected type %d got %d", __func__, |
130 | SCM_RIGHTS, cmsg->cmsg_type); | 144 | SCM_RIGHTS, cmsg->cmsg_type); |
145 | return -1; | ||
146 | } | ||
131 | #endif | 147 | #endif |
132 | fd = (*(int *)CMSG_DATA(cmsg)); | 148 | fd = (*(int *)CMSG_DATA(cmsg)); |
133 | #endif | 149 | #endif |
134 | return fd; | 150 | return fd; |
135 | #else | 151 | #else |
136 | fatal("%s: UsePrivilegeSeparation=yes not supported", | 152 | error("%s: file descriptor passing not supported", __func__); |
137 | __func__); | 153 | return -1; |
138 | #endif | 154 | #endif |
139 | } | 155 | } |