From 9bd099013fd02c00385d37ca2bc05602c3c52bcf Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Thu, 17 Aug 2017 14:33:41 +0300 Subject: [PATCH] Don't attempt to access(2) a certificate file Fixes #1375 --- src/ejabberd_config.erl | 5 +++-- src/misc.erl | 20 +++++--------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/ejabberd_config.erl b/src/ejabberd_config.erl index 1e5d495ce..5d3bc8680 100644 --- a/src/ejabberd_config.erl +++ b/src/ejabberd_config.erl @@ -28,7 +28,7 @@ -export([start/0, load_file/1, reload_file/0, read_file/1, get_option/1, get_option/2, add_option/2, has_option/1, - get_vh_by_auth_method/1, is_file_readable/1, + get_vh_by_auth_method/1, get_version/0, get_myhosts/0, get_mylang/0, get_lang/1, get_ejabberd_config_path/0, is_using_elixir_config/0, prepare_opt_val/4, transform_options/1, collect_options/1, @@ -46,11 +46,12 @@ get_global_option/2, get_local_option/2, get_global_option/3, get_local_option/3, get_option/3]). +-export([is_file_readable/1]). -deprecated([{add_global_option, 2}, {add_local_option, 2}, {get_global_option, 2}, {get_local_option, 2}, {get_global_option, 3}, {get_local_option, 3}, - {get_option, 3}]). + {get_option, 3}, {is_file_readable, 1}]). -include("ejabberd.hrl"). -include("logger.hrl"). diff --git a/src/misc.erl b/src/misc.erl index 2112cd90c..32699e76b 100644 --- a/src/misc.erl +++ b/src/misc.erl @@ -204,22 +204,12 @@ join_atoms(Atoms, Sep) -> %% in configuration validators only. -spec try_read_file(file:filename_all()) -> binary(). try_read_file(Path) -> - Res = case file:read_file_info(Path) of - {ok, #file_info{type = Type, access = Access}} -> - case {Type, Access} of - {regular, read} -> ok; - {regular, read_write} -> ok; - {regular, _} -> {error, file:format_error(eaccess)}; - _ -> {error, "not a regular file"} - end; - {error, Why} -> - {error, file:format_error(Why)} - end, - case Res of - ok -> + case file:open(Path, [read]) of + {ok, Fd} -> + file:close(Fd), iolist_to_binary(Path); - {error, Reason} -> - ?ERROR_MSG("Failed to read ~s: ~s", [Path, Reason]), + {error, Why} -> + ?ERROR_MSG("Failed to read ~s: ~s", [Path, file:format_error(Why)]), erlang:error(badarg) end.