]> git.sesse.net Git - betaftpd/blob - ftpd.h
Added a notice about a (not yet fixed) dcache bug.
[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 if 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. The standard
23  * FTP port is 21 -- if you really want to use BetaFTPD as your
24  * primary FTP server, change FTP_PORT.
25  */
26 #if WANT_NONROOT
27 #define FTP_PORT 12121
28 #else
29 #define FTP_PORT 21
30 #endif
31
32 /*
33  * This is the number of seconds an idle connection is allowed to
34  * remain idle (`idle' is defined as `no activity on the data socket',
35  * more or less) without getting shut down. This is not accurate,
36  * as such delays are only checked for every 60 seconds.
37  *
38  * The default (15 minutes) should be OK for most people.
39  */
40 #define TIMEOUT_SECS 900
41
42 /*
43  * This is the maximum block size you think you need. (This will most
44  * likely be the block size of your filesystem, and you're not likely
45  * to need a bigger number than this, unless your TCP stack likes
46  * big send()s better than small ones, and still manages to `interleave'
47  * the framents.) If this value is too small, your performance would be
48  * slightly worse, but it would still work. Try to keep it at a power of
49  * two -- most (read: all) FS block sizes _are_ powers of two. If you
50  * set it too high, it won't affect performance much -- you would just
51  * use a bit more memory.
52  */
53 #define MAX_BLOCK_SIZE 4096
54
55 #if HAVE_PWD_H
56 #include <pwd.h>
57 #endif
58
59 #if HAVE_SYS_TYPES_H
60 #include <sys/types.h>
61 #endif
62
63 #if HAVE_NETINET_IN_H
64 #include <netinet/in.h>
65 #endif
66
67 #if HAVE_SYS_SOCKET_H
68 #include <sys/socket.h>
69 #endif
70
71 #if HAVE_LINUX_SENDFILE && !HAVE_MMAP
72 #warning sendfile() without mmap() is not supported -- disabling sendfile()
73 #undef HAVE_LINUX_SENDFILE
74 #endif
75
76 #if WANT_DCACHE && !HAVE_MMAP
77 #warning directory cache requires use of mmap() -- disabling directory cache
78 #undef WANT_DCACHE
79 #endif
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         char root_dir[256];
121         char curr_dir[256];
122
123         struct ftran *transfer;
124
125         int rest_pos;
126 #if WANT_ASCII
127         int ascii_mode;
128 #endif
129
130         time_t last_transfer;
131 };
132
133 /* doubly linked list of file transfers */
134 struct ftran {
135         struct ftran *prev_ftran;
136         struct ftran *next_ftran;
137         struct conn *owner;
138
139         int state;              /*
140                                  * 0 = none, 1 = got PASV addr,
141                                  * 2 = waiting on PASV socket,  
142                                  * 3 = got PORT addr, 4 = waiting for
143                                  *     PORT connect, 
144                                  * 5 = transferring file (or waiting 
145                                  *     for PORT connect)
146                                  */
147         struct sockaddr_in sin;
148         int sock;
149         int dir_listing;
150 #if WANT_DCACHE
151         struct dcache *dir_cache;
152 #endif
153 #if WANT_ASCII
154         int ascii_mode;
155 #endif
156         char filename[256];
157         time_t tran_start;
158         long int size;
159
160         int local_file;
161         int block_size;
162
163 #if HAVE_MMAP
164         char *file_data;        /* mmap'ed */
165 #endif
166         long int pos;
167
168 #if WANT_UPLOAD
169         int upload;
170         int append;
171 #endif
172 };
173
174 void add_to_linked_list(struct list_element * const first,
175                         struct list_element * const elem);
176 void remove_from_linked_list(struct list_element * const elem);
177
178 struct conn *alloc_new_conn(const int sock);
179 struct ftran *alloc_new_ftran(const int sock, const struct conn * const c);
180
181 int add_fd(const int fd, const int events);
182 void del_fd(const int fd);
183
184 void destroy_conn(struct conn * const c);
185 void destroy_ftran(struct ftran * const f);
186
187 #if HAVE_POLL
188 int process_all_clients(const int num_ac);
189 int process_all_sendfiles(const int num_ac);
190 #else
191 int process_all_clients(const fd_set * const active_clients, const int num_ac);
192 int process_all_sendfiles(fd_set * const active_clients, const int num_ac);
193 #endif
194
195 int do_upload(struct ftran *f);
196 int do_download(struct ftran *f);
197 void write_xferlog(struct ftran *f);
198 int main(void);
199
200 RETSIGTYPE handle_alarm(int signum);
201
202 void accept_new_client(int * const server_sock);
203 void time_out_sockets();
204
205 void remove_bytes(struct conn * const c, const int i);
206 void numeric(struct conn * const c, const int numeric, const char * const format, ...);
207 void init_file_transfer(struct ftran * const f);
208 int create_server_socket();
209
210 #if !HAVE_POLL
211 void clear_bad_fds(int * const server_sock);
212 #endif
213
214 #if WANT_MESSAGE
215 void dump_file(struct conn * const c, const int num, const char * const filename);
216 void list_readmes(struct conn * const c);
217 #endif
218
219 #endif