mod_sasl2_bind2/mod_sasl2_bind2.lua
changeset 5184 6361afcda1a3
parent 5097 f2dfbcc676a6
equal deleted inserted replaced
5183:5be04d1b16fb 5184:6361afcda1a3
    22 end, 1);
    22 end, 1);
    23 
    23 
    24 -- Helper to actually bind a resource to a session
    24 -- Helper to actually bind a resource to a session
    25 
    25 
    26 local function do_bind(session, bind_request)
    26 local function do_bind(session, bind_request)
    27 	local resource;
    27 	local resource = session.sasl_handler.resource;
    28 
    28 
    29 	local client_name_tag = bind_request:get_child_text("tag");
    29 	if not resource then
    30 	if client_name_tag then
    30 		local client_name_tag = bind_request:get_child_text("tag");
    31 		local client_id = session.client_id;
    31 		if client_name_tag then
    32 		local tag_suffix = client_id and base64.encode(sha1(client_id):sub(1, 9)) or id.medium();
    32 			local client_id = session.client_id;
    33 		resource = ("%s~%s"):format(client_name_tag, tag_suffix);
    33 			local tag_suffix = client_id and base64.encode(sha1(client_id):sub(1, 9)) or id.medium();
       
    34 			resource = ("%s~%s"):format(client_name_tag, tag_suffix);
       
    35 		end
    34 	end
    36 	end
    35 
    37 
    36 	local success, err_type, err, err_msg = sm_bind_resource(session, resource);
    38 	local success, err_type, err, err_msg = sm_bind_resource(session, resource);
    37 	if not success then
    39 	if not success then
    38 		session.log("debug", "Resource bind failed: %s", err_msg or err);
    40 		session.log("debug", "Resource bind failed: %s", err_msg or err);