Software /
code /
prosody
Comparison
plugins/mod_saslauth.lua @ 1072:c7967004b5d0
mod_saslauth: Various logging fixes
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 30 Apr 2009 01:39:39 +0100 |
parent | 1071:216f9a9001f1 |
child | 1073:7c20373d4451 |
comparison
equal
deleted
inserted
replaced
1071:216f9a9001f1 | 1072:c7967004b5d0 |
---|---|
30 local new_sasl = require "util.sasl".new; | 30 local new_sasl = require "util.sasl".new; |
31 | 31 |
32 local function build_reply(status, ret, err_msg) | 32 local function build_reply(status, ret, err_msg) |
33 local reply = st.stanza(status, {xmlns = xmlns_sasl}); | 33 local reply = st.stanza(status, {xmlns = xmlns_sasl}); |
34 if status == "challenge" then | 34 if status == "challenge" then |
35 log("debug", ret or ""); | 35 log("debug", "%s", ret or ""); |
36 reply:text(base64.encode(ret or "")); | 36 reply:text(base64.encode(ret or "")); |
37 elseif status == "failure" then | 37 elseif status == "failure" then |
38 reply:tag(ret):up(); | 38 reply:tag(ret):up(); |
39 if err_msg then reply:tag("text"):text(err_msg); end | 39 if err_msg then reply:tag("text"):text(err_msg); end |
40 elseif status == "success" then | 40 elseif status == "success" then |
41 log("debug", ret or ""); | 41 log("debug", "%s", ret or ""); |
42 reply:text(base64.encode(ret or "")); | 42 reply:text(base64.encode(ret or "")); |
43 else | 43 else |
44 error("Unknown sasl status: "..status); | 44 error("Unknown sasl status: "..status); |
45 end | 45 end |
46 return reply; | 46 return reply; |
87 return; -- FIXME ignoring out of order stanzas because ejabberd does | 87 return; -- FIXME ignoring out of order stanzas because ejabberd does |
88 end | 88 end |
89 local text = stanza[1]; | 89 local text = stanza[1]; |
90 if text then | 90 if text then |
91 text = base64.decode(text); | 91 text = base64.decode(text); |
92 log("debug", text); | 92 log("debug", "%s", text); |
93 if not text then | 93 if not text then |
94 session.sasl_handler = nil; | 94 session.sasl_handler = nil; |
95 session.send(build_reply("failure", "incorrect-encoding")); | 95 session.send(build_reply("failure", "incorrect-encoding")); |
96 return; | 96 return; |
97 end | 97 end |
98 end | 98 end |
99 local status, ret, err_msg = session.sasl_handler:feed(text); | 99 local status, ret, err_msg = session.sasl_handler:feed(text); |
100 handle_status(session, status); | 100 handle_status(session, status); |
101 local s = build_reply(status, ret, err_msg); | 101 local s = build_reply(status, ret, err_msg); |
102 log("debug", "sasl reply: "..tostring(s)); | 102 log("debug", "sasl reply: %s", tostring(s)); |
103 session.send(s); | 103 session.send(s); |
104 end | 104 end |
105 | 105 |
106 module:add_handler("c2s_unauthed", "auth", xmlns_sasl, sasl_handler); | 106 module:add_handler("c2s_unauthed", "auth", xmlns_sasl, sasl_handler); |
107 module:add_handler("c2s_unauthed", "abort", xmlns_sasl, sasl_handler); | 107 module:add_handler("c2s_unauthed", "abort", xmlns_sasl, sasl_handler); |
128 end | 128 end |
129 end); | 129 end); |
130 | 130 |
131 module:add_iq_handler("c2s", "urn:ietf:params:xml:ns:xmpp-bind", | 131 module:add_iq_handler("c2s", "urn:ietf:params:xml:ns:xmpp-bind", |
132 function (session, stanza) | 132 function (session, stanza) |
133 log("debug", "Client tried to bind to a resource"); | 133 log("debug", "Client requesting a resource bind"); |
134 local resource; | 134 local resource; |
135 if stanza.attr.type == "set" then | 135 if stanza.attr.type == "set" then |
136 local bind = stanza.tags[1]; | 136 local bind = stanza.tags[1]; |
137 if bind and bind.attr.xmlns == xmlns_bind then | 137 if bind and bind.attr.xmlns == xmlns_bind then |
138 resource = bind:child_with_name("resource"); | 138 resource = bind:child_with_name("resource"); |
151 end | 151 end |
152 end); | 152 end); |
153 | 153 |
154 module:add_iq_handler("c2s", "urn:ietf:params:xml:ns:xmpp-session", | 154 module:add_iq_handler("c2s", "urn:ietf:params:xml:ns:xmpp-session", |
155 function (session, stanza) | 155 function (session, stanza) |
156 log("debug", "Client tried to bind to a resource"); | 156 log("debug", "Client requesting a session"); |
157 session.send(st.reply(stanza)); | 157 session.send(st.reply(stanza)); |
158 end); | 158 end); |