xref: /freebsd/contrib/sendmail/include/libmilter/mfapi.h (revision 6b7c9af44b73355e01755ac7a0fb8ffc608b25ab)
1 /*
2  * Copyright (c) 1999-2002 Sendmail, Inc. and its suppliers.
3  *	All rights reserved.
4  *
5  * By using this file, you agree to the terms and conditions set
6  * forth in the LICENSE file which can be found at the top level of
7  * the sendmail distribution.
8  *
9  *
10  *	$Id: mfapi.h,v 8.41 2002/03/22 21:36:12 gshapiro Exp $
11  */
12 
13 /*
14 **  MFAPI.H -- Global definitions for mail filter library and mail filters.
15 */
16 
17 #ifndef _LIBMILTER_MFAPI_H
18 # define _LIBMILTER_MFAPI_H	1
19 
20 # include <sys/types.h>
21 # include <sys/socket.h>
22 # include "libmilter/mfdef.h"
23 
24 # define LIBMILTER_API		extern
25 
26 
27 #ifndef _SOCK_ADDR
28 # define _SOCK_ADDR	struct sockaddr
29 #endif /* ! _SOCK_ADDR */
30 
31 /*
32 **  libmilter functions return one of the following to indicate
33 **  success/failure:
34 */
35 
36 #define MI_SUCCESS	0
37 #define MI_FAILURE	(-1)
38 
39 /* "forward" declarations */
40 typedef struct smfi_str SMFICTX;
41 typedef struct smfi_str *SMFICTX_PTR;
42 
43 typedef struct smfiDesc smfiDesc_str;
44 typedef struct smfiDesc	*smfiDesc_ptr;
45 
46 /*
47 **  Type which callbacks should return to indicate message status.
48 **  This may take on one of the SMFIS_* values listed below.
49 */
50 
51 typedef int	sfsistat;
52 
53 #if defined(__linux__) && defined(__GNUC__) && defined(__cplusplus) && __GNUC_MINOR__ >= 8
54 # define SM__P(X)	__PMT(X)
55 #else /* __linux__ && __GNUC__ && __cplusplus && _GNUC_MINOR__ >= 8 */
56 # define SM__P(X)	__P(X)
57 #endif /* __linux__ && __GNUC__ && __cplusplus && _GNUC_MINOR__ >= 8 */
58 
59 /* Some platforms don't define __P -- do it for them here: */
60 #ifndef __P
61 # ifdef __STDC__
62 #  define __P(X) X
63 # else /* __STDC__ */
64 #  define __P(X) ()
65 # endif /* __STDC__ */
66 #endif /* __P */
67 
68 /*
69 **  structure describing one milter
70 */
71 
72 struct smfiDesc
73 {
74 	char		*xxfi_name;	/* filter name */
75 	int		xxfi_version;	/* version code -- do not change */
76 	unsigned long	xxfi_flags;	/* flags */
77 
78 	/* connection info filter */
79 	sfsistat	(*xxfi_connect) SM__P((SMFICTX *, char *, _SOCK_ADDR *));
80 
81 	/* SMTP HELO command filter */
82 	sfsistat	(*xxfi_helo) SM__P((SMFICTX *, char *));
83 
84 	/* envelope sender filter */
85 	sfsistat	(*xxfi_envfrom) SM__P((SMFICTX *, char **));
86 
87 	/* envelope recipient filter */
88 	sfsistat	(*xxfi_envrcpt) SM__P((SMFICTX *, char **));
89 
90 	/* header filter */
91 	sfsistat	(*xxfi_header) SM__P((SMFICTX *, char *, char *));
92 
93 	/* end of header */
94 	sfsistat	(*xxfi_eoh) SM__P((SMFICTX *));
95 
96 	/* body block */
97 	sfsistat	(*xxfi_body) SM__P((SMFICTX *, unsigned char *, size_t));
98 
99 	/* end of message */
100 	sfsistat	(*xxfi_eom) SM__P((SMFICTX *));
101 
102 	/* message aborted */
103 	sfsistat	(*xxfi_abort) SM__P((SMFICTX *));
104 
105 	/* connection cleanup */
106 	sfsistat	(*xxfi_close) SM__P((SMFICTX *));
107 };
108 
109 LIBMILTER_API int smfi_register __P((struct smfiDesc));
110 LIBMILTER_API int smfi_main __P((void));
111 LIBMILTER_API int smfi_setbacklog __P((int));
112 LIBMILTER_API int smfi_setdbg __P((int));
113 LIBMILTER_API int smfi_settimeout __P((int));
114 LIBMILTER_API int smfi_setconn __P((char *));
115 LIBMILTER_API int smfi_stop __P((void));
116 
117 #define SMFI_VERSION	2		/* version number */
118 
119 /*
120 **  What the filter might do -- values to be ORed together for
121 **  smfiDesc.xxfi_flags.
122 */
123 
124 #define SMFIF_NONE	0x00000000L	/* no flags */
125 #define SMFIF_ADDHDRS	0x00000001L	/* filter may add headers */
126 #define SMFIF_CHGBODY	0x00000002L	/* filter may replace body */
127 #define SMFIF_MODBODY	SMFIF_CHGBODY	/* backwards compatible */
128 #define SMFIF_ADDRCPT	0x00000004L	/* filter may add recipients */
129 #define SMFIF_DELRCPT	0x00000008L	/* filter may delete recipients */
130 #define SMFIF_CHGHDRS	0x00000010L	/* filter may change/delete headers */
131 #if _FFR_QUARANTINE
132 # define SMFIF_QUARANTINE 0x00000020L	/* filter may quarantine envelope */
133 #endif /* _FFR_QUARANTINE */
134 
135 /*
136 **  Continue processing message/connection.
137 */
138 
139 #define SMFIS_CONTINUE	0
140 
141 /*
142 **  Reject the message/connection.
143 **  No further routines will be called for this message
144 **  (or connection, if returned from a connection-oriented routine).
145 */
146 
147 #define SMFIS_REJECT	1
148 
149 /*
150 **  Accept the message,
151 **  but silently discard the message.
152 **  No further routines will be called for this message.
153 **  This is only meaningful from message-oriented routines.
154 */
155 
156 #define SMFIS_DISCARD	2
157 
158 /*
159 **  Accept the message/connection.
160 **  No further routines will be called for this message
161 **  (or connection, if returned from a connection-oriented routine;
162 **  in this case, it causes all messages on this connection
163 **  to be accepted without filtering).
164 */
165 
166 #define SMFIS_ACCEPT	3
167 
168 /*
169 **  Return a temporary failure, i.e.,
170 **  the corresponding SMTP command will return a 4xx status code.
171 **  In some cases this may prevent further routines from
172 **  being called on this message or connection,
173 **  although in other cases (e.g., when processing an envelope
174 **  recipient) processing of the message will continue.
175 */
176 
177 #define SMFIS_TEMPFAIL	4
178 
179 #if 0
180 /*
181 **  Filter Routine Details
182 */
183 
184 /* connection info filter */
185 extern sfsistat	xxfi_connect __P((SMFICTX *, char *, _SOCK_ADDR *));
186 
187 /*
188 **  xxfi_connect(ctx, hostname, hostaddr) Invoked on each connection
189 **
190 **	char *hostname; Host domain name, as determined by a reverse lookup
191 **		on the host address.
192 **	_SOCK_ADDR *hostaddr; Host address, as determined by a getpeername
193 **		call on the SMTP socket.
194 */
195 
196 /* SMTP HELO command filter */
197 extern sfsistat	xxfi_helo __P((SMFICTX *, char *));
198 
199 /*
200 **  xxfi_helo(ctx, helohost) Invoked on SMTP HELO/EHLO command
201 **
202 **	char *helohost; Value passed to HELO/EHLO command, which should be
203 **		the domain name of the sending host (but is, in practice,
204 **		anything the sending host wants to send).
205 */
206 
207 /* envelope sender filter */
208 extern sfsistat	xxfi_envfrom __P((SMFICTX *, char **));
209 
210 /*
211 **  xxfi_envfrom(ctx, argv) Invoked on envelope from
212 **
213 **	char **argv; Null-terminated SMTP command arguments;
214 **		argv[0] is guaranteed to be the sender address.
215 **		Later arguments are the ESMTP arguments.
216 */
217 
218 /* envelope recipient filter */
219 extern sfsistat	xxfi_envrcpt __P((SMFICTX *, char **));
220 
221 /*
222 **  xxfi_envrcpt(ctx, argv) Invoked on each envelope recipient
223 **
224 **	char **argv; Null-terminated SMTP command arguments;
225 **		argv[0] is guaranteed to be the recipient address.
226 **		Later arguments are the ESMTP arguments.
227 */
228 
229 /* header filter */
230 extern sfsistat	xxfi_header __P((SMFICTX *, char *, char *));
231 
232 /*
233 **  xxfi_header(ctx, headerf, headerv) Invoked on each message header. The
234 **  content of the header may have folded white space (that is, multiple
235 **  lines with following white space) included.
236 **
237 **	char *headerf; Header field name
238 **	char *headerv; Header field value
239 */
240 
241 /* end of header */
242 extern sfsistat	xxfi_eoh __P((SMFICTX *));
243 
244 /*
245 **  xxfi_eoh(ctx) Invoked at end of header
246 */
247 
248 /* body block */
249 extern sfsistat	xxfi_body __P((SMFICTX *, unsigned char *, size_t));
250 
251 /*
252 **  xxfi_body(ctx, bodyp, bodylen) Invoked for each body chunk. There may
253 **  be multiple body chunks passed to the filter. End-of-lines are
254 **  represented as received from SMTP (normally Carriage-Return/Line-Feed).
255 **
256 **	unsigned char *bodyp; Pointer to body data
257 **	size_t bodylen; Length of body data
258 */
259 
260 /* end of message */
261 extern sfsistat	xxfi_eom __P((SMFICTX *));
262 
263 /*
264 **  xxfi_eom(ctx) Invoked at end of message. This routine can perform
265 **  special operations such as modifying the message header, body, or
266 **  envelope.
267 */
268 
269 /* message aborted */
270 extern sfsistat	xxfi_abort __P((SMFICTX *));
271 
272 /*
273 **  xxfi_abort(ctx) Invoked if message is aborted outside of the control of
274 **  the filter, for example, if the SMTP sender issues an RSET command. If
275 **  xxfi_abort is called, xxfi_eom will not be called and vice versa.
276 */
277 
278 /* connection cleanup */
279 extern sfsistat	xxfi_close __P((SMFICTX *));
280 
281 /*
282 **  xxfi_close(ctx) Invoked at end of the connection. This is called on
283 **  close even if the previous mail transaction was aborted.
284 */
285 #endif /* 0 */
286 
287 /*
288 **  Additional information is passed in to the vendor filter routines using
289 **  symbols. Symbols correspond closely to sendmail macros. The symbols
290 **  defined depend on the context. The value of a symbol is accessed using:
291 */
292 
293 /* Return the value of a symbol. */
294 LIBMILTER_API char * smfi_getsymval __P((SMFICTX *, char *));
295 
296 /*
297 **  Return the value of a symbol.
298 **
299 **	SMFICTX *ctx; Opaque context structure
300 **	char *symname; The name of the symbol to access.
301 */
302 
303 /*
304 **  Vendor filter routines that want to pass additional information back to
305 **  the MTA for use in SMTP replies may call smfi_setreply before returning.
306 */
307 
308 LIBMILTER_API int smfi_setreply __P((SMFICTX *, char *, char *, char *));
309 
310 #if _FFR_MULTILINE
311 /*
312 **  Alternatively, smfi_setmlreply can be called if a multi-line SMTP reply
313 **  is needed.
314 */
315 
316 LIBMILTER_API int smfi_setmlreply __P((SMFICTX *, const char *, const char *, ...));
317 #endif /* _FFR_MULTILINE */
318 
319 /*
320 **  Set the specific reply code to be used in response to the active
321 **  command. If not specified, a generic reply code is used.
322 **
323 **	SMFICTX *ctx; Opaque context structure
324 **	char *rcode; The three-digit (RFC 821) SMTP reply code to be
325 **		returned, e.g., ``551''.
326 **	char *xcode; The extended (RFC 2034) reply code, e.g., ``5.7.6''.
327 **	char *message; The text part of the SMTP reply.
328 */
329 
330 /*
331 **  The xxfi_eom routine is called at the end of a message (essentially,
332 **  after the final DATA dot). This routine can call some special routines
333 **  to modify the envelope, header, or body of the message before the
334 **  message is enqueued. These routines must not be called from any vendor
335 **  routine other than xxfi_eom.
336 */
337 
338 LIBMILTER_API int smfi_addheader __P((SMFICTX *, char *, char *));
339 
340 /*
341 **  Add a header to the message. This header is not passed to other
342 **  filters. It is not checked for standards compliance; the mail filter
343 **  must ensure that no protocols are violated as a result of adding this
344 **  header.
345 **
346 **	SMFICTX *ctx; Opaque context structure
347 **	char *headerf; Header field name
348 **	char *headerv; Header field value
349 */
350 
351 LIBMILTER_API int smfi_chgheader __P((SMFICTX *, char *, int, char *));
352 
353 /*
354 **  Change/delete a header in the message.  It is not checked for standards
355 **  compliance; the mail filter must ensure that no protocols are violated
356 **  as a result of adding this header.
357 **
358 **	SMFICTX *ctx; Opaque context structure
359 **	char *headerf; Header field name
360 **	int index; The Nth occurence of header field name
361 **	char *headerv; New header field value (empty for delete header)
362 */
363 
364 LIBMILTER_API int smfi_addrcpt __P((SMFICTX *, char *));
365 
366 /*
367 **  Add a recipient to the envelope
368 **
369 **	SMFICTX *ctx; Opaque context structure
370 **	char *rcpt; Recipient to be added
371 */
372 
373 LIBMILTER_API int smfi_delrcpt __P((SMFICTX *, char *));
374 
375 #if _FFR_SMFI_PROGRESS
376 /*
377 **  Send a "no-op" up to the MTA to tell it we're still alive, so long
378 **  milter-side operations don't time out.
379 **
380 **	SMFICTX *ctx; Opaque context structure
381 */
382 
383 LIBMILTER_API int smfi_progress __P((SMFICTX *));
384 #endif /* _FFR_SMFI_PROGRESS */
385 
386 /*
387 **  Delete a recipient from the envelope
388 **
389 **	SMFICTX *ctx; Opaque context structure
390 **	char *rcpt; Envelope recipient to be deleted. This should be in
391 **		exactly the form passed to xxfi_envrcpt or the address may
392 **		not be deleted.
393 */
394 
395 LIBMILTER_API int smfi_replacebody __P((SMFICTX *, unsigned char *, int));
396 
397 /*
398 **  Replace the body of the message. This routine may be called multiple
399 **  times if the body is longer than convenient to send in one call. End of
400 **  line should be represented as Carriage-Return/Line Feed.
401 **
402 **	char *bodyp; Pointer to block of body information to insert
403 **	int bodylen; Length of data pointed at by bodyp
404 */
405 
406 /*
407 **  If the message is aborted (for example, if the SMTP sender sends the
408 **  envelope but then does a QUIT or RSET before the data is sent),
409 **  xxfi_abort is called. This can be used to reset state.
410 */
411 
412 #if _FFR_QUARANTINE
413 /*
414 **  Quarantine an envelope
415 **
416 **	SMFICTX *ctx; Opaque context structure
417 **	char *reason: explanation
418 */
419 
420 LIBMILTER_API int smfi_quarantine __P((SMFICTX *ctx, char *reason));
421 #endif /* _FFR_QUARANTINE */
422 
423 /*
424 **  Connection-private data (specific to an SMTP connection) can be
425 **  allocated using the smfi_setpriv routine; routines can access private
426 **  data using smfi_getpriv.
427 */
428 
429 LIBMILTER_API int smfi_setpriv __P((SMFICTX *, void *));
430 
431 /*
432 **  Set the private data pointer
433 **
434 **	SMFICTX *ctx; Opaque context structure
435 **	void *privatedata; Pointer to private data area
436 */
437 
438 LIBMILTER_API void *smfi_getpriv __P((SMFICTX *));
439 
440 
441 #endif /* !_LIBMILTER_MFAPI_H */
442