mirror of
https://github.com/Cisco-Talos/clamav.git
synced 2025-10-19 10:23:17 +00:00

Change the clean-cache to use SHA2-256 instead of MD5. Note that all references are changed to specify "SHA2-256" now instead of "SHA256", for clarity. But there is no plan to add support for SHA3 algorithms at this time. Significant code cleanup. E.g.: - Implemented goto-done error handling. - Used `uint8_t *` instead of `unsigned char *`. - Use `bool` for boolean checks, rather than `int. - Used `#defines` instead of magic numbers. - Removed duplicate `#defines` for things like hash length. Add new option to calculate and record additional hash types when the "generate metadata JSON" feature is enabled: - libclamav option: `CL_SCAN_GENERAL_STORE_EXTRA_HASHES` - clamscan option: `--json-store-extra-hashes` (default off) - clamd.conf option: `JsonStoreExtraHashes` (default 'no') Renamed the sigtool option `--sha256` to `--sha2-256`. The original option is still functional, but is deprecated. For the "generate metadata JSON" feature, the file hash is now stored as "sha2-256" instead of "FileMD5". If you enable the "extra hashes" option, then it will also record "md5" and "sha1". Deprecate and disable the internal "SHA collect" feature. This option had been hidden behind C #ifdef checks for an option that wasn't exposed through CMake, so it was basically unavailable anyways. Changes to calculate file hashes when they're needed and no sooner. For the FP feature in the matcher module, I have mimiced the optimization in the FMAP scan routine which makes it so that it can calculate multiple hashes in a single pass of the file. The `HandlerType` feature stores a hash of the file in the scan ctx to prevent retyping the exact same data more than once. I removed that hash field and replaced it with an attribute flag that is applied to the new recursion stack layer when retyping a file. This also closes a minor bug that would prevent retyping a file with an all-zero hash. :) The work upgrading cache.c to support SHA2-256 sized hashes thanks to: https://github.com/m-sola CLAM-255 CLAM-1858 CLAM-1859 CLAM-1860
76 lines
2.5 KiB
C
76 lines
2.5 KiB
C
/*
|
|
* Copyright (C) 2013-2025 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
|
|
* Copyright (C) 2007-2013 Sourcefire, Inc.
|
|
*
|
|
* Authors: Tomasz Kojm, Török Edvin
|
|
*
|
|
* 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 __SCANNER_H
|
|
#define __SCANNER_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
// libclamav
|
|
#include "clamav.h"
|
|
#include "others.h"
|
|
|
|
// common
|
|
#include "optparser.h"
|
|
|
|
#include "thrmgr.h"
|
|
#include "session.h"
|
|
|
|
enum scan_type { TYPE_INIT = -1,
|
|
TYPE_SCAN = 0,
|
|
TYPE_CONTSCAN = 1,
|
|
TYPE_MULTISCAN = 2 };
|
|
|
|
struct scan_cb_data {
|
|
int scantype;
|
|
int odesc;
|
|
int type;
|
|
int infected;
|
|
int errors;
|
|
int total;
|
|
int id;
|
|
const client_conn_t *conn;
|
|
const char *toplevel_path;
|
|
unsigned long scanned;
|
|
struct cl_scan_options *options;
|
|
struct cl_engine *engine;
|
|
const struct optstruct *opts;
|
|
threadpool_t *thr_pool;
|
|
jobgroup_t *group;
|
|
dev_t dev;
|
|
};
|
|
|
|
struct cb_context {
|
|
const char *filename;
|
|
unsigned long long virsize;
|
|
char virhash[33];
|
|
struct scan_cb_data *scandata;
|
|
};
|
|
|
|
cl_error_t scanfd(const client_conn_t *conn, unsigned long int *scanned, const struct cl_engine *engine, struct cl_scan_options *options, const struct optstruct *opts, int odesc, int stream);
|
|
int scanstream(int odesc, unsigned long int *scanned, const struct cl_engine *engine, struct cl_scan_options *options, const struct optstruct *opts, char term);
|
|
cl_error_t scan_callback(STATBUF *sb, char *filename, const char *msg, enum cli_ftw_reason reason, struct cli_ftw_cbdata *data);
|
|
int scan_pathchk(const char *path, struct cli_ftw_cbdata *data);
|
|
void hash_callback(int fd, unsigned long long size, const char *md5, const char *virname, void *ctx);
|
|
void msg_callback(enum cl_msg severity, const char *fullmsg, const char *msg, void *ctx);
|
|
void clamd_virus_found_cb(int fd, const char *virname, void *context);
|
|
|
|
#endif
|