91 --proc = nil; |
91 --proc = nil; |
92 return nil, "internal-server-error"; |
92 return nil, "internal-server-error"; |
93 end |
93 end |
94 end |
94 end |
95 |
95 |
96 function new_external_provider(host) |
96 local host = module.host; |
97 local provider = {}; |
97 local provider = {}; |
98 |
98 |
99 function provider.test_password(username, password) |
99 function provider.test_password(username, password) |
100 return do_query("auth", username, password); |
100 return do_query("auth", username, password); |
101 end |
|
102 |
|
103 function provider.set_password(username, password) |
|
104 return do_query("setpass", username, password); |
|
105 end |
|
106 |
|
107 function provider.user_exists(username) |
|
108 return do_query("isuser", username); |
|
109 end |
|
110 |
|
111 function provider.create_user(username, password) return nil, "Account creation/modification not available."; end |
|
112 |
|
113 function provider.get_sasl_handler() |
|
114 local testpass_authentication_profile = { |
|
115 plain_test = function(sasl, username, password, realm) |
|
116 local prepped_username = nodeprep(username); |
|
117 if not prepped_username then |
|
118 log("debug", "NODEprep failed on username: %s", username); |
|
119 return "", nil; |
|
120 end |
|
121 return usermanager.test_password(prepped_username, realm, password), true; |
|
122 end, |
|
123 }; |
|
124 return new_sasl(module.host, testpass_authentication_profile); |
|
125 end |
|
126 |
|
127 function provider.is_admin(jid) |
|
128 local admins = config.get(host, "core", "admins"); |
|
129 if admins ~= config.get("*", "core", "admins") then |
|
130 if type(admins) == "table" then |
|
131 jid = jid_bare(jid); |
|
132 for _,admin in ipairs(admins) do |
|
133 if admin == jid then return true; end |
|
134 end |
|
135 elseif admins then |
|
136 log("error", "Option 'admins' for host '%s' is not a table", host); |
|
137 end |
|
138 end |
|
139 return usermanager.is_admin(jid); -- Test whether it's a global admin instead |
|
140 end |
|
141 |
|
142 return provider; |
|
143 end |
101 end |
144 |
102 |
145 module:provides("auth", new_external_provider(module.host)); |
103 function provider.set_password(username, password) |
|
104 return do_query("setpass", username, password); |
|
105 end |
|
106 |
|
107 function provider.user_exists(username) |
|
108 return do_query("isuser", username); |
|
109 end |
|
110 |
|
111 function provider.create_user(username, password) return nil, "Account creation/modification not available."; end |
|
112 |
|
113 function provider.get_sasl_handler() |
|
114 local testpass_authentication_profile = { |
|
115 plain_test = function(sasl, username, password, realm) |
|
116 local prepped_username = nodeprep(username); |
|
117 if not prepped_username then |
|
118 log("debug", "NODEprep failed on username: %s", username); |
|
119 return "", nil; |
|
120 end |
|
121 return usermanager.test_password(prepped_username, realm, password), true; |
|
122 end, |
|
123 }; |
|
124 return new_sasl(host, testpass_authentication_profile); |
|
125 end |
|
126 |
|
127 function provider.is_admin(jid) |
|
128 local admins = config.get(host, "core", "admins"); |
|
129 if admins ~= config.get("*", "core", "admins") then |
|
130 if type(admins) == "table" then |
|
131 jid = jid_bare(jid); |
|
132 for _,admin in ipairs(admins) do |
|
133 if admin == jid then return true; end |
|
134 end |
|
135 elseif admins then |
|
136 log("error", "Option 'admins' for host '%s' is not a table", host); |
|
137 end |
|
138 end |
|
139 return usermanager.is_admin(jid); -- Test whether it's a global admin instead |
|
140 end |
|
141 |
|
142 module:provides("auth", provider); |