Download | Plain Text | Line Numbers
diff -Nur ucspi-tcp-0.88/Makefile ucspi-tcp-0.88-spp/Makefile
--- ucspi-tcp-0.88/Makefile 2000-03-18 16:18:42.000000000 +0100
+++ ucspi-tcp-0.88-spp/Makefile 2006-09-26 12:29:33.000000000 +0200
@@ -463,7 +463,7 @@
prog: \
tcpserver tcprules tcprulescheck argv0 recordio tcpclient who@ date@ \
finger@ http@ tcpcat mconnect mconnect-io addcr delcr fixcrio \
-rblsmtpd rts
+rblsmtpd rblspp rts
prot.o: \
compile prot.c hasshsgr.h prot.h
@@ -474,6 +474,11 @@
./load rblsmtpd commands.o dns.a time.a unix.a byte.a \
`cat socket.lib`
+rblspp: \
+load rblspp.o dns.a time.a unix.a byte.a socket.lib
+ ./load rblspp dns.a time.a unix.a byte.a \
+ `cat socket.lib`
+
rblsmtpd.o: \
compile rblsmtpd.c byte.h str.h scan.h fmt.h env.h exit.h sig.h \
buffer.h readwrite.h sgetopt.h subgetopt.h strerr.h stralloc.h \
@@ -481,6 +486,13 @@
tai.h uint64.h taia.h
./compile rblsmtpd.c
+rblspp.o: \
+compile rblspp.c byte.h str.h scan.h fmt.h env.h exit.h \
+buffer.h readwrite.h sgetopt.h subgetopt.h strerr.h stralloc.h \
+gen_alloc.h dns.h stralloc.h iopause.h taia.h \
+tai.h uint64.h taia.h
+ ./compile rblspp.c
+
readclose.o: \
compile readclose.c readwrite.h error.h readclose.h stralloc.h \
gen_alloc.h
diff -Nur ucspi-tcp-0.88/TARGETS ucspi-tcp-0.88-spp/TARGETS
--- ucspi-tcp-0.88/TARGETS 2000-03-18 16:18:42.000000000 +0100
+++ ucspi-tcp-0.88-spp/TARGETS 2006-09-26 12:17:16.000000000 +0200
@@ -153,8 +153,10 @@
fixcrio.o
fixcrio
rblsmtpd.o
+rblspp.o
commands.o
rblsmtpd
+rblspp
rts
prog
install.o
diff -Nur ucspi-tcp-0.88/rblspp.c ucspi-tcp-0.88-spp/rblspp.c
--- ucspi-tcp-0.88/rblspp.c 1970-01-01 01:00:00.000000000 +0100
+++ ucspi-tcp-0.88-spp/rblspp.c 2006-12-08 11:16:46.000000000 +0100
@@ -0,0 +1,209 @@
+#include "byte.h"
+#include "str.h"
+#include "scan.h"
+#include "fmt.h"
+#include "env.h"
+#include "exit.h"
+#include "buffer.h"
+#include "readwrite.h"
+#include "sgetopt.h"
+#include "strerr.h"
+#include "stralloc.h"
+#include "dns.h"
+
+#define FATAL "rblspp: fatal: "
+
+void nomem(void)
+{
+ strerr_die2x(111,FATAL,"out of memory");
+}
+void usage(void)
+{
+ strerr_die1x(100,"rblspp: usage: rblspp [ -b | -B ] [ -c | -C ] [ -r base ] [ -a base ]");
+}
+
+char *ip_env;
+static stralloc ip_reverse;
+
+void ip_init(void)
+{
+ unsigned int i;
+ unsigned int j;
+
+ ip_env = env_get("TCPREMOTEIP");
+ if (!ip_env) ip_env = "";
+
+ if (!stralloc_copys(&ip_reverse,"")) nomem();
+
+ i = str_len(ip_env);
+ while (i) {
+ for (j = i;j > 0;--j) if (ip_env[j - 1] == '.') break;
+ if (!stralloc_catb(&ip_reverse,ip_env + j,i - j)) nomem();
+ if (!stralloc_cats(&ip_reverse,".")) nomem();
+ if (!j) break;
+ i = j - 1;
+ }
+}
+
+int flagrblbounce = 0;
+int flagfailclosed = 0;
+int flagmustnotbounce = 0;
+
+int decision = 0; /* 0 undecided, 1 accept, 2 reject, 3 bounce */
+static stralloc text; /* defined if decision is 2 or 3 */
+
+static stralloc tmp;
+
+void rbl(char *base)
+{
+ int i;
+ char *altreply = 0;
+ if (decision) return;
+ if (!stralloc_copy(&tmp,&ip_reverse)) nomem();
+ i = str_chr(base, ':');
+ if (base[i]) {
+ base[i] = 0;
+ altreply = base+i+1;
+ }
+ if (!stralloc_cats(&tmp,base)) nomem();
+ if (altreply) {
+ if (dns_ip4(&text,&tmp) == -1) {
+ flagmustnotbounce = 1;
+ if (flagfailclosed) {
+ if (!stralloc_copys(&text,"temporary RBL lookup error")) nomem();
+ decision = 2;
+ }
+ return;
+ }
+ if (text.len) {
+ if(!stralloc_copys(&text, "")) nomem();
+ while(*altreply) {
+ char *x;
+ i = str_chr(altreply, '%');
+ if(!stralloc_catb(&text, altreply, i)) nomem();
+ if(altreply[i] &&
+ altreply[i+1]=='I' &&
+ altreply[i+2]=='P' &&
+ altreply[i+3]=='%') {
+ if(!stralloc_catb(&text, ip_env, str_len(ip_env))) nomem();
+ altreply+=i+4;
+ } else if(altreply[i]) {
+ if(!stralloc_cats(&text, "%")) nomem();
+ altreply+=i+1;
+ } else {
+ altreply+=i;
+ }
+ }
+ }
+ } else {
+ if (dns_txt(&text,&tmp) == -1) {
+ flagmustnotbounce = 1;
+ if (flagfailclosed) {
+ if (!stralloc_copys(&text,"temporary RBL lookup error")) nomem();
+ decision = 2;
+ }
+ return;
+ }
+ }
+ if (text.len)
+ if (flagrblbounce)
+ decision = 3;
+ else
+ decision = 2;
+}
+
+void antirbl(char *base)
+{
+ if (decision) return;
+ if (!stralloc_copy(&tmp,&ip_reverse)) nomem();
+ if (!stralloc_cats(&tmp,base)) nomem();
+ if (dns_ip4(&text,&tmp) == -1) {
+ flagmustnotbounce = 1;
+ if (!flagfailclosed)
+ decision = 1;
+ return;
+ }
+ if (text.len)
+ decision = 1;
+}
+
+char strnum[FMT_ULONG];
+static stralloc message;
+
+char outspace[1]; buffer out = BUFFER_INIT(write,1,outspace,sizeof outspace);
+
+void rblspp(void)
+{
+ int i;
+
+ if (flagmustnotbounce || (decision == 2)) {
+ if (!stralloc_copys(&message,"E451 ")) nomem();
+ }
+ else
+ if (!stralloc_copys(&message,"E553 ")) nomem();
+
+ if (text.len > 200) text.len = 200;
+ if (!stralloc_cat(&message,&text)) nomem();
+ for (i = 0;i < message.len;++i)
+ if ((message.s[i] < 32) || (message.s[i] > 126))
+ message.s[i] = '?';
+
+ buffer_puts(buffer_2,"rblspp: ");
+ buffer_puts(buffer_2,ip_env);
+ buffer_puts(buffer_2," pid ");
+ buffer_put(buffer_2,strnum,fmt_ulong(strnum,getppid()));
+ buffer_puts(buffer_2,": ");
+ buffer_put(buffer_2,message.s,message.len);
+ buffer_puts(buffer_2,"\n");
+ buffer_flush(buffer_2);
+
+ if (!stralloc_cats(&message,"\r\n")) nomem();
+
+ buffer_putflush(&out,message.s,message.len);
+
+ _exit(0);
+}
+
+main(int argc,char **argv,char **envp)
+{
+ char *x;
+ int opt;
+ int rcount;
+
+ x = env_get("SMTPRCPTCOUNT");
+ if (x) {
+ rcount = atoi(x);
+ if (rcount > 0) _exit(0);
+ }
+
+ ip_init();
+
+ x = env_get("RBLSPP");
+ if (x) {
+ if (!*x)
+ decision = 1;
+ else if (*x == '-') {
+ if (!stralloc_copys(&text,x + 1)) nomem();
+ decision = 3;
+ }
+ else {
+ if (!stralloc_copys(&text,x)) nomem();
+ decision = 2;
+ }
+ }
+
+ while ((opt = getopt(argc,argv,"bBcCr:a:")) != opteof)
+ switch(opt) {
+ case 'b': flagrblbounce = 1; break;
+ case 'B': flagrblbounce = 0; break;
+ case 'c': flagfailclosed = 1; break;
+ case 'C': flagfailclosed = 0; break;
+ case 'r': rbl(optarg); break;
+ case 'a': antirbl(optarg); break;
+ default: usage();
+ }
+
+ if (decision >= 2) rblspp();
+
+ _exit(0);
+}