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