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
69 const uint8_t *data,
const uint32_t data_len)
71 if (data == NULL || data_len == 0)
110 static int DetectDatasetParse(
const char *
str,
char *cmd,
int cmd_len,
char *
name,
int name_len,
111 enum DatasetTypes *
type,
char *load,
size_t load_size,
char *save,
size_t save_size,
112 uint64_t *memcap, uint32_t *
hashsize)
114 bool cmd_set =
false;
115 bool name_set =
false;
116 bool load_set =
false;
117 bool save_set =
false;
118 bool state_set =
false;
120 char copy[strlen(
str)+1];
122 char *xsaveptr = NULL;
123 char *key = strtok_r(copy,
",", &xsaveptr);
124 while (key != NULL) {
125 while (*key !=
'\0' && isblank(*key)) {
128 char *val = strchr(key,
' ');
131 while (*val !=
'\0' && isblank(*val)) {
139 if (strlen(key) == 0) {
144 if (val && strlen(val) != 0) {
149 }
else if (!name_set) {
150 if (val && strlen(val) != 0) {
160 if (strcmp(key,
"type") == 0) {
163 if (strcmp(val,
"md5") == 0) {
165 }
else if (strcmp(val,
"sha256") == 0) {
167 }
else if (strcmp(val,
"string") == 0) {
169 }
else if (strcmp(val,
"ipv4") == 0) {
171 }
else if (strcmp(val,
"ipv6") == 0) {
173 }
else if (strcmp(val,
"ip") == 0) {
180 }
else if (strcmp(key,
"save") == 0) {
188 }
else if (strcmp(key,
"load") == 0) {
196 }
else if (strcmp(key,
"state") == 0) {
206 if (strcmp(key,
"memcap") == 0) {
209 " resetting to default",
214 if (strcmp(key,
"hashsize") == 0) {
217 " resetting to default",
227 key = strtok_r(NULL,
",", &xsaveptr);
230 if ((load_set || save_set) && state_set) {
231 SCLogWarning(
"'state' can not be mixed with 'load' and 'save'");
236 while (strlen(
name) > 0 && isblank(
name[strlen(
name) - 1])) {
241 for (
size_t i = 0; i < strlen(
name); i++) {
242 if (isblank(
name[i])) {
243 SCLogError(
"spaces not allowed in dataset names");
252 static void GetDirName(
const char *in,
char *out,
size_t outs)
254 if (strlen(in) == 0) {
258 size_t size = strlen(in) + 1;
262 char *dir = dirname(tmp);
268 char *load,
size_t load_size)
280 char dir[PATH_MAX] =
"";
285 if (snprintf(path,
sizeof(path),
"%s/%s", dir, load) >= (
int)
sizeof(path))
290 strlcpy(load, path, load_size);
291 SCLogDebug(
"using path '%s' (HAVE_LIBGEN_H)", load);
302 strlcpy(load, loadp, load_size);
303 SCLogDebug(
"using path '%s' (non-HAVE_LIBGEN_H)", load);
311 char *save,
size_t save_size)
316 if (
ConfGetBool(
"datasets.rules.allow-write", &allow_save)) {
318 SCLogError(
"Rules containing save/state datasets have been disabled");
323 int allow_absolute = 0;
324 (void)
ConfGetBool(
"datasets.rules.allow-absolute-filenames", &allow_absolute);
325 if (allow_absolute) {
326 SCLogNotice(
"Allowing absolute filename for dataset rule: %s", save);
329 SCLogError(
"Absolute paths not allowed: %s", save);
334 SCLogError(
"Directory traversals not allowed: %s", save);
343 if (snprintf(path,
sizeof(path),
"%s/%s", dir, save) >= (
int)
sizeof(path))
348 strlcpy(save, path, save_size);
361 char load[PATH_MAX] =
"";
362 char save[PATH_MAX] =
"";
365 SCLogError(
"datasets are only supported for sticky buffers");
371 SCLogError(
"datasets are only supported for sticky buffers");
375 if (!DetectDatasetParse(rawstr, cmd_str,
sizeof(cmd_str),
name,
sizeof(
name), &
type, load,
376 sizeof(load), save,
sizeof(save), &memcap, &
hashsize)) {
380 if (strcmp(cmd_str,
"isset") == 0) {
382 }
else if (strcmp(cmd_str,
"isnotset") == 0) {
384 }
else if (strcmp(cmd_str,
"set") == 0) {
386 }
else if (strcmp(cmd_str,
"unset") == 0) {
389 SCLogError(
"dataset action \"%s\" is not supported.", cmd_str);
395 if (strlen(save) == 0 && strlen(load) != 0) {
396 if (SetupLoadPath(
de_ctx, load,
sizeof(load)) != 0)
400 }
else if (strlen(save) != 0 && strlen(load) == 0) {
401 if (SetupSavePath(
de_ctx, save,
sizeof(save)) != 0)
405 }
else if (strlen(save) != 0 && strlen(load) != 0 &&
406 strcmp(save, load) == 0) {
407 if (SetupSavePath(
de_ctx, save,
sizeof(save)) != 0)
409 strlcpy(load, save,
sizeof(load));
427 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
#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.
#define SCLogNotice(...)
Macro used to log NOTICE messages.
#define DEBUG_VALIDATE_BUG_ON(exp)