mod_auth_pam/mod_auth_pam.lua
changeset 1593 3e4d15ae2133
parent 1538 57bb2497fadc
--- a/mod_auth_pam/mod_auth_pam.lua	Tue Jan 20 11:02:14 2015 +0000
+++ b/mod_auth_pam/mod_auth_pam.lua	Sun Jan 25 13:04:02 2015 +0100
@@ -4,14 +4,21 @@
 -- Requires https://github.com/devurandom/lua-pam
 -- and LuaPosix
 
-local posix = require "posix";
+local have_posix, posix = pcall(require, "posix");
 local pam = require "pam";
 local new_sasl = require "util.sasl".new;
 
-function user_exists(username)
-	return not not posix.getpasswd(username);
+if have_posix then
+	function user_exists(username)
+		return not not posix.getpasswd(username);
+	end
+else
+	function user_exists()
+		return true;
+	end
 end
 
+
 function test_password(username, password)
 	local h, err = pam.start("xmpp", username, {
 		function (t)
@@ -21,15 +28,14 @@
 		end
 	});
 	if h and h:authenticate() and h:endx(pam.SUCCESS) then
-		return user_exists(username), true;
+		return user_exists(username);
 	end
-	return nil, true;
 end
 
 function get_sasl_handler()
 	return new_sasl(module.host, {
 		plain_test = function(sasl, ...)
-			return test_password(...)
+			return test_password(...), true;
 		end
 	});
 end