Plesk8 und qmail – Die Wiederbelebung eines Zombies

Da Plesk8 und qmail wohl auf unseren rootserver kommen.
Problem ist nur, dass qmail seit 98 nicht mehr weiterentwickelt wurde und seitdem von allerhand Leuten wie wild gepatcht wird.

SWsoft steht dem auch in keiner Weise nach und stattet sein qmail mit 25 (!!!) Patches aus.
Selbige bekommt man hier: kb.swsoft.com/article_22_1161_en.html
Und die Version 1.03 von qmail lässt sich mit Google schnell finden: ftp.eu.uu.net/pub/unix/mail/qmail/qmail-1.03.tar.gz
Patchen kann man nicht einfach so… Nein.

Da muss man genaue Reihenfolgen einhalten weil der ein oder andere Patch auf einem anderen Aufbaut:

  1. cd /usr/src/qmail-1.03
  2. patchDir=/usr/src/qmail_patches
  3. patches="
  4. $patchDir/patch-BC
  5. $patchDir/patch-TD
  6. $patchDir/patch-big-dns
  7. $patchDir/patch-chown
  8. $patchDir/patch-pb
  9. $patchDir/patch-pe
  10. $patchDir/patch-pf
  11. $patchDir/patch-pg
  12. $patchDir/patch-ph
  13. $patchDir/patch-pi
  14. $patchDir/patch-pp
  15. $patchDir/patch-ps
  16. $patchDir/patch-pt
  17. $patchDir/patch-pu-tls
  18. $patchDir/patch-pv-smtp-auth
  19. $patchDir/patch-qmail-date-localtime
  20. $patchDir/patch-qmtpd
  21. $patchDir/patch-quota
  22. $patchDir/fr49-quota-patch
  23. $patchDir/patch-spf
  24. $patchDir/patch-z01-isoc
  25. $patchDir/patch-z02-libssl
  26. $patchDir/patch-z03-next-mx
  27. $patchDir/patch-z04-tcp-env
  28. $patchDir/patch-z10-spp
  29. $patchDir/patch-z15-smtpd-relay-reject
  30. "
  31. for p in $patches;
  32. do echo;
  33. echo $p;
  34. patch  -p0  < $p;
  35. res=$?;
  36. if test $res -ne 0; then
  37. echo "ERRROR: patch $p";
  38. break;
  39. fi;
  40. done

Wer dachte das wars….
neinneinneinneinnein.

Alle INSTALL-Datei lesen. Das heißt man muss auch noch das hier ausführen:

  1. # groupadd nofiles
  2. # useradd -g nofiles -d /var/qmail/alias alias
  3. # useradd -g nofiles -d /var/qmail qmaild
  4. # useradd -g nofiles -d /var/qmail qmaill
  5. # useradd -g nofiles -d /var/qmail qmailp
  6. # groupadd qmail
  7. # useradd -g qmail -d /var/qmail qmailq
  8. # useradd -g qmail -d /var/qmail qmailr
  9. # useradd -g qmail -d /var/qmail qmails

Vor dem Kompilieren muss man nämlich noch die Zahl in der Datei conf-spawn von 1000 auf 255 ändern (bei den meisten Distris reicht es wenn sie unterhalb von 509 ist).

  1. make setup check

, so der offz. Compilebefehl lieft dann aber immer noch keine Binaries die denen entsprechen, die Plesk installiert.
Durch das viele Rumgepatche hat man es nämlich geschafft die Makefile inkompatibel zu machen.
Zeile 115ff müssen nun so aussehen:

  1. ( ./auto-uid auto_uida `head -1 conf-users` `id -u \`head -1 conf-users\` ` \
  2. &&./auto-uid auto_uidd `head -2 conf-users | tail -1` `id -u \`head -2 conf-users | tail -1\`` \
  3. &&./auto-uid auto_uidl `head -3 conf-users | tail -1` `id -u \`head -3 conf-users | tail -1\`` \
  4. &&./auto-uid auto_uido `head -4 conf-users | tail -1` `id -u \`head -4 conf-users | tail -1\`` \
  5. &&./auto-uid auto_uidp `head -5 conf-users | tail -1` `id -u \`head -5 conf-users | tail -1\`` \
  6. &&./auto-uid auto_uidq `head -6 conf-users | tail -1` `id -u \`head -6 conf-users | tail -1\`` \
  7. &&./auto-uid auto_uidr `head -7 conf-users | tail -1` `id -u \`head -7 conf-users | tail -1\`` \
  8. &&./auto-uid auto_uids `head -8 conf-users | tail -1` `id -u \`head -8 conf-users | tail -1\`` \
  9. &&./auto-gid auto_gidq `head -1 conf-groups` 1002 \
  10. &&./auto-gid auto_gidn `head -2 conf-groups | tail -1` 1001 \
  11. ) > auto_uids.c.tmp && mv auto_uids.c.tmp auto_uids.c

