Software /
code /
prosody
Comparison
plugins/mod_saslauth.lua @ 295:bb078eb1f1de
mod_saslauth: Code cleanup
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 16 Nov 2008 02:27:22 +0500 |
parent | 293:b446de4e258e |
child | 296:21835c4fc34f |
comparison
equal
deleted
inserted
replaced
293:b446de4e258e | 295:bb078eb1f1de |
---|---|
54 end | 54 end |
55 end | 55 end |
56 return func, nil; | 56 return func, nil; |
57 end | 57 end |
58 | 58 |
59 function do_sasl(session, stanza) | 59 function sasl_handler(session, stanza) |
60 if stanza.name == "auth" then | |
61 -- FIXME ignoring duplicates because ejabberd does | |
62 session.sasl_handler = new_sasl(stanza.attr.mechanism, session.host, password_callback); | |
63 elseif not session.sasl_handler then | |
64 return; -- FIXME ignoring out of order stanzas because ejabberd does | |
65 end | |
60 local text = stanza[1]; | 66 local text = stanza[1]; |
61 if text then | 67 if text then |
62 text = base64.decode(text); | 68 text = base64.decode(text); |
63 if not text then | 69 if not text then |
64 session.sasl_handler = nil; | 70 session.sasl_handler = nil; |
71 local s = build_reply(status, ret, err_msg); | 77 local s = build_reply(status, ret, err_msg); |
72 log("debug", "sasl reply: "..tostring(s)); | 78 log("debug", "sasl reply: "..tostring(s)); |
73 session.send(s); | 79 session.send(s); |
74 end | 80 end |
75 | 81 |
76 add_handler("c2s_unauthed", "auth", xmlns_sasl, | 82 add_handler("c2s_unauthed", "auth", xmlns_sasl, sasl_handler); |
77 function (session, stanza) | 83 add_handler("c2s_unauthed", "abort", xmlns_sasl, sasl_handler); |
78 if not session.sasl_handler then | 84 add_handler("c2s_unauthed", "response", xmlns_sasl, sasl_handler); |
79 session.sasl_handler = new_sasl(stanza.attr.mechanism, session.host, password_callback); | |
80 do_sasl(session, stanza); | |
81 else | |
82 error("Client tried to negotiate SASL again", 0); | |
83 end | |
84 end); | |
85 | |
86 add_handler("c2s_unauthed", "abort", xmlns_sasl, | |
87 function(session, stanza) | |
88 if not session.sasl_handler then error("Attempt to abort when sasl has not started"); end | |
89 do_sasl(session, stanza); | |
90 end); | |
91 | |
92 add_handler("c2s_unauthed", "response", xmlns_sasl, | |
93 function(session, stanza) | |
94 if not session.sasl_handler then error("Attempt to respond when sasl has not started"); end | |
95 do_sasl(session, stanza); | |
96 end); | |
97 | 85 |
98 add_event_hook("stream-features", | 86 add_event_hook("stream-features", |
99 function (session, features) | 87 function (session, features) |
100 if not session.username then | 88 if not session.username then |
101 t_insert(features, "<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>"); | 89 t_insert(features, "<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>"); |