Changeset

2904:3e06b0f52363

Merge 0.7->trunk
author Matthew Wild <mwild1@gmail.com>
date Thu, 18 Mar 2010 10:11:11 +0000
parents 2900:5b8411968a05 (current diff) 2903:d6da8f8e3502 (diff)
children 2906:2b54ef7cec32
files
diffstat 1 files changed, 12 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/util/sasl_cyrus.lua	Thu Mar 18 01:44:55 2010 +0000
+++ b/util/sasl_cyrus.lua	Thu Mar 18 10:11:11 2010 +0000
@@ -39,7 +39,7 @@
 		if st then
 			initialized = true;
 		else
-			log("error", "Failed to initialize CyrusSASL: %s", errmsg);
+			log("error", "Failed to initialize Cyrus SASL: %s", errmsg);
 		end
 	end
 end
@@ -52,7 +52,14 @@
 
 	sasl_i.realm = realm;
 	sasl_i.service_name = service_name;
-	sasl_i.cyrus = cyrussasl.server_new(service_name, nil, realm, nil, nil)
+
+	local st, ret = pcall(cyrussasl.server_new, service_name, nil, realm, nil, nil)
+	if st then
+		sasl_i.cyrus = ret;
+	else
+		log("error", "Creating SASL server connection failed: %s", ret);
+		return nil;
+	end
 
 	if cyrussasl.set_canon_cb then
 		local c14n_cb = function (user)
@@ -63,10 +70,6 @@
 		cyrussasl.set_canon_cb(sasl_i.cyrus, c14n_cb);
 	end
 
-	if sasl_i.cyrus == 0 then
-		log("error", "got NULL return value from server_new")
-		return nil;
-	end
 	cyrussasl.setssf(sasl_i.cyrus, 0, 0xffffffff)
 	local s = setmetatable(sasl_i, method);
 	return s;
@@ -79,7 +82,7 @@
 
 -- set the forbidden mechanisms
 function method:forbidden( restrict )
-	log("debug", "Called method:forbidden. NOT IMPLEMENTED.")
+	log("warn", "Called method:forbidden. NOT IMPLEMENTED.")
 	return {}
 end
 
@@ -120,16 +123,12 @@
 	   return "challenge", data
 	elseif (err == -4) then -- SASL_NOMECH
 	   log("debug", "SASL mechanism not available from remote end")
-	   return "failure", 
-	     "undefined-condition",
-	     "SASL mechanism not available"
+	   return "failure", "invalid-mechanism", "SASL mechanism not available"
 	elseif (err == -13) then -- SASL_BADAUTH
 	   return "failure", "not-authorized", cyrussasl.get_message( self.cyrus )
 	else
 	   log("debug", "Got SASL error condition %d", err)
-	   return "failure", 
-	     "undefined-condition",
-	     cyrussasl.get_message( self.cyrus )
+	   return "failure", "undefined-condition", cyrussasl.get_message( self.cyrus )
 	end
 end