Die GIDs 1002 und 1001 sind leider noch hardcoded. Ich hoffe dafür finde ich eine Anpassung.

Als letztes muss noch eine Datei names

  1. ssl.lib

im qmail-Verzeichnis angelegt werden.
Der kreative Inhalt (ja ./configure ist schon was feines…):

  1. -lssl -lcrypto

Nun funktioniert auch das Kompilieren.

DANKE SWsoft!!!

So, aber warum der ganze Spaß eigenltich?
Damit man qmail-tap in qmail einpatchen kann (reshmeat.net/projects/qmailtap/ bzw www.inter7.com/?page=qmailtap)

Natürlich passt der Patch auch nicht mehr.
Hier eine gepatchter Patch (Hallo?! Gehts noch?!):

  1. diff -Nur qmail-1.03/error.h qmail-1.03.tap/error.h
  2. --- qmail-1.03/error.h  1998-06-15 05:53:16.000000000 -0500
  3. +++ qmail-1.03.tap/error.h  2005-06-06 13:02:38.000000000 -0500
  4. @@ -1,5 +1,6 @@
  5. #ifndef ERROR_H
  6. #define ERROR_H
  7. +#include
  8.  
  9. extern int errno;
  10.  
  11. diff -Nur qmail-1.03/Makefile qmail-1.03.tap/Makefile
  12. --- qmail-1.03/Makefile 1998-06-15 05:53:16.000000000 -0500
  13. +++ qmail-1.03.tap/Makefile 2005-02-15 12:50:37.000000000 -0600
  14. @@ -1419,13 +1419,14 @@
  15. nroff -man qmail-qstat.8 > qmail-qstat.0
  16.  
  17. qmail-queue: \
  18. -load qmail-queue.o triggerpull.o fmtqfn.o now.o date822fmt.o \
  19. -datetime.a seek.a ndelay.a open.a sig.a alloc.a substdio.a error.a \
  20. -str.a fs.a auto_qmail.o auto_split.o auto_uids.o
  21. +load qmail-queue.o triggerpull.o fmtqfn.o now.o date822fmt.o qregex.o \
  22. +datetime.a seek.a case.a ndelay.a open.a sig.a getln.a stralloc.a alloc.a \
  23. +substdio.a error.a control.o constmap.o str.a fs.a auto_qmail.o \
  24. +auto_split.o auto_uids.o
  25. ./load qmail-queue triggerpull.o fmtqfn.o now.o \
  26. -   date822fmt.o datetime.a seek.a ndelay.a open.a sig.a \
  27. -   alloc.a substdio.a error.a str.a fs.a auto_qmail.o \
  28. -   auto_split.o auto_uids.o
  29. +   date822fmt.o qregex.o control.o constmap.o datetime.a case.a seek.a \
  30. +   ndelay.a open.a sig.a getln.a stralloc.a alloc.a substdio.a error.a \
  31. +   str.a fs.a auto_qmail.o auto_split.o auto_uids.o
  32.  
  33. qmail-queue.0: \
  34. qmail-queue.8
  35. @@ -1681,6 +1682,10 @@
  36. constmap.h stralloc.h gen_alloc.h rcpthosts.h
  37. ./compile rcpthosts.c
  38.  
  39. +qregex.o: \
  40. +compile qregex.c qregex.h
  41. +   ./compile qregex.c
  42. +
  43. readsubdir.o: \
  44. compile readsubdir.c readsubdir.h direntry.h fmt.h scan.h str.h \
  45. auto_split.h
  46. diff -Nur qmail-1.03/qmail-control.9 qmail-1.03.tap/qmail-control.9
  47. --- qmail-1.03/qmail-control.9  1998-06-15 05:53:16.000000000 -0500
  48. +++ qmail-1.03.tap/qmail-control.9  2005-06-06 13:10:03.000000000 -0500
  49. @@ -69,6 +69,7 @@
  50. .I servercert.pem   \fR(none)   \fRqmail-smtpd
  51. .I smtpgreeting \fIme   \fRqmail-smtpd
  52. .I smtproutes   \fR(none)   \fRqmail-remote
  53. +.I taps    \fR(none)   \fRqmail-queue
  54. .I spfbehavior  \fR0    \fRqmail-smtpd
  55. .I spfexp   \fR(default)    \fRqmail-smtpd
  56. .I spfguess \fR(none)   \fRqmail-smtpd
  57. diff -Nur qmail-1.03/qmail-queue.8 qmail-1.03.tap/qmail-queue.8
  58. --- qmail-1.03/qmail-queue.8    1998-06-15 05:53:16.000000000 -0500
  59. +++ qmail-1.03.tap/qmail-queue.8    2005-06-06 13:11:01.000000000 -0500
  60. @@ -40,6 +40,12 @@
  61. However, the recipients probably expect to see a proper header,
  62. as described in
  63. .BR qmail-header(5) .
  64. +.SH "CONTROL FILES"
  65. +.TP 5
  66. +.I taps
  67. +Should contain regex syntax of email addresses to tap and
  68. +the associated email address to send the copy to. The two
  69. +fields should be separated by a colon.
  70. .SH "FILESYSTEM RESTRICTIONS"
  71. .B qmail-queue
  72. imposes two constraints on the queue structure:
  73. diff -Nur qmail-1.03/qmail-queue.c qmail-1.03.tap/qmail-queue.c
  74. --- qmail-1.03/qmail-queue.c    1998-06-15 05:53:16.000000000 -0500
  75. +++ qmail-1.03.tap/qmail-queue.c    2005-05-17 14:59:00.000000000 -0500
  76. @@ -16,6 +16,8 @@
  77. #include "auto_uids.h"
  78. #include "date822fmt.h"
  79. #include "fmtqfn.h"
  80. +#include "stralloc.h"
  81. +#include "constmap.h"
  82.  
  83. #define DEATH 86400 /* 24 hours; _must_ be below q-s's OSSIFIED (36 hours) */
  84. #define ADDR 1003
  85. @@ -25,6 +27,14 @@
  86. char outbuf[256];
  87. struct substdio ssout;
  88.  
  89. +int tapok = 0;
  90. +stralloc tap = {0};
  91. +struct constmap maptap;
  92. +stralloc chkaddr = {0};
  93. +int tapped;
  94. +stralloc tapaddr = {0};
  95. +stralloc controlfile = {0};
  96. +
  97. datetime_sec starttime;
  98. struct datetime dt;
  99. unsigned long mypid;
  100. @@ -175,6 +185,13 @@
  101.  
  102. alarm(DEATH);
  103.  
  104. + stralloc_copys( &controlfile, auto_qmail);
  105. + stralloc_cats( &controlfile, "/control/taps");
  106. + stralloc_0( &controlfile);
  107. + tapok = control_readfile(&tap,controlfile.s,0);
  108. + if (tapok == -1) die(65);
  109. + if (!constmap_init(&maptap,tap.s,tap.len,0)) die(65);
  110. +
  111. pidopen();
  112. if (fstat(messfd,&pidst) == -1) die(63);
  113.  
  114. @@ -219,14 +236,28 @@
  115. if (substdio_get(&ssin,&ch,1) < 1) die_read();
  116. if (ch != 'F') die(91);
  117. if (substdio_bput(&ssout,&ch,1) == -1) die_write();
  118. + stralloc_0(&chkaddr);
  119. for (len = 0;len < ADDR;++len)
  120. {
  121. +   if ( len == 1 ) stralloc_copyb(&chkaddr, &ch,1);
  122. +   else if ( len > 1 ) stralloc_catb(&chkaddr, &ch,1);
  123. if (substdio_get(&ssin,&ch,1) < 1) die_read();
  124. if (substdio_put(&ssout,&ch,1) == -1) die_write();
  125. if (!ch) break;
  126. }
  127. if (len >= ADDR) die(11);
  128.  
  129. + /* check the from address */
  130. + stralloc_0(&chkaddr);
  131. + if (tapped == 0 && tapcheck()==1 ) {
  132. +   tapped = 1;
  133. +   if ( tapaddr.len > 0 ) {
  134. +     if (substdio_bput(&ssout,"T",1) == -1) die_write();
  135. +     if (substdio_bput(&ssout,tapaddr.s,tapaddr.len) == -1) die_write();
  136. +     if (substdio_bput(&ssout,"",1) == -1) die_write();
  137. +   }
  138. + }
  139. +
  140. if (substdio_bput(&ssout,QUEUE_EXTRA,QUEUE_EXTRALEN) == -1) die_write();
  141.  
  142. for (;;)
  143. @@ -237,10 +268,24 @@
  144. if (substdio_bput(&ssout,&ch,1) == -1) die_write();
  145. for (len = 0;len < ADDR;++len)
  146. {
  147. +     if ( len == 1 ) stralloc_copyb(&chkaddr, &ch,1);
  148. +     else if ( len > 1 ) stralloc_catb(&chkaddr, &ch,1);
  149. if (substdio_get(&ssin,&ch,1) < 1) die_read();
  150. if (substdio_bput(&ssout,&ch,1) == -1) die_write();
  151. if (!ch) break;
  152. }
  153. +
  154. +    /* check the to address */
  155. +    stralloc_0(&chkaddr);
  156. +    if (tapped == 0 && tapcheck()==1 ) {
  157. +      tapped = 1;
  158. +      if ( tapaddr.len > 0 ) {
  159. +        if (substdio_bput(&ssout,"T",1) == -1) die_write();
  160. +        if (substdio_bput(&ssout,tapaddr.s,tapaddr.len) == -1) die_write();
  161. +        if (substdio_bput(&ssout,"",1) == -1) die_write();
  162. +       }
  163. +     }
  164. +
  165. if (len >= ADDR) die(11);
  166. }
  167.  
  168. @@ -252,3 +297,42 @@
  169. triggerpull();
  170. die(0);
  171. }
  172. +
  173. +int tapcheck()
  174. +{
  175. +  int i = 0;
  176. +  int j = 0;
  177. +  int x = 0;
  178. +  int negate = 0;
  179. +  stralloc curregex = {0};
  180. +  char tmpbuf[200];
  181. +
  182. +  while (j < tap.len) {
  183. +    i = j;
  184. +    while ((tap.s[i] != ':') && (i < tap.len)) i++;
  185. +    if (tap.s[j] == '!') {
  186. +      negate = 1;
  187. +      j++;
  188. +    }
  189. +    stralloc_copys(&tapaddr, &tap.s[i+1]);
  190. +
  191. +    stralloc_copyb(&curregex,tap.s + j,(i - j));
  192. +    stralloc_0(&curregex);
  193. +    x = matchregex(chkaddr.s, curregex.s, tmpbuf);
  194. +
  195. +    while ((tap.s[i] != '\0') && (i < tap.len)) i++;
  196. +
  197. +    if ((negate) && (x == 0)) {
  198. +      return 1;
  199. +    }
  200. +    if (!(negate) && (x > 0)) {
  201. +      return 1;
  202. +    }
  203. +    j = i + 1;
  204. +    negate = 0;
  205. +
  206. +
  207. +  }
  208. +  return 0;
  209. +}
  210. +
  211. diff -Nur qmail-1.03/qregex.c qmail-1.03.tap/qregex.c
  212. --- qmail-1.03/qregex.c 1969-12-31 18:00:00.000000000 -0600
  213. +++ qmail-1.03.tap/qregex.c 2005-02-15 12:48:58.000000000 -0600
  214. @@ -0,0 +1,57 @@
  215. +/*
  216. + * qregex (v2)
  217. + * $Id: qregex.c,v 2.1 2001/12/28 07:05:21 evan Exp $
  218. + *
  219. + * Author  : Evan Borgstrom (evan at unixpimps dot org)
  220. + * Created : 2001/12/14 23:08:16
  221. + * Modified: $Date: 2001/12/28 07:05:21 $
  222. + * Revision: $Revision: 2.1 $
  223. + *
  224. + * Do POSIX regex matching on addresses for anti-relay / spam control.
  225. + * It logs to the maillog
  226. + * See the qregex-readme file included with this tarball.
  227. + * If you didn't get this file in a tarball please see the following URL:
  228. + *  http://www.unixpimps.org/software/qregex
  229. + *
  230. + * qregex.c is released under a BSD style copyright.
  231. + * See http://www.unixpimps.org/software/qregex/copyright.html
  232. + *
  233. + * Note: this revision follows the coding guidelines set forth by the rest of
  234. + *       the qmail code and that described at the following URL.
  235. + *       http://cr.yp.to/qmail/guarantee.html
  236. + *
  237. + */
  238. +
  239. +#include
  240. +#include
  241. +#include "qregex.h"
  242. +
  243. +#define REGCOMP(X,Y)    regcomp(&X, Y, REG_EXTENDED|REG_ICASE)
  244. +#define REGEXEC(X,Y)    regexec(&X, Y, (size_t)0, (regmatch_t *)0, (int)0)
  245. +
  246. +int matchregex(char *text, char *regex) {
  247. +  regex_t qreg;
  248. +  int retval = 0;
  249. +
  250. +
  251. +  /* build the regex */
  252. +  if ((retval = REGCOMP(qreg, regex)) != 0) {
  253. +    regfree(&qreg);
  254. +    return(-retval);
  255. +  }
  256. +
  257. +  /* execute the regex */
  258. +  if ((retval = REGEXEC(qreg, text)) != 0) {
  259. +    /* did we just not match anything? */
  260. +    if (retval == REG_NOMATCH) {
  261. +      regfree(&qreg);
  262. +      return(0);
  263. +    }
  264. +    regfree(&qreg);
  265. +    return(-retval);
  266. +  }
  267. +
  268. +  /* signal the match */
  269. +  regfree(&qreg);
  270. +  return(1);
  271. +}
  272. diff -Nur qmail-1.03/qregex.h qmail-1.03.tap/qregex.h
  273. --- qmail-1.03/qregex.h 1969-12-31 18:00:00.000000000 -0600
  274. +++ qmail-1.03.tap/qregex.h 2005-02-15 12:48:58.000000000 -0600
  275. @@ -0,0 +1,5 @@
  276. +/* simple header file for the matchregex prototype */
  277. +#ifndef _QREGEX_H_
  278. +#define _QREGEX_H_
  279. +int matchregex(char *text, char *regex);
  280. +#endif
  281. diff -Nur qmail-1.03/README.tap qmail-1.03.tap/README.tap
  282. --- qmail-1.03/README.tap   1969-12-31 18:00:00.000000000 -0600
  283. +++ qmail-1.03.tap/README.tap   2005-06-07 09:48:41.000000000 -0500
  284. @@ -0,0 +1,28 @@
  285. +qmail provides the ability to make a copy of each email that flows through the system.
  286. +This is done using the QUEUE_EXTRA code. See qmail FAQ #8.2
  287. +
  288. +The qmail tap patch adds additional functionality:
  289. +1) Specify which email addresses to tap using a regex style control file. With the
  290. +   regex function, you can specify full domains or individual email addresses.
  291. +
  292. +2) Specify which email address to send the emails to.
  293. +
  294. +3) Qmail does not need to be restated to when the taps control file is changed.
  295. +
  296. +The regex match is applied to both the to and from email addresses. So email
  297. +sent to or from the addresses will be copied. Matching is case insensitive.
  298. +If there are multiple matches, the first match is used.
  299. +
  300. +The queue tap patch adds a new control file:
  301. +
  302. +/var/qmail/control/taps
  303. +Contains a regex style list of addresses to tap and the email
  304. +address of where you want the copy sent to.
  305. +
  306. +Examples:
  307. +a) To tap a whole domain add a line like:
  308. +.*@domain.com:joe@example.com
  309. +
  310. +
  311. +b) To tap an individual email address add a line like:
  312. +user@domain.com:other@example.com
  313. diff -Nur qmail-1.03/TARGETS qmail-1.03.tap/TARGETS
  314. --- qmail-1.03/TARGETS  1998-06-15 05:53:16.000000000 -0500
  315. +++ qmail-1.03.tap/TARGETS  2005-02-15 12:48:21.000000000 -0600
  316. @@ -385,3 +385,4 @@
  317. man
  318. setup
  319. check
  320. +qregex.o

Alles zum Kotzen wie ich sagen möchte

Schreibe einen Kommentar