]> Pileus Git - ~andy/fetchmail/commitdiff
Eliminate agethostbyname call in non-ETRN modes.
authorEric S. Raymond <esr@thyrsus.com>
Sun, 2 Aug 1998 18:43:17 +0000 (18:43 -0000)
committerEric S. Raymond <esr@thyrsus.com>
Sun, 2 Aug 1998 18:43:17 +0000 (18:43 -0000)
svn path=/trunk/; revision=2033

NEWS
driver.c
env.c
fetchmail.c
fetchmail.h
fetchmail.man

diff --git a/NEWS b/NEWS
index 8e9a10406ad7ea7e4d0ca724bf1c23292eaea3e1..5824e43e98541ad3ff6040897d8f56bb46f124a7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,12 @@ fetchmail-4.5.5 ():
 * Fixed the spam-block code that I broke in 4.5.3 :-(.
 * Updated the entry on setting up sendmail spam blocks.
 * Added setrlimit call to inhibit core dumps unless debugging is on.
+* The default of smtplist has been changed; the undocumented feature that
+  it always included the fetchmail host's FQDN is gone (this is now
+  true for ETRN mode only).
+* Modes other than ETRN no longer need to know the fetchmail host's FQDN.
+  This eliminates a gethostbyname() call and makes fetchmail more independent
+  of local DNS configuration quirks.
 
 There are 257 people on fetchmail-friends and 255 on fetchmail-announce.
 
index 2ed48634b79d063a2cdd2da362b63766d42511ce..efff0bb28e1d23ce3c454021766cacbe832bffa2 100644 (file)
--- a/driver.c
+++ b/driver.c
@@ -364,7 +364,7 @@ static int smtp_open(struct query *ctl)
         * What it will affect is the listener's logging.
         */
        struct idlist   *idp;
-       char *id_me = run.invisible ? ctl->server.truename : fetchmailhost;
+       char *id_me = run.invisible ? ctl->server.truename : "localhost";
        int oldphase = phase;
 
        errno = 0;
@@ -890,8 +890,8 @@ int num;            /* index of message */
 #else
        sprintf(buf, 
 #endif /* HAVE_SNPRINTF */
-       "From: <FETCHMAIL-DAEMON@%s>\r\nTo: %s@localhost\r\nSubject: Headerless mail from %s's mailbox on %s\r\n",
-               fetchmailhost, user, ctl->remotename, ctl->server.truename);
+       "From: FETCHMAIL-DAEMON\r\nTo: %s@localhost\r\nSubject: Headerless mail from %s's mailbox on %s\r\n",
+               user, ctl->remotename, ctl->server.truename);
        headers = xstrdup(buf);
     }
 
@@ -1360,8 +1360,7 @@ int num;          /* index of message */
             * but this can be secure information that would be bad
             * to reveal.
             */
-           sprintf(buf, "\tby %s (fetchmail-%s %s)\n",
-                   fetchmailhost, 
+           sprintf(buf, "\tby fetchmail-%s %s\n",
                    RELEASE_ID,
                    protocol->name);
            n = stuffline(ctl, buf);
diff --git a/env.c b/env.c
index 453e1449696560ad153fd7762259a5c25a1781b0..67679d19edbae01cb6a16cc4e0ed143de5161818 100644 (file)
--- a/env.c
+++ b/env.c
@@ -55,32 +55,6 @@ void envquery(int argc, char **argv)
        }
     }
 
-    /* we'll need this for the SMTP forwarding target and error messages */
-    if (gethostname(tmpbuf, sizeof(tmpbuf)))
-    {
-       fprintf(stderr, "%s: can't determine your host!", program_name);
-       exit(PS_IOERR);
-    }
-#ifdef HAVE_GETHOSTBYNAME
-    /* if we got a . in the hostname assume it is a FQDN */
-    if (strchr(tmpbuf, '.') == NULL)
-    {
-       struct hostent *hp;
-
-       /* in case we got a basename (as we do in Linux) make a FQDN of it */
-       hp = gethostbyname(tmpbuf);
-       if (hp == (struct hostent *) NULL)
-       {
-           /* exit with error message */
-           fprintf(stderr, "gethostbyname failed for %s\n", tmpbuf);
-           exit(PS_DNS);
-       }
-       fetchmailhost = xstrdup(hp->h_name);
-    }
-    else
-#endif /* HAVE_GETHOSTBYNAME */
-       fetchmailhost = xstrdup(tmpbuf);
-
 #define RCFILE_NAME    ".fetchmailrc"
     rcfile = (char *) xmalloc(strlen(home)+strlen(RCFILE_NAME)+2);
     /* avoid //.fetchmailrc */
