Go to the documentation of this file.
44 #define PARSE_REGEX "([a-z]+)(?:,\\s*([\\-_A-z0-9\\s\\.]+)){1,4}"
70 const uint8_t *data,
const uint32_t data_len)
72 if (data == NULL || data_len == 0)
96 static int DetectDatarepParse(
const char *
str,
char *cmd,
int cmd_len,
char *name,
int name_len,
98 uint64_t *memcap, uint32_t *
hashsize)
100 bool cmd_set =
false;
101 bool name_set =
false;
102 bool value_set =
false;
104 char copy[strlen(
str)+1];
106 char *xsaveptr = NULL;
107 char *key = strtok_r(copy,
",", &xsaveptr);
108 while (key != NULL) {
109 while (*key !=
'\0' && isblank(*key)) {
112 char *val = strchr(key,
' ');
115 while (*val !=
'\0' && isblank(*val)) {
123 if (strlen(key) == 0) {
133 }
else if (!cmd_set) {
139 }
else if (!value_set) {
153 if (strcmp(key,
"type") == 0) {
156 if (strcmp(val,
"md5") == 0) {
158 }
else if (strcmp(val,
"sha256") == 0) {
160 }
else if (strcmp(val,
"string") == 0) {
162 }
else if (strcmp(val,
"ipv4") == 0) {
164 }
else if (strcmp(val,
"ip") == 0) {
166 }
else if (strcmp(val,
"ipv6") == 0) {
173 }
else if (strcmp(key,
"load") == 0) {
177 if (strcmp(key,
"memcap") == 0) {
180 " resetting to default",
185 if (strcmp(key,
"hashsize") == 0) {
188 " resetting to default",
198 key = strtok_r(NULL,
",", &xsaveptr);
202 SCLogError(
"if load is used type must be set as well");
206 if (!name_set || !cmd_set || !value_set) {
212 while (strlen(name) > 0 && isblank(name[strlen(name) - 1])) {
213 name[strlen(name) - 1] =
'\0';
217 for (
size_t i = 0; i < strlen(name); i++) {
218 if (isblank(name[i])) {
219 SCLogError(
"spaces not allowed in dataset names");
228 static void GetDirName(
const char *in,
char *out,
size_t outs)
230 if (strlen(in) == 0) {
234 size_t size = strlen(in) + 1;
238 char *dir = dirname(tmp);
244 char *load,
size_t load_size)
256 char dir[PATH_MAX] =
"";
261 if (snprintf(path,
sizeof(path),
"%s/%s", dir, load) >= (
int)
sizeof(path))
266 strlcpy(load, path, load_size);
267 SCLogDebug(
"using path '%s' (HAVE_LIBGEN_H)", load);
269 SCLogDebug(
"path '%s' does not exist (HAVE_LIBGEN_H)", path);
280 strlcpy(load, loadp, load_size);
281 SCLogDebug(
"using path '%s' (non-HAVE_LIBGEN_H)", load);
283 SCLogDebug(
"path '%s' does not exist (non-HAVE_LIBGEN_H)", loadp);
294 char cmd_str[16] =
"", name[64] =
"";
296 char load[PATH_MAX] =
"";
302 SCLogError(
"datarep is only supported for sticky buffers");
308 SCLogError(
"datarep is only supported for sticky buffers");
312 if (!DetectDatarepParse(rawstr, cmd_str,
sizeof(cmd_str), name,
sizeof(name), &
type, load,
313 sizeof(load), &value, &memcap, &
hashsize)) {
317 if (strlen(load) != 0) {
318 if (SetupLoadPath(
de_ctx, load,
sizeof(load)) != 0)
323 if (strcmp(cmd_str,
">") == 0) {
325 }
else if (strcmp(cmd_str,
"<") == 0) {
327 }
else if (strcmp(cmd_str,
"==") == 0) {
330 SCLogError(
"datarep operation \"%s\" is not supported.", cmd_str);
336 SCLogError(
"failed to set up datarep set '%s'.", name);
349 cmd_str, strlen(name) ? name :
"(none)");
SigTableElmt * sigmatch_table
void(* Free)(DetectEngineCtx *, void *)
int ParseSizeStringU64(const char *size, uint64_t *res)
struct HtpBodyChunk_ * next
int DetectDatarepMatch(ThreadVars *, DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
main detection engine ctx
int StringParseUint16(uint16_t *res, int base, size_t len, const char *str)
void DetectDatarepRegister(void)
int DetectBufferGetActiveList(DetectEngineCtx *de_ctx, Signature *s)
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
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)
#define DATASET_TYPE_NOTSET
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Per thread variable structure.
#define SCLogWarning(...)
Macro used to log WARNING messages.
SignatureInitData * init_data
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 DetectDatarepBufferMatch(DetectEngineThreadCtx *det_ctx, const DetectDatarepData *sd, const uint8_t *data, const uint32_t data_len)
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.
void DetectDatarepFree(DetectEngineCtx *, void *)
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.
DataRepResultType DatasetLookupwRep(Dataset *set, const uint8_t *data, const uint32_t data_len, const DataRepType *rep)