mod_auth_internal_hashed, mod_auth_internal_plain, mod_privacy, mod_private, mod_regi...
authorKim Alvefur <zash@zash.se>
Fri, 19 Apr 2013 14:14:06 +0000 (16:14 +0200)
committerKim Alvefur <zash@zash.se>
Fri, 19 Apr 2013 14:14:06 +0000 (16:14 +0200)
plugins/mod_auth_internal_hashed.lua
plugins/mod_auth_internal_plain.lua
plugins/mod_privacy.lua
plugins/mod_private.lua
plugins/mod_register.lua
plugins/mod_vcard.lua
plugins/muc/mod_muc.lua

index cb6cc8ff6d3f922a253c6e0103ae7297e356fbb2..2b041e432021283ce9aac727532afb6e95376421 100644 (file)
@@ -7,13 +7,14 @@
 -- COPYING file in the source package for more information.
 --
 
-local datamanager = require "util.datamanager";
 local log = require "util.logger".init("auth_internal_hashed");
 local getAuthenticationDatabaseSHA1 = require "util.sasl.scram".getAuthenticationDatabaseSHA1;
 local usermanager = require "core.usermanager";
 local generate_uuid = require "util.uuid".generate;
 local new_sasl = require "util.sasl".new;
 
+local accounts = module:open_store("accounts");
+
 local to_hex;
 do
        local function replace_byte_with_hex(byte)
@@ -44,7 +45,7 @@ local provider = {};
 log("debug", "initializing internal_hashed authentication provider for host '%s'", host);
 
 function provider.test_password(username, password)
-       local credentials = datamanager.load(username, host, "accounts") or {};
+       local credentials = accounts:get(username) or {};
 
        if credentials.password ~= nil and string.len(credentials.password) ~= 0 then
                if credentials.password ~= password then
@@ -75,7 +76,7 @@ function provider.test_password(username, password)
 end
 
 function provider.set_password(username, password)
-       local account = datamanager.load(username, host, "accounts");
+       local account = accounts:get(username);
        if account then
                account.salt = account.salt or generate_uuid();
                account.iteration_count = account.iteration_count or iteration_count;
@@ -87,13 +88,13 @@ function provider.set_password(username, password)
                account.server_key = server_key_hex
 
                account.password = nil;
-               return datamanager.store(username, host, "accounts", account);
+               return accounts:set(username, account);
        end
        return nil, "Account not available.";
 end
 
 function provider.user_exists(username)
-       local account = datamanager.load(username, host, "accounts");
+       local account = accounts:get(username);
        if not account then
                log("debug", "account not found for username '%s' at host '%s'", username, host);
                return nil, "Auth failed. Invalid username";
@@ -102,22 +103,22 @@ function provider.user_exists(username)
 end
 
 function provider.users()
-       return datamanager.users(host, "accounts");
+       return accounts:users();
 end
 
 function provider.create_user(username, password)
        if password == nil then
-               return datamanager.store(username, host, "accounts", {});
+               return accounts:set(username, {});
        end
        local salt = generate_uuid();
        local valid, stored_key, server_key = getAuthenticationDatabaseSHA1(password, salt, iteration_count);
        local stored_key_hex = to_hex(stored_key);
        local server_key_hex = to_hex(server_key);
-       return datamanager.store(username, host, "accounts", {stored_key = stored_key_hex, server_key = server_key_hex, salt = salt, iteration_count = iteration_count});
+       return accounts:set(username, {stored_key = stored_key_hex, server_key = server_key_hex, salt = salt, iteration_count = iteration_count});
 end
 
 function provider.delete_user(username)
-       return datamanager.store(username, host, "accounts", nil);
+       return accounts:set(username, nil);
 end
 
 function provider.get_sasl_handler()
@@ -126,11 +127,11 @@ function provider.get_sasl_handler()
                        return usermanager.test_password(username, realm, password), true;
                end,
                scram_sha_1 = function(sasl, username, realm)
