#LyX 1.1 created this file. For more info see http://www.lyx.org/
\lyxformat 218
\textclass linuxdoc
\language english
\inputencoding default
\fontscheme default
\graphics default
\paperfontsize 10
\spacing single 
\papersize Default
\paperpackage a4
\use_geometry 0
\use_amsmath 0
\paperorientation portrait
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\defskip medskip
\quotes_language english
\quotes_times 2
\papercolumns 1
\papersides 1
\paperpagestyle default

\layout Title
\added_space_top vfill \added_space_bottom vfill 
How to Install Amavis-milter for Debian Sendmail
\layout Author

Jean-Paul Stewart <jps@maxlingua.com>
\layout Date

23.10.2001
\layout Abstract

This document provides a step-by-step guide to the installation and configuratio
n of the Amavis antivirus software available from 
\begin_inset LatexCommand \url{http://www.amavis.org/}

\end_inset 

 on the Debian GNU/Linux operating system.
 It has been adapted from the documentation available there.
 Amavis supports many different methods of implementation.
 I have chosen to implement Amavis-libmilter as the interface between Amavis
 and Sendmail.
 Another option with Amavis + Sendmail, which I am not describing here,
 involves employing Amavis as a sort of intermediate local delivery agent.
 Please be advised that this software requires an existing CLI antivirus
 scanning engine and database.
 The selection and procurement of such software is not discussed in this
 document.
 There is ample information available at the amavis.org site.
 These installation examples make extensive use of the outstanding Sendmail
 and libmilter-dev Debian packages maintained by Richard 
\begin_inset Quotes eld
\end_inset 

cowboy
\begin_inset Quotes erd
\end_inset 

 Nelson.
 Thanks Cowboy! Thank you Amavis developers!
\layout Standard


\begin_inset LatexCommand \tableofcontents{}

\end_inset 


\layout Section

Software Dependencies
\layout Enumerate

At a minimum you need to be running the Debian 3.0 (Woody) distribution from
 
\begin_inset LatexCommand \url{http://www.debian.org/}

\end_inset 

.
 Older versions of Debian do not provide an adequate sendmail package (they
 lack the libmilter API).
\layout Enumerate

Obviously, sendmail needs to be installed on your system.
\layout Enumerate

As mentioned in the abstract, you will have to obtain your own antiviral
 engine from an independent vendor.
\layout Enumerate

The 
\begin_inset Quotes eld
\end_inset 

file
\begin_inset Quotes erd
\end_inset 

 package.
\layout Enumerate

The 
\begin_inset Quotes eld
\end_inset 

arc
\begin_inset Quotes erd
\end_inset 

 utility.
 It is not available as a Debian package.
 You can obtain the source code for this program at 
\begin_inset LatexCommand \url{ftp://metalab.unc.edu/pub/Linux/utils/compress/arc521.tar.Z}

\end_inset 

.
 
\layout Enumerate

The 
\begin_inset Quotes eld
\end_inset 

bzip2
\begin_inset Quotes erd
\end_inset 

 package.
\layout Enumerate

The 
\begin_inset Quotes eld
\end_inset 

lha
\begin_inset Quotes erd
\end_inset 

 package.
\layout Enumerate

The 
\begin_inset Quotes eld
\end_inset 

unarj
\begin_inset Quotes erd
\end_inset 

 package.
\layout Enumerate

The 
\begin_inset Quotes eld
\end_inset 

unrar
\begin_inset Quotes erd
\end_inset 

 package.
\layout Enumerate

The 
\begin_inset Quotes eld
\end_inset 

zoo
\begin_inset Quotes erd
\end_inset 

 package.
\layout Enumerate

You may need to install a few perl modules.
 The required modules are
\layout Itemize

IO-stringy
\layout Itemize

Syslog
\layout Itemize

MailTools
\layout Itemize

MIME-Base64
\layout Itemize

MIME-tools
\layout Itemize

Convert-UUlib
\layout Itemize

Convert-TNEF
\layout Itemize

Compress-Zlib
\layout Itemize

Archive-Tar
\layout Itemize

Archive-Zip
\layout Itemize

libnet
\layout Section

Installing the Software Dependencies
\layout Standard

Update your distribution files with the usual:
\layout Verbatim

apt-get update
\layout Standard

and install file, bzip2, lha, unarj, unrar, and zoo in one shot with:
\layout Verbatim

apt-get install file bzip2 lha unarj unrar zoo
\layout Standard

Install all the perl modules in one shot with:
\layout Verbatim

apt-get install libio-stringy-perl libunix-syslog-perl libmailtools-perl
 libmime-base64-perl libmime-perl libconvert-uulib-perl libconvert-tnef-perl
 libcompress-zlib-perl libarchive-tar-perl libarchive-zip-perl libnet-perl
\layout Standard

Installing the 
\begin_inset Quotes eld
\end_inset 

arc
\begin_inset Quotes erd
\end_inset 

 utility is much more of a hassle.
 Furthermore, it is an unmaintained old MS-DOS port with a non-free license.
 I will describe what I did to compile it on a Intel platform (suggestions
 on better ways to do this are appreciated).
 The next few steps assume that you have the GNU 
\begin_inset Quotes eld
\end_inset 

make
\begin_inset Quotes erd
\end_inset 

 and 
\begin_inset Quotes eld
\end_inset 

gcc
\begin_inset Quotes erd
\end_inset 

 packges installed on your system.
 If this is not the case then try:
\layout Verbatim

apt-get install make gcc
\layout Standard

Let's create a temporary directory somewhere so that we can make a mess
 in it.
 Since my login is 
\begin_inset Quotes eld
\end_inset 

jps
\begin_inset Quotes erd
\end_inset 

, I made a directory named 
\begin_inset Quotes eld
\end_inset 

/home/jps/tmp/
\begin_inset Quotes erd
\end_inset 

.
 Copy the arc521.tar.Z file into your new temporary diretory and type: 
\layout Verbatim

uncompress arc521.tar.Z; tar xf arc521.tar
\layout Standard

or something equivalent to uncompress and untar the archive.
 This will create a bunch of files.
 We need to delete some lines from the file named 
\begin_inset Quotes eld
\end_inset 

arcdos.c
\begin_inset Quotes erd
\end_inset 

.
 It is probably set to be read-only, so type:
\layout Verbatim

chmod u+w arcdos.c
\layout Standard

Open arcdos.c for editing and delete (or comment out) lines 35-38 inclusive.
 (It is the definition of a structure that begins with 
\begin_inset Quotes eld
\end_inset 

struct timeval
\begin_inset Quotes erd
\end_inset 

 on line 35 and ends with 
\begin_inset Quotes eld
\end_inset 

};
\begin_inset Quotes erd
\end_inset 

 on line 38).
 We are done with that, so close the file.
 Now type:
\layout Verbatim

make
\layout Standard

This command WILL FAIL with a bunch of warnings and an error message complaining
 about 
\begin_inset Quotes eld
\end_inset 

tmclock.o
\begin_inset Quotes erd
\end_inset 

, but it accomplished some necessary things anyway.
 Now open the file named 
\begin_inset Quotes eld
\end_inset 

Makefile
\begin_inset Quotes erd
\end_inset 

 for editing.
 Go to the line that says 
\begin_inset Quotes eld
\end_inset 

System = -DBSD=1
\begin_inset Quotes erd
\end_inset 

.
 It should be on line 31.
 Change the line so that it says:
\layout Verbatim

System = -DSYSV=1
\layout Standard

Close the Makefile and run make again by typing:
\layout Verbatim

make
\layout Standard

That should compile the 
\begin_inset Quotes eld
\end_inset 

arc
\begin_inset Quotes erd
\end_inset 

 utility successfully.
 You can ignore the warnings about 
\begin_inset Quotes eld
\end_inset 

mktemp
\begin_inset Quotes erd
\end_inset 

 and 
\begin_inset Quotes eld
\end_inset 

mkstemp
\begin_inset Quotes erd
\end_inset 

.
 There should now be an executable program with the name of 
\begin_inset Quotes eld
\end_inset 

arc
\begin_inset Quotes erd
\end_inset 

 in your temporary directory.
 As root, copy this file to 
\begin_inset Quotes eld
\end_inset 

/usr/local/bin
\begin_inset Quotes erd
\end_inset 

 or the usual place where you keep home-cooked binaries.
 Just make sure that it is in your path.
 Test this by typing 
\begin_inset Quotes eld
\end_inset 

arc
\begin_inset Quotes erd
\end_inset 

 and see if the arc usage guide scrolls up your terminal.
 You can delete all the files in your temporary directory now, but leave
 the directory itself because we will be using it later.
 Aren't .deb packages so much easier? 
\layout Section

Example Installation of an Antivirus Scanner
\layout Standard

I am using a Linux commandline scanner from NAI Associates, Inc.
 You will have to avail yourself of the documentation at 
\begin_inset LatexCommand \url{http://www.amavis.org/}

\end_inset 

 if you don't know where to obtain a scanner.
 For example, you could place your scanner binary along with its' data files
 in a directory named 
\begin_inset Quotes eld
\end_inset 

/usr/local/share/av
\begin_inset Quotes erd
\end_inset 

.
 Then create a symlink to the binary in the 
\begin_inset Quotes eld
\end_inset 

/usr/local/bin
\begin_inset Quotes erd
\end_inset 

 directory.
 This way, the command to execute the scanner is in your path, and the Amavis
 configure script will find it.
 For a more advanced configuration (once you have the easy stuff out of
 the way), take a look at the example start-stop script at the end of this
 document.
\layout Section

Obtaining the Libmilter Sourcecode and Libraries
\layout Standard

In order to be able to build Amavis with the libmilter interface, you need
 to have the Sendmail's libmilter sourcecode and libraries available.
 Don't worry, this is very easy with Debian.
 The following command will dowload everything required to your system:
\layout Verbatim

apt-get install libmilter-dev
\layout Section

Obtaining the Amavis Sourcecode
\layout Subsection

Checking the latest copy out of CVS
\layout Standard

\begin_float footnote 
\layout Standard

As of October 23, 2001; the CVS copy might not compile.
 Skip to the next section if you don't want to fool around.
\end_float 
Now that we have extracted the libmilter files, the next step is to obtain
 the latest copy of the Amavis sourcecode.
 We will retrieve this code from the Amavis CVS repository at 
\begin_inset LatexCommand \url{http://sourceforge.net/}

\end_inset 

.
 If you do not already have the CVS package installed on your system, you
 can obtain it with the command:
\layout Verbatim

apt-get install cvs
\layout Verbatim

cvs -d:pserver:anonymous@cvs.amavis.sourceforge.net:/cvsroot/amavis login
\layout Standard

You will be logging in anonymously, so just press enter at the password
 prompt.
 If CVS gives you a hard time about 
\begin_inset Quotes eld
\end_inset 

$HOME/.cvspass
\begin_inset Quotes erd
\end_inset 

 not existing, then simply type:
\layout Verbatim

touch $HOME/.cvspass
\layout Standard

and issue the command once more.
 With these preliminaries out of the way we can download the actual source
 with:
\layout Verbatim

cvs -z3 -d:pserver:anonymous@cvs.amavis.sourceforge.net:/cvsroot/amavis co
 amavis
\layout Standard

This will create a subdirectory named 
\begin_inset Quotes eld
\end_inset 

amavis
\begin_inset Quotes erd
\end_inset 

 in your temporary directory.
 Please skip to section titled 
\begin_inset Quotes eld
\end_inset 

Building Amavis
\begin_inset Quotes erd
\end_inset 

.
\layout Subsection

If the CVS copy blows chunks
\layout Standard

If you are like me, and the CVS copy died hideously during 
\begin_inset Quotes eld
\end_inset 

./configure
\begin_inset Quotes erd
\end_inset 

, then download the the 
\begin_inset Quotes eld
\end_inset 

official
\begin_inset Quotes erd
\end_inset 

 CVS snapshot from 
\begin_inset LatexCommand \url{http://sourceforge.net/projects/amavis/}

\end_inset 

.
 The available version at the time of this writing was 
\begin_inset Quotes eld
\end_inset 

amavisd-snaphot-20010714
\begin_inset Quotes erd
\end_inset 

.
 You can dowload this as a tarball.
 Copy this file into your temporary directory and run:
\layout Verbatim

tar zxf <filename>
\layout Standard

That should give you a nice directory of sourcecode.
\layout Section

Building Amavis
\layout Standard

Regardless of the method you used to obtain it, please change to your new
 amavis sourcecode directory and type the following command to build Amavis
 with libmilter:
\layout Verbatim

LDFLAGS=
\begin_inset Quotes erd
\end_inset 

-L/usr/lib/libmilter
\begin_inset Quotes erd
\end_inset 

 ./configure --with-amavisuser=amavis --prefix=/usr/local --with-runtime-dir=/var
/local/amavis --enable-milter --with-sendmail-source=/usr/include/libmilter
\layout Standard

Then simply run make by typing:
\layout Verbatim

make
\layout Standard

This will create, among other things, the amavisd perl script and the amavis-mil
ter binary in your 
\begin_inset Quotes eld
\end_inset 

<amavis-sourcecode-directory>/amavis/
\begin_inset Quotes erd
\end_inset 

 directory.
 If the previous steps failed for any reason, go to the section titled 
\begin_inset Quotes eld
\end_inset 

If the CVS copy blows chunks
\begin_inset Quotes erd
\end_inset 

 and rerun the 
\begin_inset Quotes eld
\end_inset 

Building Amavis
\begin_inset Quotes erd
\end_inset 

 section from the beginning.
\layout Section

Installing and Running Amavis
\layout Standard

Hopefully we passed the correct options to the Amavis configure script so
 that when we install it, the Debian file system policy won't be violated.
 That would be bad karma.
 Create a user named 
\begin_inset Quotes eld
\end_inset 

amavis
\begin_inset Quotes erd
\end_inset 

 with:
\layout Verbatim

useradd amavis
\layout Standard

From the amavis-sourcecode-directory type:
\layout Verbatim

make install
\layout Standard

If everythiny worked, the install script should have
\layout Itemize

copied the amavisd perl script to /usr/local/sbin
\layout Itemize

copied the amavis-milter binary to /usr/local/sbin
\layout Itemize

created the /var/local/amavis directory with owner amavis and mode 2700
 or 0700
\layout Itemize

created a file named /etc/amavisd.conf
\layout Standard

Now you will need to create an alias in /etc/aliases or /etc/mail/aliases
 (or wherever you keep your mail aliases) for the 
\begin_inset Quotes eld
\end_inset 

virusalert
\begin_inset Quotes erd
\end_inset 

 email address that Amavis will try and send virus reports to.
 Generally, this should be the system administrator.
\layout Standard

Don't forget to rebuild the aliases file by issuing:
\layout Verbatim

newaliases
\layout Standard

Finally, open up the /etc/mail/sendmail.mc file for editing and insert the
 following two lines anywhere after the line the begins with 
\begin_inset Quotes eld
\end_inset 

## Custom configurations
\begin_inset Quotes erd
\end_inset 

 (it is near the bottom):
\layout Verbatim

define(`_FFR_MILTER', `1')dnl
\layout Verbatim

INPUT_MAIL_FILTER(`milter-amavis', `S=local:/var/local/amavis/amavis-milter.sock,
 T=S:10m;R:10m;E:10m')dnl
\layout Standard

After you close the /etc/mail/sendmail.mc file, start-up amavis-milter and
 amavisd with the following three commands:
\layout Verbatim

rm -rf /var/local/amavis/amavis-milter.sock
\layout Verbatim

nohup /usr/local/sbin/amavis-milter -p /var/local/amavis/amavis-milter.sock
 &
\layout Verbatim

/usr/local/sbin/amavisd
\layout Standard

Now that Amavis is ready and running, you can fire-up your new sendmail
 configuration with:
\layout Verbatim

sendmailconfig
\layout Standard

This command will recreate the /etc/mail/sendmail.cf file from the /etc/mail/send
mail.mc file and reload the sendmail daemon.
 An alternate approach is to delete the /etc/mail/sendmail.cf file, run 
\begin_inset Quotes eld
\end_inset 

make
\begin_inset Quotes erd
\end_inset 

 in the /etc/mail directory, and restart sendmail with 
\begin_inset Quotes eld
\end_inset 

/etc/init.d/sendmail restart
\begin_inset Quotes erd
\end_inset 

 (or whatever it is that you use).
\layout Section

An Example Startup script
\layout Code

#!/bin/sh 
\layout Code

# /etc/init.d/amavis-ramdisk
\layout Code

# Script to run Amavis from a ram disk.
\layout Code

\layout Code

# I keep my antiviral scanner and data files on a ramdisk for speed.
\layout Code

AVDIR="/usr/local/share/av.original"
\layout Code

RAMDISK="/usr/local/share/av.ramdisk"
\layout Code

AMAVISBIN="/usr/local/sbin"
\layout Code

AMAVISSOCK="/var/local/amavis"
\layout Code

[ -d $AVDIR -a -d $RAMDISK ] || exit 0
\layout Code

case "$1" in
\layout Code

start)
\layout Code

   mke2fs /dev/ram0 > /dev/null 2>&1
\layout Code

   mount /dev/ram0 $RAMDISK
\layout Code

   cp $AVDIR/* $RAMDISK
\layout Code

   if [ -S $AMAVISSOCK/amavis-milter.sock ]; then
\layout Code

      rm -rf $AMAVISSOCK/amavis-milter.sock
\layout Code

   fi
\layout Code

   if [ -S $AMAVISSOCK/amavisd.sock ]; then
\layout Code

      rm -rf $AMAVISSOCK/amavisd.sock
\layout Code

   fi
\layout Code

   nohup $AMAVISBIN/amavis-milter -p $AMAVISSOCK/amavis-milter.sock &
\layout Code

   $AMAVISBIN/amavisd
\layout Code

;;
\layout Code

stop)
\layout Code

   kill -9 `ps x | grep amavisd | grep -v grep | awk '{print $1}'`2> /dev/null
\layout Code

   kill -9 `ps x | grep amavis-milter | grep -v grep | awk '{print $1}'`
 2> /dev/null
\layout Code

   # I need to sleep for some reason :(
\layout Code

   sleep 2umount /dev/ram0
\layout Code

;;
\layout Code

*)
\layout Code

   echo "Usage: /etc/init.d/amavis-ramdisk {start|stop}"
\layout Code

   exit 1
\layout Code

;;
\layout Code

esac
\layout Code

exit 0
\layout Standard

Don't forget to update your antivirus data files regularly.
 
\layout Quote

Send all comments and corrections to <jps@maxlingua.com>.
 Support free software!
\the_end
