| 511 | | }}} |
| 512 | | 1. users テーブルに、符号化されたパスワードのためのフィールドと、 salt のためのフィールドを追加。ハッシュ関数は SHA1、 salt は 5文字とする。 |
| 513 | | {{{ |
| 514 | | mysql> alter table users add (passwd char(40), salt char(5)); |
| 515 | | }}} |
| 516 | | 1. salt を設定する。ランダムな 5文字を設定する方法はいくつか考えられるかも知れないが、とりあえず以下のような感じでやってみた。ちなみに plain_passwd が NULL になっているアカウントは、届いたメールを転送するだけで送受信に使う予定のないアカウントなので、 salt は設定していない。 |
| 517 | | {{{ |
| 518 | | mysql> update users set salt = substring(encrypt(rand()), 3, 5) where plain_passwd is not null; |
| 519 | | }}} |
| 520 | | 1. salt を元に、平文のパスワードを符号化する。 SHA1() 関数も CONCAT() 関数も引数が NULL ならよしなに NULL を返してくれるので、 WHERE 句は不要。 |
| 521 | | {{{ |
| 522 | | mysql> update users set passwd = sha1(concat(salt, plain_passwd)); |
| 523 | | }}} |
| 524 | | 1. 平文のパスワードはもはや不要。捨ててしまえ。 |
| 525 | | {{{ |
| 526 | | mysql> alter table users drop plain_passwd; |
| 527 | | }}} |
| | 511 | |
| | 512 | mysql> update users set uid=XXX, gid=XXX where userid='toshiyuki.murayama'; |
| | 513 | mysql> quit |
| | 514 | |
| | 515 | (...他のユーザーも) |
| | 516 | }}} |
| | 517 | |
| | 518 | この辺の作業は流石にターミナル 2つ開いてやった方がいいかもね。あんまりユーザー数多いならスクリプト書いた方がいいかも…。 |
| | 585 | |
| | 586 | Maildir 形式の設定は conf.d/10-mail.conf にて。 |
| | 587 | |
| | 588 | {{{ |
| | 589 | # vim /etc/dovecot/conf.d/10-mail.conf |
| | 590 | |
| | 591 | mail_location = maildir:~/Maildir |
| | 592 | }}} |
| | 593 | |
| | 594 | 認証周りの設定は conf.d/10-auth.conf にて。 |
| | 595 | |
| | 596 | {{{ |
| | 597 | # vim /etc/dovecot/conf.d/10-auth.conf |
| | 598 | |
| | 599 | # 平文認証。通信路は SSL で保護されているので無問題。むしろ生のパスワードが渡されないと SQL で認証できない。 |
| | 600 | auth_mechanisms = plain |
| | 601 | |
| | 602 | # 認証には SQL を使用するので、挿入するファイルを変更 |
| | 603 | #!include auth-system.conf.ext # ←コメントアウト |
| | 604 | !include auth-sql.conf.ext # ←こっちのコメントアウトを外す |
| | 605 | }}} |
| | 606 | |
| | 607 | それから SSL 関連の設定は conf.d/10-ssl.conf にて行う。 |
| | 608 | |
| | 609 | {{{ |
| | 610 | # vim /etc/dovecot/conf.d/10-ssl.conf |
| | 611 | |
| | 612 | ssl = yes |
| | 613 | ssl_cert = </etc/httpd/conf/ssl/developer.harapeko.jp.crt |
| | 614 | ssl_key = </etc/httpd/conf/ssl/developer.harapeko.jp.key |
| | 615 | ssl_ca = </etc/httpd/conf/ssl/intermediate.crt |
| | 616 | }}} |
| | 617 | |
| | 618 | ここまでの設定に関しては、以下のサイトが参考になった。 |
| | 619 | |
| | 620 | * [http://d.hatena.ne.jp/defiant/20110421/1303362615 dovecot-2.0.x ハマリ道 - defiantの日記] |
| | 621 | |
| | 622 | そして、 SQL 認証に関する設定。これは conf.d/10-auth.conf が include しているファイル conf.d/auth-sql.conf.ext の中で、更に conf.d/dovecot-sql.conf.ext ファイルを、変数が設定されたファイルとして参照しているので、そいつを作成してその中に記述する。 |
| | 623 | |
| | 624 | {{{ |
| | 625 | # vim /etc/dovecot/conf.d/dovecot-sql.conf.ext |
| | 626 | |
| | 627 | driver = mysql |
| | 628 | connect = host=localhost dbname=mailusers user=mailusers password=パスワード |
| | 629 | password_query = select userid as username, domain, plain_passwd as password from users where userid = '%n' and domain = '%d' |
| | 630 | user_query = select home, uid, gid from users where userid = '%n' and domain = '%d' |
| | 631 | }}} |
| | 632 | |
| | 633 | 以上で設定は完了。起動し、デフォルトで起動するようにする。 |
| | 634 | |
| | 635 | {{{ |
| | 636 | # /etc/init.d/dovecot start |
| | 637 | # chkconfig --add dovecot |
| | 638 | # chkconfig dovecot on |
| | 639 | }}} |
| | 640 | |
| | 641 | === Submission over TLS の設定 === |
| | 642 | |
| | 643 | cyrus-SASL と SQL auxprop プラグインはすでにインストールされていた。 MD5 認証用プラグインは今回は使わないのでインストールしない。 |
| | 644 | |
| | 645 | 設定ファイルは前回とは異なり、 /etc/sasl2/smtpd.conf 以外の 2つのファイルは削除されていた。安心して左記のファイルのみを編集する。 |
| | 646 | |
| | 647 | {{{ |
| | 648 | # vim /etc/sasl2/smtpd.conf |
| | 649 | |
| | 650 | pwcheck_method: auxprop |
| | 651 | auxprop_plugin: sql |
| | 652 | mech_list: plain |
| | 653 | sql_engine: mysql |
| | 654 | sql_hostnames: localhost |
| | 655 | sql_user: mailusers |
| | 656 | sql_passwd: パスワード |
| | 657 | sql_database: mailusers |
| | 658 | sql_select: select plain_passwd as password from users where userid = '%u' |
| | 659 | }}} |
| | 660 | |
| | 661 | こっちも mech_list は plain のみとした。 |
| | 662 | |
| | 663 | さらに main.cf を編集。 |
| | 664 | |
| | 665 | {{{ |
| | 666 | # vim /etc/postfix/main.cf |
| | 667 | |
| | 668 | # 以下の行を追加 |
| | 669 | smtpd_sasl_auth_enable = yes |
| | 670 | smtpd_sasl_security_options = noanonymous # noplaintext は外した。 |
| | 671 | smtpd_sasl_local_domain = $myhostname |
| | 672 | smtpd_tls_cert_file = /etc/httpd/conf/ssl/developer.harapeko.jp.crt |
| | 673 | smtpd_tls_key_file = /etc/httpd/conf/ssl/developer.harapeko.jp.key |
| | 674 | smtpd_tls_CAfile = /etc/httpd/conf/ssl/intermediate.crt # ルート CA 証明書の指定を追加 |
| | 675 | smtpd_use_tls = yes |
| | 676 | smtpd_tls_auth_only = yes |
| | 677 | smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination |
| | 678 | }}} |
| | 679 | |
| | 680 | そして postfix を再起動…。 |
| | 681 | |
| | 682 | {{{ |
| | 683 | # /etc/init.d/postfix restart |
| | 684 | }}} |