-                       local credentials = datamanager.load(username, host, "accounts");
+                       local credentials = accounts:get(username);
                        if not credentials then return; end
                        if credentials.password then
                                usermanager.set_password(username, credentials.password, host);
-                               credentials = datamanager.load(username, host, "accounts");
+                               credentials = accounts:get(username);
                                if not credentials then return; end
                        end
                        
index 178ae5a5879e67f31230f7868d1e12fcfb3e7060..e411c4f7d7f5b429121268008539604b0a44f95a 100644 (file)
@@ -6,20 +6,21 @@
 -- COPYING file in the source package for more information.
 --
 
-local datamanager = require "util.datamanager";
 local usermanager = require "core.usermanager";
 local new_sasl = require "util.sasl".new;
 
 local log = module._log;
 local host = module.host;
 
+local accounts = module:open_store("accounts");
+
 -- define auth provider
 local provider = {};
 log("debug", "initializing internal_plain authentication provider for host '%s'", host);
 
 function provider.test_password(username, password)
        log("debug", "test password '%s' for user %s at host %s", password, username, host);
-       local credentials = datamanager.load(username, host, "accounts") or {};
+       local credentials = accounts:get(username) or {};
 
        if password == credentials.password then
                return true;
@@ -30,20 +31,20 @@ end
 
 function provider.get_password(username)
        log("debug", "get_password for username '%s' at host '%s'", username, host);
-       return (datamanager.load(username, host, "accounts") or {}).password;
+       return (accounts:get(username) or {}).password;
 end
 
 function provider.set_password(username, password)
-       local account = datamanager.load(username, host, "accounts");
+       local account = accounts:get(username);
        if account then
                account.password = password;
-               return datamanager.store(username, host, "accounts", account);
+               return accounts:set(username, account);
        end
        return nil, "Account not available.";
 end
 
 function provider.user_exists(username)
-       local account = datamanager.load(username, host, "accounts");
+       local account = accounts:get(username);
        if not account then
                log("debug", "account not found for username '%s' at host '%s'", username, host);
                return nil, "Auth failed. Invalid username";
@@ -52,15 +53,15 @@ function provider.user_exists(username)
 end
 
 function provider.users()
-       return datamanager.users(host, "accounts");
+       return accounts:users();
 end
 
 function provider.create_user(username, password)
-       return datamanager.store(username, host, "accounts", {password = password});
+       return accounts:set(username, {password = password});
 end
 
 function provider.delete_user(username)
-       return datamanager.store(username, host, "accounts", nil);
+       return accounts:set(username, nil);
 end
 
 function provider.get_sasl_handler()
index dc6b153a46caff8cd41916ce84a26020d2f42653..31ace9f9df126eb25ddaf66d40226bb1788ea28d 100644 (file)
@@ -10,7 +10,6 @@
 module:add_feature("jabber:iq:privacy");
 
 local st = require "util.stanza";
-local datamanager = require "util.datamanager";
 local bare_sessions, full_sessions = prosody.bare_sessions, prosody.full_sessions;
 local util_Jid = require "util.jid";
 local jid_bare = util_Jid.bare;
@@ -18,6 +17,8 @@ local jid_split, jid_join = util_Jid.split, util_Jid.join;
 local load_roster = require "core.rostermanager".load_roster;
 local to_number = tonumber;
 
+local privacy_storage = module:open_store();
+
 function isListUsed(origin, name, privacy_lists)
        local user = bare_sessions[origin.username.."@"..origin.host];
        if user then
