Репозиторий Sisyphus
Последнее обновление: 1 октября 2023 | Пакетов: 18631 | Посещений: 37655801
en ru br
Репозитории ALT
S:0.103.8-alt1
5.1: 0.98.1-alt0.M51.1
4.1: 0.97.8-alt0.M41.1
+updates:0.94.1-alt0.M41.1
4.0: 0.97.8-alt0.M40.1
+updates:0.91.2-alt1
3.0: 0.86.2-alt1
+updates:0.91.1-alt0.M30.1
+backports:0.93.3-alt0.M30.1
www.altlinux.org/Changes

Другие репозитории
Upstream:0.93rc1

Группа :: Работа с файлами
Пакет: clamav

 Главная   Изменения   Спек   Патчи   Sources   Загрузить   Gear   Bugs and FR  Repocop 

Патч: clamav-milter-0.86.1-log.patch
Скачать


--- clamav-milter/clamav-milter.c.orig	2005-07-15 11:23:50 +0500
+++ clamav-milter/clamav-milter.c	2005-07-15 11:50:18 +0500
@@ -198,11 +198,17 @@
 /*
  * Each thread has one of these
  */
+char    *NoQueueID = "00000000000000";
 struct	privdata {
+        /* Connection oriented data */
+        char    *helo;          /* Sender's helo */
+        char    *ConnectQueueID;  /* sendmail's message id then connection initialized */
+        int     MsgCount;       /* Message counter */
+
+        /* Message oriented data */
 	char	*from;	/* Who sent the message */
 	char	*subject;	/* Original subject */
 	char	*sender;	/* Secretary - often used in mailing lists */
-	char	*helo;		/* The HELO string */
 	char	**to;	/* Who is the message going to */
 	int	numTo;	/* Number of people the message is going to */
 #ifndef	SESSION
@@ -226,8 +232,11 @@
 				 */
 	int	statusCount;	/* number of X-Virus-Status headers */
 	int	serverNumber;	/* Index into serverIPs */
+	char	*QueueID;		/* sendmail's message (queue) id */
 };
 
+void signal_handler( int s);
+
 #ifdef	SESSION
 static	int		createSession(unsigned int s);
 #else
@@ -235,9 +244,7 @@
 #endif
 static	int		findServer(void);
 static	sfsistat	clamfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr);
-#ifdef	CL_DEBUG
 static	sfsistat	clamfi_helo(SMFICTX *ctx, char *helostring);
-#endif
 static	sfsistat	clamfi_envfrom(SMFICTX *ctx, char **argv);
 static	sfsistat	clamfi_envrcpt(SMFICTX *ctx, char **argv);
 static	sfsistat	clamfi_header(SMFICTX *ctx, char *headerf, char *headerv);
@@ -247,7 +254,7 @@
 static	sfsistat	clamfi_abort(SMFICTX *ctx);
 static	sfsistat	clamfi_close(SMFICTX *ctx);
 static	void		clamfi_cleanup(SMFICTX *ctx);
-static	void		clamfi_free(struct privdata *privdata);
+static	void		clamfi_free_msgdata(struct privdata *privdata);
 static	int		clamfi_send(struct privdata *privdata, size_t len, const char *format, ...);
 static	int		clamd_recv(int sock, char *buf, size_t len);
 static	off_t		updateSigFile(void);
@@ -522,11 +529,7 @@
 		SMFI_VERSION,	/* version code -- leave untouched */
 		SMFIF_ADDHDRS|SMFIF_CHGHDRS,	/* flags - we add and deleted headers */
 		clamfi_connect, /* connection callback */
-#ifdef	CL_DEBUG
 		clamfi_helo,	/* HELO filter callback */
-#else
-		NULL,
-#endif
 		clamfi_envfrom, /* envelope sender filter callback */
 		clamfi_envrcpt, /* envelope recipient filter callback */
 		clamfi_header, /* header filter callback */
@@ -1989,18 +1992,30 @@
 	char ip[INET_ADDRSTRLEN];	/* IPv4 only */
 #endif
 	const char *remoteIP;
+	struct privdata *privdata;
+	char *QueueID = smfi_getsymval(ctx, "i");
 
 	if(quitting)
 		return cl_error;
 
+	if (!QueueID) {
+	    QueueID = NoQueueID;
+	    if(use_syslog)
+		syslog(LOG_WARNING,
+			_("%s: clamfi_connect: Message ID is NULL. Check for 'i' macros in Milter.macros.connect in sendmail.cf."),
+			QueueID);
+	}
+
+	cli_dbgmsg(_("[%d] %s: clamfi_connect: starting...\n"), getpid(), QueueID);
+
 	if(ctx == NULL) {
 		if(use_syslog)
-			syslog(LOG_ERR, _("clamfi_connect: ctx is null"));
+			syslog(LOG_ERR, _("%s: clamfi_connect: ctx is null"), QueueID);
 		return cl_error;
 	}
 	if(hostname == NULL) {
 		if(use_syslog)
-			syslog(LOG_ERR, _("clamfi_connect: hostname is null"));
+			syslog(LOG_ERR, _("%s: clamfi_connect: hostname is null"), QueueID);
 		return cl_error;
 	}
 	if((hostaddr == NULL) || (&(((struct sockaddr_in *)(hostaddr))->sin_addr) == NULL))
@@ -2021,7 +2036,7 @@
 
 		if(remoteIP == NULL) {
 			if(use_syslog)
-				syslog(LOG_ERR, _("clamfi_connect: remoteIP is null"));
+				syslog(LOG_ERR, _("%s: clamfi_connect: remoteIP is null"), QueueID);
 			return cl_error;
 		}
 	}
@@ -2030,12 +2045,12 @@
 	if(debug_level >= 4) {
 		if(hostname[0] == '[') {
 			if(use_syslog)
-				syslog(LOG_NOTICE, _("clamfi_connect: connection from %s"), remoteIP);
-			cli_dbgmsg(_("clamfi_connect: connection from %s\n"), remoteIP);
+				syslog(LOG_NOTICE, _("%s: clamfi_connect: connection from %s"), QueueID, remoteIP);
+			cli_dbgmsg(_("%s: clamfi_connect: connection from %s\n"), QueueID, remoteIP);
 		} else {
 			if(use_syslog)
-				syslog(LOG_NOTICE, _("clamfi_connect: connection from %s [%s]"), hostname, remoteIP);
-			cli_dbgmsg(_("clamfi_connect: connection from %s [%s]\n"), hostname, remoteIP);
+				syslog(LOG_NOTICE, _("%s: clamfi_connect: connection from %s [%s]"), QueueID, hostname, remoteIP);
+			cli_dbgmsg(_("%s: clamfi_connect: connection from %s [%s]\n"), QueueID, hostname, remoteIP);
 		}
 	}
 #endif
@@ -2055,7 +2070,7 @@
 		 */
 		if((hostmail = smfi_getsymval(ctx, "{if_name}")) == NULL) {
 			if(use_syslog)
-				syslog(LOG_ERR, _("Can't get sendmail hostname"));
+				syslog(LOG_ERR, _("%s: clamfi_connect: Can't get sendmail hostname"), QueueID);
 			return cl_error;
 		}
 		/*
@@ -2064,7 +2079,7 @@
 		 */
 		if(clamfi_gethostbyname(hostmail, &hostent, buf, sizeof(buf)) != 0) {
 			if(use_syslog)
-				syslog(LOG_WARNING, _("Access Denied: Host Unknown (%s)"), hostmail);
+				syslog(LOG_WARNING, _("%s: clamfi_connect: Access Denied: Host Unknown (%s)"), QueueID, hostmail);
 			if(hostmail[0] == '[')
 				/*
 				 * A case could be made that it's not clamAV's
@@ -2073,8 +2088,8 @@
 				 * just too worried about any knock on effects
 				 * to do that...
 				 */
-				cli_warnmsg(_("Can't find entry for IP address %s in DNS - check your DNS setting\n"),
-					hostmail);
+				cli_warnmsg(_("%s: clamfi_connect: Can't find entry for IP address %s in DNS - check your DNS setting\n"),
+					QueueID, hostname);
 			return cl_error;
 		}
 
