次のページ 前のページ 目次へ

6. 配送ソフトウェアのインストール

6.1 Qmail v1.03

安全・高速で、利用も簡単。 これは私のお気に入りの MTA (mail transport agent) です。

現在 qmail を同梱しているディストリビューションはありません。 ここでは qmail のコンパイルとインストールについて中心に見ていきます。 これが qmail で唯一面倒な所だからです。設定はとてもわかりやすいです。

qmail の入手

http://www.qmail.org へ行き、最新版をダウンロードします。

(訳注:日本からは ミラーサイト に行くと良いでしょう。

なおソフトウェアアーカイブが ftp://ftp.jp.qmail.org/qmail/ から、作者による qmail 関連文書群の翻訳が http://www.jp.qmail.org/ からそれぞれ利用できます。)

ソースの展開

次にファイルを展開します。

mv qmail.tar.gz /usr/local/src
cd /usr/local/src ; tar -zxvf qmail.tar.gz

(訳注: qmail-1.03.tar.gz という名前かもしれません)

bz2 バージョン (圧縮率の良い新しいフォーマット) を入手した場合は、 tar の部分を次のように置き換えてください。

bunzip2 qmail.tar.bz2
tar -xvf qmail.tar

コンパイルの準備

では qmail のディレクトリに移動し、設定のデフォルト値を見てみましょう。

cd qmail; more conf-*

デフォルト値を変更する必要はないはずですが、 (例えば) インストール先のディレクトリを変えたり、 コンパイルの際のフラグをより良いものに指定したりできます。

(訳注:例えばインストールディレクトリを /usr/local/qmail にするには ``echo /usr/local/qmail > conf-qmail'' などのようにして、 conf-qmail に指定します。 詳細は同梱のドキュメントファイルを参照してください)

次にインストール先のディレクトリを作ります。

mkdir /var/qmail

Debian 以外のディストリビューションでは、qmail が使用するユーザ ID をいくつか追加する必要があるでしょう。 qmail の高いセキュリティはこれらに依存しているのです。

qmail はいくつかのモジュールに分割されていて、 それぞれは独立した UID で動作します。 このことにより、侵入者がメールシステム全体を乗っ取ったり、 root 権限を奪い取ったりするのが難しくなっています。

ユーザの追加は以下を実行するか、

   # groupadd nofiles
   # useradd -g nofiles -d /var/qmail/alias alias
   # useradd -g nofiles -d /var/qmail qmaild
   # useradd -g nofiles -d /var/qmail qmaill
   # useradd -g nofiles -d /var/qmail qmailp
   # groupadd qmail
   # useradd -g qmail -d /var/qmail qmailq
   # useradd -g qmail -d /var/qmail qmailr
   # useradd -g qmail -d /var/qmail qmails

もしくは /etc/passwd/etc/group を手作業で編集します。

Evan E. によると、 groupadd には "-g groupid" パラメータを使用する必要があったそうです(Caldera 1.2)。 使用しないと groupadd が次のエラーを出してしまうのだそうです。 "A groupwith that name already exists."

/etc/group/etc/passwd それぞれには、例えば次のような行を追加します。

        qmail:*:2107:
        nofiles:*:2108:

および

        alias:*:7790:2108::/var/qmail/alias:/bin/true
        qmaild:*:7791:2108::/var/qmail:/bin/true
        qmaill:*:7792:2108::/var/qmail:/bin/true
        qmailp:*:7793:2108::/var/qmail:/bin/true
        qmailq:*:7794:2107::/var/qmail:/bin/true
        qmailr:*:7795:2107::/var/qmail:/bin/true
        qmails:*:7796:2107::/var/qmail:/bin/true

設定を確認するために以下を実行します。

make setup check

次に qmail の設定を行います。

./config

注意してほしいのですが、このときあなたのサーバ名は DNS によって名前解決できなければいけません。 さもないと ./config は混乱してしまいます。

(訳注: DNS が無い場合などは ``./config-fast foo.bar.com'' のようにして直接サーバ名を指定することもできます。./config を実行した場合は、ホスト名や IP アドレスを DNS から直接検索して設定ファイルが生成されます)

次にいくつか alias (別名) を追加する必要があります。 qmail は /etc/alias を使用しないからです (オプションパッケージをコンパイル・インストールすれば使用するようにできます)。

これは私の設定です。

File : ".qmail-MAILER-DAEMON"
&postmaster
File : ".qmail-bin"
&root
File : ".qmail-daemon"
&root
File : ".qmail-decode"
&root
File : ".qmail-dumper"
&root
File : ".qmail-games"
&root
File : ".qmail-ingres"
&root
File : ".qmail-mailer-daemon"
&postmaster
File : ".qmail-manager"
&root
File : ".qmail-news"
&root
File : ".qmail-nobody"
&root
File : ".qmail-operator"
&root
File : ".qmail-postmaster"
&root
File : ".qmail-root"
&guylhem
File : ".qmail-system"
&root
File : ".qmail-toor"
&root
File : ".qmail-uucp"
&root
File : ".qmail-uucp-default"
|preline -dr /usr/bin/uux - -r -gC -a"${SENDER:-MAILER-DAEMON}" lm!rmail "($DEFAULT@$HOST)"

これらの各ファイルは ~alias に作る必要があります。 .qmail-root&guylhem は root 宛のメールを受け取るログイン名で置き換えます。

(訳注、ここでいう ~alias の `~'とはユーザ `alias' のホームディレクトリ、つまり /var/qmail/alias の事です)

UUCP ユーザは注意!!!!!

QMAIL FAQ の UUCP に関する記述を信用してはいけません。 私の .qmail-uucp-default を代わりに使用してください! さもなければ UUCP 接続ではどのようなメールも送ることはできないでしょう。

さて、ここで各ユーザが受け取るメールのフォーマットを決めなければなりません。

私のおすすめは以下です。

デフォルトのフォーマットを変更するには、 /var/qmail/boot の各ファイルを見て、 一番気に入ったものを /var/qmail/rc へコピーします。

homeproc は安全な選択ですが、 セキュリティを考慮すると home がより好ましいでしょう。

qmail の設定

/var/qmail/control で次のものを編集します。

defaultdomain, me, plusdomain

これら 3 つの例は qmail の凄さと設定の簡単さを示しています!

locals, rcpthosts

virtual domain name をサポートしたければ、 これらのファイルに追加の名前を加えるだけです。 追加した名前あてに送られた全てのメールはローカルのメールとして扱われます。

localsrcpthosts の違いは、 後者はローカルのエイリアスとしては扱われないということです。 これは yahoo.com や lemel.fr といった freeemail アドレスからメールを受け取る際に便利です。 またメールをそういったローカル以外のユーザへも送る、 つまり例えば someone@yahoo.com 宛のメールをローカルで処理したくない場合も便利です。

virtualdomains

これによりデフォルトの外向け送信モードを指定できます。 例えば次のようにすれば、送出メールのデフォルトを uucp ではなく smtp にできます。

#:alias-uucp

uucp で送るのであればこのようにします。

:alias-uucp

qmail のテスト

さて設定が終わりましたので、以下を実行しましょう。

sh -cf '/var/qmail/rc &'
qmail が起動します (現在稼働中の MTA を邪魔することはないです)。 次に:

echo to: mylogin | /var/qmail/bin/qmail-inject

あなたはこのメールを /var/qmail/boot/ で選択したフォーマットで受け取るはずです。

他の MTA を削除する

テストに成功したら、現行の MTA を kill しましょう。

killall -STOP daemon_name ; 子プロセスが走っている場合、killall -CONT 子プロセス名 を実行、待機、 killall -STOP を再度実行、 をいやになるまで繰り返してください。

子プロセスが存在しなければ、killall -TERM して、 killall -CONT を実行します。

その後、古い MTA をディスクから削除します (方法はインスールしたディストリビューションによります。 例えば Redhat, Caldera, Suse なら rpm -e --nodeps を、 Debian なら dpkg -r --force-depends になります)。 次に以下を実行します。

# ln -s /var/qmail/bin/sendmail /usr/lib/sendmail
# ln -s /var/qmail/bin/sendmail /usr/sbin/sendmail

次に /etc/inetd.conf の qmail-smtpd を設定します (全てを一行に書きます)。

smtp stream tcp nowait qmaild /var/qmail/bin/tcp-env tcp-env /var/qmail/bin/qmail-smtpd

SysV-init を採用していない古いディストリビューションを使っている場合は、 単にブートスクリプトに以下を追加します。

sh -cf '/var/qmail/rc &' 

追加先は普通 /etc/rc.local でしょうが、違うかもしれません。

SysV-init に準じたディストリビューション (RedHat, Caldera, Suse, Debian) の場合は、 以下のスクリプトを /etc/init.d/ に追加します。

(訳注:RedHat の場合 /etc/rc.d/init.d/ に追加します)

Debian の場合

#!/bin/sh

test -x /var/qmail/rc || exit 0

case "$1" in
  start)
     echo -n "Starting mta: "
     sh -cf '/var/qmail/rc &'
     echo "qmail."
     ;;
  stop)
     echo -n "Stopping mta: "
     killall qmail-lspawn
     echo "qmail."
     ;;
  restart)
     echo -n "Restarting mta: "
     killall -HUP qmail-lspawn
     killall -ALRM qmail-lspawn
     echo "qmail."
     ;;
  *)
     echo "Usage: /etc/init.d/qmail {start|stop|restart}"
     exit 1
