Software /
code /
prosody
Annotate
plugins/mod_auth_ldap.lua @ 13076:f4e33d17eaa8
mod_tls: Drop request for client certificates on outgoing connections
It is the other end who should request client certificates for these
connections, we only need to send ours. Hopefully this was treated as a
noop, so probably no harm in keeping it. But hey, spring cleaning? :)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 19 Apr 2023 11:14:11 +0200 |
parent | 12977:74b9e05af71e |
child | 13224:71c28b36923f |
rev | line source |
---|---|
11837
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 -- mod_auth_ldap |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 |
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12642
diff
changeset
|
3 local new_sasl = require "prosody.util.sasl".new; |
11837
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 local lualdap = require "lualdap"; |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 local function ldap_filter_escape(s) |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 return (s:gsub("[*()\\%z]", function(c) return ("\\%02x"):format(c:byte()) end)); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 -- Config options |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 local ldap_server = module:get_option_string("ldap_server", "localhost"); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 local ldap_rootdn = module:get_option_string("ldap_rootdn", ""); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 local ldap_password = module:get_option_string("ldap_password", ""); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 local ldap_tls = module:get_option_boolean("ldap_tls"); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 local ldap_scope = module:get_option_string("ldap_scope", "subtree"); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 local ldap_filter = module:get_option_string("ldap_filter", "(uid=$user)"):gsub("%%s", "$user", 1); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 local ldap_base = assert(module:get_option_string("ldap_base"), "ldap_base is a required option for ldap"); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 local ldap_mode = module:get_option_string("ldap_mode", "bind"); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 local ldap_admins = module:get_option_string("ldap_admin_filter", |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 module:get_option_string("ldap_admins")); -- COMPAT with mistake in documentation |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 local host = ldap_filter_escape(module:get_option_string("realm", module.host)); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 |
12642
9061f9621330
Switch to a new role-based authorization framework, removing is_admin()
Matthew Wild <mwild1@gmail.com>
parents:
11837
diff
changeset
|
23 if ldap_admins then |
9061f9621330
Switch to a new role-based authorization framework, removing is_admin()
Matthew Wild <mwild1@gmail.com>
parents:
11837
diff
changeset
|
24 module:log("error", "The 'ldap_admin_filter' option has been deprecated, ".. |
9061f9621330
Switch to a new role-based authorization framework, removing is_admin()
Matthew Wild <mwild1@gmail.com>
parents:
11837
diff
changeset
|
25 "and will be ignored. Equivalent functionality may be added in ".. |
9061f9621330
Switch to a new role-based authorization framework, removing is_admin()
Matthew Wild <mwild1@gmail.com>
parents:
11837
diff
changeset
|
26 "the future if there is demand." |
9061f9621330
Switch to a new role-based authorization framework, removing is_admin()
Matthew Wild <mwild1@gmail.com>
parents:
11837
diff
changeset
|
27 ); |
9061f9621330
Switch to a new role-based authorization framework, removing is_admin()
Matthew Wild <mwild1@gmail.com>
parents:
11837
diff
changeset
|
28 end |
9061f9621330
Switch to a new role-based authorization framework, removing is_admin()
Matthew Wild <mwild1@gmail.com>
parents:
11837
diff
changeset
|
29 |
11837
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 -- Initiate connection |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 local ld = nil; |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 module.unload = function() if ld then pcall(ld, ld.close); end end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 function ldap_do_once(method, ...) |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 if ld == nil then |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 local err; |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 ld, err = lualdap.open_simple(ldap_server, ldap_rootdn, ldap_password, ldap_tls); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 if not ld then return nil, err, "reconnect"; end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 -- luacheck: ignore 411/success |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 local success, iterator, invariant, initial = pcall(ld[method], ld, ...); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 if not success then ld = nil; return nil, iterator, "search"; end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 local success, dn, attr = pcall(iterator, invariant, initial); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 if not success then ld = nil; return success, dn, "iter"; end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 return dn, attr, "return"; |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 function ldap_do(method, retry_count, ...) |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 local dn, attr, where; |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 for _=1,1+retry_count do |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 dn, attr, where = ldap_do_once(method, ...); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 if dn or not(attr) then break; end -- nothing or something found |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 module:log("warn", "LDAP: %s %s (in %s)", tostring(dn), tostring(attr), where); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 -- otherwise retry |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
58 end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
59 if not dn and attr then |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
60 module:log("error", "LDAP: %s", tostring(attr)); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
61 end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
62 return dn, attr; |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
63 end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
64 |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
65 function get_user(username) |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
66 module:log("debug", "get_user(%q)", username); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
67 return ldap_do("search", 2, { |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
68 base = ldap_base; |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
69 scope = ldap_scope; |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
70 sizelimit = 1; |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
71 filter = ldap_filter:gsub("%$(%a+)", { |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
72 user = ldap_filter_escape(username); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
73 host = host; |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
74 }); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
75 }); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
76 end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
78 local provider = {}; |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
79 |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
80 function provider.create_user(username, password) -- luacheck: ignore 212 |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
81 return nil, "Account creation not available with LDAP."; |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
82 end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
83 |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
84 function provider.user_exists(username) |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
85 return not not get_user(username); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
86 end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
87 |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
88 function provider.set_password(username, password) |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
89 local dn, attr = get_user(username); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
90 if not dn then return nil, attr end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
91 if attr.userPassword == password then return true end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
92 return ldap_do("modify", 2, dn, { '=', userPassword = password }); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
93 end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
94 |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
95 if ldap_mode == "getpasswd" then |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
96 function provider.get_password(username) |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
97 local dn, attr = get_user(username); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
98 if dn and attr then |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
99 return attr.userPassword; |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
100 end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
101 end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
102 |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
103 function provider.test_password(username, password) |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
104 return provider.get_password(username) == password; |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
105 end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
106 |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
107 function provider.get_sasl_handler() |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
108 return new_sasl(module.host, { |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
109 plain = function(sasl, username) -- luacheck: ignore 212/sasl |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
110 local password = provider.get_password(username); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
111 if not password then return "", nil; end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
112 return password, true; |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
113 end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
114 }); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
115 end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
116 elseif ldap_mode == "bind" then |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
117 local function test_password(userdn, password) |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
118 local ok, err = lualdap.open_simple(ldap_server, userdn, password, ldap_tls); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
119 if not ok then |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
120 module:log("debug", "ldap open_simple error: %s", err); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
121 end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
122 return not not ok; |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
123 end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
124 |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
125 function provider.test_password(username, password) |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
126 local dn = get_user(username); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
127 if not dn then return end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
128 return test_password(dn, password) |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
129 end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
130 |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
131 function provider.get_sasl_handler() |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
132 return new_sasl(module.host, { |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
133 plain_test = function(sasl, username, password) -- luacheck: ignore 212/sasl |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
134 return provider.test_password(username, password), true; |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
135 end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
136 }); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
137 end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
138 else |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
139 module:log("error", "Unsupported ldap_mode %s", tostring(ldap_mode)); |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
140 end |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
141 |
a37bf4497280
mod_auth_ldap: Import from prosody-modules rev f52452911187
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
142 module:provides("auth", provider); |