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