Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

These changes should allow mail_from.is_resolvable to register its own

timeout handler for the case where DNS never comes back (UDP).  In
this case we will DENYSOFT.  The plugin timeout and timeout message is
in mail_from.is_resolvable.ini, and the global plugin timeout for this
plugin is set to 0 in mail_from.is_resolvable.timeout.  The docs are
updated, and while I was working on this I found a bug in the default
timeout value in the code ('' instead of 0).  I fixed this in
plugins/lookup_rdns.strict.js as well as added calls to clear the timeout
when we call next().
  • Loading branch information...
commit 4565d8bc85239537c04dd932788688a7e721d078 1 parent 6cd8777
@godsflaw godsflaw authored
View
3  config/mail_from.is_resolvable.ini
@@ -0,0 +1,3 @@
+[general]
+timeout=60
+timeout_msg=timed out when looking up sender's MX.
View
1  config/mail_from.is_resolvable.timeout
@@ -0,0 +1 @@
+0
View
25 docs/plugins/mail_from.is_resolvable.md
@@ -3,3 +3,28 @@ mail_from.is_resolvable
This plugin checks that the domain used in MAIL FROM is resolvable to an MX
record.
+
+
+Configuration mail_from.is_resolvable.ini
+------------------------------------------
+
+This is the general configuration file for the plugin.
+
+* mail_from.is_resolvable.general.timeout
+
+ How long we should give this plugin before we time it out (seconds).
+
+
+* mail_from.is_resolvable.general.timeout_msg
+
+ Text to send when plugin reaches timeout (text).
+
+
+Configuration mail_from.is_resolvable.timeout
+---------------------------------------------
+
+This is how we specify to Haraka that our plugin should have a certain timeout.
+If you specify 0 here, then the plugin will never timeout while the connection
+is active. This is also required for this plugin, which needs to handle its
+own timeouts. To actually specify the timeout for this plugin, please see
+the general config in mail_from.is_resolvable.ini.
View
7 plugins/lookup_rdns.strict.js
@@ -69,7 +69,7 @@ exports.hook_lookup_rdns = function (next, connection) {
var rev_nxdomain = config.reverse && (config.reverse['nxdomain'] || '');
var rev_dnserror = config.reverse && (config.reverse['dnserror'] || '');
var nomatch = config.general && (config.general['nomatch'] || '');
- var timeout = config.general && (config.general['timeout'] || '');
+ var timeout = config.general && (config.general['timeout'] || 60);
var timeout_msg = config.general && (config.general['timeout_msg'] || '');
timeout_id = setTimeout(function () {
@@ -90,6 +90,7 @@ exports.hook_lookup_rdns = function (next, connection) {
if (err) {
if (!called_next) {
called_next++;
+ clearTimeout(timeout_id);
if (_in_whitelist(plugin, connection.remote_ip)) {
next(OK, connection.remote_ip);
@@ -118,6 +119,7 @@ exports.hook_lookup_rdns = function (next, connection) {
if (err) {
if (!called_next && !total_checks) {
called_next++;
+ clearTimeout(timeout_id);
if (_in_whitelist(plugin, rdns)) {
next(OK, rdns);
@@ -132,6 +134,7 @@ exports.hook_lookup_rdns = function (next, connection) {
// We found a match, call next() and return
if (!called_next) {
called_next++;
+ clearTimeout(timeout_id);
return next(OK, rdns);
}
}
@@ -139,6 +142,8 @@ exports.hook_lookup_rdns = function (next, connection) {
if (!called_next && !total_checks) {
called_next++;
+ clearTimeout(timeout_id);
+
if (_in_whitelist(plugin, rdns)) {
next(OK, rdns);
} else {
View
34 plugins/mail_from.is_resolvable.js
@@ -3,24 +3,46 @@
var dns = require('dns');
exports.hook_mail = function(next, connection, params) {
- var mail_from = params[0];
+ var mail_from = params[0];
+
// Check for MAIL FROM without an @ first - ignore those here
if (!mail_from.host) {
return next();
}
-
- var domain = mail_from.host;
- var plugin = this;
-
- // TODO: this is too simple I think - needs work on handling DNS errors
+
+ var called_next = 0;
+ var timeout_id = 0;
+ var plugin = this;
+ var domain = mail_from.host;
+ var config = this.config.get('mail_from.is_resolvable.ini', 'ini');
+ var timeout = config.general && (config.general['timeout'] || 60);
+ var timeout_msg = config.general && (config.general['timeout_msg'] || '');
+
+ // Just in case DNS never comes back (UDP), we should DENYSOFT.
+ timeout_id = setTimeout(function () {
+ plugin.loginfo('timed out when looking up ' + domain +
+ '\'s MX record. Disconnecting.');
+ called_next++;
+ return next(DENYSOFT, timeout_msg);
+ }, timeout * 1000);
+
dns.resolveMx(domain, function(err, addresses) {
+ if (called_next) {
+ // This happens when we've called next() from our plugin timeout
+ // handler, but we eventually get a response from DNS. We do not
+ // want to call next() again, so we just return.
+ return;
+ }
if (err && err.code != dns.NXDOMAIN && err.code != 'ENOTFOUND') {
plugin.logerror("DNS Error: " + err);
+ clearTimeout(timeout_id);
return next(DENYSOFT, "Temporary resolver error");
}
if (addresses && addresses.length) {
+ clearTimeout(timeout_id);
return next();
}
+ clearTimeout(timeout_id);
return next(DENYSOFT, "No MX for your FROM address");
});
}
Please sign in to comment.
Something went wrong with that request. Please try again.