esac

exit 0

RedHat の場合

#!/bin/sh
#
# qmail      This shell script takes care of starting and stopping qmail.
#
# description: qmail is a Mail Transport Agent, which is the program \
#              that moves mail from one machine to another.
# processname: qmail
# config: /var/qmail/control/

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

export PATH=$PATH:/var/qmail/bin

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -f /usr/sbin/sendmail ] || exit 0

# See how we were called.
case "$1" in
  start)
        # Start daemons.
        echo -n "Starting qmail: "
        qmail-start '|preline procmail' splogger qmail &
        touch /var/lock/subsys/qmail
        echo
        ;;
  stop)
        # Stop daemons.
        echo -n "Shutting down qmail: "
        killproc qmail-lspawn
        echo
        rm -f /var/lock/subsys/qmail
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  status)
        status qmail
        ;;
  *)
        echo "Usage: qmail {start|stop|restart|status}"
        exit 1
esac

exit 0

そしてシンボリックリンクを /etc/rcN.d/ に作ります。例えば次のようになります。

(訳注:RedHat の場合 /etc/rc.d/rcN.d/ になります。また N はランレベルを表しています)

ln -sf /etc/init.d/qmail /etc/rc1.d/K19qmail

始めの文字が K なら、このランレベル (ランレベル 1 はシングルモード、6 はリブートを表します) では qmail を kill します。 始めの文字が S ならこのランレベルでは qmail を実行します。

RedHat, Caldera, Suse では Debian のように /etc/ 直下ではなく、 /etc/rc.d/ を使用します。つまり例えば /etc//rc.d/rc1.d や /etc/rc.d/init.d のようになります。

まあこんなところでしょう、みなさん!

変更を反映するのにリブートする必要はありません (使ってるのは Linux だというのをお忘れですか? 他の安っぽい OS とは違いますよ!)。 単に次のコマンドを実行するだけです。

killall inetd
init 1

これによってシングルユーザーモードに入ります。 そして次を実行して、デフォルトのランレベル (/etc/inittab の initdefault ラベルで指定されています)に戻ります。

exit

手動で qmail スクリプトを起動する事もできますが、 "init" の方法を使えば qmail スクリプトが正しい位置にあるかどうかがわかります。 すなわち network スクリプトの後で、かつ email に依存した プログラムの前に実行されるかどうかです (例えば inn の前に起動されていないと警告が表示されます)。

6.2 Smail v3.1

smail 3.1 は、UUCP だけのサイトや、 SMTP でも一部のサイトでは デファクトスタンダードの転送エージェントのようです。 smail は設定が簡単で、ソースにパッチを当てなくてもコンパイルでき、 かなり安全です。

smail の設定

お使いのディストリビューションから smail のバイナリをインストールするか、 smail のソースを入手してコンパイルしてください (筆者は前者の方法をお勧めします)。 smail をソースから作る場合は、以下の行を os/linux ファイルに加える必要があります。 これは、正しく動作するシェルスクリプトを 'sed' に生成させるためです。

