2 local st = require "util.stanza";
3 local send = require "core.sessionmanager".send_to_session;
5 local usermanager_validate_credentials = require "core.usermanager".validate_credentials;
6 local t_concat = table.concat;
7 local tostring = tostring;
9 local log = require "util.logger".init("mod_saslauth");
11 local xmlns_sasl ='urn:ietf:params:xml:ns:xmpp-sasl';
13 local new_connhandler = require "net.connhandlers".new;
14 local new_sasl = require "util.sasl".new;
16 add_handler("c2s_unauthed", "auth",
17 function (session, stanza)
18 if not session.sasl_handler then
19 session.sasl_handler = new_sasl(stanza.attr.mechanism,
20 function (username, password)
22 require "core.usermanager"
23 if usermanager_validate_credentials(session.host, username, password) then
30 local success, err = sessionmanager.make_authenticated(session, username);
32 sessionmanager.destroy_session(session);
34 session.sasl_handler = nil;
35 session.connhandler = new_connhandler("xmpp-client", session);
36 session.notopen = true;
40 log("debug", "SASL failure, reason: %s", reason);
44 log("debug", "SASL writes: %s", tostring(stanza));
45 send(session, stanza);
48 session.sasl_handler:feed(stanza);
50 error("Client tried to negotiate SASL again", 0);