X-Git-Url: https://jfr.im/git/irc/rqf/shadowircd.git/blobdiff_plain/d3455e2c7e2f9040e1b7628d9cf52b26a24dcefc..8e3b2b85c7221f2f9f1ca6d5e48880d521d2a1a3:/src/logger.c diff --git a/src/logger.c b/src/logger.c index 3452ebe..53cd72b 100644 --- a/src/logger.c +++ b/src/logger.c @@ -38,7 +38,6 @@ #include "ircd_defs.h" #include "logger.h" #include "s_conf.h" -#include "sprintf_irc.h" #include "send.h" #include "client.h" #include "s_serv.h" @@ -50,7 +49,6 @@ static FILE *log_oper; static FILE *log_foper; static FILE *log_server; static FILE *log_kill; -static FILE *log_gline; static FILE *log_kline; static FILE *log_operspy; static FILE *log_ioerror; @@ -71,16 +69,60 @@ static struct log_struct log_table[LAST_LOGFILE] = { &ConfigFileEntry.fname_serverlog, &log_server }, { &ConfigFileEntry.fname_killlog, &log_kill }, { &ConfigFileEntry.fname_klinelog, &log_kline }, - { &ConfigFileEntry.fname_glinelog, &log_gline }, { &ConfigFileEntry.fname_operspylog, &log_operspy }, { &ConfigFileEntry.fname_ioerrorlog, &log_ioerror } }; +static void +verify_logfile_access(const char *filename) +{ + char *dirname, *d; + char buf[512]; + d = rb_dirname(filename); + dirname = LOCAL_COPY(d); + rb_free(d); + + if(access(dirname, F_OK) == -1) + { + rb_snprintf(buf, sizeof(buf), "WARNING: Unable to access logfile %s - parent directory %s does not exist", filename, dirname); + if(testing_conf || server_state_foreground) + fprintf(stderr, "%s\n", buf); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s", buf); + return; + } + + if(access(filename, F_OK) == -1) + { + if(access(dirname, W_OK) == -1) + { + rb_snprintf(buf, sizeof(buf), "WARNING: Unable to access logfile %s - access to parent directory %s failed: %s", + filename, dirname, strerror(errno)); + if(testing_conf || server_state_foreground) + fprintf(stderr, "%s\n", buf); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s", buf); + } + return; + } + + if(access(filename, W_OK) == -1) + { + rb_snprintf(buf, sizeof(buf), "WARNING: Access denied for logfile %s: %s", filename, strerror(errno)); + if(testing_conf || server_state_foreground) + fprintf(stderr, "%s\n", buf); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s", buf); + return; + } + return; +} + void init_main_logfile(void) { + verify_logfile_access(logFileName); if(log_main == NULL) + { log_main = fopen(logFileName, "a"); + } } void @@ -88,26 +130,40 @@ open_logfiles(void) { int i; - if(log_main != NULL) - fclose(log_main); + close_logfiles(); log_main = fopen(logFileName, "a"); /* log_main is handled above, so just do the rest */ for(i = 1; i < LAST_LOGFILE; i++) { - /* close open logfiles */ + /* reopen those with paths */ + if(!EmptyString(*log_table[i].name)) + { + verify_logfile_access(*log_table[i].name); + *log_table[i].logfile = fopen(*log_table[i].name, "a"); + } + } +} + +void +close_logfiles(void) +{ + int i; + + if(log_main != NULL) + fclose(log_main); + + /* log_main is handled above, so just do the rest */ + for(i = 1; i < LAST_LOGFILE; i++) + { if(*log_table[i].logfile != NULL) { fclose(*log_table[i].logfile); *log_table[i].logfile = NULL; } - - /* reopen those with paths */ - if(!EmptyString(*log_table[i].name)) - *log_table[i].logfile = fopen(*log_table[i].name, "a"); } -} +} void ilog(ilogfile dest, const char *format, ...) @@ -130,6 +186,7 @@ ilog(ilogfile dest, const char *format, ...) { fclose(logfile); *log_table[dest].logfile = NULL; + return; } fflush(logfile);