]> Pileus Git - ~andy/fetchmail/blob - fetchmail.c
Deal with the possibility that we might be running as a subprocess.
[~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             if (!isatty(0))
520             {
521                 fprintf(stderr,
522                         _("fetchmail: can't find a password for %s@s.\n"),
523                         ctl->remotename, ctl->server.pollname);
524                 return(PS_AUTHFAIL);
525             }
526             else
527             {
528                 char* password_prompt = _("Enter password for %s@%s: ");
529
530                 xalloca(tmpbuf, char *, strlen(password_prompt) +
531                         strlen(ctl->remotename) +
532                         strlen(ctl->server.pollname) + 1);
533                 (void) sprintf(tmpbuf, password_prompt,
534                                ctl->remotename, ctl->server.pollname);
535                 ctl->password = xstrdup((char *)getpassword(tmpbuf));
536             }
537     }
538
539     /*
540      * Time to initiate the SOCKS library (this is not mandatory: it just
541      * registers the correct application name for logging purpose. If you
542      * have some problem, comment out these lines).
543      */
544 #ifdef HAVE_SOCKS
545     SOCKSinit("fetchmail");
546 #endif /* HAVE_SOCKS */
547
548     /*
549      * Maybe time to go to demon mode...
550      */
551     if (run.poll_interval)
552     {
553         if (!nodetach)
554             daemonize(run.logfile, terminate_run);
555         report(stdout, _("starting fetchmail %s daemon \n"), VERSION);
556
557         /*
558          * We'll set up a handler for these when we're sleeping,
559          * but ignore them otherwise so as not to interrupt a poll.
560          */
561         signal(SIGUSR1, SIG_IGN);
562         if (run.poll_interval && !getuid())
563             signal(SIGHUP, SIG_IGN);
564     }
565     else if (run.logfile && access(run.logfile, F_OK) == 0)
566     {
567         freopen(run.logfile, "a", stdout);
568         freopen(run.logfile, "a", stderr);
569     }
570
571
572 #ifdef linux
573     interface_init();
574 #endif /* linux */
575
576     /* beyond here we don't want more than one fetchmail running per user */
577     umask(0077);
578     signal(SIGABRT, terminate_run);
579     signal(SIGINT, terminate_run);
580     signal(SIGTERM, terminate_run);
581     signal(SIGALRM, terminate_run);
582     signal(SIGPIPE, terminate_run);
583     signal(SIGQUIT, terminate_run);
584
585     /* here's the exclusion lock */
586 #ifndef O_SYNC
587 #define O_SYNC  0       /* use it if we have it */
588 #endif
589     if ((st = open(lockfile, O_WRONLY|O_CREAT|O_EXCL|O_SYNC, 0666)) != -1)
590     {
591         sprintf(tmpbuf,"%d", getpid());
592         write(st, tmpbuf, strlen(tmpbuf));
593         if (run.poll_interval)
594         {
595             sprintf(tmpbuf," %d", run.poll_interval);
596             write(st, tmpbuf, strlen(tmpbuf));
597         }
598         close(st);      /* should be safe, fd was opened with O_SYNC */
599         lock_acquired = TRUE;
600     }
601
602     /*
603      * Query all hosts. If there's only one, the error return will
604      * reflect the status of that transaction.
605      */
606     do {
607         /* 
608          * Check to see if the rcfile has been touched.  If so,
609          * re-exec so the file will be reread.  Doing it this way
610          * avoids all the complications of trying to deallocate the
611          * in-core control structures -- and the potential memory
612          * leaks...
613          */
614         struct stat     rcstat;
615
616         if (stat(rcfile, &rcstat) == -1)
617         {
618             if (errno != ENOENT)
619                 report(stderr, 
620                        _("couldn't time-check %s (error %d)\n"),
621                        rcfile, errno);
622         }
623         else if (rcstat.st_mtime > parsetime)
624         {
625             report(stdout, _("restarting fetchmail (%s changed)\n"), rcfile);
626             execvp("fetchmail", argv);
627             report(stderr, _("attempt to re-exec fetchmail failed\n"));
628         }
629
630 #if defined(HAVE_RES_SEARCH) && defined(USE_TCPIP_FOR_DNS)
631         /*
632          * This was an efficiency hack that backfired.  The theory
633          * was that using TCP/IP for DNS queries would get us better
634          * reliability and shave off some per-UDP-packet costs.
635          * Unfortunately it interacted badly with diald, which effectively 
636          * filters out DNS queries over TCP/IP for reasons having to do
637          * with some obscure kernel problem involving bootstrapping of
638          * dynamically-addressed links.  I don't understand this mess
639          * and don't want to, so it's "See ya!" to this hack.
640          */
641         sethostent(TRUE);       /* use TCP/IP for mailserver queries */
642 #endif /* HAVE_RES_SEARCH */
643
644         batchcount = 0;
645         for (ctl = querylist; ctl; ctl = ctl->next)
646         {
647             if (ctl->active && !(implicitmode && ctl->server.skip))
648             {
649                 if (ctl->wedged)
650                 {
651                     report(stderr, 
652                           _("poll of %s skipped (failed authentication or too many timeouts)\n"),
653                           ctl->server.pollname);
654                     continue;
655                 }
656
657                 /* check skip interval first so that it counts all polls */
658                 if (run.poll_interval && ctl->server.interval) 
659                 {
660                     if (ctl->server.poll_count++ % ctl->server.interval) 
661                     {
662                         if (outlevel >= O_VERBOSE)
663                             report(stdout,
664                                     _("interval not reached, not querying %s\n"),
665                                     ctl->server.pollname);
666                         continue;
667                     }
668                 }
669
670 #if (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__)
671                 /* interface_approve() does its own error logging */
672                 if (!interface_approve(&ctl->server))
673                     continue;
674 #endif /* (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__) */
675
676                 querystatus = query_host(ctl);
677
678 #ifdef POP3_ENABLE
679                 if (!check_only)
680                     uid_end_query(ctl);
681 #endif  /* POP3_ENABLE */
682
683                 if (querystatus == PS_SUCCESS)
684                     successes++;
685                 else if (!check_only && 
686                          ((querystatus!=PS_NOMAIL) || (outlevel==O_DEBUG)))
687                 switch(querystatus)
688                 {
689                 case PS_SUCCESS:
690                     report(stdout, "Query status=SUCCESS\n"); break ;
691                 case PS_NOMAIL: 
692                     report(stdout, "Query status=NOMAIL\n"); break ;
693                 case PS_SOCKET:
694                     report(stdout, "Query status=SOCKET\n"); break ;
695                 case PS_AUTHFAIL:
696                     report(stdout, "Query status=AUTHFAIL\n"); break ;
697                 case PS_PROTOCOL:
698                     report(stdout, "Query status=PROTOCOL\n"); break ;
699                 case PS_SYNTAX:
700                     report(stdout, "Query status=SYNTAX\n"); break ;
701                 case PS_IOERR:
702                     report(stdout, "Query status=IOERR\n"); break ;
703                 case PS_ERROR:
704                     report(stdout, "Query status=ERROR\n"); break ;
705                 case PS_EXCLUDE:
706                     report(stdout, "Query status=EXCLUDE\n"); break ;
707                 case PS_LOCKBUSY:
708                     report(stdout, "Query status=LOCKBUSY\n"); break ;
709                 case PS_SMTP:
710                     report(stdout, "Query status=SMTP\n"); break ;
711                 case PS_DNS:
712                     report(stdout, "Query status=DNS\n"); break ;
713                 case PS_BSMTP:
714                     report(stdout, "Query status=BSMTP\n"); break ;
715                 case PS_MAXFETCH:
716                     report(stdout, "Query status=MAXFETCH\n"); break ;
717                 case PS_UNDEFINED:
718                     report(stdout, "Query status=UNDEFINED\n"); break ;
719                 case PS_TRANSIENT:
720                     report(stdout, "Query status=TRANSIENT\n"); break ;
721                 case PS_REFUSED:
722                     report(stdout, "Query status=REFUSED\n"); break ;
723                 case PS_RETAINED:
724                     report(stdout, "Query status=RETAINED\n"); break ;
725                 case PS_TRUNCATED:
726                     report(stdout, "Query status=TRUNCATED\n"); break ;
727                 default:
728                     report(stdout, _("Query status=%d\n"), querystatus); break;
729                 }
730
731 #if (defined(linux) && !INET6_ENABLE) || defined (__FreeBSD__)
732                 if (ctl->server.monitor)
733                 {
734                     /*
735                      * Allow some time for the link to quiesce.  One
736                      * second is usually sufficient, three is safe.
737                      * Note:  this delay is important - don't remove!
738                      */
739                     sleep(3);
740                     interface_note_activity(&ctl->server);
741                 }
742 #endif /* (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__) */
743             }
744         }
745
746 #if defined(HAVE_RES_SEARCH) && defined(USE_TCPIP_FOR_DNS)
747         endhostent();           /* release TCP/IP connection to nameserver */
748 #endif /* HAVE_RES_SEARCH */
749
750         /* close connections cleanly */
751         terminate_poll(0);
752
753         /*
754          * OK, we've polled.  Now sleep.
755          */
756         if (run.poll_interval)
757         {
758             /* 
759              * Because passwords can expire, it may happen that *all*
760              * hosts are now out of the loop due to authfail
761              * conditions.  If this happens daemon-mode fetchmail
762              * should softly and silently vanish away, rather than
763              * spinning uselessly.
764              */
765             int unwedged = 0;
766
767             for (ctl = querylist; ctl; ctl = ctl->next)
768                 if (ctl->active && !(implicitmode && ctl->server.skip))
769                     if (!ctl->wedged)
770                         unwedged++;
771             if (!unwedged)
772             {
773                 report(stderr, _("All connections are wedged.  Exiting.\n"));
774                 /* FIXME: someday, send notification mail */
775                 exit(PS_AUTHFAIL);
776             }
777
778             if (outlevel >= O_VERBOSE)
779                 report(stdout, 
780                        _("fetchmail: sleeping at %s\n"), rfc822timestamp());
781
782             /*
783              * With this simple hack, we make it possible for a foreground 
784              * fetchmail to wake up one in daemon mode.  What we want is the
785              * side effect of interrupting any sleep that may be going on,
786              * forcing fetchmail to re-poll its hosts.  The second line is
787              * for people who think all system daemons wake up on SIGHUP.
788              */
789             signal(SIGUSR1, donothing);
790             if (!getuid())
791                 signal(SIGHUP, donothing);
792
793             /* time for a pause in the action... */
794             {
795 #ifndef __EMX__
796 #ifdef SLEEP_WITH_ALARM         /* not normally on */
797                 /*
798                  * We can't use sleep(3) here because we need an alarm(3)
799                  * equivalent in order to implement server nonresponse timeout.
800                  * We'll just assume setitimer(2) is available since fetchmail
801                  * has to have a BSDoid socket layer to work at all.
802                  */
803                 /* 
804                  * This code stopped working under glibc-2, apparently due
805                  * to the change in signal(2) semantics.  (The siginterrupt
806                  * line, added later, should fix this problem.) John Stracke
807                  * <francis@netscape.com> wrote:
808                  *
809                  * The problem seems to be that, after hitting the interval
810                  * timer while talking to the server, the process no longer
811                  * responds to SIGALRM.  I put in printf()s to see when it
812                  * reached the pause() for the poll interval, and I checked
813                  * the return from setitimer(), and everything seemed to be
814                  * working fine, except that the pause() just ignored SIGALRM.
815                  * I thought maybe the itimer wasn't being fired, so I hit
816                  * it with a SIGALRM from the command line, and it ignored
817                  * that, too.  SIGUSR1 woke it up just fine, and it proceeded
818                  * to repoll--but, when the dummy server didn't respond, it
819                  * never timed out, and SIGALRM wouldn't make it.
820                  *
821                  * (continued below...)
822                  */
823                 struct itimerval ntimeout;
824
825                 ntimeout.it_interval.tv_sec = 5; /* repeat alarm every 5 secs */
826                 ntimeout.it_interval.tv_usec = 0;
827                 ntimeout.it_value.tv_sec  = run.poll_interval;
828                 ntimeout.it_value.tv_usec = 0;
829
830                 siginterrupt(SIGALRM, 1);
831                 alarm_latch = FALSE;
832                 signal(SIGALRM, gotsigalrm);    /* first trap signals */
833                 setitimer(ITIMER_REAL,&ntimeout,NULL);  /* then start timer */
834                 /* there is a very small window between the next two lines */
835                 /* which could result in a deadlock.  But this will now be  */
836                 /* caught by periodical alarms (see it_interval) */
837                 if (!alarm_latch)
838                     pause();
839                 /* stop timer */
840                 ntimeout.it_interval.tv_sec = ntimeout.it_interval.tv_usec = 0;
841                 ntimeout.it_value.tv_sec  = ntimeout.it_value.tv_usec = 0;
842                 setitimer(ITIMER_REAL,&ntimeout,NULL);  /* now stop timer */
843                 signal(SIGALRM, SIG_IGN);
844 #else
845                 /* 
846                  * So the workaround I used is to make it sleep by using
847                  * select() instead of setitimer()/pause().  select() is
848                  * perfectly happy being called with a timeout and
849                  * no file descriptors; it just sleeps until it hits the
850                  * timeout.  The only concern I had was that it might
851                  * implement its timeout with SIGALRM--there are some
852                  * Unices where this is done, because select() is a library
853                  * function--but apparently not.
854                  */
855                 struct timeval timeout;
856
857                 timeout.tv_sec = run.poll_interval;
858                 timeout.tv_usec = 0;
859                 do {
860                     lastsig = 0;
861                     select(0,0,0,0, &timeout);
862                 } while (lastsig == SIGCHLD);
863 #endif
864 #else /* EMX */
865                 alarm_latch = FALSE;
866                 signal(SIGALRM, gotsigalrm);
867                 _beginthread(itimerthread, NULL, 32768, NULL);
868                 /* see similar code above */
869                 if (!alarm_latch)
870                     pause();
871                 signal(SIGALRM, SIG_IGN);
872 #endif /* ! EMX */
873                 if (lastsig == SIGUSR1
874                         || ((run.poll_interval && !getuid()) && lastsig == SIGHUP))
875                 {
876 #ifdef SYS_SIGLIST_DECLARED
877                     report(stdout, 
878                            _("awakened by %s\n"), sys_siglist[lastsig]);
879 #else
880                     report(stdout, 
881                            _("awakened by signal %d\n"), lastsig);
882 #endif
883                     /* received a wakeup - unwedge all servers in case */
884                     /* the problem has been manually repaired          */
885                     for (ctl = querylist; ctl; ctl = ctl->next)
886                         ctl->wedged = FALSE;
887                 }
888             }
889
890             /* now lock out interrupts again */
891             signal(SIGUSR1, SIG_IGN);
892             if (!getuid())
893                 signal(SIGHUP, SIG_IGN);
894
895             if (outlevel >= O_VERBOSE)
896                 report(stdout, _("awakened at %s\n"), rfc822timestamp());
897         }
898     } while
899         (run.poll_interval);
900
901     if (outlevel >= O_VERBOSE)
902         report(stdout, _("normal termination, status %d\n"),
903                 successes ? PS_SUCCESS : querystatus);
904
905     terminate_run(0);
906     exit(successes ? PS_SUCCESS : querystatus);
907 }
908
909 static void optmerge(struct query *h2, struct query *h1, int force)
910 /* merge two options records */
911 {
912     /*
913      * If force is off, modify h2 fields only when they're empty (treat h1
914      * as defaults).  If force is on, modify each h2 field whenever h1
915      * is nonempty (treat h1 as an override).  
916      */
917 #define LIST_MERGE(dstl, srcl) if (force ? !!srcl : !dstl) \
918                                                 free_str_list(&dstl), \
919                                                 append_str_list(&dstl, &srcl)
920     LIST_MERGE(h2->server.localdomains, h1->server.localdomains);
921     LIST_MERGE(h2->localnames, h1->localnames);
922     LIST_MERGE(h2->mailboxes, h1->mailboxes);
923     LIST_MERGE(h2->smtphunt, h1->smtphunt);
924     LIST_MERGE(h2->antispam, h1->antispam);
925 #undef LIST_MERGE
926
927 #define FLAG_MERGE(fld) if (force ? !!h1->fld : !h2->fld) h2->fld = h1->fld
928     FLAG_MERGE(server.via);
929     FLAG_MERGE(server.protocol);
930 #if INET6_ENABLE
931     FLAG_MERGE(server.service);
932     FLAG_MERGE(server.netsec);
933 #else /* INET6_ENABLE */
934     FLAG_MERGE(server.port);
935 #endif /* INET6_ENABLE */
936     FLAG_MERGE(server.interval);
937     FLAG_MERGE(server.preauthenticate);
938     FLAG_MERGE(server.timeout);
939     FLAG_MERGE(server.envelope);
940     FLAG_MERGE(server.envskip);
941     FLAG_MERGE(server.qvirtual);
942     FLAG_MERGE(server.skip);
943     FLAG_MERGE(server.dns);
944     FLAG_MERGE(server.checkalias);
945     FLAG_MERGE(server.uidl);
946
947 #if defined(linux) || defined(__FreeBSD__)
948     FLAG_MERGE(server.interface);
949     FLAG_MERGE(server.monitor);
950     FLAG_MERGE(server.interface_pair);
951 #endif /* linux || defined(__FreeBSD__) */
952
953     FLAG_MERGE(server.plugin);
954     FLAG_MERGE(server.plugout);
955
956     FLAG_MERGE(wildcard);
957     FLAG_MERGE(remotename);
958     FLAG_MERGE(password);
959     FLAG_MERGE(mda);
960     FLAG_MERGE(bsmtp);
961     FLAG_MERGE(listener);
962     FLAG_MERGE(smtpaddress);
963     FLAG_MERGE(preconnect);
964     FLAG_MERGE(postconnect);
965
966     FLAG_MERGE(keep);
967     FLAG_MERGE(flush);
968     FLAG_MERGE(fetchall);
969     FLAG_MERGE(rewrite);
970     FLAG_MERGE(forcecr);
971     FLAG_MERGE(stripcr);
972     FLAG_MERGE(pass8bits);
973     FLAG_MERGE(dropstatus);
974     FLAG_MERGE(mimedecode);
975     FLAG_MERGE(limit);
976     FLAG_MERGE(warnings);
977     FLAG_MERGE(fetchlimit);
978     FLAG_MERGE(batchlimit);
979 #ifdef  SSL_ENABLE
980     FLAG_MERGE(use_ssl);
981     FLAG_MERGE(sslkey);
982     FLAG_MERGE(sslcert);
983 #endif
984     FLAG_MERGE(expunge);
985
986     FLAG_MERGE(properties);
987 #undef FLAG_MERGE
988 }
989
990 static int load_params(int argc, char **argv, int optind)
991 {
992     int implicitmode, st;
993     struct passwd *pw;
994     struct query def_opts, *ctl;
995     struct stat rcstat;
996
997     run.bouncemail = TRUE;
998
999     memset(&def_opts, '\0', sizeof(struct query));
1000     def_opts.smtp_socket = -1;
1001     def_opts.smtpaddress = (char *)0;
1002 #define ANTISPAM(n)     save_str(&def_opts.antispam, STRING_DUMMY, 0)->val.status.num = (n)
1003     ANTISPAM(571);      /* sendmail */
1004     ANTISPAM(550);      /* old exim */
1005     ANTISPAM(501);      /* new exim */
1006     ANTISPAM(554);      /* Postfix */
1007 #undef ANTISPAM
1008
1009     def_opts.server.protocol = P_AUTO;
1010     def_opts.server.timeout = CLIENT_TIMEOUT;
1011     def_opts.warnings = WARNING_INTERVAL;
1012     def_opts.remotename = user;
1013     def_opts.listener = SMTP_MODE;
1014
1015     /* note the parse time, so we can pick up on modifications */
1016     parsetime = 0;      /* foil compiler warnings */
1017     if (stat(rcfile, &rcstat) != -1)
1018         parsetime = rcstat.st_mtime;
1019     else if (errno != ENOENT)
1020         report(stderr, _("couldn't time-check the run-control file\n"));
1021
1022     /* this builds the host list */
1023     if ((st = prc_parse_file(rcfile, !versioninfo)) != 0)
1024         /*
1025          * FIXME: someday, send notification mail here if backgrounded.
1026          * Right now, that can happen if the user changes the rcfile
1027          * while the fetchmail is running in background.  Do similarly
1028          * for the other exit() calls in this function.
1029          */
1030         exit(st);
1031
1032     if ((implicitmode = (optind >= argc)))
1033     {
1034         for (ctl = querylist; ctl; ctl = ctl->next)
1035             ctl->active = TRUE;
1036     }
1037     else
1038         for (; optind < argc; optind++) 
1039         {
1040             flag        predeclared =  FALSE;
1041
1042             /*
1043              * If hostname corresponds to a host known from the rc file,
1044              * simply declare it active.  Otherwise synthesize a host
1045              * record from command line and defaults
1046              */
1047             for (ctl = querylist; ctl; ctl = ctl->next)
1048                 if (!strcmp(ctl->server.pollname, argv[optind])
1049                         || str_in_list(&ctl->server.akalist, argv[optind], TRUE))
1050                 {
1051                     /* Is this correct? */
1052                     if(predeclared)
1053                         fprintf(stderr,_("Warning: multiple mentions of host %s in config file\n"),argv[optind]);
1054                     ctl->active = TRUE;
1055                     predeclared = TRUE;
1056                 }
1057
1058             if (!predeclared)
1059             {
1060                 /*
1061                  * Allocate and link record without copying in
1062                  * command-line args; we'll do that with the optmerge
1063                  * call later on.
1064                  */
1065                 ctl = hostalloc((struct query *)NULL);
1066                 ctl->server.via =
1067                     ctl->server.pollname = xstrdup(argv[optind]);
1068                 ctl->active = TRUE;
1069                 ctl->server.lead_server = (struct hostdata *)NULL;
1070             }
1071         }
1072
1073     /*
1074      * If there's a defaults record, merge it and lose it.
1075      */ 
1076     if (querylist && strcmp(querylist->server.pollname, "defaults") == 0)
1077     {
1078         for (ctl = querylist->next; ctl; ctl = ctl->next)
1079             optmerge(ctl, querylist, FALSE);
1080         querylist = querylist->next;
1081     }
1082
1083     /* don't allow a defaults record after the first */
1084     for (ctl = querylist; ctl; ctl = ctl->next)
1085         if (ctl != querylist && strcmp(ctl->server.pollname, "defaults") == 0)
1086             exit(PS_SYNTAX);
1087
1088     /* use localhost if we never fetch the FQDN of this host */
1089     fetchmailhost = "localhost";
1090
1091     /* here's where we override globals */
1092     if (cmd_run.logfile)
1093         run.logfile = cmd_run.logfile;
1094     if (cmd_run.idfile)
1095         run.idfile = cmd_run.idfile;
1096     /* do this before the keep/fetchall test below, otherwise -d0 may fail */
1097     if (cmd_run.poll_interval >= 0)
1098         run.poll_interval = cmd_run.poll_interval;
1099     if (cmd_run.invisible)
1100         run.invisible = cmd_run.invisible;
1101     if (cmd_run.use_syslog)
1102         run.use_syslog = (cmd_run.use_syslog == FLAG_TRUE);
1103     if (cmd_run.postmaster)
1104         run.postmaster = cmd_run.postmaster;
1105     if (cmd_run.bouncemail)
1106         run.bouncemail = cmd_run.bouncemail;
1107
1108     /* check and daemon options are not compatible */
1109     if (check_only && run.poll_interval)
1110         run.poll_interval = 0;
1111
1112     /* merge in wired defaults, do sanity checks and prepare internal fields */
1113     for (ctl = querylist; ctl; ctl = ctl->next)
1114     {
1115         ctl->wedged = FALSE;
1116
1117         if (configdump || (ctl->active && !(implicitmode && ctl->server.skip)))
1118         {
1119             /* merge in defaults */
1120             optmerge(ctl, &def_opts, FALSE);
1121
1122             /* force command-line options */
1123             optmerge(ctl, &cmd_opts, TRUE);
1124
1125             /* this code enables flags to be turned off */
1126 #define DEFAULT(flag, dflt)     if (flag == FLAG_TRUE)\
1127                                         flag = TRUE;\
1128                                 else if (flag == FLAG_FALSE)\
1129                                         flag = FALSE;\
1130                                 else\
1131                                         flag = (dflt)
1132             DEFAULT(ctl->keep, FALSE);
1133             DEFAULT(ctl->fetchall, FALSE);
1134             DEFAULT(ctl->flush, FALSE);
1135             DEFAULT(ctl->rewrite, TRUE);
1136             DEFAULT(ctl->stripcr, (ctl->mda != (char *)NULL)); 
1137             DEFAULT(ctl->forcecr, FALSE);
1138             DEFAULT(ctl->pass8bits, FALSE);
1139             DEFAULT(ctl->dropstatus, FALSE);
1140             DEFAULT(ctl->mimedecode, FALSE);
1141             DEFAULT(ctl->server.dns, TRUE);
1142             DEFAULT(ctl->server.uidl, FALSE);
1143 #ifdef  SSL_ENABLE
1144             DEFAULT(ctl->use_ssl, FALSE);
1145 #endif
1146             DEFAULT(ctl->server.checkalias, FALSE);
1147 #undef DEFAULT
1148
1149             /*
1150              * DNS support is required for some protocols.  We used to
1151              * do this unconditionally, but it made fetchmail excessively
1152              * vulnerable to misconfigured DNS setups.
1153              *
1154              * If we're using ETRN, the smtp hunt list is the list of
1155              * systems we're polling on behalf of; these have to be 
1156              * fully-qualified domain names.  The default for this list
1157              * should be the FQDN of localhost.
1158              *
1159              * If we're using Kerberos for authentication, we need 
1160              * the FQDN in order to generate capability keys.
1161              */
1162             if (ctl->server.protocol == P_ETRN
1163                          || ctl->server.preauthenticate == A_KERBEROS_V4
1164                          || ctl->server.preauthenticate == A_KERBEROS_V5)
1165                 if (strcmp(fetchmailhost, "localhost") == 0)
1166                         fetchmailhost = host_fqdn();
1167
1168             /*
1169              * Make sure we have a nonempty host list to forward to.
1170              */
1171             if (!ctl->smtphunt)
1172                 save_str(&ctl->smtphunt, fetchmailhost, FALSE);
1173
1174             /* if `user' doesn't name a real local user, try to run as root */
1175             if ((pw = getpwnam(user)) == (struct passwd *)NULL)
1176                 ctl->uid = 0;
1177             else
1178                 ctl->uid = pw->pw_uid;  /* for local delivery via MDA */
1179             if (!ctl->localnames)       /* for local delivery via SMTP */
1180                 save_str_pair(&ctl->localnames, user, NULL);
1181
1182 #if !defined(HAVE_GETHOSTBYNAME) || !defined(HAVE_RES_SEARCH)
1183             /* can't handle multidrop mailboxes unless we can do DNS lookups */
1184             if (ctl->localnames && ctl->localnames->next && ctl->server.dns)
1185             {
1186                 ctl->server.dns = FALSE;
1187                 report(stderr, _("fetchmail: warning: no DNS available to check multidrop fetches from %s\n"), ctl->server.pollname);
1188             }
1189 #endif /* !HAVE_GETHOSTBYNAME || !HAVE_RES_SEARCH */
1190
1191             /*
1192              *
1193              * Compute the true name of the mailserver host.  
1194              * There are two clashing cases here:
1195              *
1196              * (1) The poll name is a label, possibly on one of several
1197              *     poll configurations for the same host.  In this case 
1198              *     the `via' option will be present and give the true name.
1199              *
1200              * (2) The poll name is the true one, the via name is 
1201              *     localhost.   This is going to be typical for ssh-using
1202              *     configurations.
1203              *
1204              * We're going to assume the via name is true unless it's
1205              * localhost.
1206              */
1207             if (ctl->server.via && strcmp(ctl->server.via, "localhost"))
1208                 ctl->server.queryname = xstrdup(ctl->server.via);
1209             else
1210                 ctl->server.queryname = xstrdup(ctl->server.pollname);
1211
1212 #ifdef HESIOD
1213         /* If either the pollname or vianame are "hesiod" we want to
1214            lookup the user's hesiod pobox host */
1215
1216         if (!strcasecmp(ctl->server.queryname, "hesiod")) {
1217             struct hes_postoffice *hes_p;
1218             hes_p = hes_getmailhost(ctl->remotename);
1219             if (hes_p != NULL && strcmp(hes_p->po_type, "POP") == 0) {
1220                  free(ctl->server.queryname);
1221                  ctl->server.queryname = xstrdup(hes_p->po_host);
1222                  if (ctl->server.via)
1223                      free(ctl->server.via);
1224                  ctl->server.via = xstrdup(hes_p->po_host);
1225             } else {
1226                  report(stderr,
1227                         _("couldn't find HESIOD pobox for %s\n"),
1228                         ctl->remotename);
1229             }
1230         }
1231 #endif /* HESIOD */
1232
1233             /*
1234              * We may have to canonicalize the server truename for later use.
1235              * Do this just once for each lead server, if necessary, in order
1236              * to minimize DNS round trips.
1237              */
1238             if (ctl->server.lead_server)
1239             {
1240                 char    *leadname = ctl->server.lead_server->truename;
1241
1242                 /* prevent core dump from ill-formed or duplicate entry */
1243                 if (!leadname)
1244                 {
1245                     report(stderr, 
1246                            _("Lead server has no name.\n"));
1247                     exit(PS_SYNTAX);
1248                 }
1249
1250                 ctl->server.truename = xstrdup(leadname);
1251             }
1252 #ifdef HAVE_GETHOSTBYNAME
1253             else if (ctl->server.preauthenticate==A_KERBEROS_V4 ||
1254                 ctl->server.preauthenticate==A_KERBEROS_V5 ||
1255                 (ctl->server.dns && MULTIDROP(ctl)))
1256             {
1257                 struct hostent  *namerec;
1258
1259                 /* compute the canonical name of the host */
1260                 errno = 0;
1261                 namerec = gethostbyname(ctl->server.queryname);
1262                 if (namerec == (struct hostent *)NULL)
1263                 {
1264                     report(stderr,
1265                           _("couldn't find canonical DNS name of %s\n"),
1266                           ctl->server.pollname);
1267                     exit(PS_DNS);
1268                 }
1269                 else
1270                     ctl->server.truename=xstrdup((char *)namerec->h_name);
1271             }
1272 #endif /* HAVE_GETHOSTBYNAME */
1273             else
1274                 ctl->server.truename = xstrdup(ctl->server.queryname);
1275
1276             /* if no folders were specified, set up the null one as default */
1277             if (!ctl->mailboxes)
1278                 save_str(&ctl->mailboxes, (char *)NULL, 0);
1279
1280             /* maybe user overrode timeout on command line? */
1281             if (ctl->server.timeout == -1)      
1282                 ctl->server.timeout = CLIENT_TIMEOUT;
1283
1284 #if !INET6_ENABLE
1285             /* sanity checks */
1286             if (ctl->server.port < 0)
1287             {
1288                 (void) fprintf(stderr,
1289                                _("%s configuration invalid, port number cannot be negative\n"),
1290                                ctl->server.pollname);
1291                 exit(PS_SYNTAX);
1292             }
1293             if (ctl->server.protocol == P_RPOP && ctl->server.port >= 1024)
1294             {
1295                 (void) fprintf(stderr,
1296                                _("%s configuration invalid, RPOP requires a privileged port\n"),
1297                                ctl->server.pollname);
1298                 exit(PS_SYNTAX);
1299             }
1300             if (ctl->listener == LMTP_MODE)
1301             {
1302                 struct idlist   *idp;
1303
1304                 for (idp = ctl->smtphunt; idp; idp = idp->next)
1305                 {
1306                     char        *cp;
1307
1308                     if (!(cp = strrchr(idp->id, '/')) ||
1309                                 (atoi(++cp) == SMTP_PORT))
1310                     {
1311                         (void) fprintf(stderr,
1312                                        _("%s configuration invalid, LMTP can't use default SMTP port\n"),
1313                                        ctl->server.pollname);
1314                         exit(PS_SYNTAX);
1315                     }
1316                 }
1317             }
1318 #endif /* !INET6_ENABLE */
1319
1320             /*
1321              * "I beg to you, have mercy on the week minds like myself."
1322              * wrote Pehr Anderson.  Your petition is granted.
1323              */
1324             if (ctl->fetchall && ctl->keep && run.poll_interval && !nodetach)
1325             {
1326                 (void) fprintf(stderr,
1327                                _("Both fetchall and keep on in daemon mode is a mistake!\n"));
1328                 exit(PS_SYNTAX);
1329             }
1330         }
1331     }
1332
1333 #ifdef POP3_ENABLE
1334     /* initialize UID handling */
1335     if (!versioninfo && (st = prc_filecheck(run.idfile, !versioninfo)) != 0)
1336         exit(st);
1337     else
1338         initialize_saved_lists(querylist, run.idfile);
1339 #endif /* POP3_ENABLE */
1340
1341     /*
1342      * If the user didn't set a last-resort user to get misaddressed
1343      * multidrop mail, set an appropriate default here.
1344      */
1345     if (!run.postmaster)
1346     {
1347         if (getuid())                           /* ordinary user */
1348             run.postmaster = user;
1349         else                                    /* root */
1350             run.postmaster = "postmaster";
1351     }
1352
1353     return(implicitmode);
1354 }
1355
1356 static void terminate_poll(int sig)
1357 /* to be executed at the end of a poll cycle */
1358 {
1359     /*
1360      * Close all SMTP delivery sockets.  For optimum performance
1361      * we'd like to hold them open til end of run, but (1) this
1362      * loses if our poll interval is longer than the MTA's inactivity
1363      * timeout, and (2) some MTAs (like smail) don't deliver after
1364      * each message, but rather queue up mail and wait to actually
1365      * deliver it until the input socket is closed. 
1366      *
1367      * Sending SMTP QUIT on signal is theoretically nice, but led to a 
1368      * subtle bug.  If fetchmail was terminated by signal while it was 
1369      * shipping message text, it would hang forever waiting for a
1370      * command acknowledge.  In theory we could enable the QUIT
1371      * only outside of the message send.  In practice, we don't
1372      * care.  All mailservers hang up on a dropped TCP/IP connection
1373      * anyway.
1374      */
1375
1376     if (sig != 0)
1377         report(stdout, _("terminated with signal %d\n"), sig);
1378     else
1379     {
1380         struct query *ctl;
1381
1382         /* terminate all SMTP connections cleanly */
1383         for (ctl = querylist; ctl; ctl = ctl->next)
1384             if (ctl->smtp_socket != -1)
1385             {
1386                 SMTP_quit(ctl->smtp_socket);
1387                 SockClose(ctl->smtp_socket);
1388                 ctl->smtp_socket = -1;
1389             }
1390     }
1391
1392 #ifdef POP3_ENABLE
1393     /*
1394      * Update UID information at end of each poll, rather than at end
1395      * of run, because that way we don't lose all UIDL information since
1396      * the beginning of time if fetchmail crashes.
1397      */
1398     if (!check_only)
1399         write_saved_lists(querylist, run.idfile);
1400 #endif /* POP3_ENABLE */
1401 }
1402
1403 static void terminate_run(int sig)
1404 /* to be executed on normal or signal-induced termination */
1405 {
1406     struct query        *ctl;
1407
1408     terminate_poll(sig);
1409
1410     /* 
1411      * Craig Metz, the RFC1938 one-time-password guy, points out:
1412      * "Remember that most kernels don't zero pages before handing them to the
1413      * next process and many kernels share pages between user and kernel space.
1414      * You'd be very surprised what you can find from a short program to do a
1415      * malloc() and then dump the contents of the pages you got. By zeroing
1416      * the secrets at end of run (earlier if you can), you make sure the next
1417      * guy can't get the password/pass phrase."
1418      *
1419      * Right you are, Craig!
1420      */
1421     for (ctl = querylist; ctl; ctl = ctl->next)
1422         if (ctl->password)
1423           memset(ctl->password, '\0', strlen(ctl->password));
1424
1425 #if !defined(HAVE_ATEXIT) && !defined(HAVE_ON_EXIT)
1426     unlockit();
1427 #endif
1428
1429     exit(successes ? PS_SUCCESS : querystatus);
1430 }
1431
1432 /*
1433  * Sequence of protocols to try when autoprobing, most capable to least.
1434  */
1435 static const int autoprobe[] = 
1436 {
1437 #ifdef IMAP_ENABLE
1438     P_IMAP,
1439 #endif /* IMAP_ENABLE */
1440 #ifdef POP3_ENABLE
1441     P_POP3,
1442 #endif /* POP3_ENABLE */
1443 #ifdef POP2_ENABLE
1444     P_POP2
1445 #endif /* POP2_ENABLE */
1446 };
1447
1448 static int query_host(struct query *ctl)
1449 /* perform fetch transaction with single host */
1450 {
1451     int i, st;
1452
1453     /*
1454      * If we're syslogging the progress messages are automatically timestamped.
1455      * Force timestamping if we're going to a logfile.
1456      */
1457     if (outlevel >= O_VERBOSE || (run.logfile && outlevel > O_SILENT))
1458     {
1459         report(stdout, _("%s querying %s (protocol %s) at %s\n"),
1460                VERSION,
1461                ctl->server.pollname,
1462                showproto(ctl->server.protocol),
1463                rfc822timestamp());
1464     }
1465     switch (ctl->server.protocol) {
1466     case P_AUTO:
1467         for (i = 0; i < sizeof(autoprobe)/sizeof(autoprobe[0]); i++)
1468         {
1469             ctl->server.protocol = autoprobe[i];
1470             if ((st = query_host(ctl)) == PS_SUCCESS || st == PS_NOMAIL || st == PS_AUTHFAIL || st == PS_LOCKBUSY || st == PS_SMTP)
1471                 break;
1472         }
1473         ctl->server.protocol = P_AUTO;
1474         return(st);
1475     case P_POP2:
1476 #ifdef POP2_ENABLE
1477         return(doPOP2(ctl));
1478 #else
1479         report(stderr, _("POP2 support is not configured.\n"));
1480         return(PS_PROTOCOL);
1481 #endif /* POP2_ENABLE */
1482         break;
1483     case P_POP3:
1484     case P_APOP:
1485     case P_RPOP:
1486 #ifdef POP3_ENABLE
1487         return(doPOP3(ctl));
1488 #else
1489         report(stderr, _("POP3 support is not configured.\n"));
1490         return(PS_PROTOCOL);
1491 #endif /* POP3_ENABLE */
1492         break;
1493     case P_IMAP:
1494     case P_IMAP_K4:
1495     case P_IMAP_CRAM_MD5:
1496     case P_IMAP_LOGIN:
1497 #ifdef GSSAPI
1498     case P_IMAP_GSS:
1499 #endif /* GSSAPI */
1500 #ifdef IMAP_ENABLE
1501         return(doIMAP(ctl));
1502 #else
1503         report(stderr, _("IMAP support is not configured.\n"));
1504         return(PS_PROTOCOL);
1505 #endif /* IMAP_ENABLE */
1506     case P_ETRN:
1507 #ifndef ETRN_ENABLE
1508         report(stderr, _("ETRN support is not configured.\n"));
1509         return(PS_PROTOCOL);
1510 #else
1511 #ifdef HAVE_GETHOSTBYNAME
1512         return(doETRN(ctl));
1513 #else
1514         report(stderr, _("Cannot support ETRN without gethostbyname(2).\n"));
1515         return(PS_PROTOCOL);
1516 #endif /* HAVE_GETHOSTBYNAME */
1517 #endif /* ETRN_ENABLE */
1518     default:
1519         report(stderr, _("unsupported protocol selected.\n"));
1520         return(PS_PROTOCOL);
1521     }
1522 }
1523
1524 static void dump_params (struct runctl *runp,
1525                          struct query *querylist, flag implicit)
1526 /* display query parameters in English */
1527 {
1528     struct query *ctl;
1529
1530     if (runp->poll_interval)
1531         printf(_("Poll interval is %d seconds\n"), runp->poll_interval);
1532     if (runp->logfile)
1533         printf(_("Logfile is %s\n"), runp->logfile);
1534     if (strcmp(runp->idfile, IDFILE_NAME))
1535         printf(_("Idfile is %s\n"), runp->idfile);
1536 #if defined(HAVE_SYSLOG)
1537     if (runp->use_syslog)
1538         printf(_("Progress messages will be logged via syslog\n"));
1539 #endif
1540     if (runp->invisible)
1541         printf(_("Fetchmail will masquerade and will not generate Received\n"));
1542     if (runp->postmaster)
1543         printf(_("Fetchmail will forward misaddressed multidrop messages to %s.\n"),
1544                runp->postmaster);
1545
1546     if (!runp->bouncemail)
1547         printf(_("Fetchmail will direct error mail to the postmaster.\n"));
1548     else if (outlevel >= O_VERBOSE)
1549         printf(_("Fetchmail will direct error mail to the sender.\n"));
1550
1551     for (ctl = querylist; ctl; ctl = ctl->next)
1552     {
1553         if (!ctl->active || (implicit && ctl->server.skip))
1554             continue;
1555
1556         printf(_("Options for retrieving from %s@%s:\n"),
1557                ctl->remotename, visbuf(ctl->server.pollname));
1558
1559         if (ctl->server.via && (ctl->server.protocol != P_ETRN))
1560             printf(_("  Mail will be retrieved via %s\n"), ctl->server.via);
1561
1562         if (ctl->server.interval)
1563             printf(_("  Poll of this server will occur every %d intervals.\n"),
1564                    ctl->server.interval);
1565         if (ctl->server.truename)
1566             printf(_("  True name of server is %s.\n"), ctl->server.truename);
1567         if (ctl->server.skip || outlevel >= O_VERBOSE)
1568             printf(_("  This host %s be queried when no host is specified.\n"),
1569                    ctl->server.skip ? _("will not") : _("will"));
1570         /*
1571          * Don't poll for password when there is one or when using the ETRN
1572          * or IMAP-GSS protocol
1573          */
1574         /* ETRN, IMAP_GSS, and IMAP_K4 do not need a password, so skip this */
1575         if ( (ctl->server.protocol != P_ETRN)
1576 #ifdef GSSAPI
1577                                 && (ctl->server.protocol != P_IMAP_GSS)
1578 #endif /* GSSAPI */
1579                                 && (ctl->server.protocol != P_IMAP_K4) ) {
1580                 if (!ctl->password)
1581                         printf(_("  Password will be prompted for.\n"));
1582                 else if (outlevel >= O_VERBOSE)
1583                 {
1584                         if (ctl->server.protocol == P_APOP)
1585                                 printf(_("  APOP secret = \"%s\".\n"),
1586                                                         visbuf(ctl->password));
1587                         else if (ctl->server.protocol == P_RPOP)
1588                                 printf(_("  RPOP id = \"%s\".\n"),
1589                                                         visbuf(ctl->password));
1590                         else
1591                                 printf(_("  Password = \"%s\".\n"),
1592                                                         visbuf(ctl->password));
1593                 }
1594         }
1595
1596         if (ctl->server.protocol == P_POP3 
1597 #if INET6_ENABLE
1598             && ctl->server.service && !strcmp(ctl->server.service, KPOP_PORT)
1599 #else /* INET6_ENABLE */
1600             && ctl->server.port == KPOP_PORT
1601 #endif /* INET6_ENABLE */
1602             && (ctl->server.preauthenticate == A_KERBEROS_V4 ||
1603                 ctl->server.preauthenticate == A_KERBEROS_V5))
1604             printf(_("  Protocol is KPOP with Kerberos %s authentication"),
1605                    ctl->server.preauthenticate == A_KERBEROS_V5 ? "V" : "IV");
1606         else
1607             printf(_("  Protocol is %s"), showproto(ctl->server.protocol));
1608 #if INET6_ENABLE
1609         if (ctl->server.service)
1610             printf(_(" (using service %s)"), ctl->server.service);
1611         if (ctl->server.netsec)
1612             printf(_(" (using network security options %s)"), ctl->server.netsec);
1613 #else /* INET6_ENABLE */
1614         if (ctl->server.port)
1615             printf(_(" (using port %d)"), ctl->server.port);
1616 #endif /* INET6_ENABLE */
1617         else if (outlevel >= O_VERBOSE)
1618             printf(_(" (using default port)"));
1619         if (ctl->server.uidl && (ctl->server.protocol != P_ETRN))
1620             printf(_(" (forcing UIDL use)"));
1621         putchar('.');
1622         putchar('\n');
1623         if (ctl->server.preauthenticate == A_KERBEROS_V4)
1624             printf(_("  Kerberos V4 preauthentication enabled.\n"));
1625         else if (ctl->server.preauthenticate == A_KERBEROS_V5)
1626             printf(_("  Kerberos V5 preauthentication enabled.\n"));
1627         else if (ctl->server.preauthenticate == A_SSH)
1628             printf(_("  End-to-end encryption assumed.\n"));
1629 #ifdef  SSL_ENABLE
1630         if (ctl->use_ssl)
1631             printf("  SSL encrypted sessions enabled.\n");
1632 #endif
1633         if (ctl->server.timeout > 0)
1634             printf(_("  Server nonresponse timeout is %d seconds"), ctl->server.timeout);
1635         if (ctl->server.timeout ==  CLIENT_TIMEOUT)
1636             printf(_(" (default).\n"));
1637         else
1638             printf(".\n");
1639
1640         if (ctl->server.protocol != P_ETRN) {
1641                 if (!ctl->mailboxes->id)
1642                     printf(_("  Default mailbox selected.\n"));
1643                 else
1644                 {
1645                     struct idlist *idp;
1646
1647                     printf(_("  Selected mailboxes are:"));
1648                     for (idp = ctl->mailboxes; idp; idp = idp->next)
1649                         printf(" %s", idp->id);
1650                     printf("\n");
1651                 }
1652                 printf(_("  %s messages will be retrieved (--all %s).\n"),
1653                        ctl->fetchall ? _("All") : _("Only new"),
1654                        ctl->fetchall ? "on" : "off");
1655                 printf(_("  Fetched messages %s be kept on the server (--keep %s).\n"),
1656                        ctl->keep ? _("will") : _("will not"),
1657                        ctl->keep ? "on" : "off");
1658                 printf(_("  Old messages %s be flushed before message retrieval (--flush %s).\n"),
1659                        ctl->flush ? _("will") : _("will not"),
1660                        ctl->flush ? "on" : "off");
1661                 printf(_("  Rewrite of server-local addresses is %s (--norewrite %s).\n"),
1662                        ctl->rewrite ? _("enabled") : _("disabled"),
1663                        ctl->rewrite ? "off" : "on");
1664                 printf(_("  Carriage-return stripping is %s (stripcr %s).\n"),
1665                        ctl->stripcr ? _("enabled") : _("disabled"),
1666                        ctl->stripcr ? "on" : "off");
1667                 printf(_("  Carriage-return forcing is %s (forcecr %s).\n"),
1668                        ctl->forcecr ? _("enabled") : _("disabled"),
1669                        ctl->forcecr ? "on" : "off");
1670                 printf(_("  Interpretation of Content-Transfer-Encoding is %s (pass8bits %s).\n"),
1671                        ctl->pass8bits ? _("disabled") : _("enabled"),
1672                        ctl->pass8bits ? "on" : "off");
1673                 printf(_("  MIME decoding is %s (mimedecode %s).\n"),
1674                        ctl->mimedecode ? _("enabled") : _("disabled"),
1675                        ctl->mimedecode ? "on" : "off");
1676                 printf(_("  Nonempty Status lines will be %s (dropstatus %s)\n"),
1677                        ctl->dropstatus ? _("discarded") : _("kept"),
1678                        ctl->dropstatus ? "on" : "off");
1679                 if (NUM_NONZERO(ctl->limit))
1680                 {
1681                     if (NUM_NONZERO(ctl->limit))
1682                         printf(_("  Message size limit is %d octets (--limit %d).\n"), 
1683                                ctl->limit, ctl->limit);
1684                     else if (outlevel >= O_VERBOSE)
1685                         printf(_("  No message size limit (--limit 0).\n"));
1686                     if (run.poll_interval > 0)
1687                         printf(_("  Message size warning interval is %d seconds (--warnings %d).\n"), 
1688                                ctl->warnings, ctl->warnings);
1689                     else if (outlevel >= O_VERBOSE)
1690                         printf(_("  Size warnings on every poll (--warnings 0).\n"));
1691                 }
1692                 if (NUM_NONZERO(ctl->fetchlimit))
1693                     printf(_("  Received-message limit is %d (--fetchlimit %d).\n"),
1694                            ctl->fetchlimit, ctl->fetchlimit);
1695                 else if (outlevel >= O_VERBOSE)
1696                     printf(_("  No received-message limit (--fetchlimit 0).\n"));
1697                 if (NUM_NONZERO(ctl->batchlimit))
1698                     printf(_("  SMTP message batch limit is %d.\n"), ctl->batchlimit);
1699                 else if (outlevel >= O_VERBOSE)
1700                     printf(_("  No SMTP message batch limit (--batchlimit 0).\n"));
1701                 if (ctl->server.protocol == P_IMAP)
1702                 {
1703                     if (NUM_NONZERO(ctl->expunge))
1704                         printf(_("  Deletion interval between expunges forced to %d (--expunge %d).\n"), ctl->expunge, ctl->expunge);
1705                     else if (outlevel >= O_VERBOSE)
1706                         printf(_("  No forced expunges (--expunge 0).\n"));
1707                 }
1708         }
1709         if (ctl->bsmtp)
1710             printf(_("  Messages will be appended to %s as BSMTP\n"), visbuf(ctl->bsmtp));
1711         else if (ctl->mda && (ctl->server.protocol != P_ETRN))
1712             printf(_("  Messages will be delivered with \"%s\".\n"), visbuf(ctl->mda));
1713         else
1714         {
1715             struct idlist *idp;
1716
1717             printf(_("  Messages will be %cMTP-forwarded to:"), ctl->listener);
1718             for (idp = ctl->smtphunt; idp; idp = idp->next)
1719             {
1720                 printf(" %s", idp->id);
1721                 if (!idp->val.status.mark)
1722                     printf(_(" (default)"));
1723             }
1724             printf("\n");
1725             if (ctl->smtpaddress)
1726                 printf(_("  Host part of MAIL FROM line will be %s\n"),
1727                        ctl->smtpaddress);
1728         }
1729         if (ctl->server.protocol != P_ETRN)
1730         {
1731                 if (ctl->antispam != (struct idlist *)NULL)
1732                 {
1733                     struct idlist *idp;
1734
1735                     printf(_("  Recognized listener spam block responses are:"));
1736                     for (idp = ctl->antispam; idp; idp = idp->next)
1737                         printf(" %d", idp->val.status.num);
1738                     printf("\n");
1739                 }
1740                 else if (outlevel >= O_VERBOSE)
1741                     printf(_("  Spam-blocking disabled\n"));
1742         }
1743         if (ctl->preconnect)
1744             printf(_("  Server connection will be brought up with \"%s\".\n"),
1745                    visbuf(ctl->preconnect));
1746         else if (outlevel >= O_VERBOSE)
1747             printf(_("  No pre-connection command.\n"));
1748         if (ctl->postconnect)
1749             printf(_("  Server connection will be taken down with \"%s\".\n"),
1750                    visbuf(ctl->postconnect));
1751         else if (outlevel >= O_VERBOSE)
1752             printf(_("  No post-connection command.\n"));
1753         if (ctl->server.protocol != P_ETRN) {
1754                 if (!ctl->localnames)
1755                     printf(_("  No localnames declared for this host.\n"));
1756                 else
1757                 {
1758                     struct idlist *idp;
1759                     int count = 0;
1760
1761                     for (idp = ctl->localnames; idp; idp = idp->next)
1762                         ++count;
1763
1764                     if (count > 1 || ctl->wildcard)
1765                         printf(_("  Multi-drop mode: "));
1766                     else
1767                         printf(_("  Single-drop mode: "));
1768
1769                     printf(_("%d local name(s) recognized.\n"), count);
1770                     if (outlevel >= O_VERBOSE)
1771                     {
1772                         for (idp = ctl->localnames; idp; idp = idp->next)
1773                             if (idp->val.id2)
1774                                 printf("\t%s -> %s\n", idp->id, idp->val.id2);
1775                             else
1776                                 printf("\t%s\n", idp->id);
1777                         if (ctl->wildcard)
1778                             fputs("\t*\n", stdout);
1779                     }
1780
1781                     if (count > 1 || ctl->wildcard)
1782                     {
1783                         printf(_("  DNS lookup for multidrop addresses is %s.\n"),
1784                                ctl->server.dns ? _("enabled") : _("disabled"));
1785                         if (ctl->server.dns)
1786                         {
1787                             printf(_("  Server aliases will be compared with multidrop addresses by "));
1788                             if (ctl->server.checkalias)
1789                                 printf(_("IP address.\n"));
1790                             else
1791                                 printf(_("name.\n"));
1792                         }
1793                         if (ctl->server.envelope == STRING_DISABLED)
1794                             printf(_("  Envelope-address routing is disabled\n"));
1795                         else
1796                         {
1797                             printf(_("  Envelope header is assumed to be: %s\n"),
1798                                    ctl->server.envelope ? ctl->server.envelope:_("Received"));
1799                             if (ctl->server.envskip > 1 || outlevel >= O_VERBOSE)
1800                                 printf(_("  Number of envelope header to be parsed: %d\n"),
1801                                        ctl->server.envskip);
1802                             if (ctl->server.qvirtual)
1803                                 printf(_("  Prefix %s will be removed from user id\n"),
1804                                        ctl->server.qvirtual);
1805                             else if (outlevel >= O_VERBOSE) 
1806                                 printf(_("  No prefix stripping\n"));
1807                         }
1808
1809                         if (ctl->server.akalist)
1810                         {
1811                             struct idlist *idp;
1812
1813                             printf(_("  Predeclared mailserver aliases:"));
1814                             for (idp = ctl->server.akalist; idp; idp = idp->next)
1815                                 printf(" %s", idp->id);
1816                             putchar('\n');
1817                         }
1818                         if (ctl->server.localdomains)
1819                         {
1820                             struct idlist *idp;
1821
1822                             printf(_("  Local domains:"));
1823                             for (idp = ctl->server.localdomains; idp; idp = idp->next)
1824                                 printf(" %s", idp->id);
1825                             putchar('\n');
1826                         }
1827                     }
1828                 }
1829         }
1830 #if defined(linux) || defined(__FreeBSD__)
1831         if (ctl->server.interface)
1832             printf(_("  Connection must be through interface %s.\n"), ctl->server.interface);
1833         else if (outlevel >= O_VERBOSE)
1834             printf(_("  No interface requirement specified.\n"));
1835         if (ctl->server.monitor)
1836             printf(_("  Polling loop will monitor %s.\n"), ctl->server.monitor);
1837         else if (outlevel >= O_VERBOSE)
1838             printf(_("  No monitor interface specified.\n"));
1839 #endif
1840
1841         if (ctl->server.plugin)
1842             printf(_("  Server connections will be mode via plugin %s (--plugin %s).\n"), ctl->server.plugin, ctl->server.plugin);
1843         else if (outlevel >= O_VERBOSE)
1844             printf(_("  No plugin command specified.\n"));
1845         if (ctl->server.plugout)
1846             printf(_("  Listener connections will be mode via plugout %s (--plugout %s).\n"), ctl->server.plugout, ctl->server.plugout);
1847         else if (outlevel >= O_VERBOSE)
1848             printf(_("  No plugout command specified.\n"));
1849
1850         if (ctl->server.protocol > P_POP2 && (ctl->server.protocol != P_ETRN))
1851         {
1852             if (!ctl->oldsaved)
1853                 printf(_("  No UIDs saved from this host.\n"));
1854             else
1855             {
1856                 struct idlist *idp;
1857                 int count = 0;
1858
1859                 for (idp = ctl->oldsaved; idp; idp = idp->next)
1860                     ++count;
1861
1862                 printf(_("  %d UIDs saved.\n"), count);
1863                 if (outlevel >= O_VERBOSE)
1864                     for (idp = ctl->oldsaved; idp; idp = idp->next)
1865                         printf("\t%s\n", idp->id);
1866             }
1867         }
1868
1869         if (ctl->properties)
1870             printf(_("  Pass-through properties \"%s\".\n"),
1871                    visbuf(ctl->properties));
1872     }
1873 }
1874
1875 /* fetchmail.c ends here */