Configuration of sendmail V8

If you have sendmail installed on your systen chances are you have the whole 
set of sendmail configuration files. For instance, the Slackware distribution 
I have hid them in a package called smailcnf.tgz. You'll most likely find 
them in /usr/src/sendmail/cf. There should be a approx. 50KB big README which 
describes the new configuration-method for sendmail. In addition, you will 
need all the m4 macros for sendmail (which should have come with the sendmail
sources, or you can have sendmail-cf.blabla.rpm; sure other distrib schemes 
have their equivalent packages too) 

Though sendmail is controlled via an almost 20KB big configuration file
(/etc/sendmail.cf) you don't have to write it on your own (which most of the 
people think, those who are scared of sendmail). In order to facilitate the
configuration of sendmail you will need the following m4 script, it replaces
the ugly SENDMAIL.sh :) It needs fnet.m4 that is included in last tx and that 
goes in ..../sendmail-cf/mailer/ and another configuration file which follows
(ifmail.mc) which goes in ....sendmail/cf/cf. 

The m4 script will create your /etc/sendmail.cf file from these two other 
files and a few other supporting files, which you may or may not need to 
change.

NOTES:
* adds anti-spam support (add email/domains to block in /etc/sendmail.rej)
* assumess you use *.fidonet.org domain for fidonet and *.ftn for othernets
* uses a "mailertable" database for special routings (others than internet
  smart host and FTN smart host)
* uses "revaliases" database to masquerade From: lines; putting the real
  email on them.
* uses a "private" database to redirect messages to addresses on other
  domains than yours (that is useful to avoid sending to internet mail
  write on your machine to users that are also on your machine)

Now inorder to make IFMAIL known you will need to create a file called
.....sendmail-cf/mailer/ftn.m4 with the following content:


