comparison mod_auth_dovecot/mod_auth_dovecot.lua @ 272:6b35c23664db

mod_auth_dovecot: Use sequential (instead of fixed) id for messages
author Javier Torres <javitonino@gmail.com>
date Sat, 30 Oct 2010 23:39:40 +0200
parents 05ea4abb664d
children 8d283ae7f29d
comparison
equal deleted inserted replaced
271:05ea4abb664d 272:6b35c23664db
15 15
16 local prosody = _G.prosody; 16 local prosody = _G.prosody;
17 local socket_path = module:get_option_string("dovecot_auth_socket", "/var/run/dovecot/auth-login"); 17 local socket_path = module:get_option_string("dovecot_auth_socket", "/var/run/dovecot/auth-login");
18 18
19 function new_default_provider(host) 19 function new_default_provider(host)
20 local provider = { name = "dovecot", c = nil }; 20 local provider = { name = "dovecot", c = nil, request_id = 0 };
21 log("debug", "initializing dovecot authentication provider for host '%s'", host); 21 log("debug", "initializing dovecot authentication provider for host '%s'", host);
22 22
23 -- Closes the socket 23 -- Closes the socket
24 function provider.close(self) 24 function provider.close(self)
25 if (provider.c ~= nil) then 25 if (provider.c ~= nil) then
126 end 126 end
127 127
128 -- Send auth data 128 -- Send auth data
129 username = username .. "@" .. module.host; -- FIXME: this is actually a hack for my server 129 username = username .. "@" .. module.host; -- FIXME: this is actually a hack for my server
130 local b64 = base64.encode(username .. "\0" .. username .. "\0" .. password); 130 local b64 = base64.encode(username .. "\0" .. username .. "\0" .. password);
131 local id = "54321"; -- FIXME: probably can just be a fixed value if making one request per connection 131 provider.request_id = provider.request_id + 1
132 if (not provider:send("AUTH\t" .. id .. "\tPLAIN\tservice=XMPP\tresp=" .. b64 .. "\n")) then 132 if (not provider:send("AUTH\t" .. provider.request_id .. "\tPLAIN\tservice=XMPP\tresp=" .. b64 .. "\n")) then
133 return nil, "Auth failed. Dovecot communications error"; 133 return nil, "Auth failed. Dovecot communications error";
134 end 134 end
135
135 136
136 -- Get response 137 -- Get response
137 local l = provider:receive(); 138 local l = provider:receive();
138 if (not l) then 139 if (not l) then
139 return nil, "Auth failed. Dovecot communications error"; 140 return nil, "Auth failed. Dovecot communications error";