Skip to content

Commit

Permalink
Make looking up rDNS a hook
Browse files Browse the repository at this point in the history
  • Loading branch information
baudehlo committed Aug 9, 2011
1 parent 07a8100 commit f2b1142
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,7 @@ function setupClient(self) {
self.process_data(data);
});

dns.reverse(self.remote_ip, function(err, domains) {
if (err) {
switch (err.code) {
case dns.NXDOMAIN: self.remote_host = 'NXDOMAIN'; break;
default: self.remote_host = 'DNSERROR'; break;
}
}
else {
self.remote_host = domains[0] || 'Unknown';
}
self.remote_info = self.remote_info || self.remote_host;

plugins.run_hooks('connect', self);
});
plugins.run_hooks('lookup_rdns', self);
}

function Connection(client) {
Expand Down Expand Up @@ -248,6 +235,43 @@ Connection.prototype.init_transaction = function() {
/////////////////////////////////////////////////////////////////////////////
// SMTP Responses

Connection.prototype.lookup_rdns_respond = function (retval, msg) {
switch(retval) {
case constants.ok:
this.remote_host = msg || 'Unknown';
plugins.run_hooks('connect', this);
break;
case constants.deny:
case constants.denydisconnect:
case constants.disconnect:
this.respond(500, msg || "rDNS Lookup Failed");
this.disconnect();
break;
case constants.denysoft:
this.respond(450, msg || "rDNS Temporary Failure");
break;
default:
var self = this;
dns.reverse(this.remote_ip, function(err, domains) {
self.rdns_response(err, domains);
})
}
}

Connection.prototype.rdns_response = function (err, domains) {
if (err) {
switch (err.code) {
case dns.NXDOMAIN: this.remote_host = 'NXDOMAIN'; break;
default: this.remote_host = 'DNSERROR'; break;
}
}
else {
this.remote_host = domains[0] || 'Unknown';
}
this.remote_info = this.remote_info || this.remote_host;
plugins.run_hooks('connect', this);
}

Connection.prototype.unrecognized_command_respond = function(retval, msg) {
switch(retval) {
case constants.ok:
Expand Down

0 comments on commit f2b1142

Please sign in to comment.