diet-qmail-oversize-dns.patch
author Tomas Zeman <tzeman@volny.cz>
Fri, 12 Apr 2013 11:42:52 +0200
changeset 146 9d936651549d
parent 141 0f8cd90097d8
permissions -rw-r--r--
lighttpd-backport.patch: no systemd; fixed deps

Accept oversize DNS packets; CNAME errors avoidance

diff -r 262ce8533627 source/dietlibc/diet-qmail/FrugalBuild
--- a/source/dietlibc/diet-qmail/FrugalBuild	Fri May 04 20:22:54 2012 +0200
+++ b/source/dietlibc/diet-qmail/FrugalBuild	Fri May 04 21:03:18 2012 +0200
@@ -8,13 +8,14 @@
 # + queue-fix package with patches:
 #	errno
 #	dietlibc
+# + oversize DNS packets patch
 # Maintainer: Tomas Zeman <tzeman@volny.cz>
 
 branch=diet
 pkgorig=qmail
 pkgname=$branch-$pkgorig
 pkgver=1.03
-pkgrel=2
+pkgrel=3
 pkgdesc="A secure, reliable, efficient, SMTP/POP3 server."
 url="http://cr.yp.to/qmail.html"
 depends=('daemontools' 'ucspi-tcp' 'openssl')
@@ -43,6 +44,7 @@
 	http://www.netmeridian.com/e-huss/queue-fix-1.4.tar.gz \
 	queue-fix-errno.patch \
 	queue-fix-dietlibc.patch \
+	qmail-103-oversize-dns.patch \
         rc smtpd_run pop3d_run qmail.profile qmail.rc send_log_run \
         send_run smtpd_log_run pop3d_log_run tcp.smtp tcp.pop3 \
         make_cert.sh)
@@ -57,6 +59,7 @@
           'ce42fcc4daf5076adcf8fea6a9a84f2e1716c67c' \
           '72be22c7987ff3639692cda21c09dec340e06a4a' \
           '7d3525ab4a2e0e2be2bcd074dd94ae2784309d1b' \
+          '6eac86e4782ad3863c6d35ba2ddc38130d8e8dcc' \
           '3111cc689b5b1f6caa38997bf5f85aa3a516ef9c' \
           '3a80e44c97fd3035ce16c68fd2f611a64c61d169' \
           'f14f63c7b1bdc2d1f527249235551dc7f21ad47d' \
@@ -181,6 +184,7 @@
   Fpatch qregex-20060423-qmail.patch
   Fpatch qmail-dietlibc.patch
   Fpatch qmail-smtpd.spam.patch
+  Fpatch qmail-103-oversize-dns.patch
 
   # compile qmail
   make it man || Fdie 
diff -r 262ce8533627 source/dietlibc/diet-qmail/qmail-103-oversize-dns.patch
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/dietlibc/diet-qmail/qmail-103-oversize-dns.patch	Fri May 04 21:03:18 2012 +0200
@@ -0,0 +1,71 @@
+http://www.ckdhr.com/ckd/qmail-103.patch
+
+Description from http://qmail.ruk.cuni.cz/top.html :
+Christopher K. Davis has a patch to accept oversize DNS packets which works on
+both qmail's dns.c and tcpserver's dns.c. If you don't want to patch qmail, you
+can ameliorate the problem somewhat using djbdns, which returns only the
+records you ask for, making for a smaller ANSWER section. 
+
+--- qmail-1.03/dns.c.103	Mon Aug 17 16:06:58 1998
++++ qmail-1.03/dns.c	Wed Aug 26 16:28:56 1998
+@@ -21,10 +21,12 @@
+ static unsigned short getshort(c) unsigned char *c;
+ { unsigned short u; u = c[0]; return (u << 8) + c[1]; }
+ 
+-static union { HEADER hdr; unsigned char buf[PACKETSZ]; } response;
++static struct { unsigned char *buf; } response;
++static int responsebuflen = 0;
+ static int responselen;
+ static unsigned char *responseend;
+ static unsigned char *responsepos;
++static unsigned long saveresoptions;
+ 
+ static int numanswers;
+ static char name[MAXDNAME];
+@@ -45,18 +47,33 @@
+  errno = 0;
+  if (!stralloc_copy(&glue,domain)) return DNS_MEM;
+  if (!stralloc_0(&glue)) return DNS_MEM;
+- responselen = lookup(glue.s,C_IN,type,response.buf,sizeof(response));
++ if (!responsebuflen)
++  if (response.buf = (unsigned char *)alloc(PACKETSZ+1))
++   responsebuflen = PACKETSZ+1;
++  else return DNS_MEM;
++
++ responselen = lookup(glue.s,C_IN,type,response.buf,responsebuflen);
++ if ((responselen >= responsebuflen) ||
++     (responselen > 0 && (((HEADER *)response.buf)->tc)))
++  {
++   if (responsebuflen < 65536)
++    if (alloc_re(&response.buf, responsebuflen, 65536))
++     responsebuflen = 65536;
++    else return DNS_MEM;
++    saveresoptions = _res.options;
++    _res.options |= RES_USEVC;
++    responselen = lookup(glue.s,C_IN,type,response.buf,responsebuflen);
++    _res.options = saveresoptions;
++  }
+  if (responselen <= 0)
+   {
+    if (errno == ECONNREFUSED) return DNS_SOFT;
+    if (h_errno == TRY_AGAIN) return DNS_SOFT;
+    return DNS_HARD;
+   }
+- if (responselen >= sizeof(response))
+-   responselen = sizeof(response);
+  responseend = response.buf + responselen;
+  responsepos = response.buf + sizeof(HEADER);
+- n = ntohs(response.hdr.qdcount);
++ n = ntohs(((HEADER *)response.buf)->qdcount);
+  while (n-- > 0)
+   {
+    i = dn_expand(response.buf,responseend,responsepos,name,MAXDNAME);
+@@ -66,7 +83,7 @@
+    if (i < QFIXEDSZ) return DNS_SOFT;
+    responsepos += QFIXEDSZ;
+   }
+- numanswers = ntohs(response.hdr.ancount);
++ numanswers = ntohs(((HEADER *)response.buf)->ancount);
+  return 0;
+ }
+