ClamSMTP 1.10-1 Install (rpm)


アンチウィルス・メールスキャナとしてClamSMTP 1.10.1をインストールした時のメモ。

  • Postfix 2.6.5
  • ClamAV 0.95.3
  • ClamSMTP 1.10-1

まずはClamAVをインストールした時のメモでClamAVのインストールの後、ClamSMTPのサイトSource RPMSからソースを落としてくる。

$ rpm -ivh clamsmtp-1.10-1.src.rpm
$ cd ~/rpm/SPECS

ビルドする。

$ rpmbuild -bb --clean clamsmtp.spec

インストールする。

$ cd ../RPMS/x86_64
$ su
# rpm -ivh clamsmtp-1.10-1.x86_64.rpm


コンフィグファイル。

# vi /etc/clamstpd.conf
# ------------------------------------------------------------------------------
#                        SAMPLE CLAMSMTPD CONFIG FILE
# ------------------------------------------------------------------------------
# 
# - Comments are a line that starts with a #
# - All the options are found below with sample settings


# The address to send scanned mail to. 
# This option is required unless TransparentProxy is enabled
OutAddress: 127.0.0.1:10026

# The maximum number of connection allowed at once.
# Be sure that clamd can also handle this many connections
#MaxConnections: 64

# Amount of time (in seconds) to wait on network IO
#TimeOut: 180

# Keep Alives (ie: NOOP's to server)
#KeepAlives: 0

# Send XCLIENT commands to receiving server
#XClient: off

# Address to listen on (defaults to all local addresses on port 10025)
Listen: 127.0.0.1:10025

# The address clamd is listening on
ClamAddress: /var/run/clamav/clamd

# A header to add to all scanned email
Header: X-Virus-Scanned: Scanned

# Directory for temporary files
#TempDirectory: /tmp

# What to do when we see a virus (use 'bounce' or 'pass' or 'drop'
#Action: drop 

# Whether or not to keep virus files 
#Quarantine: off

# Enable transparent proxy support 
#TransparentProxy: off

# User to switch to
User: clamav

# Virus actions: There's an option to run a script every time a virus is found. 
# !IMPORTANT! This can open a hole in your server's security big enough to drive
# farm vehicles through. Be sure you know what you're doing. !IMPORTANT!
#VirusAction: /path/to/some/script.sh

Postfixの設定ファイルにフィルターのアドレスを追記する。

# vi /etc/postfix/main.cf
content_filter = scan:127.0.0.1:10025
receive_override_options = no_address_mappings
# vi /etc/postfix/master.cf
scan      unix  -       -       n       -       16      smtp
	-o smtp_send_xforward_command=yes
127.0.0.1:10026 inet    n  -    n       -       16      smtpd
	-o content_filter=
	-o receive_override_options=no_unknown_recipient_checks,no_header_body_checks
	-o smtpd_helo_restrictions=
	-o smtpd_client_restrictions=
	-o smtpd_sender_restrictions=
	-o smtpd_recipient_restrictions=permit_mynetworks,reject
	-o mynetworks_style=host
	-o smtpd_authorized_xforward_hosts=127.0.0.0/8

起動スクリプト。

#!/bin/sh
# clamsmtpd        Script to start/stop clamsmtpd.
#
# chkconfig:    - 63 38
# description:  clamsmtpd is smtpd for clamav antivirus daemon.
#
# processname: clamsmtpd
# pidfile: /var/run/clamav/clamsmtpd.pid
#
# author: Martynas Bieliauskas  2004 Sep 20
#

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

# Get network config
. /etc/sysconfig/network

###########################################################################
# CONFIGURATION

# Most configuration options are found in the clamsmtpd.conf file
# The location of configuration file
config=/etc/clamsmtpd.conf

# The prefix clamsmtpd was installed to
prefix=/usr

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

###########################################################################
# SCRIPT

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 /var/run/clamav/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 $?

起動設定後、起動。Postfixもリロードする。

# chkconfig --add clamsmtpd
# chkconfig clamsmtpd on
# service clamsmtpd strat && service postfix reload

Starting ClamSmtpd:				[  OK  ]
postfix/postfix-script: refreshing the Postfix mail system

動作確認でテストメールを出してみる。

# /usr/sbin/sendmail -t user@example.com
.
# cat /var/log/maillog
Mar  9 02:05:18 localhost postfix/pickup[9203]: 1B3B22A148: uid=xxx from=<user>
Mar  9 02:05:18 localhost postfix/cleanup[29284]: 1B3B22A148: message-id=<20100318220518.1B3B22A148@localhost.domain.tld>
Mar  9 02:05:18 localhost postfix/qmgr[28813]: 1B3B22A148: from=<user@example.com>, size=179, nrcpt=1 (queue active)
Mar  9 02:05:18 localhost clamsmtpd: 100003: accepted connection from: 127.0.0.1
Mar  9 02:05:18 localhost postfix/smtpd[29288]: connect from localhost.domain.tld[127.0.0.1]
Mar  9 02:05:18 localhost postfix/smtpd[29288]: 31AAA2A120: client=localhost.domain.tld[127.0.0.1]
Mar  9 02:05:18 localhost postfix/cleanup[29284]: 31AAA2A120: message-id=<20100318220518.1B3B22A148@localhost.domain.tld>
Mar  9 02:05:18 localhost postfix/qmgr[28813]: 31AAA2A120: from=<user@example.com>, size=379, nrcpt=1 (queue active)
Mar  9 02:05:18 localhost postfix/smtp[29286]: 1B3B22A148: to=<user@example.com>, relay=127.0.0.1[127.0.0.1]:10025, delay=2.1, delays=1.9/0.01/0.06/0.06, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 31AAA2A120)
Mar  9 02:05:18 localhost clamsmtpd: 100003: from=user@example.com, to=user@example.com, status=CLEAN
Mar  9 02:05:18 localhost postfix/smtpd[29288]: disconnect from localhost.domain.tld[127.0.0.1]
Mar  9 02:05:18 localhost postfix/qmgr[28813]: 1B3B22A148: removed
Mar  9 02:05:18 localhost postfix/virtual[29293]: 31AAA2A120: to=<user@example.com>, relay=virtual, delay=0.07, delays=0.05/0.01/0/0.01, dsn=2.0.0, status=sent (delivered to maildir)
Mar  9 02:05:18 localhost postfix/qmgr[28813]: 31AAA2A120: removed