CASE_NO_NEWLINES=true 

インストールが済んだら、設定ファイルがいくつか /etc/smail ディレクトリに入っているはずです (ただし古いディストリビューションではインストール先が違うかもしれません)。 それでは、設定ファイルの編集を始めましょう!

"config" ファイル

# From
smart_path=polux
smart_transport=uux

# To
hostname=barberouge
domains=linux.lmm.com

visible_name=barberouge.linux.lmm.com
uucp_name=barberouge.linux.lmm.com

# max_message_size=512k
# auth_domains=foo.bar
# more_hostnames=barberouge.polux.freenix.fr

さてまず、メールを配送してくれるのは誰でしょうか? 筆者のマシンは UUCP (つまり uux 配送) 経由で "polux" からメールを受け取っています。 もちろん、このファイルはあなたの環境に合わせて変える必要があります。 例えば "bargw.bar.foobar.com" から "smtp" 経由でメールを受け取っている場合には、 transports ファイルは必要ありません。 この場合には "-transport_file " を定義すれば、 ファイルが不要であることを示すことができます。

また "postmaster_address = yourname" を使ったり、 "visible_name" を使って外部向けのアドレスからネットワークトポロジーを 隠したり (ゲートウェイマシンの場合)、 "more_hostnames" を使ってメールを受け取る際に使える 別名アドレスを設定したりできます。

詳しい説明については smail の文書を見てください。 また /usr/doc/smail/examples に入っている例を見て、 あなたの環境に合う例があるかどうかも調べるとよいでしょう。

"directors" ファイル

# aliasinclude - expand ":include:filename" addresses produced by alias files
# This entry and the next one are pretty much boiler-plate.  Reasons
# for making significant changes are few.  The sole purpose of these
# is to match and expand addresses of the form:
#       :include:pathname
# which may occur in alias files or mailing-list/forward files
# (produced by any director with a driver of forwardfile).
aliasinclude:
        driver = aliasinclude,          # use this special-case driver
        nobody;                         # associate nobody user with addresses
                                        #  when mild permission violations
                                        #  are encountered
        copysecure,                     # get permissions from alias director
        copyowners,                     # get owners from alias director



# forwardinclude - expand ":include:filename" addrs produced by forward files
forwardinclude:
        driver = forwardinclude,        # use this special-case driver
        nobody;
        copysecure,                     # get perms from forwarding director
        copyowners,                     # get owners from forwarding director


# aliases - search for alias expansions stored in a database
# This is the standard aliases file.  It is used for generic things,
# like mapping root, postmaster, MAILER-DAEMON and uucp to site
# admins, creating some small system alias expansions, and such.  In
# this site configuration, the aliases file is used mostly for
# machine-specific aliasing/forwarding information.  Global forwarding
# information should be put in the "forward" database.
aliases:
        driver=aliasfile,               # general-purpose aliasing director
        -nobody,                        # all addresses are associated
                                        # with nobody by default, so setting
                                        # this is not useful.
        sender_okay,                    # don't remove sender from expansions
        owner=owner-$user;              # problems go to an owner address
        file=/etc/aliases,
        modemask=002,                   # should not be globally writable
        optional,                       # ignore if file does not exist
        proto=lsearch,                  # unsorted ASCII file


# forward - search for expansions stored in a forwarding database
# This is the subdomain-wide user forwarding database.  Entries are
# maintained here for current or past users, to forward their mail to
# their preferred mail-reading machine.  The forward database is
# shipped around the TCP/IP network as changes are made, to keep the
# network consistent.
#forward:
#       driver = aliasfile,             # general-purpose aliasing director
#       -nobody,                        # all addresses are associated
#                                       # with nobody by default, so setting
#                                       # this is not useful.
#       owner = real-$user;             # problems go to an owner address
#
#       file = /etc/forward,
#       modemask = 002,
#       proto = dbm,                    # use dbm(3X) library for access


# dotforward - expand .forward files in user home directories
# For users that have an entry in the "forward" database, a ".forward"
# file is only used if it is on the "home" machine, as identified in
# the forward database.  If used, it is treated as a list of addresses
# to which mail should be delivered, rather than (or in addition to)
# the user identified in the local address.
dotforward:
        driver = forwardfile,           # general-purpose forwarding director
        owner = postmaster, nobody, sender_okay;

        file = ~/.forward,              # .forward file in home directories
        checkowner,                     # the user can own this file
        owners = root,                  # or root can own the file
        modemask = 002,                 # it should not be globally writable
        caution = daemon:root,          # don't run things as root or daemon
        # be extra careful of remotely accessible home directories
        unsecure = "~uucp:/tmp:/usr/tmp:/var/tmp"


# forwardto - expand a "Forward to " in user mailbox files
# This emulates the V6/V7/System-V forwarding mechanism which uses a
# line of forward addresses stored at the beginning of user mailbox files
# prefixed with the string "Forward to "
forwardto:
        driver = forwardfile,
        owner = postmaster, nobody, sender_okay;

        file = /var/spool/mail/${lc:user},      # point at user mailbox files
        forwardto,                      # enable "Forward to " function
        checkowner,                     # the user can own this file
        owners = root,                  # or root can own the file
        modemask = 0002,                # under System V, group mail can write
        caution = daemon:root           # don't run things as root or daemon


# user - match users on the local host with delivery to their mailboxes
user:   driver = user;                  # driver to match usernames
        transport = local               # local transport goes to mailboxes


# real_user - match usernames when prefixed with the string "real-"
# This is useful for allowing an address which explicitly delivers to a
# user's mailbox file.  For example, errors in a .forward file expansion
# could be delivered here, or forwarding loops between multiple machines
# can be resolved by using a real-username address.  Also, users that
# wish to use mail as a means of transferring data to a machine that
# is not their "home" machine can mail to real-login-name@remote.host.
real_user:
        driver = user;
        transport = local,
        prefix = "real-"                # for example, match real-root


# lists - expand mailing lists stored in a list directory
# mailing lists can be created simply by creating a file in the
# /etc/smail/lists directory.
lists:  driver = forwardfile,
        caution,                        # flag all addresses with caution
        nobody,                         # and then associate the nobody user
        owner = owner-$user;            # system V sites may wish to use
                                        # o-$user, as owner-$user may be
                                        # too long for a 14-char filename.
        file = lists/${lc:user}         # lists is under $smail_lib_dir


