~ari-tczew/ubuntu/dapper/fetchmail/fix-CVE-2008-2711

« back to all changes in this revision

Viewing changes to fetchmail.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-02-07 12:12:13 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060207121213-onurwfrzdlzlzxnt
Tags: 6.3.2-2ubuntu1
* Resynchronise with Debian. This brings the new upstream version to dapper
  since upstream support for 6.2 was dropped.
* Drop debian/patches/CVE-2005-4348.dpatch, upstream now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <errno.h>
26
26
#include <sys/types.h>
27
27
#include <sys/stat.h>
28
 
#include <sys/time.h>   /* needed for Sun 4.1.2 */
29
28
#ifdef HAVE_SETRLIMIT
30
29
#include <sys/resource.h>
31
30
#endif /* HAVE_SETRLIMIT */
32
 
#include <sys/utsname.h>
 
31
 
 
32
#ifdef HAVE_SOCKS
 
33
#include <socks.h> /* SOCKSinit() */
 
34
#endif /* HAVE_SOCKS */
 
35
 
 
36
#ifdef HAVE_LANGINFO_H
 
37
#include <langinfo.h>
 
38
#endif
33
39
 
34
40
#include "fetchmail.h"
35
41
#include "socket.h"
54
60
struct runctl run;          /* global controls for this run */
55
61
flag nodetach;              /* if TRUE, don't detach daemon process */
56
62
flag quitmode;              /* if --quit was set */
 
63
int  quitind;               /* optind after position of last --quit option */
57
64
flag check_only;            /* if --probe was set */
58
65
flag versioninfo;           /* emit only version info */
59
66
char *user;                 /* the name of the invoking user */
63
70
flag configdump;            /* dump control blocks for configurator */
64
71
char *fetchmailhost;        /* either `localhost' or the host's FQDN */
65
72
 
66
 
#if NET_SECURITY
67
 
void *request = NULL;
68
 
int requestlen = 0;
69
 
#endif /* NET_SECURITY */
 
73
static int quitonly;        /* if we should quit after killing the running daemon */
70
74
 
71
75
static int querystatus;         /* status of query */
72
76
static int successes;           /* count number of successful polls */
99
103
#endif
100
104
 
101
105
#if defined(HAVE_SETLOCALE) && defined(ENABLE_NLS) && defined(HAVE_STRFTIME)
102
 
#include <time.h>
103
106
#include <locale.h>
 
107
/** returns timestamp in current locale,
 
108
 * and resets LC_TIME locale to POSIX. */
