「Postfix」+「Cyrus-SASL」の設定

「Postfix」を普通に外部から利用出来るようにしてしまうと不正中継に利用されてしまいます。
そこで、不正中継を行わないように「Cyrus-SASL」を利用してSMTP-AUTHの導入を行います。
また、ここでは「Cyrus-SASL」のバージョンは2.1.22、「Postfix」のバージョンは2.5.1としています。
それぞれが、2.1.20、2.2.4の場合はこちらを参照して下さい。
なお、「Berkeley DB」のインストールは完了済みとします。

「Cyrus-SASL」のインストール

ここで注意が必要なのは、tarファイルの展開時にtarコマンドだと長いファイル名があるため上手く展開が出来ず、 @LongLinkというファイルが作成されてしまいます。
その為、gtar(GNU tar)を利用して展開します。

Solaris# mkdir /usr/local/src/cyrus-sasl <= 作業用ディレクトリの作成
Solaris# chmod 777 /usr/local/src/cyrus-sasl <= 作業用ディレクトリのパーミッション変更
Solaris# exit <= 一般ユーザになる
Solaris% cd /usr/local/src/cyrus-sasl <= 作業用ディレクトリへ移動
Solaris% wget ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-sasl-2.1.22.tar.gz <= 「Cyrus-SASL」のソースをダウンロード
Solaris% gunzip -c cyrus-sasl-2.1.22.tar.gz | gtar xf - <= ダウンロードしたファイルの展開
Solaris% cd cyrus-sasl-2.1.22 <= 展開したディレクトリに移動
Solaris% ./configure \
--disable-gssapi \
--disable-krb4 \
--disable-srp \
--disable-anon \
--enable-cram \
--enable-digest\
--enable-plain \
--enable-login \
--enable-otp \
--enable-ntlm \
--with-dbpath=/usr/local/etc/sasldb2 \
--with-saslauthd=/usr/local/var/saslauthd \
--with-authdaemond=/usr/local/var/spool/authdaemon \
--with-pwcheck=/usr/local/var/pwcheck \
--with-openssl=/usr/sfw/bin \
--with-plugindir=/usr/local/lib/sasl2 \
--with-bdb-libdir=/usr/local/BerkeleyDB.4.4/lib \
--with-bdb-incdir=/usr/local/BerkeleyDB.4.4/include |& tee configure.log

crypt.hのインクルードする箇所を変更
Solaris% vi saslauthd/auth_getpwent.c <= auth_getpwent.cの編集
42行目以降を変更
#include <pwd.h>

# ifdef WITH_DES
#  ifdef WITH_SSL_DES
#   include <openssl/des.h>
#  else
#   include <des.h>
#  endif /* WITH_SSL_DES */
# endif /* WITH_DES */

