aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rwxr-xr-xconfigure5
-rw-r--r--core/storagemanager.lua7
-rw-r--r--core/usermanager.lua4
-rw-r--r--plugins/mod_admin_telnet.lua12
-rw-r--r--plugins/mod_auth_internal_hashed.lua4
-rw-r--r--plugins/mod_auth_internal_plain.lua4
-rw-r--r--plugins/mod_storage_internal.lua8
-rw-r--r--plugins/mod_storage_sql.lua11
-rw-r--r--plugins/muc/muc.lib.lua2
-rw-r--r--util/datamanager.lua19
11 files changed, 75 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 1acdd051..0e69192a 100644
--- a/Makefile
+++ b/Makefile
@@ -52,7 +52,8 @@ util/%.so:
$(MAKE) install -C util-src
%.install: %
- sed "s|^CFG_SOURCEDIR=.*;$$|CFG_SOURCEDIR='$(INSTALLEDSOURCE)';|; \
+ sed "1s/\blua\b/$(RUNWITH)/; \
+ s|^CFG_SOURCEDIR=.*;$$|CFG_SOURCEDIR='$(INSTALLEDSOURCE)';|; \
s|^CFG_CONFIGDIR=.*;$$|CFG_CONFIGDIR='$(INSTALLEDCONFIG)';|; \
s|^CFG_DATADIR=.*;$$|CFG_DATADIR='$(INSTALLEDDATA)';|; \
s|^CFG_PLUGINDIR=.*;$$|CFG_PLUGINDIR='$(INSTALLEDMODULES)/';|;" < $^ > $@
diff --git a/configure b/configure
index 209fdccb..df62cc05 100755
--- a/configure
+++ b/configure
@@ -16,6 +16,7 @@ OPENSSL_LIB=crypto
CC=gcc
CXX=g++
LD=gcc
+RUNWITH=lua
CFLAGS="-fPIC -Wall"
LDFLAGS="-shared"
@@ -171,6 +172,9 @@ do
--linker=*)
LD="$value"
;;
+ --runwith=*)
+ RUNWITH="$value"
+ ;;
*)
echo "Error: Unknown flag: $1"
exit 1
@@ -341,6 +345,7 @@ LDFLAGS=$LDFLAGS
CC=$CC
CXX=$CXX
LD=$LD
+RUNWITH=$RUNWITH
EOF
diff --git a/core/storagemanager.lua b/core/storagemanager.lua
index 5a7bb7bd..36a671be 100644
--- a/core/storagemanager.lua
+++ b/core/storagemanager.lua
@@ -118,6 +118,13 @@ end
function datamanager.store(username, host, datastore, data)
return open(host, datastore):set(username, data);
end
+function datamanager.users(host, datastore, typ)
+ local driver = open(host, datastore, typ);
+ if not driver.users then
+ return function() log("warn", "storage driver %s does not support listing users", driver.name) end
+ end
+ return driver:users();
+end
function datamanager.stores(username, host, typ)
return get_driver(host):stores(username, typ);
end
diff --git a/core/usermanager.lua b/core/usermanager.lua
index 0ed61f23..417d7037 100644
--- a/core/usermanager.lua
+++ b/core/usermanager.lua
@@ -96,6 +96,10 @@ function delete_user(username, host)
return storagemanager.purge(username, host);
end
+function users(host)
+ return hosts[host].users.users();
+end
+
function get_sasl_handler(host, session)
return hosts[host].users.get_sasl_handler(session);
end
diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua
index 62fb10a0..9d3186d6 100644
--- a/plugins/mod_admin_telnet.lua
+++ b/plugins/mod_admin_telnet.lua
@@ -228,6 +228,7 @@ function commands.help(session, data)
print [[user:create(jid, password) - Create the specified user account]]
print [[user:password(jid, password) - Set the password for the specified user account]]
print [[user:delete(jid) - Permanently remove the specified user account]]
+ print [[user:list(hostname) - List users on the specified host]]
elseif section == "server" then
print [[server:version() - Show the server's version number]]
print [[server:uptime() - Show how long the server has been running]]
@@ -952,6 +953,17 @@ function def_env.user:password(jid, password)
end
end
+function def_env.user:list(host)
+ if not host then
+ return nil, "No host given";
+ end
+ local print = self.session.print;
+ for user in um.users(host) do
+ print(user.."@"..host);
+ end
+ return true;
+end
+
def_env.xmpp = {};
local st = require "util.stanza";
diff --git a/plugins/mod_auth_internal_hashed.lua b/plugins/mod_auth_internal_hashed.lua
index b61fba80..4535f9c9 100644
--- a/plugins/mod_auth_internal_hashed.lua
+++ b/plugins/mod_auth_internal_hashed.lua
@@ -102,6 +102,10 @@ function provider.user_exists(username)
return true;
end
+function provider.users()
+ return datamanager.users(host, "accounts");
+end
+
function provider.create_user(username, password)
if password == nil then
return datamanager.store(username, host, "accounts", {});
diff --git a/plugins/mod_auth_internal_plain.lua b/plugins/mod_auth_internal_plain.lua
index b7723dd7..7514164d 100644
--- a/plugins/mod_auth_internal_plain.lua
+++ b/plugins/mod_auth_internal_plain.lua
@@ -52,6 +52,10 @@ function provider.user_exists(username)
return true;
end
+function provider.users()
+ return datamanager.users(host, "accounts");
+end
+
function provider.create_user(username, password)
return datamanager.store(username, host, "accounts", {password = password});
end
diff --git a/plugins/mod_storage_internal.lua b/plugins/mod_storage_internal.lua
index 039202dd..972ecbee 100644
--- a/plugins/mod_storage_internal.lua
+++ b/plugins/mod_storage_internal.lua
@@ -5,8 +5,8 @@ local host = module.host;
local driver = {};
local driver_mt = { __index = driver };
-function driver:open(store)
- return setmetatable({ store = store }, driver_mt);
+function driver:open(store, typ)
+ return setmetatable({ store = store, type = typ }, driver_mt);
end
function driver:get(user)
return datamanager.load(user, host, self.store);
@@ -20,6 +20,10 @@ function driver:stores(username)
return datamanager.stores(username, host);
end
+function driver:users()
+ return datamanager.users(host, self.store, self.type);
+end
+
function driver:purge(user)
return datamanager.purge(user, host);
end
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua
index c9a45fca..f6fa94e7 100644
--- a/plugins/mod_storage_sql.lua
+++ b/plugins/mod_storage_sql.lua
@@ -298,6 +298,17 @@ function keyval_store:set(username, data)
end
if success then return ret, err; else return rollback(nil, ret); end
end
+function keyval_store:users()
+ local stmt, err = dosql("SELECT DISTINCT `user` FROM `prosody` WHERE `host`=? AND `store`=?", host, self.store);
+ if not stmt then
+ return rollback(nil, err);
+ end
+ local next = stmt:rows();
+ return commit(function()
+ local row = next();
+ return row and row[1];
+ end);
+end
local function map_store_get(key)
local stmt, err = getsql("SELECT * FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", key or "");
diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua
index a7603535..6ba7b621 100644
--- a/plugins/muc/muc.lib.lua
+++ b/plugins/muc/muc.lib.lua
@@ -522,7 +522,7 @@ function room_mt:handle_to_occupant(origin, stanza) -- PM, vCards, etc
end
end
elseif not current_nick then -- not in room
- if type == "error" or type == "result" and stanza.name == "iq" then
+ if (type == "error" or type == "result") and stanza.name == "iq" then
local id = stanza.attr.id;
stanza.attr.from, stanza.attr.to, stanza.attr.id = deconstruct_stanza_id(self, stanza);
if stanza.attr.id then
diff --git a/util/datamanager.lua b/util/datamanager.lua
index 9207f555..08d9d6af 100644
--- a/util/datamanager.lua
+++ b/util/datamanager.lua
@@ -282,6 +282,25 @@ local type_map = {
list = "list";
}
+function users(host, store, typ)
+ typ = type_map[typ or "keyval"];
+ local store_dir = format("%s/%s/%s", data_path, encode(host), encode(store));
+
+ local mode, err = lfs.attributes(store_dir, "mode");
+ if not mode then
+ return function() log("debug", err or (store_dir .. " does not exist")) end
+ end
+ local next, state = lfs.dir(store_dir);
+ return function(state)
+ for node in next, state do
+ local file, ext = node:match("^(.*)%.([dalist]+)$");
+ if file and ext == typ then
+ return decode(file);
+ end
+ end
+ end, state;
+end
+
function stores(username, host, typ)
typ = type_map[typ or "keyval"];
local store_dir = format("%s/%s/", data_path, encode(host));