1 /* vi: set sw=4 ts=4: */
3 * Simple FTP daemon, based on vsftpd 2.0.7 (written by Chris Evans)
5 * Author: Adam Tkac <vonsch@gmail.com>
7 * Only subset of FTP protocol is implemented but vast majority of clients
8 * should not have any problem. You have to run this daemon via inetd.
11 * -w - enable FTP write commands
15 #include <netinet/tcp.h>
26 FTP_STATFILE_OK = 213,
35 #if ENABLE_FEATURE_FTP_WRITE
41 #if ENABLE_FEATURE_FTP_WRITE
46 #if ENABLE_FEATURE_FTP_WRITE
49 FTP_BADSENDCONN = 425,
51 FTP_BADSENDFILE = 451,
53 FTP_COMMANDNOTIMPL = 502,
63 #define mk_const4(a,b,c,d) (((a * 0x100 + b) * 0x100 + c) * 0x100 + d)
64 #define mk_const3(a,b,c) ((a * 0x100 + b) * 0x100 + c)
65 const_ALLO = mk_const4('A', 'L', 'L', 'O'),
66 const_APPE = mk_const4('A', 'P', 'P', 'E'),
67 const_CDUP = mk_const4('C', 'D', 'U', 'P'),
68 const_CWD = mk_const3('C', 'W', 'D'),
69 const_DELE = mk_const4('D', 'E', 'L', 'E'),
70 const_HELP = mk_const4('H', 'E', 'L', 'P'),
71 const_LIST = mk_const4('L', 'I', 'S', 'T'),
72 const_MKD = mk_const3('M', 'K', 'D'),
73 const_MODE = mk_const4('M', 'O', 'D', 'E'),
74 const_NLST = mk_const4('N', 'L', 'S', 'T'),
75 const_NOOP = mk_const4('N', 'O', 'O', 'P'),
76 const_PASS = mk_const4('P', 'A', 'S', 'S'),
77 const_PASV = mk_const4('P', 'A', 'S', 'V'),
78 const_PORT = mk_const4('P', 'O', 'R', 'T'),
79 const_PWD = mk_const3('P', 'W', 'D'),
80 const_QUIT = mk_const4('Q', 'U', 'I', 'T'),
81 const_REST = mk_const4('R', 'E', 'S', 'T'),
82 const_RETR = mk_const4('R', 'E', 'T', 'R'),
83 const_RMD = mk_const3('R', 'M', 'D'),
84 const_RNFR = mk_const4('R', 'N', 'F', 'R'),
85 const_RNTO = mk_const4('R', 'N', 'T', 'O'),
86 const_STAT = mk_const4('S', 'T', 'A', 'T'),
87 const_STOR = mk_const4('S', 'T', 'O', 'R'),
88 const_STOU = mk_const4('S', 'T', 'O', 'U'),
89 const_STRU = mk_const4('S', 'T', 'R', 'U'),
90 const_SYST = mk_const4('S', 'Y', 'S', 'T'),
91 const_TYPE = mk_const4('T', 'Y', 'P', 'E'),
92 const_USER = mk_const4('U', 'S', 'E', 'R'),
96 char *p_control_line_buf;
97 len_and_sockaddr *local_addr;
98 len_and_sockaddr *port_addr;
104 #if ENABLE_FEATURE_FTP_WRITE
106 smallint write_enable;
109 #define G (*(struct globals*)&bb_common_bufsiz1)
110 #define INIT_G() do { } while (0)
114 replace_text(const char *str, const char from, const char *to)
116 size_t retlen, remainlen, chunklen, tolen;
121 remainlen = strlen(str);
125 /* simply alloc strlen(str)*strlen(to). To is max 2 so it's allowed */
126 ret = xmalloc(remainlen * strlen(to) + 1);
130 found = strchr(remain, from);
132 chunklen = found - remain;
134 /* Copy chunk which doesn't contain 'from' to ret */
135 memcpy(&ret[retlen], remain, chunklen);
138 /* Now copy 'to' instead of 'from' */
139 memcpy(&ret[retlen], to, tolen);
145 * The last chunk. We are already sure that we have enough space
146 * so we can use strcpy.
148 strcpy(&ret[retlen], remain);
156 replace_char(char *str, char from, char to)
160 /* Don't use strchr here...*/
161 while ((ptr = strchr(str, from)) != NULL) {
168 str_netfd_write(const char *str, int fd)
170 xwrite(fd, str, strlen(str));
174 ftp_write_str_common(unsigned int status, const char *str, char sep)
176 char *escaped_str, *response;
179 escaped_str = replace_text(str, '\377', "\377\377");
181 response = xasprintf("%u%c%s\r\n", status, sep, escaped_str);
184 len = strlen(response);
185 replace_char(escaped_str, '\n', '\0');
187 /* Change trailing '\0' back to '\n' */
188 response[len - 1] = '\n';
189 xwrite(STDIN_FILENO, response, len);
193 cmdio_write(int status, const char *p_text)
195 ftp_write_str_common(status, p_text, ' ');
199 cmdio_write_hyphen(int status, const char *p_text)
201 ftp_write_str_common(status, p_text, '-');
205 cmdio_write_raw(const char *p_text)
207 str_netfd_write(p_text, STDIN_FILENO);
211 cmdio_get_cmd_and_arg(void)
218 G.ftp_cmp = cmd = xmalloc_reads(STDIN_FILENO, NULL, NULL);
222 * now we should change all '\0' to '\n' - xmalloc_reads will be improved,
225 len = strlen(cmd) - 1;
226 while (len >= 0 && cmd[len] == '\r') {
231 G.ftp_arg = strchr(cmd, ' ');
232 if (G.ftp_arg != NULL) {
238 cmdval = (cmdval << 8) + ((unsigned char)*cmd++ & (unsigned char)~0x20);
244 init_data_sock_params(int sock_fd)
246 struct linger linger;
250 memset(&linger, 0, sizeof(linger));
252 linger.l_linger = 32767;
254 setsockopt(sock_fd, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
255 setsockopt(sock_fd, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger));
259 ftpdataio_get_pasv_fd(void)
263 remote_fd = accept(G.pasv_listen_fd, NULL, 0);
266 cmdio_write(FTP_BADSENDCONN, "Can't establish connection");
270 init_data_sock_params(remote_fd);
275 ftpdataio_get_port_fd(void)
279 /* Do we want die or print error to client? */
280 remote_fd = xconnect_stream(G.port_addr);
282 init_data_sock_params(remote_fd);
287 ftpdataio_dispose_transfer_fd(void)
289 /* This close() blocks because we set SO_LINGER */
290 if (G.data_fd > STDOUT_FILENO) {
291 if (close(G.data_fd) < 0) {
292 /* Do it again without blocking. */
293 struct linger linger;
295 memset(&linger, 0, sizeof(linger));
296 setsockopt(G.data_fd, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger));
306 return (G.port_addr != NULL) ? 1: 0;
312 return (G.pasv_listen_fd != -1) ? 1 : 0;
316 get_remote_transfer_fd(const char *p_status_msg)
321 remote_fd = ftpdataio_get_pasv_fd();
323 remote_fd = ftpdataio_get_port_fd();
328 cmdio_write(FTP_DATACONN, p_status_msg);
335 char *cwd, *promoted_cwd, *response;
337 cwd = xrealloc_getcwd_or_warn(NULL);
341 /* We _have to_ promote each " to "" */
342 promoted_cwd = replace_text(cwd, '\"', "\"\"");
344 response = xasprintf("\"%s\"", promoted_cwd);
346 cmdio_write(FTP_PWDOK, response);
355 /* XXX Do we need check ftp_arg != NULL? */
356 retval = chdir(G.ftp_arg);
358 cmdio_write(FTP_CWDOK, "Directory changed");
360 cmdio_write(FTP_FILEFAIL, "Can't change directory");
366 G.ftp_arg = xstrdup("..");
372 data_transfer_checks_ok(void)
374 if (!pasv_active() && !port_active()) {
375 cmdio_write(FTP_BADSENDCONN, "Use PORT or PASV first");
385 if (G.port_addr != NULL)
394 if (G.pasv_listen_fd > STDOUT_FILENO)
395 close(G.pasv_listen_fd);
396 G.pasv_listen_fd = -1;
400 statbuf_getperms(const struct stat *statbuf)
403 enum { r = 'r', w = 'w', x = 'x', s = 's', S = 'S' };
406 memset(perms, '-', 10);
409 switch (statbuf->st_mode & S_IFMT) {
410 case S_IFREG: perms[0] = '-'; break;
411 case S_IFDIR: perms[0] = 'd'; break;
412 case S_IFLNK: perms[0] = 'l'; break;
413 case S_IFIFO: perms[0] = 'p'; break;
414 case S_IFSOCK: perms[0] = s; break;
415 case S_IFCHR: perms[0] = 'c'; break;
416 case S_IFBLK: perms[0] = 'b'; break;
419 if (statbuf->st_mode & S_IRUSR) perms[1] = r;
420 if (statbuf->st_mode & S_IWUSR) perms[2] = w;
421 if (statbuf->st_mode & S_IXUSR) perms[3] = x;
422 if (statbuf->st_mode & S_IRGRP) perms[4] = r;
423 if (statbuf->st_mode & S_IWGRP) perms[5] = w;
424 if (statbuf->st_mode & S_IXGRP) perms[6] = x;
425 if (statbuf->st_mode & S_IROTH) perms[7] = r;
426 if (statbuf->st_mode & S_IWOTH) perms[8] = w;
427 if (statbuf->st_mode & S_IXOTH) perms[9] = x;
428 if (statbuf->st_mode & S_ISUID) perms[3] = (perms[3] == x) ? s : S;
429 if (statbuf->st_mode & S_ISGID) perms[6] = (perms[6] == x) ? s : S;
430 if (statbuf->st_mode & S_ISVTX) perms[9] = (perms[9] == x) ? 't' : 'T';
438 write_filestats(int fd, const char *filename,
439 const struct stat *statbuf)
442 char *stats, *lnkname = NULL, *perms;
447 const char *format = "%b %d %H:%M";
449 name = bb_get_last_path_component_nostrip(filename);
451 if (statbuf != NULL) {
452 size = statbuf->st_size;
454 if (S_ISLNK(statbuf->st_mode))
455 /* Damn symlink... */
456 lnkname = xmalloc_readlink(filename);
458 tm = gmtime(&statbuf->st_mtime);
459 retval = strftime(timestr, sizeof(timestr), format, tm);
461 bb_error_msg_and_die("strftime");
463 timestr[sizeof(timestr) - 1] = '\0';
465 perms = statbuf_getperms(statbuf);
467 stats = xasprintf("%s %u\tftp ftp %"OFF_FMT"u\t%s %s",
468 perms, (int) statbuf->st_nlink,
469 size, timestr, name);
473 stats = xstrdup(name);
475 str_netfd_write(stats, fd);
477 if (lnkname != NULL) {
478 str_netfd_write(" -> ", fd);
479 str_netfd_write(lnkname, fd);
482 str_netfd_write("\r\n", fd);
486 write_dirstats(int fd, const char *dname, int details)
489 struct dirent *dirent;
493 dir = xopendir(dname);
496 dirent = readdir(dir);
500 /* Ignore . and .. */
501 if (dirent->d_name[0] == '.') {
502 if (dirent->d_name[1] == '\0'
503 || (dirent->d_name[1] == '.' && dirent->d_name[2] == '\0')
510 filename = xasprintf("%s/%s", dname, dirent->d_name);
511 if (lstat(filename, &statbuf) != 0) {
516 filename = xstrdup(dirent->d_name);
518 write_filestats(fd, filename, details ? &statbuf : NULL);
529 int bind_retries = 10;
531 enum { min_port = 1024, max_port = 65535 };
532 char *addr, *wire_addr, *response;
536 G.pasv_listen_fd = xsocket(G.local_addr->u.sa.sa_family, SOCK_STREAM, 0);
537 setsockopt_reuseaddr(G.pasv_listen_fd);
539 /* TODO bind() with port == 0 and then call getsockname */
540 while (--bind_retries) {
541 port = rand() % max_port;
542 if (port < min_port) {
546 set_nport(G.local_addr, htons(port));
547 /* We don't want to use xbind, it'll die if port is in use */
548 if (bind(G.pasv_listen_fd, &G.local_addr->u.sa, G.local_addr->len) != 0) {
549 /* do we want check if errno == EADDRINUSE ? */
552 xlisten(G.pasv_listen_fd, 1);
557 bb_error_msg_and_die("can't create pasv socket");
559 addr = xmalloc_sockaddr2dotted_noport(&G.local_addr->u.sa);
560 wire_addr = replace_text(addr, '.', ",");
563 response = xasprintf("Entering Passive Mode (%s,%u,%u)",
564 wire_addr, (int)(port >> 8), (int)(port & 255));
566 cmdio_write(FTP_PASVOK, response);
575 int trans_ret, retval;
578 off_t offset = G.restart_pos;
583 if (!data_transfer_checks_ok())
586 /* XXX Do we need check if ftp_arg != NULL? */
587 opened_file = open(G.ftp_arg, O_RDONLY | O_NONBLOCK);
588 if (opened_file < 0) {
589 cmdio_write(FTP_FILEFAIL, "Can't open file");
593 retval = fstat(opened_file, &statbuf);
594 if (retval < 0 || !S_ISREG(statbuf.st_mode)) {
595 /* Note - pretend open failed */
596 cmdio_write(FTP_FILEFAIL, "Can't open file");
600 /* Now deactive O_NONBLOCK, otherwise we have a problem on DMAPI filesystems
603 ndelay_off(opened_file);
605 /* Set the download offset (from REST) if any */
607 xlseek(opened_file, offset, SEEK_SET);
609 response = xasprintf(
610 "Opening BINARY mode data connection for (%s %"OFF_FMT"u bytes).",
611 G.ftp_arg, statbuf.st_size);
613 remote_fd = get_remote_transfer_fd(response);
616 goto port_pasv_cleanup_out;
618 trans_ret = bb_copyfd_eof(opened_file, remote_fd);
619 ftpdataio_dispose_transfer_fd();
621 cmdio_write(FTP_BADSENDFILE, "Error sending local file");
623 cmdio_write(FTP_TRANSFEROK, "File sent OK");
625 port_pasv_cleanup_out:
633 handle_dir_common(int full_details, int stat_cmd)
638 if (!stat_cmd && !data_transfer_checks_ok())
643 cmdio_write_hyphen(FTP_STATFILE_OK, "Status follows:");
645 fd = get_remote_transfer_fd("Here comes the directory listing");
650 if (G.ftp_arg != NULL) {
651 if (lstat(G.ftp_arg, &statbuf) != 0) {
652 /* Dir doesn't exist => return ok to client */
655 if (S_ISREG(statbuf.st_mode) || S_ISLNK(statbuf.st_mode))
656 write_filestats(fd, G.ftp_arg, &statbuf);
657 else if (S_ISDIR(statbuf.st_mode))
658 write_dirstats(fd, G.ftp_arg, full_details);
660 write_dirstats(fd, ".", full_details);
663 /* Well, if we can't open directory/file it doesn't matter */
665 ftpdataio_dispose_transfer_fd();
668 cmdio_write(FTP_TRANSFEROK, "OK");
670 cmdio_write(FTP_STATFILE_OK, "End of status");
676 handle_dir_common(1, 0);
683 && ( ((G.ftp_arg[0] | 0x20) == 'i' && G.ftp_arg[1] == '\0')
684 || !strcasecmp(G.ftp_arg, "L8")
685 || !strcasecmp(G.ftp_arg, "L 8")
688 cmdio_write(FTP_TYPEOK, "Switching to Binary mode");
690 cmdio_write(FTP_BADCMD, "Unrecognised TYPE command");
698 char *raw = NULL, *port_part;
699 len_and_sockaddr *lsa = NULL;
704 if (G.ftp_arg == NULL)
707 raw = replace_text(G.ftp_arg, ',', ".");
709 port_part = strrchr(raw, '.');
710 if (port_part == NULL)
713 port = xatou16(&port_part[1]);
716 port_part = strrchr(raw, '.');
717 if (port_part == NULL)
720 port |= xatou16(&port_part[1]) << 8;
723 lsa = xdotted2sockaddr(raw, port);
729 cmdio_write(FTP_BADCMD, "Illegal PORT command");
734 cmdio_write(FTP_PORTOK, "PORT command successful. Consider using PASV");
737 #if ENABLE_FEATURE_FTP_WRITE
739 handle_upload_common(int is_append, int is_unique)
741 char *template = NULL;
747 fileflags = O_CREAT | O_WRONLY | O_APPEND,
750 off_t offset = G.restart_pos;
753 if (!data_transfer_checks_ok())
757 template = xstrdup("uniq.XXXXXX");
759 * XXX Use mkostemp here? vsftpd opens file with O_CREAT, O_WRONLY,
760 * O_APPEND and O_EXCL flags...
762 new_file_fd = mkstemp(template);
764 /* XXX Do we need check if ftp_arg != NULL? */
765 if (!is_append && offset == 0)
766 new_file_fd = open(G.ftp_arg, O_CREAT | O_WRONLY | O_APPEND | O_NONBLOCK | O_TRUNC, 0666);
768 new_file_fd = open(G.ftp_arg, O_CREAT | O_WRONLY | O_APPEND | O_NONBLOCK, 0666);
771 if (new_file_fd < 0) {
772 cmdio_write(FTP_UPLOADFAIL, "Can't create file");
776 if (!is_append && offset != 0) {
777 /* warning, allows seek past end of file! Check for seek > size? */
778 xlseek(new_file_fd, offset, SEEK_SET);
782 char *resp = xasprintf("FILE: %s", template);
783 remote_fd = get_remote_transfer_fd(resp);
787 remote_fd = get_remote_transfer_fd("Ok to send data");
792 trans_ret = bb_copyfd_eof(remote_fd, new_file_fd);
793 ftpdataio_dispose_transfer_fd();
796 cmdio_write(FTP_BADSENDFILE, "Failure writing to local file");
798 cmdio_write(FTP_TRANSFEROK, "File receive OK");
809 handle_upload_common(0, 0);
817 /* Do we need check if ftp_arg != NULL? */
818 retval = mkdir(G.ftp_arg, 0770);
820 cmdio_write(FTP_FILEFAIL, "Create directory operation failed");
824 cmdio_write(FTP_MKDIROK, "created");
832 /* Do we need check if ftp_arg != NULL? */
833 retval = rmdir(G.ftp_arg);
835 cmdio_write(FTP_FILEFAIL, "rmdir failed");
837 cmdio_write(FTP_RMDIROK, "rmdir successful");
845 /* Do we need check if ftp_arg != NULL? */
846 retval = unlink(G.ftp_arg);
848 cmdio_write(FTP_FILEFAIL, "Delete failed");
850 cmdio_write(FTP_DELEOK, "Delete successful");
852 #endif /* ENABLE_FEATURE_FTP_WRITE */
857 /* When ftp_arg == NULL simply restart from beginning */
858 G.restart_pos = xatoi_u(G.ftp_arg);
859 cmdio_write(FTP_RESTOK, "Restart OK");
862 #if ENABLE_FEATURE_FTP_WRITE
869 /* Clear old value */
870 free(G.rnfr_filename);
872 /* Does it exist? Do we need check if ftp_arg != NULL? */
873 retval = stat(G.ftp_arg, &statbuf);
876 G.rnfr_filename = xstrdup(G.ftp_arg);
877 cmdio_write(FTP_RNFROK, "Ready for RNTO");
879 cmdio_write(FTP_FILEFAIL, "RNFR command failed");
887 /* If we didn't get a RNFR, throw a wobbly */
888 if (G.rnfr_filename == NULL) {
889 cmdio_write(FTP_NEEDRNFR, "RNFR required first");
893 /* XXX Do we need check if ftp_arg != NULL? */
894 retval = rename(G.rnfr_filename, G.ftp_arg);
896 free(G.rnfr_filename);
899 cmdio_write(FTP_RENAMEOK, "Rename successful");
901 cmdio_write(FTP_FILEFAIL, "Rename failed");
903 #endif /* ENABLE_FEATURE_FTP_WRITE */
908 handle_dir_common(0, 0);
911 #if ENABLE_FEATURE_FTP_WRITE
915 handle_upload_common(1, 0);
922 cmdio_write_hyphen(FTP_HELP, "Recognized commands:");
923 cmdio_write_raw(" ALLO CDUP CWD HELP LIST\r\n"
924 " MODE NLST NOOP PASS PASV PORT PWD QUIT\r\n"
925 " REST RETR STAT STRU SYST TYPE USER\r\n"
926 #if ENABLE_FEATURE_FTP_WRITE
927 " APPE DELE MKD RMD RNFR RNTO STOR STOU\r\n"
930 cmdio_write(FTP_HELP, "Help OK");
933 #if ENABLE_FEATURE_FTP_WRITE
937 handle_upload_common(0, 1);
944 cmdio_write_hyphen(FTP_STATOK, "FTP server status:");
945 cmdio_write_raw(" TYPE: BINARY\r\n");
946 cmdio_write(FTP_STATOK, "End of status");
950 handle_stat_file(void)
952 handle_dir_common(1, 1);
955 /* TODO: libbb candidate (tftp has another copy) */
956 static len_and_sockaddr *get_sock_lsa(int s)
958 len_and_sockaddr *lsa;
961 if (getsockname(s, NULL, &len) != 0)
963 lsa = xzalloc(LSA_LEN_SIZE + len);
965 getsockname(s, &lsa->u.sa, &lsa->len);
969 int ftpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
970 int ftpd_main(int argc UNUSED_PARAM, char **argv)
972 smallint user_was_specified = 0;
976 G.local_addr = get_sock_lsa(STDIN_FILENO);
978 /* This is confusing:
979 * bb_error_msg_and_die("stdin is not a socket");
982 /* Help text says that ftpd must be used as inetd service,
983 * which is by far the most usual cause of get_sock_lsa
987 logmode = LOGMODE_SYSLOG;
989 USE_FEATURE_FTP_WRITE(G.write_enable =) getopt32(argv, "" USE_FEATURE_FTP_WRITE("w"));
991 xchdir(argv[optind]);
995 // if (G.local_addr->u.sa.sa_family != AF_INET)
996 // bb_error_msg_and_die("Only IPv4 is supported");
998 /* Signals. We'll always take -EPIPE rather than a rude signal, thanks */
999 signal(SIGPIPE, SIG_IGN);
1001 /* Set up options on the command socket */
1002 setsockopt(STDIN_FILENO, IPPROTO_TCP, TCP_NODELAY, &const_int_1, sizeof(const_int_1));
1003 setsockopt(STDIN_FILENO, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
1004 setsockopt(STDIN_FILENO, SOL_SOCKET, SO_OOBINLINE, &const_int_1, sizeof(const_int_1));
1006 cmdio_write(FTP_GREET, "Welcome");
1009 uint32_t cmdval = cmdio_get_cmd_and_arg();
1011 if (cmdval == const_USER) {
1012 if (G.ftp_arg == NULL || strcasecmp(G.ftp_arg, "anonymous") != 0)
1013 cmdio_write(FTP_LOGINERR, "Server is anonymous only");
1015 user_was_specified = 1;
1016 cmdio_write(FTP_GIVEPWORD, "Please specify the password");
1018 } else if (cmdval == const_PASS) {
1019 if (user_was_specified)
1021 cmdio_write(FTP_NEEDUSER, "Login with USER");
1022 } else if (cmdval == const_QUIT) {
1023 cmdio_write(FTP_GOODBYE, "Goodbye");
1026 cmdio_write(FTP_LOGINERR,
1027 "Login with USER and PASS");
1032 cmdio_write(FTP_LOGINOK, "Login successful");
1035 uint32_t cmdval = cmdio_get_cmd_and_arg();
1037 if (cmdval == const_QUIT) {
1038 cmdio_write(FTP_GOODBYE, "Goodbye");
1041 if (cmdval == const_PWD)
1043 else if (cmdval == const_CWD)
1045 else if (cmdval == const_CDUP)
1047 else if (cmdval == const_PASV)
1049 else if (cmdval == const_RETR)
1051 else if (cmdval == const_NOOP)
1052 cmdio_write(FTP_NOOPOK, "NOOP ok");
1053 else if (cmdval == const_SYST)
1054 cmdio_write(FTP_SYSTOK, "UNIX Type: L8");
1055 else if (cmdval == const_HELP)
1057 else if (cmdval == const_LIST)
1059 else if (cmdval == const_TYPE)
1061 else if (cmdval == const_PORT)
1063 else if (cmdval == const_REST)
1065 else if (cmdval == const_NLST)
1067 #if ENABLE_FEATURE_FTP_WRITE
1068 else if (G.write_enable) {
1069 if (cmdval == const_STOR)
1071 else if (cmdval == const_MKD)
1073 else if (cmdval == const_RMD)
1075 else if (cmdval == const_DELE)
1077 else if (cmdval == const_RNFR)
1079 else if (cmdval == const_RNTO)
1081 else if (cmdval == const_APPE)
1083 else if (cmdval == const_STOU)
1087 else if (cmdval == const_STRU) {
1089 && (G.ftp_arg[0] | 0x20) == 'f'
1090 && G.ftp_arg[1] == '\0'
1092 cmdio_write(FTP_STRUOK, "Structure set to F");
1094 cmdio_write(FTP_BADSTRU, "Bad STRU command");
1096 } else if (cmdval == const_MODE) {
1098 && (G.ftp_arg[0] | 0x20) == 's'
1099 && G.ftp_arg[1] == '\0'
1101 cmdio_write(FTP_MODEOK, "Mode set to S");
1103 cmdio_write(FTP_BADMODE, "Bad MODE command");
1105 else if (cmdval == const_ALLO)
1106 cmdio_write(FTP_ALLOOK, "ALLO command ignored");
1107 else if (cmdval == const_STAT) {
1108 if (G.ftp_arg == NULL)
1112 } else if (cmdval == const_USER)
1113 cmdio_write(FTP_LOGINERR, "Can't change to another user");
1114 else if (cmdval == const_PASS)
1115 cmdio_write(FTP_LOGINOK, "Already logged in");
1116 else if (cmdval == const_STOR
1117 || cmdval == const_MKD
1118 || cmdval == const_RMD
1119 || cmdval == const_DELE
1120 || cmdval == const_RNFR
1121 || cmdval == const_RNTO
1122 || cmdval == const_APPE
1123 || cmdval == const_STOU
1125 cmdio_write(FTP_NOPERM, "Permission denied");
1127 cmdio_write(FTP_BADCMD, "Unknown command");