2014-01-24 14:24:56 -05:00
|
|
|
/*
|
2020-01-03 15:44:07 -05:00
|
|
|
* Copyright (C) 2014-2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
|
2014-01-24 14:24:56 -05:00
|
|
|
*
|
|
|
|
* Authors: Kevin Lin <klin@sourcefire.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
* MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
#include "clamav-config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#if HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <zlib.h>
|
|
|
|
|
2014-07-01 19:38:01 -04:00
|
|
|
#include "clamav.h"
|
2014-01-24 14:24:56 -05:00
|
|
|
#include "others.h"
|
|
|
|
#include "gpt.h"
|
2014-02-10 17:08:45 -05:00
|
|
|
#include "mbr.h"
|
2014-02-07 12:22:44 -05:00
|
|
|
#include "str.h"
|
2020-04-29 14:19:41 -07:00
|
|
|
#include "entconv.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 "partition_intersection.h"
|
2014-01-24 14:24:56 -05:00
|
|
|
#include "scanners.h"
|
2014-02-07 17:12:43 -05:00
|
|
|
#include "dconf.h"
|
2014-01-24 14:24:56 -05:00
|
|
|
|
|
|
|
//#define DEBUG_GPT_PARSE
|
|
|
|
//#define DEBUG_GPT_PRINT
|
|
|
|
|
|
|
|
#ifdef DEBUG_GPT_PARSE
|
2018-12-03 12:40:13 -05:00
|
|
|
#define gpt_parsemsg(...) cli_dbgmsg(__VA_ARGS__)
|
2014-01-24 14:24:56 -05:00
|
|
|
#else
|
2018-12-03 12:40:13 -05:00
|
|
|
#define gpt_parsemsg(...) ;
|
2014-01-24 14:24:56 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG_GPT_PRINT
|
2018-12-03 12:40:13 -05:00
|
|
|
#define gpt_printmsg(...) cli_dbgmsg(__VA_ARGS__)
|
2014-01-24 14:24:56 -05:00
|
|
|
#else
|
2018-12-03 12:40:13 -05:00
|
|
|
#define gpt_printmsg(...) ;
|
2014-01-24 14:24:56 -05:00
|
|
|
#endif
|
|
|
|
|
2014-02-06 18:50:41 -05:00
|
|
|
enum GPT_SCANSTATE {
|
|
|
|
INVALID,
|
|
|
|
PRIMARY_ONLY,
|
|
|
|
SECONDARY_ONLY,
|
|
|
|
BOTH
|
|
|
|
};
|
|
|
|
|
|
|
|
static int gpt_scan_partitions(cli_ctx *ctx, struct gpt_header hdr, size_t sectorsize);
|
|
|
|
static int gpt_validate_header(cli_ctx *ctx, struct gpt_header hdr, size_t sectorsize);
|
2014-02-10 17:08:45 -05:00
|
|
|
static int gpt_check_mbr(cli_ctx *ctx, size_t sectorsize);
|
2014-02-06 18:50:41 -05:00
|
|
|
static void gpt_printSectors(cli_ctx *ctx, size_t sectorsize);
|
2018-12-03 12:40:13 -05:00
|
|
|
static void gpt_printGUID(uint8_t GUID[], const char *msg);
|
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
|
|
|
static int gpt_partition_intersection(cli_ctx *ctx, struct gpt_header hdr, size_t sectorsize);
|
2014-02-06 18:50:41 -05:00
|
|
|
|
2014-02-10 12:00:01 -05:00
|
|
|
/* returns 0 on failing to detect sectorsize */
|
|
|
|
size_t gpt_detect_size(fmap_t *map)
|
|
|
|
{
|
|
|
|
unsigned char *buff;
|
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
buff = (unsigned char *)fmap_need_off_once(map, 512, 8);
|
2014-03-13 12:47:40 -04:00
|
|
|
if (!buff) return 0;
|
2014-07-10 18:11:49 -04:00
|
|
|
if (0 == strncmp((const char *)buff, GPT_SIGNATURE_STR, 8))
|
2014-02-10 12:00:01 -05:00
|
|
|
return 512;
|
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
buff = (unsigned char *)fmap_need_off_once(map, 1024, 8);
|
2014-03-13 12:47:40 -04:00
|
|
|
if (!buff) return 0;
|
2014-07-10 18:11:49 -04:00
|
|
|
if (0 == strncmp((const char *)buff, GPT_SIGNATURE_STR, 8))
|
2014-02-10 12:00:01 -05:00
|
|
|
return 1024;
|
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
buff = (unsigned char *)fmap_need_off_once(map, 2048, 8);
|
2014-03-13 12:47:40 -04:00
|
|
|
if (!buff) return 0;
|
2014-07-10 18:11:49 -04:00
|
|
|
if (0 == strncmp((const char *)buff, GPT_SIGNATURE_STR, 8))
|
2014-02-10 12:00:01 -05:00
|
|
|
return 2048;
|
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
buff = (unsigned char *)fmap_need_off_once(map, 4096, 8);
|
2014-03-13 12:47:40 -04:00
|
|
|
if (!buff) return 0;
|
2014-07-10 18:11:49 -04:00
|
|
|
if (0 == strncmp((const char *)buff, GPT_SIGNATURE_STR, 8))
|
2014-02-10 12:00:01 -05:00
|
|
|
return 4096;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* attempts to detect sector size is input as 0 */
|
|
|
|
int cli_scangpt(cli_ctx *ctx, size_t sectorsize)
|
2014-01-24 14:24:56 -05:00
|
|
|
{
|
|
|
|
struct gpt_header phdr, shdr;
|
2014-02-06 18:50:41 -05:00
|
|
|
enum GPT_SCANSTATE state = INVALID;
|
2014-03-11 15:55:47 -04:00
|
|
|
int ret = CL_CLEAN, detection = CL_CLEAN;
|
2014-02-10 12:00:01 -05:00
|
|
|
size_t maplen;
|
2014-02-06 18:50:41 -05:00
|
|
|
off_t pos = 0;
|
2014-01-24 14:24:56 -05:00
|
|
|
|
2014-02-06 18:50:41 -05:00
|
|
|
gpt_parsemsg("The beginning of something big: GPT parsing\n");
|
2014-01-24 14:24:56 -05:00
|
|
|
|
2014-02-06 18:50:41 -05:00
|
|
|
if (!ctx || !ctx->fmap) {
|
|
|
|
cli_errmsg("cli_scangpt: Invalid context\n");
|
|
|
|
return CL_ENULLARG;
|
|
|
|
}
|
|
|
|
|
2018-02-21 15:00:59 -05:00
|
|
|
/* sector size calculation */
|
2014-02-10 12:00:01 -05:00
|
|
|
if (sectorsize == 0) {
|
|
|
|
sectorsize = gpt_detect_size((*ctx->fmap));
|
2014-03-14 12:49:21 -04:00
|
|
|
cli_dbgmsg("cli_scangpt: detected %lu sector size\n", (unsigned long)sectorsize);
|
2014-02-10 12:00:01 -05:00
|
|
|
}
|
|
|
|
if (sectorsize == 0) {
|
2018-02-21 15:00:59 -05:00
|
|
|
cli_errmsg("cli_scangpt: could not determine sector size\n");
|
2014-02-10 12:00:01 -05:00
|
|
|
return CL_EFORMAT;
|
|
|
|
}
|
2014-02-06 18:50:41 -05:00
|
|
|
|
|
|
|
/* size of total file must be a multiple of the sector size */
|
2014-01-24 14:24:56 -05:00
|
|
|
maplen = (*ctx->fmap)->real_len;
|
2014-02-06 18:50:41 -05:00
|
|
|
if ((maplen % sectorsize) != 0) {
|
2014-03-14 12:49:21 -04:00
|
|
|
cli_dbgmsg("cli_scangpt: File sized %lu is not a multiple of sector size %lu\n",
|
|
|
|
(unsigned long)maplen, (unsigned long)sectorsize);
|
2014-02-06 18:50:41 -05:00
|
|
|
return CL_EFORMAT;
|
|
|
|
}
|
2014-01-24 14:24:56 -05:00
|
|
|
|
2014-02-10 17:08:45 -05:00
|
|
|
/* check the protective mbr */
|
|
|
|
ret = gpt_check_mbr(ctx, sectorsize);
|
2014-03-11 15:55:47 -04:00
|
|
|
if (ret != CL_CLEAN) {
|
2018-07-20 22:28:48 -04:00
|
|
|
if (SCAN_ALLMATCHES && (ret == CL_VIRUS))
|
2014-03-11 15:55:47 -04:00
|
|
|
detection = CL_VIRUS;
|
|
|
|
else
|
|
|
|
return ret;
|
2014-02-10 17:08:45 -05:00
|
|
|
}
|
|
|
|
|
2014-02-06 18:50:41 -05:00
|
|
|
pos = GPT_PRIMARY_HDR_LBA * sectorsize; /* sector 1 (second sector) is the primary gpt header */
|
2014-01-24 14:24:56 -05:00
|
|
|
|
2014-02-06 18:50:41 -05:00
|
|
|
/* read primary gpt header */
|
|
|
|
cli_dbgmsg("cli_scangpt: Using primary GPT header\n");
|
|
|
|
if (fmap_readn(*ctx->fmap, &phdr, pos, sizeof(phdr)) != sizeof(phdr)) {
|
2014-01-24 14:24:56 -05:00
|
|
|
cli_dbgmsg("cli_scangpt: Invalid primary GPT header\n");
|
2014-02-06 18:50:41 -05:00
|
|
|
return CL_EFORMAT;
|
2014-01-24 14:24:56 -05:00
|
|
|
}
|
2014-02-06 18:50:41 -05:00
|
|
|
|
|
|
|
pos = maplen - sectorsize; /* last sector is the secondary gpt header */
|
|
|
|
|
|
|
|
if (gpt_validate_header(ctx, phdr, sectorsize)) {
|
|
|
|
cli_dbgmsg("cli_scangpt: Primary GPT header is invalid\n");
|
|
|
|
cli_dbgmsg("cli_scangpt: Using secondary GPT header\n");
|
|
|
|
|
|
|
|
state = SECONDARY_ONLY;
|
|
|
|
|
|
|
|
/* read secondary gpt header */
|
|
|
|
if (fmap_readn(*ctx->fmap, &shdr, pos, sizeof(shdr)) != sizeof(shdr)) {
|
|
|
|
cli_dbgmsg("cli_scangpt: Invalid secondary GPT header\n");
|
|
|
|
return CL_EFORMAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gpt_validate_header(ctx, shdr, sectorsize)) {
|
|
|
|
cli_dbgmsg("cli_scangpt: Secondary GPT header is invalid\n");
|
|
|
|
cli_dbgmsg("cli_scangpt: Disk is unusable\n");
|
|
|
|
return CL_EFORMAT;
|
|
|
|
}
|
2018-12-03 12:40:13 -05:00
|
|
|
} else {
|
2014-02-06 18:50:41 -05:00
|
|
|
cli_dbgmsg("cli_scangpt: Checking secondary GPT header\n");
|
2014-01-24 14:24:56 -05:00
|
|
|
|
2014-02-06 18:50:41 -05:00
|
|
|
state = PRIMARY_ONLY;
|
2014-01-24 14:24:56 -05:00
|
|
|
|
2014-02-06 18:50:41 -05:00
|
|
|
/* check validity of secondary header; still using the primary */
|
|
|
|
if (fmap_readn(*ctx->fmap, &shdr, pos, sizeof(shdr)) != sizeof(shdr)) {
|
|
|
|
cli_dbgmsg("cli_scangpt: Invalid secondary GPT header\n");
|
2018-12-03 12:40:13 -05:00
|
|
|
} else if (gpt_validate_header(ctx, shdr, sectorsize)) {
|
2014-02-06 18:50:41 -05:00
|
|
|
cli_dbgmsg("cli_scangpt: Secondary GPT header is invalid\n");
|
|
|
|
}
|
2020-01-03 15:44:07 -05:00
|
|
|
/* check that the two partition table crc32 checksum match,
|
2014-02-06 18:50:41 -05:00
|
|
|
* may want a different hashing function */
|
2018-12-03 12:40:13 -05:00
|
|
|
else if (phdr.tableCRC32 != shdr.tableCRC32) {
|
2014-02-06 18:50:41 -05:00
|
|
|
cli_dbgmsg("cli_scangpt: Primary and secondary GPT header table CRC32 differ\n");
|
|
|
|
cli_dbgmsg("cli_scangpt: Set to scan primary and secondary partition tables\n");
|
|
|
|
|
|
|
|
state = BOTH;
|
2018-12-03 12:40:13 -05:00
|
|
|
} else {
|
2014-02-06 18:50:41 -05:00
|
|
|
cli_dbgmsg("cli_scangpt: Secondary GPT header check OK\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check that the partition table has no intersections - HEURISTICS */
|
2018-07-20 22:28:48 -04:00
|
|
|
if (SCAN_HEURISTIC_PARTITION_INTXN && (ctx->dconf->other & OTHER_CONF_PRTNINTXN)) {
|
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
|
|
|
ret = gpt_partition_intersection(ctx, phdr, sectorsize);
|
2014-03-11 15:55:47 -04:00
|
|
|
if (ret != CL_CLEAN) {
|
2018-07-20 22:28:48 -04:00
|
|
|
if (SCAN_ALLMATCHES && (ret == CL_VIRUS))
|
2014-03-11 15:55:47 -04:00
|
|
|
detection = CL_VIRUS;
|
|
|
|
else
|
|
|
|
return ret;
|
2014-02-06 18:50:41 -05: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
|
|
|
ret = gpt_partition_intersection(ctx, shdr, sectorsize);
|
2014-03-11 15:55:47 -04:00
|
|
|
if (ret != CL_CLEAN) {
|
2018-07-20 22:28:48 -04:00
|
|
|
if (SCAN_ALLMATCHES && (ret == CL_VIRUS))
|
2014-03-11 15:55:47 -04:00
|
|
|
detection = CL_VIRUS;
|
|
|
|
else
|
|
|
|
return ret;
|
2014-02-06 18:50:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* scanning partitions */
|
|
|
|
switch (state) {
|
2018-12-03 12:40:13 -05:00
|
|
|
case PRIMARY_ONLY:
|
|
|
|
cli_dbgmsg("cli_scangpt: Scanning primary GPT partitions only\n");
|
|
|
|
ret = gpt_scan_partitions(ctx, phdr, sectorsize);
|
|
|
|
if (ret != CL_CLEAN) {
|
|
|
|
if (SCAN_ALLMATCHES && (ret == CL_VIRUS))
|
|
|
|
detection = CL_VIRUS;
|
|
|
|
else
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SECONDARY_ONLY:
|
|
|
|
cli_dbgmsg("cli_scangpt: Scanning secondary GPT partitions only\n");
|
|
|
|
ret = gpt_scan_partitions(ctx, shdr, sectorsize);
|
|
|
|
if (ret != CL_CLEAN) {
|
|
|
|
if (SCAN_ALLMATCHES && (ret == CL_VIRUS))
|
|
|
|
detection = CL_VIRUS;
|
|
|
|
else
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BOTH:
|
|
|
|
cli_dbgmsg("cli_scangpt: Scanning primary GPT partitions\n");
|
|
|
|
ret = gpt_scan_partitions(ctx, phdr, sectorsize);
|
|
|
|
if (ret != CL_CLEAN) {
|
|
|
|
if (SCAN_ALLMATCHES && (ret == CL_VIRUS))
|
|
|
|
detection = CL_VIRUS;
|
|
|
|
else
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
cli_dbgmsg("cli_scangpt: Scanning secondary GPT partitions\n");
|
|
|
|
ret = gpt_scan_partitions(ctx, shdr, sectorsize);
|
|
|
|
if (ret != CL_CLEAN) {
|
|
|
|
if (SCAN_ALLMATCHES && (ret == CL_VIRUS))
|
|
|
|
detection = CL_VIRUS;
|
|
|
|
else
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cli_dbgmsg("cli_scangpt: State is invalid\n");
|
2014-02-06 18:50:41 -05:00
|
|
|
}
|
|
|
|
|
2014-03-11 15:55:47 -04:00
|
|
|
return detection;
|
2014-01-24 14:24:56 -05:00
|
|
|
}
|
|
|
|
|
2014-02-06 18:50:41 -05:00
|
|
|
static int gpt_scan_partitions(cli_ctx *ctx, struct gpt_header hdr, size_t sectorsize)
|
2014-01-24 14:24:56 -05:00
|
|
|
{
|
2014-02-06 18:50:41 -05:00
|
|
|
struct gpt_partition_entry gpe;
|
2014-03-11 15:55:47 -04:00
|
|
|
int ret = CL_CLEAN, detection = CL_CLEAN;
|
2018-12-03 12:40:13 -05:00
|
|
|
size_t maplen, part_size = 0;
|
2014-02-06 18:50:41 -05:00
|
|
|
off_t pos = 0, part_off = 0;
|
|
|
|
unsigned i = 0, j = 0;
|
|
|
|
uint32_t max_prtns = 0;
|
2014-01-24 14:24:56 -05:00
|
|
|
|
2014-02-06 18:50:41 -05:00
|
|
|
/* convert endian to host */
|
2018-12-03 12:40:13 -05:00
|
|
|
hdr.signature = be64_to_host(hdr.signature);
|
|
|
|
hdr.revision = be32_to_host(hdr.revision);
|
|
|
|
hdr.headerSize = le32_to_host(hdr.headerSize);
|
|
|
|
hdr.headerCRC32 = le32_to_host(hdr.headerCRC32);
|
|
|
|
hdr.reserved = le32_to_host(hdr.reserved);
|
|
|
|
hdr.currentLBA = le64_to_host(hdr.currentLBA);
|
|
|
|
hdr.backupLBA = le64_to_host(hdr.backupLBA);
|
|
|
|
hdr.firstUsableLBA = le64_to_host(hdr.firstUsableLBA);
|
|
|
|
hdr.lastUsableLBA = le64_to_host(hdr.lastUsableLBA);
|
|
|
|
hdr.tableStartLBA = le64_to_host(hdr.tableStartLBA);
|
2014-02-06 18:50:41 -05:00
|
|
|
hdr.tableNumEntries = le32_to_host(hdr.tableNumEntries);
|
2018-12-03 12:40:13 -05:00
|
|
|
hdr.tableEntrySize = le32_to_host(hdr.tableEntrySize);
|
|
|
|
hdr.tableCRC32 = le32_to_host(hdr.tableCRC32);
|
2014-02-06 18:50:41 -05:00
|
|
|
|
|
|
|
/* print header info for the debug */
|
|
|
|
cli_dbgmsg("GPT Header:\n");
|
2017-08-21 17:03:42 -04:00
|
|
|
cli_dbgmsg("Signature: 0x%llx\n", (long long unsigned)hdr.signature);
|
2014-02-06 18:50:41 -05:00
|
|
|
cli_dbgmsg("Revision: %x\n", hdr.revision);
|
|
|
|
gpt_printGUID(hdr.DiskGUID, "DISK GUID");
|
|
|
|
cli_dbgmsg("Partition Entry Count: %u\n", hdr.tableNumEntries);
|
|
|
|
cli_dbgmsg("Partition Entry Size: %u\n", hdr.tableEntrySize);
|
|
|
|
|
|
|
|
maplen = (*ctx->fmap)->real_len;
|
|
|
|
|
|
|
|
/* check engine maxpartitions limit */
|
|
|
|
if (hdr.tableNumEntries < ctx->engine->maxpartitions) {
|
|
|
|
max_prtns = hdr.tableNumEntries;
|
2018-12-03 12:40:13 -05:00
|
|
|
} else {
|
2014-02-06 18:50:41 -05:00
|
|
|
max_prtns = ctx->engine->maxpartitions;
|
|
|
|
}
|
|
|
|
|
2020-03-21 14:15:28 -04:00
|
|
|
/* use the partition tables to pass partitions to cli_magic_scan_nested_fmap_type */
|
2014-02-06 18:50:41 -05:00
|
|
|
pos = hdr.tableStartLBA * sectorsize;
|
|
|
|
for (i = 0; i < max_prtns; ++i) {
|
|
|
|
/* read in partition entry */
|
|
|
|
if (fmap_readn(*ctx->fmap, &gpe, pos, sizeof(gpe)) != sizeof(gpe)) {
|
|
|
|
cli_dbgmsg("cli_scangpt: Invalid GPT partition entry\n");
|
|
|
|
return CL_EFORMAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* convert the endian to host */
|
2018-12-03 12:40:13 -05:00
|
|
|
gpe.firstLBA = le64_to_host(gpe.firstLBA);
|
|
|
|
gpe.lastLBA = le64_to_host(gpe.lastLBA);
|
2014-02-06 18:50:41 -05:00
|
|
|
gpe.attributes = le64_to_host(gpe.attributes);
|
|
|
|
for (j = 0; j < 36; ++j) {
|
|
|
|
gpe.name[i] = le16_to_host(gpe.name[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check that partition is not empty and within a valid location */
|
|
|
|
if (gpe.firstLBA == 0) {
|
|
|
|
/* empty partition, invalid */
|
2018-12-03 12:40:13 -05:00
|
|
|
} else if ((gpe.firstLBA > gpe.lastLBA) ||
|
|
|
|
(gpe.firstLBA < hdr.firstUsableLBA) || (gpe.lastLBA > hdr.lastUsableLBA)) {
|
2014-02-06 18:50:41 -05:00
|
|
|
cli_dbgmsg("cli_scangpt: GPT partition exists outside specified bounds\n");
|
|
|
|
gpt_parsemsg("%llu < %llu, %llu > %llu\n", gpe.firstLBA, hdr.firstUsableLBA,
|
|
|
|
gpe.lastLBA, hdr.lastUsableLBA);
|
|
|
|
/* partition exists outside bounds specified by header or invalid */
|
2018-12-03 12:40:13 -05:00
|
|
|
} else if (((gpe.lastLBA + 1) * sectorsize) > maplen) {
|
2014-02-06 18:50:41 -05:00
|
|
|
/* partition exists outside bounds of the file map */
|
2018-12-03 12:40:13 -05:00
|
|
|
} else {
|
2020-03-19 21:23:54 -04:00
|
|
|
char *namestr = NULL;
|
|
|
|
|
|
|
|
namestr = (char *)cli_utf16toascii((char *)gpe.name, 72);
|
|
|
|
|
2014-02-06 18:50:41 -05:00
|
|
|
/* print partition entry data for debug */
|
|
|
|
cli_dbgmsg("GPT Partition Entry %u:\n", i);
|
2020-03-19 21:23:54 -04:00
|
|
|
cli_dbgmsg("Name: %s\n", namestr);
|
2014-02-06 18:50:41 -05:00
|
|
|
gpt_printGUID(gpe.typeGUID, "Type GUID");
|
|
|
|
gpt_printGUID(gpe.uniqueGUID, "Unique GUID");
|
2017-08-21 17:03:42 -04:00
|
|
|
cli_dbgmsg("Attributes: %llx\n", (long long unsigned)gpe.attributes);
|
2014-02-06 18:50:41 -05:00
|
|
|
cli_dbgmsg("Blocks: [%llu(%llu) -> %llu(%llu)]\n",
|
2018-12-03 12:40:13 -05:00
|
|
|
(long long unsigned)gpe.firstLBA, (long long unsigned)(gpe.firstLBA * sectorsize),
|
|
|
|
(long long unsigned)gpe.lastLBA, (long long unsigned)((gpe.lastLBA + 1) * sectorsize));
|
2014-02-06 18:50:41 -05:00
|
|
|
|
2020-03-21 14:15:28 -04:00
|
|
|
/* send the partition to cli_magic_scan_nested_fmap_type */
|
2018-12-03 12:40:13 -05:00
|
|
|
part_off = gpe.firstLBA * sectorsize;
|
2014-02-06 18:50:41 -05:00
|
|
|
part_size = (gpe.lastLBA - gpe.firstLBA + 1) * sectorsize;
|
2020-03-21 14:15:28 -04:00
|
|
|
ret = cli_magic_scan_nested_fmap_type(*ctx->fmap, part_off, part_size, ctx, CL_TYPE_PART_ANY, namestr);
|
2020-03-19 21:23:54 -04:00
|
|
|
if (NULL != namestr) {
|
|
|
|
free(namestr);
|
|
|
|
}
|
2014-03-11 15:55:47 -04:00
|
|
|
if (ret != CL_CLEAN) {
|
2018-07-20 22:28:48 -04:00
|
|
|
if (SCAN_ALLMATCHES && (ret == CL_VIRUS))
|
2014-03-11 15:55:47 -04:00
|
|
|
detection = CL_VIRUS;
|
|
|
|
else
|
2014-02-06 18:50:41 -05:00
|
|
|
return ret;
|
|
|
|
}
|
2014-01-24 14:24:56 -05:00
|
|
|
}
|
2014-02-06 18:50:41 -05:00
|
|
|
|
|
|
|
/* increment the offsets to next partition entry */
|
|
|
|
pos += hdr.tableEntrySize;
|
2014-01-24 14:24:56 -05:00
|
|
|
}
|
2014-02-06 18:50:41 -05:00
|
|
|
|
2014-02-07 17:18:23 -05:00
|
|
|
if (i >= ctx->engine->maxpartitions) {
|
2014-02-07 10:50:06 -05:00
|
|
|
cli_dbgmsg("cli_scangpt: max partitions reached\n");
|
2014-02-06 18:50:41 -05:00
|
|
|
}
|
|
|
|
|
2014-03-11 15:55:47 -04:00
|
|
|
return detection;
|
2014-01-24 14:24:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static int gpt_validate_header(cli_ctx *ctx, struct gpt_header hdr, size_t sectorsize)
|
|
|
|
{
|
|
|
|
uint32_t crc32_calc, crc32_ref;
|
|
|
|
uint64_t tableLastLBA, lastLBA;
|
|
|
|
size_t maplen, ptable_start, ptable_len;
|
|
|
|
unsigned char *ptable;
|
|
|
|
|
|
|
|
maplen = (*ctx->fmap)->real_len;
|
|
|
|
|
|
|
|
/* checking header crc32 checksum */
|
2018-12-03 12:40:13 -05:00
|
|
|
crc32_ref = le32_to_host(hdr.headerCRC32);
|
2014-01-24 14:24:56 -05:00
|
|
|
hdr.headerCRC32 = 0; /* checksum is calculated with field = 0 */
|
2018-12-03 12:40:13 -05:00
|
|
|
crc32_calc = crc32(0, (unsigned char *)&hdr, sizeof(hdr));
|
2014-01-24 14:24:56 -05:00
|
|
|
if (crc32_calc != crc32_ref) {
|
|
|
|
cli_dbgmsg("cli_scangpt: GPT header checksum mismatch\n");
|
|
|
|
gpt_parsemsg("%x != %x\n", crc32_calc, crc32_ref);
|
2014-02-06 18:50:41 -05:00
|
|
|
return CL_EFORMAT;
|
2014-01-24 14:24:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* convert endian to host to check partition table */
|
2018-12-03 12:40:13 -05:00
|
|
|
hdr.signature = be64_to_host(hdr.signature);
|
|
|
|
hdr.revision = be32_to_host(hdr.revision);
|
|
|
|
hdr.headerSize = le32_to_host(hdr.headerSize);
|
|
|
|
hdr.headerCRC32 = crc32_ref;
|
|
|
|
hdr.reserved = le32_to_host(hdr.reserved);
|
|
|
|
hdr.currentLBA = le64_to_host(hdr.currentLBA);
|
|
|
|
hdr.backupLBA = le64_to_host(hdr.backupLBA);
|
|
|
|
hdr.firstUsableLBA = le64_to_host(hdr.firstUsableLBA);
|
|
|
|
hdr.lastUsableLBA = le64_to_host(hdr.lastUsableLBA);
|
|
|
|
hdr.tableStartLBA = le64_to_host(hdr.tableStartLBA);
|
2014-01-24 14:24:56 -05:00
|
|
|
hdr.tableNumEntries = le32_to_host(hdr.tableNumEntries);
|
2018-12-03 12:40:13 -05:00
|
|
|
hdr.tableEntrySize = le32_to_host(hdr.tableEntrySize);
|
|
|
|
hdr.tableCRC32 = le32_to_host(hdr.tableCRC32);
|
2014-01-24 14:24:56 -05:00
|
|
|
|
|
|
|
ptable_start = hdr.tableStartLBA * sectorsize;
|
2018-12-03 12:40:13 -05:00
|
|
|
ptable_len = hdr.tableNumEntries * hdr.tableEntrySize;
|
2014-01-24 14:24:56 -05:00
|
|
|
tableLastLBA = (hdr.tableStartLBA + (ptable_len / sectorsize)) - 1;
|
2018-12-03 12:40:13 -05:00
|
|
|
lastLBA = (maplen / sectorsize) - 1;
|
2014-01-24 14:24:56 -05:00
|
|
|
|
|
|
|
/** HEADER CHECKS **/
|
|
|
|
gpt_printSectors(ctx, sectorsize);
|
|
|
|
|
|
|
|
/* check signature */
|
|
|
|
if (hdr.signature != GPT_SIGNATURE) {
|
|
|
|
cli_dbgmsg("cli_scangpt: Invalid GPT header signature %llx\n",
|
2018-12-03 12:40:13 -05:00
|
|
|
(long long unsigned)hdr.signature);
|
2014-02-06 18:50:41 -05:00
|
|
|
return CL_EFORMAT;
|
2014-01-24 14:24:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check header size */
|
|
|
|
if (hdr.headerSize != sizeof(hdr)) {
|
|
|
|
cli_dbgmsg("cli_scangpt: GPT header size does not match stated size\n");
|
2014-02-06 18:50:41 -05:00
|
|
|
return CL_EFORMAT;
|
2014-01-24 14:24:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check reserved value == 0 */
|
|
|
|
if (hdr.reserved != GPT_HDR_RESERVED) {
|
|
|
|
cli_dbgmsg("cli_scangpt: GPT header reserved is not expected value\n");
|
2014-02-06 18:50:41 -05:00
|
|
|
return CL_EFORMAT;
|
2014-01-24 14:24:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check that sectors are in a valid configuration */
|
|
|
|
if (!((hdr.currentLBA == GPT_PRIMARY_HDR_LBA && hdr.backupLBA == lastLBA) ||
|
|
|
|
(hdr.currentLBA == lastLBA && hdr.backupLBA == GPT_PRIMARY_HDR_LBA))) {
|
|
|
|
cli_dbgmsg("cli_scangpt: GPT secondary header is not last LBA\n");
|
2014-02-06 18:50:41 -05:00
|
|
|
return CL_EFORMAT;
|
2014-01-24 14:24:56 -05:00
|
|
|
}
|
|
|
|
if (hdr.firstUsableLBA > hdr.lastUsableLBA) {
|
|
|
|
cli_dbgmsg("cli_scangpt: GPT first usable sectors is after last usable sector\n");
|
2014-02-06 18:50:41 -05:00
|
|
|
return CL_EFORMAT;
|
2014-01-24 14:24:56 -05:00
|
|
|
}
|
|
|
|
if (hdr.firstUsableLBA <= GPT_PRIMARY_HDR_LBA || hdr.lastUsableLBA >= lastLBA) {
|
|
|
|
cli_dbgmsg("cli_scangpt: GPT usable sectors intersects header sector\n");
|
2014-02-06 18:50:41 -05:00
|
|
|
return CL_EFORMAT;
|
2014-01-24 14:24:56 -05:00
|
|
|
}
|
|
|
|
if ((hdr.tableStartLBA <= hdr.firstUsableLBA && tableLastLBA >= hdr.firstUsableLBA) ||
|
|
|
|
(hdr.tableStartLBA >= hdr.firstUsableLBA && hdr.tableStartLBA <= hdr.lastUsableLBA)) {
|
|
|
|
cli_dbgmsg("cli_scangpt: GPT usable sectors intersects partition table\n");
|
2014-02-06 18:50:41 -05:00
|
|
|
return CL_EFORMAT;
|
2014-01-24 14:24:56 -05:00
|
|
|
}
|
|
|
|
if (hdr.tableStartLBA <= GPT_PRIMARY_HDR_LBA || tableLastLBA >= lastLBA) {
|
|
|
|
cli_dbgmsg("cli_scangpt: GPT partition table intersects header sector\n");
|
2014-02-06 18:50:41 -05:00
|
|
|
return CL_EFORMAT;
|
2014-01-24 14:24:56 -05:00
|
|
|
}
|
|
|
|
|
2014-02-06 18:50:41 -05:00
|
|
|
/* check that valid table entry size */
|
2014-02-10 12:00:01 -05:00
|
|
|
if (hdr.tableEntrySize != sizeof(struct gpt_partition_entry)) {
|
2014-02-06 18:50:41 -05:00
|
|
|
cli_dbgmsg("cli_scangpt: cannot parse gpt with partition entry sized %u\n",
|
|
|
|
hdr.tableEntrySize);
|
|
|
|
return CL_EFORMAT;
|
|
|
|
}
|
|
|
|
|
2014-01-24 14:24:56 -05:00
|
|
|
/* check valid table */
|
|
|
|
if ((ptable_start + ptable_len) > maplen) {
|
|
|
|
cli_dbgmsg("cli_scangpt: GPT partition table extends over fmap limit\n");
|
2014-02-06 18:50:41 -05:00
|
|
|
return CL_EFORMAT;
|
2014-01-24 14:24:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/** END HEADER CHECKS **/
|
|
|
|
|
|
|
|
/* checking partition table crc32 checksum */
|
2018-12-03 12:40:13 -05:00
|
|
|
ptable = (unsigned char *)fmap_need_off_once((*ctx->fmap), ptable_start, ptable_len);
|
2014-01-24 14:24:56 -05:00
|
|
|
crc32_calc = crc32(0, ptable, ptable_len);
|
|
|
|
if (crc32_calc != hdr.tableCRC32) {
|
|
|
|
cli_dbgmsg("cli_scangpt: GPT partition table checksum mismatch\n");
|
|
|
|
gpt_parsemsg("%x != %x\n", crc32_calc, hdr.tableCRC32);
|
2014-02-06 18:50:41 -05:00
|
|
|
return CL_EFORMAT;
|
2014-01-24 14:24:56 -05:00
|
|
|
}
|
|
|
|
|
2014-02-06 18:50:41 -05:00
|
|
|
return CL_SUCCESS;
|
2014-01-24 14:24:56 -05:00
|
|
|
}
|
|
|
|
|
2014-02-10 17:08:45 -05:00
|
|
|
static int gpt_check_mbr(cli_ctx *ctx, size_t sectorsize)
|
|
|
|
{
|
|
|
|
struct mbr_boot_record pmbr;
|
|
|
|
off_t pos = 0, mbr_base = 0;
|
2018-12-03 12:40:13 -05:00
|
|
|
int ret = CL_CLEAN;
|
2014-02-10 17:08:45 -05:00
|
|
|
unsigned i = 0;
|
|
|
|
|
|
|
|
/* read the mbr */
|
|
|
|
mbr_base = sectorsize - sizeof(struct mbr_boot_record);
|
2018-12-03 12:40:13 -05:00
|
|
|
pos = (MBR_SECTOR * sectorsize) + mbr_base;
|
2014-02-10 17:08:45 -05:00
|
|
|
|
|
|
|
if (fmap_readn(*ctx->fmap, &pmbr, pos, sizeof(pmbr)) != sizeof(pmbr)) {
|
|
|
|
cli_dbgmsg("cli_scangpt: Invalid primary MBR header\n");
|
|
|
|
return CL_EFORMAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* convert mbr */
|
|
|
|
mbr_convert_to_host(&pmbr);
|
|
|
|
|
|
|
|
/* check the protective mbr - warning */
|
|
|
|
if (pmbr.entries[0].type == MBR_PROTECTIVE) {
|
|
|
|
/* check the efi partition matches the gpt spec */
|
|
|
|
if (pmbr.entries[0].firstLBA != GPT_PRIMARY_HDR_LBA) {
|
|
|
|
cli_warnmsg("cli_scangpt: protective MBR first LBA is incorrect %u\n",
|
|
|
|
pmbr.entries[0].firstLBA);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* other entries are empty */
|
|
|
|
for (i = 1; i < MBR_MAX_PARTITION_ENTRIES; ++i) {
|
|
|
|
if (pmbr.entries[i].type != MBR_EMPTY) {
|
|
|
|
cli_warnmsg("cli_scangpt: protective MBR has non-empty partition\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-12-03 12:40:13 -05:00
|
|
|
} else if (pmbr.entries[0].type == MBR_HYBRID) {
|
2014-02-10 17:08:45 -05:00
|
|
|
/* hybrid mbr detected */
|
|
|
|
cli_warnmsg("cli_scangpt: detected a hybrid MBR\n");
|
2018-12-03 12:40:13 -05:00
|
|
|
} else {
|
2014-02-10 17:08:45 -05:00
|
|
|
/* non-protective mbr detected */
|
|
|
|
cli_warnmsg("cli_scangpt: detected a non-protective MBR\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* scan the bootloader segment - pushed to scanning mbr */
|
|
|
|
/* check if MBR size matches GPT size */
|
|
|
|
/* check if the MBR and GPT partitions align - heuristic */
|
|
|
|
/* scan the MBR partitions - additional scans */
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-02-06 18:50:41 -05:00
|
|
|
static void gpt_printSectors(cli_ctx *ctx, size_t sectorsize)
|
2014-01-24 14:24:56 -05:00
|
|
|
{
|
2014-02-06 18:50:41 -05:00
|
|
|
#ifdef DEBUG_GPT_PARSE
|
|
|
|
struct gpt_header phdr, shdr;
|
|
|
|
off_t ppos = 0, spos = 0;
|
|
|
|
size_t pptable_len, sptable_len, maplen;
|
|
|
|
uint64_t ptableLastLBA, stableLastLBA;
|
2014-01-24 14:24:56 -05:00
|
|
|
|
2014-02-06 18:50:41 -05:00
|
|
|
/* sector size calculation */
|
|
|
|
sectorsize = GPT_DEFAULT_SECTOR_SIZE;
|
2014-01-24 14:24:56 -05:00
|
|
|
|
|
|
|
maplen = (*ctx->fmap)->real_len;
|
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
ppos = 1 * sectorsize; /* sector 1 (second sector) is the primary gpt header */
|
2014-02-06 18:50:41 -05:00
|
|
|
spos = maplen - sectorsize; /* last sector is the secondary gpt header */
|
|
|
|
|
|
|
|
/* read in the primary and secondary gpt headers */
|
|
|
|
if (fmap_readn(*ctx->fmap, &phdr, ppos, sizeof(phdr)) != sizeof(phdr)) {
|
2014-01-24 14:24:56 -05:00
|
|
|
cli_dbgmsg("cli_scangpt: Invalid primary GPT header\n");
|
2014-02-06 18:50:41 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (fmap_readn(*ctx->fmap, &shdr, spos, sizeof(shdr)) != sizeof(shdr)) {
|
|
|
|
cli_dbgmsg("cli_scangpt: Invalid secondary GPT header\n");
|
|
|
|
return;
|
2014-01-24 14:24:56 -05:00
|
|
|
}
|
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
pptable_len = phdr.tableNumEntries * phdr.tableEntrySize;
|
|
|
|
sptable_len = shdr.tableNumEntries * shdr.tableEntrySize;
|
2014-02-06 18:50:41 -05:00
|
|
|
ptableLastLBA = (phdr.tableStartLBA + (pptable_len / sectorsize)) - 1;
|
|
|
|
stableLastLBA = (shdr.tableStartLBA + (sptable_len / sectorsize)) - 1;
|
2014-01-24 14:24:56 -05:00
|
|
|
|
2014-02-06 18:50:41 -05:00
|
|
|
gpt_parsemsg("0: MBR\n");
|
|
|
|
gpt_parsemsg("%llu: Primary GPT Header\n", phdr.currentLBA);
|
|
|
|
gpt_parsemsg("%llu-%llu: Primary GPT Partition Table\n", phdr.tableStartLBA, ptableLastLBA);
|
2018-02-21 15:00:59 -05:00
|
|
|
gpt_parsemsg("%llu-%llu: Usable LBAs\n", phdr.firstUsableLBA, phdr.lastUsableLBA);
|
2014-02-06 18:50:41 -05:00
|
|
|
gpt_parsemsg("%llu-%llu: Secondary GPT Partition Table\n", shdr.tableStartLBA, stableLastLBA);
|
|
|
|
gpt_parsemsg("%llu: Secondary GPT Header\n", phdr.backupLBA);
|
|
|
|
#else
|
2014-07-10 18:11:49 -04:00
|
|
|
UNUSEDPARAM(ctx);
|
|
|
|
UNUSEDPARAM(sectorsize);
|
2014-02-06 18:50:41 -05:00
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
}
|
2014-01-24 14:24:56 -05:00
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
static void gpt_printGUID(uint8_t GUID[], const char *msg)
|
2014-02-06 18:50:41 -05:00
|
|
|
{
|
2014-12-22 12:13:38 -05:00
|
|
|
cli_dbgmsg("%s: %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
|
|
|
|
msg, GUID[0], GUID[1], GUID[2], GUID[3], GUID[4], GUID[5], GUID[6], GUID[7],
|
|
|
|
GUID[8], GUID[9], GUID[10], GUID[11], GUID[12], GUID[13], GUID[14], GUID[15]);
|
2014-02-06 18:50:41 -05:00
|
|
|
}
|
2014-01-24 14:24:56 -05: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
|
|
|
static int gpt_partition_intersection(cli_ctx *ctx, struct gpt_header hdr, size_t sectorsize)
|
2014-02-06 18:50:41 -05: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
|
|
|
partition_intersection_list_t prtncheck;
|
2014-02-06 18:50:41 -05:00
|
|
|
struct gpt_partition_entry gpe;
|
|
|
|
unsigned i, pitxn;
|
2014-03-11 15:55:47 -04:00
|
|
|
int ret = CL_CLEAN, tmp = CL_CLEAN;
|
2014-02-06 18:50:41 -05:00
|
|
|
off_t pos;
|
|
|
|
size_t maplen;
|
|
|
|
uint32_t max_prtns = 0;
|
2018-12-03 12:40:13 -05:00
|
|
|
int virus_found = 0;
|
2014-02-06 18:50:41 -05:00
|
|
|
|
|
|
|
maplen = (*ctx->fmap)->real_len;
|
|
|
|
|
|
|
|
/* convert endian to host to check partition table */
|
2018-12-03 12:40:13 -05:00
|
|
|
hdr.tableStartLBA = le64_to_host(hdr.tableStartLBA);
|
2014-01-24 14:24:56 -05:00
|
|
|
hdr.tableNumEntries = le32_to_host(hdr.tableNumEntries);
|
|
|
|
|
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
|
|
|
partition_intersection_list_init(&prtncheck);
|
2014-01-24 14:24:56 -05:00
|
|
|
|
2014-02-06 18:50:41 -05:00
|
|
|
/* check engine maxpartitions limit */
|
|
|
|
if (hdr.tableNumEntries < ctx->engine->maxpartitions) {
|
|
|
|
max_prtns = hdr.tableNumEntries;
|
2018-12-03 12:40:13 -05:00
|
|
|
} else {
|
2014-02-06 18:50:41 -05:00
|
|
|
max_prtns = ctx->engine->maxpartitions;
|
2014-01-24 14:24:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pos = hdr.tableStartLBA * sectorsize;
|
2014-02-06 18:50:41 -05:00
|
|
|
for (i = 0; i < max_prtns; ++i) {
|
2014-01-24 14:24:56 -05:00
|
|
|
/* read in partition entry */
|
|
|
|
if (fmap_readn(*ctx->fmap, &gpe, pos, sizeof(gpe)) != sizeof(gpe)) {
|
2014-02-06 18:50:41 -05:00
|
|
|
cli_dbgmsg("cli_scangpt: Invalid GPT partition entry\n");
|
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
|
|
|
partition_intersection_list_free(&prtncheck);
|
2014-01-24 14:24:56 -05:00
|
|
|
return CL_EFORMAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* convert the endian to host */
|
|
|
|
gpe.firstLBA = le64_to_host(gpe.firstLBA);
|
2018-12-03 12:40:13 -05:00
|
|
|
gpe.lastLBA = le64_to_host(gpe.lastLBA);
|
2014-01-24 14:24:56 -05:00
|
|
|
|
|
|
|
if (gpe.firstLBA == 0) {
|
2014-02-06 18:50:41 -05:00
|
|
|
/* empty partition, invalid */
|
2018-12-03 12:40:13 -05:00
|
|
|
} else if ((gpe.firstLBA > gpe.lastLBA) ||
|
|
|
|
(gpe.firstLBA < hdr.firstUsableLBA) || (gpe.lastLBA > hdr.lastUsableLBA)) {
|
2014-01-24 14:24:56 -05:00
|
|
|
/* partition exists outside bounds specified by header or invalid */
|
2018-12-03 12:40:13 -05:00
|
|
|
} else if (((gpe.lastLBA + 1) * sectorsize) > maplen) {
|
2014-02-06 18:50:41 -05:00
|
|
|
/* partition exists outside bounds of the file map */
|
2018-12-03 12:40:13 -05:00
|
|
|
} else {
|
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
|
|
|
tmp = partition_intersection_list_check(&prtncheck, &pitxn, gpe.firstLBA, gpe.lastLBA - gpe.firstLBA + 1);
|
2014-02-06 18:50:41 -05:00
|
|
|
if (tmp != CL_CLEAN) {
|
2017-04-18 12:03:36 -04:00
|
|
|
if (tmp == CL_VIRUS) {
|
2014-02-06 18:50:41 -05:00
|
|
|
cli_dbgmsg("cli_scangpt: detected intersection with partitions "
|
2018-12-03 12:40:13 -05:00
|
|
|
"[%u, %u]\n",
|
|
|
|
pitxn, i);
|
2017-04-18 12:03:36 -04:00
|
|
|
ret = cli_append_virus(ctx, PRTN_INTXN_DETECTION);
|
|
|
|
if (ret == CL_VIRUS)
|
|
|
|
virus_found = 1;
|
2018-07-20 22:28:48 -04:00
|
|
|
if (SCAN_ALLMATCHES || ret == CL_CLEAN)
|
2017-04-18 12:03:36 -04:00
|
|
|
tmp = 0;
|
|
|
|
else
|
|
|
|
goto leave;
|
|
|
|
} else {
|
2014-02-06 18:50:41 -05:00
|
|
|
ret = tmp;
|
2017-04-18 12:03:36 -04:00
|
|
|
goto leave;
|
2014-01-24 14:24:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* increment the offsets to next partition entry */
|
|
|
|
pos += hdr.tableEntrySize;
|
|
|
|
}
|
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
leave:
|
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
|
|
|
partition_intersection_list_free(&prtncheck);
|
2017-04-18 12:03:36 -04:00
|
|
|
if (virus_found)
|
|
|
|
return CL_VIRUS;
|
2014-02-06 18:50:41 -05:00
|
|
|
return ret;
|
2014-01-24 14:24:56 -05:00
|
|
|
}
|