| トップ | Solaris | FreeBSD | Gentoo | CentOS | Fedora | Windows | Tips | 自宅サーバの動作確認 | サイト内検索(Namazu) | サイト内検索(HE) |
「Postfix」を普通に外部から利用出来るようにしてしまうと不正中継に利用されてしまいます。
そこで、不正中継を行わないように「Cyrus-SASL」を利用してSMTP-AUTHの導入を行います。
また、認証にはシステムアカウントを利用します。
なお、ここでは「Cyrus-SASL」のバージョンは2.1.20、「Postfix」のバージョンは2.2.4としています。
それぞれが、2.1.22、2.5.1の場合はこちらを参照して下さい。
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.20.tar.gz <= 「Cyrus-SASL」のソースをダウンロード
Solaris% gunzip -c cyrus-sasl-2.1.20.tar.gz | tar xf - <= ダウンロードしたファイルの展開
Solaris% cd cyrus-sasl-2.1.20 <= 展開したディレクトリに移動
Solaris% ./configure \
--disable-gssapi \
--disable-krb4 \
--disable-otp \
--disable-srp \
--disable-anon \
--enable-login \
--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 |& tee configure.log
nroffでは適切に整形されない為、gnroffを使用するように変更
Solaris% vi saslauthd/Makefile <= Makefileの編集
nroff -mdoc $(srcdir)/saslauthd.mdoc > $(srcdir)/saslauthd.8
↓
gnroff -mdoc $(srcdir)/saslauthd.mdoc > $(srcdir)/saslauthd.8
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 |
データベースの設定
「Cyrus-SASL」が利用する認証データベースの設定を行います。
Solaris# vi /usr/local/lib/sasl2/smtpd.conf <= 設定ファイルの作成 pwcheck_method: saslauthd <= 認証に利用するもの mech_list: plain login <= 利用可能な認証メカニズム |
「Postfix」をSASLに対応するように再コンパイルします。
また、同時にSSLにも対応させます。
Solaris% cd /usr/local/src/postfix/postfix-2.2.4 <= 展開したディレクトリへ移動 Solaris% gmake tidy <= 以前に「Postfix」をコンパイルした場合 Solaris% gmake makefiles \ CCARGS="-DUSE_SASL_AUTH -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.2.4] <= 空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 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 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 Postfix queues. queue_directory: [/var/spool/postfix] <= 空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 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 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 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 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 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 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 destination directory for the Postfix README files. Specify "no" if you do not want to install these files. readme_directory: [no] <= 空Enter |
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 <= 匿名を許可しない 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 <= 上記以外拒否 |
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で停止する
|
「Postfix」の設定ファイルをリロードします。
Solaris# /usr/sbin/postfix reload |