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
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
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
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().
48 void change_dir (void)
52 if (!path_is_secure(S_arg
)) {
53 send_reply(S_cmd_sk
, "550 Path is insecure.\r\n");
57 err
= chdir(expanded_arg());
60 send_reply(S_cmd_sk
, "550 Could not change dir.\r\n");
64 send_reply(S_cmd_sk
, "250 Directory changed.\r\n");