<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook V3.1//EN"> 

<article>

<!-- Header -->

 <artheader>

  <!-- title of HOWTO, include the word HOWTO -->

  <title>Postfix-Cyrus-Web-cyradm-HOWTO</title>

  <author>
     <firstname>Luc</firstname>
     <surname>de Louw</surname>
     <affiliation>
        <address>
           <email>luc at delouw.ch</email>
        </address>
     </affiliation>
  </author>

<revhistory>

<revision>
        <revnumber>1.0.2</revnumber>
        <date>2002-05-08</date>
        <authorinitials>ldl</authorinitials>
        <revremark>
		Added basic description for sieve and correct sender handling, minor fixes to db related stuff, Added mysql-lookup for
                »mydestination« , fixed bug for builing postfix with mysqlsupport,
		Fixed the worldreadable private key, and some other minor bugs.
        </revremark>
</revision>

<revision>
	<revnumber>1.0.1</revnumber>
	<date>2002-04-07</date>
	<authorinitials>ldl</authorinitials>
	<revremark>
		Added an important fix for compiling pam_mysql
	</revremark>
</revision>

<revision>
	<revnumber>1.0.0</revnumber>
	<date>2002-04-07</date>
	<authorinitials>ldl</authorinitials>
	<revremark>
		Initial Release
	</revremark>
</revision>

      <!-- Additional (*earlier*) revision histories go here -->
   </revhistory>

  <abstract>
    <indexterm>
      <primary>Postfix and Cyrus</primary>
    </indexterm>

    <para>
	This document guides you through the installation of the Postfix mail transportation agent (MTA), 
	the Cyrus IMAP server. The goal is a fully functional high-performance 
	mailsystem with user-administration with Web-cyradm, a webinterface. Data like virtualusers, 
	aliases etc. are stored in a mysql database.
    </para>

  </abstract>

 </artheader>


<!-- Section1: intro -->

 <sect1 id="intro">
   <title>Introduction</title>

   <indexterm>
    <primary>disk!introduction</primary>
   </indexterm>

   <sect2>
	<title>Contributors and Contacts</title>
	<para>First I would thank all those people who send questions and suggestions that made a
	further development of this document possible. It shows me, sharing knowledge is the right way.
	I would encourage you to send me more suggestion, just write me an email <email>luc at delouw.ch</email>
	</para>
   </sect2>

   <sect2>
	<title>Why I wrote this document</title>

	<para>There are different approaches howto set up different mailsystems. Most documents available are
	related to Sendmail, procmail, WU-IMAPd and friends. These fine-running software is unfortunately very
	un-flexible concerning user administration.
	</para>

	<para>For longer time I was testing alternative MTA's like qmail, postfix and exim, IMAP/POP-servers like 
	Cyrus, vpopmail, Courier IMAP and others.</para>
	
	<para>At the end of the day, from my point of view the couple Postfix/Cyrus seems to be the
	most flexible and performant solution.</para>
	
	<para>All these combinations of software had one in common: there was only little documentation available
	concerning how this software is working together with each other.
	For installing the software, lot of effort must be spent to get all information needed to get all 
	software running.</para>
	
    </sect2>


<!-- Section2: copyright -->

  <sect2 id="copyright">
   <title>Copyright Information</title>

   <para>
    This document is copyrighted (c) 2002 Luc de Louw and is
    distributed under the terms of the Linux Documentation Project
    (LDP) license, stated below. 
   </para>

   <para>
    Unless otherwise stated, Linux HOWTO documents are
    copyrighted by their respective authors. Linux HOWTO documents may
    be reproduced and distributed in whole or in part, in any medium
    physical or electronic, as long as this copyright notice is
    retained on all copies. Commercial redistribution is allowed and
    encouraged; however, the author would like to be notified of any
    such distributions.
   </para>

   <para>
    All translations, derivative works, or aggregate works
    incorporating any Linux HOWTO documents must be covered under this
    copyright notice. That is, you may not produce a derivative work
    from a HOWTO and impose additional restrictions on its
    distribution. Exceptions to these rules may be granted under
    certain conditions; please contact the Linux HOWTO coordinator at
    the address given below.
   </para>

   <para>
    In short, we wish to promote dissemination of this
    information through as many channels as possible. However, we do
    wish to retain copyright on the HOWTO documents, and would like to
    be notified of any plans to redistribute the HOWTOs.
   </para>

   <para>
    If you have any questions, please contact 
    <email>linux-howto at metalab.unc.edu</email>
   </para>
  </sect2>

<!-- Section2: disclaimer -->

  <sect2 id="disclaimer">
   <title>Disclaimer</title>

   <para>
    No liability for the contents of this documents can be accepted.
    Use the concepts, examples and other content at your own risk.
    As this is a new edition of this document, there may be errors
    and inaccuracies, that may of course be damaging to your system.
    Proceed with caution, and although this is highly unlikely,
    the author(s) do not take any responsibility for that.
   </para>

   <para>
    All copyrights are held by their by their respective owners, unless
    specifically noted otherwise.  Use of a term in this document
    should not be regarded as affecting the validity of any trademark
    or service mark.
   </para>

   <para>
    Naming of particular products or brands should not be seen 
    as endorsements.
   </para>

   <para>
    You are strongly recommended to take a backup of your system 
    before major installation and backups at regular intervals.
   </para>
  </sect2>