# ....sendmail-cf/mailer/ftn.m4
#
# IFMAIL FTN mailer for sendmail V8
#
# MAILER(smtp) and MAILER(uucp) must be included!
#
PUSHDIVERT(-1)
ifdef(`FIDO_MAILER_FLAGS',, `define(`FIDO_MAILER_FLAGS', `8mDFMuSC')')
ifdef(`FIDO_MAILER_PATH',, `define(`FIDO_MAILER_PATH', /usr/lib/ifmail/ifmail)')
ifdef(`FIDO_MAILER_USER',, `define(`FIDO_MAILER_USER', `fnet:uucp')')
ifdef(`FIDO_MAILER_ARGS_H',, `define(`FIDO_MAILER_ARGS_H', `ifmail -r $h -g h $u')')
ifdef(`FIDO_MAILER_ARGS_C',, `define(`FIDO_MAILER_ARGS_C', `ifmail -r $h -g c $u')')
ifdef(`FIDO_MAILER_ARGS_B',, `define(`FIDO_MAILER_ARGS_B', `ifmail -b -r $h -g h $u')')
ifdef(`FIDO_MAILER_ARGS_P',, `define(`FIDO_MAILER_ARGS_P', `ifmail -l-3 -r $h -g h $u')')
POPDIVERT

#############################
# FIDO Mailer specification #
#############################

VERSIONID(`@(#)fnet.m4  1.01 (srtxg@f2219.n293.z2.fidonet.org) 7/7/97')

# normal fnet mailer, pkt as hold
Mfnet,  P=FIDO_MAILER_PATH, F=FIDO_MAILER_FLAGS, S=11, R=21,
        _OPTINS(`FIDO_MAILER_CHARSET', `C=', `, ')U=FIDO_MAILER_USER,
        ifdef(`FIDO_MAILER_MAX', `M=FIDO_MAILER_MAX, ')A=FIDO_MAILER_ARGS_H

# This is for crash mail just in case you need it * USE WHITH CARE *
Mfnet-crash,  P=FIDO_MAILER_PATH, F=FIDO_MAILER_FLAGS, S=11, R=21,
        _OPTINS(`FIDO_MAILER_CHARSET', `C=', `, ')U=FIDO_MAILER_USER,
        ifdef(`FIDO_MAILER_MAX', `M=FIDO_MAILER_MAX, ')A=FIDO_MAILER_ARGS_C

# This doesn't split messages when writting in pkt, of course the node
# receiving the pkt must be able to handle arbitrary size messages.
# if the other end uses ifmail too use this.
Mfnet-big,  P=FIDO_MAILER_PATH, F=FIDO_MAILER_FLAGS, S=11, R=21,
        _OPTINS(`FIDO_MAILER_CHARSET', `C=', `, ')U=FIDO_MAILER_USER,
        ifdef(`FIDO_MAILER_MAX', `M=FIDO_MAILER_MAX, ')A=FIDO_MAILER_ARGS_B

# This one uses a "kludge verbosity" of level -3, that is nothing is kept
# from usenet/email infos.
Mfnet-poor, P=FIDO_MAILER_PATH, F=FIDO_MAILER_FLAGS, S=11, R=21,
	_OPTINS(`FIDO_MAILER_CHARSET', `C=', `, ')U=FIDO_MAILER_USER,
	ifdef(`FIDO_MAILER_MAX', `M=FIDO_MAILER_MAX, ')A=FIDO_MAILER_ARGS_P

As one can see the m4 configuration file for ifmail isn't that complex, and we
don't have to care about what exactly is happening, we simply use the defined
mailer "ftn" like the predefined mailers "smtp", "uucp" etc. A simple 
definition of the ftn mailer options will be explaned later on.

Now let's go on to the next configuration file. I called it /ifmail.mc, but 
the name isn't that relevant, what is only necessary is that it resides in 
.....sendmail/cf/cf. ifmail.mc looks like this:

# ....sendmail/cf/cf/ifmail.mc
#
# sendmail V8 configuration for mymachine.mc
# using UUCP and IFMAIL
#
divert(-1)
define(`SMART_HOST',		``[smtp.your.provider.com]'')
define(`FIDO_HOST_ADDRESS',	``f15.n2.z3.fidonet.org'')
define(`FIDO_SMART_HOST',	``f1.n2.z3.fidonet.org'')
define(`FIDO_GATEWAY',		``f4.n5.z6.fidonet.org'')
define(`USE_FGATE')

include(`../m4/cf.m4')
define(`confDEF_USER_ID',``8:12'')
define(`confMATCH_GECOS',`True')
define(`confTRY_NULL_MX_LIST',`True')
define(`confTO_QUEUEWARN', `2d')
define(`confTO_QUEUERETURN', `8d')
define(`confUSE_ERRORS_TO',`True')
define(`confTRUSTED_USERS',`fnet')
OSTYPE(`linux')
undefine(`UUCP_RELAY')
undefine(`BITNET_RELAY')
FEATURE(redirect)
FEATURE(always_add_domain)
FEATURE(use_cw_file)
FEATURE(nodns)
FEATURE(nocanonify)
FEATURE(mailertable)
FEATURE(genericstable,``hash -o /etc/revaliases'')
GENERICS_DOMAIN_FILE(confCW_FILE)
FEATURE(masquerade_envelope)
FEATURE(local_procmail)
MAILER(procmail)
MAILER(smtp)
MAILER(fnet)
MAILER(uucp)

LOCAL_CONFIG
# Pseudo-domains (don't call the DNS on them)
CPz1.fidonet.org z2.fidonet.org z3.fidonet.org z4.fidonet.org
CPz5.fidonet.org z6.fidonet.org ftn

# Domains and addresses we refuse mail from
FR/etc/sendmail.rej

# for fidonet address, don't send trough fnet mailer addresses like
# smtp.z2.fidonet.org, www.z2.fidonet.org, etc
CFfidonet ns ns2 mail smtp www ftp

# email address on other domains that we redirect
Kprivate hash -o /etc/private

LOCAL_NET_CONFIG
# private
R$+ < @ $+ > $*			$: < $(private $1 @ $2 $: $) > $1 < @ $2 > $3
R< $+ > $+ < @ $+ > $*		$@ $>97 $1
R<> $+ < @ $+ > $*		$: $1 < @ $2 > $3

# ************ FIDONET.ORG ***********
# for nodes allways put leading $* if you want to route his points too
# routed trough default smart host FIDO_SMART_HOST
R$* < @ $~F $+ .z1.fidonet.org . > $*	$#fnet $@ FIDO_SMART_HOST $: $1 < @ $2 $3 .z1.fidonet.org > $4
R$* < @ $~F $+ .z2.fidonet.org . > $*	$#fnet $@ FIDO_SMART_HOST $: $1 < @ $2 $3 .z2.fidonet.org > $4
R$* < @ $~F $+ .z3.fidonet.org . > $*	$#fnet $@ FIDO_SMART_HOST $: $1 < @ $2 $3 .z3.fidonet.org > $4
R$* < @ $~F $+ .z4.fidonet.org . > $*	$#fnet $@ FIDO_SMART_HOST $: $1 < @ $2 $3 .z4.fidonet.org > $4
R$* < @ $~F $+ .z5.fidonet.org . > $*	$#fnet $@ FIDO_SMART_HOST $: $1 < @ $2 $3 .z5.fidonet.org > $4
R$* < @ $~F $+ .z6.fidonet.org . > $*	$#fnet $@ FIDO_SMART_HOST $: $1 < @ $2 $3 .z6.fidonet.org > $4

# all the remaining FTN's (via fido smart host FIDO_SMART_HOST)
R$* < @ $+ .ftn . > $*			$#fnet $@ FIDO_SMART_HOST $: $1 < @ $2 .ftn > $3

# If you don't have internet connectivity comment out this line
# to send through the gateway FIDO_GATEWAY
# (packets will go to your default uplink FIDO_SMART_HOST)
ifdef(`USE_FGATE',`',`#')R$* < @ $* > $*			$#fnet $@ FIDO_SMART_HOST $: $1 % $2 < @ FIDO_GATEWAY > $3

LOCAL_RULE_0
###################
# ANTI-SPAM RULES #
###################

Scheck_mail
R < $=R >			$#error $@ 5.7.1 $: "571 unsolicited email is refused"
R $=R				$#error $@ 5.7.1 $: "571 unsolicited email is refused"
R$*				$: $>3 $1
R $+ < @ $* $=R >		$#error $@ 5.7.1 $: "571 unsolicited email is refused"
R $+ < @ $* $=R . >		$#error $@ 5.7.1 $: "571 unsolicited email is refused"
R$*				$@ OK

Scheck_compat
#sender-address $| recipient-address
R $+ % $* @ FIDO_GATEWAY $| $*	$: $1 @ $2 $| $3
R < $+ @ $* $=R > $| $*		$#error $@ 5.7.1 $: "571 unsolicited email is refused"
R $+ @ $* $=R $| $*		$#error $@ 5.7.1 $: "571 unsolicited email is refused"
R < $=R > $| $*			$#error $@ 5.7.1 $: "571 unsolicited email is refused"
R $=R $| $*			$#error $@ 5.7.1 $: "571 unsolicited email is refused"

# To: "UUCP" at local is returned back. Because it happens with ifmail
# receiving mail to "UUCP" via FTN but whitout a To: line specifying a
# destination ! 8-)
R $* fidonet.org $| UUCP	$#error $: "You MUST provide a To: address"
R $* ftn $| UUCP		$#error $: "You MUST provide a To: address"

R$*				$@ OK
#############
#    End    #
#############

You will need to reconfigure the following lines in the ifmail.mc file to 
reflect your systems configuration. 

define(`SMART_HOST',            ``[smtp.your.provider.com]'')
define(`FIDO_HOST_ADDRESS',     ``f15.n2.z3.fidonet.org'')
define(`FIDO_SMART_HOST',       ``f1.n2.z3.fidonet.org'')
define(`FIDO_GATEWAY',          ``f4.n5.z6.fidonet.org'')
define(`USE_FGATE')

Here's a breif explanation of the above mailer defines.

SMART_HOST defines your ISP smart host, that is the machine you sent
	email to. That is a machine accessible by smtp (when you
	connect to the internet throug PPP do "sendmail -q" and it
	delivers the mail). enclose the name with [ ] if you are not 
	connected 24h/24h, otherwise problems will happen.
FIDO_HOST_ADDRESS is *your* fido address (can be a point address of course)
FIDO_SMART_HOST your fido uplink address, that is where you send pkt to.
FIDO_GATEWAY the fidonet -> internet gateway nearest to you
USE_FGATE this one is a little different. If you have *NO* internet
	connectivity at all, that is if you rely on the fidonet gateway,
	put this line:
define(`USE_FGATE')
	however, if you can connect to the internet to send to a smart host
	put this one instead :
undefine(`USE_FGATE')

After editing the ifmail.mc file, your ready to create the sendmail.cf file. 
Go to the directory ....sendmail/cf/cf and execute pmake ifmail.cf. The file
.....sendmail/cf/cf/obj/ifmail.cf should have been created. Move this file to 
/etc/sendmail.cf and the sendmail configuration is ready. In case pmake isn't 
installed run this instead:

m4 ifmail.mc > /etc/sendmail.cf

#
#
Don't forget to include in /etc/sendmail.cw a list of all your machine local
addresses (either uucp name if one, fidonet, other FTN,...).
Exemple I have :

# sendmail.cw - include all aliases for your machine here.
chanae.stben.be
linux.chanae.stben.be
f2219.n293.z2.fidonet.org
p29.f1.n850.z4.fidonet.org
f4120.n320.z101.francom.ftn

#
#
If you are connected to other FTN networks or if you want some routing other
than trough FIDO_SMART_HOST and/or SMART_HOST edit the file /etc/mailertable
to add some special routings, using the syntax :

domain		transport:trough.system

ex:

f2219.n293.z2.fidonet.org	fnet:f2219.n293.z2.fidonet.org

sends direct to 2:293/2219 trough fnet. NOTE: points aren't handled, for
that you will also need:

..f2219.n293.z2.fidonet.org	fnet:f2219.n293.z2.fidonet.org

note the leading dot !

For *your* points put (assming you are f15.n2.z3.fidonet.org) :

..f15.n2.z3.fidonet.org		fnet:%1.f15.n2.z3.fidonet.org

(again note the leading dot, and the %1)

for othernets is the same, ex:

..maxwellnet.ftn			fnet:f12.n34.z555.maxwellnet.ftn

and for other transports too:

..some.uucp			uucp-dom:barney
..some.smtp			smtp:[local.networked.machine]

each time you modify /etc/mailertable you need to recompile it running:

makemap hash /etc/mailertable < /etc/mailertable

#
#
To masquerade From: addresses edit /etc/revaliases and add lines like

localuser	login@somewhere

to masquerade the local user "localuser" as "login@somewhere".
each time you modify /etc/revaliases you need to recompile it running:

makemap hash /etc/revaliases < etc/revaliases

#
#
To redirect mail to specific users of other domains add in /etc/private
lines like:

someuser@somewhere	someother@other.place
user@domain		localuser

For exemple if you use "peter" as your login on your linux box; and
your email at your ISP is psmith@aol.com; then you can put:

psmith@aol.com		peter

so if someone sends mail to psmith@aol.com it isn't sent to internet
but directly sent to local user peter.

each time you modify /etc/private you need to recompile it running:

makemap hash /etc/private < /etc/private

#
#
Here is a breif explanation of what "F=8mDFMhuSC, S=11, R=21" in
the fnet.m4 file delivery agent definition:

The F section contains the flags which describe a delivery agent's
behavior. Here is a breakdown of what your flags mean:
	8 = use 8 bit
	m = allow delivery to multiple recipients
	D = force inclusion of date information in mail header
	M = force inclusion of message identification information in mail
            header 
	F = force inclusion of sender (From) information in mail header
	h = preserve case in hostname 
	u = preserve case for username

The C flag causes sendmail to append a domain to recipients without one
(the domain of the sender. Useful when sending to someone on your own
BBS); and the S flag causes sendmail to invoke the delivery agent
(in this case ifmail) with the user and group id specified by the U=
equate. If the U= equate is missing or 0 sendmail runs the delivery agent 
as root (note: in sendmail versions prior to v8.7, there was no U= equate,
so the S flag causes sendmail to always run the delivery agent as root). 
I don't have a U= equate, so ifmail runs as root which seems to be fine for 
me. 

The S section specifies the Sender rewriting rule set, with rule 51 being 
used for the envelope and rule 31 used for the header. Finally the R section 
specifies the Recipient rewriting rule set. In this case rule set 21 is used 
for rewriting both headers and the envelope. Look around in your sendmail.cf 
file to find these rules and see what they do.

By the way, this information comes from the book "sendmail, 2nd edition" by 
Bryan Costales and Eric Allman (who is the author of sendmail) published by 
O'Reilly & Associates (ISBN 1-56592-222-0). I strongly recommend it to anyone
who is working with sendmail. It is very thourough and well written, with many 
examples.

After successfully creating a sendmail.cf file your now ready to create a 
mail alias-file. Without going in to great detail, mail aliasing is just 
one of sendmails powerful features which allows forwarding of mail to other
sites and users. Its not hard to adminaster. The mail sent to the person on 
the left is forwarded to the person on the right. Here's what my alias file 
looks like.    

#
# /etc/aliases
#
# compile this file by issueing the command: newaliases
#
nobody: /dev/null
root: gfryde01
support: gfryde01
admin: gfryde01
operator: gfryde01
postmaster: gfryde01
faxadmin: gfryde01 
usenet: gfryde01
sysop: gfryde01
uucp: gfryde01
news: gfryde01
mail: gfryde01
fnet: gfryde01
fido: gfryde01
greg_frydenlund: gfryde01
greg.frydenlund: gfryde01
gregfrydenlund: gfryde01

This file has to be compiled with the command newaliases to a database after 
any changes.  

Now to start sendmail as a daemon by entering:

/usr/sbin/sendmail -bd -q 15m

Add the above line to /etc/rc.d/rc.local. On many systems it is already defined
in /etc/rc.d/rc.M which is possible, too. Alternatively one can start sendmail
by cron, and let inetd listen to the port. For this enter the following in the
crontab of the user root:

*/20  * * * *   /usr/sbin/sendmail -q

and insert the following into your /etc/inetd.conf:

smtp  stream  tcp   nowait  root  /usr/sbin/tcpd  /usr/sbin/sendmail -bs

Don't forget to kill -HUP inetd after changing inetd.conf, to inform inetd 
about your changes.

sendmail will write its log messages via syslogd. I recommend to enter the 
following entry in /etc/syslog.conf:

mail.*                      /var/log/mail

Do not forget to restart syslogd after this change with a killall -1 as already
described in Configuration of ifcico.

#
#
#
# Testing sendmails rewrite rules_

Sendmail has a built-in mechanism which allows you to test the rewrite rules
found in a .cf file.  The rewrite rules we are particularly interested in are
the fidonet ones. First, you will need to startup sendmail in "test mode" 
with the following command.

sendmail -bt

Second, issue the following command at the prompt and hopefully you should see 
something simialiar the list below.

> 3,0 me@f10.n125.z1.fidonet.org

The last line in the list below is the one were interested in.

rewrite: ruleset   3     input: me @ f10 . n125 . z1 . fidonet . org
rewrite: ruleset  96     input: < me @ f10 . n125 . z1 . fidonet . org . >
rewrite: ruleset  96   returns: < me @ f10 . n125 . z1 . fidonet . org . >
rewrite: ruleset   3   returns: < me @ f10 . n125 . z1 . fidonet . org . >
rewrite: ruleset   0     input: < me @ f10 . n125 . z1 . fidonet . org . >
rewrite: ruleset  98     input: < me @ f10 . n125 . z1 . fidonet . org . >
rewrite: ruleset  98   returns: < me @ f10 . n125 . z1 . fidonet . org . >
rewrite: ruleset   0   returns: $# ftn $@ f33 . n125 . z1 $: me < @ f33 . n125
.. z1 . fidonet . org >
  
As you can see at the bottom of this list the mailer _ftn_ is called which 
is exactly what you want. I suggest you try various address (me@localhost) 
to be sure that sendmail handles all the rewrite rules appropreiatly for 
your own system.