/*++ /* NAME /* milter 3 /* SUMMARY /* generic MTA-side mail filter interface /* SYNOPSIS /* #include <milter.h> /* /* MILTERS *milter_create(milter_names, conn_timeout, cmd_timeout, /* msg_timeout, protocol, def_action, /* conn_macros, helo_macros, /* mail_macros, rcpt_macros, /* data_macros, eoh_macros, /* eod_macros, unk_macros, /* macro_deflts) /* const char *milter_names; /* int conn_timeout; /* int cmd_timeout; /* int msg_timeout; /* const char *protocol; /* const char *def_action; /* const char *conn_macros; /* const char *helo_macros; /* const char *mail_macros; /* const char *rcpt_macrps; /* const char *data_macros; /* const char *eoh_macros; /* const char *eod_macros; /* const char *unk_macros; /* const char *macro_deflts; /* /* void milter_free(milters) /* MILTERS *milters; /* /* void milter_macro_callback(milters, mac_lookup, mac_context) /* const char *(*mac_lookup)(const char *name, void *context); /* void *mac_context; /* /* void milter_edit_callback(milters, add_header, upd_header, /* ins_header, del_header, chg_from, /* add_rcpt, add_rcpt_par, del_rcpt, /* repl_body, context) /* MILTERS *milters; /* MILTER_ADD_HEADER_FN add_header; /* MILTER_EDIT_HEADER_FN upd_header; /* MILTER_EDIT_HEADER_FN ins_header; /* MILTER_DEL_HEADER_FN del_header; /* MILTER_EDIT_FROM_FN chg_from; /* MILTER_EDIT_RCPT_FN add_rcpt; /* MILTER_EDIT_RCPT_PAR_FN add_rcpt_par; /* MILTER_EDIT_RCPT_FN del_rcpt; /* MILTER_EDIT_BODY_FN repl_body; /* void *context; /* /* const char *milter_conn_event(milters, client_name, client_addr, /* client_port, addr_family) /* MILTERS *milters; /* const char *client_name; /* const char *client_addr; /* const char *client_port; /* int addr_family; /* /* const char *milter_disc_event(milters) /* MILTERS *milters; /* /* const char *milter_helo_event(milters, helo_name, esmtp_flag) /* MILTERS *milters; /* const char *helo_name; /* int esmtp_flag; /* /* const char *milter_mail_event(milters, argv) /* MILTERS *milters; /* const char **argv; /* /* const char *milter_rcpt_event(milters, flags, argv) /* MILTERS *milters; /* int flags; /* const char **argv; /* /* const char *milter_data_event(milters) /* MILTERS *milters; /* /* const char *milter_unknown_event(milters, command) /* MILTERS *milters; /* const char *command; /* /* const char *milter_other_event(milters) /* MILTERS *milters; /* /* const char *milter_message(milters, qfile, data_offset, auto_hdrs) /* MILTERS *milters; /* VSTREAM *qfile; /* off_t data_offset; /* ARGV *auto_hdrs; /* /* const char *milter_abort(milters) /* MILTERS *milters; /* /* int milter_send(milters, fp) /* MILTERS *milters; /* VSTREAM *fp; /* /* MILTERS *milter_receive(fp, count) /* VSTREAM *fp; /* int count; /* /* int milter_dummy(milters, fp) /* MILTERS *milters; /* VSTREAM *fp; /* DESCRIPTION /* The functions in this module manage one or more milter (mail /* filter) clients. Currently, only the Sendmail 8 filter /* protocol is supported. /* /* The functions that inspect content or envelope commands /* return either an SMTP reply ([45]XX followed by enhanced /* status code and text), "D" (discard), "H" (quarantine), /* "S" (shutdown connection), or a null pointer, which means /* "no news is good news". /* /* milter_create() instantiates the milter clients specified /* with the milter_names argument. The conn_macros etc. /* arguments specify the names of macros that are sent to the /* mail filter applications upon a connect etc. event, and the /* macro_deflts argument specifies macro defaults that will be used /* only if the application's lookup call-back returns null. This /* function should be called during process initialization, /* before entering a chroot jail. The timeout parameters specify /* time limits for the completion of the specified request /* classes. The protocol parameter specifies a protocol version /* and optional extensions. When the milter application is /* unavailable, the milter client will go into a suitable error /* state as specified with the def_action parameter (i.e. /* reject, tempfail or accept all subsequent events). /* /* milter_free() disconnects from the milter instances that /* are still opened, and destroys the data structures created /* by milter_create(). This function is safe to call at any /* point after milter_create(). /* /* milter_macro_callback() specifies a call-back function and /* context for macro lookup. This function must be called /* before milter_conn_event(). /* /* milter_edit_callback() specifies call-back functions and /* context for editing the queue file after the end-of-data /* is received. This function must be called before milter_message(); /* /* milter_conn_event() reports an SMTP client connection event /* to the specified milter instances, after sending the macros /* specified with the milter_create() conn_macros argument. /* This function must be called before reporting any other /* events. /* /* milter_disc_event() reports an SMTP client disconnection /* event to the specified milter instances. No events can /* reported after this call. To simplify usage, redundant calls /* of this function are NO-OPs and don't raise a run-time /* error. /* /* milter_helo_event() reports a HELO or EHLO event to the /* specified milter instances, after sending the macros that /* were specified with the milter_create() helo_macros argument. /* /* milter_mail_event() reports a MAIL FROM event to the specified /* milter instances, after sending the macros that were specified /* with the milter_create() mail_macros argument. /* /* milter_rcpt_event() reports an RCPT TO event to the specified /* milter instances, after sending the macros that were specified /* with the milter_create() rcpt_macros argument. The flags /* argument supports the following: /* .IP MILTER_FLAG_WANT_RCPT_REJ /* When this flag is cleared, invoke all milters. When this /* flag is set, invoke only milters that want to receive /* rejected recipients; with Sendmail V8 Milters, {rcpt_mailer} /* is set to "error", {rcpt_host} is set to an enhanced status /* code, and {rcpt_addr} is set to descriptive text. /* .PP /* milter_data_event() reports a DATA event to the specified /* milter instances, after sending the macros that were specified /* with the milter_create() data_macros argument. /* /* milter_unknown_event() reports an unknown command event to /* the specified milter instances, after sending the macros /* that were specified with the milter_create() unk_macros /* argument. /* /* milter_other_event() returns the current default mail filter /* reply for the current SMTP connection state; it does not /* change milter states. A null pointer result means that all /* is well. This function can be used for SMTP commands such /* as AUTH, STARTTLS that don't have their own milter event /* routine. /* /* milter_message() sends the message header and body to the /* to the specified milter instances, and sends the macros /* specified with the milter_create() eoh_macros after the /* message header, and with the eod_macros argument at /* the end. Each milter sees the result of any changes made /* by a preceding milter. This function must be called with /* as argument an open Postfix queue file. /* /* milter_abort() cancels a mail transaction in progress. To /* simplify usage, redundant calls of this function are NO-OPs /* and don't raise a run-time error. /* /* milter_send() sends a list of mail filters over the specified /* stream. When given a null list pointer, a "no filter" /* indication is sent. The result is non-zero in case of /* error. /* /* milter_receive() receives the specified number of mail /* filters over the specified stream. The result is a null /* pointer when no milters were sent, or when an error happened. /* /* milter_dummy() is like milter_send(), except that it sends /* a dummy, but entirely valid, mail filter list. /* SEE ALSO /* milter8(3) Sendmail 8 Milter protocol /* DIAGNOSTICS /* Panic: interface violation. /* Fatal errors: memory allocation problem. /* LICENSE /* .ad /* .fi /* The Secure Mailer license must be distributed with this software. /* AUTHOR(S) /* Wietse Venema /* IBM T.J. Watson Research /* P.O. Box 704 /* Yorktown Heights, NY 10598, USA /* /* Wietse Venema /* Google, Inc. /* 111 8th Avenue /* New York, NY 10011, USA
/*--*/
if (msg_verbose)
msg_info("report helo to all milters"); for (resp = 0, m = milters->milter_list; resp == 0 && m != 0; m = m->next) {
any_macros = MILTER_MACRO_EVAL(global_macros, m, milters, helo_macros);
resp = m->helo_event(m, helo_name, esmtp_flag, any_macros); if (any_macros != global_macros)
argv_free(any_macros);
} if (global_macros)
argv_free(global_macros); return (resp);
}
if (msg_verbose)
msg_info("report sender to all milters"); for (resp = 0, m = milters->milter_list; resp == 0 && m != 0; m = m->next) {
any_macros = MILTER_MACRO_EVAL(global_macros, m, milters, mail_macros);
resp = m->mail_event(m, argv, any_macros); if (any_macros != global_macros)
argv_free(any_macros);
} if (global_macros)
argv_free(global_macros); return (resp);
}
if (msg_verbose)
msg_info("report data to all milters"); for (resp = 0, m = milters->milter_list; resp == 0 && m != 0; m = m->next) {
any_macros = MILTER_MACRO_EVAL(global_macros, m, milters, data_macros);
resp = m->data_event(m, any_macros); if (any_macros != global_macros)
argv_free(any_macros);
} if (global_macros)
argv_free(global_macros); return (resp);
}
if (msg_verbose)
msg_info("report unknown command to all milters"); for (resp = 0, m = milters->milter_list; resp == 0 && m != 0; m = m->next) {
any_macros = MILTER_MACRO_EVAL(global_macros, m, milters, unk_macros);
resp = m->unknown_event(m, command, any_macros); if (any_macros != global_macros)
argv_free(any_macros);
} if (global_macros)
argv_free(global_macros); return (resp);
}
if (msg_verbose)
msg_info("query milter states for other event"); for (resp = 0, m = milters->milter_list; resp == 0 && m != 0; m = m->next)
resp = m->other_event(m); return (resp);
}
if (msg_verbose)
msg_info("inspect content by all milters"); for (resp = 0, m = milters->milter_list; resp == 0 && m != 0; m = m->next) {
any_eoh_macros = MILTER_MACRO_EVAL(global_eoh_macros, m, milters, eoh_macros);
any_eod_macros = MILTER_MACRO_EVAL(global_eod_macros, m, milters, eod_macros);
resp = m->message(m, fp, data_offset, any_eoh_macros, any_eod_macros,
auto_hdrs); if (any_eoh_macros != global_eoh_macros)
argv_free(any_eoh_macros); if (any_eod_macros != global_eod_macros)
argv_free(any_eod_macros);
} if (global_eoh_macros)
argv_free(global_eoh_macros); if (global_eod_macros)
argv_free(global_eod_macros); return (resp);
}
/* milter_abort - cancel message receiving state, all milters */
void milter_abort(MILTERS *milters)
{
MILTER *m;
if (msg_verbose)
msg_info("abort all milters"); for (m = milters->milter_list; m != 0; m = m->next)
m->abort(m);
}
/* milter_disc_event - report client disconnect event to all milters */
if (msg_verbose)
msg_info("free all milters"); for (m = milters->milter_list; m != 0; m = next)
next = m->next, m->free(m); if (milters->macros)
milter_macros_free(milters->macros); if (milters->macro_defaults)
htable_free(milters->macro_defaults, myfree);
myfree((void *) milters);
}
/* milter_dummy - send empty milter list */
int milter_dummy(MILTERS *milters, VSTREAM *stream)
{
MILTERS dummy = *milters;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.