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