plugins/mod_legacyauth.lua

changeset 1832
5ae3209fefa2
parent 1830
5408d5100bd0
child 1833
f4c88dd32724
equal deleted inserted replaced
1831:d5a1fd78a06a 1832:5ae3209fefa2
14 local config = require "core.configmanager"; 14 local config = require "core.configmanager";
15 local secure_auth_only = config.get(module:get_host(), "core", "require_encryption"); 15 local secure_auth_only = config.get(module:get_host(), "core", "require_encryption");
16 16
17 local sessionmanager = require "core.sessionmanager"; 17 local sessionmanager = require "core.sessionmanager";
18 local usermanager = require "core.usermanager"; 18 local usermanager = require "core.usermanager";
19 local nodeprep = require "util.encodings".stringprep.nodeprep;
20 local resourceprep = require "util.encodings".stringprep.resourceprep;
19 21
20 module:add_feature("jabber:iq:auth"); 22 module:add_feature("jabber:iq:auth");
21 module:add_event_hook("stream-features", function (session, features) 23 module:add_event_hook("stream-features", function (session, features)
22 if secure_auth_only and not session.secure then 24 if secure_auth_only and not session.secure then
23 -- Sorry, not offering to insecure streams! 25 -- Sorry, not offering to insecure streams!
44 :tag("password"):up() 46 :tag("password"):up()
45 :tag("resource"):up()); 47 :tag("resource"):up());
46 return true; 48 return true;
47 else 49 else
48 username, password, resource = t_concat(username), t_concat(password), t_concat(resource); 50 username, password, resource = t_concat(username), t_concat(password), t_concat(resource);
51 username = nodeprep(username);
52 resource = resourceprep(resource)
49 local reply = st.reply(stanza); 53 local reply = st.reply(stanza);
50 require "core.usermanager" 54 require "core.usermanager"
51 if usermanager.validate_credentials(session.host, username, password) then 55 if username and resource and usermanager.validate_credentials(session.host, username, password) then
52 -- Authentication successful! 56 -- Authentication successful!
53 local success, err = sessionmanager.make_authenticated(session, username); 57 local success, err = sessionmanager.make_authenticated(session, username);
54 if success then 58 if success then
55 local err_type, err_msg; 59 local err_type, err_msg;
56 success, err_type, err, err_msg = sessionmanager.bind_resource(session, resource); 60 success, err_type, err, err_msg = sessionmanager.bind_resource(session, resource);
57 if not success then 61 if not success then
58 session.send(st.error_reply(stanza, err_type, err, err_msg)); 62 session.send(st.error_reply(stanza, err_type, err, err_msg));
63 session.username, session.type = nil, "c2s_unauthed"; -- FIXME should this be placed in sessionmanager?
64 return true;
65 elseif resource ~= session.resource then -- server changed resource, not supported by legacy auth
66 session.send(st.error_reply(stanza, "cancel", "conflict", "The requested resource could not be assigned to this session."));
67 session:close(); -- FIXME undo resource bind and auth instead of closing the session?
59 return true; 68 return true;
60 end 69 end
61 end 70 end
62 session.send(st.reply(stanza)); 71 session.send(st.reply(stanza));
63 return true; 72 return true;

mercurial