On my main server at home I run Debian as the main OS. The default MTA on Debian is Exim, while I had already installed Postfix myself for a previous project. For a project I’m very interested in, knowledge of sendmail is required, so I figured I’d revive my rather extensive sendmail knowledge and see if I could get it to operate on Debian Sid (Sid: development/unstable branch of Debian)
Installation
The installation of sendmail, as with most Debian packages, is very straightforward. All the software for Debian, much like most Linux distributions nowadays, is packaged and available from an online repository. The tool aptitude can be used to install a package from one of these repositories:
omega:~# aptitude install sendmail
As a result of this simple little command however, a LOT of things actually happen:
The following extra packages will be installed:
sendmail-base sendmail-bin sendmail-cf sensible-mda
Suggested packages:
sendmail-doc rmail logcheck sasl2-bin
The following packages will be REMOVED:
postfix
The following NEW packages will be installed:
sendmail sendmail-base sendmail-bin sendmail-cf sensible-mda
0 upgraded, 5 newly installed, 1 to remove and 335 not upgraded.
Need to get 2,084 kB of archives.
So we see here the postfix package actually being removed. Debian knows that postfix functions as MTA and that in most ordinary cases no two MTA’s should be running on one server.
We also see a number of new packages being install, sendmail, sendmail-base, sendmail-bin, sendmail-cf and ‘sensible-mda’, which aptitude apparently finds to be required to set up a sendmail MTA. One thing that’s often overlooked in the aptitude output is the ‘Suggested packages:’. I’ve found these to be very accurate suggestions in the past so when we’re done converting to sendmail we’ll check out these packages as well.
Frequently I install small applications and hardly really check the output that flies by. An MTA however is often a complicated and important service which requires meticulous checking. One thing I immediately noticed:
Setting up sendmail-base (8.14.4-2) ...
adduser: Warning: The home directory `/var/lib/sendmail' does not belong to the user you are currently creating.
This should immediately trigger a mental note to verify which user is being created as part of the installation of the sendmail-base package. After the installation finishes a quick check in /etc/passwd reveals:
smmta:x:125:125:Mail Transfer Agent,,,:/var/lib/sendmail:/bin/false
smmsp:x:126:140:Mail Submission Program,,,:/var/lib/sendmail:/bin/false
omega:~# ls -la /var/lib/sendmail/
total 8
drwxr-s--x 2 smmta smmsp 4096 Jun 25 01:59 .
drwxr-xr-x 91 root root 4096 Jun 26 01:28 ..
-rw-rw---- 1 root smmsp 0 Jun 25 01:59 dead.letter
So two new users were created, both having the same homedirectory, somewhat odd but it explains the error message.
Immediately after the install we also see right away that sendmail has been started up:
omega:~# ps xa|grep sendmail|grep -v grep
25117 ? Ss 0:05 sendmail: MTA: accepting connections
And inspection shows it’s also immediately accepting connections on port 25, the SMTP port:
omega:~# telnet localhost 25
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 omega.dutchie.org. ESMTP Sendmail 8.14.4/8.14.4/Debian-2; Wed, 29 Jun 2011 08:27:52 +0200; (No UCE/UBE) logging access from: localhost.localdomain(OK)-localhost.localdomain [127.0.0.1]
Configuration
The packages that have been installed have installed some documentation according to Debian standards:
omega:/usr/share/doc/sendmail# ls -dlF /usr/share/doc/sendmail*
drwxr-xr-x 2 root root 4096 Jun 25 01:59 /usr/share/doc/sendmail/
lrwxrwxrwx 1 root root 8 Jun 25 01:58 /usr/share/doc/sendmail-base -> sendmail/
drwxr-xr-x 2 root root 4096 Jun 25 01:59 /usr/share/doc/sendmail-bin/
lrwxrwxrwx 1 root root 8 Jun 25 01:59 /usr/share/doc/sendmail-cf -> sendmail/
The README.gz file gives a couple of good points to get started:
- Overview of directory permissions required
- DontBlameSendmail
- File locking note
Interesting is that not all the recommendations in the README.gz file are implemented in the Debian package, for example:
omega:/etc/mail# ls -l ../aliases
-rw-r--r-- 1 root root 222 Oct 4 2009 ../aliases
While the README.gz suggests permissions 0640. We see however from the timestamp on this file that this aliases file is a much older one already and a leftover from the postfix package that was removed when installing sendmail. This leaves open a potential risk of authorized users (in this case everybody) to lock the file and make locking by sendmail impossible!
All of the configuration files have been installed in /etc/mail. The most important one to inspect right away is of course sendmail.cf and its source sendmail.mc. Right after the install a sendmail.cf.errors has also been generated (?):
omega:/etc/mail# cat sendmail.cf.errors
*** ERROR: FEATURE() should be before MAILER()
*** MAILER(`local') must appear after FEATURE(`always_add_domain')*** ERROR: FEATURE() should be before MAILER()
*** MAILER(`local') must appear after FEATURE(`allmasquerade')*** ERROR: FEATURE() should be before MAILER()
Sendmail.cf is a generated file with an M4 file as its source. M4 is a rather complex macro processors which turns a small and simple file like sendmail.mc into a complicated and approx. 15 times as large sendmail.cf. Inspection of sendmail.cf has often been referred to as ‘black magic’, indicating the complexity of the file as sendmail has an enormous amount of configuration options.
I can’t be quite sure yet but the sendmail.cf.errors are probably quite harmless as they appear to be caused by something that’s been added dynamically to sendmail.mc:
dnl # Masquerading options
FEATURE(`always_add_domain')dnl
MASQUERADE_AS(`3dn.nl.')dnl
FEATURE(`allmasquerade')dnl
FEATURE(`masquerade_envelope')dnl
As we can see, 3dn.nl is in here, which is my local mail domain. The Debian package builder probably decided to simply add these lines to the end of the sendmail.mc before generating a reasonable default configuration. It’s also handy to know this as we now have a pretty good idea of what has been done to give sendmail a reasonable initial configuration. Just to be certain though, I moved these lines before the MAILER_DEFINITIONS and regenerated sendmail.cf:
omega:/etc/mail# make sendmail.cf
Updating databases ...
Reading configuration from /etc/mail/sendmail.conf.
Validating configuration.
Creating /etc/mail/databases...
Updating Makefile ...
Reading configuration from /etc/mail/sendmail.conf.
Validating configuration.
Creating /etc/mail/Makefile...
Updating sendmail.cf ...
This got rid of the error messages and shows something I don’t remember having seen before on earlier sendmail installs, which is the sendmail.conf file being used. Inspection of this file reveals:
# Parameter file for sendmail (sourced by /usr/share/sendmail/sendmail)
# Make all changes herein, instead of altering /etc/init.d/sendmail.
#
# After making changes here, you'll need to run /usr/sbin/sendmailconfig
# or /usr/share/sendmail/update_conf to have the changes take effect -
# If you change DAEMON_MODE, QUEUE_MODE, or QUEUE_INTERVAL, you'll also
# need to run /etc/init.d/sendmail restart.