Changeset

12088:e5028f6eb599 0.11

mod_pep: Prevent creation of services for non-existent users Using a dedicated service should give identical behavior, except for a possible timing difference in the user existence lookup.
author Kim Alvefur <zash@zash.se>
date Thu, 04 Nov 2021 00:55:59 +0100
parents 12087:19f67d44ec37
children 12089:76b4e3f12b53
files plugins/mod_pep.lua
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_pep.lua	Thu Nov 04 00:36:41 2021 +0100
+++ b/plugins/mod_pep.lua	Thu Nov 04 00:55:59 2021 +0100
@@ -9,6 +9,7 @@
 local cache = require "util.cache";
 local set = require "util.set";
 local storagemanager = require "core.storagemanager";
+local usermanager = require "core.usermanager";
 
 local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
 local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event";
@@ -174,6 +175,17 @@
 	end
 end
 
+local nobody_service = pubsub.new({
+	service = pubsub.new({
+		node_defaults = {
+			["max_items"] = 1;
+			["persist_items"] = false;
+			["access_model"] = "presence";
+			["send_last_published_item"] = "on_sub_and_presence";
+		};
+	});
+});
+
 function get_pep_service(username)
 	module:log("debug", "get_pep_service(%q)", username);
 	local user_bare = jid_join(username, host);
@@ -181,6 +193,9 @@
 	if service then
 		return service;
 	end
+	if not usermanager.user_exists(username, host) then
+		return nobody_service;
+	end
 	service = pubsub.new({
 		pep_username = username;
 		node_defaults = {