Skip to content

Commit d59154e

Browse files
committed
Example Program: Add --disable-cache feature
Also minor fixes to sys.rs and clamav.h formatting
1 parent 5c5456a commit d59154e

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

examples/ex_scan_callbacks.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,8 @@ int main(int argc, char **argv)
12771277
char *hash_out = NULL;
12781278
char *file_type_out = NULL;
12791279

1280+
bool disable_cache = false;
1281+
12801282
int i = 0;
12811283

12821284
const char *help_string =
@@ -1296,6 +1298,7 @@ int main(int argc, char **argv)
12961298
" Corresponding to the interactive scan options.\n"
12971299
"--one-match (-1) : Disable allmatch (stops scans after one match).\n"
12981300
"--gen-json : Generate scan metadata JSON.\n"
1301+
"--disable-cache : Disable caching of clean scan results.\n"
12991302
"\n"
13001303
"Scripted scan options are:\n"
13011304
"%s";
@@ -1332,6 +1335,9 @@ int main(int argc, char **argv)
13321335
} else if (strcmp(argv[i], "--debug") == 0) {
13331336
debug_mode = true;
13341337
printf("Enabling debug mode.\n");
1338+
} else if (strcmp(argv[i], "--disable-cache") == 0) {
1339+
printf("Disabling caching of clean scan results.\n");
1340+
disable_cache = true;
13351341
} else {
13361342
printf("Unknown option: %s\n", argv[i]);
13371343
printf(help_string, argv[0], argv[0], command_list);
@@ -1386,6 +1392,10 @@ int main(int argc, char **argv)
13861392
cl_engine_set_num(engine, CL_ENGINE_MAX_SCANSIZE, 1024 /*MB*/ * 1024 /*KB*/ * 1024 /*bytes*/);
13871393
cl_engine_set_num(engine, CL_ENGINE_MAX_FILESIZE, 1024 /*MB*/ * 1024 /*KB*/ * 1024 /*bytes*/);
13881394

1395+
if (disable_cache) {
1396+
cl_engine_set_num(engine, CL_ENGINE_DISABLE_CACHE, 1); // Disable cache for clean results
1397+
}
1398+
13891399
/*
13901400
* Load signatures.
13911401
* At least 1 signature required to initialize stuff required for scanning.

libclamav/clamav.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ extern "C" {
8787
typedef enum cl_verdict_t {
8888
CL_VERDICT_NOTHING_FOUND = 0, /**< No alerting signatures matched. */
8989
CL_VERDICT_TRUSTED, /**< The scan target has been deemed trusted (e.g. by FP signature or Authenticode). */
90-
CL_VERDICT_STRONG_INDICATOR, /**< One or more strong indicator signatures matched. */
90+
CL_VERDICT_STRONG_INDICATOR, /**< One or more strong indicator signatures matched. */
9191
CL_VERDICT_POTENTIALLY_UNWANTED, /**< One or more potentially unwanted signatures matched. */
9292
} cl_verdict_t;
9393

