annotate mod_muc_restrict_status/mod_muc_restrict_status.lua @ 6319:04c3273cb81f

mod_auth_cyrus: Add empty 'profile' table to SASL handler objects This is for compatibility with Prosody's built-in util.sasl objects. A SASL profile table usually includes methods supported by the backend, which can be used by SASL mechanism handlers to perform operations (such as testing the password). It also optionally contains a 'cb' field with channel binding method handlers. The Cyrus backend doesn't support channel binding, and doesn't have the same concept of auth backend methods (it handles all that internally, and Prosody has no insight or control over it). Thus, we create an empty profile which informs Prosody that the SASL handler does not support any of the auth or channel binding methods. Some features will not work, but they didn't work anyway. This just makes it explicit. This fixes a traceback in mod_sasl2_fast, which expected SASL handlers to always contain a 'profile' field.
author Matthew Wild <mwild1@gmail.com>
date Thu, 04 Sep 2025 10:14:46 +0100
parents 52bd0ac397b5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6315
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
1 module:depends"muc";
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
2
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
3 local restrict_by_default = module:get_option_boolean("muc_room_default_restrict_status", true);
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
4
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
5 local function should_restrict_status(room)
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
6 local restrict_status = room._data.restrict_status;
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
7 if restrict_status == nil then
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
8 restrict_status = restrict_by_default;
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
9 end
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
10 return restrict_status;
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
11 end
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
12
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
13 module:hook("muc-config-form", function(event)
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
14 local room, form = event.room, event.form;
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
15 table.insert(form, {
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
16 name = "{xmpp:prosody.im}muc#roomconfig_unaffiliated_status",
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
17 type = "boolean",
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
18 label = "Display status message from non-members",
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
19 value = not should_restrict_status(room),
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
20 });
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
21 end);
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
22
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
23 module:hook("muc-config-submitted", function(event)
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
24 local room, fields, changed = event.room, event.fields, event.changed;
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
25 local new_restrict_status = not fields["{xmpp:prosody.im}muc#roomconfig_unaffiliated_status"];
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
26 if new_restrict_status ~= should_restrict_status(room) then
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
27 if new_restrict_status == restrict_by_default then
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
28 room._data.restrict_status = nil;
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
29 else
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
30 room._data.restrict_status = new_restrict_status;
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
31 end
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
32 if type(changed) == "table" then
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
33 changed["{xmpp:prosody.im}muc#roomconfig_unaffiliated_status"] = true;
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
34 else
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
35 event.changed = true;
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
36 end
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
37 end
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
38 end);
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
39
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
40 module:hook("muc-disco#info", function (event)
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
41 local room, form, formdata = event.room, event.form, event.formdata;
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
42
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
43 local allow_unaffiliated_status = not should_restrict_status(room);
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
44 table.insert(form, {
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
45 name = "{xmpp:prosody.im}muc#roomconfig_unaffiliated_status",
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
46 type = "boolean",
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
47 });
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
48 formdata["{xmpp:prosody.im}muc#roomconfig_unaffiliated_status"] = allow_unaffiliated_status;
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
49 end);
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
50
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
51 local function filter_status_tags(tag)
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
52 if tag.name == "status" then
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
53 return nil;
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
54 end
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
55 return tag;
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
56 end
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
57
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
58 local function thehook(event)
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
59 local stanza = event.stanza;
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
60 if event.room:get_affiliation(stanza.attr.from) then return end
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
61 if should_restrict_status(event.room) then
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
62 stanza:maptags(filter_status_tags);
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
63 end
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
64 end
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
65
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
66 module:hook("muc-occupant-pre-join", thehook, 20);
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
67 module:hook("muc-occupant-pre-leave", thehook, 20);
52bd0ac397b5 mod_muc_restrict_status: create new module
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
diff changeset
68 module:hook("muc-occupant-pre-change", thehook, 20);