@@ -2084,7 +2099,7 @@
 			perror(hostent.h_name);
 			/*strcpy(ip, (char *)inet_ntoa(*(struct in_addr *)hostent.h_addr));*/
 			if(use_syslog)
-				syslog(LOG_WARNING, _("Access Denied: Can't get IP address for (%s)"), hostent.h_name);
+				syslog(LOG_WARNING, _("%s: clamfi_connect: Access Denied: Can't get IP address for (%s)"), QueueID, hostent.h_name);
 			return cl_error;
 		}
 #else
@@ -2101,7 +2116,7 @@
 		if(!hosts_ctl(progname, hostent.h_name, ip, STRING_UNKNOWN)) {
 			pthread_mutex_unlock(&wrap_mutex);
 			if(use_syslog)
-				syslog(LOG_WARNING, _("Access Denied for %s[%s]"), hostent.h_name, ip);
+				syslog(LOG_WARNING, _("%s: clamfi_connect: Access Denied for %s[%s]"), QueueID, hostent.h_name, ip);
 			return SMFIS_TEMPFAIL;
 		}
 		pthread_mutex_unlock(&wrap_mutex);
@@ -2113,14 +2128,15 @@
 		 * Patch from "Richard G. Roberto" <rgr@dedlegend.com>
 		 * Always scan whereever the message is from
 		 */
-		return SMFIS_CONTINUE;
+		/* return SMFIS_CONTINUE; */ /* Replaced to goto by ASY */
+		goto EXIT;
 
 	if(!oflag)
 		if(strcmp(remoteIP, "127.0.0.1") == 0) {
 #ifdef	CL_DEBUG
 			if(use_syslog)
-				syslog(LOG_DEBUG, _("clamfi_connect: not scanning outgoing messages"));
-			cli_dbgmsg(_("clamfi_connect: not scanning outgoing messages\n"));
+				syslog(LOG_DEBUG, _("%s: clamfi_connect: not scanning outgoing messages"), QueueID);
+			cli_dbgmsg(_("%s: clamfi_connect: not scanning outgoing messages\n"), QueueID);
 #endif
 			return SMFIS_ACCEPT;
 		}
@@ -2128,8 +2144,8 @@
 	if((!lflag) && isLocalAddr(inet_addr(remoteIP))) {
 #ifdef	CL_DEBUG
 		if(use_syslog)
-			syslog(LOG_DEBUG, _("clamfi_connect: not scanning local messages"));
-		cli_dbgmsg(_("clamfi_connect: not scanning local messages\n"));
+			syslog(LOG_DEBUG, _("%s: clamfi_connect: not scanning local messages"), QueueID);
+		cli_dbgmsg(_("%s: clamfi_connect: not scanning local messages\n"), QueueID);
 #endif
 		return SMFIS_ACCEPT;
 	}
@@ -2143,30 +2159,135 @@
 
 		if(gethostname(me, sizeof(me) - 1) < 0) {
 			if(use_syslog)
-				syslog(LOG_WARNING, _("clamfi_connect: gethostname failed"));
+				syslog(LOG_WARNING, _("%s: clamfi_connect: gethostname failed"), QueueID);
 			return SMFIS_CONTINUE;
 		}
 		if(strcasecmp(hostname, me) == 0) {
 			if(use_syslog)
-				syslog(LOG_NOTICE, _("Rejected email falsely claiming to be from here"));
+				syslog(LOG_NOTICE, _("%s: clamfi_connect: Rejected email falsely claiming to be from here"), QueueID);
 			smfi_setreply(ctx, "550", "5.7.1", _("You have claimed to be me, but you are not"));
 			broadcast(_("Forged local address detected"));
 			return SMFIS_REJECT;
 		}
 	}
+
+EXIT:
+	privdata = (struct privdata *) cli_calloc(1, sizeof(struct privdata));
+
+	if (smfi_setpriv(ctx, privdata) == MI_SUCCESS) {
+	    if (logVerbose && use_syslog)
+		syslog(LOG_DEBUG,
+			_("%s: clamfi_connect: smfi_setpriv ok, privdata=%p, remoteIP=%s"),
+			QueueID, privdata, remoteIP);
+	} else {
+	    if (use_syslog) syslog(LOG_ERR, _("%s: clamfi_connect: smfi_setpriv error"), QueueID);
+	    return cl_error;
+	}
+
+	memset(privdata, '\0', sizeof *privdata);
+
+	if ((privdata->ConnectQueueID = strdup(QueueID)) == NULL) {
+	    if(use_syslog)
+		syslog(LOG_ERR,
+			_("%s: clamfi_connect: Error allocation memory for privdata->QueueID"),
+			QueueID);
+	    return cl_error;
+	}
+
+	cli_dbgmsg(_("[%d] %s: clamfi_connect: ...connected\n"), getpid(), QueueID);
+
 	return SMFIS_CONTINUE;
