]> Pileus Git - ~andy/fetchmail/blob - fetchmail.h
Make alloca safe.
[~andy/fetchmail] / fetchmail.h
1 /*
2  * For license terms, see the file COPYING in this directory.
3  */
4
5 /* constants designating the various supported protocols */
6 #define         P_AUTO          0
7 #define         P_POP2          2
8 #define         P_POP3          3
9 #define         P_IMAP          4
10 #define         P_IMAP_K4       5
11 #define         P_IMAP_GSS      6
12 #define         P_APOP          7
13 #define         P_RPOP          8
14 #define         P_ETRN          9
15
16 #if INET6
17 #define         KPOP_PORT       "kpop"
18 #else /* INET6 */
19 #define         KPOP_PORT       1109
20 #endif /* INET6 */
21
22 /* preauthentication types */
23 #define         A_PASSWORD      0       /* password or inline authentication */
24 #define         A_KERBEROS_V4   1       /* preauthenticate w/ Kerberos V4 */
25 #define         A_KERBEROS_V5   2       /* preauthenticate w/ Kerberos V5 */
26
27 /*
28  * Definitions for buffer sizes.  We get little help on setting maxima
29  * from IMAP RFCs up to 2060, so these are mostly from POP3.
30  */
31 #define         HOSTLEN         635     /* max hostname length (RFC1123) */
32 #define         POPBUFSIZE      512     /* max length of response (RFC1939) */
33 #define         IDLEN           128     /* max length of UID (RFC1939) */
34
35 /* per RFC1939 this should be 40, but Microsoft Exchange ignores that limit */
36 #define         USERNAMELEN     128     /* max POP3 arg length */
37
38 /* clear a netBSD kernel parameter out of the way */ 
39 #undef          MSGBUFSIZE
40
41 /*
42  * The RFC822 limit on message line size is just 998.  But
43  * make this *way* oversized; idiot DOS-world mailers that
44  * don't line-wrap properly often ship entire paragraphs as
45  * lines.
46  */
47 #define         MSGBUFSIZE      8192
48
49 #define         PASSWORDLEN     64      /* max password length */
50 #define         DIGESTLEN       33      /* length of MD5 digest */
51
52 /* exit code values */
53 #define         PS_SUCCESS      0       /* successful receipt of messages */
54 #define         PS_NOMAIL       1       /* no mail available */
55 #define         PS_SOCKET       2       /* socket I/O woes */
56 #define         PS_AUTHFAIL     3       /* user authorization failed */
57 #define         PS_PROTOCOL     4       /* protocol violation */
58 #define         PS_SYNTAX       5       /* command-line syntax error */
59 #define         PS_IOERR        6       /* bad permissions on rc file */
60 #define         PS_ERROR        7       /* protocol error */
61 #define         PS_EXCLUDE      8       /* client-side exclusion error */
62 #define         PS_LOCKBUSY     9       /* server responded lock busy */
63 #define         PS_SMTP         10      /* SMTP error */
64 #define         PS_DNS          11      /* fatal DNS error */   
65 #define         PS_UNDEFINED    12      /* something I hadn't thought of */
66 #define         PS_TRANSIENT    13      /* transient failure (internal use) */
67 #define         PS_REFUSED      14      /* mail refused (internal use) */
68 #define         PS_RETAINED     15      /* message retained (internal use) */
69 #define         PS_TRUNCATED    16      /* headers incomplete (internal use) */
70
71 /* output noise level */
72 #define         O_SILENT        0       /* mute, max squelch, etc. */
73 #define         O_NORMAL        1       /* user-friendly */
74 #define         O_VERBOSE       2       /* chatty */
75 #define         O_DEBUG         3       /* prolix */
76 #define         O_MONITOR       O_VERBOSE
77
78 #define         SIZETICKER      1024    /* print 1 dot per this many bytes */
79
80 /*
81  * We #ifdef this and use flag rather than bool
82  * to avoid a type clash with curses.h
83  */
84 #ifndef TRUE
85 #define FALSE   0
86 #define TRUE    1
87 #endif /* TRUE */
88 typedef char    flag;
89
90 /* we need to use zero as a flag-uninitialized value */
91 #define FLAG_TRUE       2
92 #define FLAG_FALSE      1
93
94 struct runctl
95 {
96     char        *logfile;
97     char        *idfile;
98     int         poll_interval;
99     flag        use_syslog;
100     flag        invisible;
101     char        *postmaster;
102 };
103
104 struct idlist
105 {
106     char *id;
107     union
108     {
109         struct
110         {
111             short       num;
112             flag        mark;           /* UID-index information */
113 #define UID_UNSEEN      0               /* hasn't been seen */
114 #define UID_SEEN        1               /* seen, but not deleted */
115 #define UID_DELETED     2               /* this message has been deleted */
116 #define UID_EXPUNGED    3               /* this message has been expunged */ 
117         }
118         status;
119         char *id2;
120     } val;
121     struct idlist *next;
122 };
123
124 struct method           /* describe methods for protocol state machine */
125 {
126     char *name;                 /* protocol name */
127 #if INET6
128     char *service;
129 #else /* INET6 */
130     int port;                   /* service port */
131 #endif /* INET6 */
132     flag tagged;                /* if true, generate & expect command tags */
133     flag delimited;             /* if true, accept "." message delimiter */
134     int (*parse_response)();    /* response_parsing function */
135     int (*password_canonify)(); /* canonicalize password */
136     int (*getauth)();           /* authorization fetcher */
137     int (*getrange)();          /* get message range to fetch */
138     int (*getsizes)();          /* get sizes of messages */
139     int (*is_old)();            /* check for old message */
140     int (*fetch_headers)();     /* fetch FROM headera given message */
141     int (*fetch_body)();        /* fetch a given message */
142     int (*trail)();             /* eat trailer of a message */
143     int (*delete)();            /* delete method */
144     int (*logout_cmd)();        /* logout command */
145     flag retry;                 /* can getrange poll for new messages? */
146 };
147
148 struct hostdata         /* shared among all user connections to given server */
149 {
150     /* rc file data */
151     char *pollname;                     /* poll label of host */
152     char *via;                          /* "true" server name if non-NULL */
153     struct idlist *akalist;             /* server name first, then akas */
154     struct idlist *localdomains;        /* list of pass-through domains */
155     int protocol;                       /* protocol type */
156 #if INET6
157     char *service;                      /* IPv6 service name */
158     void *netsec;                       /* IPv6 security request */
159 #else /* INET6 */
160     int port;                           /* TCP/IP service port number */
161 #endif /* INET6 */
162     int interval;                       /* # cycles to skip between polls */
163     int preauthenticate;                /* preauthentication mode to try */
164     int timeout;                        /* inactivity timout in seconds */
165     char *envelope;                     /* envelope address list header */
166     int envskip;                        /* skip to numbered envelope header */
167     char *qvirtual;                     /* prefix removed from local user id */
168     flag skip;                          /* suppress poll in implicit mode? */
169     flag dns;                           /* do DNS lookup on multidrop? */
170     flag uidl;                          /* use RFC1725 UIDLs? */
171 #ifdef SDPS_ENABLE
172     flag sdps;                          /* use Demon Internet SDPS *ENV */
173 #endif /* SDPS_ENABLE */
174     flag checkalias;                    /* resolve aliases by comparing IPs? */
175
176
177 #ifdef linux
178     char *interface;
179     char *monitor;
180     int  monitor_io;
181     struct interface_pair_s *interface_pair;
182 #endif /* linux */
183
184     /* computed for internal use */
185     struct method *base_protocol;       /* relevant protocol method table */
186     int poll_count;                     /* count of polls so far */
187     char *queryname;                    /* name to attempt DNS lookup on */
188     char *truename;                     /* "true name" of server host */
189     struct hostdata *lead_server;       /* ptr to lead query for this server */
190     int esmtp_options;
191 };
192
193 struct query
194 {
195     /* mailserver connection controls */
196     struct hostdata server;
197
198     /* per-user data */
199     struct idlist *localnames;  /* including calling user's name */
200     int wildcard;               /* should unmatched names be passed through */
201     char *remotename;           /* remote login name to use */
202     char *password;             /* remote password to use */
203     struct idlist *mailboxes;   /* list of mailboxes to check */
204     struct idlist *smtphunt;    /* list of SMTP hosts to try forwarding to */
205     char *smtphost;             /* actual SMTP host to point to */
206     char *smtpaddress;          /* address we want to force in the delivery messages */ 
207     struct idlist *antispam;    /* list of listener's antispam response */
208     char *mda;                  /* local MDA to pass mail to */
209     char *preconnect;           /* pre-connection command to execute */
210     char *postconnect;          /* post-connection command to execute */
211
212     /* per-user control flags */
213     flag keep;                  /* if TRUE, leave messages undeleted */
214     flag fetchall;              /* if TRUE, fetch all (not just unseen) */
215     flag flush;                 /* if TRUE, delete messages already seen */
216     flag rewrite;               /* if TRUE, canonicalize recipient addresses */
217     flag stripcr;               /* if TRUE, strip CRs in text */
218     flag forcecr;               /* if TRUE, force CRs before LFs in text */
219     flag pass8bits;             /* if TRUE, ignore Content-Transfer-Encoding */
220     flag dropstatus;            /* if TRUE, drop Status lines in mail */
221     flag mimedecode;            /* if TRUE, decode MIME-coded headers/coded printable*/
222     int limit;                  /* limit size of retrieved messages */
223     int warnings;               /* size warning interval */
224     int fetchlimit;             /* max # msgs to get in single poll */
225     int batchlimit;             /* max # msgs to pass in single SMTP session */
226     int expunge;                /* max # msgs to pass between expunges */
227     char *properties;           /* passthrough properties for extensions */
228
229     struct idlist *oldsaved, *newsaved;
230
231     /* internal use -- per-poll state */
232     flag active;                /* should we actually poll this server? */
233     char *destaddr;             /* destination host for this query */
234     int errcount;               /* count transient errors in last pass */
235     int smtp_socket;            /* socket descriptor for SMTP connection */
236     unsigned int uid;           /* UID of user to deliver to */
237     struct idlist *skipped;     /* messages skipped on the mail server */
238
239     /* internal use -- per-message state */
240     int mimemsg;                /* bitmask indicating MIME body-type */
241     char digest [DIGESTLEN];    /* md5 digest buffer */
242
243     /* internal use -- housekeeping */
244     struct query *next;         /* next query control block in chain */
245 };
246
247 /*
248  * Numeric option handling.  Numeric option value of zero actually means
249  * it's unspecified.  Value less than zero is zero.
250  */
251 #define NUM_VALUE(n)            (((n) == 0) ? -1 : (n))
252 #define NUM_NONZERO(n)          ((n) > 0)
253 #define NUM_ZERO(n)             ((n) < 0)
254 #define NUM_SPECIFIED(n)        ((n) != 0)
255
256 #define MULTIDROP(ctl)  (ctl->wildcard || \
257                                 ((ctl)->localnames && (ctl)->localnames->next))
258
259 /*
260  * Note: tags are generated with an a%04d format from a 1-origin
261  * integer sequence number.  Length 4 permits transaction numbers
262  * up to 9999, so we force rollover with % 10000.  There's no special
263  * reason for this format other than to look like the exmples in the
264  * IMAP RFCs.
265  */
266 #define TAGLEN  6               /* 'a' + 4 digits + NUL */
267 extern char tag[TAGLEN];
268 #define TAGMOD  10000
269
270 /* list of hosts assembled from run control file and command line */
271 extern struct query cmd_opts, *querylist;
272
273 /* what's returned by envquery */
274 extern void envquery(int, char **);
275
276 /* controls the detail level of status/progress messages written to stderr */
277 extern int outlevel;            /* see the O_.* constants above */
278 extern int yydebug;             /* enable parse debugging */
279
280 /* these get computed */
281 extern int batchcount;          /* count of messages sent in current batch */
282 extern flag peek_capable;       /* can we read msgs without setting seen? */
283
284 /* miscellaneous global controls */
285 extern struct runctl run;       /* global controls for this run */
286 extern flag nodetach;           /* if TRUE, don't detach daemon process */
287 extern flag quitmode;           /* if --quit was set */
288 extern flag check_only;         /* if --check was set */
289 extern char *rcfile;            /* path name of rc file */
290 extern int linelimit;           /* limit # lines retrieved per site */
291 extern flag versioninfo;        /* emit only version info */
292 extern char *user;              /* name of invoking user */
293 extern char *home;              /* home directory of invoking user */
294 extern int pass;                /* number of re-polling pass */
295 extern flag configdump;         /* dump control blocks as Python dictionary */
296 extern char *fetchmailhost;     /* either "localhost" or an FQDN */
297
298 /* prototypes for globally callable functions */
299
300 /* error.c: Error reporting */
301 #if defined(HAVE_STDARG_H)
302 void error_init(int foreground);
303 void error (int status, int errnum, const char *format, ...);
304 void error_build (const char *format, ...);
305 void error_complete (int status, int errnum, const char *format, ...);
306 void error_at_line (int, int, const char *, unsigned int, const char *, ...);
307 #else
308 void error ();
309 void error_build ();
310 void error_complete ();
311 void error_at_line ();
312 #endif
313
314 /* driver.c: transaction support */
315 void set_timeout(int);
316 #if defined(HAVE_STDARG_H)
317 void gen_send (int sock, const char *, ... );
318 int gen_recv(int sock, char *buf, int size);
319 int gen_transact (int sock, char *, ... );
320 #else
321 void gen_send ();
322 int gen_recv();
323 int gen_transact ();
324 #endif
325
326 /* use these to track what was happening when the nonresponse timer fired */
327 #define GENERAL_WAIT    0       /* unknown wait type */
328 #define OPEN_WAIT       1       /* waiting from mailserver open */
329 #define SERVER_WAIT     2       /* waiting for mailserver response */
330 #define LISTENER_WAIT   3       /* waiting for listener initialization */
331 #define FORWARDING_WAIT 4       /* waiting for listener response */
332 extern int phase;
333
334 /* mark values for name lists */
335 #define XMIT_ACCEPT             1
336 #define XMIT_REJECT             2
337 #define XMIT_ANTISPAM           3
338
339 /* sink.c: forwarding */
340 int stuffline(struct query *, char *);
341 int open_sink(struct query*, char*, struct idlist*, long reallen, int*, int*);
342 void release_sink(struct query *);
343 int close_sink(struct query *, flag);
344
345 /* rfc822.c: RFC822 header parsing */
346 char *reply_hack(char *, const char *);
347 char *nxtaddr(const char *);
348
349 /* uid.c: UID support */
350 void initialize_saved_lists(struct query *, const char *);
351 struct idlist *save_str(struct idlist **, const char *, flag);
352 void free_str_list(struct idlist **);
353 void save_str_pair(struct idlist **, const char *, const char *);
354 void free_str_pair_list(struct idlist **);
355 int delete_str(struct idlist **, int);
356 int str_in_list(struct idlist **, const char *, const flag);
357 int str_nr_in_list(struct idlist **, const char *);
358 int str_nr_last_in_list(struct idlist **, const char *);
359 void str_set_mark( struct idlist **, const char *, const flag);
360 int count_list( struct idlist **idl );
361 char *str_from_nr_list( struct idlist **idl, int number );
362 char *str_find(struct idlist **, int);
363 char *idpair_find(struct idlist **, const char *);
364 void append_str_list(struct idlist **, struct idlist **);
365 void expunge_uids(struct query *);
366 void update_str_lists(struct query *);
367 void write_saved_lists(struct query *, const char *);
368
369 /* rcfile_y.y */
370 int prc_parse_file(const char *, const flag);
371 int prc_filecheck(const char *, const flag);
372
373 /* base64.c */
374 void to64frombits(unsigned char *, const unsigned char *, int);
375 int from64tobits(char *, const char *);
376
377 /* unmime.c */
378 /* Bit-mask returned by MimeBodyType */
379 #define MSG_IS_7BIT       0x01
380 #define MSG_IS_8BIT       0x02
381 #define MSG_NEEDS_DECODE  0x80
382 extern void UnMimeHeader(unsigned char *buf);
383 extern int  MimeBodyType(unsigned char *hdrs, int WantDecode);
384 extern int  UnMimeBodyline(unsigned char **buf, int collapsedoubledot);
385
386 /* interface.c */
387 void interface_parse(char *, struct hostdata *);
388 void interface_note_activity(struct hostdata *);
389 int interface_approve(struct hostdata *);
390
391 /* xmalloc.c */
392 #if defined(HAVE_VOIDPOINTER)
393 #define XMALLOCTYPE void
394 #else
395 #define XMALLOCTYPE char
396 #endif
397 XMALLOCTYPE *xmalloc(int);
398 XMALLOCTYPE *xrealloc(XMALLOCTYPE *, int);
399 char *xstrdup(const char *);
400 #if defined(HAVE_ALLOCA_H)
401 #include <alloca.h>
402 #else
403 #ifdef _AIX
404  #pragma alloca
405 #endif
406 #endif
407 #define xalloca(ptr, t, n)      if (!(ptr = (t) alloca(n))) error(PS_UNDEFINED, 0, "alloca failed")
408
409 /* protocol driver and methods */
410 int do_protocol(struct query *, const struct method *);
411 int doPOP2 (struct query *); 
412 int doPOP3 (struct query *);
413 int doIMAP (struct query *);
414 int doETRN (struct query *);
415
416 /* miscellanea */
417 struct query *hostalloc(struct query *); 
418 int parsecmdline (int, char **, struct runctl *, struct query *);
419 char *MD5Digest (unsigned char *);
420 int POP3_auth_rpa(unsigned char *, unsigned char *, int socket);
421 int daemonize(const char *, void (*)(int));
422 char *getpassword(char *);
423 void escapes(const char *, char *);
424 char *visbuf(const char *);
425 char *showproto(int);
426 void dump_config(struct runctl *runp, struct query *querylist);
427 int is_host_alias(const char *, struct query *);
428 char *host_fqdn(void);
429 #ifdef SDPS_ENABLE
430 char *sdps_envto;
431 #endif /* SDPS_ENABLE */
432
433 void yyerror(const char *);
434 int yylex(void);
435
436 #ifdef __EMX__
437 void itimerthread(void*);
438 /* Have to include these first to avoid errors from redefining getcwd
439    and chdir.  They're re-include protected in EMX, so it's okay, I
440    guess.  */
441 #include <stdlib.h>
442 #include <unistd.h>
443 /* Redefine getcwd and chdir to get drive-letter support so we can
444    find all of our lock files and stuff. */
445 #define getcwd _getcwd2
446 #define chdir _chdir2
447 #endif
448
449 #define STRING_DISABLED (char *)-1
450 #define STRING_DUMMY    ""
451
452 /* fetchmail.h ends here */