Thanks for patch 1, I'll look into it.
patch 2: SO_BINDTODEVICE was fixed last week, please check against CVS. I'll
look
into INET_ADDRSTRLEN, thanks for that one.
patch 3: was fixed three days ago, please check against CVS.

Please always ensure that you apply patches against the latest CVS (if in
doubt ASK FIRST
before you start work), it saves your time and ours.

All the best,

-Nigel

> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of Serge Vakulenko
> Sent: 05 October 2004 18:17
> To: [EMAIL PROTECTED]
> Subject: [Clamav-devel] Patch for sender host name and IP address
> in reporttemplate
>
>
> Hi,
>
> Here is a patch for clamav-0.80rc3.
>
> 1) Added three new macros for template file:
>    %n - remote host name
>    %a - remote IP address
>    %s - sender e-mail
> 2) Problems compiling under FreeBSD-3.4 - fixed. Added conditional
> define for
>    INET_ADDRSTRLEN, and ifdef for SO_BINDTODEVICE.
> 3) Fixed crash on privdata->headers empty when %h used in template
>    file but no --headers option.
>
> Now it is possible to get sender host name/address in virus
> report message.
> For example, I use the following template file:
>
> *** VIRUS DETECTED: %v ***
>
> The message has been blocked.
>
> Sender: %s
> Host: %n
> IP address: %a
> --------------------------------------------------------------
> %h
> --------------------------------------------------------------
> ___
> Regards,
> Serge Vakulenko
>
> --- clamav-milter-old.c    Tue Sep 28 02:05:49 2004
> +++ clamav-milter.c    Tue Oct  5 20:45:37 2004
> @@ -590,6 +590,8 @@
>      char    *received;    /* keep track of received from */
>      const    char    *rejectCode;    /* 550 or 554? */
>      char    *messageID;    /* sendmailID */
> +    char    *remoteHost;    /* remote hostname (by [EMAIL PROTECTED]) */
> +    const char    *remoteAddr;    /* remote IP address */
>      int    discard;    /*
>                   * looks like the remote end is playing ping
>                   * pong with us
> @@ -1124,6 +1126,7 @@
>       */
>      if(getuid() == 0) {
>          if(iface) {
> +#ifdef SO_BINDTODEVICE
>              struct ifreq ifr;
>
>              memset(&ifr, '\0', sizeof(struct ifreq));
> @@ -1132,6 +1135,9 @@
>                  perror(iface);
>                  return EX_UNAVAILABLE;
>              }
> +#else
> +            return EX_UNAVAILABLE;
> +#endif
>          }
>          if((cpt = cfgopt(copt, "User")) != NULL) {
>              if((user = getpwnam(cpt->strarg)) == NULL) {
> @@ -1852,6 +1858,10 @@
>  }
>  #endif
>
> +#ifndef INET_ADDRSTRLEN
> +#define INET_ADDRSTRLEN 16
> +#endif
> +
>  /*
>   * Sendmail wants to establish a connection to us
>   */
> @@ -1862,6 +1872,7 @@
>      char ip[INET_ADDRSTRLEN];    /* IPv4 only */
>  #endif
>      const char *remoteIP;
> +    struct privdata *privdata;
>
>      if(quitting)
>          return cl_error;
> @@ -1987,6 +1998,17 @@
>          return SMFIS_ACCEPT;
>      }
>
> +    privdata = (struct privdata *)cli_calloc(1, sizeof(struct privdata));
> +    if(privdata == NULL)
> +        return cl_error;
> +
> +    privdata->remoteHost = strdup (hostname);
> +    privdata->remoteAddr = strdup (remoteIP);
> +syslog(LOG_NOTICE, _("clamfi_connect: connection from %s [%s]"),
> hostname, remoteIP);
> +
> +    if(smfi_setpriv(ctx, privdata) != MI_SUCCESS)
> +        clamfi_free(privdata);
> +
>      return SMFIS_CONTINUE;
>  }
>
> @@ -2071,7 +2093,7 @@
>          }
>      }
>
> -    privdata = (struct privdata *)cli_calloc(1, sizeof(struct privdata));
> +    privdata = (struct privdata *)smfi_getpriv(ctx);
>      if(privdata == NULL)
>          return cl_error;
>
> @@ -2092,12 +2114,7 @@
>      if(hflag)
>          privdata->headers = header_list_new();
>
> -    if(smfi_setpriv(ctx, privdata) == MI_SUCCESS)
> -        return SMFIS_CONTINUE;
> -
> -    clamfi_free(privdata);
> -
> -    return cl_error;
> +    return SMFIS_CONTINUE;
>  }
>
>  static sfsistat
> @@ -2909,6 +2926,10 @@
>  #endif
>          if(privdata->received)
>              free(privdata->received);
> +        if(privdata->remoteHost)
> +            free(privdata->remoteHost);
> +        if(privdata->remoteAddr)
> +            free((void*) privdata->remoteAddr);
>          free(privdata);
>      }
>
> @@ -3560,11 +3581,26 @@
>                      case 'v':    /* virus name */
>                          fputs(virusname, sendmail);
>                          break;
> +                    case 'n':    /* remote hostname */
> +                        fputs(privdata->remoteHost, sendmail);
> +                        break;
> +                    case 'a':    /* remote IP address */
> +                        fputs(privdata->remoteAddr, sendmail);
> +                        break;
> +                    case 's': {    /* sender */
> +                        char *sender = privdata->from;
> +                        if (sender && strcmp(sender, "<>") == 0)
> +                            sender = 0;
> +                        if (! sender)
> +                            sender = smfi_getsymval(ctx, "_");
> +                        fputs(sender, sendmail);
> +                        }
> +                        break;
>                      case '%':
>                          putc('%', sendmail);
>                          break;
>                      case 'h':    /* headers */
> -                        if(privdata)
> +                        if(privdata && privdata->headers)
>                              header_list_print(privdata->headers,
> sendmail);
>                          break;
>                      case '\0':
>
>
>
> _______________________________________________
> http://lists.clamav.net/cgi-bin/mailman/listinfo/clamav-devel
>

_______________________________________________
http://lists.clamav.net/cgi-bin/mailman/listinfo/clamav-devel

Reply via email to