-}
+
+} /* clamfi_connect */
+
+static sfsistat 
+clamfi_helo(SMFICTX *ctx, char *helostring)
+{
+    struct privdata *privdata = (struct privdata *) smfi_getpriv(ctx);
+    char        *QueueID;
+
+    if (!privdata) {
+	if(use_syslog) syslog(LOG_ERR, _("%s: clamfi_helo: privdata is NULL, breake"),
+				smfi_getsymval(ctx, "i")); /* if NULL, (null) printed */
+	return cl_error;
+    }
+
+    if (privdata->ConnectQueueID) QueueID = privdata->ConnectQueueID;
+    else QueueID = NoQueueID;
+
+    if (logVerbose && use_syslog)
+	syslog(LOG_DEBUG, _("%s: clamfi_helo: helo/ehlo: %s"), QueueID, helostring);
+
+    cli_dbgmsg(_("[%d] %s: clamfi_helo: helo/ehlo: %s\n"), getpid(), QueueID, helostring);
+
+    if (!privdata->helo) {
+	if ((privdata->helo = strdup(helostring)) == NULL) {
+	    if(use_syslog)
+		    syslog(LOG_ERR,
+			    _("%s: clamfi_helo: Error allocation memory for privdata->helo"),
+			    QueueID);
+	    clamfi_cleanup(ctx);
+	    return cl_error;
+	}
+    } else {
+	if(use_syslog)
+	    syslog(LOG_WARNING, _("%s: clamfi_helo: privdata->helo not null "), QueueID);
+    }
+
+    return SMFIS_CONTINUE;
+
+} /* clamfi_helo */
 
 static sfsistat
 clamfi_envfrom(SMFICTX *ctx, char **argv)
 {
-	struct privdata *privdata;
 	const char *mailaddr = argv[0];
 
-	if(logVerbose)
-		syslog(LOG_DEBUG, "clamfi_envfrom: %s", argv[0]);
+	struct privdata *privdata = (struct privdata *) smfi_getpriv(ctx);
+	char *QueueID = smfi_getsymval(ctx, "i");
+
+	if (!privdata) {
+	    if (use_syslog) syslog(LOG_ERR, "%s: clamfi_envfrom: privdata is NULL, breake", QueueID);
+	    return cl_error;
+	}
+
+	/* Per message message id */
+	if (QueueID) {
+	    if ((strlen(QueueID) != 14) && use_syslog)
+		syslog(LOG_WARNING,
+			_("%s: clamfi_envfrom: Message ID length %d. It's not default for sendmail 8.11 and more"),
+			QueueID, strlen(QueueID));
+
+		if ((strcmp(QueueID,privdata->ConnectQueueID) != 0) && logVerbose && use_syslog) {
+		    syslog(LOG_DEBUG,
+			    _("%s: clamfi_envfrom: non first message in smtp connection (%s first)"),
+			    QueueID, privdata->ConnectQueueID);
+		}
+
+	    if ((privdata->QueueID = strdup(QueueID)) == NULL) {
+		if (use_syslog)
+		    syslog(LOG_ERR,
+			    _("%s: clamfi_envfrom: Error allocation memory for privdata->QueueID"), QueueID);
+		clamfi_cleanup(ctx);
+		return cl_error;
+	    }
+	} else {
+	    if ((privdata->QueueID = strdup(NoQueueID)) == NULL) {
+		if (use_syslog)
+		    syslog(LOG_ERR,
+			    _("%s: clamfi_envfrom: Error allocation memory for privdata->QueueID"), QueueID);
+		clamfi_cleanup(ctx);
+		return cl_error;
+	    }
+	    if (logVerbose && use_syslog)
+		    syslog(LOG_WARNING,
+			    _("%s: clamfi_envfrom: Message ID is NULL. Check for 'i' macros in Milter.macros.envfrom in sendmail.cf."),
+			    NoQueueID);
+	}
+
+	if (logVerbose && use_syslog) syslog(LOG_DEBUG, _("%s: clamfi_envfrom: %s"), QueueID, argv[0]);
 
-	cli_dbgmsg("clamfi_envfrom: %s\n", argv[0]);
+	cli_dbgmsg(_("[%d] %s: clamfi_envfrom: %s\n"), getpid(), QueueID, argv[0]);
 
 	if(strcmp(argv[0], "<>") == 0) {
 		mailaddr = smfi_getsymval(ctx, "{mail_addr}");
@@ -2174,11 +2295,11 @@
 			mailaddr = smfi_getsymval(ctx, "_");
 
 		if(mailaddr && *mailaddr)
-			cli_dbgmsg("Message from \"%s\" has no from field\n", mailaddr);
+			cli_dbgmsg(_("[%d] %s: Message from \"%s\" has no from field\n"), getpid(), QueueID, mailaddr);
 		else {
 #if	0
 			if(use_syslog)
-				syslog(LOG_NOTICE, _("Rejected email with empty from field"));
+				syslog(LOG_NOTICE, _("%s: Rejected email with empty from field"), QueueID);
 			smfi_setreply(ctx, "554", "5.7.1", _("You have not said who the email is from"));
 			broadcast(_("Reject email with empty from field"));
 			clamfi_cleanup(ctx);
@@ -2202,16 +2323,16 @@
 			struct timespec timeout;
 
 			cli_dbgmsg((dont_wait) ?
-					_("hit max-children limit (%u >= %u)\n") :
-					_("hit max-children limit (%u >= %u): waiting for some to exit\n"),
-				n_children, max_children);
+					_("%s: clamfi_envfrom: hit max-children limit (%u >= %u)\n") :
+					_("%s: clamfi_envfrom: hit max-children limit (%u >= %u): waiting for some to exit\n"),
+				QueueID, n_children, max_children);
 
 			if(use_syslog)
 				syslog(LOG_NOTICE,
 					(dont_wait) ?
-						_("hit max-children limit (%u >= %u)") :
-						_("hit max-children limit (%u >= %u): waiting for some to exit"),
-					n_children, max_children);
+						_("%s: clamfi_envfrom: hit max-children limit (%u >= %u)") :
+						_("%s: clamfi_envfrom: hit max-children limit (%u >= %u): waiting for some to exit"),
+					QueueID, n_children, max_children);
 
 			if(dont_wait) {
 				pthread_mutex_unlock(&n_children_mutex);
@@ -2248,22 +2369,18 @@
 		}
 		n_children++;
 
-		cli_dbgmsg(_(">n_children = %d\n"), n_children);
+		cli_dbgmsg(_("[%d] %s: clamfi_envfrom: >n_children = %d\n"), getpid(), QueueID, n_children);
 		pthread_mutex_unlock(&n_children_mutex);
 
 		if(child_timeout && (rc == ETIMEDOUT)) {
 #ifdef	CL_DEBUG
 			if(use_syslog)
-				syslog(LOG_NOTICE, _("Timeout waiting for a child to die"));
+				syslog(LOG_NOTICE, _("%s: clamfi_envfrom: Timeout waiting for a child to die"), QueueID);
 #endif
-			cli_dbgmsg(_("Timeout waiting for a child to die\n"));
+			cli_dbgmsg(_("[%d] %s: clamfi_envfrom: Timeout waiting for a child to die\n"), getpid(), QueueID);
 		}
 	}
 
-	privdata = (struct privdata *)cli_calloc(1, sizeof(struct privdata));
-	if(privdata == NULL)
-		return cl_error;
-
 	privdata->dataSocket = -1;	/* 0.4 */
 #ifndef	SESSION
 	privdata->cmdSocket = -1;	/* 0.4 */
@@ -2281,33 +2398,25 @@
 	if(hflag)
 		privdata->headers = header_list_new();
 
