~ubuntu-branches/ubuntu/saucy/clamav/saucy

« back to all changes in this revision

Viewing changes to libclamav/clamav.h

  • Committer: Bazaar Package Importer
  • Author(s): Leonel Nunez
  • Date: 2008-02-11 22:52:13 UTC
  • mfrom: (1.1.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 38.
  • Revision ID: james.westby@ubuntu.com-20080211225213-p2uwj4czso1w2f8h
Tags: upstream-0.92~dfsg
ImportĀ upstreamĀ versionĀ 0.92~dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2007-2009 Sourcefire, Inc.
3
 
 *
4
 
 *  Authors: Tomasz Kojm
 
2
 *  Copyright (C) 2002 - 2007 Tomasz Kojm <tkojm@clamav.net>
5
3
 *
6
4
 *  This program is free software; you can redistribute it and/or modify
7
5
 *  it under the terms of the GNU General Public License version 2 as
23
21
 
24
22
#include <sys/types.h>
25
23
#include <sys/stat.h>
26
 
 
 
24
 
27
25
#ifdef __cplusplus
28
26
extern "C"
29
27
{
32
30
#define CL_COUNT_PRECISION 4096
33
31
 
34
32
/* return codes */
35
 
typedef enum {
36
 
    /* libclamav specific */
37
 
    CL_CLEAN = 0,
38
 
    CL_SUCCESS = 0,
39
 
    CL_VIRUS,
40
 
    CL_ENULLARG,
41
 
    CL_EARG,
42
 
    CL_EMALFDB,
43
 
    CL_ECVD,
44
 
    CL_EVERIFY,
45
 
    CL_EUNPACK,
46
 
 
47
 
    /* I/O and memory errors */
48
 
    CL_EOPEN,
49
 
    CL_ECREAT,
50
 
    CL_EUNLINK,
51
 
    CL_ESTAT,
52
 
    CL_EREAD,
53
 
    CL_ESEEK,
54
 
    CL_EWRITE,
55
 
    CL_EDUP,
56
 
    CL_EACCES,
57
 
    CL_ETMPFILE,
58
 
    CL_ETMPDIR,
59
 
    CL_EMAP,
60
 
    CL_EMEM,
61
 
    CL_ETIMEOUT,
62
 
 
63
 
    /* internal (not reported outside libclamav) */
64
 
    CL_BREAK,
65
 
    CL_EMAXREC,
66
 
    CL_EMAXSIZE,
67
 
    CL_EMAXFILES,
68
 
    CL_EFORMAT,
69
 
    CL_EBYTECODE,/* may be reported in testmode */
70
 
    CL_EBYTECODE_TESTFAIL, /* may be reported in testmode */
71
 
 
72
 
    /* c4w error codes */
73
 
    CL_ELOCK,
74
 
    CL_EBUSY,
75
 
    CL_ESTATE,
76
 
 
77
 
    /* no error codes below this line please */
78
 
    CL_ELAST_ERROR
79
 
} cl_error_t;
 
33
#define CL_CLEAN        0   /* no virus found */
 
34
#define CL_VIRUS        1   /* virus(es) found */
 
35
#define CL_SUCCESS      CL_CLEAN
 
36
#define CL_BREAK        2
 
37
 
 
38
#define CL_EMAXREC      -100 /* recursion limit exceeded */
 
39
#define CL_EMAXSIZE     -101 /* size limit exceeded */
 
40
#define CL_EMAXFILES    -102 /* files limit exceeded */
 
41
#define CL_ERAR         -103 /* rar handler error */
 
42
#define CL_EZIP         -104 /* zip handler error */
 
43
#define CL_EGZIP        -105 /* gzip handler error */
 
44
#define CL_EBZIP        -106 /* bzip2 handler error */
 
45
#define CL_EOLE2        -107 /* OLE2 handler error */
 
46
#define CL_EMSCOMP      -108 /* MS Expand handler error */
 
47
#define CL_EMSCAB       -109 /* MS CAB module error */
 
48
#define CL_EACCES       -110 /* access denied */
 
49
#define CL_ENULLARG     -111 /* null argument */
 
50
#define CL_ETMPFILE     -112 /* tmpfile() failed */
 
51
#define CL_EFSYNC       -113 /* fsync() failed */
 
52
#define CL_EMEM         -114 /* memory allocation error */
 
53
#define CL_EOPEN        -115 /* file open error */
 
54
#define CL_EMALFDB      -116 /* malformed database */
 
55
#define CL_EPATSHORT    -117 /* pattern too short */
 
56
#define CL_ETMPDIR      -118 /* mkdir() failed */
 
57
#define CL_ECVD         -119 /* not a CVD file (or broken) */
 
58
#define CL_ECVDEXTR     -120 /* CVD extraction failure */
 
59
#define CL_EMD5         -121 /* MD5 verification error */
 
60
#define CL_EDSIG        -122 /* digital signature verification error */
 
61
#define CL_EIO          -123 /* general I/O error */
 
62
#define CL_EFORMAT      -124 /* bad format or broken file */
 
63
#define CL_ESUPPORT     -125 /* not supported data format */
 
64
#define CL_ELOCKDB      -126 /* can't lock DB directory */
 
65
#define CL_EARJ         -127 /* ARJ handler error */
80
66
 
81
67
/* db options */
82
68
#define CL_DB_PHISHING      0x2
 
69
#define CL_DB_ACONLY        0x4 /* WARNING: only for developers */
83
70
#define CL_DB_PHISHING_URLS 0x8
84
71
#define CL_DB_PUA           0x10
85
 
#define CL_DB_CVDNOTMP      0x20    /* obsolete */
86
 
#define CL_DB_OFFICIAL      0x40    /* internal */
87
 
#define CL_DB_PUA_MODE      0x80
88
 
#define CL_DB_PUA_INCLUDE   0x100
89
 
#define CL_DB_PUA_EXCLUDE   0x200
90
 
#define CL_DB_COMPILED      0x400   /* internal */
91
 
#define CL_DB_DIRECTORY     0x800   /* internal */
92
 
#define CL_DB_OFFICIAL_ONLY 0x1000
93
 
#define CL_DB_BYTECODE      0x2000
94
 
#define CL_DB_SIGNED        0x4000  /* internal */
95
72
 
96
73
/* recommended db settings */
97
 
#define CL_DB_STDOPT        (CL_DB_PHISHING | CL_DB_PHISHING_URLS | CL_DB_BYTECODE)
 
74
#define CL_DB_STDOPT        (CL_DB_PHISHING | CL_DB_PHISHING_URLS)
98
75
 
99
76
/* scan options */
100
 
#define CL_SCAN_RAW                     0x0
101
 
#define CL_SCAN_ARCHIVE                 0x1
102
 
#define CL_SCAN_MAIL                    0x2
103
 
#define CL_SCAN_OLE2                    0x4
104
 
#define CL_SCAN_BLOCKENCRYPTED          0x8
105
 
#define CL_SCAN_HTML                    0x10
106
 
#define CL_SCAN_PE                      0x20
107
 
#define CL_SCAN_BLOCKBROKEN             0x40
108
 
#define CL_SCAN_MAILURL                 0x80 /* ignored */
109
 
#define CL_SCAN_BLOCKMAX                0x100 /* ignored */
110
 
#define CL_SCAN_ALGORITHMIC             0x200
111
 
#define CL_SCAN_PHISHING_BLOCKSSL       0x800 /* ssl mismatches, not ssl by itself*/
112
 
#define CL_SCAN_PHISHING_BLOCKCLOAK     0x1000
113
 
#define CL_SCAN_ELF                     0x2000
114
 
#define CL_SCAN_PDF                     0x4000
115
 
#define CL_SCAN_STRUCTURED              0x8000
116
 
#define CL_SCAN_STRUCTURED_SSN_NORMAL   0x10000
117
 
#define CL_SCAN_STRUCTURED_SSN_STRIPPED 0x20000
118
 
#define CL_SCAN_PARTIAL_MESSAGE         0x40000
119
 
#define CL_SCAN_HEURISTIC_PRECEDENCE    0x80000
120
 
#define CL_SCAN_BLOCKMACROS             0x100000
121
 
 
122
 
#define CL_SCAN_INTERNAL_COLLECT_SHA    0x80000000 /* Enables hash output in sha-collect builds - for internal use only */
 
77
#define CL_SCAN_RAW                 0x0
 
78
#define CL_SCAN_ARCHIVE             0x1
 
79
#define CL_SCAN_MAIL                0x2
 
80
#define CL_SCAN_OLE2                0x4
 
81
#define CL_SCAN_BLOCKENCRYPTED      0x8
 
82
#define CL_SCAN_HTML                0x10
 
83
#define CL_SCAN_PE                  0x20
 
84
#define CL_SCAN_BLOCKBROKEN         0x40
 
85
#define CL_SCAN_MAILURL             0x80
 
86
#define CL_SCAN_BLOCKMAX            0x100
 
87
#define CL_SCAN_ALGORITHMIC         0x200
 
88
#define CL_SCAN_PHISHING_DOMAINLIST 0x400
 
89
#define CL_SCAN_PHISHING_BLOCKSSL   0x800 /* ssl mismatches, not ssl by itself*/
 
90
#define CL_SCAN_PHISHING_BLOCKCLOAK 0x1000
 
91
#define CL_SCAN_ELF                 0x2000
 
92
#define CL_SCAN_PDF                 0x4000
123
93
 
124
94
/* recommended scan settings */
125
 
#define CL_SCAN_STDOPT          (CL_SCAN_ARCHIVE | CL_SCAN_MAIL | CL_SCAN_OLE2 | CL_SCAN_PDF | CL_SCAN_HTML | CL_SCAN_PE | CL_SCAN_ALGORITHMIC | CL_SCAN_ELF)
126
 
 
127
 
/* cl_countsigs options */
128
 
#define CL_COUNTSIGS_OFFICIAL       0x1
129
 
#define CL_COUNTSIGS_UNOFFICIAL     0x2
130
 
#define CL_COUNTSIGS_ALL            (CL_COUNTSIGS_OFFICIAL | CL_COUNTSIGS_UNOFFICIAL)
131
 
 
132
 
struct cl_engine;
133
 
struct cl_settings;
134
 
 
135
 
#define CL_INIT_DEFAULT 0x0
136
 
extern int cl_init(unsigned int initoptions);
137
 
 
138
 
extern struct cl_engine *cl_engine_new(void);
139
 
 
140
 
enum cl_engine_field {
141
 
    CL_ENGINE_MAX_SCANSIZE,         /* uint64_t */
142
 
    CL_ENGINE_MAX_FILESIZE,         /* uint64_t */
143
 
    CL_ENGINE_MAX_RECURSION,        /* uint32_t */
144
 
    CL_ENGINE_MAX_FILES,            /* uint32_t */
145
 
    CL_ENGINE_MIN_CC_COUNT,         /* uint32_t */
146
 
    CL_ENGINE_MIN_SSN_COUNT,        /* uint32_t */
147
 
    CL_ENGINE_PUA_CATEGORIES,       /* (char *) */
148
 
    CL_ENGINE_DB_OPTIONS,           /* uint32_t */
149
 
    CL_ENGINE_DB_VERSION,           /* uint32_t */
150
 
    CL_ENGINE_DB_TIME,              /* time_t */
151
 
    CL_ENGINE_AC_ONLY,              /* uint32_t */
152
 
    CL_ENGINE_AC_MINDEPTH,          /* uint32_t */
153
 
    CL_ENGINE_AC_MAXDEPTH,          /* uint32_t */
154
 
    CL_ENGINE_TMPDIR,               /* (char *) */
155
 
    CL_ENGINE_KEEPTMP,              /* uint32_t */
156
 
    CL_ENGINE_BYTECODE_SECURITY,    /* uint32_t */
157
 
    CL_ENGINE_BYTECODE_TIMEOUT,     /* uint32_t */
158
 
    CL_ENGINE_BYTECODE_MODE         /* uint32_t */
159
 
};
160
 
 
161
 
enum bytecode_security {
162
 
    CL_BYTECODE_TRUST_ALL=0, /* insecure, debug setting */
163
 
    CL_BYTECODE_TRUST_SIGNED, /* default */
164
 
    CL_BYTECODE_TRUST_NOTHING /* paranoid setting */
165
 
};
166
 
 
167
 
enum bytecode_mode {
168
 
    CL_BYTECODE_MODE_AUTO=0, /* JIT if possible, fallback to interpreter */
169
 
    CL_BYTECODE_MODE_JIT, /* force JIT */
170
 
    CL_BYTECODE_MODE_INTERPRETER, /* force interpreter */
171
 
    CL_BYTECODE_MODE_TEST, /* both JIT and interpreter, compare results,
172
 
                              all failures are fatal */
173
 
    CL_BYTECODE_MODE_OFF /* for query only, not settable */
174
 
};
175
 
 
176
 
extern int cl_engine_set_num(struct cl_engine *engine, enum cl_engine_field field, long long num);
177
 
 
178
 
extern long long cl_engine_get_num(const struct cl_engine *engine, enum cl_engine_field field, int *err);
179
 
 
180
 
extern int cl_engine_set_str(struct cl_engine *engine, enum cl_engine_field field, const char *str);
181
 
 
182
 
extern const char *cl_engine_get_str(const struct cl_engine *engine, enum cl_engine_field field, int *err);
183
 
 
184
 
extern struct cl_settings *cl_engine_settings_copy(const struct cl_engine *engine);
185
 
 
186
 
extern int cl_engine_settings_apply(struct cl_engine *engine, const struct cl_settings *settings);
187
 
 
188
 
extern int cl_engine_settings_free(struct cl_settings *settings);
189
 
 
190
 
extern int cl_engine_compile(struct cl_engine *engine);
191
 
 
192
 
extern int cl_engine_addref(struct cl_engine *engine);
193
 
 
194
 
extern int cl_engine_free(struct cl_engine *engine);
195
 
 
196
 
 
197
 
/* CALLBACKS - WARNING: unstable API - WIP */
198
 
 
199
 
 
200
 
typedef cl_error_t (*clcb_pre_scan)(int fd, void *context);
201
 
/* PRE-SCAN
202
 
Input:
203
 
fd      = File descriptor which is about to be scanned
204
 
context = Opaque application provided data
205
 
 
206
 
Output:
207
 
CL_CLEAN = File is scanned
208
 
CL_BREAK = Whitelisted by callback - file is skipped and marked as clean
209
 
CL_VIRUS = Blacklisted by callback - file is skipped and marked as infected
210
 
*/
211
 
extern void cl_engine_set_clcb_pre_scan(struct cl_engine *engine, clcb_pre_scan callback);
212
 
 
213
 
 
214
 
typedef cl_error_t (*clcb_post_scan)(int fd, int result, const char *virname, void *context);
215
 
/* POST-SCAN
216
 
Input:
217
 
fd      = File descriptor which is was scanned
218
 
result  = The scan result for the file
219
 
virname = Virus name if infected
220
 
context = Opaque application provided data
221
 
 
222
 
Output:
223
 
CL_CLEAN = Scan result is not overridden
224
 
CL_BREAK = Whitelisted by callback - scan result is set to CL_CLEAN
225
 
CL_VIRUS = Blacklisted by callback - scan result is set to CL_VIRUS
226
 
*/
227
 
extern void cl_engine_set_clcb_post_scan(struct cl_engine *engine, clcb_post_scan callback);
228
 
 
229
 
 
230
 
typedef int (*clcb_sigload)(const char *type, const char *name, void *context);
231
 
/* SIGNATURE LOAD
232
 
Input:
233
 
type = The signature type (e.g. "db", "ndb", "mdb", etc.)
234
 
name = The virus name
235
 
context = Opaque application provided data
236
 
 
237
 
Output:
238
 
0     = Load the current signature
239
 
Non 0 = Skip the current signature
240
 
 
241
 
WARNING: Some signatures (notably ldb, cbc) can be dependent upon other signatures.
242
 
         Failure to preserve dependency chains will result in database loading failure.
243
 
         It is the implementor's responsibility to guarantee consistency.
244
 
*/
245
 
extern void cl_engine_set_clcb_sigload(struct cl_engine *engine, clcb_sigload callback, void *context);
246
 
 
247
 
/* LibClamAV messages callback
248
 
 * The specified callback will be called instead of logging to stderr.
249
 
 * Messages of lower severity than specified are logged as usual.
250
 
 *
251
 
 * Just like with cl_debug() this must be called before going multithreaded.
252
 
 * Callable before cl_init, if you want to log messages from cl_init() itself.
253
 
 *
254
 
 * You can use context of cl_scandesc_callback to convey more information to the callback (such as the filename!)
255
 
 * Note: setting a 2nd callbacks overwrites previous, multiple callbacks are not
256
 
 * supported
257
 
 */
258
 
enum cl_msg {
259
 
    /* leave room for more message levels in the future */
260
 
    CL_MSG_INFO_VERBOSE = 32, /* verbose */
261
 
    CL_MSG_WARN = 64, /* LibClamAV WARNING: */
262
 
    CL_MSG_ERROR = 128/* LibClamAV ERROR: */
263
 
};
264
 
typedef void (*clcb_msg)(enum cl_msg severity, const char *fullmsg, const char *msg, void *context);
265
 
extern void cl_set_clcb_msg(clcb_msg callback);
266
 
 
267
 
/* LibClamAV hash stats callback */
268
 
typedef void (*clcb_hash)(int fd, unsigned long long size, const unsigned char *md5, const char *virname, void *context);
269
 
extern void cl_engine_set_clcb_hash(struct cl_engine *engine, clcb_hash callback);
 
95
#define CL_SCAN_STDOPT          (CL_SCAN_ARCHIVE | CL_SCAN_MAIL | CL_SCAN_OLE2 | CL_SCAN_HTML | CL_SCAN_PE | CL_SCAN_ALGORITHMIC | CL_SCAN_ELF | CL_SCAN_PHISHING_DOMAINLIST) 
 
96
 
 
97
/* aliases for backward compatibility */
 
98
#define CL_RAW          CL_SCAN_RAW
 
99
#define CL_ARCHIVE      CL_SCAN_ARCHIVE
 
100
#define CL_MAIL         CL_SCAN_MAIL
 
101
#define CL_OLE2         CL_SCAN_OLE2
 
102
#define CL_ENCRYPTED    CL_SCAN_BLOCKENCRYPTED
 
103
#define cl_node         cl_engine
 
104
#define cl_perror       cl_strerror
 
105
 
 
106
struct cl_engine {
 
107
    unsigned int refcount; /* reference counter */
 
108
    unsigned short sdb;
 
109
    unsigned int dboptions;
 
110
 
 
111
    /* Roots table */
 
112
    void **root;
 
113
 
 
114
    /* MD5 */
 
115
    void **md5_hlist;
 
116
 
 
117
    /* B-M matcher for MD5 sigs for PE sections */
 
118
    void *md5_sect;
 
119
 
 
120
    /* Zip metadata */
 
121
    void *zip_mlist;
 
122
 
 
123
    /* RAR metadata */
 
124
    void *rar_mlist;
 
125
 
 
126
    /* Phishing .pdb and .wdb databases*/
 
127
    void *whitelist_matcher;
 
128
    void *domainlist_matcher;
 
129
    void *phishcheck;
 
130
 
 
131
    /* Dynamic configuration */
 
132
    void *dconf;
 
133
};
 
134
 
 
135
struct cl_limits {
 
136
    unsigned int maxreclevel;       /* maximum recursion level for archives */
 
137
    unsigned int maxfiles;          /* maximum number of files to be scanned
 
138
                                     * within a single archive
 
139
                                     */
 
140
    unsigned int maxmailrec;        /* maximum recursion level for mail files */
 
141
    unsigned int maxratio;          /* maximum compression ratio */
 
142
    unsigned short archivememlim;   /* limit memory usage for some unpackers */
 
143
    unsigned long int maxfilesize;  /* compressed files larger than this limit
 
144
                                     * will not be scanned
 
145
                                     */
 
146
};
270
147
 
271
148
struct cl_stat {
272
149
    char *dir;
 
150
    unsigned int entries;
273
151
    struct stat *stattab;
274
152
    char **statdname;
275
 
    unsigned int entries;
276
153
};
277
154
 
278
155
struct cl_cvd {             /* field no. */
280
157
    unsigned int version;   /* 3 */
281
158
    unsigned int sigs;      /* 4 */
282
159
    unsigned int fl;        /* 5 */
283
 
                            /* padding */
284
160
    char *md5;              /* 6 */
285
161
    char *dsig;             /* 7 */
286
162
    char *builder;          /* 8 */
288
164
};
289
165
 
290
166
/* file scanning */
291
 
extern int cl_scandesc(int desc, const char **virname, unsigned long int *scanned, const struct cl_engine *engine, unsigned int scanoptions);
292
 
extern int cl_scandesc_callback(int desc, const char **virname, unsigned long int *scanned, const struct cl_engine *engine, unsigned int scanoptions, void *context);
 
167
extern int cl_scandesc(int desc, const char **virname, unsigned long int *scanned, const struct cl_engine *engine, const struct cl_limits *limits, unsigned int options);
293
168
 
294
 
extern int cl_scanfile(const char *filename, const char **virname, unsigned long int *scanned, const struct cl_engine *engine, unsigned int scanoptions);
295
 
extern int cl_scanfile_callback(const char *filename, const char **virname, unsigned long int *scanned, const struct cl_engine *engine, unsigned int scanoptions, void *context);
 
169
extern int cl_scanfile(const char *filename, const char **virname, unsigned long int *scanned, const struct cl_engine *engine, const struct cl_limits *limits, unsigned int options);
296
170
 
297
171
/* database handling */
298
 
extern int cl_load(const char *path, struct cl_engine *engine, unsigned int *signo, unsigned int dboptions);
 
172
extern int cl_load(const char *path, struct cl_engine **engine, unsigned int *signo, unsigned int options);
299
173
extern const char *cl_retdbdir(void);
300
174
 
301
175
/* engine handling */
 
176
extern int cl_build(struct cl_engine *engine);
 
177
extern struct cl_engine *cl_dup(struct cl_engine *engine);
 
178
extern void cl_free(struct cl_engine *engine);
302
179
 
303
180
/* CVD */
304
181
extern struct cl_cvd *cl_cvdhead(const char *file);
311
188
extern int cl_statchkdir(const struct cl_stat *dbstat);
312
189
extern int cl_statfree(struct cl_stat *dbstat);
313
190
 
314
 
/* count signatures */
315
 
extern int cl_countsigs(const char *path, unsigned int countoptions, unsigned int *sigs);
316
 
 
317
191
/* enable debug messages */
318
192
extern void cl_debug(void);
319
193
 
322
196
extern const char *cl_retver(void);
323
197
 
324
198
/* others */
 
199
extern void cl_settempdir(const char *dir, short leavetemps);
325
200
extern const char *cl_strerror(int clerror);
326
201
 
327
202
#ifdef __cplusplus