Software /
code /
prosody
Changeset
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 |
parents | 12653:e4a412a54462 |
children | 12655:a5a0783e9241 |
files | core/usermanager.lua |
diffstat | 1 files changed, 9 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/core/usermanager.lua Wed Jul 20 13:10:47 2022 +0200 +++ b/core/usermanager.lua Mon Aug 01 20:26:00 2022 +0100 @@ -10,7 +10,7 @@ local log = require "util.logger".init("usermanager"); local type = type; local it = require "util.iterators"; -local jid_prep = require "util.jid".prep; +local jid_prep, jid_split = require "util.jid".prep, require "util.jid".split; local config = require "core.configmanager"; local sasl_new = require "util.sasl".new; local storagemanager = require "core.storagemanager"; @@ -196,12 +196,20 @@ local function get_jid_role(jid, host) host = host or "*"; local authz_provider = (host ~= "*" and hosts[host].authz) or global_authz_provider; + local jid_node, jid_host = jid_split(jid); + if host == jid_host and jid_node then + return authz_provider.get_user_default_role(jid_node); + end return authz_provider.get_jid_role(jid); end local function set_jid_role(jid, host, role_name) host = host or "*"; local authz_provider = (host ~= "*" and hosts[host].authz) or global_authz_provider; + local _, jid_host = jid_split(jid); + if host == jid_host then + return nil, "unexpected-local-jid"; + end return authz_provider.set_jid_role(jid, role_name) end