Comparison

plugins/mod_legacyauth.lua @ 38:3fdfd6e0cb4e

SASL! (but before you get too excited, no resource binding yet. And yes, there are still plenty of rough edges to the code...) ((eg. must move <stream:features> out of xmlhandlers.lua o_O ))
author Matthew Wild <mwild1@gmail.com>
date Thu, 02 Oct 2008 01:08:58 +0100
parent 30:bcf539295f2d
child 45:363c0af290bc
comparison
equal deleted inserted replaced
37:06eadafafefa 38:3fdfd6e0cb4e
19 username, password, resource = t_concat(username), t_concat(password), t_concat(resource); 19 username, password, resource = t_concat(username), t_concat(password), t_concat(resource);
20 local reply = st.reply(stanza); 20 local reply = st.reply(stanza);
21 require "core.usermanager" 21 require "core.usermanager"
22 if usermanager.validate_credentials(session.host, username, password) then 22 if usermanager.validate_credentials(session.host, username, password) then
23 -- Authentication successful! 23 -- Authentication successful!
24 session.username = username; 24 local success, err = sessionmanager.make_authenticated(session, username);
25 session.resource = resource; 25 if success then
26 session.full_jid = username.."@"..session.host.."/"..session.resource; 26 success, err = sessionmanager.bind_resource(session, resource);
27 if session.type == "c2s_unauthed" then 27 --FIXME: Reply with error
28 session.type = "c2s"; 28 if not success then
29 local reply = st.reply(stanza);
30 reply.attr.type = "error";
31 if err == "conflict" then
32 reply:tag("error", { code = "409", type = "cancel" })
33 :tag("conflict", { xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas" });
34 elseif err == "constraint" then
35 reply:tag("error", { code = "409", type = "cancel" })
36 :tag("already-bound", { xmlns = "x-lxmppd:extensions:legacyauth" });
37 elseif err == "auth" then
38 reply:tag("error", { code = "401", type = "auth" })
39 :tag("not-authorized", { xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas" });
40 end
41 dispatch_stanza(reply);
42 return true;
43 end
29 end 44 end
30 if not hosts[session.host].sessions[username] then
31 hosts[session.host].sessions[username] = { sessions = {} };
32 end
33 hosts[session.host].sessions[username].sessions[resource] = session;
34 send(session, st.reply(stanza)); 45 send(session, st.reply(stanza));
35 return true; 46 return true;
36 else 47 else
37 local reply = st.reply(stanza); 48 local reply = st.reply(stanza);
38 reply.attr.type = "error"; 49 reply.attr.type = "error";