net.http.server: Properly handle persistent connections
[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 -- define auth provider
13 local provider = {};
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 function provider.users()
45         return next, hosts[host].sessions, nil;
46 end
47
48 -- datamanager callback to disable writes
49 local function dm_callback(username, host, datastore, data)
50         if host == module.host then
51                 return false;
52         end
53         return username, host, datastore, data;
54 end
55
56 if not module:get_option_boolean("allow_anonymous_s2s", false) then
57         module:hook("route/remote", function (event)
58                 return false; -- Block outgoing s2s from anonymous users
59         end, 300);
60 end
61
62 function module.load()
63         datamanager.add_callback(dm_callback);
64 end
65 function module.unload()
66         datamanager.remove_callback(dm_callback);
67 end
68
69 module:provides("auth", provider);
70