-	if(smfi_setpriv(ctx, privdata) == MI_SUCCESS)
-		return SMFIS_CONTINUE;
-
-	clamfi_free(privdata);
-
-	return cl_error;
-}
-
-#ifdef	CL_DEBUG
-static sfsistat
-clamfi_helo(SMFICTX *ctx, char *helostring)
-{
-	cli_dbgmsg("HELO '%s'\n", helostring);
-
 	return SMFIS_CONTINUE;
-}
-#endif
+
+} /* clamfi_envfrom */
 
 static sfsistat
 clamfi_envrcpt(SMFICTX *ctx, char **argv)
 {
 	struct privdata *privdata = (struct privdata *)smfi_getpriv(ctx);
 
-	if(logVerbose)
-		syslog(LOG_DEBUG, "clamfi_envrcpt: %s", argv[0]);
+	if (!privdata) {
+	    if (use_syslog) syslog(LOG_ERR, _("%s: clamfi_envrcpt: privdata is NULL, breake"),
+		smfi_getsymval(ctx, "i"));
+	    return cl_error;
+	}
+
+	if(logVerbose && use_syslog)
+	    syslog(LOG_DEBUG, _("%s: clamfi_envrcpt: %s, numTo: %d"), privdata->QueueID, argv[0], privdata->numTo);
 
-	cli_dbgmsg("clamfi_envrcpt: %s\n", argv[0]);
+	cli_dbgmsg(_("[%d] %s: clamfi_envrcpt: %s\n"), getpid(), privdata->QueueID, argv[0]);
 
 	if(privdata->to == NULL) {
 		privdata->to = cli_malloc(sizeof(char *) * 2);
@@ -2316,27 +2425,35 @@
 	} else
 		privdata->to = cli_realloc(privdata->to, sizeof(char *) * (privdata->numTo + 2));
 
-	if(privdata->to == NULL)
-		return cl_error;
+	if(privdata->to == NULL) {
+	    clamfi_cleanup(ctx);
+	    return cl_error;
+	}
 
 	privdata->to[privdata->numTo] = strdup(argv[0]);
 	privdata->to[++privdata->numTo] = NULL;
 
 	return SMFIS_CONTINUE;
-}
+} /* clamfi_envrcpt */
 
 static sfsistat
 clamfi_header(SMFICTX *ctx, char *headerf, char *headerv)
 {
 	struct privdata *privdata = (struct privdata *)smfi_getpriv(ctx);
 
-	if(logVerbose)
-		syslog(LOG_DEBUG, "clamfi_header: %s: %s", headerf, headerv);
+        if (!privdata) {
+            if (use_syslog) syslog(LOG_ERR, _("%s: clamfi_header: privdata is NULL, breake"),
+                   smfi_getsymval(ctx, "i"));
+            return cl_error;
+        }
+
+	if(logVerbose && use_syslog)
+		syslog(LOG_DEBUG, _("%s: clamfi_header: %s: %s"), privdata->QueueID, headerf, headerv);
 #ifdef	CL_DEBUG
 	if(debug_level >= 9)
-		cli_dbgmsg("clamfi_header: %s: %s\n", headerf, headerv);
+		cli_dbgmsg(_("[%d] %s: clamfi_header: %s: %s\n"), getpid(), privdata->QueueID, headerf, headerv);
 	else
-		cli_dbgmsg("clamfi_header\n");
+		cli_dbgmsg(_("[%d] %s: clamfi_header\n"), getpid(), privdata->QueueID);
 #endif
 
 	/*
@@ -2398,11 +2515,18 @@
 	struct privdata *privdata = (struct privdata *)smfi_getpriv(ctx);
 	char **to;
 
-	if(logVerbose)
-		syslog(LOG_DEBUG, _("clamfi_eoh"));
+	if (!privdata) {
+	    if (use_syslog) syslog(LOG_ERR, _("%s: clamfi_eoh: privdata is NULL, breake"),
+				smfi_getsymval(ctx, "i"));
+	    return cl_error;
+	}
+
+	if(logVerbose && use_syslog)
+	    syslog(LOG_DEBUG, _("%s: clamfi_eoh"), privdata->QueueID);
+
 #ifdef	CL_DEBUG
 	if(debug_level >= 4)
-		cli_dbgmsg(_("clamfi_eoh\n"));
+		cli_dbgmsg(_("[%d] %s: clamfi_eoh\n"), getpid(), privdata->QueueID);
 #endif
 
 	/*
@@ -2426,13 +2550,13 @@
 
 		if(gethostname(me, sizeof(me) - 1) < 0) {
 			if(use_syslog)
-				syslog(LOG_WARNING, _("clamfi_eoh: gethostname failed"));
+				syslog(LOG_WARNING, _("%s: clamfi_eoh: gethostname failed"), privdata->QueueID);
 			return SMFIS_CONTINUE;
 		}
 		ptr = strstr(privdata->from, me);
 		if(ptr && (ptr != privdata->from) && (*--ptr == '@')) {
 			if(use_syslog)
-				syslog(LOG_NOTICE, _("Rejected email falsely claiming to be from %s"), privdata->from);
+				syslog(LOG_NOTICE, _("%s: clamfi_eoh: Rejected email falsely claiming to be from %s"), privdata->QueueID, privdata->from);
 			smfi_setreply(ctx, "554", "5.7.1", _("You have claimed to be from me, but you are not"));
 			broadcast(_("Forged local address detected"));
 			clamfi_cleanup(ctx);
@@ -2470,14 +2594,14 @@
 	 * must be on the white list, so just accept the e-mail
 	 */
 	if(use_syslog)
-		syslog(LOG_NOTICE, _("clamfi_eoh: ignoring whitelisted message"));
+		syslog(LOG_NOTICE, _("%s: clamfi_eoh: ignoring whitelisted message"), privdata->QueueID);
 #ifdef	CL_DEBUG
-	cli_dbgmsg(_("clamfi_eoh: ignoring whitelisted message\n"));
+	cli_dbgmsg(_("[%d] %s: clamfi_eoh: ignoring whitelisted message\n"), getpid(), privdata->QueueID);
 #endif
 	clamfi_cleanup(ctx);
 
 	return SMFIS_ACCEPT;
-}
+} /* clamfi_eoh */
 
 static sfsistat
 clamfi_body(SMFICTX *ctx, u_char *bodyp, size_t len)
@@ -2485,10 +2609,17 @@
 	struct privdata *privdata = (struct privdata *)smfi_getpriv(ctx);
 	int nbytes;
 
-	if(logVerbose)
-		syslog(LOG_DEBUG, _("clamfi_envbody: %u bytes"), len);
+	if (!privdata) {
+	    if (use_syslog) syslog(LOG_ERR, _("%s: clamfi_body: privdata is NULL, breake"),
+		smfi_getsymval(ctx, "i"));
+	    return cl_error;
+	}
+
+	if(logVerbose && use_syslog)
+	    syslog(LOG_DEBUG, _("%s: clamfi_envbody: %u bytes"), privdata->QueueID, len);
+
 #ifdef	CL_DEBUG
-	cli_dbgmsg(_("clamfi_envbody: %u bytes\n"), len);
+	cli_dbgmsg(_("[%d] %s: clamfi_envbody: %u bytes\n"), getpid(), privdata->QueueID, len);
 #endif
 
 	if(len == 0)	/* unlikely */
@@ -2498,11 +2629,8 @@
 	if(streamMaxLength > 0L) {
 		if(privdata->numBytes > streamMaxLength) {
 			if(use_syslog) {
-				const char *sendmailId = smfi_getsymval(ctx, "i");
-				if(sendmailId == NULL)
-					sendmailId = "Unknown";
 				syslog(LOG_NOTICE, _("%s: Message more than StreamMaxLength (%ld) bytes - not scanned"),
-					sendmailId, streamMaxLength);
+					privdata->QueueID, streamMaxLength);
 			}
 			if(!nflag)
 				smfi_addheader(ctx, "X-Virus-Status", _("Not Scanned - StreamMaxLength exceeded"));
@@ -2528,24 +2656,28 @@
 		}
 	}
 	return SMFIS_CONTINUE;
