# HG changeset patch # User Matthew Wild # Date 1254049850 -3600 # Node ID 5ae3209fefa2c8dc1c53d08c2c1caa340b8ec542 # Parent d5a1fd78a06aa493d33490a7896417f09f823965# Parent 5408d5100bd0722982ba1e0736f2cc8bd763f1d7 Merge with waqas diff -r d5a1fd78a06a -r 5ae3209fefa2 plugins/mod_legacyauth.lua --- a/plugins/mod_legacyauth.lua Sun Sep 27 12:10:36 2009 +0100 +++ b/plugins/mod_legacyauth.lua Sun Sep 27 12:10:50 2009 +0100 @@ -16,6 +16,8 @@ local sessionmanager = require "core.sessionmanager"; local usermanager = require "core.usermanager"; +local nodeprep = require "util.encodings".stringprep.nodeprep; +local resourceprep = require "util.encodings".stringprep.resourceprep; module:add_feature("jabber:iq:auth"); module:add_event_hook("stream-features", function (session, features) @@ -46,9 +48,11 @@ return true; else username, password, resource = t_concat(username), t_concat(password), t_concat(resource); + username = nodeprep(username); + resource = resourceprep(resource) local reply = st.reply(stanza); require "core.usermanager" - if usermanager.validate_credentials(session.host, username, password) then + if username and resource and usermanager.validate_credentials(session.host, username, password) then -- Authentication successful! local success, err = sessionmanager.make_authenticated(session, username); if success then @@ -56,6 +60,11 @@ success, err_type, err, err_msg = sessionmanager.bind_resource(session, resource); if not success then session.send(st.error_reply(stanza, err_type, err, err_msg)); + session.username, session.type = nil, "c2s_unauthed"; -- FIXME should this be placed in sessionmanager? + return true; + elseif resource ~= session.resource then -- server changed resource, not supported by legacy auth + session.send(st.error_reply(stanza, "cancel", "conflict", "The requested resource could not be assigned to this session.")); + session:close(); -- FIXME undo resource bind and auth instead of closing the session? return true; end end