]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/filehash: try to open data file from rulefile dir
authorVictor Julien <victor@inliniac.net>
Tue, 14 Aug 2018 08:17:37 +0000 (10:17 +0200)
committerVictor Julien <victor@inliniac.net>
Mon, 20 Aug 2018 09:02:58 +0000 (11:02 +0200)
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.

configure.ac
src/detect-file-hash-common.c
src/suricata-common.h

index c43769075a6e44d2e0f7e630c415be76f63c7e24..98bbd32da467a5dfab782ecfa1efe975e8870267 100644 (file)
     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
index c9f7ab2918387fe88910d64e5dc286be2c4b9d5f..e3d84fc00c290fa0346bda1ecfa553eee19edc6e 100644 (file)
@@ -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;
index 29dd172e0205679bb1b74688d0a48129648e5647..245d43857355fdf6dc8f3fce57701d904742c521 100644 (file)
 #include <utime.h>
 #endif
 
+#ifdef HAVE_LIBGEN_H
+#include <libgen.h>
+#endif
+
 #if __CYGWIN__
 #if !defined _X86_ && !defined __x86_64
 #define _X86_