Added a specific reply function for the data channel.
[uftps.git] / change_dir.c
blobe9d8f5823e8b413b82a0c17a9d96ef0f3b4754ca
1 /*
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
8 * version.
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
13 * details.
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
20 #include "uftps.h"
21 #include <sys/stat.h>
22 #include <string.h>
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)
37 int l, e;
38 struct stat s;
40 if (SS.arg == NULL)
42 reply_c("501 Argument required.\r\n");
43 return;
45 l = expand_arg();
47 e = lstat(SS.arg, &s);
48 if (e == -1 || !S_ISDIR(s.st_mode))
50 if (e == -1)
51 error("Stating directory %s", SS.arg);
52 else
53 warning("Path %s is not a directory", SS.arg);
54 reply_c("550 Could not change directory.\r\n");
56 else
58 memcpy(SS.cwd, SS.arg, l);
59 SS.cwd_len = l;
60 debug("Directory changed to %s", SS.cwd);
61 reply_c("250 Directory changed.\r\n");