diff options
author | cvs2svn <admin@example.com> | 1999-10-10 21:32:03 +0000 |
---|---|---|
committer | cvs2svn <admin@example.com> | 1999-10-10 21:32:03 +0000 |
commit | 14e61fef302fbc25ab63e38bd35445637ca68139 (patch) | |
tree | dae5e50679bccd1ed8d7d4041fbb9f3d96bbc98c /src/lib/libcrypto/bio | |
parent | 3ef9529fbf0c1f8f1c9da1172e92ad3370d5fcfe (diff) | |
download | openbsd-OPENBSD_2_6_BASE.tar.gz openbsd-OPENBSD_2_6_BASE.tar.bz2 openbsd-OPENBSD_2_6_BASE.zip |
This commit was manufactured by cvs2git to create tag 'OPENBSD_2_6_BASE'.OPENBSD_2_6_BASE
Diffstat (limited to 'src/lib/libcrypto/bio')
-rw-r--r-- | src/lib/libcrypto/bio/b_dump.c | 128 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/b_print.c | 87 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/b_sock.c | 703 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bf_buff.c | 485 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bf_nbio.c | 240 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bf_null.c | 168 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bio.h | 643 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bio_cb.c | 133 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bio_err.c | 139 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bio_lib.c | 496 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_acpt.c | 466 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_bio.c | 588 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_conn.c | 618 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_fd.c | 62 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_file.c | 309 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_log.c | 232 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_mem.c | 276 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_null.c | 149 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_sock.c | 423 |
19 files changed, 0 insertions, 6345 deletions
diff --git a/src/lib/libcrypto/bio/b_dump.c b/src/lib/libcrypto/bio/b_dump.c deleted file mode 100644 index a7cd828978..0000000000 --- a/src/lib/libcrypto/bio/b_dump.c +++ /dev/null | |||
@@ -1,128 +0,0 @@ | |||
1 | /* crypto/bio/b_dump.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | /* | ||
60 | * Stolen from tjh's ssl/ssl_trc.c stuff. | ||
61 | */ | ||
62 | |||
63 | #include <stdio.h> | ||
64 | #include "cryptlib.h" | ||
65 | #include <openssl/bio.h> | ||
66 | |||
67 | #define TRUNCATE | ||
68 | #define DUMP_WIDTH 16 | ||
69 | |||
70 | int BIO_dump(BIO *bio, const char *s, int len) | ||
71 | { | ||
72 | int ret=0; | ||
73 | char buf[160+1],tmp[20]; | ||
74 | int i,j,rows,trunc; | ||
75 | unsigned char ch; | ||
76 | |||
77 | trunc=0; | ||
78 | |||
79 | #ifdef TRUNCATE | ||
80 | for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--) | ||
81 | trunc++; | ||
82 | #endif | ||
83 | |||
84 | rows=(len/DUMP_WIDTH); | ||
85 | if ((rows*DUMP_WIDTH)<len) | ||
86 | rows++; | ||
87 | for(i=0;i<rows;i++) { | ||
88 | buf[0]='\0'; /* start with empty string */ | ||
89 | sprintf(tmp,"%04x - ",i*DUMP_WIDTH); | ||
90 | strcpy(buf,tmp); | ||
91 | for(j=0;j<DUMP_WIDTH;j++) { | ||
92 | if (((i*DUMP_WIDTH)+j)>=len) { | ||
93 | strcat(buf," "); | ||
94 | } else { | ||
95 | ch=((unsigned char)*((char *)(s)+i*DUMP_WIDTH+j)) & 0xff; | ||
96 | sprintf(tmp,"%02x%c",ch,j==7?'-':' '); | ||
97 | strcat(buf,tmp); | ||
98 | } | ||
99 | } | ||
100 | strcat(buf," "); | ||
101 | for(j=0;j<DUMP_WIDTH;j++) { | ||
102 | if (((i*DUMP_WIDTH)+j)>=len) | ||
103 | break; | ||
104 | ch=((unsigned char)*((char *)(s)+i*DUMP_WIDTH+j)) & 0xff; | ||
105 | #ifndef CHARSET_EBCDIC | ||
106 | sprintf(tmp,"%c",((ch>=' ')&&(ch<='~'))?ch:'.'); | ||
107 | #else | ||
108 | sprintf(tmp,"%c",((ch>=os_toascii[' '])&&(ch<=os_toascii['~'])) | ||
109 | ? os_toebcdic[ch] | ||
110 | : '.'); | ||
111 | #endif | ||
112 | strcat(buf,tmp); | ||
113 | } | ||
114 | strcat(buf,"\n"); | ||
115 | /* if this is the last call then update the ddt_dump thing so that | ||
116 | * we will move the selection point in the debug window | ||
117 | */ | ||
118 | ret+=BIO_write(bio,(char *)buf,strlen(buf)); | ||
119 | } | ||
120 | #ifdef TRUNCATE | ||
121 | if (trunc > 0) { | ||
122 | sprintf(buf,"%04x - <SPACES/NULS>\n",len+trunc); | ||
123 | ret+=BIO_write(bio,(char *)buf,strlen(buf)); | ||
124 | } | ||
125 | #endif | ||
126 | return(ret); | ||
127 | } | ||
128 | |||
diff --git a/src/lib/libcrypto/bio/b_print.c b/src/lib/libcrypto/bio/b_print.c deleted file mode 100644 index f448004298..0000000000 --- a/src/lib/libcrypto/bio/b_print.c +++ /dev/null | |||
@@ -1,87 +0,0 @@ | |||
1 | /* crypto/bio/b_print.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | /* | ||
60 | * Stolen from tjh's ssl/ssl_trc.c stuff. | ||
61 | */ | ||
62 | |||
63 | #include <stdio.h> | ||
64 | #include <stdarg.h> | ||
65 | #include "cryptlib.h" | ||
66 | #include <openssl/bio.h> | ||
67 | |||
68 | int BIO_printf (BIO *bio, ...) | ||
69 | { | ||
70 | va_list args; | ||
71 | char *format; | ||
72 | int ret; | ||
73 | MS_STATIC char hugebuf[1024*2]; /* 10k in one chunk is the limit */ | ||
74 | |||
75 | va_start(args, bio); | ||
76 | format=va_arg(args, char *); | ||
77 | |||
78 | hugebuf[0]='\0'; | ||
79 | |||
80 | vsprintf(hugebuf,format,args); | ||
81 | |||
82 | ret=BIO_write(bio,hugebuf,strlen(hugebuf)); | ||
83 | |||
84 | va_end(args); | ||
85 | return(ret); | ||
86 | } | ||
87 | |||
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c deleted file mode 100644 index d29b29ff8b..0000000000 --- a/src/lib/libcrypto/bio/b_sock.c +++ /dev/null | |||
@@ -1,703 +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) return(1); | ||
109 | if (i < 0) | ||
110 | { | ||
111 | BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_INVALID_IP_ADDRESS); | ||
112 | goto err; | ||
113 | } | ||
114 | |||
115 | /* do a gethostbyname */ | ||
116 | if (!BIO_sock_init()) | ||
117 | return(0); /* don't generate another error code here */ | ||
118 | |||
119 | CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); | ||
120 | locked = 1; | ||
121 | he=BIO_gethostbyname(str); | ||
122 | if (he == NULL) | ||
123 | { | ||
124 | BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_BAD_HOSTNAME_LOOKUP); | ||
125 | goto err; | ||
126 | } | ||
127 | |||
128 | /* cast to short because of win16 winsock definition */ | ||
129 | if ((short)he->h_addrtype != AF_INET) | ||
130 | { | ||
131 | BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET); | ||
132 | goto err; | ||
133 | } | ||
134 | for (i=0; i<4; i++) | ||
135 | ip[i]=he->h_addr_list[0][i]; | ||
136 | err = 0; | ||
137 | |||
138 | err: | ||
139 | if (locked) | ||
140 | CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); | ||
141 | if (err) | ||
142 | { | ||
143 | ERR_add_error_data(2,"host=",str); | ||
144 | return 0; | ||
145 | } | ||
146 | else | ||
147 | return 1; | ||
148 | } | ||
149 | |||
150 | int BIO_get_port(const char *str, unsigned short *port_ptr) | ||
151 | { | ||
152 | int i; | ||
153 | struct servent *s; | ||
154 | |||
155 | if (str == NULL) | ||
156 | { | ||
157 | BIOerr(BIO_F_BIO_GET_PORT,BIO_R_NO_PORT_DEFINED); | ||
158 | return(0); | ||
159 | } | ||
160 | i=atoi(str); | ||
161 | if (i != 0) | ||
162 | *port_ptr=(unsigned short)i; | ||
163 | else | ||
164 | { | ||
165 | CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME); | ||
166 | s=getservbyname(str,"tcp"); | ||
167 | if(s != NULL) | ||
168 | *port_ptr=ntohs((unsigned short)s->s_port); | ||
169 | CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME); | ||
170 | if(s == NULL) | ||
171 | { | ||
172 | if (strcmp(str,"http") == 0) | ||
173 | *port_ptr=80; | ||
174 | else if (strcmp(str,"telnet") == 0) | ||
175 | *port_ptr=23; | ||
176 | else if (strcmp(str,"socks") == 0) | ||
177 | *port_ptr=1080; | ||
178 | else if (strcmp(str,"https") == 0) | ||
179 | *port_ptr=443; | ||
180 | else if (strcmp(str,"ssl") == 0) | ||
181 | *port_ptr=443; | ||
182 | else if (strcmp(str,"ftp") == 0) | ||
183 | *port_ptr=21; | ||
184 | else if (strcmp(str,"gopher") == 0) | ||
185 | *port_ptr=70; | ||
186 | #if 0 | ||
187 | else if (strcmp(str,"wais") == 0) | ||
188 | *port_ptr=21; | ||
189 | #endif | ||
190 | else | ||
191 | { | ||
192 | SYSerr(SYS_F_GETSERVBYNAME,get_last_socket_error()); | ||
193 | ERR_add_error_data(3,"service='",str,"'"); | ||
194 | return(0); | ||
195 | } | ||
196 | } | ||
197 | } | ||
198 | return(1); | ||
199 | } | ||
200 | |||
201 | int BIO_sock_error(int sock) | ||
202 | { | ||
203 | int j,i; | ||
204 | int size; | ||
205 | |||
206 | size=sizeof(int); | ||
207 | /* Note: under Windows the third parameter is of type (char *) | ||
208 | * whereas under other systems it is (void *) if you don't have | ||
209 | * a cast it will choke the compiler: if you do have a cast then | ||
210 | * you can either go for (char *) or (void *). | ||
211 | */ | ||
212 | i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(void *)&j,(void *)&size); | ||
213 | if (i < 0) | ||
214 | return(1); | ||
215 | else | ||
216 | return(j); | ||
217 | } | ||
218 | |||
219 | long BIO_ghbn_ctrl(int cmd, int iarg, char *parg) | ||
220 | { | ||
221 | int i; | ||
222 | char **p; | ||
223 | |||
224 | switch (cmd) | ||
225 | { | ||
226 | case BIO_GHBN_CTRL_HITS: | ||
227 | return(BIO_ghbn_hits); | ||
228 | /* break; */ | ||
229 | case BIO_GHBN_CTRL_MISSES: | ||
230 | return(BIO_ghbn_miss); | ||
231 | /* break; */ | ||
232 | case BIO_GHBN_CTRL_CACHE_SIZE: | ||
233 | return(GHBN_NUM); | ||
234 | /* break; */ | ||
235 | case BIO_GHBN_CTRL_GET_ENTRY: | ||
236 | if ((iarg >= 0) && (iarg <GHBN_NUM) && | ||
237 | (ghbn_cache[iarg].order > 0)) | ||
238 | { | ||
239 | p=(char **)parg; | ||
240 | if (p == NULL) return(0); | ||
241 | *p=ghbn_cache[iarg].name; | ||
242 | ghbn_cache[iarg].name[128]='\0'; | ||
243 | return(1); | ||
244 | } | ||
245 | return(0); | ||
246 | /* break; */ | ||
247 | case BIO_GHBN_CTRL_FLUSH: | ||
248 | for (i=0; i<GHBN_NUM; i++) | ||
249 | ghbn_cache[i].order=0; | ||
250 | break; | ||
251 | default: | ||
252 | return(0); | ||
253 | } | ||
254 | return(1); | ||
255 | } | ||
256 | |||
257 | static struct hostent *ghbn_dup(struct hostent *a) | ||
258 | { | ||
259 | struct hostent *ret; | ||
260 | int i,j; | ||
261 | |||
262 | MemCheck_off(); | ||
263 | ret=(struct hostent *)Malloc(sizeof(struct hostent)); | ||
264 | if (ret == NULL) return(NULL); | ||
265 | memset(ret,0,sizeof(struct hostent)); | ||
266 | |||
267 | for (i=0; a->h_aliases[i] != NULL; i++) | ||
268 | ; | ||
269 | i++; | ||
270 | ret->h_aliases = (char **)Malloc(i*sizeof(char *)); | ||
271 | if (ret->h_aliases == NULL) | ||
272 | goto err; | ||
273 | memset(ret->h_aliases, 0, i*sizeof(char *)); | ||
274 | |||
275 | for (i=0; a->h_addr_list[i] != NULL; i++) | ||
276 | ; | ||
277 | i++; | ||
278 | ret->h_addr_list=(char **)Malloc(i*sizeof(char *)); | ||
279 | if (ret->h_addr_list == NULL) | ||
280 | goto err; | ||
281 | memset(ret->h_addr_list, 0, i*sizeof(char *)); | ||
282 | |||
283 | j=strlen(a->h_name)+1; | ||
284 | if ((ret->h_name=Malloc(j)) == NULL) goto err; | ||
285 | memcpy((char *)ret->h_name,a->h_name,j+1); | ||
286 | for (i=0; a->h_aliases[i] != NULL; i++) | ||
287 | { | ||
288 | j=strlen(a->h_aliases[i])+1; | ||
289 | if ((ret->h_aliases[i]=Malloc(j)) == NULL) goto err; | ||
290 | memcpy(ret->h_aliases[i],a->h_aliases[i],j+1); | ||
291 | } | ||
292 | ret->h_length=a->h_length; | ||
293 | ret->h_addrtype=a->h_addrtype; | ||
294 | for (i=0; a->h_addr_list[i] != NULL; i++) | ||
295 | { | ||
296 | if ((ret->h_addr_list[i]=Malloc(a->h_length)) == NULL) | ||
297 | goto err; | ||
298 | memcpy(ret->h_addr_list[i],a->h_addr_list[i],a->h_length); | ||
299 | } | ||
300 | if (0) | ||
301 | { | ||
302 | err: | ||
303 | if (ret != NULL) | ||
304 | ghbn_free(ret); | ||
305 | ret=NULL; | ||
306 | } | ||
307 | MemCheck_on(); | ||
308 | return(ret); | ||
309 | } | ||
310 | |||
311 | static void ghbn_free(struct hostent *a) | ||
312 | { | ||
313 | int i; | ||
314 | |||
315 | if(a == NULL) | ||
316 | return; | ||
317 | |||
318 | if (a->h_aliases != NULL) | ||
319 | { | ||
320 | for (i=0; a->h_aliases[i] != NULL; i++) | ||
321 | Free(a->h_aliases[i]); | ||
322 | Free(a->h_aliases); | ||
323 | } | ||
324 | if (a->h_addr_list != NULL) | ||
325 | { | ||
326 | for (i=0; a->h_addr_list[i] != NULL; i++) | ||
327 | Free(a->h_addr_list[i]); | ||
328 | Free(a->h_addr_list); | ||
329 | } | ||
330 | if (a->h_name != NULL) Free((char *)a->h_name); | ||
331 | Free(a); | ||
332 | } | ||
333 | |||
334 | struct hostent *BIO_gethostbyname(const char *name) | ||
335 | { | ||
336 | struct hostent *ret; | ||
337 | int i,lowi=0,j; | ||
338 | unsigned long low= (unsigned long)-1; | ||
339 | |||
340 | /* return(gethostbyname(name)); */ | ||
341 | |||
342 | #if 0 /* It doesn't make sense to use locking here: The function interface | ||
343 | * is not thread-safe, because threads can never be sure when | ||
344 | * some other thread destroys the data they were given a pointer to. | ||
345 | */ | ||
346 | CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); | ||
347 | #endif | ||
348 | j=strlen(name); | ||
349 | if (j < 128) | ||
350 | { | ||
351 | for (i=0; i<GHBN_NUM; i++) | ||
352 | { | ||
353 | if (low > ghbn_cache[i].order) | ||
354 | { | ||
355 | low=ghbn_cache[i].order; | ||
356 | lowi=i; | ||
357 | } | ||
358 | if (ghbn_cache[i].order > 0) | ||
359 | { | ||
360 | if (strncmp(name,ghbn_cache[i].name,128) == 0) | ||
361 | break; | ||
362 | } | ||
363 | } | ||
364 | } | ||
365 | else | ||
366 | i=GHBN_NUM; | ||
367 | |||
368 | if (i == GHBN_NUM) /* no hit*/ | ||
369 | { | ||
370 | BIO_ghbn_miss++; | ||
371 | ret=gethostbyname(name); | ||
372 | |||
373 | if (ret == NULL) | ||
374 | goto end; | ||
375 | if (j > 128) /* too big to cache */ | ||
376 | { | ||
377 | #if 0 /* If we were trying to make this function thread-safe (which | ||
378 | * is bound to fail), we'd have to give up in this case | ||
379 | * (or allocate more memory). */ | ||
380 | ret = NULL; | ||
381 | #endif | ||
382 | goto end; | ||
383 | } | ||
384 | |||
385 | /* else add to cache */ | ||
386 | if (ghbn_cache[lowi].ent != NULL) | ||
387 | ghbn_free(ghbn_cache[lowi].ent); /* XXX not thread-safe */ | ||
388 | ghbn_cache[lowi].name[0] = '\0'; | ||
389 | |||
390 | if((ret=ghbn_cache[lowi].ent=ghbn_dup(ret)) == NULL) | ||
391 | { | ||
392 | BIOerr(BIO_F_BIO_GETHOSTBYNAME,ERR_R_MALLOC_FAILURE); | ||
393 | goto end; | ||
394 | } | ||
395 | strncpy(ghbn_cache[lowi].name,name,128); | ||
396 | ghbn_cache[lowi].order=BIO_ghbn_miss+BIO_ghbn_hits; | ||
397 | } | ||
398 | else | ||
399 | { | ||
400 | BIO_ghbn_hits++; | ||
401 | ret= ghbn_cache[i].ent; | ||
402 | ghbn_cache[i].order=BIO_ghbn_miss+BIO_ghbn_hits; | ||
403 | } | ||
404 | end: | ||
405 | #if 0 | ||
406 | CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); | ||
407 | #endif | ||
408 | return(ret); | ||
409 | } | ||
410 | |||
411 | int BIO_sock_init(void) | ||
412 | { | ||
413 | #ifdef WINDOWS | ||
414 | static struct WSAData wsa_state; | ||
415 | |||
416 | if (!wsa_init_done) | ||
417 | { | ||
418 | int err; | ||
419 | |||
420 | #ifdef SIGINT | ||
421 | signal(SIGINT,(void (*)(int))BIO_sock_cleanup); | ||
422 | #endif | ||
423 | wsa_init_done=1; | ||
424 | memset(&wsa_state,0,sizeof(wsa_state)); | ||
425 | if (WSAStartup(0x0101,&wsa_state)!=0) | ||
426 | { | ||
427 | err=WSAGetLastError(); | ||
428 | SYSerr(SYS_F_WSASTARTUP,err); | ||
429 | BIOerr(BIO_F_BIO_SOCK_INIT,BIO_R_WSASTARTUP); | ||
430 | return(-1); | ||
431 | } | ||
432 | } | ||
433 | #endif /* WINDOWS */ | ||
434 | return(1); | ||
435 | } | ||
436 | |||
437 | void BIO_sock_cleanup(void) | ||
438 | { | ||
439 | #ifdef WINDOWS | ||
440 | if (wsa_init_done) | ||
441 | { | ||
442 | wsa_init_done=0; | ||
443 | WSACancelBlockingCall(); | ||
444 | WSACleanup(); | ||
445 | } | ||
446 | #endif | ||
447 | } | ||
448 | |||
449 | #if !defined(VMS) || __VMS_VER >= 70000000 | ||
450 | |||
451 | int BIO_socket_ioctl(int fd, long type, unsigned long *arg) | ||
452 | { | ||
453 | int i; | ||
454 | |||
455 | i=ioctlsocket(fd,type,arg); | ||
456 | if (i < 0) | ||
457 | SYSerr(SYS_F_IOCTLSOCKET,get_last_socket_error()); | ||
458 | return(i); | ||
459 | } | ||
460 | #endif /* __VMS_VER */ | ||
461 | |||
462 | /* The reason I have implemented this instead of using sscanf is because | ||
463 | * Visual C 1.52c gives an unresolved external when linking a DLL :-( */ | ||
464 | static int get_ip(const char *str, unsigned char ip[4]) | ||
465 | { | ||
466 | unsigned int tmp[4]; | ||
467 | int num=0,c,ok=0; | ||
468 | |||
469 | tmp[0]=tmp[1]=tmp[2]=tmp[3]=0; | ||
470 | |||
471 | for (;;) | ||
472 | { | ||
473 | c= *(str++); | ||
474 | if ((c >= '0') && (c <= '9')) | ||
475 | { | ||
476 | ok=1; | ||
477 | tmp[num]=tmp[num]*10+c-'0'; | ||
478 | if (tmp[num] > 255) return(-1); | ||
479 | } | ||
480 | else if (c == '.') | ||
481 | { | ||
482 | if (!ok) return(-1); | ||
483 | if (num == 3) break; | ||
484 | num++; | ||
485 | ok=0; | ||
486 | } | ||
487 | else if ((num == 3) && ok) | ||
488 | break; | ||
489 | else | ||
490 | return(0); | ||
491 | } | ||
492 | ip[0]=tmp[0]; | ||
493 | ip[1]=tmp[1]; | ||
494 | ip[2]=tmp[2]; | ||
495 | ip[3]=tmp[3]; | ||
496 | return(1); | ||
497 | } | ||
498 | |||
499 | int BIO_get_accept_socket(char *host, int bind_mode) | ||
500 | { | ||
501 | int ret=0; | ||
502 | struct sockaddr_in server,client; | ||
503 | int s= -1,cs; | ||
504 | unsigned char ip[4]; | ||
505 | unsigned short port; | ||
506 | char *str,*e; | ||
507 | const char *h,*p; | ||
508 | unsigned long l; | ||
509 | int err_num; | ||
510 | |||
511 | if (!BIO_sock_init()) return(INVALID_SOCKET); | ||
512 | |||
513 | if ((str=BUF_strdup(host)) == NULL) return(INVALID_SOCKET); | ||
514 | |||
515 | h=p=NULL; | ||
516 | h=str; | ||
517 | for (e=str; *e; e++) | ||
518 | { | ||
519 | if (*e == ':') | ||
520 | { | ||
521 | p= &(e[1]); | ||
522 | *e='\0'; | ||
523 | } | ||
524 | else if (*e == '/') | ||
525 | { | ||
526 | *e='\0'; | ||
527 | break; | ||
528 | } | ||
529 | } | ||
530 | |||
531 | if (p == NULL) | ||
532 | { | ||
533 | p=h; | ||
534 | h="*"; | ||
535 | } | ||
536 | |||
537 | if (!BIO_get_port(p,&port)) return(INVALID_SOCKET); | ||
538 | |||
539 | memset((char *)&server,0,sizeof(server)); | ||
540 | server.sin_family=AF_INET; | ||
541 | server.sin_port=htons(port); | ||
542 | |||
543 | if (strcmp(h,"*") == 0) | ||
544 | server.sin_addr.s_addr=INADDR_ANY; | ||
545 | else | ||
546 | { | ||
547 | if (!BIO_get_host_ip(h,&(ip[0]))) return(INVALID_SOCKET); | ||
548 | l=(unsigned long) | ||
549 | ((unsigned long)ip[0]<<24L)| | ||
550 | ((unsigned long)ip[1]<<16L)| | ||
551 | ((unsigned long)ip[2]<< 8L)| | ||
552 | ((unsigned long)ip[3]); | ||
553 | server.sin_addr.s_addr=htonl(l); | ||
554 | } | ||
555 | |||
556 | again: | ||
557 | s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); | ||
558 | if (s == INVALID_SOCKET) | ||
559 | { | ||
560 | SYSerr(SYS_F_SOCKET,get_last_socket_error()); | ||
561 | ERR_add_error_data(3,"port='",host,"'"); | ||
562 | BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_CREATE_SOCKET); | ||
563 | goto err; | ||
564 | } | ||
565 | |||
566 | #ifdef SO_REUSEADDR | ||
567 | if (bind_mode == BIO_BIND_REUSEADDR) | ||
568 | { | ||
569 | int i=1; | ||
570 | |||
571 | ret=setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&i,sizeof(i)); | ||
572 | bind_mode=BIO_BIND_NORMAL; | ||
573 | } | ||
574 | #endif | ||
575 | if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1) | ||
576 | { | ||
577 | #ifdef SO_REUSEADDR | ||
578 | err_num=get_last_socket_error(); | ||
579 | if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) && | ||
580 | (err_num == EADDRINUSE)) | ||
581 | { | ||
582 | memcpy((char *)&client,(char *)&server,sizeof(server)); | ||
583 | if (strcmp(h,"*") == 0) | ||
584 | client.sin_addr.s_addr=htonl(0x7F000001); | ||
585 | cs=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); | ||
586 | if (cs != INVALID_SOCKET) | ||
587 | { | ||
588 | int ii; | ||
589 | ii=connect(cs,(struct sockaddr *)&client, | ||
590 | sizeof(client)); | ||
591 | closesocket(cs); | ||
592 | if (ii == INVALID_SOCKET) | ||
593 | { | ||
594 | bind_mode=BIO_BIND_REUSEADDR; | ||
595 | closesocket(s); | ||
596 | goto again; | ||
597 | } | ||
598 | /* else error */ | ||
599 | } | ||
600 | /* else error */ | ||
601 | } | ||
602 | #endif | ||
603 | SYSerr(SYS_F_BIND,err_num); | ||
604 | ERR_add_error_data(3,"port='",host,"'"); | ||
605 | BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_BIND_SOCKET); | ||
606 | goto err; | ||
607 | } | ||
608 | if (listen(s,MAX_LISTEN) == -1) | ||
609 | { | ||
610 | SYSerr(SYS_F_BIND,get_last_socket_error()); | ||
611 | ERR_add_error_data(3,"port='",host,"'"); | ||
612 | BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_LISTEN_SOCKET); | ||
613 | goto err; | ||
614 | } | ||
615 | ret=1; | ||
616 | err: | ||
617 | if (str != NULL) Free(str); | ||
618 | if ((ret == 0) && (s != INVALID_SOCKET)) | ||
619 | { | ||
620 | closesocket(s); | ||
621 | s= INVALID_SOCKET; | ||
622 | } | ||
623 | return(s); | ||
624 | } | ||
625 | |||
626 | int BIO_accept(int sock, char **addr) | ||
627 | { | ||
628 | int ret=INVALID_SOCKET; | ||
629 | static struct sockaddr_in from; | ||
630 | unsigned long l; | ||
631 | unsigned short port; | ||
632 | int len; | ||
633 | char *p; | ||
634 | |||
635 | memset((char *)&from,0,sizeof(from)); | ||
636 | len=sizeof(from); | ||
637 | /* Note: under VMS with SOCKETSHR the fourth parameter is currently | ||
638 | * of type (int *) whereas under other systems it is (void *) if | ||
639 | * you don't have a cast it will choke the compiler: if you do | ||
640 | * have a cast then you can either go for (int *) or (void *). | ||
641 | */ | ||
642 | ret=accept(sock,(struct sockaddr *)&from,(void *)&len); | ||
643 | if (ret == INVALID_SOCKET) | ||
644 | { | ||
645 | SYSerr(SYS_F_ACCEPT,get_last_socket_error()); | ||
646 | BIOerr(BIO_F_BIO_ACCEPT,BIO_R_ACCEPT_ERROR); | ||
647 | goto end; | ||
648 | } | ||
649 | |||
650 | if (addr == NULL) goto end; | ||
651 | |||
652 | l=ntohl(from.sin_addr.s_addr); | ||
653 | port=ntohs(from.sin_port); | ||
654 | if (*addr == NULL) | ||
655 | { | ||
656 | if ((p=Malloc(24)) == NULL) | ||
657 | { | ||
658 | BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE); | ||
659 | goto end; | ||
660 | } | ||
661 | *addr=p; | ||
662 | } | ||
663 | sprintf(*addr,"%d.%d.%d.%d:%d", | ||
664 | (unsigned char)(l>>24L)&0xff, | ||
665 | (unsigned char)(l>>16L)&0xff, | ||
666 | (unsigned char)(l>> 8L)&0xff, | ||
667 | (unsigned char)(l )&0xff, | ||
668 | port); | ||
669 | end: | ||
670 | return(ret); | ||
671 | } | ||
672 | |||
673 | int BIO_set_tcp_ndelay(int s, int on) | ||
674 | { | ||
675 | int ret=0; | ||
676 | #if defined(TCP_NODELAY) && (defined(IPPROTO_TCP) || defined(SOL_TCP)) | ||
677 | int opt; | ||
678 | |||
679 | #ifdef SOL_TCP | ||
680 | opt=SOL_TCP; | ||
681 | #else | ||
682 | #ifdef IPPROTO_TCP | ||
683 | opt=IPPROTO_TCP; | ||
684 | #endif | ||
685 | #endif | ||
686 | |||
687 | ret=setsockopt(s,opt,TCP_NODELAY,(char *)&on,sizeof(on)); | ||
688 | #endif | ||
689 | return(ret == 0); | ||
690 | } | ||
691 | #endif | ||
692 | |||
693 | int BIO_socket_nbio(int s, int mode) | ||
694 | { | ||
695 | int ret= -1; | ||
696 | unsigned long l; | ||
697 | |||
698 | l=mode; | ||
699 | #ifdef FIONBIO | ||
700 | ret=BIO_socket_ioctl(s,FIONBIO,&l); | ||
701 | #endif | ||
702 | return(ret == 0); | ||
703 | } | ||
diff --git a/src/lib/libcrypto/bio/bf_buff.c b/src/lib/libcrypto/bio/bf_buff.c deleted file mode 100644 index acd8148138..0000000000 --- a/src/lib/libcrypto/bio/bf_buff.c +++ /dev/null | |||
@@ -1,485 +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,char *buf,int num); | ||
66 | static int buffer_read(BIO *h,char *buf,int size); | ||
67 | static int buffer_puts(BIO *h,char *str); | ||
68 | static int buffer_gets(BIO *h,char *str,int size); | ||
69 | static long buffer_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
70 | static int buffer_new(BIO *h); | ||
71 | static int buffer_free(BIO *data); | ||
72 | #define DEFAULT_BUFFER_SIZE 1024 | ||
73 | |||
74 | static BIO_METHOD methods_buffer= | ||
75 | { | ||
76 | BIO_TYPE_BUFFER, | ||
77 | "buffer", | ||
78 | buffer_write, | ||
79 | buffer_read, | ||
80 | buffer_puts, | ||
81 | buffer_gets, | ||
82 | buffer_ctrl, | ||
83 | buffer_new, | ||
84 | buffer_free, | ||
85 | }; | ||
86 | |||
87 | BIO_METHOD *BIO_f_buffer(void) | ||
88 | { | ||
89 | return(&methods_buffer); | ||
90 | } | ||
91 | |||
92 | static int buffer_new(BIO *bi) | ||
93 | { | ||
94 | BIO_F_BUFFER_CTX *ctx; | ||
95 | |||
96 | ctx=(BIO_F_BUFFER_CTX *)Malloc(sizeof(BIO_F_BUFFER_CTX)); | ||
97 | if (ctx == NULL) return(0); | ||
98 | ctx->ibuf=(char *)Malloc(DEFAULT_BUFFER_SIZE); | ||
99 | if (ctx->ibuf == NULL) { Free(ctx); return(0); } | ||
100 | ctx->obuf=(char *)Malloc(DEFAULT_BUFFER_SIZE); | ||
101 | if (ctx->obuf == NULL) { Free(ctx->ibuf); Free(ctx); return(0); } | ||
102 | ctx->ibuf_size=DEFAULT_BUFFER_SIZE; | ||
103 | ctx->obuf_size=DEFAULT_BUFFER_SIZE; | ||
104 | ctx->ibuf_len=0; | ||
105 | ctx->ibuf_off=0; | ||
106 | ctx->obuf_len=0; | ||
107 | ctx->obuf_off=0; | ||
108 | |||
109 | bi->init=1; | ||
110 | bi->ptr=(char *)ctx; | ||
111 | bi->flags=0; | ||
112 | return(1); | ||
113 | } | ||
114 | |||
115 | static int buffer_free(BIO *a) | ||
116 | { | ||
117 | BIO_F_BUFFER_CTX *b; | ||
118 | |||
119 | if (a == NULL) return(0); | ||
120 | b=(BIO_F_BUFFER_CTX *)a->ptr; | ||
121 | if (b->ibuf != NULL) Free(b->ibuf); | ||
122 | if (b->obuf != NULL) Free(b->obuf); | ||
123 | Free(a->ptr); | ||
124 | a->ptr=NULL; | ||
125 | a->init=0; | ||
126 | a->flags=0; | ||
127 | return(1); | ||
128 | } | ||
129 | |||
130 | static int buffer_read(BIO *b, char *out, int outl) | ||
131 | { | ||
132 | int i,num=0; | ||
133 | BIO_F_BUFFER_CTX *ctx; | ||
134 | |||
135 | if (out == NULL) return(0); | ||
136 | ctx=(BIO_F_BUFFER_CTX *)b->ptr; | ||
137 | |||
138 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | ||
139 | num=0; | ||
140 | BIO_clear_retry_flags(b); | ||
141 | |||
142 | start: | ||
143 | i=ctx->ibuf_len; | ||
144 | /* If there is stuff left over, grab it */ | ||
145 | if (i != 0) | ||
146 | { | ||
147 | if (i > outl) i=outl; | ||
148 | memcpy(out,&(ctx->ibuf[ctx->ibuf_off]),i); | ||
149 | ctx->ibuf_off+=i; | ||
150 | ctx->ibuf_len-=i; | ||
151 | num+=i; | ||
152 | if (outl == i) return(num); | ||
153 | outl-=i; | ||
154 | out+=i; | ||
155 | } | ||
156 | |||
157 | /* We may have done a partial read. try to do more. | ||
158 | * We have nothing in the buffer. | ||
159 | * If we get an error and have read some data, just return it | ||
160 | * and let them retry to get the error again. | ||
161 | * copy direct to parent address space */ | ||
162 | if (outl > ctx->ibuf_size) | ||
163 | { | ||
164 | for (;;) | ||
165 | { | ||
166 | i=BIO_read(b->next_bio,out,outl); | ||
167 | if (i <= 0) | ||
168 | { | ||
169 | BIO_copy_next_retry(b); | ||
170 | if (i < 0) return((num > 0)?num:i); | ||
171 | if (i == 0) return(num); | ||
172 | } | ||
173 | num+=i; | ||
174 | if (outl == i) return(num); | ||
175 | out+=i; | ||
176 | outl-=i; | ||
177 | } | ||
178 | } | ||
179 | /* else */ | ||
180 | |||
181 | /* we are going to be doing some buffering */ | ||
182 | i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size); | ||
183 | if (i <= 0) | ||
184 | { | ||
185 | BIO_copy_next_retry(b); | ||
186 | if (i < 0) return((num > 0)?num:i); | ||
187 | if (i == 0) return(num); | ||
188 | } | ||
189 | ctx->ibuf_off=0; | ||
190 | ctx->ibuf_len=i; | ||
191 | |||
192 | /* Lets re-read using ourselves :-) */ | ||
193 | goto start; | ||
194 | } | ||
195 | |||
196 | static int buffer_write(BIO *b, char *in, int inl) | ||
197 | { | ||
198 | int i,num=0; | ||
199 | BIO_F_BUFFER_CTX *ctx; | ||
200 | |||
201 | if ((in == NULL) || (inl <= 0)) return(0); | ||
202 | ctx=(BIO_F_BUFFER_CTX *)b->ptr; | ||
203 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | ||
204 | |||
205 | BIO_clear_retry_flags(b); | ||
206 | start: | ||
207 | i=ctx->obuf_size-(ctx->obuf_len+ctx->obuf_off); | ||
208 | /* add to buffer and return */ | ||
209 | if (i >= inl) | ||
210 | { | ||
211 | memcpy(&(ctx->obuf[ctx->obuf_len]),in,inl); | ||
212 | ctx->obuf_len+=inl; | ||
213 | return(num+inl); | ||
214 | } | ||
215 | /* else */ | ||
216 | /* stuff already in buffer, so add to it first, then flush */ | ||
217 | if (ctx->obuf_len != 0) | ||
218 | { | ||
219 | if (i > 0) /* lets fill it up if we can */ | ||
220 | { | ||
221 | memcpy(&(ctx->obuf[ctx->obuf_len]),in,i); | ||
222 | in+=i; | ||
223 | inl-=i; | ||
224 | num+=i; | ||
225 | ctx->obuf_len+=i; | ||
226 | } | ||
227 | /* we now have a full buffer needing flushing */ | ||
228 | for (;;) | ||
229 | { | ||
230 | i=BIO_write(b->next_bio,&(ctx->obuf[ctx->obuf_off]), | ||
231 | ctx->obuf_len); | ||
232 | if (i <= 0) | ||
233 | { | ||
234 | BIO_copy_next_retry(b); | ||
235 | |||
236 | if (i < 0) return((num > 0)?num:i); | ||
237 | if (i == 0) return(num); | ||
238 | } | ||
239 | ctx->obuf_off+=i; | ||
240 | ctx->obuf_len-=i; | ||
241 | if (ctx->obuf_len == 0) break; | ||
242 | } | ||
243 | } | ||
244 | /* we only get here if the buffer has been flushed and we | ||
245 | * still have stuff to write */ | ||
246 | ctx->obuf_off=0; | ||
247 | |||
248 | /* we now have inl bytes to write */ | ||
249 | while (inl >= ctx->obuf_size) | ||
250 | { | ||
251 | i=BIO_write(b->next_bio,in,inl); | ||
252 | if (i <= 0) | ||
253 | { | ||
254 | BIO_copy_next_retry(b); | ||
255 | if (i < 0) return((num > 0)?num:i); | ||
256 | if (i == 0) return(num); | ||
257 | } | ||
258 | num+=i; | ||
259 | in+=i; | ||
260 | inl-=i; | ||
261 | if (inl == 0) return(num); | ||
262 | } | ||
263 | |||
264 | /* copy the rest into the buffer since we have only a small | ||
265 | * amount left */ | ||
266 | goto start; | ||
267 | } | ||
268 | |||
269 | static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr) | ||
270 | { | ||
271 | BIO *dbio; | ||
272 | BIO_F_BUFFER_CTX *ctx; | ||
273 | long ret=1; | ||
274 | char *p1,*p2; | ||
275 | int r,i,*ip; | ||
276 | int ibs,obs; | ||
277 | |||
278 | ctx=(BIO_F_BUFFER_CTX *)b->ptr; | ||
279 | |||
280 | switch (cmd) | ||
281 | { | ||
282 | case BIO_CTRL_RESET: | ||
283 | ctx->ibuf_off=0; | ||
284 | ctx->ibuf_len=0; | ||
285 | ctx->obuf_off=0; | ||
286 | ctx->obuf_len=0; | ||
287 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
288 | break; | ||
289 | case BIO_CTRL_INFO: | ||
290 | ret=(long)ctx->obuf_len; | ||
291 | break; | ||
292 | case BIO_C_GET_BUFF_NUM_LINES: | ||
293 | ret=0; | ||
294 | p1=ctx->ibuf; | ||
295 | for (i=ctx->ibuf_off; i<ctx->ibuf_len; i++) | ||
296 | { | ||
297 | if (p1[i] == '\n') ret++; | ||
298 | } | ||
299 | break; | ||
300 | case BIO_CTRL_WPENDING: | ||
301 | ret=(long)ctx->obuf_len; | ||
302 | if (ret == 0) | ||
303 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
304 | break; | ||
305 | case BIO_CTRL_PENDING: | ||
306 | ret=(long)ctx->ibuf_len; | ||
307 | if (ret == 0) | ||
308 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
309 | break; | ||
310 | case BIO_C_SET_BUFF_READ_DATA: | ||
311 | if (num > ctx->ibuf_size) | ||
312 | { | ||
313 | p1=Malloc((int)num); | ||
314 | if (p1 == NULL) goto malloc_error; | ||
315 | if (ctx->ibuf != NULL) Free(ctx->ibuf); | ||
316 | ctx->ibuf=p1; | ||
317 | } | ||
318 | ctx->ibuf_off=0; | ||
319 | ctx->ibuf_len=(int)num; | ||
320 | memcpy(ctx->ibuf,ptr,(int)num); | ||
321 | ret=1; | ||
322 | break; | ||
323 | case BIO_C_SET_BUFF_SIZE: | ||
324 | if (ptr != NULL) | ||
325 | { | ||
326 | ip=(int *)ptr; | ||
327 | if (*ip == 0) | ||
328 | { | ||
329 | ibs=(int)num; | ||
330 | obs=ctx->obuf_size; | ||
331 | } | ||
332 | else /* if (*ip == 1) */ | ||
333 | { | ||
334 | ibs=ctx->ibuf_size; | ||
335 | obs=(int)num; | ||
336 | } | ||
337 | } | ||
338 | else | ||
339 | { | ||
340 | ibs=(int)num; | ||
341 | obs=(int)num; | ||
342 | } | ||
343 | p1=ctx->ibuf; | ||
344 | p2=ctx->obuf; | ||
345 | if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size)) | ||
346 | { | ||
347 | p1=(char *)Malloc((int)num); | ||
348 | if (p1 == NULL) goto malloc_error; | ||
349 | } | ||
350 | if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size)) | ||
351 | { | ||
352 | p2=(char *)Malloc((int)num); | ||
353 | if (p2 == NULL) | ||
354 | { | ||
355 | if (p1 != ctx->ibuf) Free(p1); | ||
356 | goto malloc_error; | ||
357 | } | ||
358 | } | ||
359 | if (ctx->ibuf != p1) | ||
360 | { | ||
361 | Free(ctx->ibuf); | ||
362 | ctx->ibuf=p1; | ||
363 | ctx->ibuf_off=0; | ||
364 | ctx->ibuf_len=0; | ||
365 | ctx->ibuf_size=ibs; | ||
366 | } | ||
367 | if (ctx->obuf != p2) | ||
368 | { | ||
369 | Free(ctx->obuf); | ||
370 | ctx->obuf=p2; | ||
371 | ctx->obuf_off=0; | ||
372 | ctx->obuf_len=0; | ||
373 | ctx->obuf_size=obs; | ||
374 | } | ||
375 | break; | ||
376 | case BIO_C_DO_STATE_MACHINE: | ||
377 | BIO_clear_retry_flags(b); | ||
378 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
379 | BIO_copy_next_retry(b); | ||
380 | break; | ||
381 | |||
382 | case BIO_CTRL_FLUSH: | ||
383 | if (ctx->obuf_len <= 0) | ||
384 | { | ||
385 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
386 | break; | ||
387 | } | ||
388 | |||
389 | for (;;) | ||
390 | { | ||
391 | BIO_clear_retry_flags(b); | ||
392 | if (ctx->obuf_len > ctx->obuf_off) | ||
393 | { | ||
394 | r=BIO_write(b->next_bio, | ||
395 | &(ctx->obuf[ctx->obuf_off]), | ||
396 | ctx->obuf_len-ctx->obuf_off); | ||
397 | #if 0 | ||
398 | fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len-ctx->obuf_off,r); | ||
399 | #endif | ||
400 | BIO_copy_next_retry(b); | ||
401 | if (r <= 0) return((long)r); | ||
402 | ctx->obuf_off+=r; | ||
403 | } | ||
404 | else | ||
405 | { | ||
406 | ctx->obuf_len=0; | ||
407 | ctx->obuf_off=0; | ||
408 | ret=1; | ||
409 | break; | ||
410 | } | ||
411 | } | ||
412 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
413 | break; | ||
414 | case BIO_CTRL_DUP: | ||
415 | dbio=(BIO *)ptr; | ||
416 | if ( !BIO_set_read_buffer_size(dbio,ctx->ibuf_size) || | ||
417 | !BIO_set_write_buffer_size(dbio,ctx->obuf_size)) | ||
418 | ret=0; | ||
419 | break; | ||
420 | default: | ||
421 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
422 | break; | ||
423 | } | ||
424 | return(ret); | ||
425 | malloc_error: | ||
426 | BIOerr(BIO_F_BUFFER_CTRL,ERR_R_MALLOC_FAILURE); | ||
427 | return(0); | ||
428 | } | ||
429 | |||
430 | static int buffer_gets(BIO *b, char *buf, int size) | ||
431 | { | ||
432 | BIO_F_BUFFER_CTX *ctx; | ||
433 | int num=0,i,flag; | ||
434 | char *p; | ||
435 | |||
436 | ctx=(BIO_F_BUFFER_CTX *)b->ptr; | ||
437 | size--; /* reserve space for a '\0' */ | ||
438 | BIO_clear_retry_flags(b); | ||
439 | |||
440 | for (;;) | ||
441 | { | ||
442 | if (ctx->ibuf_len > 0) | ||
443 | { | ||
444 | p= &(ctx->ibuf[ctx->ibuf_off]); | ||
445 | flag=0; | ||
446 | for (i=0; (i<ctx->ibuf_len) && (i<size); i++) | ||
447 | { | ||
448 | *(buf++)=p[i]; | ||
449 | if (p[i] == '\n') | ||
450 | { | ||
451 | flag=1; | ||
452 | i++; | ||
453 | break; | ||
454 | } | ||
455 | } | ||
456 | num+=i; | ||
457 | size-=i; | ||
458 | ctx->ibuf_len-=i; | ||
459 | ctx->ibuf_off+=i; | ||
460 | if ((flag) || (i == size)) | ||
461 | { | ||
462 | *buf='\0'; | ||
463 | return(num); | ||
464 | } | ||
465 | } | ||
466 | else /* read another chunk */ | ||
467 | { | ||
468 | i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size); | ||
469 | if (i <= 0) | ||
470 | { | ||
471 | BIO_copy_next_retry(b); | ||
472 | if (i < 0) return((num > 0)?num:i); | ||
473 | if (i == 0) return(num); | ||
474 | } | ||
475 | ctx->ibuf_len=i; | ||
476 | ctx->ibuf_off=0; | ||
477 | } | ||
478 | } | ||
479 | } | ||
480 | |||
481 | static int buffer_puts(BIO *b, char *str) | ||
482 | { | ||
483 | return(BIO_write(b,str,strlen(str))); | ||
484 | } | ||
485 | |||
diff --git a/src/lib/libcrypto/bio/bf_nbio.c b/src/lib/libcrypto/bio/bf_nbio.c deleted file mode 100644 index cbec2bae29..0000000000 --- a/src/lib/libcrypto/bio/bf_nbio.c +++ /dev/null | |||
@@ -1,240 +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,char *buf,int num); | ||
70 | static int nbiof_read(BIO *h,char *buf,int size); | ||
71 | static int nbiof_puts(BIO *h,char *str); | ||
72 | static int nbiof_gets(BIO *h,char *str,int size); | ||
73 | static long nbiof_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
74 | static int nbiof_new(BIO *h); | ||
75 | static int nbiof_free(BIO *data); | ||
76 | typedef struct nbio_test_st | ||
77 | { | ||
78 | /* only set if we sent a 'should retry' error */ | ||
79 | int lrn; | ||
80 | int lwn; | ||
81 | } NBIO_TEST; | ||
82 | |||
83 | static BIO_METHOD methods_nbiof= | ||
84 | { | ||
85 | BIO_TYPE_NBIO_TEST, | ||
86 | "non-blocking IO test filter", | ||
87 | nbiof_write, | ||
88 | nbiof_read, | ||
89 | nbiof_puts, | ||
90 | nbiof_gets, | ||
91 | nbiof_ctrl, | ||
92 | nbiof_new, | ||
93 | nbiof_free, | ||
94 | }; | ||
95 | |||
96 | BIO_METHOD *BIO_f_nbio_test(void) | ||
97 | { | ||
98 | return(&methods_nbiof); | ||
99 | } | ||
100 | |||
101 | static int nbiof_new(BIO *bi) | ||
102 | { | ||
103 | NBIO_TEST *nt; | ||
104 | |||
105 | nt=(NBIO_TEST *)Malloc(sizeof(NBIO_TEST)); | ||
106 | nt->lrn= -1; | ||
107 | nt->lwn= -1; | ||
108 | bi->ptr=(char *)nt; | ||
109 | bi->init=1; | ||
110 | bi->flags=0; | ||
111 | return(1); | ||
112 | } | ||
113 | |||
114 | static int nbiof_free(BIO *a) | ||
115 | { | ||
116 | if (a == NULL) return(0); | ||
117 | if (a->ptr != NULL) | ||
118 | Free(a->ptr); | ||
119 | a->ptr=NULL; | ||
120 | a->init=0; | ||
121 | a->flags=0; | ||
122 | return(1); | ||
123 | } | ||
124 | |||
125 | static int nbiof_read(BIO *b, char *out, int outl) | ||
126 | { | ||
127 | NBIO_TEST *nt; | ||
128 | int ret=0; | ||
129 | #if 0 | ||
130 | int num; | ||
131 | unsigned char n; | ||
132 | #endif | ||
133 | |||
134 | if (out == NULL) return(0); | ||
135 | if (b->next_bio == NULL) return(0); | ||
136 | nt=(NBIO_TEST *)b->ptr; | ||
137 | |||
138 | BIO_clear_retry_flags(b); | ||
139 | #if 0 | ||
140 | RAND_bytes(&n,1); | ||
141 | num=(n&0x07); | ||
142 | |||
143 | if (outl > num) outl=num; | ||
144 | |||
145 | if (num == 0) | ||
146 | { | ||
147 | ret= -1; | ||
148 | BIO_set_retry_read(b); | ||
149 | } | ||
150 | else | ||
151 | #endif | ||
152 | { | ||
153 | ret=BIO_read(b->next_bio,out,outl); | ||
154 | if (ret < 0) | ||
155 | BIO_copy_next_retry(b); | ||
156 | } | ||
157 | return(ret); | ||
158 | } | ||
159 | |||
160 | static int nbiof_write(BIO *b, char *in, int inl) | ||
161 | { | ||
162 | NBIO_TEST *nt; | ||
163 | int ret=0; | ||
164 | int num; | ||
165 | unsigned char n; | ||
166 | |||
167 | if ((in == NULL) || (inl <= 0)) return(0); | ||
168 | if (b->next_bio == NULL) return(0); | ||
169 | nt=(NBIO_TEST *)b->ptr; | ||
170 | |||
171 | BIO_clear_retry_flags(b); | ||
172 | |||
173 | #if 1 | ||
174 | if (nt->lwn > 0) | ||
175 | { | ||
176 | num=nt->lwn; | ||
177 | nt->lwn=0; | ||
178 | } | ||
179 | else | ||
180 | { | ||
181 | RAND_bytes(&n,1); | ||
182 | num=(n&7); | ||
183 | } | ||
184 | |||
185 | if (inl > num) inl=num; | ||
186 | |||
187 | if (num == 0) | ||
188 | { | ||
189 | ret= -1; | ||
190 | BIO_set_retry_write(b); | ||
191 | } | ||
192 | else | ||
193 | #endif | ||
194 | { | ||
195 | ret=BIO_write(b->next_bio,in,inl); | ||
196 | if (ret < 0) | ||
197 | { | ||
198 | BIO_copy_next_retry(b); | ||
199 | nt->lwn=inl; | ||
200 | } | ||
201 | } | ||
202 | return(ret); | ||
203 | } | ||
204 | |||
205 | static long nbiof_ctrl(BIO *b, int cmd, long num, char *ptr) | ||
206 | { | ||
207 | long ret; | ||
208 | |||
209 | if (b->next_bio == NULL) return(0); | ||
210 | switch (cmd) | ||
211 | { | ||
212 | case BIO_C_DO_STATE_MACHINE: | ||
213 | BIO_clear_retry_flags(b); | ||
214 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
215 | BIO_copy_next_retry(b); | ||
216 | break; | ||
217 | case BIO_CTRL_DUP: | ||
218 | ret=0L; | ||
219 | break; | ||
220 | default: | ||
221 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
222 | break; | ||
223 | } | ||
224 | return(ret); | ||
225 | } | ||
226 | |||
227 | static int nbiof_gets(BIO *bp, char *buf, int size) | ||
228 | { | ||
229 | if (bp->next_bio == NULL) return(0); | ||
230 | return(BIO_gets(bp->next_bio,buf,size)); | ||
231 | } | ||
232 | |||
233 | |||
234 | static int nbiof_puts(BIO *bp, char *str) | ||
235 | { | ||
236 | if (bp->next_bio == NULL) return(0); | ||
237 | return(BIO_puts(bp->next_bio,str)); | ||
238 | } | ||
239 | |||
240 | |||
diff --git a/src/lib/libcrypto/bio/bf_null.c b/src/lib/libcrypto/bio/bf_null.c deleted file mode 100644 index 3254a55dce..0000000000 --- a/src/lib/libcrypto/bio/bf_null.c +++ /dev/null | |||
@@ -1,168 +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,char *buf,int num); | ||
69 | static int nullf_read(BIO *h,char *buf,int size); | ||
70 | static int nullf_puts(BIO *h,char *str); | ||
71 | static int nullf_gets(BIO *h,char *str,int size); | ||
72 | static long nullf_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
73 | static int nullf_new(BIO *h); | ||
74 | static int nullf_free(BIO *data); | ||
75 | static BIO_METHOD methods_nullf= | ||
76 | { | ||
77 | BIO_TYPE_NULL_FILTER, | ||
78 | "NULL filter", | ||
79 | nullf_write, | ||
80 | nullf_read, | ||
81 | nullf_puts, | ||
82 | nullf_gets, | ||
83 | nullf_ctrl, | ||
84 | nullf_new, | ||
85 | nullf_free, | ||
86 | }; | ||
87 | |||
88 | BIO_METHOD *BIO_f_null(void) | ||
89 | { | ||
90 | return(&methods_nullf); | ||
91 | } | ||
92 | |||
93 | static int nullf_new(BIO *bi) | ||
94 | { | ||
95 | bi->init=1; | ||
96 | bi->ptr=NULL; | ||
97 | bi->flags=0; | ||
98 | return(1); | ||
99 | } | ||
100 | |||
101 | static int nullf_free(BIO *a) | ||
102 | { | ||
103 | if (a == NULL) return(0); | ||
104 | /* a->ptr=NULL; | ||
105 | a->init=0; | ||
106 | a->flags=0;*/ | ||
107 | return(1); | ||
108 | } | ||
109 | |||
110 | static int nullf_read(BIO *b, char *out, int outl) | ||
111 | { | ||
112 | int ret=0; | ||
113 | |||
114 | if (out == NULL) return(0); | ||
115 | if (b->next_bio == NULL) return(0); | ||
116 | ret=BIO_read(b->next_bio,out,outl); | ||
117 | BIO_clear_retry_flags(b); | ||
118 | BIO_copy_next_retry(b); | ||
119 | return(ret); | ||
120 | } | ||
121 | |||
122 | static int nullf_write(BIO *b, char *in, int inl) | ||
123 | { | ||
124 | int ret=0; | ||
125 | |||
126 | if ((in == NULL) || (inl <= 0)) return(0); | ||
127 | if (b->next_bio == NULL) return(0); | ||
128 | ret=BIO_write(b->next_bio,in,inl); | ||
129 | BIO_clear_retry_flags(b); | ||
130 | BIO_copy_next_retry(b); | ||
131 | return(ret); | ||
132 | } | ||
133 | |||
134 | static long nullf_ctrl(BIO *b, int cmd, long num, char *ptr) | ||
135 | { | ||
136 | long ret; | ||
137 | |||
138 | if (b->next_bio == NULL) return(0); | ||
139 | switch(cmd) | ||
140 | { | ||
141 | case BIO_C_DO_STATE_MACHINE: | ||
142 | BIO_clear_retry_flags(b); | ||
143 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
144 | BIO_copy_next_retry(b); | ||
145 | break; | ||
146 | case BIO_CTRL_DUP: | ||
147 | ret=0L; | ||
148 | break; | ||
149 | default: | ||
150 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
151 | } | ||
152 | return(ret); | ||
153 | } | ||
154 | |||
155 | static int nullf_gets(BIO *bp, char *buf, int size) | ||
156 | { | ||
157 | if (bp->next_bio == NULL) return(0); | ||
158 | return(BIO_gets(bp->next_bio,buf,size)); | ||
159 | } | ||
160 | |||
161 | |||
162 | static int nullf_puts(BIO *bp, char *str) | ||
163 | { | ||
164 | if (bp->next_bio == NULL) return(0); | ||
165 | return(BIO_puts(bp->next_bio,str)); | ||
166 | } | ||
167 | |||
168 | |||
diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h deleted file mode 100644 index 54bf622a3b..0000000000 --- a/src/lib/libcrypto/bio/bio.h +++ /dev/null | |||
@@ -1,643 +0,0 @@ | |||
1 | /* crypto/bio/bio.h */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #ifndef HEADER_BIO_H | ||
60 | #define HEADER_BIO_H | ||
61 | |||
62 | #ifdef __cplusplus | ||
63 | extern "C" { | ||
64 | #endif | ||
65 | |||
66 | #include <stdio.h> | ||
67 | #include <stdlib.h> | ||
68 | #include <openssl/crypto.h> | ||
69 | |||
70 | /* These are the 'types' of BIOs */ | ||
71 | #define BIO_TYPE_NONE 0 | ||
72 | #define BIO_TYPE_MEM (1|0x0400) | ||
73 | #define BIO_TYPE_FILE (2|0x0400) | ||
74 | |||
75 | #define BIO_TYPE_FD (4|0x0400|0x0100) | ||
76 | #define BIO_TYPE_SOCKET (5|0x0400|0x0100) | ||
77 | #define BIO_TYPE_NULL (6|0x0400) | ||
78 | #define BIO_TYPE_SSL (7|0x0200) | ||
79 | #define BIO_TYPE_MD (8|0x0200) /* pasive filter */ | ||
80 | #define BIO_TYPE_BUFFER (9|0x0200) /* filter */ | ||
81 | #define BIO_TYPE_CIPHER (10|0x0200) /* filter */ | ||
82 | #define BIO_TYPE_BASE64 (11|0x0200) /* filter */ | ||
83 | #define BIO_TYPE_CONNECT (12|0x0400|0x0100) /* socket - connect */ | ||
84 | #define BIO_TYPE_ACCEPT (13|0x0400|0x0100) /* socket for accept */ | ||
85 | #define BIO_TYPE_PROXY_CLIENT (14|0x0200) /* client proxy BIO */ | ||
86 | #define BIO_TYPE_PROXY_SERVER (15|0x0200) /* server proxy BIO */ | ||
87 | #define BIO_TYPE_NBIO_TEST (16|0x0200) /* server proxy BIO */ | ||
88 | #define BIO_TYPE_NULL_FILTER (17|0x0200) | ||
89 | #define BIO_TYPE_BER (18|0x0200) /* BER -> bin filter */ | ||
90 | #define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */ | ||
91 | |||
92 | #define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */ | ||
93 | #define BIO_TYPE_FILTER 0x0200 | ||
94 | #define BIO_TYPE_SOURCE_SINK 0x0400 | ||
95 | |||
96 | /* BIO_FILENAME_READ|BIO_CLOSE to open or close on free. | ||
97 | * BIO_set_fp(in,stdin,BIO_NOCLOSE); */ | ||
98 | #define BIO_NOCLOSE 0x00 | ||
99 | #define BIO_CLOSE 0x01 | ||
100 | |||
101 | /* These are used in the following macros and are passed to | ||
102 | * BIO_ctrl() */ | ||
103 | #define BIO_CTRL_RESET 1 /* opt - rewind/zero etc */ | ||
104 | #define BIO_CTRL_EOF 2 /* opt - are we at the eof */ | ||
105 | #define BIO_CTRL_INFO 3 /* opt - extra tit-bits */ | ||
106 | #define BIO_CTRL_SET 4 /* man - set the 'IO' type */ | ||
107 | #define BIO_CTRL_GET 5 /* man - get the 'IO' type */ | ||
108 | #define BIO_CTRL_PUSH 6 /* opt - internal, used to signify change */ | ||
109 | #define BIO_CTRL_POP 7 /* opt - internal, used to signify change */ | ||
110 | #define BIO_CTRL_GET_CLOSE 8 /* man - set the 'close' on free */ | ||
111 | #define BIO_CTRL_SET_CLOSE 9 /* man - set the 'close' on free */ | ||
112 | #define BIO_CTRL_PENDING 10 /* opt - is their more data buffered */ | ||
113 | #define BIO_CTRL_FLUSH 11 /* opt - 'flush' buffered output */ | ||
114 | #define BIO_CTRL_DUP 12 /* man - extra stuff for 'duped' BIO */ | ||
115 | #define BIO_CTRL_WPENDING 13 /* opt - number of bytes still to write */ | ||
116 | /* callback is int cb(BIO *bio,state,ret); */ | ||
117 | #define BIO_CTRL_SET_CALLBACK 14 /* opt - set callback function */ | ||
118 | #define BIO_CTRL_GET_CALLBACK 15 /* opt - set callback function */ | ||
119 | |||
120 | #define BIO_CTRL_SET_FILENAME 30 /* BIO_s_file special */ | ||
121 | |||
122 | /* modifiers */ | ||
123 | #define BIO_FP_READ 0x02 | ||
124 | #define BIO_FP_WRITE 0x04 | ||
125 | #define BIO_FP_APPEND 0x08 | ||
126 | #define BIO_FP_TEXT 0x10 | ||
127 | |||
128 | #define BIO_FLAGS_READ 0x01 | ||
129 | #define BIO_FLAGS_WRITE 0x02 | ||
130 | #define BIO_FLAGS_IO_SPECIAL 0x04 | ||
131 | #define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL) | ||
132 | #define BIO_FLAGS_SHOULD_RETRY 0x08 | ||
133 | |||
134 | /* Used in BIO_gethostbyname() */ | ||
135 | #define BIO_GHBN_CTRL_HITS 1 | ||
136 | #define BIO_GHBN_CTRL_MISSES 2 | ||
137 | #define BIO_GHBN_CTRL_CACHE_SIZE 3 | ||
138 | #define BIO_GHBN_CTRL_GET_ENTRY 4 | ||
139 | #define BIO_GHBN_CTRL_FLUSH 5 | ||
140 | |||
141 | /* Mostly used in the SSL BIO */ | ||
142 | /* Not used anymore | ||
143 | * #define BIO_FLAGS_PROTOCOL_DELAYED_READ 0x10 | ||
144 | * #define BIO_FLAGS_PROTOCOL_DELAYED_WRITE 0x20 | ||
145 | * #define BIO_FLAGS_PROTOCOL_STARTUP 0x40 | ||
146 | */ | ||
147 | |||
148 | #define BIO_FLAGS_BASE64_NO_NL 0x100 | ||
149 | |||
150 | #define BIO_set_flags(b,f) ((b)->flags|=(f)) | ||
151 | #define BIO_get_flags(b) ((b)->flags) | ||
152 | #define BIO_set_retry_special(b) \ | ||
153 | ((b)->flags|=(BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY)) | ||
154 | #define BIO_set_retry_read(b) \ | ||
155 | ((b)->flags|=(BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY)) | ||
156 | #define BIO_set_retry_write(b) \ | ||
157 | ((b)->flags|=(BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY)) | ||
158 | |||
159 | /* These are normally used internally in BIOs */ | ||
160 | #define BIO_clear_flags(b,f) ((b)->flags&= ~(f)) | ||
161 | #define BIO_clear_retry_flags(b) \ | ||
162 | ((b)->flags&= ~(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) | ||
163 | #define BIO_get_retry_flags(b) \ | ||
164 | ((b)->flags&(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) | ||
165 | |||
166 | /* These shouldbe used by the application to tell why we should retry */ | ||
167 | #define BIO_should_read(a) ((a)->flags & BIO_FLAGS_READ) | ||
168 | #define BIO_should_write(a) ((a)->flags & BIO_FLAGS_WRITE) | ||
169 | #define BIO_should_io_special(a) ((a)->flags & BIO_FLAGS_IO_SPECIAL) | ||
170 | #define BIO_retry_type(a) ((a)->flags & BIO_FLAGS_RWS) | ||
171 | #define BIO_should_retry(a) ((a)->flags & BIO_FLAGS_SHOULD_RETRY) | ||
172 | |||
173 | /* The next two are used in conjunction with the | ||
174 | * BIO_should_io_special() condition. After this returns true, | ||
175 | * BIO *BIO_get_retry_BIO(BIO *bio, int *reason); will walk the BIO | ||
176 | * stack and return the 'reason' for the special and the offending BIO. | ||
177 | * Given a BIO, BIO_get_retry_reason(bio) will return the code. */ | ||
178 | /* Returned from the SSL bio when the certificate retrieval code had an error */ | ||
179 | #define BIO_RR_SSL_X509_LOOKUP 0x01 | ||
180 | /* Returned from the connect BIO when a connect would have blocked */ | ||
181 | #define BIO_RR_CONNECT 0x02 | ||
182 | |||
183 | /* These are passed by the BIO callback */ | ||
184 | #define BIO_CB_FREE 0x01 | ||
185 | #define BIO_CB_READ 0x02 | ||
186 | #define BIO_CB_WRITE 0x03 | ||
187 | #define BIO_CB_PUTS 0x04 | ||
188 | #define BIO_CB_GETS 0x05 | ||
189 | #define BIO_CB_CTRL 0x06 | ||
190 | |||
191 | /* The callback is called before and after the underling operation, | ||
192 | * The BIO_CB_RETURN flag indicates if it is after the call */ | ||
193 | #define BIO_CB_RETURN 0x80 | ||
194 | #define BIO_CB_return(a) ((a)|BIO_CB_RETURN)) | ||
195 | #define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN)) | ||
196 | #define BIO_cb_post(a) ((a)&BIO_CB_RETURN) | ||
197 | |||
198 | #define BIO_set_callback(b,cb) ((b)->callback=(cb)) | ||
199 | #define BIO_set_callback_arg(b,arg) ((b)->cb_arg=(char *)(arg)) | ||
200 | #define BIO_get_callback_arg(b) ((b)->cb_arg) | ||
201 | #define BIO_get_callback(b) ((b)->callback) | ||
202 | #define BIO_method_name(b) ((b)->method->name) | ||
203 | #define BIO_method_type(b) ((b)->method->type) | ||
204 | |||
205 | #ifndef WIN16 | ||
206 | typedef struct bio_method_st | ||
207 | { | ||
208 | int type; | ||
209 | const char *name; | ||
210 | int (*bwrite)(); | ||
211 | int (*bread)(); | ||
212 | int (*bputs)(); | ||
213 | int (*bgets)(); | ||
214 | long (*ctrl)(); | ||
215 | int (*create)(); | ||
216 | int (*destroy)(); | ||
217 | } BIO_METHOD; | ||
218 | #else | ||
219 | typedef struct bio_method_st | ||
220 | { | ||
221 | int type; | ||
222 | const char *name; | ||
223 | int (_far *bwrite)(); | ||
224 | int (_far *bread)(); | ||
225 | int (_far *bputs)(); | ||
226 | int (_far *bgets)(); | ||
227 | long (_far *ctrl)(); | ||
228 | int (_far *create)(); | ||
229 | int (_far *destroy)(); | ||
230 | } BIO_METHOD; | ||
231 | #endif | ||
232 | |||
233 | typedef struct bio_st | ||
234 | { | ||
235 | BIO_METHOD *method; | ||
236 | /* bio, mode, argp, argi, argl, ret */ | ||
237 | long (*callback)(struct bio_st *,int,const char *,int, long,long); | ||
238 | char *cb_arg; /* first argument for the callback */ | ||
239 | |||
240 | int init; | ||
241 | int shutdown; | ||
242 | int flags; /* extra storage */ | ||
243 | int retry_reason; | ||
244 | int num; | ||
245 | void *ptr; | ||
246 | struct bio_st *next_bio; /* used by filter BIOs */ | ||
247 | struct bio_st *prev_bio; /* used by filter BIOs */ | ||
248 | int references; | ||
249 | unsigned long num_read; | ||
250 | unsigned long num_write; | ||
251 | |||
252 | CRYPTO_EX_DATA ex_data; | ||
253 | } BIO; | ||
254 | |||
255 | typedef struct bio_f_buffer_ctx_struct | ||
256 | { | ||
257 | /* BIO *bio; */ /* this is now in the BIO struct */ | ||
258 | int ibuf_size; /* how big is the input buffer */ | ||
259 | int obuf_size; /* how big is the output buffer */ | ||
260 | |||
261 | char *ibuf; /* the char array */ | ||
262 | int ibuf_len; /* how many bytes are in it */ | ||
263 | int ibuf_off; /* write/read offset */ | ||
264 | |||
265 | char *obuf; /* the char array */ | ||
266 | int obuf_len; /* how many bytes are in it */ | ||
267 | int obuf_off; /* write/read offset */ | ||
268 | } BIO_F_BUFFER_CTX; | ||
269 | |||
270 | /* connect BIO stuff */ | ||
271 | #define BIO_CONN_S_BEFORE 1 | ||
272 | #define BIO_CONN_S_GET_IP 2 | ||
273 | #define BIO_CONN_S_GET_PORT 3 | ||
274 | #define BIO_CONN_S_CREATE_SOCKET 4 | ||
275 | #define BIO_CONN_S_CONNECT 5 | ||
276 | #define BIO_CONN_S_OK 6 | ||
277 | #define BIO_CONN_S_BLOCKED_CONNECT 7 | ||
278 | #define BIO_CONN_S_NBIO 8 | ||
279 | /*#define BIO_CONN_get_param_hostname BIO_ctrl */ | ||
280 | |||
281 | #define BIO_number_read(b) ((b)->num_read) | ||
282 | #define BIO_number_written(b) ((b)->num_write) | ||
283 | |||
284 | #define BIO_C_SET_CONNECT 100 | ||
285 | #define BIO_C_DO_STATE_MACHINE 101 | ||
286 | #define BIO_C_SET_NBIO 102 | ||
287 | #define BIO_C_SET_PROXY_PARAM 103 | ||
288 | #define BIO_C_SET_FD 104 | ||
289 | #define BIO_C_GET_FD 105 | ||
290 | #define BIO_C_SET_FILE_PTR 106 | ||
291 | #define BIO_C_GET_FILE_PTR 107 | ||
292 | #define BIO_C_SET_FILENAME 108 | ||
293 | #define BIO_C_SET_SSL 109 | ||
294 | #define BIO_C_GET_SSL 110 | ||
295 | #define BIO_C_SET_MD 111 | ||
296 | #define BIO_C_GET_MD 112 | ||
297 | #define BIO_C_GET_CIPHER_STATUS 113 | ||
298 | #define BIO_C_SET_BUF_MEM 114 | ||
299 | #define BIO_C_GET_BUF_MEM_PTR 115 | ||
300 | #define BIO_C_GET_BUFF_NUM_LINES 116 | ||
301 | #define BIO_C_SET_BUFF_SIZE 117 | ||
302 | #define BIO_C_SET_ACCEPT 118 | ||
303 | #define BIO_C_SSL_MODE 119 | ||
304 | #define BIO_C_GET_MD_CTX 120 | ||
305 | #define BIO_C_GET_PROXY_PARAM 121 | ||
306 | #define BIO_C_SET_BUFF_READ_DATA 122 /* data to read first */ | ||
307 | #define BIO_C_GET_CONNECT 123 | ||
308 | #define BIO_C_GET_ACCEPT 124 | ||
309 | #define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125 | ||
310 | #define BIO_C_GET_SSL_NUM_RENEGOTIATES 126 | ||
311 | #define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127 | ||
312 | #define BIO_C_FILE_SEEK 128 | ||
313 | #define BIO_C_GET_CIPHER_CTX 129 | ||
314 | #define BIO_C_SET_BUF_MEM_EOF_RETURN 130/*return end of input value*/ | ||
315 | #define BIO_C_SET_BIND_MODE 131 | ||
316 | #define BIO_C_GET_BIND_MODE 132 | ||
317 | #define BIO_C_FILE_TELL 133 | ||
318 | #define BIO_C_GET_SOCKS 134 | ||
319 | #define BIO_C_SET_SOCKS 135 | ||
320 | |||
321 | #define BIO_C_SET_WRITE_BUF_SIZE 136/* for BIO_s_bio */ | ||
322 | #define BIO_C_GET_WRITE_BUF_SIZE 137 | ||
323 | #define BIO_C_MAKE_BIO_PAIR 138 | ||
324 | #define BIO_C_DESTROY_BIO_PAIR 139 | ||
325 | #define BIO_C_GET_WRITE_GUARANTEE 140 | ||
326 | #define BIO_C_GET_READ_REQUEST 141 | ||
327 | #define BIO_C_SHUTDOWN_WR 142 | ||
328 | |||
329 | |||
330 | #define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,(char *)arg) | ||
331 | #define BIO_get_app_data(s) BIO_get_ex_data(s,0) | ||
332 | |||
333 | /* BIO_s_connect() and BIO_s_socks4a_connect() */ | ||
334 | #define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name) | ||
335 | #define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port) | ||
336 | #define BIO_set_conn_ip(b,ip) BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)ip) | ||
337 | #define BIO_set_conn_int_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,3,(char *)port) | ||
338 | #define BIO_get_conn_hostname(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0) | ||
339 | #define BIO_get_conn_port(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1) | ||
340 | #define BIO_get_conn_ip(b,ip) BIO_ptr_ctrl(b,BIO_C_SET_CONNECT,2) | ||
341 | #define BIO_get_conn_int_port(b,port) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,port) | ||
342 | |||
343 | |||
344 | #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) | ||
345 | |||
346 | /* BIO_s_accept_socket() */ | ||
347 | #define BIO_set_accept_port(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0,(char *)name) | ||
348 | #define BIO_get_accept_port(b) BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0) | ||
349 | /* #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */ | ||
350 | #define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?"a":NULL) | ||
351 | #define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio) | ||
352 | |||
353 | #define BIO_BIND_NORMAL 0 | ||
354 | #define BIO_BIND_REUSEADDR_IF_UNUSED 1 | ||
355 | #define BIO_BIND_REUSEADDR 2 | ||
356 | #define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL) | ||
357 | #define BIO_get_bind_mode(b,mode) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL) | ||
358 | |||
359 | #define BIO_do_connect(b) BIO_do_handshake(b) | ||
360 | #define BIO_do_accept(b) BIO_do_handshake(b) | ||
361 | #define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL) | ||
362 | |||
363 | /* BIO_s_proxy_client() */ | ||
364 | #define BIO_set_url(b,url) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,0,(char *)(url)) | ||
365 | #define BIO_set_proxies(b,p) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,1,(char *)(p)) | ||
366 | /* BIO_set_nbio(b,n) */ | ||
367 | #define BIO_set_filter_bio(b,s) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,2,(char *)(s)) | ||
368 | /* BIO *BIO_get_filter_bio(BIO *bio); */ | ||
369 | #define BIO_set_proxy_cb(b,cb) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,3,(char *)(cb)) | ||
370 | #define BIO_set_proxy_header(b,sk) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,4,(char *)sk) | ||
371 | #define BIO_set_no_connect_return(b,bool) BIO_int_ctrl(b,BIO_C_SET_PROXY_PARAM,5,bool) | ||
372 | |||
373 | #define BIO_get_proxy_header(b,skp) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,0,(char *)skp) | ||
374 | #define BIO_get_proxies(b,pxy_p) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,1,(char *)(pxy_p)) | ||
375 | #define BIO_get_url(b,url) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,2,(char *)(url)) | ||
376 | #define BIO_get_no_connect_return(b) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,5,NULL) | ||
377 | |||
378 | #define BIO_set_fd(b,fd,c) BIO_int_ctrl(b,BIO_C_SET_FD,c,fd) | ||
379 | #define BIO_get_fd(b,c) BIO_ctrl(b,BIO_C_GET_FD,0,(char *)c) | ||
380 | |||
381 | #define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp) | ||
382 | #define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp) | ||
383 | |||
384 | #define BIO_seek(b,ofs) (int)BIO_ctrl(b,BIO_C_FILE_SEEK,ofs,NULL) | ||
385 | #define BIO_tell(b) (int)BIO_ctrl(b,BIO_C_FILE_TELL,0,NULL) | ||
386 | |||
387 | /* name is cast to lose const, but might be better to route through a function | ||
388 | so we can do it safely */ | ||
389 | #ifdef CONST_STRICT | ||
390 | /* If you are wondering why this isn't defined, its because CONST_STRICT is | ||
391 | * purely a compile-time kludge to allow const to be checked. | ||
392 | */ | ||
393 | int BIO_read_filename(BIO *b,const char *name); | ||
394 | #else | ||
395 | #define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ | ||
396 | BIO_CLOSE|BIO_FP_READ,(char *)name) | ||
397 | #endif | ||
398 | #define BIO_write_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ | ||
399 | BIO_CLOSE|BIO_FP_WRITE,name) | ||
400 | #define BIO_append_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ | ||
401 | BIO_CLOSE|BIO_FP_APPEND,name) | ||
402 | #define BIO_rw_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ | ||
403 | BIO_CLOSE|BIO_FP_READ|BIO_FP_WRITE,name) | ||
404 | |||
405 | /* WARNING WARNING, this ups the reference count on the read bio of the | ||
406 | * SSL structure. This is because the ssl read BIO is now pointed to by | ||
407 | * the next_bio field in the bio. So when you free the BIO, make sure | ||
408 | * you are doing a BIO_free_all() to catch the underlying BIO. */ | ||
409 | #define BIO_set_ssl(b,ssl,c) BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)ssl) | ||
410 | #define BIO_get_ssl(b,sslp) BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)sslp) | ||
411 | #define BIO_set_ssl_mode(b,client) BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL) | ||
412 | #define BIO_set_ssl_renegotiate_bytes(b,num) \ | ||
413 | BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL); | ||
414 | #define BIO_get_num_renegotiates(b) \ | ||
415 | BIO_ctrl(b,BIO_C_SET_SSL_NUM_RENEGOTIATES,0,NULL); | ||
416 | #define BIO_set_ssl_renegotiate_timeout(b,seconds) \ | ||
417 | BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL); | ||
418 | |||
419 | /* defined in evp.h */ | ||
420 | /* #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,1,(char *)md) */ | ||
421 | |||
422 | #define BIO_get_mem_data(b,pp) BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)pp) | ||
423 | #define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)bm) | ||
424 | #define BIO_get_mem_ptr(b,pp) BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0,(char *)pp) | ||
425 | #define BIO_set_mem_eof_return(b,v) \ | ||
426 | BIO_ctrl(b,BIO_C_SET_BUF_MEM_EOF_RETURN,v,NULL) | ||
427 | |||
428 | /* For the BIO_f_buffer() type */ | ||
429 | #define BIO_get_buffer_num_lines(b) BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL) | ||
430 | #define BIO_set_buffer_size(b,size) BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL) | ||
431 | #define BIO_set_read_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0) | ||
432 | #define BIO_set_write_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1) | ||
433 | #define BIO_set_buffer_read_data(b,buf,num) BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf) | ||
434 | |||
435 | /* Don't use the next one unless you know what you are doing :-) */ | ||
436 | #define BIO_dup_state(b,ret) BIO_ctrl(b,BIO_CTRL_DUP,0,(char *)(ret)) | ||
437 | |||
438 | #define BIO_reset(b) (int)BIO_ctrl(b,BIO_CTRL_RESET,0,NULL) | ||
439 | #define BIO_eof(b) (int)BIO_ctrl(b,BIO_CTRL_EOF,0,NULL) | ||
440 | #define BIO_set_close(b,c) (int)BIO_ctrl(b,BIO_CTRL_SET_CLOSE,(c),NULL) | ||
441 | #define BIO_get_close(b) (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL) | ||
442 | #define BIO_pending(b) (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL) | ||
443 | #define BIO_wpending(b) (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL) | ||
444 | /* ...pending macros have inappropriate return type */ | ||
445 | size_t BIO_ctrl_pending(BIO *b); | ||
446 | size_t BIO_ctrl_wpending(BIO *b); | ||
447 | #define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL) | ||
448 | #define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0,(char *)cbp) | ||
449 | #define BIO_set_info_callback(b,cb) (int)BIO_ctrl(b,BIO_CTRL_SET_CALLBACK,0,(char *)cb) | ||
450 | |||
451 | /* For the BIO_f_buffer() type */ | ||
452 | #define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL) | ||
453 | |||
454 | /* For BIO_s_bio() */ | ||
455 | #define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL) | ||
456 | #define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL) | ||
457 | #define BIO_make_bio_pair(b1,b2) (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2) | ||
458 | #define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL) | ||
459 | /* macros with inappropriate type -- but ...pending macros use int too: */ | ||
460 | #define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL) | ||
461 | #define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL) | ||
462 | size_t BIO_ctrl_get_write_guarantee(BIO *b); | ||
463 | size_t BIO_ctrl_get_read_request(BIO *b); | ||
464 | |||
465 | |||
466 | |||
467 | #ifdef NO_STDIO | ||
468 | #define NO_FP_API | ||
469 | #endif | ||
470 | |||
471 | |||
472 | /* These two aren't currently implemented */ | ||
473 | /* int BIO_get_ex_num(BIO *bio); */ | ||
474 | /* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */ | ||
475 | int BIO_set_ex_data(BIO *bio,int idx,char *data); | ||
476 | char *BIO_get_ex_data(BIO *bio,int idx); | ||
477 | int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), | ||
478 | int (*dup_func)(), void (*free_func)()); | ||
479 | |||
480 | # if defined(WIN16) && defined(_WINDLL) | ||
481 | BIO_METHOD *BIO_s_file_internal(void); | ||
482 | BIO *BIO_new_file_internal(char *filename, char *mode); | ||
483 | BIO *BIO_new_fp_internal(FILE *stream, int close_flag); | ||
484 | # define BIO_s_file BIO_s_file_internal | ||
485 | # define BIO_new_file BIO_new_file_internal | ||
486 | # define BIO_new_fp BIO_new_fp_internal | ||
487 | # else /* FP_API */ | ||
488 | BIO_METHOD *BIO_s_file(void ); | ||
489 | BIO *BIO_new_file(const char *filename, const char *mode); | ||
490 | BIO *BIO_new_fp(FILE *stream, int close_flag); | ||
491 | # define BIO_s_file_internal BIO_s_file | ||
492 | # define BIO_new_file_internal BIO_new_file | ||
493 | # define BIO_new_fp_internal BIO_s_file | ||
494 | # endif /* FP_API */ | ||
495 | BIO * BIO_new(BIO_METHOD *type); | ||
496 | int BIO_set(BIO *a,BIO_METHOD *type); | ||
497 | int BIO_free(BIO *a); | ||
498 | int BIO_read(BIO *b, void *data, int len); | ||
499 | int BIO_gets(BIO *bp,char *buf, int size); | ||
500 | int BIO_write(BIO *b, const char *data, int len); | ||
501 | int BIO_puts(BIO *bp,const char *buf); | ||
502 | long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg); | ||
503 | char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg); | ||
504 | long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg); | ||
505 | BIO * BIO_push(BIO *b,BIO *append); | ||
506 | BIO * BIO_pop(BIO *b); | ||
507 | void BIO_free_all(BIO *a); | ||
508 | BIO * BIO_find_type(BIO *b,int bio_type); | ||
509 | BIO * BIO_get_retry_BIO(BIO *bio, int *reason); | ||
510 | int BIO_get_retry_reason(BIO *bio); | ||
511 | BIO * BIO_dup_chain(BIO *in); | ||
512 | |||
513 | #ifndef WIN16 | ||
514 | long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi, | ||
515 | long argl,long ret); | ||
516 | #else | ||
517 | long _far _loadds BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi, | ||
518 | long argl,long ret); | ||
519 | #endif | ||
520 | |||
521 | BIO_METHOD *BIO_s_mem(void); | ||
522 | BIO_METHOD *BIO_s_socket(void); | ||
523 | BIO_METHOD *BIO_s_connect(void); | ||
524 | BIO_METHOD *BIO_s_accept(void); | ||
525 | BIO_METHOD *BIO_s_fd(void); | ||
526 | BIO_METHOD *BIO_s_log(void); | ||
527 | BIO_METHOD *BIO_s_bio(void); | ||
528 | BIO_METHOD *BIO_s_null(void); | ||
529 | BIO_METHOD *BIO_f_null(void); | ||
530 | BIO_METHOD *BIO_f_buffer(void); | ||
531 | BIO_METHOD *BIO_f_nbio_test(void); | ||
532 | /* BIO_METHOD *BIO_f_ber(void); */ | ||
533 | |||
534 | int BIO_sock_should_retry(int i); | ||
535 | int BIO_sock_non_fatal_error(int error); | ||
536 | int BIO_fd_should_retry(int i); | ||
537 | int BIO_fd_non_fatal_error(int error); | ||
538 | int BIO_dump(BIO *b,const char *bytes,int len); | ||
539 | |||
540 | struct hostent *BIO_gethostbyname(const char *name); | ||
541 | /* We might want a thread-safe interface too: | ||
542 | * struct hostent *BIO_gethostbyname_r(const char *name, | ||
543 | * struct hostent *result, void *buffer, size_t buflen); | ||
544 | * or something similar (caller allocates a struct hostent, | ||
545 | * pointed to by "result", and additional buffer space for the various | ||
546 | * substructures; if the buffer does not suffice, NULL is returned | ||
547 | * and an appropriate error code is set). | ||
548 | */ | ||
549 | int BIO_sock_error(int sock); | ||
550 | int BIO_socket_ioctl(int fd, long type, unsigned long *arg); | ||
551 | int BIO_socket_nbio(int fd,int mode); | ||
552 | int BIO_get_port(const char *str, unsigned short *port_ptr); | ||
553 | int BIO_get_host_ip(const char *str, unsigned char *ip); | ||
554 | int BIO_get_accept_socket(char *host_port,int mode); | ||
555 | int BIO_accept(int sock,char **ip_port); | ||
556 | int BIO_sock_init(void ); | ||
557 | void BIO_sock_cleanup(void); | ||
558 | int BIO_set_tcp_ndelay(int sock,int turn_on); | ||
559 | |||
560 | void ERR_load_BIO_strings(void ); | ||
561 | |||
562 | BIO *BIO_new_socket(int sock, int close_flag); | ||
563 | BIO *BIO_new_fd(int fd, int close_flag); | ||
564 | BIO *BIO_new_connect(char *host_port); | ||
565 | BIO *BIO_new_accept(char *host_port); | ||
566 | |||
567 | int BIO_new_bio_pair(BIO **bio1, size_t writebuf1, | ||
568 | BIO **bio2, size_t writebuf2); | ||
569 | /* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints. | ||
570 | * Otherwise returns 0 and sets *bio1 and *bio2 to NULL. | ||
571 | * Size 0 uses default value. | ||
572 | */ | ||
573 | |||
574 | void BIO_copy_next_retry(BIO *b); | ||
575 | |||
576 | long BIO_ghbn_ctrl(int cmd,int iarg,char *parg); | ||
577 | |||
578 | int BIO_printf(BIO *bio, ...); | ||
579 | |||
580 | /* BEGIN ERROR CODES */ | ||
581 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
582 | * made after this point may be overwritten when the script is next run. | ||
583 | */ | ||
584 | |||
585 | /* Error codes for the BIO functions. */ | ||
586 | |||
587 | /* Function codes. */ | ||
588 | #define BIO_F_ACPT_STATE 100 | ||
589 | #define BIO_F_BIO_ACCEPT 101 | ||
590 | #define BIO_F_BIO_BER_GET_HEADER 102 | ||
591 | #define BIO_F_BIO_CTRL 103 | ||
592 | #define BIO_F_BIO_GETHOSTBYNAME 120 | ||
593 | #define BIO_F_BIO_GETS 104 | ||
594 | #define BIO_F_BIO_GET_ACCEPT_SOCKET 105 | ||
595 | #define BIO_F_BIO_GET_HOST_IP 106 | ||
596 | #define BIO_F_BIO_GET_PORT 107 | ||
597 | #define BIO_F_BIO_MAKE_PAIR 121 | ||
598 | #define BIO_F_BIO_NEW 108 | ||
599 | #define BIO_F_BIO_NEW_FILE 109 | ||
600 | #define BIO_F_BIO_PUTS 110 | ||
601 | #define BIO_F_BIO_READ 111 | ||
602 | #define BIO_F_BIO_SOCK_INIT 112 | ||
603 | #define BIO_F_BIO_WRITE 113 | ||
604 | #define BIO_F_BUFFER_CTRL 114 | ||
605 | #define BIO_F_CONN_STATE 115 | ||
606 | #define BIO_F_FILE_CTRL 116 | ||
607 | #define BIO_F_MEM_WRITE 117 | ||
608 | #define BIO_F_SSL_NEW 118 | ||
609 | #define BIO_F_WSASTARTUP 119 | ||
610 | |||
611 | /* Reason codes. */ | ||
612 | #define BIO_R_ACCEPT_ERROR 100 | ||
613 | #define BIO_R_BAD_FOPEN_MODE 101 | ||
614 | #define BIO_R_BAD_HOSTNAME_LOOKUP 102 | ||
615 | #define BIO_R_BROKEN_PIPE 124 | ||
616 | #define BIO_R_CONNECT_ERROR 103 | ||
617 | #define BIO_R_ERROR_SETTING_NBIO 104 | ||
618 | #define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105 | ||
619 | #define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106 | ||
620 | #define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107 | ||
621 | #define BIO_R_INVALID_ARGUMENT 125 | ||
622 | #define BIO_R_INVALID_IP_ADDRESS 108 | ||
623 | #define BIO_R_IN_USE 123 | ||
624 | #define BIO_R_KEEPALIVE 109 | ||
625 | #define BIO_R_NBIO_CONNECT_ERROR 110 | ||
626 | #define BIO_R_NO_ACCEPT_PORT_SPECIFIED 111 | ||
627 | #define BIO_R_NO_HOSTNAME_SPECIFIED 112 | ||
628 | #define BIO_R_NO_PORT_DEFINED 113 | ||
629 | #define BIO_R_NO_PORT_SPECIFIED 114 | ||
630 | #define BIO_R_NULL_PARAMETER 115 | ||
631 | #define BIO_R_TAG_MISMATCH 116 | ||
632 | #define BIO_R_UNABLE_TO_BIND_SOCKET 117 | ||
633 | #define BIO_R_UNABLE_TO_CREATE_SOCKET 118 | ||
634 | #define BIO_R_UNABLE_TO_LISTEN_SOCKET 119 | ||
635 | #define BIO_R_UNINITIALIZED 120 | ||
636 | #define BIO_R_UNSUPPORTED_METHOD 121 | ||
637 | #define BIO_R_WSASTARTUP 122 | ||
638 | |||
639 | #ifdef __cplusplus | ||
640 | } | ||
641 | #endif | ||
642 | #endif | ||
643 | |||
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 712d98a3a1..0000000000 --- a/src/lib/libcrypto/bio/bio_err.c +++ /dev/null | |||
@@ -1,139 +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 | */ | ||
59 | |||
60 | #include <stdio.h> | ||
61 | #include <openssl/err.h> | ||
62 | #include <openssl/bio.h> | ||
63 | |||
64 | /* BEGIN ERROR CODES */ | ||
65 | #ifndef NO_ERR | ||
66 | static ERR_STRING_DATA BIO_str_functs[]= | ||
67 | { | ||
68 | {ERR_PACK(0,BIO_F_ACPT_STATE,0), "ACPT_STATE"}, | ||
69 | {ERR_PACK(0,BIO_F_BIO_ACCEPT,0), "BIO_accept"}, | ||
70 | {ERR_PACK(0,BIO_F_BIO_BER_GET_HEADER,0), "BIO_BER_GET_HEADER"}, | ||
71 | {ERR_PACK(0,BIO_F_BIO_CTRL,0), "BIO_ctrl"}, | ||
72 | {ERR_PACK(0,BIO_F_BIO_GETHOSTBYNAME,0), "BIO_gethostbyname"}, | ||
73 | {ERR_PACK(0,BIO_F_BIO_GETS,0), "BIO_gets"}, | ||
74 | {ERR_PACK(0,BIO_F_BIO_GET_ACCEPT_SOCKET,0), "BIO_get_accept_socket"}, | ||
75 | {ERR_PACK(0,BIO_F_BIO_GET_HOST_IP,0), "BIO_get_host_ip"}, | ||
76 | {ERR_PACK(0,BIO_F_BIO_GET_PORT,0), "BIO_get_port"}, | ||
77 | {ERR_PACK(0,BIO_F_BIO_MAKE_PAIR,0), "BIO_MAKE_PAIR"}, | ||
78 | {ERR_PACK(0,BIO_F_BIO_NEW,0), "BIO_new"}, | ||
79 | {ERR_PACK(0,BIO_F_BIO_NEW_FILE,0), "BIO_new_file"}, | ||
80 | {ERR_PACK(0,BIO_F_BIO_PUTS,0), "BIO_puts"}, | ||
81 | {ERR_PACK(0,BIO_F_BIO_READ,0), "BIO_read"}, | ||
82 | {ERR_PACK(0,BIO_F_BIO_SOCK_INIT,0), "BIO_sock_init"}, | ||
83 | {ERR_PACK(0,BIO_F_BIO_WRITE,0), "BIO_write"}, | ||
84 | {ERR_PACK(0,BIO_F_BUFFER_CTRL,0), "BUFFER_CTRL"}, | ||
85 | {ERR_PACK(0,BIO_F_CONN_STATE,0), "CONN_STATE"}, | ||
86 | {ERR_PACK(0,BIO_F_FILE_CTRL,0), "FILE_CTRL"}, | ||
87 | {ERR_PACK(0,BIO_F_MEM_WRITE,0), "MEM_WRITE"}, | ||
88 | {ERR_PACK(0,BIO_F_SSL_NEW,0), "SSL_new"}, | ||
89 | {ERR_PACK(0,BIO_F_WSASTARTUP,0), "WSASTARTUP"}, | ||
90 | {0,NULL} | ||
91 | }; | ||
92 | |||
93 | static ERR_STRING_DATA BIO_str_reasons[]= | ||
94 | { | ||
95 | {BIO_R_ACCEPT_ERROR ,"accept error"}, | ||
96 | {BIO_R_BAD_FOPEN_MODE ,"bad fopen mode"}, | ||
97 | {BIO_R_BAD_HOSTNAME_LOOKUP ,"bad hostname lookup"}, | ||
98 | {BIO_R_BROKEN_PIPE ,"broken pipe"}, | ||
99 | {BIO_R_CONNECT_ERROR ,"connect error"}, | ||
100 | {BIO_R_ERROR_SETTING_NBIO ,"error setting nbio"}, | ||
101 | {BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET,"error setting nbio on accepted socket"}, | ||
102 | {BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET,"error setting nbio on accept socket"}, | ||
103 | {BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET ,"gethostbyname addr is not af inet"}, | ||
104 | {BIO_R_INVALID_ARGUMENT ,"invalid argument"}, | ||
105 | {BIO_R_INVALID_IP_ADDRESS ,"invalid ip address"}, | ||
106 | {BIO_R_IN_USE ,"in use"}, | ||
107 | {BIO_R_KEEPALIVE ,"keepalive"}, | ||
108 | {BIO_R_NBIO_CONNECT_ERROR ,"nbio connect error"}, | ||
109 | {BIO_R_NO_ACCEPT_PORT_SPECIFIED ,"no accept port specified"}, | ||
110 | {BIO_R_NO_HOSTNAME_SPECIFIED ,"no hostname specified"}, | ||
111 | {BIO_R_NO_PORT_DEFINED ,"no port defined"}, | ||
112 | {BIO_R_NO_PORT_SPECIFIED ,"no port specified"}, | ||
113 | {BIO_R_NULL_PARAMETER ,"null parameter"}, | ||
114 | {BIO_R_TAG_MISMATCH ,"tag mismatch"}, | ||
115 | {BIO_R_UNABLE_TO_BIND_SOCKET ,"unable to bind socket"}, | ||
116 | {BIO_R_UNABLE_TO_CREATE_SOCKET ,"unable to create socket"}, | ||
117 | {BIO_R_UNABLE_TO_LISTEN_SOCKET ,"unable to listen socket"}, | ||
118 | {BIO_R_UNINITIALIZED ,"uninitialized"}, | ||
119 | {BIO_R_UNSUPPORTED_METHOD ,"unsupported method"}, | ||
120 | {BIO_R_WSASTARTUP ,"wsastartup"}, | ||
121 | {0,NULL} | ||
122 | }; | ||
123 | |||
124 | #endif | ||
125 | |||
126 | void ERR_load_BIO_strings(void) | ||
127 | { | ||
128 | static int init=1; | ||
129 | |||
130 | if (init) | ||
131 | { | ||
132 | init=0; | ||
133 | #ifndef NO_ERR | ||
134 | ERR_load_strings(ERR_LIB_BIO,BIO_str_functs); | ||
135 | ERR_load_strings(ERR_LIB_BIO,BIO_str_reasons); | ||
136 | #endif | ||
137 | |||
138 | } | ||
139 | } | ||
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c deleted file mode 100644 index b72688ea90..0000000000 --- a/src/lib/libcrypto/bio/bio_lib.c +++ /dev/null | |||
@@ -1,496 +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 *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 *)Malloc(sizeof(BIO)); | ||
74 | if (ret == NULL) | ||
75 | { | ||
76 | BIOerr(BIO_F_BIO_NEW,ERR_R_MALLOC_FAILURE); | ||
77 | return(NULL); | ||
78 | } | ||
79 | if (!BIO_set(ret,method)) | ||
80 | { | ||
81 | Free(ret); | ||
82 | ret=NULL; | ||
83 | } | ||
84 | return(ret); | ||
85 | } | ||
86 | |||
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,(char *)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,(char *)a,&a->ex_data); | ||
133 | |||
134 | if ((a->method == NULL) || (a->method->destroy == NULL)) return(1); | ||
135 | ret=a->method->destroy(a); | ||
136 | Free(a); | ||
137 | return(1); | ||
138 | } | ||
139 | |||
140 | int BIO_read(BIO *b, void *out, int outl) | ||
141 | { | ||
142 | int i; | ||
143 | long (*cb)(); | ||
144 | |||
145 | if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL)) | ||
146 | { | ||
147 | BIOerr(BIO_F_BIO_READ,BIO_R_UNSUPPORTED_METHOD); | ||
148 | return(-2); | ||
149 | } | ||
150 | |||
151 | cb=b->callback; | ||
152 | if ((cb != NULL) && | ||
153 | ((i=(int)cb(b,BIO_CB_READ,out,outl,0L,1L)) <= 0)) | ||
154 | return(i); | ||
155 | |||
156 | if (!b->init) | ||
157 | { | ||
158 | BIOerr(BIO_F_BIO_READ,BIO_R_UNINITIALIZED); | ||
159 | return(-2); | ||
160 | } | ||
161 | |||
162 | i=b->method->bread(b,out,outl); | ||
163 | |||
164 | if (i > 0) b->num_read+=(unsigned long)i; | ||
165 | |||
166 | if (cb != NULL) | ||
167 | i=(int)cb(b,BIO_CB_READ|BIO_CB_RETURN,out,outl, | ||
168 | 0L,(long)i); | ||
169 | return(i); | ||
170 | } | ||
171 | |||
172 | int BIO_write(BIO *b, const char *in, int inl) | ||
173 | { | ||
174 | int i; | ||
175 | long (*cb)(); | ||
176 | |||
177 | if (b == NULL) | ||
178 | return(0); | ||
179 | |||
180 | cb=b->callback; | ||
181 | if ((b->method == NULL) || (b->method->bwrite == NULL)) | ||
182 | { | ||
183 | BIOerr(BIO_F_BIO_WRITE,BIO_R_UNSUPPORTED_METHOD); | ||
184 | return(-2); | ||
185 | } | ||
186 | |||
187 | if ((cb != NULL) && | ||
188 | ((i=(int)cb(b,BIO_CB_WRITE,in,inl,0L,1L)) <= 0)) | ||
189 | return(i); | ||
190 | |||
191 | if (!b->init) | ||
192 | { | ||
193 | BIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITIALIZED); | ||
194 | return(-2); | ||
195 | } | ||
196 | |||
197 | i=b->method->bwrite(b,in,inl); | ||
198 | |||
199 | if (i > 0) b->num_write+=(unsigned long)i; | ||
200 | |||
201 | /* This is evil and not thread safe. If the BIO has been freed, | ||
202 | * we must not call the callback. The only way to be able to | ||
203 | * determine this is the reference count which is now invalid since | ||
204 | * the memory has been free()ed. | ||
205 | */ | ||
206 | if (b->references <= 0) abort(); | ||
207 | if (cb != NULL) /* && (b->references >= 1)) */ | ||
208 | i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl, | ||
209 | 0L,(long)i); | ||
210 | return(i); | ||
211 | } | ||
212 | |||
213 | int BIO_puts(BIO *b, const char *in) | ||
214 | { | ||
215 | int i; | ||
216 | long (*cb)(); | ||
217 | |||
218 | if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) | ||
219 | { | ||
220 | BIOerr(BIO_F_BIO_PUTS,BIO_R_UNSUPPORTED_METHOD); | ||
221 | return(-2); | ||
222 | } | ||
223 | |||
224 | cb=b->callback; | ||
225 | |||
226 | if ((cb != NULL) && | ||
227 | ((i=(int)cb(b,BIO_CB_PUTS,in,0,0L,1L)) <= 0)) | ||
228 | return(i); | ||
229 | |||
230 | if (!b->init) | ||
231 | { | ||
232 | BIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITIALIZED); | ||
233 | return(-2); | ||
234 | } | ||
235 | |||
236 | i=b->method->bputs(b,in); | ||
237 | |||
238 | if (cb != NULL) | ||
239 | i=(int)cb(b,BIO_CB_PUTS|BIO_CB_RETURN,in,0, | ||
240 | 0L,(long)i); | ||
241 | return(i); | ||
242 | } | ||
243 | |||
244 | int BIO_gets(BIO *b, char *in, int inl) | ||
245 | { | ||
246 | int i; | ||
247 | long (*cb)(); | ||
248 | |||
249 | if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL)) | ||
250 | { | ||
251 | BIOerr(BIO_F_BIO_GETS,BIO_R_UNSUPPORTED_METHOD); | ||
252 | return(-2); | ||
253 | } | ||
254 | |||
255 | cb=b->callback; | ||
256 | |||
257 | if ((cb != NULL) && | ||
258 | ((i=(int)cb(b,BIO_CB_GETS,in,inl,0L,1L)) <= 0)) | ||
259 | return(i); | ||
260 | |||
261 | if (!b->init) | ||
262 | { | ||
263 | BIOerr(BIO_F_BIO_GETS,BIO_R_UNINITIALIZED); | ||
264 | return(-2); | ||
265 | } | ||
266 | |||
267 | i=b->method->bgets(b,in,inl); | ||
268 | |||
269 | if (cb != NULL) | ||
270 | i=(int)cb(b,BIO_CB_GETS|BIO_CB_RETURN,in,inl, | ||
271 | 0L,(long)i); | ||
272 | return(i); | ||
273 | } | ||
274 | |||
275 | long BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg) | ||
276 | { | ||
277 | int i; | ||
278 | |||
279 | i=iarg; | ||
280 | return(BIO_ctrl(b,cmd,larg,(char *)&i)); | ||
281 | } | ||
282 | |||
283 | char *BIO_ptr_ctrl(BIO *b, int cmd, long larg) | ||
284 | { | ||
285 | char *p=NULL; | ||
286 | |||
287 | if (BIO_ctrl(b,cmd,larg,(char *)&p) <= 0) | ||
288 | return(NULL); | ||
289 | else | ||
290 | return(p); | ||
291 | } | ||
292 | |||
293 | long BIO_ctrl(BIO *b, int cmd, long larg, void *parg) | ||
294 | { | ||
295 | long ret; | ||
296 | long (*cb)(); | ||
297 | |||
298 | if (b == NULL) return(0); | ||
299 | |||
300 | if ((b->method == NULL) || (b->method->ctrl == NULL)) | ||
301 | { | ||
302 | BIOerr(BIO_F_BIO_CTRL,BIO_R_UNSUPPORTED_METHOD); | ||
303 | return(-2); | ||
304 | } | ||
305 | |||
306 | cb=b->callback; | ||
307 | |||
308 | if ((cb != NULL) && | ||
309 | ((ret=cb(b,BIO_CB_CTRL,parg,cmd,larg,1L)) <= 0)) | ||
310 | return(ret); | ||
311 | |||
312 | ret=b->method->ctrl(b,cmd,larg,parg); | ||
313 | |||
314 | if (cb != NULL) | ||
315 | ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,parg,cmd, | ||
316 | larg,ret); | ||
317 | return(ret); | ||
318 | } | ||
319 | |||
320 | /* It is unfortunate to duplicate in functions what the BIO_(w)pending macros | ||
321 | * do; but those macros have inappropriate return type, and for interfacing | ||
322 | * from other programming languages, C macros aren't much of a help anyway. */ | ||
323 | size_t BIO_ctrl_pending(BIO *bio) | ||
324 | { | ||
325 | return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL); | ||
326 | } | ||
327 | |||
328 | size_t BIO_ctrl_wpending(BIO *bio) | ||
329 | { | ||
330 | return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL); | ||
331 | } | ||
332 | |||
333 | |||
334 | /* put the 'bio' on the end of b's list of operators */ | ||
335 | BIO *BIO_push(BIO *b, BIO *bio) | ||
336 | { | ||
337 | BIO *lb; | ||
338 | |||
339 | if (b == NULL) return(bio); | ||
340 | lb=b; | ||
341 | while (lb->next_bio != NULL) | ||
342 | lb=lb->next_bio; | ||
343 | lb->next_bio=bio; | ||
344 | if (bio != NULL) | ||
345 | bio->prev_bio=lb; | ||
346 | /* called to do internal processing */ | ||
347 | BIO_ctrl(b,BIO_CTRL_PUSH,0,NULL); | ||
348 | return(b); | ||
349 | } | ||
350 | |||
351 | /* Remove the first and return the rest */ | ||
352 | BIO *BIO_pop(BIO *b) | ||
353 | { | ||
354 | BIO *ret; | ||
355 | |||
356 | if (b == NULL) return(NULL); | ||
357 | ret=b->next_bio; | ||
358 | |||
359 | if (b->prev_bio != NULL) | ||
360 | b->prev_bio->next_bio=b->next_bio; | ||
361 | if (b->next_bio != NULL) | ||
362 | b->next_bio->prev_bio=b->prev_bio; | ||
363 | |||
364 | b->next_bio=NULL; | ||
365 | b->prev_bio=NULL; | ||
366 | BIO_ctrl(b,BIO_CTRL_POP,0,NULL); | ||
367 | return(ret); | ||
368 | } | ||
369 | |||
370 | BIO *BIO_get_retry_BIO(BIO *bio, int *reason) | ||
371 | { | ||
372 | BIO *b,*last; | ||
373 | |||
374 | b=last=bio; | ||
375 | for (;;) | ||
376 | { | ||
377 | if (!BIO_should_retry(b)) break; | ||
378 | last=b; | ||
379 | b=b->next_bio; | ||
380 | if (b == NULL) break; | ||
381 | } | ||
382 | if (reason != NULL) *reason=last->retry_reason; | ||
383 | return(last); | ||
384 | } | ||
385 | |||
386 | int BIO_get_retry_reason(BIO *bio) | ||
387 | { | ||
388 | return(bio->retry_reason); | ||
389 | } | ||
390 | |||
391 | BIO *BIO_find_type(BIO *bio, int type) | ||
392 | { | ||
393 | int mt,mask; | ||
394 | |||
395 | mask=type&0xff; | ||
396 | do { | ||
397 | if (bio->method != NULL) | ||
398 | { | ||
399 | mt=bio->method->type; | ||
400 | |||
401 | if (!mask) | ||
402 | { | ||
403 | if (mt & type) return(bio); | ||
404 | } | ||
405 | else if (mt == type) | ||
406 | return(bio); | ||
407 | } | ||
408 | bio=bio->next_bio; | ||
409 | } while (bio != NULL); | ||
410 | return(NULL); | ||
411 | } | ||
412 | |||
413 | void BIO_free_all(BIO *bio) | ||
414 | { | ||
415 | BIO *b; | ||
416 | int ref; | ||
417 | |||
418 | while (bio != NULL) | ||
419 | { | ||
420 | b=bio; | ||
421 | ref=b->references; | ||
422 | bio=bio->next_bio; | ||
423 | BIO_free(b); | ||
424 | /* Since ref count > 1, don't free anyone else. */ | ||
425 | if (ref > 1) break; | ||
426 | } | ||
427 | } | ||
428 | |||
429 | BIO *BIO_dup_chain(BIO *in) | ||
430 | { | ||
431 | BIO *ret=NULL,*eoc=NULL,*bio,*new; | ||
432 | |||
433 | for (bio=in; bio != NULL; bio=bio->next_bio) | ||
434 | { | ||
435 | if ((new=BIO_new(bio->method)) == NULL) goto err; | ||
436 | new->callback=bio->callback; | ||
437 | new->cb_arg=bio->cb_arg; | ||
438 | new->init=bio->init; | ||
439 | new->shutdown=bio->shutdown; | ||
440 | new->flags=bio->flags; | ||
441 | |||
442 | /* This will let SSL_s_sock() work with stdin/stdout */ | ||
443 | new->num=bio->num; | ||
444 | |||
445 | if (!BIO_dup_state(bio,(char *)new)) | ||
446 | { | ||
447 | BIO_free(new); | ||
448 | goto err; | ||
449 | } | ||
450 | |||
451 | /* copy app data */ | ||
452 | if (!CRYPTO_dup_ex_data(bio_meth,&new->ex_data,&bio->ex_data)) | ||
453 | goto err; | ||
454 | |||
455 | if (ret == NULL) | ||
456 | { | ||
457 | eoc=new; | ||
458 | ret=eoc; | ||
459 | } | ||
460 | else | ||
461 | { | ||
462 | BIO_push(eoc,new); | ||
463 | eoc=new; | ||
464 | } | ||
465 | } | ||
466 | return(ret); | ||
467 | err: | ||
468 | if (ret != NULL) | ||
469 | BIO_free(ret); | ||
470 | return(NULL); | ||
471 | } | ||
472 | |||
473 | void BIO_copy_next_retry(BIO *b) | ||
474 | { | ||
475 | BIO_set_flags(b,BIO_get_retry_flags(b->next_bio)); | ||
476 | b->retry_reason=b->next_bio->retry_reason; | ||
477 | } | ||
478 | |||
479 | int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), | ||
480 | int (*dup_func)(), void (*free_func)()) | ||
481 | { | ||
482 | bio_meth_num++; | ||
483 | return(CRYPTO_get_ex_new_index(bio_meth_num-1,&bio_meth, | ||
484 | argl,argp,new_func,dup_func,free_func)); | ||
485 | } | ||
486 | |||
487 | int BIO_set_ex_data(BIO *bio, int idx, char *data) | ||
488 | { | ||
489 | return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data)); | ||
490 | } | ||
491 | |||
492 | char *BIO_get_ex_data(BIO *bio, int idx) | ||
493 | { | ||
494 | return(CRYPTO_get_ex_data(&(bio->ex_data),idx)); | ||
495 | } | ||
496 | |||
diff --git a/src/lib/libcrypto/bio/bss_acpt.c b/src/lib/libcrypto/bio/bss_acpt.c deleted file mode 100644 index 47af80f76d..0000000000 --- a/src/lib/libcrypto/bio/bss_acpt.c +++ /dev/null | |||
@@ -1,466 +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,char *buf,int num); | ||
96 | static int acpt_read(BIO *h,char *buf,int size); | ||
97 | static int acpt_puts(BIO *h,char *str); | ||
98 | static long acpt_ctrl(BIO *h,int cmd,long arg1,char *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 | }; | ||
122 | |||
123 | BIO_METHOD *BIO_s_accept(void) | ||
124 | { | ||
125 | return(&methods_acceptp); | ||
126 | } | ||
127 | |||
128 | static int acpt_new(BIO *bi) | ||
129 | { | ||
130 | BIO_ACCEPT *ba; | ||
131 | |||
132 | bi->init=0; | ||
133 | bi->num=INVALID_SOCKET; | ||
134 | bi->flags=0; | ||
135 | if ((ba=BIO_ACCEPT_new()) == NULL) | ||
136 | return(0); | ||
137 | bi->ptr=(char *)ba; | ||
138 | ba->state=ACPT_S_BEFORE; | ||
139 | bi->shutdown=1; | ||
140 | return(1); | ||
141 | } | ||
142 | |||
143 | BIO_ACCEPT *BIO_ACCEPT_new(void) | ||
144 | { | ||
145 | BIO_ACCEPT *ret; | ||
146 | |||
147 | if ((ret=(BIO_ACCEPT *)Malloc(sizeof(BIO_ACCEPT))) == NULL) | ||
148 | return(NULL); | ||
149 | |||
150 | memset(ret,0,sizeof(BIO_ACCEPT)); | ||
151 | ret->accept_sock=INVALID_SOCKET; | ||
152 | ret->bind_mode=BIO_BIND_NORMAL; | ||
153 | return(ret); | ||
154 | } | ||
155 | |||
156 | void BIO_ACCEPT_free(BIO_ACCEPT *a) | ||
157 | { | ||
158 | if(a == NULL) | ||
159 | return; | ||
160 | |||
161 | if (a->param_addr != NULL) Free(a->param_addr); | ||
162 | if (a->addr != NULL) Free(a->addr); | ||
163 | if (a->bio_chain != NULL) BIO_free(a->bio_chain); | ||
164 | Free(a); | ||
165 | } | ||
166 | |||
167 | static void acpt_close_socket(BIO *bio) | ||
168 | { | ||
169 | BIO_ACCEPT *c; | ||
170 | |||
171 | c=(BIO_ACCEPT *)bio->ptr; | ||
172 | if (c->accept_sock != INVALID_SOCKET) | ||
173 | { | ||
174 | shutdown(c->accept_sock,2); | ||
175 | closesocket(c->accept_sock); | ||
176 | c->accept_sock=INVALID_SOCKET; | ||
177 | bio->num=INVALID_SOCKET; | ||
178 | } | ||
179 | } | ||
180 | |||
181 | static int acpt_free(BIO *a) | ||
182 | { | ||
183 | BIO_ACCEPT *data; | ||
184 | |||
185 | if (a == NULL) return(0); | ||
186 | data=(BIO_ACCEPT *)a->ptr; | ||
187 | |||
188 | if (a->shutdown) | ||
189 | { | ||
190 | acpt_close_socket(a); | ||
191 | BIO_ACCEPT_free(data); | ||
192 | a->ptr=NULL; | ||
193 | a->flags=0; | ||
194 | a->init=0; | ||
195 | } | ||
196 | return(1); | ||
197 | } | ||
198 | |||
199 | static int acpt_state(BIO *b, BIO_ACCEPT *c) | ||
200 | { | ||
201 | BIO *bio=NULL,*dbio; | ||
202 | int s= -1; | ||
203 | int i; | ||
204 | |||
205 | again: | ||
206 | switch (c->state) | ||
207 | { | ||
208 | case ACPT_S_BEFORE: | ||
209 | if (c->param_addr == NULL) | ||
210 | { | ||
211 | BIOerr(BIO_F_ACPT_STATE,BIO_R_NO_ACCEPT_PORT_SPECIFIED); | ||
212 | return(-1); | ||
213 | } | ||
214 | s=BIO_get_accept_socket(c->param_addr,c->bind_mode); | ||
215 | if (s == INVALID_SOCKET) | ||
216 | return(-1); | ||
217 | |||
218 | if (c->accept_nbio) | ||
219 | { | ||
220 | if (!BIO_socket_nbio(s,1)) | ||
221 | { | ||
222 | closesocket(s); | ||
223 | BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET); | ||
224 | return(-1); | ||
225 | } | ||
226 | } | ||
227 | c->accept_sock=s; | ||
228 | b->num=s; | ||
229 | c->state=ACPT_S_GET_ACCEPT_SOCKET; | ||
230 | return(1); | ||
231 | /* break; */ | ||
232 | case ACPT_S_GET_ACCEPT_SOCKET: | ||
233 | if (b->next_bio != NULL) | ||
234 | { | ||
235 | c->state=ACPT_S_OK; | ||
236 | goto again; | ||
237 | } | ||
238 | i=BIO_accept(c->accept_sock,&(c->addr)); | ||
239 | if (i < 0) return(i); | ||
240 | bio=BIO_new_socket(i,BIO_CLOSE); | ||
241 | if (bio == NULL) goto err; | ||
242 | |||
243 | BIO_set_callback(bio,BIO_get_callback(b)); | ||
244 | BIO_set_callback_arg(bio,BIO_get_callback_arg(b)); | ||
245 | |||
246 | if (c->nbio) | ||
247 | { | ||
248 | if (!BIO_socket_nbio(i,1)) | ||
249 | { | ||
250 | BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET); | ||
251 | goto err; | ||
252 | } | ||
253 | } | ||
254 | |||
255 | /* If the accept BIO has an bio_chain, we dup it and | ||
256 | * put the new socket at the end. */ | ||
257 | if (c->bio_chain != NULL) | ||
258 | { | ||
259 | if ((dbio=BIO_dup_chain(c->bio_chain)) == NULL) | ||
260 | goto err; | ||
261 | if (!BIO_push(dbio,bio)) goto err; | ||
262 | bio=dbio; | ||
263 | } | ||
264 | if (BIO_push(b,bio) == NULL) goto err; | ||
265 | |||
266 | c->state=ACPT_S_OK; | ||
267 | return(1); | ||
268 | err: | ||
269 | if (bio != NULL) | ||
270 | BIO_free(bio); | ||
271 | else if (s >= 0) | ||
272 | closesocket(s); | ||
273 | return(0); | ||
274 | /* break; */ | ||
275 | case ACPT_S_OK: | ||
276 | if (b->next_bio == NULL) | ||
277 | { | ||
278 | c->state=ACPT_S_GET_ACCEPT_SOCKET; | ||
279 | goto again; | ||
280 | } | ||
281 | return(1); | ||
282 | /* break; */ | ||
283 | default: | ||
284 | return(0); | ||
285 | /* break; */ | ||
286 | } | ||
287 | |||
288 | } | ||
289 | |||
290 | static int acpt_read(BIO *b, char *out, int outl) | ||
291 | { | ||
292 | int ret=0; | ||
293 | BIO_ACCEPT *data; | ||
294 | |||
295 | BIO_clear_retry_flags(b); | ||
296 | data=(BIO_ACCEPT *)b->ptr; | ||
297 | |||
298 | while (b->next_bio == NULL) | ||
299 | { | ||
300 | ret=acpt_state(b,data); | ||
301 | if (ret <= 0) return(ret); | ||
302 | } | ||
303 | |||
304 | ret=BIO_read(b->next_bio,out,outl); | ||
305 | BIO_copy_next_retry(b); | ||
306 | return(ret); | ||
307 | } | ||
308 | |||
309 | static int acpt_write(BIO *b, char *in, int inl) | ||
310 | { | ||
311 | int ret; | ||
312 | BIO_ACCEPT *data; | ||
313 | |||
314 | BIO_clear_retry_flags(b); | ||
315 | data=(BIO_ACCEPT *)b->ptr; | ||
316 | |||
317 | while (b->next_bio == NULL) | ||
318 | { | ||
319 | ret=acpt_state(b,data); | ||
320 | if (ret <= 0) return(ret); | ||
321 | } | ||
322 | |||
323 | ret=BIO_write(b->next_bio,in,inl); | ||
324 | BIO_copy_next_retry(b); | ||
325 | return(ret); | ||
326 | } | ||
327 | |||
328 | static long acpt_ctrl(BIO *b, int cmd, long num, char *ptr) | ||
329 | { | ||
330 | BIO *dbio; | ||
331 | int *ip; | ||
332 | long ret=1; | ||
333 | BIO_ACCEPT *data; | ||
334 | char **pp; | ||
335 | |||
336 | data=(BIO_ACCEPT *)b->ptr; | ||
337 | |||
338 | switch (cmd) | ||
339 | { | ||
340 | case BIO_CTRL_RESET: | ||
341 | ret=0; | ||
342 | data->state=ACPT_S_BEFORE; | ||
343 | acpt_close_socket(b); | ||
344 | b->flags=0; | ||
345 | break; | ||
346 | case BIO_C_DO_STATE_MACHINE: | ||
347 | /* use this one to start the connection */ | ||
348 | ret=(long)acpt_state(b,data); | ||
349 | break; | ||
350 | case BIO_C_SET_ACCEPT: | ||
351 | if (ptr != NULL) | ||
352 | { | ||
353 | if (num == 0) | ||
354 | { | ||
355 | b->init=1; | ||
356 | if (data->param_addr != NULL) | ||
357 | Free(data->param_addr); | ||
358 | data->param_addr=BUF_strdup(ptr); | ||
359 | } | ||
360 | else if (num == 1) | ||
361 | { | ||
362 | data->accept_nbio=(ptr != NULL); | ||
363 | } | ||
364 | else if (num == 2) | ||
365 | { | ||
366 | if (data->bio_chain != NULL) | ||
367 | BIO_free(data->bio_chain); | ||
368 | data->bio_chain=(BIO *)ptr; | ||
369 | } | ||
370 | } | ||
371 | break; | ||
372 | case BIO_C_SET_NBIO: | ||
373 | data->nbio=(int)num; | ||
374 | break; | ||
375 | case BIO_C_SET_FD: | ||
376 | b->init=1; | ||
377 | b->num= *((int *)ptr); | ||
378 | data->accept_sock=b->num; | ||
379 | data->state=ACPT_S_GET_ACCEPT_SOCKET; | ||
380 | b->shutdown=(int)num; | ||
381 | b->init=1; | ||
382 | break; | ||
383 | case BIO_C_GET_FD: | ||
384 | if (b->init) | ||
385 | { | ||
386 | ip=(int *)ptr; | ||
387 | if (ip != NULL) | ||
388 | *ip=data->accept_sock; | ||
389 | ret=data->accept_sock; | ||
390 | } | ||
391 | else | ||
392 | ret= -1; | ||
393 | break; | ||
394 | case BIO_C_GET_ACCEPT: | ||
395 | if (b->init) | ||
396 | { | ||
397 | if (ptr != NULL) | ||
398 | { | ||
399 | pp=(char **)ptr; | ||
400 | *pp=data->param_addr; | ||
401 | } | ||
402 | else | ||
403 | ret= -1; | ||
404 | } | ||
405 | else | ||
406 | ret= -1; | ||
407 | break; | ||
408 | case BIO_CTRL_GET_CLOSE: | ||
409 | ret=b->shutdown; | ||
410 | break; | ||
411 | case BIO_CTRL_SET_CLOSE: | ||
412 | b->shutdown=(int)num; | ||
413 | break; | ||
414 | case BIO_CTRL_PENDING: | ||
415 | case BIO_CTRL_WPENDING: | ||
416 | ret=0; | ||
417 | break; | ||
418 | case BIO_CTRL_FLUSH: | ||
419 | break; | ||
420 | case BIO_C_SET_BIND_MODE: | ||
421 | data->bind_mode=(int)num; | ||
422 | break; | ||
423 | case BIO_C_GET_BIND_MODE: | ||
424 | ret=(long)data->bind_mode; | ||
425 | break; | ||
426 | case BIO_CTRL_DUP: | ||
427 | dbio=(BIO *)ptr; | ||
428 | /* if (data->param_port) EAY EAY | ||
429 | BIO_set_port(dbio,data->param_port); | ||
430 | if (data->param_hostname) | ||
431 | BIO_set_hostname(dbio,data->param_hostname); | ||
432 | BIO_set_nbio(dbio,data->nbio); */ | ||
433 | break; | ||
434 | |||
435 | default: | ||
436 | ret=0; | ||
437 | break; | ||
438 | } | ||
439 | return(ret); | ||
440 | } | ||
441 | |||
442 | static int acpt_puts(BIO *bp, char *str) | ||
443 | { | ||
444 | int n,ret; | ||
445 | |||
446 | n=strlen(str); | ||
447 | ret=acpt_write(bp,str,n); | ||
448 | return(ret); | ||
449 | } | ||
450 | |||
451 | BIO *BIO_new_accept(char *str) | ||
452 | { | ||
453 | BIO *ret; | ||
454 | |||
455 | ret=BIO_new(BIO_s_accept()); | ||
456 | if (ret == NULL) return(NULL); | ||
457 | if (BIO_set_accept_port(ret,str)) | ||
458 | return(ret); | ||
459 | else | ||
460 | { | ||
461 | BIO_free(ret); | ||
462 | return(NULL); | ||
463 | } | ||
464 | } | ||
465 | |||
466 | #endif | ||
diff --git a/src/lib/libcrypto/bio/bss_bio.c b/src/lib/libcrypto/bio/bss_bio.c deleted file mode 100644 index 562e9d8de2..0000000000 --- a/src/lib/libcrypto/bio/bss_bio.c +++ /dev/null | |||
@@ -1,588 +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 <stdlib.h> | ||
17 | #include <string.h> | ||
18 | |||
19 | #include <openssl/bio.h> | ||
20 | #include <openssl/err.h> | ||
21 | #include <openssl/crypto.h> | ||
22 | |||
23 | static int bio_new(BIO *bio); | ||
24 | static int bio_free(BIO *bio); | ||
25 | static int bio_read(BIO *bio, char *buf, int size); | ||
26 | static int bio_write(BIO *bio, char *buf, int num); | ||
27 | static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr); | ||
28 | static int bio_puts(BIO *bio, char *str); | ||
29 | |||
30 | static int bio_make_pair(BIO *bio1, BIO *bio2); | ||
31 | static void bio_destroy_pair(BIO *bio); | ||
32 | |||
33 | static BIO_METHOD methods_biop = | ||
34 | { | ||
35 | BIO_TYPE_BIO, | ||
36 | "BIO pair", | ||
37 | bio_write, | ||
38 | bio_read, | ||
39 | bio_puts, | ||
40 | NULL /* no bio_gets */, | ||
41 | bio_ctrl, | ||
42 | bio_new, | ||
43 | bio_free | ||
44 | }; | ||
45 | |||
46 | BIO_METHOD *BIO_s_bio(void) | ||
47 | { | ||
48 | return &methods_biop; | ||
49 | } | ||
50 | |||
51 | struct bio_bio_st | ||
52 | { | ||
53 | BIO *peer; /* NULL if buf == NULL. | ||
54 | * If peer != NULL, then peer->ptr is also a bio_bio_st, | ||
55 | * and its "peer" member points back to us. | ||
56 | * peer != NULL iff init != 0 in the BIO. */ | ||
57 | |||
58 | /* This is for what we write (i.e. reading uses peer's struct): */ | ||
59 | int closed; /* valid iff peer != NULL */ | ||
60 | size_t len; /* valid iff buf != NULL; 0 if peer == NULL */ | ||
61 | size_t offset; /* valid iff buf != NULL; 0 if len == 0 */ | ||
62 | size_t size; | ||
63 | char *buf; /* "size" elements (if != NULL) */ | ||
64 | |||
65 | size_t request; /* valid iff peer != NULL; 0 if len != 0, | ||
66 | * otherwise set by peer to number of bytes | ||
67 | * it (unsuccesfully) tried to read, | ||
68 | * never more than buffer space (size-len) warrants. */ | ||
69 | }; | ||
70 | |||
71 | static int bio_new(BIO *bio) | ||
72 | { | ||
73 | struct bio_bio_st *b; | ||
74 | |||
75 | b = Malloc(sizeof *b); | ||
76 | if (b == NULL) | ||
77 | return 0; | ||
78 | |||
79 | b->peer = NULL; | ||
80 | b->size = 17*1024; /* enough for one TLS record (just a default) */ | ||
81 | b->buf = NULL; | ||
82 | |||
83 | bio->ptr = b; | ||
84 | return 1; | ||
85 | } | ||
86 | |||
87 | |||
88 | static int bio_free(BIO *bio) | ||
89 | { | ||
90 | struct bio_bio_st *b; | ||
91 | |||
92 | if (bio == NULL) | ||
93 | return 0; | ||
94 | b = bio->ptr; | ||
95 | |||
96 | assert(b != NULL); | ||
97 | |||
98 | if (b->peer) | ||
99 | bio_destroy_pair(bio); | ||
100 | |||
101 | if (b->buf != NULL) | ||
102 | { | ||
103 | Free(b->buf); | ||
104 | } | ||
105 | |||
106 | Free(b); | ||
107 | |||
108 | return 1; | ||
109 | } | ||
110 | |||
111 | |||
112 | |||
113 | static int bio_read(BIO *bio, char *buf, int size_) | ||
114 | { | ||
115 | size_t size = size_; | ||
116 | size_t rest; | ||
117 | struct bio_bio_st *b, *peer_b; | ||
118 | |||
119 | BIO_clear_retry_flags(bio); | ||
120 | |||
121 | if (!bio->init) | ||
122 | return 0; | ||
123 | |||
124 | b = bio->ptr; | ||
125 | assert(b != NULL); | ||
126 | assert(b->peer != NULL); | ||
127 | peer_b = b->peer->ptr; | ||
128 | assert(peer_b != NULL); | ||
129 | assert(peer_b->buf != NULL); | ||
130 | |||
131 | peer_b->request = 0; /* will be set in "retry_read" situation */ | ||
132 | |||
133 | if (buf == NULL || size == 0) | ||
134 | return 0; | ||
135 | |||
136 | if (peer_b->len == 0) | ||
137 | { | ||
138 | if (peer_b->closed) | ||
139 | return 0; /* writer has closed, and no data is left */ | ||
140 | else | ||
141 | { | ||
142 | BIO_set_retry_read(bio); /* buffer is empty */ | ||
143 | if (size <= peer_b->size) | ||
144 | peer_b->request = size; | ||
145 | else | ||
146 | /* don't ask for more than the peer can | ||
147 | * deliver in one write */ | ||
148 | peer_b->request = peer_b->size; | ||
149 | return -1; | ||
150 | } | ||
151 | } | ||
152 | |||
153 | /* we can read */ | ||
154 | if (peer_b->len < size) | ||
155 | size = peer_b->len; | ||
156 | |||
157 | /* now read "size" bytes */ | ||
158 | |||
159 | rest = size; | ||
160 | |||
161 | assert(rest > 0); | ||
162 | do /* one or two iterations */ | ||
163 | { | ||
164 | size_t chunk; | ||
165 | |||
166 | assert(rest <= peer_b->len); | ||
167 | if (peer_b->offset + rest <= peer_b->size) | ||
168 | chunk = rest; | ||
169 | else | ||
170 | /* wrap around ring buffer */ | ||
171 | chunk = peer_b->size - peer_b->offset; | ||
172 | assert(peer_b->offset + chunk <= peer_b->size); | ||
173 | |||
174 | memcpy(buf, peer_b->buf + peer_b->offset, chunk); | ||
175 | |||
176 | peer_b->len -= chunk; | ||
177 | if (peer_b->len) | ||
178 | { | ||
179 | peer_b->offset += chunk; | ||
180 | assert(peer_b->offset <= peer_b->size); | ||
181 | if (peer_b->offset == peer_b->size) | ||
182 | peer_b->offset = 0; | ||
183 | buf += chunk; | ||
184 | } | ||
185 | else | ||
186 | { | ||
187 | /* buffer now empty, no need to advance "buf" */ | ||
188 | assert(chunk == rest); | ||
189 | peer_b->offset = 0; | ||
190 | } | ||
191 | rest -= chunk; | ||
192 | } | ||
193 | while (rest); | ||
194 | |||
195 | return size; | ||
196 | } | ||
197 | |||
198 | static int bio_write(BIO *bio, char *buf, int num_) | ||
199 | { | ||
200 | size_t num = num_; | ||
201 | size_t rest; | ||
202 | struct bio_bio_st *b; | ||
203 | |||
204 | BIO_clear_retry_flags(bio); | ||
205 | |||
206 | if (!bio->init || buf == NULL || num == 0) | ||
207 | return 0; | ||
208 | |||
209 | b = bio->ptr; | ||
210 | assert(b != NULL); | ||
211 | assert(b->peer != NULL); | ||
212 | assert(b->buf != NULL); | ||
213 | |||
214 | b->request = 0; | ||
215 | if (b->closed) | ||
216 | { | ||
217 | /* we already closed */ | ||
218 | BIOerr(BIO_F_BIO_WRITE, BIO_R_BROKEN_PIPE); | ||
219 | return -1; | ||
220 | } | ||
221 | |||
222 | assert(b->len <= b->size); | ||
223 | |||
224 | if (b->len == b->size) | ||
225 | { | ||
226 | BIO_set_retry_write(bio); /* buffer is full */ | ||
227 | return -1; | ||
228 | } | ||
229 | |||
230 | /* we can write */ | ||
231 | if (num > b->size - b->len) | ||
232 | num = b->size - b->len; | ||
233 | |||
234 | /* now write "num" bytes */ | ||
235 | |||
236 | rest = num; | ||
237 | |||
238 | assert(rest > 0); | ||
239 | do /* one or two iterations */ | ||
240 | { | ||
241 | size_t write_offset; | ||
242 | size_t chunk; | ||
243 | |||
244 | assert(b->len + rest <= b->size); | ||
245 | |||
246 | write_offset = b->offset + b->len; | ||
247 | if (write_offset >= b->size) | ||
248 | write_offset -= b->size; | ||
249 | /* b->buf[write_offset] is the first byte we can write to. */ | ||
250 | |||
251 | if (write_offset + rest <= b->size) | ||
252 | chunk = rest; | ||
253 | else | ||
254 | /* wrap around ring buffer */ | ||
255 | chunk = b->size - write_offset; | ||
256 | |||
257 | memcpy(b->buf + write_offset, buf, chunk); | ||
258 | |||
259 | b->len += chunk; | ||
260 | |||
261 | assert(b->len <= b->size); | ||
262 | |||
263 | rest -= chunk; | ||
264 | buf += chunk; | ||
265 | } | ||
266 | while (rest); | ||
267 | |||
268 | return num; | ||
269 | } | ||
270 | |||
271 | |||
272 | static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | ||
273 | { | ||
274 | long ret; | ||
275 | struct bio_bio_st *b = bio->ptr; | ||
276 | |||
277 | assert(b != NULL); | ||
278 | |||
279 | switch (cmd) | ||
280 | { | ||
281 | /* specific CTRL codes */ | ||
282 | |||
283 | case BIO_C_SET_WRITE_BUF_SIZE: | ||
284 | if (b->peer) | ||
285 | { | ||
286 | BIOerr(BIO_F_BIO_CTRL, BIO_R_IN_USE); | ||
287 | ret = 0; | ||
288 | } | ||
289 | else if (num == 0) | ||
290 | { | ||
291 | BIOerr(BIO_F_BIO_CTRL, BIO_R_INVALID_ARGUMENT); | ||
292 | ret = 0; | ||
293 | } | ||
294 | else | ||
295 | { | ||
296 | size_t new_size = num; | ||
297 | |||
298 | if (b->size != new_size) | ||
299 | { | ||
300 | if (b->buf) | ||
301 | { | ||
302 | Free(b->buf); | ||
303 | b->buf = NULL; | ||
304 | } | ||
305 | b->size = new_size; | ||
306 | } | ||
307 | ret = 1; | ||
308 | } | ||
309 | break; | ||
310 | |||
311 | case BIO_C_GET_WRITE_BUF_SIZE: | ||
312 | num = (long) b->size; | ||
313 | |||
314 | case BIO_C_MAKE_BIO_PAIR: | ||
315 | { | ||
316 | BIO *other_bio = ptr; | ||
317 | |||
318 | if (bio_make_pair(bio, other_bio)) | ||
319 | ret = 1; | ||
320 | else | ||
321 | ret = 0; | ||
322 | } | ||
323 | break; | ||
324 | |||
325 | case BIO_C_DESTROY_BIO_PAIR: | ||
326 | /* Effects both BIOs in the pair -- call just once! | ||
327 | * Or let BIO_free(bio1); BIO_free(bio2); do the job. */ | ||
328 | bio_destroy_pair(bio); | ||
329 | ret = 1; | ||
330 | break; | ||
331 | |||
332 | case BIO_C_GET_WRITE_GUARANTEE: | ||
333 | /* How many bytes can the caller feed to the next write | ||
334 | * withouth having to keep any? */ | ||
335 | if (b->peer == NULL || b->closed) | ||
336 | ret = 0; | ||
337 | else | ||
338 | ret = (long) b->size - b->len; | ||
339 | break; | ||
340 | |||
341 | case BIO_C_GET_READ_REQUEST: | ||
342 | /* If the peer unsuccesfully tried to read, how many bytes | ||
343 | * were requested? (As with BIO_CTRL_PENDING, that number | ||
344 | * can usually be treated as boolean.) */ | ||
345 | ret = (long) b->request; | ||
346 | break; | ||
347 | |||
348 | case BIO_C_SHUTDOWN_WR: | ||
349 | /* similar to shutdown(..., SHUT_WR) */ | ||
350 | b->closed = 1; | ||
351 | ret = 1; | ||
352 | break; | ||
353 | |||
354 | |||
355 | /* standard CTRL codes follow */ | ||
356 | |||
357 | case BIO_CTRL_RESET: | ||
358 | if (b->buf != NULL) | ||
359 | { | ||
360 | b->len = 0; | ||
361 | b->offset = 0; | ||
362 | } | ||
363 | ret = 0; | ||
364 | break; | ||
365 | |||
366 | case BIO_CTRL_GET_CLOSE: | ||
367 | ret = bio->shutdown; | ||
368 | break; | ||
369 | |||
370 | case BIO_CTRL_SET_CLOSE: | ||
371 | bio->shutdown = (int) num; | ||
372 | ret = 1; | ||
373 | break; | ||
374 | |||
375 | case BIO_CTRL_PENDING: | ||
376 | if (b->peer != NULL) | ||
377 | { | ||
378 | struct bio_bio_st *peer_b = b->peer->ptr; | ||
379 | |||
380 | ret = (long) peer_b->len; | ||
381 | } | ||
382 | else | ||
383 | ret = 0; | ||
384 | break; | ||
385 | |||
386 | case BIO_CTRL_WPENDING: | ||
387 | if (b->buf != NULL) | ||
388 | ret = (long) b->len; | ||
389 | else | ||
390 | ret = 0; | ||
391 | break; | ||
392 | |||
393 | case BIO_CTRL_DUP: | ||
394 | /* See BIO_dup_chain for circumstances we have to expect. */ | ||
395 | { | ||
396 | BIO *other_bio = ptr; | ||
397 | struct bio_bio_st *other_b; | ||
398 | |||
399 | assert(other_bio != NULL); | ||
400 | other_b = other_bio->ptr; | ||
401 | assert(other_b != NULL); | ||
402 | |||
403 | assert(other_b->buf == NULL); /* other_bio is always fresh */ | ||
404 | |||
405 | other_b->size = b->size; | ||
406 | } | ||
407 | |||
408 | ret = 1; | ||
409 | break; | ||
410 | |||
411 | case BIO_CTRL_FLUSH: | ||
412 | ret = 1; | ||
413 | break; | ||
414 | |||
415 | case BIO_CTRL_EOF: | ||
416 | { | ||
417 | BIO *other_bio = ptr; | ||
418 | |||
419 | if (other_bio) | ||
420 | { | ||
421 | struct bio_bio_st *other_b = other_bio->ptr; | ||
422 | |||
423 | assert(other_b != NULL); | ||
424 | ret = other_b->len == 0 && other_b->closed; | ||
425 | } | ||
426 | else | ||
427 | ret = 1; | ||
428 | } | ||
429 | break; | ||
430 | |||
431 | default: | ||
432 | ret = 0; | ||
433 | } | ||
434 | return ret; | ||
435 | } | ||
436 | |||
437 | static int bio_puts(BIO *bio, char *str) | ||
438 | { | ||
439 | return bio_write(bio, str, strlen(str)); | ||
440 | } | ||
441 | |||
442 | |||
443 | static int bio_make_pair(BIO *bio1, BIO *bio2) | ||
444 | { | ||
445 | struct bio_bio_st *b1, *b2; | ||
446 | |||
447 | assert(bio1 != NULL); | ||
448 | assert(bio2 != NULL); | ||
449 | |||
450 | b1 = bio1->ptr; | ||
451 | b2 = bio2->ptr; | ||
452 | |||
453 | if (b1->peer != NULL || b2->peer != NULL) | ||
454 | { | ||
455 | BIOerr(BIO_F_BIO_MAKE_PAIR, BIO_R_IN_USE); | ||
456 | return 0; | ||
457 | } | ||
458 | |||
459 | if (b1->buf == NULL) | ||
460 | { | ||
461 | b1->buf = Malloc(b1->size); | ||
462 | if (b1->buf == NULL) | ||
463 | { | ||
464 | BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); | ||
465 | return 0; | ||
466 | } | ||
467 | b1->len = 0; | ||
468 | b1->offset = 0; | ||
469 | } | ||
470 | |||
471 | if (b2->buf == NULL) | ||
472 | { | ||
473 | b2->buf = Malloc(b2->size); | ||
474 | if (b2->buf == NULL) | ||
475 | { | ||
476 | BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); | ||
477 | return 0; | ||
478 | } | ||
479 | b2->len = 0; | ||
480 | b2->offset = 0; | ||
481 | } | ||
482 | |||
483 | b1->peer = bio2; | ||
484 | b1->closed = 0; | ||
485 | b1->request = 0; | ||
486 | b2->peer = bio1; | ||
487 | b2->closed = 0; | ||
488 | b2->request = 0; | ||
489 | |||
490 | bio1->init = 1; | ||
491 | bio2->init = 1; | ||
492 | |||
493 | return 1; | ||
494 | } | ||
495 | |||
496 | static void bio_destroy_pair(BIO *bio) | ||
497 | { | ||
498 | struct bio_bio_st *b = bio->ptr; | ||
499 | |||
500 | if (b != NULL) | ||
501 | { | ||
502 | BIO *peer_bio = b->peer; | ||
503 | |||
504 | if (peer_bio != NULL) | ||
505 | { | ||
506 | struct bio_bio_st *peer_b = peer_bio->ptr; | ||
507 | |||
508 | assert(peer_b != NULL); | ||
509 | assert(peer_b->peer == bio); | ||
510 | |||
511 | peer_b->peer = NULL; | ||
512 | peer_bio->init = 0; | ||
513 | assert(peer_b->buf != NULL); | ||
514 | peer_b->len = 0; | ||
515 | peer_b->offset = 0; | ||
516 | |||
517 | b->peer = NULL; | ||
518 | bio->init = 0; | ||
519 | assert(b->buf != NULL); | ||
520 | b->len = 0; | ||
521 | b->offset = 0; | ||
522 | } | ||
523 | } | ||
524 | } | ||
525 | |||
526 | |||
527 | /* Exported convenience functions */ | ||
528 | int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1, | ||
529 | BIO **bio2_p, size_t writebuf2) | ||
530 | { | ||
531 | BIO *bio1 = NULL, *bio2 = NULL; | ||
532 | long r; | ||
533 | int ret = 0; | ||
534 | |||
535 | bio1 = BIO_new(BIO_s_bio()); | ||
536 | if (bio1 == NULL) | ||
537 | goto err; | ||
538 | bio2 = BIO_new(BIO_s_bio()); | ||
539 | if (bio2 == NULL) | ||
540 | goto err; | ||
541 | |||
542 | if (writebuf1) | ||
543 | { | ||
544 | r = BIO_set_write_buf_size(bio1, writebuf1); | ||
545 | if (!r) | ||
546 | goto err; | ||
547 | } | ||
548 | if (writebuf2) | ||
549 | { | ||
550 | r = BIO_set_write_buf_size(bio2, writebuf2); | ||
551 | if (!r) | ||
552 | goto err; | ||
553 | } | ||
554 | |||
555 | r = BIO_make_bio_pair(bio1, bio2); | ||
556 | if (!r) | ||
557 | goto err; | ||
558 | ret = 1; | ||
559 | |||
560 | err: | ||
561 | if (ret == 0) | ||
562 | { | ||
563 | if (bio1) | ||
564 | { | ||
565 | BIO_free(bio1); | ||
566 | bio1 = NULL; | ||
567 | } | ||
568 | if (bio2) | ||
569 | { | ||
570 | BIO_free(bio2); | ||
571 | bio2 = NULL; | ||
572 | } | ||
573 | } | ||
574 | |||
575 | *bio1_p = bio1; | ||
576 | *bio2_p = bio2; | ||
577 | return ret; | ||
578 | } | ||
579 | |||
580 | size_t BIO_ctrl_get_write_guarantee(BIO *bio) | ||
581 | { | ||
582 | return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL); | ||
583 | } | ||
584 | |||
585 | size_t BIO_ctrl_get_read_request(BIO *bio) | ||
586 | { | ||
587 | return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL); | ||
588 | } | ||
diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c deleted file mode 100644 index 68c46e3d69..0000000000 --- a/src/lib/libcrypto/bio/bss_conn.c +++ /dev/null | |||
@@ -1,618 +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 | * compatable 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 compatablity with the ssl info_callback */ | ||
98 | int (*info_callback)(); | ||
99 | } BIO_CONNECT; | ||
100 | |||
101 | static int conn_write(BIO *h,char *buf,int num); | ||
102 | static int conn_read(BIO *h,char *buf,int size); | ||
103 | static int conn_puts(BIO *h,char *str); | ||
104 | static long conn_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
105 | static int conn_new(BIO *h); | ||
106 | static int conn_free(BIO *data); | ||
107 | |||
108 | static int conn_state(BIO *b, BIO_CONNECT *c); | ||
109 | static void conn_close_socket(BIO *data); | ||
110 | BIO_CONNECT *BIO_CONNECT_new(void ); | ||
111 | void BIO_CONNECT_free(BIO_CONNECT *a); | ||
112 | |||
113 | static BIO_METHOD methods_connectp= | ||
114 | { | ||
115 | BIO_TYPE_CONNECT, | ||
116 | "socket connect", | ||
117 | conn_write, | ||
118 | conn_read, | ||
119 | conn_puts, | ||
120 | NULL, /* connect_gets, */ | ||
121 | conn_ctrl, | ||
122 | conn_new, | ||
123 | conn_free, | ||
124 | }; | ||
125 | |||
126 | static int conn_state(BIO *b, BIO_CONNECT *c) | ||
127 | { | ||
128 | int ret= -1,i; | ||
129 | unsigned long l; | ||
130 | char *p,*q; | ||
131 | int (*cb)()=NULL; | ||
132 | |||
133 | if (c->info_callback != NULL) | ||
134 | cb=c->info_callback; | ||
135 | |||
136 | for (;;) | ||
137 | { | ||
138 | switch (c->state) | ||
139 | { | ||
140 | case BIO_CONN_S_BEFORE: | ||
141 | p=c->param_hostname; | ||
142 | if (p == NULL) | ||
143 | { | ||
144 | BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTNAME_SPECIFIED); | ||
145 | goto exit_loop; | ||
146 | } | ||
147 | for ( ; *p != '\0'; p++) | ||
148 | { | ||
149 | if ((*p == ':') || (*p == '/')) break; | ||
150 | } | ||
151 | |||
152 | i= *p; | ||
153 | if ((i == ':') || (i == '/')) | ||
154 | { | ||
155 | |||
156 | *(p++)='\0'; | ||
157 | if (i == ':') | ||
158 | { | ||
159 | for (q=p; *q; q++) | ||
160 | if (*q == '/') | ||
161 | { | ||
162 | *q='\0'; | ||
163 | break; | ||
164 | } | ||
165 | if (c->param_port != NULL) | ||
166 | Free(c->param_port); | ||
167 | c->param_port=BUF_strdup(p); | ||
168 | } | ||
169 | } | ||
170 | |||
171 | if (c->param_port == NULL) | ||
172 | { | ||
173 | BIOerr(BIO_F_CONN_STATE,BIO_R_NO_PORT_SPECIFIED); | ||
174 | ERR_add_error_data(2,"host=",c->param_hostname); | ||
175 | goto exit_loop; | ||
176 | } | ||
177 | c->state=BIO_CONN_S_GET_IP; | ||
178 | break; | ||
179 | |||
180 | case BIO_CONN_S_GET_IP: | ||
181 | if (BIO_get_host_ip(c->param_hostname,&(c->ip[0])) <= 0) | ||
182 | goto exit_loop; | ||
183 | c->state=BIO_CONN_S_GET_PORT; | ||
184 | break; | ||
185 | |||
186 | case BIO_CONN_S_GET_PORT: | ||
187 | if (c->param_port == NULL) | ||
188 | { | ||
189 | abort(); | ||
190 | goto exit_loop; | ||
191 | } | ||
192 | else if (BIO_get_port(c->param_port,&c->port) <= 0) | ||
193 | goto exit_loop; | ||
194 | c->state=BIO_CONN_S_CREATE_SOCKET; | ||
195 | break; | ||
196 | |||
197 | case BIO_CONN_S_CREATE_SOCKET: | ||
198 | /* now setup address */ | ||
199 | memset((char *)&c->them,0,sizeof(c->them)); | ||
200 | c->them.sin_family=AF_INET; | ||
201 | c->them.sin_port=htons((unsigned short)c->port); | ||
202 | l=(unsigned long) | ||
203 | ((unsigned long)c->ip[0]<<24L)| | ||
204 | ((unsigned long)c->ip[1]<<16L)| | ||
205 | ((unsigned long)c->ip[2]<< 8L)| | ||
206 | ((unsigned long)c->ip[3]); | ||
207 | c->them.sin_addr.s_addr=htonl(l); | ||
208 | c->state=BIO_CONN_S_CREATE_SOCKET; | ||
209 | |||
210 | ret=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); | ||
211 | if (ret == INVALID_SOCKET) | ||
212 | { | ||
213 | SYSerr(SYS_F_SOCKET,get_last_socket_error()); | ||
214 | ERR_add_error_data(4,"host=",c->param_hostname, | ||
215 | ":",c->param_port); | ||
216 | BIOerr(BIO_F_CONN_STATE,BIO_R_UNABLE_TO_CREATE_SOCKET); | ||
217 | goto exit_loop; | ||
218 | } | ||
219 | b->num=ret; | ||
220 | c->state=BIO_CONN_S_NBIO; | ||
221 | break; | ||
222 | |||
223 | case BIO_CONN_S_NBIO: | ||
224 | if (c->nbio) | ||
225 | { | ||
226 | if (!BIO_socket_nbio(b->num,1)) | ||
227 | { | ||
228 | BIOerr(BIO_F_CONN_STATE,BIO_R_ERROR_SETTING_NBIO); | ||
229 | ERR_add_error_data(4,"host=", | ||
230 | c->param_hostname, | ||
231 | ":",c->param_port); | ||
232 | goto exit_loop; | ||
233 | } | ||
234 | } | ||
235 | c->state=BIO_CONN_S_CONNECT; | ||
236 | |||
237 | #ifdef SO_KEEPALIVE | ||
238 | i=1; | ||
239 | i=setsockopt(b->num,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i)); | ||
240 | if (i < 0) | ||
241 | { | ||
242 | SYSerr(SYS_F_SOCKET,get_last_socket_error()); | ||
243 | ERR_add_error_data(4,"host=",c->param_hostname, | ||
244 | ":",c->param_port); | ||
245 | BIOerr(BIO_F_CONN_STATE,BIO_R_KEEPALIVE); | ||
246 | goto exit_loop; | ||
247 | } | ||
248 | #endif | ||
249 | break; | ||
250 | |||
251 | case BIO_CONN_S_CONNECT: | ||
252 | BIO_clear_retry_flags(b); | ||
253 | ret=connect(b->num, | ||
254 | (struct sockaddr *)&c->them, | ||
255 | sizeof(c->them)); | ||
256 | b->retry_reason=0; | ||
257 | if (ret < 0) | ||
258 | { | ||
259 | if (BIO_sock_should_retry(ret)) | ||
260 | { | ||
261 | BIO_set_retry_special(b); | ||
262 | c->state=BIO_CONN_S_BLOCKED_CONNECT; | ||
263 | b->retry_reason=BIO_RR_CONNECT; | ||
264 | } | ||
265 | else | ||
266 | { | ||
267 | SYSerr(SYS_F_CONNECT,get_last_socket_error()); | ||
268 | ERR_add_error_data(4,"host=", | ||
269 | c->param_hostname, | ||
270 | ":",c->param_port); | ||
271 | BIOerr(BIO_F_CONN_STATE,BIO_R_CONNECT_ERROR); | ||
272 | } | ||
273 | goto exit_loop; | ||
274 | } | ||
275 | else | ||
276 | c->state=BIO_CONN_S_OK; | ||
277 | break; | ||
278 | |||
279 | case BIO_CONN_S_BLOCKED_CONNECT: | ||
280 | i=BIO_sock_error(b->num); | ||
281 | if (i) | ||
282 | { | ||
283 | BIO_clear_retry_flags(b); | ||
284 | SYSerr(SYS_F_CONNECT,i); | ||
285 | ERR_add_error_data(4,"host=", | ||
286 | c->param_hostname, | ||
287 | ":",c->param_port); | ||
288 | BIOerr(BIO_F_CONN_STATE,BIO_R_NBIO_CONNECT_ERROR); | ||
289 | ret=0; | ||
290 | goto exit_loop; | ||
291 | } | ||
292 | else | ||
293 | c->state=BIO_CONN_S_OK; | ||
294 | break; | ||
295 | |||
296 | case BIO_CONN_S_OK: | ||
297 | ret=1; | ||
298 | goto exit_loop; | ||
299 | default: | ||
300 | abort(); | ||
301 | goto exit_loop; | ||
302 | } | ||
303 | |||
304 | if (cb != NULL) | ||
305 | { | ||
306 | if (!(ret=cb((BIO *)b,c->state,ret))) | ||
307 | goto end; | ||
308 | } | ||
309 | } | ||
310 | |||
311 | /* Loop does not exit */ | ||
312 | exit_loop: | ||
313 | if (cb != NULL) | ||
314 | ret=cb((BIO *)b,c->state,ret); | ||
315 | end: | ||
316 | return(ret); | ||
317 | } | ||
318 | |||
319 | BIO_CONNECT *BIO_CONNECT_new(void) | ||
320 | { | ||
321 | BIO_CONNECT *ret; | ||
322 | |||
323 | if ((ret=(BIO_CONNECT *)Malloc(sizeof(BIO_CONNECT))) == NULL) | ||
324 | return(NULL); | ||
325 | ret->state=BIO_CONN_S_BEFORE; | ||
326 | ret->param_hostname=NULL; | ||
327 | ret->param_port=NULL; | ||
328 | ret->info_callback=NULL; | ||
329 | ret->nbio=0; | ||
330 | ret->ip[0]=0; | ||
331 | ret->ip[1]=0; | ||
332 | ret->ip[2]=0; | ||
333 | ret->ip[3]=0; | ||
334 | ret->port=0; | ||
335 | memset((char *)&ret->them,0,sizeof(ret->them)); | ||
336 | return(ret); | ||
337 | } | ||
338 | |||
339 | void BIO_CONNECT_free(BIO_CONNECT *a) | ||
340 | { | ||
341 | if(a == NULL) | ||
342 | return; | ||
343 | |||
344 | if (a->param_hostname != NULL) | ||
345 | Free(a->param_hostname); | ||
346 | if (a->param_port != NULL) | ||
347 | Free(a->param_port); | ||
348 | Free(a); | ||
349 | } | ||
350 | |||
351 | BIO_METHOD *BIO_s_connect(void) | ||
352 | { | ||
353 | return(&methods_connectp); | ||
354 | } | ||
355 | |||
356 | static int conn_new(BIO *bi) | ||
357 | { | ||
358 | bi->init=0; | ||
359 | bi->num=INVALID_SOCKET; | ||
360 | bi->flags=0; | ||
361 | if ((bi->ptr=(char *)BIO_CONNECT_new()) == NULL) | ||
362 | return(0); | ||
363 | else | ||
364 | return(1); | ||
365 | } | ||
366 | |||
367 | static void conn_close_socket(BIO *bio) | ||
368 | { | ||
369 | BIO_CONNECT *c; | ||
370 | |||
371 | c=(BIO_CONNECT *)bio->ptr; | ||
372 | if (bio->num != INVALID_SOCKET) | ||
373 | { | ||
374 | /* Only do a shutdown if things were established */ | ||
375 | if (c->state == BIO_CONN_S_OK) | ||
376 | shutdown(bio->num,2); | ||
377 | closesocket(bio->num); | ||
378 | bio->num=INVALID_SOCKET; | ||
379 | } | ||
380 | } | ||
381 | |||
382 | static int conn_free(BIO *a) | ||
383 | { | ||
384 | BIO_CONNECT *data; | ||
385 | |||
386 | if (a == NULL) return(0); | ||
387 | data=(BIO_CONNECT *)a->ptr; | ||
388 | |||
389 | if (a->shutdown) | ||
390 | { | ||
391 | conn_close_socket(a); | ||
392 | BIO_CONNECT_free(data); | ||
393 | a->ptr=NULL; | ||
394 | a->flags=0; | ||
395 | a->init=0; | ||
396 | } | ||
397 | return(1); | ||
398 | } | ||
399 | |||
400 | static int conn_read(BIO *b, char *out, int outl) | ||
401 | { | ||
402 | int ret=0; | ||
403 | BIO_CONNECT *data; | ||
404 | |||
405 | data=(BIO_CONNECT *)b->ptr; | ||
406 | if (data->state != BIO_CONN_S_OK) | ||
407 | { | ||
408 | ret=conn_state(b,data); | ||
409 | if (ret <= 0) | ||
410 | return(ret); | ||
411 | } | ||
412 | |||
413 | if (out != NULL) | ||
414 | { | ||
415 | clear_socket_error(); | ||
416 | ret=readsocket(b->num,out,outl); | ||
417 | BIO_clear_retry_flags(b); | ||
418 | if (ret <= 0) | ||
419 | { | ||
420 | if (BIO_sock_should_retry(ret)) | ||
421 | BIO_set_retry_read(b); | ||
422 | } | ||
423 | } | ||
424 | return(ret); | ||
425 | } | ||
426 | |||
427 | static int conn_write(BIO *b, char *in, int inl) | ||
428 | { | ||
429 | int ret; | ||
430 | BIO_CONNECT *data; | ||
431 | |||
432 | data=(BIO_CONNECT *)b->ptr; | ||
433 | if (data->state != BIO_CONN_S_OK) | ||
434 | { | ||
435 | ret=conn_state(b,data); | ||
436 | if (ret <= 0) return(ret); | ||
437 | } | ||
438 | |||
439 | clear_socket_error(); | ||
440 | ret=writesocket(b->num,in,inl); | ||
441 | BIO_clear_retry_flags(b); | ||
442 | if (ret <= 0) | ||
443 | { | ||
444 | if (BIO_sock_should_retry(ret)) | ||
445 | BIO_set_retry_write(b); | ||
446 | } | ||
447 | return(ret); | ||
448 | } | ||
449 | |||
450 | static long conn_ctrl(BIO *b, int cmd, long num, char *ptr) | ||
451 | { | ||
452 | BIO *dbio; | ||
453 | int *ip; | ||
454 | const char **pptr; | ||
455 | long ret=1; | ||
456 | BIO_CONNECT *data; | ||
457 | |||
458 | data=(BIO_CONNECT *)b->ptr; | ||
459 | |||
460 | switch (cmd) | ||
461 | { | ||
462 | case BIO_CTRL_RESET: | ||
463 | ret=0; | ||
464 | data->state=BIO_CONN_S_BEFORE; | ||
465 | conn_close_socket(b); | ||
466 | b->flags=0; | ||
467 | break; | ||
468 | case BIO_C_DO_STATE_MACHINE: | ||
469 | /* use this one to start the connection */ | ||
470 | if (!data->state != BIO_CONN_S_OK) | ||
471 | ret=(long)conn_state(b,data); | ||
472 | else | ||
473 | ret=1; | ||
474 | break; | ||
475 | case BIO_C_GET_CONNECT: | ||
476 | if (ptr != NULL) | ||
477 | { | ||
478 | pptr=(const char **)ptr; | ||
479 | if (num == 0) | ||
480 | { | ||
481 | *pptr=data->param_hostname; | ||
482 | |||
483 | } | ||
484 | else if (num == 1) | ||
485 | { | ||
486 | *pptr=data->param_port; | ||
487 | } | ||
488 | else if (num == 2) | ||
489 | { | ||
490 | *pptr= (char *)&(data->ip[0]); | ||
491 | } | ||
492 | else if (num == 3) | ||
493 | { | ||
494 | *((int *)ptr)=data->port; | ||
495 | } | ||
496 | if ((!b->init) || (ptr == NULL)) | ||
497 | *pptr="not initalised"; | ||
498 | ret=1; | ||
499 | } | ||
500 | break; | ||
501 | case BIO_C_SET_CONNECT: | ||
502 | if (ptr != NULL) | ||
503 | { | ||
504 | b->init=1; | ||
505 | if (num == 0) | ||
506 | { | ||
507 | if (data->param_hostname != NULL) | ||
508 | Free(data->param_hostname); | ||
509 | data->param_hostname=BUF_strdup(ptr); | ||
510 | } | ||
511 | else if (num == 1) | ||
512 | { | ||
513 | if (data->param_port != NULL) | ||
514 | Free(data->param_port); | ||
515 | data->param_port=BUF_strdup(ptr); | ||
516 | } | ||
517 | else if (num == 2) | ||
518 | { | ||
519 | char buf[16]; | ||
520 | |||
521 | sprintf(buf,"%d.%d.%d.%d", | ||
522 | ptr[0],ptr[1],ptr[2],ptr[3]); | ||
523 | if (data->param_hostname != NULL) | ||
524 | Free(data->param_hostname); | ||
525 | data->param_hostname=BUF_strdup(buf); | ||
526 | memcpy(&(data->ip[0]),ptr,4); | ||
527 | } | ||
528 | else if (num == 3) | ||
529 | { | ||
530 | char buf[16]; | ||
531 | |||
532 | sprintf(buf,"%d",*(int *)ptr); | ||
533 | if (data->param_port != NULL) | ||
534 | Free(data->param_port); | ||
535 | data->param_port=BUF_strdup(buf); | ||
536 | data->port= *(int *)ptr; | ||
537 | } | ||
538 | } | ||
539 | break; | ||
540 | case BIO_C_SET_NBIO: | ||
541 | data->nbio=(int)num; | ||
542 | break; | ||
543 | case BIO_C_GET_FD: | ||
544 | if (b->init) | ||
545 | { | ||
546 | ip=(int *)ptr; | ||
547 | if (ip != NULL) | ||
548 | *ip=b->num; | ||
549 | ret=b->num; | ||
550 | } | ||
551 | else | ||
552 | ret= -1; | ||
553 | break; | ||
554 | case BIO_CTRL_GET_CLOSE: | ||
555 | ret=b->shutdown; | ||
556 | break; | ||
557 | case BIO_CTRL_SET_CLOSE: | ||
558 | b->shutdown=(int)num; | ||
559 | break; | ||
560 | case BIO_CTRL_PENDING: | ||
561 | case BIO_CTRL_WPENDING: | ||
562 | ret=0; | ||
563 | break; | ||
564 | case BIO_CTRL_FLUSH: | ||
565 | break; | ||
566 | case BIO_CTRL_DUP: | ||
567 | dbio=(BIO *)ptr; | ||
568 | if (data->param_port) | ||
569 | BIO_set_conn_port(dbio,data->param_port); | ||
570 | if (data->param_hostname) | ||
571 | BIO_set_conn_hostname(dbio,data->param_hostname); | ||
572 | BIO_set_nbio(dbio,data->nbio); | ||
573 | (void)BIO_set_info_callback(dbio,data->info_callback); | ||
574 | break; | ||
575 | case BIO_CTRL_SET_CALLBACK: | ||
576 | data->info_callback=(int (*)())ptr; | ||
577 | break; | ||
578 | case BIO_CTRL_GET_CALLBACK: | ||
579 | { | ||
580 | int (**fptr)(); | ||
581 | |||
582 | fptr=(int (**)())ptr; | ||
583 | *fptr=data->info_callback; | ||
584 | } | ||
585 | break; | ||
586 | default: | ||
587 | ret=0; | ||
588 | break; | ||
589 | } | ||
590 | return(ret); | ||
591 | } | ||
592 | |||
593 | static int conn_puts(BIO *bp, char *str) | ||
594 | { | ||
595 | int n,ret; | ||
596 | |||
597 | n=strlen(str); | ||
598 | ret=conn_write(bp,str,n); | ||
599 | return(ret); | ||
600 | } | ||
601 | |||
602 | BIO *BIO_new_connect(char *str) | ||
603 | { | ||
604 | BIO *ret; | ||
605 | |||
606 | ret=BIO_new(BIO_s_connect()); | ||
607 | if (ret == NULL) return(NULL); | ||
608 | if (BIO_set_conn_hostname(ret,str)) | ||
609 | return(ret); | ||
610 | else | ||
611 | { | ||
612 | BIO_free(ret); | ||
613 | return(NULL); | ||
614 | } | ||
615 | } | ||
616 | |||
617 | #endif | ||
618 | |||
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 52c0c39df0..0000000000 --- a/src/lib/libcrypto/bio/bss_file.c +++ /dev/null | |||
@@ -1,309 +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,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,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,char *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 | }; | ||
95 | |||
96 | BIO *BIO_new_file(const char *filename, const char *mode) | ||
97 | { | ||
98 | BIO *ret; | ||
99 | FILE *file; | ||
100 | |||
101 | if ((file=fopen(filename,mode)) == NULL) | ||
102 | { | ||
103 | SYSerr(SYS_F_FOPEN,get_last_sys_error()); | ||
104 | ERR_add_error_data(5,"fopen('",filename,"','",mode,"')"); | ||
105 | BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB); | ||
106 | return(NULL); | ||
107 | } | ||
108 | if ((ret=BIO_new(BIO_s_file_internal())) == NULL) | ||
109 | return(NULL); | ||
110 | |||
111 | BIO_set_fp(ret,file,BIO_CLOSE); | ||
112 | return(ret); | ||
113 | } | ||
114 | |||
115 | BIO *BIO_new_fp(FILE *stream, int close_flag) | ||
116 | { | ||
117 | BIO *ret; | ||
118 | |||
119 | if ((ret=BIO_new(BIO_s_file())) == NULL) | ||
120 | return(NULL); | ||
121 | |||
122 | BIO_set_fp(ret,stream,close_flag); | ||
123 | return(ret); | ||
124 | } | ||
125 | |||
126 | BIO_METHOD *BIO_s_file(void) | ||
127 | { | ||
128 | return(&methods_filep); | ||
129 | } | ||
130 | |||
131 | static int MS_CALLBACK file_new(BIO *bi) | ||
132 | { | ||
133 | bi->init=0; | ||
134 | bi->num=0; | ||
135 | bi->ptr=NULL; | ||
136 | return(1); | ||
137 | } | ||
138 | |||
139 | static int MS_CALLBACK file_free(BIO *a) | ||
140 | { | ||
141 | if (a == NULL) return(0); | ||
142 | if (a->shutdown) | ||
143 | { | ||
144 | if ((a->init) && (a->ptr != NULL)) | ||
145 | { | ||
146 | fclose((FILE *)a->ptr); | ||
147 | a->ptr=NULL; | ||
148 | } | ||
149 | a->init=0; | ||
150 | } | ||
151 | return(1); | ||
152 | } | ||
153 | |||
154 | static int MS_CALLBACK file_read(BIO *b, char *out, int outl) | ||
155 | { | ||
156 | int ret=0; | ||
157 | |||
158 | if (b->init && (out != NULL)) | ||
159 | { | ||
160 | ret=fread(out,1,(int)outl,(FILE *)b->ptr); | ||
161 | } | ||
162 | return(ret); | ||
163 | } | ||
164 | |||
165 | static int MS_CALLBACK file_write(BIO *b, char *in, int inl) | ||
166 | { | ||
167 | int ret=0; | ||
168 | |||
169 | if (b->init && (in != NULL)) | ||
170 | { | ||
171 | if (fwrite(in,(int)inl,1,(FILE *)b->ptr)) | ||
172 | ret=inl; | ||
173 | /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */ | ||
174 | /* acording to Tim Hudson <tjh@cryptsoft.com>, the commented | ||
175 | * out version above can cause 'inl' write calls under | ||
176 | * some stupid stdio implementations (VMS) */ | ||
177 | } | ||
178 | return(ret); | ||
179 | } | ||
180 | |||
181 | static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, char *ptr) | ||
182 | { | ||
183 | long ret=1; | ||
184 | FILE *fp=(FILE *)b->ptr; | ||
185 | FILE **fpp; | ||
186 | char p[4]; | ||
187 | |||
188 | switch (cmd) | ||
189 | { | ||
190 | case BIO_C_FILE_SEEK: | ||
191 | case BIO_CTRL_RESET: | ||
192 | ret=(long)fseek(fp,num,0); | ||
193 | break; | ||
194 | case BIO_CTRL_EOF: | ||
195 | ret=(long)feof(fp); | ||
196 | break; | ||
197 | case BIO_C_FILE_TELL: | ||
198 | case BIO_CTRL_INFO: | ||
199 | ret=ftell(fp); | ||
200 | break; | ||
201 | case BIO_C_SET_FILE_PTR: | ||
202 | file_free(b); | ||
203 | b->shutdown=(int)num&BIO_CLOSE; | ||
204 | b->ptr=(char *)ptr; | ||
205 | b->init=1; | ||
206 | #if defined(MSDOS) || defined(WINDOWS) | ||
207 | /* Set correct text/binary mode */ | ||
208 | if (num & BIO_FP_TEXT) | ||
209 | _setmode(fileno((FILE *)ptr),_O_TEXT); | ||
210 | else | ||
211 | _setmode(fileno((FILE *)ptr),_O_BINARY); | ||
212 | #endif | ||
213 | break; | ||
214 | case BIO_C_SET_FILENAME: | ||
215 | file_free(b); | ||
216 | b->shutdown=(int)num&BIO_CLOSE; | ||
217 | if (num & BIO_FP_APPEND) | ||
218 | { | ||
219 | if (num & BIO_FP_READ) | ||
220 | strcpy(p,"a+"); | ||
221 | else strcpy(p,"a"); | ||
222 | } | ||
223 | else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE)) | ||
224 | strcpy(p,"r+"); | ||
225 | else if (num & BIO_FP_WRITE) | ||
226 | strcpy(p,"w"); | ||
227 | else if (num & BIO_FP_READ) | ||
228 | strcpy(p,"r"); | ||
229 | else | ||
230 | { | ||
231 | BIOerr(BIO_F_FILE_CTRL,BIO_R_BAD_FOPEN_MODE); | ||
232 | ret=0; | ||
233 | break; | ||
234 | } | ||
235 | #if defined(MSDOS) || defined(WINDOWS) | ||
236 | if (!(num & BIO_FP_TEXT)) | ||
237 | strcat(p,"b"); | ||
238 | else | ||
239 | strcat(p,"t"); | ||
240 | #endif | ||
241 | fp=fopen(ptr,p); | ||
242 | if (fp == NULL) | ||
243 | { | ||
244 | SYSerr(SYS_F_FOPEN,get_last_sys_error()); | ||
245 | ERR_add_error_data(5,"fopen('",ptr,"','",p,"')"); | ||
246 | BIOerr(BIO_F_FILE_CTRL,ERR_R_SYS_LIB); | ||
247 | ret=0; | ||
248 | break; | ||
249 | } | ||
250 | b->ptr=(char *)fp; | ||
251 | b->init=1; | ||
252 | break; | ||
253 | case BIO_C_GET_FILE_PTR: | ||
254 | /* the ptr parameter is actually a FILE ** in this case. */ | ||
255 | if (ptr != NULL) | ||
256 | { | ||
257 | fpp=(FILE **)ptr; | ||
258 | *fpp=(FILE *)b->ptr; | ||
259 | } | ||
260 | break; | ||
261 | case BIO_CTRL_GET_CLOSE: | ||
262 | ret=(long)b->shutdown; | ||
263 | break; | ||
264 | case BIO_CTRL_SET_CLOSE: | ||
265 | b->shutdown=(int)num; | ||
266 | break; | ||
267 | case BIO_CTRL_FLUSH: | ||
268 | fflush((FILE *)b->ptr); | ||
269 | break; | ||
270 | case BIO_CTRL_DUP: | ||
271 | ret=1; | ||
272 | break; | ||
273 | |||
274 | case BIO_CTRL_WPENDING: | ||
275 | case BIO_CTRL_PENDING: | ||
276 | case BIO_CTRL_PUSH: | ||
277 | case BIO_CTRL_POP: | ||
278 | default: | ||
279 | ret=0; | ||
280 | break; | ||
281 | } | ||
282 | return(ret); | ||
283 | } | ||
284 | |||
285 | static int MS_CALLBACK file_gets(BIO *bp, char *buf, int size) | ||
286 | { | ||
287 | int ret=0; | ||
288 | |||
289 | buf[0]='\0'; | ||
290 | fgets(buf,size,(FILE *)bp->ptr); | ||
291 | if (buf[0] != '\0') | ||
292 | ret=strlen(buf); | ||
293 | return(ret); | ||
294 | } | ||
295 | |||
296 | static int MS_CALLBACK file_puts(BIO *bp, char *str) | ||
297 | { | ||
298 | int n,ret; | ||
299 | |||
300 | n=strlen(str); | ||
301 | ret=file_write(bp,str,n); | ||
302 | return(ret); | ||
303 | } | ||
304 | |||
305 | #endif /* NO_STDIO */ | ||
306 | |||
307 | #endif /* HEADER_BSS_FILE_C */ | ||
308 | |||
309 | |||
diff --git a/src/lib/libcrypto/bio/bss_log.c b/src/lib/libcrypto/bio/bss_log.c deleted file mode 100644 index db82e757e7..0000000000 --- a/src/lib/libcrypto/bio/bss_log.c +++ /dev/null | |||
@@ -1,232 +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 (or event log | ||
61 | under NT). | ||
62 | |||
63 | */ | ||
64 | |||
65 | |||
66 | #include <stdio.h> | ||
67 | #include <errno.h> | ||
68 | |||
69 | #ifndef WIN32 | ||
70 | #ifdef __ultrix | ||
71 | #include <sys/syslog.h> | ||
72 | #else | ||
73 | #include <syslog.h> | ||
74 | #endif | ||
75 | #endif | ||
76 | |||
77 | #include "cryptlib.h" | ||
78 | #include <openssl/buffer.h> | ||
79 | #include <openssl/err.h> | ||
80 | #ifndef NO_SYSLOG | ||
81 | |||
82 | |||
83 | static int MS_CALLBACK slg_write(BIO *h,char *buf,int num); | ||
84 | static int MS_CALLBACK slg_puts(BIO *h,char *str); | ||
85 | static long MS_CALLBACK slg_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
86 | static int MS_CALLBACK slg_new(BIO *h); | ||
87 | static int MS_CALLBACK slg_free(BIO *data); | ||
88 | static int xopenlog(BIO* bp, const char* name, int level); | ||
89 | static int xcloselog(BIO* bp); | ||
90 | |||
91 | static BIO_METHOD methods_slg= | ||
92 | { | ||
93 | BIO_TYPE_MEM,"syslog", | ||
94 | slg_write, | ||
95 | NULL, | ||
96 | slg_puts, | ||
97 | NULL, | ||
98 | slg_ctrl, | ||
99 | slg_new, | ||
100 | slg_free, | ||
101 | }; | ||
102 | |||
103 | BIO_METHOD *BIO_s_log(void) | ||
104 | { | ||
105 | return(&methods_slg); | ||
106 | } | ||
107 | |||
108 | static int MS_CALLBACK slg_new(BIO *bi) | ||
109 | { | ||
110 | bi->init=1; | ||
111 | bi->num=0; | ||
112 | bi->ptr=NULL; | ||
113 | #ifndef WIN32 | ||
114 | xopenlog(bi, "application", LOG_DAEMON); | ||
115 | #else | ||
116 | xopenlog(bi, "application", 0); | ||
117 | #endif | ||
118 | return(1); | ||
119 | } | ||
120 | |||
121 | static int MS_CALLBACK slg_free(BIO *a) | ||
122 | { | ||
123 | if (a == NULL) return(0); | ||
124 | xcloselog(a); | ||
125 | return(1); | ||
126 | } | ||
127 | |||
128 | static int MS_CALLBACK slg_write(BIO *b, char *in, int inl) | ||
129 | { | ||
130 | int ret= inl; | ||
131 | char* buf= in; | ||
132 | char* pp; | ||
133 | #if defined(WIN32) | ||
134 | LPTSTR lpszStrings[1]; | ||
135 | WORD evtype= EVENTLOG_ERROR_TYPE; | ||
136 | #else | ||
137 | int priority; | ||
138 | #endif | ||
139 | |||
140 | if((buf= (char *)Malloc(inl+ 1)) == NULL){ | ||
141 | return(0); | ||
142 | } | ||
143 | strncpy(buf, in, inl); | ||
144 | buf[inl]= '\0'; | ||
145 | #if defined(WIN32) | ||
146 | if(strncmp(buf, "ERR ", 4) == 0){ | ||
147 | evtype= EVENTLOG_ERROR_TYPE; | ||
148 | pp= buf+ 4; | ||
149 | }else if(strncmp(buf, "WAR ", 4) == 0){ | ||
150 | evtype= EVENTLOG_WARNING_TYPE; | ||
151 | pp= buf+ 4; | ||
152 | }else if(strncmp(buf, "INF ", 4) == 0){ | ||
153 | evtype= EVENTLOG_INFORMATION_TYPE; | ||
154 | pp= buf+ 4; | ||
155 | }else{ | ||
156 | evtype= EVENTLOG_ERROR_TYPE; | ||
157 | pp= buf; | ||
158 | } | ||
159 | lpszStrings[0]= pp; | ||
160 | |||
161 | if(b->ptr) | ||
162 | ReportEvent(b->ptr, evtype, 0, 1024, NULL, 1, 0, | ||
163 | lpszStrings, NULL); | ||
164 | #else | ||
165 | if(strncmp(buf, "ERR ", 4) == 0){ | ||
166 | priority= LOG_ERR; | ||
167 | pp= buf+ 4; | ||
168 | }else if(strncmp(buf, "WAR ", 4) == 0){ | ||
169 | priority= LOG_WARNING; | ||
170 | pp= buf+ 4; | ||
171 | }else if(strncmp(buf, "INF ", 4) == 0){ | ||
172 | priority= LOG_INFO; | ||
173 | pp= buf+ 4; | ||
174 | }else{ | ||
175 | priority= LOG_ERR; | ||
176 | pp= buf; | ||
177 | } | ||
178 | |||
179 | syslog(priority, "%s", pp); | ||
180 | #endif | ||
181 | Free(buf); | ||
182 | return(ret); | ||
183 | } | ||
184 | |||
185 | static long MS_CALLBACK slg_ctrl(BIO *b, int cmd, long num, char *ptr) | ||
186 | { | ||
187 | switch (cmd) | ||
188 | { | ||
189 | case BIO_CTRL_SET: | ||
190 | xcloselog(b); | ||
191 | xopenlog(b, ptr, num); | ||
192 | break; | ||
193 | default: | ||
194 | break; | ||
195 | } | ||
196 | return(0); | ||
197 | } | ||
198 | |||
199 | static int MS_CALLBACK slg_puts(BIO *bp, char *str) | ||
200 | { | ||
201 | int n,ret; | ||
202 | |||
203 | n=strlen(str); | ||
204 | ret=slg_write(bp,str,n); | ||
205 | return(ret); | ||
206 | } | ||
207 | |||
208 | static int xopenlog(BIO* bp, const char* name, int level) | ||
209 | { | ||
210 | #if defined(WIN32) | ||
211 | if((bp->ptr= (char *)RegisterEventSource(NULL, name)) == NULL){ | ||
212 | return(0); | ||
213 | } | ||
214 | #else | ||
215 | openlog(name, LOG_PID|LOG_CONS, level); | ||
216 | #endif | ||
217 | return(1); | ||
218 | } | ||
219 | |||
220 | static int xcloselog(BIO* bp) | ||
221 | { | ||
222 | #if defined(WIN32) | ||
223 | if(bp->ptr) | ||
224 | DeregisterEventSource((HANDLE)(bp->ptr)); | ||
225 | bp->ptr= NULL; | ||
226 | #else | ||
227 | closelog(); | ||
228 | #endif | ||
229 | return(1); | ||
230 | } | ||
231 | |||
232 | #endif | ||
diff --git a/src/lib/libcrypto/bio/bss_mem.c b/src/lib/libcrypto/bio/bss_mem.c deleted file mode 100644 index 7e749a503e..0000000000 --- a/src/lib/libcrypto/bio/bss_mem.c +++ /dev/null | |||
@@ -1,276 +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,char *buf,int num); | ||
65 | static int mem_read(BIO *h,char *buf,int size); | ||
66 | static int mem_puts(BIO *h,char *str); | ||
67 | static int mem_gets(BIO *h,char *str,int size); | ||
68 | static long mem_ctrl(BIO *h,int cmd,long arg1,char *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 | }; | ||
83 | |||
84 | /* bio->num is used to hold the value to return on 'empty', if it is | ||
85 | * 0, should_retry is not set */ | ||
86 | |||
87 | BIO_METHOD *BIO_s_mem(void) | ||
88 | { | ||
89 | return(&mem_method); | ||
90 | } | ||
91 | |||
92 | static int mem_new(BIO *bi) | ||
93 | { | ||
94 | BUF_MEM *b; | ||
95 | |||
96 | if ((b=BUF_MEM_new()) == NULL) | ||
97 | return(0); | ||
98 | bi->shutdown=1; | ||
99 | bi->init=1; | ||
100 | bi->num= -1; | ||
101 | bi->ptr=(char *)b; | ||
102 | return(1); | ||
103 | } | ||
104 | |||
105 | static int mem_free(BIO *a) | ||
106 | { | ||
107 | if (a == NULL) return(0); | ||
108 | if (a->shutdown) | ||
109 | { | ||
110 | if ((a->init) && (a->ptr != NULL)) | ||
111 | { | ||
112 | BUF_MEM_free((BUF_MEM *)a->ptr); | ||
113 | a->ptr=NULL; | ||
114 | } | ||
115 | } | ||
116 | return(1); | ||
117 | } | ||
118 | |||
119 | static int mem_read(BIO *b, char *out, int outl) | ||
120 | { | ||
121 | int ret= -1; | ||
122 | BUF_MEM *bm; | ||
123 | int i; | ||
124 | char *from,*to; | ||
125 | |||
126 | bm=(BUF_MEM *)b->ptr; | ||
127 | BIO_clear_retry_flags(b); | ||
128 | ret=(outl > bm->length)?bm->length:outl; | ||
129 | if ((out != NULL) && (ret > 0)) | ||
130 | { | ||
131 | memcpy(out,bm->data,ret); | ||
132 | bm->length-=ret; | ||
133 | /* memmove(&(bm->data[0]),&(bm->data[ret]), bm->length); */ | ||
134 | from=(char *)&(bm->data[ret]); | ||
135 | to=(char *)&(bm->data[0]); | ||
136 | for (i=0; i<bm->length; i++) | ||
137 | to[i]=from[i]; | ||
138 | } | ||
139 | else if (bm->length == 0) | ||
140 | { | ||
141 | if (b->num != 0) | ||
142 | BIO_set_retry_read(b); | ||
143 | ret= b->num; | ||
144 | } | ||
145 | return(ret); | ||
146 | } | ||
147 | |||
148 | static int mem_write(BIO *b, char *in, int inl) | ||
149 | { | ||
150 | int ret= -1; | ||
151 | int blen; | ||
152 | BUF_MEM *bm; | ||
153 | |||
154 | bm=(BUF_MEM *)b->ptr; | ||
155 | if (in == NULL) | ||
156 | { | ||
157 | BIOerr(BIO_F_MEM_WRITE,BIO_R_NULL_PARAMETER); | ||
158 | goto end; | ||
159 | } | ||
160 | |||
161 | BIO_clear_retry_flags(b); | ||
162 | blen=bm->length; | ||
163 | if (BUF_MEM_grow(bm,blen+inl) != (blen+inl)) | ||
164 | goto end; | ||
165 | memcpy(&(bm->data[blen]),in,inl); | ||
166 | ret=inl; | ||
167 | end: | ||
168 | return(ret); | ||
169 | } | ||
170 | |||
171 | static long mem_ctrl(BIO *b, int cmd, long num, char *ptr) | ||
172 | { | ||
173 | long ret=1; | ||
174 | char **pptr; | ||
175 | |||
176 | BUF_MEM *bm=(BUF_MEM *)b->ptr; | ||
177 | |||
178 | switch (cmd) | ||
179 | { | ||
180 | case BIO_CTRL_RESET: | ||
181 | if (bm->data != NULL) | ||
182 | memset(bm->data,0,bm->max); | ||
183 | bm->length=0; | ||
184 | break; | ||
185 | case BIO_CTRL_EOF: | ||
186 | ret=(long)(bm->length == 0); | ||
187 | break; | ||
188 | case BIO_C_SET_BUF_MEM_EOF_RETURN: | ||
189 | b->num=(int)num; | ||
190 | break; | ||
191 | case BIO_CTRL_INFO: | ||
192 | ret=(long)bm->length; | ||
193 | if (ptr != NULL) | ||
194 | { | ||
195 | pptr=(char **)ptr; | ||
196 | *pptr=(char *)&(bm->data[0]); | ||
197 | } | ||
198 | break; | ||
199 | case BIO_C_SET_BUF_MEM: | ||
200 | mem_free(b); | ||
201 | b->shutdown=(int)num; | ||
202 | b->ptr=ptr; | ||
203 | break; | ||
204 | case BIO_C_GET_BUF_MEM_PTR: | ||
205 | if (ptr != NULL) | ||
206 | { | ||
207 | pptr=(char **)ptr; | ||
208 | *pptr=(char *)bm; | ||
209 | } | ||
210 | break; | ||
211 | case BIO_CTRL_GET_CLOSE: | ||
212 | ret=(long)b->shutdown; | ||
213 | break; | ||
214 | case BIO_CTRL_SET_CLOSE: | ||
215 | b->shutdown=(int)num; | ||
216 | break; | ||
217 | |||
218 | case BIO_CTRL_WPENDING: | ||
219 | ret=0L; | ||
220 | break; | ||
221 | case BIO_CTRL_PENDING: | ||
222 | ret=(long)bm->length; | ||
223 | break; | ||
224 | case BIO_CTRL_DUP: | ||
225 | case BIO_CTRL_FLUSH: | ||
226 | ret=1; | ||
227 | break; | ||
228 | case BIO_CTRL_PUSH: | ||
229 | case BIO_CTRL_POP: | ||
230 | default: | ||
231 | ret=0; | ||
232 | break; | ||
233 | } | ||
234 | return(ret); | ||
235 | } | ||
236 | |||
237 | static int mem_gets(BIO *bp, char *buf, int size) | ||
238 | { | ||
239 | int i,j; | ||
240 | int ret= -1; | ||
241 | char *p; | ||
242 | BUF_MEM *bm=(BUF_MEM *)bp->ptr; | ||
243 | |||
244 | BIO_clear_retry_flags(bp); | ||
245 | j=bm->length; | ||
246 | if (j <= 0) return(0); | ||
247 | p=bm->data; | ||
248 | for (i=0; i<j; i++) | ||
249 | { | ||
250 | if (p[i] == '\n') break; | ||
251 | } | ||
252 | if (i == j) | ||
253 | { | ||
254 | BIO_set_retry_read(bp); | ||
255 | /* return(-1); change the semantics 0.6.6a */ | ||
256 | } | ||
257 | else | ||
258 | i++; | ||
259 | /* i is the max to copy */ | ||
260 | if ((size-1) < i) i=size-1; | ||
261 | i=mem_read(bp,buf,i); | ||
262 | if (i > 0) buf[i]='\0'; | ||
263 | ret=i; | ||
264 | return(ret); | ||
265 | } | ||
266 | |||
267 | static int mem_puts(BIO *bp, char *str) | ||
268 | { | ||
269 | int n,ret; | ||
270 | |||
271 | n=strlen(str); | ||
272 | ret=mem_write(bp,str,n); | ||
273 | /* memory semantics is that it will always work */ | ||
274 | return(ret); | ||
275 | } | ||
276 | |||
diff --git a/src/lib/libcrypto/bio/bss_null.c b/src/lib/libcrypto/bio/bss_null.c deleted file mode 100644 index d04be888e5..0000000000 --- a/src/lib/libcrypto/bio/bss_null.c +++ /dev/null | |||
@@ -1,149 +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,char *buf,int num); | ||
65 | static int null_read(BIO *h,char *buf,int size); | ||
66 | static int null_puts(BIO *h,char *str); | ||
67 | static int null_gets(BIO *h,char *str,int size); | ||
68 | static long null_ctrl(BIO *h,int cmd,long arg1,char *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 | }; | ||
83 | |||
84 | BIO_METHOD *BIO_s_null(void) | ||
85 | { | ||
86 | return(&null_method); | ||
87 | } | ||
88 | |||
89 | static int null_new(BIO *bi) | ||
90 | { | ||
91 | bi->init=1; | ||
92 | bi->num=0; | ||
93 | bi->ptr=(NULL); | ||
94 | return(1); | ||
95 | } | ||
96 | |||
97 | static int null_free(BIO *a) | ||
98 | { | ||
99 | if (a == NULL) return(0); | ||
100 | return(1); | ||
101 | } | ||
102 | |||
103 | static int null_read(BIO *b, char *out, int outl) | ||
104 | { | ||
105 | return(0); | ||
106 | } | ||
107 | |||
108 | static int null_write(BIO *b, char *in, int inl) | ||
109 | { | ||
110 | return(inl); | ||
111 | } | ||
112 | |||
113 | static long null_ctrl(BIO *b, int cmd, long num, char *ptr) | ||
114 | { | ||
115 | long ret=1; | ||
116 | |||
117 | switch (cmd) | ||
118 | { | ||
119 | case BIO_CTRL_RESET: | ||
120 | case BIO_CTRL_EOF: | ||
121 | case BIO_CTRL_SET: | ||
122 | case BIO_CTRL_SET_CLOSE: | ||
123 | case BIO_CTRL_FLUSH: | ||
124 | case BIO_CTRL_DUP: | ||
125 | ret=1; | ||
126 | break; | ||
127 | case BIO_CTRL_GET_CLOSE: | ||
128 | case BIO_CTRL_INFO: | ||
129 | case BIO_CTRL_GET: | ||
130 | case BIO_CTRL_PENDING: | ||
131 | case BIO_CTRL_WPENDING: | ||
132 | default: | ||
133 | ret=0; | ||
134 | break; | ||
135 | } | ||
136 | return(ret); | ||
137 | } | ||
138 | |||
139 | static int null_gets(BIO *bp, char *buf, int size) | ||
140 | { | ||
141 | return(0); | ||
142 | } | ||
143 | |||
144 | static int null_puts(BIO *bp, char *str) | ||
145 | { | ||
146 | if (str == NULL) return(0); | ||
147 | return(strlen(str)); | ||
148 | } | ||
149 | |||
diff --git a/src/lib/libcrypto/bio/bss_sock.c b/src/lib/libcrypto/bio/bss_sock.c deleted file mode 100644 index d336b99fe8..0000000000 --- a/src/lib/libcrypto/bio/bss_sock.c +++ /dev/null | |||
@@ -1,423 +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,char *buf,int num); | ||
69 | static int sock_read(BIO *h,char *buf,int size); | ||
70 | static int sock_puts(BIO *h,char *str); | ||
71 | static long sock_ctrl(BIO *h,int cmd,long arg1,char *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,char *buf,int num); | ||
78 | static int fd_read(BIO *h,char *buf,int size); | ||
79 | static int fd_puts(BIO *h,char *str); | ||
80 | static long fd_ctrl(BIO *h,int cmd,long arg1,char *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 | }; | ||
99 | |||
100 | BIO_METHOD *BIO_s_socket(void) | ||
101 | { | ||
102 | return(&methods_sockp); | ||
103 | } | ||
104 | #else | ||
105 | static BIO_METHOD methods_fdp= | ||
106 | { | ||
107 | BIO_TYPE_FD,"file descriptor", | ||
108 | fd_write, | ||
109 | fd_read, | ||
110 | fd_puts, | ||
111 | NULL, /* fd_gets, */ | ||
112 | fd_ctrl, | ||
113 | fd_new, | ||
114 | fd_free, | ||
115 | }; | ||
116 | |||
117 | BIO_METHOD *BIO_s_fd(void) | ||
118 | { | ||
119 | return(&methods_fdp); | ||
120 | } | ||
121 | #endif | ||
122 | |||
123 | #ifndef BIO_FD | ||
124 | BIO *BIO_new_socket(int fd, int close_flag) | ||
125 | #else | ||
126 | BIO *BIO_new_fd(int fd,int close_flag) | ||
127 | #endif | ||
128 | { | ||
129 | BIO *ret; | ||
130 | |||
131 | #ifndef BIO_FD | ||
132 | ret=BIO_new(BIO_s_socket()); | ||
133 | #else | ||
134 | ret=BIO_new(BIO_s_fd()); | ||
135 | #endif | ||
136 | if (ret == NULL) return(NULL); | ||
137 | BIO_set_fd(ret,fd,close_flag); | ||
138 | return(ret); | ||
139 | } | ||
140 | |||
141 | #ifndef BIO_FD | ||
142 | static int sock_new(BIO *bi) | ||
143 | #else | ||
144 | static int fd_new(BIO *bi) | ||
145 | #endif | ||
146 | { | ||
147 | bi->init=0; | ||
148 | bi->num=0; | ||
149 | bi->ptr=NULL; | ||
150 | bi->flags=0; | ||
151 | return(1); | ||
152 | } | ||
153 | |||
154 | #ifndef BIO_FD | ||
155 | static int sock_free(BIO *a) | ||
156 | #else | ||
157 | static int fd_free(BIO *a) | ||
158 | #endif | ||
159 | { | ||
160 | if (a == NULL) return(0); | ||
161 | if (a->shutdown) | ||
162 | { | ||
163 | if (a->init) | ||
164 | { | ||
165 | #ifndef BIO_FD | ||
166 | shutdown(a->num,2); | ||
167 | closesocket(a->num); | ||
168 | #else /* BIO_FD */ | ||
169 | close(a->num); | ||
170 | #endif | ||
171 | |||
172 | } | ||
173 | a->init=0; | ||
174 | a->flags=0; | ||
175 | } | ||
176 | return(1); | ||
177 | } | ||
178 | |||
179 | #ifndef BIO_FD | ||
180 | static int sock_read(BIO *b, char *out, int outl) | ||
181 | #else | ||
182 | static int fd_read(BIO *b, char *out,int outl) | ||
183 | #endif | ||
184 | { | ||
185 | int ret=0; | ||
186 | |||
187 | if (out != NULL) | ||
188 | { | ||
189 | #ifndef BIO_FD | ||
190 | clear_socket_error(); | ||
191 | ret=readsocket(b->num,out,outl); | ||
192 | #else | ||
193 | clear_sys_error(); | ||
194 | ret=read(b->num,out,outl); | ||
195 | #endif | ||
196 | BIO_clear_retry_flags(b); | ||
197 | if (ret <= 0) | ||
198 | { | ||
199 | #ifndef BIO_FD | ||
200 | if (BIO_sock_should_retry(ret)) | ||
201 | #else | ||
202 | if (BIO_fd_should_retry(ret)) | ||
203 | #endif | ||
204 | BIO_set_retry_read(b); | ||
205 | } | ||
206 | } | ||
207 | return(ret); | ||
208 | } | ||
209 | |||
210 | #ifndef BIO_FD | ||
211 | static int sock_write(BIO *b, char *in, int inl) | ||
212 | #else | ||
213 | static int fd_write(BIO *b, char *in, int inl) | ||
214 | #endif | ||
215 | { | ||
216 | int ret; | ||
217 | |||
218 | #ifndef BIO_FD | ||
219 | clear_socket_error(); | ||
220 | ret=writesocket(b->num,in,inl); | ||
221 | #else | ||
222 | clear_sys_error(); | ||
223 | ret=write(b->num,in,inl); | ||
224 | #endif | ||
225 | BIO_clear_retry_flags(b); | ||
226 | if (ret <= 0) | ||
227 | { | ||
228 | #ifndef BIO_FD | ||
229 | if (BIO_sock_should_retry(ret)) | ||
230 | #else | ||
231 | if (BIO_fd_should_retry(ret)) | ||
232 | #endif | ||
233 | BIO_set_retry_write(b); | ||
234 | } | ||
235 | return(ret); | ||
236 | } | ||
237 | |||
238 | #ifndef BIO_FD | ||
239 | static long sock_ctrl(BIO *b, int cmd, long num, char *ptr) | ||
240 | #else | ||
241 | static long fd_ctrl(BIO *b, int cmd, long num, char *ptr) | ||
242 | #endif | ||
243 | { | ||
244 | long ret=1; | ||
245 | int *ip; | ||
246 | |||
247 | switch (cmd) | ||
248 | { | ||
249 | case BIO_CTRL_RESET: | ||
250 | num=0; | ||
251 | case BIO_C_FILE_SEEK: | ||
252 | #ifdef BIO_FD | ||
253 | ret=(long)lseek(b->num,num,0); | ||
254 | #else | ||
255 | ret=0; | ||
256 | #endif | ||
257 | break; | ||
258 | case BIO_C_FILE_TELL: | ||
259 | case BIO_CTRL_INFO: | ||
260 | #ifdef BIO_FD | ||
261 | ret=(long)lseek(b->num,0,1); | ||
262 | #else | ||
263 | ret=0; | ||
264 | #endif | ||
265 | break; | ||
266 | case BIO_C_SET_FD: | ||
267 | #ifndef BIO_FD | ||
268 | sock_free(b); | ||
269 | #else | ||
270 | fd_free(b); | ||
271 | #endif | ||
272 | b->num= *((int *)ptr); | ||
273 | b->shutdown=(int)num; | ||
274 | b->init=1; | ||
275 | break; | ||
276 | case BIO_C_GET_FD: | ||
277 | if (b->init) | ||
278 | { | ||
279 | ip=(int *)ptr; | ||
280 | if (ip != NULL) *ip=b->num; | ||
281 | ret=b->num; | ||
282 | } | ||
283 | else | ||
284 | ret= -1; | ||
285 | break; | ||
286 | case BIO_CTRL_GET_CLOSE: | ||
287 | ret=b->shutdown; | ||
288 | break; | ||
289 | case BIO_CTRL_SET_CLOSE: | ||
290 | b->shutdown=(int)num; | ||
291 | break; | ||
292 | case BIO_CTRL_PENDING: | ||
293 | case BIO_CTRL_WPENDING: | ||
294 | ret=0; | ||
295 | break; | ||
296 | case BIO_CTRL_DUP: | ||
297 | case BIO_CTRL_FLUSH: | ||
298 | ret=1; | ||
299 | break; | ||
300 | default: | ||
301 | ret=0; | ||
302 | break; | ||
303 | } | ||
304 | return(ret); | ||
305 | } | ||
306 | |||
307 | #ifdef undef | ||
308 | static int sock_gets(BIO *bp, char *buf,int size) | ||
309 | { | ||
310 | return(-1); | ||
311 | } | ||
312 | #endif | ||
313 | |||
314 | #ifndef BIO_FD | ||
315 | static int sock_puts(BIO *bp, char *str) | ||
316 | #else | ||
317 | static int fd_puts(BIO *bp, char *str) | ||
318 | #endif | ||
319 | { | ||
320 | int n,ret; | ||
321 | |||
322 | n=strlen(str); | ||
323 | #ifndef BIO_FD | ||
324 | ret=sock_write(bp,str,n); | ||
325 | #else | ||
326 | ret=fd_write(bp,str,n); | ||
327 | #endif | ||
328 | return(ret); | ||
329 | } | ||
330 | |||
331 | #ifndef BIO_FD | ||
332 | int BIO_sock_should_retry(int i) | ||
333 | #else | ||
334 | int BIO_fd_should_retry(int i) | ||
335 | #endif | ||
336 | { | ||
337 | int err; | ||
338 | |||
339 | if ((i == 0) || (i == -1)) | ||
340 | { | ||
341 | #ifndef BIO_FD | ||
342 | err=get_last_socket_error(); | ||
343 | #else | ||
344 | err=get_last_sys_error(); | ||
345 | #endif | ||
346 | |||
347 | #if defined(WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */ | ||
348 | if ((i == -1) && (err == 0)) | ||
349 | return(1); | ||
350 | #endif | ||
351 | |||
352 | #ifndef BIO_FD | ||
353 | return(BIO_sock_non_fatal_error(err)); | ||
354 | #else | ||
355 | return(BIO_fd_non_fatal_error(err)); | ||
356 | #endif | ||
357 | } | ||
358 | return(0); | ||
359 | } | ||
360 | |||
361 | #ifndef BIO_FD | ||
362 | int BIO_sock_non_fatal_error(int err) | ||
363 | #else | ||
364 | int BIO_fd_non_fatal_error(int err) | ||
365 | #endif | ||
366 | { | ||
367 | switch (err) | ||
368 | { | ||
369 | #if !defined(BIO_FD) && defined(WINDOWS) | ||
370 | # if defined(WSAEWOULDBLOCK) | ||
371 | case WSAEWOULDBLOCK: | ||
372 | # endif | ||
373 | |||
374 | # if 0 /* This appears to always be an error */ | ||
375 | # if defined(WSAENOTCONN) | ||
376 | case WSAENOTCONN: | ||
377 | # endif | ||
378 | # endif | ||
379 | #endif | ||
380 | |||
381 | #ifdef EWOULDBLOCK | ||
382 | # ifdef WSAEWOULDBLOCK | ||
383 | # if WSAEWOULDBLOCK != EWOULDBLOCK | ||
384 | case EWOULDBLOCK: | ||
385 | # endif | ||
386 | # else | ||
387 | case EWOULDBLOCK: | ||
388 | # endif | ||
389 | #endif | ||
390 | |||
391 | #if defined(ENOTCONN) | ||
392 | case ENOTCONN: | ||
393 | #endif | ||
394 | |||
395 | #ifdef EINTR | ||
396 | case EINTR: | ||
397 | #endif | ||
398 | |||
399 | #ifdef EAGAIN | ||
400 | #if EWOULDBLOCK != EAGAIN | ||
401 | case EAGAIN: | ||
402 | # endif | ||
403 | #endif | ||
404 | |||
405 | #ifdef EPROTO | ||
406 | case EPROTO: | ||
407 | #endif | ||
408 | |||
409 | #ifdef EINPROGRESS | ||
410 | case EINPROGRESS: | ||
411 | #endif | ||
412 | |||
413 | #ifdef EALREADY | ||
414 | case EALREADY: | ||
415 | #endif | ||
416 | return(1); | ||
417 | /* break; */ | ||
418 | default: | ||
419 | break; | ||
420 | } | ||
421 | return(0); | ||
422 | } | ||
423 | #endif | ||