#ifdef HAVE_CRYPT_H
#include <crypt.h>
#endif
/* END PUBLIC DEPENDENCIES *
↓
#include <pwd.h>

#ifdef HAVE_CRYPT_H <= 記述箇所を変更
#include <crypt.h> <= 記述箇所を変更
#endif <= 記述箇所を変更

# ifdef WITH_DES
#  ifdef WITH_SSL_DES
#   include <openssl/des.h>
#  else
#   include <des.h>
#  endif /* WITH_SSL_DES */
# endif /* WITH_DES */
/* END PUBLIC DEPENDENCIES *


Solaris% gmake |& tee make.log <= コンパイル
Solaris% su <= スーパーユーザになる
Password: <= パスワードの入力
Solaris# gmake install |& tee make-install.log <= インストール

パスの追加

「Postfix」の再コンパイルに備えて、「Cyrus-SASL」のライブラリをパスに追加します。

Solaris# crle -u -l /usr/local/lib/sasl2

ディレクトリの作成

configure時に指定したディレクトリがない場合、ディレクトリを作成します。

Solaris# mkdir /usr/local/etc
Solaris# mkdir /usr/local/var
Solaris# mkdir /usr/local/var/saslauthd
「Postfix」の再コンパイル

「Postfix」をSASLに対応するように再コンパイルします。
また、同時にSSLにも対応させます。

Solaris% cd /usr/local/src/postfix/postfix-2.5.1 <= 展開したディレクトリへ移動
Solaris% gmake tidy <= 以前に「Postfix」をコンパイルした場合
Solaris% gmake makefiles \
CCARGS="-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/local/include/sasl -DUSE_TLS -I/usr/sfw/include" \
AUXLIBS="-L/usr/local/lib -lsasl2 -L/usr/sfw/lib -lssl -lcrypto" |& tee makefile.log

Solaris% gmake |& tee make.log <= コンパイル
Solaris% su <= スーパーユーザになる
Password: <= パスワードの入力
Solaris# gmake install |& tee make-install.log <= インストール

Please specify the prefix for installed file names. Specify this ONLY
if you are building ready-to-install packages for distribution to other
machines.
install_root: [/] <= 空Enter

Please specify a directory for scratch files while installing Postfix.
You must have write permission in this directory.
tempdir: [/usr/local/src/postfix/postfix-2.5.1] <= 空Enter

Please specify the final destination directory for installed Postfix
configuration files.
config_directory: [/etc/postfix] <= 空Enter

Please specify the final destination directory for installed Postfix
administrative commands. This directory should be in the command search
path of adminstrative users.
command_directory: [/usr/sbin] <= 空Enter

Please specify the final destination directory for installed Postfix
daemon programs. This directory should not be in the command search
path of any users.
daemon_directory: [/usr/libexec/postfix] <= 空Enter

Please specify the final destination directory for Postfix-writable
data files such as caches or random numbers. This directory should not
be shared with non-Postfix software.
data_directory: [/var/lib/postfix] <= 空Enter

Please specify the destination directory for the Postfix HTML files.
Specify "no" if you do not want to install these files.
html_directory: [no] <= 空Enter

Please specify the owner of the Postfix queue. Specify an account with
numerical user ID and group ID values that are not used by any other
accounts on the system.
mail_owner: [postfix] <= 空Enter

Please specify the final destination pathname for the installed Postfix
mailq command. This is the Sendmail-compatible mail queue listing
command.
mailq_path: [/usr/bin/mailq] <= 空Enter

Please specify the destination directory for the Postfix on-line manual
pages. You can no longer specify "no" here.
manpage_directory: [/usr/local/man] <= 空Enter

Please specify the final destination pathname for the installed Postfix
newaliases command. This is the Sendmail-compatible command to build
alias databases for the Postfix local delivery agent.
newaliases_path: [/usr/bin/newaliases] <= 空Enter

Please specify the final destination directory for Postfix queues.
queue_directory: [/var/spool/postfix] <= 空Enter

Please specify the destination directory for the Postfix README files.
Specify "no" if you do not want to install these files.
readme_directory: [no] <= 空Enter

Please specify the final destination pathname for the installed Postfix
sendmail command. This is the Sendmail-compatible mail posting
interface.
sendmail_path: [/usr/lib/sendmail] <= 空Enter

Please specify the group for mail submission and for queue management
commands. Specify a group name with a numerical group ID that is not
shared with other accounts, not even with the Postfix mail_owner
account. You can no longer specify "no" here.
setgid_group: [postdrop] <= 空Enter
「Postfix」の設定

SMTP認証の為に設定ファイルを編集します。

Solaris# vi /etc/postfix/main.cf <= 設定ファイルの編集
SMTP認証の為に以下を追加
smtpd_sasl_auth_enable = yes <= SMTP認証を有効にする
smtpd_sasl_local_domain = $mydomain <= SMTP認証するローカルドメインの指定
smtpd_sasl_security_options = noanonymous, noplaintext
	・noanonymous <= 匿名を許可しない
	・noplaintext <= 暗号化されないパスワードを許可しない
broken_sasl_auth_clients = yes <= AUTHコマンドのサポートを認識できないクライアントへの対応
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
 <= SMTP認証の要求(リレーするものを設定)
	・permit_mynetworks <= mynetworksで指定されたネットワークからのリレーを許可
	・permit_sasl_authenticated <= SMTP認証を通過したものは許可
	・reject_unauth_destination <= 上記以外拒否
SMTP認証の為のSASLの設定

SMTP認証にはシステムアカウントを利用する方法と、sasldb2を利用する方法があります。
sasldb2を利用すれば、システムアカウントとは異なるパスワードを設定できますので、 こちらの方がセキュリティは高くなります。

1.システムアカウントを利用した認証(pamを利用)

pamを利用する場合、CRAM-MD5等の暗号化したパスワードが利用できない為、上記の「Postfix」の設定を変更します。

Solaris# vi /etc/postfix/main.cf <= 設定ファイルの編集
smtpd_sasl_security_options = noanonymous, noplaintext
↓
smtpd_sasl_security_options = noanonymous <= 「noplaintext」の削除

「saslauthd」の設定

認証メカニズムはPLAIN方式とLOGIN方式に限定します。

Solaris# vi /usr/local/lib/sasl2/smtpd.conf <= 設定ファイルの作成
pwcheck_method: saslauthd <= 認証に利用するもの
mech_list: plain login <=  利用可能な認証メカニズム

「Cyrus-SASL」の起動

pamを利用して起動します。

Solaris# /usr/local/sbin/saslauthd -a pam

「Cyrus-SASL」の自動起動

「Cyrus-SASL」用の起動スクリプトを作成し、ランレベル2,3の時に自動起動するようにします。

Solaris# vi /etc/init.d/cyrus-sasl <= 起動スクリプトファイルの作成
#!/sbin/sh

PS='/usr/bin/ps'
GREP='/usr/bin/grep'
AWK='/usr/bin/awk'

ALL_PID=`$PS -aef | $GREP saslauthd | $GREP -v grep | $AWK '{print $2}'`
PID=`echo $ALL_PID | $AWK '{print $1}'`

case "$1" in
'start')
        if [ -f /usr/local/sbin/saslauthd ]; then
                if [ $PID ]; then
                        echo "Cyrus-SASL has started"
                else
                        /usr/local/sbin/saslauthd -a pam
                        echo "Running: Cyrus-SASL"
                fi
        fi
        ;;

'stop')
        if [ $PID ]; then
                while [ $PID ]
                do
                        kill -9 $PID
                        ALL_PID=`$PS -aef | $GREP saslauthd | $GREP -v grep | $AWK '{print $2}'`
                        PID=`echo $ALL_PID | $AWK '{print $1}'`
                done
                echo "Stopping: Cyrus-SASL"
        else
                echo "Cyrus-SASL has stopped"
        fi
        ;;

'restart')
        $0 stop
        sleep 3
        $0 start
        ;;

'status')
        if [ $PID ]; then
                echo "Cyrus-SASL starts"
        else
                echo "Cyrus-SASL stopped"
        fi
        ;;

*)
        echo "Usage: $0 { start | stop | restart | status }"
        exit 1
        ;;

esac
exit 0


Solaris# chmod 744 /etc/init.d/cyrus-sasl <= 起動スクリプトに実行権限付加
Solaris# ln /etc/init.d/cyrus-sasl /etc/rc2.d/S87cyrus-sasl <= ランレベル2で起動する
Solaris# ln /etc/init.d/cyrus-sasl /etc/rc3.d/S87cyrus-sasl <= ランレベル3で起動する
Solaris# ln /etc/init.d/cyrus-sasl /etc/rc0.d/K37cyrus-sasl <= ランレベル0で停止する

2.sasldb2による認証

「Cyrus-SASL」が利用する認証データベースの設定を行います。

Solaris# vi /usr/local/lib/sasl2/smtpd.conf <= 設定ファイルの作成
pwcheck_method: auxprop <= 認証に利用するもの
auxprop_plugin: sasldb <= 認証プラグインの指定
mech_list: cram-md5 <= 利用可能な認証メカニズム

SASLのデータベースにユーザを追加します。

・新規登録
Solaris# saslpasswd2 -u crimson-snow.net -c kaz <= ユーザ kaz を追加
Password: <= パスワード
Again (for verification): <= パスワード(確認)

・パスワード変更
Solaris# saslpasswd2 -u crimson-snow.net kaz <= ユーザ kaz のパスワードを変更
Password: <= パスワード
Again (for verification): <= パスワード(確認)

・ユーザ削除
Solaris# saslpasswd2 -u crimson-snow.net -d kaz <= ユーザ kaz を削除

・ユーザ確認
Solaris# sasldblistusers2

SALSのデータベースをPostfixから参照できるようにします。

Solaris# chgrp postdrop /usr/local/etc/sasldb2 <= 所属グループをpostfixに変更

Solaris# chmod 640 /usr/local/etc/sasldb2 <= パーミッションを変更
「Postfix」のリロード

「Postfix」の設定ファイルをリロードします。

Solaris# /usr/sbin/postfix reload
▲ページのトップへ