2003-07-29 15:48:06 +00:00
/*
2022-01-06 16:53:44 -08:00
* Copyright ( C ) 2013 - 2022 Cisco Systems , Inc . and / or its affiliates . All rights reserved .
2013-03-08 17:24:50 -05:00
* Copyright ( C ) 2007 - 2013 Sourcefire , Inc .
2008-04-02 15:24:51 +00:00
*
* Authors : Tomasz Kojm
2003-07-29 15:48:06 +00:00
*
* This program is free software ; you can redistribute it and / or modify
2007-03-31 20:31:04 +00:00
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation .
2003-07-29 15:48:06 +00:00
*
* 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
2006-04-09 19:59:28 +00:00
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston ,
* MA 02110 - 1301 , USA .
2003-07-29 15:48:06 +00:00
*/
# ifndef __CLAMAV_H
# define __CLAMAV_H
2014-07-02 13:45:56 -04:00
# ifdef _WIN32
# ifndef OWN_WINSOCK
# include <winsock2.h>
# endif
# endif
2014-07-01 19:38:01 -04:00
# include <openssl/ssl.h>
# include <openssl/err.h>
2012-07-17 14:33:07 -04:00
/* Certain OSs already use 64bit variables in their stat struct */
2018-12-03 12:40:13 -05:00
# if (!defined(__FreeBSD__) && !defined(__APPLE__))
2021-05-27 13:15:52 -07:00
# define STAT64_OK 1
2017-02-08 15:00:54 -05:00
# else
2021-05-27 13:15:52 -07:00
# define STAT64_OK 0
2017-02-08 15:00:54 -05:00
# endif
2012-07-17 14:33:07 -04:00
2021-05-27 13:15:52 -07:00
# if defined(HAVE_STAT64) && STAT64_OK
2012-07-16 15:36:49 -04:00
2012-07-17 16:34:12 -04:00
# include <unistd.h>
2012-07-16 15:36:49 -04:00
# define STATBUF struct stat64
2013-09-25 16:22:18 -04:00
# define CLAMSTAT stat64
2012-07-16 15:36:49 -04:00
# define LSTAT lstat64
# define FSTAT fstat64
2018-12-03 12:40:13 -05:00
# define safe_open(a, b) open(a, b | O_LARGEFILE)
2021-05-27 13:15:52 -07:00
2012-07-16 15:36:49 -04:00
# else
# define STATBUF struct stat
2013-09-25 16:22:18 -04:00
# define CLAMSTAT stat
2012-07-16 15:36:49 -04:00
# define LSTAT lstat
# define FSTAT fstat
2012-11-02 12:15:45 -07:00
/* Nothing is safe in windows, not even open, safe_open defined under /win32 */
# ifndef _WIN32
# define safe_open open
# endif
2012-07-16 15:36:49 -04:00
# endif
2014-07-09 12:02:48 -04:00
# define UNUSEDPARAM(x) (void)(x)
2003-07-29 15:48:06 +00:00
# include <sys/types.h>
# include <sys/stat.h>
2008-10-17 17:00:13 +00:00
2018-12-05 20:46:20 -05:00
# include "clamav-types.h"
2019-09-07 11:29:15 -04:00
# include "clamav-version.h"
2018-07-20 22:28:48 -04:00
2003-07-29 15:48:06 +00:00
# ifdef __cplusplus
2018-12-03 12:40:13 -05:00
extern " C " {
2003-07-29 15:48:06 +00:00
# endif
# define CL_COUNT_PRECISION 4096
/* return codes */
2018-08-14 14:00:31 -07:00
typedef enum cl_error_t {
2009-02-12 13:53:23 +00:00
/* libclamav specific */
2018-12-03 12:40:13 -05:00
CL_CLEAN = 0 ,
2009-02-12 13:53:23 +00:00
CL_SUCCESS = 0 ,
CL_VIRUS ,
CL_ENULLARG ,
2009-03-12 15:21:36 +00:00
CL_EARG ,
2009-02-12 13:53:23 +00:00
CL_EMALFDB ,
CL_ECVD ,
CL_EVERIFY ,
CL_EUNPACK ,
2004-06-02 00:36:05 +00:00
2009-02-12 13:53:23 +00:00
/* I/O and memory errors */
CL_EOPEN ,
CL_ECREAT ,
CL_EUNLINK ,
CL_ESTAT ,
CL_EREAD ,
CL_ESEEK ,
CL_EWRITE ,
CL_EDUP ,
CL_EACCES ,
CL_ETMPFILE ,
CL_ETMPDIR ,
CL_EMAP ,
CL_EMEM ,
2009-02-16 18:27:08 +00:00
CL_ETIMEOUT ,
2009-02-12 13:53:23 +00:00
/* internal (not reported outside libclamav) */
CL_BREAK ,
CL_EMAXREC ,
CL_EMAXSIZE ,
CL_EMAXFILES ,
2009-07-08 12:45:06 +03:00
CL_EFORMAT ,
2011-04-05 16:33:38 +02:00
CL_EPARSE ,
2018-12-03 12:40:13 -05:00
CL_EBYTECODE , /* may be reported in testmode */
2010-07-29 13:22:35 +03:00
CL_EBYTECODE_TESTFAIL , /* may be reported in testmode */
2010-07-16 13:50:36 +02:00
2010-12-08 11:23:43 +02:00
/* c4w error codes */
CL_ELOCK ,
CL_EBUSY ,
CL_ESTATE ,
2019-02-12 15:10:04 -05:00
CL_VERIFIED , /* The binary has been deemed trusted */
2020-02-23 12:38:18 -05:00
CL_ERROR , /* Unspecified / generic error */
2019-02-12 15:10:04 -05:00
2010-07-16 13:50:36 +02:00
/* no error codes below this line please */
CL_ELAST_ERROR
2009-02-12 13:53:23 +00:00
} cl_error_t ;
2006-11-01 16:04:54 +00:00
2005-11-13 02:08:28 +00:00
/* db options */
2018-12-03 12:37:58 -05:00
// clang-format off
2018-07-20 22:28:48 -04:00
# define CL_DB_PHISHING 0x2
# define CL_DB_PHISHING_URLS 0x8
# define CL_DB_PUA 0x10
# define CL_DB_CVDNOTMP 0x20 /* obsolete */
# define CL_DB_OFFICIAL 0x40 /* internal */
# define CL_DB_PUA_MODE 0x80
# define CL_DB_PUA_INCLUDE 0x100
# define CL_DB_PUA_EXCLUDE 0x200
# define CL_DB_COMPILED 0x400 /* internal */
# define CL_DB_DIRECTORY 0x800 /* internal */
# define CL_DB_OFFICIAL_ONLY 0x1000
# define CL_DB_BYTECODE 0x2000
# define CL_DB_SIGNED 0x4000 /* internal */
2020-07-06 13:03:35 -07:00
# define CL_DB_BYTECODE_UNSIGNED 0x8000 /* Caution: You should never run bytecode signatures from untrusted sources. Doing so may result in arbitrary code execution. */
2018-07-20 22:28:48 -04:00
# define CL_DB_UNSIGNED 0x10000 /* internal */
# define CL_DB_BYTECODE_STATS 0x20000
# define CL_DB_ENHANCED 0x40000
# define CL_DB_PCRE_STATS 0x80000
# define CL_DB_YARA_EXCLUDE 0x100000
# define CL_DB_YARA_ONLY 0x200000
2005-11-13 02:08:28 +00:00
2006-11-01 16:04:54 +00:00
/* recommended db settings */
2018-07-20 22:28:48 -04:00
# define CL_DB_STDOPT (CL_DB_PHISHING | CL_DB_PHISHING_URLS | CL_DB_BYTECODE)
/*** scan options ***/
struct cl_scan_options {
uint32_t general ;
uint32_t parse ;
uint32_t heuristic ;
uint32_t mail ;
uint32_t dev ;
} ;
/* general */
2020-01-23 17:42:33 -08:00
# define CL_SCAN_GENERAL_ALLMATCHES 0x1 /* scan in all-match mode */
# define CL_SCAN_GENERAL_COLLECT_METADATA 0x2 /* collect metadata (--gen-json) */
# define CL_SCAN_GENERAL_HEURISTICS 0x4 /* option to enable heuristic alerts */
# define CL_SCAN_GENERAL_HEURISTIC_PRECEDENCE 0x8 /* allow heuristic match to take precedence. */
# define CL_SCAN_GENERAL_UNPRIVILEGED 0x10 /* scanner will not have read access to files. */
2018-07-20 22:28:48 -04:00
/* parsing capabilities options */
# define CL_SCAN_PARSE_ARCHIVE 0x1
# define CL_SCAN_PARSE_ELF 0x2
# define CL_SCAN_PARSE_PDF 0x4
# define CL_SCAN_PARSE_SWF 0x8
# define CL_SCAN_PARSE_HWP3 0x10
# define CL_SCAN_PARSE_XMLDOCS 0x20
# define CL_SCAN_PARSE_MAIL 0x40
# define CL_SCAN_PARSE_OLE2 0x80
# define CL_SCAN_PARSE_HTML 0x100
# define CL_SCAN_PARSE_PE 0x200
/* heuristic alerting options */
2016-04-21 12:13:57 -04:00
# define CL_SCAN_HEURISTIC_BROKEN 0x2 /* alert on broken PE and broken ELF files */
# define CL_SCAN_HEURISTIC_EXCEEDS_MAX 0x4 /* alert when files exceed scan limits (filesize, max scansize, or max recursion depth) */
# define CL_SCAN_HEURISTIC_PHISHING_SSL_MISMATCH 0x8 /* alert on SSL mismatches */
# define CL_SCAN_HEURISTIC_PHISHING_CLOAK 0x10 /* alert on cloaked URLs in emails */
# define CL_SCAN_HEURISTIC_MACROS 0x20 /* alert on OLE2 files containing macros */
# define CL_SCAN_HEURISTIC_ENCRYPTED_ARCHIVE 0x40 /* alert if archive is encrypted (rar, zip, etc) */
# define CL_SCAN_HEURISTIC_ENCRYPTED_DOC 0x80 /* alert if a document is encrypted (pdf, docx, etc) */
# define CL_SCAN_HEURISTIC_PARTITION_INTXN 0x100 /* alert if partition table size doesn't make sense */
# define CL_SCAN_HEURISTIC_STRUCTURED 0x200 /* data loss prevention options, i.e. alert when detecting personal information */
# define CL_SCAN_HEURISTIC_STRUCTURED_SSN_NORMAL 0x400 /* alert when detecting social security numbers */
# define CL_SCAN_HEURISTIC_STRUCTURED_SSN_STRIPPED 0x800 /* alert when detecting stripped social security numbers */
# define CL_SCAN_HEURISTIC_STRUCTURED_CC 0x1000 /* alert when detecting credit card numbers */
GIF, PNG bugfixes; Add AlertBrokenMedia option
Added a new scan option to alert on broken media (graphics) file
formats. This feature mitigates the risk of malformed media files
intended to exploit vulnerabilities in other software. At present
media validation exists for JPEG, TIFF, PNG, and GIF files.
To enable this feature, set `AlertBrokenMedia yes` in clamd.conf, or
use the `--alert-broken-media` option when using `clamscan`.
These options are disabled by default for now.
Application developers may enable this scan option by enabling
`CL_SCAN_HEURISTIC_BROKEN_MEDIA` for the `heuristic` scan option bit
field.
Fixed PNG parser logic bugs that caused an excess of parsing errors
and fixed a stack exhaustion issue affecting some systems when
scanning PNG files. PNG file type detection was disabled via
signature database update for 0.103.0 to mitigate effects from these
bugs.
Fixed an issue where PNG and GIF files no longer work with Target:5
(graphics) signatures if detected as CL_TYPE_PNG/GIF rather than as
CL_TYPE_GRAPHICS. Target types now support up to 10 possible file
types to make way for additional graphics types in future releases.
Scanning JPEG, TIFF, PNG, and GIF files will no longer return "parse"
errors when file format validation fails. Instead, the scan will alert
with the "Heuristics.Broken.Media" signature prefix and a descriptive
suffix to indicate the issue, provided that the "alert broken media"
feature is enabled.
GIF format validation will no longer fail if the GIF image is missing
the trailer byte, as this appears to be a relatively common issue in
otherwise functional GIF files.
Added a TIFF dynamic configuration (DCONF) option, which was missing.
This will allow us to disable TIFF format validation via signature
database update in the event that it proves to be problematic.
This feature already exists for many other file types.
Added CL_TYPE_JPEG and CL_TYPE_TIFF types.
2020-11-04 15:49:43 -08:00
# define CL_SCAN_HEURISTIC_BROKEN_MEDIA 0x2000 /* alert if a file does not match the identified file format, works with JPEG, TIFF, GIF, PNG */
2018-07-20 22:28:48 -04:00
/* mail scanning options */
# define CL_SCAN_MAIL_PARTIAL_MESSAGE 0x1
/* dev options */
# define CL_SCAN_DEV_COLLECT_SHA 0x1 /* Enables hash output in sha-collect builds - for internal use only */
# define CL_SCAN_DEV_COLLECT_PERFORMANCE_INFO 0x2 /* collect performance timings */
2004-09-13 16:44:01 +00:00
2010-02-12 15:52:19 +01:00
/* cl_countsigs options */
2018-12-03 12:37:58 -05:00
# define CL_COUNTSIGS_OFFICIAL 0x1
# define CL_COUNTSIGS_UNOFFICIAL 0x2
# define CL_COUNTSIGS_ALL (CL_COUNTSIGS_OFFICIAL | CL_COUNTSIGS_UNOFFICIAL)
2010-02-12 15:52:19 +01:00
2013-11-18 20:22:42 +00:00
/* For the new engine_options bit field in the engine */
# define ENGINE_OPTIONS_NONE 0x0
# define ENGINE_OPTIONS_DISABLE_CACHE 0x1
# define ENGINE_OPTIONS_FORCE_TO_DISK 0x2
2014-05-27 22:45:01 -04:00
# define ENGINE_OPTIONS_DISABLE_PE_STATS 0x4
2016-03-16 15:42:35 -04:00
# define ENGINE_OPTIONS_DISABLE_PE_CERTS 0x8
# define ENGINE_OPTIONS_PE_DUMPCERTS 0x10
2018-12-03 12:37:58 -05:00
// clang-format on
2013-11-18 20:22:42 +00:00
2008-11-10 17:39:58 +00:00
struct cl_engine ;
2009-03-02 18:56:03 +00:00
struct cl_settings ;
2004-09-13 16:44:01 +00:00
2018-11-16 11:02:15 -08:00
/* ----------------------------------------------------------------------------
* Enable global libclamav features .
*/
/**
* @ brief Enable debug messages
*/
extern void cl_debug ( void ) ;
/**
* @ brief Set libclamav to always create section hashes for PE files .
*
* Section hashes are used in . mdb signature .
*/
extern void cl_always_gen_section_hash ( void ) ;
/* ----------------------------------------------------------------------------
* Scan engine functions .
*/
2014-06-20 16:09:28 -04:00
/**
2018-11-16 11:02:15 -08:00
* @ brief This function initializes the openssl crypto system .
2018-08-08 12:00:06 -07:00
*
* Called by cl_init ( ) and does not need to be cleaned up as de - init
* is handled automatically by openssl 1.0 .2 . h and 1.1 .0
*
2014-06-20 16:09:28 -04:00
* @ return Always returns 0
2018-11-16 11:02:15 -08:00
*/
2014-06-20 16:09:28 -04:00
int cl_initialize_crypto ( void ) ;
/**
2018-11-16 11:02:15 -08:00
* @ brief This is a deprecated function that used to clean up ssl crypto inits .
2018-08-08 12:00:06 -07:00
*
2018-11-16 11:02:15 -08:00
* Call to EVP_cleanup ( ) has been removed since cleanup is now handled by
* auto - deinit as of openssl 1.0 .2 h and 1.1 .0
2014-06-20 16:09:28 -04:00
*/
void cl_cleanup_crypto ( void ) ;
2018-12-03 12:40:13 -05:00
# define CL_INIT_DEFAULT 0x0
2018-11-16 11:02:15 -08:00
/**
* @ brief Initialize the ClamAV library .
*
* @ param initoptions Unused .
* @ return cl_error_t CL_SUCCESS if everything initalized correctly .
*/
2020-04-18 10:46:57 -04:00
extern cl_error_t cl_init ( unsigned int initoptions ) ;
2005-02-20 04:14:06 +00:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Allocate a new scanning engine and initialize default settings .
*
* The engine should be freed with ` cl_engine_free ( ) ` .
*
* @ return struct cl_engine * Pointer to the scanning engine .
*/
2008-11-13 15:55:35 +00:00
extern struct cl_engine * cl_engine_new ( void ) ;
2007-12-15 20:34:31 +00:00
2008-11-11 14:42:12 +00:00
enum cl_engine_field {
2018-12-03 12:40:13 -05:00
CL_ENGINE_MAX_SCANSIZE , /* uint64_t */
CL_ENGINE_MAX_FILESIZE , /* uint64_t */
CL_ENGINE_MAX_RECURSION , /* uint32_t */
CL_ENGINE_MAX_FILES , /* uint32_t */
CL_ENGINE_MIN_CC_COUNT , /* uint32_t */
CL_ENGINE_MIN_SSN_COUNT , /* uint32_t */
CL_ENGINE_PUA_CATEGORIES , /* (char *) */
CL_ENGINE_DB_OPTIONS , /* uint32_t */
CL_ENGINE_DB_VERSION , /* uint32_t */
CL_ENGINE_DB_TIME , /* time_t */
CL_ENGINE_AC_ONLY , /* uint32_t */
CL_ENGINE_AC_MINDEPTH , /* uint32_t */
CL_ENGINE_AC_MAXDEPTH , /* uint32_t */
CL_ENGINE_TMPDIR , /* (char *) */
CL_ENGINE_KEEPTMP , /* uint32_t */
CL_ENGINE_BYTECODE_SECURITY , /* uint32_t */
CL_ENGINE_BYTECODE_TIMEOUT , /* uint32_t */
CL_ENGINE_BYTECODE_MODE , /* uint32_t */
CL_ENGINE_MAX_EMBEDDEDPE , /* uint64_t */
CL_ENGINE_MAX_HTMLNORMALIZE , /* uint64_t */
CL_ENGINE_MAX_HTMLNOTAGS , /* uint64_t */
CL_ENGINE_MAX_SCRIPTNORMALIZE , /* uint64_t */
CL_ENGINE_MAX_ZIPTYPERCG , /* uint64_t */
CL_ENGINE_FORCETODISK , /* uint32_t */
CL_ENGINE_DISABLE_CACHE , /* uint32_t */
CL_ENGINE_DISABLE_PE_STATS , /* uint32_t */
CL_ENGINE_STATS_TIMEOUT , /* uint32_t */
CL_ENGINE_MAX_PARTITIONS , /* uint32_t */
CL_ENGINE_MAX_ICONSPE , /* uint32_t */
CL_ENGINE_MAX_RECHWP3 , /* uint32_t */
2019-08-16 17:18:59 -07:00
CL_ENGINE_MAX_SCANTIME , /* uint32_t */
2018-12-03 12:40:13 -05:00
CL_ENGINE_PCRE_MATCH_LIMIT , /* uint64_t */
CL_ENGINE_PCRE_RECMATCH_LIMIT , /* uint64_t */
CL_ENGINE_PCRE_MAX_FILESIZE , /* uint64_t */
CL_ENGINE_DISABLE_PE_CERTS , /* uint32_t */
2019-08-16 17:18:59 -07:00
CL_ENGINE_PE_DUMPCERTS , /* uint32_t */
2010-01-22 14:36:56 +02:00
} ;
enum bytecode_security {
2018-12-03 12:40:13 -05:00
CL_BYTECODE_TRUST_ALL = 0 , /* obsolete */
CL_BYTECODE_TRUST_SIGNED , /* default */
CL_BYTECODE_TRUST_NOTHING /* paranoid setting */
2008-11-11 14:42:12 +00:00
} ;
2005-03-18 01:27:45 +00:00
2010-07-29 13:22:35 +03:00
enum bytecode_mode {
2018-12-03 12:40:13 -05:00
CL_BYTECODE_MODE_AUTO = 0 , /* JIT if possible, fallback to interpreter */
CL_BYTECODE_MODE_JIT , /* force JIT */
2010-07-29 13:22:35 +03:00
CL_BYTECODE_MODE_INTERPRETER , /* force interpreter */
2018-12-03 12:40:13 -05:00
CL_BYTECODE_MODE_TEST , /* both JIT and interpreter, compare results, all failures are fatal */
CL_BYTECODE_MODE_OFF /* for query only, not settable */
2010-07-29 13:22:35 +03:00
} ;
2014-01-21 11:30:27 -05:00
struct cli_section_hash {
unsigned char md5 [ 16 ] ;
size_t len ;
} ;
typedef struct cli_stats_sections {
size_t nsections ;
struct cli_section_hash * sections ;
} stats_section_t ;
2013-10-25 10:17:22 -04:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Set a numerical engine option .
*
2020-03-19 21:23:54 -04:00
* Caution : changing options for an engine that is in - use is not thread - safe !
*
2018-11-16 11:02:15 -08:00
* @ param engine An initialized scan engine .
* @ param cl_engine_field A CL_ENGINE option .
* @ param num The new engine option value .
* @ return cl_error_t CL_SUCCESS if successfully set .
* @ return cl_error_t CL_EARG if the field number was incorrect .
* @ return cl_error_t CL_ENULLARG null arguments were provided .
*/
2020-04-18 10:46:57 -04:00
extern cl_error_t cl_engine_set_num ( struct cl_engine * engine , enum cl_engine_field field , long long num ) ;
2007-01-09 20:06:51 +00:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Get a numerical engine option .
*
* @ param engine An initialized scan engine .
* @ param cl_engine_field A CL_ENGINE option .
* @ param err ( optional ) A cl_error_t status code .
* @ return long long The numerical option value .
*/
2009-03-12 15:23:20 +00:00
extern long long cl_engine_get_num ( const struct cl_engine * engine , enum cl_engine_field field , int * err ) ;
2009-03-12 15:21:36 +00:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Set a string engine option .
*
2020-03-19 21:23:54 -04:00
* If the string option has already been set , the existing string will be free ' d
* and the new string will replace it .
*
* Caution : changing options for an engine that is in - use is not thread - safe !
*
2018-11-16 11:02:15 -08:00
* @ param engine An initialized scan engine .
* @ param cl_engine_field A CL_ENGINE option .
* @ param str The new engine option value .
* @ return cl_error_t CL_SUCCESS if successfully set .
* @ return cl_error_t CL_EARG if the field number was incorrect .
* @ return cl_error_t CL_EMEM if a memory allocation error occurred .
* @ return cl_error_t CL_ENULLARG null arguments were provided .
*/
2020-04-18 10:46:57 -04:00
extern cl_error_t cl_engine_set_str ( struct cl_engine * engine , enum cl_engine_field field , const char * str ) ;
2009-03-12 15:21:36 +00:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Get a string engine option .
*
* @ param engine An initialized scan engine .
* @ param cl_engine_field A CL_ENGINE option .
* @ param err ( optional ) A cl_error_t status code .
* @ return const char * The string option value .
*/
2009-03-12 15:23:20 +00:00
extern const char * cl_engine_get_str ( const struct cl_engine * engine , enum cl_engine_field field , int * err ) ;
2007-12-14 22:39:37 +00:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Copy the settings from an existing scan engine .
*
* The cl_settings pointer is allocated and must be freed with cl_engine_settings_free ( ) .
*
* @ param engine An configured scan engine .
* @ return struct cl_settings * The settings .
*/
2009-03-02 18:56:03 +00:00
extern struct cl_settings * cl_engine_settings_copy ( const struct cl_engine * engine ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Apply settings from a settings structure to a scan engine .
*
2020-03-19 21:23:54 -04:00
* Caution : changing options for an engine that is in - use is not thread - safe !
*
2018-11-16 11:02:15 -08:00
* @ param engine A scan engine .
* @ param settings The settings .
* @ return cl_error_t CL_SUCCESS if successful .
* @ return cl_error_t CL_EMEM if a memory allocation error occurred .
*/
2020-04-18 10:46:57 -04:00
extern cl_error_t cl_engine_settings_apply ( struct cl_engine * engine , const struct cl_settings * settings ) ;
2009-03-02 18:56:03 +00:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Free a settings struct pointer .
*
* @ param settings The settings struct pointer .
* @ return cl_error_t CL_SUCCESS if successful .
* @ return cl_error_t CL_ENULLARG null arguments were provided .
*/
2020-04-18 10:46:57 -04:00
extern cl_error_t cl_engine_settings_free ( struct cl_settings * settings ) ;
2009-03-02 18:56:03 +00:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Prepare the scanning engine .
*
* Called this after all required databases have been loaded and settings have
* been applied .
*
* @ param engine A scan engine .
* @ return cl_error_t CL_SUCCESS if successful .
* @ return cl_error_t CL_ENULLARG null arguments were provided .
*/
2020-04-18 10:46:57 -04:00
extern cl_error_t cl_engine_compile ( struct cl_engine * engine ) ;
2008-02-08 19:32:45 +00:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Add a reference count to the engine .
*
* Thread safety mechanism so that the engine is not free ' d by another thread .
*
* The engine is initialized with refcount = 1 , so this only needs to be called
* for additional scanning threads .
*
* @ param engine A scan engine .
* @ return cl_error_t CL_SUCCESS if successful .
* @ return cl_error_t CL_ENULLARG null arguments were provided .
*/
2020-04-18 10:46:57 -04:00
extern cl_error_t cl_engine_addref ( struct cl_engine * engine ) ;
2008-07-31 16:26:50 +00:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Free an engine .
*
* Will lower the reference count on an engine . If the reference count hits
* zero , the engine will be freed .
*
* @ param engine A scan engine .
* @ return cl_error_t CL_SUCCESS if successful .
* @ return cl_error_t CL_ENULLARG null arguments were provided .
*/
2020-04-18 10:46:57 -04:00
extern cl_error_t cl_engine_free ( struct cl_engine * engine ) ;
2008-10-17 17:00:13 +00:00
2018-11-16 11:02:15 -08:00
/* ----------------------------------------------------------------------------
* Callback function type definitions .
*/
2011-06-14 17:00:06 +02:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Pre - cache callback .
*
* Called for each processed file ( both the entry level - AKA ' outer ' - file and
* inner files - those generated when processing archive and container files ) , before
* the actual scanning takes place .
*
* @ param fd File descriptor which is about to be scanned .
* @ param type File type detected via magic - i . e . NOT on the fly - ( e . g . " CL_TYPE_MSEXE " ) .
* @ param context Opaque application provided data .
* @ return CL_CLEAN = File is scanned .
2021-05-27 13:15:52 -07:00
* @ return CL_BREAK = Allowed by callback - file is skipped and marked as clean .
* @ return CL_VIRUS = Blocked by callback - file is skipped and marked as infected .
2018-11-16 11:02:15 -08:00
*/
2011-06-14 17:00:06 +02:00
typedef cl_error_t ( * clcb_pre_cache ) ( int fd , const char * type , void * context ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Set a custom pre - cache callback function .
*
2020-03-19 21:23:54 -04:00
* Caution : changing options for an engine that is in - use is not thread - safe !
*
2018-11-16 11:02:15 -08:00
* @ param engine The initialized scanning engine .
* @ param callback The callback function pointer .
*/
2011-06-15 04:50:54 +02:00
extern void cl_engine_set_clcb_pre_cache ( struct cl_engine * engine , clcb_pre_cache callback ) ;
2011-06-14 17:00:06 +02:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Pre - scan callback .
*
* Called for each NEW file ( inner and outer ) before the scanning takes place . This is
* roughly the the same as clcb_before_cache , but it is affected by clean file caching .
* This means that it won ' t be called if a clean cached file ( inner or outer ) is
* scanned a second time .
*
* @ param fd File descriptor which is about to be scanned .
* @ param type File type detected via magic - i . e . NOT on the fly - ( e . g . " CL_TYPE_MSEXE " ) .
* @ param context Opaque application provided data .
* @ return CL_CLEAN = File is scanned .
2021-05-27 13:15:52 -07:00
* @ return CL_BREAK = Allowed by callback - file is skipped and marked as clean .
* @ return CL_VIRUS = Blocked by callback - file is skipped and marked as infected .
2018-11-16 11:02:15 -08:00
*/
2011-06-14 17:00:06 +02:00
typedef cl_error_t ( * clcb_pre_scan ) ( int fd , const char * type , void * context ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Set a custom pre - scan callback function .
*
2020-03-19 21:23:54 -04:00
* Caution : changing options for an engine that is in - use is not thread - safe !
*
2018-11-16 11:02:15 -08:00
* @ param engine The initialized scanning engine .
* @ param callback The callback function pointer .
*/
2011-06-14 17:00:06 +02:00
extern void cl_engine_set_clcb_pre_scan ( struct cl_engine * engine , clcb_pre_scan callback ) ;
2010-06-22 15:41:19 +02:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Post - scan callback .
*
* Called for each processed file ( inner and outer ) , after the scanning is complete .
* In all - match mode , the virname will be one of the matches , but there is no
* guarantee in which order the matches will occur , thus the final virname may
* be any one of the matches .
*
* @ param fd File descriptor which was scanned .
* @ param result The scan result for the file .
* @ param virname A signature name if there was one or more matches .
* @ param context Opaque application provided data .
* @ return Scan result is not overridden .
2021-05-27 13:15:52 -07:00
* @ return CL_BREAK = Allowed by callback - scan result is set to CL_CLEAN .
* @ return Blocked by callback - scan result is set to CL_VIRUS .
2018-11-16 11:02:15 -08:00
*/
2010-07-07 03:01:55 +02:00
typedef cl_error_t ( * clcb_post_scan ) ( int fd , int result , const char * virname , void * context ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Set a custom post - scan callback function .
*
2020-03-19 21:23:54 -04:00
* Caution : changing options for an engine that is in - use is not thread - safe !
*
2018-11-16 11:02:15 -08:00
* @ param engine The initialized scanning engine .
* @ param callback The callback function pointer .
*/
2010-07-07 03:01:55 +02:00
extern void cl_engine_set_clcb_post_scan ( struct cl_engine * engine , clcb_post_scan callback ) ;
2010-06-22 15:41:19 +02:00
2018-11-16 11:02:15 -08:00
/**
2021-05-27 13:15:52 -07:00
* @ brief Virus - found callback .
2018-11-16 11:02:15 -08:00
*
* Called for each signature match .
* If all - match is enabled , clcb_virus_found ( ) may be called multiple times per
* scan .
*
* In addition , clcb_virus_found ( ) does not have a return value and thus .
2021-05-27 13:15:52 -07:00
* can not be used to ignore the match .
2018-11-16 11:02:15 -08:00
*
* @ param fd File descriptor which was scanned .
* @ param virname Virus name .
* @ param context Opaque application provided data .
*/
2015-10-01 17:47:37 -04:00
typedef void ( * clcb_virus_found ) ( int fd , const char * virname , void * context ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Set a custom virus - found callback function .
*
2020-03-19 21:23:54 -04:00
* Caution : changing options for an engine that is in - use is not thread - safe !
*
2018-11-16 11:02:15 -08:00
* @ param engine The initialized scanning engine .
* @ param callback The callback function pointer .
*/
2015-10-01 17:47:37 -04:00
extern void cl_engine_set_clcb_virus_found ( struct cl_engine * engine , clcb_virus_found callback ) ;
2010-06-22 15:41:19 +02:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Signature - load callback .
*
* May be used to ignore signatures at database load time .
*
* WARNING : Some signatures ( notably ldb , cbc ) can be dependent upon other signatures .
* Failure to preserve dependency chains will result in database loading failure .
* It is the implementor ' s responsibility to guarantee consistency .
*
* @ param type The signature type ( e . g . " db " , " ndb " , " mdb " , etc . )
* @ param name Signature name .
* @ param custom The signature is official ( custom = = 0 ) or custom ( custom ! = 0 )
* @ param context Opaque application provided data
* @ return 0 to load the current signature .
* @ return Non - 0 to skip the current signature .
*/
2011-06-14 19:04:02 +02:00
typedef int ( * clcb_sigload ) ( const char * type , const char * name , unsigned int custom , void * context ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Set a custom signature - load callback function .
*
2020-03-19 21:23:54 -04:00
* Caution : changing options for an engine that is in - use is not thread - safe !
*
2018-11-16 11:02:15 -08:00
* @ param engine The initialized scanning engine .
* @ param callback The callback function pointer .
* @ param context Opaque application provided data .
*/
2010-06-22 15:41:19 +02:00
extern void cl_engine_set_clcb_sigload ( struct cl_engine * engine , clcb_sigload callback , void * context ) ;
2018-11-16 11:02:15 -08:00
enum cl_msg {
/* leave room for more message levels in the future */
CL_MSG_INFO_VERBOSE = 32 , /* verbose */
2018-12-03 12:40:13 -05:00
CL_MSG_WARN = 64 , /* LibClamAV WARNING: */
CL_MSG_ERROR = 128 /* LibClamAV ERROR: */
2018-11-16 11:02:15 -08:00
} ;
2021-07-16 11:47:23 -07:00
/**
* @ brief Progress callback for sig - load , engine - compile , and engine - free .
*
* Progress is complete when total_items = = now_completed .
*
* Note : The callback should return CL_SUCCESS . We reserve the right to have it
* cancel the operation in the future if you return something else . . .
* . . . but for now , the return value will be ignored .
*
* @ param total_items Total number of items
* @ param now_completed Number of items completed
* @ param context Opaque application provided data
* @ return cl_error_t reserved for future use
*/
typedef cl_error_t ( * clcb_progress ) ( size_t total_items , size_t now_completed , void * context ) ;
/**
* @ brief Set a progress callback function to be called incrementally during a
* database load .
*
* Caution : changing options for an engine that is in - use is not thread - safe !
*
* @ param engine The initialized scanning engine
* @ param callback The callback function pointer
* @ param context Opaque application provided data
*/
extern void cl_engine_set_clcb_sigload_progress ( struct cl_engine * engine , clcb_progress callback , void * context ) ;
/**
* @ brief Set a progress callback function to be called incrementally during an
* engine compile .
*
* Disclaimer : the number of items for this is a rough estimate of the items that
* tend to take longest to compile and doesn ' t represent an accurate number of
* things compiled .
*
* Caution : changing options for an engine that is in - use is not thread - safe !
*
* @ param engine The initialized scanning engine
* @ param callback The callback function pointer
* @ param context Opaque application provided data
*/
extern void cl_engine_set_clcb_engine_compile_progress ( struct cl_engine * engine , clcb_progress callback , void * context ) ;
/**
* @ brief Set a progress callback function to be called incrementally during an
* engine free ( if the engine is in fact freed ) .
*
* Disclaimer : the number of items for this is a rough estimate of the items that
* tend to take longest to free and doesn ' t represent an accurate number of
* things freed .
*
* Caution : changing options for an engine that is in - use is not thread - safe !
*
* @ param engine The initialized scanning engine
* @ param callback The callback function pointer
* @ param context Opaque application provided data
*/
extern void cl_engine_set_clcb_engine_free_progress ( struct cl_engine * engine , clcb_progress callback , void * context ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Logging message callback for info , warning , and error messages .
*
2010-11-02 12:26:33 +02:00
* The specified callback will be called instead of logging to stderr .
* Messages of lower severity than specified are logged as usual .
*
2018-11-16 11:02:15 -08:00
* Callback may be used to silence logging by assigning a do - nothing function .
* Does not affect debug log messages .
*
2010-11-02 12:26:33 +02:00
* Just like with cl_debug ( ) this must be called before going multithreaded .
* Callable before cl_init , if you want to log messages from cl_init ( ) itself .
*
2018-11-16 11:02:15 -08:00
* You can use context of cl_scandesc_callback to convey more information to
* the callback ( such as the filename ! ) .
*
2010-11-02 12:26:33 +02:00
* Note : setting a 2 nd callbacks overwrites previous , multiple callbacks are not
2018-11-16 11:02:15 -08:00
* supported .
*
* @ param severity Message severity ( CL_MSG_INFO_VERBOSE , CL_MSG_WARN , or CL_MSG_ERROR ) .
* @ param fullmsg The log message including the " LibClamAV <severity>: " prefix .
* @ param msg The log message .
* @ param context Opaque application provided data .
2010-11-02 12:26:33 +02:00
*/
typedef void ( * clcb_msg ) ( enum cl_msg severity , const char * fullmsg , const char * msg , void * context ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Set a custom logging message callback function for all of libclamav .
*
* @ param callback The callback function pointer .
*/
2010-11-02 12:26:33 +02:00
extern void cl_set_clcb_msg ( clcb_msg callback ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief LibClamAV hash stats callback .
*
* Callback that provides the hash of a scanned sample if a signature alerted .
* Provides a mechanism to record detection statistics .
*
* @ param fd File descriptor if available , else - 1.
* @ param size Sample size
* @ param md5 Sample md5 hash
* @ param virname Signature name that the sample matched against
* @ param context Opaque application provided data
*/
2010-11-02 12:26:33 +02:00
typedef void ( * clcb_hash ) ( int fd , unsigned long long size , const unsigned char * md5 , const char * virname , void * context ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Set a custom hash stats callback function .
*
2020-03-19 21:23:54 -04:00
* Caution : changing options for an engine that is in - use is not thread - safe !
*
2018-11-16 11:02:15 -08:00
* @ param engine The initialized scanning engine .
* @ param callback The callback function pointer .
*/
2010-11-02 12:26:33 +02:00
extern void cl_engine_set_clcb_hash ( struct cl_engine * engine , clcb_hash callback ) ;
2010-06-22 15:41:19 +02:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Archive meta matching callback function .
*
2021-05-27 13:15:52 -07:00
* May be used to block archive / container samples based on archive metadata .
2018-11-16 11:02:15 -08:00
* Function is invoked multiple times per archive . Typically once per contained file .
*
* Note : Used by the - - archive - verbose clamscan option . Overriding this will alter
* the output from - - archive - verbose .
*
* @ param container_type String name of type ( CL_TYPE ) .
* @ param fsize_container Sample size
* @ param filename Filename associated with the data in archive .
* @ param fsize_real Size of file after decompression ( according to the archive ) .
* @ param is_encrypted Boolean non - zero if the contained file is encrypted .
* @ param filepos_container File index in container .
* @ param context Opaque application provided data .
2021-05-27 13:15:52 -07:00
* @ return CL_VIRUS to block ( alert on )
2018-11-16 11:02:15 -08:00
* @ return CL_CLEAN to continue scanning
*/
2018-12-03 12:40:13 -05:00
typedef cl_error_t ( * clcb_meta ) ( const char * container_type , unsigned long fsize_container , const char * filename ,
unsigned long fsize_real , int is_encrypted , unsigned int filepos_container , void * context ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Set a custom archive metadata matching callback function .
*
2020-03-19 21:23:54 -04:00
* Caution : changing options for an engine that is in - use is not thread - safe !
*
2018-11-16 11:02:15 -08:00
* @ param engine The initialized scanning engine .
* @ param callback The callback function pointer .
*/
2011-08-22 15:22:55 +03:00
extern void cl_engine_set_clcb_meta ( struct cl_engine * engine , clcb_meta callback ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief File properties callback function .
*
* Invoked after a scan the CL_SCAN_GENERAL_COLLECT_METADATA general scan option
* is enabled and libclamav was built with json support .
*
* @ param j_propstr File properties / metadata in a JSON encoded string .
* @ param rc The cl_error_t return code from the scan .
* @ param cbdata Opaque application provided data .
*/
2014-06-03 13:31:50 -04:00
typedef int ( * clcb_file_props ) ( const char * j_propstr , int rc , void * cbdata ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Set a custom file properties callback function .
*
2020-03-19 21:23:54 -04:00
* Caution : changing options for an engine that is in - use is not thread - safe !
*
2018-11-16 11:02:15 -08:00
* @ param engine The initialized scanning engine .
* @ param callback The callback function pointer .
*/
2015-03-27 13:21:49 -04:00
extern void cl_engine_set_clcb_file_props ( struct cl_engine * engine , clcb_file_props callback ) ;
2014-06-03 13:31:50 -04:00
2018-11-16 11:02:15 -08:00
/* ----------------------------------------------------------------------------
* Statistics / telemetry gathering callbacks .
*
* The statistics callback functions may be used to implement a telemetry
* gathering feature .
*
* The structure definition for ` cbdata ` is entirely up to the caller , as are
* the implementations of each of the callback functions defined below .
*/
/**
* @ brief Set a pointer the caller - defined cbdata structure .
*
* The data must persist at least until ` clcb_stats_submit ( ) ` is called , or
* ` clcb_stats_flush ( ) ` is called ( optional ) .
*
2020-03-19 21:23:54 -04:00
* Caution : changing options for an engine that is in - use is not thread - safe !
*
2018-11-16 11:02:15 -08:00
* @ param engine The scanning engine .
* @ param cbdata The statistics data . Probably a pointer to a malloc ' d struct .
*/
2013-10-25 10:17:22 -04:00
extern void cl_engine_set_stats_set_cbdata ( struct cl_engine * engine , void * cbdata ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Add sample metadata to the statistics for a sample that matched on a signature .
*
* @ param virname Name of the signature that matched .
* @ param md5 Sample hash .
* @ param size Sample size .
* @ param sections PE section data , if applicable .
* @ param cbdata The statistics data . Probably a pointer to a malloc ' d struct .
*/
2014-01-21 11:30:27 -05:00
typedef void ( * clcb_stats_add_sample ) ( const char * virname , const unsigned char * md5 , size_t size , stats_section_t * sections , void * cbdata ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Set a custom callback function to add sample metadata to a statistics report .
*
2020-03-19 21:23:54 -04:00
* Caution : changing options for an engine that is in - use is not thread - safe !
*
2018-11-16 11:02:15 -08:00
* @ param engine The initialized scanning engine .
* @ param callback The callback function pointer .
*/
2013-10-25 10:17:22 -04:00
extern void cl_engine_set_clcb_stats_add_sample ( struct cl_engine * engine , clcb_stats_add_sample callback ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Remove a specific sample from the statistics report .
*
* @ param virname Name of the signature that matched .
* @ param md5 Sample hash .
* @ param size Sample size .
* @ param cbdata The statistics data . Probably a pointer to a malloc ' d struct .
*/
2014-01-21 11:30:27 -05:00
typedef void ( * clcb_stats_remove_sample ) ( const char * virname , const unsigned char * md5 , size_t size , void * cbdata ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Set a custom callback function to remove sample metadata from a statistics report .
*
2020-03-19 21:23:54 -04:00
* Caution : changing options for an engine that is in - use is not thread - safe !
*
2018-11-16 11:02:15 -08:00
* @ param engine The initialized scanning engine .
* @ param callback The callback function pointer .
*/
2013-10-25 10:17:22 -04:00
extern void cl_engine_set_clcb_stats_remove_sample ( struct cl_engine * engine , clcb_stats_remove_sample callback ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Decrement the hit count listed in the statistics report for a specific sample .
*
* @ param virname Name of the signature that matched .
* @ param md5 Sample hash .
* @ param size Sample size .
* @ param cbdata The statistics data . Probably a pointer to a malloc ' d struct .
*/
2014-01-21 11:30:27 -05:00
typedef void ( * clcb_stats_decrement_count ) ( const char * virname , const unsigned char * md5 , size_t size , void * cbdata ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Set a custom callback function to decrement the hit count listed in the statistics report for a specific sample .
*
* This function may remove the sample from the report if the hit count is decremented to 0.
*
* @ param engine The initialized scanning engine .
* @ param callback The callback function pointer .
*/
2013-10-25 10:17:22 -04:00
extern void cl_engine_set_clcb_stats_decrement_count ( struct cl_engine * engine , clcb_stats_decrement_count callback ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Function to submit a statistics report .
*
* @ param engine The initialized scanning engine .
* @ param cbdata The statistics data . Probably a pointer to a malloc ' d struct .
*/
2013-10-25 10:17:22 -04:00
typedef void ( * clcb_stats_submit ) ( struct cl_engine * engine , void * cbdata ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Set a custom callback function to submit the statistics report .
*
2020-03-19 21:23:54 -04:00
* Caution : changing options for an engine that is in - use is not thread - safe !
*
2018-11-16 11:02:15 -08:00
* @ param engine The initialized scanning engine .
* @ param callback The callback function pointer .
*/
2013-10-25 10:17:22 -04:00
extern void cl_engine_set_clcb_stats_submit ( struct cl_engine * engine , clcb_stats_submit callback ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Function to flush / free the statistics report data .
*
* @ param engine The initialized scanning engine .
* @ param cbdata The statistics data . Probably a pointer to a malloc ' d struct .
*/
2013-10-25 10:17:22 -04:00
typedef void ( * clcb_stats_flush ) ( struct cl_engine * engine , void * cbdata ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Set a custom callback function to flush / free the statistics report data .
*
2020-03-19 21:23:54 -04:00
* Caution : changing options for an engine that is in - use is not thread - safe !
*
2018-11-16 11:02:15 -08:00
* @ param engine The initialized scanning engine .
* @ param callback The callback function pointer .
*/
2013-10-25 10:17:22 -04:00
extern void cl_engine_set_clcb_stats_flush ( struct cl_engine * engine , clcb_stats_flush callback ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Function to get the number of samples listed in the statistics report .
*
* @ param cbdata The statistics data . Probably a pointer to a malloc ' d struct .
*/
2013-10-25 10:17:22 -04:00
typedef size_t ( * clcb_stats_get_num ) ( void * cbdata ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Set a custom callback function to get the number of samples listed in the statistics report .
*
2020-03-19 21:23:54 -04:00
* Caution : changing options for an engine that is in - use is not thread - safe !
*
2018-11-16 11:02:15 -08:00
* @ param engine The initialized scanning engine .
* @ param callback The callback function pointer .
*/
2013-10-25 10:17:22 -04:00
extern void cl_engine_set_clcb_stats_get_num ( struct cl_engine * engine , clcb_stats_get_num callback ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Function to get the size of memory used to store the statistics report .
*
* @ param cbdata The statistics data . Probably a pointer to a malloc ' d struct .
*/
2013-10-25 10:17:22 -04:00
typedef size_t ( * clcb_stats_get_size ) ( void * cbdata ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Set a custom callback function to get the size of memory used to store the statistics report .
*
2020-03-19 21:23:54 -04:00
* Caution : changing options for an engine that is in - use is not thread - safe !
*
2018-11-16 11:02:15 -08:00
* @ param engine The initialized scanning engine .
* @ param callback The callback function pointer .
*/
2013-10-25 10:17:22 -04:00
extern void cl_engine_set_clcb_stats_get_size ( struct cl_engine * engine , clcb_stats_get_size callback ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Function to get the machine ' s unique host ID .
*
* @ param cbdata The statistics data . Probably a pointer to a malloc ' d struct .
*/
2018-12-03 12:40:13 -05:00
typedef char * ( * clcb_stats_get_hostid ) ( void * cbdata ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Set a custom callback function to get the machine ' s unique host ID .
*
2020-03-19 21:23:54 -04:00
* Caution : changing options for an engine that is in - use is not thread - safe !
*
2018-11-16 11:02:15 -08:00
* @ param engine The initialized scanning engine .
* @ param callback The callback function pointer .
*/
2013-10-25 10:17:22 -04:00
extern void cl_engine_set_clcb_stats_get_hostid ( struct cl_engine * engine , clcb_stats_get_hostid callback ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Function enables the built - in statistics reporting feature .
*
* @ param engine The initialized scanning engine .
*/
2014-03-07 13:09:37 -05:00
extern void cl_engine_stats_enable ( struct cl_engine * engine ) ;
2018-11-16 11:02:15 -08:00
/* ----------------------------------------------------------------------------
* File scanning .
*/
/**
* @ brief Scan a file , given a file descriptor .
*
* @ param desc File descriptor of an open file . The caller must provide this or the map .
* @ param filename ( optional ) Filepath of the open file descriptor or file map .
* @ param [ out ] virname Will be set to a statically allocated ( i . e . needs not be freed ) signature name if the scan matches against a signature .
* @ param [ out ] scanned The number of bytes scanned .
* @ param engine The scanning engine .
* @ param scanoptions Scanning options .
* @ return cl_error_t CL_CLEAN , CL_VIRUS , or an error code if an error occured during the scan .
*/
2020-03-19 21:23:54 -04:00
extern cl_error_t cl_scandesc ( int desc , const char * filename , const char * * virname , unsigned long int * scanned , const struct cl_engine * engine , struct cl_scan_options * scanoptions ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Scan a file , given a file descriptor .
*
* This callback variant allows the caller to provide a context structure that caller provided callback functions can interpret .
*
* @ param desc File descriptor of an open file . The caller must provide this or the map .
* @ param filename ( optional ) Filepath of the open file descriptor or file map .
* @ param [ out ] virname Will be set to a statically allocated ( i . e . needs not be freed ) signature name if the scan matches against a signature .
* @ param [ out ] scanned The number of bytes scanned .
* @ param engine The scanning engine .
* @ param scanoptions Scanning options .
2021-07-14 15:33:52 -07:00
* @ param [ in , out ] context An opaque context structure allowing the caller to record details about the sample being scanned .
2018-11-16 11:02:15 -08:00
* @ return cl_error_t CL_CLEAN , CL_VIRUS , or an error code if an error occured during the scan .
*/
2020-03-19 21:23:54 -04:00
extern cl_error_t cl_scandesc_callback ( int desc , const char * filename , const char * * virname , unsigned long int * scanned , const struct cl_engine * engine , struct cl_scan_options * scanoptions , void * context ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Scan a file , given a filename .
*
* @ param filename Filepath of the file to be scanned .
* @ param [ out ] virname Will be set to a statically allocated ( i . e . needs not be freed ) signature name if the scan matches against a signature .
* @ param [ out ] scanned The number of bytes scanned .
* @ param engine The scanning engine .
* @ param scanoptions Scanning options .
* @ return cl_error_t CL_CLEAN , CL_VIRUS , or an error code if an error occured during the scan .
*/
2020-03-19 21:23:54 -04:00
extern cl_error_t cl_scanfile ( const char * filename , const char * * virname , unsigned long int * scanned , const struct cl_engine * engine , struct cl_scan_options * scanoptions ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Scan a file , given a filename .
*
* This callback variant allows the caller to provide a context structure that caller provided callback functions can interpret .
*
* @ param filename Filepath of the file to be scanned .
* @ param [ out ] virname Will be set to a statically allocated ( i . e . needs not be freed ) signature name if the scan matches against a signature .
* @ param [ out ] scanned The number of bytes scanned .
* @ param engine The scanning engine .
* @ param scanoptions Scanning options .
2021-07-14 15:33:52 -07:00
* @ param [ in , out ] context An opaque context structure allowing the caller to record details about the sample being scanned .
2018-11-16 11:02:15 -08:00
* @ return cl_error_t CL_CLEAN , CL_VIRUS , or an error code if an error occured during the scan .
*/
2020-03-19 21:23:54 -04:00
extern cl_error_t cl_scanfile_callback ( const char * filename , const char * * virname , unsigned long int * scanned , const struct cl_engine * engine , struct cl_scan_options * scanoptions , void * context ) ;
2018-11-16 11:02:15 -08:00
/* ----------------------------------------------------------------------------
* Database handling .
*/
2021-07-16 11:47:23 -07:00
/**
* @ brief Load the signature databases found at the path .
*
* @ param path May be a file or directory .
* @ param engine The engine to load the signatures into
* @ param [ out ] signo The number of signatures loaded
* @ param dboptions Database load bitflag field . See the CL_DB_ * defines , above .
* @ return cl_error_t
*/
2020-04-18 10:46:57 -04:00
extern cl_error_t cl_load ( const char * path , struct cl_engine * engine , unsigned int * signo , unsigned int dboptions ) ;
2021-07-16 11:47:23 -07:00
/**
* @ brief Get the default database directory path .
*
* @ return const char *
*/
2018-11-16 11:02:15 -08:00
extern const char * cl_retdbdir ( void ) ;
/* ----------------------------------------------------------------------------
* CVD / database functions
*/
2003-07-29 15:48:06 +00:00
2018-12-03 12:40:13 -05:00
struct cl_cvd { /* field no. */
char * time ; /* 2 */
unsigned int version ; /* 3 */
unsigned int sigs ; /* 4 */
unsigned int fl ; /* 5 */
/* padding */
char * md5 ; /* 6 */
char * dsig ; /* 7 */
char * builder ; /* 8 */
unsigned int stime ; /* 9 */
2003-09-29 11:44:52 +00:00
} ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Read the CVD header data from a file .
*
* The returned pointer must be free ' d with cl_cvdfree ( ) .
*
* @ param file Filepath of CVD file .
* @ return struct cl_cvd * Pointer to an allocated CVD header data structure .
*/
2003-09-29 11:44:52 +00:00
extern struct cl_cvd * cl_cvdhead ( const char * file ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Parse the CVD header .
*
* Buffer length is not an argument , and the check must be done
* by the caller cl_cvdhead ( ) .
*
* The returned pointer must be free ' d with cl_cvdfree ( ) .
*
* @ param head Pointer to the header data buffer .
* @ return struct cl_cvd * Pointer to an allocated CVD header data structure .
*/
2003-10-26 06:01:03 +00:00
extern struct cl_cvd * cl_cvdparse ( const char * head ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Verify a CVD file by loading and unloading it .
*
* @ param file Filepath of CVD file .
* @ return cl_error_t CL_SUCCESS if success , else a CL_E * error code .
*/
2020-04-18 10:46:57 -04:00
extern cl_error_t cl_cvdverify ( const char * file ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Free a CVD header struct .
*
* @ param cvd Pointer to a CVD header struct .
*/
2003-09-29 11:44:52 +00:00
extern void cl_cvdfree ( struct cl_cvd * cvd ) ;
2018-11-16 11:02:15 -08:00
/* ----------------------------------------------------------------------------
* DB directory stat functions .
* Use these functions to watch for database changes .
*/
struct cl_stat {
char * dir ;
STATBUF * stattab ;
char * * statdname ;
unsigned int entries ;
} ;
/**
* @ brief Initialize a directory to be watched for database changes .
*
* The dbstat out variable is allocated and must be freed using cl_statfree ( ) .
*
* @ param dirname Pathname of the database directory .
* @ param [ out ] dbstat dbstat handle .
* @ return cl_error_t CL_SUCCESS if successfully initialized .
*/
2020-04-18 10:46:57 -04:00
extern cl_error_t cl_statinidir ( const char * dirname , struct cl_stat * dbstat ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Check the database directory for changes .
*
* @ param dbstat dbstat handle .
* @ return int 0 No change .
* @ return int 1 Some change occured .
*/
2003-07-29 15:48:06 +00:00
extern int cl_statchkdir ( const struct cl_stat * dbstat ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Free the dbstat handle .
*
* @ param dbstat dbstat handle .
* @ return cl_error_t CL_SUCCESS
* @ return cl_error_t CL_ENULLARG
*/
2020-04-18 10:46:57 -04:00
extern cl_error_t cl_statfree ( struct cl_stat * dbstat ) ;
2003-07-29 15:48:06 +00:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Count the number of signatures in a database file or directory .
*
* @ param path Path of the database file or directory .
* @ param countoptions A bitflag field . May be CL_COUNTSIGS_OFFICIAL , CL_COUNTSIGS_UNOFFICIAL , or CL_COUNTSIGS_ALL .
* @ param [ out ] sigs The number of sigs .
* @ return cl_error_t CL_SUCCESS if success , else a CL_E * error type .
*/
2020-04-18 10:46:57 -04:00
extern cl_error_t cl_countsigs ( const char * path , unsigned int countoptions , unsigned int * sigs ) ;
2010-02-12 15:52:19 +01:00
2018-11-16 11:02:15 -08:00
/* ----------------------------------------------------------------------------
* Software versions .
*/
2003-07-29 15:48:06 +00:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Get the Functionality Level ( FLEVEL ) .
*
* @ return unsigned int The FLEVEL .
*/
2006-11-01 16:04:54 +00:00
extern unsigned int cl_retflevel ( void ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Get the ClamAV version string .
*
* E . g . clamav - 0.100 .0 - beta
*
* @ return const char * The version string .
*/
2006-11-01 16:04:54 +00:00
extern const char * cl_retver ( void ) ;
2003-07-29 15:48:06 +00:00
2018-11-16 11:02:15 -08:00
/* ----------------------------------------------------------------------------
* Others .
*/
2004-03-11 08:33:45 +00:00
extern const char * cl_strerror ( int clerror ) ;
2003-07-29 15:48:06 +00:00
2018-11-16 11:02:15 -08:00
/* ----------------------------------------------------------------------------
* Custom data scanning .
*/
2011-06-14 20:19:25 +03:00
struct cl_fmap ;
typedef struct cl_fmap cl_fmap_t ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Read callback function type .
*
* A callback function pointer type for reading data from a cl_fmap_t that uses
* reads data from a handle interface .
*
* Read ' count ' bytes starting at ' offset ' into the buffer ' buf '
*
* Thread safety : It is guaranteed that only one callback is executing for a
* specific handle at any time , but there might be multiple callbacks executing
* for different handle at the same time .
*
* @ param handle The handle passed to cl_fmap_open_handle , its meaning is up
* to the callback ' s implementation
* @ param buf A buffer to read data into , must be at least offset + count
* bytes in size .
* @ param count The number of bytes to read .
* @ param offset The the offset into buf to read the data to . If successful ,
* the number of bytes actually read is returned . Upon reading
* end - of - file , zero is returned . Otherwise , a - 1 is returned
* and the global variable errno is set to indicate the error .
2011-06-14 20:19:25 +03:00
*/
2018-12-03 12:40:13 -05:00
typedef off_t ( * clcb_pread ) ( void * handle , void * buf , size_t count , off_t offset ) ;
2011-06-14 20:19:25 +03:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Open a map given a handle .
*
* Open a map for scanning custom data accessed by a handle and pread ( lseek +
2021-10-03 14:13:55 -07:00
* read ) - like interface . For example a file descriptor or a WIN32 HANDLE .
2011-06-14 20:19:25 +03:00
* By default fmap will use aging to discard old data , unless you tell it not
* to .
2018-11-16 11:02:15 -08:00
*
2011-06-14 20:19:25 +03:00
* The handle will be passed to the callback each time .
2018-11-16 11:02:15 -08:00
*
* @ param handle A handle that may be accessed using lseek + read .
* @ param offset Initial offset to start scanning .
* @ param len Length of the data from the start ( not the offset ) .
* @ param pread_cb A callback function to read data from the handle .
2021-10-03 14:13:55 -07:00
* @ param use_aging Set to a non - zero value to enable aging .
2018-11-16 11:02:15 -08:00
* @ return cl_fmap_t * A map representing the handle interface .
2011-06-14 20:19:25 +03:00
*/
2018-12-03 12:40:13 -05:00
extern cl_fmap_t * cl_fmap_open_handle ( void * handle , size_t offset , size_t len ,
2021-10-03 14:13:55 -07:00
clcb_pread pread_cb , int use_aging ) ;
2011-06-14 20:19:25 +03:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Open a map given a buffer .
*
* Open a map for scanning custom data , where the data is already in memory ,
2011-06-14 20:19:25 +03:00
* either in the form of a buffer , a memory mapped file , etc .
* Note that the memory [ start , start + len ) must be the _entire_ file ,
* you can ' t give it parts of a file and expect detection to work .
2018-11-16 11:02:15 -08:00
*
* @ param start Pointer to a buffer of data .
* @ param len Length in bytes of the data .
* @ return cl_fmap_t * A map representing the buffer .
2011-06-14 20:19:25 +03:00
*/
extern cl_fmap_t * cl_fmap_open_memory ( const void * start , size_t len ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Releases resources associated with the map .
*
* You should release any resources you hold only after ( handles , maps ) calling
* this function .
*
* @ param map Map to be closed .
*/
2018-12-03 12:40:13 -05:00
extern void cl_fmap_close ( cl_fmap_t * ) ;
2011-06-14 20:19:25 +03:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Scan custom data .
*
* @ param map Buffer to be scanned , in form of a cl_fmap_t .
* @ param filename Name of data origin . Does not need to be an actual
* file on disk . May be NULL if a name is not available .
* @ param [ out ] virname Pointer to receive the signature match name name if a
* signature matched .
* @ param [ out ] scanned Number of bytes scanned .
* @ param engine The scanning engine .
* @ param scanoptions The scanning options struct .
* @ param context An application - defined context struct , opaque to
* libclamav . May be used within your callback functions .
* @ return cl_error_t CL_CLEAN if no signature matched . CL_VIRUS if a
* signature matched . Another CL_E * error code if an
* error occured .
*/
2020-03-19 21:23:54 -04:00
extern cl_error_t cl_scanmap_callback ( cl_fmap_t * map , const char * filename , const char * * virname , unsigned long int * scanned , const struct cl_engine * engine , struct cl_scan_options * scanoptions , void * context ) ;
2011-06-14 20:19:25 +03:00
2018-11-16 11:02:15 -08:00
/* ----------------------------------------------------------------------------
* Crypto / hashing functions
*/
2018-08-23 01:05:51 -04:00
# define MD5_HASH_SIZE 16
2014-07-01 19:38:01 -04:00
# define SHA1_HASH_SIZE 20
# define SHA256_HASH_SIZE 32
2018-08-23 23:19:47 -04:00
# define SHA384_HASH_SIZE 48
2018-09-01 23:29:45 -04:00
# define SHA512_HASH_SIZE 64
2014-07-01 19:38:01 -04:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Generate a hash of data .
*
* @ param alg The hashing algorithm to use .
* @ param buf The data to be hashed .
* @ param len The length of the to - be - hashed data .
* @ param [ out ] obuf ( optional ) A buffer to store the generated hash . Use NULL to dynamically allocate buffer .
* @ param [ out ] olen ( optional ) A pointer that stores how long the generated hash is .
* @ return A pointer to the generated hash or obuf if obuf is not NULL .
2014-07-01 19:38:01 -04:00
*/
2014-07-29 10:49:43 -06:00
unsigned char * cl_hash_data ( const char * alg , const void * buf , size_t len , unsigned char * obuf , unsigned int * olen ) ;
2014-07-01 19:38:01 -04:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Generate a hash of a file .
*
* @ param ctx A pointer to the OpenSSL EVP_MD_CTX object .
* @ param fd The file descriptor .
* @ param [ out ] olen ( optional ) The length of the generated hash .
* @ return A pointer to a malloc ' d buffer that holds the generated hash .
2014-07-01 19:38:01 -04:00
*/
unsigned char * cl_hash_file_fd_ctx ( EVP_MD_CTX * ctx , int fd , unsigned int * olen ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Generate a hash of a file .
*
* @ param fd The file descriptor .
* @ param alg The hashing algorithm to use .
* @ param [ out ] olen ( optional ) The length of the generated hash .
* @ return A pointer to a malloc ' d buffer that holds the generated hash .
2014-07-01 19:38:01 -04:00
*/
2014-07-29 10:49:43 -06:00
unsigned char * cl_hash_file_fd ( int fd , const char * alg , unsigned int * olen ) ;
2014-07-01 19:38:01 -04:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Generate a hash of a file .
*
* @ param fp A pointer to a FILE object .
* @ param alg The hashing algorithm to use .
* @ param [ out ] olen ( optional ) The length of the generated hash .
* @ return A pointer to a malloc ' d buffer that holds the generated hash .
2014-07-01 19:38:01 -04:00
*/
2014-07-29 10:49:43 -06:00
unsigned char * cl_hash_file_fp ( FILE * fp , const char * alg , unsigned int * olen ) ;
2014-07-01 19:38:01 -04:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Generate a sha256 hash of data .
*
* @ param buf The data to hash .
* @ param len The length of the to - be - hashed data .
* @ param [ out ] obuf ( optional ) A pointer to store the generated hash . Use NULL to dynamically allocate buffer .
* @ param [ out ] olen ( optional ) The length of the generated hash .
* @ return A pointer to a malloc ' d buffer that holds the generated hash .
2014-07-01 19:38:01 -04:00
*/
unsigned char * cl_sha256 ( const void * buf , size_t len , unsigned char * obuf , unsigned int * olen ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Generate a sha384 hash of data .
*
* @ param buf The data to hash .
* @ param len The length of the to - be - hashed data .
* @ param [ out ] obuf ( optional ) A pointer to store the generated hash . Use NULL to dynamically allocate buffer .
* @ param [ out ] olen ( optional ) The length of the generated hash .
* @ return A pointer to a malloc ' d buffer that holds the generated hash .
2018-08-23 23:19:47 -04:00
*/
unsigned char * cl_sha384 ( const void * buf , size_t len , unsigned char * obuf , unsigned int * olen ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Generate a sha512 hash of data .
*
* @ param buf The data to hash .
* @ param len The length of the to - be - hashed data .
* @ param [ out ] obuf ( optional ) A pointer to store the generated hash . Use NULL to dynamically allocate buffer .
* @ param [ out ] olen ( optional ) The length of the generated hash .
* @ return A pointer to a malloc ' d buffer that holds the generated hash .
2018-09-02 22:07:14 -04:00
*/
unsigned char * cl_sha512 ( const void * buf , size_t len , unsigned char * obuf , unsigned int * olen ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Generate a sha1 hash of data .
*
* @ param buf The data to hash .
* @ param len The length of the to - be - hashed data .
* @ param [ out ] obuf ( optional ) A pointer to store the generated hash . Use NULL to dynamically allocate buffer .
* @ param [ out ] olen ( optional ) The length of the generated hash .
* @ return A pointer to a malloc ' d buffer that holds the generated hash .
2014-07-01 19:38:01 -04:00
*/
unsigned char * cl_sha1 ( const void * buf , size_t len , unsigned char * obuf , unsigned int * olen ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Verify validity of signed data .
*
* @ param pkey The public key of the keypair that signed the data .
* @ param alg The algorithm used to hash the data .
* @ param sig The signature block .
* @ param siglen The length of the signature .
* @ param data The data that was signed .
* @ param datalen The length of the data .
* @ param decode Whether or not to base64 - decode the signature prior to verification . 1 for yes , 0 for no .
* @ return 0 for success , - 1 for error or invalid signature .
2014-07-01 19:38:01 -04:00
*/
2014-07-29 10:49:43 -06:00
int cl_verify_signature ( EVP_PKEY * pkey , const char * alg , unsigned char * sig , unsigned int siglen , unsigned char * data , size_t datalen , int decode ) ;
2014-07-01 19:38:01 -04:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Verify validity of signed data .
*
* @ param pkey The public key of the keypair that signed the data .
* @ param alg The algorithm used to hash the data .
* @ param sig The signature block .
* @ param siglen The length of the signature .
* @ param digest The hash of the signed data .
* @ return 0 for success , - 1 for error or invalid signature .
2014-07-01 19:38:01 -04:00
*/
2014-07-29 10:49:43 -06:00
int cl_verify_signature_hash ( EVP_PKEY * pkey , const char * alg , unsigned char * sig , unsigned int siglen , unsigned char * digest ) ;
2014-07-01 19:38:01 -04:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Verify validity of signed data .
*
* @ param pkey The public key of the keypair that signed the data .
* @ param alg The algorithm used to hash the data .
* @ param sig The signature block .
* @ param siglen The length of the signature .
* @ param fd The file descriptor .
* @ return 0 for success , - 1 for error or invalid signature .
2014-07-01 19:38:01 -04:00
*/
2014-07-29 10:49:43 -06:00
int cl_verify_signature_fd ( EVP_PKEY * pkey , const char * alg , unsigned char * sig , unsigned int siglen , int fd ) ;
2014-07-01 19:38:01 -04:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Verify validity of signed data .
*
* @ param x509path The path to the public key of the keypair that signed the data .
* @ param alg The algorithm used to hash the data .
* @ param sig The signature block .
* @ param siglen The length of the signature .
* @ param digest The hash of the signed data .
* @ return 0 for success , - 1 for error or invalid signature .
2014-07-01 19:38:01 -04:00
*/
2014-07-29 10:49:43 -06:00
int cl_verify_signature_hash_x509_keyfile ( char * x509path , const char * alg , unsigned char * sig , unsigned int siglen , unsigned char * digest ) ;
2014-07-01 19:38:01 -04:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Verify validity of signed data .
*
* @ param x509path The path to the public key of the keypair that signed the data .
* @ param alg The algorithm used to hash the data .
* @ param sig The signature block .
* @ param siglen The length of the signature .
* @ param fd The file descriptor .
* @ return 0 for success , - 1 for error or invalid signature .
2014-07-01 19:38:01 -04:00
*/
2014-07-29 10:49:43 -06:00
int cl_verify_signature_fd_x509_keyfile ( char * x509path , const char * alg , unsigned char * sig , unsigned int siglen , int fd ) ;
2014-07-01 19:38:01 -04:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Verify validity of signed data .
*
* @ param x509path The path to the public key of the keypair that signed the data .
* @ param alg The algorithm used to hash the data .
* @ param sig The signature block .
* @ param siglen The length of the signature .
* @ param data The data that was signed .
* @ param datalen The length of the data .
* @ param decode Whether or not to base64 - decode the signature prior to verification . 1 for yes , 0 for no .
* @ return 0 for success , - 1 for error or invalid signature .
2014-07-01 19:38:01 -04:00
*/
2014-07-29 10:49:43 -06:00
int cl_verify_signature_x509_keyfile ( char * x509path , const char * alg , unsigned char * sig , unsigned int siglen , unsigned char * data , size_t datalen , int decode ) ;
2014-07-01 19:38:01 -04:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Verify validity of signed data
*
* @ param x509 The X509 object of the public key of the keypair that signed the data .
* @ param alg The algorithm used to hash the data .
* @ param sig The signature block .
* @ param siglen The length of the signature .
* @ param digest The hash of the signed data .
* @ return 0 for success , - 1 for error or invalid signature .
2014-07-01 19:38:01 -04:00
*/
2014-07-29 10:49:43 -06:00
int cl_verify_signature_hash_x509 ( X509 * x509 , const char * alg , unsigned char * sig , unsigned int siglen , unsigned char * digest ) ;
2014-07-01 19:38:01 -04:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Verify validity of signed data .
*
* @ param x509 The X509 object of the public key of the keypair that signed the data .
* @ param alg The algorithm used to hash the data .
* @ param sig The signature block .
* @ param siglen The length of the signature .
* @ param fd The file descriptor .
* @ return 0 for success , - 1 for error or invalid signature .
2014-07-01 19:38:01 -04:00
*/
2014-07-29 10:49:43 -06:00
int cl_verify_signature_fd_x509 ( X509 * x509 , const char * alg , unsigned char * sig , unsigned int siglen , int fd ) ;
2014-07-01 19:38:01 -04:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Verify validity of signed data .
*
* @ param x509 The X509 object of the public key of the keypair that signed the data .
* @ param alg The algorithm used to hash the data .
* @ param sig The signature block .
* @ param siglen The length of the signature .
* @ param data The data that was signed .
* @ param datalen The length of the data .
* @ param decode Whether or not to base64 - decode the signature prior to verification . 1 for yes , 0 for no .
* @ return 0 for success , - 1 for error or invalid signature .
2014-07-01 19:38:01 -04:00
*/
2014-07-29 10:49:43 -06:00
int cl_verify_signature_x509 ( X509 * x509 , const char * alg , unsigned char * sig , unsigned int siglen , unsigned char * data , size_t datalen , int decode ) ;
2014-07-01 19:38:01 -04:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Get an X509 object from memory .
*
* @ param data A pointer to a spot in memory that contains the PEM X509 cert .
* @ param len The length of the data .
* @ return A pointer to the X509 object on success , NULL on error .
2014-07-01 19:38:01 -04:00
*/
X509 * cl_get_x509_from_mem ( void * data , unsigned int len ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Validate an X509 certificate chain , with the chain being located in a directory .
*
* @ param tsdir The path to the trust store directory .
* @ param certpath The path to the X509 certificate to be validated .
* @ return 0 for success , - 1 for error or invalid certificate .
2014-07-01 19:38:01 -04:00
*/
int cl_validate_certificate_chain_ts_dir ( char * tsdir , char * certpath ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Validate an X509 certificate chain with support for a CRL .
*
* @ param authorities A NULL - terminated array of strings that hold the path of the CA ' s X509 certificate .
* @ param crlpath ( optional ) A path to the CRL file . NULL if no CRL .
* @ param certpath The path to the X509 certificate to be validated .
* @ return 0 for success , - 1 for error or invalid certificate .
2014-07-01 19:38:01 -04:00
*/
int cl_validate_certificate_chain ( char * * authorities , char * crlpath , char * certpath ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Load an X509 certificate from a file .
*
* @ param certpath The path to the X509 certificate .
2014-07-01 19:38:01 -04:00
*/
X509 * cl_load_cert ( const char * certpath ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Parse an ASN1_TIME object .
*
* @ param timeobj The ASN1_TIME object .
* @ return A pointer to a ( struct tm ) . Adjusted for time zone and daylight savings time .
2014-07-01 19:38:01 -04:00
*/
struct tm * cl_ASN1_GetTimeT ( ASN1_TIME * timeobj ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Load a CRL file into an X509_CRL object .
*
* @ param file The path to the CRL .
* @ return A pointer to an X509_CRL object or NULL on error .
2014-07-01 19:38:01 -04:00
*/
X509_CRL * cl_load_crl ( const char * timeobj ) ;
2018-11-16 11:02:15 -08:00
/**
* @ brief Sign data with a key stored on disk .
*
* @ param keypath The path to the RSA private key .
* @ param alg The hash / signature algorithm to use .
* @ param hash The hash to sign .
* @ param [ out ] olen A pointer that stores the size of the signature .
* @ param Whether or not to base64 - encode the signature . 1 for yes , 0 for no .
* @ return The generated signature .
2014-07-01 19:38:01 -04:00
*/
2014-07-29 10:49:43 -06:00
unsigned char * cl_sign_data_keyfile ( char * keypath , const char * alg , unsigned char * hash , unsigned int * olen , int encode ) ;
2014-07-01 19:38:01 -04:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Sign data with an RSA private key object .
*
* @ param pkey The RSA private key object .
* @ param alg The hash / signature algorithm to use .
* @ param hash The hash to sign .
* @ param [ out ] olen A pointer that stores the size of the signature .
* @ param Whether or not to base64 - encode the signature . 1 for yes , 0 for no .
* @ return The generated signature .
2014-07-01 19:38:01 -04:00
*/
2014-07-29 10:49:43 -06:00
unsigned char * cl_sign_data ( EVP_PKEY * pkey , const char * alg , unsigned char * hash , unsigned int * olen , int encode ) ;
2014-07-01 19:38:01 -04:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Sign a file with an RSA private key object .
*
* @ param fd The file descriptor .
* @ param pkey The RSA private key object .
* @ param alg The hash / signature algorithm to use .
* @ param [ out ] olen A pointer that stores the size of the signature .
* @ param encode Whether or not to base64 - encode the signature . 1 for yes , 0 for no .
* @ return The generated signature .
2014-07-01 19:38:01 -04:00
*/
2014-07-29 10:49:43 -06:00
unsigned char * cl_sign_file_fd ( int fd , EVP_PKEY * pkey , const char * alg , unsigned int * olen , int encode ) ;
2014-07-01 19:38:01 -04:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Sign a file with an RSA private key object .
*
* @ param fp A pointer to a FILE object .
* @ param pkey The RSA private key object .
* @ param alg The hash / signature algorithm to use .
* @ param [ out ] olen A pointer that stores the size of the signature .
* @ param encode Whether or not to base64 - encode the signature . 1 for yes , 0 for no .
* @ return The generated signature .
2014-07-01 19:38:01 -04:00
*/
2014-07-29 10:49:43 -06:00
unsigned char * cl_sign_file_fp ( FILE * fp , EVP_PKEY * pkey , const char * alg , unsigned int * olen , int encode ) ;
2014-07-01 19:38:01 -04:00
2018-11-16 11:02:15 -08:00
/**
* @ brief Get the Private Key stored on disk .
*
* @ param keypath The path on disk where the private key is stored .
* @ return A pointer to the EVP_PKEY object that contains the private key in memory .
2014-07-01 19:38:01 -04:00
*/
EVP_PKEY * cl_get_pkey_file ( char * keypath ) ;
void * cl_hash_init ( const char * alg ) ;
2014-07-28 15:32:27 -06:00
int cl_update_hash ( void * ctx , const void * data , size_t sz ) ;
2014-07-01 19:38:01 -04:00
int cl_finish_hash ( void * ctx , void * buf ) ;
void cl_hash_destroy ( void * ctx ) ;
2003-07-29 15:48:06 +00:00
# ifdef __cplusplus
2005-05-21 00:51:24 +00:00
}
2003-07-29 15:48:06 +00:00
# endif
2018-11-16 11:02:15 -08:00
2006-11-01 16:04:54 +00:00
# endif /* __CLAMAV_H */