From 33eb55ae3423341978e067ffd7bd9ffaf10da34c Mon Sep 17 00:00:00 2001 From: Moritz Grimm Date: Wed, 6 May 2015 17:00:23 +0000 Subject: [PATCH] Relocate config file check * Stop supporting systems without stat(2) while here * Remove some additional configure checks for ubiquitous functions (>=C99) --- configure.ac | 4 ---- src/cfg.c | 27 +++++++++++++++++++++++++++ src/cfg.h | 2 ++ src/cfg_xmlfile.c | 3 +++ src/ezstream.c | 40 +--------------------------------------- src/ezstream.h | 3 --- 6 files changed, 33 insertions(+), 46 deletions(-) diff --git a/configure.ac b/configure.ac index 94a0736..c3fb9a6 100644 --- a/configure.ac +++ b/configure.ac @@ -239,11 +239,7 @@ AC_CHECK_FUNCS([ \ popen \ random \ setlocale \ - snprintf \ srandomdev \ - stat \ - strncasecmp \ - strtoll \ ]) AC_REPLACE_FUNCS([ \ diff --git a/src/cfg.c b/src/cfg.c index c707a9f..675ad3e 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -20,8 +20,12 @@ #include "compat.h" +#include + +#include #include #include +#include #include "cfg_private.h" #include "cfg_xmlfile.h" @@ -161,6 +165,29 @@ cfg_stream_fmt2str(enum cfg_stream_format fmt) } } +int +cfg_file_check(const char *file) +{ + struct stat st; + + if (0 > stat(file, &st)) { + log_error("%s: %s", file, strerror(errno)); + return (-1); + } + + if (st.st_mode & S_IROTH) + log_warning("%s: world readable", file); + else if (st.st_mode & S_IRGRP) + log_notice("%s: group readable", file); + + if (st.st_mode & S_IWOTH) { + log_error("%s: world writeable", file); + return (-1); + } + + return (0); +} + int cfg_set_program_name(const char *progname, const char **errstrp) { diff --git a/src/cfg.h b/src/cfg.h index 4e5ac0f..0620b81 100644 --- a/src/cfg.h +++ b/src/cfg.h @@ -69,6 +69,8 @@ int cfg_stream_str2fmt(const char *, enum cfg_stream_format *); const char * cfg_stream_fmt2str(enum cfg_stream_format); +int cfg_file_check(const char *); + int cfg_set_program_name(const char *, const char **); int cfg_set_program_config_type(enum cfg_config_type, const char **); int cfg_set_program_config_file(const char *, const char **); diff --git a/src/cfg_xmlfile.c b/src/cfg_xmlfile.c index 6dde417..105acd0 100644 --- a/src/cfg_xmlfile.c +++ b/src/cfg_xmlfile.c @@ -319,6 +319,9 @@ cfg_xmlfile_parse(const char *config_file) xmlLineNumbersDefault(1); + if (0 > cfg_file_check(config_file)) + goto error; + doc = xmlParseFile(config_file); if (!doc) { log_error("%s: not well-formed XML", config_file); diff --git a/src/ezstream.c b/src/ezstream.c index 78adbe8..5c5b389 100644 --- a/src/ezstream.c +++ b/src/ezstream.c @@ -1014,47 +1014,9 @@ main(int argc, char *argv[]) 0 > cfg_encoder_init() || 0 > playlist_init() || 0 > cfg_reload()) - return (ret); + return (ez_shutdown(ret)); shout_init(); - { - /* - * Attempt to open configFile here for a more meaningful error - * message. Where possible, do it with stat() and check for - * safe config file permissions. - */ -#ifdef HAVE_STAT - struct stat st; - - if (stat(cfg_get_program_config_file(), &st) == -1) { - log_error("%s: %s", cfg_get_program_config_file(), - strerror(errno)); - return (ez_shutdown(2)); - } - if (cfg_get_program_verbosity() && (st.st_mode & (S_IRGRP | S_IROTH))) - log_warning("%s: group and/or world readable", - cfg_get_program_config_file()); - if (st.st_mode & (S_IWGRP | S_IWOTH)) { - log_error("%s: group and/or world writeable", - cfg_get_program_config_file()); - return (ez_shutdown(2)); - } -#else - FILE *tmp; - - if ((tmp = fopen(cfg_get_program_config_file(), "r")) == NULL) { - log_error("%s: %s", cfg_get_program_config_file(), - strerror(errno)); - usage(); - return (ez_shutdown(2)); - } - fclose(tmp); -#endif /* HAVE_STAT */ - } - - if (0 > cfg_reload()) - return (ez_shutdown(2)); - if (!cfg_get_server_hostname() || !cfg_get_server_port()){ log_error("%s: missing server configuration", diff --git a/src/ezstream.h b/src/ezstream.h index 43b0846..04f09e9 100644 --- a/src/ezstream.h +++ b/src/ezstream.h @@ -28,9 +28,6 @@ # include #endif /* HAVE_SYS_TIME_H */ #include -#ifdef HAVE_SYS_STAT_H -# include -#endif /* HAVE_SYS_STAT_H */ #include #include