Update of /cvsroot/openantivirus/samba-vscan/f-secure
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26082
Modified Files:
Tag: VSCAN_0_3
vscan-fsav_core.c
Log Message:
added some error checking; modified some syslog messages; some other
fixes
Index: vscan-fsav_core.c
===================================================================
RCS file: /cvsroot/openantivirus/samba-vscan/f-secure/Attic/vscan-fsav_core.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-fsav_core.c 8 Jan 2004 18:41:05 -0000 1.1.2.2
+++ vscan-fsav_core.c 10 Mar 2004 15:59:09 -0000 1.1.2.3
@@ -4,6 +4,8 @@
* virusscanning module for samba. provides helper methods to call fsecure
*
* Copyright (C) Monex AG Oliver Jehle, 2003
+ * Copyright (C) Rainer Link, 2004
+ * OpenAntiVirus.org <rainer-pBPPa8WU5k41Tgt60Rntydi2O/[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,12 +26,17 @@
#include "vscan-global.h"
#include "vscan-fsav.h"
+extern BOOL verbose_file_logging;
+extern BOOL send_warning_message;
+
static const char module_id[] = VSCAN_MODULE_STR " " SAMBA_VSCAN_VERSION_STR;
/**
* create handle
*
* all functions use a handle
+ *
+ * returns NULL on failure
*/
@@ -243,16 +250,27 @@
* switch user id of the fsavd process to the effective user id, else we cant connect
*/
- setreuid(geteuid(), geteuid());
- setsid();
+ rc=setreuid(geteuid(), geteuid());
+ if (rc != 0) {
+ vscan_syslog("ERROR: slave cannot setreuid %s (%i)",
+ strerror(errno), errno);
+ exit(0);
+ }
+ rc=setsid();
+ if (rc != 0) {
+ vscan_syslog("ERROR: slave cannot setsid %s (%i)",
+ strerror(errno), errno);
+ exit(0);
+ }
+
rc = execlp(binary, binary, config, socket, dbdir,
"--standalone", (char *) 0);
if (rc != 0) {
DEBUG(5,
- ("samba-vscan (%s) slave cannot execlp %s (%i)\n ",
- module_id, strerror(errno), errno));
+ vscan_syslog("ERROR: slave cannot execlp %s %s (%i)",
+ binary, strerror(errno), errno);
}
exit(0);
}
@@ -262,35 +280,52 @@
/**
* scan a file
*
+ * Returns -2 on a minor error, -1 on error, 0 if no virus was found,
+ * 1 if a virus was found
*/
int fsav_scan(fsav_handle * h, char *file)
{
if (!h)
- return 1;
+ return -1;
DEBUG(5, ("samba-vscan (%s) scan %s\n ", module_id, file));
+ if ( verbose_file_logging )
+ vscan_syslog("INFO: Scanning file : '%s'", scan_file);
+
fsav_clean_handle(h);
snprintf(h->buffer, BUFFERSIZE, "SCAN\t%s\n", file);
- if (fsav_process(h))
- return 2;
+ if (fsav_process(h)) {
+ vscan_syslog("ERROR: unknown error occured");
+ return -1;
+ }
if (h->infected) {
+ /* virus found */
h->rc = 1;
+ /* FIXME: is parsing of virus name possible based on fsavd resonse?!? */
+ vscan_syslog_alert("ALERT - Scan result: '%s' infected with virus, client: '%s'",
+ infected_file, client_ip);
} else {
if (h->fail)
- h->rc = 2;
+ /* error */
+ h->rc = -1;
+ if ( verbose_file_logging )
+ vscan_syslog("ERROR: file %s not found, not readable or an error occured", file);
+
else
+ /* no virus found, everything OK */
h->rc = 0;
+ if ( verbose_file_logging )
+ vscan_syslog("INFO: file %s is clean", file);
}
DEBUG(5,
("samba-vscan (%s) scan %s rc=(%i) buffer=%s\n", module_id,
file, h->rc, h->buffer));
- if (h->rc == 1)
- vscan_syslog("samba-vscan (%s) found virus in %s",
- module_id, file);
+
return h->rc;
+
}
/**
@@ -334,8 +369,8 @@
if (h->sockd < 0) {
vscan_syslog
- ("samba-vscan (%s) socket_create cannot connect %s",
- module_id, h->server->sun_path);
+ ("ERROR: socket_create cannot connect %s",
+ h->server->sun_path);
h->rc = 2;
}
DEBUG(5,
@@ -350,6 +385,7 @@
* connect to a fsav instance, if not successfull and in userinstance mode, try
* start a new instance
*
+ * returns 0 on success, 1 or 2 as error
*/
int fsav_connect_handle(fsav_handle * h)
@@ -369,20 +405,50 @@
h->rc = 2;
return h->rc;
}
- fsav_switch_uid(h);
+ if(fsav_switch_uid(h)) {
+ DEBUG(5,
+ ("samba-vscan (%s) switch user not successfull\n",
+ module_id));
+ h->rc = 2;
+ return h->rc;
+ }
+
DEBUG(5, ("samba-vscan (%s) connect try connect \n", module_id));
rc = connect(h->sockd, (struct sockaddr *) h->server,
sizeof(struct sockaddr_un));
- fsav_switch_uid(h);
+
+
+ if(fsav_switch_uid(h)) {
+ DEBUG(5,
+ ("samba-vscan (%s) switch user back not successfull\n",
+ module_id));
+ h->rc = 2;
+ return h->rc;
+ }
+
if (rc != 0 && h->userinstance) {
DEBUG(5,
("samba-vscan (%s) connect try restart and connect \n",
module_id));
fsav_start(h);
- fsav_switch_uid(h);
+
+ if(fsav_switch_uid(h)) {
+ DEBUG(5,
+ ("samba-vscan (%s) switch user not successfull\n",
+ module_id));
+ h->rc = 2;
+ return h->rc;
+ }
rc = connect(h->sockd, (struct sockaddr *) h->server,
sizeof(struct sockaddr_un));
- fsav_switch_uid(h);
+
+ if(fsav_switch_uid(h)) {
+ DEBUG(5,
+ ("samba-vscan (%s) switch user not successfull\n",
+ module_id));
+ h->rc = 2;
+ return h->rc;
+ }
}
DEBUG(5,
("samba-vscan (%s) connect done rc=%i \n", module_id, rc));
@@ -455,7 +521,7 @@
return h->rc;
}
/**
- * switch the uid , depend on the uid set in the handle
+ * switch the uid, depends on the uid set in the handle
*
*/
void fsav_switch_uid(fsav_handle * h) {
@@ -468,9 +534,11 @@
if (h->uid == -1) {
h->uid = geteuid();
seteuid(h->connect_uid);
- DEBUG(5,("samba-vscan (%s) switching user from (%i) to (%i)\n ", module_id, h->connect_uid,h->uid));
+ DEBUG(5,("samba-vscan (%s) switching user from (%i) to (%i)\n ",
+ module_id, h->connect_uid,h->uid));
} else {
- DEBUG(5,("samba-vscan (%s) switching user back (%i) to (%i)\n ", module_id, h->connect_uid,h->uid));
+ DEBUG(5,("samba-vscan (%s) switching user back (%i) to (%i)\n ",
+ module_id, h->connect_uid,h->uid));
seteuid(h->uid);
h->uid = -1;
}
@@ -479,6 +547,7 @@
* process
*
* send a command to fsav and handle the result
+ * Returns 0 on success, 1 on error
*/
int fsav_process(fsav_handle * h)
@@ -492,10 +561,22 @@
("samba-vscan (%s) process write %s\n ", module_id,
h->buffer));
h->rc = 0;
- fsav_switch_uid(h);
+ if(fsav_switch_uid(h)) {
+ DEBUG(5,
+ ("samba-vscan (%s) switch user not successfull\n",
+ module_id));
+ h->rc = 2;
+ return h->rc;
+ }
+
if (write(h->sockd, h->buffer, strlen(h->buffer)) <= 0) {
h->rc = 1;
- fsav_switch_uid(h);
+ fsav_switch_uid(h);
+ if(fsav_switch_uid(h)) {
+ DEBUG(5,
+ ("samba-vscan (%s) switch user back not successfull\n",
+ module_id));
+ }
return h->rc;
}
fsav_clean_handle(h);
@@ -557,7 +638,13 @@
}
- fsav_switch_uid(h);
+ fsav_switch_uid(h);
+ if(fsav_switch_uid(h)) {
+ DEBUG(5,
+ ("samba-vscan (%s) switch user back not successfull\n",
+ module_id));
+ }
+
DEBUG(5,
("samba-vscan (%s) process read end infected: %i fail: %i configured: %i buffer: %s \n ",
module_id, h->infected, h->fail, h->configured, h->buffer));
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&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.