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 log = require "util.logger".init("auth_anonymous");
10 local new_sasl = require "util.sasl".new;
11 local datamanager = require "util.datamanager";
13 function new_default_provider(host)
14 local provider = { name = "anonymous" };
16 function provider.test_password(username, password)
17 return nil, "Password based auth not supported.";
20 function provider.get_password(username)
21 return nil, "Password not available.";
24 function provider.set_password(username, password)
25 return nil, "Password based auth not supported.";
28 function provider.user_exists(username)
29 return nil, "Only anonymous users are supported."; -- FIXME check if anonymous user is connected?
32 function provider.create_user(username, password)
33 return nil, "Account creation/modification not supported.";
36 function provider.get_sasl_handler()
37 local realm = module:get_option("sasl_realm") or module.host;
38 local anonymous_authentication_profile = {
39 anonymous = function(sasl, username, realm)
40 return true; -- for normal usage you should always return true here
43 return new_sasl(realm, anonymous_authentication_profile);
49 local function dm_callback(username, host, datastore, data)
50 if host == module.host then
53 return username, host, datastore, data;
55 local host = hosts[module.host];
56 local _saved_disallow_s2s = host.disallow_s2s;
57 function module.load()
58 _saved_disallow_s2s = host.disallow_s2s;
59 host.disallow_s2s = module:get_option("disallow_s2s") ~= false;
60 datamanager.add_callback(dm_callback);
62 function module.unload()
63 host.disallow_s2s = _saved_disallow_s2s;
64 datamanager.remove_callback(dm_callback);
67 module:add_item("auth-provider", new_default_provider(module.host));