Added more logging messages.
[uftps.git] / change_dir.c
blob55193917af1aa93bae145f1b2820ed52a0658fa0
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
19 #include "uftps.h"
22 * CWD command implementation.
24 * As we don't have root privileges, we can't execute the server within a
25 * chroot() environment. Therefore, we must impose a couple of restrictions
26 * when the client tries to change the current working directory:
28 * 1. The command argument (i.e. the path we are being requested for) cannot
29 * contain any reference to the self directory "." nor to the parent
30 * directory ".."
32 * 2. If the argument begins with '/', it will be understood as an absolute path
33 * and then will be concatenated with the base directory (not visible to the
34 * client).
36 * 3. In any other case the parameter will be interpreted as a relative path, so
37 * it will simply be appended to the current working path.
39 * The complete working directory is retrieved via getcwd(). Given that we want
40 * to hide part of it (the base path), BdLen contains the number of characters
41 * we have to skip. All this just to emulate chroot().
45 #include <unistd.h>
48 void change_dir (void)
50 int err;
52 if (!path_is_secure(S_arg)) {
53 send_reply(S_cmd_sk, "550 Path is insecure.\r\n");
54 return;
57 err = chdir(expanded_arg());
59 if (err == -1) {
60 send_reply(S_cmd_sk, "550 Could not change dir.\r\n");
61 return;
64 send_reply(S_cmd_sk, "250 Directory changed.\r\n");