mirror of
https://gitlab.xiph.org/xiph/ezstream.git
synced 2024-09-01 03:54:15 -04:00
Relocate config file check
* Stop supporting systems without stat(2) while here * Remove some additional configure checks for ubiquitous functions (>=C99)
This commit is contained in:
parent
05c7e32997
commit
33eb55ae34
@ -239,11 +239,7 @@ AC_CHECK_FUNCS([ \
|
||||
popen \
|
||||
random \
|
||||
setlocale \
|
||||
snprintf \
|
||||
srandomdev \
|
||||
stat \
|
||||
strncasecmp \
|
||||
strtoll \
|
||||
])
|
||||
|
||||
AC_REPLACE_FUNCS([ \
|
||||
|
27
src/cfg.c
27
src/cfg.c
@ -20,8 +20,12 @@
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#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)
|
||||
{
|
||||
|
@ -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 **);
|
||||
|
@ -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);
|
||||
|
@ -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",
|
||||
|
@ -28,9 +28,6 @@
|
||||
# include <sys/time.h>
|
||||
#endif /* HAVE_SYS_TIME_H */
|
||||
#include <time.h>
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
# include <sys/stat.h>
|
||||
#endif /* HAVE_SYS_STAT_H */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
Loading…
Reference in New Issue
Block a user