~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/others.h

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2007-2008 Sourcefire, Inc.
 
2
 *  Copyright (C) 2007-2010 Sourcefire, Inc.
3
3
 *
4
4
 *  Authors: Tomasz Kojm
5
5
 *
27
27
#include "clamav-config.h"
28
28
#endif
29
29
 
 
30
#ifdef HAVE_UNISTD_H
 
31
#include <unistd.h>
 
32
#endif
 
33
 
30
34
#include <stdio.h>
31
35
#include <stdlib.h>
32
36
#include "cltypes.h"
33
37
 
34
38
#include "clamav.h"
35
39
#include "dconf.h"
 
40
#include "filetypes.h"
 
41
#include "fmap.h"
36
42
#include "libclamunrar_iface/unrar_iface.h"
37
43
#include "regex/regex.h"
 
44
#include "bytecode.h"
 
45
#include "bytecode_api.h"
38
46
 
39
47
/*
40
48
 * CL_FLEVEL is the signature f-level specific to the current code and
45
53
 * in re-enabling affected modules.
46
54
 */
47
55
 
48
 
#define CL_FLEVEL 44
 
56
#define CL_FLEVEL 50
49
57
#define CL_FLEVEL_DCONF CL_FLEVEL
50
58
 
51
59
extern uint8_t cli_debug_flag;
91
99
#define NAME_MAX 256
92
100
#endif
93
101
 
 
102
typedef struct bitset_tag
 
103
{
 
104
        unsigned char *bitset;
 
105
        unsigned long length;
 
106
} bitset_t;
 
107
 
94
108
/* internal clamav context */
95
 
