Software /
code /
prosody-modules
Changeset
1273:1b543060f31e
mod_auth_ldap: Cleanup, reorder and some comments
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 15 Jan 2014 14:35:27 +0100 |
parents | 1272:717a08403b26 |
children | 1274:4b15437d6c56 |
files | mod_auth_ldap/mod_auth_ldap.lua |
diffstat | 1 files changed, 18 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_auth_ldap/mod_auth_ldap.lua Sat Jan 11 00:20:59 2014 +0100 +++ b/mod_auth_ldap/mod_auth_ldap.lua Wed Jan 15 14:35:27 2014 +0100 @@ -1,7 +1,9 @@ +-- mod_auth_ldap local new_sasl = require "util.sasl".new; -local log = require "util.logger".init("auth_ldap"); +local lualdap = require "lualdap"; +-- Config options local ldap_server = module:get_option_string("ldap_server", "localhost"); local ldap_rootdn = module:get_option_string("ldap_rootdn", ""); local ldap_password = module:get_option_string("ldap_password", ""); @@ -10,7 +12,7 @@ local ldap_filter = module:get_option_string("ldap_filter", "(uid=%s)"); local ldap_base = assert(module:get_option_string("ldap_base"), "ldap_base is a required option for ldap"); -local lualdap = require "lualdap"; +-- Initiate connection local ld = assert(lualdap.open_simple(ldap_server, ldap_rootdn, ldap_password, ldap_tls)); module.unload = function() ld:close(); end @@ -27,6 +29,20 @@ local provider = {}; +function provider.create_user(username, password) + return nil, "Account creation not available with LDAP."; +end + +function provider.user_exists(username) + return not not get_user(username); +end + +function provider.set_password(username, password) + local dn, attr = get_user(username); + if not dn then return nil, attr end + if attr.userPassword == password then return true end + return ld:modify(dn, { '=', userPassword = password })(); +end function provider.get_password(username) local dn, attr = get_user(username); if dn and attr then @@ -37,16 +53,6 @@ function provider.test_password(username, password) return provider.get_password(username) == password; end -function provider.user_exists(username) - return not not get_user(username); -end -function provider.set_password(username, password) - local dn, attr = get_user(username); - if not dn then return nil, attr end - if attr.userPassword == password then return true end - return ld:modify(dn, { '=', userPassword = password })(); -end -function provider.create_user(username, password) return nil, "Account creation not available with LDAP."; end function provider.get_sasl_handler() return new_sasl(module.host, {