# owners - expand mailing lists stored in a list owner directory
# mailing lists owner lists can be created simply by creating a file
# in the /etc/smail/lists/owner directory.  Mailing list owners
# are sent locally generated errors dealing with a mailing list of the
# same name.  To create an owner list for a mailing list, create a
# file with the name of the list in /etc/smail/lists/owner.  This
# will create a list address of owner-listname, as is used by the
# "lists" director above.
owners: driver = forwardfile,
        caution,                        # flag all addresses with caution
        nobody,                         # and then associate the nobody user
        owner = postmaster;             # system V sites may wish to use
                                        # o-$user, as owner-$user may be
                                        # too long for a 14-char filename.
        prefix = "owner-",
        file = lists/owner/${lc:user}   # lists is under $smail_lib_dir


# request - expand mailing lists stored in a list request directory
# mailing lists request lists can be created simply by creating a file
# in the /etc/smail/lists/request directory.  Request addresses
# are typically used as a standard address for queries about a mailing
# list.  For example, requests for additions or deletions to a list
# will generally be sent to "list-request", which should be set up to
# forward to the appropriate person or persons.
request: driver = forwardfile,
        caution,                        # flag all addresses with caution
        nobody,                         # and then associate the nobody user
        owner = postmaster;             # system V sites may wish to use
                                        # o-$user, as owner-$user may be
                                        # too long for a 14-char filename.
        suffix = "-request",
        file = lists/request/${lc:user} # lists is under $smail_lib_dir

このファイルを変える必要はほとんどないはずです。 ただし smail を使ってメーリングリストを運用したい場合は メーリングリスト関係のオプションが必要ですし、 例えばメールの転送を無効化したければ転送関係のオプションが必要です。

"fidopaths" ファイル

.f105.n324.z2.fidonet.org       f105.n324.z2.fidonet.org!%s
.n324.z2.fidonet.org            f105.n324.z2.fidonet.org!%s
.z2.fidonet.org                 f105.n324.z2.fidonet.org!%s
.fidonet.org                    f105.n324.z2.fidonet.org!%s

このようなファイルは、 ifmail と FIDO を使っている場合だけ作成してくだ さい。

"routers" ファイル

# forces - force certain paths
# This database exists as a means of hardcoding the paths to various
# machines or domains.  It is for use in creating temporary tweaks to
# the other routing databases.  To change the database, edit the file
# maps/force.path and type "make" in the maps/ subdirectory.
forces:
        driver = pathalias,             # router to search paths file
        method = /etc/smail/maps/table; # transports are in this file
        file = forcepaths,              # file containing force path info
        proto = lsearch,                # use the sorted path file
        optional,
        reopen                          # close when not being used


uucp_neighbors:
        driver=uuname,                  # use a program which returns neighbors
        transport=uux;
        cmd="/usr/bin/uuname -a",       # specifically, use the uuname program
#        domain=uucp                    # strip ending ".uucp"


# smart_host - a partially specified smarthost director
# If the config file attribute smart_path is defined as a path from the
# local host to a remote host, then hostnames not matched otherwise will
# be sent off to the stated remote host.  The config file attribute
# smart_transport can be used to specify a different transport.
# If the smart_path attribute is not defined, this router is ignored.
smart_host:
        driver = smarthost,             # special-case driver
        transport = uux                 # by default deliver over UUCP
#       path=phreak


# ifmail - to send mails to fidonet and vice versa
ifmail:
        driver=pathalias,
        transport=ifmail;
        file=fidopaths,
        proto=lsearch

ifmail の部分は、 FIDO メール用の ifmail を使っている場合だけ書いてください。 転送モードは、 "uux" (つまり UUCP) から例えば "smtp" に変えたり、 さらには "/etc/smail/maps/table" に書かれた 「特定のマシンやドメインへのパスの直書き」 に変えることもできます。

この機能は、内部ネットワーク宛に出したメールを すぐに配送したい場合に便利です。 なぜならこういったメールはインターネットに UUCP 接続して配送する必要がないからです。

"transports" ファイル

# local - deliver mail to local users
# Tell smail to append directly to user mailbox files in the /var/spool/mail
# directory.
#local: driver = appendfile,            # append message to a file
#       -return_path,                   # include a Return-Path: field
#       local,                          # use local forms for delivery
#       from,                           # supply a From_ envelope line
#       unix_from_hack;                 # insert > before From in body
#
#       file = /var/spool/mail/${lc:user},      # use this location for Linux
#                                               # Note, mail spool must be 1777
#       file = ~/mailfile,              # use this location for better security
#       group = mail,                   # group to own file for System V
#       mode = 0660,                    # under System V, group mail can access
#       suffix = "\n",                  # append an extra newline
#       append_as_user,


# This allows each user to have a ~/.procmailrc file to control filtering
# of mail and saving mail from mail lists in separate mailboxes if they wish.
local:  +inet,
        -uucp,
        driver = pipe,                  # append message to a file
        return_path,                    # include a Return-Path: field
        local,                          # use local forms for delivery
        from,                           # supply a From_ envelope line
        unix_from_hack;                 # insert > before From in body

        cmd = "/usr/bin/procmail",      # use procmail for local delivery
        parent_env,                     # environment info from parent addr
        pipe_as_user,                   # use user-id associated with address
        umask = 0022,                   # umask for child process
#       -ignore_status,                 # exit status should be believed
#       -ignore_write_errors,           # retry on broken pipes


# pipe - deliver mail to shell commands
# This is used implicitly when smail encounters addresses which begin with
# a vertical bar character, such as "|/usr/lib/news/recnews talk.bizarre".
# The vertical bar is removed from the address before being given to the
# transport.
#pipe:  driver = pipe,                  # pipe message to another program
#       return_path, local, from, unix_from_hack;
#
#       cmd = "/bin/sh -c $user",       # send address to the Bourne Shell
#       parent_env,                     # environment info from parent addr
#       pipe_as_user,                   # use user-id associated with address
#       umask = 0022,                   # umask for child process
#       -log_output,                    # do not log stdout/stderr
#       ignore_status,                  # exit status may be bogus, ignore it
#       ignore_write_errors,            # ignore broken pipes


