annotate mod_report_affiliations/traits.lib.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 e905ef16efb7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6030
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local known_traits = {};
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local function trait_added(event)
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 local trait = event.item;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local name = trait.name;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 if known_traits[name] then return; end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 known_traits[name] = trait.probabilities;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local function trait_removed(event)
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local trait = event.item;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 known_traits[trait.name] = nil;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 module:handle_items("account-trait", trait_added, trait_removed);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 local function bayes_probability(prior, prob_given_true, prob_given_false)
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 local numerator = prob_given_true * prior;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 local denominator = numerator + prob_given_false * (1 - prior);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 return numerator / denominator;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 local function prob_is_bad(traits, prior)
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 prior = prior or 0.50;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 for trait, state in pairs(traits) do
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 local probabilities = known_traits[trait];
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 if probabilities then
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 if state then
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 prior = bayes_probability(
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 prior,
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 probabilities.prob_bad_true,
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 probabilities.prob_bad_false
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 );
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 else
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 prior = bayes_probability(
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 prior,
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 1 - probabilities.prob_bad_true,
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 1 - probabilities.prob_bad_false
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 );
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 return prior;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 local function get_probability_bad(username, prior)
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 local user_traits = {};
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 module:fire_event("get-account-traits", { username = username, host = module.host, traits = user_traits });
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 local result = prob_is_bad(user_traits, prior);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 return result;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 return {
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 get_probability_bad = get_probability_bad;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 };