Fix LIST directory argument manipulation.
[uftps.git] / expand_arg.c
blob4108a3320db3c6ca9fade32427e2122acc2b053f
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 <string.h>
25 * Expand the command argument to its corresponding full "virtual" path. This
26 * is necessary because chdir() is never performed so the correct path needs to
27 * be resolved for each file or directory to be accessed.
29 * Returns the length of the expanded argument, including the trailing null
30 * byte (just as apply_path() does).
32 int expand_arg (void)
34 int len = SS.cwd_len;
36 memcpy(SS.aux, SS.cwd, len);
38 if (SS.arg != NULL)
40 len = apply_path(SS.arg, SS.aux, len);
41 if (len == -1)
43 reply_c("552 Path overflow.\r\n");
44 fatal("Path overflow expanding argument");
48 SS.arg = SS.aux;
49 debug("Argument expanded to '%s'", SS.arg);
50 return len;