aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2019-04-29 17:27:08 +0200
committerKim Alvefur <zash@zash.se>2019-04-29 17:27:08 +0200
commitcdea7586e4fc49b4a16b972f69adeeea1dd9136e (patch)
treeed3545c2a166dee4bf591395536e740a8951d413 /plugins
parentd9d997c8619b47534f0a18ce67cc9a90621e43b9 (diff)
downloadprosody-cdea7586e4fc49b4a16b972f69adeeea1dd9136e.tar.gz
prosody-cdea7586e4fc49b4a16b972f69adeeea1dd9136e.zip
mod_mimicking: Improve error handling
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_mimicking.lua36
1 files changed, 31 insertions, 5 deletions
diff --git a/plugins/mod_mimicking.lua b/plugins/mod_mimicking.lua
index 43d165d2..b586a70c 100644
--- a/plugins/mod_mimicking.lua
+++ b/plugins/mod_mimicking.lua
@@ -22,22 +22,34 @@ function module.load()
end
module:hook("user-registered", function(user)
- skeletons:set(skeleton(user.username), { username = user.username });
+ local skel = skeleton(user.username);
+ local ok, err = skeletons:set(skel, { username = user.username });
+ if not ok then
+ module:log("error", "Unable to store mimicry data (%q => %q): %s", user.username, skel, err);
+ end
end);
module:hook("user-deleted", function(user)
- skeletons:set(skeleton(user.username), nil);
+ local skel = skeleton(user.username);
+ local ok, err = skeletons:set(skel, nil);
+ if not ok and err then
+ module:log("error", "Unable to clear mimicry data (%q): %s", skel, err);
+ end
end);
module:hook("user-registering", function(user)
- if skeletons:get(skeleton(user.username)) then
+ local existing, err = skeletons:get(skeleton(user.username));
+ if existing then
+ module:log("debug", "Attempt to register username '%s' which could be confused with '%s'", user.username, existing.username);
user.allowed = false;
+ elseif err then
+ module:log("error", "Unable to check if new username '%s' can be confused with any existing user: %s", err);
end
end);
function module.command(arg)
if (arg[1] ~= "bootstrap" or not arg[2]) then
- usage("mod_mimicking bootstrap <host>", "Initialize username mimicry index");
+ usage("mod_mimicking bootstrap <host>", "Initialize username mimicry database");
return;
end
@@ -53,7 +65,21 @@ function module.command(arg)
skeletons = storagemanager.open(host, "skeletons");
+ local count = 0;
for user in usermanager.users(host) do
- skeletons:set(skeleton(user), { username = user });
+ local skel = skeleton(user);
+ local existing, err = skeletons:get(skel);
+ if existing and existing.username ~= user then
+ module:log("warn", "Existing usernames '%s' and '%s' are confusable", existing.username, user);
+ elseif err then
+ module:log("error", "Error checking for existing mimicry data (%q = %q): %s", user, skel, err);
+ end
+ local ok, err = skeletons:set(skel, { username = user });
+ if ok then
+ count = count + 1;
+ elseif err then
+ module:log("error", "Unable to store mimicry data (%q => %q): %s", user, skel, err);
+ end
end
+ module:log("info", "%d usernames indexed", count);
end