Project

General

Profile

Bug #99 ยป 0001-Fix-bug-99.patch

Jason Ish, 02/18/2010 12:54 AM

View differences:

src/conf-yaml-loader.c
}
else {
if (state == CONF_KEY) {
/* If the node already exists, check if we can
* override it. If we can, free it then continue
* otherwise move onto the next configuration
* parameter. */
ConfNode *n0 = ConfNodeLookupChild(parent, value);
if (n0 != NULL) {
if (n0->allow_override) {
ConfNodeRemove(n0);
}
else {
state = CONF_VAL;
goto next;
}
}
if (parent->is_seq) {
if (parent->val == NULL) {
parent->val = strdup(value);
}
}
node = ConfNodeNew();
node->name = strdup(value);
TAILQ_INSERT_TAIL(&parent->head, node, next);
ConfNode *n0 = ConfNodeLookupChild(parent, value);
if (n0 != NULL) {
node = n0;
}
else {
node = ConfNodeNew();
node->name = strdup(value);
TAILQ_INSERT_TAIL(&parent->head, node, next);
}
state = CONF_VAL;
}
else {
node->val = strdup(value);
if (node->allow_override) {
if (node->val != NULL)
free(node->val);
node->val = strdup(value);
}
state = CONF_KEY;
}
}
......
done = 1;
}
next:
yaml_event_delete(&event);
continue;
src/conf.c
* \todo Consider having the in-memory configuration database a direct
* reflection of the configuration file and moving command line
* parameters to a primary lookup table?
*
* \todo Get rid of allow override and go with a simpler first set,
* stays approach?
*/
#include <string.h>
......
"Error allocating memory for new configuration node");
exit(EXIT_FAILURE);
}
/* By default we allow an override. */
new->allow_override = 1;
TAILQ_INIT(&new->head);
return new;
......
ConfGetNode(char *key)
{
ConfNode *node = root;
char *saveptr;
char *saveptr = NULL;
char *token;
/* Need to dup the key for tokenization... */
......
ConfNode *parent = root;
ConfNode *node;
char *token;
char *saveptr;
char *saveptr = NULL;
/* First check if the node already exists. */
node = ConfGetNode(name);
......
node->parent = parent;
TAILQ_INSERT_TAIL(&parent->head, node, next);
parent = node;
}
else {
parent = node;
}
token = strtok_r(NULL, ".", &saveptr);
if (token == NULL) {
if (!node->allow_override)
break;
if (node->val != NULL)
free(node->val);
node->val = strdup(val);
......
return 1;
}
static int
ConfSetTest(void)
{
ConfCreateContextBackup();
ConfInit();
/* Set some value with 2 levels. */
if (ConfSet("one.two", "three", 1) != 1)
return 0;
ConfNode *n = ConfGetNode("one.two");
if (n == NULL)
return 0;
/* Set another 2 level parameter with the same first level, this
* used to trigger a bug that caused the second level of the name
* to become a first level node. */
if (ConfSet("one.three", "four", 1) != 1)
return 0;
n = ConfGetNode("one.three");
if (n == NULL)
return 0;
/* A top level node of "three" should not exist. */
n = ConfGetNode("three");
if (n != NULL)
return 0;
ConfDeInit();
ConfRestoreContextBackup();
return 1;
}
void
ConfRegisterTests(void)
{
UtRegisterTest("ConfTestGetNonExistant", ConfTestGetNonExistant, 1);
UtRegisterTest("ConfSetTest", ConfSetTest, 1);
UtRegisterTest("ConfTestSetAndGet", ConfTestSetAndGet, 1);
UtRegisterTest("ConfTestOverrideValue1", ConfTestOverrideValue1, 1);
UtRegisterTest("ConfTestOverrideValue2", ConfTestOverrideValue2, 1);
src/suricata.c
}
}
else if(strcmp((long_opts[option_index]).name , "pfring-clusterid") == 0){
printf ("clusterid %s\n",optarg);
if (ConfSet("pfring.clusterid", optarg, 0) != 1) {
fprintf(stderr, "ERROR: Failed to set pfring clusterid.\n");
exit(EXIT_FAILURE);
    (1-1/1)