From 254f85a5c003c6687ea07695373f3770fdbe3832 Mon Sep 17 00:00:00 2001 From: Tomas Mraz Date: Thu, 12 Jul 2012 00:05:11 +0200 Subject: [PATCH] fix s_server with new glibc when no global IPv6 address (#839031) --- ...ps.patch => openssl-1.0.1c-ipv6-apps.patch | 57 ++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-) rename openssl-1.0.1-beta2-ipv6-apps.patch => openssl-1.0.1c-ipv6-apps.patch (88%) diff --git a/openssl-1.0.1-beta2-ipv6-apps.patch b/openssl-1.0.1c-ipv6-apps.patch similarity index 88% rename from openssl-1.0.1-beta2-ipv6-apps.patch rename to openssl-1.0.1c-ipv6-apps.patch index 4e2f60c..41e0b36 100644 --- a/openssl-1.0.1-beta2-ipv6-apps.patch +++ b/openssl-1.0.1c-ipv6-apps.patch @@ -1,6 +1,6 @@ -diff -up openssl-1.0.1-beta2/apps/s_apps.h.ipv6-apps openssl-1.0.1-beta2/apps/s_apps.h ---- openssl-1.0.1-beta2/apps/s_apps.h.ipv6-apps 2012-02-02 12:56:27.216889198 +0100 -+++ openssl-1.0.1-beta2/apps/s_apps.h 2012-02-02 12:56:27.257889552 +0100 +diff -up openssl-1.0.1c/apps/s_apps.h.ipv6-apps openssl-1.0.1c/apps/s_apps.h +--- openssl-1.0.1c/apps/s_apps.h.ipv6-apps 2012-07-11 22:46:02.409221206 +0200 ++++ openssl-1.0.1c/apps/s_apps.h 2012-07-11 22:46:02.451222165 +0200 @@ -148,7 +148,7 @@ typedef fd_mask fd_set; #define PORT_STR "4433" #define PROTOCOL "tcp" @@ -23,9 +23,9 @@ diff -up openssl-1.0.1-beta2/apps/s_apps.h.ipv6-apps openssl-1.0.1-beta2/apps/s_ long MS_CALLBACK bio_dump_callback(BIO *bio, int cmd, const char *argp, int argi, long argl, long ret); -diff -up openssl-1.0.1-beta2/apps/s_client.c.ipv6-apps openssl-1.0.1-beta2/apps/s_client.c ---- openssl-1.0.1-beta2/apps/s_client.c.ipv6-apps 2012-02-02 12:56:27.238889388 +0100 -+++ openssl-1.0.1-beta2/apps/s_client.c 2012-02-02 12:56:27.258889561 +0100 +diff -up openssl-1.0.1c/apps/s_client.c.ipv6-apps openssl-1.0.1c/apps/s_client.c +--- openssl-1.0.1c/apps/s_client.c.ipv6-apps 2012-07-11 22:46:02.433221754 +0200 ++++ openssl-1.0.1c/apps/s_client.c 2012-07-11 22:46:02.452222187 +0200 @@ -563,7 +563,7 @@ int MAIN(int argc, char **argv) int cbuf_len,cbuf_off; int sbuf_len,sbuf_off; @@ -35,7 +35,7 @@ diff -up openssl-1.0.1-beta2/apps/s_client.c.ipv6-apps openssl-1.0.1-beta2/apps/ int full_log=1; char *host=SSL_HOST_NAME; char *cert_file=NULL,*key_file=NULL; -@@ -670,13 +670,12 @@ int MAIN(int argc, char **argv) +@@ -664,13 +664,12 @@ int MAIN(int argc, char **argv) else if (strcmp(*argv,"-port") == 0) { if (--argc < 1) goto bad; @@ -51,7 +51,7 @@ diff -up openssl-1.0.1-beta2/apps/s_client.c.ipv6-apps openssl-1.0.1-beta2/apps/ goto bad; } else if (strcmp(*argv,"-verify") == 0) -@@ -1260,7 +1259,7 @@ bad: +@@ -1253,7 +1252,7 @@ bad: re_start: @@ -60,9 +60,9 @@ diff -up openssl-1.0.1-beta2/apps/s_client.c.ipv6-apps openssl-1.0.1-beta2/apps/ { BIO_printf(bio_err,"connect:errno=%d\n",get_last_socket_error()); SHUTDOWN(s); -diff -up openssl-1.0.1-beta2/apps/s_server.c.ipv6-apps openssl-1.0.1-beta2/apps/s_server.c ---- openssl-1.0.1-beta2/apps/s_server.c.ipv6-apps 2012-02-02 12:56:27.239889397 +0100 -+++ openssl-1.0.1-beta2/apps/s_server.c 2012-02-02 12:56:27.259889570 +0100 +diff -up openssl-1.0.1c/apps/s_server.c.ipv6-apps openssl-1.0.1c/apps/s_server.c +--- openssl-1.0.1c/apps/s_server.c.ipv6-apps 2012-07-11 22:46:02.434221777 +0200 ++++ openssl-1.0.1c/apps/s_server.c 2012-07-11 22:46:02.453222210 +0200 @@ -929,7 +929,7 @@ int MAIN(int argc, char *argv[]) { X509_VERIFY_PARAM *vpm = NULL; @@ -72,7 +72,7 @@ diff -up openssl-1.0.1-beta2/apps/s_server.c.ipv6-apps openssl-1.0.1-beta2/apps/ char *CApath=NULL,*CAfile=NULL; unsigned char *context = NULL; char *dhfile = NULL; -@@ -1010,8 +1010,7 @@ int MAIN(int argc, char *argv[]) +@@ -1000,8 +1000,7 @@ int MAIN(int argc, char *argv[]) (strcmp(*argv,"-accept") == 0)) { if (--argc < 1) goto bad; @@ -82,7 +82,7 @@ diff -up openssl-1.0.1-beta2/apps/s_server.c.ipv6-apps openssl-1.0.1-beta2/apps/ } else if (strcmp(*argv,"-verify") == 0) { -@@ -1888,9 +1887,9 @@ bad: +@@ -1878,9 +1877,9 @@ bad: BIO_printf(bio_s_out,"ACCEPT\n"); (void)BIO_flush(bio_s_out); if (www) @@ -94,9 +94,9 @@ diff -up openssl-1.0.1-beta2/apps/s_server.c.ipv6-apps openssl-1.0.1-beta2/apps/ print_stats(bio_s_out,ctx); ret=0; end: -diff -up openssl-1.0.1-beta2/apps/s_socket.c.ipv6-apps openssl-1.0.1-beta2/apps/s_socket.c ---- openssl-1.0.1-beta2/apps/s_socket.c.ipv6-apps 2011-12-02 15:39:40.000000000 +0100 -+++ openssl-1.0.1-beta2/apps/s_socket.c 2012-01-19 14:53:30.000000000 +0100 +diff -up openssl-1.0.1c/apps/s_socket.c.ipv6-apps openssl-1.0.1c/apps/s_socket.c +--- openssl-1.0.1c/apps/s_socket.c.ipv6-apps 2011-12-02 15:39:40.000000000 +0100 ++++ openssl-1.0.1c/apps/s_socket.c 2012-07-11 22:49:05.411400450 +0200 @@ -102,9 +102,7 @@ static struct hostent *GetHostByName(cha static void ssl_sock_cleanup(void); #endif @@ -216,7 +216,7 @@ diff -up openssl-1.0.1-beta2/apps/s_socket.c.ipv6-apps openssl-1.0.1-beta2/apps/ { int sock; char *name = NULL; -@@ -322,33 +333,45 @@ int do_server(int port, int type, int *r +@@ -322,33 +333,50 @@ int do_server(int port, int type, int *r } } @@ -228,7 +228,7 @@ diff -up openssl-1.0.1-beta2/apps/s_socket.c.ipv6-apps openssl-1.0.1-beta2/apps/ - int s= -1; + struct addrinfo *res, *res0 = NULL, hints; + char * failed_call = NULL; -+ int s; ++ int s = INVALID_SOCKET; + int e; if (!ssl_sock_init()) return(0); @@ -246,10 +246,10 @@ diff -up openssl-1.0.1-beta2/apps/s_socket.c.ipv6-apps openssl-1.0.1-beta2/apps/ - memcpy(&server.sin_addr,ip,4); -#endif + memset(&hints, '\0', sizeof(hints)); -+ hints.ai_family = AF_INET6; ++ hints.ai_family = AF_INET6; +tryipv4: + hints.ai_socktype = type; -+ hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; ++ hints.ai_flags = AI_PASSIVE; - if (type == SOCK_STREAM) - s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); @@ -258,10 +258,15 @@ diff -up openssl-1.0.1-beta2/apps/s_socket.c.ipv6-apps openssl-1.0.1-beta2/apps/ + e = getaddrinfo(NULL, port, &hints, &res); + if (e) + { -+ fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e)); -+ if (e == EAI_SYSTEM) -+ perror("getaddrinfo"); -+ return (0); ++ if (hints.ai_family == AF_INET) ++ { ++ fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e)); ++ if (e == EAI_SYSTEM) ++ perror("getaddrinfo"); ++ return (0); ++ } ++ else ++ res = NULL; + } - if (s == INVALID_SOCKET) goto err; @@ -283,7 +288,7 @@ diff -up openssl-1.0.1-beta2/apps/s_socket.c.ipv6-apps openssl-1.0.1-beta2/apps/ #if defined SOL_SOCKET && defined SO_REUSEADDR { int j = 1; -@@ -356,35 +379,49 @@ static int init_server_long(int *sock, i +@@ -356,35 +384,49 @@ static int init_server_long(int *sock, i (void *) &j, sizeof j); } #endif @@ -350,7 +355,7 @@ diff -up openssl-1.0.1-beta2/apps/s_socket.c.ipv6-apps openssl-1.0.1-beta2/apps/ int len; /* struct linger ling; */ -@@ -431,135 +468,58 @@ redoit: +@@ -431,135 +473,58 @@ redoit: */ if (host == NULL) goto end;