# file - deliver mail to files
# This is used implicitly when smail encounters addresses which begin with
# a slash or squiggle character, such as "/usr/info/list_messages" or
# perhaps "~/Mail/inbox".
#file:  driver = appendfile,
#       return_path, local, from, unix_from_hack;
#
#       file = $user,                   # file is taken from address
#       append_as_user,                 # use user-id associated with address
#       expand_user,                    # expand ~ and $ within address
#       check_path,
#       suffix = "\n",
#       mode = 0644


# uux - deliver to the rmail program on a remote UUCP site
#
# As many as five recipient addresses will be delivered to the remote
# host in one UUCP transaction.
uux:    driver = pipe,
        -uucp,
        inet,
#       uucp,                           # use UUCP-style addressing forms
        from,                           # supply a From_ envelope line
        max_addrs = 5,                  # at most 5 addresses per invocation
        max_chars = 200;                # at most 200 chars of addresses
# the -r flag prevents immediate delivery, parentheses around the
# $user variable prevent special interpretation by uux.
        cmd = "/usr/bin/uux - -r -g$grade $host!rmail $((${strip:user})$)",
#        cmd="/usr/bin/uux - $host!rmail $(($user)$)",
        ignore_write_errors,            # ignore broken pipes
        umask = 0022,
#       pipe_as_sender,


# uux_one_addr - deliver mail over UUCP to a remote host that can take
#                one address at a time.
# This is often necessary when delivering to a site running an unmodified
# version of 4.1BSD.
uux_one_addr:
        driver = pipe,
        uucp,                           # use UUCP-style addressing forms
        from;                           # supply a From_ envelope line
# the -r flag prevents immediate delivery
        cmd = "/usr/bin/uux - -r -g$grade $host!rmail (${strip:user})",
        umask = 0022,
        pipe_as_sender


queueonly:
        driver = pipe;                  # send the message to a pipe
        cmd = "/usr/lib/sendmail -Q -f $sender -bm $user",
                                        # use getmail for local delivery
        user=root,                      # execute getmail as "root"
        group=mail,                     # execute getmail as "mail"
        parent_env,                     # environment info from parent addr
        -pipe_as_user,                  # use user-id associated with address
        umask = 0007,                   # umask for child process
 
# to deliver the message.  The smtp transport is included only if BSD
# networking exists.
# The uucp attribute can be specified for transfers within the UUCP
# zone.  The inet attribute must be specified for transfers within the
# Internet.
# NOTE: This is hardly optimal, a backend should exist which can handle
#       multiple messages per connection.
# ALSO: It may be necessary to restrict max_addrs to 100, as this is the
#       lower limit SMTP requires an implementation to handle for one
#       message.
smtp:   driver=tcpsmtp,
        inet,                           # if UUCP_ZONE is not defined
#       uucp,                           # if UUCP_ZONE is defined
        -max_addrs, -max_chars;         # no limit on number of addresses

        short_timeout=5m,               # timeout for short operations
        long_timeout=2h,                # timeout for longer SMTP operations
        service=smtp,                   # connect to this service port
# For internet use: uncomment the below 4 lines
       use_bind,                       # resolve MX and multiple A records
       defnames,                       # use standard domain searching
       defer_no_connect,               # try again if the nameserver is down
       local_mx_okay,                  # fail an MX to the local host


ifmail:
        from,received,max_addrs=5,max_chars=200,
        driver=pipe;
        pipe_as_sender,
        cmd="/usr/local/bin/ifmail -x9 -r$host $((${strip:user})$)"

ifmail の部分は、 FIDO メール用の ifmail を使っている場合だけ書いてください。 それ以外には、このファイルを編集する必要はないはずです。 このファイルは配送エージェント (uux, smtp 等)を定義し、 他の設定ファイルのパラメータとして使えるようにします。

セキュリティを向上させるため、 筆者は "pipes" や "file" などをコメントアウトしている点に注意してください。

"maps/" ディレクトリ

このディレクトリには map ファイルと table ファイルが入っています:

まず map ファイルの例を示します。

#N      foo.bar foo2.bar2
#S      AT 486/RedHat Linux 1.2.13
#O      organization
#C      contact
#E      administration (email)
#T      phone
#P      address
#R
#U      hosts connected via uucp
#W      created/edited by
#
hname polux

hname linux.eu.org

hname = polux
hname = polux.linux.eu.org

繰り返しますが、このファイルはあなたの環境に合わせて編集してください (筆者は polux.linux.eu.org からメールを配送してもらっています)。

次は table ファイルの例です。

 
*       uux

異なる配送エージェントを異なるパスに向けるように定義することもできます。 例えば、"smtp" を内部ネットワークに向け、 "uux" (つまり UUCP) を世界の残りの場所に向けることができますし、 その逆の設定も可能です (筆者は出したメールは全て UUCP で送っているので、 "*" を使っています!)。

他の役立つ設定例

これまで示したファイルは、 筆者が現在自分のサイトで使っているファイルなので、 読者の皆さんが作る独自の設定ファイルの 例/雛型として使っても何の問題もないはずです。

以下に示すファイルは、 別の方法で smail を設定する際に役立つ例として用意しました。

#ident "@(#) transports,v 1.2 1990/10/24 05:20:46 tron Exp"

# See smail(5) for a complete description of the contents of this file.

# local - deliver mail to local users
#
# Tell smail to append directly to user mailbox files in the /usr/mail
# directory.
local:  driver = appendfile,            # append message to a file
        return_path,                    # include a Return-Path: field
        local,                          # use local forms for delivery
        from,                           # supply a From_ envelope line
        unix_from_hack;                 # insert > before From in body

        file = /usr/mail/${lc:user},    # use this location for System V
        group = mail,                   # group to own file for System V
        mode = 0660,                    # under System V, group mail can access
        suffix = "\n",                  # append an extra newline
        append_as_user,

