s/qmail 4.3.21
Next generation secure email transport
Loading...
Searching...
No Matches
smtpdlog.c
Go to the documentation of this file.
1#include <unistd.h>
2#include "buffer.h"
3#include "str.h"
4#include "byte.h"
5#include "env.h"
6#include "fmt.h"
7#include "exit.h"
8#include "smtpdlog.h"
9#include "qmail.h"
10
11#define FDLOG 2
12
23
24static char strnum[FMT_ULONG];
25static char logbuf[BUFSIZE_LINE];
26buffer bo2 = BUFFER_INIT(write,FDLOG,logbuf,sizeof(logbuf));
27
29{
30 reply421pgl = env_get("REPLY_GREYLISTED");
31 reply550hlo = env_get("REPLY_HELO");
32 reply550mbx = env_get("REPLY_MAILBOX");
33 reply552siz = env_get("REPLY_MAXSIZE");
34 reply553bmf = env_get("REPLY_BADMAILFROM");
35 reply553brt = env_get("REPLY_BADRCPTTO");
36 reply553env = env_get("REPLY_SENDEREXIST");
37 reply553ngw = env_get("REPLY_NOGATEWAY");
38 reply553inv = env_get("REPLY_SENDERINVALID");
39 reply554cnt = env_get("REPLY_CONTENT");
40}
41
42static void logs(char *s) { if (buffer_puts(&bo2,s) == -1) _exit(1); } /* single string */
43static void logp(char *s) { logs(" P:"); logs(s); } /* protocol */
44static void logh(char *s1,char *s2,char *s3) { logs(" S:"); logs(s1); logs(":"); logs(s2); logs(" H:"); logs(s3); } /* host */
45static void logm(char *s) { logs(" F:"); logs(s); } /* mailfrom */
46static void logt(char *s) { logs(" T:"); logs(s); } /* rcptto */
47static void logi(char *s) { logs(" '"); logs(s); logs("'"); } /* information */
48static void logn(char *s) { if (buffer_puts(&bo2,s) == -1 ) _exit(1); if (buffer_flush(&bo2) == -1) _exit(1); } /* end */
49static void logpid() { strnum[fmt_ulong(strnum,getpid())] = 0; logs("qmail-smtpd: pid "); logs(strnum); logs(" "); }
50
51void smtp_loga(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7,char *s8,char *s9)
52 { logpid(); logs(s1); logs(s9); logp(s2); logh(s3,s4,s5); logm(s6); logt(s7), logs(" ?~"); logi(s8); logn("\n"); } /* Auth info */
53void smtp_logb(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
54 { logpid(); logs(s1); logs(s7); logp(s2); logh(s3,s4,s5); logs(" ?~"); logi(s6); logn("\n"); } /* Auth info */
55void smtp_logg(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
56 { logpid(); logs(s1); logp(s2); logh(s3,s4,s5); logm(s6); logt(s7); logn("\n"); } /* Generic */
57void smtp_logh(char *s1,char *s2,char *s3,char *s4,char *s5)
58 { logpid(); logs(s1); logp(s2); logh(s3,s4,s5); logn("\n"); } /* Host */
59void smtp_logi(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7,char *s8)
60 { logpid(); logs(s1); logp(s2); logh(s3,s4,s5); logm(s6); logt(s7); logi(s8); logn("\n"); } /* Generic + Info */
61void smtp_logr(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7,char *s8)
62 { logpid(); logs(s1); logs(s2); logp(s3); logh(s4,s5,s6); logm(s7); logt(s8); logn("\n"); } /* Recipient */
63
64void die_read() { _exit(1); }
65void die_alarm() { out("451 timeout (#4.4.2)\r\n"); flush(); _exit(1); }
66void die_nomem() { out("421 out of memory (#4.3.0)\r\n"); flush(); _exit(1); }
67void die_control() { out("421 unable to read controls (#4.3.0)\r\n"); flush(); _exit(1); }
68void die_ipme() { out("421 unable to figure out my IP addresses (#4.3.0)\r\n"); flush(); _exit(1); }
69void die_tls() { out("454 TLS not available due to temporary reason (#5.7.3)\r\n"); flush(); _exit(1); }
70void die_recipients() { out("421 unable to check recipients (#4.3.0)\r\n"); flush(); _exit(1); }
71
72void err_unimpl() { out("500 unimplemented (#5.5.1)\r\n"); flush(); _exit(1); }
73void err_syntax() { out("555 syntax error (#5.5.4)\r\n"); flush(); _exit(1); }
74void err_noop() { out("250 ok\r\n"); }
75void err_vrfy() { out("252 send some mail, i'll try my best\r\n"); }
76void err_qqt() { out("451 qqt failure (#4.3.0)\r\n"); }
77
78int err_child() { out("454 problem with child and I can't auth (#4.3.0)\r\n"); return -1; }
79int err_fork() { out("454 child won't start and I can't auth (#4.3.0)\r\n"); return -1; }
80int err_pipe() { out("454 unable to open pipe and I can't auth (#4.3.0)\r\n"); return -1; }
81int err_write() { out("454 unable to write pipe and I can't auth (#4.3.0)\r\n"); return -1; }
82
83int err_postgl() { out("454 problem with child and I can't greylist (#4.3.0)\r\n"); return -1; }
84int err_forkgl() { out("454 problem with child and I can't greylist (#4.3.0)\r\n"); return -1; }
85
86/* TLS */
87
89{
90 out("454 TLS not available due to temporary reason (#5.7.3)\r\n");
91 flush();
92 _exit(1);
93}
94void err_tlsreq(char *s1,char *s2,char *s3,char *s4,char *s5)
95{
96 out("535 STARTTLS required (#5.7.1)\r\n");
97 smtp_logh(s1,s2,s3,s4,s5);
98 flush();
99 _exit(1);
100}
101
102/* Helo */
103
104void err_helo(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7,char *s8)
105{
106 out("550 sorry, invalid HELO/EHLO greeting ");
108 out(" (#5.7.1)\r\n");
109 smtp_logi(s1,s2,s3,s4,s5,s6,s7,s8);
110 flush();
111 _exit(1);
112 }
113
114/* Auth */
115
116void err_authsetup(char *s1,char *s2,char *s3,char *s4,char *s5)
117{
118 out("530 Auth not available (#5.7.1)\r\n");
119 smtp_logh(s1,s2,s3,s4,s5);
120 flush();
121 _exit(1);
122}
124{
125 out("503 you're already authenticated (#5.5.0)\r\n");
126}
128{
129 out("503 no auth during mail transaction (#5.5.0)\r\n");
130}
131void err_authfail(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
132{
133 out("535 authentication failed (#5.7.1)\r\n");
134 smtp_logb(s1,s2,s3,s4,s5,s6,s7);
135 flush();
136 _exit(1);
137}
138void err_authreq(char *s1,char *s2,char *s3,char *s4,char *s5)
139{
140 out("535 authentication required (#5.7.1)\r\n"); smtp_logh(s1,s2,s3,s4,s5);
141 flush();
142 _exit(1);
143}
144void err_submission(char *s1,char *s2,char *s3,char *s4,char *s5)
145{
146 out("530 Authorization required (#5.7.1) \r\n"); smtp_logh(s1,s2,s3,s4,s5);
147 flush();
148 _exit(1);
149}
151{
152 out("501 auth exchange canceled (#5.0.0)\r\n");
153 return -1;
154}
156{
157 out("501 malformed auth input (#5.5.4)\r\n");
158 return -1;
159}
160void err_authinvalid(char *s1,char *s2,char *s3,char *s4,char *s5)
161{
162 out("504 auth type unimplemented (#5.5.1)\r\n");
163 smtp_logh(s1,s2,s3,s4,s5);
164 flush();
165 _exit(1);
166}
168{
169 out("504 auth type unimplemented (#5.5.1)\r\n");
170 return -1;
171}
172
173/* Mail From: */
174
175void err_wantmail() { out("503 MAIL first (#5.5.1)\r\n"); flush(); _exit(1); }
176
177void err_mav(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
178{
179 out("553 sorry, invalid sender address specified ");
181 out(" (#5.7.1)\r\n");
182 smtp_logg(s1,s2,s3,s4,s5,s6,s7);
183 flush();
184 _exit(1);
185}
186void err_bmf(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7,char *s8)
187{
188 out("553 sorry, your envelope sender is in my badmailfrom list ");
190 out(" (#5.7.1)\r\n");
191 smtp_logi(s1,s2,s3,s4,s5,s6,s7,s8);
192 flush();
193 _exit(1);
194}
195void err_mfdns(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
196{
197 out("553 sorry, your envelope sender must exist ");
199 out(" (#5.7.1)\r\n");
200 smtp_logg(s1,s2,s3,s4,s5,s6,s7);
201 flush();
202 _exit(1);
203}
204
205/* SPF */
206
207void err_spf(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7,char *msg)
208{
209 int i, j;
210 int len = str_len(msg);
211
212 for (i = 0; i < len; i = j + 1) {
213 j = byte_chr(msg + i, len - i, '\n') + i;
214 if (j < len) {
215 out("550-");
216 msg[j] = 0;
217 out(msg);
218 msg[j] = '\n';
219 } else {
220 out("550 ");
221 out(msg);
222 }
223 }
224 out(" (#5.7.1)\r\n");
225
226 smtp_logg(s1,s2,s3,s4,s5,s6,s7);
227 flush();
228 _exit(1);
229}
230
231/* Rcpt To: */
232
233void err_wantrcpt() { out("503 RCPT first (#5.5.1)\r\n"); flush(); _exit(1); }
234
235void postgrey(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
236{
237 out("421 greylisted");
239 out(" (#4.3.0)\r\n");
240 smtp_logg(s1,s2,s3,s4,s5,s6,s7);
241}
242void err_nogateway(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
243{
244 out("553 sorry, that domain isn't in my list of allowed rcpthosts ");
246 out(" (#5.7.1)\r\n");
247 smtp_logg(s1,s2,s3,s4,s5,s6,s7);
248 flush();
249 _exit(1);
250}
251void err_brt(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
252{
253 out("553 sorry, your envelope recipient is in my badrcptto list ");
255 out(" (#5.7.1)\r\n");
256 smtp_logg(s1,s2,s3,s4,s5,s6,s7);
257 flush();
258 _exit(1);
259}
260void err_rcpts(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
261{
262 out("452 sorry, too many recipients (#4.5.3)\r\n"); /* RFC 5321 */
263 smtp_logg(s1,s2,s3,s4,s5,s6,s7);
264 flush();
265 _exit(1);
266}
267void err_recipient(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
268{
269 if (env_get("RECIPIENTS450"))
270 out("450 sorry, mailbox currently unavailable (#4.2.1)\r\n");
271 else {
272 out("550 sorry, no mailbox by that name ");
273 if (reply550mbx) out(reply550mbx); out(" (#5.7.1)\r\n");
274 }
275 smtp_logg(s1,s2,s3,s4,s5,s6,s7);
276}
277
278/* Data */
279
281{
282 out("451 Bare Line Feeds (LF) are not accepted in SMTP; CRLF is required according to RFC 2822.\r\n");
283 flush();
284 _exit(1);
285}
287{
288 out("503 DATA command not accepted at this time (#5.5.1)\r\n");
289 flush();
290 _exit(1);
291}
292void err_size(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
293{
294 out("552 sorry, that message size exceeds my databytes limit (#5.3.4)\r\n");
295 smtp_logg(s1,s2,s3,s4,s5,s6,s7);
296 flush();
297 _exit(1);
298}
299void err_data(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7,char *s8)
300{
301 out("554 sorry, invalid message content ");
303 out(" (#5.3.2)\r\n");
304 smtp_logi(s1,s2,s3,s4,s5,s6,s7,s8);
305 flush();
306 _exit(1);
307}
#define FDLOG
stralloc out
Definition dnscname.c:12
void _exit(int)
ulongalloc msg
Definition matchup.c:56
char strnum[FMT_ULONG]
char logbuf[BUFSIZE_LOG]
Definition qmail-popup.c:77
int j
Definition qmail-send.c:926
#define BUFSIZE_LINE
Definition qmail.h:8
void err_wantrcpt()
Definition smtpdlog.c:233
void die_control()
Definition smtpdlog.c:67
void smtp_logh(char *s1, char *s2, char *s3, char *s4, char *s5)
Definition smtpdlog.c:57
void err_noop()
Definition smtpdlog.c:74
void err_wantmail()
Definition smtpdlog.c:175
char * reply550mbx
Definition smtpdlog.c:15
void err_authmail()
Definition smtpdlog.c:127
void err_mav(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
Definition smtpdlog.c:177
void err_qqt()
Definition smtpdlog.c:76
void err_recipient(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
Definition smtpdlog.c:267
void smtp_logg(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
Definition smtpdlog.c:55
void postgrey(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
Definition smtpdlog.c:235
void die_nomem()
Definition smtpdlog.c:66
void err_helo(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *s8)
Definition smtpdlog.c:104
int err_child()
Definition smtpdlog.c:78
void err_submission(char *s1, char *s2, char *s3, char *s4, char *s5)
Definition smtpdlog.c:144
char * reply553env
Definition smtpdlog.c:20
void err_authinvalid(char *s1, char *s2, char *s3, char *s4, char *s5)
Definition smtpdlog.c:160
void err_authsetup(char *s1, char *s2, char *s3, char *s4, char *s5)
Definition smtpdlog.c:116
void smtp_logr(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *s8)
Definition smtpdlog.c:61
void err_authfail(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
Definition smtpdlog.c:131
void straynewline()
Definition smtpdlog.c:280
char * reply421pgl
Definition smtpdlog.c:13
void err_rcpts(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
Definition smtpdlog.c:260
int err_write()
Definition smtpdlog.c:81
void err_spf(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *msg)
Definition smtpdlog.c:207
void err_tlsreq(char *s1, char *s2, char *s3, char *s4, char *s5)
Definition smtpdlog.c:94
void smtp_loga(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *s8, char *s9)
Definition smtpdlog.c:51
void err_bmf(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *s8)
Definition smtpdlog.c:186
int err_fork()
Definition smtpdlog.c:79
void err_authreq(char *s1, char *s2, char *s3, char *s4, char *s5)
Definition smtpdlog.c:138
int err_starttls()
Definition smtpdlog.c:88
buffer bo2
Definition smtpdlog.c:26
void smtp_logi(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *s8)
Definition smtpdlog.c:59
void err_notorious()
Definition smtpdlog.c:286
void err_authd()
Definition smtpdlog.c:123
void err_mfdns(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
Definition smtpdlog.c:195
char * reply554cnt
Definition smtpdlog.c:22
char * reply553inv
Definition smtpdlog.c:21
char * reply550hlo
Definition smtpdlog.c:14
void die_read()
Definition smtpdlog.c:64
char * reply552siz
Definition smtpdlog.c:16
int err_pipe()
Definition smtpdlog.c:80
char * reply553ngw
Definition smtpdlog.c:19
void smtpdlog_init()
Definition smtpdlog.c:28
void die_ipme()
Definition smtpdlog.c:68
char * reply553brt
Definition smtpdlog.c:18
void err_unimpl()
Definition smtpdlog.c:72
int err_authinput()
Definition smtpdlog.c:155
void err_size(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
Definition smtpdlog.c:292
int err_postgl()
Definition smtpdlog.c:83
void err_nogateway(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
Definition smtpdlog.c:242
void smtp_logb(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
Definition smtpdlog.c:53
void err_syntax()
Definition smtpdlog.c:73
int err_authabort()
Definition smtpdlog.c:150
void err_vrfy()
Definition smtpdlog.c:75
void err_data(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *s8)
Definition smtpdlog.c:299
char * reply553bmf
Definition smtpdlog.c:17
int err_noauth()
Definition smtpdlog.c:167
void err_brt(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
Definition smtpdlog.c:251
void die_alarm()
Definition smtpdlog.c:65
int err_forkgl()
Definition smtpdlog.c:84
void die_tls()
Definition smtpdlog.c:69
void die_recipients()
Definition smtpdlog.c:70
void flush(void)
Definition qmail-smtpd.c:91
void write()