70 end |
70 end |
71 end |
71 end |
72 return status, ret, err_msg; |
72 return status, ret, err_msg; |
73 end |
73 end |
74 |
74 |
|
75 local function sasl_process_cdata(session, stanza) |
|
76 local text = stanza[1]; |
|
77 if text then |
|
78 text = base64.decode(text); |
|
79 --log("debug", "AUTH: %s", text:gsub("[%z\001-\008\011\012\014-\031]", " ")); |
|
80 if not text then |
|
81 session.sasl_handler = nil; |
|
82 session.send(build_reply("failure", "incorrect-encoding")); |
|
83 return true; |
|
84 end |
|
85 end |
|
86 local status, ret, err_msg = session.sasl_handler:process(text); |
|
87 status, ret, err_msg = handle_status(session, status, ret, err_msg); |
|
88 local s = build_reply(status, ret, err_msg); |
|
89 log("debug", "sasl reply: %s", tostring(s)); |
|
90 session.send(s); |
|
91 return true; |
|
92 end |
|
93 |
75 local function sasl_handler(event) |
94 local function sasl_handler(event) |
76 local session, stanza = event.origin, event.stanza; |
95 local session, stanza = event.origin, event.stanza; |
77 if session.type ~= "c2s_unauthed" then return; end |
96 if session.type ~= "c2s_unauthed" then return; end |
78 |
97 |
79 if stanza.name == "auth" then |
98 if stanza.name == "auth" then |
98 return true; |
117 return true; |
99 end |
118 end |
100 elseif not session.sasl_handler then |
119 elseif not session.sasl_handler then |
101 return true; -- FIXME ignoring out of order stanzas because ejabberd does |
120 return true; -- FIXME ignoring out of order stanzas because ejabberd does |
102 end |
121 end |
103 local text = stanza[1]; |
122 return sasl_process_cdata(session, stanza); |
104 if text then |
|
105 text = base64.decode(text); |
|
106 --log("debug", "AUTH: %s", text:gsub("[%z\001-\008\011\012\014-\031]", " ")); |
|
107 if not text then |
|
108 session.sasl_handler = nil; |
|
109 session.send(build_reply("failure", "incorrect-encoding")); |
|
110 return true; |
|
111 end |
|
112 end |
|
113 local status, ret, err_msg = session.sasl_handler:process(text); |
|
114 status, ret, err_msg = handle_status(session, status, ret, err_msg); |
|
115 local s = build_reply(status, ret, err_msg); |
|
116 log("debug", "sasl reply: %s", tostring(s)); |
|
117 session.send(s); |
|
118 return true; |
|
119 end |
123 end |
120 |
124 |
121 module:hook("stanza/urn:ietf:params:xml:ns:xmpp-sasl:auth", sasl_handler); |
125 module:hook("stanza/urn:ietf:params:xml:ns:xmpp-sasl:auth", sasl_handler); |
122 module:hook("stanza/urn:ietf:params:xml:ns:xmpp-sasl:response", sasl_handler); |
126 module:hook("stanza/urn:ietf:params:xml:ns:xmpp-sasl:response", sasl_handler); |
123 module:hook("stanza/urn:ietf:params:xml:ns:xmpp-sasl:abort", function(event) |
127 module:hook("stanza/urn:ietf:params:xml:ns:xmpp-sasl:abort", function(event) |