xref: /original-bsd/usr.sbin/sendmail/cf/m4/proto.m4 (revision 2cc11bfc)
1divert(-1)
2#
3# Copyright (c) 1983 Eric P. Allman
4# Copyright (c) 1988 The Regents of the University of California.
5# All rights reserved.
6#
7# %sccs.include.redist.sh%
8#
9divert(0)
10
11VERSIONID(`@(#)proto.m4	6.42 (Berkeley) 06/01/93')
12
13MAILER(local)dnl
14
15ifdef(`_OLD_SENDMAIL_',
16`define(`_SET_96_', 6)dnl
17define(`_SET_97_', 7)dnl',
18`# level 4 config file format
19V4
20define(`_SET_96_', 96)dnl
21define(`_SET_97_', 97)dnl')
22
23##################
24#   local info   #
25##################
26
27CP.
28
29Cwlocalhost
30ifdef(`USE_CW_FILE',
31`# file containing names of hosts for which we receive email
32CONCAT(`Fw', confCW_FILE)', `dnl')
33
34ifdef(`UUCP_RELAY',
35`# UUCP relay host
36CONCAT(DY, UUCP_RELAY)
37CPUUCP
38
39')dnl
40ifdef(`BITNET_RELAY',
41`#  BITNET relay host
42CONCAT(DB, BITNET_RELAY)
43CPBITNET
44
45')dnl
46ifdef(`CSNET_RELAY',
47`# CSNET relay host
48CONCAT(DC, CSNET_RELAY)
49CPCSNET
50
51')dnl
52ifdef(`FAX_RELAY',
53`# FAX relay host
54CONCAT(DF, FAX_RELAY)
55CPFAX
56
57')dnl
58ifdef(`SMART_HOST',
59`# "Smart" UUCP relay host
60CONCAT(DS, SMART_HOST)
61
62')dnl
63ifdef(`MAILER_TABLE',
64`# Mailer table (overriding domains)
65Kmailertable MAILER_TABLE
66
67')dnl
68# who I send unqualified names to (null means deliver locally)
69CONCAT(DR, ifdef(`LOCAL_RELAY', LOCAL_RELAY))
70
71# who gets all local email traffic ($R has precedence for unqualified names)
72CONCAT(DH, ifdef(`MAIL_HUB', MAIL_HUB))
73
74# my official hostname ($w or $w.$D)
75CONCAT(Dj$w, ifdef(`NEED_DOMAIN', .$D))
76
77# who I masquerade as (can be $j)
78CONCAT(DM, ifdef(`MASQUERADE_NAME', MASQUERADE_NAME, $j))
79
80# class L: names that should be delivered locally, even if we have a relay
81# class E: names that should be exposed as from this host, even if we masquerade
82CLroot
83CEroot
84undivert(5)dnl
85
86# operators that cannot be in local usernames (i.e., network indicators)
87CO @ % ifdef(`_NO_UUCP_', `', `!')
88
89# a class with just dot (for identifying canonical names)
90C..
91
92ifdef(`_OLD_SENDMAIL_', `dnl',
93`# dequoting map
94Kdequote dequote')
95
96undivert(6)dnl
97
98######################
99#   Special macros   #
100######################
101
102# SMTP initial login message
103CONCAT(De, confSMTP_LOGIN_MSG)
104
105# UNIX initial From header format
106CONCAT(Dl, confFROM_LINE)
107
108# my name for error messages
109CONCAT(Dn, confMAILER_NAME)
110
111# delimiter (operator) characters
112CONCAT(Do, confOPERATORS)
113
114# format of a total name
115CONCAT(Dq, ifdef(`confFROM_HEADER', confFROM_HEADER,
116	ifdef(`_OLD_SENDMAIL_', `$g$?x ($x)$.', `$?x$x <$g>$|$g$.')))
117include(`../m4/version.m4')
118
119###############
120#   Options   #
121###############
122
123# strip message body to 7 bits on input?
124CONCAT(O7, confSEVEN_BIT_INPUT)
125
126# wait (in minutes) for alias file rebuild
127CONCAT(Oa, confALIAS_WAIT)
128
129# location of alias file
130CONCAT(OA, ifdef(`ALIAS_FILE', ALIAS_FILE, /etc/aliases))
131
132# minimum number of free blocks on filesystem
133CONCAT(Ob, confMIN_FREE_BLOCKS)
134
135# substitution for space (blank) characters
136CONCAT(OB, confBLANK_SUB)
137
138# connect to "expensive" mailers on initial submission?
139CONCAT(Oc, confCON_EXPENSIVE)
140
141# checkpoint queue runs after every N successful deliveries
142CONCAT(OC, confCHECKPOINT_INTERVAL)
143
144# default delivery mode
145CONCAT(Od, confDELIVERY_MODE)
146
147# automatically rebuild the alias database?
148CONCAT(OD, confAUTO_REBUILD)
149
150# error message header/file */
151ifdef(`confERROR_MESSAGE',
152	concat(OE, confERROR_MESSAGE),
153	#OE/etc/sendmail.oE)
154
155# error mode
156ifdef(`confERROR_MODE',
157	concat(Oe, confERROR_MODE),
158	#Oep)
159
160# save Unix-style "From_" lines at top of header?
161CONCAT(Of, confSAVE_FROM_LINES)
162
163# temporary file mode
164CONCAT(OF, confTEMP_FILE_MODE)
165
166# match recipients against GECOS field?
167CONCAT(OG, confMATCH_GECOS)
168
169# default GID
170CONCAT(Og, confDEF_GROUP_ID)
171
172# maximum hop count
173CONCAT(Oh, confMAX_HOP)
174
175# location of help file
176CONCAT(OH, ifdef(`HELP_FILE', HELP_FILE, /usr/lib/sendmail.hf))
177
178# ignore dots as terminators in incoming messages?
179CONCAT(Oi, confIGNORE_DOTS)
180
181# Insist that the BIND name server be running to resolve names
182ifdef(`confBIND_OPTS',
183	CONCAT(OI, confBIND_OPTS),
184	#OI)
185
186# deliver MIME-encapsulated error messages?
187CONCAT(Oj, confMIME_FORMAT_ERRORS)
188
189# Forward file search path
190ifdef(`confFORWARD_PATH',
191	CONCAT(OJ, confFORWARD_PATH),
192	#OJ/var/forward/$u:$z/.forward.$w:$z/.forward)
193
194# open connection cache size
195CONCAT(Ok, confMCI_CACHE_SIZE)
196
197# open connection cache timeout
198CONCAT(OK, confMCI_CACHE_TIMEOUT)
199
200# log level
201CONCAT(OL, confLOG_LEVEL)
202
203# send to me too, even in an alias expansion?
204CONCAT(Om, confME_TOO)
205
206# verify RHS in newaliases?
207CONCAT(On, confCHECK_ALIASES)
208
209# default messages to old style headers if no special punctuation?
210CONCAT(Oo, confOLD_STYLE_HEADERS)
211
212# SMTP daemon options
213ifdef(`confDAEMON_OPTIONS',
214	CONCAT(OO, confDAEMON_OPTIONS),
215	#OOPort=esmtp)
216
217# privacy flags
218CONCAT(Op, confPRIVACY_FLAGS)
219
220# who (if anyone) should get extra copies of error messages
221ifdef(`confCOPY_ERRORS_TO',
222	CONCAT(OP, confCOPY_ERRORS_TO),
223	#OPPostmaster)
224
225# slope of queue-only function
226ifdef(`confQUEUE_FACTOR',
227	CONCAT(Oq, confQUEUE_FACTOR),
228	#Oq600000)
229
230# queue directory
231CONCAT(OQ, ifdef(`QUEUE_DIR', QUEUE_DIR, /var/spool/mqueue))
232
233# read timeout -- now OK per RFC 1123 section 5.3.2
234ifdef(`confREAD_TIMEOUT',
235	CONCAT(Or, confREAD_TIMEOUT),
236	#Ordatablock=10m)
237
238# queue up everything before forking?
239CONCAT(Os, confSAFE_QUEUE)
240
241# status file
242CONCAT(OS, ifdef(`STATUS_FILE', STATUS_FILE, /etc/sendmail.st))
243
244# default message timeout interval
245CONCAT(OT, confMESSAGE_TIMEOUT)
246
247# time zone handling:
248#  if undefined, use system default
249#  if defined but null, use TZ envariable passed in
250#  if defined and non-null, use that info
251ifelse(confTIME_ZONE, `USE_SYSTEM', `#Ot',
252	confTIME_ZONE, `USE_TZ', `',
253	`CONCAT(Ot, confTIME_ZONE)')
254
255# default UID
256CONCAT(Ou, confDEF_USER_ID)
257
258# list of locations of user database file (null means no lookup)
259OU`'ifdef(`confUSERDB_SPEC', `confUSERDB_SPEC')
260
261# fallback MX host
262ifdef(`confFALLBACK_MX',
263	CONCAT(OV, confFALLBACK_MX),
264	#OVfall.back.host.net)
265
266# load average at which we just queue messages
267CONCAT(Ox, confQUEUE_LA)
268
269# load average at which we refuse connections
270CONCAT(OX, confREFUSE_LA)
271
272# work recipient factor
273ifdef(`confWORK_RECIPIENT_FACTOR',
274	CONCAT(Oy, confWORK_RECIPIENT_FACTOR),
275	#Oy30000)
276
277# deliver each queued job in a separate process?
278CONCAT(OY, confSEPARATE_PROC)
279
280# work class factor
281ifdef(`confWORK_CLASS_FACTOR',
282	CONCAT(Oz, confWORK_CLASS_FACTOR),
283	#Oz1800)
284
285# work time factor
286ifdef(`confWORK_TIME_FACTOR',
287	CONCAT(OZ, confWORK_TIME_FACTOR),
288	#OZ90000)
289
290###########################
291#   Message precedences   #
292###########################
293
294Pfirst-class=0
295Pspecial-delivery=100
296Plist=-30
297Pbulk=-60
298Pjunk=-100
299
300#####################
301#   Trusted users   #
302#####################
303
304Troot
305Tdaemon
306Tuucp
307
308#########################
309#   Format of headers   #
310#########################
311
312H?P?Return-Path: $g
313HReceived: $?sfrom $s $.$?_($_) $.by $j ($v/$Z)$?r with $r$. id $i; $b
314H?D?Resent-Date: $a
315H?D?Date: $a
316H?F?Resent-From: $q
317H?F?From: $q
318H?x?Full-Name: $x
319HSubject:
320# HPosted-Date: $a
321# H?l?Received-Date: $b
322H?M?Resent-Message-Id: <$t.$i@$j>
323H?M?Message-Id: <$t.$i@$j>
324#
325######################################################################
326######################################################################
327#####
328#####			REWRITING RULES
329#####
330######################################################################
331######################################################################
332
333undivert(9)dnl
334
335###########################################
336###  Rulset 3 -- Name Canonicalization  ###
337###########################################
338S3
339
340# handle null input and list syntax (translate to <@> special case)
341R$@			$@ <@>
342R$*:;$*			$@ $1 :; <@>
343
344# basic textual canonicalization -- note RFC733 heuristic here
345R$*<$*>$*<$*>$*		<$2>$3$4$5			strip multiple <> <>
346R$*<$*<$+>$*>$*		<$3>$5				2-level <> nesting
347R$*<>$*			$@ <@>				MAIL FROM:<> case
348R$*<$+>$*		$2				basic RFC821/822 parsing
349
350# make sure <@a,@b,@c:user@d> syntax is easy to parse -- undone later
351R@ $+ , $+		@ $1 : $2			change all "," to ":"
352
353# localize and dispose of route-based addresses
354R@ $+ : $+		$@ $>_SET_96_ < @$1 > : $2		handle <route-addr>
355
356# find focus for list syntax
357R $+ : $* ; @ $+	$@ $>_SET_96_ $1 : $2 ; < @ $3 >	list syntax
358R $+ : $* ;		$@ $1 : $2;			list syntax
359
360# find focus for @ syntax addresses
361R$+ @ $+		$: $1 < @ $2 >			focus on domain
362R$+ < $+ @ $+ >		$1 $2 < @ $3 >			move gaze right
363R$+ < @ $+ >		$@ $>_SET_96_ $1 < @ $2 >		already canonical
364
365ifdef(`_NO_UUCP_', `dnl',
366`# convert old-style addresses to a domain-based address
367R$- ! $+		$@ $>_SET_96_ $2 < @ $1 .UUCP >	resolve uucp names
368R$+ . $- ! $+		$@ $>_SET_96_ $3 < @ $1 . $2 >		domain uucps
369R$+ ! $+		$@ $>_SET_96_ $2 < @ $1 .UUCP >	uucp subdomains')
370
371# if we have % signs, take the rightmost one
372R$* % $*		$1 @ $2				First make them all @s.
373R$* @ $* @ $*		$1 % $2 @ $3			Undo all but the last.
374R$* @ $*		$@ $>_SET_96_ $1 < @ $2 >		Insert < > and finish
375
376# else we must be a local name
377
378
379################################################
380###  Ruleset _SET_96_ -- bottom half of ruleset 3  ###
381################################################
382
383#  At this point, everything should be in a "local_part<@domain>extra" format.
384S`'_SET_96_
385
386# handle special cases for local names
387R$* < @ localhost > $*		$: $1 < @ $j . > $2		no domain at all
388R$* < @ localhost . $m > $*	$: $1 < @ $j . > $2		local domain
389ifdef(`_NO_UUCP_', `dnl',
390`R$* < @ localhost . UUCP > $*	$: $1 < @ $j . > $2		.UUCP domain')
391undivert(2)dnl
392
393ifdef(`_NO_UUCP_', `dnl',
394`ifdef(`UUCP_RELAY',
395`# pass UUCP addresses straight through
396R$* < @ $+ . UUCP > $*		$@ $1 < @ $2 . UUCP > $3',
397`# if really UUCP, handle it immediately
398ifdef(`_CLASS_U_',
399`R$* < @ $=U . UUCP > $*	$@ $1 < @ $2 . UUCP > $3', `dnl')
400ifdef(`_CLASS_V_',
401`R$* < @ $=V . UUCP > $*	$@ $1 < @ $2 . UUCP > $3', `dnl')
402ifdef(`_CLASS_W_',
403`R$* < @ $=W . UUCP > $*	$@ $1 < @ $2 . UUCP > $3', `dnl')
404ifdef(`_CLASS_X_',
405`R$* < @ $=X . UUCP > $*	$@ $1 < @ $2 . UUCP > $3', `dnl')
406ifdef(`_CLASS_Y_',
407`R$* < @ $=Y . UUCP > $*	$@ $1 < @ $2 . UUCP > $3', `dnl')
408
409# try UUCP traffic as a local address
410R$* < @ $+ . UUCP > $*		$: $1 < @ $[ $2 $] . UUCP > $3
411ifdef(`_OLD_SENDMAIL_',
412`R$* < @ $+ . $+ . UUCP > $*		$@ $1 < @ $2 . $3 . > $4',
413`R$* < @ $+ . . UUCP > $*		$@ $1 < @ $2 . > $3')')
414')
415ifdef(`_NO_CANONIFY_', `dnl',
416`# pass to name server to make hostname canonical
417R$* < @ $* $~P > $*		$: $1 < @ $[ $2 $3 $] > $4
418')
419undivert(8)dnl
420
421# if this is the local hostname, make sure we treat is as canonical
422R$* < @ $j > $*			$: $1 < @ $j . > $2
423
424
425##################################################
426###  Ruleset 4 -- Final Output Post-rewriting  ###
427##################################################
428S4
429
430R$*<@>			$@ $1				handle <> and list:;
431
432# resolve numeric addresses to name if possible
433R$* < @ [ $+ ] > $*	$: $1 < @ $[ [$2] $] > $3	lookup numeric internet addr
434
435# strip trailing dot off possibly canonical name
436R$* < @ $+ . > $*	$1 < @ $2 > $3
437
438# externalize local domain info
439R$* < $+ > $*		$1 $2 $3			defocus
440R@ $+ : @ $+ : $+	@ $1 , @ $2 : $3		<route-addr> canonical
441R@ $*			$@ @ $1				... and exit
442
443ifdef(`_NO_UUCP_', `dnl',
444`# UUCP must always be presented in old form
445R$+ @ $- . UUCP		$2!$1				u@h.UUCP => h!u')
446
447# delete duplicate local names
448R$+ % $=w @ $=w		$1 @ $j				u%host@host => u@host
449
450
451
452##############################################################
453###   Ruleset _SET_97_ -- recanonicalize and call ruleset zero   ###
454###		   (used for recursive calls)		   ###
455##############################################################
456
457S`'_SET_97_
458R$*			$: $>3 $1
459R$*			$@ $>0 $1
460
461
462######################################
463###   Ruleset 0 -- Parse Address   ###
464######################################
465
466S0
467
468R<@>			$#local $: <>			special case error msgs
469R$*:;<@>		$#error $@ USAGE $: "list:; syntax illegal for recipient addresses"
470
471ifdef(`_MAILER_smtp_',
472`# handle numeric address spec
473R$* < @ [ $+ ] > $*	$: $1 < @ $[ [$2] $] > $3	numeric internet addr
474R$* < @ [ $+ ] > $*	$#smtp $@ [$2] $: $1 @ [$2] $3	numeric internet spec',
475`dnl')
476
477# now delete the local info -- note $=O to find characters that cause forwarding
478R$* < @ > $*		$@ $>_SET_97_ $1			user@ => user
479R< @ $=w . > : $*	$@ $>_SET_97_ $2			@here:... -> ...
480R$* $=O $* < @ $=w . >	$@ $>_SET_97_ $1 $2 $3			...@here -> ...
481ifdef(`MAILER_TABLE',
482`
483# try mailer table lookup
484R$* <@ $+ > $*		$: < $2 > $1 < @ $2 > $3	extract host name
485R<$+ . > $*		$: < $1 > $2			strip trailing dot
486R<$- . $+ > $*		$: < $(mailertable .$2 $: $) > $3	lookup
487R<$- : $+ > $*		$# $1 $@ $2 $: $3		check -- resolved?
488R<$- . $+ > $*		$: $>90 <$2> $3			try domain',
489`dnl')
490
491# short circuit local delivery so forwarded email works
492ifdef(`_LOCAL_NOT_STICKY_',
493`R$=L < @ $=w . >		$#local $: @ $1			special local names
494R$+ < @ $=w . >		$#local $: $1			dispose directly',
495`R$+ < @ $=w . >		$: $1 < @ $2 @ $H >		first try hub
496ifdef(`_OLD_SENDMAIL_',
497`R$+ < $+ @ $-:$+ >	$# $3 $@ $4 $: $1 < $2 >	yep ....
498R$+ < $+ @ $+ >		$#relay $@ $3 $: $1 < $2 >	yep ....
499R$+ < $+ @ >		$#local $: $1			nope, local address',
500`R$+ < $+ @ $+ >		$#local $: $1			yep ....
501R$+ < $+ @ >		$#local $: @ $1			nope, local address')')
502undivert(3)dnl
503undivert(4)dnl
504
505# resolve remotely connected UUCP links (if any)
506ifdef(`_CLASS_V_',
507`R$* < @ $=V . UUCP > $*		$#smtp $@ $V $: <@ $V> : $1 @ $2.UUCP $3',
508	`dnl')
509ifdef(`_CLASS_W_',
510`R$* < @ $=W . UUCP > $*		$#smtp $@ $W $: <@ $W> : $1 @ $2.UUCP $3',
511	`dnl')
512ifdef(`_CLASS_X_',
513`R$* < @ $=X . UUCP > $*		$#smtp $@ $X $: <@ $X> : $1 @ $2.UUCP $3',
514	`dnl')
515
516# resolve fake top level domains by forwarding to other hosts
517ifdef(`BITNET_RELAY',
518`R$*<@$+.BITNET>$*	$#smtp $@ $B. $: $1 <@$2.BITNET> $3	user@host.BITNET',
519	`dnl')
520ifdef(`CSNET_RELAY',
521`R$*<@$+.CSNET>$*	$#smtp $@ $C. $: $1 <@$2.CSNET> $3	user@host.CSNET',
522	`dnl')
523ifdef(`_MAILER_fax_',
524`R$+ < @ $+ .FAX >	$#fax $@ $2 $: $1			user@host.FAX',
525`ifdef(`FAX_RELAY',
526`R$*<@$+.FAX>$*		$#smtp $@ $F. $: $1 <@$2.FAX> $3	user@host.FAX',
527	`dnl')')
528
529ifdef(`UUCP_RELAY',
530`# forward non-local UUCP traffic to our UUCP relay
531R$*<@$*.UUCP>$*		$#smtp $@ $Y. $: <@ $Y> : $1 @ $2.UUCP $3	uucp mail',
532`ifdef(`_MAILER_uucp_',
533`# forward other UUCP traffic straight to UUCP
534R< @ $+ .UUCP > : $+	$#uucp $@ $1 $: $2			@host.UUCP:...
535R$+ < @ $+ .UUCP >	$#uucp $@ $2 $: $1			user@host.UUCP',
536	`dnl')')
537
538ifdef(`_LOCAL_RULES_',
539`# figure out what should stay in our local mail system
540undivert(1)',
541`ifdef(`_MAILER_smtp_',
542`# deal with other remote names
543R$* < @ $* > $*		$#smtp $@ $2 $: $1 < @ $2 > $3		user@host.domain')')
544ifdef(`SMART_HOST', `
545# pass names that still have a host to a smarthost
546R$* < @ $* > $*		$: < $S > $1 < @ $2 > $3	glue on smarthost name
547R<$-:$+> $* < @$* > $*	$# $1 $@ $2 $: $3 < @ $4 > $5	if non-null, use it
548R<$+> $* < @$* > $*	$#suucp $@ $1 $: $2 < @ $3 > $4	if non-null, use it
549R<> $* < @ $* > $*	$1 < @ $2 > $3			else strip off gunk',
550`ifdef(`_LOCAL_RULES_', `
551# reject messages that have host names we do not understand
552R$* < @ $* > $*		$#error $@ NOHOST $: Unrecognized host name $2',
553`dnl')')
554ifdef(`_MAILER_USENET_', `
555# addresses sent to net.group.USENET will get forwarded to a newsgroup
556R$+ . USENET		$# usenet $: $1')
557
558ifdef(`_OLD_SENDMAIL_',
559`# forward remaining names to local relay, if any
560R$=L			$#local $: $1			special local names
561R$+			$: $1 < @ $R >			append relay
562R$+ < @ >		$: $1 < @ $H >			no relay, try hub
563R$+ < @ >		$#local $: $1			no relay or hub: local
564R$+ < @ $=w  >		$#local $: $1			we are relay/hub: local
565R$+ < @ $-:$+ >		$# $2 $@ $3 $: $1		deliver to relay/hub
566R$+ < @ $+ >		$#relay $@ $2 $: $1		deliver to relay/hub',
567
568`# if this is quoted, strip the quotes and try again
569R$+			$: $(dequote $1 $)		strip quotes
570R$* $=O $*		$@ $>_SET_97_ $1 $2 $3			try again
571
572# handle locally delivered names
573R$=L			$#local $: @ $1			special local names
574R$+			$#local $: $1			regular local names
575
576###########################################################################
577###   Ruleset 5 -- special rewriting after aliases have been expanded   ###
578###		   (new sendmail only)					###
579###########################################################################
580
581S5
582
583# see if we have a relay or a hub
584R$+			$: $1 < @ $R >
585R$+ < @ >		$: $1 < @ $H >			no relay, try hub
586R$+ < @ $=w >		$@ $1				we are relay/hub: local
587R$+ < @ $-:$+ >		$# $2 $@ $3 $: $1		send to relay or hub
588ifdef(`_MAILER_smtp_',
589`R$+ < @ $+ >		$#relay $@ $2 $: $1		send to relay or hub')')
590ifdef(`MAILER_TABLE',
591`
592
593###########################################################################
594###  Ruleset 90 -- try domain part of mailertable entry 		###
595###		   (new sendmail only)					###
596###########################################################################
597
598S90
599R<$- . $+ > $*		$: < $(mailertable .$2 $: $) > $3	lookup
600R<$- : $+ > $*		$# $1 $@ $2 $: $3		check -- resolved?
601R<$- . $+ > $*		$@ $>90 <$2> $3			no -- strip & try again
602R<$*> $*		$@ $2				no match',
603`dnl')
604#
605######################################################################
606######################################################################
607#####
608`#####			MAILER DEFINITIONS'
609#####
610######################################################################
611######################################################################
612undivert(7)dnl
613