]> Pileus Git - ~andy/fetchmail/blobdiff - fetchmail.c
More about Daemin Internet.
[~andy/fetchmail] / fetchmail.c
index 47133a93d7c81d351b6e4f02a3350cd059eff62c..d9ff9258a1ff0cc05271a46f4a775b1f147d321f 100644 (file)
@@ -257,6 +257,64 @@ int main (int argc, char **argv)
     }
 #undef FETCHMAIL_PIDFILE
 
+#ifdef HAVE_SETRLIMIT
+    /*
+     * Before getting passwords, disable core dumps unless -v -d0 mode is on.
+     * Core dumps could otherwise contain passwords to be scavenged by a
+     * cracker.
+     */
+    if (outlevel < O_VERBOSE || run.poll_interval > 0)
+    {
+       struct rlimit corelimit;
+       corelimit.rlim_cur = 0;
+       corelimit.rlim_max = 0;
+       setrlimit(RLIMIT_CORE, &corelimit);
+    }
+#endif /* HAVE_SETRLIMIT */
+
+    /* parse the ~/.netrc file (if present) for future password lookups. */
+    xalloca(netrc_file, char *, strlen (home) + 8);
+    strcpy (netrc_file, home);
+    strcat (netrc_file, "/.netrc");
+    netrc_list = parse_netrc(netrc_file);
+
+    /* pick up passwords where we can */ 
+    for (ctl = querylist; ctl; ctl = ctl->next)
+    {
+       if (ctl->active && !(implicitmode && ctl->server.skip)&&!ctl->password)
+       {
+           if (ctl->server.preauthenticate == A_KERBEROS_V4 ||
+               ctl->server.preauthenticate == A_KERBEROS_V5 ||
+#ifdef GSSAPI
+               ctl->server.protocol == P_IMAP_GSS ||
+#endif /* GSSAPI */
+               ctl->server.protocol == P_IMAP_K4)
+               /* Server won't care what the password is, but there
+                  must be some non-null string here.  */
+               ctl->password = ctl->remotename;
+           else
+           {
+               netrc_entry *p;
+
+               /* look up the pollname and account in the .netrc file. */
+               p = search_netrc(netrc_list,
+                                ctl->server.pollname, ctl->remotename);
+               /* if we find a matching entry with a password, use it */
+               if (p && p->password)
+                   ctl->password = xstrdup(p->password);
+
+               /* otherwise try with "via" name if there is one */
+               else if (ctl->server.via)
+               {
+                   p = search_netrc(netrc_list, 
+                                    ctl->server.via, ctl->remotename);
+                   if (p && p->password)
+                       ctl->password = xstrdup(p->password);
+               }
+           }
+       }
+    }
+
     /* perhaps we just want to check options? */
     if (versioninfo)
     {
@@ -388,79 +446,25 @@ int main (int argc, char **argv)
        }
     }
 