104
109
static char *timestamp (void)
105
110
{
106
111
    time_t      now;
107
 
    static char buf[60];
 
112
    static char buf[60]; /* RATS: ignore */
108
113
 
109
114
    time (&now);
110
115
    setlocale (LC_TIME, "");
118
123
 
119
124
static RETSIGTYPE donothing(int sig) 
120
125
{
121
 
    extern volatile int lastsig;        /* declared in idle.c */
122
126
    set_signal_handler(sig, donothing);
123
127
    lastsig = sig;
124
128
}
125
129
 
 
130
static void printcopyright(FILE *fp) {
 
131
        fprintf(fp, GT_("Copyright (C) 2002, 2003 Eric S. Raymond\n"
 
132
                   "Copyright (C) 2004 Matthias Andree, Eric S. Raymond, Rob F. Funk, Graham Wilson\n"
 
133
                   "Copyright (C) 2005 Matthias Andree, Sunil Shetye\n"
 
134
                   "Copyright (C) 2006 Matthias Andree\n"));
 
135
        fprintf(fp, GT_("Fetchmail comes with ABSOLUTELY NO WARRANTY. This is free software, and you\n"
 
136
                   "are welcome to redistribute it under certain conditions. For details,\n"
 
137
                   "please see the file COPYING in the source or documentation directory.\n"));
 
138
}
 
139
 
 
140
const char *iana_charset;
 
141
 
126
142
int main(int argc, char **argv)
127
143
{
128
144
    int bkgd = FALSE;
129
 
    int parsestatus, implicitmode = FALSE;
 
145
    int implicitmode = FALSE;
130
146
    struct query *ctl;
131
147
    netrc_entry *netrc_list;
132
148
    char *netrc_file, *tmpbuf;
142
158
    setlocale (LC_ALL, "");
143
159
    bindtextdomain(PACKAGE, LOCALEDIR);
144
160
    textdomain(PACKAGE);
 
161
    iana_charset = norm_charmap(nl_langinfo(CODESET)); /* normalize local
 
162
                                                          charset to
 
163
                                                          IANA charset. */
 
164
#else
 
165
    iana_charset = "US-ASCII";
145
166
#endif
146
167
 
 
168
    if (getuid() == 0) {
 
169
        report(stderr, GT_("WARNING: Running as root is discouraged.\n"));
 
170
    }
 
171
 
147
172
    /*
148
173
     * Note: because we can't initialize reporting before we  know whether
149
174
     * syslog is supposed to be on, this message will go to stdout and
182
207
    }
183
208
#endif
184
209
 
185
 
    if ((parsestatus = parsecmdline(argc,argv, &cmd_run, &cmd_opts)) < 0)
186
 
        exit(PS_SYNTAX);
 
210
    {
 
211
        int i;
 
212
 
 
213
        i = parsecmdline(argc, argv, &cmd_run, &cmd_opts);
 
214
        if (i < 0)
 
215
            exit(PS_SYNTAX);
 
216
 
 
217
        if (quitmode && quitind == argc)
 
218
            quitonly = 1;
 
219
    }
187
220
 
188
221
    if (versioninfo)
189
222
    {
190
 
        printf(GT_("This is fetchmail release %s"), VERSION);
 
223
        const char *features = 
191
224
#ifdef POP2_ENABLE
192
 
        printf("+POP2");
 
225
        "+POP2"
193
226
#endif /* POP2_ENABLE */
194
227
#ifndef POP3_ENABLE
195
 
        printf("-POP3");
 
228
        "-POP3"
196
229
#endif /* POP3_ENABLE */
197
230
#ifndef IMAP_ENABLE
198
 
        printf("-IMAP");
 
231
        "-IMAP"
199
232
#endif /* IMAP_ENABLE */
200
233
#ifdef GSSAPI
201
 
        printf("+IMAP-GSS");
 
234
        "+IMAP-GSS"
202
235
#endif /* GSSAPI */
203
236
#ifdef RPA_ENABLE
204
 
        printf("+RPA");
 
237
        "+RPA"
205
238
#endif /* RPA_ENABLE */
206
239
#ifdef NTLM_ENABLE
207
 
        printf("+NTLM");
 
240
        "+NTLM"
208
241
#endif /* NTLM_ENABLE */
209
242
#ifdef SDPS_ENABLE
210
 
        printf("+SDPS");
 
243
        "+SDPS"
211
244
#endif /* SDPS_ENABLE */
212
245
#ifndef ETRN_ENABLE
213
 
        printf("-ETRN");
 
246
        "-ETRN"
214
247
#endif /* ETRN_ENABLE */
215
248
#ifndef ODMR_ENABLE
216
 
        printf("-ODMR");
 
249
        "-ODMR"
217
250
#endif /* ODMR_ENABLE */
218
251
#ifdef SSL_ENABLE
219
 
        printf("+SSL");
 
252
        "+SSL"
220
253
#endif
221
 
#if OPIE_ENABLE
222
 
        printf("+OPIE");
 
254
#ifdef OPIE_ENABLE
 
255
        "+OPIE"
223
256
#endif /* OPIE_ENABLE */
224
 
#if INET6_ENABLE
225
 
        printf("+INET6");
226
 
#endif /* INET6_ENABLE */
227
 
#if NET_SECURITY
228
 
        printf("+NETSEC");
229
 
#endif /* NET_SECURITY */
 
257
#ifdef HAVE_PKG_hesiod
 
258
        "+HESIOD"
 
259
#endif
230
260
#ifdef HAVE_SOCKS
231
 
        printf("+SOCKS");
 
261
        "+SOCKS"
232
262
#endif /* HAVE_SOCKS */
233
 
#if ENABLE_NLS
234
 
        printf("+NLS");
 
263
#ifdef ENABLE_NLS
 
264
        "+NLS"
235
265
#endif /* ENABLE_NLS */
236
 
#ifdef HESIOD
237
 
        printf("+HESIOD");
238
 
#endif /* HESIOD */
239
 
        putchar('\n');
 
266
        ".\n";
 
267
        printf(GT_("This is fetchmail release %s"), VERSION);
 
268
        fputs(features, stdout);
 
269
        puts("");
 
270
        printcopyright(stdout);
 
271
        puts("");
240
272
        fputs("Fallback MDA: ", stdout);
241
273
#ifdef FALLBACK_MDA
242
274
        fputs(FALLBACK_MDA, stdout);
250
282
        system("uname -a");
251
283
    }
252
284
 
253
 
    /* avoid parsing the config file if all we're doing is killing a daemon */ 
254
 
    if (!(quitmode && argc == 2))
 
285
    /* avoid parsing the config file if all we're doing is killing a daemon */
 
286
    if (!quitonly)
255
287
        implicitmode = load_params(argc, argv, optind);
256
288
 
257
289
#if defined(HAVE_SYSLOG)
292
324
    /* parse the ~/.netrc file (if present) for future password lookups. */
293
325
    netrc_file = prependdir (NETRC_FILE, home);
294
326
    netrc_list = parse_netrc(netrc_file);
 
327
    free(netrc_file);
295
328
#undef NETRC_FILE
296
329
 
297
330
    /* pick up passwords where we can */ 
326
359
        }
327
360
    }
328
361
 
 
362
    free_netrc(netrc_list);
 
363
    netrc_list = 0;
 
364
 
329
365
    /* perhaps we just want to check options? */
330
366
    if (versioninfo)
331
367
    {
357
393
    pid = bkgd ? -pid : pid;
358
394
 
359
395
    /* if no mail servers listed and nothing in background, we're done */
360
 
    if (!(quitmode && argc == 2) && pid == 0 && querylist == NULL) {
 
396
    if (!quitonly && pid == 0 && querylist == NULL) {
361
397
        (void)fputs(GT_("fetchmail: no mailservers have been specified.\n"),stderr);
362
398
        exit(PS_SYNTAX);
363
399
    }
365
401
    /* perhaps user asked us to kill the other fetchmail */
366
402
    if (quitmode)
367
403
    {
368
 
        if (pid == 0) 
369
 
        {
370
 
            fprintf(stderr,GT_("fetchmail: no other fetchmail is running\n"));
371
 
            if (argc == 2)
372
 
                exit(PS_EXCLUDE);
373
 
        }
374
 
        else if (getpid() == pid)
375
 
        {
376
 
            /* this test enables re-execing on a changed rcfile */
377
 
            if (argc == 2)
378
 
            {
 
404
        if (pid == 0 || pid == getpid())
 
405
            /* this test enables re-execing on a changed rcfile
 
406
             * for pid == getpid() */
 
407
        {
 
408
            if (quitonly) {
379
409
                fprintf(stderr,GT_("fetchmail: no other fetchmail is running\n"));
380
410
                exit(PS_EXCLUDE);
381
411
            }
388
418
        }
389
419
        else
390
420
        {
391
 
            fprintf(stderr,GT_("fetchmail: %s fetchmail at %d killed.\n"),
392
 
                    bkgd ? GT_("background") : GT_("foreground"), pid);
393
 
            lock_release();
394
 
            if (argc == 2)
 
421
            int maxwait;
 
422
 
 
423
            if (outlevel > O_SILENT)
 
424
                fprintf(stderr,GT_("fetchmail: %s fetchmail at %d killed.\n"),
 
425
                        bkgd ? GT_("background") : GT_("foreground"), pid);
 
426
            /* We used to nuke the other process's lock here, with
 
427
             * fm_lock_release(), which is broken. The other process
 
428
             * needs to clear its lock by itself. */
 
429
            if (quitonly)
395
430
                exit(0);
396
 
            else
397
 
                pid = 0; 
 
431
 
 
432
            /* wait for other process to exit */
 
433
            maxwait = 10; /* seconds */
 
434
            while (kill(pid, 0) == 0 && --maxwait >= 0) {
 
435
                sleep(1);
 
436
            }
 
437
            pid = 0;
398
438
        }
399
439
    }
400
440
 
463
503
                        GT_("fetchmail: can't find a password for %s@%s.\n"),
464
504
                        ctl->remotename, ctl->server.pollname);
465
505
                return(PS_AUTHFAIL);
466
 
            }
467
 
            else
468
 
            {
469
 
                char* password_prompt = GT_("Enter password for %s@%s: ");
 
506
            } else {
 
507
                const char* password_prompt = GT_("Enter password for %s@%s: ");
 
508
                size_t pplen = strlen(password_prompt) + strlen(ctl->remotename) + strlen(ctl->server.pollname) + 1;
470
509
 
471
 
                xalloca(tmpbuf, char *, strlen(password_prompt) +
472
 
                        strlen(ctl->remotename) +
473
 
                        strlen(ctl->server.pollname) + 1);
474
 
                (void) sprintf(tmpbuf, password_prompt,
475
 
                               ctl->remotename, ctl->server.pollname);
 
510
                tmpbuf = xmalloc(pplen);
 
511
                snprintf(tmpbuf, pplen, password_prompt,
 
512
                        ctl->remotename, ctl->server.pollname);
476
513
                ctl->password = xstrdup((char *)fm_getpassword(tmpbuf));
 
514
                free(tmpbuf);
477
515
            }
478
516
        }
479
517
    }
