diff options
Diffstat (limited to 'src/lib/libcrypto/bio/bss_conn.c')
-rw-r--r-- | src/lib/libcrypto/bio/bss_conn.c | 146 |
1 files changed, 58 insertions, 88 deletions
diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c index 6e547bf866..68c46e3d69 100644 --- a/src/lib/libcrypto/bio/bss_conn.c +++ b/src/lib/libcrypto/bio/bss_conn.c | |||
@@ -62,9 +62,7 @@ | |||
62 | #include <errno.h> | 62 | #include <errno.h> |
63 | #define USE_SOCKETS | 63 | #define USE_SOCKETS |
64 | #include "cryptlib.h" | 64 | #include "cryptlib.h" |
65 | #include "bio.h" | 65 | #include <openssl/bio.h> |
66 | |||
67 | /* BIOerr(BIO_F_WSASTARTUP,BIO_R_WSASTARTUP ); */ | ||
68 | 66 | ||
69 | #ifdef WIN16 | 67 | #ifdef WIN16 |
70 | #define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ | 68 | #define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ |
@@ -72,6 +70,12 @@ | |||
72 | #define SOCKET_PROTOCOL IPPROTO_TCP | 70 | #define SOCKET_PROTOCOL IPPROTO_TCP |
73 | #endif | 71 | #endif |
74 | 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 | |||
75 | typedef struct bio_connect_st | 79 | typedef struct bio_connect_st |
76 | { | 80 | { |
77 | int state; | 81 | int state; |
@@ -81,13 +85,12 @@ typedef struct bio_connect_st | |||
81 | int nbio; | 85 | int nbio; |
82 | 86 | ||
83 | unsigned char ip[4]; | 87 | unsigned char ip[4]; |
84 | short port; | 88 | unsigned short port; |
85 | 89 | ||
86 | struct sockaddr_in them; | 90 | struct sockaddr_in them; |
87 | 91 | ||
88 | /* int socket; this will be kept in bio->num so that it is | 92 | /* int socket; this will be kept in bio->num so that it is |
89 | * compatable with the bss_sock bio */ | 93 | * compatable with the bss_sock bio */ |
90 | int error; | ||
91 | 94 | ||
92 | /* called when the connection is initially made | 95 | /* called when the connection is initially made |
93 | * callback(BIO,state,ret); The callback should return | 96 | * callback(BIO,state,ret); The callback should return |
@@ -95,38 +98,18 @@ typedef struct bio_connect_st | |||
95 | int (*info_callback)(); | 98 | int (*info_callback)(); |
96 | } BIO_CONNECT; | 99 | } BIO_CONNECT; |
97 | 100 | ||
98 | #ifndef NOPROTO | ||
99 | static int conn_write(BIO *h,char *buf,int num); | 101 | static int conn_write(BIO *h,char *buf,int num); |
100 | static int conn_read(BIO *h,char *buf,int size); | 102 | static int conn_read(BIO *h,char *buf,int size); |
101 | static int conn_puts(BIO *h,char *str); | 103 | static int conn_puts(BIO *h,char *str); |
102 | static long conn_ctrl(BIO *h,int cmd,long arg1,char *arg2); | 104 | static long conn_ctrl(BIO *h,int cmd,long arg1,char *arg2); |
103 | static int conn_new(BIO *h); | 105 | static int conn_new(BIO *h); |
104 | static int conn_free(BIO *data); | 106 | static int conn_free(BIO *data); |
105 | #else | ||
106 | static int conn_write(); | ||
107 | static int conn_read(); | ||
108 | static int conn_puts(); | ||
109 | static long conn_ctrl(); | ||
110 | static int conn_new(); | ||
111 | static int conn_free(); | ||
112 | #endif | ||
113 | |||
114 | #ifndef NOPROTO | ||
115 | 107 | ||
116 | static int conn_state(BIO *b, BIO_CONNECT *c); | 108 | static int conn_state(BIO *b, BIO_CONNECT *c); |
117 | static void conn_close_socket(BIO *data); | 109 | static void conn_close_socket(BIO *data); |
118 | BIO_CONNECT *BIO_CONNECT_new(void ); | 110 | BIO_CONNECT *BIO_CONNECT_new(void ); |
119 | void BIO_CONNECT_free(BIO_CONNECT *a); | 111 | void BIO_CONNECT_free(BIO_CONNECT *a); |
120 | 112 | ||
121 | #else | ||
122 | |||
123 | static int conn_state(); | ||
124 | static void conn_close_socket(); | ||
125 | BIO_CONNECT *BIO_CONNECT_new(); | ||
126 | void BIO_CONNECT_free(); | ||
127 | |||
128 | #endif | ||
129 | |||
130 | static BIO_METHOD methods_connectp= | 113 | static BIO_METHOD methods_connectp= |
131 | { | 114 | { |
132 | BIO_TYPE_CONNECT, | 115 | BIO_TYPE_CONNECT, |
@@ -140,9 +123,7 @@ static BIO_METHOD methods_connectp= | |||
140 | conn_free, | 123 | conn_free, |
141 | }; | 124 | }; |
142 | 125 | ||
143 | static int conn_state(b,c) | 126 | static int conn_state(BIO *b, BIO_CONNECT *c) |
144 | BIO *b; | ||
145 | BIO_CONNECT *c; | ||
146 | { | 127 | { |
147 | int ret= -1,i; | 128 | int ret= -1,i; |
148 | unsigned long l; | 129 | unsigned long l; |
@@ -160,7 +141,7 @@ BIO_CONNECT *c; | |||
160 | p=c->param_hostname; | 141 | p=c->param_hostname; |
161 | if (p == NULL) | 142 | if (p == NULL) |
162 | { | 143 | { |
163 | BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTHNAME_SPECIFIED); | 144 | BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTNAME_SPECIFIED); |
164 | goto exit_loop; | 145 | goto exit_loop; |
165 | } | 146 | } |
166 | for ( ; *p != '\0'; p++) | 147 | for ( ; *p != '\0'; p++) |
@@ -187,7 +168,7 @@ BIO_CONNECT *c; | |||
187 | } | 168 | } |
188 | } | 169 | } |
189 | 170 | ||
190 | if (p == NULL) | 171 | if (c->param_port == NULL) |
191 | { | 172 | { |
192 | BIOerr(BIO_F_CONN_STATE,BIO_R_NO_PORT_SPECIFIED); | 173 | BIOerr(BIO_F_CONN_STATE,BIO_R_NO_PORT_SPECIFIED); |
193 | ERR_add_error_data(2,"host=",c->param_hostname); | 174 | ERR_add_error_data(2,"host=",c->param_hostname); |
@@ -203,7 +184,12 @@ BIO_CONNECT *c; | |||
203 | break; | 184 | break; |
204 | 185 | ||
205 | case BIO_CONN_S_GET_PORT: | 186 | case BIO_CONN_S_GET_PORT: |
206 | if (BIO_get_port(c->param_port,&c->port) <= 0) | 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) | ||
207 | goto exit_loop; | 193 | goto exit_loop; |
208 | c->state=BIO_CONN_S_CREATE_SOCKET; | 194 | c->state=BIO_CONN_S_CREATE_SOCKET; |
209 | break; | 195 | break; |
@@ -235,12 +221,9 @@ BIO_CONNECT *c; | |||
235 | break; | 221 | break; |
236 | 222 | ||
237 | case BIO_CONN_S_NBIO: | 223 | case BIO_CONN_S_NBIO: |
238 | #ifdef FIONBIO | ||
239 | if (c->nbio) | 224 | if (c->nbio) |
240 | { | 225 | { |
241 | l=1; | 226 | if (!BIO_socket_nbio(b->num,1)) |
242 | ret=BIO_socket_ioctl(b->num,FIONBIO,&l); | ||
243 | if (ret < 0) | ||
244 | { | 227 | { |
245 | BIOerr(BIO_F_CONN_STATE,BIO_R_ERROR_SETTING_NBIO); | 228 | BIOerr(BIO_F_CONN_STATE,BIO_R_ERROR_SETTING_NBIO); |
246 | ERR_add_error_data(4,"host=", | 229 | ERR_add_error_data(4,"host=", |
@@ -249,7 +232,6 @@ BIO_CONNECT *c; | |||
249 | goto exit_loop; | 232 | goto exit_loop; |
250 | } | 233 | } |
251 | } | 234 | } |
252 | #endif | ||
253 | c->state=BIO_CONN_S_CONNECT; | 235 | c->state=BIO_CONN_S_CONNECT; |
254 | 236 | ||
255 | #ifdef SO_KEEPALIVE | 237 | #ifdef SO_KEEPALIVE |
@@ -326,17 +308,15 @@ BIO_CONNECT *c; | |||
326 | } | 308 | } |
327 | } | 309 | } |
328 | 310 | ||
329 | if (1) | 311 | /* Loop does not exit */ |
330 | { | ||
331 | exit_loop: | 312 | exit_loop: |
332 | if (cb != NULL) | 313 | if (cb != NULL) |
333 | ret=cb((BIO *)b,c->state,ret); | 314 | ret=cb((BIO *)b,c->state,ret); |
334 | } | ||
335 | end: | 315 | end: |
336 | return(ret); | 316 | return(ret); |
337 | } | 317 | } |
338 | 318 | ||
339 | BIO_CONNECT *BIO_CONNECT_new() | 319 | BIO_CONNECT *BIO_CONNECT_new(void) |
340 | { | 320 | { |
341 | BIO_CONNECT *ret; | 321 | BIO_CONNECT *ret; |
342 | 322 | ||
@@ -353,13 +333,14 @@ BIO_CONNECT *BIO_CONNECT_new() | |||
353 | ret->ip[3]=0; | 333 | ret->ip[3]=0; |
354 | ret->port=0; | 334 | ret->port=0; |
355 | memset((char *)&ret->them,0,sizeof(ret->them)); | 335 | memset((char *)&ret->them,0,sizeof(ret->them)); |
356 | ret->error=0; | ||
357 | return(ret); | 336 | return(ret); |
358 | } | 337 | } |
359 | 338 | ||
360 | void BIO_CONNECT_free(a) | 339 | void BIO_CONNECT_free(BIO_CONNECT *a) |
361 | BIO_CONNECT *a; | ||
362 | { | 340 | { |
341 | if(a == NULL) | ||
342 | return; | ||
343 | |||
363 | if (a->param_hostname != NULL) | 344 | if (a->param_hostname != NULL) |
364 | Free(a->param_hostname); | 345 | Free(a->param_hostname); |
365 | if (a->param_port != NULL) | 346 | if (a->param_port != NULL) |
@@ -367,13 +348,12 @@ BIO_CONNECT *a; | |||
367 | Free(a); | 348 | Free(a); |
368 | } | 349 | } |
369 | 350 | ||
370 | BIO_METHOD *BIO_s_connect() | 351 | BIO_METHOD *BIO_s_connect(void) |
371 | { | 352 | { |
372 | return(&methods_connectp); | 353 | return(&methods_connectp); |
373 | } | 354 | } |
374 | 355 | ||
375 | static int conn_new(bi) | 356 | static int conn_new(BIO *bi) |
376 | BIO *bi; | ||
377 | { | 357 | { |
378 | bi->init=0; | 358 | bi->init=0; |
379 | bi->num=INVALID_SOCKET; | 359 | bi->num=INVALID_SOCKET; |
@@ -384,8 +364,7 @@ BIO *bi; | |||
384 | return(1); | 364 | return(1); |
385 | } | 365 | } |
386 | 366 | ||
387 | static void conn_close_socket(bio) | 367 | static void conn_close_socket(BIO *bio) |
388 | BIO *bio; | ||
389 | { | 368 | { |
390 | BIO_CONNECT *c; | 369 | BIO_CONNECT *c; |
391 | 370 | ||
@@ -395,17 +374,12 @@ BIO *bio; | |||
395 | /* Only do a shutdown if things were established */ | 374 | /* Only do a shutdown if things were established */ |
396 | if (c->state == BIO_CONN_S_OK) | 375 | if (c->state == BIO_CONN_S_OK) |
397 | shutdown(bio->num,2); | 376 | shutdown(bio->num,2); |
398 | # ifdef WINDOWS | ||
399 | closesocket(bio->num); | 377 | closesocket(bio->num); |
400 | # else | ||
401 | close(bio->num); | ||
402 | # endif | ||
403 | bio->num=INVALID_SOCKET; | 378 | bio->num=INVALID_SOCKET; |
404 | } | 379 | } |
405 | } | 380 | } |
406 | 381 | ||
407 | static int conn_free(a) | 382 | static int conn_free(BIO *a) |
408 | BIO *a; | ||
409 | { | 383 | { |
410 | BIO_CONNECT *data; | 384 | BIO_CONNECT *data; |
411 | 385 | ||
@@ -423,10 +397,7 @@ BIO *a; | |||
423 | return(1); | 397 | return(1); |
424 | } | 398 | } |
425 | 399 | ||
426 | static int conn_read(b,out,outl) | 400 | static int conn_read(BIO *b, char *out, int outl) |
427 | BIO *b; | ||
428 | char *out; | ||
429 | int outl; | ||
430 | { | 401 | { |
431 | int ret=0; | 402 | int ret=0; |
432 | BIO_CONNECT *data; | 403 | BIO_CONNECT *data; |
@@ -442,11 +413,7 @@ int outl; | |||
442 | if (out != NULL) | 413 | if (out != NULL) |
443 | { | 414 | { |
444 | clear_socket_error(); | 415 | clear_socket_error(); |
445 | #if defined(WINDOWS) | 416 | ret=readsocket(b->num,out,outl); |
446 | ret=recv(b->num,out,outl,0); | ||
447 | #else | ||
448 | ret=read(b->num,out,outl); | ||
449 | #endif | ||
450 | BIO_clear_retry_flags(b); | 417 | BIO_clear_retry_flags(b); |
451 | if (ret <= 0) | 418 | if (ret <= 0) |
452 | { | 419 | { |
@@ -457,10 +424,7 @@ int outl; | |||
457 | return(ret); | 424 | return(ret); |
458 | } | 425 | } |
459 | 426 | ||
460 | static int conn_write(b,in,inl) | 427 | static int conn_write(BIO *b, char *in, int inl) |
461 | BIO *b; | ||
462 | char *in; | ||
463 | int inl; | ||
464 | { | 428 | { |
465 | int ret; | 429 | int ret; |
466 | BIO_CONNECT *data; | 430 | BIO_CONNECT *data; |
@@ -473,11 +437,7 @@ int inl; | |||
473 | } | 437 | } |
474 | 438 | ||
475 | clear_socket_error(); | 439 | clear_socket_error(); |
476 | #if defined(WINDOWS) | 440 | ret=writesocket(b->num,in,inl); |
477 | ret=send(b->num,in,inl,0); | ||
478 | #else | ||
479 | ret=write(b->num,in,inl); | ||
480 | #endif | ||
481 | BIO_clear_retry_flags(b); | 441 | BIO_clear_retry_flags(b); |
482 | if (ret <= 0) | 442 | if (ret <= 0) |
483 | { | 443 | { |
@@ -487,15 +447,11 @@ int inl; | |||
487 | return(ret); | 447 | return(ret); |
488 | } | 448 | } |
489 | 449 | ||
490 | static long conn_ctrl(b,cmd,num,ptr) | 450 | static long conn_ctrl(BIO *b, int cmd, long num, char *ptr) |
491 | BIO *b; | ||
492 | int cmd; | ||
493 | long num; | ||
494 | char *ptr; | ||
495 | { | 451 | { |
496 | BIO *dbio; | 452 | BIO *dbio; |
497 | int *ip; | 453 | int *ip; |
498 | char **pptr; | 454 | const char **pptr; |
499 | long ret=1; | 455 | long ret=1; |
500 | BIO_CONNECT *data; | 456 | BIO_CONNECT *data; |
501 | 457 | ||
@@ -519,7 +475,7 @@ char *ptr; | |||
519 | case BIO_C_GET_CONNECT: | 475 | case BIO_C_GET_CONNECT: |
520 | if (ptr != NULL) | 476 | if (ptr != NULL) |
521 | { | 477 | { |
522 | pptr=(char **)ptr; | 478 | pptr=(const char **)ptr; |
523 | if (num == 0) | 479 | if (num == 0) |
524 | { | 480 | { |
525 | *pptr=data->param_hostname; | 481 | *pptr=data->param_hostname; |
@@ -559,9 +515,26 @@ char *ptr; | |||
559 | data->param_port=BUF_strdup(ptr); | 515 | data->param_port=BUF_strdup(ptr); |
560 | } | 516 | } |
561 | else if (num == 2) | 517 | else if (num == 2) |
562 | memcpy(data->ip,ptr,4); | 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 | } | ||
563 | else if (num == 3) | 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); | ||
564 | data->port= *(int *)ptr; | 536 | data->port= *(int *)ptr; |
537 | } | ||
565 | } | 538 | } |
566 | break; | 539 | break; |
567 | case BIO_C_SET_NBIO: | 540 | case BIO_C_SET_NBIO: |
@@ -597,7 +570,7 @@ char *ptr; | |||
597 | if (data->param_hostname) | 570 | if (data->param_hostname) |
598 | BIO_set_conn_hostname(dbio,data->param_hostname); | 571 | BIO_set_conn_hostname(dbio,data->param_hostname); |
599 | BIO_set_nbio(dbio,data->nbio); | 572 | BIO_set_nbio(dbio,data->nbio); |
600 | BIO_set_info_callback(dbio,data->info_callback); | 573 | (void)BIO_set_info_callback(dbio,data->info_callback); |
601 | break; | 574 | break; |
602 | case BIO_CTRL_SET_CALLBACK: | 575 | case BIO_CTRL_SET_CALLBACK: |
603 | data->info_callback=(int (*)())ptr; | 576 | data->info_callback=(int (*)())ptr; |
@@ -617,9 +590,7 @@ char *ptr; | |||
617 | return(ret); | 590 | return(ret); |
618 | } | 591 | } |
619 | 592 | ||
620 | static int conn_puts(bp,str) | 593 | static int conn_puts(BIO *bp, char *str) |
621 | BIO *bp; | ||
622 | char *str; | ||
623 | { | 594 | { |
624 | int n,ret; | 595 | int n,ret; |
625 | 596 | ||
@@ -628,8 +599,7 @@ char *str; | |||
628 | return(ret); | 599 | return(ret); |
629 | } | 600 | } |
630 | 601 | ||
631 | BIO *BIO_new_connect(str) | 602 | BIO *BIO_new_connect(char *str) |
632 | char *str; | ||
633 | { | 603 | { |
634 | BIO *ret; | 604 | BIO *ret; |
635 | 605 | ||