diff options
| author | Sergey Ponomarev <stokito@gmail.com> | 2021-01-17 20:35:08 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-03-09 17:45:10 +0100 |
| commit | b6e6c83ab301ac92f649d63f5cfe0fddde3d142e (patch) | |
| tree | 0a87125a92134c02f42d49814a08e79d9d2c1622 | |
| parent | 0b25e810ed73334d30f99ba7073f21369b33ab18 (diff) | |
| download | busybox-w32-b6e6c83ab301ac92f649d63f5cfe0fddde3d142e.tar.gz busybox-w32-b6e6c83ab301ac92f649d63f5cfe0fddde3d142e.tar.bz2 busybox-w32-b6e6c83ab301ac92f649d63f5cfe0fddde3d142e.zip | |
wget: new option FEATURE_WGET_FTP to enable/disable FTP
Introduce a separate option FTPS_SUPPORTED instead of not obvious ENABLE_FEATURE_WGET_HTTPS.
function old new delta
P_FTP 4 - -4
P_FTPS 5 - -5
reset_beg_range_to_zero 41 - -41
parse_url 431 366 -65
parse_pasv_epsv 154 - -154
.rodata 115566 115408 -158
ftpcmd 204 - -204
spawn_ssl_client 291 - -291
wget_main 2998 2664 -334
------------------------------------------------------------------------------
(add/remove: 0/7 grow/shrink: 0/3 up/down: 0/-1256) Total: -1256 bytes
Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | networking/wget.c | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/networking/wget.c b/networking/wget.c index e660c279c..3edc5f870 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
| @@ -25,6 +25,13 @@ | |||
| 25 | //config: default y | 25 | //config: default y |
| 26 | //config: depends on WGET | 26 | //config: depends on WGET |
| 27 | //config: | 27 | //config: |
| 28 | //config:config FEATURE_WGET_FTP | ||
| 29 | //config: bool "Enable FTP protocol (+1k)" | ||
| 30 | //config: default y | ||
| 31 | //config: depends on WGET | ||
| 32 | //config: help | ||
| 33 | //config: To support FTPS, enable FEATURE_WGET_HTTPS as well. | ||
| 34 | //config: | ||
| 28 | //config:config FEATURE_WGET_AUTHENTICATION | 35 | //config:config FEATURE_WGET_AUTHENTICATION |
| 29 | //config: bool "Enable HTTP authentication" | 36 | //config: bool "Enable HTTP authentication" |
| 30 | //config: default y | 37 | //config: default y |
| @@ -48,12 +55,12 @@ | |||
| 48 | //config: | 55 | //config: |
| 49 | //config:config FEATURE_WGET_HTTPS | 56 | //config:config FEATURE_WGET_HTTPS |
| 50 | //config: bool "Support HTTPS using internal TLS code" | 57 | //config: bool "Support HTTPS using internal TLS code" |
| 51 | //it also enables FTPS support, but it's not well tested yet | ||
| 52 | //config: default y | 58 | //config: default y |
| 53 | //config: depends on WGET | 59 | //config: depends on WGET |
| 54 | //config: select TLS | 60 | //config: select TLS |
| 55 | //config: help | 61 | //config: help |
| 56 | //config: wget will use internal TLS code to connect to https:// URLs. | 62 | //config: wget will use internal TLS code to connect to https:// URLs. |
| 63 | //config: It also enables FTPS support, but it's not well tested yet. | ||
| 57 | //config: Note: | 64 | //config: Note: |
| 58 | //config: On NOMMU machines, ssl_helper applet should be available | 65 | //config: On NOMMU machines, ssl_helper applet should be available |
| 59 | //config: in the $PATH for this to work. Make sure to select that applet. | 66 | //config: in the $PATH for this to work. Make sure to select that applet. |
| @@ -173,6 +180,7 @@ | |||
| 173 | 180 | ||
| 174 | 181 | ||
| 175 | #define SSL_SUPPORTED (ENABLE_FEATURE_WGET_OPENSSL || ENABLE_FEATURE_WGET_HTTPS) | 182 | #define SSL_SUPPORTED (ENABLE_FEATURE_WGET_OPENSSL || ENABLE_FEATURE_WGET_HTTPS) |
| 183 | #define FTPS_SUPPORTED (ENABLE_FEATURE_WGET_FTP && ENABLE_FEATURE_WGET_HTTPS) | ||
| 176 | 184 | ||
| 177 | struct host_info { | 185 | struct host_info { |
| 178 | char *allocated; | 186 | char *allocated; |
| @@ -182,14 +190,16 @@ struct host_info { | |||
| 182 | char *host; | 190 | char *host; |
| 183 | int port; | 191 | int port; |
| 184 | }; | 192 | }; |
| 185 | static const char P_FTP[] ALIGN1 = "ftp"; | ||
| 186 | static const char P_HTTP[] ALIGN1 = "http"; | 193 | static const char P_HTTP[] ALIGN1 = "http"; |
| 187 | #if SSL_SUPPORTED | 194 | #if SSL_SUPPORTED |
| 188 | # if ENABLE_FEATURE_WGET_HTTPS | ||
| 189 | static const char P_FTPS[] ALIGN1 = "ftps"; | ||
| 190 | # endif | ||
| 191 | static const char P_HTTPS[] ALIGN1 = "https"; | 195 | static const char P_HTTPS[] ALIGN1 = "https"; |
| 192 | #endif | 196 | #endif |
| 197 | #if ENABLE_FEATURE_WGET_FTP | ||
| 198 | static const char P_FTP[] ALIGN1 = "ftp"; | ||
| 199 | #endif | ||
| 200 | #if FTPS_SUPPORTED | ||
| 201 | static const char P_FTPS[] ALIGN1 = "ftps"; | ||
| 202 | #endif | ||
| 193 | 203 | ||
| 194 | #if ENABLE_FEATURE_WGET_LONG_OPTIONS | 204 | #if ENABLE_FEATURE_WGET_LONG_OPTIONS |
| 195 | /* User-specified headers prevent using our corresponding built-in headers. */ | 205 | /* User-specified headers prevent using our corresponding built-in headers. */ |
| @@ -482,6 +492,7 @@ static char fgets_trim_sanitize(FILE *fp, const char *fmt) | |||
| 482 | return c; | 492 | return c; |
| 483 | } | 493 | } |
| 484 | 494 | ||
| 495 | #if ENABLE_FEATURE_WGET_FTP | ||
| 485 | static int ftpcmd(const char *s1, const char *s2, FILE *fp) | 496 | static int ftpcmd(const char *s1, const char *s2, FILE *fp) |
| 486 | { | 497 | { |
| 487 | int result; | 498 | int result; |
| @@ -507,6 +518,7 @@ static int ftpcmd(const char *s1, const char *s2, FILE *fp) | |||
| 507 | G.wget_buf[3] = ' '; | 518 | G.wget_buf[3] = ' '; |
| 508 | return result; | 519 | return result; |
| 509 | } | 520 | } |
| 521 | #endif | ||
| 510 | 522 | ||
| 511 | static void parse_url(const char *src_url, struct host_info *h) | 523 | static void parse_url(const char *src_url, struct host_info *h) |
| 512 | { | 524 | { |
| @@ -515,30 +527,31 @@ static void parse_url(const char *src_url, struct host_info *h) | |||
| 515 | free(h->allocated); | 527 | free(h->allocated); |
| 516 | h->allocated = url = xstrdup(src_url); | 528 | h->allocated = url = xstrdup(src_url); |
| 517 | 529 | ||
| 518 | h->protocol = P_FTP; | 530 | h->protocol = P_HTTP; |
| 519 | p = strstr(url, "://"); | 531 | p = strstr(url, "://"); |
| 520 | if (p) { | 532 | if (p) { |
| 521 | *p = '\0'; | 533 | *p = '\0'; |
| 522 | h->host = p + 3; | 534 | h->host = p + 3; |
| 535 | #if ENABLE_FEATURE_WGET_FTP | ||
| 523 | if (strcmp(url, P_FTP) == 0) { | 536 | if (strcmp(url, P_FTP) == 0) { |
| 524 | h->port = bb_lookup_std_port(P_FTP, "tcp", 21); | 537 | h->port = bb_lookup_std_port(P_FTP, "tcp", 21); |
| 538 | h->protocol = P_FTP; | ||
| 525 | } else | 539 | } else |
| 526 | #if SSL_SUPPORTED | 540 | #endif |
| 527 | # if ENABLE_FEATURE_WGET_HTTPS | 541 | #if FTPS_SUPPORTED |
| 528 | if (strcmp(url, P_FTPS) == 0) { | 542 | if (strcmp(url, P_FTPS) == 0) { |
| 529 | h->port = bb_lookup_std_port(P_FTPS, "tcp", 990); | 543 | h->port = bb_lookup_std_port(P_FTPS, "tcp", 990); |
| 530 | h->protocol = P_FTPS; | 544 | h->protocol = P_FTPS; |
| 531 | } else | 545 | } else |
| 532 | # endif | 546 | #endif |
| 547 | #if SSL_SUPPORTED | ||
| 533 | if (strcmp(url, P_HTTPS) == 0) { | 548 | if (strcmp(url, P_HTTPS) == 0) { |
| 534 | h->port = bb_lookup_std_port(P_HTTPS, "tcp", 443); | 549 | h->port = bb_lookup_std_port(P_HTTPS, "tcp", 443); |
| 535 | h->protocol = P_HTTPS; | 550 | h->protocol = P_HTTPS; |
| 536 | } else | 551 | } else |
| 537 | #endif | 552 | #endif |
| 538 | if (strcmp(url, P_HTTP) == 0) { | 553 | if (strcmp(url, P_HTTP) == 0) { |
| 539 | http: | 554 | goto http; |
| 540 | h->port = bb_lookup_std_port(P_HTTP, "tcp", 80); | ||
| 541 | h->protocol = P_HTTP; | ||
| 542 | } else { | 555 | } else { |
| 543 | *p = ':'; | 556 | *p = ':'; |
| 544 | bb_error_msg_and_die("not an http or ftp url: %s", url); | 557 | bb_error_msg_and_die("not an http or ftp url: %s", url); |
| @@ -546,7 +559,8 @@ static void parse_url(const char *src_url, struct host_info *h) | |||
| 546 | } else { | 559 | } else { |
| 547 | // GNU wget is user-friendly and falls back to http:// | 560 | // GNU wget is user-friendly and falls back to http:// |
| 548 | h->host = url; | 561 | h->host = url; |
| 549 | goto http; | 562 | http: |
| 563 | h->port = bb_lookup_std_port(P_HTTP, "tcp", 80); | ||
| 550 | } | 564 | } |
| 551 | 565 | ||
| 552 | // FYI: | 566 | // FYI: |
| @@ -796,6 +810,7 @@ static void spawn_ssl_client(const char *host, int network_fd, int flags) | |||
| 796 | } | 810 | } |
| 797 | #endif | 811 | #endif |
| 798 | 812 | ||
| 813 | #if ENABLE_FEATURE_WGET_FTP | ||
| 799 | static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa) | 814 | static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa) |
| 800 | { | 815 | { |
| 801 | FILE *sfp; | 816 | FILE *sfp; |
| @@ -803,7 +818,7 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_ | |||
| 803 | int port; | 818 | int port; |
| 804 | 819 | ||
| 805 | sfp = open_socket(lsa); | 820 | sfp = open_socket(lsa); |
| 806 | #if ENABLE_FEATURE_WGET_HTTPS | 821 | #if FTPS_SUPPORTED |
| 807 | if (target->protocol == P_FTPS) | 822 | if (target->protocol == P_FTPS) |
| 808 | spawn_ssl_client(target->host, fileno(sfp), TLSLOOP_EXIT_ON_LOCAL_EOF); | 823 | spawn_ssl_client(target->host, fileno(sfp), TLSLOOP_EXIT_ON_LOCAL_EOF); |
| 809 | #endif | 824 | #endif |
| @@ -859,7 +874,7 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_ | |||
| 859 | 874 | ||
| 860 | *dfpp = open_socket(lsa); | 875 | *dfpp = open_socket(lsa); |
| 861 | 876 | ||
| 862 | #if ENABLE_FEATURE_WGET_HTTPS | 877 | #if FTPS_SUPPORTED |
| 863 | if (target->protocol == P_FTPS) { | 878 | if (target->protocol == P_FTPS) { |
| 864 | /* "PROT P" enables encryption of data stream. | 879 | /* "PROT P" enables encryption of data stream. |
| 865 | * Without it (or with "PROT C"), data is sent unencrypted. | 880 | * Without it (or with "PROT C"), data is sent unencrypted. |
| @@ -885,6 +900,7 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_ | |||
| 885 | 900 | ||
| 886 | return sfp; | 901 | return sfp; |
| 887 | } | 902 | } |
| 903 | #endif | ||
| 888 | 904 | ||
| 889 | static void NOINLINE retrieve_file_data(FILE *dfp) | 905 | static void NOINLINE retrieve_file_data(FILE *dfp) |
| 890 | { | 906 | { |
| @@ -1407,10 +1423,12 @@ However, in real world it was observed that some web servers | |||
| 1407 | /* For HTTP, data is pumped over the same connection */ | 1423 | /* For HTTP, data is pumped over the same connection */ |
| 1408 | dfp = sfp; | 1424 | dfp = sfp; |
| 1409 | } else { | 1425 | } else { |
| 1426 | #if ENABLE_FEATURE_WGET_FTP | ||
| 1410 | /* | 1427 | /* |
| 1411 | * FTP session | 1428 | * FTP session |
| 1412 | */ | 1429 | */ |
| 1413 | sfp = prepare_ftp_session(&dfp, &target, lsa); | 1430 | sfp = prepare_ftp_session(&dfp, &target, lsa); |
| 1431 | #endif | ||
| 1414 | } | 1432 | } |
| 1415 | 1433 | ||
| 1416 | free(lsa); | 1434 | free(lsa); |
| @@ -1428,6 +1446,7 @@ However, in real world it was observed that some web servers | |||
| 1428 | fprintf(stderr, "remote file exists\n"); | 1446 | fprintf(stderr, "remote file exists\n"); |
| 1429 | } | 1447 | } |
| 1430 | 1448 | ||
| 1449 | #if ENABLE_FEATURE_WGET_FTP | ||
| 1431 | if (dfp != sfp) { | 1450 | if (dfp != sfp) { |
| 1432 | /* It's ftp. Close data connection properly */ | 1451 | /* It's ftp. Close data connection properly */ |
| 1433 | fclose(dfp); | 1452 | fclose(dfp); |
| @@ -1435,6 +1454,7 @@ However, in real world it was observed that some web servers | |||
| 1435 | bb_error_msg_and_die("ftp error: %s", G.wget_buf); | 1454 | bb_error_msg_and_die("ftp error: %s", G.wget_buf); |
| 1436 | /* ftpcmd("QUIT", NULL, sfp); - why bother? */ | 1455 | /* ftpcmd("QUIT", NULL, sfp); - why bother? */ |
| 1437 | } | 1456 | } |
| 1457 | #endif | ||
| 1438 | fclose(sfp); | 1458 | fclose(sfp); |
| 1439 | 1459 | ||
| 1440 | free(server.allocated); | 1460 | free(server.allocated); |
