1 AUTHOR: Hints Author <ivo at thecourtofeden dot org>
5 LICENSE: GNU Free Documentation License Version 1.2
7 SYNOPSIS: E-mail server based on Qmail and Cyrus IMAP
10 In this hint we install software that route email to a destination
11 user after it is scanned for viruses and spam. Multiple domains are possible
12 We also look at maintains backup and monitoring. This setup is tested on a
13 LFS-6 system kernel 2.6.5 glibc-2.3.3-20040326 nptl gcc-3.3.3.
22 Make sure there is an MX record in DNS to point mail for the virtual
23 domains to the host running qmail. (Mostly the DNS runs on the ISP side.)
25 This is what roughly happens:
27 Here is a mail to olaf@linuxfrombinary.org to your SMTP server.
28 The SMTP server wants to find out who is linuxfrombinary.org. The domain
29 part of that email address needs to be resolved in an ip address.
30 DNS ( Domain Name Server) is used to resolve the domain in an ip
31 address and point to a mail server that will accept connections.
32 An MX (Mail eXchange) record is used for that.
34 Now the mail is routed to your ip address for your mail server on port 25.
35 Port 25 is your SMTP port that listens for mail from your domains.
36 Your IP address can be your fixed DSL ip address or a connection on
37 your campus, or other fixed ip address connections to the internet. If you
38 behind masquerading you need to set up forwarding rules for both SMTP and
39 IMAP. It should be possible have a dynamic ip address domain name solution
40 on the internet from where you can host your mail server from dailup or isdn
50 3. Packet dependencies
54 4. Installation of Avmailgate
55 5. Installation of Qmail
56 6. Installation of Nail
57 7. Installation of Fcron
58 8. Installation of Procmail
59 9. Installation of SpamAssassin dependencies
60 10. Installation of Razor-agents-sdk
61 11. Installation of Razor-agents
62 12. Installation of SpamAssassin
63 13. Installation of F-Prot Antivirus
64 14. Installation of Distributed Checksum Clearinghouse
65 15. Installation of Anomy-sanitizer
66 16. Installation of Imap
67 17. Make templates directory's
68 18. Add domain example.com
70 20. Starting up all processes
71 21. Monitoring the processes
72 22. Migrating mail from backups
73 23. Interesting readings
82 http://www.sleepycat.com/update/snapshot/db-4.1.25.tar.gz
85 ftp://ftp.openssl.org/source/openssl-0.9.7d.tar.gz
87 Avmailgate: antivir-mailgate-2.0.2-5
88 http://www.hbedv.com/files/antivir/release/avlxmgt.tgz
90 The free license can be ordered here:
91 http://www.antivir.de/order/privreg/order_e.htm
94 http://cr.yp.to/software/qmail-1.03.tar.gz
95 http://ds9a.nl/qmail/moni.csi.hu/pub/glibc-2.3.1/qmail-1.03.errno.patch
96 http://ds9a.nl/qmail/moni.csi.hu/pub/glibc-2.3.1/qmail-1.03.qmail_local.patch
99 http://heanet.dl.sourceforge.net/sourceforge/nail/nail-10.7.tar.bz2
102 http://fcron.free.fr/fcron-2.9.4.src.tar.gz
105 http://www.procmail.org/procmail-3.22.tar.gz
108 http://razor.sourceforge.net/download/index.html
109 razor-agents-sdk-2.03.tar.gz
110 razor-agents-2.40.tar.gz
113 http://au2.spamassassin.org/released/Mail-SpamAssassin-2.63.tar.bz2
116 ftp://ftp.f-prot.com/pub/linux/fp-linux-ws-4.4.2.tar.gz
118 Distributed Checksum Clearinghouse:
119 http://www.rhyolite.com/anti-spam/dcc/source/dcc-dccm-1.2.47.tar.Z
122 http://mailtools.anomy.net/dist/anomy-sanitizer-1.67.tar.gz
125 ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-sasl-2.1.18.tar.gz
126 ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-imapd-2.2.3.tar.gz
133 First of all I wanna thank Gerard and all the others for providing
134 the platform where we do the stuff we do.
136 In this hint we setup a mail server that serve two virtual example domains
137 and have different example users per domain:
139 - linuxfromsource.org
141 - John the Ripper john@linuxfromsource.org
142 - Susie Summer susie@linuxfromsource.org
143 - Dirk Beekmans dirk@linuxfromsource.org
146 - linuxfrombinary.org
148 - Olaf Olsen olaf@linuxfrombinary.org
149 - Jennifer Loopneus jennifer@linuxfrombinary.org
150 - Pamela Andersom pamela@linuxfrombinary.org
152 John is the local administer so he gets the mail for root, postmaster and
153 himself. All the user names must be unique as each user has its own box so if
154 olaf have a email account on linuxfrombinary AND linuxfromsource he must
155 be the same person because its the same mailbox. And if Olaf opens his
156 mailbox he sees mail from both the domains. Comprende ?
158 There is also a cyrus user to administer the IMAP server daemon and the
159 mailboxes. But he got a password for both for unix and imap/sasl.
161 A mail user do not needs a unix password set to get mail. If one of the
162 mail users needs access on the mail server you give him a unix password
163 as well as the imap/sasl password.
165 I really like to know if you are using this setup. So drop me a mail
166 and send me some feedback on how thing can be better.
170 3. Packet dependencies
171 ======================
176 This is a default BLFS install
179 ../dist/configure --prefix=/usr \
183 make docdir=/usr/share/doc/db-4.1.25 instal
186 B. Open Secure Socket Layer
187 ---------------------------
189 This is a default BLFS install
190 Please add you own architecture after the -march switch
192 sed 's/^passwd/openssl-passwd/' doc/apps/passwd.pod \
193 > doc/apps/openssl-passwd.pod &&
194 rm doc/apps/passwd.pod &&
195 mv doc/crypto/{,openssl_}threads.pod &&
196 sed -i -e 's/-m486/-march=i686/' Configure &&
197 ./config --openssldir=/etc/ssl --prefix=/usr shared &&
198 make MANDIR=/usr/share/man &&
199 make MANDIR=/usr/share/man install &&
200 cp -r certs /etc/ssl &&
207 If any one know of other imap/mail deps, mail me, i have 40+ packs already
208 installed beyond lfs when i start building this server.
209 In /path/to/cyrus-imapd-2.2.3/doc/install-prereq.html you find them all.
213 4. Installation of Avmailgate
214 =============================
216 Avmailgate offers virus protection by having a daemon listening on port 25.
217 This is the SMTP port. When mail gets thru, it checks for viruses and
218 then it uses qmail's sendmail wrapper to inject the mail into the qmail queue.
220 The other option is to have qmail's smtp server started from (x)inetd and
221 listening on port xxx where avmailgate is forwarding virus checked mail to.
222 But this gives only more rules for the firewall when heres an other port open.
224 useradd -c 'Daemon User' -d /dev/null -g daemon -s /bin/false daemon
226 cd /usr/src/avmailgate-2.0.2-5/avmailgate
228 mkdir /usr/lib/AntiVir
229 cp vdf/antivir.vdf /usr/lib/AntiVir
230 chown daemon:daemon /usr/lib/AntiVir
231 chown daemon:daemon /usr/lib/AntiVir/antivir.vdf
233 cp bin/antivir /usr/lib/AntiVir
234 chown daemon:daemon /usr/lib/AntiVir/antivir
236 cp etc/avmailgate.conf /etc
237 cp etc/avmailgate.acl /etc
238 cp etc/antivir.conf /etc
240 --------------------------------------------------------------------------------
241 Edit /etc/avmailgate.conf # Here we say witch user and group
242 # avgate runs under and to use the
243 # sendmail wrapper from qmail that
244 # we install in the next section.
251 # ForwardTo /usr/lib/sendmail -oem -oi
258 ForwardTo /usr/sbin/sendmail -oem -oi
260 --------------------------------------------------------------------------------
261 Edit /etc/avmailgate.acl # We do this to prevent relaying to
262 # other domains than ours.
265 local: hbedv.com antivir.de
269 local: linuxfromsource.org linuxfrombinary.org
271 --------------------------------------------------------------------------------
273 cp bin/avgated /usr/sbin
274 cp bin/avgatefwd /usr/sbin
276 mkdir /var/spool/avmailgate
277 chown daemon.daemon /var/spool/avmailgate
278 chmod 700 /var/spool/avmailgate
279 cd /var/spool/avmailgate
283 chown daemon.daemon *
286 Goto: http://www.antivir.de/order/privreg/order_e.htm
287 fill in the form and you get a key mailed to you.
289 cp hbedv.key /usr/lib/AntiVir/avmgate.key
290 chown daemon.daemon /usr/lib/AntiVir/avmgate.key
292 In the fcron section we set the cron job for virus updates
294 cp init/rc.avgate /etc/rc.d/init.d/avgate
296 chmod 700 /etc/init.d/avgate
298 Adjust the Sxx and Kxx to your situation and it might be handy to start
299 it before you start qmail.
301 cd /etc/rc.d/rc0.d &&
302 ln -s ../init.d/avgate Kxxavgate &&
304 ln -s ../init.d/avgate Kxxavgate &&
306 ln -s ../init.d/avgate Kxxavgate &&
308 ln -s ../init.d/avgate Sxxavgate &&
310 ln -s ../init.d/avgate Sxxavgate &&
312 ln -s ../init.d/avgate Sxxavgate &&
314 ln -s ../init.d/avgate Kxxavgate
318 5. Installation of Qmail
319 ========================
321 A. Patching the source
322 ----------------------
324 As time progresses software change, except for qmail that sticks with
325 version number 1.0.3 for ages i guess ;) Well lets say that that
326 if you using glibc-2.3.1 or better, then qmail will not compile because
327 of an incompatible declaration of errno.
329 To compensate for that, we use the recommended patches found at:
331 http://ds9a.nl/qmail/moni.csi.hu/pub/glibc-2.3.1/
333 qmail-1.03.errno.patch
334 qmail-1.03.qmail_local.patch
338 patch -p1 < /path/to/qmail-1.03.errno.patch
339 patch -p1 < /path/to/qmail-1.03.qmail_local.patch
342 B. Create a working directory for Qmail and untar sources
343 ---------------------------------------------------------
346 mkdir /opt/qmail/alias &&
348 tar zxvpf qmail-1.03.tar.gz &&
352 C. Change the program parameters. Read the documentation for other
354 ------------------------------------------------------------------
364 Add: (Use your own architecture and compiler flags)
369 D. Create user and group ID's
370 -----------------------------
374 Add: (Use your own ID's if this is conflicting)
381 Add: (Use your own ID's if this is conflicting)
383 alias:x:1000:100::/opt/qmail/alias:
384 qmaild:x:1001:100::/opt/qmail:
385 qmaill:x:1002:100::/opt/qmail:
386 qmailp:x:1003:100::/opt/qmail:
387 qmailq:x:1004:110::/opt/qmail:
388 qmailr:x:1005:110::/opt/qmail:
389 qmails:x:1006:110::/opt/qmail:
396 If you use DNS response packets larger than 512 bytes
397 qmail 1.03 chokes on it sometimes.
402 static union { HEADER hdr; unsigned char buf[PACKETSZ]; } response;
405 static union { HEADER hdr; unsigned char buf[65536]; } response;
408 F. Final compilation and installation
409 -------------------------------------
414 G. Create the init script.
415 --------------------------
417 cat << EOF > /etc/rc.d/init.d/qmail
419 # Begin $rc_base/init.d/qmail
421 # Based on sysklogd script from LFS-3.1 and earlier.
422 # Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org
424 source /etc/sysconfig/rc
427 test -x /opt/qmail/rc || exit 0
431 echo -n "Starting Qmail... "
432 sh -cf '/opt/qmail/rc &'
437 echo -n "Stopping Qmail... "
438 killall -9 qmail-send
443 echo -n "Restarting Qmail... "
444 killall -HUP qmail-lspawn
445 killall -ALRM qmail-lspawn
450 echo "Usage: $0 {start|stop|restart}"
457 # End /etc/rc.d/init.d/qmail
461 H. Set up links and permissions
462 -------------------------------
464 chmod 700 /etc/rc.d/init.d/qmail
466 Adjust the Sxx and Kxx to your situation
468 cd /etc/rc.d/rc0.d &&
469 ln -s ../init.d/qmail Kxxqmail &&
471 ln -s ../init.d/qmail Kxxqmail &&
473 ln -s ../init.d/qmail Kxxqmail &&
475 ln -s ../init.d/qmail Sxxqmail &&
477 ln -s ../init.d/qmail Sxxqmail &&
479 ln -s ../init.d/qmail Sxxqmail &&
481 ln -s ../init.d/qmail Kxxqmail
484 ln -s /opt/qmail/bin/sendmail
490 Configuration of qmail can happen in many ways, read the documentation
491 on the different kinds of configurations. At the end of this document
492 there are sections which describe all the actions necessary to add a domain
493 or user. For now i explain the steps.
496 J. Editing the Qmail Control/Config files
497 -----------------------------------------
499 Editing the control files is tricky and I've spent lot's of time
500 fiddling around with it. Key thing to understand is that
501 the host and domain name have something to do with the canonicalized
502 name that is assigned to your link with the internet.
503 For the people that use a ppp or an adsl connection this is often
504 something like sdf23-2.dsl.blabla.com Please don't ask me why,
505 it works and if anyone has a good explanation mail me !!
507 One way of finding out is with the commands that come with bind
508 dig or nslookup you can also try to login on an other box, logout,
509 and than run to that other box login again and read: your last login
510 was on xxx.xxxx.xxxxx.org or do an chat session on that box. I know
511 it isn't elegant but it works ;-)
513 For now lets hack some qmail
515 --------------------------------------------------------------------------------
516 cat << EOF > /opt/qmail/rc
519 # Using splogger to send the log through syslog.
520 # Using qmail-local to deliver messages to Maildir by default.
522 exec env - PATH="/opt/qmail/bin:$PATH" \
523 qmail-start ./Maildir/ splogger qmail &
525 --------------------------------------------------------------------------------
527 chmod 700 /opt/qmail/rc
529 cd /opt/qmail/control
531 --------------------------------------------------------------------------------
533 Edit: me # This is the hostname of local server
537 <hostname> (example adsl32.net.xs4all.nl)
539 --------------------------------------------------------------------------------
541 Edit: virtualdomains # Specify virtual domains
545 linuxfromsource.org:source
546 linuxfrombinary.org:binary
548 --------------------------------------------------------------------------------
550 Edit: locals # Domains that should be treated as
555 localhost # The local name
556 adsl32.net.xs4all.nl # The canonicalized name
557 intern.net # An example local domain
559 --------------------------------------------------------------------------------
561 Edit: defaultdomain # Same as 'me' minus the first part
565 <domainname> (example net.xs4all.nl)
567 --------------------------------------------------------------------------------
569 Edit: smtpgreeting # Adjust to taste
573 Hi and welcome to this SMTP server
575 --------------------------------------------------------------------------------
577 Edit: rcpthosts # Important file to prevent relaying of
578 mail by outsiders, List all machines
579 and domains on the network that
580 allowed to relay mail on this server.
586 otherinterndomain.org
593 Make the aliases, John is a mortal user on the system who gets
594 administrative email eg for root and for bounced or failed messages.
595 The first three aliases are necessary. For each user an alias is a necessity.
596 and only needs the username
600 echo john > .qmail-mailer-daemon
601 echo john > .qmail-postmaster
602 echo john > .qmail-root
604 and further for all users:
606 echo <user> > .qmail-<user>
610 echo john > .qmail-john
613 K. Per user virtual domain config
614 ---------------------------------
615 Now we split up our users for the virtual domains. If new mail arrives it is
616 forwarded to the user in the first part of the email address. Lets say there
617 is mail for susie@linuxfromsource.org. The alias file .qmail-susie is used to
618 forward the mail to susie, '&user' means forward. The .qmail file in her home
619 directory now determine the faith of the message.
621 The file .qmail-default is used if all other usernames fails to have a
622 .qmail-<user> alias for it. For example 'zuzie@linuxfromsource.org'.
623 You can write one line that says: ./Maildir/ to .qmail-default.
624 Now unresolved mail is sitting in the /home/virt-dom/Maildir/new directory.
626 John is the local mail admin who loves to get the unresolved mail and therefore
627 we say &john to '.qmail-default'. Now John determine the faith of the message.
628 He either trash it of forward it to the appropriate recipient.
631 /opt/qmail/bin/maildirmake Maildir
632 echo '&john' > .qmail-default
633 echo '&john' > .qmail-postmaster
634 echo '&john' > .qmail-webmaster
635 echo '&john' > .qmail-root
636 echo '&john' > .qmail-john
637 echo '&susie' > .qmail-susie
638 echo '&dirk' > .qmail-dirk
639 chown -R source.mailuser .
643 /opt/qmail/bin/maildirmake Maildir
644 echo '&john' > .qmail-default
645 echo '&john' > .qmail-postmaster
646 echo '&john' > .qmail-webmaster
647 echo '&john' > .qmail-root
648 echo '&olaf' > .qmail-olaf
649 echo '&jennifer' > .qmail-jennifer
650 echo '&pamela' > .qmail-pamela
651 chown -R binary.mailuser .
654 And now for all users substitute <user> for the login name. Here comes the
655 filtering with procmail into play.
659 echo '| preline /usr/bin/procmail' > .qmail
661 Now make sure the permissions are set right.
663 chown -R <user>.mailuser <userdir>/ (for all users)
667 6. Installation of nail
668 =======================
670 This peace of software is used by internal processes such as
671 fcron. It a small command line utility for sending email.
673 ./configure --prefix=/usr \
674 --with-mailspool=/var/mail \
675 --with-sendmail=/usr/sbin/sendmail &&
679 ln -s /usr/bin/nail mail
683 7. Installation of fcron
684 ========================
686 This is a default BLFS install
688 Fcron is the program we use as scheduler for some virus update scripts.
689 Its a very handy program anyway so here we go.
692 A. Adding a new entry to the syslog
693 -----------------------------------
695 cat >> /etc/syslog.conf << "EOF"
696 # Begin fcron addition to /etc/syslog.conf
698 cron.* -/var/log/cron.log
703 /etc/rc.d/init.d/sysklogd reload
706 B. Setting up a fcron user and group.
707 -------------------------------------
709 Use your own id's when necessary
712 fcron:x:14:14::/dev/null:/bin/false
718 C. Configure and build fcron
719 ----------------------------
721 ./configure --without-sendmail --with-answer-all=no &&
726 D. Add init script to /etc/rc.d/init.d
727 --------------------------------------
729 cat > /etc/rc.d/init.d/fcron << "EOF"
731 # Begin $rc_base/init.d/fcron
733 # Based on sysklogd script from LFS-3.1 and earlier.
734 # Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org
741 echo "Starting fcron..."
746 echo "Stopping fcron..."
761 echo "Usage: $0 {start|stop|restart|status}"
766 # End $rc_base/init.d/fcron
769 E. Set up links and permissions
770 -------------------------------
772 chmod 700 /etc/rc.d/init.d/fcron
774 Adjust the Sxx and Kxx to your situation.
776 cd /etc/rc.d/rc0.d &&
777 ln -s ../init.d/fcron Kxxfcron &&
779 ln -s ../init.d/fcron Kxxfcron &&
781 ln -s ../init.d/fcron Kxxfcron &&
783 ln -s ../init.d/fcron Sxxfcron &&
785 ln -s ../init.d/fcron Sxxfcron &&
787 ln -s ../init.d/fcron Sxxfcron &&
789 ln -s ../init.d/fcron Kxxfcron
791 use this to start fron
793 /etc/init.d/fcron start
795 So if we want to make use of the scheduler do this
799 We add the entries we need when appropriate programs are installed.
803 25 0 * * * root /usr/lib/AntiVir/antivir --update -q
807 27 4,16 * * * /usr/f-prot/tools/check-updates.pl -cron
811 8. Installation of Procmail
812 ===========================
814 This is a default BLFS install.
816 We use procmail to filter the email and deliver it to the cyrus imap
819 make BASENAME=/usr install &&
824 9. Installation of SpamAssassin dependencies
825 ============================================
828 http://spamassassin.taint.org/dist/INSTALL
830 There are some perl-modules that not come with the presumed perl-5.8.3 standard
831 installation in LFS 5.1 or perl-5.8.3 in general.
833 SpamAssassin Razor Cyrus and probably more depends on perl, no worries there is
834 an easy way to update your system.
837 A. The direct internet way
838 --------------------------
839 When you are connected to the internet commence this as root:
844 A series of questions is asked and stores this information in:
845 /usr/lib/perl5/5.8.3/CPAN/Config.pm
847 if you get weird looping experiences say /usr/bin/wget --passive in
850 Now type this in the CPAN shell:
852 o conf prerequisites_policy ask
855 And now for ease of administration, install these optional perl modules.
858 install Term::ReadKey
861 install Term::ReadLine
863 i /Term::ReadLine::Gnu/
864 install Term::ReadLine::Gnu
866 i /Term::ReadLine::Perl/
867 install Term::ReadLine::Perl
870 What follows are dependences of SpamAssassin although it doesn't need it,
871 it makes life easyer ;)
880 If you are using a nptl system (LFS-6) you get an error during the test.
884 cd /where_ever/cpan/build/DB_File-1.808
888 Add -lpthread to the $LIBS variable
891 { $LIBS = '-ldb -lpthread' }
905 You can safely say yes to these dependencies:
918 You can safely say yes to these dependencies:
923 i /ExtUtils::MakeMaker/
924 install ExtUtils::MakeMaker
928 These are versions are installed.
933 ExtUtils-MakeMaker-6.21
941 Term-ReadLine-Gnu-1.14
942 Term-ReadLine-Perl-1.0203
946 Once the modules are installed you can read all about it by doing:
948 perldoc <name>::<name>
955 B. The local source tarball method, sometimes less troublesome
956 --------------------------------------------------------------
958 Untar any of the above modules archives and say:
967 10. Installation of Razor-agents-sdk
968 ====================================
977 11. Installation of Razor-agents
978 ================================
980 http://razor.sourceforge.net/docs/
982 Untar the razor-agents archive and say:
989 I got an error at the end of make install something like:
990 Digest::SHA1 object version 2.01 does not match bootstrap parameter 2.10
993 I did the amazingly following thing. I went to:
995 /where_ever/cpan/build/Digest-SHA1-2.10/
1001 Then i removed the source directory of razor-agents and untarred the
1002 tarball cleanly again. After that razor compiled clean.
1004 maybe you have to issue a:
1006 mv /man/man5/razor-* /usr/share/man/man5/
1009 Now proceed with executing:
1011 razor-client # creates symbolic links
1012 razor-admin -create # creates the razor home
1013 razor-admin -register # registers an account
1017 12. Installation of SpamAssassin
1018 ================================
1020 perl -MCPAN -e shell
1022 i /Mail::SpamAssassin/
1023 install Mail::SpamAssassin
1027 If you want to prevent spam checking from eg. user@domain.com you
1030 Edit /etc/mail/spamassassin/local.cf
1034 whitelist_from user@domain.com
1038 spamassassin -t < sample-nonspam.txt > nonspam.out
1039 spamassassin -t < sample-spam.txt > spam.out
1041 In the header of spam.out you find an spam indication.
1045 13. Installation of F-Prot Antivirus.
1046 =====================================
1048 This software is used by anomy mail sanitizer.
1052 tar xvfz /path/to/fp-linux-ws-4.4.2.tar.gz
1054 ln -fs /usr/f-prot/f-prot.sh bin/f-prot
1055 ln -fs /usr/f-prot/man_pages/f-prot.1 /usr/share/man/man1/
1056 ln -fs /usr/f-prot/man_pages/check-updates.pl.8 /usr/share/man/man8/
1058 chmod +x /usr/f-prot/f-prot
1059 chmod +x /usr/f-prot/tools/check-updates.pl
1062 vi /usr/f-prot/f-prot.sh
1065 exec /usr/local/f-prot/f-prot ${@+"$@"}
1068 exec /usr/f-prot/f-prot ${@+"$@"}
1071 vi /usr/f-prot/tools/check-updates.pl
1074 my $signatureDirectory = '/usr/local/f-prot/';
1077 my $signatureDirectory = '/usr/f-prot/';
1086 perl -MCPAN -e shell
1088 install Bundle::libnet
1092 In the cron section of this hint you find the appropriate entry.
1093 for now test the virus update script.
1095 /usr/f-prot/tools/check-updates.pl
1098 For more information see this:
1100 /usr/bin/f-prot -help
1104 14. Installation of Distributed Checksum Clearinghouse
1105 ======================================================
1107 This software is used by SpamAssassin
1111 The Distributed Checksum Clearinghouse or DCC is a cooperative, distributed
1112 system intended to detect "bulk" mail or mail sent to many people.
1114 add to /etc/passwd :
1116 bin:x:1:1:bin:/bin:/bin/sh
1118 ./configure --bindir=/usr/bin --mandir=/usr/man &&
1124 15. Installation of Anomy-sanitizer
1125 ===================================
1127 Anomy-sanitizer uses this perl library's, but they are already
1128 installed with a standard perl install.
1134 Untar the packet in /usr/src
1138 chmod 750 /usr/anomy
1139 mkdir /var/quarantine
1143 This whole section is used from the mail.txt hint.
1144 Its a good config so why not use it ?
1147 cat > /usr/anomy/anomy.conf << "EOF"
1148 # Configuration file for Anomy Sanitizer
1151 # Do not log to STDERR:
1154 # Don't insert log in the message itself:
1157 # Advertisement to insert in each mail header:
1158 header_info = X-Sanitizer: This mail was sanitized
1162 # Enable filename based policy decisions:
1165 # Protect against buffer overflows and null values:
1168 # Replace MIME boundaries with our own:
1171 # Fix invalid and ambiguous MIME boundaries, if possible:
1174 # Trust signed and/or encrypted messages:
1176 msg_pgp_warning = WARNING: Unsanitized content follows.\n
1178 # Defang shell scripts:
1181 # Defang active HTML:
1184 # Defang UUEncoded files:
1187 # Sanitize forwarded content too:
1190 # Testing? Set to 1 for testing, 0 for production:
1193 ## Warn user about unscanned parts, etc.
1196 # Force all parts (except text/html parts) to
1203 # Disable "score" based mail discarding:
1207 msg_file_drop = \n*****\n
1208 msg_file_drop += NOTE: An attachment named %FILENAME was deleted from
1209 msg_file_drop += this message because was a windows executable.
1210 msg_file_drop += Contact the system administrator for more information.
1213 ## File attachment name mangling rules:
1216 file_name_tpl = /var/quarantine/att-$F-$T.$$
1218 # Number of rulesets we are defining:
1220 file_default_policy = defang
1222 # Delete probably nasty attachments:
1223 file_list_1 = (?i)(winmail.dat)|
1224 file_list_1 += (\.(vb[se]|exe|com|cab|dll|ocx|msi|cmd|bat|pif|lnk|hlp|ms[ip]|reg|asd))$
1225 file_list_1_policy = drop
1226 file_list_1_scanner = 0
1228 # Allow known "safe" file types and those that can be
1229 # scanned by the downstream virus scanner:
1230 file_list_2 = (?i)\.(doc|dot|rtf|xls|ppt|xlw|jpg|gif|png|tiff?|txt|zip|tgz|gz)
1231 file_list_2_policy = accept
1232 file_list_2_scanner = 0
1234 # Any attachment not listed above gets renamed.
1239 16. Installation of Imap
1240 ========================
1242 A. Compile and install SASL
1243 ---------------------------
1245 If you have a LFS-6 system (linux-2.6.x glibc+nptl):
1247 export LDFLAGS="-lpthread"
1249 ./configure --prefix=/usr --disable-krb4 \
1254 chmod 4755 /usr/cyrus/deliver
1257 B. Create uid/gid for the cyrus admin
1258 -------------------------------------
1262 We assume a user of "cyrus" and a group of "mail",
1263 though any user and group name can be used.
1267 Add: (Use your own ID's if this is conflicting)
1269 cyrus:x:90:90:Imap-Server:/usr/cyrus:/bin/bash
1273 Add: (Use your own ID's if this is conflicting)
1282 C. Compile and install IMAP
1283 ---------------------------
1285 export CPPFLAGS="-I/usr/include/et"
1287 ./configure --prefix=/usr \
1290 --with-cyrus-user=cyrus \
1291 --with-cyrus-group=mail &&
1296 And install some tools
1298 cp -av tools/ /usr/cyrus
1299 rm -fr /usr/cyrus/tools/CVS
1300 chown -R cyrus.mail /usr/cyrus
1306 Add these two lines to your /etc/syslog.conf
1308 local6.debug -/var/log/imapd.log
1309 auth.debug -/var/log/auth.log
1311 touch /var/log/imapd.log
1313 The last 3 lines are only necessary if you use SSL
1314 Create /etc/imapd.conf
1316 cat > /etc/imapd.conf << "EOF"
1317 configdirectory: /var/imap
1318 partition-default: /var/spool/imap
1320 sasl_pwcheck_method: saslauthd
1321 allowanonymouslogin: no
1322 tls_ca_file: /var/imap/server.pem
1323 tls_cert_file: /var/imap/server.pem
1324 tls_key_file: /var/imap/server.pem
1328 E. Making the director's
1329 ------------------------
1331 mkdir /var/imap /var/spool/imap
1332 chown cyrus.mail /var/imap /var/spool/imap
1333 chmod 750 /var/spool/imap
1337 F. Making the imap structure
1338 ----------------------------
1344 chattr +S /var/spool/imap
1345 chattr +S /opt/qmail/queue
1347 When users are added do:
1353 G. Change Other files
1354 ---------------------
1356 Added to /etc/services although only imap/imaps is needed.
1357 This is what the manual recommends.
1373 H. Setting the cyrus user password for imap
1374 -------------------------------------------
1376 /usr/sbin/saslpasswd2 cyrus
1378 chown cyrus.mail /etc/sasldb2
1380 cd /usr/src/cyrus-imapd-2.2.3
1382 You can uncomment the things you don't like here
1384 cp master/conf/normal.conf /etc/cyrus.conf
1387 I. Getting SSL to work.
1388 -----------------------
1389 We already adapted the /etc/imapd.conf for SSL
1390 Its known that M$ Outlook and Netscape mail clients
1391 can handle SSL connections.
1395 openssl req -new -x509 -nodes -out /var/imap/server.pem -keyout \
1396 /var/imap/server.pem -days 365 &&
1397 chown cyrus.mail /var/imap/server.pem
1400 J. Making the init.d script.
1401 ----------------------------
1403 cat > /etc/rc.d/init.d/imapd << "EOF"
1405 # Begin $rc_base/init.d/imapd
1407 # Based on sysklogd script from LFS-3.1 and earlier.
1408 # Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org
1415 echo "Starting the IMAP server..."
1416 /usr/cyrus/bin/master &
1421 echo "Stopping the IMAP server..."
1422 killproc /usr/cyrus/bin/master
1426 echo "Reloading the IMAP server..."
1427 reloadproc /usr/cyrus/bin/master
1437 statusproc /usr/cyrus/bin/master
1441 echo "Usage: $0 {start|stop|reload|restart|status}"
1447 # End $rc_base/init.d/imapd
1450 Adjust the runlevel link numbers Kxx and Sxx to taste.
1452 chmod 700 /etc/rc.d/init.d/imapd &&
1454 cd /etc/rc.d/rc0.d &&
1455 ln -s ../init.d/imapd Kxximapd &&
1457 ln -s ../init.d/imapd Kxximapd &&
1459 ln -s ../init.d/imapd Kxximapd &&
1461 ln -s ../init.d/imapd Sxximapd &&
1463 ln -s ../init.d/imapd Sxximapd &&
1465 ln -s ../init.d/imapd Sxximapd &&
1467 ln -s ../init.d/imapd Kxximapd
1469 /etc/init.d/imapd start
1471 Well, if it works, you supposed to see this:
1474 Active Internet connections (servers and established)
1475 Proto Recv-Q Send-Q Local Address Foreign Address State
1476 tcp 0 0 *:imaps *:* LISTEN
1477 tcp 0 0 *:pop3s *:* LISTEN
1478 tcp 0 0 *:pop3 *:* LISTEN
1479 tcp 0 0 *:imap *:* LISTEN
1480 tcp 0 0 *:sieve *:* LISTEN
1482 You might only need imap or imaps , adjust this in /etc/cyrus.conf
1483 Comment out services that you don't want.
1486 K. Check configuration
1487 ----------------------
1489 Now lets see what works and what not.
1491 If you want to login with telnet to test you need to add:
1499 telnet localhost imap
1501 Test all the authentications possible and again fiddling with the
1502 /etc/imapd.conf wont hurt. Read the imapd.conf man page and just change the
1503 the config file, restart the daemon and:
1505 tail -f /var/log/imapd.log
1506 tail -f /var/log/sys.log
1507 tail -f /var/log/auth.log
1509 Now become the cyrus admin and test the various options.
1513 imtest -m login -p imap localhost
1514 imtest -m OTP -p imap localhost
1515 imtest -m DIGEST-MD5 -p imap localhost
1516 imtest -m CRAM-MD5 -p imap localhost
1518 Use this to bail out !!
1521 You can test STARTTLS by using imtest:
1523 imtest -t "" localhost
1526 L. Per User Imap Configuration
1527 ------------------------------
1529 This is the bare minimum to perform for each imap user you want to add.
1531 First become the cyrus administrator
1535 Use the cyradm program to administer the IMAP folders for each user.
1537 cyradm --auth login localhost
1539 localhost.localnet> cm user.john
1540 localhost.localnet> cm user.john.SPAM
1541 localhost.localnet> quit
1547 And set the imap password for john
1552 There are more things possible, but knowing to delete a mailbox is handy
1553 if you new to all this.
1555 Say to the access control list of the user john mailbox that the
1556 cyrus user may delete john's folders, this is not the default case.
1558 localhost.localnet> setaclmailbox user.john cyrus c
1560 localhost.localnet> deletemailbox user.john
1562 If you want to get into it do this:
1564 localhost.localnet> help
1567 authenticate, login, auth authenticate to server
1568 chdir, cd change current directory
1569 createmailbox, create, cm create mailbox
1570 deleteaclmailbox, deleteacl, dam remove ACLs from mailbox
1571 deletemailbox, delete, dm delete mailbox
1572 disconnect, disc disconnect from current server
1573 exit, quit exit cyradm
1574 help, ? show commands
1575 info display mailbox/server metadata
1576 listacl, lam, listaclmailbox list ACLs on mailbox
1577 listmailbox, lm list mailboxes
1578 listquota, lq list quotas on specified root
1579 listquotaroot, lqr, lqm show quota roots and quotas for mailbox
1580 reconstruct reconstruct mailbox (if supported
1581 renamemailbox, rename, renm rename (and optionally relocate) mailbox
1582 server, servername, connect show current server or connect to server
1583 setaclmailbox, sam, setacl set ACLs on mailbox
1584 setinfo set server metadata
1585 setquota, sq set quota on mailbox or resource
1586 version, ver display version info of current server
1590 17. Make templates directory's
1591 =============================
1592 A. Create a domain template directory
1593 -------------------------------------
1594 mkdir /etc/skel.domain
1596 /opt/qmail/bin/maildirmake Maildir
1599 B. Create a user template directory
1600 -----------------------------------
1601 touch /var/log/procmail.log
1602 chmod 666 /var/log/procmail.log
1604 mkdir /etc/skel.user
1607 echo '| preline /usr/bin/procmail' > .qmail
1609 cat > .procmailrc << "EOF"
1610 USER="<user>" # here you define the username
1611 PATH=/usr/bin:/bin:/usr/cyrus/bin:/usr/anomy/bin
1613 #VERBOSE=1 # uncomment these if you want to see
1614 #LOGABSTRACT=all # more what's happening in procmail.log
1615 LOGFILE="/var/log/procmail.log"
1616 SANE="deliver -a $USER -m user.$USER"
1620 #######################################################
1621 # FIRST: REMOVE THE LEADING "From " field #
1622 # Cyrus bombs if it sees a leading "From " (not #
1623 # to be confused with "From:"). By running sed #
1624 # as a filter we simply remove the first line without #
1625 # any real thought. #
1626 #######################################################
1631 # Anomy mail sanitizer
1634 | sanitizer.pl /usr/anomy/anomy.conf
1644 * ^X-Spam-Status: Yes
1648 # Empty To: From: Subject:
1663 # Porn Spam although you might wand to see those ;-)
1666 * ^Subject.*(\|<\pornography\>)
1670 * ^.*(\|<\pornography\>)
1674 # Example From spam traps although SpamAssassin should filter it.
1681 * ^From:.*(advertising|sales|offers|promotion|reply|request|theuseful)
1685 # Example Subject spam traps
1688 * ^Subject:.*\[ADV\]
1708 chmod 600 .procmailrc
1713 18. Add domain example.com
1714 ==========================
1716 A. Create a master user ID and home directory for the new domain
1717 ----------------------------------------------------------------
1718 useradd -c 'example.com' -g mailusers -m -k /etc/skel.domain example
1721 B. Edit /etc/avmailgate.acl
1722 ---------------------------
1723 Add domain name to local:
1724 local: linuxfromsource.org linuxfrombinary.org example.com
1727 C. Edit /opt/qmail/control/virtualdomains
1728 -----------------------------------------
1733 D. Edit /opt/qmail/control/rcpthosts
1734 ------------------------------------
1742 Users will not require a unix password set. So they become
1743 valid unix accounts without unix login.
1744 John is an admin because root is not supposed to get mail.
1746 This is roughly how stuff works.
1747 Mail is coming in for a domain, lets say pamela@linuxfrombinary.org.
1748 It's first put into a drop box /home/binary/Maildir/ and then processed
1749 further via .qmail-xxx files. These files contain a user name who is supposed
1750 to get the mail. The user has a .qmail file in his or her home directory
1751 which says what to do with the incoming mail. In this case pipe it to
1752 the program /usr/bin/procmail that filters the mail and send that to the
1753 /usr/cyrus/bin/deliver program which stores it in the IMAP boxes.
1758 useradd -c 'john' -g mailusers -m -k /etc/skel.user john
1761 B. Imap Configuration
1762 ---------------------
1764 cyradm --auth login localhost
1766 localhost.localnet> cm user.john
1767 localhost.localnet> cm user.john.SPAM
1768 localhost.localnet> quit
1775 C. Qmail Configuration
1776 ----------------------
1779 If John is one of these:
1780 echo john > .qmail-mailer-daemon
1781 echo john > .qmail-postmaster
1782 echo john > .qmail-root
1785 echo john > .qmail-john
1787 chown alias.qmail .qmail-john
1790 If John belongs to example.org:
1793 If John is one of these:
1794 echo '&john' > .qmail-default
1795 echo '&john' > .qmail-postmaster
1796 echo '&john' > .qmail-webmaster
1797 echo '&john' > .qmail-root
1800 echo '&john' > .qmail-john
1802 chown -R example.mailuser .
1806 D. Procmail configuration
1807 -------------------------
1811 Change <user> in john
1815 20. Starting up all processes
1816 =============================
1818 You should know how to make the links for the different run levels.
1819 Otherwise Gerard Beekmans has a guide where this issue is addressed.
1821 /etc/init.d/sysklogd restart
1822 /etc/init.d/avgate start
1823 /etc/init.d/qmail start
1824 /etc/init.d/imap start
1828 21. Monitoring the processes.
1829 =============================
1831 Oke just start mailing everyone from localhost and remote and
1832 have a terminal running with the following command:
1834 tail -f /var/log/mail.log
1836 tail -f /var/log/sys.log
1838 tail -f /var/log/imapd.log
1840 tail -f /var/log/procmail.log
1843 Active Internet connections (servers and established)
1844 Proto Recv-Q Send-Q Local Address Foreign Address State
1845 tcp 0 0 *:pop3 *:* LISTEN
1846 tcp 0 0 *:imap *:* LISTEN
1847 tcp 0 0 *:ssh *:* LISTEN
1848 tcp 0 0 *:smtp *:* LISTEN
1849 Active UNIX domain sockets (servers and established)
1850 Proto RefCnt Flags Type State I-Node Path
1851 unix 2 [ ACC ] STREAM LISTENING 16068 /var/imap/socket/lmtp
1853 If you wanna know WTF Qmail is doing:
1855 for reading the queue:
1856 /opt/qmail/bin/qmail-qread
1859 /opt/qmail/bin/qmail-qstat
1862 /opt/qmail/bin/qmail-showctl
1866 22. Migrating mail from backups.
1867 ================================
1869 Make a back up of the /var/spool/imap/user directory
1870 and the /var/imap/mailboxes.db on your existing mail server.
1871 If the Berkeley database version is different on the new system
1872 it might be wise to export mailboxes.db to a plain text version.
1877 tar cvpf user-backup.tar user/
1878 mv user-backup.tar /tmp
1880 Add to the backup /var/imap/mailboxes.db in plaintext format
1883 ctl_mboxlist -d > /tmp/mailboxes.txt
1888 tar uvpf user-backup.tar mailboxes.txt
1891 gzip -9 user-backup.tar
1893 Go to the new system and unpack the user folders and mailboxes.db
1894 Stop the Imap daemon.
1896 mv user-backup.tar.gz /tmp
1898 tar zxvpf /tmp/user-backup.tar.gz
1899 mv mailboxes.txt /tmp
1903 ctl_mboxlist -u -f /var/imap/mailboxes.db < /tmp/mailboxes.txt
1905 Now that all the old mailboxes are restored, we can rebuild the mailboxes.db.
1907 ctl_cyrusdb -r # rebuild the cyrus mailboxes database
1908 reconstruct # reconstruct mailboxes
1910 cyradm --auth login localhost # Use the admin console for cyrus-imap.
1911 Password: # Enter the imap/sasl password.
1912 localhost.localnet> lm # Check to see if mailboxes are restored.
1913 localhost.localnet> exit # Leave the cyrusadm console.
1915 exit # exit the cyrus user.
1917 Every user that has imap login access needs a entry in /etc/sasldb2 again
1918 So do this for every imap user on the new server.
1922 If you want a hint on reading a remote imap box with fetchmail on a client,
1923 compile fetchmail and procmail and put the following in a .fetchmailrc in your
1929 poll "linuxfromsource.org"
1935 mda "/usr/bin/procmail -d john"
1941 poll mail.linuxfromsource.org port 993
1951 poll mail.linuxfrombinary.org with proto imap:
1952 plugin "ssh %h /usr/cyrus/bin/imtest" auth ssh;
1953 user john is john here
1957 23. Interesting readings.
1958 =========================
1960 All this information didn't come to me in a dream. It's a combination of
1961 sources that I used. A little file that I used to log thing has grown into
1962 this hint and hopefully it's useful for others as well. Understanding e-mail
1963 by this hint is not gonna help you enough, you have to RTFM A LOT.
1965 So almost every software packet has a website.
1966 In the tarball there is a lot of information.
1967 Software installs a lot of man and info pages.
1970 http://linuxdoc.org/HOWTO/Cyrus-IMAP.html
1973 http://www.linuxjournal.com/article.php?sid=2313
1974 http://www.abiglime.com/webmaster/articles/cgi/062398.htm
1975 http://www.summersault.com/chris/techno/qmail/qmail-antispam.html
1976 http://sysadmin.oreilly.com/news/imap2_1000.html
1979 Google, Some ppl on #lfs, a friend enz
1981 Running Qmail - ISBN 0-672-31945-4 - Richard Blum - Sams Publishing 2000
1988 The author does not feel responsible for loss or destruction of data and
1989 mail due to typos and bad language. So if you wipe out you system or get your
1990 dog killed don't come to me to cry on my shoulder. Be a man/woman and take
1991 responsibility for your own actions. On the other hand if your are successful
1992 and want to contribute, throw a BIG bag of money to Gerard Beekmans, he deserves
1993 it. This is my contribution to LFS and improvements are welcome.
1997 * Jim Gifford <lfs-hints at jg555 dot com> for using the anomy.conf
2005 * Changed LFS version from 3 to 4
2006 * Added c-client to the list of prerequisites, there could be more deps !!
2007 * Moved Berkeley DB there as well and version updated from 3.0.1 -> 4.0.14
2008 * Moved cyrus-sasl-1.5.27 -> cyrus-sasl-2.1.9
2009 * Moved cyrus-imapd-2.0.16 -> cyrus-imapd-2.1.9
2010 * Added Transport Layer Security (TLS) support
2011 * Added Openssl 0.9.6g
2012 * Added Avmailgate 2.0.1.7
2015 * Added Procmail 3.22
2016 * Added SpamAssassin 2.43
2017 * Added Vipul's Razor v2.20 + sdk 2.20
2018 * Added F-prot Antivirus 3.12b
2019 * Added Distributed Checksum Clearinghouse 1.1.15
2020 * Added Anomy-sanitizer 1.55
2021 * Added Various comments and command improvements
2024 * Moved to new hint format
2025 * Changed LFS version from 4 to 5 and LFS 6 (nptl linux-2.6 udev).
2026 * Where possible made install commands the same as in BLFS.
2027 * Removed c-client because its a php dependency.
2028 * Made per user per domain sections.
2029 * Updated Berkeley DB 4.0.14 -> 4.1.25
2030 * Updated Openssl-0.9.6g -> 0.9.7d
2031 * Updated avmailgate-2.0.1.7 -> 2.0.2-5
2032 * Added 2 qmail patches for usage with glibc-2.3.1 or better.
2033 * Updated nail-10.0 -> 10.7
2034 * Updated fcron-2.0.0 -> 2.9.4
2035 * Updated razor-agents-2.20 -> 2.40
2036 * Updated Mail-SpamAssassin-2.43 -> 2.63
2037 * Updated f-prot_3.12b -> fp-linux-ws-4.4.2
2038 * Updated dcc-dccproc-1.1.15 -> dcc-dccm-1.2.47.tar.Z
2039 * Updated anomy-sanitizer-1.55 -> 1.67
2040 * Updated cyrus-sasl-2.1.9 -> 2.1.18
2041 * Updated cyrus-imapd-2.1.9 -> 2.2.3