# pipe - deliver mail to shell commands
#
# This is used implicitly when smail encounters addresses which begin with
# a vertical bar character, such as "|/usr/lib/news/recnews talk.bizarre".
# The vertical bar is removed from the address before being given to the
# transport.
pipe:   driver = pipe,                  # pipe message to another program
        return_path, local, from, unix_from_hack;

        cmd = "/bin/sh -c $user",       # send address to the Bourne Shell
        parent_env,                     # environment info from parent addr
        pipe_as_user,                   # use user-id associated with address
        umask = 0022,                   # umask for child process
        -log_output,                    # do not log stdout/stderr
        ignore_status,                  # exit status may be bogus, ignore it
        ignore_write_errors,            # ignore broken pipes

# file - deliver mail to files
#
# This is used implicitly when smail encounters addresses which begin with a
# slash or squiggle character, such as "/usr/info/list_messages" or perhaps
# "~/Mail/inbox".
file:   driver = appendfile,
        return_path, local, from, unix_from_hack;

        file = $user,                   # file is taken from address
        append_as_user,                 # use user-id associated with address
        expand_user,                    # expand ~ and $ within address
        suffix = "\n",
        mode = 0644

# uux - deliver to the rmail program on a remote UUCP site
#
# As many as five recipient addresses will be delivered to the remote host in
# one UUCP transaction.
uux:    driver = pipe,
        uucp,                           # use UUCP-style addressing forms
        from,                           # supply a From_ envelope line
        max_addrs = 5,                  # at most 5 addresses per invocation
        max_chars = 200;                # at most 200 chars of addresses

        # the -r flag prevents immediate delivery, parentheses around the
        # $user variable prevent special interpretation by uux.
        cmd = "/usr/bin/uux - -r -g$grade $host!rmail $((${strip:user})$)",
        umask = 0022,
        pipe_as_sender

# uux_one_addr - deliver mail over UUCP to a remote host that can take one
# address at a time.
#
# This is often necessary when delivering to a site running an unmodified
# version of 4.1BSD.
uux_one_addr:
        driver = pipe,
        uucp,                           # use UUCP-style addressing forms
        from;                           # supply a From_ envelope line

        # the -r flag prevents immediate delivery
        cmd = "/usr/bin/uux - -r -g$grade $host!rmail (${strip:user})",
        umask = 0022, pipe_as_sender

# demand - deliver to a remote rmail program, polling on demand
demand: driver = pipe,
        uucp, from, max_addrs = 5, max_chars = 200;

        # with no -r flag, try to contact remote site immediately
        cmd = "/usr/bin/uux - -g$grade $host!rmail $(($user)$)",
        umask = 0022, pipe_as_sender

# uusmtp - deliver to the rsmtp program on a remote UUCP site
#
# Deliver using a simple Batched SMTP protocol to the remote machine.
# This allows much more arbitrary addresses to be used.  It also
# removes the limit on recipient addresses per invocation of uux.
uusmtp: driver = pipe,
        bsmtp,                          # send batched SMTP commands
        -max_addrs,                     # there is no limit on the number or
        -max_chars;                     #   total size of recipient addresses.

        # supply -r to prevent immediate delivery, the recipient addresses
        # are stored in the data sent to the standard input of rsmtp.
        cmd = "/usr/bin/uux - -r -g$grade $host!rsmtp",
        umask = 0022, pipe_as_sender

# demand_uusmtp - deliver to a remote rsmtp program, polling on demand
demand_uusmtp:
        driver = pipe,
        bsmtp, -max_addrs, -max_chars;

        # with no -r flag, try to contact remote site immediately
        cmd = "/usr/bin/uux - -g$grade $host!rsmtp",
        umask = 0022, pipe_as_sender

# smtp - deliver using SMTP over TCP/IP
#
# Connect to a remote host using TCP/IP and initiate an SMTP conversation to
# deliver the message.  The smtp transport is included only if BSD networking
# exists.

# NOTE: It may be necessary to restrict max_addrs to 100, as this is the
#       lower limit SMTP requires an implementation to handle for one
#       message.
smtp:   driver = smtp,
        -max_addrs,
        -max_chars

#ident "@(#) table,v 1.2 1990/10/24 05:20:31 tron Exp"

# This file names the transports that are to be used in delivering
# to specific hosts from bargw.

#host           transport
#--------       ---------
curdsgw         demand_uusmtp   # deliver using batched SMTP
oldbsd          uux_one_addr    # 4.1BSD sites cannot take more than one addr
sun             demand          # call sun when their is mail to send
*               uux             # for all others, poll at intervals

inetd の再起動

smail を SMTP デーモンとして実行するには、 以下の設定のどちらかを /etc/inetd.conf に加えてください:

         smtp stream tcp nowait  root  /usr/bin/smtpd smtpd

または:

         smtp stream tcp nowait  root  /usr/sbin/tcpd  /usr/sbin/in.smtpd

elm を使った場合には、出したメールは自動的に送信されます。

Smail を SMTP で使用する

一般に ISP は SMTP を使っているので、 メールを送る際の問題はないはずです。 メールを送っている途中にインターネット接続が切れた場合には、 そのメールは "/var/spool/smail/input" に残ります。 次に接続が回復した時に "runq" を実行すれば、 そのメールが送られます。 ただしメールの受信には問題があります。 というのも ISP はあなただけではなく、 たくさんの顧客の面倒を見なくてはならないからです!

普通は POP プロトコルを使ってメールを受け取ることができます。 後述の POP に関する章を見てください。

6.3 時代遅れになってしまった章: Sendmail+IDA

大きなサイトには、 sendmail を選んでもいいかもしれません。 なんせ「びっくりするほど使いやすい」そうですから (qmail を知っている人には、比較対象が悪いということになるのでしょうが)。 もっとも、 sendmail+IDA と sendmail 8.x のどちらを選ぶかを決めなくてはなりません。

Linux の初心者やセキュリティ担当者への注意: 簡単に設定できる方がいいのなら smail か qmail をお試しください。 ずっと使いやすい上に、安全面でも優れています。

ソースからのインストール

お使いのディストリビューションが、 すぐに使える状態の sendmail パッケージ (RedHat, Caldera, Suse なら .rpm, Debian なら .deb) を提供してくれいていない場合には、 ソースを入手して以下の手順で作業してください。

あらかじめ書いてある hostname, aliases, smarthost の名前を、 自分のサイトのものに変更してください。 もとのファイルは uuup だけを使うサイト用になっています。 またこのサイトはドメイン化したへッダを持ち、 smart host と通信することが前提となっています。 変更が終わったら、"make yourhostname.cf" を実行し、 できあがったファイルを /etc/sendmmal.cf に移動してください。

