Comparison

plugins/mod_register.lua @ 7709:0af1783d1592

mod_register: Additional logging for various registration failure cases
author Kim Alvefur <zash@zash.se>
date Wed, 02 Nov 2016 13:08:12 +0100
parent 7570:c61ea328fac2
child 7710:08f5b483ff00
comparison
equal deleted inserted replaced
7708:c420a38db5ef 7709:0af1783d1592
202 module:hook("stanza/iq/jabber:iq:register:query", function(event) 202 module:hook("stanza/iq/jabber:iq:register:query", function(event)
203 local session, stanza = event.origin, event.stanza; 203 local session, stanza = event.origin, event.stanza;
204 local log = session.log or module._log; 204 local log = session.log or module._log;
205 205
206 if not(allow_registration) or session.type ~= "c2s_unauthed" then 206 if not(allow_registration) or session.type ~= "c2s_unauthed" then
207 log("debug", "Attempted registration when disabled or already authenticated");
207 session.send(st.error_reply(stanza, "cancel", "service-unavailable")); 208 session.send(st.error_reply(stanza, "cancel", "service-unavailable"));
208 else 209 else
209 local query = stanza.tags[1]; 210 local query = stanza.tags[1];
210 if stanza.attr.type == "get" then 211 if stanza.attr.type == "get" then
211 local reply = st.reply(stanza); 212 local reply = st.reply(stanza);
215 if query.tags[1] and query.tags[1].name == "remove" then 216 if query.tags[1] and query.tags[1].name == "remove" then
216 session.send(st.error_reply(stanza, "auth", "registration-required")); 217 session.send(st.error_reply(stanza, "auth", "registration-required"));
217 else 218 else
218 local data, errors = parse_response(query); 219 local data, errors = parse_response(query);
219 if errors then 220 if errors then
221 log("debug", "Error parsing registration form:");
222 for field, err in pairs(errors) do
223 log("debug", "Field %q: %s", field, err);
224 end
220 session.send(st.error_reply(stanza, "modify", "not-acceptable")); 225 session.send(st.error_reply(stanza, "modify", "not-acceptable"));
221 else 226 else
222 -- Check that the user is not blacklisted or registering too often 227 -- Check that the user is not blacklisted or registering too often
223 if not session.ip then 228 if not session.ip then
224 log("debug", "User's IP not known; can't apply blacklist/whitelist"); 229 log("debug", "User's IP not known; can't apply blacklist/whitelist");
225 elseif blacklisted_ips[session.ip] or (whitelist_only and not whitelisted_ips[session.ip]) then 230 elseif blacklisted_ips[session.ip] or (whitelist_only and not whitelisted_ips[session.ip]) then
226 session.send(st.error_reply(stanza, "cancel", "not-acceptable", "You are not allowed to register an account.")); 231 session.send(st.error_reply(stanza, "cancel", "not-acceptable", "You are not allowed to register an account."));
227 return true; 232 return true;
228 elseif min_seconds_between_registrations and not whitelisted_ips[session.ip] then 233 elseif min_seconds_between_registrations and not whitelisted_ips[session.ip] then
229 if not check_throttle(session.ip) then 234 if not check_throttle(session.ip) then
235 log("debug", "Registrations over limit for ip %s", session.ip or "?");
230 session.send(st.error_reply(stanza, "wait", "not-acceptable")); 236 session.send(st.error_reply(stanza, "wait", "not-acceptable"));
231 return true; 237 return true;
232 end 238 end
233 end 239 end
234 local username, password = nodeprep(data.username), data.password; 240 local username, password = nodeprep(data.username), data.password;
235 data.username, data.password = nil, nil; 241 data.username, data.password = nil, nil;
236 local host = module.host; 242 local host = module.host;
237 if not username or username == "" then 243 if not username or username == "" then
244 log("debug", "The requested username is invalid.");
238 session.send(st.error_reply(stanza, "modify", "not-acceptable", "The requested username is invalid.")); 245 session.send(st.error_reply(stanza, "modify", "not-acceptable", "The requested username is invalid."));
239 return true; 246 return true;
240 end 247 end
241 local user = { username = username , host = host, allowed = true } 248 local user = { username = username , host = host, allowed = true }
242 module:fire_event("user-registering", user); 249 module:fire_event("user-registering", user);
243 if not user.allowed then 250 if not user.allowed then
251 log("debug", "Registration disallowed by module");
244 session.send(st.error_reply(stanza, "modify", "not-acceptable", "The requested username is forbidden.")); 252 session.send(st.error_reply(stanza, "modify", "not-acceptable", "The requested username is forbidden."));
245 elseif usermanager_user_exists(username, host) then 253 elseif usermanager_user_exists(username, host) then
254 log("debug", "Attempt to register with existing username");
246 session.send(st.error_reply(stanza, "cancel", "conflict", "The requested username already exists.")); 255 session.send(st.error_reply(stanza, "cancel", "conflict", "The requested username already exists."));
247 else 256 else
248 -- TODO unable to write file, file may be locked, etc, what's the correct error? 257 -- TODO unable to write file, file may be locked, etc, what's the correct error?
249 local error_reply = st.error_reply(stanza, "wait", "internal-server-error", "Failed to write data to disk."); 258 local error_reply = st.error_reply(stanza, "wait", "internal-server-error", "Failed to write data to disk.");
250 if usermanager_create_user(username, password, host) then 259 if usermanager_create_user(username, password, host) then
251 if next(data) and not account_details:set(username, data) then 260 if next(data) and not account_details:set(username, data) then
261 log("debug", "Could not store extra details");
252 usermanager_delete_user(username, host); 262 usermanager_delete_user(username, host);
253 session.send(error_reply); 263 session.send(error_reply);
254 return true; 264 return true;
255 end 265 end
256 session.send(st.reply(stanza)); -- user created! 266 session.send(st.reply(stanza)); -- user created!
257 log("info", "User account created: %s@%s", username, host); 267 log("info", "User account created: %s@%s", username, host);
258 module:fire_event("user-registered", { 268 module:fire_event("user-registered", {
259 username = username, host = host, source = "mod_register", 269 username = username, host = host, source = "mod_register",
260 session = session }); 270 session = session });
261 else 271 else
272 log("debug", "Could not create user");
262 session.send(error_reply); 273 session.send(error_reply);
263 end 274 end
264 end 275 end
265 end 276 end
266 end 277 end