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