/[imapfilter]/imapfilter/imapfilter.h
ViewVC logotype

Annotation of /imapfilter/imapfilter.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.62 - (hide annotations)
Sun Jul 27 10:08:42 2003 UTC (20 years, 8 months ago) by lefcha
Branch: MAIN
Changes since 1.61: +19 -4 lines
File MIME type: text/plain
Added STARTTLS support.

1 lefcha 1.9 #ifndef IMAPFILTER_H
2     #define IMAPFILTER_H
3    
4     #include <stdio.h>
5 lefcha 1.25 #include <unistd.h>
6     #include <sys/stat.h>
7     #include <sys/types.h>
8 lefcha 1.29 #include <dirent.h>
9 lefcha 1.9
10 lefcha 1.54 #include "config.h"
11    
12     #ifdef SSL_TLS
13     #include <openssl/ssl.h>
14     #include <openssl/x509.h>
15     #endif
16    
17 lefcha 1.9 #ifndef DATA_H
18     #include "data.h"
19     #endif
20    
21 lefcha 1.43 /* Program's version number. */
22 lefcha 1.60 #define IMAPFILTER_VERSION "0.8.9"
23 lefcha 1.43
24 lefcha 1.11 /* Error codes returned by functions. */
25 lefcha 1.22 #define ERROR_SIGNAL 1
26     #define ERROR_TRIVIAL 2
27     #define ERROR_FILE_OPEN 3
28 lefcha 1.32 #define ERROR_LOCKFILE 4
29 lefcha 1.29 #define ERROR_CONFIG_PARSE 5
30     #define ERROR_MEMORY_ALLOCATION 6
31     #define ERROR_SETUID 7
32     #define ERROR_TERMIO 8
33     #define ERROR_NETWORK 9
34     #define ERROR_SSL 10
35     #define ERROR_PASSPHRASE 11
36     #define ERROR_ENCRYPT 12
37     #define ERROR_DECRYPT 13
38 lefcha 1.30 #define ERROR_FORK 14
39     #define ERROR_UNDEFINED 15
40 lefcha 1.9
41 lefcha 1.54 /* SSL/TLS certificate status for the server. */
42     #define SSL_CERT_OK 0
43     #define SSL_CERT_NONEXISTENT 1
44     #define SSL_CERT_MISMATCH 2
45    
46     /* Action to be applied, concerning the SSL/TLS certificate. */
47     #define SSL_CERT_ACTION_ACCEPT 0
48     #define SSL_CERT_ACTION_REJECT 1
49     #define SSL_CERT_ACTION_CONTINUE 0
50     #define SSL_CERT_ACTION_ABORT 1
51    
52 lefcha 1.30 /* Flags that control the program's execution options. */
53 lefcha 1.36 #define OPTION_DETAILS_QUIET 0x0001
54     #define OPTION_DETAILS_NORMAL 0x0002
55     #define OPTION_DETAILS_VERBOSE 0x0004
56     #define OPTION_DETAILS_CLEAR 0xfff8
57 lefcha 1.38 #define OPTION_ERRORS 0x0008
58     #define OPTION_EXPUNGE 0x0010
59     #define OPTION_HEADERS 0x0020
60     #define OPTION_NAMESPACE 0x0040
61     #define OPTION_SUBSCRIBE 0x0080
62 lefcha 1.58 #define OPTION_PASSWORD_EDITOR 0x0100
63     #define OPTION_DAEMON_MODE 0x0200
64 lefcha 1.30
65     /* Other flags. */
66 lefcha 1.54 #define FLAG_DAEMON_MODE 0x01
67     #define FLAG_TTY 0x02
68     #define FLAG_TTY_MODIFIED 0x04
69     #define FLAG_BLANK_PASSWORD 0x08
70 lefcha 1.57 #define FLAG_SIGHUP_RECEIVED 0x10
71 lefcha 1.25
72     /* Capabilities of mail server. */
73     #define CAPABILITY_NONE 0x00
74     #define CAPABILITY_NAMESPACE 0x01
75 lefcha 1.61 #define CAPABILITY_AUTH_CRAM_MD5 0x02
76 lefcha 1.62 #define CAPABILITY_STARTTLS 0x04
77 lefcha 1.9
78 lefcha 1.12 /* Flags for logger. */
79 lefcha 1.55 #define LOG_PREAMBLE 0
80 lefcha 1.49 #define LOG_ACCOUNT 1
81     #define LOG_MAILBOX 2
82     #define LOG_FILTER 3
83     #define LOG_ACTION 4
84     #define LOG_DESTINATION_ACCOUNT 5
85 lefcha 1.12 #define LOG_DESTINATION_MAILBOX 6
86 lefcha 1.55 #define LOG_HEADER 7
87 lefcha 1.12
88 lefcha 1.17 /* Buffer size of the IMAP command. */
89 lefcha 1.9 #define SMALL_CMD 64
90 lefcha 1.32 #define MEDIUM_CMD 512
91     #define BIG_CMD 32768
92 lefcha 1.9
93 lefcha 1.35 /* Store IMAP command type may replace,add or remove flags. */
94     #define STORE_FLAG_REPLACE 1
95     #define STORE_FLAG_ADD 2
96     #define STORE_FLAG_REMOVE 3
97    
98 lefcha 1.9 /* Buffer size of server's response. */
99 lefcha 1.55 #define RESPONSE_BUF 4096
100 lefcha 1.20 #define RESULT_BUF 512
101 lefcha 1.9
102 lefcha 1.16 /* Response codes. */
103 lefcha 1.44 #define RESPONSE_NULLBODY -2
104     #define RESPONSE_NONE -1
105 lefcha 1.16 #define RESPONSE_OK 0
106     #define RESPONSE_NO 1
107 lefcha 1.44 #define RESPONSE_BAD 2
108     #define RESPONSE_BYE 3
109     #define RESPONSE_PREAUTH 4
110     #define RESPONSE_READONLY 5
111     #define RESPONSE_TRYCREATE 6
112 lefcha 1.16
113 lefcha 1.61 /* Size of input buffer. */
114     #define INPUT_BUF 4096
115 lefcha 1.9
116 lefcha 1.25 /* Length of mailbox namespace prefix. */
117     #define NAMESPACE_PREFIX_LEN 64
118    
119 lefcha 1.26 /* Encryption and decryption buffers. */
120     #define ENCRYPTION_BUF 1024
121     #define DECRYPTION_BUF 4096
122    
123 lefcha 1.35 /* Buffer to save flags of the store IMAP command. */
124     #define STORE_FLAGS_BUF 64
125    
126 lefcha 1.27 /* Maximum passwords the password editor can handle. */
127 lefcha 1.32 #define EDITOR_PASSWORDS_MAX 64
128 lefcha 1.27
129 lefcha 1.47 /* Lenght of charset for IMAP SEARCH requests. */
130     #define CHARSET_LEN 64
131    
132 lefcha 1.1
133     #define min(A, B) ((A) < (B) ? (A) : (B))
134 lefcha 1.15 #define plural(A) ((A) == 1 ? "" : "s")
135 lefcha 1.1
136    
137 lefcha 1.27 /* Secure memory information. */
138     typedef struct secmem {
139 lefcha 1.49 void *buf; /* Allocated memory buffer. */
140     size_t size; /* Size of the buffer. */
141     struct secmem *prev, *next; /* Previous/next node of doubly linked
142     * list. */
143 lefcha 1.27 } secmem_t;
144    
145    
146 lefcha 1.32 /* Namespace of IMAP mailboxes. */
147     typedef struct namesp {
148 lefcha 1.49 char prefix[NAMESPACE_PREFIX_LEN];
149     char delim;
150 lefcha 1.32 } namesp_t;
151    
152    
153 lefcha 1.61 /* auth.c */
154 lefcha 1.62 #ifdef CRAM_MD5
155 lefcha 1.61 int imf_cram_md5(int *sock, char *user, char *pass);
156    
157 lefcha 1.62 #endif
158    
159 lefcha 1.9 /* file.c */
160 lefcha 1.27 int read_config(char *cfg);
161     int parse_config(FILE * fd);
162 lefcha 1.57 void reread_config(char *cfg);
163 lefcha 1.27 void set_options(char *line, regmatch_t * match);
164    
165     int read_passwords(void);
166     int parse_passwords(FILE * fd);
167 lefcha 1.60 int store_passwords(account_t ** accts);
168 lefcha 1.27
169 lefcha 1.25 int create_homedir(void);
170 lefcha 1.26 int exists_file(char *fname);
171     int exists_dir(char *fname);
172 lefcha 1.25 int create_file(char *fname, mode_t mode);
173 lefcha 1.49
174 lefcha 1.9 #ifdef CHECK_PERMISSIONS
175 lefcha 1.25 int check_file_perms(char *fname, mode_t mode);
176     int check_dir_perms(char *dname, mode_t mode);
177 lefcha 1.49
178 lefcha 1.9 #endif
179 lefcha 1.1
180 lefcha 1.54 #ifdef SSL_TLS
181     int imf_ssl_cert(SSL * ssl);
182     int imf_ssl_check_cert(X509 * pcert, unsigned char *pmd, unsigned int *pmdlen);
183     void imf_ssl_print_cert(X509 * cert, unsigned char *md, unsigned int *mdlen);
184     int imf_ssl_new_cert(X509 * cert);
185     int imf_ssl_cert_mismatch(void);
186    
187     #endif
188    
189 lefcha 1.9 /* imapfilter.c */
190     void usage(void);
191 lefcha 1.43 void version(void);
192 lefcha 1.1
193 lefcha 1.9 /* imap.c */
194 lefcha 1.32 unsigned int send_command(int *sock, char *cmd);
195 lefcha 1.61 void send_command_cont(int *sock, char *cmd);
196 lefcha 1.49
197 lefcha 1.9 #ifdef DEBUG
198 lefcha 1.32 int imap_noop(int *sock);
199 lefcha 1.49
200 lefcha 1.9 #endif
201 lefcha 1.32 int imap_capability(int *sock);
202     int imap_namespace(int *sock);
203     int imap_logout(int *sock);
204 lefcha 1.62
205     #ifdef SSL_TLS
206     int imap_starttls(int *sock);
207    
208     #endif
209 lefcha 1.61 int imap_authenticate(int *sock, char *auth, int cont);
210 lefcha 1.32 int imap_login(int *sock, char *user, char *pass);
211 lefcha 1.49
212 lefcha 1.32 /* int imap_list(int *sock, char *refer, char *mbox); */
213     int imap_subscribe(int *sock, char *mbox);
214 lefcha 1.54
215     /* int imap_examine(int *sock, char *mbox); */
216 lefcha 1.32 int imap_select(int *sock, char *mbox);
217     int imap_status(int *sock, char *mbox, char *items);
218     int imap_create(int *sock, char *mbox);
219 lefcha 1.47 int imap_search(int *sock, char *charset, char *search);
220 lefcha 1.32 int imap_fetch(int *sock, char *mesg, char *items);
221 lefcha 1.35 int imap_store(int *sock, char *mesg, unsigned int mode, char *flags);
222 lefcha 1.32 int imap_copy(int *sock, char *mesg, char *mbox);
223     int imap_append(int *sock, char *mbox, unsigned int size);
224     int imap_close(int *sock);
225 lefcha 1.34 int imap_expunge(int *sock);
226 lefcha 1.29
227     /* lock.c */
228     void lockfile_create(void);
229     void lockfile_check(void);
230 lefcha 1.30 pid_t lockfile_pid(void);
231 lefcha 1.29 int lockfile_remove(void);
232 lefcha 1.30 void kill_imapfilter(void);
233 lefcha 1.9
234     /* log.c */
235 lefcha 1.13 void info(const char *info,...);
236     void verbose(const char *info,...);
237     void error(const char *errmsg,...);
238     void fatal(unsigned int errnum, const char *fatal,...);
239 lefcha 1.22 void catch_signals(void);
240     void signal_handler(int sig);
241 lefcha 1.9 int open_logfile(void);
242     int create_logfile(void);
243     int close_logfile(void);
244 lefcha 1.12 void log_info(int flag, void *ptr);
245 lefcha 1.11 char *get_time(void);
246 lefcha 1.9
247 lefcha 1.13 /* memory.c */
248     void *xmalloc(size_t size);
249 lefcha 1.19 void *xrealloc(void *ptr, size_t size);
250 lefcha 1.26 void xfree(void *ptr);
251 lefcha 1.13 char *xstrdup(const char *s);
252    
253 lefcha 1.27 void *smalloc(size_t size);
254     void *srealloc(void *ptr, size_t size);
255     void sfree(void *ptr);
256     char *sstrdup(const char *s);
257 lefcha 1.34 void secmem_append(secmem_t * node);
258 lefcha 1.27 secmem_t *secmem_find(void *ptr);
259 lefcha 1.34 void secmem_remove(secmem_t * node);
260 lefcha 1.27 void secmem_clear(void);
261 lefcha 1.49
262 lefcha 1.27 void corefile_disable(void);
263    
264 lefcha 1.16 /* misc.c */
265     char *strcasestr(const char *haystack, const char *needle);
266     char *ultostr(unsigned long int num, int base);
267 lefcha 1.24 char *xstrncpy(char *dest, const char *src, size_t size);
268 lefcha 1.16
269 lefcha 1.25 /* passwd.c */
270 lefcha 1.26 void get_password(char *passwd, size_t pwlen);
271 lefcha 1.49
272 lefcha 1.26 #ifdef ENCRYPTED_PASSWORDS
273 lefcha 1.60 int encrypt_passwords(FILE * fd, account_t ** accts);
274 lefcha 1.34 int decrypt_passwords(unsigned char **buf, FILE * fd);
275 lefcha 1.26 void password_editor(void);
276 lefcha 1.49
277 lefcha 1.26 #endif
278 lefcha 1.25
279 lefcha 1.9 /* request.c */
280 lefcha 1.32 int test(int *sock);
281     int check_capabilities(int *sock);
282 lefcha 1.34 int check_namespace(int *sock, namesp_t * nsp);
283 lefcha 1.62
284     #ifdef SSL_TLS
285     int imf_starttls(int *sock);
286    
287     #endif
288 lefcha 1.32 int login(int *sock, char *user, char *pass);
289 lefcha 1.51 int check_mailbox(int *sock, char *mbox);
290 lefcha 1.34 int select_mailbox(int *sock, char *mbox, namesp_t * nsp);
291     int mailbox_status(int *sock, char *mbox, namesp_t * nsp);
292 lefcha 1.32 int close_mailbox(int *sock);
293     int logout(int *sock);
294 lefcha 1.9
295 lefcha 1.53 int apply_filters(char *mbox, filter_t ** filters);
296 lefcha 1.19 int match_filter(filter_t * filter, char **mesgs);
297 lefcha 1.9
298     void empty_fifo(mask_t ** mfifo);
299 lefcha 1.11 void queue_fifo(mask_t ** mfifo, mask_t * mask);
300     mask_t *dequeue_fifo(mask_t ** mfifo);
301 lefcha 1.9
302 lefcha 1.49 char *generate_filter_and(mask_t * mask, unsigned int masknum, unsigned int masklen);
303     char *generate_filter_or(mask_t * mask, unsigned int masknum, unsigned int masklen);
304 lefcha 1.9
305 lefcha 1.53 int apply_action(char *mbox, char *mesgs, unsigned int *type, account_t * raccount, char *destmbox, unsigned int *msgflags, char *args);
306 lefcha 1.9 int action_delete(char *mesgs, char *args);
307 lefcha 1.53 int action_copy(char *mbox, char *mesgs, char *destmbox, char *args);
308     int action_move(char *mbox, char *mesgs, char *destmbox, char *args);
309     int action_rcopy(char *mbox, char *mesgs, account_t * destacc, char *destmbox, char *args);
310     int action_rmove(char *mbox, char *mesgs, account_t * destacc, char *destmbox, char *args);
311 lefcha 1.35 int action_flag(char *mesgs, unsigned int *type, unsigned int *msgflags, char *args);
312 lefcha 1.11 int action_list(char *mesgs, char *args);
313 lefcha 1.9
314 lefcha 1.32 unsigned int count_messages(char *mesgs);
315 lefcha 1.33 char *convert_messages(char *mesgs);
316 lefcha 1.50 int substitute_date(char *str);
317     void current_date(char *destmbox);
318     void message_date(char *mesg, char *destmbox);
319 lefcha 1.53 void default_variables(char *mbox, char *destmbox);
320 lefcha 1.32
321 lefcha 1.11 /* response.c */
322 lefcha 1.32 void receive_response(int *sock, char *buf);
323     int server_response(int *sock, unsigned int tag);
324 lefcha 1.40 void bye_response(char *buf);
325 lefcha 1.32 int greeting_response(int *sock);
326 lefcha 1.39 int logout_response(int *sock, unsigned int tag);
327 lefcha 1.32 int capability_response(int *sock, unsigned int tag);
328 lefcha 1.61 int authenticate_response(int *sock, unsigned int tag, unsigned char **cont);
329 lefcha 1.34 int namespace_response(int *sock, unsigned int tag, namesp_t * nsp);
330 lefcha 1.32 int status_response(int *sock, unsigned int tag, char *mbox);
331     int select_response(int *sock, unsigned int tag);
332     int search_response(int *sock, unsigned int tag, char **mesgs);
333 lefcha 1.43 int fetch_response(int *sock, unsigned int tag, int reset, char *fetch);
334 lefcha 1.32 int fetchsize_response(int *sock, unsigned int *size, unsigned int tag);
335     int append_response(int *sock, unsigned int tag);
336     int copy_response(int *sock, unsigned int tag);
337 lefcha 1.55 int analyze_response(int *sock, char *buf);
338 lefcha 1.61 void init_ibuf(void);
339     void reset_ibuf(void);
340     void check_ibuf(void);
341 lefcha 1.25
342     /* socket.c */
343 lefcha 1.49 int init_connection(int *sock, char *serv, unsigned short int port, unsigned int protocol);
344 lefcha 1.62
345     #ifdef SSL_TLS
346     int imf_ssl_init(int *sock, unsigned int protocol);
347    
348     #endif
349 lefcha 1.32 int close_connection(int *sock);
350     int socket_read(int *sock, char *buf);
351     int socket_write(int *sock, char *data);
352 lefcha 1.25
353     /* tty.c */
354     int tty_store(void);
355     int tty_disable_echo(void);
356     int tty_restore(void);
357 lefcha 1.11
358 lefcha 1.13 #endif /* IMAPFILTER_H */

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26