Annotate

plugins/mod_auth_anonymous.lua @ 5284:5d2282a29387

net.server: Don't return anything from config-reloaded hook, fixes logrotate heisenbug
author Kim Alvefur <zash@zash.se>
date Sat, 29 Dec 2012 19:09:23 +0100
parent 5229:5566236f363f
child 5370:7838acadb0fa
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 --
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
8
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
9 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
10 local datamanager = require "util.datamanager";
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
11
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
12 -- define auth provider
5117
2c7e1ce8f482 mod_auth_*: Use module:provides().
Waqas Hussain <waqas20@gmail.com>
parents: 5115
diff changeset
13 local provider = {};
3190
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14
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
15 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
16 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
17 end
3190
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
18
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
19 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
20 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
21 end
3190
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22
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
23 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
24 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
25 end
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26
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
27 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
28 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
29 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
30
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 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
32 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
33 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
34
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 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
36 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
37 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
38 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
39 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
40 };
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 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
42 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
43
5229
5566236f363f mod_auth_anonymous: Implement user iteration API
Kim Alvefur <zash@zash.se>
parents: 5117
diff changeset
44 function provider.users()
5566236f363f mod_auth_anonymous: Implement user iteration API
Kim Alvefur <zash@zash.se>
parents: 5117
diff changeset
45 return next, hosts[host].sessions, nil;
5566236f363f mod_auth_anonymous: Implement user iteration API
Kim Alvefur <zash@zash.se>
parents: 5117
diff changeset
46 end
5566236f363f mod_auth_anonymous: Implement user iteration API
Kim Alvefur <zash@zash.se>
parents: 5117
diff changeset
47
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
48 -- 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
49 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
50 if host == module.host then
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
51 return false;
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
52 end
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
53 return username, host, datastore, data;
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
54 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
55
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
56 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
57 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
58 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
59 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
60 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
61
3190
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
62 function module.load()
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
63 datamanager.add_callback(dm_callback);
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
64 end
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
65 function module.unload()
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
66 datamanager.remove_callback(dm_callback);
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
67 end
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
68
5117
2c7e1ce8f482 mod_auth_*: Use module:provides().
Waqas Hussain <waqas20@gmail.com>
parents: 5115
diff changeset
69 module:provides("auth", provider);
3190
c4069680a01c mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
70