Changeset

3065:0b8bd6f6a9c7

Merge 0.7->trunk
author Matthew Wild <mwild1@gmail.com>
date Thu, 20 May 2010 11:44:41 +0100
parents 3060:6c1cfb4cea3c (current diff) 3064:596303990c7c (diff)
children 3067:8dfa246a4413
files core/usermanager.lua
diffstat 3 files changed, 22 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/core/usermanager.lua	Thu May 20 10:48:44 2010 +0100
+++ b/core/usermanager.lua	Thu May 20 11:44:41 2010 +0100
@@ -16,6 +16,8 @@
 local config = require "core.configmanager";
 local hosts = hosts;
 
+local require_provisioning = config.get("*", "core", "cyrus_require_provisioning") or false;
+
 local prosody = _G.prosody;
 
 module "usermanager"
@@ -71,12 +73,12 @@
 	end
 
 	function provider:user_exists(username)
-		if is_cyrus(host) then return true; end
+		if not(require_provisioning) and is_cyrus(host) then return true; end
 		return datamanager.load(username, host, "accounts") ~= nil; -- FIXME also check for empty credentials
 	end
 
 	function provider:create_user(username, password)
-		if is_cyrus(host) then return nil, "Account creation/modification not available with Cyrus SASL."; end
+		if not(require_provisioning) and is_cyrus(host) then return nil, "Account creation/modification not available with Cyrus SASL."; end
 		return datamanager.store(username, host, "accounts", {password = password});
 	end
 
--- a/plugins/mod_saslauth.lua	Thu May 20 10:48:44 2010 +0100
+++ b/plugins/mod_saslauth.lua	Thu May 20 11:44:41 2010 +0100
@@ -27,6 +27,7 @@
 
 local secure_auth_only = module:get_option("c2s_require_encryption") or module:get_option("require_encryption");
 local sasl_backend = module:get_option("sasl_backend") or "builtin";
+local require_provisioning = module:get_option("cyrus_require_provisioning") or false;
 
 local log = module._log;
 
@@ -45,7 +46,7 @@
 	if ok then
 		local cyrus_new = cyrus.new;
 		new_sasl = function(realm)
-			return cyrus_new(realm, module:get_option("cyrus_service_name") or "xmpp");
+			return cyrus_new(module:get_option("cyrus_service_realm") or realm, module:get_option("cyrus_service_name") or "xmpp");
 		end
 	else
 		module:log("error", "Failed to load Cyrus SASL because: %s", cyrus);
@@ -94,7 +95,7 @@
 	return reply;
 end
 
-local function handle_status(session, status)
+local function handle_status(session, status, ret, err_msg)
 	if status == "failure" then
 		session.sasl_handler = session.sasl_handler:clean_clone();
 	elseif status == "success" then
@@ -103,12 +104,20 @@
 			module:log("warn", "SASL succeeded but we didn't get a username!");
 			session.sasl_handler = nil;
 			session:reset_stream();
-			return;
+			return status, ret, err_msg;
 		end
-		sm_make_authenticated(session, session.sasl_handler.username);
-		session.sasl_handler = nil;
-		session:reset_stream();
+
+		if not(require_provisioning) or usermanager_user_exists(username, session.host) then
+			sm_make_authenticated(session, session.sasl_handler.username);
+			session.sasl_handler = nil;
+			session:reset_stream();
+		else
+			module:log("warn", "SASL succeeded but we don't have an account provisioned for %s", username);
+			session.sasl_handler = session.sasl_handler:clean_clone();
+			return "failure", "not-authorized", "User authenticated successfully, but not provisioned for XMPP";
+		end
 	end
+	return status, ret, err_msg;
 end
 
 local function sasl_handler(session, stanza)
@@ -142,7 +151,7 @@
 		end
 	end
 	local status, ret, err_msg = session.sasl_handler:process(text);
-	handle_status(session, status);
+	status, ret, err_msg = handle_status(session, status, ret, err_msg);
 	local s = build_reply(status, ret, err_msg);
 	log("debug", "sasl reply: %s", tostring(s));
 	session.send(s);
--- a/util/sasl_cyrus.lua	Thu May 20 10:48:44 2010 +0100
+++ b/util/sasl_cyrus.lua	Thu May 20 11:44:41 2010 +0100
@@ -45,10 +45,10 @@
 end
 
 -- create a new SASL object which can be used to authenticate clients
-function new(realm, service_name)
+function new(realm, service_name, app_name)
 	local sasl_i = {};
 
-	init(service_name);
+	init(app_name or service_name);
 
 	sasl_i.realm = realm;
 	sasl_i.service_name = service_name;