diff options
author | jsing <> | 2014-04-15 16:37:22 +0000 |
---|---|---|
committer | jsing <> | 2014-04-15 16:37:22 +0000 |
commit | bb63ff2d125e51688213d0af9e4f785cf3865063 (patch) | |
tree | 41dd30d546977ed0c409d7de59564fa1a2e3b100 /src/lib | |
parent | 90b03b7785bece7b16c6a38b7db633fcfdd9ecf4 (diff) | |
download | openbsd-bb63ff2d125e51688213d0af9e4f785cf3865063.tar.gz openbsd-bb63ff2d125e51688213d0af9e4f785cf3865063.tar.bz2 openbsd-bb63ff2d125e51688213d0af9e4f785cf3865063.zip |
First pass at applying KNF to the OpenSSL code, which almost makes it
readable. This pass is whitespace only and can readily be verified using
tr and md5.
Diffstat (limited to 'src/lib')
44 files changed, 9352 insertions, 9338 deletions
diff --git a/src/lib/libcrypto/bio/b_dump.c b/src/lib/libcrypto/bio/b_dump.c index 492ee09275..bea94969a2 100644 --- a/src/lib/libcrypto/bio/b_dump.c +++ b/src/lib/libcrypto/bio/b_dump.c | |||
@@ -66,122 +66,125 @@ | |||
66 | 66 | ||
67 | #define TRUNCATE | 67 | #define TRUNCATE |
68 | #define DUMP_WIDTH 16 | 68 | #define DUMP_WIDTH 16 |
69 | #define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH-((i-(i>6?6:i)+3)/4)) | 69 | #define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH - ((i - (i > 6 ? 6 : i) + 3) / 4)) |
70 | 70 | ||
71 | int BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u), | 71 | int |
72 | void *u, const char *s, int len) | 72 | BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u), |
73 | { | 73 | void *u, const char *s, int len) |
74 | { | ||
74 | return BIO_dump_indent_cb(cb, u, s, len, 0); | 75 | return BIO_dump_indent_cb(cb, u, s, len, 0); |
75 | } | 76 | } |
76 | 77 | ||
77 | int BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), | 78 | int |
78 | void *u, const char *s, int len, int indent) | 79 | BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), |
79 | { | 80 | void *u, const char *s, int len, int indent) |
80 | int ret=0; | 81 | { |
81 | char buf[288+1],tmp[20],str[128+1]; | 82 | int ret = 0; |
82 | int i,j,rows,trc; | 83 | char buf[288 + 1], tmp[20], str[128 + 1]; |
84 | int i, j, rows, trc; | ||
83 | unsigned char ch; | 85 | unsigned char ch; |
84 | int dump_width; | 86 | int dump_width; |
85 | 87 | ||
86 | trc=0; | 88 | trc = 0; |
87 | 89 | ||
88 | #ifdef TRUNCATE | 90 | #ifdef TRUNCATE |
89 | for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--) | 91 | for (; (len > 0) && ((s[len - 1] == ' ') || (s[len - 1] == '\0')); len--) |
90 | trc++; | 92 | trc++; |
91 | #endif | 93 | #endif |
92 | 94 | ||
93 | if (indent < 0) | 95 | if (indent < 0) |
94 | indent = 0; | 96 | indent = 0; |
95 | if (indent) | 97 | if (indent) { |
96 | { | 98 | if (indent > 128) |
97 | if (indent > 128) indent=128; | 99 | indent = 128; |
98 | memset(str,' ',indent); | 100 | memset(str, ' ', indent); |
99 | } | 101 | } |
100 | str[indent]='\0'; | 102 | str[indent] = '\0'; |
101 | 103 | ||
102 | dump_width=DUMP_WIDTH_LESS_INDENT(indent); | 104 | dump_width = DUMP_WIDTH_LESS_INDENT(indent); |
103 | rows=(len/dump_width); | 105 | rows = (len / dump_width); |
104 | if ((rows*dump_width)<len) | 106 | if ((rows * dump_width) < len) |
105 | rows++; | 107 | rows++; |
106 | for(i=0;i<rows;i++) | 108 | for (i = 0; i < rows; i++) { |
107 | { | 109 | buf[0] = '\0'; /* start with empty string */ |
108 | buf[0]='\0'; /* start with empty string */ | 110 | BUF_strlcpy(buf, str, sizeof buf); |
109 | BUF_strlcpy(buf,str,sizeof buf); | 111 | (void) snprintf(tmp, sizeof tmp, "%04x - ", i*dump_width); |
110 | (void) snprintf(tmp,sizeof tmp,"%04x - ",i*dump_width); | 112 | BUF_strlcat(buf, tmp, sizeof buf); |
111 | BUF_strlcat(buf,tmp,sizeof buf); | 113 | for (j = 0; j < dump_width; j++) { |
112 | for(j=0;j<dump_width;j++) | 114 | if (((i*dump_width) + j) >= len) { |
113 | { | 115 | BUF_strlcat(buf, " ", sizeof buf); |
114 | if (((i*dump_width)+j)>=len) | 116 | } else { |
115 | { | 117 | ch = ((unsigned char)*(s + i*dump_width + j)) & 0xff; |
116 | BUF_strlcat(buf," ",sizeof buf); | 118 | (void) snprintf(tmp, sizeof tmp, "%02x%c", ch, |
117 | } | 119 | j == 7 ? '-' : ' '); |
118 | else | 120 | BUF_strlcat(buf, tmp, sizeof buf); |
119 | { | ||
120 | ch=((unsigned char)*(s+i*dump_width+j)) & 0xff; | ||
121 | (void) snprintf(tmp,sizeof tmp,"%02x%c",ch, | ||
122 | j==7?'-':' '); | ||
123 | BUF_strlcat(buf,tmp,sizeof buf); | ||
124 | } | ||
125 | } | 121 | } |
126 | BUF_strlcat(buf," ",sizeof buf); | 122 | } |
127 | for(j=0;j<dump_width;j++) | 123 | BUF_strlcat(buf, " ", sizeof buf); |
128 | { | 124 | for (j = 0; j < dump_width; j++) { |
129 | if (((i*dump_width)+j)>=len) | 125 | if (((i*dump_width) + j) >= len) |
130 | break; | 126 | break; |
131 | ch=((unsigned char)*(s+i*dump_width+j)) & 0xff; | 127 | ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff; |
132 | #ifndef CHARSET_EBCDIC | 128 | #ifndef CHARSET_EBCDIC |
133 | (void) snprintf(tmp,sizeof tmp,"%c", | 129 | (void) snprintf(tmp, sizeof tmp, "%c", |
134 | ((ch>=' ')&&(ch<='~'))?ch:'.'); | 130 | ((ch >= ' ') && (ch <= '~')) ? ch : '.'); |
135 | #else | 131 | #else |
136 | (void) snprintf(tmp,sizeof tmp,"%c", | 132 | (void) snprintf(tmp, sizeof tmp, "%c", |
137 | ((ch>=os_toascii[' '])&&(ch<=os_toascii['~'])) | 133 | ((ch >= os_toascii[' ']) && (ch <= os_toascii['~'])) |
138 | ? os_toebcdic[ch] | 134 | ? os_toebcdic[ch] : '.'); |
139 | : '.'); | ||
140 | #endif | 135 | #endif |
141 | BUF_strlcat(buf,tmp,sizeof buf); | 136 | BUF_strlcat(buf, tmp, sizeof buf); |
142 | } | 137 | } |
143 | BUF_strlcat(buf,"\n",sizeof buf); | 138 | BUF_strlcat(buf, "\n", sizeof buf); |
144 | /* if this is the last call then update the ddt_dump thing so | 139 | /* if this is the last call then update the ddt_dump thing so |
145 | * that we will move the selection point in the debug window | 140 | * that we will move the selection point in the debug window |
146 | */ | 141 | */ |
147 | ret+=cb((void *)buf,strlen(buf),u); | 142 | ret += cb((void *)buf, strlen(buf), u); |
148 | } | 143 | } |
149 | #ifdef TRUNCATE | 144 | #ifdef TRUNCATE |
150 | if (trc > 0) | 145 | if (trc > 0) { |
151 | { | 146 | (void) snprintf(buf, sizeof buf, "%s%04x - <SPACES/NULS>\n", |
152 | (void) snprintf(buf,sizeof buf,"%s%04x - <SPACES/NULS>\n",str, | 147 | str, len + trc); |
153 | len+trc); | 148 | ret += cb((void *)buf, strlen(buf), u); |
154 | ret+=cb((void *)buf,strlen(buf),u); | ||
155 | } | ||
156 | #endif | ||
157 | return(ret); | ||
158 | } | 149 | } |
150 | #endif | ||
151 | return (ret); | ||
152 | } | ||
159 | 153 | ||
160 | #ifndef OPENSSL_NO_FP_API | 154 | #ifndef OPENSSL_NO_FP_API |
161 | static int write_fp(const void *data, size_t len, void *fp) | 155 | static int |
162 | { | 156 | write_fp(const void *data, size_t len, void *fp) |
157 | { | ||
163 | return UP_fwrite(data, len, 1, fp); | 158 | return UP_fwrite(data, len, 1, fp); |
164 | } | 159 | } |
165 | int BIO_dump_fp(FILE *fp, const char *s, int len) | 160 | |
166 | { | 161 | int |
162 | BIO_dump_fp(FILE *fp, const char *s, int len) | ||
163 | { | ||
167 | return BIO_dump_cb(write_fp, fp, s, len); | 164 | return BIO_dump_cb(write_fp, fp, s, len); |
168 | } | 165 | } |
169 | int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent) | 166 | |
170 | { | 167 | int |
168 | BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent) | ||
169 | { | ||
171 | return BIO_dump_indent_cb(write_fp, fp, s, len, indent); | 170 | return BIO_dump_indent_cb(write_fp, fp, s, len, indent); |
172 | } | 171 | } |
173 | #endif | 172 | #endif |
174 | 173 | ||
175 | static int write_bio(const void *data, size_t len, void *bp) | 174 | static int |
176 | { | 175 | write_bio(const void *data, size_t len, void *bp) |
176 | { | ||
177 | return BIO_write((BIO *)bp, (const char *)data, len); | 177 | return BIO_write((BIO *)bp, (const char *)data, len); |
178 | } | 178 | } |
179 | int BIO_dump(BIO *bp, const char *s, int len) | 179 | |
180 | { | 180 | int |
181 | BIO_dump(BIO *bp, const char *s, int len) | ||
182 | { | ||
181 | return BIO_dump_cb(write_bio, bp, s, len); | 183 | return BIO_dump_cb(write_bio, bp, s, len); |
182 | } | 184 | } |
183 | int BIO_dump_indent(BIO *bp, const char *s, int len, int indent) | ||
184 | { | ||
185 | return BIO_dump_indent_cb(write_bio, bp, s, len, indent); | ||
186 | } | ||
187 | 185 | ||
186 | int | ||
187 | BIO_dump_indent(BIO *bp, const char *s, int len, int indent) | ||
188 | { | ||
189 | return BIO_dump_indent_cb(write_bio, bp, s, len, indent); | ||
190 | } | ||
diff --git a/src/lib/libcrypto/bio/b_print.c b/src/lib/libcrypto/bio/b_print.c index 143a7cfefa..b3b0d45ee6 100644 --- a/src/lib/libcrypto/bio/b_print.c +++ b/src/lib/libcrypto/bio/b_print.c | |||
@@ -125,16 +125,15 @@ | |||
125 | #define LLONG long | 125 | #define LLONG long |
126 | #endif | 126 | #endif |
127 | 127 | ||
128 | static void fmtstr (char **, char **, size_t *, size_t *, | 128 | static void fmtstr(char **, char **, size_t *, size_t *, const char *, |
129 | const char *, int, int, int); | 129 | int, int, int); |
130 | static void fmtint (char **, char **, size_t *, size_t *, | 130 | static void fmtint(char **, char **, size_t *, size_t *, LLONG, int, |
131 | LLONG, int, int, int, int); | 131 | int, int, int); |
132 | static void fmtfp (char **, char **, size_t *, size_t *, | 132 | static void fmtfp(char **, char **, size_t *, size_t *, LDOUBLE, |
133 | LDOUBLE, int, int, int); | 133 | int, int, int); |
134 | static void doapr_outch (char **, char **, size_t *, size_t *, int); | 134 | static void doapr_outch(char **, char **, size_t *, size_t *, int); |
135 | static void _dopr(char **sbuffer, char **buffer, | 135 | static void _dopr(char **sbuffer, char **buffer, size_t *maxlen, |
136 | size_t *maxlen, size_t *retlen, int *truncated, | 136 | size_t *retlen, int *truncated, const char *format, va_list args); |
137 | const char *format, va_list args); | ||
138 | 137 | ||
139 | /* format read states */ | 138 | /* format read states */ |
140 | #define DP_S_DEFAULT 0 | 139 | #define DP_S_DEFAULT 0 |
@@ -166,607 +165,576 @@ static void _dopr(char **sbuffer, char **buffer, | |||
166 | #define OSSL_MAX(p,q) ((p >= q) ? p : q) | 165 | #define OSSL_MAX(p,q) ((p >= q) ? p : q) |
167 | 166 | ||
168 | static void | 167 | static void |
169 | _dopr( | 168 | _dopr(char **sbuffer, char **buffer, size_t *maxlen, size_t *retlen, |
170 | char **sbuffer, | 169 | int *truncated, const char *format, va_list args) |
171 | char **buffer, | ||
172 | size_t *maxlen, | ||
173 | size_t *retlen, | ||
174 | int *truncated, | ||
175 | const char *format, | ||
176 | va_list args) | ||
177 | { | 170 | { |
178 | char ch; | 171 | char ch; |
179 | LLONG value; | 172 | LLONG value; |
180 | LDOUBLE fvalue; | 173 | LDOUBLE fvalue; |
181 | char *strvalue; | 174 | char *strvalue; |
182 | int min; | 175 | int min; |
183 | int max; | 176 | int max; |
184 | int state; | 177 | int state; |
185 | int flags; | 178 | int flags; |
186 | int cflags; | 179 | int cflags; |
187 | size_t currlen; | 180 | size_t currlen; |
188 | 181 | ||
189 | state = DP_S_DEFAULT; | 182 | state = DP_S_DEFAULT; |
190 | flags = currlen = cflags = min = 0; | 183 | flags = currlen = cflags = min = 0; |
191 | max = -1; | 184 | max = -1; |
192 | ch = *format++; | 185 | ch = *format++; |
193 | 186 | ||
194 | while (state != DP_S_DONE) { | 187 | while (state != DP_S_DONE) { |
195 | if (ch == '\0' || (buffer == NULL && currlen >= *maxlen)) | 188 | if (ch == '\0' || (buffer == NULL && currlen >= *maxlen)) |
196 | state = DP_S_DONE; | 189 | state = DP_S_DONE; |
197 | 190 | ||
198 | switch (state) { | 191 | switch (state) { |
199 | case DP_S_DEFAULT: | 192 | case DP_S_DEFAULT: |
200 | if (ch == '%') | 193 | if (ch == '%') |
201 | state = DP_S_FLAGS; | 194 | state = DP_S_FLAGS; |
202 | else | 195 | else |
203 | doapr_outch(sbuffer,buffer, &currlen, maxlen, ch); | 196 | doapr_outch(sbuffer, buffer, &currlen, maxlen, ch); |
204 | ch = *format++; | 197 | ch = *format++; |
205 | break; | 198 | break; |
206 | case DP_S_FLAGS: | 199 | case DP_S_FLAGS: |
207 | switch (ch) { | 200 | switch (ch) { |
208 | case '-': | 201 | case '-': |
209 | flags |= DP_F_MINUS; | 202 | flags |= DP_F_MINUS; |
210 | ch = *format++; | 203 | ch = *format++; |
211 | break; | 204 | break; |
212 | case '+': | 205 | case '+': |
213 | flags |= DP_F_PLUS; | 206 | flags |= DP_F_PLUS; |
214 | ch = *format++; | 207 | ch = *format++; |
215 | break; | 208 | break; |
216 | case ' ': | 209 | case ' ': |
217 | flags |= DP_F_SPACE; | 210 | flags |= DP_F_SPACE; |
218 | ch = *format++; | 211 | ch = *format++; |
219 | break; | 212 | break; |
220 | case '#': | 213 | case '#': |
221 | flags |= DP_F_NUM; | 214 | flags |= DP_F_NUM; |
222 | ch = *format++; | 215 | ch = *format++; |
223 | break; | 216 | break; |
224 | case '0': | 217 | case '0': |
225 | flags |= DP_F_ZERO; | 218 | flags |= DP_F_ZERO; |
226 | ch = *format++; | 219 | ch = *format++; |
227 | break; | 220 | break; |
228 | default: | 221 | default: |
229 | state = DP_S_MIN; | 222 | state = DP_S_MIN; |
230 | break; | 223 | break; |
231 | } | 224 | } |
232 | break; | 225 | break; |
233 | case DP_S_MIN: | 226 | case DP_S_MIN: |
234 | if (isdigit((unsigned char)ch)) { | 227 | if (isdigit((unsigned char)ch)) { |
235 | min = 10 * min + char_to_int(ch); | 228 | min = 10 * min + char_to_int(ch); |
236 | ch = *format++; | 229 | ch = *format++; |
237 | } else if (ch == '*') { | 230 | } else if (ch == '*') { |
238 | min = va_arg(args, int); | 231 | min = va_arg(args, int); |
239 | ch = *format++; | 232 | ch = *format++; |
240 | state = DP_S_DOT; | 233 | state = DP_S_DOT; |
241 | } else | 234 | } else |
242 | state = DP_S_DOT; | 235 | state = DP_S_DOT; |
243 | break; | 236 | break; |
244 | case DP_S_DOT: | 237 | case DP_S_DOT: |
245 | if (ch == '.') { | 238 | if (ch == '.') { |
246 | state = DP_S_MAX; | 239 | state = DP_S_MAX; |
247 | ch = *format++; | 240 | ch = *format++; |
248 | } else | 241 | } else |
249 | state = DP_S_MOD; | 242 | state = DP_S_MOD; |
250 | break; | 243 | break; |
251 | case DP_S_MAX: | 244 | case DP_S_MAX: |
252 | if (isdigit((unsigned char)ch)) { | 245 | if (isdigit((unsigned char)ch)) { |
253 | if (max < 0) | 246 | if (max < 0) |
254 | max = 0; | 247 | max = 0; |
255 | max = 10 * max + char_to_int(ch); | 248 | max = 10 * max + char_to_int(ch); |
256 | ch = *format++; | 249 | ch = *format++; |
257 | } else if (ch == '*') { | 250 | } else if (ch == '*') { |
258 | max = va_arg(args, int); | 251 | max = va_arg(args, int); |
259 | ch = *format++; | 252 | ch = *format++; |
260 | state = DP_S_MOD; | 253 | state = DP_S_MOD; |
261 | } else | 254 | } else |
262 | state = DP_S_MOD; | 255 | state = DP_S_MOD; |
263 | break; | 256 | break; |
264 | case DP_S_MOD: | 257 | case DP_S_MOD: |
265 | switch (ch) { | 258 | switch (ch) { |
266 | case 'h': | 259 | case 'h': |
267 | cflags = DP_C_SHORT; | 260 | cflags = DP_C_SHORT; |
268 | ch = *format++; | 261 | ch = *format++; |
269 | break; | 262 | break; |
270 | case 'l': | 263 | case 'l': |
271 | if (*format == 'l') { | 264 | if (*format == 'l') { |
272 | cflags = DP_C_LLONG; | 265 | cflags = DP_C_LLONG; |
273 | format++; | 266 | format++; |
274 | } else | 267 | } else |
275 | cflags = DP_C_LONG; | 268 | cflags = DP_C_LONG; |
276 | ch = *format++; | 269 | ch = *format++; |
277 | break; | 270 | break; |
278 | case 'q': | 271 | case 'q': |
279 | cflags = DP_C_LLONG; | 272 | cflags = DP_C_LLONG; |
280 | ch = *format++; | 273 | ch = *format++; |
281 | break; | 274 | break; |
282 | case 'L': | 275 | case 'L': |
283 | cflags = DP_C_LDOUBLE; | 276 | cflags = DP_C_LDOUBLE; |
284 | ch = *format++; | 277 | ch = *format++; |
285 | break; | 278 | break; |
286 | default: | 279 | default: |
287 | break; | 280 | break; |
288 | } | 281 | } |
289 | state = DP_S_CONV; | 282 | state = DP_S_CONV; |
290 | break; | 283 | break; |
291 | case DP_S_CONV: | 284 | case DP_S_CONV: |
292 | switch (ch) { | 285 | switch (ch) { |
293 | case 'd': | 286 | case 'd': |
294 | case 'i': | 287 | case 'i': |
295 | switch (cflags) { | 288 | switch (cflags) { |
296 | case DP_C_SHORT: | 289 | case DP_C_SHORT: |
297 | value = (short int)va_arg(args, int); | 290 | value = (short int)va_arg(args, int); |
298 | break; | 291 | break; |
299 | case DP_C_LONG: | 292 | case DP_C_LONG: |
300 | value = va_arg(args, long int); | 293 | value = va_arg(args, long int); |
301 | break; | 294 | break; |
302 | case DP_C_LLONG: | 295 | case DP_C_LLONG: |
303 | value = va_arg(args, LLONG); | 296 | value = va_arg(args, LLONG); |
304 | break; | 297 | break; |
305 | default: | 298 | default: |
306 | value = va_arg(args, int); | 299 | value = va_arg(args, int); |
307 | break; | 300 | break; |
308 | } | 301 | } |
309 | fmtint(sbuffer, buffer, &currlen, maxlen, | 302 | fmtint(sbuffer, buffer, &currlen, maxlen, |
310 | value, 10, min, max, flags); | 303 | value, 10, min, max, flags); |
311 | break; | 304 | break; |
312 | case 'X': | 305 | case 'X': |
313 | flags |= DP_F_UP; | 306 | flags |= DP_F_UP; |
314 | /* FALLTHROUGH */ | 307 | /* FALLTHROUGH */ |
315 | case 'x': | 308 | case 'x': |
316 | case 'o': | 309 | case 'o': |
317 | case 'u': | 310 | case 'u': |
318 | flags |= DP_F_UNSIGNED; | 311 | flags |= DP_F_UNSIGNED; |
319 | switch (cflags) { | 312 | switch (cflags) { |
320 | case DP_C_SHORT: | 313 | case DP_C_SHORT: |
321 | value = (unsigned short int)va_arg(args, unsigned int); | 314 | value = (unsigned short int)va_arg( |
322 | break; | 315 | args, unsigned int); |
323 | case DP_C_LONG: | 316 | break; |
324 | value = (LLONG) va_arg(args, | 317 | case DP_C_LONG: |
325 | unsigned long int); | 318 | value = (LLONG)va_arg(args, |
326 | break; | 319 | unsigned long int); |
327 | case DP_C_LLONG: | 320 | break; |
328 | value = va_arg(args, unsigned LLONG); | 321 | case DP_C_LLONG: |
329 | break; | 322 | value = va_arg(args, unsigned LLONG); |
330 | default: | 323 | break; |
331 | value = (LLONG) va_arg(args, | 324 | default: |
332 | unsigned int); | 325 | value = (LLONG)va_arg(args, |
333 | break; | 326 | unsigned int); |
334 | } | 327 | break; |
335 | fmtint(sbuffer, buffer, &currlen, maxlen, value, | 328 | } |
336 | ch == 'o' ? 8 : (ch == 'u' ? 10 : 16), | 329 | fmtint(sbuffer, buffer, &currlen, maxlen, value, |
337 | min, max, flags); | 330 | ch == 'o' ? 8 : (ch == 'u' ? 10 : 16), |
338 | break; | 331 | min, max, flags); |
339 | case 'f': | 332 | break; |
340 | if (cflags == DP_C_LDOUBLE) | 333 | case 'f': |
341 | fvalue = va_arg(args, LDOUBLE); | 334 | if (cflags == DP_C_LDOUBLE) |
342 | else | 335 | fvalue = va_arg(args, LDOUBLE); |
343 | fvalue = va_arg(args, double); | 336 | else |
344 | fmtfp(sbuffer, buffer, &currlen, maxlen, | 337 | fvalue = va_arg(args, double); |
345 | fvalue, min, max, flags); | 338 | fmtfp(sbuffer, buffer, &currlen, maxlen, |
346 | break; | 339 | fvalue, min, max, flags); |
347 | case 'E': | 340 | break; |
348 | flags |= DP_F_UP; | 341 | case 'E': |
349 | case 'e': | 342 | flags |= DP_F_UP; |
350 | if (cflags == DP_C_LDOUBLE) | 343 | case 'e': |
351 | fvalue = va_arg(args, LDOUBLE); | 344 | if (cflags == DP_C_LDOUBLE) |
352 | else | 345 | fvalue = va_arg(args, LDOUBLE); |
353 | fvalue = va_arg(args, double); | 346 | else |
354 | break; | 347 | fvalue = va_arg(args, double); |
355 | case 'G': | 348 | break; |
356 | flags |= DP_F_UP; | 349 | case 'G': |
357 | case 'g': | 350 | flags |= DP_F_UP; |
358 | if (cflags == DP_C_LDOUBLE) | 351 | case 'g': |
359 | fvalue = va_arg(args, LDOUBLE); | 352 | if (cflags == DP_C_LDOUBLE) |
360 | else | 353 | fvalue = va_arg(args, LDOUBLE); |
361 | fvalue = va_arg(args, double); | 354 | else |
362 | break; | 355 | fvalue = va_arg(args, double); |
363 | case 'c': | 356 | break; |
364 | doapr_outch(sbuffer, buffer, &currlen, maxlen, | 357 | case 'c': |
365 | va_arg(args, int)); | 358 | doapr_outch(sbuffer, buffer, &currlen, maxlen, |
366 | break; | 359 | va_arg(args, int)); |
367 | case 's': | 360 | break; |
368 | strvalue = va_arg(args, char *); | 361 | case 's': |
369 | if (max < 0) { | 362 | strvalue = va_arg(args, char *); |
370 | if (buffer) | 363 | if (max < 0) { |
371 | max = INT_MAX; | 364 | if (buffer) |
372 | else | 365 | max = INT_MAX; |
373 | max = *maxlen; | 366 | else |
367 | max = *maxlen; | ||
368 | } | ||
369 | fmtstr(sbuffer, buffer, &currlen, maxlen, | ||
370 | strvalue, flags, min, max); | ||
371 | break; | ||
372 | case 'p': | ||
373 | value = (long)va_arg(args, void *); | ||
374 | fmtint(sbuffer, buffer, &currlen, maxlen, | ||
375 | value, 16, min, max, flags|DP_F_NUM); | ||
376 | break; | ||
377 | case 'n': /* XXX */ | ||
378 | if (cflags == DP_C_SHORT) { | ||
379 | short int *num; | ||
380 | num = va_arg(args, short int *); | ||
381 | *num = currlen; | ||
382 | } else if (cflags == DP_C_LONG) { /* XXX */ | ||
383 | long int *num; | ||
384 | num = va_arg(args, long int *); | ||
385 | *num = (long int) currlen; | ||
386 | } else if (cflags == DP_C_LLONG) { /* XXX */ | ||
387 | LLONG *num; | ||
388 | num = va_arg(args, LLONG *); | ||
389 | *num = (LLONG) currlen; | ||
390 | } else { | ||
391 | int *num; | ||
392 | num = va_arg(args, int *); | ||
393 | *num = currlen; | ||
394 | } | ||
395 | break; | ||
396 | case '%': | ||
397 | doapr_outch(sbuffer, buffer, &currlen, maxlen, ch); | ||
398 | break; | ||
399 | case 'w': | ||
400 | /* not supported yet, treat as next char */ | ||
401 | ch = *format++; | ||
402 | break; | ||
403 | default: | ||
404 | /* unknown, skip */ | ||
405 | break; | ||
406 | } | ||
407 | ch = *format++; | ||
408 | state = DP_S_DEFAULT; | ||
409 | flags = cflags = min = 0; | ||
410 | max = -1; | ||
411 | break; | ||
412 | case DP_S_DONE: | ||
413 | break; | ||
414 | default: | ||
415 | break; | ||
374 | } | 416 | } |
375 | fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue, | 417 | } |
376 | flags, min, max); | 418 | *truncated = (currlen > *maxlen - 1); |
377 | break; | 419 | if (*truncated) |
378 | case 'p': | 420 | currlen = *maxlen - 1; |
379 | value = (long)va_arg(args, void *); | 421 | doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0'); |
380 | fmtint(sbuffer, buffer, &currlen, maxlen, | 422 | *retlen = currlen - 1; |
381 | value, 16, min, max, flags|DP_F_NUM); | 423 | return; |
382 | break; | ||
383 | case 'n': /* XXX */ | ||
384 | if (cflags == DP_C_SHORT) { | ||
385 | short int *num; | ||
386 | num = va_arg(args, short int *); | ||
387 | *num = currlen; | ||
388 | } else if (cflags == DP_C_LONG) { /* XXX */ | ||
389 | long int *num; | ||
390 | num = va_arg(args, long int *); | ||
391 | *num = (long int) currlen; | ||
392 | } else if (cflags == DP_C_LLONG) { /* XXX */ | ||
393 | LLONG *num; | ||
394 | num = va_arg(args, LLONG *); | ||
395 | *num = (LLONG) currlen; | ||
396 | } else { | ||
397 | int *num; | ||
398 | num = va_arg(args, int *); | ||
399 | *num = currlen; | ||
400 | } | ||
401 | break; | ||
402 | case '%': | ||
403 | doapr_outch(sbuffer, buffer, &currlen, maxlen, ch); | ||
404 | break; | ||
405 | case 'w': | ||
406 | /* not supported yet, treat as next char */ | ||
407 | ch = *format++; | ||
408 | break; | ||
409 | default: | ||
410 | /* unknown, skip */ | ||
411 | break; | ||
412 | } | ||
413 | ch = *format++; | ||
414 | state = DP_S_DEFAULT; | ||
415 | flags = cflags = min = 0; | ||
416 | max = -1; | ||
417 | break; | ||
418 | case DP_S_DONE: | ||
419 | break; | ||
420 | default: | ||
421 | break; | ||
422 | } | ||
423 | } | ||
424 | *truncated = (currlen > *maxlen - 1); | ||
425 | if (*truncated) | ||
426 | currlen = *maxlen - 1; | ||
427 | doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0'); | ||
428 | *retlen = currlen - 1; | ||
429 | return; | ||
430 | } | 424 | } |
431 | 425 | ||
432 | static void | 426 | static void |
433 | fmtstr( | 427 | fmtstr(char **sbuffer, char **buffer, size_t *currlen, size_t *maxlen, |
434 | char **sbuffer, | 428 | const char *value, int flags, int min, int max) |
435 | char **buffer, | ||
436 | size_t *currlen, | ||
437 | size_t *maxlen, | ||
438 | const char *value, | ||
439 | int flags, | ||
440 | int min, | ||
441 | int max) | ||
442 | { | 429 | { |
443 | int padlen, strln; | 430 | int padlen, strln; |
444 | int cnt = 0; | 431 | int cnt = 0; |
445 | 432 | ||
446 | if (value == 0) | 433 | if (value == 0) |
447 | value = "<NULL>"; | 434 | value = "<NULL>"; |
448 | for (strln = 0; value[strln]; ++strln) | 435 | for (strln = 0; value[strln]; ++strln) |
449 | ; | 436 | ; |
450 | padlen = min - strln; | 437 | padlen = min - strln; |
451 | if (padlen < 0) | 438 | if (padlen < 0) |
452 | padlen = 0; | 439 | padlen = 0; |
453 | if (flags & DP_F_MINUS) | 440 | if (flags & DP_F_MINUS) |
454 | padlen = -padlen; | 441 | padlen = -padlen; |
455 | 442 | ||
456 | while ((padlen > 0) && (cnt < max)) { | 443 | while ((padlen > 0) && (cnt < max)) { |
457 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); | 444 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); |
458 | --padlen; | 445 | --padlen; |
459 | ++cnt; | 446 | ++cnt; |
460 | } | 447 | } |
461 | while (*value && (cnt < max)) { | 448 | while (*value && (cnt < max)) { |
462 | doapr_outch(sbuffer, buffer, currlen, maxlen, *value++); | 449 | doapr_outch(sbuffer, buffer, currlen, maxlen, *value++); |
463 | ++cnt; | 450 | ++cnt; |
464 | } | 451 | } |
465 | while ((padlen < 0) && (cnt < max)) { | 452 | while ((padlen < 0) && (cnt < max)) { |
466 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); | 453 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); |
467 | ++padlen; | 454 | ++padlen; |
468 | ++cnt; | 455 | ++cnt; |
469 | } | 456 | } |
470 | } | 457 | } |
471 | 458 | ||
472 | static void | 459 | static void |
473 | fmtint( | 460 | fmtint(char **sbuffer, char **buffer, size_t *currlen, size_t *maxlen, |
474 | char **sbuffer, | 461 | LLONG value, int base, int min, int max, int flags) |
475 | char **buffer, | ||
476 | size_t *currlen, | ||
477 | size_t *maxlen, | ||
478 | LLONG value, | ||
479 | int base, | ||
480 | int min, | ||
481 | int max, | ||
482 | int flags) | ||
483 | { | 462 | { |
484 | int signvalue = 0; | 463 | int signvalue = 0; |
485 | const char *prefix = ""; | 464 | const char *prefix = ""; |
486 | unsigned LLONG uvalue; | 465 | unsigned LLONG uvalue; |
487 | char convert[DECIMAL_SIZE(value)+3]; | 466 | char convert[DECIMAL_SIZE(value) + 3]; |
488 | int place = 0; | 467 | int place = 0; |
489 | int spadlen = 0; | 468 | int spadlen = 0; |
490 | int zpadlen = 0; | 469 | int zpadlen = 0; |
491 | int caps = 0; | 470 | int caps = 0; |
492 | 471 | ||
493 | if (max < 0) | 472 | if (max < 0) |
494 | max = 0; | 473 | max = 0; |
495 | uvalue = value; | 474 | uvalue = value; |
496 | if (!(flags & DP_F_UNSIGNED)) { | 475 | if (!(flags & DP_F_UNSIGNED)) { |
497 | if (value < 0) { | 476 | if (value < 0) { |
498 | signvalue = '-'; | 477 | signvalue = '-'; |
499 | uvalue = -value; | 478 | uvalue = -value; |
500 | } else if (flags & DP_F_PLUS) | 479 | } else if (flags & DP_F_PLUS) |
501 | signvalue = '+'; | 480 | signvalue = '+'; |
502 | else if (flags & DP_F_SPACE) | 481 | else if (flags & DP_F_SPACE) |
503 | signvalue = ' '; | 482 | signvalue = ' '; |
504 | } | 483 | } |
505 | if (flags & DP_F_NUM) { | 484 | if (flags & DP_F_NUM) { |
506 | if (base == 8) prefix = "0"; | 485 | if (base == 8) |
507 | if (base == 16) prefix = "0x"; | 486 | prefix = "0"; |
508 | } | 487 | if (base == 16) |
509 | if (flags & DP_F_UP) | 488 | prefix = "0x"; |
510 | caps = 1; | 489 | } |
511 | do { | 490 | if (flags & DP_F_UP) |
512 | convert[place++] = | 491 | caps = 1; |
513 | (caps ? "0123456789ABCDEF" : "0123456789abcdef") | 492 | do { |
514 | [uvalue % (unsigned) base]; | 493 | convert[place++] = (caps ? "0123456789ABCDEF" : |
515 | uvalue = (uvalue / (unsigned) base); | 494 | "0123456789abcdef")[uvalue % (unsigned) base]; |
516 | } while (uvalue && (place < (int)sizeof(convert))); | 495 | uvalue = (uvalue / (unsigned) base); |
517 | if (place == sizeof(convert)) | 496 | } while (uvalue && (place < (int)sizeof(convert))); |
518 | place--; | 497 | if (place == sizeof(convert)) |
519 | convert[place] = 0; | 498 | place--; |
520 | 499 | convert[place] = 0; | |
521 | zpadlen = max - place; | 500 | |
522 | spadlen = min - OSSL_MAX(max, place) - (signvalue ? 1 : 0) - strlen(prefix); | 501 | zpadlen = max - place; |
523 | if (zpadlen < 0) | 502 | spadlen = min - OSSL_MAX(max, place) - (signvalue ? 1 : 0) - |
524 | zpadlen = 0; | 503 | strlen(prefix); |
525 | if (spadlen < 0) | 504 | if (zpadlen < 0) |
526 | spadlen = 0; | 505 | zpadlen = 0; |
527 | if (flags & DP_F_ZERO) { | 506 | if (spadlen < 0) |
528 | zpadlen = OSSL_MAX(zpadlen, spadlen); | 507 | spadlen = 0; |
529 | spadlen = 0; | 508 | if (flags & DP_F_ZERO) { |
530 | } | 509 | zpadlen = OSSL_MAX(zpadlen, spadlen); |
531 | if (flags & DP_F_MINUS) | 510 | spadlen = 0; |
532 | spadlen = -spadlen; | 511 | } |
533 | 512 | if (flags & DP_F_MINUS) | |
534 | /* spaces */ | 513 | spadlen = -spadlen; |
535 | while (spadlen > 0) { | 514 | |
536 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); | 515 | /* spaces */ |
537 | --spadlen; | 516 | while (spadlen > 0) { |
538 | } | 517 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); |
539 | 518 | --spadlen; | |
540 | /* sign */ | 519 | } |
541 | if (signvalue) | 520 | |
542 | doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue); | 521 | /* sign */ |
543 | 522 | if (signvalue) | |
544 | /* prefix */ | 523 | doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue); |
545 | while (*prefix) { | 524 | |
546 | doapr_outch(sbuffer, buffer, currlen, maxlen, *prefix); | 525 | /* prefix */ |
547 | prefix++; | 526 | while (*prefix) { |
548 | } | 527 | doapr_outch(sbuffer, buffer, currlen, maxlen, *prefix); |
549 | 528 | prefix++; | |
550 | /* zeros */ | 529 | } |
551 | if (zpadlen > 0) { | 530 | |
552 | while (zpadlen > 0) { | 531 | /* zeros */ |
553 | doapr_outch(sbuffer, buffer, currlen, maxlen, '0'); | 532 | if (zpadlen > 0) { |
554 | --zpadlen; | 533 | while (zpadlen > 0) { |
555 | } | 534 | doapr_outch(sbuffer, buffer, currlen, maxlen, '0'); |
556 | } | 535 | --zpadlen; |
557 | /* digits */ | 536 | } |
558 | while (place > 0) | 537 | } |
559 | doapr_outch(sbuffer, buffer, currlen, maxlen, convert[--place]); | 538 | /* digits */ |
560 | 539 | while (place > 0) | |
561 | /* left justified spaces */ | 540 | doapr_outch(sbuffer, buffer, currlen, maxlen, convert[--place]); |
562 | while (spadlen < 0) { | 541 | |
563 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); | 542 | /* left justified spaces */ |
564 | ++spadlen; | 543 | while (spadlen < 0) { |
565 | } | 544 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); |
566 | return; | 545 | ++spadlen; |
546 | } | ||
547 | return; | ||
567 | } | 548 | } |
568 | 549 | ||
569 | static LDOUBLE | 550 | static LDOUBLE |
570 | abs_val(LDOUBLE value) | 551 | abs_val(LDOUBLE value) |
571 | { | 552 | { |
572 | LDOUBLE result = value; | 553 | LDOUBLE result = value; |
573 | if (value < 0) | 554 | if (value < 0) |
574 | result = -value; | 555 | result = -value; |
575 | return result; | 556 | return result; |
576 | } | 557 | } |
577 | 558 | ||
578 | static LDOUBLE | 559 | static LDOUBLE |
579 | pow_10(int in_exp) | 560 | pow_10(int in_exp) |
580 | { | 561 | { |
581 | LDOUBLE result = 1; | 562 | LDOUBLE result = 1; |
582 | while (in_exp) { | 563 | while (in_exp) { |
583 | result *= 10; | 564 | result *= 10; |
584 | in_exp--; | 565 | in_exp--; |
585 | } | 566 | } |
586 | return result; | 567 | return result; |
587 | } | 568 | } |
588 | 569 | ||
589 | static long | 570 | static long |
590 | roundv(LDOUBLE value) | 571 | roundv(LDOUBLE value) |
591 | { | 572 | { |
592 | long intpart; | 573 | long intpart; |
593 | intpart = (long) value; | 574 | intpart = (long) value; |
594 | value = value - intpart; | 575 | value = value - intpart; |
595 | if (value >= 0.5) | 576 | if (value >= 0.5) |
596 | intpart++; | 577 | intpart++; |
597 | return intpart; | 578 | return intpart; |
598 | } | 579 | } |
599 | 580 | ||
600 | static void | 581 | static void |
601 | fmtfp( | 582 | fmtfp(char **sbuffer, char **buffer, size_t *currlen, size_t *maxlen, |
602 | char **sbuffer, | 583 | LDOUBLE fvalue, int min, int max, int flags) |
603 | char **buffer, | ||
604 | size_t *currlen, | ||
605 | size_t *maxlen, | ||
606 | LDOUBLE fvalue, | ||
607 | int min, | ||
608 | int max, | ||
609 | int flags) | ||
610 | { | 584 | { |
611 | int signvalue = 0; | 585 | int signvalue = 0; |
612 | LDOUBLE ufvalue; | 586 | LDOUBLE ufvalue; |
613 | char iconvert[20]; | 587 | char iconvert[20]; |
614 | char fconvert[20]; | 588 | char fconvert[20]; |
615 | int iplace = 0; | 589 | int iplace = 0; |
616 | int fplace = 0; | 590 | int fplace = 0; |
617 | int padlen = 0; | 591 | int padlen = 0; |
618 | int zpadlen = 0; | 592 | int zpadlen = 0; |
619 | int caps = 0; | 593 | int caps = 0; |
620 | long intpart; | 594 | long intpart; |
621 | long fracpart; | 595 | long fracpart; |
622 | long max10; | 596 | long max10; |
623 | 597 | ||
624 | if (max < 0) | 598 | if (max < 0) |
625 | max = 6; | 599 | max = 6; |
626 | ufvalue = abs_val(fvalue); | 600 | ufvalue = abs_val(fvalue); |
627 | if (fvalue < 0) | 601 | if (fvalue < 0) |
628 | signvalue = '-'; | 602 | signvalue = '-'; |
629 | else if (flags & DP_F_PLUS) | 603 | else if (flags & DP_F_PLUS) |
630 | signvalue = '+'; | 604 | signvalue = '+'; |
631 | else if (flags & DP_F_SPACE) | 605 | else if (flags & DP_F_SPACE) |
632 | signvalue = ' '; | 606 | signvalue = ' '; |
633 | 607 | ||
634 | intpart = (long)ufvalue; | 608 | intpart = (long)ufvalue; |
635 | 609 | ||
636 | /* sorry, we only support 9 digits past the decimal because of our | 610 | /* sorry, we only support 9 digits past the decimal because of our |
637 | conversion method */ | 611 | conversion method */ |
638 | if (max > 9) | 612 | if (max > 9) |
639 | max = 9; | 613 | max = 9; |
640 | 614 | ||
641 | /* we "cheat" by converting the fractional part to integer by | 615 | /* we "cheat" by converting the fractional part to integer by |
642 | multiplying by a factor of 10 */ | 616 | multiplying by a factor of 10 */ |
643 | max10 = roundv(pow_10(max)); | 617 | max10 = roundv(pow_10(max)); |
644 | fracpart = roundv(pow_10(max) * (ufvalue - intpart)); | 618 | fracpart = roundv(pow_10(max) * (ufvalue - intpart)); |
645 | 619 | ||
646 | if (fracpart >= max10) { | 620 | if (fracpart >= max10) { |
647 | intpart++; | 621 | intpart++; |
648 | fracpart -= max10; | 622 | fracpart -= max10; |
649 | } | 623 | } |
650 | 624 | ||
651 | /* convert integer part */ | 625 | /* convert integer part */ |
652 | do { | 626 | do { |
653 | iconvert[iplace++] = | 627 | iconvert[iplace++] = (caps ? "0123456789ABCDEF" : |
654 | (caps ? "0123456789ABCDEF" | 628 | "0123456789abcdef")[intpart % 10]; |
655 | : "0123456789abcdef")[intpart % 10]; | 629 | intpart = (intpart / 10); |
656 | intpart = (intpart / 10); | 630 | } while (intpart && (iplace < (int)sizeof(iconvert))); |
657 | } while (intpart && (iplace < (int)sizeof(iconvert))); | 631 | if (iplace == sizeof iconvert) |
658 | if (iplace == sizeof iconvert) | 632 | iplace--; |
659 | iplace--; | 633 | iconvert[iplace] = 0; |
660 | iconvert[iplace] = 0; | 634 | |
661 | 635 | /* convert fractional part */ | |
662 | /* convert fractional part */ | 636 | do { |
663 | do { | 637 | fconvert[fplace++] = (caps ? "0123456789ABCDEF" : |
664 | fconvert[fplace++] = | 638 | "0123456789abcdef")[fracpart % 10]; |
665 | (caps ? "0123456789ABCDEF" | 639 | fracpart = (fracpart / 10); |
666 | : "0123456789abcdef")[fracpart % 10]; | 640 | } while (fplace < max); |
667 | fracpart = (fracpart / 10); | 641 | if (fplace == sizeof fconvert) |
668 | } while (fplace < max); | 642 | fplace--; |
669 | if (fplace == sizeof fconvert) | 643 | fconvert[fplace] = 0; |
670 | fplace--; | 644 | |
671 | fconvert[fplace] = 0; | 645 | /* -1 for decimal point, another -1 if we are printing a sign */ |
672 | 646 | padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0); | |
673 | /* -1 for decimal point, another -1 if we are printing a sign */ | 647 | zpadlen = max - fplace; |
674 | padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0); | 648 | if (zpadlen < 0) |
675 | zpadlen = max - fplace; | 649 | zpadlen = 0; |
676 | if (zpadlen < 0) | 650 | if (padlen < 0) |
677 | zpadlen = 0; | 651 | padlen = 0; |
678 | if (padlen < 0) | 652 | if (flags & DP_F_MINUS) |
679 | padlen = 0; | 653 | padlen = -padlen; |
680 | if (flags & DP_F_MINUS) | 654 | |
681 | padlen = -padlen; | 655 | if ((flags & DP_F_ZERO) && (padlen > 0)) { |
682 | 656 | if (signvalue) { | |
683 | if ((flags & DP_F_ZERO) && (padlen > 0)) { | 657 | doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue); |
684 | if (signvalue) { | 658 | --padlen; |
685 | doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue); | 659 | signvalue = 0; |
686 | --padlen; | 660 | } |
687 | signvalue = 0; | 661 | while (padlen > 0) { |
688 | } | 662 | doapr_outch(sbuffer, buffer, currlen, maxlen, '0'); |
689 | while (padlen > 0) { | 663 | --padlen; |
690 | doapr_outch(sbuffer, buffer, currlen, maxlen, '0'); | 664 | } |
691 | --padlen; | 665 | } |
692 | } | 666 | while (padlen > 0) { |
693 | } | 667 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); |
694 | while (padlen > 0) { | 668 | --padlen; |
695 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); | 669 | } |
696 | --padlen; | 670 | if (signvalue) |
697 | } | 671 | doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue); |
698 | if (signvalue) | 672 | |
699 | doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue); | 673 | while (iplace > 0) |
700 | 674 | doapr_outch(sbuffer, buffer, currlen, maxlen, iconvert[--iplace]); | |
701 | while (iplace > 0) | 675 | |
702 | doapr_outch(sbuffer, buffer, currlen, maxlen, iconvert[--iplace]); | 676 | /* |
703 | 677 | * Decimal point. This should probably use locale to find the correct | |
704 | /* | 678 | * char to print out. |
705 | * Decimal point. This should probably use locale to find the correct | 679 | */ |
706 | * char to print out. | 680 | if (max > 0 || (flags & DP_F_NUM)) { |
707 | */ | 681 | doapr_outch(sbuffer, buffer, currlen, maxlen, '.'); |
708 | if (max > 0 || (flags & DP_F_NUM)) { | 682 | |
709 | doapr_outch(sbuffer, buffer, currlen, maxlen, '.'); | 683 | while (fplace > 0) |
710 | 684 | doapr_outch(sbuffer, buffer, currlen, maxlen, fconvert[--fplace]); | |
711 | while (fplace > 0) | 685 | } |
712 | doapr_outch(sbuffer, buffer, currlen, maxlen, fconvert[--fplace]); | 686 | while (zpadlen > 0) { |
713 | } | 687 | doapr_outch(sbuffer, buffer, currlen, maxlen, '0'); |
714 | while (zpadlen > 0) { | 688 | --zpadlen; |
715 | doapr_outch(sbuffer, buffer, currlen, maxlen, '0'); | 689 | } |
716 | --zpadlen; | 690 | |
717 | } | 691 | while (padlen < 0) { |
718 | 692 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); | |
719 | while (padlen < 0) { | 693 | ++padlen; |
720 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); | 694 | } |
721 | ++padlen; | ||
722 | } | ||
723 | } | 695 | } |
724 | 696 | ||
725 | static void | 697 | static void |
726 | doapr_outch( | 698 | doapr_outch(char **sbuffer, char **buffer, size_t *currlen, size_t *maxlen, |
727 | char **sbuffer, | ||
728 | char **buffer, | ||
729 | size_t *currlen, | ||
730 | size_t *maxlen, | ||
731 | int c) | 699 | int c) |
732 | { | 700 | { |
733 | /* If we haven't at least one buffer, someone has doe a big booboo */ | 701 | /* If we haven't at least one buffer, someone has doe a big booboo */ |
734 | assert(*sbuffer != NULL || buffer != NULL); | 702 | assert(*sbuffer != NULL || buffer != NULL); |
735 | 703 | ||
736 | if (buffer) { | 704 | if (buffer) { |
737 | while (*currlen >= *maxlen) { | 705 | while (*currlen >= *maxlen) { |
738 | if (*buffer == NULL) { | 706 | if (*buffer == NULL) { |
739 | if (*maxlen == 0) | 707 | if (*maxlen == 0) |
740 | *maxlen = 1024; | 708 | *maxlen = 1024; |
741 | *buffer = OPENSSL_malloc(*maxlen); | 709 | *buffer = OPENSSL_malloc(*maxlen); |
742 | if (*currlen > 0) { | 710 | if (*currlen > 0) { |
743 | assert(*sbuffer != NULL); | 711 | assert(*sbuffer != NULL); |
744 | memcpy(*buffer, *sbuffer, *currlen); | 712 | memcpy(*buffer, *sbuffer, *currlen); |
713 | } | ||
714 | *sbuffer = NULL; | ||
715 | } else { | ||
716 | *maxlen += 1024; | ||
717 | *buffer = OPENSSL_realloc(*buffer, *maxlen); | ||
718 | } | ||
745 | } | 719 | } |
746 | *sbuffer = NULL; | 720 | /* What to do if *buffer is NULL? */ |
747 | } else { | 721 | assert(*sbuffer != NULL || *buffer != NULL); |
748 | *maxlen += 1024; | ||
749 | *buffer = OPENSSL_realloc(*buffer, *maxlen); | ||
750 | } | ||
751 | } | 722 | } |
752 | /* What to do if *buffer is NULL? */ | ||
753 | assert(*sbuffer != NULL || *buffer != NULL); | ||
754 | } | ||
755 | 723 | ||
756 | if (*currlen < *maxlen) { | 724 | if (*currlen < *maxlen) { |
757 | if (*sbuffer) | 725 | if (*sbuffer) |
758 | (*sbuffer)[(*currlen)++] = (char)c; | 726 | (*sbuffer)[(*currlen)++] = (char)c; |
759 | else | 727 | else |
760 | (*buffer)[(*currlen)++] = (char)c; | 728 | (*buffer)[(*currlen)++] = (char)c; |
761 | } | 729 | } |
762 | 730 | ||
763 | return; | 731 | return; |
764 | } | 732 | } |
765 | 733 | ||
766 | /***************************************************************************/ | 734 | /***************************************************************************/ |
767 | 735 | ||
768 | int BIO_printf (BIO *bio, const char *format, ...) | 736 | int BIO_printf (BIO *bio, const char *format, ...) |
769 | { | 737 | { |
770 | va_list args; | 738 | va_list args; |
771 | int ret; | 739 | int ret; |
772 | 740 | ||
@@ -775,15 +743,15 @@ int BIO_printf (BIO *bio, const char *format, ...) | |||
775 | ret = BIO_vprintf(bio, format, args); | 743 | ret = BIO_vprintf(bio, format, args); |
776 | 744 | ||
777 | va_end(args); | 745 | va_end(args); |
778 | return(ret); | 746 | return (ret); |
779 | } | 747 | } |
780 | 748 | ||
781 | int BIO_vprintf (BIO *bio, const char *format, va_list args) | 749 | int BIO_vprintf (BIO *bio, const char *format, va_list args) |
782 | { | 750 | { |
783 | int ret; | 751 | int ret; |
784 | size_t retlen; | 752 | size_t retlen; |
785 | char hugebuf[1024*2]; /* Was previously 10k, which is unreasonable | 753 | char hugebuf[1024*2]; /* Was previously 10k, which is unreasonable |
786 | in small-stack environments, like threads | 754 | in small - stack environments, like threads |
787 | or DOS programs. */ | 755 | or DOS programs. */ |
788 | char *hugebufp = hugebuf; | 756 | char *hugebufp = hugebuf; |
789 | size_t hugebufsize = sizeof(hugebuf); | 757 | size_t hugebufsize = sizeof(hugebuf); |
@@ -792,27 +760,25 @@ int BIO_vprintf (BIO *bio, const char *format, va_list args) | |||
792 | 760 | ||
793 | dynbuf = NULL; | 761 | dynbuf = NULL; |
794 | CRYPTO_push_info("doapr()"); | 762 | CRYPTO_push_info("doapr()"); |
795 | _dopr(&hugebufp, &dynbuf, &hugebufsize, | 763 | _dopr(&hugebufp, &dynbuf, &hugebufsize, &retlen, &ignored, |
796 | &retlen, &ignored, format, args); | 764 | format, args); |
797 | if (dynbuf) | 765 | if (dynbuf) { |
798 | { | 766 | ret = BIO_write(bio, dynbuf, (int)retlen); |
799 | ret=BIO_write(bio, dynbuf, (int)retlen); | ||
800 | OPENSSL_free(dynbuf); | 767 | OPENSSL_free(dynbuf); |
801 | } | 768 | } else { |
802 | else | 769 | ret = BIO_write(bio, hugebuf, (int)retlen); |
803 | { | ||
804 | ret=BIO_write(bio, hugebuf, (int)retlen); | ||
805 | } | ||
806 | CRYPTO_pop_info(); | ||
807 | return(ret); | ||
808 | } | 770 | } |
771 | CRYPTO_pop_info(); | ||
772 | return (ret); | ||
773 | } | ||
809 | 774 | ||
810 | /* As snprintf is not available everywhere, we provide our own implementation. | 775 | /* As snprintf is not available everywhere, we provide our own implementation. |
811 | * This function has nothing to do with BIOs, but it's closely related | 776 | * This function has nothing to do with BIOs, but it's closely related |
812 | * to BIO_printf, and we need *some* name prefix ... | 777 | * to BIO_printf, and we need *some* name prefix ... |
813 | * (XXX the function should be renamed, but to what?) */ | 778 | * (XXX the function should be renamed, but to what?) */ |
814 | int BIO_snprintf(char *buf, size_t n, const char *format, ...) | 779 | int |
815 | { | 780 | BIO_snprintf(char *buf, size_t n, const char *format, ...) |
781 | { | ||
816 | va_list args; | 782 | va_list args; |
817 | int ret; | 783 | int ret; |
818 | 784 | ||
@@ -821,11 +787,12 @@ int BIO_snprintf(char *buf, size_t n, const char *format, ...) | |||
821 | ret = BIO_vsnprintf(buf, n, format, args); | 787 | ret = BIO_vsnprintf(buf, n, format, args); |
822 | 788 | ||
823 | va_end(args); | 789 | va_end(args); |
824 | return(ret); | 790 | return (ret); |
825 | } | 791 | } |
826 | 792 | ||
827 | int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) | 793 | int |
828 | { | 794 | BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) |
795 | { | ||
829 | size_t retlen; | 796 | size_t retlen; |
830 | int truncated; | 797 | int truncated; |
831 | 798 | ||
@@ -839,4 +806,4 @@ int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) | |||
839 | return -1; | 806 | return -1; |
840 | else | 807 | else |
841 | return (retlen <= INT_MAX) ? (int)retlen : -1; | 808 | return (retlen <= INT_MAX) ? (int)retlen : -1; |
842 | } | 809 | } |
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c index bd43307456..d739452580 100644 --- a/src/lib/libcrypto/bio/b_sock.c +++ b/src/lib/libcrypto/bio/b_sock.c | |||
@@ -85,7 +85,7 @@ NETDB_DEFINE_CONTEXT | |||
85 | #endif | 85 | #endif |
86 | 86 | ||
87 | #if defined(OPENSSL_SYS_WINDOWS) || (defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)) | 87 | #if defined(OPENSSL_SYS_WINDOWS) || (defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)) |
88 | static int wsa_init_done=0; | 88 | static int wsa_init_done = 0; |
89 | #endif | 89 | #endif |
90 | 90 | ||
91 | /* | 91 | /* |
@@ -100,36 +100,36 @@ static int wsa_init_done=0; | |||
100 | #endif | 100 | #endif |
101 | 101 | ||
102 | #if 0 | 102 | #if 0 |
103 | static unsigned long BIO_ghbn_hits=0L; | 103 | static unsigned long BIO_ghbn_hits = 0L; |
104 | static unsigned long BIO_ghbn_miss=0L; | 104 | static unsigned long BIO_ghbn_miss = 0L; |
105 | 105 | ||
106 | #define GHBN_NUM 4 | 106 | #define GHBN_NUM 4 |
107 | static struct ghbn_cache_st | 107 | static struct ghbn_cache_st { |
108 | { | ||
109 | char name[129]; | 108 | char name[129]; |
110 | struct hostent *ent; | 109 | struct hostent *ent; |
111 | unsigned long order; | 110 | unsigned long order; |
112 | } ghbn_cache[GHBN_NUM]; | 111 | } ghbn_cache[GHBN_NUM]; |
113 | #endif | 112 | #endif |
114 | 113 | ||
115 | static int get_ip(const char *str,unsigned char *ip); | 114 | static int get_ip(const char *str, unsigned char *ip); |
116 | #if 0 | 115 | #if 0 |
117 | static void ghbn_free(struct hostent *a); | 116 | static void ghbn_free(struct hostent *a); |
118 | static struct hostent *ghbn_dup(struct hostent *a); | 117 | static struct hostent *ghbn_dup(struct hostent *a); |
119 | #endif | 118 | #endif |
120 | int BIO_get_host_ip(const char *str, unsigned char *ip) | 119 | |
121 | { | 120 | int |
121 | BIO_get_host_ip(const char *str, unsigned char *ip) | ||
122 | { | ||
122 | int i; | 123 | int i; |
123 | int err = 1; | 124 | int err = 1; |
124 | int locked = 0; | 125 | int locked = 0; |
125 | struct hostent *he; | 126 | struct hostent *he; |
126 | 127 | ||
127 | i=get_ip(str,ip); | 128 | i = get_ip(str, ip); |
128 | if (i < 0) | 129 | if (i < 0) { |
129 | { | 130 | BIOerr(BIO_F_BIO_GET_HOST_IP, BIO_R_INVALID_IP_ADDRESS); |
130 | BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_INVALID_IP_ADDRESS); | ||
131 | goto err; | 131 | goto err; |
132 | } | 132 | } |
133 | 133 | ||
134 | /* At this point, we have something that is most probably correct | 134 | /* At this point, we have something that is most probably correct |
135 | in some way, so let's init the socket. */ | 135 | in some way, so let's init the socket. */ |
@@ -138,172 +138,169 @@ int BIO_get_host_ip(const char *str, unsigned char *ip) | |||
138 | 138 | ||
139 | /* If the string actually contained an IP address, we need not do | 139 | /* If the string actually contained an IP address, we need not do |
140 | anything more */ | 140 | anything more */ |
141 | if (i > 0) return(1); | 141 | if (i > 0) |
142 | return (1); | ||
142 | 143 | ||
143 | /* do a gethostbyname */ | 144 | /* do a gethostbyname */ |
144 | CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); | 145 | CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); |
145 | locked = 1; | 146 | locked = 1; |
146 | he=BIO_gethostbyname(str); | 147 | he = BIO_gethostbyname(str); |
147 | if (he == NULL) | 148 | if (he == NULL) { |
148 | { | 149 | BIOerr(BIO_F_BIO_GET_HOST_IP, BIO_R_BAD_HOSTNAME_LOOKUP); |
149 | BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_BAD_HOSTNAME_LOOKUP); | ||
150 | goto err; | 150 | goto err; |
151 | } | 151 | } |
152 | 152 | ||
153 | /* cast to short because of win16 winsock definition */ | 153 | /* cast to short because of win16 winsock definition */ |
154 | if ((short)he->h_addrtype != AF_INET) | 154 | if ((short)he->h_addrtype != AF_INET) { |
155 | { | 155 | BIOerr(BIO_F_BIO_GET_HOST_IP, BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET); |
156 | BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET); | ||
157 | goto err; | 156 | goto err; |
158 | } | 157 | } |
159 | for (i=0; i<4; i++) | 158 | for (i = 0; i < 4; i++) |
160 | ip[i]=he->h_addr_list[0][i]; | 159 | ip[i] = he->h_addr_list[0][i]; |
161 | err = 0; | 160 | err = 0; |
162 | 161 | ||
163 | err: | 162 | err: |
164 | if (locked) | 163 | if (locked) |
165 | CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); | 164 | CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); |
166 | if (err) | 165 | if (err) { |
167 | { | 166 | ERR_add_error_data(2, "host=", str); |
168 | ERR_add_error_data(2,"host=",str); | ||
169 | return 0; | 167 | return 0; |
170 | } | 168 | } else |
171 | else | ||
172 | return 1; | 169 | return 1; |
173 | } | 170 | } |
174 | 171 | ||
175 | int BIO_get_port(const char *str, unsigned short *port_ptr) | 172 | int |
176 | { | 173 | BIO_get_port(const char *str, unsigned short *port_ptr) |
174 | { | ||
177 | int i; | 175 | int i; |
178 | struct servent *s; | 176 | struct servent *s; |
179 | 177 | ||
180 | if (str == NULL) | 178 | if (str == NULL) { |
181 | { | 179 | BIOerr(BIO_F_BIO_GET_PORT, BIO_R_NO_PORT_DEFINED); |
182 | BIOerr(BIO_F_BIO_GET_PORT,BIO_R_NO_PORT_DEFINED); | 180 | return (0); |
183 | return(0); | 181 | } |
184 | } | 182 | i = atoi(str); |
185 | i=atoi(str); | ||
186 | if (i != 0) | 183 | if (i != 0) |
187 | *port_ptr=(unsigned short)i; | 184 | *port_ptr = (unsigned short)i; |
188 | else | 185 | else { |
189 | { | ||
190 | CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME); | 186 | CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME); |
191 | /* Note: under VMS with SOCKETSHR, it seems like the first | 187 | /* Note: under VMS with SOCKETSHR, it seems like the first |
192 | * parameter is 'char *', instead of 'const char *' | 188 | * parameter is 'char *', instead of 'const char *' |
193 | */ | 189 | */ |
194 | #ifndef CONST_STRICT | 190 | #ifndef CONST_STRICT |
195 | s=getservbyname((char *)str,"tcp"); | 191 | s = getservbyname((char *)str, "tcp"); |
196 | #else | 192 | #else |
197 | s=getservbyname(str,"tcp"); | 193 | s = getservbyname(str, "tcp"); |
198 | #endif | 194 | #endif |
199 | if(s != NULL) | 195 | if (s != NULL) |
200 | *port_ptr=ntohs((unsigned short)s->s_port); | 196 | *port_ptr = ntohs((unsigned short)s->s_port); |
201 | CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME); | 197 | CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME); |
202 | if(s == NULL) | 198 | if (s == NULL) { |
203 | { | 199 | if (strcmp(str, "http") == 0) |
204 | if (strcmp(str,"http") == 0) | 200 | *port_ptr = 80; |
205 | *port_ptr=80; | 201 | else if (strcmp(str, "telnet") == 0) |
206 | else if (strcmp(str,"telnet") == 0) | 202 | *port_ptr = 23; |
207 | *port_ptr=23; | 203 | else if (strcmp(str, "socks") == 0) |
208 | else if (strcmp(str,"socks") == 0) | 204 | *port_ptr = 1080; |
209 | *port_ptr=1080; | 205 | else if (strcmp(str, "https") == 0) |
210 | else if (strcmp(str,"https") == 0) | 206 | *port_ptr = 443; |
211 | *port_ptr=443; | 207 | else if (strcmp(str, "ssl") == 0) |
212 | else if (strcmp(str,"ssl") == 0) | 208 | *port_ptr = 443; |
213 | *port_ptr=443; | 209 | else if (strcmp(str, "ftp") == 0) |
214 | else if (strcmp(str,"ftp") == 0) | 210 | *port_ptr = 21; |
215 | *port_ptr=21; | 211 | else if (strcmp(str, "gopher") == 0) |
216 | else if (strcmp(str,"gopher") == 0) | 212 | *port_ptr = 70; |
217 | *port_ptr=70; | ||
218 | #if 0 | 213 | #if 0 |
219 | else if (strcmp(str,"wais") == 0) | 214 | else if (strcmp(str, "wais") == 0) |
220 | *port_ptr=21; | 215 | *port_ptr = 21; |
221 | #endif | 216 | #endif |
222 | else | 217 | else { |
223 | { | 218 | SYSerr(SYS_F_GETSERVBYNAME, errno); |
224 | SYSerr(SYS_F_GETSERVBYNAME,errno); | 219 | ERR_add_error_data(3, "service = '", str, "'"); |
225 | ERR_add_error_data(3,"service='",str,"'"); | 220 | return (0); |
226 | return(0); | ||
227 | } | ||
228 | } | 221 | } |
229 | } | 222 | } |
230 | return(1); | ||
231 | } | 223 | } |
224 | return (1); | ||
225 | } | ||
232 | 226 | ||
233 | int BIO_sock_error(int sock) | 227 | int |
234 | { | 228 | BIO_sock_error(int sock) |
235 | int j,i; | 229 | { |
230 | int j, i; | ||
236 | int size; | 231 | int size; |
237 | 232 | ||
238 | #if defined(OPENSSL_SYS_BEOS_R5) | 233 | #if defined(OPENSSL_SYS_BEOS_R5) |
239 | return 0; | 234 | return 0; |
240 | #endif | 235 | #endif |
241 | 236 | ||
242 | size=sizeof(int); | 237 | size = sizeof(int); |
243 | /* Note: under Windows the third parameter is of type (char *) | 238 | /* Note: under Windows the third parameter is of type (char *) |
244 | * whereas under other systems it is (void *) if you don't have | 239 | * whereas under other systems it is (void *) if you don't have |
245 | * a cast it will choke the compiler: if you do have a cast then | 240 | * a cast it will choke the compiler: if you do have a cast then |
246 | * you can either go for (char *) or (void *). | 241 | * you can either go for (char *) or (void *). |
247 | */ | 242 | */ |
248 | i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(void *)&j,(void *)&size); | 243 | i = getsockopt(sock, SOL_SOCKET, SO_ERROR,(void *)&j,(void *)&size); |
249 | if (i < 0) | 244 | if (i < 0) |
250 | return(1); | 245 | return (1); |
251 | else | 246 | else |
252 | return(j); | 247 | return (j); |
253 | } | 248 | } |
254 | 249 | ||
255 | #if 0 | 250 | #if 0 |
256 | long BIO_ghbn_ctrl(int cmd, int iarg, char *parg) | 251 | long |
257 | { | 252 | BIO_ghbn_ctrl(int cmd, int iarg, char *parg) |
253 | { | ||
258 | int i; | 254 | int i; |
259 | char **p; | 255 | char **p; |
260 | 256 | ||
261 | switch (cmd) | 257 | switch (cmd) { |
262 | { | ||
263 | case BIO_GHBN_CTRL_HITS: | 258 | case BIO_GHBN_CTRL_HITS: |
264 | return(BIO_ghbn_hits); | 259 | return (BIO_ghbn_hits); |
265 | /* break; */ | 260 | /* break; */ |
266 | case BIO_GHBN_CTRL_MISSES: | 261 | case BIO_GHBN_CTRL_MISSES: |
267 | return(BIO_ghbn_miss); | 262 | return (BIO_ghbn_miss); |
268 | /* break; */ | 263 | /* break; */ |
269 | case BIO_GHBN_CTRL_CACHE_SIZE: | 264 | case BIO_GHBN_CTRL_CACHE_SIZE: |
270 | return(GHBN_NUM); | 265 | return (GHBN_NUM); |
271 | /* break; */ | 266 | /* break; */ |
272 | case BIO_GHBN_CTRL_GET_ENTRY: | 267 | case BIO_GHBN_CTRL_GET_ENTRY: |
273 | if ((iarg >= 0) && (iarg <GHBN_NUM) && | 268 | if ((iarg >= 0) && (iarg < GHBN_NUM) && |
274 | (ghbn_cache[iarg].order > 0)) | 269 | (ghbn_cache[iarg].order > 0)) { |
275 | { | 270 | p = (char **)parg; |
276 | p=(char **)parg; | 271 | if (p == NULL) |
277 | if (p == NULL) return(0); | 272 | return (0); |
278 | *p=ghbn_cache[iarg].name; | 273 | *p = ghbn_cache[iarg].name; |
279 | ghbn_cache[iarg].name[128]='\0'; | 274 | ghbn_cache[iarg].name[128] = '\0'; |
280 | return(1); | 275 | return (1); |
281 | } | 276 | } |
282 | return(0); | 277 | return (0); |
283 | /* break; */ | 278 | /* break; */ |
284 | case BIO_GHBN_CTRL_FLUSH: | 279 | case BIO_GHBN_CTRL_FLUSH: |
285 | for (i=0; i<GHBN_NUM; i++) | 280 | for (i = 0; i < GHBN_NUM; i++) |
286 | ghbn_cache[i].order=0; | 281 | ghbn_cache[i].order = 0; |
287 | break; | 282 | break; |
288 | default: | 283 | default: |
289 | return(0); | 284 | return (0); |
290 | } | ||
291 | return(1); | ||
292 | } | 285 | } |
286 | return (1); | ||
287 | } | ||
293 | #endif | 288 | #endif |
294 | 289 | ||
295 | #if 0 | 290 | #if 0 |
296 | static struct hostent *ghbn_dup(struct hostent *a) | 291 | static struct hostent |
297 | { | 292 | *ghbn_dup(struct hostent *a) |
293 | { | ||
298 | struct hostent *ret; | 294 | struct hostent *ret; |
299 | int i,j; | 295 | int i, j; |
300 | 296 | ||
301 | MemCheck_off(); | 297 | MemCheck_off(); |
302 | ret=(struct hostent *)OPENSSL_malloc(sizeof(struct hostent)); | 298 | ret = (struct hostent *)OPENSSL_malloc(sizeof(struct hostent)); |
303 | if (ret == NULL) return(NULL); | 299 | if (ret == NULL) |
304 | memset(ret,0,sizeof(struct hostent)); | 300 | return (NULL); |
301 | memset(ret, 0, sizeof(struct hostent)); | ||
305 | 302 | ||
306 | for (i=0; a->h_aliases[i] != NULL; i++) | 303 | for (i = 0; a->h_aliases[i] != NULL; i++) |
307 | ; | 304 | ; |
308 | i++; | 305 | i++; |
309 | ret->h_aliases = (char **)OPENSSL_malloc(i*sizeof(char *)); | 306 | ret->h_aliases = (char **)OPENSSL_malloc(i*sizeof(char *)); |
@@ -311,69 +308,66 @@ static struct hostent *ghbn_dup(struct hostent *a) | |||
311 | goto err; | 308 | goto err; |
312 | memset(ret->h_aliases, 0, i*sizeof(char *)); | 309 | memset(ret->h_aliases, 0, i*sizeof(char *)); |
313 | 310 | ||
314 | for (i=0; a->h_addr_list[i] != NULL; i++) | 311 | for (i = 0; a->h_addr_list[i] != NULL; i++) |
315 | ; | 312 | ; |
316 | i++; | 313 | i++; |
317 | ret->h_addr_list=(char **)OPENSSL_malloc(i*sizeof(char *)); | 314 | ret->h_addr_list = (char **)OPENSSL_malloc(i*sizeof(char *)); |
318 | if (ret->h_addr_list == NULL) | 315 | if (ret->h_addr_list == NULL) |
319 | goto err; | 316 | goto err; |
320 | memset(ret->h_addr_list, 0, i*sizeof(char *)); | 317 | memset(ret->h_addr_list, 0, i*sizeof(char *)); |
321 | 318 | ||
322 | j=strlen(a->h_name)+1; | 319 | j = strlen(a->h_name) + 1; |
323 | if ((ret->h_name=OPENSSL_malloc(j)) == NULL) goto err; | 320 | if ((ret->h_name = OPENSSL_malloc(j)) == NULL) goto err; |
324 | memcpy((char *)ret->h_name,a->h_name,j); | 321 | memcpy((char *)ret->h_name, a->h_name, j); |
325 | for (i=0; a->h_aliases[i] != NULL; i++) | 322 | for (i = 0; a->h_aliases[i] != NULL; i++) { |
326 | { | 323 | j = strlen(a->h_aliases[i]) + 1; |
327 | j=strlen(a->h_aliases[i])+1; | 324 | if ((ret->h_aliases[i] = OPENSSL_malloc(j)) == NULL) goto err; |
328 | if ((ret->h_aliases[i]=OPENSSL_malloc(j)) == NULL) goto err; | 325 | memcpy(ret->h_aliases[i], a->h_aliases[i], j); |
329 | memcpy(ret->h_aliases[i],a->h_aliases[i],j); | 326 | } |
330 | } | 327 | ret->h_length = a->h_length; |
331 | ret->h_length=a->h_length; | 328 | ret->h_addrtype = a->h_addrtype; |
332 | ret->h_addrtype=a->h_addrtype; | 329 | for (i = 0; a->h_addr_list[i] != NULL; i++) { |
333 | for (i=0; a->h_addr_list[i] != NULL; i++) | 330 | if ((ret->h_addr_list[i] = OPENSSL_malloc(a->h_length)) == NULL) |
334 | { | ||
335 | if ((ret->h_addr_list[i]=OPENSSL_malloc(a->h_length)) == NULL) | ||
336 | goto err; | 331 | goto err; |
337 | memcpy(ret->h_addr_list[i],a->h_addr_list[i],a->h_length); | 332 | memcpy(ret->h_addr_list[i], a->h_addr_list[i], a->h_length); |
338 | } | 333 | } |
339 | if (0) | 334 | if (0) { |
340 | { | 335 | err: |
341 | err: | ||
342 | if (ret != NULL) | 336 | if (ret != NULL) |
343 | ghbn_free(ret); | 337 | ghbn_free(ret); |
344 | ret=NULL; | 338 | ret = NULL; |
345 | } | ||
346 | MemCheck_on(); | ||
347 | return(ret); | ||
348 | } | 339 | } |
340 | MemCheck_on(); | ||
341 | return (ret); | ||
342 | } | ||
349 | 343 | ||
350 | static void ghbn_free(struct hostent *a) | 344 | static void |
351 | { | 345 | ghbn_free(struct hostent *a) |
346 | { | ||
352 | int i; | 347 | int i; |
353 | 348 | ||
354 | if(a == NULL) | 349 | if (a == NULL) |
355 | return; | 350 | return; |
356 | 351 | ||
357 | if (a->h_aliases != NULL) | 352 | if (a->h_aliases != NULL) { |
358 | { | 353 | for (i = 0; a->h_aliases[i] != NULL; i++) |
359 | for (i=0; a->h_aliases[i] != NULL; i++) | ||
360 | OPENSSL_free(a->h_aliases[i]); | 354 | OPENSSL_free(a->h_aliases[i]); |
361 | OPENSSL_free(a->h_aliases); | 355 | OPENSSL_free(a->h_aliases); |
362 | } | 356 | } |
363 | if (a->h_addr_list != NULL) | 357 | if (a->h_addr_list != NULL) { |
364 | { | 358 | for (i = 0; a->h_addr_list[i] != NULL; i++) |
365 | for (i=0; a->h_addr_list[i] != NULL; i++) | ||
366 | OPENSSL_free(a->h_addr_list[i]); | 359 | OPENSSL_free(a->h_addr_list[i]); |
367 | OPENSSL_free(a->h_addr_list); | 360 | OPENSSL_free(a->h_addr_list); |
368 | } | ||
369 | if (a->h_name != NULL) OPENSSL_free(a->h_name); | ||
370 | OPENSSL_free(a); | ||
371 | } | 361 | } |
362 | if (a->h_name != NULL) | ||
363 | OPENSSL_free(a->h_name); | ||
364 | OPENSSL_free(a); | ||
365 | } | ||
372 | 366 | ||
373 | #endif | 367 | #endif |
374 | 368 | ||
375 | struct hostent *BIO_gethostbyname(const char *name) | 369 | struct hostent |
376 | { | 370 | *BIO_gethostbyname(const char *name) { |
377 | #if 1 | 371 | #if 1 |
378 | /* Caching gethostbyname() results forever is wrong, | 372 | /* Caching gethostbyname() results forever is wrong, |
379 | * so we have to let the true gethostbyname() worry about this */ | 373 | * so we have to let the true gethostbyname() worry about this */ |
@@ -384,8 +378,8 @@ struct hostent *BIO_gethostbyname(const char *name) | |||
384 | #endif | 378 | #endif |
385 | #else | 379 | #else |
386 | struct hostent *ret; | 380 | struct hostent *ret; |
387 | int i,lowi=0,j; | 381 | int i, lowi = 0, j; |
388 | unsigned long low= (unsigned long)-1; | 382 | unsigned long low = (unsigned long) - 1; |
389 | 383 | ||
390 | 384 | ||
391 | # if 0 | 385 | # if 0 |
@@ -395,42 +389,37 @@ struct hostent *BIO_gethostbyname(const char *name) | |||
395 | */ | 389 | */ |
396 | CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); | 390 | CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); |
397 | # endif | 391 | # endif |
398 | j=strlen(name); | 392 | j = strlen(name); |
399 | if (j < 128) | 393 | if (j < 128) { |
400 | { | 394 | for (i = 0; i < GHBN_NUM; i++) { |
401 | for (i=0; i<GHBN_NUM; i++) | 395 | if (low > ghbn_cache[i].order) { |
402 | { | 396 | low = ghbn_cache[i].order; |
403 | if (low > ghbn_cache[i].order) | 397 | lowi = i; |
404 | { | 398 | } |
405 | low=ghbn_cache[i].order; | 399 | if (ghbn_cache[i].order > 0) { |
406 | lowi=i; | 400 | if (strncmp(name, ghbn_cache[i].name, 128) == 0) |
407 | } | ||
408 | if (ghbn_cache[i].order > 0) | ||
409 | { | ||
410 | if (strncmp(name,ghbn_cache[i].name,128) == 0) | ||
411 | break; | 401 | break; |
412 | } | ||
413 | } | 402 | } |
414 | } | 403 | } |
415 | else | 404 | } else |
416 | i=GHBN_NUM; | 405 | i = GHBN_NUM; |
417 | 406 | ||
418 | if (i == GHBN_NUM) /* no hit*/ | 407 | if (i == GHBN_NUM) /* no hit*/ |
419 | { | 408 | { |
420 | BIO_ghbn_miss++; | 409 | BIO_ghbn_miss++; |
421 | /* Note: under VMS with SOCKETSHR, it seems like the first | 410 | /* Note: under VMS with SOCKETSHR, it seems like the first |
422 | * parameter is 'char *', instead of 'const char *' | 411 | * parameter is 'char *', instead of 'const char *' |
423 | */ | 412 | */ |
424 | # ifndef CONST_STRICT | 413 | # ifndef CONST_STRICT |
425 | ret=gethostbyname((char *)name); | 414 | ret = gethostbyname((char *)name); |
426 | # else | 415 | # else |
427 | ret=gethostbyname(name); | 416 | ret = gethostbyname(name); |
428 | # endif | 417 | # endif |
429 | 418 | ||
430 | if (ret == NULL) | 419 | if (ret == NULL) |
431 | goto end; | 420 | goto end; |
432 | if (j > 128) /* too big to cache */ | 421 | if (j > 128) /* too big to cache */ |
433 | { | 422 | { |
434 | # if 0 | 423 | # if 0 |
435 | /* If we were trying to make this function thread-safe (which | 424 | /* If we were trying to make this function thread-safe (which |
436 | * is bound to fail), we'd have to give up in this case | 425 | * is bound to fail), we'd have to give up in this case |
@@ -438,118 +427,113 @@ struct hostent *BIO_gethostbyname(const char *name) | |||
438 | ret = NULL; | 427 | ret = NULL; |
439 | # endif | 428 | # endif |
440 | goto end; | 429 | goto end; |
441 | } | 430 | } |
442 | 431 | ||
443 | /* else add to cache */ | 432 | /* else add to cache */ |
444 | if (ghbn_cache[lowi].ent != NULL) | 433 | if (ghbn_cache[lowi].ent != NULL) |
445 | ghbn_free(ghbn_cache[lowi].ent); /* XXX not thread-safe */ | 434 | ghbn_free(ghbn_cache[lowi].ent); /* XXX not thread-safe */ |
446 | ghbn_cache[lowi].name[0] = '\0'; | 435 | ghbn_cache[lowi].name[0] = '\0'; |
447 | 436 | ||
448 | if((ret=ghbn_cache[lowi].ent=ghbn_dup(ret)) == NULL) | 437 | if ((ret = ghbn_cache[lowi].ent = ghbn_dup(ret)) == NULL) { |
449 | { | 438 | BIOerr(BIO_F_BIO_GETHOSTBYNAME, ERR_R_MALLOC_FAILURE); |
450 | BIOerr(BIO_F_BIO_GETHOSTBYNAME,ERR_R_MALLOC_FAILURE); | ||
451 | goto end; | 439 | goto end; |
452 | } | ||
453 | strncpy(ghbn_cache[lowi].name,name,128); | ||
454 | ghbn_cache[lowi].order=BIO_ghbn_miss+BIO_ghbn_hits; | ||
455 | } | 440 | } |
456 | else | 441 | strncpy(ghbn_cache[lowi].name, name, 128); |
457 | { | 442 | ghbn_cache[lowi].order = BIO_ghbn_miss + BIO_ghbn_hits; |
443 | } else { | ||
458 | BIO_ghbn_hits++; | 444 | BIO_ghbn_hits++; |
459 | ret= ghbn_cache[i].ent; | 445 | ret = ghbn_cache[i].ent; |
460 | ghbn_cache[i].order=BIO_ghbn_miss+BIO_ghbn_hits; | 446 | ghbn_cache[i].order = BIO_ghbn_miss + BIO_ghbn_hits; |
461 | } | 447 | } |
462 | end: | 448 | end: |
463 | # if 0 | 449 | # if 0 |
464 | CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); | 450 | CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); |
465 | # endif | 451 | # endif |
466 | return(ret); | 452 | return (ret); |
467 | #endif | 453 | #endif |
468 | } | 454 | } |
469 | 455 | ||
470 | 456 | ||
471 | int BIO_sock_init(void) | 457 | int |
472 | { | 458 | BIO_sock_init(void) |
459 | { | ||
473 | #ifdef OPENSSL_SYS_WINDOWS | 460 | #ifdef OPENSSL_SYS_WINDOWS |
474 | static struct WSAData wsa_state; | 461 | static struct WSAData wsa_state; |
475 | 462 | ||
476 | if (!wsa_init_done) | 463 | if (!wsa_init_done) { |
477 | { | ||
478 | int err; | 464 | int err; |
479 | 465 | ||
480 | wsa_init_done=1; | 466 | wsa_init_done = 1; |
481 | memset(&wsa_state,0,sizeof(wsa_state)); | 467 | memset(&wsa_state, 0, sizeof(wsa_state)); |
482 | /* Not making wsa_state available to the rest of the | 468 | /* Not making wsa_state available to the rest of the |
483 | * code is formally wrong. But the structures we use | 469 | * code is formally wrong. But the structures we use |
484 | * are [beleived to be] invariable among Winsock DLLs, | 470 | * are [beleived to be] invariable among Winsock DLLs, |
485 | * while API availability is [expected to be] probed | 471 | * while API availability is [expected to be] probed |
486 | * at run-time with DSO_global_lookup. */ | 472 | * at run-time with DSO_global_lookup. */ |
487 | if (WSAStartup(0x0202,&wsa_state)!=0) | 473 | if (WSAStartup(0x0202, &wsa_state) != 0) { |
488 | { | 474 | err = WSAGetLastError(); |
489 | err=WSAGetLastError(); | 475 | SYSerr(SYS_F_WSASTARTUP, err); |
490 | SYSerr(SYS_F_WSASTARTUP,err); | 476 | BIOerr(BIO_F_BIO_SOCK_INIT, BIO_R_WSASTARTUP); |
491 | BIOerr(BIO_F_BIO_SOCK_INIT,BIO_R_WSASTARTUP); | 477 | return (-1); |
492 | return(-1); | ||
493 | } | ||
494 | } | 478 | } |
479 | } | ||
495 | #endif /* OPENSSL_SYS_WINDOWS */ | 480 | #endif /* OPENSSL_SYS_WINDOWS */ |
496 | #ifdef WATT32 | 481 | #ifdef WATT32 |
497 | extern int _watt_do_exit; | 482 | extern int _watt_do_exit; |
498 | _watt_do_exit = 0; /* don't make sock_init() call exit() */ | 483 | _watt_do_exit = 0; |
484 | /* don't make sock_init() call exit() */ | ||
499 | if (sock_init()) | 485 | if (sock_init()) |
500 | return (-1); | 486 | return (-1); |
501 | #endif | 487 | #endif |
502 | 488 | ||
503 | #if defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK) | 489 | #if defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK) |
504 | WORD wVerReq; | 490 | WORD wVerReq; |
505 | WSADATA wsaData; | 491 | WSADATA wsaData; |
506 | int err; | 492 | int err; |
507 | 493 | ||
508 | if (!wsa_init_done) | 494 | if (!wsa_init_done) { |
509 | { | 495 | wsa_init_done = 1; |
510 | wsa_init_done=1; | 496 | wVerReq = MAKEWORD( 2, 0 ); |
511 | wVerReq = MAKEWORD( 2, 0 ); | 497 | err = WSAStartup(wVerReq, &wsaData); |
512 | err = WSAStartup(wVerReq,&wsaData); | 498 | if (err != 0) { |
513 | if (err != 0) | 499 | SYSerr(SYS_F_WSASTARTUP, err); |
514 | { | 500 | BIOerr(BIO_F_BIO_SOCK_INIT, BIO_R_WSASTARTUP); |
515 | SYSerr(SYS_F_WSASTARTUP,err); | 501 | return (-1); |
516 | BIOerr(BIO_F_BIO_SOCK_INIT,BIO_R_WSASTARTUP); | ||
517 | return(-1); | ||
518 | } | ||
519 | } | 502 | } |
503 | } | ||
520 | #endif | 504 | #endif |
521 | 505 | ||
522 | return(1); | 506 | return (1); |
523 | } | 507 | } |
524 | 508 | ||
525 | void BIO_sock_cleanup(void) | 509 | void |
526 | { | 510 | BIO_sock_cleanup(void) |
511 | { | ||
527 | #ifdef OPENSSL_SYS_WINDOWS | 512 | #ifdef OPENSSL_SYS_WINDOWS |
528 | if (wsa_init_done) | 513 | if (wsa_init_done) { |
529 | { | 514 | wsa_init_done = 0; |
530 | wsa_init_done=0; | ||
531 | #if 0 /* this call is claimed to be non-present in Winsock2 */ | 515 | #if 0 /* this call is claimed to be non-present in Winsock2 */ |
532 | WSACancelBlockingCall(); | 516 | WSACancelBlockingCall(); |
533 | #endif | 517 | #endif |
534 | WSACleanup(); | 518 | WSACleanup(); |
535 | } | 519 | } |
536 | #elif defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK) | 520 | #elif defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK) |
537 | if (wsa_init_done) | 521 | if (wsa_init_done) { |
538 | { | 522 | wsa_init_done = 0; |
539 | wsa_init_done=0; | 523 | WSACleanup(); |
540 | WSACleanup(); | ||
541 | } | ||
542 | #endif | ||
543 | } | 524 | } |
525 | #endif | ||
526 | } | ||
544 | 527 | ||
545 | #if !defined(OPENSSL_SYS_VMS) || __VMS_VER >= 70000000 | 528 | #if !defined(OPENSSL_SYS_VMS) || __VMS_VER >= 70000000 |
546 | 529 | ||
547 | int BIO_socket_ioctl(int fd, long type, void *arg) | 530 | int |
548 | { | 531 | BIO_socket_ioctl(int fd, long type, void *arg) |
532 | { | ||
549 | int i; | 533 | int i; |
550 | 534 | ||
551 | #ifdef __DJGPP__ | 535 | #ifdef __DJGPP__ |
552 | i=ioctl(fd,type,(char *)arg); | 536 | i = ioctl(fd, type,(char *)arg); |
553 | #else | 537 | #else |
554 | # if defined(OPENSSL_SYS_VMS) | 538 | # if defined(OPENSSL_SYS_VMS) |
555 | /* 2011-02-18 SMS. | 539 | /* 2011-02-18 SMS. |
@@ -574,402 +558,399 @@ int BIO_socket_ioctl(int fd, long type, void *arg) | |||
574 | # define ARG arg | 558 | # define ARG arg |
575 | # endif /* defined(OPENSSL_SYS_VMS) [else] */ | 559 | # endif /* defined(OPENSSL_SYS_VMS) [else] */ |
576 | 560 | ||
577 | i=ioctl(fd,type,ARG); | 561 | i = ioctl(fd, type, ARG); |
578 | #endif /* __DJGPP__ */ | 562 | #endif /* __DJGPP__ */ |
579 | if (i < 0) | 563 | if (i < 0) |
580 | SYSerr(SYS_F_IOCTLSOCKET,errno); | 564 | SYSerr(SYS_F_IOCTLSOCKET, errno); |
581 | return(i); | 565 | return (i); |
582 | } | 566 | } |
583 | #endif /* __VMS_VER */ | 567 | #endif /* __VMS_VER */ |
584 | 568 | ||
585 | /* The reason I have implemented this instead of using sscanf is because | 569 | /* The reason I have implemented this instead of using sscanf is because |
586 | * Visual C 1.52c gives an unresolved external when linking a DLL :-( */ | 570 | * Visual C 1.52c gives an unresolved external when linking a DLL :-( */ |
587 | static int get_ip(const char *str, unsigned char ip[4]) | 571 | static int |
588 | { | 572 | get_ip(const char *str, unsigned char ip[4]) |
573 | { | ||
589 | unsigned int tmp[4]; | 574 | unsigned int tmp[4]; |
590 | int num=0,c,ok=0; | 575 | int num = 0, c, ok = 0; |
591 | 576 | ||
592 | tmp[0]=tmp[1]=tmp[2]=tmp[3]=0; | 577 | tmp[0] = tmp[1] = tmp[2] = tmp[3] = 0; |
593 | 578 | ||
594 | for (;;) | 579 | for (;;) { |
595 | { | ||
596 | c= *(str++); | 580 | c= *(str++); |
597 | if ((c >= '0') && (c <= '9')) | 581 | if ((c >= '0') && (c <= '9')) { |
598 | { | 582 | ok = 1; |
599 | ok=1; | 583 | tmp[num] = tmp[num]*10 + c-'0'; |
600 | tmp[num]=tmp[num]*10+c-'0'; | 584 | if (tmp[num] > 255) |
601 | if (tmp[num] > 255) return(0); | 585 | return (0); |
602 | } | 586 | } else if (c == '.') { |
603 | else if (c == '.') | 587 | if (!ok) |
604 | { | 588 | return (-1); |
605 | if (!ok) return(-1); | 589 | if (num == 3) |
606 | if (num == 3) return(0); | 590 | return (0); |
607 | num++; | 591 | num++; |
608 | ok=0; | 592 | ok = 0; |
609 | } | 593 | } else if (c == '\0' && (num == 3) && ok) |
610 | else if (c == '\0' && (num == 3) && ok) | 594 | break; |
611 | break; | ||
612 | else | 595 | else |
613 | return(0); | 596 | return (0); |
614 | } | ||
615 | ip[0]=tmp[0]; | ||
616 | ip[1]=tmp[1]; | ||
617 | ip[2]=tmp[2]; | ||
618 | ip[3]=tmp[3]; | ||
619 | return(1); | ||
620 | } | 597 | } |
621 | 598 | ip[0] = tmp[0]; | |
622 | int BIO_get_accept_socket(char *host, int bind_mode) | 599 | ip[1] = tmp[1]; |
623 | { | 600 | ip[2] = tmp[2]; |
624 | int ret=0; | 601 | ip[3] = tmp[3]; |
602 | return (1); | ||
603 | } | ||
604 | |||
605 | int | ||
606 | BIO_get_accept_socket(char *host, int bind_mode) | ||
607 | { | ||
608 | int ret = 0; | ||
625 | union { | 609 | union { |
626 | struct sockaddr sa; | 610 | struct sockaddr sa; |
627 | struct sockaddr_in sa_in; | 611 | struct sockaddr_in sa_in; |
628 | #if OPENSSL_USE_IPV6 | 612 | #if OPENSSL_USE_IPV6 |
629 | struct sockaddr_in6 sa_in6; | 613 | struct sockaddr_in6 sa_in6; |
630 | #endif | 614 | #endif |
631 | } server,client; | 615 | } server, client; |
632 | int s=-1,cs,addrlen; | 616 | int s = -1, cs, addrlen; |
633 | unsigned char ip[4]; | 617 | unsigned char ip[4]; |
634 | unsigned short port; | 618 | unsigned short port; |
635 | char *str=NULL,*e; | 619 | char *str = NULL, *e; |
636 | char *h,*p; | 620 | char *h, *p; |
637 | unsigned long l; | 621 | unsigned long l; |
638 | int err_num; | 622 | int err_num; |
639 | 623 | ||
640 | if (BIO_sock_init() != 1) return(-1); | 624 | if (BIO_sock_init() != 1) |
625 | return (-1); | ||
641 | 626 | ||
642 | if ((str=BUF_strdup(host)) == NULL) return(-1); | 627 | if ((str = BUF_strdup(host)) == NULL) |
628 | return (-1); | ||
643 | 629 | ||
644 | h=p=NULL; | 630 | h = p = NULL; |
645 | h=str; | 631 | h = str; |
646 | for (e=str; *e; e++) | 632 | for (e = str; *e; e++) { |
647 | { | 633 | if (*e == ':') { |
648 | if (*e == ':') | 634 | p = e; |
649 | { | 635 | } else if (*e == '/') { |
650 | p=e; | 636 | *e = '\0'; |
651 | } | ||
652 | else if (*e == '/') | ||
653 | { | ||
654 | *e='\0'; | ||
655 | break; | 637 | break; |
656 | } | ||
657 | } | 638 | } |
658 | if (p) *p++='\0'; /* points at last ':', '::port' is special [see below] */ | 639 | } |
659 | else p=h,h=NULL; | 640 | if (p) |
641 | *p++='\0'; /* points at last ':', '::port' is special [see below] */ | ||
642 | else | ||
643 | p = h, h = NULL; | ||
660 | 644 | ||
661 | #ifdef EAI_FAMILY | 645 | #ifdef EAI_FAMILY |
662 | do { | 646 | do { |
663 | static union { void *p; | 647 | static union { |
664 | int (WSAAPI *f)(const char *,const char *, | 648 | void *p; |
665 | const struct addrinfo *, | 649 | int (WSAAPI *f)(const char *, const char *, |
666 | struct addrinfo **); | 650 | const struct addrinfo *, |
667 | } p_getaddrinfo = {NULL}; | 651 | struct addrinfo **); |
668 | static union { void *p; | 652 | } p_getaddrinfo = {NULL}; |
653 | static union { | ||
654 | void *p; | ||
669 | void (WSAAPI *f)(struct addrinfo *); | 655 | void (WSAAPI *f)(struct addrinfo *); |
670 | } p_freeaddrinfo = {NULL}; | 656 | } p_freeaddrinfo = {NULL}; |
671 | struct addrinfo *res,hint; | 657 | struct addrinfo *res, hint; |
672 | 658 | ||
673 | if (p_getaddrinfo.p==NULL) | 659 | if (p_getaddrinfo.p == NULL) { |
674 | { | 660 | if ((p_getaddrinfo.p = DSO_global_lookup("getaddrinfo"))==NULL || |
675 | if ((p_getaddrinfo.p=DSO_global_lookup("getaddrinfo"))==NULL || | 661 | (p_freeaddrinfo.p = DSO_global_lookup("freeaddrinfo"))==NULL) |
676 | (p_freeaddrinfo.p=DSO_global_lookup("freeaddrinfo"))==NULL) | 662 | p_getaddrinfo.p = (void*) - 1; |
677 | p_getaddrinfo.p=(void*)-1; | 663 | } |
678 | } | 664 | if (p_getaddrinfo.p == (void *) - 1) break; |
679 | if (p_getaddrinfo.p==(void *)-1) break; | 665 | |
680 | 666 | /* '::port' enforces IPv6 wildcard listener. Some OSes, | |
681 | /* '::port' enforces IPv6 wildcard listener. Some OSes, | 667 | * e.g. Solaris, default to IPv6 without any hint. Also |
682 | * e.g. Solaris, default to IPv6 without any hint. Also | 668 | * note that commonly IPv6 wildchard socket can service |
683 | * note that commonly IPv6 wildchard socket can service | 669 | * IPv4 connections just as well... */ |
684 | * IPv4 connections just as well... */ | 670 | memset(&hint, 0, sizeof(hint)); |
685 | memset(&hint,0,sizeof(hint)); | 671 | hint.ai_flags = AI_PASSIVE; |
686 | hint.ai_flags = AI_PASSIVE; | 672 | if (h) { |
687 | if (h) | 673 | if (strchr(h, ':')) { |
688 | { | 674 | if (h[1] == '\0') |
689 | if (strchr(h,':')) | 675 | h = NULL; |
690 | { | ||
691 | if (h[1]=='\0') h=NULL; | ||
692 | #if OPENSSL_USE_IPV6 | 676 | #if OPENSSL_USE_IPV6 |
693 | hint.ai_family = AF_INET6; | 677 | hint.ai_family = AF_INET6; |
694 | #else | 678 | #else |
695 | h=NULL; | 679 | h = NULL; |
696 | #endif | 680 | #endif |
697 | } | 681 | } else if (h[0] == '*' && h[1] == '\0') { |
698 | else if (h[0]=='*' && h[1]=='\0') | 682 | hint.ai_family = AF_INET; |
699 | { | 683 | h = NULL; |
700 | hint.ai_family = AF_INET; | ||
701 | h=NULL; | ||
702 | } | 684 | } |
703 | } | 685 | } |
704 | 686 | ||
705 | if ((*p_getaddrinfo.f)(h,p,&hint,&res)) break; | 687 | if ((*p_getaddrinfo.f)(h, p, &hint, &res)) |
688 | break; | ||
706 | 689 | ||
707 | addrlen = res->ai_addrlen<=sizeof(server) ? | 690 | addrlen = res->ai_addrlen <= sizeof(server) ? |
708 | res->ai_addrlen : | 691 | res->ai_addrlen : sizeof(server); |
709 | sizeof(server); | 692 | memcpy(&server, res->ai_addr, addrlen); |
710 | memcpy(&server, res->ai_addr, addrlen); | ||
711 | 693 | ||
712 | (*p_freeaddrinfo.f)(res); | 694 | (*p_freeaddrinfo.f)(res); |
713 | goto again; | 695 | goto again; |
714 | } while (0); | 696 | } while (0); |
715 | #endif | 697 | #endif |
716 | 698 | ||
717 | if (!BIO_get_port(p,&port)) goto err; | 699 | if (!BIO_get_port(p, &port)) |
700 | goto err; | ||
718 | 701 | ||
719 | memset((char *)&server,0,sizeof(server)); | 702 | memset((char *)&server, 0, sizeof(server)); |
720 | server.sa_in.sin_family=AF_INET; | 703 | server.sa_in.sin_family = AF_INET; |
721 | server.sa_in.sin_port=htons(port); | 704 | server.sa_in.sin_port = htons(port); |
722 | addrlen = sizeof(server.sa_in); | 705 | addrlen = sizeof(server.sa_in); |
723 | 706 | ||
724 | if (h == NULL || strcmp(h,"*") == 0) | 707 | if (h == NULL || strcmp(h, "*") == 0) |
725 | server.sa_in.sin_addr.s_addr=INADDR_ANY; | 708 | server.sa_in.sin_addr.s_addr = INADDR_ANY; |
726 | else | 709 | else { |
727 | { | 710 | if (!BIO_get_host_ip(h, &(ip[0]))) |
728 | if (!BIO_get_host_ip(h,&(ip[0]))) goto err; | 711 | goto err; |
729 | l=(unsigned long) | 712 | l = (unsigned long) |
730 | ((unsigned long)ip[0]<<24L)| | 713 | ((unsigned long)ip[0]<<24L)| |
731 | ((unsigned long)ip[1]<<16L)| | 714 | ((unsigned long)ip[1]<<16L)| |
732 | ((unsigned long)ip[2]<< 8L)| | 715 | ((unsigned long)ip[2]<< 8L)| |
733 | ((unsigned long)ip[3]); | 716 | ((unsigned long)ip[3]); |
734 | server.sa_in.sin_addr.s_addr=htonl(l); | 717 | server.sa_in.sin_addr.s_addr = htonl(l); |
735 | } | 718 | } |
736 | 719 | ||
737 | again: | 720 | again: |
738 | s=socket(server.sa.sa_family,SOCK_STREAM,SOCKET_PROTOCOL); | 721 | s = socket(server.sa.sa_family, SOCK_STREAM, SOCKET_PROTOCOL); |
739 | if (s == -1) | 722 | if (s == -1) { |
740 | { | 723 | SYSerr(SYS_F_SOCKET, errno); |
741 | SYSerr(SYS_F_SOCKET,errno); | 724 | ERR_add_error_data(3, "port = '", host, "'"); |
742 | ERR_add_error_data(3,"port='",host,"'"); | 725 | BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, BIO_R_UNABLE_TO_CREATE_SOCKET); |
743 | BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_CREATE_SOCKET); | ||
744 | goto err; | 726 | goto err; |
745 | } | 727 | } |
746 | 728 | ||
747 | #ifdef SO_REUSEADDR | 729 | #ifdef SO_REUSEADDR |
748 | if (bind_mode == BIO_BIND_REUSEADDR) | 730 | if (bind_mode == BIO_BIND_REUSEADDR) { |
749 | { | 731 | int i = 1; |
750 | int i=1; | ||
751 | 732 | ||
752 | ret=setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&i,sizeof(i)); | 733 | ret = setsockopt(s, SOL_SOCKET, SO_REUSEADDR,(char *)&i, sizeof(i)); |
753 | bind_mode=BIO_BIND_NORMAL; | 734 | bind_mode = BIO_BIND_NORMAL; |
754 | } | 735 | } |
755 | #endif | 736 | #endif |
756 | if (bind(s,&server.sa,addrlen) == -1) | 737 | if (bind(s, &server.sa, addrlen) == -1) { |
757 | { | ||
758 | #ifdef SO_REUSEADDR | 738 | #ifdef SO_REUSEADDR |
759 | err_num=errno; | 739 | err_num = errno; |
760 | if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) && | 740 | if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) && |
761 | #ifdef OPENSSL_SYS_WINDOWS | 741 | #ifdef OPENSSL_SYS_WINDOWS |
762 | /* Some versions of Windows define EADDRINUSE to | 742 | /* Some versions of Windows define EADDRINUSE to |
763 | * a dummy value. | 743 | * a dummy value. |
764 | */ | 744 | */ |
765 | (err_num == WSAEADDRINUSE)) | 745 | (err_num == WSAEADDRINUSE)) |
766 | #else | 746 | #else |
767 | (err_num == EADDRINUSE)) | 747 | (err_num == EADDRINUSE)) |
768 | #endif | 748 | #endif |
769 | { | 749 | { |
770 | client = server; | 750 | client = server; |
771 | if (h == NULL || strcmp(h,"*") == 0) | 751 | if (h == NULL || strcmp(h, "*") == 0) { |
772 | { | ||
773 | #if OPENSSL_USE_IPV6 | 752 | #if OPENSSL_USE_IPV6 |
774 | if (client.sa.sa_family == AF_INET6) | 753 | if (client.sa.sa_family == AF_INET6) { |
775 | { | 754 | memset(&client.sa_in6.sin6_addr, 0, sizeof(client.sa_in6.sin6_addr)); |
776 | memset(&client.sa_in6.sin6_addr,0,sizeof(client.sa_in6.sin6_addr)); | 755 | client.sa_in6.sin6_addr.s6_addr[15] = 1; |
777 | client.sa_in6.sin6_addr.s6_addr[15]=1; | 756 | } else |
778 | } | 757 | #endif |
779 | else | 758 | if (client.sa.sa_family == AF_INET) { |
780 | #endif | 759 | client.sa_in.sin_addr.s_addr = htonl(0x7F000001); |
781 | if (client.sa.sa_family == AF_INET) | 760 | } else |
782 | { | 761 | goto err; |
783 | client.sa_in.sin_addr.s_addr=htonl(0x7F000001); | 762 | } |
784 | } | 763 | cs = socket(client.sa.sa_family, SOCK_STREAM, SOCKET_PROTOCOL); |
785 | else goto err; | 764 | if (cs != -1) { |
786 | } | ||
787 | cs=socket(client.sa.sa_family,SOCK_STREAM,SOCKET_PROTOCOL); | ||
788 | if (cs != -1) | ||
789 | { | ||
790 | int ii; | 765 | int ii; |
791 | ii=connect(cs,&client.sa,addrlen); | 766 | ii = connect(cs, &client.sa, addrlen); |
792 | close(cs); | 767 | close(cs); |
793 | if (ii == -1) | 768 | if (ii == -1) { |
794 | { | 769 | bind_mode = BIO_BIND_REUSEADDR; |
795 | bind_mode=BIO_BIND_REUSEADDR; | ||
796 | close(s); | 770 | close(s); |
797 | goto again; | 771 | goto again; |
798 | } | ||
799 | /* else error */ | ||
800 | } | 772 | } |
801 | /* else error */ | 773 | /* else error */ |
802 | } | 774 | } |
775 | /* else error */ | ||
776 | } | ||
803 | #endif | 777 | #endif |
804 | SYSerr(SYS_F_BIND,err_num); | 778 | SYSerr(SYS_F_BIND, err_num); |
805 | ERR_add_error_data(3,"port='",host,"'"); | 779 | ERR_add_error_data(3, "port = '", host, "'"); |
806 | BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_BIND_SOCKET); | 780 | BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, BIO_R_UNABLE_TO_BIND_SOCKET); |
807 | goto err; | 781 | goto err; |
808 | } | 782 | } |
809 | if (listen(s,MAX_LISTEN) == -1) | 783 | if (listen(s, MAX_LISTEN) == -1) { |
810 | { | 784 | SYSerr(SYS_F_BIND, errno); |
811 | SYSerr(SYS_F_BIND,errno); | 785 | ERR_add_error_data(3, "port = '", host, "'"); |
812 | ERR_add_error_data(3,"port='",host,"'"); | 786 | BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, BIO_R_UNABLE_TO_LISTEN_SOCKET); |
813 | BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_LISTEN_SOCKET); | ||
814 | goto err; | 787 | goto err; |
815 | } | 788 | } |
816 | ret=1; | 789 | ret = 1; |
817 | err: | 790 | err: |
818 | if (str != NULL) OPENSSL_free(str); | 791 | if (str != NULL) |
819 | if ((ret == 0) && (s != -1)) | 792 | OPENSSL_free(str); |
820 | { | 793 | if ((ret == 0) && (s != -1)) { |
821 | close(s); | 794 | close(s); |
822 | s= -1; | 795 | s = -1; |
823 | } | ||
824 | return(s); | ||
825 | } | 796 | } |
797 | return (s); | ||
798 | } | ||
826 | 799 | ||
827 | int BIO_accept(int sock, char **addr) | 800 | int |
828 | { | 801 | BIO_accept(int sock, char **addr) |
829 | int ret=-1; | 802 | { |
803 | int ret = -1; | ||
830 | unsigned long l; | 804 | unsigned long l; |
831 | unsigned short port; | 805 | unsigned short port; |
832 | char *p; | 806 | char *p; |
833 | 807 | ||
834 | struct { | 808 | struct { |
835 | /* | 809 | /* |
836 | * As for following union. Trouble is that there are platforms | 810 | * As for following union. Trouble is that there are platforms |
837 | * that have socklen_t and there are platforms that don't, on | 811 | * that have socklen_t and there are platforms that don't, on |
838 | * some platforms socklen_t is int and on some size_t. So what | 812 | * some platforms socklen_t is int and on some size_t. So what |
839 | * one can do? One can cook #ifdef spaghetti, which is nothing | 813 | * one can do? One can cook #ifdef spaghetti, which is nothing |
840 | * but masochistic. Or one can do union between int and size_t. | 814 | * but masochistic. Or one can do union between int and size_t. |
841 | * One naturally does it primarily for 64-bit platforms where | 815 | * One naturally does it primarily for 64-bit platforms where |
842 | * sizeof(int) != sizeof(size_t). But would it work? Note that | 816 | * sizeof(int) != sizeof(size_t). But would it work? Note that |
843 | * if size_t member is initialized to 0, then later int member | 817 | * if size_t member is initialized to 0, then later int member |
844 | * assignment naturally does the job on little-endian platforms | 818 | * assignment naturally does the job on little-endian platforms |
845 | * regardless accept's expectations! What about big-endians? | 819 | * regardless accept's expectations! What about big-endians? |
846 | * If accept expects int*, then it works, and if size_t*, then | 820 | * If accept expects int*, then it works, and if size_t*, then |
847 | * length value would appear as unreasonably large. But this | 821 | * length value would appear as unreasonably large. But this |
848 | * won't prevent it from filling in the address structure. The | 822 | * won't prevent it from filling in the address structure. The |
849 | * trouble of course would be if accept returns more data than | 823 | * trouble of course would be if accept returns more data than |
850 | * actual buffer can accomodate and overwrite stack... That's | 824 | * actual buffer can accomodate and overwrite stack... That's |
851 | * where early OPENSSL_assert comes into picture. Besides, the | 825 | * where early OPENSSL_assert comes into picture. Besides, the |
852 | * only 64-bit big-endian platform found so far that expects | 826 | * only 64-bit big-endian platform found so far that expects |
853 | * size_t* is HP-UX, where stack grows towards higher address. | 827 | * size_t* is HP-UX, where stack grows towards higher address. |
854 | * <appro> | 828 | * <appro> |
855 | */ | 829 | */ |
856 | union { size_t s; int i; } len; | 830 | union { |
857 | union { | 831 | size_t s; |
858 | struct sockaddr sa; | 832 | int i; |
859 | struct sockaddr_in sa_in; | 833 | } len; |
834 | union { | ||
835 | struct sockaddr sa; | ||
836 | struct sockaddr_in sa_in; | ||
860 | #if OPENSSL_USE_IPV6 | 837 | #if OPENSSL_USE_IPV6 |
861 | struct sockaddr_in6 sa_in6; | 838 | struct sockaddr_in6 sa_in6; |
862 | #endif | 839 | #endif |
863 | } from; | 840 | } from; |
864 | } sa; | 841 | } sa; |
865 | 842 | ||
866 | sa.len.s=0; | 843 | sa.len.s = 0; |
867 | sa.len.i=sizeof(sa.from); | 844 | sa.len.i = sizeof(sa.from); |
868 | memset(&sa.from,0,sizeof(sa.from)); | 845 | memset(&sa.from, 0, sizeof(sa.from)); |
869 | ret=accept(sock,&sa.from.sa,(void *)&sa.len); | 846 | ret = accept(sock, &sa.from.sa,(void *)&sa.len); |
870 | if (sizeof(sa.len.i)!=sizeof(sa.len.s) && sa.len.i==0) | 847 | if (sizeof(sa.len.i) != sizeof(sa.len.s) && sa.len.i == 0) { |
871 | { | 848 | OPENSSL_assert(sa.len.s <= sizeof(sa.from)); |
872 | OPENSSL_assert(sa.len.s<=sizeof(sa.from)); | ||
873 | sa.len.i = (int)sa.len.s; | 849 | sa.len.i = (int)sa.len.s; |
874 | /* use sa.len.i from this point */ | 850 | /* use sa.len.i from this point */ |
875 | } | 851 | } |
876 | if (ret == -1) | 852 | if (ret == -1) { |
877 | { | 853 | if (BIO_sock_should_retry(ret)) return -2; |
878 | if(BIO_sock_should_retry(ret)) return -2; | 854 | SYSerr(SYS_F_ACCEPT, errno); |
879 | SYSerr(SYS_F_ACCEPT,errno); | 855 | BIOerr(BIO_F_BIO_ACCEPT, BIO_R_ACCEPT_ERROR); |
880 | BIOerr(BIO_F_BIO_ACCEPT,BIO_R_ACCEPT_ERROR); | ||
881 | goto end; | 856 | goto end; |
882 | } | 857 | } |
883 | 858 | ||
884 | if (addr == NULL) goto end; | 859 | if (addr == NULL) |
860 | goto end; | ||
885 | 861 | ||
886 | #ifdef EAI_FAMILY | 862 | #ifdef EAI_FAMILY |
887 | do { | 863 | do { |
888 | char h[NI_MAXHOST],s[NI_MAXSERV]; | 864 | char h[NI_MAXHOST], s[NI_MAXSERV]; |
889 | size_t nl; | 865 | size_t nl; |
890 | static union { void *p; | 866 | static union { |
891 | int (WSAAPI *f)(const struct sockaddr *,size_t/*socklen_t*/, | 867 | void *p; |
892 | char *,size_t,char *,size_t,int); | 868 | int (WSAAPI *f)(const struct sockaddr *, |
893 | } p_getnameinfo = {NULL}; | 869 | size_t/*socklen_t*/, char *, size_t, |
894 | /* 2nd argument to getnameinfo is specified to | 870 | char *, size_t, int); |
895 | * be socklen_t. Unfortunately there is a number | 871 | } p_getnameinfo = {NULL}; |
896 | * of environments where socklen_t is not defined. | 872 | /* 2nd argument to getnameinfo is specified to |
897 | * As it's passed by value, it's safe to pass it | 873 | * be socklen_t. Unfortunately there is a number |
898 | * as size_t... <appro> */ | 874 | * of environments where socklen_t is not defined. |
899 | 875 | * As it's passed by value, it's safe to pass it | |
900 | if (p_getnameinfo.p==NULL) | 876 | * as size_t... <appro> */ |
901 | { | 877 | |
902 | if ((p_getnameinfo.p=DSO_global_lookup("getnameinfo"))==NULL) | 878 | if (p_getnameinfo.p == NULL) { |
903 | p_getnameinfo.p=(void*)-1; | 879 | if ((p_getnameinfo.p = DSO_global_lookup("getnameinfo")) == NULL) |
880 | p_getnameinfo.p = (void*) - 1; | ||
881 | } | ||
882 | if (p_getnameinfo.p == (void *) - 1) | ||
883 | break; | ||
884 | |||
885 | if ((*p_getnameinfo.f)(&sa.from.sa, sa.len.i, h, sizeof(h), | ||
886 | s, sizeof(s), NI_NUMERICHOST|NI_NUMERICSERV)) | ||
887 | break; | ||
888 | nl = strlen(h) + strlen(s) + 2; | ||
889 | p = *addr; | ||
890 | if (p) { | ||
891 | *p = '\0'; | ||
892 | p = OPENSSL_realloc(p, nl); | ||
893 | } else { | ||
894 | p = OPENSSL_malloc(nl); | ||
895 | } | ||
896 | if (p == NULL) { | ||
897 | BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); | ||
898 | goto end; | ||
904 | } | 899 | } |
905 | if (p_getnameinfo.p==(void *)-1) break; | 900 | *addr = p; |
906 | 901 | (void) snprintf(*addr, nl, "%s:%s", h, s); | |
907 | if ((*p_getnameinfo.f)(&sa.from.sa,sa.len.i,h,sizeof(h),s,sizeof(s), | ||
908 | NI_NUMERICHOST|NI_NUMERICSERV)) break; | ||
909 | nl = strlen(h)+strlen(s)+2; | ||
910 | p = *addr; | ||
911 | if (p) { *p = '\0'; p = OPENSSL_realloc(p,nl); } | ||
912 | else { p = OPENSSL_malloc(nl); } | ||
913 | if (p==NULL) | ||
914 | { | ||
915 | BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE); | ||
916 | goto end; | 902 | goto end; |
917 | } | 903 | } while (0); |
918 | *addr = p; | 904 | #endif |
919 | (void) snprintf(*addr,nl,"%s:%s",h,s); | 905 | if (sa.from.sa.sa_family != AF_INET) |
920 | goto end; | 906 | goto end; |
921 | } while(0); | 907 | l = ntohl(sa.from.sa_in.sin_addr.s_addr); |
922 | #endif | 908 | port = ntohs(sa.from.sa_in.sin_port); |
923 | if (sa.from.sa.sa_family != AF_INET) goto end; | 909 | if (*addr == NULL) { |
924 | l=ntohl(sa.from.sa_in.sin_addr.s_addr); | 910 | if ((p = OPENSSL_malloc(24)) == NULL) { |
925 | port=ntohs(sa.from.sa_in.sin_port); | 911 | BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); |
926 | if (*addr == NULL) | ||
927 | { | ||
928 | if ((p=OPENSSL_malloc(24)) == NULL) | ||
929 | { | ||
930 | BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE); | ||
931 | goto end; | 912 | goto end; |
932 | } | ||
933 | *addr=p; | ||
934 | } | 913 | } |
935 | (void) snprintf(*addr,24,"%d.%d.%d.%d:%d", | 914 | *addr = p; |
936 | (unsigned char)(l>>24L)&0xff, | ||
937 | (unsigned char)(l>>16L)&0xff, | ||
938 | (unsigned char)(l>> 8L)&0xff, | ||
939 | (unsigned char)(l )&0xff, | ||
940 | port); | ||
941 | end: | ||
942 | return(ret); | ||
943 | } | 915 | } |
916 | (void) snprintf(*addr, 24, "%d.%d.%d.%d:%d", | ||
917 | (unsigned char)(l >> 24L) & 0xff, (unsigned char)(l >> 16L) & 0xff, | ||
918 | (unsigned char)(l >> 8L) & 0xff, (unsigned char)(l) & 0xff, port); | ||
944 | 919 | ||
945 | int BIO_set_tcp_ndelay(int s, int on) | 920 | end: |
946 | { | 921 | return (ret); |
947 | int ret=0; | 922 | } |
923 | |||
924 | int | ||
925 | BIO_set_tcp_ndelay(int s, int on) | ||
926 | { | ||
927 | int ret = 0; | ||
948 | #if defined(TCP_NODELAY) && (defined(IPPROTO_TCP) || defined(SOL_TCP)) | 928 | #if defined(TCP_NODELAY) && (defined(IPPROTO_TCP) || defined(SOL_TCP)) |
949 | int opt; | 929 | int opt; |
950 | 930 | ||
951 | #ifdef SOL_TCP | 931 | #ifdef SOL_TCP |
952 | opt=SOL_TCP; | 932 | opt = SOL_TCP; |
953 | #else | 933 | #else |
954 | #ifdef IPPROTO_TCP | 934 | #ifdef IPPROTO_TCP |
955 | opt=IPPROTO_TCP; | 935 | opt = IPPROTO_TCP; |
956 | #endif | 936 | #endif |
957 | #endif | 937 | #endif |
958 | 938 | ||
959 | ret=setsockopt(s,opt,TCP_NODELAY,(char *)&on,sizeof(on)); | 939 | ret = setsockopt(s, opt, TCP_NODELAY,(char *)&on, sizeof(on)); |
960 | #endif | 940 | #endif |
961 | return(ret == 0); | 941 | return (ret == 0); |
962 | } | 942 | } |
963 | 943 | ||
964 | int BIO_socket_nbio(int s, int mode) | 944 | int |
965 | { | 945 | BIO_socket_nbio(int s, int mode) |
966 | int ret= -1; | 946 | { |
947 | int ret = -1; | ||
967 | int l; | 948 | int l; |
968 | 949 | ||
969 | l=mode; | 950 | l = mode; |
970 | #ifdef FIONBIO | 951 | #ifdef FIONBIO |
971 | ret=BIO_socket_ioctl(s,FIONBIO,&l); | 952 | ret = BIO_socket_ioctl(s, FIONBIO, &l); |
972 | #endif | 953 | #endif |
973 | return(ret == 0); | 954 | return (ret == 0); |
974 | } | 955 | } |
975 | #endif | 956 | #endif |
diff --git a/src/lib/libcrypto/bio/bf_buff.c b/src/lib/libcrypto/bio/bf_buff.c index 4b5a132d8a..9518cf977e 100644 --- a/src/lib/libcrypto/bio/bf_buff.c +++ b/src/lib/libcrypto/bio/bf_buff.c | |||
@@ -61,7 +61,7 @@ | |||
61 | #include "cryptlib.h" | 61 | #include "cryptlib.h" |
62 | #include <openssl/bio.h> | 62 | #include <openssl/bio.h> |
63 | 63 | ||
64 | static int buffer_write(BIO *h, const char *buf,int num); | 64 | static int buffer_write(BIO *h, const char *buf, int num); |
65 | static int buffer_read(BIO *h, char *buf, int size); | 65 | static int buffer_read(BIO *h, char *buf, int size); |
66 | static int buffer_puts(BIO *h, const char *str); | 66 | static int buffer_puts(BIO *h, const char *str); |
67 | static int buffer_gets(BIO *h, char *str, int size); | 67 | static int buffer_gets(BIO *h, char *str, int size); |
@@ -71,8 +71,7 @@ static int buffer_free(BIO *data); | |||
71 | static long buffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); | 71 | static long buffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); |
72 | #define DEFAULT_BUFFER_SIZE 4096 | 72 | #define DEFAULT_BUFFER_SIZE 4096 |
73 | 73 | ||
74 | static BIO_METHOD methods_buffer= | 74 | static BIO_METHOD methods_buffer = { |
75 | { | ||
76 | BIO_TYPE_BUFFER, | 75 | BIO_TYPE_BUFFER, |
77 | "buffer", | 76 | "buffer", |
78 | buffer_write, | 77 | buffer_write, |
@@ -83,430 +82,444 @@ static BIO_METHOD methods_buffer= | |||
83 | buffer_new, | 82 | buffer_new, |
84 | buffer_free, | 83 | buffer_free, |
85 | buffer_callback_ctrl, | 84 | buffer_callback_ctrl, |
86 | }; | 85 | }; |
87 | 86 | ||
88 | BIO_METHOD *BIO_f_buffer(void) | 87 | BIO_METHOD |
89 | { | 88 | *BIO_f_buffer(void) |
90 | return(&methods_buffer); | 89 | { |
91 | } | 90 | return (&methods_buffer); |
91 | } | ||
92 | 92 | ||
93 | static int buffer_new(BIO *bi) | 93 | static int |
94 | { | 94 | buffer_new(BIO *bi) |
95 | { | ||
95 | BIO_F_BUFFER_CTX *ctx; | 96 | BIO_F_BUFFER_CTX *ctx; |
96 | 97 | ||
97 | ctx=(BIO_F_BUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_F_BUFFER_CTX)); | 98 | ctx = (BIO_F_BUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_F_BUFFER_CTX)); |
98 | if (ctx == NULL) return(0); | 99 | if (ctx == NULL) |
99 | ctx->ibuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE); | 100 | return (0); |
100 | if (ctx->ibuf == NULL) { OPENSSL_free(ctx); return(0); } | 101 | ctx->ibuf = (char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE); |
101 | ctx->obuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE); | 102 | if (ctx->ibuf == NULL) { |
102 | if (ctx->obuf == NULL) { OPENSSL_free(ctx->ibuf); OPENSSL_free(ctx); return(0); } | 103 | OPENSSL_free(ctx); |
103 | ctx->ibuf_size=DEFAULT_BUFFER_SIZE; | 104 | return (0); |
104 | ctx->obuf_size=DEFAULT_BUFFER_SIZE; | ||
105 | ctx->ibuf_len=0; | ||
106 | ctx->ibuf_off=0; | ||
107 | ctx->obuf_len=0; | ||
108 | ctx->obuf_off=0; | ||
109 | |||
110 | bi->init=1; | ||
111 | bi->ptr=(char *)ctx; | ||
112 | bi->flags=0; | ||
113 | return(1); | ||
114 | } | 105 | } |
115 | 106 | ctx->obuf = (char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE); | |
116 | static int buffer_free(BIO *a) | 107 | if (ctx->obuf == NULL) { |
117 | { | 108 | OPENSSL_free(ctx->ibuf); |
109 | OPENSSL_free(ctx); | ||
110 | return (0); | ||
111 | } | ||
112 | ctx->ibuf_size = DEFAULT_BUFFER_SIZE; | ||
113 | ctx->obuf_size = DEFAULT_BUFFER_SIZE; | ||
114 | ctx->ibuf_len = 0; | ||
115 | ctx->ibuf_off = 0; | ||
116 | ctx->obuf_len = 0; | ||
117 | ctx->obuf_off = 0; | ||
118 | |||
119 | bi->init = 1; | ||
120 | bi->ptr = (char *)ctx; | ||
121 | bi->flags = 0; | ||
122 | return (1); | ||
123 | } | ||
124 | |||
125 | static int | ||
126 | buffer_free(BIO *a) | ||
127 | { | ||
118 | BIO_F_BUFFER_CTX *b; | 128 | BIO_F_BUFFER_CTX *b; |
119 | 129 | ||
120 | if (a == NULL) return(0); | 130 | if (a == NULL) |
121 | b=(BIO_F_BUFFER_CTX *)a->ptr; | 131 | return (0); |
122 | if (b->ibuf != NULL) OPENSSL_free(b->ibuf); | 132 | b = (BIO_F_BUFFER_CTX *)a->ptr; |
123 | if (b->obuf != NULL) OPENSSL_free(b->obuf); | 133 | if (b->ibuf != NULL) |
134 | OPENSSL_free(b->ibuf); | ||
135 | if (b->obuf != NULL) | ||
136 | OPENSSL_free(b->obuf); | ||
124 | OPENSSL_free(a->ptr); | 137 | OPENSSL_free(a->ptr); |
125 | a->ptr=NULL; | 138 | a->ptr = NULL; |
126 | a->init=0; | 139 | a->init = 0; |
127 | a->flags=0; | 140 | a->flags = 0; |
128 | return(1); | 141 | return (1); |
129 | } | 142 | } |
130 | 143 | ||
131 | static int buffer_read(BIO *b, char *out, int outl) | 144 | static int |
132 | { | 145 | buffer_read(BIO *b, char *out, int outl) |
133 | int i,num=0; | 146 | { |
147 | int i, num = 0; | ||
134 | BIO_F_BUFFER_CTX *ctx; | 148 | BIO_F_BUFFER_CTX *ctx; |
135 | 149 | ||
136 | if (out == NULL) return(0); | 150 | if (out == NULL) |
137 | ctx=(BIO_F_BUFFER_CTX *)b->ptr; | 151 | return (0); |
152 | ctx = (BIO_F_BUFFER_CTX *)b->ptr; | ||
138 | 153 | ||
139 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | 154 | if ((ctx == NULL) || (b->next_bio == NULL)) |
140 | num=0; | 155 | return (0); |
156 | num = 0; | ||
141 | BIO_clear_retry_flags(b); | 157 | BIO_clear_retry_flags(b); |
142 | 158 | ||
143 | start: | 159 | start: |
144 | i=ctx->ibuf_len; | 160 | i = ctx->ibuf_len; |
145 | /* If there is stuff left over, grab it */ | 161 | /* If there is stuff left over, grab it */ |
146 | if (i != 0) | 162 | if (i != 0) { |
147 | { | 163 | if (i > outl) |
148 | if (i > outl) i=outl; | 164 | i = outl; |
149 | memcpy(out,&(ctx->ibuf[ctx->ibuf_off]),i); | 165 | memcpy(out, &(ctx->ibuf[ctx->ibuf_off]), i); |
150 | ctx->ibuf_off+=i; | 166 | ctx->ibuf_off += i; |
151 | ctx->ibuf_len-=i; | 167 | ctx->ibuf_len -= i; |
152 | num+=i; | 168 | num += i; |
153 | if (outl == i) return(num); | 169 | if (outl == i) |
154 | outl-=i; | 170 | return (num); |
155 | out+=i; | 171 | outl -= i; |
156 | } | 172 | out += i; |
173 | } | ||
157 | 174 | ||
158 | /* We may have done a partial read. try to do more. | 175 | /* We may have done a partial read. try to do more. |
159 | * We have nothing in the buffer. | 176 | * We have nothing in the buffer. |
160 | * If we get an error and have read some data, just return it | 177 | * If we get an error and have read some data, just return it |
161 | * and let them retry to get the error again. | 178 | * and let them retry to get the error again. |
162 | * copy direct to parent address space */ | 179 | * copy direct to parent address space */ |
163 | if (outl > ctx->ibuf_size) | 180 | if (outl > ctx->ibuf_size) { |
164 | { | 181 | for (;;) { |
165 | for (;;) | 182 | i = BIO_read(b->next_bio, out, outl); |
166 | { | 183 | if (i <= 0) { |
167 | i=BIO_read(b->next_bio,out,outl); | ||
168 | if (i <= 0) | ||
169 | { | ||
170 | BIO_copy_next_retry(b); | 184 | BIO_copy_next_retry(b); |
171 | if (i < 0) return((num > 0)?num:i); | 185 | if (i < 0) |
172 | if (i == 0) return(num); | 186 | return ((num > 0) ? num : i); |
173 | } | 187 | if (i == 0) |
174 | num+=i; | 188 | return (num); |
175 | if (outl == i) return(num); | ||
176 | out+=i; | ||
177 | outl-=i; | ||
178 | } | 189 | } |
190 | num += i; | ||
191 | if (outl == i) | ||
192 | return (num); | ||
193 | out += i; | ||
194 | outl -= i; | ||
179 | } | 195 | } |
196 | } | ||
180 | /* else */ | 197 | /* else */ |
181 | 198 | ||
182 | /* we are going to be doing some buffering */ | 199 | /* we are going to be doing some buffering */ |
183 | i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size); | 200 | i = BIO_read(b->next_bio, ctx->ibuf, ctx->ibuf_size); |
184 | if (i <= 0) | 201 | if (i <= 0) { |
185 | { | ||
186 | BIO_copy_next_retry(b); | 202 | BIO_copy_next_retry(b); |
187 | if (i < 0) return((num > 0)?num:i); | 203 | if (i < 0) |
188 | if (i == 0) return(num); | 204 | return ((num > 0) ? num : i); |
189 | } | 205 | if (i == 0) |
190 | ctx->ibuf_off=0; | 206 | return (num); |
191 | ctx->ibuf_len=i; | 207 | } |
208 | ctx->ibuf_off = 0; | ||
209 | ctx->ibuf_len = i; | ||
192 | 210 | ||
193 | /* Lets re-read using ourselves :-) */ | 211 | /* Lets re-read using ourselves :-) */ |
194 | goto start; | 212 | goto start; |
195 | } | 213 | } |
196 | 214 | ||
197 | static int buffer_write(BIO *b, const char *in, int inl) | 215 | static int |
198 | { | 216 | buffer_write(BIO *b, const char *in, int inl) |
199 | int i,num=0; | 217 | { |
218 | int i, num = 0; | ||
200 | BIO_F_BUFFER_CTX *ctx; | 219 | BIO_F_BUFFER_CTX *ctx; |
201 | 220 | ||
202 | if ((in == NULL) || (inl <= 0)) return(0); | 221 | if ((in == NULL) || (inl <= 0)) |
203 | ctx=(BIO_F_BUFFER_CTX *)b->ptr; | 222 | return (0); |
204 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | 223 | ctx = (BIO_F_BUFFER_CTX *)b->ptr; |
224 | if ((ctx == NULL) || (b->next_bio == NULL)) | ||
225 | return (0); | ||
205 | 226 | ||
206 | BIO_clear_retry_flags(b); | 227 | BIO_clear_retry_flags(b); |
207 | start: | 228 | start: |
208 | i=ctx->obuf_size-(ctx->obuf_len+ctx->obuf_off); | 229 | i = ctx->obuf_size - (ctx->obuf_len + ctx->obuf_off); |
209 | /* add to buffer and return */ | 230 | /* add to buffer and return */ |
210 | if (i >= inl) | 231 | if (i >= inl) { |
211 | { | 232 | memcpy(&(ctx->obuf[ctx->obuf_off + ctx->obuf_len]), in, inl); |
212 | memcpy(&(ctx->obuf[ctx->obuf_off+ctx->obuf_len]),in,inl); | 233 | ctx->obuf_len += inl; |
213 | ctx->obuf_len+=inl; | 234 | return (num + inl); |
214 | return(num+inl); | 235 | } |
215 | } | ||
216 | /* else */ | 236 | /* else */ |
217 | /* stuff already in buffer, so add to it first, then flush */ | 237 | /* stuff already in buffer, so add to it first, then flush */ |
218 | if (ctx->obuf_len != 0) | 238 | if (ctx->obuf_len != 0) { |
219 | { | ||
220 | if (i > 0) /* lets fill it up if we can */ | 239 | if (i > 0) /* lets fill it up if we can */ |
221 | { | 240 | { |
222 | memcpy(&(ctx->obuf[ctx->obuf_off+ctx->obuf_len]),in,i); | 241 | memcpy(&(ctx->obuf[ctx->obuf_off + ctx->obuf_len]), in, i); |
223 | in+=i; | 242 | in += i; |
224 | inl-=i; | 243 | inl -= i; |
225 | num+=i; | 244 | num += i; |
226 | ctx->obuf_len+=i; | 245 | ctx->obuf_len += i; |
227 | } | 246 | } |
228 | /* we now have a full buffer needing flushing */ | 247 | /* we now have a full buffer needing flushing */ |
229 | for (;;) | 248 | for (;;) { |
230 | { | 249 | i = BIO_write(b->next_bio, &(ctx->obuf[ctx->obuf_off]), |
231 | i=BIO_write(b->next_bio,&(ctx->obuf[ctx->obuf_off]), | 250 | ctx->obuf_len); |
232 | ctx->obuf_len); | 251 | if (i <= 0) { |
233 | if (i <= 0) | ||
234 | { | ||
235 | BIO_copy_next_retry(b); | 252 | BIO_copy_next_retry(b); |
236 | 253 | ||
237 | if (i < 0) return((num > 0)?num:i); | 254 | if (i < 0) |
238 | if (i == 0) return(num); | 255 | return ((num > 0) ? num : i); |
239 | } | 256 | if (i == 0) |
240 | ctx->obuf_off+=i; | 257 | return (num); |
241 | ctx->obuf_len-=i; | ||
242 | if (ctx->obuf_len == 0) break; | ||
243 | } | 258 | } |
259 | ctx->obuf_off += i; | ||
260 | ctx->obuf_len -= i; | ||
261 | if (ctx->obuf_len == 0) | ||
262 | break; | ||
244 | } | 263 | } |
264 | } | ||
245 | /* we only get here if the buffer has been flushed and we | 265 | /* we only get here if the buffer has been flushed and we |
246 | * still have stuff to write */ | 266 | * still have stuff to write */ |
247 | ctx->obuf_off=0; | 267 | ctx->obuf_off = 0; |
248 | 268 | ||
249 | /* we now have inl bytes to write */ | 269 | /* we now have inl bytes to write */ |
250 | while (inl >= ctx->obuf_size) | 270 | while (inl >= ctx->obuf_size) { |
251 | { | 271 | i = BIO_write(b->next_bio, in, inl); |
252 | i=BIO_write(b->next_bio,in,inl); | 272 | if (i <= 0) { |
253 | if (i <= 0) | ||
254 | { | ||
255 | BIO_copy_next_retry(b); | 273 | BIO_copy_next_retry(b); |
256 | if (i < 0) return((num > 0)?num:i); | 274 | if (i < 0) |
257 | if (i == 0) return(num); | 275 | return ((num > 0) ? num : i); |
258 | } | 276 | if (i == 0) |
259 | num+=i; | 277 | return (num); |
260 | in+=i; | ||
261 | inl-=i; | ||
262 | if (inl == 0) return(num); | ||
263 | } | 278 | } |
279 | num += i; | ||
280 | in += i; | ||
281 | inl -= i; | ||
282 | if (inl == 0) | ||
283 | return (num); | ||
284 | } | ||
264 | 285 | ||
265 | /* copy the rest into the buffer since we have only a small | 286 | /* copy the rest into the buffer since we have only a small |
266 | * amount left */ | 287 | * amount left */ |
267 | goto start; | 288 | goto start; |
268 | } | 289 | } |
269 | 290 | ||
270 | static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr) | 291 | static long |
271 | { | 292 | buffer_ctrl(BIO *b, int cmd, long num, void *ptr) |
293 | { | ||
272 | BIO *dbio; | 294 | BIO *dbio; |
273 | BIO_F_BUFFER_CTX *ctx; | 295 | BIO_F_BUFFER_CTX *ctx; |
274 | long ret=1; | 296 | long ret = 1; |
275 | char *p1,*p2; | 297 | char *p1, *p2; |
276 | int r,i,*ip; | 298 | int r, i, *ip; |
277 | int ibs,obs; | 299 | int ibs, obs; |
278 | 300 | ||
279 | ctx=(BIO_F_BUFFER_CTX *)b->ptr; | 301 | ctx = (BIO_F_BUFFER_CTX *)b->ptr; |
280 | 302 | ||
281 | switch (cmd) | 303 | switch (cmd) { |
282 | { | ||
283 | case BIO_CTRL_RESET: | 304 | case BIO_CTRL_RESET: |
284 | ctx->ibuf_off=0; | 305 | ctx->ibuf_off = 0; |
285 | ctx->ibuf_len=0; | 306 | ctx->ibuf_len = 0; |
286 | ctx->obuf_off=0; | 307 | ctx->obuf_off = 0; |
287 | ctx->obuf_len=0; | 308 | ctx->obuf_len = 0; |
288 | if (b->next_bio == NULL) return(0); | 309 | if (b->next_bio == NULL) |
289 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 310 | return (0); |
311 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
290 | break; | 312 | break; |
291 | case BIO_CTRL_INFO: | 313 | case BIO_CTRL_INFO: |
292 | ret=(long)ctx->obuf_len; | 314 | ret = (long)ctx->obuf_len; |
293 | break; | 315 | break; |
294 | case BIO_C_GET_BUFF_NUM_LINES: | 316 | case BIO_C_GET_BUFF_NUM_LINES: |
295 | ret=0; | 317 | ret = 0; |
296 | p1=ctx->ibuf; | 318 | p1 = ctx->ibuf; |
297 | for (i=0; i<ctx->ibuf_len; i++) | 319 | for (i = 0; i < ctx->ibuf_len; i++) { |
298 | { | 320 | if (p1[ctx->ibuf_off + i] == '\n') |
299 | if (p1[ctx->ibuf_off + i] == '\n') ret++; | 321 | ret++; |
300 | } | 322 | } |
301 | break; | 323 | break; |
302 | case BIO_CTRL_WPENDING: | 324 | case BIO_CTRL_WPENDING: |
303 | ret=(long)ctx->obuf_len; | 325 | ret = (long)ctx->obuf_len; |
304 | if (ret == 0) | 326 | if (ret == 0) { |
305 | { | 327 | if (b->next_bio == NULL) |
306 | if (b->next_bio == NULL) return(0); | 328 | return (0); |
307 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 329 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
308 | } | 330 | } |
309 | break; | 331 | break; |
310 | case BIO_CTRL_PENDING: | 332 | case BIO_CTRL_PENDING: |
311 | ret=(long)ctx->ibuf_len; | 333 | ret = (long)ctx->ibuf_len; |
312 | if (ret == 0) | 334 | if (ret == 0) { |
313 | { | 335 | if (b->next_bio == NULL) |
314 | if (b->next_bio == NULL) return(0); | 336 | return (0); |
315 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 337 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
316 | } | 338 | } |
317 | break; | 339 | break; |
318 | case BIO_C_SET_BUFF_READ_DATA: | 340 | case BIO_C_SET_BUFF_READ_DATA: |
319 | if (num > ctx->ibuf_size) | 341 | if (num > ctx->ibuf_size) { |
320 | { | 342 | p1 = OPENSSL_malloc((int)num); |
321 | p1=OPENSSL_malloc((int)num); | 343 | if (p1 == NULL) |
322 | if (p1 == NULL) goto malloc_error; | 344 | goto malloc_error; |
323 | if (ctx->ibuf != NULL) OPENSSL_free(ctx->ibuf); | 345 | if (ctx->ibuf != NULL) |
324 | ctx->ibuf=p1; | 346 | OPENSSL_free(ctx->ibuf); |
325 | } | 347 | ctx->ibuf = p1; |
326 | ctx->ibuf_off=0; | 348 | } |
327 | ctx->ibuf_len=(int)num; | 349 | ctx->ibuf_off = 0; |
328 | memcpy(ctx->ibuf,ptr,(int)num); | 350 | ctx->ibuf_len = (int)num; |
329 | ret=1; | 351 | memcpy(ctx->ibuf, ptr,(int)num); |
352 | ret = 1; | ||
330 | break; | 353 | break; |
331 | case BIO_C_SET_BUFF_SIZE: | 354 | case BIO_C_SET_BUFF_SIZE: |
332 | if (ptr != NULL) | 355 | if (ptr != NULL) { |
333 | { | 356 | ip = (int *)ptr; |
334 | ip=(int *)ptr; | 357 | if (*ip == 0) { |
335 | if (*ip == 0) | 358 | ibs = (int)num; |
336 | { | 359 | obs = ctx->obuf_size; |
337 | ibs=(int)num; | ||
338 | obs=ctx->obuf_size; | ||
339 | } | ||
340 | else /* if (*ip == 1) */ | ||
341 | { | ||
342 | ibs=ctx->ibuf_size; | ||
343 | obs=(int)num; | ||
344 | } | ||
345 | } | ||
346 | else | ||
347 | { | ||
348 | ibs=(int)num; | ||
349 | obs=(int)num; | ||
350 | } | 360 | } |
351 | p1=ctx->ibuf; | 361 | else /* if (*ip == 1) */ |
352 | p2=ctx->obuf; | ||
353 | if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size)) | ||
354 | { | 362 | { |
355 | p1=(char *)OPENSSL_malloc((int)num); | 363 | ibs = ctx->ibuf_size; |
356 | if (p1 == NULL) goto malloc_error; | 364 | obs = (int)num; |
357 | } | 365 | } |
358 | if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size)) | 366 | } else { |
359 | { | 367 | ibs = (int)num; |
360 | p2=(char *)OPENSSL_malloc((int)num); | 368 | obs = (int)num; |
361 | if (p2 == NULL) | 369 | } |
362 | { | 370 | p1 = ctx->ibuf; |
363 | if (p1 != ctx->ibuf) OPENSSL_free(p1); | 371 | p2 = ctx->obuf; |
372 | if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size)) { | ||
373 | p1 = (char *)OPENSSL_malloc((int)num); | ||
374 | if (p1 == NULL) | ||
375 | goto malloc_error; | ||
376 | } | ||
377 | if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size)) { | ||
378 | p2 = (char *)OPENSSL_malloc((int)num); | ||
379 | if (p2 == NULL) { | ||
380 | if (p1 != ctx->ibuf) | ||
381 | OPENSSL_free(p1); | ||
364 | goto malloc_error; | 382 | goto malloc_error; |
365 | } | ||
366 | } | 383 | } |
367 | if (ctx->ibuf != p1) | 384 | } |
368 | { | 385 | if (ctx->ibuf != p1) { |
369 | OPENSSL_free(ctx->ibuf); | 386 | OPENSSL_free(ctx->ibuf); |
370 | ctx->ibuf=p1; | 387 | ctx->ibuf = p1; |
371 | ctx->ibuf_off=0; | 388 | ctx->ibuf_off = 0; |
372 | ctx->ibuf_len=0; | 389 | ctx->ibuf_len = 0; |
373 | ctx->ibuf_size=ibs; | 390 | ctx->ibuf_size = ibs; |
374 | } | 391 | } |
375 | if (ctx->obuf != p2) | 392 | if (ctx->obuf != p2) { |
376 | { | ||
377 | OPENSSL_free(ctx->obuf); | 393 | OPENSSL_free(ctx->obuf); |
378 | ctx->obuf=p2; | 394 | ctx->obuf = p2; |
379 | ctx->obuf_off=0; | 395 | ctx->obuf_off = 0; |
380 | ctx->obuf_len=0; | 396 | ctx->obuf_len = 0; |
381 | ctx->obuf_size=obs; | 397 | ctx->obuf_size = obs; |
382 | } | 398 | } |
383 | break; | 399 | break; |
384 | case BIO_C_DO_STATE_MACHINE: | 400 | case BIO_C_DO_STATE_MACHINE: |
385 | if (b->next_bio == NULL) return(0); | 401 | if (b->next_bio == NULL) |
402 | return (0); | ||
386 | BIO_clear_retry_flags(b); | 403 | BIO_clear_retry_flags(b); |
387 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 404 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
388 | BIO_copy_next_retry(b); | 405 | BIO_copy_next_retry(b); |
389 | break; | 406 | break; |
390 | 407 | ||
391 | case BIO_CTRL_FLUSH: | 408 | case BIO_CTRL_FLUSH: |
392 | if (b->next_bio == NULL) return(0); | 409 | if (b->next_bio == NULL) |
393 | if (ctx->obuf_len <= 0) | 410 | return (0); |
394 | { | 411 | if (ctx->obuf_len <= 0) { |
395 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 412 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
396 | break; | 413 | break; |
397 | } | 414 | } |
398 | 415 | ||
399 | for (;;) | 416 | for (;;) { |
400 | { | ||
401 | BIO_clear_retry_flags(b); | 417 | BIO_clear_retry_flags(b); |
402 | if (ctx->obuf_len > 0) | 418 | if (ctx->obuf_len > 0) { |
403 | { | 419 | r = BIO_write(b->next_bio, |
404 | r=BIO_write(b->next_bio, | 420 | &(ctx->obuf[ctx->obuf_off]), |
405 | &(ctx->obuf[ctx->obuf_off]), | 421 | ctx->obuf_len); |
406 | ctx->obuf_len); | ||
407 | #if 0 | 422 | #if 0 |
408 | fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len,r); | 423 | fprintf(stderr, "FLUSH [%3d] %3d -> %3d\n", ctx->obuf_off, ctx->obuf_len, r); |
409 | #endif | 424 | #endif |
410 | BIO_copy_next_retry(b); | 425 | BIO_copy_next_retry(b); |
411 | if (r <= 0) return((long)r); | 426 | if (r <= 0) |
412 | ctx->obuf_off+=r; | 427 | return ((long)r); |
413 | ctx->obuf_len-=r; | 428 | ctx->obuf_off += r; |
414 | } | 429 | ctx->obuf_len -= r; |
415 | else | 430 | } else { |
416 | { | 431 | ctx->obuf_len = 0; |
417 | ctx->obuf_len=0; | 432 | ctx->obuf_off = 0; |
418 | ctx->obuf_off=0; | 433 | ret = 1; |
419 | ret=1; | ||
420 | break; | 434 | break; |
421 | } | ||
422 | } | 435 | } |
423 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 436 | } |
437 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
424 | break; | 438 | break; |
425 | case BIO_CTRL_DUP: | 439 | case BIO_CTRL_DUP: |
426 | dbio=(BIO *)ptr; | 440 | dbio = (BIO *)ptr; |
427 | if ( !BIO_set_read_buffer_size(dbio,ctx->ibuf_size) || | 441 | if (!BIO_set_read_buffer_size(dbio, ctx->ibuf_size) || |
428 | !BIO_set_write_buffer_size(dbio,ctx->obuf_size)) | 442 | !BIO_set_write_buffer_size(dbio, ctx->obuf_size)) |
429 | ret=0; | 443 | ret = 0; |
430 | break; | 444 | break; |
431 | default: | 445 | default: |
432 | if (b->next_bio == NULL) return(0); | 446 | if (b->next_bio == NULL) |
433 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 447 | return (0); |
448 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
434 | break; | 449 | break; |
435 | } | ||
436 | return(ret); | ||
437 | malloc_error: | ||
438 | BIOerr(BIO_F_BUFFER_CTRL,ERR_R_MALLOC_FAILURE); | ||
439 | return(0); | ||
440 | } | 450 | } |
441 | 451 | return (ret); | |
442 | static long buffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | 452 | malloc_error: |
443 | { | 453 | BIOerr(BIO_F_BUFFER_CTRL, ERR_R_MALLOC_FAILURE); |
444 | long ret=1; | 454 | return (0); |
445 | 455 | } | |
446 | if (b->next_bio == NULL) return(0); | 456 | |
447 | switch (cmd) | 457 | static long |
448 | { | 458 | buffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) |
459 | { | ||
460 | long ret = 1; | ||
461 | |||
462 | if (b->next_bio == NULL) | ||
463 | return (0); | ||
464 | switch (cmd) { | ||
449 | default: | 465 | default: |
450 | ret=BIO_callback_ctrl(b->next_bio,cmd,fp); | 466 | ret = BIO_callback_ctrl(b->next_bio, cmd, fp); |
451 | break; | 467 | break; |
452 | } | ||
453 | return(ret); | ||
454 | } | 468 | } |
469 | return (ret); | ||
470 | } | ||
455 | 471 | ||
456 | static int buffer_gets(BIO *b, char *buf, int size) | 472 | static int |
457 | { | 473 | buffer_gets(BIO *b, char *buf, int size) |
474 | { | ||
458 | BIO_F_BUFFER_CTX *ctx; | 475 | BIO_F_BUFFER_CTX *ctx; |
459 | int num=0,i,flag; | 476 | int num = 0, i, flag; |
460 | char *p; | 477 | char *p; |
461 | 478 | ||
462 | ctx=(BIO_F_BUFFER_CTX *)b->ptr; | 479 | ctx = (BIO_F_BUFFER_CTX *)b->ptr; |
463 | size--; /* reserve space for a '\0' */ | 480 | size--; /* reserve space for a '\0' */ |
464 | BIO_clear_retry_flags(b); | 481 | BIO_clear_retry_flags(b); |
465 | 482 | ||
466 | for (;;) | 483 | for (;;) { |
467 | { | 484 | if (ctx->ibuf_len > 0) { |
468 | if (ctx->ibuf_len > 0) | 485 | p = &(ctx->ibuf[ctx->ibuf_off]); |
469 | { | 486 | flag = 0; |
470 | p= &(ctx->ibuf[ctx->ibuf_off]); | 487 | for (i = 0; (i < ctx->ibuf_len) && (i < size); i++) { |
471 | flag=0; | 488 | *(buf++) = p[i]; |
472 | for (i=0; (i<ctx->ibuf_len) && (i<size); i++) | 489 | if (p[i] == '\n') { |
473 | { | 490 | flag = 1; |
474 | *(buf++)=p[i]; | ||
475 | if (p[i] == '\n') | ||
476 | { | ||
477 | flag=1; | ||
478 | i++; | 491 | i++; |
479 | break; | 492 | break; |
480 | } | ||
481 | } | ||
482 | num+=i; | ||
483 | size-=i; | ||
484 | ctx->ibuf_len-=i; | ||
485 | ctx->ibuf_off+=i; | ||
486 | if (flag || size == 0) | ||
487 | { | ||
488 | *buf='\0'; | ||
489 | return(num); | ||
490 | } | 493 | } |
491 | } | 494 | } |
495 | num += i; | ||
496 | size -= i; | ||
497 | ctx->ibuf_len -= i; | ||
498 | ctx->ibuf_off += i; | ||
499 | if (flag || size == 0) { | ||
500 | *buf = '\0'; | ||
501 | return (num); | ||
502 | } | ||
503 | } | ||
492 | else /* read another chunk */ | 504 | else /* read another chunk */ |
493 | { | 505 | { |
494 | i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size); | 506 | i = BIO_read(b->next_bio, ctx->ibuf, ctx->ibuf_size); |
495 | if (i <= 0) | 507 | if (i <= 0) { |
496 | { | ||
497 | BIO_copy_next_retry(b); | 508 | BIO_copy_next_retry(b); |
498 | *buf='\0'; | 509 | *buf = '\0'; |
499 | if (i < 0) return((num > 0)?num:i); | 510 | if (i < 0) |
500 | if (i == 0) return(num); | 511 | return ((num > 0) ? num : i); |
501 | } | 512 | if (i == 0) |
502 | ctx->ibuf_len=i; | 513 | return (num); |
503 | ctx->ibuf_off=0; | ||
504 | } | 514 | } |
515 | ctx->ibuf_len = i; | ||
516 | ctx->ibuf_off = 0; | ||
505 | } | 517 | } |
506 | } | 518 | } |
519 | } | ||
507 | 520 | ||
508 | static int buffer_puts(BIO *b, const char *str) | 521 | static int |
509 | { | 522 | buffer_puts(BIO *b, const char *str) |
510 | return(buffer_write(b,str,strlen(str))); | 523 | { |
511 | } | 524 | return (buffer_write(b, str, strlen(str))); |
512 | 525 | } | |
diff --git a/src/lib/libcrypto/bio/bf_lbuf.c b/src/lib/libcrypto/bio/bf_lbuf.c index ec0f7eb0b7..838839f1bf 100644 --- a/src/lib/libcrypto/bio/bf_lbuf.c +++ b/src/lib/libcrypto/bio/bf_lbuf.c | |||
@@ -62,7 +62,7 @@ | |||
62 | #include <openssl/bio.h> | 62 | #include <openssl/bio.h> |
63 | #include <openssl/evp.h> | 63 | #include <openssl/evp.h> |
64 | 64 | ||
65 | static int linebuffer_write(BIO *h, const char *buf,int num); | 65 | static int linebuffer_write(BIO *h, const char *buf, int num); |
66 | static int linebuffer_read(BIO *h, char *buf, int size); | 66 | static int linebuffer_read(BIO *h, char *buf, int size); |
67 | static int linebuffer_puts(BIO *h, const char *str); | 67 | static int linebuffer_puts(BIO *h, const char *str); |
68 | static int linebuffer_gets(BIO *h, char *str, int size); | 68 | static int linebuffer_gets(BIO *h, char *str, int size); |
@@ -76,8 +76,7 @@ static long linebuffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); | |||
76 | 76 | ||
77 | /* #define DEBUG */ | 77 | /* #define DEBUG */ |
78 | 78 | ||
79 | static BIO_METHOD methods_linebuffer= | 79 | static BIO_METHOD methods_linebuffer = { |
80 | { | ||
81 | BIO_TYPE_LINEBUFFER, | 80 | BIO_TYPE_LINEBUFFER, |
82 | "linebuffer", | 81 | "linebuffer", |
83 | linebuffer_write, | 82 | linebuffer_write, |
@@ -88,310 +87,313 @@ static BIO_METHOD methods_linebuffer= | |||
88 | linebuffer_new, | 87 | linebuffer_new, |
89 | linebuffer_free, | 88 | linebuffer_free, |
90 | linebuffer_callback_ctrl, | 89 | linebuffer_callback_ctrl, |
91 | }; | 90 | }; |
92 | 91 | ||
93 | BIO_METHOD *BIO_f_linebuffer(void) | 92 | BIO_METHOD |
94 | { | 93 | *BIO_f_linebuffer(void) |
95 | return(&methods_linebuffer); | 94 | { |
96 | } | 95 | return (&methods_linebuffer); |
96 | } | ||
97 | 97 | ||
98 | typedef struct bio_linebuffer_ctx_struct | 98 | typedef struct bio_linebuffer_ctx_struct { |
99 | { | ||
100 | char *obuf; /* the output char array */ | 99 | char *obuf; /* the output char array */ |
101 | int obuf_size; /* how big is the output buffer */ | 100 | int obuf_size; /* how big is the output buffer */ |
102 | int obuf_len; /* how many bytes are in it */ | 101 | int obuf_len; /* how many bytes are in it */ |
103 | } BIO_LINEBUFFER_CTX; | 102 | } BIO_LINEBUFFER_CTX; |
104 | 103 | ||
105 | static int linebuffer_new(BIO *bi) | 104 | static int |
106 | { | 105 | linebuffer_new(BIO *bi) |
106 | { | ||
107 | BIO_LINEBUFFER_CTX *ctx; | 107 | BIO_LINEBUFFER_CTX *ctx; |
108 | 108 | ||
109 | ctx=(BIO_LINEBUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_LINEBUFFER_CTX)); | 109 | ctx = (BIO_LINEBUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_LINEBUFFER_CTX)); |
110 | if (ctx == NULL) return(0); | 110 | if (ctx == NULL) |
111 | ctx->obuf=(char *)OPENSSL_malloc(DEFAULT_LINEBUFFER_SIZE); | 111 | return (0); |
112 | if (ctx->obuf == NULL) { OPENSSL_free(ctx); return(0); } | 112 | ctx->obuf = (char *)OPENSSL_malloc(DEFAULT_LINEBUFFER_SIZE); |
113 | ctx->obuf_size=DEFAULT_LINEBUFFER_SIZE; | 113 | if (ctx->obuf == NULL) { |
114 | ctx->obuf_len=0; | 114 | OPENSSL_free(ctx); |
115 | 115 | return (0); | |
116 | bi->init=1; | ||
117 | bi->ptr=(char *)ctx; | ||
118 | bi->flags=0; | ||
119 | return(1); | ||
120 | } | 116 | } |
117 | ctx->obuf_size = DEFAULT_LINEBUFFER_SIZE; | ||
118 | ctx->obuf_len = 0; | ||
119 | |||
120 | bi->init = 1; | ||
121 | bi->ptr = (char *)ctx; | ||
122 | bi->flags = 0; | ||
123 | return (1); | ||
124 | } | ||
121 | 125 | ||
122 | static int linebuffer_free(BIO *a) | 126 | static int |
123 | { | 127 | linebuffer_free(BIO *a) |
128 | { | ||
124 | BIO_LINEBUFFER_CTX *b; | 129 | BIO_LINEBUFFER_CTX *b; |
125 | 130 | ||
126 | if (a == NULL) return(0); | 131 | if (a == NULL) |
127 | b=(BIO_LINEBUFFER_CTX *)a->ptr; | 132 | return (0); |
128 | if (b->obuf != NULL) OPENSSL_free(b->obuf); | 133 | b = (BIO_LINEBUFFER_CTX *)a->ptr; |
134 | if (b->obuf != NULL) | ||
135 | OPENSSL_free(b->obuf); | ||
129 | OPENSSL_free(a->ptr); | 136 | OPENSSL_free(a->ptr); |
130 | a->ptr=NULL; | 137 | a->ptr = NULL; |
131 | a->init=0; | 138 | a->init = 0; |
132 | a->flags=0; | 139 | a->flags = 0; |
133 | return(1); | 140 | return (1); |
134 | } | 141 | } |
135 | 142 | ||
136 | static int linebuffer_read(BIO *b, char *out, int outl) | 143 | static int |
137 | { | 144 | linebuffer_read(BIO *b, char *out, int outl) |
138 | int ret=0; | 145 | { |
139 | 146 | int ret = 0; | |
140 | if (out == NULL) return(0); | 147 | |
141 | if (b->next_bio == NULL) return(0); | 148 | if (out == NULL) |
142 | ret=BIO_read(b->next_bio,out,outl); | 149 | return (0); |
150 | if (b->next_bio == NULL) | ||
151 | return (0); | ||
152 | ret = BIO_read(b->next_bio, out, outl); | ||
143 | BIO_clear_retry_flags(b); | 153 | BIO_clear_retry_flags(b); |
144 | BIO_copy_next_retry(b); | 154 | BIO_copy_next_retry(b); |
145 | return(ret); | 155 | return (ret); |
146 | } | 156 | } |
147 | 157 | ||
148 | static int linebuffer_write(BIO *b, const char *in, int inl) | 158 | static int |
149 | { | 159 | linebuffer_write(BIO *b, const char *in, int inl) |
150 | int i,num=0,foundnl; | 160 | { |
161 | int i, num = 0, foundnl; | ||
151 | BIO_LINEBUFFER_CTX *ctx; | 162 | BIO_LINEBUFFER_CTX *ctx; |
152 | 163 | ||
153 | if ((in == NULL) || (inl <= 0)) return(0); | 164 | if ((in == NULL) || (inl <= 0)) |
154 | ctx=(BIO_LINEBUFFER_CTX *)b->ptr; | 165 | return (0); |
155 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | 166 | ctx = (BIO_LINEBUFFER_CTX *)b->ptr; |
167 | if ((ctx == NULL) || (b->next_bio == NULL)) | ||
168 | return (0); | ||
156 | 169 | ||
157 | BIO_clear_retry_flags(b); | 170 | BIO_clear_retry_flags(b); |
158 | 171 | ||
159 | do | 172 | do { |
160 | { | ||
161 | const char *p; | 173 | const char *p; |
162 | 174 | ||
163 | for(p = in; p < in + inl && *p != '\n'; p++) | 175 | for (p = in; p < in + inl && *p != '\n'; p++) |
164 | ; | 176 | ; |
165 | if (*p == '\n') | 177 | if (*p == '\n') { |
166 | { | ||
167 | p++; | 178 | p++; |
168 | foundnl = 1; | 179 | foundnl = 1; |
169 | } | 180 | } else |
170 | else | ||
171 | foundnl = 0; | 181 | foundnl = 0; |
172 | 182 | ||
173 | /* If a NL was found and we already have text in the save | 183 | /* If a NL was found and we already have text in the save |
174 | buffer, concatenate them and write */ | 184 | buffer, concatenate them and write */ |
175 | while ((foundnl || p - in > ctx->obuf_size - ctx->obuf_len) | 185 | while ((foundnl || p - in > ctx->obuf_size - ctx->obuf_len) && |
176 | && ctx->obuf_len > 0) | 186 | ctx->obuf_len > 0) { |
177 | { | ||
178 | int orig_olen = ctx->obuf_len; | 187 | int orig_olen = ctx->obuf_len; |
179 | 188 | ||
180 | i = ctx->obuf_size - ctx->obuf_len; | 189 | i = ctx->obuf_size - ctx->obuf_len; |
181 | if (p - in > 0) | 190 | if (p - in > 0) { |
182 | { | 191 | if (i >= p - in) { |
183 | if (i >= p - in) | ||
184 | { | ||
185 | memcpy(&(ctx->obuf[ctx->obuf_len]), | 192 | memcpy(&(ctx->obuf[ctx->obuf_len]), |
186 | in,p - in); | 193 | in, p - in); |
187 | ctx->obuf_len += p - in; | 194 | ctx->obuf_len += p - in; |
188 | inl -= p - in; | 195 | inl -= p - in; |
189 | num += p - in; | 196 | num += p - in; |
190 | in = p; | 197 | in = p; |
191 | } | 198 | } else { |
192 | else | ||
193 | { | ||
194 | memcpy(&(ctx->obuf[ctx->obuf_len]), | 199 | memcpy(&(ctx->obuf[ctx->obuf_len]), |
195 | in,i); | 200 | in, i); |
196 | ctx->obuf_len += i; | 201 | ctx->obuf_len += i; |
197 | inl -= i; | 202 | inl -= i; |
198 | in += i; | 203 | in += i; |
199 | num += i; | 204 | num += i; |
200 | } | ||
201 | } | 205 | } |
206 | } | ||
202 | 207 | ||
203 | #if 0 | 208 | #if 0 |
204 | BIO_write(b->next_bio, "<*<", 3); | 209 | BIO_write(b->next_bio, "<*<", 3); |
205 | #endif | 210 | #endif |
206 | i=BIO_write(b->next_bio, | 211 | i = BIO_write(b->next_bio, ctx->obuf, ctx->obuf_len); |
207 | ctx->obuf, ctx->obuf_len); | 212 | if (i <= 0) { |
208 | if (i <= 0) | ||
209 | { | ||
210 | ctx->obuf_len = orig_olen; | 213 | ctx->obuf_len = orig_olen; |
211 | BIO_copy_next_retry(b); | 214 | BIO_copy_next_retry(b); |
212 | |||
213 | #if 0 | 215 | #if 0 |
214 | BIO_write(b->next_bio, ">*>", 3); | 216 | BIO_write(b->next_bio, ">*>", 3); |
215 | #endif | 217 | #endif |
216 | if (i < 0) return((num > 0)?num:i); | 218 | if (i < 0) |
217 | if (i == 0) return(num); | 219 | return ((num > 0) ? num : i); |
218 | } | 220 | if (i == 0) |
221 | return (num); | ||
222 | } | ||
219 | #if 0 | 223 | #if 0 |
220 | BIO_write(b->next_bio, ">*>", 3); | 224 | BIO_write(b->next_bio, ">*>", 3); |
221 | #endif | 225 | #endif |
222 | if (i < ctx->obuf_len) | 226 | if (i < ctx->obuf_len) |
223 | memmove(ctx->obuf, ctx->obuf + i, | 227 | memmove(ctx->obuf, ctx->obuf + i, |
224 | ctx->obuf_len - i); | 228 | ctx->obuf_len - i); |
225 | ctx->obuf_len-=i; | 229 | ctx->obuf_len -= i; |
226 | } | 230 | } |
227 | 231 | ||
228 | /* Now that the save buffer is emptied, let's write the input | 232 | /* Now that the save buffer is emptied, let's write the input |
229 | buffer if a NL was found and there is anything to write. */ | 233 | buffer if a NL was found and there is anything to write. */ |
230 | if ((foundnl || p - in > ctx->obuf_size) && p - in > 0) | 234 | if ((foundnl || p - in > ctx->obuf_size) && p - in > 0) { |
231 | { | ||
232 | #if 0 | 235 | #if 0 |
233 | BIO_write(b->next_bio, "<*<", 3); | 236 | BIO_write(b->next_bio, "<*<", 3); |
234 | #endif | 237 | #endif |
235 | i=BIO_write(b->next_bio,in,p - in); | 238 | i = BIO_write(b->next_bio, in, p - in); |
236 | if (i <= 0) | 239 | if (i <= 0) { |
237 | { | ||
238 | BIO_copy_next_retry(b); | 240 | BIO_copy_next_retry(b); |
239 | #if 0 | 241 | #if 0 |
240 | BIO_write(b->next_bio, ">*>", 3); | 242 | BIO_write(b->next_bio, ">*>", 3); |
241 | #endif | 243 | #endif |
242 | if (i < 0) return((num > 0)?num:i); | 244 | if (i < 0) |
243 | if (i == 0) return(num); | 245 | return ((num > 0) ? num : i); |
244 | } | 246 | if (i == 0) |
247 | return (num); | ||
248 | } | ||
245 | #if 0 | 249 | #if 0 |
246 | BIO_write(b->next_bio, ">*>", 3); | 250 | BIO_write(b->next_bio, ">*>", 3); |
247 | #endif | 251 | #endif |
248 | num+=i; | 252 | num += i; |
249 | in+=i; | 253 | in += i; |
250 | inl-=i; | 254 | inl -= i; |
251 | } | ||
252 | } | 255 | } |
253 | while(foundnl && inl > 0); | 256 | } while (foundnl && inl > 0); |
254 | /* We've written as much as we can. The rest of the input buffer, if | 257 | /* We've written as much as we can. The rest of the input buffer, if |
255 | any, is text that doesn't and with a NL and therefore needs to be | 258 | any, is text that doesn't and with a NL and therefore needs to be |
256 | saved for the next trip. */ | 259 | saved for the next trip. */ |
257 | if (inl > 0) | 260 | if (inl > 0) { |
258 | { | ||
259 | memcpy(&(ctx->obuf[ctx->obuf_len]), in, inl); | 261 | memcpy(&(ctx->obuf[ctx->obuf_len]), in, inl); |
260 | ctx->obuf_len += inl; | 262 | ctx->obuf_len += inl; |
261 | num += inl; | 263 | num += inl; |
262 | } | ||
263 | return num; | ||
264 | } | 264 | } |
265 | return num; | ||
266 | } | ||
265 | 267 | ||
266 | static long linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr) | 268 | static long |
267 | { | 269 | linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr) |
270 | { | ||
268 | BIO *dbio; | 271 | BIO *dbio; |
269 | BIO_LINEBUFFER_CTX *ctx; | 272 | BIO_LINEBUFFER_CTX *ctx; |
270 | long ret=1; | 273 | long ret = 1; |
271 | char *p; | 274 | char *p; |
272 | int r; | 275 | int r; |
273 | int obs; | 276 | int obs; |
274 | 277 | ||
275 | ctx=(BIO_LINEBUFFER_CTX *)b->ptr; | 278 | ctx = (BIO_LINEBUFFER_CTX *)b->ptr; |
276 | 279 | ||
277 | switch (cmd) | 280 | switch (cmd) { |
278 | { | ||
279 | case BIO_CTRL_RESET: | 281 | case BIO_CTRL_RESET: |
280 | ctx->obuf_len=0; | 282 | ctx->obuf_len = 0; |
281 | if (b->next_bio == NULL) return(0); | 283 | if (b->next_bio == NULL) |
282 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 284 | return (0); |
285 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
283 | break; | 286 | break; |
284 | case BIO_CTRL_INFO: | 287 | case BIO_CTRL_INFO: |
285 | ret=(long)ctx->obuf_len; | 288 | ret = (long)ctx->obuf_len; |
286 | break; | 289 | break; |
287 | case BIO_CTRL_WPENDING: | 290 | case BIO_CTRL_WPENDING: |
288 | ret=(long)ctx->obuf_len; | 291 | ret = (long)ctx->obuf_len; |
289 | if (ret == 0) | 292 | if (ret == 0) { |
290 | { | 293 | if (b->next_bio == NULL) |
291 | if (b->next_bio == NULL) return(0); | 294 | return (0); |
292 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 295 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
293 | } | 296 | } |
294 | break; | 297 | break; |
295 | case BIO_C_SET_BUFF_SIZE: | 298 | case BIO_C_SET_BUFF_SIZE: |
296 | obs=(int)num; | 299 | obs = (int)num; |
297 | p=ctx->obuf; | 300 | p = ctx->obuf; |
298 | if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size)) | 301 | if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size)) { |
299 | { | 302 | p = (char *)OPENSSL_malloc((int)num); |
300 | p=(char *)OPENSSL_malloc((int)num); | ||
301 | if (p == NULL) | 303 | if (p == NULL) |
302 | goto malloc_error; | 304 | goto malloc_error; |
303 | } | 305 | } |
304 | if (ctx->obuf != p) | 306 | if (ctx->obuf != p) { |
305 | { | 307 | if (ctx->obuf_len > obs) { |
306 | if (ctx->obuf_len > obs) | ||
307 | { | ||
308 | ctx->obuf_len = obs; | 308 | ctx->obuf_len = obs; |
309 | } | 309 | } |
310 | memcpy(p, ctx->obuf, ctx->obuf_len); | 310 | memcpy(p, ctx->obuf, ctx->obuf_len); |
311 | OPENSSL_free(ctx->obuf); | 311 | OPENSSL_free(ctx->obuf); |
312 | ctx->obuf=p; | 312 | ctx->obuf = p; |
313 | ctx->obuf_size=obs; | 313 | ctx->obuf_size = obs; |
314 | } | 314 | } |
315 | break; | 315 | break; |
316 | case BIO_C_DO_STATE_MACHINE: | 316 | case BIO_C_DO_STATE_MACHINE: |
317 | if (b->next_bio == NULL) return(0); | 317 | if (b->next_bio == NULL) |
318 | return (0); | ||
318 | BIO_clear_retry_flags(b); | 319 | BIO_clear_retry_flags(b); |
319 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 320 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
320 | BIO_copy_next_retry(b); | 321 | BIO_copy_next_retry(b); |
321 | break; | 322 | break; |
322 | 323 | ||
323 | case BIO_CTRL_FLUSH: | 324 | case BIO_CTRL_FLUSH: |
324 | if (b->next_bio == NULL) return(0); | 325 | if (b->next_bio == NULL) |
325 | if (ctx->obuf_len <= 0) | 326 | return (0); |
326 | { | 327 | if (ctx->obuf_len <= 0) { |
327 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 328 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
328 | break; | 329 | break; |
329 | } | 330 | } |
330 | 331 | ||
331 | for (;;) | 332 | for (;;) { |
332 | { | ||
333 | BIO_clear_retry_flags(b); | 333 | BIO_clear_retry_flags(b); |
334 | if (ctx->obuf_len > 0) | 334 | if (ctx->obuf_len > 0) { |
335 | { | 335 | r = BIO_write(b->next_bio, |
336 | r=BIO_write(b->next_bio, | 336 | ctx->obuf, ctx->obuf_len); |
337 | ctx->obuf, ctx->obuf_len); | ||
338 | #if 0 | 337 | #if 0 |
339 | fprintf(stderr,"FLUSH %3d -> %3d\n",ctx->obuf_len,r); | 338 | fprintf(stderr, "FLUSH %3d -> %3d\n", ctx->obuf_len, r); |
340 | #endif | 339 | #endif |
341 | BIO_copy_next_retry(b); | 340 | BIO_copy_next_retry(b); |
342 | if (r <= 0) return((long)r); | 341 | if (r <= 0) |
342 | return ((long)r); | ||
343 | if (r < ctx->obuf_len) | 343 | if (r < ctx->obuf_len) |
344 | memmove(ctx->obuf, ctx->obuf + r, | 344 | memmove(ctx->obuf, ctx->obuf + r, |
345 | ctx->obuf_len - r); | 345 | ctx->obuf_len - r); |
346 | ctx->obuf_len-=r; | 346 | ctx->obuf_len -= r; |
347 | } | 347 | } else { |
348 | else | 348 | ctx->obuf_len = 0; |
349 | { | 349 | ret = 1; |
350 | ctx->obuf_len=0; | ||
351 | ret=1; | ||
352 | break; | 350 | break; |
353 | } | ||
354 | } | 351 | } |
355 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 352 | } |
353 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
356 | break; | 354 | break; |
357 | case BIO_CTRL_DUP: | 355 | case BIO_CTRL_DUP: |
358 | dbio=(BIO *)ptr; | 356 | dbio = (BIO *)ptr; |
359 | if ( !BIO_set_write_buffer_size(dbio,ctx->obuf_size)) | 357 | if (!BIO_set_write_buffer_size(dbio, ctx->obuf_size)) |
360 | ret=0; | 358 | ret = 0; |
361 | break; | 359 | break; |
362 | default: | 360 | default: |
363 | if (b->next_bio == NULL) return(0); | 361 | if (b->next_bio == NULL) |
364 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 362 | return (0); |
363 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
365 | break; | 364 | break; |
366 | } | ||
367 | return(ret); | ||
368 | malloc_error: | ||
369 | BIOerr(BIO_F_LINEBUFFER_CTRL,ERR_R_MALLOC_FAILURE); | ||
370 | return(0); | ||
371 | } | 365 | } |
366 | return (ret); | ||
367 | malloc_error: | ||
368 | BIOerr(BIO_F_LINEBUFFER_CTRL, ERR_R_MALLOC_FAILURE); | ||
369 | return (0); | ||
370 | } | ||
372 | 371 | ||
373 | static long linebuffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | 372 | static long |
374 | { | 373 | linebuffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) |
375 | long ret=1; | 374 | { |
375 | long ret = 1; | ||
376 | 376 | ||
377 | if (b->next_bio == NULL) return(0); | 377 | if (b->next_bio == NULL) |
378 | switch (cmd) | 378 | return (0); |
379 | { | 379 | switch (cmd) { |
380 | default: | 380 | default: |
381 | ret=BIO_callback_ctrl(b->next_bio,cmd,fp); | 381 | ret = BIO_callback_ctrl(b->next_bio, cmd, fp); |
382 | break; | 382 | break; |
383 | } | ||
384 | return(ret); | ||
385 | } | 383 | } |
384 | return (ret); | ||
385 | } | ||
386 | 386 | ||
387 | static int linebuffer_gets(BIO *b, char *buf, int size) | 387 | static int |
388 | { | 388 | linebuffer_gets(BIO *b, char *buf, int size) |
389 | if (b->next_bio == NULL) return(0); | 389 | { |
390 | return(BIO_gets(b->next_bio,buf,size)); | 390 | if (b->next_bio == NULL) |
391 | } | 391 | return (0); |
392 | 392 | return (BIO_gets(b->next_bio, buf, size)); | |
393 | static int linebuffer_puts(BIO *b, const char *str) | 393 | } |
394 | { | ||
395 | return(linebuffer_write(b,str,strlen(str))); | ||
396 | } | ||
397 | 394 | ||
395 | static int | ||
396 | linebuffer_puts(BIO *b, const char *str) | ||
397 | { | ||
398 | return (linebuffer_write(b, str, strlen(str))); | ||
399 | } | ||
diff --git a/src/lib/libcrypto/bio/bf_nbio.c b/src/lib/libcrypto/bio/bf_nbio.c index 028616c064..76f8f31950 100644 --- a/src/lib/libcrypto/bio/bf_nbio.c +++ b/src/lib/libcrypto/bio/bf_nbio.c | |||
@@ -65,23 +65,22 @@ | |||
65 | /* BIO_put and BIO_get both add to the digest, | 65 | /* BIO_put and BIO_get both add to the digest, |
66 | * BIO_gets returns the digest */ | 66 | * BIO_gets returns the digest */ |
67 | 67 | ||
68 | static int nbiof_write(BIO *h,const char *buf,int num); | 68 | static int nbiof_write(BIO *h, const char *buf, int num); |
69 | static int nbiof_read(BIO *h,char *buf,int size); | 69 | static int nbiof_read(BIO *h, char *buf, int size); |
70 | static int nbiof_puts(BIO *h,const char *str); | 70 | static int nbiof_puts(BIO *h, const char *str); |
71 | static int nbiof_gets(BIO *h,char *str,int size); | 71 | static int nbiof_gets(BIO *h, char *str, int size); |
72 | static long nbiof_ctrl(BIO *h,int cmd,long arg1,void *arg2); | 72 | static long nbiof_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
73 | static int nbiof_new(BIO *h); | 73 | static int nbiof_new(BIO *h); |
74 | static int nbiof_free(BIO *data); | 74 | static int nbiof_free(BIO *data); |
75 | static long nbiof_callback_ctrl(BIO *h,int cmd,bio_info_cb *fp); | 75 | static long nbiof_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); |
76 | typedef struct nbio_test_st | 76 | |
77 | { | 77 | typedef struct nbio_test_st { |
78 | /* only set if we sent a 'should retry' error */ | 78 | /* only set if we sent a 'should retry' error */ |
79 | int lrn; | 79 | int lrn; |
80 | int lwn; | 80 | int lwn; |
81 | } NBIO_TEST; | 81 | } NBIO_TEST; |
82 | 82 | ||
83 | static BIO_METHOD methods_nbiof= | 83 | static BIO_METHOD methods_nbiof = { |
84 | { | ||
85 | BIO_TYPE_NBIO_TEST, | 84 | BIO_TYPE_NBIO_TEST, |
86 | "non-blocking IO test filter", | 85 | "non-blocking IO test filter", |
87 | nbiof_write, | 86 | nbiof_write, |
@@ -92,162 +91,170 @@ static BIO_METHOD methods_nbiof= | |||
92 | nbiof_new, | 91 | nbiof_new, |
93 | nbiof_free, | 92 | nbiof_free, |
94 | nbiof_callback_ctrl, | 93 | nbiof_callback_ctrl, |
95 | }; | 94 | }; |
96 | 95 | ||
97 | BIO_METHOD *BIO_f_nbio_test(void) | 96 | BIO_METHOD |
98 | { | 97 | *BIO_f_nbio_test(void) |
99 | return(&methods_nbiof); | 98 | { |
100 | } | 99 | return (&methods_nbiof); |
100 | } | ||
101 | 101 | ||
102 | static int nbiof_new(BIO *bi) | 102 | static int |
103 | { | 103 | nbiof_new(BIO *bi) |
104 | { | ||
104 | NBIO_TEST *nt; | 105 | NBIO_TEST *nt; |
105 | 106 | ||
106 | if (!(nt=(NBIO_TEST *)OPENSSL_malloc(sizeof(NBIO_TEST)))) return(0); | 107 | if (!(nt = (NBIO_TEST *)OPENSSL_malloc(sizeof(NBIO_TEST)))) |
107 | nt->lrn= -1; | 108 | return (0); |
108 | nt->lwn= -1; | 109 | nt->lrn = -1; |
109 | bi->ptr=(char *)nt; | 110 | nt->lwn = -1; |
110 | bi->init=1; | 111 | bi->ptr = (char *)nt; |
111 | bi->flags=0; | 112 | bi->init = 1; |
112 | return(1); | 113 | bi->flags = 0; |
113 | } | 114 | return (1); |
115 | } | ||
114 | 116 | ||
115 | static int nbiof_free(BIO *a) | 117 | static int |
116 | { | 118 | nbiof_free(BIO *a) |
117 | if (a == NULL) return(0); | 119 | { |
120 | if (a == NULL) | ||
121 | return (0); | ||
118 | if (a->ptr != NULL) | 122 | if (a->ptr != NULL) |
119 | OPENSSL_free(a->ptr); | 123 | OPENSSL_free(a->ptr); |
120 | a->ptr=NULL; | 124 | a->ptr = NULL; |
121 | a->init=0; | 125 | a->init = 0; |
122 | a->flags=0; | 126 | a->flags = 0; |
123 | return(1); | 127 | return (1); |
124 | } | 128 | } |
125 | 129 | ||
126 | static int nbiof_read(BIO *b, char *out, int outl) | 130 | static int |
127 | { | 131 | nbiof_read(BIO *b, char *out, int outl) |
128 | int ret=0; | 132 | { |
133 | int ret = 0; | ||
129 | #if 1 | 134 | #if 1 |
130 | int num; | 135 | int num; |
131 | unsigned char n; | 136 | unsigned char n; |
132 | #endif | 137 | #endif |
133 | 138 | ||
134 | if (out == NULL) return(0); | 139 | if (out == NULL) |
135 | if (b->next_bio == NULL) return(0); | 140 | return (0); |
141 | if (b->next_bio == NULL) | ||
142 | return (0); | ||
136 | 143 | ||
137 | BIO_clear_retry_flags(b); | 144 | BIO_clear_retry_flags(b); |
138 | #if 1 | 145 | #if 1 |
139 | RAND_pseudo_bytes(&n,1); | 146 | RAND_pseudo_bytes(&n, 1); |
140 | num=(n&0x07); | 147 | num = (n & 0x07); |
141 | 148 | ||
142 | if (outl > num) outl=num; | 149 | if (outl > num) |
150 | outl = num; | ||
143 | 151 | ||
144 | if (num == 0) | 152 | if (num == 0) { |
145 | { | 153 | ret = -1; |
146 | ret= -1; | ||
147 | BIO_set_retry_read(b); | 154 | BIO_set_retry_read(b); |
148 | } | 155 | } else |
149 | else | ||
150 | #endif | 156 | #endif |
151 | { | 157 | { |
152 | ret=BIO_read(b->next_bio,out,outl); | 158 | ret = BIO_read(b->next_bio, out, outl); |
153 | if (ret < 0) | 159 | if (ret < 0) |
154 | BIO_copy_next_retry(b); | 160 | BIO_copy_next_retry(b); |
155 | } | ||
156 | return(ret); | ||
157 | } | 161 | } |
162 | return (ret); | ||
163 | } | ||
158 | 164 | ||
159 | static int nbiof_write(BIO *b, const char *in, int inl) | 165 | static int |
160 | { | 166 | nbiof_write(BIO *b, const char *in, int inl) |
167 | { | ||
161 | NBIO_TEST *nt; | 168 | NBIO_TEST *nt; |
162 | int ret=0; | 169 | int ret = 0; |
163 | int num; | 170 | int num; |
164 | unsigned char n; | 171 | unsigned char n; |
165 | 172 | ||
166 | if ((in == NULL) || (inl <= 0)) return(0); | 173 | if ((in == NULL) || (inl <= 0)) |
167 | if (b->next_bio == NULL) return(0); | 174 | return (0); |
168 | nt=(NBIO_TEST *)b->ptr; | 175 | if (b->next_bio == NULL) |
176 | return (0); | ||
177 | nt = (NBIO_TEST *)b->ptr; | ||
169 | 178 | ||
170 | BIO_clear_retry_flags(b); | 179 | BIO_clear_retry_flags(b); |
171 | 180 | ||
172 | #if 1 | 181 | #if 1 |
173 | if (nt->lwn > 0) | 182 | if (nt->lwn > 0) { |
174 | { | 183 | num = nt->lwn; |
175 | num=nt->lwn; | 184 | nt->lwn = 0; |
176 | nt->lwn=0; | 185 | } else { |
177 | } | 186 | RAND_pseudo_bytes(&n, 1); |
178 | else | 187 | num = (n&7); |
179 | { | 188 | } |
180 | RAND_pseudo_bytes(&n,1); | ||
181 | num=(n&7); | ||
182 | } | ||
183 | 189 | ||
184 | if (inl > num) inl=num; | 190 | if (inl > num) |
191 | inl = num; | ||
185 | 192 | ||
186 | if (num == 0) | 193 | if (num == 0) { |
187 | { | 194 | ret = -1; |
188 | ret= -1; | ||
189 | BIO_set_retry_write(b); | 195 | BIO_set_retry_write(b); |
190 | } | 196 | } else |
191 | else | ||
192 | #endif | 197 | #endif |
193 | { | 198 | { |
194 | ret=BIO_write(b->next_bio,in,inl); | 199 | ret = BIO_write(b->next_bio, in, inl); |
195 | if (ret < 0) | 200 | if (ret < 0) { |
196 | { | ||
197 | BIO_copy_next_retry(b); | 201 | BIO_copy_next_retry(b); |
198 | nt->lwn=inl; | 202 | nt->lwn = inl; |
199 | } | ||
200 | } | 203 | } |
201 | return(ret); | ||
202 | } | 204 | } |
205 | return (ret); | ||
206 | } | ||
203 | 207 | ||
204 | static long nbiof_ctrl(BIO *b, int cmd, long num, void *ptr) | 208 | static long |
205 | { | 209 | nbiof_ctrl(BIO *b, int cmd, long num, void *ptr) |
210 | { | ||
206 | long ret; | 211 | long ret; |
207 | 212 | ||
208 | if (b->next_bio == NULL) return(0); | 213 | if (b->next_bio == NULL) |
209 | switch (cmd) | 214 | return (0); |
210 | { | 215 | switch (cmd) { |
211 | case BIO_C_DO_STATE_MACHINE: | 216 | case BIO_C_DO_STATE_MACHINE: |
212 | BIO_clear_retry_flags(b); | 217 | BIO_clear_retry_flags(b); |
213 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 218 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
214 | BIO_copy_next_retry(b); | 219 | BIO_copy_next_retry(b); |
215 | break; | 220 | break; |
216 | case BIO_CTRL_DUP: | 221 | case BIO_CTRL_DUP: |
217 | ret=0L; | 222 | ret = 0L; |
218 | break; | 223 | break; |
219 | default: | 224 | default: |
220 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 225 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
221 | break; | 226 | break; |
222 | } | ||
223 | return(ret); | ||
224 | } | 227 | } |
228 | return (ret); | ||
229 | } | ||
225 | 230 | ||
226 | static long nbiof_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | 231 | static long |
227 | { | 232 | nbiof_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) |
228 | long ret=1; | 233 | { |
234 | long ret = 1; | ||
229 | 235 | ||
230 | if (b->next_bio == NULL) return(0); | 236 | if (b->next_bio == NULL) |
231 | switch (cmd) | 237 | return (0); |
232 | { | 238 | switch (cmd) { |
233 | default: | 239 | default: |
234 | ret=BIO_callback_ctrl(b->next_bio,cmd,fp); | 240 | ret = BIO_callback_ctrl(b->next_bio, cmd, fp); |
235 | break; | 241 | break; |
236 | } | ||
237 | return(ret); | ||
238 | } | ||
239 | |||
240 | static int nbiof_gets(BIO *bp, char *buf, int size) | ||
241 | { | ||
242 | if (bp->next_bio == NULL) return(0); | ||
243 | return(BIO_gets(bp->next_bio,buf,size)); | ||
244 | } | ||
245 | |||
246 | |||
247 | static int nbiof_puts(BIO *bp, const char *str) | ||
248 | { | ||
249 | if (bp->next_bio == NULL) return(0); | ||
250 | return(BIO_puts(bp->next_bio,str)); | ||
251 | } | 242 | } |
243 | return (ret); | ||
244 | } | ||
252 | 245 | ||
246 | static int | ||
247 | nbiof_gets(BIO *bp, char *buf, int size) | ||
248 | { | ||
249 | if (bp->next_bio == NULL) | ||
250 | return (0); | ||
251 | return (BIO_gets(bp->next_bio, buf, size)); | ||
252 | } | ||
253 | 253 | ||
254 | static int | ||
255 | nbiof_puts(BIO *bp, const char *str) | ||
256 | { | ||
257 | if (bp->next_bio == NULL) | ||
258 | return (0); | ||
259 | return (BIO_puts(bp->next_bio, str)); | ||
260 | } | ||
diff --git a/src/lib/libcrypto/bio/bf_null.c b/src/lib/libcrypto/bio/bf_null.c index c1bf39a904..354731c0c7 100644 --- a/src/lib/libcrypto/bio/bf_null.c +++ b/src/lib/libcrypto/bio/bf_null.c | |||
@@ -72,8 +72,8 @@ static long nullf_ctrl(BIO *h, int cmd, long arg1, void *arg2); | |||
72 | static int nullf_new(BIO *h); | 72 | static int nullf_new(BIO *h); |
73 | static int nullf_free(BIO *data); | 73 | static int nullf_free(BIO *data); |
74 | static long nullf_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); | 74 | static long nullf_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); |
75 | static BIO_METHOD methods_nullf= | 75 | |
76 | { | 76 | static BIO_METHOD methods_nullf = { |
77 | BIO_TYPE_NULL_FILTER, | 77 | BIO_TYPE_NULL_FILTER, |
78 | "NULL filter", | 78 | "NULL filter", |
79 | nullf_write, | 79 | nullf_write, |
@@ -84,100 +84,113 @@ static BIO_METHOD methods_nullf= | |||
84 | nullf_new, | 84 | nullf_new, |
85 | nullf_free, | 85 | nullf_free, |
86 | nullf_callback_ctrl, | 86 | nullf_callback_ctrl, |
87 | }; | 87 | }; |
88 | 88 | ||
89 | BIO_METHOD *BIO_f_null(void) | 89 | BIO_METHOD |
90 | { | 90 | *BIO_f_null(void) |
91 | return(&methods_nullf); | 91 | { |
92 | } | 92 | return (&methods_nullf); |
93 | 93 | } | |
94 | static int nullf_new(BIO *bi) | 94 | |
95 | { | 95 | static int |
96 | bi->init=1; | 96 | nullf_new(BIO *bi) |
97 | bi->ptr=NULL; | 97 | { |
98 | bi->flags=0; | 98 | bi->init = 1; |
99 | return(1); | 99 | bi->ptr = NULL; |
100 | } | 100 | bi->flags = 0; |
101 | 101 | return (1); | |
102 | static int nullf_free(BIO *a) | 102 | } |
103 | { | 103 | |
104 | if (a == NULL) return(0); | 104 | static int |
105 | nullf_free(BIO *a) | ||
106 | { | ||
107 | if (a == NULL) | ||
108 | return (0); | ||
105 | /* a->ptr=NULL; | 109 | /* a->ptr=NULL; |
106 | a->init=0; | 110 | a->init=0; |
107 | a->flags=0;*/ | 111 | a->flags=0;*/ |
108 | return(1); | 112 | return (1); |
109 | } | 113 | } |
110 | 114 | ||
111 | static int nullf_read(BIO *b, char *out, int outl) | 115 | static int |
112 | { | 116 | nullf_read(BIO *b, char *out, int outl) |
113 | int ret=0; | 117 | { |
114 | 118 | int ret = 0; | |
115 | if (out == NULL) return(0); | 119 | |
116 | if (b->next_bio == NULL) return(0); | 120 | if (out == NULL) |
117 | ret=BIO_read(b->next_bio,out,outl); | 121 | return (0); |
122 | if (b->next_bio == NULL) | ||
123 | return (0); | ||
124 | ret = BIO_read(b->next_bio, out, outl); | ||
118 | BIO_clear_retry_flags(b); | 125 | BIO_clear_retry_flags(b); |
119 | BIO_copy_next_retry(b); | 126 | BIO_copy_next_retry(b); |
120 | return(ret); | 127 | return (ret); |
121 | } | 128 | } |
122 | 129 | ||
123 | static int nullf_write(BIO *b, const char *in, int inl) | 130 | static int |
124 | { | 131 | nullf_write(BIO *b, const char *in, int inl) |
125 | int ret=0; | 132 | { |
126 | 133 | int ret = 0; | |
127 | if ((in == NULL) || (inl <= 0)) return(0); | 134 | |
128 | if (b->next_bio == NULL) return(0); | 135 | if ((in == NULL) || (inl <= 0)) |
129 | ret=BIO_write(b->next_bio,in,inl); | 136 | return (0); |
137 | if (b->next_bio == NULL) | ||
138 | return (0); | ||
139 | ret = BIO_write(b->next_bio, in, inl); | ||
130 | BIO_clear_retry_flags(b); | 140 | BIO_clear_retry_flags(b); |
131 | BIO_copy_next_retry(b); | 141 | BIO_copy_next_retry(b); |
132 | return(ret); | 142 | return (ret); |
133 | } | 143 | } |
134 | 144 | ||
135 | static long nullf_ctrl(BIO *b, int cmd, long num, void *ptr) | 145 | static long |
136 | { | 146 | nullf_ctrl(BIO *b, int cmd, long num, void *ptr) |
147 | { | ||
137 | long ret; | 148 | long ret; |
138 | 149 | ||
139 | if (b->next_bio == NULL) return(0); | 150 | if (b->next_bio == NULL) |
140 | switch(cmd) | 151 | return (0); |
141 | { | 152 | switch (cmd) { |
142 | case BIO_C_DO_STATE_MACHINE: | 153 | case BIO_C_DO_STATE_MACHINE: |
143 | BIO_clear_retry_flags(b); | 154 | BIO_clear_retry_flags(b); |
144 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 155 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
145 | BIO_copy_next_retry(b); | 156 | BIO_copy_next_retry(b); |
146 | break; | 157 | break; |
147 | case BIO_CTRL_DUP: | 158 | case BIO_CTRL_DUP: |
148 | ret=0L; | 159 | ret = 0L; |
149 | break; | 160 | break; |
150 | default: | 161 | default: |
151 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 162 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
152 | } | ||
153 | return(ret); | ||
154 | } | 163 | } |
164 | return (ret); | ||
165 | } | ||
155 | 166 | ||
156 | static long nullf_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | 167 | static long |
157 | { | 168 | nullf_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) |
158 | long ret=1; | 169 | { |
170 | long ret = 1; | ||
159 | 171 | ||
160 | if (b->next_bio == NULL) return(0); | 172 | if (b->next_bio == NULL) |
161 | switch (cmd) | 173 | return (0); |
162 | { | 174 | switch (cmd) { |
163 | default: | 175 | default: |
164 | ret=BIO_callback_ctrl(b->next_bio,cmd,fp); | 176 | ret = BIO_callback_ctrl(b->next_bio, cmd, fp); |
165 | break; | 177 | break; |
166 | } | ||
167 | return(ret); | ||
168 | } | 178 | } |
169 | 179 | return (ret); | |
170 | static int nullf_gets(BIO *bp, char *buf, int size) | 180 | } |
171 | { | 181 | |
172 | if (bp->next_bio == NULL) return(0); | 182 | static int |
173 | return(BIO_gets(bp->next_bio,buf,size)); | 183 | nullf_gets(BIO *bp, char *buf, int size) |
174 | } | 184 | { |
175 | 185 | if (bp->next_bio == NULL) | |
176 | 186 | return (0); | |
177 | static int nullf_puts(BIO *bp, const char *str) | 187 | return (BIO_gets(bp->next_bio, buf, size)); |
178 | { | 188 | } |
179 | if (bp->next_bio == NULL) return(0); | 189 | |
180 | return(BIO_puts(bp->next_bio,str)); | 190 | static int |
181 | } | 191 | nullf_puts(BIO *bp, const char *str) |
182 | 192 | { | |
183 | 193 | if (bp->next_bio == NULL) | |
194 | return (0); | ||
195 | return (BIO_puts(bp->next_bio, str)); | ||
196 | } | ||
diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h index 05699ab212..4f1d02ada5 100644 --- a/src/lib/libcrypto/bio/bio.h +++ b/src/lib/libcrypto/bio/bio.h | |||
@@ -151,7 +151,7 @@ extern "C" { | |||
151 | 151 | ||
152 | #define BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP 37 /* flag whether the last */ | 152 | #define BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP 37 /* flag whether the last */ |
153 | #define BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP 38 /* I/O operation tiemd out */ | 153 | #define BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP 38 /* I/O operation tiemd out */ |
154 | 154 | ||
155 | /* #ifdef IP_MTU_DISCOVER */ | 155 | /* #ifdef IP_MTU_DISCOVER */ |
156 | #define BIO_CTRL_DGRAM_MTU_DISCOVER 39 /* set DF bit on egress packets */ | 156 | #define BIO_CTRL_DGRAM_MTU_DISCOVER 39 /* set DF bit on egress packets */ |
157 | /* #endif */ | 157 | /* #endif */ |
@@ -282,9 +282,10 @@ void BIO_clear_flags(BIO *b, int flags); | |||
282 | #define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN)) | 282 | #define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN)) |
283 | #define BIO_cb_post(a) ((a)&BIO_CB_RETURN) | 283 | #define BIO_cb_post(a) ((a)&BIO_CB_RETURN) |
284 | 284 | ||
285 | long (*BIO_get_callback(const BIO *b)) (struct bio_st *,int,const char *,int, long,long); | 285 | long (*BIO_get_callback(const BIO *b))(struct bio_st *, int, const char *, |
286 | void BIO_set_callback(BIO *b, | 286 | int, long, long); |
287 | long (*callback)(struct bio_st *,int,const char *,int, long,long)); | 287 | void BIO_set_callback(BIO *b, |
288 | long (*callback)(struct bio_st *, int, const char *, int, long, long)); | ||
288 | char *BIO_get_callback_arg(const BIO *b); | 289 | char *BIO_get_callback_arg(const BIO *b); |
289 | void BIO_set_callback_arg(BIO *b, char *arg); | 290 | void BIO_set_callback_arg(BIO *b, char *arg); |
290 | 291 | ||
@@ -293,8 +294,7 @@ int BIO_method_type(const BIO *b); | |||
293 | 294 | ||
294 | typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long); | 295 | typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long); |
295 | 296 | ||
296 | typedef struct bio_method_st | 297 | typedef struct bio_method_st { |
297 | { | ||
298 | int type; | 298 | int type; |
299 | const char *name; | 299 | const char *name; |
300 | int (*bwrite)(BIO *, const char *, int); | 300 | int (*bwrite)(BIO *, const char *, int); |
@@ -304,14 +304,13 @@ typedef struct bio_method_st | |||
304 | long (*ctrl)(BIO *, int, long, void *); | 304 | long (*ctrl)(BIO *, int, long, void *); |
305 | int (*create)(BIO *); | 305 | int (*create)(BIO *); |
306 | int (*destroy)(BIO *); | 306 | int (*destroy)(BIO *); |
307 | long (*callback_ctrl)(BIO *, int, bio_info_cb *); | 307 | long (*callback_ctrl)(BIO *, int, bio_info_cb *); |
308 | } BIO_METHOD; | 308 | } BIO_METHOD; |
309 | 309 | ||
310 | struct bio_st | 310 | struct bio_st { |
311 | { | ||
312 | BIO_METHOD *method; | 311 | BIO_METHOD *method; |
313 | /* bio, mode, argp, argi, argl, ret */ | 312 | /* bio, mode, argp, argi, argl, ret */ |
314 | long (*callback)(struct bio_st *,int,const char *,int, long,long); | 313 | long (*callback)(struct bio_st *, int, const char *, int, long, long); |
315 | char *cb_arg; /* first argument for the callback */ | 314 | char *cb_arg; /* first argument for the callback */ |
316 | 315 | ||
317 | int init; | 316 | int init; |
@@ -327,12 +326,11 @@ struct bio_st | |||
327 | unsigned long num_write; | 326 | unsigned long num_write; |
328 | 327 | ||
329 | CRYPTO_EX_DATA ex_data; | 328 | CRYPTO_EX_DATA ex_data; |
330 | }; | 329 | }; |
331 | 330 | ||
332 | DECLARE_STACK_OF(BIO) | 331 | DECLARE_STACK_OF(BIO) |
333 | 332 | ||
334 | typedef struct bio_f_buffer_ctx_struct | 333 | typedef struct bio_f_buffer_ctx_struct { |
335 | { | ||
336 | /* Buffers are setup like this: | 334 | /* Buffers are setup like this: |
337 | * | 335 | * |
338 | * <---------------------- size -----------------------> | 336 | * <---------------------- size -----------------------> |
@@ -346,30 +344,28 @@ typedef struct bio_f_buffer_ctx_struct | |||
346 | int ibuf_size; /* how big is the input buffer */ | 344 | int ibuf_size; /* how big is the input buffer */ |
347 | int obuf_size; /* how big is the output buffer */ | 345 | int obuf_size; /* how big is the output buffer */ |
348 | 346 | ||
349 | char *ibuf; /* the char array */ | 347 | char *ibuf; /* the char array */ |
350 | int ibuf_len; /* how many bytes are in it */ | 348 | int ibuf_len; /* how many bytes are in it */ |
351 | int ibuf_off; /* write/read offset */ | 349 | int ibuf_off; /* write/read offset */ |
352 | 350 | ||
353 | char *obuf; /* the char array */ | 351 | char *obuf; /* the char array */ |
354 | int obuf_len; /* how many bytes are in it */ | 352 | int obuf_len; /* how many bytes are in it */ |
355 | int obuf_off; /* write/read offset */ | 353 | int obuf_off; /* write/read offset */ |
356 | } BIO_F_BUFFER_CTX; | 354 | } BIO_F_BUFFER_CTX; |
357 | 355 | ||
358 | /* Prefix and suffix callback in ASN1 BIO */ | 356 | /* Prefix and suffix callback in ASN1 BIO */ |
359 | typedef int asn1_ps_func(BIO *b, unsigned char **pbuf, int *plen, void *parg); | 357 | typedef int asn1_ps_func(BIO *b, unsigned char **pbuf, int *plen, void *parg); |
360 | 358 | ||
361 | #ifndef OPENSSL_NO_SCTP | 359 | #ifndef OPENSSL_NO_SCTP |
362 | /* SCTP parameter structs */ | 360 | /* SCTP parameter structs */ |
363 | struct bio_dgram_sctp_sndinfo | 361 | struct bio_dgram_sctp_sndinfo { |
364 | { | ||
365 | uint16_t snd_sid; | 362 | uint16_t snd_sid; |
366 | uint16_t snd_flags; | 363 | uint16_t snd_flags; |
367 | uint32_t snd_ppid; | 364 | uint32_t snd_ppid; |
368 | uint32_t snd_context; | 365 | uint32_t snd_context; |
369 | }; | 366 | }; |
370 | 367 | ||
371 | struct bio_dgram_sctp_rcvinfo | 368 | struct bio_dgram_sctp_rcvinfo { |
372 | { | ||
373 | uint16_t rcv_sid; | 369 | uint16_t rcv_sid; |
374 | uint16_t rcv_ssn; | 370 | uint16_t rcv_ssn; |
375 | uint16_t rcv_flags; | 371 | uint16_t rcv_flags; |
@@ -377,13 +373,12 @@ struct bio_dgram_sctp_rcvinfo | |||
377 | uint32_t rcv_tsn; | 373 | uint32_t rcv_tsn; |
378 | uint32_t rcv_cumtsn; | 374 | uint32_t rcv_cumtsn; |
379 | uint32_t rcv_context; | 375 | uint32_t rcv_context; |
380 | }; | 376 | }; |
381 | 377 | ||
382 | struct bio_dgram_sctp_prinfo | 378 | struct bio_dgram_sctp_prinfo { |
383 | { | ||
384 | uint16_t pr_policy; | 379 | uint16_t pr_policy; |
385 | uint32_t pr_value; | 380 | uint32_t pr_value; |
386 | }; | 381 | }; |
387 | #endif | 382 | #endif |
388 | 383 | ||
389 | /* connect BIO stuff */ | 384 | /* connect BIO stuff */ |
@@ -519,7 +514,7 @@ struct bio_dgram_sctp_prinfo | |||
519 | /* If you are wondering why this isn't defined, its because CONST_STRICT is | 514 | /* If you are wondering why this isn't defined, its because CONST_STRICT is |
520 | * purely a compile-time kludge to allow const to be checked. | 515 | * purely a compile-time kludge to allow const to be checked. |
521 | */ | 516 | */ |
522 | int BIO_read_filename(BIO *b,const char *name); | 517 | int BIO_read_filename(BIO *b, const char *name); |
523 | #else | 518 | #else |
524 | #define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ | 519 | #define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ |
525 | BIO_CLOSE|BIO_FP_READ,(char *)name) | 520 | BIO_CLOSE|BIO_FP_READ,(char *)name) |
@@ -611,22 +606,27 @@ int BIO_ctrl_reset_read_request(BIO *b); | |||
611 | /* These two aren't currently implemented */ | 606 | /* These two aren't currently implemented */ |
612 | /* int BIO_get_ex_num(BIO *bio); */ | 607 | /* int BIO_get_ex_num(BIO *bio); */ |
613 | /* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */ | 608 | /* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */ |
614 | int BIO_set_ex_data(BIO *bio,int idx,void *data); | 609 | int BIO_set_ex_data(BIO *bio, int idx, void *data); |
615 | void *BIO_get_ex_data(BIO *bio,int idx); | 610 | void *BIO_get_ex_data(BIO *bio, int idx); |
616 | int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | 611 | int |
617 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | 612 | BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, |
613 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | ||
618 | unsigned long BIO_number_read(BIO *bio); | 614 | unsigned long BIO_number_read(BIO *bio); |
619 | unsigned long BIO_number_written(BIO *bio); | 615 | unsigned long BIO_number_written(BIO *bio); |
620 | 616 | ||
621 | /* For BIO_f_asn1() */ | 617 | /* For BIO_f_asn1() */ |
622 | int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, | 618 | int |
623 | asn1_ps_func *prefix_free); | 619 | BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, |
624 | int BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, | 620 | asn1_ps_func *prefix_free); |
625 | asn1_ps_func **pprefix_free); | 621 | int |
626 | int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, | 622 | BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, |
627 | asn1_ps_func *suffix_free); | 623 | asn1_ps_func **pprefix_free); |
628 | int BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, | 624 | int |
629 | asn1_ps_func **psuffix_free); | 625 | BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, |
626 | asn1_ps_func *suffix_free); | ||
627 | int | ||
628 | BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, | ||
629 | asn1_ps_func **psuffix_free); | ||
630 | 630 | ||
631 | # ifndef OPENSSL_NO_FP_API | 631 | # ifndef OPENSSL_NO_FP_API |
632 | BIO_METHOD *BIO_s_file(void ); | 632 | BIO_METHOD *BIO_s_file(void ); |
@@ -635,22 +635,23 @@ BIO *BIO_new_fp(FILE *stream, int close_flag); | |||
635 | # define BIO_s_file_internal BIO_s_file | 635 | # define BIO_s_file_internal BIO_s_file |
636 | # endif | 636 | # endif |
637 | BIO * BIO_new(BIO_METHOD *type); | 637 | BIO * BIO_new(BIO_METHOD *type); |
638 | int BIO_set(BIO *a,BIO_METHOD *type); | 638 | int BIO_set(BIO *a, BIO_METHOD *type); |
639 | int BIO_free(BIO *a); | 639 | int BIO_free(BIO *a); |
640 | void BIO_vfree(BIO *a); | 640 | void BIO_vfree(BIO *a); |
641 | int BIO_read(BIO *b, void *data, int len); | 641 | int BIO_read(BIO *b, void *data, int len); |
642 | int BIO_gets(BIO *bp,char *buf, int size); | 642 | int BIO_gets(BIO *bp, char *buf, int size); |
643 | int BIO_write(BIO *b, const void *data, int len); | 643 | int BIO_write(BIO *b, const void *data, int len); |
644 | int BIO_puts(BIO *bp,const char *buf); | 644 | int BIO_puts(BIO *bp, const char *buf); |
645 | int BIO_indent(BIO *b,int indent,int max); | 645 | int BIO_indent(BIO *b, int indent, int max); |
646 | long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg); | 646 | long BIO_ctrl(BIO *bp, int cmd, long larg, void *parg); |
647 | long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long)); | 647 | long BIO_callback_ctrl(BIO *b, int cmd, |
648 | char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg); | 648 | void (*fp)(struct bio_st *, int, const char *, int, long, long)); |
649 | long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg); | 649 | char * BIO_ptr_ctrl(BIO *bp, int cmd, long larg); |
650 | BIO * BIO_push(BIO *b,BIO *append); | 650 | long BIO_int_ctrl(BIO *bp, int cmd, long larg, int iarg); |
651 | BIO * BIO_push(BIO *b, BIO *append); | ||
651 | BIO * BIO_pop(BIO *b); | 652 | BIO * BIO_pop(BIO *b); |
652 | void BIO_free_all(BIO *a); | 653 | void BIO_free_all(BIO *a); |
653 | BIO * BIO_find_type(BIO *b,int bio_type); | 654 | BIO * BIO_find_type(BIO *b, int bio_type); |
654 | BIO * BIO_next(BIO *b); | 655 | BIO * BIO_next(BIO *b); |
655 | BIO * BIO_get_retry_BIO(BIO *bio, int *reason); | 656 | BIO * BIO_get_retry_BIO(BIO *bio, int *reason); |
656 | int BIO_get_retry_reason(BIO *bio); | 657 | int BIO_get_retry_reason(BIO *bio); |
@@ -661,8 +662,8 @@ int BIO_nread(BIO *bio, char **buf, int num); | |||
661 | int BIO_nwrite0(BIO *bio, char **buf); | 662 | int BIO_nwrite0(BIO *bio, char **buf); |
662 | int BIO_nwrite(BIO *bio, char **buf, int num); | 663 | int BIO_nwrite(BIO *bio, char **buf, int num); |
663 | 664 | ||
664 | long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi, | 665 | long BIO_debug_callback(BIO *bio, int cmd, const char *argp, int argi, |
665 | long argl,long ret); | 666 | long argl, long ret); |
666 | 667 | ||
667 | BIO_METHOD *BIO_s_mem(void); | 668 | BIO_METHOD *BIO_s_mem(void); |
668 | BIO *BIO_new_mem_buf(void *buf, int len); | 669 | BIO *BIO_new_mem_buf(void *buf, int len); |
@@ -696,12 +697,14 @@ int BIO_dgram_non_fatal_error(int error); | |||
696 | 697 | ||
697 | int BIO_fd_should_retry(int i); | 698 | int BIO_fd_should_retry(int i); |
698 | int BIO_fd_non_fatal_error(int error); | 699 | int BIO_fd_non_fatal_error(int error); |
699 | int BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u), | 700 | int |
700 | void *u, const char *s, int len); | 701 | BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u), |
701 | int BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), | 702 | void *u, const char *s, int len); |
702 | void *u, const char *s, int len, int indent); | 703 | int |
703 | int BIO_dump(BIO *b,const char *bytes,int len); | 704 | BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), |
704 | int BIO_dump_indent(BIO *b,const char *bytes,int len,int indent); | 705 | void *u, const char *s, int len, int indent); |
706 | int BIO_dump(BIO *b, const char *bytes, int len); | ||
707 | int BIO_dump_indent(BIO *b, const char *bytes, int len, int indent); | ||
705 | #ifndef OPENSSL_NO_FP_API | 708 | #ifndef OPENSSL_NO_FP_API |
706 | int BIO_dump_fp(FILE *fp, const char *s, int len); | 709 | int BIO_dump_fp(FILE *fp, const char *s, int len); |
707 | int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent); | 710 | int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent); |
@@ -717,23 +720,24 @@ struct hostent *BIO_gethostbyname(const char *name); | |||
717 | */ | 720 | */ |
718 | int BIO_sock_error(int sock); | 721 | int BIO_sock_error(int sock); |
719 | int BIO_socket_ioctl(int fd, long type, void *arg); | 722 | int BIO_socket_ioctl(int fd, long type, void *arg); |
720 | int BIO_socket_nbio(int fd,int mode); | 723 | int BIO_socket_nbio(int fd, int mode); |
721 | int BIO_get_port(const char *str, unsigned short *port_ptr); | 724 | int BIO_get_port(const char *str, unsigned short *port_ptr); |
722 | int BIO_get_host_ip(const char *str, unsigned char *ip); | 725 | int BIO_get_host_ip(const char *str, unsigned char *ip); |
723 | int BIO_get_accept_socket(char *host_port,int mode); | 726 | int BIO_get_accept_socket(char *host_port, int mode); |
724 | int BIO_accept(int sock,char **ip_port); | 727 | int BIO_accept(int sock, char **ip_port); |
725 | int BIO_sock_init(void ); | 728 | int BIO_sock_init(void ); |
726 | void BIO_sock_cleanup(void); | 729 | void BIO_sock_cleanup(void); |
727 | int BIO_set_tcp_ndelay(int sock,int turn_on); | 730 | int BIO_set_tcp_ndelay(int sock, int turn_on); |
728 | 731 | ||
729 | BIO *BIO_new_socket(int sock, int close_flag); | 732 | BIO *BIO_new_socket(int sock, int close_flag); |
730 | BIO *BIO_new_dgram(int fd, int close_flag); | 733 | BIO *BIO_new_dgram(int fd, int close_flag); |
731 | #ifndef OPENSSL_NO_SCTP | 734 | #ifndef OPENSSL_NO_SCTP |
732 | BIO *BIO_new_dgram_sctp(int fd, int close_flag); | 735 | BIO *BIO_new_dgram_sctp(int fd, int close_flag); |
733 | int BIO_dgram_is_sctp(BIO *bio); | 736 | int BIO_dgram_is_sctp(BIO *bio); |
734 | int BIO_dgram_sctp_notification_cb(BIO *b, | 737 | int |
735 | void (*handle_notifications)(BIO *bio, void *context, void *buf), | 738 | BIO_dgram_sctp_notification_cb(BIO *b, |
736 | void *context); | 739 | void (*handle_notifications)(BIO *bio, void *context, void *buf), |
740 | void *context); | ||
737 | int BIO_dgram_sctp_wait_for_dry(BIO *b); | 741 | int BIO_dgram_sctp_wait_for_dry(BIO *b); |
738 | int BIO_dgram_sctp_msg_waiting(BIO *b); | 742 | int BIO_dgram_sctp_msg_waiting(BIO *b); |
739 | #endif | 743 | #endif |
@@ -741,8 +745,9 @@ BIO *BIO_new_fd(int fd, int close_flag); | |||
741 | BIO *BIO_new_connect(char *host_port); | 745 | BIO *BIO_new_connect(char *host_port); |
742 | BIO *BIO_new_accept(char *host_port); | 746 | BIO *BIO_new_accept(char *host_port); |
743 | 747 | ||
744 | int BIO_new_bio_pair(BIO **bio1, size_t writebuf1, | 748 | int |
745 | BIO **bio2, size_t writebuf2); | 749 | BIO_new_bio_pair(BIO **bio1, size_t writebuf1, |
750 | BIO **bio2, size_t writebuf2); | ||
746 | /* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints. | 751 | /* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints. |
747 | * Otherwise returns 0 and sets *bio1 and *bio2 to NULL. | 752 | * Otherwise returns 0 and sets *bio1 and *bio2 to NULL. |
748 | * Size 0 uses default value. | 753 | * Size 0 uses default value. |
@@ -757,14 +762,18 @@ void BIO_copy_next_retry(BIO *b); | |||
757 | #else | 762 | #else |
758 | # define __bio_h__attr__(x) | 763 | # define __bio_h__attr__(x) |
759 | #endif | 764 | #endif |
760 | int BIO_printf(BIO *bio, const char *format, ...) | 765 | int |
761 | __bio_h__attr__((__format__(__printf__,2,3))); | 766 | BIO_printf(BIO *bio, const char *format, ...) |
762 | int BIO_vprintf(BIO *bio, const char *format, va_list args) | 767 | __bio_h__attr__((__format__(__printf__, 2, 3))); |
763 | __bio_h__attr__((__format__(__printf__,2,0))); | 768 | int |
764 | int BIO_snprintf(char *buf, size_t n, const char *format, ...) | 769 | BIO_vprintf(BIO *bio, const char *format, va_list args) |
765 | __bio_h__attr__((__format__(__printf__,3,4))); | 770 | __bio_h__attr__((__format__(__printf__, 2, 0))); |
766 | int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) | 771 | int |
767 | __bio_h__attr__((__format__(__printf__,3,0))); | 772 | BIO_snprintf(char *buf, size_t n, const char *format, ...) |
773 | __bio_h__attr__((__format__(__printf__, 3, 4))); | ||
774 | int | ||
775 | BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) | ||
776 | __bio_h__attr__((__format__(__printf__, 3, 0))); | ||
768 | #undef __bio_h__attr__ | 777 | #undef __bio_h__attr__ |
769 | 778 | ||
770 | /* BEGIN ERROR CODES */ | 779 | /* BEGIN ERROR CODES */ |
diff --git a/src/lib/libcrypto/bio/bio_cb.c b/src/lib/libcrypto/bio/bio_cb.c index 78c8974ab4..3e110f3751 100644 --- a/src/lib/libcrypto/bio/bio_cb.c +++ b/src/lib/libcrypto/bio/bio_cb.c | |||
@@ -63,81 +63,85 @@ | |||
63 | #include <openssl/bio.h> | 63 | #include <openssl/bio.h> |
64 | #include <openssl/err.h> | 64 | #include <openssl/err.h> |
65 | 65 | ||
66 | long BIO_debug_callback(BIO *bio, int cmd, const char *argp, | 66 | long |
67 | int argi, long argl, long ret) | 67 | BIO_debug_callback(BIO *bio, int cmd, const char *argp, int argi, long argl, |
68 | { | 68 | long ret) |
69 | { | ||
69 | BIO *b; | 70 | BIO *b; |
70 | char buf[256]; | 71 | char buf[256]; |
71 | char *p; | 72 | char *p; |
72 | long r=1; | 73 | long r = 1; |
73 | size_t p_maxlen; | 74 | size_t p_maxlen; |
74 | 75 | ||
75 | if (BIO_CB_RETURN & cmd) | 76 | if (BIO_CB_RETURN & cmd) |
76 | r=ret; | 77 | r = ret; |
77 | 78 | ||
78 | (void) snprintf(buf,sizeof buf,"BIO[%08lX]:",(unsigned long)bio); | 79 | (void) snprintf(buf, sizeof buf, "BIO[%08lX]:", (unsigned long)bio); |
79 | p= &(buf[14]); | 80 | p = &(buf[14]); |
80 | p_maxlen = sizeof buf - 14; | 81 | p_maxlen = sizeof buf - 14; |
81 | switch (cmd) | 82 | switch (cmd) { |
82 | { | ||
83 | case BIO_CB_FREE: | 83 | case BIO_CB_FREE: |
84 | (void) snprintf(p,p_maxlen,"Free - %s\n",bio->method->name); | 84 | (void) snprintf(p, p_maxlen, "Free - %s\n", bio->method->name); |
85 | break; | 85 | break; |
86 | case BIO_CB_READ: | 86 | case BIO_CB_READ: |
87 | if (bio->method->type & BIO_TYPE_DESCRIPTOR) | 87 | if (bio->method->type & BIO_TYPE_DESCRIPTOR) |
88 | (void) snprintf(p,p_maxlen,"read(%d,%lu) - %s fd=%d\n", | 88 | (void) snprintf(p, p_maxlen, |
89 | bio->num,(unsigned long)argi, | 89 | "read(%d,%lu) - %s fd=%d\n", |
90 | bio->method->name,bio->num); | 90 | bio->num,(unsigned long)argi, |
91 | bio->method->name, bio->num); | ||
91 | else | 92 | else |
92 | (void) snprintf(p,p_maxlen,"read(%d,%lu) - %s\n", | 93 | (void) snprintf(p, p_maxlen, "read(%d,%lu) - %s\n", |
93 | bio->num,(unsigned long)argi, | 94 | bio->num, (unsigned long)argi, bio->method->name); |
94 | bio->method->name); | ||
95 | break; | 95 | break; |
96 | case BIO_CB_WRITE: | 96 | case BIO_CB_WRITE: |
97 | if (bio->method->type & BIO_TYPE_DESCRIPTOR) | 97 | if (bio->method->type & BIO_TYPE_DESCRIPTOR) |
98 | (void) snprintf(p,p_maxlen,"write(%d,%lu) - %s fd=%d\n", | 98 | (void) snprintf(p, p_maxlen, |
99 | bio->num,(unsigned long)argi, | 99 | "write(%d,%lu) - %s fd=%d\n", |
100 | bio->method->name,bio->num); | 100 | bio->num, (unsigned long)argi, |
101 | bio->method->name, bio->num); | ||
101 | else | 102 | else |
102 | (void) snprintf(p,p_maxlen,"write(%d,%lu) - %s\n", | 103 | (void) snprintf(p, p_maxlen, "write(%d,%lu) - %s\n", |
103 | bio->num,(unsigned long)argi, | 104 | bio->num, (unsigned long)argi, bio->method->name); |
104 | bio->method->name); | ||
105 | break; | 105 | break; |
106 | case BIO_CB_PUTS: | 106 | case BIO_CB_PUTS: |
107 | (void) snprintf(p,p_maxlen,"puts() - %s\n",bio->method->name); | 107 | (void) snprintf(p, p_maxlen, |
108 | "puts() - %s\n", bio->method->name); | ||
108 | break; | 109 | break; |
109 | case BIO_CB_GETS: | 110 | case BIO_CB_GETS: |
110 | (void) snprintf(p,p_maxlen,"gets(%lu) - %s\n",(unsigned long)argi,bio->method->name); | 111 | (void) snprintf(p, p_maxlen, "gets(%lu) - %s\n", |
112 | (unsigned long)argi, bio->method->name); | ||
111 | break; | 113 | break; |
112 | case BIO_CB_CTRL: | 114 | case BIO_CB_CTRL: |
113 | (void) snprintf(p,p_maxlen,"ctrl(%lu) - %s\n",(unsigned long)argi,bio->method->name); | 115 | (void) snprintf(p, p_maxlen, "ctrl(%lu) - %s\n", |
116 | (unsigned long)argi, bio->method->name); | ||
114 | break; | 117 | break; |
115 | case BIO_CB_RETURN|BIO_CB_READ: | 118 | case BIO_CB_RETURN|BIO_CB_READ: |
116 | (void) snprintf(p,p_maxlen,"read return %ld\n",ret); | 119 | (void) snprintf(p, p_maxlen, "read return %ld\n", ret); |
117 | break; | 120 | break; |
118 | case BIO_CB_RETURN|BIO_CB_WRITE: | 121 | case BIO_CB_RETURN|BIO_CB_WRITE: |
119 | (void) snprintf(p,p_maxlen,"write return %ld\n",ret); | 122 | (void) snprintf(p, p_maxlen, "write return %ld\n", ret); |
120 | break; | 123 | break; |
121 | case BIO_CB_RETURN|BIO_CB_GETS: | 124 | case BIO_CB_RETURN|BIO_CB_GETS: |
122 | (void) snprintf(p,p_maxlen,"gets return %ld\n",ret); | 125 | (void) snprintf(p, p_maxlen, "gets return %ld\n", ret); |
123 | break; | 126 | break; |
124 | case BIO_CB_RETURN|BIO_CB_PUTS: | 127 | case BIO_CB_RETURN|BIO_CB_PUTS: |
125 | (void) snprintf(p,p_maxlen,"puts return %ld\n",ret); | 128 | (void) snprintf(p, p_maxlen, "puts return %ld\n", ret); |
126 | break; | 129 | break; |
127 | case BIO_CB_RETURN|BIO_CB_CTRL: | 130 | case BIO_CB_RETURN|BIO_CB_CTRL: |
128 | (void) snprintf(p,p_maxlen,"ctrl return %ld\n",ret); | 131 | (void) snprintf(p, p_maxlen, "ctrl return %ld\n", ret); |
129 | break; | 132 | break; |
130 | default: | 133 | default: |
131 | (void) snprintf(p,p_maxlen,"bio callback - unknown type (%d)\n",cmd); | 134 | (void) snprintf(p, p_maxlen, |
135 | "bio callback - unknown type (%d)\n", cmd); | ||
132 | break; | 136 | break; |
133 | } | 137 | } |
134 | 138 | ||
135 | b=(BIO *)bio->cb_arg; | 139 | b = (BIO *)bio->cb_arg; |
136 | if (b != NULL) | 140 | if (b != NULL) |
137 | BIO_write(b,buf,strlen(buf)); | 141 | BIO_write(b, buf, strlen(buf)); |
138 | #if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16) | 142 | #if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16) |
139 | else | 143 | else |
140 | fputs(buf,stderr); | 144 | fputs(buf, stderr); |
141 | #endif | 145 | #endif |
142 | return(r); | 146 | return (r); |
143 | } | 147 | } |
diff --git a/src/lib/libcrypto/bio/bio_err.c b/src/lib/libcrypto/bio/bio_err.c index 0dbfbd80d3..86e9a3082b 100644 --- a/src/lib/libcrypto/bio/bio_err.c +++ b/src/lib/libcrypto/bio/bio_err.c | |||
@@ -68,88 +68,85 @@ | |||
68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_BIO,func,0) | 68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_BIO,func,0) |
69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_BIO,0,reason) | 69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_BIO,0,reason) |
70 | 70 | ||
71 | static ERR_STRING_DATA BIO_str_functs[]= | 71 | static ERR_STRING_DATA BIO_str_functs[]= { |
72 | { | 72 | {ERR_FUNC(BIO_F_ACPT_STATE), "ACPT_STATE"}, |
73 | {ERR_FUNC(BIO_F_ACPT_STATE), "ACPT_STATE"}, | 73 | {ERR_FUNC(BIO_F_BIO_ACCEPT), "BIO_accept"}, |
74 | {ERR_FUNC(BIO_F_BIO_ACCEPT), "BIO_accept"}, | 74 | {ERR_FUNC(BIO_F_BIO_BER_GET_HEADER), "BIO_BER_GET_HEADER"}, |
75 | {ERR_FUNC(BIO_F_BIO_BER_GET_HEADER), "BIO_BER_GET_HEADER"}, | 75 | {ERR_FUNC(BIO_F_BIO_CALLBACK_CTRL), "BIO_callback_ctrl"}, |
76 | {ERR_FUNC(BIO_F_BIO_CALLBACK_CTRL), "BIO_callback_ctrl"}, | 76 | {ERR_FUNC(BIO_F_BIO_CTRL), "BIO_ctrl"}, |
77 | {ERR_FUNC(BIO_F_BIO_CTRL), "BIO_ctrl"}, | 77 | {ERR_FUNC(BIO_F_BIO_GETHOSTBYNAME), "BIO_gethostbyname"}, |
78 | {ERR_FUNC(BIO_F_BIO_GETHOSTBYNAME), "BIO_gethostbyname"}, | 78 | {ERR_FUNC(BIO_F_BIO_GETS), "BIO_gets"}, |
79 | {ERR_FUNC(BIO_F_BIO_GETS), "BIO_gets"}, | 79 | {ERR_FUNC(BIO_F_BIO_GET_ACCEPT_SOCKET), "BIO_get_accept_socket"}, |
80 | {ERR_FUNC(BIO_F_BIO_GET_ACCEPT_SOCKET), "BIO_get_accept_socket"}, | 80 | {ERR_FUNC(BIO_F_BIO_GET_HOST_IP), "BIO_get_host_ip"}, |
81 | {ERR_FUNC(BIO_F_BIO_GET_HOST_IP), "BIO_get_host_ip"}, | 81 | {ERR_FUNC(BIO_F_BIO_GET_PORT), "BIO_get_port"}, |
82 | {ERR_FUNC(BIO_F_BIO_GET_PORT), "BIO_get_port"}, | 82 | {ERR_FUNC(BIO_F_BIO_MAKE_PAIR), "BIO_MAKE_PAIR"}, |
83 | {ERR_FUNC(BIO_F_BIO_MAKE_PAIR), "BIO_MAKE_PAIR"}, | 83 | {ERR_FUNC(BIO_F_BIO_NEW), "BIO_new"}, |
84 | {ERR_FUNC(BIO_F_BIO_NEW), "BIO_new"}, | 84 | {ERR_FUNC(BIO_F_BIO_NEW_FILE), "BIO_new_file"}, |
85 | {ERR_FUNC(BIO_F_BIO_NEW_FILE), "BIO_new_file"}, | 85 | {ERR_FUNC(BIO_F_BIO_NEW_MEM_BUF), "BIO_new_mem_buf"}, |
86 | {ERR_FUNC(BIO_F_BIO_NEW_MEM_BUF), "BIO_new_mem_buf"}, | 86 | {ERR_FUNC(BIO_F_BIO_NREAD), "BIO_nread"}, |
87 | {ERR_FUNC(BIO_F_BIO_NREAD), "BIO_nread"}, | 87 | {ERR_FUNC(BIO_F_BIO_NREAD0), "BIO_nread0"}, |
88 | {ERR_FUNC(BIO_F_BIO_NREAD0), "BIO_nread0"}, | 88 | {ERR_FUNC(BIO_F_BIO_NWRITE), "BIO_nwrite"}, |
89 | {ERR_FUNC(BIO_F_BIO_NWRITE), "BIO_nwrite"}, | 89 | {ERR_FUNC(BIO_F_BIO_NWRITE0), "BIO_nwrite0"}, |
90 | {ERR_FUNC(BIO_F_BIO_NWRITE0), "BIO_nwrite0"}, | 90 | {ERR_FUNC(BIO_F_BIO_PUTS), "BIO_puts"}, |
91 | {ERR_FUNC(BIO_F_BIO_PUTS), "BIO_puts"}, | 91 | {ERR_FUNC(BIO_F_BIO_READ), "BIO_read"}, |
92 | {ERR_FUNC(BIO_F_BIO_READ), "BIO_read"}, | 92 | {ERR_FUNC(BIO_F_BIO_SOCK_INIT), "BIO_sock_init"}, |
93 | {ERR_FUNC(BIO_F_BIO_SOCK_INIT), "BIO_sock_init"}, | 93 | {ERR_FUNC(BIO_F_BIO_WRITE), "BIO_write"}, |
94 | {ERR_FUNC(BIO_F_BIO_WRITE), "BIO_write"}, | 94 | {ERR_FUNC(BIO_F_BUFFER_CTRL), "BUFFER_CTRL"}, |
95 | {ERR_FUNC(BIO_F_BUFFER_CTRL), "BUFFER_CTRL"}, | 95 | {ERR_FUNC(BIO_F_CONN_CTRL), "CONN_CTRL"}, |
96 | {ERR_FUNC(BIO_F_CONN_CTRL), "CONN_CTRL"}, | 96 | {ERR_FUNC(BIO_F_CONN_STATE), "CONN_STATE"}, |
97 | {ERR_FUNC(BIO_F_CONN_STATE), "CONN_STATE"}, | 97 | {ERR_FUNC(BIO_F_DGRAM_SCTP_READ), "DGRAM_SCTP_READ"}, |
98 | {ERR_FUNC(BIO_F_DGRAM_SCTP_READ), "DGRAM_SCTP_READ"}, | 98 | {ERR_FUNC(BIO_F_FILE_CTRL), "FILE_CTRL"}, |
99 | {ERR_FUNC(BIO_F_FILE_CTRL), "FILE_CTRL"}, | 99 | {ERR_FUNC(BIO_F_FILE_READ), "FILE_READ"}, |
100 | {ERR_FUNC(BIO_F_FILE_READ), "FILE_READ"}, | 100 | {ERR_FUNC(BIO_F_LINEBUFFER_CTRL), "LINEBUFFER_CTRL"}, |
101 | {ERR_FUNC(BIO_F_LINEBUFFER_CTRL), "LINEBUFFER_CTRL"}, | 101 | {ERR_FUNC(BIO_F_MEM_READ), "MEM_READ"}, |
102 | {ERR_FUNC(BIO_F_MEM_READ), "MEM_READ"}, | 102 | {ERR_FUNC(BIO_F_MEM_WRITE), "MEM_WRITE"}, |
103 | {ERR_FUNC(BIO_F_MEM_WRITE), "MEM_WRITE"}, | 103 | {ERR_FUNC(BIO_F_SSL_NEW), "SSL_new"}, |
104 | {ERR_FUNC(BIO_F_SSL_NEW), "SSL_new"}, | 104 | {ERR_FUNC(BIO_F_WSASTARTUP), "WSASTARTUP"}, |
105 | {ERR_FUNC(BIO_F_WSASTARTUP), "WSASTARTUP"}, | 105 | {0, NULL} |
106 | {0,NULL} | 106 | }; |
107 | }; | ||
108 | 107 | ||
109 | static ERR_STRING_DATA BIO_str_reasons[]= | 108 | static ERR_STRING_DATA BIO_str_reasons[]= { |
110 | { | 109 | {ERR_REASON(BIO_R_ACCEPT_ERROR) , "accept error"}, |
111 | {ERR_REASON(BIO_R_ACCEPT_ERROR) ,"accept error"}, | 110 | {ERR_REASON(BIO_R_BAD_FOPEN_MODE) , "bad fopen mode"}, |
112 | {ERR_REASON(BIO_R_BAD_FOPEN_MODE) ,"bad fopen mode"}, | 111 | {ERR_REASON(BIO_R_BAD_HOSTNAME_LOOKUP) , "bad hostname lookup"}, |
113 | {ERR_REASON(BIO_R_BAD_HOSTNAME_LOOKUP) ,"bad hostname lookup"}, | 112 | {ERR_REASON(BIO_R_BROKEN_PIPE) , "broken pipe"}, |
114 | {ERR_REASON(BIO_R_BROKEN_PIPE) ,"broken pipe"}, | 113 | {ERR_REASON(BIO_R_CONNECT_ERROR) , "connect error"}, |
115 | {ERR_REASON(BIO_R_CONNECT_ERROR) ,"connect error"}, | 114 | {ERR_REASON(BIO_R_EOF_ON_MEMORY_BIO) , "EOF on memory BIO"}, |
116 | {ERR_REASON(BIO_R_EOF_ON_MEMORY_BIO) ,"EOF on memory BIO"}, | 115 | {ERR_REASON(BIO_R_ERROR_SETTING_NBIO) , "error setting nbio"}, |
117 | {ERR_REASON(BIO_R_ERROR_SETTING_NBIO) ,"error setting nbio"}, | 116 | {ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET), "error setting nbio on accepted socket"}, |
118 | {ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET),"error setting nbio on accepted socket"}, | 117 | {ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET), "error setting nbio on accept socket"}, |
119 | {ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET),"error setting nbio on accept socket"}, | 118 | {ERR_REASON(BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET), "gethostbyname addr is not af inet"}, |
120 | {ERR_REASON(BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET),"gethostbyname addr is not af inet"}, | 119 | {ERR_REASON(BIO_R_INVALID_ARGUMENT) , "invalid argument"}, |
121 | {ERR_REASON(BIO_R_INVALID_ARGUMENT) ,"invalid argument"}, | 120 | {ERR_REASON(BIO_R_INVALID_IP_ADDRESS) , "invalid ip address"}, |
122 | {ERR_REASON(BIO_R_INVALID_IP_ADDRESS) ,"invalid ip address"}, | 121 | {ERR_REASON(BIO_R_IN_USE) , "in use"}, |
123 | {ERR_REASON(BIO_R_IN_USE) ,"in use"}, | 122 | {ERR_REASON(BIO_R_KEEPALIVE) , "keepalive"}, |
124 | {ERR_REASON(BIO_R_KEEPALIVE) ,"keepalive"}, | 123 | {ERR_REASON(BIO_R_NBIO_CONNECT_ERROR) , "nbio connect error"}, |
125 | {ERR_REASON(BIO_R_NBIO_CONNECT_ERROR) ,"nbio connect error"}, | 124 | {ERR_REASON(BIO_R_NO_ACCEPT_PORT_SPECIFIED), "no accept port specified"}, |
126 | {ERR_REASON(BIO_R_NO_ACCEPT_PORT_SPECIFIED),"no accept port specified"}, | 125 | {ERR_REASON(BIO_R_NO_HOSTNAME_SPECIFIED) , "no hostname specified"}, |
127 | {ERR_REASON(BIO_R_NO_HOSTNAME_SPECIFIED) ,"no hostname specified"}, | 126 | {ERR_REASON(BIO_R_NO_PORT_DEFINED) , "no port defined"}, |
128 | {ERR_REASON(BIO_R_NO_PORT_DEFINED) ,"no port defined"}, | 127 | {ERR_REASON(BIO_R_NO_PORT_SPECIFIED) , "no port specified"}, |
129 | {ERR_REASON(BIO_R_NO_PORT_SPECIFIED) ,"no port specified"}, | 128 | {ERR_REASON(BIO_R_NO_SUCH_FILE) , "no such file"}, |
130 | {ERR_REASON(BIO_R_NO_SUCH_FILE) ,"no such file"}, | 129 | {ERR_REASON(BIO_R_NULL_PARAMETER) , "null parameter"}, |
131 | {ERR_REASON(BIO_R_NULL_PARAMETER) ,"null parameter"}, | 130 | {ERR_REASON(BIO_R_TAG_MISMATCH) , "tag mismatch"}, |
132 | {ERR_REASON(BIO_R_TAG_MISMATCH) ,"tag mismatch"}, | 131 | {ERR_REASON(BIO_R_UNABLE_TO_BIND_SOCKET) , "unable to bind socket"}, |
133 | {ERR_REASON(BIO_R_UNABLE_TO_BIND_SOCKET) ,"unable to bind socket"}, | 132 | {ERR_REASON(BIO_R_UNABLE_TO_CREATE_SOCKET), "unable to create socket"}, |
134 | {ERR_REASON(BIO_R_UNABLE_TO_CREATE_SOCKET),"unable to create socket"}, | 133 | {ERR_REASON(BIO_R_UNABLE_TO_LISTEN_SOCKET), "unable to listen socket"}, |
135 | {ERR_REASON(BIO_R_UNABLE_TO_LISTEN_SOCKET),"unable to listen socket"}, | 134 | {ERR_REASON(BIO_R_UNINITIALIZED) , "uninitialized"}, |
136 | {ERR_REASON(BIO_R_UNINITIALIZED) ,"uninitialized"}, | 135 | {ERR_REASON(BIO_R_UNSUPPORTED_METHOD) , "unsupported method"}, |
137 | {ERR_REASON(BIO_R_UNSUPPORTED_METHOD) ,"unsupported method"}, | 136 | {ERR_REASON(BIO_R_WRITE_TO_READ_ONLY_BIO), "write to read only BIO"}, |
138 | {ERR_REASON(BIO_R_WRITE_TO_READ_ONLY_BIO),"write to read only BIO"}, | 137 | {ERR_REASON(BIO_R_WSASTARTUP) , "WSAStartup"}, |
139 | {ERR_REASON(BIO_R_WSASTARTUP) ,"WSAStartup"}, | 138 | {0, NULL} |
140 | {0,NULL} | 139 | }; |
141 | }; | ||
142 | 140 | ||
143 | #endif | 141 | #endif |
144 | 142 | ||
145 | void ERR_load_BIO_strings(void) | 143 | void |
146 | { | 144 | ERR_load_BIO_strings(void) |
145 | { | ||
147 | #ifndef OPENSSL_NO_ERR | 146 | #ifndef OPENSSL_NO_ERR |
148 | 147 | if (ERR_func_error_string(BIO_str_functs[0].error) == NULL) { | |
149 | if (ERR_func_error_string(BIO_str_functs[0].error) == NULL) | 148 | ERR_load_strings(0, BIO_str_functs); |
150 | { | 149 | ERR_load_strings(0, BIO_str_reasons); |
151 | ERR_load_strings(0,BIO_str_functs); | ||
152 | ERR_load_strings(0,BIO_str_reasons); | ||
153 | } | ||
154 | #endif | ||
155 | } | 150 | } |
151 | #endif | ||
152 | } | ||
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c index 9c9646afa8..9e8fb7913a 100644 --- a/src/lib/libcrypto/bio/bio_lib.c +++ b/src/lib/libcrypto/bio/bio_lib.c | |||
@@ -63,539 +63,571 @@ | |||
63 | #include <openssl/bio.h> | 63 | #include <openssl/bio.h> |
64 | #include <openssl/stack.h> | 64 | #include <openssl/stack.h> |
65 | 65 | ||
66 | BIO *BIO_new(BIO_METHOD *method) | 66 | BIO |
67 | { | 67 | *BIO_new(BIO_METHOD *method) |
68 | BIO *ret=NULL; | 68 | { |
69 | 69 | BIO *ret = NULL; | |
70 | ret=(BIO *)OPENSSL_malloc(sizeof(BIO)); | 70 | |
71 | if (ret == NULL) | 71 | ret = (BIO *)OPENSSL_malloc(sizeof(BIO)); |
72 | { | 72 | if (ret == NULL) { |
73 | BIOerr(BIO_F_BIO_NEW,ERR_R_MALLOC_FAILURE); | 73 | BIOerr(BIO_F_BIO_NEW, ERR_R_MALLOC_FAILURE); |
74 | return(NULL); | 74 | return (NULL); |
75 | } | 75 | } |
76 | if (!BIO_set(ret,method)) | 76 | if (!BIO_set(ret, method)) { |
77 | { | ||
78 | OPENSSL_free(ret); | 77 | OPENSSL_free(ret); |
79 | ret=NULL; | 78 | ret = NULL; |
80 | } | ||
81 | return(ret); | ||
82 | } | 79 | } |
80 | return (ret); | ||
81 | } | ||
83 | 82 | ||
84 | int BIO_set(BIO *bio, BIO_METHOD *method) | 83 | int |
85 | { | 84 | BIO_set(BIO *bio, BIO_METHOD *method) |
86 | bio->method=method; | 85 | { |
87 | bio->callback=NULL; | 86 | bio->method = method; |
88 | bio->cb_arg=NULL; | 87 | bio->callback = NULL; |
89 | bio->init=0; | 88 | bio->cb_arg = NULL; |
90 | bio->shutdown=1; | 89 | bio->init = 0; |
91 | bio->flags=0; | 90 | bio->shutdown = 1; |
92 | bio->retry_reason=0; | 91 | bio->flags = 0; |
93 | bio->num=0; | 92 | bio->retry_reason = 0; |
94 | bio->ptr=NULL; | 93 | bio->num = 0; |
95 | bio->prev_bio=NULL; | 94 | bio->ptr = NULL; |
96 | bio->next_bio=NULL; | 95 | bio->prev_bio = NULL; |
97 | bio->references=1; | 96 | bio->next_bio = NULL; |
98 | bio->num_read=0L; | 97 | bio->references = 1; |
99 | bio->num_write=0L; | 98 | bio->num_read = 0L; |
99 | bio->num_write = 0L; | ||
100 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data); | 100 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data); |
101 | if (method->create != NULL) | 101 | if (method->create != NULL) |
102 | if (!method->create(bio)) | 102 | if (!method->create(bio)) { |
103 | { | ||
104 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio, | 103 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio, |
105 | &bio->ex_data); | 104 | &bio->ex_data); |
106 | return(0); | 105 | return (0); |
107 | } | 106 | } |
108 | return(1); | 107 | return (1); |
109 | } | 108 | } |
110 | 109 | ||
111 | int BIO_free(BIO *a) | 110 | int |
112 | { | 111 | BIO_free(BIO *a) |
112 | { | ||
113 | int i; | 113 | int i; |
114 | 114 | ||
115 | if (a == NULL) return(0); | 115 | if (a == NULL) |
116 | return (0); | ||
116 | 117 | ||
117 | i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_BIO); | 118 | i = CRYPTO_add(&a->references, -1, CRYPTO_LOCK_BIO); |
118 | #ifdef REF_PRINT | 119 | #ifdef REF_PRINT |
119 | REF_PRINT("BIO",a); | 120 | REF_PRINT("BIO", a); |
120 | #endif | 121 | #endif |
121 | if (i > 0) return(1); | 122 | if (i > 0) |
123 | return (1); | ||
122 | #ifdef REF_CHECK | 124 | #ifdef REF_CHECK |
123 | if (i < 0) | 125 | if (i < 0) { |
124 | { | 126 | fprintf(stderr, "BIO_free, bad reference count\n"); |
125 | fprintf(stderr,"BIO_free, bad reference count\n"); | ||
126 | abort(); | 127 | abort(); |
127 | } | 128 | } |
128 | #endif | 129 | #endif |
129 | if ((a->callback != NULL) && | 130 | if ((a->callback != NULL) && |
130 | ((i=(int)a->callback(a,BIO_CB_FREE,NULL,0,0L,1L)) <= 0)) | 131 | ((i = (int)a->callback(a, BIO_CB_FREE, NULL, 0, 0L, 1L)) <= 0)) |
131 | return(i); | 132 | return (i); |
132 | 133 | ||
133 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, a, &a->ex_data); | 134 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, a, &a->ex_data); |
134 | 135 | ||
135 | if ((a->method == NULL) || (a->method->destroy == NULL)) return(1); | 136 | if ((a->method == NULL) || (a->method->destroy == NULL)) |
137 | return (1); | ||
136 | a->method->destroy(a); | 138 | a->method->destroy(a); |
137 | OPENSSL_free(a); | 139 | OPENSSL_free(a); |
138 | return(1); | 140 | return (1); |
139 | } | 141 | } |
140 | 142 | ||
141 | void BIO_vfree(BIO *a) | 143 | void |
142 | { BIO_free(a); } | 144 | BIO_vfree(BIO *a) |
145 | { | ||
146 | BIO_free(a); | ||
147 | } | ||
143 | 148 | ||
144 | void BIO_clear_flags(BIO *b, int flags) | 149 | void |
145 | { | 150 | BIO_clear_flags(BIO *b, int flags) |
151 | { | ||
146 | b->flags &= ~flags; | 152 | b->flags &= ~flags; |
147 | } | 153 | } |
148 | 154 | ||
149 | int BIO_test_flags(const BIO *b, int flags) | 155 | int |
150 | { | 156 | BIO_test_flags(const BIO *b, int flags) |
157 | { | ||
151 | return (b->flags & flags); | 158 | return (b->flags & flags); |
152 | } | 159 | } |
153 | 160 | ||
154 | void BIO_set_flags(BIO *b, int flags) | 161 | void |
155 | { | 162 | BIO_set_flags(BIO *b, int flags) |
163 | { | ||
156 | b->flags |= flags; | 164 | b->flags |= flags; |
157 | } | 165 | } |
158 | 166 | ||
159 | long (*BIO_get_callback(const BIO *b))(struct bio_st *,int,const char *,int, long,long) | 167 | long |
160 | { | 168 | (*BIO_get_callback(const BIO *b))(struct bio_st *, int, const char *, int, |
169 | long, long) | ||
170 | { | ||
161 | return b->callback; | 171 | return b->callback; |
162 | } | 172 | } |
163 | 173 | ||
164 | void BIO_set_callback(BIO *b, long (*cb)(struct bio_st *,int,const char *,int, long,long)) | 174 | void |
165 | { | 175 | BIO_set_callback(BIO *b, long (*cb)(struct bio_st *, int, const char *, int, |
176 | long, long)) | ||
177 | { | ||
166 | b->callback = cb; | 178 | b->callback = cb; |
167 | } | 179 | } |
168 | 180 | ||
169 | void BIO_set_callback_arg(BIO *b, char *arg) | 181 | void |
170 | { | 182 | BIO_set_callback_arg(BIO *b, char *arg) |
183 | { | ||
171 | b->cb_arg = arg; | 184 | b->cb_arg = arg; |
172 | } | 185 | } |
173 | 186 | ||
174 | char * BIO_get_callback_arg(const BIO *b) | 187 | char * |
175 | { | 188 | BIO_get_callback_arg(const BIO *b) |
189 | { | ||
176 | return b->cb_arg; | 190 | return b->cb_arg; |
177 | } | 191 | } |
178 | 192 | ||
179 | const char * BIO_method_name(const BIO *b) | 193 | const char * |
180 | { | 194 | BIO_method_name(const BIO *b) |
195 | { | ||
181 | return b->method->name; | 196 | return b->method->name; |
182 | } | 197 | } |
183 | 198 | ||
184 | int BIO_method_type(const BIO *b) | 199 | int |
185 | { | 200 | BIO_method_type(const BIO *b) |
201 | { | ||
186 | return b->method->type; | 202 | return b->method->type; |
187 | } | 203 | } |
188 | |||
189 | 204 | ||
190 | int BIO_read(BIO *b, void *out, int outl) | 205 | int |
191 | { | 206 | BIO_read(BIO *b, void *out, int outl) |
207 | { | ||
192 | int i; | 208 | int i; |
193 | long (*cb)(BIO *,int,const char *,int,long,long); | 209 | long (*cb)(BIO *, int, const char *, int, long, long); |
194 | 210 | ||
195 | if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL)) | 211 | if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL)) { |
196 | { | 212 | BIOerr(BIO_F_BIO_READ, BIO_R_UNSUPPORTED_METHOD); |
197 | BIOerr(BIO_F_BIO_READ,BIO_R_UNSUPPORTED_METHOD); | 213 | return (-2); |
198 | return(-2); | 214 | } |
199 | } | ||
200 | 215 | ||
201 | cb=b->callback; | 216 | cb = b->callback; |
202 | if ((cb != NULL) && | 217 | if ((cb != NULL) && |
203 | ((i=(int)cb(b,BIO_CB_READ,out,outl,0L,1L)) <= 0)) | 218 | ((i = (int)cb(b, BIO_CB_READ, out, outl, 0L, 1L)) <= 0)) |
204 | return(i); | 219 | return (i); |
205 | 220 | ||
206 | if (!b->init) | 221 | if (!b->init) { |
207 | { | 222 | BIOerr(BIO_F_BIO_READ, BIO_R_UNINITIALIZED); |
208 | BIOerr(BIO_F_BIO_READ,BIO_R_UNINITIALIZED); | 223 | return (-2); |
209 | return(-2); | 224 | } |
210 | } | ||
211 | 225 | ||
212 | i=b->method->bread(b,out,outl); | 226 | i = b->method->bread(b, out, outl); |
213 | 227 | ||
214 | if (i > 0) b->num_read+=(unsigned long)i; | 228 | if (i > 0) |
229 | b->num_read += (unsigned long)i; | ||
215 | 230 | ||
216 | if (cb != NULL) | 231 | if (cb != NULL) |
217 | i=(int)cb(b,BIO_CB_READ|BIO_CB_RETURN,out,outl, | 232 | i = (int)cb(b, BIO_CB_READ|BIO_CB_RETURN, out, outl, |
218 | 0L,(long)i); | 233 | 0L, (long)i); |
219 | return(i); | 234 | return (i); |
220 | } | 235 | } |
221 | 236 | ||
222 | int BIO_write(BIO *b, const void *in, int inl) | 237 | int |
223 | { | 238 | BIO_write(BIO *b, const void *in, int inl) |
239 | { | ||
224 | int i; | 240 | int i; |
225 | long (*cb)(BIO *,int,const char *,int,long,long); | 241 | long (*cb)(BIO *, int, const char *, int, long, long); |
226 | 242 | ||
227 | if (b == NULL) | 243 | if (b == NULL) |
228 | return(0); | 244 | return (0); |
229 | 245 | ||
230 | cb=b->callback; | 246 | cb = b->callback; |
231 | if ((b->method == NULL) || (b->method->bwrite == NULL)) | 247 | if ((b->method == NULL) || (b->method->bwrite == NULL)) { |
232 | { | 248 | BIOerr(BIO_F_BIO_WRITE, BIO_R_UNSUPPORTED_METHOD); |
233 | BIOerr(BIO_F_BIO_WRITE,BIO_R_UNSUPPORTED_METHOD); | 249 | return (-2); |
234 | return(-2); | 250 | } |
235 | } | ||
236 | 251 | ||
237 | if ((cb != NULL) && | 252 | if ((cb != NULL) && |
238 | ((i=(int)cb(b,BIO_CB_WRITE,in,inl,0L,1L)) <= 0)) | 253 | ((i = (int)cb(b, BIO_CB_WRITE, in, inl, 0L, 1L)) <= 0)) |
239 | return(i); | 254 | return (i); |
240 | 255 | ||
241 | if (!b->init) | 256 | if (!b->init) { |
242 | { | 257 | BIOerr(BIO_F_BIO_WRITE, BIO_R_UNINITIALIZED); |
243 | BIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITIALIZED); | 258 | return (-2); |
244 | return(-2); | 259 | } |
245 | } | ||
246 | 260 | ||
247 | i=b->method->bwrite(b,in,inl); | 261 | i = b->method->bwrite(b, in, inl); |
248 | 262 | ||
249 | if (i > 0) b->num_write+=(unsigned long)i; | 263 | if (i > 0) |
264 | b->num_write += (unsigned long)i; | ||
250 | 265 | ||
251 | if (cb != NULL) | 266 | if (cb != NULL) |
252 | i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl, | 267 | i = (int)cb(b, BIO_CB_WRITE|BIO_CB_RETURN, in, inl, |
253 | 0L,(long)i); | 268 | 0L, (long)i); |
254 | return(i); | 269 | return (i); |
255 | } | 270 | } |
256 | 271 | ||
257 | int BIO_puts(BIO *b, const char *in) | 272 | int |
258 | { | 273 | BIO_puts(BIO *b, const char *in) |
274 | { | ||
259 | int i; | 275 | int i; |
260 | long (*cb)(BIO *,int,const char *,int,long,long); | 276 | long (*cb)(BIO *, int, const char *, int, long, long); |
261 | 277 | ||
262 | if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) | 278 | if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) { |
263 | { | 279 | BIOerr(BIO_F_BIO_PUTS, BIO_R_UNSUPPORTED_METHOD); |
264 | BIOerr(BIO_F_BIO_PUTS,BIO_R_UNSUPPORTED_METHOD); | 280 | return (-2); |
265 | return(-2); | 281 | } |
266 | } | ||
267 | 282 | ||
268 | cb=b->callback; | 283 | cb = b->callback; |
269 | 284 | ||
270 | if ((cb != NULL) && | 285 | if ((cb != NULL) && |
271 | ((i=(int)cb(b,BIO_CB_PUTS,in,0,0L,1L)) <= 0)) | 286 | ((i = (int)cb(b, BIO_CB_PUTS, in, 0, 0L, 1L)) <= 0)) |
272 | return(i); | 287 | return (i); |
273 | 288 | ||
274 | if (!b->init) | 289 | if (!b->init) { |
275 | { | 290 | BIOerr(BIO_F_BIO_PUTS, BIO_R_UNINITIALIZED); |
276 | BIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITIALIZED); | 291 | return (-2); |
277 | return(-2); | 292 | } |
278 | } | ||
279 | 293 | ||
280 | i=b->method->bputs(b,in); | 294 | i = b->method->bputs(b, in); |
281 | 295 | ||
282 | if (i > 0) b->num_write+=(unsigned long)i; | 296 | if (i > 0) |
297 | b->num_write += (unsigned long)i; | ||
283 | 298 | ||
284 | if (cb != NULL) | 299 | if (cb != NULL) |
285 | i=(int)cb(b,BIO_CB_PUTS|BIO_CB_RETURN,in,0, | 300 | i = (int)cb(b, BIO_CB_PUTS|BIO_CB_RETURN, in, 0, 0L, (long)i); |
286 | 0L,(long)i); | 301 | return (i); |
287 | return(i); | 302 | } |
288 | } | ||
289 | 303 | ||
290 | int BIO_gets(BIO *b, char *in, int inl) | 304 | int |
291 | { | 305 | BIO_gets(BIO *b, char *in, int inl) |
306 | { | ||
292 | int i; | 307 | int i; |
293 | long (*cb)(BIO *,int,const char *,int,long,long); | 308 | long (*cb)(BIO *, int, const char *, int, long, long); |
294 | 309 | ||
295 | if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL)) | 310 | if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL)) { |
296 | { | 311 | BIOerr(BIO_F_BIO_GETS, BIO_R_UNSUPPORTED_METHOD); |
297 | BIOerr(BIO_F_BIO_GETS,BIO_R_UNSUPPORTED_METHOD); | 312 | return (-2); |
298 | return(-2); | 313 | } |
299 | } | ||
300 | 314 | ||
301 | cb=b->callback; | 315 | cb = b->callback; |
302 | 316 | ||
303 | if ((cb != NULL) && | 317 | if ((cb != NULL) && |
304 | ((i=(int)cb(b,BIO_CB_GETS,in,inl,0L,1L)) <= 0)) | 318 | ((i = (int)cb(b, BIO_CB_GETS, in, inl, 0L, 1L)) <= 0)) |
305 | return(i); | 319 | return (i); |
306 | 320 | ||
307 | if (!b->init) | 321 | if (!b->init) { |
308 | { | 322 | BIOerr(BIO_F_BIO_GETS, BIO_R_UNINITIALIZED); |
309 | BIOerr(BIO_F_BIO_GETS,BIO_R_UNINITIALIZED); | 323 | return (-2); |
310 | return(-2); | 324 | } |
311 | } | ||
312 | 325 | ||
313 | i=b->method->bgets(b,in,inl); | 326 | i = b->method->bgets(b, in, inl); |
314 | 327 | ||
315 | if (cb != NULL) | 328 | if (cb != NULL) |
316 | i=(int)cb(b,BIO_CB_GETS|BIO_CB_RETURN,in,inl, | 329 | i = (int)cb(b, BIO_CB_GETS|BIO_CB_RETURN, in, inl, 0L, (long)i); |
317 | 0L,(long)i); | 330 | return (i); |
318 | return(i); | 331 | } |
319 | } | ||
320 | 332 | ||
321 | int BIO_indent(BIO *b,int indent,int max) | 333 | int |
322 | { | 334 | BIO_indent(BIO *b, int indent, int max) |
323 | if(indent < 0) | 335 | { |
324 | indent=0; | 336 | if (indent < 0) |
325 | if(indent > max) | 337 | indent = 0; |
326 | indent=max; | 338 | if (indent > max) |
327 | while(indent--) | 339 | indent = max; |
328 | if(BIO_puts(b," ") != 1) | 340 | while (indent--) |
329 | return 0; | 341 | if (BIO_puts(b, " ") != 1) |
342 | return 0; | ||
330 | return 1; | 343 | return 1; |
331 | } | 344 | } |
332 | 345 | ||
333 | long BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg) | 346 | long |
334 | { | 347 | BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg) |
348 | { | ||
335 | int i; | 349 | int i; |
336 | 350 | ||
337 | i=iarg; | 351 | i = iarg; |
338 | return(BIO_ctrl(b,cmd,larg,(char *)&i)); | 352 | return (BIO_ctrl(b, cmd, larg,(char *)&i)); |
339 | } | 353 | } |
340 | 354 | ||
341 | char *BIO_ptr_ctrl(BIO *b, int cmd, long larg) | 355 | char |
342 | { | 356 | *BIO_ptr_ctrl(BIO *b, int cmd, long larg) |
343 | char *p=NULL; | 357 | { |
358 | char *p = NULL; | ||
344 | 359 | ||
345 | if (BIO_ctrl(b,cmd,larg,(char *)&p) <= 0) | 360 | if (BIO_ctrl(b, cmd, larg,(char *)&p) <= 0) |
346 | return(NULL); | 361 | return (NULL); |
347 | else | 362 | else |
348 | return(p); | 363 | return (p); |
349 | } | 364 | } |
350 | 365 | ||
351 | long BIO_ctrl(BIO *b, int cmd, long larg, void *parg) | 366 | long |
352 | { | 367 | BIO_ctrl(BIO *b, int cmd, long larg, void *parg) |
368 | { | ||
353 | long ret; | 369 | long ret; |
354 | long (*cb)(BIO *,int,const char *,int,long,long); | 370 | long (*cb)(BIO *, int, const char *, int, long, long); |
355 | 371 | ||
356 | if (b == NULL) return(0); | 372 | if (b == NULL) |
373 | return (0); | ||
357 | 374 | ||
358 | if ((b->method == NULL) || (b->method->ctrl == NULL)) | 375 | if ((b->method == NULL) || (b->method->ctrl == NULL)) { |
359 | { | 376 | BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD); |
360 | BIOerr(BIO_F_BIO_CTRL,BIO_R_UNSUPPORTED_METHOD); | 377 | return (-2); |
361 | return(-2); | 378 | } |
362 | } | ||
363 | 379 | ||
364 | cb=b->callback; | 380 | cb = b->callback; |
365 | 381 | ||
366 | if ((cb != NULL) && | 382 | if ((cb != NULL) && |
367 | ((ret=cb(b,BIO_CB_CTRL,parg,cmd,larg,1L)) <= 0)) | 383 | ((ret = cb(b, BIO_CB_CTRL, parg, cmd, larg, 1L)) <= 0)) |
368 | return(ret); | 384 | return (ret); |
369 | 385 | ||
370 | ret=b->method->ctrl(b,cmd,larg,parg); | 386 | ret = b->method->ctrl(b, cmd, larg, parg); |
371 | 387 | ||
372 | if (cb != NULL) | 388 | if (cb != NULL) |
373 | ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,parg,cmd, | 389 | ret = cb(b, BIO_CB_CTRL|BIO_CB_RETURN, parg, cmd, larg, ret); |
374 | larg,ret); | 390 | return (ret); |
375 | return(ret); | 391 | } |
376 | } | ||
377 | 392 | ||
378 | long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long)) | 393 | long |
379 | { | 394 | BIO_callback_ctrl(BIO *b, int cmd, |
395 | void (*fp)(struct bio_st *, int, const char *, int, long, long)) | ||
396 | { | ||
380 | long ret; | 397 | long ret; |
381 | long (*cb)(BIO *,int,const char *,int,long,long); | 398 | long (*cb)(BIO *, int, const char *, int, long, long); |
382 | 399 | ||
383 | if (b == NULL) return(0); | 400 | if (b == NULL) |
401 | return (0); | ||
384 | 402 | ||
385 | if ((b->method == NULL) || (b->method->callback_ctrl == NULL)) | 403 | if ((b->method == NULL) || (b->method->callback_ctrl == NULL)) { |
386 | { | 404 | BIOerr(BIO_F_BIO_CALLBACK_CTRL, BIO_R_UNSUPPORTED_METHOD); |
387 | BIOerr(BIO_F_BIO_CALLBACK_CTRL,BIO_R_UNSUPPORTED_METHOD); | 405 | return (-2); |
388 | return(-2); | 406 | } |
389 | } | ||
390 | 407 | ||
391 | cb=b->callback; | 408 | cb = b->callback; |
392 | 409 | ||
393 | if ((cb != NULL) && | 410 | if ((cb != NULL) && |
394 | ((ret=cb(b,BIO_CB_CTRL,(void *)&fp,cmd,0,1L)) <= 0)) | 411 | ((ret = cb(b, BIO_CB_CTRL,(void *)&fp, cmd, 0, 1L)) <= 0)) |
395 | return(ret); | 412 | return (ret); |
396 | 413 | ||
397 | ret=b->method->callback_ctrl(b,cmd,fp); | 414 | ret = b->method->callback_ctrl(b, cmd, fp); |
398 | 415 | ||
399 | if (cb != NULL) | 416 | if (cb != NULL) |
400 | ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,(void *)&fp,cmd, | 417 | ret = cb(b, BIO_CB_CTRL|BIO_CB_RETURN,(void *)&fp, cmd, 0, ret); |
401 | 0,ret); | 418 | return (ret); |
402 | return(ret); | 419 | } |
403 | } | ||
404 | 420 | ||
405 | /* It is unfortunate to duplicate in functions what the BIO_(w)pending macros | 421 | /* It is unfortunate to duplicate in functions what the BIO_(w)pending macros |
406 | * do; but those macros have inappropriate return type, and for interfacing | 422 | * do; but those macros have inappropriate return type, and for interfacing |
407 | * from other programming languages, C macros aren't much of a help anyway. */ | 423 | * from other programming languages, C macros aren't much of a help anyway. */ |
408 | size_t BIO_ctrl_pending(BIO *bio) | 424 | size_t |
409 | { | 425 | BIO_ctrl_pending(BIO *bio) |
426 | { | ||
410 | return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL); | 427 | return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL); |
411 | } | 428 | } |
412 | 429 | ||
413 | size_t BIO_ctrl_wpending(BIO *bio) | 430 | size_t |
414 | { | 431 | BIO_ctrl_wpending(BIO *bio) |
432 | { | ||
415 | return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL); | 433 | return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL); |
416 | } | 434 | } |
417 | 435 | ||
418 | 436 | ||
419 | /* put the 'bio' on the end of b's list of operators */ | 437 | /* put the 'bio' on the end of b's list of operators */ |
420 | BIO *BIO_push(BIO *b, BIO *bio) | 438 | BIO |
421 | { | 439 | *BIO_push(BIO *b, BIO *bio) |
440 | { | ||
422 | BIO *lb; | 441 | BIO *lb; |
423 | 442 | ||
424 | if (b == NULL) return(bio); | 443 | if (b == NULL) |
425 | lb=b; | 444 | return (bio); |
445 | lb = b; | ||
426 | while (lb->next_bio != NULL) | 446 | while (lb->next_bio != NULL) |
427 | lb=lb->next_bio; | 447 | lb = lb->next_bio; |
428 | lb->next_bio=bio; | 448 | lb->next_bio = bio; |
429 | if (bio != NULL) | 449 | if (bio != NULL) |
430 | bio->prev_bio=lb; | 450 | bio->prev_bio = lb; |
431 | /* called to do internal processing */ | 451 | /* called to do internal processing */ |
432 | BIO_ctrl(b,BIO_CTRL_PUSH,0,lb); | 452 | BIO_ctrl(b, BIO_CTRL_PUSH, 0, lb); |
433 | return(b); | 453 | return (b); |
434 | } | 454 | } |
435 | 455 | ||
436 | /* Remove the first and return the rest */ | 456 | /* Remove the first and return the rest */ |
437 | BIO *BIO_pop(BIO *b) | 457 | BIO |
438 | { | 458 | *BIO_pop(BIO *b) |
459 | { | ||
439 | BIO *ret; | 460 | BIO *ret; |
440 | 461 | ||
441 | if (b == NULL) return(NULL); | 462 | if (b == NULL) |
442 | ret=b->next_bio; | 463 | return (NULL); |
464 | ret = b->next_bio; | ||
443 | 465 | ||
444 | BIO_ctrl(b,BIO_CTRL_POP,0,b); | 466 | BIO_ctrl(b, BIO_CTRL_POP, 0, b); |
445 | 467 | ||
446 | if (b->prev_bio != NULL) | 468 | if (b->prev_bio != NULL) |
447 | b->prev_bio->next_bio=b->next_bio; | 469 | b->prev_bio->next_bio = b->next_bio; |
448 | if (b->next_bio != NULL) | 470 | if (b->next_bio != NULL) |
449 | b->next_bio->prev_bio=b->prev_bio; | 471 | b->next_bio->prev_bio = b->prev_bio; |
450 | 472 | ||
451 | b->next_bio=NULL; | 473 | b->next_bio = NULL; |
452 | b->prev_bio=NULL; | 474 | b->prev_bio = NULL; |
453 | return(ret); | 475 | return (ret); |
454 | } | 476 | } |
455 | 477 | ||
456 | BIO *BIO_get_retry_BIO(BIO *bio, int *reason) | 478 | BIO |
457 | { | 479 | *BIO_get_retry_BIO(BIO *bio, int *reason) |
458 | BIO *b,*last; | 480 | { |
481 | BIO *b, *last; | ||
459 | 482 | ||
460 | b=last=bio; | 483 | b = last = bio; |
461 | for (;;) | 484 | for (;;) { |
462 | { | ||
463 | if (!BIO_should_retry(b)) break; | 485 | if (!BIO_should_retry(b)) break; |
464 | last=b; | 486 | last = b; |
465 | b=b->next_bio; | 487 | b = b->next_bio; |
466 | if (b == NULL) break; | 488 | if (b == NULL) |
467 | } | 489 | break; |
468 | if (reason != NULL) *reason=last->retry_reason; | 490 | } |
469 | return(last); | 491 | if (reason != NULL) |
470 | } | 492 | *reason = last->retry_reason; |
493 | return (last); | ||
494 | } | ||
471 | 495 | ||
472 | int BIO_get_retry_reason(BIO *bio) | 496 | int |
473 | { | 497 | BIO_get_retry_reason(BIO *bio) |
474 | return(bio->retry_reason); | 498 | { |
475 | } | 499 | return (bio->retry_reason); |
500 | } | ||
476 | 501 | ||
477 | BIO *BIO_find_type(BIO *bio, int type) | 502 | BIO |
478 | { | 503 | *BIO_find_type(BIO *bio, int type) |
479 | int mt,mask; | 504 | { |
480 | 505 | int mt, mask; | |
481 | if(!bio) return NULL; | 506 | |
482 | mask=type&0xff; | 507 | if (!bio) |
483 | do { | 508 | return NULL; |
484 | if (bio->method != NULL) | 509 | mask = type & 0xff; |
485 | { | 510 | do { |
486 | mt=bio->method->type; | 511 | if (bio->method != NULL) { |
487 | 512 | mt = bio->method->type; | |
488 | if (!mask) | 513 | if (!mask) { |
489 | { | 514 | if (mt & type) |
490 | if (mt & type) return(bio); | 515 | return (bio); |
491 | } | 516 | } else if (mt == type) |
492 | else if (mt == type) | 517 | return (bio); |
493 | return(bio); | 518 | } |
494 | } | 519 | bio = bio->next_bio; |
495 | bio=bio->next_bio; | 520 | } while (bio != NULL); |
496 | } while (bio != NULL); | 521 | return (NULL); |
497 | return(NULL); | 522 | } |
498 | } | ||
499 | 523 | ||
500 | BIO *BIO_next(BIO *b) | 524 | BIO |
501 | { | 525 | *BIO_next(BIO *b) |
502 | if(!b) return NULL; | 526 | { |
527 | if (!b) | ||
528 | return NULL; | ||
503 | return b->next_bio; | 529 | return b->next_bio; |
504 | } | 530 | } |
505 | 531 | ||
506 | void BIO_free_all(BIO *bio) | 532 | void |
507 | { | 533 | BIO_free_all(BIO *bio) |
534 | { | ||
508 | BIO *b; | 535 | BIO *b; |
509 | int ref; | 536 | int ref; |
510 | 537 | ||
511 | while (bio != NULL) | 538 | while (bio != NULL) { |
512 | { | 539 | b = bio; |
513 | b=bio; | 540 | ref = b->references; |
514 | ref=b->references; | 541 | bio = bio->next_bio; |
515 | bio=bio->next_bio; | ||
516 | BIO_free(b); | 542 | BIO_free(b); |
517 | /* Since ref count > 1, don't free anyone else. */ | 543 | /* Since ref count > 1, don't free anyone else. */ |
518 | if (ref > 1) break; | 544 | if (ref > 1) |
519 | } | 545 | break; |
520 | } | 546 | } |
547 | } | ||
521 | 548 | ||
522 | BIO *BIO_dup_chain(BIO *in) | 549 | BIO |
523 | { | 550 | *BIO_dup_chain(BIO *in) |
524 | BIO *ret=NULL,*eoc=NULL,*bio,*new_bio; | 551 | { |
552 | BIO *ret = NULL, *eoc = NULL, *bio, *new_bio; | ||
525 | 553 | ||
526 | for (bio=in; bio != NULL; bio=bio->next_bio) | 554 | for (bio = in; bio != NULL; bio = bio->next_bio) { |
527 | { | 555 | if ((new_bio = BIO_new(bio->method)) == NULL) goto err; |
528 | if ((new_bio=BIO_new(bio->method)) == NULL) goto err; | 556 | new_bio->callback = bio->callback; |
529 | new_bio->callback=bio->callback; | 557 | new_bio->cb_arg = bio->cb_arg; |
530 | new_bio->cb_arg=bio->cb_arg; | 558 | new_bio->init = bio->init; |
531 | new_bio->init=bio->init; | 559 | new_bio->shutdown = bio->shutdown; |
532 | new_bio->shutdown=bio->shutdown; | 560 | new_bio->flags = bio->flags; |
533 | new_bio->flags=bio->flags; | ||
534 | 561 | ||
535 | /* This will let SSL_s_sock() work with stdin/stdout */ | 562 | /* This will let SSL_s_sock() work with stdin/stdout */ |
536 | new_bio->num=bio->num; | 563 | new_bio->num = bio->num; |
537 | 564 | ||
538 | if (!BIO_dup_state(bio,(char *)new_bio)) | 565 | if (!BIO_dup_state(bio,(char *)new_bio)) { |
539 | { | ||
540 | BIO_free(new_bio); | 566 | BIO_free(new_bio); |
541 | goto err; | 567 | goto err; |
542 | } | 568 | } |
543 | 569 | ||
544 | /* copy app data */ | 570 | /* copy app data */ |
545 | if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_BIO, &new_bio->ex_data, | 571 | if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_BIO, |
546 | &bio->ex_data)) | 572 | &new_bio->ex_data, &bio->ex_data)) |
547 | goto err; | 573 | goto err; |
548 | 574 | ||
549 | if (ret == NULL) | 575 | if (ret == NULL) { |
550 | { | 576 | eoc = new_bio; |
551 | eoc=new_bio; | 577 | ret = eoc; |
552 | ret=eoc; | 578 | } else { |
553 | } | 579 | BIO_push(eoc, new_bio); |
554 | else | 580 | eoc = new_bio; |
555 | { | ||
556 | BIO_push(eoc,new_bio); | ||
557 | eoc=new_bio; | ||
558 | } | ||
559 | } | 581 | } |
560 | return(ret); | 582 | } |
583 | return (ret); | ||
561 | err: | 584 | err: |
562 | if (ret != NULL) | 585 | if (ret != NULL) |
563 | BIO_free(ret); | 586 | BIO_free(ret); |
564 | return(NULL); | 587 | return (NULL); |
565 | } | ||
566 | 588 | ||
567 | void BIO_copy_next_retry(BIO *b) | 589 | } |
568 | { | ||
569 | BIO_set_flags(b,BIO_get_retry_flags(b->next_bio)); | ||
570 | b->retry_reason=b->next_bio->retry_reason; | ||
571 | } | ||
572 | 590 | ||
573 | int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | 591 | void |
574 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | 592 | BIO_copy_next_retry(BIO *b) |
575 | { | 593 | { |
594 | BIO_set_flags(b, BIO_get_retry_flags(b->next_bio)); | ||
595 | b->retry_reason = b->next_bio->retry_reason; | ||
596 | } | ||
597 | |||
598 | int | ||
599 | BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
600 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | ||
601 | { | ||
576 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_BIO, argl, argp, | 602 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_BIO, argl, argp, |
577 | new_func, dup_func, free_func); | 603 | new_func, dup_func, free_func); |
578 | } | 604 | } |
579 | 605 | ||
580 | int BIO_set_ex_data(BIO *bio, int idx, void *data) | 606 | int |
581 | { | 607 | BIO_set_ex_data(BIO *bio, int idx, void *data) |
582 | return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data)); | 608 | { |
583 | } | 609 | return (CRYPTO_set_ex_data(&(bio->ex_data), idx, data)); |
610 | } | ||
584 | 611 | ||
585 | void *BIO_get_ex_data(BIO *bio, int idx) | 612 | void |
586 | { | 613 | *BIO_get_ex_data(BIO *bio, int idx) |
587 | return(CRYPTO_get_ex_data(&(bio->ex_data),idx)); | 614 | { |
588 | } | 615 | return (CRYPTO_get_ex_data(&(bio->ex_data), idx)); |
616 | } | ||
589 | 617 | ||
590 | unsigned long BIO_number_read(BIO *bio) | 618 | unsigned long |
619 | BIO_number_read(BIO *bio) | ||
591 | { | 620 | { |
592 | if(bio) return bio->num_read; | 621 | if (bio) |
622 | return bio->num_read; | ||
593 | return 0; | 623 | return 0; |
594 | } | 624 | } |
595 | 625 | ||
596 | unsigned long BIO_number_written(BIO *bio) | 626 | unsigned long |
627 | BIO_number_written(BIO *bio) | ||
597 | { | 628 | { |
598 | if(bio) return bio->num_write; | 629 | if (bio) |
630 | return bio->num_write; | ||
599 | return 0; | 631 | return 0; |
600 | } | 632 | } |
601 | 633 | ||
diff --git a/src/lib/libcrypto/bio/bss_acpt.c b/src/lib/libcrypto/bio/bss_acpt.c index 04bfb6fb9d..d772515d64 100644 --- a/src/lib/libcrypto/bio/bss_acpt.c +++ b/src/lib/libcrypto/bio/bss_acpt.c | |||
@@ -75,8 +75,7 @@ | |||
75 | #undef FIONBIO | 75 | #undef FIONBIO |
76 | #endif | 76 | #endif |
77 | 77 | ||
78 | typedef struct bio_accept_st | 78 | typedef struct bio_accept_st { |
79 | { | ||
80 | int state; | 79 | int state; |
81 | char *param_addr; | 80 | char *param_addr; |
82 | 81 | ||
@@ -90,7 +89,7 @@ typedef struct bio_accept_st | |||
90 | * If 2, always use SO_REUSEADDR. */ | 89 | * If 2, always use SO_REUSEADDR. */ |
91 | int bind_mode; | 90 | int bind_mode; |
92 | BIO *bio_chain; | 91 | BIO *bio_chain; |
93 | } BIO_ACCEPT; | 92 | } BIO_ACCEPT; |
94 | 93 | ||
95 | static int acpt_write(BIO *h, const char *buf, int num); | 94 | static int acpt_write(BIO *h, const char *buf, int num); |
96 | static int acpt_read(BIO *h, char *buf, int size); | 95 | static int acpt_read(BIO *h, char *buf, int size); |
@@ -107,8 +106,7 @@ static void BIO_ACCEPT_free(BIO_ACCEPT *a); | |||
107 | #define ACPT_S_GET_ACCEPT_SOCKET 2 | 106 | #define ACPT_S_GET_ACCEPT_SOCKET 2 |
108 | #define ACPT_S_OK 3 | 107 | #define ACPT_S_OK 3 |
109 | 108 | ||
110 | static BIO_METHOD methods_acceptp= | 109 | static BIO_METHOD methods_acceptp = { |
111 | { | ||
112 | BIO_TYPE_ACCEPT, | 110 | BIO_TYPE_ACCEPT, |
113 | "socket accept", | 111 | "socket accept", |
114 | acpt_write, | 112 | acpt_write, |
@@ -119,321 +117,313 @@ static BIO_METHOD methods_acceptp= | |||
119 | acpt_new, | 117 | acpt_new, |
120 | acpt_free, | 118 | acpt_free, |
121 | NULL, | 119 | NULL, |
122 | }; | 120 | }; |
123 | 121 | ||
124 | BIO_METHOD *BIO_s_accept(void) | 122 | BIO_METHOD |
125 | { | 123 | *BIO_s_accept(void) |
126 | return(&methods_acceptp); | 124 | { |
127 | } | 125 | return (&methods_acceptp); |
126 | } | ||
128 | 127 | ||
129 | static int acpt_new(BIO *bi) | 128 | static int |
130 | { | 129 | acpt_new(BIO *bi) |
130 | { | ||
131 | BIO_ACCEPT *ba; | 131 | BIO_ACCEPT *ba; |
132 | 132 | ||
133 | bi->init=0; | 133 | bi->init = 0; |
134 | bi->num=-1; | 134 | bi->num = -1; |
135 | bi->flags=0; | 135 | bi->flags = 0; |
136 | if ((ba=BIO_ACCEPT_new()) == NULL) | 136 | if ((ba = BIO_ACCEPT_new()) == NULL) |
137 | return(0); | 137 | return (0); |
138 | bi->ptr=(char *)ba; | 138 | bi->ptr = (char *)ba; |
139 | ba->state=ACPT_S_BEFORE; | 139 | ba->state = ACPT_S_BEFORE; |
140 | bi->shutdown=1; | 140 | bi->shutdown = 1; |
141 | return(1); | 141 | return (1); |
142 | } | 142 | } |
143 | 143 | ||
144 | static BIO_ACCEPT *BIO_ACCEPT_new(void) | 144 | static BIO_ACCEPT |
145 | { | 145 | *BIO_ACCEPT_new(void) |
146 | { | ||
146 | BIO_ACCEPT *ret; | 147 | BIO_ACCEPT *ret; |
147 | 148 | ||
148 | if ((ret=(BIO_ACCEPT *)OPENSSL_malloc(sizeof(BIO_ACCEPT))) == NULL) | 149 | if ((ret = (BIO_ACCEPT *)OPENSSL_malloc(sizeof(BIO_ACCEPT))) == NULL) |
149 | return(NULL); | 150 | return (NULL); |
150 | 151 | ||
151 | memset(ret,0,sizeof(BIO_ACCEPT)); | 152 | memset(ret, 0, sizeof(BIO_ACCEPT)); |
152 | ret->accept_sock=-1; | 153 | ret->accept_sock = -1; |
153 | ret->bind_mode=BIO_BIND_NORMAL; | 154 | ret->bind_mode = BIO_BIND_NORMAL; |
154 | return(ret); | 155 | return (ret); |
155 | } | 156 | } |
156 | 157 | ||
157 | static void BIO_ACCEPT_free(BIO_ACCEPT *a) | 158 | static void |
158 | { | 159 | BIO_ACCEPT_free(BIO_ACCEPT *a) |
159 | if(a == NULL) | 160 | { |
160 | return; | 161 | if (a == NULL) |
161 | 162 | return; | |
162 | if (a->param_addr != NULL) OPENSSL_free(a->param_addr); | 163 | |
163 | if (a->addr != NULL) OPENSSL_free(a->addr); | 164 | if (a->param_addr != NULL) |
164 | if (a->bio_chain != NULL) BIO_free(a->bio_chain); | 165 | OPENSSL_free(a->param_addr); |
166 | if (a->addr != NULL) | ||
167 | OPENSSL_free(a->addr); | ||
168 | if (a->bio_chain != NULL) | ||
169 | BIO_free(a->bio_chain); | ||
165 | OPENSSL_free(a); | 170 | OPENSSL_free(a); |
166 | } | 171 | } |
167 | 172 | ||
168 | static void acpt_close_socket(BIO *bio) | 173 | static void |
169 | { | 174 | acpt_close_socket(BIO *bio) |
175 | { | ||
170 | BIO_ACCEPT *c; | 176 | BIO_ACCEPT *c; |
171 | 177 | ||
172 | c=(BIO_ACCEPT *)bio->ptr; | 178 | c = (BIO_ACCEPT *)bio->ptr; |
173 | if (c->accept_sock != -1) | 179 | if (c->accept_sock != -1) { |
174 | { | ||
175 | shutdown(c->accept_sock, SHUT_RDWR); | 180 | shutdown(c->accept_sock, SHUT_RDWR); |
176 | close(c->accept_sock); | 181 | close(c->accept_sock); |
177 | c->accept_sock=-1; | 182 | c->accept_sock = -1; |
178 | bio->num=-1; | 183 | bio->num = -1; |
179 | } | ||
180 | } | 184 | } |
185 | } | ||
181 | 186 | ||
182 | static int acpt_free(BIO *a) | 187 | static int |
183 | { | 188 | acpt_free(BIO *a) |
189 | { | ||
184 | BIO_ACCEPT *data; | 190 | BIO_ACCEPT *data; |
185 | 191 | ||
186 | if (a == NULL) return(0); | 192 | if (a == NULL) |
187 | data=(BIO_ACCEPT *)a->ptr; | 193 | return (0); |
188 | 194 | data = (BIO_ACCEPT *)a->ptr; | |
189 | if (a->shutdown) | 195 | |
190 | { | 196 | if (a->shutdown) { |
191 | acpt_close_socket(a); | 197 | acpt_close_socket(a); |
192 | BIO_ACCEPT_free(data); | 198 | BIO_ACCEPT_free(data); |
193 | a->ptr=NULL; | 199 | a->ptr = NULL; |
194 | a->flags=0; | 200 | a->flags = 0; |
195 | a->init=0; | 201 | a->init = 0; |
196 | } | ||
197 | return(1); | ||
198 | } | 202 | } |
199 | 203 | return (1); | |
200 | static int acpt_state(BIO *b, BIO_ACCEPT *c) | 204 | } |
201 | { | 205 | |
202 | BIO *bio=NULL,*dbio; | 206 | static int |
203 | int s= -1; | 207 | acpt_state(BIO *b, BIO_ACCEPT *c) |
208 | { | ||
209 | BIO *bio = NULL, *dbio; | ||
210 | int s = -1; | ||
204 | int i; | 211 | int i; |
205 | 212 | ||
206 | again: | 213 | again: |
207 | switch (c->state) | 214 | switch (c->state) { |
208 | { | ||
209 | case ACPT_S_BEFORE: | 215 | case ACPT_S_BEFORE: |
210 | if (c->param_addr == NULL) | 216 | if (c->param_addr == NULL) { |
211 | { | 217 | BIOerr(BIO_F_ACPT_STATE, BIO_R_NO_ACCEPT_PORT_SPECIFIED); |
212 | BIOerr(BIO_F_ACPT_STATE,BIO_R_NO_ACCEPT_PORT_SPECIFIED); | 218 | return (-1); |
213 | return(-1); | 219 | } |
214 | } | 220 | s = BIO_get_accept_socket(c->param_addr, c->bind_mode); |
215 | s=BIO_get_accept_socket(c->param_addr,c->bind_mode); | ||
216 | if (s == -1) | 221 | if (s == -1) |
217 | return(-1); | 222 | return (-1); |
218 | 223 | ||
219 | if (c->accept_nbio) | 224 | if (c->accept_nbio) { |
220 | { | 225 | if (!BIO_socket_nbio(s, 1)) { |
221 | if (!BIO_socket_nbio(s,1)) | ||
222 | { | ||
223 | close(s); | 226 | close(s); |
224 | BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET); | 227 | BIOerr(BIO_F_ACPT_STATE, BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET); |
225 | return(-1); | 228 | return (-1); |
226 | } | ||
227 | } | 229 | } |
228 | c->accept_sock=s; | 230 | } |
229 | b->num=s; | 231 | c->accept_sock = s; |
230 | c->state=ACPT_S_GET_ACCEPT_SOCKET; | 232 | b->num = s; |
231 | return(1); | 233 | c->state = ACPT_S_GET_ACCEPT_SOCKET; |
234 | return (1); | ||
232 | /* break; */ | 235 | /* break; */ |
233 | case ACPT_S_GET_ACCEPT_SOCKET: | 236 | case ACPT_S_GET_ACCEPT_SOCKET: |
234 | if (b->next_bio != NULL) | 237 | if (b->next_bio != NULL) { |
235 | { | 238 | c->state = ACPT_S_OK; |
236 | c->state=ACPT_S_OK; | ||
237 | goto again; | 239 | goto again; |
238 | } | 240 | } |
239 | BIO_clear_retry_flags(b); | 241 | BIO_clear_retry_flags(b); |
240 | b->retry_reason=0; | 242 | b->retry_reason = 0; |
241 | i=BIO_accept(c->accept_sock,&(c->addr)); | 243 | i = BIO_accept(c->accept_sock, &(c->addr)); |
242 | 244 | ||
243 | /* -2 return means we should retry */ | 245 | /* -2 return means we should retry */ |
244 | if(i == -2) | 246 | if (i == -2) { |
245 | { | ||
246 | BIO_set_retry_special(b); | 247 | BIO_set_retry_special(b); |
247 | b->retry_reason=BIO_RR_ACCEPT; | 248 | b->retry_reason = BIO_RR_ACCEPT; |
248 | return -1; | 249 | return -1; |
249 | } | 250 | } |
250 | 251 | ||
251 | if (i < 0) return(i); | 252 | if (i < 0) |
253 | return (i); | ||
252 | 254 | ||
253 | bio=BIO_new_socket(i,BIO_CLOSE); | 255 | bio = BIO_new_socket(i, BIO_CLOSE); |
254 | if (bio == NULL) goto err; | 256 | if (bio == NULL) |
257 | goto err; | ||
255 | 258 | ||
256 | BIO_set_callback(bio,BIO_get_callback(b)); | 259 | BIO_set_callback(bio, BIO_get_callback(b)); |
257 | BIO_set_callback_arg(bio,BIO_get_callback_arg(b)); | 260 | BIO_set_callback_arg(bio, BIO_get_callback_arg(b)); |
258 | 261 | ||
259 | if (c->nbio) | 262 | if (c->nbio) { |
260 | { | 263 | if (!BIO_socket_nbio(i, 1)) { |
261 | if (!BIO_socket_nbio(i,1)) | 264 | BIOerr(BIO_F_ACPT_STATE, BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET); |
262 | { | ||
263 | BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET); | ||
264 | goto err; | 265 | goto err; |
265 | } | ||
266 | } | 266 | } |
267 | } | ||
267 | 268 | ||
268 | /* If the accept BIO has an bio_chain, we dup it and | 269 | /* If the accept BIO has an bio_chain, we dup it and |
269 | * put the new socket at the end. */ | 270 | * put the new socket at the end. */ |
270 | if (c->bio_chain != NULL) | 271 | if (c->bio_chain != NULL) { |
271 | { | 272 | if ((dbio = BIO_dup_chain(c->bio_chain)) == NULL) |
272 | if ((dbio=BIO_dup_chain(c->bio_chain)) == NULL) | ||
273 | goto err; | 273 | goto err; |
274 | if (!BIO_push(dbio,bio)) goto err; | 274 | if (!BIO_push(dbio, bio)) goto err; |
275 | bio=dbio; | 275 | bio = dbio; |
276 | } | 276 | } |
277 | if (BIO_push(b,bio) == NULL) goto err; | 277 | if (BIO_push(b, bio) |
278 | == NULL) goto err; | ||
279 | |||
280 | c->state = ACPT_S_OK; | ||
281 | return (1); | ||
278 | 282 | ||
279 | c->state=ACPT_S_OK; | ||
280 | return(1); | ||
281 | err: | 283 | err: |
282 | if (bio != NULL) | 284 | if (bio != NULL) |
283 | BIO_free(bio); | 285 | BIO_free(bio); |
284 | else if (s >= 0) | 286 | else if (s >= 0) |
285 | close(s); | 287 | close(s); |
286 | return(0); | 288 | return (0); |
287 | /* break; */ | 289 | /* break; */ |
288 | case ACPT_S_OK: | 290 | case ACPT_S_OK: |
289 | if (b->next_bio == NULL) | 291 | if (b->next_bio == NULL) { |
290 | { | 292 | c->state = ACPT_S_GET_ACCEPT_SOCKET; |
291 | c->state=ACPT_S_GET_ACCEPT_SOCKET; | ||
292 | goto again; | 293 | goto again; |
293 | } | 294 | } |
294 | return(1); | 295 | return (1); |
295 | /* break; */ | 296 | /* break; */ |
296 | default: | 297 | default: |
297 | return(0); | 298 | return (0); |
298 | /* break; */ | 299 | /* break; */ |
299 | } | ||
300 | |||
301 | } | 300 | } |
301 | } | ||
302 | 302 | ||
303 | static int acpt_read(BIO *b, char *out, int outl) | 303 | static int |
304 | { | 304 | acpt_read(BIO *b, char *out, int outl) |
305 | int ret=0; | 305 | { |
306 | int ret = 0; | ||
306 | BIO_ACCEPT *data; | 307 | BIO_ACCEPT *data; |
307 | 308 | ||
308 | BIO_clear_retry_flags(b); | 309 | BIO_clear_retry_flags(b); |
309 | data=(BIO_ACCEPT *)b->ptr; | 310 | data = (BIO_ACCEPT *)b->ptr; |
310 | 311 | ||
311 | while (b->next_bio == NULL) | 312 | while (b->next_bio == NULL) { |
312 | { | 313 | ret = acpt_state(b, data); |
313 | ret=acpt_state(b,data); | 314 | if (ret <= 0) |
314 | if (ret <= 0) return(ret); | 315 | return (ret); |
315 | } | 316 | } |
316 | 317 | ||
317 | ret=BIO_read(b->next_bio,out,outl); | 318 | ret = BIO_read(b->next_bio, out, outl); |
318 | BIO_copy_next_retry(b); | 319 | BIO_copy_next_retry(b); |
319 | return(ret); | 320 | return (ret); |
320 | } | 321 | } |
321 | 322 | ||
322 | static int acpt_write(BIO *b, const char *in, int inl) | 323 | static int |
323 | { | 324 | acpt_write(BIO *b, const char *in, int inl) |
325 | { | ||
324 | int ret; | 326 | int ret; |
325 | BIO_ACCEPT *data; | 327 | BIO_ACCEPT *data; |
326 | 328 | ||
327 | BIO_clear_retry_flags(b); | 329 | BIO_clear_retry_flags(b); |
328 | data=(BIO_ACCEPT *)b->ptr; | 330 | data = (BIO_ACCEPT *)b->ptr; |
329 | 331 | ||
330 | while (b->next_bio == NULL) | 332 | while (b->next_bio == NULL) { |
331 | { | 333 | ret = acpt_state(b, data); |
332 | ret=acpt_state(b,data); | 334 | if (ret <= 0) |
333 | if (ret <= 0) return(ret); | 335 | return (ret); |
334 | } | 336 | } |
335 | 337 | ||
336 | ret=BIO_write(b->next_bio,in,inl); | 338 | ret = BIO_write(b->next_bio, in, inl); |
337 | BIO_copy_next_retry(b); | 339 | BIO_copy_next_retry(b); |
338 | return(ret); | 340 | return (ret); |
339 | } | 341 | } |
340 | 342 | ||
341 | static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr) | 343 | static long |
342 | { | 344 | acpt_ctrl(BIO *b, int cmd, long num, void *ptr) |
345 | { | ||
343 | int *ip; | 346 | int *ip; |
344 | long ret=1; | 347 | long ret = 1; |
345 | BIO_ACCEPT *data; | 348 | BIO_ACCEPT *data; |
346 | char **pp; | 349 | char **pp; |
347 | 350 | ||
348 | data=(BIO_ACCEPT *)b->ptr; | 351 | data = (BIO_ACCEPT *)b->ptr; |
349 | 352 | ||
350 | switch (cmd) | 353 | switch (cmd) { |
351 | { | ||
352 | case BIO_CTRL_RESET: | 354 | case BIO_CTRL_RESET: |
353 | ret=0; | 355 | ret = 0; |
354 | data->state=ACPT_S_BEFORE; | 356 | data->state = ACPT_S_BEFORE; |
355 | acpt_close_socket(b); | 357 | acpt_close_socket(b); |
356 | b->flags=0; | 358 | b->flags = 0; |
357 | break; | 359 | break; |
358 | case BIO_C_DO_STATE_MACHINE: | 360 | case BIO_C_DO_STATE_MACHINE: |
359 | /* use this one to start the connection */ | 361 | /* use this one to start the connection */ |
360 | ret=(long)acpt_state(b,data); | 362 | ret = (long)acpt_state(b, data); |
361 | break; | 363 | break; |
362 | case BIO_C_SET_ACCEPT: | 364 | case BIO_C_SET_ACCEPT: |
363 | if (ptr != NULL) | 365 | if (ptr != NULL) { |
364 | { | 366 | if (num == 0) { |
365 | if (num == 0) | 367 | b->init = 1; |
366 | { | ||
367 | b->init=1; | ||
368 | if (data->param_addr != NULL) | 368 | if (data->param_addr != NULL) |
369 | OPENSSL_free(data->param_addr); | 369 | OPENSSL_free(data->param_addr); |
370 | data->param_addr=BUF_strdup(ptr); | 370 | data->param_addr = BUF_strdup(ptr); |
371 | } | 371 | } else if (num == 1) { |
372 | else if (num == 1) | 372 | data->accept_nbio = (ptr != NULL); |
373 | { | 373 | } else if (num == 2) { |
374 | data->accept_nbio=(ptr != NULL); | ||
375 | } | ||
376 | else if (num == 2) | ||
377 | { | ||
378 | if (data->bio_chain != NULL) | 374 | if (data->bio_chain != NULL) |
379 | BIO_free(data->bio_chain); | 375 | BIO_free(data->bio_chain); |
380 | data->bio_chain=(BIO *)ptr; | 376 | data->bio_chain = (BIO *)ptr; |
381 | } | ||
382 | } | 377 | } |
378 | } | ||
383 | break; | 379 | break; |
384 | case BIO_C_SET_NBIO: | 380 | case BIO_C_SET_NBIO: |
385 | data->nbio=(int)num; | 381 | data->nbio = (int)num; |
386 | break; | 382 | break; |
387 | case BIO_C_SET_FD: | 383 | case BIO_C_SET_FD: |
388 | b->init=1; | 384 | b->init = 1; |
389 | b->num= *((int *)ptr); | 385 | b->num= *((int *)ptr); |
390 | data->accept_sock=b->num; | 386 | data->accept_sock = b->num; |
391 | data->state=ACPT_S_GET_ACCEPT_SOCKET; | 387 | data->state = ACPT_S_GET_ACCEPT_SOCKET; |
392 | b->shutdown=(int)num; | 388 | b->shutdown = (int)num; |
393 | b->init=1; | 389 | b->init = 1; |
394 | break; | 390 | break; |
395 | case BIO_C_GET_FD: | 391 | case BIO_C_GET_FD: |
396 | if (b->init) | 392 | if (b->init) { |
397 | { | 393 | ip = (int *)ptr; |
398 | ip=(int *)ptr; | ||
399 | if (ip != NULL) | 394 | if (ip != NULL) |
400 | *ip=data->accept_sock; | 395 | *ip = data->accept_sock; |
401 | ret=data->accept_sock; | 396 | ret = data->accept_sock; |
402 | } | 397 | } else |
403 | else | 398 | ret = -1; |
404 | ret= -1; | ||
405 | break; | 399 | break; |
406 | case BIO_C_GET_ACCEPT: | 400 | case BIO_C_GET_ACCEPT: |
407 | if (b->init) | 401 | if (b->init) { |
408 | { | 402 | if (ptr != NULL) { |
409 | if (ptr != NULL) | 403 | pp = (char **)ptr; |
410 | { | 404 | *pp = data->param_addr; |
411 | pp=(char **)ptr; | 405 | } else |
412 | *pp=data->param_addr; | 406 | ret = -1; |
413 | } | 407 | } else |
414 | else | 408 | ret = -1; |
415 | ret= -1; | ||
416 | } | ||
417 | else | ||
418 | ret= -1; | ||
419 | break; | 409 | break; |
420 | case BIO_CTRL_GET_CLOSE: | 410 | case BIO_CTRL_GET_CLOSE: |
421 | ret=b->shutdown; | 411 | ret = b->shutdown; |
422 | break; | 412 | break; |
423 | case BIO_CTRL_SET_CLOSE: | 413 | case BIO_CTRL_SET_CLOSE: |
424 | b->shutdown=(int)num; | 414 | b->shutdown = (int)num; |
425 | break; | 415 | break; |
426 | case BIO_CTRL_PENDING: | 416 | case BIO_CTRL_PENDING: |
427 | case BIO_CTRL_WPENDING: | 417 | case BIO_CTRL_WPENDING: |
428 | ret=0; | 418 | ret = 0; |
429 | break; | 419 | break; |
430 | case BIO_CTRL_FLUSH: | 420 | case BIO_CTRL_FLUSH: |
431 | break; | 421 | break; |
432 | case BIO_C_SET_BIND_MODE: | 422 | case BIO_C_SET_BIND_MODE: |
433 | data->bind_mode=(int)num; | 423 | data->bind_mode = (int)num; |
434 | break; | 424 | break; |
435 | case BIO_C_GET_BIND_MODE: | 425 | case BIO_C_GET_BIND_MODE: |
436 | ret=(long)data->bind_mode; | 426 | ret = (long)data->bind_mode; |
437 | break; | 427 | break; |
438 | case BIO_CTRL_DUP: | 428 | case BIO_CTRL_DUP: |
439 | /* dbio=(BIO *)ptr; | 429 | /* dbio=(BIO *)ptr; |
@@ -441,38 +431,41 @@ static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
441 | BIO_set_port(dbio,data->param_port); | 431 | BIO_set_port(dbio,data->param_port); |
442 | if (data->param_hostname) | 432 | if (data->param_hostname) |
443 | BIO_set_hostname(dbio,data->param_hostname); | 433 | BIO_set_hostname(dbio,data->param_hostname); |
444 | BIO_set_nbio(dbio,data->nbio); */ | 434 | BIO_set_nbio(dbio,data->nbio); |
435 | */ | ||
445 | break; | 436 | break; |
446 | 437 | ||
447 | default: | 438 | default: |
448 | ret=0; | 439 | ret = 0; |
449 | break; | 440 | break; |
450 | } | ||
451 | return(ret); | ||
452 | } | 441 | } |
453 | 442 | return (ret); | |
454 | static int acpt_puts(BIO *bp, const char *str) | 443 | } |
455 | { | 444 | |
456 | int n,ret; | 445 | static int |
457 | 446 | acpt_puts(BIO *bp, const char *str) | |
458 | n=strlen(str); | 447 | { |
459 | ret=acpt_write(bp,str,n); | 448 | int n, ret; |
460 | return(ret); | 449 | |
461 | } | 450 | n = strlen(str); |
462 | 451 | ret = acpt_write(bp, str, n); | |
463 | BIO *BIO_new_accept(char *str) | 452 | return (ret); |
464 | { | 453 | } |
454 | |||
455 | BIO | ||
456 | *BIO_new_accept(char *str) | ||
457 | { | ||
465 | BIO *ret; | 458 | BIO *ret; |
466 | 459 | ||
467 | ret=BIO_new(BIO_s_accept()); | 460 | ret = BIO_new(BIO_s_accept()); |
468 | if (ret == NULL) return(NULL); | 461 | if (ret == NULL) |
469 | if (BIO_set_accept_port(ret,str)) | 462 | return (NULL); |
470 | return(ret); | 463 | if (BIO_set_accept_port(ret, str)) |
471 | else | 464 | return (ret); |
472 | { | 465 | else { |
473 | BIO_free(ret); | 466 | BIO_free(ret); |
474 | return(NULL); | 467 | return (NULL); |
475 | } | ||
476 | } | 468 | } |
469 | } | ||
477 | 470 | ||
478 | #endif | 471 | #endif |
diff --git a/src/lib/libcrypto/bio/bss_bio.c b/src/lib/libcrypto/bio/bss_bio.c index 52ef0ebcb3..a74fcfdabc 100644 --- a/src/lib/libcrypto/bio/bss_bio.c +++ b/src/lib/libcrypto/bio/bss_bio.c | |||
@@ -103,8 +103,7 @@ static int bio_puts(BIO *bio, const char *str); | |||
103 | static int bio_make_pair(BIO *bio1, BIO *bio2); | 103 | static int bio_make_pair(BIO *bio1, BIO *bio2); |
104 | static void bio_destroy_pair(BIO *bio); | 104 | static void bio_destroy_pair(BIO *bio); |
105 | 105 | ||
106 | static BIO_METHOD methods_biop = | 106 | static BIO_METHOD methods_biop = { |
107 | { | ||
108 | BIO_TYPE_BIO, | 107 | BIO_TYPE_BIO, |
109 | "BIO pair", | 108 | "BIO pair", |
110 | bio_write, | 109 | bio_write, |
@@ -117,50 +116,51 @@ static BIO_METHOD methods_biop = | |||
117 | NULL /* no bio_callback_ctrl */ | 116 | NULL /* no bio_callback_ctrl */ |
118 | }; | 117 | }; |
119 | 118 | ||
120 | BIO_METHOD *BIO_s_bio(void) | 119 | BIO_METHOD |
121 | { | 120 | *BIO_s_bio(void) |
121 | { | ||
122 | return &methods_biop; | 122 | return &methods_biop; |
123 | } | 123 | } |
124 | |||
125 | struct bio_bio_st { | ||
126 | BIO *peer; /* NULL if buf == NULL. | ||
127 | * If peer != NULL, then peer->ptr is also a bio_bio_st, | ||
128 | * and its "peer" member points back to us. | ||
129 | * peer != NULL iff init != 0 in the BIO. */ | ||
124 | 130 | ||
125 | struct bio_bio_st | ||
126 | { | ||
127 | BIO *peer; /* NULL if buf == NULL. | ||
128 | * If peer != NULL, then peer->ptr is also a bio_bio_st, | ||
129 | * and its "peer" member points back to us. | ||
130 | * peer != NULL iff init != 0 in the BIO. */ | ||
131 | |||
132 | /* This is for what we write (i.e. reading uses peer's struct): */ | 131 | /* This is for what we write (i.e. reading uses peer's struct): */ |
133 | int closed; /* valid iff peer != NULL */ | 132 | int closed; /* valid iff peer != NULL */ |
134 | size_t len; /* valid iff buf != NULL; 0 if peer == NULL */ | 133 | size_t len; /* valid iff buf != NULL; 0 if peer == NULL */ |
135 | size_t offset; /* valid iff buf != NULL; 0 if len == 0 */ | 134 | size_t offset; /* valid iff buf != NULL; 0 if len == 0 */ |
136 | size_t size; | 135 | size_t size; |
137 | char *buf; /* "size" elements (if != NULL) */ | 136 | char *buf; /* "size" elements (if != NULL) */ |
138 | 137 | ||
139 | size_t request; /* valid iff peer != NULL; 0 if len != 0, | 138 | size_t request; /* valid iff peer != NULL; 0 if len != 0, |
140 | * otherwise set by peer to number of bytes | 139 | * otherwise set by peer to number of bytes |
141 | * it (unsuccessfully) tried to read, | 140 | * it (unsuccessfully) tried to read, |
142 | * never more than buffer space (size-len) warrants. */ | 141 | * never more than buffer space (size-len) warrants. */ |
143 | }; | 142 | }; |
144 | 143 | ||
145 | static int bio_new(BIO *bio) | 144 | static int |
146 | { | 145 | bio_new(BIO *bio) |
146 | { | ||
147 | struct bio_bio_st *b; | 147 | struct bio_bio_st *b; |
148 | 148 | ||
149 | b = OPENSSL_malloc(sizeof *b); | 149 | b = OPENSSL_malloc(sizeof *b); |
150 | if (b == NULL) | 150 | if (b == NULL) |
151 | return 0; | 151 | return 0; |
152 | 152 | ||
153 | b->peer = NULL; | 153 | b->peer = NULL; |
154 | b->size = 17*1024; /* enough for one TLS record (just a default) */ | 154 | b->size = 17 * 1024; /* enough for one TLS record (just a default) */ |
155 | b->buf = NULL; | 155 | b->buf = NULL; |
156 | 156 | ||
157 | bio->ptr = b; | 157 | bio->ptr = b; |
158 | return 1; | 158 | return 1; |
159 | } | 159 | } |
160 | 160 | ||
161 | 161 | static int | |
162 | static int bio_free(BIO *bio) | 162 | bio_free(BIO *bio) |
163 | { | 163 | { |
164 | struct bio_bio_st *b; | 164 | struct bio_bio_st *b; |
165 | 165 | ||
166 | if (bio == NULL) | 166 | if (bio == NULL) |
@@ -171,21 +171,21 @@ static int bio_free(BIO *bio) | |||
171 | 171 | ||
172 | if (b->peer) | 172 | if (b->peer) |
173 | bio_destroy_pair(bio); | 173 | bio_destroy_pair(bio); |
174 | 174 | ||
175 | if (b->buf != NULL) | 175 | if (b->buf != NULL) { |
176 | { | ||
177 | OPENSSL_free(b->buf); | 176 | OPENSSL_free(b->buf); |
178 | } | 177 | } |
179 | 178 | ||
180 | OPENSSL_free(b); | 179 | OPENSSL_free(b); |
181 | 180 | ||
182 | return 1; | 181 | return 1; |
183 | } | 182 | } |
184 | 183 | ||
185 | 184 | ||
186 | 185 | ||
187 | static int bio_read(BIO *bio, char *buf, int size_) | 186 | static int |
188 | { | 187 | bio_read(BIO *bio, char *buf, int size_) |
188 | { | ||
189 | size_t size = size_; | 189 | size_t size = size_; |
190 | size_t rest; | 190 | size_t rest; |
191 | struct bio_bio_st *b, *peer_b; | 191 | struct bio_bio_st *b, *peer_b; |
@@ -207,12 +207,10 @@ static int bio_read(BIO *bio, char *buf, int size_) | |||
207 | if (buf == NULL || size == 0) | 207 | if (buf == NULL || size == 0) |
208 | return 0; | 208 | return 0; |
209 | 209 | ||
210 | if (peer_b->len == 0) | 210 | if (peer_b->len == 0) { |
211 | { | ||
212 | if (peer_b->closed) | 211 | if (peer_b->closed) |
213 | return 0; /* writer has closed, and no data is left */ | 212 | return 0; /* writer has closed, and no data is left */ |
214 | else | 213 | else { |
215 | { | ||
216 | BIO_set_retry_read(bio); /* buffer is empty */ | 214 | BIO_set_retry_read(bio); /* buffer is empty */ |
217 | if (size <= peer_b->size) | 215 | if (size <= peer_b->size) |
218 | peer_b->request = size; | 216 | peer_b->request = size; |
@@ -221,22 +219,22 @@ static int bio_read(BIO *bio, char *buf, int size_) | |||
221 | * deliver in one write */ | 219 | * deliver in one write */ |
222 | peer_b->request = peer_b->size; | 220 | peer_b->request = peer_b->size; |
223 | return -1; | 221 | return -1; |
224 | } | ||
225 | } | 222 | } |
223 | } | ||
226 | 224 | ||
227 | /* we can read */ | 225 | /* we can read */ |
228 | if (peer_b->len < size) | 226 | if (peer_b->len < size) |
229 | size = peer_b->len; | 227 | size = peer_b->len; |
230 | 228 | ||
231 | /* now read "size" bytes */ | 229 | /* now read "size" bytes */ |
232 | 230 | ||
233 | rest = size; | 231 | rest = size; |
234 | 232 | ||
235 | assert(rest > 0); | 233 | assert(rest > 0); |
236 | do /* one or two iterations */ | 234 | do /* one or two iterations */ |
237 | { | 235 | { |
238 | size_t chunk; | 236 | size_t chunk; |
239 | 237 | ||
240 | assert(rest <= peer_b->len); | 238 | assert(rest <= peer_b->len); |
241 | if (peer_b->offset + rest <= peer_b->size) | 239 | if (peer_b->offset + rest <= peer_b->size) |
242 | chunk = rest; | 240 | chunk = rest; |
@@ -244,30 +242,26 @@ static int bio_read(BIO *bio, char *buf, int size_) | |||
244 | /* wrap around ring buffer */ | 242 | /* wrap around ring buffer */ |
245 | chunk = peer_b->size - peer_b->offset; | 243 | chunk = peer_b->size - peer_b->offset; |
246 | assert(peer_b->offset + chunk <= peer_b->size); | 244 | assert(peer_b->offset + chunk <= peer_b->size); |
247 | 245 | ||
248 | memcpy(buf, peer_b->buf + peer_b->offset, chunk); | 246 | memcpy(buf, peer_b->buf + peer_b->offset, chunk); |
249 | 247 | ||
250 | peer_b->len -= chunk; | 248 | peer_b->len -= chunk; |
251 | if (peer_b->len) | 249 | if (peer_b->len) { |
252 | { | ||
253 | peer_b->offset += chunk; | 250 | peer_b->offset += chunk; |
254 | assert(peer_b->offset <= peer_b->size); | 251 | assert(peer_b->offset <= peer_b->size); |
255 | if (peer_b->offset == peer_b->size) | 252 | if (peer_b->offset == peer_b->size) |
256 | peer_b->offset = 0; | 253 | peer_b->offset = 0; |
257 | buf += chunk; | 254 | buf += chunk; |
258 | } | 255 | } else { |
259 | else | ||
260 | { | ||
261 | /* buffer now empty, no need to advance "buf" */ | 256 | /* buffer now empty, no need to advance "buf" */ |
262 | assert(chunk == rest); | 257 | assert(chunk == rest); |
263 | peer_b->offset = 0; | 258 | peer_b->offset = 0; |
264 | } | ||
265 | rest -= chunk; | ||
266 | } | 259 | } |
267 | while (rest); | 260 | rest -= chunk; |
268 | 261 | } while (rest); | |
262 | |||
269 | return size; | 263 | return size; |
270 | } | 264 | } |
271 | 265 | ||
272 | /* non-copying interface: provide pointer to available data in buffer | 266 | /* non-copying interface: provide pointer to available data in buffer |
273 | * bio_nread0: return number of available bytes | 267 | * bio_nread0: return number of available bytes |
@@ -277,32 +271,32 @@ static int bio_read(BIO *bio, char *buf, int size_) | |||
277 | */ | 271 | */ |
278 | /* WARNING: The non-copying interface is largely untested as of yet | 272 | /* WARNING: The non-copying interface is largely untested as of yet |
279 | * and may contain bugs. */ | 273 | * and may contain bugs. */ |
280 | static ossl_ssize_t bio_nread0(BIO *bio, char **buf) | 274 | static ossl_ssize_t |
281 | { | 275 | bio_nread0(BIO *bio, char **buf) |
276 | { | ||
282 | struct bio_bio_st *b, *peer_b; | 277 | struct bio_bio_st *b, *peer_b; |
283 | ossl_ssize_t num; | 278 | ossl_ssize_t num; |
284 | 279 | ||
285 | BIO_clear_retry_flags(bio); | 280 | BIO_clear_retry_flags(bio); |
286 | 281 | ||
287 | if (!bio->init) | 282 | if (!bio->init) |
288 | return 0; | 283 | return 0; |
289 | 284 | ||
290 | b = bio->ptr; | 285 | b = bio->ptr; |
291 | assert(b != NULL); | 286 | assert(b != NULL); |
292 | assert(b->peer != NULL); | 287 | assert(b->peer != NULL); |
293 | peer_b = b->peer->ptr; | 288 | peer_b = b->peer->ptr; |
294 | assert(peer_b != NULL); | 289 | assert(peer_b != NULL); |
295 | assert(peer_b->buf != NULL); | 290 | assert(peer_b->buf != NULL); |
296 | 291 | ||
297 | peer_b->request = 0; | 292 | peer_b->request = 0; |
298 | 293 | ||
299 | if (peer_b->len == 0) | 294 | if (peer_b->len == 0) { |
300 | { | ||
301 | char dummy; | 295 | char dummy; |
302 | 296 | ||
303 | /* avoid code duplication -- nothing available for reading */ | 297 | /* avoid code duplication -- nothing available for reading */ |
304 | return bio_read(bio, &dummy, 1); /* returns 0 or -1 */ | 298 | return bio_read(bio, &dummy, 1); /* returns 0 or -1 */ |
305 | } | 299 | } |
306 | 300 | ||
307 | num = peer_b->len; | 301 | num = peer_b->len; |
308 | if (peer_b->size < peer_b->offset + num) | 302 | if (peer_b->size < peer_b->offset + num) |
@@ -313,10 +307,11 @@ static ossl_ssize_t bio_nread0(BIO *bio, char **buf) | |||
313 | if (buf != NULL) | 307 | if (buf != NULL) |
314 | *buf = peer_b->buf + peer_b->offset; | 308 | *buf = peer_b->buf + peer_b->offset; |
315 | return num; | 309 | return num; |
316 | } | 310 | } |
317 | 311 | ||
318 | static ossl_ssize_t bio_nread(BIO *bio, char **buf, size_t num_) | 312 | static ossl_ssize_t |
319 | { | 313 | bio_nread(BIO *bio, char **buf, size_t num_) |
314 | { | ||
320 | struct bio_bio_st *b, *peer_b; | 315 | struct bio_bio_st *b, *peer_b; |
321 | ossl_ssize_t num, available; | 316 | ossl_ssize_t num, available; |
322 | 317 | ||
@@ -335,22 +330,21 @@ static ossl_ssize_t bio_nread(BIO *bio, char **buf, size_t num_) | |||
335 | peer_b = b->peer->ptr; | 330 | peer_b = b->peer->ptr; |
336 | 331 | ||
337 | peer_b->len -= num; | 332 | peer_b->len -= num; |
338 | if (peer_b->len) | 333 | if (peer_b->len) { |
339 | { | ||
340 | peer_b->offset += num; | 334 | peer_b->offset += num; |
341 | assert(peer_b->offset <= peer_b->size); | 335 | assert(peer_b->offset <= peer_b->size); |
342 | if (peer_b->offset == peer_b->size) | 336 | if (peer_b->offset == peer_b->size) |
343 | peer_b->offset = 0; | 337 | peer_b->offset = 0; |
344 | } | 338 | } else |
345 | else | ||
346 | peer_b->offset = 0; | 339 | peer_b->offset = 0; |
347 | 340 | ||
348 | return num; | 341 | return num; |
349 | } | 342 | } |
350 | 343 | ||
351 | 344 | ||
352 | static int bio_write(BIO *bio, const char *buf, int num_) | 345 | static int |
353 | { | 346 | bio_write(BIO *bio, const char *buf, int num_) |
347 | { | ||
354 | size_t num = num_; | 348 | size_t num = num_; |
355 | size_t rest; | 349 | size_t rest; |
356 | struct bio_bio_st *b; | 350 | struct bio_bio_st *b; |
@@ -360,38 +354,37 @@ static int bio_write(BIO *bio, const char *buf, int num_) | |||
360 | if (!bio->init || buf == NULL || num == 0) | 354 | if (!bio->init || buf == NULL || num == 0) |
361 | return 0; | 355 | return 0; |
362 | 356 | ||
363 | b = bio->ptr; | 357 | b = bio->ptr; |
358 | |||
364 | assert(b != NULL); | 359 | assert(b != NULL); |
365 | assert(b->peer != NULL); | 360 | assert(b->peer != NULL); |
366 | assert(b->buf != NULL); | 361 | assert(b->buf != NULL); |
367 | 362 | ||
368 | b->request = 0; | 363 | b->request = 0; |
369 | if (b->closed) | 364 | if (b->closed) { |
370 | { | ||
371 | /* we already closed */ | 365 | /* we already closed */ |
372 | BIOerr(BIO_F_BIO_WRITE, BIO_R_BROKEN_PIPE); | 366 | BIOerr(BIO_F_BIO_WRITE, BIO_R_BROKEN_PIPE); |
373 | return -1; | 367 | return -1; |
374 | } | 368 | } |
375 | 369 | ||
376 | assert(b->len <= b->size); | 370 | assert(b->len <= b->size); |
377 | 371 | ||
378 | if (b->len == b->size) | 372 | if (b->len == b->size) { |
379 | { | ||
380 | BIO_set_retry_write(bio); /* buffer is full */ | 373 | BIO_set_retry_write(bio); /* buffer is full */ |
381 | return -1; | 374 | return -1; |
382 | } | 375 | } |
383 | 376 | ||
384 | /* we can write */ | 377 | /* we can write */ |
385 | if (num > b->size - b->len) | 378 | if (num > b->size - b->len) |
386 | num = b->size - b->len; | 379 | num = b->size - b->len; |
387 | 380 | ||
388 | /* now write "num" bytes */ | 381 | /* now write "num" bytes */ |
389 | 382 | ||
390 | rest = num; | 383 | rest = num; |
391 | 384 | ||
392 | assert(rest > 0); | 385 | assert(rest > 0); |
393 | do /* one or two iterations */ | 386 | do /* one or two iterations */ |
394 | { | 387 | { |
395 | size_t write_offset; | 388 | size_t write_offset; |
396 | size_t chunk; | 389 | size_t chunk; |
397 | 390 | ||
@@ -407,20 +400,19 @@ static int bio_write(BIO *bio, const char *buf, int num_) | |||
407 | else | 400 | else |
408 | /* wrap around ring buffer */ | 401 | /* wrap around ring buffer */ |
409 | chunk = b->size - write_offset; | 402 | chunk = b->size - write_offset; |
410 | 403 | ||
411 | memcpy(b->buf + write_offset, buf, chunk); | 404 | memcpy(b->buf + write_offset, buf, chunk); |
412 | 405 | ||
413 | b->len += chunk; | 406 | b->len += chunk; |
414 | 407 | ||
415 | assert(b->len <= b->size); | 408 | assert(b->len <= b->size); |
416 | 409 | ||
417 | rest -= chunk; | 410 | rest -= chunk; |
418 | buf += chunk; | 411 | buf += chunk; |
419 | } | 412 | } while (rest); |
420 | while (rest); | ||
421 | 413 | ||
422 | return num; | 414 | return num; |
423 | } | 415 | } |
424 | 416 | ||
425 | /* non-copying interface: provide pointer to region to write to | 417 | /* non-copying interface: provide pointer to region to write to |
426 | * bio_nwrite0: check how much space is available | 418 | * bio_nwrite0: check how much space is available |
@@ -428,8 +420,9 @@ static int bio_write(BIO *bio, const char *buf, int num_) | |||
428 | * (example usage: bio_nwrite0(), write to buffer, bio_nwrite() | 420 | * (example usage: bio_nwrite0(), write to buffer, bio_nwrite() |
429 | * or just bio_nwrite(), write to buffer) | 421 | * or just bio_nwrite(), write to buffer) |
430 | */ | 422 | */ |
431 | static ossl_ssize_t bio_nwrite0(BIO *bio, char **buf) | 423 | static ossl_ssize_t |
432 | { | 424 | bio_nwrite0(BIO *bio, char **buf) |
425 | { | ||
433 | struct bio_bio_st *b; | 426 | struct bio_bio_st *b; |
434 | size_t num; | 427 | size_t num; |
435 | size_t write_offset; | 428 | size_t write_offset; |
@@ -439,25 +432,24 @@ static ossl_ssize_t bio_nwrite0(BIO *bio, char **buf) | |||
439 | if (!bio->init) | 432 | if (!bio->init) |
440 | return 0; | 433 | return 0; |
441 | 434 | ||
442 | b = bio->ptr; | 435 | b = bio->ptr; |
436 | |||
443 | assert(b != NULL); | 437 | assert(b != NULL); |
444 | assert(b->peer != NULL); | 438 | assert(b->peer != NULL); |
445 | assert(b->buf != NULL); | 439 | assert(b->buf != NULL); |
446 | 440 | ||
447 | b->request = 0; | 441 | b->request = 0; |
448 | if (b->closed) | 442 | if (b->closed) { |
449 | { | ||
450 | BIOerr(BIO_F_BIO_NWRITE0, BIO_R_BROKEN_PIPE); | 443 | BIOerr(BIO_F_BIO_NWRITE0, BIO_R_BROKEN_PIPE); |
451 | return -1; | 444 | return -1; |
452 | } | 445 | } |
453 | 446 | ||
454 | assert(b->len <= b->size); | 447 | assert(b->len <= b->size); |
455 | 448 | ||
456 | if (b->len == b->size) | 449 | if (b->len == b->size) { |
457 | { | ||
458 | BIO_set_retry_write(bio); | 450 | BIO_set_retry_write(bio); |
459 | return -1; | 451 | return -1; |
460 | } | 452 | } |
461 | 453 | ||
462 | num = b->size - b->len; | 454 | num = b->size - b->len; |
463 | write_offset = b->offset + b->len; | 455 | write_offset = b->offset + b->len; |
@@ -474,10 +466,11 @@ static ossl_ssize_t bio_nwrite0(BIO *bio, char **buf) | |||
474 | assert(write_offset + num <= b->size); | 466 | assert(write_offset + num <= b->size); |
475 | 467 | ||
476 | return num; | 468 | return num; |
477 | } | 469 | } |
478 | 470 | ||
479 | static ossl_ssize_t bio_nwrite(BIO *bio, char **buf, size_t num_) | 471 | static ossl_ssize_t |
480 | { | 472 | bio_nwrite(BIO *bio, char **buf, size_t num_) |
473 | { | ||
481 | struct bio_bio_st *b; | 474 | struct bio_bio_st *b; |
482 | ossl_ssize_t num, space; | 475 | ossl_ssize_t num, space; |
483 | 476 | ||
@@ -497,46 +490,39 @@ static ossl_ssize_t bio_nwrite(BIO *bio, char **buf, size_t num_) | |||
497 | assert(b->len <= b->size); | 490 | assert(b->len <= b->size); |
498 | 491 | ||
499 | return num; | 492 | return num; |
500 | } | 493 | } |
501 | 494 | ||
502 | 495 | ||
503 | static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | 496 | static long |
504 | { | 497 | bio_ctrl(BIO *bio, int cmd, long num, void *ptr) |
498 | { | ||
505 | long ret; | 499 | long ret; |
506 | struct bio_bio_st *b = bio->ptr; | 500 | struct bio_bio_st *b = bio->ptr; |
507 | 501 | ||
508 | assert(b != NULL); | 502 | assert(b != NULL); |
509 | 503 | ||
510 | switch (cmd) | 504 | switch (cmd) { |
511 | { | 505 | /* specific CTRL codes */ |
512 | /* specific CTRL codes */ | ||
513 | 506 | ||
514 | case BIO_C_SET_WRITE_BUF_SIZE: | 507 | case BIO_C_SET_WRITE_BUF_SIZE: |
515 | if (b->peer) | 508 | if (b->peer) { |
516 | { | ||
517 | BIOerr(BIO_F_BIO_CTRL, BIO_R_IN_USE); | 509 | BIOerr(BIO_F_BIO_CTRL, BIO_R_IN_USE); |
518 | ret = 0; | 510 | ret = 0; |
519 | } | 511 | } else if (num == 0) { |
520 | else if (num == 0) | ||
521 | { | ||
522 | BIOerr(BIO_F_BIO_CTRL, BIO_R_INVALID_ARGUMENT); | 512 | BIOerr(BIO_F_BIO_CTRL, BIO_R_INVALID_ARGUMENT); |
523 | ret = 0; | 513 | ret = 0; |
524 | } | 514 | } else { |
525 | else | ||
526 | { | ||
527 | size_t new_size = num; | 515 | size_t new_size = num; |
528 | 516 | ||
529 | if (b->size != new_size) | 517 | if (b->size != new_size) { |
530 | { | 518 | if (b->buf) { |
531 | if (b->buf) | ||
532 | { | ||
533 | OPENSSL_free(b->buf); | 519 | OPENSSL_free(b->buf); |
534 | b->buf = NULL; | 520 | b->buf = NULL; |
535 | } | ||
536 | b->size = new_size; | ||
537 | } | 521 | } |
538 | ret = 1; | 522 | b->size = new_size; |
539 | } | 523 | } |
524 | ret = 1; | ||
525 | } | ||
540 | break; | 526 | break; |
541 | 527 | ||
542 | case BIO_C_GET_WRITE_BUF_SIZE: | 528 | case BIO_C_GET_WRITE_BUF_SIZE: |
@@ -545,15 +531,15 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | |||
545 | 531 | ||
546 | case BIO_C_MAKE_BIO_PAIR: | 532 | case BIO_C_MAKE_BIO_PAIR: |
547 | { | 533 | { |
548 | BIO *other_bio = ptr; | 534 | BIO *other_bio = ptr; |
549 | 535 | ||
550 | if (bio_make_pair(bio, other_bio)) | 536 | if (bio_make_pair(bio, other_bio)) |
551 | ret = 1; | 537 | ret = 1; |
552 | else | 538 | else |
553 | ret = 0; | 539 | ret = 0; |
554 | } | 540 | } |
555 | break; | 541 | break; |
556 | 542 | ||
557 | case BIO_C_DESTROY_BIO_PAIR: | 543 | case BIO_C_DESTROY_BIO_PAIR: |
558 | /* Affects both BIOs in the pair -- call just once! | 544 | /* Affects both BIOs in the pair -- call just once! |
559 | * Or let BIO_free(bio1); BIO_free(bio2); do the job. */ | 545 | * Or let BIO_free(bio1); BIO_free(bio2); do the job. */ |
@@ -596,12 +582,12 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | |||
596 | /* prepare for non-copying read */ | 582 | /* prepare for non-copying read */ |
597 | ret = (long) bio_nread0(bio, ptr); | 583 | ret = (long) bio_nread0(bio, ptr); |
598 | break; | 584 | break; |
599 | 585 | ||
600 | case BIO_C_NREAD: | 586 | case BIO_C_NREAD: |
601 | /* non-copying read */ | 587 | /* non-copying read */ |
602 | ret = (long) bio_nread(bio, ptr, (size_t) num); | 588 | ret = (long) bio_nread(bio, ptr, (size_t) num); |
603 | break; | 589 | break; |
604 | 590 | ||
605 | case BIO_C_NWRITE0: | 591 | case BIO_C_NWRITE0: |
606 | /* prepare for non-copying write */ | 592 | /* prepare for non-copying write */ |
607 | ret = (long) bio_nwrite0(bio, ptr); | 593 | ret = (long) bio_nwrite0(bio, ptr); |
@@ -611,18 +597,18 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | |||
611 | /* non-copying write */ | 597 | /* non-copying write */ |
612 | ret = (long) bio_nwrite(bio, ptr, (size_t) num); | 598 | ret = (long) bio_nwrite(bio, ptr, (size_t) num); |
613 | break; | 599 | break; |
614 | |||
615 | 600 | ||
616 | /* standard CTRL codes follow */ | 601 | |
602 | /* standard CTRL codes follow */ | ||
617 | 603 | ||
618 | case BIO_CTRL_RESET: | 604 | case BIO_CTRL_RESET: |
619 | if (b->buf != NULL) | 605 | if (b->buf != NULL) { |
620 | { | ||
621 | b->len = 0; | 606 | b->len = 0; |
622 | b->offset = 0; | 607 | b->offset = 0; |
623 | } | 608 | } |
624 | ret = 0; | 609 | ret = 0; |
625 | break; | 610 | break; |
611 | |||
626 | 612 | ||
627 | case BIO_CTRL_GET_CLOSE: | 613 | case BIO_CTRL_GET_CLOSE: |
628 | ret = bio->shutdown; | 614 | ret = bio->shutdown; |
@@ -634,13 +620,11 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | |||
634 | break; | 620 | break; |
635 | 621 | ||
636 | case BIO_CTRL_PENDING: | 622 | case BIO_CTRL_PENDING: |
637 | if (b->peer != NULL) | 623 | if (b->peer != NULL) { |
638 | { | ||
639 | struct bio_bio_st *peer_b = b->peer->ptr; | 624 | struct bio_bio_st *peer_b = b->peer->ptr; |
640 | 625 | ||
641 | ret = (long) peer_b->len; | 626 | ret = (long) peer_b->len; |
642 | } | 627 | } else |
643 | else | ||
644 | ret = 0; | 628 | ret = 0; |
645 | break; | 629 | break; |
646 | 630 | ||
@@ -654,16 +638,16 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | |||
654 | case BIO_CTRL_DUP: | 638 | case BIO_CTRL_DUP: |
655 | /* See BIO_dup_chain for circumstances we have to expect. */ | 639 | /* See BIO_dup_chain for circumstances we have to expect. */ |
656 | { | 640 | { |
657 | BIO *other_bio = ptr; | 641 | BIO *other_bio = ptr; |
658 | struct bio_bio_st *other_b; | 642 | struct bio_bio_st *other_b; |
659 | 643 | ||
660 | assert(other_bio != NULL); | 644 | assert(other_bio != NULL); |
661 | other_b = other_bio->ptr; | 645 | other_b = other_bio->ptr; |
662 | assert(other_b != NULL); | 646 | assert(other_b != NULL); |
663 | 647 | ||
664 | assert(other_b->buf == NULL); /* other_bio is always fresh */ | 648 | assert(other_b->buf == NULL); /* other_bio is always fresh */ |
665 | 649 | ||
666 | other_b->size = b->size; | 650 | other_b->size = b->size; |
667 | } | 651 | } |
668 | 652 | ||
669 | ret = 1; | 653 | ret = 1; |
@@ -675,34 +659,34 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | |||
675 | 659 | ||
676 | case BIO_CTRL_EOF: | 660 | case BIO_CTRL_EOF: |
677 | { | 661 | { |
678 | BIO *other_bio = ptr; | 662 | BIO *other_bio = ptr; |
679 | 663 | ||
680 | if (other_bio) | 664 | if (other_bio) { |
681 | { | 665 | struct bio_bio_st *other_b = other_bio->ptr; |
682 | struct bio_bio_st *other_b = other_bio->ptr; | 666 | |
683 | 667 | assert(other_b != NULL); | |
684 | assert(other_b != NULL); | 668 | ret = other_b->len == 0 && other_b->closed; |
685 | ret = other_b->len == 0 && other_b->closed; | 669 | } else |
686 | } | 670 | ret = 1; |
687 | else | ||
688 | ret = 1; | ||
689 | } | 671 | } |
690 | break; | 672 | break; |
691 | 673 | ||
692 | default: | 674 | default: |
693 | ret = 0; | 675 | ret = 0; |
694 | } | ||
695 | return ret; | ||
696 | } | 676 | } |
677 | return ret; | ||
678 | } | ||
697 | 679 | ||
698 | static int bio_puts(BIO *bio, const char *str) | 680 | static int |
699 | { | 681 | bio_puts(BIO *bio, const char *str) |
682 | { | ||
700 | return bio_write(bio, str, strlen(str)); | 683 | return bio_write(bio, str, strlen(str)); |
701 | } | 684 | } |
702 | 685 | ||
703 | 686 | ||
704 | static int bio_make_pair(BIO *bio1, BIO *bio2) | 687 | static int |
705 | { | 688 | bio_make_pair(BIO *bio1, BIO *bio2) |
689 | { | ||
706 | struct bio_bio_st *b1, *b2; | 690 | struct bio_bio_st *b1, *b2; |
707 | 691 | ||
708 | assert(bio1 != NULL); | 692 | assert(bio1 != NULL); |
@@ -710,37 +694,32 @@ static int bio_make_pair(BIO *bio1, BIO *bio2) | |||
710 | 694 | ||
711 | b1 = bio1->ptr; | 695 | b1 = bio1->ptr; |
712 | b2 = bio2->ptr; | 696 | b2 = bio2->ptr; |
713 | 697 | ||
714 | if (b1->peer != NULL || b2->peer != NULL) | 698 | if (b1->peer != NULL || b2->peer != NULL) { |
715 | { | ||
716 | BIOerr(BIO_F_BIO_MAKE_PAIR, BIO_R_IN_USE); | 699 | BIOerr(BIO_F_BIO_MAKE_PAIR, BIO_R_IN_USE); |
717 | return 0; | 700 | return 0; |
718 | } | 701 | } |
719 | 702 | ||
720 | if (b1->buf == NULL) | 703 | if (b1->buf == NULL) { |
721 | { | ||
722 | b1->buf = OPENSSL_malloc(b1->size); | 704 | b1->buf = OPENSSL_malloc(b1->size); |
723 | if (b1->buf == NULL) | 705 | if (b1->buf == NULL) { |
724 | { | ||
725 | BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); | 706 | BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); |
726 | return 0; | 707 | return 0; |
727 | } | 708 | } |
728 | b1->len = 0; | 709 | b1->len = 0; |
729 | b1->offset = 0; | 710 | b1->offset = 0; |
730 | } | 711 | } |
731 | 712 | ||
732 | if (b2->buf == NULL) | 713 | if (b2->buf == NULL) { |
733 | { | ||
734 | b2->buf = OPENSSL_malloc(b2->size); | 714 | b2->buf = OPENSSL_malloc(b2->size); |
735 | if (b2->buf == NULL) | 715 | if (b2->buf == NULL) { |
736 | { | ||
737 | BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); | 716 | BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); |
738 | return 0; | 717 | return 0; |
739 | } | 718 | } |
740 | b2->len = 0; | 719 | b2->len = 0; |
741 | b2->offset = 0; | 720 | b2->offset = 0; |
742 | } | 721 | } |
743 | 722 | ||
744 | b1->peer = bio2; | 723 | b1->peer = bio2; |
745 | b1->closed = 0; | 724 | b1->closed = 0; |
746 | b1->request = 0; | 725 | b1->request = 0; |
@@ -752,18 +731,17 @@ static int bio_make_pair(BIO *bio1, BIO *bio2) | |||
752 | bio2->init = 1; | 731 | bio2->init = 1; |
753 | 732 | ||
754 | return 1; | 733 | return 1; |
755 | } | 734 | } |
756 | 735 | ||
757 | static void bio_destroy_pair(BIO *bio) | 736 | static void |
758 | { | 737 | bio_destroy_pair(BIO *bio) |
738 | { | ||
759 | struct bio_bio_st *b = bio->ptr; | 739 | struct bio_bio_st *b = bio->ptr; |
760 | 740 | ||
761 | if (b != NULL) | 741 | if (b != NULL) { |
762 | { | ||
763 | BIO *peer_bio = b->peer; | 742 | BIO *peer_bio = b->peer; |
764 | 743 | ||
765 | if (peer_bio != NULL) | 744 | if (peer_bio != NULL) { |
766 | { | ||
767 | struct bio_bio_st *peer_b = peer_bio->ptr; | 745 | struct bio_bio_st *peer_b = peer_bio->ptr; |
768 | 746 | ||
769 | assert(peer_b != NULL); | 747 | assert(peer_b != NULL); |
@@ -774,151 +752,149 @@ static void bio_destroy_pair(BIO *bio) | |||
774 | assert(peer_b->buf != NULL); | 752 | assert(peer_b->buf != NULL); |
775 | peer_b->len = 0; | 753 | peer_b->len = 0; |
776 | peer_b->offset = 0; | 754 | peer_b->offset = 0; |
777 | 755 | ||
778 | b->peer = NULL; | 756 | b->peer = NULL; |
779 | bio->init = 0; | 757 | bio->init = 0; |
780 | assert(b->buf != NULL); | 758 | assert(b->buf != NULL); |
781 | b->len = 0; | 759 | b->len = 0; |
782 | b->offset = 0; | 760 | b->offset = 0; |
783 | } | ||
784 | } | 761 | } |
785 | } | 762 | } |
786 | 763 | } | |
764 | |||
787 | 765 | ||
788 | /* Exported convenience functions */ | 766 | /* Exported convenience functions */ |
789 | int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1, | 767 | int |
790 | BIO **bio2_p, size_t writebuf2) | 768 | BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1, BIO **bio2_p, size_t writebuf2) |
791 | { | 769 | { |
792 | BIO *bio1 = NULL, *bio2 = NULL; | 770 | BIO *bio1 = NULL, *bio2 = NULL; |
793 | long r; | 771 | long r; |
794 | int ret = 0; | 772 | int ret = 0; |
795 | 773 | ||
796 | bio1 = BIO_new(BIO_s_bio()); | 774 | bio1 = BIO_new(BIO_s_bio()); |
797 | if (bio1 == NULL) | 775 | if (bio1 == NULL) |
798 | goto err; | 776 | goto err; |
799 | bio2 = BIO_new(BIO_s_bio()); | 777 | bio2 = BIO_new(BIO_s_bio()); |
800 | if (bio2 == NULL) | 778 | if (bio2 == NULL) |
801 | goto err; | 779 | goto err; |
802 | 780 | ||
803 | if (writebuf1) | 781 | if (writebuf1) { |
804 | { | 782 | r = BIO_set_write_buf_size(bio1, writebuf1); |
805 | r = BIO_set_write_buf_size(bio1, writebuf1); | 783 | if (!r) |
806 | if (!r) | 784 | goto err; |
807 | goto err; | 785 | } |
808 | } | 786 | if (writebuf2) { |
809 | if (writebuf2) | 787 | r = BIO_set_write_buf_size(bio2, writebuf2); |
810 | { | 788 | if (!r) |
811 | r = BIO_set_write_buf_size(bio2, writebuf2); | 789 | goto err; |
812 | if (!r) | ||
813 | goto err; | ||
814 | } | ||
815 | |||
816 | r = BIO_make_bio_pair(bio1, bio2); | ||
817 | if (!r) | ||
818 | goto err; | ||
819 | ret = 1; | ||
820 | |||
821 | err: | ||
822 | if (ret == 0) | ||
823 | { | ||
824 | if (bio1) | ||
825 | { | ||
826 | BIO_free(bio1); | ||
827 | bio1 = NULL; | ||
828 | } | ||
829 | if (bio2) | ||
830 | { | ||
831 | BIO_free(bio2); | ||
832 | bio2 = NULL; | ||
833 | } | ||
834 | } | ||
835 | |||
836 | *bio1_p = bio1; | ||
837 | *bio2_p = bio2; | ||
838 | return ret; | ||
839 | } | ||
840 | |||
841 | size_t BIO_ctrl_get_write_guarantee(BIO *bio) | ||
842 | { | ||
843 | return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL); | ||
844 | } | 790 | } |
845 | 791 | ||
846 | size_t BIO_ctrl_get_read_request(BIO *bio) | 792 | r = BIO_make_bio_pair(bio1, bio2); |
847 | { | 793 | if (!r) |
848 | return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL); | 794 | goto err; |
795 | ret = 1; | ||
796 | |||
797 | err: | ||
798 | if (ret == 0) { | ||
799 | if (bio1) { | ||
800 | BIO_free(bio1); | ||
801 | bio1 = NULL; | ||
802 | } | ||
803 | if (bio2) { | ||
804 | BIO_free(bio2); | ||
805 | bio2 = NULL; | ||
806 | } | ||
849 | } | 807 | } |
850 | 808 | ||
851 | int BIO_ctrl_reset_read_request(BIO *bio) | 809 | *bio1_p = bio1; |
852 | { | 810 | *bio2_p = bio2; |
811 | return ret; | ||
812 | } | ||
813 | |||
814 | size_t | ||
815 | BIO_ctrl_get_write_guarantee(BIO *bio) | ||
816 | { | ||
817 | return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL); | ||
818 | } | ||
819 | |||
820 | size_t | ||
821 | BIO_ctrl_get_read_request(BIO *bio) | ||
822 | { | ||
823 | return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL); | ||
824 | } | ||
825 | |||
826 | int | ||
827 | BIO_ctrl_reset_read_request(BIO *bio) | ||
828 | { | ||
853 | return (BIO_ctrl(bio, BIO_C_RESET_READ_REQUEST, 0, NULL) != 0); | 829 | return (BIO_ctrl(bio, BIO_C_RESET_READ_REQUEST, 0, NULL) != 0); |
854 | } | 830 | } |
855 | 831 | ||
856 | 832 | ||
857 | /* BIO_nread0/nread/nwrite0/nwrite are available only for BIO pairs for now | 833 | /* BIO_nread0/nread/nwrite0/nwrite are available only for BIO pairs for now |
858 | * (conceivably some other BIOs could allow non-copying reads and writes too.) | 834 | * (conceivably some other BIOs could allow non-copying reads and writes too.) |
859 | */ | 835 | */ |
860 | int BIO_nread0(BIO *bio, char **buf) | 836 | int |
861 | { | 837 | BIO_nread0(BIO *bio, char **buf) |
838 | { | ||
862 | long ret; | 839 | long ret; |
863 | 840 | ||
864 | if (!bio->init) | 841 | if (!bio->init) { |
865 | { | ||
866 | BIOerr(BIO_F_BIO_NREAD0, BIO_R_UNINITIALIZED); | 842 | BIOerr(BIO_F_BIO_NREAD0, BIO_R_UNINITIALIZED); |
867 | return -2; | 843 | return -2; |
868 | } | 844 | } |
869 | 845 | ||
870 | ret = BIO_ctrl(bio, BIO_C_NREAD0, 0, buf); | 846 | ret = BIO_ctrl(bio, BIO_C_NREAD0, 0, buf); |
871 | if (ret > INT_MAX) | 847 | if (ret > INT_MAX) |
872 | return INT_MAX; | 848 | return INT_MAX; |
873 | else | 849 | else |
874 | return (int) ret; | 850 | return (int) ret; |
875 | } | 851 | } |
876 | 852 | ||
877 | int BIO_nread(BIO *bio, char **buf, int num) | 853 | int |
878 | { | 854 | BIO_nread(BIO *bio, char **buf, int num) |
855 | { | ||
879 | int ret; | 856 | int ret; |
880 | 857 | ||
881 | if (!bio->init) | 858 | if (!bio->init) { |
882 | { | ||
883 | BIOerr(BIO_F_BIO_NREAD, BIO_R_UNINITIALIZED); | 859 | BIOerr(BIO_F_BIO_NREAD, BIO_R_UNINITIALIZED); |
884 | return -2; | 860 | return -2; |
885 | } | 861 | } |
886 | 862 | ||
887 | ret = (int) BIO_ctrl(bio, BIO_C_NREAD, num, buf); | 863 | ret = (int) BIO_ctrl(bio, BIO_C_NREAD, num, buf); |
888 | if (ret > 0) | 864 | if (ret > 0) |
889 | bio->num_read += ret; | 865 | bio->num_read += ret; |
890 | return ret; | 866 | return ret; |
891 | } | 867 | } |
892 | 868 | ||
893 | int BIO_nwrite0(BIO *bio, char **buf) | 869 | int |
894 | { | 870 | BIO_nwrite0(BIO *bio, char **buf) |
871 | { | ||
895 | long ret; | 872 | long ret; |
896 | 873 | ||
897 | if (!bio->init) | 874 | if (!bio->init) { |
898 | { | ||
899 | BIOerr(BIO_F_BIO_NWRITE0, BIO_R_UNINITIALIZED); | 875 | BIOerr(BIO_F_BIO_NWRITE0, BIO_R_UNINITIALIZED); |
900 | return -2; | 876 | return -2; |
901 | } | 877 | } |
902 | 878 | ||
903 | ret = BIO_ctrl(bio, BIO_C_NWRITE0, 0, buf); | 879 | ret = BIO_ctrl(bio, BIO_C_NWRITE0, 0, buf); |
904 | if (ret > INT_MAX) | 880 | if (ret > INT_MAX) |
905 | return INT_MAX; | 881 | return INT_MAX; |
906 | else | 882 | else |
907 | return (int) ret; | 883 | return (int) ret; |
908 | } | 884 | } |
909 | 885 | ||
910 | int BIO_nwrite(BIO *bio, char **buf, int num) | 886 | int |
911 | { | 887 | BIO_nwrite(BIO *bio, char **buf, int num) |
888 | { | ||
912 | int ret; | 889 | int ret; |
913 | 890 | ||
914 | if (!bio->init) | 891 | if (!bio->init) { |
915 | { | ||
916 | BIOerr(BIO_F_BIO_NWRITE, BIO_R_UNINITIALIZED); | 892 | BIOerr(BIO_F_BIO_NWRITE, BIO_R_UNINITIALIZED); |
917 | return -2; | 893 | return -2; |
918 | } | 894 | } |
919 | 895 | ||
920 | ret = BIO_ctrl(bio, BIO_C_NWRITE, num, buf); | 896 | ret = BIO_ctrl(bio, BIO_C_NWRITE, num, buf); |
921 | if (ret > 0) | 897 | if (ret > 0) |
922 | bio->num_write += ret; | 898 | bio->num_write += ret; |
923 | return ret; | 899 | return ret; |
924 | } | 900 | } |
diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c index 5162e75c87..df34c49a4a 100644 --- a/src/lib/libcrypto/bio/bss_conn.c +++ b/src/lib/libcrypto/bio/bss_conn.c | |||
@@ -76,8 +76,7 @@ | |||
76 | #endif | 76 | #endif |
77 | 77 | ||
78 | 78 | ||
79 | typedef struct bio_connect_st | 79 | typedef struct bio_connect_st { |
80 | { | ||
81 | int state; | 80 | int state; |
82 | 81 | ||
83 | char *param_hostname; | 82 | char *param_hostname; |
@@ -95,8 +94,8 @@ typedef struct bio_connect_st | |||
95 | /* called when the connection is initially made | 94 | /* called when the connection is initially made |
96 | * callback(BIO,state,ret); The callback should return | 95 | * callback(BIO,state,ret); The callback should return |
97 | * 'ret'. state is for compatibility with the ssl info_callback */ | 96 | * 'ret'. state is for compatibility with the ssl info_callback */ |
98 | int (*info_callback)(const BIO *bio,int state,int ret); | 97 | int (*info_callback)(const BIO *bio, int state, int ret); |
99 | } BIO_CONNECT; | 98 | } BIO_CONNECT; |
100 | 99 | ||
101 | static int conn_write(BIO *h, const char *buf, int num); | 100 | static int conn_write(BIO *h, const char *buf, int num); |
102 | static int conn_read(BIO *h, char *buf, int size); | 101 | static int conn_read(BIO *h, char *buf, int size); |
@@ -108,11 +107,10 @@ static long conn_callback_ctrl(BIO *h, int cmd, bio_info_cb *); | |||
108 | 107 | ||
109 | static int conn_state(BIO *b, BIO_CONNECT *c); | 108 | static int conn_state(BIO *b, BIO_CONNECT *c); |
110 | static void conn_close_socket(BIO *data); | 109 | static void conn_close_socket(BIO *data); |
111 | BIO_CONNECT *BIO_CONNECT_new(void ); | 110 | BIO_CONNECT *BIO_CONNECT_new(void); |
112 | void BIO_CONNECT_free(BIO_CONNECT *a); | 111 | void BIO_CONNECT_free(BIO_CONNECT *a); |
113 | 112 | ||
114 | static BIO_METHOD methods_connectp= | 113 | static BIO_METHOD methods_connectp = { |
115 | { | ||
116 | BIO_TYPE_CONNECT, | 114 | BIO_TYPE_CONNECT, |
117 | "socket connect", | 115 | "socket connect", |
118 | conn_write, | 116 | conn_write, |
@@ -123,530 +121,501 @@ static BIO_METHOD methods_connectp= | |||
123 | conn_new, | 121 | conn_new, |
124 | conn_free, | 122 | conn_free, |
125 | conn_callback_ctrl, | 123 | conn_callback_ctrl, |
126 | }; | 124 | }; |
127 | 125 | ||
128 | static int conn_state(BIO *b, BIO_CONNECT *c) | 126 | static int |
129 | { | 127 | conn_state(BIO *b, BIO_CONNECT *c) |
130 | int ret= -1,i; | 128 | { |
129 | int ret = -1, i; | ||
131 | unsigned long l; | 130 | unsigned long l; |
132 | char *p,*q; | 131 | char *p, *q; |
133 | int (*cb)(const BIO *,int,int)=NULL; | 132 | int (*cb)(const BIO *, int, int) = NULL; |
134 | 133 | ||
135 | if (c->info_callback != NULL) | 134 | if (c->info_callback != NULL) |
136 | cb=c->info_callback; | 135 | cb = c->info_callback; |
137 | 136 | ||
138 | for (;;) | 137 | for (;;) { |
139 | { | 138 | switch (c->state) { |
140 | switch (c->state) | ||
141 | { | ||
142 | case BIO_CONN_S_BEFORE: | 139 | case BIO_CONN_S_BEFORE: |
143 | p=c->param_hostname; | 140 | p = c->param_hostname; |
144 | if (p == NULL) | 141 | if (p == NULL) { |
145 | { | 142 | BIOerr(BIO_F_CONN_STATE, BIO_R_NO_HOSTNAME_SPECIFIED); |
146 | BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTNAME_SPECIFIED); | ||
147 | goto exit_loop; | 143 | goto exit_loop; |
148 | } | 144 | } |
149 | for ( ; *p != '\0'; p++) | 145 | for (; *p != '\0'; p++) { |
150 | { | 146 | if ((*p == ':') || (*p == '/')) |
151 | if ((*p == ':') || (*p == '/')) break; | 147 | break; |
152 | } | 148 | } |
153 | 149 | ||
154 | i= *p; | 150 | i= *p; |
155 | if ((i == ':') || (i == '/')) | 151 | if ((i == ':') || (i == '/')) { |
156 | { | 152 | *(p++) = '\0'; |
157 | 153 | if (i == ':') { | |
158 | *(p++)='\0'; | 154 | for (q = p; *q; q++) |
159 | if (i == ':') | 155 | if (*q == '/') { |
160 | { | 156 | *q = '\0'; |
161 | for (q=p; *q; q++) | ||
162 | if (*q == '/') | ||
163 | { | ||
164 | *q='\0'; | ||
165 | break; | 157 | break; |
166 | } | 158 | } |
167 | if (c->param_port != NULL) | 159 | if (c->param_port != NULL) |
168 | OPENSSL_free(c->param_port); | 160 | OPENSSL_free(c->param_port); |
169 | c->param_port=BUF_strdup(p); | 161 | c->param_port = BUF_strdup(p); |
170 | } | ||
171 | } | 162 | } |
163 | } | ||
172 | 164 | ||
173 | if (c->param_port == NULL) | 165 | if (c->param_port == NULL) { |
174 | { | 166 | BIOerr(BIO_F_CONN_STATE, BIO_R_NO_PORT_SPECIFIED); |
175 | BIOerr(BIO_F_CONN_STATE,BIO_R_NO_PORT_SPECIFIED); | 167 | ERR_add_error_data(2, "host=", c->param_hostname); |
176 | ERR_add_error_data(2,"host=",c->param_hostname); | ||
177 | goto exit_loop; | 168 | goto exit_loop; |
178 | } | 169 | } |
179 | c->state=BIO_CONN_S_GET_IP; | 170 | c->state = BIO_CONN_S_GET_IP; |
180 | break; | 171 | break; |
181 | 172 | ||
182 | case BIO_CONN_S_GET_IP: | 173 | case BIO_CONN_S_GET_IP: |
183 | if (BIO_get_host_ip(c->param_hostname,&(c->ip[0])) <= 0) | 174 | if (BIO_get_host_ip(c->param_hostname, &(c->ip[0])) <= 0) |
184 | goto exit_loop; | 175 | goto exit_loop; |
185 | c->state=BIO_CONN_S_GET_PORT; | 176 | c->state = BIO_CONN_S_GET_PORT; |
186 | break; | 177 | break; |
187 | 178 | ||
188 | case BIO_CONN_S_GET_PORT: | 179 | case BIO_CONN_S_GET_PORT: |
189 | if (c->param_port == NULL) | 180 | if (c->param_port == NULL) { |
190 | { | ||
191 | /* abort(); */ | 181 | /* abort(); */ |
192 | goto exit_loop; | 182 | goto exit_loop; |
193 | } | 183 | } else if (BIO_get_port(c->param_port, &c->port) <= 0) |
194 | else if (BIO_get_port(c->param_port,&c->port) <= 0) | ||
195 | goto exit_loop; | 184 | goto exit_loop; |
196 | c->state=BIO_CONN_S_CREATE_SOCKET; | 185 | c->state = BIO_CONN_S_CREATE_SOCKET; |
197 | break; | 186 | break; |
198 | 187 | ||
199 | case BIO_CONN_S_CREATE_SOCKET: | 188 | case BIO_CONN_S_CREATE_SOCKET: |
200 | /* now setup address */ | 189 | /* now setup address */ |
201 | memset((char *)&c->them,0,sizeof(c->them)); | 190 | memset((char *)&c->them, 0, sizeof(c->them)); |
202 | c->them.sin_family=AF_INET; | 191 | c->them.sin_family = AF_INET; |
203 | c->them.sin_port=htons((unsigned short)c->port); | 192 | c->them.sin_port = htons((unsigned short)c->port); |
204 | l=(unsigned long) | 193 | l = (unsigned long) |
205 | ((unsigned long)c->ip[0]<<24L)| | 194 | ((unsigned long)c->ip[0] << 24L)| |
206 | ((unsigned long)c->ip[1]<<16L)| | 195 | ((unsigned long)c->ip[1] << 16L)| |
207 | ((unsigned long)c->ip[2]<< 8L)| | 196 | ((unsigned long)c->ip[2] << 8L)| |
208 | ((unsigned long)c->ip[3]); | 197 | ((unsigned long)c->ip[3]); |
209 | c->them.sin_addr.s_addr=htonl(l); | 198 | c->them.sin_addr.s_addr = htonl(l); |
210 | c->state=BIO_CONN_S_CREATE_SOCKET; | 199 | c->state = BIO_CONN_S_CREATE_SOCKET; |
211 | 200 | ||
212 | ret=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); | 201 | ret = socket(AF_INET, SOCK_STREAM, SOCKET_PROTOCOL); |
213 | if (ret == -1) | 202 | if (ret == -1) { |
214 | { | 203 | SYSerr(SYS_F_SOCKET, errno); |
215 | SYSerr(SYS_F_SOCKET,errno); | 204 | ERR_add_error_data(4, "host=", |
216 | ERR_add_error_data(4,"host=",c->param_hostname, | 205 | c->param_hostname, ":", c->param_port); |
217 | ":",c->param_port); | 206 | BIOerr(BIO_F_CONN_STATE, |
218 | BIOerr(BIO_F_CONN_STATE,BIO_R_UNABLE_TO_CREATE_SOCKET); | 207 | BIO_R_UNABLE_TO_CREATE_SOCKET); |
219 | goto exit_loop; | 208 | goto exit_loop; |
220 | } | 209 | } |
221 | b->num=ret; | 210 | b->num = ret; |
222 | c->state=BIO_CONN_S_NBIO; | 211 | c->state = BIO_CONN_S_NBIO; |
223 | break; | 212 | break; |
224 | 213 | ||
225 | case BIO_CONN_S_NBIO: | 214 | case BIO_CONN_S_NBIO: |
226 | if (c->nbio) | 215 | if (c->nbio) { |
227 | { | 216 | if (!BIO_socket_nbio(b->num, 1)) { |
228 | if (!BIO_socket_nbio(b->num,1)) | 217 | BIOerr(BIO_F_CONN_STATE, |
229 | { | 218 | BIO_R_ERROR_SETTING_NBIO); |
230 | BIOerr(BIO_F_CONN_STATE,BIO_R_ERROR_SETTING_NBIO); | 219 | ERR_add_error_data(4, "host=", |
231 | ERR_add_error_data(4,"host=", | 220 | c->param_hostname, ":", |
232 | c->param_hostname, | 221 | c->param_port); |
233 | ":",c->param_port); | ||
234 | goto exit_loop; | 222 | goto exit_loop; |
235 | } | ||
236 | } | 223 | } |
237 | c->state=BIO_CONN_S_CONNECT; | 224 | } |
225 | c->state = BIO_CONN_S_CONNECT; | ||
238 | 226 | ||
239 | #if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE) | 227 | #if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE) |
240 | i=1; | 228 | i = 1; |
241 | i=setsockopt(b->num,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i)); | 229 | i = setsockopt(b->num, SOL_SOCKET, SO_KEEPALIVE,(char *)&i, sizeof(i)); |
242 | if (i < 0) | 230 | if (i < 0) { |
243 | { | 231 | SYSerr(SYS_F_SOCKET, errno); |
244 | SYSerr(SYS_F_SOCKET,errno); | 232 | ERR_add_error_data(4, "host=", |
245 | ERR_add_error_data(4,"host=",c->param_hostname, | 233 | c->param_hostname, ":", c->param_port); |
246 | ":",c->param_port); | 234 | BIOerr(BIO_F_CONN_STATE, BIO_R_KEEPALIVE); |
247 | BIOerr(BIO_F_CONN_STATE,BIO_R_KEEPALIVE); | ||
248 | goto exit_loop; | 235 | goto exit_loop; |
249 | } | 236 | } |
250 | #endif | 237 | #endif |
251 | break; | 238 | break; |
252 | 239 | ||
253 | case BIO_CONN_S_CONNECT: | 240 | case BIO_CONN_S_CONNECT: |
254 | BIO_clear_retry_flags(b); | 241 | BIO_clear_retry_flags(b); |
255 | ret=connect(b->num, | 242 | ret = connect(b->num, |
256 | (struct sockaddr *)&c->them, | 243 | (struct sockaddr *)&c->them, |
257 | sizeof(c->them)); | 244 | sizeof(c->them)); |
258 | b->retry_reason=0; | 245 | b->retry_reason = 0; |
259 | if (ret < 0) | 246 | if (ret < 0) { |
260 | { | 247 | if (BIO_sock_should_retry(ret)) { |
261 | if (BIO_sock_should_retry(ret)) | ||
262 | { | ||
263 | BIO_set_retry_special(b); | 248 | BIO_set_retry_special(b); |
264 | c->state=BIO_CONN_S_BLOCKED_CONNECT; | 249 | c->state = BIO_CONN_S_BLOCKED_CONNECT; |
265 | b->retry_reason=BIO_RR_CONNECT; | 250 | b->retry_reason = BIO_RR_CONNECT; |
266 | } | 251 | } else { |
267 | else | 252 | SYSerr(SYS_F_CONNECT, errno); |
268 | { | 253 | ERR_add_error_data(4, "host=", |
269 | SYSerr(SYS_F_CONNECT,errno); | 254 | c->param_hostname, ":", |
270 | ERR_add_error_data(4,"host=", | 255 | c->param_port); |
271 | c->param_hostname, | 256 | BIOerr(BIO_F_CONN_STATE, |
272 | ":",c->param_port); | 257 | BIO_R_CONNECT_ERROR); |
273 | BIOerr(BIO_F_CONN_STATE,BIO_R_CONNECT_ERROR); | ||
274 | } | ||
275 | goto exit_loop; | ||
276 | } | 258 | } |
277 | else | 259 | goto exit_loop; |
278 | c->state=BIO_CONN_S_OK; | 260 | } else |
261 | c->state = BIO_CONN_S_OK; | ||
279 | break; | 262 | break; |
280 | 263 | ||
281 | case BIO_CONN_S_BLOCKED_CONNECT: | 264 | case BIO_CONN_S_BLOCKED_CONNECT: |
282 | i=BIO_sock_error(b->num); | 265 | i = BIO_sock_error(b->num); |
283 | if (i) | 266 | if (i) { |
284 | { | ||
285 | BIO_clear_retry_flags(b); | 267 | BIO_clear_retry_flags(b); |
286 | SYSerr(SYS_F_CONNECT,i); | 268 | SYSerr(SYS_F_CONNECT, i); |
287 | ERR_add_error_data(4,"host=", | 269 | ERR_add_error_data(4, "host=", |
288 | c->param_hostname, | 270 | c->param_hostname, ":", c->param_port); |
289 | ":",c->param_port); | 271 | BIOerr(BIO_F_CONN_STATE, |
290 | BIOerr(BIO_F_CONN_STATE,BIO_R_NBIO_CONNECT_ERROR); | 272 | BIO_R_NBIO_CONNECT_ERROR); |
291 | ret=0; | 273 | ret = 0; |
292 | goto exit_loop; | 274 | goto exit_loop; |
293 | } | 275 | } else |
294 | else | 276 | c->state = BIO_CONN_S_OK; |
295 | c->state=BIO_CONN_S_OK; | ||
296 | break; | 277 | break; |
297 | 278 | ||
298 | case BIO_CONN_S_OK: | 279 | case BIO_CONN_S_OK: |
299 | ret=1; | 280 | ret = 1; |
300 | goto exit_loop; | 281 | goto exit_loop; |
301 | default: | 282 | default: |
302 | /* abort(); */ | 283 | /* abort(); */ |
303 | goto exit_loop; | 284 | goto exit_loop; |
304 | } | 285 | } |
305 | 286 | ||
306 | if (cb != NULL) | 287 | if (cb != NULL) { |
307 | { | 288 | if (!(ret = cb((BIO *)b, c->state, ret))) |
308 | if (!(ret=cb((BIO *)b,c->state,ret))) | ||
309 | goto end; | 289 | goto end; |
310 | } | ||
311 | } | 290 | } |
291 | } | ||
312 | 292 | ||
313 | /* Loop does not exit */ | 293 | /* Loop does not exit */ |
314 | exit_loop: | 294 | exit_loop: |
315 | if (cb != NULL) | 295 | if (cb != NULL) |
316 | ret=cb((BIO *)b,c->state,ret); | 296 | ret = cb((BIO *)b, c->state, ret); |
317 | end: | 297 | end: |
318 | return(ret); | 298 | return (ret); |
319 | } | 299 | } |
320 | 300 | ||
321 | BIO_CONNECT *BIO_CONNECT_new(void) | 301 | BIO_CONNECT |
322 | { | 302 | *BIO_CONNECT_new(void) |
303 | { | ||
323 | BIO_CONNECT *ret; | 304 | BIO_CONNECT *ret; |
324 | 305 | ||
325 | if ((ret=(BIO_CONNECT *)OPENSSL_malloc(sizeof(BIO_CONNECT))) == NULL) | 306 | if ((ret = (BIO_CONNECT *)OPENSSL_malloc(sizeof(BIO_CONNECT))) == NULL) |
326 | return(NULL); | 307 | return (NULL); |
327 | ret->state=BIO_CONN_S_BEFORE; | 308 | ret->state = BIO_CONN_S_BEFORE; |
328 | ret->param_hostname=NULL; | 309 | ret->param_hostname = NULL; |
329 | ret->param_port=NULL; | 310 | ret->param_port = NULL; |
330 | ret->info_callback=NULL; | 311 | ret->info_callback = NULL; |
331 | ret->nbio=0; | 312 | ret->nbio = 0; |
332 | ret->ip[0]=0; | 313 | ret->ip[0] = 0; |
333 | ret->ip[1]=0; | 314 | ret->ip[1] = 0; |
334 | ret->ip[2]=0; | 315 | ret->ip[2] = 0; |
335 | ret->ip[3]=0; | 316 | ret->ip[3] = 0; |
336 | ret->port=0; | 317 | ret->port = 0; |
337 | memset((char *)&ret->them,0,sizeof(ret->them)); | 318 | memset((char *)&ret->them, 0, sizeof(ret->them)); |
338 | return(ret); | 319 | return (ret); |
339 | } | 320 | } |
340 | 321 | ||
341 | void BIO_CONNECT_free(BIO_CONNECT *a) | 322 | void |
342 | { | 323 | BIO_CONNECT_free(BIO_CONNECT *a) |
343 | if(a == NULL) | 324 | { |
344 | return; | 325 | if (a == NULL) |
326 | return; | ||
345 | 327 | ||
346 | if (a->param_hostname != NULL) | 328 | if (a->param_hostname != NULL) |
347 | OPENSSL_free(a->param_hostname); | 329 | OPENSSL_free(a->param_hostname); |
348 | if (a->param_port != NULL) | 330 | if (a->param_port != NULL) |
349 | OPENSSL_free(a->param_port); | 331 | OPENSSL_free(a->param_port); |
350 | OPENSSL_free(a); | 332 | OPENSSL_free(a); |
351 | } | 333 | } |
352 | 334 | ||
353 | BIO_METHOD *BIO_s_connect(void) | 335 | BIO_METHOD |
354 | { | 336 | *BIO_s_connect(void) |
355 | return(&methods_connectp); | 337 | { |
356 | } | 338 | return (&methods_connectp); |
357 | 339 | } | |
358 | static int conn_new(BIO *bi) | 340 | |
359 | { | 341 | static int |
360 | bi->init=0; | 342 | conn_new(BIO *bi) |
361 | bi->num=-1; | 343 | { |
362 | bi->flags=0; | 344 | bi->init = 0; |
363 | if ((bi->ptr=(char *)BIO_CONNECT_new()) == NULL) | 345 | bi->num = -1; |
364 | return(0); | 346 | bi->flags = 0; |
347 | if ((bi->ptr = (char *)BIO_CONNECT_new()) == NULL) | ||
348 | return (0); | ||
365 | else | 349 | else |
366 | return(1); | 350 | return (1); |
367 | } | 351 | } |
368 | 352 | ||
369 | static void conn_close_socket(BIO *bio) | 353 | static void |
370 | { | 354 | conn_close_socket(BIO *bio) |
355 | { | ||
371 | BIO_CONNECT *c; | 356 | BIO_CONNECT *c; |
372 | 357 | ||
373 | c=(BIO_CONNECT *)bio->ptr; | 358 | c = (BIO_CONNECT *)bio->ptr; |
374 | if (bio->num != -1) | 359 | if (bio->num != -1) { |
375 | { | ||
376 | /* Only do a shutdown if things were established */ | 360 | /* Only do a shutdown if things were established */ |
377 | if (c->state == BIO_CONN_S_OK) | 361 | if (c->state == BIO_CONN_S_OK) |
378 | shutdown(bio->num, SHUT_RDWR); | 362 | shutdown(bio->num, SHUT_RDWR); |
379 | close(bio->num); | 363 | close(bio->num); |
380 | bio->num=-1; | 364 | bio->num = -1; |
381 | } | ||
382 | } | 365 | } |
366 | } | ||
383 | 367 | ||
384 | static int conn_free(BIO *a) | 368 | static int |
385 | { | 369 | conn_free(BIO *a) |
370 | { | ||
386 | BIO_CONNECT *data; | 371 | BIO_CONNECT *data; |
387 | 372 | ||
388 | if (a == NULL) return(0); | 373 | if (a == NULL) |
389 | data=(BIO_CONNECT *)a->ptr; | 374 | return (0); |
390 | 375 | data = (BIO_CONNECT *)a->ptr; | |
391 | if (a->shutdown) | 376 | |
392 | { | 377 | if (a->shutdown) { |
393 | conn_close_socket(a); | 378 | conn_close_socket(a); |
394 | BIO_CONNECT_free(data); | 379 | BIO_CONNECT_free(data); |
395 | a->ptr=NULL; | 380 | a->ptr = NULL; |
396 | a->flags=0; | 381 | a->flags = 0; |
397 | a->init=0; | 382 | a->init = 0; |
398 | } | ||
399 | return(1); | ||
400 | } | 383 | } |
401 | 384 | return (1); | |
402 | static int conn_read(BIO *b, char *out, int outl) | 385 | } |
403 | { | 386 | |
404 | int ret=0; | 387 | static int |
388 | conn_read(BIO *b, char *out, int outl) | ||
389 | { | ||
390 | int ret = 0; | ||
405 | BIO_CONNECT *data; | 391 | BIO_CONNECT *data; |
406 | 392 | ||
407 | data=(BIO_CONNECT *)b->ptr; | 393 | data = (BIO_CONNECT *)b->ptr; |
408 | if (data->state != BIO_CONN_S_OK) | 394 | if (data->state != BIO_CONN_S_OK) { |
409 | { | 395 | ret = conn_state(b, data); |
410 | ret=conn_state(b,data); | ||
411 | if (ret <= 0) | 396 | if (ret <= 0) |
412 | return(ret); | 397 | return (ret); |
413 | } | 398 | } |
414 | 399 | ||
415 | if (out != NULL) | 400 | if (out != NULL) { |
416 | { | ||
417 | errno = 0; | 401 | errno = 0; |
418 | ret=read(b->num,out,outl); | 402 | ret = read(b->num, out, outl); |
419 | BIO_clear_retry_flags(b); | 403 | BIO_clear_retry_flags(b); |
420 | if (ret <= 0) | 404 | if (ret <= 0) { |
421 | { | ||
422 | if (BIO_sock_should_retry(ret)) | 405 | if (BIO_sock_should_retry(ret)) |
423 | BIO_set_retry_read(b); | 406 | BIO_set_retry_read(b); |
424 | } | ||
425 | } | 407 | } |
426 | return(ret); | ||
427 | } | 408 | } |
409 | return (ret); | ||
410 | } | ||
428 | 411 | ||
429 | static int conn_write(BIO *b, const char *in, int inl) | 412 | static int |
430 | { | 413 | conn_write(BIO *b, const char *in, int inl) |
414 | { | ||
431 | int ret; | 415 | int ret; |
432 | BIO_CONNECT *data; | 416 | BIO_CONNECT *data; |
433 | 417 | ||
434 | data=(BIO_CONNECT *)b->ptr; | 418 | data = (BIO_CONNECT *)b->ptr; |
435 | if (data->state != BIO_CONN_S_OK) | 419 | if (data->state != BIO_CONN_S_OK) { |
436 | { | 420 | ret = conn_state(b, data); |
437 | ret=conn_state(b,data); | 421 | if (ret <= 0) |
438 | if (ret <= 0) return(ret); | 422 | return (ret); |
439 | } | 423 | } |
440 | 424 | ||
441 | errno = 0; | 425 | errno = 0; |
442 | ret=write(b->num,in,inl); | 426 | ret = write(b->num, in, inl); |
443 | BIO_clear_retry_flags(b); | 427 | BIO_clear_retry_flags(b); |
444 | if (ret <= 0) | 428 | if (ret <= 0) { |
445 | { | ||
446 | if (BIO_sock_should_retry(ret)) | 429 | if (BIO_sock_should_retry(ret)) |
447 | BIO_set_retry_write(b); | 430 | BIO_set_retry_write(b); |
448 | } | ||
449 | return(ret); | ||
450 | } | 431 | } |
432 | return (ret); | ||
433 | } | ||
451 | 434 | ||
452 | static long conn_ctrl(BIO *b, int cmd, long num, void *ptr) | 435 | static long |
453 | { | 436 | conn_ctrl(BIO *b, int cmd, long num, void *ptr) |
437 | { | ||
454 | BIO *dbio; | 438 | BIO *dbio; |
455 | int *ip; | 439 | int *ip; |
456 | const char **pptr; | 440 | const char **pptr; |
457 | long ret=1; | 441 | long ret = 1; |
458 | BIO_CONNECT *data; | 442 | BIO_CONNECT *data; |
459 | 443 | ||
460 | data=(BIO_CONNECT *)b->ptr; | 444 | data = (BIO_CONNECT *)b->ptr; |
461 | 445 | ||
462 | switch (cmd) | 446 | switch (cmd) { |
463 | { | ||
464 | case BIO_CTRL_RESET: | 447 | case BIO_CTRL_RESET: |
465 | ret=0; | 448 | ret = 0; |
466 | data->state=BIO_CONN_S_BEFORE; | 449 | data->state = BIO_CONN_S_BEFORE; |
467 | conn_close_socket(b); | 450 | conn_close_socket(b); |
468 | b->flags=0; | 451 | b->flags = 0; |
469 | break; | 452 | break; |
470 | case BIO_C_DO_STATE_MACHINE: | 453 | case BIO_C_DO_STATE_MACHINE: |
471 | /* use this one to start the connection */ | 454 | /* use this one to start the connection */ |
472 | if (data->state != BIO_CONN_S_OK) | 455 | if (data->state != BIO_CONN_S_OK) |
473 | ret=(long)conn_state(b,data); | 456 | ret = (long)conn_state(b, data); |
474 | else | 457 | else |
475 | ret=1; | 458 | ret = 1; |
476 | break; | 459 | break; |
477 | case BIO_C_GET_CONNECT: | 460 | case BIO_C_GET_CONNECT: |
478 | if (ptr != NULL) | 461 | if (ptr != NULL) { |
479 | { | 462 | pptr = (const char **)ptr; |
480 | pptr=(const char **)ptr; | 463 | if (num == 0) { |
481 | if (num == 0) | 464 | *pptr = data->param_hostname; |
482 | { | 465 | |
483 | *pptr=data->param_hostname; | 466 | } else if (num == 1) { |
484 | 467 | *pptr = data->param_port; | |
485 | } | 468 | } else if (num == 2) { |
486 | else if (num == 1) | 469 | *pptr = (char *)&(data->ip[0]); |
487 | { | 470 | } else if (num == 3) { |
488 | *pptr=data->param_port; | 471 | *((int *)ptr) = data->port; |
489 | } | ||
490 | else if (num == 2) | ||
491 | { | ||
492 | *pptr= (char *)&(data->ip[0]); | ||
493 | } | ||
494 | else if (num == 3) | ||
495 | { | ||
496 | *((int *)ptr)=data->port; | ||
497 | } | ||
498 | if ((!b->init) || (ptr == NULL)) | ||
499 | *pptr="not initialized"; | ||
500 | ret=1; | ||
501 | } | 472 | } |
473 | if ((!b->init) || (ptr == NULL)) | ||
474 | *pptr = "not initialized"; | ||
475 | ret = 1; | ||
476 | } | ||
502 | break; | 477 | break; |
503 | case BIO_C_SET_CONNECT: | 478 | case BIO_C_SET_CONNECT: |
504 | if (ptr != NULL) | 479 | if (ptr != NULL) { |
505 | { | 480 | b->init = 1; |
506 | b->init=1; | 481 | if (num == 0) { |
507 | if (num == 0) | ||
508 | { | ||
509 | if (data->param_hostname != NULL) | 482 | if (data->param_hostname != NULL) |
510 | OPENSSL_free(data->param_hostname); | 483 | OPENSSL_free(data->param_hostname); |
511 | data->param_hostname=BUF_strdup(ptr); | 484 | data->param_hostname = BUF_strdup(ptr); |
512 | } | 485 | } else if (num == 1) { |
513 | else if (num == 1) | ||
514 | { | ||
515 | if (data->param_port != NULL) | 486 | if (data->param_port != NULL) |
516 | OPENSSL_free(data->param_port); | 487 | OPENSSL_free(data->param_port); |
517 | data->param_port=BUF_strdup(ptr); | 488 | data->param_port = BUF_strdup(ptr); |
518 | } | 489 | } else if (num == 2) { |
519 | else if (num == 2) | ||
520 | { | ||
521 | char buf[16]; | 490 | char buf[16]; |
522 | unsigned char *p = ptr; | 491 | unsigned char *p = ptr; |
523 | 492 | ||
524 | (void) snprintf(buf,sizeof buf,"%d.%d.%d.%d", | 493 | (void) snprintf(buf, sizeof buf, "%d.%d.%d.%d", |
525 | p[0],p[1],p[2],p[3]); | 494 | p[0], p[1], p[2], p[3]); |
526 | if (data->param_hostname != NULL) | 495 | if (data->param_hostname != NULL) |
527 | OPENSSL_free(data->param_hostname); | 496 | OPENSSL_free(data->param_hostname); |
528 | data->param_hostname=BUF_strdup(buf); | 497 | data->param_hostname = BUF_strdup(buf); |
529 | memcpy(&(data->ip[0]),ptr,4); | 498 | memcpy(&(data->ip[0]), ptr, 4); |
530 | } | 499 | } else if (num == 3) { |
531 | else if (num == 3) | 500 | char buf[DECIMAL_SIZE(int) + 1]; |
532 | { | ||
533 | char buf[DECIMAL_SIZE(int)+1]; | ||
534 | 501 | ||
535 | (void) snprintf(buf,sizeof buf,"%d",*(int *)ptr); | 502 | (void) snprintf(buf, sizeof buf, "%d", |
503 | *(int *)ptr); | ||
536 | if (data->param_port != NULL) | 504 | if (data->param_port != NULL) |
537 | OPENSSL_free(data->param_port); | 505 | OPENSSL_free(data->param_port); |
538 | data->param_port=BUF_strdup(buf); | 506 | data->param_port = BUF_strdup(buf); |
539 | data->port= *(int *)ptr; | 507 | data->port= *(int *)ptr; |
540 | } | ||
541 | } | 508 | } |
509 | } | ||
542 | break; | 510 | break; |
543 | case BIO_C_SET_NBIO: | 511 | case BIO_C_SET_NBIO: |
544 | data->nbio=(int)num; | 512 | data->nbio = (int)num; |
545 | break; | 513 | break; |
546 | case BIO_C_GET_FD: | 514 | case BIO_C_GET_FD: |
547 | if (b->init) | 515 | if (b->init) { |
548 | { | 516 | ip = (int *)ptr; |
549 | ip=(int *)ptr; | ||
550 | if (ip != NULL) | 517 | if (ip != NULL) |
551 | *ip=b->num; | 518 | *ip = b->num; |
552 | ret=b->num; | 519 | ret = b->num; |
553 | } | 520 | } else |
554 | else | 521 | ret = -1; |
555 | ret= -1; | ||
556 | break; | 522 | break; |
557 | case BIO_CTRL_GET_CLOSE: | 523 | case BIO_CTRL_GET_CLOSE: |
558 | ret=b->shutdown; | 524 | ret = b->shutdown; |
559 | break; | 525 | break; |
560 | case BIO_CTRL_SET_CLOSE: | 526 | case BIO_CTRL_SET_CLOSE: |
561 | b->shutdown=(int)num; | 527 | b->shutdown = (int)num; |
562 | break; | 528 | break; |
563 | case BIO_CTRL_PENDING: | 529 | case BIO_CTRL_PENDING: |
564 | case BIO_CTRL_WPENDING: | 530 | case BIO_CTRL_WPENDING: |
565 | ret=0; | 531 | ret = 0; |
566 | break; | 532 | break; |
567 | case BIO_CTRL_FLUSH: | 533 | case BIO_CTRL_FLUSH: |
568 | break; | 534 | break; |
569 | case BIO_CTRL_DUP: | 535 | case BIO_CTRL_DUP: |
570 | { | 536 | { |
571 | dbio=(BIO *)ptr; | 537 | dbio = (BIO *)ptr; |
572 | if (data->param_port) | 538 | if (data->param_port) |
573 | BIO_set_conn_port(dbio,data->param_port); | 539 | BIO_set_conn_port(dbio, data->param_port); |
574 | if (data->param_hostname) | 540 | if (data->param_hostname) |
575 | BIO_set_conn_hostname(dbio,data->param_hostname); | 541 | BIO_set_conn_hostname(dbio, |
576 | BIO_set_nbio(dbio,data->nbio); | 542 | data->param_hostname); |
577 | /* FIXME: the cast of the function seems unlikely to be a good idea */ | 543 | BIO_set_nbio(dbio, data->nbio); |
578 | (void)BIO_set_info_callback(dbio,(bio_info_cb *)data->info_callback); | 544 | /* FIXME: the cast of the function seems unlikely to be a good idea */ |
545 | (void)BIO_set_info_callback(dbio, | ||
546 | (bio_info_cb *)data->info_callback); | ||
579 | } | 547 | } |
580 | break; | 548 | break; |
581 | case BIO_CTRL_SET_CALLBACK: | 549 | case BIO_CTRL_SET_CALLBACK: |
582 | { | 550 | { |
583 | #if 0 /* FIXME: Should this be used? -- Richard Levitte */ | 551 | #if 0 /* FIXME: Should this be used? -- Richard Levitte */ |
584 | BIOerr(BIO_F_CONN_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | 552 | BIOerr(BIO_F_CONN_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); |
585 | ret = -1; | 553 | ret = -1; |
586 | #else | 554 | #else |
587 | ret=0; | 555 | ret = 0; |
588 | #endif | 556 | #endif |
589 | } | 557 | } |
590 | break; | 558 | break; |
591 | case BIO_CTRL_GET_CALLBACK: | 559 | case BIO_CTRL_GET_CALLBACK: |
592 | { | 560 | { |
593 | int (**fptr)(const BIO *bio,int state,int xret); | 561 | int (**fptr)(const BIO *bio, int state, int xret); |
594 | 562 | ||
595 | fptr=(int (**)(const BIO *bio,int state,int xret))ptr; | 563 | fptr = (int (**)(const BIO *bio, int state, int xret))ptr; |
596 | *fptr=data->info_callback; | 564 | *fptr = data->info_callback; |
597 | } | 565 | } |
598 | break; | 566 | break; |
599 | default: | 567 | default: |
600 | ret=0; | 568 | ret = 0; |
601 | break; | 569 | break; |
602 | } | ||
603 | return(ret); | ||
604 | } | 570 | } |
571 | return (ret); | ||
572 | } | ||
605 | 573 | ||
606 | static long conn_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | 574 | static long |
607 | { | 575 | conn_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) |
608 | long ret=1; | 576 | { |
577 | long ret = 1; | ||
609 | BIO_CONNECT *data; | 578 | BIO_CONNECT *data; |
610 | 579 | ||
611 | data=(BIO_CONNECT *)b->ptr; | 580 | data = (BIO_CONNECT *)b->ptr; |
612 | 581 | ||
613 | switch (cmd) | 582 | switch (cmd) { |
614 | { | ||
615 | case BIO_CTRL_SET_CALLBACK: | 583 | case BIO_CTRL_SET_CALLBACK: |
616 | { | 584 | { |
617 | data->info_callback=(int (*)(const struct bio_st *, int, int))fp; | 585 | data->info_callback = (int (*)(const struct bio_st *, int, int))fp; |
618 | } | 586 | } |
619 | break; | 587 | break; |
620 | default: | 588 | default: |
621 | ret=0; | 589 | ret = 0; |
622 | break; | 590 | break; |
623 | } | ||
624 | return(ret); | ||
625 | } | 591 | } |
626 | 592 | return (ret); | |
627 | static int conn_puts(BIO *bp, const char *str) | 593 | } |
628 | { | 594 | |
629 | int n,ret; | 595 | static int |
630 | 596 | conn_puts(BIO *bp, const char *str) | |
631 | n=strlen(str); | 597 | { |
632 | ret=conn_write(bp,str,n); | 598 | int n, ret; |
633 | return(ret); | 599 | |
634 | } | 600 | n = strlen(str); |
635 | 601 | ret = conn_write(bp, str, n); | |
636 | BIO *BIO_new_connect(char *str) | 602 | return (ret); |
637 | { | 603 | } |
604 | |||
605 | BIO | ||
606 | *BIO_new_connect(char *str) | ||
607 | { | ||
638 | BIO *ret; | 608 | BIO *ret; |
639 | 609 | ||
640 | ret=BIO_new(BIO_s_connect()); | 610 | ret = BIO_new(BIO_s_connect()); |
641 | if (ret == NULL) return(NULL); | 611 | if (ret == NULL) |
642 | if (BIO_set_conn_hostname(ret,str)) | 612 | return (NULL); |
643 | return(ret); | 613 | if (BIO_set_conn_hostname(ret, str)) |
644 | else | 614 | return (ret); |
645 | { | 615 | else { |
646 | BIO_free(ret); | 616 | BIO_free(ret); |
647 | return(NULL); | 617 | return (NULL); |
648 | } | ||
649 | } | 618 | } |
619 | } | ||
650 | 620 | ||
651 | #endif | 621 | #endif |
652 | |||
diff --git a/src/lib/libcrypto/bio/bss_dgram.c b/src/lib/libcrypto/bio/bss_dgram.c index 67a13ae845..330f6fc404 100644 --- a/src/lib/libcrypto/bio/bss_dgram.c +++ b/src/lib/libcrypto/bio/bss_dgram.c | |||
@@ -113,7 +113,8 @@ static long dgram_sctp_ctrl(BIO *h, int cmd, long arg1, void *arg2); | |||
113 | static int dgram_sctp_new(BIO *h); | 113 | static int dgram_sctp_new(BIO *h); |
114 | static int dgram_sctp_free(BIO *data); | 114 | static int dgram_sctp_free(BIO *data); |
115 | #ifdef SCTP_AUTHENTICATION_EVENT | 115 | #ifdef SCTP_AUTHENTICATION_EVENT |
116 | static void dgram_sctp_handle_auth_free_key_event(BIO *b, union sctp_notification *snp); | 116 | static void dgram_sctp_handle_auth_free_key_event(BIO *b, |
117 | union sctp_notification *snp); | ||
117 | #endif | 118 | #endif |
118 | #endif | 119 | #endif |
119 | 120 | ||
@@ -121,8 +122,7 @@ static int BIO_dgram_should_retry(int s); | |||
121 | 122 | ||
122 | static void get_current_time(struct timeval *t); | 123 | static void get_current_time(struct timeval *t); |
123 | 124 | ||
124 | static BIO_METHOD methods_dgramp= | 125 | static BIO_METHOD methods_dgramp = { |
125 | { | ||
126 | BIO_TYPE_DGRAM, | 126 | BIO_TYPE_DGRAM, |
127 | "datagram socket", | 127 | "datagram socket", |
128 | dgram_write, | 128 | dgram_write, |
@@ -133,11 +133,10 @@ static BIO_METHOD methods_dgramp= | |||
133 | dgram_new, | 133 | dgram_new, |
134 | dgram_free, | 134 | dgram_free, |
135 | NULL, | 135 | NULL, |
136 | }; | 136 | }; |
137 | 137 | ||
138 | #ifndef OPENSSL_NO_SCTP | 138 | #ifndef OPENSSL_NO_SCTP |
139 | static BIO_METHOD methods_dgramp_sctp= | 139 | static BIO_METHOD methods_dgramp_sctp = { |
140 | { | ||
141 | BIO_TYPE_DGRAM_SCTP, | 140 | BIO_TYPE_DGRAM_SCTP, |
142 | "datagram sctp socket", | 141 | "datagram sctp socket", |
143 | dgram_sctp_write, | 142 | dgram_sctp_write, |
@@ -148,11 +147,10 @@ static BIO_METHOD methods_dgramp_sctp= | |||
148 | dgram_sctp_new, | 147 | dgram_sctp_new, |
149 | dgram_sctp_free, | 148 | dgram_sctp_free, |
150 | NULL, | 149 | NULL, |
151 | }; | 150 | }; |
152 | #endif | 151 | #endif |
153 | 152 | ||
154 | typedef struct bio_dgram_data_st | 153 | typedef struct bio_dgram_data_st { |
155 | { | ||
156 | union { | 154 | union { |
157 | struct sockaddr sa; | 155 | struct sockaddr sa; |
158 | struct sockaddr_in sa_in; | 156 | struct sockaddr_in sa_in; |
@@ -165,18 +163,16 @@ typedef struct bio_dgram_data_st | |||
165 | unsigned int mtu; | 163 | unsigned int mtu; |
166 | struct timeval next_timeout; | 164 | struct timeval next_timeout; |
167 | struct timeval socket_timeout; | 165 | struct timeval socket_timeout; |
168 | } bio_dgram_data; | 166 | } bio_dgram_data; |
169 | 167 | ||
170 | #ifndef OPENSSL_NO_SCTP | 168 | #ifndef OPENSSL_NO_SCTP |
171 | typedef struct bio_dgram_sctp_save_message_st | 169 | typedef struct bio_dgram_sctp_save_message_st { |
172 | { | 170 | BIO *bio; |
173 | BIO *bio; | 171 | char *data; |
174 | char *data; | 172 | int length; |
175 | int length; | 173 | } bio_dgram_sctp_save_message; |
176 | } bio_dgram_sctp_save_message; | ||
177 | 174 | ||
178 | typedef struct bio_dgram_sctp_data_st | 175 | typedef struct bio_dgram_sctp_data_st { |
179 | { | ||
180 | union { | 176 | union { |
181 | struct sockaddr sa; | 177 | struct sockaddr sa; |
182 | struct sockaddr_in sa_in; | 178 | struct sockaddr_in sa_in; |
@@ -198,79 +194,88 @@ typedef struct bio_dgram_sctp_data_st | |||
198 | int save_shutdown; | 194 | int save_shutdown; |
199 | int peer_auth_tested; | 195 | int peer_auth_tested; |
200 | bio_dgram_sctp_save_message saved_message; | 196 | bio_dgram_sctp_save_message saved_message; |
201 | } bio_dgram_sctp_data; | 197 | } bio_dgram_sctp_data; |
202 | #endif | 198 | #endif |
203 | 199 | ||
204 | BIO_METHOD *BIO_s_datagram(void) | 200 | BIO_METHOD |
205 | { | 201 | *BIO_s_datagram(void) |
206 | return(&methods_dgramp); | 202 | { |
207 | } | 203 | return (&methods_dgramp); |
204 | } | ||
208 | 205 | ||
209 | BIO *BIO_new_dgram(int fd, int close_flag) | 206 | BIO |
210 | { | 207 | *BIO_new_dgram(int fd, int close_flag) |
208 | { | ||
211 | BIO *ret; | 209 | BIO *ret; |
212 | 210 | ||
213 | ret=BIO_new(BIO_s_datagram()); | 211 | ret = BIO_new(BIO_s_datagram()); |
214 | if (ret == NULL) return(NULL); | 212 | if (ret == NULL) |
215 | BIO_set_fd(ret,fd,close_flag); | 213 | return (NULL); |
216 | return(ret); | 214 | BIO_set_fd(ret, fd, close_flag); |
217 | } | 215 | return (ret); |
216 | } | ||
218 | 217 | ||
219 | static int dgram_new(BIO *bi) | 218 | static int |
220 | { | 219 | dgram_new(BIO *bi) |
220 | { | ||
221 | bio_dgram_data *data = NULL; | 221 | bio_dgram_data *data = NULL; |
222 | 222 | ||
223 | bi->init=0; | 223 | bi->init = 0; |
224 | bi->num=0; | 224 | bi->num = 0; |
225 | data = OPENSSL_malloc(sizeof(bio_dgram_data)); | 225 | data = OPENSSL_malloc(sizeof(bio_dgram_data)); |
226 | if (data == NULL) | 226 | if (data == NULL) |
227 | return 0; | 227 | return 0; |
228 | memset(data, 0x00, sizeof(bio_dgram_data)); | 228 | memset(data, 0x00, sizeof(bio_dgram_data)); |
229 | bi->ptr = data; | 229 | bi->ptr = data; |
230 | 230 | ||
231 | bi->flags=0; | 231 | bi->flags = 0; |
232 | return(1); | 232 | return (1); |
233 | } | 233 | } |
234 | 234 | ||
235 | static int dgram_free(BIO *a) | 235 | static int |
236 | { | 236 | dgram_free(BIO *a) |
237 | { | ||
237 | bio_dgram_data *data; | 238 | bio_dgram_data *data; |
238 | 239 | ||
239 | if (a == NULL) return(0); | 240 | if (a == NULL) |
240 | if ( ! dgram_clear(a)) | 241 | return (0); |
242 | if (!dgram_clear(a)) | ||
241 | return 0; | 243 | return 0; |
242 | 244 | ||
243 | data = (bio_dgram_data *)a->ptr; | 245 | data = (bio_dgram_data *)a->ptr; |
244 | if(data != NULL) OPENSSL_free(data); | 246 | if (data != NULL) |
247 | OPENSSL_free(data); | ||
245 | 248 | ||
246 | return(1); | 249 | return (1); |
247 | } | 250 | } |
248 | 251 | ||
249 | static int dgram_clear(BIO *a) | 252 | static int |
250 | { | 253 | dgram_clear(BIO *a) |
251 | if (a == NULL) return(0); | 254 | { |
252 | if (a->shutdown) | 255 | if (a == NULL) |
253 | { | 256 | return (0); |
254 | if (a->init) | 257 | if (a->shutdown) { |
255 | { | 258 | if (a->init) { |
256 | shutdown(a->num, SHUT_RDWR); | 259 | shutdown(a->num, SHUT_RDWR); |
257 | close(a->num); | 260 | close(a->num); |
258 | } | ||
259 | a->init=0; | ||
260 | a->flags=0; | ||
261 | } | 261 | } |
262 | return(1); | 262 | a->init = 0; |
263 | a->flags = 0; | ||
263 | } | 264 | } |
265 | return (1); | ||
266 | } | ||
264 | 267 | ||
265 | static void dgram_adjust_rcv_timeout(BIO *b) | 268 | static void |
266 | { | 269 | dgram_adjust_rcv_timeout(BIO *b) |
270 | { | ||
267 | #if defined(SO_RCVTIMEO) | 271 | #if defined(SO_RCVTIMEO) |
268 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; | 272 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; |
269 | union { size_t s; int i; } sz = {0}; | 273 | union { size_t s; |
274 | int i; | ||
275 | } sz = {0}; | ||
270 | 276 | ||
271 | /* Is a timer active? */ | 277 | /* Is a timer active? */ |
272 | if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0) | 278 | if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0) { |
273 | { | ||
274 | struct timeval timenow, timeleft; | 279 | struct timeval timenow, timeleft; |
275 | 280 | ||
276 | /* Read current socket timeout */ | 281 | /* Read current socket timeout */ |
@@ -279,20 +284,19 @@ static void dgram_adjust_rcv_timeout(BIO *b) | |||
279 | 284 | ||
280 | sz.i = sizeof(timeout); | 285 | sz.i = sizeof(timeout); |
281 | if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | 286 | if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, |
282 | (void*)&timeout, &sz.i) < 0) | 287 | (void*)&timeout, &sz.i) < 0) { |
283 | { perror("getsockopt"); } | 288 | perror("getsockopt"); |
284 | else | 289 | } else { |
285 | { | ||
286 | data->socket_timeout.tv_sec = timeout / 1000; | 290 | data->socket_timeout.tv_sec = timeout / 1000; |
287 | data->socket_timeout.tv_usec = (timeout % 1000) * 1000; | 291 | data->socket_timeout.tv_usec = (timeout % 1000) * 1000; |
288 | } | 292 | } |
289 | #else | 293 | #else |
290 | sz.i = sizeof(data->socket_timeout); | 294 | sz.i = sizeof(data->socket_timeout); |
291 | if ( getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | 295 | if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, |
292 | &(data->socket_timeout), (void *)&sz) < 0) | 296 | &(data->socket_timeout), (void *)&sz) < 0) { |
293 | { perror("getsockopt"); } | 297 | perror("getsockopt"); |
294 | else if (sizeof(sz.s)!=sizeof(sz.i) && sz.i==0) | 298 | } else if (sizeof(sz.s) != sizeof(sz.i) && sz.i == 0) |
295 | OPENSSL_assert(sz.s<=sizeof(data->socket_timeout)); | 299 | OPENSSL_assert(sz.s <= sizeof(data->socket_timeout)); |
296 | #endif | 300 | #endif |
297 | 301 | ||
298 | /* Get current time */ | 302 | /* Get current time */ |
@@ -302,126 +306,128 @@ static void dgram_adjust_rcv_timeout(BIO *b) | |||
302 | memcpy(&timeleft, &(data->next_timeout), sizeof(struct timeval)); | 306 | memcpy(&timeleft, &(data->next_timeout), sizeof(struct timeval)); |
303 | timeleft.tv_sec -= timenow.tv_sec; | 307 | timeleft.tv_sec -= timenow.tv_sec; |
304 | timeleft.tv_usec -= timenow.tv_usec; | 308 | timeleft.tv_usec -= timenow.tv_usec; |
305 | if (timeleft.tv_usec < 0) | 309 | if (timeleft.tv_usec < 0) { |
306 | { | ||
307 | timeleft.tv_sec--; | 310 | timeleft.tv_sec--; |
308 | timeleft.tv_usec += 1000000; | 311 | timeleft.tv_usec += 1000000; |
309 | } | 312 | } |
310 | 313 | ||
311 | if (timeleft.tv_sec < 0) | 314 | if (timeleft.tv_sec < 0) { |
312 | { | ||
313 | timeleft.tv_sec = 0; | 315 | timeleft.tv_sec = 0; |
314 | timeleft.tv_usec = 1; | 316 | timeleft.tv_usec = 1; |
315 | } | 317 | } |
316 | 318 | ||
317 | /* Adjust socket timeout if next handhake message timer | 319 | /* Adjust socket timeout if next handhake message timer |
318 | * will expire earlier. | 320 | * will expire earlier. |
319 | */ | 321 | */ |
320 | if ((data->socket_timeout.tv_sec == 0 && data->socket_timeout.tv_usec == 0) || | 322 | if ((data->socket_timeout.tv_sec == 0 && |
321 | (data->socket_timeout.tv_sec > timeleft.tv_sec) || | 323 | data->socket_timeout.tv_usec == 0) || |
322 | (data->socket_timeout.tv_sec == timeleft.tv_sec && | 324 | (data->socket_timeout.tv_sec > timeleft.tv_sec) || |
323 | data->socket_timeout.tv_usec >= timeleft.tv_usec)) | 325 | (data->socket_timeout.tv_sec == timeleft.tv_sec && |
324 | { | 326 | data->socket_timeout.tv_usec >= timeleft.tv_usec)) { |
325 | #ifdef OPENSSL_SYS_WINDOWS | 327 | #ifdef OPENSSL_SYS_WINDOWS |
326 | timeout = timeleft.tv_sec * 1000 + timeleft.tv_usec / 1000; | 328 | timeout = timeleft.tv_sec * 1000 + timeleft.tv_usec / 1000; |
327 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | 329 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, |
328 | (void*)&timeout, sizeof(timeout)) < 0) | 330 | (void*)&timeout, sizeof(timeout)) < 0) { |
329 | { perror("setsockopt"); } | 331 | perror("setsockopt"); |
332 | } | ||
330 | #else | 333 | #else |
331 | if ( setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, &timeleft, | 334 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, |
332 | sizeof(struct timeval)) < 0) | 335 | &timeleft, sizeof(struct timeval)) < 0) { |
333 | { perror("setsockopt"); } | 336 | perror("setsockopt"); |
334 | #endif | ||
335 | } | 337 | } |
336 | } | ||
337 | #endif | 338 | #endif |
339 | } | ||
338 | } | 340 | } |
341 | #endif | ||
342 | } | ||
339 | 343 | ||
340 | static void dgram_reset_rcv_timeout(BIO *b) | 344 | static void |
341 | { | 345 | dgram_reset_rcv_timeout(BIO *b) |
346 | { | ||
342 | #if defined(SO_RCVTIMEO) | 347 | #if defined(SO_RCVTIMEO) |
343 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; | 348 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; |
344 | 349 | ||
345 | /* Is a timer active? */ | 350 | /* Is a timer active? */ |
346 | if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0) | 351 | if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0) { |
347 | { | ||
348 | #ifdef OPENSSL_SYS_WINDOWS | 352 | #ifdef OPENSSL_SYS_WINDOWS |
349 | int timeout = data->socket_timeout.tv_sec * 1000 + | 353 | int timeout = data->socket_timeout.tv_sec * 1000 + |
350 | data->socket_timeout.tv_usec / 1000; | 354 | data->socket_timeout.tv_usec / 1000; |
351 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | 355 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, |
352 | (void*)&timeout, sizeof(timeout)) < 0) | 356 | (void*)&timeout, sizeof(timeout)) < 0) { |
353 | { perror("setsockopt"); } | 357 | perror("setsockopt"); |
358 | } | ||
354 | #else | 359 | #else |
355 | if ( setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, &(data->socket_timeout), | 360 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, |
356 | sizeof(struct timeval)) < 0) | 361 | &(data->socket_timeout), sizeof(struct timeval)) < 0) { |
357 | { perror("setsockopt"); } | 362 | perror("setsockopt"); |
358 | #endif | ||
359 | } | 363 | } |
360 | #endif | 364 | #endif |
361 | } | 365 | } |
366 | #endif | ||
367 | } | ||
362 | 368 | ||
363 | static int dgram_read(BIO *b, char *out, int outl) | 369 | static int |
364 | { | 370 | dgram_read(BIO *b, char *out, int outl) |
365 | int ret=0; | 371 | { |
372 | int ret = 0; | ||
366 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; | 373 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; |
367 | 374 | ||
368 | struct { | 375 | struct { |
369 | /* | 376 | /* |
370 | * See commentary in b_sock.c. <appro> | 377 | * See commentary in b_sock.c. <appro> |
371 | */ | 378 | */ |
372 | union { size_t s; int i; } len; | 379 | union { |
373 | union { | 380 | size_t s; |
374 | struct sockaddr sa; | 381 | int i; |
375 | struct sockaddr_in sa_in; | 382 | } len; |
383 | union { | ||
384 | struct sockaddr sa; | ||
385 | struct sockaddr_in sa_in; | ||
376 | #if OPENSSL_USE_IPV6 | 386 | #if OPENSSL_USE_IPV6 |
377 | struct sockaddr_in6 sa_in6; | 387 | struct sockaddr_in6 sa_in6; |
378 | #endif | 388 | #endif |
379 | } peer; | 389 | } peer; |
380 | } sa; | 390 | } sa; |
381 | 391 | ||
382 | sa.len.s=0; | 392 | sa.len.s = 0; |
383 | sa.len.i=sizeof(sa.peer); | 393 | sa.len.i = sizeof(sa.peer); |
384 | 394 | ||
385 | if (out != NULL) | 395 | if (out != NULL) { |
386 | { | ||
387 | errno = 0; | 396 | errno = 0; |
388 | memset(&sa.peer, 0x00, sizeof(sa.peer)); | 397 | memset(&sa.peer, 0x00, sizeof(sa.peer)); |
389 | dgram_adjust_rcv_timeout(b); | 398 | dgram_adjust_rcv_timeout(b); |
390 | ret=recvfrom(b->num,out,outl,0,&sa.peer.sa,(void *)&sa.len); | 399 | ret = recvfrom(b->num, out, outl, 0, &sa.peer.sa,(void *)&sa.len); |
391 | if (sizeof(sa.len.i)!=sizeof(sa.len.s) && sa.len.i==0) | 400 | if (sizeof(sa.len.i) != sizeof(sa.len.s) && sa.len.i == 0) { |
392 | { | 401 | OPENSSL_assert(sa.len.s <= sizeof(sa.peer)); |
393 | OPENSSL_assert(sa.len.s<=sizeof(sa.peer)); | ||
394 | sa.len.i = (int)sa.len.s; | 402 | sa.len.i = (int)sa.len.s; |
395 | } | 403 | } |
396 | 404 | ||
397 | if ( ! data->connected && ret >= 0) | 405 | if (! data->connected && ret >= 0) |
398 | BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, &sa.peer); | 406 | BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, &sa.peer); |
399 | 407 | ||
400 | BIO_clear_retry_flags(b); | 408 | BIO_clear_retry_flags(b); |
401 | if (ret < 0) | 409 | if (ret < 0) { |
402 | { | 410 | if (BIO_dgram_should_retry(ret)) { |
403 | if (BIO_dgram_should_retry(ret)) | ||
404 | { | ||
405 | BIO_set_retry_read(b); | 411 | BIO_set_retry_read(b); |
406 | data->_errno = errno; | 412 | data->_errno = errno; |
407 | } | ||
408 | } | 413 | } |
414 | } | ||
409 | 415 | ||
410 | dgram_reset_rcv_timeout(b); | 416 | dgram_reset_rcv_timeout(b); |
411 | } | ||
412 | return(ret); | ||
413 | } | 417 | } |
418 | return (ret); | ||
419 | } | ||
414 | 420 | ||
415 | static int dgram_write(BIO *b, const char *in, int inl) | 421 | static int |
416 | { | 422 | dgram_write(BIO *b, const char *in, int inl) |
423 | { | ||
417 | int ret; | 424 | int ret; |
418 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; | 425 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; |
419 | errno = 0; | 426 | errno = 0; |
420 | 427 | ||
421 | if ( data->connected ) | 428 | if (data->connected) |
422 | ret=write(b->num,in,inl); | 429 | ret = write(b->num, in, inl); |
423 | else | 430 | else { |
424 | { | ||
425 | int peerlen = sizeof(data->peer); | 431 | int peerlen = sizeof(data->peer); |
426 | 432 | ||
427 | if (data->peer.sa.sa_family == AF_INET) | 433 | if (data->peer.sa.sa_family == AF_INET) |
@@ -431,33 +437,33 @@ static int dgram_write(BIO *b, const char *in, int inl) | |||
431 | peerlen = sizeof(data->peer.sa_in6); | 437 | peerlen = sizeof(data->peer.sa_in6); |
432 | #endif | 438 | #endif |
433 | #if defined(NETWARE_CLIB) && defined(NETWARE_BSDSOCK) | 439 | #if defined(NETWARE_CLIB) && defined(NETWARE_BSDSOCK) |
434 | ret=sendto(b->num, (char *)in, inl, 0, &data->peer.sa, peerlen); | 440 | ret = sendto(b->num, (char *)in, inl, 0, &data->peer.sa, peerlen); |
435 | #else | 441 | #else |
436 | ret=sendto(b->num, in, inl, 0, &data->peer.sa, peerlen); | 442 | ret = sendto(b->num, in, inl, 0, &data->peer.sa, peerlen); |
437 | #endif | 443 | #endif |
438 | } | 444 | } |
439 | 445 | ||
440 | BIO_clear_retry_flags(b); | 446 | BIO_clear_retry_flags(b); |
441 | if (ret <= 0) | 447 | if (ret <= 0) { |
442 | { | 448 | if (BIO_dgram_should_retry(ret)) { |
443 | if (BIO_dgram_should_retry(ret)) | 449 | BIO_set_retry_write(b); |
444 | { | 450 | |
445 | BIO_set_retry_write(b); | ||
446 | data->_errno = errno; | 451 | data->_errno = errno; |
447 | 452 | ||
448 | #if 0 /* higher layers are responsible for querying MTU, if necessary */ | 453 | #if 0 /* higher layers are responsible for querying MTU, if necessary */ |
449 | if ( data->_errno == EMSGSIZE) | 454 | if (data->_errno == EMSGSIZE) |
450 | /* retrieve the new MTU */ | 455 | /* retrieve the new MTU */ |
451 | BIO_ctrl(b, BIO_CTRL_DGRAM_QUERY_MTU, 0, NULL); | 456 | BIO_ctrl(b, BIO_CTRL_DGRAM_QUERY_MTU, 0, NULL); |
452 | #endif | 457 | #endif |
453 | } | ||
454 | } | 458 | } |
455 | return(ret); | ||
456 | } | 459 | } |
460 | return (ret); | ||
461 | } | ||
457 | 462 | ||
458 | static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | 463 | static long |
459 | { | 464 | dgram_ctrl(BIO *b, int cmd, long num, void *ptr) |
460 | long ret=1; | 465 | { |
466 | long ret = 1; | ||
461 | int *ip; | 467 | int *ip; |
462 | struct sockaddr *to = NULL; | 468 | struct sockaddr *to = NULL; |
463 | bio_dgram_data *data = NULL; | 469 | bio_dgram_data *data = NULL; |
@@ -472,76 +478,73 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
472 | #if OPENSSL_USE_IPV6 | 478 | #if OPENSSL_USE_IPV6 |
473 | struct sockaddr_in6 s6; | 479 | struct sockaddr_in6 s6; |
474 | #endif | 480 | #endif |
475 | } addr; | 481 | } addr; |
476 | #endif | 482 | #endif |
477 | 483 | ||
478 | data = (bio_dgram_data *)b->ptr; | 484 | data = (bio_dgram_data *)b->ptr; |
479 | 485 | ||
480 | switch (cmd) | 486 | switch (cmd) { |
481 | { | ||
482 | case BIO_CTRL_RESET: | 487 | case BIO_CTRL_RESET: |
483 | num=0; | 488 | num = 0; |
484 | case BIO_C_FILE_SEEK: | 489 | case BIO_C_FILE_SEEK: |
485 | ret=0; | 490 | ret = 0; |
486 | break; | 491 | break; |
487 | case BIO_C_FILE_TELL: | 492 | case BIO_C_FILE_TELL: |
488 | case BIO_CTRL_INFO: | 493 | case BIO_CTRL_INFO: |
489 | ret=0; | 494 | ret = 0; |
490 | break; | 495 | break; |
491 | case BIO_C_SET_FD: | 496 | case BIO_C_SET_FD: |
492 | dgram_clear(b); | 497 | dgram_clear(b); |
493 | b->num= *((int *)ptr); | 498 | b->num= *((int *)ptr); |
494 | b->shutdown=(int)num; | 499 | b->shutdown = (int)num; |
495 | b->init=1; | 500 | b->init = 1; |
496 | break; | 501 | break; |
497 | case BIO_C_GET_FD: | 502 | case BIO_C_GET_FD: |
498 | if (b->init) | 503 | if (b->init) { |
499 | { | 504 | ip = (int *)ptr; |
500 | ip=(int *)ptr; | 505 | if (ip != NULL) |
501 | if (ip != NULL) *ip=b->num; | 506 | *ip = b->num; |
502 | ret=b->num; | 507 | ret = b->num; |
503 | } | 508 | } else |
504 | else | 509 | ret = -1; |
505 | ret= -1; | ||
506 | break; | 510 | break; |
507 | case BIO_CTRL_GET_CLOSE: | 511 | case BIO_CTRL_GET_CLOSE: |
508 | ret=b->shutdown; | 512 | ret = b->shutdown; |
509 | break; | 513 | break; |
510 | case BIO_CTRL_SET_CLOSE: | 514 | case BIO_CTRL_SET_CLOSE: |
511 | b->shutdown=(int)num; | 515 | b->shutdown = (int)num; |
512 | break; | 516 | break; |
513 | case BIO_CTRL_PENDING: | 517 | case BIO_CTRL_PENDING: |
514 | case BIO_CTRL_WPENDING: | 518 | case BIO_CTRL_WPENDING: |
515 | ret=0; | 519 | ret = 0; |
516 | break; | 520 | break; |
517 | case BIO_CTRL_DUP: | 521 | case BIO_CTRL_DUP: |
518 | case BIO_CTRL_FLUSH: | 522 | case BIO_CTRL_FLUSH: |
519 | ret=1; | 523 | ret = 1; |
520 | break; | 524 | break; |
521 | case BIO_CTRL_DGRAM_CONNECT: | 525 | case BIO_CTRL_DGRAM_CONNECT: |
522 | to = (struct sockaddr *)ptr; | 526 | to = (struct sockaddr *)ptr; |
523 | #if 0 | 527 | #if 0 |
524 | if (connect(b->num, to, sizeof(struct sockaddr)) < 0) | 528 | if (connect(b->num, to, sizeof(struct sockaddr)) < 0) { |
525 | { perror("connect"); ret = 0; } | 529 | perror("connect"); |
526 | else | 530 | ret = 0; |
527 | { | 531 | } else { |
528 | #endif | 532 | #endif |
529 | switch (to->sa_family) | 533 | switch (to->sa_family) { |
530 | { | 534 | case AF_INET: |
531 | case AF_INET: | 535 | memcpy(&data->peer, to, sizeof(data->peer.sa_in)); |
532 | memcpy(&data->peer,to,sizeof(data->peer.sa_in)); | 536 | break; |
533 | break; | ||
534 | #if OPENSSL_USE_IPV6 | 537 | #if OPENSSL_USE_IPV6 |
535 | case AF_INET6: | 538 | case AF_INET6: |
536 | memcpy(&data->peer,to,sizeof(data->peer.sa_in6)); | 539 | memcpy(&data->peer, to, sizeof(data->peer.sa_in6)); |
537 | break; | 540 | break; |
538 | #endif | 541 | #endif |
539 | default: | 542 | default: |
540 | memcpy(&data->peer,to,sizeof(data->peer.sa)); | 543 | memcpy(&data->peer, to, sizeof(data->peer.sa)); |
541 | break; | 544 | break; |
542 | } | ||
543 | #if 0 | ||
544 | } | 545 | } |
546 | #if 0 | ||
547 | } | ||
545 | #endif | 548 | #endif |
546 | break; | 549 | break; |
547 | /* (Linux)kernel sets DF bit on outgoing IP packets */ | 550 | /* (Linux)kernel sets DF bit on outgoing IP packets */ |
@@ -549,31 +552,31 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
549 | #if defined(OPENSSL_SYS_LINUX) && defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DO) | 552 | #if defined(OPENSSL_SYS_LINUX) && defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DO) |
550 | addr_len = (socklen_t)sizeof(addr); | 553 | addr_len = (socklen_t)sizeof(addr); |
551 | memset((void *)&addr, 0, sizeof(addr)); | 554 | memset((void *)&addr, 0, sizeof(addr)); |
552 | if (getsockname(b->num, &addr.sa, &addr_len) < 0) | 555 | if (getsockname(b->num, &addr.sa, &addr_len) < 0) { |
553 | { | ||
554 | ret = 0; | 556 | ret = 0; |
555 | break; | 557 | break; |
556 | } | 558 | } |
557 | switch (addr.sa.sa_family) | 559 | switch (addr.sa.sa_family) { |
558 | { | ||
559 | case AF_INET: | 560 | case AF_INET: |
560 | sockopt_val = IP_PMTUDISC_DO; | 561 | sockopt_val = IP_PMTUDISC_DO; |
561 | if ((ret = setsockopt(b->num, IPPROTO_IP, IP_MTU_DISCOVER, | 562 | if ((ret = setsockopt(b->num, IPPROTO_IP, |
562 | &sockopt_val, sizeof(sockopt_val))) < 0) | 563 | IP_MTU_DISCOVER, &sockopt_val, |
564 | sizeof(sockopt_val))) < 0) | ||
563 | perror("setsockopt"); | 565 | perror("setsockopt"); |
564 | break; | 566 | break; |
565 | #if OPENSSL_USE_IPV6 && defined(IPV6_MTU_DISCOVER) && defined(IPV6_PMTUDISC_DO) | 567 | #if OPENSSL_USE_IPV6 && defined(IPV6_MTU_DISCOVER) && defined(IPV6_PMTUDISC_DO) |
566 | case AF_INET6: | 568 | case AF_INET6: |
567 | sockopt_val = IPV6_PMTUDISC_DO; | 569 | sockopt_val = IPV6_PMTUDISC_DO; |
568 | if ((ret = setsockopt(b->num, IPPROTO_IPV6, IPV6_MTU_DISCOVER, | 570 | if ((ret = setsockopt(b->num, IPPROTO_IPV6, |
569 | &sockopt_val, sizeof(sockopt_val))) < 0) | 571 | IPV6_MTU_DISCOVER, &sockopt_val, |
572 | sizeof(sockopt_val))) < 0) | ||
570 | perror("setsockopt"); | 573 | perror("setsockopt"); |
571 | break; | 574 | break; |
572 | #endif | 575 | #endif |
573 | default: | 576 | default: |
574 | ret = -1; | 577 | ret = -1; |
575 | break; | 578 | break; |
576 | } | 579 | } |
577 | ret = -1; | 580 | ret = -1; |
578 | #else | 581 | #else |
579 | break; | 582 | break; |
@@ -582,74 +585,67 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
582 | #if defined(OPENSSL_SYS_LINUX) && defined(IP_MTU) | 585 | #if defined(OPENSSL_SYS_LINUX) && defined(IP_MTU) |
583 | addr_len = (socklen_t)sizeof(addr); | 586 | addr_len = (socklen_t)sizeof(addr); |
584 | memset((void *)&addr, 0, sizeof(addr)); | 587 | memset((void *)&addr, 0, sizeof(addr)); |
585 | if (getsockname(b->num, &addr.sa, &addr_len) < 0) | 588 | if (getsockname(b->num, &addr.sa, &addr_len) < 0) { |
586 | { | ||
587 | ret = 0; | 589 | ret = 0; |
588 | break; | 590 | break; |
589 | } | 591 | } |
590 | sockopt_len = sizeof(sockopt_val); | 592 | sockopt_len = sizeof(sockopt_val); |
591 | switch (addr.sa.sa_family) | 593 | switch (addr.sa.sa_family) { |
592 | { | ||
593 | case AF_INET: | 594 | case AF_INET: |
594 | if ((ret = getsockopt(b->num, IPPROTO_IP, IP_MTU, (void *)&sockopt_val, | 595 | if ((ret = getsockopt(b->num, IPPROTO_IP, IP_MTU, |
595 | &sockopt_len)) < 0 || sockopt_val < 0) | 596 | (void *)&sockopt_val, &sockopt_len)) < 0 || |
596 | { | 597 | sockopt_val < 0) { |
597 | ret = 0; | 598 | ret = 0; |
598 | } | 599 | } else { |
599 | else | ||
600 | { | ||
601 | /* we assume that the transport protocol is UDP and no | 600 | /* we assume that the transport protocol is UDP and no |
602 | * IP options are used. | 601 | * IP options are used. |
603 | */ | 602 | */ |
604 | data->mtu = sockopt_val - 8 - 20; | 603 | data->mtu = sockopt_val - 8 - 20; |
605 | ret = data->mtu; | 604 | ret = data->mtu; |
606 | } | 605 | } |
607 | break; | 606 | break; |
608 | #if OPENSSL_USE_IPV6 && defined(IPV6_MTU) | 607 | #if OPENSSL_USE_IPV6 && defined(IPV6_MTU) |
609 | case AF_INET6: | 608 | case AF_INET6: |
610 | if ((ret = getsockopt(b->num, IPPROTO_IPV6, IPV6_MTU, (void *)&sockopt_val, | 609 | if ((ret = getsockopt(b->num, IPPROTO_IPV6, IPV6_MTU, |
611 | &sockopt_len)) < 0 || sockopt_val < 0) | 610 | (void *)&sockopt_val, &sockopt_len)) < 0 || |
612 | { | 611 | sockopt_val < 0) { |
613 | ret = 0; | 612 | ret = 0; |
614 | } | 613 | } else { |
615 | else | ||
616 | { | ||
617 | /* we assume that the transport protocol is UDP and no | 614 | /* we assume that the transport protocol is UDP and no |
618 | * IPV6 options are used. | 615 | * IPV6 options are used. |
619 | */ | 616 | */ |
620 | data->mtu = sockopt_val - 8 - 40; | 617 | data->mtu = sockopt_val - 8 - 40; |
621 | ret = data->mtu; | 618 | ret = data->mtu; |
622 | } | 619 | } |
623 | break; | 620 | break; |
624 | #endif | 621 | #endif |
625 | default: | 622 | default: |
626 | ret = 0; | 623 | ret = 0; |
627 | break; | 624 | break; |
628 | } | 625 | } |
629 | #else | 626 | #else |
630 | ret = 0; | 627 | ret = 0; |
631 | #endif | 628 | #endif |
632 | break; | 629 | break; |
633 | case BIO_CTRL_DGRAM_GET_FALLBACK_MTU: | 630 | case BIO_CTRL_DGRAM_GET_FALLBACK_MTU: |
634 | switch (data->peer.sa.sa_family) | 631 | switch (data->peer.sa.sa_family) { |
635 | { | 632 | case AF_INET: |
636 | case AF_INET: | 633 | ret = 576 - 20 - 8; |
637 | ret = 576 - 20 - 8; | 634 | break; |
638 | break; | ||
639 | #if OPENSSL_USE_IPV6 | 635 | #if OPENSSL_USE_IPV6 |
640 | case AF_INET6: | 636 | case AF_INET6: |
641 | #ifdef IN6_IS_ADDR_V4MAPPED | 637 | #ifdef IN6_IS_ADDR_V4MAPPED |
642 | if (IN6_IS_ADDR_V4MAPPED(&data->peer.sa_in6.sin6_addr)) | 638 | if (IN6_IS_ADDR_V4MAPPED(&data->peer.sa_in6.sin6_addr)) |
643 | ret = 576 - 20 - 8; | 639 | ret = 576 - 20 - 8; |
644 | else | 640 | else |
645 | #endif | 641 | #endif |
646 | ret = 1280 - 40 - 8; | 642 | ret = 1280 - 40 - 8; |
647 | break; | 643 | break; |
648 | #endif | 644 | #endif |
649 | default: | 645 | default: |
650 | ret = 576 - 20 - 8; | 646 | ret = 576 - 20 - 8; |
651 | break; | 647 | break; |
652 | } | 648 | } |
653 | break; | 649 | break; |
654 | case BIO_CTRL_DGRAM_GET_MTU: | 650 | case BIO_CTRL_DGRAM_GET_MTU: |
655 | return data->mtu; | 651 | return data->mtu; |
@@ -661,65 +657,59 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
661 | case BIO_CTRL_DGRAM_SET_CONNECTED: | 657 | case BIO_CTRL_DGRAM_SET_CONNECTED: |
662 | to = (struct sockaddr *)ptr; | 658 | to = (struct sockaddr *)ptr; |
663 | 659 | ||
664 | if ( to != NULL) | 660 | if (to != NULL) { |
665 | { | ||
666 | data->connected = 1; | 661 | data->connected = 1; |
667 | switch (to->sa_family) | 662 | switch (to->sa_family) { |
668 | { | ||
669 | case AF_INET: | ||
670 | memcpy(&data->peer,to,sizeof(data->peer.sa_in)); | ||
671 | break; | ||
672 | #if OPENSSL_USE_IPV6 | ||
673 | case AF_INET6: | ||
674 | memcpy(&data->peer,to,sizeof(data->peer.sa_in6)); | ||
675 | break; | ||
676 | #endif | ||
677 | default: | ||
678 | memcpy(&data->peer,to,sizeof(data->peer.sa)); | ||
679 | break; | ||
680 | } | ||
681 | } | ||
682 | else | ||
683 | { | ||
684 | data->connected = 0; | ||
685 | memset(&(data->peer), 0x00, sizeof(data->peer)); | ||
686 | } | ||
687 | break; | ||
688 | case BIO_CTRL_DGRAM_GET_PEER: | ||
689 | switch (data->peer.sa.sa_family) | ||
690 | { | ||
691 | case AF_INET: | 663 | case AF_INET: |
692 | ret=sizeof(data->peer.sa_in); | 664 | memcpy(&data->peer, to, sizeof(data->peer.sa_in)); |
693 | break; | 665 | break; |
694 | #if OPENSSL_USE_IPV6 | 666 | #if OPENSSL_USE_IPV6 |
695 | case AF_INET6: | 667 | case AF_INET6: |
696 | ret=sizeof(data->peer.sa_in6); | 668 | memcpy(&data->peer, to, sizeof(data->peer.sa_in6)); |
697 | break; | 669 | break; |
698 | #endif | 670 | #endif |
699 | default: | 671 | default: |
700 | ret=sizeof(data->peer.sa); | 672 | memcpy(&data->peer, to, sizeof(data->peer.sa)); |
701 | break; | 673 | break; |
702 | } | 674 | } |
703 | if (num==0 || num>ret) | 675 | } else { |
704 | num=ret; | 676 | data->connected = 0; |
705 | memcpy(ptr,&data->peer,(ret=num)); | 677 | memset(&(data->peer), 0x00, sizeof(data->peer)); |
678 | } | ||
679 | break; | ||
680 | case BIO_CTRL_DGRAM_GET_PEER: | ||
681 | switch (data->peer.sa.sa_family) { | ||
682 | case AF_INET: | ||
683 | ret = sizeof(data->peer.sa_in); | ||
684 | break; | ||
685 | #if OPENSSL_USE_IPV6 | ||
686 | case AF_INET6: | ||
687 | ret = sizeof(data->peer.sa_in6); | ||
688 | break; | ||
689 | #endif | ||
690 | default: | ||
691 | ret = sizeof(data->peer.sa); | ||
692 | break; | ||
693 | } | ||
694 | if (num == 0 || num > ret) | ||
695 | num = ret; | ||
696 | memcpy(ptr, &data->peer, (ret = num)); | ||
706 | break; | 697 | break; |
707 | case BIO_CTRL_DGRAM_SET_PEER: | 698 | case BIO_CTRL_DGRAM_SET_PEER: |
708 | to = (struct sockaddr *) ptr; | 699 | to = (struct sockaddr *) ptr; |
709 | switch (to->sa_family) | 700 | switch (to->sa_family) { |
710 | { | 701 | case AF_INET: |
711 | case AF_INET: | 702 | memcpy(&data->peer, to, sizeof(data->peer.sa_in)); |
712 | memcpy(&data->peer,to,sizeof(data->peer.sa_in)); | 703 | break; |
713 | break; | ||
714 | #if OPENSSL_USE_IPV6 | 704 | #if OPENSSL_USE_IPV6 |
715 | case AF_INET6: | 705 | case AF_INET6: |
716 | memcpy(&data->peer,to,sizeof(data->peer.sa_in6)); | 706 | memcpy(&data->peer, to, sizeof(data->peer.sa_in6)); |
717 | break; | 707 | break; |
718 | #endif | 708 | #endif |
719 | default: | 709 | default: |
720 | memcpy(&data->peer,to,sizeof(data->peer.sa)); | 710 | memcpy(&data->peer, to, sizeof(data->peer.sa)); |
721 | break; | 711 | break; |
722 | } | 712 | } |
723 | break; | 713 | break; |
724 | case BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT: | 714 | case BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT: |
725 | memcpy(&(data->next_timeout), ptr, sizeof(struct timeval)); | 715 | memcpy(&(data->next_timeout), ptr, sizeof(struct timeval)); |
@@ -728,47 +718,53 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
728 | case BIO_CTRL_DGRAM_SET_RECV_TIMEOUT: | 718 | case BIO_CTRL_DGRAM_SET_RECV_TIMEOUT: |
729 | #ifdef OPENSSL_SYS_WINDOWS | 719 | #ifdef OPENSSL_SYS_WINDOWS |
730 | { | 720 | { |
731 | struct timeval *tv = (struct timeval *)ptr; | 721 | struct timeval *tv = (struct timeval *)ptr; |
732 | int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000; | 722 | int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000; |
733 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | 723 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, |
734 | (void*)&timeout, sizeof(timeout)) < 0) | 724 | (void*)&timeout, sizeof(timeout)) < 0) { |
735 | { perror("setsockopt"); ret = -1; } | 725 | perror("setsockopt"); |
726 | ret = -1; | ||
727 | } | ||
736 | } | 728 | } |
737 | #else | 729 | #else |
738 | if ( setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, ptr, | 730 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, ptr, |
739 | sizeof(struct timeval)) < 0) | 731 | sizeof(struct timeval)) < 0) { |
740 | { perror("setsockopt"); ret = -1; } | 732 | perror("setsockopt"); |
733 | ret = -1; | ||
734 | } | ||
741 | #endif | 735 | #endif |
742 | break; | 736 | break; |
743 | case BIO_CTRL_DGRAM_GET_RECV_TIMEOUT: | 737 | case BIO_CTRL_DGRAM_GET_RECV_TIMEOUT: |
744 | { | 738 | { |
745 | union { size_t s; int i; } sz = {0}; | 739 | union { |
740 | size_t s; | ||
741 | int i; | ||
742 | } sz = {0}; | ||
746 | #ifdef OPENSSL_SYS_WINDOWS | 743 | #ifdef OPENSSL_SYS_WINDOWS |
747 | int timeout; | 744 | int timeout; |
748 | struct timeval *tv = (struct timeval *)ptr; | 745 | struct timeval *tv = (struct timeval *)ptr; |
749 | 746 | ||
750 | sz.i = sizeof(timeout); | 747 | sz.i = sizeof(timeout); |
751 | if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | 748 | if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, |
752 | (void*)&timeout, &sz.i) < 0) | 749 | (void*)&timeout, &sz.i) < 0) { |
753 | { perror("getsockopt"); ret = -1; } | 750 | perror("getsockopt"); |
754 | else | 751 | ret = -1; |
755 | { | 752 | } else { |
756 | tv->tv_sec = timeout / 1000; | 753 | tv->tv_sec = timeout / 1000; |
757 | tv->tv_usec = (timeout % 1000) * 1000; | 754 | tv->tv_usec = (timeout % 1000) * 1000; |
758 | ret = sizeof(*tv); | 755 | ret = sizeof(*tv); |
759 | } | 756 | } |
760 | #else | 757 | #else |
761 | sz.i = sizeof(struct timeval); | 758 | sz.i = sizeof(struct timeval); |
762 | if ( getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | 759 | if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, |
763 | ptr, (void *)&sz) < 0) | 760 | ptr, (void *)&sz) < 0) { |
764 | { perror("getsockopt"); ret = -1; } | 761 | perror("getsockopt"); |
765 | else if (sizeof(sz.s)!=sizeof(sz.i) && sz.i==0) | 762 | ret = -1; |
766 | { | 763 | } else if (sizeof(sz.s)!=sizeof(sz.i) && sz.i==0) { |
767 | OPENSSL_assert(sz.s<=sizeof(struct timeval)); | 764 | OPENSSL_assert(sz.s <= sizeof(struct timeval)); |
768 | ret = (int)sz.s; | 765 | ret = (int)sz.s; |
769 | } | 766 | } else |
770 | else | 767 | ret = sz.i; |
771 | ret = sz.i; | ||
772 | #endif | 768 | #endif |
773 | } | 769 | } |
774 | break; | 770 | break; |
@@ -777,47 +773,53 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
777 | case BIO_CTRL_DGRAM_SET_SEND_TIMEOUT: | 773 | case BIO_CTRL_DGRAM_SET_SEND_TIMEOUT: |
778 | #ifdef OPENSSL_SYS_WINDOWS | 774 | #ifdef OPENSSL_SYS_WINDOWS |
779 | { | 775 | { |
780 | struct timeval *tv = (struct timeval *)ptr; | 776 | struct timeval *tv = (struct timeval *)ptr; |
781 | int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000; | 777 | int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000; |
782 | if (setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, | 778 | if (setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, |
783 | (void*)&timeout, sizeof(timeout)) < 0) | 779 | (void*)&timeout, sizeof(timeout)) < 0) { |
784 | { perror("setsockopt"); ret = -1; } | 780 | perror("setsockopt"); |
781 | ret = -1; | ||
782 | } | ||
785 | } | 783 | } |
786 | #else | 784 | #else |
787 | if ( setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, ptr, | 785 | if (setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, ptr, |
788 | sizeof(struct timeval)) < 0) | 786 | sizeof(struct timeval)) < 0) { |
789 | { perror("setsockopt"); ret = -1; } | 787 | perror("setsockopt"); |
788 | ret = -1; | ||
789 | } | ||
790 | #endif | 790 | #endif |
791 | break; | 791 | break; |
792 | case BIO_CTRL_DGRAM_GET_SEND_TIMEOUT: | 792 | case BIO_CTRL_DGRAM_GET_SEND_TIMEOUT: |
793 | { | 793 | { |
794 | union { size_t s; int i; } sz = {0}; | 794 | union { |
795 | size_t s; | ||
796 | int i; | ||
797 | } sz = {0}; | ||
795 | #ifdef OPENSSL_SYS_WINDOWS | 798 | #ifdef OPENSSL_SYS_WINDOWS |
796 | int timeout; | 799 | int timeout; |
797 | struct timeval *tv = (struct timeval *)ptr; | 800 | struct timeval *tv = (struct timeval *)ptr; |
798 | 801 | ||
799 | sz.i = sizeof(timeout); | 802 | sz.i = sizeof(timeout); |
800 | if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, | 803 | if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, |
801 | (void*)&timeout, &sz.i) < 0) | 804 | (void*)&timeout, &sz.i) < 0) { |
802 | { perror("getsockopt"); ret = -1; } | 805 | perror("getsockopt"); |
803 | else | 806 | ret = -1; |
804 | { | 807 | } else { |
805 | tv->tv_sec = timeout / 1000; | 808 | tv->tv_sec = timeout / 1000; |
806 | tv->tv_usec = (timeout % 1000) * 1000; | 809 | tv->tv_usec = (timeout % 1000) * 1000; |
807 | ret = sizeof(*tv); | 810 | ret = sizeof(*tv); |
808 | } | 811 | } |
809 | #else | 812 | #else |
810 | sz.i = sizeof(struct timeval); | 813 | sz.i = sizeof(struct timeval); |
811 | if ( getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, | 814 | if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, |
812 | ptr, (void *)&sz) < 0) | 815 | ptr, (void *)&sz) < 0) { |
813 | { perror("getsockopt"); ret = -1; } | 816 | perror("getsockopt"); |
814 | else if (sizeof(sz.s)!=sizeof(sz.i) && sz.i==0) | 817 | ret = -1; |
815 | { | 818 | } else if (sizeof(sz.s) != sizeof(sz.i) && sz.i == 0) { |
816 | OPENSSL_assert(sz.s<=sizeof(struct timeval)); | 819 | OPENSSL_assert(sz.s <= sizeof(struct timeval)); |
817 | ret = (int)sz.s; | 820 | ret = (int)sz.s; |
818 | } | 821 | } else |
819 | else | 822 | ret = sz.i; |
820 | ret = sz.i; | ||
821 | #endif | 823 | #endif |
822 | } | 824 | } |
823 | break; | 825 | break; |
@@ -826,52 +828,52 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
826 | /* fall-through */ | 828 | /* fall-through */ |
827 | case BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP: | 829 | case BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP: |
828 | #ifdef OPENSSL_SYS_WINDOWS | 830 | #ifdef OPENSSL_SYS_WINDOWS |
829 | if ( data->_errno == WSAETIMEDOUT) | 831 | if (data->_errno == WSAETIMEDOUT) |
830 | #else | 832 | #else |
831 | if ( data->_errno == EAGAIN) | 833 | if (data->_errno == EAGAIN) |
832 | #endif | 834 | #endif |
833 | { | 835 | { |
834 | ret = 1; | 836 | ret = 1; |
835 | data->_errno = 0; | 837 | data->_errno = 0; |
836 | } | 838 | } else |
837 | else | ||
838 | ret = 0; | 839 | ret = 0; |
839 | break; | 840 | break; |
840 | #ifdef EMSGSIZE | 841 | #ifdef EMSGSIZE |
841 | case BIO_CTRL_DGRAM_MTU_EXCEEDED: | 842 | case BIO_CTRL_DGRAM_MTU_EXCEEDED: |
842 | if ( data->_errno == EMSGSIZE) | 843 | if (data->_errno == EMSGSIZE) { |
843 | { | ||
844 | ret = 1; | 844 | ret = 1; |
845 | data->_errno = 0; | 845 | data->_errno = 0; |
846 | } | 846 | } else |
847 | else | ||
848 | ret = 0; | 847 | ret = 0; |
849 | break; | 848 | break; |
850 | #endif | 849 | #endif |
851 | default: | 850 | default: |
852 | ret=0; | 851 | ret = 0; |
853 | break; | 852 | break; |
854 | } | ||
855 | return(ret); | ||
856 | } | 853 | } |
854 | return (ret); | ||
855 | } | ||
857 | 856 | ||
858 | static int dgram_puts(BIO *bp, const char *str) | 857 | static int |
859 | { | 858 | dgram_puts(BIO *bp, const char *str) |
860 | int n,ret; | 859 | { |
860 | int n, ret; | ||
861 | 861 | ||
862 | n=strlen(str); | 862 | n = strlen(str); |
863 | ret=dgram_write(bp,str,n); | 863 | ret = dgram_write(bp, str, n); |
864 | return(ret); | 864 | return (ret); |
865 | } | 865 | } |
866 | 866 | ||
867 | #ifndef OPENSSL_NO_SCTP | 867 | #ifndef OPENSSL_NO_SCTP |
868 | BIO_METHOD *BIO_s_datagram_sctp(void) | 868 | BIO_METHOD |
869 | { | 869 | *BIO_s_datagram_sctp(void) |
870 | return(&methods_dgramp_sctp); | 870 | { |
871 | } | 871 | return (&methods_dgramp_sctp); |
872 | } | ||
872 | 873 | ||
873 | BIO *BIO_new_dgram_sctp(int fd, int close_flag) | 874 | BIO |
874 | { | 875 | *BIO_new_dgram_sctp(int fd, int close_flag) |
876 | { | ||
875 | BIO *bio; | 877 | BIO *bio; |
876 | int ret, optval = 20000; | 878 | int ret, optval = 20000; |
877 | int auth_data = 0, auth_forward = 0; | 879 | int auth_data = 0, auth_forward = 0; |
@@ -887,9 +889,10 @@ BIO *BIO_new_dgram_sctp(int fd, int close_flag) | |||
887 | #endif | 889 | #endif |
888 | #endif | 890 | #endif |
889 | 891 | ||
890 | bio=BIO_new(BIO_s_datagram_sctp()); | 892 | bio = BIO_new(BIO_s_datagram_sctp()); |
891 | if (bio == NULL) return(NULL); | 893 | if (bio == NULL) |
892 | BIO_set_fd(bio,fd,close_flag); | 894 | return (NULL); |
895 | BIO_set_fd(bio, fd, close_flag); | ||
893 | 896 | ||
894 | /* Activate SCTP-AUTH for DATA and FORWARD-TSN chunks */ | 897 | /* Activate SCTP-AUTH for DATA and FORWARD-TSN chunks */ |
895 | auth.sauth_chunk = OPENSSL_SCTP_DATA_CHUNK_TYPE; | 898 | auth.sauth_chunk = OPENSSL_SCTP_DATA_CHUNK_TYPE; |
@@ -909,13 +912,14 @@ BIO *BIO_new_dgram_sctp(int fd, int close_flag) | |||
909 | OPENSSL_assert(ret >= 0); | 912 | OPENSSL_assert(ret >= 0); |
910 | 913 | ||
911 | for (p = (unsigned char*) authchunks->gauth_chunks; | 914 | for (p = (unsigned char*) authchunks->gauth_chunks; |
912 | p < (unsigned char*) authchunks + sockopt_len; | 915 | p < (unsigned char*) authchunks + sockopt_len; |
913 | p += sizeof(uint8_t)) | 916 | p += sizeof(uint8_t)) { |
914 | { | 917 | if (*p == OPENSSL_SCTP_DATA_CHUNK_TYPE) |
915 | if (*p == OPENSSL_SCTP_DATA_CHUNK_TYPE) auth_data = 1; | 918 | auth_data = 1; |
916 | if (*p == OPENSSL_SCTP_FORWARD_CUM_TSN_CHUNK_TYPE) auth_forward = 1; | 919 | if (*p == OPENSSL_SCTP_FORWARD_CUM_TSN_CHUNK_TYPE) |
917 | } | 920 | auth_forward = 1; |
918 | 921 | } | |
922 | |||
919 | OPENSSL_free(authchunks); | 923 | OPENSSL_free(authchunks); |
920 | 924 | ||
921 | OPENSSL_assert(auth_data); | 925 | OPENSSL_assert(auth_data); |
@@ -947,20 +951,22 @@ BIO *BIO_new_dgram_sctp(int fd, int close_flag) | |||
947 | ret = setsockopt(fd, IPPROTO_SCTP, SCTP_PARTIAL_DELIVERY_POINT, &optval, sizeof(optval)); | 951 | ret = setsockopt(fd, IPPROTO_SCTP, SCTP_PARTIAL_DELIVERY_POINT, &optval, sizeof(optval)); |
948 | OPENSSL_assert(ret >= 0); | 952 | OPENSSL_assert(ret >= 0); |
949 | 953 | ||
950 | return(bio); | 954 | return (bio); |
951 | } | 955 | } |
952 | 956 | ||
953 | int BIO_dgram_is_sctp(BIO *bio) | 957 | int |
954 | { | 958 | BIO_dgram_is_sctp(BIO *bio) |
959 | { | ||
955 | return (BIO_method_type(bio) == BIO_TYPE_DGRAM_SCTP); | 960 | return (BIO_method_type(bio) == BIO_TYPE_DGRAM_SCTP); |
956 | } | 961 | } |
957 | 962 | ||
958 | static int dgram_sctp_new(BIO *bi) | 963 | static int |
959 | { | 964 | dgram_sctp_new(BIO *bi) |
965 | { | ||
960 | bio_dgram_sctp_data *data = NULL; | 966 | bio_dgram_sctp_data *data = NULL; |
961 | 967 | ||
962 | bi->init=0; | 968 | bi->init = 0; |
963 | bi->num=0; | 969 | bi->num = 0; |
964 | data = OPENSSL_malloc(sizeof(bio_dgram_sctp_data)); | 970 | data = OPENSSL_malloc(sizeof(bio_dgram_sctp_data)); |
965 | if (data == NULL) | 971 | if (data == NULL) |
966 | return 0; | 972 | return 0; |
@@ -968,46 +974,50 @@ static int dgram_sctp_new(BIO *bi) | |||
968 | #ifdef SCTP_PR_SCTP_NONE | 974 | #ifdef SCTP_PR_SCTP_NONE |
969 | data->prinfo.pr_policy = SCTP_PR_SCTP_NONE; | 975 | data->prinfo.pr_policy = SCTP_PR_SCTP_NONE; |
970 | #endif | 976 | #endif |
971 | bi->ptr = data; | 977 | bi->ptr = data; |
972 | 978 | ||
973 | bi->flags=0; | 979 | bi->flags = 0; |
974 | return(1); | 980 | return (1); |
975 | } | 981 | } |
976 | 982 | ||
977 | static int dgram_sctp_free(BIO *a) | 983 | static int |
978 | { | 984 | dgram_sctp_free(BIO *a) |
985 | { | ||
979 | bio_dgram_sctp_data *data; | 986 | bio_dgram_sctp_data *data; |
980 | 987 | ||
981 | if (a == NULL) return(0); | 988 | if (a == NULL) |
982 | if ( ! dgram_clear(a)) | 989 | return (0); |
990 | if (! dgram_clear(a)) | ||
983 | return 0; | 991 | return 0; |
984 | 992 | ||
985 | data = (bio_dgram_sctp_data *)a->ptr; | 993 | data = (bio_dgram_sctp_data *)a->ptr; |
986 | if(data != NULL) OPENSSL_free(data); | 994 | if (data != NULL) |
995 | OPENSSL_free(data); | ||
987 | 996 | ||
988 | return(1); | 997 | return (1); |
989 | } | 998 | } |
990 | 999 | ||
991 | #ifdef SCTP_AUTHENTICATION_EVENT | 1000 | #ifdef SCTP_AUTHENTICATION_EVENT |
992 | void dgram_sctp_handle_auth_free_key_event(BIO *b, union sctp_notification *snp) | 1001 | void |
993 | { | 1002 | dgram_sctp_handle_auth_free_key_event(BIO *b, union sctp_notification *snp) |
1003 | { | ||
994 | int ret; | 1004 | int ret; |
995 | struct sctp_authkey_event* authkeyevent = &snp->sn_auth_event; | 1005 | struct sctp_authkey_event* authkeyevent = &snp->sn_auth_event; |
996 | 1006 | ||
997 | if (authkeyevent->auth_indication == SCTP_AUTH_FREE_KEY) | 1007 | if (authkeyevent->auth_indication == SCTP_AUTH_FREE_KEY) { |
998 | { | ||
999 | struct sctp_authkeyid authkeyid; | 1008 | struct sctp_authkeyid authkeyid; |
1000 | 1009 | ||
1001 | /* delete key */ | 1010 | /* delete key */ |
1002 | authkeyid.scact_keynumber = authkeyevent->auth_keynumber; | 1011 | authkeyid.scact_keynumber = authkeyevent->auth_keynumber; |
1003 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DELETE_KEY, | 1012 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DELETE_KEY, |
1004 | &authkeyid, sizeof(struct sctp_authkeyid)); | 1013 | &authkeyid, sizeof(struct sctp_authkeyid)); |
1005 | } | ||
1006 | } | 1014 | } |
1015 | } | ||
1007 | #endif | 1016 | #endif |
1008 | 1017 | ||
1009 | static int dgram_sctp_read(BIO *b, char *out, int outl) | 1018 | static int |
1010 | { | 1019 | dgram_sctp_read(BIO *b, char *out, int outl) |
1020 | { | ||
1011 | int ret = 0, n = 0, i, optval; | 1021 | int ret = 0, n = 0, i, optval; |
1012 | socklen_t optlen; | 1022 | socklen_t optlen; |
1013 | bio_dgram_sctp_data *data = (bio_dgram_sctp_data *)b->ptr; | 1023 | bio_dgram_sctp_data *data = (bio_dgram_sctp_data *)b->ptr; |
@@ -1017,12 +1027,10 @@ static int dgram_sctp_read(BIO *b, char *out, int outl) | |||
1017 | struct cmsghdr *cmsg; | 1027 | struct cmsghdr *cmsg; |
1018 | char cmsgbuf[512]; | 1028 | char cmsgbuf[512]; |
1019 | 1029 | ||
1020 | if (out != NULL) | 1030 | if (out != NULL) { |
1021 | { | ||
1022 | errno = 0; | 1031 | errno = 0; |
1023 | 1032 | ||
1024 | do | 1033 | do { |
1025 | { | ||
1026 | memset(&data->rcvinfo, 0x00, sizeof(struct bio_dgram_sctp_rcvinfo)); | 1034 | memset(&data->rcvinfo, 0x00, sizeof(struct bio_dgram_sctp_rcvinfo)); |
1027 | iov.iov_base = out; | 1035 | iov.iov_base = out; |
1028 | iov.iov_len = outl; | 1036 | iov.iov_len = outl; |
@@ -1035,15 +1043,12 @@ static int dgram_sctp_read(BIO *b, char *out, int outl) | |||
1035 | msg.msg_flags = 0; | 1043 | msg.msg_flags = 0; |
1036 | n = recvmsg(b->num, &msg, 0); | 1044 | n = recvmsg(b->num, &msg, 0); |
1037 | 1045 | ||
1038 | if (msg.msg_controllen > 0) | 1046 | if (msg.msg_controllen > 0) { |
1039 | { | 1047 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) { |
1040 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) | ||
1041 | { | ||
1042 | if (cmsg->cmsg_level != IPPROTO_SCTP) | 1048 | if (cmsg->cmsg_level != IPPROTO_SCTP) |
1043 | continue; | 1049 | continue; |
1044 | #ifdef SCTP_RCVINFO | 1050 | #ifdef SCTP_RCVINFO |
1045 | if (cmsg->cmsg_type == SCTP_RCVINFO) | 1051 | if (cmsg->cmsg_type == SCTP_RCVINFO) { |
1046 | { | ||
1047 | struct sctp_rcvinfo *rcvinfo; | 1052 | struct sctp_rcvinfo *rcvinfo; |
1048 | 1053 | ||
1049 | rcvinfo = (struct sctp_rcvinfo *)CMSG_DATA(cmsg); | 1054 | rcvinfo = (struct sctp_rcvinfo *)CMSG_DATA(cmsg); |
@@ -1054,11 +1059,10 @@ static int dgram_sctp_read(BIO *b, char *out, int outl) | |||
1054 | data->rcvinfo.rcv_tsn = rcvinfo->rcv_tsn; | 1059 | data->rcvinfo.rcv_tsn = rcvinfo->rcv_tsn; |
1055 | data->rcvinfo.rcv_cumtsn = rcvinfo->rcv_cumtsn; | 1060 | data->rcvinfo.rcv_cumtsn = rcvinfo->rcv_cumtsn; |
1056 | data->rcvinfo.rcv_context = rcvinfo->rcv_context; | 1061 | data->rcvinfo.rcv_context = rcvinfo->rcv_context; |
1057 | } | 1062 | } |
1058 | #endif | 1063 | #endif |
1059 | #ifdef SCTP_SNDRCV | 1064 | #ifdef SCTP_SNDRCV |
1060 | if (cmsg->cmsg_type == SCTP_SNDRCV) | 1065 | if (cmsg->cmsg_type == SCTP_SNDRCV) { |
1061 | { | ||
1062 | struct sctp_sndrcvinfo *sndrcvinfo; | 1066 | struct sctp_sndrcvinfo *sndrcvinfo; |
1063 | 1067 | ||
1064 | sndrcvinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); | 1068 | sndrcvinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); |
@@ -1069,23 +1073,20 @@ static int dgram_sctp_read(BIO *b, char *out, int outl) | |||
1069 | data->rcvinfo.rcv_tsn = sndrcvinfo->sinfo_tsn; | 1073 | data->rcvinfo.rcv_tsn = sndrcvinfo->sinfo_tsn; |
1070 | data->rcvinfo.rcv_cumtsn = sndrcvinfo->sinfo_cumtsn; | 1074 | data->rcvinfo.rcv_cumtsn = sndrcvinfo->sinfo_cumtsn; |
1071 | data->rcvinfo.rcv_context = sndrcvinfo->sinfo_context; | 1075 | data->rcvinfo.rcv_context = sndrcvinfo->sinfo_context; |
1072 | } | ||
1073 | #endif | ||
1074 | } | 1076 | } |
1077 | #endif | ||
1075 | } | 1078 | } |
1079 | } | ||
1076 | 1080 | ||
1077 | if (n <= 0) | 1081 | if (n <= 0) { |
1078 | { | ||
1079 | if (n < 0) | 1082 | if (n < 0) |
1080 | ret = n; | 1083 | ret = n; |
1081 | break; | 1084 | break; |
1082 | } | 1085 | } |
1083 | 1086 | ||
1084 | if (msg.msg_flags & MSG_NOTIFICATION) | 1087 | if (msg.msg_flags & MSG_NOTIFICATION) { |
1085 | { | ||
1086 | snp = (union sctp_notification*) out; | 1088 | snp = (union sctp_notification*) out; |
1087 | if (snp->sn_header.sn_type == SCTP_SENDER_DRY_EVENT) | 1089 | if (snp->sn_header.sn_type == SCTP_SENDER_DRY_EVENT) { |
1088 | { | ||
1089 | #ifdef SCTP_EVENT | 1090 | #ifdef SCTP_EVENT |
1090 | struct sctp_event event; | 1091 | struct sctp_event event; |
1091 | #else | 1092 | #else |
@@ -1095,13 +1096,12 @@ static int dgram_sctp_read(BIO *b, char *out, int outl) | |||
1095 | /* If a message has been delayed until the socket | 1096 | /* If a message has been delayed until the socket |
1096 | * is dry, it can be sent now. | 1097 | * is dry, it can be sent now. |
1097 | */ | 1098 | */ |
1098 | if (data->saved_message.length > 0) | 1099 | if (data->saved_message.length > 0) { |
1099 | { | ||
1100 | dgram_sctp_write(data->saved_message.bio, data->saved_message.data, | 1100 | dgram_sctp_write(data->saved_message.bio, data->saved_message.data, |
1101 | data->saved_message.length); | 1101 | data->saved_message.length); |
1102 | OPENSSL_free(data->saved_message.data); | 1102 | OPENSSL_free(data->saved_message.data); |
1103 | data->saved_message.length = 0; | 1103 | data->saved_message.length = 0; |
1104 | } | 1104 | } |
1105 | 1105 | ||
1106 | /* disable sender dry event */ | 1106 | /* disable sender dry event */ |
1107 | #ifdef SCTP_EVENT | 1107 | #ifdef SCTP_EVENT |
@@ -1121,7 +1121,7 @@ static int dgram_sctp_read(BIO *b, char *out, int outl) | |||
1121 | i = setsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, sizeof(struct sctp_event_subscribe)); | 1121 | i = setsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, sizeof(struct sctp_event_subscribe)); |
1122 | OPENSSL_assert(i >= 0); | 1122 | OPENSSL_assert(i >= 0); |
1123 | #endif | 1123 | #endif |
1124 | } | 1124 | } |
1125 | 1125 | ||
1126 | #ifdef SCTP_AUTHENTICATION_EVENT | 1126 | #ifdef SCTP_AUTHENTICATION_EVENT |
1127 | if (snp->sn_header.sn_type == SCTP_AUTHENTICATION_EVENT) | 1127 | if (snp->sn_header.sn_type == SCTP_AUTHENTICATION_EVENT) |
@@ -1132,14 +1132,12 @@ static int dgram_sctp_read(BIO *b, char *out, int outl) | |||
1132 | data->handle_notifications(b, data->notification_context, (void*) out); | 1132 | data->handle_notifications(b, data->notification_context, (void*) out); |
1133 | 1133 | ||
1134 | memset(out, 0, outl); | 1134 | memset(out, 0, outl); |
1135 | } | 1135 | } else |
1136 | else | ||
1137 | ret += n; | 1136 | ret += n; |
1138 | } | 1137 | } |
1139 | while ((msg.msg_flags & MSG_NOTIFICATION) && (msg.msg_flags & MSG_EOR) && (ret < outl)); | 1138 | while ((msg.msg_flags & MSG_NOTIFICATION) && (msg.msg_flags & MSG_EOR) && (ret < outl)); |
1140 | 1139 | ||
1141 | if (ret > 0 && !(msg.msg_flags & MSG_EOR)) | 1140 | if (ret > 0 && !(msg.msg_flags & MSG_EOR)) { |
1142 | { | ||
1143 | /* Partial message read, this should never happen! */ | 1141 | /* Partial message read, this should never happen! */ |
1144 | 1142 | ||
1145 | /* The buffer was too small, this means the peer sent | 1143 | /* The buffer was too small, this means the peer sent |
@@ -1159,8 +1157,8 @@ static int dgram_sctp_read(BIO *b, char *out, int outl) | |||
1159 | * max record size (2^14 + 2048 + 13) | 1157 | * max record size (2^14 + 2048 + 13) |
1160 | */ | 1158 | */ |
1161 | optlen = (socklen_t) sizeof(int); | 1159 | optlen = (socklen_t) sizeof(int); |
1162 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_PARTIAL_DELIVERY_POINT, | 1160 | ret = getsockopt(b->num, IPPROTO_SCTP, |
1163 | &optval, &optlen); | 1161 | SCTP_PARTIAL_DELIVERY_POINT, &optval, &optlen); |
1164 | OPENSSL_assert(ret >= 0); | 1162 | OPENSSL_assert(ret >= 0); |
1165 | OPENSSL_assert(optval >= 18445); | 1163 | OPENSSL_assert(optval >= 18445); |
1166 | 1164 | ||
@@ -1173,21 +1171,18 @@ static int dgram_sctp_read(BIO *b, char *out, int outl) | |||
1173 | memset(out, 0, outl); | 1171 | memset(out, 0, outl); |
1174 | BIO_set_retry_read(b); | 1172 | BIO_set_retry_read(b); |
1175 | return -1; | 1173 | return -1; |
1176 | } | 1174 | } |
1177 | 1175 | ||
1178 | BIO_clear_retry_flags(b); | 1176 | BIO_clear_retry_flags(b); |
1179 | if (ret < 0) | 1177 | if (ret < 0) { |
1180 | { | 1178 | if (BIO_dgram_should_retry(ret)) { |
1181 | if (BIO_dgram_should_retry(ret)) | ||
1182 | { | ||
1183 | BIO_set_retry_read(b); | 1179 | BIO_set_retry_read(b); |
1184 | data->_errno = errno; | 1180 | data->_errno = errno; |
1185 | } | ||
1186 | } | 1181 | } |
1182 | } | ||
1187 | 1183 | ||
1188 | /* Test if peer uses SCTP-AUTH before continuing */ | 1184 | /* Test if peer uses SCTP-AUTH before continuing */ |
1189 | if (!data->peer_auth_tested) | 1185 | if (!data->peer_auth_tested) { |
1190 | { | ||
1191 | int ii, auth_data = 0, auth_forward = 0; | 1186 | int ii, auth_data = 0, auth_forward = 0; |
1192 | unsigned char *p; | 1187 | unsigned char *p; |
1193 | struct sctp_authchunks *authchunks; | 1188 | struct sctp_authchunks *authchunks; |
@@ -1199,29 +1194,30 @@ static int dgram_sctp_read(BIO *b, char *out, int outl) | |||
1199 | OPENSSL_assert(ii >= 0); | 1194 | OPENSSL_assert(ii >= 0); |
1200 | 1195 | ||
1201 | for (p = (unsigned char*) authchunks->gauth_chunks; | 1196 | for (p = (unsigned char*) authchunks->gauth_chunks; |
1202 | p < (unsigned char*) authchunks + optlen; | 1197 | p < (unsigned char*) authchunks + optlen; |
1203 | p += sizeof(uint8_t)) | 1198 | p += sizeof(uint8_t)) { |
1204 | { | 1199 | if (*p == OPENSSL_SCTP_DATA_CHUNK_TYPE) |
1205 | if (*p == OPENSSL_SCTP_DATA_CHUNK_TYPE) auth_data = 1; | 1200 | auth_data = 1; |
1206 | if (*p == OPENSSL_SCTP_FORWARD_CUM_TSN_CHUNK_TYPE) auth_forward = 1; | 1201 | if (*p == OPENSSL_SCTP_FORWARD_CUM_TSN_CHUNK_TYPE) |
1207 | } | 1202 | auth_forward = 1; |
1203 | } | ||
1208 | 1204 | ||
1209 | OPENSSL_free(authchunks); | 1205 | OPENSSL_free(authchunks); |
1210 | 1206 | ||
1211 | if (!auth_data || !auth_forward) | 1207 | if (!auth_data || !auth_forward) { |
1212 | { | 1208 | BIOerr(BIO_F_DGRAM_SCTP_READ, BIO_R_CONNECT_ERROR); |
1213 | BIOerr(BIO_F_DGRAM_SCTP_READ,BIO_R_CONNECT_ERROR); | ||
1214 | return -1; | 1209 | return -1; |
1215 | } | 1210 | } |
1216 | 1211 | ||
1217 | data->peer_auth_tested = 1; | 1212 | data->peer_auth_tested = 1; |
1218 | } | ||
1219 | } | 1213 | } |
1220 | return(ret); | ||
1221 | } | 1214 | } |
1215 | return (ret); | ||
1216 | } | ||
1222 | 1217 | ||
1223 | static int dgram_sctp_write(BIO *b, const char *in, int inl) | 1218 | static int |
1224 | { | 1219 | dgram_sctp_write(BIO *b, const char *in, int inl) |
1220 | { | ||
1225 | int ret; | 1221 | int ret; |
1226 | bio_dgram_sctp_data *data = (bio_dgram_sctp_data *)b->ptr; | 1222 | bio_dgram_sctp_data *data = (bio_dgram_sctp_data *)b->ptr; |
1227 | struct bio_dgram_sctp_sndinfo *sinfo = &(data->sndinfo); | 1223 | struct bio_dgram_sctp_sndinfo *sinfo = &(data->sndinfo); |
@@ -1256,8 +1252,7 @@ static int dgram_sctp_write(BIO *b, const char *in, int inl) | |||
1256 | * socket is not dry yet, we have to save it and send it | 1252 | * socket is not dry yet, we have to save it and send it |
1257 | * as soon as the socket gets dry. | 1253 | * as soon as the socket gets dry. |
1258 | */ | 1254 | */ |
1259 | if (data->save_shutdown && !BIO_dgram_sctp_wait_for_dry(b)) | 1255 | if (data->save_shutdown && !BIO_dgram_sctp_wait_for_dry(b)) { |
1260 | { | ||
1261 | data->saved_message.bio = b; | 1256 | data->saved_message.bio = b; |
1262 | data->saved_message.length = inl; | 1257 | data->saved_message.length = inl; |
1263 | data->saved_message.data = OPENSSL_malloc(inl); | 1258 | data->saved_message.data = OPENSSL_malloc(inl); |
@@ -1317,20 +1312,20 @@ static int dgram_sctp_write(BIO *b, const char *in, int inl) | |||
1317 | ret = sendmsg(b->num, &msg, 0); | 1312 | ret = sendmsg(b->num, &msg, 0); |
1318 | 1313 | ||
1319 | BIO_clear_retry_flags(b); | 1314 | BIO_clear_retry_flags(b); |
1320 | if (ret <= 0) | 1315 | if (ret <= 0) { |
1321 | { | 1316 | if (BIO_dgram_should_retry(ret)) { |
1322 | if (BIO_dgram_should_retry(ret)) | 1317 | BIO_set_retry_write(b); |
1323 | { | 1318 | |
1324 | BIO_set_retry_write(b); | ||
1325 | data->_errno = errno; | 1319 | data->_errno = errno; |
1326 | } | ||
1327 | } | 1320 | } |
1328 | return(ret); | ||
1329 | } | 1321 | } |
1322 | return (ret); | ||
1323 | } | ||
1330 | 1324 | ||
1331 | static long dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr) | 1325 | static long |
1332 | { | 1326 | dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr) |
1333 | long ret=1; | 1327 | { |
1328 | long ret = 1; | ||
1334 | bio_dgram_sctp_data *data = NULL; | 1329 | bio_dgram_sctp_data *data = NULL; |
1335 | socklen_t sockopt_len = 0; | 1330 | socklen_t sockopt_len = 0; |
1336 | struct sctp_authkeyid authkeyid; | 1331 | struct sctp_authkeyid authkeyid; |
@@ -1338,8 +1333,7 @@ static long dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
1338 | 1333 | ||
1339 | data = (bio_dgram_sctp_data *)b->ptr; | 1334 | data = (bio_dgram_sctp_data *)b->ptr; |
1340 | 1335 | ||
1341 | switch (cmd) | 1336 | switch (cmd) { |
1342 | { | ||
1343 | case BIO_CTRL_DGRAM_QUERY_MTU: | 1337 | case BIO_CTRL_DGRAM_QUERY_MTU: |
1344 | /* Set to maximum (2^14) | 1338 | /* Set to maximum (2^14) |
1345 | * and ignore user input to enable transport | 1339 | * and ignore user input to enable transport |
@@ -1384,7 +1378,8 @@ static long dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
1384 | /* Get active key */ | 1378 | /* Get active key */ |
1385 | sockopt_len = sizeof(struct sctp_authkeyid); | 1379 | sockopt_len = sizeof(struct sctp_authkeyid); |
1386 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len); | 1380 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len); |
1387 | if (ret < 0) break; | 1381 | if (ret < 0) |
1382 | break; | ||
1388 | 1383 | ||
1389 | /* Add new key */ | 1384 | /* Add new key */ |
1390 | sockopt_len = sizeof(struct sctp_authkey) + 64 * sizeof(uint8_t); | 1385 | sockopt_len = sizeof(struct sctp_authkey) + 64 * sizeof(uint8_t); |
@@ -1400,12 +1395,14 @@ static long dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
1400 | memcpy(&authkey->sca_key[0], ptr, 64 * sizeof(uint8_t)); | 1395 | memcpy(&authkey->sca_key[0], ptr, 64 * sizeof(uint8_t)); |
1401 | 1396 | ||
1402 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_KEY, authkey, sockopt_len); | 1397 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_KEY, authkey, sockopt_len); |
1403 | if (ret < 0) break; | 1398 | if (ret < 0) |
1399 | break; | ||
1404 | 1400 | ||
1405 | /* Reset active key */ | 1401 | /* Reset active key */ |
1406 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, | 1402 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, |
1407 | &authkeyid, sizeof(struct sctp_authkeyid)); | 1403 | &authkeyid, sizeof(struct sctp_authkeyid)); |
1408 | if (ret < 0) break; | 1404 | if (ret < 0) |
1405 | break; | ||
1409 | 1406 | ||
1410 | break; | 1407 | break; |
1411 | case BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY: | 1408 | case BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY: |
@@ -1414,13 +1411,15 @@ static long dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
1414 | /* Get active key */ | 1411 | /* Get active key */ |
1415 | sockopt_len = sizeof(struct sctp_authkeyid); | 1412 | sockopt_len = sizeof(struct sctp_authkeyid); |
1416 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len); | 1413 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len); |
1417 | if (ret < 0) break; | 1414 | if (ret < 0) |
1415 | break; | ||
1418 | 1416 | ||
1419 | /* Set active key */ | 1417 | /* Set active key */ |
1420 | authkeyid.scact_keynumber = authkeyid.scact_keynumber + 1; | 1418 | authkeyid.scact_keynumber = authkeyid.scact_keynumber + 1; |
1421 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, | 1419 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, |
1422 | &authkeyid, sizeof(struct sctp_authkeyid)); | 1420 | &authkeyid, sizeof(struct sctp_authkeyid)); |
1423 | if (ret < 0) break; | 1421 | if (ret < 0) |
1422 | break; | ||
1424 | 1423 | ||
1425 | /* CCS has been sent, so remember that and fall through | 1424 | /* CCS has been sent, so remember that and fall through |
1426 | * to check if we need to deactivate an old key | 1425 | * to check if we need to deactivate an old key |
@@ -1435,12 +1434,12 @@ static long dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
1435 | data->ccs_rcvd = 1; | 1434 | data->ccs_rcvd = 1; |
1436 | 1435 | ||
1437 | /* CSS has been both, received and sent, so deactivate an old key */ | 1436 | /* CSS has been both, received and sent, so deactivate an old key */ |
1438 | if (data->ccs_rcvd == 1 && data->ccs_sent == 1) | 1437 | if (data->ccs_rcvd == 1 && data->ccs_sent == 1) { |
1439 | { | ||
1440 | /* Get active key */ | 1438 | /* Get active key */ |
1441 | sockopt_len = sizeof(struct sctp_authkeyid); | 1439 | sockopt_len = sizeof(struct sctp_authkeyid); |
1442 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len); | 1440 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len); |
1443 | if (ret < 0) break; | 1441 | if (ret < 0) |
1442 | break; | ||
1444 | 1443 | ||
1445 | /* Deactivate key or delete second last key if | 1444 | /* Deactivate key or delete second last key if |
1446 | * SCTP_AUTHENTICATION_EVENT is not available. | 1445 | * SCTP_AUTHENTICATION_EVENT is not available. |
@@ -1449,22 +1448,23 @@ static long dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
1449 | #ifdef SCTP_AUTH_DEACTIVATE_KEY | 1448 | #ifdef SCTP_AUTH_DEACTIVATE_KEY |
1450 | sockopt_len = sizeof(struct sctp_authkeyid); | 1449 | sockopt_len = sizeof(struct sctp_authkeyid); |
1451 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DEACTIVATE_KEY, | 1450 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DEACTIVATE_KEY, |
1452 | &authkeyid, sockopt_len); | 1451 | &authkeyid, sockopt_len); |
1453 | if (ret < 0) break; | 1452 | if (ret < 0) |
1453 | break; | ||
1454 | #endif | 1454 | #endif |
1455 | #ifndef SCTP_AUTHENTICATION_EVENT | 1455 | #ifndef SCTP_AUTHENTICATION_EVENT |
1456 | if (authkeyid.scact_keynumber > 0) | 1456 | if (authkeyid.scact_keynumber > 0) { |
1457 | { | ||
1458 | authkeyid.scact_keynumber = authkeyid.scact_keynumber - 1; | 1457 | authkeyid.scact_keynumber = authkeyid.scact_keynumber - 1; |
1459 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DELETE_KEY, | 1458 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DELETE_KEY, |
1460 | &authkeyid, sizeof(struct sctp_authkeyid)); | 1459 | &authkeyid, sizeof(struct sctp_authkeyid)); |
1461 | if (ret < 0) break; | 1460 | if (ret < 0) |
1462 | } | 1461 | break; |
1462 | } | ||
1463 | #endif | 1463 | #endif |
1464 | 1464 | ||
1465 | data->ccs_rcvd = 0; | 1465 | data->ccs_rcvd = 0; |
1466 | data->ccs_sent = 0; | 1466 | data->ccs_sent = 0; |
1467 | } | 1467 | } |
1468 | break; | 1468 | break; |
1469 | case BIO_CTRL_DGRAM_SCTP_GET_SNDINFO: | 1469 | case BIO_CTRL_DGRAM_SCTP_GET_SNDINFO: |
1470 | /* Returns the size of the copied struct. */ | 1470 | /* Returns the size of the copied struct. */ |
@@ -1524,30 +1524,30 @@ static long dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
1524 | /* Pass to default ctrl function to | 1524 | /* Pass to default ctrl function to |
1525 | * process SCTP unspecific commands | 1525 | * process SCTP unspecific commands |
1526 | */ | 1526 | */ |
1527 | ret=dgram_ctrl(b, cmd, num, ptr); | 1527 | ret = dgram_ctrl(b, cmd, num, ptr); |
1528 | break; | 1528 | break; |
1529 | } | ||
1530 | return(ret); | ||
1531 | } | 1529 | } |
1530 | return (ret); | ||
1531 | } | ||
1532 | 1532 | ||
1533 | int BIO_dgram_sctp_notification_cb(BIO *b, | 1533 | int |
1534 | void (*handle_notifications)(BIO *bio, void *context, void *buf), | 1534 | BIO_dgram_sctp_notification_cb(BIO *b, |
1535 | void *context) | 1535 | void (*handle_notifications)(BIO *bio, void *context, void *buf), |
1536 | { | 1536 | void *context) |
1537 | { | ||
1537 | bio_dgram_sctp_data *data = (bio_dgram_sctp_data *) b->ptr; | 1538 | bio_dgram_sctp_data *data = (bio_dgram_sctp_data *) b->ptr; |
1538 | 1539 | ||
1539 | if (handle_notifications != NULL) | 1540 | if (handle_notifications != NULL) { |
1540 | { | ||
1541 | data->handle_notifications = handle_notifications; | 1541 | data->handle_notifications = handle_notifications; |
1542 | data->notification_context = context; | 1542 | data->notification_context = context; |
1543 | } | 1543 | } else |
1544 | else | ||
1545 | return -1; | 1544 | return -1; |
1546 | 1545 | ||
1547 | return 0; | 1546 | return 0; |
1548 | } | 1547 | } |
1549 | 1548 | ||
1550 | int BIO_dgram_sctp_wait_for_dry(BIO *b) | 1549 | int |
1550 | BIO_dgram_sctp_wait_for_dry(BIO *b) | ||
1551 | { | 1551 | { |
1552 | int is_dry = 0; | 1552 | int is_dry = 0; |
1553 | int n, sockflags, ret; | 1553 | int n, sockflags, ret; |
@@ -1574,9 +1574,9 @@ int BIO_dgram_sctp_wait_for_dry(BIO *b) | |||
1574 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, &eventsize); | 1574 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, &eventsize); |
1575 | if (ret < 0) | 1575 | if (ret < 0) |
1576 | return -1; | 1576 | return -1; |
1577 | 1577 | ||
1578 | event.sctp_sender_dry_event = 1; | 1578 | event.sctp_sender_dry_event = 1; |
1579 | 1579 | ||
1580 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, sizeof(struct sctp_event_subscribe)); | 1580 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, sizeof(struct sctp_event_subscribe)); |
1581 | #endif | 1581 | #endif |
1582 | if (ret < 0) | 1582 | if (ret < 0) |
@@ -1595,17 +1595,15 @@ int BIO_dgram_sctp_wait_for_dry(BIO *b) | |||
1595 | msg.msg_flags = 0; | 1595 | msg.msg_flags = 0; |
1596 | 1596 | ||
1597 | n = recvmsg(b->num, &msg, MSG_PEEK); | 1597 | n = recvmsg(b->num, &msg, MSG_PEEK); |
1598 | if (n <= 0) | 1598 | if (n <= 0) { |
1599 | { | ||
1600 | if ((n < 0) && (errno != EAGAIN) && (errno != EWOULDBLOCK)) | 1599 | if ((n < 0) && (errno != EAGAIN) && (errno != EWOULDBLOCK)) |
1601 | return -1; | 1600 | return -1; |
1602 | else | 1601 | else |
1603 | return 0; | 1602 | return 0; |
1604 | } | 1603 | } |
1605 | 1604 | ||
1606 | /* if we find a notification, process it and try again if necessary */ | 1605 | /* if we find a notification, process it and try again if necessary */ |
1607 | while (msg.msg_flags & MSG_NOTIFICATION) | 1606 | while (msg.msg_flags & MSG_NOTIFICATION) { |
1608 | { | ||
1609 | memset(&snp, 0x00, sizeof(union sctp_notification)); | 1607 | memset(&snp, 0x00, sizeof(union sctp_notification)); |
1610 | iov.iov_base = (char *)&snp; | 1608 | iov.iov_base = (char *)&snp; |
1611 | iov.iov_len = sizeof(union sctp_notification); | 1609 | iov.iov_len = sizeof(union sctp_notification); |
@@ -1618,16 +1616,14 @@ int BIO_dgram_sctp_wait_for_dry(BIO *b) | |||
1618 | msg.msg_flags = 0; | 1616 | msg.msg_flags = 0; |
1619 | 1617 | ||
1620 | n = recvmsg(b->num, &msg, 0); | 1618 | n = recvmsg(b->num, &msg, 0); |
1621 | if (n <= 0) | 1619 | if (n <= 0) { |
1622 | { | ||
1623 | if ((n < 0) && (errno != EAGAIN) && (errno != EWOULDBLOCK)) | 1620 | if ((n < 0) && (errno != EAGAIN) && (errno != EWOULDBLOCK)) |
1624 | return -1; | 1621 | return -1; |
1625 | else | 1622 | else |
1626 | return is_dry; | 1623 | return is_dry; |
1627 | } | 1624 | } |
1628 | 1625 | ||
1629 | if (snp.sn_header.sn_type == SCTP_SENDER_DRY_EVENT) | 1626 | if (snp.sn_header.sn_type == SCTP_SENDER_DRY_EVENT) { |
1630 | { | ||
1631 | is_dry = 1; | 1627 | is_dry = 1; |
1632 | 1628 | ||
1633 | /* disable sender dry event */ | 1629 | /* disable sender dry event */ |
@@ -1649,7 +1645,7 @@ int BIO_dgram_sctp_wait_for_dry(BIO *b) | |||
1649 | #endif | 1645 | #endif |
1650 | if (ret < 0) | 1646 | if (ret < 0) |
1651 | return -1; | 1647 | return -1; |
1652 | } | 1648 | } |
1653 | 1649 | ||
1654 | #ifdef SCTP_AUTHENTICATION_EVENT | 1650 | #ifdef SCTP_AUTHENTICATION_EVENT |
1655 | if (snp.sn_header.sn_type == SCTP_AUTHENTICATION_EVENT) | 1651 | if (snp.sn_header.sn_type == SCTP_AUTHENTICATION_EVENT) |
@@ -1672,34 +1668,32 @@ int BIO_dgram_sctp_wait_for_dry(BIO *b) | |||
1672 | msg.msg_flags = 0; | 1668 | msg.msg_flags = 0; |
1673 | 1669 | ||
1674 | /* if we have seen the dry already, don't wait */ | 1670 | /* if we have seen the dry already, don't wait */ |
1675 | if (is_dry) | 1671 | if (is_dry) { |
1676 | { | ||
1677 | sockflags = fcntl(b->num, F_GETFL, 0); | 1672 | sockflags = fcntl(b->num, F_GETFL, 0); |
1678 | fcntl(b->num, F_SETFL, O_NONBLOCK); | 1673 | fcntl(b->num, F_SETFL, O_NONBLOCK); |
1679 | } | 1674 | } |
1680 | 1675 | ||
1681 | n = recvmsg(b->num, &msg, MSG_PEEK); | 1676 | n = recvmsg(b->num, &msg, MSG_PEEK); |
1682 | 1677 | ||
1683 | if (is_dry) | 1678 | if (is_dry) { |
1684 | { | ||
1685 | fcntl(b->num, F_SETFL, sockflags); | 1679 | fcntl(b->num, F_SETFL, sockflags); |
1686 | } | 1680 | } |
1687 | 1681 | ||
1688 | if (n <= 0) | 1682 | if (n <= 0) { |
1689 | { | ||
1690 | if ((n < 0) && (errno != EAGAIN) && (errno != EWOULDBLOCK)) | 1683 | if ((n < 0) && (errno != EAGAIN) && (errno != EWOULDBLOCK)) |
1691 | return -1; | 1684 | return -1; |
1692 | else | 1685 | else |
1693 | return is_dry; | 1686 | return is_dry; |
1694 | } | ||
1695 | } | 1687 | } |
1688 | } | ||
1696 | 1689 | ||
1697 | /* read anything else */ | 1690 | /* read anything else */ |
1698 | return is_dry; | 1691 | return is_dry; |
1699 | } | 1692 | } |
1700 | 1693 | ||
1701 | int BIO_dgram_sctp_msg_waiting(BIO *b) | 1694 | int |
1702 | { | 1695 | BIO_dgram_sctp_msg_waiting(BIO *b) |
1696 | { | ||
1703 | int n, sockflags; | 1697 | int n, sockflags; |
1704 | union sctp_notification snp; | 1698 | union sctp_notification snp; |
1705 | struct msghdr msg; | 1699 | struct msghdr msg; |
@@ -1708,7 +1702,7 @@ int BIO_dgram_sctp_msg_waiting(BIO *b) | |||
1708 | 1702 | ||
1709 | /* Check if there are any messages waiting to be read */ | 1703 | /* Check if there are any messages waiting to be read */ |
1710 | do | 1704 | do |
1711 | { | 1705 | { |
1712 | memset(&snp, 0x00, sizeof(union sctp_notification)); | 1706 | memset(&snp, 0x00, sizeof(union sctp_notification)); |
1713 | iov.iov_base = (char *)&snp; | 1707 | iov.iov_base = (char *)&snp; |
1714 | iov.iov_len = sizeof(union sctp_notification); | 1708 | iov.iov_len = sizeof(union sctp_notification); |
@@ -1726,8 +1720,7 @@ int BIO_dgram_sctp_msg_waiting(BIO *b) | |||
1726 | fcntl(b->num, F_SETFL, sockflags); | 1720 | fcntl(b->num, F_SETFL, sockflags); |
1727 | 1721 | ||
1728 | /* if notification, process and try again */ | 1722 | /* if notification, process and try again */ |
1729 | if (n > 0 && (msg.msg_flags & MSG_NOTIFICATION)) | 1723 | if (n > 0 && (msg.msg_flags & MSG_NOTIFICATION)) { |
1730 | { | ||
1731 | #ifdef SCTP_AUTHENTICATION_EVENT | 1724 | #ifdef SCTP_AUTHENTICATION_EVENT |
1732 | if (snp.sn_header.sn_type == SCTP_AUTHENTICATION_EVENT) | 1725 | if (snp.sn_header.sn_type == SCTP_AUTHENTICATION_EVENT) |
1733 | dgram_sctp_handle_auth_free_key_event(b, &snp); | 1726 | dgram_sctp_handle_auth_free_key_event(b, &snp); |
@@ -1747,34 +1740,35 @@ int BIO_dgram_sctp_msg_waiting(BIO *b) | |||
1747 | 1740 | ||
1748 | if (data->handle_notifications != NULL) | 1741 | if (data->handle_notifications != NULL) |
1749 | data->handle_notifications(b, data->notification_context, (void*) &snp); | 1742 | data->handle_notifications(b, data->notification_context, (void*) &snp); |
1750 | } | 1743 | } |
1751 | 1744 | ||
1752 | } while (n > 0 && (msg.msg_flags & MSG_NOTIFICATION)); | 1745 | } while (n > 0 && (msg.msg_flags & MSG_NOTIFICATION)); |
1753 | 1746 | ||
1754 | /* Return 1 if there is a message to be read, return 0 otherwise. */ | 1747 | /* Return 1 if there is a message to be read, return 0 otherwise. */ |
1755 | if (n > 0) | 1748 | if (n > 0) |
1756 | return 1; | 1749 | return 1; |
1757 | else | 1750 | else |
1758 | return 0; | 1751 | return 0; |
1759 | } | 1752 | } |
1760 | 1753 | ||
1761 | static int dgram_sctp_puts(BIO *bp, const char *str) | 1754 | static int |
1762 | { | 1755 | dgram_sctp_puts(BIO *bp, const char *str) |
1763 | int n,ret; | 1756 | { |
1757 | int n, ret; | ||
1764 | 1758 | ||
1765 | n=strlen(str); | 1759 | n = strlen(str); |
1766 | ret=dgram_sctp_write(bp,str,n); | 1760 | ret = dgram_sctp_write(bp, str, n); |
1767 | return(ret); | 1761 | return (ret); |
1768 | } | 1762 | } |
1769 | #endif | 1763 | #endif |
1770 | 1764 | ||
1771 | static int BIO_dgram_should_retry(int i) | 1765 | static int |
1772 | { | 1766 | BIO_dgram_should_retry(int i) |
1767 | { | ||
1773 | int err; | 1768 | int err; |
1774 | 1769 | ||
1775 | if ((i == 0) || (i == -1)) | 1770 | if ((i == 0) || (i == -1)) { |
1776 | { | 1771 | err = errno; |
1777 | err=errno; | ||
1778 | 1772 | ||
1779 | #if defined(OPENSSL_SYS_WINDOWS) | 1773 | #if defined(OPENSSL_SYS_WINDOWS) |
1780 | /* If the socket return value (i) is -1 | 1774 | /* If the socket return value (i) is -1 |
@@ -1785,15 +1779,15 @@ static int BIO_dgram_should_retry(int i) | |||
1785 | */ | 1779 | */ |
1786 | #endif | 1780 | #endif |
1787 | 1781 | ||
1788 | return(BIO_dgram_non_fatal_error(err)); | 1782 | return (BIO_dgram_non_fatal_error(err)); |
1789 | } | ||
1790 | return(0); | ||
1791 | } | 1783 | } |
1784 | return (0); | ||
1785 | } | ||
1792 | 1786 | ||
1793 | int BIO_dgram_non_fatal_error(int err) | 1787 | int |
1794 | { | 1788 | BIO_dgram_non_fatal_error(int err) |
1795 | switch (err) | 1789 | { |
1796 | { | 1790 | switch (err) { |
1797 | #if defined(OPENSSL_SYS_WINDOWS) | 1791 | #if defined(OPENSSL_SYS_WINDOWS) |
1798 | # if defined(WSAEWOULDBLOCK) | 1792 | # if defined(WSAEWOULDBLOCK) |
1799 | case WSAEWOULDBLOCK: | 1793 | case WSAEWOULDBLOCK: |
@@ -1838,17 +1832,17 @@ int BIO_dgram_non_fatal_error(int err) | |||
1838 | case EALREADY: | 1832 | case EALREADY: |
1839 | #endif | 1833 | #endif |
1840 | 1834 | ||
1841 | return(1); | 1835 | return (1); |
1842 | /* break; */ | 1836 | /* break; */ |
1843 | default: | 1837 | default: |
1844 | break; | 1838 | break; |
1845 | } | ||
1846 | return(0); | ||
1847 | } | 1839 | } |
1840 | return (0); | ||
1841 | } | ||
1848 | 1842 | ||
1849 | static void get_current_time(struct timeval *t) | 1843 | static void |
1850 | { | 1844 | get_current_time(struct timeval *t) { |
1851 | gettimeofday(t, NULL); | 1845 | gettimeofday(t, NULL); |
1852 | } | 1846 | } |
1853 | 1847 | ||
1854 | #endif | 1848 | #endif |
diff --git a/src/lib/libcrypto/bio/bss_fd.c b/src/lib/libcrypto/bio/bss_fd.c index ab18a56310..35ddd61359 100644 --- a/src/lib/libcrypto/bio/bss_fd.c +++ b/src/lib/libcrypto/bio/bss_fd.c | |||
@@ -90,9 +90,8 @@ static int fd_new(BIO *h); | |||
90 | static int fd_free(BIO *data); | 90 | static int fd_free(BIO *data); |
91 | int BIO_fd_should_retry(int s); | 91 | int BIO_fd_should_retry(int s); |
92 | 92 | ||
93 | static BIO_METHOD methods_fdp= | 93 | static BIO_METHOD methods_fdp = { |
94 | { | 94 | BIO_TYPE_FD, "file descriptor", |
95 | BIO_TYPE_FD,"file descriptor", | ||
96 | fd_write, | 95 | fd_write, |
97 | fd_read, | 96 | fd_read, |
98 | fd_puts, | 97 | fd_puts, |
@@ -101,178 +100,182 @@ static BIO_METHOD methods_fdp= | |||
101 | fd_new, | 100 | fd_new, |
102 | fd_free, | 101 | fd_free, |
103 | NULL, | 102 | NULL, |
104 | }; | 103 | }; |
105 | 104 | ||
106 | BIO_METHOD *BIO_s_fd(void) | 105 | BIO_METHOD |
107 | { | 106 | *BIO_s_fd(void) |
108 | return(&methods_fdp); | 107 | { |
109 | } | 108 | return (&methods_fdp); |
109 | } | ||
110 | 110 | ||
111 | BIO *BIO_new_fd(int fd,int close_flag) | 111 | BIO |
112 | { | 112 | *BIO_new_fd(int fd, int close_flag) |
113 | { | ||
113 | BIO *ret; | 114 | BIO *ret; |
114 | ret=BIO_new(BIO_s_fd()); | 115 | ret = BIO_new(BIO_s_fd()); |
115 | if (ret == NULL) return(NULL); | 116 | if (ret == NULL) |
116 | BIO_set_fd(ret,fd,close_flag); | 117 | return (NULL); |
117 | return(ret); | 118 | BIO_set_fd(ret, fd, close_flag); |
118 | } | 119 | return (ret); |
120 | } | ||
119 | 121 | ||
120 | static int fd_new(BIO *bi) | 122 | static int |
121 | { | 123 | fd_new(BIO *bi) |
122 | bi->init=0; | 124 | { |
123 | bi->num=-1; | 125 | bi->init = 0; |
124 | bi->ptr=NULL; | 126 | bi->num = -1; |
127 | bi->ptr = NULL; | ||
125 | bi->flags=BIO_FLAGS_UPLINK; /* essentially redundant */ | 128 | bi->flags=BIO_FLAGS_UPLINK; /* essentially redundant */ |
126 | return(1); | 129 | return (1); |
127 | } | 130 | } |
128 | 131 | ||
129 | static int fd_free(BIO *a) | 132 | static int |
130 | { | 133 | fd_free(BIO *a) |
131 | if (a == NULL) return(0); | 134 | { |
132 | if (a->shutdown) | 135 | if (a == NULL) |
133 | { | 136 | return (0); |
134 | if (a->init) | 137 | if (a->shutdown) { |
135 | { | 138 | if (a->init) { |
136 | UP_close(a->num); | 139 | UP_close(a->num); |
137 | } | ||
138 | a->init=0; | ||
139 | a->flags=BIO_FLAGS_UPLINK; | ||
140 | } | 140 | } |
141 | return(1); | 141 | a->init = 0; |
142 | a->flags = BIO_FLAGS_UPLINK; | ||
142 | } | 143 | } |
143 | 144 | return (1); | |
144 | static int fd_read(BIO *b, char *out,int outl) | 145 | } |
145 | { | ||
146 | int ret=0; | ||
147 | 146 | ||
148 | if (out != NULL) | 147 | static int |
149 | { | 148 | fd_read(BIO *b, char *out, int outl) |
149 | { | ||
150 | int ret = 0; | ||
151 | |||
152 | if (out != NULL) { | ||
150 | errno = 0; | 153 | errno = 0; |
151 | ret=UP_read(b->num,out,outl); | 154 | ret = UP_read(b->num, out, outl); |
152 | BIO_clear_retry_flags(b); | 155 | BIO_clear_retry_flags(b); |
153 | if (ret <= 0) | 156 | if (ret <= 0) { |
154 | { | ||
155 | if (BIO_fd_should_retry(ret)) | 157 | if (BIO_fd_should_retry(ret)) |
156 | BIO_set_retry_read(b); | 158 | BIO_set_retry_read(b); |
157 | } | ||
158 | } | 159 | } |
159 | return(ret); | ||
160 | } | 160 | } |
161 | return (ret); | ||
162 | } | ||
161 | 163 | ||
162 | static int fd_write(BIO *b, const char *in, int inl) | 164 | static int |
163 | { | 165 | fd_write(BIO *b, const char *in, int inl) |
166 | { | ||
164 | int ret; | 167 | int ret; |
165 | errno = 0; | 168 | errno = 0; |
166 | ret=UP_write(b->num,in,inl); | 169 | ret = UP_write(b->num, in, inl); |
167 | BIO_clear_retry_flags(b); | 170 | BIO_clear_retry_flags(b); |
168 | if (ret <= 0) | 171 | if (ret <= 0) { |
169 | { | ||
170 | if (BIO_fd_should_retry(ret)) | 172 | if (BIO_fd_should_retry(ret)) |
171 | BIO_set_retry_write(b); | 173 | BIO_set_retry_write(b); |
172 | } | ||
173 | return(ret); | ||
174 | } | 174 | } |
175 | return (ret); | ||
176 | } | ||
175 | 177 | ||
176 | static long fd_ctrl(BIO *b, int cmd, long num, void *ptr) | 178 | static long |
177 | { | 179 | fd_ctrl(BIO *b, int cmd, long num, void *ptr) |
178 | long ret=1; | 180 | { |
181 | long ret = 1; | ||
179 | int *ip; | 182 | int *ip; |
180 | 183 | ||
181 | switch (cmd) | 184 | switch (cmd) { |
182 | { | ||
183 | case BIO_CTRL_RESET: | 185 | case BIO_CTRL_RESET: |
184 | num=0; | 186 | num = 0; |
185 | case BIO_C_FILE_SEEK: | 187 | case BIO_C_FILE_SEEK: |
186 | ret=(long)UP_lseek(b->num,num,0); | 188 | ret = (long)UP_lseek(b->num, num, 0); |
187 | break; | 189 | break; |
188 | case BIO_C_FILE_TELL: | 190 | case BIO_C_FILE_TELL: |
189 | case BIO_CTRL_INFO: | 191 | case BIO_CTRL_INFO: |
190 | ret=(long)UP_lseek(b->num,0,1); | 192 | ret = (long)UP_lseek(b->num, 0, 1); |
191 | break; | 193 | break; |
192 | case BIO_C_SET_FD: | 194 | case BIO_C_SET_FD: |
193 | fd_free(b); | 195 | fd_free(b); |
194 | b->num= *((int *)ptr); | 196 | b->num= *((int *)ptr); |
195 | b->shutdown=(int)num; | 197 | b->shutdown = (int)num; |
196 | b->init=1; | 198 | b->init = 1; |
197 | break; | 199 | break; |
198 | case BIO_C_GET_FD: | 200 | case BIO_C_GET_FD: |
199 | if (b->init) | 201 | if (b->init) { |
200 | { | 202 | ip = (int *)ptr; |
201 | ip=(int *)ptr; | 203 | if (ip != NULL) |
202 | if (ip != NULL) *ip=b->num; | 204 | *ip = b->num; |
203 | ret=b->num; | 205 | ret = b->num; |
204 | } | 206 | } else |
205 | else | 207 | ret = -1; |
206 | ret= -1; | ||
207 | break; | 208 | break; |
208 | case BIO_CTRL_GET_CLOSE: | 209 | case BIO_CTRL_GET_CLOSE: |
209 | ret=b->shutdown; | 210 | ret = b->shutdown; |
210 | break; | 211 | break; |
211 | case BIO_CTRL_SET_CLOSE: | 212 | case BIO_CTRL_SET_CLOSE: |
212 | b->shutdown=(int)num; | 213 | b->shutdown = (int)num; |
213 | break; | 214 | break; |
214 | case BIO_CTRL_PENDING: | 215 | case BIO_CTRL_PENDING: |
215 | case BIO_CTRL_WPENDING: | 216 | case BIO_CTRL_WPENDING: |
216 | ret=0; | 217 | ret = 0; |
217 | break; | 218 | break; |
218 | case BIO_CTRL_DUP: | 219 | case BIO_CTRL_DUP: |
219 | case BIO_CTRL_FLUSH: | 220 | case BIO_CTRL_FLUSH: |
220 | ret=1; | 221 | ret = 1; |
221 | break; | 222 | break; |
222 | default: | 223 | default: |
223 | ret=0; | 224 | ret = 0; |
224 | break; | 225 | break; |
225 | } | ||
226 | return(ret); | ||
227 | } | 226 | } |
227 | return (ret); | ||
228 | } | ||
228 | 229 | ||
229 | static int fd_puts(BIO *bp, const char *str) | 230 | static int |
230 | { | 231 | fd_puts(BIO *bp, const char *str) |
231 | int n,ret; | 232 | { |
233 | int n, ret; | ||
232 | 234 | ||
233 | n=strlen(str); | 235 | n = strlen(str); |
234 | ret=fd_write(bp,str,n); | 236 | ret = fd_write(bp, str, n); |
235 | return(ret); | 237 | return (ret); |
236 | } | 238 | } |
237 | 239 | ||
238 | static int fd_gets(BIO *bp, char *buf, int size) | 240 | static int |
239 | { | 241 | fd_gets(BIO *bp, char *buf, int size) |
240 | int ret=0; | 242 | { |
241 | char *ptr=buf; | 243 | int ret = 0; |
242 | char *end=buf+size-1; | 244 | char *ptr = buf; |
245 | char *end = buf + size - 1; | ||
243 | 246 | ||
244 | while ( (ptr < end) && (fd_read(bp, ptr, 1) > 0) && (ptr[0] != '\n') ) | 247 | while ((ptr < end) && (fd_read(bp, ptr, 1) > 0) && (ptr[0] != '\n')) |
245 | ptr++; | 248 | ptr++; |
246 | 249 | ||
247 | ptr[0]='\0'; | 250 | ptr[0] = '\0'; |
248 | 251 | ||
249 | if (buf[0] != '\0') | 252 | if (buf[0] != '\0') |
250 | ret=strlen(buf); | 253 | ret = strlen(buf); |
251 | return(ret); | 254 | return (ret); |
252 | } | 255 | } |
253 | 256 | ||
254 | int BIO_fd_should_retry(int i) | 257 | int |
255 | { | 258 | BIO_fd_should_retry(int i) |
259 | { | ||
256 | int err; | 260 | int err; |
257 | 261 | ||
258 | if ((i == 0) || (i == -1)) | 262 | if ((i == 0) || (i == -1)) { |
259 | { | 263 | err = errno; |
260 | err=errno; | ||
261 | 264 | ||
262 | #if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */ | 265 | #if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */ |
263 | if ((i == -1) && (err == 0)) | 266 | if ((i == -1) && (err == 0)) |
264 | return(1); | 267 | return (1); |
265 | #endif | 268 | #endif |
266 | 269 | ||
267 | return(BIO_fd_non_fatal_error(err)); | 270 | return (BIO_fd_non_fatal_error(err)); |
268 | } | ||
269 | return(0); | ||
270 | } | 271 | } |
272 | return (0); | ||
273 | } | ||
271 | 274 | ||
272 | int BIO_fd_non_fatal_error(int err) | 275 | int |
273 | { | 276 | BIO_fd_non_fatal_error(int err) |
274 | switch (err) | 277 | { |
275 | { | 278 | switch (err) { |
276 | 279 | ||
277 | #ifdef EWOULDBLOCK | 280 | #ifdef EWOULDBLOCK |
278 | # ifdef WSAEWOULDBLOCK | 281 | # ifdef WSAEWOULDBLOCK |
@@ -309,11 +312,11 @@ int BIO_fd_non_fatal_error(int err) | |||
309 | #ifdef EALREADY | 312 | #ifdef EALREADY |
310 | case EALREADY: | 313 | case EALREADY: |
311 | #endif | 314 | #endif |
312 | return(1); | 315 | return (1); |
313 | /* break; */ | 316 | /* break; */ |
314 | default: | 317 | default: |
315 | break; | 318 | break; |
316 | } | ||
317 | return(0); | ||
318 | } | 319 | } |
320 | return (0); | ||
321 | } | ||
319 | #endif | 322 | #endif |
diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c index 638572ab7f..794f503a69 100644 --- a/src/lib/libcrypto/bio/bss_file.c +++ b/src/lib/libcrypto/bio/bss_file.c | |||
@@ -102,8 +102,8 @@ static int file_gets(BIO *h, char *str, int size); | |||
102 | static long file_ctrl(BIO *h, int cmd, long arg1, void *arg2); | 102 | static long file_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
103 | static int file_new(BIO *h); | 103 | static int file_new(BIO *h); |
104 | static int file_free(BIO *data); | 104 | static int file_free(BIO *data); |
105 | static BIO_METHOD methods_filep= | 105 | |
106 | { | 106 | static BIO_METHOD methods_filep = { |
107 | BIO_TYPE_FILE, | 107 | BIO_TYPE_FILE, |
108 | "FILE pointer", | 108 | "FILE pointer", |
109 | file_write, | 109 | file_write, |
@@ -114,15 +114,16 @@ static BIO_METHOD methods_filep= | |||
114 | file_new, | 114 | file_new, |
115 | file_free, | 115 | file_free, |
116 | NULL, | 116 | NULL, |
117 | }; | 117 | }; |
118 | 118 | ||
119 | BIO *BIO_new_file(const char *filename, const char *mode) | 119 | BIO |
120 | { | 120 | *BIO_new_file(const char *filename, const char *mode) |
121 | { | ||
121 | BIO *ret; | 122 | BIO *ret; |
122 | FILE *file=NULL; | 123 | FILE *file = NULL; |
123 | 124 | ||
124 | #if defined(_WIN32) && defined(CP_UTF8) | 125 | #if defined(_WIN32) && defined(CP_UTF8) |
125 | int sz, len_0 = (int)strlen(filename)+1; | 126 | int sz, len_0 = (int)strlen(filename) + 1; |
126 | DWORD flags; | 127 | DWORD flags; |
127 | 128 | ||
128 | /* | 129 | /* |
@@ -137,173 +138,171 @@ BIO *BIO_new_file(const char *filename, const char *mode) | |||
137 | * ERROR_NO_UNICODE_TRANSLATION, in which case we fall | 138 | * ERROR_NO_UNICODE_TRANSLATION, in which case we fall |
138 | * back to fopen... | 139 | * back to fopen... |
139 | */ | 140 | */ |
140 | if ((sz=MultiByteToWideChar(CP_UTF8,(flags=MB_ERR_INVALID_CHARS), | 141 | if ((sz = MultiByteToWideChar(CP_UTF8,(flags = MB_ERR_INVALID_CHARS), |
141 | filename,len_0,NULL,0))>0 || | 142 | filename, len_0, NULL, 0)) > 0 || |
142 | (GetLastError()==ERROR_INVALID_FLAGS && | 143 | (GetLastError() == ERROR_INVALID_FLAGS && |
143 | (sz=MultiByteToWideChar(CP_UTF8,(flags=0), | 144 | (sz = MultiByteToWideChar(CP_UTF8,(flags = 0), |
144 | filename,len_0,NULL,0))>0) | 145 | filename, len_0, NULL, 0)) > 0)) { |
145 | ) | ||
146 | { | ||
147 | WCHAR wmode[8]; | 146 | WCHAR wmode[8]; |
148 | WCHAR *wfilename = _alloca(sz*sizeof(WCHAR)); | 147 | WCHAR *wfilename = _alloca(sz*sizeof(WCHAR)); |
149 | 148 | ||
150 | if (MultiByteToWideChar(CP_UTF8,flags, | 149 | if (MultiByteToWideChar(CP_UTF8, flags, filename, len_0, |
151 | filename,len_0,wfilename,sz) && | 150 | wfilename, sz) && MultiByteToWideChar(CP_UTF8, 0, mode, |
152 | MultiByteToWideChar(CP_UTF8,0,mode,strlen(mode)+1, | 151 | strlen(mode) + 1, wmode, |
153 | wmode,sizeof(wmode)/sizeof(wmode[0])) && | 152 | sizeof(wmode) / sizeof(wmode[0])) && |
154 | (file=_wfopen(wfilename,wmode))==NULL && | 153 | (file = _wfopen(wfilename, wmode)) == NULL && |
155 | (errno==ENOENT || errno==EBADF) | 154 | (errno == ENOENT || errno == EBADF) |
156 | ) /* UTF-8 decode succeeded, but no file, filename | 155 | ) /* UTF - 8 decode succeeded, but no file, filename |
157 | * could still have been locale-ized... */ | 156 | * could still have been locale-ized... */ |
158 | file = fopen(filename,mode); | 157 | file = fopen(filename, mode); |
159 | } | 158 | } else if (GetLastError() == ERROR_NO_UNICODE_TRANSLATION) { |
160 | else if (GetLastError()==ERROR_NO_UNICODE_TRANSLATION) | 159 | file = fopen(filename, mode); |
161 | { | 160 | } |
162 | file = fopen(filename,mode); | ||
163 | } | ||
164 | #else | 161 | #else |
165 | file=fopen(filename,mode); | 162 | file = fopen(filename, mode); |
163 | |||
166 | #endif | 164 | #endif |
167 | if (file == NULL) | 165 | if (file == NULL) { |
168 | { | ||
169 | SYSerr(SYS_F_FOPEN, errno); | 166 | SYSerr(SYS_F_FOPEN, errno); |
170 | ERR_add_error_data(5,"fopen('",filename,"','",mode,"')"); | 167 | ERR_add_error_data(5, "fopen('", filename, "', '", mode, "')"); |
171 | if (errno == ENOENT) | 168 | if (errno == ENOENT) |
172 | BIOerr(BIO_F_BIO_NEW_FILE,BIO_R_NO_SUCH_FILE); | 169 | BIOerr(BIO_F_BIO_NEW_FILE, BIO_R_NO_SUCH_FILE); |
173 | else | 170 | else |
174 | BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB); | 171 | BIOerr(BIO_F_BIO_NEW_FILE, ERR_R_SYS_LIB); |
175 | return(NULL); | 172 | return (NULL); |
176 | } | 173 | } |
177 | if ((ret=BIO_new(BIO_s_file())) == NULL) | 174 | if ((ret = BIO_new(BIO_s_file())) == NULL) { |
178 | { | ||
179 | fclose(file); | 175 | fclose(file); |
180 | return(NULL); | 176 | return (NULL); |
181 | } | ||
182 | |||
183 | BIO_clear_flags(ret,BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */ | ||
184 | BIO_set_fp(ret,file,BIO_CLOSE); | ||
185 | return(ret); | ||
186 | } | 177 | } |
187 | 178 | ||
188 | BIO *BIO_new_fp(FILE *stream, int close_flag) | 179 | BIO_clear_flags(ret, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */ |
189 | { | 180 | BIO_set_fp(ret, file, BIO_CLOSE); |
190 | BIO *ret; | 181 | return (ret); |
191 | 182 | } | |
192 | if ((ret=BIO_new(BIO_s_file())) == NULL) | ||
193 | return(NULL); | ||
194 | |||
195 | BIO_set_flags(ret,BIO_FLAGS_UPLINK); /* redundant, left for documentation puposes */ | ||
196 | BIO_set_fp(ret,stream,close_flag); | ||
197 | return(ret); | ||
198 | } | ||
199 | 183 | ||
200 | BIO_METHOD *BIO_s_file(void) | 184 | BIO |
201 | { | 185 | *BIO_new_fp(FILE *stream, int close_flag) |
202 | return(&methods_filep); | 186 | { |
203 | } | 187 | BIO *ret; |
204 | 188 | ||
205 | static int file_new(BIO *bi) | 189 | if ((ret = BIO_new(BIO_s_file())) == NULL) |
206 | { | 190 | return (NULL); |
207 | bi->init=0; | 191 | |
208 | bi->num=0; | 192 | BIO_set_flags(ret, BIO_FLAGS_UPLINK); /* redundant, left for documentation puposes */ |
209 | bi->ptr=NULL; | 193 | BIO_set_fp(ret, stream, close_flag); |
194 | return (ret); | ||
195 | } | ||
196 | |||
197 | BIO_METHOD | ||
198 | *BIO_s_file(void) | ||
199 | { | ||
200 | return (&methods_filep); | ||
201 | } | ||
202 | |||
203 | static int | ||
204 | file_new(BIO *bi) | ||
205 | { | ||
206 | bi->init = 0; | ||
207 | bi->num = 0; | ||
208 | bi->ptr = NULL; | ||
210 | bi->flags=BIO_FLAGS_UPLINK; /* default to UPLINK */ | 209 | bi->flags=BIO_FLAGS_UPLINK; /* default to UPLINK */ |
211 | return(1); | 210 | return (1); |
212 | } | 211 | } |
213 | 212 | ||
214 | static int file_free(BIO *a) | 213 | static int |
215 | { | 214 | file_free(BIO *a) |
216 | if (a == NULL) return(0); | 215 | { |
217 | if (a->shutdown) | 216 | if (a == NULL) |
218 | { | 217 | return (0); |
219 | if ((a->init) && (a->ptr != NULL)) | 218 | if (a->shutdown) { |
220 | { | 219 | if ((a->init) && (a->ptr != NULL)) { |
221 | if (a->flags&BIO_FLAGS_UPLINK) | 220 | if (a->flags&BIO_FLAGS_UPLINK) |
222 | UP_fclose (a->ptr); | 221 | UP_fclose (a->ptr); |
223 | else | 222 | else |
224 | fclose (a->ptr); | 223 | fclose (a->ptr); |
225 | a->ptr=NULL; | 224 | a->ptr = NULL; |
226 | a->flags=BIO_FLAGS_UPLINK; | 225 | a->flags = BIO_FLAGS_UPLINK; |
227 | } | ||
228 | a->init=0; | ||
229 | } | 226 | } |
230 | return(1); | 227 | a->init = 0; |
231 | } | 228 | } |
232 | 229 | return (1); | |
233 | static int file_read(BIO *b, char *out, int outl) | 230 | } |
234 | { | ||
235 | int ret=0; | ||
236 | 231 | ||
237 | if (b->init && (out != NULL)) | 232 | static int |
238 | { | 233 | file_read(BIO *b, char *out, int outl) |
234 | { | ||
235 | int ret = 0; | ||
236 | |||
237 | if (b->init && (out != NULL)) { | ||
239 | if (b->flags&BIO_FLAGS_UPLINK) | 238 | if (b->flags&BIO_FLAGS_UPLINK) |
240 | ret=UP_fread(out,1,(int)outl,b->ptr); | 239 | ret = UP_fread(out, 1,(int)outl, b->ptr); |
241 | else | 240 | else |
242 | ret=fread(out,1,(int)outl,(FILE *)b->ptr); | 241 | ret = fread(out, 1,(int)outl,(FILE *)b->ptr); |
243 | if(ret == 0 && (b->flags&BIO_FLAGS_UPLINK)?UP_ferror((FILE *)b->ptr):ferror((FILE *)b->ptr)) | 242 | if (ret == 0 && (b->flags & BIO_FLAGS_UPLINK) ? |
244 | { | 243 | UP_ferror((FILE *)b->ptr) : ferror((FILE *)b->ptr)) { |
245 | SYSerr(SYS_F_FREAD, errno); | 244 | SYSerr(SYS_F_FREAD, errno); |
246 | BIOerr(BIO_F_FILE_READ,ERR_R_SYS_LIB); | 245 | BIOerr(BIO_F_FILE_READ, ERR_R_SYS_LIB); |
247 | ret=-1; | 246 | ret = -1; |
248 | } | ||
249 | } | 247 | } |
250 | return(ret); | ||
251 | } | 248 | } |
249 | return (ret); | ||
250 | } | ||
252 | 251 | ||
253 | static int file_write(BIO *b, const char *in, int inl) | 252 | static int |
254 | { | 253 | file_write(BIO *b, const char *in, int inl) |
255 | int ret=0; | 254 | { |
255 | int ret = 0; | ||
256 | 256 | ||
257 | if (b->init && (in != NULL)) | 257 | if (b->init && (in != NULL)) { |
258 | { | ||
259 | if (b->flags&BIO_FLAGS_UPLINK) | 258 | if (b->flags&BIO_FLAGS_UPLINK) |
260 | ret=UP_fwrite(in,(int)inl,1,b->ptr); | 259 | ret = UP_fwrite(in,(int)inl, 1, b->ptr); |
261 | else | 260 | else |
262 | ret=fwrite(in,(int)inl,1,(FILE *)b->ptr); | 261 | ret = fwrite(in,(int)inl, 1,(FILE *)b->ptr); |
263 | if (ret) | 262 | if (ret) |
264 | ret=inl; | 263 | ret = inl; |
265 | /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */ | 264 | /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */ |
266 | /* according to Tim Hudson <tjh@cryptsoft.com>, the commented | 265 | /* according to Tim Hudson <tjh@cryptsoft.com>, the commented |
267 | * out version above can cause 'inl' write calls under | 266 | * out version above can cause 'inl' write calls under |
268 | * some stupid stdio implementations (VMS) */ | 267 | * some stupid stdio implementations (VMS) */ |
269 | } | ||
270 | return(ret); | ||
271 | } | 268 | } |
272 | 269 | return (ret); | |
273 | static long file_ctrl(BIO *b, int cmd, long num, void *ptr) | 270 | } |
274 | { | 271 | |
275 | long ret=1; | 272 | static long |
276 | FILE *fp=(FILE *)b->ptr; | 273 | file_ctrl(BIO *b, int cmd, long num, void *ptr) |
274 | { | ||
275 | long ret = 1; | ||
276 | FILE *fp = (FILE *)b->ptr; | ||
277 | FILE **fpp; | 277 | FILE **fpp; |
278 | char p[4]; | 278 | char p[4]; |
279 | 279 | ||
280 | switch (cmd) | 280 | switch (cmd) { |
281 | { | ||
282 | case BIO_C_FILE_SEEK: | 281 | case BIO_C_FILE_SEEK: |
283 | case BIO_CTRL_RESET: | 282 | case BIO_CTRL_RESET: |
284 | if (b->flags&BIO_FLAGS_UPLINK) | 283 | if (b->flags&BIO_FLAGS_UPLINK) |
285 | ret=(long)UP_fseek(b->ptr,num,0); | 284 | ret = (long)UP_fseek(b->ptr, num, 0); |
286 | else | 285 | else |
287 | ret=(long)fseek(fp,num,0); | 286 | ret = (long)fseek(fp, num, 0); |
288 | break; | 287 | break; |
289 | case BIO_CTRL_EOF: | 288 | case BIO_CTRL_EOF: |
290 | if (b->flags&BIO_FLAGS_UPLINK) | 289 | if (b->flags&BIO_FLAGS_UPLINK) |
291 | ret=(long)UP_feof(fp); | 290 | ret = (long)UP_feof(fp); |
292 | else | 291 | else |
293 | ret=(long)feof(fp); | 292 | ret = (long)feof(fp); |
294 | break; | 293 | break; |
295 | case BIO_C_FILE_TELL: | 294 | case BIO_C_FILE_TELL: |
296 | case BIO_CTRL_INFO: | 295 | case BIO_CTRL_INFO: |
297 | if (b->flags&BIO_FLAGS_UPLINK) | 296 | if (b->flags&BIO_FLAGS_UPLINK) |
298 | ret=UP_ftell(b->ptr); | 297 | ret = UP_ftell(b->ptr); |
299 | else | 298 | else |
300 | ret=ftell(fp); | 299 | ret = ftell(fp); |
301 | break; | 300 | break; |
302 | case BIO_C_SET_FILE_PTR: | 301 | case BIO_C_SET_FILE_PTR: |
303 | file_free(b); | 302 | file_free(b); |
304 | b->shutdown=(int)num&BIO_CLOSE; | 303 | b->shutdown = (int)num&BIO_CLOSE; |
305 | b->ptr=ptr; | 304 | b->ptr = ptr; |
306 | b->init=1; | 305 | b->init = 1; |
307 | #if BIO_FLAGS_UPLINK!=0 | 306 | #if BIO_FLAGS_UPLINK!=0 |
308 | #if defined(__MINGW32__) && defined(__MSVCRT__) && !defined(_IOB_ENTRIES) | 307 | #if defined(__MINGW32__) && defined(__MSVCRT__) && !defined(_IOB_ENTRIES) |
309 | #define _IOB_ENTRIES 20 | 308 | #define _IOB_ENTRIES 20 |
@@ -311,8 +310,8 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
311 | #if defined(_IOB_ENTRIES) | 310 | #if defined(_IOB_ENTRIES) |
312 | /* Safety net to catch purely internal BIO_set_fp calls */ | 311 | /* Safety net to catch purely internal BIO_set_fp calls */ |
313 | if ((size_t)ptr >= (size_t)stdin && | 312 | if ((size_t)ptr >= (size_t)stdin && |
314 | (size_t)ptr < (size_t)(stdin+_IOB_ENTRIES)) | 313 | (size_t)ptr < (size_t)(stdin + _IOB_ENTRIES)) |
315 | BIO_clear_flags(b,BIO_FLAGS_UPLINK); | 314 | BIO_clear_flags(b, BIO_FLAGS_UPLINK); |
316 | #endif | 315 | #endif |
317 | #endif | 316 | #endif |
318 | #ifdef UP_fsetmod | 317 | #ifdef UP_fsetmod |
@@ -322,102 +321,94 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
322 | #endif | 321 | #endif |
323 | { | 322 | { |
324 | #if defined(OPENSSL_SYS_WINDOWS) | 323 | #if defined(OPENSSL_SYS_WINDOWS) |
325 | int fd = _fileno((FILE*)ptr); | 324 | int fd = _fileno((FILE*)ptr); |
326 | if (num & BIO_FP_TEXT) | 325 | if (num & BIO_FP_TEXT) |
327 | _setmode(fd,_O_TEXT); | 326 | _setmode(fd, _O_TEXT); |
328 | else | 327 | else |
329 | _setmode(fd,_O_BINARY); | 328 | _setmode(fd, _O_BINARY); |
330 | #elif defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB) | 329 | #elif defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB) |
331 | int fd = fileno((FILE*)ptr); | 330 | int fd = fileno((FILE*)ptr); |
332 | /* Under CLib there are differences in file modes */ | 331 | /* Under CLib there are differences in file modes */ |
333 | if (num & BIO_FP_TEXT) | 332 | if (num & BIO_FP_TEXT) |
334 | setmode(fd,O_TEXT); | 333 | setmode(fd, O_TEXT); |
335 | else | ||
336 | setmode(fd,O_BINARY); | ||
337 | #elif defined(OPENSSL_SYS_MSDOS) | ||
338 | int fd = fileno((FILE*)ptr); | ||
339 | /* Set correct text/binary mode */ | ||
340 | if (num & BIO_FP_TEXT) | ||
341 | _setmode(fd,_O_TEXT); | ||
342 | /* Dangerous to set stdin/stdout to raw (unless redirected) */ | ||
343 | else | ||
344 | { | ||
345 | if (fd == STDIN_FILENO || fd == STDOUT_FILENO) | ||
346 | { | ||
347 | if (isatty(fd) <= 0) | ||
348 | _setmode(fd,_O_BINARY); | ||
349 | } | ||
350 | else | 334 | else |
351 | _setmode(fd,_O_BINARY); | 335 | setmode(fd, O_BINARY); |
336 | #elif defined(OPENSSL_SYS_MSDOS) | ||
337 | int fd = fileno((FILE*)ptr); | ||
338 | /* Set correct text/binary mode */ | ||
339 | if (num & BIO_FP_TEXT) | ||
340 | _setmode(fd, _O_TEXT); | ||
341 | /* Dangerous to set stdin/stdout to raw (unless redirected) */ | ||
342 | else { | ||
343 | if (fd == STDIN_FILENO || fd == STDOUT_FILENO) { | ||
344 | if (isatty(fd) <= 0) | ||
345 | _setmode(fd, _O_BINARY); | ||
346 | } else | ||
347 | _setmode(fd, _O_BINARY); | ||
352 | } | 348 | } |
353 | #elif defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN) | 349 | #elif defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN) |
354 | int fd = fileno((FILE*)ptr); | 350 | int fd = fileno((FILE*)ptr); |
355 | if (num & BIO_FP_TEXT) | 351 | if (num & BIO_FP_TEXT) |
356 | setmode(fd, O_TEXT); | 352 | setmode(fd, O_TEXT); |
357 | else | 353 | else |
358 | setmode(fd, O_BINARY); | 354 | setmode(fd, O_BINARY); |
359 | #endif | 355 | #endif |
360 | } | 356 | } |
361 | break; | 357 | break; |
362 | case BIO_C_SET_FILENAME: | 358 | case BIO_C_SET_FILENAME: |
363 | file_free(b); | 359 | file_free(b); |
364 | b->shutdown=(int)num&BIO_CLOSE; | 360 | b->shutdown = (int)num&BIO_CLOSE; |
365 | if (num & BIO_FP_APPEND) | 361 | if (num & BIO_FP_APPEND) { |
366 | { | ||
367 | if (num & BIO_FP_READ) | 362 | if (num & BIO_FP_READ) |
368 | BUF_strlcpy(p,"a+",sizeof p); | 363 | BUF_strlcpy(p, "a+", sizeof p); |
369 | else BUF_strlcpy(p,"a",sizeof p); | 364 | else BUF_strlcpy(p, "a", sizeof p); |
370 | } | 365 | } else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE)) |
371 | else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE)) | 366 | BUF_strlcpy(p, "r+", sizeof p); |
372 | BUF_strlcpy(p,"r+",sizeof p); | ||
373 | else if (num & BIO_FP_WRITE) | 367 | else if (num & BIO_FP_WRITE) |
374 | BUF_strlcpy(p,"w",sizeof p); | 368 | BUF_strlcpy(p, "w", sizeof p); |
375 | else if (num & BIO_FP_READ) | 369 | else if (num & BIO_FP_READ) |
376 | BUF_strlcpy(p,"r",sizeof p); | 370 | BUF_strlcpy(p, "r", sizeof p); |
377 | else | 371 | else { |
378 | { | 372 | BIOerr(BIO_F_FILE_CTRL, BIO_R_BAD_FOPEN_MODE); |
379 | BIOerr(BIO_F_FILE_CTRL,BIO_R_BAD_FOPEN_MODE); | 373 | ret = 0; |
380 | ret=0; | ||
381 | break; | 374 | break; |
382 | } | 375 | } |
383 | #if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN) | 376 | #if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN) |
384 | if (!(num & BIO_FP_TEXT)) | 377 | if (!(num & BIO_FP_TEXT)) |
385 | strcat(p,"b"); | 378 | strcat(p, "b"); |
386 | else | 379 | else |
387 | strcat(p,"t"); | 380 | strcat(p, "t"); |
388 | #endif | 381 | #endif |
389 | #if defined(OPENSSL_SYS_NETWARE) | 382 | #if defined(OPENSSL_SYS_NETWARE) |
390 | if (!(num & BIO_FP_TEXT)) | 383 | if (!(num & BIO_FP_TEXT)) |
391 | strcat(p,"b"); | 384 | strcat(p, "b"); |
392 | else | 385 | else |
393 | strcat(p,"t"); | 386 | strcat(p, "t"); |
394 | #endif | 387 | #endif |
395 | fp=fopen(ptr,p); | 388 | fp = fopen(ptr, p); |
396 | if (fp == NULL) | 389 | if (fp == NULL) { |
397 | { | ||
398 | SYSerr(SYS_F_FOPEN, errno); | 390 | SYSerr(SYS_F_FOPEN, errno); |
399 | ERR_add_error_data(5,"fopen('",ptr,"','",p,"')"); | 391 | ERR_add_error_data(5, "fopen('", ptr, "', '", p, "')"); |
400 | BIOerr(BIO_F_FILE_CTRL,ERR_R_SYS_LIB); | 392 | BIOerr(BIO_F_FILE_CTRL, ERR_R_SYS_LIB); |
401 | ret=0; | 393 | ret = 0; |
402 | break; | 394 | break; |
403 | } | 395 | } |
404 | b->ptr=fp; | 396 | b->ptr = fp; |
405 | b->init=1; | 397 | b->init = 1; |
406 | BIO_clear_flags(b,BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */ | 398 | BIO_clear_flags(b, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */ |
407 | break; | 399 | break; |
408 | case BIO_C_GET_FILE_PTR: | 400 | case BIO_C_GET_FILE_PTR: |
409 | /* the ptr parameter is actually a FILE ** in this case. */ | 401 | /* the ptr parameter is actually a FILE ** in this case. */ |
410 | if (ptr != NULL) | 402 | if (ptr != NULL) { |
411 | { | 403 | fpp = (FILE **)ptr; |
412 | fpp=(FILE **)ptr; | 404 | *fpp = (FILE *)b->ptr; |
413 | *fpp=(FILE *)b->ptr; | 405 | } |
414 | } | ||
415 | break; | 406 | break; |
416 | case BIO_CTRL_GET_CLOSE: | 407 | case BIO_CTRL_GET_CLOSE: |
417 | ret=(long)b->shutdown; | 408 | ret = (long)b->shutdown; |
418 | break; | 409 | break; |
419 | case BIO_CTRL_SET_CLOSE: | 410 | case BIO_CTRL_SET_CLOSE: |
420 | b->shutdown=(int)num; | 411 | b->shutdown = (int)num; |
421 | break; | 412 | break; |
422 | case BIO_CTRL_FLUSH: | 413 | case BIO_CTRL_FLUSH: |
423 | if (b->flags&BIO_FLAGS_UPLINK) | 414 | if (b->flags&BIO_FLAGS_UPLINK) |
@@ -426,7 +417,7 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
426 | fflush((FILE *)b->ptr); | 417 | fflush((FILE *)b->ptr); |
427 | break; | 418 | break; |
428 | case BIO_CTRL_DUP: | 419 | case BIO_CTRL_DUP: |
429 | ret=1; | 420 | ret = 1; |
430 | break; | 421 | break; |
431 | 422 | ||
432 | case BIO_CTRL_WPENDING: | 423 | case BIO_CTRL_WPENDING: |
@@ -434,44 +425,41 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
434 | case BIO_CTRL_PUSH: | 425 | case BIO_CTRL_PUSH: |
435 | case BIO_CTRL_POP: | 426 | case BIO_CTRL_POP: |
436 | default: | 427 | default: |
437 | ret=0; | 428 | ret = 0; |
438 | break; | 429 | break; |
439 | } | ||
440 | return(ret); | ||
441 | } | 430 | } |
431 | return (ret); | ||
432 | } | ||
442 | 433 | ||
443 | static int file_gets(BIO *bp, char *buf, int size) | 434 | static int |
444 | { | 435 | file_gets(BIO *bp, char *buf, int size) |
445 | int ret=0; | 436 | { |
437 | int ret = 0; | ||
446 | 438 | ||
447 | buf[0]='\0'; | 439 | buf[0] = '\0'; |
448 | if (bp->flags&BIO_FLAGS_UPLINK) | 440 | if (bp->flags&BIO_FLAGS_UPLINK) { |
449 | { | 441 | if (!UP_fgets(buf, size, bp->ptr)) |
450 | if (!UP_fgets(buf,size,bp->ptr)) | ||
451 | goto err; | 442 | goto err; |
452 | } | 443 | } else { |
453 | else | 444 | if (!fgets(buf, size,(FILE *)bp->ptr)) |
454 | { | ||
455 | if (!fgets(buf,size,(FILE *)bp->ptr)) | ||
456 | goto err; | 445 | goto err; |
457 | } | ||
458 | if (buf[0] != '\0') | ||
459 | ret=strlen(buf); | ||
460 | err: | ||
461 | return(ret); | ||
462 | } | 446 | } |
447 | if (buf[0] != '\0') | ||
448 | ret = strlen(buf); | ||
449 | err: | ||
450 | return (ret); | ||
451 | } | ||
463 | 452 | ||
464 | static int file_puts(BIO *bp, const char *str) | 453 | static int |
465 | { | 454 | file_puts(BIO *bp, const char *str) |
466 | int n,ret; | 455 | { |
456 | int n, ret; | ||
467 | 457 | ||
468 | n=strlen(str); | 458 | n = strlen(str); |
469 | ret=file_write(bp,str,n); | 459 | ret = file_write(bp, str, n); |
470 | return(ret); | 460 | return (ret); |
471 | } | 461 | } |
472 | 462 | ||
473 | #endif /* OPENSSL_NO_STDIO */ | 463 | #endif /* OPENSSL_NO_STDIO */ |
474 | 464 | ||
475 | #endif /* HEADER_BSS_FILE_C */ | 465 | #endif /* HEADER_BSS_FILE_C */ |
476 | |||
477 | |||
diff --git a/src/lib/libcrypto/bio/bss_log.c b/src/lib/libcrypto/bio/bss_log.c index 1cc413a916..9225af4df2 100644 --- a/src/lib/libcrypto/bio/bss_log.c +++ b/src/lib/libcrypto/bio/bss_log.c | |||
@@ -80,7 +80,7 @@ | |||
80 | # if __INITIAL_POINTER_SIZE == 64 | 80 | # if __INITIAL_POINTER_SIZE == 64 |
81 | # pragma pointer_size save | 81 | # pragma pointer_size save |
82 | # pragma pointer_size 32 | 82 | # pragma pointer_size 32 |
83 | void * _malloc32 (__size_t); | 83 | void * _malloc32 (__size_t); |
84 | # pragma pointer_size restore | 84 | # pragma pointer_size restore |
85 | # endif /* __INITIAL_POINTER_SIZE == 64 */ | 85 | # endif /* __INITIAL_POINTER_SIZE == 64 */ |
86 | # endif /* __INITIAL_POINTER_SIZE && defined _ANSI_C_SOURCE */ | 86 | # endif /* __INITIAL_POINTER_SIZE && defined _ANSI_C_SOURCE */ |
@@ -131,9 +131,8 @@ static void xopenlog(BIO* bp, char* name, int level); | |||
131 | static void xsyslog(BIO* bp, int priority, const char* string); | 131 | static void xsyslog(BIO* bp, int priority, const char* string); |
132 | static void xcloselog(BIO* bp); | 132 | static void xcloselog(BIO* bp); |
133 | 133 | ||
134 | static BIO_METHOD methods_slg= | 134 | static BIO_METHOD methods_slg = { |
135 | { | 135 | BIO_TYPE_MEM, "syslog", |
136 | BIO_TYPE_MEM,"syslog", | ||
137 | slg_write, | 136 | slg_write, |
138 | NULL, | 137 | NULL, |
139 | slg_puts, | 138 | slg_puts, |
@@ -142,43 +141,46 @@ static BIO_METHOD methods_slg= | |||
142 | slg_new, | 141 | slg_new, |
143 | slg_free, | 142 | slg_free, |
144 | NULL, | 143 | NULL, |
145 | }; | 144 | }; |
146 | 145 | ||
147 | BIO_METHOD *BIO_s_log(void) | 146 | BIO_METHOD |
148 | { | 147 | *BIO_s_log(void) |
149 | return(&methods_slg); | 148 | { |
150 | } | 149 | return (&methods_slg); |
150 | } | ||
151 | 151 | ||
152 | static int slg_new(BIO *bi) | 152 | static int |
153 | { | 153 | slg_new(BIO *bi) |
154 | bi->init=1; | 154 | { |
155 | bi->num=0; | 155 | bi->init = 1; |
156 | bi->ptr=NULL; | 156 | bi->num = 0; |
157 | bi->ptr = NULL; | ||
157 | xopenlog(bi, "application", LOG_DAEMON); | 158 | xopenlog(bi, "application", LOG_DAEMON); |
158 | return(1); | 159 | return (1); |
159 | } | 160 | } |
160 | 161 | ||
161 | static int slg_free(BIO *a) | 162 | static int |
162 | { | 163 | slg_free(BIO *a) |
163 | if (a == NULL) return(0); | 164 | { |
165 | if (a == NULL) | ||
166 | return (0); | ||
164 | xcloselog(a); | 167 | xcloselog(a); |
165 | return(1); | 168 | return (1); |
166 | } | 169 | } |
167 | 170 | ||
168 | static int slg_write(BIO *b, const char *in, int inl) | 171 | static int |
169 | { | 172 | slg_write(BIO *b, const char *in, int inl) |
170 | int ret= inl; | 173 | { |
174 | int ret = inl; | ||
171 | char* buf; | 175 | char* buf; |
172 | char* pp; | 176 | char* pp; |
173 | int priority, i; | 177 | int priority, i; |
174 | static const struct | 178 | static const struct { |
175 | { | ||
176 | int strl; | 179 | int strl; |
177 | char str[10]; | 180 | char str[10]; |
178 | int log_level; | 181 | int log_level; |
179 | } | 182 | } |
180 | mapping[] = | 183 | mapping[] = { |
181 | { | ||
182 | { 6, "PANIC ", LOG_EMERG }, | 184 | { 6, "PANIC ", LOG_EMERG }, |
183 | { 6, "EMERG ", LOG_EMERG }, | 185 | { 6, "EMERG ", LOG_EMERG }, |
184 | { 4, "EMR ", LOG_EMERG }, | 186 | { 4, "EMR ", LOG_EMERG }, |
@@ -199,69 +201,72 @@ static int slg_write(BIO *b, const char *in, int inl) | |||
199 | { 6, "DEBUG ", LOG_DEBUG }, | 201 | { 6, "DEBUG ", LOG_DEBUG }, |
200 | { 4, "DBG ", LOG_DEBUG }, | 202 | { 4, "DBG ", LOG_DEBUG }, |
201 | { 0, "", LOG_ERR } /* The default */ | 203 | { 0, "", LOG_ERR } /* The default */ |
202 | }; | 204 | }; |
203 | 205 | ||
204 | if((buf= (char *)OPENSSL_malloc(inl+ 1)) == NULL){ | 206 | if ((buf = (char *)OPENSSL_malloc(inl + 1)) == NULL) { |
205 | return(0); | 207 | return (0); |
206 | } | 208 | } |
207 | strncpy(buf, in, inl); | 209 | strncpy(buf, in, inl); |
208 | buf[inl]= '\0'; | 210 | buf[inl] = '\0'; |
209 | 211 | ||
210 | i = 0; | 212 | i = 0; |
211 | while(strncmp(buf, mapping[i].str, mapping[i].strl) != 0) i++; | 213 | while (strncmp(buf, mapping[i].str, mapping[i].strl) != 0) |
214 | i++; | ||
212 | priority = mapping[i].log_level; | 215 | priority = mapping[i].log_level; |
213 | pp = buf + mapping[i].strl; | 216 | pp = buf + mapping[i].strl; |
214 | 217 | ||
215 | xsyslog(b, priority, pp); | 218 | xsyslog(b, priority, pp); |
216 | 219 | ||
217 | OPENSSL_free(buf); | 220 | OPENSSL_free(buf); |
218 | return(ret); | 221 | return (ret); |
219 | } | 222 | } |
220 | 223 | ||
221 | static long slg_ctrl(BIO *b, int cmd, long num, void *ptr) | 224 | static long |
222 | { | 225 | slg_ctrl(BIO *b, int cmd, long num, void *ptr) |
223 | switch (cmd) | 226 | { |
224 | { | 227 | switch (cmd) { |
225 | case BIO_CTRL_SET: | 228 | case BIO_CTRL_SET: |
226 | xcloselog(b); | 229 | xcloselog(b); |
227 | xopenlog(b, ptr, num); | 230 | xopenlog(b, ptr, num); |
228 | break; | 231 | break; |
229 | default: | 232 | default: |
230 | break; | 233 | break; |
231 | } | ||
232 | return(0); | ||
233 | } | 234 | } |
235 | return (0); | ||
236 | } | ||
234 | 237 | ||
235 | static int slg_puts(BIO *bp, const char *str) | 238 | static int |
236 | { | 239 | slg_puts(BIO *bp, const char *str) |
237 | int n,ret; | 240 | { |
241 | int n, ret; | ||
238 | 242 | ||
239 | n=strlen(str); | 243 | n = strlen(str); |
240 | ret=slg_write(bp,str,n); | 244 | ret = slg_write(bp, str, n); |
241 | return(ret); | 245 | return (ret); |
242 | } | 246 | } |
243 | 247 | ||
244 | #if defined(OPENSSL_SYS_WIN32) | 248 | #if defined(OPENSSL_SYS_WIN32) |
245 | 249 | ||
246 | static void xopenlog(BIO* bp, char* name, int level) | 250 | static void |
251 | xopenlog(BIO* bp, char* name, int level) | ||
247 | { | 252 | { |
248 | if (check_winnt()) | 253 | if (check_winnt()) |
249 | bp->ptr = RegisterEventSourceA(NULL,name); | 254 | bp->ptr = RegisterEventSourceA(NULL, name); |
250 | else | 255 | else |
251 | bp->ptr = NULL; | 256 | bp->ptr = NULL; |
252 | } | 257 | } |
253 | 258 | ||
254 | static void xsyslog(BIO *bp, int priority, const char *string) | 259 | static void |
260 | xsyslog(BIO *bp, int priority, const char *string) | ||
255 | { | 261 | { |
256 | LPCSTR lpszStrings[2]; | 262 | LPCSTR lpszStrings[2]; |
257 | WORD evtype= EVENTLOG_ERROR_TYPE; | 263 | WORD evtype = EVENTLOG_ERROR_TYPE; |
258 | char pidbuf[DECIMAL_SIZE(DWORD)+4]; | 264 | char pidbuf[DECIMAL_SIZE(DWORD) + 4]; |
259 | 265 | ||
260 | if (bp->ptr == NULL) | 266 | if (bp->ptr == NULL) |
261 | return; | 267 | return; |
262 | 268 | ||
263 | switch (priority) | 269 | switch (priority) { |
264 | { | ||
265 | case LOG_EMERG: | 270 | case LOG_EMERG: |
266 | case LOG_ALERT: | 271 | case LOG_ALERT: |
267 | case LOG_CRIT: | 272 | case LOG_CRIT: |
@@ -280,33 +285,37 @@ static void xsyslog(BIO *bp, int priority, const char *string) | |||
280 | as error anyway. */ | 285 | as error anyway. */ |
281 | evtype = EVENTLOG_ERROR_TYPE; | 286 | evtype = EVENTLOG_ERROR_TYPE; |
282 | break; | 287 | break; |
283 | } | 288 | } |
284 | 289 | ||
285 | sprintf(pidbuf, "[%u] ", GetCurrentProcessId()); | 290 | sprintf(pidbuf, "[%u] ", GetCurrentProcessId()); |
286 | lpszStrings[0] = pidbuf; | 291 | lpszStrings[0] = pidbuf; |
287 | lpszStrings[1] = string; | 292 | lpszStrings[1] = string; |
288 | 293 | ||
289 | ReportEventA(bp->ptr, evtype, 0, 1024, NULL, 2, 0, | 294 | ReportEventA(bp->ptr, evtype, 0, 1024, NULL, 2, 0, |
290 | lpszStrings, NULL); | 295 | lpszStrings, NULL); |
291 | } | 296 | } |
292 | 297 | ||
293 | static void xcloselog(BIO* bp) | 298 | static void |
299 | xcloselog(BIO* bp) | ||
294 | { | 300 | { |
295 | if(bp->ptr) | 301 | if (bp->ptr) |
296 | DeregisterEventSource((HANDLE)(bp->ptr)); | 302 | DeregisterEventSource((HANDLE)(bp->ptr)); |
297 | bp->ptr= NULL; | 303 | bp->ptr = NULL; |
298 | } | 304 | } |
299 | 305 | ||
300 | #elif defined(OPENSSL_SYS_VMS) | 306 | #elif defined(OPENSSL_SYS_VMS) |
301 | 307 | ||
302 | static int VMS_OPC_target = LOG_DAEMON; | 308 | static int VMS_OPC_target = LOG_DAEMON; |
303 | 309 | ||
304 | static void xopenlog(BIO* bp, char* name, int level) | 310 | static void |
311 | xopenlog(BIO* bp, char* name, int level) | ||
305 | { | 312 | { |
306 | VMS_OPC_target = level; | 313 | VMS_OPC_target = level; |
314 | |||
307 | } | 315 | } |
308 | 316 | ||
309 | static void xsyslog(BIO *bp, int priority, const char *string) | 317 | static void |
318 | xsyslog(BIO *bp, int priority, const char *string) | ||
310 | { | 319 | { |
311 | struct dsc$descriptor_s opc_dsc; | 320 | struct dsc$descriptor_s opc_dsc; |
312 | 321 | ||
@@ -329,21 +338,28 @@ static void xsyslog(BIO *bp, int priority, const char *string) | |||
329 | 338 | ||
330 | char buf[10240]; | 339 | char buf[10240]; |
331 | unsigned int len; | 340 | unsigned int len; |
332 | struct dsc$descriptor_s buf_dsc; | 341 | struct dsc$descriptor_s buf_dsc; |
333 | $DESCRIPTOR(fao_cmd, "!AZ: !AZ"); | 342 | $DESCRIPTOR(fao_cmd, "!AZ: !AZ"); |
334 | char *priority_tag; | 343 | char *priority_tag; |
335 | 344 | ||
336 | switch (priority) | 345 | switch (priority) { |
337 | { | 346 | case LOG_EMERG: |
338 | case LOG_EMERG: priority_tag = "Emergency"; break; | 347 | priority_tag = "Emergency"; break; |
339 | case LOG_ALERT: priority_tag = "Alert"; break; | 348 | case LOG_ALERT: |
340 | case LOG_CRIT: priority_tag = "Critical"; break; | 349 | priority_tag = "Alert"; break; |
341 | case LOG_ERR: priority_tag = "Error"; break; | 350 | case LOG_CRIT: |
342 | case LOG_WARNING: priority_tag = "Warning"; break; | 351 | priority_tag = "Critical"; break; |
343 | case LOG_NOTICE: priority_tag = "Notice"; break; | 352 | case LOG_ERR: |
344 | case LOG_INFO: priority_tag = "Info"; break; | 353 | priority_tag = "Error"; break; |
345 | case LOG_DEBUG: priority_tag = "DEBUG"; break; | 354 | case LOG_WARNING: |
346 | } | 355 | priority_tag = "Warning"; break; |
356 | case LOG_NOTICE: | ||
357 | priority_tag = "Notice"; break; | ||
358 | case LOG_INFO: | ||
359 | priority_tag = "Info"; break; | ||
360 | case LOG_DEBUG: | ||
361 | priority_tag = "DEBUG"; break; | ||
362 | } | ||
347 | 363 | ||
348 | buf_dsc.dsc$b_dtype = DSC$K_DTYPE_T; | 364 | buf_dsc.dsc$b_dtype = DSC$K_DTYPE_T; |
349 | buf_dsc.dsc$b_class = DSC$K_CLASS_S; | 365 | buf_dsc.dsc$b_class = DSC$K_CLASS_S; |
@@ -353,7 +369,7 @@ static void xsyslog(BIO *bp, int priority, const char *string) | |||
353 | lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string); | 369 | lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string); |
354 | 370 | ||
355 | /* We know there's an 8-byte header. That's documented. */ | 371 | /* We know there's an 8-byte header. That's documented. */ |
356 | opcdef_p = OPCDEF_MALLOC( 8+ len); | 372 | opcdef_p = OPCDEF_MALLOC( 8 + len); |
357 | opcdef_p->opc$b_ms_type = OPC$_RQ_RQST; | 373 | opcdef_p->opc$b_ms_type = OPC$_RQ_RQST; |
358 | memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3); | 374 | memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3); |
359 | opcdef_p->opc$l_ms_rqstid = 0; | 375 | opcdef_p->opc$l_ms_rqstid = 0; |
@@ -369,13 +385,15 @@ static void xsyslog(BIO *bp, int priority, const char *string) | |||
369 | OPENSSL_free(opcdef_p); | 385 | OPENSSL_free(opcdef_p); |
370 | } | 386 | } |
371 | 387 | ||
372 | static void xcloselog(BIO* bp) | 388 | static void |
389 | xcloselog(BIO* bp) | ||
373 | { | 390 | { |
374 | } | 391 | } |
375 | 392 | ||
376 | #else /* Unix/Watt32 */ | 393 | #else /* Unix/Watt32 */ |
377 | 394 | ||
378 | static void xopenlog(BIO* bp, char* name, int level) | 395 | static void |
396 | xopenlog(BIO* bp, char* name, int level) | ||
379 | { | 397 | { |
380 | #ifdef WATT32 /* djgpp/DOS */ | 398 | #ifdef WATT32 /* djgpp/DOS */ |
381 | openlog(name, LOG_PID|LOG_CONS|LOG_NDELAY, level); | 399 | openlog(name, LOG_PID|LOG_CONS|LOG_NDELAY, level); |
@@ -384,12 +402,14 @@ static void xopenlog(BIO* bp, char* name, int level) | |||
384 | #endif | 402 | #endif |
385 | } | 403 | } |
386 | 404 | ||
387 | static void xsyslog(BIO *bp, int priority, const char *string) | 405 | static void |
406 | xsyslog(BIO *bp, int priority, const char *string) | ||
388 | { | 407 | { |
389 | syslog(priority, "%s", string); | 408 | syslog(priority, "%s", string); |
390 | } | 409 | } |
391 | 410 | ||
392 | static void xcloselog(BIO* bp) | 411 | static void |
412 | xcloselog(BIO* bp) | ||
393 | { | 413 | { |
394 | closelog(); | 414 | closelog(); |
395 | } | 415 | } |
diff --git a/src/lib/libcrypto/bio/bss_mem.c b/src/lib/libcrypto/bio/bss_mem.c index 37d4194e4b..a5192202bd 100644 --- a/src/lib/libcrypto/bio/bss_mem.c +++ b/src/lib/libcrypto/bio/bss_mem.c | |||
@@ -68,8 +68,8 @@ static int mem_gets(BIO *h, char *str, int size); | |||
68 | static long mem_ctrl(BIO *h, int cmd, long arg1, void *arg2); | 68 | static long mem_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
69 | static int mem_new(BIO *h); | 69 | static int mem_new(BIO *h); |
70 | static int mem_free(BIO *data); | 70 | static int mem_free(BIO *data); |
71 | static BIO_METHOD mem_method= | 71 | |
72 | { | 72 | static BIO_METHOD mem_method = { |
73 | BIO_TYPE_MEM, | 73 | BIO_TYPE_MEM, |
74 | "memory buffer", | 74 | "memory buffer", |
75 | mem_write, | 75 | mem_write, |
@@ -80,28 +80,31 @@ static BIO_METHOD mem_method= | |||
80 | mem_new, | 80 | mem_new, |
81 | mem_free, | 81 | mem_free, |
82 | NULL, | 82 | NULL, |
83 | }; | 83 | }; |
84 | 84 | ||
85 | /* bio->num is used to hold the value to return on 'empty', if it is | 85 | /* bio->num is used to hold the value to return on 'empty', if it is |
86 | * 0, should_retry is not set */ | 86 | * 0, should_retry is not set */ |
87 | 87 | ||
88 | BIO_METHOD *BIO_s_mem(void) | 88 | BIO_METHOD |
89 | { | 89 | *BIO_s_mem(void) |
90 | return(&mem_method); | 90 | { |
91 | } | 91 | return (&mem_method); |
92 | } | ||
92 | 93 | ||
93 | BIO *BIO_new_mem_buf(void *buf, int len) | 94 | BIO |
95 | *BIO_new_mem_buf(void *buf, int len) | ||
94 | { | 96 | { |
95 | BIO *ret; | 97 | BIO *ret; |
96 | BUF_MEM *b; | 98 | BUF_MEM *b; |
97 | size_t sz; | 99 | size_t sz; |
98 | 100 | ||
99 | if (!buf) { | 101 | if (!buf) { |
100 | BIOerr(BIO_F_BIO_NEW_MEM_BUF,BIO_R_NULL_PARAMETER); | 102 | BIOerr(BIO_F_BIO_NEW_MEM_BUF, BIO_R_NULL_PARAMETER); |
101 | return NULL; | 103 | return NULL; |
102 | } | 104 | } |
103 | sz = (len<0) ? strlen(buf) : (size_t)len; | 105 | sz = (len < 0) ? strlen(buf) : (size_t)len; |
104 | if(!(ret = BIO_new(BIO_s_mem())) ) return NULL; | 106 | if (!(ret = BIO_new(BIO_s_mem()))) |
107 | return NULL; | ||
105 | b = (BUF_MEM *)ret->ptr; | 108 | b = (BUF_MEM *)ret->ptr; |
106 | b->data = buf; | 109 | b->data = buf; |
107 | b->length = sz; | 110 | b->length = sz; |
@@ -112,208 +115,205 @@ BIO *BIO_new_mem_buf(void *buf, int len) | |||
112 | return ret; | 115 | return ret; |
113 | } | 116 | } |
114 | 117 | ||
115 | static int mem_new(BIO *bi) | 118 | static int |
116 | { | 119 | mem_new(BIO *bi) |
120 | { | ||
117 | BUF_MEM *b; | 121 | BUF_MEM *b; |
118 | 122 | ||
119 | if ((b=BUF_MEM_new()) == NULL) | 123 | if ((b = BUF_MEM_new()) == NULL) |
120 | return(0); | 124 | return (0); |
121 | bi->shutdown=1; | 125 | bi->shutdown = 1; |
122 | bi->init=1; | 126 | bi->init = 1; |
123 | bi->num= -1; | 127 | bi->num = -1; |
124 | bi->ptr=(char *)b; | 128 | bi->ptr = (char *)b; |
125 | return(1); | 129 | return (1); |
126 | } | 130 | } |
127 | 131 | ||
128 | static int mem_free(BIO *a) | 132 | static int |
129 | { | 133 | mem_free(BIO *a) |
130 | if (a == NULL) return(0); | 134 | { |
131 | if (a->shutdown) | 135 | if (a == NULL) |
132 | { | 136 | return (0); |
133 | if ((a->init) && (a->ptr != NULL)) | 137 | if (a->shutdown) { |
134 | { | 138 | if ((a->init) && (a->ptr != NULL)) { |
135 | BUF_MEM *b; | 139 | BUF_MEM *b; |
136 | b = (BUF_MEM *)a->ptr; | 140 | b = (BUF_MEM *)a->ptr; |
137 | if(a->flags & BIO_FLAGS_MEM_RDONLY) b->data = NULL; | 141 | if (a->flags & BIO_FLAGS_MEM_RDONLY) |
138 | BUF_MEM_free(b); | 142 | b->data = NULL; |
139 | a->ptr=NULL; | 143 | BUF_MEM_free(b); |
140 | } | 144 | a->ptr = NULL; |
141 | } | 145 | } |
142 | return(1); | ||
143 | } | 146 | } |
144 | 147 | return (1); | |
145 | static int mem_read(BIO *b, char *out, int outl) | 148 | } |
146 | { | 149 | |
147 | int ret= -1; | 150 | static int |
151 | mem_read(BIO *b, char *out, int outl) | ||
152 | { | ||
153 | int ret = -1; | ||
148 | BUF_MEM *bm; | 154 | BUF_MEM *bm; |
149 | 155 | ||
150 | bm=(BUF_MEM *)b->ptr; | 156 | bm = (BUF_MEM *)b->ptr; |
151 | BIO_clear_retry_flags(b); | 157 | BIO_clear_retry_flags(b); |
152 | ret=(outl >=0 && (size_t)outl > bm->length)?(int)bm->length:outl; | 158 | ret = (outl >=0 && (size_t)outl > bm->length) ? (int)bm->length : outl; |
153 | if ((out != NULL) && (ret > 0)) { | 159 | if ((out != NULL) && (ret > 0)) { |
154 | memcpy(out,bm->data,ret); | 160 | memcpy(out, bm->data, ret); |
155 | bm->length-=ret; | 161 | bm->length -= ret; |
156 | if(b->flags & BIO_FLAGS_MEM_RDONLY) bm->data += ret; | 162 | if (b->flags & BIO_FLAGS_MEM_RDONLY) |
163 | bm->data += ret; | ||
157 | else { | 164 | else { |
158 | memmove(&(bm->data[0]),&(bm->data[ret]),bm->length); | 165 | memmove(&(bm->data[0]), &(bm->data[ret]), bm->length); |
159 | } | 166 | } |
160 | } else if (bm->length == 0) | 167 | } else if (bm->length == 0) { |
161 | { | ||
162 | ret = b->num; | 168 | ret = b->num; |
163 | if (ret != 0) | 169 | if (ret != 0) |
164 | BIO_set_retry_read(b); | 170 | BIO_set_retry_read(b); |
165 | } | ||
166 | return(ret); | ||
167 | } | 171 | } |
172 | return (ret); | ||
173 | } | ||
168 | 174 | ||
169 | static int mem_write(BIO *b, const char *in, int inl) | 175 | static int |
170 | { | 176 | mem_write(BIO *b, const char *in, int inl) |
171 | int ret= -1; | 177 | { |
178 | int ret = -1; | ||
172 | int blen; | 179 | int blen; |
173 | BUF_MEM *bm; | 180 | BUF_MEM *bm; |
174 | 181 | ||
175 | bm=(BUF_MEM *)b->ptr; | 182 | bm = (BUF_MEM *)b->ptr; |
176 | if (in == NULL) | 183 | if (in == NULL) { |
177 | { | 184 | BIOerr(BIO_F_MEM_WRITE, BIO_R_NULL_PARAMETER); |
178 | BIOerr(BIO_F_MEM_WRITE,BIO_R_NULL_PARAMETER); | ||
179 | goto end; | 185 | goto end; |
180 | } | 186 | } |
181 | 187 | ||
182 | if(b->flags & BIO_FLAGS_MEM_RDONLY) { | 188 | if (b->flags & BIO_FLAGS_MEM_RDONLY) { |
183 | BIOerr(BIO_F_MEM_WRITE,BIO_R_WRITE_TO_READ_ONLY_BIO); | 189 | BIOerr(BIO_F_MEM_WRITE, BIO_R_WRITE_TO_READ_ONLY_BIO); |
184 | goto end; | 190 | goto end; |
185 | } | 191 | } |
186 | 192 | ||
187 | BIO_clear_retry_flags(b); | 193 | BIO_clear_retry_flags(b); |
188 | blen=bm->length; | 194 | blen = bm->length; |
189 | if (BUF_MEM_grow_clean(bm,blen+inl) != (blen+inl)) | 195 | if (BUF_MEM_grow_clean(bm, blen + inl) != (blen + inl)) |
190 | goto end; | 196 | goto end; |
191 | memcpy(&(bm->data[blen]),in,inl); | 197 | memcpy(&(bm->data[blen]), in, inl); |
192 | ret=inl; | 198 | ret = inl; |
193 | end: | 199 | end: |
194 | return(ret); | 200 | return (ret); |
195 | } | 201 | } |
196 | 202 | ||
197 | static long mem_ctrl(BIO *b, int cmd, long num, void *ptr) | 203 | static long |
198 | { | 204 | mem_ctrl(BIO *b, int cmd, long num, void *ptr) |
199 | long ret=1; | 205 | { |
206 | long ret = 1; | ||
200 | char **pptr; | 207 | char **pptr; |
201 | 208 | ||
202 | BUF_MEM *bm=(BUF_MEM *)b->ptr; | 209 | BUF_MEM *bm = (BUF_MEM *)b->ptr; |
203 | 210 | ||
204 | switch (cmd) | 211 | switch (cmd) { |
205 | { | ||
206 | case BIO_CTRL_RESET: | 212 | case BIO_CTRL_RESET: |
207 | if (bm->data != NULL) | 213 | if (bm->data != NULL) { |
208 | { | ||
209 | /* For read only case reset to the start again */ | 214 | /* For read only case reset to the start again */ |
210 | if(b->flags & BIO_FLAGS_MEM_RDONLY) | 215 | if (b->flags & BIO_FLAGS_MEM_RDONLY) { |
211 | { | ||
212 | bm->data -= bm->max - bm->length; | 216 | bm->data -= bm->max - bm->length; |
213 | bm->length = bm->max; | 217 | bm->length = bm->max; |
214 | } | 218 | } else { |
215 | else | 219 | memset(bm->data, 0, bm->max); |
216 | { | 220 | bm->length = 0; |
217 | memset(bm->data,0,bm->max); | ||
218 | bm->length=0; | ||
219 | } | ||
220 | } | 221 | } |
222 | } | ||
221 | break; | 223 | break; |
222 | case BIO_CTRL_EOF: | 224 | case BIO_CTRL_EOF: |
223 | ret=(long)(bm->length == 0); | 225 | ret = (long)(bm->length == 0); |
224 | break; | 226 | break; |
225 | case BIO_C_SET_BUF_MEM_EOF_RETURN: | 227 | case BIO_C_SET_BUF_MEM_EOF_RETURN: |
226 | b->num=(int)num; | 228 | b->num = (int)num; |
227 | break; | 229 | break; |
228 | case BIO_CTRL_INFO: | 230 | case BIO_CTRL_INFO: |
229 | ret=(long)bm->length; | 231 | ret = (long)bm->length; |
230 | if (ptr != NULL) | 232 | if (ptr != NULL) { |
231 | { | 233 | pptr = (char **)ptr; |
232 | pptr=(char **)ptr; | 234 | *pptr = (char *)&(bm->data[0]); |
233 | *pptr=(char *)&(bm->data[0]); | 235 | } |
234 | } | ||
235 | break; | 236 | break; |
236 | case BIO_C_SET_BUF_MEM: | 237 | case BIO_C_SET_BUF_MEM: |
237 | mem_free(b); | 238 | mem_free(b); |
238 | b->shutdown=(int)num; | 239 | b->shutdown = (int)num; |
239 | b->ptr=ptr; | 240 | b->ptr = ptr; |
240 | break; | 241 | break; |
241 | case BIO_C_GET_BUF_MEM_PTR: | 242 | case BIO_C_GET_BUF_MEM_PTR: |
242 | if (ptr != NULL) | 243 | if (ptr != NULL) { |
243 | { | 244 | pptr = (char **)ptr; |
244 | pptr=(char **)ptr; | 245 | *pptr = (char *)bm; |
245 | *pptr=(char *)bm; | 246 | } |
246 | } | ||
247 | break; | 247 | break; |
248 | case BIO_CTRL_GET_CLOSE: | 248 | case BIO_CTRL_GET_CLOSE: |
249 | ret=(long)b->shutdown; | 249 | ret = (long)b->shutdown; |
250 | break; | 250 | break; |
251 | case BIO_CTRL_SET_CLOSE: | 251 | case BIO_CTRL_SET_CLOSE: |
252 | b->shutdown=(int)num; | 252 | b->shutdown = (int)num; |
253 | break; | 253 | break; |
254 | 254 | ||
255 | case BIO_CTRL_WPENDING: | 255 | case BIO_CTRL_WPENDING: |
256 | ret=0L; | 256 | ret = 0L; |
257 | break; | 257 | break; |
258 | case BIO_CTRL_PENDING: | 258 | case BIO_CTRL_PENDING: |
259 | ret=(long)bm->length; | 259 | ret = (long)bm->length; |
260 | break; | 260 | break; |
261 | case BIO_CTRL_DUP: | 261 | case BIO_CTRL_DUP: |
262 | case BIO_CTRL_FLUSH: | 262 | case BIO_CTRL_FLUSH: |
263 | ret=1; | 263 | ret = 1; |
264 | break; | 264 | break; |
265 | case BIO_CTRL_PUSH: | 265 | case BIO_CTRL_PUSH: |
266 | case BIO_CTRL_POP: | 266 | case BIO_CTRL_POP: |
267 | default: | 267 | default: |
268 | ret=0; | 268 | ret = 0; |
269 | break; | 269 | break; |
270 | } | ||
271 | return(ret); | ||
272 | } | 270 | } |
271 | return (ret); | ||
272 | } | ||
273 | 273 | ||
274 | static int mem_gets(BIO *bp, char *buf, int size) | 274 | static int |
275 | { | 275 | mem_gets(BIO *bp, char *buf, int size) |
276 | int i,j; | 276 | { |
277 | int ret= -1; | 277 | int i, j; |
278 | int ret = -1; | ||
278 | char *p; | 279 | char *p; |
279 | BUF_MEM *bm=(BUF_MEM *)bp->ptr; | 280 | BUF_MEM *bm = (BUF_MEM *)bp->ptr; |
280 | 281 | ||
281 | BIO_clear_retry_flags(bp); | 282 | BIO_clear_retry_flags(bp); |
282 | j=bm->length; | 283 | j = bm->length; |
283 | if ((size-1) < j) j=size-1; | 284 | if ((size - 1) < j) |
284 | if (j <= 0) | 285 | j = size - 1; |
285 | { | 286 | if (j <= 0) { |
286 | *buf='\0'; | 287 | *buf = '\0'; |
287 | return 0; | 288 | return 0; |
288 | } | 289 | } |
289 | p=bm->data; | 290 | p = bm->data; |
290 | for (i=0; i<j; i++) | 291 | for (i = 0; i < j; i++) { |
291 | { | 292 | if (p[i] == '\n') { |
292 | if (p[i] == '\n') | ||
293 | { | ||
294 | i++; | 293 | i++; |
295 | break; | 294 | break; |
296 | } | ||
297 | } | 295 | } |
296 | } | ||
298 | 297 | ||
299 | /* | 298 | /* |
300 | * i is now the max num of bytes to copy, either j or up to | 299 | * i is now the max num of bytes to copy, either j or up to |
301 | * and including the first newline | 300 | * and including the first newline |
302 | */ | 301 | */ |
303 | 302 | ||
304 | i=mem_read(bp,buf,i); | 303 | i = mem_read(bp, buf, i); |
305 | if (i > 0) buf[i]='\0'; | 304 | if (i > 0) |
306 | ret=i; | 305 | buf[i] = '\0'; |
307 | return(ret); | 306 | ret = i; |
308 | } | 307 | return (ret); |
308 | } | ||
309 | 309 | ||
310 | static int mem_puts(BIO *bp, const char *str) | 310 | static int |
311 | { | 311 | mem_puts(BIO *bp, const char *str) |
312 | int n,ret; | 312 | { |
313 | int n, ret; | ||
313 | 314 | ||
314 | n=strlen(str); | 315 | n = strlen(str); |
315 | ret=mem_write(bp,str,n); | 316 | ret = mem_write(bp, str, n); |
316 | /* memory semantics is that it will always work */ | 317 | /* memory semantics is that it will always work */ |
317 | return(ret); | 318 | return (ret); |
318 | } | 319 | } |
319 | |||
diff --git a/src/lib/libcrypto/bio/bss_null.c b/src/lib/libcrypto/bio/bss_null.c index 46b73339df..51aed2ac4b 100644 --- a/src/lib/libcrypto/bio/bss_null.c +++ b/src/lib/libcrypto/bio/bss_null.c | |||
@@ -68,8 +68,8 @@ static int null_gets(BIO *h, char *str, int size); | |||
68 | static long null_ctrl(BIO *h, int cmd, long arg1, void *arg2); | 68 | static long null_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
69 | static int null_new(BIO *h); | 69 | static int null_new(BIO *h); |
70 | static int null_free(BIO *data); | 70 | static int null_free(BIO *data); |
71 | static BIO_METHOD null_method= | 71 | |
72 | { | 72 | static BIO_METHOD null_method = { |
73 | BIO_TYPE_NULL, | 73 | BIO_TYPE_NULL, |
74 | "NULL", | 74 | "NULL", |
75 | null_write, | 75 | null_write, |
@@ -80,50 +80,56 @@ static BIO_METHOD null_method= | |||
80 | null_new, | 80 | null_new, |
81 | null_free, | 81 | null_free, |
82 | NULL, | 82 | NULL, |
83 | }; | 83 | }; |
84 | 84 | ||
85 | BIO_METHOD *BIO_s_null(void) | 85 | BIO_METHOD |
86 | { | 86 | *BIO_s_null(void) |
87 | return(&null_method); | 87 | { |
88 | } | 88 | return (&null_method); |
89 | } | ||
89 | 90 | ||
90 | static int null_new(BIO *bi) | 91 | static int |
91 | { | 92 | null_new(BIO *bi) |
92 | bi->init=1; | 93 | { |
93 | bi->num=0; | 94 | bi->init = 1; |
94 | bi->ptr=(NULL); | 95 | bi->num = 0; |
95 | return(1); | 96 | bi->ptr = (NULL); |
96 | } | 97 | return (1); |
98 | } | ||
97 | 99 | ||
98 | static int null_free(BIO *a) | 100 | static int |
99 | { | 101 | null_free(BIO *a) |
100 | if (a == NULL) return(0); | 102 | { |
101 | return(1); | 103 | if (a == NULL) |
102 | } | 104 | return (0); |
103 | 105 | return (1); | |
104 | static int null_read(BIO *b, char *out, int outl) | 106 | } |
105 | { | ||
106 | return(0); | ||
107 | } | ||
108 | 107 | ||
109 | static int null_write(BIO *b, const char *in, int inl) | 108 | static int |
110 | { | 109 | null_read(BIO *b, char *out, int outl) |
111 | return(inl); | 110 | { |
112 | } | 111 | return (0); |
112 | } | ||
113 | |||
114 | static int | ||
115 | null_write(BIO *b, const char *in, int inl) | ||
116 | { | ||
117 | return (inl); | ||
118 | } | ||
113 | 119 | ||
114 | static long null_ctrl(BIO *b, int cmd, long num, void *ptr) | 120 | static long |
115 | { | 121 | null_ctrl(BIO *b, int cmd, long num, void *ptr) |
116 | long ret=1; | 122 | { |
123 | long ret = 1; | ||
117 | 124 | ||
118 | switch (cmd) | 125 | switch (cmd) { |
119 | { | ||
120 | case BIO_CTRL_RESET: | 126 | case BIO_CTRL_RESET: |
121 | case BIO_CTRL_EOF: | 127 | case BIO_CTRL_EOF: |
122 | case BIO_CTRL_SET: | 128 | case BIO_CTRL_SET: |
123 | case BIO_CTRL_SET_CLOSE: | 129 | case BIO_CTRL_SET_CLOSE: |
124 | case BIO_CTRL_FLUSH: | 130 | case BIO_CTRL_FLUSH: |
125 | case BIO_CTRL_DUP: | 131 | case BIO_CTRL_DUP: |
126 | ret=1; | 132 | ret = 1; |
127 | break; | 133 | break; |
128 | case BIO_CTRL_GET_CLOSE: | 134 | case BIO_CTRL_GET_CLOSE: |
129 | case BIO_CTRL_INFO: | 135 | case BIO_CTRL_INFO: |
@@ -131,20 +137,22 @@ static long null_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
131 | case BIO_CTRL_PENDING: | 137 | case BIO_CTRL_PENDING: |
132 | case BIO_CTRL_WPENDING: | 138 | case BIO_CTRL_WPENDING: |
133 | default: | 139 | default: |
134 | ret=0; | 140 | ret = 0; |
135 | break; | 141 | break; |
136 | } | ||
137 | return(ret); | ||
138 | } | 142 | } |
143 | return (ret); | ||
144 | } | ||
139 | 145 | ||
140 | static int null_gets(BIO *bp, char *buf, int size) | 146 | static int |
141 | { | 147 | null_gets(BIO *bp, char *buf, int size) |
142 | return(0); | 148 | { |
143 | } | 149 | return (0); |
144 | 150 | } | |
145 | static int null_puts(BIO *bp, const char *str) | ||
146 | { | ||
147 | if (str == NULL) return(0); | ||
148 | return(strlen(str)); | ||
149 | } | ||
150 | 151 | ||
152 | static int | ||
153 | null_puts(BIO *bp, const char *str) | ||
154 | { | ||
155 | if (str == NULL) | ||
156 | return (0); | ||
157 | return (strlen(str)); | ||
158 | } | ||
diff --git a/src/lib/libcrypto/bio/bss_rtcp.c b/src/lib/libcrypto/bio/bss_rtcp.c index 7dae485564..84d01e58b4 100644 --- a/src/lib/libcrypto/bio/bss_rtcp.c +++ b/src/lib/libcrypto/bio/bss_rtcp.c | |||
@@ -73,31 +73,32 @@ | |||
73 | 73 | ||
74 | typedef unsigned short io_channel; | 74 | typedef unsigned short io_channel; |
75 | /*************************************************************************/ | 75 | /*************************************************************************/ |
76 | struct io_status { short status, count; long flags; }; | 76 | struct io_status { short status, count; |
77 | long flags; | ||
78 | }; | ||
77 | 79 | ||
78 | struct rpc_msg { /* Should have member alignment inhibited */ | 80 | struct rpc_msg { /* Should have member alignment inhibited */ |
79 | char channel; /* 'A'-app data. 'R'-remote client 'G'-global */ | 81 | char channel; /* 'A'-app data. 'R'-remote client 'G'-global */ |
80 | char function; /* 'G'-get, 'P'-put, 'C'-confirm, 'X'-close */ | 82 | char function; /* 'G'-get, 'P'-put, 'C'-confirm, 'X'-close */ |
81 | unsigned short int length; /* Amount of data returned or max to return */ | 83 | unsigned short int length; /* Amount of data returned or max to return */ |
82 | char data[4092]; /* variable data */ | 84 | char data[4092]; /* variable data */ |
83 | }; | 85 | }; |
84 | #define RPC_HDR_SIZE (sizeof(struct rpc_msg) - 4092) | 86 | #define RPC_HDR_SIZE (sizeof(struct rpc_msg) - 4092) |
85 | 87 | ||
86 | struct rpc_ctx { | 88 | struct rpc_ctx { |
87 | int filled, pos; | 89 | int filled, pos; |
88 | struct rpc_msg msg; | 90 | struct rpc_msg msg; |
89 | }; | 91 | }; |
90 | 92 | ||
91 | static int rtcp_write(BIO *h,const char *buf,int num); | 93 | static int rtcp_write(BIO *h, const char *buf, int num); |
92 | static int rtcp_read(BIO *h,char *buf,int size); | 94 | static int rtcp_read(BIO *h, char *buf, int size); |
93 | static int rtcp_puts(BIO *h,const char *str); | 95 | static int rtcp_puts(BIO *h, const char *str); |
94 | static int rtcp_gets(BIO *h,char *str,int size); | 96 | static int rtcp_gets(BIO *h, char *str, int size); |
95 | static long rtcp_ctrl(BIO *h,int cmd,long arg1,void *arg2); | 97 | static long rtcp_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
96 | static int rtcp_new(BIO *h); | 98 | static int rtcp_new(BIO *h); |
97 | static int rtcp_free(BIO *data); | 99 | static int rtcp_free(BIO *data); |
98 | 100 | ||
99 | static BIO_METHOD rtcp_method= | 101 | static BIO_METHOD rtcp_method = { |
100 | { | ||
101 | BIO_TYPE_FD, | 102 | BIO_TYPE_FD, |
102 | "RTCP", | 103 | "RTCP", |
103 | rtcp_write, | 104 | rtcp_write, |
@@ -108,12 +109,13 @@ static BIO_METHOD rtcp_method= | |||
108 | rtcp_new, | 109 | rtcp_new, |
109 | rtcp_free, | 110 | rtcp_free, |
110 | NULL, | 111 | NULL, |
111 | }; | 112 | }; |
112 | 113 | ||
113 | BIO_METHOD *BIO_s_rtcp(void) | 114 | BIO_METHOD |
114 | { | 115 | *BIO_s_rtcp(void) |
115 | return(&rtcp_method); | 116 | { |
116 | } | 117 | return (&rtcp_method); |
118 | } | ||
117 | /*****************************************************************************/ | 119 | /*****************************************************************************/ |
118 | /* Decnet I/O routines. | 120 | /* Decnet I/O routines. |
119 | */ | 121 | */ |
@@ -123,25 +125,28 @@ BIO_METHOD *BIO_s_rtcp(void) | |||
123 | #pragma message disable DOLLARID | 125 | #pragma message disable DOLLARID |
124 | #endif | 126 | #endif |
125 | 127 | ||
126 | static int get ( io_channel chan, char *buffer, int maxlen, int *length ) | 128 | static int get(io_channel chan, char *buffer, int maxlen, int *length) |
127 | { | 129 | { |
128 | int status; | 130 | int status; |
129 | struct io_status iosb; | 131 | struct io_status iosb; |
130 | status = sys$qiow ( 0, chan, IO$_READVBLK, &iosb, 0, 0, | 132 | status = sys$qiow(0, chan, IO$_READVBLK, &iosb, 0, 0, buffer, maxlen, |
131 | buffer, maxlen, 0, 0, 0, 0 ); | 133 | 0, 0, 0, 0 ); |
132 | if ( (status&1) == 1 ) status = iosb.status; | 134 | if ((status & 1) == 1) |
133 | if ( (status&1) == 1 ) *length = iosb.count; | 135 | status = iosb.status; |
134 | return status; | 136 | if ((status & 1) == 1 ) |
137 | *length = iosb.count; | ||
138 | return status; | ||
135 | } | 139 | } |
136 | 140 | ||
137 | static int put ( io_channel chan, char *buffer, int length ) | 141 | static int put(io_channel chan, char *buffer, int length) |
138 | { | 142 | { |
139 | int status; | 143 | int status; |
140 | struct io_status iosb; | 144 | struct io_status iosb; |
141 | status = sys$qiow ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0, | 145 | status = sys$qiow ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0, buffer, |
142 | buffer, length, 0, 0, 0, 0 ); | 146 | length, 0, 0, 0, 0 ); |
143 | if ( (status&1) == 1 ) status = iosb.status; | 147 | if ((status & 1) == 1) |
144 | return status; | 148 | status = iosb.status; |
149 | return status; | ||
145 | } | 150 | } |
146 | 151 | ||
147 | #ifdef __DECC | 152 | #ifdef __DECC |
@@ -150,109 +155,127 @@ static int put ( io_channel chan, char *buffer, int length ) | |||
150 | 155 | ||
151 | /***************************************************************************/ | 156 | /***************************************************************************/ |
152 | 157 | ||
153 | static int rtcp_new(BIO *bi) | 158 | static int |
159 | rtcp_new(BIO *bi) | ||
154 | { | 160 | { |
155 | struct rpc_ctx *ctx; | 161 | struct rpc_ctx *ctx; |
156 | bi->init=1; | 162 | bi->init = 1; |
157 | bi->num=0; | 163 | bi->num = 0; |
158 | bi->flags = 0; | 164 | bi->flags = 0; |
159 | bi->ptr=OPENSSL_malloc(sizeof(struct rpc_ctx)); | 165 | bi->ptr = OPENSSL_malloc(sizeof(struct rpc_ctx)); |
160 | ctx = (struct rpc_ctx *) bi->ptr; | 166 | ctx = (struct rpc_ctx *)bi->ptr; |
161 | ctx->filled = 0; | 167 | ctx->filled = 0; |
162 | ctx->pos = 0; | 168 | ctx->pos = 0; |
163 | return(1); | 169 | return (1); |
164 | } | 170 | } |
165 | 171 | ||
166 | static int rtcp_free(BIO *a) | 172 | static int |
173 | rtcp_free(BIO *a) | ||
167 | { | 174 | { |
168 | if (a == NULL) return(0); | 175 | if (a == NULL) |
169 | if ( a->ptr ) OPENSSL_free ( a->ptr ); | 176 | return (0); |
177 | if (a->ptr) | ||
178 | OPENSSL_free(a->ptr); | ||
170 | a->ptr = NULL; | 179 | a->ptr = NULL; |
171 | return(1); | 180 | return (1); |
172 | } | 181 | } |
173 | 182 | ||
174 | static int rtcp_read(BIO *b, char *out, int outl) | 183 | static int |
184 | rtcp_read(BIO *b, char *out, int outl) | ||
175 | { | 185 | { |
176 | int status, length; | 186 | int status, length; |
177 | struct rpc_ctx *ctx; | 187 | struct rpc_ctx *ctx; |
178 | /* | 188 | /* |
179 | * read data, return existing. | 189 | * read data, return existing. |
180 | */ | 190 | */ |
181 | ctx = (struct rpc_ctx *) b->ptr; | 191 | ctx = (struct rpc_ctx *)b->ptr; |
182 | if ( ctx->pos < ctx->filled ) { | 192 | if (ctx->pos < ctx->filled) { |
183 | length = ctx->filled - ctx->pos; | 193 | length = ctx->filled - ctx->pos; |
184 | if ( length > outl ) length = outl; | 194 | if (length > outl) |
185 | memmove ( out, &ctx->msg.data[ctx->pos], length ); | 195 | length = outl; |
186 | ctx->pos += length; | 196 | memmove(out, &ctx->msg.data[ctx->pos], length); |
187 | return length; | 197 | ctx->pos += length; |
188 | } | 198 | return length; |
189 | /* | 199 | } |
190 | * Requst more data from R channel. | 200 | /* |
191 | */ | 201 | * Requst more data from R channel. |
192 | ctx->msg.channel = 'R'; | 202 | */ |
193 | ctx->msg.function = 'G'; | 203 | ctx->msg.channel = 'R'; |
194 | ctx->msg.length = sizeof(ctx->msg.data); | 204 | ctx->msg.function = 'G'; |
195 | status = put ( b->num, (char *) &ctx->msg, RPC_HDR_SIZE ); | 205 | ctx->msg.length = sizeof(ctx->msg.data); |
196 | if ( (status&1) == 0 ) { | 206 | status = put(b->num, (char *)&ctx->msg, RPC_HDR_SIZE); |
197 | return -1; | 207 | if ((status & 1) == 0 ) { |
198 | } | 208 | return -1; |
199 | /* | 209 | } |
200 | * Read. | 210 | /* |
201 | */ | 211 | * Read. |
202 | ctx->pos = ctx->filled = 0; | 212 | */ |
203 | status = get ( b->num, (char *) &ctx->msg, sizeof(ctx->msg), &length ); | 213 | ctx->pos = ctx->filled = 0; |
204 | if ( (status&1) == 0 ) length = -1; | 214 | status = get(b->num, (char *)&ctx->msg, sizeof(ctx->msg), &length); |
205 | if ( ctx->msg.channel != 'R' || ctx->msg.function != 'C' ) { | 215 | if ((status & 1) == 0) |
206 | length = -1; | 216 | length = -1; |
207 | } | 217 | if (ctx->msg.channel != 'R' || ctx->msg.function != 'C') { |
208 | ctx->filled = length - RPC_HDR_SIZE; | 218 | length = -1; |
209 | 219 | } | |
210 | if ( ctx->pos < ctx->filled ) { | 220 | ctx->filled = length - RPC_HDR_SIZE; |
211 | length = ctx->filled - ctx->pos; | 221 | |
212 | if ( length > outl ) length = outl; | 222 | if (ctx->pos < ctx->filled) { |
213 | memmove ( out, ctx->msg.data, length ); | 223 | length = ctx->filled - ctx->pos; |
214 | ctx->pos += length; | 224 | if (length > outl) |
215 | return length; | 225 | length = outl; |
216 | } | 226 | memmove(out, ctx->msg.data, length); |
227 | ctx->pos += length; | ||
228 | return length; | ||
229 | } | ||
217 | 230 | ||
218 | return length; | 231 | return length; |
219 | } | 232 | } |
220 | 233 | ||
221 | static int rtcp_write(BIO *b, const char *in, int inl) | 234 | static int |
235 | rtcp_write(BIO *b, const char *in, int inl) | ||
222 | { | 236 | { |
223 | int status, i, segment, length; | 237 | int status, i, segment, length; |
224 | struct rpc_ctx *ctx; | 238 | struct rpc_ctx *ctx; |
225 | /* | 239 | /* |
226 | * Output data, send in chunks no larger that sizeof(ctx->msg.data). | 240 | * Output data, send in chunks no larger that sizeof(ctx->msg.data). |
227 | */ | 241 | */ |
228 | ctx = (struct rpc_ctx *) b->ptr; | 242 | ctx = (struct rpc_ctx *)b->ptr; |
229 | for ( i = 0; i < inl; i += segment ) { | 243 | for (i = 0; i < inl; i += segment) { |
230 | segment = inl - i; | 244 | segment = inl - i; |
231 | if ( segment > sizeof(ctx->msg.data) ) segment = sizeof(ctx->msg.data); | 245 | if (segment > sizeof(ctx->msg.data)) |
232 | ctx->msg.channel = 'R'; | 246 | segment = sizeof(ctx->msg.data); |
233 | ctx->msg.function = 'P'; | 247 | ctx->msg.channel = 'R'; |
234 | ctx->msg.length = segment; | 248 | ctx->msg.function = 'P'; |
235 | memmove ( ctx->msg.data, &in[i], segment ); | 249 | ctx->msg.length = segment; |
236 | status = put ( b->num, (char *) &ctx->msg, segment + RPC_HDR_SIZE ); | 250 | memmove(ctx->msg.data, &in[i], segment); |
237 | if ((status&1) == 0 ) { i = -1; break; } | 251 | status = put(b->num, (char *) &ctx->msg, |
252 | segment + RPC_HDR_SIZE); | ||
253 | if ((status & 1) == 0) { | ||
254 | i = -1; | ||
255 | break; | ||
256 | } | ||
238 | 257 | ||
239 | status = get ( b->num, (char *) &ctx->msg, sizeof(ctx->msg), &length ); | 258 | status = get(b->num, (char *)&ctx->msg, sizeof(ctx->msg), |
240 | if ( ((status&1) == 0) || (length < RPC_HDR_SIZE) ) { i = -1; break; } | 259 | &length ); |
241 | if ( (ctx->msg.channel != 'R') || (ctx->msg.function != 'C') ) { | 260 | if (((status&1) == 0) || (length < RPC_HDR_SIZE)) { |
242 | printf("unexpected response when confirming put %c %c\n", | 261 | i = -1; |
243 | ctx->msg.channel, ctx->msg.function ); | 262 | break; |
263 | } | ||
264 | if ((ctx->msg.channel != 'R') || (ctx->msg.function != 'C')) { | ||
265 | printf("unexpected response when confirming put %c %c\n", | ||
266 | ctx->msg.channel, ctx->msg.function ); | ||
244 | 267 | ||
268 | } | ||
245 | } | 269 | } |
246 | } | 270 | return (i); |
247 | return(i); | ||
248 | } | 271 | } |
249 | 272 | ||
250 | static long rtcp_ctrl(BIO *b, int cmd, long num, void *ptr) | 273 | static long |
251 | { | 274 | rtcp_ctrl(BIO *b, int cmd, long num, void *ptr) |
252 | long ret=1; | 275 | { |
276 | long ret = 1; | ||
253 | 277 | ||
254 | switch (cmd) | 278 | switch (cmd) { |
255 | { | ||
256 | case BIO_CTRL_RESET: | 279 | case BIO_CTRL_RESET: |
257 | case BIO_CTRL_EOF: | 280 | case BIO_CTRL_EOF: |
258 | ret = 1; | 281 | ret = 1; |
@@ -260,11 +283,11 @@ static long rtcp_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
260 | case BIO_C_SET_FD: | 283 | case BIO_C_SET_FD: |
261 | b->num = num; | 284 | b->num = num; |
262 | ret = 1; | 285 | ret = 1; |
263 | break; | 286 | break; |
264 | case BIO_CTRL_SET_CLOSE: | 287 | case BIO_CTRL_SET_CLOSE: |
265 | case BIO_CTRL_FLUSH: | 288 | case BIO_CTRL_FLUSH: |
266 | case BIO_CTRL_DUP: | 289 | case BIO_CTRL_DUP: |
267 | ret=1; | 290 | ret = 1; |
268 | break; | 291 | break; |
269 | case BIO_CTRL_GET_CLOSE: | 292 | case BIO_CTRL_GET_CLOSE: |
270 | case BIO_CTRL_INFO: | 293 | case BIO_CTRL_INFO: |
@@ -272,23 +295,26 @@ static long rtcp_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
272 | case BIO_CTRL_PENDING: | 295 | case BIO_CTRL_PENDING: |
273 | case BIO_CTRL_WPENDING: | 296 | case BIO_CTRL_WPENDING: |
274 | default: | 297 | default: |
275 | ret=0; | 298 | ret = 0; |
276 | break; | 299 | break; |
277 | } | ||
278 | return(ret); | ||
279 | } | ||
280 | |||
281 | static int rtcp_gets(BIO *bp, char *buf, int size) | ||
282 | { | ||
283 | return(0); | ||
284 | } | 300 | } |
301 | return (ret); | ||
302 | } | ||
285 | 303 | ||
286 | static int rtcp_puts(BIO *bp, const char *str) | 304 | static int |
305 | rtcp_gets(BIO *bp, char *buf, int size) | ||
287 | { | 306 | { |
288 | int length; | 307 | return (0); |
289 | if (str == NULL) return(0); | ||
290 | length = strlen ( str ); | ||
291 | if ( length == 0 ) return (0); | ||
292 | return rtcp_write ( bp,str, length ); | ||
293 | } | 308 | } |
294 | 309 | ||
310 | static int | ||
311 | rtcp_puts(BIO *bp, const char *str) | ||
312 | { | ||
313 | int length; | ||
314 | if (str == NULL) | ||
315 | return (0); | ||
316 | length = strlen(str); | ||
317 | if (length == 0) | ||
318 | return (0); | ||
319 | return rtcp_write(bp, str, length); | ||
320 | } | ||
diff --git a/src/lib/libcrypto/bio/bss_sock.c b/src/lib/libcrypto/bio/bss_sock.c index eb2965970c..f6d3bf7365 100644 --- a/src/lib/libcrypto/bio/bss_sock.c +++ b/src/lib/libcrypto/bio/bss_sock.c | |||
@@ -79,8 +79,7 @@ static int sock_new(BIO *h); | |||
79 | static int sock_free(BIO *data); | 79 | static int sock_free(BIO *data); |
80 | int BIO_sock_should_retry(int s); | 80 | int BIO_sock_should_retry(int s); |
81 | 81 | ||
82 | static BIO_METHOD methods_sockp= | 82 | static BIO_METHOD methods_sockp = { |
83 | { | ||
84 | BIO_TYPE_SOCKET, | 83 | BIO_TYPE_SOCKET, |
85 | "socket", | 84 | "socket", |
86 | sock_write, | 85 | sock_write, |
@@ -91,152 +90,155 @@ static BIO_METHOD methods_sockp= | |||
91 | sock_new, | 90 | sock_new, |
92 | sock_free, | 91 | sock_free, |
93 | NULL, | 92 | NULL, |
94 | }; | 93 | }; |
95 | 94 | ||
96 | BIO_METHOD *BIO_s_socket(void) | 95 | BIO_METHOD |
97 | { | 96 | *BIO_s_socket(void) |
98 | return(&methods_sockp); | 97 | { |
99 | } | 98 | return (&methods_sockp); |
99 | } | ||
100 | 100 | ||
101 | BIO *BIO_new_socket(int fd, int close_flag) | 101 | BIO |
102 | { | 102 | *BIO_new_socket(int fd, int close_flag) |
103 | { | ||
103 | BIO *ret; | 104 | BIO *ret; |
104 | 105 | ||
105 | ret=BIO_new(BIO_s_socket()); | 106 | ret = BIO_new(BIO_s_socket()); |
106 | if (ret == NULL) return(NULL); | 107 | if (ret == NULL) |
107 | BIO_set_fd(ret,fd,close_flag); | 108 | return (NULL); |
108 | return(ret); | 109 | BIO_set_fd(ret, fd, close_flag); |
109 | } | 110 | return (ret); |
111 | } | ||
110 | 112 | ||
111 | static int sock_new(BIO *bi) | 113 | static int |
112 | { | 114 | sock_new(BIO *bi) |
113 | bi->init=0; | 115 | { |
114 | bi->num=0; | 116 | bi->init = 0; |
115 | bi->ptr=NULL; | 117 | bi->num = 0; |
116 | bi->flags=0; | 118 | bi->ptr = NULL; |
117 | return(1); | 119 | bi->flags = 0; |
118 | } | 120 | return (1); |
121 | } | ||
119 | 122 | ||
120 | static int sock_free(BIO *a) | 123 | static int |
121 | { | 124 | sock_free(BIO *a) |
122 | if (a == NULL) return(0); | 125 | { |
123 | if (a->shutdown) | 126 | if (a == NULL) |
124 | { | 127 | return (0); |
125 | if (a->init) | 128 | if (a->shutdown) { |
126 | { | 129 | if (a->init) { |
127 | shutdown(a->num, SHUT_RDWR); | 130 | shutdown(a->num, SHUT_RDWR); |
128 | close(a->num); | 131 | close(a->num); |
129 | } | ||
130 | a->init=0; | ||
131 | a->flags=0; | ||
132 | } | 132 | } |
133 | return(1); | 133 | a->init = 0; |
134 | a->flags = 0; | ||
134 | } | 135 | } |
135 | 136 | return (1); | |
136 | static int sock_read(BIO *b, char *out, int outl) | 137 | } |
137 | { | ||
138 | int ret=0; | ||
139 | 138 | ||
140 | if (out != NULL) | 139 | static int |
141 | { | 140 | sock_read(BIO *b, char *out, int outl) |
141 | { | ||
142 | int ret = 0; | ||
143 | |||
144 | if (out != NULL) { | ||
142 | errno = 0; | 145 | errno = 0; |
143 | ret=read(b->num,out,outl); | 146 | ret = read(b->num, out, outl); |
144 | BIO_clear_retry_flags(b); | 147 | BIO_clear_retry_flags(b); |
145 | if (ret <= 0) | 148 | if (ret <= 0) { |
146 | { | ||
147 | if (BIO_sock_should_retry(ret)) | 149 | if (BIO_sock_should_retry(ret)) |
148 | BIO_set_retry_read(b); | 150 | BIO_set_retry_read(b); |
149 | } | ||
150 | } | 151 | } |
151 | return(ret); | ||
152 | } | 152 | } |
153 | return (ret); | ||
154 | } | ||
153 | 155 | ||
154 | static int sock_write(BIO *b, const char *in, int inl) | 156 | static int |
155 | { | 157 | sock_write(BIO *b, const char *in, int inl) |
158 | { | ||
156 | int ret; | 159 | int ret; |
157 | 160 | ||
158 | errno = 0; | 161 | errno = 0; |
159 | ret=write(b->num,in,inl); | 162 | ret = write(b->num, in, inl); |
160 | BIO_clear_retry_flags(b); | 163 | BIO_clear_retry_flags(b); |
161 | if (ret <= 0) | 164 | if (ret <= 0) { |
162 | { | ||
163 | if (BIO_sock_should_retry(ret)) | 165 | if (BIO_sock_should_retry(ret)) |
164 | BIO_set_retry_write(b); | 166 | BIO_set_retry_write(b); |
165 | } | ||
166 | return(ret); | ||
167 | } | 167 | } |
168 | return (ret); | ||
169 | } | ||
168 | 170 | ||
169 | static long sock_ctrl(BIO *b, int cmd, long num, void *ptr) | 171 | static long |
170 | { | 172 | sock_ctrl(BIO *b, int cmd, long num, void *ptr) |
171 | long ret=1; | 173 | { |
174 | long ret = 1; | ||
172 | int *ip; | 175 | int *ip; |
173 | 176 | ||
174 | switch (cmd) | 177 | switch (cmd) { |
175 | { | ||
176 | case BIO_C_SET_FD: | 178 | case BIO_C_SET_FD: |
177 | sock_free(b); | 179 | sock_free(b); |
178 | b->num= *((int *)ptr); | 180 | b->num= *((int *)ptr); |
179 | b->shutdown=(int)num; | 181 | b->shutdown = (int)num; |
180 | b->init=1; | 182 | b->init = 1; |
181 | break; | 183 | break; |
182 | case BIO_C_GET_FD: | 184 | case BIO_C_GET_FD: |
183 | if (b->init) | 185 | if (b->init) { |
184 | { | 186 | ip = (int *)ptr; |
185 | ip=(int *)ptr; | 187 | if (ip != NULL) |
186 | if (ip != NULL) *ip=b->num; | 188 | *ip = b->num; |
187 | ret=b->num; | 189 | ret = b->num; |
188 | } | 190 | } else |
189 | else | 191 | ret = -1; |
190 | ret= -1; | ||
191 | break; | 192 | break; |
192 | case BIO_CTRL_GET_CLOSE: | 193 | case BIO_CTRL_GET_CLOSE: |
193 | ret=b->shutdown; | 194 | ret = b->shutdown; |
194 | break; | 195 | break; |
195 | case BIO_CTRL_SET_CLOSE: | 196 | case BIO_CTRL_SET_CLOSE: |
196 | b->shutdown=(int)num; | 197 | b->shutdown = (int)num; |
197 | break; | 198 | break; |
198 | case BIO_CTRL_DUP: | 199 | case BIO_CTRL_DUP: |
199 | case BIO_CTRL_FLUSH: | 200 | case BIO_CTRL_FLUSH: |
200 | ret=1; | 201 | ret = 1; |
201 | break; | 202 | break; |
202 | default: | 203 | default: |
203 | ret=0; | 204 | ret = 0; |
204 | break; | 205 | break; |
205 | } | ||
206 | return(ret); | ||
207 | } | 206 | } |
207 | return (ret); | ||
208 | } | ||
208 | 209 | ||
209 | static int sock_puts(BIO *bp, const char *str) | 210 | static int |
210 | { | 211 | sock_puts(BIO *bp, const char *str) |
211 | int n,ret; | 212 | { |
213 | int n, ret; | ||
212 | 214 | ||
213 | n=strlen(str); | 215 | n = strlen(str); |
214 | ret=sock_write(bp,str,n); | 216 | ret = sock_write(bp, str, n); |
215 | return(ret); | 217 | return (ret); |
216 | } | 218 | } |
217 | 219 | ||
218 | int BIO_sock_should_retry(int i) | 220 | int |
219 | { | 221 | BIO_sock_should_retry(int i) |
222 | { | ||
220 | int err; | 223 | int err; |
221 | 224 | ||
222 | if ((i == 0) || (i == -1)) | 225 | if ((i == 0) || (i == -1)) { |
223 | { | 226 | err = errno; |
224 | err=errno; | ||
225 | 227 | ||
226 | #if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */ | 228 | #if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */ |
227 | if ((i == -1) && (err == 0)) | 229 | if ((i == -1) && (err == 0)) |
228 | return(1); | 230 | return (1); |
229 | #endif | 231 | #endif |
230 | 232 | ||
231 | return(BIO_sock_non_fatal_error(err)); | 233 | return (BIO_sock_non_fatal_error(err)); |
232 | } | ||
233 | return(0); | ||
234 | } | 234 | } |
235 | return (0); | ||
236 | } | ||
235 | 237 | ||
236 | int BIO_sock_non_fatal_error(int err) | 238 | int |
237 | { | 239 | BIO_sock_non_fatal_error(int err) |
238 | switch (err) | 240 | { |
239 | { | 241 | switch (err) { |
240 | #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_NETWARE) | 242 | #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_NETWARE) |
241 | # if defined(WSAEWOULDBLOCK) | 243 | # if defined(WSAEWOULDBLOCK) |
242 | case WSAEWOULDBLOCK: | 244 | case WSAEWOULDBLOCK: |
@@ -284,12 +286,12 @@ int BIO_sock_non_fatal_error(int err) | |||
284 | #ifdef EALREADY | 286 | #ifdef EALREADY |
285 | case EALREADY: | 287 | case EALREADY: |
286 | #endif | 288 | #endif |
287 | return(1); | 289 | return (1); |
288 | /* break; */ | 290 | /* break; */ |
289 | default: | 291 | default: |
290 | break; | 292 | break; |
291 | } | ||
292 | return(0); | ||
293 | } | 293 | } |
294 | return (0); | ||
295 | } | ||
294 | 296 | ||
295 | #endif /* #ifndef OPENSSL_NO_SOCK */ | 297 | #endif /* #ifndef OPENSSL_NO_SOCK */ |
diff --git a/src/lib/libssl/src/crypto/bio/b_dump.c b/src/lib/libssl/src/crypto/bio/b_dump.c index 492ee09275..bea94969a2 100644 --- a/src/lib/libssl/src/crypto/bio/b_dump.c +++ b/src/lib/libssl/src/crypto/bio/b_dump.c | |||
@@ -66,122 +66,125 @@ | |||
66 | 66 | ||
67 | #define TRUNCATE | 67 | #define TRUNCATE |
68 | #define DUMP_WIDTH 16 | 68 | #define DUMP_WIDTH 16 |
69 | #define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH-((i-(i>6?6:i)+3)/4)) | 69 | #define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH - ((i - (i > 6 ? 6 : i) + 3) / 4)) |
70 | 70 | ||
71 | int BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u), | 71 | int |
72 | void *u, const char *s, int len) | 72 | BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u), |
73 | { | 73 | void *u, const char *s, int len) |
74 | { | ||
74 | return BIO_dump_indent_cb(cb, u, s, len, 0); | 75 | return BIO_dump_indent_cb(cb, u, s, len, 0); |
75 | } | 76 | } |
76 | 77 | ||
77 | int BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), | 78 | int |
78 | void *u, const char *s, int len, int indent) | 79 | BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), |
79 | { | 80 | void *u, const char *s, int len, int indent) |
80 | int ret=0; | 81 | { |
81 | char buf[288+1],tmp[20],str[128+1]; | 82 | int ret = 0; |
82 | int i,j,rows,trc; | 83 | char buf[288 + 1], tmp[20], str[128 + 1]; |
84 | int i, j, rows, trc; | ||
83 | unsigned char ch; | 85 | unsigned char ch; |
84 | int dump_width; | 86 | int dump_width; |
85 | 87 | ||
86 | trc=0; | 88 | trc = 0; |
87 | 89 | ||
88 | #ifdef TRUNCATE | 90 | #ifdef TRUNCATE |
89 | for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--) | 91 | for (; (len > 0) && ((s[len - 1] == ' ') || (s[len - 1] == '\0')); len--) |
90 | trc++; | 92 | trc++; |
91 | #endif | 93 | #endif |
92 | 94 | ||
93 | if (indent < 0) | 95 | if (indent < 0) |
94 | indent = 0; | 96 | indent = 0; |
95 | if (indent) | 97 | if (indent) { |
96 | { | 98 | if (indent > 128) |
97 | if (indent > 128) indent=128; | 99 | indent = 128; |
98 | memset(str,' ',indent); | 100 | memset(str, ' ', indent); |
99 | } | 101 | } |
100 | str[indent]='\0'; | 102 | str[indent] = '\0'; |
101 | 103 | ||
102 | dump_width=DUMP_WIDTH_LESS_INDENT(indent); | 104 | dump_width = DUMP_WIDTH_LESS_INDENT(indent); |
103 | rows=(len/dump_width); | 105 | rows = (len / dump_width); |
104 | if ((rows*dump_width)<len) | 106 | if ((rows * dump_width) < len) |
105 | rows++; | 107 | rows++; |
106 | for(i=0;i<rows;i++) | 108 | for (i = 0; i < rows; i++) { |
107 | { | 109 | buf[0] = '\0'; /* start with empty string */ |
108 | buf[0]='\0'; /* start with empty string */ | 110 | BUF_strlcpy(buf, str, sizeof buf); |
109 | BUF_strlcpy(buf,str,sizeof buf); | 111 | (void) snprintf(tmp, sizeof tmp, "%04x - ", i*dump_width); |
110 | (void) snprintf(tmp,sizeof tmp,"%04x - ",i*dump_width); | 112 | BUF_strlcat(buf, tmp, sizeof buf); |
111 | BUF_strlcat(buf,tmp,sizeof buf); | 113 | for (j = 0; j < dump_width; j++) { |
112 | for(j=0;j<dump_width;j++) | 114 | if (((i*dump_width) + j) >= len) { |
113 | { | 115 | BUF_strlcat(buf, " ", sizeof buf); |
114 | if (((i*dump_width)+j)>=len) | 116 | } else { |
115 | { | 117 | ch = ((unsigned char)*(s + i*dump_width + j)) & 0xff; |
116 | BUF_strlcat(buf," ",sizeof buf); | 118 | (void) snprintf(tmp, sizeof tmp, "%02x%c", ch, |
117 | } | 119 | j == 7 ? '-' : ' '); |
118 | else | 120 | BUF_strlcat(buf, tmp, sizeof buf); |
119 | { | ||
120 | ch=((unsigned char)*(s+i*dump_width+j)) & 0xff; | ||
121 | (void) snprintf(tmp,sizeof tmp,"%02x%c",ch, | ||
122 | j==7?'-':' '); | ||
123 | BUF_strlcat(buf,tmp,sizeof buf); | ||
124 | } | ||
125 | } | 121 | } |
126 | BUF_strlcat(buf," ",sizeof buf); | 122 | } |
127 | for(j=0;j<dump_width;j++) | 123 | BUF_strlcat(buf, " ", sizeof buf); |
128 | { | 124 | for (j = 0; j < dump_width; j++) { |
129 | if (((i*dump_width)+j)>=len) | 125 | if (((i*dump_width) + j) >= len) |
130 | break; | 126 | break; |
131 | ch=((unsigned char)*(s+i*dump_width+j)) & 0xff; | 127 | ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff; |
132 | #ifndef CHARSET_EBCDIC | 128 | #ifndef CHARSET_EBCDIC |
133 | (void) snprintf(tmp,sizeof tmp,"%c", | 129 | (void) snprintf(tmp, sizeof tmp, "%c", |
134 | ((ch>=' ')&&(ch<='~'))?ch:'.'); | 130 | ((ch >= ' ') && (ch <= '~')) ? ch : '.'); |
135 | #else | 131 | #else |
136 | (void) snprintf(tmp,sizeof tmp,"%c", | 132 | (void) snprintf(tmp, sizeof tmp, "%c", |
137 | ((ch>=os_toascii[' '])&&(ch<=os_toascii['~'])) | 133 | ((ch >= os_toascii[' ']) && (ch <= os_toascii['~'])) |
138 | ? os_toebcdic[ch] | 134 | ? os_toebcdic[ch] : '.'); |
139 | : '.'); | ||
140 | #endif | 135 | #endif |
141 | BUF_strlcat(buf,tmp,sizeof buf); | 136 | BUF_strlcat(buf, tmp, sizeof buf); |
142 | } | 137 | } |
143 | BUF_strlcat(buf,"\n",sizeof buf); | 138 | BUF_strlcat(buf, "\n", sizeof buf); |
144 | /* if this is the last call then update the ddt_dump thing so | 139 | /* if this is the last call then update the ddt_dump thing so |
145 | * that we will move the selection point in the debug window | 140 | * that we will move the selection point in the debug window |
146 | */ | 141 | */ |
147 | ret+=cb((void *)buf,strlen(buf),u); | 142 | ret += cb((void *)buf, strlen(buf), u); |
148 | } | 143 | } |
149 | #ifdef TRUNCATE | 144 | #ifdef TRUNCATE |
150 | if (trc > 0) | 145 | if (trc > 0) { |
151 | { | 146 | (void) snprintf(buf, sizeof buf, "%s%04x - <SPACES/NULS>\n", |
152 | (void) snprintf(buf,sizeof buf,"%s%04x - <SPACES/NULS>\n",str, | 147 | str, len + trc); |
153 | len+trc); | 148 | ret += cb((void *)buf, strlen(buf), u); |
154 | ret+=cb((void *)buf,strlen(buf),u); | ||
155 | } | ||
156 | #endif | ||
157 | return(ret); | ||
158 | } | 149 | } |
150 | #endif | ||
151 | return (ret); | ||
152 | } | ||
159 | 153 | ||
160 | #ifndef OPENSSL_NO_FP_API | 154 | #ifndef OPENSSL_NO_FP_API |
161 | static int write_fp(const void *data, size_t len, void *fp) | 155 | static int |
162 | { | 156 | write_fp(const void *data, size_t len, void *fp) |
157 | { | ||
163 | return UP_fwrite(data, len, 1, fp); | 158 | return UP_fwrite(data, len, 1, fp); |
164 | } | 159 | } |
165 | int BIO_dump_fp(FILE *fp, const char *s, int len) | 160 | |
166 | { | 161 | int |
162 | BIO_dump_fp(FILE *fp, const char *s, int len) | ||
163 | { | ||
167 | return BIO_dump_cb(write_fp, fp, s, len); | 164 | return BIO_dump_cb(write_fp, fp, s, len); |
168 | } | 165 | } |
169 | int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent) | 166 | |
170 | { | 167 | int |
168 | BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent) | ||
169 | { | ||
171 | return BIO_dump_indent_cb(write_fp, fp, s, len, indent); | 170 | return BIO_dump_indent_cb(write_fp, fp, s, len, indent); |
172 | } | 171 | } |
173 | #endif | 172 | #endif |
174 | 173 | ||
175 | static int write_bio(const void *data, size_t len, void *bp) | 174 | static int |
176 | { | 175 | write_bio(const void *data, size_t len, void *bp) |
176 | { | ||
177 | return BIO_write((BIO *)bp, (const char *)data, len); | 177 | return BIO_write((BIO *)bp, (const char *)data, len); |
178 | } | 178 | } |
179 | int BIO_dump(BIO *bp, const char *s, int len) | 179 | |
180 | { | 180 | int |
181 | BIO_dump(BIO *bp, const char *s, int len) | ||
182 | { | ||
181 | return BIO_dump_cb(write_bio, bp, s, len); | 183 | return BIO_dump_cb(write_bio, bp, s, len); |
182 | } | 184 | } |
183 | int BIO_dump_indent(BIO *bp, const char *s, int len, int indent) | ||
184 | { | ||
185 | return BIO_dump_indent_cb(write_bio, bp, s, len, indent); | ||
186 | } | ||
187 | 185 | ||
186 | int | ||
187 | BIO_dump_indent(BIO *bp, const char *s, int len, int indent) | ||
188 | { | ||
189 | return BIO_dump_indent_cb(write_bio, bp, s, len, indent); | ||
190 | } | ||
diff --git a/src/lib/libssl/src/crypto/bio/b_print.c b/src/lib/libssl/src/crypto/bio/b_print.c index 143a7cfefa..b3b0d45ee6 100644 --- a/src/lib/libssl/src/crypto/bio/b_print.c +++ b/src/lib/libssl/src/crypto/bio/b_print.c | |||
@@ -125,16 +125,15 @@ | |||
125 | #define LLONG long | 125 | #define LLONG long |
126 | #endif | 126 | #endif |
127 | 127 | ||
128 | static void fmtstr (char **, char **, size_t *, size_t *, | 128 | static void fmtstr(char **, char **, size_t *, size_t *, const char *, |
129 | const char *, int, int, int); | 129 | int, int, int); |
130 | static void fmtint (char **, char **, size_t *, size_t *, | 130 | static void fmtint(char **, char **, size_t *, size_t *, LLONG, int, |
131 | LLONG, int, int, int, int); | 131 | int, int, int); |
132 | static void fmtfp (char **, char **, size_t *, size_t *, | 132 | static void fmtfp(char **, char **, size_t *, size_t *, LDOUBLE, |
133 | LDOUBLE, int, int, int); | 133 | int, int, int); |
134 | static void doapr_outch (char **, char **, size_t *, size_t *, int); | 134 | static void doapr_outch(char **, char **, size_t *, size_t *, int); |
135 | static void _dopr(char **sbuffer, char **buffer, | 135 | static void _dopr(char **sbuffer, char **buffer, size_t *maxlen, |
136 | size_t *maxlen, size_t *retlen, int *truncated, | 136 | size_t *retlen, int *truncated, const char *format, va_list args); |
137 | const char *format, va_list args); | ||
138 | 137 | ||
139 | /* format read states */ | 138 | /* format read states */ |
140 | #define DP_S_DEFAULT 0 | 139 | #define DP_S_DEFAULT 0 |
@@ -166,607 +165,576 @@ static void _dopr(char **sbuffer, char **buffer, | |||
166 | #define OSSL_MAX(p,q) ((p >= q) ? p : q) | 165 | #define OSSL_MAX(p,q) ((p >= q) ? p : q) |
167 | 166 | ||
168 | static void | 167 | static void |
169 | _dopr( | 168 | _dopr(char **sbuffer, char **buffer, size_t *maxlen, size_t *retlen, |
170 | char **sbuffer, | 169 | int *truncated, const char *format, va_list args) |
171 | char **buffer, | ||
172 | size_t *maxlen, | ||
173 | size_t *retlen, | ||
174 | int *truncated, | ||
175 | const char *format, | ||
176 | va_list args) | ||
177 | { | 170 | { |
178 | char ch; | 171 | char ch; |
179 | LLONG value; | 172 | LLONG value; |
180 | LDOUBLE fvalue; | 173 | LDOUBLE fvalue; |
181 | char *strvalue; | 174 | char *strvalue; |
182 | int min; | 175 | int min; |
183 | int max; | 176 | int max; |
184 | int state; | 177 | int state; |
185 | int flags; | 178 | int flags; |
186 | int cflags; | 179 | int cflags; |
187 | size_t currlen; | 180 | size_t currlen; |
188 | 181 | ||
189 | state = DP_S_DEFAULT; | 182 | state = DP_S_DEFAULT; |
190 | flags = currlen = cflags = min = 0; | 183 | flags = currlen = cflags = min = 0; |
191 | max = -1; | 184 | max = -1; |
192 | ch = *format++; | 185 | ch = *format++; |
193 | 186 | ||
194 | while (state != DP_S_DONE) { | 187 | while (state != DP_S_DONE) { |
195 | if (ch == '\0' || (buffer == NULL && currlen >= *maxlen)) | 188 | if (ch == '\0' || (buffer == NULL && currlen >= *maxlen)) |
196 | state = DP_S_DONE; | 189 | state = DP_S_DONE; |
197 | 190 | ||
198 | switch (state) { | 191 | switch (state) { |
199 | case DP_S_DEFAULT: | 192 | case DP_S_DEFAULT: |
200 | if (ch == '%') | 193 | if (ch == '%') |
201 | state = DP_S_FLAGS; | 194 | state = DP_S_FLAGS; |
202 | else | 195 | else |
203 | doapr_outch(sbuffer,buffer, &currlen, maxlen, ch); | 196 | doapr_outch(sbuffer, buffer, &currlen, maxlen, ch); |
204 | ch = *format++; | 197 | ch = *format++; |
205 | break; | 198 | break; |
206 | case DP_S_FLAGS: | 199 | case DP_S_FLAGS: |
207 | switch (ch) { | 200 | switch (ch) { |
208 | case '-': | 201 | case '-': |
209 | flags |= DP_F_MINUS; | 202 | flags |= DP_F_MINUS; |
210 | ch = *format++; | 203 | ch = *format++; |
211 | break; | 204 | break; |
212 | case '+': | 205 | case '+': |
213 | flags |= DP_F_PLUS; | 206 | flags |= DP_F_PLUS; |
214 | ch = *format++; | 207 | ch = *format++; |
215 | break; | 208 | break; |
216 | case ' ': | 209 | case ' ': |
217 | flags |= DP_F_SPACE; | 210 | flags |= DP_F_SPACE; |
218 | ch = *format++; | 211 | ch = *format++; |
219 | break; | 212 | break; |
220 | case '#': | 213 | case '#': |
221 | flags |= DP_F_NUM; | 214 | flags |= DP_F_NUM; |
222 | ch = *format++; | 215 | ch = *format++; |
223 | break; | 216 | break; |
224 | case '0': | 217 | case '0': |
225 | flags |= DP_F_ZERO; | 218 | flags |= DP_F_ZERO; |
226 | ch = *format++; | 219 | ch = *format++; |
227 | break; | 220 | break; |
228 | default: | 221 | default: |
229 | state = DP_S_MIN; | 222 | state = DP_S_MIN; |
230 | break; | 223 | break; |
231 | } | 224 | } |
232 | break; | 225 | break; |
233 | case DP_S_MIN: | 226 | case DP_S_MIN: |
234 | if (isdigit((unsigned char)ch)) { | 227 | if (isdigit((unsigned char)ch)) { |
235 | min = 10 * min + char_to_int(ch); | 228 | min = 10 * min + char_to_int(ch); |
236 | ch = *format++; | 229 | ch = *format++; |
237 | } else if (ch == '*') { | 230 | } else if (ch == '*') { |
238 | min = va_arg(args, int); | 231 | min = va_arg(args, int); |
239 | ch = *format++; | 232 | ch = *format++; |
240 | state = DP_S_DOT; | 233 | state = DP_S_DOT; |
241 | } else | 234 | } else |
242 | state = DP_S_DOT; | 235 | state = DP_S_DOT; |
243 | break; | 236 | break; |
244 | case DP_S_DOT: | 237 | case DP_S_DOT: |
245 | if (ch == '.') { | 238 | if (ch == '.') { |
246 | state = DP_S_MAX; | 239 | state = DP_S_MAX; |
247 | ch = *format++; | 240 | ch = *format++; |
248 | } else | 241 | } else |
249 | state = DP_S_MOD; | 242 | state = DP_S_MOD; |
250 | break; | 243 | break; |
251 | case DP_S_MAX: | 244 | case DP_S_MAX: |
252 | if (isdigit((unsigned char)ch)) { | 245 | if (isdigit((unsigned char)ch)) { |
253 | if (max < 0) | 246 | if (max < 0) |
254 | max = 0; | 247 | max = 0; |
255 | max = 10 * max + char_to_int(ch); | 248 | max = 10 * max + char_to_int(ch); |
256 | ch = *format++; | 249 | ch = *format++; |
257 | } else if (ch == '*') { | 250 | } else if (ch == '*') { |
258 | max = va_arg(args, int); | 251 | max = va_arg(args, int); |
259 | ch = *format++; | 252 | ch = *format++; |
260 | state = DP_S_MOD; | 253 | state = DP_S_MOD; |
261 | } else | 254 | } else |
262 | state = DP_S_MOD; | 255 | state = DP_S_MOD; |
263 | break; | 256 | break; |
264 | case DP_S_MOD: | 257 | case DP_S_MOD: |
265 | switch (ch) { | 258 | switch (ch) { |
266 | case 'h': | 259 | case 'h': |
267 | cflags = DP_C_SHORT; | 260 | cflags = DP_C_SHORT; |
268 | ch = *format++; | 261 | ch = *format++; |
269 | break; | 262 | break; |
270 | case 'l': | 263 | case 'l': |
271 | if (*format == 'l') { | 264 | if (*format == 'l') { |
272 | cflags = DP_C_LLONG; | 265 | cflags = DP_C_LLONG; |
273 | format++; | 266 | format++; |
274 | } else | 267 | } else |
275 | cflags = DP_C_LONG; | 268 | cflags = DP_C_LONG; |
276 | ch = *format++; | 269 | ch = *format++; |
277 | break; | 270 | break; |
278 | case 'q': | 271 | case 'q': |
279 | cflags = DP_C_LLONG; | 272 | cflags = DP_C_LLONG; |
280 | ch = *format++; | 273 | ch = *format++; |
281 | break; | 274 | break; |
282 | case 'L': | 275 | case 'L': |
283 | cflags = DP_C_LDOUBLE; | 276 | cflags = DP_C_LDOUBLE; |
284 | ch = *format++; | 277 | ch = *format++; |
285 | break; | 278 | break; |
286 | default: | 279 | default: |
287 | break; | 280 | break; |
288 | } | 281 | } |
289 | state = DP_S_CONV; | 282 | state = DP_S_CONV; |
290 | break; | 283 | break; |
291 | case DP_S_CONV: | 284 | case DP_S_CONV: |
292 | switch (ch) { | 285 | switch (ch) { |
293 | case 'd': | 286 | case 'd': |
294 | case 'i': | 287 | case 'i': |
295 | switch (cflags) { | 288 | switch (cflags) { |
296 | case DP_C_SHORT: | 289 | case DP_C_SHORT: |
297 | value = (short int)va_arg(args, int); | 290 | value = (short int)va_arg(args, int); |
298 | break; | 291 | break; |
299 | case DP_C_LONG: | 292 | case DP_C_LONG: |
300 | value = va_arg(args, long int); | 293 | value = va_arg(args, long int); |
301 | break; | 294 | break; |
302 | case DP_C_LLONG: | 295 | case DP_C_LLONG: |
303 | value = va_arg(args, LLONG); | 296 | value = va_arg(args, LLONG); |
304 | break; | 297 | break; |
305 | default: | 298 | default: |
306 | value = va_arg(args, int); | 299 | value = va_arg(args, int); |
307 | break; | 300 | break; |
308 | } | 301 | } |
309 | fmtint(sbuffer, buffer, &currlen, maxlen, | 302 | fmtint(sbuffer, buffer, &currlen, maxlen, |
310 | value, 10, min, max, flags); | 303 | value, 10, min, max, flags); |
311 | break; | 304 | break; |
312 | case 'X': | 305 | case 'X': |
313 | flags |= DP_F_UP; | 306 | flags |= DP_F_UP; |
314 | /* FALLTHROUGH */ | 307 | /* FALLTHROUGH */ |
315 | case 'x': | 308 | case 'x': |
316 | case 'o': | 309 | case 'o': |
317 | case 'u': | 310 | case 'u': |
318 | flags |= DP_F_UNSIGNED; | 311 | flags |= DP_F_UNSIGNED; |
319 | switch (cflags) { | 312 | switch (cflags) { |
320 | case DP_C_SHORT: | 313 | case DP_C_SHORT: |
321 | value = (unsigned short int)va_arg(args, unsigned int); | 314 | value = (unsigned short int)va_arg( |
322 | break; | 315 | args, unsigned int); |
323 | case DP_C_LONG: | 316 | break; |
324 | value = (LLONG) va_arg(args, | 317 | case DP_C_LONG: |
325 | unsigned long int); | 318 | value = (LLONG)va_arg(args, |
326 | break; | 319 | unsigned long int); |
327 | case DP_C_LLONG: | 320 | break; |
328 | value = va_arg(args, unsigned LLONG); | 321 | case DP_C_LLONG: |
329 | break; | 322 | value = va_arg(args, unsigned LLONG); |
330 | default: | 323 | break; |
331 | value = (LLONG) va_arg(args, | 324 | default: |
332 | unsigned int); | 325 | value = (LLONG)va_arg(args, |
333 | break; | 326 | unsigned int); |
334 | } | 327 | break; |
335 | fmtint(sbuffer, buffer, &currlen, maxlen, value, | 328 | } |
336 | ch == 'o' ? 8 : (ch == 'u' ? 10 : 16), | 329 | fmtint(sbuffer, buffer, &currlen, maxlen, value, |
337 | min, max, flags); | 330 | ch == 'o' ? 8 : (ch == 'u' ? 10 : 16), |
338 | break; | 331 | min, max, flags); |
339 | case 'f': | 332 | break; |
340 | if (cflags == DP_C_LDOUBLE) | 333 | case 'f': |
341 | fvalue = va_arg(args, LDOUBLE); | 334 | if (cflags == DP_C_LDOUBLE) |
342 | else | 335 | fvalue = va_arg(args, LDOUBLE); |
343 | fvalue = va_arg(args, double); | 336 | else |
344 | fmtfp(sbuffer, buffer, &currlen, maxlen, | 337 | fvalue = va_arg(args, double); |
345 | fvalue, min, max, flags); | 338 | fmtfp(sbuffer, buffer, &currlen, maxlen, |
346 | break; | 339 | fvalue, min, max, flags); |
347 | case 'E': | 340 | break; |
348 | flags |= DP_F_UP; | 341 | case 'E': |
349 | case 'e': | 342 | flags |= DP_F_UP; |
350 | if (cflags == DP_C_LDOUBLE) | 343 | case 'e': |
351 | fvalue = va_arg(args, LDOUBLE); | 344 | if (cflags == DP_C_LDOUBLE) |
352 | else | 345 | fvalue = va_arg(args, LDOUBLE); |
353 | fvalue = va_arg(args, double); | 346 | else |
354 | break; | 347 | fvalue = va_arg(args, double); |
355 | case 'G': | 348 | break; |
356 | flags |= DP_F_UP; | 349 | case 'G': |
357 | case 'g': | 350 | flags |= DP_F_UP; |
358 | if (cflags == DP_C_LDOUBLE) | 351 | case 'g': |
359 | fvalue = va_arg(args, LDOUBLE); | 352 | if (cflags == DP_C_LDOUBLE) |
360 | else | 353 | fvalue = va_arg(args, LDOUBLE); |
361 | fvalue = va_arg(args, double); | 354 | else |
362 | break; | 355 | fvalue = va_arg(args, double); |
363 | case 'c': | 356 | break; |
364 | doapr_outch(sbuffer, buffer, &currlen, maxlen, | 357 | case 'c': |
365 | va_arg(args, int)); | 358 | doapr_outch(sbuffer, buffer, &currlen, maxlen, |
366 | break; | 359 | va_arg(args, int)); |
367 | case 's': | 360 | break; |
368 | strvalue = va_arg(args, char *); | 361 | case 's': |
369 | if (max < 0) { | 362 | strvalue = va_arg(args, char *); |
370 | if (buffer) | 363 | if (max < 0) { |
371 | max = INT_MAX; | 364 | if (buffer) |
372 | else | 365 | max = INT_MAX; |
373 | max = *maxlen; | 366 | else |
367 | max = *maxlen; | ||
368 | } | ||
369 | fmtstr(sbuffer, buffer, &currlen, maxlen, | ||
370 | strvalue, flags, min, max); | ||
371 | break; | ||
372 | case 'p': | ||
373 | value = (long)va_arg(args, void *); | ||
374 | fmtint(sbuffer, buffer, &currlen, maxlen, | ||
375 | value, 16, min, max, flags|DP_F_NUM); | ||
376 | break; | ||
377 | case 'n': /* XXX */ | ||
378 | if (cflags == DP_C_SHORT) { | ||
379 | short int *num; | ||
380 | num = va_arg(args, short int *); | ||
381 | *num = currlen; | ||
382 | } else if (cflags == DP_C_LONG) { /* XXX */ | ||
383 | long int *num; | ||
384 | num = va_arg(args, long int *); | ||
385 | *num = (long int) currlen; | ||
386 | } else if (cflags == DP_C_LLONG) { /* XXX */ | ||
387 | LLONG *num; | ||
388 | num = va_arg(args, LLONG *); | ||
389 | *num = (LLONG) currlen; | ||
390 | } else { | ||
391 | int *num; | ||
392 | num = va_arg(args, int *); | ||
393 | *num = currlen; | ||
394 | } | ||
395 | break; | ||
396 | case '%': | ||
397 | doapr_outch(sbuffer, buffer, &currlen, maxlen, ch); | ||
398 | break; | ||
399 | case 'w': | ||
400 | /* not supported yet, treat as next char */ | ||
401 | ch = *format++; | ||
402 | break; | ||
403 | default: | ||
404 | /* unknown, skip */ | ||
405 | break; | ||
406 | } | ||
407 | ch = *format++; | ||
408 | state = DP_S_DEFAULT; | ||
409 | flags = cflags = min = 0; | ||
410 | max = -1; | ||
411 | break; | ||
412 | case DP_S_DONE: | ||
413 | break; | ||
414 | default: | ||
415 | break; | ||
374 | } | 416 | } |
375 | fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue, | 417 | } |
376 | flags, min, max); | 418 | *truncated = (currlen > *maxlen - 1); |
377 | break; | 419 | if (*truncated) |
378 | case 'p': | 420 | currlen = *maxlen - 1; |
379 | value = (long)va_arg(args, void *); | 421 | doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0'); |
380 | fmtint(sbuffer, buffer, &currlen, maxlen, | 422 | *retlen = currlen - 1; |
381 | value, 16, min, max, flags|DP_F_NUM); | 423 | return; |
382 | break; | ||
383 | case 'n': /* XXX */ | ||
384 | if (cflags == DP_C_SHORT) { | ||
385 | short int *num; | ||
386 | num = va_arg(args, short int *); | ||
387 | *num = currlen; | ||
388 | } else if (cflags == DP_C_LONG) { /* XXX */ | ||
389 | long int *num; | ||
390 | num = va_arg(args, long int *); | ||
391 | *num = (long int) currlen; | ||
392 | } else if (cflags == DP_C_LLONG) { /* XXX */ | ||
393 | LLONG *num; | ||
394 | num = va_arg(args, LLONG *); | ||
395 | *num = (LLONG) currlen; | ||
396 | } else { | ||
397 | int *num; | ||
398 | num = va_arg(args, int *); | ||
399 | *num = currlen; | ||
400 | } | ||
401 | break; | ||
402 | case '%': | ||
403 | doapr_outch(sbuffer, buffer, &currlen, maxlen, ch); | ||
404 | break; | ||
405 | case 'w': | ||
406 | /* not supported yet, treat as next char */ | ||
407 | ch = *format++; | ||
408 | break; | ||
409 | default: | ||
410 | /* unknown, skip */ | ||
411 | break; | ||
412 | } | ||
413 | ch = *format++; | ||
414 | state = DP_S_DEFAULT; | ||
415 | flags = cflags = min = 0; | ||
416 | max = -1; | ||
417 | break; | ||
418 | case DP_S_DONE: | ||
419 | break; | ||
420 | default: | ||
421 | break; | ||
422 | } | ||
423 | } | ||
424 | *truncated = (currlen > *maxlen - 1); | ||
425 | if (*truncated) | ||
426 | currlen = *maxlen - 1; | ||
427 | doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0'); | ||
428 | *retlen = currlen - 1; | ||
429 | return; | ||
430 | } | 424 | } |
431 | 425 | ||
432 | static void | 426 | static void |
433 | fmtstr( | 427 | fmtstr(char **sbuffer, char **buffer, size_t *currlen, size_t *maxlen, |
434 | char **sbuffer, | 428 | const char *value, int flags, int min, int max) |
435 | char **buffer, | ||
436 | size_t *currlen, | ||
437 | size_t *maxlen, | ||
438 | const char *value, | ||
439 | int flags, | ||
440 | int min, | ||
441 | int max) | ||
442 | { | 429 | { |
443 | int padlen, strln; | 430 | int padlen, strln; |
444 | int cnt = 0; | 431 | int cnt = 0; |
445 | 432 | ||
446 | if (value == 0) | 433 | if (value == 0) |
447 | value = "<NULL>"; | 434 | value = "<NULL>"; |
448 | for (strln = 0; value[strln]; ++strln) | 435 | for (strln = 0; value[strln]; ++strln) |
449 | ; | 436 | ; |
450 | padlen = min - strln; | 437 | padlen = min - strln; |
451 | if (padlen < 0) | 438 | if (padlen < 0) |
452 | padlen = 0; | 439 | padlen = 0; |
453 | if (flags & DP_F_MINUS) | 440 | if (flags & DP_F_MINUS) |
454 | padlen = -padlen; | 441 | padlen = -padlen; |
455 | 442 | ||
456 | while ((padlen > 0) && (cnt < max)) { | 443 | while ((padlen > 0) && (cnt < max)) { |
457 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); | 444 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); |
458 | --padlen; | 445 | --padlen; |
459 | ++cnt; | 446 | ++cnt; |
460 | } | 447 | } |
461 | while (*value && (cnt < max)) { | 448 | while (*value && (cnt < max)) { |
462 | doapr_outch(sbuffer, buffer, currlen, maxlen, *value++); | 449 | doapr_outch(sbuffer, buffer, currlen, maxlen, *value++); |
463 | ++cnt; | 450 | ++cnt; |
464 | } | 451 | } |
465 | while ((padlen < 0) && (cnt < max)) { | 452 | while ((padlen < 0) && (cnt < max)) { |
466 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); | 453 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); |
467 | ++padlen; | 454 | ++padlen; |
468 | ++cnt; | 455 | ++cnt; |
469 | } | 456 | } |
470 | } | 457 | } |
471 | 458 | ||
472 | static void | 459 | static void |
473 | fmtint( | 460 | fmtint(char **sbuffer, char **buffer, size_t *currlen, size_t *maxlen, |
474 | char **sbuffer, | 461 | LLONG value, int base, int min, int max, int flags) |
475 | char **buffer, | ||
476 | size_t *currlen, | ||
477 | size_t *maxlen, | ||
478 | LLONG value, | ||
479 | int base, | ||
480 | int min, | ||
481 | int max, | ||
482 | int flags) | ||
483 | { | 462 | { |
484 | int signvalue = 0; | 463 | int signvalue = 0; |
485 | const char *prefix = ""; | 464 | const char *prefix = ""; |
486 | unsigned LLONG uvalue; | 465 | unsigned LLONG uvalue; |
487 | char convert[DECIMAL_SIZE(value)+3]; | 466 | char convert[DECIMAL_SIZE(value) + 3]; |
488 | int place = 0; | 467 | int place = 0; |
489 | int spadlen = 0; | 468 | int spadlen = 0; |
490 | int zpadlen = 0; | 469 | int zpadlen = 0; |
491 | int caps = 0; | 470 | int caps = 0; |
492 | 471 | ||
493 | if (max < 0) | 472 | if (max < 0) |
494 | max = 0; | 473 | max = 0; |
495 | uvalue = value; | 474 | uvalue = value; |
496 | if (!(flags & DP_F_UNSIGNED)) { | 475 | if (!(flags & DP_F_UNSIGNED)) { |
497 | if (value < 0) { | 476 | if (value < 0) { |
498 | signvalue = '-'; | 477 | signvalue = '-'; |
499 | uvalue = -value; | 478 | uvalue = -value; |
500 | } else if (flags & DP_F_PLUS) | 479 | } else if (flags & DP_F_PLUS) |
501 | signvalue = '+'; | 480 | signvalue = '+'; |
502 | else if (flags & DP_F_SPACE) | 481 | else if (flags & DP_F_SPACE) |
503 | signvalue = ' '; | 482 | signvalue = ' '; |
504 | } | 483 | } |
505 | if (flags & DP_F_NUM) { | 484 | if (flags & DP_F_NUM) { |
506 | if (base == 8) prefix = "0"; | 485 | if (base == 8) |
507 | if (base == 16) prefix = "0x"; | 486 | prefix = "0"; |
508 | } | 487 | if (base == 16) |
509 | if (flags & DP_F_UP) | 488 | prefix = "0x"; |
510 | caps = 1; | 489 | } |
511 | do { | 490 | if (flags & DP_F_UP) |
512 | convert[place++] = | 491 | caps = 1; |
513 | (caps ? "0123456789ABCDEF" : "0123456789abcdef") | 492 | do { |
514 | [uvalue % (unsigned) base]; | 493 | convert[place++] = (caps ? "0123456789ABCDEF" : |
515 | uvalue = (uvalue / (unsigned) base); | 494 | "0123456789abcdef")[uvalue % (unsigned) base]; |
516 | } while (uvalue && (place < (int)sizeof(convert))); | 495 | uvalue = (uvalue / (unsigned) base); |
517 | if (place == sizeof(convert)) | 496 | } while (uvalue && (place < (int)sizeof(convert))); |
518 | place--; | 497 | if (place == sizeof(convert)) |
519 | convert[place] = 0; | 498 | place--; |
520 | 499 | convert[place] = 0; | |
521 | zpadlen = max - place; | 500 | |
522 | spadlen = min - OSSL_MAX(max, place) - (signvalue ? 1 : 0) - strlen(prefix); | 501 | zpadlen = max - place; |
523 | if (zpadlen < 0) | 502 | spadlen = min - OSSL_MAX(max, place) - (signvalue ? 1 : 0) - |
524 | zpadlen = 0; | 503 | strlen(prefix); |
525 | if (spadlen < 0) | 504 | if (zpadlen < 0) |
526 | spadlen = 0; | 505 | zpadlen = 0; |
527 | if (flags & DP_F_ZERO) { | 506 | if (spadlen < 0) |
528 | zpadlen = OSSL_MAX(zpadlen, spadlen); | 507 | spadlen = 0; |
529 | spadlen = 0; | 508 | if (flags & DP_F_ZERO) { |
530 | } | 509 | zpadlen = OSSL_MAX(zpadlen, spadlen); |
531 | if (flags & DP_F_MINUS) | 510 | spadlen = 0; |
532 | spadlen = -spadlen; | 511 | } |
533 | 512 | if (flags & DP_F_MINUS) | |
534 | /* spaces */ | 513 | spadlen = -spadlen; |
535 | while (spadlen > 0) { | 514 | |
536 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); | 515 | /* spaces */ |
537 | --spadlen; | 516 | while (spadlen > 0) { |
538 | } | 517 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); |
539 | 518 | --spadlen; | |
540 | /* sign */ | 519 | } |
541 | if (signvalue) | 520 | |
542 | doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue); | 521 | /* sign */ |
543 | 522 | if (signvalue) | |
544 | /* prefix */ | 523 | doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue); |
545 | while (*prefix) { | 524 | |
546 | doapr_outch(sbuffer, buffer, currlen, maxlen, *prefix); | 525 | /* prefix */ |
547 | prefix++; | 526 | while (*prefix) { |
548 | } | 527 | doapr_outch(sbuffer, buffer, currlen, maxlen, *prefix); |
549 | 528 | prefix++; | |
550 | /* zeros */ | 529 | } |
551 | if (zpadlen > 0) { | 530 | |
552 | while (zpadlen > 0) { | 531 | /* zeros */ |
553 | doapr_outch(sbuffer, buffer, currlen, maxlen, '0'); | 532 | if (zpadlen > 0) { |
554 | --zpadlen; | 533 | while (zpadlen > 0) { |
555 | } | 534 | doapr_outch(sbuffer, buffer, currlen, maxlen, '0'); |
556 | } | 535 | --zpadlen; |
557 | /* digits */ | 536 | } |
558 | while (place > 0) | 537 | } |
559 | doapr_outch(sbuffer, buffer, currlen, maxlen, convert[--place]); | 538 | /* digits */ |
560 | 539 | while (place > 0) | |
561 | /* left justified spaces */ | 540 | doapr_outch(sbuffer, buffer, currlen, maxlen, convert[--place]); |
562 | while (spadlen < 0) { | 541 | |
563 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); | 542 | /* left justified spaces */ |
564 | ++spadlen; | 543 | while (spadlen < 0) { |
565 | } | 544 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); |
566 | return; | 545 | ++spadlen; |
546 | } | ||
547 | return; | ||
567 | } | 548 | } |
568 | 549 | ||
569 | static LDOUBLE | 550 | static LDOUBLE |
570 | abs_val(LDOUBLE value) | 551 | abs_val(LDOUBLE value) |
571 | { | 552 | { |
572 | LDOUBLE result = value; | 553 | LDOUBLE result = value; |
573 | if (value < 0) | 554 | if (value < 0) |
574 | result = -value; | 555 | result = -value; |
575 | return result; | 556 | return result; |
576 | } | 557 | } |
577 | 558 | ||
578 | static LDOUBLE | 559 | static LDOUBLE |
579 | pow_10(int in_exp) | 560 | pow_10(int in_exp) |
580 | { | 561 | { |
581 | LDOUBLE result = 1; | 562 | LDOUBLE result = 1; |
582 | while (in_exp) { | 563 | while (in_exp) { |
583 | result *= 10; | 564 | result *= 10; |
584 | in_exp--; | 565 | in_exp--; |
585 | } | 566 | } |
586 | return result; | 567 | return result; |
587 | } | 568 | } |
588 | 569 | ||
589 | static long | 570 | static long |
590 | roundv(LDOUBLE value) | 571 | roundv(LDOUBLE value) |
591 | { | 572 | { |
592 | long intpart; | 573 | long intpart; |
593 | intpart = (long) value; | 574 | intpart = (long) value; |
594 | value = value - intpart; | 575 | value = value - intpart; |
595 | if (value >= 0.5) | 576 | if (value >= 0.5) |
596 | intpart++; | 577 | intpart++; |
597 | return intpart; | 578 | return intpart; |
598 | } | 579 | } |
599 | 580 | ||
600 | static void | 581 | static void |
601 | fmtfp( | 582 | fmtfp(char **sbuffer, char **buffer, size_t *currlen, size_t *maxlen, |
602 | char **sbuffer, | 583 | LDOUBLE fvalue, int min, int max, int flags) |
603 | char **buffer, | ||
604 | size_t *currlen, | ||
605 | size_t *maxlen, | ||
606 | LDOUBLE fvalue, | ||
607 | int min, | ||
608 | int max, | ||
609 | int flags) | ||
610 | { | 584 | { |
611 | int signvalue = 0; | 585 | int signvalue = 0; |
612 | LDOUBLE ufvalue; | 586 | LDOUBLE ufvalue; |
613 | char iconvert[20]; | 587 | char iconvert[20]; |
614 | char fconvert[20]; | 588 | char fconvert[20]; |
615 | int iplace = 0; | 589 | int iplace = 0; |
616 | int fplace = 0; | 590 | int fplace = 0; |
617 | int padlen = 0; | 591 | int padlen = 0; |
618 | int zpadlen = 0; | 592 | int zpadlen = 0; |
619 | int caps = 0; | 593 | int caps = 0; |
620 | long intpart; | 594 | long intpart; |
621 | long fracpart; | 595 | long fracpart; |
622 | long max10; | 596 | long max10; |
623 | 597 | ||
624 | if (max < 0) | 598 | if (max < 0) |
625 | max = 6; | 599 | max = 6; |
626 | ufvalue = abs_val(fvalue); | 600 | ufvalue = abs_val(fvalue); |
627 | if (fvalue < 0) | 601 | if (fvalue < 0) |
628 | signvalue = '-'; | 602 | signvalue = '-'; |
629 | else if (flags & DP_F_PLUS) | 603 | else if (flags & DP_F_PLUS) |
630 | signvalue = '+'; | 604 | signvalue = '+'; |
631 | else if (flags & DP_F_SPACE) | 605 | else if (flags & DP_F_SPACE) |
632 | signvalue = ' '; | 606 | signvalue = ' '; |
633 | 607 | ||
634 | intpart = (long)ufvalue; | 608 | intpart = (long)ufvalue; |
635 | 609 | ||
636 | /* sorry, we only support 9 digits past the decimal because of our | 610 | /* sorry, we only support 9 digits past the decimal because of our |
637 | conversion method */ | 611 | conversion method */ |
638 | if (max > 9) | 612 | if (max > 9) |
639 | max = 9; | 613 | max = 9; |
640 | 614 | ||
641 | /* we "cheat" by converting the fractional part to integer by | 615 | /* we "cheat" by converting the fractional part to integer by |
642 | multiplying by a factor of 10 */ | 616 | multiplying by a factor of 10 */ |
643 | max10 = roundv(pow_10(max)); | 617 | max10 = roundv(pow_10(max)); |
644 | fracpart = roundv(pow_10(max) * (ufvalue - intpart)); | 618 | fracpart = roundv(pow_10(max) * (ufvalue - intpart)); |
645 | 619 | ||
646 | if (fracpart >= max10) { | 620 | if (fracpart >= max10) { |
647 | intpart++; | 621 | intpart++; |
648 | fracpart -= max10; | 622 | fracpart -= max10; |
649 | } | 623 | } |
650 | 624 | ||
651 | /* convert integer part */ | 625 | /* convert integer part */ |
652 | do { | 626 | do { |
653 | iconvert[iplace++] = | 627 | iconvert[iplace++] = (caps ? "0123456789ABCDEF" : |
654 | (caps ? "0123456789ABCDEF" | 628 | "0123456789abcdef")[intpart % 10]; |
655 | : "0123456789abcdef")[intpart % 10]; | 629 | intpart = (intpart / 10); |
656 | intpart = (intpart / 10); | 630 | } while (intpart && (iplace < (int)sizeof(iconvert))); |
657 | } while (intpart && (iplace < (int)sizeof(iconvert))); | 631 | if (iplace == sizeof iconvert) |
658 | if (iplace == sizeof iconvert) | 632 | iplace--; |
659 | iplace--; | 633 | iconvert[iplace] = 0; |
660 | iconvert[iplace] = 0; | 634 | |
661 | 635 | /* convert fractional part */ | |
662 | /* convert fractional part */ | 636 | do { |
663 | do { | 637 | fconvert[fplace++] = (caps ? "0123456789ABCDEF" : |
664 | fconvert[fplace++] = | 638 | "0123456789abcdef")[fracpart % 10]; |
665 | (caps ? "0123456789ABCDEF" | 639 | fracpart = (fracpart / 10); |
666 | : "0123456789abcdef")[fracpart % 10]; | 640 | } while (fplace < max); |
667 | fracpart = (fracpart / 10); | 641 | if (fplace == sizeof fconvert) |
668 | } while (fplace < max); | 642 | fplace--; |
669 | if (fplace == sizeof fconvert) | 643 | fconvert[fplace] = 0; |
670 | fplace--; | 644 | |
671 | fconvert[fplace] = 0; | 645 | /* -1 for decimal point, another -1 if we are printing a sign */ |
672 | 646 | padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0); | |
673 | /* -1 for decimal point, another -1 if we are printing a sign */ | 647 | zpadlen = max - fplace; |
674 | padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0); | 648 | if (zpadlen < 0) |
675 | zpadlen = max - fplace; | 649 | zpadlen = 0; |
676 | if (zpadlen < 0) | 650 | if (padlen < 0) |
677 | zpadlen = 0; | 651 | padlen = 0; |
678 | if (padlen < 0) | 652 | if (flags & DP_F_MINUS) |
679 | padlen = 0; | 653 | padlen = -padlen; |
680 | if (flags & DP_F_MINUS) | 654 | |
681 | padlen = -padlen; | 655 | if ((flags & DP_F_ZERO) && (padlen > 0)) { |
682 | 656 | if (signvalue) { | |
683 | if ((flags & DP_F_ZERO) && (padlen > 0)) { | 657 | doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue); |
684 | if (signvalue) { | 658 | --padlen; |
685 | doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue); | 659 | signvalue = 0; |
686 | --padlen; | 660 | } |
687 | signvalue = 0; | 661 | while (padlen > 0) { |
688 | } | 662 | doapr_outch(sbuffer, buffer, currlen, maxlen, '0'); |
689 | while (padlen > 0) { | 663 | --padlen; |
690 | doapr_outch(sbuffer, buffer, currlen, maxlen, '0'); | 664 | } |
691 | --padlen; | 665 | } |
692 | } | 666 | while (padlen > 0) { |
693 | } | 667 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); |
694 | while (padlen > 0) { | 668 | --padlen; |
695 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); | 669 | } |
696 | --padlen; | 670 | if (signvalue) |
697 | } | 671 | doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue); |
698 | if (signvalue) | 672 | |
699 | doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue); | 673 | while (iplace > 0) |
700 | 674 | doapr_outch(sbuffer, buffer, currlen, maxlen, iconvert[--iplace]); | |
701 | while (iplace > 0) | 675 | |
702 | doapr_outch(sbuffer, buffer, currlen, maxlen, iconvert[--iplace]); | 676 | /* |
703 | 677 | * Decimal point. This should probably use locale to find the correct | |
704 | /* | 678 | * char to print out. |
705 | * Decimal point. This should probably use locale to find the correct | 679 | */ |
706 | * char to print out. | 680 | if (max > 0 || (flags & DP_F_NUM)) { |
707 | */ | 681 | doapr_outch(sbuffer, buffer, currlen, maxlen, '.'); |
708 | if (max > 0 || (flags & DP_F_NUM)) { | 682 | |
709 | doapr_outch(sbuffer, buffer, currlen, maxlen, '.'); | 683 | while (fplace > 0) |
710 | 684 | doapr_outch(sbuffer, buffer, currlen, maxlen, fconvert[--fplace]); | |
711 | while (fplace > 0) | 685 | } |
712 | doapr_outch(sbuffer, buffer, currlen, maxlen, fconvert[--fplace]); | 686 | while (zpadlen > 0) { |
713 | } | 687 | doapr_outch(sbuffer, buffer, currlen, maxlen, '0'); |
714 | while (zpadlen > 0) { | 688 | --zpadlen; |
715 | doapr_outch(sbuffer, buffer, currlen, maxlen, '0'); | 689 | } |
716 | --zpadlen; | 690 | |
717 | } | 691 | while (padlen < 0) { |
718 | 692 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); | |
719 | while (padlen < 0) { | 693 | ++padlen; |
720 | doapr_outch(sbuffer, buffer, currlen, maxlen, ' '); | 694 | } |
721 | ++padlen; | ||
722 | } | ||
723 | } | 695 | } |
724 | 696 | ||
725 | static void | 697 | static void |
726 | doapr_outch( | 698 | doapr_outch(char **sbuffer, char **buffer, size_t *currlen, size_t *maxlen, |
727 | char **sbuffer, | ||
728 | char **buffer, | ||
729 | size_t *currlen, | ||
730 | size_t *maxlen, | ||
731 | int c) | 699 | int c) |
732 | { | 700 | { |
733 | /* If we haven't at least one buffer, someone has doe a big booboo */ | 701 | /* If we haven't at least one buffer, someone has doe a big booboo */ |
734 | assert(*sbuffer != NULL || buffer != NULL); | 702 | assert(*sbuffer != NULL || buffer != NULL); |
735 | 703 | ||
736 | if (buffer) { | 704 | if (buffer) { |
737 | while (*currlen >= *maxlen) { | 705 | while (*currlen >= *maxlen) { |
738 | if (*buffer == NULL) { | 706 | if (*buffer == NULL) { |
739 | if (*maxlen == 0) | 707 | if (*maxlen == 0) |
740 | *maxlen = 1024; | 708 | *maxlen = 1024; |
741 | *buffer = OPENSSL_malloc(*maxlen); | 709 | *buffer = OPENSSL_malloc(*maxlen); |
742 | if (*currlen > 0) { | 710 | if (*currlen > 0) { |
743 | assert(*sbuffer != NULL); | 711 | assert(*sbuffer != NULL); |
744 | memcpy(*buffer, *sbuffer, *currlen); | 712 | memcpy(*buffer, *sbuffer, *currlen); |
713 | } | ||
714 | *sbuffer = NULL; | ||
715 | } else { | ||
716 | *maxlen += 1024; | ||
717 | *buffer = OPENSSL_realloc(*buffer, *maxlen); | ||
718 | } | ||
745 | } | 719 | } |
746 | *sbuffer = NULL; | 720 | /* What to do if *buffer is NULL? */ |
747 | } else { | 721 | assert(*sbuffer != NULL || *buffer != NULL); |
748 | *maxlen += 1024; | ||
749 | *buffer = OPENSSL_realloc(*buffer, *maxlen); | ||
750 | } | ||
751 | } | 722 | } |
752 | /* What to do if *buffer is NULL? */ | ||
753 | assert(*sbuffer != NULL || *buffer != NULL); | ||
754 | } | ||
755 | 723 | ||
756 | if (*currlen < *maxlen) { | 724 | if (*currlen < *maxlen) { |
757 | if (*sbuffer) | 725 | if (*sbuffer) |
758 | (*sbuffer)[(*currlen)++] = (char)c; | 726 | (*sbuffer)[(*currlen)++] = (char)c; |
759 | else | 727 | else |
760 | (*buffer)[(*currlen)++] = (char)c; | 728 | (*buffer)[(*currlen)++] = (char)c; |
761 | } | 729 | } |
762 | 730 | ||
763 | return; | 731 | return; |
764 | } | 732 | } |
765 | 733 | ||
766 | /***************************************************************************/ | 734 | /***************************************************************************/ |
767 | 735 | ||
768 | int BIO_printf (BIO *bio, const char *format, ...) | 736 | int BIO_printf (BIO *bio, const char *format, ...) |
769 | { | 737 | { |
770 | va_list args; | 738 | va_list args; |
771 | int ret; | 739 | int ret; |
772 | 740 | ||
@@ -775,15 +743,15 @@ int BIO_printf (BIO *bio, const char *format, ...) | |||
775 | ret = BIO_vprintf(bio, format, args); | 743 | ret = BIO_vprintf(bio, format, args); |
776 | 744 | ||
777 | va_end(args); | 745 | va_end(args); |
778 | return(ret); | 746 | return (ret); |
779 | } | 747 | } |
780 | 748 | ||
781 | int BIO_vprintf (BIO *bio, const char *format, va_list args) | 749 | int BIO_vprintf (BIO *bio, const char *format, va_list args) |
782 | { | 750 | { |
783 | int ret; | 751 | int ret; |
784 | size_t retlen; | 752 | size_t retlen; |
785 | char hugebuf[1024*2]; /* Was previously 10k, which is unreasonable | 753 | char hugebuf[1024*2]; /* Was previously 10k, which is unreasonable |
786 | in small-stack environments, like threads | 754 | in small - stack environments, like threads |
787 | or DOS programs. */ | 755 | or DOS programs. */ |
788 | char *hugebufp = hugebuf; | 756 | char *hugebufp = hugebuf; |
789 | size_t hugebufsize = sizeof(hugebuf); | 757 | size_t hugebufsize = sizeof(hugebuf); |
@@ -792,27 +760,25 @@ int BIO_vprintf (BIO *bio, const char *format, va_list args) | |||
792 | 760 | ||
793 | dynbuf = NULL; | 761 | dynbuf = NULL; |
794 | CRYPTO_push_info("doapr()"); | 762 | CRYPTO_push_info("doapr()"); |
795 | _dopr(&hugebufp, &dynbuf, &hugebufsize, | 763 | _dopr(&hugebufp, &dynbuf, &hugebufsize, &retlen, &ignored, |
796 | &retlen, &ignored, format, args); | 764 | format, args); |
797 | if (dynbuf) | 765 | if (dynbuf) { |
798 | { | 766 | ret = BIO_write(bio, dynbuf, (int)retlen); |
799 | ret=BIO_write(bio, dynbuf, (int)retlen); | ||
800 | OPENSSL_free(dynbuf); | 767 | OPENSSL_free(dynbuf); |
801 | } | 768 | } else { |
802 | else | 769 | ret = BIO_write(bio, hugebuf, (int)retlen); |
803 | { | ||
804 | ret=BIO_write(bio, hugebuf, (int)retlen); | ||
805 | } | ||
806 | CRYPTO_pop_info(); | ||
807 | return(ret); | ||
808 | } | 770 | } |
771 | CRYPTO_pop_info(); | ||
772 | return (ret); | ||
773 | } | ||
809 | 774 | ||
810 | /* As snprintf is not available everywhere, we provide our own implementation. | 775 | /* As snprintf is not available everywhere, we provide our own implementation. |
811 | * This function has nothing to do with BIOs, but it's closely related | 776 | * This function has nothing to do with BIOs, but it's closely related |
812 | * to BIO_printf, and we need *some* name prefix ... | 777 | * to BIO_printf, and we need *some* name prefix ... |
813 | * (XXX the function should be renamed, but to what?) */ | 778 | * (XXX the function should be renamed, but to what?) */ |
814 | int BIO_snprintf(char *buf, size_t n, const char *format, ...) | 779 | int |
815 | { | 780 | BIO_snprintf(char *buf, size_t n, const char *format, ...) |
781 | { | ||
816 | va_list args; | 782 | va_list args; |
817 | int ret; | 783 | int ret; |
818 | 784 | ||
@@ -821,11 +787,12 @@ int BIO_snprintf(char *buf, size_t n, const char *format, ...) | |||
821 | ret = BIO_vsnprintf(buf, n, format, args); | 787 | ret = BIO_vsnprintf(buf, n, format, args); |
822 | 788 | ||
823 | va_end(args); | 789 | va_end(args); |
824 | return(ret); | 790 | return (ret); |
825 | } | 791 | } |
826 | 792 | ||
827 | int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) | 793 | int |
828 | { | 794 | BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) |
795 | { | ||
829 | size_t retlen; | 796 | size_t retlen; |
830 | int truncated; | 797 | int truncated; |
831 | 798 | ||
@@ -839,4 +806,4 @@ int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) | |||
839 | return -1; | 806 | return -1; |
840 | else | 807 | else |
841 | return (retlen <= INT_MAX) ? (int)retlen : -1; | 808 | return (retlen <= INT_MAX) ? (int)retlen : -1; |
842 | } | 809 | } |
diff --git a/src/lib/libssl/src/crypto/bio/b_sock.c b/src/lib/libssl/src/crypto/bio/b_sock.c index bd43307456..d739452580 100644 --- a/src/lib/libssl/src/crypto/bio/b_sock.c +++ b/src/lib/libssl/src/crypto/bio/b_sock.c | |||
@@ -85,7 +85,7 @@ NETDB_DEFINE_CONTEXT | |||
85 | #endif | 85 | #endif |
86 | 86 | ||
87 | #if defined(OPENSSL_SYS_WINDOWS) || (defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)) | 87 | #if defined(OPENSSL_SYS_WINDOWS) || (defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)) |
88 | static int wsa_init_done=0; | 88 | static int wsa_init_done = 0; |
89 | #endif | 89 | #endif |
90 | 90 | ||
91 | /* | 91 | /* |
@@ -100,36 +100,36 @@ static int wsa_init_done=0; | |||
100 | #endif | 100 | #endif |
101 | 101 | ||
102 | #if 0 | 102 | #if 0 |
103 | static unsigned long BIO_ghbn_hits=0L; | 103 | static unsigned long BIO_ghbn_hits = 0L; |
104 | static unsigned long BIO_ghbn_miss=0L; | 104 | static unsigned long BIO_ghbn_miss = 0L; |
105 | 105 | ||
106 | #define GHBN_NUM 4 | 106 | #define GHBN_NUM 4 |
107 | static struct ghbn_cache_st | 107 | static struct ghbn_cache_st { |
108 | { | ||
109 | char name[129]; | 108 | char name[129]; |
110 | struct hostent *ent; | 109 | struct hostent *ent; |
111 | unsigned long order; | 110 | unsigned long order; |
112 | } ghbn_cache[GHBN_NUM]; | 111 | } ghbn_cache[GHBN_NUM]; |
113 | #endif | 112 | #endif |
114 | 113 | ||
115 | static int get_ip(const char *str,unsigned char *ip); | 114 | static int get_ip(const char *str, unsigned char *ip); |
116 | #if 0 | 115 | #if 0 |
117 | static void ghbn_free(struct hostent *a); | 116 | static void ghbn_free(struct hostent *a); |
118 | static struct hostent *ghbn_dup(struct hostent *a); | 117 | static struct hostent *ghbn_dup(struct hostent *a); |
119 | #endif | 118 | #endif |
120 | int BIO_get_host_ip(const char *str, unsigned char *ip) | 119 | |
121 | { | 120 | int |
121 | BIO_get_host_ip(const char *str, unsigned char *ip) | ||
122 | { | ||
122 | int i; | 123 | int i; |
123 | int err = 1; | 124 | int err = 1; |
124 | int locked = 0; | 125 | int locked = 0; |
125 | struct hostent *he; | 126 | struct hostent *he; |
126 | 127 | ||
127 | i=get_ip(str,ip); | 128 | i = get_ip(str, ip); |
128 | if (i < 0) | 129 | if (i < 0) { |
129 | { | 130 | BIOerr(BIO_F_BIO_GET_HOST_IP, BIO_R_INVALID_IP_ADDRESS); |
130 | BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_INVALID_IP_ADDRESS); | ||
131 | goto err; | 131 | goto err; |
132 | } | 132 | } |
133 | 133 | ||
134 | /* At this point, we have something that is most probably correct | 134 | /* At this point, we have something that is most probably correct |
135 | in some way, so let's init the socket. */ | 135 | in some way, so let's init the socket. */ |
@@ -138,172 +138,169 @@ int BIO_get_host_ip(const char *str, unsigned char *ip) | |||
138 | 138 | ||
139 | /* If the string actually contained an IP address, we need not do | 139 | /* If the string actually contained an IP address, we need not do |
140 | anything more */ | 140 | anything more */ |
141 | if (i > 0) return(1); | 141 | if (i > 0) |
142 | return (1); | ||
142 | 143 | ||
143 | /* do a gethostbyname */ | 144 | /* do a gethostbyname */ |
144 | CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); | 145 | CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); |
145 | locked = 1; | 146 | locked = 1; |
146 | he=BIO_gethostbyname(str); | 147 | he = BIO_gethostbyname(str); |
147 | if (he == NULL) | 148 | if (he == NULL) { |
148 | { | 149 | BIOerr(BIO_F_BIO_GET_HOST_IP, BIO_R_BAD_HOSTNAME_LOOKUP); |
149 | BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_BAD_HOSTNAME_LOOKUP); | ||
150 | goto err; | 150 | goto err; |
151 | } | 151 | } |
152 | 152 | ||
153 | /* cast to short because of win16 winsock definition */ | 153 | /* cast to short because of win16 winsock definition */ |
154 | if ((short)he->h_addrtype != AF_INET) | 154 | if ((short)he->h_addrtype != AF_INET) { |
155 | { | 155 | BIOerr(BIO_F_BIO_GET_HOST_IP, BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET); |
156 | BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET); | ||
157 | goto err; | 156 | goto err; |
158 | } | 157 | } |
159 | for (i=0; i<4; i++) | 158 | for (i = 0; i < 4; i++) |
160 | ip[i]=he->h_addr_list[0][i]; | 159 | ip[i] = he->h_addr_list[0][i]; |
161 | err = 0; | 160 | err = 0; |
162 | 161 | ||
163 | err: | 162 | err: |
164 | if (locked) | 163 | if (locked) |
165 | CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); | 164 | CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); |
166 | if (err) | 165 | if (err) { |
167 | { | 166 | ERR_add_error_data(2, "host=", str); |
168 | ERR_add_error_data(2,"host=",str); | ||
169 | return 0; | 167 | return 0; |
170 | } | 168 | } else |
171 | else | ||
172 | return 1; | 169 | return 1; |
173 | } | 170 | } |
174 | 171 | ||
175 | int BIO_get_port(const char *str, unsigned short *port_ptr) | 172 | int |
176 | { | 173 | BIO_get_port(const char *str, unsigned short *port_ptr) |
174 | { | ||
177 | int i; | 175 | int i; |
178 | struct servent *s; | 176 | struct servent *s; |
179 | 177 | ||
180 | if (str == NULL) | 178 | if (str == NULL) { |
181 | { | 179 | BIOerr(BIO_F_BIO_GET_PORT, BIO_R_NO_PORT_DEFINED); |
182 | BIOerr(BIO_F_BIO_GET_PORT,BIO_R_NO_PORT_DEFINED); | 180 | return (0); |
183 | return(0); | 181 | } |
184 | } | 182 | i = atoi(str); |
185 | i=atoi(str); | ||
186 | if (i != 0) | 183 | if (i != 0) |
187 | *port_ptr=(unsigned short)i; | 184 | *port_ptr = (unsigned short)i; |
188 | else | 185 | else { |
189 | { | ||
190 | CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME); | 186 | CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME); |
191 | /* Note: under VMS with SOCKETSHR, it seems like the first | 187 | /* Note: under VMS with SOCKETSHR, it seems like the first |
192 | * parameter is 'char *', instead of 'const char *' | 188 | * parameter is 'char *', instead of 'const char *' |
193 | */ | 189 | */ |
194 | #ifndef CONST_STRICT | 190 | #ifndef CONST_STRICT |
195 | s=getservbyname((char *)str,"tcp"); | 191 | s = getservbyname((char *)str, "tcp"); |
196 | #else | 192 | #else |
197 | s=getservbyname(str,"tcp"); | 193 | s = getservbyname(str, "tcp"); |
198 | #endif | 194 | #endif |
199 | if(s != NULL) | 195 | if (s != NULL) |
200 | *port_ptr=ntohs((unsigned short)s->s_port); | 196 | *port_ptr = ntohs((unsigned short)s->s_port); |
201 | CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME); | 197 | CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME); |
202 | if(s == NULL) | 198 | if (s == NULL) { |
203 | { | 199 | if (strcmp(str, "http") == 0) |
204 | if (strcmp(str,"http") == 0) | 200 | *port_ptr = 80; |
205 | *port_ptr=80; | 201 | else if (strcmp(str, "telnet") == 0) |
206 | else if (strcmp(str,"telnet") == 0) | 202 | *port_ptr = 23; |
207 | *port_ptr=23; | 203 | else if (strcmp(str, "socks") == 0) |
208 | else if (strcmp(str,"socks") == 0) | 204 | *port_ptr = 1080; |
209 | *port_ptr=1080; | 205 | else if (strcmp(str, "https") == 0) |
210 | else if (strcmp(str,"https") == 0) | 206 | *port_ptr = 443; |
211 | *port_ptr=443; | 207 | else if (strcmp(str, "ssl") == 0) |
212 | else if (strcmp(str,"ssl") == 0) | 208 | *port_ptr = 443; |
213 | *port_ptr=443; | 209 | else if (strcmp(str, "ftp") == 0) |
214 | else if (strcmp(str,"ftp") == 0) | 210 | *port_ptr = 21; |
215 | *port_ptr=21; | 211 | else if (strcmp(str, "gopher") == 0) |
216 | else if (strcmp(str,"gopher") == 0) | 212 | *port_ptr = 70; |
217 | *port_ptr=70; | ||
218 | #if 0 | 213 | #if 0 |
219 | else if (strcmp(str,"wais") == 0) | 214 | else if (strcmp(str, "wais") == 0) |
220 | *port_ptr=21; | 215 | *port_ptr = 21; |
221 | #endif | 216 | #endif |
222 | else | 217 | else { |
223 | { | 218 | SYSerr(SYS_F_GETSERVBYNAME, errno); |
224 | SYSerr(SYS_F_GETSERVBYNAME,errno); | 219 | ERR_add_error_data(3, "service = '", str, "'"); |
225 | ERR_add_error_data(3,"service='",str,"'"); | 220 | return (0); |
226 | return(0); | ||
227 | } | ||
228 | } | 221 | } |
229 | } | 222 | } |
230 | return(1); | ||
231 | } | 223 | } |
224 | return (1); | ||
225 | } | ||
232 | 226 | ||
233 | int BIO_sock_error(int sock) | 227 | int |
234 | { | 228 | BIO_sock_error(int sock) |
235 | int j,i; | 229 | { |
230 | int j, i; | ||
236 | int size; | 231 | int size; |
237 | 232 | ||
238 | #if defined(OPENSSL_SYS_BEOS_R5) | 233 | #if defined(OPENSSL_SYS_BEOS_R5) |
239 | return 0; | 234 | return 0; |
240 | #endif | 235 | #endif |
241 | 236 | ||
242 | size=sizeof(int); | 237 | size = sizeof(int); |
243 | /* Note: under Windows the third parameter is of type (char *) | 238 | /* Note: under Windows the third parameter is of type (char *) |
244 | * whereas under other systems it is (void *) if you don't have | 239 | * whereas under other systems it is (void *) if you don't have |
245 | * a cast it will choke the compiler: if you do have a cast then | 240 | * a cast it will choke the compiler: if you do have a cast then |
246 | * you can either go for (char *) or (void *). | 241 | * you can either go for (char *) or (void *). |
247 | */ | 242 | */ |
248 | i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(void *)&j,(void *)&size); | 243 | i = getsockopt(sock, SOL_SOCKET, SO_ERROR,(void *)&j,(void *)&size); |
249 | if (i < 0) | 244 | if (i < 0) |
250 | return(1); | 245 | return (1); |
251 | else | 246 | else |
252 | return(j); | 247 | return (j); |
253 | } | 248 | } |
254 | 249 | ||
255 | #if 0 | 250 | #if 0 |
256 | long BIO_ghbn_ctrl(int cmd, int iarg, char *parg) | 251 | long |
257 | { | 252 | BIO_ghbn_ctrl(int cmd, int iarg, char *parg) |
253 | { | ||
258 | int i; | 254 | int i; |
259 | char **p; | 255 | char **p; |
260 | 256 | ||
261 | switch (cmd) | 257 | switch (cmd) { |
262 | { | ||
263 | case BIO_GHBN_CTRL_HITS: | 258 | case BIO_GHBN_CTRL_HITS: |
264 | return(BIO_ghbn_hits); | 259 | return (BIO_ghbn_hits); |
265 | /* break; */ | 260 | /* break; */ |
266 | case BIO_GHBN_CTRL_MISSES: | 261 | case BIO_GHBN_CTRL_MISSES: |
267 | return(BIO_ghbn_miss); | 262 | return (BIO_ghbn_miss); |
268 | /* break; */ | 263 | /* break; */ |
269 | case BIO_GHBN_CTRL_CACHE_SIZE: | 264 | case BIO_GHBN_CTRL_CACHE_SIZE: |
270 | return(GHBN_NUM); | 265 | return (GHBN_NUM); |
271 | /* break; */ | 266 | /* break; */ |
272 | case BIO_GHBN_CTRL_GET_ENTRY: | 267 | case BIO_GHBN_CTRL_GET_ENTRY: |
273 | if ((iarg >= 0) && (iarg <GHBN_NUM) && | 268 | if ((iarg >= 0) && (iarg < GHBN_NUM) && |
274 | (ghbn_cache[iarg].order > 0)) | 269 | (ghbn_cache[iarg].order > 0)) { |
275 | { | 270 | p = (char **)parg; |
276 | p=(char **)parg; | 271 | if (p == NULL) |
277 | if (p == NULL) return(0); | 272 | return (0); |
278 | *p=ghbn_cache[iarg].name; | 273 | *p = ghbn_cache[iarg].name; |
279 | ghbn_cache[iarg].name[128]='\0'; | 274 | ghbn_cache[iarg].name[128] = '\0'; |
280 | return(1); | 275 | return (1); |
281 | } | 276 | } |
282 | return(0); | 277 | return (0); |
283 | /* break; */ | 278 | /* break; */ |
284 | case BIO_GHBN_CTRL_FLUSH: | 279 | case BIO_GHBN_CTRL_FLUSH: |
285 | for (i=0; i<GHBN_NUM; i++) | 280 | for (i = 0; i < GHBN_NUM; i++) |
286 | ghbn_cache[i].order=0; | 281 | ghbn_cache[i].order = 0; |
287 | break; | 282 | break; |
288 | default: | 283 | default: |
289 | return(0); | 284 | return (0); |
290 | } | ||
291 | return(1); | ||
292 | } | 285 | } |
286 | return (1); | ||
287 | } | ||
293 | #endif | 288 | #endif |
294 | 289 | ||
295 | #if 0 | 290 | #if 0 |
296 | static struct hostent *ghbn_dup(struct hostent *a) | 291 | static struct hostent |
297 | { | 292 | *ghbn_dup(struct hostent *a) |
293 | { | ||
298 | struct hostent *ret; | 294 | struct hostent *ret; |
299 | int i,j; | 295 | int i, j; |
300 | 296 | ||
301 | MemCheck_off(); | 297 | MemCheck_off(); |
302 | ret=(struct hostent *)OPENSSL_malloc(sizeof(struct hostent)); | 298 | ret = (struct hostent *)OPENSSL_malloc(sizeof(struct hostent)); |
303 | if (ret == NULL) return(NULL); | 299 | if (ret == NULL) |
304 | memset(ret,0,sizeof(struct hostent)); | 300 | return (NULL); |
301 | memset(ret, 0, sizeof(struct hostent)); | ||
305 | 302 | ||
306 | for (i=0; a->h_aliases[i] != NULL; i++) | 303 | for (i = 0; a->h_aliases[i] != NULL; i++) |
307 | ; | 304 | ; |
308 | i++; | 305 | i++; |
309 | ret->h_aliases = (char **)OPENSSL_malloc(i*sizeof(char *)); | 306 | ret->h_aliases = (char **)OPENSSL_malloc(i*sizeof(char *)); |
@@ -311,69 +308,66 @@ static struct hostent *ghbn_dup(struct hostent *a) | |||
311 | goto err; | 308 | goto err; |
312 | memset(ret->h_aliases, 0, i*sizeof(char *)); | 309 | memset(ret->h_aliases, 0, i*sizeof(char *)); |
313 | 310 | ||
314 | for (i=0; a->h_addr_list[i] != NULL; i++) | 311 | for (i = 0; a->h_addr_list[i] != NULL; i++) |
315 | ; | 312 | ; |
316 | i++; | 313 | i++; |
317 | ret->h_addr_list=(char **)OPENSSL_malloc(i*sizeof(char *)); | 314 | ret->h_addr_list = (char **)OPENSSL_malloc(i*sizeof(char *)); |
318 | if (ret->h_addr_list == NULL) | 315 | if (ret->h_addr_list == NULL) |
319 | goto err; | 316 | goto err; |
320 | memset(ret->h_addr_list, 0, i*sizeof(char *)); | 317 | memset(ret->h_addr_list, 0, i*sizeof(char *)); |
321 | 318 | ||
322 | j=strlen(a->h_name)+1; | 319 | j = strlen(a->h_name) + 1; |
323 | if ((ret->h_name=OPENSSL_malloc(j)) == NULL) goto err; | 320 | if ((ret->h_name = OPENSSL_malloc(j)) == NULL) goto err; |
324 | memcpy((char *)ret->h_name,a->h_name,j); | 321 | memcpy((char *)ret->h_name, a->h_name, j); |
325 | for (i=0; a->h_aliases[i] != NULL; i++) | 322 | for (i = 0; a->h_aliases[i] != NULL; i++) { |
326 | { | 323 | j = strlen(a->h_aliases[i]) + 1; |
327 | j=strlen(a->h_aliases[i])+1; | 324 | if ((ret->h_aliases[i] = OPENSSL_malloc(j)) == NULL) goto err; |
328 | if ((ret->h_aliases[i]=OPENSSL_malloc(j)) == NULL) goto err; | 325 | memcpy(ret->h_aliases[i], a->h_aliases[i], j); |
329 | memcpy(ret->h_aliases[i],a->h_aliases[i],j); | 326 | } |
330 | } | 327 | ret->h_length = a->h_length; |
331 | ret->h_length=a->h_length; | 328 | ret->h_addrtype = a->h_addrtype; |
332 | ret->h_addrtype=a->h_addrtype; | 329 | for (i = 0; a->h_addr_list[i] != NULL; i++) { |
333 | for (i=0; a->h_addr_list[i] != NULL; i++) | 330 | if ((ret->h_addr_list[i] = OPENSSL_malloc(a->h_length)) == NULL) |
334 | { | ||
335 | if ((ret->h_addr_list[i]=OPENSSL_malloc(a->h_length)) == NULL) | ||
336 | goto err; | 331 | goto err; |
337 | memcpy(ret->h_addr_list[i],a->h_addr_list[i],a->h_length); | 332 | memcpy(ret->h_addr_list[i], a->h_addr_list[i], a->h_length); |
338 | } | 333 | } |
339 | if (0) | 334 | if (0) { |
340 | { | 335 | err: |
341 | err: | ||
342 | if (ret != NULL) | 336 | if (ret != NULL) |
343 | ghbn_free(ret); | 337 | ghbn_free(ret); |
344 | ret=NULL; | 338 | ret = NULL; |
345 | } | ||
346 | MemCheck_on(); | ||
347 | return(ret); | ||
348 | } | 339 | } |
340 | MemCheck_on(); | ||
341 | return (ret); | ||
342 | } | ||
349 | 343 | ||
350 | static void ghbn_free(struct hostent *a) | 344 | static void |
351 | { | 345 | ghbn_free(struct hostent *a) |
346 | { | ||
352 | int i; | 347 | int i; |
353 | 348 | ||
354 | if(a == NULL) | 349 | if (a == NULL) |
355 | return; | 350 | return; |
356 | 351 | ||
357 | if (a->h_aliases != NULL) | 352 | if (a->h_aliases != NULL) { |
358 | { | 353 | for (i = 0; a->h_aliases[i] != NULL; i++) |
359 | for (i=0; a->h_aliases[i] != NULL; i++) | ||
360 | OPENSSL_free(a->h_aliases[i]); | 354 | OPENSSL_free(a->h_aliases[i]); |
361 | OPENSSL_free(a->h_aliases); | 355 | OPENSSL_free(a->h_aliases); |
362 | } | 356 | } |
363 | if (a->h_addr_list != NULL) | 357 | if (a->h_addr_list != NULL) { |
364 | { | 358 | for (i = 0; a->h_addr_list[i] != NULL; i++) |
365 | for (i=0; a->h_addr_list[i] != NULL; i++) | ||
366 | OPENSSL_free(a->h_addr_list[i]); | 359 | OPENSSL_free(a->h_addr_list[i]); |
367 | OPENSSL_free(a->h_addr_list); | 360 | OPENSSL_free(a->h_addr_list); |
368 | } | ||
369 | if (a->h_name != NULL) OPENSSL_free(a->h_name); | ||
370 | OPENSSL_free(a); | ||
371 | } | 361 | } |
362 | if (a->h_name != NULL) | ||
363 | OPENSSL_free(a->h_name); | ||
364 | OPENSSL_free(a); | ||
365 | } | ||
372 | 366 | ||
373 | #endif | 367 | #endif |
374 | 368 | ||
375 | struct hostent *BIO_gethostbyname(const char *name) | 369 | struct hostent |
376 | { | 370 | *BIO_gethostbyname(const char *name) { |
377 | #if 1 | 371 | #if 1 |
378 | /* Caching gethostbyname() results forever is wrong, | 372 | /* Caching gethostbyname() results forever is wrong, |
379 | * so we have to let the true gethostbyname() worry about this */ | 373 | * so we have to let the true gethostbyname() worry about this */ |
@@ -384,8 +378,8 @@ struct hostent *BIO_gethostbyname(const char *name) | |||
384 | #endif | 378 | #endif |
385 | #else | 379 | #else |
386 | struct hostent *ret; | 380 | struct hostent *ret; |
387 | int i,lowi=0,j; | 381 | int i, lowi = 0, j; |
388 | unsigned long low= (unsigned long)-1; | 382 | unsigned long low = (unsigned long) - 1; |
389 | 383 | ||
390 | 384 | ||
391 | # if 0 | 385 | # if 0 |
@@ -395,42 +389,37 @@ struct hostent *BIO_gethostbyname(const char *name) | |||
395 | */ | 389 | */ |
396 | CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); | 390 | CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); |
397 | # endif | 391 | # endif |
398 | j=strlen(name); | 392 | j = strlen(name); |
399 | if (j < 128) | 393 | if (j < 128) { |
400 | { | 394 | for (i = 0; i < GHBN_NUM; i++) { |
401 | for (i=0; i<GHBN_NUM; i++) | 395 | if (low > ghbn_cache[i].order) { |
402 | { | 396 | low = ghbn_cache[i].order; |
403 | if (low > ghbn_cache[i].order) | 397 | lowi = i; |
404 | { | 398 | } |
405 | low=ghbn_cache[i].order; | 399 | if (ghbn_cache[i].order > 0) { |
406 | lowi=i; | 400 | if (strncmp(name, ghbn_cache[i].name, 128) == 0) |
407 | } | ||
408 | if (ghbn_cache[i].order > 0) | ||
409 | { | ||
410 | if (strncmp(name,ghbn_cache[i].name,128) == 0) | ||
411 | break; | 401 | break; |
412 | } | ||
413 | } | 402 | } |
414 | } | 403 | } |
415 | else | 404 | } else |
416 | i=GHBN_NUM; | 405 | i = GHBN_NUM; |
417 | 406 | ||
418 | if (i == GHBN_NUM) /* no hit*/ | 407 | if (i == GHBN_NUM) /* no hit*/ |
419 | { | 408 | { |
420 | BIO_ghbn_miss++; | 409 | BIO_ghbn_miss++; |
421 | /* Note: under VMS with SOCKETSHR, it seems like the first | 410 | /* Note: under VMS with SOCKETSHR, it seems like the first |
422 | * parameter is 'char *', instead of 'const char *' | 411 | * parameter is 'char *', instead of 'const char *' |
423 | */ | 412 | */ |
424 | # ifndef CONST_STRICT | 413 | # ifndef CONST_STRICT |
425 | ret=gethostbyname((char *)name); | 414 | ret = gethostbyname((char *)name); |
426 | # else | 415 | # else |
427 | ret=gethostbyname(name); | 416 | ret = gethostbyname(name); |
428 | # endif | 417 | # endif |
429 | 418 | ||
430 | if (ret == NULL) | 419 | if (ret == NULL) |
431 | goto end; | 420 | goto end; |
432 | if (j > 128) /* too big to cache */ | 421 | if (j > 128) /* too big to cache */ |
433 | { | 422 | { |
434 | # if 0 | 423 | # if 0 |
435 | /* If we were trying to make this function thread-safe (which | 424 | /* If we were trying to make this function thread-safe (which |
436 | * is bound to fail), we'd have to give up in this case | 425 | * is bound to fail), we'd have to give up in this case |
@@ -438,118 +427,113 @@ struct hostent *BIO_gethostbyname(const char *name) | |||
438 | ret = NULL; | 427 | ret = NULL; |
439 | # endif | 428 | # endif |
440 | goto end; | 429 | goto end; |
441 | } | 430 | } |
442 | 431 | ||
443 | /* else add to cache */ | 432 | /* else add to cache */ |
444 | if (ghbn_cache[lowi].ent != NULL) | 433 | if (ghbn_cache[lowi].ent != NULL) |
445 | ghbn_free(ghbn_cache[lowi].ent); /* XXX not thread-safe */ | 434 | ghbn_free(ghbn_cache[lowi].ent); /* XXX not thread-safe */ |
446 | ghbn_cache[lowi].name[0] = '\0'; | 435 | ghbn_cache[lowi].name[0] = '\0'; |
447 | 436 | ||
448 | if((ret=ghbn_cache[lowi].ent=ghbn_dup(ret)) == NULL) | 437 | if ((ret = ghbn_cache[lowi].ent = ghbn_dup(ret)) == NULL) { |
449 | { | 438 | BIOerr(BIO_F_BIO_GETHOSTBYNAME, ERR_R_MALLOC_FAILURE); |
450 | BIOerr(BIO_F_BIO_GETHOSTBYNAME,ERR_R_MALLOC_FAILURE); | ||
451 | goto end; | 439 | goto end; |
452 | } | ||
453 | strncpy(ghbn_cache[lowi].name,name,128); | ||
454 | ghbn_cache[lowi].order=BIO_ghbn_miss+BIO_ghbn_hits; | ||
455 | } | 440 | } |
456 | else | 441 | strncpy(ghbn_cache[lowi].name, name, 128); |
457 | { | 442 | ghbn_cache[lowi].order = BIO_ghbn_miss + BIO_ghbn_hits; |
443 | } else { | ||
458 | BIO_ghbn_hits++; | 444 | BIO_ghbn_hits++; |
459 | ret= ghbn_cache[i].ent; | 445 | ret = ghbn_cache[i].ent; |
460 | ghbn_cache[i].order=BIO_ghbn_miss+BIO_ghbn_hits; | 446 | ghbn_cache[i].order = BIO_ghbn_miss + BIO_ghbn_hits; |
461 | } | 447 | } |
462 | end: | 448 | end: |
463 | # if 0 | 449 | # if 0 |
464 | CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); | 450 | CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); |
465 | # endif | 451 | # endif |
466 | return(ret); | 452 | return (ret); |
467 | #endif | 453 | #endif |
468 | } | 454 | } |
469 | 455 | ||
470 | 456 | ||
471 | int BIO_sock_init(void) | 457 | int |
472 | { | 458 | BIO_sock_init(void) |
459 | { | ||
473 | #ifdef OPENSSL_SYS_WINDOWS | 460 | #ifdef OPENSSL_SYS_WINDOWS |
474 | static struct WSAData wsa_state; | 461 | static struct WSAData wsa_state; |
475 | 462 | ||
476 | if (!wsa_init_done) | 463 | if (!wsa_init_done) { |
477 | { | ||
478 | int err; | 464 | int err; |
479 | 465 | ||
480 | wsa_init_done=1; | 466 | wsa_init_done = 1; |
481 | memset(&wsa_state,0,sizeof(wsa_state)); | 467 | memset(&wsa_state, 0, sizeof(wsa_state)); |
482 | /* Not making wsa_state available to the rest of the | 468 | /* Not making wsa_state available to the rest of the |
483 | * code is formally wrong. But the structures we use | 469 | * code is formally wrong. But the structures we use |
484 | * are [beleived to be] invariable among Winsock DLLs, | 470 | * are [beleived to be] invariable among Winsock DLLs, |
485 | * while API availability is [expected to be] probed | 471 | * while API availability is [expected to be] probed |
486 | * at run-time with DSO_global_lookup. */ | 472 | * at run-time with DSO_global_lookup. */ |
487 | if (WSAStartup(0x0202,&wsa_state)!=0) | 473 | if (WSAStartup(0x0202, &wsa_state) != 0) { |
488 | { | 474 | err = WSAGetLastError(); |
489 | err=WSAGetLastError(); | 475 | SYSerr(SYS_F_WSASTARTUP, err); |
490 | SYSerr(SYS_F_WSASTARTUP,err); | 476 | BIOerr(BIO_F_BIO_SOCK_INIT, BIO_R_WSASTARTUP); |
491 | BIOerr(BIO_F_BIO_SOCK_INIT,BIO_R_WSASTARTUP); | 477 | return (-1); |
492 | return(-1); | ||
493 | } | ||
494 | } | 478 | } |
479 | } | ||
495 | #endif /* OPENSSL_SYS_WINDOWS */ | 480 | #endif /* OPENSSL_SYS_WINDOWS */ |
496 | #ifdef WATT32 | 481 | #ifdef WATT32 |
497 | extern int _watt_do_exit; | 482 | extern int _watt_do_exit; |
498 | _watt_do_exit = 0; /* don't make sock_init() call exit() */ | 483 | _watt_do_exit = 0; |
484 | /* don't make sock_init() call exit() */ | ||
499 | if (sock_init()) | 485 | if (sock_init()) |
500 | return (-1); | 486 | return (-1); |
501 | #endif | 487 | #endif |
502 | 488 | ||
503 | #if defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK) | 489 | #if defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK) |
504 | WORD wVerReq; | 490 | WORD wVerReq; |
505 | WSADATA wsaData; | 491 | WSADATA wsaData; |
506 | int err; | 492 | int err; |
507 | 493 | ||
508 | if (!wsa_init_done) | 494 | if (!wsa_init_done) { |
509 | { | 495 | wsa_init_done = 1; |
510 | wsa_init_done=1; | 496 | wVerReq = MAKEWORD( 2, 0 ); |
511 | wVerReq = MAKEWORD( 2, 0 ); | 497 | err = WSAStartup(wVerReq, &wsaData); |
512 | err = WSAStartup(wVerReq,&wsaData); | 498 | if (err != 0) { |
513 | if (err != 0) | 499 | SYSerr(SYS_F_WSASTARTUP, err); |
514 | { | 500 | BIOerr(BIO_F_BIO_SOCK_INIT, BIO_R_WSASTARTUP); |
515 | SYSerr(SYS_F_WSASTARTUP,err); | 501 | return (-1); |
516 | BIOerr(BIO_F_BIO_SOCK_INIT,BIO_R_WSASTARTUP); | ||
517 | return(-1); | ||
518 | } | ||
519 | } | 502 | } |
503 | } | ||
520 | #endif | 504 | #endif |
521 | 505 | ||
522 | return(1); | 506 | return (1); |
523 | } | 507 | } |
524 | 508 | ||
525 | void BIO_sock_cleanup(void) | 509 | void |
526 | { | 510 | BIO_sock_cleanup(void) |
511 | { | ||
527 | #ifdef OPENSSL_SYS_WINDOWS | 512 | #ifdef OPENSSL_SYS_WINDOWS |
528 | if (wsa_init_done) | 513 | if (wsa_init_done) { |
529 | { | 514 | wsa_init_done = 0; |
530 | wsa_init_done=0; | ||
531 | #if 0 /* this call is claimed to be non-present in Winsock2 */ | 515 | #if 0 /* this call is claimed to be non-present in Winsock2 */ |
532 | WSACancelBlockingCall(); | 516 | WSACancelBlockingCall(); |
533 | #endif | 517 | #endif |
534 | WSACleanup(); | 518 | WSACleanup(); |
535 | } | 519 | } |
536 | #elif defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK) | 520 | #elif defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK) |
537 | if (wsa_init_done) | 521 | if (wsa_init_done) { |
538 | { | 522 | wsa_init_done = 0; |
539 | wsa_init_done=0; | 523 | WSACleanup(); |
540 | WSACleanup(); | ||
541 | } | ||
542 | #endif | ||
543 | } | 524 | } |
525 | #endif | ||
526 | } | ||
544 | 527 | ||
545 | #if !defined(OPENSSL_SYS_VMS) || __VMS_VER >= 70000000 | 528 | #if !defined(OPENSSL_SYS_VMS) || __VMS_VER >= 70000000 |
546 | 529 | ||
547 | int BIO_socket_ioctl(int fd, long type, void *arg) | 530 | int |
548 | { | 531 | BIO_socket_ioctl(int fd, long type, void *arg) |
532 | { | ||
549 | int i; | 533 | int i; |
550 | 534 | ||
551 | #ifdef __DJGPP__ | 535 | #ifdef __DJGPP__ |
552 | i=ioctl(fd,type,(char *)arg); | 536 | i = ioctl(fd, type,(char *)arg); |
553 | #else | 537 | #else |
554 | # if defined(OPENSSL_SYS_VMS) | 538 | # if defined(OPENSSL_SYS_VMS) |
555 | /* 2011-02-18 SMS. | 539 | /* 2011-02-18 SMS. |
@@ -574,402 +558,399 @@ int BIO_socket_ioctl(int fd, long type, void *arg) | |||
574 | # define ARG arg | 558 | # define ARG arg |
575 | # endif /* defined(OPENSSL_SYS_VMS) [else] */ | 559 | # endif /* defined(OPENSSL_SYS_VMS) [else] */ |
576 | 560 | ||
577 | i=ioctl(fd,type,ARG); | 561 | i = ioctl(fd, type, ARG); |
578 | #endif /* __DJGPP__ */ | 562 | #endif /* __DJGPP__ */ |
579 | if (i < 0) | 563 | if (i < 0) |
580 | SYSerr(SYS_F_IOCTLSOCKET,errno); | 564 | SYSerr(SYS_F_IOCTLSOCKET, errno); |
581 | return(i); | 565 | return (i); |
582 | } | 566 | } |
583 | #endif /* __VMS_VER */ | 567 | #endif /* __VMS_VER */ |
584 | 568 | ||
585 | /* The reason I have implemented this instead of using sscanf is because | 569 | /* The reason I have implemented this instead of using sscanf is because |
586 | * Visual C 1.52c gives an unresolved external when linking a DLL :-( */ | 570 | * Visual C 1.52c gives an unresolved external when linking a DLL :-( */ |
587 | static int get_ip(const char *str, unsigned char ip[4]) | 571 | static int |
588 | { | 572 | get_ip(const char *str, unsigned char ip[4]) |
573 | { | ||
589 | unsigned int tmp[4]; | 574 | unsigned int tmp[4]; |
590 | int num=0,c,ok=0; | 575 | int num = 0, c, ok = 0; |
591 | 576 | ||
592 | tmp[0]=tmp[1]=tmp[2]=tmp[3]=0; | 577 | tmp[0] = tmp[1] = tmp[2] = tmp[3] = 0; |
593 | 578 | ||
594 | for (;;) | 579 | for (;;) { |
595 | { | ||
596 | c= *(str++); | 580 | c= *(str++); |
597 | if ((c >= '0') && (c <= '9')) | 581 | if ((c >= '0') && (c <= '9')) { |
598 | { | 582 | ok = 1; |
599 | ok=1; | 583 | tmp[num] = tmp[num]*10 + c-'0'; |
600 | tmp[num]=tmp[num]*10+c-'0'; | 584 | if (tmp[num] > 255) |
601 | if (tmp[num] > 255) return(0); | 585 | return (0); |
602 | } | 586 | } else if (c == '.') { |
603 | else if (c == '.') | 587 | if (!ok) |
604 | { | 588 | return (-1); |
605 | if (!ok) return(-1); | 589 | if (num == 3) |
606 | if (num == 3) return(0); | 590 | return (0); |
607 | num++; | 591 | num++; |
608 | ok=0; | 592 | ok = 0; |
609 | } | 593 | } else if (c == '\0' && (num == 3) && ok) |
610 | else if (c == '\0' && (num == 3) && ok) | 594 | break; |
611 | break; | ||
612 | else | 595 | else |
613 | return(0); | 596 | return (0); |
614 | } | ||
615 | ip[0]=tmp[0]; | ||
616 | ip[1]=tmp[1]; | ||
617 | ip[2]=tmp[2]; | ||
618 | ip[3]=tmp[3]; | ||
619 | return(1); | ||
620 | } | 597 | } |
621 | 598 | ip[0] = tmp[0]; | |
622 | int BIO_get_accept_socket(char *host, int bind_mode) | 599 | ip[1] = tmp[1]; |
623 | { | 600 | ip[2] = tmp[2]; |
624 | int ret=0; | 601 | ip[3] = tmp[3]; |
602 | return (1); | ||
603 | } | ||
604 | |||
605 | int | ||
606 | BIO_get_accept_socket(char *host, int bind_mode) | ||
607 | { | ||
608 | int ret = 0; | ||
625 | union { | 609 | union { |
626 | struct sockaddr sa; | 610 | struct sockaddr sa; |
627 | struct sockaddr_in sa_in; | 611 | struct sockaddr_in sa_in; |
628 | #if OPENSSL_USE_IPV6 | 612 | #if OPENSSL_USE_IPV6 |
629 | struct sockaddr_in6 sa_in6; | 613 | struct sockaddr_in6 sa_in6; |
630 | #endif | 614 | #endif |
631 | } server,client; | 615 | } server, client; |
632 | int s=-1,cs,addrlen; | 616 | int s = -1, cs, addrlen; |
633 | unsigned char ip[4]; | 617 | unsigned char ip[4]; |
634 | unsigned short port; | 618 | unsigned short port; |
635 | char *str=NULL,*e; | 619 | char *str = NULL, *e; |
636 | char *h,*p; | 620 | char *h, *p; |
637 | unsigned long l; | 621 | unsigned long l; |
638 | int err_num; | 622 | int err_num; |
639 | 623 | ||
640 | if (BIO_sock_init() != 1) return(-1); | 624 | if (BIO_sock_init() != 1) |
625 | return (-1); | ||
641 | 626 | ||
642 | if ((str=BUF_strdup(host)) == NULL) return(-1); | 627 | if ((str = BUF_strdup(host)) == NULL) |
628 | return (-1); | ||
643 | 629 | ||
644 | h=p=NULL; | 630 | h = p = NULL; |
645 | h=str; | 631 | h = str; |
646 | for (e=str; *e; e++) | 632 | for (e = str; *e; e++) { |
647 | { | 633 | if (*e == ':') { |
648 | if (*e == ':') | 634 | p = e; |
649 | { | 635 | } else if (*e == '/') { |
650 | p=e; | 636 | *e = '\0'; |
651 | } | ||
652 | else if (*e == '/') | ||
653 | { | ||
654 | *e='\0'; | ||
655 | break; | 637 | break; |
656 | } | ||
657 | } | 638 | } |
658 | if (p) *p++='\0'; /* points at last ':', '::port' is special [see below] */ | 639 | } |
659 | else p=h,h=NULL; | 640 | if (p) |
641 | *p++='\0'; /* points at last ':', '::port' is special [see below] */ | ||
642 | else | ||
643 | p = h, h = NULL; | ||
660 | 644 | ||
661 | #ifdef EAI_FAMILY | 645 | #ifdef EAI_FAMILY |
662 | do { | 646 | do { |
663 | static union { void *p; | 647 | static union { |
664 | int (WSAAPI *f)(const char *,const char *, | 648 | void *p; |
665 | const struct addrinfo *, | 649 | int (WSAAPI *f)(const char *, const char *, |
666 | struct addrinfo **); | 650 | const struct addrinfo *, |
667 | } p_getaddrinfo = {NULL}; | 651 | struct addrinfo **); |
668 | static union { void *p; | 652 | } p_getaddrinfo = {NULL}; |
653 | static union { | ||
654 | void *p; | ||
669 | void (WSAAPI *f)(struct addrinfo *); | 655 | void (WSAAPI *f)(struct addrinfo *); |
670 | } p_freeaddrinfo = {NULL}; | 656 | } p_freeaddrinfo = {NULL}; |
671 | struct addrinfo *res,hint; | 657 | struct addrinfo *res, hint; |
672 | 658 | ||
673 | if (p_getaddrinfo.p==NULL) | 659 | if (p_getaddrinfo.p == NULL) { |
674 | { | 660 | if ((p_getaddrinfo.p = DSO_global_lookup("getaddrinfo"))==NULL || |
675 | if ((p_getaddrinfo.p=DSO_global_lookup("getaddrinfo"))==NULL || | 661 | (p_freeaddrinfo.p = DSO_global_lookup("freeaddrinfo"))==NULL) |
676 | (p_freeaddrinfo.p=DSO_global_lookup("freeaddrinfo"))==NULL) | 662 | p_getaddrinfo.p = (void*) - 1; |
677 | p_getaddrinfo.p=(void*)-1; | 663 | } |
678 | } | 664 | if (p_getaddrinfo.p == (void *) - 1) break; |
679 | if (p_getaddrinfo.p==(void *)-1) break; | 665 | |
680 | 666 | /* '::port' enforces IPv6 wildcard listener. Some OSes, | |
681 | /* '::port' enforces IPv6 wildcard listener. Some OSes, | 667 | * e.g. Solaris, default to IPv6 without any hint. Also |
682 | * e.g. Solaris, default to IPv6 without any hint. Also | 668 | * note that commonly IPv6 wildchard socket can service |
683 | * note that commonly IPv6 wildchard socket can service | 669 | * IPv4 connections just as well... */ |
684 | * IPv4 connections just as well... */ | 670 | memset(&hint, 0, sizeof(hint)); |
685 | memset(&hint,0,sizeof(hint)); | 671 | hint.ai_flags = AI_PASSIVE; |
686 | hint.ai_flags = AI_PASSIVE; | 672 | if (h) { |
687 | if (h) | 673 | if (strchr(h, ':')) { |
688 | { | 674 | if (h[1] == '\0') |
689 | if (strchr(h,':')) | 675 | h = NULL; |
690 | { | ||
691 | if (h[1]=='\0') h=NULL; | ||
692 | #if OPENSSL_USE_IPV6 | 676 | #if OPENSSL_USE_IPV6 |
693 | hint.ai_family = AF_INET6; | 677 | hint.ai_family = AF_INET6; |
694 | #else | 678 | #else |
695 | h=NULL; | 679 | h = NULL; |
696 | #endif | 680 | #endif |
697 | } | 681 | } else if (h[0] == '*' && h[1] == '\0') { |
698 | else if (h[0]=='*' && h[1]=='\0') | 682 | hint.ai_family = AF_INET; |
699 | { | 683 | h = NULL; |
700 | hint.ai_family = AF_INET; | ||
701 | h=NULL; | ||
702 | } | 684 | } |
703 | } | 685 | } |
704 | 686 | ||
705 | if ((*p_getaddrinfo.f)(h,p,&hint,&res)) break; | 687 | if ((*p_getaddrinfo.f)(h, p, &hint, &res)) |
688 | break; | ||
706 | 689 | ||
707 | addrlen = res->ai_addrlen<=sizeof(server) ? | 690 | addrlen = res->ai_addrlen <= sizeof(server) ? |
708 | res->ai_addrlen : | 691 | res->ai_addrlen : sizeof(server); |
709 | sizeof(server); | 692 | memcpy(&server, res->ai_addr, addrlen); |
710 | memcpy(&server, res->ai_addr, addrlen); | ||
711 | 693 | ||
712 | (*p_freeaddrinfo.f)(res); | 694 | (*p_freeaddrinfo.f)(res); |
713 | goto again; | 695 | goto again; |
714 | } while (0); | 696 | } while (0); |
715 | #endif | 697 | #endif |
716 | 698 | ||
717 | if (!BIO_get_port(p,&port)) goto err; | 699 | if (!BIO_get_port(p, &port)) |
700 | goto err; | ||
718 | 701 | ||
719 | memset((char *)&server,0,sizeof(server)); | 702 | memset((char *)&server, 0, sizeof(server)); |
720 | server.sa_in.sin_family=AF_INET; | 703 | server.sa_in.sin_family = AF_INET; |
721 | server.sa_in.sin_port=htons(port); | 704 | server.sa_in.sin_port = htons(port); |
722 | addrlen = sizeof(server.sa_in); | 705 | addrlen = sizeof(server.sa_in); |
723 | 706 | ||
724 | if (h == NULL || strcmp(h,"*") == 0) | 707 | if (h == NULL || strcmp(h, "*") == 0) |
725 | server.sa_in.sin_addr.s_addr=INADDR_ANY; | 708 | server.sa_in.sin_addr.s_addr = INADDR_ANY; |
726 | else | 709 | else { |
727 | { | 710 | if (!BIO_get_host_ip(h, &(ip[0]))) |
728 | if (!BIO_get_host_ip(h,&(ip[0]))) goto err; | 711 | goto err; |
729 | l=(unsigned long) | 712 | l = (unsigned long) |
730 | ((unsigned long)ip[0]<<24L)| | 713 | ((unsigned long)ip[0]<<24L)| |
731 | ((unsigned long)ip[1]<<16L)| | 714 | ((unsigned long)ip[1]<<16L)| |
732 | ((unsigned long)ip[2]<< 8L)| | 715 | ((unsigned long)ip[2]<< 8L)| |
733 | ((unsigned long)ip[3]); | 716 | ((unsigned long)ip[3]); |
734 | server.sa_in.sin_addr.s_addr=htonl(l); | 717 | server.sa_in.sin_addr.s_addr = htonl(l); |
735 | } | 718 | } |
736 | 719 | ||
737 | again: | 720 | again: |
738 | s=socket(server.sa.sa_family,SOCK_STREAM,SOCKET_PROTOCOL); | 721 | s = socket(server.sa.sa_family, SOCK_STREAM, SOCKET_PROTOCOL); |
739 | if (s == -1) | 722 | if (s == -1) { |
740 | { | 723 | SYSerr(SYS_F_SOCKET, errno); |
741 | SYSerr(SYS_F_SOCKET,errno); | 724 | ERR_add_error_data(3, "port = '", host, "'"); |
742 | ERR_add_error_data(3,"port='",host,"'"); | 725 | BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, BIO_R_UNABLE_TO_CREATE_SOCKET); |
743 | BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_CREATE_SOCKET); | ||
744 | goto err; | 726 | goto err; |
745 | } | 727 | } |
746 | 728 | ||
747 | #ifdef SO_REUSEADDR | 729 | #ifdef SO_REUSEADDR |
748 | if (bind_mode == BIO_BIND_REUSEADDR) | 730 | if (bind_mode == BIO_BIND_REUSEADDR) { |
749 | { | 731 | int i = 1; |
750 | int i=1; | ||
751 | 732 | ||
752 | ret=setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&i,sizeof(i)); | 733 | ret = setsockopt(s, SOL_SOCKET, SO_REUSEADDR,(char *)&i, sizeof(i)); |
753 | bind_mode=BIO_BIND_NORMAL; | 734 | bind_mode = BIO_BIND_NORMAL; |
754 | } | 735 | } |
755 | #endif | 736 | #endif |
756 | if (bind(s,&server.sa,addrlen) == -1) | 737 | if (bind(s, &server.sa, addrlen) == -1) { |
757 | { | ||
758 | #ifdef SO_REUSEADDR | 738 | #ifdef SO_REUSEADDR |
759 | err_num=errno; | 739 | err_num = errno; |
760 | if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) && | 740 | if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) && |
761 | #ifdef OPENSSL_SYS_WINDOWS | 741 | #ifdef OPENSSL_SYS_WINDOWS |
762 | /* Some versions of Windows define EADDRINUSE to | 742 | /* Some versions of Windows define EADDRINUSE to |
763 | * a dummy value. | 743 | * a dummy value. |
764 | */ | 744 | */ |
765 | (err_num == WSAEADDRINUSE)) | 745 | (err_num == WSAEADDRINUSE)) |
766 | #else | 746 | #else |
767 | (err_num == EADDRINUSE)) | 747 | (err_num == EADDRINUSE)) |
768 | #endif | 748 | #endif |
769 | { | 749 | { |
770 | client = server; | 750 | client = server; |
771 | if (h == NULL || strcmp(h,"*") == 0) | 751 | if (h == NULL || strcmp(h, "*") == 0) { |
772 | { | ||
773 | #if OPENSSL_USE_IPV6 | 752 | #if OPENSSL_USE_IPV6 |
774 | if (client.sa.sa_family == AF_INET6) | 753 | if (client.sa.sa_family == AF_INET6) { |
775 | { | 754 | memset(&client.sa_in6.sin6_addr, 0, sizeof(client.sa_in6.sin6_addr)); |
776 | memset(&client.sa_in6.sin6_addr,0,sizeof(client.sa_in6.sin6_addr)); | 755 | client.sa_in6.sin6_addr.s6_addr[15] = 1; |
777 | client.sa_in6.sin6_addr.s6_addr[15]=1; | 756 | } else |
778 | } | 757 | #endif |
779 | else | 758 | if (client.sa.sa_family == AF_INET) { |
780 | #endif | 759 | client.sa_in.sin_addr.s_addr = htonl(0x7F000001); |
781 | if (client.sa.sa_family == AF_INET) | 760 | } else |
782 | { | 761 | goto err; |
783 | client.sa_in.sin_addr.s_addr=htonl(0x7F000001); | 762 | } |
784 | } | 763 | cs = socket(client.sa.sa_family, SOCK_STREAM, SOCKET_PROTOCOL); |
785 | else goto err; | 764 | if (cs != -1) { |
786 | } | ||
787 | cs=socket(client.sa.sa_family,SOCK_STREAM,SOCKET_PROTOCOL); | ||
788 | if (cs != -1) | ||
789 | { | ||
790 | int ii; | 765 | int ii; |
791 | ii=connect(cs,&client.sa,addrlen); | 766 | ii = connect(cs, &client.sa, addrlen); |
792 | close(cs); | 767 | close(cs); |
793 | if (ii == -1) | 768 | if (ii == -1) { |
794 | { | 769 | bind_mode = BIO_BIND_REUSEADDR; |
795 | bind_mode=BIO_BIND_REUSEADDR; | ||
796 | close(s); | 770 | close(s); |
797 | goto again; | 771 | goto again; |
798 | } | ||
799 | /* else error */ | ||
800 | } | 772 | } |
801 | /* else error */ | 773 | /* else error */ |
802 | } | 774 | } |
775 | /* else error */ | ||
776 | } | ||
803 | #endif | 777 | #endif |
804 | SYSerr(SYS_F_BIND,err_num); | 778 | SYSerr(SYS_F_BIND, err_num); |
805 | ERR_add_error_data(3,"port='",host,"'"); | 779 | ERR_add_error_data(3, "port = '", host, "'"); |
806 | BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_BIND_SOCKET); | 780 | BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, BIO_R_UNABLE_TO_BIND_SOCKET); |
807 | goto err; | 781 | goto err; |
808 | } | 782 | } |
809 | if (listen(s,MAX_LISTEN) == -1) | 783 | if (listen(s, MAX_LISTEN) == -1) { |
810 | { | 784 | SYSerr(SYS_F_BIND, errno); |
811 | SYSerr(SYS_F_BIND,errno); | 785 | ERR_add_error_data(3, "port = '", host, "'"); |
812 | ERR_add_error_data(3,"port='",host,"'"); | 786 | BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, BIO_R_UNABLE_TO_LISTEN_SOCKET); |
813 | BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_LISTEN_SOCKET); | ||
814 | goto err; | 787 | goto err; |
815 | } | 788 | } |
816 | ret=1; | 789 | ret = 1; |
817 | err: | 790 | err: |
818 | if (str != NULL) OPENSSL_free(str); | 791 | if (str != NULL) |
819 | if ((ret == 0) && (s != -1)) | 792 | OPENSSL_free(str); |
820 | { | 793 | if ((ret == 0) && (s != -1)) { |
821 | close(s); | 794 | close(s); |
822 | s= -1; | 795 | s = -1; |
823 | } | ||
824 | return(s); | ||
825 | } | 796 | } |
797 | return (s); | ||
798 | } | ||
826 | 799 | ||
827 | int BIO_accept(int sock, char **addr) | 800 | int |
828 | { | 801 | BIO_accept(int sock, char **addr) |
829 | int ret=-1; | 802 | { |
803 | int ret = -1; | ||
830 | unsigned long l; | 804 | unsigned long l; |
831 | unsigned short port; | 805 | unsigned short port; |
832 | char *p; | 806 | char *p; |
833 | 807 | ||
834 | struct { | 808 | struct { |
835 | /* | 809 | /* |
836 | * As for following union. Trouble is that there are platforms | 810 | * As for following union. Trouble is that there are platforms |
837 | * that have socklen_t and there are platforms that don't, on | 811 | * that have socklen_t and there are platforms that don't, on |
838 | * some platforms socklen_t is int and on some size_t. So what | 812 | * some platforms socklen_t is int and on some size_t. So what |
839 | * one can do? One can cook #ifdef spaghetti, which is nothing | 813 | * one can do? One can cook #ifdef spaghetti, which is nothing |
840 | * but masochistic. Or one can do union between int and size_t. | 814 | * but masochistic. Or one can do union between int and size_t. |
841 | * One naturally does it primarily for 64-bit platforms where | 815 | * One naturally does it primarily for 64-bit platforms where |
842 | * sizeof(int) != sizeof(size_t). But would it work? Note that | 816 | * sizeof(int) != sizeof(size_t). But would it work? Note that |
843 | * if size_t member is initialized to 0, then later int member | 817 | * if size_t member is initialized to 0, then later int member |
844 | * assignment naturally does the job on little-endian platforms | 818 | * assignment naturally does the job on little-endian platforms |
845 | * regardless accept's expectations! What about big-endians? | 819 | * regardless accept's expectations! What about big-endians? |
846 | * If accept expects int*, then it works, and if size_t*, then | 820 | * If accept expects int*, then it works, and if size_t*, then |
847 | * length value would appear as unreasonably large. But this | 821 | * length value would appear as unreasonably large. But this |
848 | * won't prevent it from filling in the address structure. The | 822 | * won't prevent it from filling in the address structure. The |
849 | * trouble of course would be if accept returns more data than | 823 | * trouble of course would be if accept returns more data than |
850 | * actual buffer can accomodate and overwrite stack... That's | 824 | * actual buffer can accomodate and overwrite stack... That's |
851 | * where early OPENSSL_assert comes into picture. Besides, the | 825 | * where early OPENSSL_assert comes into picture. Besides, the |
852 | * only 64-bit big-endian platform found so far that expects | 826 | * only 64-bit big-endian platform found so far that expects |
853 | * size_t* is HP-UX, where stack grows towards higher address. | 827 | * size_t* is HP-UX, where stack grows towards higher address. |
854 | * <appro> | 828 | * <appro> |
855 | */ | 829 | */ |
856 | union { size_t s; int i; } len; | 830 | union { |
857 | union { | 831 | size_t s; |
858 | struct sockaddr sa; | 832 | int i; |
859 | struct sockaddr_in sa_in; | 833 | } len; |
834 | union { | ||
835 | struct sockaddr sa; | ||
836 | struct sockaddr_in sa_in; | ||
860 | #if OPENSSL_USE_IPV6 | 837 | #if OPENSSL_USE_IPV6 |
861 | struct sockaddr_in6 sa_in6; | 838 | struct sockaddr_in6 sa_in6; |
862 | #endif | 839 | #endif |
863 | } from; | 840 | } from; |
864 | } sa; | 841 | } sa; |
865 | 842 | ||
866 | sa.len.s=0; | 843 | sa.len.s = 0; |
867 | sa.len.i=sizeof(sa.from); | 844 | sa.len.i = sizeof(sa.from); |
868 | memset(&sa.from,0,sizeof(sa.from)); | 845 | memset(&sa.from, 0, sizeof(sa.from)); |
869 | ret=accept(sock,&sa.from.sa,(void *)&sa.len); | 846 | ret = accept(sock, &sa.from.sa,(void *)&sa.len); |
870 | if (sizeof(sa.len.i)!=sizeof(sa.len.s) && sa.len.i==0) | 847 | if (sizeof(sa.len.i) != sizeof(sa.len.s) && sa.len.i == 0) { |
871 | { | 848 | OPENSSL_assert(sa.len.s <= sizeof(sa.from)); |
872 | OPENSSL_assert(sa.len.s<=sizeof(sa.from)); | ||
873 | sa.len.i = (int)sa.len.s; | 849 | sa.len.i = (int)sa.len.s; |
874 | /* use sa.len.i from this point */ | 850 | /* use sa.len.i from this point */ |
875 | } | 851 | } |
876 | if (ret == -1) | 852 | if (ret == -1) { |
877 | { | 853 | if (BIO_sock_should_retry(ret)) return -2; |
878 | if(BIO_sock_should_retry(ret)) return -2; | 854 | SYSerr(SYS_F_ACCEPT, errno); |
879 | SYSerr(SYS_F_ACCEPT,errno); | 855 | BIOerr(BIO_F_BIO_ACCEPT, BIO_R_ACCEPT_ERROR); |
880 | BIOerr(BIO_F_BIO_ACCEPT,BIO_R_ACCEPT_ERROR); | ||
881 | goto end; | 856 | goto end; |
882 | } | 857 | } |
883 | 858 | ||
884 | if (addr == NULL) goto end; | 859 | if (addr == NULL) |
860 | goto end; | ||
885 | 861 | ||
886 | #ifdef EAI_FAMILY | 862 | #ifdef EAI_FAMILY |
887 | do { | 863 | do { |
888 | char h[NI_MAXHOST],s[NI_MAXSERV]; | 864 | char h[NI_MAXHOST], s[NI_MAXSERV]; |
889 | size_t nl; | 865 | size_t nl; |
890 | static union { void *p; | 866 | static union { |
891 | int (WSAAPI *f)(const struct sockaddr *,size_t/*socklen_t*/, | 867 | void *p; |
892 | char *,size_t,char *,size_t,int); | 868 | int (WSAAPI *f)(const struct sockaddr *, |
893 | } p_getnameinfo = {NULL}; | 869 | size_t/*socklen_t*/, char *, size_t, |
894 | /* 2nd argument to getnameinfo is specified to | 870 | char *, size_t, int); |
895 | * be socklen_t. Unfortunately there is a number | 871 | } p_getnameinfo = {NULL}; |
896 | * of environments where socklen_t is not defined. | 872 | /* 2nd argument to getnameinfo is specified to |
897 | * As it's passed by value, it's safe to pass it | 873 | * be socklen_t. Unfortunately there is a number |
898 | * as size_t... <appro> */ | 874 | * of environments where socklen_t is not defined. |
899 | 875 | * As it's passed by value, it's safe to pass it | |
900 | if (p_getnameinfo.p==NULL) | 876 | * as size_t... <appro> */ |
901 | { | 877 | |
902 | if ((p_getnameinfo.p=DSO_global_lookup("getnameinfo"))==NULL) | 878 | if (p_getnameinfo.p == NULL) { |
903 | p_getnameinfo.p=(void*)-1; | 879 | if ((p_getnameinfo.p = DSO_global_lookup("getnameinfo")) == NULL) |
880 | p_getnameinfo.p = (void*) - 1; | ||
881 | } | ||
882 | if (p_getnameinfo.p == (void *) - 1) | ||
883 | break; | ||
884 | |||
885 | if ((*p_getnameinfo.f)(&sa.from.sa, sa.len.i, h, sizeof(h), | ||
886 | s, sizeof(s), NI_NUMERICHOST|NI_NUMERICSERV)) | ||
887 | break; | ||
888 | nl = strlen(h) + strlen(s) + 2; | ||
889 | p = *addr; | ||
890 | if (p) { | ||
891 | *p = '\0'; | ||
892 | p = OPENSSL_realloc(p, nl); | ||
893 | } else { | ||
894 | p = OPENSSL_malloc(nl); | ||
895 | } | ||
896 | if (p == NULL) { | ||
897 | BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); | ||
898 | goto end; | ||
904 | } | 899 | } |
905 | if (p_getnameinfo.p==(void *)-1) break; | 900 | *addr = p; |
906 | 901 | (void) snprintf(*addr, nl, "%s:%s", h, s); | |
907 | if ((*p_getnameinfo.f)(&sa.from.sa,sa.len.i,h,sizeof(h),s,sizeof(s), | ||
908 | NI_NUMERICHOST|NI_NUMERICSERV)) break; | ||
909 | nl = strlen(h)+strlen(s)+2; | ||
910 | p = *addr; | ||
911 | if (p) { *p = '\0'; p = OPENSSL_realloc(p,nl); } | ||
912 | else { p = OPENSSL_malloc(nl); } | ||
913 | if (p==NULL) | ||
914 | { | ||
915 | BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE); | ||
916 | goto end; | 902 | goto end; |
917 | } | 903 | } while (0); |
918 | *addr = p; | 904 | #endif |
919 | (void) snprintf(*addr,nl,"%s:%s",h,s); | 905 | if (sa.from.sa.sa_family != AF_INET) |
920 | goto end; | 906 | goto end; |
921 | } while(0); | 907 | l = ntohl(sa.from.sa_in.sin_addr.s_addr); |
922 | #endif | 908 | port = ntohs(sa.from.sa_in.sin_port); |
923 | if (sa.from.sa.sa_family != AF_INET) goto end; | 909 | if (*addr == NULL) { |
924 | l=ntohl(sa.from.sa_in.sin_addr.s_addr); | 910 | if ((p = OPENSSL_malloc(24)) == NULL) { |
925 | port=ntohs(sa.from.sa_in.sin_port); | 911 | BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); |
926 | if (*addr == NULL) | ||
927 | { | ||
928 | if ((p=OPENSSL_malloc(24)) == NULL) | ||
929 | { | ||
930 | BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE); | ||
931 | goto end; | 912 | goto end; |
932 | } | ||
933 | *addr=p; | ||
934 | } | 913 | } |
935 | (void) snprintf(*addr,24,"%d.%d.%d.%d:%d", | 914 | *addr = p; |
936 | (unsigned char)(l>>24L)&0xff, | ||
937 | (unsigned char)(l>>16L)&0xff, | ||
938 | (unsigned char)(l>> 8L)&0xff, | ||
939 | (unsigned char)(l )&0xff, | ||
940 | port); | ||
941 | end: | ||
942 | return(ret); | ||
943 | } | 915 | } |
916 | (void) snprintf(*addr, 24, "%d.%d.%d.%d:%d", | ||
917 | (unsigned char)(l >> 24L) & 0xff, (unsigned char)(l >> 16L) & 0xff, | ||
918 | (unsigned char)(l >> 8L) & 0xff, (unsigned char)(l) & 0xff, port); | ||
944 | 919 | ||
945 | int BIO_set_tcp_ndelay(int s, int on) | 920 | end: |
946 | { | 921 | return (ret); |
947 | int ret=0; | 922 | } |
923 | |||
924 | int | ||
925 | BIO_set_tcp_ndelay(int s, int on) | ||
926 | { | ||
927 | int ret = 0; | ||
948 | #if defined(TCP_NODELAY) && (defined(IPPROTO_TCP) || defined(SOL_TCP)) | 928 | #if defined(TCP_NODELAY) && (defined(IPPROTO_TCP) || defined(SOL_TCP)) |
949 | int opt; | 929 | int opt; |
950 | 930 | ||
951 | #ifdef SOL_TCP | 931 | #ifdef SOL_TCP |
952 | opt=SOL_TCP; | 932 | opt = SOL_TCP; |
953 | #else | 933 | #else |
954 | #ifdef IPPROTO_TCP | 934 | #ifdef IPPROTO_TCP |
955 | opt=IPPROTO_TCP; | 935 | opt = IPPROTO_TCP; |
956 | #endif | 936 | #endif |
957 | #endif | 937 | #endif |
958 | 938 | ||
959 | ret=setsockopt(s,opt,TCP_NODELAY,(char *)&on,sizeof(on)); | 939 | ret = setsockopt(s, opt, TCP_NODELAY,(char *)&on, sizeof(on)); |
960 | #endif | 940 | #endif |
961 | return(ret == 0); | 941 | return (ret == 0); |
962 | } | 942 | } |
963 | 943 | ||
964 | int BIO_socket_nbio(int s, int mode) | 944 | int |
965 | { | 945 | BIO_socket_nbio(int s, int mode) |
966 | int ret= -1; | 946 | { |
947 | int ret = -1; | ||
967 | int l; | 948 | int l; |
968 | 949 | ||
969 | l=mode; | 950 | l = mode; |
970 | #ifdef FIONBIO | 951 | #ifdef FIONBIO |
971 | ret=BIO_socket_ioctl(s,FIONBIO,&l); | 952 | ret = BIO_socket_ioctl(s, FIONBIO, &l); |
972 | #endif | 953 | #endif |
973 | return(ret == 0); | 954 | return (ret == 0); |
974 | } | 955 | } |
975 | #endif | 956 | #endif |
diff --git a/src/lib/libssl/src/crypto/bio/bf_buff.c b/src/lib/libssl/src/crypto/bio/bf_buff.c index 4b5a132d8a..9518cf977e 100644 --- a/src/lib/libssl/src/crypto/bio/bf_buff.c +++ b/src/lib/libssl/src/crypto/bio/bf_buff.c | |||
@@ -61,7 +61,7 @@ | |||
61 | #include "cryptlib.h" | 61 | #include "cryptlib.h" |
62 | #include <openssl/bio.h> | 62 | #include <openssl/bio.h> |
63 | 63 | ||
64 | static int buffer_write(BIO *h, const char *buf,int num); | 64 | static int buffer_write(BIO *h, const char *buf, int num); |
65 | static int buffer_read(BIO *h, char *buf, int size); | 65 | static int buffer_read(BIO *h, char *buf, int size); |
66 | static int buffer_puts(BIO *h, const char *str); | 66 | static int buffer_puts(BIO *h, const char *str); |
67 | static int buffer_gets(BIO *h, char *str, int size); | 67 | static int buffer_gets(BIO *h, char *str, int size); |
@@ -71,8 +71,7 @@ static int buffer_free(BIO *data); | |||
71 | static long buffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); | 71 | static long buffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); |
72 | #define DEFAULT_BUFFER_SIZE 4096 | 72 | #define DEFAULT_BUFFER_SIZE 4096 |
73 | 73 | ||
74 | static BIO_METHOD methods_buffer= | 74 | static BIO_METHOD methods_buffer = { |
75 | { | ||
76 | BIO_TYPE_BUFFER, | 75 | BIO_TYPE_BUFFER, |
77 | "buffer", | 76 | "buffer", |
78 | buffer_write, | 77 | buffer_write, |
@@ -83,430 +82,444 @@ static BIO_METHOD methods_buffer= | |||
83 | buffer_new, | 82 | buffer_new, |
84 | buffer_free, | 83 | buffer_free, |
85 | buffer_callback_ctrl, | 84 | buffer_callback_ctrl, |
86 | }; | 85 | }; |
87 | 86 | ||
88 | BIO_METHOD *BIO_f_buffer(void) | 87 | BIO_METHOD |
89 | { | 88 | *BIO_f_buffer(void) |
90 | return(&methods_buffer); | 89 | { |
91 | } | 90 | return (&methods_buffer); |
91 | } | ||
92 | 92 | ||
93 | static int buffer_new(BIO *bi) | 93 | static int |
94 | { | 94 | buffer_new(BIO *bi) |
95 | { | ||
95 | BIO_F_BUFFER_CTX *ctx; | 96 | BIO_F_BUFFER_CTX *ctx; |
96 | 97 | ||
97 | ctx=(BIO_F_BUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_F_BUFFER_CTX)); | 98 | ctx = (BIO_F_BUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_F_BUFFER_CTX)); |
98 | if (ctx == NULL) return(0); | 99 | if (ctx == NULL) |
99 | ctx->ibuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE); | 100 | return (0); |
100 | if (ctx->ibuf == NULL) { OPENSSL_free(ctx); return(0); } | 101 | ctx->ibuf = (char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE); |
101 | ctx->obuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE); | 102 | if (ctx->ibuf == NULL) { |
102 | if (ctx->obuf == NULL) { OPENSSL_free(ctx->ibuf); OPENSSL_free(ctx); return(0); } | 103 | OPENSSL_free(ctx); |
103 | ctx->ibuf_size=DEFAULT_BUFFER_SIZE; | 104 | return (0); |
104 | ctx->obuf_size=DEFAULT_BUFFER_SIZE; | ||
105 | ctx->ibuf_len=0; | ||
106 | ctx->ibuf_off=0; | ||
107 | ctx->obuf_len=0; | ||
108 | ctx->obuf_off=0; | ||
109 | |||
110 | bi->init=1; | ||
111 | bi->ptr=(char *)ctx; | ||
112 | bi->flags=0; | ||
113 | return(1); | ||
114 | } | 105 | } |
115 | 106 | ctx->obuf = (char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE); | |
116 | static int buffer_free(BIO *a) | 107 | if (ctx->obuf == NULL) { |
117 | { | 108 | OPENSSL_free(ctx->ibuf); |
109 | OPENSSL_free(ctx); | ||
110 | return (0); | ||
111 | } | ||
112 | ctx->ibuf_size = DEFAULT_BUFFER_SIZE; | ||
113 | ctx->obuf_size = DEFAULT_BUFFER_SIZE; | ||
114 | ctx->ibuf_len = 0; | ||
115 | ctx->ibuf_off = 0; | ||
116 | ctx->obuf_len = 0; | ||
117 | ctx->obuf_off = 0; | ||
118 | |||
119 | bi->init = 1; | ||
120 | bi->ptr = (char *)ctx; | ||
121 | bi->flags = 0; | ||
122 | return (1); | ||
123 | } | ||
124 | |||
125 | static int | ||
126 | buffer_free(BIO *a) | ||
127 | { | ||
118 | BIO_F_BUFFER_CTX *b; | 128 | BIO_F_BUFFER_CTX *b; |
119 | 129 | ||
120 | if (a == NULL) return(0); | 130 | if (a == NULL) |
121 | b=(BIO_F_BUFFER_CTX *)a->ptr; | 131 | return (0); |
122 | if (b->ibuf != NULL) OPENSSL_free(b->ibuf); | 132 | b = (BIO_F_BUFFER_CTX *)a->ptr; |
123 | if (b->obuf != NULL) OPENSSL_free(b->obuf); | 133 | if (b->ibuf != NULL) |
134 | OPENSSL_free(b->ibuf); | ||
135 | if (b->obuf != NULL) | ||
136 | OPENSSL_free(b->obuf); | ||
124 | OPENSSL_free(a->ptr); | 137 | OPENSSL_free(a->ptr); |
125 | a->ptr=NULL; | 138 | a->ptr = NULL; |
126 | a->init=0; | 139 | a->init = 0; |
127 | a->flags=0; | 140 | a->flags = 0; |
128 | return(1); | 141 | return (1); |
129 | } | 142 | } |
130 | 143 | ||
131 | static int buffer_read(BIO *b, char *out, int outl) | 144 | static int |
132 | { | 145 | buffer_read(BIO *b, char *out, int outl) |
133 | int i,num=0; | 146 | { |
147 | int i, num = 0; | ||
134 | BIO_F_BUFFER_CTX *ctx; | 148 | BIO_F_BUFFER_CTX *ctx; |
135 | 149 | ||
136 | if (out == NULL) return(0); | 150 | if (out == NULL) |
137 | ctx=(BIO_F_BUFFER_CTX *)b->ptr; | 151 | return (0); |
152 | ctx = (BIO_F_BUFFER_CTX *)b->ptr; | ||
138 | 153 | ||
139 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | 154 | if ((ctx == NULL) || (b->next_bio == NULL)) |
140 | num=0; | 155 | return (0); |
156 | num = 0; | ||
141 | BIO_clear_retry_flags(b); | 157 | BIO_clear_retry_flags(b); |
142 | 158 | ||
143 | start: | 159 | start: |
144 | i=ctx->ibuf_len; | 160 | i = ctx->ibuf_len; |
145 | /* If there is stuff left over, grab it */ | 161 | /* If there is stuff left over, grab it */ |
146 | if (i != 0) | 162 | if (i != 0) { |
147 | { | 163 | if (i > outl) |
148 | if (i > outl) i=outl; | 164 | i = outl; |
149 | memcpy(out,&(ctx->ibuf[ctx->ibuf_off]),i); | 165 | memcpy(out, &(ctx->ibuf[ctx->ibuf_off]), i); |
150 | ctx->ibuf_off+=i; | 166 | ctx->ibuf_off += i; |
151 | ctx->ibuf_len-=i; | 167 | ctx->ibuf_len -= i; |
152 | num+=i; | 168 | num += i; |
153 | if (outl == i) return(num); | 169 | if (outl == i) |
154 | outl-=i; | 170 | return (num); |
155 | out+=i; | 171 | outl -= i; |
156 | } | 172 | out += i; |
173 | } | ||
157 | 174 | ||
158 | /* We may have done a partial read. try to do more. | 175 | /* We may have done a partial read. try to do more. |
159 | * We have nothing in the buffer. | 176 | * We have nothing in the buffer. |
160 | * If we get an error and have read some data, just return it | 177 | * If we get an error and have read some data, just return it |
161 | * and let them retry to get the error again. | 178 | * and let them retry to get the error again. |
162 | * copy direct to parent address space */ | 179 | * copy direct to parent address space */ |
163 | if (outl > ctx->ibuf_size) | 180 | if (outl > ctx->ibuf_size) { |
164 | { | 181 | for (;;) { |
165 | for (;;) | 182 | i = BIO_read(b->next_bio, out, outl); |
166 | { | 183 | if (i <= 0) { |
167 | i=BIO_read(b->next_bio,out,outl); | ||
168 | if (i <= 0) | ||
169 | { | ||
170 | BIO_copy_next_retry(b); | 184 | BIO_copy_next_retry(b); |
171 | if (i < 0) return((num > 0)?num:i); | 185 | if (i < 0) |
172 | if (i == 0) return(num); | 186 | return ((num > 0) ? num : i); |
173 | } | 187 | if (i == 0) |
174 | num+=i; | 188 | return (num); |
175 | if (outl == i) return(num); | ||
176 | out+=i; | ||
177 | outl-=i; | ||
178 | } | 189 | } |
190 | num += i; | ||
191 | if (outl == i) | ||
192 | return (num); | ||
193 | out += i; | ||
194 | outl -= i; | ||
179 | } | 195 | } |
196 | } | ||
180 | /* else */ | 197 | /* else */ |
181 | 198 | ||
182 | /* we are going to be doing some buffering */ | 199 | /* we are going to be doing some buffering */ |
183 | i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size); | 200 | i = BIO_read(b->next_bio, ctx->ibuf, ctx->ibuf_size); |
184 | if (i <= 0) | 201 | if (i <= 0) { |
185 | { | ||
186 | BIO_copy_next_retry(b); | 202 | BIO_copy_next_retry(b); |
187 | if (i < 0) return((num > 0)?num:i); | 203 | if (i < 0) |
188 | if (i == 0) return(num); | 204 | return ((num > 0) ? num : i); |
189 | } | 205 | if (i == 0) |
190 | ctx->ibuf_off=0; | 206 | return (num); |
191 | ctx->ibuf_len=i; | 207 | } |
208 | ctx->ibuf_off = 0; | ||
209 | ctx->ibuf_len = i; | ||
192 | 210 | ||
193 | /* Lets re-read using ourselves :-) */ | 211 | /* Lets re-read using ourselves :-) */ |
194 | goto start; | 212 | goto start; |
195 | } | 213 | } |
196 | 214 | ||
197 | static int buffer_write(BIO *b, const char *in, int inl) | 215 | static int |
198 | { | 216 | buffer_write(BIO *b, const char *in, int inl) |
199 | int i,num=0; | 217 | { |
218 | int i, num = 0; | ||
200 | BIO_F_BUFFER_CTX *ctx; | 219 | BIO_F_BUFFER_CTX *ctx; |
201 | 220 | ||
202 | if ((in == NULL) || (inl <= 0)) return(0); | 221 | if ((in == NULL) || (inl <= 0)) |
203 | ctx=(BIO_F_BUFFER_CTX *)b->ptr; | 222 | return (0); |
204 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | 223 | ctx = (BIO_F_BUFFER_CTX *)b->ptr; |
224 | if ((ctx == NULL) || (b->next_bio == NULL)) | ||
225 | return (0); | ||
205 | 226 | ||
206 | BIO_clear_retry_flags(b); | 227 | BIO_clear_retry_flags(b); |
207 | start: | 228 | start: |
208 | i=ctx->obuf_size-(ctx->obuf_len+ctx->obuf_off); | 229 | i = ctx->obuf_size - (ctx->obuf_len + ctx->obuf_off); |
209 | /* add to buffer and return */ | 230 | /* add to buffer and return */ |
210 | if (i >= inl) | 231 | if (i >= inl) { |
211 | { | 232 | memcpy(&(ctx->obuf[ctx->obuf_off + ctx->obuf_len]), in, inl); |
212 | memcpy(&(ctx->obuf[ctx->obuf_off+ctx->obuf_len]),in,inl); | 233 | ctx->obuf_len += inl; |
213 | ctx->obuf_len+=inl; | 234 | return (num + inl); |
214 | return(num+inl); | 235 | } |
215 | } | ||
216 | /* else */ | 236 | /* else */ |
217 | /* stuff already in buffer, so add to it first, then flush */ | 237 | /* stuff already in buffer, so add to it first, then flush */ |
218 | if (ctx->obuf_len != 0) | 238 | if (ctx->obuf_len != 0) { |
219 | { | ||
220 | if (i > 0) /* lets fill it up if we can */ | 239 | if (i > 0) /* lets fill it up if we can */ |
221 | { | 240 | { |
222 | memcpy(&(ctx->obuf[ctx->obuf_off+ctx->obuf_len]),in,i); | 241 | memcpy(&(ctx->obuf[ctx->obuf_off + ctx->obuf_len]), in, i); |
223 | in+=i; | 242 | in += i; |
224 | inl-=i; | 243 | inl -= i; |
225 | num+=i; | 244 | num += i; |
226 | ctx->obuf_len+=i; | 245 | ctx->obuf_len += i; |
227 | } | 246 | } |
228 | /* we now have a full buffer needing flushing */ | 247 | /* we now have a full buffer needing flushing */ |
229 | for (;;) | 248 | for (;;) { |
230 | { | 249 | i = BIO_write(b->next_bio, &(ctx->obuf[ctx->obuf_off]), |
231 | i=BIO_write(b->next_bio,&(ctx->obuf[ctx->obuf_off]), | 250 | ctx->obuf_len); |
232 | ctx->obuf_len); | 251 | if (i <= 0) { |
233 | if (i <= 0) | ||
234 | { | ||
235 | BIO_copy_next_retry(b); | 252 | BIO_copy_next_retry(b); |
236 | 253 | ||
237 | if (i < 0) return((num > 0)?num:i); | 254 | if (i < 0) |
238 | if (i == 0) return(num); | 255 | return ((num > 0) ? num : i); |
239 | } | 256 | if (i == 0) |
240 | ctx->obuf_off+=i; | 257 | return (num); |
241 | ctx->obuf_len-=i; | ||
242 | if (ctx->obuf_len == 0) break; | ||
243 | } | 258 | } |
259 | ctx->obuf_off += i; | ||
260 | ctx->obuf_len -= i; | ||
261 | if (ctx->obuf_len == 0) | ||
262 | break; | ||
244 | } | 263 | } |
264 | } | ||
245 | /* we only get here if the buffer has been flushed and we | 265 | /* we only get here if the buffer has been flushed and we |
246 | * still have stuff to write */ | 266 | * still have stuff to write */ |
247 | ctx->obuf_off=0; | 267 | ctx->obuf_off = 0; |
248 | 268 | ||
249 | /* we now have inl bytes to write */ | 269 | /* we now have inl bytes to write */ |
250 | while (inl >= ctx->obuf_size) | 270 | while (inl >= ctx->obuf_size) { |
251 | { | 271 | i = BIO_write(b->next_bio, in, inl); |
252 | i=BIO_write(b->next_bio,in,inl); | 272 | if (i <= 0) { |
253 | if (i <= 0) | ||
254 | { | ||
255 | BIO_copy_next_retry(b); | 273 | BIO_copy_next_retry(b); |
256 | if (i < 0) return((num > 0)?num:i); | 274 | if (i < 0) |
257 | if (i == 0) return(num); | 275 | return ((num > 0) ? num : i); |
258 | } | 276 | if (i == 0) |
259 | num+=i; | 277 | return (num); |
260 | in+=i; | ||
261 | inl-=i; | ||
262 | if (inl == 0) return(num); | ||
263 | } | 278 | } |
279 | num += i; | ||
280 | in += i; | ||
281 | inl -= i; | ||
282 | if (inl == 0) | ||
283 | return (num); | ||
284 | } | ||
264 | 285 | ||
265 | /* copy the rest into the buffer since we have only a small | 286 | /* copy the rest into the buffer since we have only a small |
266 | * amount left */ | 287 | * amount left */ |
267 | goto start; | 288 | goto start; |
268 | } | 289 | } |
269 | 290 | ||
270 | static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr) | 291 | static long |
271 | { | 292 | buffer_ctrl(BIO *b, int cmd, long num, void *ptr) |
293 | { | ||
272 | BIO *dbio; | 294 | BIO *dbio; |
273 | BIO_F_BUFFER_CTX *ctx; | 295 | BIO_F_BUFFER_CTX *ctx; |
274 | long ret=1; | 296 | long ret = 1; |
275 | char *p1,*p2; | 297 | char *p1, *p2; |
276 | int r,i,*ip; | 298 | int r, i, *ip; |
277 | int ibs,obs; | 299 | int ibs, obs; |
278 | 300 | ||
279 | ctx=(BIO_F_BUFFER_CTX *)b->ptr; | 301 | ctx = (BIO_F_BUFFER_CTX *)b->ptr; |
280 | 302 | ||
281 | switch (cmd) | 303 | switch (cmd) { |
282 | { | ||
283 | case BIO_CTRL_RESET: | 304 | case BIO_CTRL_RESET: |
284 | ctx->ibuf_off=0; | 305 | ctx->ibuf_off = 0; |
285 | ctx->ibuf_len=0; | 306 | ctx->ibuf_len = 0; |
286 | ctx->obuf_off=0; | 307 | ctx->obuf_off = 0; |
287 | ctx->obuf_len=0; | 308 | ctx->obuf_len = 0; |
288 | if (b->next_bio == NULL) return(0); | 309 | if (b->next_bio == NULL) |
289 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 310 | return (0); |
311 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
290 | break; | 312 | break; |
291 | case BIO_CTRL_INFO: | 313 | case BIO_CTRL_INFO: |
292 | ret=(long)ctx->obuf_len; | 314 | ret = (long)ctx->obuf_len; |
293 | break; | 315 | break; |
294 | case BIO_C_GET_BUFF_NUM_LINES: | 316 | case BIO_C_GET_BUFF_NUM_LINES: |
295 | ret=0; | 317 | ret = 0; |
296 | p1=ctx->ibuf; | 318 | p1 = ctx->ibuf; |
297 | for (i=0; i<ctx->ibuf_len; i++) | 319 | for (i = 0; i < ctx->ibuf_len; i++) { |
298 | { | 320 | if (p1[ctx->ibuf_off + i] == '\n') |
299 | if (p1[ctx->ibuf_off + i] == '\n') ret++; | 321 | ret++; |
300 | } | 322 | } |
301 | break; | 323 | break; |
302 | case BIO_CTRL_WPENDING: | 324 | case BIO_CTRL_WPENDING: |
303 | ret=(long)ctx->obuf_len; | 325 | ret = (long)ctx->obuf_len; |
304 | if (ret == 0) | 326 | if (ret == 0) { |
305 | { | 327 | if (b->next_bio == NULL) |
306 | if (b->next_bio == NULL) return(0); | 328 | return (0); |
307 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 329 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
308 | } | 330 | } |
309 | break; | 331 | break; |
310 | case BIO_CTRL_PENDING: | 332 | case BIO_CTRL_PENDING: |
311 | ret=(long)ctx->ibuf_len; | 333 | ret = (long)ctx->ibuf_len; |
312 | if (ret == 0) | 334 | if (ret == 0) { |
313 | { | 335 | if (b->next_bio == NULL) |
314 | if (b->next_bio == NULL) return(0); | 336 | return (0); |
315 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 337 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
316 | } | 338 | } |
317 | break; | 339 | break; |
318 | case BIO_C_SET_BUFF_READ_DATA: | 340 | case BIO_C_SET_BUFF_READ_DATA: |
319 | if (num > ctx->ibuf_size) | 341 | if (num > ctx->ibuf_size) { |
320 | { | 342 | p1 = OPENSSL_malloc((int)num); |
321 | p1=OPENSSL_malloc((int)num); | 343 | if (p1 == NULL) |
322 | if (p1 == NULL) goto malloc_error; | 344 | goto malloc_error; |
323 | if (ctx->ibuf != NULL) OPENSSL_free(ctx->ibuf); | 345 | if (ctx->ibuf != NULL) |
324 | ctx->ibuf=p1; | 346 | OPENSSL_free(ctx->ibuf); |
325 | } | 347 | ctx->ibuf = p1; |
326 | ctx->ibuf_off=0; | 348 | } |
327 | ctx->ibuf_len=(int)num; | 349 | ctx->ibuf_off = 0; |
328 | memcpy(ctx->ibuf,ptr,(int)num); | 350 | ctx->ibuf_len = (int)num; |
329 | ret=1; | 351 | memcpy(ctx->ibuf, ptr,(int)num); |
352 | ret = 1; | ||
330 | break; | 353 | break; |
331 | case BIO_C_SET_BUFF_SIZE: | 354 | case BIO_C_SET_BUFF_SIZE: |
332 | if (ptr != NULL) | 355 | if (ptr != NULL) { |
333 | { | 356 | ip = (int *)ptr; |
334 | ip=(int *)ptr; | 357 | if (*ip == 0) { |
335 | if (*ip == 0) | 358 | ibs = (int)num; |
336 | { | 359 | obs = ctx->obuf_size; |
337 | ibs=(int)num; | ||
338 | obs=ctx->obuf_size; | ||
339 | } | ||
340 | else /* if (*ip == 1) */ | ||
341 | { | ||
342 | ibs=ctx->ibuf_size; | ||
343 | obs=(int)num; | ||
344 | } | ||
345 | } | ||
346 | else | ||
347 | { | ||
348 | ibs=(int)num; | ||
349 | obs=(int)num; | ||
350 | } | 360 | } |
351 | p1=ctx->ibuf; | 361 | else /* if (*ip == 1) */ |
352 | p2=ctx->obuf; | ||
353 | if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size)) | ||
354 | { | 362 | { |
355 | p1=(char *)OPENSSL_malloc((int)num); | 363 | ibs = ctx->ibuf_size; |
356 | if (p1 == NULL) goto malloc_error; | 364 | obs = (int)num; |
357 | } | 365 | } |
358 | if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size)) | 366 | } else { |
359 | { | 367 | ibs = (int)num; |
360 | p2=(char *)OPENSSL_malloc((int)num); | 368 | obs = (int)num; |
361 | if (p2 == NULL) | 369 | } |
362 | { | 370 | p1 = ctx->ibuf; |
363 | if (p1 != ctx->ibuf) OPENSSL_free(p1); | 371 | p2 = ctx->obuf; |
372 | if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size)) { | ||
373 | p1 = (char *)OPENSSL_malloc((int)num); | ||
374 | if (p1 == NULL) | ||
375 | goto malloc_error; | ||
376 | } | ||
377 | if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size)) { | ||
378 | p2 = (char *)OPENSSL_malloc((int)num); | ||
379 | if (p2 == NULL) { | ||
380 | if (p1 != ctx->ibuf) | ||
381 | OPENSSL_free(p1); | ||
364 | goto malloc_error; | 382 | goto malloc_error; |
365 | } | ||
366 | } | 383 | } |
367 | if (ctx->ibuf != p1) | 384 | } |
368 | { | 385 | if (ctx->ibuf != p1) { |
369 | OPENSSL_free(ctx->ibuf); | 386 | OPENSSL_free(ctx->ibuf); |
370 | ctx->ibuf=p1; | 387 | ctx->ibuf = p1; |
371 | ctx->ibuf_off=0; | 388 | ctx->ibuf_off = 0; |
372 | ctx->ibuf_len=0; | 389 | ctx->ibuf_len = 0; |
373 | ctx->ibuf_size=ibs; | 390 | ctx->ibuf_size = ibs; |
374 | } | 391 | } |
375 | if (ctx->obuf != p2) | 392 | if (ctx->obuf != p2) { |
376 | { | ||
377 | OPENSSL_free(ctx->obuf); | 393 | OPENSSL_free(ctx->obuf); |
378 | ctx->obuf=p2; | 394 | ctx->obuf = p2; |
379 | ctx->obuf_off=0; | 395 | ctx->obuf_off = 0; |
380 | ctx->obuf_len=0; | 396 | ctx->obuf_len = 0; |
381 | ctx->obuf_size=obs; | 397 | ctx->obuf_size = obs; |
382 | } | 398 | } |
383 | break; | 399 | break; |
384 | case BIO_C_DO_STATE_MACHINE: | 400 | case BIO_C_DO_STATE_MACHINE: |
385 | if (b->next_bio == NULL) return(0); | 401 | if (b->next_bio == NULL) |
402 | return (0); | ||
386 | BIO_clear_retry_flags(b); | 403 | BIO_clear_retry_flags(b); |
387 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 404 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
388 | BIO_copy_next_retry(b); | 405 | BIO_copy_next_retry(b); |
389 | break; | 406 | break; |
390 | 407 | ||
391 | case BIO_CTRL_FLUSH: | 408 | case BIO_CTRL_FLUSH: |
392 | if (b->next_bio == NULL) return(0); | 409 | if (b->next_bio == NULL) |
393 | if (ctx->obuf_len <= 0) | 410 | return (0); |
394 | { | 411 | if (ctx->obuf_len <= 0) { |
395 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 412 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
396 | break; | 413 | break; |
397 | } | 414 | } |
398 | 415 | ||
399 | for (;;) | 416 | for (;;) { |
400 | { | ||
401 | BIO_clear_retry_flags(b); | 417 | BIO_clear_retry_flags(b); |
402 | if (ctx->obuf_len > 0) | 418 | if (ctx->obuf_len > 0) { |
403 | { | 419 | r = BIO_write(b->next_bio, |
404 | r=BIO_write(b->next_bio, | 420 | &(ctx->obuf[ctx->obuf_off]), |
405 | &(ctx->obuf[ctx->obuf_off]), | 421 | ctx->obuf_len); |
406 | ctx->obuf_len); | ||
407 | #if 0 | 422 | #if 0 |
408 | fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len,r); | 423 | fprintf(stderr, "FLUSH [%3d] %3d -> %3d\n", ctx->obuf_off, ctx->obuf_len, r); |
409 | #endif | 424 | #endif |
410 | BIO_copy_next_retry(b); | 425 | BIO_copy_next_retry(b); |
411 | if (r <= 0) return((long)r); | 426 | if (r <= 0) |
412 | ctx->obuf_off+=r; | 427 | return ((long)r); |
413 | ctx->obuf_len-=r; | 428 | ctx->obuf_off += r; |
414 | } | 429 | ctx->obuf_len -= r; |
415 | else | 430 | } else { |
416 | { | 431 | ctx->obuf_len = 0; |
417 | ctx->obuf_len=0; | 432 | ctx->obuf_off = 0; |
418 | ctx->obuf_off=0; | 433 | ret = 1; |
419 | ret=1; | ||
420 | break; | 434 | break; |
421 | } | ||
422 | } | 435 | } |
423 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 436 | } |
437 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
424 | break; | 438 | break; |
425 | case BIO_CTRL_DUP: | 439 | case BIO_CTRL_DUP: |
426 | dbio=(BIO *)ptr; | 440 | dbio = (BIO *)ptr; |
427 | if ( !BIO_set_read_buffer_size(dbio,ctx->ibuf_size) || | 441 | if (!BIO_set_read_buffer_size(dbio, ctx->ibuf_size) || |
428 | !BIO_set_write_buffer_size(dbio,ctx->obuf_size)) | 442 | !BIO_set_write_buffer_size(dbio, ctx->obuf_size)) |
429 | ret=0; | 443 | ret = 0; |
430 | break; | 444 | break; |
431 | default: | 445 | default: |
432 | if (b->next_bio == NULL) return(0); | 446 | if (b->next_bio == NULL) |
433 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 447 | return (0); |
448 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
434 | break; | 449 | break; |
435 | } | ||
436 | return(ret); | ||
437 | malloc_error: | ||
438 | BIOerr(BIO_F_BUFFER_CTRL,ERR_R_MALLOC_FAILURE); | ||
439 | return(0); | ||
440 | } | 450 | } |
441 | 451 | return (ret); | |
442 | static long buffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | 452 | malloc_error: |
443 | { | 453 | BIOerr(BIO_F_BUFFER_CTRL, ERR_R_MALLOC_FAILURE); |
444 | long ret=1; | 454 | return (0); |
445 | 455 | } | |
446 | if (b->next_bio == NULL) return(0); | 456 | |
447 | switch (cmd) | 457 | static long |
448 | { | 458 | buffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) |
459 | { | ||
460 | long ret = 1; | ||
461 | |||
462 | if (b->next_bio == NULL) | ||
463 | return (0); | ||
464 | switch (cmd) { | ||
449 | default: | 465 | default: |
450 | ret=BIO_callback_ctrl(b->next_bio,cmd,fp); | 466 | ret = BIO_callback_ctrl(b->next_bio, cmd, fp); |
451 | break; | 467 | break; |
452 | } | ||
453 | return(ret); | ||
454 | } | 468 | } |
469 | return (ret); | ||
470 | } | ||
455 | 471 | ||
456 | static int buffer_gets(BIO *b, char *buf, int size) | 472 | static int |
457 | { | 473 | buffer_gets(BIO *b, char *buf, int size) |
474 | { | ||
458 | BIO_F_BUFFER_CTX *ctx; | 475 | BIO_F_BUFFER_CTX *ctx; |
459 | int num=0,i,flag; | 476 | int num = 0, i, flag; |
460 | char *p; | 477 | char *p; |
461 | 478 | ||
462 | ctx=(BIO_F_BUFFER_CTX *)b->ptr; | 479 | ctx = (BIO_F_BUFFER_CTX *)b->ptr; |
463 | size--; /* reserve space for a '\0' */ | 480 | size--; /* reserve space for a '\0' */ |
464 | BIO_clear_retry_flags(b); | 481 | BIO_clear_retry_flags(b); |
465 | 482 | ||
466 | for (;;) | 483 | for (;;) { |
467 | { | 484 | if (ctx->ibuf_len > 0) { |
468 | if (ctx->ibuf_len > 0) | 485 | p = &(ctx->ibuf[ctx->ibuf_off]); |
469 | { | 486 | flag = 0; |
470 | p= &(ctx->ibuf[ctx->ibuf_off]); | 487 | for (i = 0; (i < ctx->ibuf_len) && (i < size); i++) { |
471 | flag=0; | 488 | *(buf++) = p[i]; |
472 | for (i=0; (i<ctx->ibuf_len) && (i<size); i++) | 489 | if (p[i] == '\n') { |
473 | { | 490 | flag = 1; |
474 | *(buf++)=p[i]; | ||
475 | if (p[i] == '\n') | ||
476 | { | ||
477 | flag=1; | ||
478 | i++; | 491 | i++; |
479 | break; | 492 | break; |
480 | } | ||
481 | } | ||
482 | num+=i; | ||
483 | size-=i; | ||
484 | ctx->ibuf_len-=i; | ||
485 | ctx->ibuf_off+=i; | ||
486 | if (flag || size == 0) | ||
487 | { | ||
488 | *buf='\0'; | ||
489 | return(num); | ||
490 | } | 493 | } |
491 | } | 494 | } |
495 | num += i; | ||
496 | size -= i; | ||
497 | ctx->ibuf_len -= i; | ||
498 | ctx->ibuf_off += i; | ||
499 | if (flag || size == 0) { | ||
500 | *buf = '\0'; | ||
501 | return (num); | ||
502 | } | ||
503 | } | ||
492 | else /* read another chunk */ | 504 | else /* read another chunk */ |
493 | { | 505 | { |
494 | i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size); | 506 | i = BIO_read(b->next_bio, ctx->ibuf, ctx->ibuf_size); |
495 | if (i <= 0) | 507 | if (i <= 0) { |
496 | { | ||
497 | BIO_copy_next_retry(b); | 508 | BIO_copy_next_retry(b); |
498 | *buf='\0'; | 509 | *buf = '\0'; |
499 | if (i < 0) return((num > 0)?num:i); | 510 | if (i < 0) |
500 | if (i == 0) return(num); | 511 | return ((num > 0) ? num : i); |
501 | } | 512 | if (i == 0) |
502 | ctx->ibuf_len=i; | 513 | return (num); |
503 | ctx->ibuf_off=0; | ||
504 | } | 514 | } |
515 | ctx->ibuf_len = i; | ||
516 | ctx->ibuf_off = 0; | ||
505 | } | 517 | } |
506 | } | 518 | } |
519 | } | ||
507 | 520 | ||
508 | static int buffer_puts(BIO *b, const char *str) | 521 | static int |
509 | { | 522 | buffer_puts(BIO *b, const char *str) |
510 | return(buffer_write(b,str,strlen(str))); | 523 | { |
511 | } | 524 | return (buffer_write(b, str, strlen(str))); |
512 | 525 | } | |
diff --git a/src/lib/libssl/src/crypto/bio/bf_lbuf.c b/src/lib/libssl/src/crypto/bio/bf_lbuf.c index ec0f7eb0b7..838839f1bf 100644 --- a/src/lib/libssl/src/crypto/bio/bf_lbuf.c +++ b/src/lib/libssl/src/crypto/bio/bf_lbuf.c | |||
@@ -62,7 +62,7 @@ | |||
62 | #include <openssl/bio.h> | 62 | #include <openssl/bio.h> |
63 | #include <openssl/evp.h> | 63 | #include <openssl/evp.h> |
64 | 64 | ||
65 | static int linebuffer_write(BIO *h, const char *buf,int num); | 65 | static int linebuffer_write(BIO *h, const char *buf, int num); |
66 | static int linebuffer_read(BIO *h, char *buf, int size); | 66 | static int linebuffer_read(BIO *h, char *buf, int size); |
67 | static int linebuffer_puts(BIO *h, const char *str); | 67 | static int linebuffer_puts(BIO *h, const char *str); |
68 | static int linebuffer_gets(BIO *h, char *str, int size); | 68 | static int linebuffer_gets(BIO *h, char *str, int size); |
@@ -76,8 +76,7 @@ static long linebuffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); | |||
76 | 76 | ||
77 | /* #define DEBUG */ | 77 | /* #define DEBUG */ |
78 | 78 | ||
79 | static BIO_METHOD methods_linebuffer= | 79 | static BIO_METHOD methods_linebuffer = { |
80 | { | ||
81 | BIO_TYPE_LINEBUFFER, | 80 | BIO_TYPE_LINEBUFFER, |
82 | "linebuffer", | 81 | "linebuffer", |
83 | linebuffer_write, | 82 | linebuffer_write, |
@@ -88,310 +87,313 @@ static BIO_METHOD methods_linebuffer= | |||
88 | linebuffer_new, | 87 | linebuffer_new, |
89 | linebuffer_free, | 88 | linebuffer_free, |
90 | linebuffer_callback_ctrl, | 89 | linebuffer_callback_ctrl, |
91 | }; | 90 | }; |
92 | 91 | ||
93 | BIO_METHOD *BIO_f_linebuffer(void) | 92 | BIO_METHOD |
94 | { | 93 | *BIO_f_linebuffer(void) |
95 | return(&methods_linebuffer); | 94 | { |
96 | } | 95 | return (&methods_linebuffer); |
96 | } | ||
97 | 97 | ||
98 | typedef struct bio_linebuffer_ctx_struct | 98 | typedef struct bio_linebuffer_ctx_struct { |
99 | { | ||
100 | char *obuf; /* the output char array */ | 99 | char *obuf; /* the output char array */ |
101 | int obuf_size; /* how big is the output buffer */ | 100 | int obuf_size; /* how big is the output buffer */ |
102 | int obuf_len; /* how many bytes are in it */ | 101 | int obuf_len; /* how many bytes are in it */ |
103 | } BIO_LINEBUFFER_CTX; | 102 | } BIO_LINEBUFFER_CTX; |
104 | 103 | ||
105 | static int linebuffer_new(BIO *bi) | 104 | static int |
106 | { | 105 | linebuffer_new(BIO *bi) |
106 | { | ||
107 | BIO_LINEBUFFER_CTX *ctx; | 107 | BIO_LINEBUFFER_CTX *ctx; |
108 | 108 | ||
109 | ctx=(BIO_LINEBUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_LINEBUFFER_CTX)); | 109 | ctx = (BIO_LINEBUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_LINEBUFFER_CTX)); |
110 | if (ctx == NULL) return(0); | 110 | if (ctx == NULL) |
111 | ctx->obuf=(char *)OPENSSL_malloc(DEFAULT_LINEBUFFER_SIZE); | 111 | return (0); |
112 | if (ctx->obuf == NULL) { OPENSSL_free(ctx); return(0); } | 112 | ctx->obuf = (char *)OPENSSL_malloc(DEFAULT_LINEBUFFER_SIZE); |
113 | ctx->obuf_size=DEFAULT_LINEBUFFER_SIZE; | 113 | if (ctx->obuf == NULL) { |
114 | ctx->obuf_len=0; | 114 | OPENSSL_free(ctx); |
115 | 115 | return (0); | |
116 | bi->init=1; | ||
117 | bi->ptr=(char *)ctx; | ||
118 | bi->flags=0; | ||
119 | return(1); | ||
120 | } | 116 | } |
117 | ctx->obuf_size = DEFAULT_LINEBUFFER_SIZE; | ||
118 | ctx->obuf_len = 0; | ||
119 | |||
120 | bi->init = 1; | ||
121 | bi->ptr = (char *)ctx; | ||
122 | bi->flags = 0; | ||
123 | return (1); | ||
124 | } | ||
121 | 125 | ||
122 | static int linebuffer_free(BIO *a) | 126 | static int |
123 | { | 127 | linebuffer_free(BIO *a) |
128 | { | ||
124 | BIO_LINEBUFFER_CTX *b; | 129 | BIO_LINEBUFFER_CTX *b; |
125 | 130 | ||
126 | if (a == NULL) return(0); | 131 | if (a == NULL) |
127 | b=(BIO_LINEBUFFER_CTX *)a->ptr; | 132 | return (0); |
128 | if (b->obuf != NULL) OPENSSL_free(b->obuf); | 133 | b = (BIO_LINEBUFFER_CTX *)a->ptr; |
134 | if (b->obuf != NULL) | ||
135 | OPENSSL_free(b->obuf); | ||
129 | OPENSSL_free(a->ptr); | 136 | OPENSSL_free(a->ptr); |
130 | a->ptr=NULL; | 137 | a->ptr = NULL; |
131 | a->init=0; | 138 | a->init = 0; |
132 | a->flags=0; | 139 | a->flags = 0; |
133 | return(1); | 140 | return (1); |
134 | } | 141 | } |
135 | 142 | ||
136 | static int linebuffer_read(BIO *b, char *out, int outl) | 143 | static int |
137 | { | 144 | linebuffer_read(BIO *b, char *out, int outl) |
138 | int ret=0; | 145 | { |
139 | 146 | int ret = 0; | |
140 | if (out == NULL) return(0); | 147 | |
141 | if (b->next_bio == NULL) return(0); | 148 | if (out == NULL) |
142 | ret=BIO_read(b->next_bio,out,outl); | 149 | return (0); |
150 | if (b->next_bio == NULL) | ||
151 | return (0); | ||
152 | ret = BIO_read(b->next_bio, out, outl); | ||
143 | BIO_clear_retry_flags(b); | 153 | BIO_clear_retry_flags(b); |
144 | BIO_copy_next_retry(b); | 154 | BIO_copy_next_retry(b); |
145 | return(ret); | 155 | return (ret); |
146 | } | 156 | } |
147 | 157 | ||
148 | static int linebuffer_write(BIO *b, const char *in, int inl) | 158 | static int |
149 | { | 159 | linebuffer_write(BIO *b, const char *in, int inl) |
150 | int i,num=0,foundnl; | 160 | { |
161 | int i, num = 0, foundnl; | ||
151 | BIO_LINEBUFFER_CTX *ctx; | 162 | BIO_LINEBUFFER_CTX *ctx; |
152 | 163 | ||
153 | if ((in == NULL) || (inl <= 0)) return(0); | 164 | if ((in == NULL) || (inl <= 0)) |
154 | ctx=(BIO_LINEBUFFER_CTX *)b->ptr; | 165 | return (0); |
155 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | 166 | ctx = (BIO_LINEBUFFER_CTX *)b->ptr; |
167 | if ((ctx == NULL) || (b->next_bio == NULL)) | ||
168 | return (0); | ||
156 | 169 | ||
157 | BIO_clear_retry_flags(b); | 170 | BIO_clear_retry_flags(b); |
158 | 171 | ||
159 | do | 172 | do { |
160 | { | ||
161 | const char *p; | 173 | const char *p; |
162 | 174 | ||
163 | for(p = in; p < in + inl && *p != '\n'; p++) | 175 | for (p = in; p < in + inl && *p != '\n'; p++) |
164 | ; | 176 | ; |
165 | if (*p == '\n') | 177 | if (*p == '\n') { |
166 | { | ||
167 | p++; | 178 | p++; |
168 | foundnl = 1; | 179 | foundnl = 1; |
169 | } | 180 | } else |
170 | else | ||
171 | foundnl = 0; | 181 | foundnl = 0; |
172 | 182 | ||
173 | /* If a NL was found and we already have text in the save | 183 | /* If a NL was found and we already have text in the save |
174 | buffer, concatenate them and write */ | 184 | buffer, concatenate them and write */ |
175 | while ((foundnl || p - in > ctx->obuf_size - ctx->obuf_len) | 185 | while ((foundnl || p - in > ctx->obuf_size - ctx->obuf_len) && |
176 | && ctx->obuf_len > 0) | 186 | ctx->obuf_len > 0) { |
177 | { | ||
178 | int orig_olen = ctx->obuf_len; | 187 | int orig_olen = ctx->obuf_len; |
179 | 188 | ||
180 | i = ctx->obuf_size - ctx->obuf_len; | 189 | i = ctx->obuf_size - ctx->obuf_len; |
181 | if (p - in > 0) | 190 | if (p - in > 0) { |
182 | { | 191 | if (i >= p - in) { |
183 | if (i >= p - in) | ||
184 | { | ||
185 | memcpy(&(ctx->obuf[ctx->obuf_len]), | 192 | memcpy(&(ctx->obuf[ctx->obuf_len]), |
186 | in,p - in); | 193 | in, p - in); |
187 | ctx->obuf_len += p - in; | 194 | ctx->obuf_len += p - in; |
188 | inl -= p - in; | 195 | inl -= p - in; |
189 | num += p - in; | 196 | num += p - in; |
190 | in = p; | 197 | in = p; |
191 | } | 198 | } else { |
192 | else | ||
193 | { | ||
194 | memcpy(&(ctx->obuf[ctx->obuf_len]), | 199 | memcpy(&(ctx->obuf[ctx->obuf_len]), |
195 | in,i); | 200 | in, i); |
196 | ctx->obuf_len += i; | 201 | ctx->obuf_len += i; |
197 | inl -= i; | 202 | inl -= i; |
198 | in += i; | 203 | in += i; |
199 | num += i; | 204 | num += i; |
200 | } | ||
201 | } | 205 | } |
206 | } | ||
202 | 207 | ||
203 | #if 0 | 208 | #if 0 |
204 | BIO_write(b->next_bio, "<*<", 3); | 209 | BIO_write(b->next_bio, "<*<", 3); |
205 | #endif | 210 | #endif |
206 | i=BIO_write(b->next_bio, | 211 | i = BIO_write(b->next_bio, ctx->obuf, ctx->obuf_len); |
207 | ctx->obuf, ctx->obuf_len); | 212 | if (i <= 0) { |
208 | if (i <= 0) | ||
209 | { | ||
210 | ctx->obuf_len = orig_olen; | 213 | ctx->obuf_len = orig_olen; |
211 | BIO_copy_next_retry(b); | 214 | BIO_copy_next_retry(b); |
212 | |||
213 | #if 0 | 215 | #if 0 |
214 | BIO_write(b->next_bio, ">*>", 3); | 216 | BIO_write(b->next_bio, ">*>", 3); |
215 | #endif | 217 | #endif |
216 | if (i < 0) return((num > 0)?num:i); | 218 | if (i < 0) |
217 | if (i == 0) return(num); | 219 | return ((num > 0) ? num : i); |
218 | } | 220 | if (i == 0) |
221 | return (num); | ||
222 | } | ||
219 | #if 0 | 223 | #if 0 |
220 | BIO_write(b->next_bio, ">*>", 3); | 224 | BIO_write(b->next_bio, ">*>", 3); |
221 | #endif | 225 | #endif |
222 | if (i < ctx->obuf_len) | 226 | if (i < ctx->obuf_len) |
223 | memmove(ctx->obuf, ctx->obuf + i, | 227 | memmove(ctx->obuf, ctx->obuf + i, |
224 | ctx->obuf_len - i); | 228 | ctx->obuf_len - i); |
225 | ctx->obuf_len-=i; | 229 | ctx->obuf_len -= i; |
226 | } | 230 | } |
227 | 231 | ||
228 | /* Now that the save buffer is emptied, let's write the input | 232 | /* Now that the save buffer is emptied, let's write the input |
229 | buffer if a NL was found and there is anything to write. */ | 233 | buffer if a NL was found and there is anything to write. */ |
230 | if ((foundnl || p - in > ctx->obuf_size) && p - in > 0) | 234 | if ((foundnl || p - in > ctx->obuf_size) && p - in > 0) { |
231 | { | ||
232 | #if 0 | 235 | #if 0 |
233 | BIO_write(b->next_bio, "<*<", 3); | 236 | BIO_write(b->next_bio, "<*<", 3); |
234 | #endif | 237 | #endif |
235 | i=BIO_write(b->next_bio,in,p - in); | 238 | i = BIO_write(b->next_bio, in, p - in); |
236 | if (i <= 0) | 239 | if (i <= 0) { |
237 | { | ||
238 | BIO_copy_next_retry(b); | 240 | BIO_copy_next_retry(b); |
239 | #if 0 | 241 | #if 0 |
240 | BIO_write(b->next_bio, ">*>", 3); | 242 | BIO_write(b->next_bio, ">*>", 3); |
241 | #endif | 243 | #endif |
242 | if (i < 0) return((num > 0)?num:i); | 244 | if (i < 0) |
243 | if (i == 0) return(num); | 245 | return ((num > 0) ? num : i); |
244 | } | 246 | if (i == 0) |
247 | return (num); | ||
248 | } | ||
245 | #if 0 | 249 | #if 0 |
246 | BIO_write(b->next_bio, ">*>", 3); | 250 | BIO_write(b->next_bio, ">*>", 3); |
247 | #endif | 251 | #endif |
248 | num+=i; | 252 | num += i; |
249 | in+=i; | 253 | in += i; |
250 | inl-=i; | 254 | inl -= i; |
251 | } | ||
252 | } | 255 | } |
253 | while(foundnl && inl > 0); | 256 | } while (foundnl && inl > 0); |
254 | /* We've written as much as we can. The rest of the input buffer, if | 257 | /* We've written as much as we can. The rest of the input buffer, if |
255 | any, is text that doesn't and with a NL and therefore needs to be | 258 | any, is text that doesn't and with a NL and therefore needs to be |
256 | saved for the next trip. */ | 259 | saved for the next trip. */ |
257 | if (inl > 0) | 260 | if (inl > 0) { |
258 | { | ||
259 | memcpy(&(ctx->obuf[ctx->obuf_len]), in, inl); | 261 | memcpy(&(ctx->obuf[ctx->obuf_len]), in, inl); |
260 | ctx->obuf_len += inl; | 262 | ctx->obuf_len += inl; |
261 | num += inl; | 263 | num += inl; |
262 | } | ||
263 | return num; | ||
264 | } | 264 | } |
265 | return num; | ||
266 | } | ||
265 | 267 | ||
266 | static long linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr) | 268 | static long |
267 | { | 269 | linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr) |
270 | { | ||
268 | BIO *dbio; | 271 | BIO *dbio; |
269 | BIO_LINEBUFFER_CTX *ctx; | 272 | BIO_LINEBUFFER_CTX *ctx; |
270 | long ret=1; | 273 | long ret = 1; |
271 | char *p; | 274 | char *p; |
272 | int r; | 275 | int r; |
273 | int obs; | 276 | int obs; |
274 | 277 | ||
275 | ctx=(BIO_LINEBUFFER_CTX *)b->ptr; | 278 | ctx = (BIO_LINEBUFFER_CTX *)b->ptr; |
276 | 279 | ||
277 | switch (cmd) | 280 | switch (cmd) { |
278 | { | ||
279 | case BIO_CTRL_RESET: | 281 | case BIO_CTRL_RESET: |
280 | ctx->obuf_len=0; | 282 | ctx->obuf_len = 0; |
281 | if (b->next_bio == NULL) return(0); | 283 | if (b->next_bio == NULL) |
282 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 284 | return (0); |
285 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
283 | break; | 286 | break; |
284 | case BIO_CTRL_INFO: | 287 | case BIO_CTRL_INFO: |
285 | ret=(long)ctx->obuf_len; | 288 | ret = (long)ctx->obuf_len; |
286 | break; | 289 | break; |
287 | case BIO_CTRL_WPENDING: | 290 | case BIO_CTRL_WPENDING: |
288 | ret=(long)ctx->obuf_len; | 291 | ret = (long)ctx->obuf_len; |
289 | if (ret == 0) | 292 | if (ret == 0) { |
290 | { | 293 | if (b->next_bio == NULL) |
291 | if (b->next_bio == NULL) return(0); | 294 | return (0); |
292 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 295 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
293 | } | 296 | } |
294 | break; | 297 | break; |
295 | case BIO_C_SET_BUFF_SIZE: | 298 | case BIO_C_SET_BUFF_SIZE: |
296 | obs=(int)num; | 299 | obs = (int)num; |
297 | p=ctx->obuf; | 300 | p = ctx->obuf; |
298 | if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size)) | 301 | if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size)) { |
299 | { | 302 | p = (char *)OPENSSL_malloc((int)num); |
300 | p=(char *)OPENSSL_malloc((int)num); | ||
301 | if (p == NULL) | 303 | if (p == NULL) |
302 | goto malloc_error; | 304 | goto malloc_error; |
303 | } | 305 | } |
304 | if (ctx->obuf != p) | 306 | if (ctx->obuf != p) { |
305 | { | 307 | if (ctx->obuf_len > obs) { |
306 | if (ctx->obuf_len > obs) | ||
307 | { | ||
308 | ctx->obuf_len = obs; | 308 | ctx->obuf_len = obs; |
309 | } | 309 | } |
310 | memcpy(p, ctx->obuf, ctx->obuf_len); | 310 | memcpy(p, ctx->obuf, ctx->obuf_len); |
311 | OPENSSL_free(ctx->obuf); | 311 | OPENSSL_free(ctx->obuf); |
312 | ctx->obuf=p; | 312 | ctx->obuf = p; |
313 | ctx->obuf_size=obs; | 313 | ctx->obuf_size = obs; |
314 | } | 314 | } |
315 | break; | 315 | break; |
316 | case BIO_C_DO_STATE_MACHINE: | 316 | case BIO_C_DO_STATE_MACHINE: |
317 | if (b->next_bio == NULL) return(0); | 317 | if (b->next_bio == NULL) |
318 | return (0); | ||
318 | BIO_clear_retry_flags(b); | 319 | BIO_clear_retry_flags(b); |
319 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 320 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
320 | BIO_copy_next_retry(b); | 321 | BIO_copy_next_retry(b); |
321 | break; | 322 | break; |
322 | 323 | ||
323 | case BIO_CTRL_FLUSH: | 324 | case BIO_CTRL_FLUSH: |
324 | if (b->next_bio == NULL) return(0); | 325 | if (b->next_bio == NULL) |
325 | if (ctx->obuf_len <= 0) | 326 | return (0); |
326 | { | 327 | if (ctx->obuf_len <= 0) { |
327 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 328 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
328 | break; | 329 | break; |
329 | } | 330 | } |
330 | 331 | ||
331 | for (;;) | 332 | for (;;) { |
332 | { | ||
333 | BIO_clear_retry_flags(b); | 333 | BIO_clear_retry_flags(b); |
334 | if (ctx->obuf_len > 0) | 334 | if (ctx->obuf_len > 0) { |
335 | { | 335 | r = BIO_write(b->next_bio, |
336 | r=BIO_write(b->next_bio, | 336 | ctx->obuf, ctx->obuf_len); |
337 | ctx->obuf, ctx->obuf_len); | ||
338 | #if 0 | 337 | #if 0 |
339 | fprintf(stderr,"FLUSH %3d -> %3d\n",ctx->obuf_len,r); | 338 | fprintf(stderr, "FLUSH %3d -> %3d\n", ctx->obuf_len, r); |
340 | #endif | 339 | #endif |
341 | BIO_copy_next_retry(b); | 340 | BIO_copy_next_retry(b); |
342 | if (r <= 0) return((long)r); | 341 | if (r <= 0) |
342 | return ((long)r); | ||
343 | if (r < ctx->obuf_len) | 343 | if (r < ctx->obuf_len) |
344 | memmove(ctx->obuf, ctx->obuf + r, | 344 | memmove(ctx->obuf, ctx->obuf + r, |
345 | ctx->obuf_len - r); | 345 | ctx->obuf_len - r); |
346 | ctx->obuf_len-=r; | 346 | ctx->obuf_len -= r; |
347 | } | 347 | } else { |
348 | else | 348 | ctx->obuf_len = 0; |
349 | { | 349 | ret = 1; |
350 | ctx->obuf_len=0; | ||
351 | ret=1; | ||
352 | break; | 350 | break; |
353 | } | ||
354 | } | 351 | } |
355 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 352 | } |
353 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
356 | break; | 354 | break; |
357 | case BIO_CTRL_DUP: | 355 | case BIO_CTRL_DUP: |
358 | dbio=(BIO *)ptr; | 356 | dbio = (BIO *)ptr; |
359 | if ( !BIO_set_write_buffer_size(dbio,ctx->obuf_size)) | 357 | if (!BIO_set_write_buffer_size(dbio, ctx->obuf_size)) |
360 | ret=0; | 358 | ret = 0; |
361 | break; | 359 | break; |
362 | default: | 360 | default: |
363 | if (b->next_bio == NULL) return(0); | 361 | if (b->next_bio == NULL) |
364 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 362 | return (0); |
363 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
365 | break; | 364 | break; |
366 | } | ||
367 | return(ret); | ||
368 | malloc_error: | ||
369 | BIOerr(BIO_F_LINEBUFFER_CTRL,ERR_R_MALLOC_FAILURE); | ||
370 | return(0); | ||
371 | } | 365 | } |
366 | return (ret); | ||
367 | malloc_error: | ||
368 | BIOerr(BIO_F_LINEBUFFER_CTRL, ERR_R_MALLOC_FAILURE); | ||
369 | return (0); | ||
370 | } | ||
372 | 371 | ||
373 | static long linebuffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | 372 | static long |
374 | { | 373 | linebuffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) |
375 | long ret=1; | 374 | { |
375 | long ret = 1; | ||
376 | 376 | ||
377 | if (b->next_bio == NULL) return(0); | 377 | if (b->next_bio == NULL) |
378 | switch (cmd) | 378 | return (0); |
379 | { | 379 | switch (cmd) { |
380 | default: | 380 | default: |
381 | ret=BIO_callback_ctrl(b->next_bio,cmd,fp); | 381 | ret = BIO_callback_ctrl(b->next_bio, cmd, fp); |
382 | break; | 382 | break; |
383 | } | ||
384 | return(ret); | ||
385 | } | 383 | } |
384 | return (ret); | ||
385 | } | ||
386 | 386 | ||
387 | static int linebuffer_gets(BIO *b, char *buf, int size) | 387 | static int |
388 | { | 388 | linebuffer_gets(BIO *b, char *buf, int size) |
389 | if (b->next_bio == NULL) return(0); | 389 | { |
390 | return(BIO_gets(b->next_bio,buf,size)); | 390 | if (b->next_bio == NULL) |
391 | } | 391 | return (0); |
392 | 392 | return (BIO_gets(b->next_bio, buf, size)); | |
393 | static int linebuffer_puts(BIO *b, const char *str) | 393 | } |
394 | { | ||
395 | return(linebuffer_write(b,str,strlen(str))); | ||
396 | } | ||
397 | 394 | ||
395 | static int | ||
396 | linebuffer_puts(BIO *b, const char *str) | ||
397 | { | ||
398 | return (linebuffer_write(b, str, strlen(str))); | ||
399 | } | ||
diff --git a/src/lib/libssl/src/crypto/bio/bf_nbio.c b/src/lib/libssl/src/crypto/bio/bf_nbio.c index 028616c064..76f8f31950 100644 --- a/src/lib/libssl/src/crypto/bio/bf_nbio.c +++ b/src/lib/libssl/src/crypto/bio/bf_nbio.c | |||
@@ -65,23 +65,22 @@ | |||
65 | /* BIO_put and BIO_get both add to the digest, | 65 | /* BIO_put and BIO_get both add to the digest, |
66 | * BIO_gets returns the digest */ | 66 | * BIO_gets returns the digest */ |
67 | 67 | ||
68 | static int nbiof_write(BIO *h,const char *buf,int num); | 68 | static int nbiof_write(BIO *h, const char *buf, int num); |
69 | static int nbiof_read(BIO *h,char *buf,int size); | 69 | static int nbiof_read(BIO *h, char *buf, int size); |
70 | static int nbiof_puts(BIO *h,const char *str); | 70 | static int nbiof_puts(BIO *h, const char *str); |
71 | static int nbiof_gets(BIO *h,char *str,int size); | 71 | static int nbiof_gets(BIO *h, char *str, int size); |
72 | static long nbiof_ctrl(BIO *h,int cmd,long arg1,void *arg2); | 72 | static long nbiof_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
73 | static int nbiof_new(BIO *h); | 73 | static int nbiof_new(BIO *h); |
74 | static int nbiof_free(BIO *data); | 74 | static int nbiof_free(BIO *data); |
75 | static long nbiof_callback_ctrl(BIO *h,int cmd,bio_info_cb *fp); | 75 | static long nbiof_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); |
76 | typedef struct nbio_test_st | 76 | |
77 | { | 77 | typedef struct nbio_test_st { |
78 | /* only set if we sent a 'should retry' error */ | 78 | /* only set if we sent a 'should retry' error */ |
79 | int lrn; | 79 | int lrn; |
80 | int lwn; | 80 | int lwn; |
81 | } NBIO_TEST; | 81 | } NBIO_TEST; |
82 | 82 | ||
83 | static BIO_METHOD methods_nbiof= | 83 | static BIO_METHOD methods_nbiof = { |
84 | { | ||
85 | BIO_TYPE_NBIO_TEST, | 84 | BIO_TYPE_NBIO_TEST, |
86 | "non-blocking IO test filter", | 85 | "non-blocking IO test filter", |
87 | nbiof_write, | 86 | nbiof_write, |
@@ -92,162 +91,170 @@ static BIO_METHOD methods_nbiof= | |||
92 | nbiof_new, | 91 | nbiof_new, |
93 | nbiof_free, | 92 | nbiof_free, |
94 | nbiof_callback_ctrl, | 93 | nbiof_callback_ctrl, |
95 | }; | 94 | }; |
96 | 95 | ||
97 | BIO_METHOD *BIO_f_nbio_test(void) | 96 | BIO_METHOD |
98 | { | 97 | *BIO_f_nbio_test(void) |
99 | return(&methods_nbiof); | 98 | { |
100 | } | 99 | return (&methods_nbiof); |
100 | } | ||
101 | 101 | ||
102 | static int nbiof_new(BIO *bi) | 102 | static int |
103 | { | 103 | nbiof_new(BIO *bi) |
104 | { | ||
104 | NBIO_TEST *nt; | 105 | NBIO_TEST *nt; |
105 | 106 | ||
106 | if (!(nt=(NBIO_TEST *)OPENSSL_malloc(sizeof(NBIO_TEST)))) return(0); | 107 | if (!(nt = (NBIO_TEST *)OPENSSL_malloc(sizeof(NBIO_TEST)))) |
107 | nt->lrn= -1; | 108 | return (0); |
108 | nt->lwn= -1; | 109 | nt->lrn = -1; |
109 | bi->ptr=(char *)nt; | 110 | nt->lwn = -1; |
110 | bi->init=1; | 111 | bi->ptr = (char *)nt; |
111 | bi->flags=0; | 112 | bi->init = 1; |
112 | return(1); | 113 | bi->flags = 0; |
113 | } | 114 | return (1); |
115 | } | ||
114 | 116 | ||
115 | static int nbiof_free(BIO *a) | 117 | static int |
116 | { | 118 | nbiof_free(BIO *a) |
117 | if (a == NULL) return(0); | 119 | { |
120 | if (a == NULL) | ||
121 | return (0); | ||
118 | if (a->ptr != NULL) | 122 | if (a->ptr != NULL) |
119 | OPENSSL_free(a->ptr); | 123 | OPENSSL_free(a->ptr); |
120 | a->ptr=NULL; | 124 | a->ptr = NULL; |
121 | a->init=0; | 125 | a->init = 0; |
122 | a->flags=0; | 126 | a->flags = 0; |
123 | return(1); | 127 | return (1); |
124 | } | 128 | } |
125 | 129 | ||
126 | static int nbiof_read(BIO *b, char *out, int outl) | 130 | static int |
127 | { | 131 | nbiof_read(BIO *b, char *out, int outl) |
128 | int ret=0; | 132 | { |
133 | int ret = 0; | ||
129 | #if 1 | 134 | #if 1 |
130 | int num; | 135 | int num; |
131 | unsigned char n; | 136 | unsigned char n; |
132 | #endif | 137 | #endif |
133 | 138 | ||
134 | if (out == NULL) return(0); | 139 | if (out == NULL) |
135 | if (b->next_bio == NULL) return(0); | 140 | return (0); |
141 | if (b->next_bio == NULL) | ||
142 | return (0); | ||
136 | 143 | ||
137 | BIO_clear_retry_flags(b); | 144 | BIO_clear_retry_flags(b); |
138 | #if 1 | 145 | #if 1 |
139 | RAND_pseudo_bytes(&n,1); | 146 | RAND_pseudo_bytes(&n, 1); |
140 | num=(n&0x07); | 147 | num = (n & 0x07); |
141 | 148 | ||
142 | if (outl > num) outl=num; | 149 | if (outl > num) |
150 | outl = num; | ||
143 | 151 | ||
144 | if (num == 0) | 152 | if (num == 0) { |
145 | { | 153 | ret = -1; |
146 | ret= -1; | ||
147 | BIO_set_retry_read(b); | 154 | BIO_set_retry_read(b); |
148 | } | 155 | } else |
149 | else | ||
150 | #endif | 156 | #endif |
151 | { | 157 | { |
152 | ret=BIO_read(b->next_bio,out,outl); | 158 | ret = BIO_read(b->next_bio, out, outl); |
153 | if (ret < 0) | 159 | if (ret < 0) |
154 | BIO_copy_next_retry(b); | 160 | BIO_copy_next_retry(b); |
155 | } | ||
156 | return(ret); | ||
157 | } | 161 | } |
162 | return (ret); | ||
163 | } | ||
158 | 164 | ||
159 | static int nbiof_write(BIO *b, const char *in, int inl) | 165 | static int |
160 | { | 166 | nbiof_write(BIO *b, const char *in, int inl) |
167 | { | ||
161 | NBIO_TEST *nt; | 168 | NBIO_TEST *nt; |
162 | int ret=0; | 169 | int ret = 0; |
163 | int num; | 170 | int num; |
164 | unsigned char n; | 171 | unsigned char n; |
165 | 172 | ||
166 | if ((in == NULL) || (inl <= 0)) return(0); | 173 | if ((in == NULL) || (inl <= 0)) |
167 | if (b->next_bio == NULL) return(0); | 174 | return (0); |
168 | nt=(NBIO_TEST *)b->ptr; | 175 | if (b->next_bio == NULL) |
176 | return (0); | ||
177 | nt = (NBIO_TEST *)b->ptr; | ||
169 | 178 | ||
170 | BIO_clear_retry_flags(b); | 179 | BIO_clear_retry_flags(b); |
171 | 180 | ||
172 | #if 1 | 181 | #if 1 |
173 | if (nt->lwn > 0) | 182 | if (nt->lwn > 0) { |
174 | { | 183 | num = nt->lwn; |
175 | num=nt->lwn; | 184 | nt->lwn = 0; |
176 | nt->lwn=0; | 185 | } else { |
177 | } | 186 | RAND_pseudo_bytes(&n, 1); |
178 | else | 187 | num = (n&7); |
179 | { | 188 | } |
180 | RAND_pseudo_bytes(&n,1); | ||
181 | num=(n&7); | ||
182 | } | ||
183 | 189 | ||
184 | if (inl > num) inl=num; | 190 | if (inl > num) |
191 | inl = num; | ||
185 | 192 | ||
186 | if (num == 0) | 193 | if (num == 0) { |
187 | { | 194 | ret = -1; |
188 | ret= -1; | ||
189 | BIO_set_retry_write(b); | 195 | BIO_set_retry_write(b); |
190 | } | 196 | } else |
191 | else | ||
192 | #endif | 197 | #endif |
193 | { | 198 | { |
194 | ret=BIO_write(b->next_bio,in,inl); | 199 | ret = BIO_write(b->next_bio, in, inl); |
195 | if (ret < 0) | 200 | if (ret < 0) { |
196 | { | ||
197 | BIO_copy_next_retry(b); | 201 | BIO_copy_next_retry(b); |
198 | nt->lwn=inl; | 202 | nt->lwn = inl; |
199 | } | ||
200 | } | 203 | } |
201 | return(ret); | ||
202 | } | 204 | } |
205 | return (ret); | ||
206 | } | ||
203 | 207 | ||
204 | static long nbiof_ctrl(BIO *b, int cmd, long num, void *ptr) | 208 | static long |
205 | { | 209 | nbiof_ctrl(BIO *b, int cmd, long num, void *ptr) |
210 | { | ||
206 | long ret; | 211 | long ret; |
207 | 212 | ||
208 | if (b->next_bio == NULL) return(0); | 213 | if (b->next_bio == NULL) |
209 | switch (cmd) | 214 | return (0); |
210 | { | 215 | switch (cmd) { |
211 | case BIO_C_DO_STATE_MACHINE: | 216 | case BIO_C_DO_STATE_MACHINE: |
212 | BIO_clear_retry_flags(b); | 217 | BIO_clear_retry_flags(b); |
213 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 218 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
214 | BIO_copy_next_retry(b); | 219 | BIO_copy_next_retry(b); |
215 | break; | 220 | break; |
216 | case BIO_CTRL_DUP: | 221 | case BIO_CTRL_DUP: |
217 | ret=0L; | 222 | ret = 0L; |
218 | break; | 223 | break; |
219 | default: | 224 | default: |
220 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 225 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
221 | break; | 226 | break; |
222 | } | ||
223 | return(ret); | ||
224 | } | 227 | } |
228 | return (ret); | ||
229 | } | ||
225 | 230 | ||
226 | static long nbiof_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | 231 | static long |
227 | { | 232 | nbiof_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) |
228 | long ret=1; | 233 | { |
234 | long ret = 1; | ||
229 | 235 | ||
230 | if (b->next_bio == NULL) return(0); | 236 | if (b->next_bio == NULL) |
231 | switch (cmd) | 237 | return (0); |
232 | { | 238 | switch (cmd) { |
233 | default: | 239 | default: |
234 | ret=BIO_callback_ctrl(b->next_bio,cmd,fp); | 240 | ret = BIO_callback_ctrl(b->next_bio, cmd, fp); |
235 | break; | 241 | break; |
236 | } | ||
237 | return(ret); | ||
238 | } | ||
239 | |||
240 | static int nbiof_gets(BIO *bp, char *buf, int size) | ||
241 | { | ||
242 | if (bp->next_bio == NULL) return(0); | ||
243 | return(BIO_gets(bp->next_bio,buf,size)); | ||
244 | } | ||
245 | |||
246 | |||
247 | static int nbiof_puts(BIO *bp, const char *str) | ||
248 | { | ||
249 | if (bp->next_bio == NULL) return(0); | ||
250 | return(BIO_puts(bp->next_bio,str)); | ||
251 | } | 242 | } |
243 | return (ret); | ||
244 | } | ||
252 | 245 | ||
246 | static int | ||
247 | nbiof_gets(BIO *bp, char *buf, int size) | ||
248 | { | ||
249 | if (bp->next_bio == NULL) | ||
250 | return (0); | ||
251 | return (BIO_gets(bp->next_bio, buf, size)); | ||
252 | } | ||
253 | 253 | ||
254 | static int | ||
255 | nbiof_puts(BIO *bp, const char *str) | ||
256 | { | ||
257 | if (bp->next_bio == NULL) | ||
258 | return (0); | ||
259 | return (BIO_puts(bp->next_bio, str)); | ||
260 | } | ||
diff --git a/src/lib/libssl/src/crypto/bio/bf_null.c b/src/lib/libssl/src/crypto/bio/bf_null.c index c1bf39a904..354731c0c7 100644 --- a/src/lib/libssl/src/crypto/bio/bf_null.c +++ b/src/lib/libssl/src/crypto/bio/bf_null.c | |||
@@ -72,8 +72,8 @@ static long nullf_ctrl(BIO *h, int cmd, long arg1, void *arg2); | |||
72 | static int nullf_new(BIO *h); | 72 | static int nullf_new(BIO *h); |
73 | static int nullf_free(BIO *data); | 73 | static int nullf_free(BIO *data); |
74 | static long nullf_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); | 74 | static long nullf_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); |
75 | static BIO_METHOD methods_nullf= | 75 | |
76 | { | 76 | static BIO_METHOD methods_nullf = { |
77 | BIO_TYPE_NULL_FILTER, | 77 | BIO_TYPE_NULL_FILTER, |
78 | "NULL filter", | 78 | "NULL filter", |
79 | nullf_write, | 79 | nullf_write, |
@@ -84,100 +84,113 @@ static BIO_METHOD methods_nullf= | |||
84 | nullf_new, | 84 | nullf_new, |
85 | nullf_free, | 85 | nullf_free, |
86 | nullf_callback_ctrl, | 86 | nullf_callback_ctrl, |
87 | }; | 87 | }; |
88 | 88 | ||
89 | BIO_METHOD *BIO_f_null(void) | 89 | BIO_METHOD |
90 | { | 90 | *BIO_f_null(void) |
91 | return(&methods_nullf); | 91 | { |
92 | } | 92 | return (&methods_nullf); |
93 | 93 | } | |
94 | static int nullf_new(BIO *bi) | 94 | |
95 | { | 95 | static int |
96 | bi->init=1; | 96 | nullf_new(BIO *bi) |
97 | bi->ptr=NULL; | 97 | { |
98 | bi->flags=0; | 98 | bi->init = 1; |
99 | return(1); | 99 | bi->ptr = NULL; |
100 | } | 100 | bi->flags = 0; |
101 | 101 | return (1); | |
102 | static int nullf_free(BIO *a) | 102 | } |
103 | { | 103 | |
104 | if (a == NULL) return(0); | 104 | static int |
105 | nullf_free(BIO *a) | ||
106 | { | ||
107 | if (a == NULL) | ||
108 | return (0); | ||
105 | /* a->ptr=NULL; | 109 | /* a->ptr=NULL; |
106 | a->init=0; | 110 | a->init=0; |
107 | a->flags=0;*/ | 111 | a->flags=0;*/ |
108 | return(1); | 112 | return (1); |
109 | } | 113 | } |
110 | 114 | ||
111 | static int nullf_read(BIO *b, char *out, int outl) | 115 | static int |
112 | { | 116 | nullf_read(BIO *b, char *out, int outl) |
113 | int ret=0; | 117 | { |
114 | 118 | int ret = 0; | |
115 | if (out == NULL) return(0); | 119 | |
116 | if (b->next_bio == NULL) return(0); | 120 | if (out == NULL) |
117 | ret=BIO_read(b->next_bio,out,outl); | 121 | return (0); |
122 | if (b->next_bio == NULL) | ||
123 | return (0); | ||
124 | ret = BIO_read(b->next_bio, out, outl); | ||
118 | BIO_clear_retry_flags(b); | 125 | BIO_clear_retry_flags(b); |
119 | BIO_copy_next_retry(b); | 126 | BIO_copy_next_retry(b); |
120 | return(ret); | 127 | return (ret); |
121 | } | 128 | } |
122 | 129 | ||
123 | static int nullf_write(BIO *b, const char *in, int inl) | 130 | static int |
124 | { | 131 | nullf_write(BIO *b, const char *in, int inl) |
125 | int ret=0; | 132 | { |
126 | 133 | int ret = 0; | |
127 | if ((in == NULL) || (inl <= 0)) return(0); | 134 | |
128 | if (b->next_bio == NULL) return(0); | 135 | if ((in == NULL) || (inl <= 0)) |
129 | ret=BIO_write(b->next_bio,in,inl); | 136 | return (0); |
137 | if (b->next_bio == NULL) | ||
138 | return (0); | ||
139 | ret = BIO_write(b->next_bio, in, inl); | ||
130 | BIO_clear_retry_flags(b); | 140 | BIO_clear_retry_flags(b); |
131 | BIO_copy_next_retry(b); | 141 | BIO_copy_next_retry(b); |
132 | return(ret); | 142 | return (ret); |
133 | } | 143 | } |
134 | 144 | ||
135 | static long nullf_ctrl(BIO *b, int cmd, long num, void *ptr) | 145 | static long |
136 | { | 146 | nullf_ctrl(BIO *b, int cmd, long num, void *ptr) |
147 | { | ||
137 | long ret; | 148 | long ret; |
138 | 149 | ||
139 | if (b->next_bio == NULL) return(0); | 150 | if (b->next_bio == NULL) |
140 | switch(cmd) | 151 | return (0); |
141 | { | 152 | switch (cmd) { |
142 | case BIO_C_DO_STATE_MACHINE: | 153 | case BIO_C_DO_STATE_MACHINE: |
143 | BIO_clear_retry_flags(b); | 154 | BIO_clear_retry_flags(b); |
144 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 155 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
145 | BIO_copy_next_retry(b); | 156 | BIO_copy_next_retry(b); |
146 | break; | 157 | break; |
147 | case BIO_CTRL_DUP: | 158 | case BIO_CTRL_DUP: |
148 | ret=0L; | 159 | ret = 0L; |
149 | break; | 160 | break; |
150 | default: | 161 | default: |
151 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 162 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
152 | } | ||
153 | return(ret); | ||
154 | } | 163 | } |
164 | return (ret); | ||
165 | } | ||
155 | 166 | ||
156 | static long nullf_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | 167 | static long |
157 | { | 168 | nullf_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) |
158 | long ret=1; | 169 | { |
170 | long ret = 1; | ||
159 | 171 | ||
160 | if (b->next_bio == NULL) return(0); | 172 | if (b->next_bio == NULL) |
161 | switch (cmd) | 173 | return (0); |
162 | { | 174 | switch (cmd) { |
163 | default: | 175 | default: |
164 | ret=BIO_callback_ctrl(b->next_bio,cmd,fp); | 176 | ret = BIO_callback_ctrl(b->next_bio, cmd, fp); |
165 | break; | 177 | break; |
166 | } | ||
167 | return(ret); | ||
168 | } | 178 | } |
169 | 179 | return (ret); | |
170 | static int nullf_gets(BIO *bp, char *buf, int size) | 180 | } |
171 | { | 181 | |
172 | if (bp->next_bio == NULL) return(0); | 182 | static int |
173 | return(BIO_gets(bp->next_bio,buf,size)); | 183 | nullf_gets(BIO *bp, char *buf, int size) |
174 | } | 184 | { |
175 | 185 | if (bp->next_bio == NULL) | |
176 | 186 | return (0); | |
177 | static int nullf_puts(BIO *bp, const char *str) | 187 | return (BIO_gets(bp->next_bio, buf, size)); |
178 | { | 188 | } |
179 | if (bp->next_bio == NULL) return(0); | 189 | |
180 | return(BIO_puts(bp->next_bio,str)); | 190 | static int |
181 | } | 191 | nullf_puts(BIO *bp, const char *str) |
182 | 192 | { | |
183 | 193 | if (bp->next_bio == NULL) | |
194 | return (0); | ||
195 | return (BIO_puts(bp->next_bio, str)); | ||
196 | } | ||
diff --git a/src/lib/libssl/src/crypto/bio/bio.h b/src/lib/libssl/src/crypto/bio/bio.h index 05699ab212..4f1d02ada5 100644 --- a/src/lib/libssl/src/crypto/bio/bio.h +++ b/src/lib/libssl/src/crypto/bio/bio.h | |||
@@ -151,7 +151,7 @@ extern "C" { | |||
151 | 151 | ||
152 | #define BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP 37 /* flag whether the last */ | 152 | #define BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP 37 /* flag whether the last */ |
153 | #define BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP 38 /* I/O operation tiemd out */ | 153 | #define BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP 38 /* I/O operation tiemd out */ |
154 | 154 | ||
155 | /* #ifdef IP_MTU_DISCOVER */ | 155 | /* #ifdef IP_MTU_DISCOVER */ |
156 | #define BIO_CTRL_DGRAM_MTU_DISCOVER 39 /* set DF bit on egress packets */ | 156 | #define BIO_CTRL_DGRAM_MTU_DISCOVER 39 /* set DF bit on egress packets */ |
157 | /* #endif */ | 157 | /* #endif */ |
@@ -282,9 +282,10 @@ void BIO_clear_flags(BIO *b, int flags); | |||
282 | #define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN)) | 282 | #define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN)) |
283 | #define BIO_cb_post(a) ((a)&BIO_CB_RETURN) | 283 | #define BIO_cb_post(a) ((a)&BIO_CB_RETURN) |
284 | 284 | ||
285 | long (*BIO_get_callback(const BIO *b)) (struct bio_st *,int,const char *,int, long,long); | 285 | long (*BIO_get_callback(const BIO *b))(struct bio_st *, int, const char *, |
286 | void BIO_set_callback(BIO *b, | 286 | int, long, long); |
287 | long (*callback)(struct bio_st *,int,const char *,int, long,long)); | 287 | void BIO_set_callback(BIO *b, |
288 | long (*callback)(struct bio_st *, int, const char *, int, long, long)); | ||
288 | char *BIO_get_callback_arg(const BIO *b); | 289 | char *BIO_get_callback_arg(const BIO *b); |
289 | void BIO_set_callback_arg(BIO *b, char *arg); | 290 | void BIO_set_callback_arg(BIO *b, char *arg); |
290 | 291 | ||
@@ -293,8 +294,7 @@ int BIO_method_type(const BIO *b); | |||
293 | 294 | ||
294 | typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long); | 295 | typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long); |
295 | 296 | ||
296 | typedef struct bio_method_st | 297 | typedef struct bio_method_st { |
297 | { | ||
298 | int type; | 298 | int type; |
299 | const char *name; | 299 | const char *name; |
300 | int (*bwrite)(BIO *, const char *, int); | 300 | int (*bwrite)(BIO *, const char *, int); |
@@ -304,14 +304,13 @@ typedef struct bio_method_st | |||
304 | long (*ctrl)(BIO *, int, long, void *); | 304 | long (*ctrl)(BIO *, int, long, void *); |
305 | int (*create)(BIO *); | 305 | int (*create)(BIO *); |
306 | int (*destroy)(BIO *); | 306 | int (*destroy)(BIO *); |
307 | long (*callback_ctrl)(BIO *, int, bio_info_cb *); | 307 | long (*callback_ctrl)(BIO *, int, bio_info_cb *); |
308 | } BIO_METHOD; | 308 | } BIO_METHOD; |
309 | 309 | ||
310 | struct bio_st | 310 | struct bio_st { |
311 | { | ||
312 | BIO_METHOD *method; | 311 | BIO_METHOD *method; |
313 | /* bio, mode, argp, argi, argl, ret */ | 312 | /* bio, mode, argp, argi, argl, ret */ |
314 | long (*callback)(struct bio_st *,int,const char *,int, long,long); | 313 | long (*callback)(struct bio_st *, int, const char *, int, long, long); |
315 | char *cb_arg; /* first argument for the callback */ | 314 | char *cb_arg; /* first argument for the callback */ |
316 | 315 | ||
317 | int init; | 316 | int init; |
@@ -327,12 +326,11 @@ struct bio_st | |||
327 | unsigned long num_write; | 326 | unsigned long num_write; |
328 | 327 | ||
329 | CRYPTO_EX_DATA ex_data; | 328 | CRYPTO_EX_DATA ex_data; |
330 | }; | 329 | }; |
331 | 330 | ||
332 | DECLARE_STACK_OF(BIO) | 331 | DECLARE_STACK_OF(BIO) |
333 | 332 | ||
334 | typedef struct bio_f_buffer_ctx_struct | 333 | typedef struct bio_f_buffer_ctx_struct { |
335 | { | ||
336 | /* Buffers are setup like this: | 334 | /* Buffers are setup like this: |
337 | * | 335 | * |
338 | * <---------------------- size -----------------------> | 336 | * <---------------------- size -----------------------> |
@@ -346,30 +344,28 @@ typedef struct bio_f_buffer_ctx_struct | |||
346 | int ibuf_size; /* how big is the input buffer */ | 344 | int ibuf_size; /* how big is the input buffer */ |
347 | int obuf_size; /* how big is the output buffer */ | 345 | int obuf_size; /* how big is the output buffer */ |
348 | 346 | ||
349 | char *ibuf; /* the char array */ | 347 | char *ibuf; /* the char array */ |
350 | int ibuf_len; /* how many bytes are in it */ | 348 | int ibuf_len; /* how many bytes are in it */ |
351 | int ibuf_off; /* write/read offset */ | 349 | int ibuf_off; /* write/read offset */ |
352 | 350 | ||
353 | char *obuf; /* the char array */ | 351 | char *obuf; /* the char array */ |
354 | int obuf_len; /* how many bytes are in it */ | 352 | int obuf_len; /* how many bytes are in it */ |
355 | int obuf_off; /* write/read offset */ | 353 | int obuf_off; /* write/read offset */ |
356 | } BIO_F_BUFFER_CTX; | 354 | } BIO_F_BUFFER_CTX; |
357 | 355 | ||
358 | /* Prefix and suffix callback in ASN1 BIO */ | 356 | /* Prefix and suffix callback in ASN1 BIO */ |
359 | typedef int asn1_ps_func(BIO *b, unsigned char **pbuf, int *plen, void *parg); | 357 | typedef int asn1_ps_func(BIO *b, unsigned char **pbuf, int *plen, void *parg); |
360 | 358 | ||
361 | #ifndef OPENSSL_NO_SCTP | 359 | #ifndef OPENSSL_NO_SCTP |
362 | /* SCTP parameter structs */ | 360 | /* SCTP parameter structs */ |
363 | struct bio_dgram_sctp_sndinfo | 361 | struct bio_dgram_sctp_sndinfo { |
364 | { | ||
365 | uint16_t snd_sid; | 362 | uint16_t snd_sid; |
366 | uint16_t snd_flags; | 363 | uint16_t snd_flags; |
367 | uint32_t snd_ppid; | 364 | uint32_t snd_ppid; |
368 | uint32_t snd_context; | 365 | uint32_t snd_context; |
369 | }; | 366 | }; |
370 | 367 | ||
371 | struct bio_dgram_sctp_rcvinfo | 368 | struct bio_dgram_sctp_rcvinfo { |
372 | { | ||
373 | uint16_t rcv_sid; | 369 | uint16_t rcv_sid; |
374 | uint16_t rcv_ssn; | 370 | uint16_t rcv_ssn; |
375 | uint16_t rcv_flags; | 371 | uint16_t rcv_flags; |
@@ -377,13 +373,12 @@ struct bio_dgram_sctp_rcvinfo | |||
377 | uint32_t rcv_tsn; | 373 | uint32_t rcv_tsn; |
378 | uint32_t rcv_cumtsn; | 374 | uint32_t rcv_cumtsn; |
379 | uint32_t rcv_context; | 375 | uint32_t rcv_context; |
380 | }; | 376 | }; |
381 | 377 | ||
382 | struct bio_dgram_sctp_prinfo | 378 | struct bio_dgram_sctp_prinfo { |
383 | { | ||
384 | uint16_t pr_policy; | 379 | uint16_t pr_policy; |
385 | uint32_t pr_value; | 380 | uint32_t pr_value; |
386 | }; | 381 | }; |
387 | #endif | 382 | #endif |
388 | 383 | ||
389 | /* connect BIO stuff */ | 384 | /* connect BIO stuff */ |
@@ -519,7 +514,7 @@ struct bio_dgram_sctp_prinfo | |||
519 | /* If you are wondering why this isn't defined, its because CONST_STRICT is | 514 | /* If you are wondering why this isn't defined, its because CONST_STRICT is |
520 | * purely a compile-time kludge to allow const to be checked. | 515 | * purely a compile-time kludge to allow const to be checked. |
521 | */ | 516 | */ |
522 | int BIO_read_filename(BIO *b,const char *name); | 517 | int BIO_read_filename(BIO *b, const char *name); |
523 | #else | 518 | #else |
524 | #define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ | 519 | #define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ |
525 | BIO_CLOSE|BIO_FP_READ,(char *)name) | 520 | BIO_CLOSE|BIO_FP_READ,(char *)name) |
@@ -611,22 +606,27 @@ int BIO_ctrl_reset_read_request(BIO *b); | |||
611 | /* These two aren't currently implemented */ | 606 | /* These two aren't currently implemented */ |
612 | /* int BIO_get_ex_num(BIO *bio); */ | 607 | /* int BIO_get_ex_num(BIO *bio); */ |
613 | /* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */ | 608 | /* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */ |
614 | int BIO_set_ex_data(BIO *bio,int idx,void *data); | 609 | int BIO_set_ex_data(BIO *bio, int idx, void *data); |
615 | void *BIO_get_ex_data(BIO *bio,int idx); | 610 | void *BIO_get_ex_data(BIO *bio, int idx); |
616 | int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | 611 | int |
617 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | 612 | BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, |
613 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | ||
618 | unsigned long BIO_number_read(BIO *bio); | 614 | unsigned long BIO_number_read(BIO *bio); |
619 | unsigned long BIO_number_written(BIO *bio); | 615 | unsigned long BIO_number_written(BIO *bio); |
620 | 616 | ||
621 | /* For BIO_f_asn1() */ | 617 | /* For BIO_f_asn1() */ |
622 | int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, | 618 | int |
623 | asn1_ps_func *prefix_free); | 619 | BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, |
624 | int BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, | 620 | asn1_ps_func *prefix_free); |
625 | asn1_ps_func **pprefix_free); | 621 | int |
626 | int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, | 622 | BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, |
627 | asn1_ps_func *suffix_free); | 623 | asn1_ps_func **pprefix_free); |
628 | int BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, | 624 | int |
629 | asn1_ps_func **psuffix_free); | 625 | BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, |
626 | asn1_ps_func *suffix_free); | ||
627 | int | ||
628 | BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, | ||
629 | asn1_ps_func **psuffix_free); | ||
630 | 630 | ||
631 | # ifndef OPENSSL_NO_FP_API | 631 | # ifndef OPENSSL_NO_FP_API |
632 | BIO_METHOD *BIO_s_file(void ); | 632 | BIO_METHOD *BIO_s_file(void ); |
@@ -635,22 +635,23 @@ BIO *BIO_new_fp(FILE *stream, int close_flag); | |||
635 | # define BIO_s_file_internal BIO_s_file | 635 | # define BIO_s_file_internal BIO_s_file |
636 | # endif | 636 | # endif |
637 | BIO * BIO_new(BIO_METHOD *type); | 637 | BIO * BIO_new(BIO_METHOD *type); |
638 | int BIO_set(BIO *a,BIO_METHOD *type); | 638 | int BIO_set(BIO *a, BIO_METHOD *type); |
639 | int BIO_free(BIO *a); | 639 | int BIO_free(BIO *a); |
640 | void BIO_vfree(BIO *a); | 640 | void BIO_vfree(BIO *a); |
641 | int BIO_read(BIO *b, void *data, int len); | 641 | int BIO_read(BIO *b, void *data, int len); |
642 | int BIO_gets(BIO *bp,char *buf, int size); | 642 | int BIO_gets(BIO *bp, char *buf, int size); |
643 | int BIO_write(BIO *b, const void *data, int len); | 643 | int BIO_write(BIO *b, const void *data, int len); |
644 | int BIO_puts(BIO *bp,const char *buf); | 644 | int BIO_puts(BIO *bp, const char *buf); |
645 | int BIO_indent(BIO *b,int indent,int max); | 645 | int BIO_indent(BIO *b, int indent, int max); |
646 | long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg); | 646 | long BIO_ctrl(BIO *bp, int cmd, long larg, void *parg); |
647 | long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long)); | 647 | long BIO_callback_ctrl(BIO *b, int cmd, |
648 | char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg); | 648 | void (*fp)(struct bio_st *, int, const char *, int, long, long)); |
649 | long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg); | 649 | char * BIO_ptr_ctrl(BIO *bp, int cmd, long larg); |
650 | BIO * BIO_push(BIO *b,BIO *append); | 650 | long BIO_int_ctrl(BIO *bp, int cmd, long larg, int iarg); |
651 | BIO * BIO_push(BIO *b, BIO *append); | ||
651 | BIO * BIO_pop(BIO *b); | 652 | BIO * BIO_pop(BIO *b); |
652 | void BIO_free_all(BIO *a); | 653 | void BIO_free_all(BIO *a); |
653 | BIO * BIO_find_type(BIO *b,int bio_type); | 654 | BIO * BIO_find_type(BIO *b, int bio_type); |
654 | BIO * BIO_next(BIO *b); | 655 | BIO * BIO_next(BIO *b); |
655 | BIO * BIO_get_retry_BIO(BIO *bio, int *reason); | 656 | BIO * BIO_get_retry_BIO(BIO *bio, int *reason); |
656 | int BIO_get_retry_reason(BIO *bio); | 657 | int BIO_get_retry_reason(BIO *bio); |
@@ -661,8 +662,8 @@ int BIO_nread(BIO *bio, char **buf, int num); | |||
661 | int BIO_nwrite0(BIO *bio, char **buf); | 662 | int BIO_nwrite0(BIO *bio, char **buf); |
662 | int BIO_nwrite(BIO *bio, char **buf, int num); | 663 | int BIO_nwrite(BIO *bio, char **buf, int num); |
663 | 664 | ||
664 | long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi, | 665 | long BIO_debug_callback(BIO *bio, int cmd, const char *argp, int argi, |
665 | long argl,long ret); | 666 | long argl, long ret); |
666 | 667 | ||
667 | BIO_METHOD *BIO_s_mem(void); | 668 | BIO_METHOD *BIO_s_mem(void); |
668 | BIO *BIO_new_mem_buf(void *buf, int len); | 669 | BIO *BIO_new_mem_buf(void *buf, int len); |
@@ -696,12 +697,14 @@ int BIO_dgram_non_fatal_error(int error); | |||
696 | 697 | ||
697 | int BIO_fd_should_retry(int i); | 698 | int BIO_fd_should_retry(int i); |
698 | int BIO_fd_non_fatal_error(int error); | 699 | int BIO_fd_non_fatal_error(int error); |
699 | int BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u), | 700 | int |
700 | void *u, const char *s, int len); | 701 | BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u), |
701 | int BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), | 702 | void *u, const char *s, int len); |
702 | void *u, const char *s, int len, int indent); | 703 | int |
703 | int BIO_dump(BIO *b,const char *bytes,int len); | 704 | BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), |
704 | int BIO_dump_indent(BIO *b,const char *bytes,int len,int indent); | 705 | void *u, const char *s, int len, int indent); |
706 | int BIO_dump(BIO *b, const char *bytes, int len); | ||
707 | int BIO_dump_indent(BIO *b, const char *bytes, int len, int indent); | ||
705 | #ifndef OPENSSL_NO_FP_API | 708 | #ifndef OPENSSL_NO_FP_API |
706 | int BIO_dump_fp(FILE *fp, const char *s, int len); | 709 | int BIO_dump_fp(FILE *fp, const char *s, int len); |
707 | int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent); | 710 | int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent); |
@@ -717,23 +720,24 @@ struct hostent *BIO_gethostbyname(const char *name); | |||
717 | */ | 720 | */ |
718 | int BIO_sock_error(int sock); | 721 | int BIO_sock_error(int sock); |
719 | int BIO_socket_ioctl(int fd, long type, void *arg); | 722 | int BIO_socket_ioctl(int fd, long type, void *arg); |
720 | int BIO_socket_nbio(int fd,int mode); | 723 | int BIO_socket_nbio(int fd, int mode); |
721 | int BIO_get_port(const char *str, unsigned short *port_ptr); | 724 | int BIO_get_port(const char *str, unsigned short *port_ptr); |
722 | int BIO_get_host_ip(const char *str, unsigned char *ip); | 725 | int BIO_get_host_ip(const char *str, unsigned char *ip); |
723 | int BIO_get_accept_socket(char *host_port,int mode); | 726 | int BIO_get_accept_socket(char *host_port, int mode); |
724 | int BIO_accept(int sock,char **ip_port); | 727 | int BIO_accept(int sock, char **ip_port); |
725 | int BIO_sock_init(void ); | 728 | int BIO_sock_init(void ); |
726 | void BIO_sock_cleanup(void); | 729 | void BIO_sock_cleanup(void); |
727 | int BIO_set_tcp_ndelay(int sock,int turn_on); | 730 | int BIO_set_tcp_ndelay(int sock, int turn_on); |
728 | 731 | ||
729 | BIO *BIO_new_socket(int sock, int close_flag); | 732 | BIO *BIO_new_socket(int sock, int close_flag); |
730 | BIO *BIO_new_dgram(int fd, int close_flag); | 733 | BIO *BIO_new_dgram(int fd, int close_flag); |
731 | #ifndef OPENSSL_NO_SCTP | 734 | #ifndef OPENSSL_NO_SCTP |
732 | BIO *BIO_new_dgram_sctp(int fd, int close_flag); | 735 | BIO *BIO_new_dgram_sctp(int fd, int close_flag); |
733 | int BIO_dgram_is_sctp(BIO *bio); | 736 | int BIO_dgram_is_sctp(BIO *bio); |
734 | int BIO_dgram_sctp_notification_cb(BIO *b, | 737 | int |
735 | void (*handle_notifications)(BIO *bio, void *context, void *buf), | 738 | BIO_dgram_sctp_notification_cb(BIO *b, |
736 | void *context); | 739 | void (*handle_notifications)(BIO *bio, void *context, void *buf), |
740 | void *context); | ||
737 | int BIO_dgram_sctp_wait_for_dry(BIO *b); | 741 | int BIO_dgram_sctp_wait_for_dry(BIO *b); |
738 | int BIO_dgram_sctp_msg_waiting(BIO *b); | 742 | int BIO_dgram_sctp_msg_waiting(BIO *b); |
739 | #endif | 743 | #endif |
@@ -741,8 +745,9 @@ BIO *BIO_new_fd(int fd, int close_flag); | |||
741 | BIO *BIO_new_connect(char *host_port); | 745 | BIO *BIO_new_connect(char *host_port); |
742 | BIO *BIO_new_accept(char *host_port); | 746 | BIO *BIO_new_accept(char *host_port); |
743 | 747 | ||
744 | int BIO_new_bio_pair(BIO **bio1, size_t writebuf1, | 748 | int |
745 | BIO **bio2, size_t writebuf2); | 749 | BIO_new_bio_pair(BIO **bio1, size_t writebuf1, |
750 | BIO **bio2, size_t writebuf2); | ||
746 | /* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints. | 751 | /* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints. |
747 | * Otherwise returns 0 and sets *bio1 and *bio2 to NULL. | 752 | * Otherwise returns 0 and sets *bio1 and *bio2 to NULL. |
748 | * Size 0 uses default value. | 753 | * Size 0 uses default value. |
@@ -757,14 +762,18 @@ void BIO_copy_next_retry(BIO *b); | |||
757 | #else | 762 | #else |
758 | # define __bio_h__attr__(x) | 763 | # define __bio_h__attr__(x) |
759 | #endif | 764 | #endif |
760 | int BIO_printf(BIO *bio, const char *format, ...) | 765 | int |
761 | __bio_h__attr__((__format__(__printf__,2,3))); | 766 | BIO_printf(BIO *bio, const char *format, ...) |
762 | int BIO_vprintf(BIO *bio, const char *format, va_list args) | 767 | __bio_h__attr__((__format__(__printf__, 2, 3))); |
763 | __bio_h__attr__((__format__(__printf__,2,0))); | 768 | int |
764 | int BIO_snprintf(char *buf, size_t n, const char *format, ...) | 769 | BIO_vprintf(BIO *bio, const char *format, va_list args) |
765 | __bio_h__attr__((__format__(__printf__,3,4))); | 770 | __bio_h__attr__((__format__(__printf__, 2, 0))); |
766 | int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) | 771 | int |
767 | __bio_h__attr__((__format__(__printf__,3,0))); | 772 | BIO_snprintf(char *buf, size_t n, const char *format, ...) |
773 | __bio_h__attr__((__format__(__printf__, 3, 4))); | ||
774 | int | ||
775 | BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) | ||
776 | __bio_h__attr__((__format__(__printf__, 3, 0))); | ||
768 | #undef __bio_h__attr__ | 777 | #undef __bio_h__attr__ |
769 | 778 | ||
770 | /* BEGIN ERROR CODES */ | 779 | /* BEGIN ERROR CODES */ |
diff --git a/src/lib/libssl/src/crypto/bio/bio_cb.c b/src/lib/libssl/src/crypto/bio/bio_cb.c index 78c8974ab4..3e110f3751 100644 --- a/src/lib/libssl/src/crypto/bio/bio_cb.c +++ b/src/lib/libssl/src/crypto/bio/bio_cb.c | |||
@@ -63,81 +63,85 @@ | |||
63 | #include <openssl/bio.h> | 63 | #include <openssl/bio.h> |
64 | #include <openssl/err.h> | 64 | #include <openssl/err.h> |
65 | 65 | ||
66 | long BIO_debug_callback(BIO *bio, int cmd, const char *argp, | 66 | long |
67 | int argi, long argl, long ret) | 67 | BIO_debug_callback(BIO *bio, int cmd, const char *argp, int argi, long argl, |
68 | { | 68 | long ret) |
69 | { | ||
69 | BIO *b; | 70 | BIO *b; |
70 | char buf[256]; | 71 | char buf[256]; |
71 | char *p; | 72 | char *p; |
72 | long r=1; | 73 | long r = 1; |
73 | size_t p_maxlen; | 74 | size_t p_maxlen; |
74 | 75 | ||
75 | if (BIO_CB_RETURN & cmd) | 76 | if (BIO_CB_RETURN & cmd) |
76 | r=ret; | 77 | r = ret; |
77 | 78 | ||
78 | (void) snprintf(buf,sizeof buf,"BIO[%08lX]:",(unsigned long)bio); | 79 | (void) snprintf(buf, sizeof buf, "BIO[%08lX]:", (unsigned long)bio); |
79 | p= &(buf[14]); | 80 | p = &(buf[14]); |
80 | p_maxlen = sizeof buf - 14; | 81 | p_maxlen = sizeof buf - 14; |
81 | switch (cmd) | 82 | switch (cmd) { |
82 | { | ||
83 | case BIO_CB_FREE: | 83 | case BIO_CB_FREE: |
84 | (void) snprintf(p,p_maxlen,"Free - %s\n",bio->method->name); | 84 | (void) snprintf(p, p_maxlen, "Free - %s\n", bio->method->name); |
85 | break; | 85 | break; |
86 | case BIO_CB_READ: | 86 | case BIO_CB_READ: |
87 | if (bio->method->type & BIO_TYPE_DESCRIPTOR) | 87 | if (bio->method->type & BIO_TYPE_DESCRIPTOR) |
88 | (void) snprintf(p,p_maxlen,"read(%d,%lu) - %s fd=%d\n", | 88 | (void) snprintf(p, p_maxlen, |
89 | bio->num,(unsigned long)argi, | 89 | "read(%d,%lu) - %s fd=%d\n", |
90 | bio->method->name,bio->num); | 90 | bio->num,(unsigned long)argi, |
91 | bio->method->name, bio->num); | ||
91 | else | 92 | else |
92 | (void) snprintf(p,p_maxlen,"read(%d,%lu) - %s\n", | 93 | (void) snprintf(p, p_maxlen, "read(%d,%lu) - %s\n", |
93 | bio->num,(unsigned long)argi, | 94 | bio->num, (unsigned long)argi, bio->method->name); |
94 | bio->method->name); | ||
95 | break; | 95 | break; |
96 | case BIO_CB_WRITE: | 96 | case BIO_CB_WRITE: |
97 | if (bio->method->type & BIO_TYPE_DESCRIPTOR) | 97 | if (bio->method->type & BIO_TYPE_DESCRIPTOR) |
98 | (void) snprintf(p,p_maxlen,"write(%d,%lu) - %s fd=%d\n", | 98 | (void) snprintf(p, p_maxlen, |
99 | bio->num,(unsigned long)argi, | 99 | "write(%d,%lu) - %s fd=%d\n", |
100 | bio->method->name,bio->num); | 100 | bio->num, (unsigned long)argi, |
101 | bio->method->name, bio->num); | ||
101 | else | 102 | else |
102 | (void) snprintf(p,p_maxlen,"write(%d,%lu) - %s\n", | 103 | (void) snprintf(p, p_maxlen, "write(%d,%lu) - %s\n", |
103 | bio->num,(unsigned long)argi, | 104 | bio->num, (unsigned long)argi, bio->method->name); |
104 | bio->method->name); | ||
105 | break; | 105 | break; |
106 | case BIO_CB_PUTS: | 106 | case BIO_CB_PUTS: |
107 | (void) snprintf(p,p_maxlen,"puts() - %s\n",bio->method->name); | 107 | (void) snprintf(p, p_maxlen, |
108 | "puts() - %s\n", bio->method->name); | ||
108 | break; | 109 | break; |
109 | case BIO_CB_GETS: | 110 | case BIO_CB_GETS: |
110 | (void) snprintf(p,p_maxlen,"gets(%lu) - %s\n",(unsigned long)argi,bio->method->name); | 111 | (void) snprintf(p, p_maxlen, "gets(%lu) - %s\n", |
112 | (unsigned long)argi, bio->method->name); | ||
111 | break; | 113 | break; |
112 | case BIO_CB_CTRL: | 114 | case BIO_CB_CTRL: |
113 | (void) snprintf(p,p_maxlen,"ctrl(%lu) - %s\n",(unsigned long)argi,bio->method->name); | 115 | (void) snprintf(p, p_maxlen, "ctrl(%lu) - %s\n", |
116 | (unsigned long)argi, bio->method->name); | ||
114 | break; | 117 | break; |
115 | case BIO_CB_RETURN|BIO_CB_READ: | 118 | case BIO_CB_RETURN|BIO_CB_READ: |
116 | (void) snprintf(p,p_maxlen,"read return %ld\n",ret); | 119 | (void) snprintf(p, p_maxlen, "read return %ld\n", ret); |
117 | break; | 120 | break; |
118 | case BIO_CB_RETURN|BIO_CB_WRITE: | 121 | case BIO_CB_RETURN|BIO_CB_WRITE: |
119 | (void) snprintf(p,p_maxlen,"write return %ld\n",ret); | 122 | (void) snprintf(p, p_maxlen, "write return %ld\n", ret); |
120 | break; | 123 | break; |
121 | case BIO_CB_RETURN|BIO_CB_GETS: | 124 | case BIO_CB_RETURN|BIO_CB_GETS: |
122 | (void) snprintf(p,p_maxlen,"gets return %ld\n",ret); | 125 | (void) snprintf(p, p_maxlen, "gets return %ld\n", ret); |
123 | break; | 126 | break; |
124 | case BIO_CB_RETURN|BIO_CB_PUTS: | 127 | case BIO_CB_RETURN|BIO_CB_PUTS: |
125 | (void) snprintf(p,p_maxlen,"puts return %ld\n",ret); | 128 | (void) snprintf(p, p_maxlen, "puts return %ld\n", ret); |
126 | break; | 129 | break; |
127 | case BIO_CB_RETURN|BIO_CB_CTRL: | 130 | case BIO_CB_RETURN|BIO_CB_CTRL: |
128 | (void) snprintf(p,p_maxlen,"ctrl return %ld\n",ret); | 131 | (void) snprintf(p, p_maxlen, "ctrl return %ld\n", ret); |
129 | break; | 132 | break; |
130 | default: | 133 | default: |
131 | (void) snprintf(p,p_maxlen,"bio callback - unknown type (%d)\n",cmd); | 134 | (void) snprintf(p, p_maxlen, |
135 | "bio callback - unknown type (%d)\n", cmd); | ||
132 | break; | 136 | break; |
133 | } | 137 | } |
134 | 138 | ||
135 | b=(BIO *)bio->cb_arg; | 139 | b = (BIO *)bio->cb_arg; |
136 | if (b != NULL) | 140 | if (b != NULL) |
137 | BIO_write(b,buf,strlen(buf)); | 141 | BIO_write(b, buf, strlen(buf)); |
138 | #if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16) | 142 | #if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16) |
139 | else | 143 | else |
140 | fputs(buf,stderr); | 144 | fputs(buf, stderr); |
141 | #endif | 145 | #endif |
142 | return(r); | 146 | return (r); |
143 | } | 147 | } |
diff --git a/src/lib/libssl/src/crypto/bio/bio_err.c b/src/lib/libssl/src/crypto/bio/bio_err.c index 0dbfbd80d3..86e9a3082b 100644 --- a/src/lib/libssl/src/crypto/bio/bio_err.c +++ b/src/lib/libssl/src/crypto/bio/bio_err.c | |||
@@ -68,88 +68,85 @@ | |||
68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_BIO,func,0) | 68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_BIO,func,0) |
69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_BIO,0,reason) | 69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_BIO,0,reason) |
70 | 70 | ||
71 | static ERR_STRING_DATA BIO_str_functs[]= | 71 | static ERR_STRING_DATA BIO_str_functs[]= { |
72 | { | 72 | {ERR_FUNC(BIO_F_ACPT_STATE), "ACPT_STATE"}, |
73 | {ERR_FUNC(BIO_F_ACPT_STATE), "ACPT_STATE"}, | 73 | {ERR_FUNC(BIO_F_BIO_ACCEPT), "BIO_accept"}, |
74 | {ERR_FUNC(BIO_F_BIO_ACCEPT), "BIO_accept"}, | 74 | {ERR_FUNC(BIO_F_BIO_BER_GET_HEADER), "BIO_BER_GET_HEADER"}, |
75 | {ERR_FUNC(BIO_F_BIO_BER_GET_HEADER), "BIO_BER_GET_HEADER"}, | 75 | {ERR_FUNC(BIO_F_BIO_CALLBACK_CTRL), "BIO_callback_ctrl"}, |
76 | {ERR_FUNC(BIO_F_BIO_CALLBACK_CTRL), "BIO_callback_ctrl"}, | 76 | {ERR_FUNC(BIO_F_BIO_CTRL), "BIO_ctrl"}, |
77 | {ERR_FUNC(BIO_F_BIO_CTRL), "BIO_ctrl"}, | 77 | {ERR_FUNC(BIO_F_BIO_GETHOSTBYNAME), "BIO_gethostbyname"}, |
78 | {ERR_FUNC(BIO_F_BIO_GETHOSTBYNAME), "BIO_gethostbyname"}, | 78 | {ERR_FUNC(BIO_F_BIO_GETS), "BIO_gets"}, |
79 | {ERR_FUNC(BIO_F_BIO_GETS), "BIO_gets"}, | 79 | {ERR_FUNC(BIO_F_BIO_GET_ACCEPT_SOCKET), "BIO_get_accept_socket"}, |
80 | {ERR_FUNC(BIO_F_BIO_GET_ACCEPT_SOCKET), "BIO_get_accept_socket"}, | 80 | {ERR_FUNC(BIO_F_BIO_GET_HOST_IP), "BIO_get_host_ip"}, |
81 | {ERR_FUNC(BIO_F_BIO_GET_HOST_IP), "BIO_get_host_ip"}, | 81 | {ERR_FUNC(BIO_F_BIO_GET_PORT), "BIO_get_port"}, |
82 | {ERR_FUNC(BIO_F_BIO_GET_PORT), "BIO_get_port"}, | 82 | {ERR_FUNC(BIO_F_BIO_MAKE_PAIR), "BIO_MAKE_PAIR"}, |
83 | {ERR_FUNC(BIO_F_BIO_MAKE_PAIR), "BIO_MAKE_PAIR"}, | 83 | {ERR_FUNC(BIO_F_BIO_NEW), "BIO_new"}, |
84 | {ERR_FUNC(BIO_F_BIO_NEW), "BIO_new"}, | 84 | {ERR_FUNC(BIO_F_BIO_NEW_FILE), "BIO_new_file"}, |
85 | {ERR_FUNC(BIO_F_BIO_NEW_FILE), "BIO_new_file"}, | 85 | {ERR_FUNC(BIO_F_BIO_NEW_MEM_BUF), "BIO_new_mem_buf"}, |
86 | {ERR_FUNC(BIO_F_BIO_NEW_MEM_BUF), "BIO_new_mem_buf"}, | 86 | {ERR_FUNC(BIO_F_BIO_NREAD), "BIO_nread"}, |
87 | {ERR_FUNC(BIO_F_BIO_NREAD), "BIO_nread"}, | 87 | {ERR_FUNC(BIO_F_BIO_NREAD0), "BIO_nread0"}, |
88 | {ERR_FUNC(BIO_F_BIO_NREAD0), "BIO_nread0"}, | 88 | {ERR_FUNC(BIO_F_BIO_NWRITE), "BIO_nwrite"}, |
89 | {ERR_FUNC(BIO_F_BIO_NWRITE), "BIO_nwrite"}, | 89 | {ERR_FUNC(BIO_F_BIO_NWRITE0), "BIO_nwrite0"}, |
90 | {ERR_FUNC(BIO_F_BIO_NWRITE0), "BIO_nwrite0"}, | 90 | {ERR_FUNC(BIO_F_BIO_PUTS), "BIO_puts"}, |
91 | {ERR_FUNC(BIO_F_BIO_PUTS), "BIO_puts"}, | 91 | {ERR_FUNC(BIO_F_BIO_READ), "BIO_read"}, |
92 | {ERR_FUNC(BIO_F_BIO_READ), "BIO_read"}, | 92 | {ERR_FUNC(BIO_F_BIO_SOCK_INIT), "BIO_sock_init"}, |
93 | {ERR_FUNC(BIO_F_BIO_SOCK_INIT), "BIO_sock_init"}, | 93 | {ERR_FUNC(BIO_F_BIO_WRITE), "BIO_write"}, |
94 | {ERR_FUNC(BIO_F_BIO_WRITE), "BIO_write"}, | 94 | {ERR_FUNC(BIO_F_BUFFER_CTRL), "BUFFER_CTRL"}, |
95 | {ERR_FUNC(BIO_F_BUFFER_CTRL), "BUFFER_CTRL"}, | 95 | {ERR_FUNC(BIO_F_CONN_CTRL), "CONN_CTRL"}, |
96 | {ERR_FUNC(BIO_F_CONN_CTRL), "CONN_CTRL"}, | 96 | {ERR_FUNC(BIO_F_CONN_STATE), "CONN_STATE"}, |
97 | {ERR_FUNC(BIO_F_CONN_STATE), "CONN_STATE"}, | 97 | {ERR_FUNC(BIO_F_DGRAM_SCTP_READ), "DGRAM_SCTP_READ"}, |
98 | {ERR_FUNC(BIO_F_DGRAM_SCTP_READ), "DGRAM_SCTP_READ"}, | 98 | {ERR_FUNC(BIO_F_FILE_CTRL), "FILE_CTRL"}, |
99 | {ERR_FUNC(BIO_F_FILE_CTRL), "FILE_CTRL"}, | 99 | {ERR_FUNC(BIO_F_FILE_READ), "FILE_READ"}, |
100 | {ERR_FUNC(BIO_F_FILE_READ), "FILE_READ"}, | 100 | {ERR_FUNC(BIO_F_LINEBUFFER_CTRL), "LINEBUFFER_CTRL"}, |
101 | {ERR_FUNC(BIO_F_LINEBUFFER_CTRL), "LINEBUFFER_CTRL"}, | 101 | {ERR_FUNC(BIO_F_MEM_READ), "MEM_READ"}, |
102 | {ERR_FUNC(BIO_F_MEM_READ), "MEM_READ"}, | 102 | {ERR_FUNC(BIO_F_MEM_WRITE), "MEM_WRITE"}, |
103 | {ERR_FUNC(BIO_F_MEM_WRITE), "MEM_WRITE"}, | 103 | {ERR_FUNC(BIO_F_SSL_NEW), "SSL_new"}, |
104 | {ERR_FUNC(BIO_F_SSL_NEW), "SSL_new"}, | 104 | {ERR_FUNC(BIO_F_WSASTARTUP), "WSASTARTUP"}, |
105 | {ERR_FUNC(BIO_F_WSASTARTUP), "WSASTARTUP"}, | 105 | {0, NULL} |
106 | {0,NULL} | 106 | }; |
107 | }; | ||
108 | 107 | ||
109 | static ERR_STRING_DATA BIO_str_reasons[]= | 108 | static ERR_STRING_DATA BIO_str_reasons[]= { |
110 | { | 109 | {ERR_REASON(BIO_R_ACCEPT_ERROR) , "accept error"}, |
111 | {ERR_REASON(BIO_R_ACCEPT_ERROR) ,"accept error"}, | 110 | {ERR_REASON(BIO_R_BAD_FOPEN_MODE) , "bad fopen mode"}, |
112 | {ERR_REASON(BIO_R_BAD_FOPEN_MODE) ,"bad fopen mode"}, | 111 | {ERR_REASON(BIO_R_BAD_HOSTNAME_LOOKUP) , "bad hostname lookup"}, |
113 | {ERR_REASON(BIO_R_BAD_HOSTNAME_LOOKUP) ,"bad hostname lookup"}, | 112 | {ERR_REASON(BIO_R_BROKEN_PIPE) , "broken pipe"}, |
114 | {ERR_REASON(BIO_R_BROKEN_PIPE) ,"broken pipe"}, | 113 | {ERR_REASON(BIO_R_CONNECT_ERROR) , "connect error"}, |
115 | {ERR_REASON(BIO_R_CONNECT_ERROR) ,"connect error"}, | 114 | {ERR_REASON(BIO_R_EOF_ON_MEMORY_BIO) , "EOF on memory BIO"}, |
116 | {ERR_REASON(BIO_R_EOF_ON_MEMORY_BIO) ,"EOF on memory BIO"}, | 115 | {ERR_REASON(BIO_R_ERROR_SETTING_NBIO) , "error setting nbio"}, |
117 | {ERR_REASON(BIO_R_ERROR_SETTING_NBIO) ,"error setting nbio"}, | 116 | {ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET), "error setting nbio on accepted socket"}, |
118 | {ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET),"error setting nbio on accepted socket"}, | 117 | {ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET), "error setting nbio on accept socket"}, |
119 | {ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET),"error setting nbio on accept socket"}, | 118 | {ERR_REASON(BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET), "gethostbyname addr is not af inet"}, |
120 | {ERR_REASON(BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET),"gethostbyname addr is not af inet"}, | 119 | {ERR_REASON(BIO_R_INVALID_ARGUMENT) , "invalid argument"}, |
121 | {ERR_REASON(BIO_R_INVALID_ARGUMENT) ,"invalid argument"}, | 120 | {ERR_REASON(BIO_R_INVALID_IP_ADDRESS) , "invalid ip address"}, |
122 | {ERR_REASON(BIO_R_INVALID_IP_ADDRESS) ,"invalid ip address"}, | 121 | {ERR_REASON(BIO_R_IN_USE) , "in use"}, |
123 | {ERR_REASON(BIO_R_IN_USE) ,"in use"}, | 122 | {ERR_REASON(BIO_R_KEEPALIVE) , "keepalive"}, |
124 | {ERR_REASON(BIO_R_KEEPALIVE) ,"keepalive"}, | 123 | {ERR_REASON(BIO_R_NBIO_CONNECT_ERROR) , "nbio connect error"}, |
125 | {ERR_REASON(BIO_R_NBIO_CONNECT_ERROR) ,"nbio connect error"}, | 124 | {ERR_REASON(BIO_R_NO_ACCEPT_PORT_SPECIFIED), "no accept port specified"}, |
126 | {ERR_REASON(BIO_R_NO_ACCEPT_PORT_SPECIFIED),"no accept port specified"}, | 125 | {ERR_REASON(BIO_R_NO_HOSTNAME_SPECIFIED) , "no hostname specified"}, |
127 | {ERR_REASON(BIO_R_NO_HOSTNAME_SPECIFIED) ,"no hostname specified"}, | 126 | {ERR_REASON(BIO_R_NO_PORT_DEFINED) , "no port defined"}, |
128 | {ERR_REASON(BIO_R_NO_PORT_DEFINED) ,"no port defined"}, | 127 | {ERR_REASON(BIO_R_NO_PORT_SPECIFIED) , "no port specified"}, |
129 | {ERR_REASON(BIO_R_NO_PORT_SPECIFIED) ,"no port specified"}, | 128 | {ERR_REASON(BIO_R_NO_SUCH_FILE) , "no such file"}, |
130 | {ERR_REASON(BIO_R_NO_SUCH_FILE) ,"no such file"}, | 129 | {ERR_REASON(BIO_R_NULL_PARAMETER) , "null parameter"}, |
131 | {ERR_REASON(BIO_R_NULL_PARAMETER) ,"null parameter"}, | 130 | {ERR_REASON(BIO_R_TAG_MISMATCH) , "tag mismatch"}, |
132 | {ERR_REASON(BIO_R_TAG_MISMATCH) ,"tag mismatch"}, | 131 | {ERR_REASON(BIO_R_UNABLE_TO_BIND_SOCKET) , "unable to bind socket"}, |
133 | {ERR_REASON(BIO_R_UNABLE_TO_BIND_SOCKET) ,"unable to bind socket"}, | 132 | {ERR_REASON(BIO_R_UNABLE_TO_CREATE_SOCKET), "unable to create socket"}, |
134 | {ERR_REASON(BIO_R_UNABLE_TO_CREATE_SOCKET),"unable to create socket"}, | 133 | {ERR_REASON(BIO_R_UNABLE_TO_LISTEN_SOCKET), "unable to listen socket"}, |
135 | {ERR_REASON(BIO_R_UNABLE_TO_LISTEN_SOCKET),"unable to listen socket"}, | 134 | {ERR_REASON(BIO_R_UNINITIALIZED) , "uninitialized"}, |
136 | {ERR_REASON(BIO_R_UNINITIALIZED) ,"uninitialized"}, | 135 | {ERR_REASON(BIO_R_UNSUPPORTED_METHOD) , "unsupported method"}, |
137 | {ERR_REASON(BIO_R_UNSUPPORTED_METHOD) ,"unsupported method"}, | 136 | {ERR_REASON(BIO_R_WRITE_TO_READ_ONLY_BIO), "write to read only BIO"}, |
138 | {ERR_REASON(BIO_R_WRITE_TO_READ_ONLY_BIO),"write to read only BIO"}, | 137 | {ERR_REASON(BIO_R_WSASTARTUP) , "WSAStartup"}, |
139 | {ERR_REASON(BIO_R_WSASTARTUP) ,"WSAStartup"}, | 138 | {0, NULL} |
140 | {0,NULL} | 139 | }; |
141 | }; | ||
142 | 140 | ||
143 | #endif | 141 | #endif |
144 | 142 | ||
145 | void ERR_load_BIO_strings(void) | 143 | void |
146 | { | 144 | ERR_load_BIO_strings(void) |
145 | { | ||
147 | #ifndef OPENSSL_NO_ERR | 146 | #ifndef OPENSSL_NO_ERR |
148 | 147 | if (ERR_func_error_string(BIO_str_functs[0].error) == NULL) { | |
149 | if (ERR_func_error_string(BIO_str_functs[0].error) == NULL) | 148 | ERR_load_strings(0, BIO_str_functs); |
150 | { | 149 | ERR_load_strings(0, BIO_str_reasons); |
151 | ERR_load_strings(0,BIO_str_functs); | ||
152 | ERR_load_strings(0,BIO_str_reasons); | ||
153 | } | ||
154 | #endif | ||
155 | } | 150 | } |
151 | #endif | ||
152 | } | ||
diff --git a/src/lib/libssl/src/crypto/bio/bio_lib.c b/src/lib/libssl/src/crypto/bio/bio_lib.c index 9c9646afa8..9e8fb7913a 100644 --- a/src/lib/libssl/src/crypto/bio/bio_lib.c +++ b/src/lib/libssl/src/crypto/bio/bio_lib.c | |||
@@ -63,539 +63,571 @@ | |||
63 | #include <openssl/bio.h> | 63 | #include <openssl/bio.h> |
64 | #include <openssl/stack.h> | 64 | #include <openssl/stack.h> |
65 | 65 | ||
66 | BIO *BIO_new(BIO_METHOD *method) | 66 | BIO |
67 | { | 67 | *BIO_new(BIO_METHOD *method) |
68 | BIO *ret=NULL; | 68 | { |
69 | 69 | BIO *ret = NULL; | |
70 | ret=(BIO *)OPENSSL_malloc(sizeof(BIO)); | 70 | |
71 | if (ret == NULL) | 71 | ret = (BIO *)OPENSSL_malloc(sizeof(BIO)); |
72 | { | 72 | if (ret == NULL) { |
73 | BIOerr(BIO_F_BIO_NEW,ERR_R_MALLOC_FAILURE); | 73 | BIOerr(BIO_F_BIO_NEW, ERR_R_MALLOC_FAILURE); |
74 | return(NULL); | 74 | return (NULL); |
75 | } | 75 | } |
76 | if (!BIO_set(ret,method)) | 76 | if (!BIO_set(ret, method)) { |
77 | { | ||
78 | OPENSSL_free(ret); | 77 | OPENSSL_free(ret); |
79 | ret=NULL; | 78 | ret = NULL; |
80 | } | ||
81 | return(ret); | ||
82 | } | 79 | } |
80 | return (ret); | ||
81 | } | ||
83 | 82 | ||
84 | int BIO_set(BIO *bio, BIO_METHOD *method) | 83 | int |
85 | { | 84 | BIO_set(BIO *bio, BIO_METHOD *method) |
86 | bio->method=method; | 85 | { |
87 | bio->callback=NULL; | 86 | bio->method = method; |
88 | bio->cb_arg=NULL; | 87 | bio->callback = NULL; |
89 | bio->init=0; | 88 | bio->cb_arg = NULL; |
90 | bio->shutdown=1; | 89 | bio->init = 0; |
91 | bio->flags=0; | 90 | bio->shutdown = 1; |
92 | bio->retry_reason=0; | 91 | bio->flags = 0; |
93 | bio->num=0; | 92 | bio->retry_reason = 0; |
94 | bio->ptr=NULL; | 93 | bio->num = 0; |
95 | bio->prev_bio=NULL; | 94 | bio->ptr = NULL; |
96 | bio->next_bio=NULL; | 95 | bio->prev_bio = NULL; |
97 | bio->references=1; | 96 | bio->next_bio = NULL; |
98 | bio->num_read=0L; | 97 | bio->references = 1; |
99 | bio->num_write=0L; | 98 | bio->num_read = 0L; |
99 | bio->num_write = 0L; | ||
100 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data); | 100 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data); |
101 | if (method->create != NULL) | 101 | if (method->create != NULL) |
102 | if (!method->create(bio)) | 102 | if (!method->create(bio)) { |
103 | { | ||
104 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio, | 103 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio, |
105 | &bio->ex_data); | 104 | &bio->ex_data); |
106 | return(0); | 105 | return (0); |
107 | } | 106 | } |
108 | return(1); | 107 | return (1); |
109 | } | 108 | } |
110 | 109 | ||
111 | int BIO_free(BIO *a) | 110 | int |
112 | { | 111 | BIO_free(BIO *a) |
112 | { | ||
113 | int i; | 113 | int i; |
114 | 114 | ||
115 | if (a == NULL) return(0); | 115 | if (a == NULL) |
116 | return (0); | ||
116 | 117 | ||
117 | i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_BIO); | 118 | i = CRYPTO_add(&a->references, -1, CRYPTO_LOCK_BIO); |
118 | #ifdef REF_PRINT | 119 | #ifdef REF_PRINT |
119 | REF_PRINT("BIO",a); | 120 | REF_PRINT("BIO", a); |
120 | #endif | 121 | #endif |
121 | if (i > 0) return(1); | 122 | if (i > 0) |
123 | return (1); | ||
122 | #ifdef REF_CHECK | 124 | #ifdef REF_CHECK |
123 | if (i < 0) | 125 | if (i < 0) { |
124 | { | 126 | fprintf(stderr, "BIO_free, bad reference count\n"); |
125 | fprintf(stderr,"BIO_free, bad reference count\n"); | ||
126 | abort(); | 127 | abort(); |
127 | } | 128 | } |
128 | #endif | 129 | #endif |
129 | if ((a->callback != NULL) && | 130 | if ((a->callback != NULL) && |
130 | ((i=(int)a->callback(a,BIO_CB_FREE,NULL,0,0L,1L)) <= 0)) | 131 | ((i = (int)a->callback(a, BIO_CB_FREE, NULL, 0, 0L, 1L)) <= 0)) |
131 | return(i); | 132 | return (i); |
132 | 133 | ||
133 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, a, &a->ex_data); | 134 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, a, &a->ex_data); |
134 | 135 | ||
135 | if ((a->method == NULL) || (a->method->destroy == NULL)) return(1); | 136 | if ((a->method == NULL) || (a->method->destroy == NULL)) |
137 | return (1); | ||
136 | a->method->destroy(a); | 138 | a->method->destroy(a); |
137 | OPENSSL_free(a); | 139 | OPENSSL_free(a); |
138 | return(1); | 140 | return (1); |
139 | } | 141 | } |
140 | 142 | ||
141 | void BIO_vfree(BIO *a) | 143 | void |
142 | { BIO_free(a); } | 144 | BIO_vfree(BIO *a) |
145 | { | ||
146 | BIO_free(a); | ||
147 | } | ||
143 | 148 | ||
144 | void BIO_clear_flags(BIO *b, int flags) | 149 | void |
145 | { | 150 | BIO_clear_flags(BIO *b, int flags) |
151 | { | ||
146 | b->flags &= ~flags; | 152 | b->flags &= ~flags; |
147 | } | 153 | } |
148 | 154 | ||
149 | int BIO_test_flags(const BIO *b, int flags) | 155 | int |
150 | { | 156 | BIO_test_flags(const BIO *b, int flags) |
157 | { | ||
151 | return (b->flags & flags); | 158 | return (b->flags & flags); |
152 | } | 159 | } |
153 | 160 | ||
154 | void BIO_set_flags(BIO *b, int flags) | 161 | void |
155 | { | 162 | BIO_set_flags(BIO *b, int flags) |
163 | { | ||
156 | b->flags |= flags; | 164 | b->flags |= flags; |
157 | } | 165 | } |
158 | 166 | ||
159 | long (*BIO_get_callback(const BIO *b))(struct bio_st *,int,const char *,int, long,long) | 167 | long |
160 | { | 168 | (*BIO_get_callback(const BIO *b))(struct bio_st *, int, const char *, int, |
169 | long, long) | ||
170 | { | ||
161 | return b->callback; | 171 | return b->callback; |
162 | } | 172 | } |
163 | 173 | ||
164 | void BIO_set_callback(BIO *b, long (*cb)(struct bio_st *,int,const char *,int, long,long)) | 174 | void |
165 | { | 175 | BIO_set_callback(BIO *b, long (*cb)(struct bio_st *, int, const char *, int, |
176 | long, long)) | ||
177 | { | ||
166 | b->callback = cb; | 178 | b->callback = cb; |
167 | } | 179 | } |
168 | 180 | ||
169 | void BIO_set_callback_arg(BIO *b, char *arg) | 181 | void |
170 | { | 182 | BIO_set_callback_arg(BIO *b, char *arg) |
183 | { | ||
171 | b->cb_arg = arg; | 184 | b->cb_arg = arg; |
172 | } | 185 | } |
173 | 186 | ||
174 | char * BIO_get_callback_arg(const BIO *b) | 187 | char * |
175 | { | 188 | BIO_get_callback_arg(const BIO *b) |
189 | { | ||
176 | return b->cb_arg; | 190 | return b->cb_arg; |
177 | } | 191 | } |
178 | 192 | ||
179 | const char * BIO_method_name(const BIO *b) | 193 | const char * |
180 | { | 194 | BIO_method_name(const BIO *b) |
195 | { | ||
181 | return b->method->name; | 196 | return b->method->name; |
182 | } | 197 | } |
183 | 198 | ||
184 | int BIO_method_type(const BIO *b) | 199 | int |
185 | { | 200 | BIO_method_type(const BIO *b) |
201 | { | ||
186 | return b->method->type; | 202 | return b->method->type; |
187 | } | 203 | } |
188 | |||
189 | 204 | ||
190 | int BIO_read(BIO *b, void *out, int outl) | 205 | int |
191 | { | 206 | BIO_read(BIO *b, void *out, int outl) |
207 | { | ||
192 | int i; | 208 | int i; |
193 | long (*cb)(BIO *,int,const char *,int,long,long); | 209 | long (*cb)(BIO *, int, const char *, int, long, long); |
194 | 210 | ||
195 | if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL)) | 211 | if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL)) { |
196 | { | 212 | BIOerr(BIO_F_BIO_READ, BIO_R_UNSUPPORTED_METHOD); |
197 | BIOerr(BIO_F_BIO_READ,BIO_R_UNSUPPORTED_METHOD); | 213 | return (-2); |
198 | return(-2); | 214 | } |
199 | } | ||
200 | 215 | ||
201 | cb=b->callback; | 216 | cb = b->callback; |
202 | if ((cb != NULL) && | 217 | if ((cb != NULL) && |
203 | ((i=(int)cb(b,BIO_CB_READ,out,outl,0L,1L)) <= 0)) | 218 | ((i = (int)cb(b, BIO_CB_READ, out, outl, 0L, 1L)) <= 0)) |
204 | return(i); | 219 | return (i); |
205 | 220 | ||
206 | if (!b->init) | 221 | if (!b->init) { |
207 | { | 222 | BIOerr(BIO_F_BIO_READ, BIO_R_UNINITIALIZED); |
208 | BIOerr(BIO_F_BIO_READ,BIO_R_UNINITIALIZED); | 223 | return (-2); |
209 | return(-2); | 224 | } |
210 | } | ||
211 | 225 | ||
212 | i=b->method->bread(b,out,outl); | 226 | i = b->method->bread(b, out, outl); |
213 | 227 | ||
214 | if (i > 0) b->num_read+=(unsigned long)i; | 228 | if (i > 0) |
229 | b->num_read += (unsigned long)i; | ||
215 | 230 | ||
216 | if (cb != NULL) | 231 | if (cb != NULL) |
217 | i=(int)cb(b,BIO_CB_READ|BIO_CB_RETURN,out,outl, | 232 | i = (int)cb(b, BIO_CB_READ|BIO_CB_RETURN, out, outl, |
218 | 0L,(long)i); | 233 | 0L, (long)i); |
219 | return(i); | 234 | return (i); |
220 | } | 235 | } |
221 | 236 | ||
222 | int BIO_write(BIO *b, const void *in, int inl) | 237 | int |
223 | { | 238 | BIO_write(BIO *b, const void *in, int inl) |
239 | { | ||
224 | int i; | 240 | int i; |
225 | long (*cb)(BIO *,int,const char *,int,long,long); | 241 | long (*cb)(BIO *, int, const char *, int, long, long); |
226 | 242 | ||
227 | if (b == NULL) | 243 | if (b == NULL) |
228 | return(0); | 244 | return (0); |
229 | 245 | ||
230 | cb=b->callback; | 246 | cb = b->callback; |
231 | if ((b->method == NULL) || (b->method->bwrite == NULL)) | 247 | if ((b->method == NULL) || (b->method->bwrite == NULL)) { |
232 | { | 248 | BIOerr(BIO_F_BIO_WRITE, BIO_R_UNSUPPORTED_METHOD); |
233 | BIOerr(BIO_F_BIO_WRITE,BIO_R_UNSUPPORTED_METHOD); | 249 | return (-2); |
234 | return(-2); | 250 | } |
235 | } | ||
236 | 251 | ||
237 | if ((cb != NULL) && | 252 | if ((cb != NULL) && |
238 | ((i=(int)cb(b,BIO_CB_WRITE,in,inl,0L,1L)) <= 0)) | 253 | ((i = (int)cb(b, BIO_CB_WRITE, in, inl, 0L, 1L)) <= 0)) |
239 | return(i); | 254 | return (i); |
240 | 255 | ||
241 | if (!b->init) | 256 | if (!b->init) { |
242 | { | 257 | BIOerr(BIO_F_BIO_WRITE, BIO_R_UNINITIALIZED); |
243 | BIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITIALIZED); | 258 | return (-2); |
244 | return(-2); | 259 | } |
245 | } | ||
246 | 260 | ||
247 | i=b->method->bwrite(b,in,inl); | 261 | i = b->method->bwrite(b, in, inl); |
248 | 262 | ||
249 | if (i > 0) b->num_write+=(unsigned long)i; | 263 | if (i > 0) |
264 | b->num_write += (unsigned long)i; | ||
250 | 265 | ||
251 | if (cb != NULL) | 266 | if (cb != NULL) |
252 | i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl, | 267 | i = (int)cb(b, BIO_CB_WRITE|BIO_CB_RETURN, in, inl, |
253 | 0L,(long)i); | 268 | 0L, (long)i); |
254 | return(i); | 269 | return (i); |
255 | } | 270 | } |
256 | 271 | ||
257 | int BIO_puts(BIO *b, const char *in) | 272 | int |
258 | { | 273 | BIO_puts(BIO *b, const char *in) |
274 | { | ||
259 | int i; | 275 | int i; |
260 | long (*cb)(BIO *,int,const char *,int,long,long); | 276 | long (*cb)(BIO *, int, const char *, int, long, long); |
261 | 277 | ||
262 | if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) | 278 | if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) { |
263 | { | 279 | BIOerr(BIO_F_BIO_PUTS, BIO_R_UNSUPPORTED_METHOD); |
264 | BIOerr(BIO_F_BIO_PUTS,BIO_R_UNSUPPORTED_METHOD); | 280 | return (-2); |
265 | return(-2); | 281 | } |
266 | } | ||
267 | 282 | ||
268 | cb=b->callback; | 283 | cb = b->callback; |
269 | 284 | ||
270 | if ((cb != NULL) && | 285 | if ((cb != NULL) && |
271 | ((i=(int)cb(b,BIO_CB_PUTS,in,0,0L,1L)) <= 0)) | 286 | ((i = (int)cb(b, BIO_CB_PUTS, in, 0, 0L, 1L)) <= 0)) |
272 | return(i); | 287 | return (i); |
273 | 288 | ||
274 | if (!b->init) | 289 | if (!b->init) { |
275 | { | 290 | BIOerr(BIO_F_BIO_PUTS, BIO_R_UNINITIALIZED); |
276 | BIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITIALIZED); | 291 | return (-2); |
277 | return(-2); | 292 | } |
278 | } | ||
279 | 293 | ||
280 | i=b->method->bputs(b,in); | 294 | i = b->method->bputs(b, in); |
281 | 295 | ||
282 | if (i > 0) b->num_write+=(unsigned long)i; | 296 | if (i > 0) |
297 | b->num_write += (unsigned long)i; | ||
283 | 298 | ||
284 | if (cb != NULL) | 299 | if (cb != NULL) |
285 | i=(int)cb(b,BIO_CB_PUTS|BIO_CB_RETURN,in,0, | 300 | i = (int)cb(b, BIO_CB_PUTS|BIO_CB_RETURN, in, 0, 0L, (long)i); |
286 | 0L,(long)i); | 301 | return (i); |
287 | return(i); | 302 | } |
288 | } | ||
289 | 303 | ||
290 | int BIO_gets(BIO *b, char *in, int inl) | 304 | int |
291 | { | 305 | BIO_gets(BIO *b, char *in, int inl) |
306 | { | ||
292 | int i; | 307 | int i; |
293 | long (*cb)(BIO *,int,const char *,int,long,long); | 308 | long (*cb)(BIO *, int, const char *, int, long, long); |
294 | 309 | ||
295 | if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL)) | 310 | if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL)) { |
296 | { | 311 | BIOerr(BIO_F_BIO_GETS, BIO_R_UNSUPPORTED_METHOD); |
297 | BIOerr(BIO_F_BIO_GETS,BIO_R_UNSUPPORTED_METHOD); | 312 | return (-2); |
298 | return(-2); | 313 | } |
299 | } | ||
300 | 314 | ||
301 | cb=b->callback; | 315 | cb = b->callback; |
302 | 316 | ||
303 | if ((cb != NULL) && | 317 | if ((cb != NULL) && |
304 | ((i=(int)cb(b,BIO_CB_GETS,in,inl,0L,1L)) <= 0)) | 318 | ((i = (int)cb(b, BIO_CB_GETS, in, inl, 0L, 1L)) <= 0)) |
305 | return(i); | 319 | return (i); |
306 | 320 | ||
307 | if (!b->init) | 321 | if (!b->init) { |
308 | { | 322 | BIOerr(BIO_F_BIO_GETS, BIO_R_UNINITIALIZED); |
309 | BIOerr(BIO_F_BIO_GETS,BIO_R_UNINITIALIZED); | 323 | return (-2); |
310 | return(-2); | 324 | } |
311 | } | ||
312 | 325 | ||
313 | i=b->method->bgets(b,in,inl); | 326 | i = b->method->bgets(b, in, inl); |
314 | 327 | ||
315 | if (cb != NULL) | 328 | if (cb != NULL) |
316 | i=(int)cb(b,BIO_CB_GETS|BIO_CB_RETURN,in,inl, | 329 | i = (int)cb(b, BIO_CB_GETS|BIO_CB_RETURN, in, inl, 0L, (long)i); |
317 | 0L,(long)i); | 330 | return (i); |
318 | return(i); | 331 | } |
319 | } | ||
320 | 332 | ||
321 | int BIO_indent(BIO *b,int indent,int max) | 333 | int |
322 | { | 334 | BIO_indent(BIO *b, int indent, int max) |
323 | if(indent < 0) | 335 | { |
324 | indent=0; | 336 | if (indent < 0) |
325 | if(indent > max) | 337 | indent = 0; |
326 | indent=max; | 338 | if (indent > max) |
327 | while(indent--) | 339 | indent = max; |
328 | if(BIO_puts(b," ") != 1) | 340 | while (indent--) |
329 | return 0; | 341 | if (BIO_puts(b, " ") != 1) |
342 | return 0; | ||
330 | return 1; | 343 | return 1; |
331 | } | 344 | } |
332 | 345 | ||
333 | long BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg) | 346 | long |
334 | { | 347 | BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg) |
348 | { | ||
335 | int i; | 349 | int i; |
336 | 350 | ||
337 | i=iarg; | 351 | i = iarg; |
338 | return(BIO_ctrl(b,cmd,larg,(char *)&i)); | 352 | return (BIO_ctrl(b, cmd, larg,(char *)&i)); |
339 | } | 353 | } |
340 | 354 | ||
341 | char *BIO_ptr_ctrl(BIO *b, int cmd, long larg) | 355 | char |
342 | { | 356 | *BIO_ptr_ctrl(BIO *b, int cmd, long larg) |
343 | char *p=NULL; | 357 | { |
358 | char *p = NULL; | ||
344 | 359 | ||
345 | if (BIO_ctrl(b,cmd,larg,(char *)&p) <= 0) | 360 | if (BIO_ctrl(b, cmd, larg,(char *)&p) <= 0) |
346 | return(NULL); | 361 | return (NULL); |
347 | else | 362 | else |
348 | return(p); | 363 | return (p); |
349 | } | 364 | } |
350 | 365 | ||
351 | long BIO_ctrl(BIO *b, int cmd, long larg, void *parg) | 366 | long |
352 | { | 367 | BIO_ctrl(BIO *b, int cmd, long larg, void *parg) |
368 | { | ||
353 | long ret; | 369 | long ret; |
354 | long (*cb)(BIO *,int,const char *,int,long,long); | 370 | long (*cb)(BIO *, int, const char *, int, long, long); |
355 | 371 | ||
356 | if (b == NULL) return(0); | 372 | if (b == NULL) |
373 | return (0); | ||
357 | 374 | ||
358 | if ((b->method == NULL) || (b->method->ctrl == NULL)) | 375 | if ((b->method == NULL) || (b->method->ctrl == NULL)) { |
359 | { | 376 | BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD); |
360 | BIOerr(BIO_F_BIO_CTRL,BIO_R_UNSUPPORTED_METHOD); | 377 | return (-2); |
361 | return(-2); | 378 | } |
362 | } | ||
363 | 379 | ||
364 | cb=b->callback; | 380 | cb = b->callback; |
365 | 381 | ||
366 | if ((cb != NULL) && | 382 | if ((cb != NULL) && |
367 | ((ret=cb(b,BIO_CB_CTRL,parg,cmd,larg,1L)) <= 0)) | 383 | ((ret = cb(b, BIO_CB_CTRL, parg, cmd, larg, 1L)) <= 0)) |
368 | return(ret); | 384 | return (ret); |
369 | 385 | ||
370 | ret=b->method->ctrl(b,cmd,larg,parg); | 386 | ret = b->method->ctrl(b, cmd, larg, parg); |
371 | 387 | ||
372 | if (cb != NULL) | 388 | if (cb != NULL) |
373 | ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,parg,cmd, | 389 | ret = cb(b, BIO_CB_CTRL|BIO_CB_RETURN, parg, cmd, larg, ret); |
374 | larg,ret); | 390 | return (ret); |
375 | return(ret); | 391 | } |
376 | } | ||
377 | 392 | ||
378 | long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long)) | 393 | long |
379 | { | 394 | BIO_callback_ctrl(BIO *b, int cmd, |
395 | void (*fp)(struct bio_st *, int, const char *, int, long, long)) | ||
396 | { | ||
380 | long ret; | 397 | long ret; |
381 | long (*cb)(BIO *,int,const char *,int,long,long); | 398 | long (*cb)(BIO *, int, const char *, int, long, long); |
382 | 399 | ||
383 | if (b == NULL) return(0); | 400 | if (b == NULL) |
401 | return (0); | ||
384 | 402 | ||
385 | if ((b->method == NULL) || (b->method->callback_ctrl == NULL)) | 403 | if ((b->method == NULL) || (b->method->callback_ctrl == NULL)) { |
386 | { | 404 | BIOerr(BIO_F_BIO_CALLBACK_CTRL, BIO_R_UNSUPPORTED_METHOD); |
387 | BIOerr(BIO_F_BIO_CALLBACK_CTRL,BIO_R_UNSUPPORTED_METHOD); | 405 | return (-2); |
388 | return(-2); | 406 | } |
389 | } | ||
390 | 407 | ||
391 | cb=b->callback; | 408 | cb = b->callback; |
392 | 409 | ||
393 | if ((cb != NULL) && | 410 | if ((cb != NULL) && |
394 | ((ret=cb(b,BIO_CB_CTRL,(void *)&fp,cmd,0,1L)) <= 0)) | 411 | ((ret = cb(b, BIO_CB_CTRL,(void *)&fp, cmd, 0, 1L)) <= 0)) |
395 | return(ret); | 412 | return (ret); |
396 | 413 | ||
397 | ret=b->method->callback_ctrl(b,cmd,fp); | 414 | ret = b->method->callback_ctrl(b, cmd, fp); |
398 | 415 | ||
399 | if (cb != NULL) | 416 | if (cb != NULL) |
400 | ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,(void *)&fp,cmd, | 417 | ret = cb(b, BIO_CB_CTRL|BIO_CB_RETURN,(void *)&fp, cmd, 0, ret); |
401 | 0,ret); | 418 | return (ret); |
402 | return(ret); | 419 | } |
403 | } | ||
404 | 420 | ||
405 | /* It is unfortunate to duplicate in functions what the BIO_(w)pending macros | 421 | /* It is unfortunate to duplicate in functions what the BIO_(w)pending macros |
406 | * do; but those macros have inappropriate return type, and for interfacing | 422 | * do; but those macros have inappropriate return type, and for interfacing |
407 | * from other programming languages, C macros aren't much of a help anyway. */ | 423 | * from other programming languages, C macros aren't much of a help anyway. */ |
408 | size_t BIO_ctrl_pending(BIO *bio) | 424 | size_t |
409 | { | 425 | BIO_ctrl_pending(BIO *bio) |
426 | { | ||
410 | return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL); | 427 | return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL); |
411 | } | 428 | } |
412 | 429 | ||
413 | size_t BIO_ctrl_wpending(BIO *bio) | 430 | size_t |
414 | { | 431 | BIO_ctrl_wpending(BIO *bio) |
432 | { | ||
415 | return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL); | 433 | return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL); |
416 | } | 434 | } |
417 | 435 | ||
418 | 436 | ||
419 | /* put the 'bio' on the end of b's list of operators */ | 437 | /* put the 'bio' on the end of b's list of operators */ |
420 | BIO *BIO_push(BIO *b, BIO *bio) | 438 | BIO |
421 | { | 439 | *BIO_push(BIO *b, BIO *bio) |
440 | { | ||
422 | BIO *lb; | 441 | BIO *lb; |
423 | 442 | ||
424 | if (b == NULL) return(bio); | 443 | if (b == NULL) |
425 | lb=b; | 444 | return (bio); |
445 | lb = b; | ||
426 | while (lb->next_bio != NULL) | 446 | while (lb->next_bio != NULL) |
427 | lb=lb->next_bio; | 447 | lb = lb->next_bio; |
428 | lb->next_bio=bio; | 448 | lb->next_bio = bio; |
429 | if (bio != NULL) | 449 | if (bio != NULL) |
430 | bio->prev_bio=lb; | 450 | bio->prev_bio = lb; |
431 | /* called to do internal processing */ | 451 | /* called to do internal processing */ |
432 | BIO_ctrl(b,BIO_CTRL_PUSH,0,lb); | 452 | BIO_ctrl(b, BIO_CTRL_PUSH, 0, lb); |
433 | return(b); | 453 | return (b); |
434 | } | 454 | } |
435 | 455 | ||
436 | /* Remove the first and return the rest */ | 456 | /* Remove the first and return the rest */ |
437 | BIO *BIO_pop(BIO *b) | 457 | BIO |
438 | { | 458 | *BIO_pop(BIO *b) |
459 | { | ||
439 | BIO *ret; | 460 | BIO *ret; |
440 | 461 | ||
441 | if (b == NULL) return(NULL); | 462 | if (b == NULL) |
442 | ret=b->next_bio; | 463 | return (NULL); |
464 | ret = b->next_bio; | ||
443 | 465 | ||
444 | BIO_ctrl(b,BIO_CTRL_POP,0,b); | 466 | BIO_ctrl(b, BIO_CTRL_POP, 0, b); |
445 | 467 | ||
446 | if (b->prev_bio != NULL) | 468 | if (b->prev_bio != NULL) |
447 | b->prev_bio->next_bio=b->next_bio; | 469 | b->prev_bio->next_bio = b->next_bio; |
448 | if (b->next_bio != NULL) | 470 | if (b->next_bio != NULL) |
449 | b->next_bio->prev_bio=b->prev_bio; | 471 | b->next_bio->prev_bio = b->prev_bio; |
450 | 472 | ||
451 | b->next_bio=NULL; | 473 | b->next_bio = NULL; |
452 | b->prev_bio=NULL; | 474 | b->prev_bio = NULL; |
453 | return(ret); | 475 | return (ret); |
454 | } | 476 | } |
455 | 477 | ||
456 | BIO *BIO_get_retry_BIO(BIO *bio, int *reason) | 478 | BIO |
457 | { | 479 | *BIO_get_retry_BIO(BIO *bio, int *reason) |
458 | BIO *b,*last; | 480 | { |
481 | BIO *b, *last; | ||
459 | 482 | ||
460 | b=last=bio; | 483 | b = last = bio; |
461 | for (;;) | 484 | for (;;) { |
462 | { | ||
463 | if (!BIO_should_retry(b)) break; | 485 | if (!BIO_should_retry(b)) break; |
464 | last=b; | 486 | last = b; |
465 | b=b->next_bio; | 487 | b = b->next_bio; |
466 | if (b == NULL) break; | 488 | if (b == NULL) |
467 | } | 489 | break; |
468 | if (reason != NULL) *reason=last->retry_reason; | 490 | } |
469 | return(last); | 491 | if (reason != NULL) |
470 | } | 492 | *reason = last->retry_reason; |
493 | return (last); | ||
494 | } | ||
471 | 495 | ||
472 | int BIO_get_retry_reason(BIO *bio) | 496 | int |
473 | { | 497 | BIO_get_retry_reason(BIO *bio) |
474 | return(bio->retry_reason); | 498 | { |
475 | } | 499 | return (bio->retry_reason); |
500 | } | ||
476 | 501 | ||
477 | BIO *BIO_find_type(BIO *bio, int type) | 502 | BIO |
478 | { | 503 | *BIO_find_type(BIO *bio, int type) |
479 | int mt,mask; | 504 | { |
480 | 505 | int mt, mask; | |
481 | if(!bio) return NULL; | 506 | |
482 | mask=type&0xff; | 507 | if (!bio) |
483 | do { | 508 | return NULL; |
484 | if (bio->method != NULL) | 509 | mask = type & 0xff; |
485 | { | 510 | do { |
486 | mt=bio->method->type; | 511 | if (bio->method != NULL) { |
487 | 512 | mt = bio->method->type; | |
488 | if (!mask) | 513 | if (!mask) { |
489 | { | 514 | if (mt & type) |
490 | if (mt & type) return(bio); | 515 | return (bio); |
491 | } | 516 | } else if (mt == type) |
492 | else if (mt == type) | 517 | return (bio); |
493 | return(bio); | 518 | } |
494 | } | 519 | bio = bio->next_bio; |
495 | bio=bio->next_bio; | 520 | } while (bio != NULL); |
496 | } while (bio != NULL); | 521 | return (NULL); |
497 | return(NULL); | 522 | } |
498 | } | ||
499 | 523 | ||
500 | BIO *BIO_next(BIO *b) | 524 | BIO |
501 | { | 525 | *BIO_next(BIO *b) |
502 | if(!b) return NULL; | 526 | { |
527 | if (!b) | ||
528 | return NULL; | ||
503 | return b->next_bio; | 529 | return b->next_bio; |
504 | } | 530 | } |
505 | 531 | ||
506 | void BIO_free_all(BIO *bio) | 532 | void |
507 | { | 533 | BIO_free_all(BIO *bio) |
534 | { | ||
508 | BIO *b; | 535 | BIO *b; |
509 | int ref; | 536 | int ref; |
510 | 537 | ||
511 | while (bio != NULL) | 538 | while (bio != NULL) { |
512 | { | 539 | b = bio; |
513 | b=bio; | 540 | ref = b->references; |
514 | ref=b->references; | 541 | bio = bio->next_bio; |
515 | bio=bio->next_bio; | ||
516 | BIO_free(b); | 542 | BIO_free(b); |
517 | /* Since ref count > 1, don't free anyone else. */ | 543 | /* Since ref count > 1, don't free anyone else. */ |
518 | if (ref > 1) break; | 544 | if (ref > 1) |
519 | } | 545 | break; |
520 | } | 546 | } |
547 | } | ||
521 | 548 | ||
522 | BIO *BIO_dup_chain(BIO *in) | 549 | BIO |
523 | { | 550 | *BIO_dup_chain(BIO *in) |
524 | BIO *ret=NULL,*eoc=NULL,*bio,*new_bio; | 551 | { |
552 | BIO *ret = NULL, *eoc = NULL, *bio, *new_bio; | ||
525 | 553 | ||
526 | for (bio=in; bio != NULL; bio=bio->next_bio) | 554 | for (bio = in; bio != NULL; bio = bio->next_bio) { |
527 | { | 555 | if ((new_bio = BIO_new(bio->method)) == NULL) goto err; |
528 | if ((new_bio=BIO_new(bio->method)) == NULL) goto err; | 556 | new_bio->callback = bio->callback; |
529 | new_bio->callback=bio->callback; | 557 | new_bio->cb_arg = bio->cb_arg; |
530 | new_bio->cb_arg=bio->cb_arg; | 558 | new_bio->init = bio->init; |
531 | new_bio->init=bio->init; | 559 | new_bio->shutdown = bio->shutdown; |
532 | new_bio->shutdown=bio->shutdown; | 560 | new_bio->flags = bio->flags; |
533 | new_bio->flags=bio->flags; | ||
534 | 561 | ||
535 | /* This will let SSL_s_sock() work with stdin/stdout */ | 562 | /* This will let SSL_s_sock() work with stdin/stdout */ |
536 | new_bio->num=bio->num; | 563 | new_bio->num = bio->num; |
537 | 564 | ||
538 | if (!BIO_dup_state(bio,(char *)new_bio)) | 565 | if (!BIO_dup_state(bio,(char *)new_bio)) { |
539 | { | ||
540 | BIO_free(new_bio); | 566 | BIO_free(new_bio); |
541 | goto err; | 567 | goto err; |
542 | } | 568 | } |
543 | 569 | ||
544 | /* copy app data */ | 570 | /* copy app data */ |
545 | if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_BIO, &new_bio->ex_data, | 571 | if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_BIO, |
546 | &bio->ex_data)) | 572 | &new_bio->ex_data, &bio->ex_data)) |
547 | goto err; | 573 | goto err; |
548 | 574 | ||
549 | if (ret == NULL) | 575 | if (ret == NULL) { |
550 | { | 576 | eoc = new_bio; |
551 | eoc=new_bio; | 577 | ret = eoc; |
552 | ret=eoc; | 578 | } else { |
553 | } | 579 | BIO_push(eoc, new_bio); |
554 | else | 580 | eoc = new_bio; |
555 | { | ||
556 | BIO_push(eoc,new_bio); | ||
557 | eoc=new_bio; | ||
558 | } | ||
559 | } | 581 | } |
560 | return(ret); | 582 | } |
583 | return (ret); | ||
561 | err: | 584 | err: |
562 | if (ret != NULL) | 585 | if (ret != NULL) |
563 | BIO_free(ret); | 586 | BIO_free(ret); |
564 | return(NULL); | 587 | return (NULL); |
565 | } | ||
566 | 588 | ||
567 | void BIO_copy_next_retry(BIO *b) | 589 | } |
568 | { | ||
569 | BIO_set_flags(b,BIO_get_retry_flags(b->next_bio)); | ||
570 | b->retry_reason=b->next_bio->retry_reason; | ||
571 | } | ||
572 | 590 | ||
573 | int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | 591 | void |
574 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | 592 | BIO_copy_next_retry(BIO *b) |
575 | { | 593 | { |
594 | BIO_set_flags(b, BIO_get_retry_flags(b->next_bio)); | ||
595 | b->retry_reason = b->next_bio->retry_reason; | ||
596 | } | ||
597 | |||
598 | int | ||
599 | BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
600 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | ||
601 | { | ||
576 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_BIO, argl, argp, | 602 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_BIO, argl, argp, |
577 | new_func, dup_func, free_func); | 603 | new_func, dup_func, free_func); |
578 | } | 604 | } |
579 | 605 | ||
580 | int BIO_set_ex_data(BIO *bio, int idx, void *data) | 606 | int |
581 | { | 607 | BIO_set_ex_data(BIO *bio, int idx, void *data) |
582 | return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data)); | 608 | { |
583 | } | 609 | return (CRYPTO_set_ex_data(&(bio->ex_data), idx, data)); |
610 | } | ||
584 | 611 | ||
585 | void *BIO_get_ex_data(BIO *bio, int idx) | 612 | void |
586 | { | 613 | *BIO_get_ex_data(BIO *bio, int idx) |
587 | return(CRYPTO_get_ex_data(&(bio->ex_data),idx)); | 614 | { |
588 | } | 615 | return (CRYPTO_get_ex_data(&(bio->ex_data), idx)); |
616 | } | ||
589 | 617 | ||
590 | unsigned long BIO_number_read(BIO *bio) | 618 | unsigned long |
619 | BIO_number_read(BIO *bio) | ||
591 | { | 620 | { |
592 | if(bio) return bio->num_read; | 621 | if (bio) |
622 | return bio->num_read; | ||
593 | return 0; | 623 | return 0; |
594 | } | 624 | } |
595 | 625 | ||
596 | unsigned long BIO_number_written(BIO *bio) | 626 | unsigned long |
627 | BIO_number_written(BIO *bio) | ||
597 | { | 628 | { |
598 | if(bio) return bio->num_write; | 629 | if (bio) |
630 | return bio->num_write; | ||
599 | return 0; | 631 | return 0; |
600 | } | 632 | } |
601 | 633 | ||
diff --git a/src/lib/libssl/src/crypto/bio/bss_acpt.c b/src/lib/libssl/src/crypto/bio/bss_acpt.c index 04bfb6fb9d..d772515d64 100644 --- a/src/lib/libssl/src/crypto/bio/bss_acpt.c +++ b/src/lib/libssl/src/crypto/bio/bss_acpt.c | |||
@@ -75,8 +75,7 @@ | |||
75 | #undef FIONBIO | 75 | #undef FIONBIO |
76 | #endif | 76 | #endif |
77 | 77 | ||
78 | typedef struct bio_accept_st | 78 | typedef struct bio_accept_st { |
79 | { | ||
80 | int state; | 79 | int state; |
81 | char *param_addr; | 80 | char *param_addr; |
82 | 81 | ||
@@ -90,7 +89,7 @@ typedef struct bio_accept_st | |||
90 | * If 2, always use SO_REUSEADDR. */ | 89 | * If 2, always use SO_REUSEADDR. */ |
91 | int bind_mode; | 90 | int bind_mode; |
92 | BIO *bio_chain; | 91 | BIO *bio_chain; |
93 | } BIO_ACCEPT; | 92 | } BIO_ACCEPT; |
94 | 93 | ||
95 | static int acpt_write(BIO *h, const char *buf, int num); | 94 | static int acpt_write(BIO *h, const char *buf, int num); |
96 | static int acpt_read(BIO *h, char *buf, int size); | 95 | static int acpt_read(BIO *h, char *buf, int size); |
@@ -107,8 +106,7 @@ static void BIO_ACCEPT_free(BIO_ACCEPT *a); | |||
107 | #define ACPT_S_GET_ACCEPT_SOCKET 2 | 106 | #define ACPT_S_GET_ACCEPT_SOCKET 2 |
108 | #define ACPT_S_OK 3 | 107 | #define ACPT_S_OK 3 |
109 | 108 | ||
110 | static BIO_METHOD methods_acceptp= | 109 | static BIO_METHOD methods_acceptp = { |
111 | { | ||
112 | BIO_TYPE_ACCEPT, | 110 | BIO_TYPE_ACCEPT, |
113 | "socket accept", | 111 | "socket accept", |
114 | acpt_write, | 112 | acpt_write, |
@@ -119,321 +117,313 @@ static BIO_METHOD methods_acceptp= | |||
119 | acpt_new, | 117 | acpt_new, |
120 | acpt_free, | 118 | acpt_free, |
121 | NULL, | 119 | NULL, |
122 | }; | 120 | }; |
123 | 121 | ||
124 | BIO_METHOD *BIO_s_accept(void) | 122 | BIO_METHOD |
125 | { | 123 | *BIO_s_accept(void) |
126 | return(&methods_acceptp); | 124 | { |
127 | } | 125 | return (&methods_acceptp); |
126 | } | ||
128 | 127 | ||
129 | static int acpt_new(BIO *bi) | 128 | static int |
130 | { | 129 | acpt_new(BIO *bi) |
130 | { | ||
131 | BIO_ACCEPT *ba; | 131 | BIO_ACCEPT *ba; |
132 | 132 | ||
133 | bi->init=0; | 133 | bi->init = 0; |
134 | bi->num=-1; | 134 | bi->num = -1; |
135 | bi->flags=0; | 135 | bi->flags = 0; |
136 | if ((ba=BIO_ACCEPT_new()) == NULL) | 136 | if ((ba = BIO_ACCEPT_new()) == NULL) |
137 | return(0); | 137 | return (0); |
138 | bi->ptr=(char *)ba; | 138 | bi->ptr = (char *)ba; |
139 | ba->state=ACPT_S_BEFORE; | 139 | ba->state = ACPT_S_BEFORE; |
140 | bi->shutdown=1; | 140 | bi->shutdown = 1; |
141 | return(1); | 141 | return (1); |
142 | } | 142 | } |
143 | 143 | ||
144 | static BIO_ACCEPT *BIO_ACCEPT_new(void) | 144 | static BIO_ACCEPT |
145 | { | 145 | *BIO_ACCEPT_new(void) |
146 | { | ||
146 | BIO_ACCEPT *ret; | 147 | BIO_ACCEPT *ret; |
147 | 148 | ||
148 | if ((ret=(BIO_ACCEPT *)OPENSSL_malloc(sizeof(BIO_ACCEPT))) == NULL) | 149 | if ((ret = (BIO_ACCEPT *)OPENSSL_malloc(sizeof(BIO_ACCEPT))) == NULL) |
149 | return(NULL); | 150 | return (NULL); |
150 | 151 | ||
151 | memset(ret,0,sizeof(BIO_ACCEPT)); | 152 | memset(ret, 0, sizeof(BIO_ACCEPT)); |
152 | ret->accept_sock=-1; | 153 | ret->accept_sock = -1; |
153 | ret->bind_mode=BIO_BIND_NORMAL; | 154 | ret->bind_mode = BIO_BIND_NORMAL; |
154 | return(ret); | 155 | return (ret); |
155 | } | 156 | } |
156 | 157 | ||
157 | static void BIO_ACCEPT_free(BIO_ACCEPT *a) | 158 | static void |
158 | { | 159 | BIO_ACCEPT_free(BIO_ACCEPT *a) |
159 | if(a == NULL) | 160 | { |
160 | return; | 161 | if (a == NULL) |
161 | 162 | return; | |
162 | if (a->param_addr != NULL) OPENSSL_free(a->param_addr); | 163 | |
163 | if (a->addr != NULL) OPENSSL_free(a->addr); | 164 | if (a->param_addr != NULL) |
164 | if (a->bio_chain != NULL) BIO_free(a->bio_chain); | 165 | OPENSSL_free(a->param_addr); |
166 | if (a->addr != NULL) | ||
167 | OPENSSL_free(a->addr); | ||
168 | if (a->bio_chain != NULL) | ||
169 | BIO_free(a->bio_chain); | ||
165 | OPENSSL_free(a); | 170 | OPENSSL_free(a); |
166 | } | 171 | } |
167 | 172 | ||
168 | static void acpt_close_socket(BIO *bio) | 173 | static void |
169 | { | 174 | acpt_close_socket(BIO *bio) |
175 | { | ||
170 | BIO_ACCEPT *c; | 176 | BIO_ACCEPT *c; |
171 | 177 | ||
172 | c=(BIO_ACCEPT *)bio->ptr; | 178 | c = (BIO_ACCEPT *)bio->ptr; |
173 | if (c->accept_sock != -1) | 179 | if (c->accept_sock != -1) { |
174 | { | ||
175 | shutdown(c->accept_sock, SHUT_RDWR); | 180 | shutdown(c->accept_sock, SHUT_RDWR); |
176 | close(c->accept_sock); | 181 | close(c->accept_sock); |
177 | c->accept_sock=-1; | 182 | c->accept_sock = -1; |
178 | bio->num=-1; | 183 | bio->num = -1; |
179 | } | ||
180 | } | 184 | } |
185 | } | ||
181 | 186 | ||
182 | static int acpt_free(BIO *a) | 187 | static int |
183 | { | 188 | acpt_free(BIO *a) |
189 | { | ||
184 | BIO_ACCEPT *data; | 190 | BIO_ACCEPT *data; |
185 | 191 | ||
186 | if (a == NULL) return(0); | 192 | if (a == NULL) |
187 | data=(BIO_ACCEPT *)a->ptr; | 193 | return (0); |
188 | 194 | data = (BIO_ACCEPT *)a->ptr; | |
189 | if (a->shutdown) | 195 | |
190 | { | 196 | if (a->shutdown) { |
191 | acpt_close_socket(a); | 197 | acpt_close_socket(a); |
192 | BIO_ACCEPT_free(data); | 198 | BIO_ACCEPT_free(data); |
193 | a->ptr=NULL; | 199 | a->ptr = NULL; |
194 | a->flags=0; | 200 | a->flags = 0; |
195 | a->init=0; | 201 | a->init = 0; |
196 | } | ||
197 | return(1); | ||
198 | } | 202 | } |
199 | 203 | return (1); | |
200 | static int acpt_state(BIO *b, BIO_ACCEPT *c) | 204 | } |
201 | { | 205 | |
202 | BIO *bio=NULL,*dbio; | 206 | static int |
203 | int s= -1; | 207 | acpt_state(BIO *b, BIO_ACCEPT *c) |
208 | { | ||
209 | BIO *bio = NULL, *dbio; | ||
210 | int s = -1; | ||
204 | int i; | 211 | int i; |
205 | 212 | ||
206 | again: | 213 | again: |
207 | switch (c->state) | 214 | switch (c->state) { |
208 | { | ||
209 | case ACPT_S_BEFORE: | 215 | case ACPT_S_BEFORE: |
210 | if (c->param_addr == NULL) | 216 | if (c->param_addr == NULL) { |
211 | { | 217 | BIOerr(BIO_F_ACPT_STATE, BIO_R_NO_ACCEPT_PORT_SPECIFIED); |
212 | BIOerr(BIO_F_ACPT_STATE,BIO_R_NO_ACCEPT_PORT_SPECIFIED); | 218 | return (-1); |
213 | return(-1); | 219 | } |
214 | } | 220 | s = BIO_get_accept_socket(c->param_addr, c->bind_mode); |
215 | s=BIO_get_accept_socket(c->param_addr,c->bind_mode); | ||
216 | if (s == -1) | 221 | if (s == -1) |
217 | return(-1); | 222 | return (-1); |
218 | 223 | ||
219 | if (c->accept_nbio) | 224 | if (c->accept_nbio) { |
220 | { | 225 | if (!BIO_socket_nbio(s, 1)) { |
221 | if (!BIO_socket_nbio(s,1)) | ||
222 | { | ||
223 | close(s); | 226 | close(s); |
224 | BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET); | 227 | BIOerr(BIO_F_ACPT_STATE, BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET); |
225 | return(-1); | 228 | return (-1); |
226 | } | ||
227 | } | 229 | } |
228 | c->accept_sock=s; | 230 | } |
229 | b->num=s; | 231 | c->accept_sock = s; |
230 | c->state=ACPT_S_GET_ACCEPT_SOCKET; | 232 | b->num = s; |
231 | return(1); | 233 | c->state = ACPT_S_GET_ACCEPT_SOCKET; |
234 | return (1); | ||
232 | /* break; */ | 235 | /* break; */ |
233 | case ACPT_S_GET_ACCEPT_SOCKET: | 236 | case ACPT_S_GET_ACCEPT_SOCKET: |
234 | if (b->next_bio != NULL) | 237 | if (b->next_bio != NULL) { |
235 | { | 238 | c->state = ACPT_S_OK; |
236 | c->state=ACPT_S_OK; | ||
237 | goto again; | 239 | goto again; |
238 | } | 240 | } |
239 | BIO_clear_retry_flags(b); | 241 | BIO_clear_retry_flags(b); |
240 | b->retry_reason=0; | 242 | b->retry_reason = 0; |
241 | i=BIO_accept(c->accept_sock,&(c->addr)); | 243 | i = BIO_accept(c->accept_sock, &(c->addr)); |
242 | 244 | ||
243 | /* -2 return means we should retry */ | 245 | /* -2 return means we should retry */ |
244 | if(i == -2) | 246 | if (i == -2) { |
245 | { | ||
246 | BIO_set_retry_special(b); | 247 | BIO_set_retry_special(b); |
247 | b->retry_reason=BIO_RR_ACCEPT; | 248 | b->retry_reason = BIO_RR_ACCEPT; |
248 | return -1; | 249 | return -1; |
249 | } | 250 | } |
250 | 251 | ||
251 | if (i < 0) return(i); | 252 | if (i < 0) |
253 | return (i); | ||
252 | 254 | ||
253 | bio=BIO_new_socket(i,BIO_CLOSE); | 255 | bio = BIO_new_socket(i, BIO_CLOSE); |
254 | if (bio == NULL) goto err; | 256 | if (bio == NULL) |
257 | goto err; | ||
255 | 258 | ||
256 | BIO_set_callback(bio,BIO_get_callback(b)); | 259 | BIO_set_callback(bio, BIO_get_callback(b)); |
257 | BIO_set_callback_arg(bio,BIO_get_callback_arg(b)); | 260 | BIO_set_callback_arg(bio, BIO_get_callback_arg(b)); |
258 | 261 | ||
259 | if (c->nbio) | 262 | if (c->nbio) { |
260 | { | 263 | if (!BIO_socket_nbio(i, 1)) { |
261 | if (!BIO_socket_nbio(i,1)) | 264 | BIOerr(BIO_F_ACPT_STATE, BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET); |
262 | { | ||
263 | BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET); | ||
264 | goto err; | 265 | goto err; |
265 | } | ||
266 | } | 266 | } |
267 | } | ||
267 | 268 | ||
268 | /* If the accept BIO has an bio_chain, we dup it and | 269 | /* If the accept BIO has an bio_chain, we dup it and |
269 | * put the new socket at the end. */ | 270 | * put the new socket at the end. */ |
270 | if (c->bio_chain != NULL) | 271 | if (c->bio_chain != NULL) { |
271 | { | 272 | if ((dbio = BIO_dup_chain(c->bio_chain)) == NULL) |
272 | if ((dbio=BIO_dup_chain(c->bio_chain)) == NULL) | ||
273 | goto err; | 273 | goto err; |
274 | if (!BIO_push(dbio,bio)) goto err; | 274 | if (!BIO_push(dbio, bio)) goto err; |
275 | bio=dbio; | 275 | bio = dbio; |
276 | } | 276 | } |
277 | if (BIO_push(b,bio) == NULL) goto err; | 277 | if (BIO_push(b, bio) |
278 | == NULL) goto err; | ||
279 | |||
280 | c->state = ACPT_S_OK; | ||
281 | return (1); | ||
278 | 282 | ||
279 | c->state=ACPT_S_OK; | ||
280 | return(1); | ||
281 | err: | 283 | err: |
282 | if (bio != NULL) | 284 | if (bio != NULL) |
283 | BIO_free(bio); | 285 | BIO_free(bio); |
284 | else if (s >= 0) | 286 | else if (s >= 0) |
285 | close(s); | 287 | close(s); |
286 | return(0); | 288 | return (0); |
287 | /* break; */ | 289 | /* break; */ |
288 | case ACPT_S_OK: | 290 | case ACPT_S_OK: |
289 | if (b->next_bio == NULL) | 291 | if (b->next_bio == NULL) { |
290 | { | 292 | c->state = ACPT_S_GET_ACCEPT_SOCKET; |
291 | c->state=ACPT_S_GET_ACCEPT_SOCKET; | ||
292 | goto again; | 293 | goto again; |
293 | } | 294 | } |
294 | return(1); | 295 | return (1); |
295 | /* break; */ | 296 | /* break; */ |
296 | default: | 297 | default: |
297 | return(0); | 298 | return (0); |
298 | /* break; */ | 299 | /* break; */ |
299 | } | ||
300 | |||
301 | } | 300 | } |
301 | } | ||
302 | 302 | ||
303 | static int acpt_read(BIO *b, char *out, int outl) | 303 | static int |
304 | { | 304 | acpt_read(BIO *b, char *out, int outl) |
305 | int ret=0; | 305 | { |
306 | int ret = 0; | ||
306 | BIO_ACCEPT *data; | 307 | BIO_ACCEPT *data; |
307 | 308 | ||
308 | BIO_clear_retry_flags(b); | 309 | BIO_clear_retry_flags(b); |
309 | data=(BIO_ACCEPT *)b->ptr; | 310 | data = (BIO_ACCEPT *)b->ptr; |
310 | 311 | ||
311 | while (b->next_bio == NULL) | 312 | while (b->next_bio == NULL) { |
312 | { | 313 | ret = acpt_state(b, data); |
313 | ret=acpt_state(b,data); | 314 | if (ret <= 0) |
314 | if (ret <= 0) return(ret); | 315 | return (ret); |
315 | } | 316 | } |
316 | 317 | ||
317 | ret=BIO_read(b->next_bio,out,outl); | 318 | ret = BIO_read(b->next_bio, out, outl); |
318 | BIO_copy_next_retry(b); | 319 | BIO_copy_next_retry(b); |
319 | return(ret); | 320 | return (ret); |
320 | } | 321 | } |
321 | 322 | ||
322 | static int acpt_write(BIO *b, const char *in, int inl) | 323 | static int |
323 | { | 324 | acpt_write(BIO *b, const char *in, int inl) |
325 | { | ||
324 | int ret; | 326 | int ret; |
325 | BIO_ACCEPT *data; | 327 | BIO_ACCEPT *data; |
326 | 328 | ||
327 | BIO_clear_retry_flags(b); | 329 | BIO_clear_retry_flags(b); |
328 | data=(BIO_ACCEPT *)b->ptr; | 330 | data = (BIO_ACCEPT *)b->ptr; |
329 | 331 | ||
330 | while (b->next_bio == NULL) | 332 | while (b->next_bio == NULL) { |
331 | { | 333 | ret = acpt_state(b, data); |
332 | ret=acpt_state(b,data); | 334 | if (ret <= 0) |
333 | if (ret <= 0) return(ret); | 335 | return (ret); |
334 | } | 336 | } |
335 | 337 | ||
336 | ret=BIO_write(b->next_bio,in,inl); | 338 | ret = BIO_write(b->next_bio, in, inl); |
337 | BIO_copy_next_retry(b); | 339 | BIO_copy_next_retry(b); |
338 | return(ret); | 340 | return (ret); |
339 | } | 341 | } |
340 | 342 | ||
341 | static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr) | 343 | static long |
342 | { | 344 | acpt_ctrl(BIO *b, int cmd, long num, void *ptr) |
345 | { | ||
343 | int *ip; | 346 | int *ip; |
344 | long ret=1; | 347 | long ret = 1; |
345 | BIO_ACCEPT *data; | 348 | BIO_ACCEPT *data; |
346 | char **pp; | 349 | char **pp; |
347 | 350 | ||
348 | data=(BIO_ACCEPT *)b->ptr; | 351 | data = (BIO_ACCEPT *)b->ptr; |
349 | 352 | ||
350 | switch (cmd) | 353 | switch (cmd) { |
351 | { | ||
352 | case BIO_CTRL_RESET: | 354 | case BIO_CTRL_RESET: |
353 | ret=0; | 355 | ret = 0; |
354 | data->state=ACPT_S_BEFORE; | 356 | data->state = ACPT_S_BEFORE; |
355 | acpt_close_socket(b); | 357 | acpt_close_socket(b); |
356 | b->flags=0; | 358 | b->flags = 0; |
357 | break; | 359 | break; |
358 | case BIO_C_DO_STATE_MACHINE: | 360 | case BIO_C_DO_STATE_MACHINE: |
359 | /* use this one to start the connection */ | 361 | /* use this one to start the connection */ |
360 | ret=(long)acpt_state(b,data); | 362 | ret = (long)acpt_state(b, data); |
361 | break; | 363 | break; |
362 | case BIO_C_SET_ACCEPT: | 364 | case BIO_C_SET_ACCEPT: |
363 | if (ptr != NULL) | 365 | if (ptr != NULL) { |
364 | { | 366 | if (num == 0) { |
365 | if (num == 0) | 367 | b->init = 1; |
366 | { | ||
367 | b->init=1; | ||
368 | if (data->param_addr != NULL) | 368 | if (data->param_addr != NULL) |
369 | OPENSSL_free(data->param_addr); | 369 | OPENSSL_free(data->param_addr); |
370 | data->param_addr=BUF_strdup(ptr); | 370 | data->param_addr = BUF_strdup(ptr); |
371 | } | 371 | } else if (num == 1) { |
372 | else if (num == 1) | 372 | data->accept_nbio = (ptr != NULL); |
373 | { | 373 | } else if (num == 2) { |
374 | data->accept_nbio=(ptr != NULL); | ||
375 | } | ||
376 | else if (num == 2) | ||
377 | { | ||
378 | if (data->bio_chain != NULL) | 374 | if (data->bio_chain != NULL) |
379 | BIO_free(data->bio_chain); | 375 | BIO_free(data->bio_chain); |
380 | data->bio_chain=(BIO *)ptr; | 376 | data->bio_chain = (BIO *)ptr; |
381 | } | ||
382 | } | 377 | } |
378 | } | ||
383 | break; | 379 | break; |
384 | case BIO_C_SET_NBIO: | 380 | case BIO_C_SET_NBIO: |
385 | data->nbio=(int)num; | 381 | data->nbio = (int)num; |
386 | break; | 382 | break; |
387 | case BIO_C_SET_FD: | 383 | case BIO_C_SET_FD: |
388 | b->init=1; | 384 | b->init = 1; |
389 | b->num= *((int *)ptr); | 385 | b->num= *((int *)ptr); |
390 | data->accept_sock=b->num; | 386 | data->accept_sock = b->num; |
391 | data->state=ACPT_S_GET_ACCEPT_SOCKET; | 387 | data->state = ACPT_S_GET_ACCEPT_SOCKET; |
392 | b->shutdown=(int)num; | 388 | b->shutdown = (int)num; |
393 | b->init=1; | 389 | b->init = 1; |
394 | break; | 390 | break; |
395 | case BIO_C_GET_FD: | 391 | case BIO_C_GET_FD: |
396 | if (b->init) | 392 | if (b->init) { |
397 | { | 393 | ip = (int *)ptr; |
398 | ip=(int *)ptr; | ||
399 | if (ip != NULL) | 394 | if (ip != NULL) |
400 | *ip=data->accept_sock; | 395 | *ip = data->accept_sock; |
401 | ret=data->accept_sock; | 396 | ret = data->accept_sock; |
402 | } | 397 | } else |
403 | else | 398 | ret = -1; |
404 | ret= -1; | ||
405 | break; | 399 | break; |
406 | case BIO_C_GET_ACCEPT: | 400 | case BIO_C_GET_ACCEPT: |
407 | if (b->init) | 401 | if (b->init) { |
408 | { | 402 | if (ptr != NULL) { |
409 | if (ptr != NULL) | 403 | pp = (char **)ptr; |
410 | { | 404 | *pp = data->param_addr; |
411 | pp=(char **)ptr; | 405 | } else |
412 | *pp=data->param_addr; | 406 | ret = -1; |
413 | } | 407 | } else |
414 | else | 408 | ret = -1; |
415 | ret= -1; | ||
416 | } | ||
417 | else | ||
418 | ret= -1; | ||
419 | break; | 409 | break; |
420 | case BIO_CTRL_GET_CLOSE: | 410 | case BIO_CTRL_GET_CLOSE: |
421 | ret=b->shutdown; | 411 | ret = b->shutdown; |
422 | break; | 412 | break; |
423 | case BIO_CTRL_SET_CLOSE: | 413 | case BIO_CTRL_SET_CLOSE: |
424 | b->shutdown=(int)num; | 414 | b->shutdown = (int)num; |
425 | break; | 415 | break; |
426 | case BIO_CTRL_PENDING: | 416 | case BIO_CTRL_PENDING: |
427 | case BIO_CTRL_WPENDING: | 417 | case BIO_CTRL_WPENDING: |
428 | ret=0; | 418 | ret = 0; |
429 | break; | 419 | break; |
430 | case BIO_CTRL_FLUSH: | 420 | case BIO_CTRL_FLUSH: |
431 | break; | 421 | break; |
432 | case BIO_C_SET_BIND_MODE: | 422 | case BIO_C_SET_BIND_MODE: |
433 | data->bind_mode=(int)num; | 423 | data->bind_mode = (int)num; |
434 | break; | 424 | break; |
435 | case BIO_C_GET_BIND_MODE: | 425 | case BIO_C_GET_BIND_MODE: |
436 | ret=(long)data->bind_mode; | 426 | ret = (long)data->bind_mode; |
437 | break; | 427 | break; |
438 | case BIO_CTRL_DUP: | 428 | case BIO_CTRL_DUP: |
439 | /* dbio=(BIO *)ptr; | 429 | /* dbio=(BIO *)ptr; |
@@ -441,38 +431,41 @@ static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
441 | BIO_set_port(dbio,data->param_port); | 431 | BIO_set_port(dbio,data->param_port); |
442 | if (data->param_hostname) | 432 | if (data->param_hostname) |
443 | BIO_set_hostname(dbio,data->param_hostname); | 433 | BIO_set_hostname(dbio,data->param_hostname); |
444 | BIO_set_nbio(dbio,data->nbio); */ | 434 | BIO_set_nbio(dbio,data->nbio); |
435 | */ | ||
445 | break; | 436 | break; |
446 | 437 | ||
447 | default: | 438 | default: |
448 | ret=0; | 439 | ret = 0; |
449 | break; | 440 | break; |
450 | } | ||
451 | return(ret); | ||
452 | } | 441 | } |
453 | 442 | return (ret); | |
454 | static int acpt_puts(BIO *bp, const char *str) | 443 | } |
455 | { | 444 | |
456 | int n,ret; | 445 | static int |
457 | 446 | acpt_puts(BIO *bp, const char *str) | |
458 | n=strlen(str); | 447 | { |
459 | ret=acpt_write(bp,str,n); | 448 | int n, ret; |
460 | return(ret); | 449 | |
461 | } | 450 | n = strlen(str); |
462 | 451 | ret = acpt_write(bp, str, n); | |
463 | BIO *BIO_new_accept(char *str) | 452 | return (ret); |
464 | { | 453 | } |
454 | |||
455 | BIO | ||
456 | *BIO_new_accept(char *str) | ||
457 | { | ||
465 | BIO *ret; | 458 | BIO *ret; |
466 | 459 | ||
467 | ret=BIO_new(BIO_s_accept()); | 460 | ret = BIO_new(BIO_s_accept()); |
468 | if (ret == NULL) return(NULL); | 461 | if (ret == NULL) |
469 | if (BIO_set_accept_port(ret,str)) | 462 | return (NULL); |
470 | return(ret); | 463 | if (BIO_set_accept_port(ret, str)) |
471 | else | 464 | return (ret); |
472 | { | 465 | else { |
473 | BIO_free(ret); | 466 | BIO_free(ret); |
474 | return(NULL); | 467 | return (NULL); |
475 | } | ||
476 | } | 468 | } |
469 | } | ||
477 | 470 | ||
478 | #endif | 471 | #endif |
diff --git a/src/lib/libssl/src/crypto/bio/bss_bio.c b/src/lib/libssl/src/crypto/bio/bss_bio.c index 52ef0ebcb3..a74fcfdabc 100644 --- a/src/lib/libssl/src/crypto/bio/bss_bio.c +++ b/src/lib/libssl/src/crypto/bio/bss_bio.c | |||
@@ -103,8 +103,7 @@ static int bio_puts(BIO *bio, const char *str); | |||
103 | static int bio_make_pair(BIO *bio1, BIO *bio2); | 103 | static int bio_make_pair(BIO *bio1, BIO *bio2); |
104 | static void bio_destroy_pair(BIO *bio); | 104 | static void bio_destroy_pair(BIO *bio); |
105 | 105 | ||
106 | static BIO_METHOD methods_biop = | 106 | static BIO_METHOD methods_biop = { |
107 | { | ||
108 | BIO_TYPE_BIO, | 107 | BIO_TYPE_BIO, |
109 | "BIO pair", | 108 | "BIO pair", |
110 | bio_write, | 109 | bio_write, |
@@ -117,50 +116,51 @@ static BIO_METHOD methods_biop = | |||
117 | NULL /* no bio_callback_ctrl */ | 116 | NULL /* no bio_callback_ctrl */ |
118 | }; | 117 | }; |
119 | 118 | ||
120 | BIO_METHOD *BIO_s_bio(void) | 119 | BIO_METHOD |
121 | { | 120 | *BIO_s_bio(void) |
121 | { | ||
122 | return &methods_biop; | 122 | return &methods_biop; |
123 | } | 123 | } |
124 | |||
125 | struct bio_bio_st { | ||
126 | BIO *peer; /* NULL if buf == NULL. | ||
127 | * If peer != NULL, then peer->ptr is also a bio_bio_st, | ||
128 | * and its "peer" member points back to us. | ||
129 | * peer != NULL iff init != 0 in the BIO. */ | ||
124 | 130 | ||
125 | struct bio_bio_st | ||
126 | { | ||
127 | BIO *peer; /* NULL if buf == NULL. | ||
128 | * If peer != NULL, then peer->ptr is also a bio_bio_st, | ||
129 | * and its "peer" member points back to us. | ||
130 | * peer != NULL iff init != 0 in the BIO. */ | ||
131 | |||
132 | /* This is for what we write (i.e. reading uses peer's struct): */ | 131 | /* This is for what we write (i.e. reading uses peer's struct): */ |
133 | int closed; /* valid iff peer != NULL */ | 132 | int closed; /* valid iff peer != NULL */ |
134 | size_t len; /* valid iff buf != NULL; 0 if peer == NULL */ | 133 | size_t len; /* valid iff buf != NULL; 0 if peer == NULL */ |
135 | size_t offset; /* valid iff buf != NULL; 0 if len == 0 */ | 134 | size_t offset; /* valid iff buf != NULL; 0 if len == 0 */ |
136 | size_t size; | 135 | size_t size; |
137 | char *buf; /* "size" elements (if != NULL) */ | 136 | char *buf; /* "size" elements (if != NULL) */ |
138 | 137 | ||
139 | size_t request; /* valid iff peer != NULL; 0 if len != 0, | 138 | size_t request; /* valid iff peer != NULL; 0 if len != 0, |
140 | * otherwise set by peer to number of bytes | 139 | * otherwise set by peer to number of bytes |
141 | * it (unsuccessfully) tried to read, | 140 | * it (unsuccessfully) tried to read, |
142 | * never more than buffer space (size-len) warrants. */ | 141 | * never more than buffer space (size-len) warrants. */ |
143 | }; | 142 | }; |
144 | 143 | ||
145 | static int bio_new(BIO *bio) | 144 | static int |
146 | { | 145 | bio_new(BIO *bio) |
146 | { | ||
147 | struct bio_bio_st *b; | 147 | struct bio_bio_st *b; |
148 | 148 | ||
149 | b = OPENSSL_malloc(sizeof *b); | 149 | b = OPENSSL_malloc(sizeof *b); |
150 | if (b == NULL) | 150 | if (b == NULL) |
151 | return 0; | 151 | return 0; |
152 | 152 | ||
153 | b->peer = NULL; | 153 | b->peer = NULL; |
154 | b->size = 17*1024; /* enough for one TLS record (just a default) */ | 154 | b->size = 17 * 1024; /* enough for one TLS record (just a default) */ |
155 | b->buf = NULL; | 155 | b->buf = NULL; |
156 | 156 | ||
157 | bio->ptr = b; | 157 | bio->ptr = b; |
158 | return 1; | 158 | return 1; |
159 | } | 159 | } |
160 | 160 | ||
161 | 161 | static int | |
162 | static int bio_free(BIO *bio) | 162 | bio_free(BIO *bio) |
163 | { | 163 | { |
164 | struct bio_bio_st *b; | 164 | struct bio_bio_st *b; |
165 | 165 | ||
166 | if (bio == NULL) | 166 | if (bio == NULL) |
@@ -171,21 +171,21 @@ static int bio_free(BIO *bio) | |||
171 | 171 | ||
172 | if (b->peer) | 172 | if (b->peer) |
173 | bio_destroy_pair(bio); | 173 | bio_destroy_pair(bio); |
174 | 174 | ||
175 | if (b->buf != NULL) | 175 | if (b->buf != NULL) { |
176 | { | ||
177 | OPENSSL_free(b->buf); | 176 | OPENSSL_free(b->buf); |
178 | } | 177 | } |
179 | 178 | ||
180 | OPENSSL_free(b); | 179 | OPENSSL_free(b); |
181 | 180 | ||
182 | return 1; | 181 | return 1; |
183 | } | 182 | } |
184 | 183 | ||
185 | 184 | ||
186 | 185 | ||
187 | static int bio_read(BIO *bio, char *buf, int size_) | 186 | static int |
188 | { | 187 | bio_read(BIO *bio, char *buf, int size_) |
188 | { | ||
189 | size_t size = size_; | 189 | size_t size = size_; |
190 | size_t rest; | 190 | size_t rest; |
191 | struct bio_bio_st *b, *peer_b; | 191 | struct bio_bio_st *b, *peer_b; |
@@ -207,12 +207,10 @@ static int bio_read(BIO *bio, char *buf, int size_) | |||
207 | if (buf == NULL || size == 0) | 207 | if (buf == NULL || size == 0) |
208 | return 0; | 208 | return 0; |
209 | 209 | ||
210 | if (peer_b->len == 0) | 210 | if (peer_b->len == 0) { |
211 | { | ||
212 | if (peer_b->closed) | 211 | if (peer_b->closed) |
213 | return 0; /* writer has closed, and no data is left */ | 212 | return 0; /* writer has closed, and no data is left */ |
214 | else | 213 | else { |
215 | { | ||
216 | BIO_set_retry_read(bio); /* buffer is empty */ | 214 | BIO_set_retry_read(bio); /* buffer is empty */ |
217 | if (size <= peer_b->size) | 215 | if (size <= peer_b->size) |
218 | peer_b->request = size; | 216 | peer_b->request = size; |
@@ -221,22 +219,22 @@ static int bio_read(BIO *bio, char *buf, int size_) | |||
221 | * deliver in one write */ | 219 | * deliver in one write */ |
222 | peer_b->request = peer_b->size; | 220 | peer_b->request = peer_b->size; |
223 | return -1; | 221 | return -1; |
224 | } | ||
225 | } | 222 | } |
223 | } | ||
226 | 224 | ||
227 | /* we can read */ | 225 | /* we can read */ |
228 | if (peer_b->len < size) | 226 | if (peer_b->len < size) |
229 | size = peer_b->len; | 227 | size = peer_b->len; |
230 | 228 | ||
231 | /* now read "size" bytes */ | 229 | /* now read "size" bytes */ |
232 | 230 | ||
233 | rest = size; | 231 | rest = size; |
234 | 232 | ||
235 | assert(rest > 0); | 233 | assert(rest > 0); |
236 | do /* one or two iterations */ | 234 | do /* one or two iterations */ |
237 | { | 235 | { |
238 | size_t chunk; | 236 | size_t chunk; |
239 | 237 | ||
240 | assert(rest <= peer_b->len); | 238 | assert(rest <= peer_b->len); |
241 | if (peer_b->offset + rest <= peer_b->size) | 239 | if (peer_b->offset + rest <= peer_b->size) |
242 | chunk = rest; | 240 | chunk = rest; |
@@ -244,30 +242,26 @@ static int bio_read(BIO *bio, char *buf, int size_) | |||
244 | /* wrap around ring buffer */ | 242 | /* wrap around ring buffer */ |
245 | chunk = peer_b->size - peer_b->offset; | 243 | chunk = peer_b->size - peer_b->offset; |
246 | assert(peer_b->offset + chunk <= peer_b->size); | 244 | assert(peer_b->offset + chunk <= peer_b->size); |
247 | 245 | ||
248 | memcpy(buf, peer_b->buf + peer_b->offset, chunk); | 246 | memcpy(buf, peer_b->buf + peer_b->offset, chunk); |
249 | 247 | ||
250 | peer_b->len -= chunk; | 248 | peer_b->len -= chunk; |
251 | if (peer_b->len) | 249 | if (peer_b->len) { |
252 | { | ||
253 | peer_b->offset += chunk; | 250 | peer_b->offset += chunk; |
254 | assert(peer_b->offset <= peer_b->size); | 251 | assert(peer_b->offset <= peer_b->size); |
255 | if (peer_b->offset == peer_b->size) | 252 | if (peer_b->offset == peer_b->size) |
256 | peer_b->offset = 0; | 253 | peer_b->offset = 0; |
257 | buf += chunk; | 254 | buf += chunk; |
258 | } | 255 | } else { |
259 | else | ||
260 | { | ||
261 | /* buffer now empty, no need to advance "buf" */ | 256 | /* buffer now empty, no need to advance "buf" */ |
262 | assert(chunk == rest); | 257 | assert(chunk == rest); |
263 | peer_b->offset = 0; | 258 | peer_b->offset = 0; |
264 | } | ||
265 | rest -= chunk; | ||
266 | } | 259 | } |
267 | while (rest); | 260 | rest -= chunk; |
268 | 261 | } while (rest); | |
262 | |||
269 | return size; | 263 | return size; |
270 | } | 264 | } |
271 | 265 | ||
272 | /* non-copying interface: provide pointer to available data in buffer | 266 | /* non-copying interface: provide pointer to available data in buffer |
273 | * bio_nread0: return number of available bytes | 267 | * bio_nread0: return number of available bytes |
@@ -277,32 +271,32 @@ static int bio_read(BIO *bio, char *buf, int size_) | |||
277 | */ | 271 | */ |
278 | /* WARNING: The non-copying interface is largely untested as of yet | 272 | /* WARNING: The non-copying interface is largely untested as of yet |
279 | * and may contain bugs. */ | 273 | * and may contain bugs. */ |
280 | static ossl_ssize_t bio_nread0(BIO *bio, char **buf) | 274 | static ossl_ssize_t |
281 | { | 275 | bio_nread0(BIO *bio, char **buf) |
276 | { | ||
282 | struct bio_bio_st *b, *peer_b; | 277 | struct bio_bio_st *b, *peer_b; |
283 | ossl_ssize_t num; | 278 | ossl_ssize_t num; |
284 | 279 | ||
285 | BIO_clear_retry_flags(bio); | 280 | BIO_clear_retry_flags(bio); |
286 | 281 | ||
287 | if (!bio->init) | 282 | if (!bio->init) |
288 | return 0; | 283 | return 0; |
289 | 284 | ||
290 | b = bio->ptr; | 285 | b = bio->ptr; |
291 | assert(b != NULL); | 286 | assert(b != NULL); |
292 | assert(b->peer != NULL); | 287 | assert(b->peer != NULL); |
293 | peer_b = b->peer->ptr; | 288 | peer_b = b->peer->ptr; |
294 | assert(peer_b != NULL); | 289 | assert(peer_b != NULL); |
295 | assert(peer_b->buf != NULL); | 290 | assert(peer_b->buf != NULL); |
296 | 291 | ||
297 | peer_b->request = 0; | 292 | peer_b->request = 0; |
298 | 293 | ||
299 | if (peer_b->len == 0) | 294 | if (peer_b->len == 0) { |
300 | { | ||
301 | char dummy; | 295 | char dummy; |
302 | 296 | ||
303 | /* avoid code duplication -- nothing available for reading */ | 297 | /* avoid code duplication -- nothing available for reading */ |
304 | return bio_read(bio, &dummy, 1); /* returns 0 or -1 */ | 298 | return bio_read(bio, &dummy, 1); /* returns 0 or -1 */ |
305 | } | 299 | } |
306 | 300 | ||
307 | num = peer_b->len; | 301 | num = peer_b->len; |
308 | if (peer_b->size < peer_b->offset + num) | 302 | if (peer_b->size < peer_b->offset + num) |
@@ -313,10 +307,11 @@ static ossl_ssize_t bio_nread0(BIO *bio, char **buf) | |||
313 | if (buf != NULL) | 307 | if (buf != NULL) |
314 | *buf = peer_b->buf + peer_b->offset; | 308 | *buf = peer_b->buf + peer_b->offset; |
315 | return num; | 309 | return num; |
316 | } | 310 | } |
317 | 311 | ||
318 | static ossl_ssize_t bio_nread(BIO *bio, char **buf, size_t num_) | 312 | static ossl_ssize_t |
319 | { | 313 | bio_nread(BIO *bio, char **buf, size_t num_) |
314 | { | ||
320 | struct bio_bio_st *b, *peer_b; | 315 | struct bio_bio_st *b, *peer_b; |
321 | ossl_ssize_t num, available; | 316 | ossl_ssize_t num, available; |
322 | 317 | ||
@@ -335,22 +330,21 @@ static ossl_ssize_t bio_nread(BIO *bio, char **buf, size_t num_) | |||
335 | peer_b = b->peer->ptr; | 330 | peer_b = b->peer->ptr; |
336 | 331 | ||
337 | peer_b->len -= num; | 332 | peer_b->len -= num; |
338 | if (peer_b->len) | 333 | if (peer_b->len) { |
339 | { | ||
340 | peer_b->offset += num; | 334 | peer_b->offset += num; |
341 | assert(peer_b->offset <= peer_b->size); | 335 | assert(peer_b->offset <= peer_b->size); |
342 | if (peer_b->offset == peer_b->size) | 336 | if (peer_b->offset == peer_b->size) |
343 | peer_b->offset = 0; | 337 | peer_b->offset = 0; |
344 | } | 338 | } else |
345 | else | ||
346 | peer_b->offset = 0; | 339 | peer_b->offset = 0; |
347 | 340 | ||
348 | return num; | 341 | return num; |
349 | } | 342 | } |
350 | 343 | ||
351 | 344 | ||
352 | static int bio_write(BIO *bio, const char *buf, int num_) | 345 | static int |
353 | { | 346 | bio_write(BIO *bio, const char *buf, int num_) |
347 | { | ||
354 | size_t num = num_; | 348 | size_t num = num_; |
355 | size_t rest; | 349 | size_t rest; |
356 | struct bio_bio_st *b; | 350 | struct bio_bio_st *b; |
@@ -360,38 +354,37 @@ static int bio_write(BIO *bio, const char *buf, int num_) | |||
360 | if (!bio->init || buf == NULL || num == 0) | 354 | if (!bio->init || buf == NULL || num == 0) |
361 | return 0; | 355 | return 0; |
362 | 356 | ||
363 | b = bio->ptr; | 357 | b = bio->ptr; |
358 | |||
364 | assert(b != NULL); | 359 | assert(b != NULL); |
365 | assert(b->peer != NULL); | 360 | assert(b->peer != NULL); |
366 | assert(b->buf != NULL); | 361 | assert(b->buf != NULL); |
367 | 362 | ||
368 | b->request = 0; | 363 | b->request = 0; |
369 | if (b->closed) | 364 | if (b->closed) { |
370 | { | ||
371 | /* we already closed */ | 365 | /* we already closed */ |
372 | BIOerr(BIO_F_BIO_WRITE, BIO_R_BROKEN_PIPE); | 366 | BIOerr(BIO_F_BIO_WRITE, BIO_R_BROKEN_PIPE); |
373 | return -1; | 367 | return -1; |
374 | } | 368 | } |
375 | 369 | ||
376 | assert(b->len <= b->size); | 370 | assert(b->len <= b->size); |
377 | 371 | ||
378 | if (b->len == b->size) | 372 | if (b->len == b->size) { |
379 | { | ||
380 | BIO_set_retry_write(bio); /* buffer is full */ | 373 | BIO_set_retry_write(bio); /* buffer is full */ |
381 | return -1; | 374 | return -1; |
382 | } | 375 | } |
383 | 376 | ||
384 | /* we can write */ | 377 | /* we can write */ |
385 | if (num > b->size - b->len) | 378 | if (num > b->size - b->len) |
386 | num = b->size - b->len; | 379 | num = b->size - b->len; |
387 | 380 | ||
388 | /* now write "num" bytes */ | 381 | /* now write "num" bytes */ |
389 | 382 | ||
390 | rest = num; | 383 | rest = num; |
391 | 384 | ||
392 | assert(rest > 0); | 385 | assert(rest > 0); |
393 | do /* one or two iterations */ | 386 | do /* one or two iterations */ |
394 | { | 387 | { |
395 | size_t write_offset; | 388 | size_t write_offset; |
396 | size_t chunk; | 389 | size_t chunk; |
397 | 390 | ||
@@ -407,20 +400,19 @@ static int bio_write(BIO *bio, const char *buf, int num_) | |||
407 | else | 400 | else |
408 | /* wrap around ring buffer */ | 401 | /* wrap around ring buffer */ |
409 | chunk = b->size - write_offset; | 402 | chunk = b->size - write_offset; |
410 | 403 | ||
411 | memcpy(b->buf + write_offset, buf, chunk); | 404 | memcpy(b->buf + write_offset, buf, chunk); |
412 | 405 | ||
413 | b->len += chunk; | 406 | b->len += chunk; |
414 | 407 | ||
415 | assert(b->len <= b->size); | 408 | assert(b->len <= b->size); |
416 | 409 | ||
417 | rest -= chunk; | 410 | rest -= chunk; |
418 | buf += chunk; | 411 | buf += chunk; |
419 | } | 412 | } while (rest); |
420 | while (rest); | ||
421 | 413 | ||
422 | return num; | 414 | return num; |
423 | } | 415 | } |
424 | 416 | ||
425 | /* non-copying interface: provide pointer to region to write to | 417 | /* non-copying interface: provide pointer to region to write to |
426 | * bio_nwrite0: check how much space is available | 418 | * bio_nwrite0: check how much space is available |
@@ -428,8 +420,9 @@ static int bio_write(BIO *bio, const char *buf, int num_) | |||
428 | * (example usage: bio_nwrite0(), write to buffer, bio_nwrite() | 420 | * (example usage: bio_nwrite0(), write to buffer, bio_nwrite() |
429 | * or just bio_nwrite(), write to buffer) | 421 | * or just bio_nwrite(), write to buffer) |
430 | */ | 422 | */ |
431 | static ossl_ssize_t bio_nwrite0(BIO *bio, char **buf) | 423 | static ossl_ssize_t |
432 | { | 424 | bio_nwrite0(BIO *bio, char **buf) |
425 | { | ||
433 | struct bio_bio_st *b; | 426 | struct bio_bio_st *b; |
434 | size_t num; | 427 | size_t num; |
435 | size_t write_offset; | 428 | size_t write_offset; |
@@ -439,25 +432,24 @@ static ossl_ssize_t bio_nwrite0(BIO *bio, char **buf) | |||
439 | if (!bio->init) | 432 | if (!bio->init) |
440 | return 0; | 433 | return 0; |
441 | 434 | ||
442 | b = bio->ptr; | 435 | b = bio->ptr; |
436 | |||
443 | assert(b != NULL); | 437 | assert(b != NULL); |
444 | assert(b->peer != NULL); | 438 | assert(b->peer != NULL); |
445 | assert(b->buf != NULL); | 439 | assert(b->buf != NULL); |
446 | 440 | ||
447 | b->request = 0; | 441 | b->request = 0; |
448 | if (b->closed) | 442 | if (b->closed) { |
449 | { | ||
450 | BIOerr(BIO_F_BIO_NWRITE0, BIO_R_BROKEN_PIPE); | 443 | BIOerr(BIO_F_BIO_NWRITE0, BIO_R_BROKEN_PIPE); |
451 | return -1; | 444 | return -1; |
452 | } | 445 | } |
453 | 446 | ||
454 | assert(b->len <= b->size); | 447 | assert(b->len <= b->size); |
455 | 448 | ||
456 | if (b->len == b->size) | 449 | if (b->len == b->size) { |
457 | { | ||
458 | BIO_set_retry_write(bio); | 450 | BIO_set_retry_write(bio); |
459 | return -1; | 451 | return -1; |
460 | } | 452 | } |
461 | 453 | ||
462 | num = b->size - b->len; | 454 | num = b->size - b->len; |
463 | write_offset = b->offset + b->len; | 455 | write_offset = b->offset + b->len; |
@@ -474,10 +466,11 @@ static ossl_ssize_t bio_nwrite0(BIO *bio, char **buf) | |||
474 | assert(write_offset + num <= b->size); | 466 | assert(write_offset + num <= b->size); |
475 | 467 | ||
476 | return num; | 468 | return num; |
477 | } | 469 | } |
478 | 470 | ||
479 | static ossl_ssize_t bio_nwrite(BIO *bio, char **buf, size_t num_) | 471 | static ossl_ssize_t |
480 | { | 472 | bio_nwrite(BIO *bio, char **buf, size_t num_) |
473 | { | ||
481 | struct bio_bio_st *b; | 474 | struct bio_bio_st *b; |
482 | ossl_ssize_t num, space; | 475 | ossl_ssize_t num, space; |
483 | 476 | ||
@@ -497,46 +490,39 @@ static ossl_ssize_t bio_nwrite(BIO *bio, char **buf, size_t num_) | |||
497 | assert(b->len <= b->size); | 490 | assert(b->len <= b->size); |
498 | 491 | ||
499 | return num; | 492 | return num; |
500 | } | 493 | } |
501 | 494 | ||
502 | 495 | ||
503 | static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | 496 | static long |
504 | { | 497 | bio_ctrl(BIO *bio, int cmd, long num, void *ptr) |
498 | { | ||
505 | long ret; | 499 | long ret; |
506 | struct bio_bio_st *b = bio->ptr; | 500 | struct bio_bio_st *b = bio->ptr; |
507 | 501 | ||
508 | assert(b != NULL); | 502 | assert(b != NULL); |
509 | 503 | ||
510 | switch (cmd) | 504 | switch (cmd) { |
511 | { | 505 | /* specific CTRL codes */ |
512 | /* specific CTRL codes */ | ||
513 | 506 | ||
514 | case BIO_C_SET_WRITE_BUF_SIZE: | 507 | case BIO_C_SET_WRITE_BUF_SIZE: |
515 | if (b->peer) | 508 | if (b->peer) { |
516 | { | ||
517 | BIOerr(BIO_F_BIO_CTRL, BIO_R_IN_USE); | 509 | BIOerr(BIO_F_BIO_CTRL, BIO_R_IN_USE); |
518 | ret = 0; | 510 | ret = 0; |
519 | } | 511 | } else if (num == 0) { |
520 | else if (num == 0) | ||
521 | { | ||
522 | BIOerr(BIO_F_BIO_CTRL, BIO_R_INVALID_ARGUMENT); | 512 | BIOerr(BIO_F_BIO_CTRL, BIO_R_INVALID_ARGUMENT); |
523 | ret = 0; | 513 | ret = 0; |
524 | } | 514 | } else { |
525 | else | ||
526 | { | ||
527 | size_t new_size = num; | 515 | size_t new_size = num; |
528 | 516 | ||
529 | if (b->size != new_size) | 517 | if (b->size != new_size) { |
530 | { | 518 | if (b->buf) { |
531 | if (b->buf) | ||
532 | { | ||
533 | OPENSSL_free(b->buf); | 519 | OPENSSL_free(b->buf); |
534 | b->buf = NULL; | 520 | b->buf = NULL; |
535 | } | ||
536 | b->size = new_size; | ||
537 | } | 521 | } |
538 | ret = 1; | 522 | b->size = new_size; |
539 | } | 523 | } |
524 | ret = 1; | ||
525 | } | ||
540 | break; | 526 | break; |
541 | 527 | ||
542 | case BIO_C_GET_WRITE_BUF_SIZE: | 528 | case BIO_C_GET_WRITE_BUF_SIZE: |
@@ -545,15 +531,15 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | |||
545 | 531 | ||
546 | case BIO_C_MAKE_BIO_PAIR: | 532 | case BIO_C_MAKE_BIO_PAIR: |
547 | { | 533 | { |
548 | BIO *other_bio = ptr; | 534 | BIO *other_bio = ptr; |
549 | 535 | ||
550 | if (bio_make_pair(bio, other_bio)) | 536 | if (bio_make_pair(bio, other_bio)) |
551 | ret = 1; | 537 | ret = 1; |
552 | else | 538 | else |
553 | ret = 0; | 539 | ret = 0; |
554 | } | 540 | } |
555 | break; | 541 | break; |
556 | 542 | ||
557 | case BIO_C_DESTROY_BIO_PAIR: | 543 | case BIO_C_DESTROY_BIO_PAIR: |
558 | /* Affects both BIOs in the pair -- call just once! | 544 | /* Affects both BIOs in the pair -- call just once! |
559 | * Or let BIO_free(bio1); BIO_free(bio2); do the job. */ | 545 | * Or let BIO_free(bio1); BIO_free(bio2); do the job. */ |
@@ -596,12 +582,12 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | |||
596 | /* prepare for non-copying read */ | 582 | /* prepare for non-copying read */ |
597 | ret = (long) bio_nread0(bio, ptr); | 583 | ret = (long) bio_nread0(bio, ptr); |
598 | break; | 584 | break; |
599 | 585 | ||
600 | case BIO_C_NREAD: | 586 | case BIO_C_NREAD: |
601 | /* non-copying read */ | 587 | /* non-copying read */ |
602 | ret = (long) bio_nread(bio, ptr, (size_t) num); | 588 | ret = (long) bio_nread(bio, ptr, (size_t) num); |
603 | break; | 589 | break; |
604 | 590 | ||
605 | case BIO_C_NWRITE0: | 591 | case BIO_C_NWRITE0: |
606 | /* prepare for non-copying write */ | 592 | /* prepare for non-copying write */ |
607 | ret = (long) bio_nwrite0(bio, ptr); | 593 | ret = (long) bio_nwrite0(bio, ptr); |
@@ -611,18 +597,18 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | |||
611 | /* non-copying write */ | 597 | /* non-copying write */ |
612 | ret = (long) bio_nwrite(bio, ptr, (size_t) num); | 598 | ret = (long) bio_nwrite(bio, ptr, (size_t) num); |
613 | break; | 599 | break; |
614 | |||
615 | 600 | ||
616 | /* standard CTRL codes follow */ | 601 | |
602 | /* standard CTRL codes follow */ | ||
617 | 603 | ||
618 | case BIO_CTRL_RESET: | 604 | case BIO_CTRL_RESET: |
619 | if (b->buf != NULL) | 605 | if (b->buf != NULL) { |
620 | { | ||
621 | b->len = 0; | 606 | b->len = 0; |
622 | b->offset = 0; | 607 | b->offset = 0; |
623 | } | 608 | } |
624 | ret = 0; | 609 | ret = 0; |
625 | break; | 610 | break; |
611 | |||
626 | 612 | ||
627 | case BIO_CTRL_GET_CLOSE: | 613 | case BIO_CTRL_GET_CLOSE: |
628 | ret = bio->shutdown; | 614 | ret = bio->shutdown; |
@@ -634,13 +620,11 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | |||
634 | break; | 620 | break; |
635 | 621 | ||
636 | case BIO_CTRL_PENDING: | 622 | case BIO_CTRL_PENDING: |
637 | if (b->peer != NULL) | 623 | if (b->peer != NULL) { |
638 | { | ||
639 | struct bio_bio_st *peer_b = b->peer->ptr; | 624 | struct bio_bio_st *peer_b = b->peer->ptr; |
640 | 625 | ||
641 | ret = (long) peer_b->len; | 626 | ret = (long) peer_b->len; |
642 | } | 627 | } else |
643 | else | ||
644 | ret = 0; | 628 | ret = 0; |
645 | break; | 629 | break; |
646 | 630 | ||
@@ -654,16 +638,16 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | |||
654 | case BIO_CTRL_DUP: | 638 | case BIO_CTRL_DUP: |
655 | /* See BIO_dup_chain for circumstances we have to expect. */ | 639 | /* See BIO_dup_chain for circumstances we have to expect. */ |
656 | { | 640 | { |
657 | BIO *other_bio = ptr; | 641 | BIO *other_bio = ptr; |
658 | struct bio_bio_st *other_b; | 642 | struct bio_bio_st *other_b; |
659 | 643 | ||
660 | assert(other_bio != NULL); | 644 | assert(other_bio != NULL); |
661 | other_b = other_bio->ptr; | 645 | other_b = other_bio->ptr; |
662 | assert(other_b != NULL); | 646 | assert(other_b != NULL); |
663 | 647 | ||
664 | assert(other_b->buf == NULL); /* other_bio is always fresh */ | 648 | assert(other_b->buf == NULL); /* other_bio is always fresh */ |
665 | 649 | ||
666 | other_b->size = b->size; | 650 | other_b->size = b->size; |
667 | } | 651 | } |
668 | 652 | ||
669 | ret = 1; | 653 | ret = 1; |
@@ -675,34 +659,34 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | |||
675 | 659 | ||
676 | case BIO_CTRL_EOF: | 660 | case BIO_CTRL_EOF: |
677 | { | 661 | { |
678 | BIO *other_bio = ptr; | 662 | BIO *other_bio = ptr; |
679 | 663 | ||
680 | if (other_bio) | 664 | if (other_bio) { |
681 | { | 665 | struct bio_bio_st *other_b = other_bio->ptr; |
682 | struct bio_bio_st *other_b = other_bio->ptr; | 666 | |
683 | 667 | assert(other_b != NULL); | |
684 | assert(other_b != NULL); | 668 | ret = other_b->len == 0 && other_b->closed; |
685 | ret = other_b->len == 0 && other_b->closed; | 669 | } else |
686 | } | 670 | ret = 1; |
687 | else | ||
688 | ret = 1; | ||
689 | } | 671 | } |
690 | break; | 672 | break; |
691 | 673 | ||
692 | default: | 674 | default: |
693 | ret = 0; | 675 | ret = 0; |
694 | } | ||
695 | return ret; | ||
696 | } | 676 | } |
677 | return ret; | ||
678 | } | ||
697 | 679 | ||
698 | static int bio_puts(BIO *bio, const char *str) | 680 | static int |
699 | { | 681 | bio_puts(BIO *bio, const char *str) |
682 | { | ||
700 | return bio_write(bio, str, strlen(str)); | 683 | return bio_write(bio, str, strlen(str)); |
701 | } | 684 | } |
702 | 685 | ||
703 | 686 | ||
704 | static int bio_make_pair(BIO *bio1, BIO *bio2) | 687 | static int |
705 | { | 688 | bio_make_pair(BIO *bio1, BIO *bio2) |
689 | { | ||
706 | struct bio_bio_st *b1, *b2; | 690 | struct bio_bio_st *b1, *b2; |
707 | 691 | ||
708 | assert(bio1 != NULL); | 692 | assert(bio1 != NULL); |
@@ -710,37 +694,32 @@ static int bio_make_pair(BIO *bio1, BIO *bio2) | |||
710 | 694 | ||
711 | b1 = bio1->ptr; | 695 | b1 = bio1->ptr; |
712 | b2 = bio2->ptr; | 696 | b2 = bio2->ptr; |
713 | 697 | ||
714 | if (b1->peer != NULL || b2->peer != NULL) | 698 | if (b1->peer != NULL || b2->peer != NULL) { |
715 | { | ||
716 | BIOerr(BIO_F_BIO_MAKE_PAIR, BIO_R_IN_USE); | 699 | BIOerr(BIO_F_BIO_MAKE_PAIR, BIO_R_IN_USE); |
717 | return 0; | 700 | return 0; |
718 | } | 701 | } |
719 | 702 | ||
720 | if (b1->buf == NULL) | 703 | if (b1->buf == NULL) { |
721 | { | ||
722 | b1->buf = OPENSSL_malloc(b1->size); | 704 | b1->buf = OPENSSL_malloc(b1->size); |
723 | if (b1->buf == NULL) | 705 | if (b1->buf == NULL) { |
724 | { | ||
725 | BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); | 706 | BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); |
726 | return 0; | 707 | return 0; |
727 | } | 708 | } |
728 | b1->len = 0; | 709 | b1->len = 0; |
729 | b1->offset = 0; | 710 | b1->offset = 0; |
730 | } | 711 | } |
731 | 712 | ||
732 | if (b2->buf == NULL) | 713 | if (b2->buf == NULL) { |
733 | { | ||
734 | b2->buf = OPENSSL_malloc(b2->size); | 714 | b2->buf = OPENSSL_malloc(b2->size); |
735 | if (b2->buf == NULL) | 715 | if (b2->buf == NULL) { |
736 | { | ||
737 | BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); | 716 | BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); |
738 | return 0; | 717 | return 0; |
739 | } | 718 | } |
740 | b2->len = 0; | 719 | b2->len = 0; |
741 | b2->offset = 0; | 720 | b2->offset = 0; |
742 | } | 721 | } |
743 | 722 | ||
744 | b1->peer = bio2; | 723 | b1->peer = bio2; |
745 | b1->closed = 0; | 724 | b1->closed = 0; |
746 | b1->request = 0; | 725 | b1->request = 0; |
@@ -752,18 +731,17 @@ static int bio_make_pair(BIO *bio1, BIO *bio2) | |||
752 | bio2->init = 1; | 731 | bio2->init = 1; |
753 | 732 | ||
754 | return 1; | 733 | return 1; |
755 | } | 734 | } |
756 | 735 | ||
757 | static void bio_destroy_pair(BIO *bio) | 736 | static void |
758 | { | 737 | bio_destroy_pair(BIO *bio) |
738 | { | ||
759 | struct bio_bio_st *b = bio->ptr; | 739 | struct bio_bio_st *b = bio->ptr; |
760 | 740 | ||
761 | if (b != NULL) | 741 | if (b != NULL) { |
762 | { | ||
763 | BIO *peer_bio = b->peer; | 742 | BIO *peer_bio = b->peer; |
764 | 743 | ||
765 | if (peer_bio != NULL) | 744 | if (peer_bio != NULL) { |
766 | { | ||
767 | struct bio_bio_st *peer_b = peer_bio->ptr; | 745 | struct bio_bio_st *peer_b = peer_bio->ptr; |
768 | 746 | ||
769 | assert(peer_b != NULL); | 747 | assert(peer_b != NULL); |
@@ -774,151 +752,149 @@ static void bio_destroy_pair(BIO *bio) | |||
774 | assert(peer_b->buf != NULL); | 752 | assert(peer_b->buf != NULL); |
775 | peer_b->len = 0; | 753 | peer_b->len = 0; |
776 | peer_b->offset = 0; | 754 | peer_b->offset = 0; |
777 | 755 | ||
778 | b->peer = NULL; | 756 | b->peer = NULL; |
779 | bio->init = 0; | 757 | bio->init = 0; |
780 | assert(b->buf != NULL); | 758 | assert(b->buf != NULL); |
781 | b->len = 0; | 759 | b->len = 0; |
782 | b->offset = 0; | 760 | b->offset = 0; |
783 | } | ||
784 | } | 761 | } |
785 | } | 762 | } |
786 | 763 | } | |
764 | |||
787 | 765 | ||
788 | /* Exported convenience functions */ | 766 | /* Exported convenience functions */ |
789 | int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1, | 767 | int |
790 | BIO **bio2_p, size_t writebuf2) | 768 | BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1, BIO **bio2_p, size_t writebuf2) |
791 | { | 769 | { |
792 | BIO *bio1 = NULL, *bio2 = NULL; | 770 | BIO *bio1 = NULL, *bio2 = NULL; |
793 | long r; | 771 | long r; |
794 | int ret = 0; | 772 | int ret = 0; |
795 | 773 | ||
796 | bio1 = BIO_new(BIO_s_bio()); | 774 | bio1 = BIO_new(BIO_s_bio()); |
797 | if (bio1 == NULL) | 775 | if (bio1 == NULL) |
798 | goto err; | 776 | goto err; |
799 | bio2 = BIO_new(BIO_s_bio()); | 777 | bio2 = BIO_new(BIO_s_bio()); |
800 | if (bio2 == NULL) | 778 | if (bio2 == NULL) |
801 | goto err; | 779 | goto err; |
802 | 780 | ||
803 | if (writebuf1) | 781 | if (writebuf1) { |
804 | { | 782 | r = BIO_set_write_buf_size(bio1, writebuf1); |
805 | r = BIO_set_write_buf_size(bio1, writebuf1); | 783 | if (!r) |
806 | if (!r) | 784 | goto err; |
807 | goto err; | 785 | } |
808 | } | 786 | if (writebuf2) { |
809 | if (writebuf2) | 787 | r = BIO_set_write_buf_size(bio2, writebuf2); |
810 | { | 788 | if (!r) |
811 | r = BIO_set_write_buf_size(bio2, writebuf2); | 789 | goto err; |
812 | if (!r) | ||
813 | goto err; | ||
814 | } | ||
815 | |||
816 | r = BIO_make_bio_pair(bio1, bio2); | ||
817 | if (!r) | ||
818 | goto err; | ||
819 | ret = 1; | ||
820 | |||
821 | err: | ||
822 | if (ret == 0) | ||
823 | { | ||
824 | if (bio1) | ||
825 | { | ||
826 | BIO_free(bio1); | ||
827 | bio1 = NULL; | ||
828 | } | ||
829 | if (bio2) | ||
830 | { | ||
831 | BIO_free(bio2); | ||
832 | bio2 = NULL; | ||
833 | } | ||
834 | } | ||
835 | |||
836 | *bio1_p = bio1; | ||
837 | *bio2_p = bio2; | ||
838 | return ret; | ||
839 | } | ||
840 | |||
841 | size_t BIO_ctrl_get_write_guarantee(BIO *bio) | ||
842 | { | ||
843 | return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL); | ||
844 | } | 790 | } |
845 | 791 | ||
846 | size_t BIO_ctrl_get_read_request(BIO *bio) | 792 | r = BIO_make_bio_pair(bio1, bio2); |
847 | { | 793 | if (!r) |
848 | return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL); | 794 | goto err; |
795 | ret = 1; | ||
796 | |||
797 | err: | ||
798 | if (ret == 0) { | ||
799 | if (bio1) { | ||
800 | BIO_free(bio1); | ||
801 | bio1 = NULL; | ||
802 | } | ||
803 | if (bio2) { | ||
804 | BIO_free(bio2); | ||
805 | bio2 = NULL; | ||
806 | } | ||
849 | } | 807 | } |
850 | 808 | ||
851 | int BIO_ctrl_reset_read_request(BIO *bio) | 809 | *bio1_p = bio1; |
852 | { | 810 | *bio2_p = bio2; |
811 | return ret; | ||
812 | } | ||
813 | |||
814 | size_t | ||
815 | BIO_ctrl_get_write_guarantee(BIO *bio) | ||
816 | { | ||
817 | return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL); | ||
818 | } | ||
819 | |||
820 | size_t | ||
821 | BIO_ctrl_get_read_request(BIO *bio) | ||
822 | { | ||
823 | return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL); | ||
824 | } | ||
825 | |||
826 | int | ||
827 | BIO_ctrl_reset_read_request(BIO *bio) | ||
828 | { | ||
853 | return (BIO_ctrl(bio, BIO_C_RESET_READ_REQUEST, 0, NULL) != 0); | 829 | return (BIO_ctrl(bio, BIO_C_RESET_READ_REQUEST, 0, NULL) != 0); |
854 | } | 830 | } |
855 | 831 | ||
856 | 832 | ||
857 | /* BIO_nread0/nread/nwrite0/nwrite are available only for BIO pairs for now | 833 | /* BIO_nread0/nread/nwrite0/nwrite are available only for BIO pairs for now |
858 | * (conceivably some other BIOs could allow non-copying reads and writes too.) | 834 | * (conceivably some other BIOs could allow non-copying reads and writes too.) |
859 | */ | 835 | */ |
860 | int BIO_nread0(BIO *bio, char **buf) | 836 | int |
861 | { | 837 | BIO_nread0(BIO *bio, char **buf) |
838 | { | ||
862 | long ret; | 839 | long ret; |
863 | 840 | ||
864 | if (!bio->init) | 841 | if (!bio->init) { |
865 | { | ||
866 | BIOerr(BIO_F_BIO_NREAD0, BIO_R_UNINITIALIZED); | 842 | BIOerr(BIO_F_BIO_NREAD0, BIO_R_UNINITIALIZED); |
867 | return -2; | 843 | return -2; |
868 | } | 844 | } |
869 | 845 | ||
870 | ret = BIO_ctrl(bio, BIO_C_NREAD0, 0, buf); | 846 | ret = BIO_ctrl(bio, BIO_C_NREAD0, 0, buf); |
871 | if (ret > INT_MAX) | 847 | if (ret > INT_MAX) |
872 | return INT_MAX; | 848 | return INT_MAX; |
873 | else | 849 | else |
874 | return (int) ret; | 850 | return (int) ret; |
875 | } | 851 | } |
876 | 852 | ||
877 | int BIO_nread(BIO *bio, char **buf, int num) | 853 | int |
878 | { | 854 | BIO_nread(BIO *bio, char **buf, int num) |
855 | { | ||
879 | int ret; | 856 | int ret; |
880 | 857 | ||
881 | if (!bio->init) | 858 | if (!bio->init) { |
882 | { | ||
883 | BIOerr(BIO_F_BIO_NREAD, BIO_R_UNINITIALIZED); | 859 | BIOerr(BIO_F_BIO_NREAD, BIO_R_UNINITIALIZED); |
884 | return -2; | 860 | return -2; |
885 | } | 861 | } |
886 | 862 | ||
887 | ret = (int) BIO_ctrl(bio, BIO_C_NREAD, num, buf); | 863 | ret = (int) BIO_ctrl(bio, BIO_C_NREAD, num, buf); |
888 | if (ret > 0) | 864 | if (ret > 0) |
889 | bio->num_read += ret; | 865 | bio->num_read += ret; |
890 | return ret; | 866 | return ret; |
891 | } | 867 | } |
892 | 868 | ||
893 | int BIO_nwrite0(BIO *bio, char **buf) | 869 | int |
894 | { | 870 | BIO_nwrite0(BIO *bio, char **buf) |
871 | { | ||
895 | long ret; | 872 | long ret; |
896 | 873 | ||
897 | if (!bio->init) | 874 | if (!bio->init) { |
898 | { | ||
899 | BIOerr(BIO_F_BIO_NWRITE0, BIO_R_UNINITIALIZED); | 875 | BIOerr(BIO_F_BIO_NWRITE0, BIO_R_UNINITIALIZED); |
900 | return -2; | 876 | return -2; |
901 | } | 877 | } |
902 | 878 | ||
903 | ret = BIO_ctrl(bio, BIO_C_NWRITE0, 0, buf); | 879 | ret = BIO_ctrl(bio, BIO_C_NWRITE0, 0, buf); |
904 | if (ret > INT_MAX) | 880 | if (ret > INT_MAX) |
905 | return INT_MAX; | 881 | return INT_MAX; |
906 | else | 882 | else |
907 | return (int) ret; | 883 | return (int) ret; |
908 | } | 884 | } |
909 | 885 | ||
910 | int BIO_nwrite(BIO *bio, char **buf, int num) | 886 | int |
911 | { | 887 | BIO_nwrite(BIO *bio, char **buf, int num) |
888 | { | ||
912 | int ret; | 889 | int ret; |
913 | 890 | ||
914 | if (!bio->init) | 891 | if (!bio->init) { |
915 | { | ||
916 | BIOerr(BIO_F_BIO_NWRITE, BIO_R_UNINITIALIZED); | 892 | BIOerr(BIO_F_BIO_NWRITE, BIO_R_UNINITIALIZED); |
917 | return -2; | 893 | return -2; |
918 | } | 894 | } |
919 | 895 | ||
920 | ret = BIO_ctrl(bio, BIO_C_NWRITE, num, buf); | 896 | ret = BIO_ctrl(bio, BIO_C_NWRITE, num, buf); |
921 | if (ret > 0) | 897 | if (ret > 0) |
922 | bio->num_write += ret; | 898 | bio->num_write += ret; |
923 | return ret; | 899 | return ret; |
924 | } | 900 | } |
diff --git a/src/lib/libssl/src/crypto/bio/bss_conn.c b/src/lib/libssl/src/crypto/bio/bss_conn.c index 5162e75c87..df34c49a4a 100644 --- a/src/lib/libssl/src/crypto/bio/bss_conn.c +++ b/src/lib/libssl/src/crypto/bio/bss_conn.c | |||
@@ -76,8 +76,7 @@ | |||
76 | #endif | 76 | #endif |
77 | 77 | ||
78 | 78 | ||
79 | typedef struct bio_connect_st | 79 | typedef struct bio_connect_st { |
80 | { | ||
81 | int state; | 80 | int state; |
82 | 81 | ||
83 | char *param_hostname; | 82 | char *param_hostname; |
@@ -95,8 +94,8 @@ typedef struct bio_connect_st | |||
95 | /* called when the connection is initially made | 94 | /* called when the connection is initially made |
96 | * callback(BIO,state,ret); The callback should return | 95 | * callback(BIO,state,ret); The callback should return |
97 | * 'ret'. state is for compatibility with the ssl info_callback */ | 96 | * 'ret'. state is for compatibility with the ssl info_callback */ |
98 | int (*info_callback)(const BIO *bio,int state,int ret); | 97 | int (*info_callback)(const BIO *bio, int state, int ret); |
99 | } BIO_CONNECT; | 98 | } BIO_CONNECT; |
100 | 99 | ||
101 | static int conn_write(BIO *h, const char *buf, int num); | 100 | static int conn_write(BIO *h, const char *buf, int num); |
102 | static int conn_read(BIO *h, char *buf, int size); | 101 | static int conn_read(BIO *h, char *buf, int size); |
@@ -108,11 +107,10 @@ static long conn_callback_ctrl(BIO *h, int cmd, bio_info_cb *); | |||
108 | 107 | ||
109 | static int conn_state(BIO *b, BIO_CONNECT *c); | 108 | static int conn_state(BIO *b, BIO_CONNECT *c); |
110 | static void conn_close_socket(BIO *data); | 109 | static void conn_close_socket(BIO *data); |
111 | BIO_CONNECT *BIO_CONNECT_new(void ); | 110 | BIO_CONNECT *BIO_CONNECT_new(void); |
112 | void BIO_CONNECT_free(BIO_CONNECT *a); | 111 | void BIO_CONNECT_free(BIO_CONNECT *a); |
113 | 112 | ||
114 | static BIO_METHOD methods_connectp= | 113 | static BIO_METHOD methods_connectp = { |
115 | { | ||
116 | BIO_TYPE_CONNECT, | 114 | BIO_TYPE_CONNECT, |
117 | "socket connect", | 115 | "socket connect", |
118 | conn_write, | 116 | conn_write, |
@@ -123,530 +121,501 @@ static BIO_METHOD methods_connectp= | |||
123 | conn_new, | 121 | conn_new, |
124 | conn_free, | 122 | conn_free, |
125 | conn_callback_ctrl, | 123 | conn_callback_ctrl, |
126 | }; | 124 | }; |
127 | 125 | ||
128 | static int conn_state(BIO *b, BIO_CONNECT *c) | 126 | static int |
129 | { | 127 | conn_state(BIO *b, BIO_CONNECT *c) |
130 | int ret= -1,i; | 128 | { |
129 | int ret = -1, i; | ||
131 | unsigned long l; | 130 | unsigned long l; |
132 | char *p,*q; | 131 | char *p, *q; |
133 | int (*cb)(const BIO *,int,int)=NULL; | 132 | int (*cb)(const BIO *, int, int) = NULL; |
134 | 133 | ||
135 | if (c->info_callback != NULL) | 134 | if (c->info_callback != NULL) |
136 | cb=c->info_callback; | 135 | cb = c->info_callback; |
137 | 136 | ||
138 | for (;;) | 137 | for (;;) { |
139 | { | 138 | switch (c->state) { |
140 | switch (c->state) | ||
141 | { | ||
142 | case BIO_CONN_S_BEFORE: | 139 | case BIO_CONN_S_BEFORE: |
143 | p=c->param_hostname; | 140 | p = c->param_hostname; |
144 | if (p == NULL) | 141 | if (p == NULL) { |
145 | { | 142 | BIOerr(BIO_F_CONN_STATE, BIO_R_NO_HOSTNAME_SPECIFIED); |
146 | BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTNAME_SPECIFIED); | ||
147 | goto exit_loop; | 143 | goto exit_loop; |
148 | } | 144 | } |
149 | for ( ; *p != '\0'; p++) | 145 | for (; *p != '\0'; p++) { |
150 | { | 146 | if ((*p == ':') || (*p == '/')) |
151 | if ((*p == ':') || (*p == '/')) break; | 147 | break; |
152 | } | 148 | } |
153 | 149 | ||
154 | i= *p; | 150 | i= *p; |
155 | if ((i == ':') || (i == '/')) | 151 | if ((i == ':') || (i == '/')) { |
156 | { | 152 | *(p++) = '\0'; |
157 | 153 | if (i == ':') { | |
158 | *(p++)='\0'; | 154 | for (q = p; *q; q++) |
159 | if (i == ':') | 155 | if (*q == '/') { |
160 | { | 156 | *q = '\0'; |
161 | for (q=p; *q; q++) | ||
162 | if (*q == '/') | ||
163 | { | ||
164 | *q='\0'; | ||
165 | break; | 157 | break; |
166 | } | 158 | } |
167 | if (c->param_port != NULL) | 159 | if (c->param_port != NULL) |
168 | OPENSSL_free(c->param_port); | 160 | OPENSSL_free(c->param_port); |
169 | c->param_port=BUF_strdup(p); | 161 | c->param_port = BUF_strdup(p); |
170 | } | ||
171 | } | 162 | } |
163 | } | ||
172 | 164 | ||
173 | if (c->param_port == NULL) | 165 | if (c->param_port == NULL) { |
174 | { | 166 | BIOerr(BIO_F_CONN_STATE, BIO_R_NO_PORT_SPECIFIED); |
175 | BIOerr(BIO_F_CONN_STATE,BIO_R_NO_PORT_SPECIFIED); | 167 | ERR_add_error_data(2, "host=", c->param_hostname); |
176 | ERR_add_error_data(2,"host=",c->param_hostname); | ||
177 | goto exit_loop; | 168 | goto exit_loop; |
178 | } | 169 | } |
179 | c->state=BIO_CONN_S_GET_IP; | 170 | c->state = BIO_CONN_S_GET_IP; |
180 | break; | 171 | break; |
181 | 172 | ||
182 | case BIO_CONN_S_GET_IP: | 173 | case BIO_CONN_S_GET_IP: |
183 | if (BIO_get_host_ip(c->param_hostname,&(c->ip[0])) <= 0) | 174 | if (BIO_get_host_ip(c->param_hostname, &(c->ip[0])) <= 0) |
184 | goto exit_loop; | 175 | goto exit_loop; |
185 | c->state=BIO_CONN_S_GET_PORT; | 176 | c->state = BIO_CONN_S_GET_PORT; |
186 | break; | 177 | break; |
187 | 178 | ||
188 | case BIO_CONN_S_GET_PORT: | 179 | case BIO_CONN_S_GET_PORT: |
189 | if (c->param_port == NULL) | 180 | if (c->param_port == NULL) { |
190 | { | ||
191 | /* abort(); */ | 181 | /* abort(); */ |
192 | goto exit_loop; | 182 | goto exit_loop; |
193 | } | 183 | } else if (BIO_get_port(c->param_port, &c->port) <= 0) |
194 | else if (BIO_get_port(c->param_port,&c->port) <= 0) | ||
195 | goto exit_loop; | 184 | goto exit_loop; |
196 | c->state=BIO_CONN_S_CREATE_SOCKET; | 185 | c->state = BIO_CONN_S_CREATE_SOCKET; |
197 | break; | 186 | break; |
198 | 187 | ||
199 | case BIO_CONN_S_CREATE_SOCKET: | 188 | case BIO_CONN_S_CREATE_SOCKET: |
200 | /* now setup address */ | 189 | /* now setup address */ |
201 | memset((char *)&c->them,0,sizeof(c->them)); | 190 | memset((char *)&c->them, 0, sizeof(c->them)); |
202 | c->them.sin_family=AF_INET; | 191 | c->them.sin_family = AF_INET; |
203 | c->them.sin_port=htons((unsigned short)c->port); | 192 | c->them.sin_port = htons((unsigned short)c->port); |
204 | l=(unsigned long) | 193 | l = (unsigned long) |
205 | ((unsigned long)c->ip[0]<<24L)| | 194 | ((unsigned long)c->ip[0] << 24L)| |
206 | ((unsigned long)c->ip[1]<<16L)| | 195 | ((unsigned long)c->ip[1] << 16L)| |
207 | ((unsigned long)c->ip[2]<< 8L)| | 196 | ((unsigned long)c->ip[2] << 8L)| |
208 | ((unsigned long)c->ip[3]); | 197 | ((unsigned long)c->ip[3]); |
209 | c->them.sin_addr.s_addr=htonl(l); | 198 | c->them.sin_addr.s_addr = htonl(l); |
210 | c->state=BIO_CONN_S_CREATE_SOCKET; | 199 | c->state = BIO_CONN_S_CREATE_SOCKET; |
211 | 200 | ||
212 | ret=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); | 201 | ret = socket(AF_INET, SOCK_STREAM, SOCKET_PROTOCOL); |
213 | if (ret == -1) | 202 | if (ret == -1) { |
214 | { | 203 | SYSerr(SYS_F_SOCKET, errno); |
215 | SYSerr(SYS_F_SOCKET,errno); | 204 | ERR_add_error_data(4, "host=", |
216 | ERR_add_error_data(4,"host=",c->param_hostname, | 205 | c->param_hostname, ":", c->param_port); |
217 | ":",c->param_port); | 206 | BIOerr(BIO_F_CONN_STATE, |
218 | BIOerr(BIO_F_CONN_STATE,BIO_R_UNABLE_TO_CREATE_SOCKET); | 207 | BIO_R_UNABLE_TO_CREATE_SOCKET); |
219 | goto exit_loop; | 208 | goto exit_loop; |
220 | } | 209 | } |
221 | b->num=ret; | 210 | b->num = ret; |
222 | c->state=BIO_CONN_S_NBIO; | 211 | c->state = BIO_CONN_S_NBIO; |
223 | break; | 212 | break; |
224 | 213 | ||
225 | case BIO_CONN_S_NBIO: | 214 | case BIO_CONN_S_NBIO: |
226 | if (c->nbio) | 215 | if (c->nbio) { |
227 | { | 216 | if (!BIO_socket_nbio(b->num, 1)) { |
228 | if (!BIO_socket_nbio(b->num,1)) | 217 | BIOerr(BIO_F_CONN_STATE, |
229 | { | 218 | BIO_R_ERROR_SETTING_NBIO); |
230 | BIOerr(BIO_F_CONN_STATE,BIO_R_ERROR_SETTING_NBIO); | 219 | ERR_add_error_data(4, "host=", |
231 | ERR_add_error_data(4,"host=", | 220 | c->param_hostname, ":", |
232 | c->param_hostname, | 221 | c->param_port); |
233 | ":",c->param_port); | ||
234 | goto exit_loop; | 222 | goto exit_loop; |
235 | } | ||
236 | } | 223 | } |
237 | c->state=BIO_CONN_S_CONNECT; | 224 | } |
225 | c->state = BIO_CONN_S_CONNECT; | ||
238 | 226 | ||
239 | #if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE) | 227 | #if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE) |
240 | i=1; | 228 | i = 1; |
241 | i=setsockopt(b->num,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i)); | 229 | i = setsockopt(b->num, SOL_SOCKET, SO_KEEPALIVE,(char *)&i, sizeof(i)); |
242 | if (i < 0) | 230 | if (i < 0) { |
243 | { | 231 | SYSerr(SYS_F_SOCKET, errno); |
244 | SYSerr(SYS_F_SOCKET,errno); | 232 | ERR_add_error_data(4, "host=", |
245 | ERR_add_error_data(4,"host=",c->param_hostname, | 233 | c->param_hostname, ":", c->param_port); |
246 | ":",c->param_port); | 234 | BIOerr(BIO_F_CONN_STATE, BIO_R_KEEPALIVE); |
247 | BIOerr(BIO_F_CONN_STATE,BIO_R_KEEPALIVE); | ||
248 | goto exit_loop; | 235 | goto exit_loop; |
249 | } | 236 | } |
250 | #endif | 237 | #endif |
251 | break; | 238 | break; |
252 | 239 | ||
253 | case BIO_CONN_S_CONNECT: | 240 | case BIO_CONN_S_CONNECT: |
254 | BIO_clear_retry_flags(b); | 241 | BIO_clear_retry_flags(b); |
255 | ret=connect(b->num, | 242 | ret = connect(b->num, |
256 | (struct sockaddr *)&c->them, | 243 | (struct sockaddr *)&c->them, |
257 | sizeof(c->them)); | 244 | sizeof(c->them)); |
258 | b->retry_reason=0; | 245 | b->retry_reason = 0; |
259 | if (ret < 0) | 246 | if (ret < 0) { |
260 | { | 247 | if (BIO_sock_should_retry(ret)) { |
261 | if (BIO_sock_should_retry(ret)) | ||
262 | { | ||
263 | BIO_set_retry_special(b); | 248 | BIO_set_retry_special(b); |
264 | c->state=BIO_CONN_S_BLOCKED_CONNECT; | 249 | c->state = BIO_CONN_S_BLOCKED_CONNECT; |
265 | b->retry_reason=BIO_RR_CONNECT; | 250 | b->retry_reason = BIO_RR_CONNECT; |
266 | } | 251 | } else { |
267 | else | 252 | SYSerr(SYS_F_CONNECT, errno); |
268 | { | 253 | ERR_add_error_data(4, "host=", |
269 | SYSerr(SYS_F_CONNECT,errno); | 254 | c->param_hostname, ":", |
270 | ERR_add_error_data(4,"host=", | 255 | c->param_port); |
271 | c->param_hostname, | 256 | BIOerr(BIO_F_CONN_STATE, |
272 | ":",c->param_port); | 257 | BIO_R_CONNECT_ERROR); |
273 | BIOerr(BIO_F_CONN_STATE,BIO_R_CONNECT_ERROR); | ||
274 | } | ||
275 | goto exit_loop; | ||
276 | } | 258 | } |
277 | else | 259 | goto exit_loop; |
278 | c->state=BIO_CONN_S_OK; | 260 | } else |
261 | c->state = BIO_CONN_S_OK; | ||
279 | break; | 262 | break; |
280 | 263 | ||
281 | case BIO_CONN_S_BLOCKED_CONNECT: | 264 | case BIO_CONN_S_BLOCKED_CONNECT: |
282 | i=BIO_sock_error(b->num); | 265 | i = BIO_sock_error(b->num); |
283 | if (i) | 266 | if (i) { |
284 | { | ||
285 | BIO_clear_retry_flags(b); | 267 | BIO_clear_retry_flags(b); |
286 | SYSerr(SYS_F_CONNECT,i); | 268 | SYSerr(SYS_F_CONNECT, i); |
287 | ERR_add_error_data(4,"host=", | 269 | ERR_add_error_data(4, "host=", |
288 | c->param_hostname, | 270 | c->param_hostname, ":", c->param_port); |
289 | ":",c->param_port); | 271 | BIOerr(BIO_F_CONN_STATE, |
290 | BIOerr(BIO_F_CONN_STATE,BIO_R_NBIO_CONNECT_ERROR); | 272 | BIO_R_NBIO_CONNECT_ERROR); |
291 | ret=0; | 273 | ret = 0; |
292 | goto exit_loop; | 274 | goto exit_loop; |
293 | } | 275 | } else |
294 | else | 276 | c->state = BIO_CONN_S_OK; |
295 | c->state=BIO_CONN_S_OK; | ||
296 | break; | 277 | break; |
297 | 278 | ||
298 | case BIO_CONN_S_OK: | 279 | case BIO_CONN_S_OK: |
299 | ret=1; | 280 | ret = 1; |
300 | goto exit_loop; | 281 | goto exit_loop; |
301 | default: | 282 | default: |
302 | /* abort(); */ | 283 | /* abort(); */ |
303 | goto exit_loop; | 284 | goto exit_loop; |
304 | } | 285 | } |
305 | 286 | ||
306 | if (cb != NULL) | 287 | if (cb != NULL) { |
307 | { | 288 | if (!(ret = cb((BIO *)b, c->state, ret))) |
308 | if (!(ret=cb((BIO *)b,c->state,ret))) | ||
309 | goto end; | 289 | goto end; |
310 | } | ||
311 | } | 290 | } |
291 | } | ||
312 | 292 | ||
313 | /* Loop does not exit */ | 293 | /* Loop does not exit */ |
314 | exit_loop: | 294 | exit_loop: |
315 | if (cb != NULL) | 295 | if (cb != NULL) |
316 | ret=cb((BIO *)b,c->state,ret); | 296 | ret = cb((BIO *)b, c->state, ret); |
317 | end: | 297 | end: |
318 | return(ret); | 298 | return (ret); |
319 | } | 299 | } |
320 | 300 | ||
321 | BIO_CONNECT *BIO_CONNECT_new(void) | 301 | BIO_CONNECT |
322 | { | 302 | *BIO_CONNECT_new(void) |
303 | { | ||
323 | BIO_CONNECT *ret; | 304 | BIO_CONNECT *ret; |
324 | 305 | ||
325 | if ((ret=(BIO_CONNECT *)OPENSSL_malloc(sizeof(BIO_CONNECT))) == NULL) | 306 | if ((ret = (BIO_CONNECT *)OPENSSL_malloc(sizeof(BIO_CONNECT))) == NULL) |
326 | return(NULL); | 307 | return (NULL); |
327 | ret->state=BIO_CONN_S_BEFORE; | 308 | ret->state = BIO_CONN_S_BEFORE; |
328 | ret->param_hostname=NULL; | 309 | ret->param_hostname = NULL; |
329 | ret->param_port=NULL; | 310 | ret->param_port = NULL; |
330 | ret->info_callback=NULL; | 311 | ret->info_callback = NULL; |
331 | ret->nbio=0; | 312 | ret->nbio = 0; |
332 | ret->ip[0]=0; | 313 | ret->ip[0] = 0; |
333 | ret->ip[1]=0; | 314 | ret->ip[1] = 0; |
334 | ret->ip[2]=0; | 315 | ret->ip[2] = 0; |
335 | ret->ip[3]=0; | 316 | ret->ip[3] = 0; |
336 | ret->port=0; | 317 | ret->port = 0; |
337 | memset((char *)&ret->them,0,sizeof(ret->them)); | 318 | memset((char *)&ret->them, 0, sizeof(ret->them)); |
338 | return(ret); | 319 | return (ret); |
339 | } | 320 | } |
340 | 321 | ||
341 | void BIO_CONNECT_free(BIO_CONNECT *a) | 322 | void |
342 | { | 323 | BIO_CONNECT_free(BIO_CONNECT *a) |
343 | if(a == NULL) | 324 | { |
344 | return; | 325 | if (a == NULL) |
326 | return; | ||
345 | 327 | ||
346 | if (a->param_hostname != NULL) | 328 | if (a->param_hostname != NULL) |
347 | OPENSSL_free(a->param_hostname); | 329 | OPENSSL_free(a->param_hostname); |
348 | if (a->param_port != NULL) | 330 | if (a->param_port != NULL) |
349 | OPENSSL_free(a->param_port); | 331 | OPENSSL_free(a->param_port); |
350 | OPENSSL_free(a); | 332 | OPENSSL_free(a); |
351 | } | 333 | } |
352 | 334 | ||
353 | BIO_METHOD *BIO_s_connect(void) | 335 | BIO_METHOD |
354 | { | 336 | *BIO_s_connect(void) |
355 | return(&methods_connectp); | 337 | { |
356 | } | 338 | return (&methods_connectp); |
357 | 339 | } | |
358 | static int conn_new(BIO *bi) | 340 | |
359 | { | 341 | static int |
360 | bi->init=0; | 342 | conn_new(BIO *bi) |
361 | bi->num=-1; | 343 | { |
362 | bi->flags=0; | 344 | bi->init = 0; |
363 | if ((bi->ptr=(char *)BIO_CONNECT_new()) == NULL) | 345 | bi->num = -1; |
364 | return(0); | 346 | bi->flags = 0; |
347 | if ((bi->ptr = (char *)BIO_CONNECT_new()) == NULL) | ||
348 | return (0); | ||
365 | else | 349 | else |
366 | return(1); | 350 | return (1); |
367 | } | 351 | } |
368 | 352 | ||
369 | static void conn_close_socket(BIO *bio) | 353 | static void |
370 | { | 354 | conn_close_socket(BIO *bio) |
355 | { | ||
371 | BIO_CONNECT *c; | 356 | BIO_CONNECT *c; |
372 | 357 | ||
373 | c=(BIO_CONNECT *)bio->ptr; | 358 | c = (BIO_CONNECT *)bio->ptr; |
374 | if (bio->num != -1) | 359 | if (bio->num != -1) { |
375 | { | ||
376 | /* Only do a shutdown if things were established */ | 360 | /* Only do a shutdown if things were established */ |
377 | if (c->state == BIO_CONN_S_OK) | 361 | if (c->state == BIO_CONN_S_OK) |
378 | shutdown(bio->num, SHUT_RDWR); | 362 | shutdown(bio->num, SHUT_RDWR); |
379 | close(bio->num); | 363 | close(bio->num); |
380 | bio->num=-1; | 364 | bio->num = -1; |
381 | } | ||
382 | } | 365 | } |
366 | } | ||
383 | 367 | ||
384 | static int conn_free(BIO *a) | 368 | static int |
385 | { | 369 | conn_free(BIO *a) |
370 | { | ||
386 | BIO_CONNECT *data; | 371 | BIO_CONNECT *data; |
387 | 372 | ||
388 | if (a == NULL) return(0); | 373 | if (a == NULL) |
389 | data=(BIO_CONNECT *)a->ptr; | 374 | return (0); |
390 | 375 | data = (BIO_CONNECT *)a->ptr; | |
391 | if (a->shutdown) | 376 | |
392 | { | 377 | if (a->shutdown) { |
393 | conn_close_socket(a); | 378 | conn_close_socket(a); |
394 | BIO_CONNECT_free(data); | 379 | BIO_CONNECT_free(data); |
395 | a->ptr=NULL; | 380 | a->ptr = NULL; |
396 | a->flags=0; | 381 | a->flags = 0; |
397 | a->init=0; | 382 | a->init = 0; |
398 | } | ||
399 | return(1); | ||
400 | } | 383 | } |
401 | 384 | return (1); | |
402 | static int conn_read(BIO *b, char *out, int outl) | 385 | } |
403 | { | 386 | |
404 | int ret=0; | 387 | static int |
388 | conn_read(BIO *b, char *out, int outl) | ||
389 | { | ||
390 | int ret = 0; | ||
405 | BIO_CONNECT *data; | 391 | BIO_CONNECT *data; |
406 | 392 | ||
407 | data=(BIO_CONNECT *)b->ptr; | 393 | data = (BIO_CONNECT *)b->ptr; |
408 | if (data->state != BIO_CONN_S_OK) | 394 | if (data->state != BIO_CONN_S_OK) { |
409 | { | 395 | ret = conn_state(b, data); |
410 | ret=conn_state(b,data); | ||
411 | if (ret <= 0) | 396 | if (ret <= 0) |
412 | return(ret); | 397 | return (ret); |
413 | } | 398 | } |
414 | 399 | ||
415 | if (out != NULL) | 400 | if (out != NULL) { |
416 | { | ||
417 | errno = 0; | 401 | errno = 0; |
418 | ret=read(b->num,out,outl); | 402 | ret = read(b->num, out, outl); |
419 | BIO_clear_retry_flags(b); | 403 | BIO_clear_retry_flags(b); |
420 | if (ret <= 0) | 404 | if (ret <= 0) { |
421 | { | ||
422 | if (BIO_sock_should_retry(ret)) | 405 | if (BIO_sock_should_retry(ret)) |
423 | BIO_set_retry_read(b); | 406 | BIO_set_retry_read(b); |
424 | } | ||
425 | } | 407 | } |
426 | return(ret); | ||
427 | } | 408 | } |
409 | return (ret); | ||
410 | } | ||
428 | 411 | ||
429 | static int conn_write(BIO *b, const char *in, int inl) | 412 | static int |
430 | { | 413 | conn_write(BIO *b, const char *in, int inl) |
414 | { | ||
431 | int ret; | 415 | int ret; |
432 | BIO_CONNECT *data; | 416 | BIO_CONNECT *data; |
433 | 417 | ||
434 | data=(BIO_CONNECT *)b->ptr; | 418 | data = (BIO_CONNECT *)b->ptr; |
435 | if (data->state != BIO_CONN_S_OK) | 419 | if (data->state != BIO_CONN_S_OK) { |
436 | { | 420 | ret = conn_state(b, data); |
437 | ret=conn_state(b,data); | 421 | if (ret <= 0) |
438 | if (ret <= 0) return(ret); | 422 | return (ret); |
439 | } | 423 | } |
440 | 424 | ||
441 | errno = 0; | 425 | errno = 0; |
442 | ret=write(b->num,in,inl); | 426 | ret = write(b->num, in, inl); |
443 | BIO_clear_retry_flags(b); | 427 | BIO_clear_retry_flags(b); |
444 | if (ret <= 0) | 428 | if (ret <= 0) { |
445 | { | ||
446 | if (BIO_sock_should_retry(ret)) | 429 | if (BIO_sock_should_retry(ret)) |
447 | BIO_set_retry_write(b); | 430 | BIO_set_retry_write(b); |
448 | } | ||
449 | return(ret); | ||
450 | } | 431 | } |
432 | return (ret); | ||
433 | } | ||
451 | 434 | ||
452 | static long conn_ctrl(BIO *b, int cmd, long num, void *ptr) | 435 | static long |
453 | { | 436 | conn_ctrl(BIO *b, int cmd, long num, void *ptr) |
437 | { | ||
454 | BIO *dbio; | 438 | BIO *dbio; |
455 | int *ip; | 439 | int *ip; |
456 | const char **pptr; | 440 | const char **pptr; |
457 | long ret=1; | 441 | long ret = 1; |
458 | BIO_CONNECT *data; | 442 | BIO_CONNECT *data; |
459 | 443 | ||
460 | data=(BIO_CONNECT *)b->ptr; | 444 | data = (BIO_CONNECT *)b->ptr; |
461 | 445 | ||
462 | switch (cmd) | 446 | switch (cmd) { |
463 | { | ||
464 | case BIO_CTRL_RESET: | 447 | case BIO_CTRL_RESET: |
465 | ret=0; | 448 | ret = 0; |
466 | data->state=BIO_CONN_S_BEFORE; | 449 | data->state = BIO_CONN_S_BEFORE; |
467 | conn_close_socket(b); | 450 | conn_close_socket(b); |
468 | b->flags=0; | 451 | b->flags = 0; |
469 | break; | 452 | break; |
470 | case BIO_C_DO_STATE_MACHINE: | 453 | case BIO_C_DO_STATE_MACHINE: |
471 | /* use this one to start the connection */ | 454 | /* use this one to start the connection */ |
472 | if (data->state != BIO_CONN_S_OK) | 455 | if (data->state != BIO_CONN_S_OK) |
473 | ret=(long)conn_state(b,data); | 456 | ret = (long)conn_state(b, data); |
474 | else | 457 | else |
475 | ret=1; | 458 | ret = 1; |
476 | break; | 459 | break; |
477 | case BIO_C_GET_CONNECT: | 460 | case BIO_C_GET_CONNECT: |
478 | if (ptr != NULL) | 461 | if (ptr != NULL) { |
479 | { | 462 | pptr = (const char **)ptr; |
480 | pptr=(const char **)ptr; | 463 | if (num == 0) { |
481 | if (num == 0) | 464 | *pptr = data->param_hostname; |
482 | { | 465 | |
483 | *pptr=data->param_hostname; | 466 | } else if (num == 1) { |
484 | 467 | *pptr = data->param_port; | |
485 | } | 468 | } else if (num == 2) { |
486 | else if (num == 1) | 469 | *pptr = (char *)&(data->ip[0]); |
487 | { | 470 | } else if (num == 3) { |
488 | *pptr=data->param_port; | 471 | *((int *)ptr) = data->port; |
489 | } | ||
490 | else if (num == 2) | ||
491 | { | ||
492 | *pptr= (char *)&(data->ip[0]); | ||
493 | } | ||
494 | else if (num == 3) | ||
495 | { | ||
496 | *((int *)ptr)=data->port; | ||
497 | } | ||
498 | if ((!b->init) || (ptr == NULL)) | ||
499 | *pptr="not initialized"; | ||
500 | ret=1; | ||
501 | } | 472 | } |
473 | if ((!b->init) || (ptr == NULL)) | ||
474 | *pptr = "not initialized"; | ||
475 | ret = 1; | ||
476 | } | ||
502 | break; | 477 | break; |
503 | case BIO_C_SET_CONNECT: | 478 | case BIO_C_SET_CONNECT: |
504 | if (ptr != NULL) | 479 | if (ptr != NULL) { |
505 | { | 480 | b->init = 1; |
506 | b->init=1; | 481 | if (num == 0) { |
507 | if (num == 0) | ||
508 | { | ||
509 | if (data->param_hostname != NULL) | 482 | if (data->param_hostname != NULL) |
510 | OPENSSL_free(data->param_hostname); | 483 | OPENSSL_free(data->param_hostname); |
511 | data->param_hostname=BUF_strdup(ptr); | 484 | data->param_hostname = BUF_strdup(ptr); |
512 | } | 485 | } else if (num == 1) { |
513 | else if (num == 1) | ||
514 | { | ||
515 | if (data->param_port != NULL) | 486 | if (data->param_port != NULL) |
516 | OPENSSL_free(data->param_port); | 487 | OPENSSL_free(data->param_port); |
517 | data->param_port=BUF_strdup(ptr); | 488 | data->param_port = BUF_strdup(ptr); |
518 | } | 489 | } else if (num == 2) { |
519 | else if (num == 2) | ||
520 | { | ||
521 | char buf[16]; | 490 | char buf[16]; |
522 | unsigned char *p = ptr; | 491 | unsigned char *p = ptr; |
523 | 492 | ||
524 | (void) snprintf(buf,sizeof buf,"%d.%d.%d.%d", | 493 | (void) snprintf(buf, sizeof buf, "%d.%d.%d.%d", |
525 | p[0],p[1],p[2],p[3]); | 494 | p[0], p[1], p[2], p[3]); |
526 | if (data->param_hostname != NULL) | 495 | if (data->param_hostname != NULL) |
527 | OPENSSL_free(data->param_hostname); | 496 | OPENSSL_free(data->param_hostname); |
528 | data->param_hostname=BUF_strdup(buf); | 497 | data->param_hostname = BUF_strdup(buf); |
529 | memcpy(&(data->ip[0]),ptr,4); | 498 | memcpy(&(data->ip[0]), ptr, 4); |
530 | } | 499 | } else if (num == 3) { |
531 | else if (num == 3) | 500 | char buf[DECIMAL_SIZE(int) + 1]; |
532 | { | ||
533 | char buf[DECIMAL_SIZE(int)+1]; | ||
534 | 501 | ||
535 | (void) snprintf(buf,sizeof buf,"%d",*(int *)ptr); | 502 | (void) snprintf(buf, sizeof buf, "%d", |
503 | *(int *)ptr); | ||
536 | if (data->param_port != NULL) | 504 | if (data->param_port != NULL) |
537 | OPENSSL_free(data->param_port); | 505 | OPENSSL_free(data->param_port); |
538 | data->param_port=BUF_strdup(buf); | 506 | data->param_port = BUF_strdup(buf); |
539 | data->port= *(int *)ptr; | 507 | data->port= *(int *)ptr; |
540 | } | ||
541 | } | 508 | } |
509 | } | ||
542 | break; | 510 | break; |
543 | case BIO_C_SET_NBIO: | 511 | case BIO_C_SET_NBIO: |
544 | data->nbio=(int)num; | 512 | data->nbio = (int)num; |
545 | break; | 513 | break; |
546 | case BIO_C_GET_FD: | 514 | case BIO_C_GET_FD: |
547 | if (b->init) | 515 | if (b->init) { |
548 | { | 516 | ip = (int *)ptr; |
549 | ip=(int *)ptr; | ||
550 | if (ip != NULL) | 517 | if (ip != NULL) |
551 | *ip=b->num; | 518 | *ip = b->num; |
552 | ret=b->num; | 519 | ret = b->num; |
553 | } | 520 | } else |
554 | else | 521 | ret = -1; |
555 | ret= -1; | ||
556 | break; | 522 | break; |
557 | case BIO_CTRL_GET_CLOSE: | 523 | case BIO_CTRL_GET_CLOSE: |
558 | ret=b->shutdown; | 524 | ret = b->shutdown; |
559 | break; | 525 | break; |
560 | case BIO_CTRL_SET_CLOSE: | 526 | case BIO_CTRL_SET_CLOSE: |
561 | b->shutdown=(int)num; | 527 | b->shutdown = (int)num; |
562 | break; | 528 | break; |
563 | case BIO_CTRL_PENDING: | 529 | case BIO_CTRL_PENDING: |
564 | case BIO_CTRL_WPENDING: | 530 | case BIO_CTRL_WPENDING: |
565 | ret=0; | 531 | ret = 0; |
566 | break; | 532 | break; |
567 | case BIO_CTRL_FLUSH: | 533 | case BIO_CTRL_FLUSH: |
568 | break; | 534 | break; |
569 | case BIO_CTRL_DUP: | 535 | case BIO_CTRL_DUP: |
570 | { | 536 | { |
571 | dbio=(BIO *)ptr; | 537 | dbio = (BIO *)ptr; |
572 | if (data->param_port) | 538 | if (data->param_port) |
573 | BIO_set_conn_port(dbio,data->param_port); | 539 | BIO_set_conn_port(dbio, data->param_port); |
574 | if (data->param_hostname) | 540 | if (data->param_hostname) |
575 | BIO_set_conn_hostname(dbio,data->param_hostname); | 541 | BIO_set_conn_hostname(dbio, |
576 | BIO_set_nbio(dbio,data->nbio); | 542 | data->param_hostname); |
577 | /* FIXME: the cast of the function seems unlikely to be a good idea */ | 543 | BIO_set_nbio(dbio, data->nbio); |
578 | (void)BIO_set_info_callback(dbio,(bio_info_cb *)data->info_callback); | 544 | /* FIXME: the cast of the function seems unlikely to be a good idea */ |
545 | (void)BIO_set_info_callback(dbio, | ||
546 | (bio_info_cb *)data->info_callback); | ||
579 | } | 547 | } |
580 | break; | 548 | break; |
581 | case BIO_CTRL_SET_CALLBACK: | 549 | case BIO_CTRL_SET_CALLBACK: |
582 | { | 550 | { |
583 | #if 0 /* FIXME: Should this be used? -- Richard Levitte */ | 551 | #if 0 /* FIXME: Should this be used? -- Richard Levitte */ |
584 | BIOerr(BIO_F_CONN_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | 552 | BIOerr(BIO_F_CONN_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); |
585 | ret = -1; | 553 | ret = -1; |
586 | #else | 554 | #else |
587 | ret=0; | 555 | ret = 0; |
588 | #endif | 556 | #endif |
589 | } | 557 | } |
590 | break; | 558 | break; |
591 | case BIO_CTRL_GET_CALLBACK: | 559 | case BIO_CTRL_GET_CALLBACK: |
592 | { | 560 | { |
593 | int (**fptr)(const BIO *bio,int state,int xret); | 561 | int (**fptr)(const BIO *bio, int state, int xret); |
594 | 562 | ||
595 | fptr=(int (**)(const BIO *bio,int state,int xret))ptr; | 563 | fptr = (int (**)(const BIO *bio, int state, int xret))ptr; |
596 | *fptr=data->info_callback; | 564 | *fptr = data->info_callback; |
597 | } | 565 | } |
598 | break; | 566 | break; |
599 | default: | 567 | default: |
600 | ret=0; | 568 | ret = 0; |
601 | break; | 569 | break; |
602 | } | ||
603 | return(ret); | ||
604 | } | 570 | } |
571 | return (ret); | ||
572 | } | ||
605 | 573 | ||
606 | static long conn_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | 574 | static long |
607 | { | 575 | conn_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) |
608 | long ret=1; | 576 | { |
577 | long ret = 1; | ||
609 | BIO_CONNECT *data; | 578 | BIO_CONNECT *data; |
610 | 579 | ||
611 | data=(BIO_CONNECT *)b->ptr; | 580 | data = (BIO_CONNECT *)b->ptr; |
612 | 581 | ||
613 | switch (cmd) | 582 | switch (cmd) { |
614 | { | ||
615 | case BIO_CTRL_SET_CALLBACK: | 583 | case BIO_CTRL_SET_CALLBACK: |
616 | { | 584 | { |
617 | data->info_callback=(int (*)(const struct bio_st *, int, int))fp; | 585 | data->info_callback = (int (*)(const struct bio_st *, int, int))fp; |
618 | } | 586 | } |
619 | break; | 587 | break; |
620 | default: | 588 | default: |
621 | ret=0; | 589 | ret = 0; |
622 | break; | 590 | break; |
623 | } | ||
624 | return(ret); | ||
625 | } | 591 | } |
626 | 592 | return (ret); | |
627 | static int conn_puts(BIO *bp, const char *str) | 593 | } |
628 | { | 594 | |
629 | int n,ret; | 595 | static int |
630 | 596 | conn_puts(BIO *bp, const char *str) | |
631 | n=strlen(str); | 597 | { |
632 | ret=conn_write(bp,str,n); | 598 | int n, ret; |
633 | return(ret); | 599 | |
634 | } | 600 | n = strlen(str); |
635 | 601 | ret = conn_write(bp, str, n); | |
636 | BIO *BIO_new_connect(char *str) | 602 | return (ret); |
637 | { | 603 | } |
604 | |||
605 | BIO | ||
606 | *BIO_new_connect(char *str) | ||
607 | { | ||
638 | BIO *ret; | 608 | BIO *ret; |
639 | 609 | ||
640 | ret=BIO_new(BIO_s_connect()); | 610 | ret = BIO_new(BIO_s_connect()); |
641 | if (ret == NULL) return(NULL); | 611 | if (ret == NULL) |
642 | if (BIO_set_conn_hostname(ret,str)) | 612 | return (NULL); |
643 | return(ret); | 613 | if (BIO_set_conn_hostname(ret, str)) |
644 | else | 614 | return (ret); |
645 | { | 615 | else { |
646 | BIO_free(ret); | 616 | BIO_free(ret); |
647 | return(NULL); | 617 | return (NULL); |
648 | } | ||
649 | } | 618 | } |
619 | } | ||
650 | 620 | ||
651 | #endif | 621 | #endif |
652 | |||
diff --git a/src/lib/libssl/src/crypto/bio/bss_dgram.c b/src/lib/libssl/src/crypto/bio/bss_dgram.c index 67a13ae845..330f6fc404 100644 --- a/src/lib/libssl/src/crypto/bio/bss_dgram.c +++ b/src/lib/libssl/src/crypto/bio/bss_dgram.c | |||
@@ -113,7 +113,8 @@ static long dgram_sctp_ctrl(BIO *h, int cmd, long arg1, void *arg2); | |||
113 | static int dgram_sctp_new(BIO *h); | 113 | static int dgram_sctp_new(BIO *h); |
114 | static int dgram_sctp_free(BIO *data); | 114 | static int dgram_sctp_free(BIO *data); |
115 | #ifdef SCTP_AUTHENTICATION_EVENT | 115 | #ifdef SCTP_AUTHENTICATION_EVENT |
116 | static void dgram_sctp_handle_auth_free_key_event(BIO *b, union sctp_notification *snp); | 116 | static void dgram_sctp_handle_auth_free_key_event(BIO *b, |
117 | union sctp_notification *snp); | ||
117 | #endif | 118 | #endif |
118 | #endif | 119 | #endif |
119 | 120 | ||
@@ -121,8 +122,7 @@ static int BIO_dgram_should_retry(int s); | |||
121 | 122 | ||
122 | static void get_current_time(struct timeval *t); | 123 | static void get_current_time(struct timeval *t); |
123 | 124 | ||
124 | static BIO_METHOD methods_dgramp= | 125 | static BIO_METHOD methods_dgramp = { |
125 | { | ||
126 | BIO_TYPE_DGRAM, | 126 | BIO_TYPE_DGRAM, |
127 | "datagram socket", | 127 | "datagram socket", |
128 | dgram_write, | 128 | dgram_write, |
@@ -133,11 +133,10 @@ static BIO_METHOD methods_dgramp= | |||
133 | dgram_new, | 133 | dgram_new, |
134 | dgram_free, | 134 | dgram_free, |
135 | NULL, | 135 | NULL, |
136 | }; | 136 | }; |
137 | 137 | ||
138 | #ifndef OPENSSL_NO_SCTP | 138 | #ifndef OPENSSL_NO_SCTP |
139 | static BIO_METHOD methods_dgramp_sctp= | 139 | static BIO_METHOD methods_dgramp_sctp = { |
140 | { | ||
141 | BIO_TYPE_DGRAM_SCTP, | 140 | BIO_TYPE_DGRAM_SCTP, |
142 | "datagram sctp socket", | 141 | "datagram sctp socket", |
143 | dgram_sctp_write, | 142 | dgram_sctp_write, |
@@ -148,11 +147,10 @@ static BIO_METHOD methods_dgramp_sctp= | |||
148 | dgram_sctp_new, | 147 | dgram_sctp_new, |
149 | dgram_sctp_free, | 148 | dgram_sctp_free, |
150 | NULL, | 149 | NULL, |
151 | }; | 150 | }; |
152 | #endif | 151 | #endif |
153 | 152 | ||
154 | typedef struct bio_dgram_data_st | 153 | typedef struct bio_dgram_data_st { |
155 | { | ||
156 | union { | 154 | union { |
157 | struct sockaddr sa; | 155 | struct sockaddr sa; |
158 | struct sockaddr_in sa_in; | 156 | struct sockaddr_in sa_in; |
@@ -165,18 +163,16 @@ typedef struct bio_dgram_data_st | |||
165 | unsigned int mtu; | 163 | unsigned int mtu; |
166 | struct timeval next_timeout; | 164 | struct timeval next_timeout; |
167 | struct timeval socket_timeout; | 165 | struct timeval socket_timeout; |
168 | } bio_dgram_data; | 166 | } bio_dgram_data; |
169 | 167 | ||
170 | #ifndef OPENSSL_NO_SCTP | 168 | #ifndef OPENSSL_NO_SCTP |
171 | typedef struct bio_dgram_sctp_save_message_st | 169 | typedef struct bio_dgram_sctp_save_message_st { |
172 | { | 170 | BIO *bio; |
173 | BIO *bio; | 171 | char *data; |
174 | char *data; | 172 | int length; |
175 | int length; | 173 | } bio_dgram_sctp_save_message; |
176 | } bio_dgram_sctp_save_message; | ||
177 | 174 | ||
178 | typedef struct bio_dgram_sctp_data_st | 175 | typedef struct bio_dgram_sctp_data_st { |
179 | { | ||
180 | union { | 176 | union { |
181 | struct sockaddr sa; | 177 | struct sockaddr sa; |
182 | struct sockaddr_in sa_in; | 178 | struct sockaddr_in sa_in; |
@@ -198,79 +194,88 @@ typedef struct bio_dgram_sctp_data_st | |||
198 | int save_shutdown; | 194 | int save_shutdown; |
199 | int peer_auth_tested; | 195 | int peer_auth_tested; |
200 | bio_dgram_sctp_save_message saved_message; | 196 | bio_dgram_sctp_save_message saved_message; |
201 | } bio_dgram_sctp_data; | 197 | } bio_dgram_sctp_data; |
202 | #endif | 198 | #endif |
203 | 199 | ||
204 | BIO_METHOD *BIO_s_datagram(void) | 200 | BIO_METHOD |
205 | { | 201 | *BIO_s_datagram(void) |
206 | return(&methods_dgramp); | 202 | { |
207 | } | 203 | return (&methods_dgramp); |
204 | } | ||
208 | 205 | ||
209 | BIO *BIO_new_dgram(int fd, int close_flag) | 206 | BIO |
210 | { | 207 | *BIO_new_dgram(int fd, int close_flag) |
208 | { | ||
211 | BIO *ret; | 209 | BIO *ret; |
212 | 210 | ||
213 | ret=BIO_new(BIO_s_datagram()); | 211 | ret = BIO_new(BIO_s_datagram()); |
214 | if (ret == NULL) return(NULL); | 212 | if (ret == NULL) |
215 | BIO_set_fd(ret,fd,close_flag); | 213 | return (NULL); |
216 | return(ret); | 214 | BIO_set_fd(ret, fd, close_flag); |
217 | } | 215 | return (ret); |
216 | } | ||
218 | 217 | ||
219 | static int dgram_new(BIO *bi) | 218 | static int |
220 | { | 219 | dgram_new(BIO *bi) |
220 | { | ||
221 | bio_dgram_data *data = NULL; | 221 | bio_dgram_data *data = NULL; |
222 | 222 | ||
223 | bi->init=0; | 223 | bi->init = 0; |
224 | bi->num=0; | 224 | bi->num = 0; |
225 | data = OPENSSL_malloc(sizeof(bio_dgram_data)); | 225 | data = OPENSSL_malloc(sizeof(bio_dgram_data)); |
226 | if (data == NULL) | 226 | if (data == NULL) |
227 | return 0; | 227 | return 0; |
228 | memset(data, 0x00, sizeof(bio_dgram_data)); | 228 | memset(data, 0x00, sizeof(bio_dgram_data)); |
229 | bi->ptr = data; | 229 | bi->ptr = data; |
230 | 230 | ||
231 | bi->flags=0; | 231 | bi->flags = 0; |
232 | return(1); | 232 | return (1); |
233 | } | 233 | } |
234 | 234 | ||
235 | static int dgram_free(BIO *a) | 235 | static int |
236 | { | 236 | dgram_free(BIO *a) |
237 | { | ||
237 | bio_dgram_data *data; | 238 | bio_dgram_data *data; |
238 | 239 | ||
239 | if (a == NULL) return(0); | 240 | if (a == NULL) |
240 | if ( ! dgram_clear(a)) | 241 | return (0); |
242 | if (!dgram_clear(a)) | ||
241 | return 0; | 243 | return 0; |
242 | 244 | ||
243 | data = (bio_dgram_data *)a->ptr; | 245 | data = (bio_dgram_data *)a->ptr; |
244 | if(data != NULL) OPENSSL_free(data); | 246 | if (data != NULL) |
247 | OPENSSL_free(data); | ||
245 | 248 | ||
246 | return(1); | 249 | return (1); |
247 | } | 250 | } |
248 | 251 | ||
249 | static int dgram_clear(BIO *a) | 252 | static int |
250 | { | 253 | dgram_clear(BIO *a) |
251 | if (a == NULL) return(0); | 254 | { |
252 | if (a->shutdown) | 255 | if (a == NULL) |
253 | { | 256 | return (0); |
254 | if (a->init) | 257 | if (a->shutdown) { |
255 | { | 258 | if (a->init) { |
256 | shutdown(a->num, SHUT_RDWR); | 259 | shutdown(a->num, SHUT_RDWR); |
257 | close(a->num); | 260 | close(a->num); |
258 | } | ||
259 | a->init=0; | ||
260 | a->flags=0; | ||
261 | } | 261 | } |
262 | return(1); | 262 | a->init = 0; |
263 | a->flags = 0; | ||
263 | } | 264 | } |
265 | return (1); | ||
266 | } | ||
264 | 267 | ||
265 | static void dgram_adjust_rcv_timeout(BIO *b) | 268 | static void |
266 | { | 269 | dgram_adjust_rcv_timeout(BIO *b) |
270 | { | ||
267 | #if defined(SO_RCVTIMEO) | 271 | #if defined(SO_RCVTIMEO) |
268 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; | 272 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; |
269 | union { size_t s; int i; } sz = {0}; | 273 | union { size_t s; |
274 | int i; | ||
275 | } sz = {0}; | ||
270 | 276 | ||
271 | /* Is a timer active? */ | 277 | /* Is a timer active? */ |
272 | if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0) | 278 | if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0) { |
273 | { | ||
274 | struct timeval timenow, timeleft; | 279 | struct timeval timenow, timeleft; |
275 | 280 | ||
276 | /* Read current socket timeout */ | 281 | /* Read current socket timeout */ |
@@ -279,20 +284,19 @@ static void dgram_adjust_rcv_timeout(BIO *b) | |||
279 | 284 | ||
280 | sz.i = sizeof(timeout); | 285 | sz.i = sizeof(timeout); |
281 | if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | 286 | if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, |
282 | (void*)&timeout, &sz.i) < 0) | 287 | (void*)&timeout, &sz.i) < 0) { |
283 | { perror("getsockopt"); } | 288 | perror("getsockopt"); |
284 | else | 289 | } else { |
285 | { | ||
286 | data->socket_timeout.tv_sec = timeout / 1000; | 290 | data->socket_timeout.tv_sec = timeout / 1000; |
287 | data->socket_timeout.tv_usec = (timeout % 1000) * 1000; | 291 | data->socket_timeout.tv_usec = (timeout % 1000) * 1000; |
288 | } | 292 | } |
289 | #else | 293 | #else |
290 | sz.i = sizeof(data->socket_timeout); | 294 | sz.i = sizeof(data->socket_timeout); |
291 | if ( getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | 295 | if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, |
292 | &(data->socket_timeout), (void *)&sz) < 0) | 296 | &(data->socket_timeout), (void *)&sz) < 0) { |
293 | { perror("getsockopt"); } | 297 | perror("getsockopt"); |
294 | else if (sizeof(sz.s)!=sizeof(sz.i) && sz.i==0) | 298 | } else if (sizeof(sz.s) != sizeof(sz.i) && sz.i == 0) |
295 | OPENSSL_assert(sz.s<=sizeof(data->socket_timeout)); | 299 | OPENSSL_assert(sz.s <= sizeof(data->socket_timeout)); |
296 | #endif | 300 | #endif |
297 | 301 | ||
298 | /* Get current time */ | 302 | /* Get current time */ |
@@ -302,126 +306,128 @@ static void dgram_adjust_rcv_timeout(BIO *b) | |||
302 | memcpy(&timeleft, &(data->next_timeout), sizeof(struct timeval)); | 306 | memcpy(&timeleft, &(data->next_timeout), sizeof(struct timeval)); |
303 | timeleft.tv_sec -= timenow.tv_sec; | 307 | timeleft.tv_sec -= timenow.tv_sec; |
304 | timeleft.tv_usec -= timenow.tv_usec; | 308 | timeleft.tv_usec -= timenow.tv_usec; |
305 | if (timeleft.tv_usec < 0) | 309 | if (timeleft.tv_usec < 0) { |
306 | { | ||
307 | timeleft.tv_sec--; | 310 | timeleft.tv_sec--; |
308 | timeleft.tv_usec += 1000000; | 311 | timeleft.tv_usec += 1000000; |
309 | } | 312 | } |
310 | 313 | ||
311 | if (timeleft.tv_sec < 0) | 314 | if (timeleft.tv_sec < 0) { |
312 | { | ||
313 | timeleft.tv_sec = 0; | 315 | timeleft.tv_sec = 0; |
314 | timeleft.tv_usec = 1; | 316 | timeleft.tv_usec = 1; |
315 | } | 317 | } |
316 | 318 | ||
317 | /* Adjust socket timeout if next handhake message timer | 319 | /* Adjust socket timeout if next handhake message timer |
318 | * will expire earlier. | 320 | * will expire earlier. |
319 | */ | 321 | */ |
320 | if ((data->socket_timeout.tv_sec == 0 && data->socket_timeout.tv_usec == 0) || | 322 | if ((data->socket_timeout.tv_sec == 0 && |
321 | (data->socket_timeout.tv_sec > timeleft.tv_sec) || | 323 | data->socket_timeout.tv_usec == 0) || |
322 | (data->socket_timeout.tv_sec == timeleft.tv_sec && | 324 | (data->socket_timeout.tv_sec > timeleft.tv_sec) || |
323 | data->socket_timeout.tv_usec >= timeleft.tv_usec)) | 325 | (data->socket_timeout.tv_sec == timeleft.tv_sec && |
324 | { | 326 | data->socket_timeout.tv_usec >= timeleft.tv_usec)) { |
325 | #ifdef OPENSSL_SYS_WINDOWS | 327 | #ifdef OPENSSL_SYS_WINDOWS |
326 | timeout = timeleft.tv_sec * 1000 + timeleft.tv_usec / 1000; | 328 | timeout = timeleft.tv_sec * 1000 + timeleft.tv_usec / 1000; |
327 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | 329 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, |
328 | (void*)&timeout, sizeof(timeout)) < 0) | 330 | (void*)&timeout, sizeof(timeout)) < 0) { |
329 | { perror("setsockopt"); } | 331 | perror("setsockopt"); |
332 | } | ||
330 | #else | 333 | #else |
331 | if ( setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, &timeleft, | 334 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, |
332 | sizeof(struct timeval)) < 0) | 335 | &timeleft, sizeof(struct timeval)) < 0) { |
333 | { perror("setsockopt"); } | 336 | perror("setsockopt"); |
334 | #endif | ||
335 | } | 337 | } |
336 | } | ||
337 | #endif | 338 | #endif |
339 | } | ||
338 | } | 340 | } |
341 | #endif | ||
342 | } | ||
339 | 343 | ||
340 | static void dgram_reset_rcv_timeout(BIO *b) | 344 | static void |
341 | { | 345 | dgram_reset_rcv_timeout(BIO *b) |
346 | { | ||
342 | #if defined(SO_RCVTIMEO) | 347 | #if defined(SO_RCVTIMEO) |
343 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; | 348 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; |
344 | 349 | ||
345 | /* Is a timer active? */ | 350 | /* Is a timer active? */ |
346 | if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0) | 351 | if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0) { |
347 | { | ||
348 | #ifdef OPENSSL_SYS_WINDOWS | 352 | #ifdef OPENSSL_SYS_WINDOWS |
349 | int timeout = data->socket_timeout.tv_sec * 1000 + | 353 | int timeout = data->socket_timeout.tv_sec * 1000 + |
350 | data->socket_timeout.tv_usec / 1000; | 354 | data->socket_timeout.tv_usec / 1000; |
351 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | 355 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, |
352 | (void*)&timeout, sizeof(timeout)) < 0) | 356 | (void*)&timeout, sizeof(timeout)) < 0) { |
353 | { perror("setsockopt"); } | 357 | perror("setsockopt"); |
358 | } | ||
354 | #else | 359 | #else |
355 | if ( setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, &(data->socket_timeout), | 360 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, |
356 | sizeof(struct timeval)) < 0) | 361 | &(data->socket_timeout), sizeof(struct timeval)) < 0) { |
357 | { perror("setsockopt"); } | 362 | perror("setsockopt"); |
358 | #endif | ||
359 | } | 363 | } |
360 | #endif | 364 | #endif |
361 | } | 365 | } |
366 | #endif | ||
367 | } | ||
362 | 368 | ||
363 | static int dgram_read(BIO *b, char *out, int outl) | 369 | static int |
364 | { | 370 | dgram_read(BIO *b, char *out, int outl) |
365 | int ret=0; | 371 | { |
372 | int ret = 0; | ||
366 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; | 373 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; |
367 | 374 | ||
368 | struct { | 375 | struct { |
369 | /* | 376 | /* |
370 | * See commentary in b_sock.c. <appro> | 377 | * See commentary in b_sock.c. <appro> |
371 | */ | 378 | */ |
372 | union { size_t s; int i; } len; | 379 | union { |
373 | union { | 380 | size_t s; |
374 | struct sockaddr sa; | 381 | int i; |
375 | struct sockaddr_in sa_in; | 382 | } len; |
383 | union { | ||
384 | struct sockaddr sa; | ||
385 | struct sockaddr_in sa_in; | ||
376 | #if OPENSSL_USE_IPV6 | 386 | #if OPENSSL_USE_IPV6 |
377 | struct sockaddr_in6 sa_in6; | 387 | struct sockaddr_in6 sa_in6; |
378 | #endif | 388 | #endif |
379 | } peer; | 389 | } peer; |
380 | } sa; | 390 | } sa; |
381 | 391 | ||
382 | sa.len.s=0; | 392 | sa.len.s = 0; |
383 | sa.len.i=sizeof(sa.peer); | 393 | sa.len.i = sizeof(sa.peer); |
384 | 394 | ||
385 | if (out != NULL) | 395 | if (out != NULL) { |
386 | { | ||
387 | errno = 0; | 396 | errno = 0; |
388 | memset(&sa.peer, 0x00, sizeof(sa.peer)); | 397 | memset(&sa.peer, 0x00, sizeof(sa.peer)); |
389 | dgram_adjust_rcv_timeout(b); | 398 | dgram_adjust_rcv_timeout(b); |
390 | ret=recvfrom(b->num,out,outl,0,&sa.peer.sa,(void *)&sa.len); | 399 | ret = recvfrom(b->num, out, outl, 0, &sa.peer.sa,(void *)&sa.len); |
391 | if (sizeof(sa.len.i)!=sizeof(sa.len.s) && sa.len.i==0) | 400 | if (sizeof(sa.len.i) != sizeof(sa.len.s) && sa.len.i == 0) { |
392 | { | 401 | OPENSSL_assert(sa.len.s <= sizeof(sa.peer)); |
393 | OPENSSL_assert(sa.len.s<=sizeof(sa.peer)); | ||
394 | sa.len.i = (int)sa.len.s; | 402 | sa.len.i = (int)sa.len.s; |
395 | } | 403 | } |
396 | 404 | ||
397 | if ( ! data->connected && ret >= 0) | 405 | if (! data->connected && ret >= 0) |
398 | BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, &sa.peer); | 406 | BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, &sa.peer); |
399 | 407 | ||
400 | BIO_clear_retry_flags(b); | 408 | BIO_clear_retry_flags(b); |
401 | if (ret < 0) | 409 | if (ret < 0) { |
402 | { | 410 | if (BIO_dgram_should_retry(ret)) { |
403 | if (BIO_dgram_should_retry(ret)) | ||
404 | { | ||
405 | BIO_set_retry_read(b); | 411 | BIO_set_retry_read(b); |
406 | data->_errno = errno; | 412 | data->_errno = errno; |
407 | } | ||
408 | } | 413 | } |
414 | } | ||
409 | 415 | ||
410 | dgram_reset_rcv_timeout(b); | 416 | dgram_reset_rcv_timeout(b); |
411 | } | ||
412 | return(ret); | ||
413 | } | 417 | } |
418 | return (ret); | ||
419 | } | ||
414 | 420 | ||
415 | static int dgram_write(BIO *b, const char *in, int inl) | 421 | static int |
416 | { | 422 | dgram_write(BIO *b, const char *in, int inl) |
423 | { | ||
417 | int ret; | 424 | int ret; |
418 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; | 425 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; |
419 | errno = 0; | 426 | errno = 0; |
420 | 427 | ||
421 | if ( data->connected ) | 428 | if (data->connected) |
422 | ret=write(b->num,in,inl); | 429 | ret = write(b->num, in, inl); |
423 | else | 430 | else { |
424 | { | ||
425 | int peerlen = sizeof(data->peer); | 431 | int peerlen = sizeof(data->peer); |
426 | 432 | ||
427 | if (data->peer.sa.sa_family == AF_INET) | 433 | if (data->peer.sa.sa_family == AF_INET) |
@@ -431,33 +437,33 @@ static int dgram_write(BIO *b, const char *in, int inl) | |||
431 | peerlen = sizeof(data->peer.sa_in6); | 437 | peerlen = sizeof(data->peer.sa_in6); |
432 | #endif | 438 | #endif |
433 | #if defined(NETWARE_CLIB) && defined(NETWARE_BSDSOCK) | 439 | #if defined(NETWARE_CLIB) && defined(NETWARE_BSDSOCK) |
434 | ret=sendto(b->num, (char *)in, inl, 0, &data->peer.sa, peerlen); | 440 | ret = sendto(b->num, (char *)in, inl, 0, &data->peer.sa, peerlen); |
435 | #else | 441 | #else |
436 | ret=sendto(b->num, in, inl, 0, &data->peer.sa, peerlen); | 442 | ret = sendto(b->num, in, inl, 0, &data->peer.sa, peerlen); |
437 | #endif | 443 | #endif |
438 | } | 444 | } |
439 | 445 | ||
440 | BIO_clear_retry_flags(b); | 446 | BIO_clear_retry_flags(b); |
441 | if (ret <= 0) | 447 | if (ret <= 0) { |
442 | { | 448 | if (BIO_dgram_should_retry(ret)) { |
443 | if (BIO_dgram_should_retry(ret)) | 449 | BIO_set_retry_write(b); |
444 | { | 450 | |
445 | BIO_set_retry_write(b); | ||
446 | data->_errno = errno; | 451 | data->_errno = errno; |
447 | 452 | ||
448 | #if 0 /* higher layers are responsible for querying MTU, if necessary */ | 453 | #if 0 /* higher layers are responsible for querying MTU, if necessary */ |
449 | if ( data->_errno == EMSGSIZE) | 454 | if (data->_errno == EMSGSIZE) |
450 | /* retrieve the new MTU */ | 455 | /* retrieve the new MTU */ |
451 | BIO_ctrl(b, BIO_CTRL_DGRAM_QUERY_MTU, 0, NULL); | 456 | BIO_ctrl(b, BIO_CTRL_DGRAM_QUERY_MTU, 0, NULL); |
452 | #endif | 457 | #endif |
453 | } | ||
454 | } | 458 | } |
455 | return(ret); | ||
456 | } | 459 | } |
460 | return (ret); | ||
461 | } | ||
457 | 462 | ||
458 | static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | 463 | static long |
459 | { | 464 | dgram_ctrl(BIO *b, int cmd, long num, void *ptr) |
460 | long ret=1; | 465 | { |
466 | long ret = 1; | ||
461 | int *ip; | 467 | int *ip; |
462 | struct sockaddr *to = NULL; | 468 | struct sockaddr *to = NULL; |
463 | bio_dgram_data *data = NULL; | 469 | bio_dgram_data *data = NULL; |
@@ -472,76 +478,73 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
472 | #if OPENSSL_USE_IPV6 | 478 | #if OPENSSL_USE_IPV6 |
473 | struct sockaddr_in6 s6; | 479 | struct sockaddr_in6 s6; |
474 | #endif | 480 | #endif |
475 | } addr; | 481 | } addr; |
476 | #endif | 482 | #endif |
477 | 483 | ||
478 | data = (bio_dgram_data *)b->ptr; | 484 | data = (bio_dgram_data *)b->ptr; |
479 | 485 | ||
480 | switch (cmd) | 486 | switch (cmd) { |
481 | { | ||
482 | case BIO_CTRL_RESET: | 487 | case BIO_CTRL_RESET: |
483 | num=0; | 488 | num = 0; |
484 | case BIO_C_FILE_SEEK: | 489 | case BIO_C_FILE_SEEK: |
485 | ret=0; | 490 | ret = 0; |
486 | break; | 491 | break; |
487 | case BIO_C_FILE_TELL: | 492 | case BIO_C_FILE_TELL: |
488 | case BIO_CTRL_INFO: | 493 | case BIO_CTRL_INFO: |
489 | ret=0; | 494 | ret = 0; |
490 | break; | 495 | break; |
491 | case BIO_C_SET_FD: | 496 | case BIO_C_SET_FD: |
492 | dgram_clear(b); | 497 | dgram_clear(b); |
493 | b->num= *((int *)ptr); | 498 | b->num= *((int *)ptr); |
494 | b->shutdown=(int)num; | 499 | b->shutdown = (int)num; |
495 | b->init=1; | 500 | b->init = 1; |
496 | break; | 501 | break; |
497 | case BIO_C_GET_FD: | 502 | case BIO_C_GET_FD: |
498 | if (b->init) | 503 | if (b->init) { |
499 | { | 504 | ip = (int *)ptr; |
500 | ip=(int *)ptr; | 505 | if (ip != NULL) |
501 | if (ip != NULL) *ip=b->num; | 506 | *ip = b->num; |
502 | ret=b->num; | 507 | ret = b->num; |
503 | } | 508 | } else |
504 | else | 509 | ret = -1; |
505 | ret= -1; | ||
506 | break; | 510 | break; |
507 | case BIO_CTRL_GET_CLOSE: | 511 | case BIO_CTRL_GET_CLOSE: |
508 | ret=b->shutdown; | 512 | ret = b->shutdown; |
509 | break; | 513 | break; |
510 | case BIO_CTRL_SET_CLOSE: | 514 | case BIO_CTRL_SET_CLOSE: |
511 | b->shutdown=(int)num; | 515 | b->shutdown = (int)num; |
512 | break; | 516 | break; |
513 | case BIO_CTRL_PENDING: | 517 | case BIO_CTRL_PENDING: |
514 | case BIO_CTRL_WPENDING: | 518 | case BIO_CTRL_WPENDING: |
515 | ret=0; | 519 | ret = 0; |
516 | break; | 520 | break; |
517 | case BIO_CTRL_DUP: | 521 | case BIO_CTRL_DUP: |
518 | case BIO_CTRL_FLUSH: | 522 | case BIO_CTRL_FLUSH: |
519 | ret=1; | 523 | ret = 1; |
520 | break; | 524 | break; |
521 | case BIO_CTRL_DGRAM_CONNECT: | 525 | case BIO_CTRL_DGRAM_CONNECT: |
522 | to = (struct sockaddr *)ptr; | 526 | to = (struct sockaddr *)ptr; |
523 | #if 0 | 527 | #if 0 |
524 | if (connect(b->num, to, sizeof(struct sockaddr)) < 0) | 528 | if (connect(b->num, to, sizeof(struct sockaddr)) < 0) { |
525 | { perror("connect"); ret = 0; } | 529 | perror("connect"); |
526 | else | 530 | ret = 0; |
527 | { | 531 | } else { |
528 | #endif | 532 | #endif |
529 | switch (to->sa_family) | 533 | switch (to->sa_family) { |
530 | { | 534 | case AF_INET: |
531 | case AF_INET: | 535 | memcpy(&data->peer, to, sizeof(data->peer.sa_in)); |
532 | memcpy(&data->peer,to,sizeof(data->peer.sa_in)); | 536 | break; |
533 | break; | ||
534 | #if OPENSSL_USE_IPV6 | 537 | #if OPENSSL_USE_IPV6 |
535 | case AF_INET6: | 538 | case AF_INET6: |
536 | memcpy(&data->peer,to,sizeof(data->peer.sa_in6)); | 539 | memcpy(&data->peer, to, sizeof(data->peer.sa_in6)); |
537 | break; | 540 | break; |
538 | #endif | 541 | #endif |
539 | default: | 542 | default: |
540 | memcpy(&data->peer,to,sizeof(data->peer.sa)); | 543 | memcpy(&data->peer, to, sizeof(data->peer.sa)); |
541 | break; | 544 | break; |
542 | } | ||
543 | #if 0 | ||
544 | } | 545 | } |
546 | #if 0 | ||
547 | } | ||
545 | #endif | 548 | #endif |
546 | break; | 549 | break; |
547 | /* (Linux)kernel sets DF bit on outgoing IP packets */ | 550 | /* (Linux)kernel sets DF bit on outgoing IP packets */ |
@@ -549,31 +552,31 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
549 | #if defined(OPENSSL_SYS_LINUX) && defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DO) | 552 | #if defined(OPENSSL_SYS_LINUX) && defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DO) |
550 | addr_len = (socklen_t)sizeof(addr); | 553 | addr_len = (socklen_t)sizeof(addr); |
551 | memset((void *)&addr, 0, sizeof(addr)); | 554 | memset((void *)&addr, 0, sizeof(addr)); |
552 | if (getsockname(b->num, &addr.sa, &addr_len) < 0) | 555 | if (getsockname(b->num, &addr.sa, &addr_len) < 0) { |
553 | { | ||
554 | ret = 0; | 556 | ret = 0; |
555 | break; | 557 | break; |
556 | } | 558 | } |
557 | switch (addr.sa.sa_family) | 559 | switch (addr.sa.sa_family) { |
558 | { | ||
559 | case AF_INET: | 560 | case AF_INET: |
560 | sockopt_val = IP_PMTUDISC_DO; | 561 | sockopt_val = IP_PMTUDISC_DO; |
561 | if ((ret = setsockopt(b->num, IPPROTO_IP, IP_MTU_DISCOVER, | 562 | if ((ret = setsockopt(b->num, IPPROTO_IP, |
562 | &sockopt_val, sizeof(sockopt_val))) < 0) | 563 | IP_MTU_DISCOVER, &sockopt_val, |
564 | sizeof(sockopt_val))) < 0) | ||
563 | perror("setsockopt"); | 565 | perror("setsockopt"); |
564 | break; | 566 | break; |
565 | #if OPENSSL_USE_IPV6 && defined(IPV6_MTU_DISCOVER) && defined(IPV6_PMTUDISC_DO) | 567 | #if OPENSSL_USE_IPV6 && defined(IPV6_MTU_DISCOVER) && defined(IPV6_PMTUDISC_DO) |
566 | case AF_INET6: | 568 | case AF_INET6: |
567 | sockopt_val = IPV6_PMTUDISC_DO; | 569 | sockopt_val = IPV6_PMTUDISC_DO; |
568 | if ((ret = setsockopt(b->num, IPPROTO_IPV6, IPV6_MTU_DISCOVER, | 570 | if ((ret = setsockopt(b->num, IPPROTO_IPV6, |
569 | &sockopt_val, sizeof(sockopt_val))) < 0) | 571 | IPV6_MTU_DISCOVER, &sockopt_val, |
572 | sizeof(sockopt_val))) < 0) | ||
570 | perror("setsockopt"); | 573 | perror("setsockopt"); |
571 | break; | 574 | break; |
572 | #endif | 575 | #endif |
573 | default: | 576 | default: |
574 | ret = -1; | 577 | ret = -1; |
575 | break; | 578 | break; |
576 | } | 579 | } |
577 | ret = -1; | 580 | ret = -1; |
578 | #else | 581 | #else |
579 | break; | 582 | break; |
@@ -582,74 +585,67 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
582 | #if defined(OPENSSL_SYS_LINUX) && defined(IP_MTU) | 585 | #if defined(OPENSSL_SYS_LINUX) && defined(IP_MTU) |
583 | addr_len = (socklen_t)sizeof(addr); | 586 | addr_len = (socklen_t)sizeof(addr); |
584 | memset((void *)&addr, 0, sizeof(addr)); | 587 | memset((void *)&addr, 0, sizeof(addr)); |
585 | if (getsockname(b->num, &addr.sa, &addr_len) < 0) | 588 | if (getsockname(b->num, &addr.sa, &addr_len) < 0) { |
586 | { | ||
587 | ret = 0; | 589 | ret = 0; |
588 | break; | 590 | break; |
589 | } | 591 | } |
590 | sockopt_len = sizeof(sockopt_val); | 592 | sockopt_len = sizeof(sockopt_val); |
591 | switch (addr.sa.sa_family) | 593 | switch (addr.sa.sa_family) { |
592 | { | ||
593 | case AF_INET: | 594 | case AF_INET: |
594 | if ((ret = getsockopt(b->num, IPPROTO_IP, IP_MTU, (void *)&sockopt_val, | 595 | if ((ret = getsockopt(b->num, IPPROTO_IP, IP_MTU, |
595 | &sockopt_len)) < 0 || sockopt_val < 0) | 596 | (void *)&sockopt_val, &sockopt_len)) < 0 || |
596 | { | 597 | sockopt_val < 0) { |
597 | ret = 0; | 598 | ret = 0; |
598 | } | 599 | } else { |
599 | else | ||
600 | { | ||
601 | /* we assume that the transport protocol is UDP and no | 600 | /* we assume that the transport protocol is UDP and no |
602 | * IP options are used. | 601 | * IP options are used. |
603 | */ | 602 | */ |
604 | data->mtu = sockopt_val - 8 - 20; | 603 | data->mtu = sockopt_val - 8 - 20; |
605 | ret = data->mtu; | 604 | ret = data->mtu; |
606 | } | 605 | } |
607 | break; | 606 | break; |
608 | #if OPENSSL_USE_IPV6 && defined(IPV6_MTU) | 607 | #if OPENSSL_USE_IPV6 && defined(IPV6_MTU) |
609 | case AF_INET6: | 608 | case AF_INET6: |
610 | if ((ret = getsockopt(b->num, IPPROTO_IPV6, IPV6_MTU, (void *)&sockopt_val, | 609 | if ((ret = getsockopt(b->num, IPPROTO_IPV6, IPV6_MTU, |
611 | &sockopt_len)) < 0 || sockopt_val < 0) | 610 | (void *)&sockopt_val, &sockopt_len)) < 0 || |
612 | { | 611 | sockopt_val < 0) { |
613 | ret = 0; | 612 | ret = 0; |
614 | } | 613 | } else { |
615 | else | ||
616 | { | ||
617 | /* we assume that the transport protocol is UDP and no | 614 | /* we assume that the transport protocol is UDP and no |
618 | * IPV6 options are used. | 615 | * IPV6 options are used. |
619 | */ | 616 | */ |
620 | data->mtu = sockopt_val - 8 - 40; | 617 | data->mtu = sockopt_val - 8 - 40; |
621 | ret = data->mtu; | 618 | ret = data->mtu; |
622 | } | 619 | } |
623 | break; | 620 | break; |
624 | #endif | 621 | #endif |
625 | default: | 622 | default: |
626 | ret = 0; | 623 | ret = 0; |
627 | break; | 624 | break; |
628 | } | 625 | } |
629 | #else | 626 | #else |
630 | ret = 0; | 627 | ret = 0; |
631 | #endif | 628 | #endif |
632 | break; | 629 | break; |
633 | case BIO_CTRL_DGRAM_GET_FALLBACK_MTU: | 630 | case BIO_CTRL_DGRAM_GET_FALLBACK_MTU: |
634 | switch (data->peer.sa.sa_family) | 631 | switch (data->peer.sa.sa_family) { |
635 | { | 632 | case AF_INET: |
636 | case AF_INET: | 633 | ret = 576 - 20 - 8; |
637 | ret = 576 - 20 - 8; | 634 | break; |
638 | break; | ||
639 | #if OPENSSL_USE_IPV6 | 635 | #if OPENSSL_USE_IPV6 |
640 | case AF_INET6: | 636 | case AF_INET6: |
641 | #ifdef IN6_IS_ADDR_V4MAPPED | 637 | #ifdef IN6_IS_ADDR_V4MAPPED |
642 | if (IN6_IS_ADDR_V4MAPPED(&data->peer.sa_in6.sin6_addr)) | 638 | if (IN6_IS_ADDR_V4MAPPED(&data->peer.sa_in6.sin6_addr)) |
643 | ret = 576 - 20 - 8; | 639 | ret = 576 - 20 - 8; |
644 | else | 640 | else |
645 | #endif | 641 | #endif |
646 | ret = 1280 - 40 - 8; | 642 | ret = 1280 - 40 - 8; |
647 | break; | 643 | break; |
648 | #endif | 644 | #endif |
649 | default: | 645 | default: |
650 | ret = 576 - 20 - 8; | 646 | ret = 576 - 20 - 8; |
651 | break; | 647 | break; |
652 | } | 648 | } |
653 | break; | 649 | break; |
654 | case BIO_CTRL_DGRAM_GET_MTU: | 650 | case BIO_CTRL_DGRAM_GET_MTU: |
655 | return data->mtu; | 651 | return data->mtu; |
@@ -661,65 +657,59 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
661 | case BIO_CTRL_DGRAM_SET_CONNECTED: | 657 | case BIO_CTRL_DGRAM_SET_CONNECTED: |
662 | to = (struct sockaddr *)ptr; | 658 | to = (struct sockaddr *)ptr; |
663 | 659 | ||
664 | if ( to != NULL) | 660 | if (to != NULL) { |
665 | { | ||
666 | data->connected = 1; | 661 | data->connected = 1; |
667 | switch (to->sa_family) | 662 | switch (to->sa_family) { |
668 | { | ||
669 | case AF_INET: | ||
670 | memcpy(&data->peer,to,sizeof(data->peer.sa_in)); | ||
671 | break; | ||
672 | #if OPENSSL_USE_IPV6 | ||
673 | case AF_INET6: | ||
674 | memcpy(&data->peer,to,sizeof(data->peer.sa_in6)); | ||
675 | break; | ||
676 | #endif | ||
677 | default: | ||
678 | memcpy(&data->peer,to,sizeof(data->peer.sa)); | ||
679 | break; | ||
680 | } | ||
681 | } | ||
682 | else | ||
683 | { | ||
684 | data->connected = 0; | ||
685 | memset(&(data->peer), 0x00, sizeof(data->peer)); | ||
686 | } | ||
687 | break; | ||
688 | case BIO_CTRL_DGRAM_GET_PEER: | ||
689 | switch (data->peer.sa.sa_family) | ||
690 | { | ||
691 | case AF_INET: | 663 | case AF_INET: |
692 | ret=sizeof(data->peer.sa_in); | 664 | memcpy(&data->peer, to, sizeof(data->peer.sa_in)); |
693 | break; | 665 | break; |
694 | #if OPENSSL_USE_IPV6 | 666 | #if OPENSSL_USE_IPV6 |
695 | case AF_INET6: | 667 | case AF_INET6: |
696 | ret=sizeof(data->peer.sa_in6); | 668 | memcpy(&data->peer, to, sizeof(data->peer.sa_in6)); |
697 | break; | 669 | break; |
698 | #endif | 670 | #endif |
699 | default: | 671 | default: |
700 | ret=sizeof(data->peer.sa); | 672 | memcpy(&data->peer, to, sizeof(data->peer.sa)); |
701 | break; | 673 | break; |
702 | } | 674 | } |
703 | if (num==0 || num>ret) | 675 | } else { |
704 | num=ret; | 676 | data->connected = 0; |
705 | memcpy(ptr,&data->peer,(ret=num)); | 677 | memset(&(data->peer), 0x00, sizeof(data->peer)); |
678 | } | ||
679 | break; | ||
680 | case BIO_CTRL_DGRAM_GET_PEER: | ||
681 | switch (data->peer.sa.sa_family) { | ||
682 | case AF_INET: | ||
683 | ret = sizeof(data->peer.sa_in); | ||
684 | break; | ||
685 | #if OPENSSL_USE_IPV6 | ||
686 | case AF_INET6: | ||
687 | ret = sizeof(data->peer.sa_in6); | ||
688 | break; | ||
689 | #endif | ||
690 | default: | ||
691 | ret = sizeof(data->peer.sa); | ||
692 | break; | ||
693 | } | ||
694 | if (num == 0 || num > ret) | ||
695 | num = ret; | ||
696 | memcpy(ptr, &data->peer, (ret = num)); | ||
706 | break; | 697 | break; |
707 | case BIO_CTRL_DGRAM_SET_PEER: | 698 | case BIO_CTRL_DGRAM_SET_PEER: |
708 | to = (struct sockaddr *) ptr; | 699 | to = (struct sockaddr *) ptr; |
709 | switch (to->sa_family) | 700 | switch (to->sa_family) { |
710 | { | 701 | case AF_INET: |
711 | case AF_INET: | 702 | memcpy(&data->peer, to, sizeof(data->peer.sa_in)); |
712 | memcpy(&data->peer,to,sizeof(data->peer.sa_in)); | 703 | break; |
713 | break; | ||
714 | #if OPENSSL_USE_IPV6 | 704 | #if OPENSSL_USE_IPV6 |
715 | case AF_INET6: | 705 | case AF_INET6: |
716 | memcpy(&data->peer,to,sizeof(data->peer.sa_in6)); | 706 | memcpy(&data->peer, to, sizeof(data->peer.sa_in6)); |
717 | break; | 707 | break; |
718 | #endif | 708 | #endif |
719 | default: | 709 | default: |
720 | memcpy(&data->peer,to,sizeof(data->peer.sa)); | 710 | memcpy(&data->peer, to, sizeof(data->peer.sa)); |
721 | break; | 711 | break; |
722 | } | 712 | } |
723 | break; | 713 | break; |
724 | case BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT: | 714 | case BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT: |
725 | memcpy(&(data->next_timeout), ptr, sizeof(struct timeval)); | 715 | memcpy(&(data->next_timeout), ptr, sizeof(struct timeval)); |
@@ -728,47 +718,53 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
728 | case BIO_CTRL_DGRAM_SET_RECV_TIMEOUT: | 718 | case BIO_CTRL_DGRAM_SET_RECV_TIMEOUT: |
729 | #ifdef OPENSSL_SYS_WINDOWS | 719 | #ifdef OPENSSL_SYS_WINDOWS |
730 | { | 720 | { |
731 | struct timeval *tv = (struct timeval *)ptr; | 721 | struct timeval *tv = (struct timeval *)ptr; |
732 | int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000; | 722 | int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000; |
733 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | 723 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, |
734 | (void*)&timeout, sizeof(timeout)) < 0) | 724 | (void*)&timeout, sizeof(timeout)) < 0) { |
735 | { perror("setsockopt"); ret = -1; } | 725 | perror("setsockopt"); |
726 | ret = -1; | ||
727 | } | ||
736 | } | 728 | } |
737 | #else | 729 | #else |
738 | if ( setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, ptr, | 730 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, ptr, |
739 | sizeof(struct timeval)) < 0) | 731 | sizeof(struct timeval)) < 0) { |
740 | { perror("setsockopt"); ret = -1; } | 732 | perror("setsockopt"); |
733 | ret = -1; | ||
734 | } | ||
741 | #endif | 735 | #endif |
742 | break; | 736 | break; |
743 | case BIO_CTRL_DGRAM_GET_RECV_TIMEOUT: | 737 | case BIO_CTRL_DGRAM_GET_RECV_TIMEOUT: |
744 | { | 738 | { |
745 | union { size_t s; int i; } sz = {0}; | 739 | union { |
740 | size_t s; | ||
741 | int i; | ||
742 | } sz = {0}; | ||
746 | #ifdef OPENSSL_SYS_WINDOWS | 743 | #ifdef OPENSSL_SYS_WINDOWS |
747 | int timeout; | 744 | int timeout; |
748 | struct timeval *tv = (struct timeval *)ptr; | 745 | struct timeval *tv = (struct timeval *)ptr; |
749 | 746 | ||
750 | sz.i = sizeof(timeout); | 747 | sz.i = sizeof(timeout); |
751 | if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | 748 | if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, |
752 | (void*)&timeout, &sz.i) < 0) | 749 | (void*)&timeout, &sz.i) < 0) { |
753 | { perror("getsockopt"); ret = -1; } | 750 | perror("getsockopt"); |
754 | else | 751 | ret = -1; |
755 | { | 752 | } else { |
756 | tv->tv_sec = timeout / 1000; | 753 | tv->tv_sec = timeout / 1000; |
757 | tv->tv_usec = (timeout % 1000) * 1000; | 754 | tv->tv_usec = (timeout % 1000) * 1000; |
758 | ret = sizeof(*tv); | 755 | ret = sizeof(*tv); |
759 | } | 756 | } |
760 | #else | 757 | #else |
761 | sz.i = sizeof(struct timeval); | 758 | sz.i = sizeof(struct timeval); |
762 | if ( getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | 759 | if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, |
763 | ptr, (void *)&sz) < 0) | 760 | ptr, (void *)&sz) < 0) { |
764 | { perror("getsockopt"); ret = -1; } | 761 | perror("getsockopt"); |
765 | else if (sizeof(sz.s)!=sizeof(sz.i) && sz.i==0) | 762 | ret = -1; |
766 | { | 763 | } else if (sizeof(sz.s)!=sizeof(sz.i) && sz.i==0) { |
767 | OPENSSL_assert(sz.s<=sizeof(struct timeval)); | 764 | OPENSSL_assert(sz.s <= sizeof(struct timeval)); |
768 | ret = (int)sz.s; | 765 | ret = (int)sz.s; |
769 | } | 766 | } else |
770 | else | 767 | ret = sz.i; |
771 | ret = sz.i; | ||
772 | #endif | 768 | #endif |
773 | } | 769 | } |
774 | break; | 770 | break; |
@@ -777,47 +773,53 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
777 | case BIO_CTRL_DGRAM_SET_SEND_TIMEOUT: | 773 | case BIO_CTRL_DGRAM_SET_SEND_TIMEOUT: |
778 | #ifdef OPENSSL_SYS_WINDOWS | 774 | #ifdef OPENSSL_SYS_WINDOWS |
779 | { | 775 | { |
780 | struct timeval *tv = (struct timeval *)ptr; | 776 | struct timeval *tv = (struct timeval *)ptr; |
781 | int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000; | 777 | int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000; |
782 | if (setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, | 778 | if (setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, |
783 | (void*)&timeout, sizeof(timeout)) < 0) | 779 | (void*)&timeout, sizeof(timeout)) < 0) { |
784 | { perror("setsockopt"); ret = -1; } | 780 | perror("setsockopt"); |
781 | ret = -1; | ||
782 | } | ||
785 | } | 783 | } |
786 | #else | 784 | #else |
787 | if ( setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, ptr, | 785 | if (setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, ptr, |
788 | sizeof(struct timeval)) < 0) | 786 | sizeof(struct timeval)) < 0) { |
789 | { perror("setsockopt"); ret = -1; } | 787 | perror("setsockopt"); |
788 | ret = -1; | ||
789 | } | ||
790 | #endif | 790 | #endif |
791 | break; | 791 | break; |
792 | case BIO_CTRL_DGRAM_GET_SEND_TIMEOUT: | 792 | case BIO_CTRL_DGRAM_GET_SEND_TIMEOUT: |
793 | { | 793 | { |
794 | union { size_t s; int i; } sz = {0}; | 794 | union { |
795 | size_t s; | ||
796 | int i; | ||
797 | } sz = {0}; | ||
795 | #ifdef OPENSSL_SYS_WINDOWS | 798 | #ifdef OPENSSL_SYS_WINDOWS |
796 | int timeout; | 799 | int timeout; |
797 | struct timeval *tv = (struct timeval *)ptr; | 800 | struct timeval *tv = (struct timeval *)ptr; |
798 | 801 | ||
799 | sz.i = sizeof(timeout); | 802 | sz.i = sizeof(timeout); |
800 | if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, | 803 | if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, |
801 | (void*)&timeout, &sz.i) < 0) | 804 | (void*)&timeout, &sz.i) < 0) { |
802 | { perror("getsockopt"); ret = -1; } | 805 | perror("getsockopt"); |
803 | else | 806 | ret = -1; |
804 | { | 807 | } else { |
805 | tv->tv_sec = timeout / 1000; | 808 | tv->tv_sec = timeout / 1000; |
806 | tv->tv_usec = (timeout % 1000) * 1000; | 809 | tv->tv_usec = (timeout % 1000) * 1000; |
807 | ret = sizeof(*tv); | 810 | ret = sizeof(*tv); |
808 | } | 811 | } |
809 | #else | 812 | #else |
810 | sz.i = sizeof(struct timeval); | 813 | sz.i = sizeof(struct timeval); |
811 | if ( getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, | 814 | if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, |
812 | ptr, (void *)&sz) < 0) | 815 | ptr, (void *)&sz) < 0) { |
813 | { perror("getsockopt"); ret = -1; } | 816 | perror("getsockopt"); |
814 | else if (sizeof(sz.s)!=sizeof(sz.i) && sz.i==0) | 817 | ret = -1; |
815 | { | 818 | } else if (sizeof(sz.s) != sizeof(sz.i) && sz.i == 0) { |
816 | OPENSSL_assert(sz.s<=sizeof(struct timeval)); | 819 | OPENSSL_assert(sz.s <= sizeof(struct timeval)); |
817 | ret = (int)sz.s; | 820 | ret = (int)sz.s; |
818 | } | 821 | } else |
819 | else | 822 | ret = sz.i; |
820 | ret = sz.i; | ||
821 | #endif | 823 | #endif |
822 | } | 824 | } |
823 | break; | 825 | break; |
@@ -826,52 +828,52 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
826 | /* fall-through */ | 828 | /* fall-through */ |
827 | case BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP: | 829 | case BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP: |
828 | #ifdef OPENSSL_SYS_WINDOWS | 830 | #ifdef OPENSSL_SYS_WINDOWS |
829 | if ( data->_errno == WSAETIMEDOUT) | 831 | if (data->_errno == WSAETIMEDOUT) |
830 | #else | 832 | #else |
831 | if ( data->_errno == EAGAIN) | 833 | if (data->_errno == EAGAIN) |
832 | #endif | 834 | #endif |
833 | { | 835 | { |
834 | ret = 1; | 836 | ret = 1; |
835 | data->_errno = 0; | 837 | data->_errno = 0; |
836 | } | 838 | } else |
837 | else | ||
838 | ret = 0; | 839 | ret = 0; |
839 | break; | 840 | break; |
840 | #ifdef EMSGSIZE | 841 | #ifdef EMSGSIZE |
841 | case BIO_CTRL_DGRAM_MTU_EXCEEDED: | 842 | case BIO_CTRL_DGRAM_MTU_EXCEEDED: |
842 | if ( data->_errno == EMSGSIZE) | 843 | if (data->_errno == EMSGSIZE) { |
843 | { | ||
844 | ret = 1; | 844 | ret = 1; |
845 | data->_errno = 0; | 845 | data->_errno = 0; |
846 | } | 846 | } else |
847 | else | ||
848 | ret = 0; | 847 | ret = 0; |
849 | break; | 848 | break; |
850 | #endif | 849 | #endif |
851 | default: | 850 | default: |
852 | ret=0; | 851 | ret = 0; |
853 | break; | 852 | break; |
854 | } | ||
855 | return(ret); | ||
856 | } | 853 | } |
854 | return (ret); | ||
855 | } | ||
857 | 856 | ||
858 | static int dgram_puts(BIO *bp, const char *str) | 857 | static int |
859 | { | 858 | dgram_puts(BIO *bp, const char *str) |
860 | int n,ret; | 859 | { |
860 | int n, ret; | ||
861 | 861 | ||
862 | n=strlen(str); | 862 | n = strlen(str); |
863 | ret=dgram_write(bp,str,n); | 863 | ret = dgram_write(bp, str, n); |
864 | return(ret); | 864 | return (ret); |
865 | } | 865 | } |
866 | 866 | ||
867 | #ifndef OPENSSL_NO_SCTP | 867 | #ifndef OPENSSL_NO_SCTP |
868 | BIO_METHOD *BIO_s_datagram_sctp(void) | 868 | BIO_METHOD |
869 | { | 869 | *BIO_s_datagram_sctp(void) |
870 | return(&methods_dgramp_sctp); | 870 | { |
871 | } | 871 | return (&methods_dgramp_sctp); |
872 | } | ||
872 | 873 | ||
873 | BIO *BIO_new_dgram_sctp(int fd, int close_flag) | 874 | BIO |
874 | { | 875 | *BIO_new_dgram_sctp(int fd, int close_flag) |
876 | { | ||
875 | BIO *bio; | 877 | BIO *bio; |
876 | int ret, optval = 20000; | 878 | int ret, optval = 20000; |
877 | int auth_data = 0, auth_forward = 0; | 879 | int auth_data = 0, auth_forward = 0; |
@@ -887,9 +889,10 @@ BIO *BIO_new_dgram_sctp(int fd, int close_flag) | |||
887 | #endif | 889 | #endif |
888 | #endif | 890 | #endif |
889 | 891 | ||
890 | bio=BIO_new(BIO_s_datagram_sctp()); | 892 | bio = BIO_new(BIO_s_datagram_sctp()); |
891 | if (bio == NULL) return(NULL); | 893 | if (bio == NULL) |
892 | BIO_set_fd(bio,fd,close_flag); | 894 | return (NULL); |
895 | BIO_set_fd(bio, fd, close_flag); | ||
893 | 896 | ||
894 | /* Activate SCTP-AUTH for DATA and FORWARD-TSN chunks */ | 897 | /* Activate SCTP-AUTH for DATA and FORWARD-TSN chunks */ |
895 | auth.sauth_chunk = OPENSSL_SCTP_DATA_CHUNK_TYPE; | 898 | auth.sauth_chunk = OPENSSL_SCTP_DATA_CHUNK_TYPE; |
@@ -909,13 +912,14 @@ BIO *BIO_new_dgram_sctp(int fd, int close_flag) | |||
909 | OPENSSL_assert(ret >= 0); | 912 | OPENSSL_assert(ret >= 0); |
910 | 913 | ||
911 | for (p = (unsigned char*) authchunks->gauth_chunks; | 914 | for (p = (unsigned char*) authchunks->gauth_chunks; |
912 | p < (unsigned char*) authchunks + sockopt_len; | 915 | p < (unsigned char*) authchunks + sockopt_len; |
913 | p += sizeof(uint8_t)) | 916 | p += sizeof(uint8_t)) { |
914 | { | 917 | if (*p == OPENSSL_SCTP_DATA_CHUNK_TYPE) |
915 | if (*p == OPENSSL_SCTP_DATA_CHUNK_TYPE) auth_data = 1; | 918 | auth_data = 1; |
916 | if (*p == OPENSSL_SCTP_FORWARD_CUM_TSN_CHUNK_TYPE) auth_forward = 1; | 919 | if (*p == OPENSSL_SCTP_FORWARD_CUM_TSN_CHUNK_TYPE) |
917 | } | 920 | auth_forward = 1; |
918 | 921 | } | |
922 | |||
919 | OPENSSL_free(authchunks); | 923 | OPENSSL_free(authchunks); |
920 | 924 | ||
921 | OPENSSL_assert(auth_data); | 925 | OPENSSL_assert(auth_data); |
@@ -947,20 +951,22 @@ BIO *BIO_new_dgram_sctp(int fd, int close_flag) | |||
947 | ret = setsockopt(fd, IPPROTO_SCTP, SCTP_PARTIAL_DELIVERY_POINT, &optval, sizeof(optval)); | 951 | ret = setsockopt(fd, IPPROTO_SCTP, SCTP_PARTIAL_DELIVERY_POINT, &optval, sizeof(optval)); |
948 | OPENSSL_assert(ret >= 0); | 952 | OPENSSL_assert(ret >= 0); |
949 | 953 | ||
950 | return(bio); | 954 | return (bio); |
951 | } | 955 | } |
952 | 956 | ||
953 | int BIO_dgram_is_sctp(BIO *bio) | 957 | int |
954 | { | 958 | BIO_dgram_is_sctp(BIO *bio) |
959 | { | ||
955 | return (BIO_method_type(bio) == BIO_TYPE_DGRAM_SCTP); | 960 | return (BIO_method_type(bio) == BIO_TYPE_DGRAM_SCTP); |
956 | } | 961 | } |
957 | 962 | ||
958 | static int dgram_sctp_new(BIO *bi) | 963 | static int |
959 | { | 964 | dgram_sctp_new(BIO *bi) |
965 | { | ||
960 | bio_dgram_sctp_data *data = NULL; | 966 | bio_dgram_sctp_data *data = NULL; |
961 | 967 | ||
962 | bi->init=0; | 968 | bi->init = 0; |
963 | bi->num=0; | 969 | bi->num = 0; |
964 | data = OPENSSL_malloc(sizeof(bio_dgram_sctp_data)); | 970 | data = OPENSSL_malloc(sizeof(bio_dgram_sctp_data)); |
965 | if (data == NULL) | 971 | if (data == NULL) |
966 | return 0; | 972 | return 0; |
@@ -968,46 +974,50 @@ static int dgram_sctp_new(BIO *bi) | |||
968 | #ifdef SCTP_PR_SCTP_NONE | 974 | #ifdef SCTP_PR_SCTP_NONE |
969 | data->prinfo.pr_policy = SCTP_PR_SCTP_NONE; | 975 | data->prinfo.pr_policy = SCTP_PR_SCTP_NONE; |
970 | #endif | 976 | #endif |
971 | bi->ptr = data; | 977 | bi->ptr = data; |
972 | 978 | ||
973 | bi->flags=0; | 979 | bi->flags = 0; |
974 | return(1); | 980 | return (1); |
975 | } | 981 | } |
976 | 982 | ||
977 | static int dgram_sctp_free(BIO *a) | 983 | static int |
978 | { | 984 | dgram_sctp_free(BIO *a) |
985 | { | ||
979 | bio_dgram_sctp_data *data; | 986 | bio_dgram_sctp_data *data; |
980 | 987 | ||
981 | if (a == NULL) return(0); | 988 | if (a == NULL) |
982 | if ( ! dgram_clear(a)) | 989 | return (0); |
990 | if (! dgram_clear(a)) | ||
983 | return 0; | 991 | return 0; |
984 | 992 | ||
985 | data = (bio_dgram_sctp_data *)a->ptr; | 993 | data = (bio_dgram_sctp_data *)a->ptr; |
986 | if(data != NULL) OPENSSL_free(data); | 994 | if (data != NULL) |
995 | OPENSSL_free(data); | ||
987 | 996 | ||
988 | return(1); | 997 | return (1); |
989 | } | 998 | } |
990 | 999 | ||
991 | #ifdef SCTP_AUTHENTICATION_EVENT | 1000 | #ifdef SCTP_AUTHENTICATION_EVENT |
992 | void dgram_sctp_handle_auth_free_key_event(BIO *b, union sctp_notification *snp) | 1001 | void |
993 | { | 1002 | dgram_sctp_handle_auth_free_key_event(BIO *b, union sctp_notification *snp) |
1003 | { | ||
994 | int ret; | 1004 | int ret; |
995 | struct sctp_authkey_event* authkeyevent = &snp->sn_auth_event; | 1005 | struct sctp_authkey_event* authkeyevent = &snp->sn_auth_event; |
996 | 1006 | ||
997 | if (authkeyevent->auth_indication == SCTP_AUTH_FREE_KEY) | 1007 | if (authkeyevent->auth_indication == SCTP_AUTH_FREE_KEY) { |
998 | { | ||
999 | struct sctp_authkeyid authkeyid; | 1008 | struct sctp_authkeyid authkeyid; |
1000 | 1009 | ||
1001 | /* delete key */ | 1010 | /* delete key */ |
1002 | authkeyid.scact_keynumber = authkeyevent->auth_keynumber; | 1011 | authkeyid.scact_keynumber = authkeyevent->auth_keynumber; |
1003 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DELETE_KEY, | 1012 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DELETE_KEY, |
1004 | &authkeyid, sizeof(struct sctp_authkeyid)); | 1013 | &authkeyid, sizeof(struct sctp_authkeyid)); |
1005 | } | ||
1006 | } | 1014 | } |
1015 | } | ||
1007 | #endif | 1016 | #endif |
1008 | 1017 | ||
1009 | static int dgram_sctp_read(BIO *b, char *out, int outl) | 1018 | static int |
1010 | { | 1019 | dgram_sctp_read(BIO *b, char *out, int outl) |
1020 | { | ||
1011 | int ret = 0, n = 0, i, optval; | 1021 | int ret = 0, n = 0, i, optval; |
1012 | socklen_t optlen; | 1022 | socklen_t optlen; |
1013 | bio_dgram_sctp_data *data = (bio_dgram_sctp_data *)b->ptr; | 1023 | bio_dgram_sctp_data *data = (bio_dgram_sctp_data *)b->ptr; |
@@ -1017,12 +1027,10 @@ static int dgram_sctp_read(BIO *b, char *out, int outl) | |||
1017 | struct cmsghdr *cmsg; | 1027 | struct cmsghdr *cmsg; |
1018 | char cmsgbuf[512]; | 1028 | char cmsgbuf[512]; |
1019 | 1029 | ||
1020 | if (out != NULL) | 1030 | if (out != NULL) { |
1021 | { | ||
1022 | errno = 0; | 1031 | errno = 0; |
1023 | 1032 | ||
1024 | do | 1033 | do { |
1025 | { | ||
1026 | memset(&data->rcvinfo, 0x00, sizeof(struct bio_dgram_sctp_rcvinfo)); | 1034 | memset(&data->rcvinfo, 0x00, sizeof(struct bio_dgram_sctp_rcvinfo)); |
1027 | iov.iov_base = out; | 1035 | iov.iov_base = out; |
1028 | iov.iov_len = outl; | 1036 | iov.iov_len = outl; |
@@ -1035,15 +1043,12 @@ static int dgram_sctp_read(BIO *b, char *out, int outl) | |||
1035 | msg.msg_flags = 0; | 1043 | msg.msg_flags = 0; |
1036 | n = recvmsg(b->num, &msg, 0); | 1044 | n = recvmsg(b->num, &msg, 0); |
1037 | 1045 | ||
1038 | if (msg.msg_controllen > 0) | 1046 | if (msg.msg_controllen > 0) { |
1039 | { | 1047 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) { |
1040 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) | ||
1041 | { | ||
1042 | if (cmsg->cmsg_level != IPPROTO_SCTP) | 1048 | if (cmsg->cmsg_level != IPPROTO_SCTP) |
1043 | continue; | 1049 | continue; |
1044 | #ifdef SCTP_RCVINFO | 1050 | #ifdef SCTP_RCVINFO |
1045 | if (cmsg->cmsg_type == SCTP_RCVINFO) | 1051 | if (cmsg->cmsg_type == SCTP_RCVINFO) { |
1046 | { | ||
1047 | struct sctp_rcvinfo *rcvinfo; | 1052 | struct sctp_rcvinfo *rcvinfo; |
1048 | 1053 | ||
1049 | rcvinfo = (struct sctp_rcvinfo *)CMSG_DATA(cmsg); | 1054 | rcvinfo = (struct sctp_rcvinfo *)CMSG_DATA(cmsg); |
@@ -1054,11 +1059,10 @@ static int dgram_sctp_read(BIO *b, char *out, int outl) | |||
1054 | data->rcvinfo.rcv_tsn = rcvinfo->rcv_tsn; | 1059 | data->rcvinfo.rcv_tsn = rcvinfo->rcv_tsn; |
1055 | data->rcvinfo.rcv_cumtsn = rcvinfo->rcv_cumtsn; | 1060 | data->rcvinfo.rcv_cumtsn = rcvinfo->rcv_cumtsn; |
1056 | data->rcvinfo.rcv_context = rcvinfo->rcv_context; | 1061 | data->rcvinfo.rcv_context = rcvinfo->rcv_context; |
1057 | } | 1062 | } |
1058 | #endif | 1063 | #endif |
1059 | #ifdef SCTP_SNDRCV | 1064 | #ifdef SCTP_SNDRCV |
1060 | if (cmsg->cmsg_type == SCTP_SNDRCV) | 1065 | if (cmsg->cmsg_type == SCTP_SNDRCV) { |
1061 | { | ||
1062 | struct sctp_sndrcvinfo *sndrcvinfo; | 1066 | struct sctp_sndrcvinfo *sndrcvinfo; |
1063 | 1067 | ||
1064 | sndrcvinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); | 1068 | sndrcvinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); |
@@ -1069,23 +1073,20 @@ static int dgram_sctp_read(BIO *b, char *out, int outl) | |||
1069 | data->rcvinfo.rcv_tsn = sndrcvinfo->sinfo_tsn; | 1073 | data->rcvinfo.rcv_tsn = sndrcvinfo->sinfo_tsn; |
1070 | data->rcvinfo.rcv_cumtsn = sndrcvinfo->sinfo_cumtsn; | 1074 | data->rcvinfo.rcv_cumtsn = sndrcvinfo->sinfo_cumtsn; |
1071 | data->rcvinfo.rcv_context = sndrcvinfo->sinfo_context; | 1075 | data->rcvinfo.rcv_context = sndrcvinfo->sinfo_context; |
1072 | } | ||
1073 | #endif | ||
1074 | } | 1076 | } |
1077 | #endif | ||
1075 | } | 1078 | } |
1079 | } | ||
1076 | 1080 | ||
1077 | if (n <= 0) | 1081 | if (n <= 0) { |
1078 | { | ||
1079 | if (n < 0) | 1082 | if (n < 0) |
1080 | ret = n; | 1083 | ret = n; |
1081 | break; | 1084 | break; |
1082 | } | 1085 | } |
1083 | 1086 | ||
1084 | if (msg.msg_flags & MSG_NOTIFICATION) | 1087 | if (msg.msg_flags & MSG_NOTIFICATION) { |
1085 | { | ||
1086 | snp = (union sctp_notification*) out; | 1088 | snp = (union sctp_notification*) out; |
1087 | if (snp->sn_header.sn_type == SCTP_SENDER_DRY_EVENT) | 1089 | if (snp->sn_header.sn_type == SCTP_SENDER_DRY_EVENT) { |
1088 | { | ||
1089 | #ifdef SCTP_EVENT | 1090 | #ifdef SCTP_EVENT |
1090 | struct sctp_event event; | 1091 | struct sctp_event event; |
1091 | #else | 1092 | #else |
@@ -1095,13 +1096,12 @@ static int dgram_sctp_read(BIO *b, char *out, int outl) | |||
1095 | /* If a message has been delayed until the socket | 1096 | /* If a message has been delayed until the socket |
1096 | * is dry, it can be sent now. | 1097 | * is dry, it can be sent now. |
1097 | */ | 1098 | */ |
1098 | if (data->saved_message.length > 0) | 1099 | if (data->saved_message.length > 0) { |
1099 | { | ||
1100 | dgram_sctp_write(data->saved_message.bio, data->saved_message.data, | 1100 | dgram_sctp_write(data->saved_message.bio, data->saved_message.data, |
1101 | data->saved_message.length); | 1101 | data->saved_message.length); |
1102 | OPENSSL_free(data->saved_message.data); | 1102 | OPENSSL_free(data->saved_message.data); |
1103 | data->saved_message.length = 0; | 1103 | data->saved_message.length = 0; |
1104 | } | 1104 | } |
1105 | 1105 | ||
1106 | /* disable sender dry event */ | 1106 | /* disable sender dry event */ |
1107 | #ifdef SCTP_EVENT | 1107 | #ifdef SCTP_EVENT |
@@ -1121,7 +1121,7 @@ static int dgram_sctp_read(BIO *b, char *out, int outl) | |||
1121 | i = setsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, sizeof(struct sctp_event_subscribe)); | 1121 | i = setsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, sizeof(struct sctp_event_subscribe)); |
1122 | OPENSSL_assert(i >= 0); | 1122 | OPENSSL_assert(i >= 0); |
1123 | #endif | 1123 | #endif |
1124 | } | 1124 | } |
1125 | 1125 | ||
1126 | #ifdef SCTP_AUTHENTICATION_EVENT | 1126 | #ifdef SCTP_AUTHENTICATION_EVENT |
1127 | if (snp->sn_header.sn_type == SCTP_AUTHENTICATION_EVENT) | 1127 | if (snp->sn_header.sn_type == SCTP_AUTHENTICATION_EVENT) |
@@ -1132,14 +1132,12 @@ static int dgram_sctp_read(BIO *b, char *out, int outl) | |||
1132 | data->handle_notifications(b, data->notification_context, (void*) out); | 1132 | data->handle_notifications(b, data->notification_context, (void*) out); |
1133 | 1133 | ||
1134 | memset(out, 0, outl); | 1134 | memset(out, 0, outl); |
1135 | } | 1135 | } else |
1136 | else | ||
1137 | ret += n; | 1136 | ret += n; |
1138 | } | 1137 | } |
1139 | while ((msg.msg_flags & MSG_NOTIFICATION) && (msg.msg_flags & MSG_EOR) && (ret < outl)); | 1138 | while ((msg.msg_flags & MSG_NOTIFICATION) && (msg.msg_flags & MSG_EOR) && (ret < outl)); |
1140 | 1139 | ||
1141 | if (ret > 0 && !(msg.msg_flags & MSG_EOR)) | 1140 | if (ret > 0 && !(msg.msg_flags & MSG_EOR)) { |
1142 | { | ||
1143 | /* Partial message read, this should never happen! */ | 1141 | /* Partial message read, this should never happen! */ |
1144 | 1142 | ||
1145 | /* The buffer was too small, this means the peer sent | 1143 | /* The buffer was too small, this means the peer sent |
@@ -1159,8 +1157,8 @@ static int dgram_sctp_read(BIO *b, char *out, int outl) | |||
1159 | * max record size (2^14 + 2048 + 13) | 1157 | * max record size (2^14 + 2048 + 13) |
1160 | */ | 1158 | */ |
1161 | optlen = (socklen_t) sizeof(int); | 1159 | optlen = (socklen_t) sizeof(int); |
1162 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_PARTIAL_DELIVERY_POINT, | 1160 | ret = getsockopt(b->num, IPPROTO_SCTP, |
1163 | &optval, &optlen); | 1161 | SCTP_PARTIAL_DELIVERY_POINT, &optval, &optlen); |
1164 | OPENSSL_assert(ret >= 0); | 1162 | OPENSSL_assert(ret >= 0); |
1165 | OPENSSL_assert(optval >= 18445); | 1163 | OPENSSL_assert(optval >= 18445); |
1166 | 1164 | ||
@@ -1173,21 +1171,18 @@ static int dgram_sctp_read(BIO *b, char *out, int outl) | |||
1173 | memset(out, 0, outl); | 1171 | memset(out, 0, outl); |
1174 | BIO_set_retry_read(b); | 1172 | BIO_set_retry_read(b); |
1175 | return -1; | 1173 | return -1; |
1176 | } | 1174 | } |
1177 | 1175 | ||
1178 | BIO_clear_retry_flags(b); | 1176 | BIO_clear_retry_flags(b); |
1179 | if (ret < 0) | 1177 | if (ret < 0) { |
1180 | { | 1178 | if (BIO_dgram_should_retry(ret)) { |
1181 | if (BIO_dgram_should_retry(ret)) | ||
1182 | { | ||
1183 | BIO_set_retry_read(b); | 1179 | BIO_set_retry_read(b); |
1184 | data->_errno = errno; | 1180 | data->_errno = errno; |
1185 | } | ||
1186 | } | 1181 | } |
1182 | } | ||
1187 | 1183 | ||
1188 | /* Test if peer uses SCTP-AUTH before continuing */ | 1184 | /* Test if peer uses SCTP-AUTH before continuing */ |
1189 | if (!data->peer_auth_tested) | 1185 | if (!data->peer_auth_tested) { |
1190 | { | ||
1191 | int ii, auth_data = 0, auth_forward = 0; | 1186 | int ii, auth_data = 0, auth_forward = 0; |
1192 | unsigned char *p; | 1187 | unsigned char *p; |
1193 | struct sctp_authchunks *authchunks; | 1188 | struct sctp_authchunks *authchunks; |
@@ -1199,29 +1194,30 @@ static int dgram_sctp_read(BIO *b, char *out, int outl) | |||
1199 | OPENSSL_assert(ii >= 0); | 1194 | OPENSSL_assert(ii >= 0); |
1200 | 1195 | ||
1201 | for (p = (unsigned char*) authchunks->gauth_chunks; | 1196 | for (p = (unsigned char*) authchunks->gauth_chunks; |
1202 | p < (unsigned char*) authchunks + optlen; | 1197 | p < (unsigned char*) authchunks + optlen; |
1203 | p += sizeof(uint8_t)) | 1198 | p += sizeof(uint8_t)) { |
1204 | { | 1199 | if (*p == OPENSSL_SCTP_DATA_CHUNK_TYPE) |
1205 | if (*p == OPENSSL_SCTP_DATA_CHUNK_TYPE) auth_data = 1; | 1200 | auth_data = 1; |
1206 | if (*p == OPENSSL_SCTP_FORWARD_CUM_TSN_CHUNK_TYPE) auth_forward = 1; | 1201 | if (*p == OPENSSL_SCTP_FORWARD_CUM_TSN_CHUNK_TYPE) |
1207 | } | 1202 | auth_forward = 1; |
1203 | } | ||
1208 | 1204 | ||
1209 | OPENSSL_free(authchunks); | 1205 | OPENSSL_free(authchunks); |
1210 | 1206 | ||
1211 | if (!auth_data || !auth_forward) | 1207 | if (!auth_data || !auth_forward) { |
1212 | { | 1208 | BIOerr(BIO_F_DGRAM_SCTP_READ, BIO_R_CONNECT_ERROR); |
1213 | BIOerr(BIO_F_DGRAM_SCTP_READ,BIO_R_CONNECT_ERROR); | ||
1214 | return -1; | 1209 | return -1; |
1215 | } | 1210 | } |
1216 | 1211 | ||
1217 | data->peer_auth_tested = 1; | 1212 | data->peer_auth_tested = 1; |
1218 | } | ||
1219 | } | 1213 | } |
1220 | return(ret); | ||
1221 | } | 1214 | } |
1215 | return (ret); | ||
1216 | } | ||
1222 | 1217 | ||
1223 | static int dgram_sctp_write(BIO *b, const char *in, int inl) | 1218 | static int |
1224 | { | 1219 | dgram_sctp_write(BIO *b, const char *in, int inl) |
1220 | { | ||
1225 | int ret; | 1221 | int ret; |
1226 | bio_dgram_sctp_data *data = (bio_dgram_sctp_data *)b->ptr; | 1222 | bio_dgram_sctp_data *data = (bio_dgram_sctp_data *)b->ptr; |
1227 | struct bio_dgram_sctp_sndinfo *sinfo = &(data->sndinfo); | 1223 | struct bio_dgram_sctp_sndinfo *sinfo = &(data->sndinfo); |
@@ -1256,8 +1252,7 @@ static int dgram_sctp_write(BIO *b, const char *in, int inl) | |||
1256 | * socket is not dry yet, we have to save it and send it | 1252 | * socket is not dry yet, we have to save it and send it |
1257 | * as soon as the socket gets dry. | 1253 | * as soon as the socket gets dry. |
1258 | */ | 1254 | */ |
1259 | if (data->save_shutdown && !BIO_dgram_sctp_wait_for_dry(b)) | 1255 | if (data->save_shutdown && !BIO_dgram_sctp_wait_for_dry(b)) { |
1260 | { | ||
1261 | data->saved_message.bio = b; | 1256 | data->saved_message.bio = b; |
1262 | data->saved_message.length = inl; | 1257 | data->saved_message.length = inl; |
1263 | data->saved_message.data = OPENSSL_malloc(inl); | 1258 | data->saved_message.data = OPENSSL_malloc(inl); |
@@ -1317,20 +1312,20 @@ static int dgram_sctp_write(BIO *b, const char *in, int inl) | |||
1317 | ret = sendmsg(b->num, &msg, 0); | 1312 | ret = sendmsg(b->num, &msg, 0); |
1318 | 1313 | ||
1319 | BIO_clear_retry_flags(b); | 1314 | BIO_clear_retry_flags(b); |
1320 | if (ret <= 0) | 1315 | if (ret <= 0) { |
1321 | { | 1316 | if (BIO_dgram_should_retry(ret)) { |
1322 | if (BIO_dgram_should_retry(ret)) | 1317 | BIO_set_retry_write(b); |
1323 | { | 1318 | |
1324 | BIO_set_retry_write(b); | ||
1325 | data->_errno = errno; | 1319 | data->_errno = errno; |
1326 | } | ||
1327 | } | 1320 | } |
1328 | return(ret); | ||
1329 | } | 1321 | } |
1322 | return (ret); | ||
1323 | } | ||
1330 | 1324 | ||
1331 | static long dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr) | 1325 | static long |
1332 | { | 1326 | dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr) |
1333 | long ret=1; | 1327 | { |
1328 | long ret = 1; | ||
1334 | bio_dgram_sctp_data *data = NULL; | 1329 | bio_dgram_sctp_data *data = NULL; |
1335 | socklen_t sockopt_len = 0; | 1330 | socklen_t sockopt_len = 0; |
1336 | struct sctp_authkeyid authkeyid; | 1331 | struct sctp_authkeyid authkeyid; |
@@ -1338,8 +1333,7 @@ static long dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
1338 | 1333 | ||
1339 | data = (bio_dgram_sctp_data *)b->ptr; | 1334 | data = (bio_dgram_sctp_data *)b->ptr; |
1340 | 1335 | ||
1341 | switch (cmd) | 1336 | switch (cmd) { |
1342 | { | ||
1343 | case BIO_CTRL_DGRAM_QUERY_MTU: | 1337 | case BIO_CTRL_DGRAM_QUERY_MTU: |
1344 | /* Set to maximum (2^14) | 1338 | /* Set to maximum (2^14) |
1345 | * and ignore user input to enable transport | 1339 | * and ignore user input to enable transport |
@@ -1384,7 +1378,8 @@ static long dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
1384 | /* Get active key */ | 1378 | /* Get active key */ |
1385 | sockopt_len = sizeof(struct sctp_authkeyid); | 1379 | sockopt_len = sizeof(struct sctp_authkeyid); |
1386 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len); | 1380 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len); |
1387 | if (ret < 0) break; | 1381 | if (ret < 0) |
1382 | break; | ||
1388 | 1383 | ||
1389 | /* Add new key */ | 1384 | /* Add new key */ |
1390 | sockopt_len = sizeof(struct sctp_authkey) + 64 * sizeof(uint8_t); | 1385 | sockopt_len = sizeof(struct sctp_authkey) + 64 * sizeof(uint8_t); |
@@ -1400,12 +1395,14 @@ static long dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
1400 | memcpy(&authkey->sca_key[0], ptr, 64 * sizeof(uint8_t)); | 1395 | memcpy(&authkey->sca_key[0], ptr, 64 * sizeof(uint8_t)); |
1401 | 1396 | ||
1402 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_KEY, authkey, sockopt_len); | 1397 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_KEY, authkey, sockopt_len); |
1403 | if (ret < 0) break; | 1398 | if (ret < 0) |
1399 | break; | ||
1404 | 1400 | ||
1405 | /* Reset active key */ | 1401 | /* Reset active key */ |
1406 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, | 1402 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, |
1407 | &authkeyid, sizeof(struct sctp_authkeyid)); | 1403 | &authkeyid, sizeof(struct sctp_authkeyid)); |
1408 | if (ret < 0) break; | 1404 | if (ret < 0) |
1405 | break; | ||
1409 | 1406 | ||
1410 | break; | 1407 | break; |
1411 | case BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY: | 1408 | case BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY: |
@@ -1414,13 +1411,15 @@ static long dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
1414 | /* Get active key */ | 1411 | /* Get active key */ |
1415 | sockopt_len = sizeof(struct sctp_authkeyid); | 1412 | sockopt_len = sizeof(struct sctp_authkeyid); |
1416 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len); | 1413 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len); |
1417 | if (ret < 0) break; | 1414 | if (ret < 0) |
1415 | break; | ||
1418 | 1416 | ||
1419 | /* Set active key */ | 1417 | /* Set active key */ |
1420 | authkeyid.scact_keynumber = authkeyid.scact_keynumber + 1; | 1418 | authkeyid.scact_keynumber = authkeyid.scact_keynumber + 1; |
1421 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, | 1419 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, |
1422 | &authkeyid, sizeof(struct sctp_authkeyid)); | 1420 | &authkeyid, sizeof(struct sctp_authkeyid)); |
1423 | if (ret < 0) break; | 1421 | if (ret < 0) |
1422 | break; | ||
1424 | 1423 | ||
1425 | /* CCS has been sent, so remember that and fall through | 1424 | /* CCS has been sent, so remember that and fall through |
1426 | * to check if we need to deactivate an old key | 1425 | * to check if we need to deactivate an old key |
@@ -1435,12 +1434,12 @@ static long dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
1435 | data->ccs_rcvd = 1; | 1434 | data->ccs_rcvd = 1; |
1436 | 1435 | ||
1437 | /* CSS has been both, received and sent, so deactivate an old key */ | 1436 | /* CSS has been both, received and sent, so deactivate an old key */ |
1438 | if (data->ccs_rcvd == 1 && data->ccs_sent == 1) | 1437 | if (data->ccs_rcvd == 1 && data->ccs_sent == 1) { |
1439 | { | ||
1440 | /* Get active key */ | 1438 | /* Get active key */ |
1441 | sockopt_len = sizeof(struct sctp_authkeyid); | 1439 | sockopt_len = sizeof(struct sctp_authkeyid); |
1442 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len); | 1440 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len); |
1443 | if (ret < 0) break; | 1441 | if (ret < 0) |
1442 | break; | ||
1444 | 1443 | ||
1445 | /* Deactivate key or delete second last key if | 1444 | /* Deactivate key or delete second last key if |
1446 | * SCTP_AUTHENTICATION_EVENT is not available. | 1445 | * SCTP_AUTHENTICATION_EVENT is not available. |
@@ -1449,22 +1448,23 @@ static long dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
1449 | #ifdef SCTP_AUTH_DEACTIVATE_KEY | 1448 | #ifdef SCTP_AUTH_DEACTIVATE_KEY |
1450 | sockopt_len = sizeof(struct sctp_authkeyid); | 1449 | sockopt_len = sizeof(struct sctp_authkeyid); |
1451 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DEACTIVATE_KEY, | 1450 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DEACTIVATE_KEY, |
1452 | &authkeyid, sockopt_len); | 1451 | &authkeyid, sockopt_len); |
1453 | if (ret < 0) break; | 1452 | if (ret < 0) |
1453 | break; | ||
1454 | #endif | 1454 | #endif |
1455 | #ifndef SCTP_AUTHENTICATION_EVENT | 1455 | #ifndef SCTP_AUTHENTICATION_EVENT |
1456 | if (authkeyid.scact_keynumber > 0) | 1456 | if (authkeyid.scact_keynumber > 0) { |
1457 | { | ||
1458 | authkeyid.scact_keynumber = authkeyid.scact_keynumber - 1; | 1457 | authkeyid.scact_keynumber = authkeyid.scact_keynumber - 1; |
1459 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DELETE_KEY, | 1458 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DELETE_KEY, |
1460 | &authkeyid, sizeof(struct sctp_authkeyid)); | 1459 | &authkeyid, sizeof(struct sctp_authkeyid)); |
1461 | if (ret < 0) break; | 1460 | if (ret < 0) |
1462 | } | 1461 | break; |
1462 | } | ||
1463 | #endif | 1463 | #endif |
1464 | 1464 | ||
1465 | data->ccs_rcvd = 0; | 1465 | data->ccs_rcvd = 0; |
1466 | data->ccs_sent = 0; | 1466 | data->ccs_sent = 0; |
1467 | } | 1467 | } |
1468 | break; | 1468 | break; |
1469 | case BIO_CTRL_DGRAM_SCTP_GET_SNDINFO: | 1469 | case BIO_CTRL_DGRAM_SCTP_GET_SNDINFO: |
1470 | /* Returns the size of the copied struct. */ | 1470 | /* Returns the size of the copied struct. */ |
@@ -1524,30 +1524,30 @@ static long dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
1524 | /* Pass to default ctrl function to | 1524 | /* Pass to default ctrl function to |
1525 | * process SCTP unspecific commands | 1525 | * process SCTP unspecific commands |
1526 | */ | 1526 | */ |
1527 | ret=dgram_ctrl(b, cmd, num, ptr); | 1527 | ret = dgram_ctrl(b, cmd, num, ptr); |
1528 | break; | 1528 | break; |
1529 | } | ||
1530 | return(ret); | ||
1531 | } | 1529 | } |
1530 | return (ret); | ||
1531 | } | ||
1532 | 1532 | ||
1533 | int BIO_dgram_sctp_notification_cb(BIO *b, | 1533 | int |
1534 | void (*handle_notifications)(BIO *bio, void *context, void *buf), | 1534 | BIO_dgram_sctp_notification_cb(BIO *b, |
1535 | void *context) | 1535 | void (*handle_notifications)(BIO *bio, void *context, void *buf), |
1536 | { | 1536 | void *context) |
1537 | { | ||
1537 | bio_dgram_sctp_data *data = (bio_dgram_sctp_data *) b->ptr; | 1538 | bio_dgram_sctp_data *data = (bio_dgram_sctp_data *) b->ptr; |
1538 | 1539 | ||
1539 | if (handle_notifications != NULL) | 1540 | if (handle_notifications != NULL) { |
1540 | { | ||
1541 | data->handle_notifications = handle_notifications; | 1541 | data->handle_notifications = handle_notifications; |
1542 | data->notification_context = context; | 1542 | data->notification_context = context; |
1543 | } | 1543 | } else |
1544 | else | ||
1545 | return -1; | 1544 | return -1; |
1546 | 1545 | ||
1547 | return 0; | 1546 | return 0; |
1548 | } | 1547 | } |
1549 | 1548 | ||
1550 | int BIO_dgram_sctp_wait_for_dry(BIO *b) | 1549 | int |
1550 | BIO_dgram_sctp_wait_for_dry(BIO *b) | ||
1551 | { | 1551 | { |
1552 | int is_dry = 0; | 1552 | int is_dry = 0; |
1553 | int n, sockflags, ret; | 1553 | int n, sockflags, ret; |
@@ -1574,9 +1574,9 @@ int BIO_dgram_sctp_wait_for_dry(BIO *b) | |||
1574 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, &eventsize); | 1574 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, &eventsize); |
1575 | if (ret < 0) | 1575 | if (ret < 0) |
1576 | return -1; | 1576 | return -1; |
1577 | 1577 | ||
1578 | event.sctp_sender_dry_event = 1; | 1578 | event.sctp_sender_dry_event = 1; |
1579 | 1579 | ||
1580 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, sizeof(struct sctp_event_subscribe)); | 1580 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, sizeof(struct sctp_event_subscribe)); |
1581 | #endif | 1581 | #endif |
1582 | if (ret < 0) | 1582 | if (ret < 0) |
@@ -1595,17 +1595,15 @@ int BIO_dgram_sctp_wait_for_dry(BIO *b) | |||
1595 | msg.msg_flags = 0; | 1595 | msg.msg_flags = 0; |
1596 | 1596 | ||
1597 | n = recvmsg(b->num, &msg, MSG_PEEK); | 1597 | n = recvmsg(b->num, &msg, MSG_PEEK); |
1598 | if (n <= 0) | 1598 | if (n <= 0) { |
1599 | { | ||
1600 | if ((n < 0) && (errno != EAGAIN) && (errno != EWOULDBLOCK)) | 1599 | if ((n < 0) && (errno != EAGAIN) && (errno != EWOULDBLOCK)) |
1601 | return -1; | 1600 | return -1; |
1602 | else | 1601 | else |
1603 | return 0; | 1602 | return 0; |
1604 | } | 1603 | } |
1605 | 1604 | ||
1606 | /* if we find a notification, process it and try again if necessary */ | 1605 | /* if we find a notification, process it and try again if necessary */ |
1607 | while (msg.msg_flags & MSG_NOTIFICATION) | 1606 | while (msg.msg_flags & MSG_NOTIFICATION) { |
1608 | { | ||
1609 | memset(&snp, 0x00, sizeof(union sctp_notification)); | 1607 | memset(&snp, 0x00, sizeof(union sctp_notification)); |
1610 | iov.iov_base = (char *)&snp; | 1608 | iov.iov_base = (char *)&snp; |
1611 | iov.iov_len = sizeof(union sctp_notification); | 1609 | iov.iov_len = sizeof(union sctp_notification); |
@@ -1618,16 +1616,14 @@ int BIO_dgram_sctp_wait_for_dry(BIO *b) | |||
1618 | msg.msg_flags = 0; | 1616 | msg.msg_flags = 0; |
1619 | 1617 | ||
1620 | n = recvmsg(b->num, &msg, 0); | 1618 | n = recvmsg(b->num, &msg, 0); |
1621 | if (n <= 0) | 1619 | if (n <= 0) { |
1622 | { | ||
1623 | if ((n < 0) && (errno != EAGAIN) && (errno != EWOULDBLOCK)) | 1620 | if ((n < 0) && (errno != EAGAIN) && (errno != EWOULDBLOCK)) |
1624 | return -1; | 1621 | return -1; |
1625 | else | 1622 | else |
1626 | return is_dry; | 1623 | return is_dry; |
1627 | } | 1624 | } |
1628 | 1625 | ||
1629 | if (snp.sn_header.sn_type == SCTP_SENDER_DRY_EVENT) | 1626 | if (snp.sn_header.sn_type == SCTP_SENDER_DRY_EVENT) { |
1630 | { | ||
1631 | is_dry = 1; | 1627 | is_dry = 1; |
1632 | 1628 | ||
1633 | /* disable sender dry event */ | 1629 | /* disable sender dry event */ |
@@ -1649,7 +1645,7 @@ int BIO_dgram_sctp_wait_for_dry(BIO *b) | |||
1649 | #endif | 1645 | #endif |
1650 | if (ret < 0) | 1646 | if (ret < 0) |
1651 | return -1; | 1647 | return -1; |
1652 | } | 1648 | } |
1653 | 1649 | ||
1654 | #ifdef SCTP_AUTHENTICATION_EVENT | 1650 | #ifdef SCTP_AUTHENTICATION_EVENT |
1655 | if (snp.sn_header.sn_type == SCTP_AUTHENTICATION_EVENT) | 1651 | if (snp.sn_header.sn_type == SCTP_AUTHENTICATION_EVENT) |
@@ -1672,34 +1668,32 @@ int BIO_dgram_sctp_wait_for_dry(BIO *b) | |||
1672 | msg.msg_flags = 0; | 1668 | msg.msg_flags = 0; |
1673 | 1669 | ||
1674 | /* if we have seen the dry already, don't wait */ | 1670 | /* if we have seen the dry already, don't wait */ |
1675 | if (is_dry) | 1671 | if (is_dry) { |
1676 | { | ||
1677 | sockflags = fcntl(b->num, F_GETFL, 0); | 1672 | sockflags = fcntl(b->num, F_GETFL, 0); |
1678 | fcntl(b->num, F_SETFL, O_NONBLOCK); | 1673 | fcntl(b->num, F_SETFL, O_NONBLOCK); |
1679 | } | 1674 | } |
1680 | 1675 | ||
1681 | n = recvmsg(b->num, &msg, MSG_PEEK); | 1676 | n = recvmsg(b->num, &msg, MSG_PEEK); |
1682 | 1677 | ||
1683 | if (is_dry) | 1678 | if (is_dry) { |
1684 | { | ||
1685 | fcntl(b->num, F_SETFL, sockflags); | 1679 | fcntl(b->num, F_SETFL, sockflags); |
1686 | } | 1680 | } |
1687 | 1681 | ||
1688 | if (n <= 0) | 1682 | if (n <= 0) { |
1689 | { | ||
1690 | if ((n < 0) && (errno != EAGAIN) && (errno != EWOULDBLOCK)) | 1683 | if ((n < 0) && (errno != EAGAIN) && (errno != EWOULDBLOCK)) |
1691 | return -1; | 1684 | return -1; |
1692 | else | 1685 | else |
1693 | return is_dry; | 1686 | return is_dry; |
1694 | } | ||
1695 | } | 1687 | } |
1688 | } | ||
1696 | 1689 | ||
1697 | /* read anything else */ | 1690 | /* read anything else */ |
1698 | return is_dry; | 1691 | return is_dry; |
1699 | } | 1692 | } |
1700 | 1693 | ||
1701 | int BIO_dgram_sctp_msg_waiting(BIO *b) | 1694 | int |
1702 | { | 1695 | BIO_dgram_sctp_msg_waiting(BIO *b) |
1696 | { | ||
1703 | int n, sockflags; | 1697 | int n, sockflags; |
1704 | union sctp_notification snp; | 1698 | union sctp_notification snp; |
1705 | struct msghdr msg; | 1699 | struct msghdr msg; |
@@ -1708,7 +1702,7 @@ int BIO_dgram_sctp_msg_waiting(BIO *b) | |||
1708 | 1702 | ||
1709 | /* Check if there are any messages waiting to be read */ | 1703 | /* Check if there are any messages waiting to be read */ |
1710 | do | 1704 | do |
1711 | { | 1705 | { |
1712 | memset(&snp, 0x00, sizeof(union sctp_notification)); | 1706 | memset(&snp, 0x00, sizeof(union sctp_notification)); |
1713 | iov.iov_base = (char *)&snp; | 1707 | iov.iov_base = (char *)&snp; |
1714 | iov.iov_len = sizeof(union sctp_notification); | 1708 | iov.iov_len = sizeof(union sctp_notification); |
@@ -1726,8 +1720,7 @@ int BIO_dgram_sctp_msg_waiting(BIO *b) | |||
1726 | fcntl(b->num, F_SETFL, sockflags); | 1720 | fcntl(b->num, F_SETFL, sockflags); |
1727 | 1721 | ||
1728 | /* if notification, process and try again */ | 1722 | /* if notification, process and try again */ |
1729 | if (n > 0 && (msg.msg_flags & MSG_NOTIFICATION)) | 1723 | if (n > 0 && (msg.msg_flags & MSG_NOTIFICATION)) { |
1730 | { | ||
1731 | #ifdef SCTP_AUTHENTICATION_EVENT | 1724 | #ifdef SCTP_AUTHENTICATION_EVENT |
1732 | if (snp.sn_header.sn_type == SCTP_AUTHENTICATION_EVENT) | 1725 | if (snp.sn_header.sn_type == SCTP_AUTHENTICATION_EVENT) |
1733 | dgram_sctp_handle_auth_free_key_event(b, &snp); | 1726 | dgram_sctp_handle_auth_free_key_event(b, &snp); |
@@ -1747,34 +1740,35 @@ int BIO_dgram_sctp_msg_waiting(BIO *b) | |||
1747 | 1740 | ||
1748 | if (data->handle_notifications != NULL) | 1741 | if (data->handle_notifications != NULL) |
1749 | data->handle_notifications(b, data->notification_context, (void*) &snp); | 1742 | data->handle_notifications(b, data->notification_context, (void*) &snp); |
1750 | } | 1743 | } |
1751 | 1744 | ||
1752 | } while (n > 0 && (msg.msg_flags & MSG_NOTIFICATION)); | 1745 | } while (n > 0 && (msg.msg_flags & MSG_NOTIFICATION)); |
1753 | 1746 | ||
1754 | /* Return 1 if there is a message to be read, return 0 otherwise. */ | 1747 | /* Return 1 if there is a message to be read, return 0 otherwise. */ |
1755 | if (n > 0) | 1748 | if (n > 0) |
1756 | return 1; | 1749 | return 1; |
1757 | else | 1750 | else |
1758 | return 0; | 1751 | return 0; |
1759 | } | 1752 | } |
1760 | 1753 | ||
1761 | static int dgram_sctp_puts(BIO *bp, const char *str) | 1754 | static int |
1762 | { | 1755 | dgram_sctp_puts(BIO *bp, const char *str) |
1763 | int n,ret; | 1756 | { |
1757 | int n, ret; | ||
1764 | 1758 | ||
1765 | n=strlen(str); | 1759 | n = strlen(str); |
1766 | ret=dgram_sctp_write(bp,str,n); | 1760 | ret = dgram_sctp_write(bp, str, n); |
1767 | return(ret); | 1761 | return (ret); |
1768 | } | 1762 | } |
1769 | #endif | 1763 | #endif |
1770 | 1764 | ||
1771 | static int BIO_dgram_should_retry(int i) | 1765 | static int |
1772 | { | 1766 | BIO_dgram_should_retry(int i) |
1767 | { | ||
1773 | int err; | 1768 | int err; |
1774 | 1769 | ||
1775 | if ((i == 0) || (i == -1)) | 1770 | if ((i == 0) || (i == -1)) { |
1776 | { | 1771 | err = errno; |
1777 | err=errno; | ||
1778 | 1772 | ||
1779 | #if defined(OPENSSL_SYS_WINDOWS) | 1773 | #if defined(OPENSSL_SYS_WINDOWS) |
1780 | /* If the socket return value (i) is -1 | 1774 | /* If the socket return value (i) is -1 |
@@ -1785,15 +1779,15 @@ static int BIO_dgram_should_retry(int i) | |||
1785 | */ | 1779 | */ |
1786 | #endif | 1780 | #endif |
1787 | 1781 | ||
1788 | return(BIO_dgram_non_fatal_error(err)); | 1782 | return (BIO_dgram_non_fatal_error(err)); |
1789 | } | ||
1790 | return(0); | ||
1791 | } | 1783 | } |
1784 | return (0); | ||
1785 | } | ||
1792 | 1786 | ||
1793 | int BIO_dgram_non_fatal_error(int err) | 1787 | int |
1794 | { | 1788 | BIO_dgram_non_fatal_error(int err) |
1795 | switch (err) | 1789 | { |
1796 | { | 1790 | switch (err) { |
1797 | #if defined(OPENSSL_SYS_WINDOWS) | 1791 | #if defined(OPENSSL_SYS_WINDOWS) |
1798 | # if defined(WSAEWOULDBLOCK) | 1792 | # if defined(WSAEWOULDBLOCK) |
1799 | case WSAEWOULDBLOCK: | 1793 | case WSAEWOULDBLOCK: |
@@ -1838,17 +1832,17 @@ int BIO_dgram_non_fatal_error(int err) | |||
1838 | case EALREADY: | 1832 | case EALREADY: |
1839 | #endif | 1833 | #endif |
1840 | 1834 | ||
1841 | return(1); | 1835 | return (1); |
1842 | /* break; */ | 1836 | /* break; */ |
1843 | default: | 1837 | default: |
1844 | break; | 1838 | break; |
1845 | } | ||
1846 | return(0); | ||
1847 | } | 1839 | } |
1840 | return (0); | ||
1841 | } | ||
1848 | 1842 | ||
1849 | static void get_current_time(struct timeval *t) | 1843 | static void |
1850 | { | 1844 | get_current_time(struct timeval *t) { |
1851 | gettimeofday(t, NULL); | 1845 | gettimeofday(t, NULL); |
1852 | } | 1846 | } |
1853 | 1847 | ||
1854 | #endif | 1848 | #endif |
diff --git a/src/lib/libssl/src/crypto/bio/bss_fd.c b/src/lib/libssl/src/crypto/bio/bss_fd.c index ab18a56310..35ddd61359 100644 --- a/src/lib/libssl/src/crypto/bio/bss_fd.c +++ b/src/lib/libssl/src/crypto/bio/bss_fd.c | |||
@@ -90,9 +90,8 @@ static int fd_new(BIO *h); | |||
90 | static int fd_free(BIO *data); | 90 | static int fd_free(BIO *data); |
91 | int BIO_fd_should_retry(int s); | 91 | int BIO_fd_should_retry(int s); |
92 | 92 | ||
93 | static BIO_METHOD methods_fdp= | 93 | static BIO_METHOD methods_fdp = { |
94 | { | 94 | BIO_TYPE_FD, "file descriptor", |
95 | BIO_TYPE_FD,"file descriptor", | ||
96 | fd_write, | 95 | fd_write, |
97 | fd_read, | 96 | fd_read, |
98 | fd_puts, | 97 | fd_puts, |
@@ -101,178 +100,182 @@ static BIO_METHOD methods_fdp= | |||
101 | fd_new, | 100 | fd_new, |
102 | fd_free, | 101 | fd_free, |
103 | NULL, | 102 | NULL, |
104 | }; | 103 | }; |
105 | 104 | ||
106 | BIO_METHOD *BIO_s_fd(void) | 105 | BIO_METHOD |
107 | { | 106 | *BIO_s_fd(void) |
108 | return(&methods_fdp); | 107 | { |
109 | } | 108 | return (&methods_fdp); |
109 | } | ||
110 | 110 | ||
111 | BIO *BIO_new_fd(int fd,int close_flag) | 111 | BIO |
112 | { | 112 | *BIO_new_fd(int fd, int close_flag) |
113 | { | ||
113 | BIO *ret; | 114 | BIO *ret; |
114 | ret=BIO_new(BIO_s_fd()); | 115 | ret = BIO_new(BIO_s_fd()); |
115 | if (ret == NULL) return(NULL); | 116 | if (ret == NULL) |
116 | BIO_set_fd(ret,fd,close_flag); | 117 | return (NULL); |
117 | return(ret); | 118 | BIO_set_fd(ret, fd, close_flag); |
118 | } | 119 | return (ret); |
120 | } | ||
119 | 121 | ||
120 | static int fd_new(BIO *bi) | 122 | static int |
121 | { | 123 | fd_new(BIO *bi) |
122 | bi->init=0; | 124 | { |
123 | bi->num=-1; | 125 | bi->init = 0; |
124 | bi->ptr=NULL; | 126 | bi->num = -1; |
127 | bi->ptr = NULL; | ||
125 | bi->flags=BIO_FLAGS_UPLINK; /* essentially redundant */ | 128 | bi->flags=BIO_FLAGS_UPLINK; /* essentially redundant */ |
126 | return(1); | 129 | return (1); |
127 | } | 130 | } |
128 | 131 | ||
129 | static int fd_free(BIO *a) | 132 | static int |
130 | { | 133 | fd_free(BIO *a) |
131 | if (a == NULL) return(0); | 134 | { |
132 | if (a->shutdown) | 135 | if (a == NULL) |
133 | { | 136 | return (0); |
134 | if (a->init) | 137 | if (a->shutdown) { |
135 | { | 138 | if (a->init) { |
136 | UP_close(a->num); | 139 | UP_close(a->num); |
137 | } | ||
138 | a->init=0; | ||
139 | a->flags=BIO_FLAGS_UPLINK; | ||
140 | } | 140 | } |
141 | return(1); | 141 | a->init = 0; |
142 | a->flags = BIO_FLAGS_UPLINK; | ||
142 | } | 143 | } |
143 | 144 | return (1); | |
144 | static int fd_read(BIO *b, char *out,int outl) | 145 | } |
145 | { | ||
146 | int ret=0; | ||
147 | 146 | ||
148 | if (out != NULL) | 147 | static int |
149 | { | 148 | fd_read(BIO *b, char *out, int outl) |
149 | { | ||
150 | int ret = 0; | ||
151 | |||
152 | if (out != NULL) { | ||
150 | errno = 0; | 153 | errno = 0; |
151 | ret=UP_read(b->num,out,outl); | 154 | ret = UP_read(b->num, out, outl); |
152 | BIO_clear_retry_flags(b); | 155 | BIO_clear_retry_flags(b); |
153 | if (ret <= 0) | 156 | if (ret <= 0) { |
154 | { | ||
155 | if (BIO_fd_should_retry(ret)) | 157 | if (BIO_fd_should_retry(ret)) |
156 | BIO_set_retry_read(b); | 158 | BIO_set_retry_read(b); |
157 | } | ||
158 | } | 159 | } |
159 | return(ret); | ||
160 | } | 160 | } |
161 | return (ret); | ||
162 | } | ||
161 | 163 | ||
162 | static int fd_write(BIO *b, const char *in, int inl) | 164 | static int |
163 | { | 165 | fd_write(BIO *b, const char *in, int inl) |
166 | { | ||
164 | int ret; | 167 | int ret; |
165 | errno = 0; | 168 | errno = 0; |
166 | ret=UP_write(b->num,in,inl); | 169 | ret = UP_write(b->num, in, inl); |
167 | BIO_clear_retry_flags(b); | 170 | BIO_clear_retry_flags(b); |
168 | if (ret <= 0) | 171 | if (ret <= 0) { |
169 | { | ||
170 | if (BIO_fd_should_retry(ret)) | 172 | if (BIO_fd_should_retry(ret)) |
171 | BIO_set_retry_write(b); | 173 | BIO_set_retry_write(b); |
172 | } | ||
173 | return(ret); | ||
174 | } | 174 | } |
175 | return (ret); | ||
176 | } | ||
175 | 177 | ||
176 | static long fd_ctrl(BIO *b, int cmd, long num, void *ptr) | 178 | static long |
177 | { | 179 | fd_ctrl(BIO *b, int cmd, long num, void *ptr) |
178 | long ret=1; | 180 | { |
181 | long ret = 1; | ||
179 | int *ip; | 182 | int *ip; |
180 | 183 | ||
181 | switch (cmd) | 184 | switch (cmd) { |
182 | { | ||
183 | case BIO_CTRL_RESET: | 185 | case BIO_CTRL_RESET: |
184 | num=0; | 186 | num = 0; |
185 | case BIO_C_FILE_SEEK: | 187 | case BIO_C_FILE_SEEK: |
186 | ret=(long)UP_lseek(b->num,num,0); | 188 | ret = (long)UP_lseek(b->num, num, 0); |
187 | break; | 189 | break; |
188 | case BIO_C_FILE_TELL: | 190 | case BIO_C_FILE_TELL: |
189 | case BIO_CTRL_INFO: | 191 | case BIO_CTRL_INFO: |
190 | ret=(long)UP_lseek(b->num,0,1); | 192 | ret = (long)UP_lseek(b->num, 0, 1); |
191 | break; | 193 | break; |
192 | case BIO_C_SET_FD: | 194 | case BIO_C_SET_FD: |
193 | fd_free(b); | 195 | fd_free(b); |
194 | b->num= *((int *)ptr); | 196 | b->num= *((int *)ptr); |
195 | b->shutdown=(int)num; | 197 | b->shutdown = (int)num; |
196 | b->init=1; | 198 | b->init = 1; |
197 | break; | 199 | break; |
198 | case BIO_C_GET_FD: | 200 | case BIO_C_GET_FD: |
199 | if (b->init) | 201 | if (b->init) { |
200 | { | 202 | ip = (int *)ptr; |
201 | ip=(int *)ptr; | 203 | if (ip != NULL) |
202 | if (ip != NULL) *ip=b->num; | 204 | *ip = b->num; |
203 | ret=b->num; | 205 | ret = b->num; |
204 | } | 206 | } else |
205 | else | 207 | ret = -1; |
206 | ret= -1; | ||
207 | break; | 208 | break; |
208 | case BIO_CTRL_GET_CLOSE: | 209 | case BIO_CTRL_GET_CLOSE: |
209 | ret=b->shutdown; | 210 | ret = b->shutdown; |
210 | break; | 211 | break; |
211 | case BIO_CTRL_SET_CLOSE: | 212 | case BIO_CTRL_SET_CLOSE: |
212 | b->shutdown=(int)num; | 213 | b->shutdown = (int)num; |
213 | break; | 214 | break; |
214 | case BIO_CTRL_PENDING: | 215 | case BIO_CTRL_PENDING: |
215 | case BIO_CTRL_WPENDING: | 216 | case BIO_CTRL_WPENDING: |
216 | ret=0; | 217 | ret = 0; |
217 | break; | 218 | break; |
218 | case BIO_CTRL_DUP: | 219 | case BIO_CTRL_DUP: |
219 | case BIO_CTRL_FLUSH: | 220 | case BIO_CTRL_FLUSH: |
220 | ret=1; | 221 | ret = 1; |
221 | break; | 222 | break; |
222 | default: | 223 | default: |
223 | ret=0; | 224 | ret = 0; |
224 | break; | 225 | break; |
225 | } | ||
226 | return(ret); | ||
227 | } | 226 | } |
227 | return (ret); | ||
228 | } | ||
228 | 229 | ||
229 | static int fd_puts(BIO *bp, const char *str) | 230 | static int |
230 | { | 231 | fd_puts(BIO *bp, const char *str) |
231 | int n,ret; | 232 | { |
233 | int n, ret; | ||
232 | 234 | ||
233 | n=strlen(str); | 235 | n = strlen(str); |
234 | ret=fd_write(bp,str,n); | 236 | ret = fd_write(bp, str, n); |
235 | return(ret); | 237 | return (ret); |
236 | } | 238 | } |
237 | 239 | ||
238 | static int fd_gets(BIO *bp, char *buf, int size) | 240 | static int |
239 | { | 241 | fd_gets(BIO *bp, char *buf, int size) |
240 | int ret=0; | 242 | { |
241 | char *ptr=buf; | 243 | int ret = 0; |
242 | char *end=buf+size-1; | 244 | char *ptr = buf; |
245 | char *end = buf + size - 1; | ||
243 | 246 | ||
244 | while ( (ptr < end) && (fd_read(bp, ptr, 1) > 0) && (ptr[0] != '\n') ) | 247 | while ((ptr < end) && (fd_read(bp, ptr, 1) > 0) && (ptr[0] != '\n')) |
245 | ptr++; | 248 | ptr++; |
246 | 249 | ||
247 | ptr[0]='\0'; | 250 | ptr[0] = '\0'; |
248 | 251 | ||
249 | if (buf[0] != '\0') | 252 | if (buf[0] != '\0') |
250 | ret=strlen(buf); | 253 | ret = strlen(buf); |
251 | return(ret); | 254 | return (ret); |
252 | } | 255 | } |
253 | 256 | ||
254 | int BIO_fd_should_retry(int i) | 257 | int |
255 | { | 258 | BIO_fd_should_retry(int i) |
259 | { | ||
256 | int err; | 260 | int err; |
257 | 261 | ||
258 | if ((i == 0) || (i == -1)) | 262 | if ((i == 0) || (i == -1)) { |
259 | { | 263 | err = errno; |
260 | err=errno; | ||
261 | 264 | ||
262 | #if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */ | 265 | #if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */ |
263 | if ((i == -1) && (err == 0)) | 266 | if ((i == -1) && (err == 0)) |
264 | return(1); | 267 | return (1); |
265 | #endif | 268 | #endif |
266 | 269 | ||
267 | return(BIO_fd_non_fatal_error(err)); | 270 | return (BIO_fd_non_fatal_error(err)); |
268 | } | ||
269 | return(0); | ||
270 | } | 271 | } |
272 | return (0); | ||
273 | } | ||
271 | 274 | ||
272 | int BIO_fd_non_fatal_error(int err) | 275 | int |
273 | { | 276 | BIO_fd_non_fatal_error(int err) |
274 | switch (err) | 277 | { |
275 | { | 278 | switch (err) { |
276 | 279 | ||
277 | #ifdef EWOULDBLOCK | 280 | #ifdef EWOULDBLOCK |
278 | # ifdef WSAEWOULDBLOCK | 281 | # ifdef WSAEWOULDBLOCK |
@@ -309,11 +312,11 @@ int BIO_fd_non_fatal_error(int err) | |||
309 | #ifdef EALREADY | 312 | #ifdef EALREADY |
310 | case EALREADY: | 313 | case EALREADY: |
311 | #endif | 314 | #endif |
312 | return(1); | 315 | return (1); |
313 | /* break; */ | 316 | /* break; */ |
314 | default: | 317 | default: |
315 | break; | 318 | break; |
316 | } | ||
317 | return(0); | ||
318 | } | 319 | } |
320 | return (0); | ||
321 | } | ||
319 | #endif | 322 | #endif |
diff --git a/src/lib/libssl/src/crypto/bio/bss_file.c b/src/lib/libssl/src/crypto/bio/bss_file.c index 638572ab7f..794f503a69 100644 --- a/src/lib/libssl/src/crypto/bio/bss_file.c +++ b/src/lib/libssl/src/crypto/bio/bss_file.c | |||
@@ -102,8 +102,8 @@ static int file_gets(BIO *h, char *str, int size); | |||
102 | static long file_ctrl(BIO *h, int cmd, long arg1, void *arg2); | 102 | static long file_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
103 | static int file_new(BIO *h); | 103 | static int file_new(BIO *h); |
104 | static int file_free(BIO *data); | 104 | static int file_free(BIO *data); |
105 | static BIO_METHOD methods_filep= | 105 | |
106 | { | 106 | static BIO_METHOD methods_filep = { |
107 | BIO_TYPE_FILE, | 107 | BIO_TYPE_FILE, |
108 | "FILE pointer", | 108 | "FILE pointer", |
109 | file_write, | 109 | file_write, |
@@ -114,15 +114,16 @@ static BIO_METHOD methods_filep= | |||
114 | file_new, | 114 | file_new, |
115 | file_free, | 115 | file_free, |
116 | NULL, | 116 | NULL, |
117 | }; | 117 | }; |
118 | 118 | ||
119 | BIO *BIO_new_file(const char *filename, const char *mode) | 119 | BIO |
120 | { | 120 | *BIO_new_file(const char *filename, const char *mode) |
121 | { | ||
121 | BIO *ret; | 122 | BIO *ret; |
122 | FILE *file=NULL; | 123 | FILE *file = NULL; |
123 | 124 | ||
124 | #if defined(_WIN32) && defined(CP_UTF8) | 125 | #if defined(_WIN32) && defined(CP_UTF8) |
125 | int sz, len_0 = (int)strlen(filename)+1; | 126 | int sz, len_0 = (int)strlen(filename) + 1; |
126 | DWORD flags; | 127 | DWORD flags; |
127 | 128 | ||
128 | /* | 129 | /* |
@@ -137,173 +138,171 @@ BIO *BIO_new_file(const char *filename, const char *mode) | |||
137 | * ERROR_NO_UNICODE_TRANSLATION, in which case we fall | 138 | * ERROR_NO_UNICODE_TRANSLATION, in which case we fall |
138 | * back to fopen... | 139 | * back to fopen... |
139 | */ | 140 | */ |
140 | if ((sz=MultiByteToWideChar(CP_UTF8,(flags=MB_ERR_INVALID_CHARS), | 141 | if ((sz = MultiByteToWideChar(CP_UTF8,(flags = MB_ERR_INVALID_CHARS), |
141 | filename,len_0,NULL,0))>0 || | 142 | filename, len_0, NULL, 0)) > 0 || |
142 | (GetLastError()==ERROR_INVALID_FLAGS && | 143 | (GetLastError() == ERROR_INVALID_FLAGS && |
143 | (sz=MultiByteToWideChar(CP_UTF8,(flags=0), | 144 | (sz = MultiByteToWideChar(CP_UTF8,(flags = 0), |
144 | filename,len_0,NULL,0))>0) | 145 | filename, len_0, NULL, 0)) > 0)) { |
145 | ) | ||
146 | { | ||
147 | WCHAR wmode[8]; | 146 | WCHAR wmode[8]; |
148 | WCHAR *wfilename = _alloca(sz*sizeof(WCHAR)); | 147 | WCHAR *wfilename = _alloca(sz*sizeof(WCHAR)); |
149 | 148 | ||
150 | if (MultiByteToWideChar(CP_UTF8,flags, | 149 | if (MultiByteToWideChar(CP_UTF8, flags, filename, len_0, |
151 | filename,len_0,wfilename,sz) && | 150 | wfilename, sz) && MultiByteToWideChar(CP_UTF8, 0, mode, |
152 | MultiByteToWideChar(CP_UTF8,0,mode,strlen(mode)+1, | 151 | strlen(mode) + 1, wmode, |
153 | wmode,sizeof(wmode)/sizeof(wmode[0])) && | 152 | sizeof(wmode) / sizeof(wmode[0])) && |
154 | (file=_wfopen(wfilename,wmode))==NULL && | 153 | (file = _wfopen(wfilename, wmode)) == NULL && |
155 | (errno==ENOENT || errno==EBADF) | 154 | (errno == ENOENT || errno == EBADF) |
156 | ) /* UTF-8 decode succeeded, but no file, filename | 155 | ) /* UTF - 8 decode succeeded, but no file, filename |
157 | * could still have been locale-ized... */ | 156 | * could still have been locale-ized... */ |
158 | file = fopen(filename,mode); | 157 | file = fopen(filename, mode); |
159 | } | 158 | } else if (GetLastError() == ERROR_NO_UNICODE_TRANSLATION) { |
160 | else if (GetLastError()==ERROR_NO_UNICODE_TRANSLATION) | 159 | file = fopen(filename, mode); |
161 | { | 160 | } |
162 | file = fopen(filename,mode); | ||
163 | } | ||
164 | #else | 161 | #else |
165 | file=fopen(filename,mode); | 162 | file = fopen(filename, mode); |
163 | |||
166 | #endif | 164 | #endif |
167 | if (file == NULL) | 165 | if (file == NULL) { |
168 | { | ||
169 | SYSerr(SYS_F_FOPEN, errno); | 166 | SYSerr(SYS_F_FOPEN, errno); |
170 | ERR_add_error_data(5,"fopen('",filename,"','",mode,"')"); | 167 | ERR_add_error_data(5, "fopen('", filename, "', '", mode, "')"); |
171 | if (errno == ENOENT) | 168 | if (errno == ENOENT) |
172 | BIOerr(BIO_F_BIO_NEW_FILE,BIO_R_NO_SUCH_FILE); | 169 | BIOerr(BIO_F_BIO_NEW_FILE, BIO_R_NO_SUCH_FILE); |
173 | else | 170 | else |
174 | BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB); | 171 | BIOerr(BIO_F_BIO_NEW_FILE, ERR_R_SYS_LIB); |
175 | return(NULL); | 172 | return (NULL); |
176 | } | 173 | } |
177 | if ((ret=BIO_new(BIO_s_file())) == NULL) | 174 | if ((ret = BIO_new(BIO_s_file())) == NULL) { |
178 | { | ||
179 | fclose(file); | 175 | fclose(file); |
180 | return(NULL); | 176 | return (NULL); |
181 | } | ||
182 | |||
183 | BIO_clear_flags(ret,BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */ | ||
184 | BIO_set_fp(ret,file,BIO_CLOSE); | ||
185 | return(ret); | ||
186 | } | 177 | } |
187 | 178 | ||
188 | BIO *BIO_new_fp(FILE *stream, int close_flag) | 179 | BIO_clear_flags(ret, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */ |
189 | { | 180 | BIO_set_fp(ret, file, BIO_CLOSE); |
190 | BIO *ret; | 181 | return (ret); |
191 | 182 | } | |
192 | if ((ret=BIO_new(BIO_s_file())) == NULL) | ||
193 | return(NULL); | ||
194 | |||
195 | BIO_set_flags(ret,BIO_FLAGS_UPLINK); /* redundant, left for documentation puposes */ | ||
196 | BIO_set_fp(ret,stream,close_flag); | ||
197 | return(ret); | ||
198 | } | ||
199 | 183 | ||
200 | BIO_METHOD *BIO_s_file(void) | 184 | BIO |
201 | { | 185 | *BIO_new_fp(FILE *stream, int close_flag) |
202 | return(&methods_filep); | 186 | { |
203 | } | 187 | BIO *ret; |
204 | 188 | ||
205 | static int file_new(BIO *bi) | 189 | if ((ret = BIO_new(BIO_s_file())) == NULL) |
206 | { | 190 | return (NULL); |
207 | bi->init=0; | 191 | |
208 | bi->num=0; | 192 | BIO_set_flags(ret, BIO_FLAGS_UPLINK); /* redundant, left for documentation puposes */ |
209 | bi->ptr=NULL; | 193 | BIO_set_fp(ret, stream, close_flag); |
194 | return (ret); | ||
195 | } | ||
196 | |||
197 | BIO_METHOD | ||
198 | *BIO_s_file(void) | ||
199 | { | ||
200 | return (&methods_filep); | ||
201 | } | ||
202 | |||
203 | static int | ||
204 | file_new(BIO *bi) | ||
205 | { | ||
206 | bi->init = 0; | ||
207 | bi->num = 0; | ||
208 | bi->ptr = NULL; | ||
210 | bi->flags=BIO_FLAGS_UPLINK; /* default to UPLINK */ | 209 | bi->flags=BIO_FLAGS_UPLINK; /* default to UPLINK */ |
211 | return(1); | 210 | return (1); |
212 | } | 211 | } |
213 | 212 | ||
214 | static int file_free(BIO *a) | 213 | static int |
215 | { | 214 | file_free(BIO *a) |
216 | if (a == NULL) return(0); | 215 | { |
217 | if (a->shutdown) | 216 | if (a == NULL) |
218 | { | 217 | return (0); |
219 | if ((a->init) && (a->ptr != NULL)) | 218 | if (a->shutdown) { |
220 | { | 219 | if ((a->init) && (a->ptr != NULL)) { |
221 | if (a->flags&BIO_FLAGS_UPLINK) | 220 | if (a->flags&BIO_FLAGS_UPLINK) |
222 | UP_fclose (a->ptr); | 221 | UP_fclose (a->ptr); |
223 | else | 222 | else |
224 | fclose (a->ptr); | 223 | fclose (a->ptr); |
225 | a->ptr=NULL; | 224 | a->ptr = NULL; |
226 | a->flags=BIO_FLAGS_UPLINK; | 225 | a->flags = BIO_FLAGS_UPLINK; |
227 | } | ||
228 | a->init=0; | ||
229 | } | 226 | } |
230 | return(1); | 227 | a->init = 0; |
231 | } | 228 | } |
232 | 229 | return (1); | |
233 | static int file_read(BIO *b, char *out, int outl) | 230 | } |
234 | { | ||
235 | int ret=0; | ||
236 | 231 | ||
237 | if (b->init && (out != NULL)) | 232 | static int |
238 | { | 233 | file_read(BIO *b, char *out, int outl) |
234 | { | ||
235 | int ret = 0; | ||
236 | |||
237 | if (b->init && (out != NULL)) { | ||
239 | if (b->flags&BIO_FLAGS_UPLINK) | 238 | if (b->flags&BIO_FLAGS_UPLINK) |
240 | ret=UP_fread(out,1,(int)outl,b->ptr); | 239 | ret = UP_fread(out, 1,(int)outl, b->ptr); |
241 | else | 240 | else |
242 | ret=fread(out,1,(int)outl,(FILE *)b->ptr); | 241 | ret = fread(out, 1,(int)outl,(FILE *)b->ptr); |
243 | if(ret == 0 && (b->flags&BIO_FLAGS_UPLINK)?UP_ferror((FILE *)b->ptr):ferror((FILE *)b->ptr)) | 242 | if (ret == 0 && (b->flags & BIO_FLAGS_UPLINK) ? |
244 | { | 243 | UP_ferror((FILE *)b->ptr) : ferror((FILE *)b->ptr)) { |
245 | SYSerr(SYS_F_FREAD, errno); | 244 | SYSerr(SYS_F_FREAD, errno); |
246 | BIOerr(BIO_F_FILE_READ,ERR_R_SYS_LIB); | 245 | BIOerr(BIO_F_FILE_READ, ERR_R_SYS_LIB); |
247 | ret=-1; | 246 | ret = -1; |
248 | } | ||
249 | } | 247 | } |
250 | return(ret); | ||
251 | } | 248 | } |
249 | return (ret); | ||
250 | } | ||
252 | 251 | ||
253 | static int file_write(BIO *b, const char *in, int inl) | 252 | static int |
254 | { | 253 | file_write(BIO *b, const char *in, int inl) |
255 | int ret=0; | 254 | { |
255 | int ret = 0; | ||
256 | 256 | ||
257 | if (b->init && (in != NULL)) | 257 | if (b->init && (in != NULL)) { |
258 | { | ||
259 | if (b->flags&BIO_FLAGS_UPLINK) | 258 | if (b->flags&BIO_FLAGS_UPLINK) |
260 | ret=UP_fwrite(in,(int)inl,1,b->ptr); | 259 | ret = UP_fwrite(in,(int)inl, 1, b->ptr); |
261 | else | 260 | else |
262 | ret=fwrite(in,(int)inl,1,(FILE *)b->ptr); | 261 | ret = fwrite(in,(int)inl, 1,(FILE *)b->ptr); |
263 | if (ret) | 262 | if (ret) |
264 | ret=inl; | 263 | ret = inl; |
265 | /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */ | 264 | /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */ |
266 | /* according to Tim Hudson <tjh@cryptsoft.com>, the commented | 265 | /* according to Tim Hudson <tjh@cryptsoft.com>, the commented |
267 | * out version above can cause 'inl' write calls under | 266 | * out version above can cause 'inl' write calls under |
268 | * some stupid stdio implementations (VMS) */ | 267 | * some stupid stdio implementations (VMS) */ |
269 | } | ||
270 | return(ret); | ||
271 | } | 268 | } |
272 | 269 | return (ret); | |
273 | static long file_ctrl(BIO *b, int cmd, long num, void *ptr) | 270 | } |
274 | { | 271 | |
275 | long ret=1; | 272 | static long |
276 | FILE *fp=(FILE *)b->ptr; | 273 | file_ctrl(BIO *b, int cmd, long num, void *ptr) |
274 | { | ||
275 | long ret = 1; | ||
276 | FILE *fp = (FILE *)b->ptr; | ||
277 | FILE **fpp; | 277 | FILE **fpp; |
278 | char p[4]; | 278 | char p[4]; |
279 | 279 | ||
280 | switch (cmd) | 280 | switch (cmd) { |
281 | { | ||
282 | case BIO_C_FILE_SEEK: | 281 | case BIO_C_FILE_SEEK: |
283 | case BIO_CTRL_RESET: | 282 | case BIO_CTRL_RESET: |
284 | if (b->flags&BIO_FLAGS_UPLINK) | 283 | if (b->flags&BIO_FLAGS_UPLINK) |
285 | ret=(long)UP_fseek(b->ptr,num,0); | 284 | ret = (long)UP_fseek(b->ptr, num, 0); |
286 | else | 285 | else |
287 | ret=(long)fseek(fp,num,0); | 286 | ret = (long)fseek(fp, num, 0); |
288 | break; | 287 | break; |
289 | case BIO_CTRL_EOF: | 288 | case BIO_CTRL_EOF: |
290 | if (b->flags&BIO_FLAGS_UPLINK) | 289 | if (b->flags&BIO_FLAGS_UPLINK) |
291 | ret=(long)UP_feof(fp); | 290 | ret = (long)UP_feof(fp); |
292 | else | 291 | else |
293 | ret=(long)feof(fp); | 292 | ret = (long)feof(fp); |
294 | break; | 293 | break; |
295 | case BIO_C_FILE_TELL: | 294 | case BIO_C_FILE_TELL: |
296 | case BIO_CTRL_INFO: | 295 | case BIO_CTRL_INFO: |
297 | if (b->flags&BIO_FLAGS_UPLINK) | 296 | if (b->flags&BIO_FLAGS_UPLINK) |
298 | ret=UP_ftell(b->ptr); | 297 | ret = UP_ftell(b->ptr); |
299 | else | 298 | else |
300 | ret=ftell(fp); | 299 | ret = ftell(fp); |
301 | break; | 300 | break; |
302 | case BIO_C_SET_FILE_PTR: | 301 | case BIO_C_SET_FILE_PTR: |
303 | file_free(b); | 302 | file_free(b); |
304 | b->shutdown=(int)num&BIO_CLOSE; | 303 | b->shutdown = (int)num&BIO_CLOSE; |
305 | b->ptr=ptr; | 304 | b->ptr = ptr; |
306 | b->init=1; | 305 | b->init = 1; |
307 | #if BIO_FLAGS_UPLINK!=0 | 306 | #if BIO_FLAGS_UPLINK!=0 |
308 | #if defined(__MINGW32__) && defined(__MSVCRT__) && !defined(_IOB_ENTRIES) | 307 | #if defined(__MINGW32__) && defined(__MSVCRT__) && !defined(_IOB_ENTRIES) |
309 | #define _IOB_ENTRIES 20 | 308 | #define _IOB_ENTRIES 20 |
@@ -311,8 +310,8 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
311 | #if defined(_IOB_ENTRIES) | 310 | #if defined(_IOB_ENTRIES) |
312 | /* Safety net to catch purely internal BIO_set_fp calls */ | 311 | /* Safety net to catch purely internal BIO_set_fp calls */ |
313 | if ((size_t)ptr >= (size_t)stdin && | 312 | if ((size_t)ptr >= (size_t)stdin && |
314 | (size_t)ptr < (size_t)(stdin+_IOB_ENTRIES)) | 313 | (size_t)ptr < (size_t)(stdin + _IOB_ENTRIES)) |
315 | BIO_clear_flags(b,BIO_FLAGS_UPLINK); | 314 | BIO_clear_flags(b, BIO_FLAGS_UPLINK); |
316 | #endif | 315 | #endif |
317 | #endif | 316 | #endif |
318 | #ifdef UP_fsetmod | 317 | #ifdef UP_fsetmod |
@@ -322,102 +321,94 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
322 | #endif | 321 | #endif |
323 | { | 322 | { |
324 | #if defined(OPENSSL_SYS_WINDOWS) | 323 | #if defined(OPENSSL_SYS_WINDOWS) |
325 | int fd = _fileno((FILE*)ptr); | 324 | int fd = _fileno((FILE*)ptr); |
326 | if (num & BIO_FP_TEXT) | 325 | if (num & BIO_FP_TEXT) |
327 | _setmode(fd,_O_TEXT); | 326 | _setmode(fd, _O_TEXT); |
328 | else | 327 | else |
329 | _setmode(fd,_O_BINARY); | 328 | _setmode(fd, _O_BINARY); |
330 | #elif defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB) | 329 | #elif defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB) |
331 | int fd = fileno((FILE*)ptr); | 330 | int fd = fileno((FILE*)ptr); |
332 | /* Under CLib there are differences in file modes */ | 331 | /* Under CLib there are differences in file modes */ |
333 | if (num & BIO_FP_TEXT) | 332 | if (num & BIO_FP_TEXT) |
334 | setmode(fd,O_TEXT); | 333 | setmode(fd, O_TEXT); |
335 | else | ||
336 | setmode(fd,O_BINARY); | ||
337 | #elif defined(OPENSSL_SYS_MSDOS) | ||
338 | int fd = fileno((FILE*)ptr); | ||
339 | /* Set correct text/binary mode */ | ||
340 | if (num & BIO_FP_TEXT) | ||
341 | _setmode(fd,_O_TEXT); | ||
342 | /* Dangerous to set stdin/stdout to raw (unless redirected) */ | ||
343 | else | ||
344 | { | ||
345 | if (fd == STDIN_FILENO || fd == STDOUT_FILENO) | ||
346 | { | ||
347 | if (isatty(fd) <= 0) | ||
348 | _setmode(fd,_O_BINARY); | ||
349 | } | ||
350 | else | 334 | else |
351 | _setmode(fd,_O_BINARY); | 335 | setmode(fd, O_BINARY); |
336 | #elif defined(OPENSSL_SYS_MSDOS) | ||
337 | int fd = fileno((FILE*)ptr); | ||
338 | /* Set correct text/binary mode */ | ||
339 | if (num & BIO_FP_TEXT) | ||
340 | _setmode(fd, _O_TEXT); | ||
341 | /* Dangerous to set stdin/stdout to raw (unless redirected) */ | ||
342 | else { | ||
343 | if (fd == STDIN_FILENO || fd == STDOUT_FILENO) { | ||
344 | if (isatty(fd) <= 0) | ||
345 | _setmode(fd, _O_BINARY); | ||
346 | } else | ||
347 | _setmode(fd, _O_BINARY); | ||
352 | } | 348 | } |
353 | #elif defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN) | 349 | #elif defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN) |
354 | int fd = fileno((FILE*)ptr); | 350 | int fd = fileno((FILE*)ptr); |
355 | if (num & BIO_FP_TEXT) | 351 | if (num & BIO_FP_TEXT) |
356 | setmode(fd, O_TEXT); | 352 | setmode(fd, O_TEXT); |
357 | else | 353 | else |
358 | setmode(fd, O_BINARY); | 354 | setmode(fd, O_BINARY); |
359 | #endif | 355 | #endif |
360 | } | 356 | } |
361 | break; | 357 | break; |
362 | case BIO_C_SET_FILENAME: | 358 | case BIO_C_SET_FILENAME: |
363 | file_free(b); | 359 | file_free(b); |
364 | b->shutdown=(int)num&BIO_CLOSE; | 360 | b->shutdown = (int)num&BIO_CLOSE; |
365 | if (num & BIO_FP_APPEND) | 361 | if (num & BIO_FP_APPEND) { |
366 | { | ||
367 | if (num & BIO_FP_READ) | 362 | if (num & BIO_FP_READ) |
368 | BUF_strlcpy(p,"a+",sizeof p); | 363 | BUF_strlcpy(p, "a+", sizeof p); |
369 | else BUF_strlcpy(p,"a",sizeof p); | 364 | else BUF_strlcpy(p, "a", sizeof p); |
370 | } | 365 | } else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE)) |
371 | else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE)) | 366 | BUF_strlcpy(p, "r+", sizeof p); |
372 | BUF_strlcpy(p,"r+",sizeof p); | ||
373 | else if (num & BIO_FP_WRITE) | 367 | else if (num & BIO_FP_WRITE) |
374 | BUF_strlcpy(p,"w",sizeof p); | 368 | BUF_strlcpy(p, "w", sizeof p); |
375 | else if (num & BIO_FP_READ) | 369 | else if (num & BIO_FP_READ) |
376 | BUF_strlcpy(p,"r",sizeof p); | 370 | BUF_strlcpy(p, "r", sizeof p); |
377 | else | 371 | else { |
378 | { | 372 | BIOerr(BIO_F_FILE_CTRL, BIO_R_BAD_FOPEN_MODE); |
379 | BIOerr(BIO_F_FILE_CTRL,BIO_R_BAD_FOPEN_MODE); | 373 | ret = 0; |
380 | ret=0; | ||
381 | break; | 374 | break; |
382 | } | 375 | } |
383 | #if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN) | 376 | #if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN) |
384 | if (!(num & BIO_FP_TEXT)) | 377 | if (!(num & BIO_FP_TEXT)) |
385 | strcat(p,"b"); | 378 | strcat(p, "b"); |
386 | else | 379 | else |
387 | strcat(p,"t"); | 380 | strcat(p, "t"); |
388 | #endif | 381 | #endif |
389 | #if defined(OPENSSL_SYS_NETWARE) | 382 | #if defined(OPENSSL_SYS_NETWARE) |
390 | if (!(num & BIO_FP_TEXT)) | 383 | if (!(num & BIO_FP_TEXT)) |
391 | strcat(p,"b"); | 384 | strcat(p, "b"); |
392 | else | 385 | else |
393 | strcat(p,"t"); | 386 | strcat(p, "t"); |
394 | #endif | 387 | #endif |
395 | fp=fopen(ptr,p); | 388 | fp = fopen(ptr, p); |
396 | if (fp == NULL) | 389 | if (fp == NULL) { |
397 | { | ||
398 | SYSerr(SYS_F_FOPEN, errno); | 390 | SYSerr(SYS_F_FOPEN, errno); |
399 | ERR_add_error_data(5,"fopen('",ptr,"','",p,"')"); | 391 | ERR_add_error_data(5, "fopen('", ptr, "', '", p, "')"); |
400 | BIOerr(BIO_F_FILE_CTRL,ERR_R_SYS_LIB); | 392 | BIOerr(BIO_F_FILE_CTRL, ERR_R_SYS_LIB); |
401 | ret=0; | 393 | ret = 0; |
402 | break; | 394 | break; |
403 | } | 395 | } |
404 | b->ptr=fp; | 396 | b->ptr = fp; |
405 | b->init=1; | 397 | b->init = 1; |
406 | BIO_clear_flags(b,BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */ | 398 | BIO_clear_flags(b, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */ |
407 | break; | 399 | break; |
408 | case BIO_C_GET_FILE_PTR: | 400 | case BIO_C_GET_FILE_PTR: |
409 | /* the ptr parameter is actually a FILE ** in this case. */ | 401 | /* the ptr parameter is actually a FILE ** in this case. */ |
410 | if (ptr != NULL) | 402 | if (ptr != NULL) { |
411 | { | 403 | fpp = (FILE **)ptr; |
412 | fpp=(FILE **)ptr; | 404 | *fpp = (FILE *)b->ptr; |
413 | *fpp=(FILE *)b->ptr; | 405 | } |
414 | } | ||
415 | break; | 406 | break; |
416 | case BIO_CTRL_GET_CLOSE: | 407 | case BIO_CTRL_GET_CLOSE: |
417 | ret=(long)b->shutdown; | 408 | ret = (long)b->shutdown; |
418 | break; | 409 | break; |
419 | case BIO_CTRL_SET_CLOSE: | 410 | case BIO_CTRL_SET_CLOSE: |
420 | b->shutdown=(int)num; | 411 | b->shutdown = (int)num; |
421 | break; | 412 | break; |
422 | case BIO_CTRL_FLUSH: | 413 | case BIO_CTRL_FLUSH: |
423 | if (b->flags&BIO_FLAGS_UPLINK) | 414 | if (b->flags&BIO_FLAGS_UPLINK) |
@@ -426,7 +417,7 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
426 | fflush((FILE *)b->ptr); | 417 | fflush((FILE *)b->ptr); |
427 | break; | 418 | break; |
428 | case BIO_CTRL_DUP: | 419 | case BIO_CTRL_DUP: |
429 | ret=1; | 420 | ret = 1; |
430 | break; | 421 | break; |
431 | 422 | ||
432 | case BIO_CTRL_WPENDING: | 423 | case BIO_CTRL_WPENDING: |
@@ -434,44 +425,41 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
434 | case BIO_CTRL_PUSH: | 425 | case BIO_CTRL_PUSH: |
435 | case BIO_CTRL_POP: | 426 | case BIO_CTRL_POP: |
436 | default: | 427 | default: |
437 | ret=0; | 428 | ret = 0; |
438 | break; | 429 | break; |
439 | } | ||
440 | return(ret); | ||
441 | } | 430 | } |
431 | return (ret); | ||
432 | } | ||
442 | 433 | ||
443 | static int file_gets(BIO *bp, char *buf, int size) | 434 | static int |
444 | { | 435 | file_gets(BIO *bp, char *buf, int size) |
445 | int ret=0; | 436 | { |
437 | int ret = 0; | ||
446 | 438 | ||
447 | buf[0]='\0'; | 439 | buf[0] = '\0'; |
448 | if (bp->flags&BIO_FLAGS_UPLINK) | 440 | if (bp->flags&BIO_FLAGS_UPLINK) { |
449 | { | 441 | if (!UP_fgets(buf, size, bp->ptr)) |
450 | if (!UP_fgets(buf,size,bp->ptr)) | ||
451 | goto err; | 442 | goto err; |
452 | } | 443 | } else { |
453 | else | 444 | if (!fgets(buf, size,(FILE *)bp->ptr)) |
454 | { | ||
455 | if (!fgets(buf,size,(FILE *)bp->ptr)) | ||
456 | goto err; | 445 | goto err; |
457 | } | ||
458 | if (buf[0] != '\0') | ||
459 | ret=strlen(buf); | ||
460 | err: | ||
461 | return(ret); | ||
462 | } | 446 | } |
447 | if (buf[0] != '\0') | ||
448 | ret = strlen(buf); | ||
449 | err: | ||
450 | return (ret); | ||
451 | } | ||
463 | 452 | ||
464 | static int file_puts(BIO *bp, const char *str) | 453 | static int |
465 | { | 454 | file_puts(BIO *bp, const char *str) |
466 | int n,ret; | 455 | { |
456 | int n, ret; | ||
467 | 457 | ||
468 | n=strlen(str); | 458 | n = strlen(str); |
469 | ret=file_write(bp,str,n); | 459 | ret = file_write(bp, str, n); |
470 | return(ret); | 460 | return (ret); |
471 | } | 461 | } |
472 | 462 | ||
473 | #endif /* OPENSSL_NO_STDIO */ | 463 | #endif /* OPENSSL_NO_STDIO */ |
474 | 464 | ||
475 | #endif /* HEADER_BSS_FILE_C */ | 465 | #endif /* HEADER_BSS_FILE_C */ |
476 | |||
477 | |||
diff --git a/src/lib/libssl/src/crypto/bio/bss_log.c b/src/lib/libssl/src/crypto/bio/bss_log.c index 1cc413a916..9225af4df2 100644 --- a/src/lib/libssl/src/crypto/bio/bss_log.c +++ b/src/lib/libssl/src/crypto/bio/bss_log.c | |||
@@ -80,7 +80,7 @@ | |||
80 | # if __INITIAL_POINTER_SIZE == 64 | 80 | # if __INITIAL_POINTER_SIZE == 64 |
81 | # pragma pointer_size save | 81 | # pragma pointer_size save |
82 | # pragma pointer_size 32 | 82 | # pragma pointer_size 32 |
83 | void * _malloc32 (__size_t); | 83 | void * _malloc32 (__size_t); |
84 | # pragma pointer_size restore | 84 | # pragma pointer_size restore |
85 | # endif /* __INITIAL_POINTER_SIZE == 64 */ | 85 | # endif /* __INITIAL_POINTER_SIZE == 64 */ |
86 | # endif /* __INITIAL_POINTER_SIZE && defined _ANSI_C_SOURCE */ | 86 | # endif /* __INITIAL_POINTER_SIZE && defined _ANSI_C_SOURCE */ |
@@ -131,9 +131,8 @@ static void xopenlog(BIO* bp, char* name, int level); | |||
131 | static void xsyslog(BIO* bp, int priority, const char* string); | 131 | static void xsyslog(BIO* bp, int priority, const char* string); |
132 | static void xcloselog(BIO* bp); | 132 | static void xcloselog(BIO* bp); |
133 | 133 | ||
134 | static BIO_METHOD methods_slg= | 134 | static BIO_METHOD methods_slg = { |
135 | { | 135 | BIO_TYPE_MEM, "syslog", |
136 | BIO_TYPE_MEM,"syslog", | ||
137 | slg_write, | 136 | slg_write, |
138 | NULL, | 137 | NULL, |
139 | slg_puts, | 138 | slg_puts, |
@@ -142,43 +141,46 @@ static BIO_METHOD methods_slg= | |||
142 | slg_new, | 141 | slg_new, |
143 | slg_free, | 142 | slg_free, |
144 | NULL, | 143 | NULL, |
145 | }; | 144 | }; |
146 | 145 | ||
147 | BIO_METHOD *BIO_s_log(void) | 146 | BIO_METHOD |
148 | { | 147 | *BIO_s_log(void) |
149 | return(&methods_slg); | 148 | { |
150 | } | 149 | return (&methods_slg); |
150 | } | ||
151 | 151 | ||
152 | static int slg_new(BIO *bi) | 152 | static int |
153 | { | 153 | slg_new(BIO *bi) |
154 | bi->init=1; | 154 | { |
155 | bi->num=0; | 155 | bi->init = 1; |
156 | bi->ptr=NULL; | 156 | bi->num = 0; |
157 | bi->ptr = NULL; | ||
157 | xopenlog(bi, "application", LOG_DAEMON); | 158 | xopenlog(bi, "application", LOG_DAEMON); |
158 | return(1); | 159 | return (1); |
159 | } | 160 | } |
160 | 161 | ||
161 | static int slg_free(BIO *a) | 162 | static int |
162 | { | 163 | slg_free(BIO *a) |
163 | if (a == NULL) return(0); | 164 | { |
165 | if (a == NULL) | ||
166 | return (0); | ||
164 | xcloselog(a); | 167 | xcloselog(a); |
165 | return(1); | 168 | return (1); |
166 | } | 169 | } |
167 | 170 | ||
168 | static int slg_write(BIO *b, const char *in, int inl) | 171 | static int |
169 | { | 172 | slg_write(BIO *b, const char *in, int inl) |
170 | int ret= inl; | 173 | { |
174 | int ret = inl; | ||
171 | char* buf; | 175 | char* buf; |
172 | char* pp; | 176 | char* pp; |
173 | int priority, i; | 177 | int priority, i; |
174 | static const struct | 178 | static const struct { |
175 | { | ||
176 | int strl; | 179 | int strl; |
177 | char str[10]; | 180 | char str[10]; |
178 | int log_level; | 181 | int log_level; |
179 | } | 182 | } |
180 | mapping[] = | 183 | mapping[] = { |
181 | { | ||
182 | { 6, "PANIC ", LOG_EMERG }, | 184 | { 6, "PANIC ", LOG_EMERG }, |
183 | { 6, "EMERG ", LOG_EMERG }, | 185 | { 6, "EMERG ", LOG_EMERG }, |
184 | { 4, "EMR ", LOG_EMERG }, | 186 | { 4, "EMR ", LOG_EMERG }, |
@@ -199,69 +201,72 @@ static int slg_write(BIO *b, const char *in, int inl) | |||
199 | { 6, "DEBUG ", LOG_DEBUG }, | 201 | { 6, "DEBUG ", LOG_DEBUG }, |
200 | { 4, "DBG ", LOG_DEBUG }, | 202 | { 4, "DBG ", LOG_DEBUG }, |
201 | { 0, "", LOG_ERR } /* The default */ | 203 | { 0, "", LOG_ERR } /* The default */ |
202 | }; | 204 | }; |
203 | 205 | ||
204 | if((buf= (char *)OPENSSL_malloc(inl+ 1)) == NULL){ | 206 | if ((buf = (char *)OPENSSL_malloc(inl + 1)) == NULL) { |
205 | return(0); | 207 | return (0); |
206 | } | 208 | } |
207 | strncpy(buf, in, inl); | 209 | strncpy(buf, in, inl); |
208 | buf[inl]= '\0'; | 210 | buf[inl] = '\0'; |
209 | 211 | ||
210 | i = 0; | 212 | i = 0; |
211 | while(strncmp(buf, mapping[i].str, mapping[i].strl) != 0) i++; | 213 | while (strncmp(buf, mapping[i].str, mapping[i].strl) != 0) |
214 | i++; | ||
212 | priority = mapping[i].log_level; | 215 | priority = mapping[i].log_level; |
213 | pp = buf + mapping[i].strl; | 216 | pp = buf + mapping[i].strl; |
214 | 217 | ||
215 | xsyslog(b, priority, pp); | 218 | xsyslog(b, priority, pp); |
216 | 219 | ||
217 | OPENSSL_free(buf); | 220 | OPENSSL_free(buf); |
218 | return(ret); | 221 | return (ret); |
219 | } | 222 | } |
220 | 223 | ||
221 | static long slg_ctrl(BIO *b, int cmd, long num, void *ptr) | 224 | static long |
222 | { | 225 | slg_ctrl(BIO *b, int cmd, long num, void *ptr) |
223 | switch (cmd) | 226 | { |
224 | { | 227 | switch (cmd) { |
225 | case BIO_CTRL_SET: | 228 | case BIO_CTRL_SET: |
226 | xcloselog(b); | 229 | xcloselog(b); |
227 | xopenlog(b, ptr, num); | 230 | xopenlog(b, ptr, num); |
228 | break; | 231 | break; |
229 | default: | 232 | default: |
230 | break; | 233 | break; |
231 | } | ||
232 | return(0); | ||
233 | } | 234 | } |
235 | return (0); | ||
236 | } | ||
234 | 237 | ||
235 | static int slg_puts(BIO *bp, const char *str) | 238 | static int |
236 | { | 239 | slg_puts(BIO *bp, const char *str) |
237 | int n,ret; | 240 | { |
241 | int n, ret; | ||
238 | 242 | ||
239 | n=strlen(str); | 243 | n = strlen(str); |
240 | ret=slg_write(bp,str,n); | 244 | ret = slg_write(bp, str, n); |
241 | return(ret); | 245 | return (ret); |
242 | } | 246 | } |
243 | 247 | ||
244 | #if defined(OPENSSL_SYS_WIN32) | 248 | #if defined(OPENSSL_SYS_WIN32) |
245 | 249 | ||
246 | static void xopenlog(BIO* bp, char* name, int level) | 250 | static void |
251 | xopenlog(BIO* bp, char* name, int level) | ||
247 | { | 252 | { |
248 | if (check_winnt()) | 253 | if (check_winnt()) |
249 | bp->ptr = RegisterEventSourceA(NULL,name); | 254 | bp->ptr = RegisterEventSourceA(NULL, name); |
250 | else | 255 | else |
251 | bp->ptr = NULL; | 256 | bp->ptr = NULL; |
252 | } | 257 | } |
253 | 258 | ||
254 | static void xsyslog(BIO *bp, int priority, const char *string) | 259 | static void |
260 | xsyslog(BIO *bp, int priority, const char *string) | ||
255 | { | 261 | { |
256 | LPCSTR lpszStrings[2]; | 262 | LPCSTR lpszStrings[2]; |
257 | WORD evtype= EVENTLOG_ERROR_TYPE; | 263 | WORD evtype = EVENTLOG_ERROR_TYPE; |
258 | char pidbuf[DECIMAL_SIZE(DWORD)+4]; | 264 | char pidbuf[DECIMAL_SIZE(DWORD) + 4]; |
259 | 265 | ||
260 | if (bp->ptr == NULL) | 266 | if (bp->ptr == NULL) |
261 | return; | 267 | return; |
262 | 268 | ||
263 | switch (priority) | 269 | switch (priority) { |
264 | { | ||
265 | case LOG_EMERG: | 270 | case LOG_EMERG: |
266 | case LOG_ALERT: | 271 | case LOG_ALERT: |
267 | case LOG_CRIT: | 272 | case LOG_CRIT: |
@@ -280,33 +285,37 @@ static void xsyslog(BIO *bp, int priority, const char *string) | |||
280 | as error anyway. */ | 285 | as error anyway. */ |
281 | evtype = EVENTLOG_ERROR_TYPE; | 286 | evtype = EVENTLOG_ERROR_TYPE; |
282 | break; | 287 | break; |
283 | } | 288 | } |
284 | 289 | ||
285 | sprintf(pidbuf, "[%u] ", GetCurrentProcessId()); | 290 | sprintf(pidbuf, "[%u] ", GetCurrentProcessId()); |
286 | lpszStrings[0] = pidbuf; | 291 | lpszStrings[0] = pidbuf; |
287 | lpszStrings[1] = string; | 292 | lpszStrings[1] = string; |
288 | 293 | ||
289 | ReportEventA(bp->ptr, evtype, 0, 1024, NULL, 2, 0, | 294 | ReportEventA(bp->ptr, evtype, 0, 1024, NULL, 2, 0, |
290 | lpszStrings, NULL); | 295 | lpszStrings, NULL); |
291 | } | 296 | } |
292 | 297 | ||
293 | static void xcloselog(BIO* bp) | 298 | static void |
299 | xcloselog(BIO* bp) | ||
294 | { | 300 | { |
295 | if(bp->ptr) | 301 | if (bp->ptr) |
296 | DeregisterEventSource((HANDLE)(bp->ptr)); | 302 | DeregisterEventSource((HANDLE)(bp->ptr)); |
297 | bp->ptr= NULL; | 303 | bp->ptr = NULL; |
298 | } | 304 | } |
299 | 305 | ||
300 | #elif defined(OPENSSL_SYS_VMS) | 306 | #elif defined(OPENSSL_SYS_VMS) |
301 | 307 | ||
302 | static int VMS_OPC_target = LOG_DAEMON; | 308 | static int VMS_OPC_target = LOG_DAEMON; |
303 | 309 | ||
304 | static void xopenlog(BIO* bp, char* name, int level) | 310 | static void |
311 | xopenlog(BIO* bp, char* name, int level) | ||
305 | { | 312 | { |
306 | VMS_OPC_target = level; | 313 | VMS_OPC_target = level; |
314 | |||
307 | } | 315 | } |
308 | 316 | ||
309 | static void xsyslog(BIO *bp, int priority, const char *string) | 317 | static void |
318 | xsyslog(BIO *bp, int priority, const char *string) | ||
310 | { | 319 | { |
311 | struct dsc$descriptor_s opc_dsc; | 320 | struct dsc$descriptor_s opc_dsc; |
312 | 321 | ||
@@ -329,21 +338,28 @@ static void xsyslog(BIO *bp, int priority, const char *string) | |||
329 | 338 | ||
330 | char buf[10240]; | 339 | char buf[10240]; |
331 | unsigned int len; | 340 | unsigned int len; |
332 | struct dsc$descriptor_s buf_dsc; | 341 | struct dsc$descriptor_s buf_dsc; |
333 | $DESCRIPTOR(fao_cmd, "!AZ: !AZ"); | 342 | $DESCRIPTOR(fao_cmd, "!AZ: !AZ"); |
334 | char *priority_tag; | 343 | char *priority_tag; |
335 | 344 | ||
336 | switch (priority) | 345 | switch (priority) { |
337 | { | 346 | case LOG_EMERG: |
338 | case LOG_EMERG: priority_tag = "Emergency"; break; | 347 | priority_tag = "Emergency"; break; |
339 | case LOG_ALERT: priority_tag = "Alert"; break; | 348 | case LOG_ALERT: |
340 | case LOG_CRIT: priority_tag = "Critical"; break; | 349 | priority_tag = "Alert"; break; |
341 | case LOG_ERR: priority_tag = "Error"; break; | 350 | case LOG_CRIT: |
342 | case LOG_WARNING: priority_tag = "Warning"; break; | 351 | priority_tag = "Critical"; break; |
343 | case LOG_NOTICE: priority_tag = "Notice"; break; | 352 | case LOG_ERR: |
344 | case LOG_INFO: priority_tag = "Info"; break; | 353 | priority_tag = "Error"; break; |
345 | case LOG_DEBUG: priority_tag = "DEBUG"; break; | 354 | case LOG_WARNING: |
346 | } | 355 | priority_tag = "Warning"; break; |
356 | case LOG_NOTICE: | ||
357 | priority_tag = "Notice"; break; | ||
358 | case LOG_INFO: | ||
359 | priority_tag = "Info"; break; | ||
360 | case LOG_DEBUG: | ||
361 | priority_tag = "DEBUG"; break; | ||
362 | } | ||
347 | 363 | ||
348 | buf_dsc.dsc$b_dtype = DSC$K_DTYPE_T; | 364 | buf_dsc.dsc$b_dtype = DSC$K_DTYPE_T; |
349 | buf_dsc.dsc$b_class = DSC$K_CLASS_S; | 365 | buf_dsc.dsc$b_class = DSC$K_CLASS_S; |
@@ -353,7 +369,7 @@ static void xsyslog(BIO *bp, int priority, const char *string) | |||
353 | lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string); | 369 | lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string); |
354 | 370 | ||
355 | /* We know there's an 8-byte header. That's documented. */ | 371 | /* We know there's an 8-byte header. That's documented. */ |
356 | opcdef_p = OPCDEF_MALLOC( 8+ len); | 372 | opcdef_p = OPCDEF_MALLOC( 8 + len); |
357 | opcdef_p->opc$b_ms_type = OPC$_RQ_RQST; | 373 | opcdef_p->opc$b_ms_type = OPC$_RQ_RQST; |
358 | memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3); | 374 | memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3); |
359 | opcdef_p->opc$l_ms_rqstid = 0; | 375 | opcdef_p->opc$l_ms_rqstid = 0; |
@@ -369,13 +385,15 @@ static void xsyslog(BIO *bp, int priority, const char *string) | |||
369 | OPENSSL_free(opcdef_p); | 385 | OPENSSL_free(opcdef_p); |
370 | } | 386 | } |
371 | 387 | ||
372 | static void xcloselog(BIO* bp) | 388 | static void |
389 | xcloselog(BIO* bp) | ||
373 | { | 390 | { |
374 | } | 391 | } |
375 | 392 | ||
376 | #else /* Unix/Watt32 */ | 393 | #else /* Unix/Watt32 */ |
377 | 394 | ||
378 | static void xopenlog(BIO* bp, char* name, int level) | 395 | static void |
396 | xopenlog(BIO* bp, char* name, int level) | ||
379 | { | 397 | { |
380 | #ifdef WATT32 /* djgpp/DOS */ | 398 | #ifdef WATT32 /* djgpp/DOS */ |
381 | openlog(name, LOG_PID|LOG_CONS|LOG_NDELAY, level); | 399 | openlog(name, LOG_PID|LOG_CONS|LOG_NDELAY, level); |
@@ -384,12 +402,14 @@ static void xopenlog(BIO* bp, char* name, int level) | |||
384 | #endif | 402 | #endif |
385 | } | 403 | } |
386 | 404 | ||
387 | static void xsyslog(BIO *bp, int priority, const char *string) | 405 | static void |
406 | xsyslog(BIO *bp, int priority, const char *string) | ||
388 | { | 407 | { |
389 | syslog(priority, "%s", string); | 408 | syslog(priority, "%s", string); |
390 | } | 409 | } |
391 | 410 | ||
392 | static void xcloselog(BIO* bp) | 411 | static void |
412 | xcloselog(BIO* bp) | ||
393 | { | 413 | { |
394 | closelog(); | 414 | closelog(); |
395 | } | 415 | } |
diff --git a/src/lib/libssl/src/crypto/bio/bss_mem.c b/src/lib/libssl/src/crypto/bio/bss_mem.c index 37d4194e4b..a5192202bd 100644 --- a/src/lib/libssl/src/crypto/bio/bss_mem.c +++ b/src/lib/libssl/src/crypto/bio/bss_mem.c | |||
@@ -68,8 +68,8 @@ static int mem_gets(BIO *h, char *str, int size); | |||
68 | static long mem_ctrl(BIO *h, int cmd, long arg1, void *arg2); | 68 | static long mem_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
69 | static int mem_new(BIO *h); | 69 | static int mem_new(BIO *h); |
70 | static int mem_free(BIO *data); | 70 | static int mem_free(BIO *data); |
71 | static BIO_METHOD mem_method= | 71 | |
72 | { | 72 | static BIO_METHOD mem_method = { |
73 | BIO_TYPE_MEM, | 73 | BIO_TYPE_MEM, |
74 | "memory buffer", | 74 | "memory buffer", |
75 | mem_write, | 75 | mem_write, |
@@ -80,28 +80,31 @@ static BIO_METHOD mem_method= | |||
80 | mem_new, | 80 | mem_new, |
81 | mem_free, | 81 | mem_free, |
82 | NULL, | 82 | NULL, |
83 | }; | 83 | }; |
84 | 84 | ||
85 | /* bio->num is used to hold the value to return on 'empty', if it is | 85 | /* bio->num is used to hold the value to return on 'empty', if it is |
86 | * 0, should_retry is not set */ | 86 | * 0, should_retry is not set */ |
87 | 87 | ||
88 | BIO_METHOD *BIO_s_mem(void) | 88 | BIO_METHOD |
89 | { | 89 | *BIO_s_mem(void) |
90 | return(&mem_method); | 90 | { |
91 | } | 91 | return (&mem_method); |
92 | } | ||
92 | 93 | ||
93 | BIO *BIO_new_mem_buf(void *buf, int len) | 94 | BIO |
95 | *BIO_new_mem_buf(void *buf, int len) | ||
94 | { | 96 | { |
95 | BIO *ret; | 97 | BIO *ret; |
96 | BUF_MEM *b; | 98 | BUF_MEM *b; |
97 | size_t sz; | 99 | size_t sz; |
98 | 100 | ||
99 | if (!buf) { | 101 | if (!buf) { |
100 | BIOerr(BIO_F_BIO_NEW_MEM_BUF,BIO_R_NULL_PARAMETER); | 102 | BIOerr(BIO_F_BIO_NEW_MEM_BUF, BIO_R_NULL_PARAMETER); |
101 | return NULL; | 103 | return NULL; |
102 | } | 104 | } |
103 | sz = (len<0) ? strlen(buf) : (size_t)len; | 105 | sz = (len < 0) ? strlen(buf) : (size_t)len; |
104 | if(!(ret = BIO_new(BIO_s_mem())) ) return NULL; | 106 | if (!(ret = BIO_new(BIO_s_mem()))) |
107 | return NULL; | ||
105 | b = (BUF_MEM *)ret->ptr; | 108 | b = (BUF_MEM *)ret->ptr; |
106 | b->data = buf; | 109 | b->data = buf; |
107 | b->length = sz; | 110 | b->length = sz; |
@@ -112,208 +115,205 @@ BIO *BIO_new_mem_buf(void *buf, int len) | |||
112 | return ret; | 115 | return ret; |
113 | } | 116 | } |
114 | 117 | ||
115 | static int mem_new(BIO *bi) | 118 | static int |
116 | { | 119 | mem_new(BIO *bi) |
120 | { | ||
117 | BUF_MEM *b; | 121 | BUF_MEM *b; |
118 | 122 | ||
119 | if ((b=BUF_MEM_new()) == NULL) | 123 | if ((b = BUF_MEM_new()) == NULL) |
120 | return(0); | 124 | return (0); |
121 | bi->shutdown=1; | 125 | bi->shutdown = 1; |
122 | bi->init=1; | 126 | bi->init = 1; |
123 | bi->num= -1; | 127 | bi->num = -1; |
124 | bi->ptr=(char *)b; | 128 | bi->ptr = (char *)b; |
125 | return(1); | 129 | return (1); |
126 | } | 130 | } |
127 | 131 | ||
128 | static int mem_free(BIO *a) | 132 | static int |
129 | { | 133 | mem_free(BIO *a) |
130 | if (a == NULL) return(0); | 134 | { |
131 | if (a->shutdown) | 135 | if (a == NULL) |
132 | { | 136 | return (0); |
133 | if ((a->init) && (a->ptr != NULL)) | 137 | if (a->shutdown) { |
134 | { | 138 | if ((a->init) && (a->ptr != NULL)) { |
135 | BUF_MEM *b; | 139 | BUF_MEM *b; |
136 | b = (BUF_MEM *)a->ptr; | 140 | b = (BUF_MEM *)a->ptr; |
137 | if(a->flags & BIO_FLAGS_MEM_RDONLY) b->data = NULL; | 141 | if (a->flags & BIO_FLAGS_MEM_RDONLY) |
138 | BUF_MEM_free(b); | 142 | b->data = NULL; |
139 | a->ptr=NULL; | 143 | BUF_MEM_free(b); |
140 | } | 144 | a->ptr = NULL; |
141 | } | 145 | } |
142 | return(1); | ||
143 | } | 146 | } |
144 | 147 | return (1); | |
145 | static int mem_read(BIO *b, char *out, int outl) | 148 | } |
146 | { | 149 | |
147 | int ret= -1; | 150 | static int |
151 | mem_read(BIO *b, char *out, int outl) | ||
152 | { | ||
153 | int ret = -1; | ||
148 | BUF_MEM *bm; | 154 | BUF_MEM *bm; |
149 | 155 | ||
150 | bm=(BUF_MEM *)b->ptr; | 156 | bm = (BUF_MEM *)b->ptr; |
151 | BIO_clear_retry_flags(b); | 157 | BIO_clear_retry_flags(b); |
152 | ret=(outl >=0 && (size_t)outl > bm->length)?(int)bm->length:outl; | 158 | ret = (outl >=0 && (size_t)outl > bm->length) ? (int)bm->length : outl; |
153 | if ((out != NULL) && (ret > 0)) { | 159 | if ((out != NULL) && (ret > 0)) { |
154 | memcpy(out,bm->data,ret); | 160 | memcpy(out, bm->data, ret); |
155 | bm->length-=ret; | 161 | bm->length -= ret; |
156 | if(b->flags & BIO_FLAGS_MEM_RDONLY) bm->data += ret; | 162 | if (b->flags & BIO_FLAGS_MEM_RDONLY) |
163 | bm->data += ret; | ||
157 | else { | 164 | else { |
158 | memmove(&(bm->data[0]),&(bm->data[ret]),bm->length); | 165 | memmove(&(bm->data[0]), &(bm->data[ret]), bm->length); |
159 | } | 166 | } |
160 | } else if (bm->length == 0) | 167 | } else if (bm->length == 0) { |
161 | { | ||
162 | ret = b->num; | 168 | ret = b->num; |
163 | if (ret != 0) | 169 | if (ret != 0) |
164 | BIO_set_retry_read(b); | 170 | BIO_set_retry_read(b); |
165 | } | ||
166 | return(ret); | ||
167 | } | 171 | } |
172 | return (ret); | ||
173 | } | ||
168 | 174 | ||
169 | static int mem_write(BIO *b, const char *in, int inl) | 175 | static int |
170 | { | 176 | mem_write(BIO *b, const char *in, int inl) |
171 | int ret= -1; | 177 | { |
178 | int ret = -1; | ||
172 | int blen; | 179 | int blen; |
173 | BUF_MEM *bm; | 180 | BUF_MEM *bm; |
174 | 181 | ||
175 | bm=(BUF_MEM *)b->ptr; | 182 | bm = (BUF_MEM *)b->ptr; |
176 | if (in == NULL) | 183 | if (in == NULL) { |
177 | { | 184 | BIOerr(BIO_F_MEM_WRITE, BIO_R_NULL_PARAMETER); |
178 | BIOerr(BIO_F_MEM_WRITE,BIO_R_NULL_PARAMETER); | ||
179 | goto end; | 185 | goto end; |
180 | } | 186 | } |
181 | 187 | ||
182 | if(b->flags & BIO_FLAGS_MEM_RDONLY) { | 188 | if (b->flags & BIO_FLAGS_MEM_RDONLY) { |
183 | BIOerr(BIO_F_MEM_WRITE,BIO_R_WRITE_TO_READ_ONLY_BIO); | 189 | BIOerr(BIO_F_MEM_WRITE, BIO_R_WRITE_TO_READ_ONLY_BIO); |
184 | goto end; | 190 | goto end; |
185 | } | 191 | } |
186 | 192 | ||
187 | BIO_clear_retry_flags(b); | 193 | BIO_clear_retry_flags(b); |
188 | blen=bm->length; | 194 | blen = bm->length; |
189 | if (BUF_MEM_grow_clean(bm,blen+inl) != (blen+inl)) | 195 | if (BUF_MEM_grow_clean(bm, blen + inl) != (blen + inl)) |
190 | goto end; | 196 | goto end; |
191 | memcpy(&(bm->data[blen]),in,inl); | 197 | memcpy(&(bm->data[blen]), in, inl); |
192 | ret=inl; | 198 | ret = inl; |
193 | end: | 199 | end: |
194 | return(ret); | 200 | return (ret); |
195 | } | 201 | } |
196 | 202 | ||
197 | static long mem_ctrl(BIO *b, int cmd, long num, void *ptr) | 203 | static long |
198 | { | 204 | mem_ctrl(BIO *b, int cmd, long num, void *ptr) |
199 | long ret=1; | 205 | { |
206 | long ret = 1; | ||
200 | char **pptr; | 207 | char **pptr; |
201 | 208 | ||
202 | BUF_MEM *bm=(BUF_MEM *)b->ptr; | 209 | BUF_MEM *bm = (BUF_MEM *)b->ptr; |
203 | 210 | ||
204 | switch (cmd) | 211 | switch (cmd) { |
205 | { | ||
206 | case BIO_CTRL_RESET: | 212 | case BIO_CTRL_RESET: |
207 | if (bm->data != NULL) | 213 | if (bm->data != NULL) { |
208 | { | ||
209 | /* For read only case reset to the start again */ | 214 | /* For read only case reset to the start again */ |
210 | if(b->flags & BIO_FLAGS_MEM_RDONLY) | 215 | if (b->flags & BIO_FLAGS_MEM_RDONLY) { |
211 | { | ||
212 | bm->data -= bm->max - bm->length; | 216 | bm->data -= bm->max - bm->length; |
213 | bm->length = bm->max; | 217 | bm->length = bm->max; |
214 | } | 218 | } else { |
215 | else | 219 | memset(bm->data, 0, bm->max); |
216 | { | 220 | bm->length = 0; |
217 | memset(bm->data,0,bm->max); | ||
218 | bm->length=0; | ||
219 | } | ||
220 | } | 221 | } |
222 | } | ||
221 | break; | 223 | break; |
222 | case BIO_CTRL_EOF: | 224 | case BIO_CTRL_EOF: |
223 | ret=(long)(bm->length == 0); | 225 | ret = (long)(bm->length == 0); |
224 | break; | 226 | break; |
225 | case BIO_C_SET_BUF_MEM_EOF_RETURN: | 227 | case BIO_C_SET_BUF_MEM_EOF_RETURN: |
226 | b->num=(int)num; | 228 | b->num = (int)num; |
227 | break; | 229 | break; |
228 | case BIO_CTRL_INFO: | 230 | case BIO_CTRL_INFO: |
229 | ret=(long)bm->length; | 231 | ret = (long)bm->length; |
230 | if (ptr != NULL) | 232 | if (ptr != NULL) { |
231 | { | 233 | pptr = (char **)ptr; |
232 | pptr=(char **)ptr; | 234 | *pptr = (char *)&(bm->data[0]); |
233 | *pptr=(char *)&(bm->data[0]); | 235 | } |
234 | } | ||
235 | break; | 236 | break; |
236 | case BIO_C_SET_BUF_MEM: | 237 | case BIO_C_SET_BUF_MEM: |
237 | mem_free(b); | 238 | mem_free(b); |
238 | b->shutdown=(int)num; | 239 | b->shutdown = (int)num; |
239 | b->ptr=ptr; | 240 | b->ptr = ptr; |
240 | break; | 241 | break; |
241 | case BIO_C_GET_BUF_MEM_PTR: | 242 | case BIO_C_GET_BUF_MEM_PTR: |
242 | if (ptr != NULL) | 243 | if (ptr != NULL) { |
243 | { | 244 | pptr = (char **)ptr; |
244 | pptr=(char **)ptr; | 245 | *pptr = (char *)bm; |
245 | *pptr=(char *)bm; | 246 | } |
246 | } | ||
247 | break; | 247 | break; |
248 | case BIO_CTRL_GET_CLOSE: | 248 | case BIO_CTRL_GET_CLOSE: |
249 | ret=(long)b->shutdown; | 249 | ret = (long)b->shutdown; |
250 | break; | 250 | break; |
251 | case BIO_CTRL_SET_CLOSE: | 251 | case BIO_CTRL_SET_CLOSE: |
252 | b->shutdown=(int)num; | 252 | b->shutdown = (int)num; |
253 | break; | 253 | break; |
254 | 254 | ||
255 | case BIO_CTRL_WPENDING: | 255 | case BIO_CTRL_WPENDING: |
256 | ret=0L; | 256 | ret = 0L; |
257 | break; | 257 | break; |
258 | case BIO_CTRL_PENDING: | 258 | case BIO_CTRL_PENDING: |
259 | ret=(long)bm->length; | 259 | ret = (long)bm->length; |
260 | break; | 260 | break; |
261 | case BIO_CTRL_DUP: | 261 | case BIO_CTRL_DUP: |
262 | case BIO_CTRL_FLUSH: | 262 | case BIO_CTRL_FLUSH: |
263 | ret=1; | 263 | ret = 1; |
264 | break; | 264 | break; |
265 | case BIO_CTRL_PUSH: | 265 | case BIO_CTRL_PUSH: |
266 | case BIO_CTRL_POP: | 266 | case BIO_CTRL_POP: |
267 | default: | 267 | default: |
268 | ret=0; | 268 | ret = 0; |
269 | break; | 269 | break; |
270 | } | ||
271 | return(ret); | ||
272 | } | 270 | } |
271 | return (ret); | ||
272 | } | ||
273 | 273 | ||
274 | static int mem_gets(BIO *bp, char *buf, int size) | 274 | static int |
275 | { | 275 | mem_gets(BIO *bp, char *buf, int size) |
276 | int i,j; | 276 | { |
277 | int ret= -1; | 277 | int i, j; |
278 | int ret = -1; | ||
278 | char *p; | 279 | char *p; |
279 | BUF_MEM *bm=(BUF_MEM *)bp->ptr; | 280 | BUF_MEM *bm = (BUF_MEM *)bp->ptr; |
280 | 281 | ||
281 | BIO_clear_retry_flags(bp); | 282 | BIO_clear_retry_flags(bp); |
282 | j=bm->length; | 283 | j = bm->length; |
283 | if ((size-1) < j) j=size-1; | 284 | if ((size - 1) < j) |
284 | if (j <= 0) | 285 | j = size - 1; |
285 | { | 286 | if (j <= 0) { |
286 | *buf='\0'; | 287 | *buf = '\0'; |
287 | return 0; | 288 | return 0; |
288 | } | 289 | } |
289 | p=bm->data; | 290 | p = bm->data; |
290 | for (i=0; i<j; i++) | 291 | for (i = 0; i < j; i++) { |
291 | { | 292 | if (p[i] == '\n') { |
292 | if (p[i] == '\n') | ||
293 | { | ||
294 | i++; | 293 | i++; |
295 | break; | 294 | break; |
296 | } | ||
297 | } | 295 | } |
296 | } | ||
298 | 297 | ||
299 | /* | 298 | /* |
300 | * i is now the max num of bytes to copy, either j or up to | 299 | * i is now the max num of bytes to copy, either j or up to |
301 | * and including the first newline | 300 | * and including the first newline |
302 | */ | 301 | */ |
303 | 302 | ||
304 | i=mem_read(bp,buf,i); | 303 | i = mem_read(bp, buf, i); |
305 | if (i > 0) buf[i]='\0'; | 304 | if (i > 0) |
306 | ret=i; | 305 | buf[i] = '\0'; |
307 | return(ret); | 306 | ret = i; |
308 | } | 307 | return (ret); |
308 | } | ||
309 | 309 | ||
310 | static int mem_puts(BIO *bp, const char *str) | 310 | static int |
311 | { | 311 | mem_puts(BIO *bp, const char *str) |
312 | int n,ret; | 312 | { |
313 | int n, ret; | ||
313 | 314 | ||
314 | n=strlen(str); | 315 | n = strlen(str); |
315 | ret=mem_write(bp,str,n); | 316 | ret = mem_write(bp, str, n); |
316 | /* memory semantics is that it will always work */ | 317 | /* memory semantics is that it will always work */ |
317 | return(ret); | 318 | return (ret); |
318 | } | 319 | } |
319 | |||
diff --git a/src/lib/libssl/src/crypto/bio/bss_null.c b/src/lib/libssl/src/crypto/bio/bss_null.c index 46b73339df..51aed2ac4b 100644 --- a/src/lib/libssl/src/crypto/bio/bss_null.c +++ b/src/lib/libssl/src/crypto/bio/bss_null.c | |||
@@ -68,8 +68,8 @@ static int null_gets(BIO *h, char *str, int size); | |||
68 | static long null_ctrl(BIO *h, int cmd, long arg1, void *arg2); | 68 | static long null_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
69 | static int null_new(BIO *h); | 69 | static int null_new(BIO *h); |
70 | static int null_free(BIO *data); | 70 | static int null_free(BIO *data); |
71 | static BIO_METHOD null_method= | 71 | |
72 | { | 72 | static BIO_METHOD null_method = { |
73 | BIO_TYPE_NULL, | 73 | BIO_TYPE_NULL, |
74 | "NULL", | 74 | "NULL", |
75 | null_write, | 75 | null_write, |
@@ -80,50 +80,56 @@ static BIO_METHOD null_method= | |||
80 | null_new, | 80 | null_new, |
81 | null_free, | 81 | null_free, |
82 | NULL, | 82 | NULL, |
83 | }; | 83 | }; |
84 | 84 | ||
85 | BIO_METHOD *BIO_s_null(void) | 85 | BIO_METHOD |
86 | { | 86 | *BIO_s_null(void) |
87 | return(&null_method); | 87 | { |
88 | } | 88 | return (&null_method); |
89 | } | ||
89 | 90 | ||
90 | static int null_new(BIO *bi) | 91 | static int |
91 | { | 92 | null_new(BIO *bi) |
92 | bi->init=1; | 93 | { |
93 | bi->num=0; | 94 | bi->init = 1; |
94 | bi->ptr=(NULL); | 95 | bi->num = 0; |
95 | return(1); | 96 | bi->ptr = (NULL); |
96 | } | 97 | return (1); |
98 | } | ||
97 | 99 | ||
98 | static int null_free(BIO *a) | 100 | static int |
99 | { | 101 | null_free(BIO *a) |
100 | if (a == NULL) return(0); | 102 | { |
101 | return(1); | 103 | if (a == NULL) |
102 | } | 104 | return (0); |
103 | 105 | return (1); | |
104 | static int null_read(BIO *b, char *out, int outl) | 106 | } |
105 | { | ||
106 | return(0); | ||
107 | } | ||
108 | 107 | ||
109 | static int null_write(BIO *b, const char *in, int inl) | 108 | static int |
110 | { | 109 | null_read(BIO *b, char *out, int outl) |
111 | return(inl); | 110 | { |
112 | } | 111 | return (0); |
112 | } | ||
113 | |||
114 | static int | ||
115 | null_write(BIO *b, const char *in, int inl) | ||
116 | { | ||
117 | return (inl); | ||
118 | } | ||
113 | 119 | ||
114 | static long null_ctrl(BIO *b, int cmd, long num, void *ptr) | 120 | static long |
115 | { | 121 | null_ctrl(BIO *b, int cmd, long num, void *ptr) |
116 | long ret=1; | 122 | { |
123 | long ret = 1; | ||
117 | 124 | ||
118 | switch (cmd) | 125 | switch (cmd) { |
119 | { | ||
120 | case BIO_CTRL_RESET: | 126 | case BIO_CTRL_RESET: |
121 | case BIO_CTRL_EOF: | 127 | case BIO_CTRL_EOF: |
122 | case BIO_CTRL_SET: | 128 | case BIO_CTRL_SET: |
123 | case BIO_CTRL_SET_CLOSE: | 129 | case BIO_CTRL_SET_CLOSE: |
124 | case BIO_CTRL_FLUSH: | 130 | case BIO_CTRL_FLUSH: |
125 | case BIO_CTRL_DUP: | 131 | case BIO_CTRL_DUP: |
126 | ret=1; | 132 | ret = 1; |
127 | break; | 133 | break; |
128 | case BIO_CTRL_GET_CLOSE: | 134 | case BIO_CTRL_GET_CLOSE: |
129 | case BIO_CTRL_INFO: | 135 | case BIO_CTRL_INFO: |
@@ -131,20 +137,22 @@ static long null_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
131 | case BIO_CTRL_PENDING: | 137 | case BIO_CTRL_PENDING: |
132 | case BIO_CTRL_WPENDING: | 138 | case BIO_CTRL_WPENDING: |
133 | default: | 139 | default: |
134 | ret=0; | 140 | ret = 0; |
135 | break; | 141 | break; |
136 | } | ||
137 | return(ret); | ||
138 | } | 142 | } |
143 | return (ret); | ||
144 | } | ||
139 | 145 | ||
140 | static int null_gets(BIO *bp, char *buf, int size) | 146 | static int |
141 | { | 147 | null_gets(BIO *bp, char *buf, int size) |
142 | return(0); | 148 | { |
143 | } | 149 | return (0); |
144 | 150 | } | |
145 | static int null_puts(BIO *bp, const char *str) | ||
146 | { | ||
147 | if (str == NULL) return(0); | ||
148 | return(strlen(str)); | ||
149 | } | ||
150 | 151 | ||
152 | static int | ||
153 | null_puts(BIO *bp, const char *str) | ||
154 | { | ||
155 | if (str == NULL) | ||
156 | return (0); | ||
157 | return (strlen(str)); | ||
158 | } | ||
diff --git a/src/lib/libssl/src/crypto/bio/bss_rtcp.c b/src/lib/libssl/src/crypto/bio/bss_rtcp.c index 7dae485564..84d01e58b4 100644 --- a/src/lib/libssl/src/crypto/bio/bss_rtcp.c +++ b/src/lib/libssl/src/crypto/bio/bss_rtcp.c | |||
@@ -73,31 +73,32 @@ | |||
73 | 73 | ||
74 | typedef unsigned short io_channel; | 74 | typedef unsigned short io_channel; |
75 | /*************************************************************************/ | 75 | /*************************************************************************/ |
76 | struct io_status { short status, count; long flags; }; | 76 | struct io_status { short status, count; |
77 | long flags; | ||
78 | }; | ||
77 | 79 | ||
78 | struct rpc_msg { /* Should have member alignment inhibited */ | 80 | struct rpc_msg { /* Should have member alignment inhibited */ |
79 | char channel; /* 'A'-app data. 'R'-remote client 'G'-global */ | 81 | char channel; /* 'A'-app data. 'R'-remote client 'G'-global */ |
80 | char function; /* 'G'-get, 'P'-put, 'C'-confirm, 'X'-close */ | 82 | char function; /* 'G'-get, 'P'-put, 'C'-confirm, 'X'-close */ |
81 | unsigned short int length; /* Amount of data returned or max to return */ | 83 | unsigned short int length; /* Amount of data returned or max to return */ |
82 | char data[4092]; /* variable data */ | 84 | char data[4092]; /* variable data */ |
83 | }; | 85 | }; |
84 | #define RPC_HDR_SIZE (sizeof(struct rpc_msg) - 4092) | 86 | #define RPC_HDR_SIZE (sizeof(struct rpc_msg) - 4092) |
85 | 87 | ||
86 | struct rpc_ctx { | 88 | struct rpc_ctx { |
87 | int filled, pos; | 89 | int filled, pos; |
88 | struct rpc_msg msg; | 90 | struct rpc_msg msg; |
89 | }; | 91 | }; |
90 | 92 | ||
91 | static int rtcp_write(BIO *h,const char *buf,int num); | 93 | static int rtcp_write(BIO *h, const char *buf, int num); |
92 | static int rtcp_read(BIO *h,char *buf,int size); | 94 | static int rtcp_read(BIO *h, char *buf, int size); |
93 | static int rtcp_puts(BIO *h,const char *str); | 95 | static int rtcp_puts(BIO *h, const char *str); |
94 | static int rtcp_gets(BIO *h,char *str,int size); | 96 | static int rtcp_gets(BIO *h, char *str, int size); |
95 | static long rtcp_ctrl(BIO *h,int cmd,long arg1,void *arg2); | 97 | static long rtcp_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
96 | static int rtcp_new(BIO *h); | 98 | static int rtcp_new(BIO *h); |
97 | static int rtcp_free(BIO *data); | 99 | static int rtcp_free(BIO *data); |
98 | 100 | ||
99 | static BIO_METHOD rtcp_method= | 101 | static BIO_METHOD rtcp_method = { |
100 | { | ||
101 | BIO_TYPE_FD, | 102 | BIO_TYPE_FD, |
102 | "RTCP", | 103 | "RTCP", |
103 | rtcp_write, | 104 | rtcp_write, |
@@ -108,12 +109,13 @@ static BIO_METHOD rtcp_method= | |||
108 | rtcp_new, | 109 | rtcp_new, |
109 | rtcp_free, | 110 | rtcp_free, |
110 | NULL, | 111 | NULL, |
111 | }; | 112 | }; |
112 | 113 | ||
113 | BIO_METHOD *BIO_s_rtcp(void) | 114 | BIO_METHOD |
114 | { | 115 | *BIO_s_rtcp(void) |
115 | return(&rtcp_method); | 116 | { |
116 | } | 117 | return (&rtcp_method); |
118 | } | ||
117 | /*****************************************************************************/ | 119 | /*****************************************************************************/ |
118 | /* Decnet I/O routines. | 120 | /* Decnet I/O routines. |
119 | */ | 121 | */ |
@@ -123,25 +125,28 @@ BIO_METHOD *BIO_s_rtcp(void) | |||
123 | #pragma message disable DOLLARID | 125 | #pragma message disable DOLLARID |
124 | #endif | 126 | #endif |
125 | 127 | ||
126 | static int get ( io_channel chan, char *buffer, int maxlen, int *length ) | 128 | static int get(io_channel chan, char *buffer, int maxlen, int *length) |
127 | { | 129 | { |
128 | int status; | 130 | int status; |
129 | struct io_status iosb; | 131 | struct io_status iosb; |
130 | status = sys$qiow ( 0, chan, IO$_READVBLK, &iosb, 0, 0, | 132 | status = sys$qiow(0, chan, IO$_READVBLK, &iosb, 0, 0, buffer, maxlen, |
131 | buffer, maxlen, 0, 0, 0, 0 ); | 133 | 0, 0, 0, 0 ); |
132 | if ( (status&1) == 1 ) status = iosb.status; | 134 | if ((status & 1) == 1) |
133 | if ( (status&1) == 1 ) *length = iosb.count; | 135 | status = iosb.status; |
134 | return status; | 136 | if ((status & 1) == 1 ) |
137 | *length = iosb.count; | ||
138 | return status; | ||
135 | } | 139 | } |
136 | 140 | ||
137 | static int put ( io_channel chan, char *buffer, int length ) | 141 | static int put(io_channel chan, char *buffer, int length) |
138 | { | 142 | { |
139 | int status; | 143 | int status; |
140 | struct io_status iosb; | 144 | struct io_status iosb; |
141 | status = sys$qiow ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0, | 145 | status = sys$qiow ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0, buffer, |
142 | buffer, length, 0, 0, 0, 0 ); | 146 | length, 0, 0, 0, 0 ); |
143 | if ( (status&1) == 1 ) status = iosb.status; | 147 | if ((status & 1) == 1) |
144 | return status; | 148 | status = iosb.status; |
149 | return status; | ||
145 | } | 150 | } |
146 | 151 | ||
147 | #ifdef __DECC | 152 | #ifdef __DECC |
@@ -150,109 +155,127 @@ static int put ( io_channel chan, char *buffer, int length ) | |||
150 | 155 | ||
151 | /***************************************************************************/ | 156 | /***************************************************************************/ |
152 | 157 | ||
153 | static int rtcp_new(BIO *bi) | 158 | static int |
159 | rtcp_new(BIO *bi) | ||
154 | { | 160 | { |
155 | struct rpc_ctx *ctx; | 161 | struct rpc_ctx *ctx; |
156 | bi->init=1; | 162 | bi->init = 1; |
157 | bi->num=0; | 163 | bi->num = 0; |
158 | bi->flags = 0; | 164 | bi->flags = 0; |
159 | bi->ptr=OPENSSL_malloc(sizeof(struct rpc_ctx)); | 165 | bi->ptr = OPENSSL_malloc(sizeof(struct rpc_ctx)); |
160 | ctx = (struct rpc_ctx *) bi->ptr; | 166 | ctx = (struct rpc_ctx *)bi->ptr; |
161 | ctx->filled = 0; | 167 | ctx->filled = 0; |
162 | ctx->pos = 0; | 168 | ctx->pos = 0; |
163 | return(1); | 169 | return (1); |
164 | } | 170 | } |
165 | 171 | ||
166 | static int rtcp_free(BIO *a) | 172 | static int |
173 | rtcp_free(BIO *a) | ||
167 | { | 174 | { |
168 | if (a == NULL) return(0); | 175 | if (a == NULL) |
169 | if ( a->ptr ) OPENSSL_free ( a->ptr ); | 176 | return (0); |
177 | if (a->ptr) | ||
178 | OPENSSL_free(a->ptr); | ||
170 | a->ptr = NULL; | 179 | a->ptr = NULL; |
171 | return(1); | 180 | return (1); |
172 | } | 181 | } |
173 | 182 | ||
174 | static int rtcp_read(BIO *b, char *out, int outl) | 183 | static int |
184 | rtcp_read(BIO *b, char *out, int outl) | ||
175 | { | 185 | { |
176 | int status, length; | 186 | int status, length; |
177 | struct rpc_ctx *ctx; | 187 | struct rpc_ctx *ctx; |
178 | /* | 188 | /* |
179 | * read data, return existing. | 189 | * read data, return existing. |
180 | */ | 190 | */ |
181 | ctx = (struct rpc_ctx *) b->ptr; | 191 | ctx = (struct rpc_ctx *)b->ptr; |
182 | if ( ctx->pos < ctx->filled ) { | 192 | if (ctx->pos < ctx->filled) { |
183 | length = ctx->filled - ctx->pos; | 193 | length = ctx->filled - ctx->pos; |
184 | if ( length > outl ) length = outl; | 194 | if (length > outl) |
185 | memmove ( out, &ctx->msg.data[ctx->pos], length ); | 195 | length = outl; |
186 | ctx->pos += length; | 196 | memmove(out, &ctx->msg.data[ctx->pos], length); |
187 | return length; | 197 | ctx->pos += length; |
188 | } | 198 | return length; |
189 | /* | 199 | } |
190 | * Requst more data from R channel. | 200 | /* |
191 | */ | 201 | * Requst more data from R channel. |
192 | ctx->msg.channel = 'R'; | 202 | */ |
193 | ctx->msg.function = 'G'; | 203 | ctx->msg.channel = 'R'; |
194 | ctx->msg.length = sizeof(ctx->msg.data); | 204 | ctx->msg.function = 'G'; |
195 | status = put ( b->num, (char *) &ctx->msg, RPC_HDR_SIZE ); | 205 | ctx->msg.length = sizeof(ctx->msg.data); |
196 | if ( (status&1) == 0 ) { | 206 | status = put(b->num, (char *)&ctx->msg, RPC_HDR_SIZE); |
197 | return -1; | 207 | if ((status & 1) == 0 ) { |
198 | } | 208 | return -1; |
199 | /* | 209 | } |
200 | * Read. | 210 | /* |
201 | */ | 211 | * Read. |
202 | ctx->pos = ctx->filled = 0; | 212 | */ |
203 | status = get ( b->num, (char *) &ctx->msg, sizeof(ctx->msg), &length ); | 213 | ctx->pos = ctx->filled = 0; |
204 | if ( (status&1) == 0 ) length = -1; | 214 | status = get(b->num, (char *)&ctx->msg, sizeof(ctx->msg), &length); |
205 | if ( ctx->msg.channel != 'R' || ctx->msg.function != 'C' ) { | 215 | if ((status & 1) == 0) |
206 | length = -1; | 216 | length = -1; |
207 | } | 217 | if (ctx->msg.channel != 'R' || ctx->msg.function != 'C') { |
208 | ctx->filled = length - RPC_HDR_SIZE; | 218 | length = -1; |
209 | 219 | } | |
210 | if ( ctx->pos < ctx->filled ) { | 220 | ctx->filled = length - RPC_HDR_SIZE; |
211 | length = ctx->filled - ctx->pos; | 221 | |
212 | if ( length > outl ) length = outl; | 222 | if (ctx->pos < ctx->filled) { |
213 | memmove ( out, ctx->msg.data, length ); | 223 | length = ctx->filled - ctx->pos; |
214 | ctx->pos += length; | 224 | if (length > outl) |
215 | return length; | 225 | length = outl; |
216 | } | 226 | memmove(out, ctx->msg.data, length); |
227 | ctx->pos += length; | ||
228 | return length; | ||
229 | } | ||
217 | 230 | ||
218 | return length; | 231 | return length; |
219 | } | 232 | } |
220 | 233 | ||
221 | static int rtcp_write(BIO *b, const char *in, int inl) | 234 | static int |
235 | rtcp_write(BIO *b, const char *in, int inl) | ||
222 | { | 236 | { |
223 | int status, i, segment, length; | 237 | int status, i, segment, length; |
224 | struct rpc_ctx *ctx; | 238 | struct rpc_ctx *ctx; |
225 | /* | 239 | /* |
226 | * Output data, send in chunks no larger that sizeof(ctx->msg.data). | 240 | * Output data, send in chunks no larger that sizeof(ctx->msg.data). |
227 | */ | 241 | */ |
228 | ctx = (struct rpc_ctx *) b->ptr; | 242 | ctx = (struct rpc_ctx *)b->ptr; |
229 | for ( i = 0; i < inl; i += segment ) { | 243 | for (i = 0; i < inl; i += segment) { |
230 | segment = inl - i; | 244 | segment = inl - i; |
231 | if ( segment > sizeof(ctx->msg.data) ) segment = sizeof(ctx->msg.data); | 245 | if (segment > sizeof(ctx->msg.data)) |
232 | ctx->msg.channel = 'R'; | 246 | segment = sizeof(ctx->msg.data); |
233 | ctx->msg.function = 'P'; | 247 | ctx->msg.channel = 'R'; |
234 | ctx->msg.length = segment; | 248 | ctx->msg.function = 'P'; |
235 | memmove ( ctx->msg.data, &in[i], segment ); | 249 | ctx->msg.length = segment; |
236 | status = put ( b->num, (char *) &ctx->msg, segment + RPC_HDR_SIZE ); | 250 | memmove(ctx->msg.data, &in[i], segment); |
237 | if ((status&1) == 0 ) { i = -1; break; } | 251 | status = put(b->num, (char *) &ctx->msg, |
252 | segment + RPC_HDR_SIZE); | ||
253 | if ((status & 1) == 0) { | ||
254 | i = -1; | ||
255 | break; | ||
256 | } | ||
238 | 257 | ||
239 | status = get ( b->num, (char *) &ctx->msg, sizeof(ctx->msg), &length ); | 258 | status = get(b->num, (char *)&ctx->msg, sizeof(ctx->msg), |
240 | if ( ((status&1) == 0) || (length < RPC_HDR_SIZE) ) { i = -1; break; } | 259 | &length ); |
241 | if ( (ctx->msg.channel != 'R') || (ctx->msg.function != 'C') ) { | 260 | if (((status&1) == 0) || (length < RPC_HDR_SIZE)) { |
242 | printf("unexpected response when confirming put %c %c\n", | 261 | i = -1; |
243 | ctx->msg.channel, ctx->msg.function ); | 262 | break; |
263 | } | ||
264 | if ((ctx->msg.channel != 'R') || (ctx->msg.function != 'C')) { | ||
265 | printf("unexpected response when confirming put %c %c\n", | ||
266 | ctx->msg.channel, ctx->msg.function ); | ||
244 | 267 | ||
268 | } | ||
245 | } | 269 | } |
246 | } | 270 | return (i); |
247 | return(i); | ||
248 | } | 271 | } |
249 | 272 | ||
250 | static long rtcp_ctrl(BIO *b, int cmd, long num, void *ptr) | 273 | static long |
251 | { | 274 | rtcp_ctrl(BIO *b, int cmd, long num, void *ptr) |
252 | long ret=1; | 275 | { |
276 | long ret = 1; | ||
253 | 277 | ||
254 | switch (cmd) | 278 | switch (cmd) { |
255 | { | ||
256 | case BIO_CTRL_RESET: | 279 | case BIO_CTRL_RESET: |
257 | case BIO_CTRL_EOF: | 280 | case BIO_CTRL_EOF: |
258 | ret = 1; | 281 | ret = 1; |
@@ -260,11 +283,11 @@ static long rtcp_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
260 | case BIO_C_SET_FD: | 283 | case BIO_C_SET_FD: |
261 | b->num = num; | 284 | b->num = num; |
262 | ret = 1; | 285 | ret = 1; |
263 | break; | 286 | break; |
264 | case BIO_CTRL_SET_CLOSE: | 287 | case BIO_CTRL_SET_CLOSE: |
265 | case BIO_CTRL_FLUSH: | 288 | case BIO_CTRL_FLUSH: |
266 | case BIO_CTRL_DUP: | 289 | case BIO_CTRL_DUP: |
267 | ret=1; | 290 | ret = 1; |
268 | break; | 291 | break; |
269 | case BIO_CTRL_GET_CLOSE: | 292 | case BIO_CTRL_GET_CLOSE: |
270 | case BIO_CTRL_INFO: | 293 | case BIO_CTRL_INFO: |
@@ -272,23 +295,26 @@ static long rtcp_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
272 | case BIO_CTRL_PENDING: | 295 | case BIO_CTRL_PENDING: |
273 | case BIO_CTRL_WPENDING: | 296 | case BIO_CTRL_WPENDING: |
274 | default: | 297 | default: |
275 | ret=0; | 298 | ret = 0; |
276 | break; | 299 | break; |
277 | } | ||
278 | return(ret); | ||
279 | } | ||
280 | |||
281 | static int rtcp_gets(BIO *bp, char *buf, int size) | ||
282 | { | ||
283 | return(0); | ||
284 | } | 300 | } |
301 | return (ret); | ||
302 | } | ||
285 | 303 | ||
286 | static int rtcp_puts(BIO *bp, const char *str) | 304 | static int |
305 | rtcp_gets(BIO *bp, char *buf, int size) | ||
287 | { | 306 | { |
288 | int length; | 307 | return (0); |
289 | if (str == NULL) return(0); | ||
290 | length = strlen ( str ); | ||
291 | if ( length == 0 ) return (0); | ||
292 | return rtcp_write ( bp,str, length ); | ||
293 | } | 308 | } |
294 | 309 | ||
310 | static int | ||
311 | rtcp_puts(BIO *bp, const char *str) | ||
312 | { | ||
313 | int length; | ||
314 | if (str == NULL) | ||
315 | return (0); | ||
316 | length = strlen(str); | ||
317 | if (length == 0) | ||
318 | return (0); | ||
319 | return rtcp_write(bp, str, length); | ||
320 | } | ||
diff --git a/src/lib/libssl/src/crypto/bio/bss_sock.c b/src/lib/libssl/src/crypto/bio/bss_sock.c index eb2965970c..f6d3bf7365 100644 --- a/src/lib/libssl/src/crypto/bio/bss_sock.c +++ b/src/lib/libssl/src/crypto/bio/bss_sock.c | |||
@@ -79,8 +79,7 @@ static int sock_new(BIO *h); | |||
79 | static int sock_free(BIO *data); | 79 | static int sock_free(BIO *data); |
80 | int BIO_sock_should_retry(int s); | 80 | int BIO_sock_should_retry(int s); |
81 | 81 | ||
82 | static BIO_METHOD methods_sockp= | 82 | static BIO_METHOD methods_sockp = { |
83 | { | ||
84 | BIO_TYPE_SOCKET, | 83 | BIO_TYPE_SOCKET, |
85 | "socket", | 84 | "socket", |
86 | sock_write, | 85 | sock_write, |
@@ -91,152 +90,155 @@ static BIO_METHOD methods_sockp= | |||
91 | sock_new, | 90 | sock_new, |
92 | sock_free, | 91 | sock_free, |
93 | NULL, | 92 | NULL, |
94 | }; | 93 | }; |
95 | 94 | ||
96 | BIO_METHOD *BIO_s_socket(void) | 95 | BIO_METHOD |
97 | { | 96 | *BIO_s_socket(void) |
98 | return(&methods_sockp); | 97 | { |
99 | } | 98 | return (&methods_sockp); |
99 | } | ||
100 | 100 | ||
101 | BIO *BIO_new_socket(int fd, int close_flag) | 101 | BIO |
102 | { | 102 | *BIO_new_socket(int fd, int close_flag) |
103 | { | ||
103 | BIO *ret; | 104 | BIO *ret; |
104 | 105 | ||
105 | ret=BIO_new(BIO_s_socket()); | 106 | ret = BIO_new(BIO_s_socket()); |
106 | if (ret == NULL) return(NULL); | 107 | if (ret == NULL) |
107 | BIO_set_fd(ret,fd,close_flag); | 108 | return (NULL); |
108 | return(ret); | 109 | BIO_set_fd(ret, fd, close_flag); |
109 | } | 110 | return (ret); |
111 | } | ||
110 | 112 | ||
111 | static int sock_new(BIO *bi) | 113 | static int |
112 | { | 114 | sock_new(BIO *bi) |
113 | bi->init=0; | 115 | { |
114 | bi->num=0; | 116 | bi->init = 0; |
115 | bi->ptr=NULL; | 117 | bi->num = 0; |
116 | bi->flags=0; | 118 | bi->ptr = NULL; |
117 | return(1); | 119 | bi->flags = 0; |
118 | } | 120 | return (1); |
121 | } | ||
119 | 122 | ||
120 | static int sock_free(BIO *a) | 123 | static int |
121 | { | 124 | sock_free(BIO *a) |
122 | if (a == NULL) return(0); | 125 | { |
123 | if (a->shutdown) | 126 | if (a == NULL) |
124 | { | 127 | return (0); |
125 | if (a->init) | 128 | if (a->shutdown) { |
126 | { | 129 | if (a->init) { |
127 | shutdown(a->num, SHUT_RDWR); | 130 | shutdown(a->num, SHUT_RDWR); |
128 | close(a->num); | 131 | close(a->num); |
129 | } | ||
130 | a->init=0; | ||
131 | a->flags=0; | ||
132 | } | 132 | } |
133 | return(1); | 133 | a->init = 0; |
134 | a->flags = 0; | ||
134 | } | 135 | } |
135 | 136 | return (1); | |
136 | static int sock_read(BIO *b, char *out, int outl) | 137 | } |
137 | { | ||
138 | int ret=0; | ||
139 | 138 | ||
140 | if (out != NULL) | 139 | static int |
141 | { | 140 | sock_read(BIO *b, char *out, int outl) |
141 | { | ||
142 | int ret = 0; | ||
143 | |||
144 | if (out != NULL) { | ||
142 | errno = 0; | 145 | errno = 0; |
143 | ret=read(b->num,out,outl); | 146 | ret = read(b->num, out, outl); |
144 | BIO_clear_retry_flags(b); | 147 | BIO_clear_retry_flags(b); |
145 | if (ret <= 0) | 148 | if (ret <= 0) { |
146 | { | ||
147 | if (BIO_sock_should_retry(ret)) | 149 | if (BIO_sock_should_retry(ret)) |
148 | BIO_set_retry_read(b); | 150 | BIO_set_retry_read(b); |
149 | } | ||
150 | } | 151 | } |
151 | return(ret); | ||
152 | } | 152 | } |
153 | return (ret); | ||
154 | } | ||
153 | 155 | ||
154 | static int sock_write(BIO *b, const char *in, int inl) | 156 | static int |
155 | { | 157 | sock_write(BIO *b, const char *in, int inl) |
158 | { | ||
156 | int ret; | 159 | int ret; |
157 | 160 | ||
158 | errno = 0; | 161 | errno = 0; |
159 | ret=write(b->num,in,inl); | 162 | ret = write(b->num, in, inl); |
160 | BIO_clear_retry_flags(b); | 163 | BIO_clear_retry_flags(b); |
161 | if (ret <= 0) | 164 | if (ret <= 0) { |
162 | { | ||
163 | if (BIO_sock_should_retry(ret)) | 165 | if (BIO_sock_should_retry(ret)) |
164 | BIO_set_retry_write(b); | 166 | BIO_set_retry_write(b); |
165 | } | ||
166 | return(ret); | ||
167 | } | 167 | } |
168 | return (ret); | ||
169 | } | ||
168 | 170 | ||
169 | static long sock_ctrl(BIO *b, int cmd, long num, void *ptr) | 171 | static long |
170 | { | 172 | sock_ctrl(BIO *b, int cmd, long num, void *ptr) |
171 | long ret=1; | 173 | { |
174 | long ret = 1; | ||
172 | int *ip; | 175 | int *ip; |
173 | 176 | ||
174 | switch (cmd) | 177 | switch (cmd) { |
175 | { | ||
176 | case BIO_C_SET_FD: | 178 | case BIO_C_SET_FD: |
177 | sock_free(b); | 179 | sock_free(b); |
178 | b->num= *((int *)ptr); | 180 | b->num= *((int *)ptr); |
179 | b->shutdown=(int)num; | 181 | b->shutdown = (int)num; |
180 | b->init=1; | 182 | b->init = 1; |
181 | break; | 183 | break; |
182 | case BIO_C_GET_FD: | 184 | case BIO_C_GET_FD: |
183 | if (b->init) | 185 | if (b->init) { |
184 | { | 186 | ip = (int *)ptr; |
185 | ip=(int *)ptr; | 187 | if (ip != NULL) |
186 | if (ip != NULL) *ip=b->num; | 188 | *ip = b->num; |
187 | ret=b->num; | 189 | ret = b->num; |
188 | } | 190 | } else |
189 | else | 191 | ret = -1; |
190 | ret= -1; | ||
191 | break; | 192 | break; |
192 | case BIO_CTRL_GET_CLOSE: | 193 | case BIO_CTRL_GET_CLOSE: |
193 | ret=b->shutdown; | 194 | ret = b->shutdown; |
194 | break; | 195 | break; |
195 | case BIO_CTRL_SET_CLOSE: | 196 | case BIO_CTRL_SET_CLOSE: |
196 | b->shutdown=(int)num; | 197 | b->shutdown = (int)num; |
197 | break; | 198 | break; |
198 | case BIO_CTRL_DUP: | 199 | case BIO_CTRL_DUP: |
199 | case BIO_CTRL_FLUSH: | 200 | case BIO_CTRL_FLUSH: |
200 | ret=1; | 201 | ret = 1; |
201 | break; | 202 | break; |
202 | default: | 203 | default: |
203 | ret=0; | 204 | ret = 0; |
204 | break; | 205 | break; |
205 | } | ||
206 | return(ret); | ||
207 | } | 206 | } |
207 | return (ret); | ||
208 | } | ||
208 | 209 | ||
209 | static int sock_puts(BIO *bp, const char *str) | 210 | static int |
210 | { | 211 | sock_puts(BIO *bp, const char *str) |
211 | int n,ret; | 212 | { |
213 | int n, ret; | ||
212 | 214 | ||
213 | n=strlen(str); | 215 | n = strlen(str); |
214 | ret=sock_write(bp,str,n); | 216 | ret = sock_write(bp, str, n); |
215 | return(ret); | 217 | return (ret); |
216 | } | 218 | } |
217 | 219 | ||
218 | int BIO_sock_should_retry(int i) | 220 | int |
219 | { | 221 | BIO_sock_should_retry(int i) |
222 | { | ||
220 | int err; | 223 | int err; |
221 | 224 | ||
222 | if ((i == 0) || (i == -1)) | 225 | if ((i == 0) || (i == -1)) { |
223 | { | 226 | err = errno; |
224 | err=errno; | ||
225 | 227 | ||
226 | #if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */ | 228 | #if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */ |
227 | if ((i == -1) && (err == 0)) | 229 | if ((i == -1) && (err == 0)) |
228 | return(1); | 230 | return (1); |
229 | #endif | 231 | #endif |
230 | 232 | ||
231 | return(BIO_sock_non_fatal_error(err)); | 233 | return (BIO_sock_non_fatal_error(err)); |
232 | } | ||
233 | return(0); | ||
234 | } | 234 | } |
235 | return (0); | ||
236 | } | ||
235 | 237 | ||
236 | int BIO_sock_non_fatal_error(int err) | 238 | int |
237 | { | 239 | BIO_sock_non_fatal_error(int err) |
238 | switch (err) | 240 | { |
239 | { | 241 | switch (err) { |
240 | #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_NETWARE) | 242 | #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_NETWARE) |
241 | # if defined(WSAEWOULDBLOCK) | 243 | # if defined(WSAEWOULDBLOCK) |
242 | case WSAEWOULDBLOCK: | 244 | case WSAEWOULDBLOCK: |
@@ -284,12 +286,12 @@ int BIO_sock_non_fatal_error(int err) | |||
284 | #ifdef EALREADY | 286 | #ifdef EALREADY |
285 | case EALREADY: | 287 | case EALREADY: |
286 | #endif | 288 | #endif |
287 | return(1); | 289 | return (1); |
288 | /* break; */ | 290 | /* break; */ |
289 | default: | 291 | default: |
290 | break; | 292 | break; |
291 | } | ||
292 | return(0); | ||
293 | } | 293 | } |
294 | return (0); | ||
295 | } | ||
294 | 296 | ||
295 | #endif /* #ifndef OPENSSL_NO_SOCK */ | 297 | #endif /* #ifndef OPENSSL_NO_SOCK */ |