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