diff options
author | Ralf S. Engelschall <rse@openssl.org> | 1998-12-21 11:00:56 +0000 |
---|---|---|
committer | Ralf S. Engelschall <rse@openssl.org> | 1998-12-21 11:00:56 +0000 |
commit | dfeab0689f69c0b4bd3480ffd37a9cacc2f17d9c (patch) | |
tree | 2f74e0cfd76a9e092548a9bf52e579aef984299b /crypto/bio | |
parent | 58964a492275ca9a59a0cd9c8155cb2491b4b909 (diff) |
Import of old SSLeay release: SSLeay 0.9.1b (unreleased)SSLeay
Diffstat (limited to 'crypto/bio')
-rw-r--r-- | crypto/bio/b_sock.c | 121 | ||||
-rw-r--r-- | crypto/bio/bio.err | 53 | ||||
-rw-r--r-- | crypto/bio/bio.h | 94 | ||||
-rw-r--r-- | crypto/bio/bio_err.c | 11 | ||||
-rw-r--r-- | crypto/bio/bio_lib.c | 10 | ||||
-rw-r--r-- | crypto/bio/bss_acpt.c | 56 | ||||
-rw-r--r-- | crypto/bio/bss_conn.c | 62 | ||||
-rw-r--r-- | crypto/bio/bss_file.c | 2 | ||||
-rw-r--r-- | crypto/bio/bss_mem.c | 13 | ||||
-rw-r--r-- | crypto/bio/bss_sock.c | 30 | ||||
-rw-r--r-- | crypto/bio/cd | 0 | ||||
-rw-r--r-- | crypto/bio/fg | 0 | ||||
-rw-r--r-- | crypto/bio/grep | 0 | ||||
-rw-r--r-- | crypto/bio/vi | 0 |
14 files changed, 287 insertions, 165 deletions
diff --git a/crypto/bio/b_sock.c b/crypto/bio/b_sock.c index a45909527c..2c36150b9b 100644 --- a/crypto/bio/b_sock.c +++ b/crypto/bio/b_sock.c @@ -148,7 +148,7 @@ unsigned char *ip; int BIO_get_port(str,port_ptr) char *str; -short *port_ptr; +unsigned short *port_ptr; { int i; struct servent *s; @@ -223,13 +223,13 @@ char *parg; { case BIO_GHBN_CTRL_HITS: return(BIO_ghbn_hits); - break; + /* break; */ case BIO_GHBN_CTRL_MISSES: return(BIO_ghbn_miss); - break; + /* break; */ case BIO_GHBN_CTRL_CACHE_SIZE: return(GHBN_NUM); - break; + /* break; */ case BIO_GHBN_CTRL_GET_ENTRY: if ((iarg >= 0) && (iarg <GHBN_NUM) && (ghbn_cache[iarg].order > 0)) @@ -241,7 +241,7 @@ char *parg; return(1); } return(0); - break; + /* break; */ case BIO_GHBN_CTRL_FLUSH: for (i=0; i<GHBN_NUM; i++) ghbn_cache[i].order=0; @@ -258,46 +258,51 @@ struct hostent *a; struct hostent *ret; int i,j; - ret=(struct hostent *)malloc(sizeof(struct hostent)); + MemCheck_off(); + ret=(struct hostent *)Malloc(sizeof(struct hostent)); if (ret == NULL) return(NULL); memset(ret,0,sizeof(struct hostent)); for (i=0; a->h_aliases[i] != NULL; i++) ; i++; - ret->h_aliases=(char **)malloc(sizeof(char *)*i); + ret->h_aliases=(char **)Malloc(sizeof(char *)*i); memset(ret->h_aliases,0,sizeof(char *)*i); if (ret == NULL) goto err; for (i=0; a->h_addr_list[i] != NULL; i++) ; i++; - ret->h_addr_list=(char **)malloc(sizeof(char *)*i); + ret->h_addr_list=(char **)Malloc(sizeof(char *)*i); memset(ret->h_addr_list,0,sizeof(char *)*i); if (ret->h_addr_list == NULL) goto err; j=strlen(a->h_name)+1; - if ((ret->h_name=malloc(j)) == NULL) goto err; - memcpy((char *)ret->h_name,a->h_name,j); + if ((ret->h_name=Malloc(j)) == NULL) goto err; + memcpy((char *)ret->h_name,a->h_name,j+1); for (i=0; a->h_aliases[i] != NULL; i++) { j=strlen(a->h_aliases[i])+1; - if ((ret->h_aliases[i]=malloc(j)) == NULL) goto err; - memcpy(ret->h_aliases[i],a->h_aliases[i],j); + if ((ret->h_aliases[i]=Malloc(j)) == NULL) goto err; + memcpy(ret->h_aliases[i],a->h_aliases[i],j+1); } ret->h_length=a->h_length; ret->h_addrtype=a->h_addrtype; for (i=0; a->h_addr_list[i] != NULL; i++) { - if ((ret->h_addr_list[i]=malloc(a->h_length)) == NULL) + if ((ret->h_addr_list[i]=Malloc(a->h_length)) == NULL) goto err; memcpy(ret->h_addr_list[i],a->h_addr_list[i],a->h_length); } - return(ret); + if (0) + { err: - if (ret != NULL) - ghbn_free(ret); - return(NULL); + if (ret != NULL) + ghbn_free(ret); + ret=NULL; + } + MemCheck_on(); + return(ret); } static void ghbn_free(a) @@ -308,17 +313,17 @@ struct hostent *a; if (a->h_aliases != NULL) { for (i=0; a->h_aliases[i] != NULL; i++) - free(a->h_aliases[i]); - free(a->h_aliases); + Free(a->h_aliases[i]); + Free(a->h_aliases); } if (a->h_addr_list != NULL) { for (i=0; a->h_addr_list[i] != NULL; i++) - free(a->h_addr_list[i]); - free(a->h_addr_list); + Free(a->h_addr_list[i]); + Free(a->h_addr_list); } - if (a->h_name != NULL) free((char *)a->h_name); - free(a); + if (a->h_name != NULL) Free((char *)a->h_name); + Free(a); } struct hostent *BIO_gethostbyname(name) @@ -467,16 +472,18 @@ unsigned char ip[4]; return(1); } -int BIO_get_accept_socket(host) +int BIO_get_accept_socket(host,bind_mode) char *host; +int bind_mode; { int ret=0; - struct sockaddr_in server; - int s= -1; + struct sockaddr_in server,client; + int s= -1,cs; unsigned char ip[4]; short port; char *str,*h,*p,*e; unsigned long l; + int err_num; if (!BIO_sock_init()) return(INVALID_SOCKET); @@ -517,12 +524,13 @@ char *host; if (!BIO_get_host_ip(h,&(ip[0]))) return(INVALID_SOCKET); l=(unsigned long) ((unsigned long)ip[0]<<24L)| - ((unsigned long)ip[0]<<16L)| - ((unsigned long)ip[0]<< 8L)| - ((unsigned long)ip[0]); + ((unsigned long)ip[1]<<16L)| + ((unsigned long)ip[2]<< 8L)| + ((unsigned long)ip[3]); server.sin_addr.s_addr=htonl(l); } +again: s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); if (s == INVALID_SOCKET) { @@ -531,9 +539,45 @@ char *host; BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_CREATE_SOCKET); goto err; } + +#ifdef SO_REUSEADDR + if (bind_mode == BIO_BIND_REUSEADDR) + { + int i=1; + + ret=setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&i,sizeof(i)); + bind_mode=BIO_BIND_NORMAL; + } +#endif if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1) { - SYSerr(SYS_F_BIND,get_last_socket_error()); +#ifdef SO_REUSEADDR + err_num=get_last_socket_error(); + if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) && + (err_num == EADDRINUSE)) + { + memcpy((char *)&client,(char *)&server,sizeof(server)); + if (strcmp(h,"*") == 0) + client.sin_addr.s_addr=htonl(0x7F000001); + cs=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); + if (cs != INVALID_SOCKET) + { + int ii; + ii=connect(cs,(struct sockaddr *)&client, + sizeof(client)); + closesocket(cs); + if (ii == INVALID_SOCKET) + { + bind_mode=BIO_BIND_REUSEADDR; + closesocket(s); + goto again; + } + /* else error */ + } + /* else error */ + } +#endif + SYSerr(SYS_F_BIND,err_num); ERR_add_error_data(3,"port='",host,"'"); BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_BIND_SOCKET); goto err; @@ -550,11 +594,7 @@ err: if (str != NULL) Free(str); if ((ret == 0) && (s != INVALID_SOCKET)) { -#ifdef WINDOWS closesocket(s); -#else - close(s); -#endif s= INVALID_SOCKET; } return(s); @@ -626,3 +666,16 @@ int on; } #endif +int BIO_socket_nbio(s,mode) +int s; +int mode; + { + int ret= -1; + unsigned long l; + + l=mode; +#ifdef FIONBIO + ret=BIO_socket_ioctl(s,FIONBIO,&l); +#endif + return(ret == 0); + } diff --git a/crypto/bio/bio.err b/crypto/bio/bio.err index 6e2f2b63ca..daef6430f8 100644 --- a/crypto/bio/bio.err +++ b/crypto/bio/bio.err @@ -3,23 +3,25 @@ /* Function codes. */ #define BIO_F_ACPT_STATE 100 #define BIO_F_BIO_ACCEPT 101 -#define BIO_F_BIO_CTRL 102 -#define BIO_F_BIO_GETS 103 -#define BIO_F_BIO_GET_ACCEPT_SOCKET 104 -#define BIO_F_BIO_GET_HOST_IP 105 -#define BIO_F_BIO_GET_PORT 106 -#define BIO_F_BIO_NEW 107 -#define BIO_F_BIO_NEW_FILE 108 -#define BIO_F_BIO_PUTS 109 -#define BIO_F_BIO_READ 110 -#define BIO_F_BIO_SOCK_INIT 111 -#define BIO_F_BIO_WRITE 112 -#define BIO_F_BUFFER_CTRL 113 -#define BIO_F_CONN_STATE 114 -#define BIO_F_FILE_CTRL 115 -#define BIO_F_MEM_WRITE 116 -#define BIO_F_SSL_NEW 117 -#define BIO_F_WSASTARTUP 118 +#define BIO_F_BIO_BER_GET_HEADER 102 +#define BIO_F_BIO_CTRL 103 +#define BIO_F_BIO_GETS 104 +#define BIO_F_BIO_GET_ACCEPT_SOCKET 105 +#define BIO_F_BIO_GET_HOST_IP 106 +#define BIO_F_BIO_GET_PORT 107 +#define BIO_F_BIO_NEW 108 +#define BIO_F_BIO_NEW_FILE 109 +#define BIO_F_BIO_PUTS 110 +#define BIO_F_BIO_READ 111 +#define BIO_F_BIO_SOCK_INIT 112 +#define BIO_F_BIO_WRITE 113 +#define BIO_F_BUFFER_CTRL 114 +#define BIO_F_CONN_STATE 115 +#define BIO_F_FILE_CTRL 116 +#define BIO_F_MEM_WRITE 117 +#define BIO_F_SOCKS4A_STATE 118 +#define BIO_F_SSL_NEW 119 +#define BIO_F_WSASTARTUP 120 /* Reason codes. */ #define BIO_R_ACCEPT_ERROR 100 @@ -38,9 +40,14 @@ #define BIO_R_NO_PORT_DEFINED 113 #define BIO_R_NO_PORT_SPECIFIED 114 #define BIO_R_NULL_PARAMETER 115 -#define BIO_R_UNABLE_TO_BIND_SOCKET 116 -#define BIO_R_UNABLE_TO_CREATE_SOCKET 117 -#define BIO_R_UNABLE_TO_LISTEN_SOCKET 118 -#define BIO_R_UNINITALISED 119 -#define BIO_R_UNSUPPORTED_METHOD 120 -#define BIO_R_WSASTARTUP 121 +#define BIO_R_SOCKS_ID_AND_IDENT_DID_NOT_MATCH 116 +#define BIO_R_SOCKS_REJECTED_CONNECTION 117 +#define BIO_R_SOCKS_UNABLE_TO_TALK_TO_IDENT_SERVER 118 +#define BIO_R_SOCKS_UNKNOWN_ERROR 119 +#define BIO_R_TAG_MISMATCH 120 +#define BIO_R_UNABLE_TO_BIND_SOCKET 121 +#define BIO_R_UNABLE_TO_CREATE_SOCKET 122 +#define BIO_R_UNABLE_TO_LISTEN_SOCKET 123 +#define BIO_R_UNINITALISED 124 +#define BIO_R_UNSUPPORTED_METHOD 125 +#define BIO_R_WSASTARTUP 126 diff --git a/crypto/bio/bio.h b/crypto/bio/bio.h index 300b330e00..35db3dffb1 100644 --- a/crypto/bio/bio.h +++ b/crypto/bio/bio.h @@ -84,6 +84,7 @@ extern "C" { #define BIO_TYPE_PROXY_SERVER (15|0x0200) /* server proxy BIO */ #define BIO_TYPE_NBIO_TEST (16|0x0200) /* server proxy BIO */ #define BIO_TYPE_NULL_FILTER (17|0x0200) +#define BIO_TYPE_BER (18|0x0200) /* BER -> bin filter */ #define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */ #define BIO_TYPE_FILTER 0x0200 @@ -276,7 +277,7 @@ typedef struct bio_f_buffer_ctx_struct #define BIO_CONN_S_OK 6 #define BIO_CONN_S_BLOCKED_CONNECT 7 #define BIO_CONN_S_NBIO 8 -#define BIO_CONN_get_param_hostname BIO_ctrl +/*#define BIO_CONN_get_param_hostname BIO_ctrl */ #define BIO_number_read(b) ((b)->num_read) #define BIO_number_written(b) ((b)->num_write) @@ -309,6 +310,14 @@ typedef struct bio_f_buffer_ctx_struct #define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125 #define BIO_C_GET_SSL_NUM_RENEGOTIATES 126 #define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127 +#define BIO_C_FILE_SEEK 128 +#define BIO_C_GET_CIPHER_CTX 129 +#define BIO_C_SET_BUF_MEM_EOF_RETURN 130/*return end of input value*/ +#define BIO_C_SET_BIND_MODE 131 +#define BIO_C_GET_BIND_MODE 132 +#define BIO_C_FILE_TELL 133 +#define BIO_C_GET_SOCKS 134 +#define BIO_C_SET_SOCKS 135 #define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,(char *)arg) #define BIO_get_app_data(s) BIO_get_ex_data(s,0) @@ -320,7 +329,7 @@ void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), int (*dup_func)(), void (*free_func)()); -/* BIO_s_connect_socket() */ +/* BIO_s_connect() and BIO_s_socks4a_connect() */ #define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name) #define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port) #define BIO_set_conn_ip(b,ip) BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)ip) @@ -328,7 +337,8 @@ int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), #define BIO_get_conn_hostname(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0) #define BIO_get_conn_port(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1) #define BIO_get_conn_ip(b,ip) BIO_ptr_ctrl(b,BIO_C_SET_CONNECT,2) -#define BIO_get_conn_int port(b,port) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,port) +#define BIO_get_conn_int_port(b,port) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,port) + #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) @@ -339,6 +349,12 @@ int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), #define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?"a":NULL) #define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio) +#define BIO_BIND_NORMAL 0 +#define BIO_BIND_REUSEADDR_IF_UNUSED 1 +#define BIO_BIND_REUSEADDR 2 +#define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL) +#define BIO_get_bind_mode(b,mode) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL) + #define BIO_do_connect(b) BIO_do_handshake(b) #define BIO_do_accept(b) BIO_do_handshake(b) #define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL) @@ -364,12 +380,17 @@ int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), #define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp) #define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp) +#define BIO_seek(b,ofs) (int)BIO_ctrl(b,BIO_C_FILE_SEEK,ofs,NULL) +#define BIO_tell(b) (int)BIO_ctrl(b,BIO_C_FILE_TELL,0,NULL) + #define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ BIO_CLOSE|BIO_FP_READ,name) #define BIO_write_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ BIO_CLOSE|BIO_FP_WRITE,name) #define BIO_append_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ BIO_CLOSE|BIO_FP_APPEND,name) +#define BIO_rw_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ + BIO_CLOSE|BIO_FP_READ|BIO_FP_WRITE,name) /* WARNING WARNING, this ups the reference count on the read bio of the * SSL structure. This is because the ssl read BIO is now pointed to by @@ -388,8 +409,11 @@ int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), /* defined in evp.h */ /* #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,1,(char *)md) */ +#define BIO_get_mem_data(b,pp) BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)pp) #define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)bm) #define BIO_get_mem_ptr(b,pp) BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0,(char *)pp) +#define BIO_set_mem_eof_return(b,v) \ + BIO_ctrl(b,BIO_C_SET_BUF_MEM_EOF_RETURN,v,NULL) /* For the BIO_f_buffer() type */ #define BIO_get_buffer_num_lines(b) BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL) @@ -486,8 +510,9 @@ BIO_METHOD *BIO_s_accept(void); BIO_METHOD *BIO_s_fd(void); BIO_METHOD *BIO_s_null(void); BIO_METHOD *BIO_f_null(void); -BIO_METHOD *BIO_f_nbio_test(void); BIO_METHOD *BIO_f_buffer(void); +BIO_METHOD *BIO_f_nbio_test(void); +/* BIO_METHOD *BIO_f_ber(void); */ int BIO_sock_should_retry(int i); int BIO_sock_non_fatal_error(int error); @@ -498,9 +523,10 @@ int BIO_dump(BIO *b,char *bytes,int len); struct hostent *BIO_gethostbyname(char *name); int BIO_sock_error(int sock); int BIO_socket_ioctl(int fd, long type, unsigned long *arg); -int BIO_get_port(char *str, short *port_ptr); +int BIO_socket_nbio(int fd,int mode); +int BIO_get_port(char *str, unsigned short *port_ptr); int BIO_get_host_ip(char *str, unsigned char *ip); -int BIO_get_accept_socket(char *host_port); +int BIO_get_accept_socket(char *host_port,int mode); int BIO_accept(int sock,char **ip_port); int BIO_sock_init(void ); void BIO_sock_cleanup(void); @@ -552,6 +578,7 @@ BIO_METHOD *BIO_s_null(); BIO_METHOD *BIO_f_null(); BIO_METHOD *BIO_f_buffer(); BIO_METHOD *BIO_f_nbio_test(); +/* BIO_METHOD *BIO_f_ber(); */ int BIO_sock_should_retry(); int BIO_sock_non_fatal_error(); @@ -562,6 +589,7 @@ int BIO_dump(); struct hostent *BIO_gethostbyname(); int BIO_sock_error(); int BIO_socket_ioctl(); +int BIO_socket_nbio(); int BIO_get_port(); int BIO_get_host_ip(); int BIO_get_accept_socket(); @@ -579,7 +607,7 @@ BIO *BIO_new_accept(); void BIO_copy_next_retry(); -int BIO_ghbn_ctrl(); +long BIO_ghbn_ctrl(); #endif @@ -639,23 +667,24 @@ int BIO_printf(); /* Function codes. */ #define BIO_F_ACPT_STATE 100 #define BIO_F_BIO_ACCEPT 101 -#define BIO_F_BIO_CTRL 102 -#define BIO_F_BIO_GETS 103 -#define BIO_F_BIO_GET_ACCEPT_SOCKET 104 -#define BIO_F_BIO_GET_HOST_IP 105 -#define BIO_F_BIO_GET_PORT 106 -#define BIO_F_BIO_NEW 107 -#define BIO_F_BIO_NEW_FILE 108 -#define BIO_F_BIO_PUTS 109 -#define BIO_F_BIO_READ 110 -#define BIO_F_BIO_SOCK_INIT 111 -#define BIO_F_BIO_WRITE 112 -#define BIO_F_BUFFER_CTRL 113 -#define BIO_F_CONN_STATE 114 -#define BIO_F_FILE_CTRL 115 -#define BIO_F_MEM_WRITE 116 -#define BIO_F_SSL_NEW 117 -#define BIO_F_WSASTARTUP 118 +#define BIO_F_BIO_BER_GET_HEADER 102 +#define BIO_F_BIO_CTRL 103 +#define BIO_F_BIO_GETS 104 +#define BIO_F_BIO_GET_ACCEPT_SOCKET 105 +#define BIO_F_BIO_GET_HOST_IP 106 +#define BIO_F_BIO_GET_PORT 107 +#define BIO_F_BIO_NEW 108 +#define BIO_F_BIO_NEW_FILE 109 +#define BIO_F_BIO_PUTS 110 +#define BIO_F_BIO_READ 111 +#define BIO_F_BIO_SOCK_INIT 112 +#define BIO_F_BIO_WRITE 113 +#define BIO_F_BUFFER_CTRL 114 +#define BIO_F_CONN_STATE 115 +#define BIO_F_FILE_CTRL 116 +#define BIO_F_MEM_WRITE 117 +#define BIO_F_SSL_NEW 119 +#define BIO_F_WSASTARTUP 120 /* Reason codes. */ #define BIO_R_ACCEPT_ERROR 100 @@ -674,12 +703,17 @@ int BIO_printf(); #define BIO_R_NO_PORT_DEFINED 113 #define BIO_R_NO_PORT_SPECIFIED 114 #define BIO_R_NULL_PARAMETER 115 -#define BIO_R_UNABLE_TO_BIND_SOCKET 116 -#define BIO_R_UNABLE_TO_CREATE_SOCKET 117 -#define BIO_R_UNABLE_TO_LISTEN_SOCKET 118 -#define BIO_R_UNINITALISED 119 -#define BIO_R_UNSUPPORTED_METHOD 120 -#define BIO_R_WSASTARTUP 121 +#define BIO_R_SOCKS_ID_AND_IDENT_DID_NOT_MATCH 116 +#define BIO_R_SOCKS_REJECTED_CONNECTION 117 +#define BIO_R_SOCKS_UNABLE_TO_TALK_TO_IDENT_SERVER 118 +#define BIO_R_SOCKS_UNKNOWN_ERROR 119 +#define BIO_R_TAG_MISMATCH 120 +#define BIO_R_UNABLE_TO_BIND_SOCKET 121 +#define BIO_R_UNABLE_TO_CREATE_SOCKET 122 +#define BIO_R_UNABLE_TO_LISTEN_SOCKET 123 +#define BIO_R_UNINITALISED 124 +#define BIO_R_UNSUPPORTED_METHOD 125 +#define BIO_R_WSASTARTUP 126 #ifdef __cplusplus } diff --git a/crypto/bio/bio_err.c b/crypto/bio/bio_err.c index 37e14ca107..01aac6e582 100644 --- a/crypto/bio/bio_err.c +++ b/crypto/bio/bio_err.c @@ -65,6 +65,7 @@ static ERR_STRING_DATA BIO_str_functs[]= { {ERR_PACK(0,BIO_F_ACPT_STATE,0), "ACPT_STATE"}, {ERR_PACK(0,BIO_F_BIO_ACCEPT,0), "BIO_accept"}, +{ERR_PACK(0,BIO_F_BIO_BER_GET_HEADER,0), "BIO_BER_GET_HEADER"}, {ERR_PACK(0,BIO_F_BIO_CTRL,0), "BIO_ctrl"}, {ERR_PACK(0,BIO_F_BIO_GETS,0), "BIO_gets"}, {ERR_PACK(0,BIO_F_BIO_GET_ACCEPT_SOCKET,0), "BIO_get_accept_socket"}, @@ -80,6 +81,7 @@ static ERR_STRING_DATA BIO_str_functs[]= {ERR_PACK(0,BIO_F_CONN_STATE,0), "CONN_STATE"}, {ERR_PACK(0,BIO_F_FILE_CTRL,0), "FILE_CTRL"}, {ERR_PACK(0,BIO_F_MEM_WRITE,0), "MEM_WRITE"}, +{ERR_PACK(0,BIO_F_SOCKS4A_STATE,0), "SOCKS4A_STATE"}, {ERR_PACK(0,BIO_F_SSL_NEW,0), "SSL_NEW"}, {ERR_PACK(0,BIO_F_WSASTARTUP,0), "WSASTARTUP"}, {0,NULL}, @@ -103,6 +105,11 @@ static ERR_STRING_DATA BIO_str_reasons[]= {BIO_R_NO_PORT_DEFINED ,"no port defined"}, {BIO_R_NO_PORT_SPECIFIED ,"no port specified"}, {BIO_R_NULL_PARAMETER ,"null parameter"}, +{BIO_R_SOCKS_ID_AND_IDENT_DID_NOT_MATCH ,"socks id and ident did not match"}, +{BIO_R_SOCKS_REJECTED_CONNECTION ,"socks rejected connection"}, +{BIO_R_SOCKS_UNABLE_TO_TALK_TO_IDENT_SERVER,"socks unable to talk to ident server"}, +{BIO_R_SOCKS_UNKNOWN_ERROR ,"socks unknown error"}, +{BIO_R_TAG_MISMATCH ,"tag mismatch"}, {BIO_R_UNABLE_TO_BIND_SOCKET ,"unable to bind socket"}, {BIO_R_UNABLE_TO_CREATE_SOCKET ,"unable to create socket"}, {BIO_R_UNABLE_TO_LISTEN_SOCKET ,"unable to listen socket"}, @@ -118,8 +125,8 @@ void ERR_load_BIO_strings() { static int init=1; - if (init); - {; + if (init) + { init=0; #ifndef NO_ERR ERR_load_strings(ERR_LIB_BIO,BIO_str_functs); diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c index 7a66b0892e..bee1f5d2e0 100644 --- a/crypto/bio/bio_lib.c +++ b/crypto/bio/bio_lib.c @@ -167,6 +167,7 @@ int outl; } i=b->method->bread(b,out,outl); + if (i > 0) b->num_read+=(unsigned long)i; if (cb != NULL) @@ -204,9 +205,16 @@ int inl; } i=b->method->bwrite(b,in,inl); + if (i > 0) b->num_write+=(unsigned long)i; - if (cb != NULL) + /* This is evil and not thread safe. If the BIO has been freed, + * we must not call the callback. The only way to be able to + * determine this is the reference count which is now invalid since + * the memory has been free()ed. + */ + if (b->references <= 0) abort(); + if (cb != NULL) /* && (b->references >= 1)) */ i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl, 0L,(long)i); return(i); diff --git a/crypto/bio/bss_acpt.c b/crypto/bio/bss_acpt.c index e49902fa9f..872807d863 100644 --- a/crypto/bio/bss_acpt.c +++ b/crypto/bio/bss_acpt.c @@ -82,6 +82,10 @@ typedef struct bio_accept_st char *addr; int nbio; + /* If 0, it means normal, if 1, do a connect on bind failure, + * and if there is no-one listening, bind with SO_REUSEADDR. + * If 2, always use SO_REUSEADDR. */ + int bind_mode; BIO *bio_chain; } BIO_ACCEPT; @@ -162,6 +166,7 @@ BIO_ACCEPT *BIO_ACCEPT_new() memset(ret,0,sizeof(BIO_ACCEPT)); ret->accept_sock=INVALID_SOCKET; + ret->bind_mode=BIO_BIND_NORMAL; return(ret); } @@ -183,11 +188,7 @@ BIO *bio; if (c->accept_sock != INVALID_SOCKET) { shutdown(c->accept_sock,2); -# ifdef WINDOWS closesocket(c->accept_sock); -# else - close(c->accept_sock); -# endif c->accept_sock=INVALID_SOCKET; bio->num=INVALID_SOCKET; } @@ -217,7 +218,6 @@ BIO *b; BIO_ACCEPT *c; { BIO *bio=NULL,*dbio; - unsigned long l=1; int s= -1; int i; @@ -230,31 +230,24 @@ again: BIOerr(BIO_F_ACPT_STATE,BIO_R_NO_ACCEPT_PORT_SPECIFIED); return(-1); } - s=BIO_get_accept_socket(c->param_addr); + s=BIO_get_accept_socket(c->param_addr,c->bind_mode); if (s == INVALID_SOCKET) return(-1); -#ifdef FIONBIO if (c->accept_nbio) { - i=BIO_socket_ioctl(b->num,FIONBIO,&l); - if (i < 0) + if (!BIO_socket_nbio(s,1)) { -#ifdef WINDOWS closesocket(s); -#else - close(s); -# endif BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET); return(-1); } } -#endif c->accept_sock=s; b->num=s; c->state=ACPT_S_GET_ACCEPT_SOCKET; return(1); - break; + /* break; */ case ACPT_S_GET_ACCEPT_SOCKET: if (b->next_bio != NULL) { @@ -269,17 +262,14 @@ again: BIO_set_callback(bio,BIO_get_callback(b)); BIO_set_callback_arg(bio,BIO_get_callback_arg(b)); -#ifdef FIONBIO if (c->nbio) { - i=BIO_socket_ioctl(i,FIONBIO,&l); - if (i < 0) + if (!BIO_socket_nbio(i,1)) { BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET); goto err; } } -#endif /* If the accept BIO has an bio_chain, we dup it and * put the new socket at the end. */ @@ -298,15 +288,9 @@ err: if (bio != NULL) BIO_free(bio); else if (s >= 0) - { -#ifdef WINDOWS closesocket(s); -#else - close(s); -# endif - } return(0); - break; + /* break; */ case ACPT_S_OK: if (b->next_bio == NULL) { @@ -314,10 +298,10 @@ err: goto again; } return(1); - break; + /* break; */ default: return(0); - break; + /* break; */ } } @@ -417,13 +401,21 @@ char *ptr; case BIO_C_SET_NBIO: data->nbio=(int)num; break; + case BIO_C_SET_FD: + b->init=1; + b->num= *((int *)ptr); + data->accept_sock=b->num; + data->state=ACPT_S_GET_ACCEPT_SOCKET; + b->shutdown=(int)num; + b->init=1; + break; case BIO_C_GET_FD: if (b->init) { ip=(int *)ptr; if (ip != NULL) *ip=data->accept_sock; - ret=b->num; + ret=data->accept_sock; } else ret= -1; @@ -454,6 +446,12 @@ char *ptr; break; case BIO_CTRL_FLUSH: break; + case BIO_C_SET_BIND_MODE: + data->bind_mode=(int)num; + break; + case BIO_C_GET_BIND_MODE: + ret=(long)data->bind_mode; + break; case BIO_CTRL_DUP: dbio=(BIO *)ptr; /* if (data->param_port) EAY EAY diff --git a/crypto/bio/bss_conn.c b/crypto/bio/bss_conn.c index 6e547bf866..3ec1388f2e 100644 --- a/crypto/bio/bss_conn.c +++ b/crypto/bio/bss_conn.c @@ -81,13 +81,12 @@ typedef struct bio_connect_st int nbio; unsigned char ip[4]; - short port; + unsigned short port; struct sockaddr_in them; /* int socket; this will be kept in bio->num so that it is * compatable with the bss_sock bio */ - int error; /* called when the connection is initially made * callback(BIO,state,ret); The callback should return @@ -187,7 +186,7 @@ BIO_CONNECT *c; } } - if (p == NULL) + if (c->param_port == NULL) { BIOerr(BIO_F_CONN_STATE,BIO_R_NO_PORT_SPECIFIED); ERR_add_error_data(2,"host=",c->param_hostname); @@ -203,7 +202,12 @@ BIO_CONNECT *c; break; case BIO_CONN_S_GET_PORT: - if (BIO_get_port(c->param_port,&c->port) <= 0) + if (c->param_port == NULL) + { + abort(); + goto exit_loop; + } + else if (BIO_get_port(c->param_port,&c->port) <= 0) goto exit_loop; c->state=BIO_CONN_S_CREATE_SOCKET; break; @@ -235,12 +239,9 @@ BIO_CONNECT *c; break; case BIO_CONN_S_NBIO: -#ifdef FIONBIO if (c->nbio) { - l=1; - ret=BIO_socket_ioctl(b->num,FIONBIO,&l); - if (ret < 0) + if (!BIO_socket_nbio(b->num,1)) { BIOerr(BIO_F_CONN_STATE,BIO_R_ERROR_SETTING_NBIO); ERR_add_error_data(4,"host=", @@ -249,7 +250,6 @@ BIO_CONNECT *c; goto exit_loop; } } -#endif c->state=BIO_CONN_S_CONNECT; #ifdef SO_KEEPALIVE @@ -326,12 +326,10 @@ BIO_CONNECT *c; } } - if (1) - { + /* Loop does not exit */ exit_loop: - if (cb != NULL) - ret=cb((BIO *)b,c->state,ret); - } + if (cb != NULL) + ret=cb((BIO *)b,c->state,ret); end: return(ret); } @@ -353,7 +351,6 @@ BIO_CONNECT *BIO_CONNECT_new() ret->ip[3]=0; ret->port=0; memset((char *)&ret->them,0,sizeof(ret->them)); - ret->error=0; return(ret); } @@ -395,11 +392,7 @@ BIO *bio; /* Only do a shutdown if things were established */ if (c->state == BIO_CONN_S_OK) shutdown(bio->num,2); -# ifdef WINDOWS closesocket(bio->num); -# else - close(bio->num); -# endif bio->num=INVALID_SOCKET; } } @@ -442,11 +435,7 @@ int outl; if (out != NULL) { clear_socket_error(); -#if defined(WINDOWS) - ret=recv(b->num,out,outl,0); -#else - ret=read(b->num,out,outl); -#endif + ret=readsocket(b->num,out,outl); BIO_clear_retry_flags(b); if (ret <= 0) { @@ -473,11 +462,7 @@ int inl; } clear_socket_error(); -#if defined(WINDOWS) - ret=send(b->num,in,inl,0); -#else - ret=write(b->num,in,inl); -#endif + ret=writesocket(b->num,in,inl); BIO_clear_retry_flags(b); if (ret <= 0) { @@ -559,9 +544,26 @@ char *ptr; data->param_port=BUF_strdup(ptr); } else if (num == 2) - memcpy(data->ip,ptr,4); + { + char buf[16]; + + sprintf(buf,"%d.%d.%d.%d", + ptr[0],ptr[1],ptr[2],ptr[3]); + if (data->param_hostname != NULL) + Free(data->param_hostname); + data->param_hostname=BUF_strdup(buf); + memcpy(&(data->ip[0]),ptr,4); + } else if (num == 3) + { + char buf[16]; + + sprintf(buf,"%d",*(int *)ptr); + if (data->param_port != NULL) + Free(data->param_port); + data->param_port=BUF_strdup(buf); data->port= *(int *)ptr; + } } break; case BIO_C_SET_NBIO: diff --git a/crypto/bio/bss_file.c b/crypto/bio/bss_file.c index 1484cf849e..5068a7ca0d 100644 --- a/crypto/bio/bss_file.c +++ b/crypto/bio/bss_file.c @@ -214,12 +214,14 @@ char *ptr; switch (cmd) { + case BIO_C_FILE_SEEK: case BIO_CTRL_RESET: ret=(long)fseek(fp,num,0); break; case BIO_CTRL_EOF: ret=(long)feof(fp); break; + case BIO_C_FILE_TELL: case BIO_CTRL_INFO: ret=ftell(fp); break; diff --git a/crypto/bio/bss_mem.c b/crypto/bio/bss_mem.c index 40c4e39f02..8a2efb938c 100644 --- a/crypto/bio/bss_mem.c +++ b/crypto/bio/bss_mem.c @@ -92,6 +92,9 @@ static BIO_METHOD mem_method= mem_free, }; +/* bio->num is used to hold the value to return on 'empty', if it is + * 0, should_retry is not set */ + BIO_METHOD *BIO_s_mem() { return(&mem_method); @@ -106,7 +109,7 @@ BIO *bi; return(0); bi->shutdown=1; bi->init=1; - bi->num=0; + bi->num= -1; bi->ptr=(char *)b; return(1); } @@ -151,8 +154,9 @@ int outl; } else if (bm->length == 0) { - BIO_set_retry_read(b); - ret= -1; + if (b->num != 0) + BIO_set_retry_read(b); + ret= b->num; } return(ret); } @@ -204,6 +208,9 @@ char *ptr; case BIO_CTRL_EOF: ret=(long)(bm->length == 0); break; + case BIO_C_SET_BUF_MEM_EOF_RETURN: + b->num=(int)num; + break; case BIO_CTRL_INFO: ret=(long)bm->length; if (ptr != NULL) diff --git a/crypto/bio/bss_sock.c b/crypto/bio/bss_sock.c index d907a2867b..a664377d |