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>
This commit is contained in:
parent
9fe8bd8d61
commit
32c3e3a44c
@ -1263,7 +1263,7 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
break; /* does not even ask for password */
|
break; /* does not even ask for password */
|
||||||
}
|
}
|
||||||
pw = getpwnam(G.ftp_arg);
|
pw = getpwnam(G.ftp_arg);
|
||||||
cmdio_write_raw(STR(FTP_GIVEPWORD)" Please specify password\r\n");
|
cmdio_write_raw(STR(FTP_GIVEPWORD)" Specify password\r\n");
|
||||||
} else if (cmdval == const_PASS) {
|
} else if (cmdval == const_PASS) {
|
||||||
if (check_password(pw, G.ftp_arg) > 0) {
|
if (check_password(pw, G.ftp_arg) > 0) {
|
||||||
break; /* login success */
|
break; /* login success */
|
||||||
@ -1274,7 +1274,7 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
WRITE_OK(FTP_GOODBYE);
|
WRITE_OK(FTP_GOODBYE);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
cmdio_write_raw(STR(FTP_LOGINERR)" Login with USER and PASS\r\n");
|
cmdio_write_raw(STR(FTP_LOGINERR)" Login with USER+PASS\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WRITE_OK(FTP_LOGINOK);
|
WRITE_OK(FTP_LOGINOK);
|
||||||
|
@ -309,7 +309,7 @@ int ftpgetput_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
INIT_G();
|
INIT_G();
|
||||||
/* Set default values */
|
/* Set default values */
|
||||||
user = "anonymous";
|
user = "anonymous";
|
||||||
password = "busybox@";
|
password = "busybox";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Decipher the command line
|
* Decipher the command line
|
||||||
|
@ -762,12 +762,9 @@ static void spawn_ssl_client(const char *host, int network_fd, int flags)
|
|||||||
static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa)
|
static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa)
|
||||||
{
|
{
|
||||||
FILE *sfp;
|
FILE *sfp;
|
||||||
char *str;
|
char *pass;
|
||||||
int port;
|
int port;
|
||||||
|
|
||||||
if (!target->user)
|
|
||||||
target->user = xstrdup("anonymous:busybox@");
|
|
||||||
|
|
||||||
sfp = open_socket(lsa);
|
sfp = open_socket(lsa);
|
||||||
#if ENABLE_FEATURE_WGET_HTTPS
|
#if ENABLE_FEATURE_WGET_HTTPS
|
||||||
if (target->protocol == P_FTPS)
|
if (target->protocol == P_FTPS)
|
||||||
@ -778,18 +775,20 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_
|
|||||||
bb_error_msg_and_die("%s", G.wget_buf);
|
bb_error_msg_and_die("%s", G.wget_buf);
|
||||||
/* note: ftpcmd() sanitizes G.wget_buf, ok to print */
|
/* note: ftpcmd() sanitizes G.wget_buf, ok to print */
|
||||||
|
|
||||||
/*
|
/* Split username:password pair */
|
||||||
* Splitting username:password pair,
|
pass = (char*)"busybox"; /* password for "anonymous" */
|
||||||
* trying to log in
|
if (target->user) {
|
||||||
*/
|
pass = strchr(target->user, ':');
|
||||||
str = strchr(target->user, ':');
|
if (pass)
|
||||||
if (str)
|
*pass++ = '\0';
|
||||||
*str++ = '\0';
|
}
|
||||||
switch (ftpcmd("USER ", target->user, sfp)) {
|
|
||||||
|
/* Log in */
|
||||||
|
switch (ftpcmd("USER ", target->user ?: "anonymous", sfp)) {
|
||||||
case 230:
|
case 230:
|
||||||
break;
|
break;
|
||||||
case 331:
|
case 331:
|
||||||
if (ftpcmd("PASS ", str, sfp) == 230)
|
if (ftpcmd("PASS ", pass, sfp) == 230)
|
||||||
break;
|
break;
|
||||||
/* fall through (failed login) */
|
/* fall through (failed login) */
|
||||||
default:
|
default:
|
||||||
@ -798,9 +797,7 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_
|
|||||||
|
|
||||||
ftpcmd("TYPE I", NULL, sfp);
|
ftpcmd("TYPE I", NULL, sfp);
|
||||||
|
|
||||||
/*
|
/* Query file size */
|
||||||
* Querying file size
|
|
||||||
*/
|
|
||||||
if (ftpcmd("SIZE ", target->path, sfp) == 213) {
|
if (ftpcmd("SIZE ", target->path, sfp) == 213) {
|
||||||
G.content_len = BB_STRTOOFF(G.wget_buf + 4, NULL, 10);
|
G.content_len = BB_STRTOOFF(G.wget_buf + 4, NULL, 10);
|
||||||
if (G.content_len < 0 || errno) {
|
if (G.content_len < 0 || errno) {
|
||||||
@ -809,9 +806,7 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_
|
|||||||
G.got_clen = 1;
|
G.got_clen = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* Enter passive mode */
|
||||||
* Entering passive mode
|
|
||||||
*/
|
|
||||||
if (ENABLE_FEATURE_IPV6 && ftpcmd("EPSV", NULL, sfp) == 229) {
|
if (ENABLE_FEATURE_IPV6 && ftpcmd("EPSV", NULL, sfp) == 229) {
|
||||||
/* good */
|
/* good */
|
||||||
} else
|
} else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user