[Pkg-clamav-commits] [SCM] Debian repository for ClamAV branch, debian/unstable, updated. debian/0.95+dfsg-1-6156-g094ec9b

Tomasz Kojm tkojm at clamav.net
Sun Apr 4 01:19:52 UTC 2010


The following commit has been merged in the debian/unstable branch:
commit d46cdd59ea3047ee7b14a5cabde4857b11377c84
Author: Tomasz Kojm <tkojm at clamav.net>
Date:   Fri Feb 12 15:52:19 2010 +0100

    libclamav: add cl_countsigs() (bb#1473)

diff --git a/ChangeLog b/ChangeLog
index ea2ea19..02884f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Fri Feb 12 15:51:19 CET 2010 (tk)
+---------------------------------
+ * libclamav: add cl_countsigs() (bb#1473)
+
 Tue Feb  9 20:44:11 CET 2010 (acab)
 -----------------------------------
  * clamav-milter: allow SkipAuthenticated to read names from a file
diff --git a/libclamav/clamav.h b/libclamav/clamav.h
index 6bb1f1c..f998c65 100644
--- a/libclamav/clamav.h
+++ b/libclamav/clamav.h
@@ -112,6 +112,11 @@ typedef enum {
 /* recommended scan settings */
 #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)
 
+/* cl_countsigs options */
+#define CL_COUNTSIGS_OFFICIAL	    0x1
+#define CL_COUNTSIGS_UNOFFICIAL	    0x2
+#define CL_COUNTSIGS_ALL	    (CL_COUNTSIGS_OFFICIAL | CL_COUNTSIGS_UNOFFICIAL)
+
 struct cl_engine;
 struct cl_settings;
 
@@ -207,6 +212,9 @@ 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);
 
+/* count signatures */
+extern int cl_countsigs(const char *path, unsigned int countoptions, unsigned int *sigs);
+
 /* enable debug messages */
 extern void cl_debug(void);
 
diff --git a/libclamav/libclamav.map b/libclamav/libclamav.map
index 5d83ff2..643a283 100644
--- a/libclamav/libclamav.map
+++ b/libclamav/libclamav.map
@@ -26,6 +26,7 @@ CLAMAV_PUBLIC {
     cl_statchkdir;
     cl_statfree;
     cl_statinidir;
+    cl_countsigs;
     cl_strerror;
   local:
     *;
diff --git a/libclamav/readdb.c b/libclamav/readdb.c
index a94db15..9e9be12 100644
--- a/libclamav/readdb.c
+++ b/libclamav/readdb.c
@@ -3014,3 +3014,108 @@ int cl_engine_addref(struct cl_engine *engine)
 
     return CL_SUCCESS;
 }
+
+static int countentries(const char *dbname, unsigned int *sigs)
+{
+	char buffer[CLI_DEFAULT_LSIG_BUFSIZE + 1];
+	FILE *fs;
+	unsigned int entry = 0;
+
+    fs = fopen(dbname, "r");
+    if(!fs) {
+	cli_errmsg("countentries: Can't open file %s\n", dbname);
+	return CL_EOPEN;
+    }
+    while(fgets(buffer, sizeof(buffer), fs)) {
+	if(buffer[0] == '#')
+	    continue;
+	entry++;
+    }
+    fclose(fs);
+    *sigs += entry;
+    return CL_SUCCESS;
+}
+
+static int countsigs(const char *dbname, unsigned int options, unsigned int *sigs)
+{
+    if((cli_strbcasestr(dbname, ".cvd") || cli_strbcasestr(dbname, ".cld"))) {
+	if(options & CL_COUNTSIGS_OFFICIAL) {
+		struct cl_cvd *cvd = cl_cvdhead(dbname);
+	    if(!cvd) {
+		cli_errmsg("countsigs: Can't parse %s\n", dbname);
+		return CL_ECVD;
+	    }
+	    *sigs += cvd->sigs;
+	    cl_cvdfree(cvd);
+	}
+    } else if(cli_strbcasestr(dbname, ".cbc")) {
+	if(options & CL_COUNTSIGS_UNOFFICIAL)
+	    (*sigs)++;
+
+    } else if(cli_strbcasestr(dbname, ".wdb") || cli_strbcasestr(dbname, ".fp") || cli_strbcasestr(dbname, ".ftm") || cli_strbcasestr(dbname, ".cfg")) {
+	/* ignore */
+
+    } else if((options & CL_COUNTSIGS_UNOFFICIAL) && CLI_DBEXT(dbname)) {
+	return countentries(dbname, sigs);
+    }
+
+    return CL_SUCCESS;
+}
+
+int cl_countsigs(const char *path, unsigned int countoptions, unsigned int *sigs)
+{
+	struct stat sb;
+	char fname[1024];
+	struct dirent *dent;
+#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
+	union {
+	    struct dirent d;
+	    char b[offsetof(struct dirent, d_name) + NAME_MAX + 1];
+	} result;
+#endif
+	DIR *dd;
+	int ret;
+
+    if(!sigs)
+	return CL_ENULLARG;
+
+    if(stat(path, &sb) == -1) {
+	cli_errmsg("cl_countsigs: Can't stat %s\n", path);
+	return CL_ESTAT;
+    }
+
+    if((sb.st_mode & S_IFMT) == S_IFREG) {
+	return countsigs(path, countoptions, sigs);
+
+    } else if((sb.st_mode & S_IFMT) == S_IFDIR) {
+	if((dd = opendir(path)) == NULL) {
+	    cli_errmsg("cl_countsigs: Can't open directory %s\n", path);
+	    return CL_EOPEN;
+	}
+#ifdef HAVE_READDIR_R_3
+	while(!readdir_r(dd, &result.d, &dent) && dent) {
+#elif defined(HAVE_READDIR_R_2)
+	while((dent = (struct dirent *) readdir_r(dd, &result.d))) {
+#else
+	while((dent = readdir(dd))) {
+#endif
+	    if(dent->d_ino) {
+		if(strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..") && CLI_DBEXT(dent->d_name)) {
+		    snprintf(fname, sizeof(fname), "%s"PATHSEP"%s", path, dent->d_name);
+		    fname[sizeof(fname) - 1] = 0;
+		    ret = countsigs(fname, countoptions, sigs);
+		    if(ret != CL_SUCCESS) {
+			closedir(dd);
+			return ret;
+		    }
+		}
+	    }
+	}
+	closedir(dd);
+    } else {
+	cli_errmsg("cl_countsigs: Unsupported file type\n");
+	return CL_EARG;
+    }
+
+    return CL_SUCCESS;
+}
diff --git a/win32/libclamav.def b/win32/libclamav.def
index 1256818..2118218 100644
--- a/win32/libclamav.def
+++ b/win32/libclamav.def
@@ -26,6 +26,7 @@ EXPORTS cl_engine_addref
 EXPORTS cl_statinidir
 EXPORTS cl_statchkdir
 EXPORTS cl_statfree
+EXPORTS cl_countsigs
 
 ; cli_stuff - should be mangled or exported by ordinal only
 EXPORTS cli_gentemp

-- 
Debian repository for ClamAV



More information about the Pkg-clamav-commits mailing list