必要なことは、 Makefile がキチンと働くように ファイルに手を入れるだけです。 .m4 ファイルを編集してから、 sendmail.cf の作成・テストを行えば OK です。

5.67a 以前のものにはたちの悪い安全上の問題があるので、 5.67b 以降のものにアップデートするべきです。 mail.debug セットが手元にあり、 syslogd を走らせている場合には、 出入りするメールメッセージのログを取っておくのもいいでしょう。 詳しくは "/etc/syslog.conf"をご覧ください。

sendmail+IDA のソースは vixen.cso.uiuc.edu にあるはずです。 1.00 カーネルあたりの Linux で利用するなら、パッチは不要です。

1.1.50 以降のカーネルで使用する場合には、もとのソースに入っている Linux 用パッチの大部分が失敗するというふざけた事態に遭遇することになります (この sendmail が古いカーネル専用だといっているわけでは「ありません」)。

どうすればいいかは明々白々です。とにかく "make" と打ち込んで、 もし何か文句を言われたら、 ソースのその行にある Linux 専用パッチをコメントアウトしてください。

sendmail+IDA を使うおつもりなら、 是非とも sendmail5.67b+IDA1.5 になさることをお勧めします。 というのも、Linux 専用パッチがもとのソースに完備している上に、 1993 年12月1日以前の古い版が抱えていた安全上の問題も解決しているからです。

すでに申し上げた通り、現在のカーネル 2.0 の場合には、 sendmail+IDA ではなく sendmail 8.x を使うべきです。

sendmail.m4 ファイル

Sendmail+IDA を利用する場合には、 sendmail.cf を直接編集するのではなく、 sendmail.m4 を設定することになります。 こちらの方法には、メールの設定が簡単という利点があります。 Smail や 昔ながらの sendmail の設定は (大抵の人は正しい設定ができない、というほどではないとしても) 極端に難しいのです。

上記の smail の例と同じ設定にする場合の sendmail.m4 ファイルは以下のようになります。

  dnl #------------------ SAMPLE SENDMAIL.M4 FILE ------------------
  dnl #
  dnl # (the string 'dnl' is the m4 equivalent of commenting out a line)
  dnl #
  dnl # you generally don't want to override LIBDIR from the compiled in paths
  dnl #define(LIBDIR,/usr/local/lib/mail)dnl    # where all support files go
  define(LOCAL_MAILER_DEF, mailers.linux)dnl    # mailer for local delivery
  define(POSTMASTERBOUNCE)dnl                   # postmaster gets bounces
  define(PSEUDODOMAINS, BITNET UUCP)dnl         # don't try DNS on these
  dnl #
  dnl #-------------------------------------------------------------
  dnl #
  dnl # names we're known by
  define(PSEUDONYMS, myhostname.subdomain.domain myhostname.UUCP)
  dnl #
  dnl # our primary name
  define(HOSTNAME, myhostname.subdomain.domain)
  dnl #
  dnl # our uucp name
  define(UUCPNAME, myhostname)dnl
  dnl #
  dnl #-------------------------------------------------------------
  dnl #
  define(UUCPNODES, |uuname|sort|uniq)dnl       # our uucp neighbors
  define(BANGIMPLIESUUCP)dnl                    # make certain that uucp
  define(BANGONLYUUCP)dnl                       #  mail is treated correctly
  define(RELAY_HOST, my_uucp_neighbor)dnl       # our smart relay host
  define(RELAY_MAILER, UUCP-A)dnl               # we reach moria via uucp
  dnl #
  dnl #--------------------------------------------------------------------
  dnl #
  dnl # the various dbm lookup tables
  dnl #
  define(ALIASES, LIBDIR/aliases)dnl            # system aliases
  define(DOMAINTABLE, LIBDIR/domaintable)dnl    # domainize hosts
  define(PATHTABLE, LIBDIR/pathtable)dnl        # paths database
  define(GENERICFROM, LIBDIR/generics)dnl       # generic from addresses
  define(MAILERTABLE, LIBDIR/mailertable)dnl    # mailers per host or domain
  define(UUCPXTABLE, LIBDIR/uucpxtable)dnl      # paths to hosts we feed
  define(UUCPRELAYS, LIBDIR/uucprelays)dnl      # short-circuit paths
  dnl #
  dnl #--------------------------------------------------------------------
  dnl #
  dnl # include the 'real' code that makes it all work
  dnl # (provided with the source code)
  dnl #
  include(Sendmail.mc)dnl                         # REQUIRED ENTRY!!!
  dnl #
  dnl #------------ END OF SAMPLE SENDMAIL.M4 FILE -------
 

ローカルメイラの設定

他の Unix とは違って、 Linux はローカルメール配送システムを最初からは備えていません。 いまでは deliver か procmail がインストールしてあるのが普通になってます。 したがって、 そうでなくても十分ややこしい設定がさらに複雑になることはありません。 手に入りやすい deliverprocmail を使うことにしましょう。 この二つをオプションパッケージとしている Linux ディストリビューションもあります。

deliver をローカルメイラに設定するためには、 sendmail.m4 にある LOCAL_MAILER_DEF の項目を次のようにしてください。

  # -- /usr/local/lib/mail/mailers.linux --
  #     (local mailers for use on Linux )
  Mlocal, P=/usr/bin/deliver, F=SlsmFDMP, S=10, R=25/10, A=deliver $u
  Mprog,  P=/bin/sh,       F=lsDFMeuP,   S=10, R=10, A=sh -c $u

Sendmail.mc には deliver 用の初期値があらかじめ設定してあります。 Sendmail.mcsendmail.cf の一部に組み込まれるものです。 これを指定する場合には mailers.linux は使わず、 代わりに sendmail.m4 ファイルに以下の設定を行います。

   dnl --- (in sendmail.m4) ---
   define(LOCAL_MAILER_DEF, DELIVER)dnl       # mailer for local delivery

Sendmail.mc は deliver を /bin にインストールしてあることを前提にしています。 残念ながら、Slackware 1.1.1 の場合はこうなっていません (/usr/bin にインストールしてあります)。 この場合には、リンクを張ってごまかしてやるか、 deliver をソースから作り直して /bin にインストールすることになります。 メールの振り分け作業など、 総じて deliver よりも procmail の方が優れていることをお忘れなく。

