aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2012-08-06 15:35:27 +0200
committerKim Alvefur <zash@zash.se>2012-08-06 15:35:27 +0200
commite40cf146149c412e17d789d1b0a0132117494747 (patch)
tree519d4c544ce25ecf405f4df2c82d2b4f8588550d
parent183b42baa0da20b06ff3429bcc75a8ce01676a1b (diff)
downloadprosody-e40cf146149c412e17d789d1b0a0132117494747.tar.gz
prosody-e40cf146149c412e17d789d1b0a0132117494747.zip
mod_mimicking: Prevents registration of confusable usernames (by Florob) (fixes #1347)
-rw-r--r--CHANGES1
-rw-r--r--plugins/mod_mimicking.lua49
2 files changed, 50 insertions, 0 deletions
diff --git a/CHANGES b/CHANGES
index e2e90f4a..8c65f4ec 100644
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,7 @@ TRUNK
- CSI improvements
- mod\_limits: Exempted JIDs
- Archive quotas
+- mod\_mimicking
0.11.0
======
diff --git a/plugins/mod_mimicking.lua b/plugins/mod_mimicking.lua
new file mode 100644
index 00000000..9004957a
--- /dev/null
+++ b/plugins/mod_mimicking.lua
@@ -0,0 +1,49 @@
+-- Prosody IM
+-- Copyright (C) 2012 Florian Zeitz
+--
+-- This project is MIT/X11 licensed. Please see the
+-- COPYING file in the source package for more information.
+--
+
+local skeleton = require "util.confusable".skeleton;
+local datamanager = require "util.datamanager";
+local usage = require "util.prosodyctl".show_usage;
+local warn = require "util.prosodyctl".show_warning;
+local users = require "usermanager".users;
+
+module:hook("user-registered", function(user)
+ datamanager.store(skeleton(user.username), user.host, "skeletons", {username = user.username});
+end);
+
+module:hook("user-deregistered", function(user)
+ datamanager.store(skeleton(user.username), user.host, "skeletons", nil);
+end);
+
+module:hook("registration-attempt", function(user)
+ if datamanager.load(skeleton(user.username), user.host, "skeletons") then
+ user.allowed = false;
+ end
+end);
+
+function module.command(arg)
+ if (arg[1] ~= "bootstrap" or not arg[2]) then
+ usage("mod_mimicking bootstrap <host>", "Initialize skeleton database");
+ return;
+ end
+
+ local host = arg[2];
+
+ local host_session = prosody.hosts[host];
+ if not host_session then
+ return "No such host";
+ end
+ local provider = host_session.users;
+ if not(provider) or provider.name == "null" then
+ usermanager.initialize_host(host);
+ end
+ storagemanager.initialize_host(host);
+
+ for user in users(host) do
+ datamanager.store(skeleton(user), host, "skeletons", {username = user});
+ end
+end