]> Pileus Git - ~andy/fetchmail/blob - fetchmail.c
Typo fix.
[~andy/fetchmail] / fetchmail.c
1 /*
2  * fetchmail.c -- main driver module for fetchmail
3  *
4  * For license terms, see the file COPYING in this directory.
5  */
6 #include "config.h"
7
8 #include <stdio.h>
9 #include <ctype.h>
10 #if defined(STDC_HEADERS)
11 #include <stdlib.h>
12 #endif
13 #if defined(HAVE_UNISTD_H)
14 #include <unistd.h>
15 #endif
16 #include <fcntl.h>
17 #include <string.h>
18 #include <signal.h>
19 #include <getopt.h>
20 #if defined(HAVE_SYSLOG)
21 #include <syslog.h>
22 #endif
23 #include <pwd.h>
24 #ifdef __FreeBSD__
25 #include <grp.h>
26 #endif
27 #include <errno.h>
28 #include <sys/time.h>
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #ifdef HAVE_SETRLIMIT
32 #include <sys/resource.h>
33 #endif /* HAVE_SETRLIMIT */
34 #ifdef HAVE_SYS_WAIT_H
35 #include <sys/wait.h>
36 #endif /* HAVE_SYS_WAIT_H */
37 #include <sys/utsname.h>
38
39 #ifdef HAVE_GETHOSTBYNAME
40 #include <netdb.h>
41 #endif /* HAVE_GETHOSTBYNAME */
42
43 #ifdef HESIOD
44 #include <hesiod.h>
45 #endif
46
47 #include "fetchmail.h"
48 #include "tunable.h"
49 #include "smtp.h"
50 #include "netrc.h"
51 #include "i18n.h"
52
53 #ifndef ENETUNREACH
54 #define ENETUNREACH   128       /* Interactive doesn't know this */
55 #endif /* ENETUNREACH */
56
57 /* prototypes for internal functions */
58 static int load_params(int, char **, int);
59 static void dump_params (struct runctl *runp, struct query *, flag implicit);
60 static int query_host(struct query *);
61
62 /* controls the detail level of status/progress messages written to stderr */
63 int outlevel;               /* see the O_.* constants above */
64
65 /* miscellaneous global controls */
66 struct runctl run;          /* global controls for this run */
67 flag nodetach;              /* if TRUE, don't detach daemon process */
68 flag quitmode;              /* if --quit was set */
69 flag check_only;            /* if --probe was set */
70 flag versioninfo;           /* emit only version info */
71 char *user;                 /* the name of the invoking user */
72 char *home;                 /* invoking user's home directory */
73 char *program_name;         /* the name to prefix error messages with */
74 flag configdump;            /* dump control blocks for configurator */
75 const char *fetchmailhost;  /* either `localhost' or the host's FQDN */
76 volatile int lastsig;           /* last signal received */
77
78 #if NET_SECURITY
79 void *request = NULL;
80 int requestlen = 0;
81 #endif /* NET_SECURITY */
82
83 static char *lockfile;          /* name of lockfile */
84 static int lock_acquired;       /* have we acquired a lock */
85 static int querystatus;         /* status of query */
86 static int successes;           /* count number of successful polls */
87 static struct runctl cmd_run;   /* global options set from command line */
88 static time_t parsetime;        /* time of last parse */
89
90 static void terminate_run(int);
91 static void terminate_poll(int);
92
93 #ifdef SLEEP_WITH_ALARM
94 /*
95  * The function of this variable is to remove the window during which a
96  * SIGALRM can hose the code (ALARM is triggered *before* pause() is called).
97  * This is a bit of a kluge; the real right thing would use sigprocmask(),
98  * sigsuspend().  This workaround lets the interval timer trigger the first
99  * alarm after the required interval and will then generate alarms all 5
100  * seconds, until it is certain, that the critical section (ie., the window)
101  * is left.
102  */
103 #if defined(STDC_HEADERS)
104 static sig_atomic_t     alarm_latch = FALSE;
105 #else
106 /* assume int can be written in one atomic operation on non ANSI-C systems */
107 static int              alarm_latch = FALSE;
108 #endif
109
110 RETSIGTYPE gotsigalrm(sig)
111 int sig;
112 {
113     signal(sig, gotsigalrm);
114     lastsig = sig;
115     alarm_latch = TRUE;
116 }
117 #endif /* SLEEP_WITH_ALARM */
118
119 RETSIGTYPE donothing(int sig) {signal(sig, donothing); lastsig = sig;}
120
121 #ifdef HAVE_ON_EXIT
122 static void unlockit(int n, void *p)
123 #else
124 static void unlockit(void)
125 #endif
126 /* must-do actions for exit (but we can't count on being able to do malloc) */
127 {
128     if (lockfile && lock_acquired)
129         unlink(lockfile);
130 }
131
132 #ifdef __EMX__
133 /* Various EMX-specific definitions */
134 int itimerflag;
135 void itimerthread(void* dummy) {
136   if (outlevel >= O_VERBOSE)
137     report(stderr, _("fetchmail: thread sleeping for %d sec.\n"), poll_interval);
138   while(1) {
139     _sleep2(poll_interval*1000);
140     kill((getpid()), SIGALRM);
141   }
142 }
143 #endif
144
145 #ifdef __FreeBSD__
146 /* drop SGID kmem privileage until we need it */
147 static void dropprivs(void)
148 {
149     struct group *gr;
150     gid_t        egid;
151     gid_t        rgid;
152     
153     egid = getegid();
154     rgid = getgid();
155     gr = getgrgid(egid);
156     
157     if (gr && !strcmp(gr->gr_name, "kmem"))
158     {
159         extern void interface_set_gids(gid_t egid, gid_t rgid);
160         interface_set_gids(egid, rgid);
161         setegid(rgid);
162     }
163 }
164 #endif
165
166 int main(int argc, char **argv)
167 {
168     int st, bkgd = FALSE;
169     int parsestatus, implicitmode = FALSE;
170     FILE        *lockfp;
171     struct query *ctl;
172     netrc_entry *netrc_list;
173     char *netrc_file, *tmpbuf;
174     pid_t pid;
175
176 #ifdef __FreeBSD__
177     dropprivs();
178 #endif
179
180     envquery(argc, argv);
181 #ifdef ENABLE_NLS
182     bindtextdomain(PACKAGE, LOCALEDIR);
183     textdomain(PACKAGE);
184 #endif
185
186     /*
187      * Note: because we can't initialize reporting before we  know whether
188      * syslog is supposed to be on, this message will go to stdout and
189      * be lost when running in background.
190      */
191     if (outlevel >= O_VERBOSE)
192     {
193         int i;
194
195         report(stdout, "fetchmail: invoked with");
196         for (i = 0; i < argc; i++)
197             report(stdout, " %s", argv[i]);
198         report(stdout, "\n");
199     }
200
201 #define IDFILE_NAME     ".fetchids"
202     run.idfile = (char *) xmalloc(strlen(home)+sizeof(IDFILE_NAME)+1);
203     strcpy(run.idfile, home);
204     strcat(run.idfile, "/");
205     strcat(run.idfile, IDFILE_NAME);
206   
207     outlevel = O_NORMAL;
208
209     /*
210      * We used to arrange for the lockfile to be removed on exit close
211      * to where the lock was asserted.  Now we need to do it here, because
212      * we might have re-executed in background with an existing lockfile
213      * as the result of a changed rcfile (see the code near the execvp(3)
214      * call near the beginning of the polling loop for details).  We want
215      * to be sure the lockfile gets nuked on any error exit, basically.
216      */
217 #ifdef HAVE_ATEXIT
218     atexit(unlockit);
219 #endif
220 #ifdef HAVE_ON_EXIT
221     on_exit(unlockit, (char *)NULL);
222 #endif
223
224     if ((parsestatus = parsecmdline(argc,argv, &cmd_run, &cmd_opts)) < 0)
225         exit(PS_SYNTAX);
226
227     if (versioninfo)
228     {
229         printf(_("This is fetchmail release %s"), VERSION);
230 #ifdef POP2_ENABLE
231         printf("+POP2");
232 #endif /* POP2_ENABLE */
233 #ifndef POP3_ENABLE
234         printf("-POP3");
235 #endif /* POP3_ENABLE */
236 #ifndef IMAP_ENABLE
237         printf("-IMAP");
238 #endif /* IMAP_ENABLE */
239 #ifdef GSSAPI
240         printf("+IMAP-GSS");
241 #endif /* GSSAPI */
242 #ifdef RPA_ENABLE
243         printf("+RPA");
244 #endif /* RPA_ENABLE */
245 #ifdef NTLM_ENABLE
246         printf("+NTLM");
247 #endif /* NTLM_ENABLE */
248 #ifdef SDPS_ENABLE
249         printf("+SDPS");
250 #endif /* SDPS_ENABLE */
251 #ifndef ETRN_ENABLE
252         printf("-ETRN");
253 #endif /* ETRN_ENABLE */
254 #ifdef SSL_ENABLE
255         printf("+SSL");
256 #endif
257 #if OPIE_ENABLE
258         printf("+OPIE");
259 #endif /* OPIE_ENABLE */
260 #if INET6_ENABLE
261         printf("+INET6");
262 #endif /* INET6_ENABLE */
263 #if NET_SECURITY
264         printf("+NETSEC");
265 #endif /* NET_SECURITY */
266 #ifdef HAVE_SOCKS
267         printf("+SOCKS");
268 #endif /* HAVE_SOCKS */
269 #if ENABLE_NLS
270         printf("+NLS");
271 #endif /* ENABLE_NLS */
272         putchar('\n');
273         fflush(stdout);
274
275         /* this is an attempt to help remote debugging */
276         system("uname -a");
277     }
278
279     /* avoid parsing the config file if all we're doing is killing a daemon */ 
280     if (!(quitmode && argc == 2))
281         implicitmode = load_params(argc, argv, optind);
282
283 #if defined(HAVE_SYSLOG)
284     /* logging should be set up early in case we were restarted from exec */
285     if (run.use_syslog)
286     {
287         openlog(program_name, LOG_PID, LOG_MAIL);
288         report_init(-1);
289     }
290     else
291 #endif
292         report_init((run.poll_interval == 0 || nodetach) && !run.logfile);
293
294     /* set up to do lock protocol */
295 #define FETCHMAIL_PIDFILE       "fetchmail.pid"
296     if (!getuid()) {
297         xalloca(tmpbuf, char *,
298                 sizeof(PID_DIR) + sizeof(FETCHMAIL_PIDFILE));
299         sprintf(tmpbuf, "%s/%s", PID_DIR, FETCHMAIL_PIDFILE);
300     } else {
301         xalloca(tmpbuf, char *, strlen(home) + sizeof(FETCHMAIL_PIDFILE) + 2);
302         strcpy(tmpbuf, home);
303         strcat(tmpbuf, "/.");
304         strcat(tmpbuf, FETCHMAIL_PIDFILE);
305     }
306 #undef FETCHMAIL_PIDFILE
307
308 #ifdef HAVE_SETRLIMIT
309     /*
310      * Before getting passwords, disable core dumps unless -v -d0 mode is on.
311      * Core dumps could otherwise contain passwords to be scavenged by a
312      * cracker.
313      */
314     if (outlevel < O_VERBOSE || run.poll_interval > 0)
315     {
316         struct rlimit corelimit;
317         corelimit.rlim_cur = 0;
318         corelimit.rlim_max = 0;
319         setrlimit(RLIMIT_CORE, &corelimit);
320     }
321 #endif /* HAVE_SETRLIMIT */
322
323 #define NETRC_FILE      ".netrc"
324     /* parse the ~/.netrc file (if present) for future password lookups. */
325     xalloca(netrc_file, char *, strlen (home) + sizeof(NETRC_FILE) + 1);
326     strcpy (netrc_file, home);
327     strcat (netrc_file, "/");
328     strcat (netrc_file, NETRC_FILE);
329     netrc_list = parse_netrc(netrc_file);
330 #undef NETRC_FILE
331
332     /* pick up passwords where we can */ 
333     for (ctl = querylist; ctl; ctl = ctl->next)
334     {
335         if (ctl->active && !(implicitmode && ctl->server.skip)&&!ctl->password)
336         {
337             if (ctl->server.preauthenticate == A_KERBEROS_V4 ||
338                         ctl->server.preauthenticate == A_KERBEROS_V5 ||
339                         ctl->server.preauthenticate == A_SSH ||
340 #ifdef GSSAPI
341                         ctl->server.protocol == P_IMAP_GSS ||
342 #endif /* GSSAPI */
343                         ctl->server.protocol == P_IMAP_K4)
344                 /* Server won't care what the password is, but there
345                    must be some non-null string here.  */
346                 ctl->password = ctl->remotename;
347             else
348             {
349                 netrc_entry *p;
350
351                 /* look up the pollname and account in the .netrc file. */
352                 p = search_netrc(netrc_list,
353                                  ctl->server.pollname, ctl->remotename);
354                 /* if we find a matching entry with a password, use it */
355                 if (p && p->password)
356                     ctl->password = xstrdup(p->password);
357
358                 /* otherwise try with "via" name if there is one */
359                 else if (ctl->server.via)
360                 {
361                     p = search_netrc(netrc_list, 
362                                      ctl->server.via, ctl->remotename);
363                     if (p && p->password)
364                         ctl->password = xstrdup(p->password);
365                 }
366             }
367         }
368     }
369
370     /* perhaps we just want to check options? */
371     if (versioninfo)
372     {
373         int havercfile = access(rcfile, 0);
374
375         printf(_("Taking options from command line%s%s\n"),
376                                 havercfile ? "" :  _(" and "),
377                                 havercfile ? "" : rcfile);
378
379         if (outlevel >= O_VERBOSE)
380             printf(_("Lockfile at %s\n"), tmpbuf);
381
382         if (querylist == NULL)
383             fprintf(stderr,
384                     _("No mailservers set up -- perhaps %s is missing?\n"),
385                     rcfile);
386         else
387             dump_params(&run, querylist, implicitmode);
388         exit(0);
389     }
390
391     /* dump options as a Python dictionary, for configurator use */
392     if (configdump)
393     {
394         dump_config(&run, querylist);
395         exit(0);
396     }
397
398     /* check for another fetchmail running concurrently */
399     pid = -1;
400     if ((lockfile = (char *) malloc(strlen(tmpbuf) + 1)) == NULL)
401     {
402         report(stderr,_("fetchmail: cannot allocate memory for lock name.\n"));
403         exit(PS_EXCLUDE);
404     }
405     else
406         (void) strcpy(lockfile, tmpbuf);
407     if ((lockfp = fopen(lockfile, "r")) != NULL )
408     {
409         bkgd = (fscanf(lockfp,"%d %d", &pid, &st) == 2);
410
411         if (kill(pid, 0) == -1) {
412             fprintf(stderr,_("fetchmail: removing stale lockfile\n"));
413             pid = -1;
414             bkgd = FALSE;
415             unlink(lockfile);
416         }
417         fclose(lockfp); /* not checking should be safe, file mode was "r" */
418     }
419
420     /* if no mail servers listed and nothing in background, we're done */
421     if (!(quitmode && argc == 2) && pid == -1 && querylist == NULL) {
422         (void)fputs(_("fetchmail: no mailservers have been specified.\n"),stderr);
423         exit(PS_SYNTAX);
424     }
425
426     /* perhaps user asked us to kill the other fetchmail */
427     if (quitmode)
428     {
429         if (pid == -1) 
430         {
431             fprintf(stderr,_("fetchmail: no other fetchmail is running\n"));
432             if (argc == 2)
433                 exit(PS_EXCLUDE);
434         }
435         else if (kill(pid, SIGTERM) < 0)
436         {
437             fprintf(stderr,_("fetchmail: error killing %s fetchmail at %d; bailing out.\n"),
438                     bkgd ? _("background") : _("foreground"), pid);
439             exit(PS_EXCLUDE);
440         }
441         else
442         {
443             fprintf(stderr,_("fetchmail: %s fetchmail at %d killed.\n"),
444                     bkgd ? _("background") : _("foreground"), pid);
445             unlink(lockfile);
446             if (argc == 2)
447                 exit(0);
448             else
449                 pid = -1; 
450         }
451     }
452
453     /* another fetchmail is running -- wake it up or die */
454     if (pid != -1)
455     {
456         if (check_only)
457         {
458             fprintf(stderr,
459                  _("fetchmail: can't check mail while another fetchmail to same host is running.\n"));
460             return(PS_EXCLUDE);
461         }
462         else if (!implicitmode)
463         {
464             fprintf(stderr,
465                  _("fetchmail: can't poll specified hosts with another fetchmail running at %d.\n"),
466                  pid);
467                 return(PS_EXCLUDE);
468         }
469         else if (!bkgd)
470         {
471             fprintf(stderr,
472                  _("fetchmail: another foreground fetchmail is running at %d.\n"),
473                  pid);
474                 return(PS_EXCLUDE);
475         }
476         else if (argc > 1)
477         {
478             /* this test enables re-execing on a changed rcfile */
479             if (getpid() == pid)
480                 lock_acquired = TRUE;
481             else
482             {
483                 fprintf(stderr,
484                         _("fetchmail: can't accept options while a background fetchmail is running.\n"));
485                 return(PS_EXCLUDE);
486             }
487         }
488         else if (kill(pid, SIGUSR1) == 0)
489         {
490             fprintf(stderr,
491                     _("fetchmail: background fetchmail at %d awakened.\n"),
492                     pid);
493             return(0);
494         }
495         else
496         {
497             /*
498              * Should never happen -- possible only if a background fetchmail
499              * croaks after the first kill probe above but before the
500              * SIGUSR1/SIGHUP transmission.
501              */
502             fprintf(stderr,
503                     _("fetchmail: elder sibling at %d died mysteriously.\n"),
504                     pid);
505             return(PS_UNDEFINED);
506         }
507     }
508
509     /* pick up interactively any passwords we need but don't have */ 
510     for (ctl = querylist; ctl; ctl = ctl->next)
511     {
512         if (ctl->active && !(implicitmode && ctl->server.skip)
513             && ctl->server.protocol != P_ETRN 
514             && ctl->server.protocol != P_IMAP_K4
515 #ifdef GSSAPI
516             && ctl->server.protocol != P_IMAP_GSS
517 #endif /* GSSAPI */
518             && !ctl->password)
519         {
520             char* password_prompt = _("Enter password for %s@%s: ");
521
522             xalloca(tmpbuf, char *, strlen(password_prompt) +
523                     strlen(ctl->remotename) +
524                     strlen(ctl->server.pollname) + 1);
525             (void) sprintf(tmpbuf, password_prompt,
526                            ctl->remotename, ctl->server.pollname);
527             ctl->password = xstrdup((char *)getpassword(tmpbuf));
528         }
529     }
530
531     /*
532      * Time to initiate the SOCKS library (this is not mandatory: it just
533      * registers the correct application name for logging purpose. If you
534      * have some problem, comment out these lines).
535      */
536 #ifdef HAVE_SOCKS
537     SOCKSinit("fetchmail");
538 #endif /* HAVE_SOCKS */
539
540     /*
541      * Maybe time to go to demon mode...
542      */
543     if (run.poll_interval)
544     {
545         if (!nodetach)
546             daemonize(run.logfile, terminate_run);
547         report(stdout, _("starting fetchmail %s daemon \n"), VERSION);
548
549         /*
550          * We'll set up a handler for these when we're sleeping,
551          * but ignore them otherwise so as not to interrupt a poll.
552          */
553         signal(SIGUSR1, SIG_IGN);
554         if (run.poll_interval && !getuid())
555             signal(SIGHUP, SIG_IGN);
556     }
557     else if (run.logfile && access(run.logfile, F_OK) == 0)
558     {
559         freopen(run.logfile, "a", stdout);
560         freopen(run.logfile, "a", stderr);
561     }
562
563
564 #ifdef linux
565     interface_init();
566 #endif /* linux */
567
568     /* beyond here we don't want more than one fetchmail running per user */
569     umask(0077);
570     signal(SIGABRT, terminate_run);
571     signal(SIGINT, terminate_run);
572     signal(SIGTERM, terminate_run);
573     signal(SIGALRM, terminate_run);
574     signal(SIGPIPE, terminate_run);
575     signal(SIGQUIT, terminate_run);
576
577     /* here's the exclusion lock */
578 #ifndef O_SYNC
579 #define O_SYNC  0       /* use it if we have it */
580 #endif
581     if ((st = open(lockfile, O_WRONLY|O_CREAT|O_EXCL|O_SYNC, 0666)) != -1)
582     {
583         sprintf(tmpbuf,"%d", getpid());
584         write(st, tmpbuf, strlen(tmpbuf));
585         if (run.poll_interval)
586         {
587             sprintf(tmpbuf," %d", run.poll_interval);
588             write(st, tmpbuf, strlen(tmpbuf));
589         }
590         close(st);      /* should be safe, fd was opened with O_SYNC */
591         lock_acquired = TRUE;
592     }
593
594     /*
595      * Query all hosts. If there's only one, the error return will
596      * reflect the status of that transaction.
597      */
598     do {
599         /* 
600          * Check to see if the rcfile has been touched.  If so,
601          * re-exec so the file will be reread.  Doing it this way
602          * avoids all the complications of trying to deallocate the
603          * in-core control structures -- and the potential memory
604          * leaks...
605          */
606         struct stat     rcstat;
607
608         if (stat(rcfile, &rcstat) == -1)
609         {
610             if (errno != ENOENT)
611                 report(stderr, 
612                        _("couldn't time-check %s (error %d)\n"),
613                        rcfile, errno);
614         }
615         else if (rcstat.st_mtime > parsetime)
616         {
617             report(stdout, _("restarting fetchmail (%s changed)\n"), rcfile);
618             execvp("fetchmail", argv);
619             report(stderr, _("attempt to re-exec fetchmail failed\n"));
620         }
621
622 #if defined(HAVE_RES_SEARCH) && defined(USE_TCPIP_FOR_DNS)
623         /*
624          * This was an efficiency hack that backfired.  The theory
625          * was that using TCP/IP for DNS queries would get us better
626          * reliability and shave off some per-UDP-packet costs.
627          * Unfortunately it interacted badly with diald, which effectively 
628          * filters out DNS queries over TCP/IP for reasons having to do
629          * with some obscure kernel problem involving bootstrapping of
630          * dynamically-addressed links.  I don't understand this mess
631          * and don't want to, so it's "See ya!" to this hack.
632          */
633         sethostent(TRUE);       /* use TCP/IP for mailserver queries */
634 #endif /* HAVE_RES_SEARCH */
635
636         batchcount = 0;
637         for (ctl = querylist; ctl; ctl = ctl->next)
638         {
639             if (ctl->active && !(implicitmode && ctl->server.skip))
640             {
641                 if (ctl->wedged)
642                 {
643                     report(stderr, 
644                           _("poll of %s skipped (failed authentication or too many timeouts)\n"),
645                           ctl->server.pollname);
646                     continue;
647                 }
648
649                 /* check skip interval first so that it counts all polls */
650                 if (run.poll_interval && ctl->server.interval) 
651                 {
652                     if (ctl->server.poll_count++ % ctl->server.interval) 
653                     {
654                         if (outlevel >= O_VERBOSE)
655                             report(stdout,
656                                     _("interval not reached, not querying %s\n"),
657                                     ctl->server.pollname);
658                         continue;
659                     }
660                 }
661
662 #if (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__)
663                 /* interface_approve() does its own error logging */
664                 if (!interface_approve(&ctl->server))
665                     continue;
666 #endif /* (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__) */
667
668                 querystatus = query_host(ctl);
669
670 #ifdef POP3_ENABLE
671                 if (!check_only)
672                     uid_end_query(ctl);
673 #endif  /* POP3_ENABLE */
674
675                 if (querystatus == PS_SUCCESS)
676                     successes++;
677                 else if (!check_only && 
678                          ((querystatus!=PS_NOMAIL) || (outlevel==O_DEBUG)))
679                 switch(querystatus)
680                 {
681                 case PS_SUCCESS:
682                     report(stdout, "Query status=SUCCESS\n"); break ;
683                 case PS_NOMAIL: 
684                     report(stdout, "Query status=NOMAIL\n"); break ;
685                 case PS_SOCKET:
686                     report(stdout, "Query status=SOCKET\n"); break ;
687                 case PS_AUTHFAIL:
688                     report(stdout, "Query status=AUTHFAIL\n"); break ;
689                 case PS_PROTOCOL:
690                     report(stdout, "Query status=PROTOCOL\n"); break ;
691                 case PS_SYNTAX:
692                     report(stdout, "Query status=SYNTAX\n"); break ;
693                 case PS_IOERR:
694                     report(stdout, "Query status=IOERR\n"); break ;
695                 case PS_ERROR:
696                     report(stdout, "Query status=ERROR\n"); break ;
697                 case PS_EXCLUDE:
698                     report(stdout, "Query status=EXCLUDE\n"); break ;
699                 case PS_LOCKBUSY:
700                     report(stdout, "Query status=LOCKBUSY\n"); break ;
701                 case PS_SMTP:
702                     report(stdout, "Query status=SMTP\n"); break ;
703                 case PS_DNS:
704                     report(stdout, "Query status=DNS\n"); break ;
705                 case PS_BSMTP:
706                     report(stdout, "Query status=BSMTP\n"); break ;
707                 case PS_MAXFETCH:
708                     report(stdout, "Query status=MAXFETCH\n"); break ;
709                 case PS_UNDEFINED:
710                     report(stdout, "Query status=UNDEFINED\n"); break ;
711                 case PS_TRANSIENT:
712                     report(stdout, "Query status=TRANSIENT\n"); break ;
713                 case PS_REFUSED:
714                     report(stdout, "Query status=REFUSED\n"); break ;
715                 case PS_RETAINED:
716                     report(stdout, "Query status=RETAINED\n"); break ;
717                 case PS_TRUNCATED:
718                     report(stdout, "Query status=TRUNCATED\n"); break ;
719                 default:
720                     report(stdout, _("Query status=%d\n"), querystatus); break;
721                 }
722
723 #if (defined(linux) && !INET6_ENABLE) || defined (__FreeBSD__)
724                 if (ctl->server.monitor)
725                 {
726                     /*
727                      * Allow some time for the link to quiesce.  One
728                      * second is usually sufficient, three is safe.
729                      * Note:  this delay is important - don't remove!
730                      */
731                     sleep(3);
732                     interface_note_activity(&ctl->server);
733                 }
734 #endif /* (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__) */
735             }
736         }
737
738 #if defined(HAVE_RES_SEARCH) && defined(USE_TCPIP_FOR_DNS)
739         endhostent();           /* release TCP/IP connection to nameserver */
740 #endif /* HAVE_RES_SEARCH */
741
742         /* close connections cleanly */
743         terminate_poll(0);
744
745         /*
746          * OK, we've polled.  Now sleep.
747          */
748         if (run.poll_interval)
749         {
750             /* 
751              * Because passwords can expire, it may happen that *all*
752              * hosts are now out of the loop due to authfail
753              * conditions.  If this happens daemon-mode fetchmail
754              * should softly and silently vanish away, rather than
755              * spinning uselessly.
756              */
757             int unwedged = 0;
758
759             for (ctl = querylist; ctl; ctl = ctl->next)
760                 if (ctl->active && !(implicitmode && ctl->server.skip))
761                     if (!ctl->wedged)
762                         unwedged++;
763             if (!unwedged)
764             {
765                 report(stderr, _("All connections are wedged.  Exiting.\n"));
766                 /* FIXME: someday, send notification mail */
767                 exit(PS_AUTHFAIL);
768             }
769
770             if (outlevel >= O_VERBOSE)
771                 report(stdout, 
772                        _("fetchmail: sleeping at %s\n"), rfc822timestamp());
773
774             /*
775              * With this simple hack, we make it possible for a foreground 
776              * fetchmail to wake up one in daemon mode.  What we want is the
777              * side effect of interrupting any sleep that may be going on,
778              * forcing fetchmail to re-poll its hosts.  The second line is
779              * for people who think all system daemons wake up on SIGHUP.
780              */
781             signal(SIGUSR1, donothing);
782             if (!getuid())
783                 signal(SIGHUP, donothing);
784
785             /* time for a pause in the action... */
786             {
787 #ifndef __EMX__
788 #ifdef SLEEP_WITH_ALARM         /* not normally on */
789                 /*
790                  * We can't use sleep(3) here because we need an alarm(3)
791                  * equivalent in order to implement server nonresponse timeout.
792                  * We'll just assume setitimer(2) is available since fetchmail
793                  * has to have a BSDoid socket layer to work at all.
794                  */
795                 /* 
796                  * This code stopped working under glibc-2, apparently due
797                  * to the change in signal(2) semantics.  (The siginterrupt
798                  * line, added later, should fix this problem.) John Stracke
799                  * <francis@netscape.com> wrote:
800                  *
801                  * The problem seems to be that, after hitting the interval
802                  * timer while talking to the server, the process no longer
803                  * responds to SIGALRM.  I put in printf()s to see when it
804                  * reached the pause() for the poll interval, and I checked
805                  * the return from setitimer(), and everything seemed to be
806                  * working fine, except that the pause() just ignored SIGALRM.
807                  * I thought maybe the itimer wasn't being fired, so I hit
808                  * it with a SIGALRM from the command line, and it ignored
809                  * that, too.  SIGUSR1 woke it up just fine, and it proceeded
810                  * to repoll--but, when the dummy server didn't respond, it
811                  * never timed out, and SIGALRM wouldn't make it.
812                  *
813                  * (continued below...)
814                  */
815                 struct itimerval ntimeout;
816
817                 ntimeout.it_interval.tv_sec = 5; /* repeat alarm every 5 secs */
818                 ntimeout.it_interval.tv_usec = 0;
819                 ntimeout.it_value.tv_sec  = run.poll_interval;
820                 ntimeout.it_value.tv_usec = 0;
821
822                 siginterrupt(SIGALRM, 1);
823                 alarm_latch = FALSE;
824                 signal(SIGALRM, gotsigalrm);    /* first trap signals */
825                 setitimer(ITIMER_REAL,&ntimeout,NULL);  /* then start timer */
826                 /* there is a very small window between the next two lines */
827                 /* which could result in a deadlock.  But this will now be  */
828                 /* caught by periodical alarms (see it_interval) */
829                 if (!alarm_latch)
830                     pause();
831                 /* stop timer */
832                 ntimeout.it_interval.tv_sec = ntimeout.it_interval.tv_usec = 0;
833                 ntimeout.it_value.tv_sec  = ntimeout.it_value.tv_usec = 0;
834                 setitimer(ITIMER_REAL,&ntimeout,NULL);  /* now stop timer */
835                 signal(SIGALRM, SIG_IGN);
836 #else
837                 /* 
838                  * So the workaround I used is to make it sleep by using
839                  * select() instead of setitimer()/pause().  select() is
840                  * perfectly happy being called with a timeout and
841                  * no file descriptors; it just sleeps until it hits the
842                  * timeout.  The only concern I had was that it might
843                  * implement its timeout with SIGALRM--there are some
844                  * Unices where this is done, because select() is a library
845                  * function--but apparently not.
846                  */
847                 struct timeval timeout;
848
849                 timeout.tv_sec = run.poll_interval;
850                 timeout.tv_usec = 0;
851                 do {
852                     lastsig = 0;
853                     select(0,0,0,0, &timeout);
854                 } while (lastsig == SIGCHLD);
855 #endif
856 #else /* EMX */
857                 alarm_latch = FALSE;
858                 signal(SIGALRM, gotsigalrm);
859                 _beginthread(itimerthread, NULL, 32768, NULL);
860                 /* see similar code above */
861                 if (!alarm_latch)
862                     pause();
863                 signal(SIGALRM, SIG_IGN);
864 #endif /* ! EMX */
865                 if (lastsig == SIGUSR1
866                         || ((run.poll_interval && !getuid()) && lastsig == SIGHUP))
867                 {
868 #ifdef SYS_SIGLIST_DECLARED
869                     report(stdout, 
870                            _("awakened by %s\n"), sys_siglist[lastsig]);
871 #else
872                     report(stdout, 
873                            _("awakened by signal %d\n"), lastsig);
874 #endif
875                     /* received a wakeup - unwedge all servers in case */
876                     /* the problem has been manually repaired          */
877                     for (ctl = querylist; ctl; ctl = ctl->next)
878                         ctl->wedged = FALSE;
879                 }
880             }
881
882             /* now lock out interrupts again */
883             signal(SIGUSR1, SIG_IGN);
884             if (!getuid())
885                 signal(SIGHUP, SIG_IGN);
886
887             if (outlevel >= O_VERBOSE)
888                 report(stdout, _("awakened at %s\n"), rfc822timestamp());
889         }
890     } while
891         (run.poll_interval);
892
893     if (outlevel >= O_VERBOSE)
894         report(stdout, _("normal termination, status %d\n"),
895                 successes ? PS_SUCCESS : querystatus);
896
897     terminate_run(0);
898     exit(successes ? PS_SUCCESS : querystatus);
899 }
900
901 static void optmerge(struct query *h2, struct query *h1, int force)
902 /* merge two options records */
903 {
904     /*
905      * If force is off, modify h2 fields only when they're empty (treat h1
906      * as defaults).  If force is on, modify each h2 field whenever h1
907      * is nonempty (treat h1 as an override).  
908      */
909 #define LIST_MERGE(dstl, srcl) if (force ? !!srcl : !dstl) \
910                                                 free_str_list(&dstl), \
911                                                 append_str_list(&dstl, &srcl)
912     LIST_MERGE(h2->server.localdomains, h1->server.localdomains);
913     LIST_MERGE(h2->localnames, h1->localnames);
914     LIST_MERGE(h2->mailboxes, h1->mailboxes);
915     LIST_MERGE(h2->smtphunt, h1->smtphunt);
916     LIST_MERGE(h2->antispam, h1->antispam);
917 #undef LIST_MERGE
918
919 #define FLAG_MERGE(fld) if (force ? !!h1->fld : !h2->fld) h2->fld = h1->fld
920     FLAG_MERGE(server.via);
921     FLAG_MERGE(server.protocol);
922 #if INET6_ENABLE
923     FLAG_MERGE(server.service);
924     FLAG_MERGE(server.netsec);
925 #else /* INET6_ENABLE */
926     FLAG_MERGE(server.port);
927 #endif /* INET6_ENABLE */
928     FLAG_MERGE(server.interval);
929     FLAG_MERGE(server.preauthenticate);
930     FLAG_MERGE(server.timeout);
931     FLAG_MERGE(server.envelope);
932     FLAG_MERGE(server.envskip);
933     FLAG_MERGE(server.qvirtual);
934     FLAG_MERGE(server.skip);
935     FLAG_MERGE(server.dns);
936     FLAG_MERGE(server.checkalias);
937     FLAG_MERGE(server.uidl);
938
939 #if defined(linux) || defined(__FreeBSD__)
940     FLAG_MERGE(server.interface);
941     FLAG_MERGE(server.monitor);
942     FLAG_MERGE(server.interface_pair);
943 #endif /* linux || defined(__FreeBSD__) */
944
945     FLAG_MERGE(server.plugin);
946     FLAG_MERGE(server.plugout);
947
948     FLAG_MERGE(wildcard);
949     FLAG_MERGE(remotename);
950     FLAG_MERGE(password);
951     FLAG_MERGE(mda);
952     FLAG_MERGE(bsmtp);
953     FLAG_MERGE(listener);
954     FLAG_MERGE(smtpaddress);
955     FLAG_MERGE(preconnect);
956     FLAG_MERGE(postconnect);
957
958     FLAG_MERGE(keep);
959     FLAG_MERGE(flush);
960     FLAG_MERGE(fetchall);
961     FLAG_MERGE(rewrite);
962     FLAG_MERGE(forcecr);
963     FLAG_MERGE(stripcr);
964     FLAG_MERGE(pass8bits);
965     FLAG_MERGE(dropstatus);
966     FLAG_MERGE(mimedecode);
967     FLAG_MERGE(limit);
968     FLAG_MERGE(warnings);
969     FLAG_MERGE(fetchlimit);
970     FLAG_MERGE(batchlimit);
971 #ifdef  SSL_ENABLE
972     FLAG_MERGE(use_ssl);
973     FLAG_MERGE(sslkey);
974     FLAG_MERGE(sslcert);
975 #endif
976     FLAG_MERGE(expunge);
977
978     FLAG_MERGE(properties);
979 #undef FLAG_MERGE
980 }
981
982 static int load_params(int argc, char **argv, int optind)
983 {
984     int implicitmode, st;
985     struct passwd *pw;
986     struct query def_opts, *ctl;
987     struct stat rcstat;
988
989     run.bouncemail = TRUE;
990
991     memset(&def_opts, '\0', sizeof(struct query));
992     def_opts.smtp_socket = -1;
993     def_opts.smtpaddress = (char *)0;
994 #define ANTISPAM(n)     save_str(&def_opts.antispam, STRING_DUMMY, 0)->val.status.num = (n)
995     ANTISPAM(571);      /* sendmail */
996     ANTISPAM(550);      /* old exim */
997     ANTISPAM(501);      /* new exim */
998     ANTISPAM(554);      /* Postfix */
999 #undef ANTISPAM
1000
1001     def_opts.server.protocol = P_AUTO;
1002     def_opts.server.timeout = CLIENT_TIMEOUT;
1003     def_opts.warnings = WARNING_INTERVAL;
1004     def_opts.remotename = user;
1005     def_opts.listener = SMTP_MODE;
1006
1007     /* note the parse time, so we can pick up on modifications */
1008     parsetime = 0;      /* foil compiler warnings */
1009     if (stat(rcfile, &rcstat) != -1)
1010         parsetime = rcstat.st_mtime;
1011     else if (errno != ENOENT)
1012         report(stderr, _("couldn't time-check the run-control file\n"));
1013
1014     /* this builds the host list */
1015     if ((st = prc_parse_file(rcfile, !versioninfo)) != 0)
1016         /*
1017          * FIXME: someday, send notification mail here if backgrounded.
1018          * Right now, that can happen if the user changes the rcfile
1019          * while the fetchmail is running in background.  Do similarly
1020          * for the other exit() calls in this function.
1021          */
1022         exit(st);
1023
1024     if ((implicitmode = (optind >= argc)))
1025     {
1026         for (ctl = querylist; ctl; ctl = ctl->next)
1027             ctl->active = TRUE;
1028     }
1029     else
1030         for (; optind < argc; optind++) 
1031         {
1032             flag        predeclared =  FALSE;
1033
1034             /*
1035              * If hostname corresponds to a host known from the rc file,
1036              * simply declare it active.  Otherwise synthesize a host
1037              * record from command line and defaults
1038              */
1039             for (ctl = querylist; ctl; ctl = ctl->next)
1040                 if (!strcmp(ctl->server.pollname, argv[optind])
1041                         || str_in_list(&ctl->server.akalist, argv[optind], TRUE))
1042                 {
1043                     /* Is this correct? */
1044                     if(predeclared)
1045                         fprintf(stderr,_("Warning: multiple mentions of host %s in config file\n"),argv[optind]);
1046                     ctl->active = TRUE;
1047                     predeclared = TRUE;
1048                 }
1049
1050             if (!predeclared)
1051             {
1052                 /*
1053                  * Allocate and link record without copying in
1054                  * command-line args; we'll do that with the optmerge
1055                  * call later on.
1056                  */
1057                 ctl = hostalloc((struct query *)NULL);
1058                 ctl->server.via =
1059                     ctl->server.pollname = xstrdup(argv[optind]);
1060                 ctl->active = TRUE;
1061                 ctl->server.lead_server = (struct hostdata *)NULL;
1062             }
1063         }
1064
1065     /*
1066      * If there's a defaults record, merge it and lose it.
1067      */ 
1068     if (querylist && strcmp(querylist->server.pollname, "defaults") == 0)
1069     {
1070         for (ctl = querylist->next; ctl; ctl = ctl->next)
1071             optmerge(ctl, querylist, FALSE);
1072         querylist = querylist->next;
1073     }
1074
1075     /* don't allow a defaults record after the first */
1076     for (ctl = querylist; ctl; ctl = ctl->next)
1077         if (ctl != querylist && strcmp(ctl->server.pollname, "defaults") == 0)
1078             exit(PS_SYNTAX);
1079
1080     /* use localhost if we never fetch the FQDN of this host */
1081     fetchmailhost = "localhost";
1082
1083     /* here's where we override globals */
1084     if (cmd_run.logfile)
1085         run.logfile = cmd_run.logfile;
1086     if (cmd_run.idfile)
1087         run.idfile = cmd_run.idfile;
1088     /* do this before the keep/fetchall test below, otherwise -d0 may fail */
1089     if (cmd_run.poll_interval >= 0)
1090         run.poll_interval = cmd_run.poll_interval;
1091     if (cmd_run.invisible)
1092         run.invisible = cmd_run.invisible;
1093     if (cmd_run.use_syslog)
1094         run.use_syslog = (cmd_run.use_syslog == FLAG_TRUE);
1095     if (cmd_run.postmaster)
1096         run.postmaster = cmd_run.postmaster;
1097     if (cmd_run.bouncemail)
1098         run.bouncemail = cmd_run.bouncemail;
1099
1100     /* check and daemon options are not compatible */
1101     if (check_only && run.poll_interval)
1102         run.poll_interval = 0;
1103
1104     /* merge in wired defaults, do sanity checks and prepare internal fields */
1105     for (ctl = querylist; ctl; ctl = ctl->next)
1106     {
1107         ctl->wedged = FALSE;
1108
1109         if (configdump || (ctl->active && !(implicitmode && ctl->server.skip)))
1110         {
1111             /* merge in defaults */
1112             optmerge(ctl, &def_opts, FALSE);
1113
1114             /* force command-line options */
1115             optmerge(ctl, &cmd_opts, TRUE);
1116
1117             /* this code enables flags to be turned off */
1118 #define DEFAULT(flag, dflt)     if (flag == FLAG_TRUE)\
1119                                         flag = TRUE;\
1120                                 else if (flag == FLAG_FALSE)\
1121                                         flag = FALSE;\
1122                                 else\
1123                                         flag = (dflt)
1124             DEFAULT(ctl->keep, FALSE);
1125             DEFAULT(ctl->fetchall, FALSE);
1126             DEFAULT(ctl->flush, FALSE);
1127             DEFAULT(ctl->rewrite, TRUE);
1128             DEFAULT(ctl->stripcr, (ctl->mda != (char *)NULL)); 
1129             DEFAULT(ctl->forcecr, FALSE);
1130             DEFAULT(ctl->pass8bits, FALSE);
1131             DEFAULT(ctl->dropstatus, FALSE);
1132             DEFAULT(ctl->mimedecode, FALSE);
1133             DEFAULT(ctl->server.dns, TRUE);
1134             DEFAULT(ctl->server.uidl, FALSE);
1135 #ifdef  SSL_ENABLE
1136             DEFAULT(ctl->use_ssl, FALSE);
1137 #endif
1138             DEFAULT(ctl->server.checkalias, FALSE);
1139 #undef DEFAULT
1140
1141             /*
1142              * DNS support is required for some protocols.  We used to
1143              * do this unconditionally, but it made fetchmail excessively
1144              * vulnerable to misconfigured DNS setups.
1145              *
1146              * If we're using ETRN, the smtp hunt list is the list of
1147              * systems we're polling on behalf of; these have to be 
1148              * fully-qualified domain names.  The default for this list
1149              * should be the FQDN of localhost.
1150              *
1151              * If we're using Kerberos for authentication, we need 
1152              * the FQDN in order to generate capability keys.
1153              */
1154             if (ctl->server.protocol == P_ETRN
1155                          || ctl->server.preauthenticate == A_KERBEROS_V4
1156                          || ctl->server.preauthenticate == A_KERBEROS_V5)
1157                 if (strcmp(fetchmailhost, "localhost") == 0)
1158                         fetchmailhost = host_fqdn();
1159
1160             /*
1161              * Make sure we have a nonempty host list to forward to.
1162              */
1163             if (!ctl->smtphunt)
1164                 save_str(&ctl->smtphunt, fetchmailhost, FALSE);
1165
1166             /* if `user' doesn't name a real local user, try to run as root */
1167             if ((pw = getpwnam(user)) == (struct passwd *)NULL)
1168                 ctl->uid = 0;
1169             else
1170                 ctl->uid = pw->pw_uid;  /* for local delivery via MDA */
1171             if (!ctl->localnames)       /* for local delivery via SMTP */
1172                 save_str_pair(&ctl->localnames, user, NULL);
1173
1174 #if !defined(HAVE_GETHOSTBYNAME) || !defined(HAVE_RES_SEARCH)
1175             /* can't handle multidrop mailboxes unless we can do DNS lookups */
1176             if (ctl->localnames && ctl->localnames->next && ctl->server.dns)
1177             {
1178                 ctl->server.dns = FALSE;
1179                 report(stderr, _("fetchmail: warning: no DNS available to check multidrop fetches from %s\n"), ctl->server.pollname);
1180             }
1181 #endif /* !HAVE_GETHOSTBYNAME || !HAVE_RES_SEARCH */
1182
1183             /*
1184              *
1185              * Compute the true name of the mailserver host.  
1186              * There are two clashing cases here:
1187              *
1188              * (1) The poll name is a label, possibly on one of several
1189              *     poll configurations for the same host.  In this case 
1190              *     the `via' option will be present and give the true name.
1191              *
1192              * (2) The poll name is the true one, the via name is 
1193              *     localhost.   This is going to be typical for ssh-using
1194              *     configurations.
1195              *
1196              * We're going to assume the via name is true unless it's
1197              * localhost.
1198              */
1199             if (ctl->server.via && strcmp(ctl->server.via, "localhost"))
1200                 ctl->server.queryname = xstrdup(ctl->server.via);
1201             else
1202                 ctl->server.queryname = xstrdup(ctl->server.pollname);
1203
1204 #ifdef HESIOD
1205         /* If either the pollname or vianame are "hesiod" we want to
1206            lookup the user's hesiod pobox host */
1207
1208         if (!strcasecmp(ctl->server.queryname, "hesiod")) {
1209             struct hes_postoffice *hes_p;
1210             hes_p = hes_getmailhost(ctl->remotename);
1211             if (hes_p != NULL && strcmp(hes_p->po_type, "POP") == 0) {
1212                  free(ctl->server.queryname);
1213                  ctl->server.queryname = xstrdup(hes_p->po_host);
1214                  if (ctl->server.via)
1215                      free(ctl->server.via);
1216                  ctl->server.via = xstrdup(hes_p->po_host);
1217             } else {
1218                  report(stderr,
1219                         _("couldn't find HESIOD pobox for %s\n"),
1220                         ctl->remotename);
1221             }
1222         }
1223 #endif /* HESIOD */
1224
1225             /*
1226              * We may have to canonicalize the server truename for later use.
1227              * Do this just once for each lead server, if necessary, in order
1228              * to minimize DNS round trips.
1229              */
1230             if (ctl->server.lead_server)
1231             {
1232                 char    *leadname = ctl->server.lead_server->truename;
1233
1234                 /* prevent core dump from ill-formed or duplicate entry */
1235                 if (!leadname)
1236                 {
1237                     report(stderr, 
1238                            _("Lead server has no name.\n"));
1239                     exit(PS_SYNTAX);
1240                 }
1241
1242                 ctl->server.truename = xstrdup(leadname);
1243             }
1244 #ifdef HAVE_GETHOSTBYNAME
1245             else if (ctl->server.preauthenticate==A_KERBEROS_V4 ||
1246                 ctl->server.preauthenticate==A_KERBEROS_V5 ||
1247                 (ctl->server.dns && MULTIDROP(ctl)))
1248             {
1249                 struct hostent  *namerec;
1250
1251                 /* compute the canonical name of the host */
1252                 errno = 0;
1253                 namerec = gethostbyname(ctl->server.queryname);
1254                 if (namerec == (struct hostent *)NULL)
1255                 {
1256                     report(stderr,
1257                           _("couldn't find canonical DNS name of %s\n"),
1258                           ctl->server.pollname);
1259                     exit(PS_DNS);
1260                 }
1261                 else
1262                     ctl->server.truename=xstrdup((char *)namerec->h_name);
1263             }
1264 #endif /* HAVE_GETHOSTBYNAME */
1265             else
1266                 ctl->server.truename = xstrdup(ctl->server.queryname);
1267
1268             /* if no folders were specified, set up the null one as default */
1269             if (!ctl->mailboxes)
1270                 save_str(&ctl->mailboxes, (char *)NULL, 0);
1271
1272             /* maybe user overrode timeout on command line? */
1273             if (ctl->server.timeout == -1)      
1274                 ctl->server.timeout = CLIENT_TIMEOUT;
1275
1276 #if !INET6_ENABLE
1277             /* sanity checks */
1278             if (ctl->server.port < 0)
1279             {
1280                 (void) fprintf(stderr,
1281                                _("%s configuration invalid, port number cannot be negative\n"),
1282                                ctl->server.pollname);
1283                 exit(PS_SYNTAX);
1284             }
1285             if (ctl->server.protocol == P_RPOP && ctl->server.port >= 1024)
1286             {
1287                 (void) fprintf(stderr,
1288                                _("%s configuration invalid, RPOP requires a privileged port\n"),
1289                                ctl->server.pollname);
1290                 exit(PS_SYNTAX);
1291             }
1292             if (ctl->listener == LMTP_MODE)
1293             {
1294                 struct idlist   *idp;
1295
1296                 for (idp = ctl->smtphunt; idp; idp = idp->next)
1297                 {
1298                     char        *cp;
1299
1300                     if (!(cp = strrchr(idp->id, '/')) ||
1301                                 (atoi(++cp) == SMTP_PORT))
1302                     {
1303                         (void) fprintf(stderr,
1304                                        _("%s configuration invalid, LMTP can't use default SMTP port\n"),
1305                                        ctl->server.pollname);
1306                         exit(PS_SYNTAX);
1307                     }
1308                 }
1309             }
1310 #endif /* !INET6_ENABLE */
1311
1312             /*
1313              * "I beg to you, have mercy on the week minds like myself."
1314              * wrote Pehr Anderson.  Your petition is granted.
1315              */
1316             if (ctl->fetchall && ctl->keep && run.poll_interval && !nodetach)
1317             {
1318                 (void) fprintf(stderr,
1319                                _("Both fetchall and keep on in daemon mode is a mistake!\n"));
1320                 exit(PS_SYNTAX);
1321             }
1322         }
1323     }
1324
1325 #ifdef POP3_ENABLE
1326     /* initialize UID handling */
1327     if (!versioninfo && (st = prc_filecheck(run.idfile, !versioninfo)) != 0)
1328         exit(st);
1329     else
1330         initialize_saved_lists(querylist, run.idfile);
1331 #endif /* POP3_ENABLE */
1332
1333     /*
1334      * If the user didn't set a last-resort user to get misaddressed
1335      * multidrop mail, set an appropriate default here.
1336      */
1337     if (!run.postmaster)
1338     {
1339         if (getuid())                           /* ordinary user */
1340             run.postmaster = user;
1341         else                                    /* root */
1342             run.postmaster = "postmaster";
1343     }
1344
1345     return(implicitmode);
1346 }
1347
1348 static void terminate_poll(int sig)
1349 /* to be executed at the end of a poll cycle */
1350 {
1351     /*
1352      * Close all SMTP delivery sockets.  For optimum performance
1353      * we'd like to hold them open til end of run, but (1) this
1354      * loses if our poll interval is longer than the MTA's inactivity
1355      * timeout, and (2) some MTAs (like smail) don't deliver after
1356      * each message, but rather queue up mail and wait to actually
1357      * deliver it until the input socket is closed. 
1358      *
1359      * Sending SMTP QUIT on signal is theoretically nice, but led to a 
1360      * subtle bug.  If fetchmail was terminated by signal while it was 
1361      * shipping message text, it would hang forever waiting for a
1362      * command acknowledge.  In theory we could enable the QUIT
1363      * only outside of the message send.  In practice, we don't
1364      * care.  All mailservers hang up on a dropped TCP/IP connection
1365      * anyway.
1366      */
1367
1368     if (sig != 0)
1369         report(stdout, _("terminated with signal %d\n"), sig);
1370     else
1371     {
1372         struct query *ctl;
1373
1374         /* terminate all SMTP connections cleanly */
1375         for (ctl = querylist; ctl; ctl = ctl->next)
1376             if (ctl->smtp_socket != -1)
1377             {
1378                 SMTP_quit(ctl->smtp_socket);
1379                 SockClose(ctl->smtp_socket);
1380                 ctl->smtp_socket = -1;
1381             }
1382     }
1383
1384 #ifdef POP3_ENABLE
1385     /*
1386      * Update UID information at end of each poll, rather than at end
1387      * of run, because that way we don't lose all UIDL information since
1388      * the beginning of time if fetchmail crashes.
1389      */
1390     if (!check_only)
1391         write_saved_lists(querylist, run.idfile);
1392 #endif /* POP3_ENABLE */
1393 }
1394
1395 static void terminate_run(int sig)
1396 /* to be executed on normal or signal-induced termination */
1397 {
1398     struct query        *ctl;
1399
1400     terminate_poll(sig);
1401
1402     /* 
1403      * Craig Metz, the RFC1938 one-time-password guy, points out:
1404      * "Remember that most kernels don't zero pages before handing them to the
1405      * next process and many kernels share pages between user and kernel space.
1406      * You'd be very surprised what you can find from a short program to do a
1407      * malloc() and then dump the contents of the pages you got. By zeroing
1408      * the secrets at end of run (earlier if you can), you make sure the next
1409      * guy can't get the password/pass phrase."
1410      *
1411      * Right you are, Craig!
1412      */
1413     for (ctl = querylist; ctl; ctl = ctl->next)
1414         if (ctl->password)
1415           memset(ctl->password, '\0', strlen(ctl->password));
1416
1417 #if !defined(HAVE_ATEXIT) && !defined(HAVE_ON_EXIT)
1418     unlockit();
1419 #endif
1420
1421     exit(successes ? PS_SUCCESS : querystatus);
1422 }
1423
1424 /*
1425  * Sequence of protocols to try when autoprobing, most capable to least.
1426  */
1427 static const int autoprobe[] = 
1428 {
1429 #ifdef IMAP_ENABLE
1430     P_IMAP,
1431 #endif /* IMAP_ENABLE */
1432 #ifdef POP3_ENABLE
1433     P_POP3,
1434 #endif /* POP3_ENABLE */
1435 #ifdef POP2_ENABLE
1436     P_POP2
1437 #endif /* POP2_ENABLE */
1438 };
1439
1440 static int query_host(struct query *ctl)
1441 /* perform fetch transaction with single host */
1442 {
1443     int i, st;
1444
1445     /*
1446      * If we're syslogging the progress messages are automatically timestamped.
1447      * Force timestamping if we're going to a logfile.
1448      */
1449     if (outlevel >= O_VERBOSE || (run.logfile && outlevel > O_SILENT))
1450     {
1451         report(stdout, _("%s querying %s (protocol %s) at %s\n"),
1452                VERSION,
1453                ctl->server.pollname,
1454                showproto(ctl->server.protocol),
1455                rfc822timestamp());
1456     }
1457     switch (ctl->server.protocol) {
1458     case P_AUTO:
1459         for (i = 0; i < sizeof(autoprobe)/sizeof(autoprobe[0]); i++)
1460         {
1461             ctl->server.protocol = autoprobe[i];
1462             if ((st = query_host(ctl)) == PS_SUCCESS || st == PS_NOMAIL || st == PS_AUTHFAIL || st == PS_LOCKBUSY || st == PS_SMTP)
1463                 break;
1464         }
1465         ctl->server.protocol = P_AUTO;
1466         return(st);
1467     case P_POP2:
1468 #ifdef POP2_ENABLE
1469         return(doPOP2(ctl));
1470 #else
1471         report(stderr, _("POP2 support is not configured.\n"));
1472         return(PS_PROTOCOL);
1473 #endif /* POP2_ENABLE */
1474         break;
1475     case P_POP3:
1476     case P_APOP:
1477     case P_RPOP:
1478 #ifdef POP3_ENABLE
1479         return(doPOP3(ctl));
1480 #else
1481         report(stderr, _("POP3 support is not configured.\n"));
1482         return(PS_PROTOCOL);
1483 #endif /* POP3_ENABLE */
1484         break;
1485     case P_IMAP:
1486     case P_IMAP_K4:
1487     case P_IMAP_CRAM_MD5:
1488     case P_IMAP_LOGIN:
1489 #ifdef GSSAPI
1490     case P_IMAP_GSS:
1491 #endif /* GSSAPI */
1492 #ifdef IMAP_ENABLE
1493         return(doIMAP(ctl));
1494 #else
1495         report(stderr, _("IMAP support is not configured.\n"));
1496         return(PS_PROTOCOL);
1497 #endif /* IMAP_ENABLE */
1498     case P_ETRN:
1499 #ifndef ETRN_ENABLE
1500         report(stderr, _("ETRN support is not configured.\n"));
1501         return(PS_PROTOCOL);
1502 #else
1503 #ifdef HAVE_GETHOSTBYNAME
1504         return(doETRN(ctl));
1505 #else
1506         report(stderr, _("Cannot support ETRN without gethostbyname(2).\n"));
1507         return(PS_PROTOCOL);
1508 #endif /* HAVE_GETHOSTBYNAME */
1509 #endif /* ETRN_ENABLE */
1510     default:
1511         report(stderr, _("unsupported protocol selected.\n"));
1512         return(PS_PROTOCOL);
1513     }
1514 }
1515
1516 static void dump_params (struct runctl *runp,
1517                          struct query *querylist, flag implicit)
1518 /* display query parameters in English */
1519 {
1520     struct query *ctl;
1521
1522     if (runp->poll_interval)
1523         printf(_("Poll interval is %d seconds\n"), runp->poll_interval);
1524     if (runp->logfile)
1525         printf(_("Logfile is %s\n"), runp->logfile);
1526     if (strcmp(runp->idfile, IDFILE_NAME))
1527         printf(_("Idfile is %s\n"), runp->idfile);
1528 #if defined(HAVE_SYSLOG)
1529     if (runp->use_syslog)
1530         printf(_("Progress messages will be logged via syslog\n"));
1531 #endif
1532     if (runp->invisible)
1533         printf(_("Fetchmail will masquerade and will not generate Received\n"));
1534     if (runp->postmaster)
1535         printf(_("Fetchmail will forward misaddressed multidrop messages to %s.\n"),
1536                runp->postmaster);
1537
1538     if (!runp->bouncemail)
1539         printf(_("Fetchmail will direct error mail to the postmaster.\n"));
1540     else if (outlevel >= O_VERBOSE)
1541         printf(_("Fetchmail will direct error mail to the sender.\n"));
1542
1543     for (ctl = querylist; ctl; ctl = ctl->next)
1544     {
1545         if (!ctl->active || (implicit && ctl->server.skip))
1546             continue;
1547
1548         printf(_("Options for retrieving from %s@%s:\n"),
1549                ctl->remotename, visbuf(ctl->server.pollname));
1550
1551         if (ctl->server.via && (ctl->server.protocol != P_ETRN))
1552             printf(_("  Mail will be retrieved via %s\n"), ctl->server.via);
1553
1554         if (ctl->server.interval)
1555             printf(_("  Poll of this server will occur every %d intervals.\n"),
1556                    ctl->server.interval);
1557         if (ctl->server.truename)
1558             printf(_("  True name of server is %s.\n"), ctl->server.truename);
1559         if (ctl->server.skip || outlevel >= O_VERBOSE)
1560             printf(_("  This host %s be queried when no host is specified.\n"),
1561                    ctl->server.skip ? _("will not") : _("will"));
1562         /*
1563          * Don't poll for password when there is one or when using the ETRN
1564          * or IMAP-GSS protocol
1565          */
1566         /* ETRN, IMAP_GSS, and IMAP_K4 do not need a password, so skip this */
1567         if ( (ctl->server.protocol != P_ETRN)
1568 #ifdef GSSAPI
1569                                 && (ctl->server.protocol != P_IMAP_GSS)
1570 #endif /* GSSAPI */
1571                                 && (ctl->server.protocol != P_IMAP_K4) ) {
1572                 if (!ctl->password)
1573                         printf(_("  Password will be prompted for.\n"));
1574                 else if (outlevel >= O_VERBOSE)
1575                 {
1576                         if (ctl->server.protocol == P_APOP)
1577                                 printf(_("  APOP secret = \"%s\".\n"),
1578                                                         visbuf(ctl->password));
1579                         else if (ctl->server.protocol == P_RPOP)
1580                                 printf(_("  RPOP id = \"%s\".\n"),
1581                                                         visbuf(ctl->password));
1582                         else
1583                                 printf(_("  Password = \"%s\".\n"),
1584                                                         visbuf(ctl->password));
1585                 }
1586         }
1587
1588         if (ctl->server.protocol == P_POP3 
1589 #if INET6_ENABLE
1590             && ctl->server.service && !strcmp(ctl->server.service, KPOP_PORT)
1591 #else /* INET6_ENABLE */
1592             && ctl->server.port == KPOP_PORT
1593 #endif /* INET6_ENABLE */
1594             && (ctl->server.preauthenticate == A_KERBEROS_V4 ||
1595                 ctl->server.preauthenticate == A_KERBEROS_V5))
1596             printf(_("  Protocol is KPOP with Kerberos %s authentication"),
1597                    ctl->server.preauthenticate == A_KERBEROS_V5 ? "V" : "IV");
1598         else
1599             printf(_("  Protocol is %s"), showproto(ctl->server.protocol));
1600 #if INET6_ENABLE
1601         if (ctl->server.service)
1602             printf(_(" (using service %s)"), ctl->server.service);
1603         if (ctl->server.netsec)
1604             printf(_(" (using network security options %s)"), ctl->server.netsec);
1605 #else /* INET6_ENABLE */
1606         if (ctl->server.port)
1607             printf(_(" (using port %d)"), ctl->server.port);
1608 #endif /* INET6_ENABLE */
1609         else if (outlevel >= O_VERBOSE)
1610             printf(_(" (using default port)"));
1611         if (ctl->server.uidl && (ctl->server.protocol != P_ETRN))
1612             printf(_(" (forcing UIDL use)"));
1613         putchar('.');
1614         putchar('\n');
1615         if (ctl->server.preauthenticate == A_KERBEROS_V4)
1616             printf(_("  Kerberos V4 preauthentication enabled.\n"));
1617         else if (ctl->server.preauthenticate == A_KERBEROS_V5)
1618             printf(_("  Kerberos V5 preauthentication enabled.\n"));
1619         else if (ctl->server.preauthenticate == A_SSH)
1620             printf(_("  End-to-end encryption assumed.\n"));
1621 #ifdef  SSL_ENABLE
1622         if (ctl->use_ssl)
1623             printf("  SSL encrypted sessions enabled.\n");
1624 #endif
1625         if (ctl->server.timeout > 0)
1626             printf(_("  Server nonresponse timeout is %d seconds"), ctl->server.timeout);
1627         if (ctl->server.timeout ==  CLIENT_TIMEOUT)
1628             printf(_(" (default).\n"));
1629         else
1630             printf(".\n");
1631
1632         if (ctl->server.protocol != P_ETRN) {
1633                 if (!ctl->mailboxes->id)
1634                     printf(_("  Default mailbox selected.\n"));
1635                 else
1636                 {
1637                     struct idlist *idp;
1638
1639                     printf(_("  Selected mailboxes are:"));
1640                     for (idp = ctl->mailboxes; idp; idp = idp->next)
1641                         printf(" %s", idp->id);
1642                     printf("\n");
1643                 }
1644                 printf(_("  %s messages will be retrieved (--all %s).\n"),
1645                        ctl->fetchall ? _("All") : _("Only new"),
1646                        ctl->fetchall ? "on" : "off");
1647                 printf(_("  Fetched messages %s be kept on the server (--keep %s).\n"),
1648                        ctl->keep ? _("will") : _("will not"),
1649                        ctl->keep ? "on" : "off");
1650                 printf(_("  Old messages %s be flushed before message retrieval (--flush %s).\n"),
1651                        ctl->flush ? _("will") : _("will not"),
1652                        ctl->flush ? "on" : "off");
1653                 printf(_("  Rewrite of server-local addresses is %s (--norewrite %s).\n"),
1654                        ctl->rewrite ? _("enabled") : _("disabled"),
1655                        ctl->rewrite ? "off" : "on");
1656                 printf(_("  Carriage-return stripping is %s (stripcr %s).\n"),
1657                        ctl->stripcr ? _("enabled") : _("disabled"),
1658                        ctl->stripcr ? "on" : "off");
1659                 printf(_("  Carriage-return forcing is %s (forcecr %s).\n"),
1660                        ctl->forcecr ? _("enabled") : _("disabled"),
1661                        ctl->forcecr ? "on" : "off");
1662                 printf(_("  Interpretation of Content-Transfer-Encoding is %s (pass8bits %s).\n"),
1663                        ctl->pass8bits ? _("disabled") : _("enabled"),
1664                        ctl->pass8bits ? "on" : "off");
1665                 printf(_("  MIME decoding is %s (mimedecode %s).\n"),
1666                        ctl->mimedecode ? _("enabled") : _("disabled"),
1667                        ctl->mimedecode ? "on" : "off");
1668                 printf(_("  Nonempty Status lines will be %s (dropstatus %s)\n"),
1669                        ctl->dropstatus ? _("discarded") : _("kept"),
1670                        ctl->dropstatus ? "on" : "off");
1671                 if (NUM_NONZERO(ctl->limit))
1672                 {
1673                     if (NUM_NONZERO(ctl->limit))
1674                         printf(_("  Message size limit is %d octets (--limit %d).\n"), 
1675                                ctl->limit, ctl->limit);
1676                     else if (outlevel >= O_VERBOSE)
1677                         printf(_("  No message size limit (--limit 0).\n"));
1678                     if (run.poll_interval > 0)
1679                         printf(_("  Message size warning interval is %d seconds (--warnings %d).\n"), 
1680                                ctl->warnings, ctl->warnings);
1681                     else if (outlevel >= O_VERBOSE)
1682                         printf(_("  Size warnings on every poll (--warnings 0).\n"));
1683                 }
1684                 if (NUM_NONZERO(ctl->fetchlimit))
1685                     printf(_("  Received-message limit is %d (--fetchlimit %d).\n"),
1686                            ctl->fetchlimit, ctl->fetchlimit);
1687                 else if (outlevel >= O_VERBOSE)
1688                     printf(_("  No received-message limit (--fetchlimit 0).\n"));
1689                 if (NUM_NONZERO(ctl->batchlimit))
1690                     printf(_("  SMTP message batch limit is %d.\n"), ctl->batchlimit);
1691                 else if (outlevel >= O_VERBOSE)
1692                     printf(_("  No SMTP message batch limit (--batchlimit 0).\n"));
1693                 if (ctl->server.protocol == P_IMAP)
1694                 {
1695                     if (NUM_NONZERO(ctl->expunge))
1696                         printf(_("  Deletion interval between expunges forced to %d (--expunge %d).\n"), ctl->expunge, ctl->expunge);
1697                     else if (outlevel >= O_VERBOSE)
1698                         printf(_("  No forced expunges (--expunge 0).\n"));
1699                 }
1700         }
1701         if (ctl->bsmtp)
1702             printf(_("  Messages will be appended to %s as BSMTP\n"), visbuf(ctl->bsmtp));
1703         else if (ctl->mda && (ctl->server.protocol != P_ETRN))
1704             printf(_("  Messages will be delivered with \"%s\".\n"), visbuf(ctl->mda));
1705         else
1706         {
1707             struct idlist *idp;
1708
1709             printf(_("  Messages will be %cMTP-forwarded to:"), ctl->listener);
1710             for (idp = ctl->smtphunt; idp; idp = idp->next)
1711             {
1712                 printf(" %s", idp->id);
1713                 if (!idp->val.status.mark)
1714                     printf(_(" (default)"));
1715             }
1716             printf("\n");
1717             if (ctl->smtpaddress)
1718                 printf(_("  Host part of MAIL FROM line will be %s\n"),
1719                        ctl->smtpaddress);
1720         }
1721         if (ctl->server.protocol != P_ETRN)
1722         {
1723                 if (ctl->antispam != (struct idlist *)NULL)
1724                 {
1725                     struct idlist *idp;
1726
1727                     printf(_("  Recognized listener spam block responses are:"));
1728                     for (idp = ctl->antispam; idp; idp = idp->next)
1729                         printf(" %d", idp->val.status.num);
1730                     printf("\n");
1731                 }
1732                 else if (outlevel >= O_VERBOSE)
1733                     printf(_("  Spam-blocking disabled\n"));
1734         }
1735         if (ctl->preconnect)
1736             printf(_("  Server connection will be brought up with \"%s\".\n"),
1737                    visbuf(ctl->preconnect));
1738         else if (outlevel >= O_VERBOSE)
1739             printf(_("  No pre-connection command.\n"));
1740         if (ctl->postconnect)
1741             printf(_("  Server connection will be taken down with \"%s\".\n"),
1742                    visbuf(ctl->postconnect));
1743         else if (outlevel >= O_VERBOSE)
1744             printf(_("  No post-connection command.\n"));
1745         if (ctl->server.protocol != P_ETRN) {
1746                 if (!ctl->localnames)
1747                     printf(_("  No localnames declared for this host.\n"));
1748                 else
1749                 {
1750                     struct idlist *idp;
1751                     int count = 0;
1752
1753                     for (idp = ctl->localnames; idp; idp = idp->next)
1754                         ++count;
1755
1756                     if (count > 1 || ctl->wildcard)
1757                         printf(_("  Multi-drop mode: "));
1758                     else
1759                         printf(_("  Single-drop mode: "));
1760
1761                     printf(_("%d local name(s) recognized.\n"), count);
1762                     if (outlevel >= O_VERBOSE)
1763                     {
1764                         for (idp = ctl->localnames; idp; idp = idp->next)
1765                             if (idp->val.id2)
1766                                 printf("\t%s -> %s\n", idp->id, idp->val.id2);
1767                             else
1768                                 printf("\t%s\n", idp->id);
1769                         if (ctl->wildcard)
1770                             fputs("\t*\n", stdout);
1771                     }
1772
1773                     if (count > 1 || ctl->wildcard)
1774                     {
1775                         printf(_("  DNS lookup for multidrop addresses is %s.\n"),
1776                                ctl->server.dns ? _("enabled") : _("disabled"));
1777                         if (ctl->server.dns)
1778                         {
1779                             printf(_("  Server aliases will be compared with multidrop addresses by "));
1780                             if (ctl->server.checkalias)
1781                                 printf(_("IP address.\n"));
1782                             else
1783                                 printf(_("name.\n"));
1784                         }
1785                         if (ctl->server.envelope == STRING_DISABLED)
1786                             printf(_("  Envelope-address routing is disabled\n"));
1787                         else
1788                         {
1789                             printf(_("  Envelope header is assumed to be: %s\n"),
1790                                    ctl->server.envelope ? ctl->server.envelope:_("Received"));
1791                             if (ctl->server.envskip > 1 || outlevel >= O_VERBOSE)
1792                                 printf(_("  Number of envelope header to be parsed: %d\n"),
1793                                        ctl->server.envskip);
1794                             if (ctl->server.qvirtual)
1795                                 printf(_("  Prefix %s will be removed from user id\n"),
1796                                        ctl->server.qvirtual);
1797                             else if (outlevel >= O_VERBOSE) 
1798                                 printf(_("  No prefix stripping\n"));
1799                         }
1800
1801                         if (ctl->server.akalist)
1802                         {
1803                             struct idlist *idp;
1804
1805                             printf(_("  Predeclared mailserver aliases:"));
1806                             for (idp = ctl->server.akalist; idp; idp = idp->next)
1807                                 printf(" %s", idp->id);
1808                             putchar('\n');
1809                         }
1810                         if (ctl->server.localdomains)
1811                         {
1812                             struct idlist *idp;
1813
1814                             printf(_("  Local domains:"));
1815                             for (idp = ctl->server.localdomains; idp; idp = idp->next)
1816                                 printf(" %s", idp->id);
1817                             putchar('\n');
1818                         }
1819                     }
1820                 }
1821         }
1822 #if defined(linux) || defined(__FreeBSD__)
1823         if (ctl->server.interface)
1824             printf(_("  Connection must be through interface %s.\n"), ctl->server.interface);
1825         else if (outlevel >= O_VERBOSE)
1826             printf(_("  No interface requirement specified.\n"));
1827         if (ctl->server.monitor)
1828             printf(_("  Polling loop will monitor %s.\n"), ctl->server.monitor);
1829         else if (outlevel >= O_VERBOSE)
1830             printf(_("  No monitor interface specified.\n"));
1831 #endif
1832
1833         if (ctl->server.plugin)
1834             printf(_("  Server connections will be mode via plugin %s (--plugin %s).\n"), ctl->server.plugin, ctl->server.plugin);
1835         else if (outlevel >= O_VERBOSE)
1836             printf(_("  No plugin command specified.\n"));
1837         if (ctl->server.plugout)
1838             printf(_("  Listener connections will be mode via plugout %s (--plugout %s).\n"), ctl->server.plugout, ctl->server.plugout);
1839         else if (outlevel >= O_VERBOSE)
1840             printf(_("  No plugout command specified.\n"));
1841
1842         if (ctl->server.protocol > P_POP2 && (ctl->server.protocol != P_ETRN))
1843         {
1844             if (!ctl->oldsaved)
1845                 printf(_("  No UIDs saved from this host.\n"));
1846             else
1847             {
1848                 struct idlist *idp;
1849                 int count = 0;
1850
1851                 for (idp = ctl->oldsaved; idp; idp = idp->next)
1852                     ++count;
1853
1854                 printf(_("  %d UIDs saved.\n"), count);
1855                 if (outlevel >= O_VERBOSE)
1856                     for (idp = ctl->oldsaved; idp; idp = idp->next)
1857                         printf("\t%s\n", idp->id);
1858             }
1859         }
1860
1861         if (ctl->properties)
1862             printf(_("  Pass-through properties \"%s\".\n"),
1863                    visbuf(ctl->properties));
1864     }
1865 }
1866
1867 /* fetchmail.c ends here */