xref: /freebsd/contrib/sendmail/libmilter/docs/sample.html (revision 4026605903c0ab8df33c4ae8c419acdb2b652af8)
140266059SGregory Neil Shapiro<html>
240266059SGregory Neil Shapiro<head><title>A Sample Filter</title></head>
340266059SGregory Neil Shapiro<body>
440266059SGregory Neil Shapiro<h1>A Sample Filter</h1>
540266059SGregory Neil Shapiro
640266059SGregory Neil ShapiroThe following sample logs each message to a separate temporary file,
740266059SGregory Neil Shapiroadds a recipient given with the -a flag, and rejects a disallowed
840266059SGregory Neil Shapirorecipient address given with the -r flag.  It recognizes the following
940266059SGregory Neil Shapirooptions:
1040266059SGregory Neil Shapiro<p>
1140266059SGregory Neil Shapiro<center>
1240266059SGregory Neil Shapiro<table border="1" cellpadding=2 cellspacing=1>
1340266059SGregory Neil Shapiro<tr><td><code>-p port</code></td><td>The port through which the MTA will connect to the filter.</td></tr>
1440266059SGregory Neil Shapiro<tr><td><code>-t sec</code></td><td>The timeout value.</td></tr>
1540266059SGregory Neil Shapiro<tr><td><code>-r addr</code></td><td>A recipient to reject.</td></tr>
1640266059SGregory Neil Shapiro<tr><td><code>-a addr</code></td><td>A recipient to add.</td></tr>
1740266059SGregory Neil Shapiro</table>
1840266059SGregory Neil Shapiro</center>
1940266059SGregory Neil Shapiro<hr>
2040266059SGregory Neil Shapiro<pre>
2140266059SGregory Neil Shapiro#include "mfapi.h"
2240266059SGregory Neil Shapiro
2340266059SGregory Neil Shapiro#include &lt;stdio.h&gt;
2440266059SGregory Neil Shapiro#include &lt;stdlib.h&gt;
2540266059SGregory Neil Shapiro#include &lt;string.h&gt;
2640266059SGregory Neil Shapiro#include &lt;sys/types.h&gt;
2740266059SGregory Neil Shapiro#include &lt;sys/stat.h&gt;
2840266059SGregory Neil Shapiro#include &lt;sysexits.h&gt;
2940266059SGregory Neil Shapiro#include &lt;unistd.h&gt;
3040266059SGregory Neil Shapiro#ifndef bool
3140266059SGregory Neil Shapiro#define bool char
3240266059SGregory Neil Shapiro#define TRUE 1
3340266059SGregory Neil Shapiro#define FALSE 0
3440266059SGregory Neil Shapiro#endif
3540266059SGregory Neil Shapiro
3640266059SGregory Neil Shapiroextern int errno;
3740266059SGregory Neil Shapiro
3840266059SGregory Neil Shapiro
3940266059SGregory Neil Shapirostruct mlfiPriv
4040266059SGregory Neil Shapiro{
4140266059SGregory Neil Shapiro    char    *mlfi_fname;
4240266059SGregory Neil Shapiro    char    *mlfi_connectfrom;
4340266059SGregory Neil Shapiro    char    *mlfi_helofrom;
4440266059SGregory Neil Shapiro    FILE    *mlfi_fp;
4540266059SGregory Neil Shapiro};
4640266059SGregory Neil Shapiro
4740266059SGregory Neil Shapiro#define MLFIPRIV        ((struct mlfiPriv *) <a href="smfi_getpriv.html">smfi_getpriv</a>(ctx))
4840266059SGregory Neil Shapiro
4940266059SGregory Neil Shapiroextern sfsistat  mlfi_cleanup(SMFICTX *, bool);
5040266059SGregory Neil Shapiro/* recipients to add and reject (set with -a and -r options) */
5140266059SGregory Neil Shapirochar *add, *reject;
5240266059SGregory Neil Shapiro
5340266059SGregory Neil Shapirosfsistat
5440266059SGregory Neil Shapiro<a href="xxfi_connect.html">mlfi_connect</a>(ctx, hostname, hostaddr)
5540266059SGregory Neil Shapiro     SMFICTX *ctx;
5640266059SGregory Neil Shapiro     char *hostname;
5740266059SGregory Neil Shapiro     _SOCK_ADDR *hostaddr;
5840266059SGregory Neil Shapiro{
5940266059SGregory Neil Shapiro    struct mlfiPriv *priv;
6040266059SGregory Neil Shapiro    char *ident;
6140266059SGregory Neil Shapiro
6240266059SGregory Neil Shapiro    /* allocate some private memory */
6340266059SGregory Neil Shapiro    priv = malloc(sizeof *priv);
6440266059SGregory Neil Shapiro    if (priv == NULL)
6540266059SGregory Neil Shapiro    {
6640266059SGregory Neil Shapiro	/* can't accept this message right now */
6740266059SGregory Neil Shapiro	return SMFIS_TEMPFAIL;
6840266059SGregory Neil Shapiro    }
6940266059SGregory Neil Shapiro    memset(priv, '\0', sizeof *priv);
7040266059SGregory Neil Shapiro
7140266059SGregory Neil Shapiro    /* save the private data */
7240266059SGregory Neil Shapiro    <a href="smfi_setpriv.html">smfi_setpriv</a>(ctx, priv);
7340266059SGregory Neil Shapiro
7440266059SGregory Neil Shapiro    ident = <a href="smfi_getsymval.html">smfi_getsymval</a>(ctx, "_");
7540266059SGregory Neil Shapiro    if(!ident) ident = "???";
7640266059SGregory Neil Shapiro    if(!(priv-&gt;mlfi_connectfrom = strdup(ident))) {
7740266059SGregory Neil Shapiro	return SMFIS_TEMPFAIL;
7840266059SGregory Neil Shapiro    }
7940266059SGregory Neil Shapiro    /* Continue processing. */
8040266059SGregory Neil Shapiro    return SMFIS_CONTINUE;
8140266059SGregory Neil Shapiro}
8240266059SGregory Neil Shapiro
8340266059SGregory Neil Shapirosfsistat
8440266059SGregory Neil Shapiro<a href="xxfi_helo.html">mlfi_helo</a>(ctx, helohost)
8540266059SGregory Neil Shapiro     SMFICTX *ctx;
8640266059SGregory Neil Shapiro     char *helohost;
8740266059SGregory Neil Shapiro{
8840266059SGregory Neil Shapiro    char *tls;
8940266059SGregory Neil Shapiro    char *buf;
9040266059SGregory Neil Shapiro    struct mlfiPriv *priv = MLFIPRIV;
9140266059SGregory Neil Shapiro    tls = <a href="smfi_getsymval.html">smfi_getsymval</a>(ctx, "{tls_version}");
9240266059SGregory Neil Shapiro    if(!tls) tls = "No TLS";
9340266059SGregory Neil Shapiro    if(!helohost) helohost = "???";
9440266059SGregory Neil Shapiro    if(!(buf = (char*)malloc(strlen(tls) + strlen(helohost) + 3))) {
9540266059SGregory Neil Shapiro	return SMFIS_TEMPFAIL;
9640266059SGregory Neil Shapiro    }
9740266059SGregory Neil Shapiro    sprintf(buf, "%s, %s", helohost, tls);
9840266059SGregory Neil Shapiro    if(priv-&gt;mlfi_helofrom)
9940266059SGregory Neil Shapiro	free(priv-&gt;mlfi_helofrom);
10040266059SGregory Neil Shapiro    priv-&gt;mlfi_helofrom = buf;
10140266059SGregory Neil Shapiro    /* Continue processing. */
10240266059SGregory Neil Shapiro    return SMFIS_CONTINUE;
10340266059SGregory Neil Shapiro}
10440266059SGregory Neil Shapiro
10540266059SGregory Neil Shapirosfsistat
10640266059SGregory Neil Shapiro<a href="xxfi_envfrom.html">mlfi_envfrom</a>(ctx, argv)
10740266059SGregory Neil Shapiro     SMFICTX *ctx;
10840266059SGregory Neil Shapiro     char **argv;
10940266059SGregory Neil Shapiro{
11040266059SGregory Neil Shapiro    struct mlfiPriv *priv = MLFIPRIV;
11140266059SGregory Neil Shapiro    char *mailaddr = <a href="smfi_getsymval.html">smfi_getsymval</a>(ctx, "{mail_addr}");
11240266059SGregory Neil Shapiro    int argc = 0;
11340266059SGregory Neil Shapiro
11440266059SGregory Neil Shapiro    /* open a file to store this message */
11540266059SGregory Neil Shapiro    priv-&gt;mlfi_fname = strdup("/tmp/msg.XXXXXX");
11640266059SGregory Neil Shapiro    mkstemp(priv-&gt;mlfi_fname);
11740266059SGregory Neil Shapiro    if (priv-&gt;mlfi_fname == NULL)
11840266059SGregory Neil Shapiro	return SMFIS_TEMPFAIL;
11940266059SGregory Neil Shapiro    if ((priv-&gt;mlfi_fp = fopen(priv-&gt;mlfi_fname, "w+")) == NULL)
12040266059SGregory Neil Shapiro    {
12140266059SGregory Neil Shapiro	free(priv-&gt;mlfi_fname);
12240266059SGregory Neil Shapiro	return SMFIS_TEMPFAIL;
12340266059SGregory Neil Shapiro    }
12440266059SGregory Neil Shapiro
12540266059SGregory Neil Shapiro    /* count the arguments */
12640266059SGregory Neil Shapiro    while(*argv++) ++argc;
12740266059SGregory Neil Shapiro    /* log the connection information we stored earlier: */
12840266059SGregory Neil Shapiro    if(fprintf(priv-&gt;mlfi_fp, "Connect from %s (%s)\n\n",
12940266059SGregory Neil Shapiro	       priv-&gt;mlfi_helofrom, priv-&gt;mlfi_connectfrom) == EOF) {
13040266059SGregory Neil Shapiro	(void) mlfi_cleanup(ctx, FALSE);
13140266059SGregory Neil Shapiro	return SMFIS_TEMPFAIL;
13240266059SGregory Neil Shapiro    }
13340266059SGregory Neil Shapiro    /* log the sender */
13440266059SGregory Neil Shapiro    if(fprintf(priv-&gt;mlfi_fp, "FROM %s (%d argument%s)\n",
13540266059SGregory Neil Shapiro	       mailaddr?mailaddr:"???", argc,
13640266059SGregory Neil Shapiro	       (argc == 1)?"":"s")
13740266059SGregory Neil Shapiro       == EOF) {
13840266059SGregory Neil Shapiro	(void) mlfi_cleanup(ctx, FALSE);
13940266059SGregory Neil Shapiro	return SMFIS_TEMPFAIL;
14040266059SGregory Neil Shapiro    }
14140266059SGregory Neil Shapiro    /* continue processing */
14240266059SGregory Neil Shapiro    return SMFIS_CONTINUE;
14340266059SGregory Neil Shapiro}
14440266059SGregory Neil Shapiro
14540266059SGregory Neil Shapirosfsistat
14640266059SGregory Neil Shapiro<a href="xxfi_envrcpt.html">mlfi_envrcpt</a>(ctx, argv)
14740266059SGregory Neil Shapiro     SMFICTX *ctx;
14840266059SGregory Neil Shapiro     char **argv;
14940266059SGregory Neil Shapiro{
15040266059SGregory Neil Shapiro    struct mlfiPriv *priv = MLFIPRIV;
15140266059SGregory Neil Shapiro    char *rcptaddr = <a href="smfi_getsymval.html">smfi_getsymval</a>(ctx, "{rcpt_addr}");
15240266059SGregory Neil Shapiro    int argc = 0;
15340266059SGregory Neil Shapiro    /* count the arguments */
15440266059SGregory Neil Shapiro    while(*argv++) ++argc;
15540266059SGregory Neil Shapiro    /* log this recipient */
15640266059SGregory Neil Shapiro    if(reject && rcptaddr && (strcmp(rcptaddr, reject) == 0)) {
15740266059SGregory Neil Shapiro	if(fprintf(priv-&gt;mlfi_fp, "RCPT %s -- REJECTED\n", rcptaddr)
15840266059SGregory Neil Shapiro	   == EOF) {
15940266059SGregory Neil Shapiro	    (void) mlfi_cleanup(ctx, FALSE);
16040266059SGregory Neil Shapiro	    return SMFIS_TEMPFAIL;
16140266059SGregory Neil Shapiro	}
16240266059SGregory Neil Shapiro	return SMFIS_REJECT;
16340266059SGregory Neil Shapiro    }
16440266059SGregory Neil Shapiro    if(fprintf(priv-&gt;mlfi_fp, "RCPT %s (%d argument%s)\n",
16540266059SGregory Neil Shapiro	       rcptaddr?rcptaddr:"???", argc,
16640266059SGregory Neil Shapiro	       (argc == 1)?"":"s")
16740266059SGregory Neil Shapiro       == EOF) {
16840266059SGregory Neil Shapiro	(void) mlfi_cleanup(ctx, FALSE);
16940266059SGregory Neil Shapiro	return SMFIS_TEMPFAIL;
17040266059SGregory Neil Shapiro    }
17140266059SGregory Neil Shapiro    /* continue processing */
17240266059SGregory Neil Shapiro    return SMFIS_CONTINUE;
17340266059SGregory Neil Shapiro}
17440266059SGregory Neil Shapiro
17540266059SGregory Neil Shapirosfsistat
17640266059SGregory Neil Shapiro<a href="xxfi_header.html">mlfi_header</a>(ctx, headerf, headerv)
17740266059SGregory Neil Shapiro     SMFICTX *ctx;
17840266059SGregory Neil Shapiro     char *headerf;
17940266059SGregory Neil Shapiro     unsigned char *headerv;
18040266059SGregory Neil Shapiro{
18140266059SGregory Neil Shapiro    /* write the header to the log file */
18240266059SGregory Neil Shapiro    fprintf(MLFIPRIV-&gt;mlfi_fp, "%s: %s\n", headerf, headerv);
18340266059SGregory Neil Shapiro
18440266059SGregory Neil Shapiro    /* continue processing */
18540266059SGregory Neil Shapiro    return SMFIS_CONTINUE;
18640266059SGregory Neil Shapiro}
18740266059SGregory Neil Shapiro
18840266059SGregory Neil Shapirosfsistat
18940266059SGregory Neil Shapiro<a href="xxfi_eoh.html">mlfi_eoh</a>(ctx)
19040266059SGregory Neil Shapiro     SMFICTX *ctx;
19140266059SGregory Neil Shapiro{
19240266059SGregory Neil Shapiro    /* output the blank line between the header and the body */
19340266059SGregory Neil Shapiro    fprintf(MLFIPRIV-&gt;mlfi_fp, "\n");
19440266059SGregory Neil Shapiro
19540266059SGregory Neil Shapiro    /* continue processing */
19640266059SGregory Neil Shapiro    return SMFIS_CONTINUE;
19740266059SGregory Neil Shapiro}
19840266059SGregory Neil Shapiro
19940266059SGregory Neil Shapirosfsistat
20040266059SGregory Neil Shapiro<a href="xxfi_body.html">mlfi_body</a>(ctx, bodyp, bodylen)
20140266059SGregory Neil Shapiro     SMFICTX *ctx;
20240266059SGregory Neil Shapiro     unsigned char *bodyp;
20340266059SGregory Neil Shapiro     size_t bodylen;
20440266059SGregory Neil Shapiro{
20540266059SGregory Neil Shapiro    /* output body block to log file */
20640266059SGregory Neil Shapiro    int nwritten;
20740266059SGregory Neil Shapiro    if ((nwritten = fwrite(bodyp, bodylen, 1, MLFIPRIV-&gt;mlfi_fp)) != 1)
20840266059SGregory Neil Shapiro    {
20940266059SGregory Neil Shapiro	/* write failed */
21040266059SGregory Neil Shapiro	perror("error logging body");
21140266059SGregory Neil Shapiro	(void) mlfi_cleanup(ctx, FALSE);
21240266059SGregory Neil Shapiro	return SMFIS_TEMPFAIL;
21340266059SGregory Neil Shapiro    }
21440266059SGregory Neil Shapiro
21540266059SGregory Neil Shapiro    /* continue processing */
21640266059SGregory Neil Shapiro    return SMFIS_CONTINUE;
21740266059SGregory Neil Shapiro}
21840266059SGregory Neil Shapiro
21940266059SGregory Neil Shapirosfsistat
22040266059SGregory Neil Shapiro<a href="xxfi_eom.html">mlfi_eom</a>(ctx)
22140266059SGregory Neil Shapiro     SMFICTX *ctx;
22240266059SGregory Neil Shapiro{
22340266059SGregory Neil Shapiro    bool ok = TRUE;
22440266059SGregory Neil Shapiro    /* change recipients, if requested */
22540266059SGregory Neil Shapiro    if(add)
22640266059SGregory Neil Shapiro	ok = ok && (<a href="smfi_addrcpt.html">smfi_addrcpt</a>(ctx, add) == MI_SUCCESS);
22740266059SGregory Neil Shapiro    return mlfi_cleanup(ctx, ok);
22840266059SGregory Neil Shapiro}
22940266059SGregory Neil Shapiro
23040266059SGregory Neil Shapirosfsistat
23140266059SGregory Neil Shapiro<a href="xxfi_abort.html">mlfi_abort</a>(ctx)
23240266059SGregory Neil Shapiro     SMFICTX *ctx;
23340266059SGregory Neil Shapiro{
23440266059SGregory Neil Shapiro    return mlfi_cleanup(ctx, FALSE);
23540266059SGregory Neil Shapiro}
23640266059SGregory Neil Shapiro
23740266059SGregory Neil Shapirosfsistat
23840266059SGregory Neil Shapiromlfi_cleanup(ctx, ok)
23940266059SGregory Neil Shapiro     SMFICTX *ctx;
24040266059SGregory Neil Shapiro     bool ok;
24140266059SGregory Neil Shapiro{
24240266059SGregory Neil Shapiro    sfsistat rstat = SMFIS_CONTINUE;
24340266059SGregory Neil Shapiro    struct mlfiPriv *priv = MLFIPRIV;
24440266059SGregory Neil Shapiro    char *p;
24540266059SGregory Neil Shapiro    char host[512];
24640266059SGregory Neil Shapiro    char hbuf[1024];
24740266059SGregory Neil Shapiro
24840266059SGregory Neil Shapiro    if (priv == NULL)
24940266059SGregory Neil Shapiro	return rstat;
25040266059SGregory Neil Shapiro
25140266059SGregory Neil Shapiro    /* close the archive file */
25240266059SGregory Neil Shapiro    if (priv-&gt;mlfi_fp != NULL && fclose(priv-&gt;mlfi_fp) == EOF)
25340266059SGregory Neil Shapiro    {
25440266059SGregory Neil Shapiro	/* failed; we have to wait until later */
25540266059SGregory Neil Shapiro	fprintf(stderr, "Couldn't close archive file %s: %s\n",
25640266059SGregory Neil Shapiro		priv-&gt;mlfi_fname, strerror(errno));
25740266059SGregory Neil Shapiro	rstat = SMFIS_TEMPFAIL;
25840266059SGregory Neil Shapiro	(void) unlink(priv-&gt;mlfi_fname);
25940266059SGregory Neil Shapiro    }
26040266059SGregory Neil Shapiro    else if (ok)
26140266059SGregory Neil Shapiro    {
26240266059SGregory Neil Shapiro	/* add a header to the message announcing our presence */
26340266059SGregory Neil Shapiro	if (gethostname(host, sizeof host) &lt; 0)
26440266059SGregory Neil Shapiro	    strncpy(host, "localhost", sizeof host);
26540266059SGregory Neil Shapiro	p = strrchr(priv-&gt;mlfi_fname, '/');
26640266059SGregory Neil Shapiro	if (p == NULL)
26740266059SGregory Neil Shapiro	    p = priv-&gt;mlfi_fname;
26840266059SGregory Neil Shapiro	else
26940266059SGregory Neil Shapiro	    p++;
27040266059SGregory Neil Shapiro	snprintf(hbuf, sizeof hbuf, "%s@%s", p, host);
27140266059SGregory Neil Shapiro	<a href="smfi_addheader.html">smfi_addheader</a>(ctx, "X-Archived", hbuf);
27240266059SGregory Neil Shapiro    }
27340266059SGregory Neil Shapiro    else
27440266059SGregory Neil Shapiro    {
27540266059SGregory Neil Shapiro	/* message was aborted -- delete the archive file */
27640266059SGregory Neil Shapiro	fprintf(stderr, "Message aborted.  Removing %s\n",
27740266059SGregory Neil Shapiro		priv-&gt;mlfi_fname);
27840266059SGregory Neil Shapiro	rstat = SMFIS_TEMPFAIL;
27940266059SGregory Neil Shapiro	(void) unlink(priv-&gt;mlfi_fname);
28040266059SGregory Neil Shapiro    }
28140266059SGregory Neil Shapiro
28240266059SGregory Neil Shapiro    /* release private memory */
28340266059SGregory Neil Shapiro    free(priv-&gt;mlfi_fname);
28440266059SGregory Neil Shapiro
28540266059SGregory Neil Shapiro    /* return status */
28640266059SGregory Neil Shapiro    return rstat;
28740266059SGregory Neil Shapiro}
28840266059SGregory Neil Shapiro
28940266059SGregory Neil Shapirosfsistat
29040266059SGregory Neil Shapiro<a href="xxfi_close.html">mlfi_close</a>(ctx)
29140266059SGregory Neil Shapiro     SMFICTX *ctx;
29240266059SGregory Neil Shapiro{
29340266059SGregory Neil Shapiro    struct mlfiPriv *priv = MLFIPRIV;
29440266059SGregory Neil Shapiro    if(priv-&gt;mlfi_connectfrom)
29540266059SGregory Neil Shapiro	free(priv-&gt;mlfi_connectfrom);
29640266059SGregory Neil Shapiro    if(priv-&gt;mlfi_helofrom)
29740266059SGregory Neil Shapiro	free(priv-&gt;mlfi_helofrom);
29840266059SGregory Neil Shapiro    free(priv);
29940266059SGregory Neil Shapiro    <a href="smfi_setpriv.html">smfi_setpriv</a>(ctx, NULL);
30040266059SGregory Neil Shapiro    return SMFIS_CONTINUE;
30140266059SGregory Neil Shapiro}
30240266059SGregory Neil Shapiro
30340266059SGregory Neil Shapirostruct smfiDesc smfilter =
30440266059SGregory Neil Shapiro{
30540266059SGregory Neil Shapiro    "SampleFilter", /* filter name */
30640266059SGregory Neil Shapiro    SMFI_VERSION,   /* version code -- do not change */
30740266059SGregory Neil Shapiro    SMFIF_ADDHDRS,  /* flags */
30840266059SGregory Neil Shapiro    <a href="xxfi_connect.html">mlfi_connect</a>,   /* connection info filter */
30940266059SGregory Neil Shapiro    <a href="xxfi_helo.html">mlfi_helo</a>,      /* SMTP HELO command filter */
31040266059SGregory Neil Shapiro    <a href="xxfi_envfrom.html">mlfi_envfrom</a>,   /* envelope sender filter */
31140266059SGregory Neil Shapiro    <a href="xxfi_envrcpt.html">mlfi_envrcpt</a>,   /* envelope recipient filter */
31240266059SGregory Neil Shapiro    <a href="xxfi_header.html">mlfi_header</a>,    /* header filter */
31340266059SGregory Neil Shapiro    <a href="xxfi_eoh.html">mlfi_eoh</a>,       /* end of header */
31440266059SGregory Neil Shapiro    <a href="xxfi_body.html">mlfi_body</a>,      /* body block filter */
31540266059SGregory Neil Shapiro    <a href="xxfi_eom.html">mlfi_eom</a>,       /* end of message */
31640266059SGregory Neil Shapiro    <a href="xxfi_abort.html">mlfi_abort</a>,     /* message aborted */
31740266059SGregory Neil Shapiro    <a href="xxfi_close.html">mlfi_close</a>,     /* connection cleanup */
31840266059SGregory Neil Shapiro};
31940266059SGregory Neil Shapiro
32040266059SGregory Neil Shapirostatic void
32140266059SGregory Neil Shapirousage()
32240266059SGregory Neil Shapiro{
32340266059SGregory Neil Shapiro    fprintf(stderr,
32440266059SGregory Neil Shapiro	    "Usage: sample [-p socket-addr] [-t timeout] [-r reject-addr] \n\
32540266059SGregory Neil Shapiro\t[-a accept-addr]\n");
32640266059SGregory Neil Shapiro}
32740266059SGregory Neil Shapiro
32840266059SGregory Neil Shapiroint
32940266059SGregory Neil Shapiromain(argc, argv)
33040266059SGregory Neil Shapiro     int argc;
33140266059SGregory Neil Shapiro     char *argv[];
33240266059SGregory Neil Shapiro{
33340266059SGregory Neil Shapiro    int retval;
33440266059SGregory Neil Shapiro    char c;
33540266059SGregory Neil Shapiro    const char *args = "p:t:r:a:h";
33640266059SGregory Neil Shapiro    extern char *optarg;
33740266059SGregory Neil Shapiro
33840266059SGregory Neil Shapiro    /* Process command line options */
33940266059SGregory Neil Shapiro    while ((c = getopt(argc, argv, args)) != (char)EOF)
34040266059SGregory Neil Shapiro    {
34140266059SGregory Neil Shapiro	switch (c)
34240266059SGregory Neil Shapiro	{
34340266059SGregory Neil Shapiro	case 'p':
34440266059SGregory Neil Shapiro	    if (optarg == NULL || *optarg == '\0')
34540266059SGregory Neil Shapiro	    {
34640266059SGregory Neil Shapiro		(void) fprintf(stderr, "Illegal conn: %s\n",
34740266059SGregory Neil Shapiro			       optarg);
34840266059SGregory Neil Shapiro		exit(EX_USAGE);
34940266059SGregory Neil Shapiro	    }
35040266059SGregory Neil Shapiro	    if(<a href="smfi_setconn.html">smfi_setconn</a>(optarg) == MI_FAILURE)
35140266059SGregory Neil Shapiro	    {
35240266059SGregory Neil Shapiro		(void) fputs("smfi_setconn failed", stderr);
35340266059SGregory Neil Shapiro		exit(EX_SOFTWARE);
35440266059SGregory Neil Shapiro	    }
35540266059SGregory Neil Shapiro	    /*
35640266059SGregory Neil Shapiro	    ** If we're using a local socket, make sure it doesn't
35740266059SGregory Neil Shapiro	    ** already exist.
35840266059SGregory Neil Shapiro	    */
35940266059SGregory Neil Shapiro	    if(strncmp(optarg, "unix:", 5) == 0)
36040266059SGregory Neil Shapiro		unlink(optarg + 5);
36140266059SGregory Neil Shapiro	    else if(strncmp(optarg, "local:", 6) == 0)
36240266059SGregory Neil Shapiro		unlink(optarg + 6);
36340266059SGregory Neil Shapiro	    break;
36440266059SGregory Neil Shapiro
36540266059SGregory Neil Shapiro	case 't':
36640266059SGregory Neil Shapiro	    if (optarg == NULL || *optarg == '\0')
36740266059SGregory Neil Shapiro	    {
36840266059SGregory Neil Shapiro		(void) fprintf(stderr, "Illegal timeout: %s\n",
36940266059SGregory Neil Shapiro			       optarg);
37040266059SGregory Neil Shapiro		exit(EX_USAGE);
37140266059SGregory Neil Shapiro	    }
37240266059SGregory Neil Shapiro	    if(<a href="smfi_settimeout.html">smfi_settimeout</a>(atoi(optarg)) == MI_FAILURE)
37340266059SGregory Neil Shapiro	    {
37440266059SGregory Neil Shapiro		(void) fputs("smfi_settimeout failed", stderr);
37540266059SGregory Neil Shapiro		exit(EX_SOFTWARE);
37640266059SGregory Neil Shapiro	    }
37740266059SGregory Neil Shapiro	    break;
37840266059SGregory Neil Shapiro
37940266059SGregory Neil Shapiro	case 'r':
38040266059SGregory Neil Shapiro	    if (optarg == NULL)
38140266059SGregory Neil Shapiro	    {
38240266059SGregory Neil Shapiro		(void) fprintf(stderr, "Illegal reject rcpt: %s\n",
38340266059SGregory Neil Shapiro			       optarg);
38440266059SGregory Neil Shapiro		exit(EX_USAGE);
38540266059SGregory Neil Shapiro	    }
38640266059SGregory Neil Shapiro	    reject = optarg;
38740266059SGregory Neil Shapiro	    break;
38840266059SGregory Neil Shapiro
38940266059SGregory Neil Shapiro	case 'a':
39040266059SGregory Neil Shapiro	    if (optarg == NULL)
39140266059SGregory Neil Shapiro	    {
39240266059SGregory Neil Shapiro		(void) fprintf(stderr, "Illegal add rcpt: %s\n",
39340266059SGregory Neil Shapiro			       optarg);
39440266059SGregory Neil Shapiro		exit(EX_USAGE);
39540266059SGregory Neil Shapiro	    }
39640266059SGregory Neil Shapiro	    add = optarg;
39740266059SGregory Neil Shapiro	    smfilter.xxfi_flags |= SMFIF_ADDRCPT;
39840266059SGregory Neil Shapiro	    break;
39940266059SGregory Neil Shapiro	case 'h':
40040266059SGregory Neil Shapiro	default:
40140266059SGregory Neil Shapiro	    usage();
40240266059SGregory Neil Shapiro	    exit(0);
40340266059SGregory Neil Shapiro	}
40440266059SGregory Neil Shapiro    }
40540266059SGregory Neil Shapiro    if (<a href="smfi_register.html">smfi_register</a>(smfilter) == MI_FAILURE)
40640266059SGregory Neil Shapiro    {
40740266059SGregory Neil Shapiro	fprintf(stderr, "smfi_register failed\n");
40840266059SGregory Neil Shapiro	exit(EX_UNAVAILABLE);
40940266059SGregory Neil Shapiro    }
41040266059SGregory Neil Shapiro    retval = <a href="smfi_main.html">smfi_main</a>();
41140266059SGregory Neil Shapiro    return retval;
41240266059SGregory Neil Shapiro}
41340266059SGregory Neil Shapiro
41440266059SGregory Neil Shapiro/* eof */
41540266059SGregory Neil Shapiro
41640266059SGregory Neil Shapiro</pre>
41740266059SGregory Neil Shapiro<hr size="1">
41840266059SGregory Neil Shapiro<font size="-1">
41940266059SGregory Neil ShapiroCopyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
42040266059SGregory Neil ShapiroAll rights reserved.
42140266059SGregory Neil Shapiro<br>
42240266059SGregory Neil ShapiroBy using this file, you agree to the terms and conditions set
42340266059SGregory Neil Shapiroforth in the <a href="LICENSE.txt">LICENSE</a>.
42440266059SGregory Neil Shapiro</font>
42540266059SGregory Neil Shapiro</body>
42640266059SGregory Neil Shapiro</html>
427