更新libclamav库1.0.0版本
This commit is contained in:
158
clamav/libfreshclam/CMakeLists.txt
Normal file
158
clamav/libfreshclam/CMakeLists.txt
Normal file
@@ -0,0 +1,158 @@
|
||||
# Copyright (C) 2020-2022 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
|
||||
|
||||
if(WIN32)
|
||||
add_definitions(-DWIN32_LEAN_AND_MEAN)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
|
||||
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
|
||||
|
||||
# Windows compatibility headers
|
||||
include_directories(${CMAKE_SOURCE_DIR}/win32/compat)
|
||||
endif()
|
||||
|
||||
# not using an object library for the sake of Xcode compatibility
|
||||
# See: https://cmake.org/pipermail/cmake/2016-May/063479.html
|
||||
set(LIBFRESHCLAM_SOURCES
|
||||
libfreshclam.c
|
||||
libfreshclam_internal.c
|
||||
libfreshclam_internal.h
|
||||
dns.c
|
||||
dns.h
|
||||
)
|
||||
|
||||
if(ENABLE_SHARED_LIB)
|
||||
# The libfreshclam shared library.
|
||||
add_library( freshclam SHARED )
|
||||
target_sources( freshclam
|
||||
PRIVATE
|
||||
${LIBFRESHCLAM_SOURCES}
|
||||
PUBLIC
|
||||
libfreshclam.h )
|
||||
if(WIN32)
|
||||
target_sources( freshclam PRIVATE libfreshclam_main.c)
|
||||
endif()
|
||||
target_include_directories( freshclam
|
||||
PRIVATE
|
||||
${CMAKE_BINARY_DIR} # For clamav-config.h
|
||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} )
|
||||
|
||||
target_link_libraries( freshclam
|
||||
PUBLIC
|
||||
ClamAV::common
|
||||
CURL::libcurl
|
||||
OpenSSL::SSL
|
||||
OpenSSL::Crypto )
|
||||
if(APPLE)
|
||||
target_link_libraries( freshclam
|
||||
PUBLIC
|
||||
resolv
|
||||
${APPLE_CORE_FOUNDATION}
|
||||
${APPLE_SECURITY} )
|
||||
elseif(UNIX)
|
||||
if(HAVE_RESOLV_H AND NOT C_BSD) # BSD appears to have libresolv inside libc
|
||||
target_link_libraries( freshclam
|
||||
PUBLIC
|
||||
resolv )
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
set_target_properties(freshclam PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
endif()
|
||||
set_target_properties(freshclam PROPERTIES
|
||||
COMPILE_FLAGS "${WARNCFLAGS}"
|
||||
VERSION ${LIBFRESHCLAM_VERSION} SOVERSION ${LIBFRESHCLAM_SOVERSION})
|
||||
if(WIN32)
|
||||
install(TARGETS freshclam DESTINATION . COMPONENT libraries)
|
||||
install(FILES $<TARGET_PDB_FILE:freshclam> DESTINATION . OPTIONAL COMPONENT libraries)
|
||||
# Also install shared library (DLL) dependencies
|
||||
install(CODE [[
|
||||
file(GET_RUNTIME_DEPENDENCIES
|
||||
LIBRARIES
|
||||
$<TARGET_FILE:ClamAV::libfreshclam>
|
||||
RESOLVED_DEPENDENCIES_VAR _r_deps
|
||||
UNRESOLVED_DEPENDENCIES_VAR _u_deps
|
||||
DIRECTORIES
|
||||
$<TARGET_FILE_DIR:CURL::libcurl>
|
||||
$<TARGET_FILE_DIR:OpenSSL::SSL>
|
||||
$<TARGET_FILE_DIR:OpenSSL::Crypto>
|
||||
)
|
||||
foreach(_file ${_r_deps})
|
||||
string(TOLOWER ${_file} _file_lower)
|
||||
if(NOT ${_file_lower} MATCHES "c:[\\/]windows[\\/]system32.*")
|
||||
file(INSTALL
|
||||
DESTINATION "${CMAKE_INSTALL_PREFIX}"
|
||||
TYPE SHARED_LIBRARY
|
||||
FOLLOW_SYMLINK_CHAIN
|
||||
FILES "${_file}"
|
||||
)
|
||||
endif()
|
||||
endforeach()
|
||||
#message("UNRESOLVED_DEPENDENCIES_VAR: ${_u_deps}")
|
||||
]]
|
||||
COMPONENT libraries)
|
||||
else()
|
||||
install(TARGETS freshclam DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries)
|
||||
endif()
|
||||
|
||||
add_library( ClamAV::libfreshclam ALIAS freshclam )
|
||||
endif()
|
||||
|
||||
if(ENABLE_STATIC_LIB)
|
||||
# The freshclam static library.
|
||||
add_library(freshclam_static STATIC)
|
||||
target_sources(freshclam_static
|
||||
PRIVATE
|
||||
${LIBFRESHCLAM_SOURCES}
|
||||
PUBLIC
|
||||
libfreshclam.h )
|
||||
if(WIN32)
|
||||
target_sources( freshclam_static PRIVATE libfreshclam_main.c)
|
||||
endif()
|
||||
target_include_directories( freshclam_static
|
||||
PRIVATE
|
||||
${CMAKE_BINARY_DIR} # For clamav-config.h
|
||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} )
|
||||
|
||||
target_link_libraries( freshclam_static
|
||||
PUBLIC
|
||||
ClamAV::common
|
||||
CURL::libcurl
|
||||
OpenSSL::SSL
|
||||
OpenSSL::Crypto )
|
||||
if(APPLE)
|
||||
target_link_libraries( freshclam_static
|
||||
PUBLIC
|
||||
resolv
|
||||
${APPLE_CORE_FOUNDATION}
|
||||
${APPLE_SECURITY} )
|
||||
elseif(UNIX)
|
||||
if(HAVE_RESOLV_H AND NOT C_BSD) # BSD appears to have libresolv inside libc
|
||||
target_link_libraries( freshclam_static
|
||||
PUBLIC
|
||||
resolv )
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set_target_properties(freshclam_static PROPERTIES
|
||||
ARCHIVE_OUTPUT_NAME freshclam_static
|
||||
COMPILE_FLAGS "${WARNCFLAGS}"
|
||||
VERSION ${LIBFRESHCLAM_VERSION} SOVERSION ${LIBFRESHCLAM_SOVERSION})
|
||||
target_compile_definitions(freshclam_static PUBLIC freshclam_staticLIB)
|
||||
if(WIN32)
|
||||
install(TARGETS freshclam_static DESTINATION . COMPONENT libraries)
|
||||
else()
|
||||
install(TARGETS freshclam_static DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries)
|
||||
endif()
|
||||
|
||||
add_library( ClamAV::libfreshclam_static ALIAS freshclam_static )
|
||||
if(NOT ENABLE_SHARED_LIB)
|
||||
add_library( ClamAV::libfreshclam ALIAS freshclam_static )
|
||||
endif()
|
||||
endif()
|
||||
|
||||
install(
|
||||
FILES
|
||||
libfreshclam.h
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
COMPONENT libraries)
|
||||
21
clamav/libfreshclam/Doxyfile
Normal file
21
clamav/libfreshclam/Doxyfile
Normal file
@@ -0,0 +1,21 @@
|
||||
PROJECT_NAME = ClamAV - FreshClam
|
||||
OUTPUT_DIRECTORY = ../docs/freshclam
|
||||
WARNINGS = YES
|
||||
FILE_PATTERNS = *.c *.h
|
||||
PERL_PATH = /usr/bin/perl
|
||||
SEARCHENGINE = YES
|
||||
|
||||
GENERATE_LATEX=NO
|
||||
OPTIMIZE_OUTPUT_FOR_C=YES
|
||||
HAVE_DOT=YES
|
||||
CALL_GRAPH=YES
|
||||
CALLER_GRAPH=YES
|
||||
JAVADOC_AUTOBRIEF=YES
|
||||
GENERATE_MAN=NO
|
||||
EXAMPLE_PATH=examples
|
||||
|
||||
DOT_CLEANUP=NO
|
||||
MAX_DOT_GRAPH_DEPTH=3
|
||||
|
||||
EXTRACT_ALL=YES
|
||||
INPUT = .
|
||||
163
clamav/libfreshclam/dns.c
Normal file
163
clamav/libfreshclam/dns.c
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Copyright (C) 2013-2022 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
|
||||
* Copyright (C) 2007-2013 Sourcefire, Inc.
|
||||
* Copyright (C) 2004-2007 Tomasz Kojm <tkojm@clamav.net>2004 Tomasz Kojm <tkojm@clamav.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "clamav-config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "dns.h"
|
||||
#ifdef HAVE_RESOLV_H
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#ifndef _WIN32
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/nameser.h>
|
||||
#endif
|
||||
#include <resolv.h>
|
||||
|
||||
#include "output.h"
|
||||
|
||||
#ifndef PACKETSZ
|
||||
#define PACKETSZ 512
|
||||
#endif
|
||||
|
||||
char *
|
||||
dnsquery(const char *domain, int qtype, unsigned int *ttl)
|
||||
{
|
||||
unsigned char answer[PACKETSZ], *answend, *pt;
|
||||
char *txt, host[128];
|
||||
int len, type;
|
||||
unsigned int cttl, size, txtlen = 0;
|
||||
|
||||
if (ttl)
|
||||
*ttl = 0;
|
||||
if (res_init() < 0) {
|
||||
logg(LOGG_WARNING, "res_init failed\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
logg(LOGG_DEBUG, "Querying %s\n", domain);
|
||||
|
||||
memset(answer, 0, PACKETSZ);
|
||||
if ((len = res_query(domain, C_IN, qtype, answer, PACKETSZ)) < 0 || len > PACKETSZ) {
|
||||
#ifdef FRESHCLAM_DNS_FIX
|
||||
/* The DNS server in the SpeedTouch Alcatel 510 modem can't
|
||||
* handle a TXT-query, but it can resolve an ANY-query to a
|
||||
* TXT-record, so we try an ANY-query now. The thing we try
|
||||
* to resolve normally only has a TXT-record anyway.
|
||||
*/
|
||||
memset(answer, 0, PACKETSZ);
|
||||
if (qtype == T_TXT)
|
||||
qtype = T_ANY;
|
||||
if ((len = res_query(domain, C_IN, qtype, answer, PACKETSZ)) < 0) {
|
||||
logg(LOGG_INFO, "%cCan't query %s\n",
|
||||
(qtype == T_TXT || qtype == T_ANY) ? '^' : '*', domain);
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
logg(LOGG_INFO, "%cCan't query %s\n", (qtype == T_TXT) ? '^' : '*', domain);
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
if (qtype != T_TXT && qtype != T_ANY) {
|
||||
if (ttl)
|
||||
*ttl = 2;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
answend = answer + len;
|
||||
pt = answer + sizeof(HEADER);
|
||||
|
||||
if ((len = dn_expand(answer, answend, pt, host, sizeof(host))) < 0) {
|
||||
logg(LOGG_WARNING, "dn_expand failed\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pt += len;
|
||||
if (pt > answend - 4) {
|
||||
logg(LOGG_WARNING, "Bad (too short) DNS reply\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GETSHORT(type, pt);
|
||||
if (type != qtype) {
|
||||
logg(LOGG_WARNING, "Broken DNS reply.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pt += INT16SZ; /* class */
|
||||
size = 0;
|
||||
do { /* recurse through CNAME rr's */
|
||||
pt += size;
|
||||
if ((len = dn_expand(answer, answend, pt, host, sizeof(host))) < 0) {
|
||||
logg(LOGG_WARNING, "second dn_expand failed\n");
|
||||
return NULL;
|
||||
}
|
||||
pt += len;
|
||||
if (pt > answend - 10) {
|
||||
logg(LOGG_WARNING, "Bad (too short) DNS reply\n");
|
||||
return NULL;
|
||||
}
|
||||
GETSHORT(type, pt);
|
||||
pt += INT16SZ; /* class */
|
||||
GETLONG(cttl, pt);
|
||||
GETSHORT(size, pt);
|
||||
if (pt + size < answer || pt + size > answend) {
|
||||
logg(LOGG_WARNING, "DNS rr overflow\n");
|
||||
return NULL;
|
||||
}
|
||||
} while (type == T_CNAME);
|
||||
|
||||
if (type != T_TXT) {
|
||||
logg(LOGG_WARNING, "Not a TXT record\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!size || (txtlen = *pt) >= size || !txtlen) {
|
||||
logg(LOGG_WARNING, "Broken TXT record (txtlen = %d, size = %d)\n", txtlen, size);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(txt = (char *)malloc(txtlen + 1)))
|
||||
return NULL;
|
||||
|
||||
memcpy(txt, pt + 1, txtlen);
|
||||
txt[txtlen] = 0;
|
||||
if (ttl)
|
||||
*ttl = cttl;
|
||||
|
||||
return txt;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
char *
|
||||
dnsquery(const char *domain, int qtype, unsigned int *ttl)
|
||||
{
|
||||
if (ttl)
|
||||
*ttl = 1; /* ttl of 1 combined with a NULL return distinguishes a failed lookup from DNS queries not being available */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
40
clamav/libfreshclam/dns.h
Normal file
40
clamav/libfreshclam/dns.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2013-2022 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
|
||||
* Copyright (C) 2007-2013 Sourcefire, Inc.
|
||||
* Copyright (C) 2004-2007 Tomasz Kojm <tkojm@clamav.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __DNS_H
|
||||
#define __DNS_H
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "clamav-config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_RESOLV_H
|
||||
#include <sys/types.h>
|
||||
#ifndef _WIN32
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/nameser.h>
|
||||
#endif
|
||||
#include <resolv.h>
|
||||
#endif
|
||||
|
||||
char *dnsquery(const char *domain, int qtype, unsigned int *ttl);
|
||||
|
||||
#endif
|
||||
1000
clamav/libfreshclam/libfreshclam.c
Normal file
1000
clamav/libfreshclam/libfreshclam.c
Normal file
File diff suppressed because it is too large
Load Diff
264
clamav/libfreshclam/libfreshclam.h
Normal file
264
clamav/libfreshclam/libfreshclam.h
Normal file
@@ -0,0 +1,264 @@
|
||||
/*
|
||||
* Copyright (C) 2013-2022 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
|
||||
* Copyright (C) 2007-2013 Sourcefire, Inc.
|
||||
* Copyright (C) 2002-2007 Tomasz Kojm <tkojm@clamav.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __LIBFRESHCLAM_H
|
||||
#define __LIBFRESHCLAM_H
|
||||
|
||||
#include "clamav-types.h"
|
||||
|
||||
/*
|
||||
* FreshClam configuration flag options.
|
||||
*/
|
||||
// clang-format off
|
||||
#define FC_CONFIG_MSG_DEBUG 0x1 // Enable debug messages.
|
||||
#define FC_CONFIG_MSG_VERBOSE 0x2 // Enable verbose mode.
|
||||
#define FC_CONFIG_MSG_QUIET 0x4 // Only output error messages.
|
||||
#define FC_CONFIG_MSG_NOWARN 0x8 // Don't output warning messages.
|
||||
#define FC_CONFIG_MSG_STDOUT 0x10 // Write to stdout instead of stderr.
|
||||
#define FC_CONFIG_MSG_SHOWPROGRESS 0x20 // Show download progress percentage.
|
||||
|
||||
#define FC_CONFIG_LOG_VERBOSE 0x1 // Be verbose in log output as well.
|
||||
#define FC_CONFIG_LOG_NOWARN 0x2 // Don't log warning messages.
|
||||
#define FC_CONFIG_LOG_TIME 0x4 // Include timestamp in log messages.
|
||||
#define FC_CONFIG_LOG_ROTATE 0x8 // Rotate logs if they exceed MaxLogSize.
|
||||
#define FC_CONFIG_LOG_SYSLOG 0x10 // Enable Syslog.
|
||||
// clang-format on
|
||||
|
||||
/* freshclam config options */
|
||||
typedef struct fc_config_ {
|
||||
uint32_t msgFlags; /**< FC_CONFIG_MSG bitflag field. */
|
||||
uint32_t logFlags; /**< FC_CONFIG_LOG bitflag field. */
|
||||
uint64_t maxLogSize; /**< Max size of logfile, if enabled. */
|
||||
uint32_t maxAttempts; /**< Max # of download attempts. Must be > 0 */
|
||||
uint32_t connectTimeout; /**< CURLOPT_CONNECTTIMEOUT, Timeout for the. connection phase (seconds). */
|
||||
uint32_t requestTimeout; /**< CURLOPT_LOW_SPEED_TIME, Timeout for libcurl transfer operation (seconds). */
|
||||
uint32_t bCompressLocalDatabase; /**< If set, will apply gz compression to CLD databases. */
|
||||
const char *logFile; /**< (optional) Filepath to use for log output, if desired. */
|
||||
const char *logFacility; /**< (optional) System logging facility (I.e. "syslog"), if desired. */
|
||||
const char *localIP; /**< (optional) client IP for multihomed systems. */
|
||||
const char *userAgent; /**< (optional) Alternative User Agent. */
|
||||
const char *proxyServer; /**< (optional) http(s) url for proxy server. */
|
||||
uint16_t proxyPort; /**< (optional) Proxy server port #. */
|
||||
const char *proxyUsername; /**< (optional) Username for proxy server authentication .*/
|
||||
const char *proxyPassword; /**< (optional) Password for proxy server authentication. */
|
||||
const char *databaseDirectory; /**< Filepath of database directory. */
|
||||
const char *tempDirectory; /**< Filepath to store temp files. */
|
||||
} fc_config;
|
||||
|
||||
typedef enum fc_error_tag {
|
||||
FC_SUCCESS = 0,
|
||||
FC_UPTODATE = 1,
|
||||
FC_EINIT,
|
||||
FC_EDIRECTORY,
|
||||
FC_EFILE,
|
||||
FC_ECONNECTION,
|
||||
FC_EEMPTYFILE,
|
||||
FC_EBADCVD,
|
||||
FC_ETESTFAIL,
|
||||
FC_ECONFIG,
|
||||
FC_EDBDIRACCESS,
|
||||
FC_EFAILEDGET,
|
||||
FC_EMIRRORNOTSYNC,
|
||||
FC_ELOGGING,
|
||||
FC_EFAILEDUPDATE,
|
||||
FC_EMEM,
|
||||
FC_EARG,
|
||||
FC_EFORBIDDEN,
|
||||
FC_ERETRYLATER,
|
||||
FC_ERROR
|
||||
} fc_error_t;
|
||||
|
||||
/**
|
||||
* @brief Translate an FC_<code> to a human readable message.
|
||||
*
|
||||
* @param fcerror fc_error_t code
|
||||
* @return const char * message.
|
||||
*/
|
||||
const char *fc_strerror(fc_error_t fcerror);
|
||||
|
||||
/**
|
||||
* @brief Configure libfreshclam.
|
||||
*
|
||||
* This will initialize libcurl with `curl_global_init`.
|
||||
* This should only be called once per application.
|
||||
*
|
||||
* If you are initializing libfreshclam from a Windows DLL you should not
|
||||
* initialize it from DllMain or a static initializer because Windows holds
|
||||
* the loader lock during that time and it could cause a deadlock.
|
||||
*
|
||||
* @param config Configuration options.
|
||||
* @return fc_error_t FC_SUCCESS if success.
|
||||
* @return fc_error_t FC_ELOGGING if there is an issue writing to the log.
|
||||
*/
|
||||
fc_error_t fc_initialize(fc_config *config);
|
||||
|
||||
/**
|
||||
* @brief Cleanup libfreshclam features.
|
||||
*
|
||||
* This will call `curl_global_cleanup`.
|
||||
* This should only be invoke once at the end of your
|
||||
* application.
|
||||
*/
|
||||
void fc_cleanup(void);
|
||||
|
||||
/**
|
||||
* @brief Delete CVD & CLD files from database directory that aren't in the provided list.
|
||||
*
|
||||
* Will not touch files other than CLD and CVD files.
|
||||
*
|
||||
* @param databaseList List of official databases to keep.
|
||||
* @param nDatabases Number of databses in list.
|
||||
* @return fc_error_t FC_SUCCESS if success.
|
||||
* @return fc_error_t FC_EDBDIRACCESS if database access issue occured.
|
||||
* @return fc_error_t FC_EARG if invalid arguments.
|
||||
*/
|
||||
fc_error_t fc_prune_database_directory(
|
||||
char **databaseList,
|
||||
uint32_t nDatabases);
|
||||
|
||||
/**
|
||||
* @brief Test if database loads without errors.
|
||||
*
|
||||
* @param dbFilename Filename of database.
|
||||
* @param bBytecodeEnabled Non-zero if database has bytecode signatures, and should be tested.
|
||||
* @return fc_error_t FC_SUCCESS if loaded correctly.
|
||||
* @return fc_error_t FC_EARG callback was passed invalid arguments.
|
||||
*/
|
||||
fc_error_t fc_test_database(
|
||||
const char *dbFilename,
|
||||
int bBytecodeEnabled);
|
||||
|
||||
/**
|
||||
* @brief Query Update Info via DNS to get database version info, and ClamAV version info.
|
||||
*
|
||||
* Caller must free dnsUpdateInfo.
|
||||
*
|
||||
* @param dnsUpdateInfoServer (optional) The DNS server to query for Update Info. If NULL, will disable DNS update info query feature.
|
||||
* @param[out] dnsUpdateInfo The Update Info DNS reply string.
|
||||
* @param[out] newVersion New version of ClamAV available.
|
||||
* @return fc_error_t FC_SUCCESS if success.
|
||||
* @return fc_error_t FC_EARG if invalid args.
|
||||
* @return fc_error_t FC_EFAILEDGET if error or disabled and should fall back to HTTP mode for update info.
|
||||
*/
|
||||
fc_error_t fc_dns_query_update_info(
|
||||
const char *dnsUpdateInfoServer,
|
||||
char **dnsUpdateInfo,
|
||||
char **newVersion);
|
||||
|
||||
/**
|
||||
* @brief Download a database directly from a URL.
|
||||
*
|
||||
* Whole file download. Does not support incremental update.
|
||||
*
|
||||
* @param url Database URL (http, https, file).
|
||||
* @param context Application context to pass to fccb_download_complete callback.
|
||||
* @param[out] bUpdated Non-zero if database was updated to new version or is entirely new.
|
||||
* @return fc_error_t FC_SUCCESS if database downloaded and callback executed successfully.
|
||||
*/
|
||||
fc_error_t fc_download_url_database(
|
||||
const char *urlDatabase,
|
||||
void *context,
|
||||
int *bUpdated);
|
||||
|
||||
/**
|
||||
* @brief Download databases directly from a URLs.
|
||||
*
|
||||
* @param urlDatabaseList List of database URLs
|
||||
* @param nUrlDatabases Number of URLs in list.
|
||||
* @param context Application context to pass to fccb_download_complete callback.
|
||||
* @param[out] nUpdated Number of databases that were updated.
|
||||
* @return fc_error_t FC_SUCCESS if database downloaded and callback executed successfully.
|
||||
*/
|
||||
fc_error_t fc_download_url_databases(
|
||||
char **urlDatabaseList,
|
||||
uint32_t nUrlDatabases,
|
||||
void *context,
|
||||
uint32_t *nUpdated);
|
||||
|
||||
/**
|
||||
* @brief Update specific official database, given list of update servers.
|
||||
*
|
||||
* @param dbName CVD/CLD database name, excluding file extension.
|
||||
* @param serverList String array of update servers.
|
||||
* @param nServers Number of servers in list.
|
||||
* @param dnsUpdateInfoServer DNS server for update info check. May be NULL to disable use of DNS.
|
||||
* @param bScriptedUpdates Enable incremental/updates (should not be enabled for PrivateMirrors).
|
||||
* @param context Application context to pass to fccb_download_complete callback.
|
||||
* @param[out] bUpdated Non-zero if database was updated to new version or is entirely new.
|
||||
* @return fc_error_t FC_SUCCESS if database downloaded and callback executed successfully.
|
||||
*/
|
||||
fc_error_t fc_update_database(
|
||||
const char *database,
|
||||
char **serverList,
|
||||
uint32_t nServers,
|
||||
int bPrivateMirror,
|
||||
const char *dnsUpdateInfo,
|
||||
int bScriptedUpdates,
|
||||
void *context,
|
||||
int *bUpdated);
|
||||
|
||||
/**
|
||||
* @brief Update list of official databases, given list of update servers.
|
||||
*
|
||||
* @param dbNames String array of CVD/CLD database names, excluding file extensions.
|
||||
* @param nDbNames Number of names in array.
|
||||
* @param serverList String array of update servers.
|
||||
* @param nServers Number of servers in list.
|
||||
* @param dnsUpdateInfoServer DNS server for update info check. May be NULL to disable use of DNS.
|
||||
* @param bScriptedUpdates Enable incremental/updates (should not be enabled for PrivateMirrors).
|
||||
* @param context Application context to pass to fccb_download_complete callback.
|
||||
* @param[out] nUpdated Number of databases that were updated.
|
||||
* @return fc_error_t FC_SUCCESS if database downloaded and callback executed successfully.
|
||||
*/
|
||||
fc_error_t fc_update_databases(
|
||||
char **databaseList,
|
||||
uint32_t nDatabases,
|
||||
char **serverList,
|
||||
uint32_t nServers,
|
||||
int bPrivateMirror,
|
||||
const char *dnsUpdateInfo,
|
||||
int bScriptedUpdates,
|
||||
void *context,
|
||||
uint32_t *nUpdated);
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Callback function type definitions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief FreshClam callback Download Complete
|
||||
*
|
||||
* Called after each database has been downloaded or updated.
|
||||
*
|
||||
* @param dbFilepath Filename of the downloaded database in database directory.
|
||||
* @param context Opaque application provided data.
|
||||
* @return fc_error_t FC_SUCCESS if callback action was successful.
|
||||
* @return fc_error_t FC_EARG callback was passed invalid arguments.
|
||||
* @return fc_error_t FC_ETESTFAIL if callback action failed and libfreshclam should abort any additional updates.
|
||||
*/
|
||||
typedef fc_error_t (*fccb_download_complete)(const char *dbFilename, void *context);
|
||||
/**
|
||||
* @brief Set a custom Download Complete callback function.
|
||||
*
|
||||
* @param callback The callback function pointer.
|
||||
*/
|
||||
extern void fc_set_fccb_download_complete(fccb_download_complete callback);
|
||||
|
||||
#endif // __LIBFRESHCLAM_H
|
||||
44
clamav/libfreshclam/libfreshclam.map
Normal file
44
clamav/libfreshclam/libfreshclam.map
Normal file
@@ -0,0 +1,44 @@
|
||||
FRESHCLAM_PUBLIC {
|
||||
global:
|
||||
fc_strerror;
|
||||
fc_initialize;
|
||||
fc_cleanup;
|
||||
fc_prune_database_directory;
|
||||
fc_test_database;
|
||||
fc_dns_query_update_info;
|
||||
fc_download_url_database;
|
||||
fc_download_url_databases;
|
||||
fc_update_database;
|
||||
fc_update_databases;
|
||||
fc_set_fccb_download_complete;
|
||||
logg;
|
||||
logg_close;
|
||||
mprintf;
|
||||
logg_verbose;
|
||||
logg_nowarn;
|
||||
logg_time;
|
||||
logg_rotate;
|
||||
logg_size;
|
||||
logg_file;
|
||||
mprintf_verbose;
|
||||
mprintf_quiet;
|
||||
mprintf_nowarn;
|
||||
mprintf_stdout;
|
||||
mprintf_progress;
|
||||
mprintf_disabled;
|
||||
};
|
||||
FRESHCLAM_PRIVATE {
|
||||
global:
|
||||
optparse;
|
||||
optget;
|
||||
optfree;
|
||||
get_version;
|
||||
print_version;
|
||||
check_flevel;
|
||||
drop_privileges;
|
||||
daemonize_parent_wait;
|
||||
daemonize_signal_parent;
|
||||
sendln;
|
||||
local:
|
||||
*;
|
||||
};
|
||||
2721
clamav/libfreshclam/libfreshclam_internal.c
Normal file
2721
clamav/libfreshclam/libfreshclam_internal.c
Normal file
File diff suppressed because it is too large
Load Diff
95
clamav/libfreshclam/libfreshclam_internal.h
Normal file
95
clamav/libfreshclam/libfreshclam_internal.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (C) 2013-2022 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
|
||||
* Copyright (C) 2007-2013 Sourcefire, Inc.
|
||||
* Copyright (C) 2002-2007 Tomasz Kojm <tkojm@clamav.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __LIBFRESHCLAM_INTERNAL_H
|
||||
#define __LIBFRESHCLAM_INTERNAL_H
|
||||
|
||||
#include "clamav-types.h"
|
||||
|
||||
// clang-format off
|
||||
#define DNS_UPDATEINFO_NEWVERSION 0
|
||||
#define DNS_UPDATEINFO_RECORDTIME 3
|
||||
#define DNS_UPDATEINFO_VERSIONWARNING 4
|
||||
#define DNS_UPDATEINFO_REMOTEFLEVEL 5
|
||||
|
||||
#define DNS_EXTRADBINFO_RECORDTIME 1
|
||||
// clang-format on
|
||||
|
||||
#define SIZEOF_UUID_V4 37 /** For uuid_v4_gen(), includes NULL byte */
|
||||
#define MIRRORS_DAT_MAGIC "FreshClamData" /** Magic bytes for freshclam.dat found before freshclam_dat_v1_t */
|
||||
typedef struct _freshclam_dat_v1 {
|
||||
uint32_t version; /** version of this dat format */
|
||||
char uuid[SIZEOF_UUID_V4]; /** uuid to be used in user-agent */
|
||||
time_t retry_after; /** retry date. If > 0, don't update until after this date */
|
||||
} freshclam_dat_v1_t;
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Internal libfreshclam globals
|
||||
*/
|
||||
|
||||
extern fccb_download_complete g_cb_download_complete;
|
||||
|
||||
extern char *g_localIP;
|
||||
extern char *g_userAgent;
|
||||
|
||||
extern char *g_proxyServer;
|
||||
extern uint16_t g_proxyPort;
|
||||
extern char *g_proxyUsername;
|
||||
extern char *g_proxyPassword;
|
||||
|
||||
extern char *g_tempDirectory;
|
||||
extern char *g_databaseDirectory;
|
||||
|
||||
extern uint32_t g_maxAttempts;
|
||||
extern uint32_t g_connectTimeout;
|
||||
extern uint32_t g_requestTimeout;
|
||||
|
||||
extern uint32_t g_bCompressLocalDatabase;
|
||||
|
||||
extern freshclam_dat_v1_t *g_freshclamDat;
|
||||
|
||||
fc_error_t load_freshclam_dat(void);
|
||||
fc_error_t save_freshclam_dat(void);
|
||||
fc_error_t new_freshclam_dat(void);
|
||||
|
||||
fc_error_t updatedb(
|
||||
const char *database,
|
||||
const char *dnsUpdateInfo,
|
||||
char *server,
|
||||
int bPrivateMirror,
|
||||
void *context,
|
||||
int bScriptedUpdates,
|
||||
int logerr,
|
||||
int *signo,
|
||||
char **dbFilename,
|
||||
int *bUpdated);
|
||||
|
||||
fc_error_t updatecustomdb(
|
||||
const char *url,
|
||||
void *context,
|
||||
int logerr,
|
||||
int *signo,
|
||||
char **dbFilename,
|
||||
int *bUpdated);
|
||||
|
||||
#define DNS_WARNING_THRESHOLD_HOURS 12
|
||||
#define DNS_WARNING_THRESHOLD_SECONDS (DNS_WARNING_THRESHOLD_HOURS * 60 * 60)
|
||||
|
||||
#endif // __LIBFRESHCLAM_INTERNAL_H
|
||||
56
clamav/libfreshclam/libfreshclam_main.c
Normal file
56
clamav/libfreshclam/libfreshclam_main.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2013-2022 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
|
||||
* Copyright (C) 2010-2013 Sourcefire, Inc.
|
||||
*
|
||||
* Authors: aCaB <acab@clamav.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "clamav-config.h"
|
||||
#endif
|
||||
|
||||
#include <Windows.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#ifndef LIBFRESHCLAM_STATIC
|
||||
BOOL APIENTRY DllMain(HMODULE hm, DWORD why, LPVOID rsrv)
|
||||
{
|
||||
WSADATA wsa;
|
||||
switch (why) {
|
||||
case DLL_PROCESS_ATTACH:
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsa))
|
||||
return FALSE;
|
||||
return pthread_win32_process_attach_np();
|
||||
break;
|
||||
|
||||
case DLL_THREAD_ATTACH:
|
||||
return pthread_win32_thread_attach_np();
|
||||
break;
|
||||
|
||||
case DLL_THREAD_DETACH:
|
||||
return pthread_win32_thread_detach_np();
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
WSACleanup();
|
||||
pthread_win32_thread_detach_np();
|
||||
return pthread_win32_process_detach_np();
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user