libclamav/clamav.h
b151ef55
 /*
30738099
  *  Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net>
b151ef55
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2 of the License, or
  *  (at your option) any later version.
  *
  *  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
30738099
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  *  MA 02110-1301, USA.
b151ef55
  */
 
 #ifndef __CLAMAV_H
 #define __CLAMAV_H
 
 #include <sys/types.h>
 #include <sys/stat.h>
  
 #ifdef __cplusplus
 extern "C"
 {
 #endif
 
 #define CL_COUNT_PRECISION 4096
 
 /* return codes */
d2963353
 #define CL_CLEAN	0   /* no virus found */
 #define CL_VIRUS	1   /* virus(es) found */
d119f7a0
 #define CL_SUCCESS	CL_CLEAN
6c2f19c6
 #define CL_BREAK	2
1ed6a845
 
d2963353
 #define CL_EMAXREC	-100 /* recursion limit exceeded */
 #define CL_EMAXSIZE	-101 /* size limit exceeded */
 #define CL_EMAXFILES	-102 /* files limit exceeded */
 #define CL_ERAR		-103 /* rar handler error */
 #define CL_EZIP		-104 /* zip handler error */
 #define CL_EGZIP	-105 /* gzip handler error */
 #define CL_EBZIP	-106 /* bzip2 handler error */
 #define CL_EOLE2	-107 /* OLE2 handler error */
 #define CL_EMSCOMP	-108 /* MS Expand handler error */
 #define CL_EMSCAB	-109 /* MS CAB module error */
 #define CL_EACCES	-110 /* access denied */
 #define CL_ENULLARG	-111 /* null argument */
 #define CL_ETMPFILE	-112 /* tmpfile() failed */
 #define CL_EFSYNC	-113 /* fsync() failed */
 #define CL_EMEM		-114 /* memory allocation error */
 #define CL_EOPEN	-115 /* file open error */
 #define CL_EMALFDB	-116 /* malformed database */
 #define CL_EPATSHORT	-117 /* pattern too short */
 #define CL_ETMPDIR	-118 /* mkdir() failed */
 #define CL_ECVD		-119 /* not a CVD file (or broken) */
 #define CL_ECVDEXTR	-120 /* CVD extraction failure */
 #define CL_EMD5		-121 /* MD5 verification error */
 #define CL_EDSIG	-122 /* digital signature verification error */
 #define CL_EIO		-123 /* general I/O error */
 #define CL_EFORMAT	-124 /* bad format or broken file */
 #define CL_ESUPPORT	-125 /* not supported data format */
c4428bd1
 #define CL_ELOCKDB	-126 /* can't lock DB directory */
d2963353
 
 /* NodalCore */
 #define CL_ENCINIT	-200 /* NodalCore initialization failed */
 #define	CL_ENCLOAD	-201 /* error loading NodalCore database */
 #define CL_ENCIO	-202 /* general NodalCore I/O error */
d119f7a0
 
4bf0af92
 /* db options */
d2963353
 #define CL_DB_NCORE	    0x1
c6a8017e
 #define CL_DB_PHISHING	    0x2
d2963353
 #define CL_DB_ACONLY	    0x4 /* WARNING: only for developers */
c6a8017e
 #define CL_DB_PHISHING_URLS 0x8
4bf0af92
 
d2963353
 /* recommended db settings */
c6a8017e
 #define CL_DB_STDOPT	    CL_DB_PHISHING
ef653ab9
 
06d4e856
 /* scan options */
c6a8017e
 #define CL_SCAN_RAW		    0x0
 #define CL_SCAN_ARCHIVE		    0x1
 #define CL_SCAN_MAIL		    0x2
 #define CL_SCAN_OLE2		    0x4
 #define CL_SCAN_BLOCKENCRYPTED	    0x8
 #define CL_SCAN_HTML		    0x10
 #define CL_SCAN_PE		    0x20
 #define CL_SCAN_BLOCKBROKEN	    0x40
 #define CL_SCAN_MAILURL		    0x80
 #define CL_SCAN_BLOCKMAX	    0x100
92f20fef
 #define CL_SCAN_ALGORITHMIC	    0x200
32edc870
 #define CL_SCAN_PHISHING_DOMAINLIST 0x400
 #define CL_SCAN_PHISHING_BLOCKSSL   0x800 /* ssl mismatches, not ssl by itself*/
 #define CL_SCAN_PHISHING_BLOCKCLOAK 0x1000
 #define CL_SCAN_ELF		    0x2000
d2963353
 
 /* recommended scan settings */
92f20fef
 #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) 
06d4e856
 
 /* aliases for backward compatibility */
 #define CL_RAW		CL_SCAN_RAW
 #define CL_ARCHIVE	CL_SCAN_ARCHIVE
 #define CL_MAIL		CL_SCAN_MAIL
 #define CL_OLE2		CL_SCAN_OLE2
68a10c26
 #define CL_ENCRYPTED    CL_SCAN_BLOCKENCRYPTED
f477691c
 #define cl_node		cl_engine
06d4e856
 
d2963353
 /* internal structures */
f91f55e0
 struct cli_bm_patt {
d4405156
     unsigned char *pattern;
     char *virname, *offset;
df757556
     const char *viralias;
     unsigned int length;
     unsigned short target;
f91f55e0
     struct cli_bm_patt *next;
 };
 
 struct cli_ac_patt {
ff5d8419
     short int *pattern, *prefix;
     unsigned int length, mindist, maxdist, prefix_length;
df757556
     char *virname, *offset;
     const char *viralias;
ff5d8419
     unsigned short int sigid, parts, partno, alt, *altn, alt_pattern;
df757556
     unsigned short type, target;
e4d44902
     unsigned char **altc;
f91f55e0
     struct cli_ac_patt *next;
b151ef55
 };
 
ff8cb48b
 struct cli_ac_node {
d2963353
     unsigned char islast;
f91f55e0
     struct cli_ac_patt *list;
     struct cli_ac_node *trans[256], *fail;
ff8cb48b
 };
b151ef55
 
ff8cb48b
 struct cli_md5_node {
7c0991e0
     char *virname, *viralias;
     unsigned char *md5;
61f31052
     unsigned int size;
3f66a5af
     unsigned short fp;
ff8cb48b
     struct cli_md5_node *next;
 };
 
92152740
 struct cli_meta_node {
a969b98a
     int csize, size, method;
     unsigned int crc32, fileno, encrypted, maxdepth;
34e96745
     char *filename, *virname;
92152740
     struct cli_meta_node *next;
34e96745
 };
 
f477691c
 struct cli_matcher {
f91f55e0
     unsigned int maxpatlen; /* maximal length of pattern in db */
9f986368
     unsigned short ac_only;
f91f55e0
 
     /* Extended Boyer-Moore */
     int *bm_shift;
     struct cli_bm_patt **bm_suffix;
 
     /* Extended Aho-Corasick */
2989d403
     unsigned int ac_depth;
f91f55e0
     struct cli_ac_node *ac_root, **ac_nodetable;
     unsigned int ac_partsigs, ac_nodes;
f477691c
 };
 
 struct cl_engine {
     unsigned int refcount; /* reference counter */
7def75f3
     unsigned short ncore;
66acd7a9
     unsigned short sdb;
5c8ff224
     unsigned int dboptions;
f477691c
 
     /* Roots table */
     struct cli_matcher **root;
ff8cb48b
 
     /* MD5 */
f91f55e0
     struct cli_md5_node **md5_hlist;
34e96745
 
344416f6
     /* MD5 list for PE sections */
     struct cli_md5_node *md5_sect;
 
34e96745
     /* Zip metadata */
92152740
     struct cli_meta_node *zip_mlist;
 
     /* RAR metadata */
     struct cli_meta_node *rar_mlist;
 
8491951e
     /* NodalCore database handle */
     void *ncdb;
6cecbecd
 
     /* Phishing .pdb and .wdb databases*/
     void *whitelist_matcher;
     void *domainlist_matcher;
ad387e52
     void *phishcheck;
4a30feab
 
     /* Dynamic configuration */
     void *dconf;
b151ef55
 };
 
 struct cl_limits {
edb9c9b8
     unsigned int maxreclevel;	    /* maximum recursion level for archives */
d2963353
     unsigned int maxfiles;	    /* maximum number of files to be scanned
 				     * within a single archive
 				     */
edb9c9b8
     unsigned int maxmailrec;	    /* maximum recursion level for mail files */
d2963353
     unsigned int maxratio;	    /* maximum compression ratio */
     unsigned short archivememlim;   /* limit memory usage for some unpackers */
     unsigned long int maxfilesize;  /* compressed files larger than this limit
 				     * will not be scanned
 				     */
b151ef55
 };
 
 struct cl_stat {
     char *dir;
d2963353
     unsigned int entries;
b151ef55
     struct stat *stattab;
193c72c5
     char **statdname;
b151ef55
 };
 
d2963353
 struct cl_cvd {		    /* field no. */
     char *time;		    /* 2 */
     unsigned int version;   /* 3 */
     unsigned int sigs;	    /* 4 */
     unsigned int fl;	    /* 5 */
     char *md5;		    /* 6 */
     char *dsig;		    /* 7 */
     char *builder;	    /* 8 */
     unsigned int stime;	    /* 9 */
4cd4319e
 };
 
b151ef55
 /* file scanning */
f477691c
 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);
