mod_csi_simple: Consider messages encrypted payload as important (fixes part of ...
[prosody.git] / plugins / mod_auth_anonymous.lua
blob1f2bceb3dd841c667830ed37004f46c8aa29ca3b
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 -- luacheck: ignore 212
10 local new_sasl = require "util.sasl".new;
11 local datamanager = require "util.datamanager";
12 local hosts = prosody.hosts;
14 -- define auth provider
15 local provider = {};
17 function provider.test_password(username, password)
18 return nil, "Password based auth not supported.";
19 end
21 function provider.get_password(username)
22 return nil, "Password not available.";
23 end
25 function provider.set_password(username, password)
26 return nil, "Password based auth not supported.";
27 end
29 function provider.user_exists(username)
30 return nil, "Only anonymous users are supported."; -- FIXME check if anonymous user is connected?
31 end
33 function provider.create_user(username, password)
34 return nil, "Account creation/modification not supported.";
35 end
37 function provider.get_sasl_handler()
38 local anonymous_authentication_profile = {
39 anonymous = function(sasl, username, realm)
40 return true; -- for normal usage you should always return true here
41 end
43 return new_sasl(module.host, anonymous_authentication_profile);
44 end
46 function provider.users()
47 return next, hosts[module.host].sessions, nil;
48 end
50 -- datamanager callback to disable writes
51 local function dm_callback(username, host, datastore, data)
52 if host == module.host then
53 return false;
54 end
55 return username, host, datastore, data;
56 end
58 if not module:get_option_boolean("allow_anonymous_s2s", false) then
59 module:hook("route/remote", function (event)
60 return false; -- Block outgoing s2s from anonymous users
61 end, 300);
62 end
64 function module.load()
65 datamanager.add_callback(dm_callback);
66 end
67 function module.unload()
68 datamanager.remove_callback(dm_callback);
69 end
71 module:provides("auth", provider);