-}
+} /* clamfi_body */
 
 static sfsistat
 clamfi_eom(SMFICTX *ctx)
 {
 	int rc = SMFIS_CONTINUE;
 	char *ptr;
-	const char *sendmailId;
 	struct privdata *privdata = (struct privdata *)smfi_getpriv(ctx);
 	char mess[128];
 #ifdef	SESSION
 	struct session *session;
 #endif
 
-	if(logVerbose)
-		syslog(LOG_DEBUG, "clamfi_eom");
+	if (!privdata) {
+	    if (use_syslog) syslog(LOG_ERR, _("%s: clamfi_eom: privdata is NULL, breake"),
+					    smfi_getsymval(ctx, "i"));
+	    return cl_error;
+	}
 
-	cli_dbgmsg("clamfi_eom\n");
+	if(logVerbose && use_syslog) syslog(LOG_DEBUG, _("%s: clamfi_eom..."), privdata->QueueID);
+
+	cli_dbgmsg(_("[%d] %s: clamfi_eom\n"), getpid(), privdata->QueueID);
 
 	if(!nflag) {
 		/*
@@ -2621,7 +2753,7 @@
 		int nbytes;
 
 		snprintf(cmdbuf, sizeof(cmdbuf) - 1, "SCAN %s", privdata->filename);
-		cli_dbgmsg("clamfi_eom: SCAN %s\n", privdata->filename);
+		cli_dbgmsg("[%d] %s: clamfi_eom: SCAN %s\n", getpid(), privdata->QueueID, privdata->filename);
 
 		nbytes = (int)strlen(cmdbuf);
 
@@ -2631,7 +2763,7 @@
 			perror("send");
 			clamfi_cleanup(ctx);
 			if(use_syslog)
-				syslog(LOG_ERR, _("failed to send SCAN %s command to clamd"), privdata->filename);
+				syslog(LOG_ERR, _("%s: clamfi_eom: failed to send SCAN %s command to clamd"), privdata->QueueID, privdata->filename);
 			return cl_error;
 		}
 #else
@@ -2653,7 +2785,7 @@
 			perror("send");
 			clamfi_cleanup(ctx);
 			if(use_syslog)
-				syslog(LOG_ERR, _("failed to send SCAN command to clamd"));
+				syslog(LOG_ERR, _("%s: clamfi_eom: failed to send SCAN command to clamd"), privdata->QueueID);
 			return cl_error;
 		}
 
@@ -2670,8 +2802,8 @@
 #ifdef	SESSION
 #ifdef	CL_DEBUG
 		if(debug_level >= 4)
-			cli_dbgmsg(_("Waiting to read status from fd %d\n"),
-				session->sock);
+			cli_dbgmsg(_("[%d] %s: clamfi_eom: Wating to read status from fd %d\n"),
+				    getpid(), privdata->QueueID, session->sock);
 #endif
 		nbytes = clamd_recv(session->sock, mess, sizeof(mess) - 1);
 #else
@@ -2683,8 +2815,8 @@
 				*ptr = '\0';
 
 			if(logVerbose)
-				syslog(LOG_DEBUG, _("clamfi_eom: read %s"), mess);
-			cli_dbgmsg(_("clamfi_eom: read %s\n"), mess);
+				syslog(LOG_DEBUG, _("%s: clamfi_eom: read %s"), privdata->QueueID, mess);
+			cli_dbgmsg(_("[%d] %s: clamfi_eom: read %s\n"), getpid(), privdata->QueueID, mess);
 		} else {
 #ifdef	MAXHOSTNAMELEN
 			char hostname[MAXHOSTNAMELEN + 1];
@@ -2701,9 +2833,9 @@
 			 * helps by forcing a retry
 			 */
 			clamfi_cleanup(ctx);
-			syslog(LOG_NOTICE, _("clamfi_eom: read nothing from clamd on %s"), hostname);
+			syslog(LOG_NOTICE, _("%s: clamfi_eom: read nothing from clamd"), privdata->QueueID);
 #ifdef	CL_DEBUG
-			cli_dbgmsg(_("clamfi_eom: read nothing from clamd on %s\n"), hostname);
+			cli_dbgmsg(_("[%d] %s: clamfi_eom: read nothing from clamd\n"), getpid(), privdata->QueueID);
 #endif
 #ifdef	SESSION
 			pthread_mutex_lock(&sstatus_mutex);
@@ -2724,10 +2856,6 @@
 #endif
 	}
 
-	sendmailId = smfi_getsymval(ctx, "i");
-	if(sendmailId == NULL)
-		sendmailId = "Unknown";
-
 	if(!nflag) {
 		char buf[1024];
 
@@ -2805,8 +2933,8 @@
 			 * Clamd has stopped on StreamMaxLength before us
 			 */
 			if(use_syslog)
-				syslog(LOG_NOTICE, _("%s: Message more than StreamMaxLength (%ld) bytes - not scanned"),
-					sendmailId, streamMaxLength);
+				syslog(LOG_NOTICE, _("%s: clamfi_eom: Message more than StreamMaxLength (%ld) bytes - not scanned"),
+					privdata->QueueID, streamMaxLength);
 			if(!nflag)
 				smfi_addheader(ctx, "X-Virus-Status", _("Not Scanned - StreamMaxLength exceeded"));
 			clamfi_cleanup(ctx);	/* not needed, but just to be safe */
@@ -2815,9 +2943,9 @@
 		if(!nflag)
 			smfi_addheader(ctx, "X-Virus-Status", _("Not Scanned"));
 
-		cli_warnmsg("%s: %s\n", sendmailId, mess);
+		cli_warnmsg(_("[%d] %s: clamfi_eom: %s\n"), getpid(), privdata->QueueID, mess);
 		if(use_syslog)
-			syslog(LOG_ERR, "%s: %s\n", sendmailId, mess);
+			syslog(LOG_ERR, _("%s: clamfi_eom: %s\n"), privdata->QueueID, mess);
 		rc = cl_error;
 	} else if((ptr = strstr(mess, "FOUND")) != NULL) {
 		/*
@@ -2890,21 +3018,22 @@
 
 			/* Include the sendmail queue ID in the log */
 			if((ptr = smfi_getsymval(ctx, "{_}")) != NULL)
-				syslog(LOG_NOTICE, "%s: clamfi_eom: %s %s %s", sendmailId, mess, ptr, err);
+				syslog(LOG_NOTICE, "%s: clamfi_eom: %s %s %s", privdata->QueueID, mess, ptr, err);
 			else
-				syslog(LOG_NOTICE, "%s: clamfi_eom: %s %s", sendmailId, mess, err);
+				syslog(LOG_NOTICE, "%s: clamfi_eom: %s %s", privdata->QueueID, mess, err);
 #ifdef	CL_DEBUG
-			cli_dbgmsg("%s", err);
+			cli_dbgmsg("[%d] %s: clamfi_eom: %s %s\n", getpid(), privdata->QueueID, mess, err);
 #endif
 			free(err);
 		}
 
 		if(quarantine_dir != NULL)
-			qfile(privdata, sendmailId, virusname);
+			qfile(privdata, privdata->QueueID, virusname);
 
 		if(!qflag) {
 			char cmd[128];
 			FILE *sendmail;
+			int ret;
 
 			/*
 			 * If the oflag is given this sendmail command
@@ -2975,7 +3104,7 @@
 						 * some useful information
 						 */
 						fprintf(sendmail, _("The message %1$s sent from %2$s to\n"),
-							sendmailId, privdata->from);
+							privdata->QueueID, privdata->from);
 					else
 						fprintf(sendmail, _("A message sent from %s to\n"),
 							privdata->from);
@@ -3009,17 +3138,22 @@
 
 				}
 
-				cli_dbgmsg("Waiting for %s to finish\n", cmd);
-				if(pclose(sendmail) != 0)
-					if(use_syslog)
-						syslog(LOG_ERR, "%s: Failed to notify clamAV interception - see dead.letter", sendmailId);
+				cli_dbgmsg("[%d] %s: clamfi_eom: Waiting for %s to finish\n", 
+					    getpid(), privdata->QueueID, cmd);
+				ret=pclose(sendmail);
+				if(ret)
+				    if(use_syslog)
+					syslog(LOG_ERR, "%s: clamfi_eom: Failed to notify clamAV interception - see dead.letter (pclose error: %s)",
+						privdata->QueueID, strerror(ret));
 			} else if(use_syslog)
