samba-vscan/global vscan-quarantine.c,1.4.2.1,1.4.2.2

Rainer Link <[email protected]> Mon, 17 Jan 2005 13:42:59 +0000
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-serv21479

Modified Files:
      Tag: VSCAN_0_3
	vscan-quarantine.c 
Log Message:
added some doxygen comments
use smb_mkstemp for generating temp file name in quarantine


Index: vscan-quarantine.c
===================================================================
RCS file: /cvsroot/openantivirus/samba-vscan/global/vscan-quarantine.c,v
retrieving revision 1.4.2.1
retrieving revision 1.4.2.2
diff -u -d -r1.4.2.1 -r1.4.2.2
--- vscan-quarantine.c	14 Jul 2003 13:09:16 -0000	1.4.2.1
+++ vscan-quarantine.c	17 Jan 2005 13:42:57 -0000	1.4.2.2
@@ -15,8 +15,14 @@
 
 #include "vscan-global.h"
 
-/*
-  deletes the infected file
+/**
+ * deletes the infected file
+ * @param handle		pointer to vfs_handle_struct structure
+ * @param connection_struct	pointer to connect_struct structure
+ * @param virus_file		filepath of infected file	
+ * @return
+ *	 0			success, file deleted
+ *     !=0			failure, file not deleted
 */
  
 #if (SMB_VFS_INTERFACE_VERSION >= 6)
@@ -35,22 +41,51 @@
 	return 0;
 }
 
-/*
-  moves the infected file to quarantine
+/**
+ * moves the infected file to quarantine
+ * @param handle		pointer to vfs_handle_struct structure
+ * @param conn			pointer to connection_struct strucute
+ * @param virus_file		filepath of infected file
+ * @param q_dir			quarantine directory
+ * @param q_prefix		prefix of quarantine file
+ * @return
+ *	 0 			success, file quarantined
+ *     !=0			failure, file not quarantined
 */
 #if (SMB_VFS_INTERFACE_VERSION >= 6)
 int vscan_quarantine_virus(vfs_handle_struct *handle, connection_struct *conn, char *virus_file, char *q_dir, char *q_prefix) {
 #else
 int vscan_quarantine_virus(struct vfs_ops *ops, struct connection_struct *conn, char *virus_file, char *q_dir, char *q_prefix) {
 #endif
-	int rc;
-	/* FIXME: tempnam should be avoided */
-	char *q_file = tempnam(q_dir, q_prefix);
+	int rc, fd;
+	pstring q_file;
 
-	if (q_file == NULL) {
+	/* build file path */
+	pstrcpy(q_file, q_dir);
+	pstrcat(q_file, "/");
+	pstrcat(q_file, q_prefix);
+	pstrcat(q_file, "XXXXXX");
+
+	/* create temp file, q_file filled with temp file path */
+	/* NOTE: q_dir shoud have the sticky bit set! mkstemp creates
+	   a zero-byte file, but as long as rename(2) overwrites the
+	   newpath this isn't a problem */
+	fd = smb_mkstemp(q_file);
+	DEBUG(1, ("temp file is: %s\n", q_file));
+
+	if ( fd == -1 ) {
+		/* FIXME: we could call strerror, too */
 		vscan_syslog_alert("ERROR: cannot create unique quarantine filename. Probably a permission problem with directory %s", q_dir);
 		return -1;
 	}
+	/* close the opened, 0-byte file */
+	rc = close(fd);
+	if ( rc == -1 ) {
+		vscan_syslog_alert("ERROR while closing quarantine file: %s, reason: %s", q_file, strerror(errno));
+		return -1;
+	}
+	
+	/* now do the actual quarantine, i.e. renaming */
 #if (SMB_VFS_INTERFACE_VERSION >= 6)
 	rc = SMB_VFS_NEXT_RENAME(handle, conn, virus_file, q_file);
 #else
@@ -69,7 +104,10 @@
 	vscan_syslog("INFO: quarantining file '%s' to '%s' was successful", virus_file, q_file);
 	return 0;
 }
- 
+
+/**
+ do action on infected file
+*/ 
 #if (SMB_VFS_INTERFACE_VERSION >= 6)
 int vscan_do_infected_file_action(vfs_handle_struct *handle_ops, connection_struct *conn, char *virus_file, char *q_dir, char *q_prefix, enum infected_file_action_enum infected_file_action) {
 #else



-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt