From 198f14a7c021e7f2a0009e0ab38a02868678d199 Mon Sep 17 00:00:00 2001 From: Badlop Date: Mon, 23 Jun 2014 13:54:40 +0200 Subject: [PATCH] Update mod_logsession to work with ejabberd master branch #41 --- mod_logsession/README.txt | 12 ++-- mod_logsession/src/failed_auth.patch | 99 ++++++++++++++++----------- mod_logsession/src/mod_logsession.erl | 3 +- 3 files changed, 67 insertions(+), 47 deletions(-) diff --git a/mod_logsession/README.txt b/mod_logsession/README.txt index 750456b..033fdf0 100644 --- a/mod_logsession/README.txt +++ b/mod_logsession/README.txt @@ -3,7 +3,7 @@ Homepage: http://www.ejabberd.im/mod_logsession Author: Badlop - Requirements: ejabberd trunk SVN 1635 or newer + Requirements: ejabberd 14.05 or newer DESCRIPTION @@ -23,7 +23,7 @@ Note: to log the failed authentication attempts, you need to patch ejabberd. 1 Copy this file to ejabberd/src/mod_logsession.erl 2 Recompile ejabberd 3 Add to ejabberd.cfg, 'modules' section the basic configuration: - {mod_logsession, []}, + mod_logsession: {} 4 With this configuration, the log files are: /tmp/ejabberd_logsession_@HOST@.log @@ -40,13 +40,11 @@ sessionlog: EXAMPLE CONFIGURATION --------------------- -{modules, [ +modules: ... - {mod_logsession, [ - {sessionlog, "/var/log/ejabberd/session_@HOST@.log"} - ]}, + mod_logsession: + sessionlog: "/var/log/ejabberd/session_@HOST@.log" ... -]}. With that configuration, if the server has three vhosts: "localhost", "example.org" and "example.net", diff --git a/mod_logsession/src/failed_auth.patch b/mod_logsession/src/failed_auth.patch index 0699cd7..075762d 100644 --- a/mod_logsession/src/failed_auth.patch +++ b/mod_logsession/src/failed_auth.patch @@ -1,44 +1,65 @@ ---- ejabberd_c2s.erl -+++ ejabberd_c2s.erl -@@ -496,6 +496,11 @@ wait_for_auth({xmlstreamelement, El}, StateData) -> - fsm_next_state_pack(session_established, - NewStateData); - _ -> -+ ejabberd_hooks:run(failed_auth_hook, -+ StateData#state.server, -+ [legacy, U, -+ StateData#state.server, -+ StateData#state.ip]), - ?INFO_MSG( - "(~w) Failed legacy authentication for ~s", - [StateData#state.socket, -@@ -586,6 +591,11 @@ wait_for_feature_request({xmlstreamelement, El}, StateData) -> - StateData#state{ - sasl_state = NewSASLState}); - {error, Error, Username} -> -+ ejabberd_hooks:run(failed_auth_hook, +From 86a811a92b27afe43adcc3ab3692df13949c4221 Mon Sep 17 00:00:00 2001 +From: Badlop +Date: Mon, 23 Jun 2014 13:47:10 +0200 +Subject: [PATCH] Patch for mod_logsession + +--- + src/ejabberd_c2s.erl | 21 +++++++++++++++++++++ + 1 file changed, 21 insertions(+) + +diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl +index 9ce66d0..d59ec58 100644 +--- a/src/ejabberd_c2s.erl ++++ b/src/ejabberd_c2s.erl +@@ -659,6 +659,11 @@ wait_for_auth({xmlstreamelement, El}, StateData) -> + privacy_list = PrivList}, + fsm_next_state(session_established, NewStateData); + _ -> ++ ejabberd_hooks:run(failed_auth_hook, + StateData#state.server, -+ [sasl_auth, Username, ++ [legacy, U, + StateData#state.server, + StateData#state.ip]), - ?INFO_MSG( - "(~w) Failed authentication for ~s@~s", + IP = peerip(StateData#state.sockmod, + StateData#state.socket), + ?INFO_MSG("(~w) Failed legacy authentication for " +@@ -753,6 +758,11 @@ wait_for_feature_request({xmlstreamelement, El}, + fsm_next_state(wait_for_sasl_response, + StateData#state{sasl_state = NewSASLState}); + {error, Error, Username} -> ++ ejabberd_hooks:run(failed_auth_hook, ++ StateData#state.server, ++ [sasl_auth, Username, ++ StateData#state.server, ++ StateData#state.ip]), + IP = peerip(StateData#state.sockmod, StateData#state.socket), + ?INFO_MSG("(~w) Failed authentication for ~s@~s from IP ~s", [StateData#state.socket, -@@ -721,10 +731,15 @@ wait_for_sasl_response({xmlstreamelement, El}, StateData) -> - fsm_next_state(wait_for_sasl_response, - StateData#state{sasl_state = NewSASLState}); - {error, Error, Username} -> -+ ejabberd_hooks:run(failed_auth_hook, -+ StateData#state.server, -+ [sasl_resp, Username, -+ StateData#state.server, -+ StateData#state.ip]), - ?INFO_MSG( -- "(~w) Failed authentication for ~s@~s", -+ "(~w) Failed authentication for ~s@~s ~n~p", +@@ -935,6 +945,11 @@ wait_for_sasl_response({xmlstreamelement, El}, + fsm_next_state(wait_for_sasl_response, + StateData#state{sasl_state = NewSASLState}); + {error, Error, Username} -> ++ ejabberd_hooks:run(failed_auth_hook, ++ StateData#state.server, ++ [sasl_resp, Username, ++ StateData#state.server, ++ StateData#state.ip]), + IP = peerip(StateData#state.sockmod, StateData#state.socket), + ?INFO_MSG("(~w) Failed authentication for ~s@~s from IP ~s", [StateData#state.socket, -- Username, StateData#state.server]), -+ Username, StateData#state.server, StateData]), - send_element(StateData, - {xmlelement, "failure", - [{"xmlns", ?NS_SASL}], +@@ -947,6 +962,12 @@ wait_for_sasl_response({xmlstreamelement, El}, + children = []}]}), + fsm_next_state(wait_for_feature_request, StateData); + {error, Error} -> ++ Username = element(5, element(9, StateData#state.sasl_state)), ++ ejabberd_hooks:run(failed_auth_hook, ++ StateData#state.server, ++ [sasl_resp, Username, ++ StateData#state.server, ++ StateData#state.ip]), + send_element(StateData, + #xmlel{name = <<"failure">>, + attrs = [{<<"xmlns">>, ?NS_SASL}], +-- +1.8.5.3 + diff --git a/mod_logsession/src/mod_logsession.erl b/mod_logsession/src/mod_logsession.erl index 97a9062..40b2c32 100644 --- a/mod_logsession/src/mod_logsession.erl +++ b/mod_logsession/src/mod_logsession.erl @@ -57,6 +57,7 @@ start(Host, Opts) -> Filename1 = gen_mod:get_opt( sessionlog, Opts, + fun(S) -> S end, "/tmp/ejabberd_logsession_@HOST@.log"), Filename = replace_host(Host, Filename1), File = open_file(Filename), @@ -115,7 +116,7 @@ get_process_name(Host) -> gen_mod:get_module_proc(Host, ?PROCNAME). replace_host(Host, Filename) -> - re:replace(Filename, "@HOST@", Host, [global, {return, list}]). + re:replace(Filename, "@HOST@", binary_to_list(Host), [global, {return, list}]). open_file(Filename) -> {ok, File} = file:open(Filename, [append]),