Software /
code /
prosody-modules
Comparison
mod_auth_ldap/mod_auth_ldap.lua @ 2775:8407137c0a3b
mod_auth_ldap: Add annotations to ignore harmless warnings [luacheck]
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 26 Sep 2017 12:35:25 +0200 |
parent | 2774:41565a743cad |
child | 2851:4b10636bd743 |
comparison
equal
deleted
inserted
replaced
2774:41565a743cad | 2775:8407137c0a3b |
---|---|
29 local err; | 29 local err; |
30 ld, err = lualdap.open_simple(ldap_server, ldap_rootdn, ldap_password, ldap_tls); | 30 ld, err = lualdap.open_simple(ldap_server, ldap_rootdn, ldap_password, ldap_tls); |
31 if not ld then return nil, err, "reconnect"; end | 31 if not ld then return nil, err, "reconnect"; end |
32 end | 32 end |
33 | 33 |
34 -- luacheck: ignore 411/success | |
34 local success, iterator, invariant, initial = pcall(ld[method], ld, ...); | 35 local success, iterator, invariant, initial = pcall(ld[method], ld, ...); |
35 if not success then ld = nil; return nil, iterator, "search"; end | 36 if not success then ld = nil; return nil, iterator, "search"; end |
36 | 37 |
37 local success, dn, attr = pcall(iterator, invariant, initial); | 38 local success, dn, attr = pcall(iterator, invariant, initial); |
38 if not success then ld = nil; return success, dn, "iter"; end | 39 if not success then ld = nil; return success, dn, "iter"; end |
40 return dn, attr, "return"; | 41 return dn, attr, "return"; |
41 end | 42 end |
42 | 43 |
43 function ldap_do(method, retry_count, ...) | 44 function ldap_do(method, retry_count, ...) |
44 local dn, attr, where; | 45 local dn, attr, where; |
45 for i=1,1+retry_count do | 46 for _=1,1+retry_count do |
46 dn, attr, where = ldap_do_once(method, ...); | 47 dn, attr, where = ldap_do_once(method, ...); |
47 if dn or not(attr) then break; end -- nothing or something found | 48 if dn or not(attr) then break; end -- nothing or something found |
48 module:log("warn", "LDAP: %s %s (in %s)", tostring(dn), tostring(attr), where); | 49 module:log("warn", "LDAP: %s %s (in %s)", tostring(dn), tostring(attr), where); |
49 -- otherwise retry | 50 -- otherwise retry |
50 end | 51 end |
67 }); | 68 }); |
68 end | 69 end |
69 | 70 |
70 local provider = {}; | 71 local provider = {}; |
71 | 72 |
72 function provider.create_user(username, password) | 73 function provider.create_user(username, password) -- luacheck: ignore 212 |
73 return nil, "Account creation not available with LDAP."; | 74 return nil, "Account creation not available with LDAP."; |
74 end | 75 end |
75 | 76 |
76 function provider.user_exists(username) | 77 function provider.user_exists(username) |
77 return not not get_user(username); | 78 return not not get_user(username); |
96 return provider.get_password(username) == password; | 97 return provider.get_password(username) == password; |
97 end | 98 end |
98 | 99 |
99 function provider.get_sasl_handler() | 100 function provider.get_sasl_handler() |
100 return new_sasl(module.host, { | 101 return new_sasl(module.host, { |
101 plain = function(sasl, username) | 102 plain = function(sasl, username) -- luacheck: ignore 212/sasl |
102 local password = provider.get_password(username); | 103 local password = provider.get_password(username); |
103 if not password then return "", nil; end | 104 if not password then return "", nil; end |
104 return password, true; | 105 return password, true; |
105 end | 106 end |
106 }); | 107 }); |
116 return test_password(dn, password) | 117 return test_password(dn, password) |
117 end | 118 end |
118 | 119 |
119 function provider.get_sasl_handler() | 120 function provider.get_sasl_handler() |
120 return new_sasl(module.host, { | 121 return new_sasl(module.host, { |
121 plain_test = function(sasl, username, password) | 122 plain_test = function(sasl, username, password) -- luacheck: ignore 212/sasl |
122 return provider.test_password(username, password), true; | 123 return provider.test_password(username, password), true; |
123 end | 124 end |
124 }); | 125 }); |
125 end | 126 end |
126 else | 127 else |