@@ -217,7 +218,7 @@ module:hook("iq/bare/jabber:iq:privacy:query", function(data)
        if stanza.attr.to == nil then -- only service requests to own bare JID
                local query = stanza.tags[1]; -- the query element
                local valid = false;
-               local privacy_lists = datamanager.load(origin.username, origin.host, "privacy") or { lists = {} };
+               local privacy_lists = privacy_storage:get(origin.username) or { lists = {} };
 
                if privacy_lists.lists[1] then -- Code to migrate from old privacy lists format, remove in 0.8
                        module:log("info", "Upgrading format of stored privacy lists for %s@%s", origin.username, origin.host);
@@ -272,7 +273,7 @@ module:hook("iq/bare/jabber:iq:privacy:query", function(data)
                        end
                        origin.send(st.error_reply(stanza, valid[1], valid[2], valid[3]));
                else
-                       datamanager.store(origin.username, origin.host, "privacy", privacy_lists);
+                       privacy_storage:set(origin.username, privacy_lists);
                end
                return true;
        end
@@ -280,7 +281,7 @@ end);
 
 function checkIfNeedToBeBlocked(e, session)
        local origin, stanza = e.origin, e.stanza;
-       local privacy_lists = datamanager.load(session.username, session.host, "privacy") or {};
+       local privacy_lists = privacy_storage:get(session.username) or {};
        local bare_jid = session.username.."@"..session.host;
        local to = stanza.attr.to or bare_jid;
        local from = stanza.attr.from;
index 29d3162c8f9631947e4ad17ac6f747d71a040621..365a997c8d99abce4755d7d7841760c5581ff1f8 100644 (file)
@@ -9,7 +9,7 @@
 
 local st = require "util.stanza"
 
-local datamanager = require "util.datamanager"
+local private_storage = module:open_store();
 
 module:add_feature("jabber:iq:private");
 
@@ -20,7 +20,7 @@ module:hook("iq/self/jabber:iq:private:query", function(event)
        if #query.tags == 1 then
                local tag = query.tags[1];
                local key = tag.name..":"..tag.attr.xmlns;
-               local data, err = datamanager.load(origin.username, origin.host, "private");
+               local data, err = private_storage:get(origin.username);
                if err then
                        origin.send(st.error_reply(stanza, "wait", "internal-server-error"));
                        return true;
@@ -39,7 +39,7 @@ module:hook("iq/self/jabber:iq:private:query", function(event)
                                data[key] = st.preserialize(tag);
                        end
                        -- TODO delete datastore if empty
-                       if datamanager.store(origin.username, origin.host, "private", data) then
+                       if private_storage:set(origin.username, data) then
                                origin.send(st.reply(stanza));
                        else
                                origin.send(st.error_reply(stanza, "wait", "internal-server-error"));
index e941a128967a1697c785278bdff66e7298e25a4d..141a4997966a7448a4b78f0f9a9b929e5206a354 100644 (file)
@@ -8,7 +8,6 @@
 
 
 local st = require "util.stanza";
-local datamanager = require "util.datamanager";
 local dataform_new = require "util.dataforms".new;
 local usermanager_user_exists = require "core.usermanager".user_exists;
 local usermanager_create_user = require "core.usermanager".create_user;
@@ -22,6 +21,8 @@ local compat = module:get_option_boolean("registration_compat", true);
 local allow_registration = module:get_option_boolean("allow_registration", false);
 local additional_fields = module:get_option("additional_registration_fields", {});
 
+local account_details = module:open_store("account_details");
+
 local field_map = {
        username = { name = "username", type = "text-single", label = "Username", required = true };
        password = { name = "password", type = "text-private", label = "Password", required = true };
@@ -234,7 +235,7 @@ module:hook("stanza/iq/jabber:iq:register:query", function(event)
                                                -- TODO unable to write file, file may be locked, etc, what's the correct error?
                                                local error_reply = st.error_reply(stanza, "wait", "internal-server-error", "Failed to write data to disk.");
                                                if usermanager_create_user(username, password, host) then
-                                                       if next(data) and not datamanager.store(username, host, "account_details", data) then
+                                                       if next(data) and not account_details:set(username, data) then
                                                                usermanager_delete_user(username, host);
                                                                session.send(error_reply);
                                                                return true;
index d3c27cc0c401bc1e3d0d1eb18f6a0b57d5066790..26b30e3ab3c10621e9f8fa47a9eb05a4cca8413b 100644 (file)
@@ -8,7 +8,8 @@
 
 local st = require "util.stanza"
 local jid_split = require "util.jid".split;
-local datamanager = require "util.datamanager"
+
+local vcards = module:open_store();
 
 module:add_feature("vcard-temp");
 
@@ -19,9 +20,9 @@ local function handle_vcard(event)
                local vCard;
                if to then
                        local node, host = jid_split(to);
-                       vCard = st.deserialize(datamanager.load(node, host, "vcard")); -- load vCard for user or server
+                       vCard = st.deserialize(vcards:get(node)); -- load vCard for user or server
                else
-                       vCard = st.deserialize(datamanager.load(session.username, session.host, "vcard"));-- load user's own vCard
+                       vCard = st.deserialize(vcards:get(session.username));-- load user's own vCard
                end
                if vCard then
                        session.send(st.reply(stanza):add_child(vCard)); -- send vCard!
@@ -30,7 +31,7 @@ local function handle_vcard(event)
                end
        else
                if not to then
-                       if datamanager.store(session.username, session.host, "vcard", st.preserialize(stanza.tags[1])) then
+                       if vcards:set(session.username, st.preserialize(stanza.tags[1])) then
                                session.send(st.reply(stanza));
                        else
                                -- TODO unable to write file, file may be locked, etc, what's the correct error?
index 2c2d02f783170055bf5ef078be4a77993fa8bf0e..7861092c40598dfa7aabbbb2780d5c580732db08 100644 (file)
@@ -28,13 +28,14 @@ local jid_split = require "util.jid".split;
 local jid_bare = require "util.jid".bare;
 local st = require "util.stanza";
 local uuid_gen = require "util.uuid".generate;
-local datamanager = require "util.datamanager";
 local um_is_admin = require "core.usermanager".is_admin;
 local hosts = prosody.hosts;
 
 rooms = {};
 local rooms = rooms;
-local persistent_rooms = datamanager.load(nil, muc_host, "persistent") or {};
+local persistent_rooms_storage = module:open_store("persistent");
+local persistent_rooms = persistent_rooms_storage:get() or {};
+local room_configs = module:open_store("config");
 
 -- Configurable options
 muclib.set_max_history_length(module:get_option_number("max_history_messages"));
@@ -66,15 +67,15 @@ local function room_save(room, forced)
                        _data = room._data;
                        _affiliations = room._affiliations;
                };
-               datamanager.store(node, muc_host, "config", data);
+               room_configs:set(node, data);
                room._data.history = history;
        elseif forced then
-               datamanager.store(node, muc_host, "config", nil);
+               room_configs:set(node, nil);
                if not next(room._occupants) then -- Room empty
                        rooms[room.jid] = nil;
                end
        end
-       if forced then datamanager.store(nil, muc_host, "persistent", persistent_rooms); end
+       if forced then persistent_rooms_storage:set(nil, persistent_rooms); end
 end
 
 function create_room(jid)
@@ -88,7 +89,7 @@ end
 local persistent_errors = false;
 for jid in pairs(persistent_rooms) do
        local node = jid_split(jid);
-       local data = datamanager.load(node, muc_host, "config");
+       local data = room_configs:get(node);
        if data then
                local room = create_room(jid);
                room._data = data._data;
@@ -99,7 +100,7 @@ for jid in pairs(persistent_rooms) do
                persistent_errors = true;
        end
 end
-if persistent_errors then datamanager.store(nil, muc_host, "persistent", persistent_rooms); end
+if persistent_errors then persistent_rooms_storage:set(nil, persistent_rooms); end
 
 local host_room = muc_new_room(muc_host);
 host_room.route_stanza = room_route_stanza;