diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-02-06 15:02:16 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-02-06 15:02:16 +0100 |
| commit | e999657f6da95b8a40e51978461d964b56189e92 (patch) | |
| tree | 1e50e4462b775d961e141aba9eaa488e2d09672f | |
| parent | 98066662aa15a21627ef8a3fb7318b6ee301df22 (diff) | |
| download | busybox-w32-e999657f6da95b8a40e51978461d964b56189e92.tar.gz busybox-w32-e999657f6da95b8a40e51978461d964b56189e92.tar.bz2 busybox-w32-e999657f6da95b8a40e51978461d964b56189e92.zip | |
wget: preparations for ftps:// support (block move, no code changes)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | networking/wget.c | 162 |
1 files changed, 81 insertions, 81 deletions
diff --git a/networking/wget.c b/networking/wget.c index d1d85230c..9300fa30b 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
| @@ -602,87 +602,6 @@ static void reset_beg_range_to_zero(void) | |||
| 602 | /* ftruncate(G.output_fd, 0); */ | 602 | /* ftruncate(G.output_fd, 0); */ |
| 603 | } | 603 | } |
| 604 | 604 | ||
| 605 | static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa) | ||
| 606 | { | ||
| 607 | FILE *sfp; | ||
| 608 | char *str; | ||
| 609 | int port; | ||
| 610 | |||
| 611 | if (!target->user) | ||
| 612 | target->user = xstrdup("anonymous:busybox@"); | ||
| 613 | |||
| 614 | sfp = open_socket(lsa); | ||
| 615 | if (ftpcmd(NULL, NULL, sfp) != 220) | ||
| 616 | bb_error_msg_and_die("%s", sanitize_string(G.wget_buf + 4)); | ||
| 617 | |||
| 618 | /* | ||
| 619 | * Splitting username:password pair, | ||
| 620 | * trying to log in | ||
| 621 | */ | ||
| 622 | str = strchr(target->user, ':'); | ||
| 623 | if (str) | ||
| 624 | *str++ = '\0'; | ||
| 625 | switch (ftpcmd("USER ", target->user, sfp)) { | ||
| 626 | case 230: | ||
| 627 | break; | ||
| 628 | case 331: | ||
| 629 | if (ftpcmd("PASS ", str, sfp) == 230) | ||
| 630 | break; | ||
| 631 | /* fall through (failed login) */ | ||
| 632 | default: | ||
| 633 | bb_error_msg_and_die("ftp login: %s", sanitize_string(G.wget_buf + 4)); | ||
| 634 | } | ||
| 635 | |||
| 636 | ftpcmd("TYPE I", NULL, sfp); | ||
| 637 | |||
| 638 | /* | ||
| 639 | * Querying file size | ||
| 640 | */ | ||
| 641 | if (ftpcmd("SIZE ", target->path, sfp) == 213) { | ||
| 642 | G.content_len = BB_STRTOOFF(G.wget_buf + 4, NULL, 10); | ||
| 643 | if (G.content_len < 0 || errno) { | ||
| 644 | bb_error_msg_and_die("SIZE value is garbage"); | ||
| 645 | } | ||
| 646 | G.got_clen = 1; | ||
| 647 | } | ||
| 648 | |||
| 649 | /* | ||
| 650 | * Entering passive mode | ||
| 651 | */ | ||
| 652 | if (ftpcmd("PASV", NULL, sfp) != 227) { | ||
| 653 | pasv_error: | ||
| 654 | bb_error_msg_and_die("bad response to %s: %s", "PASV", sanitize_string(G.wget_buf)); | ||
| 655 | } | ||
| 656 | // Response is "227 garbageN1,N2,N3,N4,P1,P2[)garbage] | ||
| 657 | // Server's IP is N1.N2.N3.N4 (we ignore it) | ||
| 658 | // Server's port for data connection is P1*256+P2 | ||
| 659 | str = strrchr(G.wget_buf, ')'); | ||
| 660 | if (str) str[0] = '\0'; | ||
| 661 | str = strrchr(G.wget_buf, ','); | ||
| 662 | if (!str) goto pasv_error; | ||
| 663 | port = xatou_range(str+1, 0, 255); | ||
| 664 | *str = '\0'; | ||
| 665 | str = strrchr(G.wget_buf, ','); | ||
| 666 | if (!str) goto pasv_error; | ||
| 667 | port += xatou_range(str+1, 0, 255) * 256; | ||
| 668 | set_nport(&lsa->u.sa, htons(port)); | ||
| 669 | |||
| 670 | *dfpp = open_socket(lsa); | ||
| 671 | |||
| 672 | if (G.beg_range != 0) { | ||
| 673 | sprintf(G.wget_buf, "REST %"OFF_FMT"u", G.beg_range); | ||
| 674 | if (ftpcmd(G.wget_buf, NULL, sfp) == 350) | ||
| 675 | G.content_len -= G.beg_range; | ||
| 676 | else | ||
| 677 | reset_beg_range_to_zero(); | ||
| 678 | } | ||
| 679 | |||
| 680 | if (ftpcmd("RETR ", target->path, sfp) > 150) | ||
| 681 | bb_error_msg_and_die("bad response to %s: %s", "RETR", sanitize_string(G.wget_buf)); | ||
| 682 | |||
| 683 | return sfp; | ||
| 684 | } | ||
| 685 | |||
| 686 | #if ENABLE_FEATURE_WGET_OPENSSL | 605 | #if ENABLE_FEATURE_WGET_OPENSSL |
| 687 | static int spawn_https_helper_openssl(const char *host, unsigned port) | 606 | static int spawn_https_helper_openssl(const char *host, unsigned port) |
| 688 | { | 607 | { |
| @@ -808,6 +727,87 @@ static void spawn_ssl_client(const char *host, int network_fd) | |||
| 808 | } | 727 | } |
| 809 | #endif | 728 | #endif |
| 810 | 729 | ||
| 730 | static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa) | ||
| 731 | { | ||
| 732 | FILE *sfp; | ||
| 733 | char *str; | ||
| 734 | int port; | ||
| 735 | |||
| 736 | if (!target->user) | ||
| 737 | target->user = xstrdup("anonymous:busybox@"); | ||
| 738 | |||
| 739 | sfp = open_socket(lsa); | ||
| 740 | if (ftpcmd(NULL, NULL, sfp) != 220) | ||
| 741 | bb_error_msg_and_die("%s", sanitize_string(G.wget_buf + 4)); | ||
| 742 | |||
| 743 | /* | ||
| 744 | * Splitting username:password pair, | ||
| 745 | * trying to log in | ||
| 746 | */ | ||
| 747 | str = strchr(target->user, ':'); | ||
| 748 | if (str) | ||
| 749 | *str++ = '\0'; | ||
| 750 | switch (ftpcmd("USER ", target->user, sfp)) { | ||
| 751 | case 230: | ||
| 752 | break; | ||
| 753 | case 331: | ||
| 754 | if (ftpcmd("PASS ", str, sfp) == 230) | ||
| 755 | break; | ||
| 756 | /* fall through (failed login) */ | ||
| 757 | default: | ||
| 758 | bb_error_msg_and_die("ftp login: %s", sanitize_string(G.wget_buf + 4)); | ||
| 759 | } | ||
| 760 | |||
| 761 | ftpcmd("TYPE I", NULL, sfp); | ||
| 762 | |||
| 763 | /* | ||
| 764 | * Querying file size | ||
| 765 | */ | ||
| 766 | if (ftpcmd("SIZE ", target->path, sfp) == 213) { | ||
| 767 | G.content_len = BB_STRTOOFF(G.wget_buf + 4, NULL, 10); | ||
| 768 | if (G.content_len < 0 || errno) { | ||
| 769 | bb_error_msg_and_die("SIZE value is garbage"); | ||
| 770 | } | ||
| 771 | G.got_clen = 1; | ||
| 772 | } | ||
| 773 | |||
| 774 | /* | ||
| 775 | * Entering passive mode | ||
| 776 | */ | ||
| 777 | if (ftpcmd("PASV", NULL, sfp) != 227) { | ||
| 778 | pasv_error: | ||
| 779 | bb_error_msg_and_die("bad response to %s: %s", "PASV", sanitize_string(G.wget_buf)); | ||
| 780 | } | ||
| 781 | // Response is "227 garbageN1,N2,N3,N4,P1,P2[)garbage] | ||
| 782 | // Server's IP is N1.N2.N3.N4 (we ignore it) | ||
| 783 | // Server's port for data connection is P1*256+P2 | ||
| 784 | str = strrchr(G.wget_buf, ')'); | ||
| 785 | if (str) str[0] = '\0'; | ||
| 786 | str = strrchr(G.wget_buf, ','); | ||
| 787 | if (!str) goto pasv_error; | ||
| 788 | port = xatou_range(str+1, 0, 255); | ||
| 789 | *str = '\0'; | ||
| 790 | str = strrchr(G.wget_buf, ','); | ||
| 791 | if (!str) goto pasv_error; | ||
| 792 | port += xatou_range(str+1, 0, 255) * 256; | ||
| 793 | set_nport(&lsa->u.sa, htons(port)); | ||
| 794 | |||
| 795 | *dfpp = open_socket(lsa); | ||
| 796 | |||
| 797 | if (G.beg_range != 0) { | ||
| 798 | sprintf(G.wget_buf, "REST %"OFF_FMT"u", G.beg_range); | ||
| 799 | if (ftpcmd(G.wget_buf, NULL, sfp) == 350) | ||
| 800 | G.content_len -= G.beg_range; | ||
| 801 | else | ||
| 802 | reset_beg_range_to_zero(); | ||
| 803 | } | ||
| 804 | |||
| 805 | if (ftpcmd("RETR ", target->path, sfp) > 150) | ||
| 806 | bb_error_msg_and_die("bad response to %s: %s", "RETR", sanitize_string(G.wget_buf)); | ||
| 807 | |||
| 808 | return sfp; | ||
| 809 | } | ||
| 810 | |||
| 811 | static void NOINLINE retrieve_file_data(FILE *dfp) | 811 | static void NOINLINE retrieve_file_data(FILE *dfp) |
| 812 | { | 812 | { |
| 813 | #if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT | 813 | #if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT |
