diff -Naur sendmail-8.12.11.original/include/libmilter/mfapi.h sendmail-8.12.11/include/libmilter/mfapi.h --- sendmail-8.12.11.original/include/libmilter/mfapi.h Tue Oct 21 07:51:49 2003 +++ sendmail-8.12.11/include/libmilter/mfapi.h Thu Feb 19 16:21:23 2004 @@ -135,6 +135,9 @@ #if _FFR_QUARANTINE # define SMFIF_QUARANTINE 0x00000020L /* filter may quarantine envelope */ #endif /* _FFR_QUARANTINE */ +#if _FFR_SETSENDER +#define SMFIF_SETSENDER 0x00000040L /* filter may set sender */ +#endif /* _FFR_SETSENDER */ /* ** Continue processing message/connection. @@ -367,6 +370,17 @@ LIBMILTER_API int smfi_addrcpt __P((SMFICTX *, char *)); +#if _FFR_SETSENDER +/* +** Set the sender address for the message +** +** SMFICTX *ctx; Opaque context structure +** char *sender; Sender address to be set +*/ + +LIBMILTER_API int smfi_setsender __P((SMFICTX *, char *)); + +#endif /* _FFR_SETSENDER */ /* ** Add a recipient to the envelope ** diff -Naur sendmail-8.12.11.original/include/libmilter/mfdef.h sendmail-8.12.11/include/libmilter/mfdef.h --- sendmail-8.12.11.original/include/libmilter/mfdef.h Tue Nov 12 10:22:28 2002 +++ sendmail-8.12.11/include/libmilter/mfdef.h Thu Feb 19 16:21:23 2004 @@ -24,11 +24,15 @@ /* These apply to SMFIF_* flags */ #define SMFI_V1_ACTS 0x0000000FL /* The actions of V1 filter */ +#if _FFR_SETSENDER +# define SMFI_V2_ACTS 0x0000007FL /* The actions of V2 filter */ +#else #if _FFR_QUARANTINE # define SMFI_V2_ACTS 0x0000003FL /* The actions of V2 filter */ #else /* _FFR_QUARANTINE */ # define SMFI_V2_ACTS 0x0000001FL /* The actions of V2 filter */ #endif /* _FFR_QUARANTINE */ +#endif /* _FFR_SETSENDER */ #define SMFI_CURR_ACTS SMFI_V2_ACTS /* The current version */ /* address families */ @@ -52,6 +56,9 @@ # define SMFIC_RCPT 'R' /* RCPT to */ /* actions (replies) */ +#if _FFR_SETSENDER +# define SMFIR_SETSENDER 's' /* set sender */ +#endif /* _FFR_SETSENDER */ # define SMFIR_ADDRCPT '+' /* add recipient */ # define SMFIR_DELRCPT '-' /* remove recipient */ # define SMFIR_ACCEPT 'a' /* accept */ diff -Naur sendmail-8.12.11.original/libmilter/smfi.c sendmail-8.12.11/libmilter/smfi.c --- sendmail-8.12.11.original/libmilter/smfi.c Wed May 1 08:22:02 2002 +++ sendmail-8.12.11/libmilter/smfi.c Thu Feb 19 16:21:23 2004 @@ -112,6 +112,37 @@ return r; } +#if _FFR_SETSENDER +/* +** SMFI_SETSENDER -- Set the sender address for the message +** +** Parameters: +** ctx -- Opaque context structure +** rcpt -- recipient address +** +** Returns: +** MI_SUCCESS/MI_FAILURE +*/ + +int +smfi_setsender(ctx, sender) + SMFICTX *ctx; + char *sender; +{ + size_t len; + struct timeval timeout; + + if (sender == NULL || *sender == '\0') + return MI_FAILURE; + if (!mi_sendok(ctx, SMFIF_SETSENDER)) + return MI_FAILURE; + timeout.tv_sec = ctx->ctx_timeout; + timeout.tv_usec = 0; + len = strlen(sender) + 1; + return mi_wr_cmd(ctx->ctx_sd, &timeout, SMFIR_SETSENDER, sender, len); +} + +#endif /* _FFR_SETSENDER */ /* ** SMFI_ADDRCPT -- send an additional recipient to the MTA ** diff -Naur sendmail-8.12.11.original/sendmail/milter.c sendmail-8.12.11/sendmail/milter.c --- sendmail-8.12.11.original/sendmail/milter.c Tue Dec 2 10:57:44 2003 +++ sendmail-8.12.11/sendmail/milter.c Thu Feb 19 16:21:23 2004 @@ -2803,6 +2803,55 @@ e->e_msgsize += strlen(h->h_value); } } +#if _FFR_SETSENDER +/* +** MILTER_SETSENDER -- Set the sender address for the message +** +** Parameters: +** response -- encoded form of recipient address. +** rlen -- length of response. +** e -- current envelope. +** +** Returns: +** none +*/ + +static void +milter_setsender(response, rlen, e) + char *response; + ssize_t rlen; + ENVELOPE *e; +{ + int olderrors; + + if (tTd(64, 10)) + sm_dprintf("milter_setsender: "); + + /* sanity checks */ + if (response == NULL) + { + if (tTd(64, 10)) + sm_dprintf("NULL response\n"); + return; + } + + if (*response == '\0' || + strlen(response) + 1 != (size_t) rlen) + { + if (tTd(64, 10)) + sm_dprintf("didn't follow protocol (total len %d != rlen %d)\n", + (int) strlen(response), (int) (rlen - 1)); + return; + } + + if (tTd(64, 10)) + sm_dprintf("%s\n", response); + olderrors = Errors; + (void) setsender(response, e, NULL, '\0', false); + Errors = olderrors; + return; +} +#endif /* _FFR_SETSENDER */ /* ** MILTER_ADDRCPT -- Add the supplied recipient to the message ** @@ -3739,6 +3788,19 @@ } milter_changeheader(response, rlen, e); break; + +#if _FFR_SETSENDER + case SMFIR_SETSENDER: + if (!bitset(SMFIF_SETSENDER, m->mf_fflags)) + { + if (MilterLogLevel > 9) + sm_syslog(LOG_WARNING, e->e_id, + "milter_data(%s) lied about setting sender, honoring request anyway", + m->mf_name); + } + milter_setsender(response, rlen, e); + break; +#endif /* _FFR_SETSENDER */ case SMFIR_ADDRCPT: if (!bitset(SMFIF_ADDRCPT, m->mf_fflags))