aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-04-07 14:02:21 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-04-07 14:02:21 +0200
commit8edaaced16664503e89d9be80637e17dedc56ab9 (patch)
tree944e3ea4deb9a859700e382007873b5942a02e81
parent32c3e3a44cb6ae2b0ff949e9f60fa0405f081dc3 (diff)
downloadbusybox-w32-8edaaced16664503e89d9be80637e17dedc56ab9.tar.gz
busybox-w32-8edaaced16664503e89d9be80637e17dedc56ab9.tar.bz2
busybox-w32-8edaaced16664503e89d9be80637e17dedc56ab9.zip
ftpd: added -A option to disable all authentication, closes 10921
function old new delta packed_usage 32745 32777 +32 ftpd_main 2162 2156 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 32/-6) Total: 26 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/ftpd.c69
1 files changed, 40 insertions, 29 deletions
diff --git a/networking/ftpd.c b/networking/ftpd.c
index e289a6051..4ecdb4121 100644
--- a/networking/ftpd.c
+++ b/networking/ftpd.c
@@ -57,7 +57,7 @@
57//usage: "[-wvS]"IF_FEATURE_FTPD_AUTHENTICATION(" [-a USER]")" [-t N] [-T N] [DIR]" 57//usage: "[-wvS]"IF_FEATURE_FTPD_AUTHENTICATION(" [-a USER]")" [-t N] [-T N] [DIR]"
58//usage:#define ftpd_full_usage "\n\n" 58//usage:#define ftpd_full_usage "\n\n"
59//usage: IF_NOT_FEATURE_FTPD_AUTHENTICATION( 59//usage: IF_NOT_FEATURE_FTPD_AUTHENTICATION(
60//usage: "Anonymous FTP server. Accesses by clients occur under ftpd's UID.\n" 60//usage: "Anonymous FTP server. Client access occurs under ftpd's UID.\n"
61//usage: ) 61//usage: )
62//usage: IF_FEATURE_FTPD_AUTHENTICATION( 62//usage: IF_FEATURE_FTPD_AUTHENTICATION(
63//usage: "FTP server. " 63//usage: "FTP server. "
@@ -66,9 +66,11 @@
66//usage: "Should be used as inetd service, inetd.conf line:\n" 66//usage: "Should be used as inetd service, inetd.conf line:\n"
67//usage: " 21 stream tcp nowait root ftpd ftpd /files/to/serve\n" 67//usage: " 21 stream tcp nowait root ftpd ftpd /files/to/serve\n"
68//usage: "Can be run from tcpsvd:\n" 68//usage: "Can be run from tcpsvd:\n"
69//usage: " tcpsvd -vE 0.0.0.0 21 ftpd /files/to/serve\n" 69//usage: " tcpsvd -vE 0.0.0.0 21 ftpd /files/to/serve"
70//usage: "\n"
70//usage: "\n -w Allow upload" 71//usage: "\n -w Allow upload"
71//usage: IF_FEATURE_FTPD_AUTHENTICATION( 72//usage: IF_FEATURE_FTPD_AUTHENTICATION(
73//usage: "\n -A No login required, client access occurs under ftpd's UID"
72//usage: "\n -a USER Enable 'anonymous' login and map it to USER" 74//usage: "\n -a USER Enable 'anonymous' login and map it to USER"
73//usage: ) 75//usage: )
74//usage: "\n -v Log errors to stderr. -vv: verbose log" 76//usage: "\n -v Log errors to stderr. -vv: verbose log"
@@ -1157,9 +1159,12 @@ enum {
1157 OPT_1 = (1 << 1), 1159 OPT_1 = (1 << 1),
1158 OPT_A = (1 << 2), 1160 OPT_A = (1 << 2),
1159#endif 1161#endif
1160 OPT_v = (1 << ((!BB_MMU) * 3 + 0)), 1162 BIT_v = (!BB_MMU) * 3,
1161 OPT_S = (1 << ((!BB_MMU) * 3 + 1)), 1163 OPT_v = (1 << (BIT_v + 0)),
1162 OPT_w = (1 << ((!BB_MMU) * 3 + 2)) * ENABLE_FEATURE_FTPD_WRITE, 1164 OPT_S = (1 << (BIT_v + 1)),
1165 OPT_w = (1 << (BIT_v + 2)) * ENABLE_FEATURE_FTPD_WRITE,
1166 BIT_A = BIT_v + 2 + ENABLE_FEATURE_FTPD_WRITE,
1167 OPT_A = (1 << (BIT_A + 0)) * ENABLE_FEATURE_FTPD_AUTHENTICATION,
1163}; 1168};
1164 1169
1165int ftpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 1170int ftpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -1180,14 +1185,16 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
1180 G.timeout = 2 * 60; 1185 G.timeout = 2 * 60;
1181#if BB_MMU 1186#if BB_MMU
1182 opts = getopt32(argv, "^" "vS" 1187 opts = getopt32(argv, "^" "vS"
1183 IF_FEATURE_FTPD_WRITE("w") "t:+T:+" IF_FEATURE_FTPD_AUTHENTICATION("a:") 1188 IF_FEATURE_FTPD_WRITE("w") IF_FEATURE_FTPD_AUTHENTICATION("A")
1189 "t:+T:+" IF_FEATURE_FTPD_AUTHENTICATION("a:")
1184 "\0" "vv:SS", 1190 "\0" "vv:SS",
1185 &G.timeout, &abs_timeout, IF_FEATURE_FTPD_AUTHENTICATION(&anon_opt,) 1191 &G.timeout, &abs_timeout, IF_FEATURE_FTPD_AUTHENTICATION(&anon_opt,)
1186 &G.verbose, &verbose_S 1192 &G.verbose, &verbose_S
1187 ); 1193 );
1188#else 1194#else
1189 opts = getopt32(argv, "^" "l1AvS" 1195 opts = getopt32(argv, "^" "l1AvS"
1190 IF_FEATURE_FTPD_WRITE("w") "t:+T:+" IF_FEATURE_FTPD_AUTHENTICATION("a:") 1196 IF_FEATURE_FTPD_WRITE("w") IF_FEATURE_FTPD_AUTHENTICATION("A")
1197 "t:+T:+" IF_FEATURE_FTPD_AUTHENTICATION("a:")
1191 "\0" "vv:SS", 1198 "\0" "vv:SS",
1192 &G.timeout, &abs_timeout, IF_FEATURE_FTPD_AUTHENTICATION(&anon_opt,) 1199 &G.timeout, &abs_timeout, IF_FEATURE_FTPD_AUTHENTICATION(&anon_opt,)
1193 &G.verbose, &verbose_S 1200 &G.verbose, &verbose_S
@@ -1254,30 +1261,32 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
1254 signal(SIGALRM, timeout_handler); 1261 signal(SIGALRM, timeout_handler);
1255 1262
1256#if ENABLE_FEATURE_FTPD_AUTHENTICATION 1263#if ENABLE_FEATURE_FTPD_AUTHENTICATION
1257 while (1) { 1264 if (!(opts & OPT_A)) {
1258 uint32_t cmdval = cmdio_get_cmd_and_arg(); 1265 while (1) {
1259 if (cmdval == const_USER) { 1266 uint32_t cmdval = cmdio_get_cmd_and_arg();
1260 if (anon_opt && strcmp(G.ftp_arg, "anonymous") == 0) { 1267 if (cmdval == const_USER) {
1261 pw = getpwnam(anon_opt); 1268 if (anon_opt && strcmp(G.ftp_arg, "anonymous") == 0) {
1262 if (pw) 1269 pw = getpwnam(anon_opt);
1263 break; /* does not even ask for password */ 1270 if (pw)
1264 } 1271 break; /* does not even ask for password */
1265 pw = getpwnam(G.ftp_arg); 1272 }
1266 cmdio_write_raw(STR(FTP_GIVEPWORD)" Specify password\r\n"); 1273 pw = getpwnam(G.ftp_arg);
1267 } else if (cmdval == const_PASS) { 1274 cmdio_write_raw(STR(FTP_GIVEPWORD)" Specify password\r\n");
1268 if (check_password(pw, G.ftp_arg) > 0) { 1275 } else if (cmdval == const_PASS) {
1269 break; /* login success */ 1276 if (check_password(pw, G.ftp_arg) > 0) {
1277 break; /* login success */
1278 }
1279 cmdio_write_raw(STR(FTP_LOGINERR)" Login failed\r\n");
1280 pw = NULL;
1281 } else if (cmdval == const_QUIT) {
1282 WRITE_OK(FTP_GOODBYE);
1283 return 0;
1284 } else {
1285 cmdio_write_raw(STR(FTP_LOGINERR)" Login with USER+PASS\r\n");
1270 } 1286 }
1271 cmdio_write_raw(STR(FTP_LOGINERR)" Login failed\r\n");
1272 pw = NULL;
1273 } else if (cmdval == const_QUIT) {
1274 WRITE_OK(FTP_GOODBYE);
1275 return 0;
1276 } else {
1277 cmdio_write_raw(STR(FTP_LOGINERR)" Login with USER+PASS\r\n");
1278 } 1287 }
1288 WRITE_OK(FTP_LOGINOK);
1279 } 1289 }
1280 WRITE_OK(FTP_LOGINOK);
1281#endif 1290#endif
1282 1291
1283 /* Do this after auth, else /etc/passwd is not accessible */ 1292 /* Do this after auth, else /etc/passwd is not accessible */
@@ -1309,7 +1318,9 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
1309 } 1318 }
1310 1319
1311#if ENABLE_FEATURE_FTPD_AUTHENTICATION 1320#if ENABLE_FEATURE_FTPD_AUTHENTICATION
1312 change_identity(pw); 1321 if (pw)
1322 change_identity(pw);
1323 /* else: -A is in effect */
1313#endif 1324#endif
1314 1325
1315 /* RFC-959 Section 5.1 1326 /* RFC-959 Section 5.1