Software /
code /
prosody
Changeset
286:7e4908d4bdf6
Merge with Waqas changes to mod_saslauth.
author | Tobias Markmann <tm@ayena.de> |
---|---|
date | Sat, 15 Nov 2008 19:25:51 +0100 (2008-11-15) |
parents | 285:372d0891e8fd (current diff) 284:4f540755260c (diff) |
children | 288:dc53343af9ac |
files | plugins/mod_saslauth.lua |
diffstat | 1 files changed, 19 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_saslauth.lua Sat Nov 15 19:23:55 2008 +0100 +++ b/plugins/mod_saslauth.lua Sat Nov 15 19:25:51 2008 +0100 @@ -53,43 +53,26 @@ return func, nil; end +function do_sasl(session, stanza) + local text = stanza[1]; + if text then + text = base64.decode(text); + if not text then + session.sasl_handler = nil; + session.send(build_reply("failure", "incorrect-encoding")); + return; + end + end + local status, ret = session.sasl_handler:feed(text); + handle_status(session, status); + session.send(build_reply(status, ret)); +end + add_handler("c2s_unauthed", "auth", xmlns_sasl, function (session, stanza) if not session.sasl_handler then session.sasl_handler = new_sasl(stanza.attr.mechanism, session.host, password_callback); - local status, ret = session.sasl_handler:feed(stanza[1]); - handle_status(session, status); - session.send(build_reply(status, ret)); - --[[session.sasl_handler = new_sasl(stanza.attr.mechanism, - function (username, password) - -- onAuth - require "core.usermanager" - if usermanager_validate_credentials(session.host, username, password) then - return true; - end - return false; - end, - function (username) - -- onSuccess - local success, err = sessionmanager.make_authenticated(session, username); - if not success then - sessionmanager.destroy_session(session); - return; - end - session.sasl_handler = nil; - session:reset_stream(); - end, - function (reason) - -- onFail - log("debug", "SASL failure, reason: %s", reason); - end, - function (stanza) - -- onWrite - log("debug", "SASL writes: %s", tostring(stanza)); - send(session, stanza); - end - ); - session.sasl_handler:feed(stanza); ]] + do_sasl(session, stanza); else error("Client tried to negotiate SASL again", 0); end @@ -98,19 +81,15 @@ add_handler("c2s_unauthed", "abort", xmlns_sasl, function(session, stanza) if not session.sasl_handler then error("Attempt to abort when sasl has not started"); end - local status, ret = session.sasl_handler:feed(stanza[1]); - handle_status(session, status); - session.send(build_reply(status, ret)); + do_sasl(session, stanza); end); add_handler("c2s_unauthed", "response", xmlns_sasl, function(session, stanza) if not session.sasl_handler then error("Attempt to respond when sasl has not started"); end - local status, ret = session.sasl_handler:feed(stanza[1]); - handle_status(session, status); - session.send(build_reply(status, ret)); + do_sasl(session, stanza); end); - + add_event_hook("stream-features", function (session, features) if not session.username then