25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-26 16:26:24 +01:00

When a vhost is removed, remove also its accounts and rooms (EJAB-1371)

This commit is contained in:
Badlop 2011-10-20 11:13:23 +02:00
parent e681f4d4cf
commit c7c59766b2
3 changed files with 38 additions and 36 deletions

View File

@ -49,16 +49,16 @@
is_user_exists_in_other_modules/3,
remove_user/2,
remove_user/3,
remove_host/1,
plain_password_required/1,
store_type/1,
entropy/1
]).
-export([start/1
,stop/1
,start_modules/2
,stop_modules/2
,start_methods/2
,stop_methods/2
]).
-export([auth_modules/1]).
@ -80,8 +80,20 @@ start() ->
lists:foreach(fun start/1, ?MYHOSTS).
start(Host) ->
ejabberd_hooks:add(remove_host, list_to_binary(Host), ?MODULE, remove_host, 150),
start_modules(Host, auth_modules(Host)).
stop(Host) ->
ejabberd_hooks:delete(remove_host, list_to_binary(Host), ?MODULE, remove_host, 150),
stop_modules(Host, auth_modules(Host)).
remove_host(HostB) when is_binary(HostB) ->
lists:foreach(
fun({Username, Host}) ->
ejabberd_auth:remove_user(Username, Host)
end,
ejabberd_auth:get_vh_registered_users(binary_to_list(HostB))).
start_modules(Host, Modules) when is_list(Modules) ->
lists:foreach(fun (M) -> start_modules(Host, M) end, Modules);
start_modules(Host, Module) when is_atom(Module) ->
@ -92,17 +104,6 @@ stop_modules(Host, Modules) when is_list(Modules) ->
stop_modules(Host, Module) when is_atom(Module) ->
Module:stop(Host).
start_methods(Host, Methods) when is_list(Methods) ->
lists:foreach(fun (M) -> start_methods(Host, M) end, Methods);
start_methods(Host, Method) when is_atom(Method) ->
start_modules(Host, module_name(Method)).
stop_methods(Host, Methods) when is_list(Methods) ->
lists:foreach(fun (M) -> stop_methods(Host, M) end, Methods);
stop_methods(Host, Method) when is_atom(Method) ->
stop_modules(Host, module_name(Method)).
%% @spec (Server) -> bool()
%% Server = string()
@ -517,9 +518,8 @@ auth_modules() ->
%% Server = string()
%% @doc Return the list of authenticated modules for a given host.
auth_modules(Server) when is_list(Server) ->
LServer = exmpp_stringprep:nameprep(Server),
Method = ejabberd_config:get_local_option({auth_method, ejabberd:normalize_host(LServer)}),
auth_modules(Server) ->
Method = ejabberd_config:get_local_option({auth_method, Server}),
Methods = if
Method == undefined -> [];
is_list(Method) -> Method;

View File

@ -101,13 +101,18 @@ update_host_conf(Host, Config) when is_list(Host), is_list(Config) ->
case registered(Host) of
false -> {error, host_process_not_registered};
true ->
remove(Host),
remove_host_info(Host),
?MODULE:register(Host, Config)
end.
%% Removes a vhost from the system,
%% XXX deleting all ODBC data.
remove(Host) when is_list(Host) ->
HostB = list_to_binary(Host),
ejabberd_hooks:run(remove_host, HostB, [HostB]),
remove_host_info(Host).
remove_host_info(Host) ->
true = exmpp_stringprep:is_node(Host),
ID = get_clusterid(),
gen_storage:dirty_delete_where(
@ -346,10 +351,7 @@ start_host(Host) when is_list(Host) ->
gen_mod:start_module(Host, Module, Args)
end, Modules)
end,
case auth_method(Host) of
{host_method, HostMethod} ->
ejabberd_auth:start_methods(Host, HostMethod)
end,
ejabberd_auth:start(Host),
ok.
@ -366,10 +368,7 @@ stop_host(Host) when is_list(Host) ->
lists:foreach(fun(Module) ->
gen_mod:stop_module_keep_config(Host, Module)
end, gen_mod:loaded_modules(Host)),
case auth_method(Host) of
{host_method, Method} ->
ejabberd_auth:stop_methods(Host, Method)
end.
ejabberd_auth:stop(Host).
%% Get the current vhost list from a variety of sources (ODBC, internal)
get_hosts(ejabberd) -> ?MYHOSTS;
@ -417,16 +416,6 @@ diff_hosts(NewHosts, OldHosts) ->
AddHosts = NewHosts -- OldHosts,
{AddHosts,RemoveHosts}.
%% XXX - this should be part of auth, not hosts.
auth_method(Host) ->
case ejabberd_config:get_host_option(Host, auth_method) of
undefined ->
[Default] = ejabberd_config:get_host_option(global, auth_method),
{host_method, Default};
Other ->
{host_method, Other}
end.
configure_static_hosts() ->
?DEBUG("Node startup - configuring hosts: ~p", [?MYHOSTS]),
%% Add a null configuration for all MYHOSTS - this ensures

View File

@ -91,6 +91,7 @@
register_room/3,
migrate/1,
get_vh_rooms/1,
remove_host/1,
can_use_nick/3]).
%% gen_server callbacks
@ -298,6 +299,16 @@ migrate(After) ->
end
end, Rs).
remove_host(MyHostB) when is_binary(MyHostB) ->
Host = gen_mod:get_module_opt_host(binary_to_list(MyHostB), ?MODULE, "conference.@HOST@"),
?INFO_MSG("Removing rooms of MUC service ~p", [Host]),
lists:foreach(
fun(#muc_online_room{name_host = {NameB, HostB}, pid = Pid}) ->
gen_fsm:send_all_state_event(Pid, destroy),
forget_room(HostB, NameB)
end,
get_vh_rooms(list_to_binary(Host))).
%%====================================================================
%% gen_server callbacks
%%====================================================================
@ -355,6 +366,7 @@ init([Host, Opts]) ->
RoomShaper = gen_mod:get_opt(room_shaper, Opts, none),
ejabberd_router:register_route(MyHostStr),
ejabberd_hooks:add(node_hash_update, ?MODULE, migrate, 100),
ejabberd_hooks:add(remove_host, Host, ?MODULE, remove_host, 50),
load_permanent_rooms(MyHost, Host,
{Access, AccessCreate, AccessAdmin, AccessPersistent},
HistorySize,
@ -456,6 +468,7 @@ handle_info(_Info, State) ->
%%--------------------------------------------------------------------
terminate(_Reason, State) ->
ejabberd_hooks:delete(node_hash_update, ?MODULE, migrate, 100),
ejabberd_hooks:delete(remove_host, State#state.server_host, ?MODULE, remove_host, 50),
ejabberd_router:unregister_route(binary_to_list(State#state.host)),
ok.