sendmail+IDA の dbm テーブル

サイト用・ドメイン用に特殊な設定を行う場合には、 sendmail.cf を直接編集するよりも、 オプションとなっている一連の dbm テーブルを利用する方がいいでしょう。

詳しくは、 1994 年 7 月号の Linux Journal (まだ入手できればの話ですが) や、 ソースファイルに添付の文書、 まもなく刊行予定となっている LDP (Linux Documentation Project) の Networking Administration Guide最新版を参照してください。

(訳注: この辺は書いた時代が古いんですね(^^;)

本当に必要なのはどの項目か。

インターネットに接続していて、DNS を使用しているという一般的なサイト、 あるいは UUCP だけを利用しており、すべてのメールを smart RELAY_HOST 経由の UUCP でフォワードしているサイトの場合には、 特別なテーブルの設定はおそらく必要ないでしょう。

DEFAULT_HOSTPSEUDONYMS マクロの設定は、 ほぼすべてのシステムで必須です。 この二つは、正式サイト名と設定済みの aliases を指定するものです。

リレーホストとリレーメーラしか使っていないのなら、 この二つを設定しなくてもかまいません。 UUCP ホストの場合には UUCPNAME を公式の UUCP 名に設定する必要があるでしょう。

さらに メールリレーを使った smart ホストルーティングを可能にするために、 RELAY_MAILERRELAY_HOST を設定することにもなるでしょう。

メールの送付に何を用いるかは RELAY_MAILER で設定します。 UUCP サイトの場合には UUCP-A と指定するのが普通です。 もし SMTP だけを利用し、そのうえ DNS を用いているという場合には、 RELAY_MAILER の設定を変更することになるでしょう。

SLIP サイトの場合には、外部宛てのメールは全部サービスプロバイダに任せて 処理してもらうという安易な道をとりたくなるでしょうね。 そうするには、 ISOLATED_DOMAINS と VALIDATION_DOMAINS を自ドメイン名とせず、 さらに RELAY_HOST をサービスプロバイダの名前にし、 RELAY_MAILER を TCP としてください。 もちろん、システムを汎用リレーに仕立てる場合には、 いつも事前に許可をえておくことが必要です。

6.4 Sendmail 8.x

Berkeley 版の sendmail 8.7.x は、 sendmail5 以降の大規模な改訂版としては最新のものでした。 Linux でのコンパイルを組み込みでサポートしたすばらしいものになっています。 "make linux" をするだけで、すべてが揃います。

Berkeley dbm などに自力で立ち向かうよりは、 そこらへんにあるLinux アーカイブにころがっているバイナリを 見つけてくるほうがずっとお手軽でしょう。

Jason Haar 氏 j.haar at lazerjem.demon.co.uk の Sendmail 8.6.12 ディストリビューションは良くできています。 これは sunsite.unc.edu の /pub/Linux/system/Mail/delivery/sendmail-8.6.12-bin.tgz で入手できます。 ソースについての解説文書や v8 を標準的に設定する方法についての簡潔明解な説明もあります。

動かすために最低限必要なものだけを設定するというのが結論です。 少なくとも以下の例で示すことだけは、きっちりと把握してください。

8.7.x 用 mc ファイルの例

sendmail+IDA と同じように、 sendmail v8 でも 設定ファイルから sendmail.cf を作成する際には m4 を使用します。 以下の例は、私が自分のサイト用に利用している設定です (メールを外部に送信する場合には ppp -- インターネットを、 メールの受信には uucp を使用)。

        dnl divert(-1)
        #---------------------------------------------------------------------
        #
        # this is the .mc file for a linux host that's set up as follows:
        #
        #       - connected to Internet for outbound mail (ppp here)
        #       - connected via UUCP for incoming mail
        #       - domainized headers
        #       - no local mailer (use 'deliver' instead)
        #       - no DNS running so don't canonicalize outgoing via DNS
        #       - all non-local outbound mail goes to the RELAY_HOST over smtp
        #           (we run ppp and let our service provider do the work)
        #
        #                                       vds 3/31/95
        #
        #---------------------------------------------------------------------
        include(`../m4/cf.m4')
        VERSIONID(`linux nodns relays to slip service provider smarthost')dnl
        Cwmyhostname.myprimary.domain myhostname.UUCP localhost
        OSTYPE(linux)
        FEATURE(nodns)dnl
        FEATURE(always_add_domain)dnl
        FEATURE(redirect)
        FEATURE(nocanonify)
        dnl MAILER(local)dnl
        MAILER(smtp)dnl
        MAILER(uucp)dnl
        define(`RELAY_HOST', smtp:my.relay.host.domain)
        define(`SMART_HOST', smtp:my.relay.host.domain)
        define(`UUCP_RELAY', smtp:my.relay.host.domain)
        define(`LOCAL_MAILER_PATH', `/bin/deliver')
        define(`LOCAL_MAILER_ARGS', `deliver $u')

Sendmail v8 について少々

IDA 原理主義者にいわせれば、 IDA と sendmail にはいささかの相違があるということになるでしょう。 今のところ私は次の件を見つけました。

キューを実行するときに、 'runq' ではなく 'sendmail -q' と打ち込んでしまう!

CF パッケージ (訳者追記)

sendmail.cf を生成するマクロパッケージとしては、 WIDE Project の中村素典さんが作成された CF も日本では良く利用されています。

一次配布先は ftp://ftp.kyoto.wide.ad.jp/pub/mail/CF/ です。日本語で分かりやすく書かれた解説も同梱されているので、 こちらを利用するのもいいでしょう。

6.5 ローカル配信エージェント

ほかの大部分の OS とは違って、 Linux はメールシステムを内蔵していません。 したがって、ローカルメールの配送には "lmail", "procmail", "deliver" といったようなプログラムが必要です。

とはいっても、 最近のディストリビューションは、 どれもローカルメイラを同梱するようになっています。

各ローカルメイラの使い方については、 上述した sendmail5.67b+IDA1.5 のバイナリ付属文書をご覧ください。


次のページ 前のページ 目次へ