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
26 * Change the current working directory. In practice, only the FTP path is
27 * modified; without any chdir() call. This way chroot emulation is achieved:
28 * by explicitly controlling all paths.
30 * Even though the process working directory never changes, the issued path is
31 * checked for existance in order to succeed. Also, any client trie to traverse
32 * the root by issuing ".." will be silently ignored, as expand_arg() swallows
33 * every "." and ".." component.
35 void change_dir (void)
42 reply_c("501 Argument required.\r\n");
47 e
= lstat(SS
.arg
, &s
);
48 if (e
== -1 || !S_ISDIR(s
.st_mode
))
51 error("Stating directory %s", SS
.arg
);
53 warning("Path %s is not a directory", SS
.arg
);
54 reply_c("550 Could not change directory.\r\n");
58 memcpy(SS
.cwd
, SS
.arg
, l
);
60 debug("Directory changed to %s", SS
.cwd
);
61 reply_c("250 Directory changed.\r\n");