diff options
Diffstat (limited to 'networking/ftpd.c')
-rw-r--r-- | networking/ftpd.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/networking/ftpd.c b/networking/ftpd.c index 2351d6dd3..8345ae67c 100644 --- a/networking/ftpd.c +++ b/networking/ftpd.c | |||
@@ -377,7 +377,7 @@ ftpdataio_get_pasv_fd(void) | |||
377 | return remote_fd; | 377 | return remote_fd; |
378 | } | 378 | } |
379 | 379 | ||
380 | setsockopt(remote_fd, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1)); | 380 | setsockopt_keepalive(remote_fd); |
381 | return remote_fd; | 381 | return remote_fd; |
382 | } | 382 | } |
383 | 383 | ||
@@ -1186,11 +1186,11 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv) | |||
1186 | , SIG_IGN); | 1186 | , SIG_IGN); |
1187 | 1187 | ||
1188 | /* Set up options on the command socket (do we need these all? why?) */ | 1188 | /* Set up options on the command socket (do we need these all? why?) */ |
1189 | setsockopt(STDIN_FILENO, IPPROTO_TCP, TCP_NODELAY, &const_int_1, sizeof(const_int_1)); | 1189 | setsockopt_1(STDIN_FILENO, IPPROTO_TCP, TCP_NODELAY); |
1190 | setsockopt(STDIN_FILENO, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1)); | 1190 | setsockopt_keepalive(STDIN_FILENO); |
1191 | /* Telnet protocol over command link may send "urgent" data, | 1191 | /* Telnet protocol over command link may send "urgent" data, |
1192 | * we prefer it to be received in the "normal" data stream: */ | 1192 | * we prefer it to be received in the "normal" data stream: */ |
1193 | setsockopt(STDIN_FILENO, SOL_SOCKET, SO_OOBINLINE, &const_int_1, sizeof(const_int_1)); | 1193 | setsockopt_1(STDIN_FILENO, SOL_SOCKET, SO_OOBINLINE); |
1194 | 1194 | ||
1195 | WRITE_OK(FTP_GREET); | 1195 | WRITE_OK(FTP_GREET); |
1196 | signal(SIGALRM, timeout_handler); | 1196 | signal(SIGALRM, timeout_handler); |
@@ -1223,11 +1223,26 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv) | |||
1223 | #endif | 1223 | #endif |
1224 | argv += optind; | 1224 | argv += optind; |
1225 | if (argv[0]) { | 1225 | if (argv[0]) { |
1226 | const char *basedir = argv[0]; | ||
1226 | #if !BB_MMU | 1227 | #if !BB_MMU |
1227 | G.root_fd = xopen("/", O_RDONLY | O_DIRECTORY); | 1228 | G.root_fd = xopen("/", O_RDONLY | O_DIRECTORY); |
1228 | close_on_exec_on(G.root_fd); | 1229 | close_on_exec_on(G.root_fd); |
1229 | #endif | 1230 | #endif |
1230 | xchroot(argv[0]); | 1231 | if (chroot(basedir) == 0) |
1232 | basedir = "/"; | ||
1233 | #if !BB_MMU | ||
1234 | else { | ||
1235 | close(G.root_fd); | ||
1236 | G.root_fd = -1; | ||
1237 | } | ||
1238 | #endif | ||
1239 | /* | ||
1240 | * If chroot failed, assume that we aren't root, | ||
1241 | * and at least chdir to the specified DIR | ||
1242 | * (older versions were dying with error message). | ||
1243 | * If chroot worked, move current dir to new "/": | ||
1244 | */ | ||
1245 | xchdir(basedir); | ||
1231 | } | 1246 | } |
1232 | 1247 | ||
1233 | #if ENABLE_FEATURE_FTP_AUTHENTICATION | 1248 | #if ENABLE_FEATURE_FTP_AUTHENTICATION |