xref: /original-bsd/usr.sbin/sendmail/cf/m4/proto.m4 (revision c3e32dec)
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.47 (Berkeley) 06/08/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# use Errors-To: header?
201CONCAT(Ol, confUSE_ERRORS_TO)
202
203# log level
204CONCAT(OL, confLOG_LEVEL)
205
206# send to me too, even in an alias expansion?
207CONCAT(Om, confME_TOO)
208
209# verify RHS in newaliases?
210CONCAT(On, confCHECK_ALIASES)
211
212# default messages to old style headers if no special punctuation?
213CONCAT(Oo, confOLD_STYLE_HEADERS)
214
215# SMTP daemon options
216ifdef(`confDAEMON_OPTIONS',
217	CONCAT(OO, confDAEMON_OPTIONS),
218	#OOPort=esmtp)
219
220# privacy flags
221CONCAT(Op, confPRIVACY_FLAGS)
222
223# who (if anyone) should get extra copies of error messages
224ifdef(`confCOPY_ERRORS_TO',
225	CONCAT(OP, confCOPY_ERRORS_TO),
226	#OPPostmaster)
227
228# slope of queue-only function
229ifdef(`confQUEUE_FACTOR',
230	CONCAT(Oq, confQUEUE_FACTOR),
231	#Oq600000)
232
233# queue directory
234CONCAT(OQ, ifdef(`QUEUE_DIR', QUEUE_DIR, /var/spool/mqueue))
235
236# read timeout -- now OK per RFC 1123 section 5.3.2
237ifdef(`confREAD_TIMEOUT',
238	CONCAT(Or, confREAD_TIMEOUT),
239	#Ordatablock=10m)
240
241# queue up everything before forking?
242CONCAT(Os, confSAFE_QUEUE)
243
244# status file
245CONCAT(OS, ifdef(`STATUS_FILE', STATUS_FILE, /etc/sendmail.st))
246
247# default message timeout interval
248CONCAT(OT, confMESSAGE_TIMEOUT)
249
250# time zone handling:
251#  if undefined, use system default
252#  if defined but null, use TZ envariable passed in
253#  if defined and non-null, use that info
254ifelse(confTIME_ZONE, `USE_SYSTEM', `#Ot',
255	confTIME_ZONE, `USE_TZ', `',
256	`CONCAT(Ot, confTIME_ZONE)')
257
258# default UID
259CONCAT(Ou, confDEF_USER_ID)
260
261# list of locations of user database file (null means no lookup)
262OU`'ifdef(`confUSERDB_SPEC', `confUSERDB_SPEC')
263
264# fallback MX host
265ifdef(`confFALLBACK_MX',
266	CONCAT(OV, confFALLBACK_MX),
267	#OVfall.back.host.net)
268
269# load average at which we just queue messages
270CONCAT(Ox, confQUEUE_LA)
271
272# load average at which we refuse connections
273CONCAT(OX, confREFUSE_LA)
274
275# work recipient factor
276ifdef(`confWORK_RECIPIENT_FACTOR',
277	CONCAT(Oy, confWORK_RECIPIENT_FACTOR),
278	#Oy30000)
279
280# deliver each queued job in a separate process?
281CONCAT(OY, confSEPARATE_PROC)
282
283# work class factor
284ifdef(`confWORK_CLASS_FACTOR',
285	CONCAT(Oz, confWORK_CLASS_FACTOR),
286	#Oz1800)
287
288# work time factor
289ifdef(`confWORK_TIME_FACTOR',
290	CONCAT(OZ, confWORK_TIME_FACTOR),
291	#OZ90000)
292
293###########################
294#   Message precedences   #
295###########################
296
297Pfirst-class=0
298Pspecial-delivery=100
299Plist=-30
300Pbulk=-60
301Pjunk=-100
302
303#####################
304#   Trusted users   #
305#####################
306
307Troot
308Tdaemon
309Tuucp
310
311#########################
312#   Format of headers   #
313#########################
314
315H?P?Return-Path: $g
316HReceived: $?sfrom $s $.$?_($_) $.by $j ($v/$Z)$?r with $r$. id $i; $b
317H?D?Resent-Date: $a
318H?D?Date: $a
319H?F?Resent-From: $q
320H?F?From: $q
321H?x?Full-Name: $x
322HSubject:
323# HPosted-Date: $a
324# H?l?Received-Date: $b
325H?M?Resent-Message-Id: <$t.$i@$j>
326H?M?Message-Id: <$t.$i@$j>
327#
328######################################################################
329######################################################################
330#####
331#####			REWRITING RULES
332#####
333######################################################################
334######################################################################
335
336undivert(9)dnl
337
338###########################################
339###  Rulset 3 -- Name Canonicalization  ###
340###########################################
341S3
342
343# handle null input and list syntax (translate to <@> special case)
344R$@			$@ <@>
345R$*:;$*			$@ $1 :; <@>
346
347# basic textual canonicalization -- note RFC733 heuristic here
348R$*<$*>$*<$*>$*		<$2>$3$4$5			strip multiple <> <>
349R$*<$*<$+>$*>$*		<$3>$5				2-level <> nesting
350R$*<>$*			$@ <@>				MAIL FROM:<> case
351R$*<$+>$*		$2				basic RFC821/822 parsing
352
353# make sure <@a,@b,@c:user@d> syntax is easy to parse -- undone later
354R@ $+ , $+		@ $1 : $2			change all "," to ":"
355
356# localize and dispose of route-based addresses
357R@ $+ : $+		$@ $>_SET_96_ < @$1 > : $2		handle <route-addr>
358
359# find focus for list syntax
360R $+ : $* ; @ $+	$@ $>_SET_96_ $1 : $2 ; < @ $3 >	list syntax
361R $+ : $* ;		$@ $1 : $2;			list syntax
362
363# find focus for @ syntax addresses
364R$+ @ $+		$: $1 < @ $2 >			focus on domain
365R$+ < $+ @ $+ >		$1 $2 < @ $3 >			move gaze right
366R$+ < @ $+ >		$@ $>_SET_96_ $1 < @ $2 >		already canonical
367
368ifdef(`_NO_UUCP_', `dnl',
369`# convert old-style addresses to a domain-based address
370R$- ! $+		$@ $>_SET_96_ $2 < @ $1 .UUCP >	resolve uucp names
371R$+ . $- ! $+		$@ $>_SET_96_ $3 < @ $1 . $2 >		domain uucps
372R$+ ! $+		$@ $>_SET_96_ $2 < @ $1 .UUCP >	uucp subdomains')
373
374# if we have % signs, take the rightmost one
375R$* % $*		$1 @ $2				First make them all @s.
376R$* @ $* @ $*		$1 % $2 @ $3			Undo all but the last.
377R$* @ $*		$@ $>_SET_96_ $1 < @ $2 >		Insert < > and finish
378
379# else we must be a local name
380
381
382################################################
383###  Ruleset _SET_96_ -- bottom half of ruleset 3  ###
384################################################
385
386#  At this point, everything should be in a "local_part<@domain>extra" format.
387S`'_SET_96_
388
389# handle special cases for local names
390R$* < @ localhost > $*		$: $1 < @ $j . > $2		no domain at all
391R$* < @ localhost . $m > $*	$: $1 < @ $j . > $2		local domain
392ifdef(`_NO_UUCP_', `dnl',
393`R$* < @ localhost . UUCP > $*	$: $1 < @ $j . > $2		.UUCP domain')
394undivert(2)dnl
395
396ifdef(`_NO_UUCP_', `dnl',
397`ifdef(`UUCP_RELAY',
398`# pass UUCP addresses straight through
399R$* < @ $+ . UUCP > $*		$@ $1 < @ $2 . UUCP > $3',
400`# if really UUCP, handle it immediately
401ifdef(`_CLASS_U_',
402`R$* < @ $=U . UUCP > $*	$@ $1 < @ $2 . UUCP > $3', `dnl')
403ifdef(`_CLASS_V_',
404`R$* < @ $=V . UUCP > $*	$@ $1 < @ $2 . UUCP > $3', `dnl')
405ifdef(`_CLASS_W_',
406`R$* < @ $=W . UUCP > $*	$@ $1 < @ $2 . UUCP > $3', `dnl')
407ifdef(`_CLASS_X_',
408`R$* < @ $=X . UUCP > $*	$@ $1 < @ $2 . UUCP > $3', `dnl')
409ifdef(`_CLASS_Y_',
410`R$* < @ $=Y . UUCP > $*	$@ $1 < @ $2 . UUCP > $3', `dnl')
411
412# try UUCP traffic as a local address
413R$* < @ $+ . UUCP > $*		$: $1 < @ $[ $2 $] . UUCP > $3
414ifdef(`_OLD_SENDMAIL_',
415`R$* < @ $+ . $+ . UUCP > $*		$@ $1 < @ $2 . $3 . > $4',
416`R$* < @ $+ . . UUCP > $*		$@ $1 < @ $2 . > $3')')
417')
418ifdef(`_NO_CANONIFY_',
419`# make sure local host names appear canonical
420R$* < @ $=w > $*		$: $1 < @ $2 . > $3',
421`# pass to name server to make hostname canonical
422R$* < @ $* $~P > $*		$: $1 < @ $[ $2 $3 $] > $4')
423
424undivert(8)dnl
425
426# if this is the local hostname, make sure we treat is as canonical
427R$* < @ $j > $*			$: $1 < @ $j . > $2
428
429
430##################################################
431###  Ruleset 4 -- Final Output Post-rewriting  ###
432##################################################
433S4
434
435R$*<@>			$@ $1				handle <> and list:;
436
437# resolve numeric addresses to name if possible
438R$* < @ [ $+ ] > $*	$: $1 < @ $[ [$2] $] > $3	lookup numeric internet addr
439
440# strip trailing dot off possibly canonical name
441R$* < @ $+ . > $*	$1 < @ $2 > $3
442
443# externalize local domain info
444R$* < $+ > $*		$1 $2 $3			defocus
445R@ $+ : @ $+ : $+	@ $1 , @ $2 : $3		<route-addr> canonical
446R@ $*			$@ @ $1				... and exit
447
448ifdef(`_NO_UUCP_', `dnl',
449`# UUCP must always be presented in old form
450R$+ @ $- . UUCP		$2!$1				u@h.UUCP => h!u')
451
452# delete duplicate local names
453R$+ % $=w @ $=w		$1 @ $j				u%host@host => u@host
454
455
456
457##############################################################
458###   Ruleset _SET_97_ -- recanonicalize and call ruleset zero   ###
459###		   (used for recursive calls)		   ###
460##############################################################
461
462S`'_SET_97_
463R$*			$: $>3 $1
464R$*			$@ $>0 $1
465
466
467######################################
468###   Ruleset 0 -- Parse Address   ###
469######################################
470
471S0
472
473R<@>			$#local $: <>			special case error msgs
474R$*:;<@>		$#error $@ USAGE $: "list:; syntax illegal for recipient addresses"
475
476ifdef(`_MAILER_smtp_',
477`# handle numeric address spec
478R$* < @ [ $+ ] > $*	$: $1 < @ $[ [$2] $] > $3	numeric internet addr
479R$* < @ [ $+ ] > $*	$#smtp $@ [$2] $: $1 @ [$2] $3	numeric internet spec',
480`dnl')
481
482# now delete the local info -- note $=O to find characters that cause forwarding
483R$* < @ > $*		$@ $>_SET_97_ $1			user@ => user
484R< @ $=w . > : $*	$@ $>_SET_97_ $2			@here:... -> ...
485R$* $=O $* < @ $=w . >	$@ $>_SET_97_ $1 $2 $3			...@here -> ...
486ifdef(`MAILER_TABLE',
487`
488# try mailer table lookup
489R$* <@ $+ > $*		$: < $2 > $1 < @ $2 > $3	extract host name
490R< $+ . > $*		$: < $1 > $2			strip trailing dot
491R< $+ > $*		$: < $(mailertable $1 $) > $2	lookup
492R< $- : $+ > $*		$# $1 $@ $2 $: $3		check -- resolved?
493R< $+ > $*		$: $>90 <$1> $2			try domain',
494`dnl')
495
496# short circuit local delivery so forwarded email works
497ifdef(`_LOCAL_NOT_STICKY_',
498`R$=L < @ $=w . >		$#local $: @ $1			special local names
499R$+ < @ $=w . >		$#local $: $1			dispose directly',
500`R$+ < @ $=w . >		$: $1 < @ $2 @ $H >		first try hub
501ifdef(`_OLD_SENDMAIL_',
502`R$+ < $+ @ $-:$+ >	$# $3 $@ $4 $: $1 < $2 >	yep ....
503R$+ < $+ @ $+ >		$#relay $@ $3 $: $1 < $2 >	yep ....
504R$+ < $+ @ >		$#local $: $1			nope, local address',
505`R$+ < $+ @ $+ >		$#local $: $1			yep ....
506R$+ < $+ @ >		$#local $: @ $1			nope, local address')')
507undivert(3)dnl
508undivert(4)dnl
509
510ifdef(`_NO_UUCP_', `dnl',
511`# resolve remotely connected UUCP links (if any)
512ifdef(`_CLASS_V_',
513`R$* < @ $=V . UUCP > $*		$#smtp $@ $V $: <@ $V> : $1 @ $2.UUCP $3',
514	`dnl')
515ifdef(`_CLASS_W_',
516`R$* < @ $=W . UUCP > $*		$#smtp $@ $W $: <@ $W> : $1 @ $2.UUCP $3',
517	`dnl')
518ifdef(`_CLASS_X_',
519`R$* < @ $=X . UUCP > $*		$#smtp $@ $X $: <@ $X> : $1 @ $2.UUCP $3',
520	`dnl')')
521
522# resolve fake top level domains by forwarding to other hosts
523ifdef(`BITNET_RELAY',
524`R$*<@$+.BITNET>$*	$#smtp $@ $B $: $1 <@$2.BITNET> $3	user@host.BITNET',
525	`dnl')
526ifdef(`CSNET_RELAY',
527`R$*<@$+.CSNET>$*	$#smtp $@ $C $: $1 <@$2.CSNET> $3	user@host.CSNET',
528	`dnl')
529ifdef(`_MAILER_fax_',
530`R$+ < @ $+ .FAX >	$#fax $@ $2 $: $1			user@host.FAX',
531`ifdef(`FAX_RELAY',
532`R$*<@$+.FAX>$*		$#smtp $@ $F $: $1 <@$2.FAX> $3		user@host.FAX',
533	`dnl')')
534
535ifdef(`UUCP_RELAY',
536`# forward non-local UUCP traffic to our UUCP relay
537R$*<@$*.UUCP>$*		$#smtp $@ $Y $: <@ $Y> : $1 @ $2.UUCP $3	uucp mail',
538`ifdef(`_MAILER_uucp_',
539`# forward other UUCP traffic straight to UUCP
540R< @ $+ .UUCP > : $+	$#uucp $@ $1 $: $2			@host.UUCP:...
541R$+ < @ $+ .UUCP >	$#uucp $@ $2 $: $1			user@host.UUCP',
542	`dnl')')
543
544ifdef(`_LOCAL_RULES_',
545`# figure out what should stay in our local mail system
546undivert(1)',
547`ifdef(`_MAILER_smtp_',
548`# deal with other remote names
549R$* < @ $* > $*		$#smtp $@ $2 $: $1 < @ $2 > $3		user@host.domain')')
550ifdef(`SMART_HOST', `
551# pass names that still have a host to a smarthost
552R$* < @ $* > $*		$: < $S > $1 < @ $2 > $3	glue on smarthost name
553R<$-:$+> $* < @$* > $*	$# $1 $@ $2 $: $3 < @ $4 > $5	if non-null, use it
554R<$+> $* < @$* > $*	$#suucp $@ $1 $: $2 < @ $3 > $4	if non-null, use it
555R<> $* < @ $* > $*	$1 < @ $2 > $3			else strip off gunk',
556`ifdef(`_LOCAL_RULES_', `
557# reject messages that have host names we do not understand
558R$* < @ $* > $*		$#error $@ NOHOST $: Unrecognized host name $2',
559`dnl')')
560ifdef(`_MAILER_USENET_', `
561# addresses sent to net.group.USENET will get forwarded to a newsgroup
562R$+ . USENET		$# usenet $: $1')
563
564ifdef(`_OLD_SENDMAIL_',
565`# forward remaining names to local relay, if any
566R$=L			$#local $: $1			special local names
567R$+			$: $1 < @ $R >			append relay
568R$+ < @ >		$: $1 < @ $H >			no relay, try hub
569R$+ < @ >		$#local $: $1			no relay or hub: local
570R$+ < @ $=w  >		$#local $: $1			we are relay/hub: local
571R$+ < @ $-:$+ >		$# $2 $@ $3 $: $1		deliver to relay/hub
572R$+ < @ $+ >		$#relay $@ $2 $: $1		deliver to relay/hub',
573
574`# if this is quoted, strip the quotes and try again
575R$+			$: $(dequote $1 $)		strip quotes
576R$* $=O $*		$@ $>_SET_97_ $1 $2 $3			try again
577
578# handle locally delivered names
579R$=L			$#local $: @ $1			special local names
580R$+			$#local $: $1			regular local names
581
582###########################################################################
583###   Ruleset 5 -- special rewriting after aliases have been expanded   ###
584###		   (new sendmail only)					###
585###########################################################################
586
587S5
588
589# see if we have a relay or a hub
590R$+			$: $1 < @ $R >
591R$+ < @ >		$: $1 < @ $H >			no relay, try hub
592R$+ < @ $=w >		$@ $1				we are relay/hub: local
593R$+ < @ $-:$+ >		$# $2 $@ $3 $: $1		send to relay or hub
594ifdef(`_MAILER_smtp_',
595`R$+ < @ $+ >		$#relay $@ $2 $: $1		send to relay or hub')')
596ifdef(`MAILER_TABLE',
597`
598
599###########################################################################
600###  Ruleset 90 -- try domain part of mailertable entry 		###
601###		   (new sendmail only)					###
602###########################################################################
603
604S90
605R<$- . $+ > $*		$: < $(mailertable .$2 $) > $3	lookup
606R<$- : $+ > $*		$# $1 $@ $2 $: $3		check -- resolved?
607R< . $+ > $*		$@ $>90 <$1> $2			no -- strip & try again
608R<$*> $*		$@ $2				no match',
609`dnl')
610#
611######################################################################
612######################################################################
613#####
614`#####			MAILER DEFINITIONS'
615#####
616######################################################################
617######################################################################
618undivert(7)dnl
619