changeset 5180:6361afcda1a3

mod_sasl2_bind2: Support for SASL handlers forcing a specific resource
author Matthew Wild <mwild1@gmail.com>
date Wed, 01 Mar 2023 13:21:29 +0000
parents 5be04d1b16fb
children 2c6acf2d6fd4
files mod_sasl2_bind2/mod_sasl2_bind2.lua
diffstat 1 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mod_sasl2_bind2/mod_sasl2_bind2.lua	Tue Feb 28 18:15:20 2023 +0100
+++ b/mod_sasl2_bind2/mod_sasl2_bind2.lua	Wed Mar 01 13:21:29 2023 +0000
@@ -24,13 +24,15 @@
 -- Helper to actually bind a resource to a session
 
 local function do_bind(session, bind_request)
-	local resource;
+	local resource = session.sasl_handler.resource;
 
-	local client_name_tag = bind_request:get_child_text("tag");
-	if client_name_tag then
-		local client_id = session.client_id;
-		local tag_suffix = client_id and base64.encode(sha1(client_id):sub(1, 9)) or id.medium();
-		resource = ("%s~%s"):format(client_name_tag, tag_suffix);
+	if not resource then
+		local client_name_tag = bind_request:get_child_text("tag");
+		if client_name_tag then
+			local client_id = session.client_id;
+			local tag_suffix = client_id and base64.encode(sha1(client_id):sub(1, 9)) or id.medium();
+			resource = ("%s~%s"):format(client_name_tag, tag_suffix);
+		end
 	end
 
 	local success, err_type, err, err_msg = sm_bind_resource(session, resource);