Blob Blame History Raw
# patch by Imre Gergely <gimre@narancs.net>
diff -ruN dansguardian-2.10.0.3.orig/src/contentscanners/clamav.cpp dansguardian-2.10.0.3/src/contentscanners/clamav.cpp
--- dansguardian-2.10.0.3.orig/src/contentscanners/clamav.cpp	2009-05-09 22:25:45.552238568 +0200
+++ dansguardian-2.10.0.3/src/contentscanners/clamav.cpp	2009-05-09 22:44:06.398108444 +0200
@@ -69,9 +69,11 @@
 	// virus database root node
 	// Update to support ClamAV 0.90
 	// Based on patch supplied by Aecio F. Neto
-	struct cl_engine *root;
+	struct cl_engine *engine;
+#ifndef CL_INIT_DEFAULT
 	// archive limit options
 	struct cl_limits limits;
+#endif
 
 #ifdef HAVE_CLAMAV_SHM
 	// use POSIX shared memory
@@ -100,7 +102,11 @@
 // destroy plugin
 int clamavinstance::quit()
 {
-	cl_free(root);
+#ifdef CL_INIT_DEFAULT
+	cl_engine_free(engine);
+#else
+	cl_free(engine);
+#endif
 	return DGCS_OK;
 }
 
@@ -164,7 +170,11 @@
 		return DGCS_SCANERROR;
 	}
 
-	rc = cl_scandesc(fd, &vn, NULL, root, &limits, CL_SCAN_STDOPT);
+#ifdef CL_INIT_DEFAULT
+	rc = cl_scandesc(fd, &vn, NULL, engine, CL_SCAN_STDOPT);
+#else
+	rc = cl_scandesc(fd, &vn, NULL, engine, &limits, CL_SCAN_STDOPT);
+#endif
 	close(fd);
 
 #ifdef HAVE_CLAMAV_SHM
@@ -189,7 +199,11 @@
 {
 	lastmessage = lastvirusname = "";
 	const char *vn = NULL;
-	int rc = cl_scanfile(filename, &vn, NULL, root, &limits, CL_SCAN_STDOPT );
+#ifdef CL_INIT_DEFAULT
+	int rc = cl_scanfile(filename, &vn, NULL, engine, CL_SCAN_STDOPT );
+#else
+	int rc = cl_scanfile(filename, &vn, NULL, engine, &limits, CL_SCAN_STDOPT );
+#endif
 	return doRC(rc, vn);
 }
 
@@ -220,6 +234,7 @@
 // initialise libclamav
 int clamavinstance::init(void* args)
 {
+	int rc;
 	// always include these lists
 	if (!readStandardLists()) {
 		return DGCS_ERROR;
@@ -244,18 +259,41 @@
 		return DGCS_ERROR;
 	}
 
-	// set clam's own temp dir
-	if (cv["tempdir"].length() > 0)
-		cl_settempdir(cv["tempdir"].toCharArray(), 0);
-
 #ifdef DGDEBUG
 	std::cout << "Scanbuffmethod: " << smethod << std::endl;
 	std::cout << "Scanbuffdir: " << memdir << std::endl;
 	std::cout << "Tempdir: " << cv["tempdir"] << std::endl;
 #endif
 
+#ifdef CL_INIT_DEFAULT
+	if ( (rc = cl_init(CL_INIT_DEFAULT)) != CL_SUCCESS ) {
+		return DGCS_ERROR;
+    	}
+	if ( !(engine = cl_engine_new()) ) {
+		return DGCS_ERROR;
+    	}
+
+	// set file, recursion and compression ratio limits for scanning archives
+	if ( (rc = cl_engine_set_num(engine, CL_ENGINE_MAX_FILES, (long long)cv["maxfiles"].toInteger())) ) {
+		return DGCS_ERROR;
+	}
+	if ( (rc = cl_engine_set_num(engine, CL_ENGINE_MAX_FILESIZE, (long long)o.max_content_filecache_scan_size + 1024 * 1024)) ) {
+		return DGCS_ERROR;
+	}
+	if ( (rc = cl_engine_set_num(engine, CL_ENGINE_MAX_RECURSION, (long long)cv["maxreclevel"].toInteger())) ) {
+		return DGCS_ERROR;
+	}
+	if ( (rc = cl_engine_set_num(engine, CL_ENGINE_MAX_SCANSIZE, (long long)cv["maxscansize"].toInteger() * 1024)) ) {
+		return DGCS_ERROR;
+	}
+// FIXME: need debug output code here
+	if (cv["tempdir"].length() > 0)
+        	if ( (rc = cl_engine_set_str(engine, CL_ENGINE_TMPDIR, cv["tempdir"].toCharArray())) ) {
+                	return DGCS_ERROR;
+        	}
+#else
 	// set file, recursion and compression ratio limits for scanning archives
-	root = NULL;
+	engine = NULL;
 	limits.maxfiles = cv["maxfiles"].toInteger();
 	limits.maxfilesize = o.max_content_filecache_scan_size + 1024 * 1024;
 	limits.maxreclevel = cv["maxreclevel"].toInteger();
@@ -264,12 +302,35 @@
 	std::cerr << "maxfiles: " << limits.maxfiles << " maxfilesize: " << limits.maxfilesize
 		<< " maxreclevel: " << limits.maxreclevel << " maxscansize: " << limits.maxscansize << std::endl;
 #endif
+	if (cv["tempdir"].length() > 0)
+		cl_settempdir(cv["tempdir"].toCharArray(), 0);
+
+#endif
 
 	// load virus database
-	unsigned int virnum = 0;
-	int rc = cl_load(cl_retdbdir(), &root, &virnum, CL_DB_STDOPT);
+	unsigned int sigs = 0;
+#ifdef CL_INIT_DEFAULT
+	if ( (rc = cl_load(cl_retdbdir(), engine, &sigs, 0)) != CL_SUCCESS ) {
+		if (!is_daemonised)
+                	std::cerr << "Error loading clamav db: " << cl_strerror(rc) << std::endl;
+                syslog(LOG_ERR, "Error loading clamav db: %s", cl_strerror(rc));
+		return DGCS_ERROR;
+	}
+#ifdef DGDEBUG
+        std::cout << "engine: " << engine << " sigs: " << sigs << std::endl;
+#endif
+	if ( (rc = cl_engine_compile(engine)) != CL_SUCCESS ) {
+        	if (!is_daemonised)
+                	std::cerr << "Error preparing clamav engine: " << cl_strerror(rc) << std::endl;
+                syslog(LOG_ERR, "Error preparing clamav engine: %s", cl_strerror(rc));
+                return DGCS_ERROR;
+	}
+	return DGCS_OK;
+	
+#else
+	rc = cl_load(cl_retdbdir(), &engine, &sigs, CL_DB_STDOPT);
 #ifdef DGDEBUG
-	std::cout << "engine: " << root << " virnum: " << virnum << std::endl;
+	std::cout << "engine: " << engine << " sigs: " << sigs << std::endl;
 #endif
 	if (rc != 0) {
 		if (!is_daemonised)
@@ -277,7 +338,7 @@
 		syslog(LOG_ERR, "Error loading clamav db: %s", cl_strerror(rc));
 		return DGCS_ERROR;
 	}
-	rc = cl_build(root);
+	rc = cl_build(engine);
 	if (rc != 0) {
 		if (!is_daemonised)
 			std::cerr << "Error building clamav db: " << cl_strerror(rc) << std::endl;
@@ -285,4 +346,5 @@
 		return DGCS_ERROR;
 	}
 	return DGCS_OK;
+#endif
 }