samba-vscan/global vscan-parameter.c,NONE,1.1.2.1 vscan-filetype.c,1.3.2.7,1.3.2.8 vscan-functions.c,1.7.2.1,1.7.2.2

Rainer Link <[email protected]>
Newsgroups gmane.comp.security.virus.openantivirus.cvs
Message-ID <[email protected]>
Update of /cvsroot/openantivirus/samba-vscan/global
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21244/global

Modified Files:
      Tag: VSCAN_0_3
	vscan-filetype.c vscan-functions.c 
Added Files:
      Tag: VSCAN_0_3
	vscan-parameter.c 
Log Message:
started some more code-reorganisation; not finished; could have
broken stuff


Index: vscan-filetype.c
===================================================================
RCS file: /cvsroot/openantivirus/samba-vscan/global/vscan-filetype.c,v
retrieving revision 1.3.2.7
retrieving revision 1.3.2.8
diff -u -d -r1.3.2.7 -r1.3.2.8
--- vscan-filetype.c	3 Apr 2004 17:50:26 -0000	1.3.2.7
+++ vscan-filetype.c	2 May 2004 19:45:31 -0000	1.3.2.8
@@ -15,8 +15,6 @@
  *
 */  
 
-/* FIXME: when module works correctly, increase value of DEBUG statements */
-
 #include "vscan-global.h"
 
 #ifdef HAVE_FILETYPE_SUPPORT

Index: vscan-functions.c
===================================================================
RCS file: /cvsroot/openantivirus/samba-vscan/global/vscan-functions.c,v
retrieving revision 1.7.2.1
retrieving revision 1.7.2.2
diff -u -d -r1.7.2.1 -r1.7.2.2
--- vscan-functions.c	14 Jul 2003 13:09:16 -0000	1.7.2.1
+++ vscan-functions.c	2 May 2004 19:45:31 -0000	1.7.2.2
@@ -3,7 +3,7 @@
  * 
  * provides commonly used functions 
  *
- * Copyright (C) Rainer Link, 2002
+ * Copyright (C) Rainer Link, 2002-2004
  *               OpenAntiVirus.org <rainer-pBPPa8WU5k41Tgt60Rntydi2O/[email protected]>
  *
  * This software is licensed under the GNU General Public License (GPL)
@@ -183,3 +183,73 @@
   return newstr;
 }
 
