fixed bug 288; corrected config boolean parsing problems

remotes/origin/master-1.1.x
Eileen Donlon 14 years ago committed by Victor Julien
parent de1d002ea6
commit 89599d3b9b

@ -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");

@ -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");

@ -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));

@ -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;

@ -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
*

@ -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);

@ -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 */

@ -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");

@ -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");

@ -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) {

@ -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,

@ -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");

Loading…
Cancel
Save