X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=spamass-milter.cpp;h=36988923e4b806d932193703a3a4670ef7487a63;hb=1a13de003b1a90d0058ed32d639617a232c769d5;hp=65657c193021b13020da2e3c69a5cda7935a1f63;hpb=24c75baa57e47c7953cfa22f7cbaee4dbcd2a38c;p=deb_pkgs%2Fspamass-milter.git diff --git a/spamass-milter.cpp b/spamass-milter.cpp index 65657c1..3698892 100644 --- a/spamass-milter.cpp +++ b/spamass-milter.cpp @@ -1,6 +1,6 @@ // // -// $Id: spamass-milter.cpp,v 1.90 2006/03/23 21:41:36 dnelson Exp $ +// $Id: spamass-milter.cpp,v 1.94 2011/02/14 21:50:53 dnelson Exp $ // // SpamAss-Milter // - a rather trivial SpamAssassin Sendmail Milter plugin @@ -127,7 +127,7 @@ int daemon(int nochdir, int noclose); // }}} -static const char Id[] = "$Id: spamass-milter.cpp,v 1.90 2006/03/23 21:41:36 dnelson Exp $"; +static const char Id[] = "$Id: spamass-milter.cpp,v 1.94 2011/02/14 21:50:53 dnelson Exp $"; struct smfiDesc smfilter = { @@ -363,7 +363,7 @@ main(int argc, char* argv[]) // }}} /* Update a header if SA changes it, or add it if it is new. */ -void update_or_insert(SpamAssassin* assassin, SMFICTX* ctx, string oldstring, t_setter setter, char *header ) +void update_or_insert(SpamAssassin* assassin, SMFICTX* ctx, string oldstring, t_setter setter, const char *header ) { string::size_type eoh1 = assassin->d().find("\n\n"); string::size_type eoh2 = assassin->d().find("\n\r\n"); @@ -386,15 +386,16 @@ void update_or_insert(SpamAssassin* assassin, SMFICTX* ctx, string oldstring, t_ { /* change if old one was present, append if non-null */ char* cstr = const_cast(newstring.c_str()); + char* hstr = const_cast(header); if (oldsize > 0) { debug(D_UORI, "u_or_i: changing"); - smfi_chgheader(ctx, header, 1, newstring.size() > 0 ? + smfi_chgheader(ctx, hstr, 1, newstring.size() > 0 ? cstr : NULL ); } else if (newstring.size() > 0) { debug(D_UORI, "u_or_i: inserting"); - smfi_addheader(ctx, header, cstr); + smfi_addheader(ctx, hstr, cstr); } } else { @@ -465,13 +466,14 @@ assassinate(SMFICTX* ctx, SpamAssassin* assassin) the only way to do it. */ char *popen_argv[3]; FILE *p; + pid_t pid; popen_argv[0] = SENDMAIL; popen_argv[1] = spambucket; popen_argv[2] = NULL; debug(D_COPY, "calling %s %s", SENDMAIL, spambucket); - p = popenv(popen_argv, "w"); + p = popenv(popen_argv, "w",&pid); if (!p) { debug(D_COPY, "popenv failed(%s). Will not send a copy to spambucket", strerror(errno)); @@ -480,6 +482,7 @@ assassinate(SMFICTX* ctx, SpamAssassin* assassin) // Send message provided by SpamAssassin fwrite(assassin->d().c_str(), assassin->d().size(), 1, p); fclose(p); p = NULL; + waitpid(pid,0,0); } } return SMFIS_REJECT; @@ -814,9 +817,6 @@ mlfi_envrcpt(SMFICTX* ctx, char** envrcpt) struct context *sctx = (struct context*)smfi_getpriv(ctx); SpamAssassin* assassin = sctx->assassin; FILE *p; -#if defined(__FreeBSD__) - int rv; -#endif debug(D_FUNC, "mlfi_envrcpt: enter"); @@ -826,6 +826,7 @@ mlfi_envrcpt(SMFICTX* ctx, char** envrcpt) char buf[1024]; char *popen_argv[4]; + pid_t pid; popen_argv[0] = SENDMAIL; popen_argv[1] = "-bv"; @@ -834,7 +835,7 @@ mlfi_envrcpt(SMFICTX* ctx, char** envrcpt) debug(D_RCPT, "calling %s -bv %s", SENDMAIL, envrcpt[0]); - p = popenv(popen_argv, "r"); + p = popenv(popen_argv, "r", &pid); if (!p) { debug(D_RCPT, "popenv failed(%s). Will not expand aliases", strerror(errno)); @@ -863,6 +864,8 @@ mlfi_envrcpt(SMFICTX* ctx, char** envrcpt) } } fclose(p); p = NULL; + waitpid(pid,0,0); + } } else { @@ -2126,11 +2129,12 @@ void warnmacro(char *macro, char *scope) for simplicity, and always reads stdout and stderr in "r" mode. Call fclose to close the FILE. */ -FILE *popenv(char *const argv[], const char *type) +FILE *popenv(char *const argv[], const char *type, pid_t *pid) { FILE *iop; int pdes[2]; int save_errno; + if ((*type != 'r' && *type != 'w') || type[1]) { errno = EINVAL; @@ -2138,7 +2142,9 @@ FILE *popenv(char *const argv[], const char *type) } if (pipe(pdes) < 0) return (NULL); - switch (fork()) { + + *pid = fork(); + switch (*pid) { case -1: /* Error. */ save_errno = errno;