Rgrey

はじめに_

Postfixにおいて、S25R(大雑把に逆引きしてメールサーバと思えないサーバからのメールを拒否する正確にはここを参照のこと)とGreylist(SPAM業者はメールを再送させないというのを逆手にとる方法。正確にはここ参照のこと)の二つの方法のいいとこどりをした方法だそうである。

佐藤 潔さんが提案された方法で、曰く

>駆除率を上げるのではなく、フィルタリングによる悪影響を最小限にするための追加と考えてください。

とのこと。共用のメールサーバの重要な点は迷惑をかけないという一点にあるのですごく共感。

このページで述べられているPostfixによるRgreyを行ってみる。

参考_

環境_

  • Solaris 10
  • Berkeley DB 4.4
  • Perl 5.8

Berkeley DB_

まずGNU libtoolとGNU autoconfをインストール。Ring Serverなどからダウンロードする。

	% gzip -dc libtool*.tar.gz | tar xvf -
	% cd libtool*
	% ./configure |& tee config.log
	% make |& tee make.log
	% su
	# make install
% gtar xvfz autoconf-2.57.tar.gz
% cd autoconf-2.57
% ./configure
% make |& tee make,log
% make check
% su
# make install

[http://www.oracle.com/technology/software/products/berkeley-db/db/index.html

Oracle Berkeley DB]からダウンロード

% gzip -dc db-**.tar.gz | tar xvf -
% cd build_unix
% env CC=gcc ../dist/configure |& tee config.log
% make |& tee make.log
% su
# make install

Perlのインストール_

  • 以下のパッケージが入っているかを確認する
    • SUNWbtool,SUNWsprot, SUNWtoo,SUNWhea, SUNWarc, SUNWlibm, SUNWlibms, SUNWdfbh,SUNWcg6h, SUNWxwinc, SUNWolinc (64 bitなら: SUNWarcx, SUNWbtoox, SUNWdplx, SUNWscpux,SUNWsprox, SUNWtoox, SUNWlmsx, SUNWlmx, SUNWlibCx)
    • Berkeley DB(推奨程度)
    • zlib (いれて置いた方がよい)
  • /usr/ccs/binにパスが通っている必要がある
  • /usr/ucbにパスが通っていないほうがよい、通すのならばgccの パスの方を先にする
  • /usr/local/libなどにもパスを通す。Berkeley DBを使用する場 合はそういうところにもパスを通す
  • LD_LIBRARY_PATHに/usr/libを付け加えないこと
          env LD_LIBRARY_PATH = /usr/local/lib
    
	% gzip -cd perl-***.tar.gz | tar xvf -
	% cd perl***
	% sh Configure -Dcc='gcc -B/usr/ccs/bin/' -de |& tee config.log
	% make |& tee make.log
	% make test
	% su
	# make install

Perlモジュールのインストール_

CPANからインストールする。ただし、BerkeleyDBモジュールのインストールは失敗したので手動でおこなった。

# /usr/local/bin/perl -MCPAN -e shell
cpan> install Net::Server
cpan> install IO::Multiplex
cpan> install BerkeleyDB
% cd ~/.cpan/build/Berkeley-**
% gmake clean

config.inのBerkeleyDBのincludeファイルのある場所を訂正する。

% perl Makefile.PL

エラーが出るけど気にしない。

% gmake 
% gmake test
# gmake install

Postfixのインストール_

これのとおりにインストールする。

http://www.postfix-jp.info/trans-2.3/jhtml/INSTALL.html

概略

% unsetenv LD_LIBRARY_PATH
% make -f Makefile.init makefiles
% make
# mv /usr/sbin/sendmail /usr/sbin/sendmail.OFF
# mv /usr/bin/newaliases /usr/bin/newaliases.OFF
# mv /usr/bin/mailq /usr/bin/mailq.OFF
# chmod 755 /usr/sbin/sendmail.OFF /usr/bin/newaliases.OFF \
    /usr/bin/mailq.OFF
# groupadd postfix
# groupadd postdrop
# useradd -g postfix -d /no/where postfix
# make install

/etc/postfixにあるmain.cfの編集

[gotoh@hilbert postfix]# diff main.cf.org main.cf
70a71
> myhostname = hogehoge.jp
77c78
< #mydomain = domain.tld
---
> mydomain = hogehoge.jp
93c94
< #myorigin = $mydomain
---
> myorigin = $mydomain
107c108
< #inet_interfaces = all
---
> inet_interfaces = all
154c155
< #mydestination = $myhostname, localhost.$mydomain, localhost
---
> mydestination = $myhostname, $mydomain, localhost.$mydomain, localhost
256a258
> mynetworks = 192.168.11.1/28, 127.0.0.0/8
307a310
> relayhost = [192.168.11.1]
375c378
< #alias_maps = dbm:/etc/aliases
---
> alias_maps = dbm:/etc/aliases
385c388
< #alias_database = dbm:/etc/aliases
---
> alias_database = dbm:/etc/aliases

/var/svc/manifest/network/にマニフェスと作成 マニフェスとは以下のサイトを参考にして作る

Solaris10で行こう! - kumo.jp

作ったら以下のようにする

# svccfg -v import /var/svc/manifest/network/postfix.xml
# svcs -a | grep postfix
# svcs -a | grep sendmail
# svcadm disable sendmail
# svcadm enable postfix

