Browse Source

ADD: some more information to the headers injected into the emails by hermes

ps 6 years ago
parent
commit
53acbb57c8
5 changed files with 36 additions and 3 deletions
  1. 7 3
      src/Proxy.cpp
  2. 9 0
      src/Socket.cpp
  3. 1 0
      src/Socket.h
  4. 18 0
      src/Utils.cpp
  5. 1 0
      src/Utils.h

+ 7 - 3
src/Proxy.cpp

@@ -260,10 +260,14 @@ void Proxy::run(string &peer_address)
 
           outside.writeLine(strtemp);
           strtemp="";
+          string ssltls="";
+          if (outside.is_ssl_enabled())
+            ssltls=" (SSL/TLS)";
+
           if(cfg.getAddHeaders())
           {
             inside.writeLine("Received: from "+ehlostr+" ("+peer_address+")");
-            inside.writeLine("  by "+Utils::gethostname()+" with "+(esmtp?"ESTMP":"SMTP")+" via TCP; "+Utils::rfc2821_date());
+            inside.writeLine("  by "+Utils::gethostname(outside.getFD())+" with "+(esmtp?"ESTMP":"SMTP")+ssltls+" via TCP; "+Utils::rfc2821_date());
             inside.writeLine("X-Anti-Spam-Proxy: Proxied by Hermes [www.hermes-project.com]");
             if(cfg.getAddStatusHeader())
               inside.writeLine("X-Hermes-Status: "+hermes_status);
@@ -300,8 +304,8 @@ void Proxy::run(string &peer_address)
         //or to not advertise it as the last capability.
         if("250 pipelining"==Utils::strtolower(strtemp)||"250 chunking"==Utils::strtolower(strtemp))
           strtemp="250 x-noextension";
-	
-	//try to annoy spammers who send us too many senseless commands by delaying their connection a lot
+
+        //try to annoy spammers who send us too many senseless commands by delaying their connection a lot
         if("502"==code) //502 unimplemented -> count them, if bigger than a certain number, terminate connection
         {
           if(cfg.getNumberOfUnimplementedCommandsAllowed()!=-1&&++unimplemented_requests>cfg.getNumberOfUnimplementedCommandsAllowed())

+ 9 - 0
src/Socket.cpp

@@ -153,6 +153,15 @@ Socket::~Socket()
 }
 
 #ifdef HAVE_SSL
+
+/**
+ * is ssl enabled on the socket?
+ */
+bool Socket::is_ssl_enabled()
+{
+  return ssl_enabled;
+}
+
 /**
  * prepare ssl on the socket
  *

+ 1 - 0
src/Socket.h

@@ -75,6 +75,7 @@ class Socket
     Socket();
     ~Socket();
     #ifdef HAVE_SSL
+    bool is_ssl_enabled();
     void prepareSSL(bool);
     void startSSL(bool);
     #endif //HAVE_SSL

+ 18 - 0
src/Utils.cpp

@@ -622,6 +622,24 @@ string Utils::gethostname()
   return string(buf);
 }
 
+string Utils::gethostname(int s)
+{
+  struct sockaddr_in sa;
+  unsigned int dummy = sizeof sa;
+  struct hostent *hp;
+
+  if (getsockname(s,(struct sockaddr *) &sa,&dummy) == -1)
+    throw Exception("Error getting ip from socket"+Utils::errnotostrerror(errno),__FILE__,__LINE__);
+
+  hp=gethostbyaddr((const void *)&sa.sin_addr,sizeof sa.sin_addr,AF_INET);
+
+  if (hp==NULL)
+    return gethostname();
+
+  return string(hp->h_name);
+}
+
+
 void Utils::write_pid(string file,pid_t pid)
 {
   FILE *f;

+ 1 - 0
src/Utils.h

@@ -82,6 +82,7 @@ class Utils
     static string rfc2821_date(time_t *timestamp=NULL);
     static string gethostname();
     static void write_pid(string,pid_t);
+    static string gethostname(int s);
 };
 
 #endif //UTILS_H