mod_auth_anonymous, mod_auth_cyrus: Removed unused variables.
[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 -- Copyright (C) 2010 Jeff Mitchell
5 --
6 -- This project is MIT/X11 licensed. Please see the
7 -- COPYING file in the source package for more information.
8 --
9
10 local log = require "util.logger".init("auth_anonymous");
11 local new_sasl = require "util.sasl".new;
12 local datamanager = require "util.datamanager";
13
14 function new_default_provider(host)
15         local provider = { name = "anonymous" };
16
17         function provider.test_password(username, password)
18                 return nil, "Password based auth not supported.";
19         end
20
21         function provider.get_password(username)
22                 return nil, "Password not available.";
23         end
24
25         function provider.set_password(username, password)
26                 return nil, "Password based auth not supported.";
27         end
28
29         function provider.user_exists(username)
30                 return nil, "Only anonymous users are supported."; -- FIXME check if anonymous user is connected?
31         end
32
33         function provider.create_user(username, password)
34                 return nil, "Account creation/modification not supported.";
35         end
36
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
42                         end
43                 };
44                 return new_sasl(realm, anonymous_authentication_profile);
45         end
46
47         return provider;
48 end
49
50 local function dm_callback(username, host, datastore, data)
51         if host == module.host then
52                 return false;
53         end
54         return username, host, datastore, data;
55 end
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);
62 end
63 function module.unload()
64         host.disallow_s2s = _saved_disallow_s2s;
65         datamanager.remove_callback(dm_callback);
66 end
67
68 module:add_item("auth-provider", new_default_provider(module.host));
69