--- clamav-milter/clamav-milter.c.orig 2006-07-08 13:27:45 +0500 +++ clamav-milter/clamav-milter.c 2006-07-08 13:34:37 +0500 @@ -197,11 +197,18 @@ /* * Each libmilter 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 *QueueID; /* sendmail's message (queue) id */ 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 @@ -234,10 +241,11 @@ static int pingServer(int serverNumber); #endif static int findServer(void); + +void signal_handler( int s); + 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 +255,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); @@ -394,6 +402,7 @@ static short use_syslog = 0; static const char *pidFile; static int logVerbose = 0; +static int syslogVerbose = 0; static struct cfgstruct *copt; static const char *localSocket; /* milter->clamd comms */ static in_port_t tcpSocket; /* milter->clamd comms */ @@ -522,11 +531,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 */ @@ -1049,14 +1054,18 @@ streamMaxLength = (long)cpt->numarg; } - if(cfgopt(copt, "LogSyslog")) { - int fac = LOG_LOCAL6; - - if(cfgopt(copt, "LogVerbose")) { - logVerbose = 1; + if(cfgopt(copt, "LogVerbose")) { + logVerbose = 1; #if ((SENDMAIL_VERSION_A > 8) || ((SENDMAIL_VERSION_A == 8) && (SENDMAIL_VERSION_B >= 13))) smfi_setdbg(6); #endif + } + + if(cfgopt(copt, "LogSyslog")) { + int fac = LOG_LOCAL6; + + if(cfgopt(copt, "SysLogVerbose")) { + syslogVerbose = 1; } use_syslog = 1; @@ -1991,18 +2000,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)) @@ -2023,7 +2044,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; } } @@ -2032,12 +2053,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 @@ -2057,7 +2078,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; } /* @@ -2066,7 +2087,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 @@ -2075,8 +2096,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; } @@ -2086,7 +2107,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 @@ -2103,7 +2124,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); @@ -2115,14 +2136,15 @@ * Patch from "Richard G. Roberto" * 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; } @@ -2130,8 +2152,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; } @@ -2145,30 +2167,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 (syslogVerbose && 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 (syslogVerbose && 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"); - cli_dbgmsg("clamfi_envfrom: %s\n", argv[0]); + 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) && syslogVerbose && 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 (syslogVerbose && 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 (syslogVerbose && use_syslog) syslog(LOG_DEBUG, _("%s: clamfi_envfrom: %s"), QueueID, 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}"); @@ -2176,11 +2303,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); @@ -2204,16 +2331,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); @@ -2249,22 +2376,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 */ @@ -2282,33 +2405,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(syslogVerbose && 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); @@ -2317,27 +2432,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(syslogVerbose && 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 /* @@ -2399,11 +2522,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(syslogVerbose && 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 /* @@ -2427,13 +2557,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); @@ -2471,14 +2601,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) @@ -2486,10 +2616,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(syslogVerbose && 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 */ @@ -2499,11 +2636,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")); @@ -2529,24 +2663,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; + } + + if(syslogVerbose && use_syslog) syslog(LOG_DEBUG, _("%s: clamfi_eom..."), privdata->QueueID); - cli_dbgmsg("clamfi_eom\n"); + cli_dbgmsg(_("[%d] %s: clamfi_eom\n"), getpid(), privdata->QueueID); if(!nflag) { /* @@ -2626,7 +2764,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); @@ -2636,7 +2774,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 @@ -2658,7 +2796,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; } @@ -2675,8 +2813,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 @@ -2687,9 +2825,9 @@ if((ptr = strchr(mess, '\n')) != NULL) *ptr = '\0'; - if(logVerbose) - syslog(LOG_DEBUG, _("clamfi_eom: read %s"), mess); - cli_dbgmsg(_("clamfi_eom: read %s\n"), mess); + if(syslogVerbose) + 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]; @@ -2706,9 +2844,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); @@ -2729,10 +2867,6 @@ #endif } - sendmailId = smfi_getsymval(ctx, "i"); - if(sendmailId == NULL) - sendmailId = "Unknown"; - if(!nflag) { char buf[1024]; @@ -2810,8 +2944,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 */ @@ -2820,9 +2954,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) { /* @@ -2852,7 +2986,7 @@ } if(quarantine_dir) - qfile(privdata, sendmailId, virusname); + qfile(privdata, privdata->QueueID, virusname); if(use_syslog) { /* @@ -2898,11 +3032,11 @@ /* 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); } @@ -2910,6 +3044,7 @@ if(!qflag) { char cmd[128]; FILE *sendmail; + int ret; /* * If the oflag is given this sendmail command @@ -2980,7 +3115,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); @@ -3014,12 +3149,16 @@ } - cli_dbgmsg("Waiting for %s to finish\n", cmd); - if(pclose(sendmail) != 0) + 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: Failed to notify clamAV interception - see dead.letter", sendmailId); + 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) { @@ -3046,14 +3185,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) @@ -3077,8 +3220,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 { @@ -3087,8 +3230,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) { @@ -3111,57 +3254,116 @@ 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 (syslogVerbose && use_syslog) + syslog(LOG_DEBUG, _("%s: clamfi_abort: processig of message termitated"), QueueID); + 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 (syslogVerbose && 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(syslogVerbose && 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(syslogVerbose && 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(syslogVerbose && 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 @@ -3184,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; @@ -3194,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; @@ -3215,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 @@ -3242,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 @@ -3283,21 +3487,25 @@ */ cl_free(privdata->root); - 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 */ @@ -3308,15 +3516,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("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 @@ -3611,9 +3819,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 */ @@ -3636,7 +3844,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); @@ -3648,7 +3857,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); @@ -3658,11 +3867,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; @@ -3736,7 +3945,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 @@ -3750,7 +3959,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)) { @@ -3758,11 +3967,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; } @@ -3770,7 +3979,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); @@ -3782,7 +3991,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; } @@ -3794,11 +4003,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); @@ -3810,9 +4019,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 @@ -3823,11 +4032,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); @@ -3846,11 +4055,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 @@ -3864,10 +4073,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 @@ -3882,10 +4093,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