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
21 * Common definitions and some platform independence
24 /* Large file support */
25 #define _FILE_OFFSET_BITS 64
26 #define _LARGEFILE_SOURCE
27 #define _LARGEFILE64_SOURCE
34 extern void debug_msg (const char *format
, ...);
36 #define debug_msg(format, ...)
40 #define DEFAULT_PORT 2211
41 #define LINE_SIZE 4096 /* Same value as PATH_MAX */
43 /* Recognized commands; please keep it sorted with the same criteria as in
45 typedef enum _Command
{
47 FTP_ABOR
, FTP_ACCT
, FTP_ALLO
, FTP_APPE
, FTP_CDUP
, FTP_CWD
, FTP_DELE
,
48 FTP_FEAT
, FTP_HELP
, FTP_LIST
, FTP_MDTM
, FTP_MKD
, FTP_MODE
, FTP_NLST
,
49 FTP_NOOP
, FTP_OPTS
, FTP_PASS
, FTP_PASV
, FTP_PORT
, FTP_PWD
, FTP_QUIT
,
50 FTP_REIN
, FTP_REST
, FTP_RETR
, FTP_RMD
, FTP_RNFR
, FTP_RNTO
, FTP_SITE
,
51 FTP_SIZE
, FTP_SMNT
, FTP_STAT
, FTP_STOR
, FTP_STOU
, FTP_STRU
, FTP_SYST
,
56 extern char LineBuf
[LINE_SIZE
]; /* Incoming command line buffer */
57 extern char AuxBuf
[LINE_SIZE
]; /* Auxiliary buffer */
59 /* chroot() emulation */
61 extern int Basedir_len
;
63 /* Session state information (prefixed by "S_") */
64 extern int S_cmd_sk
; /* Control channel */
65 extern int S_data_sk
; /* Data channel */
66 extern int S_passive_bind_sk
; /* Cached data socket for passive mode */
67 extern int S_passive_mode
; /* Passive mode flag */
68 extern long long S_offset
; /* Last REST offset accepted */
69 extern char S_passive_str
[64]; /* Cached reply for PASV */
70 extern char *S_arg
; /* Pointer to comand line argument */
73 /*************************** FUNCTION PROTOTYPES ***************************/
75 void init_session (int cmd_sk
); /* init_session.c */
76 command_t
next_command (void); /* next_command.c */
77 void command_loop (void); /* command_loop.c */
78 void change_dir (void); /* change_dir.c */
79 void client_port (void); /* client_port.c */
80 void send_file (void); /* send_file.c */
81 void file_stats (int type
); /* file_stats.c */
82 void list_dir (int full_list
); /* list_dir.c */
83 void fatal (char *msg
); /* misc.c */
84 void send_reply (int sk
, char *msg
); /* | */
85 int path_is_secure (char *path
); /* _/ */
88 /* Inline utility functions */
92 if (S_arg
!= NULL
&& S_arg
[0] == '/') {
93 strncpy(AuxBuf
, Basedir
, Basedir_len
);
94 AuxBuf
[Basedir_len
] = '\0';
95 strncat(AuxBuf
, S_arg
, LINE_SIZE
- Basedir_len
);