aboutsummaryrefslogtreecommitdiff
path: root/src/ejabberd_auth_anonymous.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/ejabberd_auth_anonymous.erl')
-rw-r--r--src/ejabberd_auth_anonymous.erl71
1 files changed, 18 insertions, 53 deletions
diff --git a/src/ejabberd_auth_anonymous.erl b/src/ejabberd_auth_anonymous.erl
index e0c4d471f..d8947033a 100644
--- a/src/ejabberd_auth_anonymous.erl
+++ b/src/ejabberd_auth_anonymous.erl
@@ -52,17 +52,7 @@
-include("logger.hrl").
-include("jid.hrl").
-%% Create the anonymous table if at least one virtual host has anonymous features enabled
-%% Register to login / logout events
--record(anonymous, {us = {<<"">>, <<"">>} :: {binary(), binary()},
- sid = ejabberd_sm:make_sid() :: ejabberd_sm:sid()}).
-
start(Host) ->
- %% TODO: Check cluster mode
- ejabberd_mnesia:create(?MODULE, anonymous, [{ram_copies, [node()]},
- {type, bag},
- {attributes, record_info(fields, anonymous)}]),
- %% The hooks are needed to add / remove users from the anonymous tables
ejabberd_hooks:add(sm_register_connection_hook, Host,
?MODULE, register_connection, 100),
ejabberd_hooks:add(sm_remove_connection_hook, Host,
@@ -119,56 +109,33 @@ allow_multiple_connections(Host) ->
fun(V) when is_boolean(V) -> V end,
false).
-%% Check if user exist in the anonymus database
anonymous_user_exist(User, Server) ->
- LUser = jid:nodeprep(User),
- LServer = jid:nameprep(Server),
- US = {LUser, LServer},
- case catch mnesia:dirty_read({anonymous, US}) of
- [] ->
- false;
- [_H|_T] ->
- true
- end.
-
-%% Remove connection from Mnesia tables
-remove_connection(SID, LUser, LServer) ->
- US = {LUser, LServer},
- F = fun () -> mnesia:delete_object({anonymous, US, SID})
- end,
- mnesia:transaction(F).
+ lists:any(
+ fun({_LResource, Info}) ->
+ proplists:get_value(auth_module, Info) == ?MODULE
+ end, ejabberd_sm:get_user_info(User, Server)).
%% Register connection
-spec register_connection(ejabberd_sm:sid(), jid(), ejabberd_sm:info()) -> ok.
-register_connection(SID,
+register_connection(_SID,
#jid{luser = LUser, lserver = LServer}, Info) ->
- AuthModule = proplists:get_value(auth_module, Info, undefined),
- case AuthModule == (?MODULE) of
- true ->
- ejabberd_hooks:run(register_user, LServer,
- [LUser, LServer]),
- US = {LUser, LServer},
- mnesia:sync_dirty(fun () ->
- mnesia:write(#anonymous{us = US,
- sid = SID})
- end);
- false -> ok
+ case proplists:get_value(auth_module, Info) of
+ ?MODULE ->
+ ejabberd_hooks:run(register_user, LServer, [LUser, LServer]);
+ false ->
+ ok
end.
%% Remove an anonymous user from the anonymous users table
-spec unregister_connection(ejabberd_sm:sid(), jid(), ejabberd_sm:info()) -> any().
-unregister_connection(SID,
- #jid{luser = LUser, lserver = LServer}, _) ->
- purge_hook(anonymous_user_exist(LUser, LServer), LUser,
- LServer),
- remove_connection(SID, LUser, LServer).
-
-%% Launch the hook to purge user data only for anonymous users
-purge_hook(false, _LUser, _LServer) ->
- ok;
-purge_hook(true, LUser, LServer) ->
- ejabberd_hooks:run(anonymous_purge_hook, LServer,
- [LUser, LServer]).
+unregister_connection(_SID,
+ #jid{luser = LUser, lserver = LServer}, Info) ->
+ case proplists:get_value(auth_module, Info) of
+ ?MODULE ->
+ ejabberd_hooks:run(remove_user, LServer, [LUser, LServer]);
+ _ ->
+ ok
+ end.
%% ---------------------------------
%% Specific anonymous auth functions
@@ -258,8 +225,6 @@ get_password_s(User, Server) ->
Password
end.
-%% Returns true if the user exists in the DB or if an anonymous user is logged
-%% under the given name
is_user_exists(User, Server) ->
anonymous_user_exist(User, Server).