[an error occurred while processing this directive] MailServer構築(SMTP Virus Filter using ClamAV) - System House ACT

ClamSMTP 1.8

ダウンロード

ClamSMTP Sourceclamsmtp-1.8.tar.gz

インストール

/usr/local/srcディレクトリでアーカイブを展開しインストールします。
# cd /usr/local/src
# tar zxvf ダウンロード先/clamsmtp-1.8.tar.gz
# cd clamsmtp-1.8
# ./configure
# make
# make install

設定

設定ファイルを編集します。
# vi /usr/local/etc/clamsmtpd.conf

# ------------------------------------------------------------------------------
#                        CLAMSMTPD CONFIG FILE
# ------------------------------------------------------------------------------

# The address to send scanned mail to (MTAへスキャン結果を渡すアドレスとポート) 
OutAddress: 127.0.0.1:10026

# Address to listen on (MTAからのスキャン要求を受けるアドレスとポート)
Listen: 127.0.0.1:10025

# The address clamd is listening on (ClamAVとの通信ソケット)
ClamAddress: /var/run/clamav/clamd

# A header to add to all scanned email (追加するメールヘッダ)
Header: X-Virus-Scanned: ClamAV using ClamSMTP

# Directory for temporary files (作業用ディレクトリ:最後に/をつけないで指定します)
TempDirectory: /tmp

# Whether or not to keep virus files
Quarantine: on

# User to switch to
User: clamav

# Virus actions 
VirusAction: /usr/local/etc/virus_action.sh
ウィルス検出時の実行スクリプトを作成します。
# vi /usr/local/etc/virus_action.sh

#!/usr/bin/perl

$FROM   = 'ClamSMTP <clamsmtp@example.com>';          # 通知メールの差出人
$TO     = 'virusalert@example.com';                   # 通知メールの宛先
$MAILER = '/usr/sbin/sendmail -t';

open(F, $ENV{EMAIL}) or die;
@mail = <F>;
close(F);

$msg = <<EOM;
From: $FROM
To: $TO
Subject: Virus ($ENV{VIRUS}) From <$ENV{SENDER}>

A virus ($ENV{VIRUS}) was found.

The email sender:
   $ENV{SENDER}

The email recipients:
   $ENV{RECIPIENTS}

The message has been quarantined as:
EOM

open(F, "|$MAILER") or die "$MAILER: $!";
print F $msg;
foreach (@mail) { print F "   $_"; }
print F ".\n";
close(F);

unlink($ENV{EMAIL});

# chmod 755 /usr/local/etc/virus_action.sh
起動ファイルを作成します。
# vi /etc/rc.d/init.d/clamsmtpd

#!/bin/sh
# clamsmtpd    Script to start/stop clamsmtpd.
#
# chkconfig:   - 63 38
# description: clamsmtpd is smtpd for clamav antivirus daemon.
#
# processname: clamsmtpd
# pidfile: $piddir/clamsmtpd.pid

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

# Get network config
. /etc/sysconfig/network

# The location of configuration file
config=/usr/local/etc/clamsmtpd.conf

# The prefix clamsmtpd was installed to
prefix=/usr/local

# The location for pid file
piddir=/var/run/clamav

RETVAL=0

start() {
  echo -n $"Starting ClamSmtpd: "
  daemon $prefix/sbin/clamsmtpd -f $config -p $piddir/clamsmtpd.pid
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && touch /var/lock/subsys/clamsmtpd
  return $RETVAL
}

stop() {
  echo -n $"Stopping ClamSmtpd: "
  killproc clamsmtpd
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && rm -f $piddir/clamsmtpd.pid /var/lock/subsys/clamsmtpd
  return $RETVAL
}
restart() {
  stop
  start
}

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

exit $?

起動

自動起動設定を行い、起動します。
# chmod 755 /etc/rc.d/init.d/clamsmtpd
# chkconfig clamsmtpd on
# service clamsmtpd start
[an error occurred while processing this directive]
[an error occurred while processing this directive]