b151ef55
 
f477691c
 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);
b151ef55
 
d2963353
 /* database handling */
4bf0af92
 extern int cl_load(const char *path, struct cl_engine **engine, unsigned int *signo, unsigned int options);
41b894c7
 extern const char *cl_retdbdir(void);
d2963353
 
 /* engine handling */
 extern int cl_build(struct cl_engine *engine);
f477691c
 extern struct cl_engine *cl_dup(struct cl_engine *engine);
d2963353
 extern void cl_free(struct cl_engine *engine);
b151ef55
 
f91f55e0
 /* CVD */
4cd4319e
 extern struct cl_cvd *cl_cvdhead(const char *file);
442d8407
 extern struct cl_cvd *cl_cvdparse(const char *head);
 extern int cl_cvdverify(const char *file);
4cd4319e
 extern void cl_cvdfree(struct cl_cvd *cvd);
 
d2963353
 /* db dir stat functions */
b151ef55
 extern int cl_statinidir(const char *dirname, struct cl_stat *dbstat);
 extern int cl_statchkdir(const struct cl_stat *dbstat);
 extern int cl_statfree(struct cl_stat *dbstat);
 
d2963353
 /* enable debug messages */
0bcad2b1
 extern void cl_debug(void);
b151ef55
 
d2963353
 /* software versions */
 extern unsigned int cl_retflevel(void);
 extern const char *cl_retver(void);
b151ef55
 
d2963353
 /* others */
 extern void cl_settempdir(const char *dir, short leavetemps);
41b894c7
 extern const char *cl_strerror(int clerror);
b151ef55
 
 #ifdef __cplusplus
783521b4
 }
b151ef55
 #endif
  
d2963353
 #endif /* __CLAMAV_H */