diff options
author | 2014-04-13 23:31:36 +0000 | |
---|---|---|
committer | 2014-04-13 23:31:36 +0000 | |
commit | 9ee38ff1a26b740c31575c2d831852c20a6cf75f (patch) | |
tree | 6e07d809c567255896d58f75eb645a07412f94af /lib/libssl/src/apps | |
parent | compress code by turning four line comments into one line comments. (diff) | |
download | wireguard-openbsd-9ee38ff1a26b740c31575c2d831852c20a6cf75f.tar.xz wireguard-openbsd-9ee38ff1a26b740c31575c2d831852c20a6cf75f.zip |
Remove various horrible socket syscall wrappers, especially SHUTDOWN*
which did shutdown + close, all nasty and surprising. Use the raw
syscalls that everyone knows the behaviour of.
ok beck matthew
Diffstat (limited to 'lib/libssl/src/apps')
-rw-r--r-- | lib/libssl/src/apps/s_client.c | 22 | ||||
-rw-r--r-- | lib/libssl/src/apps/s_server.c | 12 | ||||
-rw-r--r-- | lib/libssl/src/apps/s_socket.c | 21 | ||||
-rw-r--r-- | lib/libssl/src/apps/s_time.c | 12 |
4 files changed, 40 insertions, 27 deletions
diff --git a/lib/libssl/src/apps/s_client.c b/lib/libssl/src/apps/s_client.c index 7559dfc113e..f7885ad21d2 100644 --- a/lib/libssl/src/apps/s_client.c +++ b/lib/libssl/src/apps/s_client.c @@ -1272,8 +1272,9 @@ re_start: if (init_client(&s,host,port,socket_type,af) == 0) { - BIO_printf(bio_err,"connect:errno=%d\n",get_last_socket_error()); - SHUTDOWN(s); + BIO_printf(bio_err,"connect:errno=%d\n",errno); + shutdown(s, SHUT_RD); + close(s); goto end; } BIO_printf(bio_c_out,"CONNECTED(%08X)\n",s); @@ -1299,8 +1300,9 @@ re_start: if (getsockname(s, &peer, (void *)&peerlen) < 0) { BIO_printf(bio_err, "getsockname:errno=%d\n", - get_last_socket_error()); - SHUTDOWN(s); + errno); + shutdown(s, SHUT_RD); + close(s); goto end; } @@ -1567,7 +1569,8 @@ SSL_set_tlsext_status_ids(con, ids); BIO_printf(bio_c_out,"drop connection and then reconnect\n"); SSL_shutdown(con); SSL_set_connect_state(con); - SHUTDOWN(SSL_get_fd(con)); + shutdown(SSL_get_fd(con), SHUT_RD); + close(SSL_get_fd(con)); goto re_start; } } @@ -1663,7 +1666,7 @@ SSL_set_tlsext_status_ids(con, ids); if ( i < 0) { BIO_printf(bio_err,"bad select %d\n", - get_last_socket_error()); + errno); goto shut; /* goto end; */ } @@ -1728,7 +1731,7 @@ SSL_set_tlsext_status_ids(con, ids); if ((k != 0) || (cbuf_len != 0)) { BIO_printf(bio_err,"write:errno=%d\n", - get_last_socket_error()); + errno); goto shut; } else @@ -1812,7 +1815,7 @@ printf("read=%d pending=%d peek=%d\n",k,SSL_pending(con),SSL_peek(con,zbuf,10240 BIO_printf(bio_c_out,"read X BLOCK\n"); break; case SSL_ERROR_SYSCALL: - ret=get_last_socket_error(); + ret=errno; BIO_printf(bio_err,"read:errno=%d\n",ret); goto shut; case SSL_ERROR_ZERO_RETURN: @@ -1905,7 +1908,8 @@ shut: if (in_init) print_stuff(bio_c_out,con,full_log); SSL_shutdown(con); - SHUTDOWN(SSL_get_fd(con)); + shutdown(SSL_get_fd(con), SHUT_RD); + close(SSL_get_fd(con)); end: if (con != NULL) { diff --git a/lib/libssl/src/apps/s_server.c b/lib/libssl/src/apps/s_server.c index a36b1a3ad6a..15070a44c17 100644 --- a/lib/libssl/src/apps/s_server.c +++ b/lib/libssl/src/apps/s_server.c @@ -2182,7 +2182,8 @@ static int sv_body(char *hostname, int s, unsigned char *context) if ((i <= 0) || (buf[0] == 'Q')) { BIO_printf(bio_s_out,"DONE\n"); - SHUTDOWN(s); + shutdown(s, SHUT_RD); + close(s); close_accept_socket(); ret= -11; goto err; @@ -2190,8 +2191,10 @@ static int sv_body(char *hostname, int s, unsigned char *context) if ((i <= 0) || (buf[0] == 'q')) { BIO_printf(bio_s_out,"DONE\n"); - if (SSL_version(con) != DTLS1_VERSION) - SHUTDOWN(s); + if (SSL_version(con) != DTLS1_VERSION) { + shutdown(s, SHUT_RD); + close(s); + } /* close_accept_socket(); ret= -11;*/ goto err; @@ -2376,7 +2379,8 @@ static void close_accept_socket(void) BIO_printf(bio_err,"shutdown accept socket\n"); if (accept_socket >= 0) { - SHUTDOWN2(accept_socket); + shutdown(accept_socket, SHUT_RDWR); + close(accept_socket); } } diff --git a/lib/libssl/src/apps/s_socket.c b/lib/libssl/src/apps/s_socket.c index 24880a9a08b..8c4421a9304 100644 --- a/lib/libssl/src/apps/s_socket.c +++ b/lib/libssl/src/apps/s_socket.c @@ -258,7 +258,7 @@ int init_client(int *sock, char *host, char *port, int type, int af) for (ai = ai_top; ai != NULL; ai = ai->ai_next) { s=socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); - if (s == INVALID_SOCKET) { continue; } + if (s == -1) { continue; } #ifndef OPENSSL_SYS_MPE if (type == SOCK_STREAM) { @@ -299,7 +299,8 @@ int do_server(int port, int type, int *ret, int (*cb)(char *hostname, int s, uns { if (do_accept(accept_socket,&sock,&name) == 0) { - SHUTDOWN(accept_socket); + shutdown(accept_socket, SHUT_RD); + close(accept_socket); return(0); } } @@ -307,11 +308,14 @@ int do_server(int port, int type, int *ret, int (*cb)(char *hostname, int s, uns sock = accept_socket; i=(*cb)(name,sock, context); if (name != NULL) OPENSSL_free(name); - if (type==SOCK_STREAM) - SHUTDOWN2(sock); + if (type==SOCK_STREAM) { + shutdown(sock, SHUT_RDWR); + close(sock); + } if (i < 0) { - SHUTDOWN2(accept_socket); + shutdown(accept_socket, SHUT_RDWR); + close(accept_socket); return(i); } } @@ -343,7 +347,7 @@ static int init_server_long(int *sock, int port, char *ip, int type) else /* type == SOCK_DGRAM */ s=socket(AF_INET, SOCK_DGRAM,IPPROTO_UDP); - if (s == INVALID_SOCKET) goto err; + if (s == -1) goto err; #if defined SOL_SOCKET && defined SO_REUSEADDR { int j = 1; @@ -365,7 +369,8 @@ static int init_server_long(int *sock, int port, char *ip, int type) err: if ((ret == 0) && (s != -1)) { - SHUTDOWN(s); + shutdown(s, SHUT_RD); + close(s); } return(ret); } @@ -397,7 +402,7 @@ redoit: * have a cast then you can either go for (int *) or (void *). */ ret=accept(acc_sock,(struct sockaddr *)&from,(void *)&len); - if (ret == INVALID_SOCKET) + if (ret == -1) { #if defined(OPENSSL_SYS_WINDOWS) || (defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)) int i; diff --git a/lib/libssl/src/apps/s_time.c b/lib/libssl/src/apps/s_time.c index 6d78afefd2f..8a5e0761f71 100644 --- a/lib/libssl/src/apps/s_time.c +++ b/lib/libssl/src/apps/s_time.c @@ -88,9 +88,6 @@ #undef PROG #define PROG s_time_main -#undef ioctl -#define ioctl ioctlsocket - #define SSL_CONNECT_NAME "localhost:4433" /*#define TEST_CERT "client.pem" */ /* no default cert. */ @@ -424,7 +421,8 @@ int MAIN(int argc, char **argv) #else SSL_shutdown(scon); #endif - SHUTDOWN2(SSL_get_fd(scon)); + shutdown(SSL_get_fd(scon), SHUT_RDWR); + close(SSL_get_fd(scon)); nConn += 1; if (SSL_session_reused(scon)) @@ -478,7 +476,8 @@ next: #else SSL_shutdown(scon); #endif - SHUTDOWN2(SSL_get_fd(scon)); + shutdown(SSL_get_fd(scon), SHUT_RDWR); + close(SSL_get_fd(scon)); nConn = 0; totalTime = 0.0; @@ -517,7 +516,8 @@ next: #else SSL_shutdown(scon); #endif - SHUTDOWN2(SSL_get_fd(scon)); + shutdown(SSL_get_fd(scon), SHUT_RDWR); + close(SSL_get_fd(scon)); nConn += 1; if (SSL_session_reused(scon)) |