Update of /cvsroot/openantivirus/samba-vscan/clamav
In directory sc8-pr-cvs1:/tmp/cvs-serv29535/clamav
Modified Files:
Tag: VSCAN_0_3
vscan-clamav.c vscan-clamav.h vscan-clamav_core.c
Log Message:
added support for libclamav into vscan-clamav (clamd still support).
use --wih-clamav to enable libclamav support. Build currently, but
not usable with Samba 3.0.0 up to now. Reason unkown.
Index: vscan-clamav.c
===================================================================
RCS file: /cvsroot/openantivirus/samba-vscan/clamav/vscan-clamav.c,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -d -r1.1.2.2 -r1.1.2.3
--- vscan-clamav.c 12 Sep 2003 07:12:14 -0000 1.1.2.2
+++ vscan-clamav.c 1 Dec 2003 13:20:40 -0000 1.1.2.3
@@ -42,6 +42,10 @@
#include "vscan-vfs.h"
+#ifdef LIBCLAMAV
+#include <clamav.h>
+#endif
+
#define VSCAN_MODULE_STR "vscan-clamav"
fstring config_file; /* location of config file, either
@@ -87,6 +91,12 @@
pstring exclude_file_types; /* list of file types which should be excluded from scanning */
+#ifdef LIBCLAMAV
+struct cl_node *clamav_root = NULL;
+struct cl_limits clamav_limits;
+BOOL clamav_loaded = False;
+#endif
+
/* module version */
static const char module_id[]=VSCAN_MODULE_STR" "SAMBA_VSCAN_VERSION_STR;
@@ -140,8 +150,12 @@
lrufiles_invalidate_time = atol(value);
DEBUG(3, ("lru file entry lifetime is: %li\n", (long)lrufiles_invalidate_time));
} else if ( StrCaseCmp("clamd socket name", param) == 0) {
+#ifdef LIBCLAMAV
+ DEBUG(3, ("clamd socket name not supported when linked against lib clamav\n"));
+#else
fstrcpy(clamd_socket_name, value);
DEBUG(3, ("clamd socket name is %s\n", clamd_socket_name));
+#endif
} else if ( StrCaseCmp("exclude file types", param) == 0 ) {
pstrcpy(exclude_file_types, value);
} else
@@ -252,6 +266,11 @@
if (!retval) vscan_syslog("ERROR: could not parse configuration file '%s'. File not found or not read-able. Using compiled-in defaults", config_file);
#endif
+#ifdef LIBCLAMAV
+ /* initialise lib clamav */
+ vscan_clamav_lib_init();
+#endif
+
/* initialise lrufiles list */
DEBUG(5, ("init lrufiles list\n"));
lrufiles_init(max_lrufiles, lrufiles_invalidate_time);
@@ -278,6 +297,10 @@
vscan_syslog("INFO: disconnected");
+#ifdef LIBCLAMAV
+ vscan_clamav_lib_done();
+#endif
+
lrufiles_destroy_all();
filetype_close();
@@ -351,6 +374,8 @@
} else
{
+
+#ifndef LIBCLAMAV
/* open socket */
sockfd = vscan_clamav_init();
@@ -360,7 +385,7 @@
errno = EACCES;
return -1;
} else if ( sockfd >= 0 ) {
-
+#endif
safe_strcpy(client_ip, conn->client_address, CLIENT_IP_SIZE -1);
/* must file actually be scanned? */
@@ -370,10 +395,11 @@
/* deny access */
if ( verbose_file_logging )
vscan_syslog("File '%s' has already been scanned and marked as infected. Not scanned any more. Access denied", filepath);
-
+
+#ifndef LIBCLAMAV
/* close socket */
vscan_clamav_end(sockfd);
-
+#endif
/* deny access */
errno = EACCES;
return -1;
@@ -382,8 +408,10 @@
if ( verbose_file_logging )
vscan_syslog("File '%s' has already been scanned, not marked as infected and not modified. Not scanned anymore. Access granted", filepath);
+#ifndef LIBCLAMAV
/* close socket */
vscan_clamav_end(sockfd);
+#endif
/* grant access */
#if (SMB_VFS_INTERFACE_VERSION >= 6)
@@ -395,11 +423,17 @@
/* ok, we must check the file */
/* scan file */
+#ifdef LIBCLAMAV
+ retval = vscan_clamav_scanfile_lib(filepath, client_ip);
+#else
retval = vscan_clamav_scanfile(sockfd, filepath, client_ip);
+#endif
if ( retval == -2 && deny_access_on_minor_error ) {
/* a minor error occured - deny access */
vscan_syslog("ERROR: daemon failed with a minor error - access to file %s denied", fname);
+#ifndef LIBCLAMAV
vscan_clamav_end(sockfd);
+#endif
/* to be safe, remove file from lrufiles */
lrufiles_delete(filepath);
@@ -410,8 +444,9 @@
} else if ( retval == -1 && deny_access_on_error ) {
/* an error occured - can not communicate to daemon - deny access */
vscan_syslog("ERROR: can not communicate to clamd - access to file %s denied", fname);
+#ifdef LIBCLAMAV
vscan_clamav_end(sockfd);
-
+#endif
/* to be safe, remove file from lrufiles */
lrufiles_delete(filepath);
@@ -421,8 +456,9 @@
return -1;
} else if ( retval == 1 ) {
/* virus found */
+#ifndef LIBCLAMAV
vscan_clamav_end(sockfd);
-
+#endif
/* do action ... */
#if (SMB_VFS_INTERFACE_VERSION >= 6)
@@ -441,10 +477,14 @@
/* file is clean, add to lrufiles */
lrufiles_add(filepath, stat_buf.st_mtime, False);
}
+#ifndef LIBCLAMAV
}
+#endif
+#ifndef LIBCLAMAV
/* close socket */
vscan_clamav_end(sockfd);
+#endif
}
#if (SMB_VFS_INTERFACE_VERSION >= 6)
return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
@@ -506,8 +546,12 @@
if ( sockfd >= 0 ) {
safe_strcpy(client_ip, fsp->conn->client_address, CLIENT_IP_SIZE -1);
/* scan only file, do nothing */
+#ifdef LIBCLAMAV
+ rv = vscan_clamav_scanfile_lib(filepath, client_ip);
+#else
rv = vscan_clamav_scanfile(sockfd, filepath, client_ip);
vscan_clamav_end(sockfd);
+#endif
if ( rv == 1 ) {
/* virus was found */
#if (SMB_VFS_INTERFACE_VERSION >= 6)
@@ -566,7 +610,7 @@
#endif
#endif
- openlog("smbd_"VSCAN_MODULE_STR, LOG_PID, SYSLOG_FACILITY);
+ openlog("smbd_"VSCAN_MODULE_STR, LOG_PID, SYSLOG_FACILITY);
#if SAMBA_VERSION_MAJOR==3
/* Samba 3.0 alphaX */
Index: vscan-clamav.h
===================================================================
RCS file: /cvsroot/openantivirus/samba-vscan/clamav/vscan-clamav.h,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -d -r1.1.2.2 -r1.1.2.3
--- vscan-clamav.h 12 Sep 2003 07:12:15 -0000 1.1.2.2
+++ vscan-clamav.h 1 Dec 2003 13:20:40 -0000 1.1.2.3
@@ -3,7 +3,6 @@
#include "vscan-global.h"
-
/* Configuration Section :-) */
/* Clam AntiVirus stuff:
@@ -82,6 +81,11 @@
/* functions by vscan-clamav_core */
/* opens socket */
int vscan_clamav_init(void);
+
+void vscan_clamav_lib_init();
+void vscan_clamav_lib_done();
+
+
/* scans a file */
int vscan_clamav_scanfile(int sockfd, char *scan_file, char *client_ip);
/* closes socket */
Index: vscan-clamav_core.c
===================================================================
RCS file: /cvsroot/openantivirus/samba-vscan/clamav/vscan-clamav_core.c,v
retrieving revision 1.5.2.1
retrieving revision 1.5.2.2
diff -u -d -r1.5.2.1 -r1.5.2.2
--- vscan-clamav_core.c 14 Jul 2003 13:09:15 -0000 1.5.2.1
+++ vscan-clamav_core.c 1 Dec 2003 13:20:40 -0000 1.5.2.2
@@ -15,11 +15,51 @@
#include "vscan-global.h"
#include "vscan-clamav_core.h"
+#ifdef LIBCLAMAV
+#include <clamav.h>
+#endif
+
extern BOOL verbose_file_logging;
extern BOOL send_warning_message;
extern fstring clamd_socket_name;
+#ifdef LIBCLAMAV
+extern struct cl_node *clamav_root;
+extern struct cl_limits clamav_limits;
+extern BOOL clamav_loaded;
+#endif
+
+
+#ifdef LIBCLAMAV
+void vscan_clamav_lib_init()
+{
+ int ret;
+ int no = 0;
+
+ if ( (ret = cl_loaddbdir(cl_retdbdir(), &clamav_root, &no)) ) {
+ vscan_syslog("ERROR: could not load clamav database, reason '%s'", cl_perror(ret));
+ clamav_loaded = False;
+ } else {
+
+ clamav_loaded = True;
+ DEBUG(3, ("Loaded %d virus signatures\n", no));
+
+ /* build the trie */
+ cl_buildtrie(clamav_root);
+
+ /* FIXME: this should be configurable */
+ /* set up archive limits */
+ clamav_limits.maxfiles = 1000; /* max files */
+ clamav_limits.maxfilesize = 10 * 1048576; /* maximal archived file size == 10 Mb */
+ clamav_limits.maxreclevel = 8; /* maximal recursion level */
+
+ }
+}
+#endif /* LIBCLAMAV */
+
+
+
/* initialise socket to clamd
returns -1 on error or the socket descriptor */
int vscan_clamav_init(void)
@@ -61,7 +101,37 @@
}
+#ifdef LIBCLAMAV
+/* Scan a file using lib clamav
+ Returns -2 on minor error, -1 on error, 0 if a no virus was found, 1 if a virus was found
+*/
+int vscan_clamav_scanfile_lib(char* scan_file, char* client_ip)
+{
+ int ret, no = 0;
+ unsigned long int size = 0;
+ char* virname;
+ ret = cl_scanfile(scan_file, &virname, &size, clamav_root, &clamav_limits, CL_ARCHIVE);
+ if ( ret == CL_CLEAN ) { /* no virus found */
+ if (verbose_file_logging) {
+ vscan_syslog("INFO: file %s is clean", scan_file);
+ }
+ return 0;
+ } else if ( ret == CL_VIRUS ) { /* virus found */
+ vscan_clamav_log_virus(scan_file, virname, client_ip);
+ return 1;
+ } else { /* error */
+ if (verbose_file_logging) {
+ vscan_syslog("ERROR: file %s not found, not readable or an error occured", scan_file);
+ }
+ return -2;
+ }
+
+ /* shouldn't get there */
+ return -2;
+
+}
+#endif
/*
Scans a file (*FILE*, not a directory - keep that in mind) for a virus
@@ -76,7 +146,7 @@
int response = 0;
char buff[1024];
char *vir = NULL, *p1 = NULL;
- FILE *fpin;
+ FILE *fpin;
/* open stream sockets */
fpin = fdopen(sockfd, "r");
@@ -151,6 +221,14 @@
vscan_syslog("ERROR: can not get result from clamd");
return -1;
}
+
+
+#ifdef LIBCLAMAV
+void vscan_clamav_lib_done()
+{
+ cl_freetrie(clamav_root);
+}
+#endif
/*
close socket
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.