2002-12-13 08:13:50 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
2004-03-15 13:59:22 +05:30
|
|
|
* ftpget
|
|
|
|
*
|
2002-12-13 08:13:50 +05:30
|
|
|
* Mini implementation of FTP to retrieve a remote file.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Jeff Angielski, The PTR Group <jeff@theptrgroup.com>
|
2007-09-21 18:46:32 +05:30
|
|
|
* Copyright (C) 2002 Glenn McGrath
|
2002-12-13 08:13:50 +05:30
|
|
|
*
|
|
|
|
* Based on wget.c by Chip Rosenthal Covad Communications
|
|
|
|
* <chip@laserlink.net>
|
|
|
|
*
|
2010-08-16 23:44:46 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2002-12-13 08:13:50 +05:30
|
|
|
*/
|
2016-11-23 13:35:14 +05:30
|
|
|
//config:config FTPGET
|
2018-12-28 07:50:17 +05:30
|
|
|
//config: bool "ftpget (7.8 kb)"
|
2016-11-23 13:35:14 +05:30
|
|
|
//config: default y
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: Retrieve a remote file via FTP.
|
2016-11-23 13:35:14 +05:30
|
|
|
//config:
|
|
|
|
//config:config FTPPUT
|
2018-12-28 07:50:17 +05:30
|
|
|
//config: bool "ftpput (7.5 kb)"
|
2016-11-23 13:35:14 +05:30
|
|
|
//config: default y
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: Store a remote file via FTP.
|
2016-11-23 13:35:14 +05:30
|
|
|
//config:
|
|
|
|
//config:config FEATURE_FTPGETPUT_LONG_OPTIONS
|
|
|
|
//config: bool "Enable long options in ftpget/ftpput"
|
|
|
|
//config: default y
|
|
|
|
//config: depends on LONG_OPTS && (FTPGET || FTPPUT)
|
|
|
|
|
|
|
|
//applet:IF_FTPGET(APPLET_ODDNAME(ftpget, ftpgetput, BB_DIR_USR_BIN, BB_SUID_DROP, ftpget))
|
|
|
|
//applet:IF_FTPPUT(APPLET_ODDNAME(ftpput, ftpgetput, BB_DIR_USR_BIN, BB_SUID_DROP, ftpput))
|
|
|
|
|
|
|
|
//kbuild:lib-$(CONFIG_FTPGET) += ftpgetput.o
|
|
|
|
//kbuild:lib-$(CONFIG_FTPPUT) += ftpgetput.o
|
2002-12-13 08:13:50 +05:30
|
|
|
|
2011-04-11 06:59:49 +05:30
|
|
|
//usage:#define ftpget_trivial_usage
|
|
|
|
//usage: "[OPTIONS] HOST [LOCAL_FILE] REMOTE_FILE"
|
|
|
|
//usage:#define ftpget_full_usage "\n\n"
|
2012-03-19 16:52:57 +05:30
|
|
|
//usage: "Download a file via FTP\n"
|
2011-04-11 06:59:49 +05:30
|
|
|
//usage: "\n -c Continue previous transfer"
|
|
|
|
//usage: "\n -v Verbose"
|
2012-03-19 16:52:57 +05:30
|
|
|
//usage: "\n -u USER Username"
|
|
|
|
//usage: "\n -p PASS Password"
|
|
|
|
//usage: "\n -P NUM Port"
|
2011-04-11 06:59:49 +05:30
|
|
|
//usage:
|
|
|
|
//usage:#define ftpput_trivial_usage
|
|
|
|
//usage: "[OPTIONS] HOST [REMOTE_FILE] LOCAL_FILE"
|
|
|
|
//usage:#define ftpput_full_usage "\n\n"
|
2012-03-19 16:52:57 +05:30
|
|
|
//usage: "Upload a file to a FTP server\n"
|
2011-04-11 06:59:49 +05:30
|
|
|
//usage: "\n -v Verbose"
|
2012-03-19 16:52:57 +05:30
|
|
|
//usage: "\n -u USER Username"
|
|
|
|
//usage: "\n -p PASS Password"
|
|
|
|
//usage: "\n -P NUM Port number"
|
2011-04-11 06:59:49 +05:30
|
|
|
|
2007-05-27 00:30:18 +05:30
|
|
|
#include "libbb.h"
|
2016-04-21 19:56:30 +05:30
|
|
|
#include "common_bufsiz.h"
|
2002-12-13 08:13:50 +05:30
|
|
|
|
2008-03-29 13:07:42 +05:30
|
|
|
struct globals {
|
2007-01-30 04:21:25 +05:30
|
|
|
const char *user;
|
|
|
|
const char *password;
|
2007-01-11 22:20:23 +05:30
|
|
|
struct len_and_sockaddr *lsa;
|
2008-03-29 13:10:35 +05:30
|
|
|
FILE *control_stream;
|
2008-03-29 13:07:42 +05:30
|
|
|
int verbose_flag;
|
|
|
|
int do_continue;
|
2011-05-14 00:27:01 +05:30
|
|
|
char buf[4]; /* actually [BUFSZ] */
|
2010-02-04 19:30:15 +05:30
|
|
|
} FIX_ALIASING;
|
2016-04-21 19:56:30 +05:30
|
|
|
#define G (*(struct globals*)bb_common_bufsiz1)
|
2008-03-29 13:07:42 +05:30
|
|
|
enum { BUFSZ = COMMON_BUFSIZE - offsetof(struct globals, buf) };
|
2008-03-29 13:10:35 +05:30
|
|
|
#define user (G.user )
|
|
|
|
#define password (G.password )
|
|
|
|
#define lsa (G.lsa )
|
|
|
|
#define control_stream (G.control_stream)
|
|
|
|
#define verbose_flag (G.verbose_flag )
|
|
|
|
#define do_continue (G.do_continue )
|
|
|
|
#define buf (G.buf )
|
2015-10-13 18:20:20 +05:30
|
|
|
#define INIT_G() do { \
|
2016-04-21 21:48:48 +05:30
|
|
|
setup_common_bufsiz(); \
|
2015-10-13 18:20:20 +05:30
|
|
|
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
|
|
|
|
} while (0)
|
2008-03-29 13:07:42 +05:30
|
|
|
|
|
|
|
|
2008-07-05 14:48:54 +05:30
|
|
|
static void ftp_die(const char *msg) NORETURN;
|
2008-03-29 13:07:42 +05:30
|
|
|
static void ftp_die(const char *msg)
|
2007-01-04 03:25:50 +05:30
|
|
|
{
|
2008-03-29 13:10:35 +05:30
|
|
|
char *cp = buf; /* buf holds peer's response */
|
2008-03-29 13:07:42 +05:30
|
|
|
|
2007-01-04 03:25:50 +05:30
|
|
|
/* Guard against garbage from remote server */
|
2008-03-29 13:07:42 +05:30
|
|
|
while (*cp >= ' ' && *cp < '\x7f')
|
|
|
|
cp++;
|
2008-03-29 13:10:35 +05:30
|
|
|
*cp = '\0';
|
|
|
|
bb_error_msg_and_die("unexpected server response%s%s: %s",
|
|
|
|
(msg ? " to " : ""), (msg ? msg : ""), buf);
|
2007-01-04 03:25:50 +05:30
|
|
|
}
|
|
|
|
|
2008-03-29 13:10:35 +05:30
|
|
|
static int ftpcmd(const char *s1, const char *s2)
|
2002-12-13 08:13:50 +05:30
|
|
|
{
|
2007-01-04 03:25:50 +05:30
|
|
|
unsigned n;
|
2008-03-29 13:10:35 +05:30
|
|
|
|
2002-12-13 08:13:50 +05:30
|
|
|
if (verbose_flag) {
|
2007-01-11 22:21:21 +05:30
|
|
|
bb_error_msg("cmd %s %s", s1, s2);
|
2002-12-13 08:13:50 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if (s1) {
|
2008-03-29 13:10:35 +05:30
|
|
|
fprintf(control_stream, (s2 ? "%s %s\r\n" : "%s %s\r\n"+3),
|
|
|
|
s1, s2);
|
|
|
|
fflush(control_stream);
|
2002-12-13 08:13:50 +05:30
|
|
|
}
|
2008-03-29 13:07:42 +05:30
|
|
|
|
2002-12-13 08:13:50 +05:30
|
|
|
do {
|
2011-05-14 00:27:01 +05:30
|
|
|
strcpy(buf, "EOF"); /* for ftp_die */
|
2008-03-29 13:10:35 +05:30
|
|
|
if (fgets(buf, BUFSZ - 2, control_stream) == NULL) {
|
|
|
|
ftp_die(NULL);
|
2004-05-04 16:13:34 +05:30
|
|
|
}
|
2006-10-08 18:19:22 +05:30
|
|
|
} while (!isdigit(buf[0]) || buf[3] != ' ');
|
2002-12-13 08:13:50 +05:30
|
|
|
|
2007-01-04 03:25:50 +05:30
|
|
|
buf[3] = '\0';
|
|
|
|
n = xatou(buf);
|
|
|
|
buf[3] = ' ';
|
|
|
|
return n;
|
2002-12-13 08:13:50 +05:30
|
|
|
}
|
|
|
|
|
2008-03-29 13:10:35 +05:30
|
|
|
static void ftp_login(void)
|
2002-12-13 08:13:50 +05:30
|
|
|
{
|
|
|
|
/* Connect to the command socket */
|
2008-03-29 13:07:42 +05:30
|
|
|
control_stream = fdopen(xconnect_stream(lsa), "r+");
|
2002-12-13 08:13:50 +05:30
|
|
|
if (control_stream == NULL) {
|
2007-01-11 22:20:23 +05:30
|
|
|
/* fdopen failed - extremely unlikely */
|
2007-01-04 03:25:50 +05:30
|
|
|
bb_perror_nomsg_and_die();
|
2002-12-13 08:13:50 +05:30
|
|
|
}
|
|
|
|
|
2008-03-29 13:10:35 +05:30
|
|
|
if (ftpcmd(NULL, NULL) != 220) {
|
2008-03-29 13:07:42 +05:30
|
|
|
ftp_die(NULL);
|
2002-12-13 08:13:50 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/* Login to the server */
|
2008-03-29 13:10:35 +05:30
|
|
|
switch (ftpcmd("USER", user)) {
|
2002-12-13 08:13:50 +05:30
|
|
|
case 230:
|
|
|
|
break;
|
|
|
|
case 331:
|
2008-03-29 13:10:35 +05:30
|
|
|
if (ftpcmd("PASS", password) != 230) {
|
2008-03-29 13:07:42 +05:30
|
|
|
ftp_die("PASS");
|
2002-12-13 08:13:50 +05:30
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2008-03-29 13:07:42 +05:30
|
|
|
ftp_die("USER");
|
2002-12-13 08:13:50 +05:30
|
|
|
}
|
|
|
|
|
2008-03-29 13:10:35 +05:30
|
|
|
ftpcmd("TYPE I", NULL);
|
2002-12-13 08:13:50 +05:30
|
|
|
}
|
|
|
|
|
2008-03-29 13:07:42 +05:30
|
|
|
static int xconnect_ftpdata(void)
|
2008-03-29 03:41:49 +05:30
|
|
|
{
|
2018-02-06 20:18:12 +05:30
|
|
|
int port_num;
|
2008-03-29 03:41:49 +05:30
|
|
|
|
2018-02-06 20:18:12 +05:30
|
|
|
if (ENABLE_FEATURE_IPV6 && ftpcmd("EPSV", NULL) == 229) {
|
|
|
|
/* good */
|
|
|
|
} else if (ftpcmd("PASV", NULL) != 227) {
|
|
|
|
ftp_die("PASV");
|
2018-02-04 23:38:34 +05:30
|
|
|
}
|
2018-02-06 20:18:12 +05:30
|
|
|
port_num = parse_pasv_epsv(buf);
|
|
|
|
if (port_num < 0)
|
|
|
|
ftp_die("PASV");
|
2008-03-29 03:41:49 +05:30
|
|
|
|
2011-04-07 21:22:20 +05:30
|
|
|
set_nport(&lsa->u.sa, htons(port_num));
|
2008-03-29 13:07:42 +05:30
|
|
|
return xconnect_stream(lsa);
|
2008-03-29 03:41:49 +05:30
|
|
|
}
|
|
|
|
|
2008-03-29 13:10:35 +05:30
|
|
|
static int pump_data_and_QUIT(int from, int to)
|
|
|
|
{
|
|
|
|
/* copy the file */
|
|
|
|
if (bb_copyfd_eof(from, to) == -1) {
|
|
|
|
/* error msg is already printed by bb_copyfd_eof */
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* close data connection */
|
|
|
|
close(from); /* don't know which one is that, so we close both */
|
|
|
|
close(to);
|
|
|
|
|
|
|
|
/* does server confirm that transfer is finished? */
|
|
|
|
if (ftpcmd(NULL, NULL) != 226) {
|
|
|
|
ftp_die(NULL);
|
|
|
|
}
|
|
|
|
ftpcmd("QUIT", NULL);
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-05-05 01:22:28 +05:30
|
|
|
#if !ENABLE_FTPGET
|
2008-03-29 13:10:35 +05:30
|
|
|
int ftp_receive(const char *local_path, char *server_path);
|
2006-05-05 01:22:28 +05:30
|
|
|
#else
|
2006-10-08 23:24:47 +05:30
|
|
|
static
|
2008-03-29 13:10:35 +05:30
|
|
|
int ftp_receive(const char *local_path, char *server_path)
|
2002-12-13 08:13:50 +05:30
|
|
|
{
|
|
|
|
int fd_data;
|
2003-12-20 11:13:34 +05:30
|
|
|
int fd_local = -1;
|
2002-12-13 08:13:50 +05:30
|
|
|
off_t beg_range = 0;
|
|
|
|
|
2008-03-29 03:41:49 +05:30
|
|
|
/* connect to the data socket */
|
2008-03-29 13:07:42 +05:30
|
|
|
fd_data = xconnect_ftpdata();
|
2002-12-13 08:13:50 +05:30
|
|
|
|
2008-03-29 13:10:35 +05:30
|
|
|
if (ftpcmd("SIZE", server_path) != 213) {
|
2006-01-10 12:06:00 +05:30
|
|
|
do_continue = 0;
|
2002-12-13 08:13:50 +05:30
|
|
|
}
|
|
|
|
|
2006-12-17 05:19:13 +05:30
|
|
|
if (LONE_DASH(local_path)) {
|
2004-03-27 15:32:48 +05:30
|
|
|
fd_local = STDOUT_FILENO;
|
2003-12-20 11:13:34 +05:30
|
|
|
do_continue = 0;
|
|
|
|
}
|
|
|
|
|
2002-12-13 08:13:50 +05:30
|
|
|
if (do_continue) {
|
|
|
|
struct stat sbuf;
|
2008-03-29 03:41:49 +05:30
|
|
|
/* lstat would be wrong here! */
|
|
|
|
if (stat(local_path, &sbuf) < 0) {
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_perror_msg_and_die("stat");
|
2002-12-13 08:13:50 +05:30
|
|
|
}
|
|
|
|
if (sbuf.st_size > 0) {
|
|
|
|
beg_range = sbuf.st_size;
|
|
|
|
} else {
|
|
|
|
do_continue = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_continue) {
|
2009-12-11 17:06:10 +05:30
|
|
|
sprintf(buf, "REST %"OFF_FMT"u", beg_range);
|
2008-03-29 13:10:35 +05:30
|
|
|
if (ftpcmd(buf, NULL) != 350) {
|
2002-12-13 08:13:50 +05:30
|
|
|
do_continue = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-29 13:10:35 +05:30
|
|
|
if (ftpcmd("RETR", server_path) > 150) {
|
2008-03-29 13:07:42 +05:30
|
|
|
ftp_die("RETR");
|
2002-12-13 08:13:50 +05:30
|
|
|
}
|
|
|
|
|
2008-03-29 13:10:35 +05:30
|
|
|
/* create local file _after_ we know that remote file exists */
|
2003-12-20 11:13:34 +05:30
|
|
|
if (fd_local == -1) {
|
2008-03-29 03:41:49 +05:30
|
|
|
fd_local = xopen(local_path,
|
|
|
|
do_continue ? (O_APPEND | O_WRONLY)
|
|
|
|
: (O_CREAT | O_TRUNC | O_WRONLY)
|
|
|
|
);
|
2002-12-18 08:17:40 +05:30
|
|
|
}
|
|
|
|
|
2008-03-29 13:10:35 +05:30
|
|
|
return pump_data_and_QUIT(fd_data, fd_local);
|
2002-12-13 08:13:50 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-05-05 01:22:28 +05:30
|
|
|
#if !ENABLE_FTPPUT
|
2008-03-29 13:10:35 +05:30
|
|
|
int ftp_send(const char *server_path, char *local_path);
|
2006-05-05 01:22:28 +05:30
|
|
|
#else
|
2006-10-08 23:24:47 +05:30
|
|
|
static
|
2008-03-29 13:10:35 +05:30
|
|
|
int ftp_send(const char *server_path, char *local_path)
|
2002-12-13 08:13:50 +05:30
|
|
|
{
|
|
|
|
int fd_data;
|
|
|
|
int fd_local;
|
|
|
|
int response;
|
|
|
|
|
2008-03-29 03:41:49 +05:30
|
|
|
/* connect to the data socket */
|
2008-03-29 13:07:42 +05:30
|
|
|
fd_data = xconnect_ftpdata();
|
2002-12-13 08:13:50 +05:30
|
|
|
|
|
|
|
/* get the local file */
|
2006-12-17 05:19:13 +05:30
|
|
|
fd_local = STDIN_FILENO;
|
2008-03-29 13:07:42 +05:30
|
|
|
if (NOT_LONE_DASH(local_path))
|
2006-08-03 21:11:12 +05:30
|
|
|
fd_local = xopen(local_path, O_RDONLY);
|
2008-03-29 13:07:42 +05:30
|
|
|
|
2008-03-29 13:10:35 +05:30
|
|
|
response = ftpcmd("STOR", server_path);
|
2002-12-13 08:13:50 +05:30
|
|
|
switch (response) {
|
|
|
|
case 125:
|
|
|
|
case 150:
|
|
|
|
break;
|
|
|
|
default:
|
2008-03-29 13:07:42 +05:30
|
|
|
ftp_die("STOR");
|
2002-12-13 08:13:50 +05:30
|
|
|
}
|
|
|
|
|
2008-03-29 13:10:35 +05:30
|
|
|
return pump_data_and_QUIT(fd_local, fd_data);
|
2002-12-13 08:13:50 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-05-27 01:49:22 +05:30
|
|
|
#if ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS
|
2007-08-13 02:28:27 +05:30
|
|
|
static const char ftpgetput_longopts[] ALIGN1 =
|
2007-07-23 22:44:14 +05:30
|
|
|
"continue\0" Required_argument "c"
|
|
|
|
"verbose\0" No_argument "v"
|
|
|
|
"username\0" Required_argument "u"
|
|
|
|
"password\0" Required_argument "p"
|
|
|
|
"port\0" Required_argument "P"
|
2007-07-24 21:24:42 +05:30
|
|
|
;
|
2006-05-27 01:49:22 +05:30
|
|
|
#endif
|
2003-12-19 16:07:52 +05:30
|
|
|
|
2007-10-11 15:35:36 +05:30
|
|
|
int ftpgetput_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 14:48:54 +05:30
|
|
|
int ftpgetput_main(int argc UNUSED_PARAM, char **argv)
|
2002-12-13 08:13:50 +05:30
|
|
|
{
|
2007-01-04 03:25:50 +05:30
|
|
|
const char *port = "ftp";
|
2002-12-13 08:13:50 +05:30
|
|
|
/* socket to ftp server */
|
|
|
|
|
2007-01-04 03:25:50 +05:30
|
|
|
#if ENABLE_FTPPUT && !ENABLE_FTPGET
|
|
|
|
# define ftp_action ftp_send
|
|
|
|
#elif ENABLE_FTPGET && !ENABLE_FTPPUT
|
|
|
|
# define ftp_action ftp_receive
|
|
|
|
#else
|
2008-03-29 13:10:35 +05:30
|
|
|
int (*ftp_action)(const char *, char *) = ftp_send;
|
2008-03-29 13:07:42 +05:30
|
|
|
|
2003-12-20 08:49:27 +05:30
|
|
|
/* Check to see if the command is ftpget or ftput */
|
2007-01-04 03:25:50 +05:30
|
|
|
if (applet_name[3] == 'g') {
|
2006-06-07 19:01:59 +05:30
|
|
|
ftp_action = ftp_receive;
|
2002-12-13 08:13:50 +05:30
|
|
|
}
|
2007-01-04 03:25:50 +05:30
|
|
|
#endif
|
2002-12-13 08:13:50 +05:30
|
|
|
|
2008-03-29 13:07:42 +05:30
|
|
|
INIT_G();
|
2002-12-13 08:13:50 +05:30
|
|
|
/* Set default values */
|
2008-03-29 13:07:42 +05:30
|
|
|
user = "anonymous";
|
2018-04-07 16:52:52 +05:30
|
|
|
password = "busybox";
|
2002-12-13 08:13:50 +05:30
|
|
|
|
2004-03-15 13:59:22 +05:30
|
|
|
/*
|
|
|
|
* Decipher the command line
|
2002-12-13 08:13:50 +05:30
|
|
|
*/
|
2017-08-09 01:25:02 +05:30
|
|
|
/* must have 2 to 3 params; -v and -c count */
|
|
|
|
#define OPTSTRING "^cvu:p:P:" "\0" "-2:?3:vv:cc"
|
2006-11-29 16:39:43 +05:30
|
|
|
#if ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS
|
2017-08-09 01:25:02 +05:30
|
|
|
getopt32long(argv, OPTSTRING, ftpgetput_longopts,
|
getopt32: remove applet_long_options
FEATURE_GETOPT_LONG made dependent on LONG_OPTS.
The folloving options are removed, now LONG_OPTS enables long options
for affected applets:
FEATURE_ENV_LONG_OPTIONS FEATURE_EXPAND_LONG_OPTIONS
FEATURE_UNEXPAND_LONG_OPTIONS FEATURE_MKDIR_LONG_OPTIONS
FEATURE_MV_LONG_OPTIONS FEATURE_RMDIR_LONG_OPTIONS
FEATURE_ADDGROUP_LONG_OPTIONS FEATURE_ADDUSER_LONG_OPTIONS
FEATURE_HWCLOCK_LONG_OPTIONS FEATURE_NSENTER_LONG_OPTS
FEATURE_CHCON_LONG_OPTIONS FEATURE_RUNCON_LONG_OPTIONS
They either had a small number of long options, or their long options are
essential.
Example: upstream addgroup and adduser have ONLY longopts,
we should probably go further and get rid
of non-standard short options.
To this end, make addgroup and adduser "select LONG_OPTS".
We had this breakage caused by us even in our own package!
#if ENABLE_LONG_OPTS || !ENABLE_ADDGROUP
/* We try to use --gid, not -g, because "standard" addgroup
* has no short option -g, it has only long --gid.
*/
argv[1] = (char*)"--gid";
#else
/* Breaks if system in fact does NOT use busybox addgroup */
argv[1] = (char*)"-g";
#endif
xargs: its lone longopt no longer depends on DESKTOP, only on LONG_OPTS.
hwclock TODO: get rid of incompatible -t, -l aliases to --systz, --localtime
Shorten help texts by omitting long option when short opt alternative exists.
Reduction of size comes from the fact that store of an immediate
(an address of longopts) to a fixed address (global variable)
is a longer insn than pushing that immediate or passing it in a register.
This effect is CPU-agnostic.
function old new delta
getopt32 1350 22 -1328
vgetopt32 - 1318 +1318
getopt32long - 24 +24
tftpd_main 562 567 +5
scan_recursive 376 380 +4
collect_cpu 545 546 +1
date_main 1096 1095 -1
hostname_main 262 259 -3
uname_main 259 255 -4
setpriv_main 362 358 -4
rmdir_main 191 187 -4
mv_main 562 558 -4
ipcalc_main 548 544 -4
ifenslave_main 641 637 -4
gzip_main 192 188 -4
gunzip_main 77 73 -4
fsfreeze_main 81 77 -4
flock_main 318 314 -4
deluser_main 337 333 -4
cp_main 374 370 -4
chown_main 175 171 -4
applet_long_options 4 - -4
xargs_main 894 889 -5
wget_main 2540 2535 -5
udhcpc_main 2767 2762 -5
touch_main 436 431 -5
tar_main 1014 1009 -5
start_stop_daemon_main 1033 1028 -5
sed_main 682 677 -5
script_main 1082 1077 -5
run_parts_main 330 325 -5
rtcwake_main 459 454 -5
od_main 2169 2164 -5
nl_main 201 196 -5
modprobe_main 773 768 -5
mkdir_main 160 155 -5
ls_main 568 563 -5
install_main 773 768 -5
hwclock_main 411 406 -5
getopt_main 622 617 -5
fstrim_main 256 251 -5
env_main 198 193 -5
dumpleases_main 635 630 -5
dpkg_main 3991 3986 -5
diff_main 1355 1350 -5
cryptpw_main 233 228 -5
cpio_main 593 588 -5
conspy_main 1135 1130 -5
chpasswd_main 313 308 -5
adduser_main 887 882 -5
addgroup_main 416 411 -5
ftpgetput_main 351 345 -6
get_terminal_width_height 242 234 -8
expand_main 690 680 -10
static.expand_longopts 18 - -18
static.unexpand_longopts 27 - -27
mkdir_longopts 28 - -28
env_longopts 30 - -30
static.ifenslave_longopts 34 - -34
mv_longopts 46 - -46
static.rmdir_longopts 48 - -48
packed_usage 31739 31687 -52
------------------------------------------------------------------------------
(add/remove: 2/8 grow/shrink: 3/49 up/down: 1352/-1840) Total: -488 bytes
text data bss dec hex filename
915681 485 6880 923046 e15a6 busybox_old
915428 485 6876 922789 e14a5 busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-08 20:08:18 +05:30
|
|
|
#else
|
2017-08-09 01:25:02 +05:30
|
|
|
getopt32(argv, OPTSTRING,
|
2006-11-29 16:39:43 +05:30
|
|
|
#endif
|
getopt32: remove applet_long_options
FEATURE_GETOPT_LONG made dependent on LONG_OPTS.
The folloving options are removed, now LONG_OPTS enables long options
for affected applets:
FEATURE_ENV_LONG_OPTIONS FEATURE_EXPAND_LONG_OPTIONS
FEATURE_UNEXPAND_LONG_OPTIONS FEATURE_MKDIR_LONG_OPTIONS
FEATURE_MV_LONG_OPTIONS FEATURE_RMDIR_LONG_OPTIONS
FEATURE_ADDGROUP_LONG_OPTIONS FEATURE_ADDUSER_LONG_OPTIONS
FEATURE_HWCLOCK_LONG_OPTIONS FEATURE_NSENTER_LONG_OPTS
FEATURE_CHCON_LONG_OPTIONS FEATURE_RUNCON_LONG_OPTIONS
They either had a small number of long options, or their long options are
essential.
Example: upstream addgroup and adduser have ONLY longopts,
we should probably go further and get rid
of non-standard short options.
To this end, make addgroup and adduser "select LONG_OPTS".
We had this breakage caused by us even in our own package!
#if ENABLE_LONG_OPTS || !ENABLE_ADDGROUP
/* We try to use --gid, not -g, because "standard" addgroup
* has no short option -g, it has only long --gid.
*/
argv[1] = (char*)"--gid";
#else
/* Breaks if system in fact does NOT use busybox addgroup */
argv[1] = (char*)"-g";
#endif
xargs: its lone longopt no longer depends on DESKTOP, only on LONG_OPTS.
hwclock TODO: get rid of incompatible -t, -l aliases to --systz, --localtime
Shorten help texts by omitting long option when short opt alternative exists.
Reduction of size comes from the fact that store of an immediate
(an address of longopts) to a fixed address (global variable)
is a longer insn than pushing that immediate or passing it in a register.
This effect is CPU-agnostic.
function old new delta
getopt32 1350 22 -1328
vgetopt32 - 1318 +1318
getopt32long - 24 +24
tftpd_main 562 567 +5
scan_recursive 376 380 +4
collect_cpu 545 546 +1
date_main 1096 1095 -1
hostname_main 262 259 -3
uname_main 259 255 -4
setpriv_main 362 358 -4
rmdir_main 191 187 -4
mv_main 562 558 -4
ipcalc_main 548 544 -4
ifenslave_main 641 637 -4
gzip_main 192 188 -4
gunzip_main 77 73 -4
fsfreeze_main 81 77 -4
flock_main 318 314 -4
deluser_main 337 333 -4
cp_main 374 370 -4
chown_main 175 171 -4
applet_long_options 4 - -4
xargs_main 894 889 -5
wget_main 2540 2535 -5
udhcpc_main 2767 2762 -5
touch_main 436 431 -5
tar_main 1014 1009 -5
start_stop_daemon_main 1033 1028 -5
sed_main 682 677 -5
script_main 1082 1077 -5
run_parts_main 330 325 -5
rtcwake_main 459 454 -5
od_main 2169 2164 -5
nl_main 201 196 -5
modprobe_main 773 768 -5
mkdir_main 160 155 -5
ls_main 568 563 -5
install_main 773 768 -5
hwclock_main 411 406 -5
getopt_main 622 617 -5
fstrim_main 256 251 -5
env_main 198 193 -5
dumpleases_main 635 630 -5
dpkg_main 3991 3986 -5
diff_main 1355 1350 -5
cryptpw_main 233 228 -5
cpio_main 593 588 -5
conspy_main 1135 1130 -5
chpasswd_main 313 308 -5
adduser_main 887 882 -5
addgroup_main 416 411 -5
ftpgetput_main 351 345 -6
get_terminal_width_height 242 234 -8
expand_main 690 680 -10
static.expand_longopts 18 - -18
static.unexpand_longopts 27 - -27
mkdir_longopts 28 - -28
env_longopts 30 - -30
static.ifenslave_longopts 34 - -34
mv_longopts 46 - -46
static.rmdir_longopts 48 - -48
packed_usage 31739 31687 -52
------------------------------------------------------------------------------
(add/remove: 2/8 grow/shrink: 3/49 up/down: 1352/-1840) Total: -488 bytes
text data bss dec hex filename
915681 485 6880 923046 e15a6 busybox_old
915428 485 6876 922789 e14a5 busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-08 20:08:18 +05:30
|
|
|
&user, &password, &port, &verbose_flag, &do_continue
|
|
|
|
);
|
2007-01-04 03:25:50 +05:30
|
|
|
argv += optind;
|
2003-12-20 11:13:34 +05:30
|
|
|
|
2003-11-04 02:50:18 +05:30
|
|
|
/* We want to do exactly _one_ DNS lookup, since some
|
|
|
|
* sites (i.e. ftp.us.debian.org) use round-robin DNS
|
|
|
|
* and we want to connect to only one IP... */
|
2008-03-29 13:07:42 +05:30
|
|
|
lsa = xhost2sockaddr(argv[0], bb_lookup_port(port, "tcp", 21));
|
2003-11-04 02:50:18 +05:30
|
|
|
if (verbose_flag) {
|
2007-01-22 15:06:41 +05:30
|
|
|
printf("Connecting to %s (%s)\n", argv[0],
|
2008-03-29 13:07:42 +05:30
|
|
|
xmalloc_sockaddr2dotted(&lsa->u.sa));
|
2003-11-04 02:50:18 +05:30
|
|
|
}
|
|
|
|
|
2008-03-29 13:10:35 +05:30
|
|
|
ftp_login();
|
2009-10-24 03:04:43 +05:30
|
|
|
return ftp_action(argv[1], argv[2] ? argv[2] : argv[1]);
|
2002-12-13 08:13:50 +05:30
|
|
|
}
|