]> Pileus Git - ~andy/fetchmail/blob - fetchmail.h
7b2076d641afa6e71b5b4cb1993e80aea3e6e9b3
[~andy/fetchmail] / fetchmail.h
1 /*
2  * For license terms, see the file COPYING in this directory.
3  */
4
5 /* We need this for HAVE_STDARG_H, etc */
6 #include "config.h"
7
8 /* We need this for size_t */
9 #include <sys/types.h>
10
11 /* We need this for time_t */
12 #if TIME_WITH_SYS_TIME
13 # include <sys/time.h>
14 # include <time.h>
15 #else
16 # if HAVE_SYS_TIME_H
17 #  include <sys/time.h>
18 # else
19 #  include <time.h>
20 # endif
21 #endif
22
23 #include <stdio.h>
24
25 /* Import Trio if needed */
26 #if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
27 #  include "trio/trio.h"
28 #endif
29
30 /* We need this for strstr */
31 #if !defined(HAVE_STRSTR) && !defined(strstr)
32 char *strstr(const char *, const char *);
33 #endif
34
35 /* constants designating the various supported protocols */
36 #define         P_AUTO          1
37 #define         P_POP2          2
38 #define         P_POP3          3
39 #define         P_APOP          4
40 #define         P_RPOP          5
41 #define         P_IMAP          6
42 #define         P_ETRN          7
43 #define         P_ODMR          8
44
45 #define         SMTP_PORT       "smtp"
46 #define         SMTP_PORT_NUM   25
47 #define         KPOP_PORT       "kpop"
48
49 #ifdef SSL_ENABLE
50 #define         SIMAP_PORT      993
51 #define         SPOP3_PORT      995
52 #endif
53
54 /* 
55  * We need to distinguish between mailbox and mailbag protocols.
56  * Under a mailbox protocol wwe're pulling mail for a speecific user.
57  * Under a mailbag protocol we're fetching mail for an entire domain.
58  */
59 #define MAILBOX_PROTOCOL(ctl)   ((ctl)->server.protocol < P_ETRN)
60
61 /* authentication types */
62 #define         A_ANY           0       /* use the first method that works */
63 #define         A_PASSWORD      1       /* password authentication */
64 #define         A_NTLM          2       /* Microsoft NTLM protocol */
65 #define         A_CRAM_MD5      3       /* CRAM-MD5 shrouding (RFC2195) */
66 #define         A_OTP           4       /* One-time password (RFC1508) */
67 #define         A_KERBEROS_V4   5       /* authenticate w/ Kerberos V4 */
68 #define         A_KERBEROS_V5   6       /* authenticate w/ Kerberos V5 */
69 #define         A_GSSAPI        7       /* authenticate with GSSAPI */
70 #define         A_SSH           8       /* authentication at session level */
71
72 /* some protocols (KERBEROS, GSSAPI, SSH) don't require a password */
73 #define NO_PASSWORD(ctl)        ((ctl)->server.authenticate > A_OTP || (ctl)->server.protocol == P_ETRN)
74
75 /*
76  * Definitions for buffer sizes.  We get little help on setting maxima
77  * from IMAP RFCs up to 2060, so these are mostly from POP3.
78  */
79 #define         HOSTLEN         635     /* max hostname length (RFC1123) */
80 #define         POPBUFSIZE      512     /* max length of response (RFC1939) */
81 #define         IDLEN           128     /* max length of UID (RFC1939) */
82
83 /* per RFC1939 this should be 40, but Microsoft Exchange ignores that limit */
84 #define         USERNAMELEN     128     /* max POP3 arg length */
85
86 /* clear a netBSD kernel parameter out of the way */ 
87 #undef          MSGBUFSIZE
88
89 /*
90  * The RFC822 limit on message line size is just 998.  But
91  * make this *way* oversized; idiot DOS-world mailers that
92  * don't line-wrap properly often ship entire paragraphs as
93  * lines.
94  */
95 #define         MSGBUFSIZE      8192
96
97 #define         NAMELEN         64      /* max username length */
98 #define         PASSWORDLEN     64      /* max password length */
99 #define         DIGESTLEN       33      /* length of MD5 digest */
100
101 /* exit code values */
102 #define         PS_SUCCESS      0       /* successful receipt of messages */
103 #define         PS_NOMAIL       1       /* no mail available */
104 #define         PS_SOCKET       2       /* socket I/O woes */
105 #define         PS_AUTHFAIL     3       /* user authorization failed */
106 #define         PS_PROTOCOL     4       /* protocol violation */
107 #define         PS_SYNTAX       5       /* command-line syntax error */
108 #define         PS_IOERR        6       /* bad permissions on rc file */
109 #define         PS_ERROR        7       /* protocol error */
110 #define         PS_EXCLUDE      8       /* client-side exclusion error */
111 #define         PS_LOCKBUSY     9       /* server responded lock busy */
112 #define         PS_SMTP         10      /* SMTP error */
113 #define         PS_DNS          11      /* fatal DNS error */
114 #define         PS_BSMTP        12      /* output batch could not be opened */
115 #define         PS_MAXFETCH     13      /* poll ended by fetch limit */
116 #define         PS_SERVBUSY     14      /* server is busy */
117 /* leave space for more codes */
118 #define         PS_UNDEFINED    23      /* something I hadn't thought of */
119 #define         PS_TRANSIENT    24      /* transient failure (internal use) */
120 #define         PS_REFUSED      25      /* mail refused (internal use) */
121 #define         PS_RETAINED     26      /* message retained (internal use) */
122 #define         PS_TRUNCATED    27      /* headers incomplete (internal use) */
123 #define         PS_REPOLL       28      /* repoll immediately with changed parameters (internal use) */
124 #define         PS_IDLETIMEOUT  29      /* timeout on imap IDLE (internal use) */
125
126 /* output noise level */
127 #define         O_SILENT        0       /* mute, max squelch, etc. */
128 #define         O_NORMAL        1       /* user-friendly */
129 #define         O_VERBOSE       2       /* chatty */
130 #define         O_DEBUG         3       /* prolix */
131 #define         O_MONITOR       O_VERBOSE
132
133 #define         SIZETICKER      1024    /* print 1 dot per this many bytes */
134
135 /*
136  * We #ifdef this and use flag rather than bool
137  * to avoid a type clash with curses.h
138  */
139 #ifndef TRUE
140 #define FALSE   0
141 #define TRUE    1
142 #endif /* TRUE */
143 typedef char    flag;
144
145 /* we need to use zero as a flag-uninitialized value */
146 #define FLAG_TRUE       2
147 #define FLAG_FALSE      1
148
149 struct runctl
150 {
151     char        *logfile;
152     char        *idfile;
153     int         poll_interval;
154     char        *postmaster;
155     flag        bouncemail;
156     flag        spambounce;
157     char        *properties;
158     flag        use_syslog;
159     flag        invisible;
160     flag        showdots;
161 };
162
163 struct idlist
164 {
165     unsigned char *id;
166     union
167     {
168         struct
169         {
170             int         num;
171             flag        mark;           /* UID-index information */
172 #define UID_UNSEEN      0               /* hasn't been seen */
173 #define UID_SEEN        1               /* seen, but not deleted */
174 #define UID_DELETED     2               /* this message has been deleted */
175 #define UID_EXPUNGED    3               /* this message has been expunged */ 
176         }
177         status;
178         unsigned char *id2;
179     } val;
180     struct idlist *next;
181 };
182
183 struct query;
184
185 struct method           /* describe methods for protocol state machine */
186 {
187     const char *name;           /* protocol name */
188     const char *service;        /* service port (unencrypted) */
189     const char *sslservice;     /* service port (SSL) */
190     flag tagged;                /* if true, generate & expect command tags */
191     flag delimited;             /* if true, accept "." message delimiter */
192     int (*parse_response)(int, char *);
193                                 /* response_parsing function */
194     int (*getauth)(int, struct query *, char *);
195                                 /* authorization fetcher */
196     int (*getrange)(int, struct query *, const char *, int *, int *, int *);
197                                 /* get message range to fetch */
198     int (*getsizes)(int, int, int *);
199                                 /* get sizes of messages */
200     int (*getpartialsizes)(int, int, int, int *);
201                                 /* get sizes of subset of messages */
202     int (*is_old)(int, struct query *, int);
203                                 /* check for old message */
204     int (*fetch_headers)(int, struct query *, int, int *);
205                                 /* fetch FROM headera given message */
206     int (*fetch_body)(int, struct query *, int, int *);
207                                 /* fetch a given message */
208     int (*trail)(int, struct query *, int);
209                                 /* eat trailer of a message */
210     int (*delete)(int, struct query *, int);
211                                 /* delete method */
212     int (*mark_seen)(int, struct query *, int);
213                                 /* mark as seen method */
214     int (*logout_cmd)(int, struct query *);
215                                 /* logout command */
216     flag retry;                 /* can getrange poll for new messages? */
217 };
218
219 struct hostdata         /* shared among all user connections to given server */
220 {
221     /* rc file data */
222     char *pollname;                     /* poll label of host */
223     char *via;                          /* "true" server name if non-NULL */
224     struct idlist *akalist;             /* server name first, then akas */
225     struct idlist *localdomains;        /* list of pass-through domains */
226     int protocol;                       /* protocol type */
227     char *service;                      /* service name */
228     int interval;                       /* # cycles to skip between polls */
229     int authenticate;                   /* authentication mode to try */
230     int timeout;                        /* inactivity timout in seconds */
231     char *envelope;                     /* envelope address list header */
232     int envskip;                        /* skip to numbered envelope header */
233     char *qvirtual;                     /* prefix removed from local user id */
234     flag skip;                          /* suppress poll in implicit mode? */
235     flag dns;                           /* do DNS lookup on multidrop? */
236     flag uidl;                          /* use RFC1725 UIDLs? */
237 #ifdef SDPS_ENABLE
238     flag sdps;                          /* use Demon Internet SDPS *ENV */
239 #endif /* SDPS_ENABLE */
240     flag checkalias;                    /* resolve aliases by comparing IPs? */
241     flag tracepolls;                    /* if TRUE, add poll trace info to Received */
242     char *principal;                    /* Kerberos principal for mail service */
243     char *esmtp_name, *esmtp_password;  /* ESMTP AUTH information */
244
245 #if defined(linux) || defined(__FreeBSD__)
246     char *interface;
247     char *monitor;
248     int  monitor_io;
249     struct interface_pair_s *interface_pair;
250 #endif /* linux */
251
252     char *plugin,*plugout;
253
254     /* computed for internal use */
255     const struct method *base_protocol; /* relevant protocol method table */
256     int poll_count;                     /* count of polls so far */
257     char *queryname;                    /* name to attempt DNS lookup on */
258     char *truename;                     /* "true name" of server host */
259     char *trueaddr;                     /* IP address of truename, as char */
260     struct hostdata *lead_server;       /* ptr to lead query for this server */
261     int esmtp_options;
262 };
263
264 struct query
265 {
266     /* mailserver connection controls */
267     struct hostdata server;
268
269     /* per-user data */
270     struct idlist *localnames;  /* including calling user's name */
271     int wildcard;               /* should unmatched names be passed through */
272     char *remotename;           /* remote login name to use */
273     char *password;             /* remote password to use */
274     struct idlist *mailboxes;   /* list of mailboxes to check */
275
276     /* per-forwarding-target data */
277     struct idlist *smtphunt;    /* list of SMTP hosts to try forwarding to */
278     struct idlist *domainlist;  /* domainlist to fetch from */
279     char *smtpaddress;          /* address to force in RCPT TO */ 
280     char *smtpname;             /* full RCPT TO name, including domain */
281     struct idlist *antispam;    /* list of listener's antispam response */
282     char *mda;                  /* local MDA to pass mail to */
283     char *bsmtp;                /* BSMTP output file */
284     char listener;              /* what's the listener's wire protocol? */
285 #define SMTP_MODE       'S'
286 #define LMTP_MODE       'L'
287     char *preconnect;           /* pre-connection command to execute */
288     char *postconnect;          /* post-connection command to execute */
289
290     /* per-user control flags */
291     flag keep;                  /* if TRUE, leave messages undeleted */
292     flag fetchall;              /* if TRUE, fetch all (not just unseen) */
293     flag flush;                 /* if TRUE, delete messages already seen */
294     flag rewrite;               /* if TRUE, canonicalize recipient addresses */
295     flag stripcr;               /* if TRUE, strip CRs in text */
296     flag forcecr;               /* if TRUE, force CRs before LFs in text */
297     flag pass8bits;             /* if TRUE, ignore Content-Transfer-Encoding */
298     flag dropstatus;            /* if TRUE, drop Status lines in mail */
299     flag dropdelivered;         /* if TRUE, drop Delivered-To lines in mail */
300     flag mimedecode;            /* if TRUE, decode MIME-armored messages */
301     flag idle;                  /* if TRUE, idle after each poll */
302     int limit;                  /* limit size of retrieved messages */
303     int warnings;               /* size warning interval */
304     int fetchlimit;             /* max # msgs to get in single poll */
305     int fetchsizelimit;         /* max # msg sizes to get in a request */
306     int fastuidl;               /* do binary search for new UIDLs? */
307     int fastuidlcount;          /* internal count for frequency of binary search */
308     int batchlimit;             /* max # msgs to pass in single SMTP session */
309     int expunge;                /* max # msgs to pass between expunges */
310     flag use_ssl;               /* use SSL encrypted session */
311     char *sslkey;               /* optional SSL private key file */
312     char *sslcert;              /* optional SSL certificate file */
313         char *sslproto;         /* force usage of protocol (ssl2|ssl3|tls1) - defaults to ssl23 */
314     char *sslcertpath;          /* Trusted certificate directory for checking the server cert */
315     flag sslcertck;             /* Strictly check the server cert. */
316     char *sslfingerprint;       /* Fingerprint to check against */
317     char *properties;           /* passthrough properties for extensions */
318
319     /* internal use -- per-poll state */
320     flag active;                /* should we actually poll this server? */
321     const char *destaddr;       /* destination host for this query */
322     int errcount;               /* count transient errors in last pass */
323     int authfailcount;          /* count of authorization failures */
324     int wehaveauthed;           /* We've managed to logon at least once! */
325     int wehavesentauthnote;     /* We've sent an authorization failure note */
326     int wedged;                 /* wedged by auth failures or timeouts? */
327     char *smtphost;             /* actual SMTP host we connected to */
328     int smtp_socket;            /* socket descriptor for SMTP connection */
329     unsigned int uid;           /* UID of user to deliver to */
330     struct idlist *skipped;     /* messages skipped on the mail server */
331     struct idlist *oldsaved, *newsaved;
332     struct idlist **oldsavedend;
333     char lastdigest[DIGESTLEN]; /* last MD5 hash seen on this connection */
334
335     /* internal use -- per-message state */
336     int mimemsg;                /* bitmask indicating MIME body-type */
337     char digest[DIGESTLEN];     /* md5 digest buffer */
338
339     /* internal use -- housekeeping */
340     struct query *next;         /* next query control block in chain */
341 };
342
343 struct msgblk                   /* message header parsed for open_sink() */
344 {
345     char                *headers;       /* raw message headers */
346     struct idlist       *recipients;    /* addressees */
347     char                return_path[HOSTLEN + USERNAMELEN + 4]; 
348     int                 msglen;
349     int                 reallen;
350 };
351
352
353 /*
354  * Numeric option handling.  Numeric option value of zero actually means
355  * it's unspecified.  Value less than zero is zero.  The reason for this
356  * screwy encoding is so we can zero out an option block in order to set the
357  * numeric flags in it to unspecified.
358  */
359 #define NUM_VALUE_IN(n)         (((n) == 0) ? -1 : (n))
360 #define NUM_VALUE_OUT(n)        (((n) < 0) ? 0 : (n))
361 #define NUM_NONZERO(n)          ((n) > 0)
362 #define NUM_ZERO(n)             ((n) < 0)
363 #define NUM_SPECIFIED(n)        ((n) != 0)
364
365 #define MULTIDROP(ctl)  (ctl->wildcard || \
366                                 ((ctl)->localnames && (ctl)->localnames->next))
367
368 /*
369  * Note: tags are generated with an a%04d format from a 1-origin
370  * integer sequence number.  Length 4 permits transaction numbers
371  * up to 9999, so we force rollover with % 10000.  There's no special
372  * reason for this format other than to look like the exmples in the
373  * IMAP RFCs.
374  */
375 #define TAGLEN  6               /* 'a' + 4 digits + NUL */
376 extern char tag[TAGLEN];
377 #define TAGMOD  10000
378
379 /* list of hosts assembled from run control file and command line */
380 extern struct query cmd_opts, *querylist;
381
382 /* what's returned by envquery */
383 extern void envquery(int, char **);
384
385 /* controls the detail level of status/progress messages written to stderr */
386 extern int outlevel;            /* see the O_.* constants above */
387 extern int yydebug;             /* enable parse debugging */
388
389 /* these get computed */
390 extern int batchcount;          /* count of messages sent in current batch */
391 extern flag peek_capable;       /* can we read msgs without setting seen? */
392
393 /* miscellaneous global controls */
394 extern struct runctl run;       /* global controls for this run */
395 extern flag nodetach;           /* if TRUE, don't detach daemon process */
396 extern flag quitmode;           /* if --quit was set */
397 extern flag check_only;         /* if --check was set */
398 extern char *rcfile;            /* path name of rc file */
399 extern int linelimit;           /* limit # lines retrieved per site */
400 extern flag versioninfo;        /* emit only version info */
401 extern char *user;              /* name of invoking user */
402 extern char *home;              /* home directory of invoking user */
403 extern char *fmhome;            /* fetchmail home directory */
404 extern int pass;                /* number of re-polling pass */
405 extern flag configdump;         /* dump control blocks as Python dictionary */
406 extern char *fetchmailhost;     /* either "localhost" or an FQDN */
407 extern int suppress_tags;       /* suppress tags in tagged protocols? */
408 extern char shroud[PASSWORDLEN*2+3];    /* string to shroud in debug output */
409 #ifdef SDPS_ENABLE
410 extern char *sdps_envfrom;
411 extern char *sdps_envto;
412 #endif /* SDPS_ENABLE */
413
414 extern const char *iana_charset;        /* IANA assigned charset name */
415
416 /* from ucs/norm_charmap.c */
417 const char *norm_charmap(const char *name);
418
419 /* prototypes for globally callable functions */
420
421 /* from /usr/include/sys/cdefs.h */
422 #if !defined __GNUC__ || __GNUC__ < 2
423 # define __attribute__(xyz)    /* Ignore. */
424 #endif
425
426 /* error.c: Error reporting */
427 #if defined(HAVE_STDARG_H)
428 void report_init(int foreground);
429 void report (FILE *fp, const char *format, ...)
430     __attribute__ ((format (printf, 2, 3)))
431     ;
432 void report_build (FILE *fp, const char *format, ...)
433     __attribute__ ((format (printf, 2, 3)))
434     ;
435 void report_complete (FILE *fp, const char *format, ...)
436     __attribute__ ((format (printf, 2, 3)))
437     ;
438 void report_at_line (FILE *fp, int, const char *, unsigned int, const char *, ...)
439     __attribute__ ((format (printf, 5, 6)))
440     ;
441 #else
442 void report ();
443 void report_build ();
444 void report_complete ();
445 void report_at_line ();
446 #endif
447
448 /* driver.c -- main driver loop */
449 void set_timeout(int);
450 int isidletimeout(void);
451 void resetidletimeout(void);
452 int do_protocol(struct query *, const struct method *);
453
454 /* transact.c: transaction support */
455 void init_transact(const struct method *);
456 int readheaders(int sock,
457                        long fetchlen,
458                        long reallen,
459                        struct query *ctl,
460                        int num,
461                        flag *suppress_readbody);
462 int readbody(int sock, struct query *ctl, flag forward, int len);
463 #if defined(HAVE_STDARG_H)
464 void gen_send(int sock, const char *, ... )
465     __attribute__ ((format (printf, 2, 3)))
466     ;
467 int gen_recv(int sock, char *buf, int size);
468 int gen_transact(int sock, const char *, ... )
469     __attribute__ ((format (printf, 2, 3)))
470     ;
471 #else
472 void gen_send();
473 int gen_recv();
474 int gen_transact();
475 #endif
476 extern struct msgblk msgblk;
477
478 /* lock.c: concurrency locking */
479 void lock_setup(void);
480 void lock_assert(void);
481 void lock_or_die(void);
482 void fm_lock_release(void);
483 int lock_state(void);
484 void lock_dispose(void);
485
486 /* use these to track what was happening when the nonresponse timer fired */
487 #define GENERAL_WAIT    0       /* unknown wait type */
488 #define OPEN_WAIT       1       /* waiting from mailserver open */
489 #define SERVER_WAIT     2       /* waiting for mailserver response */
490 #define LISTENER_WAIT   3       /* waiting for listener initialization */
491 #define FORWARDING_WAIT 4       /* waiting for listener response */
492 extern int phase;
493
494 /* response hooks can use this to identify the query stage */
495 #define STAGE_GETAUTH   0
496 #define STAGE_GETRANGE  1
497 #define STAGE_GETSIZES  2
498 #define STAGE_FETCH     3
499 #define STAGE_IDLE      4
500 #define STAGE_LOGOUT    5
501 extern int stage;
502
503 extern int mytimeout;
504
505 /* mark values for name lists */
506 #define XMIT_ACCEPT     1       /* accepted; matches local domain or name */
507 #define XMIT_REJECT     2       /* rejected; no match */
508 #define XMIT_RCPTBAD    3       /* SMTP listener rejected the name */ 
509
510 /* idle.c */
511 int interruptible_idle(int interval);
512 extern volatile int lastsig;
513
514 /* sink.c: forwarding */
515 void smtp_close(struct query *, int);
516 int smtp_open(struct query *);
517 char *rcpt_address(struct query *, const char *, int);
518 int stuffline(struct query *, char *);
519 int open_sink(struct query*, struct msgblk *, int*, int*);
520 void release_sink(struct query *);
521 int close_sink(struct query *, struct msgblk *, flag);
522 int open_warning_by_mail(struct query *, struct msgblk *);
523 #if defined(HAVE_STDARG_H)
524 void stuff_warning(const char *, struct query *, const char *, ... )
525     __attribute__ ((format (printf, 3, 4)))
526     ;
527 #else
528 void stuff_warning();
529 #endif
530 void close_warning_by_mail(struct query *, struct msgblk *);
531
532 /* rfc822.c: RFC822 header parsing */
533 unsigned char *reply_hack(unsigned char *, const unsigned char *, size_t *);
534 unsigned char *nxtaddr(const unsigned char *);
535
536 /* uid.c: UID support */
537 extern int dofastuidl;
538
539 void initialize_saved_lists(struct query *, const char *);
540 struct idlist *save_str(struct idlist **, const char *, flag);
541 void free_str_list(struct idlist **);
542 struct idlist *copy_str_list(struct idlist *idl);
543 void save_str_pair(struct idlist **, const char *, const char *);
544 void free_str_pair_list(struct idlist **);
545 int delete_str(struct idlist **, long);
546 struct idlist *str_in_list(struct idlist **, const char *, const flag);
547 int str_nr_in_list(struct idlist **, const char *);
548 int str_nr_last_in_list(struct idlist **, const char *);
549 void str_set_mark( struct idlist **, const char *, const flag);
550 int count_list( struct idlist **idl );
551 char *str_from_nr_list( struct idlist **idl, long number );
552 char *str_find(struct idlist **, long);
553 struct idlist *id_find(struct idlist **idl, long);
554 char *idpair_find(struct idlist **, const char *);
555 void append_str_list(struct idlist **, struct idlist **);
556 void expunge_uids(struct query *);
557 void uid_swap_lists(struct query *);
558 void uid_discard_new_list(struct query *ctl);
559 void uid_reset_num(struct query *ctl);
560 void write_saved_lists(struct query *, const char *);
561
562 /* rcfile_y.y */
563 int prc_parse_file(const char *, const flag);
564 int prc_filecheck(const char *, const flag);
565
566 /* base64.c */
567 void to64frombits(unsigned char *, const unsigned char *, int);
568 int from64tobits(char *, const char *, int maxlen);
569
570 /* unmime.c */
571 /* Bit-mask returned by MimeBodyType */
572 #define MSG_IS_7BIT       0x01
573 #define MSG_IS_8BIT       0x02
574 #define MSG_NEEDS_DECODE  0x80
575 extern void UnMimeHeader(unsigned char *buf);
576 extern int  MimeBodyType(unsigned char *hdrs, int WantDecode);
577 extern int  UnMimeBodyline(unsigned char **buf, flag delimited, flag issoftline);
578
579 /* interface.c */
580 void interface_init(void);
581 void interface_parse(char *, struct hostdata *);
582 void interface_note_activity(struct hostdata *);
583 int interface_approve(struct hostdata *, flag domonitor);
584
585 /* xmalloc.c */
586 #if defined(HAVE_VOIDPOINTER)
587 #define XMALLOCTYPE void
588 #else
589 #define XMALLOCTYPE char
590 #endif
591 XMALLOCTYPE *xmalloc(size_t);
592 XMALLOCTYPE *xrealloc(/*@null@*/ XMALLOCTYPE *, size_t);
593 #define xfree(p) { if (p) { free(p); } (p) = 0; }
594 char *xstrdup(const char *);
595
596 /* protocol driver and methods */
597 int doPOP2 (struct query *); 
598 int doPOP3 (struct query *);
599 int doIMAP (struct query *);
600 int doETRN (struct query *);
601 int doODMR (struct query *);
602
603 /* authentication functions */
604 int do_cram_md5(int sock, char *command, struct query *ctl, char *strip);
605 int do_rfc1731(int sock, char *command, char *truename);
606 int do_gssauth(int sock, char *command, char *service, char *hostname, char *username);
607 int do_otp(int sock, char *command, struct query *ctl);
608
609 /* miscellanea */
610
611 /* these should be of size PATH_MAX */
612 extern char currentwd[1024], rcfiledir[1024];
613
614 struct query *hostalloc(struct query *); 
615 int parsecmdline (int, char **, struct runctl *, struct query *);
616 char *prependdir (const char *, const char *);
617 char *MD5Digest (unsigned char *);
618 void hmac_md5 (unsigned char *, size_t, unsigned char *, size_t, unsigned char *, size_t);
619 int POP3_auth_rpa(unsigned char *, unsigned char *, int socket);
620 typedef RETSIGTYPE (*SIGHANDLERTYPE) (int);
621 void deal_with_sigchld(void);
622 RETSIGTYPE null_signal_handler(int sig);
623 SIGHANDLERTYPE set_signal_handler(int sig, SIGHANDLERTYPE handler);
624 int daemonize(const char *, void (*)(int));
625 char *fm_getpassword(char *);
626 void escapes(const char *, char *);
627 char *visbuf(const char *);
628 const char *showproto(int);
629 void dump_config(struct runctl *runp, struct query *querylist);
630 int is_host_alias(const char *, struct query *);
631 char *host_fqdn(void);
632 char *rfc822timestamp(void);
633 flag isafile(int);
634 char *rfc2047e(const char*, const char *);
635
636 void yyerror(const char *);
637 int yylex(void);
638
639 #ifdef __EMX__
640 void itimerthread(void*);
641 /* Have to include these first to avoid errors from redefining getcwd
642    and chdir.  They're re-include protected in EMX, so it's okay, I
643    guess.  */
644 #include <stdlib.h>
645 #include <unistd.h>
646 /* Redefine getcwd and chdir to get drive-letter support so we can
647    find all of our lock files and stuff. */
648 #define getcwd _getcwd2
649 #define chdir _chdir2
650 #endif /* _EMX_ */
651
652 # if HAVE_STRERROR
653 #  ifndef strerror              /* On some systems, strerror is a macro */
654 char *strerror (int);
655 #  endif
656 # endif /* HAVE_STRERROR */
657
658 #define STRING_DISABLED (char *)-1
659 #define STRING_DUMMY    ""
660
661 #ifdef NeXT
662 #ifndef S_IXGRP
663 #define S_IXGRP 0000010
664 #endif
665 #endif
666
667 #ifndef HAVE_STPCPY
668 char *stpcpy(char *, const char*);
669 #endif
670
671 #ifdef FETCHMAIL_DEBUG
672 #define exit(e) do { \
673        FILE *out; \
674        out = fopen("/tmp/fetchmail.log", "a"); \
675        fprintf(out, \
676                "Exiting fetchmail from file %s, line %d with status %d\n", \
677                __FILE__, __LINE__, e); \
678        fclose(out); \
679        _exit(e); \
680        } while(0)
681 #endif /* FETCHMAIL_DEBUG */
682
683 #ifdef __CYGWIN__
684 #define ROOT_UID 18
685 #else /* !__CYGWIN__ */
686 #define ROOT_UID 0
687 #endif /* __CYGWIN__ */
688
689 extern int mailserver_socket_temp;
690 extern char *program_name;
691
692 /* POSIX space characters,
693  * <tab>;<newline>;<vertical-tab>;<form-feed>;<carriage-return>;<space> */
694 #define POSIX_space "\t\n\v\f\r "
695
696 /* strlcpy/strlcat prototypes */
697 #ifndef HAVE_STRLCAT
698 size_t
699 strlcat(char *dst, const char *src, size_t siz);
700 #endif
701 #ifndef HAVE_STRLCPY
702 size_t
703 strlcpy(char *dst, const char *src, size_t siz);
704 #endif
705
706 /** Resolve the a TCP service name or a string containing only a decimal
707  * positive integer to a port number. Returns -1 for error. */
708 int servport(const char *service);
709
710 /* fetchmail.h ends here */