]> Pileus Git - ~andy/fetchmail/blob - fetchmail.c
Gunter's command-line fixes.
[~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
7 #include "config.h"
8
9 #include <stdio.h>
10 #include <ctype.h>
11 #if defined(STDC_HEADERS)
12 #include <stdlib.h>
13 #endif
14 #if defined(HAVE_UNISTD_H)
15 #include <unistd.h>
16 #endif
17 #if defined(HAVE_ALLOCA_H)
18 #include <alloca.h>
19 #else
20 #ifdef _AIX
21  #pragma alloca
22 #endif
23 #endif
24 #include <string.h>
25 #include <signal.h>
26 #if defined(HAVE_SYSLOG)
27 #include <syslog.h>
28 #endif
29 #include <pwd.h>
30 #include <errno.h>
31 #include <sys/time.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #ifdef HAVE_SYS_WAIT_H
35 #include <sys/wait.h>
36 #endif
37
38 #ifdef HAVE_GETHOSTBYNAME
39 #include <netdb.h>
40 #endif /* HAVE_GETHOSTBYNAME */
41
42 #include "fetchmail.h"
43 #include "tunable.h"
44 #include "smtp.h"
45 #include "getopt.h"
46 #include "netrc.h"
47
48 #ifndef ENETUNREACH
49 #define ENETUNREACH   128       /* Interactive doesn't know this */
50 #endif /* ENETUNREACH */
51
52 /* prototypes for internal functions */
53 static int load_params(int, char **, int);
54 static void dump_params (struct runctl *runp, struct query *, flag implicit);
55 static int query_host(struct query *);
56
57 /* controls the detail level of status/progress messages written to stderr */
58 int outlevel;           /* see the O_.* constants above */
59
60 /* miscellaneous global controls */
61 struct runctl run;      /* global controls for this run */
62 flag nodetach;          /* if TRUE, don't detach daemon process */
63 flag quitmode;          /* if --quit was set */
64 flag check_only;        /* if --probe was set */
65 flag versioninfo;       /* emit only version info */
66 char *user;             /* the name of the invoking user */
67 char *home;             /* invoking user's home directory */
68 char *fetchmailhost;    /* the name of the host running fetchmail */
69 char *program_name;     /* the name to prefix error messages with */
70 flag configdump;        /* dump control blocks for configurator */
71
72 #if NET_SECURITY
73 void *request = NULL;
74 int requestlen = 0;
75 #endif /* NET_SECURITY */
76
77 static char *lockfile;          /* name of lockfile */
78 static int querystatus;         /* status of query */
79 static int successes;           /* count number of successful polls */
80 static int lastsig;             /* last signal received */
81 static struct runctl cmd_run;   /* global options set from command line */
82
83 static void termhook();         /* forward declaration of exit hook */
84
85 /*
86  * The function of this variable is to reduce the size of the window during
87  * which two SIGALRMS in rapid succession can hose the code.  This is a
88  * bit of a kluge; the real right thing would use sigprocmask(), sigsuspend()
89  * and close the window entirely.  But since the interval isn't normally
90  * going to be less than one second this is not a big issue.
91  */
92 #if defined(__STDC__)
93 static sig_atomic_t     alarm_latch = FALSE;
94 #else
95 /* assume int can be written in one atomic operation on non ANSI-C systems */
96 static int              alarm_latch = FALSE;
97 #endif
98
99 RETSIGTYPE donothing(sig) int sig; {signal(sig, donothing); lastsig = sig;}
100 RETSIGTYPE gotsigalrm(sig) int sig; {signal(sig, donothing); lastsig = sig; alarm_latch = TRUE;}
101
102 #ifdef HAVE_ON_EXIT
103 static void unlockit(int n, void *p)
104 #else
105 static void unlockit(void)
106 #endif
107 /* must-do actions for exit (but we can't count on being able to do malloc) */
108 {
109     unlink(lockfile);
110 }
111
112 #ifdef __EMX__
113 /* Various EMX-specific definitions */
114 int itimerflag;
115 void itimerthread(void* dummy) {
116   if (outlevel == O_VERBOSE)
117     fprintf(stderr, "fetchmail: thread sleeping for %d sec.\n", poll_interval);
118   while(1) {
119     _sleep2(poll_interval*1000);
120     kill((getpid()), SIGALRM);
121   }
122 }
123 #endif
124
125 int main (int argc, char **argv)
126 {
127     int st, bkgd = FALSE;
128     int parsestatus, implicitmode = FALSE;
129     FILE        *lockfp;
130     struct query *ctl;
131     netrc_entry *netrc_list;
132     char *netrc_file, *tmpbuf;
133     pid_t pid;
134
135     envquery(argc, argv);
136
137 #define IDFILE_NAME     ".fetchids"
138     run.idfile = (char *) xmalloc(strlen(home)+strlen(IDFILE_NAME)+2);
139     strcpy(run.idfile, home);
140     strcat(run.idfile, "/");
141     strcat(run.idfile, IDFILE_NAME);
142   
143     outlevel = O_NORMAL;
144
145     if ((parsestatus = parsecmdline(argc,argv, &cmd_run, &cmd_opts)) < 0)
146         exit(PS_SYNTAX);
147
148     /* this hint to stdio should help messages come out in the right order */
149     setvbuf(stdout, NULL, _IOLBF, MSGBUFSIZE);
150
151     if (versioninfo)
152     {
153         printf("This is fetchmail release %s", RELEASE_ID);
154 #ifdef POP2_ENABLE
155         printf("+POP2");
156 #endif /* POP2_ENABLE */
157 #ifndef POP3_ENABLE
158         printf("-POP3");
159 #endif /* POP3_ENABLE */
160 #ifndef IMAP_ENABLE
161         printf("-IMAP");
162 #endif /* IMAP_ENABLE */
163 #ifdef RPA_ENABLE
164         printf("+RPA");
165 #endif /* RPA_ENABLE */
166 #ifndef ETRN_ENABLE
167         printf("-ETRN");
168 #endif /* ETRN_ENABLE */
169 #if OPIE
170         printf("+OPIE");
171 #endif /* OPIE */
172 #if INET6
173         printf("+INET6");
174 #endif /* INET6 */
175 #if NET_SECURITY
176         printf("+NETSEC");
177 #endif /* NET_SECURITY */
178         putchar('\n');
179
180         /* this is an attempt to help remote debugging */
181         system("uname -a");
182     }
183
184     /* avoid parsing the config file if all we're doing is killing a daemon */ 
185     if (!(quitmode && argc == 2))
186         implicitmode = load_params(argc, argv, optind);
187
188     /* set up to do lock protocol */
189 #define FETCHMAIL_PIDFILE       "fetchmail.pid"
190     tmpbuf = xmalloc(strlen(home) + strlen(FETCHMAIL_PIDFILE) + 3);
191     if (!getuid())
192         sprintf(tmpbuf, "%s/%s", PID_DIR, FETCHMAIL_PIDFILE);
193     else {
194         strcpy(tmpbuf, home);
195         strcat(tmpbuf, "/.");
196         strcat(tmpbuf, FETCHMAIL_PIDFILE);
197     }
198 #undef FETCHMAIL_PIDFILE
199
200     /* perhaps we just want to check options? */
201     if (versioninfo)
202     {
203         printf("Taking options from command line");
204         if (access(rcfile, 0))
205             printf("\n");
206         else
207             printf(" and %s\n", rcfile);
208         if (outlevel == O_VERBOSE)
209             printf("Lockfile at %s\n", tmpbuf);
210
211         if (querylist == NULL)
212             (void) fprintf(stderr,
213                 "No mailservers set up -- perhaps %s is missing?\n", rcfile);
214         else
215             dump_params(&run, querylist, implicitmode);
216         exit(0);
217     }
218
219     /* dump options as a Python dictionary, for configurator use */
220     if (configdump)
221     {
222         dump_config(&run, querylist);
223         exit(0);
224     }
225
226     /* check for another fetchmail running concurrently */
227     pid = -1;
228     if ((lockfile = (char *) malloc(strlen(tmpbuf) + 1)) == NULL)
229     {
230         fprintf(stderr,"fetchmail: cannot allocate memory for lock name.\n");
231         exit(PS_EXCLUDE);
232     }
233     else
234         (void) strcpy(lockfile, tmpbuf);
235     if ((lockfp = fopen(lockfile, "r")) != NULL )
236     {
237         bkgd = (fscanf(lockfp,"%d %d", &pid, &st) == 2);
238
239         if (kill(pid, 0) == -1) {
240             fprintf(stderr,"fetchmail: removing stale lockfile\n");
241             pid = -1;
242             bkgd = FALSE;
243             unlink(lockfile);
244         }
245         fclose(lockfp);
246     }
247
248     /* if no mail servers listed and nothing in background, we're done */
249     if (!(quitmode && argc == 2) && pid == -1 && querylist == NULL) {
250         (void)fputs("fetchmail: no mailservers have been specified.\n",stderr);
251         exit(PS_SYNTAX);
252     }
253
254     /* perhaps user asked us to kill the other fetchmail */
255     if (quitmode)
256     {
257         if (pid == -1) 
258         {
259             fprintf(stderr,"fetchmail: no other fetchmail is running\n");
260             if (argc == 2)
261                 exit(PS_EXCLUDE);
262         }
263         else if (kill(pid, SIGTERM) < 0)
264         {
265             fprintf(stderr,"fetchmail: error killing %s fetchmail at %d; bailing out.\n",
266                     bkgd ? "background" : "foreground", pid);
267             exit(PS_EXCLUDE);
268         }
269         else
270         {
271             fprintf(stderr,"fetchmail: %s fetchmail at %d killed.\n",
272                     bkgd ? "background" : "foreground", pid);
273             unlink(lockfile);
274             if (argc == 2)
275                 exit(0);
276             else
277                 pid = -1; 
278         }
279     }
280
281     /* another fetchmail is running -- wake it up or die */
282     if (pid != -1)
283     {
284         if (check_only)
285         {
286             fprintf(stderr,
287                  "fetchmail: can't check mail while another fetchmail to same host is running.\n");
288             return(PS_EXCLUDE);
289         }
290         else if (!implicitmode)
291         {
292             fprintf(stderr,
293                  "fetchmail: can't poll specified hosts with another fetchmail running at %d.\n",
294                  pid);
295                 return(PS_EXCLUDE);
296         }
297         else if (!bkgd)
298         {
299             fprintf(stderr,
300                  "fetchmail: another foreground fetchmail is running at %d.\n",
301                  pid);
302                 return(PS_EXCLUDE);
303         }
304         else if (argc > 1)
305         {
306             fprintf(stderr,
307                     "fetchmail: can't accept options while a background fetchmail is running.\n");
308             return(PS_EXCLUDE);
309         }
310         else if (kill(pid, SIGUSR1) == 0)
311         {
312             fprintf(stderr,
313                     "fetchmail: background fetchmail at %d awakened.\n",
314                     pid);
315             return(0);
316         }
317         else
318         {
319             /*
320              * Should never happen -- possible only if a background fetchmail
321              * croaks after the first kill probe above but before the
322              * SIGUSR1/SIGHUP transmission.
323              */
324             fprintf(stderr,
325                     "fetchmail: elder sibling at %d died mysteriously.\n",
326                     pid);
327             return(PS_UNDEFINED);
328         }
329     }
330
331     /* parse the ~/.netrc file (if present) for future password lookups. */
332     netrc_file = (char *) xmalloc (strlen (home) + 8);
333     strcpy (netrc_file, home);
334     strcat (netrc_file, "/.netrc");
335     netrc_list = parse_netrc(netrc_file);
336
337     /* pick up interactively any passwords we need but don't have */ 
338     for (ctl = querylist; ctl; ctl = ctl->next)
339         if (ctl->active && !(implicitmode && ctl->server.skip)&&!ctl->password)
340         {
341             if (ctl->server.preauthenticate == A_KERBEROS_V4 ||
342                 ctl->server.preauthenticate == A_KERBEROS_V5 ||
343                 ctl->server.protocol == P_IMAP_K4 ||
344                 ctl->server.protocol == P_IMAP_GSS)
345                 /* Server won't care what the password is, but there
346                    must be some non-null string here.  */
347                 ctl->password = ctl->remotename;
348             else
349             {
350                 /* look up the host and account in the .netrc file. */
351                 netrc_entry *p = search_netrc(netrc_list,ctl->server.pollname);
352                 while (p && strcmp(p->account, ctl->remotename))
353                     p = search_netrc(p->next, ctl->remotename);
354
355                 /* if we find a matching entry with a password, use it */
356                 if (p && p->password)
357                     ctl->password = xstrdup(p->password);
358             }
359
360             if (ctl->server.protocol != P_ETRN && ctl->server.protocol != P_IMAP_K4 && ctl->server.protocol != P_IMAP_GSS && !ctl->password)
361             {
362                 free(tmpbuf);
363 #define PASSWORD_PROMPT "Enter password for %s@%s: "
364                 tmpbuf = xmalloc(strlen(PASSWORD_PROMPT) +
365                                         strlen(ctl->remotename) +
366                                         strlen(ctl->server.pollname) + 1);
367                 (void) sprintf(tmpbuf, PASSWORD_PROMPT,
368                                ctl->remotename, ctl->server.pollname);
369                 ctl->password = xstrdup((char *)getpassword(tmpbuf));
370 #undef  PASSWORD_PROMPT
371             }
372         }
373
374     /* we don't need tmpbuf anymore */
375     free(tmpbuf);
376     tmpbuf = NULL;      /* firewall code */
377
378     /*
379      * Maybe time to go to demon mode...
380      */
381 #if defined(HAVE_SYSLOG)
382     if (run.use_syslog)
383     {
384         openlog(program_name, LOG_PID, LOG_MAIL);
385         error_init(-1);
386     }
387     else
388 #endif
389         error_init(run.poll_interval == 0 && !run.logfile);
390
391     if (run.poll_interval)
392     {
393         if (!nodetach)
394             daemonize(run.logfile, termhook);
395         error( 0, 0, "starting fetchmail %s daemon ", RELEASE_ID);
396
397         /*
398          * We'll set up a handler for these when we're sleeping,
399          * but ignore them otherwise so as not to interrupt a poll.
400          */
401         signal(SIGUSR1, SIG_IGN);
402         if (run.poll_interval && !getuid())
403             signal(SIGHUP, SIG_IGN);
404     }
405
406     /* beyond here we don't want more than one fetchmail running per user */
407     umask(0077);
408     signal(SIGABRT, termhook);
409     signal(SIGINT, termhook);
410     signal(SIGTERM, termhook);
411     signal(SIGALRM, termhook);
412     signal(SIGPIPE, termhook);
413     signal(SIGQUIT, termhook);
414
415     /* here's the exclusion lock */
416     if ((lockfp = fopen(lockfile,"w")) != NULL) {
417         fprintf(lockfp,"%d",getpid());
418         if (run.poll_interval)
419             fprintf(lockfp," %d", run.poll_interval);
420         fclose(lockfp);
421
422 #ifdef HAVE_ATEXIT
423         atexit(unlockit);
424 #endif
425 #ifdef HAVE_ON_EXIT
426         on_exit(unlockit, (char *)NULL);
427 #endif
428     }
429
430     /*
431      * Query all hosts. If there's only one, the error return will
432      * reflect the status of that transaction.
433      */
434     do {
435 #if defined(HAVE_RES_SEARCH) && defined(USE_TCPIP_FOR_DNS)
436         /*
437          * This was an efficiency hack that backfired.  The theory
438          * was that using TCP/IP for DNS queries would get us better
439          * reliability and shave off some per-UDP-packet costs.
440          * Unfortunately it interacted badly with diald, which effectively 
441          * filters out DNS queries over TCP/IP for reasons having to do
442          * with some obscure kernel problem involving bootstrapping of
443          * dynamically-addressed links.  I don't understand this mess
444          * and don't want to, so it's "See ya!" to this hack.
445          */
446         sethostent(TRUE);       /* use TCP/IP for mailserver queries */
447 #endif /* HAVE_RES_SEARCH */
448
449         batchcount = 0;
450         for (ctl = querylist; ctl; ctl = ctl->next)
451         {
452             if (ctl->active && !(implicitmode && ctl->server.skip))
453             {
454                 /* check skip interval first so that it counts all polls */
455                 if (run.poll_interval && ctl->server.interval) 
456                 {
457                     if (ctl->server.poll_count++ % ctl->server.interval) 
458                     {
459                         if (outlevel == O_VERBOSE)
460                             fprintf(stderr,
461                                     "fetchmail: interval not reached, not querying %s\n",
462                                     ctl->server.pollname);
463                         continue;
464                     }
465                 }
466
467 #if defined(linux) && !INET6
468                 /* interface_approve() does its own error logging */
469                 if (!interface_approve(&ctl->server))
470                     continue;
471 #endif /* defined(linux) && !INET6 */
472
473 #ifdef HAVE_GETHOSTBYNAME
474                 /*
475                  * This functions partly as a probe to make sure our
476                  * nameserver is still up.  The multidrop case
477                  * (especially) needs it.
478                  */
479                 if (ctl->server.preauthenticate==A_KERBEROS_V4 ||
480                     ctl->server.preauthenticate==A_KERBEROS_V5 ||
481                     MULTIDROP(ctl))
482                 {
483                     struct hostent      *namerec;
484
485                     /* compute the canonical name of the host */
486                     errno = 0;
487                     namerec = gethostbyname(ctl->server.queryname);
488                     if (namerec == (struct hostent *)NULL)
489                     {
490                         error(0, errno,
491                                 "skipping %s poll, ",
492                                 ctl->server.pollname);
493                         if (errno)
494                         {
495                             if (errno == ENETUNREACH)
496                                 break;  /* go to sleep */
497                         }
498 #ifdef HAVE_HERROR              /* NEXTSTEP doesn't */
499                         else
500                             herror("DNS error");
501 #endif /* HAVE_HERROR */
502                         continue;
503                     }
504                     else
505                     {
506                         free(ctl->server.truename);
507                         ctl->server.truename=xstrdup((char *)namerec->h_name);
508                     }
509                 }
510 #endif /* HAVE_GETHOSTBYNAME */
511
512                 querystatus = query_host(ctl);
513
514                 if (querystatus == PS_SUCCESS) {
515                     successes++;
516 #ifdef POP3_ENABLE
517                     if (!check_only)
518                       update_str_lists(ctl);
519 #endif  /* POP3_ENABLE */
520                 }
521 #if defined(linux) && !INET6
522                 if (ctl->server.monitor)
523                     {
524                         /* Allow some time for the link to quiesce.  One
525                          * second is usually sufficient, three is safe.
526                          * Note:  this delay is important - don't remove!
527                          */
528                         sleep(3);
529                         interface_note_activity(&ctl->server);
530                     }
531 #endif /* defined(linux) && !INET6 */
532             }
533         }
534
535 #if defined(HAVE_RES_SEARCH) && defined(USE_TCPIP_FOR_DNS)
536         endhostent();           /* release TCP/IP connection to nameserver */
537 #endif /* HAVE_RES_SEARCH */
538
539         /*
540          * Close all SMTP delivery sockets.  For optimum performance
541          * we'd like to hold them open til end of run, but (1) this
542          * loses if our poll interval is longer than the MTA's inactivity
543          * timeout, and (2) some MTAs (like smail) don't deliver after
544          * each message, but rather queue up mail and wait to actually
545          * deliver it until the input socket is closed. 
546          */
547         for (ctl = querylist; ctl; ctl = ctl->next)
548             if (ctl->smtp_socket != -1)
549             {
550                 SMTP_quit(ctl->smtp_socket);
551                 close(ctl->smtp_socket);
552                 ctl->smtp_socket = -1;
553             }
554
555         /*
556          * OK, we've polled.  Now sleep.
557          */
558         if (run.poll_interval)
559         {
560             if (outlevel == O_VERBOSE)
561             {
562                 time_t  now;
563
564                 time(&now);
565                 fprintf(stderr, "fetchmail: sleeping at %s", ctime(&now));
566             }
567
568             /*
569              * With this simple hack, we make it possible for a foreground 
570              * fetchmail to wake up one in daemon mode.  What we want is the
571              * side effect of interrupting any sleep that may be going on,
572              * forcing fetchmail to re-poll its hosts.  The second line is
573              * for people who think all system daemons wake up on SIGHUP.
574              */
575             signal(SIGUSR1, donothing);
576             if (!getuid())
577                 signal(SIGHUP, donothing);
578
579             /*
580              * We can't use sleep(3) here because we need an alarm(3)
581              * equivalent in order to implement server nonresponse timeout.
582              * We'll just assume setitimer(2) is available since fetchmail
583              * has to have a BSDoid socket layer to work at all.
584              */
585             {
586 #ifndef __EMX__
587 #ifdef SLEEP_WITH_ALARM         /* not normally on */
588                 /* 
589                  * This code stopped working under glibc-2, apparently due
590                  * to the change in signal(2) semantics.  (The siginterrupt
591                  * line, added later, should fix this problem.) John Stracke
592                  * <francis@netscape.com> wrote:
593                  *
594                  * The problem seems to be that, after hitting the interval
595                  * timer while talking to the server, the process no longer
596                  * responds to SIGALRM.  I put in printf()s to see when it
597                  * reached the pause() for the poll interval, and I checked
598                  * the return from setitimer(), and everything seemed to be
599                  * working fine, except that the pause() just ignored SIGALRM.
600                  * I thought maybe the itimer wasn't being fired, so I hit
601                  * it with a SIGALRM from the command line, and it ignored
602                  * that, too.  SIGUSR1 woke it up just fine, and it proceeded
603                  * to repoll--but, when the dummy server didn't respond, it
604                  * never timed out, and SIGALRM wouldn't make it.
605                  *
606                  * (continued below...)
607                  */
608                 struct itimerval ntimeout;
609
610                 ntimeout.it_interval.tv_sec = ntimeout.it_interval.tv_usec = 0;
611                 ntimeout.it_value.tv_sec  = poll_interval;
612                 ntimeout.it_value.tv_usec = 0;
613
614                 siginterrupt(SIGALRM, 1);
615                 alarm_latch = FALSE;
616                 signal(SIGALRM, gotsigalrm);    /* first trap signals */
617                 setitimer(ITIMER_REAL,&ntimeout,NULL);  /* then start timer */
618                 /* there is a very small window between the next two lines */
619                 if (!alarm_latch)
620                     pause();
621                 signal(SIGALRM, SIG_IGN);
622 #else
623                 /* 
624                  * So the workaround I used is to make it sleep by using
625                  * select() instead of setitimer()/pause().  select() is
626                  * perfectly happy being called with a timeout and
627                  * no file descriptors; it just sleeps until it hits the
628                  * timeout.  The only concern I had was that it might
629                  * implement its timeout with SIGALRM--there are some
630                  * Unices where this is done, because select() is a library
631                  * function--but apparently not.
632                  */
633                 struct timeval timeout;
634
635                 timeout.tv_sec = run.poll_interval;
636                 timeout.tv_usec = 0;
637                 lastsig = 0;
638                 select(0,0,0,0, &timeout);
639 #endif
640 #else /* EMX */
641                 alarm_latch = FALSE;
642                 signal(SIGALRM, gotsigalrm);
643                 _beginthread(itimerthread, NULL, 32768, NULL);
644                 /* see similar code above */
645                 if (!alarm_latch)
646                     pause();
647                 signal(SIGALRM, SIG_IGN);
648 #endif /* ! EMX */
649                 if (lastsig == SIGUSR1
650                         || ((run.poll_interval && !getuid()) && lastsig == SIGHUP))
651                 {
652 #ifdef SYS_SIGLIST_DECLARED
653                     error(0, 0, "awakened by %s", sys_siglist[lastsig]);
654 #else
655                     error(0, 0, "awakened by signal %d", lastsig);
656 #endif
657                 }
658             }
659
660             /* now lock out interrupts again */
661             signal(SIGUSR1, SIG_IGN);
662             if (!getuid())
663                 signal(SIGHUP, SIG_IGN);
664
665             if (outlevel == O_VERBOSE)
666             {
667                 time_t  now;
668
669                 time(&now);
670                 fprintf(stderr, "fetchmail: awakened at %s", ctime(&now));
671             }
672         }
673     } while
674         (run.poll_interval);
675
676     if (outlevel == O_VERBOSE)
677         fprintf(stderr,"fetchmail: normal termination, status %d\n",
678                 successes ? PS_SUCCESS : querystatus);
679
680     termhook(0);
681     exit(successes ? PS_SUCCESS : querystatus);
682 }
683
684 static int load_params(int argc, char **argv, int optind)
685 {
686     int implicitmode, st;
687     struct passwd *pw;
688     struct query def_opts, *ctl;
689
690     memset(&def_opts, '\0', sizeof(struct query));
691     def_opts.smtp_socket = -1;
692     def_opts.smtpaddress = (char *)0;
693     def_opts.antispam = 571;
694
695     def_opts.server.protocol = P_AUTO;
696     def_opts.server.timeout = CLIENT_TIMEOUT;
697     def_opts.remotename = user;
698     def_opts.expunge = 1;
699
700     /* this builds the host list */
701     if (prc_parse_file(rcfile, !versioninfo) != 0)
702         exit(PS_SYNTAX);
703
704     if ((implicitmode = (optind >= argc)))
705     {
706         for (ctl = querylist; ctl; ctl = ctl->next)
707             ctl->active = TRUE;
708     }
709     else
710         for (; optind < argc; optind++) 
711         {
712             /*
713              * If hostname corresponds to a host known from the rc file,
714              * simply declare it active.  Otherwise synthesize a host
715              * record from command line and defaults
716              */
717             for (ctl = querylist; ctl; ctl = ctl->next)
718                 if (!strcmp(ctl->server.pollname, argv[optind])
719                         || str_in_list(&ctl->server.akalist, argv[optind], TRUE))
720                     goto foundit;
721
722             /*
723              * Allocate and link record without copying in command-line args;
724              * we'll do that with the optmerge call later on.
725              */
726             ctl = hostalloc((struct query *)NULL);
727             ctl->server.via =
728                 ctl->server.pollname = xstrdup(argv[optind]);
729
730         foundit:
731             ctl->active = TRUE;
732         }
733
734     /*
735      * If there's a defaults record, merge it and lose it.
736      */ 
737     if (querylist && strcmp(querylist->server.pollname, "defaults") == 0)
738     {
739         for (ctl = querylist->next; ctl; ctl = ctl->next)
740             optmerge(ctl, querylist);
741         querylist = querylist->next;
742     }
743
744     /* don't allow a defaults record after the first */
745     for (ctl = querylist; ctl; ctl = ctl->next)
746         if (ctl != querylist && strcmp(ctl->server.pollname, "defaults") == 0)
747             exit(PS_SYNTAX);
748
749     /* merge in wired defaults, do sanity checks and prepare internal fields */
750     for (ctl = querylist; ctl; ctl = ctl->next)
751     {
752         if (configdump || (ctl->active && !(implicitmode && ctl->server.skip)))
753         {
754             /* merge in defaults */
755             optmerge(ctl, &def_opts);
756
757             /* make sure we have a nonempty host list to forward to */
758             if (!ctl->smtphunt)
759             {
760                 save_str(&ctl->smtphunt, fetchmailhost, FALSE);
761                 /* for non ETRN try to deliver mails to localhost if
762                  * fetchmailhost fails
763                  */
764                 if (ctl->server.protocol != P_ETRN) {
765                     save_str(&ctl->smtphunt, "localhost", FALSE);
766                 }
767             }
768
769             /* keep lusers from shooting themselves in the foot :-) */
770             if (run.poll_interval && ctl->limit)
771             {
772                 fprintf(stderr,"fetchmail: you'd never see large messages!\n");
773                 exit(PS_SYNTAX);
774             }
775
776             /* if `user' doesn't name a real local user, try to run as root */
777             if ((pw = getpwnam(user)) == (struct passwd *)NULL)
778                 ctl->uid = 0;
779             else
780                 ctl->uid = pw->pw_uid;  /* for local delivery via MDA */
781             if (!ctl->localnames)       /* for local delivery via SMTP */
782                 save_str_pair(&ctl->localnames, user, NULL);
783
784             /* this code enables flags to be turned off */
785 #define DEFAULT(flag, dflt)     if (flag == FLAG_TRUE)\
786                                         flag = TRUE;\
787                                 else if (flag == FLAG_FALSE)\
788                                         flag = FALSE;\
789                                 else\
790                                         flag = (dflt)
791             DEFAULT(ctl->keep, FALSE);
792             DEFAULT(ctl->fetchall, FALSE);
793             DEFAULT(ctl->flush, FALSE);
794             DEFAULT(ctl->rewrite, TRUE);
795             DEFAULT(ctl->stripcr, (ctl->mda != (char *)NULL)); 
796             DEFAULT(ctl->forcecr, FALSE);
797             DEFAULT(ctl->pass8bits, FALSE);
798             DEFAULT(ctl->dropstatus, FALSE);
799             DEFAULT(ctl->mimedecode, FALSE);
800             DEFAULT(ctl->server.dns, TRUE);
801             DEFAULT(ctl->server.uidl, FALSE);
802 #undef DEFAULT
803
804 #if !defined(HAVE_GETHOSTBYNAME) || !defined(HAVE_RES_SEARCH)
805             /* can't handle multidrop mailboxes unless we can do DNS lookups */
806             if (ctl->localnames && ctl->localnames->next && ctl->server.dns)
807             {
808                 ctl->server.dns = FALSE;
809                 fprintf(stderr, "fetchmail: warning: no DNS available to check multidrop fetches from %s\n", ctl->server.pollname);
810             }
811 #endif /* !HAVE_GETHOSTBYNAME || !HAVE_RES_SEARCH */
812
813             /*
814              *
815              * Compute the true name of the mailserver host.  
816              * There are two clashing cases here:
817              *
818              * (1) The poll name is a label, possibly on one of several
819              *     poll configurations for the same host.  In this case 
820              *     the `via' option will be present and give the true name.
821              *
822              * (2) The poll name is the true one, the via name is 
823              *     localhost.   This is going to be typical for ssh-using
824              *     configurations.
825              *
826              * We're going to assume the via name is true unless it's
827              * localhost.
828              *
829              * Each poll cycle, if we've got DNS, we'll try to canonicalize
830              * the name.  This will function as a probe to ensure the
831              * host's nameserver is up.
832              */
833             if (ctl->server.via && strcmp(ctl->server.via, "localhost"))
834                 ctl->server.queryname = xstrdup(ctl->server.via);
835             else
836                 ctl->server.queryname = xstrdup(ctl->server.pollname);
837             ctl->server.truename = xstrdup(ctl->server.queryname);
838
839             /* if no folders were specified, set up the null one as default */
840             if (!ctl->mailboxes)
841                 save_str(&ctl->mailboxes, (char *)NULL, 0);
842
843             /* maybe user overrode timeout on command line? */
844             if (ctl->server.timeout == -1)      
845                 ctl->server.timeout = CLIENT_TIMEOUT;
846
847 #if !INET6
848             /* sanity checks */
849             if (ctl->server.port < 0)
850             {
851                 (void) fprintf(stderr,
852                                "%s configuration invalid, port number cannot be negative",
853                                ctl->server.pollname);
854                 exit(PS_SYNTAX);
855             }
856             if (ctl->server.protocol == P_RPOP && ctl->server.port >= 1024)
857             {
858                 (void) fprintf(stderr,
859                                "%s configuration invalid, RPOP requires a privileged port",
860                                ctl->server.pollname);
861                 exit(PS_SYNTAX);
862             }
863 #endif /* !INET6 */
864         }
865     }
866
867     /* initialize UID handling */
868     if (!versioninfo && (st = prc_filecheck(run.idfile, !versioninfo)) != 0)
869         exit(st);
870 #ifdef POP3_ENABLE
871     else
872         initialize_saved_lists(querylist, run.idfile);
873 #endif /* POP3_ENABLE */
874
875     /* here's where we override globals */
876     if (cmd_run.logfile)
877         run.logfile = cmd_run.logfile;
878     if (cmd_run.idfile)
879         run.logfile = cmd_run.idfile;
880     if (cmd_run.poll_interval >= 0)
881         run.poll_interval = cmd_run.poll_interval;
882     if (cmd_run.invisible)
883         run.invisible = cmd_run.invisible;
884     if (cmd_run.use_syslog)
885         run.use_syslog = cmd_run.use_syslog;
886
887     /* check and daemon options are not compatible */
888     if (check_only && run.poll_interval)
889         run.poll_interval = 0;
890     return(implicitmode);
891 }
892
893 void termhook(int sig)
894 /* to be executed on normal or signal-induced termination */
895 {
896     struct query        *ctl;
897
898     /*
899      * Sending SMTP QUIT on signal is theoretically nice, but led to a 
900      * subtle bug.  If fetchmail was terminated by signal while it was 
901      * shipping message text, it would hang forever waiting for a
902      * command acknowledge.  In theory we could enable the QUIT
903      * only outside of the message send.  In practice, we don't
904      * care.  All mailservers hang up on a dropped TCP/IP connection
905      * anyway.
906      */
907
908     if (sig != 0)
909         error(0, 0, "terminated with signal %d", sig);
910     else
911         /* terminate all SMTP connections cleanly */
912         for (ctl = querylist; ctl; ctl = ctl->next)
913             if (ctl->smtp_socket != -1)
914                 SMTP_quit(ctl->smtp_socket);
915
916 #ifdef POP3_ENABLE
917     if (!check_only)
918         write_saved_lists(querylist, run.idfile);
919 #endif /* POP3_ENABLE */
920
921     /* 
922      * Craig Metz, the RFC1938 one-time-password guy, points out:
923      * "Remember that most kernels don't zero pages before handing them to the
924      * next process and many kernels share pages between user and kernel space.
925      * You'd be very surprised what you can find from a short program to do a
926      * malloc() and then dump the contents of the pages you got. By zeroing
927      * the secrets at end of run (earlier if you can), you make sure the next
928      * guy can't get the password/pass phrase."
929      *
930      * Right you are, Craig!
931      */
932     for (ctl = querylist; ctl; ctl = ctl->next)
933         if (ctl->password)
934           memset(ctl->password, '\0', strlen(ctl->password));
935
936 #if !defined(HAVE_ATEXIT) && !defined(HAVE_ON_EXIT)
937     unlockit();
938 #endif
939
940     exit(successes ? PS_SUCCESS : querystatus);
941 }
942
943 /*
944  * Sequence of protocols to try when autoprobing, most capable to least.
945  */
946 static const int autoprobe[] = 
947 {
948 #ifdef IMAP_ENABLE
949     P_IMAP,
950 #endif /* IMAP_ENABLE */
951 #ifdef POP3_ENABLE
952     P_POP3,
953 #endif /* POP3_ENABLE */
954 #ifdef POP2_ENABLE
955     P_POP2
956 #endif /* POP2_ENABLE */
957 };
958
959 static int query_host(struct query *ctl)
960 /* perform fetch transaction with single host */
961 {
962     int i, st;
963
964     if (outlevel == O_VERBOSE)
965     {
966         time_t now;
967
968         time(&now);
969         fprintf(stderr, "fetchmail: %s querying %s (protocol %s) at %s",
970             RELEASE_ID,
971             ctl->server.pollname, showproto(ctl->server.protocol), ctime(&now));
972     }
973     switch (ctl->server.protocol) {
974     case P_AUTO:
975         for (i = 0; i < sizeof(autoprobe)/sizeof(autoprobe[0]); i++)
976         {
977             ctl->server.protocol = autoprobe[i];
978             if ((st = query_host(ctl)) == PS_SUCCESS || st == PS_NOMAIL || st == PS_AUTHFAIL || st == PS_LOCKBUSY || st == PS_SMTP)
979                 break;
980         }
981         ctl->server.protocol = P_AUTO;
982         return(st);
983         break;
984     case P_POP2:
985 #ifdef POP2_ENABLE
986         return(doPOP2(ctl));
987 #else
988         fprintf(stderr, "POP2 support is not configured.\n");
989         return(PS_PROTOCOL);
990 #endif /* POP2_ENABLE */
991         break;
992     case P_POP3:
993     case P_APOP:
994     case P_RPOP:
995 #ifdef POP3_ENABLE
996         return(doPOP3(ctl));
997 #else
998         fprintf(stderr, "POP3 support is not configured.\n");
999         return(PS_PROTOCOL);
1000 #endif /* POP3_ENABLE */
1001         break;
1002     case P_IMAP:
1003     case P_IMAP_K4:
1004     case P_IMAP_GSS:
1005 #ifdef IMAP_ENABLE
1006         return(doIMAP(ctl));
1007 #else
1008         fprintf(stderr, "IMAP support is not configured.\n");
1009         return(PS_PROTOCOL);
1010 #endif /* IMAP_ENABLE */
1011         break;
1012     case P_ETRN:
1013 #ifndef ETRN_ENABLE
1014         fprintf(stderr, "ETRN support is not configured.\n");
1015         return(PS_PROTOCOL);
1016 #else
1017 #ifdef HAVE_GETHOSTBYNAME
1018         return(doETRN(ctl));
1019 #else
1020         fprintf(stderr, "Cannot support ETRN without gethostbyname(2).\n");
1021         return(PS_PROTOCOL);
1022 #endif /* HAVE_GETHOSTBYNAME */
1023 #endif /* ETRN_ENABLE */
1024     default:
1025         error(0, 0, "unsupported protocol selected.");
1026         return(PS_PROTOCOL);
1027     }
1028 }
1029
1030 void dump_params (struct runctl *runp, struct query *querylist, flag implicit)
1031 /* display query parameters in English */
1032 {
1033     struct query *ctl;
1034
1035     if (runp->poll_interval)
1036         printf("Poll interval is %d seconds\n", runp->poll_interval);
1037     if (runp->logfile)
1038         printf("Logfile is %s\n", runp->logfile);
1039     if (strcmp(runp->idfile, IDFILE_NAME))
1040         printf("Idfile is %s\n", runp->idfile);
1041 #if defined(HAVE_SYSLOG)
1042     if (runp->use_syslog)
1043         printf("Progress messages will be logged via syslog\n");
1044 #endif
1045     if (runp->invisible)
1046         printf("Fetchmail will masquerade and will not generate Received\n");
1047
1048     for (ctl = querylist; ctl; ctl = ctl->next)
1049     {
1050         if (!ctl->active || (implicit && ctl->server.skip))
1051             continue;
1052
1053         printf("Options for retrieving from %s@%s:\n",
1054                ctl->remotename, visbuf(ctl->server.pollname));
1055
1056         if (ctl->server.via)
1057             printf("  Mail will be retrieved via %s\n", ctl->server.via);
1058
1059         if (ctl->server.interval)
1060             printf("  Poll of this server will occur every %d intervals.\n",
1061                    ctl->server.interval);
1062         if (ctl->server.truename)
1063             printf("  True name of server is %s.\n", ctl->server.truename);
1064         if (ctl->server.skip || outlevel == O_VERBOSE)
1065             printf("  This host will%s be queried when no host is specified.\n",
1066                    ctl->server.skip ? " not" : "");
1067         if (!ctl->password)
1068             printf("  Password will be prompted for.\n");
1069         else if (outlevel == O_VERBOSE)
1070             if (ctl->server.protocol == P_APOP)
1071                 printf("  APOP secret = '%s'.\n", visbuf(ctl->password));
1072             else if (ctl->server.protocol == P_RPOP)
1073                 printf("  RPOP id = '%s'.\n", visbuf(ctl->password));
1074             else
1075                 printf("  Password = '%s'.\n", visbuf(ctl->password));
1076         if (ctl->server.protocol == P_POP3 
1077 #if INET6
1078             && !strcmp(ctl->server.service, KPOP_PORT)
1079 #else /* INET6 */
1080             && ctl->server.port == KPOP_PORT
1081 #endif /* INET6 */
1082             && (ctl->server.preauthenticate == A_KERBEROS_V4 ||
1083                 ctl->server.preauthenticate == A_KERBEROS_V5))
1084             printf("  Protocol is KPOP");
1085         else
1086             printf("  Protocol is %s", showproto(ctl->server.protocol));
1087 #if INET6
1088         if (ctl->server.service)
1089             printf(" (using service %s)", ctl->server.service);
1090         if (ctl->server.netsec)
1091             printf(" (using network security options %s)", ctl->server.netsec);
1092 #else /* INET6 */
1093         if (ctl->server.port)
1094             printf(" (using port %d)", ctl->server.port);
1095 #endif /* INET6 */
1096         else if (outlevel == O_VERBOSE)
1097             printf(" (using default port)");
1098         if (ctl->server.uidl)
1099             printf(" (forcing UIDL use)");
1100         putchar('.');
1101         putchar('\n');
1102         if (ctl->server.preauthenticate == A_KERBEROS_V4)
1103             printf("  Kerberos V4 preauthentication enabled.\n");
1104         if (ctl->server.preauthenticate == A_KERBEROS_V5)
1105             printf("  Kerberos V5 preauthentication enabled.\n");
1106         if (ctl->server.timeout > 0)
1107             printf("  Server nonresponse timeout is %d seconds", ctl->server.timeout);
1108         if (ctl->server.timeout ==  CLIENT_TIMEOUT)
1109             printf(" (default).\n");
1110         else
1111             printf(".\n");
1112
1113         if (!ctl->mailboxes->id)
1114             printf("  Default mailbox selected.\n");
1115         else
1116         {
1117             struct idlist *idp;
1118
1119             printf("  Selected mailboxes are:");
1120             for (idp = ctl->mailboxes; idp; idp = idp->next)
1121                 printf(" %s", idp->id);
1122             printf("\n");
1123         }
1124         printf("  %s messages will be retrieved (--all %s).\n",
1125                ctl->fetchall ? "All" : "Only new",
1126                ctl->fetchall ? "on" : "off");
1127         printf("  Fetched messages will%s be kept on the server (--keep %s).\n",
1128                ctl->keep ? "" : " not",
1129                ctl->keep ? "on" : "off");
1130         printf("  Old messages will%s be flushed before message retrieval (--flush %s).\n",
1131                ctl->flush ? "" : " not",
1132                ctl->flush ? "on" : "off");
1133         printf("  Rewrite of server-local addresses is %sabled (--norewrite %s).\n",
1134                ctl->rewrite ? "en" : "dis",
1135                ctl->rewrite ? "off" : "on");
1136         printf("  Carriage-return stripping is %sabled (stripcr %s).\n",
1137                ctl->stripcr ? "en" : "dis",
1138                ctl->stripcr ? "on" : "off");
1139         printf("  Carriage-return forcing is %sabled (forcecr %s).\n",
1140                ctl->forcecr ? "en" : "dis",
1141                ctl->forcecr ? "on" : "off");
1142         printf("  Interpretation of Content-Transfer-Encoding is %sabled (pass8bits %s).\n",
1143                ctl->pass8bits ? "en" : "dis",
1144                ctl->pass8bits ? "on" : "off");
1145         printf("  MIME decoding is %sabled (mimedecode %s).\n",
1146                ctl->mimedecode ? "en" : "dis",
1147                ctl->mimedecode ? "on" : "off");
1148         printf("  Nonempty Status lines will be %s (dropstatus %s)\n",
1149                ctl->dropstatus ? "discarded" : "kept",
1150                ctl->dropstatus ? "on" : "off");
1151         if (NUM_NONZERO(ctl->limit))
1152             printf("  Message size limit is %d bytes (--limit %d).\n", 
1153                    ctl->limit, ctl->limit);
1154         else if (outlevel == O_VERBOSE)
1155             printf("  No message size limit (--limit 0).\n");
1156         if (NUM_NONZERO(ctl->fetchlimit))
1157             printf("  Received-message limit is %d (--fetchlimit %d).\n",
1158                    ctl->fetchlimit, ctl->fetchlimit);
1159         else if (outlevel == O_VERBOSE)
1160             printf("  No received-message limit (--fetchlimit 0).\n");
1161         if (NUM_NONZERO(ctl->batchlimit))
1162             printf("  SMTP message batch limit is %d.\n", ctl->batchlimit);
1163         else if (outlevel == O_VERBOSE)
1164             printf("  No SMTP message batch limit (--batchlimit 0).\n");
1165         if (ctl->server.protocol == P_IMAP)
1166             if (NUM_NONZERO(ctl->expunge))
1167                 printf("  Deletion interval between expunges is %d (--expunge %d).\n", ctl->expunge, ctl->expunge);
1168             else if (outlevel == O_VERBOSE)
1169                 printf("  No expunges (--expunge 0).\n");
1170         if (ctl->mda)
1171             printf("  Messages will be delivered with '%s.'\n", visbuf(ctl->mda));
1172         else
1173         {
1174             struct idlist *idp;
1175
1176             printf("  Messages will be SMTP-forwarded to:");
1177             for (idp = ctl->smtphunt; idp; idp = idp->next)
1178             {
1179                 printf(" %s", idp->id);
1180                 if (!idp->val.status.mark)
1181                     printf(" (default)");
1182             }
1183             printf("\n");
1184             if (ctl->smtpaddress)
1185                 printf("  Host part of MAIL FROM line will be %s\n",
1186                        ctl->smtpaddress);
1187         }
1188         if (ctl->antispam != -1)
1189             printf("  Listener SMTP reponse %d will be treated as a spam block\n",
1190                    ctl->antispam);
1191         else if (outlevel == O_VERBOSE)
1192             printf("  Spam-blocking disabled\n");
1193         if (ctl->preconnect)
1194             printf("  Server connection will be brought up with '%s.'\n",
1195                    visbuf(ctl->preconnect));
1196         else if (outlevel == O_VERBOSE)
1197             printf("  No pre-connection command.\n");
1198         if (ctl->postconnect)
1199             printf("  Server connection will be taken down with '%s.'\n",
1200                    visbuf(ctl->postconnect));
1201         else if (outlevel == O_VERBOSE)
1202             printf("  No post-connection command.\n");
1203         if (!ctl->localnames)
1204             printf("  No localnames declared for this host.\n");
1205         else
1206         {
1207             struct idlist *idp;
1208             int count = 0;
1209
1210             for (idp = ctl->localnames; idp; idp = idp->next)
1211                 ++count;
1212
1213             if (count > 1 || ctl->wildcard)
1214                 printf("  Multi-drop mode: ");
1215             else
1216                 printf("  Single-drop mode: ");
1217
1218             printf("%d local name(s) recognized.\n", count);
1219             if (outlevel == O_VERBOSE)
1220             {
1221                 for (idp = ctl->localnames; idp; idp = idp->next)
1222                     if (idp->val.id2)
1223                         printf("\t%s -> %s\n", idp->id, idp->val.id2);
1224                     else
1225                         printf("\t%s\n", idp->id);
1226                 if (ctl->wildcard)
1227                     fputs("*\n", stdout);
1228             }
1229
1230             if (count > 1 || ctl->wildcard)
1231             {
1232                 printf("  DNS lookup for multidrop addresses is %sabled.\n",
1233                        ctl->server.dns ? "en" : "dis");
1234
1235                 if (ctl->server.envelope == STRING_DISABLED)
1236                     printf("  Envelope-address routing is disabled\n");
1237                 else
1238                 {
1239                     printf("  Envelope header is assumed to be: %s\n",
1240                            ctl->server.envelope ? ctl->server.envelope:"Received");
1241                     if (ctl->server.envskip > 1 || outlevel >= O_VERBOSE)
1242                         printf("  Number of envelope header to be parsed: %d\n",
1243                                ctl->server.envskip);
1244                     if (ctl->server.qvirtual)
1245                         printf("  Prefix %s will be removed from user id\n",
1246                                ctl->server.qvirtual);
1247                     else if (outlevel >= O_VERBOSE) 
1248                         printf("  No prefix stripping\n");
1249                 }
1250
1251                 if (ctl->server.akalist)
1252                 {
1253                     struct idlist *idp;
1254
1255                     printf("  Predeclared mailserver aliases:");
1256                     for (idp = ctl->server.akalist; idp; idp = idp->next)
1257                         printf(" %s", idp->id);
1258                     putchar('\n');
1259                 }
1260                 if (ctl->server.localdomains)
1261                 {
1262                     struct idlist *idp;
1263
1264                     printf("  Local domains:");
1265                     for (idp = ctl->server.localdomains; idp; idp = idp->next)
1266                         printf(" %s", idp->id);
1267                     putchar('\n');
1268                 }
1269             }
1270         }
1271 #ifdef  linux
1272         if (ctl->server.interface)
1273             printf("  Connection must be through interface %s.\n", ctl->server.interface);
1274         else if (outlevel == O_VERBOSE)
1275             printf("  No interface requirement specified.\n");
1276         if (ctl->server.monitor)
1277             printf("  Polling loop will monitor %s.\n", ctl->server.monitor);
1278         else if (outlevel == O_VERBOSE)
1279             printf("  No monitor interface specified.\n");
1280 #endif
1281
1282         if (ctl->server.protocol > P_POP2)
1283             if (!ctl->oldsaved)
1284                 printf("  No UIDs saved from this host.\n");
1285             else
1286             {
1287                 struct idlist *idp;
1288                 int count = 0;
1289
1290                 for (idp = ctl->oldsaved; idp; idp = idp->next)
1291                     ++count;
1292
1293                 printf("  %d UIDs saved.\n", count);
1294                 if (outlevel == O_VERBOSE)
1295                     for (idp = ctl->oldsaved; idp; idp = idp->next)
1296                         fprintf(stderr, "\t%s\n", idp->id);
1297             }
1298     }
1299 }
1300
1301 /* fetchmail.c ends here */