2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
9 local new_sasl = require "util.sasl".new;
10 local datamanager = require "util.datamanager";
12 function new_default_provider(host)
13 local provider = { name = "anonymous" };
15 function provider.test_password(username, password)
16 return nil, "Password based auth not supported.";
19 function provider.get_password(username)
20 return nil, "Password not available.";
23 function provider.set_password(username, password)
24 return nil, "Password based auth not supported.";
27 function provider.user_exists(username)
28 return nil, "Only anonymous users are supported."; -- FIXME check if anonymous user is connected?
31 function provider.create_user(username, password)
32 return nil, "Account creation/modification not supported.";
35 function provider.get_sasl_handler()
36 local anonymous_authentication_profile = {
37 anonymous = function(sasl, username, realm)
38 return true; -- for normal usage you should always return true here
41 return new_sasl(module.host, anonymous_authentication_profile);
47 local function dm_callback(username, host, datastore, data)
48 if host == module.host then
51 return username, host, datastore, data;
53 local host = hosts[module.host];
54 local _saved_disallow_s2s = host.disallow_s2s;
55 function module.load()
56 _saved_disallow_s2s = host.disallow_s2s;
57 host.disallow_s2s = module:get_option("disallow_s2s") ~= false;
58 datamanager.add_callback(dm_callback);
60 function module.unload()
61 host.disallow_s2s = _saved_disallow_s2s;
62 datamanager.remove_callback(dm_callback);
65 module:add_item("auth-provider", new_default_provider(module.host));