実際にメールを送ってみる

# mailx MAIL_ADDRESS

Postgreyのインストール_

Postgreyのインストール方法を参考にインストール。

ダウンロードしてきて解凍。

% gtar xvfz postgrey-1.27.tar.gz
% cd postgrey-1.27
% cp postgrey postgrey.org

postgreyを編集する。(参考

% diff postgrey postgrey.org
1c1
< #!/usr/local/bin/perl -T -w
---
> #!/usr/bin/perl -T -w
450,451c450
<             #syslog_logsock   => $^O eq 'solaris' ? 'inet' : 'unix',
<             syslog_logsock   => 'stream',
---
>             syslog_logsock   => $^O eq 'solaris' ? 'inet' : 'unix',

続いてファイルを所定の場所においていく

# cp postgrey /usr/local/sbin/
# mkdir /var/spool/postfix/postgrey
# groupadd postgrey
# useradd -d /no/home -s /no/shell postgrey
# chown postgrey:postgrey /var/spool/postfix/postgrey/
# cp postgrey_whitelist_clients postgrey_whitelist_recipients /etc/postfix

参考ページにかかれているpostgrey_greylist_clientsがどこにあるのかわからにのでとりあえず、touchでさくせいしておく

# touch /etc/postfix/postgrey_greylist_clients

/lib/svc/method/postgreyを作成する。

#!/sbin/sh
. /lib/svc/share/smf_include.sh

POSTGREY=/usr/local/sbin/postgrey
SOCKET=--inet=127.0.0.1:10023
PIDFILE=/var/run/postgrey.pid
WHITELIST="--whitelist-clients=/etc/postfix/postgrey_whitelist_clients --whiteli
st-recipients=/etc/postfix/postgrey_whitelist_recipients"

case "$1" in 
'refresh')
        if [ ! -f $PIDFILE ]; then
                exit $SMF_EXIT_MON_OFFLINE
        fi
        kill -HUP `cat $PIDFILE` 
        ;;

'start')
        if [ ! -d /etc/postfix ]; then
                exit $SMF_EXIT_ERR_CONFIG
        fi
        $POSTGREY $SOCKET \
           -d --pidfile=$PIDFILE $WHITELIST
        ;;

'stop')
        if [ ! -f $PIDFILE ]; then
                exit $SMF_EXIT_MON_OFFLINE
        fi
        kill -9 `cat $PIDFILE`
        ;;

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

その後、実行権限をつける

chmod 755 /lib/svc/method/postgrey

マニュフェストpostgrey.xmlを作る(Solaris 10 の SMFを参考につくった)

<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type='manifest' name='postgrey'>

<service
    name='network/postgrey'
    type='service'
    version='1'>

    <single_instance />

    <dependency
        name='postfix'
        grouping='require_all'
        restart_on='none'
        type='service'>
        <service_fmri value='svc:/network/postfix' />
    </dependency>

    <instance name='postgrey' enabled='false'>

        <exec_method
            type='method'
            name='start'
            exec='/lib/svc/method/postgrey start'
            timeout_seconds='120' />

        <exec_method
            type='method'
            name='stop'
            exec='/lib/svc/method/postgrey stop'
            timeout_seconds='60' />

        <exec_method
            type='method'
            name='refresh'
            exec='/lib/svc/method/postgrey refresh'
            timeout_seconds='60' />

        <property_group name='startd' type='framework'>
            <propval name='ignore_error' type='astring'
                value='core,signal' />
        </property_group>

        <property_group name='general' type='framework'>
            <propval name='action_authorization' type='astring'
                value='solaris.smf.manage.postgrey' />
        </property_group>

        <template>
            <common_name>
                <loctext xml:lang='C'>
                    postgrey
                </loctext>
            </common_name>
            <documentation>
                <manpage title='postgrey' section='1M'
                    manpath='/usr/local/man' />
            </documentation>
        </template>

    </instance>

    <stability value='Unstable' />

</service>

</service_bundle>

作ったら以下のようにする

# svccfg -v import postgrey.xml
# svcs -a | grep postgrey
# svcadm enable postgrey

Rgreyの設定_

Rgrey - S25R + greylistingを参考に/etc/postfix/main.cfを書き換える。

main.cfに以下を加える(ただし、これは運用環境により異なります)

## for Rgrey
smtpd_restriction_classes = check_greylist
check_greylist = check_policy_service inet:10023
smtpd_recipient_restrictions = check_client_access regexp:/etc/postfix/check_client_fqdn

次に/etc/postfix/check_client_fqdnを用意します。

/^unknown$/                                  check_greylist
/^[^\.]*[0-9][^0-9\.]+[0-9]/                 check_greylist
/^[^\.]*[0-9]{5}/                            check_greylist
/^([^\.]+\.)?[0-9][^\.]*\.[^\.]+\..+\.[a-z]/ check_greylist
/^[^\.]*[0-9]\.[^\.]*[0-9]-[0-9]/            check_greylist
/^[^\.]*[0-9]\.[^\.]*[0-9]\.[^\.]+\..+\./    check_greylist
/^(dhcp|dialup|ppp|adsl)[^\.]*[0-9]/         check_greylist

以上で設定終わり。

# postfix reload

戻る_