aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/ftpd.c40
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) {