+
+int vscan_inet_socket_init(const char* daemon_name, const char* ip, const unsigned short int port)
+{
+        int sockfd;
+        struct sockaddr_in servaddr;
+
+        /* create socket */
+        if (( sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) {
+               vscan_syslog("ERROR: can not create socket!\n");
+               return -1;
+        }
+
+        bzero(&servaddr, sizeof(servaddr));
+        servaddr.sin_family = AF_INET;
+        servaddr.sin_port = htons(port);
+
+        /* hm, inet_pton may not exist on all systems - FIXME ! */
+        if ( inet_pton(AF_INET, ip, &servaddr.sin_addr) <= 0 ) {
+                vscan_syslog("ERROR: inet_pton failed!\n");
+                return -1;
+        }
+
+        /* connect to socket */
+        if ( connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0 )
+        {
+                vscan_syslog("ERROR: can not connect to %s (IP: '%s', port: '%d')!\n", daemon_name, ip, port);
+                return -1;
+        }
+
+
+        return sockfd;
+
+}
+
+int vscan_unix_socket_init(const char* daemon_name, const char* socket_name)
+{
+
+        int sockfd;
+        struct sockaddr_un servaddr;
+
+        /* create socket */
+        if (( sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0 ) {
+               vscan_syslog("ERROR: can not create socket!");
+               return -1;
+        }
+
+        bzero(&servaddr, sizeof(servaddr));
+        servaddr.sun_family = AF_UNIX;
+        safe_strcpy(servaddr.sun_path, socket_name, sizeof(servaddr.sun_path)-1);
+
+        /* connect to socket */
+        if ( connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0 ) {
+                vscan_syslog("ERROR: can not connect to %s (socket: '%s')!", daemon_name, socket_name);
+                return -1;
+        }
+
+    return sockfd;
+
+}
+
+
+void vscan_socket_end(int sockfd)
+{
+        /* sockfd == -1 indicates an error while connecting to socket */
+        if ( sockfd >= 0 ) {
+                close(sockfd);
+        }
+
+}
+

--- NEW FILE: vscan-parameter.c ---
/* $Id: vscan-parameter.c,v 1.1.2.1 2004/05/02 19:45:31 reniar Exp $ 
 *
 * Parses commonly-used parameters from the samba-style vscan configuration 
 * file
 *
 * Copyright (C) Rainer Link, 2004
 *		 OpenAntiVirus.org <rainer-pBPPa8WU5k41Tgt60Rntydi2O/[email protected]>
 *
 * This module is used to parse commonly-used parameters (i.e. which
 * are the same for most vscan-samba VFS module) from the corresponding
 * vscan-samba configuration file.
 *
 * This software is licensed under the GNU General Public License (GPL)
 * See: http://www.gnu.org/copyleft/gpl.html
 *
*/

#include "vscan-global.h"

BOOL do_common_parameter(vscan_config_struct *vscan_config, const char *param, const char *value)
{
	/* we assume we handled a common parameter */
	BOOL ret = True;

        if ( StrCaseCmp("max file size", param) == 0 ) {
                /* FIXME: sanity check missing! what, if value is out of range?
                   atoi returns int - what about LFS? atoi should be avoided!
                */
                vscan_config->common.max_size = atoi(value);
                DEBUG(3, ("max file size is: %d\n", vscan_config->common.max_size));
        } else if ( StrCaseCmp("verbose file logging", param) == 0 ) {
                set_boolean(&vscan_config->common.verbose_file_logging, value);
                DEBUG(3, ("verbose file logging is: %d\n", vscan_config->common.verbose_file_logging));
        } else if ( StrCaseCmp("scan on open", param) == 0 ) {
                set_boolean(&vscan_config->common.scan_on_open, value);
                DEBUG(3, ("scan on open: %d\n", vscan_config->common.scan_on_open));
        } else if ( StrCaseCmp("scan on close", param) == 0 ) {
                set_boolean(&vscan_config->common.scan_on_close, value);
                DEBUG(3, ("scan on close is: %d\n", vscan_config->common.scan_on_close));
        } else if ( StrCaseCmp("deny access on error", param) == 0 ) {
                set_boolean(&vscan_config->common.deny_access_on_error, value);
                DEBUG(3, ("deny access on error is: %d\n", vscan_config->common.deny_access_on_error));
        } else if ( StrCaseCmp("deny access on minor error", param) == 0 ) {
                set_boolean(&vscan_config->common.deny_access_on_minor_error, value);
                DEBUG(3, ("deny access on minor error is: %d\n", vscan_config->common.deny_access_on_minor_error));
        } else if ( StrCaseCmp("send warning message", param) == 0 ) {
                set_boolean(&vscan_config->common.send_warning_message, value);
                DEBUG(3, ("send warning message is: %d\n", vscan_config->common.send_warning_message));
        } else if ( StrCaseCmp("infected file action", param) == 0 ) {
                if (StrCaseCmp("quarantine", value) == 0) {
                        vscan_config->common.infected_file_action = INFECTED_QUARANTINE;
                } else if (StrCaseCmp("delete", value) == 0) {
                        vscan_config->common.infected_file_action = INFECTED_DELETE;
                } else if (StrCaseCmp("nothing", value) == 0) {
                        vscan_config->common.infected_file_action = INFECTED_DO_NOTHING;
                } else {
                        DEBUG(2, ("samba-vscan: badly formed infected file action in configuration file, parameter %s\n", value));
                }
                DEBUG(3, ("infected file action is: %d\n", vscan_config->common.infected_file_action));
        } else if ( StrCaseCmp("quarantine directory", param) == 0 ) {
                fstrcpy(vscan_config->common.quarantine_dir, value);
                DEBUG(3, ("quarantine directory is: %s\n", vscan_config->common.quarantine_dir));
        } else if ( StrCaseCmp("quarantine prefix", param) == 0 ) {
                fstrcpy(vscan_config->common.quarantine_prefix, value);
                DEBUG(3, ("quarantine prefix is: %s\n", vscan_config->common.quarantine_prefix));
        } else if ( StrCaseCmp("max lru files entries", param) == 0 ) {
                vscan_config->common.max_lrufiles = atoi(value);
                DEBUG(3, ("max lru files entries is: %d\n", vscan_config->common.max_lrufiles));
        } else if ( StrCaseCmp("lru file entry lifetime", param) == 0 ) {
                vscan_config->common.lrufiles_invalidate_time = atol(value);
                DEBUG(3, ("lru file entry lifetime is: %li\n", (long)vscan_config->common.lrufiles_invalidate_time));
        } else if ( StrCaseCmp("exclude file types", param) == 0 ) {
                pstrcpy(vscan_config->common.exclude_file_types, value);
                DEBUG(3, ("Exclude list is: %s\n", vscan_config->common.exclude_file_types));
	} else {
		DEBUG(1, ("unkown common parameter: %s\n", param));
		ret = False;
	}

	return ret;

}




-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
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.