diff options
author | gshapiro <gshapiro@FreeBSD.org> | 2002-06-11 21:12:04 +0000 |
---|---|---|
committer | gshapiro <gshapiro@FreeBSD.org> | 2002-06-11 21:12:04 +0000 |
commit | faacdfb2c2946459651449cedf08a1bc29aee731 (patch) | |
tree | 546131e3b171104de8ab1498603b992a6971ec6a /contrib/sendmail/libmilter | |
parent | e226f8e879ed5a8d2f5cc433067b698e07dce0b6 (diff) | |
download | FreeBSD-src-faacdfb2c2946459651449cedf08a1bc29aee731.zip FreeBSD-src-faacdfb2c2946459651449cedf08a1bc29aee731.tar.gz |
Import sendmail 8.12.4
Diffstat (limited to 'contrib/sendmail/libmilter')
-rw-r--r-- | contrib/sendmail/libmilter/Makefile | 2 | ||||
-rw-r--r-- | contrib/sendmail/libmilter/README | 2 | ||||
-rw-r--r-- | contrib/sendmail/libmilter/comm.c | 2 | ||||
-rw-r--r-- | contrib/sendmail/libmilter/docs/index.html | 2 | ||||
-rw-r--r-- | contrib/sendmail/libmilter/docs/overview.html | 2 | ||||
-rw-r--r-- | contrib/sendmail/libmilter/docs/sample.html | 672 | ||||
-rw-r--r-- | contrib/sendmail/libmilter/docs/smfi_addheader.html | 25 | ||||
-rw-r--r-- | contrib/sendmail/libmilter/docs/smfi_chgheader.html | 25 | ||||
-rw-r--r-- | contrib/sendmail/libmilter/engine.c | 2 | ||||
-rw-r--r-- | contrib/sendmail/libmilter/handler.c | 10 | ||||
-rw-r--r-- | contrib/sendmail/libmilter/libmilter.h | 3 | ||||
-rw-r--r-- | contrib/sendmail/libmilter/listener.c | 119 | ||||
-rw-r--r-- | contrib/sendmail/libmilter/main.c | 26 | ||||
-rw-r--r-- | contrib/sendmail/libmilter/signal.c | 2 | ||||
-rw-r--r-- | contrib/sendmail/libmilter/sm_gethost.c | 2 | ||||
-rw-r--r-- | contrib/sendmail/libmilter/smfi.c | 3 |
16 files changed, 537 insertions, 362 deletions
diff --git a/contrib/sendmail/libmilter/Makefile b/contrib/sendmail/libmilter/Makefile index 3a3e958..04277eb 100644 --- a/contrib/sendmail/libmilter/Makefile +++ b/contrib/sendmail/libmilter/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.1.1.1 2000/08/12 21:55:47 gshapiro Exp $ +# $Id: Makefile,v 8.1 1999/11/04 00:03:40 ca Exp $ SHELL= /bin/sh BUILD= ./Build diff --git a/contrib/sendmail/libmilter/README b/contrib/sendmail/libmilter/README index 601021c..f38f68a 100644 --- a/contrib/sendmail/libmilter/README +++ b/contrib/sendmail/libmilter/README @@ -457,4 +457,4 @@ main(argc, argv) /* eof */ -$Revision: 1.1.1.7 $, Last updated $Date: 2002/02/17 21:56:45 $ +$Revision: 8.35 $, Last updated $Date: 2002/01/07 21:29:20 $ diff --git a/contrib/sendmail/libmilter/comm.c b/contrib/sendmail/libmilter/comm.c index 6ff392d..0bf7e5c 100644 --- a/contrib/sendmail/libmilter/comm.c +++ b/contrib/sendmail/libmilter/comm.c @@ -9,7 +9,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: comm.c,v 1.1.1.5 2002/04/10 03:04:59 gshapiro Exp $") +SM_RCSID("@(#)$Id: comm.c,v 8.54 2002/03/06 16:03:26 ca Exp $") #include "libmilter.h" #include <sm/errstring.h> diff --git a/contrib/sendmail/libmilter/docs/index.html b/contrib/sendmail/libmilter/docs/index.html index 3570ad5..44c5f90 100644 --- a/contrib/sendmail/libmilter/docs/index.html +++ b/contrib/sendmail/libmilter/docs/index.html @@ -4,7 +4,7 @@ </head> <body> <!-- -$Id: index.html,v 1.1.1.1 2002/02/17 21:56:45 gshapiro Exp $ +$Id: index.html,v 1.10 2001/06/01 00:05:03 ca Exp $ --> <h1>Filtering Mail with Sendmail</h1> diff --git a/contrib/sendmail/libmilter/docs/overview.html b/contrib/sendmail/libmilter/docs/overview.html index 4a46866..7f1c036 100644 --- a/contrib/sendmail/libmilter/docs/overview.html +++ b/contrib/sendmail/libmilter/docs/overview.html @@ -4,7 +4,7 @@ </head> <body> <!-- -$Id: overview.html,v 1.1.1.1 2002/02/17 21:56:45 gshapiro Exp $ +$Id: overview.html,v 1.12 2001/06/01 00:05:03 ca Exp $ --> <h1>Technical Overview</h1> diff --git a/contrib/sendmail/libmilter/docs/sample.html b/contrib/sendmail/libmilter/docs/sample.html index 7e99704..879258c 100644 --- a/contrib/sendmail/libmilter/docs/sample.html +++ b/contrib/sendmail/libmilter/docs/sample.html @@ -18,397 +18,461 @@ options: </center> <hr> <pre> -#include "mfapi.h" - +#include <sys/types.h> +#include <sys/stat.h> +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sys/types.h> -#include <sys/stat.h> #include <sysexits.h> #include <unistd.h> -#ifndef bool -#define bool char -#define TRUE 1 -#define FALSE 0 -#endif -extern int errno; +#include "libmilter/mfapi.h" + +#ifndef bool +# define bool int +# define TRUE 1 +# define FALSE 0 +#endif /* ! bool */ struct mlfiPriv { - char *mlfi_fname; - char *mlfi_connectfrom; - char *mlfi_helofrom; - FILE *mlfi_fp; + char *mlfi_fname; + char *mlfi_connectfrom; + char *mlfi_helofrom; + FILE *mlfi_fp; }; -#define MLFIPRIV ((struct mlfiPriv *) <a href="smfi_getpriv.html">smfi_getpriv</a>(ctx)) +#define MLFIPRIV ((struct mlfiPriv *) <a href="smfi_getpriv.html">smfi_getpriv</a>(ctx)) + +extern sfsistat mlfi_cleanup(SMFICTX *, bool); -extern sfsistat mlfi_cleanup(SMFICTX *, bool); /* recipients to add and reject (set with -a and -r options) */ -char *add, *reject; +char *add = NULL; +char *reject = NULL; sfsistat <a href="xxfi_connect.html">mlfi_connect</a>(ctx, hostname, hostaddr) - SMFICTX *ctx; - char *hostname; - _SOCK_ADDR *hostaddr; + SMFICTX *ctx; + char *hostname; + _SOCK_ADDR *hostaddr; { - struct mlfiPriv *priv; - char *ident; - - /* allocate some private memory */ - priv = malloc(sizeof *priv); - if (priv == NULL) - { - /* can't accept this message right now */ - return SMFIS_TEMPFAIL; - } - memset(priv, '\0', sizeof *priv); - - /* save the private data */ - <a href="smfi_setpriv.html">smfi_setpriv</a>(ctx, priv); - - ident = <a href="smfi_getsymval.html">smfi_getsymval</a>(ctx, "_"); - if(!ident) ident = "???"; - if(!(priv->mlfi_connectfrom = strdup(ident))) { - return SMFIS_TEMPFAIL; - } - /* Continue processing. */ - return SMFIS_CONTINUE; + struct mlfiPriv *priv; + char *ident; + + /* allocate some private memory */ + priv = malloc(sizeof *priv); + if (priv == NULL) + { + /* can't accept this message right now */ + return SMFIS_TEMPFAIL; + } + memset(priv, '\0', sizeof *priv); + + /* save the private data */ + <a href="smfi_setpriv.html">smfi_setpriv</a>(ctx, priv); + + ident = <a href="smfi_getsymval.html">smfi_getsymval</a>(ctx, "_"); + if (ident == NULL) + ident = "???"; + if ((priv->mlfi_connectfrom = strdup(ident)) == NULL) + { + (void) mlfi_cleanup(ctx, FALSE); + return SMFIS_TEMPFAIL; + } + + /* continue processing */ + return SMFIS_CONTINUE; } sfsistat <a href="xxfi_helo.html">mlfi_helo</a>(ctx, helohost) - SMFICTX *ctx; - char *helohost; + SMFICTX *ctx; + char *helohost; { - char *tls; - char *buf; - struct mlfiPriv *priv = MLFIPRIV; - tls = <a href="smfi_getsymval.html">smfi_getsymval</a>(ctx, "{tls_version}"); - if(!tls) tls = "No TLS"; - if(!helohost) helohost = "???"; - if(!(buf = (char*)malloc(strlen(tls) + strlen(helohost) + 3))) { - return SMFIS_TEMPFAIL; - } - sprintf(buf, "%s, %s", helohost, tls); - if(priv->mlfi_helofrom) - free(priv->mlfi_helofrom); - priv->mlfi_helofrom = buf; - /* Continue processing. */ - return SMFIS_CONTINUE; + size_t len; + char *tls; + char *buf; + struct mlfiPriv *priv = MLFIPRIV; + + tls = <a href="smfi_getsymval.html">smfi_getsymval</a>(ctx, "{tls_version}"); + if (tls == NULL) + tls = "No TLS"; + if (helohost == NULL) + helohost = "???"; + len = strlen(tls) + strlen(helohost) + 3; + if ((buf = (char*) malloc(len)) == NULL) + { + (void) mlfi_cleanup(ctx, FALSE); + return SMFIS_TEMPFAIL; + } + snprintf(buf, len, "%s, %s", helohost, tls); + if (priv->mlfi_helofrom != NULL) + free(priv->mlfi_helofrom); + priv->mlfi_helofrom = buf; + + /* continue processing */ + return SMFIS_CONTINUE; } sfsistat <a href="xxfi_envfrom.html">mlfi_envfrom</a>(ctx, argv) - SMFICTX *ctx; - char **argv; + SMFICTX *ctx; + char **argv; { - struct mlfiPriv *priv = MLFIPRIV; - char *mailaddr = <a href="smfi_getsymval.html">smfi_getsymval</a>(ctx, "{mail_addr}"); - int argc = 0; - - /* open a file to store this message */ - priv->mlfi_fname = strdup("/tmp/msg.XXXXXX"); - mkstemp(priv->mlfi_fname); - if (priv->mlfi_fname == NULL) - return SMFIS_TEMPFAIL; - if ((priv->mlfi_fp = fopen(priv->mlfi_fname, "w+")) == NULL) - { - free(priv->mlfi_fname); - return SMFIS_TEMPFAIL; - } - - /* count the arguments */ - while(*argv++) ++argc; - /* log the connection information we stored earlier: */ - if(fprintf(priv->mlfi_fp, "Connect from %s (%s)\n\n", - priv->mlfi_helofrom, priv->mlfi_connectfrom) == EOF) { - (void) mlfi_cleanup(ctx, FALSE); - return SMFIS_TEMPFAIL; - } - /* log the sender */ - if(fprintf(priv->mlfi_fp, "FROM %s (%d argument%s)\n", - mailaddr?mailaddr:"???", argc, - (argc == 1)?"":"s") - == EOF) { - (void) mlfi_cleanup(ctx, FALSE); - return SMFIS_TEMPFAIL; - } - /* continue processing */ - return SMFIS_CONTINUE; + struct mlfiPriv *priv = MLFIPRIV; + char *mailaddr = <a href="smfi_getsymval.html">smfi_getsymval</a>(ctx, "{mail_addr}"); + int argc = 0; + + /* open a file to store this message */ + if ((priv->mlfi_fname = strdup("/tmp/msg.XXXXXX")) == NULL) + { + (void) mlfi_cleanup(ctx, FALSE); + return SMFIS_TEMPFAIL; + } + + if (mkstemp(priv->mlfi_fname) == -1) + { + (void) mlfi_cleanup(ctx, FALSE); + return SMFIS_TEMPFAIL; + } + + if ((priv->mlfi_fp = fopen(priv->mlfi_fname, "w+")) == NULL) + { + (void) mlfi_cleanup(ctx, FALSE); + return SMFIS_TEMPFAIL; + } + + /* count the arguments */ + while (*argv++ != NULL) + ++argc; + + /* log the connection information we stored earlier: */ + if (fprintf(priv->mlfi_fp, "Connect from %s (%s)\n\n", + priv->mlfi_helofrom, priv->mlfi_connectfrom) == EOF) + { + (void) mlfi_cleanup(ctx, FALSE); + return SMFIS_TEMPFAIL; + } + /* log the sender */ + if (fprintf(priv->mlfi_fp, "FROM %s (%d argument%s)\n", + mailaddr ? mailaddr : "???", argc, + (argc == 1) ? "" : "s") == EOF) + { + (void) mlfi_cleanup(ctx, FALSE); + return SMFIS_TEMPFAIL; + } + + /* continue processing */ + return SMFIS_CONTINUE; } sfsistat <a href="xxfi_envrcpt.html">mlfi_envrcpt</a>(ctx, argv) - SMFICTX *ctx; - char **argv; + SMFICTX *ctx; + char **argv; { - struct mlfiPriv *priv = MLFIPRIV; - char *rcptaddr = <a href="smfi_getsymval.html">smfi_getsymval</a>(ctx, "{rcpt_addr}"); - int argc = 0; - /* count the arguments */ - while(*argv++) ++argc; - /* log this recipient */ - if(reject && rcptaddr && (strcmp(rcptaddr, reject) == 0)) { - if(fprintf(priv->mlfi_fp, "RCPT %s -- REJECTED\n", rcptaddr) - == EOF) { - (void) mlfi_cleanup(ctx, FALSE); - return SMFIS_TEMPFAIL; + struct mlfiPriv *priv = MLFIPRIV; + char *rcptaddr = <a href="smfi_getsymval.html">smfi_getsymval</a>(ctx, "{rcpt_addr}"); + int argc = 0; + + /* count the arguments */ + while (*argv++ != NULL) + ++argc; + + /* log this recipient */ + if (reject != NULL && rcptaddr != NULL && + (strcasecmp(rcptaddr, reject) == 0)) + { + if (fprintf(priv->mlfi_fp, "RCPT %s -- REJECTED\n", + rcptaddr) == EOF) + { + (void) mlfi_cleanup(ctx, FALSE); + return SMFIS_TEMPFAIL; + } + return SMFIS_REJECT; + } + if (fprintf(priv->mlfi_fp, "RCPT %s (%d argument%s)\n", + rcptaddr ? rcptaddr : "???", argc, + (argc == 1) ? "" : "s") == EOF) + { + (void) mlfi_cleanup(ctx, FALSE); + return SMFIS_TEMPFAIL; } - return SMFIS_REJECT; - } - if(fprintf(priv->mlfi_fp, "RCPT %s (%d argument%s)\n", - rcptaddr?rcptaddr:"???", argc, - (argc == 1)?"":"s") - == EOF) { - (void) mlfi_cleanup(ctx, FALSE); - return SMFIS_TEMPFAIL; - } - /* continue processing */ - return SMFIS_CONTINUE; + + /* continue processing */ + return SMFIS_CONTINUE; } sfsistat <a href="xxfi_header.html">mlfi_header</a>(ctx, headerf, headerv) - SMFICTX *ctx; - char *headerf; - unsigned char *headerv; + SMFICTX *ctx; + char *headerf; + unsigned char *headerv; { - /* write the header to the log file */ - fprintf(MLFIPRIV->mlfi_fp, "%s: %s\n", headerf, headerv); + /* write the header to the log file */ + if (fprintf(MLFIPRIV->mlfi_fp, "%s: %s\n", headerf, headerv) == EOF) + { + (void) mlfi_cleanup(ctx, FALSE); + return SMFIS_TEMPFAIL; + } - /* continue processing */ - return SMFIS_CONTINUE; + /* continue processing */ + return SMFIS_CONTINUE; } sfsistat <a href="xxfi_eoh.html">mlfi_eoh</a>(ctx) - SMFICTX *ctx; + SMFICTX *ctx; { - /* output the blank line between the header and the body */ - fprintf(MLFIPRIV->mlfi_fp, "\n"); + /* output the blank line between the header and the body */ + if (fprintf(MLFIPRIV->mlfi_fp, "\n") == EOF) + { + (void) mlfi_cleanup(ctx, FALSE); + return SMFIS_TEMPFAIL; + } - /* continue processing */ - return SMFIS_CONTINUE; + /* continue processing */ + return SMFIS_CONTINUE; } sfsistat <a href="xxfi_body.html">mlfi_body</a>(ctx, bodyp, bodylen) - SMFICTX *ctx; - unsigned char *bodyp; - size_t bodylen; + SMFICTX *ctx; + unsigned char *bodyp; + size_t bodylen; { - /* output body block to log file */ - int nwritten; - if ((nwritten = fwrite(bodyp, bodylen, 1, MLFIPRIV->mlfi_fp)) != 1) - { - /* write failed */ - perror("error logging body"); - (void) mlfi_cleanup(ctx, FALSE); - return SMFIS_TEMPFAIL; - } - - /* continue processing */ - return SMFIS_CONTINUE; + struct mlfiPriv *priv = MLFIPRIV; + + /* output body block to log file */ + if (fwrite(bodyp, bodylen, 1, priv->mlfi_fp) != 1) + { + /* write failed */ + fprintf(stderr, "Couldn't write file %s: %s\n", + priv->mlfi_fname, strerror(errno)); + (void) mlfi_cleanup(ctx, FALSE); + return SMFIS_TEMPFAIL; + } + + /* continue processing */ + return SMFIS_CONTINUE; } sfsistat <a href="xxfi_eom.html">mlfi_eom</a>(ctx) - SMFICTX *ctx; + SMFICTX *ctx; { - bool ok = TRUE; - /* change recipients, if requested */ - if(add) - ok = ok && (<a href="smfi_addrcpt.html">smfi_addrcpt</a>(ctx, add) == MI_SUCCESS); - return mlfi_cleanup(ctx, ok); + bool ok = TRUE; + + /* change recipients, if requested */ + if (add != NULL) + ok = (<a href="smfi_addrcpt.html">smfi_addrcpt</a>(ctx, add) == MI_SUCCESS); + return mlfi_cleanup(ctx, ok); } sfsistat <a href="xxfi_abort.html">mlfi_abort</a>(ctx) - SMFICTX *ctx; + SMFICTX *ctx; { - return mlfi_cleanup(ctx, FALSE); + return mlfi_cleanup(ctx, FALSE); } sfsistat mlfi_cleanup(ctx, ok) - SMFICTX *ctx; - bool ok; + SMFICTX *ctx; + bool ok; { - sfsistat rstat = SMFIS_CONTINUE; - struct mlfiPriv *priv = MLFIPRIV; - char *p; - char host[512]; - char hbuf[1024]; + sfsistat rstat = SMFIS_CONTINUE; + struct mlfiPriv *priv = MLFIPRIV; + char *p; + char host[512]; + char hbuf[1024]; - if (priv == NULL) - return rstat; + if (priv == NULL) + return rstat; - /* close the archive file */ - if (priv->mlfi_fp != NULL && fclose(priv->mlfi_fp) == EOF) - { - /* failed; we have to wait until later */ - fprintf(stderr, "Couldn't close archive file %s: %s\n", - priv->mlfi_fname, strerror(errno)); - rstat = SMFIS_TEMPFAIL; - (void) unlink(priv->mlfi_fname); - } - else if (ok) - { - /* add a header to the message announcing our presence */ - if (gethostname(host, sizeof host) < 0) - strncpy(host, "localhost", sizeof host); - p = strrchr(priv->mlfi_fname, '/'); - if (p == NULL) - p = priv->mlfi_fname; + /* close the archive file */ + if (priv->mlfi_fp != NULL && fclose(priv->mlfi_fp) == EOF) + { + /* failed; we have to wait until later */ + fprintf(stderr, "Couldn't close archive file %s: %s\n", + priv->mlfi_fname, strerror(errno)); + rstat = SMFIS_TEMPFAIL; + (void) unlink(priv->mlfi_fname); + } + else if (ok) + { + /* add a header to the message announcing our presence */ + if (gethostname(host, sizeof host) < 0) + snprintf(host, sizeof host, "localhost"); + p = strrchr(priv->mlfi_fname, '/'); + if (p == NULL) + p = priv->mlfi_fname; + else + p++; + snprintf(hbuf, sizeof hbuf, "%s@%s", p, host); + if (<a href="smfi_addheader.html">smfi_addheader</a>(ctx, "X-Archived", hbuf) != MI_SUCCESS) + { + /* failed; we have to wait until later */ + fprintf(stderr, + "Couldn't add header: X-Archived: %s\n", + hbuf); + ok = FALSE; + rstat = SMFIS_TEMPFAIL; + (void) unlink(priv->mlfi_fname); + } + } else - p++; - snprintf(hbuf, sizeof hbuf, "%s@%s", p, host); - <a href="smfi_addheader.html">smfi_addheader</a>(ctx, "X-Archived", hbuf); - } - else - { - /* message was aborted -- delete the archive file */ - fprintf(stderr, "Message aborted. Removing %s\n", - priv->mlfi_fname); - rstat = SMFIS_TEMPFAIL; - (void) unlink(priv->mlfi_fname); - } - - /* release private memory */ - free(priv->mlfi_fname); - - /* return status */ - return rstat; + { + /* message was aborted -- delete the archive file */ + fprintf(stderr, "Message aborted. Removing %s\n", + priv->mlfi_fname); + rstat = SMFIS_TEMPFAIL; + (void) unlink(priv->mlfi_fname); + } + + /* release private memory */ + if (priv->mlfi_fname != NULL) + free(priv->mlfi_fname); + + /* return status */ + return rstat; } sfsistat <a href="xxfi_close.html">mlfi_close</a>(ctx) - SMFICTX *ctx; + SMFICTX *ctx; { - struct mlfiPriv *priv = MLFIPRIV; - if(priv->mlfi_connectfrom) - free(priv->mlfi_connectfrom); - if(priv->mlfi_helofrom) - free(priv->mlfi_helofrom); - free(priv); - <a href="smfi_setpriv.html">smfi_setpriv</a>(ctx, NULL); - return SMFIS_CONTINUE; + struct mlfiPriv *priv = MLFIPRIV; + + if (priv == NULL) + return SMFIS_CONTINUE; + if (priv->mlfi_connectfrom != NULL) + free(priv->mlfi_connectfrom); + if (priv->mlfi_helofrom != NULL) + free(priv->mlfi_helofrom); + free(priv); + <a href="smfi_setpriv.html">smfi_setpriv</a>(ctx, NULL); + return SMFIS_CONTINUE; } struct smfiDesc smfilter = { - "SampleFilter", /* filter name */ - SMFI_VERSION, /* version code -- do not change */ - SMFIF_ADDHDRS, /* flags */ - <a href="xxfi_connect.html">mlfi_connect</a>, /* connection info filter */ - <a href="xxfi_helo.html">mlfi_helo</a>, /* SMTP HELO command filter */ - <a href="xxfi_envfrom.html">mlfi_envfrom</a>, /* envelope sender filter */ - <a href="xxfi_envrcpt.html">mlfi_envrcpt</a>, /* envelope recipient filter */ - <a href="xxfi_header.html">mlfi_header</a>, /* header filter */ - <a href="xxfi_eoh.html">mlfi_eoh</a>, /* end of header */ - <a href="xxfi_body.html">mlfi_body</a>, /* body block filter */ - <a href="xxfi_eom.html">mlfi_eom</a>, /* end of message */ - <a href="xxfi_abort.html">mlfi_abort</a>, /* message aborted */ - <a href="xxfi_close.html">mlfi_close</a>, /* connection cleanup */ + "SampleFilter", /* filter name */ + SMFI_VERSION, /* version code -- do not change */ + SMFIF_ADDHDRS, /* flags */ + <a href="xxfi_connect.html">mlfi_connect</a>, /* connection info filter */ + <a href="xxfi_helo.html">mlfi_helo</a>, /* SMTP HELO command filter */ + <a href="xxfi_envfrom.html">mlfi_envfrom</a>, /* envelope sender filter */ + <a href="xxfi_envrcpt.html">mlfi_envrcpt</a>, /* envelope recipient filter */ + <a href="xxfi_header.html">mlfi_header</a>, /* header filter */ + <a href="xxfi_eoh.html">mlfi_eoh</a>, /* end of header */ + <a href="xxfi_body.html">mlfi_body</a>, /* body block filter */ + <a href="xxfi_eom.html">mlfi_eom</a>, /* end of message */ + <a href="xxfi_abort.html">mlfi_abort</a>, /* message aborted */ + <a href="xxfi_close.html">mlfi_close</a>, /* connection cleanup */ }; -static void -usage() +static void +usage(prog) + char *prog; { - fprintf(stderr, - "Usage: sample [-p socket-addr] [-t timeout] [-r reject-addr] \n\ -\t[-a accept-addr]\n"); + fprintf(stderr, + "Usage: %s [-p socket-addr] [-t timeout] [-r reject-addr] [-a add-addr]\n", + prog); } int main(argc, argv) - int argc; - char *argv[]; + int argc; + char **argv; { - int retval; - char c; - const char *args = "p:t:r:a:h"; - extern char *optarg; - - /* Process command line options */ - while ((c = getopt(argc, argv, args)) != (char)EOF) - { - switch (c) + int c; + const char *args = "p:t:r:a:h"; + extern char *optarg; + + /* Process command line options */ + while ((c = getopt(argc, argv, args)) != -1) + { + switch (c) + { + case 'p': + if (optarg == NULL || *optarg == '\0') + { + (void) fprintf(stderr, "Illegal conn: %s\n", + optarg); + exit(EX_USAGE); + } + if (<a href="smfi_setconn.html">smfi_setconn</a>(optarg) == MI_FAILURE) + { + (void) fprintf(stderr, + "smfi_setconn failed\n"); + exit(EX_SOFTWARE); + } + + /* + ** If we're using a local socket, make sure it + ** doesn't already exist. Don't ever run this + ** code as root!! + */ + + if (strncasecmp(optarg, "unix:", 5) == 0) + unlink(optarg + 5); + else if (strncasecmp(optarg, "local:", 6) == 0) + unlink(optarg + 6); + break; + + case 't': + if (optarg == NULL || *optarg == '\0') + { + (void) fprintf(stderr, "Illegal timeout: %s\n", + optarg); + exit(EX_USAGE); + } + if (<a href="smfi_settimeout.html">smfi_settimeout</a>(atoi(optarg)) == MI_FAILURE) + { + (void) fprintf(stderr, + "smfi_settimeout failed\n"); + exit(EX_SOFTWARE); + } + break; + + case 'r': + if (optarg == NULL) + { + (void) fprintf(stderr, + "Illegal reject rcpt: %s\n", + optarg); + exit(EX_USAGE); + } + reject = optarg; + break; + + case 'a': + if (optarg == NULL) + { + (void) fprintf(stderr, + "Illegal add rcpt: %s\n", + optarg); + exit(EX_USAGE); + } + add = optarg; + smfilter.xxfi_flags |= SMFIF_ADDRCPT; + break; + + case 'h': + default: + usage(argv[0]); + exit(EX_USAGE); + } + } + if (<a href="smfi_register.html">smfi_register</a>(smfilter) == MI_FAILURE) { - case 'p': - if (optarg == NULL || *optarg == '\0') - { - (void) fprintf(stderr, "Illegal conn: %s\n", - optarg); - exit(EX_USAGE); - } - if(<a href="smfi_setconn.html">smfi_setconn</a>(optarg) == MI_FAILURE) - { - (void) fputs("smfi_setconn failed", stderr); - exit(EX_SOFTWARE); - } - /* - ** If we're using a local socket, make sure it doesn't - ** already exist. - */ - if(strncmp(optarg, "unix:", 5) == 0) - unlink(optarg + 5); - else if(strncmp(optarg, "local:", 6) == 0) - unlink(optarg + 6); - break; - - case 't': - if (optarg == NULL || *optarg == '\0') - { - (void) fprintf(stderr, "Illegal timeout: %s\n", - optarg); - exit(EX_USAGE); - } - if(<a href="smfi_settimeout.html">smfi_settimeout</a>(atoi(optarg)) == MI_FAILURE) - { - (void) fputs("smfi_settimeout failed", stderr); - exit(EX_SOFTWARE); - } - break; - - case 'r': - if (optarg == NULL) - { - (void) fprintf(stderr, "Illegal reject rcpt: %s\n", - optarg); - exit(EX_USAGE); - } - reject = optarg; - break; - - case 'a': - if (optarg == NULL) - { - (void) fprintf(stderr, "Illegal add rcpt: %s\n", - optarg); - exit(EX_USAGE); - } - add = optarg; - smfilter.xxfi_flags |= SMFIF_ADDRCPT; - break; - case 'h': - default: - usage(); - exit(0); + fprintf(stderr, "smfi_register failed\n"); + exit(EX_UNAVAILABLE); } - } - if (<a href="smfi_register.html">smfi_register</a>(smfilter) == MI_FAILURE) - { - fprintf(stderr, "smfi_register failed\n"); - exit(EX_UNAVAILABLE); - } - retval = <a href="smfi_main.html">smfi_main</a>(); - return retval; + return <a href="smfi_main.html">smfi_main</a>(); } /* eof */ @@ -416,7 +480,7 @@ main(argc, argv) </pre> <hr size="1"> <font size="-1"> -Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. +Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers. All rights reserved. <br> By using this file, you agree to the terms and conditions set diff --git a/contrib/sendmail/libmilter/docs/smfi_addheader.html b/contrib/sendmail/libmilter/docs/smfi_addheader.html index c6417e2..6f852ae 100644 --- a/contrib/sendmail/libmilter/docs/smfi_addheader.html +++ b/contrib/sendmail/libmilter/docs/smfi_addheader.html @@ -73,18 +73,39 @@ href="smfi_chgheader.html">smfi_chgheader</a>. <li>Neither the name nor the value of the header is checked for standards compliance. However, each line of the header must be under 2048 characters and should be under 998 characters. If longer headers - are needed, make them multiline. + are needed, make them multi-line. To make a multi-line header, insert + a line feed (ASCII 0x0a, or <tt>\n</tt> in C) followed by at least + one whitespace character such as a space (ASCII 0x20) or tab (ASCII 0x09, + or <tt>\t</tt> in C). The line feed should NOT be preceded by a + carriage return (ASCII 0x0d); the MTA will add this automatically. <b>It is the filter writer's responsibility to ensure that no standards are violated.</b> </ul> </td> </tr> +<!----------- Example code ----------> +<tr> +<th valign="top" align=left>EXAMPLE</th> + +<td> + <pre> + int ret; + SMFICTX *ctx; + + ... + + ret = smfi_addheader(ctx, "Content-Type", + "multipart/mixed;\n\tboundary=\"foobar\""); + </pre> +</td> +</tr> + </table> <hr size="1"> <font size="-1"> -Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. +Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers. All rights reserved. <br> By using this file, you agree to the terms and conditions set diff --git a/contrib/sendmail/libmilter/docs/smfi_chgheader.html b/contrib/sendmail/libmilter/docs/smfi_chgheader.html index 4969674..89ce6f2 100644 --- a/contrib/sendmail/libmilter/docs/smfi_chgheader.html +++ b/contrib/sendmail/libmilter/docs/smfi_chgheader.html @@ -75,18 +75,39 @@ Otherwise, it returns MI_SUCCESS. <li>Neither the name nor the value of the header is checked for standards compliance. However, each line of the header must be under 2048 characters and should be under 998 characters. If longer headers - are needed, make them multiline. + are needed, make them multi-line. To make a multi-line header, insert + a line feed (ASCII 0x0a, or <tt>\n</tt> in C) followed by at least + one whitespace character such as a space (ASCII 0x20) or tab (ASCII 0x09, + or <tt>\t</tt> in C). The line feed should NOT be preceded by a + carriage return (ASCII 0x0d); the MTA will add this automatically. <b>It is the filter writer's responsibility to ensure that no standards are violated.</b> </ul> </td> </tr> +<!----------- Example code ----------> +<tr> +<th valign="top" align=left>EXAMPLE</th> + +<td> + <pre> + int ret; + SMFICTX *ctx; + + ... + + ret = smfi_chgheader(ctx, "Content-Type", + "multipart/mixed;\n\tboundary=\"foobar\""); + </pre> +</td> +</tr> + </table> <hr size="1"> <font size="-1"> -Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. +Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers. All rights reserved. <br> By using this file, you agree to the terms and conditions set diff --git a/contrib/sendmail/libmilter/engine.c b/contrib/sendmail/libmilter/engine.c index 6c575a9..7414072 100644 --- a/contrib/sendmail/libmilter/engine.c +++ b/contrib/sendmail/libmilter/engine.c @@ -9,7 +9,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: engine.c,v 1.1.1.6 2002/04/10 03:04:59 gshapiro Exp $") +SM_RCSID("@(#)$Id: engine.c,v 8.109 2002/03/13 17:18:44 gshapiro Exp $") #include "libmilter.h" diff --git a/contrib/sendmail/libmilter/handler.c b/contrib/sendmail/libmilter/handler.c index b18a22b..a7b4760 100644 --- a/contrib/sendmail/libmilter/handler.c +++ b/contrib/sendmail/libmilter/handler.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2000 Sendmail, Inc. and its suppliers. + * Copyright (c) 1999-2002 Sendmail, Inc. and its suppliers. * All rights reserved. * * By using this file, you agree to the terms and conditions set @@ -9,7 +9,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: handler.c,v 1.1.1.3 2002/02/17 21:56:45 gshapiro Exp $") +SM_RCSID("@(#)$Id: handler.c,v 8.30 2002/04/29 15:06:48 ca Exp $") #include "libmilter.h" @@ -38,9 +38,11 @@ mi_handle_session(ctx) ** detach so resources are free when the thread returns ** if we ever "wait" for threads, this call must be removed */ + if (pthread_detach(ctx->ctx_id) != 0) - return MI_FAILURE; - ret = mi_engine(ctx); + ret = MI_FAILURE; + else + ret = mi_engine(ctx); if (ValidSocket(ctx->ctx_sd)) { (void) closesocket(ctx->ctx_sd); diff --git a/contrib/sendmail/libmilter/libmilter.h b/contrib/sendmail/libmilter/libmilter.h index 65b3875..fedc24f 100644 --- a/contrib/sendmail/libmilter/libmilter.h +++ b/contrib/sendmail/libmilter/libmilter.h @@ -19,7 +19,7 @@ #ifdef _DEFINE # define EXTERN # define INIT(x) = x -SM_IDSTR(MilterlId, "@(#)$Id: libmilter.h,v 1.1.1.6 2002/02/17 21:56:45 gshapiro Exp $") +SM_IDSTR(MilterlId, "@(#)$Id: libmilter.h,v 8.33 2002/04/30 23:52:24 msk Exp $") #else /* _DEFINE */ # define EXTERN extern # define INIT(x) @@ -110,6 +110,7 @@ extern void mi_clean_signals __P((void)); extern struct hostent *mi_gethostbyname __P((char *, int)); extern int mi_inet_pton __P((int, const char *, void *)); extern void mi_closener __P((void)); +extern int mi_opensocket __P((char *, int, int, smfiDesc_ptr)); /* communication functions */ extern char *mi_rd_cmd __P((socket_t, struct timeval *, char *, size_t *, char *)); diff --git a/contrib/sendmail/libmilter/listener.c b/contrib/sendmail/libmilter/listener.c index 3661488..03d8acd 100644 --- a/contrib/sendmail/libmilter/listener.c +++ b/contrib/sendmail/libmilter/listener.c @@ -9,7 +9,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: listener.c,v 1.1.1.7 2002/04/10 03:05:00 gshapiro Exp $") +SM_RCSID("@(#)$Id: listener.c,v 8.85 2002/05/28 18:17:41 gshapiro Exp $") /* ** listener.c -- threaded network listener @@ -24,6 +24,58 @@ SM_RCSID("@(#)$Id: listener.c,v 1.1.1.7 2002/04/10 03:05:00 gshapiro Exp $") # endif /* NETINET || NETINET6 */ static smutex_t L_Mutex; +static int L_family; +static SOCKADDR_LEN_T L_socksize; +static socket_t listenfd = INVALID_SOCKET; + +static socket_t mi_milteropen __P((char *, int, char *)); + +/* +** MI_OPENSOCKET -- create the socket where this filter and the MTA will meet +** +** Parameters: +** conn -- connection description +** backlog -- listen backlog +** dbg -- debug level +** smfi -- filter structure to use +** +** Return value: +** MI_SUCCESS/MI_FAILURE +*/ + +int +mi_opensocket(conn, backlog, dbg, smfi) + char *conn; + int backlog; + int dbg; + smfiDesc_ptr smfi; +{ + if (smfi == NULL || conn == NULL) + return MI_FAILURE; + + if (ValidSocket(listenfd)) + return MI_SUCCESS; + + if (dbg > 0) + { + smi_log(SMI_LOG_DEBUG, + "%s: Opening listen socket on conn %s", + smfi->xxfi_name, conn); + } + (void) smutex_init(&L_Mutex); + (void) smutex_lock(&L_Mutex); + listenfd = mi_milteropen(conn, backlog, smfi->xxfi_name); + if (!ValidSocket(listenfd)) + { + smi_log(SMI_LOG_FATAL, + "%s: Unable to create listening socket on conn %s", + smfi->xxfi_name, conn); + (void) smutex_unlock(&L_Mutex); + return MI_FAILURE; + } + + return MI_SUCCESS; +} /* ** MI_MILTEROPEN -- setup socket to listen on @@ -31,8 +83,6 @@ static smutex_t L_Mutex; ** Parameters: ** conn -- connection description ** backlog -- listen backlog -** socksize -- socksize of created socket -** family -- family of created socket ** name -- name for logging ** ** Returns: @@ -47,15 +97,14 @@ static char *sockpath = NULL; #endif /* NETUNIX */ static socket_t -mi_milteropen(conn, backlog, socksize, family, name) +mi_milteropen(conn, backlog, name) char *conn; int backlog; - SOCKADDR_LEN_T *socksize; - int *family; char *name; { socket_t sock; int sockopt = 1; + int fdflags; size_t len = 0; char *p; char *colon; @@ -82,17 +131,17 @@ mi_milteropen(conn, backlog, socksize, family, name) #if NETUNIX /* default to AF_UNIX */ addr.sa.sa_family = AF_UNIX; - *socksize = sizeof (struct sockaddr_un); + L_socksize = sizeof (struct sockaddr_un); #else /* NETUNIX */ # if NETINET /* default to AF_INET */ addr.sa.sa_family = AF_INET; - *socksize = sizeof addr.sin; + L_socksize = sizeof addr.sin; # else /* NETINET */ # if NETINET6 /* default to AF_INET6 */ addr.sa.sa_family = AF_INET6; - *socksize = sizeof addr.sin6; + L_socksize = sizeof addr.sin6; # else /* NETINET6 */ /* no protocols available */ smi_log(SMI_LOG_ERR, @@ -108,21 +157,21 @@ mi_milteropen(conn, backlog, socksize, family, name) strcasecmp(p, "local") == 0) { addr.sa.sa_family = AF_UNIX; - *socksize = sizeof (struct sockaddr_un); + L_socksize = sizeof (struct sockaddr_un); } #endif /* NETUNIX */ #if NETINET else if (strcasecmp(p, "inet") == 0) { addr.sa.sa_family = AF_INET; - *socksize = sizeof addr.sin; + L_socksize = sizeof addr.sin; } #endif /* NETINET */ #if NETINET6 else if (strcasecmp(p, "inet6") == 0) { addr.sa.sa_family = AF_INET6; - *socksize = sizeof addr.sin6; + L_socksize = sizeof addr.sin6; } #endif /* NETINET6 */ else @@ -139,17 +188,17 @@ mi_milteropen(conn, backlog, socksize, family, name) #if NETUNIX /* default to AF_UNIX */ addr.sa.sa_family = AF_UNIX; - *socksize = sizeof (struct sockaddr_un); + L_socksize = sizeof (struct sockaddr_un); #else /* NETUNIX */ # if NETINET /* default to AF_INET */ addr.sa.sa_family = AF_INET; - *socksize = sizeof addr.sin; + L_socksize = sizeof addr.sin; # else /* NETINET */ # if NETINET6 /* default to AF_INET6 */ addr.sa.sa_family = AF_INET6; - *socksize = sizeof addr.sin6; + L_socksize = sizeof addr.sin6; # else /* NETINET6 */ smi_log(SMI_LOG_ERR, "%s: unknown socket type %s", name, p); @@ -380,6 +429,16 @@ mi_milteropen(conn, backlog, socksize, family, name) return INVALID_SOCKET; } + if ((fdflags = fcntl(sock, F_GETFD, 0)) == -1 || + fcntl(sock, F_SETFD, fdflags | FD_CLOEXEC) == -1) + { + smi_log(SMI_LOG_ERR, + "%s: Unable to set close-on-exec: %s", name, + sm_errstring(errno)); + (void) closesocket(sock); + return INVALID_SOCKET; + } + if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *) &sockopt, sizeof(sockopt)) == -1) { @@ -390,7 +449,7 @@ mi_milteropen(conn, backlog, socksize, family, name) return INVALID_SOCKET; } - if (bind(sock, &addr.sa, *socksize) < 0) + if (bind(sock, &addr.sa, L_socksize) < 0) { smi_log(SMI_LOG_ERR, "%s: Unable to bind to port %s: %s", @@ -429,7 +488,7 @@ mi_milteropen(conn, backlog, socksize, family, name) } } #endif /* NETUNIX */ - *family = addr.sa.sa_family; + L_family = addr.sa.sa_family; return sock; } /* @@ -449,8 +508,6 @@ mi_thread_handle_wrapper(arg) return (void *) mi_handle_session(arg); } -static socket_t listenfd = INVALID_SOCKET; - /* ** MI_CLOSENER -- close listen socket ** @@ -528,6 +585,7 @@ mi_closener() ** dbg -- debug level ** smfi -- filter structure to use ** timeout -- timeout for reads/writes +** backlog -- listen queue backlog size ** ** Returns: ** MI_SUCCESS -- Exited normally @@ -584,7 +642,6 @@ mi_listener(conn, dbg, smfi, timeout, backlog) int backlog; { socket_t connfd = INVALID_SOCKET; - int family = AF_UNSPEC; int sockopt = 1; int r; int ret = MI_SUCCESS; @@ -595,29 +652,15 @@ mi_listener(conn, dbg, smfi, timeout, backlog) int save_errno = 0; sthread_t thread_id; _SOCK_ADDR cliaddr; - SOCKADDR_LEN_T socksize; SOCKADDR_LEN_T clilen; SMFICTX_PTR ctx; fd_set readset, excset; struct timeval chktime; - if (dbg > 0) - smi_log(SMI_LOG_DEBUG, - "%s: Opening listen socket on conn %s", - smfi->xxfi_name, conn); - (void) smutex_init(&L_Mutex); - (void) smutex_lock(&L_Mutex); - listenfd = mi_milteropen(conn, backlog, &socksize, &family, - smfi->xxfi_name); - if (!ValidSocket(listenfd)) - { - smi_log(SMI_LOG_FATAL, - "%s: Unable to create listening socket on conn %s", - smfi->xxfi_name, conn); - (void) smutex_unlock(&L_Mutex); + if (mi_opensocket(conn, backlog, dbg, smfi) == MI_FAILURE) return MI_FAILURE; - } - clilen = socksize; + + clilen = L_socksize; if (listenfd >= FD_SETSIZE) { @@ -698,7 +741,7 @@ mi_listener(conn, dbg, smfi, timeout, backlog) # ifdef BSD4_4_SOCKADDR cliaddr.sa.sa_len == 0 || # endif /* BSD4_4_SOCKADDR */ - cliaddr.sa.sa_family != family)) + cliaddr.sa.sa_family != L_family)) { (void) closesocket(connfd); connfd = INVALID_SOCKET; diff --git a/contrib/sendmail/libmilter/main.c b/contrib/sendmail/libmilter/main.c index 345741a..92690cd 100644 --- a/contrib/sendmail/libmilter/main.c +++ b/contrib/sendmail/libmilter/main.c @@ -9,7 +9,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: main.c,v 1.1.1.5 2002/04/10 03:05:00 gshapiro Exp $") +SM_RCSID("@(#)$Id: main.c,v 8.63 2002/04/30 23:52:24 msk Exp $") #define _DEFINE 1 #include "libmilter.h" @@ -93,7 +93,29 @@ smfi_stop() static int dbg = 0; static char *conn = NULL; static int timeout = MI_TIMEOUT; -static int backlog= MI_SOMAXCONN; +static int backlog = MI_SOMAXCONN; + +#if _FFR_SMFI_OPENSOCKET +/* +** SMFI_OPENSOCKET -- try the socket setup to make sure we'll be +** able to start up +** +** Parameters: +** None. +** +** Return: +** MI_SUCCESS/MI_FAILURE +*/ + +int +smfi_opensocket() +{ + if (smfi == NULL || conn == NULL) + return MI_FAILURE; + + return mi_opensocket(conn, backlog, dbg, smfi); +} +#endif /* _FFR_SMFI_OPENSOCKET */ /* ** SMFI_SETDBG -- set debug level. diff --git a/contrib/sendmail/libmilter/signal.c b/contrib/sendmail/libmilter/signal.c index 514afb6..43a8567 100644 --- a/contrib/sendmail/libmilter/signal.c +++ b/contrib/sendmail/libmilter/signal.c @@ -9,7 +9,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: signal.c,v 1.1.1.5 2002/04/10 03:05:00 gshapiro Exp $") +SM_RCSID("@(#)$Id: signal.c,v 8.37 2002/03/23 00:55:19 ca Exp $") #include "libmilter.h" diff --git a/contrib/sendmail/libmilter/sm_gethost.c b/contrib/sendmail/libmilter/sm_gethost.c index 96aaf60..1714741 100644 --- a/contrib/sendmail/libmilter/sm_gethost.c +++ b/contrib/sendmail/libmilter/sm_gethost.c @@ -9,7 +9,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: sm_gethost.c,v 1.1.1.7 2002/02/17 21:56:45 gshapiro Exp $") +SM_RCSID("@(#)$Id: sm_gethost.c,v 8.26 2001/09/11 04:04:45 gshapiro Exp $") #include <sendmail.h> #if NETINET || NETINET6 diff --git a/contrib/sendmail/libmilter/smfi.c b/contrib/sendmail/libmilter/smfi.c index 666673b..032a6ac 100644 --- a/contrib/sendmail/libmilter/smfi.c +++ b/contrib/sendmail/libmilter/smfi.c @@ -9,7 +9,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: smfi.c,v 1.1.1.3 2002/04/10 03:05:00 gshapiro Exp $") +SM_RCSID("@(#)$Id: smfi.c,v 8.64 2002/04/30 22:22:02 msk Exp $") #include <sm/varargs.h> #include "libmilter.h" @@ -267,6 +267,7 @@ smfi_quarantine(ctx, reason) ** Side Effects: ** none. */ + static int myisenhsc(s, delim) const char *s; |