mod_auth_*: Get rid of undocumented and broken 'sasl_realm' config option.
[prosody.git] / plugins / mod_auth_anonymous.lua
1 -- Prosody IM
2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
4 --
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
7 --
8
9 local log = require "util.logger".init("auth_anonymous");
10 local new_sasl = require "util.sasl".new;
11 local datamanager = require "util.datamanager";
12
13 function new_default_provider(host)
14         local provider = { name = "anonymous" };
15
16         function provider.test_password(username, password)
17                 return nil, "Password based auth not supported.";
18         end
19
20         function provider.get_password(username)
21                 return nil, "Password not available.";
22         end
23
24         function provider.set_password(username, password)
25                 return nil, "Password based auth not supported.";
26         end
27
28         function provider.user_exists(username)
29                 return nil, "Only anonymous users are supported."; -- FIXME check if anonymous user is connected?
30         end
31
32         function provider.create_user(username, password)
33                 return nil, "Account creation/modification not supported.";
34         end
35
36         function provider.get_sasl_handler()
37                 local anonymous_authentication_profile = {
38                         anonymous = function(sasl, username, realm)
39                                 return true; -- for normal usage you should always return true here
40                         end
41                 };
42                 return new_sasl(module.host, anonymous_authentication_profile);
43         end
44
45         return provider;
46 end
47
48 local function dm_callback(username, host, datastore, data)
49         if host == module.host then
50                 return false;
51         end
52         return username, host, datastore, data;
53 end
54 local host = hosts[module.host];
55 local _saved_disallow_s2s = host.disallow_s2s;
56 function module.load()
57         _saved_disallow_s2s = host.disallow_s2s;
58         host.disallow_s2s = module:get_option("disallow_s2s") ~= false;
59         datamanager.add_callback(dm_callback);
60 end
61 function module.unload()
62         host.disallow_s2s = _saved_disallow_s2s;
63         datamanager.remove_callback(dm_callback);
64 end
65
66 module:add_item("auth-provider", new_default_provider(module.host));
67