Changeset

315:3742107e2505

plugins/sasl: Use ANONYMOUS authentication when no username provided
author James Callahan <james@chatid.com>
date Mon, 10 Sep 2012 23:37:04 +1000
parents 314:ee5fc3ee9150
children 316:03ad51d96858
files plugins/sasl.lua
diffstat 1 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/sasl.lua	Fri Aug 31 19:40:14 2012 +0200
+++ b/plugins/sasl.lua	Mon Sep 10 23:37:04 2012 +1000
@@ -5,12 +5,16 @@
 	local function handle_features(features_stanza)
 		if stream.authenticated then return; end
 		stream:debug("Authenticating with SASL...");
-		local initial_data = base64("\0"..stream.username.."\0"..stream.password);
-	
 		--stream.sasl_state, initial_data = sasl_new({"PLAIN"}, stream.username, stream.password, stream.jid);
-		
-		stream:debug("Selecting PLAIN mechanism...");
-		local auth_stanza = verse.stanza("auth", { xmlns = xmlns_sasl, mechanism = "PLAIN" });
+		local mechanism , initial_data
+		if stream.username then
+			mechanism = "PLAIN"
+			initial_data = base64("\0"..stream.username.."\0"..stream.password);
+		else
+			mechanism = "ANONYMOUS"
+		end
+		stream:debug("Selecting %s mechanism...",mechanism);
+		local auth_stanza = verse.stanza("auth", { xmlns = xmlns_sasl, mechanism = mechanism });
 		if initial_data then
 			auth_stanza:text(initial_data);
 		end