[Exim] Patch: local hostname lookup before HELO

Página superior
Eliminar este mensaje
Responder a este mensaje
Autor: Vadim Vygonets
Fecha:  
A: exim-users
Asunto: [Exim] Patch: local hostname lookup before HELO
This is useful for dual-homed hosts or hosts with dynamic IP
addresses. Like for my home machine, which thinks it's
zaphod.vygo.net but in fact is something like
di3-31.dialin.huji.ac.il when it's online.

This patch (against 3.13) adds a boolean option helo_name_lookup,
which is FALSE by default. When set, it causes Exim to lookup
the hostname of the local interface from which it's connecting
before issuing the HELO or EHLO command. If the lookup fails,
Exim uses primary_hostname.

Rationale:
    1. I don't want other hosts to think I'm lying about my
       hostname.
    2. I was bored.


Yet another proposed code bloat, I know.

Vadik.
diff -uNr ../exim-3.13/src/globals.c src/globals.c
--- ../exim-3.13/src/globals.c    Thu Jan 13 17:00:12 2000
+++ src/globals.c    Fri Feb 25 01:00:26 2000
@@ -327,6 +327,7 @@
 BOOL   headers_sender_verify  = FALSE;
 BOOL   headers_sender_verify_errmsg = FALSE;
 char  *helo_accept_junk_hosts = NULL;
+BOOL   helo_name_lookup       = FALSE;
 BOOL   helo_strict_syntax     = FALSE;
 char  *helo_verify            = NULL;
 char  *hold_domains           = NULL;
diff -uNr ../exim-3.13/src/globals.h src/globals.h
--- ../exim-3.13/src/globals.h    Thu Jan 13 17:00:12 2000
+++ src/globals.h    Fri Feb 25 00:58:19 2000
@@ -207,6 +207,7 @@
 extern BOOL   headers_sender_verify;  /* TRUE to verify sender from headers */
 extern BOOL   headers_sender_verify_errmsg; /* ditto, only if errmsg */
 extern char  *helo_accept_junk_hosts; /* Allowed to use junk args */
+extern BOOL   helo_name_lookup;       /* Lookup local hostname before HELO */
 extern BOOL   helo_strict_syntax;     /* Allows _ in name if false */
 extern char  *helo_verify;            /* Check HELO argument */
 extern char  *hold_domains;           /* Hold up deliveries to these */
diff -uNr ../exim-3.13/src/readconf.c src/readconf.c
--- ../exim-3.13/src/readconf.c    Thu Jan 13 17:00:16 2000
+++ src/readconf.c    Fri Feb 25 01:01:47 2000
@@ -83,6 +83,7 @@
   { "headers_sender_verify",    opt_bool,        &headers_sender_verify },
   { "headers_sender_verify_errmsg", opt_bool,    &headers_sender_verify_errmsg },
   { "helo_accept_junk_hosts",   opt_stringptr,   &helo_accept_junk_hosts },
+  { "helo_name_lookup",         opt_bool,        &helo_name_lookup },
   { "helo_strict_syntax",       opt_bool,        &helo_strict_syntax },
   { "helo_verify",              opt_stringptr,   &helo_verify },
   { "hold_domains",             opt_stringptr,   &hold_domains },
diff -uNr ../exim-3.13/src/transports/smtp.c src/transports/smtp.c
--- ../exim-3.13/src/transports/smtp.c    Thu Jan 13 17:00:17 2000
+++ src/transports/smtp.c    Fri Feb 25 01:33:06 2000
@@ -478,6 +478,7 @@
 smtp_transport_options_block *ob =
   (smtp_transport_options_block *)(tblock->options_block);
 int max_rcpt = ob->max_rcpt;
+const char *helo_name = primary_hostname;
 char *p;
 char new_message_id[MESSAGE_ID_LENGTH + 1];
 char buffer[4096];
@@ -500,6 +501,30 @@
     return DEFER;
     }


+  /* If helo_name_lookup is set, before getting the OK response (and while the
+  remote host possibly looks up our IP address), we'd better lookup our local
+  hostname to use in HELO or EHLO command. */
+
+  if (helo_name_lookup) {
+    #if HAVE_IPV6
+    struct sockaddr_in6 sin;
+    #define SIN_FAMILY sin6_family
+    #define SIN_ADDR sin6_addr
+    #else
+    struct sockaddr_in sin;
+    #define SIN_FAMILY sin_family
+    #define SIN_ADDR sin_addr
+    #endif
+    struct hostent *hep;
+    int len = sizeof(sin);
+
+    bzero(&sin, sizeof(sin));
+    if (getsockname(sock, (struct sockaddr *)&sin, &len) != -1 &&
+        (hep = gethostbyaddr((char *)&sin.SIN_ADDR, sizeof(sin.SIN_ADDR),
+                 sin.SIN_FAMILY)) != NULL)
+      helo_name = hep->h_name;
+  }
+
   /* The first thing is to wait for an initial OK response. The dreaded "goto"
   is nevertheless a reasonably clean way of programming this kind of logic,
   where you want to escape on any error. */
@@ -534,13 +559,13 @@
   esmtp = strstr(buffer, "ESMTP") != NULL;


   if (!smtp_write_command(sock, "%s %s\r\n", esmtp? "EHLO":"HELO",
-    primary_hostname)) goto SEND_FAILED;
+    helo_name)) goto SEND_FAILED;


   if (!smtp_read_response(sock, buffer, sizeof(buffer), '2',
        ob->command_timeout))
     {
     if (!esmtp || errno != 0 || buffer[0] == 0) goto RESPONSE_FAILED;
-    if (!smtp_write_command(sock, "HELO %s\r\n", primary_hostname))
+    if (!smtp_write_command(sock, "HELO %s\r\n", helo_name))
       goto SEND_FAILED;
     if (!smtp_read_response(sock, buffer, sizeof(buffer), '2',
       ob->command_timeout)) goto RESPONSE_FAILED;