Software /
code /
prosody
Comparison
core/usermanager.lua @ 4459:2ccc386b9913
usermanager: Prep admin JIDs (fixes issue#276).
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Wed, 14 Dec 2011 07:19:58 +0500 |
parent | 4237:6b0d7d94eb7f |
child | 4773:ee55956597f4 |
comparison
equal
deleted
inserted
replaced
4458:9f6c68cb3fbd | 4459:2ccc386b9913 |
---|---|
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; |
95 return hosts[host].users; | 96 return hosts[host].users; |
96 end | 97 end |
97 | 98 |
98 function is_admin(jid, host) | 99 function is_admin(jid, host) |
99 if host and not hosts[host] then return false; end | 100 if host and not hosts[host] then return false; end |
101 if type(jid) ~= "string" then return false; end | |
100 | 102 |
101 local is_admin; | 103 local is_admin; |
102 jid = jid_bare(jid); | 104 jid = jid_bare(jid); |
103 host = host or "*"; | 105 host = host or "*"; |
104 | 106 |
106 local global_admins = config.get("*", "core", "admins"); | 108 local global_admins = config.get("*", "core", "admins"); |
107 | 109 |
108 if host_admins and host_admins ~= global_admins then | 110 if host_admins and host_admins ~= global_admins then |
109 if type(host_admins) == "table" then | 111 if type(host_admins) == "table" then |
110 for _,admin in ipairs(host_admins) do | 112 for _,admin in ipairs(host_admins) do |
111 if admin == jid then | 113 if jid_prep(admin) == jid then |
112 is_admin = true; | 114 is_admin = true; |
113 break; | 115 break; |
114 end | 116 end |
115 end | 117 end |
116 elseif host_admins then | 118 elseif host_admins then |
119 end | 121 end |
120 | 122 |
121 if not is_admin and global_admins then | 123 if not is_admin and global_admins then |
122 if type(global_admins) == "table" then | 124 if type(global_admins) == "table" then |
123 for _,admin in ipairs(global_admins) do | 125 for _,admin in ipairs(global_admins) do |
124 if admin == jid then | 126 if jid_prep(admin) == jid then |
125 is_admin = true; | 127 is_admin = true; |
126 break; | 128 break; |
127 end | 129 end |
128 end | 130 end |
129 elseif global_admins then | 131 elseif global_admins then |