diff --git a/configure.ac b/configure.ac index 000cc68000..6cbea67890 100644 --- a/configure.ac +++ b/configure.ac @@ -215,7 +215,8 @@ fi echo -n "installation for $host OS... " - e_magic_file="/usr/share/file/magic" + e_magic_file="" + e_magic_file_comment="#" case "$host" in *-*-*freebsd*) LUA_PC_NAME="lua-5.1" @@ -223,14 +224,12 @@ CFLAGS="${CFLAGS} -DOS_FREEBSD" CPPFLAGS="${CPPFLAGS} -I/usr/local/include -I/usr/local/include/libnet11" LDFLAGS="${LDFLAGS} -L/usr/local/lib -L/usr/local/lib/libnet11" - e_magic_file="/usr/share/misc/magic" ;; *-*-openbsd*) LUA_PC_NAME="lua51" CFLAGS="${CFLAGS} -D__OpenBSD__" CPPFLAGS="${CPPFLAGS} -I/usr/local/include -I/usr/local/include/libnet-1.1" LDFLAGS="${LDFLAGS} -L/usr/local/lib -I/usr/local/lib/libnet-1.1" - e_magic_file="/usr/local/share/misc/magic.mgc" ;; *darwin*|*Darwin*) LUA_PC_NAME="lua-5.1" @@ -1810,6 +1809,7 @@ if test "$WINDOWS_PATH" = "yes"; then e_sysconfdir="$e_winbase\\\\" e_sysconfrulesdir="$e_winbase\\\\rules\\\\" e_magic_file="$e_winbase\\\\magic.mgc" + e_magic_file_comment="" e_logdir="$e_winbase\\\\log" e_logfilesdir="$e_logdir\\\\files" e_logcertsdir="$e_logdir\\\\certs" @@ -1831,6 +1831,7 @@ AC_SUBST(e_sysconfrulesdir) AC_SUBST(e_localstatedir) AC_DEFINE_UNQUOTED([CONFIG_DIR],["$e_sysconfdir"],[Our CONFIG_DIR]) AC_SUBST(e_magic_file) +AC_SUBST(e_magic_file_comment) EXPAND_VARIABLE(prefix, CONFIGURE_PREFIX) EXPAND_VARIABLE(sysconfdir, CONFIGURE_SYSCONDIR) diff --git a/src/detect-filemagic.c b/src/detect-filemagic.c index 5dd28ec819..ab85feed3e 100644 --- a/src/detect-filemagic.c +++ b/src/detect-filemagic.c @@ -322,13 +322,20 @@ static void *DetectFilemagicThreadInit(void *data) (void)ConfGet("magic-file", &filename); if (filename != NULL) { - SCLogInfo("using magic-file %s", filename); + if (strlen(filename) == 0) { + /* set filename to NULL on *nix systems so magic_load uses system default path (see man libmagic) */ + SCLogInfo("using system default magic-file"); + filename = NULL; + } + else { + SCLogInfo("using magic-file %s", filename); - if ( (fd = fopen(filename, "r")) == NULL) { - SCLogWarning(SC_ERR_FOPEN, "Error opening file: \"%s\": %s", filename, strerror(errno)); - goto error; + if ( (fd = fopen(filename, "r")) == NULL) { + SCLogWarning(SC_ERR_FOPEN, "Error opening file: \"%s\": %s", filename, strerror(errno)); + goto error; + } + fclose(fd); } - fclose(fd); } if (magic_load(t->ctx, filename) != 0) { diff --git a/src/util-magic.c b/src/util-magic.c index fa05c6d90e..bad15fbe5e 100644 --- a/src/util-magic.c +++ b/src/util-magic.c @@ -58,14 +58,23 @@ int MagicInit(void) } (void)ConfGet("magic-file", &filename); + + if (filename != NULL) { - SCLogInfo("using magic-file %s", filename); + if (strlen(filename) == 0) { + /* set filename to NULL on *nix systems so magic_load uses system default path (see man libmagic) */ + SCLogInfo("using system default magic-file"); + filename = NULL; + } + else { + SCLogInfo("using magic-file %s", filename); - if ( (fd = fopen(filename, "r")) == NULL) { - SCLogWarning(SC_ERR_FOPEN, "Error opening file: \"%s\": %s", filename, strerror(errno)); - goto error; + if ( (fd = fopen(filename, "r")) == NULL) { + SCLogWarning(SC_ERR_FOPEN, "Error opening file: \"%s\": %s", filename, strerror(errno)); + goto error; + } + fclose(fd); } - fclose(fd); } if (magic_load(g_magic_ctx, filename) != 0) { diff --git a/suricata.yaml.in b/suricata.yaml.in index 6614906f13..90f590915c 100644 --- a/suricata.yaml.in +++ b/suricata.yaml.in @@ -395,7 +395,7 @@ outputs: # Magic file. The extension .mgc is added to the value here. #magic-file: /usr/share/file/magic -magic-file: @e_magic_file@ +@e_magic_file_comment@magic-file: @e_magic_file@ # When running in NFQ inline mode, it is possible to use a simulated # non-terminal NFQUEUE verdict.