diff options
Diffstat (limited to 'src/util/socks.c')
-rw-r--r-- | src/util/socks.c | 84 |
1 files changed, 57 insertions, 27 deletions
diff --git a/src/util/socks.c b/src/util/socks.c index 37e60e3e4..85548fd79 100644 --- a/src/util/socks.c +++ b/src/util/socks.c | |||
@@ -372,15 +372,18 @@ transmit_ready (void *cls, | |||
372 | return 0; | 372 | return 0; |
373 | } | 373 | } |
374 | 374 | ||
375 | GNUNET_assert (1024 >= size && size > 0); | 375 | GNUNET_assert ( (1024 >= size) && (size > 0) ); |
376 | GNUNET_assert (SOCKS5_step_done > ih->step && ih->step >= 0); | 376 | GNUNET_assert ( (SOCKS5_step_done > ih->step) && (ih->step >= 0) ); |
377 | unsigned char * b = ih->outstep[ih->step]; | 377 | unsigned char * b = ih->outstep[ih->step]; |
378 | unsigned char * e = ih->outstep[ih->step+1]; | 378 | unsigned char * e = ih->outstep[ih->step+1]; |
379 | GNUNET_assert (e <= &ih->outbuf[1024]); | 379 | GNUNET_assert (e <= &ih->outbuf[1024]); |
380 | unsigned l = e - b; | 380 | unsigned int l = e - b; |
381 | GNUNET_assert (size >= l && l >= 0); | 381 | GNUNET_assert (size >= l); |
382 | GNUNET_memcpy(buf, b, l); | 382 | GNUNET_memcpy (buf, |
383 | register_reciever (ih, register_reciever_wants(ih)); | 383 | b, |
384 | l); | ||
385 | register_reciever (ih, | ||
386 | register_reciever_wants (ih)); | ||
384 | return l; | 387 | return l; |
385 | } | 388 | } |
386 | 389 | ||
@@ -566,17 +569,25 @@ GNUNET_SOCKS_check_service (const char *service_name, | |||
566 | */ | 569 | */ |
567 | struct GNUNET_CONNECTION_Handle * | 570 | struct GNUNET_CONNECTION_Handle * |
568 | GNUNET_SOCKS_do_connect (const char *service_name, | 571 | GNUNET_SOCKS_do_connect (const char *service_name, |
569 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 572 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
570 | { | 573 | { |
571 | struct GNUNET_SOCKS_Handshake *ih; | 574 | struct GNUNET_SOCKS_Handshake *ih; |
572 | struct GNUNET_CONNECTION_Handle *socks5; /* *proxied */ | 575 | struct GNUNET_CONNECTION_Handle *socks5; /* *proxied */ |
573 | char *host0,*host1,*user,*pass; | 576 | char *host0; |
574 | unsigned long long port0,port1; | 577 | char *host1; |
575 | 578 | char *user; | |
576 | if (GNUNET_YES != GNUNET_SOCKS_check_service (service_name, cfg)) | 579 | char *pass; |
580 | unsigned long long port0; | ||
581 | unsigned long long port1; | ||
582 | |||
583 | if (GNUNET_YES != | ||
584 | GNUNET_SOCKS_check_service (service_name, cfg)) | ||
577 | return NULL; | 585 | return NULL; |
578 | if (GNUNET_OK != | 586 | if (GNUNET_OK != |
579 | GNUNET_CONFIGURATION_get_value_number (cfg, service_name, "SOCKSPORT", &port0)) | 587 | GNUNET_CONFIGURATION_get_value_number (cfg, |
588 | service_name, | ||
589 | "SOCKSPORT", | ||
590 | &port0)) | ||
580 | port0 = 9050; | 591 | port0 = 9050; |
581 | /* A typical Tor client should usually try port 9150 for the TBB too, but | 592 | /* A typical Tor client should usually try port 9150 for the TBB too, but |
582 | * GNUnet can probably assume a system Tor installation. */ | 593 | * GNUnet can probably assume a system Tor installation. */ |
@@ -588,16 +599,23 @@ GNUNET_SOCKS_do_connect (const char *service_name, | |||
588 | service_name); | 599 | service_name); |
589 | return NULL; | 600 | return NULL; |
590 | } | 601 | } |
591 | if ((GNUNET_OK != | 602 | if ( (GNUNET_OK != |
592 | GNUNET_CONFIGURATION_get_value_number (cfg, service_name, "PORT", &port1)) | 603 | GNUNET_CONFIGURATION_get_value_number (cfg, |
593 | || (port1 > 65535) || (port1 <= 0) || | 604 | service_name, |
605 | "PORT", | ||
606 | &port1)) || | ||
607 | (port1 > 65535) || | ||
608 | (port1 <= 0) || | ||
594 | (GNUNET_OK != | 609 | (GNUNET_OK != |
595 | GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "HOSTNAME", &host1))) | 610 | GNUNET_CONFIGURATION_get_value_string (cfg, |
611 | service_name, | ||
612 | "HOSTNAME", | ||
613 | &host1))) | ||
596 | { | 614 | { |
597 | LOG (GNUNET_ERROR_TYPE_WARNING, | 615 | LOG (GNUNET_ERROR_TYPE_WARNING, |
598 | _ | 616 | _("Attempting to proxy service `%s' to invalid port %d or hostname.\n"), |
599 | ("Attempting to proxy service `%s' to invalid port %d or hostname `%s'.\n"), | 617 | service_name, |
600 | service_name,port1,host1); | 618 | port1); |
601 | return NULL; | 619 | return NULL; |
602 | } | 620 | } |
603 | /* Appeared to still work after host0 corrupted, so either test case is broken, or | 621 | /* Appeared to still work after host0 corrupted, so either test case is broken, or |
@@ -605,20 +623,32 @@ GNUNET_SOCKS_do_connect (const char *service_name, | |||
605 | if (GNUNET_OK != | 623 | if (GNUNET_OK != |
606 | GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "SOCKSHOST", &host0)) | 624 | GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "SOCKSHOST", &host0)) |
607 | host0 = NULL; | 625 | host0 = NULL; |
608 | socks5 = GNUNET_CONNECTION_create_from_connect (cfg, (host0 != NULL)? host0:"127.0.0.1", port0); | 626 | socks5 = GNUNET_CONNECTION_create_from_connect (cfg, |
627 | (host0 != NULL) | ||
628 | ? host0 | ||
629 | :"127.0.0.1", | ||
630 | port0); | ||
609 | GNUNET_free_non_null (host0); | 631 | GNUNET_free_non_null (host0); |
610 | 632 | ||
611 | /* Sets to NULL if they do not exist */ | 633 | /* Sets to NULL if they do not exist */ |
612 | (void) GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "SOCKSUSER", &user); | 634 | (void) GNUNET_CONFIGURATION_get_value_string (cfg, |
613 | (void) GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "SOCKSPASS", &pass); | 635 | service_name, |
636 | "SOCKSUSER", | ||
637 | &user); | ||
638 | (void) GNUNET_CONFIGURATION_get_value_string (cfg, | ||
639 | service_name, | ||
640 | "SOCKSPASS", | ||
641 | &pass); | ||
614 | ih = GNUNET_SOCKS_init_handshake(user,pass); | 642 | ih = GNUNET_SOCKS_init_handshake(user,pass); |
615 | if (NULL != user) GNUNET_free (user); | 643 | GNUNET_free_non_null (user); |
616 | if (NULL != pass) GNUNET_free (pass); | 644 | GNUNET_free_non_null (pass); |
617 | 645 | ||
618 | GNUNET_SOCKS_set_handshake_destination (ih,host1,port1); | 646 | GNUNET_SOCKS_set_handshake_destination (ih, |
647 | host1, | ||
648 | port1); | ||
619 | GNUNET_free (host1); | 649 | GNUNET_free (host1); |
620 | 650 | return GNUNET_SOCKS_run_handshake (ih, | |
621 | return GNUNET_SOCKS_run_handshake(ih,socks5); | 651 | socks5); |
622 | } | 652 | } |
623 | 653 | ||
624 | /* socks.c */ | 654 | /* socks.c */ |