-				syslog(LOG_WARNING, _("Can't execute '%s' to send virus notice"), cmd);
+				syslog(LOG_WARNING, _("%s: clamfi_eom: Can't execute '%s' to send virus notice"), 
+						    privdata->QueueID, cmd);
 		}
 
 		if(quarantine_dir) {
 			if(use_syslog)
-				syslog(LOG_NOTICE, _("Quarantined infected mail as %s"), privdata->filename);
+				syslog(LOG_NOTICE, _("%s: clamfi_eom: Quarantined infected mail as %s"),
+						    privdata->QueueID, privdata->filename);
 			/*
 			 * Cleanup filename here otherwise clamfi_free() will
 			 * delete the file that we wish to keep because it
@@ -3043,14 +3177,18 @@
 			 */
 			if(smfi_addrcpt(ctx, quarantine) == MI_FAILURE) {
 				if(use_syslog)
-					syslog(LOG_ERR, _("Can't set quarantine user %s"), quarantine);
+					syslog(LOG_DEBUG, _("%s: clamfi_eom: Can't set quarantine user %s"),
+					    privdata->QueueID, quarantine);
 				else
-					cli_warnmsg(_("Can't set quarantine user %s\n"), quarantine);
+					cli_warnmsg(_("[%d] %s: clamfi_eom: Can't set quarantine user %s\n"),
+					    getpid(), privdata->QueueID, quarantine);
 				rc = (privdata->discard) ? SMFIS_DISCARD : SMFIS_REJECT;
 			} else {
 				if(use_syslog)
-					syslog(LOG_DEBUG, "Redirected virus to %s", quarantine);
-				cli_dbgmsg("Redirected virus to %s\n", quarantine);
+					syslog(LOG_DEBUG, _("%s: clamfi_eom: Redirected virus to %s"),
+						privdata->QueueID, quarantine);
+				cli_dbgmsg(_("[%d] %s: clamfi_eom: Redirected virus to %s\n"),
+				    getpid(), privdata->QueueID, quarantine);
 				setsubject(ctx, virusname);
 			}
 		} else if(advisory)
@@ -3074,8 +3212,8 @@
 		if(!nflag)
 			smfi_addheader(ctx, "X-Virus-Status", _("Unknown"));
 		if(use_syslog)
-			syslog(LOG_ERR, _("%s: incorrect message \"%s\" from clamd"),
-				sendmailId,
+			syslog(LOG_ERR, _("%s: clamfi_eom: incorrect message \"%s\" from clamd"),
+				privdata->QueueID,
 				mess);
 		rc = cl_error;
 	} else {
@@ -3084,8 +3222,8 @@
 
 		if(use_syslog && logClean)
 			/* Include the sendmail queue ID in the log */
-			syslog(LOG_NOTICE, _("%s: clean message from %s"),
-				sendmailId,
+			syslog(LOG_NOTICE, _("%s: clamfi_eom: clean message from %s"),
+				privdata->QueueID,
 				(privdata->from) ? privdata->from : _("an unknown sender"));
 
 		if(privdata->body) {
@@ -3108,17 +3246,23 @@
 	clamfi_cleanup(ctx);
 
 	return rc;
-}
+} /* clamfi_eom */
 
 static sfsistat
 clamfi_abort(SMFICTX *ctx)
 {
+    char *QueueID;
+
+	if (ctx) QueueID = smfi_getsymval(ctx, "i");
+	else QueueID = NoQueueID;
+
 #ifdef	CL_DEBUG
-	if(logVerbose)
-		syslog(LOG_DEBUG, "clamfi_abort");
+	cli_dbgmsg(_("[%d] %s: clamfi_abort\n"), getpid(), QueueID);
 #endif
 
-	cli_dbgmsg("clamfi_abort\n");
+	if (logVerbose && use_syslog)
+	    syslog(LOG_DEBUG, _("%s: clamfi_abort: processig of message termitated"), QueueID);
+
 	/*
 	 * Unlock incase we're called during a cond_timedwait in envfrom
 	 *
@@ -3131,43 +3275,95 @@
 
 	clamfi_cleanup(ctx);
 
-	cli_dbgmsg("clamfi_abort returns\n");
+	cli_dbgmsg(_("[%d] %s: clamfi_abort returns\n"), getpid(), QueueID);
 
 	return cl_error;
-}
+} /* clamfi_abort */
 
 static sfsistat
 clamfi_close(SMFICTX *ctx)
 {
-	struct privdata *privdata = (struct privdata *)smfi_getpriv(ctx);
+    struct privdata *privdata = (struct privdata *)smfi_getpriv(ctx);
+    /* static declaration QueueID for disuse memory allocation functions on exit */
+    char QueueID[40] = "00000000000000";
+
+    cli_dbgmsg(_("[%d] %s: clamfi_close: started, privdata = %p\n"), getpid(), smfi_getsymval(ctx, "i"), privdata);
+
+    if (!privdata) {
+	if(!oflag) {
+	    if (logVerbose && use_syslog)
+		syslog(LOG_DEBUG, _("%s: clamfi_close: privdata is NULL, not scanning outgoing messages"),
+		    smfi_getsymval(ctx, "i"));
+	} else {
+	    if (use_syslog) syslog(LOG_ERR, _("%s: clamfi_close: privdata is NULL"),
+		smfi_getsymval(ctx, "i"));
+	}
+    } else {
 
-	cli_dbgmsg("clamfi_close\n");
-	if(privdata != NULL)
-		clamfi_cleanup(ctx);
+	if(privdata->ConnectQueueID) {
+	    strncpy(QueueID, privdata->ConnectQueueID, 38);
+	    QueueID[39] = 0;
+	}
 
-	if(logVerbose)
-		syslog(LOG_DEBUG, "clamfi_close");
+	/* Cleanup  connection data */
+	if (privdata->helo) {
+	    if(logVerbose && use_syslog) syslog(LOG_DEBUG, _("%s: clamfi_close: clear helo data (helo: %s)"),
+							    QueueID, privdata->helo);
+	    free(privdata->helo);
+	    privdata->helo = NULL;
+	}
 
-	return SMFIS_CONTINUE;
-}
+	if (privdata->ConnectQueueID) {
+	    if(logVerbose && use_syslog) syslog(LOG_DEBUG, _("%s: clamfi_close: clear ConnectMesgID data"),
+							    QueueID);
+	    free(privdata->ConnectQueueID);
+	    privdata->ConnectQueueID = NULL;
+	}
+	/* Cleanup  connection data end */
+#ifdef	CL_DEBUG
+	if(debug_level >= 9)
+	    cli_dbgmsg(_("[%d] %s: clamfi_close: Free privdata\n"), getpid(), QueueID);
+#endif
+	free(privdata);
+	privdata = NULL;
+	smfi_setpriv(ctx, NULL);
+    }
+
+    if(logVerbose && use_syslog) {
+	if(!oflag) syslog(LOG_DEBUG, _("%s: clamfi_close."), smfi_getsymval(ctx, "i"));
+	else syslog(LOG_DEBUG, _("%s: clamfi_close."), QueueID);
+    }
+
+    cli_dbgmsg(_("[%d] %s: clamfi_close: ...end\n"), getpid(), QueueID);
+
+    return SMFIS_CONTINUE;
+
+} /* clamfi_close */
 
 static void
 clamfi_cleanup(SMFICTX *ctx)
 {
 	struct privdata *privdata = (struct privdata *)smfi_getpriv(ctx);
 
-	cli_dbgmsg("clamfi_cleanup\n");
+	cli_dbgmsg(_("[%d] clamfi_cleanup\n"), getpid());
 
 	if(privdata) {
-		clamfi_free(privdata);
-		smfi_setpriv(ctx, NULL);
+		clamfi_free_msgdata(privdata);
 	}
-}
+} /* clamfi_cleanup */
 
 static void
