Comparison

core/usermanager.lua @ 12654:f3dbbc7655e6

usermanager: Handle local JIDs being passed to get/set_jid_role() There is no reasonable fallback for set_jid_role() because users may have multiple roles, so that's an error.
author Matthew Wild <mwild1@gmail.com>
date Mon, 01 Aug 2022 20:26:00 +0100
parent 12653:e4a412a54462
child 12656:af315e5b71f0
comparison
equal deleted inserted replaced
12653:e4a412a54462 12654:f3dbbc7655e6
8 8
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 it = require "util.iterators"; 12 local it = require "util.iterators";
13 local jid_prep = require "util.jid".prep; 13 local jid_prep, jid_split = require "util.jid".prep, require "util.jid".split;
14 local config = require "core.configmanager"; 14 local config = require "core.configmanager";
15 local sasl_new = require "util.sasl".new; 15 local sasl_new = require "util.sasl".new;
16 local storagemanager = require "core.storagemanager"; 16 local storagemanager = require "core.storagemanager";
17 local set = require "util.set"; 17 local set = require "util.set";
18 18
194 end 194 end
195 195
196 local function get_jid_role(jid, host) 196 local function get_jid_role(jid, host)
197 host = host or "*"; 197 host = host or "*";
198 local authz_provider = (host ~= "*" and hosts[host].authz) or global_authz_provider; 198 local authz_provider = (host ~= "*" and hosts[host].authz) or global_authz_provider;
199 local jid_node, jid_host = jid_split(jid);
200 if host == jid_host and jid_node then
201 return authz_provider.get_user_default_role(jid_node);
202 end
199 return authz_provider.get_jid_role(jid); 203 return authz_provider.get_jid_role(jid);
200 end 204 end
201 205
202 local function set_jid_role(jid, host, role_name) 206 local function set_jid_role(jid, host, role_name)
203 host = host or "*"; 207 host = host or "*";
204 local authz_provider = (host ~= "*" and hosts[host].authz) or global_authz_provider; 208 local authz_provider = (host ~= "*" and hosts[host].authz) or global_authz_provider;
209 local _, jid_host = jid_split(jid);
210 if host == jid_host then
211 return nil, "unexpected-local-jid";
212 end
205 return authz_provider.set_jid_role(jid, role_name) 213 return authz_provider.set_jid_role(jid, role_name)
206 end 214 end
207 215
208 local function get_users_with_role(role, host) 216 local function get_users_with_role(role, host)
209 if not hosts[host] then return false; end 217 if not hosts[host] then return false; end