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 |
|
|
#ifndef DATA_H |
11 |
|
|
#include "data.h" |
12 |
|
|
#endif |
13 |
|
|
|
14 |
lefcha |
1.11 |
/* Error codes returned by functions. */ |
15 |
lefcha |
1.22 |
#define ERROR_SIGNAL 1 |
16 |
|
|
#define ERROR_TRIVIAL 2 |
17 |
|
|
#define ERROR_FILE_OPEN 3 |
18 |
lefcha |
1.29 |
#define ERROR_LOCK_FILE 4 |
19 |
|
|
#define ERROR_CONFIG_PARSE 5 |
20 |
|
|
#define ERROR_MEMORY_ALLOCATION 6 |
21 |
|
|
#define ERROR_SETUID 7 |
22 |
|
|
#define ERROR_TERMIO 8 |
23 |
|
|
#define ERROR_NETWORK 9 |
24 |
|
|
#define ERROR_SSL 10 |
25 |
|
|
#define ERROR_PASSPHRASE 11 |
26 |
|
|
#define ERROR_ENCRYPT 12 |
27 |
|
|
#define ERROR_DECRYPT 13 |
28 |
lefcha |
1.30 |
#define ERROR_FORK 14 |
29 |
|
|
#define ERROR_UNDEFINED 15 |
30 |
lefcha |
1.9 |
|
31 |
lefcha |
1.30 |
/* Flags that control the program's execution options. */ |
32 |
lefcha |
1.16 |
#define OPTION_DETAILS_QUIET 0x01 |
33 |
lefcha |
1.9 |
#define OPTION_DETAILS_NORMAL 0x02 |
34 |
|
|
#define OPTION_DETAILS_VERBOSE 0x04 |
35 |
|
|
#define OPTION_DETAILS_CLEAR 0xf8 |
36 |
lefcha |
1.14 |
#define OPTION_HEADERS 0x08 |
37 |
lefcha |
1.25 |
#define OPTION_NAMESPACE 0x10 |
38 |
lefcha |
1.26 |
#define OPTION_PASSWORD_EDITOR 0x20 |
39 |
lefcha |
1.30 |
#define OPTION_DAEMON_MODE 0x40 |
40 |
|
|
|
41 |
|
|
/* Other flags. */ |
42 |
|
|
#define FLAG_BLANK_PASSWORD 0x01 |
43 |
lefcha |
1.25 |
|
44 |
|
|
/* Capabilities of mail server. */ |
45 |
|
|
#define CAPABILITY_NONE 0x00 |
46 |
|
|
#define CAPABILITY_NAMESPACE 0x01 |
47 |
lefcha |
1.9 |
|
48 |
lefcha |
1.12 |
/* Flags for logger. */ |
49 |
|
|
#define LOG_WRITE 0 |
50 |
|
|
#define LOG_SERVER 1 |
51 |
|
|
#define LOG_USERNAME 2 |
52 |
|
|
#define LOG_MAILBOX 3 |
53 |
|
|
#define LOG_FILTER 4 |
54 |
|
|
#define LOG_ACTION 5 |
55 |
|
|
#define LOG_DESTINATION_MAILBOX 6 |
56 |
|
|
|
57 |
lefcha |
1.17 |
/* Buffer size of the IMAP command. */ |
58 |
lefcha |
1.9 |
#define SMALL_CMD 64 |
59 |
|
|
#define MEDIUM_CMD 256 |
60 |
|
|
#define BIG_CMD 8192 |
61 |
|
|
|
62 |
|
|
/* Buffer size of server's response. */ |
63 |
lefcha |
1.21 |
#define RESPONSE_BUF (4096 + 1) |
64 |
lefcha |
1.20 |
#define RESULT_BUF 512 |
65 |
lefcha |
1.9 |
|
66 |
lefcha |
1.16 |
/* Response codes. */ |
67 |
|
|
#define RESPONSE_BAD -1 |
68 |
|
|
#define RESPONSE_OK 0 |
69 |
|
|
#define RESPONSE_NO 1 |
70 |
|
|
#define RESPONSE_BYE 2 |
71 |
lefcha |
1.20 |
#define RESPONSE_PREAUTH 3 |
72 |
|
|
#define RESPONSE_READONLY 4 |
73 |
|
|
#define RESPONSE_TRYCREATE 5 |
74 |
lefcha |
1.16 |
|
75 |
lefcha |
1.9 |
/* Buffer size of message's headers. */ |
76 |
lefcha |
1.19 |
#define HEADERS_BUF 16384 |
77 |
lefcha |
1.9 |
|
78 |
lefcha |
1.25 |
/* Length of mailbox namespace prefix. */ |
79 |
|
|
#define NAMESPACE_PREFIX_LEN 64 |
80 |
|
|
|
81 |
lefcha |
1.26 |
/* Encryption and decryption buffers. */ |
82 |
|
|
#define ENCRYPTION_BUF 1024 |
83 |
|
|
#define DECRYPTION_BUF 4096 |
84 |
|
|
|
85 |
lefcha |
1.27 |
/* Maximum passwords the password editor can handle. */ |
86 |
|
|
#define EDITOR_PASSWORDS_MAX 64 |
87 |
|
|
|
88 |
lefcha |
1.1 |
|
89 |
|
|
#define min(A, B) ((A) < (B) ? (A) : (B)) |
90 |
lefcha |
1.15 |
#define plural(A) ((A) == 1 ? "" : "s") |
91 |
lefcha |
1.1 |
|
92 |
|
|
|
93 |
lefcha |
1.27 |
/* Secure memory information. */ |
94 |
|
|
typedef struct secmem { |
95 |
|
|
void *buf; /* Allocated memory buffer. */ |
96 |
|
|
size_t size; /* Size of the buffer. */ |
97 |
|
|
struct secmem *prev, *next; /* Previous/next node of doubly linked list. */ |
98 |
|
|
} secmem_t; |
99 |
|
|
|
100 |
|
|
|
101 |
lefcha |
1.9 |
/* file.c */ |
102 |
lefcha |
1.27 |
int read_config(char *cfg); |
103 |
|
|
int parse_config(FILE * fd); |
104 |
|
|
void set_options(char *line, regmatch_t * match); |
105 |
|
|
|
106 |
|
|
int read_passwords(void); |
107 |
|
|
int parse_passwords(FILE * fd); |
108 |
|
|
int store_passwords(account_t * accts[]); |
109 |
|
|
|
110 |
lefcha |
1.25 |
int create_homedir(void); |
111 |
lefcha |
1.26 |
int exists_file(char *fname); |
112 |
|
|
int exists_dir(char *fname); |
113 |
lefcha |
1.25 |
int create_file(char *fname, mode_t mode); |
114 |
|
|
int create_dir(char *dname, mode_t mode); |
115 |
lefcha |
1.9 |
#ifdef CHECK_PERMISSIONS |
116 |
lefcha |
1.25 |
int check_file_perms(char *fname, mode_t mode); |
117 |
|
|
int check_dir_perms(char *dname, mode_t mode); |
118 |
lefcha |
1.9 |
#endif |
119 |
lefcha |
1.1 |
|
120 |
lefcha |
1.9 |
/* imapfilter.c */ |
121 |
|
|
void usage(void); |
122 |
lefcha |
1.1 |
|
123 |
lefcha |
1.9 |
/* imap.c */ |
124 |
lefcha |
1.16 |
unsigned int send_command(char *cmd); |
125 |
lefcha |
1.9 |
#ifdef DEBUG |
126 |
|
|
int imap_noop(void); |
127 |
|
|
#endif |
128 |
lefcha |
1.16 |
int imap_capability(void); |
129 |
lefcha |
1.25 |
int imap_namespace(void); |
130 |
lefcha |
1.9 |
int imap_logout(void); |
131 |
|
|
int imap_login(char *user, char *pass); |
132 |
lefcha |
1.16 |
/* int imap_examine(char *mbox); */ |
133 |
lefcha |
1.9 |
int imap_select(char *mbox); |
134 |
|
|
int imap_status(char *mbox, char *items); |
135 |
|
|
int imap_create(char *mbox); |
136 |
|
|
int imap_search(char *search); |
137 |
lefcha |
1.16 |
int imap_fetch(char *mesg, char *headers, int peek); |
138 |
lefcha |
1.9 |
int imap_store(char *mesg, char *flags); |
139 |
|
|
int imap_copy(char *mesg, char *mbox); |
140 |
|
|
int imap_close(void); |
141 |
lefcha |
1.23 |
/* int imap_expunge(void); */ |
142 |
lefcha |
1.29 |
|
143 |
|
|
/* lock.c */ |
144 |
|
|
void lockfile_create(void); |
145 |
|
|
void lockfile_check(void); |
146 |
lefcha |
1.30 |
pid_t lockfile_pid(void); |
147 |
lefcha |
1.29 |
int lockfile_remove(void); |
148 |
lefcha |
1.30 |
void kill_imapfilter(void); |
149 |
lefcha |
1.9 |
|
150 |
|
|
/* log.c */ |
151 |
lefcha |
1.13 |
void info(const char *info,...); |
152 |
|
|
void verbose(const char *info,...); |
153 |
|
|
void error(const char *errmsg,...); |
154 |
|
|
void fatal(unsigned int errnum, const char *fatal,...); |
155 |
lefcha |
1.22 |
void catch_signals(void); |
156 |
|
|
void signal_handler(int sig); |
157 |
lefcha |
1.9 |
int open_logfile(void); |
158 |
|
|
int create_logfile(void); |
159 |
|
|
int close_logfile(void); |
160 |
lefcha |
1.12 |
void log_info(int flag, void *ptr); |
161 |
lefcha |
1.11 |
char *get_time(void); |
162 |
lefcha |
1.9 |
|
163 |
lefcha |
1.13 |
/* memory.c */ |
164 |
|
|
void *xmalloc(size_t size); |
165 |
lefcha |
1.19 |
void *xrealloc(void *ptr, size_t size); |
166 |
lefcha |
1.26 |
void xfree(void *ptr); |
167 |
lefcha |
1.13 |
char *xstrdup(const char *s); |
168 |
|
|
|
169 |
lefcha |
1.27 |
void *smalloc(size_t size); |
170 |
|
|
void *srealloc(void *ptr, size_t size); |
171 |
|
|
void sfree(void *ptr); |
172 |
|
|
char *sstrdup(const char *s); |
173 |
|
|
void secmem_append(secmem_t *node); |
174 |
|
|
secmem_t *secmem_find(void *ptr); |
175 |
|
|
void secmem_remove(secmem_t *node); |
176 |
|
|
void secmem_clear(void); |
177 |
lefcha |
1.30 |
void secmem_lock(void); |
178 |
lefcha |
1.27 |
|
179 |
|
|
void corefile_disable(void); |
180 |
|
|
|
181 |
lefcha |
1.16 |
/* misc.c */ |
182 |
|
|
char *strcasestr(const char *haystack, const char *needle); |
183 |
|
|
char *ultostr(unsigned long int num, int base); |
184 |
lefcha |
1.24 |
char *xstrncpy(char *dest, const char *src, size_t size); |
185 |
lefcha |
1.16 |
|
186 |
lefcha |
1.25 |
/* passwd.c */ |
187 |
lefcha |
1.26 |
void get_password(char *passwd, size_t pwlen); |
188 |
|
|
#ifdef ENCRYPTED_PASSWORDS |
189 |
|
|
int encrypt_passwords(FILE *fd, account_t *accts[]); |
190 |
lefcha |
1.27 |
int decrypt_passwords(unsigned char **buf, FILE *fd); |
191 |
lefcha |
1.26 |
void password_editor(void); |
192 |
|
|
#endif |
193 |
lefcha |
1.25 |
|
194 |
lefcha |
1.9 |
/* request.c */ |
195 |
|
|
int test(void); |
196 |
lefcha |
1.16 |
int check_capabilities(void); |
197 |
lefcha |
1.25 |
int check_namespace(void); |
198 |
lefcha |
1.9 |
int login(char *user, char *pass); |
199 |
|
|
int select_mailbox(char *mbox); |
200 |
lefcha |
1.11 |
int mailbox_status(char *mbox); |
201 |
lefcha |
1.9 |
int close_mailbox(void); |
202 |
|
|
int logout(void); |
203 |
|
|
|
204 |
lefcha |
1.16 |
int apply_filters(filter_t ** filters); |
205 |
lefcha |
1.19 |
int match_filter(filter_t * filter, char **mesgs); |
206 |
lefcha |
1.9 |
|
207 |
|
|
void empty_fifo(mask_t ** mfifo); |
208 |
lefcha |
1.11 |
void queue_fifo(mask_t ** mfifo, mask_t * mask); |
209 |
|
|
mask_t *dequeue_fifo(mask_t ** mfifo); |
210 |
lefcha |
1.9 |
|
211 |
lefcha |
1.11 |
char *generate_filter_and(mask_t * mask, unsigned int masknum, unsigned int masklen); |
212 |
|
|
char *generate_filter_or(mask_t * mask, unsigned int masknum, unsigned int masklen); |
213 |
lefcha |
1.9 |
|
214 |
lefcha |
1.11 |
int apply_action(char *mesgs, unsigned int *type, char *destmbox, char *args); |
215 |
lefcha |
1.9 |
int action_delete(char *mesgs, char *args); |
216 |
lefcha |
1.11 |
int action_copy(char *mesgs, char *destmbox, char *args); |
217 |
|
|
int action_move(char *mesgs, char *destmbox, char *args); |
218 |
|
|
int action_list(char *mesgs, char *args); |
219 |
lefcha |
1.9 |
|
220 |
|
|
unsigned int convert_messages(char *mesgs); |
221 |
|
|
|
222 |
lefcha |
1.11 |
/* response.c */ |
223 |
lefcha |
1.20 |
void receive_response(char *buf); |
224 |
lefcha |
1.16 |
int server_response(unsigned int tag); |
225 |
|
|
int greeting_response(void); |
226 |
|
|
int capability_response(unsigned int tag); |
227 |
lefcha |
1.25 |
int namespace_response(unsigned int tag, char *prefix, char delim); |
228 |
lefcha |
1.23 |
int status_response(unsigned int tag, char *mbox); |
229 |
lefcha |
1.16 |
int select_response(unsigned int tag); |
230 |
lefcha |
1.19 |
int search_response(unsigned int tag, char **mesgs); |
231 |
lefcha |
1.16 |
int fetch_response(unsigned int tag); |
232 |
|
|
int copy_response(unsigned int tag); |
233 |
lefcha |
1.20 |
int analyze_response(char *buf); |
234 |
lefcha |
1.25 |
|
235 |
|
|
/* socket.c */ |
236 |
|
|
#ifndef SSL_TLS |
237 |
|
|
int init_connection(char *serv, unsigned short int port); |
238 |
|
|
#else |
239 |
|
|
int init_connection(char *serv, unsigned short int port, unsigned int protocol); |
240 |
|
|
#endif |
241 |
|
|
int ssl_init(unsigned int protocol); |
242 |
|
|
int close_connection(void); |
243 |
|
|
int socket_read(char *buf); |
244 |
|
|
int socket_write(char *data); |
245 |
|
|
|
246 |
|
|
/* tty.c */ |
247 |
|
|
int tty_store(void); |
248 |
|
|
int tty_disable_echo(void); |
249 |
|
|
int tty_restore(void); |
250 |
lefcha |
1.11 |
|
251 |
lefcha |
1.13 |
#endif /* IMAPFILTER_H */ |