<!-- Section2: newversions-->

  <sect2 id="newversions">
   <title>New Versions</title>

    <indexterm>
     <primary>(your index root)!news on</primary>
    </indexterm>

   <para>
    This is the initial release.
   </para>

   <para>New version of this document are announced on freshmeat</para>

   <para>
    The latest version of this document you can get from
    <ulink url="http://www.delouw.ch/linux">http://www.delouw.ch/linux</ulink> 
   </para>

   <para>
   <itemizedlist>
    <listitem>
     <para>
      <ulink url="http://www.delouw.ch/linux/Postfix-Cyrus-Web-cyradm-HOWTO/html/index.html">HTML</ulink>.
     </para>
    </listitem>

    <listitem>
     <para>
      <ulink url="http://www.delouw.ch/linux/Postfix-Cyrus-Web-cyradm-HOWTO/Postfix-Cyrus-Web-cyradm-HOWTO.ps">
	Postscript (ISO A4 format)</ulink>.
     </para>
    </listitem>

    <listitem>
     <para>
       <ulink URL="http://www.delouw.ch/linux/Postfix-Cyrus-Web-cyradm-HOWTO/Postfix-Cyrus-Web-cyradm-HOWTO.pdf">Acrobat PDF</ulink>.
     </para>
    </listitem>

    <listitem>
     <para>
       <ulink URL="http://www.delouw.ch/linux/Postfix-Cyrus-Web-cyradm-HOWTO/Postfix-Cyrus-Web-cyradm-HOWTO.sgml">SGML Source</ulink>.
     </para>
    </listitem>

    <listitem>
     <para>
      <ulink url="http://www.delouw.ch/linux/Postfix-Cyrus-Web-cyradm-HOWTO/Postfix-Cyrus-Web-cyradm-HOWTO.tar.gz">HTML gzipped tarball</ulink>.
     </para>
    </listitem>
   </itemizedlist>
   </para>

  </sect2>

<!-- Section2: credits -->

  <sect2 id="credits">
   <title>Credits</title>

   <para>
    I would thank to the nice people at <email> discuss at linuxdoc.org</email> for
    supporting me in writing HOWTOs
   </para>

  </sect2>

<!-- Section2: feedback -->

  <sect2 id="feedback">
   <title>Feedback</title>

   <para>
    Feedback is most certainly welcome for this document. Without
    your submissions and input, this document wouldn't exist. Please
    send your additions, comments and criticisms to the following
    email address : <email>luc at delouw.ch</email>.
   </para>
   </sect2>

<!-- Section2: translations -->

  <sect2 id="translations">
   <title>Translations</title>

   <para>
     	At the moment no translations are available. A german translation is planned and would be
     	written by myself as soon as the document is valid
   </para>

   <para>
	Translations to other languages are always welcome. If you translated this document, please let
	me know, so I can set a link here
   </para>

   </sect2>

 </sect1>

<!-- Section1: intro: END -->


