22 logmsg(
WHO,111,FATAL,
"out of memory");
26 logmsg(
WHO,100,USAGE,
"rblsmtpd \
29[ -i ] [ -t timeout ] \
30[ -r base ] [ -a base ] \
31[-W] [-w delay] smtpd [ arg ... ]");
36static stralloc ip_reverse;
52 ip_env = env_get(
"TCP6REMOTEIP");
54 if (byte_equal(
ip_env,7,V4MAPPREFIX))
59 ip_env = env_get(
"TCPREMOTEIP");
61 else if (byte_equal(
ip_env,7,V4MAPPREFIX))
65 if (!stralloc_copys(&ip_reverse,
""))
nomem();
70 for (j = 15; j >= 0; j--) {
72 if (!stralloc_catb(&ip_reverse,&hexval,1))
nomem();
73 if (!stralloc_cats(&ip_reverse,
"."))
nomem();
75 hexval = tohex(
remoteip[j] >> 4 & 15);
76 if (!stralloc_catb(&ip_reverse,&hexval,1))
nomem();
77 if (!stralloc_cats(&ip_reverse,
"."))
nomem();
84 for (j = i; j > 0; --j)
85 if (
ip_env[j - 1] ==
'.')
break;
86 if (!stralloc_catb(&ip_reverse,
ip_env + j,i - j))
nomem();
87 if (!stralloc_cats(&ip_reverse,
"."))
nomem();
108 if (!stralloc_copy(&tmp,&ip_reverse))
nomem();
109 if (!stralloc_cats(&tmp,base))
nomem();
111 if (dns_txt(&text,&tmp) < 0) {
114 if (!stralloc_copys(&text,
"temporary RBL lookup error"))
nomem();
132 if (!stralloc_copy(&tmp,&ip_reverse))
nomem();
133 if (!stralloc_cats(&tmp,base))
nomem();
136 flagip = dns_ip6(&text,&tmp);
138 flagip = dns_ip4(&text,&tmp);
150static char strnum[FMT_ULONG];
151static stralloc message = {0};;
152static stralloc info = {0};
165 x = env_get(
"GREETDELAY");
173 if (!stralloc_copys(&info,
"Greetdelay: "))
nomem();
175 buffer_puts(buffer_2,
"rblsmtpd: ");
176 buffer_puts(buffer_2,
ip_env);
177 buffer_puts(buffer_2,
" pid ");
178 buffer_put(buffer_2,strnum,fmt_ulong(strnum,getpid()));
179 buffer_puts(buffer_2,
": ");
180 buffer_put(buffer_2,info.s,info.len);
181 buffer_put(buffer_2,strnum,fmt_ulong(strnum,delay));
182 buffer_puts(buffer_2,
"\n");
183 buffer_flush(buffer_2);
193 if (!stralloc_copys(&message,
"[RBL info] "))
nomem();
195 if (text.len > 200) text.len = 200;
196 if (!stralloc_cat(&message,&text))
nomem();
198 for (i = 0; i < message.len; ++i)
199 if ((message.s[i] < 32) || (message.s[i] > 126))
202 buffer_puts(buffer_2,
"rblsmtpd: ");
203 buffer_puts(buffer_2,
ip_env);
204 buffer_puts(buffer_2,
" pid ");
205 buffer_put(buffer_2,strnum,fmt_ulong(strnum,getpid()));
206 buffer_puts(buffer_2,
" ");
207 buffer_put(buffer_2,message.s,message.len);
208 buffer_puts(buffer_2,
"\n");
209 buffer_flush(buffer_2);
211 if (!stralloc_copy(&info,&message))
nomem();
212 if (!stralloc_0(&info))
nomem();
213 if (!pathexec_env(
"RBLSMTPD",info.s))
nomem();
218void reject(
char *d) { buffer_putflush(&
out,message.s,message.len); }
219void accept(
char *d) { buffer_putsflush(&
out,
"250 rblsmtpd.local\r\n"); }
220void greet(
char *d) { buffer_putsflush(&
out,
"220 rblsmtpd.local\r\n"); }
221void quit(
char *d) { buffer_putsflush(&
out,
"221 rblsmtpd.local\r\n"); _exit(0); }
222void drop(
char *d) { _exit(0); }
240 if (!stralloc_copys(&message,
"451 "))
nomem();
242 if (!stralloc_copys(&message,
"553 "))
nomem();
244 if (text.len > 200) text.len = 200;
245 if (!stralloc_cat(&message,&text))
nomem();
246 for (i = 0; i < message.len; ++i)
247 if ((message.s[i] < 32) || (message.s[i] > 126))
250 buffer_puts(buffer_2,
"rblsmtpd: ");
251 buffer_puts(buffer_2,
ip_env);
252 buffer_puts(buffer_2,
" pid ");
253 buffer_put(buffer_2,strnum,fmt_ulong(strnum,getpid()));
254 buffer_puts(buffer_2,
": ");
255 buffer_put(buffer_2,message.s,message.len);
256 buffer_puts(buffer_2,
"\n");
257 buffer_flush(buffer_2);
259 if (!stralloc_cats(&message,
"\r\n"))
nomem();
264 sig_catch(sig_alarm,(
void *)
drop);
272int main(
int argc,
char *
const argv[],
char *
const envp[])
276 unsigned long greetdelay = 0;
280 x = env_get(
"RBLSMTPD");
284 else if (*x ==
'-') {
285 if (!stralloc_copys(&text,x + 1))
nomem();
289 if (!stralloc_copys(&text,x))
nomem();
294 while ((opt = getoptb(argc,(
char **)argv,
"bBcCit:r:a:w:W")) != opteof)
301 case 't': scan_ulong(optarg,&
timeout);
break;
302 case 'r':
rbl(optarg);
break;
303 case 'a':
antirbl(optarg);
break;
305 case 'w':
if (!
decision) { scan_ulong(optarg,&greetdelay);
waitdelay(greetdelay); }
break;
318 logmsg(
WHO,111,FATAL,B(
"unable to run: ",*argv));
void waitdelay(unsigned long delay)
struct commands smtpcommands[]