518
556
        }
519
557
    }
520
558
 
521
 
#ifdef linux
522
559
    interface_init();
523
 
#endif /* linux */
524
560
 
525
561
    /* beyond here we don't want more than one fetchmail running per user */
526
562
    umask(0077);
635
671
                        }
636
672
                    }
637
673
 
638
 
#if (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__)
 
674
#ifdef CAN_MONITOR
639
675
                    /*
640
676
                     * Don't do monitoring if we were woken by a signal.
641
677
                     * Note that interface_approve() does its own error logging.
642
678
                     */
643
679
                    if (!interface_approve(&ctl->server, !lastsig))
644
680
                        continue;
645
 
#endif /* (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__) */
 
681
#endif /* CAN_MONITOR */
646
682
 
647
683
                    dofastuidl = 0; /* this is reset in the driver if required */
648
684
 
699
735
                            break;
700
736
                        }
701
737
 
702
 
#if (defined(linux) && !INET6_ENABLE) || defined (__FreeBSD__)
 
738
#ifdef CAN_MONITOR
703
739
                    if (ctl->server.monitor)
704
740
                    {
705
741
                        /*
710
746
                        sleep(3);
711
747
                        interface_note_activity(&ctl->server);
712
748
                    }
713
 
#endif /* (defined(linux) && !INET6_ENABLE) || defined(__FreeBSD__) */
 
749
#endif /* CAN_MONITOR */
714
750
                }
715
751
            }
716
752
 
830
866
#define FLAG_MERGE(fld) if (force ? !!h1->fld : !h2->fld) h2->fld = h1->fld
831
867
    FLAG_MERGE(server.via);
832
868
    FLAG_MERGE(server.protocol);
833
 
#if INET6_ENABLE
834
869
    FLAG_MERGE(server.service);
835
 
    FLAG_MERGE(server.netsec);
836
 
#else /* INET6_ENABLE */
837
 
    FLAG_MERGE(server.port);
838
 
#endif /* INET6_ENABLE */
839
870
    FLAG_MERGE(server.interval);
840
871
    FLAG_MERGE(server.authenticate);
841
872
    FLAG_MERGE(server.timeout);
848
879
    FLAG_MERGE(server.uidl);
849
880
    FLAG_MERGE(server.principal);
850
881
 
851
 
#if defined(linux) || defined(__FreeBSD__)
 
882
#ifdef CAN_MONITOR
852
883
    FLAG_MERGE(server.interface);
 
884
    FLAG_MERGE(server.interface_pair);
853
885
    FLAG_MERGE(server.monitor);
854
 
    FLAG_MERGE(server.interface_pair);
855
 
#endif /* linux || defined(__FreeBSD__) */
 
886
#endif
856
887
 
857
888
    FLAG_MERGE(server.plugin);
858
889
    FLAG_MERGE(server.plugout);
 
890
    FLAG_MERGE(server.tracepolls);
859
891
 
860
892
    FLAG_MERGE(wildcard);
861
893
    FLAG_MERGE(remotename);
870
902
 
871
903
    FLAG_MERGE(keep);
872
904
    FLAG_MERGE(flush);
 
905
    FLAG_MERGE(limitflush);
873
906
    FLAG_MERGE(fetchall);
874
907
    FLAG_MERGE(rewrite);
875
908
    FLAG_MERGE(forcecr);
896
929
#endif
897
930
    FLAG_MERGE(expunge);
898
931
 
899
 
    FLAG_MERGE(tracepolls);
900
932
    FLAG_MERGE(properties);
901
933
#undef FLAG_MERGE
902
934
}
903
935
 
 
936
/** Load configuration files.
 
937
 * \return - true if no servers found on the command line
 
938
 *         - false if servers found on the command line */