typedef struct {
 
109
typedef struct cli_ctx_tag {
96
110
    const char **virname;
97
111
    unsigned long int *scanned;
98
112
    const struct cli_matcher *root;
102
116
    unsigned int recursion;
103
117
    unsigned int scannedfiles;
104
118
    unsigned int found_possibly_unwanted;
 
119
    cli_file_t container_type; /* FIXME: to be made into a stack or array - see bb#1579 & bb#1293 */
 
120
    size_t container_size;
105
121
    struct cli_dconf *dconf;
 
122
    fmap_t **fmap;
 
123
    bitset_t* hook_lsig_matches;
106
124
} cli_ctx;
107
125
 
 
126
 
 
127
typedef struct {uint64_t v[2][4];} icon_groupset;
 
128
 
 
129
struct icomtr {
 
130
    unsigned int group[2];
 
131
    unsigned int color_avg[3];
 
132
    unsigned int color_x[3];
 
133
    unsigned int color_y[3];
 
134
    unsigned int gray_avg[3];
 
135
    unsigned int gray_x[3];
 
136
    unsigned int gray_y[3];
 
137
    unsigned int bright_avg[3];
 
138
    unsigned int bright_x[3];
 
139
    unsigned int bright_y[3];
 
140
    unsigned int dark_avg[3];
 
141
    unsigned int dark_x[3];
 
142
    unsigned int dark_y[3];
 
143
    unsigned int edge_avg[3];
 
144
    unsigned int edge_x[3];
 
145
    unsigned int edge_y[3];
 
146
    unsigned int noedge_avg[3];
 
147
    unsigned int noedge_x[3];
 
148
    unsigned int noedge_y[3];
 
149
    unsigned int rsum;
 
150
    unsigned int gsum;
 
151
    unsigned int bsum;
 
152
    unsigned int ccount;
 
153
    char *name;
 
154
};
 
155
 
 
156
struct icon_matcher {
 
157
    char **group_names[2];
 
158
    unsigned int group_counts[2];
 
159
    struct icomtr *icons[3];
 
160
    unsigned int icon_counts[3];
 
161
};
 
162
 
 
163
struct cli_dbinfo {
 
164
    char *name;
 
165
    unsigned char *hash;
 
166
    size_t size;
 
167
    struct cl_cvd *cvd;
 
168
    struct cli_dbinfo *next;
 
169
};
 
170
 
108
171
struct cl_engine {
109
172
    uint32_t refcount; /* reference counter */
110
173
    uint32_t sdb;
146
209
    /* B-M matcher for whitelist db */
147
210
    struct cli_matcher *md5_fp;
148
211
 
149
 
    /* Zip metadata */
150
 
    struct cli_meta_node *zip_mlist;
151
 
 
152
 
    /* RAR metadata */
153
 
    struct cli_meta_node *rar_mlist;
 
212
    /* Container metadata */
 
213
    struct cli_cdb *cdb;
154
214
 
155
215
    /* Phishing .pdb and .wdb databases*/
156
216
    struct regex_matcher *whitelist_matcher;
164
224
    struct cli_ftype *ftypes;
165
225
 
166
226
    /* Ignored signatures */
167
 
    struct cli_ignored *ignored;
 
227
    struct cli_matcher *ignored;
168
228
 
169
229
    /* PUA categories (to be included or excluded) */
170
230
    char *pua_cats;
171
231
 
 
232
    /* Icon reference storage */
 
233
    struct icon_matcher *iconcheck;
 
234
 
 
235
    /* Negative cache storage */
 
236
    struct CACHE *cache;
 
237
 
 
238
    /* Database information from .info files */
 
239
    struct cli_dbinfo *dbinfo;
 
240
 
172
241
    /* Used for memory pools */
173
242
    mpool_t *mempool;
 
243
 
 
244
    /* Used for bytecode */
 
245
    struct cli_all_bc bcs;
 
246
    unsigned *hooks[_BC_LAST_HOOK - _BC_START_HOOKS];
 
247
    unsigned hooks_cnt[_BC_LAST_HOOK - _BC_START_HOOKS];
 
248
    unsigned hook_lsig_ids;
 
249
    enum bytecode_security bytecode_security;
174
250
};
175
251
 
176
252
struct cl_settings {
224
300
                     (((v) & 0x00ff000000000000ULL) >> 40) | \
225
301
                     (((v) & 0xff00000000000000ULL) >> 56))
226
302
 
227
 
 
228
 
#if WORDS_BIGENDIAN == 0
229
 
 
230
303
#ifndef HAVE_ATTRIB_PACKED 
231
304
#define __attribute__(x)
232
305
#endif
237
310
#pragma pack 1
238
311
#endif
239
312
 
 
313
union unaligned_64 {
 
314
        uint64_t una_u64;
 
315
        int64_t una_s64;
 
316
} __attribute__((packed));
 
317
 
240
318
union unaligned_32 {
241
319
        uint32_t una_u32;
242
320
        int32_t una_s32;
243
321
} __attribute__((packed));
244
322
 
245
323
union unaligned_16 {
 
324
        uint16_t una_u16;
246
325
        int16_t una_s16;
247
326
} __attribute__((packed));
248
327
 
252
331
#ifdef HAVE_PRAGMA_PACK_HPPA
253
332
#pragma pack
254
333
#endif
 
334
 
 
335
#if WORDS_BIGENDIAN == 0
 
336
 
255
337
/* Little endian */
256
338
#define le16_to_host(v) (v)
257
339
#define le32_to_host(v) (v)
299
381
#endif
300
382
 
301
383
/* used by: spin, yc (C) aCaB */
302
 
#define CLI_ROL(a,b) a = ( a << (b % (sizeof(a)<<3) ))  |  (a >> (  (sizeof(a)<<3)  -  (b % (sizeof(a)<<3 )) ) )
303
 
#define CLI_ROR(a,b) a = ( a >> (b % (sizeof(a)<<3) ))  |  (a << (  (sizeof(a)<<3)  -  (b % (sizeof(a)<<3 )) ) )
 
384
#define __SHIFTBITS(a) (sizeof(a)<<3)
 
385
#define __SHIFTMASK(a) (__SHIFTBITS(a)-1)
 
386
#define CLI_ROL(a,b) a = ( a << ((b) & __SHIFTMASK(a)) ) | ( a >> ((__SHIFTBITS(a) - (b)) & __SHIFTMASK(a)) )
 
387
#define CLI_ROR(a,b) a = ( a >> ((b) & __SHIFTMASK(a)) ) | ( a << ((__SHIFTBITS(a) - (b)) & __SHIFTMASK(a)) )
304
388
 
305
389
/* Implementation independent sign-extended signed right shift */
306
390
#ifdef HAVE_SAR
310
394
#endif
311
395
#define CLI_SAR(n,s) n = CLI_SRS(n,s)
312
396
 
313
 
#ifndef FALSE
314
 
#define FALSE (0)
315
 
#endif
316
 
 
317
 
#ifndef TRUE
318
 
#define TRUE (1)
319
 
#endif
320
 
 
321
 
#ifndef MIN
322
 
#define MIN(a, b)       (((a) < (b)) ? (a) : (b))
323
 
#endif
324
 
#ifndef MAX
325
 
#define MAX(a,b)        (((a) > (b)) ? (a) : (b))
326
 
#endif
327
 
 
328
 
typedef struct bitset_tag
329
 
{
330
 
        unsigned char *bitset;
331
 
        unsigned long length;
332
 
} bitset_t;
333
 
 
334
397
#ifdef __GNUC__
335
398
void cli_warnmsg(const char *str, ...) __attribute__((format(printf, 1, 2)));
336
399
#else
347
410
 * such as debug paths, and error paths */
348
411
#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
349
412
#define UNLIKELY(cond) __builtin_expect(!!(cond), 0)
 
413
#define LIKELY(cond) __builtin_expect(!!(cond), 1)
350
414
#else
351
415
#define UNLIKELY(cond) (cond)
 
416
#define LIKELY(cond) (cond)
 
417
#endif
 
418
 
 
419
#ifdef __GNUC__
 
420
#define always_inline inline __attribute__((always_inline))
 
421
#else
 
422
#define always_inline inline
 
423
#endif
 
424
 
 
425
#if defined (__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
 
426
#define __hot__ __attribute__((hot))
 
427
#else
 
428
#define __hot__
352
429
#endif
353
430
 
354
431
#define cli_dbgmsg (!UNLIKELY(cli_debug_flag)) ? (void)0 : cli_dbgmsg_internal
359
436
void cli_dbgmsg_internal(const char *str, ...);
360
437
#endif
361
438
 
 
439
#ifdef HAVE_CLI_GETPAGESIZE
 
440
#undef HAVE_CLI_GETPAGESIZE
 
441
#endif
 
442
 
 
443
#ifdef _WIN32
 
444
static inline int cli_getpagesize(void) {
 
445
    SYSTEM_INFO si;
 
446
    GetSystemInfo(&si);
 
447
    return si.dwPageSize;
 
448
}
 
449
#else /* ! _WIN32 */
362
450
#if HAVE_SYSCONF_SC_PAGESIZE
363
451
static inline int cli_getpagesize(void) { return sysconf(_SC_PAGESIZE); }
364
452
#define HAVE_CLI_GETPAGESIZE 1
366
454
#if HAVE_GETPAGESIZE
367
455
static inline int cli_getpagesize(void) { return getpagesize(); }
368
456
#define HAVE_CLI_GETPAGESIZE 1
369
 
#endif
370
 
#define HAVE_CLI_GETPAGESIZE 0
371
 
#endif
 
457
#endif /* HAVE_GETPAGESIZE */
 
458
#endif /* HAVE_SYSCONF_SC_PAGESIZE */
 
459
#endif /* _WIN32 */
372
460
 
373
461
void *cli_malloc(size_t nmemb);
374
462
void *cli_calloc(size_t nmemb, size_t size);
382
470
int cli_unlink(const char *pathname);
383
471
int cli_readn(int fd, void *buff, unsigned int count);
384
472
int cli_writen(int fd, const void *buff, unsigned int count);
 
473
const char *cli_gettmpdir(void);
385
474
char *cli_gentemp(const char *dir);
386
475
int cli_gentempfd(const char *dir, char **name, int *fd);
387
476
unsigned int cli_rndnum(unsigned int max);
388
477
int cli_filecopy(const char *src, const char *dest);
 
478
int cli_dumpscan(int fd, off_t offset, size_t size, cli_ctx *ctx);
389
479
bitset_t *cli_bitset_init(void);
390
480
void cli_bitset_free(bitset_t *bs);
391
481
int cli_bitset_set(bitset_t *bs, unsigned long bit_offset);
395
485
int cli_updatelimits(cli_ctx *, unsigned long);
396
486
unsigned long cli_getsizelimit(cli_ctx *, unsigned long);
397
487
int cli_matchregex(const char *str, const char *regex);
 
488
void cli_qsort(void *a, size_t n, size_t es, int (*cmp)(const void *, const void *));
398
489
 
399
490
/* symlink behaviour */
400
491
#define CLI_FTW_FOLLOW_FILE_SYMLINK 0x01