]> git.sesse.net Git - betaftpd/blob - ftpd.h
Fixed a security problem where the custom snprintf() would always be used. Thanks...
[betaftpd] / ftpd.h
1 /*  ftpd.h: Prototypes for BetaFTPD
2     Copyright (C) 1999-2000 Steinar H. Gunderson
3
4     This program is is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License, version 2 of the
6     License as published by the Free Software Foundation.
7
8     This program is distributed in the hope that it will be useful,
9     but WITHOUT ANY WARRANTY; without even the implied warranty of
10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11     GNU General Public License for more details.
12
13     You should have received a copy of the GNU General Public License
14     along with this program; if not, write to the Free Software
15     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 */
17
18 #ifndef _FTPD_H
19 #define _FTPD_H 1
20
21 /*
22  * This is the port you want BetaFTPD to listen on.
23  */
24 #if WANT_NONROOT
25 #define FTP_PORT 12121
26 #else
27 #define FTP_PORT 21
28 #endif
29
30 /*
31  * This is the number of seconds an idle connection is allowed to
32  * remain idle (`idle' is defined as `no activity on the data socket',
33  * more or less) without getting shut down. This is not accurate,
34  * as such delays are only checked for every 60 seconds.
35  *
36  * The default (15 minutes) should be OK for most people.
37  */
38 #define TIMEOUT_SECS 900
39
40 /*
41  * This is the maximum block size you think you need. (This will most
42  * likely be the block size of your filesystem, and you're not likely
43  * to need a bigger number than this, unless your TCP stack likes
44  * big send()s better than small ones, and still manages to `interleave'
45  * the framents.) If this value is too small, your performance would be
46  * slightly worse, but it would still work. Try to keep it at a power of
47  * two -- most (read: all) FS block sizes _are_ powers of two. If you
48  * set it too high, it won't affect performance much -- you would just
49  * use a bit more memory.
50  */
51 #define MAX_BLOCK_SIZE 4096
52
53 #if HAVE_PWD_H
54 #include <pwd.h>
55 #endif
56
57 #if HAVE_SYS_TYPES_H
58 #include <sys/types.h>
59 #endif
60
61 #if HAVE_NETINET_IN_H
62 #include <netinet/in.h>
63 #endif
64
65 #if HAVE_SYS_SOCKET_H
66 #include <sys/socket.h>
67 #endif
68
69 #if HAVE_LINUX_SENDFILE && !HAVE_MMAP
70 #warning sendfile() without mmap() is not supported -- disabling sendfile()
71 #undef HAVE_LINUX_SENDFILE
72 #endif
73
74 #if WANT_DCACHE && !HAVE_MMAP
75 #warning directory cache requires use of mmap() -- disabling directory cache
76 #undef WANT_DCACHE
77 #endif
78
79 extern char message_buf[];
80
81 struct list_options {
82         int recursive;
83         int long_listing;
84         int classify;
85 };
86
87 /*
88  * General structure for the doubly linked lists (conn, ftran, dcache).
89  * This is used only by the generic linked list code (which inserts and
90  * removes elements from the lists).
91  */
92 struct list_element {
93         struct list_element *prev;
94         struct list_element *next;
95
96         /* structure specific data here */
97 };
98
99 /* doubly linked list of active connections */
100 struct conn {
101         struct conn *prev_conn;
102         struct conn *next_conn;
103
104         int sock;
105 #if WANT_STAT
106         struct sockaddr addr;
107 #endif
108         char recv_buf[256];
109 #if WANT_FULLSCREEN
110         char last_cmd[256];
111 #endif
112         char rename_from[256];
113
114         int buf_len;
115         int auth;
116
117         char username[17];
118
119         uid_t uid;
120         gid_t gid;
121
122         char root_dir[256];
123         char curr_dir[256];
124
125         struct ftran *transfer;
126
127         int rest_pos;
128 #if WANT_ASCII
129         int ascii_mode;
130 #endif
131
132         time_t last_transfer;
133         int free_me;
134 };
135
136 /* doubly linked list of file transfers */
137 struct ftran {
138         struct ftran *prev_ftran;
139         struct ftran *next_ftran;
140         struct conn *owner;
141
142         int state;              /*
143                                  * 0 = none, 1 = got PASV addr,
144                                  * 2 = waiting on PASV socket,  
145                                  * 3 = got PORT addr, 4 = waiting for
146                                  *     PORT connect, 
147                                  * 5 = transferring file (or waiting 
148                                  *     for PORT connect)
149                                  */
150         struct sockaddr_in sin;
151         int sock;
152         int dir_listing;
153 #if WANT_DCACHE
154         struct dcache *dir_cache;
155 #endif
156 #if WANT_ASCII
157         int ascii_mode;
158 #endif
159         char filename[256];
160         time_t tran_start;
161         long int size;
162
163         int local_file;
164         int block_size;
165
166 #if HAVE_MMAP
167         char *file_data;        /* mmap'ed */
168 #endif
169         long int pos;
170
171 #if WANT_UPLOAD
172         int upload;
173         int append;
174 #endif
175 };
176
177 void add_to_linked_list(struct list_element * const first,
178                         struct list_element * const elem);
179 void remove_from_linked_list(struct list_element * const elem);
180
181 struct conn *alloc_new_conn(const int sock);
182 struct ftran *alloc_new_ftran(const int sock, const struct conn * const c);
183
184 int add_fd(const int fd, const int events);
185 void del_fd(const int fd);
186
187 void destroy_conn(struct conn * const c);
188 void destroy_ftran(struct ftran * const f);
189
190 void finish_transfer(struct ftran * const f);
191
192 #if HAVE_POLL
193 int process_all_clients(const int num_ac);
194 int process_all_sendfiles(const int num_ac);
195 #else
196 int process_all_clients(const fd_set * const active_clients, const int num_ac);
197 int process_all_sendfiles(fd_set * const active_clients, const int num_ac);
198 #endif
199
200 int do_upload(struct ftran *f);
201 int do_download(struct ftran *f);
202 void write_xferlog(struct ftran *f);
203 int main(void);
204
205 RETSIGTYPE handle_alarm(int signum);
206
207 void accept_new_client(int * const server_sock);
208 void time_out_sockets();
209
210 void remove_bytes(struct conn * const c, const int i);
211 void numeric(struct conn * const c, const int numeric, const char * const format, ...);
212 void flush_numeric(struct conn * const c);
213 void init_file_transfer(struct ftran * const f);
214 int create_server_socket();
215
216 #if !HAVE_POLL
217 void clear_bad_fds(int * const server_sock);
218 #endif
219
220 #if HAVE_BSD_SENDFILE || HAVE_LINUX_SENDFILE
221 int mysendfile(int sock, int fd, off_t *offset, size_t count);
222 #endif  
223
224 #if WANT_MESSAGE
225 void dump_file(struct conn * const c, const int num, const char * const filename);
226 void list_readmes(struct conn * const c);
227 #endif
228
229 #endif