Changeset

7874:de3c6fb74759

Merge 0.10->trunk
author Kim Alvefur <zash@zash.se>
date Sat, 28 Jan 2017 21:39:14 +0100
parents 7870:a858066faac6 (current diff) 7873:8d1ebb9a9b44 (diff)
children 7878:2fdb7b3648d8
files plugins/mod_component.lua
diffstat 3 files changed, 25 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/.luacheckrc	Fri Jan 27 12:23:19 2017 +0100
+++ b/.luacheckrc	Sat Jan 28 21:39:14 2017 +0100
@@ -7,6 +7,9 @@
 codes = true
 ignore = { "411/err", "421/err", "411/ok", "421/ok", "211/_ENV" }
 
+files["core/"] = {
+	ignore = { "122/prosody", "122/hosts" };
+}
 files["plugins/"] = {
 	globals = { "module" };
 }
--- a/plugins/mod_component.lua	Fri Jan 27 12:23:19 2017 +0100
+++ b/plugins/mod_component.lua	Sat Jan 28 21:39:14 2017 +0100
@@ -33,7 +33,7 @@
 	if module:get_host_type() ~= "component" then
 		error("Don't load mod_component manually, it should be for a component, please see https://prosody.im/doc/components", 0);
 	end
-	
+
 	local env = module.environment;
 	env.connected = false;
 	env.session = false;
@@ -46,26 +46,26 @@
 		send = nil;
 		session.on_destroy = nil;
 	end
-	
+
 	-- Handle authentication attempts by component
 	local function handle_component_auth(event)
 		local session, stanza = event.origin, event.stanza;
-		
+
 		if session.type ~= "component_unauthed" then return; end
-	
+
 		if (not session.host) or #stanza.tags > 0 then
 			(session.log or log)("warn", "Invalid component handshake for host: %s", session.host);
 			session:close("not-authorized");
 			return true;
 		end
-		
+
 		local secret = module:get_option("component_secret");
 		if not secret then
 			(session.log or log)("warn", "Component attempted to identify as %s, but component_secret is not set", session.host);
 			session:close("not-authorized");
 			return true;
 		end
-		
+
 		local supplied_token = t_concat(stanza);
 		local calculated_token = sha1(session.streamid..secret, true);
 		if supplied_token:lower() ~= calculated_token:lower() then
@@ -73,7 +73,7 @@
 			session:close{ condition = "not-authorized", text = "Given token does not match calculated token" };
 			return true;
 		end
-		
+
 		if env.connected then
 			local policy = module:get_option_string("component_conflict_resolve", "kick_new");
 			if policy == "kick_old" then
@@ -84,7 +84,7 @@
 				return true;
 			end
 		end
-		
+
 		env.connected = true;
 		env.session = session;
 		send = session.send;
@@ -94,7 +94,7 @@
 		module:log("info", "External component successfully authenticated");
 		session.send(st.stanza("handshake"));
 		module:fire_event("component-authenticated", { session = session });
-	
+
 		return true;
 	end
 	module:hook("stanza/jabber:component:accept:handshake", handle_component_auth, -1);
@@ -125,7 +125,7 @@
 		end
 		return true;
 	end
-	
+
 	module:hook("iq/bare", handle_stanza, -1);
 	module:hook("message/bare", handle_stanza, -1);
 	module:hook("presence/bare", handle_stanza, -1);
@@ -282,14 +282,14 @@
 	if opt_keepalives then
 		conn:setoption("keepalive", opt_keepalives);
 	end
-	
+
 	session.log("info", "Incoming Jabber component connection");
-	
+
 	local stream = new_xmpp_stream(session, stream_callbacks);
 	session.stream = stream;
-	
+
 	session.notopen = true;
-	
+
 	function session.reset_stream()
 		session.notopen = true;
 		session.stream:reset();
@@ -301,7 +301,7 @@
 		module:log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_"));
 		session:close("not-well-formed");
 	end
-	
+
 	session.dispatch_stanza = stream_callbacks.handlestanza;
 
 	sessions[conn] = session;
--- a/plugins/mod_pep.lua	Fri Jan 27 12:23:19 2017 +0100
+++ b/plugins/mod_pep.lua	Sat Jan 28 21:39:14 2017 +0100
@@ -185,7 +185,11 @@
 					node = node, user = jid_bare(session.full_jid), actor = session.jid, id = id, session = session, item = st.clone(payload);
 				});
 				return true;
+			else
+				module:log("debug", "Payload is missing the <item>", node);
 			end
+		else
+			module:log("debug", "Unhandled payload: %s", payload and payload:top_tag() or "(no payload)");
 		end
 	elseif stanza.attr.type == 'get' then
 		local user = stanza.attr.to and jid_bare(stanza.attr.to) or session.username..'@'..session.host;
@@ -221,14 +225,17 @@
 				end
 			elseif node then -- node doesn't exist
 				session.send(st.error_reply(stanza, 'cancel', 'item-not-found'));
+				module:log("debug", "Item '%s' not found", node)
 				return true;
 			else --invalid request
 				session.send(st.error_reply(stanza, 'modify', 'bad-request'));
+				module:log("debug", "Invalid request: %s", tostring(payload));
 				return true;
 			end
 		else --no presence subscription
 			session.send(st.error_reply(stanza, 'auth', 'not-authorized')
 				:tag('presence-subscription-required', {xmlns='http://jabber.org/protocol/pubsub#errors'}));
+			module:log("debug", "Unauthorized request: %s", tostring(payload));
 			return true;
 		end
 	end