904
939
static int load_params(int argc, char **argv, int optind)
905
940
{
906
941
    int implicitmode, st;
930
965
    p = strrchr (rcfile, '/');
931
966
    if (p && (p - rcfile) < sizeof (rcfiledir)) {
932
967
        *p = 0;                 /* replace '/' by '0' */
933
 
        strcpy (rcfiledir, rcfile);
 
968
        strlcpy (rcfiledir, rcfile, sizeof(rcfiledir));
934
969
        *p = '/';               /* restore '/' */
935
970
        if (!rcfiledir[0])      /* "/.fetchmailrc" case */
936
971
            strcpy (rcfiledir, "/");
973
1008
                        || str_in_list(&ctl->server.akalist, argv[optind], TRUE))
974
1009
                {
975
1010
                    /* Is this correct? */
976
 
                    if (predeclared && outlevel == O_VERBOSE)
 
1011
                    if (predeclared && outlevel >= O_VERBOSE)
977
1012
                        fprintf(stderr,GT_("Warning: multiple mentions of host %s in config file\n"),argv[optind]);
978
1013
                    ctl->active = TRUE;
979
1014
                    predeclared = TRUE;
1005
1040
    }
1006
1041
 
1007
1042
    /* don't allow a defaults record after the first */
1008
 
    for (ctl = querylist; ctl; ctl = ctl->next)
1009
 
        if (ctl != querylist && strcmp(ctl->server.pollname, "defaults") == 0)
 
1043
    for (ctl = querylist; ctl; ctl = ctl->next) {
 
1044
        if (ctl != querylist && strcmp(ctl->server.pollname, "defaults") == 0) {
 
1045
            fprintf(stderr, GT_("fetchmail: Error: multiple \"defaults\" records in config file.\n"));
1010
1046
            exit(PS_SYNTAX);
 
1047
        }
 
1048
    }
1011
1049
 
1012
1050
    /* use localhost if we never fetch the FQDN of this host */
1013
1051
    fetchmailhost = "localhost";
1048
1086
     * If we're using Kerberos for authentication, we need 
1049
1087
     * the FQDN in order to generate capability keys.
1050
1088
     */
1051
 
    if (strcmp(fetchmailhost, "localhost") == 0)
1052
 
        for (ctl = querylist; ctl; ctl = ctl->next)
1053
 
            if (ctl->active && 
 
1089
    for (ctl = querylist; ctl; ctl = ctl->next)
 
1090
        if (ctl->active && 
1054
1091
                (ctl->server.protocol==P_ETRN || ctl->server.protocol==P_ODMR
1055
1092
                 || ctl->server.authenticate == A_KERBEROS_V4
1056
1093
                 || ctl->server.authenticate == A_KERBEROS_V5))
1057
 
            {
1058
 
                fetchmailhost = host_fqdn();
1059
 
                break;
1060
 
            }
 
1094
        {
 
1095
            fetchmailhost = host_fqdn(1);
 
1096
            break;
 
1097
        }
 
1098
 
 
1099
    if (!ctl) /* list exhausted */
 
1100
        fetchmailhost = host_fqdn(0);
 
1101
 
 
1102
    /* this code enables flags to be turned off */
 
1103
#define DEFAULT(flag, dflt)     if (flag == FLAG_TRUE)\
 
1104
                                        flag = TRUE;\
 
1105
                                else if (flag == FLAG_FALSE)\
 
1106
                                        flag = FALSE;\
 
1107
                                else\
 
1108
                                        flag = (dflt)
 
1109
    /* one global gets treated specially */
 
1110
    DEFAULT(run.showdots, run.poll_interval==0 || nodetach);
1061
1111
 
1062
1112
    /* merge in wired defaults, do sanity checks and prepare internal fields */
1063
1113
    for (ctl = querylist; ctl; ctl = ctl->next)
1088
1138
 
1089
1139
        if (configdump || ctl->active )
1090
1140
        {
1091
 
            /* this code enables flags to be turned off */
1092
 
#define DEFAULT(flag, dflt)     if (flag == FLAG_TRUE)\
1093
 
                                        flag = TRUE;\
1094
 
                                else if (flag == FLAG_FALSE)\
1095
 
                                        flag = FALSE;\
1096
 
                                else\
1097
 
                                        flag = (dflt)
1098
1141
            DEFAULT(ctl->keep, FALSE);
1099
1142
            DEFAULT(ctl->fetchall, FALSE);
1100
1143
            DEFAULT(ctl->flush, FALSE);
 
1144
            DEFAULT(ctl->limitflush, FALSE);
1101
1145
            DEFAULT(ctl->rewrite, TRUE);
1102
1146
            DEFAULT(ctl->stripcr, (ctl->mda != (char *)NULL)); 
1103
1147
            DEFAULT(ctl->forcecr, FALSE);
1108
1152
            DEFAULT(ctl->idle, FALSE);
1109
1153
            DEFAULT(ctl->server.dns, TRUE);
1110
1154
            DEFAULT(ctl->server.uidl, FALSE);
1111
 
#ifdef  SSL_ENABLE
1112
1155
            DEFAULT(ctl->use_ssl, FALSE);
1113
1156
            DEFAULT(ctl->sslcertck, FALSE);
1114
 
#endif
1115
1157
            DEFAULT(ctl->server.checkalias, FALSE);
1116
1158
#ifndef SSL_ENABLE
 
1159
            /*
 
1160
             * XXX FIXME: do we need this check or can we rely on the .y
 
1161
             * parser handling this?
 
1162
             */
1117
1163
            if (ctl->use_ssl) 
1118
1164
            {
1119
1165
                report(stderr, GT_("SSL support is not compiled in.\n"));
1120
1166
                exit(PS_SYNTAX);
1121
1167
            }
1122
1168
#endif /* SSL_ENABLE */
1123
 
            /* one global gets treated specially */
1124
 
            DEFAULT(run.showdots, run.poll_interval==0 || nodetach);
1125
1169
#undef DEFAULT
1126
1170
 
1127
1171
            /*
1128
1172
             * Make sure we have a nonempty host list to forward to.
1129
1173
             */
1130
1174
            if (!ctl->smtphunt)
1131
 
                save_str(&ctl->smtphunt, fetchmailhost, FALSE);
 
1175
                save_str(&ctl->smtphunt, "localhost", FALSE);
1132
1176
 
1133
1177
            /*
1134
1178
             * Make sure we have a nonempty list of domains to fetch from.
1144
1188
            if (!ctl->localnames)       /* for local delivery via SMTP */
1145
1189
                save_str_pair(&ctl->localnames, user, NULL);
1146
1190
 
1147
 
#if !defined(HAVE_GETHOSTBYNAME) || !defined(HAVE_RES_SEARCH)
 
1191
#ifndef HAVE_RES_SEARCH
1148
1192
            /* can't handle multidrop mailboxes unless we can do DNS lookups */
1149
 
            if (ctl->localnames && ctl->localnames->next && ctl->server.dns)
 
1193
            if (MULTIDROP(ctl) && ctl->server.dns)
1150
1194
            {
1151
1195
                ctl->server.dns = FALSE;
1152
1196
                report(stderr, GT_("fetchmail: warning: no DNS available to check multidrop fetches from %s\n"), ctl->server.pollname);
1153
1197
            }
1154
 
#endif /* !HAVE_GETHOSTBYNAME || !HAVE_RES_SEARCH */
 
1198
#endif /* !HAVE_RES_SEARCH */
 
1199
 
 
1200
            /*
 
1201
             * can't handle multidrop mailboxes without "envelope"
 
1202
             * option, this causes truckloads full of support complaints
 
1203
             * "all mail forwarded to postmaster"
 
1204
             */
 
1205
            if (MULTIDROP(ctl) && !ctl->server.envelope)
 
1206
            {
 
1207
                report(stderr, GT_("warning: multidrop for %s requires envelope option!\n"), ctl->server.pollname);
 
1208
                report(stderr, GT_("warning: Do not ask for support if all mail goes to postmaster!\n"));
 
1209
            }
1155
1210
 
1156
1211
            /* if no folders were specified, set up the null one as default */
1157
1212
            if (!ctl->mailboxes)
1158
1213
                save_str(&ctl->mailboxes, (char *)NULL, 0);
1159
1214
 
1160
1215
            /* maybe user overrode timeout on command line? */
1161
 
            if (ctl->server.timeout == -1)      
 
1216
            if (ctl->server.timeout == -1)
1162
1217
                ctl->server.timeout = CLIENT_TIMEOUT;
1163
1218
 
1164
 
#if !INET6_ENABLE
1165
1219
            /* sanity checks */
1166
 
            if (ctl->server.port < 0)
1167
 
            {
1168
 
                (void) fprintf(stderr,
1169
 
                               GT_("%s configuration invalid, port number cannot be negative\n"),
1170
 
                               ctl->server.pollname);
1171
 
                exit(PS_SYNTAX);
1172
 
            }
1173
 
            if (ctl->server.protocol == P_RPOP && ctl->server.port >= 1024)
1174
 
            {
1175
 
                (void) fprintf(stderr,
1176
 
                               GT_("%s configuration invalid, RPOP requires a privileged port\n"),
1177
 
                               ctl->server.pollname);
1178
 
                exit(PS_SYNTAX);
 
1220
            if (ctl->server.service) {
 
1221
                int port = servport(ctl->server.service);
 
1222
                if (port < 0)
 
1223
                {
 
1224
                    (void) fprintf(stderr,
 
1225
                                   GT_("fetchmail: %s configuration invalid, specify positive port number for service or port\n"),
 
1226
                                   ctl->server.pollname);
 
1227
                    exit(PS_SYNTAX);
 
1228
                }
 
1229
                if (ctl->server.protocol == P_RPOP && port >= 1024)
 
1230
                {
 
1231
                    (void) fprintf(stderr,
 
1232
                                   GT_("fetchmail: %s configuration invalid, RPOP requires a privileged port\n"),
 
1233
                                   ctl->server.pollname);
 
1234
                    exit(PS_SYNTAX);
 
1235
                }
1179
1236
            }
1180
1237
            if (ctl->listener == LMTP_MODE)
1181
1238
            {
1185
1242
                {
1186
1243
                    char        *cp;
1187
1244
 
1188
 
                    if (!(cp = strrchr(idp->id, '/')) ||
1189
 
                                (atoi(++cp) == SMTP_PORT))
 
1245
                    if (!(cp = strrchr((char *)idp->id, '/')) ||
 
1246
                            ++cp, (0 == strcmp(cp, SMTP_PORT))
 
1247
                                || servport(cp) == SMTP_PORT_NUM)
1190
1248
                    {
1191
1249
                        (void) fprintf(stderr,
1192
1250
                                       GT_("%s configuration invalid, LMTP can't use default SMTP port\n"),
1195
1253
                    }
1196
1254
                }
1197
1255
            }
1198
 
#endif /* !INET6_ENABLE */
1199
1256
 
1200
1257
            /*
1201
 
             * "I beg to you, have mercy on the week minds like myself."
 
1258
             * "I beg to you, have mercy on the we[a]k minds like myself."
1202
1259
             * wrote Pehr Anderson.  Your petition is granted.
1203
1260
             */
1204
 
            if (ctl->fetchall && ctl->keep && run.poll_interval && !nodetach)
 
1261
            if (ctl->fetchall && ctl->keep && run.poll_interval && !nodetach && !configdump)
1205
1262
            {
1206
1263
                (void) fprintf(stderr,
1207
1264
                               GT_("Both fetchall and keep on in daemon mode is a mistake!\n"));
1208
 
                exit(PS_SYNTAX);
1209
1265
            }
1210
1266
        }
1211
1267
    }
1236
1292
static RETSIGTYPE terminate_poll(int sig)
1237
1293
/* to be executed at the end of a poll cycle */
1238
1294
{
1239
 
    /*
1240
 
     * Close all SMTP delivery sockets.  For optimum performance
1241
 
     * we'd like to hold them open til end of run, but (1) this
1242
 
     * loses if our poll interval is longer than the MTA's inactivity
1243
 
     * timeout, and (2) some MTAs (like smail) don't deliver after
1244
 
     * each message, but rather queue up mail and wait to actually
1245
 
     * deliver it until the input socket is closed. 
1246
 
     *
1247
 
     * Sending SMTP QUIT on signal is theoretically nice, but led to a 
1248
 
     * subtle bug.  If fetchmail was terminated by signal while it was 
1249
 
     * shipping message text, it would hang forever waiting for a
1250
 
     * command acknowledge.  In theory we could enable the QUIT
1251
 
     * only outside of the message send.  In practice, we don't
1252
 
     * care.  All mailservers hang up on a dropped TCP/IP connection
1253
 
     * anyway.
1254
 
     */
1255
1295
 
1256
1296
    if (sig != 0)
1257
1297
        report(stdout, GT_("terminated with signal %d\n"), sig);
1258
 
    else
1259
 
    {
1260
 
        struct query *ctl;
1261
 
 
1262
 
        /* terminate all SMTP connections cleanly */
1263
 
        for (ctl = querylist; ctl; ctl = ctl->next)
1264
 
            if (ctl->smtp_socket != -1)
1265
 
            {
1266
 
                /* don't send QUIT for ODMR case because we're acting
1267
 
                   as a proxy between the SMTP server and client. */
1268
 
                smtp_close(ctl, ctl->server.protocol != P_ODMR);
1269
 
            }
1270
 
    }
1271
1298
 
1272
1299
#ifdef POP3_ENABLE
1273
1300
    /*
1302
1329
        if (ctl->password)
1303
1330
          memset(ctl->password, '\0', strlen(ctl->password));
1304
1331
 
1305
 
#if !defined(HAVE_ATEXIT) && !defined(HAVE_ON_EXIT)
1306
 
    lock_release();
 
1332
#if !defined(HAVE_ATEXIT)
 
1333
    fm_lock_release();
1307
1334
#endif
1308
1335
 
1309
1336
    if (activecount == 0)
1395
1422
        report(stderr, GT_("ETRN support is not configured.\n"));
1396
1423
        st = PS_PROTOCOL;
1397
1424
#else
1398
 
#ifdef HAVE_GETHOSTBYNAME
1399
1425
        st = doETRN(ctl);
1400
 
#else
1401
 
        report(stderr, GT_("Cannot support ETRN without gethostbyname(2).\n"));
1402
 
        st = PS_PROTOCOL;
1403
 
#endif /* HAVE_GETHOSTBYNAME */
1404
1426
        break;
1405
1427
#endif /* ETRN_ENABLE */
1406
1428
    case P_ODMR:
1408
1430
        report(stderr, GT_("ODMR support is not configured.\n"));
1409
1431
        st = PS_PROTOCOL;
1410
1432
#else
1411
 
#ifdef HAVE_GETHOSTBYNAME
1412
1433
        st = doODMR(ctl);
1413
 
#else
1414
 
        report(stderr, GT_("Cannot support ODMR without gethostbyname(2).\n"));
1415
 
        st = PS_PROTOCOL;
1416
 
#endif /* HAVE_GETHOSTBYNAME */
1417
1434
#endif /* ODMR_ENABLE */
1418
1435
        break;
1419
1436
    default:
1478
1495
            printf(GT_("  Mail will be retrieved via %s\n"), ctl->server.via);
1479
1496
 
1480
1497
        if (ctl->server.interval)
1481
 
            printf(GT_("  Poll of this server will occur every %d intervals.\n"),
1482
 
                   ctl->server.interval);
 
1498
            printf(ngettext("  Poll of this server will occur every %d interval.\n",
 
1499
                            "  Poll of this server will occur every %d intervals.\n",
 
1500
                            ctl->server.interval), ctl->server.interval);
1483
1501
        if (ctl->server.truename)
1484
1502
            printf(GT_("  True name of server is %s.\n"), ctl->server.truename);
1485
1503
        if (ctl->server.skip || outlevel >= O_VERBOSE)
1486
 
            printf(GT_("  This host %s be queried when no host is specified.\n"),
1487
 
                   ctl->server.skip ? GT_("will not") : GT_("will"));
 
1504
            printf(ctl->server.skip
 
1505
                   ? GT_("  This host will not be queried when no host is specified.\n")
 
1506
                   : GT_("  This host will be queried when no host is specified.\n"));
1488
1507
        if (!NO_PASSWORD(ctl))
1489
1508
        {
1490
1509
            if (!ctl->password)
1504
1523
        }
1505
1524
 
1506
1525
        if (ctl->server.protocol == P_POP3 
1507
 
#if INET6_ENABLE
1508
1526
            && ctl->server.service && !strcmp(ctl->server.service, KPOP_PORT)
1509
 
#else /* INET6_ENABLE */
1510
 
            && ctl->server.port == KPOP_PORT
1511
 
#endif /* INET6_ENABLE */
1512
1527
            && (ctl->server.authenticate == A_KERBEROS_V4 ||
1513
1528
                ctl->server.authenticate == A_KERBEROS_V5))
1514
1529
            printf(GT_("  Protocol is KPOP with Kerberos %s authentication"),
1515
1530
                   ctl->server.authenticate == A_KERBEROS_V5 ? "V" : "IV");
1516
1531
        else
1517
1532
            printf(GT_("  Protocol is %s"), showproto(ctl->server.protocol));
1518
 
#if INET6_ENABLE
1519
1533
        if (ctl->server.service)
1520
1534
            printf(GT_(" (using service %s)"), ctl->server.service);
1521
 
        if (ctl->server.netsec)
1522
 
            printf(GT_(" (using network security options %s)"), ctl->server.netsec);
1523
 
#else /* INET6_ENABLE */
1524
 
        if (ctl->server.port)
1525
 
            printf(GT_(" (using port %d)"), ctl->server.port);
1526
 
#endif /* INET6_ENABLE */
1527
1535
        else if (outlevel >= O_VERBOSE)
1528
1536
            printf(GT_(" (using default port)"));
1529
1537
        if (ctl->server.uidl && MAILBOX_PROTOCOL(ctl))
1538
1546
        case A_PASSWORD:
1539
1547
            printf(GT_("  Password authentication will be forced.\n"));
1540
1548
            break;
 
1549
        case A_MSN:
 
1550
            printf(GT_("  MSN authentication will be forced.\n"));
 
1551
            break;
1541
1552
        case A_NTLM:
1542
1553
            printf(GT_("  NTLM authentication will be forced.\n"));
1543
1554
            break;
1592
1603
 
1593
1604
                printf(GT_("  Selected mailboxes are:"));
1594
1605
                for (idp = ctl->mailboxes; idp; idp = idp->next)
1595
 
                    printf(" %s", idp->id);
 
1606
                    printf(" %s", (char *)idp->id);
1596
1607
                printf("\n");
1597
1608
            }
1598
 
            printf(GT_("  %s messages will be retrieved (--all %s).\n"),
1599
 
                   ctl->fetchall ? GT_("All") : GT_("Only new"),
1600
 
                   ctl->fetchall ? "on" : "off");
1601
 
            printf(GT_("  Fetched messages %s be kept on the server (--keep %s).\n"),
1602
 
                   ctl->keep ? GT_("will") : GT_("will not"),
1603
 
                   ctl->keep ? "on" : "off");
1604
 
            printf(GT_("  Old messages %s be flushed before message retrieval (--flush %s).\n"),
1605
 
                   ctl->flush ? GT_("will") : GT_("will not"),
1606
 
                   ctl->flush ? "on" : "off");
1607
 
            printf(GT_("  Rewrite of server-local addresses is %s (--norewrite %s).\n"),
1608
 
                   ctl->rewrite ? GT_("enabled") : GT_("disabled"),
1609
 
                   ctl->rewrite ? "off" : "on");
1610
 
            printf(GT_("  Carriage-return stripping is %s (stripcr %s).\n"),
1611
 
                   ctl->stripcr ? GT_("enabled") : GT_("disabled"),
1612
 
                   ctl->stripcr ? "on" : "off");
1613
 
            printf(GT_("  Carriage-return forcing is %s (forcecr %s).\n"),
1614
 
                   ctl->forcecr ? GT_("enabled") : GT_("disabled"),
1615
 
                   ctl->forcecr ? "on" : "off");
1616
 
            printf(GT_("  Interpretation of Content-Transfer-Encoding is %s (pass8bits %s).\n"),
1617
 
                   ctl->pass8bits ? GT_("disabled") : GT_("enabled"),
1618
 
                   ctl->pass8bits ? "on" : "off");
1619
 
            printf(GT_("  MIME decoding is %s (mimedecode %s).\n"),
1620
 
                   ctl->mimedecode ? GT_("enabled") : GT_("disabled"),
1621
 
                   ctl->mimedecode ? "on" : "off");
1622
 
            printf(GT_("  Idle after poll is %s (idle %s).\n"),
1623
 
                   ctl->idle ? GT_("enabled") : GT_("disabled"),
1624
 
                   ctl->idle ? "on" : "off");
1625
 
            printf(GT_("  Nonempty Status lines will be %s (dropstatus %s)\n"),
1626
 
                   ctl->dropstatus ? GT_("discarded") : GT_("kept"),
1627
 
                   ctl->dropstatus ? "on" : "off");
1628
 
            printf(GT_("  Delivered-To lines will be %s (dropdelivered %s)\n"),
1629
 
                   ctl->dropdelivered ? GT_("discarded") : GT_("kept"),
1630
 
                   ctl->dropdelivered ? "on" : "off");
 
1609
            printf(ctl->fetchall
 
1610
                   ? GT_("  All messages will be retrieved (--all on).\n")
 
1611
                   : GT_("  Only new messages will be retrieved (--all off).\n"));
 
1612
            printf(ctl->keep
 
1613
                   ? GT_("  Fetched messages will be kept on the server (--keep on).\n")
 
1614
                   : GT_("  Fetched messages will not be kept on the server (--keep off).\n"));
 
1615
            printf(ctl->flush
 
1616
                   ? GT_("  Old messages will be flushed before message retrieval (--flush on).\n")
 
1617
                   : GT_("  Old messages will not be flushed before message retrieval (--flush off).\n"));
 
1618
            printf(ctl->limitflush
 
1619
                   ? GT_("  Oversized messages will be flushed before message retrieval (--limitflush on).\n")
 
1620
                   : GT_("  Oversized messages will not be flushed before message retrieval (--limitflush off).\n"));
 
1621
            printf(ctl->rewrite
 
1622
                   ? GT_("  Rewrite of server-local addresses is enabled (--norewrite off).\n")
 
1623
                   : GT_("  Rewrite of server-local addresses is disabled (--norewrite on).\n"));
 
1624
            printf(ctl->stripcr
 
1625
                   ? GT_("  Carriage-return stripping is enabled (stripcr on).\n")
 
1626
                   : GT_("  Carriage-return stripping is disabled (stripcr off).\n"));
 
1627
            printf(ctl->forcecr
 
1628
                   ? GT_("  Carriage-return forcing is enabled (forcecr on).\n")
 
1629
                   : GT_("  Carriage-return forcing is disabled (forcecr off).\n"));
 
1630
            printf(ctl->pass8bits
 
1631
                   ? GT_("  Interpretation of Content-Transfer-Encoding is disabled (pass8bits on).\n")
 
1632
                   : GT_("  Interpretation of Content-Transfer-Encoding is enabled (pass8bits off).\n"));
 
1633
            printf(ctl->mimedecode
 
1634
                   ? GT_("  MIME decoding is enabled (mimedecode on).\n")
 
1635
                   : GT_("  MIME decoding is disabled (mimedecode off).\n"));
 
1636
            printf(ctl->idle
 
1637
                   ? GT_("  Idle after poll is enabled (idle on).\n")
 
1638
                   : GT_("  Idle after poll is disabled (idle off).\n"));
 
1639
            printf(ctl->dropstatus
 
1640
                   ? GT_("  Nonempty Status lines will be discarded (dropstatus on)\n")
 
1641
                   : GT_("  Nonempty Status lines will be kept (dropstatus off)\n"));
 
1642
            printf(ctl->dropdelivered
 
1643
                   ? GT_("  Delivered-To lines will be discarded (dropdelivered on)\n")
 
1644
                   : GT_("  Delivered-To lines will be kept (dropdelivered off)\n"));
1631
1645
            if (NUM_NONZERO(ctl->limit))
1632
1646
            {
1633
1647
                if (NUM_NONZERO(ctl->limit))
1679
1693
            printf(GT_("  Domains for which mail will be fetched are:"));
1680
1694
            for (idp = ctl->domainlist; idp; idp = idp->next)
1681
1695
            {
1682
 
                printf(" %s", idp->id);
 
1696
                printf(" %s", (char *)idp->id);
1683
1697
                if (!idp->val.status.mark)
1684
1698
                    printf(GT_(" (default)"));
1685
1699
            }
1699
1713
                       ctl->listener);
1700
1714
                for (idp = ctl->smtphunt; idp; idp = idp->next)
1701
1715
                {
1702
 
                    printf(" %s", idp->id);
 
1716
                    printf(" %s", (char *)idp->id);
1703
1717
                    if (!idp->val.status.mark)
1704
1718
                        printf(GT_(" (default)"));
1705
1719
                }
1752
1766
                    else
1753
1767
                        printf(GT_("  Single-drop mode: "));
1754
1768
 
1755
 
                    printf(GT_("%d local name(s) recognized.\n"), count);
 
1769
                    printf(ngettext("%d local name recognized.\n", "%d local names recognized.\n", count), count);
1756
1770
                    if (outlevel >= O_VERBOSE)
1757
1771
                    {
1758
1772
                        for (idp = ctl->localnames; idp; idp = idp->next)
1759
1773
                            if (idp->val.id2)
1760
 
                                printf("\t%s -> %s\n", idp->id, idp->val.id2);
 
1774
                                printf("\t%s -> %s\n", (char *)idp->id, (char *)idp->val.id2);
1761
1775
                            else
1762
 
                                printf("\t%s\n", idp->id);
 
1776
                                printf("\t%s\n", (char *)idp->id);
1763
1777
                        if (ctl->wildcard)
1764
1778
                            fputs("\t*\n", stdout);
1765
1779
                    }
1766
1780
 
1767
1781
                    if (count > 1 || ctl->wildcard)
1768
1782
                    {
1769
 
                        printf(GT_("  DNS lookup for multidrop addresses is %s.\n"),
1770
 
                               ctl->server.dns ? GT_("enabled") : GT_("disabled"));
 
1783
                        printf(ctl->server.dns
 
1784
                               ? GT_("  DNS lookup for multidrop addresses is enabled.\n")
 
1785
                               : GT_("  DNS lookup for multidrop addresses is disabled.\n"));
1771
1786
                        if (ctl->server.dns)
1772
1787
                        {
1773
 
                            printf(GT_("  Server aliases will be compared with multidrop addresses by "));
1774
1788
                            if (ctl->server.checkalias)
1775
 
                                printf(GT_("IP address.\n"));
 
1789
                                printf(GT_("  Server aliases will be compared with multidrop addresses by IP address.\n"));
1776
1790
                            else
1777
 
                                printf(GT_("name.\n"));
 
1791
                                printf(GT_("  Server aliases will be compared with multidrop addresses by name.\n"));
1778
1792
                        }
1779
1793
                        if (ctl->server.envelope == STRING_DISABLED)
1780
1794
                            printf(GT_("  Envelope-address routing is disabled\n"));
1781
1795
                        else
1782
1796
                        {
1783
1797
                            printf(GT_("  Envelope header is assumed to be: %s\n"),
1784
 
                                   ctl->server.envelope ? ctl->server.envelope:GT_("Received"));
1785
 
                            if (ctl->server.envskip > 1 || outlevel >= O_VERBOSE)
1786
 
                                printf(GT_("  Number of envelope header to be parsed: %d\n"),
 
1798
                                   ctl->server.envelope ? ctl->server.envelope : "Received");
 
1799
                            if (ctl->server.envskip || outlevel >= O_VERBOSE)
 
1800
                                printf(GT_("  Number of envelope headers to be skipped over: %d\n"),
1787
1801
                                       ctl->server.envskip);
1788
1802
                            if (ctl->server.qvirtual)
1789
1803
                                printf(GT_("  Prefix %s will be removed from user id\n"),
1798
1812
 
1799
1813
                            printf(GT_("  Predeclared mailserver aliases:"));
1800
1814
                            for (idp = ctl->server.akalist; idp; idp = idp->next)
1801
 
                                printf(" %s", idp->id);
 
1815
                                printf(" %s", (char *)idp->id);
1802
1816
                            putchar('\n');
1803
1817
                        }
1804
1818
                        if (ctl->server.localdomains)
1807
1821
 
1808
1822
                            printf(GT_("  Local domains:"));
1809
1823
                            for (idp = ctl->server.localdomains; idp; idp = idp->next)
1810
 
                                printf(" %s", idp->id);
 
1824
                                printf(" %s", (char *)idp->id);
1811
1825
                            putchar('\n');
1812
1826
                        }
1813
1827
                    }
1814
1828
                }
1815
1829
        }
1816
 
#if defined(linux) || defined(__FreeBSD__)
 
1830
#ifdef CAN_MONITOR
1817
1831
        if (ctl->server.interface)
1818
1832
            printf(GT_("  Connection must be through interface %s.\n"), ctl->server.interface);
1819
1833
        else if (outlevel >= O_VERBOSE)
1848
1862
                printf(GT_("  %d UIDs saved.\n"), count);
1849
1863
                if (outlevel >= O_VERBOSE)
1850
1864
                    for (idp = ctl->oldsaved; idp; idp = idp->next)
1851
 
                        printf("\t%s\n", idp->id);
 
1865
                        printf("\t%s\n", (char *)idp->id);
1852
1866
            }
1853
1867
        }
1854
1868
 
1855
 
        if (ctl->tracepolls)
 
1869
        if (ctl->server.tracepolls)
1856
1870
            printf(GT_("  Poll trace information will be added to the Received header.\n"));
1857
1871
        else if (outlevel >= O_VERBOSE)
1858
1872
            printf(GT_("  No poll trace information will be added to the Received header.\n.\n"));