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

Fix bugs introduced by previous commit

This commit is contained in:
Evgeny Khramtsov 2018-09-28 00:28:34 +03:00
parent 39fa1a810d
commit 984a00195a
3 changed files with 39 additions and 27 deletions

View File

@ -33,7 +33,7 @@
start_listeners/0, start_listener/3, stop_listeners/0, start_listeners/0, start_listener/3, stop_listeners/0,
stop_listener/2, add_listener/3, delete_listener/2, stop_listener/2, add_listener/3, delete_listener/2,
transform_options/1, validate_cfg/1, opt_type/1, transform_options/1, validate_cfg/1, opt_type/1,
config_reloaded/0]). config_reloaded/0, get_certfiles/0]).
%% Legacy API %% Legacy API
-export([parse_listener_portip/2]). -export([parse_listener_portip/2]).
@ -379,6 +379,16 @@ config_reloaded() ->
end end
end, New). end, New).
-spec get_certfiles() -> [binary()].
get_certfiles() ->
lists:filtermap(
fun({_, _, Opts}) ->
case proplists:get_value(certfile, Opts) of
undefined -> false;
Cert -> {true, Cert}
end
end, ets:tab2list(?MODULE)).
-spec report_socket_error(inet:posix(), endpoint(), module()) -> ok. -spec report_socket_error(inet:posix(), endpoint(), module()) -> ok.
report_socket_error(Reason, EndPoint, Module) -> report_socket_error(Reason, EndPoint, Module) ->
?ERROR_MSG("Failed to open socket at ~s for ~s: ~s", ?ERROR_MSG("Failed to open socket at ~s for ~s: ~s",

View File

@ -52,7 +52,13 @@ start_link() ->
-spec add_certfile(file:filename_all()) -> {ok, filename()} | {error, pkix:error_reason()}. -spec add_certfile(file:filename_all()) -> {ok, filename()} | {error, pkix:error_reason()}.
add_certfile(Path0) -> add_certfile(Path0) ->
Path = prep_path(Path0), Path = prep_path(Path0),
gen_server:call(?MODULE, {add_certfile, Path}, ?CALL_TIMEOUT). try gen_server:call(?MODULE, {add_certfile, Path}, ?CALL_TIMEOUT)
catch exit:{noproc, _} ->
case add_file(Path) of
ok -> {ok, Path};
Err -> Err
end
end.
-spec try_certfile(file:filename_all()) -> filename(). -spec try_certfile(file:filename_all()) -> filename().
try_certfile(Path0) -> try_certfile(Path0) ->
@ -140,10 +146,12 @@ init([]) ->
{Files, []} -> {Files, []} ->
{ok, #state{files = Files}}; {ok, #state{files = Files}};
{Files, [_|_]} -> {Files, [_|_]} ->
del_files(Files),
case ejabberd:is_loaded() of case ejabberd:is_loaded() of
true -> {stop, bad_certfiles}; true ->
false -> stop_ejabberd() {ok, #state{files = Files}};
false ->
del_files(Files),
stop_ejabberd()
end end
end. end.
@ -159,28 +167,24 @@ handle_call({add_certfile, Path}, _From, State) ->
end; end;
handle_call(ejabberd_started, _From, State) -> handle_call(ejabberd_started, _From, State) ->
case commit() of case commit() of
ok -> {ok, []} ->
check_domain_certfiles(), check_domain_certfiles(),
{reply, ok, State}; {reply, ok, State};
{error, _} -> _ ->
stop_ejabberd() stop_ejabberd()
end; end;
handle_call(config_reloaded, _From, State) -> handle_call(config_reloaded, _From, State) ->
Old = State#state.files, Old = State#state.files,
New = get_certfiles_from_config_options(), New = get_certfiles_from_config_options(),
del_files(sets:subtract(Old, New)), del_files(sets:subtract(Old, New)),
{_, Errs1} = add_files(New), add_files(New),
State1 = case commit() of case commit() of
ok -> {ok, _} ->
State#state{files = New};
{error, Errs2} ->
New1 = lists:foldl(
fun sets:del_element/2, New,
[File || {File, _} <- Errs1 ++ Errs2]),
State#state{files = New1}
end,
check_domain_certfiles(), check_domain_certfiles(),
{reply, ok, State1}; {reply, ok, State#state{files = New}};
error ->
{reply, ok, State}
end;
handle_call(Request, _From, State) -> handle_call(Request, _From, State) ->
?WARNING_MSG("Unexpected call: ~p", [Request]), ?WARNING_MSG("Unexpected call: ~p", [Request]),
{noreply, State}. {noreply, State}.
@ -252,7 +256,7 @@ add_file(File) ->
del_files(Files) -> del_files(Files) ->
lists:foreach(fun pkix:del_file/1, sets:to_list(Files)). lists:foreach(fun pkix:del_file/1, sets:to_list(Files)).
-spec commit() -> ok | {error, [{filename(), pkix:error_reason()}]}. -spec commit() -> {ok, [{filename(), pkix:error_reason()}]} | error.
commit() -> commit() ->
Opts = case ca_file() of Opts = case ca_file() of
undefined -> []; undefined -> [];
@ -264,14 +268,11 @@ commit() ->
log_cafile_error(CAError), log_cafile_error(CAError),
log_warnings(Warnings), log_warnings(Warnings),
fast_tls_add_certfiles(), fast_tls_add_certfiles(),
case Errors of {ok, Errors};
[] -> ok;
[_|_] -> {error, Errors}
end;
{error, File, Reason} -> {error, File, Reason} ->
?CRITICAL_MSG("Failed to write to ~s: ~s", ?CRITICAL_MSG("Failed to write to ~s: ~s",
[File, file:format_error(Reason)]), [File, file:format_error(Reason)]),
{error, [{File, Reason}]} error
end. end.
-spec check_domain_certfiles() -> ok. -spec check_domain_certfiles() -> ok.
@ -331,7 +332,8 @@ local_certfiles() ->
get_certfiles_from_config_options() -> get_certfiles_from_config_options() ->
Global = global_certfiles(), Global = global_certfiles(),
Local = local_certfiles(), Local = local_certfiles(),
sets:union(Global, Local). Listen = sets:from_list(ejabberd_listener:get_certfiles()),
sets:union([Global, Local, Listen]).
-spec prep_path(file:filename_all()) -> filename(). -spec prep_path(file:filename_all()) -> filename().
prep_path(Path0) -> prep_path(Path0) ->

View File

@ -44,9 +44,9 @@ init([]) ->
worker(ejabberd_ctl), worker(ejabberd_ctl),
worker(ejabberd_commands), worker(ejabberd_commands),
worker(ejabberd_admin), worker(ejabberd_admin),
supervisor(ejabberd_listener),
worker(ejabberd_pkix), worker(ejabberd_pkix),
worker(ejabberd_acme), worker(ejabberd_acme),
supervisor(ejabberd_listener),
worker(ejabberd_s2s), worker(ejabberd_s2s),
simple_supervisor(ejabberd_s2s_in), simple_supervisor(ejabberd_s2s_in),
simple_supervisor(ejabberd_s2s_out), simple_supervisor(ejabberd_s2s_out),