Download | Plain Text | No Line Numbers


  1. diff -Nur ucspi-tcp-0.88/Makefile ucspi-tcp-0.88-spp/Makefile
  2. --- ucspi-tcp-0.88/Makefile 2000-03-18 16:18:42.000000000 +0100
  3. +++ ucspi-tcp-0.88-spp/Makefile 2006-09-26 12:29:33.000000000 +0200
  4. @@ -463,7 +463,7 @@
  5. prog: \
  6. tcpserver tcprules tcprulescheck argv0 recordio tcpclient who@ date@ \
  7. finger@ http@ tcpcat mconnect mconnect-io addcr delcr fixcrio \
  8. -rblsmtpd rts
  9. +rblsmtpd rblspp rts
  10.  
  11. prot.o: \
  12. compile prot.c hasshsgr.h prot.h
  13. @@ -474,6 +474,11 @@
  14. ./load rblsmtpd commands.o dns.a time.a unix.a byte.a \
  15. `cat socket.lib`
  16.  
  17. +rblspp: \
  18. +load rblspp.o dns.a time.a unix.a byte.a socket.lib
  19. + ./load rblspp dns.a time.a unix.a byte.a \
  20. + `cat socket.lib`
  21. +
  22. rblsmtpd.o: \
  23. compile rblsmtpd.c byte.h str.h scan.h fmt.h env.h exit.h sig.h \
  24. buffer.h readwrite.h sgetopt.h subgetopt.h strerr.h stralloc.h \
  25. @@ -481,6 +486,13 @@
  26. tai.h uint64.h taia.h
  27. ./compile rblsmtpd.c
  28.  
  29. +rblspp.o: \
  30. +compile rblspp.c byte.h str.h scan.h fmt.h env.h exit.h \
  31. +buffer.h readwrite.h sgetopt.h subgetopt.h strerr.h stralloc.h \
  32. +gen_alloc.h dns.h stralloc.h iopause.h taia.h \
  33. +tai.h uint64.h taia.h
  34. + ./compile rblspp.c
  35. +
  36. readclose.o: \
  37. compile readclose.c readwrite.h error.h readclose.h stralloc.h \
  38. gen_alloc.h
  39. diff -Nur ucspi-tcp-0.88/TARGETS ucspi-tcp-0.88-spp/TARGETS
  40. --- ucspi-tcp-0.88/TARGETS 2000-03-18 16:18:42.000000000 +0100
  41. +++ ucspi-tcp-0.88-spp/TARGETS 2006-09-26 12:17:16.000000000 +0200
  42. @@ -153,8 +153,10 @@
  43. fixcrio.o
  44. fixcrio
  45. rblsmtpd.o
  46. +rblspp.o
  47. commands.o
  48. rblsmtpd
  49. +rblspp
  50. rts
  51. prog
  52. install.o
  53. diff -Nur ucspi-tcp-0.88/rblspp.c ucspi-tcp-0.88-spp/rblspp.c
  54. --- ucspi-tcp-0.88/rblspp.c 1970-01-01 01:00:00.000000000 +0100
  55. +++ ucspi-tcp-0.88-spp/rblspp.c 2006-12-08 11:16:46.000000000 +0100
  56. @@ -0,0 +1,209 @@
  57. +#include "byte.h"
  58. +#include "str.h"
  59. +#include "scan.h"
  60. +#include "fmt.h"
  61. +#include "env.h"
  62. +#include "exit.h"
  63. +#include "buffer.h"
  64. +#include "readwrite.h"
  65. +#include "sgetopt.h"
  66. +#include "strerr.h"
  67. +#include "stralloc.h"
  68. +#include "dns.h"
  69. +
  70. +#define FATAL "rblspp: fatal: "
  71. +
  72. +void nomem(void)
  73. +{
  74. + strerr_die2x(111,FATAL,"out of memory");
  75. +}
  76. +void usage(void)
  77. +{
  78. + strerr_die1x(100,"rblspp: usage: rblspp [ -b | -B ] [ -c | -C ] [ -r base ] [ -a base ]");
  79. +}
  80. +
  81. +char *ip_env;
  82. +static stralloc ip_reverse;
  83. +
  84. +void ip_init(void)
  85. +{
  86. + unsigned int i;
  87. + unsigned int j;
  88. +
  89. + ip_env = env_get("TCPREMOTEIP");
  90. + if (!ip_env) ip_env = "";
  91. +
  92. + if (!stralloc_copys(&ip_reverse,"")) nomem();
  93. +
  94. + i = str_len(ip_env);
  95. + while (i) {
  96. + for (j = i;j > 0;--j) if (ip_env[j - 1] == '.') break;
  97. + if (!stralloc_catb(&ip_reverse,ip_env + j,i - j)) nomem();
  98. + if (!stralloc_cats(&ip_reverse,".")) nomem();
  99. + if (!j) break;
  100. + i = j - 1;
  101. + }
  102. +}
  103. +
  104. +int flagrblbounce = 0;
  105. +int flagfailclosed = 0;
  106. +int flagmustnotbounce = 0;
  107. +
  108. +int decision = 0; /* 0 undecided, 1 accept, 2 reject, 3 bounce */
  109. +static stralloc text; /* defined if decision is 2 or 3 */
  110. +
  111. +static stralloc tmp;
  112. +
  113. +void rbl(char *base)
  114. +{
  115. + int i;
  116. + char *altreply = 0;
  117. + if (decision) return;
  118. + if (!stralloc_copy(&tmp,&ip_reverse)) nomem();
  119. + i = str_chr(base, ':');
  120. + if (base[i]) {
  121. + base[i] = 0;
  122. + altreply = base+i+1;
  123. + }
  124. + if (!stralloc_cats(&tmp,base)) nomem();
  125. + if (altreply) {
  126. + if (dns_ip4(&text,&tmp) == -1) {
  127. + flagmustnotbounce = 1;
  128. + if (flagfailclosed) {
  129. + if (!stralloc_copys(&text,"temporary RBL lookup error")) nomem();
  130. + decision = 2;
  131. + }
  132. + return;
  133. + }
  134. + if (text.len) {
  135. + if(!stralloc_copys(&text, "")) nomem();
  136. + while(*altreply) {
  137. + char *x;
  138. + i = str_chr(altreply, '%');
  139. + if(!stralloc_catb(&text, altreply, i)) nomem();
  140. + if(altreply[i] &&
  141. + altreply[i+1]=='I' &&
  142. + altreply[i+2]=='P' &&
  143. + altreply[i+3]=='%') {
  144. + if(!stralloc_catb(&text, ip_env, str_len(ip_env))) nomem();
  145. + altreply+=i+4;
  146. + } else if(altreply[i]) {
  147. + if(!stralloc_cats(&text, "%")) nomem();
  148. + altreply+=i+1;
  149. + } else {
  150. + altreply+=i;
  151. + }
  152. + }
  153. + }
  154. + } else {
  155. + if (dns_txt(&text,&tmp) == -1) {
  156. + flagmustnotbounce = 1;
  157. + if (flagfailclosed) {
  158. + if (!stralloc_copys(&text,"temporary RBL lookup error")) nomem();
  159. + decision = 2;
  160. + }
  161. + return;
  162. + }
  163. + }
  164. + if (text.len)
  165. + if (flagrblbounce)
  166. + decision = 3;
  167. + else
  168. + decision = 2;
  169. +}
  170. +
  171. +void antirbl(char *base)
  172. +{
  173. + if (decision) return;
  174. + if (!stralloc_copy(&tmp,&ip_reverse)) nomem();
  175. + if (!stralloc_cats(&tmp,base)) nomem();
  176. + if (dns_ip4(&text,&tmp) == -1) {
  177. + flagmustnotbounce = 1;
  178. + if (!flagfailclosed)
  179. + decision = 1;
  180. + return;
  181. + }
  182. + if (text.len)
  183. + decision = 1;
  184. +}
  185. +
  186. +char strnum[FMT_ULONG];
  187. +static stralloc message;
  188. +
  189. +char outspace[1]; buffer out = BUFFER_INIT(write,1,outspace,sizeof outspace);
  190. +
  191. +void rblspp(void)
  192. +{
  193. + int i;
  194. +
  195. + if (flagmustnotbounce || (decision == 2)) {
  196. + if (!stralloc_copys(&message,"E451 ")) nomem();
  197. + }
  198. + else
  199. + if (!stralloc_copys(&message,"E553 ")) nomem();
  200. +
  201. + if (text.len > 200) text.len = 200;
  202. + if (!stralloc_cat(&message,&text)) nomem();
  203. + for (i = 0;i < message.len;++i)
  204. + if ((message.s[i] < 32) || (message.s[i] > 126))
  205. + message.s[i] = '?';
  206. +
  207. + buffer_puts(buffer_2,"rblspp: ");
  208. + buffer_puts(buffer_2,ip_env);
  209. + buffer_puts(buffer_2," pid ");
  210. + buffer_put(buffer_2,strnum,fmt_ulong(strnum,getppid()));
  211. + buffer_puts(buffer_2,": ");
  212. + buffer_put(buffer_2,message.s,message.len);
  213. + buffer_puts(buffer_2,"\n");
  214. + buffer_flush(buffer_2);
  215. +
  216. + if (!stralloc_cats(&message,"\r\n")) nomem();
  217. +
  218. + buffer_putflush(&out,message.s,message.len);
  219. +
  220. + _exit(0);
  221. +}
  222. +
  223. +main(int argc,char **argv,char **envp)
  224. +{
  225. + char *x;
  226. + int opt;
  227. + int rcount;
  228. +
  229. + x = env_get("SMTPRCPTCOUNT");
  230. + if (x) {
  231. + rcount = atoi(x);
  232. + if (rcount > 0) _exit(0);
  233. + }
  234. +
  235. + ip_init();
  236. +
  237. + x = env_get("RBLSPP");
  238. + if (x) {
  239. + if (!*x)
  240. + decision = 1;
  241. + else if (*x == '-') {
  242. + if (!stralloc_copys(&text,x + 1)) nomem();
  243. + decision = 3;
  244. + }
  245. + else {
  246. + if (!stralloc_copys(&text,x)) nomem();
  247. + decision = 2;
  248. + }
  249. + }
  250. +
  251. + while ((opt = getopt(argc,argv,"bBcCr:a:")) != opteof)
  252. + switch(opt) {
  253. + case 'b': flagrblbounce = 1; break;
  254. + case 'B': flagrblbounce = 0; break;
  255. + case 'c': flagfailclosed = 1; break;
  256. + case 'C': flagfailclosed = 0; break;
  257. + case 'r': rbl(optarg); break;
  258. + case 'a': antirbl(optarg); break;
  259. + default: usage();
  260. + }
  261. +
  262. + if (decision >= 2) rblspp();
  263. +
  264. + _exit(0);
  265. +}
  266.