| 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 log = require "util.logger".init("auth_cyrus"); |
| 10 | |
| 11 | local usermanager_user_exists = require "core.usermanager".user_exists; |
| 12 | |
| 13 | local cyrus_service_realm = module:get_option("cyrus_service_realm"); |
| 14 | local cyrus_service_name = module:get_option("cyrus_service_name"); |
| 15 | local cyrus_application_name = module:get_option("cyrus_application_name"); |
| 16 | local require_provisioning = module:get_option("cyrus_require_provisioning") or false; |
| 17 | |
| 18 | prosody.unlock_globals(); --FIXME: Figure out why this is needed and |
| 19 | -- why cyrussasl isn't caught by the sandbox |
| 20 | local cyrus_new = require "util.sasl_cyrus".new; |
| 21 | prosody.lock_globals(); |
| 22 | local new_sasl = function(realm) |
| 23 | return cyrus_new( |
| 24 | cyrus_service_realm or realm, |
| 25 | cyrus_service_name or "xmpp", |
| 26 | cyrus_application_name or "prosody" |
| 27 | ); |
| 28 | end |
| 29 | |
| 30 | function new_default_provider(host) |
| 31 | local provider = { name = "cyrus" }; |
| 32 | log("debug", "initializing default authentication provider for host '%s'", host); |
| 33 | |
| 34 | function provider.test_password(username, password) |
| 35 | return nil, "Legacy auth not supported with Cyrus SASL."; |
| 36 | end |
| 37 | |
| 38 | function provider.get_password(username) |
| 39 | return nil, "Passwords unavailable for Cyrus SASL."; |
| 40 | end |
| 41 | |
| 42 | function provider.set_password(username, password) |
| 43 | return nil, "Passwords unavailable for Cyrus SASL."; |
| 44 | end |
| 45 | |
| 46 | function provider.user_exists(username) |
| 47 | if require_provisioning then |
| 48 | return usermanager_user_exists(username, module.host); |
| 49 | end |
| 50 | return true; |
| 51 | end |
| 52 | |
| 53 | function provider.create_user(username, password) |
| 54 | return nil, "Account creation/modification not available with Cyrus SASL."; |
| 55 | end |
| 56 | |
| 57 | function provider.get_sasl_handler() |
| 58 | local realm = module:get_option("sasl_realm") or module.host; |
| 59 | local handler = new_sasl(realm); |
| 60 | if require_provisioning then |
| 61 | function handler.require_provisioning(username) |
| 62 | return usermanager_user_exists(username, module.host); |
| 63 | end |
| 64 | end |
| 65 | return handler; |
| 66 | end |
| 67 | |
| 68 | return provider; |
| 69 | end |
| 70 | |
| 71 | module:add_item("auth-provider", new_default_provider(module.host)); |