Removed non portable -v flag for rm command.
[uftps.git] / change_dir.c
blob5010dd1523e7f77bc4f9515fd983a19e5d3f69b7
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 #ifdef __MINGW32__
22 # include "hase.h"
23 #else
24 # include <sys/stat.h>
25 #endif
26 #include <string.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)
41 int l, e;
42 struct stat s;
44 if (SS.arg == NULL)
46 reply_c("501 Argument required.\r\n");
47 return;
49 l = expand_arg();
51 e = lstat(SS.arg, &s);
52 if (e == -1 || !S_ISDIR(s.st_mode))
54 if (e == -1)
55 error("Stating directory %s", SS.arg);
56 else
57 warning("Path %s is not a directory", SS.arg);
58 reply_c("550 Could not change directory.\r\n");
60 else
62 #ifdef __MINGW32__
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.
68 if (l == 2)
70 SS.arg[l - 1] = '/';
71 SS.arg[l] = '\0';
72 l++;
74 #endif
75 memcpy(SS.cwd, SS.arg, l);
76 SS.cwd_len = l;
77 debug("Directory changed to %s", SS.cwd);
78 reply_c("250 Directory changed.\r\n");