<!-- Section1: Technologies  -->

 <sect1 id="tech">
  <title>Technologies</title>



  <sect2 id="postfix">
   <title>The Postfix MTA</title>
	<para>
	Quoting <ulink url="http://www.postfix.org">www.postfix.org</ulink>
	»Postfix attempts to be fast, easy to administer, and secure, while at the same time 
	being sendmail compatible enough to not upset existing users. Thus, the outside has a 
	sendmail-ish flavor, but the inside is completely different.«
	</para>
	<para>
		<figure>
	        <title>Postfix - the big picture</title>
      			<graphic FileRef="big-picture.png"></graphic>
     		</figure>
   	</para>

	<para>Doesn't it look impressive? - It looks much more complicated as it is. Postfix is indeed nice
	      to configure and handle</para>

	<para>Unlike sendmail, postfix is not one monolithic program, it is a compilation of small programs, each of
	      it has a specialized function. At this place I don't what to go into details with program does what.
	      If you are interested how Postfix is working, please see the documentation at 
	      <ulink url="http://www.postfix.org/docs.html">http://www.postfix.org/docs.html</ulink>
	</para>	

	<para>In this document you will find the information what to put in the config files</para>

  </sect2>

  <sect2 id="cyrus">
   <title>Cyrus IMAP</title>
	<para>The Cyrus IMAP is developed and maintained by Carnegie Mellon University.</para>

	<para>Unlike the WU-IMAPd Cyrus is using its own method to store the users mail. The data is stored 
	in a database, this makes Cyrus so performant. Especially with lots of users and/or lot of big emails, 
	there is nothing such fast as the Cyrus IMAP-server.</para>

	<para>
	Another very important feature is, you don't need a local Un*x user for each account. All users are 
	authenticated by the IMAP-Server. This makes it a great solution for really huge base of users.</para>

	<para>
	User administration is done by special IMAP-commands. This allows you to eighter use the commandline interface, 
	or use one of the available Webinterfaces. This Method is much more secure than a Webinterface to
	<filename> /etc/passwd</filename> !

	<para>
	Since CMU changed the license policy for Cyrus, this software is going to be used by much more users</para>

  </sect2>

  <sect2 id="mysql">
   <title>MySQL Database</title>
        <para>MySQL is a very fast, powerful and very nice to handle Database.</para>
	
	<para>Since Cyrus can authenticate its users with pam, you can use pam_mysql as a connector to the
	Userdatebase stored in MySQL. This allows you to create a nice Webinterface for your users for changing 
	passwords, define and delete aliases and more.</para>
	
  </sect2>

  <sect2 id="pam_mysql">
  <title>pam_mysql</title>
	
	<para>pam means "Pluggable authentication module" and was originally proposed by some people at Sun.
	In meantime a lot of modules have been developed. One of them is an interface to MySQL</para>

	<para>With pam_mysql you to store the users password in a mysql database. Further, Postfix is able to
	lookup aliases from a MySQL-table. At the end of the day, you have a base for all administrative tasks
	to be done by the Sysadmin.</para>
	
	<para>Further you will be able to delegate some tasks to Powerusers, e.g. creating Accounts for a particular
	Domain. Changing passwords and creating new aliases can be delegated to the user. At the end of the day 
	you as a Sysadmin have the time to do some more productive tasks, or write a HOWTO for the Linux 
	Documentation Project :-)</para>
  </sect2>	

  <sect2 id="web-cyradm">
   <title>Web-cyradm Webinterface</title>
	<para>
                <figure>
                <title>Web-cyradm Domain administration</title>
                        <graphic FileRef="home.png"></graphic>
                </figure>
        </para>

        <para>Web-cyradm is the Webinterface that allows you to perform the administrative tasks to your mailsystem
	This Screenshot shows the domain-administration part of Web-cyradm.</para>
	
	<para>Web-cyradm is written in PHP, which is often installed on webservers. Time to set up Web-cyradm takes just a
	few minutes.</para>
	
	<para>At the time being, Web-cyradm does not support different roles for its users. So you cannot use it as a
	frontend for your Powerusers (Domainadmins) or endusers. This Part of Web-cyradm is being developed, and should
	be ready for distribution in a few weeks (approx. end of may 2002.</para>

  </sect2>


 </sect1>

<!-- Section1: Technologies: END -->


<!-- Section1: Install -->

 <sect1 id="install">
  <title>Getting and installing the software</title>

	<para>
	Most of the software is included in your Linux distribution. SuSE is shipping Cyrus as far as I know since 7.1
	and Redhat at least since recent time. </para>
	
	<para>
	I suggest you to install Cyrus and SASL as binary from rpm. Postfix is needed to compile by yourself because
	the lack of MySQL support by the rpm's from the distributors. 

<!-- Section2: Mysql -->

  <sect2 id="MySQL-install">
   <title>Getting and installing MySQL</title>

	<sect3><title>Download</title>
		<para>
		Origin-Site: <ulink url="http://www.mysql.com/downloads/">http://www.mysql.com/downloads/</ulink>
		</para>
   	</sect3>

	<sect3><title>Building and installing</title>
<screen>
cd /usr/local
tar -xvzf mysql-3.23.49a.tar.gz
cd mysql-3.23.49a

./configure \
--prefix=/usr/local/mysql \
--enable-assembler \
--with-innodb

make
make install

/usr/local/mysql/bin/mysql_install_db
echo /usr/local/mysql/lib/mysql >> /etc/ld.so.conf
ldconfig
</screen>

	<para>For security-improvement add a mysql-user on your system i.e. "mysql", then</para>
	
<screen>
chown -R mysql /usr/local/mysql/var
</screen>
	<para>and change the line user=root to user=mysql in the file <filename>/usr/local/mysql/bin/safe_mysqld</filename>
	</para>

	<para>
	you may wish to start mysql automatically at boottime, copy 
	<filename>/usr/local/mysql/share/mysql/mysql.server</filename> to <filename>/etc/init.d/</filename>
	 for SuSE and Redhat. Further you need to add Symlinks to <filename>/etc/init.d/rc3.d</filename> 
	for SuSE and <filename>/etc/rc.d/rc3.d</filename>
	</para>

	<para>
	The following example is for SuSE Linux and should be easily changed for Redhat and other Linux distributions and
	commercial Unixes.
	</para>
	
<screen>
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/
ln -s /etc/init.d/mysql.server /etc/init.d/rc3.d/S20mysql
ln -s /etc/init.d/mysql.server /etc/init.d/rc3.d/k08mysql
</screen>

	</sect3>
   </sect2>


<!-- Section2: postfix -->

  <sect2 id="postfix-install">
   <title>Getting and installing Postfix</title>

	
	<sect3><title>Download</title>
                <para>
                Origin-Site: <ulink url="http://www.postfix.org/ftp-sites.html">http://www.postfix.org/ftp-sites.html</ulink>
                </para>
        </sect3>

	<sect3>	<title>Creating a User-ID (UID) and Group-ID (GID) for postfix</title>
	<para>
	Before you can build and install postfix you have to be sure a »postfix« and a »postdrop« groups and users 
	exists on the System. First check for the groups. You can check this 
	by <command>grep postfix /etc/group</command> and <command>grep maildrop /etc/group</command>
	</para>

	<para>
	If there are no such groups and users, you just create them. Search for a free nummeric UID and GID. In the 
	following example I will use UID and GID 33333 for Postfix and 33335 for the maildrop UID and GID. This ID's 
	are corresponding to other documents.
	</para>

<screen>
groupadd -g 33333 postfix
groupadd -g 33335 postdrop

useradd -u 33333 -g 33333 -d /dev/null -s /bin/false postfix
#useradd -u 33335 -g 33335 -d /dev/null -s /bin/false maildrop
</screen>

	</sect3>

	

	<sect3><title>Building and installing</title>

	<para>
	The following screen shows what you have to do, if you installed MySQL from source as described above.
	If you installed MySQL from a binary package such as rpm or deb, then you have to change the 
	include and library-flags to -I/usr/include/mysql and -L/usr/lib/mysql.  
	</para>
	
	

<screen>
tar -xvzf postfix-1.1.7.tar.gz

cd postfix-1.1.7

make -f Makefile.init makefiles \
'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include/mysql' \
'AUXLIBS=-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm'

make install
</screen>

	<para>During <command>make install</command> a few question are asked. Just pressing <keycap>Enter</keycap> should
	match your needs. For Redhat users it could be useful to enter <filename>/usr/local/share/man</filename></para>

	</sect3>
  </sect2>

<!-- Section2: cyrus -->

  <sect2 id="cyrus-install">
   <title>Getting and installing Cyrus IMAP</title>

   <sect3><title>Download and installing</title>

	<para>Like mentioned above, SuSE and Redhat are shipping Cyrus in their distributions. Just use 
	yast or the corresponding tool in Redhat.</para>

	<para>
	<itemizedlist>
    		<listitem>
     			<para>cyrus-imapd-devel-2.0.16-115
			</para>
		</listitem>

		<listitem>
                        <para>cyrus-sasl-1.5.24-157
                        </para>
                </listitem>

		<listitem>
                        <para>cyrus-sasl-gssapi-1.5.24-157
                        </para>
                </listitem>

		<listitem>
                        <para>cyrus-sasl-devel-1.5.24-157
                        </para>
                </listitem>	

                <listitem>
                        <para>perl-Cyrus-IMAP-2.0.16-115
                        </para>
                </listitem>

                <listitem>
                        <para>perl-Cyrus-SIEVE-acap-2.0.16-115
                        </para>
                </listitem>


                <listitem>
                        <para>perl-Cyrus-SIEVE-managesieve-2.0.16-115
                        </para>
                </listitem>

                <listitem>
                        <para>cyrus-imapd-2.0.16-115
                        </para>
                </listitem>

	</itemizedlist>
   	</para>

	<para>If you like, you can install it also on the commandline using:
<screen>
rpm -ihv (package-name).rpm
</screen>

	</para>

	<para>Be sure to use only the lastest available version, so check out the downloads-site of your distribution</para>

  </sect2>


  <sect2 id="pam_mysql-install">
  <title>Getting and installing pam_mysql</title>

	<sect3><title>Download</title>
		<para>Origin-Site: <ulink url="http://sourceforge.net/projects/pam-mysql/">
			http://sourceforge.net/projects/pam-mysql/</ulink>
		</para>

	</sect3>
	<sect3><title>Installing</title>

	<para>
	If you compiled MySQL by yourself, you need to create a syslink to the MySQL inludes and libraries
	</para>

<screen>
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
</screen>



<screen>
tar -xvzf pam_mysql-0.4.7.tar.gz

cd pam_mysql

make

cp pam_mysql.so /lib/security
</screen>		

	</sect3>


  <sect2 id="web-cyradm-install">
   <title>Getting and installing Web-cyradm</title>

	<sect3><title>Download</title>
                <para>
                Origin-Site: <ulink url="http://www.delouw.ch/linux/web-cyradm">http://www.delouw.ch/linux/web-cyradm</ulink>
                </para>
        </sect3>
        <sect3><title>Installing</title>

	<para>Web-cyradm is written in PHP. If you don't have a webserver with php installed, I like to refer to my 
	<ulink url="http://www.delouw.ch/linux/apache.phtml">Apache-Compile-HOWTO</ulink>. That document describes how to
	set up Apache with PHP and other modules</para>
	
<screen>
cd /usr/local/apache/htdocs

tar -xvzf web-cyradm-latest.tar.gz

touch /var/log/web-cyradm.log
chown nobody /var/log/web-cyradm.log
</screen>
	<para>After unpacking web-cyradm move it to a place in your webservers DocumentRoot</para>

	<para>This is all, now we need to configure the whole bunch of software</para>

        </sect3>

  </sect2>


 </sect1>

<!-- Section1: Install: END -->


<!-- Section1: configuration -->

 <sect1 id="configuration">
  <title>Configuration</title>

 <sect2 id="MySQL-config">
   <title>Configuring MySQL</title>

	<sect3 id="mysql_config_securing">
	<title>Securing MySQL</title>

	<para>Because you are using MySQL to authenticate users, you need to restrict network access to Port 3306.</para>
	<para>I suggest to just bind mysql to the loopback-interface 127.0.0.1. This makes sure nobody can connect to your
	MySQL-Daemon via the network.</para>

	<para>
	edit <filename>/etc/init.d/mysql.server</filename> and edit line 107 as following:</para>

	<para>Original line:</para>
<screen>
$bindir/safe_mysqld --datadir=$datadir --pid-file=$pid_file&
</screen>

	<para>Changed line:</para>
	
<screen>
$bindir/safe_mysqld --datadir=$datadir --pid-file=$pid_file \
--bind-address=127.0.0.1&
</screen>

	<para>(Re-)start your MySQL-Daemon by issuing <command>/etc/init.d/mysql.server start</command></para>

	<para>To ensure the configuration-change was successful issue: <command>netstat -an|grep LISTEN</command>. The 
	Output should be looking similar to this:</para>

<screen>
bond:~ # netstat -an|grep LISTEN
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN
</screen>
	</sect3>

	<sect3 id="Mysql_config_create_db">
		<title>Create the databases and tables</title>
		<para>Now we need to create the database and tables for postfix and web-cyradm and add a user to the 
		database</para>

		<para>
		Web-cyradm comes with two SQL-files: <filename>insertuser.sql</filename> and <filename>create.sql</filename>
		The first inserts the Database user to the database »mysql«, the second creates the database »mail« and
		the needed tables.


		<para>The password for the user »mail« in this example is »secret« please insert whatever 
		user and password you like</para>

		<para>
		First you must add the user by executing <command>/usr/local/mysql/bin/mysql &lt; insertuser.sql</command>
		After the new DB-user is successfully added, you need to reload mysql 
		with <command>mysqladmin reload</command>
		</para>


		<para>To create the needed tables in the database:</para>
<screen>
/usr/local/mysql/bin/mysql mail -u mail -p < \
/usr/local/apache/htdocs/web-cyradm/scripts/create.sql
</screen>

		<para>
		Now lets populate our tables, and insert the first admin-user. This user is needed to login
		to Web-cyradm
		</para>
		<para>
		Execute <command>/usr/local/mysql/bin/mysql mail -u mail -p</command> And type the following SQL query:
		</para>

<screen>
insert into adminuser (username, password) values ('admin', 'test');
</screen>

<para>Please note, this setup for web-cyradm is fully compatible with replex, another project. Please see  
<ulink url="http://www.replex.org">http://www.replex.org</ulink>
for more details.</para>

</sect3>	

  </sect2>

  <sect2 id="pam-config">
  <title>Configuring PAM</title>

  <para>Now we need to get sure that PAM knows how to authenticate the Cyrus users</para>

  <para>You have to create the file <filename>/etc/pam.d/imap</filename> with the following entries:</para>

<screen>
auth sufficient pam_mysql.so user=mail passwd=secret host=localhost db=mail table=accountuser usercolumn=username   passwdcolumn=password crypt=0

auth sufficient pam_unix_auth.so

account required pam_mysql.so user=mail passwd=secret host=localhost db=mail table=accountuser usercolumn=username passwdcolumn=password   crypt=0

account  sufficient       pam_unix_acct.so
</screen>

	<para>The lines containing pam_unix_auth.so and pam_unix_acct.so are only needed if you are 
	migrating from wu-IMAP to cyrus. This way the users can be authenticate with its old unix-password 
	and its new mysql-based password</para>

	<para>If you will use Cyrus also for POP-Service just <command>cp /etc/pam.d/imap /etc/pam.d/pop</command>
	</para>

<!-- Section2: postfix -->

  <sect2 id="postfix-config">
   <title>Configuring Postfix</title>

   <para>Postfix needs two major config files: <filename>main.cf</filename> and <filename>master.cf</filename>. Both needs
	now our attention.</para>

	<sect3><title>master.cf</title>
	<para>You need to change just one line:</para>
	<para>old: </para>
<screen>
flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user}
</screen>
   	<para>new: </para>
