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