2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
4 -- Copyright (C) 2010 Jeff Mitchell
6 -- This project is MIT/X11 licensed. Please see the
7 -- COPYING file in the source package for more information.
10 local log = require "util.logger".init("auth_anonymous");
11 local new_sasl = require "util.sasl".new;
12 local datamanager = require "util.datamanager";
14 function new_default_provider(host)
15 local provider = { name = "anonymous" };
17 function provider.test_password(username, password)
18 return nil, "Password based auth not supported.";
21 function provider.get_password(username)
22 return nil, "Password not available.";
25 function provider.set_password(username, password)
26 return nil, "Password based auth not supported.";
29 function provider.user_exists(username)
30 return nil, "Only anonymous users are supported."; -- FIXME check if anonymous user is connected?
33 function provider.create_user(username, password)
34 return nil, "Account creation/modification not supported.";
37 function provider.get_sasl_handler()
38 local realm = module:get_option("sasl_realm") or module.host;
39 local anonymous_authentication_profile = {
40 anonymous = function(username, realm)
41 return true; -- for normal usage you should always return true here
44 return new_sasl(realm, anonymous_authentication_profile);
50 local function dm_callback(username, host, datastore, data)
51 if host == module.host then
54 return username, host, datastore, data;
56 local host = hosts[module.host];
57 local _saved_disallow_s2s = host.disallow_s2s;
58 function module.load()
59 _saved_disallow_s2s = host.disallow_s2s;
60 host.disallow_s2s = module:get_option("disallow_s2s") ~= false;
61 datamanager.add_callback(dm_callback);
63 function module.unload()
64 host.disallow_s2s = _saved_disallow_s2s;
65 datamanager.remove_callback(dm_callback);
68 module:add_item("auth-provider", new_default_provider(module.host));