aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-04-07 13:22:52 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-04-07 13:22:52 +0200
commit32c3e3a44cb6ae2b0ff949e9f60fa0405f081dc3 (patch)
tree32fa4cc8f164ea093ee4a0d45ac9128fe9bbf2f5
parent9fe8bd8d61d8cf187ad40affb1f69fe72ae74744 (diff)
downloadbusybox-w32-32c3e3a44cb6ae2b0ff949e9f60fa0405f081dc3.tar.gz
busybox-w32-32c3e3a44cb6ae2b0ff949e9f60fa0405f081dc3.tar.bz2
busybox-w32-32c3e3a44cb6ae2b0ff949e9f60fa0405f081dc3.zip
wget,ftpd: shorten and reuse strings
function old new delta wget_main 2382 2386 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 4/0) Total: 4 bytes text data bss dec hex filename 934228 477 7296 942001 e5fb1 busybox_old 934202 477 7296 941975 e5f97 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/ftpd.c4
-rw-r--r--networking/ftpgetput.c2
-rw-r--r--networking/wget.c33
3 files changed, 17 insertions, 22 deletions
diff --git a/networking/ftpd.c b/networking/ftpd.c
index 8abbf7f57..e289a6051 100644
--- a/networking/ftpd.c
+++ b/networking/ftpd.c
@@ -1263,7 +1263,7 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
1263 break; /* does not even ask for password */ 1263 break; /* does not even ask for password */
1264 } 1264 }
1265 pw = getpwnam(G.ftp_arg); 1265 pw = getpwnam(G.ftp_arg);
1266 cmdio_write_raw(STR(FTP_GIVEPWORD)" Please specify password\r\n"); 1266 cmdio_write_raw(STR(FTP_GIVEPWORD)" Specify password\r\n");
1267 } else if (cmdval == const_PASS) { 1267 } else if (cmdval == const_PASS) {
1268 if (check_password(pw, G.ftp_arg) > 0) { 1268 if (check_password(pw, G.ftp_arg) > 0) {
1269 break; /* login success */ 1269 break; /* login success */
@@ -1274,7 +1274,7 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
1274 WRITE_OK(FTP_GOODBYE); 1274 WRITE_OK(FTP_GOODBYE);
1275 return 0; 1275 return 0;
1276 } else { 1276 } else {
1277 cmdio_write_raw(STR(FTP_LOGINERR)" Login with USER and PASS\r\n"); 1277 cmdio_write_raw(STR(FTP_LOGINERR)" Login with USER+PASS\r\n");
1278 } 1278 }
1279 } 1279 }
1280 WRITE_OK(FTP_LOGINOK); 1280 WRITE_OK(FTP_LOGINOK);
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c
index cdad629da..2f2921366 100644
--- a/networking/ftpgetput.c
+++ b/networking/ftpgetput.c
@@ -309,7 +309,7 @@ int ftpgetput_main(int argc UNUSED_PARAM, char **argv)
309 INIT_G(); 309 INIT_G();
310 /* Set default values */ 310 /* Set default values */
311 user = "anonymous"; 311 user = "anonymous";
312 password = "busybox@"; 312 password = "busybox";
313 313
314 /* 314 /*
315 * Decipher the command line 315 * Decipher the command line
diff --git a/networking/wget.c b/networking/wget.c
index 12ee29a6f..c9e576e69 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -762,12 +762,9 @@ static void spawn_ssl_client(const char *host, int network_fd, int flags)
762static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa) 762static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa)
763{ 763{
764 FILE *sfp; 764 FILE *sfp;
765 char *str; 765 char *pass;
766 int port; 766 int port;
767 767
768 if (!target->user)
769 target->user = xstrdup("anonymous:busybox@");
770
771 sfp = open_socket(lsa); 768 sfp = open_socket(lsa);
772#if ENABLE_FEATURE_WGET_HTTPS 769#if ENABLE_FEATURE_WGET_HTTPS
773 if (target->protocol == P_FTPS) 770 if (target->protocol == P_FTPS)
@@ -778,18 +775,20 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_
778 bb_error_msg_and_die("%s", G.wget_buf); 775 bb_error_msg_and_die("%s", G.wget_buf);
779 /* note: ftpcmd() sanitizes G.wget_buf, ok to print */ 776 /* note: ftpcmd() sanitizes G.wget_buf, ok to print */
780 777
781 /* 778 /* Split username:password pair */
782 * Splitting username:password pair, 779 pass = (char*)"busybox"; /* password for "anonymous" */
783 * trying to log in 780 if (target->user) {
784 */ 781 pass = strchr(target->user, ':');
785 str = strchr(target->user, ':'); 782 if (pass)
786 if (str) 783 *pass++ = '\0';
787 *str++ = '\0'; 784 }
788 switch (ftpcmd("USER ", target->user, sfp)) { 785
786 /* Log in */
787 switch (ftpcmd("USER ", target->user ?: "anonymous", sfp)) {
789 case 230: 788 case 230:
790 break; 789 break;
791 case 331: 790 case 331:
792 if (ftpcmd("PASS ", str, sfp) == 230) 791 if (ftpcmd("PASS ", pass, sfp) == 230)
793 break; 792 break;
794 /* fall through (failed login) */ 793 /* fall through (failed login) */
795 default: 794 default:
@@ -798,9 +797,7 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_
798 797
799 ftpcmd("TYPE I", NULL, sfp); 798 ftpcmd("TYPE I", NULL, sfp);
800 799
801 /* 800 /* Query file size */
802 * Querying file size
803 */
804 if (ftpcmd("SIZE ", target->path, sfp) == 213) { 801 if (ftpcmd("SIZE ", target->path, sfp) == 213) {
805 G.content_len = BB_STRTOOFF(G.wget_buf + 4, NULL, 10); 802 G.content_len = BB_STRTOOFF(G.wget_buf + 4, NULL, 10);
806 if (G.content_len < 0 || errno) { 803 if (G.content_len < 0 || errno) {
@@ -809,9 +806,7 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_
809 G.got_clen = 1; 806 G.got_clen = 1;
810 } 807 }
811 808
812 /* 809 /* Enter passive mode */
813 * Entering passive mode
814 */
815 if (ENABLE_FEATURE_IPV6 && ftpcmd("EPSV", NULL, sfp) == 229) { 810 if (ENABLE_FEATURE_IPV6 && ftpcmd("EPSV", NULL, sfp) == 229) {
816 /* good */ 811 /* good */
817 } else 812 } else