diff options
author | Colin Watson <cjwatson@debian.org> | 2009-12-29 21:42:53 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2009-12-29 21:42:53 +0000 |
commit | 87552344215a38d3a2b0d4d63dc151e05978bbe1 (patch) | |
tree | 9f4b96055e6ccaa915e8d59d9f2805e9e119371d /monitor_fdpass.c | |
parent | a25ec0b132c44c9e341e08464ff830de06b81126 (diff) | |
parent | ef94e5613d37bcbf880f21ee6094e4b1c7683a4c (diff) |
import openssh-5.1p1-gsskex-cjwatson-20080722.patch
Diffstat (limited to 'monitor_fdpass.c')
-rw-r--r-- | monitor_fdpass.c | 75 |
1 files changed, 49 insertions, 26 deletions
diff --git a/monitor_fdpass.c b/monitor_fdpass.c index 9f8e9cd55..cab538bc9 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.17 2008/03/24 16:11:07 deraadt 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)) |
@@ -49,7 +49,11 @@ mm_send_fd(int sock, int fd) | |||
49 | char ch = '\0'; | 49 | char ch = '\0'; |
50 | ssize_t n; | 50 | ssize_t n; |
51 | #ifndef HAVE_ACCRIGHTS_IN_MSGHDR | 51 | #ifndef HAVE_ACCRIGHTS_IN_MSGHDR |
52 | char tmp[CMSG_SPACE(sizeof(int))]; | 52 | union { |
53 | struct cmsghdr hdr; | ||
54 | char tmp[CMSG_SPACE(sizeof(int))]; | ||
55 | char buf[CMSG_SPACE(sizeof(int))]; | ||
56 | } cmsgbuf; | ||
53 | struct cmsghdr *cmsg; | 57 | struct cmsghdr *cmsg; |
54 | #endif | 58 | #endif |
55 | 59 | ||
@@ -58,8 +62,8 @@ mm_send_fd(int sock, int fd) | |||
58 | msg.msg_accrights = (caddr_t)&fd; | 62 | msg.msg_accrights = (caddr_t)&fd; |
59 | msg.msg_accrightslen = sizeof(fd); | 63 | msg.msg_accrightslen = sizeof(fd); |
60 | #else | 64 | #else |
61 | msg.msg_control = (caddr_t)tmp; | 65 | msg.msg_control = (caddr_t)&cmsgbuf.buf; |
62 | msg.msg_controllen = CMSG_LEN(sizeof(int)); | 66 | msg.msg_controllen = sizeof(cmsgbuf.buf); |
63 | cmsg = CMSG_FIRSTHDR(&msg); | 67 | cmsg = CMSG_FIRSTHDR(&msg); |
64 | cmsg->cmsg_len = CMSG_LEN(sizeof(int)); | 68 | cmsg->cmsg_len = CMSG_LEN(sizeof(int)); |
65 | cmsg->cmsg_level = SOL_SOCKET; | 69 | cmsg->cmsg_level = SOL_SOCKET; |
@@ -72,15 +76,21 @@ mm_send_fd(int sock, int fd) | |||
72 | msg.msg_iov = &vec; | 76 | msg.msg_iov = &vec; |
73 | msg.msg_iovlen = 1; | 77 | msg.msg_iovlen = 1; |
74 | 78 | ||
75 | if ((n = sendmsg(sock, &msg, 0)) == -1) | 79 | if ((n = sendmsg(sock, &msg, 0)) == -1) { |
76 | fatal("%s: sendmsg(%d): %s", __func__, fd, | 80 | error("%s: sendmsg(%d): %s", __func__, fd, |
77 | strerror(errno)); | 81 | strerror(errno)); |
78 | if (n != 1) | 82 | return -1; |
79 | fatal("%s: sendmsg: expected sent 1 got %ld", | 83 | } |
84 | |||
85 | if (n != 1) { | ||
86 | error("%s: sendmsg: expected sent 1 got %ld", | ||
80 | __func__, (long)n); | 87 | __func__, (long)n); |
88 | return -1; | ||
89 | } | ||
90 | return 0; | ||
81 | #else | 91 | #else |
82 | fatal("%s: UsePrivilegeSeparation=yes not supported", | 92 | error("%s: file descriptor passing not supported", __func__); |
83 | __func__); | 93 | return -1; |
84 | #endif | 94 | #endif |
85 | } | 95 | } |
86 | 96 | ||
@@ -94,7 +104,10 @@ mm_receive_fd(int sock) | |||
94 | char ch; | 104 | char ch; |
95 | int fd; | 105 | int fd; |
96 | #ifndef HAVE_ACCRIGHTS_IN_MSGHDR | 106 | #ifndef HAVE_ACCRIGHTS_IN_MSGHDR |
97 | char tmp[CMSG_SPACE(sizeof(int))]; | 107 | union { |
108 | struct cmsghdr hdr; | ||
109 | char buf[CMSG_SPACE(sizeof(int))]; | ||
110 | } cmsgbuf; | ||
98 | struct cmsghdr *cmsg; | 111 | struct cmsghdr *cmsg; |
99 | #endif | 112 | #endif |
100 | 113 | ||
@@ -107,33 +120,43 @@ mm_receive_fd(int sock) | |||
107 | msg.msg_accrights = (caddr_t)&fd; | 120 | msg.msg_accrights = (caddr_t)&fd; |
108 | msg.msg_accrightslen = sizeof(fd); | 121 | msg.msg_accrightslen = sizeof(fd); |
109 | #else | 122 | #else |
110 | msg.msg_control = tmp; | 123 | msg.msg_control = &cmsgbuf.buf; |
111 | msg.msg_controllen = sizeof(tmp); | 124 | msg.msg_controllen = sizeof(cmsgbuf.buf); |
112 | #endif | 125 | #endif |
113 | 126 | ||
114 | if ((n = recvmsg(sock, &msg, 0)) == -1) | 127 | if ((n = recvmsg(sock, &msg, 0)) == -1) { |
115 | fatal("%s: recvmsg: %s", __func__, strerror(errno)); | 128 | error("%s: recvmsg: %s", __func__, strerror(errno)); |
116 | if (n != 1) | 129 | return -1; |
117 | fatal("%s: recvmsg: expected received 1 got %ld", | 130 | } |
131 | if (n != 1) { | ||
132 | error("%s: recvmsg: expected received 1 got %ld", | ||
118 | __func__, (long)n); | 133 | __func__, (long)n); |
134 | return -1; | ||
135 | } | ||
119 | 136 | ||
120 | #ifdef HAVE_ACCRIGHTS_IN_MSGHDR | 137 | #ifdef HAVE_ACCRIGHTS_IN_MSGHDR |
121 | if (msg.msg_accrightslen != sizeof(fd)) | 138 | if (msg.msg_accrightslen != sizeof(fd)) { |
122 | fatal("%s: no fd", __func__); | 139 | error("%s: no fd", __func__); |
140 | return -1; | ||
141 | } | ||
123 | #else | 142 | #else |
124 | cmsg = CMSG_FIRSTHDR(&msg); | 143 | cmsg = CMSG_FIRSTHDR(&msg); |
125 | if (cmsg == NULL) | 144 | if (cmsg == NULL) { |
126 | fatal("%s: no message header", __func__); | 145 | error("%s: no message header", __func__); |
146 | return -1; | ||
147 | } | ||
127 | #ifndef BROKEN_CMSG_TYPE | 148 | #ifndef BROKEN_CMSG_TYPE |
128 | if (cmsg->cmsg_type != SCM_RIGHTS) | 149 | if (cmsg->cmsg_type != SCM_RIGHTS) { |
129 | fatal("%s: expected type %d got %d", __func__, | 150 | error("%s: expected type %d got %d", __func__, |
130 | SCM_RIGHTS, cmsg->cmsg_type); | 151 | SCM_RIGHTS, cmsg->cmsg_type); |
152 | return -1; | ||
153 | } | ||
131 | #endif | 154 | #endif |
132 | fd = (*(int *)CMSG_DATA(cmsg)); | 155 | fd = (*(int *)CMSG_DATA(cmsg)); |
133 | #endif | 156 | #endif |
134 | return fd; | 157 | return fd; |
135 | #else | 158 | #else |
136 | fatal("%s: UsePrivilegeSeparation=yes not supported", | 159 | error("%s: file descriptor passing not supported", __func__); |
137 | __func__); | 160 | return -1; |
138 | #endif | 161 | #endif |
139 | } | 162 | } |