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