ISP-MAIL-HOWTO. v1.2.
() 2002  , multik@multik.ru

         
Postfix, Cyrus-SASL, MySQL, Courier-IMAP, SquirrelMail, DrWeb.   
     ,   
   ,         
5-10   .    ,  
   ,      . 
     .

     : SMTP  ,
pop  imap ,     .    
.

 .       ,   
,   Linux.      Linux 
       hotmail.com,    
    .         
.        -    .

     RedHat 7.2.   
   RedHat 6.2  ASPLinux 7.2.    ,
       .    
     freshmeat.net.

     ,   ,   
  PostfixFAQ  www.postfix.org -   90% ,   
 ,  .    -     
   /var/log/messages  /var/log/maillog -   
 ,    -.  
(       ,   
)    $50/.

  ;-):       "   
,     ,   ?".

,   :
 
   postfix?   -- sendmail.   exim, 
qmail     .

 sendmail    c  . ,   ,
sendmail  .  ,      
 .   djb  -   
.   exim    .

Courier-IMAP    . -     
 IMAP ,        
 ,     .

DrWEB.    .    ,   
-  ,    AVP.  ,  
       . ,  
     -     
 .  -   ,  - .

SquirrelMail -     Web-based , 
        . 
     .

, .

   MySQL,    .  MySQL 
 MySQL   (    
)  ,     MySQL 
   ,  .     -  (
)     MySQL    mysql.com.  

# rpm -i MySQL*
Preparing db table
Preparing host table
Preparing user table
Preparing func table
Preparing tables_priv table
Preparing columns_priv table
Installing all prepared tables
020628 14:29:10  /usr/sbin/mysqld: Shutdown Complete


PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
This is done with:
/usr/bin/mysqladmin -u root -p password 'new-password'
/usr/bin/mysqladmin -u root -h multik.ip-tel.int -p password 'new-password'
See the manual for more instructions.

Please report any problems with the /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at https://order.mysql.com

Starting mysqld daemon with databases from /var/lib/mysql

 MySQL  .        
 MySQL (  root    !)

# /usr/bin/mysqladmin -u root -p password 'password'

mysqladmin   -      -   Enter.

  SASL.  ,    RPM  .
,     ,    ,   .  ,
.     .

# tar zxvf cyrus-sasl-1.5.27.tar.gz
# cd cyrus-sasl-1.5.27

    MySQL  LDAP :

http://www.surf.org.uk/downloads/sasl-1.5.27-ldap-ssl-filter-mysql-patch4.tgz

     sasl-ldap+mysql.patch   
 SASL.    : 

# patch -b -p1 < sasl-ldap+mysql.patch 
# autoheader
# autoconf
# automake -i

,  .   SASL:

# ./configure --with-mysql=/usr/include/mysql --enable-login

   :

# make
# make install
# ln -s /usr/local/lib/sasl /usr/lib/sasl
# echo /usr/lib/sasl >> /etc/ld.so.conf
# ldconfig
# cd ..

  .

# cat > /usr/local/lib/sasl/smtpd.conf
pwcheck_method: mysql                                                           
mysql_user: postfix                                                             
mysql_passwd: postfix                                                           
mysql_host: localhost                                                           
mysql_database: mail                                                            
mysql_table: aliases                                                            
mysql_uidcol: alias                                                             
mysql_pwdcol: password
^D

     .

# ln -s /usr/local/lib/sasl/smtpd.conf /usr/local/lib/sasl/imapd.conf
# ln -s /usr/local/lib/sasl/smtpd.conf /usr/local/lib/sasl/pop3d.conf


   postfix.    .    
  rpm,      postfix 
 MySQL.        - 
 ,   ,  .

# tar zxvf postfix-1.1.11.tar.gz
# cd postfix-1.1.11

  -   .      .

# make -f Makefile.init makefiles 'CCARGS=-DHAS_MYSQL -DUSE_SASL_AUTH 
-I/usr/include/mysql -I/usr/local/include -L /usr/local/lib -lsasl 
-lmysqlclient'

  :

