samba-vscan/clamav vscan-clamav.c,1.1.2.8,1.1.2.9
Rainer Link <[email protected]> Thu, 09 Sep 2004 13:05:04 +0000
| Newsgroups | gmane.comp.security.virus.openantivirus.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/openantivirus/samba-vscan/clamav
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7503
Modified Files:
Tag: VSCAN_0_3
vscan-clamav.c
Log Message:
simplified vscan_open, so that onyl one #ifdef LIBCLAMAV is needed, and
only one SMB_VFS_NEXT_OPEN/default_vfs_ops.open is nedded.
more error messages when the daemon fails
Patch by Helmut
Index: vscan-clamav.c
===================================================================
RCS file: /cvsroot/openantivirus/samba-vscan/clamav/vscan-clamav.c,v
retrieving revision 1.1.2.8
retrieving revision 1.1.2.9
diff -u -d -r1.1.2.8 -r1.1.2.9
--- vscan-clamav.c 9 Sep 2004 13:03:54 -0000 1.1.2.8
+++ vscan-clamav.c 9 Sep 2004 13:05:02 -0000 1.1.2.9
@@ -343,15 +343,8 @@
static int vscan_open(struct connection_struct *conn, PROTOTYPE_CONST char *fname, int flags, mode_t mode)
#endif
{
- int retval, must_be_checked;
SMB_STRUCT_STAT stat_buf;
-#ifndef LIBCLAMAV
- int sockfd;
-#endif
pstring filepath;
- char client_ip[CLIENT_IP_SIZE];
-
- int rc;
/* Assemble complete file path */
pstrcpy(filepath, conn->connectpath);
@@ -362,11 +355,6 @@
/* scan files while opening? */
if ( !scan_on_open ) {
DEBUG(3, ("samba-vscan - open: File '%s' not scanned as scan_on_open is not set\n", fname));
-#if (SMB_VFS_INTERFACE_VERSION >= 6)
- return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
-#else
- return default_vfs_ops.open(conn, fname, flags, mode);
-#endif
}
#if (SMB_VFS_INTERFACE_VERSION >= 6)
else if ( (SMB_VFS_NEXT_STAT(handle, conn, fname, &stat_buf)) != 0 ) { /* an error occured */
@@ -374,141 +362,82 @@
else if ( (default_vfs_ops.stat(conn, fname, &stat_buf)) != 0 ) { /* an error occured */
#endif
vscan_syslog("ERROR: File %s not found, not readable or an error occured", fname);
-#if (SMB_VFS_INTERFACE_VERSION >= 6)
- return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
-#else
- return default_vfs_ops.open(conn, fname, flags, mode);
-#endif
}
else if ( S_ISDIR(stat_buf.st_mode) ) { /* is it a directory? */
if ( verbose_file_logging )
vscan_syslog("INFO: File %s is a directory! Not scanned!", fname);
-#if (SMB_VFS_INTERFACE_VERSION >= 6)
- return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
-#else
- return default_vfs_ops.open(conn, fname, flags, mode);
-#endif
}
else if ( ( stat_buf.st_size > max_size ) && ( max_size > 0 ) ) { /* file is too large */
if ( verbose_file_logging )
vscan_syslog("INFO: File %s is larger than specified maximum file size! Not scanned!", fname);
-#if (SMB_VFS_INTERFACE_VERSION >= 6)
- return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
-#else
- return default_vfs_ops.open(conn, fname, flags, mode);
-#endif
}
else if ( stat_buf.st_size == 0 ) { /* do not scan empty files */
if ( verbose_file_logging )
vscan_syslog("INFO: File %s has size zero! Not scanned!", fname);
-#if (SMB_VFS_INTERFACE_VERSION >= 6)
- return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
-#else
- return default_vfs_ops.open(conn, fname, flags, mode);
-#endif
}
else if ( filetype_skipscan(filepath) == 1 ) {
if ( verbose_file_logging )
vscan_syslog("File '%s' not scanned as file type is on exclude list", filepath);
-#if (SMB_VFS_INTERFACE_VERSION >= 6)
- return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
-#else
- return default_vfs_ops.open(conn, fname, flags, mode);
-#endif
-
} else
{
+ char client_ip[CLIENT_IP_SIZE];
+ int must_be_checked;
-#ifndef LIBCLAMAV
- /* open socket */
- sockfd = vscan_clamav_init();
+ safe_strcpy(client_ip, conn->client_address, CLIENT_IP_SIZE -1);
+ /* must file actually be scanned? */
+ must_be_checked = lrufiles_must_be_checked(filepath, stat_buf.st_mtime);
+ if ( must_be_checked == -1 ) {
+ /* file has already been checked and marked as infected */
+ /* 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);
- if ( sockfd == -1 && deny_access_on_error ) {
- /* an error occured - can not communicate to daemon - deny access */
- vscan_syslog("ERROR: can not communicate to daemon - access denied");
+ /* deny access */
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? */
- must_be_checked = lrufiles_must_be_checked(filepath, stat_buf.st_mtime);
- if ( must_be_checked == -1 ) {
- /* file has already been checked and marked as infected */
- /* 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;
- } else if ( must_be_checked == 0 ) {
- /* file has already been checked, not marked as infected and not modified */
- 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)
- return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
-#else
- return default_vfs_ops.open(conn, fname, flags, mode);
-#endif
- }
+ } else if ( must_be_checked == 0 ) {
+ /* file has already been checked, not marked as infected and not modified */
+ 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);
+ }
+ else {
/* ok, we must check the file */
+ int retval;
- /* scan file */
#ifdef LIBCLAMAV
retval = vscan_clamav_lib_scanfile(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);
+#else /* LIBCLAMAV */
+ int sockfd;
- /* deny access */
- errno = EACCES;
- return -1;
- } 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);
-#ifndef LIBCLAMAV
+ /* open socket */
+ sockfd = vscan_clamav_init();
+ if ( sockfd == -1 ) {
+ if( deny_access_on_error ) {
+ /* an error occured - can not communicate to daemon - deny access */
+ vscan_syslog("ERROR: can not communicate to daemon - access denied");
+ errno = EACCES;
+ return -1;
+ }
+ vscan_syslog("ERROR: can not communicate to daemon - Not scanned!");
+ retval = 3; /* Access allowed, not scanned */
+ } else
+ {
+ /* scan file */
+ retval = vscan_clamav_scanfile(sockfd, filepath, client_ip);
vscan_clamav_end(sockfd);
+ }
#endif
- /* to be safe, remove file from lrufiles */
- lrufiles_delete(filepath);
-
- /* deny access */
-
- errno = EACCES;
- return -1;
- } else if ( retval == 1 ) {
+ if ( 0 == retval ) {
+ /* file is clean, add to lrufiles */
+ lrufiles_add(filepath, stat_buf.st_mtime, False);
+ }
+ else if ( 1 == retval ) {
/* virus found */
-#ifndef LIBCLAMAV
- vscan_clamav_end(sockfd);
-#endif
/* do action ... */
-
#if (SMB_VFS_INTERFACE_VERSION >= 6)
- rc = vscan_do_infected_file_action(handle, conn, filepath, quarantine_dir, quarantine_prefix, infected_file_action);
+ vscan_do_infected_file_action(handle, conn, filepath, quarantine_dir, quarantine_prefix, infected_file_action);
#else
- rc = vscan_do_infected_file_action(&default_vfs_ops, conn, filepath, quarantine_dir, quarantine_prefix, infected_file_action);
+ vscan_do_infected_file_action(&default_vfs_ops, conn, filepath, quarantine_dir, quarantine_prefix, infected_file_action);
#endif
/* add/update file. mark file as infected! */
@@ -517,18 +446,37 @@
/* virus found, deny acces */
errno = EACCES;
return -1;
- } else if ( retval == 0 ) {
- /* file is clean, add to lrufiles */
- lrufiles_add(filepath, stat_buf.st_mtime, False);
- }
-#ifndef LIBCLAMAV
- }
-#endif
+ }
+ else if ( -2 == retval ) {
+ /* to be safe, remove file from lrufiles */
+ lrufiles_delete(filepath);
-#ifndef LIBCLAMAV
- /* close socket */
- vscan_clamav_end(sockfd);
-#endif
+ if( 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);
+
+ /* deny access */
+ errno = EACCES;
+ return -1;
+ }
+ /* a minor error occured - Not scanned */
+ vscan_syslog("ERROR: daemon failed with a minor error - file %s Not scanned!", fname);
+ } else if ( -1 == retval ) {
+ /* to be safe, remove file from lrufiles */
+ lrufiles_delete(filepath);
+
+ if( 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);
+
+ /* deny access */
+ errno = EACCES;
+ return -1;
+ }
+ /* an error occured - can not communicate to daemon - Not scanned */
+ vscan_syslog("ERROR: can not communicate to clamd - file %s Not scanned!", fname);
+ }
+ }
}
#if (SMB_VFS_INTERFACE_VERSION >= 6)
return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click