Changeset

340:5d306466f3f6

mod_auth_dovecot: Use hash of vhost as PID to pass to dovecot - the ID must be unique per process, whereas we make a connection per vhost.
author Matthew Wild <mwild1@gmail.com>
date Mon, 14 Feb 2011 01:27:35 +0000
parents 339:5aa8229e8815
children 341:f801ce6826d5
files mod_auth_dovecot/mod_auth_dovecot.lua
diffstat 1 files changed, 3 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mod_auth_dovecot/mod_auth_dovecot.lua	Sun Feb 13 23:30:11 2011 +0100
+++ b/mod_auth_dovecot/mod_auth_dovecot.lua	Mon Feb 14 01:27:35 2011 +0000
@@ -12,7 +12,7 @@
 local new_sasl = require "util.sasl".new;
 local nodeprep = require "util.encodings".stringprep.nodeprep;
 local base64 = require "util.encodings".base64;
-local pposix = require "util.pposix";
+local sha1 = require "util.hashes".sha1;
 
 local prosody = prosody;
 local socket_path = module:get_option_string("dovecot_auth_socket", "/var/run/dovecot/auth-login");
@@ -22,6 +22,8 @@
 	log("debug", "initializing dovecot authentication provider for host '%s'", host);
 	
 	local conn;
+	-- Generate an id for this connection (must be a 31-bit number, unique per process)
+	local pid = tonumber(sha1(host, true):sub(1, 6), 16);
 	
 	-- Closes the socket
 	function provider.close(self)
@@ -48,7 +50,6 @@
 		end
 		
 		-- Send our handshake
-		local pid = pposix.getpid();
 		log("debug", "sending handshake to dovecot. version 1.1, cpid '%d'", pid);
 		if not provider:send("VERSION\t1\t1\n") then
 			return false