source:
trunk/server/common/patches/openssl-1.0.0n-ipv6-apps.patch
@
2567
Last change on this file since 2567 was 2558, checked in by andersk, 10 years ago | |
---|---|
File size: 13.0 KB |
-
openssl-1.0.0b/apps/s_apps.h
diff -up openssl-1.0.0b/apps/s_apps.h.ipv6-apps openssl-1.0.0b/apps/s_apps.h
old new typedef fd_mask fd_set; 148 148 #define PORT_STR "4433" 149 149 #define PROTOCOL "tcp" 150 150 151 int do_server( intport, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context);151 int do_server(char *port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context); 152 152 #ifdef HEADER_X509_H 153 153 int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx); 154 154 #endif … … int MS_CALLBACK verify_callback(int ok, 156 156 int set_cert_stuff(SSL_CTX *ctx, char *cert_file, char *key_file); 157 157 int set_cert_key_stuff(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key); 158 158 #endif 159 int init_client(int *sock, char *server, intport, int type);159 int init_client(int *sock, char *server, char *port, int type); 160 160 int should_retry(int i); 161 int extract_port(char *str, short *port_ptr); 162 int extract_host_port(char *str,char **host_ptr,unsigned char *ip,short *p); 161 int extract_host_port(char *str,char **host_ptr,char **port_ptr); 163 162 164 163 long MS_CALLBACK bio_dump_callback(BIO *bio, int cmd, const char *argp, 165 164 int argi, long argl, long ret); -
openssl-1.0.0b/apps/s_client.c
diff -up openssl-1.0.0b/apps/s_client.c.ipv6-apps openssl-1.0.0b/apps/s_client.c
old new int MAIN(int argc, char **argv) 389 389 int cbuf_len,cbuf_off; 390 390 int sbuf_len,sbuf_off; 391 391 fd_set readfds,writefds; 392 short port=PORT;392 char *port_str = PORT_STR; 393 393 int full_log=1; 394 394 char *host=SSL_HOST_NAME; 395 395 char *cert_file=NULL,*key_file=NULL; … … int MAIN(int argc, char **argv) 488 488 else if (strcmp(*argv,"-port") == 0) 489 489 { 490 490 if (--argc < 1) goto bad; 491 port=atoi(*(++argv)); 492 if (port == 0) goto bad; 491 port_str= *(++argv); 493 492 } 494 493 else if (strcmp(*argv,"-connect") == 0) 495 494 { 496 495 if (--argc < 1) goto bad; 497 if (!extract_host_port(*(++argv),&host, NULL,&port))496 if (!extract_host_port(*(++argv),&host,&port_str)) 498 497 goto bad; 499 498 } 500 499 else if (strcmp(*argv,"-verify") == 0) … … bad: 967 966 968 967 re_start: 969 968 970 if (init_client(&s,host,port ,socket_type) == 0)969 if (init_client(&s,host,port_str,socket_type) == 0) 971 970 { 972 971 BIO_printf(bio_err,"connect:errno=%d\n",get_last_socket_error()); 973 972 SHUTDOWN(s); -
openssl-1.0.0b/apps/s_server.c
diff -up openssl-1.0.0b/apps/s_server.c.ipv6-apps openssl-1.0.0b/apps/s_server.c
old new int MAIN(int argc, char *argv[]) 838 838 { 839 839 X509_VERIFY_PARAM *vpm = NULL; 840 840 int badarg = 0; 841 short port=PORT;841 char *port_str = PORT_STR; 842 842 char *CApath=NULL,*CAfile=NULL; 843 843 unsigned char *context = NULL; 844 844 char *dhfile = NULL; … … int MAIN(int argc, char *argv[]) 909 909 (strcmp(*argv,"-accept") == 0)) 910 910 { 911 911 if (--argc < 1) goto bad; 912 if (!extract_port(*(++argv),&port)) 913 goto bad; 912 port_str= *(++argv); 914 913 } 915 914 else if (strcmp(*argv,"-verify") == 0) 916 915 { … … bad: 1700 1699 BIO_printf(bio_s_out,"ACCEPT\n"); 1701 1700 (void)BIO_flush(bio_s_out); 1702 1701 if (www) 1703 do_server(port ,socket_type,&accept_socket,www_body, context);1702 do_server(port_str,socket_type,&accept_socket,www_body, context); 1704 1703 else 1705 do_server(port ,socket_type,&accept_socket,sv_body, context);1704 do_server(port_str,socket_type,&accept_socket,sv_body, context); 1706 1705 print_stats(bio_s_out,ctx); 1707 1706 ret=0; 1708 1707 end: -
openssl-1.0.0b/apps/s_socket.c
diff -up openssl-1.0.0b/apps/s_socket.c.ipv6-apps openssl-1.0.0b/apps/s_socket.c
old new static struct hostent *GetHostByName(cha 102 102 static void ssl_sock_cleanup(void); 103 103 #endif 104 104 static int ssl_sock_init(void); 105 static int init_client_ip(int *sock,unsigned char ip[4], int port, int type); 106 static int init_server(int *sock, int port, int type); 107 static int init_server_long(int *sock, int port,char *ip, int type); 105 static int init_server(int *sock, char *port, int type); 108 106 static int do_accept(int acc_sock, int *sock, char **host); 109 107 static int host_ip(char *str, unsigned char ip[4]); 110 108 … … static int ssl_sock_init(void) 234 232 return(1); 235 233 } 236 234 237 int init_client(int *sock, char *host, intport, int type)235 int init_client(int *sock, char *host, char *port, int type) 238 236 { 239 unsigned char ip[4]; 240 241 if (!host_ip(host,&(ip[0]))) 242 { 243 return(0); 244 } 245 return(init_client_ip(sock,ip,port,type)); 246 } 247 248 static int init_client_ip(int *sock, unsigned char ip[4], int port, int type) 249 { 250 unsigned long addr; 251 struct sockaddr_in them; 252 int s,i; 237 struct addrinfo *res, *res0, hints; 238 char * failed_call = NULL; 239 int s; 240 int e; 253 241 254 242 if (!ssl_sock_init()) return(0); 255 243 256 memset((char *)&them,0,sizeof(them)); 257 them.sin_family=AF_INET; 258 them.sin_port=htons((unsigned short)port); 259 addr=(unsigned long) 260 ((unsigned long)ip[0]<<24L)| 261 ((unsigned long)ip[1]<<16L)| 262 ((unsigned long)ip[2]<< 8L)| 263 ((unsigned long)ip[3]); 264 them.sin_addr.s_addr=htonl(addr); 265 266 if (type == SOCK_STREAM) 267 s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); 268 else /* ( type == SOCK_DGRAM) */ 269 s=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP); 270 271 if (s == INVALID_SOCKET) { perror("socket"); return(0); } 244 memset(&hints, '\0', sizeof(hints)); 245 hints.ai_socktype = type; 246 hints.ai_flags = AI_ADDRCONFIG; 247 248 e = getaddrinfo(host, port, &hints, &res); 249 if (e) 250 { 251 fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e)); 252 if (e == EAI_SYSTEM) 253 perror("getaddrinfo"); 254 return (0); 255 } 272 256 257 res0 = res; 258 while (res) 259 { 260 s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); 261 if (s == INVALID_SOCKET) 262 { 263 failed_call = "socket"; 264 goto nextres; 265 } 273 266 #if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE) 274 267 if (type == SOCK_STREAM) 275 268 { 276 i=0; 277 i=setsockopt(s,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i)); 278 if (i < 0) { closesocket(s); perror("keepalive"); return(0); } 269 int i=0; 270 i=setsockopt(s,SOL_SOCKET,SO_KEEPALIVE, 271 (char *)&i,sizeof(i)); 272 if (i < 0) { 273 failed_call = "keepalive"; 274 goto nextres; 275 } 279 276 } 280 277 #endif 281 282 if (connect(s,(struct sockaddr *)&them,sizeof(them)) == -1) 283 { closesocket(s); perror("connect"); return(0); } 278 if (connect(s,(struct sockaddr *)res->ai_addr, 279 res->ai_addrlen) == 0) 280 { 281 freeaddrinfo(res0); 284 282 *sock=s; 285 283 return(1); 286 284 } 287 285 288 int do_server(int port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context) 286 failed_call = "socket"; 287 nextres: 288 if (s != INVALID_SOCKET) 289 close(s); 290 res = res->ai_next; 291 } 292 freeaddrinfo(res0); 293 294 perror(failed_call); 295 return(0); 296 } 297 298 int do_server(char *port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context) 289 299 { 290 300 int sock; 291 301 char *name = NULL; … … int do_server(int port, int type, int *r 323 333 } 324 334 } 325 335 326 static int init_server _long(int *sock, int port, char *ip, int type)336 static int init_server(int *sock, char *port, int type) 327 337 { 328 int ret=0; 329 struct sockaddr_in server; 330 int s= -1; 338 struct addrinfo *res, *res0, hints; 339 char * failed_call = NULL; 340 char port_name[8]; 341 int s; 342 int e; 331 343 332 344 if (!ssl_sock_init()) return(0); 333 345 334 memset((char *)&server,0,sizeof(server)); 335 server.sin_family=AF_INET; 336 server.sin_port=htons((unsigned short)port); 337 if (ip == NULL) 338 server.sin_addr.s_addr=INADDR_ANY; 339 else 340 /* Added for T3E, address-of fails on bit field (beckman@acl.lanl.gov) */ 341 #ifndef BIT_FIELD_LIMITS 342 memcpy(&server.sin_addr.s_addr,ip,4); 343 #else 344 memcpy(&server.sin_addr,ip,4); 345 #endif 346 memset(&hints, '\0', sizeof(hints)); 347 hints.ai_socktype = type; 348 hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; 346 349 347 if (type == SOCK_STREAM) 348 s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); 349 else /* type == SOCK_DGRAM */ 350 s=socket(AF_INET, SOCK_DGRAM,IPPROTO_UDP); 350 e = getaddrinfo(NULL, port, &hints, &res); 351 if (e) 352 { 353 fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e)); 354 if (e == EAI_SYSTEM) 355 perror("getaddrinfo"); 356 return (0); 357 } 351 358 352 if (s == INVALID_SOCKET) goto err; 359 res0 = res; 360 while (res) 361 { 362 s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); 363 if (s == INVALID_SOCKET) 364 { 365 failed_call = "socket"; 366 goto nextres; 367 } 353 368 #if defined SOL_SOCKET && defined SO_REUSEADDR 354 369 { 355 370 int j = 1; … … static int init_server_long(int *sock, i 357 372 (void *) &j, sizeof j); 358 373 } 359 374 #endif 360 if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1) 375 376 if (bind(s,(struct sockaddr *)res->ai_addr, res->ai_addrlen) == -1) 361 377 { 362 #ifndef OPENSSL_SYS_WINDOWS 363 perror("bind"); 364 #endif 365 goto err; 378 failed_call = "bind"; 379 goto nextres; 366 380 } 367 /* Make it 128 for linux */ 368 if (type==SOCK_STREAM && listen(s,128) == -1) goto err; 369 *sock=s; 370 ret=1; 371 err: 372 if ((ret == 0) && (s != -1)) 381 if (type==SOCK_STREAM && listen(s,128) == -1) 373 382 { 374 SHUTDOWN(s); 383 failed_call = "listen"; 384 goto nextres; 375 385 } 376 return(ret); 386 387 *sock=s; 388 return(1); 389 390 nextres: 391 if (s != INVALID_SOCKET) 392 close(s); 393 res = res->ai_next; 377 394 } 395 freeaddrinfo(res0); 378 396 379 static int init_server(int *sock, int port, int type) 380 { 381 return(init_server_long(sock, port, NULL, type)); 397 if (s == INVALID_SOCKET) { perror("socket"); return(0); } 398 399 perror(failed_call); 400 return(0); 382 401 } 383 402 384 403 static int do_accept(int acc_sock, int *sock, char **host) 385 404 { 405 static struct sockaddr_storage from; 406 char buffer[NI_MAXHOST]; 386 407 int ret; 387 struct hostent *h1,*h2;388 static struct sockaddr_in from;389 408 int len; 390 409 /* struct linger ling; */ 391 410 … … redoit: 432 451 */ 433 452 434 453 if (host == NULL) goto end; 435 #ifndef BIT_FIELD_LIMITS 436 /* I should use WSAAsyncGetHostByName() under windows */ 437 h1=gethostbyaddr((char *)&from.sin_addr.s_addr, 438 sizeof(from.sin_addr.s_addr),AF_INET); 439 #else 440 h1=gethostbyaddr((char *)&from.sin_addr, 441 sizeof(struct in_addr),AF_INET); 442 #endif 443 if (h1 == NULL) 454 455 if (getnameinfo((struct sockaddr *)&from, sizeof(from), 456 buffer, sizeof(buffer), 457 NULL, 0, 0)) 444 458 { 445 BIO_printf(bio_err," bad gethostbyaddr\n");459 BIO_printf(bio_err,"getnameinfo failed\n"); 446 460 *host=NULL; 447 461 /* return(0); */ 448 462 } 449 463 else 450 464 { 451 if ((*host=(char *)OPENSSL_malloc(strlen( h1->h_name)+1)) == NULL)465 if ((*host=(char *)OPENSSL_malloc(strlen(buffer)+1)) == NULL) 452 466 { 453 467 perror("OPENSSL_malloc"); 454 468 closesocket(ret); 455 469 return(0); 456 470 } 457 BUF_strlcpy(*host,h1->h_name,strlen(h1->h_name)+1); 458 459 h2=GetHostByName(*host); 460 if (h2 == NULL) 461 { 462 BIO_printf(bio_err,"gethostbyname failure\n"); 463 closesocket(ret); 464 return(0); 465 } 466 if (h2->h_addrtype != AF_INET) 467 { 468 BIO_printf(bio_err,"gethostbyname addr is not AF_INET\n"); 469 closesocket(ret); 470 return(0); 471 } 471 strcpy(*host, buffer); 472 472 } 473 473 end: 474 474 *sock=ret; 475 475 return(1); 476 476 } 477 477 478 int extract_host_port(char *str, char **host_ptr, unsigned char *ip,479 short*port_ptr)478 int extract_host_port(char *str, char **host_ptr, 479 char **port_ptr) 480 480 { 481 char *h,*p ;481 char *h,*p,*x; 482 482 483 h=str; 484 p=strchr(str,':'); 483 x=h=str; 484 if (*h == '[') 485 { 486 h++; 487 p=strchr(h,']'); 485 488 if (p == NULL) 486 489 { 487 BIO_printf(bio_err,"no port defined\n");490 BIO_printf(bio_err,"no ending bracket for IPv6 address\n"); 488 491 return(0); 489 492 } 490 493 *(p++)='\0'; 491 492 if ((ip != NULL) && !host_ip(str,ip)) 493 goto err; 494 if (host_ptr != NULL) *host_ptr=h; 495 496 if (!extract_port(p,port_ptr)) 497 goto err; 498 return(1); 499 err: 500 return(0); 494 x = p; 501 495 } 502 503 static int host_ip(char *str, unsigned char ip[4]) 504 { 505 unsigned int in[4]; 506 int i; 507 508 if (sscanf(str,"%u.%u.%u.%u",&(in[0]),&(in[1]),&(in[2]),&(in[3])) == 4) 509 { 510 for (i=0; i<4; i++) 511 if (in[i] > 255) 512 { 513 BIO_printf(bio_err,"invalid IP address\n"); 514 goto err; 515 } 516 ip[0]=in[0]; 517 ip[1]=in[1]; 518 ip[2]=in[2]; 519 ip[3]=in[3]; 520 } 521 else 522 { /* do a gethostbyname */ 523 struct hostent *he; 524 525 if (!ssl_sock_init()) return(0); 526 527 he=GetHostByName(str); 528 if (he == NULL) 529 { 530 BIO_printf(bio_err,"gethostbyname failure\n"); 531 goto err; 532 } 533 /* cast to short because of win16 winsock definition */ 534 if ((short)he->h_addrtype != AF_INET) 496 p=strchr(x,':'); 497 if (p == NULL) 535 498 { 536 BIO_printf(bio_err,"gethostbyname addr is not AF_INET\n"); 537 return(0); 538 } 539 ip[0]=he->h_addr_list[0][0]; 540 ip[1]=he->h_addr_list[0][1]; 541 ip[2]=he->h_addr_list[0][2]; 542 ip[3]=he->h_addr_list[0][3]; 543 } 544 return(1); 545 err: 499 BIO_printf(bio_err,"no port defined\n"); 546 500 return(0); 547 501 } 502 *(p++)='\0'; 548 503 549 int extract_port(char *str, short *port_ptr) 550 { 551 int i; 552 struct servent *s; 504 if (host_ptr != NULL) *host_ptr=h; 505 if (port_ptr != NULL) *port_ptr=p; 553 506 554 i=atoi(str);555 if (i != 0)556 *port_ptr=(unsigned short)i;557 else558 {559 s=getservbyname(str,"tcp");560 if (s == NULL)561 {562 BIO_printf(bio_err,"getservbyname failure for %s\n",str);563 return(0);564 }565 *port_ptr=ntohs((unsigned short)s->s_port);566 }567 507 return(1); 568 508 } 569 509
Note: See TracBrowser
for help on using the repository browser.