detect/filehash: try to open data file from rulefile dir

If the data file can't be found in the default location, which
normally is 'default-rule-path', try to see if it can be found
in the path of the rule file that references it.

This makes QA much easier.
pull/3457/head
Victor Julien 8 years ago
parent 39ca1db8e8
commit 6ffa0507d2

@ -133,6 +133,7 @@
AC_CHECK_HEADERS([sys/resource.h sys/types.h sys/un.h])
AC_CHECK_HEADERS([sys/random.h])
AC_CHECK_HEADERS([utime.h])
AC_CHECK_HEADERS([libgen.h])
AC_CHECK_HEADERS([sys/socket.h net/if.h sys/mman.h linux/if_arp.h], [], [],
[[#ifdef HAVE_SYS_SOCKET_H

@ -239,8 +239,27 @@ static DetectFileHashData *DetectFileHashParse (const DetectEngineCtx *de_ctx,
char line[8192] = "";
fp = fopen(filename, "r");
if (fp == NULL) {
SCLogError(SC_ERR_OPENING_RULE_FILE, "opening hash file %s: %s", filename, strerror(errno));
goto error;
#ifdef HAVE_LIBGEN_H
if (de_ctx->rule_file != NULL) {
char *dir = dirname(de_ctx->rule_file);
if (dir != NULL) {
char path[PATH_MAX];
snprintf(path, sizeof(path), "%s/%s", dir, str);
fp = fopen(path, "r");
if (fp == NULL) {
SCLogError(SC_ERR_OPENING_RULE_FILE,
"opening hash file %s: %s", path, strerror(errno));
goto error;
}
}
}
if (fp == NULL) {
#endif
SCLogError(SC_ERR_OPENING_RULE_FILE, "opening hash file %s: %s", filename, strerror(errno));
goto error;
#ifdef HAVE_LIBGEN_H
}
#endif
}
int line_no = 0;

@ -202,6 +202,10 @@
#include <utime.h>
#endif
#ifdef HAVE_LIBGEN_H
#include <libgen.h>
#endif
#if __CYGWIN__
#if !defined _X86_ && !defined __x86_64
#define _X86_

Loading…
Cancel
Save