-clamfi_free(struct privdata *privdata)
+clamfi_free_msgdata(struct privdata *privdata)
 {
-	cli_dbgmsg("clamfi_free\n");
+    /* static declaration QueueID for disuse memory allocation functions on exit */
+    char QueueID[40] = "00000000000000";
+
+	if(privdata->QueueID) {
+	    strncpy(QueueID, privdata->QueueID, 38);
+	    QueueID[39] = 0;
+	}
+
+	cli_dbgmsg(_("[%d] %s: clamfi_free\n"), getpid(), QueueID);
 
 	if(privdata) {
 #ifdef	SESSION
@@ -3190,8 +3386,8 @@
 				perror(privdata->filename);
 				if(use_syslog)
 					syslog(LOG_ERR,
-						_("Can't remove clean file %s"),
-						privdata->filename);
+						_("%s: clamfi_free_msgdata: Can't remove clean file %s"),
+						QueueID, privdata->filename);
 			}
 			free(privdata->filename);
 			privdata->filename = NULL;
@@ -3200,7 +3396,7 @@
 		if(privdata->from) {
 #ifdef	CL_DEBUG
 			if(debug_level >= 9)
-				cli_dbgmsg("Free privdata->from\n");
+				cli_dbgmsg(_("[%d] %s: clamfi_free_msgdata: Free privdata->from\n"), getpid(), QueueID);
 #endif
 			free(privdata->from);
 			privdata->from = NULL;
@@ -3221,17 +3417,19 @@
 			for(to = privdata->to; *to; to++) {
 #ifdef	CL_DEBUG
 				if(debug_level >= 9)
-					cli_dbgmsg("Free *privdata->to\n");
+					li_dbgmsg(_("[%d] %s: clamfi_free_msgdata: Free *privdata->to\n"), getpid(), QueueID);
 #endif
 				free(*to);
 			}
 #ifdef	CL_DEBUG
 			if(debug_level >= 9)
-				cli_dbgmsg("Free privdata->to\n");
+				cli_dbgmsg(_("[%d] %s: clamfi_free_msgdata: Free privdata->to\n"), getpid(), QueueID);
 #endif
 			free(privdata->to);
 			privdata->to = NULL;
 		}
+		
+		privdata->numTo = 0;
 
 		if(external) {
 #ifdef	SESSION
@@ -3248,8 +3446,8 @@
 					char buf[64];
 					const int fd = session->sock;
 
-					cli_dbgmsg("clamfi_free: flush server %d fd %d\n",
-						privdata->serverNumber, fd);
+					cli_dbgmsg(_("[%d] %s: clamfi_free_msgdata: flush server %d fd %d\n"),
+						getpid(), QueueID, privdata->serverNumber, fd);
 
 					/*
 					 * FIXME: whenever this code gets
@@ -3281,21 +3479,25 @@
 			}
 #endif
 		}
-		if(privdata->headers)
+		if(privdata->headers) {
 			header_list_free(privdata->headers);
+			privdata->headers = NULL;
+		}
 
-#ifdef	CL_DEBUG
-		if(debug_level >= 9)
-			cli_dbgmsg("Free privdata\n");
-#endif
-		if(privdata->received)
+    		if (privdata->QueueID) {
+        		free(privdata->QueueID);
+        		privdata->QueueID = NULL;
+    		}
+
+		if(privdata->received) {
 			free(privdata->received);
-		free(privdata);
+			privdata->received = NULL;
+		}
 	}
 
 	if(max_children > 0) {
 		pthread_mutex_lock(&n_children_mutex);
-		cli_dbgmsg("clamfi_free: n_children = %d\n", n_children);
+		cli_dbgmsg(_("[%d] %s: clamfi_free_msgdata: n_children = %d\n"), getpid(), QueueID, n_children);
 		/*
 		 * Deliberately errs on the side of broadcasting too many times
 		 */
@@ -3306,15 +3508,15 @@
 					perror("pthread_cond_broadcast");
 			}
 #ifdef	CL_DEBUG
-		cli_dbgmsg("pthread_cond_broadcast\n");
+		cli_dbgmsg(_("[%d] %s: clamfi_free_msgdata: pthread_cond_broadcast\n"), getpid(), QueueID);
 #endif
 		if(pthread_cond_broadcast(&n_children_cond) < 0)
 			perror("pthread_cond_broadcast");
-		cli_dbgmsg("<n_children = %d\n", n_children);
+		cli_dbgmsg(_("[%d] %s: clamfi_free_msgdata: <n_children = %d\n"), getpid(), QueueID, n_children);
 		pthread_mutex_unlock(&n_children_mutex);
 	}
-	cli_dbgmsg("clamfi_free returns\n");
-}
+	cli_dbgmsg(_("[%d] %s: clamfi_free returns\n"), getpid(), QueueID);
+} /* clamfi_free_msgdata */
 
 /*
  * Returns < 0 for failure, otherwise the number of bytes sent
@@ -3352,8 +3554,8 @@
 		time(&t);
 		tm = localtime(&t);
 
-		cli_dbgmsg("%d:%d:%d clamfi_send: len=%u bufsiz=%u, fd=%d\n",
-			tm->tm_hour, tm->tm_min, tm->tm_sec, len,
+		cli_dbgmsg(_("[%d] %d:%d:%d clamfi_send: len=%u bufsiz=%u, fd=%d\n"),
+			getpid(), tm->tm_hour, tm->tm_min, tm->tm_sec, len,
 			sizeof(output), privdata->dataSocket);
 	}
 #endif
@@ -3592,9 +3794,9 @@
 
 #ifdef	CL_DEBUG
 	if((debug_level > 0) && use_syslog)
-		syslog(LOG_DEBUG, "connect2clamd");
+		syslog(LOG_DEBUG, "%s: connect2clamd ...", privdata->QueueID);
 	if(debug_level >= 4)
-		cli_dbgmsg("connect2clamd\n");
+		cli_dbgmsg("[%d] %s: connect2clamd ...\n", getpid(), privdata->QueueID);
 #endif
 
 	if(quarantine_dir || tmpdir) {	/* store message in a temporary file */
@@ -3617,7 +3819,8 @@
 #endif
 			perror(dir);
 			if(use_syslog)
-				syslog(LOG_ERR, _("mkdir %s failed"), dir);
+				syslog(LOG_ERR, _("%s: connect2clamd: mkdir %s failed"), privdata->QueueID, dir);
+				
 			return 0;
 		}
 		privdata->filename = (char *)cli_malloc(strlen(dir) + 12);
@@ -3629,7 +3832,7 @@
 #else
 			if(mktemp(privdata->filename) == NULL) {
 				if(use_syslog)
-					syslog(LOG_ERR, _("mktemp %s failed"), privdata->filename);
+					syslog(LOG_ERR, _("%s: connect2clamd: mktemp %s failed"), privdata->QueueID, privdata->filename);
 				return 0;
 			}
 			privdata->dataSocket = open(privdata->filename, O_CREAT|O_EXCL|O_WRONLY|O_TRUNC, 0600);
@@ -3639,11 +3842,11 @@
 		if(privdata->dataSocket < 0) {
 			perror(privdata->filename);
 			if(use_syslog)
-				syslog(LOG_ERR, _("Temporary quarantine file %s creation failed"), privdata->filename);
+				syslog(LOG_ERR, _("%s: connect2clamd: Temporary quarantine file %s creation failed"), privdata->QueueID, privdata->filename);
 			return 0;
 		}
 		privdata->serverNumber = 0;
