mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Fix anonymous user cleanup (EJAB-883)
anonymous users table and vcards were not correctly cleaned up after the user disconnect.
This commit is contained in:
parent
f4507a088a
commit
f4f949bd72
@ -149,6 +149,8 @@ allow_multiple_connections(Host) when is_list(Host) ->
|
|||||||
%% @doc Check if user exist in the anonymous database.
|
%% @doc Check if user exist in the anonymous database.
|
||||||
|
|
||||||
anonymous_user_exist(User, Server) when is_list(User), is_list(Server) ->
|
anonymous_user_exist(User, Server) when is_list(User), is_list(Server) ->
|
||||||
|
anonymous_user_exist(list_to_binary(User), list_to_binary(Server));
|
||||||
|
anonymous_user_exist(User, Server) when is_binary(User), is_binary(Server) ->
|
||||||
LUser = exmpp_stringprep:nodeprep(User),
|
LUser = exmpp_stringprep:nodeprep(User),
|
||||||
LServer = exmpp_stringprep:nameprep(Server),
|
LServer = exmpp_stringprep:nameprep(Server),
|
||||||
US = {LUser, LServer},
|
US = {LUser, LServer},
|
||||||
@ -165,7 +167,7 @@ anonymous_user_exist(User, Server) when is_list(User), is_list(Server) ->
|
|||||||
%% LServer = string()
|
%% LServer = string()
|
||||||
%% @doc Remove connection from Mnesia tables.
|
%% @doc Remove connection from Mnesia tables.
|
||||||
|
|
||||||
remove_connection(SID, LUser, LServer) when is_list(LUser), is_list(LServer) ->
|
remove_connection(SID, LUser, LServer) when is_binary(LUser), is_binary(LServer) ->
|
||||||
US = {LUser, LServer},
|
US = {LUser, LServer},
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
mnesia:delete_object({anonymous, US, SID})
|
mnesia:delete_object({anonymous, US, SID})
|
||||||
@ -201,8 +203,8 @@ register_connection(SID, JID, Info) when ?IS_JID(JID) ->
|
|||||||
%% @doc Remove an anonymous user from the anonymous users table.
|
%% @doc Remove an anonymous user from the anonymous users table.
|
||||||
|
|
||||||
unregister_connection(SID, JID, _) when ?IS_JID(JID) ->
|
unregister_connection(SID, JID, _) when ?IS_JID(JID) ->
|
||||||
LUser = exmpp_jid:prep_node_as_list(JID),
|
LUser = exmpp_jid:prep_node(JID),
|
||||||
LServer = exmpp_jid:prep_domain_as_list(JID),
|
LServer = exmpp_jid:prep_domain(JID),
|
||||||
purge_hook(anonymous_user_exist(LUser, LServer),
|
purge_hook(anonymous_user_exist(LUser, LServer),
|
||||||
LUser, LServer),
|
LUser, LServer),
|
||||||
remove_connection(SID, LUser, LServer).
|
remove_connection(SID, LUser, LServer).
|
||||||
@ -214,8 +216,8 @@ unregister_connection(SID, JID, _) when ?IS_JID(JID) ->
|
|||||||
|
|
||||||
purge_hook(false, _LUser, _LServer) ->
|
purge_hook(false, _LUser, _LServer) ->
|
||||||
ok;
|
ok;
|
||||||
purge_hook(true, LUser, LServer) when is_list(LUser), is_list(LServer) ->
|
purge_hook(true, LUser, LServer) when is_binary(LUser), is_binary(LServer) ->
|
||||||
ejabberd_hooks:run(anonymous_purge_hook, list_to_binary(LServer), [LUser, LServer]).
|
ejabberd_hooks:run(anonymous_purge_hook, LServer, [LUser, LServer]).
|
||||||
|
|
||||||
%% ---------------------------------
|
%% ---------------------------------
|
||||||
%% Specific anonymous auth functions
|
%% Specific anonymous auth functions
|
||||||
|
@ -121,6 +121,8 @@ start(Host, Opts) ->
|
|||||||
|
|
||||||
ejabberd_hooks:add(remove_user, HostB,
|
ejabberd_hooks:add(remove_user, HostB,
|
||||||
?MODULE, remove_user, 50),
|
?MODULE, remove_user, 50),
|
||||||
|
ejabberd_hooks:add(anonymous_purge_hook, HostB,
|
||||||
|
?MODULE, remove_user, 50),
|
||||||
ejabberd_hooks:add(webadmin_page_host, HostB,
|
ejabberd_hooks:add(webadmin_page_host, HostB,
|
||||||
?MODULE, webadmin_page, 50),
|
?MODULE, webadmin_page, 50),
|
||||||
ejabberd_hooks:add(webadmin_user, HostB,
|
ejabberd_hooks:add(webadmin_user, HostB,
|
||||||
@ -169,6 +171,8 @@ stop(Host) ->
|
|||||||
HostB = list_to_binary(Host),
|
HostB = list_to_binary(Host),
|
||||||
ejabberd_hooks:delete(remove_user, HostB,
|
ejabberd_hooks:delete(remove_user, HostB,
|
||||||
?MODULE, remove_user, 50),
|
?MODULE, remove_user, 50),
|
||||||
|
ejabberd_hooks:delete(anonymous_purge_hook, HostB,
|
||||||
|
?MODULE, remove_user, 50),
|
||||||
ejabberd_hooks:delete(webadmin_page_host, HostB,
|
ejabberd_hooks:delete(webadmin_page_host, HostB,
|
||||||
?MODULE, webadmin_page, 50),
|
?MODULE, webadmin_page, 50),
|
||||||
ejabberd_hooks:delete(webadmin_user, HostB,
|
ejabberd_hooks:delete(webadmin_user, HostB,
|
||||||
|
Loading…
Reference in New Issue
Block a user