Comparison

core/usermanager.lua @ 4797:e239668aa6d2

Merge 0.9->trunk
author Matthew Wild <mwild1@gmail.com>
date Sun, 29 Apr 2012 02:10:55 +0100
parent 4773:ee55956597f4
child 4943:50f63f07245f
comparison
equal deleted inserted replaced
4796:04a34287dc12 4797:e239668aa6d2
9 local modulemanager = require "core.modulemanager"; 9 local modulemanager = require "core.modulemanager";
10 local log = require "util.logger".init("usermanager"); 10 local log = require "util.logger".init("usermanager");
11 local type = type; 11 local type = type;
12 local ipairs = ipairs; 12 local ipairs = ipairs;
13 local jid_bare = require "util.jid".bare; 13 local jid_bare = require "util.jid".bare;
14 local jid_prep = require "util.jid".prep;
14 local config = require "core.configmanager"; 15 local config = require "core.configmanager";
15 local hosts = hosts; 16 local hosts = hosts;
16 local sasl_new = require "util.sasl".new; 17 local sasl_new = require "util.sasl".new;
17 18
18 local prosody = _G.prosody; 19 local prosody = _G.prosody;
38 if host_session.type ~= "local" then return; end 39 if host_session.type ~= "local" then return; end
39 40
40 host_session.events.add_handler("item-added/auth-provider", function (event) 41 host_session.events.add_handler("item-added/auth-provider", function (event)
41 local provider = event.item; 42 local provider = event.item;
42 local auth_provider = config.get(host, "core", "authentication") or default_provider; 43 local auth_provider = config.get(host, "core", "authentication") or default_provider;
43 if config.get(host, "core", "anonymous_login") then auth_provider = "anonymous"; end -- COMPAT 0.7 44 if config.get(host, "core", "anonymous_login") then
45 log("error", "Deprecated config option 'anonymous_login'. Use authentication = 'anonymous' instead.");
46 auth_provider = "anonymous";
47 end -- COMPAT 0.7
44 if provider.name == auth_provider then 48 if provider.name == auth_provider then
45 host_session.users = setmetatable(provider, provider_mt); 49 host_session.users = setmetatable(provider, provider_mt);
46 end 50 end
47 if host_session.users ~= nil and host_session.users.name ~= nil then 51 if host_session.users ~= nil and host_session.users.name ~= nil then
48 log("debug", "host '%s' now set to use user provider '%s'", host, host_session.users.name); 52 log("debug", "host '%s' now set to use user provider '%s'", host, host_session.users.name);
95 return hosts[host].users; 99 return hosts[host].users;
96 end 100 end
97 101
98 function is_admin(jid, host) 102 function is_admin(jid, host)
99 if host and not hosts[host] then return false; end 103 if host and not hosts[host] then return false; end
104 if type(jid) ~= "string" then return false; end
100 105
101 local is_admin; 106 local is_admin;
102 jid = jid_bare(jid); 107 jid = jid_bare(jid);
103 host = host or "*"; 108 host = host or "*";
104 109
106 local global_admins = config.get("*", "core", "admins"); 111 local global_admins = config.get("*", "core", "admins");
107 112
108 if host_admins and host_admins ~= global_admins then 113 if host_admins and host_admins ~= global_admins then
109 if type(host_admins) == "table" then 114 if type(host_admins) == "table" then
110 for _,admin in ipairs(host_admins) do 115 for _,admin in ipairs(host_admins) do
111 if admin == jid then 116 if jid_prep(admin) == jid then
112 is_admin = true; 117 is_admin = true;
113 break; 118 break;
114 end 119 end
115 end 120 end
116 elseif host_admins then 121 elseif host_admins then
119 end 124 end
120 125
121 if not is_admin and global_admins then 126 if not is_admin and global_admins then
122 if type(global_admins) == "table" then 127 if type(global_admins) == "table" then
123 for _,admin in ipairs(global_admins) do 128 for _,admin in ipairs(global_admins) do
124 if admin == jid then 129 if jid_prep(admin) == jid then
125 is_admin = true; 130 is_admin = true;
126 break; 131 break;
127 end 132 end
128 end 133 end
129 elseif global_admins then 134 elseif global_admins then