summaryrefslogtreecommitdiff
blob: 1cf77e1925e7717f70621fd2b6bcfefb078c2107 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
--- python-clamav-0.4.1.orig/pyclamav.c
+++ python-clamav-0.4.1/pyclamav.c
@@ -33,25 +33,6 @@
 
 /* ********************************************************* */
 
-/* To be able to compile with 
-   releases 0.75 of libclamav 
-
-   Where cl_free was cl_freetrie
-   and cl_build was cl_buildtrie
-   CL_SCAN_STDOPT did not exist
-*/
-#ifndef CL_SCAN_STDOPT
-#define CL_SCAN_STDOPT CL_RAW | CL_ARCHIVE | CL_MAIL | CL_DISABLERAR | CL_OLE2 | CL_ENCRYPTED
-void cl_free(struct cl_node *rootnode) {
-  cl_freetrie(rootnode);  
-  return;    
-} 
-
-int cl_build(struct cl_node *rootnode) {  
-  return cl_buildtrie(rootnode);    
-} 
-#endif
-
 /* For python prior to 2.3 */
 #ifndef PyMODINIT_FUNC
 #define PyMODINIT_FUNC void
@@ -68,11 +49,9 @@
 unsigned int signumber = 0;
  
 /* Structures for clamav */
-struct cl_node *root = NULL;
-struct cl_limits limits;
+struct cl_engine *engine = NULL;
 struct cl_stat dbstat;
 
-
 /*
  * If the virus database has been changed, then
  * free the current tree and reload the new one
@@ -85,22 +64,22 @@
   /* If yes : reload DB                */
   if (cl_statchkdir(&dbstat) == 1)
     {
-      /* free the tree */
-      cl_free(root); 
+      /* free the engine */
+      cl_engine_free(engine); 
       signumber=0;
-      root=NULL;
+      engine=NULL;
 
       /* Load DB */
-      if((ret = cl_load(cl_retdbdir(), &root, &signumber, CL_DB_STDOPT))) {
+      if((ret = cl_load(cl_retdbdir(), engine, &signumber, CL_DB_STDOPT)) != CL_SUCCESS) {
 	/* Raise exception with error message */
 	PyErr_SetString(PyclamavError,  cl_strerror(ret));
 	return -2;
       }
 
-      /* build the final tree */
-      if((ret = cl_build(root))) {
-	/* free the partial tree */
-	cl_free(root); 
+      /* prepare the engine */
+      if((ret = cl_engine_compile(engine))) {
+	/* free the engine */
+	cl_engine_free(engine); 
 	/* Raise exception with error message */
 	PyErr_SetString(PyclamavError, cl_strerror(ret));
 	return -2;
@@ -231,7 +210,7 @@
     return NULL;     
   }
 
-  ret = cl_scanfile(file_to_scan, &virname, &size, root, &limits, CL_SCAN_STDOPT);
+  ret = cl_scanfile(file_to_scan, &virname, &size, engine, CL_SCAN_STDOPT);
 
   /* Test return code */
   switch (ret) {
@@ -278,17 +257,21 @@
   /* Set documentation string for the module */
   PyDict_SetItemString(dict, "__doc__", PyString_FromString("pyclamav :\n\n  This is a python binding to the C libclamav library\n  (from the Clamav project - http://www.clamav.net).\n  It can be used to easily allow a Python script to scan\n  a file or a buffer against known viruses.\n\nAuthor : Alexandre Norman [norman@xael.org]\n\nFunctions :\n  - scanfile(string filename) : Scan a file for virus.\n  - get_numsig() : Return the number of known signatures.\n  - get_version() : Return the version of Clamav.\n  - version() : Return the version of pyclamav.\n"));
 
+  /* initialize libclamav */
+  cl_init(CL_INIT_DEFAULT);
+  engine = cl_engine_new();
 
-  if((ret = cl_load(cl_retdbdir(), &root, &signumber, CL_DB_STDOPT))) {
+  if((ret = cl_load(cl_retdbdir(), engine, &signumber, CL_DB_STDOPT))) {
     /* Raise exception with error message */
     PyErr_SetString(PyclamavError,  cl_strerror(ret));
+    cl_engine_free(engine);
     return;
   }
 
-  /* build the final tree */
-  if((ret = cl_build(root))) {
-    /* free the partial tree */
-    cl_free(root); 
+  /* prepare the engine */
+  if((ret = cl_engine_compile(engine)) != CL_SUCCESS) {
+    /* free up the engine resources */
+    cl_engine_free(engine); 
     /* Raise exception with error message */
     PyErr_SetString(PyclamavError, cl_strerror(ret));
     return;
@@ -299,15 +282,6 @@
   memset(&dbstat, 0, sizeof(struct cl_stat));
   cl_statinidir(cl_retdbdir(), &dbstat);
 
-
-
-  /* set up archive limits */
-  memset(&limits, 0, sizeof(struct cl_limits));
-  limits.maxfiles = 1000; /* max files */
-  limits.maxfilesize = 10 * 1048576; /* maximal archived file size == 10 Mb */
-  limits.maxreclevel = 5; /* maximal recursion level */
-  limits.archivememlim = 0; /* disable memory limit for bzip2 scanner */
-
   return ;
 }