Software /
code /
prosody-modules
Comparison
mod_auth_dovecot/mod_auth_dovecot.lua @ 273:8d283ae7f29d
mod_auth_dovecot: More debug messages
author | Javier Torres <javitonino@gmail.com> |
---|---|
date | Sun, 31 Oct 2010 00:27:17 +0200 |
parent | 272:6b35c23664db |
child | 274:cda4855863af |
comparison
equal
deleted
inserted
replaced
272:6b35c23664db | 273:8d283ae7f29d |
---|---|
34 provider:close(); | 34 provider:close(); |
35 | 35 |
36 provider.c = socket.unix(); | 36 provider.c = socket.unix(); |
37 | 37 |
38 -- Create a connection to dovecot socket | 38 -- Create a connection to dovecot socket |
39 log("debug", "connecting to dovecot socket at '%s'", socket_path); | |
39 local r, e = provider.c:connect(socket_path); | 40 local r, e = provider.c:connect(socket_path); |
40 if (not r) then | 41 if (not r) then |
41 log("warn", "error connecting to dovecot socket at '%s'. error was '%s'. check permissions", socket_path, e); | 42 log("warn", "error connecting to dovecot socket at '%s'. error was '%s'. check permissions", socket_path, e); |
42 provider:close(); | 43 provider:close(); |
43 return false; | 44 return false; |
44 end | 45 end |
45 | 46 |
46 -- Send our handshake | 47 -- Send our handshake |
47 local pid = pposix.getpid(); | 48 local pid = pposix.getpid(); |
49 log("debug", "sending handshake to dovecot. version 1.1, cpid '%d'", pid); | |
48 if not provider:send("VERSION\t1\t1\n") then | 50 if not provider:send("VERSION\t1\t1\n") then |
49 return false | 51 return false |
50 end | 52 end |
51 if (not provider:send("CPID\t" .. pid .. "\n")) then | 53 if (not provider:send("CPID\t" .. pid .. "\n")) then |
52 return false | 54 return false |
58 local l = provider:receive(); | 60 local l = provider:receive(); |
59 if (not l) then | 61 if (not l) then |
60 return false; | 62 return false; |
61 end | 63 end |
62 | 64 |
65 log("debug", "dovecot handshake: '%s'", l); | |
63 parts = string.gmatch(l, "[^\t]+"); | 66 parts = string.gmatch(l, "[^\t]+"); |
64 first = parts(); | 67 first = parts(); |
65 if (first == "VERSION") then | 68 if (first == "VERSION") then |
66 -- Version should be 1.1 | 69 -- Version should be 1.1 |
67 local v1 = parts(); | 70 local v1 = parts(); |
126 end | 129 end |
127 | 130 |
128 -- Send auth data | 131 -- Send auth data |
129 username = username .. "@" .. module.host; -- FIXME: this is actually a hack for my server | 132 username = username .. "@" .. module.host; -- FIXME: this is actually a hack for my server |
130 local b64 = base64.encode(username .. "\0" .. username .. "\0" .. password); | 133 local b64 = base64.encode(username .. "\0" .. username .. "\0" .. password); |
131 provider.request_id = provider.request_id + 1 | 134 provider.request_id = provider.request_id + 1 % 4294967296 |
132 if (not provider:send("AUTH\t" .. provider.request_id .. "\tPLAIN\tservice=XMPP\tresp=" .. b64 .. "\n")) then | 135 |
136 local msg = "AUTH\t" .. provider.request_id .. "\tPLAIN\tservice=XMPP\tresp=" .. b64; | |
137 log("debug", "sending auth request for '%s' with password '%s': '%s'", username, password, msg); | |
138 if (not provider:send(msg .. "\n")) then | |
133 return nil, "Auth failed. Dovecot communications error"; | 139 return nil, "Auth failed. Dovecot communications error"; |
134 end | 140 end |
135 | 141 |
136 | 142 |
137 -- Get response | 143 -- Get response |
138 local l = provider:receive(); | 144 local l = provider:receive(); |
145 log("debug", "got auth response: '%s'", l); | |
139 if (not l) then | 146 if (not l) then |
140 return nil, "Auth failed. Dovecot communications error"; | 147 return nil, "Auth failed. Dovecot communications error"; |
141 end | 148 end |
142 local parts = string.gmatch(l, "[^\t]+"); | 149 local parts = string.gmatch(l, "[^\t]+"); |
143 | 150 |
144 -- Check response | 151 -- Check response |
145 if (parts() == "OK") then | 152 local status = parts(); |
153 local resp_id = tonumber(parts()); | |
154 if (resp_id ~= provider.request_id) then | |
155 log("warn", "dovecot response_id(%s) doesn't match request_id(%s)", resp_id, provider.request_id); | |
156 provider:close(); | |
157 return nil, "Auth failed. Dovecot communications error"; | |
158 end | |
159 | |
160 if (status == "OK") then | |
161 log("info", "login ok for '%s'", username); | |
146 return true; | 162 return true; |
147 else | 163 else |
164 log("info", "login failed for '%s'", username); | |
148 return nil, "Auth failed. Invalid username or password."; | 165 return nil, "Auth failed. Invalid username or password."; |
149 end | 166 end |
150 end | 167 end |
151 | 168 |
152 function provider.get_password(username) | 169 function provider.get_password(username) |