Skip to content

Commit

Permalink
mod_tombstones: New module to keep deleted users and rooms tombstones
Browse files Browse the repository at this point in the history
ejabberd_auth: New check_register_user hook to allow blocking account
registration when a tombstone exists.

mod_muc_room: The room_destroyed hook must provide room persistent option,
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.erl: This could be committed to ejabberd-contrib instead of
upstream ejabberd git repository.

Example configuration:

modules:
  mod_tombstones:
    room_tombstone_expiry: 30 days
    user_tombstone_expiry: 365 days
  • Loading branch information
badlop committed Oct 17, 2024
1 parent 50ef49d commit b6401c6
Show file tree
Hide file tree
Showing 5 changed files with 400 additions and 8 deletions.
2 changes: 1 addition & 1 deletion include/mod_muc_room.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
5 changes: 5 additions & 0 deletions src/ejabberd_auth.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -307,6 +309,9 @@ try_register(User, Server, Password) ->
{error, _} = Err ->
Err
end;
false ->
{error, not_allowed}
end;
false ->
{error, not_allowed}
end
Expand Down
6 changes: 4 additions & 2 deletions src/ejabberd_web_admin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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, []),
Expand Down Expand Up @@ -1791,6 +1791,8 @@ make_command2(Name,
case {ForceExecution, ResultFormatApi} of
{true, _} ->
auto;
{false, _} ->
manual;
{_, {_, rescode}} ->
manual;
{_, {_, restuple}} ->
Expand Down
12 changes: 7 additions & 5 deletions src/mod_muc_room.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
_ ->
Expand Down Expand Up @@ -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)]),
Expand Down Expand Up @@ -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} ->
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit b6401c6

Please sign in to comment.