mod_dialback: Final sweep to get nameprep + error handling in order (hopefully)
[prosody.git] / plugins / mod_dialback.lua
index 3d1fe0e178eeb81a823006771fe906960d6881a1..e47d63ed9cb38f6e4d2fd28f1d50649a3d7508b7 100644 (file)
@@ -65,37 +65,30 @@ module:hook("stanza/jabber:server:dialback:result", function(event)
                -- he wants to be identified through dialback
                -- We need to check the key with the Authoritative server
                local attr = stanza.attr;
-               local to, from = attr.to, attr.from;
-               
-               origin.hosts[from] = { dialback_key = stanza[1] };
+               local to, from = nameprep(attr.to), nameprep(attr.from);
                
                if not hosts[to] then
                        -- Not a host that we serve
                        origin.log("info", "%s tried to connect to %s, which we don't serve", from, to);
                        origin:close("host-unknown");
                        return true;
+               elseif not from then
+                       origin:close("improper-addressing");
                end
                
+               origin.hosts[from] = { dialback_key = stanza[1] };
+               
                dialback_requests[from.."/"..origin.streamid] = origin;
                
                -- COMPAT: ejabberd, gmail and perhaps others do not always set 'to' and 'from'
                -- on streams. We fill in the session's to/from here instead.
                if not origin.from_host then
-                       origin.from_host = nameprep(attr.from);
-                       if not origin.from_host then
-                               origin.log("debug", "We need to know where to connect but remote server blindly refuses to tell us and to comply to specs, closing connection.");
-                               origin:close("invalid-from");
-                       end
+                       origin.from_host = from;
                end
                if not origin.to_host then
                        origin.to_host = nameprep(attr.to);
                end
 
-               if not origin.from_host or not origin.to_host then
-                       origin.log("debug", "Improper addressing supplied, no to or from?");
-                       origin:close("improper-addressing");
-               end
-               
                origin.log("debug", "asking %s if key %s belongs to them", from, stanza[1]);
                module:fire_event("route/remote", {
                        from_host = to, to_host = from;