Annotate

plugins/mod_auth_anonymous.lua @ 12089:76b4e3f12b53 0.11 0.11.11

mod_pep: Wipe pubsub service on user deletion Data is already wiped from storage, but this ensures everything is properly unsubscribed, possibly with notifications etc. Clears recipient cache as well, since it is no longer relevant.
author Kim Alvefur <zash@zash.se>
date Thu, 04 Nov 2021 01:00:06 +0100
parent 8053:7d26dab7ce0d
child 11122:d60094d9b458
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3190
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
1 -- Prosody IM
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
4 --
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
6 -- COPYING file in the source package for more information.
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
7 --
8053
7d26dab7ce0d mod_auth_anonymous: Ignore unused arguments to various not actually implemented functions [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6023
diff changeset
8 -- luacheck: ignore 212
3190
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
9
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
10 local new_sasl = require "util.sasl".new;
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
11 local datamanager = require "util.datamanager";
5370
7838acadb0fa mod_announce, mod_auth_anonymous, mod_c2s, mod_c2s, mod_component, mod_iq, mod_message, mod_presence, mod_tls: Access prosody.{hosts,bare_sessions,full_sessions} instead of the old globals
Kim Alvefur <zash@zash.se>
parents: 5229
diff changeset
12 local hosts = prosody.hosts;
3190
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
13
5115
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
14 -- define auth provider
5117
2c7e1ce8f482 mod_auth_*: Use module:provides().
Waqas Hussain <waqas20@gmail.com>
parents: 5115
diff changeset
15 local provider = {};
3190
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16
5115
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
17 function provider.test_password(username, password)
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
18 return nil, "Password based auth not supported.";
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
19 end
3190
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
20
5115
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
21 function provider.get_password(username)
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
22 return nil, "Password not available.";
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
23 end
3190
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
24
5115
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
25 function provider.set_password(username, password)
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
26 return nil, "Password based auth not supported.";
3190
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
27 end
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28
5115
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
29 function provider.user_exists(username)
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
30 return nil, "Only anonymous users are supported."; -- FIXME check if anonymous user is connected?
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
31 end
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
32
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
33 function provider.create_user(username, password)
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
34 return nil, "Account creation/modification not supported.";
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
35 end
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
36
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
37 function provider.get_sasl_handler()
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
38 local anonymous_authentication_profile = {
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
39 anonymous = function(sasl, username, realm)
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
40 return true; -- for normal usage you should always return true here
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
41 end
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
42 };
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
43 return new_sasl(module.host, anonymous_authentication_profile);
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
44 end
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
45
5229
5566236f363f mod_auth_anonymous: Implement user iteration API
Kim Alvefur <zash@zash.se>
parents: 5117
diff changeset
46 function provider.users()
6023
93b4058e3320 mod_auth_anonymous: Fixed a traceback in listing all users (issue#396).
Waqas Hussain <waqas20@gmail.com>
parents: 5370
diff changeset
47 return next, hosts[module.host].sessions, nil;
5229
5566236f363f mod_auth_anonymous: Implement user iteration API
Kim Alvefur <zash@zash.se>
parents: 5117
diff changeset
48 end
5566236f363f mod_auth_anonymous: Implement user iteration API
Kim Alvefur <zash@zash.se>
parents: 5117
diff changeset
49
5115
3939960b3c07 mod_auth_{internal_plain,cyrus,anonymous}: Get rid of useless wrapper function new_default_provider.
Waqas Hussain <waqas20@gmail.com>
parents: 4947
diff changeset
50 -- datamanager callback to disable writes
3190
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
51 local function dm_callback(username, host, datastore, data)
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
52 if host == module.host then
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
53 return false;
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
54 end
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
55 return username, host, datastore, data;
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
56 end
4821
deec69fc33e5 mod_auth_anonymous: Block s2s when enabled on a host (and disallow_s2s ~= false)
Matthew Wild <mwild1@gmail.com>
parents: 4765
diff changeset
57
4834
878f75ccc4fb mod_s2s, mod_auth_anonymous, hostmanager: Remove disallow_s2s flag, deprecate the config option of the same name (disable mod_s2s instead), and add 'allow_anonymous_s2s' to separately control s2s for anonymous users
Matthew Wild <mwild1@gmail.com>
parents: 4821
diff changeset
58 if not module:get_option_boolean("allow_anonymous_s2s", false) then
4821
deec69fc33e5 mod_auth_anonymous: Block s2s when enabled on a host (and disallow_s2s ~= false)
Matthew Wild <mwild1@gmail.com>
parents: 4765
diff changeset
59 module:hook("route/remote", function (event)
deec69fc33e5 mod_auth_anonymous: Block s2s when enabled on a host (and disallow_s2s ~= false)
Matthew Wild <mwild1@gmail.com>
parents: 4765
diff changeset
60 return false; -- Block outgoing s2s from anonymous users
deec69fc33e5 mod_auth_anonymous: Block s2s when enabled on a host (and disallow_s2s ~= false)
Matthew Wild <mwild1@gmail.com>
parents: 4765
diff changeset
61 end, 300);
deec69fc33e5 mod_auth_anonymous: Block s2s when enabled on a host (and disallow_s2s ~= false)
Matthew Wild <mwild1@gmail.com>
parents: 4765
diff changeset
62 end
deec69fc33e5 mod_auth_anonymous: Block s2s when enabled on a host (and disallow_s2s ~= false)
Matthew Wild <mwild1@gmail.com>
parents: 4765
diff changeset
63
3190
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
64 function module.load()
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
65 datamanager.add_callback(dm_callback);
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
66 end
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
67 function module.unload()
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
68 datamanager.remove_callback(dm_callback);
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
69 end
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
70
5117
2c7e1ce8f482 mod_auth_*: Use module:provides().
Waqas Hussain <waqas20@gmail.com>
parents: 5115
diff changeset
71 module:provides("auth", provider);
3190
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
72