1168515Sgshapiro<HTML> 2168515Sgshapiro<HEAD><TITLE>A Sample Filter</TITLE></HEAD> 3168515Sgshapiro<BODY> 4132943Sgshapiro<!-- 5266692Sgshapiro$Id: sample.html,v 1.23 2013-11-22 20:51:39 ca Exp $ 6132943Sgshapiro--> 7168515Sgshapiro<H1>A Sample Filter</H1> 890792Sgshapiro 990792SgshapiroThe following sample logs each message to a separate temporary file, 10168515Sgshapiroadds a recipient given with the -a flag, 11168515Sgshapiroand rejects a disallowed recipient address given with the -r flag. 12168515SgshapiroIt recognizes the following options: 13168515Sgshapiro<P> 14168515Sgshapiro<CENTER> 15168515Sgshapiro<TABLE border="1" cellpadding=2 cellspacing=1> 16168515Sgshapiro<TR><TD><CODE>-p port</CODE></TD><TD>The port through which the MTA will connect to the filter.</TD></TR> 17168515Sgshapiro<TR><TD><CODE>-t sec</CODE></TD><TD>The timeout value.</TD></TR> 18168515Sgshapiro<TR><TD><CODE>-r addr</CODE></TD><TD>A recipient to reject.</TD></TR> 19168515Sgshapiro<TR><TD><CODE>-a addr</CODE></TD><TD>A recipient to add.</TD></TR> 20168515Sgshapiro</TABLE> 21168515Sgshapiro</CENTER> 22168515Sgshapiro<HR> 23168515Sgshapiro<PRE> 2498121Sgshapiro#include <sys/types.h> 2598121Sgshapiro#include <sys/stat.h> 2698121Sgshapiro#include <errno.h> 2790792Sgshapiro#include <stdio.h> 2890792Sgshapiro#include <stdlib.h> 2990792Sgshapiro#include <string.h> 3090792Sgshapiro#include <sysexits.h> 3190792Sgshapiro#include <unistd.h> 3298121Sgshapiro 3398121Sgshapiro#include "libmilter/mfapi.h" 3498121Sgshapiro 3590792Sgshapiro#ifndef bool 3698121Sgshapiro# define bool int 3798121Sgshapiro# define TRUE 1 3898121Sgshapiro# define FALSE 0 3998121Sgshapiro#endif /* ! bool */ 4090792Sgshapiro 4190792Sgshapiro 4290792Sgshapirostruct mlfiPriv 4390792Sgshapiro{ 4498121Sgshapiro char *mlfi_fname; 4598121Sgshapiro char *mlfi_connectfrom; 4698121Sgshapiro char *mlfi_helofrom; 4798121Sgshapiro FILE *mlfi_fp; 4890792Sgshapiro}; 4990792Sgshapiro 50168515Sgshapiro#define MLFIPRIV ((struct mlfiPriv *) <A href="smfi_getpriv.html">smfi_getpriv</A>(ctx)) 5190792Sgshapiro 5298121Sgshapiroextern sfsistat mlfi_cleanup(SMFICTX *, bool); 5398121Sgshapiro 5490792Sgshapiro/* recipients to add and reject (set with -a and -r options) */ 5598121Sgshapirochar *add = NULL; 5698121Sgshapirochar *reject = NULL; 5790792Sgshapiro 5890792Sgshapirosfsistat 59168515Sgshapiro<A href="xxfi_connect.html">mlfi_connect</A>(ctx, hostname, hostaddr) 6098121Sgshapiro SMFICTX *ctx; 6198121Sgshapiro char *hostname; 6298121Sgshapiro _SOCK_ADDR *hostaddr; 6390792Sgshapiro{ 6498121Sgshapiro struct mlfiPriv *priv; 6598121Sgshapiro char *ident; 6690792Sgshapiro 6798121Sgshapiro /* allocate some private memory */ 6898121Sgshapiro priv = malloc(sizeof *priv); 6998121Sgshapiro if (priv == NULL) 7098121Sgshapiro { 7198121Sgshapiro /* can't accept this message right now */ 7298121Sgshapiro return SMFIS_TEMPFAIL; 7398121Sgshapiro } 7498121Sgshapiro memset(priv, '\0', sizeof *priv); 7590792Sgshapiro 7698121Sgshapiro /* save the private data */ 77168515Sgshapiro <A href="smfi_setpriv.html">smfi_setpriv</A>(ctx, priv); 7898121Sgshapiro 79168515Sgshapiro ident = <A href="smfi_getsymval.html">smfi_getsymval</A>(ctx, "_"); 8098121Sgshapiro if (ident == NULL) 8198121Sgshapiro ident = "???"; 8298121Sgshapiro if ((priv->mlfi_connectfrom = strdup(ident)) == NULL) 8398121Sgshapiro { 8498121Sgshapiro (void) mlfi_cleanup(ctx, FALSE); 8598121Sgshapiro return SMFIS_TEMPFAIL; 8698121Sgshapiro } 8798121Sgshapiro 8898121Sgshapiro /* continue processing */ 8998121Sgshapiro return SMFIS_CONTINUE; 9090792Sgshapiro} 9190792Sgshapiro 9290792Sgshapirosfsistat 93168515Sgshapiro<A href="xxfi_helo.html">mlfi_helo</A>(ctx, helohost) 9498121Sgshapiro SMFICTX *ctx; 9598121Sgshapiro char *helohost; 9690792Sgshapiro{ 9798121Sgshapiro size_t len; 9898121Sgshapiro char *tls; 9998121Sgshapiro char *buf; 10098121Sgshapiro struct mlfiPriv *priv = MLFIPRIV; 10198121Sgshapiro 102168515Sgshapiro tls = <A href="smfi_getsymval.html">smfi_getsymval</A>(ctx, "{tls_version}"); 10398121Sgshapiro if (tls == NULL) 10498121Sgshapiro tls = "No TLS"; 10598121Sgshapiro if (helohost == NULL) 10698121Sgshapiro helohost = "???"; 10798121Sgshapiro len = strlen(tls) + strlen(helohost) + 3; 10898121Sgshapiro if ((buf = (char*) malloc(len)) == NULL) 10998121Sgshapiro { 11098121Sgshapiro (void) mlfi_cleanup(ctx, FALSE); 11198121Sgshapiro return SMFIS_TEMPFAIL; 11298121Sgshapiro } 11398121Sgshapiro snprintf(buf, len, "%s, %s", helohost, tls); 11498121Sgshapiro if (priv->mlfi_helofrom != NULL) 11598121Sgshapiro free(priv->mlfi_helofrom); 11698121Sgshapiro priv->mlfi_helofrom = buf; 11798121Sgshapiro 11898121Sgshapiro /* continue processing */ 11998121Sgshapiro return SMFIS_CONTINUE; 12090792Sgshapiro} 12190792Sgshapiro 12290792Sgshapirosfsistat 123168515Sgshapiro<A href="xxfi_envfrom.html">mlfi_envfrom</A>(ctx, argv) 12498121Sgshapiro SMFICTX *ctx; 12598121Sgshapiro char **argv; 12690792Sgshapiro{ 127132943Sgshapiro int fd = -1; 128132943Sgshapiro int argc = 0; 12998121Sgshapiro struct mlfiPriv *priv = MLFIPRIV; 130168515Sgshapiro char *mailaddr = <A href="smfi_getsymval.html">smfi_getsymval</A>(ctx, "{mail_addr}"); 13190792Sgshapiro 13298121Sgshapiro /* open a file to store this message */ 13398121Sgshapiro if ((priv->mlfi_fname = strdup("/tmp/msg.XXXXXX")) == NULL) 13498121Sgshapiro { 13598121Sgshapiro (void) mlfi_cleanup(ctx, FALSE); 13698121Sgshapiro return SMFIS_TEMPFAIL; 13798121Sgshapiro } 13890792Sgshapiro 139132943Sgshapiro if ((fd = mkstemp(priv->mlfi_fname)) == -1) 14098121Sgshapiro { 14198121Sgshapiro (void) mlfi_cleanup(ctx, FALSE); 14298121Sgshapiro return SMFIS_TEMPFAIL; 14398121Sgshapiro } 14498121Sgshapiro 145132943Sgshapiro if ((priv->mlfi_fp = fdopen(fd, "w+")) == NULL) 14698121Sgshapiro { 147132943Sgshapiro (void) close(fd); 14898121Sgshapiro (void) mlfi_cleanup(ctx, FALSE); 14998121Sgshapiro return SMFIS_TEMPFAIL; 15098121Sgshapiro } 15198121Sgshapiro 15298121Sgshapiro /* count the arguments */ 15398121Sgshapiro while (*argv++ != NULL) 15498121Sgshapiro ++argc; 15598121Sgshapiro 15698121Sgshapiro /* log the connection information we stored earlier: */ 15798121Sgshapiro if (fprintf(priv->mlfi_fp, "Connect from %s (%s)\n\n", 15898121Sgshapiro priv->mlfi_helofrom, priv->mlfi_connectfrom) == EOF) 15998121Sgshapiro { 16098121Sgshapiro (void) mlfi_cleanup(ctx, FALSE); 16198121Sgshapiro return SMFIS_TEMPFAIL; 16298121Sgshapiro } 16398121Sgshapiro /* log the sender */ 16498121Sgshapiro if (fprintf(priv->mlfi_fp, "FROM %s (%d argument%s)\n", 16598121Sgshapiro mailaddr ? mailaddr : "???", argc, 16698121Sgshapiro (argc == 1) ? "" : "s") == EOF) 16798121Sgshapiro { 16898121Sgshapiro (void) mlfi_cleanup(ctx, FALSE); 16998121Sgshapiro return SMFIS_TEMPFAIL; 17098121Sgshapiro } 17198121Sgshapiro 17298121Sgshapiro /* continue processing */ 17398121Sgshapiro return SMFIS_CONTINUE; 17490792Sgshapiro} 17590792Sgshapiro 17690792Sgshapirosfsistat 177168515Sgshapiro<A href="xxfi_envrcpt.html">mlfi_envrcpt</A>(ctx, argv) 17898121Sgshapiro SMFICTX *ctx; 17998121Sgshapiro char **argv; 18090792Sgshapiro{ 18198121Sgshapiro struct mlfiPriv *priv = MLFIPRIV; 182168515Sgshapiro char *rcptaddr = <A href="smfi_getsymval.html">smfi_getsymval</A>(ctx, "{rcpt_addr}"); 18398121Sgshapiro int argc = 0; 18498121Sgshapiro 18598121Sgshapiro /* count the arguments */ 18698121Sgshapiro while (*argv++ != NULL) 18798121Sgshapiro ++argc; 18898121Sgshapiro 18998121Sgshapiro /* log this recipient */ 19098121Sgshapiro if (reject != NULL && rcptaddr != NULL && 19198121Sgshapiro (strcasecmp(rcptaddr, reject) == 0)) 19298121Sgshapiro { 19398121Sgshapiro if (fprintf(priv->mlfi_fp, "RCPT %s -- REJECTED\n", 19498121Sgshapiro rcptaddr) == EOF) 19598121Sgshapiro { 19698121Sgshapiro (void) mlfi_cleanup(ctx, FALSE); 19798121Sgshapiro return SMFIS_TEMPFAIL; 19898121Sgshapiro } 19998121Sgshapiro return SMFIS_REJECT; 20090792Sgshapiro } 20198121Sgshapiro if (fprintf(priv->mlfi_fp, "RCPT %s (%d argument%s)\n", 20298121Sgshapiro rcptaddr ? rcptaddr : "???", argc, 20398121Sgshapiro (argc == 1) ? "" : "s") == EOF) 20498121Sgshapiro { 20598121Sgshapiro (void) mlfi_cleanup(ctx, FALSE); 20698121Sgshapiro return SMFIS_TEMPFAIL; 20798121Sgshapiro } 20898121Sgshapiro 20998121Sgshapiro /* continue processing */ 21098121Sgshapiro return SMFIS_CONTINUE; 21190792Sgshapiro} 21290792Sgshapiro 21390792Sgshapirosfsistat 214168515Sgshapiro<A href="xxfi_header.html">mlfi_header</A>(ctx, headerf, headerv) 21598121Sgshapiro SMFICTX *ctx; 21698121Sgshapiro char *headerf; 21798121Sgshapiro unsigned char *headerv; 21890792Sgshapiro{ 21998121Sgshapiro /* write the header to the log file */ 22098121Sgshapiro if (fprintf(MLFIPRIV->mlfi_fp, "%s: %s\n", headerf, headerv) == EOF) 22198121Sgshapiro { 22298121Sgshapiro (void) mlfi_cleanup(ctx, FALSE); 22398121Sgshapiro return SMFIS_TEMPFAIL; 22498121Sgshapiro } 22590792Sgshapiro 22698121Sgshapiro /* continue processing */ 22798121Sgshapiro return SMFIS_CONTINUE; 22890792Sgshapiro} 22990792Sgshapiro 23090792Sgshapirosfsistat 231168515Sgshapiro<A href="xxfi_eoh.html">mlfi_eoh</A>(ctx) 23298121Sgshapiro SMFICTX *ctx; 23390792Sgshapiro{ 23498121Sgshapiro /* output the blank line between the header and the body */ 23598121Sgshapiro if (fprintf(MLFIPRIV->mlfi_fp, "\n") == EOF) 23698121Sgshapiro { 23798121Sgshapiro (void) mlfi_cleanup(ctx, FALSE); 23898121Sgshapiro return SMFIS_TEMPFAIL; 23998121Sgshapiro } 24090792Sgshapiro 24198121Sgshapiro /* continue processing */ 24298121Sgshapiro return SMFIS_CONTINUE; 24390792Sgshapiro} 24490792Sgshapiro 24590792Sgshapirosfsistat 246168515Sgshapiro<A href="xxfi_body.html">mlfi_body</A>(ctx, bodyp, bodylen) 24798121Sgshapiro SMFICTX *ctx; 24898121Sgshapiro unsigned char *bodyp; 24998121Sgshapiro size_t bodylen; 25090792Sgshapiro{ 25198121Sgshapiro struct mlfiPriv *priv = MLFIPRIV; 25290792Sgshapiro 25398121Sgshapiro /* output body block to log file */ 25498121Sgshapiro if (fwrite(bodyp, bodylen, 1, priv->mlfi_fp) != 1) 25598121Sgshapiro { 25698121Sgshapiro /* write failed */ 25798121Sgshapiro fprintf(stderr, "Couldn't write file %s: %s\n", 25898121Sgshapiro priv->mlfi_fname, strerror(errno)); 25998121Sgshapiro (void) mlfi_cleanup(ctx, FALSE); 26098121Sgshapiro return SMFIS_TEMPFAIL; 26198121Sgshapiro } 26298121Sgshapiro 26398121Sgshapiro /* continue processing */ 26498121Sgshapiro return SMFIS_CONTINUE; 26590792Sgshapiro} 26690792Sgshapiro 26790792Sgshapirosfsistat 268168515Sgshapiro<A href="xxfi_eom.html">mlfi_eom</A>(ctx) 26998121Sgshapiro SMFICTX *ctx; 27090792Sgshapiro{ 27198121Sgshapiro bool ok = TRUE; 27298121Sgshapiro 27398121Sgshapiro /* change recipients, if requested */ 27498121Sgshapiro if (add != NULL) 275168515Sgshapiro ok = (<A href="smfi_addrcpt.html">smfi_addrcpt</A>(ctx, add) == MI_SUCCESS); 27698121Sgshapiro return mlfi_cleanup(ctx, ok); 27790792Sgshapiro} 27890792Sgshapiro 27990792Sgshapirosfsistat 280168515Sgshapiro<A href="xxfi_abort.html">mlfi_abort</A>(ctx) 28198121Sgshapiro SMFICTX *ctx; 28290792Sgshapiro{ 28398121Sgshapiro return mlfi_cleanup(ctx, FALSE); 28490792Sgshapiro} 28590792Sgshapiro 28690792Sgshapirosfsistat 28790792Sgshapiromlfi_cleanup(ctx, ok) 28898121Sgshapiro SMFICTX *ctx; 28998121Sgshapiro bool ok; 29090792Sgshapiro{ 29198121Sgshapiro sfsistat rstat = SMFIS_CONTINUE; 29298121Sgshapiro struct mlfiPriv *priv = MLFIPRIV; 29398121Sgshapiro char *p; 29498121Sgshapiro char host[512]; 29598121Sgshapiro char hbuf[1024]; 29690792Sgshapiro 29798121Sgshapiro if (priv == NULL) 29898121Sgshapiro return rstat; 29990792Sgshapiro 30098121Sgshapiro /* close the archive file */ 30198121Sgshapiro if (priv->mlfi_fp != NULL && fclose(priv->mlfi_fp) == EOF) 30298121Sgshapiro { 30398121Sgshapiro /* failed; we have to wait until later */ 30498121Sgshapiro fprintf(stderr, "Couldn't close archive file %s: %s\n", 30598121Sgshapiro priv->mlfi_fname, strerror(errno)); 30698121Sgshapiro rstat = SMFIS_TEMPFAIL; 30798121Sgshapiro (void) unlink(priv->mlfi_fname); 30898121Sgshapiro } 30998121Sgshapiro else if (ok) 31098121Sgshapiro { 31198121Sgshapiro /* add a header to the message announcing our presence */ 31298121Sgshapiro if (gethostname(host, sizeof host) < 0) 31398121Sgshapiro snprintf(host, sizeof host, "localhost"); 31498121Sgshapiro p = strrchr(priv->mlfi_fname, '/'); 31598121Sgshapiro if (p == NULL) 31698121Sgshapiro p = priv->mlfi_fname; 31798121Sgshapiro else 31898121Sgshapiro p++; 31998121Sgshapiro snprintf(hbuf, sizeof hbuf, "%s@%s", p, host); 320168515Sgshapiro if (<A href="smfi_addheader.html">smfi_addheader</A>(ctx, "X-Archived", hbuf) != MI_SUCCESS) 32198121Sgshapiro { 32298121Sgshapiro /* failed; we have to wait until later */ 32398121Sgshapiro fprintf(stderr, 32498121Sgshapiro "Couldn't add header: X-Archived: %s\n", 32598121Sgshapiro hbuf); 32698121Sgshapiro ok = FALSE; 32798121Sgshapiro rstat = SMFIS_TEMPFAIL; 32898121Sgshapiro (void) unlink(priv->mlfi_fname); 32998121Sgshapiro } 33098121Sgshapiro } 33190792Sgshapiro else 33298121Sgshapiro { 33398121Sgshapiro /* message was aborted -- delete the archive file */ 33498121Sgshapiro fprintf(stderr, "Message aborted. Removing %s\n", 33598121Sgshapiro priv->mlfi_fname); 33698121Sgshapiro rstat = SMFIS_TEMPFAIL; 33798121Sgshapiro (void) unlink(priv->mlfi_fname); 33898121Sgshapiro } 33990792Sgshapiro 34098121Sgshapiro /* release private memory */ 34198121Sgshapiro if (priv->mlfi_fname != NULL) 34298121Sgshapiro free(priv->mlfi_fname); 34390792Sgshapiro 34498121Sgshapiro /* return status */ 34598121Sgshapiro return rstat; 34690792Sgshapiro} 34790792Sgshapiro 34890792Sgshapirosfsistat 349168515Sgshapiro<A href="xxfi_close.html">mlfi_close</A>(ctx) 35098121Sgshapiro SMFICTX *ctx; 35190792Sgshapiro{ 35298121Sgshapiro struct mlfiPriv *priv = MLFIPRIV; 35398121Sgshapiro 35498121Sgshapiro if (priv == NULL) 35598121Sgshapiro return SMFIS_CONTINUE; 35698121Sgshapiro if (priv->mlfi_connectfrom != NULL) 35798121Sgshapiro free(priv->mlfi_connectfrom); 35898121Sgshapiro if (priv->mlfi_helofrom != NULL) 35998121Sgshapiro free(priv->mlfi_helofrom); 36098121Sgshapiro free(priv); 361168515Sgshapiro <A href="smfi_setpriv.html">smfi_setpriv</A>(ctx, NULL); 36298121Sgshapiro return SMFIS_CONTINUE; 36390792Sgshapiro} 36490792Sgshapiro 365168515Sgshapirosfsistat 366168515Sgshapiro<A href="xxfi_unknown.html">mlfi_unknown</A>(ctx, cmd) 367168515Sgshapiro SMFICTX *ctx; 368168515Sgshapiro char *cmd; 369168515Sgshapiro{ 370168515Sgshapiro return SMFIS_CONTINUE; 371168515Sgshapiro} 372168515Sgshapiro 373168515Sgshapirosfsistat 374168515Sgshapiro<A href="xxfi_data.html">mlfi_data</A>(ctx) 375168515Sgshapiro SMFICTX *ctx; 376168515Sgshapiro{ 377168515Sgshapiro return SMFIS_CONTINUE; 378168515Sgshapiro} 379168515Sgshapiro 380168515Sgshapirosfsistat 381168515Sgshapiro<A href="xxfi_negotiate.html">mlfi_negotiate</A>(ctx, f0, f1, f2, f3, pf0, pf1, pf2, pf3) 382168515Sgshapiro SMFICTX *ctx; 383168515Sgshapiro unsigned long f0; 384168515Sgshapiro unsigned long f1; 385168515Sgshapiro unsigned long f2; 386168515Sgshapiro unsigned long f3; 387168515Sgshapiro unsigned long *pf0; 388168515Sgshapiro unsigned long *pf1; 389168515Sgshapiro unsigned long *pf2; 390168515Sgshapiro unsigned long *pf3; 391168515Sgshapiro{ 392168515Sgshapiro return SMFIS_ALL_OPTS; 393168515Sgshapiro} 394168515Sgshapiro 39590792Sgshapirostruct smfiDesc smfilter = 39690792Sgshapiro{ 39798121Sgshapiro "SampleFilter", /* filter name */ 39898121Sgshapiro SMFI_VERSION, /* version code -- do not change */ 399132943Sgshapiro SMFIF_ADDHDRS|SMFIF_ADDRCPT, 400132943Sgshapiro /* flags */ 401168515Sgshapiro <A href="xxfi_connect.html">mlfi_connect</A>, /* connection info filter */ 402168515Sgshapiro <A href="xxfi_helo.html">mlfi_helo</A>, /* SMTP HELO command filter */ 403168515Sgshapiro <A href="xxfi_envfrom.html">mlfi_envfrom</A>, /* envelope sender filter */ 404168515Sgshapiro <A href="xxfi_envrcpt.html">mlfi_envrcpt</A>, /* envelope recipient filter */ 405168515Sgshapiro <A href="xxfi_header.html">mlfi_header</A>, /* header filter */ 406168515Sgshapiro <A href="xxfi_eoh.html">mlfi_eoh</A>, /* end of header */ 407168515Sgshapiro <A href="xxfi_body.html">mlfi_body</A>, /* body block filter */ 408168515Sgshapiro <A href="xxfi_eom.html">mlfi_eom</A>, /* end of message */ 409168515Sgshapiro <A href="xxfi_abort.html">mlfi_abort</A>, /* message aborted */ 410168515Sgshapiro <A href="xxfi_close.html">mlfi_close</A>, /* connection cleanup */ 411168515Sgshapiro <A href="xxfi_unknown.html">mlfi_unknown</A>, /* unknown SMTP commands */ 412168515Sgshapiro <A href="xxfi_data.html">mlfi_data</A>, /* DATA command */ 413168515Sgshapiro <A href="xxfi_negotiate.html">mlfi_negotiate</A> /* Once, at the start of each SMTP connection */ 41490792Sgshapiro}; 41590792Sgshapiro 41698121Sgshapirostatic void 41798121Sgshapirousage(prog) 41898121Sgshapiro char *prog; 41990792Sgshapiro{ 42098121Sgshapiro fprintf(stderr, 421120256Sgshapiro "Usage: %s -p socket-addr [-t timeout] [-r reject-addr] [-a add-addr]\n", 42298121Sgshapiro prog); 42390792Sgshapiro} 42490792Sgshapiro 42590792Sgshapiroint 42690792Sgshapiromain(argc, argv) 42798121Sgshapiro int argc; 42898121Sgshapiro char **argv; 42990792Sgshapiro{ 430120256Sgshapiro bool setconn = FALSE; 43198121Sgshapiro int c; 43298121Sgshapiro const char *args = "p:t:r:a:h"; 43398121Sgshapiro extern char *optarg; 43490792Sgshapiro 43598121Sgshapiro /* Process command line options */ 43698121Sgshapiro while ((c = getopt(argc, argv, args)) != -1) 43790792Sgshapiro { 43898121Sgshapiro switch (c) 43998121Sgshapiro { 44098121Sgshapiro case 'p': 44198121Sgshapiro if (optarg == NULL || *optarg == '\0') 44298121Sgshapiro { 44398121Sgshapiro (void) fprintf(stderr, "Illegal conn: %s\n", 44498121Sgshapiro optarg); 44598121Sgshapiro exit(EX_USAGE); 44698121Sgshapiro } 447168515Sgshapiro if (<A href="smfi_setconn.html">smfi_setconn</A>(optarg) == MI_FAILURE) 44898121Sgshapiro { 44998121Sgshapiro (void) fprintf(stderr, 45098121Sgshapiro "smfi_setconn failed\n"); 45198121Sgshapiro exit(EX_SOFTWARE); 45298121Sgshapiro } 45390792Sgshapiro 45498121Sgshapiro /* 45598121Sgshapiro ** If we're using a local socket, make sure it 45698121Sgshapiro ** doesn't already exist. Don't ever run this 45798121Sgshapiro ** code as root!! 45898121Sgshapiro */ 45990792Sgshapiro 46098121Sgshapiro if (strncasecmp(optarg, "unix:", 5) == 0) 46198121Sgshapiro unlink(optarg + 5); 46298121Sgshapiro else if (strncasecmp(optarg, "local:", 6) == 0) 46398121Sgshapiro unlink(optarg + 6); 464120256Sgshapiro setconn = TRUE; 46598121Sgshapiro break; 46690792Sgshapiro 46798121Sgshapiro case 't': 46898121Sgshapiro if (optarg == NULL || *optarg == '\0') 46998121Sgshapiro { 47098121Sgshapiro (void) fprintf(stderr, "Illegal timeout: %s\n", 47198121Sgshapiro optarg); 47298121Sgshapiro exit(EX_USAGE); 47398121Sgshapiro } 474168515Sgshapiro if (<A href="smfi_settimeout.html">smfi_settimeout</A>(atoi(optarg)) == MI_FAILURE) 47598121Sgshapiro { 47698121Sgshapiro (void) fprintf(stderr, 47798121Sgshapiro "smfi_settimeout failed\n"); 47898121Sgshapiro exit(EX_SOFTWARE); 47998121Sgshapiro } 48098121Sgshapiro break; 48198121Sgshapiro 48298121Sgshapiro case 'r': 48398121Sgshapiro if (optarg == NULL) 48498121Sgshapiro { 48598121Sgshapiro (void) fprintf(stderr, 48698121Sgshapiro "Illegal reject rcpt: %s\n", 48798121Sgshapiro optarg); 48898121Sgshapiro exit(EX_USAGE); 48998121Sgshapiro } 49098121Sgshapiro reject = optarg; 49198121Sgshapiro break; 49298121Sgshapiro 49398121Sgshapiro case 'a': 49498121Sgshapiro if (optarg == NULL) 49598121Sgshapiro { 49698121Sgshapiro (void) fprintf(stderr, 49798121Sgshapiro "Illegal add rcpt: %s\n", 49898121Sgshapiro optarg); 49998121Sgshapiro exit(EX_USAGE); 50098121Sgshapiro } 50198121Sgshapiro add = optarg; 50298121Sgshapiro smfilter.xxfi_flags |= SMFIF_ADDRCPT; 50398121Sgshapiro break; 50498121Sgshapiro 50598121Sgshapiro case 'h': 50698121Sgshapiro default: 50798121Sgshapiro usage(argv[0]); 50898121Sgshapiro exit(EX_USAGE); 50998121Sgshapiro } 51090792Sgshapiro } 511120256Sgshapiro if (!setconn) 512120256Sgshapiro { 513120256Sgshapiro fprintf(stderr, "%s: Missing required -p argument\n", argv[0]); 514120256Sgshapiro usage(argv[0]); 515120256Sgshapiro exit(EX_USAGE); 516120256Sgshapiro } 517168515Sgshapiro if (<A href="smfi_register.html">smfi_register</A>(smfilter) == MI_FAILURE) 51898121Sgshapiro { 51998121Sgshapiro fprintf(stderr, "smfi_register failed\n"); 52098121Sgshapiro exit(EX_UNAVAILABLE); 52198121Sgshapiro } 522168515Sgshapiro return <A href="smfi_main.html">smfi_main</A>(); 52390792Sgshapiro} 52490792Sgshapiro 52590792Sgshapiro/* eof */ 52690792Sgshapiro 527168515Sgshapiro</PRE> 528168515Sgshapiro<HR size="1"> 529168515Sgshapiro<FONT size="-1"> 530261363SgshapiroCopyright (c) 2000-2004, 2006 Proofpoint, Inc. and its suppliers. 53190792SgshapiroAll rights reserved. 532168515Sgshapiro<BR> 53390792SgshapiroBy using this file, you agree to the terms and conditions set 534112810Sgshapiroforth in the LICENSE. 535168515Sgshapiro</FONT> 536168515Sgshapiro</BODY> 537168515Sgshapiro</HTML> 538