2 * User FTP Server, Share folders over FTP without being root.
3 * Copyright (C) 2008 Isaac Jurado
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option) any later
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 # include <sys/stat.h>
30 * Change the current working directory. In practice, only the FTP path is
31 * modified; without any chdir() call. This way chroot emulation is achieved:
32 * by explicitly controlling all paths.
34 * Even though the process working directory never changes, the issued path is
35 * checked for existance in order to succeed. Also, any client trie to traverse
36 * the root by issuing ".." will be silently ignored, as expand_arg() swallows
37 * every "." and ".." component.
39 void change_dir (void)
46 reply_c("501 Argument required.\r\n");
51 e
= lstat(SS
.arg
, &s
);
52 if (e
== -1 || !S_ISDIR(s
.st_mode
))
55 error("Stating directory %s", SS
.arg
);
57 warning("Path %s is not a directory", SS
.arg
);
58 reply_c("550 Could not change directory.\r\n");
64 * Because we converted "./" to "." in expand_arg.c (Hasefroch
65 * idiot), now we must take care in reverting the change or we
66 * will brake future CWD and PWD responses.
75 memcpy(SS
.cwd
, SS
.arg
, l
);
77 debug("Directory changed to %s", SS
.cwd
);
78 reply_c("250 Directory changed.\r\n");