diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000..3d416a67ca --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,865 @@ +# Copyright (C) 2019-2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved. + +cmake_minimum_required( VERSION 3.12...3.13 ) +set(CMAKE_C_STANDARD 90) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Change this on a release: +# During active development: set(VERSION_SUFFIX "-devel-${TODAY}") +# For beta: set(VERSION_SUFFIX "-beta") +# For release candidate: set(VERSION_SUFFIX "-rc") +# For release: set(VERSION_SUFFIX "") +string(TIMESTAMP TODAY "%Y%m%d") +set(VERSION_SUFFIX "-devel-${TODAY}") + +project( ClamAV + VERSION "0.103.0" + DESCRIPTION "ClamAV open source email, web, and end-point anti-virus toolkit." ) + +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) +include(Version) + +set(PACKAGE_NAME "${PROJECT_NAME}") +set(PACKAGE_VERSION "${PROJECT_VERSION}") +set(PACKAGE_STRING "${PROJECT_NAME} ${PROJECT_VERSION}${VERSION_SUFFIX}") +set(PACKAGE_BUGREPORT "https://bugzilla.clamav.net/") +set(PACKAGE_URL "https://www.clamav.net/") +HexVersion(PACKAGE_VERSION_NUM ${PROJECT_VERSION_MAJOR} ${PROJECT_VERSION_MINOR} ${PROJECT_VERSION_PATCH}) + +# libtool library versioning rules: http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html +set(LIBCLAMAV_CURRENT 9) +set(LIBCLAMAV_REVISION 5) +set(LIBCLAMAV_AGE 0) + +math(EXPR LIBCLAMAV_SOVERSION "${LIBCLAMAV_CURRENT} - ${LIBCLAMAV_AGE}") +set(LIBCLAMAV_VERSION "${LIBCLAMAV_SOVERSION}.${LIBCLAMAV_AGE}.${LIBCLAMAV_REVISION}") +HexVersion(LIBCLAMAV_VERSION_NUM ${LIBCLAMAV_CURRENT} ${LIBCLAMAV_REVISION} ${LIBCLAMAV_AGE}) + +set(LIBFRESHCLAM_CURRENT 2) +set(LIBFRESHCLAM_REVISION 1) +set(LIBFRESHCLAM_AGE 0) + +math(EXPR LIBFRESHCLAM_SOVERSION "${LIBFRESHCLAM_CURRENT} - ${LIBFRESHCLAM_AGE}") +set(LIBFRESHCLAM_VERSION "${LIBFRESHCLAM_SOVERSION}.${LIBFRESHCLAM_AGE}.${LIBFRESHCLAM_REVISION}") +HexVersion(LIBFRESHCLAM_VERSION_NUM ${LIBFRESHCLAM_CURRENT} ${LIBFRESHCLAM_REVISION} ${LIBFRESHCLAM_AGE}) + +# Git optionally used to add commit info into build to differentiate in bug reports. +find_package(Git) +if(Git_FOUND) + # Store git description into variable + execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --always + OUTPUT_VARIABLE REPO_VERSION) + if("${REPO_VERSION}" MATCHES "") + unset(REPO_VERSION) + else() + string(STRIP ${REPO_VERSION} REPO_VERSION) + endif() +endif() + +# Enable use of pkg-config to find depenencies. +find_package(PkgConfig QUIET) + +# +# Find Build Tools +# + +# Bison, Flex required to build Yara module for libclamav. +find_package(BISON REQUIRED) +find_package(FLEX REQUIRED) +if(MAINTAINER_MODE) + find_package(GPERF REQUIRED) +endif() + +# +# Load Build Options +# + +# CMake Option default values: +set(ENABLE_APP_DEFAULT ON) +set(ENABLE_MILTER_DEFAULT OFF) +set(ENABLE_CLAMONACC_DEFAULT ON) +set(ENABLE_EXAMPLES_DEFAULT OFF) +if(WIN32) + set(ENABLE_DOCS_DEFAULT OFF) +else() + set(ENABLE_DOCS_DEFAULT ON) +endif() +set(ENABLE_DOXYGEN_DEFAULT OFF) +set(ENABLE_UNRAR_DEFAULT ON) +set(ENABLE_SYSTEMD_DEFAULT ON) + +# See CMakeOptions.cmake for additional options. +include(CMakeOptions.cmake) + +if(ENABLE_LIBCLAMAV_ONLY AND (ENABLE_APP OR ENABLE_EXAMPLES)) + # Remember when disabled options are disabled for later diagnostics. + set(ENABLE_LIB_ONLY_DISABLED_OTHERS 1) +else() + set(ENABLE_LIB_ONLY_DISABLED_OTHERS 0) +endif() +if(ENABLE_LIBCLAMAV_ONLY) + set(ENABLE_APP OFF) + set(ENABLE_EXAMPLES OFF) +endif() + +# +# Set RPATH for custom install prefixes +# +if(APPLE) + set(CMAKE_MACOSX_RPATH 1) +endif() +set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") + +# +# Define LINUX because CMake only defines UNIX +# +if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") + set(LINUX 1) + + if(CMAKE_COMPILER_IS_GNUCXX) + # For O_LARGEFILE, O_CLOEXEC, O_DIRECTORY, O_NOFOLLOW, etc flags on older systems + # (pre POSIX.1-2008: glibc 2.11 and earlier). #4042 + set(_GNU_SOURCE 1) + endif() +endif() + +# +# Set FreeBSD include path to include /usr/local/include +# +if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + include_directories(/usr/local/include) +endif() + +# +# Use the `lib` prefix on Windows, to match previous ClamAV build +# +if(WIN32) + set(CMAKE_SHARED_LIBRARY_PREFIX "lib") + set(CMAKE_STATIC_LIBRARY_PREFIX "lib") +endif() + +# +# Find Library Dependencies +# +if (WIN32) + find_package(PThreadW32) + set(HAVE_PTHREAD_H 1) + set(_REENTRANT 1) + set(CL_THREAD_SAFE 1) +else() + set(CMAKE_THREAD_PREFER_PTHREAD 1) + find_package(Threads) + if(Threads_FOUND AND CMAKE_USE_PTHREADS_INIT) + set(HAVE_PTHREAD_H 1) + set(_REENTRANT 1) + set(CL_THREAD_SAFE 1) + endif() +endif() + +# libclamav efficacy dependencies +find_package(OpenSSL REQUIRED) +if(OPENSSL_FOUND) + set(HAVE_LIBSSL 1) +endif() + +find_package(ZLIB REQUIRED) +if(ZLIB_FOUND) + set(HAVE_ZLIB_H 1) + set(HAVE_LIBZ 1) +endif() + +find_package(BZip2 REQUIRED) +if(BZIP2_FOUND) + set(HAVE_BZLIB_H 1) +endif() + +find_package(LibXml2 REQUIRED) +if(LibXml2_FOUND) + set(HAVE_LIBXML2 1) +endif() + +find_package(PCRE2 REQUIRED) +if(PCRE2_FOUND) + set(HAVE_PCRE 1) + set(USING_PCRE2 1) +endif() + +# libclamav feature dependencies +if(NOT WIN32) + find_package(Iconv REQUIRED) + # Set variable required by libclamav to use iconv + set(HAVE_ICONV 1) +endif() + +if(ENABLE_JSON_SHARED) + set(JSONC_USE_STATIC OFF) +else() + set(JSONC_USE_STATIC ON) +endif() +find_package(JSONC REQUIRED) +# Set variable required by libclamav to use libjson-c +set(HAVE_JSON 1) + +if(BYTECODE_RUNTIME STREQUAL "llvm") + find_package(LLVM REQUIRED) + if(LLVM_FOUND) + # Set variable required by libclamav to use llvm instead of interpreter + set(LLVM_VERSION ${LLVM_VERSION_MAJOR}${LLVM_VERSION_MINOR}) + endif() +endif() + +# libfreshclam & app dependencies +if(NOT ENABLE_LIBCLAMAV_ONLY) + find_package(CURL REQUIRED) + + if(APPLE) + find_library(APPLE_CORE_FOUNDATION CoreFoundation) + if (NOT APPLE_CORE_FOUNDATION) + message(FATAL_ERROR "Apple CoreFoundation framework not found") + endif() + find_library(APPLE_SECURITY Security) + if (NOT APPLE_SECURITY) + message(FATAL_ERROR "Apple Security framework not found") + endif() + endif() + + if(ENABLE_APP) + find_package(CURSES REQUIRED) + + if(NOT WIN32 AND ENABLE_MILTER) + find_package(Milter REQUIRED) + endif() + + if(LINUX AND ENABLE_SYSTEMD) + find_package(SYSTEMD) + if(SYSTEMD_FOUND) + set(HAVE_SYSTEMD 1) + endif() + endif() + endif() +endif() + + +# Do not disable assertions based on CMAKE_BUILD_TYPE. +foreach(_build_type "Release" "MinSizeRel" "RelWithDebInfo") + foreach(_lang C CXX) + string(TOUPPER "CMAKE_${_lang}_FLAGS_${_build_type}" _var) + string(REGEX REPLACE "(^|)[/-]D *NDEBUG($|)" " " ${_var} "${${_var}}") + endforeach() +endforeach() + +# Disable optimizations if OPTIMIZE=OFF +if(NOT OPTIMIZE) + # Get rid of any previous optimization flag settings... + string(REGEX REPLACE "(\-O[011123456789])" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REGEX REPLACE "(\-O[011123456789])" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + + # ...And substitute our own. + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0") +endif() + +# Support the latest c++ standard available. +include(ExtractValidFlags) +foreach(_cxx1x_flag -std=c++14 -std=c++11) + extract_valid_cxx_flags(_cxx1x_flag_supported ${_cxx1x_flag}) + if(_cxx1x_flag_supported) + set(CXX1XCXXFLAGS ${_cxx1x_flag}) + break() + endif() +endforeach() + +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the build type" FORCE) + + # Include "None" as option to disable any additional (optimization) flags, + # relying on just CMAKE_C_FLAGS and CMAKE_CXX_FLAGS (which are empty by + # default). These strings are presented in cmake-gui. + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "None" "Debug" "Release" "MinSizeRel" "RelWithDebInfo") +endif() + +include(GNUInstallDirs) + +# For test scripts and documentation +find_package(Python3) + +# Always use '-fPIC'/'-fPIE' option. +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +# Checks for header files. +include(CheckIncludeFile) +check_include_file("arpa/inet.h" HAVE_ARPA_INET_H) +check_include_file("fcntl.h" HAVE_FCNTL_H) +check_include_file("grp.h" HAVE_GRP_H) +check_include_file("limits.h" HAVE_LIMITS_H) +check_include_file("malloc.h" HAVE_MALLOC_H) +check_include_file("netdb.h" HAVE_NETDB_H) +check_include_file("netinet/in.h" HAVE_NETINET_IN_H) +check_include_file("poll.h" HAVE_POLL_H) +check_include_file("pwd.h" HAVE_PWD_H) +check_include_file("stdbool.h" HAVE_STDBOOL_H) +check_include_file("stdlib.h" HAVE_STDLIB_H) +check_include_file("string.h" HAVE_STRING_H) +check_include_file("strings.h" HAVE_STRINGS_H) +check_include_file("sys/cdefs.h" HAVE_SYS_CDEFS_H) +check_include_file("sys/dl.h" HAVE_SYS_DL_H) +check_include_file("sys/fileio.h" HAVE_SYS_FILIO_H) +check_include_file("sys/mman.h" HAVE_SYS_MMAN_H) +check_include_file("sys/param.h" HAVE_SYS_PARAM_H) +check_include_file("sys/queue.h" HAVE_SYS_QUEUE_H) +check_include_file("sys/select.h" HAVE_SYS_SELECT_H) +check_include_file("sys/socket.h" HAVE_SYS_SOCKET_H) +check_include_file("sys/stat.h" HAVE_SYS_STAT_H) +check_include_file("sys/time.h" HAVE_SYS_TIME_H) +check_include_file("sys/times.h" HAVE_SYS_TIMES_H) +check_include_file("sys/uio.h" HAVE_SYS_UIO_H) +check_include_file("syslog.h" USE_SYSLOG) +check_include_file("termios.h" HAVE_TERMIOS_H) +check_include_file("time.h" HAVE_TIME_H) +check_include_file("unistd.h" HAVE_UNISTD_H) +check_include_file("sys/fanotify.h" HAVE_SYS_FANOTIFY_H) + +if(WIN32) + set(HAVE_RESOLV_H 1) + set(HAVE_DIRENT_H 1) + set(HAVE_DLFCN_H 1) +else() + if(APPLE) + set(BIND_8_COMPAT 1) + endif() + check_include_file("resolv.h" HAVE_RESOLV_H) # Disabled, beacuse libfreshclam/dns.c is broken. + check_include_file("dirent.h" HAVE_DIRENT_H) + check_include_file("dlfcn.h" HAVE_DLFCN_H) +endif() + +# int-types variants +check_include_file("inttypes.h" HAVE_INTTYPES_H) +check_include_file("sys/inttypes.h" HAVE_SYS_INTTYPES_H) +check_include_file("sys/int_types.h" HAVE_SYS_INT_TYPES_H) +check_include_file("stdint.h" HAVE_STDINT_H) + +include(CheckTypeSize) +# Checks for typedefs, structures, and compiler characteristics. +# AC_TYPE_SIZE_T +check_type_size("ssize_t" SIZEOF_SSIZE_T) +if(SIZEOF_SSIZE_T STREQUAL "") + # ssize_t is a signed type in POSIX storing at least -1. + # Set it to "int" to match the behavior of AC_TYPE_SSIZE_T (autotools). + set(ssize_t int) +endif() +check_type_size("off_t" SIZEOF_OFF_T) +if(SIZEOF_OFF_T STREQUAL "") + # off_t is a signed type in POSIX no narrower than int. + # Set it to "long int" to match the behavior of AC_TYPE_OFF_T (autotools). + set(off_t long int) +endif() + +check_type_size("int" SIZEOF_INT) +check_type_size("short" SIZEOF_SHORT) +check_type_size("long" SIZEOF_LONG) +check_type_size("long long" SIZEOF_LONG_LONG) + +# +# Variables for clamav-types.h.in +# +if(HAVE_SYS_INT_TYPES_H) + set(INT_TYPES_HEADER "#include ") +elseif(HAVE_INTTYPES_H) + set(INT_TYPES_HEADER "#include ") +elseif(HAVE_STDINT_H) + set(INT_TYPES_HEADER "#include ") +elseif(WIN32 AND MSVC) + # Windows / Visual C++ (not Cygwin), stdint.h should exist. + set(INT_TYPES_HEADER "#include ") +else() + # No int types header available. We'll define the types manually. + set(INT8_DEF "typedef signed char int8_t;") + set(UINT8_DEF "typedef unsigned char uint8_t;") + + if(SIZEOF_INT EQUAL 2) + set(INT16_DEF "typedef signed int int16_t;") + set(UINT16_DEF "typedef unsigned int uint16_t;") + elif(SIZEOF_SHORT EQUAL 2) + set(INT16_DEF "typedef signed short int16_t;") + set(UINT16_DEF "typedef unsigned short uint16_t;") + endif() + + if(SIZEOF_INT EQUAL 4) + set(INT32_DEF "typedef signed int int32_t;") + set(UINT32_DEF "typedef unsigned int uint32_t;") + elif(SIZEOF_LONG EQUAL 4) + set(INT32_DEF "typedef signed long int32_t;") + set(UINT32_DEF "typedef unsigned long uint32_t;") + endif() + + if(SIZEOF_LONG EQUAL 8) + set(INT64_DEF "typedef signed long int64_t;") + set(UINT64_DEF "typedef unsigned long uint64_t;") + elif(SIZEOF_LONG_LONG EQUAL 8) + set(INT64_DEF "typedef signed long long int64_t;") + set(UINT64_DEF "typedef unsigned long long uint64_t;") + endif() +endif() + +# Check for restrict keyword +#TODO: Move this to a .cmake file +foreach( ac_kw __restrict __restrict__ _Restrict restrict ) + check_c_source_compiles( + " + typedef int * int_ptr; + int foo (int_ptr ${ac_kw} ip) { + return ip[0]; + } + int main() { + int s[1]; + int * ${ac_kw} t = s; + t[0] = 0; + return foo(t); + } + " + HAVE_RESTRICT ) + + if( HAVE_RESTRICT ) + set( ac_cv_c_restrict ${ac_kw} ) + break() + endif() +endforeach() +if( HAVE_RESTRICT ) + set( restrict ${ac_cv_c_restrict} ) +endif() + +# Define inline macro as needed. +include(TestInline) +# Determine if _FILE_OFFSET_BITS 64 needs to be set to handle large files. +include(CheckFileOffsetBits) +# Determine how to pack structs on this platform. +include(CheckStructPacking) +# Check for signed right shift implementation. +include(CheckSignedRightShift) +# Check if systtem fts implementation available +include(CheckFTS) +# Check if uname(2) follows POSIX standard. +include(CheckUnamePosix) +# Check support for file descriptor passing +include(CheckFDPassing) + +# Check if big-endian +include(TestBigEndian) +TEST_BIG_ENDIAN(WORDS_BIGENDIAN) + +include(CheckStructHasMember) +check_struct_has_member("struct tm" tm_gmtoff time.h HAVE_STRUCT_TM_TM_GMTOFF) + +# Check size of pointer to decide we need 8 bytes alignment adjustment. +check_type_size("int *" SIZEOF_INT_P) +check_type_size("time_t" SIZEOF_TIME_T) + +# Checks for library functions. +include(CheckSymbolExists) +check_symbol_exists(_Exit "stdlib.h" HAVE__EXIT) +check_symbol_exists(accept4 "sys/types.h" HAVE_ACCEPT4) +check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF) +check_symbol_exists(stat64 "sys/stat.h" HAVE_STAT64) +check_symbol_exists(strcasestr "string.h" HAVE_STRCASESTR) +check_symbol_exists(strerror_r "string.h" HAVE_STRERROR_R) +check_symbol_exists(strlcat "string.h" HAVE_STRLCAT) +check_symbol_exists(strlcpy "string.h" HAVE_STRLCPY) +check_symbol_exists(strndup "string.h" HAVE_STRNDUP) +check_symbol_exists(strnlen "string.h" HAVE_STRNLEN) +check_symbol_exists(strnstr "string.h" HAVE_STRNSTR) +check_symbol_exists(sysctlbyname "sysctl.h" HAVE_SYSCTLBYNAME) +check_symbol_exists(timegm "time.h" HAVE_TIMEGM) +check_symbol_exists(vsnprintf "stdio.h" HAVE_VSNPRINTF) + +if(WIN32) + #set(HAVE_FSEEKO 1) + set(HAVE_GETADDRINFO 1) + set(HAVE_GETPAGESIZE 1) + set(HAVE_MKSTEMP 1) + set(HAVE_POLL 1) +else() + check_symbol_exists(fseeko "stdio.h" HAVE_FSEEKO) + check_symbol_exists(getaddrinfo "netdb.h" HAVE_GETADDRINFO) + check_symbol_exists(getpagesize "unistd.h" HAVE_GETPAGESIZE) + check_symbol_exists(mkstemp "unistd.h" HAVE_MKSTEMP) + check_symbol_exists(poll "poll.h" HAVE_POLL) + check_symbol_exists(setgroups "unistd.h" HAVE_SETGROUPS) + check_symbol_exists(setsid "unistd.h" HAVE_SETSID) +endif() + +include(CheckSymbolExists) +# XXX does this correctly detect initgroups (un)availability on cygwin? +check_symbol_exists(initgroups grp.h HAVE_INITGROUPS) +if(NOT HAVE_INITGROUPS AND HAVE_UNISTD_H) + # FreeBSD declares initgroups() in unistd.h + check_symbol_exists(initgroups unistd.h HAVE_INITGROUPS2) + if(HAVE_INITGROUPS2) + set(HAVE_INITGROUPS 1) + endif() +endif() + +set(WARNCFLAGS) +set(WARNCXXFLAGS) +if(CMAKE_C_COMPILER_ID MATCHES "MSVC") + if(ENABLE_WERROR) + set(WARNCFLAGS /WX) + set(WARNCXXFLAGS /WX) + endif() +else() + if(ENABLE_WERROR) + extract_valid_c_flags(WARNCFLAGS -Werror) + extract_valid_c_flags(WARNCXXFLAGS -Werror) + endif() + + # For C compiler + extract_valid_c_flags(WARNCFLAGS + -Wall -Wextra + -Wformat-security + ) + if(ENABLE_ALL_THE_WARNINGS) + extract_valid_c_flags(WARNCFLAGS + -Waddress + -Wattributes + -Wclobbered + -Wconversion + -Wdeclaration-after-statement + -Wdiv-by-zero + -Wempty-body + -Wendif-labels + -Wfloat-equal + -Wformat-nonliteral + -Winline + -Wmissing-declarations + -Wmissing-field-initializers + -Wmissing-noreturn + -Wmissing-prototypes + -Wnested-externs + #-Wno-format-nonliteral # May be required to pass format string as "const char*. + -Wpointer-arith + -Wpragmas + -Wredundant-decls + -Wshadow + -Wunreachable-code + -Wunused-parameter + -Wvla + -Wwrite-strings + -Wstrict-prototypes + -Wundef + -Wcast-align + -Wextended-offsetof # May be missing from GCC + -Wheader-guard # Only work with Clang for the moment + -Wlanguage-extension-token # May be missing from GCC + -Wmissing-variable-declarations # May be missing from GCC + #-Wpadded # Not used because we cannot change public structs + -Wshorten-64-to-32 # May be missing from GCC + -Wsign-conversion + #-Wswitch-enum # Not used because this basically disallows default case + -Wunreachable-code-break # May be missing from GCC + -Wunused-macros + ) + endif() + + # For C++ compiler + extract_valid_cxx_flags(WARNCXXFLAGS + -Wall + -Wformat-security + ) +endif() + +# autotools-compatible names +# Sphinx expects relative paths in the .rst files. Use the fact that the files +# below are all one directory level deep. +file(RELATIVE_PATH top_srcdir "${CMAKE_CURRENT_BINARY_DIR}/dir" "${CMAKE_CURRENT_SOURCE_DIR}") +file(RELATIVE_PATH top_builddir "${CMAKE_CURRENT_BINARY_DIR}/dir" "${CMAKE_CURRENT_BINARY_DIR}") +set(abs_top_srcdir "${CMAKE_CURRENT_SOURCE_DIR}") +set(abs_top_builddir "${CMAKE_CURRENT_BINARY_DIR}") +# libclamav.pc (pkg-config file) +set(prefix "${CMAKE_INSTALL_PREFIX}") +set(exec_prefix "${CMAKE_INSTALL_PREFIX}") +set(bindir "${CMAKE_INSTALL_FULL_BINDIR}") +set(sbindir "${CMAKE_INSTALL_FULL_SBINDIR}") +set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}") +set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}") +set(VERSION "${PACKAGE_VERSION}") + +# DBDIR for systemd service.in files +set(DBDIR "${DATABASE_DIRECTORY}") + +if(ENABLE_DEBUG) + set(CL_DEBUG 1) +endif() +if(ENABLE_EXPERIMENTAL) + set(CL_EXPERIMENTAL 1) +endif() +if(ENABLE_STRN_INTERNAL) + set(HAVE_STRNI 1) +endif() +if(ENABLE_FRESHCLAM_DNS_FIX) + set(FRESHCLAM_DNS_FIX 1) +endif() +if(ENABLE_FRESHCLAM_NO_CACHE) + set(FRESHCLAM_NO_CACHE 1) +endif() + +set(SCANBUFF 131072) # scan buffer size +set(FILEBUFF 8192) # file i/o buffer size + +if(APPLE) + set(C_DARWIN 1) +endif() + +include(config) +if(WIN32) + set(USE_MPOOL 1) +endif() + +add_definitions(-DHAVE_CONFIG_H) +configure_file(clamav-config.h.cmake.in clamav-config.h) +configure_file(target.h.cmake.in target.h) +configure_file(platform.h.in platform.h) +configure_file(clamav-version.h.in clamav-version.h) +configure_file(clamav-types.h.in clamav-types.h) + +if(WIN32) + # + # Windows-specific config stuff + # + + # Windows resource file + set(CLAMAV_RES "") + configure_file( + win32/res/common.rc.in + ${CMAKE_BINARY_DIR}/version.rc + @ONLY) +else() + # + # POSIX-specific config stuff + # + + # Don't confuse clamav-config.in with clamav-config.h.in or clamav-config.h.cmake.in + configure_file(clamav-config.in + ${CMAKE_CURRENT_BINARY_DIR}/clamav-config + @ONLY) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/clamav-config" + DESTINATION "${CMAKE_INSTALL_BINDIR}" + PERMISSIONS + OWNER_READ OWNER_WRITE OWNER_EXECUTE + GROUP_READ GROUP_EXECUTE + WORLD_READ WORLD_EXECUTE) + + # pkg-config + configure_file( + libclamav.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/libclamav.pc + @ONLY) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libclamav.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") +endif() + +# +# ClamAV Build targets! +# + +# Build targets for libraries. +if(ENABLE_UNRAR) + # Only build libclamunrar if enabled. + # We still define the libclamunrar_iface's interface regardless, + # so that libclamav will have unrar_iface.h in the include path. + add_subdirectory( libclamunrar ) +endif() +add_subdirectory( libclamunrar_iface ) + +if(NOT ENABLE_EXTERNAL_MSPACK) + add_subdirectory(libclammspack) +else() + find_package(MSPack) +endif() + +if(WIN32) + add_subdirectory( win32/compat ) +endif() + +add_subdirectory( libclamav ) + +if(NOT LIBCLAMAV_ONLY) + add_subdirectory( shared ) + + add_subdirectory( libfreshclam ) + + if(ENABLE_APP) + # Build targets for primary applications. + add_subdirectory( clamconf ) + + add_subdirectory( clamd ) + + add_subdirectory( clamdscan ) + + if(LINUX AND ENABLE_CLAMONACC) + add_subdirectory( clamonacc ) + endif() + + if(NOT WIN32 AND ENABLE_MILTER) + add_subdirectory( clamav-milter ) + endif() + + add_subdirectory( clamscan ) + + add_subdirectory( sigtool ) + + add_subdirectory( clambc ) + + add_subdirectory( clamsubmit ) + + add_subdirectory( freshclam ) + + add_subdirectory( clamdtop ) + + if(WIN32) + add_subdirectory( win32/conf_examples ) + else() + add_subdirectory( etc ) + endif() + endif() +endif() + +if(ENABLE_EXAMPLES) + add_subdirectory( examples ) +endif() + +if(ENABLE_DOCS) + add_subdirectory( docs ) +endif() + +if(ENABLE_FUZZ) + add_subdirectory( fuzz ) +endif() + +# +# The Summary Info. +# +include(ColourMessage) +string(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type) +message(STATUS "${Y}Configuration Options Summary${e} -- +${c} Package Version: ${e}${PACKAGE_STRING} +${c} libclamav version: ${e}${LIBCLAMAV_CURRENT}:${LIBCLAMAV_REVISION}:${LIBCLAMAV_AGE} +${c} libfreshclam version: ${e}${LIBFRESHCLAM_CURRENT}:${LIBFRESHCLAM_REVISION}:${LIBFRESHCLAM_AGE} +${c} Install prefix: ${e}${CMAKE_INSTALL_PREFIX} +${c} Target system: ${e}${CMAKE_SYSTEM} +${c} Compiler: ${e} +${b} Build type: ${e}${CMAKE_BUILD_TYPE} +${b} C compiler: ${e}${CMAKE_C_COMPILER} +${b} CFLAGS: ${e}${CMAKE_C_FLAGS_${_build_type}} ${CMAKE_C_FLAGS} +${b} WARNCFLAGS: ${e}${WARNCFLAGS} +${c} Build Options: ${e} +${b} Build apps: ${e}${ENABLE_APP} +${b} Shared library: ${e}${ENABLE_SHARED_LIB} +${b} Static library: ${e}${ENABLE_STATIC_LIB} +${b} Enable UnRAR: ${e}${ENABLE_UNRAR} +${b} Examples: ${e}${ENABLE_EXAMPLES} +${b} Build man pages: ${e}${ENABLE_DOCS} +${b} Build doxygen HTML: ${e}${ENABLE_DOXYGEN}") +if(NOT WIN32) +message("\ +${c} Build Extras: ${e}") +message("\ +${b} Build milter: ${e}${ENABLE_MILTER} (toggle with -DENABLE_MILTER=ON/OFF)") +if(LINUX) +message("\ +${b} Build clamonacc: ${e}${ENABLE_CLAMONACC} (toggle with -DENABLE_CLAMONACC=ON/OFF)") +endif() +endif() + +if(LLVM_FOUND) +message(STATUS "${C}Engine Options${e} -- +${b} Bytecode Runtime: ${e} +${_} ${BYTECODE_RUNTIME} ${e}${LLVM_INCLUDE_DIRS} +${_} ${e}${LLVM_LDFLAGS} ${LLVM_LIBRARIES} +${_} ${e}${LLVM_LIBRARY_DIRS}") +else() +message(STATUS "${C}Engine Options${e} -- +${b} Bytecode Runtime: ${e} +${_} ${BYTECODE_RUNTIME} ${e}") +endif() + +message(STATUS "${C}libclamav Dependencies${e} -- +${b} Compression support:${e} +${_} bzip2 ${e}${BZIP2_INCLUDE_DIRS} +${_} ${e}${BZIP2_LIBRARIES} +${_} zlib ${e}${ZLIB_INCLUDE_DIRS} +${_} ${e}${ZLIB_LIBRARIES} +${b} XML support: ${e} +${_} libxml2 ${e}${LIBXML2_INCLUDE_DIRS} +${_} ${e}${LIBXML2_LIBRARIES} +${b} RegEx support: ${e} +${_} libpcre2 ${e}${PCRE2_INCLUDE_DIRS} +${_} ${e}${PCRE2_LIBRARIES} +${b} Crypto support: ${e} +${_} openssl ${e}${OPENSSL_INCLUDE_DIR} +${_} ${e}${OPENSSL_LIBRARIES} +${b} JSON support: ${e} +${_} json-c ${e}${JSONC_INCLUDE_DIRS} +${_} ${e}${JSONC_LIBRARIES} +${b} Threading support: ${e}") +if (WIN32) +message("\ +${_} pthread-win32 ${e}${PThreadW32_INCLUDE_DIRS} +${_} ${e}${PThreadW32_LIBRARIES}") +elseif(Threads_FOUND AND CMAKE_USE_PTHREADS_INIT) +message("\ +${_} pthread ${e}") +else() +message("\ +${o} no ${e}") +endif() + +message(STATUS "${C}libfreshclam Extra Dependencies${e} -- +${b} HTTP support: ${e} +${_} curl ${e}${CURL_INCLUDE_DIRS} +${_} ${e}${CURL_LIBRARIES}") + +if(HAVE_LIBNCURSES) +message(STATUS "${C}Application Extra Dependencies${e} -- +${b} GUI support: ${e} +${_} ncurses ${e}${CURSES_INCLUDE_DIRS} +${_} ${e}${CURSES_LIBRARIES}") +elseif(HAVE_LIBPDCURSES) +message(STATUS "${C}Application Extra Dependencies${e} -- +${b} GUI support: ${e} +${_} pdcurses ${e}${CURSES_INCLUDE_DIRS} +${_} ${e}${CURSES_LIBRARIES}") +endif() + +if(LINUX) +if(SYSTEMD_PROGRAM_FOUND) +message("\ +${b} systemd: ${e} +${_} unit directory ${e}${SYSTEMD_UNIT_DIR} +${b} systemd ctl support: ${e}") +if(SYSTEMD_FOUND) +message("\ +${_} libsystemd ${e}${SYSTEMD_INCLUDE_DIRS} +${_} ${e}${SYSTEMD_LIBRARIES}") +else() +message("\ +${_} libsystemd ${e}not found") +endif() +else() +message("\ +${b} systemd: ${e}not found") +endif() +endif() + +if(ENABLE_MILTER) +message("\ +${b} Milter Support: ${e} +${_} libmilter ${e}${Milter_INCLUDE_DIRS} +${_} ${e}${Milter_LIBRARIES}") +endif() +message("") + +if(NOT JSONC_USE_STATIC) + message(STATUS "${g}Warning:${e} libjson-c is known to share symbol names with other JSON libraries which may result in crashes for applications that use libclamav. Consider providing a static json-c library that was compiled with: CFLAGS=\"-fPIC\". Default build settings for json-c 0.15+ should also work. Use the `-DENABLE_JSON_SHARED=OFF` option to prefer detection of the static library, or use -DJSONC_INCLUDE_DIR and -DJSONC_LIBRARY to specify the static JSON library.") +endif() diff --git a/CMakeOptions.cmake b/CMakeOptions.cmake new file mode 100644 index 0000000000..559d2a26c7 --- /dev/null +++ b/CMakeOptions.cmake @@ -0,0 +1,108 @@ +# Features that can be enabled for cmake (see CMakeLists.txt) + +if (WIN32) + set(APP_CONFIG_DIRECTORY + "${CMAKE_INSTALL_PREFIX}" CACHE STRING + "App Config directory.") + set(DATABASE_DIRECTORY + "${CMAKE_INSTALL_PREFIX}/database" CACHE STRING + "Database directory.") +else() + set(APP_CONFIG_DIRECTORY + "${CMAKE_INSTALL_PREFIX}/etc" CACHE STRING + "App Config directory.") + set(DATABASE_DIRECTORY + "${CMAKE_INSTALL_PREFIX}/share/clamav" CACHE STRING + "Database directory.") +endif() + +set(CLAMAV_USER "clamav" CACHE STRING "ClamAV User") +set(CLAMAV_GROUP "clamav" CACHE STRING "ClamAV Group") + +set(MMAP_FOR_CROSSCOMPILING + 0 CACHE STRING + "Force MMAP support for cross-compiling.") +set(DISABLE_MPOOL + 0 CACHE STRING + "Disable mpool support entirely.") + +set(BYTECODE_RUNTIME + "interpreter" CACHE STRING + "Bytecode Runtime, may be: 'llvm', 'interpreter', 'none'.") + +option(OPTIMIZE + "Allow compiler optimizations. Set to OFF to disable (i.e. to set -O0)." + ON) + +option(ENABLE_WERROR + "Compile time warnings will cause build failures.") + +option(ENABLE_ALL_THE_WARNINGS + "Enable as many compiler warnings as possible.") + +option(ENABLE_DEBUG + "Turn on extra debug output.") + +option(ENABLE_EXPERIMENTAL + "Turn on experimental features (if any).") + +option(ENABLE_FRESHCLAM_DNS_FIX + "Enable workaround for broken DNS servers.") + +option(ENABLE_FRESHCLAM_NO_CACHE + "Use 'Cache-Control: no-cache' in freshclam.") + +option(ENABLE_STRN_INTERNAL + "Enables explicit use of internal strn functions to support cross-compilation against older libs.") + +option(ENABLE_FUZZ + "Build fuzz targets. Will enable ENABLE_STATIC_LIB for you.") + +option(ENABLE_EXTERNAL_MSPACK + "Use external mspack instead of internal libclammspack.") + +option(ENABLE_JSON_SHARED + "Prefer linking with libjson-c shared library instead of static." + ON) + +option(ENABLE_APP + "Build applications (clamscan, clamd, clamdscan, clamonacc, sigtool, clambc, clamav-milter, clamdtop, clamsubmit, clamconf)." + ${ENABLE_APP_DEFAULT}) + +option(ENABLE_MILTER + "Build clamav-milter (requires ENABLE_APP))." + ${ENABLE_MILTER_DEFAULT}) + +option(ENABLE_CLAMONACC + "Build clamonacc (Linux-only, requires ENABLE_APP))." + ${ENABLE_CLAMONACC_DEFAULT}) + +option(ENABLE_DOCS + "Generate documentation." + ${ENABLE_DOCS_DEFAULT}) + +option(ENABLE_DOXYGEN + "Generate doxygen HTML documentation for clamav.h, libfreshclam.h." + ${ENABLE_DOXYGEN_DEFAULT}) + +option(ENABLE_EXAMPLES + "Build examples." + ${ENABLE_EXAMPLES_DEFAULT}) + +option(ENABLE_LIBCLAMAV_ONLY + "Build libclamav only. Excludes libfreshclam too!") + +option(ENABLE_STATIC_LIB + "Build libclamav and/or libfreshclam static libraries.") + +option(ENABLE_SHARED_LIB + "Build libclamav and/or libfreshclam shared libraries." + ON) + +option(ENABLE_UNRAR + "Build & install libclamunrar." + ${ENABLE_UNRAR_DEFAULT}) + +option(ENABLE_SYSTEMD + "Install systemd service files if systemd is found." + ${ENABLE_SYSTEMD_DEFAULT}) diff --git a/INSTALL.md b/INSTALL.autotools.md similarity index 100% rename from INSTALL.md rename to INSTALL.autotools.md diff --git a/INSTALL.cmake.md b/INSTALL.cmake.md new file mode 100644 index 0000000000..9f449c3166 --- /dev/null +++ b/INSTALL.cmake.md @@ -0,0 +1,548 @@ +# Installation Instructions + +**CAUTION**: ClamAV CMake support is experimental in this release and is not +recommended for production systems!!! + +Please help us stabilize it so we can deprecate autotools and Visual Studio. + +_Known Issues / To-do:_ + +- Support for building unit tests / feature tests and running with CTest + - A portion of this task will involve converting the shell scripts portions + to Python unit tests. +- Build fuzz targets. +- LLVM bytecode runtime support. + - Presently only the bytecode intepreter is supported. LLVM is preferable + because it is faster. This task also requires updating to use a modern + version of LLVM. Currently ClamAV is limited to LLVM 3.6. + - The built-in LLVM runtime is not supported in the CMake tooling with no + plans to add support. It will likely be removed when system-LLVM support + is updated. +- Complete the MAINTAINER_MODE option to generate files with GPerf. + +- [Installation Instructions](#installation-instructions) + - [CMake Basics](#cmake-basics) + - [Basic Release build & system install](#basic-release-build--system-install) + - [Basic Debug build](#basic-debug-build) + - [Build and install to a specific install location (prefix)](#build-and-install-to-a-specific-install-location-prefix) + - [Build using Ninja](#build-using-ninja) + - [Build and run tests](#build-and-run-tests) + - [Custom CMake options](#custom-cmake-options) + - [Custom Library Paths](#custom-library-paths) + - [Example Build Commands](#example-build-commands) + - [Linux release build, install to system](#linux-release-build-install-to-system) + - [macOS debug build, custom OpenSSL path, build examples, local install](#macos-debug-build-custom-openssl-path-build-examples-local-install) + - [Windows Build](#windows-build) + - [External Depedencies](#external-depedencies) + - [libclamav dependencies](#libclamav-dependencies) + - [libfreshclam dependencies](#libfreshclam-dependencies) + - [Application dependencies](#application-dependencies) + - [Dependency build options](#dependency-build-options) + - [bzip2](#bzip2) + - [zlib](#zlib) + - [libxml2](#libxml2) + - [libpcre2](#libpcre2) + - [openssl (libcrypto, libssl)](#openssl-libcrypto-libssl) + - [libjson-c](#libjson-c) + - [libmspack](#libmspack) + - [iconv (POSIX-only)](#iconv-posix-only) + - [pthreads-win32 (Windows-only)](#pthreads-win32-windows-only) + - [llvm (optional, _see "Bytecode Runtime" section_)](#llvm-optional-see-bytecode-runtime-section) + - [libcurl](#libcurl) + - [ncurses or pdcurses, for clamdtop](#ncurses-or-pdcurses-for-clamdtop) + - [Bytecode Runtime](#bytecode-runtime) + - [Compilers and Options](#compilers-and-options) + - [Compiling For Multiple Architectures](#compiling-for-multiple-architectures) + +## CMake Basics + +Build requirements: + +- CMake 3.13+ +- A C-toolchain such as gcc, clang, or Microsoft Visual Studio. +- Flex and Bison. On Windows, `choco install winflexbison`. + +_Important_: The following instructions assume that you have created a `build` +subdirectory and that subsequent commands are performed from said directory, +like so: + +```sh +mkdir build && cd build +``` + +### Basic Release build & system install + +```sh +cmake .. -DCMAKE_BUILD_TYPE="Release" +cmake --build . --config Release +sudo cmake --build . --config Release --target install +``` + +### Basic Debug build + +In CMake, "Debug" builds mean that symbols are compiled in. + +```sh +cmake .. -DCMAKE_BUILD_TYPE="Debug" +cmake --build . --config Debug +``` + +You will likely also wish to disable compiler/linker optimizations, which you +can do like so, using our custom `OPTIMIZE` option: + +```sh +cmake .. -DCMAKE_BUILD_TYPE="Debug" -DOPTIMIZE=OFF +cmake --build . --config Debug +``` + +### Build and install to a specific install location (prefix) + +```sh +cmake -DCMAKE_INSTALL_PREFIX:PATH=install .. +cmake --build . --target install --config Release +``` + +### Build using Ninja + +This build uses Ninja (ninja-build) instead of Make. It's _really_ fast. + +```sh +cmake .. -G Ninja +cmake --build . --config Release +``` + +### Build and run tests + +_TODO_: We have not yet added unit test support for CMake. + +- `-V`: Verbose + +- `-C `: Specify build configuration (i.e. Debug / Release), required + for Windows builds + +```sh +cmake .. +cmake --build . --config Release +ctest -C Release -V +``` + +## Custom CMake options + +The following CMake options can be selected by using `-D`. For example: + +```sh +cmake .. -DENABLE_EXAMPLES +cmake --build . --config Debug +``` + +- `APP_CONFIG_DIRECTORY`: App Config directory. + + _Default: Windows: `{prefix}`, POSIX: `{prefix}/etc`_ + +- `DATABASE_DIRECTORY`: Database directory. + + _Default: Windows: `{prefix}/database`, POSIX: `{prefix}/share/clamav`_ + +- `CLAMAV_USER`: ClamAV User (POSIX-only). + + _Default: `clamav`_ + +- `CLAMAV_GROUP`: ClamAV Group (POSIX-only). + + _Default: `clamav`_ + +- `MMAP_FOR_CROSSCOMPILING`: Force MMAP support for cross-compiling. + + _Default: `OFF`_ + +- `DISABLE_MPOOL`: Disable mpool support entirely. + + _Default: `OFF`_ + +- `BYTECODE_RUNTIME`: Bytecode Runtime, may be: `llvm`, `interpreter`, `none`. + + _Default: `interpreter`_ + +- `OPTIMIZE`: Allow compiler optimizations (eg. `-O3`). Set to `OFF` to disable + them (`-O0`). + + _Default: `ON`_ + +- `ENABLE_WERROR`: Compile time warnings will cause build failures (i.e. + `-Werror`) + + _Default: `OFF`_ + +- `ENABLE_ALL_THE_WARNINGS`: By default we use `-Wall -Wextra -Wformat-security` + for clamav libs and apps. This option enables a whole lot more. + + _Default: `OFF`_ + +- `ENABLE_DEBUG`: Turn on extra debug output. + + _Default: `OFF`_ + +- `ENABLE_FUZZ`: Build fuzz targets. Will enable `ENABLE_STATIC_LIB` for you. + + _Default: `OFF`_ + +- `ENABLE_EXTERNAL_MSPACK`: Use external mspack instead of internal libclammspack. + + _Default: `OFF`_ + +- `ENABLE_JSON_SHARED`: Prefer linking with libjson-c shared library instead of + static. Please set this to `OFF` if you're an application developer that uses + a different JSON library in your app, or if you provide libclamav to others. + + _Default: `ON`_ + +- `ENABLE_APP`: Build applications (clamscan, clamd, clamdscan, sigtool, + clambc, clamdtop, clamsubmit, clamconf). + + _Default: `ON`_ + +- `ENABLE_CLAMONACC`: (Linux-only) Build the clamonacc on-access scanning daemon. + Requires: `ENABLE_APP` + + _Default: `ON`_ + +- `ENABLE_MILTER`: (Posix-only) Build the clamav-milter mail filter daemon. + Requires: `ENABLE_APP` + + _Default: `OFF`_ + +- `ENABLE_UNRAR`: Build & install libclamunrar (UnRAR) and libclamunrar_iface. + + _Default: `ON`_ + +- `ENABLE_DOCS`: Generate man pages. + + _Default: `OFF`_ + +- `ENABLE_DOXYGEN`: Generate doxygen HTML documentation for clamav.h, + libfreshclam.h. Requires doxygen. + + _Default: `OFF`_ + +- `ENABLE_EXAMPLES`: Build examples. + + _Default: `OFF`_ + +- `ENABLE_LIBCLAMAV_ONLY`: Build libclamav only. Excludes libfreshclam too! + + _Default: `OFF`_ + +- `ENABLE_STATIC_LIB`: Build libclamav and/or libfreshclam static libraries. + + _Default: `OFF`_ + +- `ENABLE_SHARED_LIB`: Build libclamav and/or libfreshclam shared libraries. + + _Default: `ON`_ + +- `ENABLE_SYSTEMD`: Install systemd service files if systemd is found. + + _Default: `ON`_ + +- `SYSTEMD_UNIT_DIR`: Install systemd service files to a specific directory. + This will fail the build if systemd not found. + + _Default: not set_ + +## Custom Library Paths + +### Example Build Commands + +#### Linux release build, install to system + +This example sets the build system to Ninja instead of using Make, for speed. +You may need to first use `apt`/`dnf`/`pkg` to install `ninja-build` + +```sh +cmake .. -G Ninja \ + -DCMAKE_BUILD_TYPE=Release \ + -DENABLE_JSON_SHARED=OFF +ninja +sudo ninja install +``` + +#### macOS debug build, custom OpenSSL path, build examples, local install + +macOS builds use Homebrew to install `flex`, `bison`, and each of the library +dependencies. + +Note that explicit paths for OpenSSL are requires so as to avoid using an older +OpenSSL install provided by the operating system. + +This example also: + +- Build system to Ninja instead of using Make. + - You may need to first use `brew` to install `ninja`. +- Sets build type to "Debug" and explicitly disables compiler optimizations. +- Builds static libraries (and also shared libraries, which are on by default). +- Builds the example programs, just to test them out. +- Sets the install path (prefix) to ./install + +```sh +cmake .. -G Ninja \ + -DCMAKE_BUILD_TYPE=Debug \ + -DOPTIMIZE=OFF \ + -DENABLE_JSON_SHARED=OFF \ + -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl@1.1/ \ + -DOPENSSL_CRYPTO_LIBRARY=/usr/local/opt/openssl@1.1/lib/libcrypto.1.1.dylib \ + -DOPENSSL_SSL_LIBRARY=/usr/local/opt/openssl@1.1/lib/libssl.1.1.dylib \ + -DENABLE_STATIC_LIB=ON \ + -DENABLE_EXAMPLES=ON \ + -DCMAKE_INSTALL_PREFIX=install +ninja +ninja install +``` + +#### Windows Build + +Chocolatey (`choco`) is used to install `winflexbison` and `cmake`. +Visual Studio 2015+ is required, 2017+ recommended. + +These instructions assume that `$env:CLAMAV_DEPENDENCIES` is set to your +[Mussels](https://github.com/Cisco-Talos/Mussels) `install\x64` directory and +that you've used Mussels to build the `clamav_deps` collection which will +provide the required libraries. + +_Tip_: Instead of building manually, try using Mussels to automate your build! + +```ps1 +$env:CLAMAV_DEPENDENCIES="$env:userprofile\.mussels\install\x64" +cmake .. -G "Visual Studio 15 2017" -A x64 ` + -DJSONC_INCLUDE_DIR="$env:CLAMAV_DEPENDENCIES\include\json-c" ` + -DJSONC_LIBRARY="$env:CLAMAV_DEPENDENCIES\lib\json-c.lib" ` + -DBZIP2_INCLUDE_DIR="$env:CLAMAV_DEPENDENCIES\include" ` + -DBZIP2_LIBRARY_RELEASE="$env:CLAMAV_DEPENDENCIES\lib\libbz2.lib" ` + -DCURL_INCLUDE_DIR="$env:CLAMAV_DEPENDENCIES\include" ` + -DCURL_LIBRARY="$env:CLAMAV_DEPENDENCIES\lib\libcurl_imp.lib" ` + -DOPENSSL_ROOT_DIR="$env:CLAMAV_DEPENDENCIES" ` + -DOPENSSL_INCLUDE_DIR="$env:CLAMAV_DEPENDENCIES\include" ` + -DOPENSSL_CRYPTO_LIBRARY="$env:CLAMAV_DEPENDENCIES\lib\libcrypto.lib" ` + -DZLIB_LIBRARY="$env:CLAMAV_DEPENDENCIES\lib\libssl.lib" ` + -DLIBXML2_INCLUDE_DIR="$env:CLAMAV_DEPENDENCIES\include" ` + -DLIBXML2_LIBRARY="$env:CLAMAV_DEPENDENCIES\lib\libxml2.lib" ` + -DPCRE2_INCLUDE_DIR="$env:CLAMAV_DEPENDENCIES\include" ` + -DPCRE2_LIBRARY="$env:CLAMAV_DEPENDENCIES\lib\pcre2-8.lib" ` + -DCURSES_INCLUDE_DIR="$env:CLAMAV_DEPENDENCIES\include" ` + -DCURSES_LIBRARY="$env:CLAMAV_DEPENDENCIES\lib\pdcurses.lib" ` + -DPThreadW32_INCLUDE_DIR="$env:CLAMAV_DEPENDENCIES\include" ` + -DPThreadW32_LIBRARY="$env:CLAMAV_DEPENDENCIES\lib\pthreadVC2.lib" ` + -DZLIB_INCLUDE_DIR="$env:CLAMAV_DEPENDENCIES\include" ` + -DZLIB_LIBRARY="$env:CLAMAV_DEPENDENCIES\lib\zlibstatic.lib" ` + -DCMAKE_INSTALL_PREFIX="install" +cmake --build . --config Release --target install +copy $env:CLAMAV_DEPENDENCIES\lib\* .\install +``` + +_Tip_: If you're having include-path issues, try building with detailed verbosity: + +```ps1 +cmake --build . --config Release --target install -- /verbosity:detailed +``` + +### External Depedencies + +The CMake tooling is good about finding installed dependencies on POSIX systems. + +_Important_: Linux users will want the "-dev" or "-devel" package variants +which include C headers. For macOS, Homebrew doesn't separate the headers. + +#### libclamav dependencies + +App developers that only need libclamav can use the `-DENABLE_LIBCLAMAV_ONLY` +option to bypass ClamAV app dependencies. + +libclamav requires these library dependencies: + +- bzip2 +- zlib +- libxml2 +- libpcre2 +- openssl +- libjson-c +- iconv (POSIX-only, may be provided by system) +- pthreads (or on Windows: pthreads-win32) +- llvm (optional, _see [Bytecode Runtime](#bytecode-runtime)) + +#### libfreshclam dependencies + +If you want libclamav _and_ libfreshclam for your app, then use the +`-DENABLE_APP=OFF` option instead. + +libfreshclam adds these additional library dependencies: + +- libcurl + +#### Application dependencies + +For regular folk who want the ClamAV apps, you'll also need: + +- ncurses (or pdcurses), for clamdtop. +- systemd, so clamd, freshclam, clamonacc may run as a systemd service (Linux). +- libsystemd, so clamd will support the clamd.ctl socket (Linux). + +#### Dependency build options + +If you have custom install paths for the dependencies on your system or are +on Windows, you may need to use the following options... + +##### bzip2 + +```sh + -DBZIP2_INCLUDE_DIR="_filepath of bzip2 header directory_" + -DBZIP2_LIBRARIES="_filepath of bzip2 library_" +``` + +##### zlib + +```sh + -DZLIB_INCLUDE_DIR="_filepath of zlib header directory_" + -DZLIB_LIBRARY="_filepath of zlib library_" +``` + +##### libxml2 + +```sh + -DLIBXML2_INCLUDE_DIR="_filepath of libxml2 header directory_" + -DLIBXML2_LIBRARY="_filepath of libxml2 library_" +``` + +##### libpcre2 + +Hints to find libcpre2 package: + +```sh + -DPCRE2_DIR="_path to libpcre2 install root_" +``` + +Or, explicitly set header & library paths: + +```sh + -DPCRE2_INCLUDE_DIR="_filepath of libpcre2 header directory_" + -DPCRE2_LIBRARY="_filepath of libcpre2 library_" +``` + +##### openssl (libcrypto, libssl) + +Hints to find openssl package: + +```sh + -DOPENSSL_ROOT_DIR="_path to openssl install root_" +``` + +```sh + -DOPENSSL_INCLUDE_DIR="_filepath of openssl header directory_" + -DOPENSSL_CRYPTO_LIBRARY="_filepath of libcrypto library_" + -DOPENSSL_SSL_LIBRARY="_filepath of libcrypto library_" +``` + +##### libjson-c + +Tip: You're strongly encouraged to link with the a static json-c library. + +```sh + -DJSONC_INCLUDE_DIR="_path to json-c header directory_" + -DJSONC_LIBRARY="_filepath of json-c library_" +``` + +##### libmspack + +These options only apply if you use the `-DENABLE_EXTERNAL_MSPACK=ON` option. + +```sh + -DMSPack_INCLUDE_DIR="_path to mspack header directory_" + -DMSPack_LIBRARY="_filepath of libmspack library_" +``` + +##### iconv (POSIX-only) + +On POSIX platforms, iconv might be part of the C library in which case you +would not want to specify an external iconv library. + +```sh + -DIconv_INCLUDE_DIR="_path to iconv header directory_" + -DIconv_LIBRARY="_filepath of iconv library_" +``` + +##### pthreads-win32 (Windows-only) + +On POSIX platforms, pthread support is detected automatically. On Windows, you +need to specify the following: + +```sh + -DPThreadW32_INCLUDE_DIR="_path to pthread-win32 header directory_" + -DPThreadW32_LIBRARY="_filepath of pthread-win32 library_" +``` + +##### llvm (optional, _see "Bytecode Runtime" section_) + +```sh + -DBYTECODE_RUNTIME="llvm" + -DLLVM_ROOT_DIR="_path to llvm install root_" -DLLVM_FIND_VERSION="3.6.0" +``` + +##### libcurl + +```sh + -DCURL_INCLUDE_DIR="_path to curl header directory_" + -DCURL_LIBRARY="_filepath of curl library_" +``` + +##### ncurses or pdcurses, for clamdtop + +```sh + -DCURSES_INCLUDE_DIR="_path to curses header directory_" + -DCURSES_LIBRARY="_filepath of curses library_" +``` + +##### Bytecode Runtime + +Bytecode signatures are a type of executable plugin that provide extra +detection capabilities. + +ClamAV has two bytecode runtimes: + +- *LLVM*: LLVM is the preferred runtime. + + With LLVM, ClamAV JIT compiles bytecode signatures at database load time. + Bytecode signature execution is faster with LLVM. + +- *Interpreter*: The bytecode interpreter is an option on systems where a + a supported LLVM version is not available. + + With the interpreter, signature database (re)loads are faster, but execution + time is slower. + +At the moment, the interpreter is the default runtime, while we work out +compatibility issues with libLLVM. This default equates to: + +```sh +cmake .. -DBYTECODE_RUNTIME="interpreter" +``` + +To build using LLVM instead of the intereter, use: + +```sh +cmake .. \ + -DBYTECODE_RUNTIME="llvm" \ + -DLLVM_ROOT_DIR="/opt/llvm/3.6" \ + -DLLVM_FIND_VERSION="3.6.0" +``` + +To disable bytecode signature support entire, you may build with this option: + +```sh +cmake .. -DBYTECODE_RUNTIME="none" +``` + +## Compilers and Options + +_TODO_: Describe how to customize compiler toolchain with CMake. + +## Compiling For Multiple Architectures + +_TODO_: Describe how to cross-compile with CMake. diff --git a/Makefile.am b/Makefile.am index 50396ec132..1ab5018d5d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -25,8 +25,8 @@ SUBDIRS = libclamav bin_SCRIPTS=clamav-config else -SUBDIRS = libltdl libclamav libfreshclam clamscan clamd clamdscan freshclam sigtool clamconf database docs etc clamav-milter test clamdtop clambc unit_tests -EXTRA_DIST = examples shared libclamav.pc.in COPYING.bzip2 COPYING.lzma COPYING.unrar COPYING.LGPL COPYING.llvm COPYING.file COPYING.zlib COPYING.getopt COPYING.regex COPYING.YARA COPYING.pcre platform.h.in libclamunrar libclamunrar_iface libclammspack clamdscan/clamdscan.map win32 ChangeLog.md INSTALL.md NEWS.md README.md +SUBDIRS = libltdl libclamav shared libfreshclam clamscan clamd clamdscan freshclam sigtool clamconf database docs etc clamav-milter test clamdtop clambc unit_tests +EXTRA_DIST = examples shared libclamav.pc.in COPYING.bzip2 COPYING.lzma COPYING.unrar COPYING.LGPL COPYING.llvm COPYING.file COPYING.zlib COPYING.getopt COPYING.regex COPYING.YARA COPYING.pcre platform.h.in libclamunrar libclamunrar_iface libclammspack clamdscan/clamdscan.map win32 ChangeLog.md INSTALL.cmake.md INSTALL.autotools.md NEWS.md README.md cmake CMakeLists.txt CMakeOptions.cmake $(top_srcdir)/**/CMakeLists.txt libclammspack/config.h.in.cmake clamav-config.h.cmake.in target.h.cmake.in bin_SCRIPTS=clamav-config diff --git a/NEWS.md b/NEWS.md index 5973e3731a..13fbb88177 100644 --- a/NEWS.md +++ b/NEWS.md @@ -51,6 +51,11 @@ ClamAV 0.103.0 includes the following improvements and changes. at the end of a scan, but for now this detail will help users understand why a given file is being flagged as phishing. +- Added new *experimental* CMake build tooling. CMake is not yet recommended for + production builds. Our team would appreciate any assistance improving the + CMake build tooling so we can one day deprecate Autotools and remove the + Visual Studio solutions. + ### Other improvements - Added ability for freshclam and clamsubmit to override default use of openssl @@ -98,6 +103,13 @@ ClamAV 0.103.0 includes the following improvements and changes. ### New Requirements +- Autotools (automake, autoconf, m4, pkg-config, libtool) are now required in + order to build from a Git clone. + Users building from the release tarball should be unaffected. + +- Flex and Bison are now required in order to build from a Git clone. + Users building from the release tarball should be unaffected. + ### Acknowledgements The ClamAV team thanks the following individuals for their code submissions: diff --git a/README.md b/README.md index 343350a669..cbce8e49d2 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,9 @@ For detailed instructions specific to building ClamAV please investigate our the [Linux/Unix/Mac Install instructions in the User Manual](https://www.clamav.net/documents/installing-clamav-on-unix-linux-macos-from-source). +For instructions on how to build ClamAV using our new *experimental* CMake +build tooling, see [INSTALL.cmake.md](INSTALL.cmake.md) + #### Install from a binary package For binary package distribution installation instructions, head over to @@ -56,6 +59,9 @@ directory. For details on how to use either option, head over to the [Windows Install instructions in the User Manual](https://www.clamav.net/documents/installing-clamav-on-windows). +For instructions on how to build ClamAV using our new *experimental* CMake +build tooling, see [INSTALL.cmake.md](INSTALL.cmake.md) + ### Upgrading from a previous version Some tips on [how to upgrade](https://www.clamav.net/documents/upgrading-clamav) diff --git a/clam-format b/clam-format index a83dba5763..c707a348e7 100755 --- a/clam-format +++ b/clam-format @@ -72,7 +72,7 @@ git checkout libclamav/inffixed64.h git checkout libclamav/inflate64.h git checkout libclamav/inflate64.c git checkout libclamav/inflate64_priv.h -git checkout shared/queue.h +git checkout libclamav/queue.h git checkout clamonacc/c-thread-pool/thpool.c git checkout clamonacc/c-thread-pool/thpool.h git checkout clamonacc/misc/fts.c diff --git a/clamav-config.h.cmake.in b/clamav-config.h.cmake.in new file mode 100644 index 0000000000..fd74fb6bd9 --- /dev/null +++ b/clamav-config.h.cmake.in @@ -0,0 +1,608 @@ +/* clamav-config.h.cmake.in. Autoconf compatibility layer for CMake. */ + +/* Define if building universal (internal helper macro) */ +#cmakedefine AC_APPLE_UNIVERSAL_BUILD 1 + +/* mmap flag for anonymous maps */ +#cmakedefine ANONYMOUS_MAP @ANONYMOUS_MAP@ + +/* bind 8 compatibility mode, required on some systems to get T_TXT, etc from nameser_compat.h */ +#cmakedefine BIND_8_COMPAT 1 + +/* name of the clamav group */ +#define CLAMAVGROUP "@CLAMAV_GROUP@" + +/* name of the clamav user */ +#define CLAMAVUSER "@CLAMAV_USER@" + +/* enable debugging */ +#cmakedefine CL_DEBUG 1 + +/* enable experimental code */ +#cmakedefine CL_EXPERIMENTAL 1 + +/* thread safe */ +#cmakedefine CL_THREAD_SAFE 1 + +/* curses header location */ +#cmakedefine CURSES_INCLUDE @CURSES_INCLUDE@ + +/* os is aix */ +#cmakedefine C_AIX 1 + +/* os is beos */ +#cmakedefine C_BEOS 1 + +/* Increase thread stack size. */ +#cmakedefine C_BIGSTACK 1 + +/* os is bsd flavor */ +#cmakedefine C_BSD 1 + +/* os is darwin */ +#cmakedefine C_DARWIN 1 + +/* target is gnu-hurd */ +#cmakedefine C_GNU_HURD 1 + +/* os is hpux */ +#cmakedefine C_HPUX 1 + +/* os is interix */ +#cmakedefine C_INTERIX 1 + +/* os is irix */ +#cmakedefine C_IRIX 1 + +/* target is kfreebsd-gnu */ +#cmakedefine C_KFREEBSD_GNU 1 + +/* target is linux */ +#cmakedefine C_LINUX 1 + +/* os is OS/2 */ +#cmakedefine C_OS2 1 + +/* os is osf/tru64 */ +#cmakedefine C_OSF 1 + +/* os is QNX 6.x.x */ +#cmakedefine C_QNX6 1 + +/* os is solaris */ +#cmakedefine C_SOLARIS 1 + +#ifndef _WIN32 +/* Path to virus database directory. */ +#define DATADIR "@DATABASE_DIRECTORY@" + +/* where to look for the config file */ +#define CONFDIR "@APP_CONFIG_DIRECTORY@" +#endif + +/* Have sys/fanotify.h */ +#cmakedefine HAVE_SYS_FANOTIFY_H 1 + +/* whether _XOPEN_SOURCE needs to be defined for fd passing to work */ +#cmakedefine FDPASS_NEED_XOPEN 1 + +/* file i/o buffer size */ +#cmakedefine FILEBUFF @FILEBUFF@ + +/* scan buffer size */ +#cmakedefine SCANBUFF @SCANBUFF@ + +/* enable workaround for broken DNS servers */ +#cmakedefine FRESHCLAM_DNS_FIX 1 + +/* use "Cache-Control: no-cache" in freshclam */ +#cmakedefine FRESHCLAM_NO_CACHE 1 + +/* attrib aligned */ +#cmakedefine HAVE_ATTRIB_ALIGNED 1 + +/* attrib packed */ +#cmakedefine HAVE_ATTRIB_PACKED 1 + +/* have bzip2 */ +#cmakedefine HAVE_BZLIB_H 1 + +/* Define to 1 if you have the `ctime_r' function. */ +#cmakedefine HAVE_CTIME_R 1 + +/* ctime_r takes 2 arguments */ +#cmakedefine HAVE_CTIME_R_2 1 + +/* ctime_r takes 3 arguments */ +#cmakedefine HAVE_CTIME_R_3 1 + +/* Define to 1 if you have the declaration of `cygwin_conv_path', and to 0 if + you don't. */ +#cmakedefine HAVE_DECL_CYGWIN_CONV_PATH 1 + +/* Define to 1 if you have a deprecated version of the 'libjson' library + (-ljson). */ +#cmakedefine HAVE_DEPRECATED_JSON 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DIRENT_H 1 + +/* Define if you have the GNU dld library. */ +#cmakedefine HAVE_DLD 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DLD_H 1 + +/* Define to 1 if you have the `dlerror' function. */ +#cmakedefine HAVE_DLERROR 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DL_H 1 + +/* Define if you have the _dyld_func_lookup function. */ +#cmakedefine HAVE_DYLD 1 + +/* Define to 1 if you have the `enable_extended_FILE_stdio' function. */ +#cmakedefine HAVE_ENABLE_EXTENDED_FILE_STDIO 1 + +/* Define to 1 if the system has the type `error_t'. */ +#cmakedefine HAVE_ERROR_T 1 + +/* have working file descriptor passing support */ +#cmakedefine HAVE_FD_PASSING 1 + +/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ +#cmakedefine HAVE_FSEEKO 1 + +/* have getaddrinfo() */ +#cmakedefine HAVE_GETADDRINFO 1 + +/* Define to 1 if you have the `getnameinfo' function. */ +#cmakedefine HAVE_GETNAMEINFO 1 + +/* Define to 1 if getpagesize() is available */ +#cmakedefine HAVE_GETPAGESIZE 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_GRP_H 1 + +/* Define if you have the iconv() function and it works. */ +#cmakedefine HAVE_ICONV 1 + +/* Define to 1 if you have the `initgroups' function. */ +#cmakedefine HAVE_INITGROUPS 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the 'libjson' library (-ljson). */ +#cmakedefine HAVE_JSON 1 + +/* Define to '1' if you have the check.h library */ +#cmakedefine HAVE_LIBCHECK 1 + +/* Define to '1' if you have the ncurses.h library */ +#cmakedefine HAVE_LIBNCURSES 1 + +/* Define to '1' if you have the curses.h library */ +#cmakedefine HAVE_LIBPDCURSES 1 + +/* Define to 1 if you have the `ssl' library (-lssl). */ +#cmakedefine HAVE_LIBSSL 1 + +/* Define to 1 if you have the 'libxml2' library (-lxml2). */ +#cmakedefine HAVE_LIBXML2 1 + +/* Define to 1 if you have the `z' library (-lz). */ +#cmakedefine HAVE_LIBZ 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LIMITS_H 1 + +/* Define to 1 if you have the `madvise' function. */ +#cmakedefine HAVE_MADVISE 1 + +/* Define to 1 if you have the `mallinfo' function. */ +#cmakedefine HAVE_MALLINFO 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_MALLOC_H 1 + +/* Define to 1 if you have the `mkstemp' function. */ +#cmakedefine HAVE_MKSTEMP 1 + +/* Define to 1 if you have a working `mmap' system call that supports + MAP_PRIVATE. */ +#cmakedefine HAVE_MMAP 1 + +/* Define to 1 if you have a pcre library (-lpcre). */ +#cmakedefine HAVE_PCRE 1 + +/* Define to 1 if you using the pcre2 library. */ +#cmakedefine USING_PCRE2 1 + +/* Define to 1 if you have the `poll' function. */ +#cmakedefine HAVE_POLL 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_POLL_H 1 + +/* "pragma pack" */ +#cmakedefine HAVE_PRAGMA_PACK 1 + +/* "pragma pack hppa/hp-ux style" */ +#cmakedefine HAVE_PRAGMA_PACK_HPPA 1 + +/* Define if libtool can extract symbol lists from object files. */ +#cmakedefine HAVE_PRELOADED_SYMBOLS 1 + +/* Define to 1 if you have the header file */ +#cmakedefine HAVE_PTHREAD_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_PWD_H 1 + +/* Define to 1 if you have the `readdir' function. */ +#cmakedefine HAVE_READDIR 1 + +/* Define to 1 if you have the `recvmsg' function. */ +#cmakedefine HAVE_RECVMSG 1 + +/* have resolv.h */ +#cmakedefine HAVE_RESOLV_H 1 + +/* Define signed right shift implementation */ +#cmakedefine HAVE_SAR 1 + +/* Define to 1 if you have the `sched_yield' function. */ +#cmakedefine HAVE_SCHED_YIELD 1 + +/* Define to 1 if you have the `sendmsg' function. */ +#cmakedefine HAVE_SENDMSG 1 + +/* Define to 1 if you have the `setgroups' function. */ +#cmakedefine HAVE_SETGROUPS 1 + +/* Define to 1 if you have the `setsid' function. */ +#cmakedefine HAVE_SETSID 1 + +/* Define to 1 if you have the `snprintf' function. */ +#cmakedefine HAVE_SNPRINTF 1 + +/* enable stat64 */ +#cmakedefine HAVE_STAT64 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDBOOL_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `strcasestr' function. */ +#cmakedefine HAVE_STRCASESTR 1 + +/* Define to 1 if you have the `strerror_r' function. */ +#cmakedefine HAVE_STRERROR_R 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRING_H 1 + +/* Define to 1 if you have the `strlcat' function. */ +#cmakedefine HAVE_STRLCAT 1 + +/* Define to 1 if you have the `strlcpy' function. */ +#cmakedefine HAVE_STRLCPY 1 + +/* Define to 1 if you have the `strndup' function. */ +#cmakedefine HAVE_STRNDUP 1 + +/* using internal strn functions */ +#cmakedefine HAVE_STRNI 1 + +/* Define to 1 if you have the `strnlen' function. */ +#cmakedefine HAVE_STRNLEN 1 + +/* Define to 1 if you have the `strnstr' function. */ +#cmakedefine HAVE_STRNSTR 1 + +/* Define to 1 if sysconf(_SC_PAGESIZE) is available */ +#cmakedefine HAVE_SYSCONF_SC_PAGESIZE 1 + +/* Define to 1 if you have the `sysctlbyname' function. */ +#cmakedefine HAVE_SYSCTLBYNAME 1 + +/* systemd is supported */ +#cmakedefine HAVE_SYSTEMD 1 + +/* Use private fts() implementation which is LFS safe */ +#cmakedefine HAVE_SYSTEM_LFS_FTS 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_CDEFS_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_DL_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_FILIO_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_INT_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_MMAN_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_QUEUE_H 1 + +/* "have " */ +#cmakedefine HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TIMES_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_UIO_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_TERMIOS_H 1 + +/* Define to 1 if you have the `timegm' function. */ +#cmakedefine HAVE_TIMEGM 1 + +/* Define this if uname(2) is POSIX */ +#cmakedefine HAVE_UNAME_SYSCALL 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UNISTD_H 1 + +/* Define to 1 if you have the `vsnprintf' function. */ +#cmakedefine HAVE_VSNPRINTF 1 + +/* This value is set to 1 to indicate that the system argz facility works */ +#cmakedefine HAVE_WORKING_ARGZ 1 + +/* yara sources are compiled in */ +#cmakedefine HAVE_YARA 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_ZLIB_H 1 + +/* For internal use only - DO NOT DEFINE */ +#cmakedefine HAVE__INTERNAL__SHA_COLLECT 1 + +/* Define as const if the declaration of iconv() needs const. */ +#cmakedefine ICONV_CONST @ICONV_CONST@ + +/* "Full clamav library version number" */ +#define LIBCLAMAV_FULLVER "@LIBCLAMAV_VERSION@" + +/* "Major clamav library version number" */ +#define LIBCLAMAV_MAJORVER @LIBCLAMAV_SOVERSION@ + +/* "Full freshclam library version number" */ +#define LIBFRESHCLAM_FULLVER "@LIBFRESHCLAM_VERSION@" + +/* "Major freshclam library version number" */ +#define LIBFRESHCLAM_MAJORVER @LIBFRESHCLAM_SOVERSION@ + +/* The archive extension */ +#define LT_LIBEXT "@CMAKE_STATIC_LIBRARY_SUFFIX@" + +/* The archive prefix */ +#define LT_LIBPREFIX "@CMAKE_STATIC_LIBRARY_PREFIX@" + +/* Define to the extension used for runtime loadable modules, say, ".so" or ".dylib". */ +#define LT_MODULE_EXT "@CMAKE_SHARED_LIBRARY_SUFFIX@" + +/* Define to the name of the environment variable that determines the run-time + module search path. */ +#ifdef _WIN32 +#define SEARCH_LIBDIR "@CMAKE_INSTALL_PREFIX@" +#else +#define SEARCH_LIBDIR "@CMAKE_INSTALL_FULL_LIBDIR@" +#endif + +/* Define to the shared library suffix, say, ".dylib". */ +#define LT_SHARED_EXT "@CMAKE_SHARED_LIBRARY_SUFFIX@" + +/* disable assertions */ +#cmakedefine NDEBUG 1 + +/* Define if dlsym() requires a leading underscore in symbol names. */ +#cmakedefine NEED_USCORE 1 + +/* bzip funtions do not have bz2 prefix */ +#cmakedefine NOBZ2PREFIX 1 + +/* "no fd_set" */ +#cmakedefine NO_FD_SET 1 + +/* Name of package */ +#define PACKAGE "@PACKAGE_NAME@" + +/* Define to the address where bug reports for this package should be sent. */ +#cmakedefine PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@" + +/* Define to the full name of this package. */ +#cmakedefine PACKAGE_NAME "@PACKAGE_NAME@" + +/* Define to the full name and version of this package. */ +#cmakedefine PACKAGE_STRING "@PACKAGE_STRING@" + +/* Define to the one symbol short name of this package. */ +#cmakedefine PACKAGE_TARNAME "@PACKAGE_TARNAME@" + +/* Define to the home page for this package. */ +#cmakedefine PACKAGE_URL "@PACKAGE_URL@" + +/* Define to the version of this package. */ +#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@" + +/* Libprelude support enabled */ +#cmakedefine PRELUDE 1 + +/* Define whether application use libtool >= 2.0 */ +#cmakedefine PRELUDE_APPLICATION_USE_LIBTOOL2 1 + +/* Define to if the `setpgrp' function takes no argument. */ +#cmakedefine SETPGRP_VOID 1 + +/* The number of bytes in type int */ +#cmakedefine SIZEOF_INT @SIZEOF_INT@ + +/* The number of bytes in type long */ +#cmakedefine SIZEOF_LONG @SIZEOF_LONG@ + +/* The number of bytes in type long long */ +#cmakedefine SIZEOF_LONG_LONG @SIZEOF_LONG_LONG@ + +/* The number of bytes in type short */ +#cmakedefine SIZEOF_SHORT @SIZEOF_SHORT@ + +/* The number of bytes in type void * */ +#define SIZEOF_VOID_P @CMAKE_SIZEOF_VOID_P@ + +/* Define to if you have the ANSI C header files. */ +#cmakedefine STDC_HEADERS 1 + +/* Support for IPv6 */ +#cmakedefine SUPPORT_IPv6 1 + +/* enable memory pools */ +#cmakedefine USE_MPOOL 1 + +/* use syslog */ +#cmakedefine USE_SYSLOG 1 + +/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +#cmakedefine _ALL_SOURCE 1 +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +#cmakedefine _GNU_SOURCE 1 +#endif +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +#cmakedefine _POSIX_PTHREAD_SEMANTICS 1 +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +#cmakedefine _TANDEM_SOURCE 1 +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +#cmakedefine __EXTENSIONS__ 1 +#endif + +/* LLVM version (if found) */ +#cmakedefine LLVM_VERSION @LLVM_VERSION_MAJOR@@LLVM_VERSION_MINOR@ + +/* Version number of package */ +#cmakedefine VERSION "@PACKAGE_VERSION@" + +/* Version suffix for package */ +#cmakedefine VERSION_SUFFIX "@VERSION_SUFFIX@" + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +#cmakedefine WORDS_BIGENDIAN 1 +# endif +#endif + +/* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a + `char[]'. */ +#cmakedefine YYTEXT_POINTER 1 + +/* Enable large inode numbers on Mac OS X 10.5. */ +#ifndef _DARWIN_USE_64_BIT_INODE +# define _DARWIN_USE_64_BIT_INODE 1 +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +#cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@ + +/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */ +#cmakedefine _LARGEFILE_SOURCE 1 + +/* Define for large files, on AIX-style hosts. */ +#cmakedefine _LARGE_FILES 1 + +/* Define to 1 if on MINIX. */ +#cmakedefine _MINIX 1 + +/* Define to 2 if the system does not provide POSIX.1 features except with + this defined. */ +#cmakedefine _POSIX_1_SOURCE 2 + +/* POSIX compatibility */ +#cmakedefine _POSIX_PII_SOCKET 1 + +/* Define to 1 if you need to in order for `stat' and other things to work. */ +#cmakedefine _POSIX_SOURCE 1 + +/* thread safe */ +#cmakedefine _REENTRANT 1 + +/* Define so that glibc/gnulib argp.h does not typedef error_t. */ +#cmakedefine __error_t_defined 1 + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +#define inline @INLINE_KEYWORD@ +#endif + +/* Define to `long int' if does not define. */ +#cmakedefine off_t @off_t@ + +/* Define to `int' if does not define. */ +#cmakedefine ssize_t @ssize_t@ + +/* Define to the equivalent of the C99 'restrict' keyword, or to + nothing if this is not supported. Do not define if restrict is + supported directly. */ +#cmakedefine restrict @restrict@ + +/* Work around a bug in Sun C++: it does not support _Restrict or + __restrict__, even though the corresponding Sun C compiler ends up with + "#define restrict _Restrict" or "#define restrict __restrict__" in the + previous line. Perhaps some future version of Sun C++ will work with + restrict; if so, hopefully it defines __RESTRICT like Sun C does. */ +#if defined __SUNPRO_CC && !defined __RESTRICT +# define _Restrict +# define __restrict__ +#endif + +/* Define to "int" if does not define. */ +#cmakedefine socklen_t @socklen_t@ + +#include "platform.h" diff --git a/clamav-config.h.in b/clamav-config.h.in index 2a35b747f7..f4cccf8c8e 100644 --- a/clamav-config.h.in +++ b/clamav-config.h.in @@ -87,9 +87,6 @@ /* "default FD_SETSIZE value" */ #undef DEFAULT_FD_SETSIZE -/* use fanotify */ -#undef FANOTIFY - /* whether _XOPEN_SOURCE needs to be defined for fd passing to work */ #undef FDPASS_NEED_XOPEN @@ -414,6 +411,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_DL_H +/* use fanotify */ +#undef HAVE_SYS_FANOTIFY_H + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_FILIO_H diff --git a/clamav-milter/CMakeLists.txt b/clamav-milter/CMakeLists.txt new file mode 100644 index 0000000000..1fb3abb021 --- /dev/null +++ b/clamav-milter/CMakeLists.txt @@ -0,0 +1,27 @@ +# Copyright (C) 2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved. + +cmake_minimum_required( VERSION 3.12...3.13 ) + +# The clamav-milter executable. +add_executable( clamav-milter ) +target_sources( clamav-milter + PRIVATE + clamav-milter.c + clamfi.c + clamfi.h + connpool.c + connpool.h + netcode.c + netcode.h + whitelist.c + whitelist.h ) +target_include_directories( clamav-milter + PRIVATE ${CMAKE_BINARY_DIR} # For clamav-config.h +) +set_target_properties( clamav-milter PROPERTIES COMPILE_FLAGS "${WARNCFLAGS}" ) +target_link_libraries( clamav-milter + PRIVATE + ClamAV::libclamav + ClamAV::shared + Sendmail::milter ) +install(TARGETS clamav-milter DESTINATION ${CMAKE_INSTALL_SBINDIR}) diff --git a/clamav-milter/Makefile.am b/clamav-milter/Makefile.am index 38f0f93705..c37f532b05 100644 --- a/clamav-milter/Makefile.am +++ b/clamav-milter/Makefile.am @@ -24,14 +24,6 @@ if HAVE_MILTER sbin_PROGRAMS = clamav-milter clamav_milter_SOURCES = \ - $(top_srcdir)/shared/optparser.c \ - $(top_srcdir)/shared/optparser.h \ - $(top_srcdir)/shared/output.c \ - $(top_srcdir)/shared/output.h \ - $(top_srcdir)/shared/getopt.c \ - $(top_srcdir)/shared/getopt.h \ - $(top_srcdir)/shared/misc.c \ - $(top_srcdir)/shared/misc.h \ whitelist.c \ whitelist.h \ connpool.c \ @@ -47,7 +39,6 @@ AM_CFLAGS=@WERR_CFLAGS_MILTER@ endif endif -DEFS = @DEFS@ -DCL_NOLIBCLAMAV -LIBS = $(top_builddir)/libclamav/libclamav_internal_utils.la @CLAMAV_MILTER_LIBS@ @THREAD_LIBS@ -AM_CPPFLAGS = -I$(top_srcdir)/clamd -I$(top_srcdir)/libclamav -I$(top_srcdir)/shared -I$(top_srcdir) @SSL_CPPFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ +LIBS = $(top_builddir)/libclamav/libclamav.la $(top_builddir)/shared/libshared.la @CLAMAV_MILTER_LIBS@ @THREAD_LIBS@ +AM_CPPFLAGS = -I$(top_srcdir)/clamd -I$(top_srcdir)/libclamav -I$(top_builddir)/libclamav -I$(top_srcdir)/libclamunrar_iface -I$(top_srcdir)/shared -I$(top_srcdir) @SSL_CPPFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ CLEANFILES=*.gcda *.gcno diff --git a/clamav-milter/clamav-milter.c b/clamav-milter/clamav-milter.c index bc0db063d0..25a7bb137a 100644 --- a/clamav-milter/clamav-milter.c +++ b/clamav-milter/clamav-milter.c @@ -37,12 +37,14 @@ #include #include +// libclamav #include "clamav.h" +#include "default.h" -#include "shared/output.h" -#include "shared/optparser.h" -#include "shared/misc.h" -#include "libclamav/default.h" +// shared +#include "output.h" +#include "optparser.h" +#include "misc.h" #include "connpool.h" #include "netcode.h" diff --git a/clamav-milter/clamfi.c b/clamav-milter/clamfi.c index e212bb3f1a..455768f839 100644 --- a/clamav-milter/clamfi.c +++ b/clamav-milter/clamfi.c @@ -34,10 +34,13 @@ #include -#include "libclamav/clamav.h" -#include "shared/optparser.h" -#include "shared/output.h" -#include "libclamav/others.h" +// libclamav +#include "clamav.h" +#include "others.h" + +// shared +#include "optparser.h" +#include "output.h" #include "connpool.h" #include "netcode.h" diff --git a/clamav-milter/clamfi.h b/clamav-milter/clamfi.h index ea3fc04246..3a2cf22568 100644 --- a/clamav-milter/clamfi.h +++ b/clamav-milter/clamfi.h @@ -22,7 +22,7 @@ #ifndef _CLAMFI_H #define _CLAMFI_H -#include "shared/optparser.h" +#include "optparser.h" #include extern uint64_t maxfilesize; diff --git a/clamav-milter/connpool.c b/clamav-milter/connpool.c index 11bf666880..fb28e6a53d 100644 --- a/clamav-milter/connpool.c +++ b/clamav-milter/connpool.c @@ -36,9 +36,9 @@ #include #include -#include "shared/optparser.h" -#include "shared/output.h" -#include "shared/misc.h" +#include "optparser.h" +#include "output.h" +#include "misc.h" #include "connpool.h" #include "netcode.h" diff --git a/clamav-milter/connpool.h b/clamav-milter/connpool.h index 5db7698292..f8bb113de4 100644 --- a/clamav-milter/connpool.h +++ b/clamav-milter/connpool.h @@ -32,7 +32,7 @@ #include #include -#include "shared/optparser.h" +#include "optparser.h" struct CP_ENTRY { struct sockaddr *server; diff --git a/clamav-milter/netcode.c b/clamav-milter/netcode.c index 25fdff0407..ddec785bd4 100644 --- a/clamav-milter/netcode.c +++ b/clamav-milter/netcode.c @@ -28,7 +28,7 @@ #define __EXTENSIONS__ #endif /* must be first because it may define _XOPEN_SOURCE */ -#include "shared/fdpassing.h" +#include "fdpassing.h" #include #include #include @@ -45,10 +45,14 @@ #include #include -#include "libclamav/clamav.h" -#include "shared/output.h" -#include "shared/optparser.h" -#include "libclamav/others.h" +// libclamav +#include "clamav.h" +#include "others.h" + +// shared +#include "output.h" +#include "optparser.h" + #include "netcode.h" #define strerror_print(msg) logg(msg ": %s\n", cli_strerror(errno, er, sizeof(er))) diff --git a/clamav-milter/netcode.h b/clamav-milter/netcode.h index b124fa7f9e..a0e34caf3c 100644 --- a/clamav-milter/netcode.h +++ b/clamav-milter/netcode.h @@ -25,7 +25,7 @@ #include #include -#include "shared/optparser.h" +#include "optparser.h" #include "connpool.h" void nc_ping_entry(struct CP_ENTRY *cpe); diff --git a/clamav-milter/whitelist.c b/clamav-milter/whitelist.c index 087c41814f..f1e3791164 100644 --- a/clamav-milter/whitelist.c +++ b/clamav-milter/whitelist.c @@ -27,8 +27,12 @@ #include #include -#include "libclamav/regex/regex.h" -#include "shared/output.h" +// libclamav +#include "regex/regex.h" + +// shared +#include "output.h" + #include "whitelist.h" struct WHLST { diff --git a/clambc/CMakeLists.txt b/clambc/CMakeLists.txt new file mode 100644 index 0000000000..0dabc5ba9e --- /dev/null +++ b/clambc/CMakeLists.txt @@ -0,0 +1,33 @@ +# Copyright (C) 2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved. + +cmake_minimum_required( VERSION 3.12...3.13 ) + +if(WIN32) + add_definitions(-DWIN32_LEAN_AND_MEAN) + add_definitions(-DHAVE_STRUCT_TIMESPEC) + + # Windows compatibility headers + include_directories(${CMAKE_SOURCE_DIR}/win32/compat) +endif() + +# The clambc executable. +add_executable( clambc ) +target_sources( clambc + PRIVATE + bcrun.c ) +if(WIN32) + target_sources( clambc PRIVATE ${CMAKE_SOURCE_DIR}/win32/res/clambc.rc ) +endif() +target_include_directories( clambc + PRIVATE ${CMAKE_BINARY_DIR} # For clamav-config.h +) +set_target_properties( clambc PROPERTIES COMPILE_FLAGS "${WARNCFLAGS}" ) +target_link_libraries( clambc + PRIVATE + ClamAV::libclamav + ClamAV::shared ) +if(WIN32) + install(TARGETS clambc DESTINATION ${CMAKE_INSTALL_PREFIX}) +else() + install(TARGETS clambc DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/clambc/Makefile.am b/clambc/Makefile.am index 67b4350dc1..029bb66e7c 100644 --- a/clambc/Makefile.am +++ b/clambc/Makefile.am @@ -1,14 +1,8 @@ bin_PROGRAMS = clambc clambc_SOURCES = \ - $(top_srcdir)/shared/optparser.c \ - $(top_srcdir)/shared/optparser.h \ - $(top_srcdir)/shared/getopt.c \ - $(top_srcdir)/shared/getopt.h \ - $(top_srcdir)/shared/misc.c \ - $(top_srcdir)/shared/misc.h \ bcrun.c AM_CFLAGS=@WERR_CFLAGS@ @SSL_CPPFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ -AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav -LIBS = $(top_builddir)/libclamav/libclamav.la @THREAD_LIBS@ +AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav -I$(top_builddir)/libclamav -I$(top_srcdir)/libclamunrar_iface +LIBS = $(top_builddir)/libclamav/libclamav.la $(top_builddir)/shared/libshared.la @THREAD_LIBS@ CLEANFILES=*.gcda *.gcno diff --git a/clambc/bcrun.c b/clambc/bcrun.c index fe41a9dd03..66c09270eb 100644 --- a/clambc/bcrun.c +++ b/clambc/bcrun.c @@ -28,13 +28,16 @@ #endif #include +// libclamav +#include "clamav.h" +#include "dconf.h" +#include "others.h" #include "bytecode.h" #include "bytecode_priv.h" -#include "clamav.h" -#include "shared/optparser.h" -#include "shared/misc.h" -#include "libclamav/dconf.h" -#include "libclamav/others.h" + +// shared +#include "optparser.h" +#include "misc.h" #include #include diff --git a/clamconf/CMakeLists.txt b/clamconf/CMakeLists.txt new file mode 100644 index 0000000000..27ba9bd92f --- /dev/null +++ b/clamconf/CMakeLists.txt @@ -0,0 +1,33 @@ +# Copyright (C) 2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved. + +cmake_minimum_required( VERSION 3.12...3.13 ) + +if(WIN32) + add_definitions(-DWIN32_LEAN_AND_MEAN) + add_definitions(-DHAVE_STRUCT_TIMESPEC) + + # Windows compatibility headers + include_directories(${CMAKE_SOURCE_DIR}/win32/compat) +endif() + +# The clamconf executable. +add_executable( clamconf ) +target_sources( clamconf + PRIVATE + clamconf.c ) +if(WIN32) + target_sources( clamconf PRIVATE ${CMAKE_SOURCE_DIR}/win32/res/clamconf.rc ) +endif() +target_include_directories( clamconf + PRIVATE ${CMAKE_BINARY_DIR} # For clamav-config.h +) +set_target_properties( clamconf PROPERTIES COMPILE_FLAGS "${WARNCFLAGS}" ) +target_link_libraries( clamconf + PRIVATE + ClamAV::libclamav + ClamAV::shared ) +if(WIN32) + install(TARGETS clamconf DESTINATION ${CMAKE_INSTALL_PREFIX}) +else() + install(TARGETS clamconf DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/clamconf/Makefile.am b/clamconf/Makefile.am index be04f9cb74..e969ab24c2 100644 --- a/clamconf/Makefile.am +++ b/clamconf/Makefile.am @@ -21,21 +21,15 @@ bin_PROGRAMS = clamconf clamconf_SOURCES = \ - $(top_srcdir)/shared/optparser.c \ - $(top_srcdir)/shared/optparser.h \ - $(top_srcdir)/shared/getopt.c \ - $(top_srcdir)/shared/getopt.h \ - $(top_srcdir)/shared/misc.c \ - $(top_srcdir)/shared/misc.h \ clamconf.c AM_CFLAGS=@WERR_CFLAGS@ @SSL_CPPFLAGS@ -DEFS = @DEFS@ -DCL_NOTHREADS -AM_CPPFLAGS = @CLAMCONF_CPPFLAGS@ -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav\ +DEFS = @DEFS@ +AM_CPPFLAGS = @CLAMCONF_CPPFLAGS@ -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav -I$(top_builddir)/libclamav -I$(top_srcdir)/libclamunrar_iface \ @ZLIB_CFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@\ -DBUILD_CPPFLAGS="\"$(CPPFLAGS)\"" -DBUILD_CFLAGS="\"$(CFLAGS)\""\ -DBUILD_CXXFLAGS="\"$(CXXFLAGS)\"" -DBUILD_LDFLAGS="\"$(LDFLAGS)\""\ -DBUILD_CONFIGURE_FLAGS="\"$(BUILD_CONFIGURE_FLAGS)\"" -LIBS = $(top_builddir)/libclamav/libclamav.la @CLAMCONF_LIBS@ @CLAMD_LIBS@ @THREAD_LIBS@ @LIBCLAMAV_LIBS@ @ZLIB_LIBS@ +LIBS = $(top_builddir)/libclamav/libclamav.la $(top_builddir)/shared/libshared.la @CLAMCONF_LIBS@ @CLAMD_LIBS@ @THREAD_LIBS@ @LIBCLAMAV_LIBS@ @ZLIB_LIBS@ CLEANFILES=*.gcda *.gcno diff --git a/clamconf/clamconf.c b/clamconf/clamconf.c index d7423824f6..ec5f7e6daf 100644 --- a/clamconf/clamconf.c +++ b/clamconf/clamconf.c @@ -37,19 +37,22 @@ #include #include -#include "shared/optparser.h" -#include "shared/misc.h" - #include "clamav-config.h" -#include "libclamav/str.h" -#include "libclamav/clamav.h" -#include "libclamav/others.h" -#include "libclamav/readdb.h" -#include "libclamav/bytecode.h" -#include "libclamav/bytecode_detect.h" #include "target.h" + +// libclamav +#include "clamav.h" +#include "str.h" +#include "others.h" +#include "readdb.h" +#include "bytecode.h" +#include "bytecode_detect.h" #include "fpu.h" +// shared +#include "optparser.h" +#include "misc.h" + #ifndef _WIN32 extern const struct clam_option *clam_options; #else diff --git a/clamd/CMakeLists.txt b/clamd/CMakeLists.txt new file mode 100644 index 0000000000..b3799b6028 --- /dev/null +++ b/clamd/CMakeLists.txt @@ -0,0 +1,57 @@ +# Copyright (C) 2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved. + +cmake_minimum_required( VERSION 3.12...3.13 ) + +if(WIN32) + add_definitions(-DWIN32_LEAN_AND_MEAN) + add_definitions(-DHAVE_STRUCT_TIMESPEC) + + # Windows compatibility headers + include_directories(${CMAKE_SOURCE_DIR}/win32/compat) +endif() + +# The clamd executable. +add_executable( clamd ) +target_sources( clamd + PRIVATE + clamd.c + clamd_others.c + clamd_others.h + localserver.c + localserver.h + scanner.c + scanner.h + server-th.c + server.h + session.c + session.h + shared.h + tcpserver.c + tcpserver.h + thrmgr.c + thrmgr.h ) +if(WIN32) + target_sources( clamd PRIVATE ${CMAKE_SOURCE_DIR}/win32/res/clamd.rc ) +endif() +target_include_directories( clamd + PRIVATE ${CMAKE_BINARY_DIR} # For clamav-config.h +) +set_target_properties( clamd PROPERTIES COMPILE_FLAGS "${WARNCFLAGS}" ) +target_link_libraries( clamd + PRIVATE + ClamAV::libclamav + ClamAV::shared ) +if(WIN32) + install(TARGETS clamd DESTINATION ${CMAKE_INSTALL_PREFIX}) +else() + install(TARGETS clamd DESTINATION ${CMAKE_INSTALL_SBINDIR}) +endif() + +if(SYSTEMD_FOUND) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/clamav-daemon.service.in + ${CMAKE_CURRENT_BINARY_DIR}/clamav-daemon.service @ONLY) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/clamav-daemon.service + DESTINATION ${SYSTEMD_UNIT_DIR}) +endif() diff --git a/clamd/Makefile.am b/clamd/Makefile.am index c181a1f89a..be718cf9cb 100644 --- a/clamd/Makefile.am +++ b/clamd/Makefile.am @@ -23,16 +23,6 @@ if BUILD_CLAMD sbin_PROGRAMS = clamd clamd_SOURCES = \ - $(top_srcdir)/shared/output.c \ - $(top_srcdir)/shared/output.h \ - $(top_srcdir)/shared/idmef_logging.c \ - $(top_srcdir)/shared/idmef_logging.h \ - $(top_srcdir)/shared/optparser.c \ - $(top_srcdir)/shared/optparser.h \ - $(top_srcdir)/shared/getopt.c \ - $(top_srcdir)/shared/getopt.h \ - $(top_srcdir)/shared/misc.c \ - $(top_srcdir)/shared/misc.h \ clamd.c \ tcpserver.c \ tcpserver.h \ @@ -46,8 +36,8 @@ clamd_SOURCES = \ server.h \ scanner.c \ scanner.h \ - others.c \ - others.h \ + clamd_others.c \ + clamd_others.h \ shared.h AM_CFLAGS=@WERR_CFLAGS@ @@ -58,8 +48,8 @@ endif endif -LIBS = $(top_builddir)/libclamav/libclamav.la @CLAMD_LIBS@ @THREAD_LIBS@ -AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav @SSL_CPPFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ +LIBS = $(top_builddir)/libclamav/libclamav.la $(top_builddir)/shared/libshared.la @CLAMD_LIBS@ @THREAD_LIBS@ +AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav -I$(top_builddir)/libclamav -I$(top_srcdir)/libclamunrar_iface @SSL_CPPFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ # it does support --help and --version but with the default config file # it outputs an error message which tells us to edit the config files diff --git a/clamd/clamd.c b/clamd/clamd.c index 3807a0dfea..5b9f3a4bcd 100644 --- a/clamd/clamd.c +++ b/clamd/clamd.c @@ -56,19 +56,21 @@ #include "target.h" -#include "libclamav/clamav.h" -#include "libclamav/others.h" -#include "libclamav/matcher-ac.h" -#include "libclamav/readdb.h" +// libclamav +#include "clamav.h" +#include "others.h" +#include "matcher-ac.h" +#include "readdb.h" -#include "shared/output.h" -#include "shared/optparser.h" -#include "shared/misc.h" +// shared +#include "output.h" +#include "optparser.h" +#include "misc.h" #include "server.h" #include "tcpserver.h" #include "localserver.h" -#include "others.h" +#include "clamd_others.h" #include "shared.h" #include "scanner.h" diff --git a/clamd/others.c b/clamd/clamd_others.c similarity index 99% rename from clamd/others.c rename to clamd/clamd_others.c index 7c5d38a7ae..3c0d2f22ff 100644 --- a/clamd/others.c +++ b/clamd/clamd_others.c @@ -24,7 +24,7 @@ #endif /* must be first because it may define _XOPEN_SOURCE */ -#include "shared/fdpassing.h" +#include "fdpassing.h" #include #include #include @@ -67,15 +67,19 @@ #endif /* HAVE_POLL */ #include -#include "libclamav/clamav.h" -#include "libclamav/scanners.h" -#include "shared/optparser.h" -#include "shared/output.h" -#include "shared/misc.h" -#include "libclamav/others.h" +// libclamav +#include "clamav.h" +#include "scanners.h" #include "others.h" +// shared +#include "optparser.h" +#include "output.h" +#include "misc.h" + +#include "clamd_others.h" + static pthread_mutex_t virusaction_lock = PTHREAD_MUTEX_INITIALIZER; static void xfree(void *p) diff --git a/clamd/others.h b/clamd/clamd_others.h similarity index 98% rename from clamd/others.h rename to clamd/clamd_others.h index 054b91c133..f4b397185b 100644 --- a/clamd/others.h +++ b/clamd/clamd_others.h @@ -27,7 +27,7 @@ #endif #include -#include "shared/optparser.h" +#include "optparser.h" #include "thrmgr.h" #include "clamav-types.h" diff --git a/clamd/localserver.c b/clamd/localserver.c index dd34afec76..7d150a08c0 100644 --- a/clamd/localserver.c +++ b/clamd/localserver.c @@ -36,14 +36,16 @@ #include #endif -#include "libclamav/clamav.h" -#include "libclamav/str.h" +// libclamav +#include "clamav.h" +#include "str.h" -#include "shared/optparser.h" -#include "shared/output.h" -#include "shared/misc.h" +// shared +#include "optparser.h" +#include "output.h" +#include "misc.h" -#include "others.h" +#include "clamd_others.h" #include "server.h" #include "localserver.h" diff --git a/clamd/localserver.h b/clamd/localserver.h index 942b2d1af0..4f9f7e3d5d 100644 --- a/clamd/localserver.h +++ b/clamd/localserver.h @@ -22,7 +22,7 @@ #ifndef __LOCALSERVER_H #define __LOCALSERVER_H -#include "shared/optparser.h" +#include "optparser.h" int localserver(const struct optstruct *opts); diff --git a/clamd/scanner.c b/clamd/scanner.c index 71ce0580e3..5087458bfe 100644 --- a/clamd/scanner.c +++ b/clamd/scanner.c @@ -45,16 +45,18 @@ #endif #include -#include "libclamav/clamav.h" -#include "libclamav/others.h" -#include "libclamav/scanners.h" +// libclamav +#include "clamav.h" +#include "others.h" +#include "scanners.h" -#include "shared/idmef_logging.h" -#include "shared/optparser.h" -#include "shared/output.h" -#include "shared/misc.h" +// shared +#include "idmef_logging.h" +#include "optparser.h" +#include "output.h" +#include "misc.h" -#include "others.h" +#include "clamd_others.h" #include "scanner.h" #include "shared.h" #include "thrmgr.h" diff --git a/clamd/scanner.h b/clamd/scanner.h index 860f8a4f27..f43b9df8ef 100644 --- a/clamd/scanner.h +++ b/clamd/scanner.h @@ -24,9 +24,13 @@ #include -#include "libclamav/others.h" -#include "libclamav/clamav.h" -#include "shared/optparser.h" +// libclamav +#include "clamav.h" +#include "others.h" + +// shared +#include "optparser.h" + #include "thrmgr.h" #include "session.h" diff --git a/clamd/server-th.c b/clamd/server-th.c index 19ee80614b..b11ac1cf6c 100644 --- a/clamd/server-th.c +++ b/clamd/server-th.c @@ -45,21 +45,23 @@ #ifdef C_SOLARIS #include #endif -#include "libclamav/clamav.h" -#include "shared/output.h" -#include "shared/optparser.h" -#include "shared/misc.h" +// libclamav +#include "clamav.h" +#include "others.h" +#include "readdb.h" -#include "shared/idmef_logging.h" +// shared +#include "output.h" +#include "optparser.h" +#include "misc.h" +#include "idmef_logging.h" #include "server.h" #include "thrmgr.h" #include "session.h" -#include "others.h" +#include "clamd_others.h" #include "shared.h" -#include "libclamav/others.h" -#include "libclamav/readdb.h" #define BUFFSIZE 1024 diff --git a/clamd/server.h b/clamd/server.h index 2d20a5dc35..1f2e78ed75 100644 --- a/clamd/server.h +++ b/clamd/server.h @@ -26,10 +26,15 @@ #include #include -#include "libclamav/clamav.h" -#include "shared/optparser.h" +// libclamav +#include "clamav.h" + +// shared +#include "optparser.h" + #include "thrmgr.h" #include "session.h" + struct thrarg { int sid; struct cl_scan_options *options; diff --git a/clamd/session.c b/clamd/session.c index 0fdde3e504..6693631bda 100644 --- a/clamd/session.c +++ b/clamd/session.c @@ -50,15 +50,17 @@ #include #include -#include "libclamav/clamav.h" -#include "libclamav/str.h" -#include "libclamav/others.h" +// libclamav +#include "clamav.h" +#include "str.h" +#include "others.h" -#include "shared/optparser.h" -#include "shared/output.h" -#include "shared/misc.h" +// shared +#include "optparser.h" +#include "output.h" +#include "misc.h" -#include "others.h" +#include "clamd_others.h" #include "scanner.h" #include "server.h" #include "session.h" diff --git a/clamd/session.h b/clamd/session.h index 0a9f11b81f..26869e5e30 100644 --- a/clamd/session.h +++ b/clamd/session.h @@ -49,10 +49,14 @@ #define CMD23 "GET / HTTP/2" #define CMD24 "" -#include "libclamav/clamav.h" -#include "shared/optparser.h" +// libclamav +#include "clamav.h" + +// shared +#include "optparser.h" + #include "server.h" -#include "others.h" +#include "clamd_others.h" enum commands { COMMAND_UNKNOWN = 0, diff --git a/clamd/tcpserver.c b/clamd/tcpserver.c index 114b180fc6..0eda1a220b 100644 --- a/clamd/tcpserver.c +++ b/clamd/tcpserver.c @@ -37,13 +37,15 @@ #endif #include -#include "libclamav/clamav.h" +// libclamav +#include "clamav.h" -#include "shared/optparser.h" -#include "shared/output.h" -#include "shared/misc.h" +// shared +#include "optparser.h" +#include "output.h" +#include "misc.h" -#include "others.h" +#include "clamd_others.h" #include "server.h" #include "tcpserver.h" diff --git a/clamd/tcpserver.h b/clamd/tcpserver.h index c52bf67291..a01a734495 100644 --- a/clamd/tcpserver.h +++ b/clamd/tcpserver.h @@ -22,7 +22,7 @@ #ifndef __TCPSERVER_H #define __TCPSERVER_H -#include "shared/optparser.h" +#include "optparser.h" int tcpserver(int **lsockets, unsigned int *nlsockets, char *ipaddr, const struct optstruct *opts); diff --git a/clamd/thrmgr.c b/clamd/thrmgr.c index c021658049..046b9b2b58 100644 --- a/clamd/thrmgr.c +++ b/clamd/thrmgr.c @@ -30,14 +30,17 @@ #include #include -#include "shared/output.h" - -#include "libclamav/clamav.h" -#include "thrmgr.h" +// libclamav +#include "clamav.h" #include "others.h" #include "mpool.h" + +// shared +#include "output.h" + +#include "thrmgr.h" +#include "clamd_others.h" #include "server.h" -#include "libclamav/others.h" #ifdef HAVE_MALLINFO #include diff --git a/clamdscan/CMakeLists.txt b/clamdscan/CMakeLists.txt new file mode 100644 index 0000000000..7357967819 --- /dev/null +++ b/clamdscan/CMakeLists.txt @@ -0,0 +1,37 @@ +# Copyright (C) 2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved. + +cmake_minimum_required( VERSION 3.12...3.13 ) + +if(WIN32) + add_definitions(-DWIN32_LEAN_AND_MEAN) + add_definitions(-DHAVE_STRUCT_TIMESPEC) + + # Windows compatibility headers + include_directories(${CMAKE_SOURCE_DIR}/win32/compat) +endif() + +# The clamdscan executable. +add_executable( clamdscan ) +target_sources( clamdscan + PRIVATE + clamdscan.c + client.c + client.h + proto.c + proto.h ) +if(WIN32) + target_sources( clamdscan PRIVATE ${CMAKE_SOURCE_DIR}/win32/res/clamdscan.rc ) +endif() +target_include_directories( clamdscan + PRIVATE ${CMAKE_BINARY_DIR} # For clamav-config.h +) +set_target_properties( clamdscan PROPERTIES COMPILE_FLAGS "${WARNCFLAGS}" ) +target_link_libraries( clamdscan + PRIVATE + ClamAV::libclamav + ClamAV::shared ) +if(WIN32) + install(TARGETS clamdscan DESTINATION ${CMAKE_INSTALL_PREFIX}) +else() + install(TARGETS clamdscan DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/clamdscan/Makefile.am b/clamdscan/Makefile.am index 25bb510b22..8c066eca39 100644 --- a/clamdscan/Makefile.am +++ b/clamdscan/Makefile.am @@ -22,18 +22,6 @@ if BUILD_CLAMD bin_PROGRAMS = clamdscan clamdscan_SOURCES = \ - $(top_srcdir)/shared/output.c \ - $(top_srcdir)/shared/output.h \ - $(top_srcdir)/shared/optparser.c \ - $(top_srcdir)/shared/optparser.h \ - $(top_srcdir)/shared/misc.c \ - $(top_srcdir)/shared/misc.h \ - $(top_srcdir)/shared/getopt.c \ - $(top_srcdir)/shared/getopt.h \ - $(top_srcdir)/shared/actions.c \ - $(top_srcdir)/shared/actions.h \ - $(top_srcdir)/shared/clamdcom.c \ - $(top_srcdir)/shared/clamdcom.h \ clamdscan.c \ proto.c \ proto.h \ @@ -44,9 +32,8 @@ AM_CFLAGS=@WERR_CFLAGS@ endif -DEFS = @DEFS@ -DCL_NOTHREADS -DCL_NOLIBCLAMAV -AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/clamscan -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav @SSL_CPPFLAGS@ @CLAMDSCAN_CPPFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ -LIBS = $(top_builddir)/libclamav/libclamav_internal_utils_nothreads.la @CLAMDSCAN_LIBS@ +AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/clamscan -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav -I$(top_builddir)/libclamav -I$(top_srcdir)/libclamunrar_iface @SSL_CPPFLAGS@ @CLAMDSCAN_CPPFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ +LIBS = $(top_builddir)/shared/libshared.la $(top_builddir)/libclamav/libclamav.la @CLAMDSCAN_LIBS@ @THREAD_LIBS@ AM_INSTALLCHECK_STD_OPTIONS_EXEMPT=clamdscan$(EXEEXT) CLEANFILES=*.gcda *.gcno diff --git a/clamdscan/clamdscan.c b/clamdscan/clamdscan.c index 5a7b5b93fd..a82755f27a 100644 --- a/clamdscan/clamdscan.c +++ b/clamdscan/clamdscan.c @@ -35,13 +35,14 @@ #include #include +// libclamav #include "clamav.h" -#include "libclamav/clamav.h" -#include "shared/output.h" -#include "shared/misc.h" -#include "shared/optparser.h" -#include "shared/actions.h" +// shared +#include "output.h" +#include "misc.h" +#include "optparser.h" +#include "actions.h" #include "client.h" diff --git a/clamdscan/client.c b/clamdscan/client.c index c24db09377..1a8f0ed92b 100644 --- a/clamdscan/client.c +++ b/clamdscan/client.c @@ -53,15 +53,17 @@ #include #endif -#include "libclamav/clamav.h" -#include "shared/optparser.h" -#include "shared/output.h" -#include "shared/misc.h" -#include "shared/actions.h" -#include "shared/clamdcom.h" - -#include "libclamav/str.h" -#include "libclamav/others.h" +// libclamav +#include "clamav.h" +#include "str.h" +#include "others.h" + +// shared +#include "optparser.h" +#include "output.h" +#include "misc.h" +#include "actions.h" +#include "clamdcom.h" #include "client.h" #include "proto.h" diff --git a/clamdscan/client.h b/clamdscan/client.h index bfe5e4bd32..b13b4afa52 100644 --- a/clamdscan/client.h +++ b/clamdscan/client.h @@ -25,7 +25,7 @@ #define CLAMDSCAN_DEFAULT_PING_INTERVAL 1 #define CLAMDSCAN_DEFAULT_PING_ATTEMPTS 30 -#include "shared/optparser.h" +#include "optparser.h" enum { CONT, diff --git a/clamdscan/proto.c b/clamdscan/proto.c index 9585efc6d4..ee13f870ba 100644 --- a/clamdscan/proto.c +++ b/clamdscan/proto.c @@ -30,7 +30,7 @@ #endif /* must be first because it may define _XOPEN_SOURCE */ -#include "shared/fdpassing.h" +#include "fdpassing.h" #include #ifdef HAVE_UNISTD_H #include @@ -52,12 +52,15 @@ #include #endif -#include "libclamav/clamav.h" -#include "libclamav/others.h" -#include "shared/actions.h" -#include "shared/output.h" -#include "shared/misc.h" -#include "shared/clamdcom.h" +// libclamav +#include "clamav.h" +#include "others.h" + +// shared +#include "actions.h" +#include "output.h" +#include "misc.h" +#include "clamdcom.h" #include "proto.h" #include "client.h" diff --git a/clamdscan/proto.h b/clamdscan/proto.h index e6cb2c3225..fff1924676 100644 --- a/clamdscan/proto.h +++ b/clamdscan/proto.h @@ -21,7 +21,7 @@ #ifndef PROTO_H #define PROTO_H -#include "shared/misc.h" +#include "misc.h" int dconnect(void); int serial_client_scan(char *file, int scantype, int *infected, int *err, int maxlevel, int flags); diff --git a/clamdtop/CMakeLists.txt b/clamdtop/CMakeLists.txt new file mode 100644 index 0000000000..1f4dda14f1 --- /dev/null +++ b/clamdtop/CMakeLists.txt @@ -0,0 +1,34 @@ +# Copyright (C) 2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved. + +cmake_minimum_required( VERSION 3.12...3.13 ) + +if(WIN32) + add_definitions(-DWIN32_LEAN_AND_MEAN) + add_definitions(-DHAVE_STRUCT_TIMESPEC) + + # Windows compatibility headers + include_directories(${CMAKE_SOURCE_DIR}/win32/compat) +endif() + +# The clamdtop executable. +add_executable( clamdtop ) +target_sources( clamdtop + PRIVATE + clamdtop.c ) +if(WIN32) + target_sources( clamdtop PRIVATE ${CMAKE_SOURCE_DIR}/win32/res/clamdtop.rc ) +endif() +target_include_directories( clamdtop + PRIVATE ${CMAKE_BINARY_DIR} # For clamav-config.h +) +set_target_properties( clamdtop PROPERTIES COMPILE_FLAGS "${WARNCFLAGS}" ) +target_link_libraries( clamdtop + PRIVATE + ClamAV::libclamav + ClamAV::shared + Curses::curses ) +if(WIN32) + install(TARGETS clamdtop DESTINATION ${CMAKE_INSTALL_PREFIX}) +else() + install(TARGETS clamdtop DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/clamdtop/Makefile.am b/clamdtop/Makefile.am index d24a28a66e..c1735e2fa1 100644 --- a/clamdtop/Makefile.am +++ b/clamdtop/Makefile.am @@ -2,17 +2,15 @@ if HAVE_CURSES bin_PROGRAMS = clamdtop man_MANS = $(top_builddir)/docs/man/clamdtop.1 clamdtop_SOURCES = \ - $(top_srcdir)/shared/optparser.c \ - $(top_srcdir)/shared/optparser.h \ - $(top_srcdir)/shared/getopt.c \ - $(top_srcdir)/shared/getopt.h \ - $(top_srcdir)/shared/misc.c \ - $(top_srcdir)/shared/misc.h \ clamdtop.c AM_CFLAGS=@WERR_CFLAGS@ -AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav @SSL_CPPFLAGS@ @CURSES_CPPFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ -clamdtop_LDADD = @SSL_LDFLAGS@ @SSL_LIBS@ @CURSES_LIBS@ $(top_builddir)/libclamav/libclamav_internal_utils_nothreads.la +AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav -I$(top_builddir)/libclamav -I$(top_srcdir)/libclamunrar_iface @SSL_CPPFLAGS@ @CURSES_CPPFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ +clamdtop_LDADD = @SSL_LDFLAGS@ @SSL_LIBS@ @CURSES_LIBS@ @THREAD_LIBS@ $(top_builddir)/shared/libshared.la $(top_builddir)/libclamav/libclamav.la endif -DEFS = @DEFS@ -DCL_NOTHREADS -DCL_NOLIBCLAMAV + +DEFS = @DEFS@ + +# Add clamdtop.c to extra_dist so make dist will include it even if curses +# wasn't detected on this dist builder. EXTRA_DIST = clamdtop.c diff --git a/clamdtop/clamdtop.c b/clamdtop/clamdtop.c index ea3201ee85..8d13c98080 100644 --- a/clamdtop/clamdtop.c +++ b/clamdtop/clamdtop.c @@ -60,11 +60,15 @@ #include #include -#include "libclamav/clamav.h" -#include "shared/optparser.h" -#include "shared/misc.h" #include "platform.h" +// libclamav +#include "clamav.h" + +// shared +#include "optparser.h" +#include "misc.h" + /* Types, prototypes and globals*/ typedef struct connection { int sd; @@ -441,7 +445,7 @@ static void cleanup(void) for (i = 0; i < global.num_clamd; i++) { if (global.conn[i].sd && global.conn[i].sd != -1) { (void)send_string_noreconn(&global.conn[i], "nEND\n"); -#ifndef WIN32 +#ifndef _WIN32 close(global.conn[i].sd); #else closesocket(global.conn[i].sd); @@ -718,7 +722,7 @@ static int make_connection_real(const char *soname, conn_t *conn) print_con_info(conn, "Connecting to: %s\n", soname); if (connect(s, p->ai_addr, p->ai_addrlen)) { perror("connect"); -#ifndef WIN32 +#ifndef _WIN32 close(s); #else closesocket(s); @@ -826,7 +830,7 @@ static void reconnect(conn_t *conn) EXIT_PROGRAM(RECONNECT_FAIL); } if (conn->sd != -1) { -#ifndef WIN32 +#ifndef _WIN32 close(conn->sd); #else closesocket(conn->sd); @@ -855,7 +859,7 @@ static int recv_line(conn_t *conn, char *buf, size_t len) print_con_info(conn, "%s: %s", conn->remote, strerror(errno)); /* it could be a timeout, be nice and send an END */ (void)send_string_noreconn(conn, "nEND\n"); -#ifndef WIN32 +#ifndef _WIN32 close(conn->sd); #else closesocket(conn->sd); diff --git a/clamonacc/CMakeLists.txt b/clamonacc/CMakeLists.txt new file mode 100644 index 0000000000..b731ad9f25 --- /dev/null +++ b/clamonacc/CMakeLists.txt @@ -0,0 +1,60 @@ +# Copyright (C) 2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved. + +cmake_minimum_required( VERSION 3.12...3.13 ) + +# The clamonacc executable. +add_executable( clamonacc ) +target_sources( clamonacc + PRIVATE + clamonacc.c + clamonacc.h + c-thread-pool/thpool.c + c-thread-pool/thpool.h + client/client.c + client/client.h + client/communication.c + client/communication.h + client/protocol.c + client/protocol.h + fanotif/fanotif.c + fanotif/fanotif.h + inotif/inotif.c + inotif/inotif.h + inotif/hash.c + inotif/hash.h + misc/priv_fts.h + misc/utils.c + misc/utils.h + scan/onas_queue.c + scan/onas_queue.h + scan/thread.c + scan/thread.h ) + +if(NOT HAVE_SYSTEM_LFS_FTS) + target_sources( clamonacc + PRIVATE + misc/fts.c ) +endif() + +target_include_directories( clamonacc + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} # So subdir source can #include "clamonacc.h" + ${CMAKE_BINARY_DIR} # For clamav-config.h + ${CMAKE_SOURCE_DIR}/clamd # Yes, this is a hack! We want to use clamd headers even though clamd isn't a library. +) + +set_target_properties( clamonacc PROPERTIES COMPILE_FLAGS "${WARNCFLAGS}" ) +target_link_libraries( clamonacc + PRIVATE + ClamAV::libclamav + ClamAV::shared ) +install(TARGETS clamonacc DESTINATION ${CMAKE_INSTALL_SBINDIR}) + +if(SYSTEMD_FOUND) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/clamav-clamonacc.service.in + ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamonacc.service @ONLY) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamonacc.service + DESTINATION ${SYSTEMD_UNIT_DIR}) +endif() diff --git a/clamonacc/Makefile.am b/clamonacc/Makefile.am index 799715779c..181e22056f 100644 --- a/clamonacc/Makefile.am +++ b/clamonacc/Makefile.am @@ -21,39 +21,29 @@ sbin_PROGRAMS = clamonacc clamonacc_SOURCES = \ - $(top_srcdir)/shared/output.c \ - $(top_srcdir)/shared/output.h \ - $(top_srcdir)/shared/optparser.c \ - $(top_srcdir)/shared/optparser.h \ - $(top_srcdir)/shared/misc.c \ - $(top_srcdir)/shared/misc.h \ - $(top_srcdir)/shared/getopt.c \ - $(top_srcdir)/shared/getopt.h \ - $(top_srcdir)/shared/actions.c \ - $(top_srcdir)/shared/actions.h \ clamonacc.c \ clamonacc.h \ - ./client/client.c \ - ./client/client.h \ - ./client/protocol.c \ - ./client/protocol.h \ - ./client/communication.c \ - ./client/communication.h \ - ./inotif/inotif.c \ - ./inotif/inotif.h \ - ./fanotif/fanotif.c \ - ./fanotif/fanotif.h \ - ./inotif/hash.c \ - ./inotif/hash.h \ - ./misc/utils.c \ - ./misc/utils.h \ - ./misc/priv_fts.h \ - ./scan/thread.c \ - ./scan/thread.h \ - ./scan/queue.c \ - ./scan/queue.h \ - ./c-thread-pool/thpool.c \ - ./c-thread-pool/thpool.h + client/client.c \ + client/client.h \ + client/protocol.c \ + client/protocol.h \ + client/communication.c \ + client/communication.h \ + inotif/inotif.c \ + inotif/inotif.h \ + fanotif/fanotif.c \ + fanotif/fanotif.h \ + inotif/hash.c \ + inotif/hash.h \ + misc/utils.c \ + misc/utils.h \ + misc/priv_fts.h \ + scan/thread.c \ + scan/thread.h \ + scan/onas_queue.c \ + scan/onas_queue.h \ + c-thread-pool/thpool.c \ + c-thread-pool/thpool.h if !SYSTEM_LFS_FTS @@ -62,9 +52,12 @@ endif AM_CFLAGS=@WERR_CFLAGS@ -DEFS = @DEFS@ -DCL_NOLIBCLAMAV -LIBS = $(top_builddir)/libclamav/libclamav_internal_utils.la @CURL_LIBS@ @CLAMONACC_LIBS@ @THREAD_LIBS@ -AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/clamonacc -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav @CURL_CPPFLAGS@ @SSL_CPPFLAGS@ @CLAMONACC_CPPFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ +if INSTALL_SYSTEMD_UNITS +systemdsystemunit_DATA = clamav-clamonacc.service +endif + +LIBS = $(top_builddir)/shared/libshared.la $(top_builddir)/libclamav/libclamav.la @CURL_LIBS@ @CLAMONACC_LIBS@ @THREAD_LIBS@ +AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/clamonacc -I$(top_srcdir)/shared -I$(top_srcdir)/clamd -I$(top_srcdir)/libclamav -I$(top_builddir)/libclamav -I$(top_srcdir)/libclamunrar_iface @CURL_CPPFLAGS@ @SSL_CPPFLAGS@ @CLAMONACC_CPPFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ AM_INSTALLCHECK_STD_OPTIONS_EXEMPT=clamonacc$(EXEEXT) CLEANFILES=*.gcda *.gcno diff --git a/clamonacc/clamav-clamonacc.service.in b/clamonacc/clamav-clamonacc.service.in new file mode 100644 index 0000000000..c031db3ebc --- /dev/null +++ b/clamonacc/clamav-clamonacc.service.in @@ -0,0 +1,17 @@ +# clamonacc systemd service file primarily the work of ChadDevOps & Aaron Brighton +# See: https://medium.com/@aaronbrighton/installation-configuration-of-clamav-antivirus-on-ubuntu-18-04-a6416bab3b41#a340 + +[Unit] +Description=ClamAV On-Access Scanner +Documentation=man:clamonacc(8) man:clamd.conf(5) https://www.clamav.net/documents +Requires=clamav-daemon.service +After=clamav-daemon.service syslog.target network.target + +[Service] +Type=simple +User=root +ExecStartPre=/bin/bash -c "while [ ! -S /run/clamav/clamd.ctl ]; do sleep 1; done" +ExecStart=@prefix@/sbin/clamonacc -F --config-file=@APP_CONFIG_DIRECTORY@/clamd.conf --log=/var/log/clamav/clamonacc.log --move=/root/quarantine + +[Install] +WantedBy=multi-user.target diff --git a/clamonacc/clamonacc.c b/clamonacc/clamonacc.c index c82d4075e9..8e87772f54 100644 --- a/clamonacc/clamonacc.c +++ b/clamonacc/clamonacc.c @@ -35,25 +35,28 @@ #endif #include #include -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) #include -#include #endif +#include #include -#include "libclamav/clamav.h" -#include "libclamav/others.h" -#include "shared/output.h" -#include "shared/misc.h" -#include "shared/optparser.h" -#include "shared/actions.h" +// libclamav +#include "clamav.h" +#include "others.h" + +// shared +#include "output.h" +#include "misc.h" +#include "optparser.h" +#include "actions.h" #include "clamonacc.h" #include "client/client.h" #include "fanotif/fanotif.h" #include "inotif/inotif.h" -#include "scan/queue.h" +#include "scan/onas_queue.h" pthread_t ddd_pid = 0; pthread_t scan_queue_pid = 0; @@ -178,7 +181,7 @@ int main(int argc, char **argv) break; } -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) /* Setup fanotify */ switch (onas_setup_fanotif(&ctx)) { case CL_SUCCESS: @@ -294,7 +297,7 @@ int onas_start_eloop(struct onas_context **ctx) return CL_EARG; } -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) ret = onas_fan_eloop(ctx); #endif @@ -304,7 +307,7 @@ int onas_start_eloop(struct onas_context **ctx) static int startup_checks(struct onas_context *ctx) { -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) char faerr[128]; #endif int ret = 0; @@ -316,7 +319,7 @@ static int startup_checks(struct onas_context *ctx) goto done; } -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) ctx->fan_fd = fanotify_init(FAN_CLASS_CONTENT | FAN_UNLIMITED_QUEUE | FAN_UNLIMITED_MARKS, O_LARGEFILE | O_RDONLY); if (ctx->fan_fd < 0) { logg("!Clamonacc: fanotify_init failed: %s\n", cli_strerror(errno, faerr, sizeof(faerr))); diff --git a/clamonacc/clamonacc.h b/clamonacc/clamonacc.h index 4bf38f9cea..8240364d88 100644 --- a/clamonacc/clamonacc.h +++ b/clamonacc/clamonacc.h @@ -22,7 +22,8 @@ #ifndef __ONAS_CLAMONACC_H #define __ONAS_CLAMONACC_H -#include "libclamav/clamav.h" +// libclamav +#include "clamav.h" #ifndef ONAS_DEBUG #define ONAS_DEBUG diff --git a/clamonacc/client/client.c b/clamonacc/client/client.c index a18e6966c6..7ad4fce62f 100644 --- a/clamonacc/client/client.c +++ b/clamonacc/client/client.c @@ -52,14 +52,16 @@ #include #endif -#include "libclamav/clamav.h" -#include "shared/optparser.h" -#include "shared/output.h" -#include "shared/misc.h" -#include "shared/actions.h" - -#include "libclamav/str.h" -#include "libclamav/others.h" +// libclamav +#include "clamav.h" +#include "str.h" +#include "others.h" + +// shared +#include "optparser.h" +#include "output.h" +#include "misc.h" +#include "actions.h" #include "communication.h" #include "client.h" diff --git a/clamonacc/client/client.h b/clamonacc/client/client.h index 42bd52720d..1b6be9c30d 100644 --- a/clamonacc/client/client.h +++ b/clamonacc/client/client.h @@ -24,7 +24,7 @@ #include -#include "shared/optparser.h" +#include "optparser.h" #include "../clamonacc.h" #define ONAS_DEFAULT_PING_INTERVAL 1 diff --git a/clamonacc/client/communication.c b/clamonacc/client/communication.c index faccd54ccc..d6a122e71b 100644 --- a/clamonacc/client/communication.c +++ b/clamonacc/client/communication.c @@ -38,7 +38,7 @@ #include #endif -#include "shared/output.h" +#include "output.h" #include "communication.h" diff --git a/clamonacc/client/communication.h b/clamonacc/client/communication.h index 01ce7eef1e..e8b638599b 100644 --- a/clamonacc/client/communication.h +++ b/clamonacc/client/communication.h @@ -30,7 +30,7 @@ #include #endif -#include "shared/misc.h" +#include "misc.h" struct RCVLN { char buf[PATH_MAX + 1024]; diff --git a/clamonacc/client/protocol.c b/clamonacc/client/protocol.c index d796e1906d..4ad3315776 100644 --- a/clamonacc/client/protocol.c +++ b/clamonacc/client/protocol.c @@ -30,7 +30,7 @@ #endif /* must be first because it may define _XOPEN_SOURCE */ -#include "shared/fdpassing.h" +#include "fdpassing.h" #include #include #ifdef HAVE_UNISTD_H @@ -53,11 +53,14 @@ #include #endif -#include "libclamav/clamav.h" -#include "libclamav/others.h" -#include "shared/actions.h" -#include "shared/output.h" -#include "shared/misc.h" +// libclamav +#include "clamav.h" +#include "others.h" + +// shared +#include "actions.h" +#include "output.h" +#include "misc.h" #include "communication.h" #include "protocol.h" diff --git a/clamonacc/client/protocol.h b/clamonacc/client/protocol.h index 683eeb0b43..82d5964668 100644 --- a/clamonacc/client/protocol.h +++ b/clamonacc/client/protocol.h @@ -24,7 +24,7 @@ #include -#include "shared/misc.h" +#include "misc.h" #include "../clamonacc.h" int onas_dsresult(CURL *curl, int scantype, uint64_t maxstream, const char *filename, int fd, int64_t timeout, int *printok, int *errors, cl_error_t *ret_code); diff --git a/clamonacc/fanotif/fanotif.c b/clamonacc/fanotif/fanotif.c index ee898f451b..f6b911b943 100644 --- a/clamonacc/fanotif/fanotif.c +++ b/clamonacc/fanotif/fanotif.c @@ -22,7 +22,7 @@ #include "clamav-config.h" #endif -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) #include #include @@ -36,13 +36,16 @@ #include -#include "libclamav/clamav.h" -#include "libclamav/scanners.h" +// libclamav +#include "clamav.h" +#include "scanners.h" -#include "shared/optparser.h" -#include "shared/output.h" +// shared +#include "optparser.h" +#include "output.h" -#include "clamd/server.h" +// clamd +#include "server.h" #include "../inotif/hash.h" #include "../inotif/inotif.h" @@ -50,7 +53,7 @@ #include "../client/client.h" #include "../scan/thread.h" -#include "../scan/queue.h" +#include "../scan/onas_queue.h" #include "../misc/utils.h" diff --git a/clamonacc/fanotif/fanotif.h b/clamonacc/fanotif/fanotif.h index 2e905f7f6d..b5f7c81427 100644 --- a/clamonacc/fanotif/fanotif.h +++ b/clamonacc/fanotif/fanotif.h @@ -21,8 +21,10 @@ #ifndef __ONAS_FAN_H #define __ONAS_FAN_H +// libclamav +#include "clamav.h" + #include "../clamonacc.h" -#include "libclamav/clamav.h" //void *onas_fan_th(void *arg); cl_error_t onas_setup_fanotif(struct onas_context **ctx); diff --git a/clamonacc/inotif/hash.c b/clamonacc/inotif/hash.c index dfa8c1d37d..1cfd75b980 100644 --- a/clamonacc/inotif/hash.c +++ b/clamonacc/inotif/hash.c @@ -33,28 +33,30 @@ #include #include -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) #include #endif -#include "../fanotif/fanotif.h" - -#include "hash.h" -#include "inotif.h" +// libclamav +#include "clamav.h" +#include "scanners.h" +#include "str.h" -#include "libclamav/clamav.h" -#include "libclamav/scanners.h" -#include "libclamav/str.h" +// shared +#include "optparser.h" +#include "output.h" -#include "shared/optparser.h" -#include "shared/output.h" +// clamd +#include "server.h" +#include "clamd_others.h" +#include "scanner.h" -#include "clamd/server.h" -#include "clamd/others.h" -#include "clamd/scanner.h" +#include "../fanotif/fanotif.h" +#include "hash.h" +#include "inotif.h" #include "../misc/priv_fts.h" -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) static struct onas_bucket *onas_bucket_init(); static void onas_free_bucket(struct onas_bucket *bckt); diff --git a/clamonacc/inotif/hash.h b/clamonacc/inotif/hash.h index ed15f342f7..97fd64334d 100644 --- a/clamonacc/inotif/hash.h +++ b/clamonacc/inotif/hash.h @@ -21,7 +21,7 @@ #ifndef __ONAS_HASH_H #define __ONAS_HASH_H -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) #define ONAS_FANWATCH 0x1 #define ONAS_INWATCH 0x2 diff --git a/clamonacc/inotif/inotif.c b/clamonacc/inotif/inotif.c index 2e43c7c27a..51e52d2378 100644 --- a/clamonacc/inotif/inotif.c +++ b/clamonacc/inotif/inotif.c @@ -34,31 +34,32 @@ #include #include -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) #include #include #endif -#include "../fanotif/fanotif.h" +// libclamav +#include "clamav.h" +#include "scanners.h" + +// shared +#include "optparser.h" +#include "output.h" +// clamd +#include "server.h" +#include "clamd_others.h" +#include "scanner.h" + +#include "../fanotif/fanotif.h" #include "hash.h" #include "inotif.h" - #include "../scan/thread.h" -#include "../scan/queue.h" +#include "../scan/onas_queue.h" #include "../misc/utils.h" -#include "libclamav/clamav.h" -#include "libclamav/scanners.h" - -#include "shared/optparser.h" -#include "shared/output.h" - -#include "clamd/server.h" -#include "clamd/others.h" -#include "clamd/scanner.h" - -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) static int onas_ddd_init_ht(uint32_t ht_size); static int onas_ddd_init_wdlt(uint64_t nwatches); diff --git a/clamonacc/inotif/inotif.h b/clamonacc/inotif/inotif.h index 7b7ad6611a..e46b7a9f75 100644 --- a/clamonacc/inotif/inotif.h +++ b/clamonacc/inotif/inotif.h @@ -21,10 +21,14 @@ #ifndef __ONAS_IN_H #define __ONAS_IN_H -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) + +// libclamav +#include "clamav.h" + +// shared +#include "optparser.h" -#include "shared/optparser.h" -#include "libclamav/clamav.h" #include "clamonacc.h" /* diff --git a/clamonacc/misc/utils.c b/clamonacc/misc/utils.c index f2e9282185..fc5f28d673 100644 --- a/clamonacc/misc/utils.c +++ b/clamonacc/misc/utils.c @@ -30,17 +30,23 @@ #include #include #include -#include "libclamav/clamav.h" -#include "shared/optparser.h" -#include "shared/output.h" + +// libclamav +#include "clamav.h" + +// shared +#include "optparser.h" +#include "output.h" + +// clamd +#include "scanner.h" #include "utils.h" -#include "clamd/scanner.h" #include "../clamonacc.h" #include "../client/client.h" -#include "../scan/queue.h" +#include "../scan/onas_queue.h" -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) extern pthread_cond_t onas_scan_queue_empty_cond; diff --git a/clamonacc/misc/utils.h b/clamonacc/misc/utils.h index 6405f3f4cd..37f53a0c2b 100644 --- a/clamonacc/misc/utils.h +++ b/clamonacc/misc/utils.h @@ -21,8 +21,12 @@ #ifndef __CLAMD_ONAS_OTHERS_H #define __CLAMD_ONAS_OTHERS_H -#include "shared/optparser.h" -#include "libclamav/clamav.h" +// libclamav +#include "clamav.h" + +// shared +#include "optparser.h" + #include "../clamonacc.h" typedef enum { @@ -31,7 +35,7 @@ typedef enum { CHK_SELF } cli_check_t; -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) int onas_fan_checkowner(int pid, const struct optstruct *opts); #endif char **onas_get_opt_list(const char *fname, int *num_entries, cl_error_t *err); diff --git a/clamonacc/scan/queue.c b/clamonacc/scan/onas_queue.c similarity index 98% rename from clamonacc/scan/queue.c rename to clamonacc/scan/onas_queue.c index 3c5ff10046..f550791f55 100644 --- a/clamonacc/scan/queue.c +++ b/clamonacc/scan/onas_queue.c @@ -32,17 +32,17 @@ #include #include -#include "../misc/utils.h" - -#include "libclamav/clamav.h" +// libclamav +#include "clamav.h" -#include "shared/optparser.h" -#include "shared/output.h" +// shared +#include "optparser.h" +#include "output.h" +#include "../misc/utils.h" #include "../c-thread-pool/thpool.h" - #include "thread.h" -#include "queue.h" +#include "onas_queue.h" static void onas_scan_queue_exit(void *arg); static int onas_consume_event(threadpool thpool); diff --git a/clamonacc/scan/queue.h b/clamonacc/scan/onas_queue.h similarity index 100% rename from clamonacc/scan/queue.h rename to clamonacc/scan/onas_queue.h diff --git a/clamonacc/scan/thread.c b/clamonacc/scan/thread.c index ed8ea4b682..df5710e6ae 100644 --- a/clamonacc/scan/thread.c +++ b/clamonacc/scan/thread.c @@ -30,14 +30,17 @@ #include #include -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) #include #endif -#include "shared/optparser.h" -#include "shared/output.h" +// libclamav +#include "others.h" + +// shared +#include "optparser.h" +#include "output.h" -#include "libclamav/others.h" #include "../misc/priv_fts.h" #include "../misc/utils.h" #include "../client/client.h" @@ -110,7 +113,7 @@ static cl_error_t onas_scan_safe(struct onas_scan_event *event_data, const char int ret = 0; int fd = 0; -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) uint8_t b_fanotify; b_fanotify = event_data->bool_opts & ONAS_SCTH_B_FANOTIFY ? 1 : 0; @@ -133,7 +136,7 @@ static cl_error_t onas_scan_safe(struct onas_scan_event *event_data, const char static cl_error_t onas_scan_thread_scanfile(struct onas_scan_event *event_data, const char *fname, STATBUF sb, int *infected, int *err, cl_error_t *ret_code) { -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) struct fanotify_response res; uint8_t b_fanotify; #endif @@ -151,7 +154,7 @@ static cl_error_t onas_scan_thread_scanfile(struct onas_scan_event *event_data, b_scan = event_data->bool_opts & ONAS_SCTH_B_SCAN ? 1 : 0; b_deny_on_error = event_data->bool_opts & ONAS_SCTH_B_DENY_ON_E ? 1 : 0; -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) b_fanotify = event_data->bool_opts & ONAS_SCTH_B_FANOTIFY ? 1 : 0; if (b_fanotify) { res.fd = event_data->fmd->fd; @@ -166,7 +169,7 @@ static cl_error_t onas_scan_thread_scanfile(struct onas_scan_event *event_data, logg("*ClamWorker: scan failed with error code %d\n", *ret_code); } -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) if (b_fanotify) { if ((*err && *ret_code && b_deny_on_error) || *infected) { res.response = FAN_DENY; @@ -175,7 +178,7 @@ static cl_error_t onas_scan_thread_scanfile(struct onas_scan_event *event_data, #endif } -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) if (b_fanotify) { if (event_data->fmd->mask & FAN_ALL_PERM_EVENTS) { ret = write(event_data->fan_fd, &res, sizeof(res)); @@ -325,7 +328,7 @@ void *onas_scan_worker(void *arg) b_inotify = event_data->bool_opts & ONAS_SCTH_B_INOTIFY ? 1 : 0; b_fanotify = event_data->bool_opts & ONAS_SCTH_B_FANOTIFY ? 1 : 0; -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) if (b_inotify) { logg("*ClamWorker: handling inotify event ...\n"); @@ -363,7 +366,7 @@ void *onas_scan_worker(void *arg) event_data->pathname = NULL; } -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) if (NULL != event_data->fmd) { free(event_data->fmd); event_data->fmd = NULL; diff --git a/clamonacc/scan/thread.h b/clamonacc/scan/thread.h index 2fa75099bd..176dee560b 100644 --- a/clamonacc/scan/thread.h +++ b/clamonacc/scan/thread.h @@ -21,11 +21,15 @@ #ifndef __ONAS_SCTH_H #define __ONAS_SCTH_H -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) #include #endif -#include "shared/optparser.h" -#include "libclamav/clamav.h" + +// libclamav +#include "clamav.h" + +// shared +#include "optparser.h" #define ONAS_SCTH_B_DIR 0x01 #define ONAS_SCTH_B_FILE 0x02 @@ -51,7 +55,7 @@ struct onas_scan_event { int64_t portnum; char *pathname; int fan_fd; -#if defined(FANOTIFY) +#if defined(HAVE_SYS_FANOTIFY_H) struct fanotify_event_metadata *fmd; #endif uint8_t retry_attempts; diff --git a/clamscan/CMakeLists.txt b/clamscan/CMakeLists.txt new file mode 100644 index 0000000000..b9c28bd6ca --- /dev/null +++ b/clamscan/CMakeLists.txt @@ -0,0 +1,36 @@ +# Copyright (C) 2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved. + +cmake_minimum_required( VERSION 3.12...3.13 ) + +if(WIN32) + add_definitions(-DWIN32_LEAN_AND_MEAN) + add_definitions(-DHAVE_STRUCT_TIMESPEC) + + # Windows compatibility headers + include_directories(${CMAKE_SOURCE_DIR}/win32/compat) +endif() + +# The clamscan executable. +add_executable( clamscan ) +target_sources( clamscan + PRIVATE + clamscan.c + manager.c + manager.h + global.h ) +if(WIN32) + target_sources( clamscan PRIVATE ${CMAKE_SOURCE_DIR}/win32/res/clamscan.rc ) +endif() +target_include_directories( clamscan + PRIVATE ${CMAKE_BINARY_DIR} # For clamav-config.h +) +set_target_properties( clamscan PROPERTIES COMPILE_FLAGS "${WARNCFLAGS}" ) +target_link_libraries( clamscan + PRIVATE + ClamAV::libclamav + ClamAV::shared ) +if(WIN32) + install(TARGETS clamscan DESTINATION ${CMAKE_INSTALL_PREFIX}) +else() + install(TARGETS clamscan DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/clamscan/Makefile.am b/clamscan/Makefile.am index 13e4dd0bce..8faf427c7d 100644 --- a/clamscan/Makefile.am +++ b/clamscan/Makefile.am @@ -23,24 +23,14 @@ bin_PROGRAMS = clamscan clamscan_SOURCES = \ - $(top_srcdir)/shared/output.c \ - $(top_srcdir)/shared/output.h \ - $(top_srcdir)/shared/getopt.c \ - $(top_srcdir)/shared/getopt.h \ - $(top_srcdir)/shared/optparser.c \ - $(top_srcdir)/shared/optparser.h \ - $(top_srcdir)/shared/actions.c \ - $(top_srcdir)/shared/actions.h \ - $(top_srcdir)/shared/misc.c \ - $(top_srcdir)/shared/misc.h \ clamscan.c \ global.h \ manager.c \ manager.h AM_CFLAGS=@WERR_CFLAGS@ -DEFS = @DEFS@ -DCL_NOTHREADS -LIBS = $(top_builddir)/libclamav/libclamav.la @THREAD_LIBS@ @CLAMSCAN_LIBS@ -AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav @SSL_CPPFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ @CLAMSCAN_CPPFLAGS@ +DEFS = @DEFS@ +LIBS = $(top_builddir)/libclamav/libclamav.la $(top_builddir)/shared/libshared.la @THREAD_LIBS@ @CLAMSCAN_LIBS@ +AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav -I$(top_builddir)/libclamav -I$(top_srcdir)/libclamunrar_iface @SSL_CPPFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ @CLAMSCAN_CPPFLAGS@ CLEANFILES=*.gcda *.gcno diff --git a/clamscan/clamscan.c b/clamscan/clamscan.c index dafdcc8e09..bf70844f08 100644 --- a/clamscan/clamscan.c +++ b/clamscan/clamscan.c @@ -39,17 +39,19 @@ #include #endif +// libclamav +#include "clamav.h" #include "others.h" -#include "global.h" -#include "manager.h" +#include "str.h" -#include "shared/misc.h" -#include "shared/output.h" -#include "shared/actions.h" -#include "shared/optparser.h" +// shared +#include "misc.h" +#include "output.h" +#include "actions.h" +#include "optparser.h" -#include "libclamav/str.h" -#include "libclamav/clamav.h" +#include "global.h" +#include "manager.h" void help(void); diff --git a/clamscan/manager.c b/clamscan/manager.c index 861024bd1f..c056421ea6 100644 --- a/clamscan/manager.c +++ b/clamscan/manager.c @@ -49,20 +49,23 @@ #include #include +// libclamav +#include "clamav.h" +#include "others.h" +#include "matcher-ac.h" +#include "matcher-pcre.h" +#include "str.h" +#include "readdb.h" + +// shared +#include "optparser.h" +#include "actions.h" +#include "output.h" +#include "misc.h" + #include "manager.h" #include "global.h" -#include "shared/optparser.h" -#include "shared/actions.h" -#include "shared/output.h" -#include "shared/misc.h" - -#include "libclamav/clamav.h" -#include "libclamav/others.h" -#include "libclamav/matcher-ac.h" -#include "libclamav/matcher-pcre.h" -#include "libclamav/str.h" -#include "libclamav/readdb.h" #ifdef C_LINUX dev_t procdev; diff --git a/clamscan/manager.h b/clamscan/manager.h index 17d36a6266..f3646055e9 100644 --- a/clamscan/manager.h +++ b/clamscan/manager.h @@ -22,7 +22,7 @@ #ifndef __MANAGER_H #define __MANAGER_H -#include "shared/optparser.h" +#include "optparser.h" int scanmanager(const struct optstruct *opts); diff --git a/clamsubmit/CMakeLists.txt b/clamsubmit/CMakeLists.txt new file mode 100644 index 0000000000..4b7f89490b --- /dev/null +++ b/clamsubmit/CMakeLists.txt @@ -0,0 +1,40 @@ +# Copyright (C) 2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved. + +cmake_minimum_required( VERSION 3.12...3.13 ) + +if(WIN32) + add_definitions(-DWIN32_LEAN_AND_MEAN) + add_definitions(-DHAVE_STRUCT_TIMESPEC) + + # Windows compatibility headers + include_directories(${CMAKE_SOURCE_DIR}/win32/compat) +endif() + +# The clamsubmit executable. +add_executable( clamsubmit ) +target_sources( clamsubmit + PRIVATE + clamsubmit.c ) +if(WIN32) + target_sources( clamsubmit PRIVATE ${CMAKE_SOURCE_DIR}/win32/res/clamsubmit.rc ) +endif() +target_include_directories( clamsubmit + PRIVATE ${CMAKE_BINARY_DIR} # For clamav-config.h +) +set_target_properties( clamsubmit PROPERTIES COMPILE_FLAGS "${WARNCFLAGS}" ) +target_link_libraries( clamsubmit + PRIVATE + ClamAV::libclamav + ClamAV::shared + JSONC::jsonc ) +if(APPLE) + target_link_libraries( clamsubmit + PUBLIC + ${APPLE_CORE_FOUNDATION} + ${APPLE_SECURITY} ) +endif() +if(WIN32) + install(TARGETS clamsubmit DESTINATION ${CMAKE_INSTALL_PREFIX}) +else() + install(TARGETS clamsubmit DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/clamsubmit/Makefile.am b/clamsubmit/Makefile.am index 466e5a2f13..5178b3791f 100644 --- a/clamsubmit/Makefile.am +++ b/clamsubmit/Makefile.am @@ -19,40 +19,12 @@ bin_PROGRAMS = clamsubmit clamsubmit_SOURCES = \ - $(top_srcdir)/shared/output.c \ - $(top_srcdir)/shared/output.h \ - $(top_srcdir)/shared/optparser.c \ - $(top_srcdir)/shared/optparser.h \ - $(top_srcdir)/shared/getopt.c \ - $(top_srcdir)/shared/getopt.h \ - $(top_srcdir)/shared/misc.c \ - $(top_srcdir)/shared/misc.h \ - $(top_srcdir)/shared/cert_util.c \ - $(top_srcdir)/shared/cert_util.h \ - $(top_srcdir)/shared/cert_util_internal.h \ clamsubmit.c -if MACOS - clamsubmit_SOURCES += \ - $(top_srcdir)/shared/mac/cert_util_mac.m \ - $(top_srcdir)/shared/cert_util.h -endif -if WINDOWS - clamsubmit_SOURCES += \ - $(top_srcdir)/shared/win/cert_util_win.c \ - $(top_srcdir)/shared/cert_util.h -endif -if LINUX - clamsubmit_SOURCES += \ - $(top_srcdir)/shared/linux/cert_util_linux.c \ - $(top_srcdir)/shared/cert_util.h -endif - - AM_CFLAGS=@WERR_CFLAGS@ @CLAMSUBMIT_CFLAGS@ -DEFS = @DEFS@ -DCL_NOTHREADS -AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav @SSL_CPPFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ -LIBS = $(top_builddir)/libclamav/libclamav.la @CLAMSUBMIT_LIBS@ @THREAD_LIBS@ @JSON_LIBS@ @SSL_LIBS@ +DEFS = @DEFS@ +AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav -I$(top_builddir)/libclamav -I$(top_srcdir)/libclamunrar_iface @SSL_CPPFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ +LIBS = $(top_builddir)/libclamav/libclamav.la $(top_builddir)/shared/libshared.la @CLAMSUBMIT_LIBS@ @THREAD_LIBS@ @JSON_LIBS@ @SSL_LIBS@ if MACOS AM_LDFLAGS = -framework CoreFoundation -framework Security diff --git a/clamsubmit/clamsubmit.c b/clamsubmit/clamsubmit.c index a10d8e6e34..ac21d58671 100644 --- a/clamsubmit/clamsubmit.c +++ b/clamsubmit/clamsubmit.c @@ -11,13 +11,18 @@ #endif #include +#include #include "target.h" -#include "libclamav/clamav.h" -#include "libclamav/others.h" -#include "shared/misc.h" -#include "shared/getopt.h" -#include "shared/cert_util.h" + +// libclamav +#include "clamav.h" +#include "others.h" + +// shared +#include "misc.h" +#include "getopt.h" +#include "cert_util.h" #define OPTS "e:p:n:N:V:H:h?v?d" diff --git a/cmake/CheckFDPassing.c b/cmake/CheckFDPassing.c new file mode 100644 index 0000000000..7f02e4b7de --- /dev/null +++ b/cmake/CheckFDPassing.c @@ -0,0 +1,147 @@ +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#include +#include +#include +#include +#include +#ifdef HAVE_SYS_UIO_H +#include +#endif +#include +#include + +#if !defined CMSG_SPACE || !defined CMSG_LEN +#ifndef ALIGN +#define ALIGN(len) len +#endif + +#ifndef CMSG_SPACE +#define CMSG_SPACE(len) (ALIGN(sizeof(struct cmsghdr)) + ALIGN(len)) +#endif + +#ifndef CMSG_LEN +#define CMSG_LEN(len) (ALIGN(sizeof(struct cmsghdr)) + len) +#endif +#endif + +#define TEST "test" + +static int send_fd(int s, int fd) +{ + struct msghdr msg; + struct cmsghdr *cmsg; + unsigned char fdbuf[CMSG_SPACE(sizeof(int))]; + struct iovec iov[1]; + char dummy[] = ""; + + iov[0].iov_base = dummy; + iov[0].iov_len = 1; + + memset(&msg, 0, sizeof(msg)); + msg.msg_control = fdbuf; + /* must send/receive at least one byte */ + msg.msg_iov = iov; + msg.msg_iovlen = 1; + msg.msg_controllen = CMSG_LEN(sizeof(int)); + + cmsg = CMSG_FIRSTHDR(&msg); + cmsg->cmsg_len = CMSG_LEN(sizeof(int)); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + *(int *)CMSG_DATA(cmsg) = fd; + + if (sendmsg(s, &msg, 0) == -1) { + perror("sendmsg"); + close(s); + return -1; + } + return 0; +} + +static int testfd(int desc) +{ + char buf[256]; + if (read(desc, buf, sizeof(buf)) != sizeof(TEST)) { + fprintf(stderr, "test data not received correctly!"); + return 1; + } + return memcmp(buf, TEST, sizeof(TEST)); +} + +static int recv_fd(int desc) +{ + unsigned char buf[CMSG_SPACE(sizeof(int))]; + struct msghdr msg; + struct cmsghdr *cmsg; + struct iovec iov[1]; + char dummy; + int ret = 2; + + memset(&msg, 0, sizeof(msg)); + iov[0].iov_base = &dummy; + iov[0].iov_len = 1; + msg.msg_iov = iov; + msg.msg_iovlen = 1; + msg.msg_control = buf; + msg.msg_controllen = sizeof(buf); + + if (recvmsg(desc, &msg, 0) == -1) { + perror("recvmsg failed!"); + return -1; + } + if ((msg.msg_flags & MSG_TRUNC) || (msg.msg_flags & MSG_CTRUNC)) { + fprintf(stderr, "control message truncated"); + return -1; + } + for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; + cmsg = CMSG_NXTHDR(&msg, cmsg)) { + if (cmsg->cmsg_len == CMSG_LEN(sizeof(int)) && + cmsg->cmsg_level == SOL_SOCKET && + cmsg->cmsg_type == SCM_RIGHTS) { + int fd = *(int *)CMSG_DATA(cmsg); + ret = testfd(fd); + close(fd); + } + } + return ret; +} + +int main(void) +{ + int fd[2]; + int pip[2]; + pid_t pid; + int status; + + if (pipe(pip)) { + perror("pipe"); + return 1; + } + + if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) { + perror("socketpair"); + return 1; + } + + if ((pid = fork()) < 0) { + perror("fork"); + } else if (!pid) { + exit(recv_fd(fd[1])); + } else { + /* parent */ + if (send_fd(fd[0], pip[0]) == -1) { + kill(pid, 9); + waitpid(pid, NULL, 0); + return 2; + } + if (write(pip[1], TEST, sizeof(TEST)) != sizeof(TEST)) { + close(pip[1]); + return -1; + } + close(pip[1]); + waitpid(pid, &status, 0); + } + return status; +} diff --git a/cmake/CheckFDPassing.cmake b/cmake/CheckFDPassing.cmake new file mode 100644 index 0000000000..039d9eb4d1 --- /dev/null +++ b/cmake/CheckFDPassing.cmake @@ -0,0 +1,105 @@ +# +# Check if file descriptor passing is supported +# Derived from work submitted by Richard Lyons +# + +GET_FILENAME_COMPONENT(_selfdir_CheckFDPassing + "${CMAKE_CURRENT_LIST_FILE}" PATH) + +include(CheckSymbolExists) +check_symbol_exists(recvmsg "sys/socket.h" HAVE_RECVMSG) +check_symbol_exists(sendmsg "sys/socket.h" HAVE_SENDMSG) + +# Extra -D Compile Definitions for check_c_source_compiles() +set(CMAKE_REQUIRED_DEFINITIONS "") +if(HAVE_SYS_TYPES_H) + set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS};-DHAVE_SYS_TYPES_H=1") +endif() +if(HAVE_SYS_UIO_H) + set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS};-DHAVE_SYS_UIO_H=1") +endif() + +# Check for msg_control field in struct msghdr +check_c_source_compiles( + " + #define _XOPEN_SOURCE 500 + #ifdef HAVE_SYS_TYPES_H + # include + #endif + #include + #ifdef HAVE_SYS_UIO_H + # include + #endif + + int main(void) { + #ifdef msg_control + # error msg_control defined + #endif + + struct msghdr m; + m.msg_control = 0; + return 0; + } + " + HAVE_CONTROL_IN_MSGHDR ) + +if(HAVE_CONTROL_IN_MSGHDR) + # + # Check whether BSD 4.4 / RFC2292 style fd passing works + # + set(EXTRA_COMPILE_DEFINITIONS "") + if(HAVE_SYS_TYPES_H) + set(EXTRA_COMPILE_DEFINITIONS "${EXTRA_COMPILE_DEFINITIONS} -DHAVE_SYS_TYPES_H=1") + endif() + if(HAVE_SYS_UIO_H) + set(EXTRA_COMPILE_DEFINITIONS "${EXTRA_COMPILE_DEFINITIONS} -DHAVE_SYS_UIO_H=1") + endif() + + # Try without _XOPEN_SOURCE first + try_run( + # Name of variable to store the run result (process exit status; number) in: + test_run_result + # Name of variable to store the compile result (TRUE or FALSE) in: + test_compile_result + # Binary directory: + ${CMAKE_CURRENT_BINARY_DIR} + # Source file to be compiled: + ${_selfdir_CheckFDPassing}/CheckFDPassing.c + # Extra -D Compile Definitions + COMPILE_DEFINITIONS ${EXTRA_COMPILE_DEFINITIONS} + # Where to store the output produced during compilation: + COMPILE_OUTPUT_VARIABLE test_compile_output + # Where to store the output produced by running the compiled executable: + RUN_OUTPUT_VARIABLE test_run_output ) + + # Did compilation succeed and process return 0 (success)? + if("${test_compile_result}" AND ("${test_run_result}" EQUAL 0)) + set(HAVE_FD_PASSING 1) + else() + # Try again, this time with: #define _XOPEN_SOURCE 500 + set(EXTRA_COMPILE_DEFINITIONS "${EXTRA_COMPILE_DEFINITIONS} -D_XOPEN_SOURCE=500") + + try_run( + # Name of variable to store the run result (process exit status; number) in: + test_run_result + # Name of variable to store the compile result (TRUE or FALSE) in: + test_compile_result + # Binary directory: + ${CMAKE_CURRENT_BINARY_DIR} + # Source file to be compiled: + ${_selfdir_CheckFDPassing}/CheckFDPassing.c + # Extra -D Compile Definitions + COMPILE_DEFINITIONS ${EXTRA_COMPILE_DEFINITIONS} + # Where to store the output produced during compilation: + COMPILE_OUTPUT_VARIABLE test_compile_output + # Where to store the output produced by running the compiled executable: + RUN_OUTPUT_VARIABLE test_run_output ) + + # Did compilation succeed and process return 0 (success)? + if("${test_compile_result}" AND ("${test_run_result}" EQUAL 0)) + set(HAVE_FD_PASSING 1) + set(FDPASS_NEED_XOPEN 1) + endif() + endif() + +endif() diff --git a/cmake/CheckFTS.cmake b/cmake/CheckFTS.cmake new file mode 100644 index 0000000000..e92f9c43cd --- /dev/null +++ b/cmake/CheckFTS.cmake @@ -0,0 +1,20 @@ +# +# Check for struct packing features +# This feature reworked from m4/reorganization/code_checks/compiler_attribs.m4 +# + +GET_FILENAME_COMPONENT(_selfdir_CheckFTS + "${CMAKE_CURRENT_LIST_FILE}" PATH) + +# Check if __attribute__((packed)) is available +check_c_source_compiles( + " + #include + + int main(void) { + fts_open((void *)0, FTS_PHYSICAL, (void *)0); + + return 0; + } + " + HAVE_SYSTEM_LFS_FTS ) diff --git a/cmake/CheckFileOffsetBits.c b/cmake/CheckFileOffsetBits.c new file mode 100644 index 0000000000..d948fecf2b --- /dev/null +++ b/cmake/CheckFileOffsetBits.c @@ -0,0 +1,14 @@ +#include + +#define KB ((off_t)1024) +#define MB ((off_t)1024 * KB) +#define GB ((off_t)1024 * MB) +#define TB ((off_t)1024 * GB) +int t2[(((64 * GB -1) % 671088649) == 268434537) + && (((TB - (64 * GB -1) + 255) % 1792151290) == 305159546)? 1: -1]; + +int main() +{ + ; + return 0; +} diff --git a/cmake/CheckFileOffsetBits.cmake b/cmake/CheckFileOffsetBits.cmake new file mode 100644 index 0000000000..8a74b9e11f --- /dev/null +++ b/cmake/CheckFileOffsetBits.cmake @@ -0,0 +1,43 @@ +# - Check if _FILE_OFFSET_BITS macro needed for large files +# CHECK_FILE_OFFSET_BITS () +# +# The following variables may be set before calling this macro to +# modify the way the check is run: +# +# CMAKE_REQUIRED_FLAGS = string of compile command line flags +# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) +# CMAKE_REQUIRED_INCLUDES = list of include directories +# Copyright (c) 2009, Michihiro NAKAJIMA +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +#INCLUDE(CheckCSourceCompiles) + +GET_FILENAME_COMPONENT(_selfdir_CheckFileOffsetBits + "${CMAKE_CURRENT_LIST_FILE}" PATH) + +MACRO (CHECK_FILE_OFFSET_BITS) + IF(NOT DEFINED _FILE_OFFSET_BITS) + MESSAGE(STATUS "Checking _FILE_OFFSET_BITS for large files") + TRY_COMPILE(__WITHOUT_FILE_OFFSET_BITS_64 + ${CMAKE_CURRENT_BINARY_DIR} + ${_selfdir_CheckFileOffsetBits}/CheckFileOffsetBits.c + COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}) + IF(NOT __WITHOUT_FILE_OFFSET_BITS_64) + TRY_COMPILE(__WITH_FILE_OFFSET_BITS_64 + ${CMAKE_CURRENT_BINARY_DIR} + ${_selfdir_CheckFileOffsetBits}/CheckFileOffsetBits.c + COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_FILE_OFFSET_BITS=64) + ENDIF(NOT __WITHOUT_FILE_OFFSET_BITS_64) + + IF(NOT __WITHOUT_FILE_OFFSET_BITS_64 AND __WITH_FILE_OFFSET_BITS_64) + SET(_FILE_OFFSET_BITS 64 CACHE INTERNAL "_FILE_OFFSET_BITS macro needed for large files") + MESSAGE(STATUS "Checking _FILE_OFFSET_BITS for large files - needed") + ELSE(NOT __WITHOUT_FILE_OFFSET_BITS_64 AND __WITH_FILE_OFFSET_BITS_64) + SET(_FILE_OFFSET_BITS "" CACHE INTERNAL "_FILE_OFFSET_BITS macro needed for large files") + MESSAGE(STATUS "Checking _FILE_OFFSET_BITS for large files - not needed") + ENDIF(NOT __WITHOUT_FILE_OFFSET_BITS_64 AND __WITH_FILE_OFFSET_BITS_64) + ENDIF(NOT DEFINED _FILE_OFFSET_BITS) + +ENDMACRO (CHECK_FILE_OFFSET_BITS) diff --git a/cmake/CheckSignedRightShift.c b/cmake/CheckSignedRightShift.c new file mode 100644 index 0000000000..b8d4097495 --- /dev/null +++ b/cmake/CheckSignedRightShift.c @@ -0,0 +1,6 @@ +int main(void) +{ + int a = -1; + int b = a >> 1; + return (a != b); +} diff --git a/cmake/CheckSignedRightShift.cmake b/cmake/CheckSignedRightShift.cmake new file mode 100644 index 0000000000..6d65704896 --- /dev/null +++ b/cmake/CheckSignedRightShift.cmake @@ -0,0 +1,26 @@ +# +# Check for signed right-shift +# + +GET_FILENAME_COMPONENT(_selfdir_CheckSignedRightShift + "${CMAKE_CURRENT_LIST_FILE}" PATH) + +# Check for signed right-shift (HAVE_SAR) +try_run( + # Name of variable to store the run result (process exit status; number) in: + test_run_result + # Name of variable to store the compile result (TRUE or FALSE) in: + test_compile_result + # Binary directory: + ${CMAKE_CURRENT_BINARY_DIR} + # Source file to be compiled: + ${_selfdir_CheckSignedRightShift}/CheckSignedRightShift.c + # Where to store the output produced during compilation: + COMPILE_OUTPUT_VARIABLE test_compile_output + # Where to store the output produced by running the compiled executable: + RUN_OUTPUT_VARIABLE test_run_output ) + +# Did compilation succeed and process return 0 (success)? +if("${test_compile_result}" AND ("${test_run_result}" EQUAL 0)) + set(HAVE_SAR 1) +endif() diff --git a/cmake/CheckStructPacking.cmake b/cmake/CheckStructPacking.cmake new file mode 100644 index 0000000000..4e6a1c41c8 --- /dev/null +++ b/cmake/CheckStructPacking.cmake @@ -0,0 +1,72 @@ +# +# Check for struct packing features +# This feature reworked from m4/reorganization/code_checks/compiler_attribs.m4 +# + +GET_FILENAME_COMPONENT(_selfdir_CheckStructPacking + "${CMAKE_CURRENT_LIST_FILE}" PATH) + +# Check if __attribute__((packed)) is available +check_c_source_compiles( + " + #ifdef __GNUC__ + struct { int i __attribute__((packed)); } s; + #else + #error Only checking for packed attribute on gcc-like compilers + #endif + " + HAVE_ATTRIB_PACKED ) +if(NOT HAVE_ATTRIB_PACKED) + # Check for packing via pragma (HAVE_PRAGMA_PACK) + try_run( + # Name of variable to store the run result (process exit status; number) in: + test_run_result + # Name of variable to store the compile result (TRUE or FALSE) in: + test_compile_result + # Binary directory: + ${CMAKE_CURRENT_BINARY_DIR} + # Source file to be compiled: + ${_selfdir_CheckStructPacking}/CheckStructPacking_PRAGMA_PACK.c + # Where to store the output produced during compilation: + COMPILE_OUTPUT_VARIABLE test_compile_output + # Where to store the output produced by running the compiled executable: + RUN_OUTPUT_VARIABLE test_run_output ) + + # Did compilation succeed and process return 0 (success)? + if("${test_compile_result}" AND ("${test_run_result}" EQUAL 0)) + set(HAVE_PRAGMA_PACK 1) + endif() + + if(NOT HAVE_PRAGMA_PACK) + # Check for packing via hppa/hp-uux pragma (HAVE_PRAGMA_PACK_HPPA) + try_run( + # Name of variable to store the run result (process exit status; number) in: + test_run_result + # Name of variable to store the compile result (TRUE or FALSE) in: + test_compile_result + # Binary directory: + ${CMAKE_CURRENT_BINARY_DIR} + # Source file to be compiled: + ${_selfdir_CheckStructPacking}/CheckStructPacking_PRAGMA_PACK_HPPA.c + # Where to store the output produced during compilation: + COMPILE_OUTPUT_VARIABLE test_compile_output + # Where to store the output produced by running the compiled executable: + RUN_OUTPUT_VARIABLE test_run_output ) + + # Did compilation succeed and process return 0 (success)? + if("${test_compile_result}" AND ("${test_run_result}" EQUAL 0)) + set(HAVE_PRAGMA_PACK_HPPA 1) + endif() + endif() +endif() + +# Check if struct __attribute__((aligned)) is available +check_c_source_compiles( + " + typedef int cl_aligned_int __attribute__((aligned)); + " + HAVE_ATTRIB_ALIGNED ) + +if (NOT (HAVE_ATTRIB_PACKED OR HAVE_PRAGMA_PACK OR HAVE_PRAGMA_PACK_HPPA)) + message(FATAL_ERROR "Failed to determine how to pack structs with this compiler!") +endif() diff --git a/cmake/CheckStructPacking_PRAGMA_PACK.c b/cmake/CheckStructPacking_PRAGMA_PACK.c new file mode 100644 index 0000000000..f07a8fa8a5 --- /dev/null +++ b/cmake/CheckStructPacking_PRAGMA_PACK.c @@ -0,0 +1,9 @@ +int main(int argc, char **argv) +{ +#pragma pack(1) /* has to be in column 1 ! */ + struct { + char c; + long l; + } s; + return sizeof(s) == sizeof(s.c) + sizeof(s.l) ? 0 : 1; +} diff --git a/cmake/CheckStructPacking_PRAGMA_PACK_HPPA.c b/cmake/CheckStructPacking_PRAGMA_PACK_HPPA.c new file mode 100644 index 0000000000..1166b563c5 --- /dev/null +++ b/cmake/CheckStructPacking_PRAGMA_PACK_HPPA.c @@ -0,0 +1,10 @@ +/* hppa/hp-ux wants pragma outside of function */ +#pragma pack 1 /* has to be in column 1 ! */ +struct { + char c; + long l; +} s; +int main(int argc, char **argv) +{ + return sizeof(s) == sizeof(s.c) + sizeof(s.l) ? 0 : 1; +} diff --git a/cmake/CheckUnamePosix.c b/cmake/CheckUnamePosix.c new file mode 100644 index 0000000000..9c1110a01a --- /dev/null +++ b/cmake/CheckUnamePosix.c @@ -0,0 +1,6 @@ +#include +int main() +{ + struct utsname unm; + return uname(&unm); +} diff --git a/cmake/CheckUnamePosix.cmake b/cmake/CheckUnamePosix.cmake new file mode 100644 index 0000000000..9d0e643d31 --- /dev/null +++ b/cmake/CheckUnamePosix.cmake @@ -0,0 +1,27 @@ +# +# Check for POSIX compliant uname(2) sys call. +# This feature reworked from http://www.gnu.org/software/autoconf-archive/ax_check_uname_syscall.html +# + +GET_FILENAME_COMPONENT(_selfdir_CheckUnamePosix + "${CMAKE_CURRENT_LIST_FILE}" PATH) + +# Check that the POSIX compliant uname(2) call works properly (HAVE_UNAME_SYSCALL) +try_run( + # Name of variable to store the run result (process exit status; number) in: + test_run_result + # Name of variable to store the compile result (TRUE or FALSE) in: + test_compile_result + # Binary directory: + ${CMAKE_CURRENT_BINARY_DIR} + # Source file to be compiled: + ${_selfdir_CheckUnamePosix}/CheckUnamePosix.c + # Where to store the output produced during compilation: + COMPILE_OUTPUT_VARIABLE test_compile_output + # Where to store the output produced by running the compiled executable: + RUN_OUTPUT_VARIABLE test_run_output ) + +# Did compilation succeed and process return 0 (success)? +if("${test_compile_result}" AND ("${test_run_result}" EQUAL 0)) + set(HAVE_UNAME_SYSCALL 1) +endif() diff --git a/cmake/ColourMessage.cmake b/cmake/ColourMessage.cmake new file mode 100644 index 0000000000..86d1aa4360 --- /dev/null +++ b/cmake/ColourMessage.cmake @@ -0,0 +1,20 @@ +# From https://stackoverflow.com/questions/18968979/how-to-get-colorized-output-with-cmake + +string(ASCII 27 Esc) +set(e "${Esc}[m") # Colour Reset +set(o "${Esc}[1m") # Colour Bold +set(r "${Esc}[31m") # Red +set(g "${Esc}[32m") # Green +set(y "${Esc}[33m") # Yellow +set(b "${Esc}[34m") # Blue +set(m "${Esc}[35m") # Magenta +set(c "${Esc}[36m") # Cyan +set(w "${Esc}[37m") # White +set(R "${Esc}[1;31m") # Bold Red +set(G "${Esc}[1;32m") # Bold Green +set(Y "${Esc}[1;33m") # Bold Yellow +set(B "${Esc}[1;34m") # Bold Blue +set(M "${Esc}[1;35m") # Bold Magenta +set(C "${Esc}[1;36m") # Bold Cyan +set(W "${Esc}[1;37m") # Bold White +set(_ "") # No-op, for alignment purposes diff --git a/cmake/ExtractValidFlags.cmake b/cmake/ExtractValidFlags.cmake new file mode 100644 index 0000000000..fab817074c --- /dev/null +++ b/cmake/ExtractValidFlags.cmake @@ -0,0 +1,31 @@ +# Convenience function that checks the availability of certain +# C or C++ compiler flags and returns valid ones as a string. + +include(CheckCCompilerFlag) +include(CheckCXXCompilerFlag) + +function(extract_valid_c_flags varname) + set(valid_flags) + foreach(flag IN LISTS ARGN) + string(REGEX REPLACE "[^a-zA-Z0-9_]+" "_" flag_var ${flag}) + set(flag_var "C_FLAG_${flag_var}") + check_c_compiler_flag("${flag}" "${flag_var}") + if(${flag_var}) + set(valid_flags "${valid_flags} ${flag}") + endif() + endforeach() + set(${varname} "${valid_flags}" PARENT_SCOPE) +endfunction() + +function(extract_valid_cxx_flags varname) + set(valid_flags) + foreach(flag IN LISTS ARGN) + string(REGEX REPLACE "[^a-zA-Z0-9_]+" "_" flag_var ${flag}) + set(flag_var "CXX_FLAG_${flag_var}") + check_cxx_compiler_flag("${flag}" "${flag_var}") + if(${flag_var}) + set(valid_flags "${valid_flags} ${flag}") + endif() + endforeach() + set(${varname} "${valid_flags}" PARENT_SCOPE) +endfunction() \ No newline at end of file diff --git a/cmake/FindCURSES.cmake b/cmake/FindCURSES.cmake new file mode 100644 index 0000000000..a0755c6972 --- /dev/null +++ b/cmake/FindCURSES.cmake @@ -0,0 +1,148 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindCURSES +------- + +Finds the CURSES library. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following imported targets, if found: + +``Curses::curses`` + The CURSES library + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``CURSES_FOUND`` + True if the system has the CURSES library. +``CURSES_VERSION`` + The version of the CURSES library which was found. +``CURSES_INCLUDE_DIRS`` + Include directories needed to use CURSES. +``CURSES_LIBRARIES`` + Libraries needed to link to CURSES. + +Cache Variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``CURSES_INCLUDE_DIR`` + The directory containing ``foo.h``. +``CURSES_LIBRARY`` + The path to the CURSES library. + +#]=======================================================================] + +find_package(PkgConfig QUIET) +# First try for NCurses +pkg_check_modules(PC_NCurses QUIET ncurses) + +find_path(NCURSES_INCLUDE_DIR + NAMES ncurses.h + PATHS ${PC_NCurses_INCLUDE_DIRS} ${CURSES_INCLUDE_DIR} +) + +string(FIND ${NCURSES_INCLUDE_DIR} "-NOTFOUND" NCURSES_NOT_FOUND) +if(NCURSES_NOT_FOUND EQUAL -1) + # + # ncurses WAS found! + # + set(HAVE_LIBNCURSES 1) + set(CURSES_INCLUDE "") + + find_library(CURSES_LIBRARY + NAMES ncurses + PATHS ${PC_NCurses_LIBRARY_DIRS} + ) + + set(CURSES_VERSION ${PC_NCurses_VERSION}) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(CURSES + FOUND_VAR CURSES_FOUND + REQUIRED_VARS + CURSES_LIBRARY + NCURSES_INCLUDE_DIR + VERSION_VAR CURSES_VERSION + ) + + set(HAVE_LIBNCURSES 1) + set(CURSES_INCLUDE "") + + set(CURSES_LIBRARIES ${CURSES_LIBRARY}) + set(CURSES_INCLUDE_DIRS ${NCURSES_INCLUDE_DIR}) + set(CURSES_DEFINITIONS ${PC_NCurses_CFLAGS_OTHER}) + + if (NOT TARGET Curses::curses) + add_library(Curses::curses UNKNOWN IMPORTED) + set_target_properties(Curses::curses PROPERTIES + IMPORTED_LOCATION "${CURSES_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${PC_NCurses_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${CURSES_INCLUDE_DIR}" + ) + endif() +else() + # Try for PDCurses + pkg_check_modules(PC_PDCurses QUIET curses) + + find_path(PDCURSES_INCLUDE_DIR + NAMES curses.h + PATHS ${PC_PDCurses_INCLUDE_DIRS} ${CURSES_INCLUDE_DIR} + ) + + string(FIND ${PDCURSES_INCLUDE_DIR} "-NOTFOUND" PDCURSES_NOT_FOUND) + if(PDCURSES_NOT_FOUND EQUAL -1) + # + # pdcurses WAS found! + # + set(HAVE_LIBPDCURSES 1) + set(CURSES_INCLUDE "") + + find_library(CURSES_LIBRARY + NAMES curses + PATHS ${PC_PDCurses_LIBRARY_DIRS} + ) + + set(CURSES_VERSION ${PC_PDCurses_VERSION}) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(CURSES + FOUND_VAR CURSES_FOUND + REQUIRED_VARS + CURSES_LIBRARY + PDCURSES_INCLUDE_DIR + VERSION_VAR CURSES_VERSION + ) + + set(HAVE_LIBPDCURSES 1) + set(CURSES_INCLUDE "") + + set(CURSES_LIBRARIES ${CURSES_LIBRARY}) + set(CURSES_INCLUDE_DIRS ${PDCURSES_INCLUDE_DIR}) + set(CURSES_DEFINITIONS ${PC_PDCurses_CFLAGS_OTHER}) + + if (NOT TARGET Curses::curses) + add_library(Curses::curses UNKNOWN IMPORTED) + set_target_properties(Curses::curses PROPERTIES + IMPORTED_LOCATION "${CURSES_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${PC_PDCurses_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${CURSES_INCLUDE_DIR}" + ) + endif() + else() + message(FATAL_ERROR "Unable to find ncurses or pdcurses") + endif() +endif() + +mark_as_advanced( + CURSES_INCLUDE_DIR + CURSES_LIBRARY +) diff --git a/cmake/FindCUnit.cmake b/cmake/FindCUnit.cmake new file mode 100644 index 0000000000..ada87c1653 --- /dev/null +++ b/cmake/FindCUnit.cmake @@ -0,0 +1,40 @@ +# - Try to find cunit +# Once done this will define +# CUNIT_FOUND - System has cunit +# CUNIT_INCLUDE_DIRS - The cunit include directories +# CUNIT_LIBRARIES - The libraries needed to use cunit + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_CUNIT QUIET cunit) + +find_path(CUNIT_INCLUDE_DIR + NAMES CUnit/CUnit.h + HINTS ${PC_CUNIT_INCLUDE_DIRS} +) +find_library(CUNIT_LIBRARY + NAMES cunit + HINTS ${PC_CUNIT_LIBRARY_DIRS} +) + +if(CUNIT_INCLUDE_DIR) + set(_version_regex "^#define[ \t]+CU_VERSION[ \t]+\"([^\"]+)\".*") + file(STRINGS "${CUNIT_INCLUDE_DIR}/CUnit/CUnit.h" + CUNIT_VERSION REGEX "${_version_regex}") + string(REGEX REPLACE "${_version_regex}" "\\1" + CUNIT_VERSION "${CUNIT_VERSION}") + unset(_version_regex) +endif() + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set CUNIT_FOUND to TRUE +# if all listed variables are TRUE and the requested version matches. +find_package_handle_standard_args(CUnit REQUIRED_VARS + CUNIT_LIBRARY CUNIT_INCLUDE_DIR + VERSION_VAR CUNIT_VERSION) + +if(CUNIT_FOUND) + set(CUNIT_LIBRARIES ${CUNIT_LIBRARY}) + set(CUNIT_INCLUDE_DIRS ${CUNIT_INCLUDE_DIR}) +endif() + +mark_as_advanced(CUNIT_INCLUDE_DIR CUNIT_LIBRARY) diff --git a/cmake/FindJSONC.cmake b/cmake/FindJSONC.cmake new file mode 100644 index 0000000000..0779cefe7e --- /dev/null +++ b/cmake/FindJSONC.cmake @@ -0,0 +1,48 @@ +# From https://github.com/fastogt/cmake/blob/master/FindJSON-C.cmake +# Copyright (c) 2018, FastoGT +# License: BSD 3-Clause +# Modified by: Micah Snyder + +# JSONC_FOUND - true if library and headers were found +# JSONC_INCLUDE_DIRS - include directories +# JSONC_LIBRARIES - library directories + +if(JSONC_USE_STATIC) + add_library(jsonc STATIC IMPORTED GLOBAL) +else() + add_library(jsonc SHARED IMPORTED GLOBAL) +endif(JSONC_USE_STATIC) + +find_package(PkgConfig QUIET) +PKG_CHECK_MODULES(PC_JSONC QUIET json-c) + +find_path(JSONC_INCLUDE_DIR json.h + HINTS ${PC_JSONC_INCLUDEDIR} ${PC_JSONC_INCLUDE_DIRS} PATH_SUFFIXES json-c json) + +if(JSONC_USE_STATIC) + find_library(JSONC_LIBRARY NAMES libjson-c.a libjson-c-static.a + HINTS ${PC_JSONC_LIBDIR} ${PC_JSONC_LIBRARY_DIRS}) +else() + find_library(JSONC_LIBRARY NAMES json-c libjson-c + HINTS ${PC_JSONC_LIBDIR} ${PC_JSONC_LIBRARY_DIRS}) +endif(JSONC_USE_STATIC) + +set(JSONC_LIBRARIES ${JSONC_LIBRARY}) +set(JSONC_INCLUDE_DIRS ${JSONC_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(JSONC DEFAULT_MSG JSONC_LIBRARIES JSONC_INCLUDE_DIRS) + +if(JSONC_FOUND AND NOT TARGET JSONC::jsonc) + add_library(JSONC::jsonc UNKNOWN IMPORTED) + set_target_properties(JSONC::jsonc PROPERTIES + IMPORTED_LOCATION "${JSONC_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${PC_JSONC_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${JSONC_INCLUDE_DIRS}" + ) +endif() + +mark_as_advanced( + JSONC_INCLUDE_DIR + JSONC_LIBRARY +) diff --git a/cmake/FindLLVM.cmake b/cmake/FindLLVM.cmake new file mode 100644 index 0000000000..5ebd02b9e2 --- /dev/null +++ b/cmake/FindLLVM.cmake @@ -0,0 +1,195 @@ +# - Find LLVM headers and libraries. +# This module locates LLVM and adapts the llvm-config output for use with +# CMake. +# +# A given list of COMPONENTS is passed to llvm-config. +# +# The following variables are defined: +# LLVM_FOUND - true if LLVM was found +# LLVM_CXXFLAGS - C++ compiler flags for files that include LLVM headers. +# LLVM_HOST_TARGET - Target triple used to configure LLVM. +# LLVM_INCLUDE_DIRS - Directory containing LLVM include files. +# LLVM_LDFLAGS - Linker flags to add when linking against LLVM +# (includes -LLLVM_LIBRARY_DIRS). +# LLVM_LIBRARIES - Full paths to the library files to link against. +# LLVM_LIBRARY_DIRS - Directory containing LLVM libraries. +# LLVM_NATIVE_ARCH - Backend corresponding to LLVM_HOST_TARGET, e.g., +# X86 for x86_64 and i686 hosts. +# LLVM_ROOT_DIR - The root directory of the LLVM installation. +# llvm-config is searched for in ${LLVM_ROOT_DIR}/bin. +# LLVM_VERSION_MAJOR - Major version of LLVM. +# LLVM_VERSION_MINOR - Minor version of LLVM. +# LLVM_VERSION_STRING - Full LLVM version string (e.g. 6.0.0svn). +# LLVM_VERSION_BASE_STRING - Base LLVM version string without git/svn suffix (e.g. 6.0.0). +# +# Note: The variable names were chosen in conformance with the offical CMake +# guidelines, see ${CMAKE_ROOT}/Modules/readme.txt. + +# Try suffixed versions to pick up the newest LLVM install available on Debian +# derivatives. +# We also want an user-specified LLVM_ROOT_DIR to take precedence over the +# system default locations such as /usr/local/bin. Executing find_program() +# multiples times is the approach recommended in the docs. +set(llvm_config_names llvm-config-9.0 llvm-config90 + llvm-config-8.0 llvm-config80 + llvm-config-7.0 llvm-config70 + llvm-config-6.0 llvm-config60 + llvm-config-5.0 llvm-config50 + llvm-config-4.0 llvm-config40 + llvm-config-3.9 llvm-config39 + llvm-config) +find_program(LLVM_CONFIG + NAMES ${llvm_config_names} + PATHS ${LLVM_ROOT_DIR}/bin NO_DEFAULT_PATH + DOC "Path to llvm-config tool.") +find_program(LLVM_CONFIG NAMES ${llvm_config_names}) + +# Prints a warning/failure message depending on the required/quiet flags. Copied +# from FindPackageHandleStandardArgs.cmake because it doesn't seem to be exposed. +macro(_LLVM_FAIL _msg) + if(LLVM_FIND_REQUIRED) + message(FATAL_ERROR "${_msg}") + else() + if(NOT LLVM_FIND_QUIETLY) + message(STATUS "${_msg}") + endif() + endif() +endmacro() + + +if(NOT LLVM_CONFIG) + if(NOT LLVM_FIND_QUIETLY) + message(WARNING "Could not find llvm-config (LLVM >= ${LLVM_FIND_VERSION}). Try manually setting LLVM_CONFIG to the llvm-config executable of the installation to use.") + endif() +else() + macro(llvm_set var flag) + if(LLVM_FIND_QUIETLY) + set(_quiet_arg ERROR_QUIET) + endif() + set(result_code) + execute_process( + COMMAND ${LLVM_CONFIG} --${flag} + RESULT_VARIABLE result_code + OUTPUT_VARIABLE LLVM_${var} + OUTPUT_STRIP_TRAILING_WHITESPACE + ${_quiet_arg} + ) + if(result_code) + _LLVM_FAIL("Failed to execute llvm-config ('${LLVM_CONFIG}', result code: '${result_code})'") + else() + if(${ARGV2}) + file(TO_CMAKE_PATH "${LLVM_${var}}" LLVM_${var}) + endif() + endif() + endmacro() + macro(llvm_set_libs var flag components) + if(LLVM_FIND_QUIETLY) + set(_quiet_arg ERROR_QUIET) + endif() + set(result_code) + execute_process( + COMMAND ${LLVM_CONFIG} --${flag} ${components} + RESULT_VARIABLE result_code + OUTPUT_VARIABLE tmplibs + OUTPUT_STRIP_TRAILING_WHITESPACE + ${_quiet_arg} + ) + if(result_code) + _LLVM_FAIL("Failed to execute llvm-config ('${LLVM_CONFIG}', result code: '${result_code})'") + else() + file(TO_CMAKE_PATH "${tmplibs}" tmplibs) + string(REGEX MATCHALL "${pattern}[^ ]+" LLVM_${var} ${tmplibs}) + endif() + endmacro() + + llvm_set(VERSION_STRING version) + llvm_set(CXXFLAGS cxxflags) + llvm_set(HOST_TARGET host-target) + llvm_set(INCLUDE_DIRS includedir true) + llvm_set(ROOT_DIR prefix true) + llvm_set(ENABLE_ASSERTIONS assertion-mode) + + # The LLVM version string _may_ contain a git/svn suffix, so match only the x.y.z part + string(REGEX MATCH "^[0-9]+[.][0-9]+[.][0-9]+" LLVM_VERSION_BASE_STRING "${LLVM_VERSION_STRING}") + + # Versions below 4.0 do not support components debuginfomsf and demangle + if(${LLVM_VERSION_STRING} MATCHES "^3\\..*") + list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfomsf" index) + list(REMOVE_ITEM LLVM_FIND_COMPONENTS "demangle" index) + endif() + # Versions below 6.0 do not support component windowsmanifest + if(${LLVM_VERSION_STRING} MATCHES "^[3-5]\\..*") + list(REMOVE_ITEM LLVM_FIND_COMPONENTS "windowsmanifest" index) + endif() + + llvm_set(LDFLAGS ldflags) + # In LLVM 3.5+, the system library dependencies (e.g. "-lz") are accessed + # using the separate "--system-libs" flag. + llvm_set(SYSTEM_LIBS system-libs) + string(REPLACE "\n" " " LLVM_LDFLAGS "${LLVM_LDFLAGS} ${LLVM_SYSTEM_LIBS}") + llvm_set(LIBRARY_DIRS libdir true) + llvm_set_libs(LIBRARIES libs "${LLVM_FIND_COMPONENTS}") + # LLVM bug: llvm-config --libs tablegen returns -lLLVM-3.8.0 + # but code for it is not in shared library + if("${LLVM_FIND_COMPONENTS}" MATCHES "tablegen") + if (NOT "${LLVM_LIBRARIES}" MATCHES "LLVMTableGen") + set(LLVM_LIBRARIES "${LLVM_LIBRARIES};-lLLVMTableGen") + endif() + endif() + + # Versions below 4.0 do not support llvm-config --cmakedir + if(${LLVM_VERSION_STRING} MATCHES "^3\\.6.*") + set(LLVM_CMAKEDIR ${LLVM_ROOT_DIR}/share/llvm/cmake) + elseif(${LLVM_VERSION_STRING} MATCHES "^3\\..*") + set(LLVM_CMAKEDIR ${LLVM_LIBRARY_DIRS}/cmake/llvm) + else() + llvm_set(CMAKEDIR cmakedir) + endif() + + llvm_set(TARGETS_TO_BUILD targets-built) + string(REGEX MATCHALL "${pattern}[^ ]+" LLVM_TARGETS_TO_BUILD ${LLVM_TARGETS_TO_BUILD}) + + # Parse LLVM_NATIVE_ARCH manually from LLVMConfig.cmake; including it leads to issues like + # https://github.com/ldc-developers/ldc/issues/3079. + + file(STRINGS "${LLVM_CMAKEDIR}/LLVMConfig.cmake" LLVM_NATIVE_ARCH LIMIT_COUNT 1 REGEX "^set\\(LLVM_NATIVE_ARCH (.+)\\)$") + string(REGEX MATCH "set\\(LLVM_NATIVE_ARCH (.+)\\)" LLVM_NATIVE_ARCH "${LLVM_NATIVE_ARCH}") + set(LLVM_NATIVE_ARCH ${CMAKE_MATCH_1}) + message(STATUS "LLVM_NATIVE_ARCH: ${LLVM_NATIVE_ARCH}") +endif() + +# On CMake builds of LLVM, the output of llvm-config --cxxflags does not +# include -fno-rtti, leading to linker errors. Be sure to add it. +if(NOT MSVC AND (CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"))) + if(NOT ${LLVM_CXXFLAGS} MATCHES "-fno-rtti") + set(LLVM_CXXFLAGS "${LLVM_CXXFLAGS} -fno-rtti") + endif() +endif() + +# Remove some clang-specific flags for gcc. +if(CMAKE_COMPILER_IS_GNUCXX) + string(REPLACE "-Wcovered-switch-default " "" LLVM_CXXFLAGS ${LLVM_CXXFLAGS}) + string(REPLACE "-Wstring-conversion " "" LLVM_CXXFLAGS ${LLVM_CXXFLAGS}) + string(REPLACE "-fcolor-diagnostics " "" LLVM_CXXFLAGS ${LLVM_CXXFLAGS}) + # this requires more recent gcc versions (not supported by 4.9) + string(REPLACE "-Werror=unguarded-availability-new " "" LLVM_CXXFLAGS ${LLVM_CXXFLAGS}) +endif() + +# Remove gcc-specific flags for clang. +if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") + string(REPLACE "-Wno-maybe-uninitialized " "" LLVM_CXXFLAGS ${LLVM_CXXFLAGS}) +endif() + +string(REGEX REPLACE "([0-9]+).*" "\\1" LLVM_VERSION_MAJOR "${LLVM_VERSION_STRING}" ) +string(REGEX REPLACE "[0-9]+\\.([0-9]+).*[A-Za-z]*" "\\1" LLVM_VERSION_MINOR "${LLVM_VERSION_STRING}" ) + +if (${LLVM_VERSION_STRING} VERSION_LESS ${LLVM_FIND_VERSION}) + message(FATAL_ERROR "Unsupported LLVM version found ${LLVM_VERSION_STRING}. At least version ${LLVM_FIND_VERSION} is required.") +endif() + +# Use the default CMake facilities for handling QUIET/REQUIRED. +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(LLVM + REQUIRED_VARS LLVM_ROOT_DIR LLVM_HOST_TARGET + VERSION_VAR LLVM_VERSION_STRING) diff --git a/cmake/FindMSPack.cmake b/cmake/FindMSPack.cmake new file mode 100644 index 0000000000..cad448f4e1 --- /dev/null +++ b/cmake/FindMSPack.cmake @@ -0,0 +1,86 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindMSPack +------- + +Finds the MSPack library. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following imported targets, if found: + +``MSPack::mspack`` + The MSPack library + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``MSPack_FOUND`` + True if the system has the MSPack library. +``MSPack_VERSION`` + The version of the MSPack library which was found. +``MSPack_INCLUDE_DIRS`` + Include directories needed to use MSPack. +``MSPack_LIBRARIES`` + Libraries needed to link to MSPack. + +Cache Variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``MSPack_INCLUDE_DIR`` + The directory containing ``foo.h``. +``MSPack_LIBRARY`` + The path to the MSPack library. + +#]=======================================================================] + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_MSPack QUIET mspack) + +find_path(MSPack_INCLUDE_DIR + NAMES mspack.h + PATHS ${PC_MSPack_INCLUDE_DIRS} + PATH_SUFFIXES mspack +) +find_library(MSPack_LIBRARY + NAMES mspack + PATHS ${PC_MSPack_LIBRARY_DIRS} +) + +set(MSPack_VERSION ${PC_MSPack_VERSION}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(MSPack + FOUND_VAR MSPack_FOUND + REQUIRED_VARS + MSPack_LIBRARY + MSPack_INCLUDE_DIR + VERSION_VAR MSPack_VERSION +) + +if(MSPack_FOUND) + set(MSPack_LIBRARIES ${MSPack_LIBRARY}) + set(MSPack_INCLUDE_DIRS ${MSPack_INCLUDE_DIR}) + set(MSPack_DEFINITIONS ${PC_MSPack_CFLAGS_OTHER}) +endif() + +if(MSPack_FOUND AND NOT TARGET MSPack::mspack) + add_library(MSPack::mspack UNKNOWN IMPORTED) + set_target_properties(MSPack::mspack PROPERTIES + IMPORTED_LOCATION "${MSPack_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${PC_MSPack_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${MSPack_INCLUDE_DIR}" + ) +endif() + +mark_as_advanced( + MSPack_INCLUDE_DIR + MSPack_LIBRARY +) diff --git a/cmake/FindMilter.cmake b/cmake/FindMilter.cmake new file mode 100644 index 0000000000..39a19e3b1c --- /dev/null +++ b/cmake/FindMilter.cmake @@ -0,0 +1,86 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindMilter +------- + +Finds the Milter library. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following imported targets, if found: + +``Sendmail::milter`` + The Sendmail milter library + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``Milter_FOUND`` + True if the system has the Milter library. +``Milter_VERSION`` + The version of the Milter library which was found. +``Milter_INCLUDE_DIRS`` + Include directories needed to use Milter. +``Milter_LIBRARIES`` + Libraries needed to link to Milter. + +Cache Variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``Milter_INCLUDE_DIR`` + The directory containing ``foo.h``. +``Milter_LIBRARY`` + The path to the Milter library. + +#]=======================================================================] + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_Milter QUIET milter) + +find_path(Milter_INCLUDE_DIR + NAMES libmilter/mfapi.h + PATHS ${PC_Milter_INCLUDE_DIRS} + PATH_SUFFIXES milter +) +find_library(Milter_LIBRARY + NAMES milter + PATHS ${PC_Milter_LIBRARY_DIRS} +) + +set(Milter_VERSION ${PC_Milter_VERSION}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Milter + FOUND_VAR Milter_FOUND + REQUIRED_VARS + Milter_LIBRARY + Milter_INCLUDE_DIR + VERSION_VAR Milter_VERSION +) + +if(Milter_FOUND) + set(Milter_LIBRARIES ${Milter_LIBRARY}) + set(Milter_INCLUDE_DIRS ${Milter_INCLUDE_DIR}) + set(Milter_DEFINITIONS ${PC_Milter_CFLAGS_OTHER}) +endif() + +if(Milter_FOUND AND NOT TARGET Sendmail::milter) + add_library(Sendmail::milter UNKNOWN IMPORTED) + set_target_properties(Sendmail::milter PROPERTIES + IMPORTED_LOCATION "${Milter_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${PC_Milter_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${Milter_INCLUDE_DIR}" + ) +endif() + +mark_as_advanced( + Milter_INCLUDE_DIR + Milter_LIBRARY +) diff --git a/cmake/FindPCRE2.cmake b/cmake/FindPCRE2.cmake new file mode 100644 index 0000000000..b529b72c11 --- /dev/null +++ b/cmake/FindPCRE2.cmake @@ -0,0 +1,86 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindPCRE2 +------- + +Finds the PCRE2 library. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following imported targets, if found: + +``PCRE2::pcre2`` + The PCRE2 library + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``PCRE2_FOUND`` + True if the system has the PCRE2 library. +``PCRE2_VERSION`` + The version of the PCRE2 library which was found. +``PCRE2_INCLUDE_DIRS`` + Include directories needed to use PCRE2. +``PCRE2_LIBRARIES`` + Libraries needed to link to PCRE2. + +Cache Variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``PCRE2_INCLUDE_DIR`` + The directory containing ``foo.h``. +``PCRE2_LIBRARY`` + The path to the PCRE2 library. + +#]=======================================================================] + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_PCRE2 QUIET pcre2) + +find_path(PCRE2_INCLUDE_DIR + NAMES pcre2.h + PATHS ${PC_PCRE2_INCLUDE_DIRS} + PATH_SUFFIXES pcre2 +) +find_library(PCRE2_LIBRARY + NAMES pcre2-8 + PATHS ${PC_PCRE2_LIBRARY_DIRS} +) + +set(PCRE2_VERSION ${PC_PCRE2_VERSION}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PCRE2 + FOUND_VAR PCRE2_FOUND + REQUIRED_VARS + PCRE2_LIBRARY + PCRE2_INCLUDE_DIR + VERSION_VAR PCRE2_VERSION +) + +if(PCRE2_FOUND) + set(PCRE2_LIBRARIES ${PCRE2_LIBRARY}) + set(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR}) + set(PCRE2_DEFINITIONS ${PC_PCRE2_CFLAGS_OTHER}) +endif() + +if(PCRE2_FOUND AND NOT TARGET PCRE2::pcre2) + add_library(PCRE2::pcre2 UNKNOWN IMPORTED) + set_target_properties(PCRE2::pcre2 PROPERTIES + IMPORTED_LOCATION "${PCRE2_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${PC_PCRE2_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${PCRE2_INCLUDE_DIR}" + ) +endif() + +mark_as_advanced( + PCRE2_INCLUDE_DIR + PCRE2_LIBRARY +) diff --git a/cmake/FindPthreadW32.cmake b/cmake/FindPthreadW32.cmake new file mode 100644 index 0000000000..4fded1eb70 --- /dev/null +++ b/cmake/FindPthreadW32.cmake @@ -0,0 +1,90 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindPThreadW32 +------- + +Finds the PThreadW32 library. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following imported targets, if found: + +``PThreadW32::pthreadw32`` + The PThreadW32 library + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``PThreadW32_FOUND`` + True if the system has the PThreadW32 library. +``PThreadW32_VERSION`` + The version of the PThreadW32 library which was found. +``PThreadW32_INCLUDE_DIRS`` + Include directories needed to use PThreadW32. +``PThreadW32_LIBRARIES`` + Libraries needed to link to PThreadW32. + +Cache Variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``PThreadW32_INCLUDE_DIR`` + The directory containing ``foo.h``. +``PThreadW32_LIBRARY`` + The path to the PThreadW32 library. + +#]=======================================================================] + +if(NOT WIN32) + message(FATAL_ERROR "This find module intended for use on Windows") +endif() + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_PThreadW32 QUIET pthreadw32) + +find_path(PThreadW32_INCLUDE_DIR + NAMES pthread.h + PATHS ${PC_PThreadW32_INCLUDE_DIRS} + PATH_SUFFIXES pthreadw32 +) +find_library(PThreadW32_LIBRARY + NAMES pthreadVC2 + PATHS ${PC_PThreadW32_LIBRARY_DIRS} +) + +set(PThreadW32_VERSION ${PC_PThreadW32_VERSION}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PThreadW32 + FOUND_VAR PThreadW32_FOUND + REQUIRED_VARS + PThreadW32_LIBRARY + PThreadW32_INCLUDE_DIR + VERSION_VAR PThreadW32_VERSION +) + +if(PThreadW32_FOUND) + set(PThreadW32_LIBRARIES ${PThreadW32_LIBRARY}) + set(PThreadW32_INCLUDE_DIRS ${PThreadW32_INCLUDE_DIR}) + set(PThreadW32_DEFINITIONS ${PC_PThreadW32_CFLAGS_OTHER}) +endif() + +if(PThreadW32_FOUND AND NOT TARGET PThreadW32::pthreadw32) + add_library(PThreadW32::pthreadw32 UNKNOWN IMPORTED) + set_target_properties(PThreadW32::pthreadw32 PROPERTIES + IMPORTED_LOCATION "${PThreadW32_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${PC_PThreadW32_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${PThreadW32_INCLUDE_DIR}" + ) +endif() + +mark_as_advanced( + PThreadW32_INCLUDE_DIR + PThreadW32_LIBRARY +) diff --git a/cmake/FindSYSTEMD.cmake b/cmake/FindSYSTEMD.cmake new file mode 100644 index 0000000000..ee32ffbcac --- /dev/null +++ b/cmake/FindSYSTEMD.cmake @@ -0,0 +1,125 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindSYSTEMD +------- + +Finds the SYSTEMD library. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following imported targets, if found: + +``SYSTEMD::systemd`` + The SYSTEMD library + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``SYSTEMD_FOUND`` + True if the system has the SYSTEMD library. +``SYSTEMD_VERSION`` + The version of the SYSTEMD library which was found. +``SYSTEMD_INCLUDE_DIRS`` + Include directories needed to use SYSTEMD. +``SYSTEMD_LIBRARIES`` + Libraries needed to link to SYSTEMD. + +``SYSTEMD_PROGRAM_FOUND`` + True if library and headers were found +``SYSTEMD_UNIT_DIR`` + Include directories + +Cache Variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``SYSTEMD_INCLUDE_DIR`` + The directory containing ``foo.h``. +``SYSTEMD_LIBRARY`` + The path to the SYSTEMD library. + +#]=======================================================================] + +# +# First, We'll check for libsystemd and define a target. +# +find_package(PkgConfig QUIET) +pkg_check_modules(PC_SYSTEMD QUIET libsystemd) + +if (NOT PC_SYSTEMD_FOUND) + # libsystemd not found. What about libsystemd-DAEMON? + pkg_check_modules(PC_SYSTEMD QUIET libsystemd-daemon) + if (PC_SYSTEMD_FOUND) + message(STATUS "libsystemd-daemon found") + else() + message(STATUS "libsystemd-daemon not found") + endif() +endif() + +find_path(SYSTEMD_INCLUDE_DIR + NAMES systemd/sd-bus.h + PATHS ${PC_SYSTEMD_INCLUDE_DIRS} + PATH_SUFFIXES systemd +) +find_library(SYSTEMD_LIBRARY + NAMES systemd + PATHS ${PC_SYSTEMD_LIBRARY_DIRS} +) + +set(SYSTEMD_VERSION ${PC_SYSTEMD_VERSION}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SYSTEMD + FOUND_VAR SYSTEMD_FOUND + REQUIRED_VARS + SYSTEMD_LIBRARY + SYSTEMD_INCLUDE_DIR + VERSION_VAR SYSTEMD_VERSION +) + +if(SYSTEMD_FOUND) + set(SYSTEMD_LIBRARIES ${SYSTEMD_LIBRARY}) + set(SYSTEMD_INCLUDE_DIRS ${SYSTEMD_INCLUDE_DIR}) + set(SYSTEMD_DEFINITIONS ${PC_SYSTEMD_CFLAGS_OTHER}) + + if(NOT TARGET SYSTEMD::systemd) + add_library(SYSTEMD::systemd UNKNOWN IMPORTED) + set_target_properties(SYSTEMD::systemd PROPERTIES + IMPORTED_LOCATION "${SYSTEMD_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${PC_SYSTEMD_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${SYSTEMD_INCLUDE_DIR}" + ) + endif() +endif() + +mark_as_advanced( + SYSTEMD_INCLUDE_DIR + SYSTEMD_LIBRARY +) + +# +# Next, We'll check for plain ol' systemd application, needed if we want to install the service unit files +# +pkg_check_modules(SYSTEMD_PROGRAM QUIET systemd) + +if (SYSTEMD_PROGRAM_FOUND) + if ("${SYSTEMD_UNIT_DIR}" STREQUAL "") + # Use pkg-config to look up the systemd unit install directory + execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} + --variable=systemdsystemunitdir systemd + OUTPUT_VARIABLE SYSTEMD_UNIT_DIR) + string(REGEX REPLACE "[ \t\n]+" "" SYSTEMD_UNIT_DIR "${SYSTEMD_UNIT_DIR}") + endif() + + message(STATUS "systemd services install dir: ${SYSTEMD_UNIT_DIR}") +else() + if (SYSTEMD_UNIT_DIR) + message (FATAL_ERROR "SYSTEMD_UNIT_DIR was defined but pkg-config was not able to find systemd!") + endif() +endif() diff --git a/cmake/TestInline.c b/cmake/TestInline.c new file mode 100644 index 0000000000..db0d056c69 --- /dev/null +++ b/cmake/TestInline.c @@ -0,0 +1,5 @@ +/* Test source lifted from /usr/share/autoconf/autoconf/c.m4 */ +typedef int foo_t; +static inline foo_t static_foo(){return 0;} +foo_t foo(){return 0;} +int main(int argc, char *argv[]){return 0;} diff --git a/cmake/TestInline.cmake b/cmake/TestInline.cmake new file mode 100644 index 0000000000..a3264b2405 --- /dev/null +++ b/cmake/TestInline.cmake @@ -0,0 +1,22 @@ +# From https://gitlab.kitware.com/cmake/community/-/wikis/contrib/macros/TestInline +# Modified to use configure_file() approach, and to address script path issues. +# See: https://stackoverflow.com/questions/3781222/add-definitions-vs-configure-file +# Inspired from /usr/share/autoconf/autoconf/c.m4 + +GET_FILENAME_COMPONENT(_selfdir_TestInline + "${CMAKE_CURRENT_LIST_FILE}" PATH) + +FOREACH(KEYWORD "inline" "__inline__" "__inline") + IF(NOT DEFINED C_INLINE) + TRY_COMPILE(C_HAS_${KEYWORD} "${CMAKE_CURRENT_BINARY_DIR}" + "${_selfdir_TestInline}/TestInline.c" + COMPILE_DEFINITIONS "-Dinline=${KEYWORD}") + IF(C_HAS_${KEYWORD}) + SET(C_INLINE TRUE) + SET(INLINE_KEYWORD "${KEYWORD}" CACHE INTERNAL "inline macro defined as ${KEYWORD}") + ENDIF(C_HAS_${KEYWORD}) + ENDIF(NOT DEFINED C_INLINE) +ENDFOREACH(KEYWORD) +IF(NOT DEFINED C_INLINE) + SET(INLINE_KEYWORD "" CACHE INTERNAL "inline macro definition not required") +ENDIF(NOT DEFINED C_INLINE) diff --git a/cmake/Version.cmake b/cmake/Version.cmake new file mode 100644 index 0000000000..8ac4849c97 --- /dev/null +++ b/cmake/Version.cmake @@ -0,0 +1,11 @@ +# Converts a version such as 1.2.255 to 0x0102ff +function(HexVersion version_hex_var major minor patch) + math(EXPR version_dec "${major} * 256 * 256 + ${minor} * 256 + ${patch}") + set(version_hex "0x") + foreach(i RANGE 5 0 -1) + math(EXPR num "(${version_dec} >> (4 * ${i})) & 15") + string(SUBSTRING "0123456789abcdef" ${num} 1 num_hex) + set(version_hex "${version_hex}${num_hex}") + endforeach() + set(${version_hex_var} "${version_hex}" PARENT_SCOPE) +endfunction() diff --git a/cmake/config.cmake b/cmake/config.cmake new file mode 100644 index 0000000000..234e8e5a15 --- /dev/null +++ b/cmake/config.cmake @@ -0,0 +1,142 @@ +include(CheckIncludeFile) +include(CheckLibraryExists) +include(CheckSymbolExists) +include(CheckFunctionExists) +include(CheckCSourceCompiles) + +# Check for mmap() support, required for HAVE_MPOOL. +# +# checks for private fixed mappings, we don't need fixed mappings, +# so check only wether private mappings work. +check_include_file(sys/mman.h HAVE_SYS_MMAN_H) +if(MMAP_FOR_CROSSCOMPILING) + set(HAVE_MMAP 1) +else() + check_c_source_compiles( + " + #include + #include + #include + #ifdef HAVE_SYS_TYPES_H + #include + #endif + #ifdef HAVE_SYS_STAT_H + #include + #endif + #include + int main(void) + { + char *data, *data2, *data3; + size_t i, datasize = 1024; + int fd; + + /* First, make a file with some known garbage in it. */ + data = (char*) malloc(datasize); + if(!data) + return 1; + for(i=0;i + int main(void) + { + mmap((void *)0, 0, PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + return 0; + } + " + HAVE_MMAP_MAP_ANONYMOUS +) +if(HAVE_MMAP_MAP_ANONYMOUS) + set(ANONYMOUS_MAP MAP_ANONYMOUS) +else() + check_c_source_compiles( + " + /* OPENBSD WORKAROUND - DND*/ + #include + /* OPENBSD WORKAROUND - END*/ + #include + int main(void) + { + mmap((void *)0, 0, PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); + return 0; + } + " + HAVE_MMAP_MAP_ANON + ) + if(HAVE_MMAP_MAP_ANON) + set(ANONYMOUS_MAP MAP_ANON) + endif() +endif() + +# Check for getting the pagesize. +check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE) +check_c_source_compiles( + " + #include + #if HAVE_UNISTD_H + #include + #endif + int main(void) + { + int x = sysconf(_SC_PAGESIZE); + return 0; + } + " + HAVE_SYSCONF_SC_PAGESIZE +) + +# Check for mempool support +if(DISABLE_MPOOL) + message("****** mempool support disabled (DISABLE_MPOOL enabled)") +elseif(NOT HAVE_MMAP) + message("****** mempool support disabled (mmap() not available or not usable)") +elseif(NOT HAVE_GETPAGESIZE AND NOT HAVE_SYSCONF_SC_PAGESIZE) + message("****** mempool support disabled (pagesize cannot be determined)") +elseif(NOT HAVE_MMAP_MAP_ANON AND NOT HAVE_MMAP_MAP_ANONYMOUS) + message("****** mempool support disabled (anonymous mmap not available)") +else() + set(USE_MPOOL 1) +endif() diff --git a/configure.ac b/configure.ac index ac08acccfb..d5aaf830d5 100644 --- a/configure.ac +++ b/configure.ac @@ -40,7 +40,7 @@ AC_CREATE_TARGET_H([target.h]) dnl -Wall and -Werror here are NOT CFLAGS, they refer to automake warnings dnl enable stealth builds and psychedelic tests -AM_INIT_AUTOMAKE([1.11.1 -Wall -Wportability -Wno-override std-options foreign dist-bzip2 no-define color-tests parallel-tests tar-ustar]) +AM_INIT_AUTOMAKE([1.11.1 -Wall -Wportability -Wno-override subdir-objects std-options foreign dist-bzip2 no-define color-tests parallel-tests tar-ustar]) AM_SILENT_RULES([yes]) AC_USE_SYSTEM_EXTENSIONS m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) @@ -198,6 +198,7 @@ if test "x$enable_libclamav_only" != "xyes"; then clamscan/Makefile database/Makefile docs/Makefile + shared/Makefile clamd/Makefile clamd/clamav-daemon.service clamd/clamav-daemon.socket @@ -232,7 +233,12 @@ if test "x$enable_libclamav_only" != "xyes"; then fi AM_COND_IF([BUILD_CLAMONACC], - [AC_CONFIG_FILES([clamonacc/Makefile])]) + [AC_CONFIG_FILES([ + clamonacc/Makefile + clamonacc/clamav-clamonacc.service + docs/man/clamonacc.8 + ]) +]) # Define variables needed to generate clamav-types.h. m4_include([m4/reorganization/types.m4]) diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt new file mode 100644 index 0000000000..cc228d6424 --- /dev/null +++ b/docs/CMakeLists.txt @@ -0,0 +1,100 @@ + +# +# man pages +# +# .1 files +configure_file(man/clamscan.1.in man/clamscan.1) +configure_file(man/freshclam.1.in man/freshclam.1) +configure_file(man/sigtool.1.in man/sigtool.1) +configure_file(man/clamdscan.1.in man/clamdscan.1) +configure_file(man/clamconf.1.in man/clamconf.1) +configure_file(man/clamdtop.1.in man/clamdtop.1) +configure_file(man/clamsubmit.1.in man/clamsubmit.1) +configure_file(man/clambc.1.in man/clambc.1) +# .5 files +configure_file(man/clamd.conf.5.in man/clamd.conf.5) +configure_file(man/clamav-milter.conf.5.in man/clamav-milter.conf.5) +configure_file(man/freshclam.conf.5.in man/freshclam.conf.5) +# .8 files +configure_file(man/clamd.8.in man/clamd.8) +configure_file(man/clamav-milter.8.in man/clamav-milter.8) +if(LINUX) + configure_file(man/clamonacc.8.in man/clamonacc.8) +endif() + +set(MAN1_FILES + man/clamscan.1 + man/freshclam.1 + man/sigtool.1 + man/clamdscan.1 + man/clamconf.1 + man/clamdtop.1 + man/clamsubmit.1 + man/clambc.1) +foreach(m IN LISTS MAN1_FILES) + install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/${m} + DESTINATION + ${CMAKE_INSTALL_PREFIX}/share/man/man1) +endforeach() + +set(MAN5_FILES + man/clamd.conf.5 + man/clamav-milter.conf.5 + man/freshclam.conf.5) +foreach(m IN LISTS MAN5_FILES) + install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/${m} + DESTINATION + ${CMAKE_INSTALL_PREFIX}/share/man/man5) +endforeach() + +set(MAN8_FILES + man/clamd.8 + man/clamav-milter.8) +foreach(m IN LISTS MAN8_FILES) + install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/${m} + DESTINATION + ${CMAKE_INSTALL_PREFIX}/share/man/man8) +endforeach() + +if(LINUX) + # Also install Linux-only manpage + install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/man/clamonacc.8 + DESTINATION + ${CMAKE_INSTALL_PREFIX}/share/man/man8) +endif() + +if(ENABLE_DOXYGEN) + # + # clamav.h doxygen docs + # + find_package(Doxygen REQUIRED) + + set(DOXYGEN_GENERATE_HTML YES) + set(DOXYGEN_GENERATE_MAN NO) + set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + + set(EXTRACT_ALL YES) + set(HIDE_UNDOC_MEMBERS YES) + set(JAVADOC_AUTOBRIEF YES) + set(OPTIMIZE_OUTPUT_FOR_C YES) + set(FULL_PATH_NAMES NO) + set(GENERATE_LATEX NO) + + doxygen_add_docs(doxygen + ${CMAKE_SOURCE_DIR}/libclamav/clamav.h + ${CMAKE_SOURCE_DIR}/libfreshclam/libfreshclam.h + COMMENT "Generate html documentation" + ) + + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html + DESTINATION ${CMAKE_INSTALL_DOCDIR} + COMPONENT "docs" OPTIONAL) +endif() diff --git a/docs/Makefile.am b/docs/Makefile.am index 48bc70728f..63fd5b76dd 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -21,6 +21,10 @@ EXTRA_DIST = html $(top_srcdir)/docs/man/*.in man_MANS = man/clamscan.1 man/freshclam.1 man/sigtool.1 man/clamd.8 man/clamd.conf.5 man/clamdscan.1 man/clamav-milter.8 man/clamav-milter.conf.5 man/freshclam.conf.5 man/clamconf.1 man/clamdtop.1 man/clambc.1 +if BUILD_CLAMONACC +man_MANS += man/clamonacc.8 +endif + if ENABLE_CLAMSUBMIT man_MANS += man/clamsubmit.1 endif diff --git a/docs/man/clamdscan.1.in b/docs/man/clamdscan.1.in index 4d34f88db5..226a0b6107 100644 --- a/docs/man/clamdscan.1.in +++ b/docs/man/clamdscan.1.in @@ -1,59 +1,68 @@ .TH "Clamd client" "1" "February 12, 2009" "ClamAV @VERSION@" "Clam AntiVirus" .SH "NAME" -.LP +.LP clamdscan \- scan files and directories for viruses using Clam AntiVirus Daemon .SH "SYNOPSIS" -.LP +.LP clamdscan [options] [file/directory] .SH "DESCRIPTION" -.LP +.LP clamdscan is a clamd client which may be used as a clamscan replacement. It accepts all the options implemented in clamscan but most of them will be ignored because its scanning abilities only depend on clamd. .SH "OPTIONS" -.LP +.LP -.TP +.TP \fB\-h, \-\-help\fR Display help information and exit. -.TP +.TP \fB\-V, \-\-version\fR Print version number and exit. -.TP +.TP \fB\-v, \-\-verbose\fR Be verbose. -.TP +.TP \fB\-\-quiet\fR Be quiet \- only output error messages. -.TP +.TP \fB\-\-stdout\fR Write all messages (except for libclamav output) to the standard output (stdout). -.TP +.TP \fB\-\-config\-file=FILE\fR Read clamd settings from FILE. -.TP +.TP \fB\-l FILE, \-\-log=FILE\fR Save the scan report to FILE. -.TP +.TP \fB\-f FILE, \-\-file\-list=FILE\fR Scan files listed line by line in FILE. -.TP +.TP +\fB\-p A[:I], \-\-ping A[:I]\fR +Ping clamd A times at optional interval I. +.TP \fB\-m, \-\-multiscan\fR In the multiscan mode clamd will attempt to scan the directory contents in parallel using available threads. This option is especially useful on multiprocessor and multi-core systems. If you pass more than one file or directory in the command line, they are put in a queue and sent to clamd individually. This means, that single files are always scanned by a single thread. Similarly, clamdscan will wait for clamd to finish a directory scan (performed in multiscan mode) before sending request to scan another directory. This option can be combined with \-\-fdpass (see below). .TP \fB\-z, \-\-allmatch\fR After a match, continue scanning within the file for additional matches. -.TP +.TP \fB\-\-remove\fR Remove infected files. \fBBe careful.\fR -.TP +.TP \fB\-\-move=DIRECTORY\fR Move infected files into DIRECTORY. -.TP +.TP +\fB\-\-copy=DIRECTORY\fR +Copy infected files into DIRECTORY. +.TP \fB\-\-no\-summary\fR Do not display summary at the end of scanning. .TP \fB\-\-reload\fR Request clamd to reload virus database. .TP +\fB\-\-allmatch\fR +Continue scanning within file after finding a match. +.TP \fB\-\-fdpass\fR Pass the file descriptor permissions to clamd. This is useful if clamd is running as a different user as it is faster than streaming the file to clamd. Only available if connected to clamd via local(unix) socket. @@ -61,16 +70,16 @@ Only available if connected to clamd via local(unix) socket. \fB\-\-stream\fR Forces file streaming to clamd. This is generally not needed as clamdscan detects automatically if streaming is required. This option only exists for debugging and testing purposes, in all other cases \-\-fdpass is preferred. .SH "EXAMPLES" -.LP -.TP +.LP +.TP (0) To scan a one file: \fBclamdscan file\fR -.TP +.TP (1) To scan a current working directory: \fBclamdscan\fR -.TP +.TP (2) To scan all files in /home: \fBclamdscan /home\fR @@ -85,17 +94,17 @@ Forces file streaming to clamd. This is generally not needed as clamdscan detect \fBcat file_to_scan | clamdscan \-\fR .SH "RETURN CODES" -.LP +.LP 0 : No virus found. -.TP +.TP 1 : Virus(es) found. -.TP +.TP 2 : An error occurred. .SH "CREDITS" Please check the full documentation for credits. .SH "AUTHOR" -.LP +.LP Tomasz Kojm .SH "SEE ALSO" -.LP +.LP clamd(8), clamd.conf(5), clamscan(1) diff --git a/docs/man/clamonacc.8.in b/docs/man/clamonacc.8.in new file mode 100644 index 0000000000..f7bbea847c --- /dev/null +++ b/docs/man/clamonacc.8.in @@ -0,0 +1,81 @@ +.TH "Clam On-Access Scanner" "8" "July 29, 2020" "ClamAV @VERSION@" "Clam AntiVirus" +.SH "NAME" +.LP +clamonacc \- an anti\-virus on\-access scanning daemon and clamd client +.SH "SYNOPSIS" +.LP +clamd [options] +.SH "DESCRIPTION" +.LP +The clamonacc daemon registers for file access notifications from the Linux kernel and in response, submits scans to the clamd scanning daemon for a verdict. On-Access is only available on Linux systems. On Linux, On-Access requires a kernel version >= 3.8. This is because it leverages a kernel api called fanotify to block processes from attempting to access malicious files. This prevention occurs in kernel-space, and thus offers stronger protection than a purely user-space solution. +.SH "OPTIONS" +.LP +.TP +\fB\-h, \-\-help\fR +Output help information and exit. +.TP +\fB\-V, \-\-version\fR +Print the version number and exit. +.TP +\fB\-v, \-\-verbose\fR +Be verbose. +.TP +\fB\-l FILE, \-\-log=FILE\fR +Save the scan report to FILE. +.TP +\fB\-F, \-\-foreground\fR +Run in foreground; do not daemonize. +.TP +\fB\-w FILE, \-\-watch\-list=FILE\fR +Watch directories from FILE. +.TP +\fB\-e FILE, \-\-exclude\-list=FILE\fR +Exclude directories from FILE. +.TP +\fB\-p A[:I], \-\-ping A[:I]\fR +Ping clamd A times at optional interval I. +.TP +\fB\-\-remove\fR +Remove infected files. \fBBe careful.\fR +.TP +\fB\-\-move=DIRECTORY\fR +Move infected files into DIRECTORY. +.TP +\fB\-\-copy=DIRECTORY\fR +Copy infected files into DIRECTORY. +.TP +\fB\-c FILE, \-\-config\-file=FILE\fR +Read configuration from FILE. +.TP +\fB\-\-allmatch\fR +Continue scanning within file after finding a match. +.TP +\fB\-\-fdpass\fR +Pass the file descriptor permissions to clamd. This is useful if clamd is running as a different user as it is faster than streaming the file to clamd. +Only available if connected to clamd via local(unix) socket. +.TP +\fB\-\-stream\fR +Forces file streaming to clamd. This is generally not needed as clamdscan detects automatically if streaming is required. This option only exists for debugging and testing purposes, in all other cases \-\-fdpass is preferred. +.SH "SIGNALS" +.LP +ClamOnAcc recognizes the following signals: +.TP +\fBSIGHUP\fR +Reopen the logfile. +.TP +\fBSIGUSR2\fR +Reload the signature databases. +.TP +\fBSIGTERM\fR +Perform a clean exit. +.SH "FILES" +.LP +@CFGDIR@/clamd.conf +.SH "CREDITS" +Please check the full documentation for credits. +.SH "AUTHOR" +.LP +Tomasz Kojm +.SH "SEE ALSO" +.LP +clamd.conf(5), clamd(8) diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt new file mode 100644 index 0000000000..fa9ac8029f --- /dev/null +++ b/etc/CMakeLists.txt @@ -0,0 +1,23 @@ +# +# clamav config files +# + +install( + FILES + ${CMAKE_CURRENT_SOURCE_DIR}/clamd.conf.sample + DESTINATION + ${APP_CONFIG_DIRECTORY}) + +install( + FILES + ${CMAKE_CURRENT_SOURCE_DIR}/freshclam.conf.sample + DESTINATION + ${APP_CONFIG_DIRECTORY}) + +if(ENABLE_MILTER) + install( + FILES + ${CMAKE_CURRENT_SOURCE_DIR}/clamav-milter.conf.sample + DESTINATION + ${APP_CONFIG_DIRECTORY}) +endif() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000000..6805fd6cb7 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,24 @@ +# Copyright (C) 2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved. + +cmake_minimum_required( VERSION 3.12...3.13 ) + +# +# Example executables +# +add_executable(ex1) +target_sources(ex1 + PRIVATE ex1.c) +set_target_properties( ex1 PROPERTIES COMPILE_FLAGS "${WARNCFLAGS}" ) +target_link_libraries(ex1 + PRIVATE + ClamAV::libclamav) + +if(ENABLE_STATIC_LIB) + add_executable(ex1_static) + set_target_properties( ex1_static PROPERTIES COMPILE_FLAGS "${WARNCFLAGS}" ) + target_sources(ex1_static + PRIVATE ex1.c) + target_link_libraries(ex1_static + PRIVATE + ClamAV::libclamav_static) +endif() diff --git a/freshclam/CMakeLists.txt b/freshclam/CMakeLists.txt new file mode 100644 index 0000000000..545d5d4ba6 --- /dev/null +++ b/freshclam/CMakeLists.txt @@ -0,0 +1,55 @@ +# Copyright (C) 2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved. + +cmake_minimum_required( VERSION 3.12...3.13 ) + +if(WIN32) + add_definitions(-DWIN32_LEAN_AND_MEAN) + add_definitions(-DHAVE_STRUCT_TIMESPEC) + + # Windows compatibility headers + include_directories(${CMAKE_SOURCE_DIR}/win32/compat) +endif() + +# The freshclam executable. +add_executable( freshclam-bin ) +target_sources( freshclam-bin + PRIVATE + freshclam.c + execute.c + execute.h + notify.c + notify.h ) +if(WIN32) + target_sources( freshclam-bin PRIVATE ${CMAKE_SOURCE_DIR}/win32/res/freshclam.rc ) +endif() +set_target_properties( freshclam-bin PROPERTIES COMPILE_FLAGS "${WARNCFLAGS}" ) +target_link_libraries(freshclam-bin + PRIVATE + ClamAV::libfreshclam + ClamAV::libclamav + ClamAV::shared ) +if(WIN32) + install(TARGETS freshclam-bin DESTINATION ${CMAKE_INSTALL_PREFIX}) +else() + install(TARGETS freshclam-bin DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() + +# Install an empty database directory +if(WIN32) + INSTALL(CODE "FILE(MAKE_DIRECTORY \${ENV}\${CMAKE_INSTALL_PREFIX}/database)") +else() + INSTALL(CODE "FILE(MAKE_DIRECTORY \${ENV}\${CMAKE_INSTALL_PREFIX}/share/clamav)") +endif() + +# now we rename resman-bin executable to resman using target properties +set_target_properties( freshclam-bin + PROPERTIES OUTPUT_NAME freshclam ) + +if(SYSTEMD_FOUND) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/clamav-freshclam.service.in + ${CMAKE_CURRENT_BINARY_DIR}/clamav-freshclam.service @ONLY) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/clamav-freshclam.service + DESTINATION ${SYSTEMD_UNIT_DIR}) +endif() diff --git a/freshclam/Makefile.am b/freshclam/Makefile.am index e05e170d23..95f4d6c6b5 100644 --- a/freshclam/Makefile.am +++ b/freshclam/Makefile.am @@ -22,15 +22,6 @@ bin_PROGRAMS = freshclam freshclam_SOURCES = \ - $(top_srcdir)/shared/output.h \ - $(top_srcdir)/shared/optparser.c \ - $(top_srcdir)/shared/optparser.h \ - $(top_srcdir)/shared/getopt.c \ - $(top_srcdir)/shared/getopt.h \ - $(top_srcdir)/shared/misc.h \ - $(top_srcdir)/shared/misc.c \ - $(top_srcdir)/shared/clamdcom.h \ - $(top_srcdir)/shared/clamdcom.c \ freshclam.c \ notify.c \ notify.h \ @@ -42,9 +33,9 @@ systemdsystemunit_DATA = clamav-freshclam.service endif AM_CFLAGS=@WERR_CFLAGS@ -DEFS = @DEFS@ -DCL_NOTHREADS -AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav -I$(top_srcdir)/libfreshclam @CURL_CPPFLAGS@ @SSL_CPPFLAGS@ @FRESHCLAM_CPPFLAGS@ @ZLIB_CFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ -LIBS = @SSL_LDFLAGS@ @SSL_LIBS@ @CURL_LDFLAGS@ @CURL_LIBS@ $(top_builddir)/libclamav/libclamav.la $(top_builddir)/libfreshclam/libfreshclam.la @FRESHCLAM_LIBS@ @ZLIB_LIBS@ @THREAD_LIBS@ +DEFS = @DEFS@ +AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav -I$(top_builddir)/libclamav -I$(top_srcdir)/libclamunrar_iface -I$(top_srcdir)/libfreshclam @CURL_CPPFLAGS@ @SSL_CPPFLAGS@ @FRESHCLAM_CPPFLAGS@ @ZLIB_CFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ +LIBS = @SSL_LDFLAGS@ @SSL_LIBS@ @CURL_LDFLAGS@ @CURL_LIBS@ $(top_builddir)/libclamav/libclamav.la $(top_builddir)/shared/libshared.la $(top_builddir)/libfreshclam/libfreshclam.la @FRESHCLAM_LIBS@ @ZLIB_LIBS@ @THREAD_LIBS@ AM_INSTALLCHECK_STD_OPTIONS_EXEMPT=freshclam$(EXEEXT) CLEANFILES=*.gcda *.gcno diff --git a/freshclam/execute.c b/freshclam/execute.c index df08f663b4..8abd0cd035 100644 --- a/freshclam/execute.c +++ b/freshclam/execute.c @@ -29,8 +29,8 @@ #include #include -#include "shared/output.h" -#include "shared/optparser.h" +#include "output.h" +#include "optparser.h" #include "execute.h" #define MAX_CHILDREN 5 diff --git a/freshclam/execute.h b/freshclam/execute.h index 7b5319eb22..679aa5b1af 100644 --- a/freshclam/execute.h +++ b/freshclam/execute.h @@ -20,7 +20,7 @@ #ifndef __EXECUTE_H #define __EXECUTE_H -#include "shared/optparser.h" +#include "optparser.h" extern int g_active_children; diff --git a/freshclam/freshclam.c b/freshclam/freshclam.c index 17c7c94a77..4ae0481254 100644 --- a/freshclam/freshclam.c +++ b/freshclam/freshclam.c @@ -22,8 +22,6 @@ #include "clamav-config.h" #endif -#include "libfreshclam/libfreshclam.h" - #include #include #ifdef HAVE_UNISTD_H @@ -51,15 +49,19 @@ #endif #include "target.h" + +// libclamav #include "clamav.h" -#include "libfreshclam/libfreshclam.h" +#include "others.h" +#include "str.h" -#include "libclamav/others.h" -#include "libclamav/str.h" +// shared +#include "optparser.h" +#include "output.h" +#include "misc.h" -#include "shared/optparser.h" -#include "shared/output.h" -#include "shared/misc.h" +// libfreshclam +#include "libfreshclam.h" #include "execute.h" #include "notify.h" @@ -214,7 +216,7 @@ fc_error_t download_complete_callback(const char *dbFilename, void *context) fc_error_t ret; fc_ctx *fc_context = (fc_ctx *)context; -#ifndef WIN32 +#ifndef _WIN32 char firstline[256]; char lastline[256]; int pipefd[2]; @@ -235,7 +237,7 @@ fc_error_t download_complete_callback(const char *dbFilename, void *context) logg("Testing database: '%s' ...\n", dbFilename); if (fc_context->bTestDatabases) { -#ifdef WIN32 +#ifdef _WIN32 __try { ret = fc_test_database(dbFilename, fc_context->bBytecodeEnabled); diff --git a/freshclam/notify.c b/freshclam/notify.c index 8dbc3cd7e2..b3c970fe1c 100644 --- a/freshclam/notify.c +++ b/freshclam/notify.c @@ -38,9 +38,9 @@ #include #include -#include "shared/optparser.h" -#include "shared/output.h" -#include "shared/clamdcom.h" +#include "optparser.h" +#include "output.h" +#include "clamdcom.h" #include "notify.h" diff --git a/fuzz/Makefile.am b/fuzz/Makefile.am index 00eb1b7488..16cb778e0c 100644 --- a/fuzz/Makefile.am +++ b/fuzz/Makefile.am @@ -14,7 +14,7 @@ LIB_FUZZING_ENGINE_DEPRECATED ?= libstandalone_fuzz_target_runner.a AM_CPPFLAGS = \ @SSL_CPPFLAGS@ \ - -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav \ + -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav -I$(top_builddir)/libclamav -I$(top_srcdir)/libclamunrar_iface \ -std=c++11 -stdlib=libc++ AM_LDFLAGS = \ diff --git a/libclamav/CMakeLists.txt b/libclamav/CMakeLists.txt new file mode 100644 index 0000000000..18cf8dcf93 --- /dev/null +++ b/libclamav/CMakeLists.txt @@ -0,0 +1,607 @@ +# Copyright (C) 2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved. + +cmake_minimum_required( VERSION 3.12...3.13 ) + +include_directories( + ${LIBXML2_INCLUDE_DIR} + ${OPENSSL_INCLUDE_DIR} + ${ZLIB_INCLUDE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + $ + ${CMAKE_CURRENT_SOURCE_DIR}/.. +) + +configure_file(version.h.in version.h) + +if(WIN32) + add_definitions(-DWIN32_LEAN_AND_MEAN) + add_definitions(-DHAVE_STRUCT_TIMESPEC) + + # Windows compatibility headers + include_directories(${CMAKE_SOURCE_DIR}/win32/compat) +endif() + +# 3rd party libraries included in libclamav +add_library( regex OBJECT ) +target_sources( regex + PRIVATE + regex/strlcpy.c + regex/regcomp.c + regex/regerror.c + regex/regexec.c + regex/regfree.c + PUBLIC + regex/cclass.h + regex/cname.h + regex/regex.h + regex/regex2.h + regex/utils.h ) +target_include_directories( regex + PRIVATE ${CMAKE_BINARY_DIR} + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) +set_target_properties(regex PROPERTIES + COMPILE_FLAGS "${WARNCFLAGS}") +target_link_libraries( regex + PRIVATE + JSONC::jsonc ) + +add_library( lzma_sdk OBJECT ) +target_sources( lzma_sdk + PRIVATE + 7z/7zAlloc.c + 7z/7zBuf.c + 7z/7zBuf2.c + 7z/7zCrc.c + 7z/7zCrcOpt.c + 7z/7zDec.c + 7z/7zFile.c + 7z/7zIn.c + 7z/7zStream.c + 7z/Bcj2.c + 7z/Bra.c + 7z/Bra86.c + 7z/BraIA64.c + 7z/CpuArch.c + 7z/Delta.c + 7z/Lzma2Dec.c + 7z/LzmaDec.c + 7z/Ppmd7.c + 7z/Ppmd7Dec.c + 7z/Xz.c + 7z/XzCrc64.c + 7z/XzDec.c + 7z/XzIn.c + PUBLIC + 7z/7z.h + 7z/Xz.h + 7z/Alloc.h + 7z/7zFile.h + 7z/XzCrc64.h + 7z/RotateDefs.h + 7z/Types.h + 7z/Ppmd7.h + 7z/LzmaDec.h + 7z/Ppmd.h + 7z/Lzma2Dec.h + 7z/Delta.h + 7z/CpuArch.h + 7z/CpuArch.h + 7z/Bra.h + 7z/Bcj2.h + 7z/7zVersion.h + 7z/7zCrc.h + 7z/7zBuf.h + 7z/7zAlloc.h ) +target_include_directories( lzma_sdk + PRIVATE ${CMAKE_BINARY_DIR} + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) +set_target_properties(lzma_sdk PROPERTIES + COMPILE_FLAGS "${WARNCFLAGS}") +target_link_libraries( lzma_sdk + PRIVATE + JSONC::jsonc ) + +bison_target( yara_grammar + yara_grammar.y ${CMAKE_CURRENT_BINARY_DIR}/yara_grammar.c ) +flex_target( yara_lexer + yara_lexer.l ${CMAKE_CURRENT_BINARY_DIR}/yara_lexer.c ) +add_flex_bison_dependency(yara_lexer yara_grammar) + +add_library( yara OBJECT ) +target_sources( yara + PRIVATE + yara_compiler.c + yara_exec.c + yara_hash.c + yara_parser.c + yara_arena.c + ${BISON_yara_grammar_OUTPUTS} + ${FLEX_yara_lexer_OUTPUTS} + PUBLIC + yara_arena.h + yara_compiler.h + yara_clam.h + yara_hash.h + yara_exec.h + yara_parser.h ) +target_include_directories( yara + PRIVATE + ${CMAKE_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} ) +set_target_properties(yara PROPERTIES + COMPILE_FLAGS "${WARNCFLAGS}") +target_link_libraries( yara + PRIVATE + JSONC::jsonc ) + +add_library( tomsfastmath OBJECT ) +target_sources( tomsfastmath + PRIVATE + tomsfastmath/addsub/fp_add.c + tomsfastmath/addsub/fp_add_d.c + tomsfastmath/addsub/fp_addmod.c + tomsfastmath/addsub/fp_cmp.c + tomsfastmath/addsub/fp_cmp_d.c + tomsfastmath/addsub/fp_cmp_mag.c + tomsfastmath/addsub/fp_sub.c + tomsfastmath/addsub/fp_sub_d.c + tomsfastmath/addsub/fp_submod.c + tomsfastmath/addsub/s_fp_add.c + tomsfastmath/addsub/s_fp_sub.c + tomsfastmath/bin/fp_radix_size.c + tomsfastmath/bin/fp_read_radix.c + tomsfastmath/bin/fp_read_signed_bin.c + tomsfastmath/bin/fp_read_unsigned_bin.c + tomsfastmath/bin/fp_reverse.c + tomsfastmath/bin/fp_s_rmap.c + tomsfastmath/bin/fp_signed_bin_size.c + tomsfastmath/bin/fp_to_signed_bin.c + tomsfastmath/bin/fp_to_unsigned_bin.c + tomsfastmath/bin/fp_toradix.c + tomsfastmath/bin/fp_toradix_n.c + tomsfastmath/bin/fp_unsigned_bin_size.c + tomsfastmath/bit/fp_cnt_lsb.c + tomsfastmath/bit/fp_count_bits.c + tomsfastmath/bit/fp_div_2.c + tomsfastmath/bit/fp_div_2d.c + tomsfastmath/bit/fp_lshd.c + tomsfastmath/bit/fp_mod_2d.c + tomsfastmath/bit/fp_rshd.c + tomsfastmath/divide/fp_div.c + tomsfastmath/divide/fp_div_d.c + tomsfastmath/divide/fp_mod.c + tomsfastmath/divide/fp_mod_d.c + tomsfastmath/exptmod/fp_2expt.c + tomsfastmath/exptmod/fp_exptmod.c + tomsfastmath/misc/fp_ident.c + tomsfastmath/misc/fp_set.c + tomsfastmath/mont/fp_montgomery_calc_normalization.c + tomsfastmath/mont/fp_montgomery_reduce.c + tomsfastmath/mont/fp_montgomery_setup.c + tomsfastmath/mul/fp_mul.c + tomsfastmath/mul/fp_mul_comba.c + tomsfastmath/mul/fp_mul_2.c + tomsfastmath/mul/fp_mul_2d.c + tomsfastmath/mul/fp_mul_comba_12.c + tomsfastmath/mul/fp_mul_comba_17.c + tomsfastmath/mul/fp_mul_comba_20.c + tomsfastmath/mul/fp_mul_comba_24.c + tomsfastmath/mul/fp_mul_comba_28.c + tomsfastmath/mul/fp_mul_comba_3.c + tomsfastmath/mul/fp_mul_comba_32.c + tomsfastmath/mul/fp_mul_comba_4.c + tomsfastmath/mul/fp_mul_comba_48.c + tomsfastmath/mul/fp_mul_comba_6.c + tomsfastmath/mul/fp_mul_comba_64.c + tomsfastmath/mul/fp_mul_comba_7.c + tomsfastmath/mul/fp_mul_comba_8.c + tomsfastmath/mul/fp_mul_comba_9.c + tomsfastmath/mul/fp_mul_comba_small_set.c + tomsfastmath/mul/fp_mul_d.c + tomsfastmath/mul/fp_mulmod.c + tomsfastmath/numtheory/fp_invmod.c + tomsfastmath/sqr/fp_sqr.c + tomsfastmath/sqr/fp_sqr_comba_12.c + tomsfastmath/sqr/fp_sqr_comba_17.c + tomsfastmath/sqr/fp_sqr_comba_20.c + tomsfastmath/sqr/fp_sqr_comba_24.c + tomsfastmath/sqr/fp_sqr_comba_28.c + tomsfastmath/sqr/fp_sqr_comba_3.c + tomsfastmath/sqr/fp_sqr_comba_32.c + tomsfastmath/sqr/fp_sqr_comba_4.c + tomsfastmath/sqr/fp_sqr_comba_48.c + tomsfastmath/sqr/fp_sqr_comba_6.c + tomsfastmath/sqr/fp_sqr_comba_64.c + tomsfastmath/sqr/fp_sqr_comba_7.c + tomsfastmath/sqr/fp_sqr_comba_8.c + tomsfastmath/sqr/fp_sqr_comba_9.c + tomsfastmath/sqr/fp_sqr_comba_generic.c + tomsfastmath/sqr/fp_sqr_comba_small_set.c + tomsfastmath/sqr/fp_sqrmod.c + PUBLIC + bignum.h + bignum_fast.h ) +target_include_directories( tomsfastmath + PRIVATE ${CMAKE_BINARY_DIR} + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) +set_target_properties(tomsfastmath PROPERTIES + COMPILE_FLAGS "${WARNCFLAGS}") + +# clamav clamav_obj +add_library( clamav_obj OBJECT ) +target_sources( clamav_obj + PRIVATE + # Utils + blob.c blob.h + conv.c conv.h + fpu.c fpu.h + hashtab.c hashtab.h + iowrap.c iowrap.h + json_api.c json_api.h + jsparse/textbuf.h + others_common.c others.h + qsort.c + sf_base64decode.c sf_base64decode.h + str.c str.h + strlcat.c + table.c table.h + text.c text.h + uniq.c uniq.h + www.c www.h + # Utils Disasm + disasm-common.h disasm.c disasm.h disasmpriv.h + # Matcher + filtering.c filtering.h + matcher-ac.c matcher-ac.h + matcher-bm.c matcher-bm.h + matcher-byte-comp.c matcher-byte-comp.h + matcher-hash.c matcher-hash.h + matcher-pcre.c matcher-pcre.h + matcher.c matcher.h + regex_pcre.c regex_pcre.h + # Database + cvd.c cvd.h + dconf.c dconf.h + dsig.c dsig.h + readdb.c readdb.h + # Core + cache.c cache.h + crtmgr.c crtmgr.h + crypto.c + default.h + filetypes_int.h filetypes.c filetypes.h + fmap.c fmap.h + mpool.c mpool.h + others.c + perflogging.c perflogging.h + scanners.c scanners.h + textdet.c textdet.h + version.c + # file normalization (for matching) + htmlnorm.c htmlnorm.h + jsparse/generated/keywords.h + jsparse/generated/operators.h + jsparse/js-norm.c + jsparse/js-norm.h + jsparse/lexglobal.h + textnorm.c textnorm.h + # heuristics (hardcoded exploit/malware detection) + partition_intersection.c partition_intersection.h + special.c special.h + # clamav statistics + hostid_internal.c hostid_internal.h + stats_json.c stats_json.h + stats.c stats.h + # clamav bytecode support + bcfeatures.h + builtin_bytecodes.h + bytecode_api_decl.c + bytecode_api_impl.h + bytecode_api.c bytecode_api.h + bytecode_detect.c bytecode_detect.h + bytecode_hooks.h + bytecode_priv.h + bytecode_vm.c + bytecode.c bytecode.h + events.c events.h + type_desc.h + # utils: compression + 7z_iface.c 7z_iface.h + explode.c explode.h + inffixed64.h + inflate64_priv.h inflate64.c inflate64.h + lzma_iface.c lzma_iface.h + lzw/lzwdec.c lzw/lzwdec.h + xz_iface.c xz_iface.h + # utils: encryption + arc4.c arc4.h + rijndael.c rijndael.h + # utils: text conversion + encoding_aliases.h + entconv.c entconv.h + entitylist.h + # Data-Loss-Prevention + dlp.c dlp.h + # + # FILE PARSERS + # + # autoit + autoit.c autoit.h + # binhex + binhex.c binhex.h + # cpio + cpio.c cpio.h + # install shield + ishield.c ishield.h + # cab / chm + libmspack.c libmspack.h + # msszdd + msexpand.c msexpand.h + # nsis + nsis/bzlib_private.h + nsis/bzlib.c + nsis/infblock.c + nsis/nsis_bzlib.h + nsis/nsis_zconf.h + nsis/nsis_zlib.h + nsis/nsis_zutil.h + nsis/nulsft.c nsis/nulsft.h + # office docs + hwp.c hwp.h + msdoc.c msdoc.h + msxml_parser.c msxml_parser.h + msxml.c msxml.h + ole2_extract.c ole2_extract.h + xlm_extract.c xlm_extract.h + ooxml.c ooxml.h + rtf.c rtf.h + vba_extract.c vba_extract.h + # executables + asn1.c asn1.h + elf.c elf.h + execs.c execs.h + macho.c macho.h + pe_icons.c pe_icons.h + pe_structs.h + pe.c pe.h + rebuildpe.c rebuildpe.h + # executable unpackers + aspack.c aspack.h + fsg.c fsg.h + mew.c mew.h + packlibs.c packlibs.h + petite.c petite.h + spin.c spin.h + unsp.c unsp.h + upack.c upack.h + upx.c upx.h + wwunpack.c wwunpack.h + yc.c yc.h + # mail & phishing + iana_cctld.h + iana_tld.h + line.c line.h + mbox.c mbox.h + message.c message.h + phish_domaincheck_db.c phish_domaincheck_db.h + phish_whitelist.c phish_whitelist.h + phishcheck.c phishcheck.h + regex_list.c regex_list.h + regex_suffix.c regex_suffix.h + # sis + sis.c sis.h + # tnef + tnef.c tnef.h + # uuencode + uuencode.c uuencode.h + # swf (flash) + swf.c swf.h + # pdf + pdf.c pdf.h + pdfng.c + pdfdecode.c pdfdecode.h + # xdp + xdp.c xdp.h + # ARJ archive + unarj.c unarj.h + # TAR archive + is_tar.c is_tar.h + untar.c untar.h + # ZIP archive + unzip.c unzip.h + # DMG archive + adc.c adc.h + dmg.c dmg.h + # XAR archive + xar.c xar.h + # EGG archive + egg.c egg.h + # Master Boot Record partition + mbr.c mbr.h + # GUID Parition Table partition + gpt.c gpt.h + # Apple Partition Map partition + apm.c apm.h + # HFS+ partition + hfsplus.c hfsplus.h + # iso9660 partition + iso9660.c iso9660.h + # OpenIOC + openioc.c openioc.h + # JPEG image format checker + jpeg.c jpeg.h + # PNG image format checker + png.c png.h + # TIFF image format checker + tiff.c tiff.h + # GIF image format checker + gif.c gif.h + PUBLIC + clamav.h ) + +if(WIN32) + target_sources( clamav_obj PRIVATE libclamav_main.c ) +endif() + +# Bytecode Runtime +add_library( bytecode_runtime OBJECT ) +if(LLVM_FOUND) + target_sources( bytecode_runtime + PRIVATE + c++/detect.cpp + c++/ClamBCRTChecks.cpp + c++/bytecode2llvm.cpp + bytecode_priv.h + bytecode.h ) + set_target_properties(bytecode_runtime PROPERTIES + COMPILE_FLAGS "${WARNCXXFLAGS} ${CXX1XCXXFLAGS}") +else() + target_sources( bytecode_runtime + PRIVATE + bytecode_nojit.c + bytecode_priv.h + bytecode.h ) + set_target_properties(bytecode_runtime PROPERTIES + COMPILE_FLAGS "${WARNCFLAGS}") +endif() +target_include_directories( bytecode_runtime + PRIVATE ${CMAKE_BINARY_DIR} + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) +target_link_libraries( bytecode_runtime + PRIVATE + JSONC::jsonc ) + +target_include_directories( clamav_obj + PRIVATE ${CMAKE_BINARY_DIR} ${JSONC_INCLUDE_DIRS} + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + INTERFACE ${CMAKE_BINARY_DIR} ) +target_link_libraries( clamav_obj + PUBLIC + regex + lzma_sdk + yara + tomsfastmath + bytecode_runtime + ClamAV::libmspack + ClamAV::libclamunrar_iface_iface + OpenSSL::SSL + OpenSSL::Crypto + ZLIB::ZLIB + BZip2::BZip2 + PCRE2::pcre2 + LibXml2::LibXml2 + JSONC::jsonc ) +if (WIN32) + target_link_libraries( clamav_obj + PUBLIC + PThreadW32::pthreadw32 + ClamAV::win32_compat + wsock32 ws2_32 ) +else() + target_link_libraries( clamav_obj + PUBLIC + Threads::Threads + Iconv::Iconv + ${CMAKE_DL_LIBS} + m ) +endif() +set_target_properties(clamav_obj PROPERTIES + COMPILE_FLAGS "${WARNCFLAGS}") + +if(ENABLE_SHARED_LIB) + # The clamav shared library. + add_library( clamav SHARED ) + set_target_properties(clamav PROPERTIES + VERSION ${LIBCLAMAV_VERSION} + SOVERSION ${LIBCLAMAV_SOVERSION}) + target_sources( clamav + PUBLIC + clamav.h ) + target_link_libraries( clamav + PUBLIC + clamav_obj + regex + lzma_sdk + yara + tomsfastmath + bytecode_runtime + ClamAV::libmspack + ClamAV::libclamunrar_iface_iface + OpenSSL::SSL + OpenSSL::Crypto + ZLIB::ZLIB + BZip2::BZip2 + PCRE2::pcre2 + LibXml2::LibXml2 + JSONC::jsonc ) + set_target_properties(clamav PROPERTIES + COMPILE_FLAGS "${WARNCFLAGS}" + VERSION ${LIBCLAMAV_VERSION} SOVERSION ${LIBCLAMAV_SOVERSION}) + if(WIN32) + set_target_properties(clamav PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) + else() + target_link_libraries( clamav PUBLIC Iconv::Iconv ) + endif() + if(WIN32) + install(TARGETS clamav DESTINATION ${CMAKE_INSTALL_PREFIX}) + else() + install(TARGETS clamav DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() + + if(LLVM_FOUND) + target_link_directories( clamav PRIVATE ${LLVM_LIBRARY_DIRS} ) + target_link_libraries( clamav PRIVATE ${LLVM_LIBRARIES} ) + endif() + + add_library( ClamAV::libclamav ALIAS clamav ) +endif() + +if(ENABLE_STATIC_LIB) + # The clamav static library. + add_library(clamav_static STATIC) + target_sources(clamav_static + PUBLIC + clamav.h ) + target_link_libraries(clamav_static + PUBLIC + clamav_obj + regex + lzma_sdk + yara + tomsfastmath + bytecode_runtime + ClamAV::libmspack + ClamAV::libclamunrar_iface_iface + OpenSSL::SSL + OpenSSL::Crypto + ZLIB::ZLIB + BZip2::BZip2 + PCRE2::pcre2 + LibXml2::LibXml2 + JSONC::jsonc ) + if(NOT WIN32) + target_link_libraries( clamav PUBLIC Iconv::Iconv ) + endif() + set_target_properties(clamav_static PROPERTIES + ARCHIVE_OUTPUT_NAME clamav_static + COMPILE_FLAGS "${WARNCFLAGS}" + VERSION ${LIBCLAMAV_VERSION} SOVERSION ${LIBCLAMAV_SOVERSION}) + target_compile_definitions(clamav_static PUBLIC clamav_staticLIB) + if(WIN32) + install(TARGETS clamav_static DESTINATION ${CMAKE_INSTALL_PREFIX}) + else() + install(TARGETS clamav_static DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() + + add_library( ClamAV::libclamav_static ALIAS clamav_static ) +endif() + +install( + FILES + clamav.h + ${CMAKE_BINARY_DIR}/clamav-types.h + ${CMAKE_BINARY_DIR}/clamav-version.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/libclamav/Makefile.am b/libclamav/Makefile.am index 0eaba3e5bd..ae655cfecc 100644 --- a/libclamav/Makefile.am +++ b/libclamav/Makefile.am @@ -19,6 +19,7 @@ # MA 02110-1301, USA. AM_YFLAGS = -d +AM_LFLAGS = -d AM_CPPFLAGS = -I$(top_srcdir) -I@srcdir@/nsis $(LTDLINCL) AM_CFLAGS=@WERR_CFLAGS@ lib_LTLIBRARIES = @@ -89,7 +90,7 @@ libclamunrar_la_SOURCES = \ lib_LTLIBRARIES += libclamunrar.la EXTRA_DIST += @top_srcdir@/libclamunrar/libclamunrar.map - +libclamunrar_iface_la_CXXFLAGS = $(AM_CPPFLAGS) -I@top_srcdir@/libclamunrar libclamunrar_iface_la_LIBADD = libclamunrar.la libclamunrar_iface_la_LDFLAGS = -module @TH_SAFE@ -version-info @LIBCLAMAV_VERSION@ -no-undefined @@ -108,72 +109,11 @@ IFACELIBADD = -dlopen libclamunrar_iface.la IFACEDEP = libclamunrar_iface.la endif -libclamav_internal_utils_la_SOURCES=str.c\ - str.h\ - conv.c \ - conv.h \ - crypto.c \ - clamav.h \ - iowrap.c \ - iowrap.h \ - others_common.c \ - others.h \ - qsort.c \ - regex/strlcpy.c \ - regex/regcomp.c \ - regex/regerror.c \ - regex/regexec.c \ - regex/regfree.c \ - regex/cclass.h \ - regex/cname.h \ - regex/regex.h \ - regex/regex2.h \ - regex/utils.h \ - strlcat.c - -libclamav_internal_utils_la_LDFLAGS=-static @SSL_LDFLAGS@ @JSON_LDFLAGS@ -libclamav_internal_utils_la_CFLAGS=$(AM_CFLAGS) -fPIC -DPIC @SSL_CPPFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ @XML_CPPFLAGS@ -libclamav_internal_utils_la_LIBADD=@SSL_LIBS@ @PCRE_LIBS@ - -libclamav_internal_utils_nothreads_la_SOURCES=str.c\ - conv.c \ - conv.h \ - crypto.c \ - clamav.h \ - str.h\ - iowrap.c \ - iowrap.h \ - others_common.c \ - others.h \ - qsort.c \ - regex/strlcpy.c \ - regex/regcomp.c \ - regex/regerror.c \ - regex/regexec.c \ - regex/regfree.c \ - regex/cclass.h \ - regex/cname.h \ - regex/regex.h \ - regex/regex2.h \ - regex/utils.h \ - strlcat.c - -libclamav_internal_utils_nothreads_la_LDFLAGS=-static @SSL_LDFLAGS@ @JSON_LDFLAGS@ -libclamav_internal_utils_nothreads_la_CFLAGS=$(AM_CFLAGS) -DCL_NOTHREADS @SSL_CPPFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ -libclamav_internal_utils_nothreads_la_LIBADD=@SSL_LIBS@ @PCRE_LIBS@ -SUBDIRS= - -if ENABLE_LLVM -LLVMLIBADD=c++/libclamavcxx.la -lstdc++ -lm -LLVMDEP=c++/libclamavcxx.la -SUBDIRS+=c++ -else -LLVMLIBADD=libclamav_nocxx.la -LLVMDEP=libclamav_nocxx.la -c++/Makefile: c++/Makefile.nollvm.in - $(AM_V_at) cp $< $@ -distclean-recursive distdir maintainer-clean-recursive: c++/Makefile -endif +# We need libclamunrar_iface in the include path even if we don't build it, +# because we #include "unrar_iface.h" +# We still want to support unrar if it is later provided, which is why we don't +# just wrap all the unrar scanners code with #ifdefs. +IFACE_CFLAGS = -I@top_srcdir@/libclamunrar_iface if USE_INTERNAL_MSPACK # libmspack version: 0.8alpha (1:0:1) @@ -254,16 +194,57 @@ maintainer-clean: distclean-recursive distdir maintainer-clean-recursive: libmspack/Makefile endif +libclamav_internal_utils_la_SOURCES= \ + conv.c \ + conv.h \ + crypto.c \ + iowrap.c \ + iowrap.h \ + others_common.c \ + others.h \ + qsort.c \ + regex/cclass.h \ + regex/cname.h \ + regex/regcomp.c \ + regex/regerror.c \ + regex/regex.h \ + regex/regex2.h \ + regex/regexec.c \ + regex/regfree.c \ + regex/strlcpy.c \ + regex/utils.h \ + str.c \ + str.h \ + strlcat.c + +libclamav_internal_utils_la_LDFLAGS=-static @SSL_LDFLAGS@ @JSON_LDFLAGS@ +libclamav_internal_utils_la_CFLAGS=$(AM_CFLAGS) $(IFACE_CFLAGS) -fPIC -DPIC @SSL_CPPFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ @XML_CPPFLAGS@ +libclamav_internal_utils_la_LIBADD=@SSL_LIBS@ @PCRE_LIBS@ + +SUBDIRS= + +if ENABLE_LLVM +LLVMLIBADD=c++/libclamavcxx.la -lstdc++ -lm +LLVMDEP=c++/libclamavcxx.la +SUBDIRS+=c++ +else +LLVMLIBADD=libclamav_nocxx.la +LLVMDEP=libclamav_nocxx.la +c++/Makefile: c++/Makefile.nollvm.in + $(AM_V_at) cp $< $@ +distclean-recursive distdir maintainer-clean-recursive: c++/Makefile +endif + if ENABLE_YARA YARA_CFLAGS=-DHAVE_YARA endif libclamav_nocxx_la_SOURCES = bytecode_nojit.c -libclamav_nocxx_la_CFLAGS=$(AM_CFLAGS) @SSL_CPPFLAGS@ @JSON_CPPFLAGS@ @ZLIB_CFLAGS@ @PCRE_CPPFLAGS@ +libclamav_nocxx_la_CFLAGS=$(AM_CFLAGS) $(IFACE_CFLAGS) @SSL_CPPFLAGS@ @JSON_CPPFLAGS@ @ZLIB_CFLAGS@ @PCRE_CPPFLAGS@ libclamav_la_LIBADD = @SSL_LIBS@ @JSON_LIBS@ @PCRE_LIBS@ @LIBCLAMAV_LIBS@ @ZLIB_LIBS@ @LIBLTDL@ $(XML_LIBS) $(IFACELIBADD) $(MSPACKLIBADD) $(LLVMLIBADD) libclamav_internal_utils.la @THREAD_LIBS@ @LIBM@ libclamav_la_DEPENDENCIES = @LTDLDEPS@ $(IFACEDEP) $(LLVMDEP) $(MSPACKDEP) libclamav_internal_utils.la -libclamav_la_CFLAGS = $(MSPACK_CFLAGS) $(AM_CFLAGS) $(YARA_CFLAGS) -DSEARCH_LIBDIR=\"$(libdir)\" @LIBCLAMAV_CPPFLAGS@ @SSL_CPPFLAGS@ @JSON_CPPFLAGS@ @ZLIB_CFLAGS@ @PCRE_CPPFLAGS@ @XML_CPPFLAGS@ +libclamav_la_CFLAGS = $(IFACE_CFLAGS) $(MSPACK_CFLAGS) $(AM_CFLAGS) $(YARA_CFLAGS) -DSEARCH_LIBDIR=\"$(libdir)\" @LIBCLAMAV_CPPFLAGS@ @SSL_CPPFLAGS@ @JSON_CPPFLAGS@ @ZLIB_CFLAGS@ @PCRE_CPPFLAGS@ @XML_CPPFLAGS@ libclamav_la_LDFLAGS = @SSL_LDFLAGS@ @TH_SAFE@ @JSON_LDFLAGS@ @LIBICONV@ $(XML_LIBS) -version-info @LIBCLAMAV_VERSION@ -no-undefined if VERSIONSCRIPT @@ -528,8 +509,8 @@ libclamav_la_SOURCES = \ gpt.h \ apm.c \ apm.h \ - prtn_intxn.c \ - prtn_intxn.h \ + partition_intersection.c \ + partition_intersection.h \ json_api.c\ json_api.h\ xz_iface.c \ @@ -564,8 +545,8 @@ libclamav_la_SOURCES = \ www.h \ stats_json.c \ stats_json.h \ - hostid.c \ - hostid.h \ + hostid_internal.c \ + hostid_internal.h \ openioc.c \ openioc.h \ msdoc.c \ @@ -587,7 +568,8 @@ libclamav_la_SOURCES = \ matcher-byte-comp.c \ matcher-byte-comp.h \ egg.c \ - egg.h + egg.h \ + queue.h if ENABLE_YARA libclamav_la_SOURCES += yara_arena.c \ @@ -608,86 +590,86 @@ endif libclamav_la_SOURCES += bignum.h\ bignum_fast.h\ - tomsfastmath/addsub/fp_add.c\ - tomsfastmath/addsub/fp_add_d.c\ - tomsfastmath/addsub/fp_addmod.c\ - tomsfastmath/addsub/fp_cmp.c\ - tomsfastmath/addsub/fp_cmp_d.c\ - tomsfastmath/addsub/fp_cmp_mag.c\ - tomsfastmath/addsub/fp_sub.c\ - tomsfastmath/addsub/fp_sub_d.c\ - tomsfastmath/addsub/fp_submod.c\ - tomsfastmath/addsub/s_fp_add.c\ - tomsfastmath/addsub/s_fp_sub.c\ - tomsfastmath/bin/fp_radix_size.c\ - tomsfastmath/bin/fp_read_radix.c\ - tomsfastmath/bin/fp_read_signed_bin.c\ - tomsfastmath/bin/fp_read_unsigned_bin.c\ - tomsfastmath/bin/fp_reverse.c\ - tomsfastmath/bin/fp_s_rmap.c\ - tomsfastmath/bin/fp_signed_bin_size.c\ - tomsfastmath/bin/fp_to_signed_bin.c\ - tomsfastmath/bin/fp_to_unsigned_bin.c\ - tomsfastmath/bin/fp_toradix.c\ - tomsfastmath/bin/fp_toradix_n.c\ - tomsfastmath/bin/fp_unsigned_bin_size.c\ - tomsfastmath/bit/fp_cnt_lsb.c\ - tomsfastmath/bit/fp_count_bits.c\ - tomsfastmath/bit/fp_div_2.c\ - tomsfastmath/bit/fp_div_2d.c\ - tomsfastmath/bit/fp_lshd.c\ - tomsfastmath/bit/fp_mod_2d.c\ - tomsfastmath/bit/fp_rshd.c\ - tomsfastmath/divide/fp_div.c\ - tomsfastmath/divide/fp_div_d.c\ - tomsfastmath/divide/fp_mod.c\ - tomsfastmath/divide/fp_mod_d.c\ - tomsfastmath/exptmod/fp_2expt.c\ - tomsfastmath/exptmod/fp_exptmod.c\ - tomsfastmath/misc/fp_ident.c\ - tomsfastmath/misc/fp_set.c\ - tomsfastmath/mont/fp_montgomery_calc_normalization.c\ - tomsfastmath/mont/fp_montgomery_reduce.c\ - tomsfastmath/mont/fp_montgomery_setup.c\ - tomsfastmath/mul/fp_mul.c\ - tomsfastmath/mul/fp_mul_comba.c\ - tomsfastmath/mul/fp_mul_2.c\ - tomsfastmath/mul/fp_mul_2d.c\ - tomsfastmath/mul/fp_mul_comba_12.c\ - tomsfastmath/mul/fp_mul_comba_17.c\ - tomsfastmath/mul/fp_mul_comba_20.c\ - tomsfastmath/mul/fp_mul_comba_24.c\ - tomsfastmath/mul/fp_mul_comba_28.c\ - tomsfastmath/mul/fp_mul_comba_3.c\ - tomsfastmath/mul/fp_mul_comba_32.c\ - tomsfastmath/mul/fp_mul_comba_4.c\ - tomsfastmath/mul/fp_mul_comba_48.c\ - tomsfastmath/mul/fp_mul_comba_6.c\ - tomsfastmath/mul/fp_mul_comba_64.c\ - tomsfastmath/mul/fp_mul_comba_7.c\ - tomsfastmath/mul/fp_mul_comba_8.c\ - tomsfastmath/mul/fp_mul_comba_9.c\ - tomsfastmath/mul/fp_mul_comba_small_set.c\ - tomsfastmath/mul/fp_mul_d.c\ - tomsfastmath/mul/fp_mulmod.c\ - tomsfastmath/numtheory/fp_invmod.c\ - tomsfastmath/sqr/fp_sqr.c\ - tomsfastmath/sqr/fp_sqr_comba_12.c\ - tomsfastmath/sqr/fp_sqr_comba_17.c\ - tomsfastmath/sqr/fp_sqr_comba_20.c\ - tomsfastmath/sqr/fp_sqr_comba_24.c\ - tomsfastmath/sqr/fp_sqr_comba_28.c\ - tomsfastmath/sqr/fp_sqr_comba_3.c\ - tomsfastmath/sqr/fp_sqr_comba_32.c\ - tomsfastmath/sqr/fp_sqr_comba_4.c\ - tomsfastmath/sqr/fp_sqr_comba_48.c\ - tomsfastmath/sqr/fp_sqr_comba_6.c\ - tomsfastmath/sqr/fp_sqr_comba_64.c\ - tomsfastmath/sqr/fp_sqr_comba_7.c\ - tomsfastmath/sqr/fp_sqr_comba_8.c\ - tomsfastmath/sqr/fp_sqr_comba_9.c\ - tomsfastmath/sqr/fp_sqr_comba_generic.c\ - tomsfastmath/sqr/fp_sqr_comba_small_set.c\ + tomsfastmath/addsub/fp_add.c\ + tomsfastmath/addsub/fp_add_d.c\ + tomsfastmath/addsub/fp_addmod.c\ + tomsfastmath/addsub/fp_cmp.c\ + tomsfastmath/addsub/fp_cmp_d.c\ + tomsfastmath/addsub/fp_cmp_mag.c\ + tomsfastmath/addsub/fp_sub.c\ + tomsfastmath/addsub/fp_sub_d.c\ + tomsfastmath/addsub/fp_submod.c\ + tomsfastmath/addsub/s_fp_add.c\ + tomsfastmath/addsub/s_fp_sub.c\ + tomsfastmath/bin/fp_radix_size.c\ + tomsfastmath/bin/fp_read_radix.c\ + tomsfastmath/bin/fp_read_signed_bin.c\ + tomsfastmath/bin/fp_read_unsigned_bin.c\ + tomsfastmath/bin/fp_reverse.c\ + tomsfastmath/bin/fp_s_rmap.c\ + tomsfastmath/bin/fp_signed_bin_size.c\ + tomsfastmath/bin/fp_to_signed_bin.c\ + tomsfastmath/bin/fp_to_unsigned_bin.c\ + tomsfastmath/bin/fp_toradix.c\ + tomsfastmath/bin/fp_toradix_n.c\ + tomsfastmath/bin/fp_unsigned_bin_size.c\ + tomsfastmath/bit/fp_cnt_lsb.c\ + tomsfastmath/bit/fp_count_bits.c\ + tomsfastmath/bit/fp_div_2.c\ + tomsfastmath/bit/fp_div_2d.c\ + tomsfastmath/bit/fp_lshd.c\ + tomsfastmath/bit/fp_mod_2d.c\ + tomsfastmath/bit/fp_rshd.c\ + tomsfastmath/divide/fp_div.c\ + tomsfastmath/divide/fp_div_d.c\ + tomsfastmath/divide/fp_mod.c\ + tomsfastmath/divide/fp_mod_d.c\ + tomsfastmath/exptmod/fp_2expt.c\ + tomsfastmath/exptmod/fp_exptmod.c\ + tomsfastmath/misc/fp_ident.c\ + tomsfastmath/misc/fp_set.c\ + tomsfastmath/mont/fp_montgomery_calc_normalization.c\ + tomsfastmath/mont/fp_montgomery_reduce.c\ + tomsfastmath/mont/fp_montgomery_setup.c\ + tomsfastmath/mul/fp_mul.c\ + tomsfastmath/mul/fp_mul_comba.c\ + tomsfastmath/mul/fp_mul_2.c\ + tomsfastmath/mul/fp_mul_2d.c\ + tomsfastmath/mul/fp_mul_comba_12.c\ + tomsfastmath/mul/fp_mul_comba_17.c\ + tomsfastmath/mul/fp_mul_comba_20.c\ + tomsfastmath/mul/fp_mul_comba_24.c\ + tomsfastmath/mul/fp_mul_comba_28.c\ + tomsfastmath/mul/fp_mul_comba_3.c\ + tomsfastmath/mul/fp_mul_comba_32.c\ + tomsfastmath/mul/fp_mul_comba_4.c\ + tomsfastmath/mul/fp_mul_comba_48.c\ + tomsfastmath/mul/fp_mul_comba_6.c\ + tomsfastmath/mul/fp_mul_comba_64.c\ + tomsfastmath/mul/fp_mul_comba_7.c\ + tomsfastmath/mul/fp_mul_comba_8.c\ + tomsfastmath/mul/fp_mul_comba_9.c\ + tomsfastmath/mul/fp_mul_comba_small_set.c\ + tomsfastmath/mul/fp_mul_d.c\ + tomsfastmath/mul/fp_mulmod.c\ + tomsfastmath/numtheory/fp_invmod.c\ + tomsfastmath/sqr/fp_sqr.c\ + tomsfastmath/sqr/fp_sqr_comba_12.c\ + tomsfastmath/sqr/fp_sqr_comba_17.c\ + tomsfastmath/sqr/fp_sqr_comba_20.c\ + tomsfastmath/sqr/fp_sqr_comba_24.c\ + tomsfastmath/sqr/fp_sqr_comba_28.c\ + tomsfastmath/sqr/fp_sqr_comba_3.c\ + tomsfastmath/sqr/fp_sqr_comba_32.c\ + tomsfastmath/sqr/fp_sqr_comba_4.c\ + tomsfastmath/sqr/fp_sqr_comba_48.c\ + tomsfastmath/sqr/fp_sqr_comba_6.c\ + tomsfastmath/sqr/fp_sqr_comba_64.c\ + tomsfastmath/sqr/fp_sqr_comba_7.c\ + tomsfastmath/sqr/fp_sqr_comba_8.c\ + tomsfastmath/sqr/fp_sqr_comba_9.c\ + tomsfastmath/sqr/fp_sqr_comba_generic.c\ + tomsfastmath/sqr/fp_sqr_comba_small_set.c\ tomsfastmath/sqr/fp_sqrmod.c .PHONY2: version.h.tmp @@ -713,13 +695,16 @@ version.h.tmp: fi lib_LTLIBRARIES += libclamav.la -noinst_LTLIBRARIES = libclamav_internal_utils.la libclamav_internal_utils_nothreads.la libclamav_nocxx.la -EXTRA_DIST += regex/engine.c tomsfastmath/sqr/fp_sqr_comba.c tomsfastmath/mul/fp_mul_comba.c libclamav.map \ +noinst_LTLIBRARIES = libclamav_internal_utils.la libclamav_nocxx.la +EXTRA_DIST += regex/engine.c tomsfastmath/sqr/fp_sqr_comba.c tomsfastmath/mul/fp_mul_comba.c libclamav.map libclamav_main.c \ jsparse/generated/operators.h jsparse/generated/keywords.h jsparse/future_reserved_words.list\ - jsparse/keywords.list jsparse/special_keywords.list jsparse/operators.gperf + jsparse/keywords.list jsparse/special_keywords.list jsparse/operators.gperf version.h.in COMMON_CLEANFILES+=version.h version.h.tmp *.gcda *.gcno + +BUILT_SOURCES = yara_grammar.h + if MAINTAINER_MODE -BUILT_SOURCES=jsparse/generated/operators.h jsparse/generated/keywords.h jsparse-keywords.gperf +BUILT_SOURCES += jsparse/generated/operators.h jsparse/generated/keywords.h jsparse-keywords.gperf GPERF_FLAGS=-E -t -L ANSI-C -C -F ', TOK_ERROR' -c diff --git a/libclamav/apm.c b/libclamav/apm.c index 1645b55726..e3499e8a8b 100644 --- a/libclamav/apm.c +++ b/libclamav/apm.c @@ -33,7 +33,7 @@ #include "clamav-types.h" #include "others.h" #include "apm.h" -#include "prtn_intxn.h" +#include "partition_intersection.h" #include "scanners.h" #include "dconf.h" @@ -45,7 +45,7 @@ #define apm_parsemsg(...) ; #endif -static int apm_prtn_intxn(cli_ctx *ctx, struct apm_partition_info *aptable, size_t sectorsize, int old_school); +static int apm_partition_intersection(cli_ctx *ctx, struct apm_partition_info *aptable, size_t sectorsize, int old_school); int cli_scanapm(cli_ctx *ctx) { @@ -134,7 +134,7 @@ int cli_scanapm(cli_ctx *ctx) /* check that the partition table fits in the space specified - HEURISTICS */ if (SCAN_HEURISTIC_PARTITION_INTXN && (ctx->dconf->other & OTHER_CONF_PRTNINTXN)) { - ret = apm_prtn_intxn(ctx, &aptable, sectorsize, old_school); + ret = apm_partition_intersection(ctx, &aptable, sectorsize, old_school); if (ret != CL_CLEAN) { if (SCAN_ALLMATCHES && (ret == CL_VIRUS)) detection = CL_VIRUS; @@ -239,9 +239,9 @@ int cli_scanapm(cli_ctx *ctx) return detection; } -static int apm_prtn_intxn(cli_ctx *ctx, struct apm_partition_info *aptable, size_t sectorsize, int old_school) +static int apm_partition_intersection(cli_ctx *ctx, struct apm_partition_info *aptable, size_t sectorsize, int old_school) { - prtn_intxn_list_t prtncheck; + partition_intersection_list_t prtncheck; struct apm_partition_info apentry; unsigned i, pitxn; int ret = CL_CLEAN, tmp = CL_CLEAN; @@ -249,7 +249,7 @@ static int apm_prtn_intxn(cli_ctx *ctx, struct apm_partition_info *aptable, size uint32_t max_prtns = 0; int virus_found = 0; - prtn_intxn_list_init(&prtncheck); + partition_intersection_list_init(&prtncheck); /* check engine maxpartitions limit */ if (aptable->numPartitions < ctx->engine->maxpartitions) { @@ -263,7 +263,7 @@ static int apm_prtn_intxn(cli_ctx *ctx, struct apm_partition_info *aptable, size pos = i * sectorsize; if (fmap_readn(*ctx->fmap, &apentry, pos, sizeof(apentry)) != sizeof(apentry)) { cli_dbgmsg("cli_scanapm: Invalid Apple partition entry\n"); - prtn_intxn_list_free(&prtncheck); + partition_intersection_list_free(&prtncheck); return CL_EFORMAT; } @@ -283,7 +283,7 @@ static int apm_prtn_intxn(cli_ctx *ctx, struct apm_partition_info *aptable, size } } - tmp = prtn_intxn_list_check(&prtncheck, &pitxn, apentry.pBlockStart, apentry.pBlockCount); + tmp = partition_intersection_list_check(&prtncheck, &pitxn, apentry.pBlockStart, apentry.pBlockCount); if (tmp != CL_CLEAN) { if (tmp == CL_VIRUS) { apm_parsemsg("Name: %s\n", (char *)aptable.name); @@ -308,7 +308,7 @@ static int apm_prtn_intxn(cli_ctx *ctx, struct apm_partition_info *aptable, size } leave: - prtn_intxn_list_free(&prtncheck); + partition_intersection_list_free(&prtncheck); if (virus_found) return CL_VIRUS; return ret; diff --git a/libclamav/bytecode.c b/libclamav/bytecode.c index 14da5ad495..034c05ecbe 100644 --- a/libclamav/bytecode.c +++ b/libclamav/bytecode.c @@ -29,6 +29,10 @@ #include #include +#if HAVE_JSON +#include "json.h" +#endif + #include "dconf.h" #include "clamav.h" #include "others.h" @@ -41,9 +45,6 @@ #include "bytecode_api.h" #include "bytecode_api_impl.h" #include "builtin_bytecodes.h" -#if HAVE_JSON -#include "json.h" -#endif #ifndef MAX_TRACKED_BC #define MAX_TRACKED_BC 64 diff --git a/libclamav/bytecode.h b/libclamav/bytecode.h index bceed32e4b..db7a4437dd 100644 --- a/libclamav/bytecode.h +++ b/libclamav/bytecode.h @@ -27,6 +27,7 @@ #include #include "fmap.h" #include "bytecode_detect.h" +#include "platform.h" struct cli_dbio; struct cli_bc_ctx; @@ -105,7 +106,7 @@ void cli_bytecode_context_destroy(struct cli_bc_ctx *ctx); #ifdef __cplusplus extern "C" { #endif -extern int have_clamjit; +extern LIBCLAMAV_EXPORT int have_clamjit; #ifdef __cplusplus } #endif diff --git a/libclamav/bytecode_api.c b/libclamav/bytecode_api.c index 24c4f3561b..727dd7d1ca 100644 --- a/libclamav/bytecode_api.c +++ b/libclamav/bytecode_api.c @@ -35,6 +35,13 @@ #include #include +#if HAVE_JSON +#include +#endif +#if HAVE_BZLIB_H +#include +#endif + #include "clamav.h" #include "clambc.h" #include "bytecode.h" @@ -52,12 +59,6 @@ #include "str.h" #include "filetypes.h" #include "lzma_iface.h" -#if HAVE_JSON -#include "json.h" -#endif -#if HAVE_BZLIB_H -#include -#endif #define EV ctx->bc_events @@ -1644,7 +1645,7 @@ uint32_t cli_bcapi_engine_scan_options_ex(struct cli_bc_ctx *ctx, const uint8_t result = (cctx->options->heuristic & CL_SCAN_HEURISTIC_ENCRYPTED_ARCHIVE) ? 1 : 0; } else if (cli_memstr(option_name_l, name_len, "encrypted doc", sizeof("encrypted doc"))) { result = (cctx->options->heuristic & CL_SCAN_HEURISTIC_ENCRYPTED_DOC) ? 1 : 0; - } else if (cli_memstr(option_name_l, name_len, "partition intxn", sizeof("partition intxn"))) { + } else if (cli_memstr(option_name_l, name_len, "partition intersection", sizeof("partition intersection"))) { result = (cctx->options->heuristic & CL_SCAN_HEURISTIC_PARTITION_INTXN) ? 1 : 0; } else if (cli_memstr(option_name_l, name_len, "structured", sizeof("structured"))) { result = (cctx->options->heuristic & CL_SCAN_HEURISTIC_STRUCTURED) ? 1 : 0; diff --git a/libclamav/bytecode_api.h b/libclamav/bytecode_api.h index 9b57eaf5c7..de16c1405b 100644 --- a/libclamav/bytecode_api.h +++ b/libclamav/bytecode_api.h @@ -1333,36 +1333,36 @@ int32_t json_get_int(int32_t objid); * Check if any given scan option is enabled. * Returns non-zero if the following named options are set: * - * "general allmatch" - all-match mode is enabled - * "general collect metadata" - --gen-json is enabled - * "general heuristics" - --gen-json is enabled + * "general allmatch" - all-match mode is enabled + * "general collect metadata" - --gen-json is enabled + * "general heuristics" - --gen-json is enabled * - * "parse archive" - archive parsing is enabled - * "parse pdf" - pdf parsing is enabled - * "parse swf" - swf parsing is enabled - * "parse hwp3" - hwp3 parsing is enabled - * "parse xmldocs" - xmldocs parsing is enabled - * "parse mail" - mail parsing is enabled - * "parse ole2" - ole2 parsing is enabled - * "parse html" - html parsing is enabled - * "parse pe" - pe parsing is enabled + * "parse archive" - archive parsing is enabled + * "parse pdf" - pdf parsing is enabled + * "parse swf" - swf parsing is enabled + * "parse hwp3" - hwp3 parsing is enabled + * "parse xmldocs" - xmldocs parsing is enabled + * "parse mail" - mail parsing is enabled + * "parse ole2" - ole2 parsing is enabled + * "parse html" - html parsing is enabled + * "parse pe" - pe parsing is enabled * - * "heuristic precedence" - heuristic signatures are set to take precedence - * "heuristic broken" - broken pe heuristic is enabled - * "heuristic exceeds max" - heuristic for when max settings are exceeded is enabled - * "heuristic phishing ssl mismatch" - phishing ssl mismatch heuristic is enabled - * "heuristic phishing cloak" - phishing cloak heuristic is enabled - * "heuristic macros" - macros heuristic is enabled - * "heuristic encrypted" - encrypted heuristic is enabled - * "heuristic partition intxn" - macpartition intxnros heuristic is enabled - * "heuristic structured" - structured heuristic is enabled - * "heuristic structured ssn normal" - structured ssn normal heuristic is enabled + * "heuristic precedence" - heuristic signatures are set to take precedence + * "heuristic broken" - broken pe heuristic is enabled + * "heuristic exceeds max" - heuristic for when max settings are exceeded is enabled + * "heuristic phishing ssl mismatch" - phishing ssl mismatch heuristic is enabled + * "heuristic phishing cloak" - phishing cloak heuristic is enabled + * "heuristic macros" - macros heuristic is enabled + * "heuristic encrypted" - encrypted heuristic is enabled + * "heuristic partition intersection" - macpartition intersectionros heuristic is enabled + * "heuristic structured" - structured heuristic is enabled + * "heuristic structured ssn normal" - structured ssn normal heuristic is enabled * "heuristic structured ssn stripped" - structured ssn stripped heuristic is enabled * - * "mail partial message" - parsing of partial mail messages is enabled + * "mail partial message" - parsing of partial mail messages is enabled * - * "dev collect sha" - --dev-collect-hashes is enabled - * "dev collect performance info" - --dev-performance is enabled + * "dev collect sha" - --dev-collect-hashes is enabled + * "dev collect performance info" - --dev-performance is enabled * * @param[in] scan_options enum value for desired scan option category. * @return CL_SCAN_