mod_auth_anonymous: add disallow_s2s to the host object if s2s communication is disal...
[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 new_sasl = require "util.sasl".new;
10 local datamanager = require "util.datamanager";
11
12 function new_default_provider(host)
13         local provider = { name = "anonymous" };
14
15         function provider.test_password(username, password)
16                 return nil, "Password based auth not supported.";
17         end
18
19         function provider.get_password(username)
20                 return nil, "Password not available.";
21         end
22
23         function provider.set_password(username, password)
24                 return nil, "Password based auth not supported.";
25         end
26
27         function provider.user_exists(username)
28                 return nil, "Only anonymous users are supported."; -- FIXME check if anonymous user is connected?
29         end
30
31         function provider.create_user(username, password)
32                 return nil, "Account creation/modification not supported.";
33         end
34
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
39                         end
40                 };
41                 return new_sasl(module.host, anonymous_authentication_profile);
42         end
43
44         return provider;
45 end
46
47 local function dm_callback(username, host, datastore, data)
48         if host == module.host then
49                 return false;
50         end
51         return username, host, datastore, data;
52 end
53
54 if module:get_option_boolean("disallow_s2s", true) then
55         hosts[module.host].disallow_s2s = true;
56         module:hook("route/remote", function (event)
57                 return false; -- Block outgoing s2s from anonymous users
58         end, 300);
59 end
60
61 function module.load()
62         datamanager.add_callback(dm_callback);
63 end
64 function module.unload()
65         datamanager.remove_callback(dm_callback);
66 end
67
68 module:add_item("auth-provider", new_default_provider(module.host));
69