<screen>
flags= user=cyrus argv=/usr/cyrus/bin/deliver -r ${sender} -m ${extension} ${user}
</screen>

	<para>
	What affect that changes?
	</para>

	<para>
	A look to the cyrus man-pages <command>man deliver</command>clears that issue:
	</para>
	
	<para>
	The Postfix default setup uses a wrong path to the cyrus deliver, this ist the first change.
	The parameter »-r« Inserts a proper return path, without that mail rejected by sieve will be sent to cyrus at yourdomain.
	</para>

	</sect3>

	<sect3><title>main.cf</title>
	<para>Here you need to change some more things like hostname, relaying, alias-lookups etc.</para>

	<para>First change hostname:</para>
<screen>myhostname = foo.bar.org</screen>

<para>mydestination</para>
<para>Here you have to put all domainnames that are local (corresponding to sendmail's /etc/mail/sendmail.cw)
If you have multiple domains separate them with comma</para>

<para>FIXME: mysql-stuff to be tested</para>

<screen>
mydestination = foo.bar.org, example.com, furchbar-grausam.ch, 
 whatever.domain.tld, mysql:/etc/postfix/mysql-mydestination.cf
</screen>

<para>relayhost</para>

<para>Here you define where to deliver outgoing mails. If you do not provide any host. mails are delivered directly 
to the destination smtp host. Usually your relayhosts are your providers smtp-server </para>

<screen>relayhost = relay01.foobar.net relay02.foobar.net relay03.foobar.net</screen>

<para>mailtransport</para>

<para>Here you define how the mails accepted for local delivery should be handled. In our situation mails should be 
delivered by the cyrus delivery-program</para>

<screen>mailbox_transport = cyrus</screen>

<para>At the end of file you need to add:</para>
<screen>virtual_maps = hash:/etc/postfix/virtual, mysql:/etc/postfix/mysql-virtual.cf</screen>

<para>Outgoing addresses should be rewritten from i.e test0002 at domain to user.name at virtualhost.com. This is important 
if you like to use a webmail interface.
</para>

<screen>
sender_canonical_maps = mysql:/etc/postfix/mysql-canonical.cf 
</screen>


<para>Now you need to create the file <filename>/etc/postfix/mysql-virtual.cf</filename>: </para>
 
<screen>
#
# mysql config file for alias lookups on postfix
# comments are ok.
#

# the user name and password to log into the mysql server
hosts = localhost
user = mail
password = secret

# the database name on the servers
dbname = mail

# the table name
table = virtual

#
select_field = dest
where_field = alias
additional_conditions = and status = '1'
</screen>

<para>The file <filename>/etc/postfix/mysql-canonical.cf</filename>:</para>

<screen>
# mysql config file for canonical lookups on postfix
# comments are ok.
#

# the user name and password to log into the mysql server
hosts = localhost
user = mail
password = secret

# the database name on the servers
dbname = mail

# the table name
table = virtual
#
select_field = alias
where_field = username
# Return the first match only
additional_conditions = and status = '1' limit 1
</screen>

<para>
FIXME: to be tested... Finally the file <filename>/etc/postfix/mysql-mydestination.cf</filename>:
<para>

<screen>
# mysql config file for local domain (like sendmails sendmail.cw) lookups on postfix
# comments are ok.
#

# the user name and password to log into the mysql server
hosts = localhost
user = mail
password = secret

# the database name on the servers
dbname = mail

# the table name
table = domain
#
select_field = domain_name
where_field = domain_name
</screen>


</sect3> 

  </sect2>

<!-- Section2: cyrus -->

  <sect2 id="cyrus-config">
   <title>Configuring Cyrus IMAP</title>

   <para>There is only little changes needed. Edit <filename>/etc/imapd.conf</filename> and take care that the following 
	entry is done</para>

<screen>
    sasl_pwcheck_method: pam
</screen>

	<para>This tells the Cyrus IMAP to authenticate using PAM</para>

	<para>If you want to enable Cyrus' TLS/SSL facilities you have to create a certificate first. This requires an 
	OpenSSL installation</para>

<screen>
openssl req -new -nodes -out req.pem -keyout key.pem  
openssl rsa -in key.pem -out new.key.pem
openssl x509 -in req.pem -out ca-cert -req \
-signkey new.key.pem -days 999 

mkdir /var/imap

mv new.key.pem /var/imap/server.pem

chown cyrus:mail /var/imap/server.pem
chmod 600 /var/imap/server.pem # protection for the private key

echo tls_cert_file: /var/imap/server.pem >> /etc/imapd.conf
echo tls_key_file: /var/imap/server.pem >> /etc/imapd.conf

</screen>

	<para>You need to add the cyrus user to /etc/sasldb:</para>

<para>FIXME: Why is Unix-auth needed? subject to be investigated. Until further notice enable 
pam_unix_auth.so
</para>

<screen>
saslpasswd cyrus
passwd cyrus
</screen>


	<para>
	If you like to use sieve (A Mail Filtering Language), you must change an entry
	in <filename>/etc/services</filename>. Add or change the following line:
	</para>
	
<screen>
sieve           2000/tcp
</screen>

  </sect2>


  <sect2 id="web-cyradm-config">
   <title>Configuring Web-cyradm</title>

<para>You just need to do some changes in <filename>/usr/local/apache/htdocs/web-cyradm/config.inc.php</filename>

<screen>
cp   config.inc.php-dist config.inc.php

touch /var/log/web-cyradm-login.log
chown nobody /var/log/web-cyradm-login.log
</screen>

<para>Edit the file and change the password and databasename to the appropriate values</para>



  </sect2>

 </sect1>

<!-- Section1: config: END -->


<!-- Section1: test -->

 <sect1 id="test">
  <title>Testing the setup</title>

   <indexterm>
    <primary>(your index root)!implementation</primary>
   </indexterm>

<sect2 id="test-running">
<title>(Re-)Starting the daemons</title>

  <para>Now all the software has been installed and configured, lets do some testings now. First you have to (re-)start all
the daemons affected </para>

<itemizedlist>
    <listitem>
     <para>
	<command>postfix start</command>
     </para>
    </listitem>

    <listitem>
     <para>
        <command>/etc/init.d/cyrus start</command>
     </para>
    </listitem>

    <listitem>
     <para>
        <command>/etc/init.d/mysql.server start</command>
     </para>
    </listitem>

    <listitem>
     <para>
        <command>/usr/local/apache/bin/apachectl startssl</command>
     </para>
    </listitem>
</itemizedlist>

<para>Hopefully all daemons started without any complaints...</para>

<para>Now you can verify if the daemons are running properly by issuing <command>netstat -an|grep LISTEN</command>
<para>The output should look similar like that:</para>

<screen>
bond:~ # netstat -an|grep LISTEN
tcp        0      0 0.0.0.0:993             0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:995             0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:110             0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:143             0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:2000            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN
</screen>

<para>The port are assigned like this:</para>

<itemizedlist>
    <listitem>
     <para>
	993	imap-ssl
     </para>
    </listitem>


    <listitem>
     <para>
        995     pop3-ssl
     </para>
    </listitem>


    <listitem>
     <para>
        3306     mysql
     </para>
    </listitem>

    <listitem>
     <para>
        110     pop3
     </para>
    </listitem>

    <listitem>
     <para>
        143     imap
     </para>
    </listitem>

    <listitem>
     <para>
        2000     sieve
     </para>
    </listitem>


    <listitem>
     <para>
        80     http
     </para>
    </listitem>

    <listitem>
     <para>
        25     smtp
     </para>
    </listitem>

    <listitem>	
     <para>
        443     https
     </para>
    </listitem>

</itemizedlist>

</sect2>

<sect2 id="testing-web-cyradm">
<title>Testing Web-cyradm</title>

<para>Now you should be able to connect to <ulink url="http://localhost/web-cyradm/">http://localhost/web-cyradm/</ulink>
Login with the credentials defined before.</para>

<para>Define a Domainname and some accounts. Be sure the domainname belongs to your server. If not you have to fake it by 
enter the domain in <filename>/etc/hosts</filename>. The Domain must also be defined as local in 
<filename>/etc/postfix/main.cf</filename> (mydestination = domain)</para>

</sect2>


<sect2 id="testing-postfix">
<title>Testing postfix</title>

<para>Now we are going to write a mail:</para>

<screen>
telnet localhost 25
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail ESMTP Postfix

helo localhost
250 mail
mail from: luc at delouw.ch
250 Ok
rcpt to: rcpt to: luc at localhost
250 Ok

data
354 End data with &lt;CR&gt;&lt;LF&gt;.&lt;CR&gt;&lt;LF&gt;
some text
.
250 Ok: queued as B58E141D33

quit
</screen>

<para>If you see such a message, then all seems to work fine. Be sure to specify a recipients address you previously defined 
in the web-cyradm database</para>

<para>If you get an error like this:</para>

<screen>
rcpt to: luc at localhost
451 &lt;luc at localhost&gt;: Temporary lookup failure
</screen>

<para>Then eighter MySQL is not running, DB permission are not set properly or you 
miss-configured <filename>/etc/postfix/main.cf</filename>

<para>On any errors, I suggest to examine <filename>/var/log/mail</filename>. Often you will find some hints whats went wrong.
</para>

</sect2>

<sect2 id="testing-cyrus">
<title>Testing the IMAP and POP functionality</title>

<para>To make that kind of tests. you just need a mailclient like kmail or netscape
(Yes of course M$-Products are working as well) but in this example I'll using kmail</para>

<figure>
      <title>Creating a new account</title>
      <graphic FileRef="imap-account.png"></graphic>
</figure>

<para>If you enabled TLS/SSL, you may wish to test also the following:

<figure>
      <title>Testing TLS/SSL functionality</title>
      <graphic FileRef="imap-tls.png"></graphic>
</figure>

<para>If login fails, and you are sure, you typed the right password, take care that MySQL is running</para>


 </sect1>

<!-- Section1: test: END -->


<!-- Section1: moreinfo -->

 <sect1 id="moreinfo">
  <title>Further Information</title>

   <indexterm>
    <primary>(your index root)!information resources</primary>
   </indexterm>

  <para>
	Here you will find some other resources available in the internet
  </para>

<!-- Section2: newsgroups -->

  <sect2 id="newsgroups">
   <title>News groups</title>

    <indexterm>
     <primary>disk!information resources!news groups</primary>
    </indexterm>

   <para>Some of the most interesting news groups are:

    <itemizedlist>

     <listitem>
      <para>
       <ulink url="news:alt.comp.mail.postfix">alt.comp.mail.postfix</ulink>
      </para>
	<para>This is low traffic-group</para>
     </listitem>


     <listitem>
      <para>
       <ulink url="news:comp.mail.imap">comp.mail.imap</ulink>
      </para>
     </listitem>

    </itemizedlist>
   </para>

   <para>Maybe you also check out your country newsgroups e.g ch.comp.os.linux</para>

   <para>
    Most newsgroups have their own FAQ that are designed to answer most
    of your questions, as the name Frequently Asked Questions indicate.
    Fresh versions should be posted regularly to the relevant newsgroups.
    If you cannot find it in your news spool you could go directly to the
    <ulink url="ftp://rtfm.mit.edu/">FAQ main archive FTP site</ulink>.
    The WWW versions can be browsed at the 
    <ulink url="http://www.cis.ohio-state.edu/hypertext/faq/usenet/FAQ-List.html">FAQ
    main archive WWW site</ulink>.
   </para>
  </sect2>

<!-- Section2: maillists -->

  <sect2 id="maillists">
   <title>Mailing Lists</title>

    <indexterm>
     <primary>disk!information resources!mailing lists</primary>
    </indexterm>

   <sect3>
   <title><email>postfix-users at postfix.org</email></title>
   <para>
   Send an mail to <email>majordomo at postfix.org</email> with the content (not subject):
<screen>
subscribe postfix-users</screen> </para>
   <para>Before writing to the list, check out the archive: <ulink url="http://www.deja.com/group/mailing.postfix.users">
   http://www.deja.com/group/mailing.postfix.users</ulink></para>

  </sect3>

  <sect3>

   <title><email>info-cyrus at lists.andrew.cmu.edu</email></title>
   <para>Send an mail to <email>majordomo at lists.andrew.cmu.edu</email> with the content (not subject):
<screen>
subscribe info-cyrus</screen> </para>
   <para>Before writing to the list, check out the archive: 
   <ulink url="http://asg.web.cmu.edu/archive/index.php?mailbox=archive.info-cyrus">
   http://asg.web.cmu.edu/archive/index.php?mailbox=archive.info-cyrus </ulink></para> 

  </sect3>

  </sect2>

<!-- Section2: howto -->

  <sect2 id="howto">
   <title>HOWTO</title>

    <indexterm>
     <primary>disk!information resources!HOWTOs</primary>
    </indexterm>

   <para>
    These are intended as the primary starting points to get the
    background information as well as show you how to solve a
    specific problem. Some relevant HOWTOs are
    <Literal remap="tt"><ulink url="http://www.linuxdoc.org/HOWTO/Cyrus-IMAP.html">Cyrus-IMAP</ulink></Literal> and 
    <Literal remap="tt"><ulink url="http://www.linuxdoc.org/HOWTO/Apache-Compile-HOWTO/index.html</Literal>">
	Apache-Compile-HOWTO</ulink></Literal>.  The main site for these is the
    <ulink url="http://www.linuxdoc.org/">LDP archive</ulink>
   </para>

  </sect2>

<!-- Section2: local-res -->

  <sect2 id="local-res">
   <title>Local Resources</title>

    <indexterm>
     <primary>disk!information resources!local</primary>
    </indexterm>

   <para>
	Usually distributions installs some documentation to your system. As a standard they are
	located in <filename>/usr/share/doc/packages</filename></para>
	<para>The SuSE rpms of Cyrus contains a lot a such documentation.</para>
	<para>Postfix has some html-files in the source directory <filename>/usr/local/postfix-20010228-pl08/html</filename></para>
	<para>PAM comes also with lots of documentation in <filename>/usr/share/doc/packages/pam</filename></para>
	<para>The pam_mysql module has a readme with the size of 1670 bytes :-( </para>

<!-- Section2: web -->

  <sect2 id="web">
   <title>Web Sites</title>

    <indexterm>
     <primary>disk!information resources!WWW</primary>
    </indexterm>
    <indexterm>
     <primary>disk!information resources!web pages</primary>
    </indexterm>

   <para>
    There are a huge number of informative web sites available. By
    their very nature they change quickly so do not be surprised
    if these links become quickly outdated.
   </para>

   <para>
    A good starting point is of course the 
    <ulink url="http://www.linuxdoc.org/">Linux Documentation
    Project</ulink> home page, an information central for
    documentation, project pages and much more.
   </para>

   <para>
	To get more deepened information about Postfix, then <ulink url="http://www.postfix.org">www.postfix.org</ulink>
	would be the starting point.
   </para>

   <para>
    Please let me know if you have any other leads that can be 
    of interest.
   </para>
  </sect2>

 </sect1>

<!-- Section1: moreinfo: END -->

<!-- Section1: faq -->

 <sect1 id="faq">
  <title>Questions and Answers</title>

   <indexterm>
    <primary>(your index root)!FAQ</primary>
   </indexterm>
   <indexterm>
    <primary>(your index root)!frequently asked questions</primary>
   </indexterm>

  <para>
	Here I answer the questions which I got from users. If you don't find an answer feel free to contact me
</para>

  <para>
   <itemizedlist>
    <listitem>
     <para>
      Q: Why MySQL and not LDAP?
     </para>

     <para>
      A: Good question. LDAP is role-based and it would be indeed a better solution for such applications. Unfortunately LDAP
      is very hard to set up. You have to make proper schemes etc. MySQL is the way strait ahead, it is very easy to handle and 
      versatile. There is a PAM module available for LDAP, feel free to use it.
     </para>
    </listitem>

    <listitem>
     <para>
      Q: Why Postfix and not Qmail?
     </para>

     <para>
      A: Lots of people like to see such a setup with Qmail. The reason why is, Mysql-support is a hack and not in the
      included in the main source-tree. This could end up in a bad situation. Think if a security-hole is found in qmail
      and the patch does not work with the corrected version. Postfix is supporting MySQL natively. Another (personal) reason is
      that I find Postfix more sympatic (I don't know why)
     </para>
    </listitem>


    <listitem>
     <para>
      Q: I got a Error: "Temporary lookup failure"
     </para>

     <para>
      A: Postfix cannot look up the alias table. Must common failure is that MySQL is not running, or there is a authentication
      Error. Check <filename>/var/log/mail</filename> and <filename>/usr/local/mysql/var/&lt;hostname&gt;.err</filename>
      to track the error
     </para>
    </listitem>

    <listitem>
     <para>
      Q: Does this HOWTO also work on other platforms?
     </para>

     <para>
      A: Unsure. I personally compiled MySQL and Apache on AIX 4.3 and 5.1L (php does not run properly on AIX), 
      Solaris 6/7/8 and HP-UX. Cyrus, pam_mysql and cyrus I never tried. On Solaris there is maybe a chance to get pam_mysql 
      running. On AIX there is no PAM, but a similar mechanism. In short: Try it, and let me know if were successful
     </para>
    </listitem>

   </itemizedlist>

   <comment>
TO BE DONE
   </comment>

 </sect1>


</article>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-namecase-general:t
sgml-general-insert-case:lower
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:nil
sgml-parent-document:nil
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->

