diff --git a/src/alert-debuglog.c b/src/alert-debuglog.c index 5406015268..3961285c2c 100644 --- a/src/alert-debuglog.c +++ b/src/alert-debuglog.c @@ -501,6 +501,7 @@ OutputCtx *AlertDebugLogInitCtx(ConfNode *conf) output_ctx->data = file_ctx; output_ctx->DeInit = AlertDebugLogDeInitCtx; + SCLogInfo("Alert debug log output initialized, filename: %s", filename); return output_ctx; error: @@ -514,6 +515,7 @@ error: /** \brief Read the config set the file pointer, open the file * \param file_ctx pointer to a created LogFileCtx using LogFileNewCtx() * \param filename name of log file + * \param mode append mode (bool) * \return -1 if failure, 0 if succesful * */ int AlertDebugLogOpenFileCtx(LogFileCtx *file_ctx, const char *filename, const @@ -527,7 +529,7 @@ int AlertDebugLogOpenFileCtx(LogFileCtx *file_ctx, const char *filename, const snprintf(log_path, PATH_MAX, "%s/%s", log_dir, filename); - if (strcasecmp(mode, "yes") == 0) { + if (ConfValIsTrue(mode)) { file_ctx->fp = fopen(log_path, "a"); } else { file_ctx->fp = fopen(log_path, "w"); diff --git a/src/alert-fastlog.c b/src/alert-fastlog.c index d1a2932dbe..52e5b84d78 100644 --- a/src/alert-fastlog.c +++ b/src/alert-fastlog.c @@ -378,6 +378,7 @@ static void AlertFastLogDeInitCtx(OutputCtx *output_ctx) /** \brief Read the config set the file pointer, open the file * \param file_ctx pointer to a created LogFileCtx using LogFileNewCtx() * \param filename name of log file + * \param mode append mode (bool) * \return -1 if failure, 0 if succesful * */ static int AlertFastLogOpenFileCtx(LogFileCtx *file_ctx, const char *filename, @@ -391,7 +392,7 @@ static int AlertFastLogOpenFileCtx(LogFileCtx *file_ctx, const char *filename, snprintf(log_path, PATH_MAX, "%s/%s", log_dir, filename); - if (strcasecmp(mode, "yes") == 0) { + if (ConfValIsTrue(mode)) { file_ctx->fp = fopen(log_path, "a"); } else { file_ctx->fp = fopen(log_path, "w"); diff --git a/src/alert-prelude.c b/src/alert-prelude.c index 6c1c0e78c0..bf3b8b38ae 100644 --- a/src/alert-prelude.c +++ b/src/alert-prelude.c @@ -852,9 +852,9 @@ OutputCtx *AlertPreludeInitCtx(ConfNode *conf) ctx->client = client; ctx->log_packet_content = 0; ctx->log_packet_header = 1; - if (log_packet_content && strcmp(log_packet_content,"yes")==0) + if (log_packet_content && ConfValIsTrue(log_packet_content)) ctx->log_packet_content = 1; - if (log_packet_header && strcmp(log_packet_header,"yes")!=0) + if (log_packet_header && ConfValIsFalse(log_packet_header)) ctx->log_packet_header = 0; output_ctx = SCMalloc(sizeof(OutputCtx)); diff --git a/src/alert-syslog.c b/src/alert-syslog.c index 19ee389598..db67c78ad4 100644 --- a/src/alert-syslog.c +++ b/src/alert-syslog.c @@ -120,12 +120,6 @@ void TmModuleAlertSyslogIPv6Register (void) { */ OutputCtx *AlertSyslogInitCtx(ConfNode *conf) { - const char *enabled = ConfNodeLookupChildValue(conf, "enabled"); - if (enabled != NULL && strcasecmp(enabled, "no") == 0) { - SCLogDebug("alert-syslog module has been disabled"); - return NULL; - } - const char *facility_s = ConfNodeLookupChildValue(conf, "facility"); if (facility_s == NULL) { facility_s = DEFAULT_ALERT_SYSLOG_FACILITY_STR; diff --git a/src/conf.c b/src/conf.c index 233de1cda0..075281fb11 100644 --- a/src/conf.c +++ b/src/conf.c @@ -358,7 +358,7 @@ int ConfGetChildValueBool(ConfNode *base, char *name, int *val) /** * \brief Check if a value is true. * - * The value of considered true if it is a string with the value of 1, + * The value is considered true if it is a string with the value of 1, * yes, true or on. The test is not case sensitive, any other value * is false. * @@ -381,6 +381,32 @@ ConfValIsTrue(const char *val) return 0; } +/** + * \brief Check if a value is false. + * + * The value is considered false if it is a string with the value of 0, + * no, false or off. The test is not case sensitive, any other value + * is not false. + * + * \param val The string to test for a false value. + * + * \retval 1 If the value is false, 0 if not. + */ +int +ConfValIsFalse(const char *val) +{ + char *falses[] = {"0", "no", "false", "off"}; + size_t u; + + for (u = 0; u < sizeof(falses) / sizeof(falses[0]); u++) { + if (strcasecmp(val, falses[u]) == 0) { + return 1; + } + } + + return 0; +} + /** * \brief Retrieve a configuration value as a double * diff --git a/src/conf.h b/src/conf.h index a068bc7891..92c1f99502 100644 --- a/src/conf.h +++ b/src/conf.h @@ -69,6 +69,7 @@ void ConfNodeRemove(ConfNode *); void ConfRegisterTests(); int ConfNodeChildValueIsTrue(ConfNode *node, const char *key); int ConfValIsTrue(const char *val); +int ConfValIsFalse(const char *val); ConfNode *ConfNodeLookupKeyValue(ConfNode *base, const char *key, const char *value); diff --git a/src/counters.c b/src/counters.c index 81ffcff45b..45ecd2d0c0 100644 --- a/src/counters.c +++ b/src/counters.c @@ -323,7 +323,7 @@ static void SCPerfInitOPCtx(void) /* Check if the stats module is enabled or not */ if (stats != NULL) { const char *enabled = ConfNodeLookupChildValue(stats, "enabled"); - if (strcasecmp(enabled, "no") == 0) { + if (enabled != NULL && ConfValIsFalse(enabled)) { sc_counter_enabled = FALSE; SCLogDebug("Stats module has been disabled"); SCReturn; @@ -334,7 +334,7 @@ static void SCPerfInitOPCtx(void) const char *append = ConfNodeLookupChildValue(stats, "append"); if (append != NULL) - sc_counter_append = (strcasecmp(append,"yes") == 0); + sc_counter_append = ConfValIsTrue(append); } /* Store the engine start time */ diff --git a/src/log-droplog.c b/src/log-droplog.c index dd8b7b684d..e9a991c561 100644 --- a/src/log-droplog.c +++ b/src/log-droplog.c @@ -146,11 +146,6 @@ TmEcode LogDropLogThreadDeinit(ThreadVars *t, void *data) */ OutputCtx *LogDropLogInitCtx(ConfNode *conf) { - const char *enable = ConfNodeLookupChildValue(conf, "enabled"); - if (enable == NULL || strcasecmp (enable, "no") == 0) { - return NULL; - } - LogFileCtx *logfile_ctx = LogFileNewCtx(); if (logfile_ctx == NULL) { SCLogDebug("LogDropLogInitCtx: Could not create new LogFileCtx"); @@ -202,6 +197,7 @@ static void LogDropLogDeInitCtx(OutputCtx *output_ctx) /** \brief Read the config set the file pointer, open the file * \param file_ctx pointer to a created LogFileCtx using LogFileNewCtx() * \param filename name of log file + * \param mode append mode (bool) * \return -1 if failure, 0 if succesful * */ static int LogDropLogOpenFileCtx(LogFileCtx *file_ctx, const char *filename, @@ -215,7 +211,7 @@ static int LogDropLogOpenFileCtx(LogFileCtx *file_ctx, const char *filename, snprintf(log_path, PATH_MAX, "%s/%s", log_dir, filename); - if (strcasecmp(mode, "yes") == 0) { + if (ConfValIsTrue(mode)) { file_ctx->fp = fopen(log_path, "a"); } else { file_ctx->fp = fopen(log_path, "w"); diff --git a/src/log-httplog.c b/src/log-httplog.c index 92452cbfee..3e43bd5cad 100644 --- a/src/log-httplog.c +++ b/src/log-httplog.c @@ -411,6 +411,7 @@ void LogHttpLogExitPrintStats(ThreadVars *tv, void *data) { OutputCtx *LogHttpLogInitCtx(ConfNode *conf) { int ret=0; + LogFileCtx* file_ctx=LogFileNewCtx(); if(file_ctx == NULL) @@ -439,6 +440,8 @@ OutputCtx *LogHttpLogInitCtx(ConfNode *conf) output_ctx->data = file_ctx; output_ctx->DeInit = LogHttpLogDeInitCtx; + SCLogInfo("HTTP log output initialized, filename: %s", filename); + return output_ctx; } @@ -451,7 +454,8 @@ static void LogHttpLogDeInitCtx(OutputCtx *output_ctx) /** \brief Read the config set the file pointer, open the file * \param file_ctx pointer to a created LogFileCtx using LogFileNewCtx() - * \param config_file for loading separate configs + * \param filename name of log file + * \param mode append mode (bool) * \return -1 if failure, 0 if succesful * */ int LogHttpLogOpenFileCtx(LogFileCtx *file_ctx, const char *filename, const @@ -465,7 +469,7 @@ int LogHttpLogOpenFileCtx(LogFileCtx *file_ctx, const char *filename, const snprintf(log_path, PATH_MAX, "%s/%s", log_dir, filename); - if (strcasecmp(mode, "yes") == 0) { + if (ConfValIsTrue(mode)) { file_ctx->fp = fopen(log_path, "a"); } else { file_ctx->fp = fopen(log_path, "w"); diff --git a/src/stream-tcp.c b/src/stream-tcp.c index 5681d70ba1..519012bb28 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -378,26 +378,24 @@ void StreamTcpInitConfig(char quiet) SCLogInfo("stream \"memcap\": %"PRIu32"", stream_config.memcap); } - if ((ConfGetBool("stream.midstream", &stream_config.midstream)) == 0) { - stream_config.midstream = FALSE; - } + ConfGetBool("stream.midstream", &stream_config.midstream); + if (!quiet) { SCLogInfo("stream \"midstream\" session pickups: %s", stream_config.midstream ? "enabled" : "disabled"); } - if ((ConfGetBool("stream.async_oneside", &stream_config.async_oneside)) == 0) - { - stream_config.async_oneside = FALSE; - } + ConfGetBool("stream.async_oneside", &stream_config.async_oneside); + if (!quiet) { SCLogInfo("stream \"async_oneside\": %s", stream_config.async_oneside ? "enabled" : "disabled"); } - char *csum = NULL; - if ((ConfGet("stream.checksum_validation", &csum)) == 1) { - if (strcmp(csum, "yes") == 0) { + int csum = 0; + + if ((ConfGetBool("stream.checksum_validation", &csum)) == 1) { + if (csum == 1) { stream_config.flags |= STREAMTCP_INIT_FLAG_CHECKSUM_VALIDATION; - } + } /* Default is that we validate the checksum of all the packets */ } else { stream_config.flags |= STREAMTCP_INIT_FLAG_CHECKSUM_VALIDATION; @@ -409,11 +407,10 @@ void StreamTcpInitConfig(char quiet) "enabled" : "disabled"); } - char *inl = NULL; - if ((ConfGet("stream.inline", &inl)) == 1) { - if (strcasecmp(inl, "yes") == 0) { - stream_inline = 1; - } + int inl = 0; + + if (ConfGetBool("stream.inline", &inl) == 1) { + stream_inline = inl; } if (!quiet) { diff --git a/src/util-debug.c b/src/util-debug.c index cedce077a2..6e3464b746 100644 --- a/src/util-debug.c +++ b/src/util-debug.c @@ -1154,7 +1154,7 @@ void SCLogLoadConfig(void) /* By default an output is enabled. */ const char *enabled = ConfNodeLookupChildValue(output, "enabled"); - if (enabled != NULL && strcmp(enabled, "no") == 0) + if (enabled != NULL && ConfValIsFalse(enabled)) continue; /* if available use the log format setting for this output, diff --git a/src/util-profiling.c b/src/util-profiling.c index c36ccd2a30..3dbe2d79d3 100644 --- a/src/util-profiling.c +++ b/src/util-profiling.c @@ -428,7 +428,7 @@ SCProfilingDump(void) struct timeval tval; struct tm *tms; if (profiling_output_to_file == 1) { - if (strcasecmp(profiling_file_mode, "yes") == 0) { + if (ConfValIsTrue(profiling_file_mode)) { fp = fopen(profiling_file_name, "a"); } else { fp = fopen(profiling_file_name, "w");