From: Michael Altizer (mialtize) Date: Wed, 5 Sep 2018 19:02:58 +0000 (-0400) Subject: Merge pull request #1353 in SNORT/snort3 from alpine to master X-Git-Tag: 3.0.0-248~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9a89f12d5422ff00231cb322560b640b09f2e43b;p=thirdparty%2Fsnort3.git Merge pull request #1353 in SNORT/snort3 from alpine to master Squashed commit of the following: commit 8bfe2663676b663fb4dad6788e8663e825f56f65 Author: Michael Altizer Date: Tue Sep 4 21:25:45 2018 -0400 build: Add libnsl and libsocket to Snort for Solaris builds Fixes Snort build on OpenIndiana. commit 42dccb76a6c0d504118e2c71a68aa71070b09b9c Author: Michael Altizer Date: Tue Sep 4 18:30:54 2018 -0400 build: Fall back on TI-RPC if no built-in RPC DB is found Necessary for getrpcent() on musl-based Linux systems. commit c70cd8e45e2227c2937d350ad05d82c39f05350c Author: Michael Altizer Date: Tue Sep 4 19:07:14 2018 -0400 daqs: Include unistd.h directly for better cross-platform compatibility commit cb2df1c310054404c80339ff2b4de072ba1ed551 Author: Michael Altizer Date: Tue Sep 4 15:32:45 2018 -0400 build: Introduce a more robust check for GNU strerror_r This should better handle the case where we're using alternative C libraries on Linux like musl. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index e6a01fb45..e06881f82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,6 +125,14 @@ else () LZMA: OFF") endif () +if (USE_TIRPC) + message("\ + RPC DB: TIRPC") +else () + message("\ + RPC DB: Built-in") +endif () + if (HAVE_SAFEC AND SAFEC_ENABLED) message("\ SafeC: ON") diff --git a/cmake/FindTIRPC.cmake b/cmake/FindTIRPC.cmake new file mode 100644 index 000000000..467cb4032 --- /dev/null +++ b/cmake/FindTIRPC.cmake @@ -0,0 +1,44 @@ +# FindTIRPC +# --------- +# +# Find the native TIRPC includes and library. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module will set the following variables in your project: +# +# ``TIRPC_INCLUDE_DIRS`` +# where to find rpc.h, etc. +# ``TIRPC_LIBRARIES`` +# the libraries to link against to use TIRPC. +# ``TIRPC_VERSION`` +# the version of TIRPC found. +# ``TIRPC_FOUND`` +# true if the TIRPC headers and libraries were found. +# + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_TIRPC libtirpc) + +find_path(TIRPC_INCLUDE_DIRS + NAMES netconfig.h + PATH_SUFFIXES tirpc + HINTS ${PC_TIRPC_INCLUDE_DIRS} +) + +find_library(TIRPC_LIBRARIES + NAMES tirpc + HINTS ${PC_TIRPC_LIBRARY_DIRS} +) + +set(TIRPC_VERSION ${PC_TIRPC_VERSION}) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(TIRPC + REQUIRED_VARS TIRPC_LIBRARIES TIRPC_INCLUDE_DIRS + VERSION_VAR TIRPC_VERSION +) + +mark_as_advanced(TIRPC_INCLUDE_DIRS TIRPC_LIBRARIES) diff --git a/cmake/sanity_checks.cmake b/cmake/sanity_checks.cmake index 4907516cb..f2b501e60 100644 --- a/cmake/sanity_checks.cmake +++ b/cmake/sanity_checks.cmake @@ -1,9 +1,9 @@ +include(CheckCXXSourceCompiles) include(CheckIncludeFileCXX) include(CheckFunctionExists) +include(CheckLibraryExists) include(CheckSymbolExists) include(CheckTypeSize) -include(CheckLibraryExists) -include(CheckCXXSourceCompiles) include (TestBigEndian) test_big_endian(WORDS_BIGENDIAN) @@ -17,6 +17,42 @@ check_function_exists(malloc_trim HAVE_MALLOC_TRIM) check_function_exists(memrchr HAVE_MEMRCHR) check_function_exists(sigaction HAVE_SIGACTION) +check_cxx_source_compiles( + " + #include + #include + + void check(char c) {} + + int main() + { + char buffer[1024]; + /* This will not compile if strerror_r does not return a char* */ + check(strerror_r(EACCES, buffer, sizeof(buffer))[0]); + return 0; + } + " + HAVE_GNU_STRERROR_R) + +# vvvvvvvvv GETRPCENT TEST vvvvvvvvv +cmake_push_check_state(RESET) +if ( CMAKE_SYSTEM_NAME STREQUAL SunOS ) + set(CMAKE_REQUIRED_LIBRARIES nsl) +endif () +check_function_exists(getrpcent HAVE_GETRPCENT) +if (NOT HAVE_GETRPCENT) + find_package(TIRPC) + set(CMAKE_REQUIRED_LIBRARIES ${TIRPC_LIBRARIES}) + check_function_exists(getrpcent HAVE_TIRPC_GETRPCENT) + if (HAVE_TIRPC_GETRPCENT) + set(USE_TIRPC TRUE) + else() + message(SEND_ERROR "Couldn't find an RPC program number database implementation!") + endif() +endif() +cmake_pop_check_state() +# ^^^^^^^^^ GETRPCENT TEST ^^^^^^^^^ + #-------------------------------------------------------------------------- # Checks for typedefs, structures, and compiler characteristics. #-------------------------------------------------------------------------- diff --git a/config.cmake.h.in b/config.cmake.h.in index 7ac063abe..7066c299a 100644 --- a/config.cmake.h.in +++ b/config.cmake.h.in @@ -135,6 +135,8 @@ #cmakedefine HAVE_UUID 1 +#cmakedefine USE_TIRPC 1 + /* Availability of specific library functions */ @@ -150,6 +152,9 @@ /* Define to 1 if you have the `sigaction' function. */ #cmakedefine HAVE_SIGACTION 1 +/* Define to 1 if you have the GNU form of the `strerror_r' function. */ +#cmakedefine HAVE_GNU_STRERROR_R 1 + /* Available compiler options */ diff --git a/daqs/daq_file.c b/daqs/daq_file.c index 192236a6b..92f9093cf 100644 --- a/daqs/daq_file.c +++ b/daqs/daq_file.c @@ -24,16 +24,14 @@ #include "daq_user.h" -#include #include #include #include #include #include - -#include #include -#include +#include +#include #include #include diff --git a/daqs/daq_hext.c b/daqs/daq_hext.c index 97311483d..b9524e227 100644 --- a/daqs/daq_hext.c +++ b/daqs/daq_hext.c @@ -24,19 +24,17 @@ #include "daq_user.h" -#include +#include #include #include #include #include #include #include - -#include -#include -#include -#include #include +#include +#include +#include #include #include diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c066be3b6..679bfdc22 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -43,6 +43,11 @@ if ( ICONV_FOUND ) LIST(APPEND EXTERNAL_INCLUDES ${ICONV_INCLUDE_DIR}) endif () +if ( USE_TIRPC ) + LIST(APPEND EXTERNAL_LIBRARIES ${TIRPC_LIBRARIES}) + LIST(APPEND EXTERNAL_INCLUDES ${TIRPC_INCLUDE_DIRS}) +endif () + include_directories(BEFORE ${LUAJIT_INCLUDE_DIR}) include_directories(AFTER ${EXTERNAL_INCLUDES}) @@ -178,6 +183,11 @@ target_link_libraries( snort ${EXTERNAL_LIBRARIES} ) +# Solaris requires libnsl and libsocket for various network-related library functions +if ( CMAKE_SYSTEM_NAME STREQUAL SunOS ) + target_link_libraries(snort nsl socket) +endif () + # setting export properties set_property(TARGET snort APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${LUAJIT_INCLUDE_DIR} diff --git a/src/network_inspectors/appid/service_plugins/service_rpc.cc b/src/network_inspectors/appid/service_plugins/service_rpc.cc index 42fd65232..a6e5d0b2c 100644 --- a/src/network_inspectors/appid/service_plugins/service_rpc.cc +++ b/src/network_inspectors/appid/service_plugins/service_rpc.cc @@ -27,7 +27,7 @@ #include -#if defined(__FreeBSD__) || defined(__OpenBSD__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(USE_TIRPC) #include #elif defined(__sun) #include diff --git a/src/utils/util.cc b/src/utils/util.cc index a26f0a2d1..34d2b64ca 100644 --- a/src/utils/util.cc +++ b/src/utils/util.cc @@ -605,8 +605,7 @@ const char* get_error(int errnum) { static THREAD_LOCAL char buf[128]; -#if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE < 200112L && \ - defined(_XOPEN_SOURCE) && _XOPEN_SOURCE < 600) || _GNU_SOURCE +#if defined(HAVE_GNU_STRERROR_R) return strerror_r(errnum, buf, sizeof(buf)); #else (void)strerror_r(errnum, buf, sizeof(buf));