summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bio
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bio')
-rw-r--r--src/lib/libcrypto/bio/b_dump.c156
-rw-r--r--src/lib/libcrypto/bio/b_print.c829
-rw-r--r--src/lib/libcrypto/bio/b_sock.c740
-rw-r--r--src/lib/libcrypto/bio/bf_buff.c510
-rw-r--r--src/lib/libcrypto/bio/bf_lbuf.c397
-rw-r--r--src/lib/libcrypto/bio/bf_nbio.c255
-rw-r--r--src/lib/libcrypto/bio/bf_null.c183
-rw-r--r--src/lib/libcrypto/bio/bio.h693
-rw-r--r--src/lib/libcrypto/bio/bio_cb.c133
-rw-r--r--src/lib/libcrypto/bio/bio_err.c152
-rw-r--r--src/lib/libcrypto/bio/bio_lib.c543
-rw-r--r--src/lib/libcrypto/bio/bss_acpt.c479
-rw-r--r--src/lib/libcrypto/bio/bss_bio.c872
-rw-r--r--src/lib/libcrypto/bio/bss_conn.c652
-rw-r--r--src/lib/libcrypto/bio/bss_fd.c282
-rw-r--r--src/lib/libcrypto/bio/bss_file.c324
-rw-r--r--src/lib/libcrypto/bio/bss_log.c395
-rw-r--r--src/lib/libcrypto/bio/bss_mem.c317
-rw-r--r--src/lib/libcrypto/bio/bss_null.c150
-rw-r--r--src/lib/libcrypto/bio/bss_sock.c299
20 files changed, 0 insertions, 8361 deletions
diff --git a/src/lib/libcrypto/bio/b_dump.c b/src/lib/libcrypto/bio/b_dump.c
deleted file mode 100644
index 983604fb49..0000000000
--- a/src/lib/libcrypto/bio/b_dump.c
+++ /dev/null
@@ -1,156 +0,0 @@
1/* crypto/bio/b_dump.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/*
60 * Stolen from tjh's ssl/ssl_trc.c stuff.
61 */
62
63#include <stdio.h>
64#include "cryptlib.h"
65#include <openssl/bio.h>
66
67#define TRUNCATE
68#define DUMP_WIDTH 16
69#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH-((i-(i>6?6:i)+3)/4))
70
71int BIO_dump(BIO *bio, const char *s, int len)
72 {
73 return BIO_dump_indent(bio, s, len, 0);
74 }
75
76int BIO_dump_indent(BIO *bio, const char *s, int len, int indent)
77 {
78 int ret=0;
79 char buf[288+1],tmp[20],str[128+1];
80 int i,j,rows,trunc;
81 unsigned char ch;
82 int dump_width;
83
84 trunc=0;
85
86#ifdef TRUNCATE
87 for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--)
88 trunc++;
89#endif
90
91 if (indent < 0)
92 indent = 0;
93 if (indent)
94 {
95 if (indent > 128) indent=128;
96 memset(str,' ',indent);
97 }
98 str[indent]='\0';
99
100 dump_width=DUMP_WIDTH_LESS_INDENT(indent);
101 rows=(len/dump_width);
102 if ((rows*dump_width)<len)
103 rows++;
104 for(i=0;i<rows;i++)
105 {
106 buf[0]='\0'; /* start with empty string */
107 strlcpy(buf,str,sizeof buf);
108 snprintf(tmp,sizeof tmp,"%04x - ",i*dump_width);
109 strlcat(buf,tmp,sizeof buf);
110 for(j=0;j<dump_width;j++)
111 {
112 if (((i*dump_width)+j)>=len)
113 {
114 strlcat(buf," ",sizeof buf);
115 }
116 else
117 {
118 ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
119 snprintf(tmp,sizeof tmp,"%02x%c",ch,
120 j==7?'-':' ');
121 strlcat(buf,tmp,sizeof buf);
122 }
123 }
124 strlcat(buf," ",sizeof buf);
125 for(j=0;j<dump_width;j++)
126 {
127 if (((i*dump_width)+j)>=len)
128 break;
129 ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
130#ifndef CHARSET_EBCDIC
131 snprintf(tmp,sizeof tmp,"%c",
132 ((ch>=' ')&&(ch<='~'))?ch:'.');
133#else
134 snprintf(tmp,sizeof tmp,"%c",
135 ((ch>=os_toascii[' '])&&(ch<=os_toascii['~']))
136 ? os_toebcdic[ch]
137 : '.');
138#endif
139 strlcat(buf,tmp,sizeof buf);
140 }
141 strlcat(buf,"\n",sizeof buf);
142 /* if this is the last call then update the ddt_dump thing so that
143 * we will move the selection point in the debug window
144 */
145 ret+=BIO_write(bio,(char *)buf,strlen(buf));
146 }
147#ifdef TRUNCATE
148 if (trunc > 0)
149 {
150 snprintf(buf,sizeof buf,"%s%04x - <SPACES/NULS>\n",str,
151 len+trunc);
152 ret+=BIO_write(bio,(char *)buf,strlen(buf));
153 }
154#endif
155 return(ret);
156 }
diff --git a/src/lib/libcrypto/bio/b_print.c b/src/lib/libcrypto/bio/b_print.c
deleted file mode 100644
index 80c9cb69db..0000000000
--- a/src/lib/libcrypto/bio/b_print.c
+++ /dev/null
@@ -1,829 +0,0 @@
1/* crypto/bio/b_print.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* disable assert() unless BIO_DEBUG has been defined */
60#ifndef BIO_DEBUG
61# ifndef NDEBUG
62# define NDEBUG
63# endif
64#endif
65
66/*
67 * Stolen from tjh's ssl/ssl_trc.c stuff.
68 */
69
70#include <stdio.h>
71#include <string.h>
72#include <ctype.h>
73#include <assert.h>
74#include <limits.h>
75#include "cryptlib.h"
76#ifndef NO_SYS_TYPES_H
77#include <sys/types.h>
78#endif
79#include <openssl/bn.h> /* To get BN_LLONG properly defined */
80#include <openssl/bio.h>
81
82#ifdef BN_LLONG
83# ifndef HAVE_LONG_LONG
84# define HAVE_LONG_LONG 1
85# endif
86#endif
87
88/***************************************************************************/
89
90/*
91 * Copyright Patrick Powell 1995
92 * This code is based on code written by Patrick Powell <papowell@astart.com>
93 * It may be used for any purpose as long as this notice remains intact
94 * on all source code distributions.
95 */
96
97/*
98 * This code contains numerious changes and enhancements which were
99 * made by lots of contributors over the last years to Patrick Powell's
100 * original code:
101 *
102 * o Patrick Powell <papowell@astart.com> (1995)
103 * o Brandon Long <blong@fiction.net> (1996, for Mutt)
104 * o Thomas Roessler <roessler@guug.de> (1998, for Mutt)
105 * o Michael Elkins <me@cs.hmc.edu> (1998, for Mutt)
106 * o Andrew Tridgell <tridge@samba.org> (1998, for Samba)
107 * o Luke Mewburn <lukem@netbsd.org> (1999, for LukemFTP)
108 * o Ralf S. Engelschall <rse@engelschall.com> (1999, for Pth)
109 * o ... (for OpenSSL)
110 */
111
112#ifdef HAVE_LONG_DOUBLE
113#define LDOUBLE long double
114#else
115#define LDOUBLE double
116#endif
117
118#if HAVE_LONG_LONG
119# if defined(OPENSSL_SYS_WIN32) && !defined(__GNUC__)
120# define LLONG _int64
121# else
122# define LLONG long long
123# endif
124#else
125#define LLONG long
126#endif
127
128static void fmtstr (char **, char **, size_t *, size_t *,
129 const char *, int, int, int);
130static void fmtint (char **, char **, size_t *, size_t *,
131 LLONG, int, int, int, int);
132static void fmtfp (char **, char **, size_t *, size_t *,
133 LDOUBLE, int, int, int);
134static void doapr_outch (char **, char **, size_t *, size_t *, int);
135static void _dopr(char **sbuffer, char **buffer,
136 size_t *maxlen, size_t *retlen, int *truncated,
137 const char *format, va_list args);
138
139/* format read states */
140#define DP_S_DEFAULT 0
141#define DP_S_FLAGS 1
142#define DP_S_MIN 2
143#define DP_S_DOT 3
144#define DP_S_MAX 4
145#define DP_S_MOD 5
146#define DP_S_CONV 6
147#define DP_S_DONE 7
148
149/* format flags - Bits */
150#define DP_F_MINUS (1 << 0)
151#define DP_F_PLUS (1 << 1)
152#define DP_F_SPACE (1 << 2)
153#define DP_F_NUM (1 << 3)
154#define DP_F_ZERO (1 << 4)
155#define DP_F_UP (1 << 5)
156#define DP_F_UNSIGNED (1 << 6)
157
158/* conversion flags */
159#define DP_C_SHORT 1
160#define DP_C_LONG 2
161#define DP_C_LDOUBLE 3
162#define DP_C_LLONG 4
163
164/* some handy macros */
165#define char_to_int(p) (p - '0')
166#define OSSL_MAX(p,q) ((p >= q) ? p : q)
167
168static void
169_dopr(
170 char **sbuffer,
171 char **buffer,
172 size_t *maxlen,
173 size_t *retlen,
174 int *truncated,
175 const char *format,
176 va_list args)
177{
178 char ch;
179 LLONG value;
180 LDOUBLE fvalue;
181 char *strvalue;
182 int min;
183 int max;
184 int state;
185 int flags;
186 int cflags;
187 size_t currlen;
188
189 state = DP_S_DEFAULT;
190 flags = currlen = cflags = min = 0;
191 max = -1;
192 ch = *format++;
193
194 while (state != DP_S_DONE) {
195 if (ch == '\0' || (buffer == NULL && currlen >= *maxlen))
196 state = DP_S_DONE;
197
198 switch (state) {
199 case DP_S_DEFAULT:
200 if (ch == '%')
201 state = DP_S_FLAGS;
202 else
203 doapr_outch(sbuffer,buffer, &currlen, maxlen, ch);
204 ch = *format++;
205 break;
206 case DP_S_FLAGS:
207 switch (ch) {
208 case '-':
209 flags |= DP_F_MINUS;
210 ch = *format++;
211 break;
212 case '+':
213 flags |= DP_F_PLUS;
214 ch = *format++;
215 break;
216 case ' ':
217 flags |= DP_F_SPACE;
218 ch = *format++;
219 break;
220 case '#':
221 flags |= DP_F_NUM;
222 ch = *format++;
223 break;
224 case '0':
225 flags |= DP_F_ZERO;
226 ch = *format++;
227 break;
228 default:
229 state = DP_S_MIN;
230 break;
231 }
232 break;
233 case DP_S_MIN:
234 if (isdigit((unsigned char)ch)) {
235 min = 10 * min + char_to_int(ch);
236 ch = *format++;
237 } else if (ch == '*') {
238 min = va_arg(args, int);
239 ch = *format++;
240 state = DP_S_DOT;
241 } else
242 state = DP_S_DOT;
243 break;
244 case DP_S_DOT:
245 if (ch == '.') {
246 state = DP_S_MAX;
247 ch = *format++;
248 } else
249 state = DP_S_MOD;
250 break;
251 case DP_S_MAX:
252 if (isdigit((unsigned char)ch)) {
253 if (max < 0)
254 max = 0;
255 max = 10 * max + char_to_int(ch);
256 ch = *format++;
257 } else if (ch == '*') {
258 max = va_arg(args, int);
259 ch = *format++;
260 state = DP_S_MOD;
261 } else
262 state = DP_S_MOD;
263 break;
264 case DP_S_MOD:
265 switch (ch) {
266 case 'h':
267 cflags = DP_C_SHORT;
268 ch = *format++;
269 break;
270 case 'l':
271 if (*format == 'l') {
272 cflags = DP_C_LLONG;
273 format++;
274 } else
275 cflags = DP_C_LONG;
276 ch = *format++;
277 break;
278 case 'q':
279 cflags = DP_C_LLONG;
280 ch = *format++;
281 break;
282 case 'L':
283 cflags = DP_C_LDOUBLE;
284 ch = *format++;
285 break;
286 default:
287 break;
288 }
289 state = DP_S_CONV;
290 break;
291 case DP_S_CONV:
292 switch (ch) {
293 case 'd':
294 case 'i':
295 switch (cflags) {
296 case DP_C_SHORT:
297 value = (short int)va_arg(args, int);
298 break;
299 case DP_C_LONG:
300 value = va_arg(args, long int);
301 break;
302 case DP_C_LLONG:
303 value = va_arg(args, LLONG);
304 break;
305 default:
306 value = va_arg(args, int);
307 break;
308 }
309 fmtint(sbuffer, buffer, &currlen, maxlen,
310 value, 10, min, max, flags);
311 break;
312 case 'X':
313 flags |= DP_F_UP;
314 /* FALLTHROUGH */
315 case 'x':
316 case 'o':
317 case 'u':
318 flags |= DP_F_UNSIGNED;
319 switch (cflags) {
320 case DP_C_SHORT:
321 value = (unsigned short int)va_arg(args, unsigned int);
322 break;
323 case DP_C_LONG:
324 value = (LLONG) va_arg(args,
325 unsigned long int);
326 break;
327 case DP_C_LLONG:
328 value = va_arg(args, unsigned LLONG);
329 break;
330 default:
331 value = (LLONG) va_arg(args,
332 unsigned int);
333 break;
334 }
335 fmtint(sbuffer, buffer, &currlen, maxlen, value,
336 ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),
337 min, max, flags);
338 break;
339 case 'f':
340 if (cflags == DP_C_LDOUBLE)
341 fvalue = va_arg(args, LDOUBLE);
342 else
343 fvalue = va_arg(args, double);
344 fmtfp(sbuffer, buffer, &currlen, maxlen,
345 fvalue, min, max, flags);
346 break;
347 case 'E':
348 flags |= DP_F_UP;
349 case 'e':
350 if (cflags == DP_C_LDOUBLE)
351 fvalue = va_arg(args, LDOUBLE);
352 else
353 fvalue = va_arg(args, double);
354 break;
355 case 'G':
356 flags |= DP_F_UP;
357 case 'g':
358 if (cflags == DP_C_LDOUBLE)
359 fvalue = va_arg(args, LDOUBLE);
360 else
361 fvalue = va_arg(args, double);
362 break;
363 case 'c':
364 doapr_outch(sbuffer, buffer, &currlen, maxlen,
365 va_arg(args, int));
366 break;
367 case 's':
368 strvalue = va_arg(args, char *);
369 if (max < 0) {
370 if (buffer)
371 max = INT_MAX;
372 else
373 max = *maxlen;
374 }
375 fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,
376 flags, min, max);
377 break;
378 case 'p':
379 value = (long)va_arg(args, void *);
380 fmtint(sbuffer, buffer, &currlen, maxlen,
381 value, 16, min, max, flags);
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}
431
432static void
433fmtstr(
434 char **sbuffer,
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{
443 int padlen, strln;
444 int cnt = 0;
445
446 if (value == 0)
447 value = "<NULL>";
448 for (strln = 0; value[strln]; ++strln)
449 ;
450 padlen = min - strln;
451 if (padlen < 0)
452 padlen = 0;
453 if (flags & DP_F_MINUS)
454 padlen = -padlen;
455
456 while ((padlen > 0) && (cnt < max)) {
457 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
458 --padlen;
459 ++cnt;
460 }
461 while (*value && (cnt < max)) {
462 doapr_outch(sbuffer, buffer, currlen, maxlen, *value++);
463 ++cnt;
464 }
465 while ((padlen < 0) && (cnt < max)) {
466 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
467 ++padlen;
468 ++cnt;
469 }
470}
471
472static void
473fmtint(
474 char **sbuffer,
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{
484 int signvalue = 0;
485 unsigned LLONG uvalue;
486 char convert[20];
487 int place = 0;
488 int spadlen = 0;
489 int zpadlen = 0;
490 int caps = 0;
491
492 if (max < 0)
493 max = 0;
494 uvalue = value;
495 if (!(flags & DP_F_UNSIGNED)) {
496 if (value < 0) {
497 signvalue = '-';
498 uvalue = -value;
499 } else if (flags & DP_F_PLUS)
500 signvalue = '+';
501 else if (flags & DP_F_SPACE)
502 signvalue = ' ';
503 }
504 if (flags & DP_F_UP)
505 caps = 1;
506 do {
507 convert[place++] =
508 (caps ? "0123456789ABCDEF" : "0123456789abcdef")
509 [uvalue % (unsigned) base];
510 uvalue = (uvalue / (unsigned) base);
511 } while (uvalue && (place < 20));
512 if (place == 20)
513 place--;
514 convert[place] = 0;
515
516 zpadlen = max - place;
517 spadlen = min - OSSL_MAX(max, place) - (signvalue ? 1 : 0);
518 if (zpadlen < 0)
519 zpadlen = 0;
520 if (spadlen < 0)
521 spadlen = 0;
522 if (flags & DP_F_ZERO) {
523 zpadlen = OSSL_MAX(zpadlen, spadlen);
524 spadlen = 0;
525 }
526 if (flags & DP_F_MINUS)
527 spadlen = -spadlen;
528
529 /* spaces */
530 while (spadlen > 0) {
531 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
532 --spadlen;
533 }
534
535 /* sign */
536 if (signvalue)
537 doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
538
539 /* zeros */
540 if (zpadlen > 0) {
541 while (zpadlen > 0) {
542 doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
543 --zpadlen;
544 }
545 }
546 /* digits */
547 while (place > 0)
548 doapr_outch(sbuffer, buffer, currlen, maxlen, convert[--place]);
549
550 /* left justified spaces */
551 while (spadlen < 0) {
552 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
553 ++spadlen;
554 }
555 return;
556}
557
558static LDOUBLE
559abs_val(LDOUBLE value)
560{
561 LDOUBLE result = value;
562 if (value < 0)
563 result = -value;
564 return result;
565}
566
567static LDOUBLE
568pow10(int exp)
569{
570 LDOUBLE result = 1;
571 while (exp) {
572 result *= 10;
573 exp--;
574 }
575 return result;
576}
577
578static long
579roundv(LDOUBLE value)
580{
581 long intpart;
582 intpart = (long) value;
583 value = value - intpart;
584 if (value >= 0.5)
585 intpart++;
586 return intpart;
587}
588
589static void
590fmtfp(
591 char **sbuffer,
592 char **buffer,
593 size_t *currlen,
594 size_t *maxlen,
595 LDOUBLE fvalue,
596 int min,
597 int max,
598 int flags)
599{
600 int signvalue = 0;
601 LDOUBLE ufvalue;
602 char iconvert[20];
603 char fconvert[20];
604 int iplace = 0;
605 int fplace = 0;
606 int padlen = 0;
607 int zpadlen = 0;
608 int caps = 0;
609 long intpart;
610 long fracpart;
611
612 if (max < 0)
613 max = 6;
614 ufvalue = abs_val(fvalue);
615 if (fvalue < 0)
616 signvalue = '-';
617 else if (flags & DP_F_PLUS)
618 signvalue = '+';
619 else if (flags & DP_F_SPACE)
620 signvalue = ' ';
621
622 intpart = (long)ufvalue;
623
624 /* sorry, we only support 9 digits past the decimal because of our
625 conversion method */
626 if (max > 9)
627 max = 9;
628
629 /* we "cheat" by converting the fractional part to integer by
630 multiplying by a factor of 10 */
631 fracpart = roundv((pow10(max)) * (ufvalue - intpart));
632
633 if (fracpart >= pow10(max)) {
634 intpart++;
635 fracpart -= (long)pow10(max);
636 }
637
638 /* convert integer part */
639 do {
640 iconvert[iplace++] =
641 (caps ? "0123456789ABCDEF"
642 : "0123456789abcdef")[intpart % 10];
643 intpart = (intpart / 10);
644 } while (intpart && (iplace < 20));
645 if (iplace == 20)
646 iplace--;
647 iconvert[iplace] = 0;
648
649 /* convert fractional part */
650 do {
651 fconvert[fplace++] =
652 (caps ? "0123456789ABCDEF"
653 : "0123456789abcdef")[fracpart % 10];
654 fracpart = (fracpart / 10);
655 } while (fplace < max);
656 if (fplace == 20)
657 fplace--;
658 fconvert[fplace] = 0;
659
660 /* -1 for decimal point, another -1 if we are printing a sign */
661 padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
662 zpadlen = max - fplace;
663 if (zpadlen < 0)
664 zpadlen = 0;
665 if (padlen < 0)
666 padlen = 0;
667 if (flags & DP_F_MINUS)
668 padlen = -padlen;
669
670 if ((flags & DP_F_ZERO) && (padlen > 0)) {
671 if (signvalue) {
672 doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
673 --padlen;
674 signvalue = 0;
675 }
676 while (padlen > 0) {
677 doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
678 --padlen;
679 }
680 }
681 while (padlen > 0) {
682 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
683 --padlen;
684 }
685 if (signvalue)
686 doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
687
688 while (iplace > 0)
689 doapr_outch(sbuffer, buffer, currlen, maxlen, iconvert[--iplace]);
690
691 /*
692 * Decimal point. This should probably use locale to find the correct
693 * char to print out.
694 */
695 if (max > 0) {
696 doapr_outch(sbuffer, buffer, currlen, maxlen, '.');
697
698 while (fplace > 0)
699 doapr_outch(sbuffer, buffer, currlen, maxlen, fconvert[--fplace]);
700 }
701 while (zpadlen > 0) {
702 doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
703 --zpadlen;
704 }
705
706 while (padlen < 0) {
707 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
708 ++padlen;
709 }
710}
711
712static void
713doapr_outch(
714 char **sbuffer,
715 char **buffer,
716 size_t *currlen,
717 size_t *maxlen,
718 int c)
719{
720 /* If we haven't at least one buffer, someone has doe a big booboo */
721 assert(*sbuffer != NULL || buffer != NULL);
722
723 if (buffer) {
724 while (*currlen >= *maxlen) {
725 if (*buffer == NULL) {
726 if (*maxlen == 0)
727 *maxlen = 1024;
728 *buffer = OPENSSL_malloc(*maxlen);
729 if (*currlen > 0) {
730 assert(*sbuffer != NULL);
731 memcpy(*buffer, *sbuffer, *currlen);
732 }
733 *sbuffer = NULL;
734 } else {
735 *maxlen += 1024;
736 *buffer = OPENSSL_realloc(*buffer, *maxlen);
737 }
738 }
739 /* What to do if *buffer is NULL? */
740 assert(*sbuffer != NULL || *buffer != NULL);
741 }
742
743 if (*currlen < *maxlen) {
744 if (*sbuffer)
745 (*sbuffer)[(*currlen)++] = (char)c;
746 else
747 (*buffer)[(*currlen)++] = (char)c;
748 }
749
750 return;
751}
752
753/***************************************************************************/
754
755int BIO_printf (BIO *bio, const char *format, ...)
756 {
757 va_list args;
758 int ret;
759
760 va_start(args, format);
761
762 ret = BIO_vprintf(bio, format, args);
763
764 va_end(args);
765 return(ret);
766 }
767
768int BIO_vprintf (BIO *bio, const char *format, va_list args)
769 {
770 int ret;
771 size_t retlen;
772 char hugebuf[1024*2]; /* Was previously 10k, which is unreasonable
773 in small-stack environments, like threads
774 or DOS programs. */
775 char *hugebufp = hugebuf;
776 size_t hugebufsize = sizeof(hugebuf);
777 char *dynbuf = NULL;
778 int ignored;
779
780 dynbuf = NULL;
781 CRYPTO_push_info("doapr()");
782 _dopr(&hugebufp, &dynbuf, &hugebufsize,
783 &retlen, &ignored, format, args);
784 if (dynbuf)
785 {
786 ret=BIO_write(bio, dynbuf, (int)retlen);
787 OPENSSL_free(dynbuf);
788 }
789 else
790 {
791 ret=BIO_write(bio, hugebuf, (int)retlen);
792 }
793 CRYPTO_pop_info();
794 return(ret);
795 }
796
797/* As snprintf is not available everywhere, we provide our own implementation.
798 * This function has nothing to do with BIOs, but it's closely related
799 * to BIO_printf, and we need *some* name prefix ...
800 * (XXX the function should be renamed, but to what?) */
801int BIO_snprintf(char *buf, size_t n, const char *format, ...)
802 {
803 va_list args;
804 int ret;
805
806 va_start(args, format);
807
808 ret = BIO_vsnprintf(buf, n, format, args);
809
810 va_end(args);
811 return(ret);
812 }
813
814int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
815 {
816 size_t retlen;
817 int truncated;
818
819 _dopr(&buf, NULL, &n, &retlen, &truncated, format, args);
820
821 if (truncated)
822 /* In case of truncation, return -1 like traditional snprintf.
823 * (Current drafts for ISO/IEC 9899 say snprintf should return
824 * the number of characters that would have been written,
825 * had the buffer been large enough.) */
826 return -1;
827 else
828 return (retlen <= INT_MAX) ? retlen : -1;
829 }
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c
deleted file mode 100644
index 45bd7c47e8..0000000000
--- a/src/lib/libcrypto/bio/b_sock.c
+++ /dev/null
@@ -1,740 +0,0 @@
1/* crypto/bio/b_sock.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_SOCK
60
61#include <stdio.h>
62#include <stdlib.h>
63#include <errno.h>
64#define USE_SOCKETS
65#include "cryptlib.h"
66#include <openssl/bio.h>
67
68#ifdef OPENSSL_SYS_WIN16
69#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
70#else
71#define SOCKET_PROTOCOL IPPROTO_TCP
72#endif
73
74#ifdef SO_MAXCONN
75#define MAX_LISTEN SO_MAXCONN
76#elif defined(SOMAXCONN)
77#define MAX_LISTEN SOMAXCONN
78#else
79#define MAX_LISTEN 32
80#endif
81
82#ifdef OPENSSL_SYS_WINDOWS
83static int wsa_init_done=0;
84#endif
85
86static unsigned long BIO_ghbn_hits=0L;
87static unsigned long BIO_ghbn_miss=0L;
88
89#define GHBN_NUM 4
90static struct ghbn_cache_st
91 {
92 char name[129];
93 struct hostent *ent;
94 unsigned long order;
95 } ghbn_cache[GHBN_NUM];
96
97static int get_ip(const char *str,unsigned char *ip);
98#if 0
99static void ghbn_free(struct hostent *a);
100static struct hostent *ghbn_dup(struct hostent *a);
101#endif
102int BIO_get_host_ip(const char *str, unsigned char *ip)
103 {
104 int i;
105 int err = 1;
106 int locked = 0;
107 struct hostent *he;
108
109 i=get_ip(str,ip);
110 if (i < 0)
111 {
112 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_INVALID_IP_ADDRESS);
113 goto err;
114 }
115
116 /* At this point, we have something that is most probably correct
117 in some way, so let's init the socket. */
118 if (BIO_sock_init() != 1)
119 return 0; /* don't generate another error code here */
120
121 /* If the string actually contained an IP address, we need not do
122 anything more */
123 if (i > 0) return(1);
124
125 /* do a gethostbyname */
126 CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
127 locked = 1;
128 he=BIO_gethostbyname(str);
129 if (he == NULL)
130 {
131 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_BAD_HOSTNAME_LOOKUP);
132 goto err;
133 }
134
135 /* cast to short because of win16 winsock definition */
136 if ((short)he->h_addrtype != AF_INET)
137 {
138 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET);
139 goto err;
140 }
141 for (i=0; i<4; i++)
142 ip[i]=he->h_addr_list[0][i];
143 err = 0;
144
145 err:
146 if (locked)
147 CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME);
148 if (err)
149 {
150 ERR_add_error_data(2,"host=",str);
151 return 0;
152 }
153 else
154 return 1;
155 }
156
157int BIO_get_port(const char *str, unsigned short *port_ptr)
158 {
159 int i;
160 struct servent *s;
161
162 if (str == NULL)
163 {
164 BIOerr(BIO_F_BIO_GET_PORT,BIO_R_NO_PORT_DEFINED);
165 return(0);
166 }
167 i=atoi(str);
168 if (i != 0)
169 *port_ptr=(unsigned short)i;
170 else
171 {
172 CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME);
173 /* Note: under VMS with SOCKETSHR, it seems like the first
174 * parameter is 'char *', instead of 'const char *'
175 */
176 s=getservbyname(
177#ifndef CONST_STRICT
178 (char *)
179#endif
180 str,"tcp");
181 if(s != NULL)
182 *port_ptr=ntohs((unsigned short)s->s_port);
183 CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME);
184 if(s == NULL)
185 {
186 if (strcmp(str,"http") == 0)
187 *port_ptr=80;
188 else if (strcmp(str,"telnet") == 0)
189 *port_ptr=23;
190 else if (strcmp(str,"socks") == 0)
191 *port_ptr=1080;
192 else if (strcmp(str,"https") == 0)
193 *port_ptr=443;
194 else if (strcmp(str,"ssl") == 0)
195 *port_ptr=443;
196 else if (strcmp(str,"ftp") == 0)
197 *port_ptr=21;
198 else if (strcmp(str,"gopher") == 0)
199 *port_ptr=70;
200#if 0
201 else if (strcmp(str,"wais") == 0)
202 *port_ptr=21;
203#endif
204 else
205 {
206 SYSerr(SYS_F_GETSERVBYNAME,get_last_socket_error());
207 ERR_add_error_data(3,"service='",str,"'");
208 return(0);
209 }
210 }
211 }
212 return(1);
213 }
214
215int BIO_sock_error(int sock)
216 {
217 int j,i;
218 int size;
219
220 size=sizeof(int);
221 /* Note: under Windows the third parameter is of type (char *)
222 * whereas under other systems it is (void *) if you don't have
223 * a cast it will choke the compiler: if you do have a cast then
224 * you can either go for (char *) or (void *).
225 */
226 i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(void *)&j,(void *)&size);
227 if (i < 0)
228 return(1);
229 else
230 return(j);
231 }
232
233long BIO_ghbn_ctrl(int cmd, int iarg, char *parg)
234 {
235 int i;
236 char **p;
237
238 switch (cmd)
239 {
240 case BIO_GHBN_CTRL_HITS:
241 return(BIO_ghbn_hits);
242 /* break; */
243 case BIO_GHBN_CTRL_MISSES:
244 return(BIO_ghbn_miss);
245 /* break; */
246 case BIO_GHBN_CTRL_CACHE_SIZE:
247 return(GHBN_NUM);
248 /* break; */
249 case BIO_GHBN_CTRL_GET_ENTRY:
250 if ((iarg >= 0) && (iarg <GHBN_NUM) &&
251 (ghbn_cache[iarg].order > 0))
252 {
253 p=(char **)parg;
254 if (p == NULL) return(0);
255 *p=ghbn_cache[iarg].name;
256 ghbn_cache[iarg].name[128]='\0';
257 return(1);
258 }
259 return(0);
260 /* break; */
261 case BIO_GHBN_CTRL_FLUSH:
262 for (i=0; i<GHBN_NUM; i++)
263 ghbn_cache[i].order=0;
264 break;
265 default:
266 return(0);
267 }
268 return(1);
269 }
270
271#if 0
272static struct hostent *ghbn_dup(struct hostent *a)
273 {
274 struct hostent *ret;
275 int i,j;
276
277 MemCheck_off();
278 ret=(struct hostent *)OPENSSL_malloc(sizeof(struct hostent));
279 if (ret == NULL) return(NULL);
280 memset(ret,0,sizeof(struct hostent));
281
282 for (i=0; a->h_aliases[i] != NULL; i++)
283 ;
284 i++;
285 ret->h_aliases = (char **)OPENSSL_malloc(i*sizeof(char *));
286 if (ret->h_aliases == NULL)
287 goto err;
288 memset(ret->h_aliases, 0, i*sizeof(char *));
289
290 for (i=0; a->h_addr_list[i] != NULL; i++)
291 ;
292 i++;
293 ret->h_addr_list=(char **)OPENSSL_malloc(i*sizeof(char *));
294 if (ret->h_addr_list == NULL)
295 goto err;
296 memset(ret->h_addr_list, 0, i*sizeof(char *));
297
298 j=strlen(a->h_name)+1;
299 if ((ret->h_name=OPENSSL_malloc(j)) == NULL) goto err;
300 memcpy((char *)ret->h_name,a->h_name,j);
301 for (i=0; a->h_aliases[i] != NULL; i++)
302 {
303 j=strlen(a->h_aliases[i])+1;
304 if ((ret->h_aliases[i]=OPENSSL_malloc(j)) == NULL) goto err;
305 memcpy(ret->h_aliases[i],a->h_aliases[i],j);
306 }
307 ret->h_length=a->h_length;
308 ret->h_addrtype=a->h_addrtype;
309 for (i=0; a->h_addr_list[i] != NULL; i++)
310 {
311 if ((ret->h_addr_list[i]=OPENSSL_malloc(a->h_length)) == NULL)
312 goto err;
313 memcpy(ret->h_addr_list[i],a->h_addr_list[i],a->h_length);
314 }
315 if (0)
316 {
317err:
318 if (ret != NULL)
319 ghbn_free(ret);
320 ret=NULL;
321 }
322 MemCheck_on();
323 return(ret);
324 }
325
326static void ghbn_free(struct hostent *a)
327 {
328 int i;
329
330 if(a == NULL)
331 return;
332
333 if (a->h_aliases != NULL)
334 {
335 for (i=0; a->h_aliases[i] != NULL; i++)
336 OPENSSL_free(a->h_aliases[i]);
337 OPENSSL_free(a->h_aliases);
338 }
339 if (a->h_addr_list != NULL)
340 {
341 for (i=0; a->h_addr_list[i] != NULL; i++)
342 OPENSSL_free(a->h_addr_list[i]);
343 OPENSSL_free(a->h_addr_list);
344 }
345 if (a->h_name != NULL) OPENSSL_free(a->h_name);
346 OPENSSL_free(a);
347 }
348
349#endif
350
351struct hostent *BIO_gethostbyname(const char *name)
352 {
353#if 1
354 /* Caching gethostbyname() results forever is wrong,
355 * so we have to let the true gethostbyname() worry about this */
356 return gethostbyname(name);
357#else
358 struct hostent *ret;
359 int i,lowi=0,j;
360 unsigned long low= (unsigned long)-1;
361
362
363# if 0
364 /* It doesn't make sense to use locking here: The function interface
365 * is not thread-safe, because threads can never be sure when
366 * some other thread destroys the data they were given a pointer to.
367 */
368 CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
369# endif
370 j=strlen(name);
371 if (j < 128)
372 {
373 for (i=0; i<GHBN_NUM; i++)
374 {
375 if (low > ghbn_cache[i].order)
376 {
377 low=ghbn_cache[i].order;
378 lowi=i;
379 }
380 if (ghbn_cache[i].order > 0)
381 {
382 if (strncmp(name,ghbn_cache[i].name,128) == 0)
383 break;
384 }
385 }
386 }
387 else
388 i=GHBN_NUM;
389
390 if (i == GHBN_NUM) /* no hit*/
391 {
392 BIO_ghbn_miss++;
393 /* Note: under VMS with SOCKETSHR, it seems like the first
394 * parameter is 'char *', instead of 'const char *'
395 */
396 ret=gethostbyname(
397# ifndef CONST_STRICT
398 (char *)
399# endif
400 name);
401
402 if (ret == NULL)
403 goto end;
404 if (j > 128) /* too big to cache */
405 {
406# if 0
407 /* If we were trying to make this function thread-safe (which
408 * is bound to fail), we'd have to give up in this case
409 * (or allocate more memory). */
410 ret = NULL;
411# endif
412 goto end;
413 }
414
415 /* else add to cache */
416 if (ghbn_cache[lowi].ent != NULL)
417 ghbn_free(ghbn_cache[lowi].ent); /* XXX not thread-safe */
418 ghbn_cache[lowi].name[0] = '\0';
419
420 if((ret=ghbn_cache[lowi].ent=ghbn_dup(ret)) == NULL)
421 {
422 BIOerr(BIO_F_BIO_GETHOSTBYNAME,ERR_R_MALLOC_FAILURE);
423 goto end;
424 }
425 strncpy(ghbn_cache[lowi].name,name,128);
426 ghbn_cache[lowi].order=BIO_ghbn_miss+BIO_ghbn_hits;
427 }
428 else
429 {
430 BIO_ghbn_hits++;
431 ret= ghbn_cache[i].ent;
432 ghbn_cache[i].order=BIO_ghbn_miss+BIO_ghbn_hits;
433 }
434end:
435# if 0
436 CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME);
437# endif
438 return(ret);
439#endif
440 }
441
442
443int BIO_sock_init(void)
444 {
445#ifdef OPENSSL_SYS_WINDOWS
446 static struct WSAData wsa_state;
447
448 if (!wsa_init_done)
449 {
450 int err;
451
452#ifdef SIGINT
453 signal(SIGINT,(void (*)(int))BIO_sock_cleanup);
454#endif
455 wsa_init_done=1;
456 memset(&wsa_state,0,sizeof(wsa_state));
457 if (WSAStartup(0x0101,&wsa_state)!=0)
458 {
459 err=WSAGetLastError();
460 SYSerr(SYS_F_WSASTARTUP,err);
461 BIOerr(BIO_F_BIO_SOCK_INIT,BIO_R_WSASTARTUP);
462 return(-1);
463 }
464 }
465#endif /* OPENSSL_SYS_WINDOWS */
466 return(1);
467 }
468
469void BIO_sock_cleanup(void)
470 {
471#ifdef OPENSSL_SYS_WINDOWS
472 if (wsa_init_done)
473 {
474 wsa_init_done=0;
475 WSACancelBlockingCall();
476 WSACleanup();
477 }
478#endif
479 }
480
481#if !defined(OPENSSL_SYS_VMS) || __VMS_VER >= 70000000
482
483int BIO_socket_ioctl(int fd, long type, unsigned long *arg)
484 {
485 int i;
486
487#ifdef __DJGPP__
488 i=ioctlsocket(fd,type,(char *)arg);
489#else
490 i=ioctlsocket(fd,type,arg);
491#endif /* __DJGPP__ */
492 if (i < 0)
493 SYSerr(SYS_F_IOCTLSOCKET,get_last_socket_error());
494 return(i);
495 }
496#endif /* __VMS_VER */
497
498/* The reason I have implemented this instead of using sscanf is because
499 * Visual C 1.52c gives an unresolved external when linking a DLL :-( */
500static int get_ip(const char *str, unsigned char ip[4])
501 {
502 unsigned int tmp[4];
503 int num=0,c,ok=0;
504
505 tmp[0]=tmp[1]=tmp[2]=tmp[3]=0;
506
507 for (;;)
508 {
509 c= *(str++);
510 if ((c >= '0') && (c <= '9'))
511 {
512 ok=1;
513 tmp[num]=tmp[num]*10+c-'0';
514 if (tmp[num] > 255) return(0);
515 }
516 else if (c == '.')
517 {
518 if (!ok) return(-1);
519 if (num == 3) return(0);
520 num++;
521 ok=0;
522 }
523 else if (c == '\0' && (num == 3) && ok)
524 break;
525 else
526 return(0);
527 }
528 ip[0]=tmp[0];
529 ip[1]=tmp[1];
530 ip[2]=tmp[2];
531 ip[3]=tmp[3];
532 return(1);
533 }
534
535int BIO_get_accept_socket(char *host, int bind_mode)
536 {
537 int ret=0;
538 struct sockaddr_in server,client;
539 int s=INVALID_SOCKET,cs;
540 unsigned char ip[4];
541 unsigned short port;
542 char *str=NULL,*e;
543 const char *h,*p;
544 unsigned long l;
545 int err_num;
546
547 if (BIO_sock_init() != 1) return(INVALID_SOCKET);
548
549 if ((str=BUF_strdup(host)) == NULL) return(INVALID_SOCKET);
550
551 h=p=NULL;
552 h=str;
553 for (e=str; *e; e++)
554 {
555 if (*e == ':')
556 {
557 p= &(e[1]);
558 *e='\0';
559 }
560 else if (*e == '/')
561 {
562 *e='\0';
563 break;
564 }
565 }
566
567 if (p == NULL)
568 {
569 p=h;
570 h="*";
571 }
572
573 if (!BIO_get_port(p,&port)) goto err;
574
575 memset((char *)&server,0,sizeof(server));
576 server.sin_family=AF_INET;
577 server.sin_port=htons(port);
578
579 if (strcmp(h,"*") == 0)
580 server.sin_addr.s_addr=INADDR_ANY;
581 else
582 {
583 if (!BIO_get_host_ip(h,&(ip[0]))) goto err;
584 l=(unsigned long)
585 ((unsigned long)ip[0]<<24L)|
586 ((unsigned long)ip[1]<<16L)|
587 ((unsigned long)ip[2]<< 8L)|
588 ((unsigned long)ip[3]);
589 server.sin_addr.s_addr=htonl(l);
590 }
591
592again:
593 s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
594 if (s == INVALID_SOCKET)
595 {
596 SYSerr(SYS_F_SOCKET,get_last_socket_error());
597 ERR_add_error_data(3,"port='",host,"'");
598 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_CREATE_SOCKET);
599 goto err;
600 }
601
602#ifdef SO_REUSEADDR
603 if (bind_mode == BIO_BIND_REUSEADDR)
604 {
605 int i=1;
606
607 ret=setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&i,sizeof(i));
608 bind_mode=BIO_BIND_NORMAL;
609 }
610#endif
611 if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1)
612 {
613#ifdef SO_REUSEADDR
614 err_num=get_last_socket_error();
615 if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) &&
616 (err_num == EADDRINUSE))
617 {
618 memcpy((char *)&client,(char *)&server,sizeof(server));
619 if (strcmp(h,"*") == 0)
620 client.sin_addr.s_addr=htonl(0x7F000001);
621 cs=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
622 if (cs != INVALID_SOCKET)
623 {
624 int ii;
625 ii=connect(cs,(struct sockaddr *)&client,
626 sizeof(client));
627 closesocket(cs);
628 if (ii == INVALID_SOCKET)
629 {
630 bind_mode=BIO_BIND_REUSEADDR;
631 closesocket(s);
632 goto again;
633 }
634 /* else error */
635 }
636 /* else error */
637 }
638#endif
639 SYSerr(SYS_F_BIND,err_num);
640 ERR_add_error_data(3,"port='",host,"'");
641 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_BIND_SOCKET);
642 goto err;
643 }
644 if (listen(s,MAX_LISTEN) == -1)
645 {
646 SYSerr(SYS_F_BIND,get_last_socket_error());
647 ERR_add_error_data(3,"port='",host,"'");
648 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_LISTEN_SOCKET);
649 goto err;
650 }
651 ret=1;
652err:
653 if (str != NULL) OPENSSL_free(str);
654 if ((ret == 0) && (s != INVALID_SOCKET))
655 {
656 closesocket(s);
657 s= INVALID_SOCKET;
658 }
659 return(s);
660 }
661
662int BIO_accept(int sock, char **addr)
663 {
664 int ret=INVALID_SOCKET;
665 static struct sockaddr_in from;
666 unsigned long l;
667 unsigned short port;
668 int len;
669 char *p;
670
671 memset((char *)&from,0,sizeof(from));
672 len=sizeof(from);
673 /* Note: under VMS with SOCKETSHR the fourth parameter is currently
674 * of type (int *) whereas under other systems it is (void *) if
675 * you don't have a cast it will choke the compiler: if you do
676 * have a cast then you can either go for (int *) or (void *).
677 */
678 ret=accept(sock,(struct sockaddr *)&from,(void *)&len);
679 if (ret == INVALID_SOCKET)
680 {
681 if(BIO_sock_should_retry(ret)) return -2;
682 SYSerr(SYS_F_ACCEPT,get_last_socket_error());
683 BIOerr(BIO_F_BIO_ACCEPT,BIO_R_ACCEPT_ERROR);
684 goto end;
685 }
686
687 if (addr == NULL) goto end;
688
689 l=ntohl(from.sin_addr.s_addr);
690 port=ntohs(from.sin_port);
691 if (*addr == NULL)
692 {
693 if ((p=OPENSSL_malloc(24)) == NULL)
694 {
695 BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE);
696 goto end;
697 }
698 *addr=p;
699 }
700 sprintf(*addr,"%d.%d.%d.%d:%d",
701 (unsigned char)(l>>24L)&0xff,
702 (unsigned char)(l>>16L)&0xff,
703 (unsigned char)(l>> 8L)&0xff,
704 (unsigned char)(l )&0xff,
705 port);
706end:
707 return(ret);
708 }
709
710int BIO_set_tcp_ndelay(int s, int on)
711 {
712 int ret=0;
713#if defined(TCP_NODELAY) && (defined(IPPROTO_TCP) || defined(SOL_TCP))
714 int opt;
715
716#ifdef SOL_TCP
717 opt=SOL_TCP;
718#else
719#ifdef IPPROTO_TCP
720 opt=IPPROTO_TCP;
721#endif
722#endif
723
724 ret=setsockopt(s,opt,TCP_NODELAY,(char *)&on,sizeof(on));
725#endif
726 return(ret == 0);
727 }
728#endif
729
730int BIO_socket_nbio(int s, int mode)
731 {
732 int ret= -1;
733 unsigned long l;
734
735 l=mode;
736#ifdef FIONBIO
737 ret=BIO_socket_ioctl(s,FIONBIO,&l);
738#endif
739 return(ret == 0);
740 }
diff --git a/src/lib/libcrypto/bio/bf_buff.c b/src/lib/libcrypto/bio/bf_buff.c
deleted file mode 100644
index 6ccda06596..0000000000
--- a/src/lib/libcrypto/bio/bf_buff.c
+++ /dev/null
@@ -1,510 +0,0 @@
1/* crypto/bio/bf_buff.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/bio.h>
63
64static int buffer_write(BIO *h, const char *buf,int num);
65static int buffer_read(BIO *h, char *buf, int size);
66static int buffer_puts(BIO *h, const char *str);
67static int buffer_gets(BIO *h, char *str, int size);
68static long buffer_ctrl(BIO *h, int cmd, long arg1, void *arg2);
69static int buffer_new(BIO *h);
70static int buffer_free(BIO *data);
71static long buffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
72#define DEFAULT_BUFFER_SIZE 4096
73
74static BIO_METHOD methods_buffer=
75 {
76 BIO_TYPE_BUFFER,
77 "buffer",
78 buffer_write,
79 buffer_read,
80 buffer_puts,
81 buffer_gets,
82 buffer_ctrl,
83 buffer_new,
84 buffer_free,
85 buffer_callback_ctrl,
86 };
87
88BIO_METHOD *BIO_f_buffer(void)
89 {
90 return(&methods_buffer);
91 }
92
93static int buffer_new(BIO *bi)
94 {
95 BIO_F_BUFFER_CTX *ctx;
96
97 ctx=(BIO_F_BUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_F_BUFFER_CTX));
98 if (ctx == NULL) return(0);
99 ctx->ibuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
100 if (ctx->ibuf == NULL) { OPENSSL_free(ctx); return(0); }
101 ctx->obuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
102 if (ctx->obuf == NULL) { OPENSSL_free(ctx->ibuf); OPENSSL_free(ctx); return(0); }
103 ctx->ibuf_size=DEFAULT_BUFFER_SIZE;
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 }
115
116static int buffer_free(BIO *a)
117 {
118 BIO_F_BUFFER_CTX *b;
119
120 if (a == NULL) return(0);
121 b=(BIO_F_BUFFER_CTX *)a->ptr;
122 if (b->ibuf != NULL) OPENSSL_free(b->ibuf);
123 if (b->obuf != NULL) OPENSSL_free(b->obuf);
124 OPENSSL_free(a->ptr);
125 a->ptr=NULL;
126 a->init=0;
127 a->flags=0;
128 return(1);
129 }
130
131static int buffer_read(BIO *b, char *out, int outl)
132 {
133 int i,num=0;
134 BIO_F_BUFFER_CTX *ctx;
135
136 if (out == NULL) return(0);
137 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
138
139 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
140 num=0;
141 BIO_clear_retry_flags(b);
142
143start:
144 i=ctx->ibuf_len;
145 /* If there is stuff left over, grab it */
146 if (i != 0)
147 {
148 if (i > outl) i=outl;
149 memcpy(out,&(ctx->ibuf[ctx->ibuf_off]),i);
150 ctx->ibuf_off+=i;
151 ctx->ibuf_len-=i;
152 num+=i;
153 if (outl == i) return(num);
154 outl-=i;
155 out+=i;
156 }
157
158 /* We may have done a partial read. try to do more.
159 * We have nothing in the buffer.
160 * If we get an error and have read some data, just return it
161 * and let them retry to get the error again.
162 * copy direct to parent address space */
163 if (outl > ctx->ibuf_size)
164 {
165 for (;;)
166 {
167 i=BIO_read(b->next_bio,out,outl);
168 if (i <= 0)
169 {
170 BIO_copy_next_retry(b);
171 if (i < 0) return((num > 0)?num:i);
172 if (i == 0) return(num);
173 }
174 num+=i;
175 if (outl == i) return(num);
176 out+=i;
177 outl-=i;
178 }
179 }
180 /* else */
181
182 /* we are going to be doing some buffering */
183 i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size);
184 if (i <= 0)
185 {
186 BIO_copy_next_retry(b);
187 if (i < 0) return((num > 0)?num:i);
188 if (i == 0) return(num);
189 }
190 ctx->ibuf_off=0;
191 ctx->ibuf_len=i;
192
193 /* Lets re-read using ourselves :-) */
194 goto start;
195 }
196
197static int buffer_write(BIO *b, const char *in, int inl)
198 {
199 int i,num=0;
200 BIO_F_BUFFER_CTX *ctx;
201
202 if ((in == NULL) || (inl <= 0)) return(0);
203 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
204 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
205
206 BIO_clear_retry_flags(b);
207start:
208 i=ctx->obuf_size-(ctx->obuf_len+ctx->obuf_off);
209 /* add to buffer and return */
210 if (i >= inl)
211 {
212 memcpy(&(ctx->obuf[ctx->obuf_len]),in,inl);
213 ctx->obuf_len+=inl;
214 return(num+inl);
215 }
216 /* else */
217 /* stuff already in buffer, so add to it first, then flush */
218 if (ctx->obuf_len != 0)
219 {
220 if (i > 0) /* lets fill it up if we can */
221 {
222 memcpy(&(ctx->obuf[ctx->obuf_len]),in,i);
223 in+=i;
224 inl-=i;
225 num+=i;
226 ctx->obuf_len+=i;
227 }
228 /* we now have a full buffer needing flushing */
229 for (;;)
230 {
231 i=BIO_write(b->next_bio,&(ctx->obuf[ctx->obuf_off]),
232 ctx->obuf_len);
233 if (i <= 0)
234 {
235 BIO_copy_next_retry(b);
236
237 if (i < 0) return((num > 0)?num:i);
238 if (i == 0) return(num);
239 }
240 ctx->obuf_off+=i;
241 ctx->obuf_len-=i;
242 if (ctx->obuf_len == 0) break;
243 }
244 }
245 /* we only get here if the buffer has been flushed and we
246 * still have stuff to write */
247 ctx->obuf_off=0;
248
249 /* we now have inl bytes to write */
250 while (inl >= ctx->obuf_size)
251 {
252 i=BIO_write(b->next_bio,in,inl);
253 if (i <= 0)
254 {
255 BIO_copy_next_retry(b);
256 if (i < 0) return((num > 0)?num:i);
257 if (i == 0) return(num);
258 }
259 num+=i;
260 in+=i;
261 inl-=i;
262 if (inl == 0) return(num);
263 }
264
265 /* copy the rest into the buffer since we have only a small
266 * amount left */
267 goto start;
268 }
269
270static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
271 {
272 BIO *dbio;
273 BIO_F_BUFFER_CTX *ctx;
274 long ret=1;
275 char *p1,*p2;
276 int r,i,*ip;
277 int ibs,obs;
278
279 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
280
281 switch (cmd)
282 {
283 case BIO_CTRL_RESET:
284 ctx->ibuf_off=0;
285 ctx->ibuf_len=0;
286 ctx->obuf_off=0;
287 ctx->obuf_len=0;
288 if (b->next_bio == NULL) return(0);
289 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
290 break;
291 case BIO_CTRL_INFO:
292 ret=(long)ctx->obuf_len;
293 break;
294 case BIO_C_GET_BUFF_NUM_LINES:
295 ret=0;
296 p1=ctx->ibuf;
297 for (i=ctx->ibuf_off; i<ctx->ibuf_len; i++)
298 {
299 if (p1[i] == '\n') ret++;
300 }
301 break;
302 case BIO_CTRL_WPENDING:
303 ret=(long)ctx->obuf_len;
304 if (ret == 0)
305 {
306 if (b->next_bio == NULL) return(0);
307 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
308 }
309 break;
310 case BIO_CTRL_PENDING:
311 ret=(long)ctx->ibuf_len;
312 if (ret == 0)
313 {
314 if (b->next_bio == NULL) return(0);
315 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
316 }
317 break;
318 case BIO_C_SET_BUFF_READ_DATA:
319 if (num > ctx->ibuf_size)
320 {
321 p1=OPENSSL_malloc((int)num);
322 if (p1 == NULL) goto malloc_error;
323 if (ctx->ibuf != NULL) OPENSSL_free(ctx->ibuf);
324 ctx->ibuf=p1;
325 }
326 ctx->ibuf_off=0;
327 ctx->ibuf_len=(int)num;
328 memcpy(ctx->ibuf,ptr,(int)num);
329 ret=1;
330 break;
331 case BIO_C_SET_BUFF_SIZE:
332 if (ptr != NULL)
333 {
334 ip=(int *)ptr;
335 if (*ip == 0)
336 {
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 }
351 p1=ctx->ibuf;
352 p2=ctx->obuf;
353 if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size))
354 {
355 p1=(char *)OPENSSL_malloc((int)num);
356 if (p1 == NULL) goto malloc_error;
357 }
358 if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size))
359 {
360 p2=(char *)OPENSSL_malloc((int)num);
361 if (p2 == NULL)
362 {
363 if (p1 != ctx->ibuf) OPENSSL_free(p1);
364 goto malloc_error;
365 }
366 }
367 if (ctx->ibuf != p1)
368 {
369 OPENSSL_free(ctx->ibuf);
370 ctx->ibuf=p1;
371 ctx->ibuf_off=0;
372 ctx->ibuf_len=0;
373 ctx->ibuf_size=ibs;
374 }
375 if (ctx->obuf != p2)
376 {
377 OPENSSL_free(ctx->obuf);
378 ctx->obuf=p2;
379 ctx->obuf_off=0;
380 ctx->obuf_len=0;
381 ctx->obuf_size=obs;
382 }
383 break;
384 case BIO_C_DO_STATE_MACHINE:
385 if (b->next_bio == NULL) return(0);
386 BIO_clear_retry_flags(b);
387 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
388 BIO_copy_next_retry(b);
389 break;
390
391 case BIO_CTRL_FLUSH:
392 if (b->next_bio == NULL) return(0);
393 if (ctx->obuf_len <= 0)
394 {
395 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
396 break;
397 }
398
399 for (;;)
400 {
401 BIO_clear_retry_flags(b);
402 if (ctx->obuf_len > ctx->obuf_off)
403 {
404 r=BIO_write(b->next_bio,
405 &(ctx->obuf[ctx->obuf_off]),
406 ctx->obuf_len-ctx->obuf_off);
407#if 0
408fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len-ctx->obuf_off,r);
409#endif
410 BIO_copy_next_retry(b);
411 if (r <= 0) return((long)r);
412 ctx->obuf_off+=r;
413 }
414 else
415 {
416 ctx->obuf_len=0;
417 ctx->obuf_off=0;
418 ret=1;
419 break;
420 }
421 }
422 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
423 break;
424 case BIO_CTRL_DUP:
425 dbio=(BIO *)ptr;
426 if ( !BIO_set_read_buffer_size(dbio,ctx->ibuf_size) ||
427 !BIO_set_write_buffer_size(dbio,ctx->obuf_size))
428 ret=0;
429 break;
430 default:
431 if (b->next_bio == NULL) return(0);
432 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
433 break;
434 }
435 return(ret);
436malloc_error:
437 BIOerr(BIO_F_BUFFER_CTRL,ERR_R_MALLOC_FAILURE);
438 return(0);
439 }
440
441static long buffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
442 {
443 long ret=1;
444
445 if (b->next_bio == NULL) return(0);
446 switch (cmd)
447 {
448 default:
449 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
450 break;
451 }
452 return(ret);
453 }
454
455static int buffer_gets(BIO *b, char *buf, int size)
456 {
457 BIO_F_BUFFER_CTX *ctx;
458 int num=0,i,flag;
459 char *p;
460
461 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
462 size--; /* reserve space for a '\0' */
463 BIO_clear_retry_flags(b);
464
465 for (;;)
466 {
467 if (ctx->ibuf_len > 0)
468 {
469 p= &(ctx->ibuf[ctx->ibuf_off]);
470 flag=0;
471 for (i=0; (i<ctx->ibuf_len) && (i<size); i++)
472 {
473 *(buf++)=p[i];
474 if (p[i] == '\n')
475 {
476 flag=1;
477 i++;
478 break;
479 }
480 }
481 num+=i;
482 size-=i;
483 ctx->ibuf_len-=i;
484 ctx->ibuf_off+=i;
485 if ((flag) || (i == size))
486 {
487 *buf='\0';
488 return(num);
489 }
490 }
491 else /* read another chunk */
492 {
493 i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size);
494 if (i <= 0)
495 {
496 BIO_copy_next_retry(b);
497 if (i < 0) return((num > 0)?num:i);
498 if (i == 0) return(num);
499 }
500 ctx->ibuf_len=i;
501 ctx->ibuf_off=0;
502 }
503 }
504 }
505
506static int buffer_puts(BIO *b, const char *str)
507 {
508 return(buffer_write(b,str,strlen(str)));
509 }
510
diff --git a/src/lib/libcrypto/bio/bf_lbuf.c b/src/lib/libcrypto/bio/bf_lbuf.c
deleted file mode 100644
index ec0f7eb0b7..0000000000
--- a/src/lib/libcrypto/bio/bf_lbuf.c
+++ /dev/null
@@ -1,397 +0,0 @@
1/* crypto/bio/bf_buff.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/bio.h>
63#include <openssl/evp.h>
64
65static int linebuffer_write(BIO *h, const char *buf,int num);
66static int linebuffer_read(BIO *h, char *buf, int size);
67static int linebuffer_puts(BIO *h, const char *str);
68static int linebuffer_gets(BIO *h, char *str, int size);
69static long linebuffer_ctrl(BIO *h, int cmd, long arg1, void *arg2);
70static int linebuffer_new(BIO *h);
71static int linebuffer_free(BIO *data);
72static long linebuffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
73
74/* A 10k maximum should be enough for most purposes */
75#define DEFAULT_LINEBUFFER_SIZE 1024*10
76
77/* #define DEBUG */
78
79static BIO_METHOD methods_linebuffer=
80 {
81 BIO_TYPE_LINEBUFFER,
82 "linebuffer",
83 linebuffer_write,
84 linebuffer_read,
85 linebuffer_puts,
86 linebuffer_gets,
87 linebuffer_ctrl,
88 linebuffer_new,
89 linebuffer_free,
90 linebuffer_callback_ctrl,
91 };
92
93BIO_METHOD *BIO_f_linebuffer(void)
94 {
95 return(&methods_linebuffer);
96 }
97
98typedef struct bio_linebuffer_ctx_struct
99 {
100 char *obuf; /* the output char array */
101 int obuf_size; /* how big is the output buffer */
102 int obuf_len; /* how many bytes are in it */
103 } BIO_LINEBUFFER_CTX;
104
105static int linebuffer_new(BIO *bi)
106 {
107 BIO_LINEBUFFER_CTX *ctx;
108
109 ctx=(BIO_LINEBUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_LINEBUFFER_CTX));
110 if (ctx == NULL) return(0);
111 ctx->obuf=(char *)OPENSSL_malloc(DEFAULT_LINEBUFFER_SIZE);
112 if (ctx->obuf == NULL) { OPENSSL_free(ctx); return(0); }
113 ctx->obuf_size=DEFAULT_LINEBUFFER_SIZE;
114 ctx->obuf_len=0;
115
116 bi->init=1;
117 bi->ptr=(char *)ctx;
118 bi->flags=0;
119 return(1);
120 }
121
122static int linebuffer_free(BIO *a)
123 {
124 BIO_LINEBUFFER_CTX *b;
125
126 if (a == NULL) return(0);
127 b=(BIO_LINEBUFFER_CTX *)a->ptr;
128 if (b->obuf != NULL) OPENSSL_free(b->obuf);
129 OPENSSL_free(a->ptr);
130 a->ptr=NULL;
131 a->init=0;
132 a->flags=0;
133 return(1);
134 }
135
136static int linebuffer_read(BIO *b, char *out, int outl)
137 {
138 int ret=0;
139
140 if (out == NULL) return(0);
141 if (b->next_bio == NULL) return(0);
142 ret=BIO_read(b->next_bio,out,outl);
143 BIO_clear_retry_flags(b);
144 BIO_copy_next_retry(b);
145 return(ret);
146 }
147
148static int linebuffer_write(BIO *b, const char *in, int inl)
149 {
150 int i,num=0,foundnl;
151 BIO_LINEBUFFER_CTX *ctx;
152
153 if ((in == NULL) || (inl <= 0)) return(0);
154 ctx=(BIO_LINEBUFFER_CTX *)b->ptr;
155 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
156
157 BIO_clear_retry_flags(b);
158
159 do
160 {
161 const char *p;
162
163 for(p = in; p < in + inl && *p != '\n'; p++)
164 ;
165 if (*p == '\n')
166 {
167 p++;
168 foundnl = 1;
169 }
170 else
171 foundnl = 0;
172
173 /* If a NL was found and we already have text in the save
174 buffer, concatenate them and write */
175 while ((foundnl || p - in > ctx->obuf_size - ctx->obuf_len)
176 && ctx->obuf_len > 0)
177 {
178 int orig_olen = ctx->obuf_len;
179
180 i = ctx->obuf_size - ctx->obuf_len;
181 if (p - in > 0)
182 {
183 if (i >= p - in)
184 {
185 memcpy(&(ctx->obuf[ctx->obuf_len]),
186 in,p - in);
187 ctx->obuf_len += p - in;
188 inl -= p - in;
189 num += p - in;
190 in = p;
191 }
192 else
193 {
194 memcpy(&(ctx->obuf[ctx->obuf_len]),
195 in,i);
196 ctx->obuf_len += i;
197 inl -= i;
198 in += i;
199 num += i;
200 }
201 }
202
203#if 0
204BIO_write(b->next_bio, "<*<", 3);
205#endif
206 i=BIO_write(b->next_bio,
207 ctx->obuf, ctx->obuf_len);
208 if (i <= 0)
209 {
210 ctx->obuf_len = orig_olen;
211 BIO_copy_next_retry(b);
212
213#if 0
214BIO_write(b->next_bio, ">*>", 3);
215#endif
216 if (i < 0) return((num > 0)?num:i);
217 if (i == 0) return(num);
218 }
219#if 0
220BIO_write(b->next_bio, ">*>", 3);
221#endif
222 if (i < ctx->obuf_len)
223 memmove(ctx->obuf, ctx->obuf + i,
224 ctx->obuf_len - i);
225 ctx->obuf_len-=i;
226 }
227
228 /* 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. */
230 if ((foundnl || p - in > ctx->obuf_size) && p - in > 0)
231 {
232#if 0
233BIO_write(b->next_bio, "<*<", 3);
234#endif
235 i=BIO_write(b->next_bio,in,p - in);
236 if (i <= 0)
237 {
238 BIO_copy_next_retry(b);
239#if 0
240BIO_write(b->next_bio, ">*>", 3);
241#endif
242 if (i < 0) return((num > 0)?num:i);
243 if (i == 0) return(num);
244 }
245#if 0
246BIO_write(b->next_bio, ">*>", 3);
247#endif
248 num+=i;
249 in+=i;
250 inl-=i;
251 }
252 }
253 while(foundnl && inl > 0);
254 /* 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
256 saved for the next trip. */
257 if (inl > 0)
258 {
259 memcpy(&(ctx->obuf[ctx->obuf_len]), in, inl);
260 ctx->obuf_len += inl;
261 num += inl;
262 }
263 return num;
264 }
265
266static long linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr)
267 {
268 BIO *dbio;
269 BIO_LINEBUFFER_CTX *ctx;
270 long ret=1;
271 char *p;
272 int r;
273 int obs;
274
275 ctx=(BIO_LINEBUFFER_CTX *)b->ptr;
276
277 switch (cmd)
278 {
279 case BIO_CTRL_RESET:
280 ctx->obuf_len=0;
281 if (b->next_bio == NULL) return(0);
282 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
283 break;
284 case BIO_CTRL_INFO:
285 ret=(long)ctx->obuf_len;
286 break;
287 case BIO_CTRL_WPENDING:
288 ret=(long)ctx->obuf_len;
289 if (ret == 0)
290 {
291 if (b->next_bio == NULL) return(0);
292 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
293 }
294 break;
295 case BIO_C_SET_BUFF_SIZE:
296 obs=(int)num;
297 p=ctx->obuf;
298 if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size))
299 {
300 p=(char *)OPENSSL_malloc((int)num);
301 if (p == NULL)
302 goto malloc_error;
303 }
304 if (ctx->obuf != p)
305 {
306 if (ctx->obuf_len > obs)
307 {
308 ctx->obuf_len = obs;
309 }
310 memcpy(p, ctx->obuf, ctx->obuf_len);
311 OPENSSL_free(ctx->obuf);
312 ctx->obuf=p;
313 ctx->obuf_size=obs;
314 }
315 break;
316 case BIO_C_DO_STATE_MACHINE:
317 if (b->next_bio == NULL) return(0);
318 BIO_clear_retry_flags(b);
319 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
320 BIO_copy_next_retry(b);
321 break;
322
323 case BIO_CTRL_FLUSH:
324 if (b->next_bio == NULL) return(0);
325 if (ctx->obuf_len <= 0)
326 {
327 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
328 break;
329 }
330
331 for (;;)
332 {
333 BIO_clear_retry_flags(b);
334 if (ctx->obuf_len > 0)
335 {
336 r=BIO_write(b->next_bio,
337 ctx->obuf, ctx->obuf_len);
338#if 0
339fprintf(stderr,"FLUSH %3d -> %3d\n",ctx->obuf_len,r);
340#endif
341 BIO_copy_next_retry(b);
342 if (r <= 0) return((long)r);
343 if (r < ctx->obuf_len)
344 memmove(ctx->obuf, ctx->obuf + r,
345 ctx->obuf_len - r);
346 ctx->obuf_len-=r;
347 }
348 else
349 {
350 ctx->obuf_len=0;
351 ret=1;
352 break;
353 }
354 }
355 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
356 break;
357 case BIO_CTRL_DUP:
358 dbio=(BIO *)ptr;
359 if ( !BIO_set_write_buffer_size(dbio,ctx->obuf_size))
360 ret=0;
361 break;
362 default:
363 if (b->next_bio == NULL) return(0);
364 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
365 break;
366 }
367 return(ret);
368malloc_error:
369 BIOerr(BIO_F_LINEBUFFER_CTRL,ERR_R_MALLOC_FAILURE);
370 return(0);
371 }
372
373static long linebuffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
374 {
375 long ret=1;
376
377 if (b->next_bio == NULL) return(0);
378 switch (cmd)
379 {
380 default:
381 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
382 break;
383 }
384 return(ret);
385 }
386
387static int linebuffer_gets(BIO *b, char *buf, int size)
388 {
389 if (b->next_bio == NULL) return(0);
390 return(BIO_gets(b->next_bio,buf,size));
391 }
392
393static int linebuffer_puts(BIO *b, const char *str)
394 {
395 return(linebuffer_write(b,str,strlen(str)));
396 }
397
diff --git a/src/lib/libcrypto/bio/bf_nbio.c b/src/lib/libcrypto/bio/bf_nbio.c
deleted file mode 100644
index 1ce2bfacc0..0000000000
--- a/src/lib/libcrypto/bio/bf_nbio.c
+++ /dev/null
@@ -1,255 +0,0 @@
1/* crypto/bio/bf_nbio.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/rand.h>
63#include <openssl/bio.h>
64
65/* BIO_put and BIO_get both add to the digest,
66 * BIO_gets returns the digest */
67
68static int nbiof_write(BIO *h,const char *buf,int num);
69static int nbiof_read(BIO *h,char *buf,int size);
70static int nbiof_puts(BIO *h,const char *str);
71static int nbiof_gets(BIO *h,char *str,int size);
72static long nbiof_ctrl(BIO *h,int cmd,long arg1,void *arg2);
73static int nbiof_new(BIO *h);
74static int nbiof_free(BIO *data);
75static long nbiof_callback_ctrl(BIO *h,int cmd,bio_info_cb *fp);
76typedef struct nbio_test_st
77 {
78 /* only set if we sent a 'should retry' error */
79 int lrn;
80 int lwn;
81 } NBIO_TEST;
82
83static BIO_METHOD methods_nbiof=
84 {
85 BIO_TYPE_NBIO_TEST,
86 "non-blocking IO test filter",
87 nbiof_write,
88 nbiof_read,
89 nbiof_puts,
90 nbiof_gets,
91 nbiof_ctrl,
92 nbiof_new,
93 nbiof_free,
94 nbiof_callback_ctrl,
95 };
96
97BIO_METHOD *BIO_f_nbio_test(void)
98 {
99 return(&methods_nbiof);
100 }
101
102static int nbiof_new(BIO *bi)
103 {
104 NBIO_TEST *nt;
105
106 if (!(nt=(NBIO_TEST *)OPENSSL_malloc(sizeof(NBIO_TEST)))) return(0);
107 nt->lrn= -1;
108 nt->lwn= -1;
109 bi->ptr=(char *)nt;
110 bi->init=1;
111 bi->flags=0;
112 return(1);
113 }
114
115static int nbiof_free(BIO *a)
116 {
117 if (a == NULL) return(0);
118 if (a->ptr != NULL)
119 OPENSSL_free(a->ptr);
120 a->ptr=NULL;
121 a->init=0;
122 a->flags=0;
123 return(1);
124 }
125
126static int nbiof_read(BIO *b, char *out, int outl)
127 {
128 NBIO_TEST *nt;
129 int ret=0;
130#if 0
131 int num;
132 unsigned char n;
133#endif
134
135 if (out == NULL) return(0);
136 if (b->next_bio == NULL) return(0);
137 nt=(NBIO_TEST *)b->ptr;
138
139 BIO_clear_retry_flags(b);
140#if 0
141 RAND_pseudo_bytes(&n,1);
142 num=(n&0x07);
143
144 if (outl > num) outl=num;
145
146 if (num == 0)
147 {
148 ret= -1;
149 BIO_set_retry_read(b);
150 }
151 else
152#endif
153 {
154 ret=BIO_read(b->next_bio,out,outl);
155 if (ret < 0)
156 BIO_copy_next_retry(b);
157 }
158 return(ret);
159 }
160
161static int nbiof_write(BIO *b, const char *in, int inl)
162 {
163 NBIO_TEST *nt;
164 int ret=0;
165 int num;
166 unsigned char n;
167
168 if ((in == NULL) || (inl <= 0)) return(0);
169 if (b->next_bio == NULL) return(0);
170 nt=(NBIO_TEST *)b->ptr;
171
172 BIO_clear_retry_flags(b);
173
174#if 1
175 if (nt->lwn > 0)
176 {
177 num=nt->lwn;
178 nt->lwn=0;
179 }
180 else
181 {
182 RAND_pseudo_bytes(&n,1);
183 num=(n&7);
184 }
185
186 if (inl > num) inl=num;
187
188 if (num == 0)
189 {
190 ret= -1;
191 BIO_set_retry_write(b);
192 }
193 else
194#endif
195 {
196 ret=BIO_write(b->next_bio,in,inl);
197 if (ret < 0)
198 {
199 BIO_copy_next_retry(b);
200 nt->lwn=inl;
201 }
202 }
203 return(ret);
204 }
205
206static long nbiof_ctrl(BIO *b, int cmd, long num, void *ptr)
207 {
208 long ret;
209
210 if (b->next_bio == NULL) return(0);
211 switch (cmd)
212 {
213 case BIO_C_DO_STATE_MACHINE:
214 BIO_clear_retry_flags(b);
215 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
216 BIO_copy_next_retry(b);
217 break;
218 case BIO_CTRL_DUP:
219 ret=0L;
220 break;
221 default:
222 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
223 break;
224 }
225 return(ret);
226 }
227
228static long nbiof_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
229 {
230 long ret=1;
231
232 if (b->next_bio == NULL) return(0);
233 switch (cmd)
234 {
235 default:
236 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
237 break;
238 }
239 return(ret);
240 }
241
242static int nbiof_gets(BIO *bp, char *buf, int size)
243 {
244 if (bp->next_bio == NULL) return(0);
245 return(BIO_gets(bp->next_bio,buf,size));
246 }
247
248
249static int nbiof_puts(BIO *bp, const char *str)
250 {
251 if (bp->next_bio == NULL) return(0);
252 return(BIO_puts(bp->next_bio,str));
253 }
254
255
diff --git a/src/lib/libcrypto/bio/bf_null.c b/src/lib/libcrypto/bio/bf_null.c
deleted file mode 100644
index c1bf39a904..0000000000
--- a/src/lib/libcrypto/bio/bf_null.c
+++ /dev/null
@@ -1,183 +0,0 @@
1/* crypto/bio/bf_null.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/bio.h>
63
64/* BIO_put and BIO_get both add to the digest,
65 * BIO_gets returns the digest */
66
67static int nullf_write(BIO *h, const char *buf, int num);
68static int nullf_read(BIO *h, char *buf, int size);
69static int nullf_puts(BIO *h, const char *str);
70static int nullf_gets(BIO *h, char *str, int size);
71static long nullf_ctrl(BIO *h, int cmd, long arg1, void *arg2);
72static int nullf_new(BIO *h);
73static int nullf_free(BIO *data);
74static long nullf_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
75static BIO_METHOD methods_nullf=
76 {
77 BIO_TYPE_NULL_FILTER,
78 "NULL filter",
79 nullf_write,
80 nullf_read,
81 nullf_puts,
82 nullf_gets,
83 nullf_ctrl,
84 nullf_new,
85 nullf_free,
86 nullf_callback_ctrl,
87 };
88
89BIO_METHOD *BIO_f_null(void)
90 {
91 return(&methods_nullf);
92 }
93
94static int nullf_new(BIO *bi)
95 {
96 bi->init=1;
97 bi->ptr=NULL;
98 bi->flags=0;
99 return(1);
100 }
101
102static int nullf_free(BIO *a)
103 {
104 if (a == NULL) return(0);
105/* a->ptr=NULL;
106 a->init=0;
107 a->flags=0;*/
108 return(1);
109 }
110
111static int nullf_read(BIO *b, char *out, int outl)
112 {
113 int ret=0;
114
115 if (out == NULL) return(0);
116 if (b->next_bio == NULL) return(0);
117 ret=BIO_read(b->next_bio,out,outl);
118 BIO_clear_retry_flags(b);
119 BIO_copy_next_retry(b);
120 return(ret);
121 }
122
123static int nullf_write(BIO *b, const char *in, int inl)
124 {
125 int ret=0;
126
127 if ((in == NULL) || (inl <= 0)) return(0);
128 if (b->next_bio == NULL) return(0);
129 ret=BIO_write(b->next_bio,in,inl);
130 BIO_clear_retry_flags(b);
131 BIO_copy_next_retry(b);
132 return(ret);
133 }
134
135static long nullf_ctrl(BIO *b, int cmd, long num, void *ptr)
136 {
137 long ret;
138
139 if (b->next_bio == NULL) return(0);
140 switch(cmd)
141 {
142 case BIO_C_DO_STATE_MACHINE:
143 BIO_clear_retry_flags(b);
144 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
145 BIO_copy_next_retry(b);
146 break;
147 case BIO_CTRL_DUP:
148 ret=0L;
149 break;
150 default:
151 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
152 }
153 return(ret);
154 }
155
156static long nullf_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
157 {
158 long ret=1;
159
160 if (b->next_bio == NULL) return(0);
161 switch (cmd)
162 {
163 default:
164 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
165 break;
166 }
167 return(ret);
168 }
169
170static int nullf_gets(BIO *bp, char *buf, int size)
171 {
172 if (bp->next_bio == NULL) return(0);
173 return(BIO_gets(bp->next_bio,buf,size));
174 }
175
176
177static int nullf_puts(BIO *bp, const char *str)
178 {
179 if (bp->next_bio == NULL) return(0);
180 return(BIO_puts(bp->next_bio,str));
181 }
182
183
diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h
deleted file mode 100644
index c5caf253c9..0000000000
--- a/src/lib/libcrypto/bio/bio.h
+++ /dev/null
@@ -1,693 +0,0 @@
1/* crypto/bio/bio.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_BIO_H
60#define HEADER_BIO_H
61
62#ifndef OPENSSL_NO_FP_API
63# include <stdio.h>
64#endif
65#include <stdarg.h>
66
67#include <openssl/crypto.h>
68#include <openssl/e_os2.h>
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
74/* These are the 'types' of BIOs */
75#define BIO_TYPE_NONE 0
76#define BIO_TYPE_MEM (1|0x0400)
77#define BIO_TYPE_FILE (2|0x0400)
78
79#define BIO_TYPE_FD (4|0x0400|0x0100)
80#define BIO_TYPE_SOCKET (5|0x0400|0x0100)
81#define BIO_TYPE_NULL (6|0x0400)
82#define BIO_TYPE_SSL (7|0x0200)
83#define BIO_TYPE_MD (8|0x0200) /* passive filter */
84#define BIO_TYPE_BUFFER (9|0x0200) /* filter */
85#define BIO_TYPE_CIPHER (10|0x0200) /* filter */
86#define BIO_TYPE_BASE64 (11|0x0200) /* filter */
87#define BIO_TYPE_CONNECT (12|0x0400|0x0100) /* socket - connect */
88#define BIO_TYPE_ACCEPT (13|0x0400|0x0100) /* socket for accept */
89#define BIO_TYPE_PROXY_CLIENT (14|0x0200) /* client proxy BIO */
90#define BIO_TYPE_PROXY_SERVER (15|0x0200) /* server proxy BIO */
91#define BIO_TYPE_NBIO_TEST (16|0x0200) /* server proxy BIO */
92#define BIO_TYPE_NULL_FILTER (17|0x0200)
93#define BIO_TYPE_BER (18|0x0200) /* BER -> bin filter */
94#define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */
95#define BIO_TYPE_LINEBUFFER (20|0x0200) /* filter */
96
97#define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */
98#define BIO_TYPE_FILTER 0x0200
99#define BIO_TYPE_SOURCE_SINK 0x0400
100
101/* BIO_FILENAME_READ|BIO_CLOSE to open or close on free.
102 * BIO_set_fp(in,stdin,BIO_NOCLOSE); */
103#define BIO_NOCLOSE 0x00
104#define BIO_CLOSE 0x01
105
106/* These are used in the following macros and are passed to
107 * BIO_ctrl() */
108#define BIO_CTRL_RESET 1 /* opt - rewind/zero etc */
109#define BIO_CTRL_EOF 2 /* opt - are we at the eof */
110#define BIO_CTRL_INFO 3 /* opt - extra tit-bits */
111#define BIO_CTRL_SET 4 /* man - set the 'IO' type */
112#define BIO_CTRL_GET 5 /* man - get the 'IO' type */
113#define BIO_CTRL_PUSH 6 /* opt - internal, used to signify change */
114#define BIO_CTRL_POP 7 /* opt - internal, used to signify change */
115#define BIO_CTRL_GET_CLOSE 8 /* man - set the 'close' on free */
116#define BIO_CTRL_SET_CLOSE 9 /* man - set the 'close' on free */
117#define BIO_CTRL_PENDING 10 /* opt - is their more data buffered */
118#define BIO_CTRL_FLUSH 11 /* opt - 'flush' buffered output */
119#define BIO_CTRL_DUP 12 /* man - extra stuff for 'duped' BIO */
120#define BIO_CTRL_WPENDING 13 /* opt - number of bytes still to write */
121/* callback is int cb(BIO *bio,state,ret); */
122#define BIO_CTRL_SET_CALLBACK 14 /* opt - set callback function */
123#define BIO_CTRL_GET_CALLBACK 15 /* opt - set callback function */
124
125#define BIO_CTRL_SET_FILENAME 30 /* BIO_s_file special */
126
127/* modifiers */
128#define BIO_FP_READ 0x02
129#define BIO_FP_WRITE 0x04
130#define BIO_FP_APPEND 0x08
131#define BIO_FP_TEXT 0x10
132
133#define BIO_FLAGS_READ 0x01
134#define BIO_FLAGS_WRITE 0x02
135#define BIO_FLAGS_IO_SPECIAL 0x04
136#define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL)
137#define BIO_FLAGS_SHOULD_RETRY 0x08
138
139/* Used in BIO_gethostbyname() */
140#define BIO_GHBN_CTRL_HITS 1
141#define BIO_GHBN_CTRL_MISSES 2
142#define BIO_GHBN_CTRL_CACHE_SIZE 3
143#define BIO_GHBN_CTRL_GET_ENTRY 4
144#define BIO_GHBN_CTRL_FLUSH 5
145
146/* Mostly used in the SSL BIO */
147/* Not used anymore
148 * #define BIO_FLAGS_PROTOCOL_DELAYED_READ 0x10
149 * #define BIO_FLAGS_PROTOCOL_DELAYED_WRITE 0x20
150 * #define BIO_FLAGS_PROTOCOL_STARTUP 0x40
151 */
152
153#define BIO_FLAGS_BASE64_NO_NL 0x100
154
155/* This is used with memory BIOs: it means we shouldn't free up or change the
156 * data in any way.
157 */
158#define BIO_FLAGS_MEM_RDONLY 0x200
159
160#define BIO_set_flags(b,f) ((b)->flags|=(f))
161#define BIO_get_flags(b) ((b)->flags)
162#define BIO_set_retry_special(b) \
163 ((b)->flags|=(BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY))
164#define BIO_set_retry_read(b) \
165 ((b)->flags|=(BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY))
166#define BIO_set_retry_write(b) \
167 ((b)->flags|=(BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY))
168
169/* These are normally used internally in BIOs */
170#define BIO_clear_flags(b,f) ((b)->flags&= ~(f))
171#define BIO_clear_retry_flags(b) \
172 ((b)->flags&= ~(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))
173#define BIO_get_retry_flags(b) \
174 ((b)->flags&(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))
175
176/* These should be used by the application to tell why we should retry */
177#define BIO_should_read(a) ((a)->flags & BIO_FLAGS_READ)
178#define BIO_should_write(a) ((a)->flags & BIO_FLAGS_WRITE)
179#define BIO_should_io_special(a) ((a)->flags & BIO_FLAGS_IO_SPECIAL)
180#define BIO_retry_type(a) ((a)->flags & BIO_FLAGS_RWS)
181#define BIO_should_retry(a) ((a)->flags & BIO_FLAGS_SHOULD_RETRY)
182
183/* The next three are used in conjunction with the
184 * BIO_should_io_special() condition. After this returns true,
185 * BIO *BIO_get_retry_BIO(BIO *bio, int *reason); will walk the BIO
186 * stack and return the 'reason' for the special and the offending BIO.
187 * Given a BIO, BIO_get_retry_reason(bio) will return the code. */
188/* Returned from the SSL bio when the certificate retrieval code had an error */
189#define BIO_RR_SSL_X509_LOOKUP 0x01
190/* Returned from the connect BIO when a connect would have blocked */
191#define BIO_RR_CONNECT 0x02
192/* Returned from the accept BIO when an accept would have blocked */
193#define BIO_RR_ACCEPT 0x03
194
195/* These are passed by the BIO callback */
196#define BIO_CB_FREE 0x01
197#define BIO_CB_READ 0x02
198#define BIO_CB_WRITE 0x03
199#define BIO_CB_PUTS 0x04
200#define BIO_CB_GETS 0x05
201#define BIO_CB_CTRL 0x06
202
203/* The callback is called before and after the underling operation,
204 * The BIO_CB_RETURN flag indicates if it is after the call */
205#define BIO_CB_RETURN 0x80
206#define BIO_CB_return(a) ((a)|BIO_CB_RETURN))
207#define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN))
208#define BIO_cb_post(a) ((a)&BIO_CB_RETURN)
209
210#define BIO_set_callback(b,cb) ((b)->callback=(cb))
211#define BIO_set_callback_arg(b,arg) ((b)->cb_arg=(char *)(arg))
212#define BIO_get_callback_arg(b) ((b)->cb_arg)
213#define BIO_get_callback(b) ((b)->callback)
214#define BIO_method_name(b) ((b)->method->name)
215#define BIO_method_type(b) ((b)->method->type)
216
217typedef struct bio_st BIO;
218
219typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long);
220
221#ifndef OPENSSL_SYS_WIN16
222typedef struct bio_method_st
223 {
224 int type;
225 const char *name;
226 int (*bwrite)(BIO *, const char *, int);
227 int (*bread)(BIO *, char *, int);
228 int (*bputs)(BIO *, const char *);
229 int (*bgets)(BIO *, char *, int);
230 long (*ctrl)(BIO *, int, long, void *);
231 int (*create)(BIO *);
232 int (*destroy)(BIO *);
233 long (*callback_ctrl)(BIO *, int, bio_info_cb *);
234 } BIO_METHOD;
235#else
236typedef struct bio_method_st
237 {
238 int type;
239 const char *name;
240 int (_far *bwrite)();
241 int (_far *bread)();
242 int (_far *bputs)();
243 int (_far *bgets)();
244 long (_far *ctrl)();
245 int (_far *create)();
246 int (_far *destroy)();
247 long (_fat *callback_ctrl)();
248 } BIO_METHOD;
249#endif
250
251struct bio_st
252 {
253 BIO_METHOD *method;
254 /* bio, mode, argp, argi, argl, ret */
255 long (*callback)(struct bio_st *,int,const char *,int, long,long);
256 char *cb_arg; /* first argument for the callback */
257
258 int init;
259 int shutdown;
260 int flags; /* extra storage */
261 int retry_reason;
262 int num;
263 void *ptr;
264 struct bio_st *next_bio; /* used by filter BIOs */
265 struct bio_st *prev_bio; /* used by filter BIOs */
266 int references;
267 unsigned long num_read;
268 unsigned long num_write;
269
270 CRYPTO_EX_DATA ex_data;
271 };
272
273DECLARE_STACK_OF(BIO)
274
275typedef struct bio_f_buffer_ctx_struct
276 {
277 /* BIO *bio; */ /* this is now in the BIO struct */
278 int ibuf_size; /* how big is the input buffer */
279 int obuf_size; /* how big is the output buffer */
280
281 char *ibuf; /* the char array */
282 int ibuf_len; /* how many bytes are in it */
283 int ibuf_off; /* write/read offset */
284
285 char *obuf; /* the char array */
286 int obuf_len; /* how many bytes are in it */
287 int obuf_off; /* write/read offset */
288 } BIO_F_BUFFER_CTX;
289
290/* connect BIO stuff */
291#define BIO_CONN_S_BEFORE 1
292#define BIO_CONN_S_GET_IP 2
293#define BIO_CONN_S_GET_PORT 3
294#define BIO_CONN_S_CREATE_SOCKET 4
295#define BIO_CONN_S_CONNECT 5
296#define BIO_CONN_S_OK 6
297#define BIO_CONN_S_BLOCKED_CONNECT 7
298#define BIO_CONN_S_NBIO 8
299/*#define BIO_CONN_get_param_hostname BIO_ctrl */
300
301#define BIO_C_SET_CONNECT 100
302#define BIO_C_DO_STATE_MACHINE 101
303#define BIO_C_SET_NBIO 102
304#define BIO_C_SET_PROXY_PARAM 103
305#define BIO_C_SET_FD 104
306#define BIO_C_GET_FD 105
307#define BIO_C_SET_FILE_PTR 106
308#define BIO_C_GET_FILE_PTR 107
309#define BIO_C_SET_FILENAME 108
310#define BIO_C_SET_SSL 109
311#define BIO_C_GET_SSL 110
312#define BIO_C_SET_MD 111
313#define BIO_C_GET_MD 112
314#define BIO_C_GET_CIPHER_STATUS 113
315#define BIO_C_SET_BUF_MEM 114
316#define BIO_C_GET_BUF_MEM_PTR 115
317#define BIO_C_GET_BUFF_NUM_LINES 116
318#define BIO_C_SET_BUFF_SIZE 117
319#define BIO_C_SET_ACCEPT 118
320#define BIO_C_SSL_MODE 119
321#define BIO_C_GET_MD_CTX 120
322#define BIO_C_GET_PROXY_PARAM 121
323#define BIO_C_SET_BUFF_READ_DATA 122 /* data to read first */
324#define BIO_C_GET_CONNECT 123
325#define BIO_C_GET_ACCEPT 124
326#define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125
327#define BIO_C_GET_SSL_NUM_RENEGOTIATES 126
328#define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127
329#define BIO_C_FILE_SEEK 128
330#define BIO_C_GET_CIPHER_CTX 129
331#define BIO_C_SET_BUF_MEM_EOF_RETURN 130/*return end of input value*/
332#define BIO_C_SET_BIND_MODE 131
333#define BIO_C_GET_BIND_MODE 132
334#define BIO_C_FILE_TELL 133
335#define BIO_C_GET_SOCKS 134
336#define BIO_C_SET_SOCKS 135
337
338#define BIO_C_SET_WRITE_BUF_SIZE 136/* for BIO_s_bio */
339#define BIO_C_GET_WRITE_BUF_SIZE 137
340#define BIO_C_MAKE_BIO_PAIR 138
341#define BIO_C_DESTROY_BIO_PAIR 139
342#define BIO_C_GET_WRITE_GUARANTEE 140
343#define BIO_C_GET_READ_REQUEST 141
344#define BIO_C_SHUTDOWN_WR 142
345#define BIO_C_NREAD0 143
346#define BIO_C_NREAD 144
347#define BIO_C_NWRITE0 145
348#define BIO_C_NWRITE 146
349#define BIO_C_RESET_READ_REQUEST 147
350
351
352#define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,arg)
353#define BIO_get_app_data(s) BIO_get_ex_data(s,0)
354
355/* BIO_s_connect() and BIO_s_socks4a_connect() */
356#define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name)
357#define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port)
358#define BIO_set_conn_ip(b,ip) BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)ip)
359#define BIO_set_conn_int_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,3,(char *)port)
360#define BIO_get_conn_hostname(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0)
361#define BIO_get_conn_port(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1)
362#define BIO_get_conn_ip(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,2)
363#define BIO_get_conn_int_port(b) BIO_int_ctrl(b,BIO_C_GET_CONNECT,3)
364
365
366#define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL)
367
368/* BIO_s_accept_socket() */
369#define BIO_set_accept_port(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0,(char *)name)
370#define BIO_get_accept_port(b) BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0)
371/* #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */
372#define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?"a":NULL)
373#define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio)
374
375#define BIO_BIND_NORMAL 0
376#define BIO_BIND_REUSEADDR_IF_UNUSED 1
377#define BIO_BIND_REUSEADDR 2
378#define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL)
379#define BIO_get_bind_mode(b,mode) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL)
380
381#define BIO_do_connect(b) BIO_do_handshake(b)
382#define BIO_do_accept(b) BIO_do_handshake(b)
383#define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL)
384
385/* BIO_s_proxy_client() */
386#define BIO_set_url(b,url) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,0,(char *)(url))
387#define BIO_set_proxies(b,p) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,1,(char *)(p))
388/* BIO_set_nbio(b,n) */
389#define BIO_set_filter_bio(b,s) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,2,(char *)(s))
390/* BIO *BIO_get_filter_bio(BIO *bio); */
391#define BIO_set_proxy_cb(b,cb) BIO_callback_ctrl(b,BIO_C_SET_PROXY_PARAM,3,(void *(*cb)()))
392#define BIO_set_proxy_header(b,sk) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,4,(char *)sk)
393#define BIO_set_no_connect_return(b,bool) BIO_int_ctrl(b,BIO_C_SET_PROXY_PARAM,5,bool)
394
395#define BIO_get_proxy_header(b,skp) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,0,(char *)skp)
396#define BIO_get_proxies(b,pxy_p) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,1,(char *)(pxy_p))
397#define BIO_get_url(b,url) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,2,(char *)(url))
398#define BIO_get_no_connect_return(b) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,5,NULL)
399
400#define BIO_set_fd(b,fd,c) BIO_int_ctrl(b,BIO_C_SET_FD,c,fd)
401#define BIO_get_fd(b,c) BIO_ctrl(b,BIO_C_GET_FD,0,(char *)c)
402
403#define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp)
404#define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp)
405
406#define BIO_seek(b,ofs) (int)BIO_ctrl(b,BIO_C_FILE_SEEK,ofs,NULL)
407#define BIO_tell(b) (int)BIO_ctrl(b,BIO_C_FILE_TELL,0,NULL)
408
409/* name is cast to lose const, but might be better to route through a function
410 so we can do it safely */
411#ifdef CONST_STRICT
412/* If you are wondering why this isn't defined, its because CONST_STRICT is
413 * purely a compile-time kludge to allow const to be checked.
414 */
415int BIO_read_filename(BIO *b,const char *name);
416#else
417#define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
418 BIO_CLOSE|BIO_FP_READ,(char *)name)
419#endif
420#define BIO_write_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
421 BIO_CLOSE|BIO_FP_WRITE,name)
422#define BIO_append_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
423 BIO_CLOSE|BIO_FP_APPEND,name)
424#define BIO_rw_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
425 BIO_CLOSE|BIO_FP_READ|BIO_FP_WRITE,name)
426
427/* WARNING WARNING, this ups the reference count on the read bio of the
428 * SSL structure. This is because the ssl read BIO is now pointed to by
429 * the next_bio field in the bio. So when you free the BIO, make sure
430 * you are doing a BIO_free_all() to catch the underlying BIO. */
431#define BIO_set_ssl(b,ssl,c) BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)ssl)
432#define BIO_get_ssl(b,sslp) BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)sslp)
433#define BIO_set_ssl_mode(b,client) BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL)
434#define BIO_set_ssl_renegotiate_bytes(b,num) \
435 BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL);
436#define BIO_get_num_renegotiates(b) \
437 BIO_ctrl(b,BIO_C_GET_SSL_NUM_RENEGOTIATES,0,NULL);
438#define BIO_set_ssl_renegotiate_timeout(b,seconds) \
439 BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL);
440
441/* defined in evp.h */
442/* #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,1,(char *)md) */
443
444#define BIO_get_mem_data(b,pp) BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)pp)
445#define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)bm)
446#define BIO_get_mem_ptr(b,pp) BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0,(char *)pp)
447#define BIO_set_mem_eof_return(b,v) \
448 BIO_ctrl(b,BIO_C_SET_BUF_MEM_EOF_RETURN,v,NULL)
449
450/* For the BIO_f_buffer() type */
451#define BIO_get_buffer_num_lines(b) BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL)
452#define BIO_set_buffer_size(b,size) BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL)
453#define BIO_set_read_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0)
454#define BIO_set_write_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1)
455#define BIO_set_buffer_read_data(b,buf,num) BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf)
456
457/* Don't use the next one unless you know what you are doing :-) */
458#define BIO_dup_state(b,ret) BIO_ctrl(b,BIO_CTRL_DUP,0,(char *)(ret))
459
460#define BIO_reset(b) (int)BIO_ctrl(b,BIO_CTRL_RESET,0,NULL)
461#define BIO_eof(b) (int)BIO_ctrl(b,BIO_CTRL_EOF,0,NULL)
462#define BIO_set_close(b,c) (int)BIO_ctrl(b,BIO_CTRL_SET_CLOSE,(c),NULL)
463#define BIO_get_close(b) (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL)
464#define BIO_pending(b) (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL)
465#define BIO_wpending(b) (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL)
466/* ...pending macros have inappropriate return type */
467size_t BIO_ctrl_pending(BIO *b);
468size_t BIO_ctrl_wpending(BIO *b);
469#define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL)
470#define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0, \
471 cbp)
472#define BIO_set_info_callback(b,cb) (int)BIO_callback_ctrl(b,BIO_CTRL_SET_CALLBACK,cb)
473
474/* For the BIO_f_buffer() type */
475#define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL)
476
477/* For BIO_s_bio() */
478#define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL)
479#define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL)
480#define BIO_make_bio_pair(b1,b2) (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2)
481#define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL)
482#define BIO_shutdown_wr(b) (int)BIO_ctrl(b, BIO_C_SHUTDOWN_WR, 0, NULL)
483/* macros with inappropriate type -- but ...pending macros use int too: */
484#define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL)
485#define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL)
486size_t BIO_ctrl_get_write_guarantee(BIO *b);
487size_t BIO_ctrl_get_read_request(BIO *b);
488int BIO_ctrl_reset_read_request(BIO *b);
489
490/* These two aren't currently implemented */
491/* int BIO_get_ex_num(BIO *bio); */
492/* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */
493int BIO_set_ex_data(BIO *bio,int idx,void *data);
494void *BIO_get_ex_data(BIO *bio,int idx);
495int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
496 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
497unsigned long BIO_number_read(BIO *bio);
498unsigned long BIO_number_written(BIO *bio);
499
500# ifndef OPENSSL_NO_FP_API
501# if defined(OPENSSL_SYS_WIN16) && defined(_WINDLL)
502BIO_METHOD *BIO_s_file_internal(void);
503BIO *BIO_new_file_internal(char *filename, char *mode);
504BIO *BIO_new_fp_internal(FILE *stream, int close_flag);
505# define BIO_s_file BIO_s_file_internal
506# define BIO_new_file BIO_new_file_internal
507# define BIO_new_fp BIO_new_fp_internal
508# else /* FP_API */
509BIO_METHOD *BIO_s_file(void );
510BIO *BIO_new_file(const char *filename, const char *mode);
511BIO *BIO_new_fp(FILE *stream, int close_flag);
512# define BIO_s_file_internal BIO_s_file
513# define BIO_new_file_internal BIO_new_file
514# define BIO_new_fp_internal BIO_s_file
515# endif /* FP_API */
516# endif
517BIO * BIO_new(BIO_METHOD *type);
518int BIO_set(BIO *a,BIO_METHOD *type);
519int BIO_free(BIO *a);
520void BIO_vfree(BIO *a);
521int BIO_read(BIO *b, void *data, int len);
522int BIO_gets(BIO *bp,char *buf, int size);
523int BIO_write(BIO *b, const void *data, int len);
524int BIO_puts(BIO *bp,const char *buf);
525long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg);
526long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long));
527char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg);
528long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg);
529BIO * BIO_push(BIO *b,BIO *append);
530BIO * BIO_pop(BIO *b);
531void BIO_free_all(BIO *a);
532BIO * BIO_find_type(BIO *b,int bio_type);
533BIO * BIO_next(BIO *b);
534BIO * BIO_get_retry_BIO(BIO *bio, int *reason);
535int BIO_get_retry_reason(BIO *bio);
536BIO * BIO_dup_chain(BIO *in);
537
538int BIO_nread0(BIO *bio, char **buf);
539int BIO_nread(BIO *bio, char **buf, int num);
540int BIO_nwrite0(BIO *bio, char **buf);
541int BIO_nwrite(BIO *bio, char **buf, int num);
542
543#ifndef OPENSSL_SYS_WIN16
544long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,
545 long argl,long ret);
546#else
547long _far _loadds BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,
548 long argl,long ret);
549#endif
550
551BIO_METHOD *BIO_s_mem(void);
552BIO *BIO_new_mem_buf(void *buf, int len);
553BIO_METHOD *BIO_s_socket(void);
554BIO_METHOD *BIO_s_connect(void);
555BIO_METHOD *BIO_s_accept(void);
556BIO_METHOD *BIO_s_fd(void);
557#ifndef OPENSSL_SYS_OS2
558BIO_METHOD *BIO_s_log(void);
559#endif
560BIO_METHOD *BIO_s_bio(void);
561BIO_METHOD *BIO_s_null(void);
562BIO_METHOD *BIO_f_null(void);
563BIO_METHOD *BIO_f_buffer(void);
564#ifdef OPENSSL_SYS_VMS
565BIO_METHOD *BIO_f_linebuffer(void);
566#endif
567BIO_METHOD *BIO_f_nbio_test(void);
568/* BIO_METHOD *BIO_f_ber(void); */
569
570int BIO_sock_should_retry(int i);
571int BIO_sock_non_fatal_error(int error);
572int BIO_fd_should_retry(int i);
573int BIO_fd_non_fatal_error(int error);
574int BIO_dump(BIO *b,const char *bytes,int len);
575int BIO_dump_indent(BIO *b,const char *bytes,int len,int indent);
576
577struct hostent *BIO_gethostbyname(const char *name);
578/* We might want a thread-safe interface too:
579 * struct hostent *BIO_gethostbyname_r(const char *name,
580 * struct hostent *result, void *buffer, size_t buflen);
581 * or something similar (caller allocates a struct hostent,
582 * pointed to by "result", and additional buffer space for the various
583 * substructures; if the buffer does not suffice, NULL is returned
584 * and an appropriate error code is set).
585 */
586int BIO_sock_error(int sock);
587int BIO_socket_ioctl(int fd, long type, unsigned long *arg);
588int BIO_socket_nbio(int fd,int mode);
589int BIO_get_port(const char *str, unsigned short *port_ptr);
590int BIO_get_host_ip(const char *str, unsigned char *ip);
591int BIO_get_accept_socket(char *host_port,int mode);
592int BIO_accept(int sock,char **ip_port);
593int BIO_sock_init(void );
594void BIO_sock_cleanup(void);
595int BIO_set_tcp_ndelay(int sock,int turn_on);
596
597BIO *BIO_new_socket(int sock, int close_flag);
598BIO *BIO_new_fd(int fd, int close_flag);
599BIO *BIO_new_connect(char *host_port);
600BIO *BIO_new_accept(char *host_port);
601
602int BIO_new_bio_pair(BIO **bio1, size_t writebuf1,
603 BIO **bio2, size_t writebuf2);
604/* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints.
605 * Otherwise returns 0 and sets *bio1 and *bio2 to NULL.
606 * Size 0 uses default value.
607 */
608
609void BIO_copy_next_retry(BIO *b);
610
611long BIO_ghbn_ctrl(int cmd,int iarg,char *parg);
612
613int BIO_printf(BIO *bio, const char *format, ...);
614int BIO_vprintf(BIO *bio, const char *format, va_list args);
615int BIO_snprintf(char *buf, size_t n, const char *format, ...);
616int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args);
617
618/* BEGIN ERROR CODES */
619/* The following lines are auto generated by the script mkerr.pl. Any changes
620 * made after this point may be overwritten when the script is next run.
621 */
622void ERR_load_BIO_strings(void);
623
624/* Error codes for the BIO functions. */
625
626/* Function codes. */
627#define BIO_F_ACPT_STATE 100
628#define BIO_F_BIO_ACCEPT 101
629#define BIO_F_BIO_BER_GET_HEADER 102
630#define BIO_F_BIO_CTRL 103
631#define BIO_F_BIO_GETHOSTBYNAME 120
632#define BIO_F_BIO_GETS 104
633#define BIO_F_BIO_GET_ACCEPT_SOCKET 105
634#define BIO_F_BIO_GET_HOST_IP 106
635#define BIO_F_BIO_GET_PORT 107
636#define BIO_F_BIO_MAKE_PAIR 121
637#define BIO_F_BIO_NEW 108
638#define BIO_F_BIO_NEW_FILE 109
639#define BIO_F_BIO_NEW_MEM_BUF 126
640#define BIO_F_BIO_NREAD 123
641#define BIO_F_BIO_NREAD0 124
642#define BIO_F_BIO_NWRITE 125
643#define BIO_F_BIO_NWRITE0 122
644#define BIO_F_BIO_PUTS 110
645#define BIO_F_BIO_READ 111
646#define BIO_F_BIO_SOCK_INIT 112
647#define BIO_F_BIO_WRITE 113
648#define BIO_F_BUFFER_CTRL 114
649#define BIO_F_CONN_CTRL 127
650#define BIO_F_CONN_STATE 115
651#define BIO_F_FILE_CTRL 116
652#define BIO_F_FILE_READ 130
653#define BIO_F_LINEBUFFER_CTRL 129
654#define BIO_F_MEM_READ 128
655#define BIO_F_MEM_WRITE 117
656#define BIO_F_SSL_NEW 118
657#define BIO_F_WSASTARTUP 119
658
659/* Reason codes. */
660#define BIO_R_ACCEPT_ERROR 100
661#define BIO_R_BAD_FOPEN_MODE 101
662#define BIO_R_BAD_HOSTNAME_LOOKUP 102
663#define BIO_R_BROKEN_PIPE 124
664#define BIO_R_CONNECT_ERROR 103
665#define BIO_R_EOF_ON_MEMORY_BIO 127
666#define BIO_R_ERROR_SETTING_NBIO 104
667#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105
668#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106
669#define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107
670#define BIO_R_INVALID_ARGUMENT 125
671#define BIO_R_INVALID_IP_ADDRESS 108
672#define BIO_R_IN_USE 123
673#define BIO_R_KEEPALIVE 109
674#define BIO_R_NBIO_CONNECT_ERROR 110
675#define BIO_R_NO_ACCEPT_PORT_SPECIFIED 111
676#define BIO_R_NO_HOSTNAME_SPECIFIED 112
677#define BIO_R_NO_PORT_DEFINED 113
678#define BIO_R_NO_PORT_SPECIFIED 114
679#define BIO_R_NO_SUCH_FILE 128
680#define BIO_R_NULL_PARAMETER 115
681#define BIO_R_TAG_MISMATCH 116
682#define BIO_R_UNABLE_TO_BIND_SOCKET 117
683#define BIO_R_UNABLE_TO_CREATE_SOCKET 118
684#define BIO_R_UNABLE_TO_LISTEN_SOCKET 119
685#define BIO_R_UNINITIALIZED 120
686#define BIO_R_UNSUPPORTED_METHOD 121
687#define BIO_R_WRITE_TO_READ_ONLY_BIO 126
688#define BIO_R_WSASTARTUP 122
689
690#ifdef __cplusplus
691}
692#endif
693#endif
diff --git a/src/lib/libcrypto/bio/bio_cb.c b/src/lib/libcrypto/bio/bio_cb.c
deleted file mode 100644
index 0ffa4d2136..0000000000
--- a/src/lib/libcrypto/bio/bio_cb.c
+++ /dev/null
@@ -1,133 +0,0 @@
1/* crypto/bio/bio_cb.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <stdlib.h>
62#include "cryptlib.h"
63#include <openssl/bio.h>
64#include <openssl/err.h>
65
66long MS_CALLBACK BIO_debug_callback(BIO *bio, int cmd, const char *argp,
67 int argi, long argl, long ret)
68 {
69 BIO *b;
70 MS_STATIC char buf[256];
71 char *p;
72 long r=1;
73
74 if (BIO_CB_RETURN & cmd)
75 r=ret;
76
77 sprintf(buf,"BIO[%08lX]:",(unsigned long)bio);
78 p= &(buf[14]);
79 switch (cmd)
80 {
81 case BIO_CB_FREE:
82 sprintf(p,"Free - %s\n",bio->method->name);
83 break;
84 case BIO_CB_READ:
85 if (bio->method->type & BIO_TYPE_DESCRIPTOR)
86 sprintf(p,"read(%d,%d) - %s fd=%d\n",bio->num,argi,bio->method->name,bio->num);
87 else
88 sprintf(p,"read(%d,%d) - %s\n",bio->num,argi,bio->method->name);
89 break;
90 case BIO_CB_WRITE:
91 if (bio->method->type & BIO_TYPE_DESCRIPTOR)
92 sprintf(p,"write(%d,%d) - %s fd=%d\n",bio->num,argi,bio->method->name,bio->num);
93 else
94 sprintf(p,"write(%d,%d) - %s\n",bio->num,argi,bio->method->name);
95 break;
96 case BIO_CB_PUTS:
97 sprintf(p,"puts() - %s\n",bio->method->name);
98 break;
99 case BIO_CB_GETS:
100 sprintf(p,"gets(%d) - %s\n",argi,bio->method->name);
101 break;
102 case BIO_CB_CTRL:
103 sprintf(p,"ctrl(%d) - %s\n",argi,bio->method->name);
104 break;
105 case BIO_CB_RETURN|BIO_CB_READ:
106 sprintf(p,"read return %ld\n",ret);
107 break;
108 case BIO_CB_RETURN|BIO_CB_WRITE:
109 sprintf(p,"write return %ld\n",ret);
110 break;
111 case BIO_CB_RETURN|BIO_CB_GETS:
112 sprintf(p,"gets return %ld\n",ret);
113 break;
114 case BIO_CB_RETURN|BIO_CB_PUTS:
115 sprintf(p,"puts return %ld\n",ret);
116 break;
117 case BIO_CB_RETURN|BIO_CB_CTRL:
118 sprintf(p,"ctrl return %ld\n",ret);
119 break;
120 default:
121 sprintf(p,"bio callback - unknown type (%d)\n",cmd);
122 break;
123 }
124
125 b=(BIO *)bio->cb_arg;
126 if (b != NULL)
127 BIO_write(b,buf,strlen(buf));
128#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)
129 else
130 fputs(buf,stderr);
131#endif
132 return(r);
133 }
diff --git a/src/lib/libcrypto/bio/bio_err.c b/src/lib/libcrypto/bio/bio_err.c
deleted file mode 100644
index 68a119d895..0000000000
--- a/src/lib/libcrypto/bio/bio_err.c
+++ /dev/null
@@ -1,152 +0,0 @@
1/* crypto/bio/bio_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/bio.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA BIO_str_functs[]=
68 {
69{ERR_PACK(0,BIO_F_ACPT_STATE,0), "ACPT_STATE"},
70{ERR_PACK(0,BIO_F_BIO_ACCEPT,0), "BIO_accept"},
71{ERR_PACK(0,BIO_F_BIO_BER_GET_HEADER,0), "BIO_BER_GET_HEADER"},
72{ERR_PACK(0,BIO_F_BIO_CTRL,0), "BIO_ctrl"},
73{ERR_PACK(0,BIO_F_BIO_GETHOSTBYNAME,0), "BIO_gethostbyname"},
74{ERR_PACK(0,BIO_F_BIO_GETS,0), "BIO_gets"},
75{ERR_PACK(0,BIO_F_BIO_GET_ACCEPT_SOCKET,0), "BIO_get_accept_socket"},
76{ERR_PACK(0,BIO_F_BIO_GET_HOST_IP,0), "BIO_get_host_ip"},
77{ERR_PACK(0,BIO_F_BIO_GET_PORT,0), "BIO_get_port"},
78{ERR_PACK(0,BIO_F_BIO_MAKE_PAIR,0), "BIO_MAKE_PAIR"},
79{ERR_PACK(0,BIO_F_BIO_NEW,0), "BIO_new"},
80{ERR_PACK(0,BIO_F_BIO_NEW_FILE,0), "BIO_new_file"},
81{ERR_PACK(0,BIO_F_BIO_NEW_MEM_BUF,0), "BIO_new_mem_buf"},
82{ERR_PACK(0,BIO_F_BIO_NREAD,0), "BIO_nread"},
83{ERR_PACK(0,BIO_F_BIO_NREAD0,0), "BIO_nread0"},
84{ERR_PACK(0,BIO_F_BIO_NWRITE,0), "BIO_nwrite"},
85{ERR_PACK(0,BIO_F_BIO_NWRITE0,0), "BIO_nwrite0"},
86{ERR_PACK(0,BIO_F_BIO_PUTS,0), "BIO_puts"},
87{ERR_PACK(0,BIO_F_BIO_READ,0), "BIO_read"},
88{ERR_PACK(0,BIO_F_BIO_SOCK_INIT,0), "BIO_sock_init"},
89{ERR_PACK(0,BIO_F_BIO_WRITE,0), "BIO_write"},
90{ERR_PACK(0,BIO_F_BUFFER_CTRL,0), "BUFFER_CTRL"},
91{ERR_PACK(0,BIO_F_CONN_CTRL,0), "CONN_CTRL"},
92{ERR_PACK(0,BIO_F_CONN_STATE,0), "CONN_STATE"},
93{ERR_PACK(0,BIO_F_FILE_CTRL,0), "FILE_CTRL"},
94{ERR_PACK(0,BIO_F_FILE_READ,0), "FILE_READ"},
95{ERR_PACK(0,BIO_F_LINEBUFFER_CTRL,0), "LINEBUFFER_CTRL"},
96{ERR_PACK(0,BIO_F_MEM_READ,0), "MEM_READ"},
97{ERR_PACK(0,BIO_F_MEM_WRITE,0), "MEM_WRITE"},
98{ERR_PACK(0,BIO_F_SSL_NEW,0), "SSL_new"},
99{ERR_PACK(0,BIO_F_WSASTARTUP,0), "WSASTARTUP"},
100{0,NULL}
101 };
102
103static ERR_STRING_DATA BIO_str_reasons[]=
104 {
105{BIO_R_ACCEPT_ERROR ,"accept error"},
106{BIO_R_BAD_FOPEN_MODE ,"bad fopen mode"},
107{BIO_R_BAD_HOSTNAME_LOOKUP ,"bad hostname lookup"},
108{BIO_R_BROKEN_PIPE ,"broken pipe"},
109{BIO_R_CONNECT_ERROR ,"connect error"},
110{BIO_R_EOF_ON_MEMORY_BIO ,"EOF on memory BIO"},
111{BIO_R_ERROR_SETTING_NBIO ,"error setting nbio"},
112{BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET,"error setting nbio on accepted socket"},
113{BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET,"error setting nbio on accept socket"},
114{BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET ,"gethostbyname addr is not af inet"},
115{BIO_R_INVALID_ARGUMENT ,"invalid argument"},
116{BIO_R_INVALID_IP_ADDRESS ,"invalid ip address"},
117{BIO_R_IN_USE ,"in use"},
118{BIO_R_KEEPALIVE ,"keepalive"},
119{BIO_R_NBIO_CONNECT_ERROR ,"nbio connect error"},
120{BIO_R_NO_ACCEPT_PORT_SPECIFIED ,"no accept port specified"},
121{BIO_R_NO_HOSTNAME_SPECIFIED ,"no hostname specified"},
122{BIO_R_NO_PORT_DEFINED ,"no port defined"},
123{BIO_R_NO_PORT_SPECIFIED ,"no port specified"},
124{BIO_R_NO_SUCH_FILE ,"no such file"},
125{BIO_R_NULL_PARAMETER ,"null parameter"},
126{BIO_R_TAG_MISMATCH ,"tag mismatch"},
127{BIO_R_UNABLE_TO_BIND_SOCKET ,"unable to bind socket"},
128{BIO_R_UNABLE_TO_CREATE_SOCKET ,"unable to create socket"},
129{BIO_R_UNABLE_TO_LISTEN_SOCKET ,"unable to listen socket"},
130{BIO_R_UNINITIALIZED ,"uninitialized"},
131{BIO_R_UNSUPPORTED_METHOD ,"unsupported method"},
132{BIO_R_WRITE_TO_READ_ONLY_BIO ,"write to read only BIO"},
133{BIO_R_WSASTARTUP ,"WSAStartup"},
134{0,NULL}
135 };
136
137#endif
138
139void ERR_load_BIO_strings(void)
140 {
141 static int init=1;
142
143 if (init)
144 {
145 init=0;
146#ifndef OPENSSL_NO_ERR
147 ERR_load_strings(ERR_LIB_BIO,BIO_str_functs);
148 ERR_load_strings(ERR_LIB_BIO,BIO_str_reasons);
149#endif
150
151 }
152 }
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c
deleted file mode 100644
index 50df2238fa..0000000000
--- a/src/lib/libcrypto/bio/bio_lib.c
+++ /dev/null
@@ -1,543 +0,0 @@
1/* crypto/bio/bio_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include <openssl/crypto.h>
62#include "cryptlib.h"
63#include <openssl/bio.h>
64#include <openssl/stack.h>
65
66BIO *BIO_new(BIO_METHOD *method)
67 {
68 BIO *ret=NULL;
69
70 ret=(BIO *)OPENSSL_malloc(sizeof(BIO));
71 if (ret == NULL)
72 {
73 BIOerr(BIO_F_BIO_NEW,ERR_R_MALLOC_FAILURE);
74 return(NULL);
75 }
76 if (!BIO_set(ret,method))
77 {
78 OPENSSL_free(ret);
79 ret=NULL;
80 }
81 return(ret);
82 }
83
84int BIO_set(BIO *bio, BIO_METHOD *method)
85 {
86 bio->method=method;
87 bio->callback=NULL;
88 bio->cb_arg=NULL;
89 bio->init=0;
90 bio->shutdown=1;
91 bio->flags=0;
92 bio->retry_reason=0;
93 bio->num=0;
94 bio->ptr=NULL;
95 bio->prev_bio=NULL;
96 bio->next_bio=NULL;
97 bio->references=1;
98 bio->num_read=0L;
99 bio->num_write=0L;
100 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data);
101 if (method->create != NULL)
102 if (!method->create(bio))
103 {
104 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio,
105 &bio->ex_data);
106 return(0);
107 }
108 return(1);
109 }
110
111int BIO_free(BIO *a)
112 {
113 int ret=0,i;
114
115 if (a == NULL) return(0);
116
117 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_BIO);
118#ifdef REF_PRINT
119 REF_PRINT("BIO",a);
120#endif
121 if (i > 0) return(1);
122#ifdef REF_CHECK
123 if (i < 0)
124 {
125 fprintf(stderr,"BIO_free, bad reference count\n");
126 abort();
127 }
128#endif
129 if ((a->callback != NULL) &&
130 ((i=(int)a->callback(a,BIO_CB_FREE,NULL,0,0L,1L)) <= 0))
131 return(i);
132
133 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, a, &a->ex_data);
134
135 if ((a->method == NULL) || (a->method->destroy == NULL)) return(1);
136 ret=a->method->destroy(a);
137 OPENSSL_free(a);
138 return(1);
139 }
140
141void BIO_vfree(BIO *a)
142 { BIO_free(a); }
143
144int BIO_read(BIO *b, void *out, int outl)
145 {
146 int i;
147 long (*cb)();
148
149 if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL))
150 {
151 BIOerr(BIO_F_BIO_READ,BIO_R_UNSUPPORTED_METHOD);
152 return(-2);
153 }
154
155 cb=b->callback;
156 if ((cb != NULL) &&
157 ((i=(int)cb(b,BIO_CB_READ,out,outl,0L,1L)) <= 0))
158 return(i);
159
160 if (!b->init)
161 {
162 BIOerr(BIO_F_BIO_READ,BIO_R_UNINITIALIZED);
163 return(-2);
164 }
165
166 i=b->method->bread(b,out,outl);
167
168 if (i > 0) b->num_read+=(unsigned long)i;
169
170 if (cb != NULL)
171 i=(int)cb(b,BIO_CB_READ|BIO_CB_RETURN,out,outl,
172 0L,(long)i);
173 return(i);
174 }
175
176int BIO_write(BIO *b, const void *in, int inl)
177 {
178 int i;
179 long (*cb)();
180
181 if (b == NULL)
182 return(0);
183
184 cb=b->callback;
185 if ((b->method == NULL) || (b->method->bwrite == NULL))
186 {
187 BIOerr(BIO_F_BIO_WRITE,BIO_R_UNSUPPORTED_METHOD);
188 return(-2);
189 }
190
191 if ((cb != NULL) &&
192 ((i=(int)cb(b,BIO_CB_WRITE,in,inl,0L,1L)) <= 0))
193 return(i);
194
195 if (!b->init)
196 {
197 BIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITIALIZED);
198 return(-2);
199 }
200
201 i=b->method->bwrite(b,in,inl);
202
203 if (i > 0) b->num_write+=(unsigned long)i;
204
205 if (cb != NULL)
206 i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl,
207 0L,(long)i);
208 return(i);
209 }
210
211int BIO_puts(BIO *b, const char *in)
212 {
213 int i;
214 long (*cb)();
215
216 if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL))
217 {
218 BIOerr(BIO_F_BIO_PUTS,BIO_R_UNSUPPORTED_METHOD);
219 return(-2);
220 }
221
222 cb=b->callback;
223
224 if ((cb != NULL) &&
225 ((i=(int)cb(b,BIO_CB_PUTS,in,0,0L,1L)) <= 0))
226 return(i);
227
228 if (!b->init)
229 {
230 BIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITIALIZED);
231 return(-2);
232 }
233
234 i=b->method->bputs(b,in);
235
236 if (i > 0) b->num_write+=(unsigned long)i;
237
238 if (cb != NULL)
239 i=(int)cb(b,BIO_CB_PUTS|BIO_CB_RETURN,in,0,
240 0L,(long)i);
241 return(i);
242 }
243
244int BIO_gets(BIO *b, char *in, int inl)
245 {
246 int i;
247 long (*cb)();
248
249 if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL))
250 {
251 BIOerr(BIO_F_BIO_GETS,BIO_R_UNSUPPORTED_METHOD);
252 return(-2);
253 }
254
255 cb=b->callback;
256
257 if ((cb != NULL) &&
258 ((i=(int)cb(b,BIO_CB_GETS,in,inl,0L,1L)) <= 0))
259 return(i);
260
261 if (!b->init)
262 {
263 BIOerr(BIO_F_BIO_GETS,BIO_R_UNINITIALIZED);
264 return(-2);
265 }
266
267 i=b->method->bgets(b,in,inl);
268
269 if (cb != NULL)
270 i=(int)cb(b,BIO_CB_GETS|BIO_CB_RETURN,in,inl,
271 0L,(long)i);
272 return(i);
273 }
274
275long BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg)
276 {
277 int i;
278
279 i=iarg;
280 return(BIO_ctrl(b,cmd,larg,(char *)&i));
281 }
282
283char *BIO_ptr_ctrl(BIO *b, int cmd, long larg)
284 {
285 char *p=NULL;
286
287 if (BIO_ctrl(b,cmd,larg,(char *)&p) <= 0)
288 return(NULL);
289 else
290 return(p);
291 }
292
293long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)
294 {
295 long ret;
296 long (*cb)();
297
298 if (b == NULL) return(0);
299
300 if ((b->method == NULL) || (b->method->ctrl == NULL))
301 {
302 BIOerr(BIO_F_BIO_CTRL,BIO_R_UNSUPPORTED_METHOD);
303 return(-2);
304 }
305
306 cb=b->callback;
307
308 if ((cb != NULL) &&
309 ((ret=cb(b,BIO_CB_CTRL,parg,cmd,larg,1L)) <= 0))
310 return(ret);
311
312 ret=b->method->ctrl(b,cmd,larg,parg);
313
314 if (cb != NULL)
315 ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,parg,cmd,
316 larg,ret);
317 return(ret);
318 }
319
320long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long))
321 {
322 long ret;
323 long (*cb)();
324
325 if (b == NULL) return(0);
326
327 if ((b->method == NULL) || (b->method->callback_ctrl == NULL))
328 {
329 BIOerr(BIO_F_BIO_CTRL,BIO_R_UNSUPPORTED_METHOD);
330 return(-2);
331 }
332
333 cb=b->callback;
334
335 if ((cb != NULL) &&
336 ((ret=cb(b,BIO_CB_CTRL,(void *)&fp,cmd,0,1L)) <= 0))
337 return(ret);
338
339 ret=b->method->callback_ctrl(b,cmd,fp);
340
341 if (cb != NULL)
342 ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,(void *)&fp,cmd,
343 0,ret);
344 return(ret);
345 }
346
347/* It is unfortunate to duplicate in functions what the BIO_(w)pending macros
348 * do; but those macros have inappropriate return type, and for interfacing
349 * from other programming languages, C macros aren't much of a help anyway. */
350size_t BIO_ctrl_pending(BIO *bio)
351 {
352 return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL);
353 }
354
355size_t BIO_ctrl_wpending(BIO *bio)
356 {
357 return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL);
358 }
359
360
361/* put the 'bio' on the end of b's list of operators */
362BIO *BIO_push(BIO *b, BIO *bio)
363 {
364 BIO *lb;
365
366 if (b == NULL) return(bio);
367 lb=b;
368 while (lb->next_bio != NULL)
369 lb=lb->next_bio;
370 lb->next_bio=bio;
371 if (bio != NULL)
372 bio->prev_bio=lb;
373 /* called to do internal processing */
374 BIO_ctrl(b,BIO_CTRL_PUSH,0,NULL);
375 return(b);
376 }
377
378/* Remove the first and return the rest */
379BIO *BIO_pop(BIO *b)
380 {
381 BIO *ret;
382
383 if (b == NULL) return(NULL);
384 ret=b->next_bio;
385
386 if (b->prev_bio != NULL)
387 b->prev_bio->next_bio=b->next_bio;
388 if (b->next_bio != NULL)
389 b->next_bio->prev_bio=b->prev_bio;
390
391 b->next_bio=NULL;
392 b->prev_bio=NULL;
393 BIO_ctrl(b,BIO_CTRL_POP,0,NULL);
394 return(ret);
395 }
396
397BIO *BIO_get_retry_BIO(BIO *bio, int *reason)
398 {
399 BIO *b,*last;
400
401 b=last=bio;
402 for (;;)
403 {
404 if (!BIO_should_retry(b)) break;
405 last=b;
406 b=b->next_bio;
407 if (b == NULL) break;
408 }
409 if (reason != NULL) *reason=last->retry_reason;
410 return(last);
411 }
412
413int BIO_get_retry_reason(BIO *bio)
414 {
415 return(bio->retry_reason);
416 }
417
418BIO *BIO_find_type(BIO *bio, int type)
419 {
420 int mt,mask;
421
422 if(!bio) return NULL;
423 mask=type&0xff;
424 do {
425 if (bio->method != NULL)
426 {
427 mt=bio->method->type;
428
429 if (!mask)
430 {
431 if (mt & type) return(bio);
432 }
433 else if (mt == type)
434 return(bio);
435 }
436 bio=bio->next_bio;
437 } while (bio != NULL);
438 return(NULL);
439 }
440
441BIO *BIO_next(BIO *b)
442 {
443 if(!b) return NULL;
444 return b->next_bio;
445 }
446
447void BIO_free_all(BIO *bio)
448 {
449 BIO *b;
450 int ref;
451
452 while (bio != NULL)
453 {
454 b=bio;
455 ref=b->references;
456 bio=bio->next_bio;
457 BIO_free(b);
458 /* Since ref count > 1, don't free anyone else. */
459 if (ref > 1) break;
460 }
461 }
462
463BIO *BIO_dup_chain(BIO *in)
464 {
465 BIO *ret=NULL,*eoc=NULL,*bio,*new;
466
467 for (bio=in; bio != NULL; bio=bio->next_bio)
468 {
469 if ((new=BIO_new(bio->method)) == NULL) goto err;
470 new->callback=bio->callback;
471 new->cb_arg=bio->cb_arg;
472 new->init=bio->init;
473 new->shutdown=bio->shutdown;
474 new->flags=bio->flags;
475
476 /* This will let SSL_s_sock() work with stdin/stdout */
477 new->num=bio->num;
478
479 if (!BIO_dup_state(bio,(char *)new))
480 {
481 BIO_free(new);
482 goto err;
483 }
484
485 /* copy app data */
486 if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_BIO, &new->ex_data,
487 &bio->ex_data))
488 goto err;
489
490 if (ret == NULL)
491 {
492 eoc=new;
493 ret=eoc;
494 }
495 else
496 {
497 BIO_push(eoc,new);
498 eoc=new;
499 }
500 }
501 return(ret);
502err:
503 if (ret != NULL)
504 BIO_free(ret);
505 return(NULL);
506 }
507
508void BIO_copy_next_retry(BIO *b)
509 {
510 BIO_set_flags(b,BIO_get_retry_flags(b->next_bio));
511 b->retry_reason=b->next_bio->retry_reason;
512 }
513
514int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
515 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
516 {
517 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_BIO, argl, argp,
518 new_func, dup_func, free_func);
519 }
520
521int BIO_set_ex_data(BIO *bio, int idx, void *data)
522 {
523 return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data));
524 }
525
526void *BIO_get_ex_data(BIO *bio, int idx)
527 {
528 return(CRYPTO_get_ex_data(&(bio->ex_data),idx));
529 }
530
531unsigned long BIO_number_read(BIO *bio)
532{
533 if(bio) return bio->num_read;
534 return 0;
535}
536
537unsigned long BIO_number_written(BIO *bio)
538{
539 if(bio) return bio->num_write;
540 return 0;
541}
542
543IMPLEMENT_STACK_OF(BIO)
diff --git a/src/lib/libcrypto/bio/bss_acpt.c b/src/lib/libcrypto/bio/bss_acpt.c
deleted file mode 100644
index 8ea1db158b..0000000000
--- a/src/lib/libcrypto/bio/bss_acpt.c
+++ /dev/null
@@ -1,479 +0,0 @@
1/* crypto/bio/bss_acpt.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_SOCK
60
61#include <stdio.h>
62#include <errno.h>
63#define USE_SOCKETS
64#include "cryptlib.h"
65#include <openssl/bio.h>
66
67#ifdef OPENSSL_SYS_WIN16
68#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
69#else
70#define SOCKET_PROTOCOL IPPROTO_TCP
71#endif
72
73#if (defined(OPENSSL_SYS_VMS) && __VMS_VER < 70000000)
74/* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */
75#undef FIONBIO
76#endif
77
78typedef struct bio_accept_st
79 {
80 int state;
81 char *param_addr;
82
83 int accept_sock;
84 int accept_nbio;
85
86 char *addr;
87 int nbio;
88 /* If 0, it means normal, if 1, do a connect on bind failure,
89 * and if there is no-one listening, bind with SO_REUSEADDR.
90 * If 2, always use SO_REUSEADDR. */
91 int bind_mode;
92 BIO *bio_chain;
93 } BIO_ACCEPT;
94
95static int acpt_write(BIO *h, const char *buf, int num);
96static int acpt_read(BIO *h, char *buf, int size);
97static int acpt_puts(BIO *h, const char *str);
98static long acpt_ctrl(BIO *h, int cmd, long arg1, void *arg2);
99static int acpt_new(BIO *h);
100static int acpt_free(BIO *data);
101static int acpt_state(BIO *b, BIO_ACCEPT *c);
102static void acpt_close_socket(BIO *data);
103BIO_ACCEPT *BIO_ACCEPT_new(void );
104void BIO_ACCEPT_free(BIO_ACCEPT *a);
105
106#define ACPT_S_BEFORE 1
107#define ACPT_S_GET_ACCEPT_SOCKET 2
108#define ACPT_S_OK 3
109
110static BIO_METHOD methods_acceptp=
111 {
112 BIO_TYPE_ACCEPT,
113 "socket accept",
114 acpt_write,
115 acpt_read,
116 acpt_puts,
117 NULL, /* connect_gets, */
118 acpt_ctrl,
119 acpt_new,
120 acpt_free,
121 NULL,
122 };
123
124BIO_METHOD *BIO_s_accept(void)
125 {
126 return(&methods_acceptp);
127 }
128
129static int acpt_new(BIO *bi)
130 {
131 BIO_ACCEPT *ba;
132
133 bi->init=0;
134 bi->num=INVALID_SOCKET;
135 bi->flags=0;
136 if ((ba=BIO_ACCEPT_new()) == NULL)
137 return(0);
138 bi->ptr=(char *)ba;
139 ba->state=ACPT_S_BEFORE;
140 bi->shutdown=1;
141 return(1);
142 }
143
144BIO_ACCEPT *BIO_ACCEPT_new(void)
145 {
146 BIO_ACCEPT *ret;
147
148 if ((ret=(BIO_ACCEPT *)OPENSSL_malloc(sizeof(BIO_ACCEPT))) == NULL)
149 return(NULL);
150
151 memset(ret,0,sizeof(BIO_ACCEPT));
152 ret->accept_sock=INVALID_SOCKET;
153 ret->bind_mode=BIO_BIND_NORMAL;
154 return(ret);
155 }
156
157void BIO_ACCEPT_free(BIO_ACCEPT *a)
158 {
159 if(a == NULL)
160 return;
161
162 if (a->param_addr != NULL) OPENSSL_free(a->param_addr);
163 if (a->addr != NULL) OPENSSL_free(a->addr);
164 if (a->bio_chain != NULL) BIO_free(a->bio_chain);
165 OPENSSL_free(a);
166 }
167
168static void acpt_close_socket(BIO *bio)
169 {
170 BIO_ACCEPT *c;
171
172 c=(BIO_ACCEPT *)bio->ptr;
173 if (c->accept_sock != INVALID_SOCKET)
174 {
175 shutdown(c->accept_sock,2);
176 closesocket(c->accept_sock);
177 c->accept_sock=INVALID_SOCKET;
178 bio->num=INVALID_SOCKET;
179 }
180 }
181
182static int acpt_free(BIO *a)
183 {
184 BIO_ACCEPT *data;
185
186 if (a == NULL) return(0);
187 data=(BIO_ACCEPT *)a->ptr;
188
189 if (a->shutdown)
190 {
191 acpt_close_socket(a);
192 BIO_ACCEPT_free(data);
193 a->ptr=NULL;
194 a->flags=0;
195 a->init=0;
196 }
197 return(1);
198 }
199
200static int acpt_state(BIO *b, BIO_ACCEPT *c)
201 {
202 BIO *bio=NULL,*dbio;
203 int s= -1;
204 int i;
205
206again:
207 switch (c->state)
208 {
209 case ACPT_S_BEFORE:
210 if (c->param_addr == NULL)
211 {
212 BIOerr(BIO_F_ACPT_STATE,BIO_R_NO_ACCEPT_PORT_SPECIFIED);
213 return(-1);
214 }
215 s=BIO_get_accept_socket(c->param_addr,c->bind_mode);
216 if (s == INVALID_SOCKET)
217 return(-1);
218
219 if (c->accept_nbio)
220 {
221 if (!BIO_socket_nbio(s,1))
222 {
223 closesocket(s);
224 BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET);
225 return(-1);
226 }
227 }
228 c->accept_sock=s;
229 b->num=s;
230 c->state=ACPT_S_GET_ACCEPT_SOCKET;
231 return(1);
232 /* break; */
233 case ACPT_S_GET_ACCEPT_SOCKET:
234 if (b->next_bio != NULL)
235 {
236 c->state=ACPT_S_OK;
237 goto again;
238 }
239 BIO_clear_retry_flags(b);
240 b->retry_reason=0;
241 i=BIO_accept(c->accept_sock,&(c->addr));
242
243 /* -2 return means we should retry */
244 if(i == -2)
245 {
246 BIO_set_retry_special(b);
247 b->retry_reason=BIO_RR_ACCEPT;
248 return -1;
249 }
250
251 if (i < 0) return(i);
252
253 bio=BIO_new_socket(i,BIO_CLOSE);
254 if (bio == NULL) goto err;
255
256 BIO_set_callback(bio,BIO_get_callback(b));
257 BIO_set_callback_arg(bio,BIO_get_callback_arg(b));
258
259 if (c->nbio)
260 {
261 if (!BIO_socket_nbio(i,1))
262 {
263 BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET);
264 goto err;
265 }
266 }
267
268 /* If the accept BIO has an bio_chain, we dup it and
269 * put the new socket at the end. */
270 if (c->bio_chain != NULL)
271 {
272 if ((dbio=BIO_dup_chain(c->bio_chain)) == NULL)
273 goto err;
274 if (!BIO_push(dbio,bio)) goto err;
275 bio=dbio;
276 }
277 if (BIO_push(b,bio) == NULL) goto err;
278
279 c->state=ACPT_S_OK;
280 return(1);
281err:
282 if (bio != NULL)
283 BIO_free(bio);
284 else if (s >= 0)
285 closesocket(s);
286 return(0);
287 /* break; */
288 case ACPT_S_OK:
289 if (b->next_bio == NULL)
290 {
291 c->state=ACPT_S_GET_ACCEPT_SOCKET;
292 goto again;
293 }
294 return(1);
295 /* break; */
296 default:
297 return(0);
298 /* break; */
299 }
300
301 }
302
303static int acpt_read(BIO *b, char *out, int outl)
304 {
305 int ret=0;
306 BIO_ACCEPT *data;
307
308 BIO_clear_retry_flags(b);
309 data=(BIO_ACCEPT *)b->ptr;
310
311 while (b->next_bio == NULL)
312 {
313 ret=acpt_state(b,data);
314 if (ret <= 0) return(ret);
315 }
316
317 ret=BIO_read(b->next_bio,out,outl);
318 BIO_copy_next_retry(b);
319 return(ret);
320 }
321
322static int acpt_write(BIO *b, const char *in, int inl)
323 {
324 int ret;
325 BIO_ACCEPT *data;
326
327 BIO_clear_retry_flags(b);
328 data=(BIO_ACCEPT *)b->ptr;
329
330 while (b->next_bio == NULL)
331 {
332 ret=acpt_state(b,data);
333 if (ret <= 0) return(ret);
334 }
335
336 ret=BIO_write(b->next_bio,in,inl);
337 BIO_copy_next_retry(b);
338 return(ret);
339 }
340
341static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr)
342 {
343 BIO *dbio;
344 int *ip;
345 long ret=1;
346 BIO_ACCEPT *data;
347 char **pp;
348
349 data=(BIO_ACCEPT *)b->ptr;
350
351 switch (cmd)
352 {
353 case BIO_CTRL_RESET:
354 ret=0;
355 data->state=ACPT_S_BEFORE;
356 acpt_close_socket(b);
357 b->flags=0;
358 break;
359 case BIO_C_DO_STATE_MACHINE:
360 /* use this one to start the connection */
361 ret=(long)acpt_state(b,data);
362 break;
363 case BIO_C_SET_ACCEPT:
364 if (ptr != NULL)
365 {
366 if (num == 0)
367 {
368 b->init=1;
369 if (data->param_addr != NULL)
370 OPENSSL_free(data->param_addr);
371 data->param_addr=BUF_strdup(ptr);
372 }
373 else if (num == 1)
374 {
375 data->accept_nbio=(ptr != NULL);
376 }
377 else if (num == 2)
378 {
379 if (data->bio_chain != NULL)
380 BIO_free(data->bio_chain);
381 data->bio_chain=(BIO *)ptr;
382 }
383 }
384 break;
385 case BIO_C_SET_NBIO:
386 data->nbio=(int)num;
387 break;
388 case BIO_C_SET_FD:
389 b->init=1;
390 b->num= *((int *)ptr);
391 data->accept_sock=b->num;
392 data->state=ACPT_S_GET_ACCEPT_SOCKET;
393 b->shutdown=(int)num;
394 b->init=1;
395 break;
396 case BIO_C_GET_FD:
397 if (b->init)
398 {
399 ip=(int *)ptr;
400 if (ip != NULL)
401 *ip=data->accept_sock;
402 ret=data->accept_sock;
403 }
404 else
405 ret= -1;
406 break;
407 case BIO_C_GET_ACCEPT:
408 if (b->init)
409 {
410 if (ptr != NULL)
411 {
412 pp=(char **)ptr;
413 *pp=data->param_addr;
414 }
415 else
416 ret= -1;
417 }
418 else
419 ret= -1;
420 break;
421 case BIO_CTRL_GET_CLOSE:
422 ret=b->shutdown;
423 break;
424 case BIO_CTRL_SET_CLOSE:
425 b->shutdown=(int)num;
426 break;
427 case BIO_CTRL_PENDING:
428 case BIO_CTRL_WPENDING:
429 ret=0;
430 break;
431 case BIO_CTRL_FLUSH:
432 break;
433 case BIO_C_SET_BIND_MODE:
434 data->bind_mode=(int)num;
435 break;
436 case BIO_C_GET_BIND_MODE:
437 ret=(long)data->bind_mode;
438 break;
439 case BIO_CTRL_DUP:
440 dbio=(BIO *)ptr;
441/* if (data->param_port) EAY EAY
442 BIO_set_port(dbio,data->param_port);
443 if (data->param_hostname)
444 BIO_set_hostname(dbio,data->param_hostname);
445 BIO_set_nbio(dbio,data->nbio); */
446 break;
447
448 default:
449 ret=0;
450 break;
451 }
452 return(ret);
453 }
454
455static int acpt_puts(BIO *bp, const char *str)
456 {
457 int n,ret;
458
459 n=strlen(str);
460 ret=acpt_write(bp,str,n);
461 return(ret);
462 }
463
464BIO *BIO_new_accept(char *str)
465 {
466 BIO *ret;
467
468 ret=BIO_new(BIO_s_accept());
469 if (ret == NULL) return(NULL);
470 if (BIO_set_accept_port(ret,str))
471 return(ret);
472 else
473 {
474 BIO_free(ret);
475 return(NULL);
476 }
477 }
478
479#endif
diff --git a/src/lib/libcrypto/bio/bss_bio.c b/src/lib/libcrypto/bio/bss_bio.c
deleted file mode 100644
index 1c485a4479..0000000000
--- a/src/lib/libcrypto/bio/bss_bio.c
+++ /dev/null
@@ -1,872 +0,0 @@
1/* crypto/bio/bss_bio.c -*- Mode: C; c-file-style: "eay" -*- */
2
3/* Special method for a BIO where the other endpoint is also a BIO
4 * of this kind, handled by the same thread (i.e. the "peer" is actually
5 * ourselves, wearing a different hat).
6 * Such "BIO pairs" are mainly for using the SSL library with I/O interfaces
7 * for which no specific BIO method is available.
8 * See ssl/ssltest.c for some hints on how this can be used. */
9
10/* BIO_DEBUG implies BIO_PAIR_DEBUG */
11#ifdef BIO_DEBUG
12# ifndef BIO_PAIR_DEBUG
13# define BIO_PAIR_DEBUG
14# endif
15#endif
16
17/* disable assert() unless BIO_PAIR_DEBUG has been defined */
18#ifndef BIO_PAIR_DEBUG
19# ifndef NDEBUG
20# define NDEBUG
21# endif
22#endif
23
24#include <assert.h>
25#include <limits.h>
26#include <stdlib.h>
27#include <string.h>
28
29#include <openssl/bio.h>
30#include <openssl/err.h>
31#include <openssl/err.h>
32#include <openssl/crypto.h>
33
34#include "e_os.h"
35
36/* VxWorks defines SSIZE_MAX with an empty value causing compile errors */
37#if defined(OPENSSL_SYS_VSWORKS)
38# undef SSIZE_MAX
39#endif
40#ifndef SSIZE_MAX
41# define SSIZE_MAX INT_MAX
42#endif
43
44static int bio_new(BIO *bio);
45static int bio_free(BIO *bio);
46static int bio_read(BIO *bio, char *buf, int size);
47static int bio_write(BIO *bio, const char *buf, int num);
48static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr);
49static int bio_puts(BIO *bio, const char *str);
50
51static int bio_make_pair(BIO *bio1, BIO *bio2);
52static void bio_destroy_pair(BIO *bio);
53
54static BIO_METHOD methods_biop =
55{
56 BIO_TYPE_BIO,
57 "BIO pair",
58 bio_write,
59 bio_read,
60 bio_puts,
61 NULL /* no bio_gets */,
62 bio_ctrl,
63 bio_new,
64 bio_free,
65 NULL /* no bio_callback_ctrl */
66};
67
68BIO_METHOD *BIO_s_bio(void)
69 {
70 return &methods_biop;
71 }
72
73struct bio_bio_st
74{
75 BIO *peer; /* NULL if buf == NULL.
76 * If peer != NULL, then peer->ptr is also a bio_bio_st,
77 * and its "peer" member points back to us.
78 * peer != NULL iff init != 0 in the BIO. */
79
80 /* This is for what we write (i.e. reading uses peer's struct): */
81 int closed; /* valid iff peer != NULL */
82 size_t len; /* valid iff buf != NULL; 0 if peer == NULL */
83 size_t offset; /* valid iff buf != NULL; 0 if len == 0 */
84 size_t size;
85 char *buf; /* "size" elements (if != NULL) */
86
87 size_t request; /* valid iff peer != NULL; 0 if len != 0,
88 * otherwise set by peer to number of bytes
89 * it (unsuccessfully) tried to read,
90 * never more than buffer space (size-len) warrants. */
91};
92
93static int bio_new(BIO *bio)
94 {
95 struct bio_bio_st *b;
96
97 b = OPENSSL_malloc(sizeof *b);
98 if (b == NULL)
99 return 0;
100
101 b->peer = NULL;
102 b->size = 17*1024; /* enough for one TLS record (just a default) */
103 b->buf = NULL;
104
105 bio->ptr = b;
106 return 1;
107 }
108
109
110static int bio_free(BIO *bio)
111 {
112 struct bio_bio_st *b;
113
114 if (bio == NULL)
115 return 0;
116 b = bio->ptr;
117
118 assert(b != NULL);
119
120 if (b->peer)
121 bio_destroy_pair(bio);
122
123 if (b->buf != NULL)
124 {
125 OPENSSL_free(b->buf);
126 }
127
128 OPENSSL_free(b);
129
130 return 1;
131 }
132
133
134
135static int bio_read(BIO *bio, char *buf, int size_)
136 {
137 size_t size = size_;
138 size_t rest;
139 struct bio_bio_st *b, *peer_b;
140
141 BIO_clear_retry_flags(bio);
142
143 if (!bio->init)
144 return 0;
145
146 b = bio->ptr;
147 assert(b != NULL);
148 assert(b->peer != NULL);
149 peer_b = b->peer->ptr;
150 assert(peer_b != NULL);
151 assert(peer_b->buf != NULL);
152
153 peer_b->request = 0; /* will be set in "retry_read" situation */
154
155 if (buf == NULL || size == 0)
156 return 0;
157
158 if (peer_b->len == 0)
159 {
160 if (peer_b->closed)
161 return 0; /* writer has closed, and no data is left */
162 else
163 {
164 BIO_set_retry_read(bio); /* buffer is empty */
165 if (size <= peer_b->size)
166 peer_b->request = size;
167 else
168 /* don't ask for more than the peer can
169 * deliver in one write */
170 peer_b->request = peer_b->size;
171 return -1;
172 }
173 }
174
175 /* we can read */
176 if (peer_b->len < size)
177 size = peer_b->len;
178
179 /* now read "size" bytes */
180
181 rest = size;
182
183 assert(rest > 0);
184 do /* one or two iterations */
185 {
186 size_t chunk;
187
188 assert(rest <= peer_b->len);
189 if (peer_b->offset + rest <= peer_b->size)
190 chunk = rest;
191 else
192 /* wrap around ring buffer */
193 chunk = peer_b->size - peer_b->offset;
194 assert(peer_b->offset + chunk <= peer_b->size);
195
196 memcpy(buf, peer_b->buf + peer_b->offset, chunk);
197
198 peer_b->len -= chunk;
199 if (peer_b->len)
200 {
201 peer_b->offset += chunk;
202 assert(peer_b->offset <= peer_b->size);
203 if (peer_b->offset == peer_b->size)
204 peer_b->offset = 0;
205 buf += chunk;
206 }
207 else
208 {
209 /* buffer now empty, no need to advance "buf" */
210 assert(chunk == rest);
211 peer_b->offset = 0;
212 }
213 rest -= chunk;
214 }
215 while (rest);
216
217 return size;
218 }
219
220/* non-copying interface: provide pointer to available data in buffer
221 * bio_nread0: return number of available bytes
222 * bio_nread: also advance index
223 * (example usage: bio_nread0(), read from buffer, bio_nread()
224 * or just bio_nread(), read from buffer)
225 */
226/* WARNING: The non-copying interface is largely untested as of yet
227 * and may contain bugs. */
228static ssize_t bio_nread0(BIO *bio, char **buf)
229 {
230 struct bio_bio_st *b, *peer_b;
231 ssize_t num;
232
233 BIO_clear_retry_flags(bio);
234
235 if (!bio->init)
236 return 0;
237
238 b = bio->ptr;
239 assert(b != NULL);
240 assert(b->peer != NULL);
241 peer_b = b->peer->ptr;
242 assert(peer_b != NULL);
243 assert(peer_b->buf != NULL);
244
245 peer_b->request = 0;
246
247 if (peer_b->len == 0)
248 {
249 char dummy;
250
251 /* avoid code duplication -- nothing available for reading */
252 return bio_read(bio, &dummy, 1); /* returns 0 or -1 */
253 }
254
255 num = peer_b->len;
256 if (peer_b->size < peer_b->offset + num)
257 /* no ring buffer wrap-around for non-copying interface */
258 num = peer_b->size - peer_b->offset;
259 assert(num > 0);
260
261 if (buf != NULL)
262 *buf = peer_b->buf + peer_b->offset;
263 return num;
264 }
265
266static ssize_t bio_nread(BIO *bio, char **buf, size_t num_)
267 {
268 struct bio_bio_st *b, *peer_b;
269 ssize_t num, available;
270
271 if (num_ > SSIZE_MAX)
272 num = SSIZE_MAX;
273 else
274 num = (ssize_t)num_;
275
276 available = bio_nread0(bio, buf);
277 if (num > available)
278 num = available;
279 if (num <= 0)
280 return num;
281
282 b = bio->ptr;
283 peer_b = b->peer->ptr;
284
285 peer_b->len -= num;
286 if (peer_b->len)
287 {
288 peer_b->offset += num;
289 assert(peer_b->offset <= peer_b->size);
290 if (peer_b->offset == peer_b->size)
291 peer_b->offset = 0;
292 }
293 else
294 peer_b->offset = 0;
295
296 return num;
297 }
298
299
300static int bio_write(BIO *bio, const char *buf, int num_)
301 {
302 size_t num = num_;
303 size_t rest;
304 struct bio_bio_st *b;
305
306 BIO_clear_retry_flags(bio);
307
308 if (!bio->init || buf == NULL || num == 0)
309 return 0;
310
311 b = bio->ptr;
312 assert(b != NULL);
313 assert(b->peer != NULL);
314 assert(b->buf != NULL);
315
316 b->request = 0;
317 if (b->closed)
318 {
319 /* we already closed */
320 BIOerr(BIO_F_BIO_WRITE, BIO_R_BROKEN_PIPE);
321 return -1;
322 }
323
324 assert(b->len <= b->size);
325
326 if (b->len == b->size)
327 {
328 BIO_set_retry_write(bio); /* buffer is full */
329 return -1;
330 }
331
332 /* we can write */
333 if (num > b->size - b->len)
334 num = b->size - b->len;
335
336 /* now write "num" bytes */
337
338 rest = num;
339
340 assert(rest > 0);
341 do /* one or two iterations */
342 {
343 size_t write_offset;
344 size_t chunk;
345
346 assert(b->len + rest <= b->size);
347
348 write_offset = b->offset + b->len;
349 if (write_offset >= b->size)
350 write_offset -= b->size;
351 /* b->buf[write_offset] is the first byte we can write to. */
352
353 if (write_offset + rest <= b->size)
354 chunk = rest;
355 else
356 /* wrap around ring buffer */
357 chunk = b->size - write_offset;
358
359 memcpy(b->buf + write_offset, buf, chunk);
360
361 b->len += chunk;
362
363 assert(b->len <= b->size);
364
365 rest -= chunk;
366 buf += chunk;
367 }
368 while (rest);
369
370 return num;
371 }
372
373/* non-copying interface: provide pointer to region to write to
374 * bio_nwrite0: check how much space is available
375 * bio_nwrite: also increase length
376 * (example usage: bio_nwrite0(), write to buffer, bio_nwrite()
377 * or just bio_nwrite(), write to buffer)
378 */
379static ssize_t bio_nwrite0(BIO *bio, char **buf)
380 {
381 struct bio_bio_st *b;
382 size_t num;
383 size_t write_offset;
384
385 BIO_clear_retry_flags(bio);
386
387 if (!bio->init)
388 return 0;
389
390 b = bio->ptr;
391 assert(b != NULL);
392 assert(b->peer != NULL);
393 assert(b->buf != NULL);
394
395 b->request = 0;
396 if (b->closed)
397 {
398 BIOerr(BIO_F_BIO_NWRITE0, BIO_R_BROKEN_PIPE);
399 return -1;
400 }
401
402 assert(b->len <= b->size);
403
404 if (b->len == b->size)
405 {
406 BIO_set_retry_write(bio);
407 return -1;
408 }
409
410 num = b->size - b->len;
411 write_offset = b->offset + b->len;
412 if (write_offset >= b->size)
413 write_offset -= b->size;
414 if (write_offset + num > b->size)
415 /* no ring buffer wrap-around for non-copying interface
416 * (to fulfil the promise by BIO_ctrl_get_write_guarantee,
417 * BIO_nwrite may have to be called twice) */
418 num = b->size - write_offset;
419
420 if (buf != NULL)
421 *buf = b->buf + write_offset;
422 assert(write_offset + num <= b->size);
423
424 return num;
425 }
426
427static ssize_t bio_nwrite(BIO *bio, char **buf, size_t num_)
428 {
429 struct bio_bio_st *b;
430 ssize_t num, space;
431
432 if (num_ > SSIZE_MAX)
433 num = SSIZE_MAX;
434 else
435 num = (ssize_t)num_;
436
437 space = bio_nwrite0(bio, buf);
438 if (num > space)
439 num = space;
440 if (num <= 0)
441 return num;
442 b = bio->ptr;
443 assert(b != NULL);
444 b->len += num;
445 assert(b->len <= b->size);
446
447 return num;
448 }
449
450
451static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
452 {
453 long ret;
454 struct bio_bio_st *b = bio->ptr;
455
456 assert(b != NULL);
457
458 switch (cmd)
459 {
460 /* specific CTRL codes */
461
462 case BIO_C_SET_WRITE_BUF_SIZE:
463 if (b->peer)
464 {
465 BIOerr(BIO_F_BIO_CTRL, BIO_R_IN_USE);
466 ret = 0;
467 }
468 else if (num == 0)
469 {
470 BIOerr(BIO_F_BIO_CTRL, BIO_R_INVALID_ARGUMENT);
471 ret = 0;
472 }
473 else
474 {
475 size_t new_size = num;
476
477 if (b->size != new_size)
478 {
479 if (b->buf)
480 {
481 OPENSSL_free(b->buf);
482 b->buf = NULL;
483 }
484 b->size = new_size;
485 }
486 ret = 1;
487 }
488 break;
489
490 case BIO_C_GET_WRITE_BUF_SIZE:
491 ret = (long) b->size;
492 break;
493
494 case BIO_C_MAKE_BIO_PAIR:
495 {
496 BIO *other_bio = ptr;
497
498 if (bio_make_pair(bio, other_bio))
499 ret = 1;
500 else
501 ret = 0;
502 }
503 break;
504
505 case BIO_C_DESTROY_BIO_PAIR:
506 /* Effects both BIOs in the pair -- call just once!
507 * Or let BIO_free(bio1); BIO_free(bio2); do the job. */
508 bio_destroy_pair(bio);
509 ret = 1;
510 break;
511
512 case BIO_C_GET_WRITE_GUARANTEE:
513 /* How many bytes can the caller feed to the next write
514 * without having to keep any? */
515 if (b->peer == NULL || b->closed)
516 ret = 0;
517 else
518 ret = (long) b->size - b->len;
519 break;
520
521 case BIO_C_GET_READ_REQUEST:
522 /* If the peer unsuccessfully tried to read, how many bytes
523 * were requested? (As with BIO_CTRL_PENDING, that number
524 * can usually be treated as boolean.) */
525 ret = (long) b->request;
526 break;
527
528 case BIO_C_RESET_READ_REQUEST:
529 /* Reset request. (Can be useful after read attempts
530 * at the other side that are meant to be non-blocking,
531 * e.g. when probing SSL_read to see if any data is
532 * available.) */
533 b->request = 0;
534 ret = 1;
535 break;
536
537 case BIO_C_SHUTDOWN_WR:
538 /* similar to shutdown(..., SHUT_WR) */
539 b->closed = 1;
540 ret = 1;
541 break;
542
543 case BIO_C_NREAD0:
544 /* prepare for non-copying read */
545 ret = (long) bio_nread0(bio, ptr);
546 break;
547
548 case BIO_C_NREAD:
549 /* non-copying read */
550 ret = (long) bio_nread(bio, ptr, (size_t) num);
551 break;
552
553 case BIO_C_NWRITE0:
554 /* prepare for non-copying write */
555 ret = (long) bio_nwrite0(bio, ptr);
556 break;
557
558 case BIO_C_NWRITE:
559 /* non-copying write */
560 ret = (long) bio_nwrite(bio, ptr, (size_t) num);
561 break;
562
563
564 /* standard CTRL codes follow */
565
566 case BIO_CTRL_RESET:
567 if (b->buf != NULL)
568 {
569 b->len = 0;
570 b->offset = 0;
571 }
572 ret = 0;
573 break;
574
575 case BIO_CTRL_GET_CLOSE:
576 ret = bio->shutdown;
577 break;
578
579 case BIO_CTRL_SET_CLOSE:
580 bio->shutdown = (int) num;
581 ret = 1;
582 break;
583
584 case BIO_CTRL_PENDING:
585 if (b->peer != NULL)
586 {
587 struct bio_bio_st *peer_b = b->peer->ptr;
588
589 ret = (long) peer_b->len;
590 }
591 else
592 ret = 0;
593 break;
594
595 case BIO_CTRL_WPENDING:
596 if (b->buf != NULL)
597 ret = (long) b->len;
598 else
599 ret = 0;
600 break;
601
602 case BIO_CTRL_DUP:
603 /* See BIO_dup_chain for circumstances we have to expect. */
604 {
605 BIO *other_bio = ptr;
606 struct bio_bio_st *other_b;
607
608 assert(other_bio != NULL);
609 other_b = other_bio->ptr;
610 assert(other_b != NULL);
611
612 assert(other_b->buf == NULL); /* other_bio is always fresh */
613
614 other_b->size = b->size;
615 }
616
617 ret = 1;
618 break;
619
620 case BIO_CTRL_FLUSH:
621 ret = 1;
622 break;
623
624 case BIO_CTRL_EOF:
625 {
626 BIO *other_bio = ptr;
627
628 if (other_bio)
629 {
630 struct bio_bio_st *other_b = other_bio->ptr;
631
632 assert(other_b != NULL);
633 ret = other_b->len == 0 && other_b->closed;
634 }
635 else
636 ret = 1;
637 }
638 break;
639
640 default:
641 ret = 0;
642 }
643 return ret;
644 }
645
646static int bio_puts(BIO *bio, const char *str)
647 {
648 return bio_write(bio, str, strlen(str));
649 }
650
651
652static int bio_make_pair(BIO *bio1, BIO *bio2)
653 {
654 struct bio_bio_st *b1, *b2;
655
656 assert(bio1 != NULL);
657 assert(bio2 != NULL);
658
659 b1 = bio1->ptr;
660 b2 = bio2->ptr;
661
662 if (b1->peer != NULL || b2->peer != NULL)
663 {
664 BIOerr(BIO_F_BIO_MAKE_PAIR, BIO_R_IN_USE);
665 return 0;
666 }
667
668 if (b1->buf == NULL)
669 {
670 b1->buf = OPENSSL_malloc(b1->size);
671 if (b1->buf == NULL)
672 {
673 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
674 return 0;
675 }
676 b1->len = 0;
677 b1->offset = 0;
678 }
679
680 if (b2->buf == NULL)
681 {
682 b2->buf = OPENSSL_malloc(b2->size);
683 if (b2->buf == NULL)
684 {
685 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
686 return 0;
687 }
688 b2->len = 0;
689 b2->offset = 0;
690 }
691
692 b1->peer = bio2;
693 b1->closed = 0;
694 b1->request = 0;
695 b2->peer = bio1;
696 b2->closed = 0;
697 b2->request = 0;
698
699 bio1->init = 1;
700 bio2->init = 1;
701
702 return 1;
703 }
704
705static void bio_destroy_pair(BIO *bio)
706 {
707 struct bio_bio_st *b = bio->ptr;
708
709 if (b != NULL)
710 {
711 BIO *peer_bio = b->peer;
712
713 if (peer_bio != NULL)
714 {
715 struct bio_bio_st *peer_b = peer_bio->ptr;
716
717 assert(peer_b != NULL);
718 assert(peer_b->peer == bio);
719
720 peer_b->peer = NULL;
721 peer_bio->init = 0;
722 assert(peer_b->buf != NULL);
723 peer_b->len = 0;
724 peer_b->offset = 0;
725
726 b->peer = NULL;
727 bio->init = 0;
728 assert(b->buf != NULL);
729 b->len = 0;
730 b->offset = 0;
731 }
732 }
733 }
734
735
736/* Exported convenience functions */
737int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1,
738 BIO **bio2_p, size_t writebuf2)
739 {
740 BIO *bio1 = NULL, *bio2 = NULL;
741 long r;
742 int ret = 0;
743
744 bio1 = BIO_new(BIO_s_bio());
745 if (bio1 == NULL)
746 goto err;
747 bio2 = BIO_new(BIO_s_bio());
748 if (bio2 == NULL)
749 goto err;
750
751 if (writebuf1)
752 {
753 r = BIO_set_write_buf_size(bio1, writebuf1);
754 if (!r)
755 goto err;
756 }
757 if (writebuf2)
758 {
759 r = BIO_set_write_buf_size(bio2, writebuf2);
760 if (!r)
761 goto err;
762 }
763
764 r = BIO_make_bio_pair(bio1, bio2);
765 if (!r)
766 goto err;
767 ret = 1;
768
769 err:
770 if (ret == 0)
771 {
772 if (bio1)
773 {
774 BIO_free(bio1);
775 bio1 = NULL;
776 }
777 if (bio2)
778 {
779 BIO_free(bio2);
780 bio2 = NULL;
781 }
782 }
783
784 *bio1_p = bio1;
785 *bio2_p = bio2;
786 return ret;
787 }
788
789size_t BIO_ctrl_get_write_guarantee(BIO *bio)
790 {
791 return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL);
792 }
793
794size_t BIO_ctrl_get_read_request(BIO *bio)
795 {
796 return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL);
797 }
798
799int BIO_ctrl_reset_read_request(BIO *bio)
800 {
801 return (BIO_ctrl(bio, BIO_C_RESET_READ_REQUEST, 0, NULL) != 0);
802 }
803
804
805/* BIO_nread0/nread/nwrite0/nwrite are available only for BIO pairs for now
806 * (conceivably some other BIOs could allow non-copying reads and writes too.)
807 */
808int BIO_nread0(BIO *bio, char **buf)
809 {
810 long ret;
811
812 if (!bio->init)
813 {
814 BIOerr(BIO_F_BIO_NREAD0, BIO_R_UNINITIALIZED);
815 return -2;
816 }
817
818 ret = BIO_ctrl(bio, BIO_C_NREAD0, 0, buf);
819 if (ret > INT_MAX)
820 return INT_MAX;
821 else
822 return (int) ret;
823 }
824
825int BIO_nread(BIO *bio, char **buf, int num)
826 {
827 int ret;
828
829 if (!bio->init)
830 {
831 BIOerr(BIO_F_BIO_NREAD, BIO_R_UNINITIALIZED);
832 return -2;
833 }
834
835 ret = (int) BIO_ctrl(bio, BIO_C_NREAD, num, buf);
836 if (ret > 0)
837 bio->num_read += ret;
838 return ret;
839 }
840
841int BIO_nwrite0(BIO *bio, char **buf)
842 {
843 long ret;
844
845 if (!bio->init)
846 {
847 BIOerr(BIO_F_BIO_NWRITE0, BIO_R_UNINITIALIZED);
848 return -2;
849 }
850
851 ret = BIO_ctrl(bio, BIO_C_NWRITE0, 0, buf);
852 if (ret > INT_MAX)
853 return INT_MAX;
854 else
855 return (int) ret;
856 }
857
858int BIO_nwrite(BIO *bio, char **buf, int num)
859 {
860 int ret;
861
862 if (!bio->init)
863 {
864 BIOerr(BIO_F_BIO_NWRITE, BIO_R_UNINITIALIZED);
865 return -2;
866 }
867
868 ret = BIO_ctrl(bio, BIO_C_NWRITE, num, buf);
869 if (ret > 0)
870 bio->num_read += ret;
871 return ret;
872 }
diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c
deleted file mode 100644
index f91ae4c8c6..0000000000
--- a/src/lib/libcrypto/bio/bss_conn.c
+++ /dev/null
@@ -1,652 +0,0 @@
1/* crypto/bio/bss_conn.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_SOCK
60
61#include <stdio.h>
62#include <errno.h>
63#define USE_SOCKETS
64#include "cryptlib.h"
65#include <openssl/bio.h>
66
67#ifdef OPENSSL_SYS_WIN16
68#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
69#else
70#define SOCKET_PROTOCOL IPPROTO_TCP
71#endif
72
73#if (defined(OPENSSL_SYS_VMS) && __VMS_VER < 70000000)
74/* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */
75#undef FIONBIO
76#endif
77
78
79typedef struct bio_connect_st
80 {
81 int state;
82
83 char *param_hostname;
84 char *param_port;
85 int nbio;
86
87 unsigned char ip[4];
88 unsigned short port;
89
90 struct sockaddr_in them;
91
92 /* int socket; this will be kept in bio->num so that it is
93 * compatible with the bss_sock bio */
94
95 /* called when the connection is initially made
96 * callback(BIO,state,ret); The callback should return
97 * 'ret'. state is for compatibility with the ssl info_callback */
98 int (*info_callback)(const BIO *bio,int state,int ret);
99 } BIO_CONNECT;
100
101static int conn_write(BIO *h, const char *buf, int num);
102static int conn_read(BIO *h, char *buf, int size);
103static int conn_puts(BIO *h, const char *str);
104static long conn_ctrl(BIO *h, int cmd, long arg1, void *arg2);
105static int conn_new(BIO *h);
106static int conn_free(BIO *data);
107static long conn_callback_ctrl(BIO *h, int cmd, bio_info_cb *);
108
109static int conn_state(BIO *b, BIO_CONNECT *c);
110static void conn_close_socket(BIO *data);
111BIO_CONNECT *BIO_CONNECT_new(void );
112void BIO_CONNECT_free(BIO_CONNECT *a);
113
114static BIO_METHOD methods_connectp=
115 {
116 BIO_TYPE_CONNECT,
117 "socket connect",
118 conn_write,
119 conn_read,
120 conn_puts,
121 NULL, /* connect_gets, */
122 conn_ctrl,
123 conn_new,
124 conn_free,
125 conn_callback_ctrl,
126 };
127
128static int conn_state(BIO *b, BIO_CONNECT *c)
129 {
130 int ret= -1,i;
131 unsigned long l;
132 char *p,*q;
133 int (*cb)()=NULL;
134
135 if (c->info_callback != NULL)
136 cb=c->info_callback;
137
138 for (;;)
139 {
140 switch (c->state)
141 {
142 case BIO_CONN_S_BEFORE:
143 p=c->param_hostname;
144 if (p == NULL)
145 {
146 BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTNAME_SPECIFIED);
147 goto exit_loop;
148 }
149 for ( ; *p != '\0'; p++)
150 {
151 if ((*p == ':') || (*p == '/')) break;
152 }
153
154 i= *p;
155 if ((i == ':') || (i == '/'))
156 {
157
158 *(p++)='\0';
159 if (i == ':')
160 {
161 for (q=p; *q; q++)
162 if (*q == '/')
163 {
164 *q='\0';
165 break;
166 }
167 if (c->param_port != NULL)
168 OPENSSL_free(c->param_port);
169 c->param_port=BUF_strdup(p);
170 }
171 }
172
173 if (c->param_port == NULL)
174 {
175 BIOerr(BIO_F_CONN_STATE,BIO_R_NO_PORT_SPECIFIED);
176 ERR_add_error_data(2,"host=",c->param_hostname);
177 goto exit_loop;
178 }
179 c->state=BIO_CONN_S_GET_IP;
180 break;
181
182 case BIO_CONN_S_GET_IP:
183 if (BIO_get_host_ip(c->param_hostname,&(c->ip[0])) <= 0)
184 goto exit_loop;
185 c->state=BIO_CONN_S_GET_PORT;
186 break;
187
188 case BIO_CONN_S_GET_PORT:
189 if (c->param_port == NULL)
190 {
191 /* abort(); */
192 goto exit_loop;
193 }
194 else if (BIO_get_port(c->param_port,&c->port) <= 0)
195 goto exit_loop;
196 c->state=BIO_CONN_S_CREATE_SOCKET;
197 break;
198
199 case BIO_CONN_S_CREATE_SOCKET:
200 /* now setup address */
201 memset((char *)&c->them,0,sizeof(c->them));
202 c->them.sin_family=AF_INET;
203 c->them.sin_port=htons((unsigned short)c->port);
204 l=(unsigned long)
205 ((unsigned long)c->ip[0]<<24L)|
206 ((unsigned long)c->ip[1]<<16L)|
207 ((unsigned long)c->ip[2]<< 8L)|
208 ((unsigned long)c->ip[3]);
209 c->them.sin_addr.s_addr=htonl(l);
210 c->state=BIO_CONN_S_CREATE_SOCKET;
211
212 ret=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
213 if (ret == INVALID_SOCKET)
214 {
215 SYSerr(SYS_F_SOCKET,get_last_socket_error());
216 ERR_add_error_data(4,"host=",c->param_hostname,
217 ":",c->param_port);
218 BIOerr(BIO_F_CONN_STATE,BIO_R_UNABLE_TO_CREATE_SOCKET);
219 goto exit_loop;
220 }
221 b->num=ret;
222 c->state=BIO_CONN_S_NBIO;
223 break;
224
225 case BIO_CONN_S_NBIO:
226 if (c->nbio)
227 {
228 if (!BIO_socket_nbio(b->num,1))
229 {
230 BIOerr(BIO_F_CONN_STATE,BIO_R_ERROR_SETTING_NBIO);
231 ERR_add_error_data(4,"host=",
232 c->param_hostname,
233 ":",c->param_port);
234 goto exit_loop;
235 }
236 }
237 c->state=BIO_CONN_S_CONNECT;
238
239#if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE)
240 i=1;
241 i=setsockopt(b->num,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));
242 if (i < 0)
243 {
244 SYSerr(SYS_F_SOCKET,get_last_socket_error());
245 ERR_add_error_data(4,"host=",c->param_hostname,
246 ":",c->param_port);
247 BIOerr(BIO_F_CONN_STATE,BIO_R_KEEPALIVE);
248 goto exit_loop;
249 }
250#endif
251 break;
252
253 case BIO_CONN_S_CONNECT:
254 BIO_clear_retry_flags(b);
255 ret=connect(b->num,
256 (struct sockaddr *)&c->them,
257 sizeof(c->them));
258 b->retry_reason=0;
259 if (ret < 0)
260 {
261 if (BIO_sock_should_retry(ret))
262 {
263 BIO_set_retry_special(b);
264 c->state=BIO_CONN_S_BLOCKED_CONNECT;
265 b->retry_reason=BIO_RR_CONNECT;
266 }
267 else
268 {
269 SYSerr(SYS_F_CONNECT,get_last_socket_error());
270 ERR_add_error_data(4,"host=",
271 c->param_hostname,
272 ":",c->param_port);
273 BIOerr(BIO_F_CONN_STATE,BIO_R_CONNECT_ERROR);
274 }
275 goto exit_loop;
276 }
277 else
278 c->state=BIO_CONN_S_OK;
279 break;
280
281 case BIO_CONN_S_BLOCKED_CONNECT:
282 i=BIO_sock_error(b->num);
283 if (i)
284 {
285 BIO_clear_retry_flags(b);
286 SYSerr(SYS_F_CONNECT,i);
287 ERR_add_error_data(4,"host=",
288 c->param_hostname,
289 ":",c->param_port);
290 BIOerr(BIO_F_CONN_STATE,BIO_R_NBIO_CONNECT_ERROR);
291 ret=0;
292 goto exit_loop;
293 }
294 else
295 c->state=BIO_CONN_S_OK;
296 break;
297
298 case BIO_CONN_S_OK:
299 ret=1;
300 goto exit_loop;
301 default:
302 /* abort(); */
303 goto exit_loop;
304 }
305
306 if (cb != NULL)
307 {
308 if (!(ret=cb((BIO *)b,c->state,ret)))
309 goto end;
310 }
311 }
312
313 /* Loop does not exit */
314exit_loop:
315 if (cb != NULL)
316 ret=cb((BIO *)b,c->state,ret);
317end:
318 return(ret);
319 }
320
321BIO_CONNECT *BIO_CONNECT_new(void)
322 {
323 BIO_CONNECT *ret;
324
325 if ((ret=(BIO_CONNECT *)OPENSSL_malloc(sizeof(BIO_CONNECT))) == NULL)
326 return(NULL);
327 ret->state=BIO_CONN_S_BEFORE;
328 ret->param_hostname=NULL;
329 ret->param_port=NULL;
330 ret->info_callback=NULL;
331 ret->nbio=0;
332 ret->ip[0]=0;
333 ret->ip[1]=0;
334 ret->ip[2]=0;
335 ret->ip[3]=0;
336 ret->port=0;
337 memset((char *)&ret->them,0,sizeof(ret->them));
338 return(ret);
339 }
340
341void BIO_CONNECT_free(BIO_CONNECT *a)
342 {
343 if(a == NULL)
344 return;
345
346 if (a->param_hostname != NULL)
347 OPENSSL_free(a->param_hostname);
348 if (a->param_port != NULL)
349 OPENSSL_free(a->param_port);
350 OPENSSL_free(a);
351 }
352
353BIO_METHOD *BIO_s_connect(void)
354 {
355 return(&methods_connectp);
356 }
357
358static int conn_new(BIO *bi)
359 {
360 bi->init=0;
361 bi->num=INVALID_SOCKET;
362 bi->flags=0;
363 if ((bi->ptr=(char *)BIO_CONNECT_new()) == NULL)
364 return(0);
365 else
366 return(1);
367 }
368
369static void conn_close_socket(BIO *bio)
370 {
371 BIO_CONNECT *c;
372
373 c=(BIO_CONNECT *)bio->ptr;
374 if (bio->num != INVALID_SOCKET)
375 {
376 /* Only do a shutdown if things were established */
377 if (c->state == BIO_CONN_S_OK)
378 shutdown(bio->num,2);
379 closesocket(bio->num);
380 bio->num=INVALID_SOCKET;
381 }
382 }
383
384static int conn_free(BIO *a)
385 {
386 BIO_CONNECT *data;
387
388 if (a == NULL) return(0);
389 data=(BIO_CONNECT *)a->ptr;
390
391 if (a->shutdown)
392 {
393 conn_close_socket(a);
394 BIO_CONNECT_free(data);
395 a->ptr=NULL;
396 a->flags=0;
397 a->init=0;
398 }
399 return(1);
400 }
401
402static int conn_read(BIO *b, char *out, int outl)
403 {
404 int ret=0;
405 BIO_CONNECT *data;
406
407 data=(BIO_CONNECT *)b->ptr;
408 if (data->state != BIO_CONN_S_OK)
409 {
410 ret=conn_state(b,data);
411 if (ret <= 0)
412 return(ret);
413 }
414
415 if (out != NULL)
416 {
417 clear_socket_error();
418 ret=readsocket(b->num,out,outl);
419 BIO_clear_retry_flags(b);
420 if (ret <= 0)
421 {
422 if (BIO_sock_should_retry(ret))
423 BIO_set_retry_read(b);
424 }
425 }
426 return(ret);
427 }
428
429static int conn_write(BIO *b, const char *in, int inl)
430 {
431 int ret;
432 BIO_CONNECT *data;
433
434 data=(BIO_CONNECT *)b->ptr;
435 if (data->state != BIO_CONN_S_OK)
436 {
437 ret=conn_state(b,data);
438 if (ret <= 0) return(ret);
439 }
440
441 clear_socket_error();
442 ret=writesocket(b->num,in,inl);
443 BIO_clear_retry_flags(b);
444 if (ret <= 0)
445 {
446 if (BIO_sock_should_retry(ret))
447 BIO_set_retry_write(b);
448 }
449 return(ret);
450 }
451
452static long conn_ctrl(BIO *b, int cmd, long num, void *ptr)
453 {
454 BIO *dbio;
455 int *ip;
456 const char **pptr;
457 long ret=1;
458 BIO_CONNECT *data;
459
460 data=(BIO_CONNECT *)b->ptr;
461
462 switch (cmd)
463 {
464 case BIO_CTRL_RESET:
465 ret=0;
466 data->state=BIO_CONN_S_BEFORE;
467 conn_close_socket(b);
468 b->flags=0;
469 break;
470 case BIO_C_DO_STATE_MACHINE:
471 /* use this one to start the connection */
472 if (!data->state != BIO_CONN_S_OK)
473 ret=(long)conn_state(b,data);
474 else
475 ret=1;
476 break;
477 case BIO_C_GET_CONNECT:
478 if (ptr != NULL)
479 {
480 pptr=(const char **)ptr;
481 if (num == 0)
482 {
483 *pptr=data->param_hostname;
484
485 }
486 else if (num == 1)
487 {
488 *pptr=data->param_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 }
502 break;
503 case BIO_C_SET_CONNECT:
504 if (ptr != NULL)
505 {
506 b->init=1;
507 if (num == 0)
508 {
509 if (data->param_hostname != NULL)
510 OPENSSL_free(data->param_hostname);
511 data->param_hostname=BUF_strdup(ptr);
512 }
513 else if (num == 1)
514 {
515 if (data->param_port != NULL)
516 OPENSSL_free(data->param_port);
517 data->param_port=BUF_strdup(ptr);
518 }
519 else if (num == 2)
520 {
521 char buf[16];
522 char *p = ptr;
523
524 sprintf(buf,"%d.%d.%d.%d",
525 p[0],p[1],p[2],p[3]);
526 if (data->param_hostname != NULL)
527 OPENSSL_free(data->param_hostname);
528 data->param_hostname=BUF_strdup(buf);
529 memcpy(&(data->ip[0]),ptr,4);
530 }
531 else if (num == 3)
532 {
533 char buf[16];
534
535 sprintf(buf,"%d",*(int *)ptr);
536 if (data->param_port != NULL)
537 OPENSSL_free(data->param_port);
538 data->param_port=BUF_strdup(buf);
539 data->port= *(int *)ptr;
540 }
541 }
542 break;
543 case BIO_C_SET_NBIO:
544 data->nbio=(int)num;
545 break;
546 case BIO_C_GET_FD:
547 if (b->init)
548 {
549 ip=(int *)ptr;
550 if (ip != NULL)
551 *ip=b->num;
552 ret=b->num;
553 }
554 else
555 ret= -1;
556 break;
557 case BIO_CTRL_GET_CLOSE:
558 ret=b->shutdown;
559 break;
560 case BIO_CTRL_SET_CLOSE:
561 b->shutdown=(int)num;
562 break;
563 case BIO_CTRL_PENDING:
564 case BIO_CTRL_WPENDING:
565 ret=0;
566 break;
567 case BIO_CTRL_FLUSH:
568 break;
569 case BIO_CTRL_DUP:
570 {
571 dbio=(BIO *)ptr;
572 if (data->param_port)
573 BIO_set_conn_port(dbio,data->param_port);
574 if (data->param_hostname)
575 BIO_set_conn_hostname(dbio,data->param_hostname);
576 BIO_set_nbio(dbio,data->nbio);
577 /* FIXME: the cast of the function seems unlikely to be a good idea */
578 (void)BIO_set_info_callback(dbio,(bio_info_cb *)data->info_callback);
579 }
580 break;
581 case BIO_CTRL_SET_CALLBACK:
582 {
583#if 0 /* FIXME: Should this be used? -- Richard Levitte */
584 BIOerr(BIO_F_CONN_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
585 ret = -1;
586#else
587 ret=0;
588#endif
589 }
590 break;
591 case BIO_CTRL_GET_CALLBACK:
592 {
593 int (**fptr)();
594
595 fptr=(int (**)())ptr;
596 *fptr=data->info_callback;
597 }
598 break;
599 default:
600 ret=0;
601 break;
602 }
603 return(ret);
604 }
605
606static long conn_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
607 {
608 long ret=1;
609 BIO_CONNECT *data;
610
611 data=(BIO_CONNECT *)b->ptr;
612
613 switch (cmd)
614 {
615 case BIO_CTRL_SET_CALLBACK:
616 {
617 data->info_callback=(int (*)(const struct bio_st *, int, int))fp;
618 }
619 break;
620 default:
621 ret=0;
622 break;
623 }
624 return(ret);
625 }
626
627static int conn_puts(BIO *bp, const char *str)
628 {
629 int n,ret;
630
631 n=strlen(str);
632 ret=conn_write(bp,str,n);
633 return(ret);
634 }
635
636BIO *BIO_new_connect(char *str)
637 {
638 BIO *ret;
639
640 ret=BIO_new(BIO_s_connect());
641 if (ret == NULL) return(NULL);
642 if (BIO_set_conn_hostname(ret,str))
643 return(ret);
644 else
645 {
646 BIO_free(ret);
647 return(NULL);
648 }
649 }
650
651#endif
652
diff --git a/src/lib/libcrypto/bio/bss_fd.c b/src/lib/libcrypto/bio/bss_fd.c
deleted file mode 100644
index 5e3e187de6..0000000000
--- a/src/lib/libcrypto/bio/bss_fd.c
+++ /dev/null
@@ -1,282 +0,0 @@
1/* crypto/bio/bss_fd.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#define USE_SOCKETS
62#include "cryptlib.h"
63#include <openssl/bio.h>
64
65static int fd_write(BIO *h, const char *buf, int num);
66static int fd_read(BIO *h, char *buf, int size);
67static int fd_puts(BIO *h, const char *str);
68static long fd_ctrl(BIO *h, int cmd, long arg1, void *arg2);
69static int fd_new(BIO *h);
70static int fd_free(BIO *data);
71int BIO_fd_should_retry(int s);
72
73static BIO_METHOD methods_fdp=
74 {
75 BIO_TYPE_FD,"file descriptor",
76 fd_write,
77 fd_read,
78 fd_puts,
79 NULL, /* fd_gets, */
80 fd_ctrl,
81 fd_new,
82 fd_free,
83 NULL,
84 };
85
86BIO_METHOD *BIO_s_fd(void)
87 {
88 return(&methods_fdp);
89 }
90
91BIO *BIO_new_fd(int fd,int close_flag)
92 {
93 BIO *ret;
94 ret=BIO_new(BIO_s_fd());
95 if (ret == NULL) return(NULL);
96 BIO_set_fd(ret,fd,close_flag);
97 return(ret);
98 }
99
100static int fd_new(BIO *bi)
101 {
102 bi->init=0;
103 bi->num=0;
104 bi->ptr=NULL;
105 bi->flags=0;
106 return(1);
107 }
108
109static int fd_free(BIO *a)
110 {
111 if (a == NULL) return(0);
112 if (a->shutdown)
113 {
114 if (a->init)
115 {
116 close(a->num);
117 }
118 a->init=0;
119 a->flags=0;
120 }
121 return(1);
122 }
123
124static int fd_read(BIO *b, char *out,int outl)
125 {
126 int ret=0;
127
128 if (out != NULL)
129 {
130 clear_sys_error();
131 ret=read(b->num,out,outl);
132 BIO_clear_retry_flags(b);
133 if (ret <= 0)
134 {
135 if (BIO_fd_should_retry(ret))
136 BIO_set_retry_read(b);
137 }
138 }
139 return(ret);
140 }
141
142static int fd_write(BIO *b, const char *in, int inl)
143 {
144 int ret;
145 clear_sys_error();
146 ret=write(b->num,in,inl);
147 BIO_clear_retry_flags(b);
148 if (ret <= 0)
149 {
150 if (BIO_fd_should_retry(ret))
151 BIO_set_retry_write(b);
152 }
153 return(ret);
154 }
155
156static long fd_ctrl(BIO *b, int cmd, long num, void *ptr)
157 {
158 long ret=1;
159 int *ip;
160
161 switch (cmd)
162 {
163 case BIO_CTRL_RESET:
164 num=0;
165 case BIO_C_FILE_SEEK:
166 ret=(long)lseek(b->num,num,0);
167 break;
168 case BIO_C_FILE_TELL:
169 case BIO_CTRL_INFO:
170 ret=(long)lseek(b->num,0,1);
171 break;
172 case BIO_C_SET_FD:
173 fd_free(b);
174 b->num= *((int *)ptr);
175 b->shutdown=(int)num;
176 b->init=1;
177 break;
178 case BIO_C_GET_FD:
179 if (b->init)
180 {
181 ip=(int *)ptr;
182 if (ip != NULL) *ip=b->num;
183 ret=b->num;
184 }
185 else
186 ret= -1;
187 break;
188 case BIO_CTRL_GET_CLOSE:
189 ret=b->shutdown;
190 break;
191 case BIO_CTRL_SET_CLOSE:
192 b->shutdown=(int)num;
193 break;
194 case BIO_CTRL_PENDING:
195 case BIO_CTRL_WPENDING:
196 ret=0;
197 break;
198 case BIO_CTRL_DUP:
199 case BIO_CTRL_FLUSH:
200 ret=1;
201 break;
202 default:
203 ret=0;
204 break;
205 }
206 return(ret);
207 }
208
209static int fd_puts(BIO *bp, const char *str)
210 {
211 int n,ret;
212
213 n=strlen(str);
214 ret=fd_write(bp,str,n);
215 return(ret);
216 }
217
218int BIO_fd_should_retry(int i)
219 {
220 int err;
221
222 if ((i == 0) || (i == -1))
223 {
224 err=get_last_sys_error();
225
226#if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
227 if ((i == -1) && (err == 0))
228 return(1);
229#endif
230
231 return(BIO_fd_non_fatal_error(err));
232 }
233 return(0);
234 }
235
236int BIO_fd_non_fatal_error(int err)
237 {
238 switch (err)
239 {
240
241#ifdef EWOULDBLOCK
242# ifdef WSAEWOULDBLOCK
243# if WSAEWOULDBLOCK != EWOULDBLOCK
244 case EWOULDBLOCK:
245# endif
246# else
247 case EWOULDBLOCK:
248# endif
249#endif
250
251#if defined(ENOTCONN)
252 case ENOTCONN:
253#endif
254
255#ifdef EINTR
256 case EINTR:
257#endif
258
259#ifdef EAGAIN
260#if EWOULDBLOCK != EAGAIN
261 case EAGAIN:
262# endif
263#endif
264
265#ifdef EPROTO
266 case EPROTO:
267#endif
268
269#ifdef EINPROGRESS
270 case EINPROGRESS:
271#endif
272
273#ifdef EALREADY
274 case EALREADY:
275#endif
276 return(1);
277 /* break; */
278 default:
279 break;
280 }
281 return(0);
282 }
diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c
deleted file mode 100644
index 826b361fa2..0000000000
--- a/src/lib/libcrypto/bio/bss_file.c
+++ /dev/null
@@ -1,324 +0,0 @@
1/* crypto/bio/bss_file.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/*
60 * 03-Dec-1997 rdenny@dc3.com Fix bug preventing use of stdin/stdout
61 * with binary data (e.g. asn1parse -inform DER < xxx) under
62 * Windows
63 */
64
65#ifndef HEADER_BSS_FILE_C
66#define HEADER_BSS_FILE_C
67
68#include <stdio.h>
69#include <errno.h>
70#include "cryptlib.h"
71#include <openssl/bio.h>
72#include <openssl/err.h>
73
74#if !defined(OPENSSL_NO_STDIO)
75
76static int MS_CALLBACK file_write(BIO *h, const char *buf, int num);
77static int MS_CALLBACK file_read(BIO *h, char *buf, int size);
78static int MS_CALLBACK file_puts(BIO *h, const char *str);
79static int MS_CALLBACK file_gets(BIO *h, char *str, int size);
80static long MS_CALLBACK file_ctrl(BIO *h, int cmd, long arg1, void *arg2);
81static int MS_CALLBACK file_new(BIO *h);
82static int MS_CALLBACK file_free(BIO *data);
83static BIO_METHOD methods_filep=
84 {
85 BIO_TYPE_FILE,
86 "FILE pointer",
87 file_write,
88 file_read,
89 file_puts,
90 file_gets,
91 file_ctrl,
92 file_new,
93 file_free,
94 NULL,
95 };
96
97BIO *BIO_new_file(const char *filename, const char *mode)
98 {
99 BIO *ret;
100 FILE *file;
101
102 if ((file=fopen(filename,mode)) == NULL)
103 {
104 SYSerr(SYS_F_FOPEN,get_last_sys_error());
105 ERR_add_error_data(5,"fopen('",filename,"','",mode,"')");
106 if (errno == ENOENT)
107 BIOerr(BIO_F_BIO_NEW_FILE,BIO_R_NO_SUCH_FILE);
108 else
109 BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB);
110 return(NULL);
111 }
112 if ((ret=BIO_new(BIO_s_file_internal())) == NULL)
113 return(NULL);
114
115 BIO_set_fp(ret,file,BIO_CLOSE);
116 return(ret);
117 }
118
119BIO *BIO_new_fp(FILE *stream, int close_flag)
120 {
121 BIO *ret;
122
123 if ((ret=BIO_new(BIO_s_file())) == NULL)
124 return(NULL);
125
126 BIO_set_fp(ret,stream,close_flag);
127 return(ret);
128 }
129
130BIO_METHOD *BIO_s_file(void)
131 {
132 return(&methods_filep);
133 }
134
135static int MS_CALLBACK file_new(BIO *bi)
136 {
137 bi->init=0;
138 bi->num=0;
139 bi->ptr=NULL;
140 return(1);
141 }
142
143static int MS_CALLBACK file_free(BIO *a)
144 {
145 if (a == NULL) return(0);
146 if (a->shutdown)
147 {
148 if ((a->init) && (a->ptr != NULL))
149 {
150 fclose((FILE *)a->ptr);
151 a->ptr=NULL;
152 }
153 a->init=0;
154 }
155 return(1);
156 }
157
158static int MS_CALLBACK file_read(BIO *b, char *out, int outl)
159 {
160 int ret=0;
161
162 if (b->init && (out != NULL))
163 {
164 ret=fread(out,1,(int)outl,(FILE *)b->ptr);
165 if(ret == 0 && ferror((FILE *)b->ptr))
166 {
167 SYSerr(SYS_F_FREAD,get_last_sys_error());
168 BIOerr(BIO_F_FILE_READ,ERR_R_SYS_LIB);
169 ret=-1;
170 }
171 }
172 return(ret);
173 }
174
175static int MS_CALLBACK file_write(BIO *b, const char *in, int inl)
176 {
177 int ret=0;
178
179 if (b->init && (in != NULL))
180 {
181 if (fwrite(in,(int)inl,1,(FILE *)b->ptr))
182 ret=inl;
183 /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */
184 /* according to Tim Hudson <tjh@cryptsoft.com>, the commented
185 * out version above can cause 'inl' write calls under
186 * some stupid stdio implementations (VMS) */
187 }
188 return(ret);
189 }
190
191static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr)
192 {
193 long ret=1;
194 FILE *fp=(FILE *)b->ptr;
195 FILE **fpp;
196 char p[4];
197
198 switch (cmd)
199 {
200 case BIO_C_FILE_SEEK:
201 case BIO_CTRL_RESET:
202 ret=(long)fseek(fp,num,0);
203 break;
204 case BIO_CTRL_EOF:
205 ret=(long)feof(fp);
206 break;
207 case BIO_C_FILE_TELL:
208 case BIO_CTRL_INFO:
209 ret=ftell(fp);
210 break;
211 case BIO_C_SET_FILE_PTR:
212 file_free(b);
213 b->shutdown=(int)num&BIO_CLOSE;
214 b->ptr=(char *)ptr;
215 b->init=1;
216#if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS)
217 /* Set correct text/binary mode */
218 if (num & BIO_FP_TEXT)
219 _setmode(fileno((FILE *)ptr),_O_TEXT);
220 else
221 _setmode(fileno((FILE *)ptr),_O_BINARY);
222#elif defined(OPENSSL_SYS_OS2)
223 if (num & BIO_FP_TEXT)
224 setmode(fileno((FILE *)ptr), O_TEXT);
225 else
226 setmode(fileno((FILE *)ptr), O_BINARY);
227#endif
228 break;
229 case BIO_C_SET_FILENAME:
230 file_free(b);
231 b->shutdown=(int)num&BIO_CLOSE;
232 if (num & BIO_FP_APPEND)
233 {
234 if (num & BIO_FP_READ)
235 strcpy(p,"a+");
236 else strcpy(p,"a");
237 }
238 else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE))
239 strcpy(p,"r+");
240 else if (num & BIO_FP_WRITE)
241 strcpy(p,"w");
242 else if (num & BIO_FP_READ)
243 strcpy(p,"r");
244 else
245 {
246 BIOerr(BIO_F_FILE_CTRL,BIO_R_BAD_FOPEN_MODE);
247 ret=0;
248 break;
249 }
250#if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS)
251 if (!(num & BIO_FP_TEXT))
252 strcat(p,"b");
253 else
254 strcat(p,"t");
255#endif
256 fp=fopen(ptr,p);
257 if (fp == NULL)
258 {
259 SYSerr(SYS_F_FOPEN,get_last_sys_error());
260 ERR_add_error_data(5,"fopen('",ptr,"','",p,"')");
261 BIOerr(BIO_F_FILE_CTRL,ERR_R_SYS_LIB);
262 ret=0;
263 break;
264 }
265 b->ptr=(char *)fp;
266 b->init=1;
267 break;
268 case BIO_C_GET_FILE_PTR:
269 /* the ptr parameter is actually a FILE ** in this case. */
270 if (ptr != NULL)
271 {
272 fpp=(FILE **)ptr;
273 *fpp=(FILE *)b->ptr;
274 }
275 break;
276 case BIO_CTRL_GET_CLOSE:
277 ret=(long)b->shutdown;
278 break;
279 case BIO_CTRL_SET_CLOSE:
280 b->shutdown=(int)num;
281 break;
282 case BIO_CTRL_FLUSH:
283 fflush((FILE *)b->ptr);
284 break;
285 case BIO_CTRL_DUP:
286 ret=1;
287 break;
288
289 case BIO_CTRL_WPENDING:
290 case BIO_CTRL_PENDING:
291 case BIO_CTRL_PUSH:
292 case BIO_CTRL_POP:
293 default:
294 ret=0;
295 break;
296 }
297 return(ret);
298 }
299
300static int MS_CALLBACK file_gets(BIO *bp, char *buf, int size)
301 {
302 int ret=0;
303
304 buf[0]='\0';
305 fgets(buf,size,(FILE *)bp->ptr);
306 if (buf[0] != '\0')
307 ret=strlen(buf);
308 return(ret);
309 }
310
311static int MS_CALLBACK file_puts(BIO *bp, const char *str)
312 {
313 int n,ret;
314
315 n=strlen(str);
316 ret=file_write(bp,str,n);
317 return(ret);
318 }
319
320#endif /* OPENSSL_NO_STDIO */
321
322#endif /* HEADER_BSS_FILE_C */
323
324
diff --git a/src/lib/libcrypto/bio/bss_log.c b/src/lib/libcrypto/bio/bss_log.c
deleted file mode 100644
index a39d95297c..0000000000
--- a/src/lib/libcrypto/bio/bss_log.c
+++ /dev/null
@@ -1,395 +0,0 @@
1/* crypto/bio/bss_log.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/*
57 Why BIO_s_log?
58
59 BIO_s_log is useful for system daemons (or services under NT).
60 It is one-way BIO, it sends all stuff to syslogd (on system that
61 commonly use that), or event log (on NT), or OPCOM (on OpenVMS).
62
63*/
64
65
66#include <stdio.h>
67#include <errno.h>
68
69#include "cryptlib.h"
70
71#if defined(OPENSSL_SYS_WIN32)
72# include <process.h>
73#elif defined(OPENSSL_SYS_VMS)
74# include <opcdef.h>
75# include <descrip.h>
76# include <lib$routines.h>
77# include <starlet.h>
78#elif defined(__ultrix)
79# include <sys/syslog.h>
80#elif !defined(MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && !defined(NO_SYSLOG) /* Unix */
81# include <syslog.h>
82#endif
83
84#include <openssl/buffer.h>
85#include <openssl/err.h>
86
87#ifndef NO_SYSLOG
88
89#if defined(OPENSSL_SYS_WIN32)
90#define LOG_EMERG 0
91#define LOG_ALERT 1
92#define LOG_CRIT 2
93#define LOG_ERR 3
94#define LOG_WARNING 4
95#define LOG_NOTICE 5
96#define LOG_INFO 6
97#define LOG_DEBUG 7
98
99#define LOG_DAEMON (3<<3)
100#elif defined(OPENSSL_SYS_VMS)
101/* On VMS, we don't really care about these, but we need them to compile */
102#define LOG_EMERG 0
103#define LOG_ALERT 1
104#define LOG_CRIT 2
105#define LOG_ERR 3
106#define LOG_WARNING 4
107#define LOG_NOTICE 5
108#define LOG_INFO 6
109#define LOG_DEBUG 7
110
111#define LOG_DAEMON OPC$M_NM_NTWORK
112#endif
113
114static int MS_CALLBACK slg_write(BIO *h, const char *buf, int num);
115static int MS_CALLBACK slg_puts(BIO *h, const char *str);
116static long MS_CALLBACK slg_ctrl(BIO *h, int cmd, long arg1, void *arg2);
117static int MS_CALLBACK slg_new(BIO *h);
118static int MS_CALLBACK slg_free(BIO *data);
119static void xopenlog(BIO* bp, char* name, int level);
120static void xsyslog(BIO* bp, int priority, const char* string);
121static void xcloselog(BIO* bp);
122#ifdef OPENSSL_SYS_WIN32
123LONG (WINAPI *go_for_advapi)() = RegOpenKeyEx;
124HANDLE (WINAPI *register_event_source)() = NULL;
125BOOL (WINAPI *deregister_event_source)() = NULL;
126BOOL (WINAPI *report_event)() = NULL;
127#define DL_PROC(m,f) (GetProcAddress( m, f ))
128#ifdef UNICODE
129#define DL_PROC_X(m,f) DL_PROC( m, f "W" )
130#else
131#define DL_PROC_X(m,f) DL_PROC( m, f "A" )
132#endif
133#endif
134
135static BIO_METHOD methods_slg=
136 {
137 BIO_TYPE_MEM,"syslog",
138 slg_write,
139 NULL,
140 slg_puts,
141 NULL,
142 slg_ctrl,
143 slg_new,
144 slg_free,
145 NULL,
146 };
147
148BIO_METHOD *BIO_s_log(void)
149 {
150 return(&methods_slg);
151 }
152
153static int MS_CALLBACK slg_new(BIO *bi)
154 {
155 bi->init=1;
156 bi->num=0;
157 bi->ptr=NULL;
158 xopenlog(bi, "application", LOG_DAEMON);
159 return(1);
160 }
161
162static int MS_CALLBACK slg_free(BIO *a)
163 {
164 if (a == NULL) return(0);
165 xcloselog(a);
166 return(1);
167 }
168
169static int MS_CALLBACK slg_write(BIO *b, const char *in, int inl)
170 {
171 int ret= inl;
172 char* buf;
173 char* pp;
174 int priority, i;
175 static struct
176 {
177 int strl;
178 char str[10];
179 int log_level;
180 }
181 mapping[] =
182 {
183 { 6, "PANIC ", LOG_EMERG },
184 { 6, "EMERG ", LOG_EMERG },
185 { 4, "EMR ", LOG_EMERG },
186 { 6, "ALERT ", LOG_ALERT },
187 { 4, "ALR ", LOG_ALERT },
188 { 5, "CRIT ", LOG_CRIT },
189 { 4, "CRI ", LOG_CRIT },
190 { 6, "ERROR ", LOG_ERR },
191 { 4, "ERR ", LOG_ERR },
192 { 8, "WARNING ", LOG_WARNING },
193 { 5, "WARN ", LOG_WARNING },
194 { 4, "WAR ", LOG_WARNING },
195 { 7, "NOTICE ", LOG_NOTICE },
196 { 5, "NOTE ", LOG_NOTICE },
197 { 4, "NOT ", LOG_NOTICE },
198 { 5, "INFO ", LOG_INFO },
199 { 4, "INF ", LOG_INFO },
200 { 6, "DEBUG ", LOG_DEBUG },
201 { 4, "DBG ", LOG_DEBUG },
202 { 0, "", LOG_ERR } /* The default */
203 };
204
205 if((buf= (char *)OPENSSL_malloc(inl+ 1)) == NULL){
206 return(0);
207 }
208 strncpy(buf, in, inl);
209 buf[inl]= '\0';
210
211 i = 0;
212 while(strncmp(buf, mapping[i].str, mapping[i].strl) != 0) i++;
213 priority = mapping[i].log_level;
214 pp = buf + mapping[i].strl;
215
216 xsyslog(b, priority, pp);
217
218 OPENSSL_free(buf);
219 return(ret);
220 }
221
222static long MS_CALLBACK slg_ctrl(BIO *b, int cmd, long num, void *ptr)
223 {
224 switch (cmd)
225 {
226 case BIO_CTRL_SET:
227 xcloselog(b);
228 xopenlog(b, ptr, num);
229 break;
230 default:
231 break;
232 }
233 return(0);
234 }
235
236static int MS_CALLBACK slg_puts(BIO *bp, const char *str)
237 {
238 int n,ret;
239
240 n=strlen(str);
241 ret=slg_write(bp,str,n);
242 return(ret);
243 }
244
245#if defined(OPENSSL_SYS_WIN32)
246
247static void xopenlog(BIO* bp, char* name, int level)
248{
249 if ( !register_event_source )
250 {
251 HANDLE advapi;
252 if ( !(advapi = GetModuleHandle("advapi32")) )
253 return;
254 register_event_source = (HANDLE (WINAPI *)())DL_PROC_X(advapi,
255 "RegisterEventSource" );
256 deregister_event_source = (BOOL (WINAPI *)())DL_PROC(advapi,
257 "DeregisterEventSource");
258 report_event = (BOOL (WINAPI *)())DL_PROC_X(advapi,
259 "ReportEvent" );
260 if ( !(register_event_source && deregister_event_source &&
261 report_event) )
262 {
263 register_event_source = NULL;
264 deregister_event_source = NULL;
265 report_event = NULL;
266 return;
267 }
268 }
269 bp->ptr= (char *)register_event_source(NULL, name);
270}
271
272static void xsyslog(BIO *bp, int priority, const char *string)
273{
274 LPCSTR lpszStrings[2];
275 WORD evtype= EVENTLOG_ERROR_TYPE;
276 int pid = _getpid();
277 char pidbuf[20];
278
279 switch (priority)
280 {
281 case LOG_EMERG:
282 case LOG_ALERT:
283 case LOG_CRIT:
284 case LOG_ERR:
285 evtype = EVENTLOG_ERROR_TYPE;
286 break;
287 case LOG_WARNING:
288 evtype = EVENTLOG_WARNING_TYPE;
289 break;
290 case LOG_NOTICE:
291 case LOG_INFO:
292 case LOG_DEBUG:
293 evtype = EVENTLOG_INFORMATION_TYPE;
294 break;
295 default: /* Should never happen, but set it
296 as error anyway. */
297 evtype = EVENTLOG_ERROR_TYPE;
298 break;
299 }
300
301 sprintf(pidbuf, "[%d] ", pid);
302 lpszStrings[0] = pidbuf;
303 lpszStrings[1] = string;
304
305 if(report_event && bp->ptr)
306 report_event(bp->ptr, evtype, 0, 1024, NULL, 2, 0,
307 lpszStrings, NULL);
308}
309
310static void xcloselog(BIO* bp)
311{
312 if(deregister_event_source && bp->ptr)
313 deregister_event_source((HANDLE)(bp->ptr));
314 bp->ptr= NULL;
315}
316
317#elif defined(OPENSSL_SYS_VMS)
318
319static int VMS_OPC_target = LOG_DAEMON;
320
321static void xopenlog(BIO* bp, char* name, int level)
322{
323 VMS_OPC_target = level;
324}
325
326static void xsyslog(BIO *bp, int priority, const char *string)
327{
328 struct dsc$descriptor_s opc_dsc;
329 struct opcdef *opcdef_p;
330 char buf[10240];
331 unsigned int len;
332 struct dsc$descriptor_s buf_dsc;
333 $DESCRIPTOR(fao_cmd, "!AZ: !AZ");
334 char *priority_tag;
335
336 switch (priority)
337 {
338 case LOG_EMERG: priority_tag = "Emergency"; break;
339 case LOG_ALERT: priority_tag = "Alert"; break;
340 case LOG_CRIT: priority_tag = "Critical"; break;
341 case LOG_ERR: priority_tag = "Error"; break;
342 case LOG_WARNING: priority_tag = "Warning"; break;
343 case LOG_NOTICE: priority_tag = "Notice"; break;
344 case LOG_INFO: priority_tag = "Info"; break;
345 case LOG_DEBUG: priority_tag = "DEBUG"; break;
346 }
347
348 buf_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
349 buf_dsc.dsc$b_class = DSC$K_CLASS_S;
350 buf_dsc.dsc$a_pointer = buf;
351 buf_dsc.dsc$w_length = sizeof(buf) - 1;
352
353 lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string);
354
355 /* we know there's an 8 byte header. That's documented */
356 opcdef_p = (struct opcdef *) OPENSSL_malloc(8 + len);
357 opcdef_p->opc$b_ms_type = OPC$_RQ_RQST;
358 memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3);
359 opcdef_p->opc$l_ms_rqstid = 0;
360 memcpy(&opcdef_p->opc$l_ms_text, buf, len);
361
362 opc_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
363 opc_dsc.dsc$b_class = DSC$K_CLASS_S;
364 opc_dsc.dsc$a_pointer = (char *)opcdef_p;
365 opc_dsc.dsc$w_length = len + 8;
366
367 sys$sndopr(opc_dsc, 0);
368
369 OPENSSL_free(opcdef_p);
370}
371
372static void xcloselog(BIO* bp)
373{
374}
375
376#else /* Unix */
377
378static void xopenlog(BIO* bp, char* name, int level)
379{
380 openlog(name, LOG_PID|LOG_CONS, level);
381}
382
383static void xsyslog(BIO *bp, int priority, const char *string)
384{
385 syslog(priority, "%s", string);
386}
387
388static void xcloselog(BIO* bp)
389{
390 closelog();
391}
392
393#endif /* Unix */
394
395#endif /* NO_SYSLOG */
diff --git a/src/lib/libcrypto/bio/bss_mem.c b/src/lib/libcrypto/bio/bss_mem.c
deleted file mode 100644
index 28ff7582bf..0000000000
--- a/src/lib/libcrypto/bio/bss_mem.c
+++ /dev/null
@@ -1,317 +0,0 @@
1/* crypto/bio/bss_mem.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/bio.h>
63
64static int mem_write(BIO *h, const char *buf, int num);
65static int mem_read(BIO *h, char *buf, int size);
66static int mem_puts(BIO *h, const char *str);
67static int mem_gets(BIO *h, char *str, int size);
68static long mem_ctrl(BIO *h, int cmd, long arg1, void *arg2);
69static int mem_new(BIO *h);
70static int mem_free(BIO *data);
71static BIO_METHOD mem_method=
72 {
73 BIO_TYPE_MEM,
74 "memory buffer",
75 mem_write,
76 mem_read,
77 mem_puts,
78 mem_gets,
79 mem_ctrl,
80 mem_new,
81 mem_free,
82 NULL,
83 };
84
85/* bio->num is used to hold the value to return on 'empty', if it is
86 * 0, should_retry is not set */
87
88BIO_METHOD *BIO_s_mem(void)
89 {
90 return(&mem_method);
91 }
92
93BIO *BIO_new_mem_buf(void *buf, int len)
94{
95 BIO *ret;
96 BUF_MEM *b;
97 if (!buf) {
98 BIOerr(BIO_F_BIO_NEW_MEM_BUF,BIO_R_NULL_PARAMETER);
99 return NULL;
100 }
101 if(len == -1) len = strlen(buf);
102 if(!(ret = BIO_new(BIO_s_mem())) ) return NULL;
103 b = (BUF_MEM *)ret->ptr;
104 b->data = buf;
105 b->length = len;
106 b->max = len;
107 ret->flags |= BIO_FLAGS_MEM_RDONLY;
108 /* Since this is static data retrying wont help */
109 ret->num = 0;
110 return ret;
111}
112
113static int mem_new(BIO *bi)
114 {
115 BUF_MEM *b;
116
117 if ((b=BUF_MEM_new()) == NULL)
118 return(0);
119 bi->shutdown=1;
120 bi->init=1;
121 bi->num= -1;
122 bi->ptr=(char *)b;
123 return(1);
124 }
125
126static int mem_free(BIO *a)
127 {
128 if (a == NULL) return(0);
129 if (a->shutdown)
130 {
131 if ((a->init) && (a->ptr != NULL))
132 {
133 BUF_MEM *b;
134 b = (BUF_MEM *)a->ptr;
135 if(a->flags & BIO_FLAGS_MEM_RDONLY) b->data = NULL;
136 BUF_MEM_free(b);
137 a->ptr=NULL;
138 }
139 }
140 return(1);
141 }
142
143static int mem_read(BIO *b, char *out, int outl)
144 {
145 int ret= -1;
146 BUF_MEM *bm;
147 int i;
148 char *from,*to;
149
150 bm=(BUF_MEM *)b->ptr;
151 BIO_clear_retry_flags(b);
152 ret=(outl > bm->length)?bm->length:outl;
153 if ((out != NULL) && (ret > 0)) {
154 memcpy(out,bm->data,ret);
155 bm->length-=ret;
156 /* memmove(&(bm->data[0]),&(bm->data[ret]), bm->length); */
157 if(b->flags & BIO_FLAGS_MEM_RDONLY) bm->data += ret;
158 else {
159 from=(char *)&(bm->data[ret]);
160 to=(char *)&(bm->data[0]);
161 for (i=0; i<bm->length; i++)
162 to[i]=from[i];
163 }
164 } else if (bm->length == 0)
165 {
166 ret = b->num;
167 if (ret != 0)
168 BIO_set_retry_read(b);
169 }
170 return(ret);
171 }
172
173static int mem_write(BIO *b, const char *in, int inl)
174 {
175 int ret= -1;
176 int blen;
177 BUF_MEM *bm;
178
179 bm=(BUF_MEM *)b->ptr;
180 if (in == NULL)
181 {
182 BIOerr(BIO_F_MEM_WRITE,BIO_R_NULL_PARAMETER);
183 goto end;
184 }
185
186 if(b->flags & BIO_FLAGS_MEM_RDONLY) {
187 BIOerr(BIO_F_MEM_WRITE,BIO_R_WRITE_TO_READ_ONLY_BIO);
188 goto end;
189 }
190
191 BIO_clear_retry_flags(b);
192 blen=bm->length;
193 if (BUF_MEM_grow(bm,blen+inl) != (blen+inl))
194 goto end;
195 memcpy(&(bm->data[blen]),in,inl);
196 ret=inl;
197end:
198 return(ret);
199 }
200
201static long mem_ctrl(BIO *b, int cmd, long num, void *ptr)
202 {
203 long ret=1;
204 char **pptr;
205
206 BUF_MEM *bm=(BUF_MEM *)b->ptr;
207
208 switch (cmd)
209 {
210 case BIO_CTRL_RESET:
211 if (bm->data != NULL)
212 {
213 /* For read only case reset to the start again */
214 if(b->flags & BIO_FLAGS_MEM_RDONLY)
215 {
216 bm->data -= bm->max - bm->length;
217 bm->length = bm->max;
218 }
219 else
220 {
221 memset(bm->data,0,bm->max);
222 bm->length=0;
223 }
224 }
225 break;
226 case BIO_CTRL_EOF:
227 ret=(long)(bm->length == 0);
228 break;
229 case BIO_C_SET_BUF_MEM_EOF_RETURN:
230 b->num=(int)num;
231 break;
232 case BIO_CTRL_INFO:
233 ret=(long)bm->length;
234 if (ptr != NULL)
235 {
236 pptr=(char **)ptr;
237 *pptr=(char *)&(bm->data[0]);
238 }
239 break;
240 case BIO_C_SET_BUF_MEM:
241 mem_free(b);
242 b->shutdown=(int)num;
243 b->ptr=ptr;
244 break;
245 case BIO_C_GET_BUF_MEM_PTR:
246 if (ptr != NULL)
247 {
248 pptr=(char **)ptr;
249 *pptr=(char *)bm;
250 }
251 break;
252 case BIO_CTRL_GET_CLOSE:
253 ret=(long)b->shutdown;
254 break;
255 case BIO_CTRL_SET_CLOSE:
256 b->shutdown=(int)num;
257 break;
258
259 case BIO_CTRL_WPENDING:
260 ret=0L;
261 break;
262 case BIO_CTRL_PENDING:
263 ret=(long)bm->length;
264 break;
265 case BIO_CTRL_DUP:
266 case BIO_CTRL_FLUSH:
267 ret=1;
268 break;
269 case BIO_CTRL_PUSH:
270 case BIO_CTRL_POP:
271 default:
272 ret=0;
273 break;
274 }
275 return(ret);
276 }
277
278static int mem_gets(BIO *bp, char *buf, int size)
279 {
280 int i,j;
281 int ret= -1;
282 char *p;
283 BUF_MEM *bm=(BUF_MEM *)bp->ptr;
284
285 BIO_clear_retry_flags(bp);
286 j=bm->length;
287 if (j <= 0) return(0);
288 p=bm->data;
289 for (i=0; i<j; i++)
290 {
291 if (p[i] == '\n') break;
292 }
293 if (i == j)
294 {
295 BIO_set_retry_read(bp);
296 /* return(-1); change the semantics 0.6.6a */
297 }
298 else
299 i++;
300 /* i is the max to copy */
301 if ((size-1) < i) i=size-1;
302 i=mem_read(bp,buf,i);
303 if (i > 0) buf[i]='\0';
304 ret=i;
305 return(ret);
306 }
307
308static int mem_puts(BIO *bp, const char *str)
309 {
310 int n,ret;
311
312 n=strlen(str);
313 ret=mem_write(bp,str,n);
314 /* memory semantics is that it will always work */
315 return(ret);
316 }
317
diff --git a/src/lib/libcrypto/bio/bss_null.c b/src/lib/libcrypto/bio/bss_null.c
deleted file mode 100644
index 46b73339df..0000000000
--- a/src/lib/libcrypto/bio/bss_null.c
+++ /dev/null
@@ -1,150 +0,0 @@
1/* crypto/bio/bss_null.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/bio.h>
63
64static int null_write(BIO *h, const char *buf, int num);
65static int null_read(BIO *h, char *buf, int size);
66static int null_puts(BIO *h, const char *str);
67static int null_gets(BIO *h, char *str, int size);
68static long null_ctrl(BIO *h, int cmd, long arg1, void *arg2);
69static int null_new(BIO *h);
70static int null_free(BIO *data);
71static BIO_METHOD null_method=
72 {
73 BIO_TYPE_NULL,
74 "NULL",
75 null_write,
76 null_read,
77 null_puts,
78 null_gets,
79 null_ctrl,
80 null_new,
81 null_free,
82 NULL,
83 };
84
85BIO_METHOD *BIO_s_null(void)
86 {
87 return(&null_method);
88 }
89
90static int null_new(BIO *bi)
91 {
92 bi->init=1;
93 bi->num=0;
94 bi->ptr=(NULL);
95 return(1);
96 }
97
98static int null_free(BIO *a)
99 {
100 if (a == NULL) return(0);
101 return(1);
102 }
103
104static int null_read(BIO *b, char *out, int outl)
105 {
106 return(0);
107 }
108
109static int null_write(BIO *b, const char *in, int inl)
110 {
111 return(inl);
112 }
113
114static long null_ctrl(BIO *b, int cmd, long num, void *ptr)
115 {
116 long ret=1;
117
118 switch (cmd)
119 {
120 case BIO_CTRL_RESET:
121 case BIO_CTRL_EOF:
122 case BIO_CTRL_SET:
123 case BIO_CTRL_SET_CLOSE:
124 case BIO_CTRL_FLUSH:
125 case BIO_CTRL_DUP:
126 ret=1;
127 break;
128 case BIO_CTRL_GET_CLOSE:
129 case BIO_CTRL_INFO:
130 case BIO_CTRL_GET:
131 case BIO_CTRL_PENDING:
132 case BIO_CTRL_WPENDING:
133 default:
134 ret=0;
135 break;
136 }
137 return(ret);
138 }
139
140static int null_gets(BIO *bp, char *buf, int size)
141 {
142 return(0);
143 }
144
145static int null_puts(BIO *bp, const char *str)
146 {
147 if (str == NULL) return(0);
148 return(strlen(str));
149 }
150
diff --git a/src/lib/libcrypto/bio/bss_sock.c b/src/lib/libcrypto/bio/bss_sock.c
deleted file mode 100644
index fdabd16d7e..0000000000
--- a/src/lib/libcrypto/bio/bss_sock.c
+++ /dev/null
@@ -1,299 +0,0 @@
1/* crypto/bio/bss_sock.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_SOCK
60
61#include <stdio.h>
62#include <errno.h>
63#define USE_SOCKETS
64#include "cryptlib.h"
65#include <openssl/bio.h>
66
67static int sock_write(BIO *h, const char *buf, int num);
68static int sock_read(BIO *h, char *buf, int size);
69static int sock_puts(BIO *h, const char *str);
70static long sock_ctrl(BIO *h, int cmd, long arg1, void *arg2);
71static int sock_new(BIO *h);
72static int sock_free(BIO *data);
73int BIO_sock_should_retry(int s);
74
75static BIO_METHOD methods_sockp=
76 {
77 BIO_TYPE_SOCKET,
78 "socket",
79 sock_write,
80 sock_read,
81 sock_puts,
82 NULL, /* sock_gets, */
83 sock_ctrl,
84 sock_new,
85 sock_free,
86 NULL,
87 };
88
89BIO_METHOD *BIO_s_socket(void)
90 {
91 return(&methods_sockp);
92 }
93
94BIO *BIO_new_socket(int fd, int close_flag)
95 {
96 BIO *ret;
97
98 ret=BIO_new(BIO_s_socket());
99 if (ret == NULL) return(NULL);
100 BIO_set_fd(ret,fd,close_flag);
101 return(ret);
102 }
103
104static int sock_new(BIO *bi)
105 {
106 bi->init=0;
107 bi->num=0;
108 bi->ptr=NULL;
109 bi->flags=0;
110 return(1);
111 }
112
113static int sock_free(BIO *a)
114 {
115 if (a == NULL) return(0);
116 if (a->shutdown)
117 {
118 if (a->init)
119 {
120 SHUTDOWN2(a->num);
121 }
122 a->init=0;
123 a->flags=0;
124 }
125 return(1);
126 }
127
128static int sock_read(BIO *b, char *out, int outl)
129 {
130 int ret=0;
131
132 if (out != NULL)
133 {
134 clear_socket_error();
135 ret=readsocket(b->num,out,outl);
136 BIO_clear_retry_flags(b);
137 if (ret <= 0)
138 {
139 if (BIO_sock_should_retry(ret))
140 BIO_set_retry_read(b);
141 }
142 }
143 return(ret);
144 }
145
146static int sock_write(BIO *b, const char *in, int inl)
147 {
148 int ret;
149
150 clear_socket_error();
151 ret=writesocket(b->num,in,inl);
152 BIO_clear_retry_flags(b);
153 if (ret <= 0)
154 {
155 if (BIO_sock_should_retry(ret))
156 BIO_set_retry_write(b);
157 }
158 return(ret);
159 }
160
161static long sock_ctrl(BIO *b, int cmd, long num, void *ptr)
162 {
163 long ret=1;
164 int *ip;
165
166 switch (cmd)
167 {
168 case BIO_CTRL_RESET:
169 num=0;
170 case BIO_C_FILE_SEEK:
171 ret=0;
172 break;
173 case BIO_C_FILE_TELL:
174 case BIO_CTRL_INFO:
175 ret=0;
176 break;
177 case BIO_C_SET_FD:
178 sock_free(b);
179 b->num= *((int *)ptr);
180 b->shutdown=(int)num;
181 b->init=1;
182 break;
183 case BIO_C_GET_FD:
184 if (b->init)
185 {
186 ip=(int *)ptr;
187 if (ip != NULL) *ip=b->num;
188 ret=b->num;
189 }
190 else
191 ret= -1;
192 break;
193 case BIO_CTRL_GET_CLOSE:
194 ret=b->shutdown;
195 break;
196 case BIO_CTRL_SET_CLOSE:
197 b->shutdown=(int)num;
198 break;
199 case BIO_CTRL_PENDING:
200 case BIO_CTRL_WPENDING:
201 ret=0;
202 break;
203 case BIO_CTRL_DUP:
204 case BIO_CTRL_FLUSH:
205 ret=1;
206 break;
207 default:
208 ret=0;
209 break;
210 }
211 return(ret);
212 }
213
214static int sock_puts(BIO *bp, const char *str)
215 {
216 int n,ret;
217
218 n=strlen(str);
219 ret=sock_write(bp,str,n);
220 return(ret);
221 }
222
223int BIO_sock_should_retry(int i)
224 {
225 int err;
226
227 if ((i == 0) || (i == -1))
228 {
229 err=get_last_socket_error();
230
231#if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
232 if ((i == -1) && (err == 0))
233 return(1);
234#endif
235
236 return(BIO_sock_non_fatal_error(err));
237 }
238 return(0);
239 }
240
241int BIO_sock_non_fatal_error(int err)
242 {
243 switch (err)
244 {
245#if defined(OPENSSL_SYS_WINDOWS)
246# if defined(WSAEWOULDBLOCK)
247 case WSAEWOULDBLOCK:
248# endif
249
250# if 0 /* This appears to always be an error */
251# if defined(WSAENOTCONN)
252 case WSAENOTCONN:
253# endif
254# endif
255#endif
256
257#ifdef EWOULDBLOCK
258# ifdef WSAEWOULDBLOCK
259# if WSAEWOULDBLOCK != EWOULDBLOCK
260 case EWOULDBLOCK:
261# endif
262# else
263 case EWOULDBLOCK:
264# endif
265#endif
266
267#if defined(ENOTCONN)
268 case ENOTCONN:
269#endif
270
271#ifdef EINTR
272 case EINTR:
273#endif
274
275#ifdef EAGAIN
276#if EWOULDBLOCK != EAGAIN
277 case EAGAIN:
278# endif
279#endif
280
281#ifdef EPROTO
282 case EPROTO:
283#endif
284
285#ifdef EINPROGRESS
286 case EINPROGRESS:
287#endif
288
289#ifdef EALREADY
290 case EALREADY:
291#endif
292 return(1);
293 /* break; */
294 default:
295 break;
296 }
297 return(0);
298 }
299#endif