# make
# adduser postfix
# groupadd postdrop
# make install

 ,      :

install_root: [/]
tempdir: [/usr/src/post/postfix-1.1.11] /tmp
config_directory: [/etc/postfix]
daemon_directory: [/usr/libexec/postfix]
command_directory: [/usr/sbin]
queue_directory: [/var/spool/postfix]
sendmail_path: [/usr/sbin/sendmail]
newaliases_path: [/usr/bin/newaliases]
mailq_path: [/usr/bin/mailq]
mail_owner: [postfix]
setgid_group: [postdrop]
manpage_directory: [/usr/local/man]
sample_directory: [/etc/postfix]
readme_directory: [no]

. Postfix .     .

# cd /etc/postfix/

# mcedit main.cf (  mcedit   vi, emacs   
    -   ;-) ) 

    postfix,    
:

broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable = yes
transport_maps = mysql:/etc/postfix/transport.cf
virtual_mailbox_base = /
virtual_uid_maps = mysql:/etc/postfix/ids.cf
virtual_gid_maps = mysql:/etc/postfix/gids.cf
virtual_mailbox_maps = mysql:/etc/postfix/aliases.cf
virtual_maps = mysql:/etc/postfix/remote_aliases.cf
relay_domains = $transport_maps
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated,check_relay_domains                                                                
disable_vrfy_command = yes

      ,     
 postfix   FAQ. 

 ,      .

# cat > transport.cf
user = postfix
password = postfix
dbname = mail
table = transport
select_field = transport
where_field = domain
hosts = localhost
^D

# cat > ids.cf
user = postfix
password = postfix
dbname = mail
table = aliases
select_field = id
where_field = alias
hosts = localhost
^D

# cat > gids.cf
user = postfix
password = postfix
dbname = mail
table = aliases
select_field = gid
where_field = alias
hosts = localhost
^D

         
   -  !.

 ,     ,   postfix
 MySQL  localhost,   postfix  
postfix,    mail. ,     
 -          
,   . ,      (
  chmod).

,    .

# postfix check

    -   . 
-   - ,    .

         
 mysql -p:

mysql> create database mail;
Query OK, 1 row affected (0.62 sec)
mysql> grant insert,select,delete,update on mail.* to postfix@localhost identified by 'postfix';
Query OK, 0 rows affected (0.72 sec)
mysql> use mail;
Database changed
mysql> create table transport (domain varchar(255) PRIMARY KEY, transport char(8));
Query OK, 0 rows affected (0.00 sec)

mysql> create table aliases (id int(6), gid int(6), alias varchar(255) PRIMARY KEY, maildir varchar(255),password varchar(128), info varchar(128));
Query OK, 0 rows affected (0.00 sec)

mysql> create table remote_aliases (alias varchar(255) PRIMARY KEY, rcpt varchar(255));
Query OK, 0 rows affected (0.02 sec)

      : 

     ,  postfix

mysql> desc transport;
+-----------+--------------+------+-----+---------+-------+
| Field     | Type         | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| domain    | varchar(255) |      | PRI |         |       |
| transport | varchar(8)   | YES  |     | NULL    |       |
+-----------+--------------+------+-----+---------+-------+
2 rows in set (0.05 sec)

     :

mysql> desc aliases;
+----------+--------------+------+-----+---------+-------+
| Field    | Type         | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| id       | int(6)       | YES  |     | NULL    |       |
| gid      | int(6)       | YES  |     | NULL    |       |
| alias    | varchar(255) |      | PRI |         |       |
| maildir  | varchar(255) | YES  |     | NULL    |       |
| password | varchar(128) | YES  |     | NULL    |       |
| info     | varchar(128) | YES  |     | NULL    |       |
+----------+--------------+------+-----+---------+-------+
6 rows in set (0.06 sec)

       .  
    .

mysql> desc remote_aliases;
+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| alias | varchar(255) |      | PRI |         |       |
| rcpt  | varchar(255) | YES  |     | NULL    |       |
+-------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

