mod_legacyauth: Don't allow server-generated resource identifiers, as these are not support by legacy auth.
authorWaqas Hussain <waqas20@gmail.com>
Sun, 27 Sep 2009 15:50:41 +0500
changeset 1833 5408d5100bd0
parent 1832 a805e4fe104a
child 1835 5ae3209fefa2
mod_legacyauth: Don't allow server-generated resource identifiers, as these are not support by legacy auth.
plugins/mod_legacyauth.lua
--- a/plugins/mod_legacyauth.lua	Sun Sep 27 15:30:01 2009 +0500
+++ b/plugins/mod_legacyauth.lua	Sun Sep 27 15:50:41 2009 +0500
@@ -52,7 +52,7 @@
 				resource = resourceprep(resource)
 				local reply = st.reply(stanza);
 				require "core.usermanager"
-				if username and 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
@@ -62,6 +62,10 @@
 							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
 					session.send(st.reply(stanza));