1 #ifndef _MILTER_H_INCLUDED_ 2 #define _MILTER_H_INCLUDED_ 3 4 /*++ 5 /* NAME 6 /* milter 3h 7 /* SUMMARY 8 /* smtp server 9 /* SYNOPSIS 10 /* Postfix MTA-side Milter implementation 11 /* DESCRIPTION 12 /* .nf 13 14 /* 15 * Utility library. 16 */ 17 #include <vstring.h> 18 #include <vstream.h> 19 #include <argv.h> 20 21 /* 22 * Global library. 23 */ 24 #include <attr.h> 25 26 /* 27 * Each Milter handle is an element of a null-terminated linked list. The 28 * functions are virtual so that we can support multiple MTA-side Milter 29 * implementations. The Sendmail 8 and Sendmail X Milter-side APIs are too 30 * different to implement the MTA side as a single hybrid. 31 */ 32 typedef struct MILTER { 33 char *name; /* full name including transport */ 34 int flags; /* see below */ 35 struct MILTER *next; /* linkage */ 36 struct MILTERS *parent; /* parent information */ 37 struct MILTER_MACROS *macros; /* private macros */ 38 void (*connect_on_demand) (struct MILTER *); 39 const char *(*conn_event) (struct MILTER *, const char *, const char *, const char *, unsigned, ARGV *); 40 const char *(*helo_event) (struct MILTER *, const char *, int, ARGV *); 41 const char *(*mail_event) (struct MILTER *, const char **, ARGV *); 42 const char *(*rcpt_event) (struct MILTER *, const char **, ARGV *); 43 const char *(*data_event) (struct MILTER *, ARGV *); 44 const char *(*message) (struct MILTER *, VSTREAM *, off_t, ARGV *, ARGV *, ARGV *); 45 const char *(*unknown_event) (struct MILTER *, const char *, ARGV *); 46 const char *(*other_event) (struct MILTER *); 47 void (*abort) (struct MILTER *); 48 void (*disc_event) (struct MILTER *); 49 int (*active) (struct MILTER *); 50 int (*send) (struct MILTER *, VSTREAM *); 51 void (*free) (struct MILTER *); 52 } MILTER; 53 54 #define MILTER_FLAG_NONE (0) 55 #define MILTER_FLAG_WANT_RCPT_REJ (1<<0) /* see S8_RCPT_MAILER_ERROR */ 56 57 extern MILTER *milter8_create(const char *, int, int, int, const char *, const char *, struct MILTERS *); 58 extern MILTER *milter8_receive(VSTREAM *, struct MILTERS *); 59 60 /* 61 * As of Sendmail 8.14 each milter can override the default macro list. If a 62 * Milter has its own macro list, a null member means use the global 63 * definition. 64 */ 65 typedef struct MILTER_MACROS { 66 char *conn_macros; /* macros for connect event */ 67 char *helo_macros; /* macros for HELO/EHLO command */ 68 char *mail_macros; /* macros for MAIL FROM command */ 69 char *rcpt_macros; /* macros for RCPT TO command */ 70 char *data_macros; /* macros for DATA command */ 71 char *eoh_macros; /* macros for end-of-headers */ 72 char *eod_macros; /* macros for END-OF-DATA command */ 73 char *unk_macros; /* macros for unknown command */ 74 } MILTER_MACROS; 75 76 extern MILTER_MACROS *milter_macros_create(const char *, const char *, 77 const char *, const char *, 78 const char *, const char *, 79 const char *, const char *); 80 extern MILTER_MACROS *milter_macros_alloc(int); 81 extern void milter_macros_free(MILTER_MACROS *); 82 extern int milter_macros_print(ATTR_PRINT_COMMON_FN, VSTREAM *, int, const void *); 83 extern int milter_macros_scan(ATTR_SCAN_COMMON_FN, VSTREAM *, int, void *); 84 85 #define MILTER_MACROS_ALLOC_ZERO 1 /* null pointer */ 86 #define MILTER_MACROS_ALLOC_EMPTY 2 /* mystrdup(""); */ 87 88 /* 89 * Helper to parse list of name=value default macro settings. 90 */ 91 extern struct HTABLE *milter_macro_defaults_create(const char *); 92 93 /* 94 * A bunch of Milters. 95 */ 96 typedef const char *(*MILTER_MAC_LOOKUP_FN) (const char *, void *); 97 typedef const char *(*MILTER_ADD_HEADER_FN) (void *, const char *, const char *, const char *); 98 typedef const char *(*MILTER_EDIT_HEADER_FN) (void *, ssize_t, const char *, const char *, const char *); 99 typedef const char *(*MILTER_DEL_HEADER_FN) (void *, ssize_t, const char *); 100 typedef const char *(*MILTER_EDIT_FROM_FN) (void *, const char *, const char *); 101 typedef const char *(*MILTER_EDIT_RCPT_FN) (void *, const char *); 102 typedef const char *(*MILTER_EDIT_RCPT_PAR_FN) (void *, const char *, const char *); 103 typedef const char *(*MILTER_EDIT_BODY_FN) (void *, int, int, VSTRING *); 104 105 typedef struct MILTERS { 106 MILTER *milter_list; /* linked list of Milters */ 107 MILTER_MAC_LOOKUP_FN mac_lookup; 108 void *mac_context; /* macro lookup context */ 109 struct MILTER_MACROS *macros; 110 struct HTABLE *macro_defaults; 111 void *chg_context; /* context for queue file changes */ 112 MILTER_ADD_HEADER_FN add_header; 113 MILTER_EDIT_HEADER_FN upd_header; 114 MILTER_DEL_HEADER_FN del_header; 115 MILTER_EDIT_HEADER_FN ins_header; 116 MILTER_EDIT_FROM_FN chg_from; 117 MILTER_EDIT_RCPT_FN add_rcpt; 118 MILTER_EDIT_RCPT_PAR_FN add_rcpt_par; 119 MILTER_EDIT_RCPT_FN del_rcpt; 120 MILTER_EDIT_BODY_FN repl_body; 121 } MILTERS; 122 123 #define milter_create(milter_names, conn_timeout, cmd_timeout, msg_timeout, \ 124 protocol, def_action, conn_macros, helo_macros, \ 125 mail_macros, rcpt_macros, data_macros, eoh_macros, \ 126 eod_macros, unk_macros, macro_deflts) \ 127 milter_new(milter_names, conn_timeout, cmd_timeout, msg_timeout, \ 128 protocol, def_action, milter_macros_create(conn_macros, \ 129 helo_macros, mail_macros, rcpt_macros, data_macros, \ 130 eoh_macros, eod_macros, unk_macros), \ 131 milter_macro_defaults_create(macro_deflts)) 132 133 extern MILTERS *milter_new(const char *, int, int, int, const char *, 134 const char *, MILTER_MACROS *, 135 struct HTABLE *); 136 extern void milter_macro_callback(MILTERS *, MILTER_MAC_LOOKUP_FN, void *); 137 extern void milter_edit_callback(MILTERS *milters, MILTER_ADD_HEADER_FN, 138 MILTER_EDIT_HEADER_FN, MILTER_EDIT_HEADER_FN, 139 MILTER_DEL_HEADER_FN, MILTER_EDIT_FROM_FN, 140 MILTER_EDIT_RCPT_FN, MILTER_EDIT_RCPT_PAR_FN, 141 MILTER_EDIT_RCPT_FN, MILTER_EDIT_BODY_FN, 142 void *); 143 extern const char *milter_conn_event(MILTERS *, const char *, const char *, const char *, unsigned); 144 extern const char *milter_helo_event(MILTERS *, const char *, int); 145 extern const char *milter_mail_event(MILTERS *, const char **); 146 extern const char *milter_rcpt_event(MILTERS *, int, const char **); 147 extern const char *milter_data_event(MILTERS *); 148 extern const char *milter_message(MILTERS *, VSTREAM *, off_t, ARGV *); 149 extern const char *milter_unknown_event(MILTERS *, const char *); 150 extern const char *milter_other_event(MILTERS *); 151 extern void milter_abort(MILTERS *); 152 extern void milter_disc_event(MILTERS *); 153 extern int milter_dummy(MILTERS *, VSTREAM *); 154 extern int milter_send(MILTERS *, VSTREAM *); 155 extern MILTERS *milter_receive(VSTREAM *, int); 156 extern void milter_free(MILTERS *); 157 158 /* 159 * Milter body edit commands. 160 */ 161 #define MILTER_BODY_START 1 /* start message body */ 162 #define MILTER_BODY_LINE 2 /* message body line */ 163 #define MILTER_BODY_END 3 /* end message body */ 164 165 /* 166 * Sendmail 8 macro names. We support forms with and without the {}. 167 */ 168 #define S8_MAC__ "{_}" /* sender host, see client_resolve */ 169 #define S8_MAC_J "{j}" /* myhostname */ 170 #define S8_MAC_V "{v}" /* mail_name + mail_version */ 171 172 #define S8_MAC_DAEMON_NAME "{daemon_name}" 173 #define S8_MAC_IF_NAME "{if_name}" 174 #define S8_MAC_IF_ADDR "{if_addr}" 175 176 #define S8_MAC_CLIENT_ADDR "{client_addr}" 177 #define S8_MAC_CLIENT_CONN "{client_connections}" 178 #define S8_MAC_CLIENT_NAME "{client_name}" 179 #define S8_MAC_CLIENT_PORT "{client_port}" 180 #define S8_MAC_CLIENT_PTR "{client_ptr}" 181 #define S8_MAC_CLIENT_RES "{client_resolve}" 182 183 #define S8_MAC_DAEMON_ADDR "{daemon_addr}" 184 #define S8_MAC_DAEMON_PORT "{daemon_port}" 185 186 #define S8_MAC_TLS_VERSION "{tls_version}" 187 #define S8_MAC_CIPHER "{cipher}" 188 #define S8_MAC_CIPHER_BITS "{cipher_bits}" 189 #define S8_MAC_CERT_SUBJECT "{cert_subject}" 190 #define S8_MAC_CERT_ISSUER "{cert_issuer}" 191 192 #define S8_MAC_I "{i}" /* queue ID */ 193 #define S8_MAC_AUTH_TYPE "{auth_type}" /* SASL method */ 194 #define S8_MAC_AUTH_AUTHEN "{auth_authen}" /* SASL username */ 195 #define S8_MAC_AUTH_AUTHOR "{auth_author}" /* SASL sender */ 196 197 #define S8_MAC_MAIL_MAILER "{mail_mailer}" /* sender transport */ 198 #define S8_MAC_MAIL_HOST "{mail_host}" /* sender nexthop */ 199 #define S8_MAC_MAIL_ADDR "{mail_addr}" /* sender address */ 200 201 #define S8_MAC_RCPT_MAILER "{rcpt_mailer}" /* recip transport */ 202 #define S8_MAC_RCPT_HOST "{rcpt_host}" /* recip nexthop */ 203 #define S8_MAC_RCPT_ADDR "{rcpt_addr}" /* recip address */ 204 205 #define S8_RCPT_MAILER_ERROR "error" /* see MILTER_FLAG_WANT_RCPT_REJ */ 206 207 /* LICENSE 208 /* .ad 209 /* .fi 210 /* The Secure Mailer license must be distributed with this software. 211 /* AUTHOR(S) 212 /* Wietse Venema 213 /* IBM T.J. Watson Research 214 /* P.O. Box 704 215 /* Yorktown Heights, NY 10598, USA 216 /* 217 /* Wietse Venema 218 /* Google, Inc. 219 /* 111 8th Avenue 220 /* New York, NY 10011, USA 221 /*--*/ 222 223 #endif 224