,    postfix   MySQL
# mysql -u postfix -p

 postfix

# postfix start
postfix/postfix-script: starting the Postfix mail system

   MySQL   test.ru

mysql> insert into transport values ('test.ru','virtual:');

  multik@test.ru.      
     /   .

mysql> insert into aliases values (1000,12,'multik@test.ru','/var/spool/vmail/test.ru_multik/','testpassword','info');

 1000     - ,      
UID  .  RedHat  UID   500,  
,  500   -  .  12 - 
GID  mail   .

,    . ,   
  postfix    -    
      .

 ,         .

# mkdir /var/spool/vmail
# chown nobody.mail /var/spool/vmail
# chmod 770 /var/spool/vmail

 ,      :

$ telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.test.ru ESMTP Postfix
mail from: multik@test.ru
250 Ok
rcpt to: multik@test.ru
250 Ok
data
354 End data with <CR><LF>.<CR><LF>
hello
.
250 Ok: queued as 252BFEEAE6

 /var/log/messages    :

Jun 28 16:24:21 multik postfix/smtpd[21863]: connect from multik.ip-tel.int[127.0.0.1]
Jun 28 16:24:23 multik postfix/smtpd[21863]: 252BFEEAE6: client=multik.ip-tel.int[127.0.0.1]
Jun 28 16:24:32 multik postfix/cleanup[21919]: 252BFEEAE6: message-id=<20020628122423.252BFEEAE6@mail.test.ru>
Jun 28 16:24:32 multik postfix/qmgr[21762]: 252BFEEAE6: from=<multik@test.ru>, size=340, nrcpt=1 (queue active)
Jun 28 16:24:32 multik postfix/virtual[21921]: 252BFEEAE6: to=<multik@test.ru>, relay=virtual, delay=9, status=sent (maildir)

     ,  ,     
 .

# ls -lR /var/spool/vmail
/var/spool/vmail:
 4
drwx------    5 1000     mail         4096  28 16:26 test.ru_multik

/var/spool/vmail/test.ru_multik:
 12
drwx------    2 1000     mail         4096  28 16:26 cur
drwx------    2 1000     mail         4096  28 16:26 new
drwx------    2 1000     mail         4096  28 16:26 tmp

/var/spool/vmail/test.ru_multik/cur:
 0

/var/spool/vmail/test.ru_multik/new:
 4
-rw-------    1 1000     mail          389  28 16:26 1025267217.21935_0.multik.ip-tel.int

