summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd/filter_api.h
blob: 6740db2c309fe8f77607f5b7fe207842ea75a00a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*	$OpenBSD: filter_api.h,v 1.4 2012/08/20 21:14:17 gilles Exp $	*/

/*
 * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/socket.h>

#include <netdb.h>

#define	FILTER_API_VERSION	 50

#define MAX_LINE_SIZE		 2048
#define MAX_LOCALPART_SIZE	 64
#define MAX_DOMAINPART_SIZE	 255

enum filter_status {
	STATUS_IGNORE,
	STATUS_REJECT,
	STATUS_ACCEPT,
	STATUS_WAITING
};

enum filter_type {
	FILTER_CONNECT		= 0x001,
	FILTER_HELO		= 0x002,
	FILTER_EHLO		= 0x004,
	FILTER_MAIL		= 0x008,
	FILTER_RCPT		= 0x010,
	FILTER_DATALINE		= 0x020,
	FILTER_QUIT		= 0x040,
	FILTER_CLOSE		= 0x080,
	FILTER_RSET		= 0x100,
};

struct filter_connect {
	char			hostname[MAXHOSTNAMELEN];
	struct sockaddr_storage	hostaddr;
};

struct filter_helo {
	char			helohost[MAXHOSTNAMELEN];
};
 
struct filter_mail {
	char			user[MAX_LOCALPART_SIZE];
	char			domain[MAX_DOMAINPART_SIZE];
};

struct filter_rcpt {
	char			user[MAX_LOCALPART_SIZE];
	char			domain[MAX_DOMAINPART_SIZE];
};

struct filter_dataline {
	char			line[MAX_LINE_SIZE];
};

union filter_union {
	struct filter_connect	connect;
	struct filter_helo	helo;
	struct filter_mail	mail;
	struct filter_rcpt	rcpt;
	struct filter_dataline	dataline;
};

struct filter_msg {
	uint64_t		id;	 /* set by smtpd(8) */
	uint64_t		cl_id;	 /* set by smtpd(8) */
	int8_t       		code;
	uint8_t			version;
	enum filter_type	type;
	union filter_union	u;
};

/**/
void filter_init(void);
void filter_loop(void);

void filter_register_connect_callback(enum filter_status (*)(uint64_t, struct filter_connect *, void *), void *);
void filter_register_helo_callback(enum filter_status (*)(uint64_t, struct filter_helo *, void *), void *);
void filter_register_ehlo_callback(enum filter_status (*)(uint64_t, struct filter_helo *, void *), void *);
void filter_register_mail_callback(enum filter_status (*)(uint64_t, struct filter_mail *, void *), void *);
void filter_register_rcpt_callback(enum filter_status (*)(uint64_t, struct filter_rcpt *, void *), void *);
void filter_register_dataline_callback(enum filter_status (*)(uint64_t, struct filter_dataline *, void *), void *);
void filter_register_quit_callback(enum filter_status (*)(uint64_t, void *), void *);
void filter_register_close_callback(enum filter_status (*)(uint64_t, void *), void *);
void filter_register_rset_callback(enum filter_status (*)(uint64_t, void *), void *);