Comparison

plugins/mod_auth_cyrus.lua @ 3192:8ad50989d79e

mod_auth_cyrus: Auth provider with support for Cyrus SASL.
author Waqas Hussain <waqas20@gmail.com>
date Mon, 07 Jun 2010 04:23:08 +0500
child 3271:1b6c2984c1f4
comparison
equal deleted inserted replaced
3191:b6388c4f9250 3192:8ad50989d79e
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("usermanager");
11 local type = type;
12 local ipairs = ipairs;
13 local jid_bare = require "util.jid".bare;
14 local config = require "core.configmanager";
15
16 local cyrus_service_realm = module:get_option("cyrus_service_realm");
17 local cyrus_service_name = module:get_option("cyrus_service_name");
18 local cyrus_application_name = module:get_option("cyrus_application_name");
19
20 prosody.unlock_globals(); --FIXME: Figure out why this is needed and
21 -- why cyrussasl isn't caught by the sandbox
22 local cyrus_new = require "util.sasl_cyrus".new;
23 prosody.lock_globals();
24 local new_sasl = function(realm)
25 return cyrus_new(
26 cyrus_service_realm or realm,
27 cyrus_service_name or "xmpp",
28 cyrus_application_name or "prosody"
29 );
30 end
31
32 function new_default_provider(host)
33 local provider = { name = "cyrus" };
34 log("debug", "initializing default authentication provider for host '%s'", host);
35
36 function provider.test_password(username, password)
37 return nil, "Legacy auth not supported with Cyrus SASL.";
38 end
39
40 function provider.get_password(username)
41 return nil, "Passwords unavailable for Cyrus SASL.";
42 end
43
44 function provider.set_password(username, password)
45 return nil, "Passwords unavailable for Cyrus SASL.";
46 end
47
48 function provider.user_exists(username)
49 return true;
50 end
51
52 function provider.create_user(username, password)
53 return nil, "Account creation/modification not available with Cyrus SASL.";
54 end
55
56 function provider.get_sasl_handler()
57 local realm = module:get_option("sasl_realm") or module.host;
58 return new_sasl(realm);
59 end
60
61 function provider.is_admin(jid)
62 local admins = config.get(host, "core", "admins");
63 if admins ~= config.get("*", "core", "admins") and type(admins) == "table" then
64 jid = jid_bare(jid);
65 for _,admin in ipairs(admins) do
66 if admin == jid then return true; end
67 end
68 elseif admins then
69 log("error", "Option 'admins' for host '%s' is not a table", host);
70 end
71 return is_admin(jid); -- Test whether it's a global admin instead
72 end
73 return provider;
74 end
75
76 module:add_item("auth-provider", new_default_provider(module.host));
77