/var/spool/vmail/test.ru_multik/tmp:
 0

    IMAP  POP3 .  
     . (  :     sendmail
   pop3  Outlook' ?)

   Courier-IMAP

# tar zxvf courier-imap-1.5.1.tar.gz
# adduser courier
# chown courier.courier courier-imap-1.5.1
# cd courier-imap-1.5.1
# su - courier
$ cd /{ }/courier-imap-1.5.1
$ ./configure
$ make

   ,      , 
  :

$ authlib/authinfo
AUTHENTICATION_MODULES="authdaemon"
AUTHDAEMONMODULELIST="authcustom authcram authmysql authuserdb authpam"
SASL_AUTHENTICATION_MODULES="CRAM-SHA1 CRAM-MD5 PLAIN LOGIN"

    authmysql.  ,   .

 -  courier   : 
$ exit
# make install
# make install_configure

    :

# cd /usr/lib/courier-imap/etc/
# cp authdaemonrc.dist authdaemonrc

 authdaemonrc -  

authmodulelist="authcustom authcram authuserdb authmysql authpam"

       .
 
authmodulelist="authmysql"

   .
 
 ,   MySQL    :

# cat > authmysqlrc
MYSQL_SERVER            localhost
MYSQL_USERNAME          postfix
MYSQL_PASSWORD          postfix
MYSQL_PORT              3306
MYSQL_DATABASE          mail
MYSQL_USER_TABLE        aliases
MYSQL_CLEAR_PWFIELD     password
DEFAULT_DOMAIN          test.ru
MYSQL_UID_FIELD         id
MYSQL_GID_FIELD         gid 
MYSQL_LOGIN_FIELD       alias
MYSQL_HOME_FIELD        maildir
MYSQL_NAME_FIELD        info
MYSQL_MAILDIR_FIELD     maildir
^D

 DEFAULT_DOMAIN ,    ,  
     . ,  , 
   .

  pop3.

/usr/lib/courier-imap/libexec/pop3d.rc start

       .

:

# telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Hello there.
user multik@test.ru
+OK Password required.
pass testpassword
+OK logged in.
list
+OK POP3 clients that break here, they violate STD53.
1 400
.
quit
+OK Bye-bye.
Connection closed by foreign host.

 ,   .      
.

 maillog      :

Jun 28 17:27:17 multik pop3d: LOGIN, user=multik@test.ru, ip=[::ffff:127.0.0.1]
Jun 28 17:27:24 multik pop3d: LOGOUT, user=multik@test.ru, ip=[::ffff:127.0.0.1], top=0, retr=0
 
 -   .   
imap   pop,    
  .

    .           
    .  DrWeb.

  drweb.ru :
 
drweb-4.28.1-linux.tgz 
drweb-postfix-4.28.4-linux.tgz

  .     rpm  -   
.

,       .

# cd /opt/drweb
# ./drweb
Key file: /opt/drweb/drweb.key
Registration info:
0100003942
Evaluation Key (ID Anti-Virus Lab. Ltd, St.Petersburg) 
This is an EVALUATION version with limited functionality!
To get your registration key, call regional dealer.
Loading /var/drweb/bases/drwebase.vdb - Ok, virus records: 29405

 , drweb    .    
  ,    .      .
       .  
  -       
.

  /opt/drweb/doc/postfix/readme.rus

  drweb     postfix:

# adduser drweb
# mkdir /var/spool/drweb
# chown drweb.drweb /var/spool/drweb
# chmod 770 /var/spool/drweb

 /etc/postfix/master.cf,      DrWeb:

  smtp          inet  n       -       n       -       50      smtpd -o content_filter=filter:dummy

    :

filter    unix  -       n       n       -       -       pipe                    
  flags=R user=drweb argv=/opt/drweb/drweb-postfix -f ${sender} -- ${recipient}

     /etc/drweb/drweb_postfix.conf

    :

SkipObject = pass
    ,  drweb  .

MailbombObject = pass
  ,    ,   
  .       
  ,    . DrWeb  
   .

AdminMail = root@test.ru
    

FilterMail = DrWeb-DAEMON@ip-tel.ru
          .

 :

SenderNotify = no
     -  90%     
  .    ,   
   .

  /etc/rc.d/drwebd  /etc/init.d/drwebd    ntsysv
 chkconfig   drweb   . , 
 drweb  rpm,    .  ,   
.

     :

cd /var/drweb
chown -R drweb.drweb *

   drweb:

/etc/init.d/drwebd start
Starting Dr. Web daemon...Key file: /opt/drweb/drwebd.key
Registration info:
0100003943
Evaluation Key (ID Anti-Virus Lab. Ltd, St.Petersburg) 
This is an EVALUATION version with limited functionality!
To get your registration key, call regional dealer.
Loading /var/drweb/bases/drwebase.vdb - Ok, virus records: 29405
Daemon is installed, TCP socket created on port 3000

    /opt/drweb/drweb-postfix.  
   -   ,    
 .      :

Jun 29 13:41:08 multik drweb-postfix: load configuration from /etc/drweb/drweb_postfix.conf
Jun 29 13:41:08 multik drweb-postfix: Actions: infected=Q, suspicious=Q, skip=P, mailbomb=P, scanning_error=T, processing_error=R, empty_from=C, spam_filter=P
Jun 29 13:41:08 multik drweb-postfix: dwlib: read_conf(/etc/drweb/drweb_postfix.conf): successfully loaded
Jun 29 13:41:08 multik drweb-postfix: dwlib: startup: set timeout for whole session to 60000 milliseconds (-1 means infinite)
Jun 29 13:41:08 multik drweb-postfix: drweb-pipe: [2250] started ...

.   .  postfix  drweb   
 .  ,  - .   
  ,    .

    .      .   
      .    DrWeb 
,   perl.     String::CRC32. 
       man CPAN    install
  .        :

    http://www.cpan.org/modules/by-module/String/String-CRC32-1.2.tar.gz

 :

# tar zxvf String-CRC32-1.2.tar.gz
# cd String-CRC32-1.2
# perl Makefile.PL
# make
# make test
# make install

:
# cd /opt/drweb/update
# ./update.pl

update.pl       DrWeb,    
 drwebd,   .       
 :

Key file: /opt/drweb/drweb.key
Registration info:
0100003942
Evaluation Key (ID Anti-Virus Lab. Ltd, St.Petersburg) 
This is an EVALUATION version with limited functionality!
To get your registration key, call regional dealer.
Loading /var/drweb/bases/drwtoday.vdb - Ok, virus records: 173
Loading /var/drweb/bases/drw42807.vdb - Ok, virus records: 33
Loading /var/drweb/bases/drw42806.vdb - Ok, virus records: 57
Loading /var/drweb/bases/drw42805.vdb - Ok, virus records: 133
Loading /var/drweb/bases/drw42804.vdb - Ok, virus records: 123
Loading /var/drweb/bases/drw42803.vdb - Ok, virus records: 73
Loading /var/drweb/bases/drw42802.vdb - Ok, virus records: 143
Loading /var/drweb/bases/drw42801.vdb - Ok, virus records: 76
Loading /var/drweb/bases/drwebase.vdb - Ok, virus records: 29405

,     drweb   . 
     update.pl  crontab.    
 .  :      
 drweb.       DrWeb,   
    . 

   -  www-:

    SquirellMail  http://www.squirrelmail.org/ 
   .    
 Apache c PHP.        . 
    ,   .  ,
     .   -  SquirellMail
  imap  -    .

       :

1 - ,      .    -
  ,   drweb, postfix, courier pop3 /
imap c mysql.   update'     . 
      -     - 
  ""?       
  drweb.

2 - ,   MySQL  DrWeb   .

  .       ,  
.

      .       Apache  
PHP,     WWW -    
.      MySQL   :


mysql> desc admins;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| login    | varchar(20) | YES  |     | NULL    |       |
| password | varchar(20) | YES  |     | NULL    |       |
| rights   | int(6)      | YES  |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+
3 rows in set (0.04 sec)

      'admin','password',0. 

        , 
       .

    3 . auth.php.txt 
global.php.txt  index.php.txt

 .php.txt   -      . 
      ,  .   
global.php. ,    .    - , 
     admins.

      .   " ", 
  ,      . .

 !

 ,     -  .

    :
$ telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.test.ru ESMTP Postfix
ehlo multik
250-mail.test.ru
250-PIPELINING
250-SIZE 10240000
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-XVERP
250 8BITMIME

       :
 
250-AUTH LOGIN PLAIN DIGEST-MD5 CRAM-MD5
250-AUTH=LOGIN PLAIN DIGEST-MD5 CRAM-MD5

   ,  -    ( ,
TheBat  stuphead)      . 
 !     ? 

    ,  Cyrus-SASL.  , 
  .... ,    .  sasldb  
 . :

 /etc/sasldb   (  sasldblistusers) 
  postfix    DIGEST-MD5  CRAM-MD5.   -
  .

  sasldb    ,    
 LOGIN, DIGEST-MD5  CRAM-MD5   sasldb,   ,
   pwcheck_method. ,      
     (Outlook  Mozilla -  
 -      PLAIN),    
      ,   
:

saslpasswd -c -u `postconf -h myhostname` username

   SASL. , ,   v2    ,  
v2    -,   postfix    
 Cyrus-SASL v2.

Courier-IMAP  SASL  ,      .

   . !

(c) 2002   multik@multik.ru
