Mercurial > prosody-hg
comparison plugins/adhoc/mod_adhoc.lua @ 13097:6771acb8e857
mod_adhoc: Silence permission errors when listing commands
Since throwing a pile of 'access denied', even at debug level, seems
akin to calling wolf :)
Cutting down on debug noise is also good.
Passing a flag instead of using module:could seemed easier here.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 07 May 2023 13:13:42 +0200 |
| parents | 3174308d127e |
| children |
comparison
equal
deleted
inserted
replaced
| 13096:9638ff8b1c81 | 13097:6771acb8e857 |
|---|---|
| 12 local xmlns_cmd = "http://jabber.org/protocol/commands"; | 12 local xmlns_cmd = "http://jabber.org/protocol/commands"; |
| 13 local commands = {}; | 13 local commands = {}; |
| 14 | 14 |
| 15 module:add_feature(xmlns_cmd); | 15 module:add_feature(xmlns_cmd); |
| 16 | 16 |
| 17 local function check_permissions(event, node, command) | 17 local function check_permissions(event, node, command, execute) |
| 18 return (command.permission == "check" and module:may("adhoc:"..node, event)) | 18 return (command.permission == "check" and module:may("adhoc:"..node, event, not execute)) |
| 19 or (command.permission == "local_user" and jid_host(event.stanza.attr.from) == module.host) | 19 or (command.permission == "local_user" and jid_host(event.stanza.attr.from) == module.host) |
| 20 or (command.permission == "any"); | 20 or (command.permission == "any"); |
| 21 end | 21 end |
| 22 | 22 |
| 23 module:hook("host-disco-info-node", function (event) | 23 module:hook("host-disco-info-node", function (event) |
| 60 module:hook("iq-set/host/"..xmlns_cmd..":command", function (event) | 60 module:hook("iq-set/host/"..xmlns_cmd..":command", function (event) |
| 61 local origin, stanza = event.origin, event.stanza; | 61 local origin, stanza = event.origin, event.stanza; |
| 62 local node = stanza.tags[1].attr.node | 62 local node = stanza.tags[1].attr.node |
| 63 local command = commands[node]; | 63 local command = commands[node]; |
| 64 if command then | 64 if command then |
| 65 if not check_permissions(event, node, command) then | 65 if not check_permissions(event, node, command, true) then |
| 66 origin.send(st.error_reply(stanza, "auth", "forbidden", "You don't have permission to execute this command"):up() | 66 origin.send(st.error_reply(stanza, "auth", "forbidden", "You don't have permission to execute this command"):up() |
| 67 :add_child(command:cmdtag("canceled") | 67 :add_child(command:cmdtag("canceled") |
| 68 :tag("note", {type="error"}):text("You don't have permission to execute this command"))); | 68 :tag("note", {type="error"}):text("You don't have permission to execute this command"))); |
| 69 return true | 69 return true |
| 70 end | 70 end |
