Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions plugins/pfring/runmode-pfring.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static void *OldParsePfringConfig(const char *iface)
SCLogInfo("%s: ZC interface detected, not setting cluster-id", pfconf->iface);
} else if ((pfconf->threads == 1) && (strncmp(pfconf->iface, "dna", 3) == 0)) {
SCLogInfo("DNA interface detected, not setting cluster-id");
} else if (SCConfGet("pfring.cluster-id", &tmpclusterid) != 1) {
} else if (SCConfGetNonNull("pfring.cluster-id", &tmpclusterid) != 1) {
SCLogError("Could not get cluster-id from config");
} else {
if (StringParseInt32(&pfconf->cluster_id, 10, 0, (const char *)tmpclusterid) < 0) {
Expand All @@ -152,7 +152,7 @@ static void *OldParsePfringConfig(const char *iface)
} else if ((pfconf->threads == 1) && (strncmp(pfconf->iface, "dna", 3) == 0)) {
SCLogInfo(
"%s: DNA interface detected, not setting cluster type for PF_RING", pfconf->iface);
} else if (SCConfGet("pfring.cluster-type", &tmpctype) != 1) {
} else if (SCConfGetNonNull("pfring.cluster-type", &tmpctype) != 1) {
SCLogError("Could not get cluster-type from config");
} else if (strcmp(tmpctype, "cluster_round_robin") == 0) {
SCLogInfo("%s: Using round-robin cluster mode for PF_RING", pfconf->iface);
Expand Down Expand Up @@ -275,7 +275,7 @@ static void *ParsePfringConfig(const char *iface)
(void)SC_ATOMIC_ADD(pfconf->ref, pfconf->threads);

/* command line value has precedence */
if (SCConfGet("pfring.cluster-id", &tmpclusterid) == 1) {
if (SCConfGetNonNull("pfring.cluster-id", &tmpclusterid) == 1) {
if (StringParseInt32(&pfconf->cluster_id, 10, 0, (const char *)tmpclusterid) < 0) {
SCLogWarning("Invalid value for "
"pfring.cluster-id: '%s'. Resetting to 1.",
Expand Down Expand Up @@ -425,7 +425,7 @@ static int GetDevAndParser(const char **live_dev, ConfigIfaceParserFunc *parser)
*parser = OldParsePfringConfig;
/* In v1: try to get interface name from config */
if (*live_dev == NULL) {
if (SCConfGet("pfring.interface", live_dev) == 1) {
if (SCConfGetNonNull("pfring.interface", live_dev) == 1) {
SCLogInfo("Using interface %s", *live_dev);
LiveRegisterDevice(*live_dev);
} else {
Expand Down
5 changes: 5 additions & 0 deletions rust/sys/src/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ extern "C" {
name: *const ::std::os::raw::c_char, vptr: *mut *const ::std::os::raw::c_char,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn SCConfGetNonNull(
name: *const ::std::os::raw::c_char, vptr: *mut *const ::std::os::raw::c_char,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn SCConfGetInt(
name: *const ::std::os::raw::c_char, val: *mut intmax_t,
Expand Down
2 changes: 1 addition & 1 deletion src/app-layer-htp-mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void HTPParseMemcap(void)

/** set config values for memcap, prealloc and hash_size */
uint64_t memcap;
if ((SCConfGet("app-layer.protocols.http.memcap", &conf_val)) == 1) {
if ((SCConfGetNonNull("app-layer.protocols.http.memcap", &conf_val)) == 1) {
if (ParseSizeStringU64(conf_val, &memcap) < 0) {
SCLogError("Error parsing http.memcap "
"from conf file - %s. Killing engine",
Expand Down
4 changes: 2 additions & 2 deletions src/app-layer-htp-range.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ void HttpRangeContainersInit(void)
const char *str = NULL;
uint64_t memcap = HTTP_RANGE_DEFAULT_MEMCAP;
uint32_t timeout = HTTP_RANGE_DEFAULT_TIMEOUT;
if (SCConfGet("app-layer.protocols.http.byterange.memcap", &str) == 1) {
if (SCConfGetNonNull("app-layer.protocols.http.byterange.memcap", &str) == 1) {
if (ParseSizeStringU64(str, &memcap) < 0) {
SCLogWarning("memcap value cannot be deduced: %s,"
" resetting to default",
str);
memcap = 0;
}
}
if (SCConfGet("app-layer.protocols.http.byterange.timeout", &str) == 1) {
if (SCConfGetNonNull("app-layer.protocols.http.byterange.timeout", &str) == 1) {
size_t slen = strlen(str);
if (slen > UINT16_MAX || StringParseUint32(&timeout, 10, (uint16_t)slen, str) <= 0) {
SCLogWarning("timeout value cannot be deduced: %s,"
Expand Down
2 changes: 1 addition & 1 deletion src/app-layer-smtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ static void SMTPConfigure(void) {
uint64_t value = SMTP_DEFAULT_MAX_TX;
smtp_config.max_tx = SMTP_DEFAULT_MAX_TX;
const char *str = NULL;
if (SCConfGet("app-layer.protocols.smtp.max-tx", &str) == 1) {
if (SCConfGetNonNull("app-layer.protocols.smtp.max-tx", &str) == 1) {
if (ParseSizeStringU64(str, &value) < 0) {
SCLogWarning("max-tx value cannot be deduced: %s,"
" keeping default",
Expand Down
2 changes: 1 addition & 1 deletion src/app-layer-ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void RegisterSSHParsers(void)
/* Check if we should generate Hassh fingerprints */
int enable_hassh = SSH_CONFIG_DEFAULT_HASSH;
const char *strval = NULL;
if (SCConfGet("app-layer.protocols.ssh.hassh", &strval) != 1) {
if (SCConfGetNonNull("app-layer.protocols.ssh.hassh", &strval) != 1) {
enable_hassh = SSH_CONFIG_DEFAULT_HASSH;
} else if (strcmp(strval, "auto") == 0) {
enable_hassh = SSH_CONFIG_DEFAULT_HASSH;
Expand Down
4 changes: 2 additions & 2 deletions src/app-layer-ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3137,7 +3137,7 @@ static void CheckJA3Enabled(void)
const char *strval = NULL;
/* Check if we should generate JA3 fingerprints */
int enable_ja3 = SSL_CONFIG_DEFAULT_JA3;
if (SCConfGet("app-layer.protocols.tls.ja3-fingerprints", &strval) != 1) {
if (SCConfGetNonNull("app-layer.protocols.tls.ja3-fingerprints", &strval) != 1) {
enable_ja3 = SSL_CONFIG_DEFAULT_JA3;
} else if (strcmp(strval, "auto") == 0) {
enable_ja3 = SSL_CONFIG_DEFAULT_JA3;
Expand All @@ -3162,7 +3162,7 @@ static void CheckJA4Enabled(void)
const char *strval = NULL;
/* Check if we should generate JA4 fingerprints */
int enable_ja4 = SSL_CONFIG_DEFAULT_JA4;
if (SCConfGet("app-layer.protocols.tls.ja4-fingerprints", &strval) != 1) {
if (SCConfGetNonNull("app-layer.protocols.tls.ja4-fingerprints", &strval) != 1) {
enable_ja4 = SSL_CONFIG_DEFAULT_JA4;
} else if (strcmp(strval, "auto") == 0) {
enable_ja4 = SSL_CONFIG_DEFAULT_JA4;
Expand Down
30 changes: 27 additions & 3 deletions src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,30 @@ int SCConfGet(const char *name, const char **vptr)
}
}

/**
* \brief Retrieve the non-null value of a configuration node.
*
* This function will return the value for a configuration node based
* on the full name of the node. If the value were NULL, return 0
* (this could happen if the requested node does exist but is not a node
* that contains a value, but contains children SCConfNodes instead.)
*
* \param name Name of configuration parameter to get.
* \param vptr Pointer that will be set to the configuration value parameter.
* Note that this is just a reference to the actual value, not a copy.
*
* \retval 1 will be returned if the value is found, otherwise 0 will
* be returned.
*/
int SCConfGetNonNull(const char *name, const char **vptr)
{
int r = SCConfGet(name, vptr);
if (r == 1 && *vptr == NULL) {
return 0;
}
return r;
}

int SCConfGetChildValue(const SCConfNode *base, const char *name, const char **vptr)
{
SCConfNode *node = SCConfNodeLookupChild(base, name);
Expand Down Expand Up @@ -500,7 +524,7 @@ int SCConfGetBool(const char *name, int *val)
const char *strval = NULL;

*val = 0;
if (SCConfGet(name, &strval) != 1)
if (SCConfGetNonNull(name, &strval) != 1)
return 0;

*val = SCConfValIsTrue(strval);
Expand Down Expand Up @@ -604,7 +628,7 @@ int SCConfGetDouble(const char *name, double *val)
double tmpdo;
char *endptr;

if (SCConfGet(name, &strval) == 0)
if (SCConfGetNonNull(name, &strval) == 0)
return 0;

errno = 0;
Expand Down Expand Up @@ -634,7 +658,7 @@ int SCConfGetFloat(const char *name, float *val)
double tmpfl;
char *endptr;

if (SCConfGet(name, &strval) == 0)
if (SCConfGetNonNull(name, &strval) == 0)
return 0;

errno = 0;
Expand Down
1 change: 1 addition & 0 deletions src/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void SCConfInit(void);
void SCConfDeInit(void);
SCConfNode *SCConfGetRootNode(void);
int SCConfGet(const char *name, const char **vptr);
int SCConfGetNonNull(const char *name, const char **vptr);
int SCConfGetInt(const char *name, intmax_t *val);
int SCConfGetBool(const char *name, int *val);
int SCConfGetDouble(const char *name, double *val);
Expand Down
2 changes: 1 addition & 1 deletion src/counters.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ static void StatsInitCtxPreOutput(void)
}

const char *prefix = NULL;
if (SCConfGet("stats.decoder-events-prefix", &prefix) != 1) {
if (SCConfGetNonNull("stats.decoder-events-prefix", &prefix) != 1) {
prefix = "decoder.event";
}
stats_decoder_events_prefix = prefix;
Expand Down
8 changes: 4 additions & 4 deletions src/datasets.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ void DatasetPostReloadCleanup(void)
void DatasetGetDefaultMemcap(uint64_t *memcap, uint32_t *hashsize)
{
const char *str = NULL;
if (SCConfGet("datasets.defaults.memcap", &str) == 1) {
if (SCConfGetNonNull("datasets.defaults.memcap", &str) == 1) {
if (ParseSizeStringU64(str, memcap) < 0) {
SCLogWarning("memcap value cannot be deduced: %s,"
" resetting to default",
Expand All @@ -605,7 +605,7 @@ void DatasetGetDefaultMemcap(uint64_t *memcap, uint32_t *hashsize)
}

*hashsize = (uint32_t)DATASETS_HASHSIZE_DEFAULT;
if (SCConfGet("datasets.defaults.hashsize", &str) == 1) {
if (SCConfGetNonNull("datasets.defaults.hashsize", &str) == 1) {
if (ParseSizeStringU32(str, hashsize) < 0) {
*hashsize = (uint32_t)DATASETS_HASHSIZE_DEFAULT;
SCLogWarning("hashsize value cannot be deduced: %s,"
Expand All @@ -624,12 +624,12 @@ int DatasetsInit(void)
DatasetGetDefaultMemcap(&default_memcap, &default_hashsize);
if (datasets != NULL) {
const char *str = NULL;
if (SCConfGet("datasets.limits.total-hashsizes", &str) == 1) {
if (SCConfGetNonNull("datasets.limits.total-hashsizes", &str) == 1) {
if (ParseSizeStringU32(str, &dataset_max_total_hashsize) < 0) {
FatalError("failed to parse datasets.limits.total-hashsizes value: %s", str);
}
}
if (SCConfGet("datasets.limits.single-hashsize", &str) == 1) {
if (SCConfGetNonNull("datasets.limits.single-hashsize", &str) == 1) {
if (ParseSizeStringU32(str, &dataset_max_one_hashsize) < 0) {
FatalError("failed to parse datasets.limits.single-hashsize value: %s", str);
}
Expand Down
8 changes: 4 additions & 4 deletions src/defrag-hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void DefragInitConfig(bool quiet)

uint64_t defrag_memcap;
/** set config values for memcap, prealloc and hash_size */
if ((SCConfGet("defrag.memcap", &conf_val)) == 1) {
if ((SCConfGetNonNull("defrag.memcap", &conf_val)) == 1) {
if (ParseSizeStringU64(conf_val, &defrag_memcap) < 0) {
SCLogError("Error parsing defrag.memcap "
"from conf file - %s. Killing engine",
Expand All @@ -198,7 +198,7 @@ void DefragInitConfig(bool quiet)
SC_ATOMIC_SET(defrag_config.memcap, defrag_memcap);
}
}
if ((SCConfGet("defrag.hash-size", &conf_val)) == 1) {
if ((SCConfGetNonNull("defrag.hash-size", &conf_val)) == 1) {
if (StringParseUint32(&configval, 10, strlen(conf_val),
conf_val) > 0) {
defrag_config.hash_size = configval;
Expand All @@ -207,7 +207,7 @@ void DefragInitConfig(bool quiet)
}
}

if ((SCConfGet("defrag.trackers", &conf_val)) == 1) {
if ((SCConfGetNonNull("defrag.trackers", &conf_val)) == 1) {
if (StringParseUint32(&configval, 10, strlen(conf_val),
conf_val) > 0) {
defrag_config.prealloc = configval;
Expand Down Expand Up @@ -250,7 +250,7 @@ void DefragInitConfig(bool quiet)
(uintmax_t)sizeof(DefragTrackerHashRow));
}

if ((SCConfGet("defrag.prealloc", &conf_val)) == 1) {
if ((SCConfGetNonNull("defrag.prealloc", &conf_val)) == 1) {
if (SCConfValIsTrue(conf_val)) {
/* pre allocate defrag trackers */
for (i = 0; i < defrag_config.prealloc; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/detect-engine-threshold.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ static int ThresholdsInit(struct Thresholds *t)
uint64_t memcap = 16 * 1024 * 1024;

const char *str;
if (SCConfGet("detect.thresholds.memcap", &str) == 1) {
if (SCConfGetNonNull("detect.thresholds.memcap", &str) == 1) {
if (ParseSizeStringU64(str, &memcap) < 0) {
SCLogError("Error parsing detect.thresholds.memcap from conf file - %s", str);
return -1;
Expand Down
2 changes: 1 addition & 1 deletion src/detect-engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -4464,7 +4464,7 @@ int DetectEngineMultiTenantSetup(const bool unix_socket)
master->multi_tenant_enabled = 1;

const char *handler = NULL;
if (SCConfGet("multi-detect.selector", &handler) == 1) {
if (SCConfGetNonNull("multi-detect.selector", &handler) == 1) {
SCLogConfig("multi-tenant selector type %s", handler);

if (strcmp(handler, "vlan") == 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/detect-uricontent.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ int DetectUricontentSetup(DetectEngineCtx *de_ctx, Signature *s, const char *con
SCEnter();

const char *legacy = NULL;
if (SCConfGet("legacy.uricontent", &legacy) == 1) {
if (SCConfGetNonNull("legacy.uricontent", &legacy) == 1) {
if (strcasecmp("disabled", legacy) == 0) {
SCLogError("uricontent deprecated. To "
"use a rule with \"uricontent\", either set the "
Expand Down
6 changes: 3 additions & 3 deletions src/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void HostInitConfig(bool quiet)
uint32_t configval = 0;

/** set config values for memcap, prealloc and hash_size */
if ((SCConfGet("host.memcap", &conf_val)) == 1) {
if ((SCConfGetNonNull("host.memcap", &conf_val)) == 1) {
uint64_t host_memcap = 0;
if (ParseSizeStringU64(conf_val, &host_memcap) < 0) {
SCLogError("Error parsing host.memcap "
Expand All @@ -203,14 +203,14 @@ void HostInitConfig(bool quiet)
SC_ATOMIC_SET(host_config.memcap, host_memcap);
}
}
if ((SCConfGet("host.hash-size", &conf_val)) == 1) {
if ((SCConfGetNonNull("host.hash-size", &conf_val)) == 1) {
if (StringParseUint32(&configval, 10, strlen(conf_val),
conf_val) > 0) {
host_config.hash_size = configval;
}
}

if ((SCConfGet("host.prealloc", &conf_val)) == 1) {
if ((SCConfGetNonNull("host.prealloc", &conf_val)) == 1) {
if (StringParseUint32(&configval, 10, strlen(conf_val),
conf_val) > 0) {
host_config.prealloc = configval;
Expand Down
6 changes: 3 additions & 3 deletions src/ippair.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void IPPairInitConfig(bool quiet)

/** set config values for memcap, prealloc and hash_size */
uint64_t ippair_memcap;
if ((SCConfGet("ippair.memcap", &conf_val)) == 1) {
if ((SCConfGetNonNull("ippair.memcap", &conf_val)) == 1) {
if (ParseSizeStringU64(conf_val, &ippair_memcap) < 0) {
SCLogError("Error parsing ippair.memcap "
"from conf file - %s. Killing engine",
Expand All @@ -197,14 +197,14 @@ void IPPairInitConfig(bool quiet)
SC_ATOMIC_SET(ippair_config.memcap, ippair_memcap);
}
}
if ((SCConfGet("ippair.hash-size", &conf_val)) == 1) {
if ((SCConfGetNonNull("ippair.hash-size", &conf_val)) == 1) {
if (StringParseUint32(&configval, 10, strlen(conf_val),
conf_val) > 0) {
ippair_config.hash_size = configval;
}
}

if ((SCConfGet("ippair.prealloc", &conf_val)) == 1) {
if ((SCConfGetNonNull("ippair.prealloc", &conf_val)) == 1) {
if (StringParseUint32(&configval, 10, strlen(conf_val),
conf_val) > 0) {
ippair_config.prealloc = configval;
Expand Down
2 changes: 1 addition & 1 deletion src/reputation.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ static char *SRepCompleteFilePath(char *file)

/* Path not specified */
if (PathIsRelative(file)) {
if (SCConfGet("default-reputation-path", &defaultpath) == 1) {
if (SCConfGetNonNull("default-reputation-path", &defaultpath) == 1) {
SCLogDebug("Default path: %s", defaultpath);
size_t path_len = sizeof(char) * (strlen(defaultpath) +
strlen(file) + 2);
Expand Down
4 changes: 2 additions & 2 deletions src/runmode-erf-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int RunModeErfFileSingle(void)

SCEnter();

if (SCConfGet("erf-file.file", &file) == 0) {
if (SCConfGetNonNull("erf-file.file", &file) == 0) {
FatalError("Failed to get erf-file.file from config.");
}

Expand Down Expand Up @@ -110,7 +110,7 @@ int RunModeErfFileAutoFp(void)
uint16_t thread;

const char *file = NULL;
if (SCConfGet("erf-file.file", &file) == 0) {
if (SCConfGetNonNull("erf-file.file", &file) == 0) {
FatalError("Failed retrieving erf-file.file from config");
}

Expand Down
4 changes: 2 additions & 2 deletions src/runmode-pcap-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int RunModeFilePcapSingle(void)
const char *file = NULL;
char tname[TM_THREAD_NAME_MAX];

if (SCConfGet("pcap-file.file", &file) == 0) {
if (SCConfGetNonNull("pcap-file.file", &file) == 0) {
FatalError("Failed retrieving pcap-file from Conf");
}

Expand Down Expand Up @@ -125,7 +125,7 @@ int RunModeFilePcapAutoFp(void)
uint16_t thread;

const char *file = NULL;
if (SCConfGet("pcap-file.file", &file) == 0) {
if (SCConfGetNonNull("pcap-file.file", &file) == 0) {
FatalError("Failed retrieving pcap-file from Conf");
}
SCLogDebug("file %s", file);
Expand Down
2 changes: 1 addition & 1 deletion src/runmode-pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static void *ParsePcapConfig(const char *iface)

aconf->checksum_mode = CHECKSUM_VALIDATION_AUTO;
aconf->bpf_filter = NULL;
if ((SCConfGet("bpf-filter", &tmpbpf)) == 1) {
if ((SCConfGetNonNull("bpf-filter", &tmpbpf)) == 1) {
aconf->bpf_filter = tmpbpf;
}

Expand Down
2 changes: 1 addition & 1 deletion src/source-nfq.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void NFQInitConfig(bool quiet)

memset(&nfq_config, 0, sizeof(nfq_config));

if ((SCConfGet("nfq.mode", &nfq_mode)) == 0) {
if ((SCConfGetNonNull("nfq.mode", &nfq_mode)) == 0) {
nfq_config.mode = NFQ_ACCEPT_MODE;
} else {
if (!strcmp("accept", nfq_mode)) {
Expand Down
Loading
Loading