Fixed: Self-references could be added to rosters via presence subscriptions
[prosody.git] / plugins / mod_saslauth.lua
index f226203ee4079d5e8b52bc2d92fa7452852e8cbf..8d1e05298bd817de2b42dae9ff3a233dcf886c45 100644 (file)
@@ -1,4 +1,4 @@
--- Prosody IM v0.4
+-- Prosody IM
 -- Copyright (C) 2008-2009 Matthew Wild
 -- Copyright (C) 2008-2009 Waqas Hussain
 -- 
@@ -64,15 +64,15 @@ local function handle_status(session, status)
        end
 end
 
-local function password_callback(node, host, mechanism, decoder)
-       local password = (datamanager_load(node, host, "accounts") or {}).password; -- FIXME handle hashed passwords
+local function password_callback(node, hostname, realm, mechanism, decoder)
+       local password = (datamanager_load(node, hostname, "accounts") or {}).password; -- FIXME handle hashed passwords
        local func = function(x) return x; end;
        if password then
                if mechanism == "PLAIN" then
                        return func, password;
                elseif mechanism == "DIGEST-MD5" then
-                       if decoder then node, host, password = decoder(node), decoder(host), decoder(password); end
-                       return func, md5(node..":"..host..":"..password);
+                       if decoder then node, realm, password = decoder(node), decoder(realm), decoder(password); end
+                       return func, md5(node..":"..realm..":"..password);
                end
        end
        return func, nil;
@@ -121,7 +121,10 @@ local bind_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-bind' };
 local xmpp_session_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-session' };
 module:add_event_hook("stream-features", 
                function (session, features)                                                                                            
-                       if not session.username and ((not secure_auth_only) or session.secure) then
+                       if not session.username then
+                               if secure_auth_only and not session.secure then
+                                       return;
+                               end
                                features:tag("mechanisms", mechanisms_attr);
                                -- TODO: Provide PLAIN only if TLS is active, this is a SHOULD from the introduction of RFC 4616. This behavior could be overridden via configuration but will issuing a warning or so.
                                        if config.get(session.host or "*", "core", "anonymous_login") then