From 71ad7c368d51b46453234b840531ce3c256efca3 Mon Sep 17 00:00:00 2001 From: Badlop Date: Mon, 14 Oct 2024 13:34:42 +0200 Subject: [PATCH] Minor improvements to support mod_tombstones New check_register_user hook in ejabberd_auth.erl to allow blocking account registration when a tombstone exists. Modified room_destroyed hook in mod_muc_room.erl Until now the hook passed as arguments: LServer, Room, Host. Now it passes: LServer, Room, Host, Persistent That new Persistent argument passes the room persistent option, required by mod_tombstones because only persistent rooms should generate a tombstone, temporary ones should not. And the persistent option should not be completely overwritten, as we must still known its real value even when room is being destroyed. mod_tombstones is available in experimental mode in ejabberd-contrib git. Initial feature request: #2546 --- include/mod_muc_room.hrl | 2 +- src/ejabberd_auth.erl | 5 +++++ src/ejabberd_web_admin.erl | 6 ++++-- src/mod_muc_room.erl | 12 +++++++----- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/include/mod_muc_room.hrl b/include/mod_muc_room.hrl index a278e3ae3..1d0ca4442 100644 --- a/include/mod_muc_room.hrl +++ b/include/mod_muc_room.hrl @@ -44,7 +44,7 @@ allow_visitor_nickchange = true :: boolean(), public = true :: boolean(), public_list = true :: boolean(), - persistent = false :: boolean(), + persistent = false :: boolean() | {destroying, boolean()}, moderated = true :: boolean(), captcha_protected = false :: boolean(), members_by_default = true :: boolean(), diff --git a/src/ejabberd_auth.erl b/src/ejabberd_auth.erl index c37d4c187..3f2b65b3e 100644 --- a/src/ejabberd_auth.erl +++ b/src/ejabberd_auth.erl @@ -293,6 +293,8 @@ try_register(User, Server, Password) -> false -> case ejabberd_router:is_my_host(LServer) of true -> + case ejabberd_hooks:run_fold(check_register_user, LServer, true, [User, Server, Password]) of + true -> case lists:foldl( fun(_, ok) -> ok; @@ -307,6 +309,9 @@ try_register(User, Server, Password) -> {error, _} = Err -> Err end; + false -> + {error, not_allowed} + end; false -> {error, not_allowed} end diff --git a/src/ejabberd_web_admin.erl b/src/ejabberd_web_admin.erl index 9dce1ff70..35441b700 100644 --- a/src/ejabberd_web_admin.erl +++ b/src/ejabberd_web_admin.erl @@ -1726,7 +1726,7 @@ make_command_raw_value(Name, Request, BaseArguments) -> raw_value | raw_and_value} | {input_name_append, [binary()]} | - {force_execution, boolean()} | + {force_execution, boolean() | undefined} | {table_options, {PageSize :: integer(), RemainingPath :: [binary()]}} | {result_named, boolean()} | {result_links, @@ -1737,7 +1737,7 @@ make_command_raw_value(Name, Request, BaseArguments) -> {style, normal | danger}. make_command2(Name, Request, BaseArguments, Options) -> Only = proplists:get_value(only, Options, all), - ForceExecution = proplists:get_value(force_execution, Options, false), + ForceExecution = proplists:get_value(force_execution, Options, undefined), InputNameAppend = proplists:get_value(input_name_append, Options, []), Resultnamed = proplists:get_value(result_named, Options, false), ResultLinks = proplists:get_value(result_links, Options, []), @@ -1791,6 +1791,8 @@ make_command2(Name, case {ForceExecution, ResultFormatApi} of {true, _} -> auto; + {false, _} -> + manual; {_, {_, rescode}} -> manual; {_, {_, restuple}} -> diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl index 73b7a7386..da2f70b78 100644 --- a/src/mod_muc_room.erl +++ b/src/mod_muc_room.erl @@ -540,7 +540,7 @@ normal_state({route, <<"">>, case NewStateData of stop -> Conf = StateData#state.config, - {stop, normal, StateData#state{config = Conf#config{persistent = false}}}; + {stop, normal, StateData#state{config = Conf#config{persistent = {destroying, Conf#config.persistent}}}}; _ when NewStateData#state.just_created -> close_room_if_temporary_and_empty(NewStateData); _ -> @@ -736,7 +736,7 @@ handle_event({destroy, Reason}, _StateName, [jid:encode(StateData#state.jid), Reason]), add_to_log(room_existence, destroyed, StateData), Conf = StateData#state.config, - {stop, shutdown, StateData#state{config = Conf#config{persistent = false}}}; + {stop, shutdown, StateData#state{config = Conf#config{persistent = {destroying, Conf#config.persistent}}}}; handle_event(destroy, StateName, StateData) -> ?INFO_MSG("Destroyed MUC room ~ts", [jid:encode(StateData#state.jid)]), @@ -856,7 +856,7 @@ handle_sync_event({muc_unsubscribe, From}, _From, StateName, from = From, sub_els = [#muc_unsubscribe{}]}, case process_iq_mucsub(From, IQ, StateData) of {result, _, stop} -> - {stop, normal, StateData#state{config = Conf#config{persistent = false}}}; + {stop, normal, StateData#state{config = Conf#config{persistent = {destroying, Conf#config.persistent}}}}; {result, _, NewState} -> {reply, ok, StateName, NewState}; {ignore, NewState} -> @@ -1015,8 +1015,10 @@ terminate(Reason, _StateName, _ -> add_to_log(room_existence, stopped, StateData), case (StateData#state.config)#config.persistent of - false -> - ejabberd_hooks:run(room_destroyed, LServer, [LServer, Room, Host]); + false -> + ejabberd_hooks:run(room_destroyed, LServer, [LServer, Room, Host, false]); + {destroying, Persistent} -> + ejabberd_hooks:run(room_destroyed, LServer, [LServer, Room, Host, Persistent]); _ -> ok end