comparison mod_auth_dovecot/mod_auth_dovecot.lua @ 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 5aa8229e8815
children 8e9e5c7d97ff
comparison
equal deleted inserted replaced
339:5aa8229e8815 340:5d306466f3f6
10 local usermanager = require "core.usermanager"; 10 local usermanager = require "core.usermanager";
11 local log = require "util.logger".init("auth_dovecot"); 11 local log = require "util.logger".init("auth_dovecot");
12 local new_sasl = require "util.sasl".new; 12 local new_sasl = require "util.sasl".new;
13 local nodeprep = require "util.encodings".stringprep.nodeprep; 13 local nodeprep = require "util.encodings".stringprep.nodeprep;
14 local base64 = require "util.encodings".base64; 14 local base64 = require "util.encodings".base64;
15 local pposix = require "util.pposix"; 15 local sha1 = require "util.hashes".sha1;
16 16
17 local prosody = prosody; 17 local prosody = prosody;
18 local socket_path = module:get_option_string("dovecot_auth_socket", "/var/run/dovecot/auth-login"); 18 local socket_path = module:get_option_string("dovecot_auth_socket", "/var/run/dovecot/auth-login");
19 19
20 function new_provider(host) 20 function new_provider(host)
21 local provider = { name = "dovecot", request_id = 0 }; 21 local provider = { name = "dovecot", request_id = 0 };
22 log("debug", "initializing dovecot authentication provider for host '%s'", host); 22 log("debug", "initializing dovecot authentication provider for host '%s'", host);
23 23
24 local conn; 24 local conn;
25 -- Generate an id for this connection (must be a 31-bit number, unique per process)
26 local pid = tonumber(sha1(host, true):sub(1, 6), 16);
25 27
26 -- Closes the socket 28 -- Closes the socket
27 function provider.close(self) 29 function provider.close(self)
28 if conn then 30 if conn then
29 conn:close(); 31 conn:close();
46 provider:close(); 48 provider:close();
47 return false; 49 return false;
48 end 50 end
49 51
50 -- Send our handshake 52 -- Send our handshake
51 local pid = pposix.getpid();
52 log("debug", "sending handshake to dovecot. version 1.1, cpid '%d'", pid); 53 log("debug", "sending handshake to dovecot. version 1.1, cpid '%d'", pid);
53 if not provider:send("VERSION\t1\t1\n") then 54 if not provider:send("VERSION\t1\t1\n") then
54 return false 55 return false
55 end 56 end
56 if not provider:send("CPID\t" .. pid .. "\n") then 57 if not provider:send("CPID\t" .. pid .. "\n") then