lfs-uefi: fix efivar-37 FTBFS
[linux_from_scratch_hints.git] / qmail_cyrus.txt
blob3b6aba6f3199ccefc980b1dde4bd567ae988d407
1 AUTHOR: Hints Author <ivo at thecourtofeden dot org>
3 DATE: 2004-05-04
5 LICENSE: GNU Free Documentation License Version 1.2
7 SYNOPSIS: E-mail server based on Qmail and Cyrus IMAP 
9 DESCRIPTION:
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.
15 ATTACHMENTS:
16 none
18 PREREQUISITES:
20 A MX record in DNS
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
41    connections.
43 HINT:
45 TABLE OF CONTENTS
46 =================
48 1.  Sources
49 2.  Introduction
50 3.  Packet dependencies
51   A  Berkeley DB
52   B  Openssl
53   C  Others
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
69 19. Add user John
70 20. Starting up all processes
71 21. Monitoring the processes
72 22. Migrating mail from backups
73 23. Interesting readings
74 24. Legal Blurb
78 1. Sources
79 ==========
81 Berkeley DB: 
82 http://www.sleepycat.com/update/snapshot/db-4.1.25.tar.gz
84 Openssl:
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
93 Qmail:  
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
98 Nail:
99 http://heanet.dl.sourceforge.net/sourceforge/nail/nail-10.7.tar.bz2
101 Fcron:
102 http://fcron.free.fr/fcron-2.9.4.src.tar.gz
104 Procmail:
105 http://www.procmail.org/procmail-3.22.tar.gz
107 Razor:
108 http://razor.sourceforge.net/download/index.html
109 razor-agents-sdk-2.03.tar.gz
110 razor-agents-2.40.tar.gz
112 SpamAssassin:
113 http://au2.spamassassin.org/released/Mail-SpamAssassin-2.63.tar.bz2
115 F-Prot Antivirus:
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
121 Anomy-sanitizer:
122 http://mailtools.anomy.net/dist/anomy-sanitizer-1.67.tar.gz
124 IMAP/SASL:
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
130 2. Introduction
131 ===============
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
145       
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 ======================
173 A. Berkeley DB
174 --------------
176 This is a default BLFS install
178 cd build_unix &&
179 ../dist/configure --prefix=/usr \
180   --enable-compat185 \
181   --enable-cxx &&
182   make &&
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 &&
201 rmdir /etc/ssl/lib
204 C. Other deps
205 -------------
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
239                 
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.
246 Change:
248 # User                            uucp 
249 # Group                           uucp
251 # ForwardTo /usr/lib/sendmail -oem -oi
255   User                            daemon
256   Group                           daemon
258   ForwardTo /usr/sbin/sendmail -oem -oi
259   
260 --------------------------------------------------------------------------------
261 Edit /etc/avmailgate.acl               # We do this to prevent relaying to 
262                                        # other domains than ours.
263 Change:
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 
280 mkdir incoming 
281 mkdir outgoing 
282 mkdir rejected 
283 chown daemon.daemon * 
284 chmod -R 700 * 
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 &&
303 cd ../rc1.d &&
304 ln -s ../init.d/avgate Kxxavgate &&
305 cd ../rc2.d &&
306 ln -s ../init.d/avgate Kxxavgate &&
307 cd ../rc3.d &&
308 ln -s ../init.d/avgate Sxxavgate &&
309 cd ../rc4.d &&
310 ln -s ../init.d/avgate Sxxavgate &&
311 cd ../rc5.d &&
312 ln -s ../init.d/avgate Sxxavgate &&
313 cd ../rc6.d &&
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
336 Example:
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 ---------------------------------------------------------
345 mkdir /opt/qmail &&
346 mkdir /opt/qmail/alias &&
347 cd /usr/src &&
348 tar zxvpf qmail-1.03.tar.gz &&
349 cd qmail-1.03 &&
352 C. Change the program parameters. Read the documentation for other
353    modifications 
354 ------------------------------------------------------------------
356 vi conf-qmail 
358 Add :
360 /opt/qmail
362 vi conf-cc
364 Add: (Use your own architecture and compiler flags)
366 gcc -O3 -march=i686
369 D. Create user and group ID's
370 -----------------------------
372 vi /etc/group
374 Add: (Use your own ID's if this is conflicting)
376 nofiles:x:100:
377 qmail:x:110:
379 vi /etc/passwd
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:
391 pwck && grpck 
394 E. DNS Hack
395 -----------
396 If you use DNS response packets larger than 512 bytes
397 qmail 1.03 chokes on it sometimes. 
399 vi +24 dns.c
401 And change:
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 -------------------------------------
411 make setup check
414 G. Create the init script.
415 --------------------------
417 cat << EOF > /etc/rc.d/init.d/qmail
418 #!/bin/bash
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
425 source $rc_functions
427 test -x /opt/qmail/rc || exit 0
429 case "$1" in
430  start)
431   echo -n "Starting Qmail...  "
432   sh -cf '/opt/qmail/rc &'
433   evaluate_retval
434  ;;
436  stop)
437   echo -n "Stopping Qmail... "
438   killall -9 qmail-send
439   evaluate_retval
440  ;;
442  restart)
443   echo -n "Restarting Qmail... "
444   killall -HUP qmail-lspawn
445   killall -ALRM qmail-lspawn
446   evaluate_retval
447  ;;
449  *)
450   echo "Usage: $0 {start|stop|restart}"
451   exit 1
452   
453 esac
455 exit 0
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 &&
470 cd ../rc1.d &&
471 ln -s ../init.d/qmail Kxxqmail &&
472 cd ../rc2.d &&
473 ln -s ../init.d/qmail Kxxqmail &&
474 cd ../rc3.d &&
475 ln -s ../init.d/qmail Sxxqmail &&
476 cd ../rc4.d &&
477 ln -s ../init.d/qmail Sxxqmail &&
478 cd ../rc5.d &&
479 ln -s ../init.d/qmail Sxxqmail &&
480 cd ../rc6.d &&
481 ln -s ../init.d/qmail Kxxqmail
483 cd /usr/sbin &&
484 ln -s /opt/qmail/bin/sendmail
487 I. Note
488 -------
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 -----------------------------------------
498    
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 
517 #!/bin/sh
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
535 Add:
537 <hostname> (example adsl32.net.xs4all.nl)
539 --------------------------------------------------------------------------------
541 Edit: virtualdomains                   # Specify virtual domains 
543 Add:
545 linuxfromsource.org:source
546 linuxfrombinary.org:binary
548 --------------------------------------------------------------------------------
550 Edit: locals                           # Domains that should be treated as 
551                                          locals
553 Add:
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 
563 Add:
565 <domainname> (example net.xs4all.nl)
567 --------------------------------------------------------------------------------
569 Edit: smtpgreeting                     # Adjust to taste
571 Add:
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.
582 Add:
584 linuxfrombinary.org
585 linuxfromsource.org
586 otherinterndomain.org
587 internhost1
588 internhost2
590 chmod 644 *
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
598 cd /opt/qmail/alias
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>
608 eg 
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.
630 cd /home/source
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 .
640 chmod 640 .qmail-*
642 cd /home/binary
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 .
652 chmod 640 .qmail-*
654 And now for all users substitute <user> for the login name. Here comes the 
655 filtering with procmail into play. 
657 cd /home/<user>
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 &&
676 make &&
677 make install && 
678 cd /usr/bin &&
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
700 # End fcron addition
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
711 vi /etc/passwd
712 fcron:x:14:14::/dev/null:/bin/false
714 vi /etc/group
715 fcron:x:14:
718 C. Configure and build fcron
719 ----------------------------
721 ./configure --without-sendmail --with-answer-all=no &&
722 make &&
723 make install
726 D. Add init script to /etc/rc.d/init.d
727 --------------------------------------
729 cat > /etc/rc.d/init.d/fcron << "EOF"
730 #!/bin/sh
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
736 . /etc/sysconfig/rc
737 . $rc_functions
739 case "$1" in
740         start)
741                 echo "Starting fcron..."
742                 loadproc fcron
743                 ;;
745         stop)
746                 echo "Stopping fcron..."
747                 killproc fcron
748                 ;;
750         restart)
751                 $0 stop
752                 sleep 1
753                 $0 start
754                 ;;
756         status)
757                 statusproc fcron
758                 ;;
760         *)
761                 echo "Usage: $0 {start|stop|restart|status}"
762                 exit 1
763                 ;;
764 esac
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 &&
778 cd ../rc1.d &&
779 ln -s ../init.d/fcron Kxxfcron &&
780 cd ../rc2.d &&
781 ln -s ../init.d/fcron Kxxfcron &&
782 cd ../rc3.d &&
783 ln -s ../init.d/fcron Sxxfcron &&
784 cd ../rc4.d &&
785 ln -s ../init.d/fcron Sxxfcron &&
786 cd ../rc5.d &&
787 ln -s ../init.d/fcron Sxxfcron &&
788 cd ../rc6.d &&
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
797 fcrontab -e -u root
799 We add the entries we need when appropriate programs are installed.
801 Avmailgate:
803 25 0 * * * root /usr/lib/AntiVir/antivir --update -q
805 F-prot Antivirus:
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
817 system.
819 make BASENAME=/usr install &&
820 make install-suid
824 9. Installation of SpamAssassin dependencies
825 ============================================
827 read:
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:
841 perl -MCPAN -e shell
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
848 the questions asked.
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.
857 i /Term::ReadKey/
858 install Term::ReadKey
860 i /Term::ReadLine/
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 ;)
873 i /HTML::Parser/
874 install HTML::Parser
876 i /DB_File/
877 install DB_File
880 If you are using a nptl system (LFS-6) you get an error during the test.
881 Proceed as follows:
883 quit
884 cd /where_ever/cpan/build/DB_File-1.808
885 make clean
886 vi Makefile.PL
888 Add  -lpthread to the $LIBS variable
889 so line 28 reads:
891       { $LIBS = '-ldb  -lpthread' }
893 perl Makefile.PL
894 make 
895 make test
896 make install
898 And continue:
900 perl -MCPAN -e shell
902 i /Mail::Audit/
903 install Mail::Audit
905 You can safely say yes to these dependencies:
907     Mail::Mailer
908     MIME::Entity
909     Mail::Internet
910     IO::Stringy
911       
912 i /Net::SMTP/
913 install Net::SMTP
915 i /Net::DNS/
916 install Net::DNS
918 You can safely say yes to these dependencies:
920    Digest::HMAC_MD5
921    Digest::SHA1
922    
923 i /ExtUtils::MakeMaker/
924 install ExtUtils::MakeMaker
926 quit
928 These are versions are installed.
930 DB_File-1.808
931 Digest-HMAC-1.01
932 Digest-SHA1-2.10
933 ExtUtils-MakeMaker-6.21
934 HTML-Parser-3.36
935 HTML-Tagset-3.03
936 IO-stringy-2.109
937 MIME-tools-5.411
938 Mail-Audit-2.1
939 MailTools-1.62
940 Net-DNS-0.47
941 Term-ReadLine-Gnu-1.14
942 Term-ReadLine-Perl-1.0203
943 TermReadKey-2.21
944 libnet-1.18
946 Once the modules are installed you can read all about it by doing:
948 perldoc <name>::<name> 
952 perldoc Mail::Audit
955 B. The local source tarball method, sometimes less troublesome
956 --------------------------------------------------------------
958 Untar any of the above modules archives and say:
960 perl Makefile.PL
961 make
962 make test
963 make install
967 10. Installation of Razor-agents-sdk
968 ====================================
970 perl Makefile.PL
971 make
972 make test
973 make install
974                                           
977 11. Installation of Razor-agents
978 ================================
979 Read: 
980 http://razor.sourceforge.net/docs/
982 Untar the razor-agents archive and say:
984 perl Makefile.PL
985 make
986 make test
987 make install
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
991 at blablabla 
993 I did the amazingly following thing. I went to:
995 /where_ever/cpan/build/Digest-SHA1-2.10/
997 and issue a:
999 make install
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/
1007 rm -fr /man
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
1025 quit
1027 If you want to prevent spam checking from eg. user@domain.com you 
1028 only have to this:
1030 Edit /etc/mail/spamassassin/local.cf
1032 Add:
1034 whitelist_from user@domain.com
1037 Test it
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.
1050 cd /usr
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
1064 Change:
1065 exec /usr/local/f-prot/f-prot ${@+"$@"}
1067 To: 
1068 exec /usr/f-prot/f-prot ${@+"$@"}
1071 vi /usr/f-prot/tools/check-updates.pl
1073 Change:
1074 my $signatureDirectory = '/usr/local/f-prot/';
1076 to: 
1077 my $signatureDirectory = '/usr/f-prot/';
1080 And test it.
1082 f-prot -verno
1084 f-prot /etc/passwd
1086 perl -MCPAN -e shell
1088 install Bundle::libnet
1089 install Bundle::LWP
1090 install IO
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
1109 From the man page:
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 &&
1119 make &&
1120 make install
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.
1130 MIME::Base64 
1131 MIME::QuotedPrint 
1134 Untar the packet in /usr/src
1136 cd /usr/src 
1137 mv anomy /usr
1138 chmod 750 /usr/anomy
1139 mkdir /var/quarantine
1140 chown -R 0.0 anomy
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:
1152 feat_log_stderr = 0
1154 # Don't insert log in the message itself:
1155 feat_log_inline = 0
1157 # Advertisement to insert in each mail header:
1158 header_info = X-Sanitizer: This mail was sanitized
1159 header_url = 0
1160 header_rev = 0
1162 # Enable filename based policy decisions:
1163 feat_files = 1
1165 # Protect against buffer overflows and null values:
1166 feat_lengths = 1
1168 # Replace MIME boundaries with our own:
1169 feat_boundaries = 1
1171 # Fix invalid and ambiguous MIME boundaries, if possible:
1172 feat_fixmime = 1
1174 # Trust signed and/or encrypted messages:
1175 feat_trust_pgp = 1
1176 msg_pgp_warning = WARNING: Unsanitized content follows.\n
1178 # Defang shell scripts:
1179 feat_scripts = 0
1181 # Defang active HTML:
1182 feat_html = 1
1184 # Defang UUEncoded files:
1185 feat_uuencoded = 0
1187 # Sanitize forwarded content too:
1188 feat_forwards = 1
1190 # Testing? Set to 1 for testing, 0 for production:
1191 feat_testing = 0
1193 ## Warn user about unscanned parts, etc.
1194 feat_verbose = 1
1196 # Force all parts (except text/html parts) to
1197 # have file names.
1198 feat_force_name = 1
1200 # Disable web bugs:
1201 feat_webbugs = 1
1203 # Disable "score" based mail discarding:
1204 score_panic = 0
1205 score_bad = 0
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:
1219 file_list_rules = 2
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 \
1250    --with-gnu-ld &&
1251 make &&
1252 make install
1254 chmod 4755 /usr/cyrus/deliver
1257 B. Create uid/gid for the cyrus admin
1258 -------------------------------------
1260 mkdir /usr/cyrus
1262 We assume a user of "cyrus" and a group of "mail",
1263 though any user and group name can be used. 
1265 vi /etc/passwd
1267    Add: (Use your own ID's if this is conflicting)
1269 cyrus:x:90:90:Imap-Server:/usr/cyrus:/bin/bash
1271 vi /etc/group
1273    Add: (Use your own ID's if this is conflicting)
1275 mail:x:90:daemon
1277 passwd cyrus &&
1279 pwck && pwconv
1282 C. Compile and install IMAP
1283 ---------------------------
1285 export CPPFLAGS="-I/usr/include/et"
1287 ./configure --prefix=/usr \
1288  --with-auth=unix \
1289  --without-krb \
1290  --with-cyrus-user=cyrus \
1291  --with-cyrus-group=mail &&
1292 make depend &&
1293 make all &&
1294 make install
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
1303 D. Configuring IMAP
1304 -------------------
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
1319 admins: cyrus
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 
1334 chmod 750 /var/imap
1337 F. Making the imap structure
1338 ----------------------------
1340 su - cyrus
1341 tools/mkimap
1342 exit 
1344 chattr +S /var/spool/imap
1345 chattr +S /opt/qmail/queue
1347 When users are added do:
1349 cd /var/imap
1350 chattr -R +S user/*
1352                   
1353 G. Change Other files
1354 ---------------------
1356 Added to /etc/services although only imap/imaps is needed.
1357 This is what the manual recommends.
1359    pop3      110/tcp
1360    nntp      119/tcp
1361    imap      143/tcp
1362    imsp      406/tcp
1363    nntps     563/tcp
1364    acap      674/tcp
1365    imaps     993/tcp
1366    pop3s     995/tcp
1367    kpop      1109/tcp
1368    sieve     2000/tcp
1369    lmtp      2003/tcp
1370    fud       4201/udp
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.
1393 Type this:
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"
1404 #!/bin/bash
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
1410 . /etc/sysconfig/rc
1411 . $rc_functions
1413 case "$1" in
1414  start)
1415   echo "Starting the IMAP server..."
1416   /usr/cyrus/bin/master &
1417   evaluate_retval
1418   ;;
1420  stop)
1421   echo "Stopping the IMAP server..."
1422   killproc /usr/cyrus/bin/master
1423   ;;
1425  reload)
1426   echo "Reloading the IMAP server..."
1427   reloadproc /usr/cyrus/bin/master
1428   ;;
1430  restart)
1431   $0 stop
1432   sleep 1
1433   $0 start
1434   ;;
1436  status)
1437   statusproc /usr/cyrus/bin/master
1438   ;;
1440  *)
1441   echo "Usage: $0 {start|stop|reload|restart|status}"
1442   exit 1
1443   ;;
1445 esac
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 &&
1456 cd ../rc1.d &&
1457 ln -s ../init.d/imapd Kxximapd &&
1458 cd ../rc2.d &&
1459 ln -s ../init.d/imapd Kxximapd &&
1460 cd ../rc3.d &&
1461 ln -s ../init.d/imapd Sxximapd &&
1462 cd ../rc4.d &&
1463 ln -s ../init.d/imapd Sxximapd &&
1464 cd ../rc5.d &&
1465 ln -s ../init.d/imapd Sxximapd &&
1466 cd ../rc6.d &&
1467 ln -s ../init.d/imapd Kxximapd
1469 /etc/init.d/imapd start
1471 Well, if it works, you supposed to see this:
1473 netstat -vat
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:
1493 allowplaintext yes 
1495 to /etc/imapd.conf
1497 Now try:
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.
1511 su - cyrus
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 !!
1519 . logout
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
1533 su - cyrus 
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
1543 Become root again
1545 exit
1547 And set the imap password for john
1549 saslpasswd2 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
1595 cd /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
1606 cd /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
1612 SHELL=/bin/bash
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"
1617 SPAM="$SANE.SPAM"
1618 ANOMY=/usr/anomy
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   #######################################################
1629 | sed 1d
1631 # Anomy mail sanitizer
1633 :0fw
1634 | sanitizer.pl /usr/anomy/anomy.conf
1637 # Spam Assassin
1639 :0fw
1640 * < 256000
1641 | spamassassin
1644 * ^X-Spam-Status: Yes
1645 | $SPAM
1648 # Empty To: From: Subject:
1651 * !^To:
1652 | $SPAM
1655 * !^From:
1656 | $SPAM
1659 * !^Subject:
1660 | $SPAM
1663 # Porn Spam although you might wand to see those ;-)
1666 * ^Subject.*(\|<\pornography\>)
1667 | $SPAM
1669 :0 B
1670 * ^.*(\|<\pornography\>)
1671 | $SPAM
1674 # Example From spam traps although SpamAssassin should filter it.
1677 * ^FROM_advertising
1678 | $SPAM
1681 * ^From:.*(advertising|sales|offers|promotion|reply|request|theuseful)
1682 | $SPAM
1685 # Example Subject spam traps
1688 * ^Subject:.*\[ADV\]
1689 | $SPAM
1692 * ^Subject:\ ADV
1693 | $SPAM
1696 # Else
1697    
1699 | $SANE 
1703 EXITCODE=$?
1704 HOST
1708 chmod 600 .procmailrc
1709 chmod 600 .qmail
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 -----------------------------------------
1729 Add:
1730 example.com:example
1733 D. Edit /opt/qmail/control/rcpthosts
1734 ------------------------------------
1735 Add:
1736 example.com
1740 19. Add user John
1741 =================
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.
1756 A. The unix account
1757 -------------------
1758 useradd -c 'john' -g mailusers -m -k /etc/skel.user john
1761 B. Imap Configuration
1762 ---------------------
1763 su - cyrus 
1764 cyradm --auth login localhost
1766 localhost.localnet> cm user.john
1767 localhost.localnet> cm user.john.SPAM
1768 localhost.localnet> quit
1770 exit
1772 saslpasswd2 john
1775 C. Qmail Configuration
1776 ----------------------
1777 cd /opt/qmail/alias
1779 If John is one of these:
1780 echo john > .qmail-mailer-daemon
1781 echo john > .qmail-postmaster
1782 echo john > .qmail-root
1784 Otherwise:
1785 echo john > .qmail-john
1787 chown alias.qmail .qmail-john
1790 If John belongs to example.org:
1791 cd /home/example
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
1799 Otherwise:
1800 echo '&john'       > .qmail-john
1802 chown -R example.mailuser .
1803 chmod 640 .qmail-*
1806 D. Procmail configuration
1807 -------------------------
1808 cd /home/john/
1809 vi .procmailrc
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
1839 or 
1840 tail -f /var/log/procmail.log
1842 netstat -vat
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
1858 for statistics:
1859 /opt/qmail/bin/qmail-qstat
1861 for information:
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.
1875 cd /var/spool/imap
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
1882 su - cyrus
1883 ctl_mboxlist -d > /tmp/mailboxes.txt
1884 exit 
1887 cd /tmp
1888 tar uvpf user-backup.tar mailboxes.txt
1889 rm 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
1897 cd /var/spool/imap
1898 tar zxvpf /tmp/user-backup.tar.gz 
1899 mv mailboxes.txt /tmp
1901 su - cyrus
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.
1920 saslpasswd2 <user>
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
1924 home dir and do 
1926 fetchmail -v
1928 <snip>
1929 poll "linuxfromsource.org"
1930 protocol imap
1931 no envelope
1932 no dns
1933 username "john"
1934 password "xxxx"
1935 mda "/usr/bin/procmail -d john"
1936 </snip>
1940 <snip>
1941 poll mail.linuxfromsource.org port 993 
1942 protocol IMAP:
1943 user john
1944 password secret
1946 </snip>
1950 <snip>
1951 poll mail.linuxfrombinary.org with proto imap:
1952 plugin "ssh %h /usr/cyrus/bin/imtest" auth ssh;
1953 user john is john here
1954 </snip>
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.
1969 The HOWTO:
1970 http://linuxdoc.org/HOWTO/Cyrus-IMAP.html
1972 Some article's:
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
1985 24. Legal Blurb
1986 ==============
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.
1996 ACKNOWLEDGMENTS:
1997   * Jim Gifford <lfs-hints at jg555 dot com> for using the anomy.conf
1999 CHANGELOG:
2001 [2001-12-15] v 1.0
2002   * Initial commit
2003   
2004 [2002-10-16] v 1.1
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
2013   *  Added Nail 10.0
2014   *  Added Fcron 2.0.0 
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
2022   
2023 [2004-05-04] v 1.2
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