xref: /openbsd/usr.sbin/smtpd/report_smtp.c (revision d3140113)
1 /*	$OpenBSD: report_smtp.c,v 1.12 2021/06/14 17:58:16 eric Exp $	*/
2 
3 /*
4  * Copyright (c) 2018 Gilles Chehade <gilles@poolp.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #include "smtpd.h"
20 
21 void
report_smtp_link_connect(const char * direction,uint64_t qid,const char * rdns,int fcrdns,const struct sockaddr_storage * ss_src,const struct sockaddr_storage * ss_dest)22 report_smtp_link_connect(const char *direction, uint64_t qid, const char *rdns, int fcrdns,
23     const struct sockaddr_storage *ss_src,
24     const struct sockaddr_storage *ss_dest)
25 {
26 	struct timeval	tv;
27 
28 	gettimeofday(&tv, NULL);
29 
30 	m_create(p_lka, IMSG_REPORT_SMTP_LINK_CONNECT, 0, 0, -1);
31 	m_add_string(p_lka, direction);
32 	m_add_timeval(p_lka, &tv);
33 	m_add_id(p_lka, qid);
34 	m_add_string(p_lka, rdns);
35 	m_add_int(p_lka, fcrdns);
36 	m_add_sockaddr(p_lka, (const struct sockaddr *)ss_src);
37 	m_add_sockaddr(p_lka, (const struct sockaddr *)ss_dest);
38 	m_close(p_lka);
39 }
40 
41 void
report_smtp_link_greeting(const char * direction,uint64_t qid,const char * domain)42 report_smtp_link_greeting(const char *direction, uint64_t qid,
43     const char *domain)
44 {
45 	struct timeval	tv;
46 
47 	gettimeofday(&tv, NULL);
48 
49 	m_create(p_lka, IMSG_REPORT_SMTP_LINK_GREETING, 0, 0, -1);
50 	m_add_string(p_lka, direction);
51 	m_add_timeval(p_lka, &tv);
52 	m_add_id(p_lka, qid);
53 	m_add_string(p_lka, domain);
54 	m_close(p_lka);
55 }
56 
57 void
report_smtp_link_identify(const char * direction,uint64_t qid,const char * method,const char * identity)58 report_smtp_link_identify(const char *direction, uint64_t qid, const char *method, const char *identity)
59 {
60 	struct timeval	tv;
61 
62 	gettimeofday(&tv, NULL);
63 
64 	m_create(p_lka, IMSG_REPORT_SMTP_LINK_IDENTIFY, 0, 0, -1);
65 	m_add_string(p_lka, direction);
66 	m_add_timeval(p_lka, &tv);
67 	m_add_id(p_lka, qid);
68 	m_add_string(p_lka, method);
69 	m_add_string(p_lka, identity);
70 	m_close(p_lka);
71 }
72 
73 void
report_smtp_link_tls(const char * direction,uint64_t qid,const char * ssl)74 report_smtp_link_tls(const char *direction, uint64_t qid, const char *ssl)
75 {
76 	struct timeval	tv;
77 
78 	gettimeofday(&tv, NULL);
79 
80 	m_create(p_lka, IMSG_REPORT_SMTP_LINK_TLS, 0, 0, -1);
81 	m_add_string(p_lka, direction);
82 	m_add_timeval(p_lka, &tv);
83 	m_add_id(p_lka, qid);
84 	m_add_string(p_lka, ssl);
85 	m_close(p_lka);
86 }
87 
88 void
report_smtp_link_disconnect(const char * direction,uint64_t qid)89 report_smtp_link_disconnect(const char *direction, uint64_t qid)
90 {
91 	struct timeval	tv;
92 
93 	gettimeofday(&tv, NULL);
94 
95 	m_create(p_lka, IMSG_REPORT_SMTP_LINK_DISCONNECT, 0, 0, -1);
96 	m_add_string(p_lka, direction);
97 	m_add_timeval(p_lka, &tv);
98 	m_add_id(p_lka, qid);
99 	m_close(p_lka);
100 }
101 
102 void
report_smtp_link_auth(const char * direction,uint64_t qid,const char * user,const char * result)103 report_smtp_link_auth(const char *direction, uint64_t qid, const char *user, const char *result)
104 {
105 	struct timeval	tv;
106 
107 	gettimeofday(&tv, NULL);
108 
109 	m_create(p_lka, IMSG_REPORT_SMTP_LINK_AUTH, 0, 0, -1);
110 	m_add_string(p_lka, direction);
111 	m_add_timeval(p_lka, &tv);
112 	m_add_id(p_lka, qid);
113 	m_add_string(p_lka, user);
114 	m_add_string(p_lka, result);
115 	m_close(p_lka);
116 }
117 
118 void
report_smtp_tx_reset(const char * direction,uint64_t qid,uint32_t msgid)119 report_smtp_tx_reset(const char *direction, uint64_t qid, uint32_t msgid)
120 {
121 	struct timeval	tv;
122 
123 	gettimeofday(&tv, NULL);
124 
125 	m_create(p_lka, IMSG_REPORT_SMTP_TX_RESET, 0, 0, -1);
126 	m_add_string(p_lka, direction);
127 	m_add_timeval(p_lka, &tv);
128 	m_add_id(p_lka, qid);
129 	m_add_u32(p_lka, msgid);
130 	m_close(p_lka);
131 }
132 
133 void
report_smtp_tx_begin(const char * direction,uint64_t qid,uint32_t msgid)134 report_smtp_tx_begin(const char *direction, uint64_t qid, uint32_t msgid)
135 {
136 	struct timeval	tv;
137 
138 	gettimeofday(&tv, NULL);
139 
140 	m_create(p_lka, IMSG_REPORT_SMTP_TX_BEGIN, 0, 0, -1);
141 	m_add_string(p_lka, direction);
142 	m_add_timeval(p_lka, &tv);
143 	m_add_id(p_lka, qid);
144 	m_add_u32(p_lka, msgid);
145 	m_close(p_lka);
146 }
147 
148 void
report_smtp_tx_mail(const char * direction,uint64_t qid,uint32_t msgid,const char * address,int ok)149 report_smtp_tx_mail(const char *direction, uint64_t qid, uint32_t msgid, const char *address, int ok)
150 {
151 	struct timeval	tv;
152 
153 	gettimeofday(&tv, NULL);
154 
155 	m_create(p_lka, IMSG_REPORT_SMTP_TX_MAIL, 0, 0, -1);
156 	m_add_string(p_lka, direction);
157 	m_add_timeval(p_lka, &tv);
158 	m_add_id(p_lka, qid);
159 	m_add_u32(p_lka, msgid);
160 	m_add_string(p_lka, address);
161 	m_add_int(p_lka, ok);
162 	m_close(p_lka);
163 }
164 
165 void
report_smtp_tx_rcpt(const char * direction,uint64_t qid,uint32_t msgid,const char * address,int ok)166 report_smtp_tx_rcpt(const char *direction, uint64_t qid, uint32_t msgid, const char *address, int ok)
167 {
168 	struct timeval	tv;
169 
170 	gettimeofday(&tv, NULL);
171 
172 	m_create(p_lka, IMSG_REPORT_SMTP_TX_RCPT, 0, 0, -1);
173 	m_add_string(p_lka, direction);
174 	m_add_timeval(p_lka, &tv);
175 	m_add_id(p_lka, qid);
176 	m_add_u32(p_lka, msgid);
177 	m_add_string(p_lka, address);
178 	m_add_int(p_lka, ok);
179 	m_close(p_lka);
180 }
181 
182 void
report_smtp_tx_envelope(const char * direction,uint64_t qid,uint32_t msgid,uint64_t evpid)183 report_smtp_tx_envelope(const char *direction, uint64_t qid, uint32_t msgid, uint64_t evpid)
184 {
185 	struct timeval	tv;
186 
187 	gettimeofday(&tv, NULL);
188 
189 	m_create(p_lka, IMSG_REPORT_SMTP_TX_ENVELOPE, 0, 0, -1);
190 	m_add_string(p_lka, direction);
191 	m_add_timeval(p_lka, &tv);
192 	m_add_id(p_lka, qid);
193 	m_add_u32(p_lka, msgid);
194 	m_add_id(p_lka, evpid);
195 	m_close(p_lka);
196 }
197 
198 void
report_smtp_tx_data(const char * direction,uint64_t qid,uint32_t msgid,int ok)199 report_smtp_tx_data(const char *direction, uint64_t qid, uint32_t msgid, int ok)
200 {
201 	struct timeval	tv;
202 
203 	gettimeofday(&tv, NULL);
204 
205 	m_create(p_lka, IMSG_REPORT_SMTP_TX_DATA, 0, 0, -1);
206 	m_add_string(p_lka, direction);
207 	m_add_timeval(p_lka, &tv);
208 	m_add_id(p_lka, qid);
209 	m_add_u32(p_lka, msgid);
210 	m_add_int(p_lka, ok);
211 	m_close(p_lka);
212 }
213 
214 void
report_smtp_tx_commit(const char * direction,uint64_t qid,uint32_t msgid,size_t msgsz)215 report_smtp_tx_commit(const char *direction, uint64_t qid, uint32_t msgid, size_t msgsz)
216 {
217 	struct timeval	tv;
218 
219 	gettimeofday(&tv, NULL);
220 
221 	m_create(p_lka, IMSG_REPORT_SMTP_TX_COMMIT, 0, 0, -1);
222 	m_add_string(p_lka, direction);
223 	m_add_timeval(p_lka, &tv);
224 	m_add_id(p_lka, qid);
225 	m_add_u32(p_lka, msgid);
226 	m_add_size(p_lka, msgsz);
227 	m_close(p_lka);
228 }
229 
230 void
report_smtp_tx_rollback(const char * direction,uint64_t qid,uint32_t msgid)231 report_smtp_tx_rollback(const char *direction, uint64_t qid, uint32_t msgid)
232 {
233 	struct timeval	tv;
234 
235 	gettimeofday(&tv, NULL);
236 
237 	m_create(p_lka, IMSG_REPORT_SMTP_TX_ROLLBACK, 0, 0, -1);
238 	m_add_string(p_lka, direction);
239 	m_add_timeval(p_lka, &tv);
240 	m_add_id(p_lka, qid);
241 	m_add_u32(p_lka, msgid);
242 	m_close(p_lka);
243 }
244 
245 void
report_smtp_protocol_client(const char * direction,uint64_t qid,const char * command)246 report_smtp_protocol_client(const char *direction, uint64_t qid, const char *command)
247 {
248 	struct timeval	tv;
249 
250 	gettimeofday(&tv, NULL);
251 
252 	m_create(p_lka, IMSG_REPORT_SMTP_PROTOCOL_CLIENT, 0, 0, -1);
253 	m_add_string(p_lka, direction);
254 	m_add_timeval(p_lka, &tv);
255 	m_add_id(p_lka, qid);
256 	m_add_string(p_lka, command);
257 	m_close(p_lka);
258 }
259 
260 void
report_smtp_protocol_server(const char * direction,uint64_t qid,const char * response)261 report_smtp_protocol_server(const char *direction, uint64_t qid, const char *response)
262 {
263 	struct timeval	tv;
264 
265 	gettimeofday(&tv, NULL);
266 
267 	m_create(p_lka, IMSG_REPORT_SMTP_PROTOCOL_SERVER, 0, 0, -1);
268 	m_add_string(p_lka, direction);
269 	m_add_timeval(p_lka, &tv);
270 	m_add_id(p_lka, qid);
271 	m_add_string(p_lka, response);
272 	m_close(p_lka);
273 }
274 
275 void
report_smtp_filter_response(const char * direction,uint64_t qid,int phase,int response,const char * param)276 report_smtp_filter_response(const char *direction, uint64_t qid, int phase, int response, const char *param)
277 {
278 	struct timeval	tv;
279 
280 	gettimeofday(&tv, NULL);
281 
282 	m_create(p_lka, IMSG_REPORT_SMTP_FILTER_RESPONSE, 0, 0, -1);
283 	m_add_string(p_lka, direction);
284 	m_add_timeval(p_lka, &tv);
285 	m_add_id(p_lka, qid);
286 	m_add_int(p_lka, phase);
287 	m_add_int(p_lka, response);
288 	m_add_string(p_lka, param);
289 	m_close(p_lka);
290 }
291 
292 void
report_smtp_timeout(const char * direction,uint64_t qid)293 report_smtp_timeout(const char *direction, uint64_t qid)
294 {
295 	struct timeval	tv;
296 
297 	gettimeofday(&tv, NULL);
298 
299 	m_create(p_lka, IMSG_REPORT_SMTP_TIMEOUT, 0, 0, -1);
300 	m_add_string(p_lka, direction);
301 	m_add_timeval(p_lka, &tv);
302 	m_add_id(p_lka, qid);
303 	m_close(p_lka);
304 }
305