Comparison

mod_log_auth/mod_log_auth.lua @ 2702:caabb980d1d8

Merge commit
author tmolitor <thilo@eightysoft.de>
date Mon, 24 Apr 2017 20:57:23 +0200
parent 2699:dae655657a92
child 3941:6d1ec8099315
comparison
equal deleted inserted replaced
2701:d96831e46b64 2702:caabb980d1d8
1 local mode = module:get_option_string("log_auth_ips", "failure"); 1 local mode = module:get_option_string("log_auth_ips", "failure");
2 assert(({ all = true, failure = true, success = true })[mode], "Unknown log mode: "..tostring(mode).." - valid modes are 'all', 'failure', 'success'"); 2 assert(({ all = true, failure = true, success = true })[mode],
3 "Unknown log mode: "..tostring(mode).." - valid modes are 'all', 'failure', 'success'");
3 4
4 if mode == "failure" or mode == "all" then 5 if mode == "failure" or mode == "all" then
5 module:hook("authentication-failure", function (event) 6 module:hook("authentication-failure", function (event)
6 module:log("info", "Failed authentication attempt (%s) for user %s from IP: %s", event.condition or "unknown-condition", event.session.username or "?", event.session.ip or "?"); 7 local session = event.session;
8 local username = session.username or session.sasl_handler and session.sasl_handler.username or "?";
9 session.log("info", "Failed authentication attempt (%s) for user %s from IP: %s",
10 event.condition or "unknown-condition", username, session.ip or "?");
7 end); 11 end);
8 end 12 end
9 13
10 if mode == "success" or mode == "all" then 14 if mode == "success" or mode == "all" then
11 module:hook("authentication-success", function (event) 15 module:hook("authentication-success", function (event)
12 local session = event.session; 16 local session = event.session;
13 module:log("info", "Successful authentication as %s from IP: %s", session.username, session.ip or "?"); 17 session.log("info", "Successful authentication as %s from IP: %s", session.username, session.ip or "?");
14 end); 18 end);
15 end 19 end