2003-07-29 15:48:06 +00:00
|
|
|
/*
|
2020-01-03 15:44:07 -05:00
|
|
|
* Copyright (C) 2013-2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
|
2019-01-25 10:15:50 -05:00
|
|
|
* Copyright (C) 2007-2013 Sourcefire, Inc.
|
2009-02-13 10:55:45 +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
|
|
|
*/
|
|
|
|
|
2004-02-06 13:46:08 +00:00
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
#include "clamav-config.h"
|
|
|
|
#endif
|
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2008-07-30 15:20:30 +00:00
|
|
|
#include <signal.h>
|
2020-08-21 20:20:36 -07:00
|
|
|
#include <locale.h>
|
2008-07-30 15:20:30 +00:00
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2003-07-29 15:48:06 +00:00
|
|
|
#include <unistd.h>
|
2007-02-25 02:54:38 +00:00
|
|
|
#endif
|
2009-09-24 19:23:21 +02:00
|
|
|
#ifndef _WIN32
|
2003-07-29 15:48:06 +00:00
|
|
|
#include <sys/time.h>
|
2007-02-25 02:54:38 +00:00
|
|
|
#endif
|
2003-07-29 15:48:06 +00:00
|
|
|
#include <time.h>
|
2007-01-30 21:11:32 +00:00
|
|
|
#ifdef C_LINUX
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#endif
|
2003-07-29 15:48:06 +00:00
|
|
|
|
Add CMake build tooling
This patch adds experimental-quality CMake build tooling.
The libmspack build required a modification to use "" instead of <> for
header #includes. This will hopefully be included in the libmspack
upstream project when adding CMake build tooling to libmspack.
Removed use of libltdl when using CMake.
Flex & Bison are now required to build.
If -DMAINTAINER_MODE, then GPERF is also required, though it currently
doesn't actually do anything. TODO!
I found that the autotools build system was generating the lexer output
but not actually compiling it, instead using previously generated (and
manually renamed) lexer c source. As a consequence, changes to the .l
and .y files weren't making it into the build. To resolve this, I
removed generated flex/bison files and fixed the tooling to use the
freshly generated files. Flex and bison are now required build tools.
On Windows, this adds a dependency on the winflexbison package,
which can be obtained using Chocolatey or may be manually installed.
CMake tooling only has partial support for building with external LLVM
library, and no support for the internal LLVM (to be removed in the
future). I.e. The CMake build currently only supports the bytecode
interpreter.
Many files used include paths relative to the top source directory or
relative to the current project, rather than relative to each build
target. Modern CMake support requires including internal dependency
headers the same way you would external dependency headers (albeit
with "" instead of <>). This meant correcting all header includes to
be relative to the build targets and not relative to the workspace.
For example, ...
```c
include "../libclamav/clamav.h"
include "clamd/clamd_others.h"
```
... becomes:
```c
// libclamav
include "clamav.h"
// clamd
include "clamd_others.h"
```
Fixes header name conflicts by renaming a few of the files.
Converted the "shared" code into a static library, which depends on
libclamav. The ironically named "shared" static library provides
features common to the ClamAV apps which are not required in
libclamav itself and are not intended for use by downstream projects.
This change was required for correct modern CMake practices but was
also required to use the automake "subdir-objects" option.
This eliminates warnings when running autoreconf which, in the next
version of autoconf & automake are likely to break the build.
libclamav used to build in multiple stages where an earlier stage is
a static library containing utils required by the "shared" code.
Linking clamdscan and clamdtop with this libclamav utils static lib
allowed these two apps to function without libclamav. While this is
nice in theory, the practical gains are minimal and it complicates
the build system. As such, the autotools and CMake tooling was
simplified for improved maintainability and this feature was thrown
out. clamdtop and clamdscan now require libclamav to function.
Removed the nopthreads version of the autotools
libclamav_internal_utils static library and added pthread linking to
a couple apps that may have issues building on some platforms without
it, with the intention of removing needless complexity from the
source. Kept the regular version of libclamav_internal_utils.la
though it is no longer used anywhere but in libclamav.
Added an experimental doxygen build option which attempts to build
clamav.h and libfreshclam doxygen html docs.
The CMake build tooling also may build the example program(s), which
isn't a feature in the Autotools build system.
Changed C standard to C90+ due to inline linking issues with socket.h
when linking libfreshclam.so on Linux.
Generate common.rc for win32.
Fix tabs/spaces in shared Makefile.am, and remove vestigial ifndef
from misc.c.
Add CMake files to the automake dist, so users can try the new
CMake tooling w/out having to build from a git clone.
clamonacc changes:
- Renamed FANOTIFY macro to HAVE_SYS_FANOTIFY_H to better match other
similar macros.
- Added a new clamav-clamonacc.service systemd unit file, based on
the work of ChadDevOps & Aaron Brighton.
- Added missing clamonacc man page.
Updates to clamdscan man page, add missing options.
Remove vestigial CL_NOLIBCLAMAV definitions (all apps now use
libclamav).
Rename Windows mspack.dll to libmspack.dll so all ClamAV-built
libraries have the lib-prefix with Visual Studio as with CMake.
2020-08-13 00:25:34 -07:00
|
|
|
// libclamav
|
|
|
|
#include "clamav.h"
|
2003-07-29 15:48:06 +00:00
|
|
|
#include "others.h"
|
Add CMake build tooling
This patch adds experimental-quality CMake build tooling.
The libmspack build required a modification to use "" instead of <> for
header #includes. This will hopefully be included in the libmspack
upstream project when adding CMake build tooling to libmspack.
Removed use of libltdl when using CMake.
Flex & Bison are now required to build.
If -DMAINTAINER_MODE, then GPERF is also required, though it currently
doesn't actually do anything. TODO!
I found that the autotools build system was generating the lexer output
but not actually compiling it, instead using previously generated (and
manually renamed) lexer c source. As a consequence, changes to the .l
and .y files weren't making it into the build. To resolve this, I
removed generated flex/bison files and fixed the tooling to use the
freshly generated files. Flex and bison are now required build tools.
On Windows, this adds a dependency on the winflexbison package,
which can be obtained using Chocolatey or may be manually installed.
CMake tooling only has partial support for building with external LLVM
library, and no support for the internal LLVM (to be removed in the
future). I.e. The CMake build currently only supports the bytecode
interpreter.
Many files used include paths relative to the top source directory or
relative to the current project, rather than relative to each build
target. Modern CMake support requires including internal dependency
headers the same way you would external dependency headers (albeit
with "" instead of <>). This meant correcting all header includes to
be relative to the build targets and not relative to the workspace.
For example, ...
```c
include "../libclamav/clamav.h"
include "clamd/clamd_others.h"
```
... becomes:
```c
// libclamav
include "clamav.h"
// clamd
include "clamd_others.h"
```
Fixes header name conflicts by renaming a few of the files.
Converted the "shared" code into a static library, which depends on
libclamav. The ironically named "shared" static library provides
features common to the ClamAV apps which are not required in
libclamav itself and are not intended for use by downstream projects.
This change was required for correct modern CMake practices but was
also required to use the automake "subdir-objects" option.
This eliminates warnings when running autoreconf which, in the next
version of autoconf & automake are likely to break the build.
libclamav used to build in multiple stages where an earlier stage is
a static library containing utils required by the "shared" code.
Linking clamdscan and clamdtop with this libclamav utils static lib
allowed these two apps to function without libclamav. While this is
nice in theory, the practical gains are minimal and it complicates
the build system. As such, the autotools and CMake tooling was
simplified for improved maintainability and this feature was thrown
out. clamdtop and clamdscan now require libclamav to function.
Removed the nopthreads version of the autotools
libclamav_internal_utils static library and added pthread linking to
a couple apps that may have issues building on some platforms without
it, with the intention of removing needless complexity from the
source. Kept the regular version of libclamav_internal_utils.la
though it is no longer used anywhere but in libclamav.
Added an experimental doxygen build option which attempts to build
clamav.h and libfreshclam doxygen html docs.
The CMake build tooling also may build the example program(s), which
isn't a feature in the Autotools build system.
Changed C standard to C90+ due to inline linking issues with socket.h
when linking libfreshclam.so on Linux.
Generate common.rc for win32.
Fix tabs/spaces in shared Makefile.am, and remove vestigial ifndef
from misc.c.
Add CMake files to the automake dist, so users can try the new
CMake tooling w/out having to build from a git clone.
clamonacc changes:
- Renamed FANOTIFY macro to HAVE_SYS_FANOTIFY_H to better match other
similar macros.
- Added a new clamav-clamonacc.service systemd unit file, based on
the work of ChadDevOps & Aaron Brighton.
- Added missing clamonacc man page.
Updates to clamdscan man page, add missing options.
Remove vestigial CL_NOLIBCLAMAV definitions (all apps now use
libclamav).
Rename Windows mspack.dll to libmspack.dll so all ClamAV-built
libraries have the lib-prefix with Visual Studio as with CMake.
2020-08-13 00:25:34 -07:00
|
|
|
#include "str.h"
|
2004-03-29 00:00:58 +00:00
|
|
|
|
Add CMake build tooling
This patch adds experimental-quality CMake build tooling.
The libmspack build required a modification to use "" instead of <> for
header #includes. This will hopefully be included in the libmspack
upstream project when adding CMake build tooling to libmspack.
Removed use of libltdl when using CMake.
Flex & Bison are now required to build.
If -DMAINTAINER_MODE, then GPERF is also required, though it currently
doesn't actually do anything. TODO!
I found that the autotools build system was generating the lexer output
but not actually compiling it, instead using previously generated (and
manually renamed) lexer c source. As a consequence, changes to the .l
and .y files weren't making it into the build. To resolve this, I
removed generated flex/bison files and fixed the tooling to use the
freshly generated files. Flex and bison are now required build tools.
On Windows, this adds a dependency on the winflexbison package,
which can be obtained using Chocolatey or may be manually installed.
CMake tooling only has partial support for building with external LLVM
library, and no support for the internal LLVM (to be removed in the
future). I.e. The CMake build currently only supports the bytecode
interpreter.
Many files used include paths relative to the top source directory or
relative to the current project, rather than relative to each build
target. Modern CMake support requires including internal dependency
headers the same way you would external dependency headers (albeit
with "" instead of <>). This meant correcting all header includes to
be relative to the build targets and not relative to the workspace.
For example, ...
```c
include "../libclamav/clamav.h"
include "clamd/clamd_others.h"
```
... becomes:
```c
// libclamav
include "clamav.h"
// clamd
include "clamd_others.h"
```
Fixes header name conflicts by renaming a few of the files.
Converted the "shared" code into a static library, which depends on
libclamav. The ironically named "shared" static library provides
features common to the ClamAV apps which are not required in
libclamav itself and are not intended for use by downstream projects.
This change was required for correct modern CMake practices but was
also required to use the automake "subdir-objects" option.
This eliminates warnings when running autoreconf which, in the next
version of autoconf & automake are likely to break the build.
libclamav used to build in multiple stages where an earlier stage is
a static library containing utils required by the "shared" code.
Linking clamdscan and clamdtop with this libclamav utils static lib
allowed these two apps to function without libclamav. While this is
nice in theory, the practical gains are minimal and it complicates
the build system. As such, the autotools and CMake tooling was
simplified for improved maintainability and this feature was thrown
out. clamdtop and clamdscan now require libclamav to function.
Removed the nopthreads version of the autotools
libclamav_internal_utils static library and added pthread linking to
a couple apps that may have issues building on some platforms without
it, with the intention of removing needless complexity from the
source. Kept the regular version of libclamav_internal_utils.la
though it is no longer used anywhere but in libclamav.
Added an experimental doxygen build option which attempts to build
clamav.h and libfreshclam doxygen html docs.
The CMake build tooling also may build the example program(s), which
isn't a feature in the Autotools build system.
Changed C standard to C90+ due to inline linking issues with socket.h
when linking libfreshclam.so on Linux.
Generate common.rc for win32.
Fix tabs/spaces in shared Makefile.am, and remove vestigial ifndef
from misc.c.
Add CMake files to the automake dist, so users can try the new
CMake tooling w/out having to build from a git clone.
clamonacc changes:
- Renamed FANOTIFY macro to HAVE_SYS_FANOTIFY_H to better match other
similar macros.
- Added a new clamav-clamonacc.service systemd unit file, based on
the work of ChadDevOps & Aaron Brighton.
- Added missing clamonacc man page.
Updates to clamdscan man page, add missing options.
Remove vestigial CL_NOLIBCLAMAV definitions (all apps now use
libclamav).
Rename Windows mspack.dll to libmspack.dll so all ClamAV-built
libraries have the lib-prefix with Visual Studio as with CMake.
2020-08-13 00:25:34 -07:00
|
|
|
// shared
|
|
|
|
#include "misc.h"
|
|
|
|
#include "output.h"
|
|
|
|
#include "actions.h"
|
|
|
|
#include "optparser.h"
|
2003-11-09 19:26:44 +00:00
|
|
|
|
Add CMake build tooling
This patch adds experimental-quality CMake build tooling.
The libmspack build required a modification to use "" instead of <> for
header #includes. This will hopefully be included in the libmspack
upstream project when adding CMake build tooling to libmspack.
Removed use of libltdl when using CMake.
Flex & Bison are now required to build.
If -DMAINTAINER_MODE, then GPERF is also required, though it currently
doesn't actually do anything. TODO!
I found that the autotools build system was generating the lexer output
but not actually compiling it, instead using previously generated (and
manually renamed) lexer c source. As a consequence, changes to the .l
and .y files weren't making it into the build. To resolve this, I
removed generated flex/bison files and fixed the tooling to use the
freshly generated files. Flex and bison are now required build tools.
On Windows, this adds a dependency on the winflexbison package,
which can be obtained using Chocolatey or may be manually installed.
CMake tooling only has partial support for building with external LLVM
library, and no support for the internal LLVM (to be removed in the
future). I.e. The CMake build currently only supports the bytecode
interpreter.
Many files used include paths relative to the top source directory or
relative to the current project, rather than relative to each build
target. Modern CMake support requires including internal dependency
headers the same way you would external dependency headers (albeit
with "" instead of <>). This meant correcting all header includes to
be relative to the build targets and not relative to the workspace.
For example, ...
```c
include "../libclamav/clamav.h"
include "clamd/clamd_others.h"
```
... becomes:
```c
// libclamav
include "clamav.h"
// clamd
include "clamd_others.h"
```
Fixes header name conflicts by renaming a few of the files.
Converted the "shared" code into a static library, which depends on
libclamav. The ironically named "shared" static library provides
features common to the ClamAV apps which are not required in
libclamav itself and are not intended for use by downstream projects.
This change was required for correct modern CMake practices but was
also required to use the automake "subdir-objects" option.
This eliminates warnings when running autoreconf which, in the next
version of autoconf & automake are likely to break the build.
libclamav used to build in multiple stages where an earlier stage is
a static library containing utils required by the "shared" code.
Linking clamdscan and clamdtop with this libclamav utils static lib
allowed these two apps to function without libclamav. While this is
nice in theory, the practical gains are minimal and it complicates
the build system. As such, the autotools and CMake tooling was
simplified for improved maintainability and this feature was thrown
out. clamdtop and clamdscan now require libclamav to function.
Removed the nopthreads version of the autotools
libclamav_internal_utils static library and added pthread linking to
a couple apps that may have issues building on some platforms without
it, with the intention of removing needless complexity from the
source. Kept the regular version of libclamav_internal_utils.la
though it is no longer used anywhere but in libclamav.
Added an experimental doxygen build option which attempts to build
clamav.h and libfreshclam doxygen html docs.
The CMake build tooling also may build the example program(s), which
isn't a feature in the Autotools build system.
Changed C standard to C90+ due to inline linking issues with socket.h
when linking libfreshclam.so on Linux.
Generate common.rc for win32.
Fix tabs/spaces in shared Makefile.am, and remove vestigial ifndef
from misc.c.
Add CMake files to the automake dist, so users can try the new
CMake tooling w/out having to build from a git clone.
clamonacc changes:
- Renamed FANOTIFY macro to HAVE_SYS_FANOTIFY_H to better match other
similar macros.
- Added a new clamav-clamonacc.service systemd unit file, based on
the work of ChadDevOps & Aaron Brighton.
- Added missing clamonacc man page.
Updates to clamdscan man page, add missing options.
Remove vestigial CL_NOLIBCLAMAV definitions (all apps now use
libclamav).
Rename Windows mspack.dll to libmspack.dll so all ClamAV-built
libraries have the lib-prefix with Visual Studio as with CMake.
2020-08-13 00:25:34 -07:00
|
|
|
#include "global.h"
|
|
|
|
#include "manager.h"
|
2008-02-08 17:50:44 +00:00
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
void help(void);
|
|
|
|
|
2007-01-30 21:11:32 +00:00
|
|
|
struct s_info info;
|
2012-08-10 11:39:48 -04:00
|
|
|
short recursion = 0, bell = 0;
|
|
|
|
short printinfected = 0, printclean = 1;
|
2004-03-30 21:11:25 +00:00
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
int main(int argc, char **argv)
|
2003-07-29 15:48:06 +00:00
|
|
|
{
|
2018-12-03 12:40:13 -05:00
|
|
|
int ds, dms, ret;
|
|
|
|
double mb, rmb;
|
|
|
|
struct timeval t1, t2;
|
2020-01-03 15:53:29 -05:00
|
|
|
time_t date_start, date_end;
|
2019-11-03 17:05:25 -05:00
|
|
|
|
2019-09-16 13:43:02 -07:00
|
|
|
char buffer[26];
|
2009-09-24 19:23:21 +02:00
|
|
|
#ifndef _WIN32
|
2018-12-03 12:40:13 -05:00
|
|
|
sigset_t sigset;
|
2007-02-25 02:54:38 +00:00
|
|
|
#endif
|
2018-12-03 12:40:13 -05:00
|
|
|
struct optstruct *opts;
|
|
|
|
const struct optstruct *opt;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2018-07-30 20:19:28 -04:00
|
|
|
if (check_flevel())
|
2018-12-03 12:40:13 -05:00
|
|
|
exit(2);
|
2010-05-10 17:05:16 +02:00
|
|
|
|
2020-08-21 20:20:36 -07:00
|
|
|
#if !defined(_WIN32)
|
|
|
|
if(!setlocale(LC_CTYPE, "")) {
|
|
|
|
mprintf("^Failed to set locale\n");
|
|
|
|
}
|
|
|
|
#if !defined(C_BEOS)
|
2008-07-30 15:20:30 +00:00
|
|
|
sigemptyset(&sigset);
|
|
|
|
sigaddset(&sigset, SIGXFSZ);
|
|
|
|
sigprocmask(SIG_SETMASK, &sigset, NULL);
|
2020-08-21 20:20:36 -07:00
|
|
|
#endif /* !C_BEOS */
|
|
|
|
#endif /* !_WIN32 */
|
2008-07-30 15:20:30 +00:00
|
|
|
|
2014-03-07 14:09:46 -05:00
|
|
|
cl_initialize_crypto();
|
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
if ((opts = optparse(NULL, argc, argv, 1, OPT_CLAMSCAN, 0, NULL)) == NULL) {
|
|
|
|
mprintf("!Can't parse command line options\n");
|
|
|
|
return 2;
|
2006-05-15 18:30:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
if (optget(opts, "verbose")->enabled) {
|
|
|
|
mprintf_verbose = 1;
|
|
|
|
logg_verbose = 1;
|
2004-03-29 00:00:58 +00:00
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
if (optget(opts, "quiet")->enabled)
|
|
|
|
mprintf_quiet = 1;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
if (optget(opts, "stdout")->enabled)
|
|
|
|
mprintf_stdout = 1;
|
2006-05-15 18:30:18 +00:00
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
if (optget(opts, "debug")->enabled) {
|
2003-11-09 19:26:44 +00:00
|
|
|
#if defined(C_LINUX)
|
2018-12-03 12:40:13 -05:00
|
|
|
/* njh@bandsman.co.uk: create a dump if needed */
|
|
|
|
struct rlimit rlim;
|
2003-11-09 19:26:44 +00:00
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY;
|
|
|
|
if (setrlimit(RLIMIT_CORE, &rlim) < 0)
|
|
|
|
perror("setrlimit");
|
2003-11-09 19:26:44 +00:00
|
|
|
#endif
|
2018-12-03 12:40:13 -05:00
|
|
|
cl_debug(); /* enable debug messages */
|
2003-11-09 19:26:44 +00:00
|
|
|
}
|
2003-08-02 22:37:52 +00:00
|
|
|
|
2013-10-09 15:57:56 -04:00
|
|
|
if (optget(opts, "gen-mdb")->enabled) {
|
|
|
|
cl_always_gen_section_hash();
|
|
|
|
}
|
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
if (optget(opts, "version")->enabled) {
|
|
|
|
print_version(optget(opts, "database")->strarg);
|
|
|
|
optfree(opts);
|
|
|
|
return 0;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
if (optget(opts, "help")->enabled) {
|
|
|
|
optfree(opts);
|
|
|
|
help();
|
|
|
|
return 0;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
if (optget(opts, "recursive")->enabled)
|
|
|
|
recursion = 1;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
if (optget(opts, "infected")->enabled)
|
|
|
|
printinfected = 1;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
if (optget(opts, "suppress-ok-results")->enabled)
|
|
|
|
printclean = 0;
|
2012-08-10 11:39:48 -04:00
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
if (optget(opts, "bell")->enabled)
|
|
|
|
bell = 1;
|
2004-01-09 01:10:52 +00:00
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
/* initialize logger */
|
2018-12-03 12:40:13 -05:00
|
|
|
if ((opt = optget(opts, "log"))->enabled) {
|
|
|
|
logg_file = opt->strarg;
|
|
|
|
if (logg("#\n-------------------------------------------------------------------------------\n\n")) {
|
|
|
|
mprintf("!Problem with internal logger.\n");
|
|
|
|
optfree(opts);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
logg_file = NULL;
|
|
|
|
|
|
|
|
if (actsetup(opts)) {
|
|
|
|
optfree(opts);
|
|
|
|
logg_close();
|
|
|
|
exit(2);
|
2009-02-12 15:14:12 +00:00
|
|
|
}
|
2006-05-15 18:30:18 +00:00
|
|
|
|
2007-01-30 21:11:32 +00:00
|
|
|
memset(&info, 0, sizeof(struct s_info));
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2020-01-03 15:53:29 -05:00
|
|
|
date_start = time(NULL);
|
2009-10-12 23:38:38 +02:00
|
|
|
gettimeofday(&t1, NULL);
|
2007-02-25 02:54:38 +00:00
|
|
|
|
2008-12-30 10:33:43 +00:00
|
|
|
ret = scanmanager(opts);
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
if (!optget(opts, "no-summary")->enabled) {
|
2020-01-03 15:53:29 -05:00
|
|
|
struct tm tmp;
|
2018-12-03 12:40:13 -05:00
|
|
|
|
2020-01-03 15:53:29 -05:00
|
|
|
date_end = time(NULL);
|
2019-11-03 17:05:25 -05:00
|
|
|
gettimeofday(&t2, NULL);
|
2018-12-03 12:40:13 -05:00
|
|
|
ds = t2.tv_sec - t1.tv_sec;
|
|
|
|
dms = t2.tv_usec - t1.tv_usec;
|
|
|
|
ds -= (dms < 0) ? (1) : (0);
|
|
|
|
dms += (dms < 0) ? (1000000) : (0);
|
|
|
|
logg("\n----------- SCAN SUMMARY -----------\n");
|
|
|
|
logg("Known viruses: %u\n", info.sigs);
|
|
|
|
logg("Engine version: %s\n", get_version());
|
|
|
|
logg("Scanned directories: %u\n", info.dirs);
|
|
|
|
logg("Scanned files: %u\n", info.files);
|
|
|
|
logg("Infected files: %u\n", info.ifiles);
|
|
|
|
if (info.errors)
|
|
|
|
logg("Total errors: %u\n", info.errors);
|
|
|
|
if (notremoved) {
|
|
|
|
logg("Not removed: %u\n", notremoved);
|
|
|
|
}
|
|
|
|
if (notmoved) {
|
|
|
|
logg("Not %s: %u\n", optget(opts, "copy")->enabled ? "moved" : "copied", notmoved);
|
|
|
|
}
|
|
|
|
mb = info.blocks * (CL_COUNT_PRECISION / 1024) / 1024.0;
|
|
|
|
logg("Data scanned: %2.2lf MB\n", mb);
|
|
|
|
rmb = info.rblocks * (CL_COUNT_PRECISION / 1024) / 1024.0;
|
|
|
|
logg("Data read: %2.2lf MB (ratio %.2f:1)\n", rmb, info.rblocks ? (double)info.blocks / (double)info.rblocks : 0);
|
|
|
|
logg("Time: %u.%3.3u sec (%u m %u s)\n", ds, dms / 1000, ds / 60, ds % 60);
|
2019-11-03 17:05:25 -05:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2020-01-03 15:53:29 -05:00
|
|
|
if (0 != localtime_s(&tmp, &date_start)) {
|
2019-11-03 17:05:25 -05:00
|
|
|
#else
|
2020-01-03 15:53:29 -05:00
|
|
|
if (!localtime_r(&date_start, &tmp)) {
|
2019-11-03 17:05:25 -05:00
|
|
|
#endif
|
2020-01-03 15:53:29 -05:00
|
|
|
logg("!Failed to get local time for Start Date.\n");
|
|
|
|
}
|
|
|
|
strftime(buffer, sizeof(buffer), "%Y:%m:%d %H:%M:%S", &tmp);
|
|
|
|
logg("Start Date: %s\n", buffer);
|
2019-11-03 17:05:25 -05:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2020-01-03 15:53:29 -05:00
|
|
|
if (0 != localtime_s(&tmp, &date_end)) {
|
2019-11-03 17:05:25 -05:00
|
|
|
#else
|
2020-01-03 15:53:29 -05:00
|
|
|
if (!localtime_r(&date_end, &tmp)) {
|
2019-11-03 17:05:25 -05:00
|
|
|
#endif
|
2020-01-03 15:53:29 -05:00
|
|
|
logg("!Failed to get local time for End Date.\n");
|
|
|
|
}
|
|
|
|
strftime(buffer, sizeof(buffer), "%Y:%m:%d %H:%M:%S", &tmp);
|
2019-11-03 17:05:25 -05:00
|
|
|
logg("End Date: %s\n", buffer);
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2008-12-30 10:33:43 +00:00
|
|
|
optfree(opts);
|
2014-05-09 17:09:29 -04:00
|
|
|
|
2004-03-13 20:08:10 +00:00
|
|
|
return ret;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void help(void)
|
|
|
|
{
|
|
|
|
mprintf_stdout = 1;
|
|
|
|
|
|
|
|
mprintf("\n");
|
2018-02-06 16:23:07 -05:00
|
|
|
mprintf(" Clam AntiVirus: Scanner %s\n", get_version());
|
2018-03-27 13:06:46 -04:00
|
|
|
printf(" By The ClamAV Team: https://www.clamav.net/about.html#credits\n");
|
2020-01-03 15:44:07 -05:00
|
|
|
printf(" (C) 2020 Cisco Systems, Inc.\n");
|
2018-02-06 16:23:07 -05:00
|
|
|
mprintf("\n");
|
|
|
|
mprintf(" clamscan [options] [file/directory/-]\n");
|
|
|
|
mprintf("\n");
|
|
|
|
mprintf(" --help -h Show this help\n");
|
2004-08-18 15:22:48 +00:00
|
|
|
mprintf(" --version -V Print version number\n");
|
2003-11-11 22:10:27 +00:00
|
|
|
mprintf(" --verbose -v Be verbose\n");
|
2011-08-22 16:58:48 +03:00
|
|
|
mprintf(" --archive-verbose -a Show filenames inside scanned archives\n");
|
2004-08-18 15:22:48 +00:00
|
|
|
mprintf(" --debug Enable libclamav's debug messages\n");
|
|
|
|
mprintf(" --quiet Only output error messages\n");
|
2019-05-21 14:49:42 -04:00
|
|
|
mprintf(" --stdout Write to stdout instead of stderr. Does not affect 'debug' messages.\n");
|
2004-08-18 15:22:48 +00:00
|
|
|
mprintf(" --no-summary Disable summary at end of scanning\n");
|
|
|
|
mprintf(" --infected -i Only print infected files\n");
|
2012-08-10 11:39:48 -04:00
|
|
|
mprintf(" --suppress-ok-results -o Skip printing OK files\n");
|
2004-08-18 15:22:48 +00:00
|
|
|
mprintf(" --bell Sound bell on virus detection\n");
|
2003-07-29 15:48:06 +00:00
|
|
|
mprintf("\n");
|
2004-07-05 23:50:55 +00:00
|
|
|
mprintf(" --tempdir=DIRECTORY Create temporary files in DIRECTORY\n");
|
2008-12-30 10:33:43 +00:00
|
|
|
mprintf(" --leave-temps[=yes/no(*)] Do not remove temporary files\n");
|
2018-02-06 16:23:07 -05:00
|
|
|
mprintf(" --gen-json[=yes/no(*)] Generate JSON description of scanned file(s). JSON will be printed and also-\n");
|
|
|
|
mprintf(" dropped to the temp directory if --leave-temps is enabled.\n");
|
|
|
|
mprintf(" --database=FILE/DIR -d FILE/DIR Load virus database from FILE or load all supported db files from DIR\n");
|
2009-11-10 19:30:33 +01:00
|
|
|
mprintf(" --official-db-only[=yes/no(*)] Only load official signatures\n");
|
2004-02-20 15:49:29 +00:00
|
|
|
mprintf(" --log=FILE -l FILE Save scan report to FILE\n");
|
2008-12-30 10:33:43 +00:00
|
|
|
mprintf(" --recursive[=yes/no(*)] -r Scan subdirectories recursively\n");
|
2012-11-27 14:48:50 -08:00
|
|
|
mprintf(" --allmatch[=yes/no(*)] -z Continue scanning within file after finding a match\n");
|
2009-08-05 16:27:48 +02:00
|
|
|
mprintf(" --cross-fs[=yes(*)/no] Scan files and directories on other filesystems\n");
|
2010-12-28 18:24:51 +01:00
|
|
|
mprintf(" --follow-dir-symlinks[=0/1(*)/2] Follow directory symlinks (0 = never, 1 = direct, 2 = always)\n");
|
|
|
|
mprintf(" --follow-file-symlinks[=0/1(*)/2] Follow file symlinks (0 = never, 1 = direct, 2 = always)\n");
|
2009-05-21 13:43:05 +00:00
|
|
|
mprintf(" --file-list=FILE -f FILE Scan files from FILE\n");
|
2008-12-30 10:33:43 +00:00
|
|
|
mprintf(" --remove[=yes/no(*)] Remove infected files. Be careful!\n");
|
2003-11-11 22:10:27 +00:00
|
|
|
mprintf(" --move=DIRECTORY Move infected files into DIRECTORY\n");
|
2006-10-29 14:37:20 +00:00
|
|
|
mprintf(" --copy=DIRECTORY Copy infected files into DIRECTORY\n");
|
2004-05-09 22:11:30 +00:00
|
|
|
mprintf(" --exclude=REGEX Don't scan file names matching REGEX\n");
|
2005-03-01 01:32:53 +00:00
|
|
|
mprintf(" --exclude-dir=REGEX Don't scan directories matching REGEX\n");
|
2004-05-09 22:11:30 +00:00
|
|
|
mprintf(" --include=REGEX Only scan file names matching REGEX\n");
|
2005-03-01 01:32:53 +00:00
|
|
|
mprintf(" --include-dir=REGEX Only scan directories matching REGEX\n");
|
2003-07-29 15:48:06 +00:00
|
|
|
mprintf("\n");
|
2010-03-19 17:42:25 +01:00
|
|
|
mprintf(" --bytecode[=yes(*)/no] Load bytecode from the database\n");
|
2011-02-17 19:17:35 +01:00
|
|
|
mprintf(" --bytecode-unsigned[=yes/no(*)] Load unsigned bytecode\n");
|
2020-07-06 13:03:35 -07:00
|
|
|
mprintf(" **Caution**: You should NEVER run bytecode signatures from untrusted sources.\n");
|
|
|
|
mprintf(" Doing so may result in arbitrary code execution.\n");
|
2010-12-28 18:24:51 +01:00
|
|
|
mprintf(" --bytecode-timeout=N Set bytecode timeout (in milliseconds)\n");
|
2015-02-19 12:47:20 -05:00
|
|
|
mprintf(" --statistics[=none(*)/bytecode/pcre] Collect and print execution statistics\n");
|
2008-12-30 10:33:43 +00:00
|
|
|
mprintf(" --detect-pua[=yes/no(*)] Detect Possibly Unwanted Applications\n");
|
2008-07-31 16:26:50 +00:00
|
|
|
mprintf(" --exclude-pua=CAT Skip PUA sigs of category CAT\n");
|
|
|
|
mprintf(" --include-pua=CAT Load PUA sigs of category CAT\n");
|
2008-12-30 10:33:43 +00:00
|
|
|
mprintf(" --detect-structured[=yes/no(*)] Detect structured data (SSN, Credit Card)\n");
|
2008-05-07 10:51:23 +00:00
|
|
|
mprintf(" --structured-ssn-format=X SSN format (0=normal,1=stripped,2=both)\n");
|
|
|
|
mprintf(" --structured-ssn-count=N Min SSN count to generate a detect\n");
|
|
|
|
mprintf(" --structured-cc-count=N Min CC count to generate a detect\n");
|
2016-04-21 12:13:57 -04:00
|
|
|
mprintf(" --structured-cc-mode=X CC mode (0=credit debit and private label, 1=credit cards only\n");
|
2008-12-30 10:33:43 +00:00
|
|
|
mprintf(" --scan-mail[=yes(*)/no] Scan mail files\n");
|
2018-10-10 06:02:28 -07:00
|
|
|
mprintf(" --phishing-sigs[=yes(*)/no] Enable email signature-based phishing detection\n");
|
|
|
|
mprintf(" --phishing-scan-urls[=yes(*)/no] Enable URL signature-based phishing detection\n");
|
|
|
|
mprintf(" --heuristic-alerts[=yes(*)/no] Heuristic alerts\n");
|
2008-12-30 10:33:43 +00:00
|
|
|
mprintf(" --heuristic-scan-precedence[=yes/no(*)] Stop scanning as soon as a heuristic match is found\n");
|
2018-02-06 16:23:07 -05:00
|
|
|
mprintf(" --normalize[=yes(*)/no] Normalize html, script, and text files. Use normalize=no for yara compatibility\n");
|
2008-12-30 10:33:43 +00:00
|
|
|
mprintf(" --scan-pe[=yes(*)/no] Scan PE files\n");
|
|
|
|
mprintf(" --scan-elf[=yes(*)/no] Scan ELF files\n");
|
|
|
|
mprintf(" --scan-ole2[=yes(*)/no] Scan OLE2 containers\n");
|
|
|
|
mprintf(" --scan-pdf[=yes(*)/no] Scan PDF files\n");
|
2013-02-05 19:46:56 -05:00
|
|
|
mprintf(" --scan-swf[=yes(*)/no] Scan SWF files\n");
|
2008-12-30 10:33:43 +00:00
|
|
|
mprintf(" --scan-html[=yes(*)/no] Scan HTML files\n");
|
2016-02-02 14:23:13 -05:00
|
|
|
mprintf(" --scan-xmldocs[=yes(*)/no] Scan xml-based document files\n");
|
|
|
|
mprintf(" --scan-hwp3[=yes(*)/no] Scan HWP3 files\n");
|
2008-12-30 10:33:43 +00:00
|
|
|
mprintf(" --scan-archive[=yes(*)/no] Scan archive files (supported by libclamav)\n");
|
2018-10-10 06:02:28 -07:00
|
|
|
mprintf(" --alert-broken[=yes/no(*)] Alert on broken executable files (PE & ELF)\n");
|
|
|
|
mprintf(" --alert-encrypted[=yes/no(*)] Alert on encrypted archives and documents\n");
|
|
|
|
mprintf(" --alert-encrypted-archive[=yes/no(*)] Alert on encrypted archives\n");
|
|
|
|
mprintf(" --alert-encrypted-doc[=yes/no(*)] Alert on encrypted documents\n");
|
|
|
|
mprintf(" --alert-macros[=yes/no(*)] Alert on OLE2 files containing VBA macros\n");
|
|
|
|
mprintf(" --alert-exceeds-max[=yes/no(*)] Alert on files that exceed max file size, max scan size, or max recursion limit\n");
|
|
|
|
mprintf(" --alert-phishing-ssl[=yes/no(*)] Alert on emails containing SSL mismatches in URLs\n");
|
|
|
|
mprintf(" --alert-phishing-cloak[=yes/no(*)] Alert on emails containing cloaked URLs\n");
|
|
|
|
mprintf(" --alert-partition-intersection[=yes/no(*)] Alert on raw DMG image files containing partition intersections\n");
|
2012-11-30 09:57:25 -05:00
|
|
|
mprintf(" --nocerts Disable authenticode certificate chain verification in PE files\n");
|
2013-01-08 15:10:03 -05:00
|
|
|
mprintf(" --dumpcerts Dump authenticode certificate chain in PE files\n");
|
2004-08-18 15:22:48 +00:00
|
|
|
mprintf("\n");
|
2020-04-01 17:21:46 -07:00
|
|
|
mprintf(" --max-scantime=#n Scan time longer than this will be skipped and assumed clean (milliseconds)\n");
|
2008-02-13 02:06:19 +00:00
|
|
|
mprintf(" --max-filesize=#n Files larger than this will be skipped and assumed clean\n");
|
2008-12-30 10:33:43 +00:00
|
|
|
mprintf(" --max-scansize=#n The maximum amount of data to scan for each container file (**)\n");
|
|
|
|
mprintf(" --max-files=#n The maximum number of files to scan for each container file (**)\n");
|
|
|
|
mprintf(" --max-recursion=#n Maximum archive recursion level for container file (**)\n");
|
2005-03-25 22:23:57 +00:00
|
|
|
mprintf(" --max-dir-recursion=#n Maximum directory recursion level\n");
|
2012-11-27 17:15:02 -05:00
|
|
|
mprintf(" --max-embeddedpe=#n Maximum size file to check for embedded PE\n");
|
|
|
|
mprintf(" --max-htmlnormalize=#n Maximum size of HTML file to normalize\n");
|
|
|
|
mprintf(" --max-htmlnotags=#n Maximum size of normalized HTML file to scan\n");
|
|
|
|
mprintf(" --max-scriptnormalize=#n Maximum size of script file to normalize\n");
|
|
|
|
mprintf(" --max-ziptypercg=#n Maximum size zip to type reanalyze\n");
|
2014-03-05 17:20:41 -05:00
|
|
|
mprintf(" --max-partitions=#n Maximum number of partitions in disk image to be scanned\n");
|
2014-03-06 18:19:11 -05:00
|
|
|
mprintf(" --max-iconspe=#n Maximum number of icons in PE file to be scanned\n");
|
2016-01-19 14:25:55 -05:00
|
|
|
mprintf(" --max-rechwp3=#n Maximum recursive calls to HWP3 parsing function\n");
|
2014-09-19 11:41:47 -04:00
|
|
|
#if HAVE_PCRE
|
|
|
|
mprintf(" --pcre-match-limit=#n Maximum calls to the PCRE match function.\n");
|
|
|
|
mprintf(" --pcre-recmatch-limit=#n Maximum recursive calls to the PCRE match function.\n");
|
2015-02-05 08:30:26 -08:00
|
|
|
mprintf(" --pcre-max-filesize=#n Maximum size file to perform PCRE subsig matching.\n");
|
2014-09-19 11:41:47 -04:00
|
|
|
#endif /* HAVE_PCRE */
|
2015-12-21 16:50:33 -05:00
|
|
|
mprintf(" --disable-cache Disable caching and cache checks for hash sums of scanned files.\n");
|
2008-06-10 16:59:19 +00:00
|
|
|
mprintf("\n");
|
2018-02-06 16:23:07 -05:00
|
|
|
mprintf("Pass in - as the filename for stdin.\n");
|
|
|
|
mprintf("\n");
|
2008-12-30 10:33:43 +00:00
|
|
|
mprintf("(*) Default scan settings\n");
|
|
|
|
mprintf("(**) Certain files (e.g. documents, archives, etc.) may in turn contain other\n");
|
|
|
|
mprintf(" files inside. The above options ensure safe processing of this kind of data.\n\n");
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|