-		cli_dbgmsg("Saving message to %s to scan later\n", privdata->filename);
+		cli_dbgmsg("[%d] %s: connect2clamd: Saving message to %s to scan later\n", getpid(), privdata->QueueID, privdata->filename);
 	} else {	/* communicate to clamd */
 		int freeServer, nbytes;
 		struct sockaddr_in reply;
@@ -3717,7 +3920,7 @@
 		if(serverIPs[freeServer] == (int)inet_addr("127.0.0.1")) {
 			privdata->filename = cli_gentemp(NULL);
 			if(privdata->filename) {
-				cli_dbgmsg("connect2clamd(%d): creating %s\n", freeServer, privdata->filename);
+				cli_dbgmsg("[%d] %s: connect2clamd(%d): creating %s\n", getpid(), privdata->QueueID, freeServer, privdata->filename);
 #ifdef	O_TEXT
 				privdata->dataSocket = open(privdata->filename, O_WRONLY|O_CREAT|O_EXCL|O_TRUNC|O_TEXT, 0600);
 #else
@@ -3731,7 +3934,7 @@
 					return sendToFrom(privdata);
 			}
 		}
-		cli_dbgmsg("connect2clamd(%d): STREAM\n", freeServer);
+		cli_dbgmsg("[%d] %s: connect2clamd(%d): STREAM\n", getpid(), privdata->QueueID, freeServer);
 
 		session = &sessions[freeServer];
 		if((session->sock < 0) || (send(session->sock, "STREAM\n", 7, 0) < 7)) {
@@ -3739,11 +3942,11 @@
 			pthread_mutex_lock(&sstatus_mutex);
 			session->status = CMDSOCKET_DOWN;
 			pthread_mutex_unlock(&sstatus_mutex);
-			cli_warnmsg("Failed sending stream to server %d (fd %d) errno %d\n",
-				freeServer, session->sock, errno);
+			cli_warnmsg("[%d] %s: connect2clamd: Failed sending stream to server %d (fd %d) errno %d\n",
+				getpid(), privdata->QueueID, freeServer, session->sock, errno);
 			if(use_syslog)
-				syslog(LOG_ERR, _("failed to send STREAM command clamd server %d"),
-					freeServer);
+				syslog(LOG_ERR, _("[%d] %s: connect2clamd: failed to send STREAM command clamd server %d"),
+					getpid(), privdata->QueueID, freeServer);
 
 			return 0;
 		}
@@ -3751,7 +3954,7 @@
 		if(send(privdata->cmdSocket, "STREAM\n", 7, 0) < 7) {
 			perror("send");
 			if(use_syslog)
-				syslog(LOG_ERR, _("failed to send STREAM command clamd"));
+				syslog(LOG_ERR, _("%s: connect2clamd: failed to send STREAM command clamd"), privdata->QueueID);
 			return 0;
 		}
 		shutdown(privdata->cmdSocket, SHUT_WR);
@@ -3763,7 +3966,7 @@
 		if((privdata->dataSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
 			perror("socket");
 			if(use_syslog)
-				syslog(LOG_ERR, _("failed to create TCPSocket to talk to clamd"));
+				syslog(LOG_ERR, _("%s: connect2clamd: failed to create TCPSocket to talk to clamd"), privdata->QueueID);
 			return 0;
 		}
 
@@ -3775,11 +3978,11 @@
 			if(nbytes < 0) {
 				perror("recv");
 				if(use_syslog)
-					syslog(LOG_ERR, _("recv failed from clamd getting PORT"));
+					syslog(LOG_ERR, _("%s: connect2clamd: recv failed from clamd getting PORT"), privdata->QueueID);
 				cli_warnmsg("Failed get PORT from server %d (fd %d) errno %d\n",
 					freeServer, session->sock, errno);
 			} else if(use_syslog)
-				syslog(LOG_ERR, _("EOF from clamd getting PORT"));
+				syslog(LOG_ERR, _("%s: connect2clamd: EOF from clamd getting PORT"), privdata->QueueID);
 			pthread_mutex_lock(&sstatus_mutex);
 			session->status = CMDSOCKET_DOWN;
 			pthread_mutex_unlock(&sstatus_mutex);
@@ -3791,9 +3994,9 @@
 			if(nbytes < 0) {
 				perror("recv");
 				if(use_syslog)
-					syslog(LOG_ERR, _("recv failed from clamd getting PORT"));
+					syslog(LOG_ERR, _("%s: connect2clamd: recv failed from clamd getting PORT"), privdata->QueueID);
 			} else if(use_syslog)
-				syslog(LOG_ERR, _("EOF from clamd getting PORT"));
+				syslog(LOG_ERR, _("%s: connect2clamd: EOF from clamd getting PORT"), privdata->QueueID);
 			return 0;
 		}
 #endif
@@ -3804,11 +4007,11 @@
 #endif
 		if(sscanf(buf, "PORT %hu\n", &p) != 1) {
 			if(use_syslog)
-				syslog(LOG_ERR, _("Expected port information from clamd, got '%s'"),
-					buf);
+				syslog(LOG_ERR, _("%s: connect2clamd: Expected port information from clamd, got '%s'"),
+					privdata->QueueID, buf);
 			else
-				cli_warnmsg(_("Expected port information from clamd, got '%s'\n"),
-					buf);
+				cli_warnmsg(_("[%d] %s: connect2clamd: Expected port information from clamd, got '%s'\n"),
+					getpid(), privdata->QueueID, buf);
 #ifdef	SESSION
 			session->status = CMDSOCKET_DOWN;
 			pthread_mutex_unlock(&sstatus_mutex);
@@ -3827,11 +4030,11 @@
 #ifdef	CL_DEBUG
 		if(debug_level >= 4)
 #ifdef	SESSION
-			cli_dbgmsg(_("Connecting to local port %d - data %d cmd %d\n"),
-				p, privdata->dataSocket, session->sock);
+			cli_dbgmsg(_("[%d] %s: connect2clamd: Connecting to local port %d - data %d cmd %d\n"),
+				getpid(), privdata->QueueID, p, privdata->dataSocket, session->sock);
 #else
-			cli_dbgmsg(_("Connecting to local port %d - data %d cmd %d\n"),
-				p, privdata->dataSocket, privdata->cmdSocket);
+			cli_dbgmsg(_("[%d] %s: connect2clamd: Connecting to local port %d - data %d cmd %d\n"),
+				getpid(), privdata->QueueID, p, privdata->dataSocket, privdata->cmdSocket);
 #endif
 #endif
 
@@ -3845,10 +4048,12 @@
 #ifdef HAVE_STRERROR_R
 				strerror_r(errno, buf, sizeof(buf));
 				syslog(LOG_ERR,
-					_("Failed to connect to port %d given by clamd: %s"),
-					p, buf);
+					_("%s: connect2clamd: Failed to connect to port %d given by clamd: %s"),
+					privdata->QueueID, p, buf);
 #else
-				syslog(LOG_ERR, _("Failed to connect to port %d given by clamd: %s"), p, strerror(errno));
+				syslog(LOG_ERR,
+					_("%s: connect2clamd: Failed to connect to port %d given by clamd: %s"),
+					privdata->QueueID, p, strerror(errno));
 #endif
 			}
 #ifdef	SESSION
@@ -3863,10 +4068,10 @@
 	if(!sendToFrom(privdata))
 		return 0;
 
-	cli_dbgmsg("connect2clamd: serverNumber = %d\n", privdata->serverNumber);
+	cli_dbgmsg("[%d] %s: connect2clamd: serverNumber = %d\n", getpid(), privdata->QueueID, privdata->serverNumber);
 
 	return 1;
-}
+} /* connect2clamd */
 
 /*
  * Combine the To and From into one clamfi_send to save bandwidth
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin