diff --git a/src/Proxy.cpp b/src/Proxy.cpp index f5d009b..6036442 100644 --- a/src/Proxy.cpp +++ b/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()) diff --git a/src/Socket.cpp b/src/Socket.cpp index 36c5c97..56ab3c4 100644 --- a/src/Socket.cpp +++ b/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 * diff --git a/src/Socket.h b/src/Socket.h index 453fb86..889c0df 100644 --- a/src/Socket.h +++ b/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 diff --git a/src/Utils.cpp b/src/Utils.cpp index 95504dc..f259547 100644 --- a/src/Utils.cpp +++ b/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; diff --git a/src/Utils.h b/src/Utils.h index 42190d5..ad05f1f 100644 --- a/src/Utils.h +++ b/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