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
24 # include <sys/stat.h>
31 * Open the file specified in the argument after performing various checks.
32 * Returns the opened file descriptor when successful, -1 on error. The total
33 * size of the file is stored in "file_size".
35 * This function is the common code between all send_file() implementations.
36 * Note that, on error, everybody is notified so the invocation to this function
37 * is as simple as possible.
39 int open_file (off_t
*file_size
)
46 reply_c("501 Argument required.\r\n");
51 /* Avoid following symlinks, as usual */
52 e
= lstat(SS
.arg
, &s
);
53 if (e
== -1 || !S_ISREG(s
.st_mode
))
56 error("Stating file %s", SS
.arg
);
58 warning("%s is not a regular file", SS
.arg
);
59 reply_c("550 Not a file.\r\n");
62 *file_size
= s
.st_size
;
64 f
= open(SS
.arg
, O_RDONLY
);
67 error("Opening file %s", SS
.arg
);
68 reply_c("550 Could not open file.\r\n");