index bc841b28bdc080cd1eda5e31eaebd2a39b4402a9..912fdb7b8e5ac628c8bc50ebd1e77ec79049df36 100644 (file)
@@ -67,7 +67,6 @@ flag check_only;      /* if --probe was set */
 flag versioninfo;      /* emit only version info */
 char *user;            /* the name of the invoking user */
 char *home;            /* invoking user's home directory */
-char *fetchmailhost;   /* the name of the host running fetchmail */
 char *program_name;    /* the name to prefix error messages with */
 flag configdump;       /* dump control blocks for configurator */
 
@@ -839,13 +838,48 @@ static int load_params(int argc, char **argv, int optind)
            /* make sure we have a nonempty host list to forward to */
            if (!ctl->smtphunt)
            {
-               save_str(&ctl->smtphunt, fetchmailhost, FALSE);
-               /* for non ETRN try to deliver mails to localhost if
-                * fetchmailhost fails
+               char    tmpbuf[HOSTLEN+1];
+               /*
+                * If we're using ETRN, the smtp hunt list is the list of
+                * systems we're polling on behalf of; these have to be 
+                * fully-qualified domain names.  The default for this list
+                * should be the FQDN of localhost.
                 */
-               if (ctl->server.protocol != P_ETRN) {
-                   save_str(&ctl->smtphunt, "localhost", FALSE);
+               if (ctl->server.protocol == P_ETRN)
+               {
+                   char *fetchmailhost;
+
+                   if (gethostname(tmpbuf, sizeof(tmpbuf)))
+                   {
+                       fprintf(stderr, "%s: can't determine your host!",
+                               program_name);
+                       exit(PS_DNS);
+                   }
+#ifdef HAVE_GETHOSTBYNAME
+                   /* if we got a . in the hostname assume it is a FQDN */
+                   if (strchr(tmpbuf, '.') == NULL)
+                   {
+                       struct hostent *hp;
+
+                       /* if we got a basename (as we do in Linux) make a FQDN of it */
+                       hp = gethostbyname(tmpbuf);
+                       if (hp == (struct hostent *) NULL)
+                       {
+                           /* exit with error message */
+                           fprintf(stderr,
+                                   "gethostbyname failed for %s\n", tmpbuf);
+                           exit(PS_DNS);
+                       }
+                       fetchmailhost = xstrdup(hp->h_name);
+                   }
+                   else
+#endif /* HAVE_GETHOSTBYNAME */
+                       fetchmailhost = xstrdup(tmpbuf);
+
+                   save_str(&ctl->smtphunt, fetchmailhost, FALSE);
                }
+               else
+                   save_str(&ctl->smtphunt, "localhost", FALSE);
            }
 
            /* keep lusers from shooting themselves in the foot :-) */
index c4ce591deb7f7af5e15eaaa92120af5b9fe764b5..21de95d4958eff3631fe362936862865afba6e03 100644 (file)
@@ -276,7 +276,6 @@ extern int linelimit;               /* limit # lines retrieved per site */
 extern flag versioninfo;       /* emit only version info */
 extern char *user;             /* name of invoking user */
 extern char *home;             /* home directory of invoking user */
-extern char *fetchmailhost;    /* the name of the host running fetchmail */
 extern int pass;               /* number of re-polling pass */
 extern flag configdump;                /* dump control blocks as Python dictionary */
 
index 32d58e1d2d12a9de279957a8d0e77f895058e0af..bb9abd54d52698588247b86d75698a274d2e794f 100644 (file)
@@ -220,10 +220,11 @@ Specify a hunt list of hosts to forward mail to (one or more
 hostnames, comma-separated).  In ETRN mode, set the host that the
 mailserver is asked to ship mail to.  Hosts are tried in list order;
 the first one that is up becomes the forwarding or ETRN target for the
-current run.  In all modes except ETRN, `localhost' is added to the
-end of the list as an invisible default.  Each hostname may have a
-'/'-delimited suffix specifying a port or service to forward to; the
-default is 25 (or "smtp" under IPv6). 
+current run.  In ETRN mode, the FQDN of the machine running fetchmail
+is added to the end of the list as an invisible default; in all other
+modes `localhost' is added to the end of the list as an invisible
+default.  Each hostname may have a '/'-delimited suffix specifying a
+port or service to forward to; the default is 25 (or "smtp" under IPv6). 
 .TP
 .B \-D domain, --smtpaddress domain
 (Keyword: smtpaddress)