-    /* parse the ~/.netrc file (if present) for future password lookups. */
-    xalloca(netrc_file, char *, strlen (home) + 8);
-    strcpy (netrc_file, home);
-    strcat (netrc_file, "/.netrc");
-    netrc_list = parse_netrc(netrc_file);
-
-#ifdef HAVE_SETRLIMIT
-    /*
-     * Before getting passwords, disable core dumps unless -v -d0 mode is on.
-     * Core dumps could otherwise contain passwords to be scavenged by a
-     * cracker.
-     */
-    if (outlevel < O_VERBOSE || run.poll_interval > 0)
-    {
-       struct rlimit corelimit;
-       corelimit.rlim_cur = 0;
-       corelimit.rlim_max = 0;
-       setrlimit(RLIMIT_CORE, &corelimit);
-    }
-#endif /* HAVE_SETRLIMIT */
-
     /* pick up interactively any passwords we need but don't have */ 
     for (ctl = querylist; ctl; ctl = ctl->next)
     {
-       if (ctl->active && !(implicitmode && ctl->server.skip)&&!ctl->password)
-       {
-           if (ctl->server.preauthenticate == A_KERBEROS_V4 ||
-               ctl->server.preauthenticate == A_KERBEROS_V5 ||
-#ifdef GSSAPI
-               ctl->server.protocol == P_IMAP_GSS ||
-#endif /* GSSAPI */
-               ctl->server.protocol == P_IMAP_K4)
-               /* Server won't care what the password is, but there
-                  must be some non-null string here.  */
-               ctl->password = ctl->remotename;
-           else
-           {
-               netrc_entry *p;
-
-               /* look up the pollname and account in the .netrc file. */
-               p = search_netrc(netrc_list, ctl->server.pollname);
-               while (p && strcmp(p->account, ctl->remotename))
-                   p = search_netrc(p->next, ctl->remotename);
-               /* if we find a matching entry with a password, use it */
-               if (p && p->password)
-                   ctl->password = xstrdup(p->password);
-
-               /* otherwise try with "via" name if there is one */
-               else if (ctl->server.via)
-               {
-                   p = search_netrc(netrc_list, ctl->server.via);
-                   while (p && strcmp(p->account, ctl->remotename))
-                       p = search_netrc(p->next, ctl->remotename);
-                   if (p && p->password)
-                       ctl->password = xstrdup(p->password);
-               }
-           }
-
-           if (ctl->server.protocol != P_ETRN && ctl->server.protocol != P_IMAP_K4
+       if (ctl->active && !(implicitmode && ctl->server.skip)
+           && ctl->server.protocol != P_ETRN 
+           && ctl->server.protocol != P_IMAP_K4
 #ifdef GSSAPI
-                && ctl->server.protocol != P_IMAP_GSS
+           && ctl->server.protocol != P_IMAP_GSS
 #endif /* GSSAPI */
-                && !ctl->password)
-           {
-               char* password_prompt = _("Enter password for %s@%s: ");
-
-               xalloca(tmpbuf, char *, strlen(password_prompt) +
-                                       strlen(ctl->remotename) +
-                                       strlen(ctl->server.pollname) + 1);
-               (void) sprintf(tmpbuf, password_prompt,
-                              ctl->remotename, ctl->server.pollname);
-               ctl->password = xstrdup((char *)getpassword(tmpbuf));
-           }
+           && !ctl->password)
+       {
+           char* password_prompt = _("Enter password for %s@%s: ");
+
+           xalloca(tmpbuf, char *, strlen(password_prompt) +
+                   strlen(ctl->remotename) +
+                   strlen(ctl->server.pollname) + 1);
+           (void) sprintf(tmpbuf, password_prompt,
+                          ctl->remotename, ctl->server.pollname);
+           ctl->password = xstrdup((char *)getpassword(tmpbuf));
        }
     }
 
@@ -874,6 +878,8 @@ static int load_params(int argc, char **argv, int optind)
     struct passwd *pw;
     struct query def_opts, *ctl;
 
+    run.bouncemail = TRUE;
+
     memset(&def_opts, '\0', sizeof(struct query));
     def_opts.smtp_socket = -1;
     def_opts.smtpaddress = (char *)0;
@@ -885,7 +891,6 @@ static int load_params(int argc, char **argv, int optind)
     def_opts.server.timeout = CLIENT_TIMEOUT;
     def_opts.warnings = WARNING_INTERVAL;
     def_opts.remotename = user;
-    def_opts.expunge = 1;
     def_opts.listener = SMTP_MODE;
 
     /* this builds the host list */
@@ -1161,6 +1166,8 @@ static int load_params(int argc, char **argv, int optind)
        run.use_syslog = (cmd_run.use_syslog == FLAG_TRUE);
     if (cmd_run.postmaster)
        run.postmaster = cmd_run.postmaster;
+    if (cmd_run.bouncemail)
+       run.bouncemail = cmd_run.bouncemail;
 
     /* check and daemon options are not compatible */
     if (check_only && run.poll_interval)
@@ -1258,11 +1265,12 @@ static int query_host(struct query *ctl)
 {
     int i, st;
 
-    if (outlevel >= O_VERBOSE)
+    /*
+     * If we're syslogging the progress messages are automatically timestamped.
+     * Force timestamping if we're going to a logfile.
+     */
+    if (outlevel >= O_VERBOSE || (run.logfile && outlevel > O_SILENT))
     {
-       time_t now;
-
-       time(&now);
        report(stdout, _("%s querying %s (protocol %s) at %s\n"),
               VERSION,
               ctl->server.pollname,
@@ -1279,7 +1287,6 @@ static int query_host(struct query *ctl)
        }
        ctl->server.protocol = P_AUTO;
        return(st);
-       break;
     case P_POP2:
 #ifdef POP2_ENABLE
        return(doPOP2(ctl));
@@ -1309,7 +1316,6 @@ static int query_host(struct query *ctl)
        report(stderr, _("IMAP support is not configured.\n"));
        return(PS_PROTOCOL);
 #endif /* IMAP_ENABLE */
-       break;
     case P_ETRN:
 #ifndef ETRN_ENABLE
        report(stderr, _("ETRN support is not configured.\n"));
@@ -1350,6 +1356,11 @@ static void dump_params (struct runctl *runp,
        printf(_("Fetchmail will forward misaddressed multidrop messages to %s.\n"),
               runp->postmaster);
 
+    if (!runp->bouncemail)
+       printf(_("Fetchmail will direct error mail to the postmaster.\n"));
+    else if (outlevel >= O_VERBOSE)
+       printf(_("Fetchmail will direct error mail to the sender.\n"));
+
     for (ctl = querylist; ctl; ctl = ctl->next)
     {
        if (!ctl->active || (implicit && ctl->server.skip))
@@ -1375,9 +1386,9 @@ static void dump_params (struct runctl *runp,
         */
        if (!ctl->password && (ctl->server.protocol != P_ETRN)
 #ifdef GSSAPI
-            && (ctl->server.protocol != P_IMAP_GSS)
+               && (ctl->server.protocol != P_IMAP_GSS)
 #endif /* GSSAPI */
-        )
+               && ctl->server.protocol != P_IMAP_K4)
            printf(_("  Password will be prompted for.\n"));
        else if (outlevel >= O_VERBOSE)
            if (ctl->server.protocol == P_APOP)
@@ -1487,9 +1498,9 @@ static void dump_params (struct runctl *runp,
                    printf(_("  No SMTP message batch limit (--batchlimit 0).\n"));
                if (ctl->server.protocol == P_IMAP)
                    if (NUM_NONZERO(ctl->expunge))
-                       printf(_("  Deletion interval between expunges is %d (--expunge %d).\n"), ctl->expunge, ctl->expunge);
+                       printf(_("  Deletion interval between expunges forced to %d (--expunge %d).\n"), ctl->expunge, ctl->expunge);
                    else if (outlevel >= O_VERBOSE)
-                       printf(_("  No expunges (--expunge 0).\n"));
+                       printf(_("  No forced expunges (--expunge 0).\n"));
        }
        if (ctl->bsmtp)
            printf(_("  Messages will be appended to %s as BSMTP\n"), visbuf(ctl->bsmtp));