認証システムは清く正しく美しく

新しいさらに詳細なエントリーを投稿しました。
以下の内容は古いものになります。
以前までメールサーバーの送信時の認証システムをpostfix&DracdでPOP befor smtpで運用していた。
メカニズムとしてはPOPでメールの受信に成功したリモートホストのIPアドレスをsyslogから読んで、データベースに登録し、そのデータベースにあるホストからのメールの送信を許可するというもの。
これはなんというか、いかにも後付け感というか、増設感があって無理やりっぽくてなんかもひとつカッコよくないし美しくない。
ほかの認証システムにはSMTP-AUTHという技術があり、これは送信時にSMTPサーバーで認証するというもので非常にスマートな方法だが、以前から何度も挑戦するもコンパイルに失敗していて諦めていた。
で、とうとうこれに成功したので、(しかもSUNのccで)インストールの方法を書いてみる。
環境はultra5 + solaris10(デベロッパー)+ SunStudio11 で postfix-2.2.8+cyrus-sasl-2.1.21をビルド


必要条件:openssl(solaris10でデフォルトでインストールされているopensslではライブラリが足りないので、ソースからコンパイルのこと)
postfixでのSMTP-AUTHに必要なもの
postfix(もちろん) cyrus-sasl-2
コンパイルの方針
コンパイラはSunのccで
cyrus-sasl2 は/usr/local/sasl2 以下に、postfixは/usr/local/postfix以下に。
前準備
postfixの動作するユーザー postfix グループpostfix postdropを作っておく
まずsaslのインストール

$export CC=/opt/SUNWspro/bin/cc
$export CFLAGS=’-I/include -I/usr/sfw/include -I/usr/include -I/opt/sfw/include -I/opt/SUNWspro/include -I/usr/local/include’
$export LDFLAGS=’-L/usr/lib -L/lib -L/usr/sfw/lib -L/opt/sfw/lib -L/usr/local/lib’
$export F77=/opt/SUNWspro/bin/f77
$export CXX=/opt/SUNWspro/bin/CC
解凍したソースツリー上で
$ ./configure –with-saslauthd=/var/cyrus –with-pwcheck=/var/cyrus –enable-login –disable-otp –disable-krb4 –disable-gssapi –disable-anon –with-dblib=none –enable-static –disable-digest –disable-srp –prefix=/usr/local/sasl2 –with-openssl=/usr/local/ssl –prefix=/usr/local/sasl2
$dmake
make時に
/opt/SUNWspro/bin/cc -DHAVE_CONFIG_H -DSASLAUTHD_CONF_FILE_DEFAULT=\”/usr/local/sasl2/etc/saslauthd.conf\” -I. -I. -I.. -I. -I. -I. -I./include -I./include -I./../include -I/include -I/usr/sfw/include -I/usr/include -I/opt/sfw/include -I/opt/SUNWspro/include -I/usr/local/include -c `test -f ‘auth_getpwent.c’ || echo ‘./’`auth_getpwent.c
“/usr/include/crypt.h”, line 36: syntax error before or at: (
“/usr/include/crypt.h”, line 36: syntax error before or at: const
“/usr/include/crypt.h”, line 36: syntax error before or at: )
“/usr/include/crypt.h”, line 36: warning: syntax error: empty declaration
cc: acomp failed for auth_getpwent.c
gmake[3]: *** [auth_getpwent.o] Error 2
gmake[3]: Leaving directory `/home/bbr/src/cyrus-sasl-2.1.21/saslauthd’
gmake[2]: *** [all] Error 2
gmake[2]: Leaving directory `/home/bbr/src/cyrus-sasl-2.1.21/saslauthd’
gmake[1]: *** [all-recursive] Error 1
gmake[1]: Leaving directory `/home/bbr/src/cyrus-sasl-2.1.21′
gmake: *** [all] Error 2
というエラーが出たが、/usr/include/crypt.hなどというファイルはないので、ソースツリー以下のsaslauthd/auth_getpwent.cのcrypt.hをインクルードしている行をコメントアウトしたらコンパイルが通った。無理やりっぽいけどちゃんと動くので問題なし。
具体的には #include <crypt.h> を /* #include <crypt.h> */ に書き換える。
# dmake instal
#ln -s /usr/local/sasl2/lib/* /usr/lib/
#vi /usr/local/sasl2/lib/sasl2/smtpd.conf
pwcheck_method: saslauthd
allowanonymouslogin: no
allowplaintext: yes
#mkdir /var/cyrus
#chmod 700 /var/cyrus
# chown postfix /var/cyrus

postfixのインストール

$export CC=/opt/SUNWspro/bin/cc
$export CFLAGS=’-I/include -I/usr/sfw/include -I/usr/include -I/opt/sfw/include -I/opt/SUNWspro/include -I/usr/local/include’
$export LDFLAGS=’-L/usr/lib -L/lib -L/usr/sfw/lib -L/opt/sfw/lib -L/usr/local/lib’
$export F77=/opt/SUNWspro/bin/f77
$export CXX=/opt/SUNWspro/bin/CC
解凍したソースツリー上で
$ gmake makefiles CCARGS=”-DUSE_SASL_AUTH -I/usr/local/include/sasl” AUXLIBS=”-L/usr/local/lib -R/usr/local/lib -lsasl2 -lm -lz”
(LD_LIBRARY_PATHを設定していると起こられるのではずしておく)
$ dmake
# gmake install
#vi /etc/postfix/main.cf
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain =
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, che
ck_relay_domains, reject
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
を追加。(その他の設定は各自で調べてください)
/usr/loca/postfix/sbin/postfix start

動作確認:
telnet ホスト 25
として、
220 メールサーバー名 ESMTP Postfix
ehlo test ←ここは入力する
250-メールサーバー名
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN CRAM-MD5
250-AUTH=LOGIN PLAIN CRAM-MD5
250 8BITMIME
などと帰ってきたらPLAIN CRAM-MD5でのAUTHを許可しているということなので成功。
no SASL authentication mechanisms などとsyslogにあがる時はsaslのライブラリが読めていない可能性大。

コメントする

メールアドレスが公開されることはありません。

PAGE TOP