mod_auth_internal_hashed: Get rid of useless wrapper function new_hashpass_provider.

This commit is contained in:
Waqas Hussain 2012-09-12 21:40:00 +05:00
parent e7c19c5cb6
commit 2e28c81f01

View file

@ -39,11 +39,12 @@ end
-- Default; can be set per-user
local iteration_count = 4096;
function new_hashpass_provider(host)
local provider = { name = "internal_hashed" };
log("debug", "initializing internal_hashed authentication provider for host '%s'", host);
local host = module.host;
-- define auth provider
local provider = { name = "internal_hashed" };
log("debug", "initializing internal_hashed authentication provider for host '%s'", host);
function provider.test_password(username, password)
function provider.test_password(username, password)
local credentials = datamanager.load(username, host, "accounts") or {};
if credentials.password ~= nil and string.len(credentials.password) ~= 0 then
@ -72,9 +73,9 @@ function new_hashpass_provider(host)
else
return nil, "Auth failed. Invalid username, password, or password hash information.";
end
end
end
function provider.set_password(username, password)
function provider.set_password(username, password)
local account = datamanager.load(username, host, "accounts");
if account then
account.salt = account.salt or generate_uuid();
@ -90,18 +91,18 @@ function new_hashpass_provider(host)
return datamanager.store(username, host, "accounts", account);
end
return nil, "Account not available.";
end
end
function provider.user_exists(username)
function provider.user_exists(username)
local account = datamanager.load(username, host, "accounts");
if not account then
log("debug", "account not found for username '%s' at host '%s'", username, module.host);
log("debug", "account not found for username '%s' at host '%s'", username, host);
return nil, "Auth failed. Invalid username";
end
return true;
end
end
function provider.create_user(username, password)
function provider.create_user(username, password)
if password == nil then
return datamanager.store(username, host, "accounts", {});
end
@ -110,13 +111,13 @@ function new_hashpass_provider(host)
local stored_key_hex = to_hex(stored_key);
local server_key_hex = to_hex(server_key);
return datamanager.store(username, host, "accounts", {stored_key = stored_key_hex, server_key = server_key_hex, salt = salt, iteration_count = iteration_count});
end
end
function provider.delete_user(username)
function provider.delete_user(username)
return datamanager.store(username, host, "accounts", nil);
end
end
function provider.get_sasl_handler()
function provider.get_sasl_handler()
local testpass_authentication_profile = {
plain_test = function(sasl, username, password, realm)
local prepped_username = nodeprep(username);
@ -141,11 +142,8 @@ function new_hashpass_provider(host)
return stored_key, server_key, iteration_count, salt, true;
end
};
return new_sasl(module.host, testpass_authentication_profile);
end
return provider;
return new_sasl(host, testpass_authentication_profile);
end
module:add_item("auth-provider", new_hashpass_provider(module.host));
module:add_item("auth-provider", provider);