if (unlikely(new == NULL)) {
return NULL;
}
- /* By default we allow an override. */
- new->allow_override = 1;
TAILQ_INIT(&new->head);
return new;
* \retval 1 if the value was set otherwise 0.
*/
int
-ConfSet(char *name, char *val, int allow_override)
+ConfSet(char *name, char *val)
{
ConfNode *node = ConfGetNodeOrCreate(name);
- if (node == NULL || !node->allow_override) {
+ if (node == NULL || node->final) {
return 0;
}
if (node->val != NULL)
SCFree(node->val);
node->val = SCStrdup(val);
- node->allow_override = allow_override;
+ return 1;
+}
+
+int
+ConfSetFinal(char *name, char *val)
+{
+ ConfNode *node = ConfGetNodeOrCreate(name);
+ if (node == NULL) {
+ return 0;
+ }
+ if (node->val != NULL)
+ SCFree(node->val);
+ node->val = SCStrdup(val);
+ node->final = 1;
return 1;
}
char value[] = "some-value";
char *value0;
- if (ConfSet(name, value, 1) != 1)
+ if (ConfSet(name, value) != 1)
return 0;
if (ConfGet(name, &value0) != 1)
return 0;
char *val;
int rc;
- if (ConfSet(name, value0, 1) != 1)
+ if (ConfSet(name, value0) != 1)
return 0;
- if (ConfSet(name, value1, 1) != 1)
+ if (ConfSet(name, value1) != 1)
return 0;
if (ConfGet(name, &val) != 1)
return 0;
}
/**
- * Test that overriding a value is not allowed provided that
- * allow_override is false and make sure the value was not overrided.
+ * Test that a final value will not be overrided by a ConfSet.
*/
static int
ConfTestOverrideValue2(void)
char *val;
int rc;
- if (ConfSet(name, value0, 0) != 1)
+ if (ConfSetFinal(name, value0) != 1)
return 0;
- if (ConfSet(name, value1, 1) != 0)
+ if (ConfSet(name, value1) != 0)
return 0;
if (ConfGet(name, &val) != 1)
return 0;
char name[] = "some-int.x";
intmax_t val;
- if (ConfSet(name, "0", 1) != 1)
+ if (ConfSet(name, "0") != 1)
return 0;
if (ConfGetInt(name, &val) != 1)
return 0;
if (val != 0)
return 0;
- if (ConfSet(name, "-1", 1) != 1)
+ if (ConfSet(name, "-1") != 1)
return 0;
if (ConfGetInt(name, &val) != 1)
return 0;
if (val != -1)
return 0;
- if (ConfSet(name, "0xffff", 1) != 1)
+ if (ConfSet(name, "0xffff") != 1)
return 0;
if (ConfGetInt(name, &val) != 1)
return 0;
if (val != 0xffff)
return 0;
- if (ConfSet(name, "not-an-int", 1) != 1)
+ if (ConfSet(name, "not-an-int") != 1)
return 0;
if (ConfGetInt(name, &val) != 0)
return 0;
size_t u;
for (u = 0; u < sizeof(trues) / sizeof(trues[0]); u++) {
- if (ConfSet(name, trues[u], 1) != 1)
+ if (ConfSet(name, trues[u]) != 1)
return 0;
if (ConfGetBool(name, &val) != 1)
return 0;
}
for (u = 0; u < sizeof(falses) / sizeof(falses[0]); u++) {
- if (ConfSet(name, falses[u], 1) != 1)
+ if (ConfSet(name, falses[u]) != 1)
return 0;
if (ConfGetBool(name, &val) != 1)
return 0;
int ret = 1;
ConfCreateContextBackup();
ConfInit();
- ConfSet("af-packet.0.interface", "eth0", 1);
- ConfSet("af-packet.1.interface", "default", 1);
- ConfSet("af-packet.1.cluster-type", "cluster_cpu", 1);
+ ConfSet("af-packet.0.interface", "eth0");
+ ConfSet("af-packet.1.interface", "default");
+ ConfSet("af-packet.1.cluster-type", "cluster_cpu");
ConfNode *root = ConfGetNode("af-packet.0");
ConfNode *dflt = ConfGetNode("af-packet.1");
return 0;
}
- ConfSet("af-packet.0.cluster-type", "cluster_flow", 1);
+ ConfSet("af-packet.0.cluster-type", "cluster_flow");
ConfGetChildValueWithDefault(root, dflt, "cluster-type", &val);
if (strcmp(val, "cluster_flow")) {
intmax_t val;
ConfCreateContextBackup();
ConfInit();
- ConfSet("af-packet.0.interface", "eth0", 1);
- ConfSet("af-packet.1.interface", "default", 1);
- ConfSet("af-packet.1.threads", "2", 1);
+ ConfSet("af-packet.0.interface", "eth0");
+ ConfSet("af-packet.1.interface", "default");
+ ConfSet("af-packet.1.threads", "2");
ConfNode *root = ConfGetNode("af-packet.0");
ConfNode *dflt = ConfGetNode("af-packet.1");
return 0;
}
- ConfSet("af-packet.0.threads", "1", 1);
+ ConfSet("af-packet.0.threads", "1");
ConfGetChildValueIntWithDefault(root, dflt, "threads", &val);
ConfDeInit();
int val;
ConfCreateContextBackup();
ConfInit();
- ConfSet("af-packet.0.interface", "eth0", 1);
- ConfSet("af-packet.1.interface", "default", 1);
- ConfSet("af-packet.1.use-mmap", "yes", 1);
+ ConfSet("af-packet.0.interface", "eth0");
+ ConfSet("af-packet.1.interface", "default");
+ ConfSet("af-packet.1.use-mmap", "yes");
ConfNode *root = ConfGetNode("af-packet.0");
ConfNode *dflt = ConfGetNode("af-packet.1");
return 0;
}
- ConfSet("af-packet.0.use-mmap", "no", 1);
+ ConfSet("af-packet.0.use-mmap", "no");
ConfGetChildValueBoolWithDefault(root, dflt, "use-mmap", &val);
ConfDeInit();
ConfCreateContextBackup();
ConfInit();
- if (ConfSet("some.nested.parameter", "blah", 1) != 1)
+ if (ConfSet("some.nested.parameter", "blah") != 1)
return 0;
ConfNode *node = ConfGetNode("some.nested.parameter");
ConfInit();
/* Set some value with 2 levels. */
- if (ConfSet("one.two", "three", 1) != 1)
+ if (ConfSet("one.two", "three") != 1)
return 0;
ConfNode *n = ConfGetNode("one.two");
if (n == NULL)
/* 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)
+ if (ConfSet("one.three", "four") != 1)
return 0;
n = ConfGetNode("one.three");
}
if(strlen(bpf_filter) > 0) {
- if (ConfSet("bpf-filter", bpf_filter, 0) != 1) {
+ if (ConfSetFinal("bpf-filter", bpf_filter) != 1) {
SCLogError(SC_ERR_FATAL, "Failed to set bpf filter.");
return TM_ECODE_FAILED;
}
while((bpf_comment_tmp = strchr(bpf_filter, '\n')) != NULL) {
*bpf_comment_tmp = ' ';
}
- if(ConfSet("bpf-filter", bpf_filter, 0) != 1) {
+ if(ConfSetFinal("bpf-filter", bpf_filter) != 1) {
SCLogError(SC_ERR_FOPEN, "ERROR: Failed to set bpf filter!");
SCFree(bpf_filter);
exit(EXIT_FAILURE);
#ifdef HAVE_MPIPE
} else if (run_mode == RUNMODE_TILERA_MPIPE) {
if (strlen(pcap_dev)) {
- if (ConfSet("mpipe.single_mpipe_dev", pcap_dev, 0) != 1) {
+ if (ConfSetFinal("mpipe.single_mpipe_dev", pcap_dev) != 1) {
fprintf(stderr, "ERROR: Failed to set mpipe.single_mpipe_dev\n");
SCReturnInt(TM_ECODE_FAILED);
}
/* FIXME add backward compat support */
/* iface has been set on command line */
if (strlen(pcap_dev)) {
- if (ConfSet("pfring.live-interface", pcap_dev, 0) != 1) {
+ if (ConfSetFinal("pfring.live-interface", pcap_dev) != 1) {
SCLogError(SC_ERR_INITIALIZATION, "Failed to set pfring.live-interface");
SCReturnInt(TM_ECODE_FAILED);
}
} else if (run_mode == RUNMODE_AFP_DEV) {
/* iface has been set on command line */
if (strlen(pcap_dev)) {
- if (ConfSet("af-packet.live-interface", pcap_dev, 0) != 1) {
+ if (ConfSetFinal("af-packet.live-interface", pcap_dev) != 1) {
SCLogError(SC_ERR_INITIALIZATION, "Failed to set af-packet.live-interface");
SCReturnInt(TM_ECODE_FAILED);
}
}
else if(strcmp((long_opts[option_index]).name , "pfring-cluster-id") == 0){
#ifdef HAVE_PFRING
- if (ConfSet("pfring.cluster-id", optarg, 0) != 1) {
+ if (ConfSetFinal("pfring.cluster-id", optarg) != 1) {
fprintf(stderr, "ERROR: Failed to set pfring.cluster-id.\n");
return TM_ECODE_FAILED;
}
}
else if(strcmp((long_opts[option_index]).name , "pfring-cluster-type") == 0){
#ifdef HAVE_PFRING
- if (ConfSet("pfring.cluster-type", optarg, 0) != 1) {
+ if (ConfSetFinal("pfring.cluster-type", optarg) != 1) {
fprintf(stderr, "ERROR: Failed to set pfring.cluster-type.\n");
return TM_ECODE_FAILED;
}
return TM_ECODE_FAILED;
}
} else if(strcmp((long_opts[option_index]).name, "init-errors-fatal") == 0) {
- if (ConfSet("engine.init-failure-fatal", "1", 0) != 1) {
+ if (ConfSetFinal("engine.init-failure-fatal", "1") != 1) {
fprintf(stderr, "ERROR: Failed to set engine init-failure-fatal.\n");
return TM_ECODE_FAILED;
}
if (suri->run_mode == RUNMODE_UNKNOWN) {
suri->run_mode = RUNMODE_UNIX_SOCKET;
if (optarg) {
- if (ConfSet("unix-command.filename", optarg, 0) != 1) {
+ if (ConfSetFinal("unix-command.filename", optarg) != 1) {
fprintf(stderr, "ERROR: Failed to set unix-command.filename.\n");
return TM_ECODE_FAILED;
}
}
else if(strcmp((long_opts[option_index]).name, "fatal-unittests") == 0) {
#ifdef UNITTESTS
- if (ConfSet("unittests.failure-fatal", "1", 0) != 1) {
+ if (ConfSetFinal("unittests.failure-fatal", "1") != 1) {
fprintf(stderr, "ERROR: Failed to set unittests failure-fatal.\n");
return TM_ECODE_FAILED;
}
}
else if (strcmp((long_opts[option_index]).name, "erf-in") == 0) {
suri->run_mode = RUNMODE_ERF_FILE;
- if (ConfSet("erf-file.file", optarg, 0) != 1) {
+ if (ConfSetFinal("erf-file.file", optarg) != 1) {
fprintf(stderr, "ERROR: Failed to set erf-file.file\n");
return TM_ECODE_FAILED;
}
}
else if(strcmp((long_opts[option_index]).name, "pcap-buffer-size") == 0) {
#ifdef HAVE_PCAP_SET_BUFF
- if (ConfSet("pcap.buffer-size", optarg, 0) != 1) {
+ if (ConfSetFinal("pcap.buffer-size", optarg) != 1) {
fprintf(stderr, "ERROR: Failed to set pcap-buffer-size.\n");
return TM_ECODE_FAILED;
}
case 'T':
SCLogInfo("Running suricata under test mode");
conf_test = 1;
- if (ConfSet("engine.init-failure-fatal", "1", 0) != 1) {
+ if (ConfSetFinal("engine.init-failure-fatal", "1") != 1) {
fprintf(stderr, "ERROR: Failed to set engine init-failure-fatal.\n");
return TM_ECODE_FAILED;
}
usage(argv[0]);
return TM_ECODE_FAILED;
}
- if (ConfSet("pcap-file.file", optarg, 0) != 1) {
+ if (ConfSetFinal("pcap-file.file", optarg) != 1) {
fprintf(stderr, "ERROR: Failed to set pcap-file.file\n");
return TM_ECODE_FAILED;
}