/[gentoo]/xml/htdocs/doc/en/virt-mail-howto.xml
Gentoo

Contents of /xml/htdocs/doc/en/virt-mail-howto.xml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.24 - (hide annotations) (download) (as text)
Sun Feb 8 08:02:20 2004 UTC (10 years, 8 months ago) by swift
Branch: MAIN
Changes since 1.23: +14 -3 lines
File MIME type: application/xml
#36356 - Fix security issue with the various mysql-*.cnf configuration files

1 zhen 1.3 <?xml version = '1.0' encoding = 'UTF-8'?>
2 swift 1.24 <!-- $Header: /home/cvsroot/gentoo/xml/htdocs/doc/en/virt-mail-howto.xml,v 1.23 2004/01/07 15:15:11 swift Exp $ -->
3 swift 1.16 <!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
4    
5 zhen 1.3 <guide link=" /doc/en/virt-mail-howto.xml" >
6 zhen 1.1 <title>Virtual Mailhosting System Guide</title>
7 zhen 1.3 <author title="Author" >
8 antifa 1.9 <mail link="antifa@gentoo.org" >Ken Nowack</mail>
9 zhen 1.3 </author>
10     <author title="Author" >
11 antifa 1.9 <mail link="ezra@revoltltd.org" >Ezra Gorman</mail>
12 zhen 1.3 </author>
13 klasikahl 1.22 <author title="Editor">
14     <mail link="klasikahl@gentoo.org" >Zack Gilburd</mail>
15     </author>
16 zhen 1.1 <abstract>This document details how to create a virtual mailhosting system based upon postfix, mysql, courier-imap, and cyrus-sasl. </abstract>
17 swift 1.24 <version>1.0.9</version>
18     <date>February 8, 2004</date>
19 zhen 1.3 <!--
20    
21     Contents
22    
23     I. Introduction
24     II. Postfix Basics
25     III. Courier-imap
26     IV. Cyrus-sasl
27     V. SSL Certificates for Postfix and Apache
28     VI. Adding SSL and SASL support to Postfix
29     VII. MySQL
30     VIII. Apache and phpMyAdmin
31     IX. The vmail user
32     X. Configuring MySQL Authentication and vhosts
33     XI. Squirrelmail
34     XII. Mailman
35     XIII. Content Filtering and Anti-Virus
36     XIV. Wrap Up
37     XV. Troubleshooting
38 zhen 1.1
39 zhen 1.3 --><chapter>
40 zhen 1.1 <title>Introduction</title>
41 zhen 1.3 <body>
42     <p>For most gentoo users, a simple mail client and fetchmail will do. However, if you're hosting a domain with your system, you'll need a full blown MTA (Mail Transfer Agent). And if you're hosting multiple domains, then you'll definitely need something more robust to handle all of the email for your users. This system was designed to be an elegant solution to that problem.</p>
43     <p>A virtual mail system needs to be able to handle email for numerous domains with multiple users over a variety of interfaces. This presents some issues that must be dealt with. For instance, what if you have two users on different domains that want the same user name? If you are providing imap access and smtp-auth, how do combine the various authentication daemons into a single system? How do you provide security for the numerous components that comprise the system? How do you manage it all?</p>
44     <p>This howto will show you how to set up with a mail system capable of handling mail for as many domains as your hardware can handle, supports virtual mail users that don't require shell accounts, has domain specific user names, can authenticate web, imap, smtp, and pop3 clients against a single database, utilizes ssl for transport layer security, has a web interface, can handle mailing lists for any domain on the machine, and is controlled by a nice, central and easy mysql database. </p>
45 vapier 1.7 <p>There are quite a variety of ways to go about setting up a virtual mailhosting system. With so may options, another may be the best choice for your specific needs. Consider investigating <uri>http://www.qmail.org/</uri> and <uri>http://www.exim.org/</uri> to explore your options. </p>
46 zhen 1.3 <p>The following packages are used in this setup:
47 zhen 1.1
48 swift 1.17 apache, courier-imap, pam_mysql, postfix, mod_php, phpmyadmin, squirrelmail, cyrus-sasl, mysql, php, and mailman.</p>
49 zhen 1.3 <p>Make sure to turn on the following USE variables in <path>/etc/make.conf</path> before compiling the packages: <c>USE=&quot;mysql imap libwww maildir sasl ssl&quot;</c>. Otherwise you will most likely have to recompile things to get the support you need for all the protocols. Further, it's a good idea to turn off any other mail and network variables, like ipv6.</p>
50 swift 1.8 <impo>This howto was written for postfix-2.0.x. If you are using postfix &lt; 2 some of the variables in this document will be different. It is recommended that you upgrade. Some other packages included in this howto are version sensitive as well. You are advised to read the documentation included with packages if you run into issues with this.</impo>
51 antifa 1.12 <impo>This document uses apache-1.3.x. Apache-2 has been marked stable in portage. However there are still a number of issues with php integration. Until php support in apache-2.0.x is marked stable, this guide will continue to use the 1.3.x version.</impo>
52 zhen 1.3 <impo>You need a domain name to run a public mail server, or at least an MX record for a domain. Ideally you would have control of at least two domains to take advantage of your new virtual domain functionality.</impo>
53     <impo>Make sure <path>/etc/hostname</path> is set to the right hostname for your mail server. Verify your hostname is set correctly with <c>hostname</c>. Also verify that there are no conflicting entries in <path>/etc/hosts</path>.</impo>
54     <note>It is recommended that you read this entire document and familiarize yourself with all the steps before attempting the install. If you run into problems with any of the steps, check the troubleshooting guide at the end of this document. Also, not all the referenced packages are necessary, this set up is very flexible. For instance, if you do not desire a web interface, feel free to skip the squirrelmail section.</note>
55     </body>
56 zhen 1.1 </chapter>
57     <chapter>
58     <title>Postfix Basics</title>
59 zhen 1.3 <body>
60     <pre caption="Install postfix" ># <i>emerge postfix</i>
61     </pre>
62     <warn>Verify that you have not installed any other MTA, such as ssmtp, exim, or qmail, or you will surely have BIG problems.</warn>
63     <p>After postfix is installed, it's time to configure it. Change the following options in <path>/etc/postfix/main.cf</path>:</p>
64     <pre caption="/etc/postfix/main.cf" >
65 rajiv 1.14 myhostname = $host.domain.name
66     mydomain = $domain.name
67     inet_interfaces = all
68     mydestination = $myhostname, localhost.$mydomain $mydomain
69     mynetworks = my.ip.net.work/24, 127.0.0.0/8
70     home_mailbox = .maildir/
71     local_destination_concurrency_limit = 2
72     default_destination_concurrency_limit = 10 </pre>
73 zhen 1.3 <p>Next change the following in <path>/etc/postfix/master.cf</path>. This will turn on verbose output for debugging:</p>
74     <pre caption="/etc/postfix/master.cf" >
75 rajiv 1.14 # service type private unpriv chroot wakeup maxproc command + args
76     # (yes) (yes) (yes) (never) (50)
77     #
78     ==========================================================================
79     smtp inet n - n - - smtpd -v
80    
81     <codenote>Just add the <c>-v</c> after the smtpd in the above line</codenote>
82 zhen 1.3 </pre>
83     <p>Next, edit <path>/etc/mail/aliases</path> to add your local aliases. There should at least be an alias for root like: <c>root: your@email.address</c>.</p>
84     <pre caption="Starting postfix for the first time" >
85 rajiv 1.14 # <i>/usr/bin/newaliases</i>
86 zhen 1.3 <codenote>This will install the new aliases. You only need to do this </codenote>
87     <codenote>when you update or install aliases.</codenote>
88    
89 rajiv 1.14 # <i>/etc/init.d/postfix start</i>
90 zhen 1.3 </pre>
91     <p>Now that postfix is running, fire up your favorite console mail client and send yourself an email. I use <c>mutt</c> for all my console mail. Verify that postfix is delivering mail to local users, once that's done, we're on to the next step.</p>
92     <note>I strongly recommend that you verify this basic postfix setup is functioning before you progress to the next step of the howto. </note>
93     </body>
94 zhen 1.1 </chapter>
95     <chapter>
96     <title>Courier-imap</title>
97 zhen 1.3 <body>
98     <pre caption="Install courier-imap" ># <i>emerge courier-imap</i>
99     </pre>
100     <pre caption="Courier-imap configuration" >
101 rajiv 1.14 # <i>cd /etc/courier-imap</i>
102 zhen 1.3 <codenote>If you want to use the ssl capabilities of courier-imap or pop3, </codenote>
103     <codenote>you'll need to create certs for this purpose.</codenote>
104     <codenote>This step is recommended. If you do not want to use ssl, skip this step.</codenote>
105 rajiv 1.14
106     # <i>nano -w pop3d.cnf</i>
107     # <i>nano -w imapd.cnf</i>
108 zhen 1.3 <codenote>Change the C, ST, L, CN, and email parameters to match your server.</codenote>
109 rajiv 1.14
110     # <i>mkpop3dcert</i>
111     # <i>mkimapdcert</i>
112 zhen 1.3 </pre>
113     <pre caption="Start the courier services you need." >
114 rajiv 1.14 # <i>/etc/init.d/courier-imapd start</i>
115     # <i>/etc/init.d/courier-imapd-ssl start</i>
116     # <i>/etc/init.d/courier-pop3d start</i>
117     # <i>/etc/init.d/courier-pop3d-ssl start</i>
118 zhen 1.3 </pre>
119     <p>Start up your favorite mail client and verify that all connections you've started work for receiving and sending mail. Now that the basics work, we're going to do a whole bunch of stuff at once to get the rest of the system running. Again, please verify that what we've installed already works before progressing.</p>
120     </body>
121 zhen 1.1 </chapter>
122     <chapter>
123     <title>Cyrus-sasl</title>
124 zhen 1.3 <body>
125     <p>Next we're going to install cyrus-sasl. Sasl is going to play the role of actually passing your auth variables to pam, which will in turn pass that information to mysql for authentication of smtp users. For this howto, we'll not even try to verify that sasl is working until mysql is set up and contains a test user. Which is fine since we'll be authenticating against mysql in the end anyway.</p>
126     <note>Now for some reason, sasl will not play nicely with pam against the shadow file. I banged my head against this problem for, well, a long time. If anyone knows why sasl will not auth against the shadow file in its current gentoo incarnation, please <mail link="ken@kickasskungfu.com" >email me</mail> as I'd love to hear a solution to this.</note>
127     <pre caption="Configuring and installing the cyrus-sasl ebuild" >
128 rajiv 1.14 # <i>USE='-ldap -mysql' emerge cyrus-sasl</i>
129 zhen 1.3 <codenote>We don't have ldap and we're not using sasl's mysql capabilities </codenote>
130     <codenote>so we need to turn them off for this build.</codenote>
131     </pre>
132 klasikahl 1.22 <p>Next, edit <path>/usr/lib/sasl2/smtpd.conf</path>.</p>
133 zhen 1.3 <pre caption="Starting sasl" >
134 klasikahl 1.22 # <i>nano -w /usr/lib/sasl2/smtpd.conf</i>
135 rajiv 1.14 pwcheck_method: saslauthd
136     mech_list: LOGIN PLAIN
137 antifa 1.9 <codenote>It's important to turn off auth mehtods we are not using.</codenote>
138     <codenote>They cause problems for some mail clients.</codenote>
139 rajiv 1.14 # <i>/etc/init.d/saslauthd start</i>
140 zhen 1.3 </pre>
141     </body>
142 zhen 1.1 </chapter>
143     <chapter>
144     <title>SSL Certs for Postfix and Apache</title>
145 zhen 1.3 <body>
146     <p>Next we're going to make a set of ssl certificates for postfix and apache.</p>
147     <pre>
148 rajiv 1.14 # <i>cd /etc/ssl/</i>
149     # <i>nano -w openssl.cnf</i>
150    
151 zhen 1.3 <codenote>Change the following default values for your domain:</codenote>
152 rajiv 1.14 countryName_default
153     stateOrProvinceName_default
154     localityName_default
155     0.organizationName_default
156     commonName_default
157     emailAddress_default.
158    
159     <codenote>If the variables are not already present, just add them in a sensible place.</codenote>
160    
161 zhen 1.1
162 rajiv 1.14 # <i>cd misc</i>
163     # <i>nano -w CA.pl</i>
164 zhen 1.3 <codenote>We need to add -nodes to the # create a certificate and</codenote>
165     <codenote>#create a certificate request code in order to let our new ssl</codenote>
166     <codenote>certs be loaded without a password. Otherwise when you</codenote>
167     <codenote>reboot your ssl certs will not be available.</codenote>
168 rajiv 1.14
169     # create a certificate
170     system (&quot;$REQ -new -nodes -x509 -keyout newreq.pem -out newreq.pem $DAYS&quot;);
171    
172     # create a certificate request
173     system (&quot;$REQ -new -nodes -keyout newreq.pem -out newreq.pem $DAYS&quot;);
174 zhen 1.1
175 rajiv 1.14 # <i>./CA.pl -newca</i>
176     # <i>./CA.pl -newreq</i>
177     # <i>./CA.pl -sign</i>
178     # <i>cp newcert.pem /etc/postfix</i>
179     # <i>cp newreq.pem /etc/postfix</i>
180     # <i>cp demoCA/cacert.pem /etc/postfix</i>
181 zhen 1.3 <codenote>Now we do the same thing for apache</codenote>
182    
183 rajiv 1.14 # <i>openssl req -new > new.cert.csr</i>
184     # <i>openssl rsa -in privkey.pem -out new.cert.key</i>
185     # <i>openssl x509 -in new.cert.csr -out new.cert.cert -req -signkey new.cert.key -days 365</i>
186 zhen 1.3 <codenote>Just leave the resulting certificates here for now.</codenote>
187     <codenote>We'll install them after Apache is installed.</codenote>
188     </pre>
189     </body>
190 zhen 1.1 </chapter>
191     <chapter>
192     <title>Adding SSL and SASL support to Postfix</title>
193 zhen 1.3 <body>
194     <p>Now edit the postfix config's to make it aware of your new sasl and ssl capabilities. Add the following parameters to the end of the file where they will be easy to find.</p>
195     <pre caption="/etc/postfix/main.cf" >
196 rajiv 1.14 # <i>nano -w /etc/postfix/main.cf</i>
197    
198     smtpd_sasl_auth_enable = yes
199     smtpd_sasl2_auth_enable = yes
200     smtpd_sasl_security_options = noanonymous
201     broken_sasl_auth_clients = yes
202     smtpd_sasl_local_domain =
203    
204     <codenote>The broken_sasl_auth_clients option and the login auth method </codenote>
205 zhen 1.3 <codenote>are for outlook and outlook express only and are undocumented.</codenote>
206     <codenote>Isn't having to hack software for stupid, broken, M$ BS great?</codenote>
207     <codenote>smtpd_sasl_local_domain appends a domain name to clients using</codenote>
208     <codenote>smtp-auth. Make sure it's blank or your user names will get</codenote>
209     <codenote>mangled by postfix and be unable to auth.</codenote>
210 zhen 1.1
211 rajiv 1.14 smtpd_recipient_restrictions =
212     permit_sasl_authenticated,
213     permit_mynetworks,
214     reject_unauth_destination
215    
216    
217     smtpd_use_tls = yes
218     #smtpd_tls_auth_only = yes
219     smtpd_tls_key_file = /etc/postfix/newreq.pem
220     smtpd_tls_cert_file = /etc/postfix/newcert.pem
221     smtpd_tls_CAfile = /etc/postfix/cacert.pem
222     smtpd_tls_loglevel = 3
223     smtpd_tls_received_header = yes
224     smtpd_tls_session_cache_timeout = 3600s
225     tls_random_source = dev:/dev/urandom
226    
227     <codenote>smtpd_tls_auth_only is commented out to ease testing the system. </codenote>
228 zhen 1.3 <codenote>You can turn this on later if you desire.</codenote>
229 rajiv 1.14
230     # <i>postfix reload</i>
231 zhen 1.3 </pre>
232     <p>Now we're going to verify that the config's we added were picked up by postfix.</p>
233     <pre caption="Verifying sasl and tls support" >
234 rajiv 1.14 # <i>telnet localhost 25</i>
235 zhen 1.1
236 rajiv 1.14 Trying 127.0.0.1...
237     Connected to localhost.
238     Escape character is '^]'.
239     220 mail.domain.com ESMTP Postfix
240     <i>EHLO domain.com</i>
241     250-mail.domain.com
242     250-PIPELINING
243     250-SIZE 10240000
244     250-VRFY
245     250-ETRN
246     250-STARTTLS
247     250-AUTH LOGIN PLAIN
248     250-AUTH=LOGIN PLAIN
249     250-XVERP
250     250 8BITMIME
251     <i>^]</i>
252     telnet> <i>quit</i>
253 zhen 1.3 </pre>
254     <p>Verify that the above AUTH and STARTTLS lines now appear in your postfix install. As I said before, as it stands now AUTH will not work. that's because sasl will try to auth against it's sasldb, instead of the shadow file for some unknown reason, which we have not set up. So we're going to just plow through and set up mysql to hold all of our auth and virtual domain information.
255 zhen 1.1 </p>
256 zhen 1.3 </body>
257 zhen 1.1 </chapter>
258     <chapter>
259     <title>MySQL</title>
260 zhen 1.3 <body>
261     <p>Next we're going to install and configure MySQL. You'll need the <uri link="http://kickasskungfu.com/~ken/genericmailsql.sql" >genericmailsql.sql</uri> dumpfile for this step.</p>
262     <pre caption="Installing and configuring MySQL" >
263 rajiv 1.14 # <i>emerge mysql</i>
264 zhen 1.3
265 rajiv 1.14 # <i>/usr/bin/mysql_install_db</i>
266 zhen 1.3 <codenote>After this command runs follow the onscreen directions</codenote>
267     <codenote>for adding a root password with mysql,</codenote>
268     <codenote>not mysqladmin, otherwise your db will be wide open.</codenote>
269 zhen 1.1
270 rajiv 1.14 # <i>/etc/init.d/mysql start</i>
271     # <i>mysqladmin -u root -p create mailsql</i>
272     # <i>mysql -u root -p mailsql &lt; genericmailsql.sql</i>
273    
274     # <i>mysql -u root -p mysql</i>
275     mysql> <i>GRANT SELECT,INSERT,UPDATE,DELETE</i>
276     -> <i>ON mailsql.*</i>
277     -> <i>TO mailsql@localhost</i>
278     -> <i>IDENTIFIED BY '$password';</i>
279    
280     -> <i>quit</i>
281 zhen 1.3 <codenote>Verify that the new mailsql user can connect to the mysql server.</codenote>
282 rajiv 1.14
283     # <i>mysql -u mailsql -p mailsql</i>
284 zhen 1.3 </pre>
285     <p>Your new database has default values and tables set up for two domains. The following tables are included:
286 zhen 1.1 <ul>
287 zhen 1.3 <li>alias - local email alias and mailman alias information.</li>
288     <li>relocated - relocated user email address maps</li>
289     <li>transport - default mail transport information for all domains you are hosting</li>
290     <li>users - all user account information</li>
291     <li>virtual - virtual domain email alias maps</li>
292     </ul>
293     </p>
294     <pre caption="alias table sample" >
295 rajiv 1.15 id alias destination
296     1 root foo@bar.com
297     2 postmaster foo@bar.com
298 rajiv 1.14 </pre>
299 zhen 1.3 <pre caption="user table sample" >
300 rajiv 1.15 <codenote>Line wrapped for clarity</codenote>
301     id email clear name uid gid homedir \
302     maildir quota postfix
303     10 foo@virt-bar.org $password realname virtid virtid /home/vmail \
304     /home/vmail/virt-bar.org/foo/.maildir/ y
305     13 foo@bar.com $password realname localid localid /home/foo \
306     /home/foo/.maildir/ y
307 rajiv 1.14 </pre>
308 zhen 1.3 <pre caption="transport table sample" >
309 rajiv 1.15 id domain destination
310     1 bar.com local:
311     2 virt-bar.org virtual:
312 rajiv 1.14 </pre>
313 zhen 1.3 <pre caption="virtual table sample" >
314 rajiv 1.15 id email destination
315     3 root@virt-bar.org other@email.address
316 rajiv 1.14 </pre>
317 zhen 1.3 </body>
318 zhen 1.1 </chapter>
319     <chapter>
320     <title>Apache and phpMyAdmin</title>
321 zhen 1.3 <body>
322     <p>Next we'll set up apache and add an interface to interact with the database more easily. </p>
323     <pre caption="Setting up apache and phpmyadmin" >
324 swift 1.17 # <i>emerge apache mod_php phpmyadmin</i>
325 zhen 1.3 </pre>
326 swift 1.23 <p>There are plenty of guides out there about how to set up apache with php. Like this one: <uri>http://www.linuxguruz.org/z.php?id=31</uri>. There are also numerous posts on <uri>http://forums.gentoo.org</uri> detailing how to solve problems with the installation (search for 'apache php'). So, that said, I'm not going to cover it here. Set up the apache and php installs, then continue with this howto. Now, a word for the wise: .htaccess the directory that you put phpmyadmin in. If you do not do this, search engine spiders will come along and index the page which in turn will mean that anyone will be able to find your phpmyadmin page via google and in turn be able to come change your database however they want which is <e>BAD!</e> There are many howtos on this including: <uri>http://www.csoft.net/docs/micro/htaccess.html.en</uri>.</p>
327 zhen 1.3 <p>Now we're going to install the Apache certificates we made previously. The Apache-SSL directives that you need to use the resulting cert are:
328 zhen 1.1 <ul>
329 zhen 1.3 <li>SSLCertificateFile /path/to/certs/new.cert.cert</li>
330     <li>SSLCertificateKeyFile /path/to/certs/new.cert.key</li>
331     </ul>
332     </p>
333     <pre caption="Install Apache SSL certificates" >
334 rajiv 1.14 # <i>cp /etc/ssl/misc/new.cert.cert /etc/apache/conf/ssl/</i>
335     # <i>cp /etc/ssl/misc/new.cert.key /etc/apache/conf/ssl/</i>
336     # <i>nano -w /etc/apache/conf/vhosts/ssl.default-vhost.conf</i>
337 zhen 1.3 <codenote>Change the following parameters</codenote>
338 rajiv 1.14
339     ServerName host.domain.name
340     ServerAdmin your@email.address
341     SSLCertificateFile /etc/apache/conf/ssl/new.cert.cert
342     SSLCertificateKeyFile /etc/apache/conf/ssl/new.cert.key
343    
344     # <i>/etc/init.d/apache restart</i>
345 zhen 1.3 </pre>
346     <note>If you have an existing apache install, you'll likely have to perform a full server reboot to install your new certificates. Check your logs to verify apache restarted successfully.</note>
347     <p>Next, configure phpMyAdmin.</p>
348     <pre caption="Configuring phpMyAdmin" >
349 pylon 1.21 # <i>nano -w /var/www/localhost/htdocs/phpmyadmin/config.inc.php</i>
350 zhen 1.3 <codenote>Change the following parameters</codenote>
351 rajiv 1.14
352 rajiv 1.15 $cfg['Servers'][$i]['host'] = 'localhost'; // MySQL hostname
353     $cfg['Servers'][$i]['controluser'] = 'mailsql'; // MySQL control user settings
354     // (this user must have read-only
355     $cfg['Servers'][$i]['controlpass'] = '$password'; // access to the &quot;mysql/user&quot;
356     // and &quot;mysql/db&quot; tables)
357     $cfg['Servers'][$i]['user'] = 'mailsql'; // MySQL user
358     $cfg['Servers'][$i]['password'] = '$password'; // MySQL password
359 rajiv 1.14 </pre>
360 zhen 1.3 <p>Now enter the phpmyadmin page and browse the tables. You'll want to add in your local aliases, edit your user table to add a test user, and change your transport table to add information about your domains. The default values supplied with the dumpfile should be a sufficient guide to what values need to go where. Make sure that if you put information in the database that it is accurate. For instance, make sure the local users home dir exists and that the correct uid/gid values are in place. The maildirs should be created automatically by postfix when the user receives their first email. So, in general, it's a good idea to send a &quot;Welcome&quot; mail to a new user after you setup their account to make sure the .maildir gets created. </p>
361     </body>
362 zhen 1.1 </chapter>
363     <chapter>
364     <title>The vmail user</title>
365 zhen 1.3 <body>
366     <p>At this point you may be wondering what user and directory to use for virtual mail users, and rightly so. Let's set that up.</p>
367     <pre caption="Adding the vmail user" >
368 rajiv 1.14 # <i>adduser -d /home/vmail -s /bin/false vmail</i>
369     # <i>uid=`cat /etc/passwd | grep vmail | cut -f 3 -d :`</i>
370     # <i>groupadd -g $uid vmail</i>
371     # <i>mkdir /home/vmail</i>
372     # <i>chown vmail. /home/vmail</i>
373 zhen 1.3 </pre>
374     <p>So now when you're setting up vmail accounts, use the vmail uid, gid, and homedir. When you're setting up local accounts, use that users uid, gid, and homedir. We've been meaning to create a php admin page for this setup but haven't gotten around to it yet, as phpmyadmin generally works fine for us.</p>
375     </body>
376 zhen 1.1 </chapter>
377     <chapter>
378     <title>Configuring MySQL Authentication and vhosts</title>
379 zhen 1.3 <body>
380     <p>Next we'll reconfigure our authentication to use the mailsql database in courier-imap and postfix. In all of the following examples, replace $password with the password you set for the mailsql mysql user.</p>
381     <pre>
382 swift 1.20 # <i>emerge pam_mysql</i>
383 rajiv 1.14 # <i>nano -w /etc/pam.d/imap</i>
384 zhen 1.3 <codenote>Comment out the existing auth lines and add the following as shown.</codenote>
385 zhen 1.1
386 rajiv 1.14 #auth required pam_nologin.so
387     #auth required pam_stack.so service=system-auth
388     #account required pam_stack.so service=system-auth
389     #session required pam_stack.so service=system-auth
390    
391 swift 1.18 auth optional pam_mysql.so host=localhost db=mailsql user=mailsql \
392 rajiv 1.14 passwd=$password table=users usercolumn=email passwdcolumn=clear crypt=0
393 swift 1.18 account required pam_mysql.so host=localhost db=mailsql user=mailsql \
394 rajiv 1.14 passwd=$password table=users usercolumn=email passwdcolumn=clear crypt=0
395 zhen 1.1
396 rajiv 1.14 # <i>nano -w /etc/pam.d/pop3</i>
397     # <i>nano -w /etc/pam.d/smtp</i>
398 zhen 1.3 <codenote>Make the same changes to the pop3 and smtp files</codenote>
399     </pre>
400     <p>Next, we need to edit courier's authentication config's.</p>
401     <pre>
402 rajiv 1.14 # <i>nano -w /etc/courier-imap/authdaemonrc</i>
403     authmodulelist=&quot;authmysql authpam&quot;
404 zhen 1.1
405 rajiv 1.14 # <i>nano -w /etc/courier-imap/authdaemond.conf</i>
406     AUTHDAEMOND=&quot;authdaemond.mysql&quot;
407 zhen 1.1
408 rajiv 1.14 # <i>nano -w /etc/courier-imap/authmysqlrc</i>
409     MYSQL_SERVER localhost
410     MYSQL_USERNAME mailsql
411     MYSQL_PASSWORD $password
412     MYSQL_DATABASE mailsql
413     MYSQL_USER_TABLE users
414     #MYSQL_CRYPT_PWFIELD crypt (make sure this is commented out since we're storing plaintext)
415     MYSQL_CLEAR_PWFIELD clear
416     MYSQL_UID_FIELD uid
417     MYSQL_GID_FIELD gid
418     MYSQL_LOGIN_FIELD email
419     MYSQL_HOME_FIELD homedir
420     MYSQL_NAME_FIELD name
421     MYSQL_MAILDIR_FIELD maildir
422 zhen 1.1
423 rajiv 1.14 # <i>/etc/init.d/authdaemond restart</i>
424     # <i>/etc/init.d/saslauthd restart</i>
425 zhen 1.3 </pre>
426     <p>We're almost there I promise! Next, set up the rest of the necessary config's for postfix to interract with the database for all it's other transport needs.</p>
427     <pre caption="/etc/postfix/mysql-aliases.cf" >
428 rajiv 1.14 # <i>nano -w /etc/postfix/mysql-aliases.cf</i>
429     # mysql-aliases.cf
430 zhen 1.1
431 rajiv 1.14 user = mailsql
432     password = $password
433     dbname = mailsql
434     table = alias
435     select_field = destination
436     where_field = alias
437     hosts = unix:/var/run/mysqld/mysqld.sock
438     </pre>
439 zhen 1.3 <pre caption="/etc/postfix/mysql-relocated.cf" >
440 rajiv 1.14 # <i>nano -w /etc/postfix/mysql-relocated.cf</i>
441     # mysql-relocated.cf
442 zhen 1.1
443 rajiv 1.14 user = mailsql
444     password = $password
445     dbname = mailsql
446     table = relocated
447     select_field = destination
448     where_field = email
449     hosts = unix:/var/run/mysqld/mysqld.sock
450     </pre>
451 zhen 1.3 <pre caption="/etc/postfix/mysql-transport.cf (optional)" >
452 rajiv 1.14 # <i>nano -w /etc/postfix/mysql-transport.cf</i>
453     # mysql-transport.cf
454 zhen 1.1
455 rajiv 1.14 user = mailsql
456     password = $password
457     dbname = mailsql
458     table = transport
459     select_field = destination
460     where_field = domain
461     hosts = unix:/var/run/mysqld/mysqld.sock
462     </pre>
463 zhen 1.3 <pre caption="/etc/postfix/mysql-virtual-gid.cf (optional)" >
464 rajiv 1.14 # <i>nano -w /etc/postfix/mysql-virtual-gid.cf</i>
465     #myql-virtual-gid.cf
466 zhen 1.1
467 rajiv 1.14 user = mailsql
468     password = $password
469     dbname = mailsql
470     table = users
471     select_field = gid
472     where_field = email
473     additional_conditions = and postfix = 'y'
474     hosts = unix:/var/run/mysqld/mysqld.sock
475     </pre>
476 zhen 1.3 <pre caption="/etc/postfix/mysql-virtual-maps.cf" >
477 rajiv 1.14 # <i>nano -w /etc/postfix/mysql-virtual-maps.cf</i>
478     #myql-virtual-maps.cf
479 zhen 1.1
480 rajiv 1.14 user = mailsql
481     password = $password
482     dbname = mailsql
483     table = users
484     select_field = maildir
485     where_field = email
486     additional_conditions = and postfix = 'y'
487     hosts = unix:/var/run/mysqld/mysqld.sock
488     </pre>
489 zhen 1.3 <pre caption="/etc/postfix/mysql-virtual-uid.cf (optional)" >
490 rajiv 1.14 # <i>nano -w /etc/postfix/mysql-virtual-uid.cf</i>
491     # mysql-virtual-uid.cf
492 zhen 1.1
493 rajiv 1.14 user = mailsql
494     password = $password
495     dbname = mailsql
496     table = users
497     select_field = uid
498     where_field = email
499     additional_conditions = and postfix = 'y'
500     hosts = unix:/var/run/mysqld/mysqld.sock
501     </pre>
502 zhen 1.3 <pre caption="/etc/postfix/mysql-virtual.cf" >
503 rajiv 1.14 # <i>nano -w /etc/postfix/mysql-virtual.cf</i>
504     # mysql-virtual.cf
505 zhen 1.1
506 rajiv 1.14 user = mailsql
507     password = $password
508     dbname = mailsql
509     table = virtual
510     select_field = destination
511     where_field = email
512     hosts = unix:/var/run/mysqld/mysqld.sock
513     </pre>
514 zhen 1.3 <p>Lastly, edit <path>/etc/postfix/main.cf</path> one more time.</p>
515     <pre caption="/etc/postfix/main.cf" >
516 rajiv 1.14 # <i>nano -w /etc/postfix/main.cf</i>
517     alias_maps = mysql:/etc/postfix/mysql-aliases.cf
518     relocated_maps = mysql:/etc/postfix/mysql-relocated.cf
519    
520     local_transport = local
521     local_recipient_maps = $alias_maps $virtual_mailbox_maps unix:passwd.byname
522    
523     virtual_transport = virtual
524     virtual_mailbox_domains =
525     virt-bar.com,
526     $other-virtual-domain.com
527    
528     virtual_minimum_uid = 1000
529     virtual_gid_maps = static:$vmail-gid
530     virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-maps.cf
531     virtual_alias_maps = mysql:/etc/postfix/mysql-virtual.cf
532     virtual_uid_maps = static:$vmail-uid
533     virtual_mailbox_base = /
534     #virtual_mailbox_limit =
535     </pre>
536 swift 1.24
537     <p>
538     For security reasons you should change the permissions of the various
539     <path>/etc/mail/mysql-*.cf</path>:
540     </p>
541    
542     <pre caption="Changing file permission">
543     # <i>chmod 640 /etc/postfix/mysql-*.cf</i>
544     # <i>chgrp postfix /etc/postfix/mysql-*.cf</i>
545     </pre>
546    
547 zhen 1.3 <p>As of Postfix 2.0.x, there were a number of significant changes over the 1.1.x release. Notably the transport, virtual-gid, and virtual-uid tables are no longer necessary. The tables are still included if you wish to use them.</p>
548     <note>It is recommended tha you read VIRTUAL_README included with the postfix doc's for more information.</note>
549     <pre># <i>postfix reload</i>
550     </pre>
551     <p>Now, if all went well, you should have a functioning mailhost. Users should be able to authenticate against the sql database, using their full email address, for pop3, imap, and smtp. I would highly suggest that you verify that everything is working at this point. If you run into problems (with as many things as this setup has going on, it's likely that you will) check the troubleshooting section of this howto.</p>
552     </body>
553 zhen 1.1 </chapter>
554     <chapter>
555     <title>Squirrelmail</title>
556 zhen 1.3 <body>
557     <pre>
558 rajiv 1.14 # <i>emerge squirrelmail</i>
559 zhen 1.3 <codenote>I like to add a link to the htdocs space for a shorter url.</codenote>
560    
561 pylon 1.21 # <i>ln -s /var/www/localhost/htdocs/squirrelmail/ /var/www/localhost/htdocs/mail</i>
562     # <i>cd /var/www/localhost/htdocs/mail/conf</i>
563 rajiv 1.14 # <i>./conf.pl</i>
564 zhen 1.3 <codenote>Change your Organization, Server, and Folder settings for squirrelmail.</codenote>
565     <codenote>Now you should be able to login to squirrelmail, again - with your full email address,</codenote>
566     <codenote>and use your new webmail setup.</codenote>
567     </pre>
568     </body>
569 zhen 1.1 </chapter>
570     <chapter>
571     <title>Mailman</title>
572 zhen 1.3 <body>
573 swift 1.8 <p>Last step: mailman. The new version of mailman has very nice virtual domain support, which is why I use it, not to mention it's really a great package. To get this package installed and working correctly for virtual domains is going to require a bit of hacking. I really recommend reading all of the mailman documentation, including README.POSTFIX.gz, to understand what's being done here.</p>
574 antifa 1.12 <p>One further note, current versions of mailman install to /usr/local/mailman. If you're like me and wish to change the default install location, it can be overridden in the ebuild filoe by changing the INSTALLDIR variable.</p>
575 zhen 1.3 <pre caption="/usr/portage/net-mail/mailman/mailman-$ver.ebuild">
576 rajiv 1.14 # <i>nano -w /usr/portage/net-mail/mailman/mailman-$ver.ebuild</i>
577     MAILGID="280"
578     <codenote>Set MAILGID to the mailman group instead of nobody</codenote>
579     <codenote>This is needed for postfix integration</codenote>
580 zhen 1.3 </pre>
581     <pre>
582 rajiv 1.14 # <i>emerge mailman</i>
583     <codenote>This package is currently masked as well, so you'll need to unmask it or give </codenote>
584     <codenote>emerge an explicit path to the ebuild. Once it's installed, follow the directions</codenote>
585     <codenote>in the README.gentoo.gz *except* do not add your aliases to /etc/mail/aliases.</codenote>
586     <codenote>We will instead be linking the entire alias db into postfix.</codenote>
587 zhen 1.3
588 rajiv 1.14 # <i>zless /usr/share/doc/mailman-$ver/README.gentoo.gz</i>
589 zhen 1.3 </pre>
590 antifa 1.12 <pre caption="Setting defaults: Mailman/Defaults.py">
591 rajiv 1.14 # <i> nano -w /var/mailman/Mailman/Defaults.py</i>
592     <codenote>Change the values below to reflect your primary domain, virtuals will be set next.</codenote>
593     DEFAULT_EMAIL_HOST = 'domain.com'
594     DEFAULT_URL_HOST = 'www.domain.com'
595 antifa 1.12 </pre>
596 zhen 1.3 <pre caption="mailman config: mm_cfg.py">
597 rajiv 1.14 # <i>nano -w /var/mailman/Mailman/mm_cfg.py</i>
598     MTA = "Postfix"
599     POSTFIX_STYLE_VIRTUAL_DOMAINS = ['virt-domain.com', 'virt.domain2.com']
600     add_virtualhost('www.virt.domain.com', 'virt.domain.com')
601     add_virtualhost('www.virt.domain2.com', 'virt.domain2.com')
602 zhen 1.3 <codenote>This is required for your virtual domains for mailman to function.</codenote>
603     </pre>
604     <pre>
605 rajiv 1.14 <codenote>Once that's finished, add your first list.</codenote>
606 zhen 1.3
607 rajiv 1.14 # <i>su mailman</i>
608     # <i>cd ~</i>
609     # <i>bin/newlist test</i>
610     Enter the email of the person running the list: your@email.address
611     Initial test password:
612     Hit enter to continue with test owner notification...
613     <codenote>Virtual domain lists may be specified with</codenote>
614     <codenote>list@domain.com style list names</codenote>
615     # <i>bin/genaliases</i>
616     <codenote>Now that your aliases have been generated,</codenote>
617     <codenote>verify that they were added successfully.</codenote>
618    
619     # <i>nano -w data/aliases</i>
620     # STANZA START: test
621     # CREATED:
622     test: "|/var/mailman/mail/mailman post test"
623     test-admin: "|/var/mailman/mail/mailman admin test"
624     test-bounces: "|/var/mailman/mail/mailman bounces test"
625     test-confirm: "|/var/mailman/mail/mailman confirm test"
626     test-join: "|/var/mailman/mail/mailman join test"
627     test-leave: "|/var/mailman/mail/mailman leave test"
628     test-owner: "|/var/mailman/mail/mailman owner test"
629     test-request: "|/var/mailman/mail/mailman request test"
630     test-subscribe: "|/var/mailman/mail/mailman subscribe test"
631     test-unsubscribe: "|/var/mailman/mail/mailman unsubscribe test"
632     # STANZA END: test
633    
634     # <i>/etc/init.d/mailman start</i>
635     # <i>rc-update add mailman default</i>
636     <codenote>To start mailman at once and on every reboot</codenote>
637 zhen 1.3 </pre>
638    
639     <pre caption="Adding mailman alias support to postfix">
640 rajiv 1.14 # <i>nano -w /etc/postfix/main.cf</i>
641     owner_request_special = no
642     recipient_delimiter = +
643     <codenote>Read README.POSTFIX.gz for details on this</codenote>
644    
645     alias_maps =
646     hash:/var/mailman/data/aliases,
647     mysql:/etc/postfix/mysql-aliases.cf
648    
649     virtual_alias_maps =
650     hash:/var/mailman/data/virtual-mailman,
651     mysql:/etc/postfix/mysql-virtual.cf
652     <codenote>This adds mailman alias file support to postfix</codenote>
653     <codenote>You may of course use the mysql tables for this,</codenote>
654     <codenote>but I hate doing that by hand. Also, if you are not</codenote>
655     <codenote>using virtual domains, adding the virtual alias maps</codenote>
656     <codenote>to postfix may cause problems, be warned.</codenote>
657 zhen 1.3 </pre>
658     <p> You should now be able to setup mailing lists for any domain on your box. Last note on this, make sure you run all mailman commands as the user mailman (<c>su mailman</c>) or else the permissions will be wrong and you'll have to fix them. Read the mailman doc's for more information on setting up and managing mailman lists.</p>
659     </body>
660     </chapter>
661     <chapter>
662     <title>Content Filtering and Anti-Virus</title>
663 antifa 1.9 <body><p>Coming soon...it would be done already but I need some perl help and testing to make it so. If you'd like to volunteer for that, please email me.</p></body>
664 zhen 1.1 </chapter>
665     <chapter>
666     <title>Wrap Up</title>
667 zhen 1.3 <body>
668     <p>Ok, you're all set, edit <path>/etc/postfix/master.cf</path> and turn off verbose mode for production use. You'll probably also want to add the services to your startup routine to make sure everything comes back up on a reboot. Make sure to add all the services you're using - apache, mysql, saslauthd, postfix, courier-imapd, courier-imapd-ssl, courier-pop3d, and courier-pop3d-ssl are all up to your decision on what access you want to provide. I generally have all the services enabled.</p>
669     <pre caption="Wrap up" >
670 rajiv 1.14 # <i>postfix reload</i>
671     # <i>rc-update add $service default</i>
672 zhen 1.3 </pre>
673     <p>
674     <e>Have fun!</e>
675     </p>
676     </body>
677 zhen 1.1 </chapter>
678     <chapter>
679     <title>Troubleshooting</title>
680     <section>
681 zhen 1.3 <title>Introduction</title>
682     <body>
683     <p>Troubleshooting: This is a short troubleshooting guide for the set up we've detailed how to install here. It is not exhaustive, but meant as a place to get you started in figuring out problems. With a complicated setup such as this, it's imperative that you narrow down the problem to the particular component that is malfunctioning. In general I do that by following a few steps. Start from the base of the system and work your way up, ruling out components that work along the way until you discover which component is having the problem.</p>
684     </body>
685 zhen 1.1 </section>
686     <section>
687 zhen 1.3 <title>Step 1: Check your config files.</title>
688     <body>
689     <p>Typos are killers, especially when dealing with authentication systems. Scan your config's and mailsql database for typo's. You can debug all you want, but if you're not passing the right information back and forth to your mail system, it's not going to work. If you make a change to a config file for a service, make sure you restart that service so that the config change gets picked up.</p>
690     <pre>
691 rajiv 1.14 # <i>/etc/init.d/service restart</i>
692 zhen 1.3 </pre>
693     </body>
694 zhen 1.1 </section>
695     <section>
696 zhen 1.3 <title>Step 2: Are all the necessary services actually running?</title>
697     <body>
698     <p>If it's not running, start it up. It's awful hard to debug a service that isn't running. Sometimes a service will act like it's started but still not function. Sometimes, when a bad config is used, or a bad transmission comes into a mail component, the service will hang and keep the port from being used by another process. Sometimes you can detect this with netstat. Or, if you've been at it awhile, just take a break and reboot your box in the meantime. That will clear out any hung services. Then you can come back fresh and try it again.</p>
699     <pre>
700 rajiv 1.14 # <i>/etc/init.d/$service status</i>
701     # <i>netstat -a | grep $service (or $port)</i>
702 zhen 1.3 </pre>
703     </body>
704 zhen 1.1 </section>
705     <section>
706 zhen 1.3 <title>Step 3: Are all the service using the current config's?</title>
707     <body>
708     <p>If you've recently made a change to a config file, restart that service to make sure it's using the current version. Some of the components will dump their current config's to you, like postfix.</p>
709     <pre>
710 rajiv 1.14 # <i>apachectl fullstatus</i> (needs lynx installed)
711     # <i>apachectl configtest</i> (checks config sanity)
712     # <i>postconf -n</i> (will tell you exactly what param's postfix is using)
713     # <i>/etc/init.d/$service restart</i>
714 zhen 1.3 </pre>
715     </body>
716 zhen 1.1 </section>
717     <section>
718 zhen 1.3 <title>Step 4: Check the logs.</title>
719     <body>
720     <p>Repeat after me, logs are my friend. My next troubleshooting stop is always the logs. Sometimes it's helpful to try a failed operation again then check the logs so that the error message is right at the bottom (or top depending on your logger) instead of buried in there somewhere. See if there is any information in your log that can help you diagnose the problem, or at the very least, figure out which component is having the problem.</p>
721     <pre>
722 rajiv 1.14 # <i>kill -USR1 `ps -C metalog -o pid=`</i>(to turn off metalog buffering)
723     # <i>nano -w /var/log/mail/current</i>
724     # <i>cat /var/log/mysql/mysql.log</i>
725     # <i>tail /var/log/apache/error_log</i>
726 zhen 1.3 </pre>
727     <p>You may also find the debug_peer parameters in main.cf helpful. Setting these will increase log output over just verbose mode.</p>
728     <pre caption="adding debug_peer support">
729 rajiv 1.14 # <i>nano -w /etc/postfix/main.cf</i>
730     debug_peer_level = 5
731     debug_peer_list = $host.domain.name
732     <codenote>Uncomment one of the suggested debugger</codenote>
733     <codenote>commands as well.</codenote>
734 zhen 1.3 </pre>
735     </body>
736 zhen 1.1 </section>
737     <section>
738 zhen 1.3 <title>Step 5: Talk to the service itself.</title>
739     <body>
740     <p>SMTP, IMAP, and POP3 all respond to telnet sessions. As we've seen earlier when we verified postfix's config. Sometimes it's helpful to open a telnet session to the service itself and see what's happening.</p>
741     <pre>
742 rajiv 1.14 # <i>telnet localhost $port</i>
743 zhen 1.3 <codenote>SMTP is 25, IMAP is 143, POP3 is 110. You should receive at least an OK string,</codenote>
744     <codenote>letting you know that the service is running and ready to respond to requests.</codenote>
745 zhen 1.1
746 rajiv 1.14 Trying 127.0.0.1...
747     Connected to localhost.
748     Escape character is '^]'.
749 rajiv 1.15 * OK Courier-IMAP ready. Copyright 1998-2002 Double Precision, Inc.
750 rajiv 1.14 </pre>
751 zhen 1.3 </body>
752 zhen 1.1 </section>
753     <section>
754 zhen 1.3 <title>Step 6: Sometimes only the big guns will give you the information you need: strace.</title>
755     <body>
756     <p>You should have this installed anyway. This is an invaluable tool for debugging software. You can start commands from the command line with strace and watch all the system calls as they happen. It often dumps a huge amount of information, so you'll either need to watch it realtime as you retry a failed transaction with the mail system, or dump the output to a file for review.</p>
757     <pre>
758 rajiv 1.14 # <i>emerge strace</i>
759     # <i>strace $command</i>
760     # <i>strace -p `ps -C $service -o pid=`</i>
761 zhen 1.3 </pre>
762     </body>
763 zhen 1.1 </section>
764     <section>
765 zhen 1.3 <title>Step 7: Research</title>
766     <body>
767     <p>Once you have the information, if you can diagnose and fix the problem, great! If not, you'll probably need to go digging on the net for information that will help you fix it. Here's a list of sites you can check to see if your error has already been resolved. There's also a really good howto on setting up smtp-auth which contains some great debugging ideas.</p>
768     <p>
769     <ul>
770     <li>
771     <uri>http://forums.gentoo.org/</uri> - Great forums for gentoo users</li>
772     <li>
773     <uri>http://bugs.gentoo.org/</uri> - Bugs database for gentoo - great place to look for specific errors</li>
774     <li>
775     <uri>http://postfix.state-of-mind.de/</uri> - smtp-auth howto</li>
776     <li>
777     <uri>http://marc.theaimsgroup.com/?l=postfix-users</uri> - Postfix mailing lists - searchable</li>
778     <li>
779     <uri>http://sourceforge.net/mailarchive/forum.php?forum_id=6705</uri> - Courier-imap mailing list archives - not searchable</li>
780     <li>
781     <uri>http://www.google.com/</uri> - If all else fails, there's always google, which has never failed me</li>
782     <li>I also spend a lot of time on irc.freenode.net #gentoo. Irc is a great place to go for help.</li>
783     </ul>
784     </p>
785     </body>
786 zhen 1.1 </section>
787     </chapter>
788     </guide>

  ViewVC Help
Powered by ViewVC 1.1.20