libclamav_rust/src/sys.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,22 @@ pub struct cl_scan_layer {
129129
_unused: [u8; 0],
130130
}
131131
pub type cl_scan_layer_t = cl_scan_layer;
132-
#[doc = " @brief Callback interface to get access to the current layer using the scan-\n layer abstraction. This grants access to file content and attributes as well\n as those of each ancestor layers (if any).\n\n Called for each processed file including both the top level file (i.e. the\n zeroeth layer) and all contained files (recursively).\n\n @param layer Scan layer (abstraction) for the current layer being scanned.\n Use the `cl_scan_layer_*` functions to access layer data and metadata.\n You may want to use `cl_scan_layer_get_fmap()` to get the file map for the current layer.\n You may also use it to access ancestor layers using `cl_scan_layer_get_parent_layer()`.\n\n @param context The application context pointer passed in to the `cl_scan*()` function.\n\n @return CL_BREAK\n\n Scan aborted by callback (the rest of the scan is skipped).\n This does not mark the file as clean or infected, it just skips the rest of the scan.\n\n @return CL_SUCCESS / CL_CLEAN\n\n File scan will continue.\n\n For CL_SCAN_CALLBACK_ALERT: Means you want to ignore this specific alert and keep scanning.\n This is different than CL_VERIFIED because it does not affect prior or future alerts.\n Return CL_VERIFIED instead if you want to remove prior alerts for this layer and skip\n the rest of the scan for this layer.\n\n @return CL_VIRUS\n\n This will mark the file as infected. A new alert will be added.\n\n For CL_SCAN_CALLBACK_ALERT: Means you agree with the alert (no extra alert needed).\n Remember that CL_SUCCESS means you want to ignore the alert.\n\n @return CL_VERIFIED\n\n Layer explicitly trusted by the callback and previous alerts removed FOR THIS layer.\n You might want to do this if you trust the hash or verified a digital signature.\n The rest of the scan will be skipped FOR THIS layer.\n For contained files, this does NOT mean that the parent or adjacent layers are trusted."]
132+
#[doc = " @brief Callback interface to get access to the current layer using the scan-\n layer abstraction. This grants access to file content and attributes as well\n as those of each ancestor layers (if any).\n\n Called for each processed file including both the top level file (i.e. the\n zeroeth layer) and all contained files (recursively).\n\n @param layer Scan layer (abstraction) for the current layer being scanned.\n Use the `cl_scan_layer_*` functions to access layer data and metadata.\n You may want to use `cl_scan_layer_get_fmap()` to get the file map for the current layer.\n You may also use it to access ancestor layers using `cl_scan_layer_get_parent_layer()`.\n\n @param context The application context pointer passed in to the `cl_scan*()` function.\n\n @return CL_BREAK\n\n Scan aborted by callback (the rest of the scan is skipped).\n This does not mark the file as clean or infected, it just skips the rest of the scan.\n\n @return CL_SUCCESS\n\n File scan will continue.\n\n For CL_SCAN_CALLBACK_ALERT: Means you want to ignore this specific alert and keep scanning.\n This is different than CL_VERIFIED because it does not affect prior or future alerts.\n Return CL_VERIFIED instead if you want to remove prior alerts for this layer and skip\n the rest of the scan for this layer.\n\n @return CL_VIRUS\n\n This will mark the file as infected. A new alert will be added.\n\n For CL_SCAN_CALLBACK_ALERT: Means you agree with the alert (no extra alert needed).\n Remember that CL_SUCCESS means you want to ignore the alert.\n\n @return CL_VERIFIED\n\n Layer explicitly trusted by the callback and previous alerts removed FOR THIS layer.\n You might want to do this if you trust the hash or verified a digital signature.\n The rest of the scan will be skipped FOR THIS layer.\n For contained files, this does NOT mean that the parent or adjacent layers are trusted."]
133133
pub type clcb_scan = ::std::option::Option<
134134
unsafe extern "C" fn(
135135
layer: *mut cl_scan_layer_t,
136136
context: *mut ::std::os::raw::c_void,
137137
) -> cl_error_t,
138138
>;
139-
#[doc = " @brief Pre-cache callback.\n\n @deprecated This function is deprecated and will be removed in a future release.\n Use `CL_SCAN_CALLBACK_PRE_HASH` with `cl_engine_set_scan_callback()` instead.\n\n Called for each processed file (both the entry level - AKA 'outer' - file and\n inner files - those generated when processing archive and container files), before\n the actual scanning takes place.\n\n @param fd File descriptor which is about to be scanned.\n @param type File type detected via magic - i.e. NOT on the fly - (e.g. \"CL_TYPE_MSEXE\").\n @param context Opaque application provided data.\n @return CL_CLEAN = File is scanned.\n @return CL_BREAK = Allowed by callback - file is skipped and marked as clean.\n @return CL_VIRUS = Blocked by callback - file is skipped and marked as infected."]
139+
#[doc = " @brief Pre-cache callback.\n\n @deprecated This function is deprecated and will be removed in a future release.\n Use `CL_SCAN_CALLBACK_PRE_HASH` with `cl_engine_set_scan_callback()` instead.\n\n Called for each processed file (both the entry level - AKA 'outer' - file and\n inner files - those generated when processing archive and container files), before\n the actual scanning takes place.\n\n @param fd File descriptor which is about to be scanned.\n @param type File type detected via magic - i.e. NOT on the fly - (e.g. \"CL_TYPE_MSEXE\").\n @param context Opaque application provided data.\n @return CL_SUCCESS = File is scanned.\n @return CL_BREAK = Allowed by callback - file is skipped and marked as clean.\n @return CL_VIRUS = Blocked by callback - file is skipped and marked as infected."]
140140
pub type clcb_pre_cache = ::std::option::Option<
141141
unsafe extern "C" fn(
142142
fd: ::std::os::raw::c_int,
143143
type_: *const ::std::os::raw::c_char,
144144
context: *mut ::std::os::raw::c_void,
145145
) -> cl_error_t,
146146
>;
147-
#[doc = " @brief File inspection callback.\n\n @deprecated This function is deprecated and will be removed in a future release.\n Use `CL_SCAN_CALLBACK_PRE_SCAN` with `cl_engine_set_scan_callback()` instead.\n\n You can use the `cl_fmap_*` functions to access the file map, file name, file size, file contents,\n and those of each ancestor layers (if any).\n\n Called for each NEW file (inner and outer).\n Provides capability to record embedded file information during a scan.\n\n @param fd Current file descriptor which is about to be scanned.\n @param type Current file type detected via magic - i.e. NOT on the fly - (e.g. \"CL_TYPE_MSEXE\").\n @param ancestors An array of ancestors filenames of size `recursion_level`. filenames may be NULL.\n @param parent_file_size Parent file size.\n @param file_name Current file name, or NULL if the file does not have a name or ClamAV failed to record the name.\n @param file_size Current file size.\n @param file_buffer Current file buffer pointer.\n @param recursion_level Recursion level / depth of the current file.\n @param layer_attributes See LAYER_ATTRIBUTES_* flags.\n @param context Opaque application provided data.\n @return CL_CLEAN = File is scanned.\n @return CL_BREAK = Whitelisted by callback - file is skipped and marked as clean.\n @return CL_VIRUS = Blacklisted by callback - file is skipped and marked as infected."]
147+
#[doc = " @brief File inspection callback.\n\n @deprecated This function is deprecated and will be removed in a future release.\n Use `CL_SCAN_CALLBACK_PRE_SCAN` with `cl_engine_set_scan_callback()` instead.\n\n You can use the `cl_fmap_*` functions to access the file map, file name, file size, file contents,\n and those of each ancestor layers (if any).\n\n Called for each NEW file (inner and outer).\n Provides capability to record embedded file information during a scan.\n\n @param fd Current file descriptor which is about to be scanned.\n @param type Current file type detected via magic - i.e. NOT on the fly - (e.g. \"CL_TYPE_MSEXE\").\n @param ancestors An array of ancestors filenames of size `recursion_level`. filenames may be NULL.\n @param parent_file_size Parent file size.\n @param file_name Current file name, or NULL if the file does not have a name or ClamAV failed to record the name.\n @param file_size Current file size.\n @param file_buffer Current file buffer pointer.\n @param recursion_level Recursion level / depth of the current file.\n @param layer_attributes See LAYER_ATTRIBUTES_* flags.\n @param context Opaque application provided data.\n @return CL_SUCCESS = File is scanned.\n @return CL_BREAK = Whitelisted by callback - file is skipped and marked as clean.\n @return CL_VIRUS = Blacklisted by callback - file is skipped and marked as infected."]
148148
pub type clcb_file_inspection = ::std::option::Option<
149149
unsafe extern "C" fn(
150150
fd: ::std::os::raw::c_int,
@@ -159,15 +159,15 @@ pub type clcb_file_inspection = ::std::option::Option<
159159
context: *mut ::std::os::raw::c_void,
160160
) -> cl_error_t,
161161
>;
162-
#[doc = " @brief Pre-scan callback.\n\n @deprecated This function is deprecated and will be removed in a future release.\n\n Called for each NEW file (inner and outer) before the scanning takes place. This is\n roughly the same as clcb_before_cache, but it is affected by clean file caching.\n This means that it won't be called if a clean cached file (inner or outer) is\n scanned a second time.\n\n @param fd File descriptor which is about to be scanned.\n @param type File type detected via magic - i.e. NOT on the fly - (e.g. \"CL_TYPE_MSEXE\").\n @param context Opaque application provided data.\n @return CL_CLEAN = File is scanned.\n @return CL_BREAK = Allowed by callback - file is skipped and marked as clean.\n @return CL_VIRUS = Blocked by callback - file is skipped and marked as infected."]
162+
#[doc = " @brief Pre-scan callback.\n\n @deprecated This function is deprecated and will be removed in a future release.\n\n Called for each NEW file (inner and outer) before the scanning takes place. This is\n roughly the same as clcb_before_cache, but it is affected by clean file caching.\n This means that it won't be called if a clean cached file (inner or outer) is\n scanned a second time.\n\n @param fd File descriptor which is about to be scanned.\n @param type File type detected via magic - i.e. NOT on the fly - (e.g. \"CL_TYPE_MSEXE\").\n @param context Opaque application provided data.\n @return CL_SUCCESS = File is scanned.\n @return CL_BREAK = Allowed by callback - file is skipped and marked as clean.\n @return CL_VIRUS = Blocked by callback - file is skipped and marked as infected."]
163163
pub type clcb_pre_scan = ::std::option::Option<
164164
unsafe extern "C" fn(
165165
fd: ::std::os::raw::c_int,
166166
type_: *const ::std::os::raw::c_char,
167167
context: *mut ::std::os::raw::c_void,
168168
) -> cl_error_t,
169169
>;
170-
#[doc = " @brief Post-scan callback.\n\n @deprecated This function is deprecated and will be removed in a future release.\n Use `CL_SCAN_CALLBACK_PRE_SCAN` with `cl_engine_set_scan_callback()` instead.\n\n Called for each processed file (inner and outer), after the scanning is complete.\n In all-match mode, the virname will be one of the matches, but there is no\n guarantee in which order the matches will occur, thus the final virname may\n be any one of the matches.\n\n @param fd File descriptor which was scanned.\n @param result The scan result for the file.\n @param virname A signature name if there was one or more matches.\n @param context Opaque application provided data.\n @return Scan result is not overridden.\n @return CL_BREAK = Allowed by callback - scan result is set to CL_CLEAN.\n @return Blocked by callback - scan result is set to CL_VIRUS."]
170+
#[doc = " @brief Post-scan callback.\n\n @deprecated This function is deprecated and will be removed in a future release.\n Use `CL_SCAN_CALLBACK_PRE_SCAN` with `cl_engine_set_scan_callback()` instead.\n\n Called for each processed file (inner and outer), after the scanning is complete.\n In all-match mode, the virname will be one of the matches, but there is no\n guarantee in which order the matches will occur, thus the final virname may\n be any one of the matches.\n\n @param fd File descriptor which was scanned.\n @param result The scan result for the file.\n @param virname A signature name if there was one or more matches.\n @param context Opaque application provided data.\n @return CL_SUCCESS = File is scanned.\n @return CL_BREAK = Allowed by callback - file is skipped and marked as clean.\n @return CL_VIRUS = Blocked by callback - file is skipped and marked as infected."]
171171
pub type clcb_post_scan = ::std::option::Option<
172172
unsafe extern "C" fn(
173173
fd: ::std::os::raw::c_int,
@@ -211,7 +211,7 @@ pub type clcb_hash = ::std::option::Option<
211211
context: *mut ::std::os::raw::c_void,
212212
),
213213
>;
214-
#[doc = " @brief Archive meta matching callback function.\n\n May be used to block archive/container samples based on archive metadata.\n Function is invoked multiple times per archive. Typically once per contained file.\n\n Note: Used by the --archive-verbose clamscan option. Overriding this will alter\n the output from --archive-verbose.\n\n @param container_type String name of type (CL_TYPE).\n @param fsize_container Sample size\n @param filename Filename associated with the data in archive.\n @param fsize_real Size of file after decompression (according to the archive).\n @param is_encrypted Boolean non-zero if the contained file is encrypted.\n @param filepos_container File index in container.\n @param context Opaque application provided data.\n @return CL_VIRUS to block (alert on)\n @return CL_CLEAN to continue scanning"]
214+
#[doc = " @brief Archive meta matching callback function.\n\n May be used to block archive/container samples based on archive metadata.\n Function is invoked multiple times per archive. Typically once per contained file.\n\n Note: Used by the --archive-verbose clamscan option. Overriding this will alter\n the output from --archive-verbose.\n\n @param container_type String name of type (CL_TYPE).\n @param fsize_container Sample size\n @param filename Filename associated with the data in archive.\n @param fsize_real Size of file after decompression (according to the archive).\n @param is_encrypted Boolean non-zero if the contained file is encrypted.\n @param filepos_container File index in container.\n @param context Opaque application provided data.\n @return CL_VIRUS to block (alert on)\n @return CL_SUCCESS to continue scanning"]
215215
pub type clcb_meta = ::std::option::Option<
216216
unsafe extern "C" fn(
217217
container_type: *const ::std::os::raw::c_char,

0 commit comments

Comments
 (0)