s/qmail 4.3.20
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"); }
73void err_syntax() { out("555 syntax error (#5.5.4)\r\n"); }
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 _exit(1);
92}
93void err_tlsreq(char *s1,char *s2,char *s3,char *s4,char *s5)
94{
95 out("535 STARTTLS required (#5.7.1)\r\n");
96 smtp_logh(s1,s2,s3,s4,s5);
97}
98
99/* Helo */
100
101void err_helo(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7,char *s8)
102{
103 out("550 sorry, invalid HELO/EHLO greeting ");
105 out(" (#5.7.1)\r\n");
106 smtp_logi(s1,s2,s3,s4,s5,s6,s7,s8);
107 }
108
109/* Auth */
110
111void err_authsetup(char *s1,char *s2,char *s3,char *s4,char *s5)
112{
113 out("530 Auth not available (#5.7.1)\r\n");
114 smtp_logh(s1,s2,s3,s4,s5);
115}
117{
118 out("503 you're already authenticated (#5.5.0)\r\n");
119}
121{
122 out("503 no auth during mail transaction (#5.5.0)\r\n");
123}
124void err_authfail(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
125{
126 out("535 authentication failed (#5.7.1)\r\n"); smtp_logb(s1,s2,s3,s4,s5,s6,s7);
127}
128void err_authreq(char *s1,char *s2,char *s3,char *s4,char *s5)
129{
130 out("535 authentication required (#5.7.1)\r\n"); smtp_logh(s1,s2,s3,s4,s5);
131}
132void err_submission(char *s1,char *s2,char *s3,char *s4,char *s5)
133{
134 out("530 Authorization required (#5.7.1) \r\n"); smtp_logh(s1,s2,s3,s4,s5);
135}
137{
138 out("501 auth exchange canceled (#5.0.0)\r\n");
139 return -1;
140}
142{
143 out("501 malformed auth input (#5.5.4)\r\n");
144 return -1;
145}
146void err_authinvalid(char *s1,char *s2,char *s3,char *s4,char *s5)
147{
148 out("504 auth type unimplemented (#5.5.1)\r\n");
149 smtp_logh(s1,s2,s3,s4,s5);
150}
152{
153 out("504 auth type unimplemented (#5.5.1)\r\n");
154 return -1;
155}
156
157/* Mail From: */
158
159void err_wantmail() { out("503 MAIL first (#5.5.1)\r\n"); }
160
161void err_mav(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
162{
163 out("553 sorry, invalid sender address specified ");
165 out(" (#5.7.1)\r\n");
166 smtp_logg(s1,s2,s3,s4,s5,s6,s7);
167}
168void err_bmf(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7,char *s8)
169{
170 out("553 sorry, your envelope sender is in my badmailfrom list ");
172 out(" (#5.7.1)\r\n");
173 smtp_logi(s1,s2,s3,s4,s5,s6,s7,s8);
174}
175void err_mfdns(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
176{
177 out("553 sorry, your envelope sender must exist ");
179 out(" (#5.7.1)\r\n");
180 smtp_logg(s1,s2,s3,s4,s5,s6,s7);
181}
182
183/* SPF */
184
185void err_spf(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7,char *msg)
186{
187 int i, j;
188 int len = str_len(msg);
189
190 for (i = 0; i < len; i = j + 1) {
191 j = byte_chr(msg + i, len - i, '\n') + i;
192 if (j < len) {
193 out("550-");
194 msg[j] = 0;
195 out(msg);
196 msg[j] = '\n';
197 } else {
198 out("550 ");
199 out(msg);
200 }
201 }
202 out(" (#5.7.1)\r\n");
203
204 smtp_logg(s1,s2,s3,s4,s5,s6,s7);
205}
206
207/* Rcpt To: */
208
209void err_wantrcpt() { out("503 RCPT first (#5.5.1)\r\n"); }
210
211void postgrey(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
212{
213 out("421 greylisted");
215 out(" (#4.3.0)\r\n");
216 smtp_logg(s1,s2,s3,s4,s5,s6,s7);
217}
218void err_nogateway(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
219{
220 out("553 sorry, that domain isn't in my list of allowed rcpthosts ");
222 out(" (#5.7.1)\r\n");
223 smtp_logg(s1,s2,s3,s4,s5,s6,s7);
224}
225void err_brt(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
226{
227 out("553 sorry, your envelope recipient is in my badrcptto list ");
229 out(" (#5.7.1)\r\n");
230 smtp_logg(s1,s2,s3,s4,s5,s6,s7);
231}
232void err_rcpts(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
233{
234 out("452 sorry, too many recipients (#4.5.3)\r\n"); /* RFC 5321 */
235 smtp_logg(s1,s2,s3,s4,s5,s6,s7);
236}
237void err_recipient(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
238{
239 if (env_get("RECIPIENTS450"))
240 out("450 sorry, mailbox currently unavailable (#4.2.1)\r\n");
241 else {
242 out("550 sorry, no mailbox by that name ");
243 if (reply550mbx) out(reply550mbx); out(" (#5.7.1)\r\n");
244 }
245 smtp_logg(s1,s2,s3,s4,s5,s6,s7);
246}
247
248/* Data */
249
251{
252 out("451 Bare Line Feeds (LF) are not accepted in SMTP; CRLF is required according to RFC 2822.\r\n");
253 flush();
254 _exit(1);
255}
257{
258 out("503 DATA command not accepted at this time (#5.5.1)\r\n");
259 flush();
260 _exit(1);
261}
262void err_size(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7)
263{
264 out("552 sorry, that message size exceeds my databytes limit (#5.3.4)\r\n");
265 smtp_logg(s1,s2,s3,s4,s5,s6,s7);
266}
267void err_data(char *s1,char *s2,char *s3,char *s4,char *s5,char *s6,char *s7,char *s8)
268{
269 out("554 sorry, invalid message content ");
271 out(" (#5.3.2)\r\n");
272 smtp_logi(s1,s2,s3,s4,s5,s6,s7,s8);
273}
stralloc out
Definition: dnscname.c:12
void _exit(int)
ulongalloc msg
Definition: matchup.c:56
char strnum[FMT_ULONG]
Definition: qmail-inject.c:505
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:209
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:159
char * reply550mbx
Definition: smtpdlog.c:15
void err_authmail()
Definition: smtpdlog.c:120
void err_mav(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
Definition: smtpdlog.c:161
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:237
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:211
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:101
int err_child()
Definition: smtpdlog.c:78
void err_submission(char *s1, char *s2, char *s3, char *s4, char *s5)
Definition: smtpdlog.c:132
char * reply553env
Definition: smtpdlog.c:20
void err_authinvalid(char *s1, char *s2, char *s3, char *s4, char *s5)
Definition: smtpdlog.c:146
void err_authsetup(char *s1, char *s2, char *s3, char *s4, char *s5)
Definition: smtpdlog.c:111
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:124
void straynewline()
Definition: smtpdlog.c:250
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:232
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:185
void err_tlsreq(char *s1, char *s2, char *s3, char *s4, char *s5)
Definition: smtpdlog.c:93
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:168
int err_fork()
Definition: smtpdlog.c:79
void err_authreq(char *s1, char *s2, char *s3, char *s4, char *s5)
Definition: smtpdlog.c:128
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:256
void err_authd()
Definition: smtpdlog.c:116
void err_mfdns(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
Definition: smtpdlog.c:175
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:141
void err_size(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
Definition: smtpdlog.c:262
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:218
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
#define FDLOG
Definition: smtpdlog.c:11
int err_authabort()
Definition: smtpdlog.c:136
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:267
char * reply553bmf
Definition: smtpdlog.c:17
int err_noauth()
Definition: smtpdlog.c:151
void err_brt(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7)
Definition: smtpdlog.c:225
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()