Go to the documentation of this file.
45 #define DETECT_DATASET_CMD_SET 0
46 #define DETECT_DATASET_CMD_UNSET 1
47 #define DETECT_DATASET_CMD_ISNOTSET 2
48 #define DETECT_DATASET_CMD_ISSET 3
71 const uint8_t *data,
const uint32_t data_len)
73 if (data == NULL || data_len == 0)
112 static int DetectDatasetParse(
const char *
str,
char *cmd,
int cmd_len,
char *name,
int name_len,
113 enum DatasetTypes *
type,
char *load,
size_t load_size,
char *save,
size_t save_size,
114 uint64_t *memcap, uint32_t *
hashsize)
116 bool cmd_set =
false;
117 bool name_set =
false;
118 bool load_set =
false;
119 bool save_set =
false;
120 bool state_set =
false;
122 char copy[strlen(
str)+1];
124 char *xsaveptr = NULL;
125 char *key = strtok_r(copy,
",", &xsaveptr);
126 while (key != NULL) {
127 while (*key !=
'\0' && isblank(*key)) {
130 char *val = strchr(key,
' ');
133 while (*val !=
'\0' && isblank(*val)) {
141 if (strlen(key) == 0) {
146 if (val && strlen(val) != 0) {
151 }
else if (!name_set) {
152 if (val && strlen(val) != 0) {
162 if (strcmp(key,
"type") == 0) {
165 if (strcmp(val,
"md5") == 0) {
167 }
else if (strcmp(val,
"sha256") == 0) {
169 }
else if (strcmp(val,
"string") == 0) {
171 }
else if (strcmp(val,
"ipv4") == 0) {
173 }
else if (strcmp(val,
"ipv6") == 0) {
175 }
else if (strcmp(val,
"ip") == 0) {
182 }
else if (strcmp(key,
"save") == 0) {
190 }
else if (strcmp(key,
"load") == 0) {
198 }
else if (strcmp(key,
"state") == 0) {
208 if (strcmp(key,
"memcap") == 0) {
211 " resetting to default",
216 if (strcmp(key,
"hashsize") == 0) {
219 " resetting to default",
229 key = strtok_r(NULL,
",", &xsaveptr);
232 if ((load_set || save_set) && state_set) {
233 SCLogWarning(
"'state' can not be mixed with 'load' and 'save'");
238 while (strlen(name) > 0 && isblank(name[strlen(name) - 1])) {
239 name[strlen(name) - 1] =
'\0';
243 for (
size_t i = 0; i < strlen(name); i++) {
244 if (isblank(name[i])) {
245 SCLogError(
"spaces not allowed in dataset names");
254 static void GetDirName(
const char *in,
char *out,
size_t outs)
256 if (strlen(in) == 0) {
260 size_t size = strlen(in) + 1;
264 char *dir = dirname(tmp);
270 char *load,
size_t load_size)
282 char dir[PATH_MAX] =
"";
287 if (snprintf(path,
sizeof(path),
"%s/%s", dir, load) >= (
int)
sizeof(path))
292 strlcpy(load, path, load_size);
293 SCLogDebug(
"using path '%s' (HAVE_LIBGEN_H)", load);
304 strlcpy(load, loadp, load_size);
305 SCLogDebug(
"using path '%s' (non-HAVE_LIBGEN_H)", load);
313 char *save,
size_t save_size)
318 if (
ConfGetBool(
"datasets.rules.allow-write", &allow_save)) {
320 SCLogError(
"Rules containing save/state datasets have been disabled");
325 int allow_absolute = 0;
326 (void)
ConfGetBool(
"datasets.rules.allow-absolute-filenames", &allow_absolute);
327 if (allow_absolute) {
328 SCLogNotice(
"Allowing absolute filename for dataset rule: %s", save);
331 SCLogError(
"Absolute paths not allowed: %s", save);
336 SCLogError(
"Directory traversals not allowed: %s", save);
345 if (snprintf(path,
sizeof(path),
"%s/%s", dir, save) >= (
int)
sizeof(path))
350 strlcpy(save, path, save_size);
363 char load[PATH_MAX] =
"";
364 char save[PATH_MAX] =
"";
367 SCLogError(
"datasets are only supported for sticky buffers");
373 SCLogError(
"datasets are only supported for sticky buffers");
377 if (!DetectDatasetParse(rawstr, cmd_str,
sizeof(cmd_str), name,
sizeof(name), &
type, load,
378 sizeof(load), save,
sizeof(save), &memcap, &
hashsize)) {
382 if (strcmp(cmd_str,
"isset") == 0) {
384 }
else if (strcmp(cmd_str,
"isnotset") == 0) {
386 }
else if (strcmp(cmd_str,
"set") == 0) {
388 }
else if (strcmp(cmd_str,
"unset") == 0) {
391 SCLogError(
"dataset action \"%s\" is not supported.", cmd_str);
397 if (strlen(save) == 0 && strlen(load) != 0) {
398 if (SetupLoadPath(
de_ctx, load,
sizeof(load)) != 0)
402 }
else if (strlen(save) != 0 && strlen(load) == 0) {
403 if (SetupSavePath(
de_ctx, save,
sizeof(save)) != 0)
407 }
else if (strlen(save) != 0 && strlen(load) != 0 &&
408 strcmp(save, load) == 0) {
409 if (SetupSavePath(
de_ctx, save,
sizeof(save)) != 0)
411 strlcpy(load, save,
sizeof(load));
414 SCLogDebug(
"name '%s' load '%s' save '%s'", name, load, save);
417 SCLogError(
"failed to set up dataset '%s'.", name);
429 cmd_str, strlen(name) ? name :
"(none)");
SigTableElmt * sigmatch_table
void(* Free)(DetectEngineCtx *, void *)
int ConfGetBool(const char *name, int *val)
Retrieve a configuration value as a boolean.
#define DETECT_DATASET_CMD_SET
int ParseSizeStringU64(const char *size, uint64_t *res)
struct HtpBodyChunk_ * next
main detection engine ctx
const char * ConfigGetDataDirectory(void)
int DetectBufferGetActiveList(DetectEngineCtx *de_ctx, Signature *s)
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
#define DETECT_DATASET_CMD_ISSET
size_t strlcpy(char *dst, const char *src, size_t siz)
Dataset * DatasetGet(const char *name, enum DatasetTypes type, const char *save, const char *load, uint64_t memcap, uint32_t hashsize)
bool SCPathContainsTraversal(const char *path)
Check for directory traversal.
int DatasetRemove(Dataset *set, const uint8_t *data, const uint32_t data_len)
int DatasetAdd(Dataset *set, const uint8_t *data, const uint32_t data_len)
void DetectDatasetFree(DetectEngineCtx *, void *)
#define DATASET_TYPE_NOTSET
Per thread variable structure.
#define SCLogWarning(...)
Macro used to log WARNING messages.
void DetectDatasetRegister(void)
SignatureInitData * init_data
int DatasetLookup(Dataset *set, const uint8_t *data, const uint32_t data_len)
see if data is part of the set
Data structures and function prototypes for keeping state for the detection engine.
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
#define DETECT_SM_LIST_NOTSET
bool SCPathExists(const char *path)
Check if a path exists.
int DetectDatasetBufferMatch(DetectEngineThreadCtx *det_ctx, const DetectDatasetData *sd, const uint8_t *data, const uint32_t data_len)
#define DATASET_NAME_MAX_LEN
#define DETECT_DATASET_CMD_UNSET
int PathIsAbsolute(const char *path)
Check if a path is absolute.
int ParseSizeStringU32(const char *size, uint32_t *res)
#define SCLogError(...)
Macro used to log ERROR messages.
#define DETECT_DATASET_CMD_ISNOTSET
char * DetectLoadCompleteSigPath(const DetectEngineCtx *de_ctx, const char *sig_file)
Create the path if default-rule-path was specified.
SigMatch * SigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
int DetectDatasetMatch(ThreadVars *, DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
#define SCLogNotice(...)
Macro used to log NOTICE messages.
#define DEBUG_VALIDATE_BUG_ON(exp)