diff options
author | Andrey Mozzhuhin <amozzhuhin@yandex.ru> | 2017-01-24 23:02:04 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-01-24 23:04:25 +0100 |
commit | 2181fb4af8680730e0157310ffeeb3a35768beb0 (patch) | |
tree | 916974edafb3290da2c90fb38b9f39dd56cdfb2a | |
parent | dff9fefd500401ad7821c9890fee4c3fb88f64eb (diff) | |
download | busybox-w32-2181fb4af8680730e0157310ffeeb3a35768beb0.tar.gz busybox-w32-2181fb4af8680730e0157310ffeeb3a35768beb0.tar.bz2 busybox-w32-2181fb4af8680730e0157310ffeeb3a35768beb0.zip |
ftpd: new option -a ANON_USER to allow anonymous logins
Anonymous ftpd login is useful even when ftpd authentication feature
is enabled. Anonymous logins provide simple password-less connection
for FTP clients.
To allow password-less connection user command line option '-a USER' is
added. This option specifies the system user to use when
'anonymous' username is given in USER command. No password is required
in this case.
function old new delta
ftpd_main 2164 2232 +68
packed_usage 31015 31046 +31
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 99/0) Total: 99 bytes
Signed-off-by: Andrey Mozzhuhin <amozzhuhin@yandex.ru>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/ftpd.c | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/networking/ftpd.c b/networking/ftpd.c index a4626c0b5..104d414de 100644 --- a/networking/ftpd.c +++ b/networking/ftpd.c | |||
@@ -47,20 +47,26 @@ | |||
47 | //kbuild:lib-$(CONFIG_FTPD) += ftpd.o | 47 | //kbuild:lib-$(CONFIG_FTPD) += ftpd.o |
48 | 48 | ||
49 | //usage:#define ftpd_trivial_usage | 49 | //usage:#define ftpd_trivial_usage |
50 | //usage: "[-wvS] [-t N] [-T N] [DIR]" | 50 | //usage: "[-wvS]"IF_FEATURE_FTPD_AUTHENTICATION(" [-a USER]")" [-t N] [-T N] [DIR]" |
51 | //usage:#define ftpd_full_usage "\n\n" | 51 | //usage:#define ftpd_full_usage "\n\n" |
52 | //usage: "Anonymous FTP server\n" | 52 | //usage: IF_NOT_FEATURE_FTPD_AUTHENTICATION( |
53 | //usage: "\n" | 53 | //usage: "Anonymous FTP server. Accesses by clients occur under ftpd's UID.\n" |
54 | //usage: "ftpd should be used as an inetd service.\n" | 54 | //usage: ) |
55 | //usage: "ftpd's line for inetd.conf:\n" | 55 | //usage: IF_FEATURE_FTPD_AUTHENTICATION( |
56 | //usage: "FTP server. " | ||
57 | //usage: ) | ||
58 | //usage: "Chroots to DIR, if this fails (run by non-root), cds to it.\n" | ||
59 | //usage: "Should be used as inetd service, inetd.conf line:\n" | ||
56 | //usage: " 21 stream tcp nowait root ftpd ftpd /files/to/serve\n" | 60 | //usage: " 21 stream tcp nowait root ftpd ftpd /files/to/serve\n" |
57 | //usage: "It also can be ran from tcpsvd:\n" | 61 | //usage: "Can be run from tcpsvd:\n" |
58 | //usage: " tcpsvd -vE 0.0.0.0 21 ftpd /files/to/serve\n" | 62 | //usage: " tcpsvd -vE 0.0.0.0 21 ftpd /files/to/serve\n" |
59 | //usage: "\n -w Allow upload" | 63 | //usage: "\n -w Allow upload" |
60 | //usage: "\n -v Log errors to stderr. -vv: verbose log" | 64 | //usage: "\n -v Log errors to stderr. -vv: verbose log" |
61 | //usage: "\n -S Log errors to syslog. -SS: verbose log" | 65 | //usage: "\n -S Log errors to syslog. -SS: verbose log" |
66 | //usage: IF_FEATURE_FTPD_AUTHENTICATION( | ||
67 | //usage: "\n -a USER Enable 'anonymous' login and map it to USER" | ||
68 | //usage: ) | ||
62 | //usage: "\n -t,-T Idle and absolute timeouts" | 69 | //usage: "\n -t,-T Idle and absolute timeouts" |
63 | //usage: "\n DIR Change root to this directory" | ||
64 | 70 | ||
65 | #include "libbb.h" | 71 | #include "libbb.h" |
66 | #include "common_bufsiz.h" | 72 | #include "common_bufsiz.h" |
@@ -1154,6 +1160,7 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv) | |||
1154 | { | 1160 | { |
1155 | #if ENABLE_FEATURE_FTPD_AUTHENTICATION | 1161 | #if ENABLE_FEATURE_FTPD_AUTHENTICATION |
1156 | struct passwd *pw = NULL; | 1162 | struct passwd *pw = NULL; |
1163 | char *anon_opt = NULL; | ||
1157 | #endif | 1164 | #endif |
1158 | unsigned abs_timeout; | 1165 | unsigned abs_timeout; |
1159 | unsigned verbose_S; | 1166 | unsigned verbose_S; |
@@ -1166,12 +1173,18 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv) | |||
1166 | G.timeout = 2 * 60; | 1173 | G.timeout = 2 * 60; |
1167 | opt_complementary = "vv:SS"; | 1174 | opt_complementary = "vv:SS"; |
1168 | #if BB_MMU | 1175 | #if BB_MMU |
1169 | opts = getopt32(argv, "vS" IF_FEATURE_FTPD_WRITE("w") "t:+T:+", &G.timeout, &abs_timeout, &G.verbose, &verbose_S); | 1176 | opts = getopt32(argv, "vS" |
1177 | IF_FEATURE_FTPD_WRITE("w") "t:+T:+" IF_FEATURE_FTPD_AUTHENTICATION("a:"), | ||
1178 | &G.timeout, &abs_timeout, IF_FEATURE_FTPD_AUTHENTICATION(&anon_opt,) | ||
1179 | &G.verbose, &verbose_S); | ||
1170 | #else | 1180 | #else |
1171 | opts = getopt32(argv, "l1AvS" IF_FEATURE_FTPD_WRITE("w") "t:+T:+", &G.timeout, &abs_timeout, &G.verbose, &verbose_S); | 1181 | opts = getopt32(argv, "l1AvS" |
1182 | IF_FEATURE_FTPD_WRITE("w") "t:+T:+" IF_FEATURE_FTPD_AUTHENTICATION("a:"), | ||
1183 | &G.timeout, &abs_timeout, IF_FEATURE_FTPD_AUTHENTICATION(&anon_opt,) | ||
1184 | &G.verbose, &verbose_S); | ||
1172 | if (opts & (OPT_l|OPT_1)) { | 1185 | if (opts & (OPT_l|OPT_1)) { |
1173 | /* Our secret backdoor to ls */ | 1186 | /* Our secret backdoor to ls */ |
1174 | /* TODO: pass --group-directories-first? would be nice, but ls doesn't do that yet */ | 1187 | /* TODO: pass --group-directories-first? */ |
1175 | if (fchdir(3) != 0) | 1188 | if (fchdir(3) != 0) |
1176 | _exit(127); | 1189 | _exit(127); |
1177 | /* memset(&G, 0, sizeof(G)); - ls_main does it */ | 1190 | /* memset(&G, 0, sizeof(G)); - ls_main does it */ |
@@ -1234,7 +1247,12 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv) | |||
1234 | #if ENABLE_FEATURE_FTPD_AUTHENTICATION | 1247 | #if ENABLE_FEATURE_FTPD_AUTHENTICATION |
1235 | while (1) { | 1248 | while (1) { |
1236 | uint32_t cmdval = cmdio_get_cmd_and_arg(); | 1249 | uint32_t cmdval = cmdio_get_cmd_and_arg(); |
1237 | if (cmdval == const_USER) { | 1250 | if (cmdval == const_USER) { |
1251 | if (anon_opt && strcmp(G.ftp_arg, "anonymous") == 0) { | ||
1252 | pw = getpwnam(anon_opt); | ||
1253 | if (pw) | ||
1254 | break; /* does not even ask for password */ | ||
1255 | } | ||
1238 | pw = getpwnam(G.ftp_arg); | 1256 | pw = getpwnam(G.ftp_arg); |
1239 | cmdio_write_raw(STR(FTP_GIVEPWORD)" Please specify password\r\n"); | 1257 | cmdio_write_raw(STR(FTP_GIVEPWORD)" Please specify password\r\n"); |
1240 | } else if (cmdval == const_PASS) { | 1258 | } else if (cmdval == const_PASS) { |