1 /* $NetBSD: cleanup.h,v 1.1.1.1 2009/06/23 10:08:43 tron Exp $ */
9 /* canonicalize and enqueue message
11 /* #include "cleanup.h"
33 #include <been_here.h>
34 #include <mail_stream.h>
35 #include <mail_conf.h>
36 #include <mime_state.h>
37 #include <string_list.h>
38 #include <cleanup_user.h>
46 * These state variables are accessed by many functions, and there is only
47 * one instance of each per message.
49 typedef struct CLEANUP_STATE
{
50 VSTRING
*attr_buf
; /* storage for named attribute */
51 VSTRING
*temp1
; /* scratch buffer, local use only */
52 VSTRING
*temp2
; /* scratch buffer, local use only */
53 VSTRING
*stripped_buf
; /* character stripped input */
54 VSTREAM
*src
; /* current input stream */
55 VSTREAM
*dst
; /* current output stream */
56 MAIL_STREAM
*handle
; /* mail stream handle */
57 char *queue_name
; /* queue name */
58 char *queue_id
; /* queue file basename */
59 struct timeval arrival_time
; /* arrival time */
60 char *fullname
; /* envelope sender full name */
61 char *sender
; /* envelope sender address */
62 char *recip
; /* envelope recipient address */
63 char *orig_rcpt
; /* original recipient address */
64 char *return_receipt
; /* return-receipt address */
65 char *errors_to
; /* errors-to address */
66 int flags
; /* processing options, status flags */
67 int qmgr_opts
; /* qmgr processing options */
68 int errs
; /* any badness experienced */
69 int err_mask
; /* allowed badness */
70 int headers_seen
; /* which headers were seen */
71 int hop_count
; /* count of received: headers */
72 char *resent
; /* any resent- header seen */
73 BH_TABLE
*dups
; /* recipient dup filter */
74 void (*action
) (struct CLEANUP_STATE
*, int, const char *, ssize_t
);
75 off_t data_offset
; /* start of message content */
76 off_t body_offset
; /* start of body content */
77 off_t xtra_offset
; /* start of extra segment */
78 off_t cont_length
; /* length including Milter edits */
79 off_t sender_pt_offset
; /* replace sender here */
80 off_t sender_pt_target
; /* record after sender address */
81 off_t append_rcpt_pt_offset
; /* append recipient here */
82 off_t append_rcpt_pt_target
; /* target of above record */
83 off_t append_hdr_pt_offset
; /* append header here */
84 off_t append_hdr_pt_target
; /* target of above record */
85 ssize_t rcpt_count
; /* recipient count */
86 char *reason
; /* failure reason */
87 char *smtp_reply
; /* failure reason, SMTP-style */
88 NVTABLE
*attr
; /* queue file attribute list */
89 MIME_STATE
*mime_state
; /* MIME state engine */
90 int mime_errs
; /* MIME error flags */
91 char *hdr_rewrite_context
; /* header rewrite context */
92 char *filter
; /* from header/body patterns */
93 char *redirect
; /* from header/body patterns */
94 char *dsn_envid
; /* DSN envelope ID */
95 int dsn_ret
; /* DSN full/hdrs */
96 int dsn_notify
; /* DSN never/delay/fail/success */
97 char *dsn_orcpt
; /* DSN original recipient */
98 char *verp_delims
; /* VERP delimiters (optional) */
100 int defer_delay
; /* deferred delivery */
104 * Miscellaneous Milter support.
106 MILTERS
*milters
; /* mail filters */
107 const char *client_name
; /* real or ersatz client */
108 const char *reverse_name
; /* real or ersatz client */
109 const char *client_addr
; /* real or ersatz client */
110 int client_af
; /* real or ersatz client */
111 const char *client_port
; /* real or ersatz client */
112 VSTRING
*milter_ext_from
; /* externalized sender */
113 VSTRING
*milter_ext_rcpt
; /* externalized recipient */
114 VSTRING
*milter_err_text
; /* milter call-back reply */
117 * Support for Milter body replacement requests.
119 struct CLEANUP_REGION
*free_regions
;/* unused regions */
120 struct CLEANUP_REGION
*body_regions
;/* regions with body content */
121 struct CLEANUP_REGION
*curr_body_region
;
125 * Status flags. Flags 0-15 are reserved for cleanup_user.h.
127 #define CLEANUP_FLAG_INRCPT (1<<16) /* Processing recipient records */
128 #define CLEANUP_FLAG_WARN_SEEN (1<<17) /* REC_TYPE_WARN record seen */
129 #define CLEANUP_FLAG_END_SEEN (1<<18) /* REC_TYPE_END record seen */
134 extern MAPS
*cleanup_comm_canon_maps
;
135 extern MAPS
*cleanup_send_canon_maps
;
136 extern MAPS
*cleanup_rcpt_canon_maps
;
137 extern int cleanup_comm_canon_flags
;
138 extern int cleanup_send_canon_flags
;
139 extern int cleanup_rcpt_canon_flags
;
140 extern MAPS
*cleanup_header_checks
;
141 extern MAPS
*cleanup_mimehdr_checks
;
142 extern MAPS
*cleanup_nesthdr_checks
;
143 extern MAPS
*cleanup_body_checks
;
144 extern MAPS
*cleanup_virt_alias_maps
;
145 extern ARGV
*cleanup_masq_domains
;
146 extern STRING_LIST
*cleanup_masq_exceptions
;
147 extern int cleanup_masq_flags
;
148 extern MAPS
*cleanup_send_bcc_maps
;
149 extern MAPS
*cleanup_rcpt_bcc_maps
;
154 extern VSTRING
*cleanup_reject_chars
;
155 extern VSTRING
*cleanup_strip_chars
;
160 extern MILTERS
*cleanup_milters
;
163 * Address canonicalization fine control.
165 #define CLEANUP_CANON_FLAG_ENV_FROM (1<<0) /* envelope sender */
166 #define CLEANUP_CANON_FLAG_ENV_RCPT (1<<1) /* envelope recipient */
167 #define CLEANUP_CANON_FLAG_HDR_FROM (1<<2) /* header sender */
168 #define CLEANUP_CANON_FLAG_HDR_RCPT (1<<3) /* header recipient */
171 * Address masquerading fine control.
173 #define CLEANUP_MASQ_FLAG_ENV_FROM (1<<0) /* envelope sender */
174 #define CLEANUP_MASQ_FLAG_ENV_RCPT (1<<1) /* envelope recipient */
175 #define CLEANUP_MASQ_FLAG_HDR_FROM (1<<2) /* header sender */
176 #define CLEANUP_MASQ_FLAG_HDR_RCPT (1<<3) /* header recipient */
179 * Restrictions on extension propagation.
181 extern int cleanup_ext_prop_mask
;
184 * Saved queue file names, so the files can be removed in case of a fatal
187 extern char *cleanup_path
;
188 extern VSTRING
*cleanup_trace_path
;
189 extern VSTRING
*cleanup_bounce_path
;
194 extern CLEANUP_STATE
*cleanup_state_alloc(VSTREAM
*);
195 extern void cleanup_state_free(CLEANUP_STATE
*);
200 extern CLEANUP_STATE
*cleanup_open(VSTREAM
*);
201 extern void cleanup_control(CLEANUP_STATE
*, int);
202 extern int cleanup_flush(CLEANUP_STATE
*);
203 extern void cleanup_free(CLEANUP_STATE
*);
204 extern void cleanup_all(void);
205 extern void cleanup_sig(int);
206 extern void cleanup_pre_jail(char *, char **);
207 extern void cleanup_post_jail(char *, char **);
208 extern CONFIG_BOOL_TABLE cleanup_bool_table
[];
209 extern CONFIG_INT_TABLE cleanup_int_table
[];
210 extern CONFIG_BOOL_TABLE cleanup_bool_table
[];
211 extern CONFIG_STR_TABLE cleanup_str_table
[];
212 extern CONFIG_TIME_TABLE cleanup_time_table
[];
214 #define CLEANUP_RECORD(s, t, b, l) ((s)->action((s), (t), (b), (l)))
219 extern void cleanup_out(CLEANUP_STATE
*, int, const char *, ssize_t
);
220 extern void cleanup_out_string(CLEANUP_STATE
*, int, const char *);
221 extern void PRINTFLIKE(3, 4) cleanup_out_format(CLEANUP_STATE
*, int, const char *,...);
222 extern void cleanup_out_header(CLEANUP_STATE
*, VSTRING
*);
224 #define CLEANUP_OUT_BUF(s, t, b) \
225 cleanup_out((s), (t), vstring_str((b)), VSTRING_LEN((b)))
227 #define CLEANUP_OUT_OK(s) \
228 (!((s)->errs & (s)->err_mask) && !((s)->flags & CLEANUP_FLAG_DISCARD))
233 extern void cleanup_envelope(CLEANUP_STATE
*, int, const char *, ssize_t
);
238 extern void cleanup_message(CLEANUP_STATE
*, int, const char *, ssize_t
);
241 * cleanup_extracted.c
243 extern void cleanup_extracted(CLEANUP_STATE
*, int, const char *, ssize_t
);
248 extern void cleanup_final(CLEANUP_STATE
*);
253 extern int cleanup_rewrite_external(const char *, VSTRING
*, const char *);
254 extern int cleanup_rewrite_internal(const char *, VSTRING
*, const char *);
255 extern int cleanup_rewrite_tree(const char *, TOK822
*);
260 extern int cleanup_map11_external(CLEANUP_STATE
*, VSTRING
*, MAPS
*, int);
261 extern int cleanup_map11_internal(CLEANUP_STATE
*, VSTRING
*, MAPS
*, int);
262 extern int cleanup_map11_tree(CLEANUP_STATE
*, TOK822
*, MAPS
*, int);
267 ARGV
*cleanup_map1n_internal(CLEANUP_STATE
*, const char *, MAPS
*, int);
270 * cleanup_masquerade.c
272 extern int cleanup_masquerade_external(VSTRING
*, ARGV
*);
273 extern int cleanup_masquerade_internal(VSTRING
*, ARGV
*);
274 extern int cleanup_masquerade_tree(TOK822
*, ARGV
*);
277 * cleanup_recipient.c
279 extern void cleanup_out_recipient(CLEANUP_STATE
*, const char *, int, const char *, const char *);
284 extern void cleanup_addr_sender(CLEANUP_STATE
*, const char *);
285 extern void cleanup_addr_recipient(CLEANUP_STATE
*, const char *);
286 extern void cleanup_addr_bcc(CLEANUP_STATE
*, const char *);
291 extern int cleanup_bounce(CLEANUP_STATE
*);
294 * MSG_STATS compatibility.
296 #define CLEANUP_MSG_STATS(stats, state) \
297 MSG_STATS_INIT1(stats, incoming_arrival, state->arrival_time)
302 extern void cleanup_milter_receive(CLEANUP_STATE
*, int);
303 extern void cleanup_milter_inspect(CLEANUP_STATE
*, MILTERS
*);
304 extern void cleanup_milter_emul_mail(CLEANUP_STATE
*, MILTERS
*, const char *);
305 extern void cleanup_milter_emul_rcpt(CLEANUP_STATE
*, MILTERS
*, const char *);
306 extern void cleanup_milter_emul_data(CLEANUP_STATE
*, MILTERS
*);
308 #define CLEANUP_MILTER_OK(s) \
309 (((s)->flags & CLEANUP_FLAG_MILTER) != 0 \
310 && (s)->errs == 0 && ((s)->flags & CLEANUP_FLAG_DISCARD) == 0)
313 * cleanup_body_edit.c
315 typedef struct CLEANUP_REGION
{
316 off_t start
; /* start of region */
317 off_t len
; /* length or zero (open-ended) */
318 off_t write_offs
; /* write offset */
319 struct CLEANUP_REGION
*next
; /* linkage */
322 extern void cleanup_region_init(CLEANUP_STATE
*);
323 extern CLEANUP_REGION
*cleanup_region_open(CLEANUP_STATE
*, ssize_t
);
324 extern void cleanup_region_close(CLEANUP_STATE
*, CLEANUP_REGION
*);
325 extern CLEANUP_REGION
*cleanup_region_return(CLEANUP_STATE
*, CLEANUP_REGION
*);
326 extern void cleanup_region_done(CLEANUP_STATE
*);
328 extern int cleanup_body_edit_start(CLEANUP_STATE
*);
329 extern int cleanup_body_edit_write(CLEANUP_STATE
*, int, VSTRING
*);
330 extern int cleanup_body_edit_finish(CLEANUP_STATE
*);
331 extern void cleanup_body_edit_free(CLEANUP_STATE
*);
336 /* The Secure Mailer license must be distributed with this software.
339 /* IBM T.J. Watson Research
341 /* Yorktown Heights, NY 10598, USA