@> remark if leading colon R$* : $* <@> $: $2 strip colon if marked R$* <@> $: $1 unmark R$* ; $1 strip trailing semi R$* < $+ :; > $* $@ $2 :; <@> catch R$* < $* ; > $1 < $2 > bogus bracketed semi # null input now results from list:; syntax R$@ $@ :; <@> # strip angle brackets -- note RFC733 heuristic to get innermost item R$* $: < $1 > housekeeping <> R$+ < $* > < $2 > strip excess on left R< $* > $+ < $1 > strip excess on right R<> $@ < @ > MAIL FROM:<> case R< $+ > $: $1 remove housekeeping <> # strip route address <@a,@b,@c:user@d> -> R@ $+ , $+ $2 R@ [ $* ] : $+ $2 R@ $+ : $+ $2 # find focus for list syntax R $+ : $* ; @ $+ $@ $>Canonify2 $1 : $2 ; < @ $3 > list syntax R $+ : $* ; $@ $1 : $2; list syntax # find focus for @ syntax addresses R$+ @ $+ $: $1 < @ $2 > focus on domain R$+ < $+ @ $+ > $1 $2 < @ $3 > move gaze right R$+ < @ $+ > $@ $>Canonify2 $1 < @ $2 > already canonical # convert old-style addresses to a domain-based address R$- ! $+ $@ $>Canonify2 $2 < @ $1 .UUCP > resolve uucp names R$+ . $- ! $+ $@ $>Canonify2 $3 < @ $1 . $2 > domain uucps R$+ ! $+ $@ $>Canonify2 $2 < @ $1 .UUCP > uucp subdomains # if we have % signs, take the rightmost one R$* % $* $1 @ $2 First make them all @s. R$* @ $* @ $* $1 % $2 @ $3 Undo all but the last. R$* @ $* $@ $>Canonify2 $1 < @ $2 > Insert < > and finish # else we must be a local name R$* $@ $>Canonify2 $1 ################################################ ### Ruleset 96 -- bottom half of ruleset 3 ### ################################################ SCanonify2=96 # handle special cases for local names R$* < @ localhost > $* $: $1 < @ $j . > $2 no domain at all R$* < @ localhost . $m > $* $: $1 < @ $j . > $2 local domain R$* < @ localhost . UUCP > $* $: $1 < @ $j . > $2 .UUCP domain # check for IPv4/IPv6 domain literal R$* < @ [ $+ ] > $* $: $1 < @@ [ $2 ] > $3 mark [addr] R$* < @@ $=w > $* $: $1 < @ $j . > $3 self-literal R$* < @@ $+ > $* $@ $1 < @ $2 > $3 canon IP addr # if really UUCP, handle it immediately # try UUCP traffic as a local address R$* < @ $+ . UUCP > $* $: $1 < @ $[ $2 $] . UUCP . > $3 R$* < @ $+ . . UUCP . > $* $@ $1 < @ $2 . > $3 # hostnames ending in class P are always canonical R$* < @ $* $=P > $* $: $1 < @ $2 $3 . > $4 R$* < @ $* $~P > $* $: $&{daemon_flags} $| $1 < @ $2 $3 > $4 R$* CC $* $| $* < @ $+.$+ > $* $: $3 < @ $4.$5 . > $6 R$* CC $* $| $* $: $3 # pass to name server to make hostname canonical R$* $| $* < @ $* > $* $: $2 < @ $[ $3 $] > $4 R$* $| $* $: $2 # local host aliases and pseudo-domains are always canonical R$* < @ $=w > $* $: $1 < @ $2 . > $3 R$* < @ $=M > $* $: $1 < @ $2 . > $3 R$* < @ $* . . > $* $1 < @ $2 . > $3 ################################################## ### Ruleset 4 -- Final Output Post-rewriting ### ################################################## Sfinal=4 R$+ :; <@> $@ $1 : handle R$* <@> $@ handle <> and list:; # strip trailing dot off possibly canonical name R$* < @ $+ . > $* $1 < @ $2 > $3 # eliminate internal code R$* < @ *LOCAL* > $* $1 < @ $j > $2 # externalize local domain info R$* < $+ > $* $1 $2 $3 defocus R@ $+ : @ $+ : $+ @ $1 , @ $2 : $3 canonical R@ $* $@ @ $1 ... and exit # UUCP must always be presented in old form R$+ @ $- . UUCP $2!$1 u@h.UUCP => h!u # delete duplicate local names R$+ % $=w @ $=w $1 @ $2 u%host@host => u@host ############################################################## ### Ruleset 97 -- recanonicalize and call ruleset zero ### ### (used for recursive calls) ### ############################################################## SRecurse=97 R$* $: $>canonify $1 R$* $@ $>parse $1 ###################################### ### Ruleset 0 -- Parse Address ### ###################################### Sparse=0 R$* $: $>Parse0 $1 initial parsing R<@> $#local $: <@> special case error msgs R$* $: $>ParseLocal $1 handle local hacks R$* $: $>Parse1 $1 final parsing # # Parse0 -- do initial syntax checking and eliminate local addresses. # This should either return with the (possibly modified) input # or return with a #error mailer. It should not return with a # #mailer other than the #error mailer. # SParse0 R<@> $@ <@> special case error msgs R$* : $* ; <@> $#error $@ 5.1.3 $: "553 List:; syntax illegal for recipient addresses" R@ <@ $* > < @ $1 > catch "@@host" bogosity R<@ $+> $#error $@ 5.1.3 $: "553 User address required" R$+ <@> $#error $@ 5.1.3 $: "553 Hostname required" R$* $: <> $1 R<> $* < @ [ $* ] : $+ > $* $1 < @ [ $2 ] : $3 > $4 R<> $* < @ [ $* ] , $+ > $* $1 < @ [ $2 ] , $3 > $4 R<> $* < @ [ $* ] $+ > $* $#error $@ 5.1.2 $: "553 Invalid address" R<> $* < @ [ $+ ] > $* $1 < @ [ $2 ] > $3 R<> $* <$* : $* > $* $#error $@ 5.1.3 $: "553 Colon illegal in host name part" R<> $* $1 R$* < @ . $* > $* $#error $@ 5.1.2 $: "553 Invalid host name" R$* < @ $* .. $* > $* $#error $@ 5.1.2 $: "553 Invalid host name" R$* < @ $* @ > $* $#error $@ 5.1.2 $: "553 Invalid route address" R$* @ $* < @ $* > $* $#error $@ 5.1.3 $: "553 Invalid route address" R$* , $~O $* $#error $@ 5.1.3 $: "553 Invalid route address" # now delete the local info -- note $=O to find characters that cause forwarding R$* < @ > $* $@ $>Parse0 $>canonify $1 user@ => user R< @ $=w . > : $* $@ $>Parse0 $>canonify $2 @here:... -> ... R$- < @ $=w . > $: $(dequote $1 $) < @ $2 . > dequote "foo"@here R< @ $+ > $#error $@ 5.1.3 $: "553 User address required" R$* $=O $* < @ $=w . > $@ $>Parse0 $>canonify $1 $2 $3 ...@here -> ... R$- $: $(dequote $1 $) < @ *LOCAL* > dequote "foo" R< @ *LOCAL* > $#error $@ 5.1.3 $: "553 User address required" R$* $=O $* < @ *LOCAL* > $@ $>Parse0 $>canonify $1 $2 $3 ...@*LOCAL* -> ... R$* < @ *LOCAL* > $: $1 # # Parse1 -- the bottom half of ruleset 0. # SParse1 # handle numeric address spec R$* < @ [ $+ ] > $* $: $>ParseLocal $1 < @ [ $2 ] > $3 numeric internet spec R$* < @ [ $+ ] > $* $: $1 < @ [ $2 ] : $S > $3 Add smart host to path R$* < @ [ $+ ] : > $* $#esmtp $@ [$2] $: $1 < @ [$2] > $3 no smarthost: send R$* < @ [ $+ ] : $- : $*> $* $#$3 $@ $4 $: $1 < @ [$2] > $5 smarthost with mailer R$* < @ [ $+ ] : $+ > $* $#esmtp $@ $3 $: $1 < @ [$2] > $4 smarthost without mailer # short circuit local delivery so forwarded email works R$=L < @ $=w . > $#local $: @ $1 special local names R$+ < @ $=w . > $#local $: $1 regular local name # resolve remotely connected UUCP links (if any) # resolve fake top level domains by forwarding to other hosts # pass names that still have a host to a smarthost (if defined) R$* < @ $* > $* $: $>MailerToTriple < $S > $1 < @ $2 > $3 glue on smarthost name # deal with other remote names R$* < @$* > $* $#esmtp $@ $2 $: $1 < @ $2 > $3 user@host.domain # handle locally delivered names R$=L $#local $: @ $1 special local names R$+ $#local $: $1 regular local names ########################################################################### ### Ruleset 5 -- special rewriting after aliases have been expanded ### ########################################################################### SLocal_localaddr Slocaladdr=5 R$+ $: $1 $| $>"Local_localaddr" $1 R$+ $| $#ok $@ $1 no change R$+ $| $#$* $#$2 R$+ $| $* $: $1 # deal with plussed users so aliases work nicely R$+ + * $#local $@ $&h $: $1 R$+ + $* $#local $@ + $2 $: $1 + * # prepend an empty "forward host" on the front R$+ $: <> $1 R< > $+ $: < > < $1 <> $&h > nope, restore +detail R< > < $+ <> + $* > $: < > < $1 + $2 > check whether +detail R< > < $+ <> $* > $: < > < $1 > else discard R< > < $+ + $* > $* < > < $1 > + $2 $3 find the user part R< > < $+ > + $* $#local $@ $2 $: @ $1 strip the extra + R< > < $+ > $@ $1 no +detail R$+ $: $1 <> $&h add +detail back in R$+ <> + $* $: $1 + $2 check whether +detail R$+ <> $* $: $1 else discard R< local : $* > $* $: $>MailerToTriple < local : $1 > $2 no host extension R< error : $* > $* $: $>MailerToTriple < error : $1 > $2 no host extension R< $~[ : $+ > $+ $: $>MailerToTriple < $1 : $2 > $3 < @ $2 > R< $+ > $+ $@ $>MailerToTriple < $1 > $2 < @ $1 > ################################################################### ### Ruleset 95 -- canonify mailer:[user@]host syntax to triple ### ################################################################### SMailerToTriple=95 R< > $* $@ $1 strip off null relay R< error : $-.$-.$- : $+ > $* $#error $@ $1.$2.$3 $: $4 R< error : $- : $+ > $* $#error $@ $(dequote $1 $) $: $2 R< error : $+ > $* $#error $: $1 R< local : $* > $* $>CanonLocal < $1 > $2 R< $~[ : $+ @ $+ > $*<$*>$* $# $1 $@ $3 $: $2<@$3> use literal user R< $~[ : $+ > $* $# $1 $@ $2 $: $3 try qualified mailer R< $=w > $* $@ $2 delete local host R< $+ > $* $#relay $@ $1 $: $2 use unqualified mailer ################################################################### ### Ruleset CanonLocal -- canonify local: syntax ### ################################################################### SCanonLocal # strip local host from routed addresses R< $* > < @ $+ > : $+ $@ $>Recurse $3 R< $* > $+ $=O $+ < @ $+ > $@ $>Recurse $2 $3 $4 # strip trailing dot from any host name that may appear R< $* > $* < @ $* . > $: < $1 > $2 < @ $3 > # handle local: syntax -- use old user, either with or without host R< > $* < @ $* > $* $#local $@ $1@$2 $: $1 R< > $+ $#local $@ $1 $: $1 # handle local:user@host syntax -- ignore host part R< $+ @ $+ > $* < @ $* > $: < $1 > $3 < @ $4 > # handle local:user syntax R< $+ > $* <@ $* > $* $#local $@ $2@$3 $: $1 R< $+ > $* $#local $@ $2 $: $1 ################################################################### ### Ruleset 93 -- convert header names to masqueraded form ### ################################################################### SMasqHdr=93 # do not masquerade anything in class N R$* < @ $* $=N . > $@ $1 < @ $2 $3 . > R$* < @ *LOCAL* > $@ $1 < @ $j . > ################################################################### ### Ruleset 94 -- convert envelope names to masqueraded form ### ################################################################### SMasqEnv=94 R$* < @ *LOCAL* > $* $: $1 < @ $j . > $2 ################################################################### ### Ruleset 98 -- local part of ruleset zero (can be null) ### ################################################################### SParseLocal=98 ###################################################################### ### D: LookUpDomain -- search for domain in access database ### ### Parameters: ### <$1> -- key (domain name) ### <$2> -- default (what to return if not found in db) ### <$3> -- mark (must be <(!|+) single-token>) ### ! does lookup only with tag ### + does lookup with and without tag ### <$4> -- passthru (additional data passed unchanged through) ###################################################################### SD R<$*> <$+> <$- $-> <$*> $: < $(access $4:$1 $: ? $) > <$1> <$2> <$3 $4> <$5> R <$+> <$+> <+ $-> <$*> $: < $(access $1 $: ? $) > <$1> <$2> <+ $3> <$4> R <$+> <$+> <$- $-> <$*> $@ <$2> <$5> R <[$+.$-]> <$+> <$- $-> <$*> $@ $>D <[$1]> <$3> <$4 $5> <$6> R <[$+::$-]> <$+> <$- $-> <$*> $: $>D <[$1]> <$3> <$4 $5> <$6> R <[$+:$-]> <$+> <$- $-> <$*> $: $>D <[$1]> <$3> <$4 $5> <$6> R <$+.$+> <$+> <$- $-> <$*> $@ $>D <$2> <$3> <$4 $5> <$6> R <$+> <$+> <$- $-> <$*> $@ <$2> <$5> R<$* > <$+> <$+> <$- $-> <$*> $@ <> <$6> R<$*> <$+> <$+> <$- $-> <$*> $@ <$1> <$6> ###################################################################### ### A: LookUpAddress -- search for host address in access database ### ### Parameters: ### <$1> -- key (dot quadded host address) ### <$2> -- default (what to return if not found in db) ### <$3> -- mark (must be <(!|+) single-token>) ### ! does lookup only with tag ### + does lookup with and without tag ### <$4> -- passthru (additional data passed through) ###################################################################### SA R<$+> <$+> <$- $-> <$*> $: < $(access $4:$1 $: ? $) > <$1> <$2> <$3 $4> <$5> R <$+> <$+> <+ $-> <$*> $: < $(access $1 $: ? $) > <$1> <$2> <+ $3> <$4> R <$+> <$+> <$- $-> <$*> $@ <$2> <$5> R <$+::$-> <$+> <$- $-> <$*> $@ $>A <$1> <$3> <$4 $5> <$6> R <$+:$-> <$+> <$- $-> <$*> $@ $>A <$1> <$3> <$4 $5> <$6> R <$+.$-> <$+> <$- $-> <$*> $@ $>A <$1> <$3> <$4 $5> <$6> R <$+> <$+> <$- $-> <$*> $@ <$2> <$5> R<$* > <$+> <$+> <$- $-> <$*> $@ <> <$6> R<$*> <$+> <$+> <$- $-> <$*> $@ <$1> <$6> ###################################################################### ### CanonAddr -- Convert an address into a standard form for ### relay checking. Route address syntax is ### crudely converted into a %-hack address. ### ### Parameters: ### $1 -- full recipient address ### ### Returns: ### parsed address, not in source route form ###################################################################### SCanonAddr R$* $: $>Parse0 $>canonify $1 make domain canonical ###################################################################### ### ParseRecipient -- Strip off hosts in $=R as well as possibly ### $* $=m or the access database. ### Check user portion for host separators. ### ### Parameters: ### $1 -- full recipient address ### ### Returns: ### parsed, non-local-relaying address ###################################################################### SParseRecipient R$* $: $>CanonAddr $1 R $* < @ $* . > $1 < @ $2 > strip trailing dots R $- < @ $* > $: $(dequote $1 $) < @ $2 > dequote local part # if no $=O character, no host in the user portion, we are done R $* $=O $* < @ $* > $: $1 $2 $3 < @ $4> R $* $@ $1 R $* < @ $* $=R > $: $1 < @ $2 $3 > R $* < @ $+ > $: $>D <$2> <+ To> <$1 < @ $2 >> R<$+> <$+> $: <$1> $2 R $* < @ $* > $@ $>ParseRecipient $1 R<$+> $* $@ $2 ###################################################################### ### check_relay -- check hostname/address on SMTP startup ###################################################################### Scheck_relay R$* $: $>"RateControl" dummy R$* $: $>"ConnControl" dummy SLocal_check_relay Scheckrelay R$* $: $1 $| $>"Local_check_relay" $1 R$* $| $* $| $#$* $#$3 R$* $| $* $| $* $@ $>"Basic_check_relay" $1 $| $2 SBasic_check_relay # check for deferred delivery mode R$* $: < $&{deliveryMode} > $1 R< d > $* $@ deferred R< $* > $* $: $2 R$+ $| $+ $: $>D < $1 > <+ Connect> < $2 > R $| $+ $: $>A < $1 > <+ Connect> <> empty client_name R <$+> $: $>A < $1 > <+ Connect> <> no: another lookup R <$*> $: OK found nothing R<$={Accept}> <$*> $@ $1 return value of lookup R <$*> $#error $@ 5.7.1 $: "550 Access denied" R <$*> $#discard $: discard R <$*> $#error $@ quarantine $: $1 R <$*> $#error $@ $1.$2.$3 $: $4 R <$*> $#error $: $1 R<$* > <$*> $#error $@ 4.3.0 $: "451 Temporary system failure. Please try again later." R<$+> <$*> $#error $: $1 ###################################################################### ### check_mail -- check SMTP `MAIL FROM:' command argument ###################################################################### SLocal_check_mail Scheckmail R$* $: $1 $| $>"Local_check_mail" $1 R$* $| $#$* $#$2 R$* $| $* $@ $>"Basic_check_mail" $1 SBasic_check_mail # check for deferred delivery mode R$* $: < $&{deliveryMode} > $1 R< d > $* $@ deferred R< $* > $* $: $2 # authenticated? R$* $: $1 $| $>"tls_client" $&{verify} $| MAIL R$* $| $#$+ $#$2 R$* $| $* $: $1 R<> $@ we MUST accept <> (RFC 1123) R$+ $: $1 R<$+> $: <@> <$1> R$+ $: <@> <$1> R$* $: $&{daemon_flags} $| $1 R$* f $* $| <@> < $* @ $- > $: < ? $&{client_name} > < $3 @ $4 > R$* u $* $| <@> < $* > $: < $3 > R$* $| $* $: $2 # handle case of @localhost on address R<@> < $* @ localhost > $: < ? $&{client_name} > < $1 @ localhost > R<@> < $* @ [127.0.0.1] > $: < ? $&{client_name} > < $1 @ [127.0.0.1] > R<@> < $* @ [IPv6:0:0:0:0:0:0:0:1] > $: < ? $&{client_name} > < $1 @ [IPv6:0:0:0:0:0:0:0:1] > R<@> < $* @ [IPv6:::1] > $: < ? $&{client_name} > < $1 @ [IPv6:::1] > R<@> < $* @ localhost.$m > $: < ? $&{client_name} > < $1 @ localhost.$m > R<@> < $* @ localhost.UUCP > $: < ? $&{client_name} > < $1 @ localhost.UUCP > R<@> $* $: $1 no localhost as domain R $* $: $2 local client: ok R <$+> $#error $@ 5.5.4 $: "553 Real domain name required for sender address" R $* $: $1 R$* $: $>CanonAddr $1 canonify sender address and mark it R $* < @ $+ . > $1 < @ $2 > strip trailing dots # handle non-DNS hostnames (*.bitnet, *.decnet, *.uucp, etc) R $* < @ $* $=P > $: $1 < @ $2 $3 > R $* < @ $j > $: $1 < @ $j > R $* < @ $+ > $: $) > $1 < @ $2 > R> $* < @ $+ > $: <$2> $3 < @ $4 > # check sender address: user@address, user@, address R<$+> $+ < @ $* > $: @<$1> <$2 < @ $3 >> $| R<$+> $+ $: @<$1> <$2> $| R@ <$+> <$*> $| <$+> $: <@> <$1> <$2> $| $>SearchList <+ From> $| <$3> <> R<@> <$+> <$*> $| <$*> $: <$3> <$1> <$2> reverse result # retransform for further use R <$+> <$*> $: <$1> $2 no match R<$+> <$+> <$*> $: <$1> $3 relevant result, keep it # handle case of no @domain on address R $* $: $&{daemon_flags} $| $1 R$* u $* $| $* $: $3 R$* $| $* $: $2 R $* $: < ? $&{client_addr} > $1 R $* $@ ...local unqualed ok R $* $#error $@ 5.5.4 $: "553 Domain name required for sender address " $&f ...remote is not # check results R $* $: @ $1 mark address: nothing known about it R<$={ResOk}> $* $: @ $2 domain ok R $* $#error $@ 4.1.8 $: "451 Domain of sender address " $&f " does not resolve" R $* $#error $@ 5.1.8 $: "553 Domain of sender address " $&f " does not exist" R<$={Accept}> $* $# $1 accept from access map R $* $#discard $: discard R $* $#error $@ quarantine $: $1 R $* $#error $@ 5.7.1 $: "550 Access denied" R $* $#error $@ $1.$2.$3 $: $4 R $* $#error $: $1 R<> $* $#error $@ 4.3.0 $: "451 Temporary system failure. Please try again later." R<$+> $* $#error $: $1 error from access db ###################################################################### ### check_rcpt -- check SMTP `RCPT TO:' command argument ###################################################################### SLocal_check_rcpt Scheckrcpt R$* $: $1 $| $>"Local_check_rcpt" $1 R$* $| $#$* $#$2 R$* $| $* $@ $>"Basic_check_rcpt" $1 SBasic_check_rcpt # empty address? R<> $#error $@ nouser $: "553 User address required" R$@ $#error $@ nouser $: "553 User address required" # check for deferred delivery mode R$* $: < $&{deliveryMode} > $1 R< d > $* $@ deferred R< $* > $* $: $2 ###################################################################### R$* $: $1 $| @ $>"Rcpt_ok" $1 R$* $| @ $#TEMP $+ $: $1 $| T $2 R$* $| @ $#$* $#$2 R$* $| @ RELAY $@ RELAY R$* $| @ $* $: O $| $>"Relay_ok" $1 R$* $| T $+ $: T $2 $| $>"Relay_ok" $1 R$* $| $#TEMP $+ $#error $2 R$* $| $#$* $#$2 R$* $| RELAY $@ RELAY R T $+ $| $* $#error $1 # anything else is bogus R$* $#error $@ 5.7.1 $: "550 Relaying denied" ###################################################################### ### Rcpt_ok: is the recipient ok? ###################################################################### SRcpt_ok R$* $: $>ParseRecipient $1 strip relayable hosts # authenticated via TLS? R$* $: $1 $| $>RelayTLS client authenticated? R$* $| $# $+ $# $2 error/ok? R$* $| $* $: $1 no R$* $: $1 $| $>"Local_Relay_Auth" $&{auth_type} R$* $| $# $* $# $2 R$* $| NO $: $1 R$* $| $* $: $1 $| $&{auth_type} R$* $| $: $1 R$* $| $={TrustAuthMech} $# RELAY R$* $| $* $: $1 # anything terminating locally is ok R$+ < @ $=w > $@ RELAY R$+ < @ $* $=R > $@ RELAY R$+ < @ $+ > $: $>D <$2> <+ To> <$1 < @ $2 >> R $* $@ RELAY R<$* > $* $#TEMP $@ 4.3.0 $: "451 Temporary system failure. Please try again later." R<$*> <$*> $: $2 # check for local user (i.e. unqualified address) R$* $: $1 R $* < @ $+ > $: $1 < @ $2 > # local user is ok R $+ $@ RELAY R<$+> $* $: $2 ###################################################################### ### Relay_ok: is the relay/sender ok? ###################################################################### SRelay_ok # anything originating locally is ok # check IP address R$* $: $&{client_addr} R$@ $@ RELAY originated locally R0 $@ RELAY originated locally R127.0.0.1 $@ RELAY originated locally RIPv6:0:0:0:0:0:0:0:1 $@ RELAY originated locally RIPv6:::1 $@ RELAY originated locally R$=R $* $@ RELAY relayable IP address R$* $: $>A <$1> <+ Connect> <$1> R $* $@ RELAY relayable IP address R<> $* $#TEMP $@ 4.3.0 $: "451 Temporary system failure. Please try again later." R<$*> <$*> $: $2 R$* $: [ $1 ] put brackets around it... R$=w $@ RELAY ... and see if it is local # check client name: first: did it resolve? R$* $: < $&{client_resolve} > R $#TEMP $@ 4.4.0 $: "450 Relaying temporarily denied. Cannot resolve PTR record for " $&{client_addr} R $#error $@ 5.7.1 $: "550 Relaying denied. IP name possibly forged " $&{client_name} R $#error $@ 5.7.1 $: "550 Relaying denied. IP name lookup failed " $&{client_name} R$* $: <@> $&{client_name} # pass to name server to make hostname canonical R<@> $* $=P $: $1 $2 R<@> $+ $: $[ $1 $] R$* . $1 strip trailing dots R $=w $@ RELAY R $* $=R $@ RELAY R $* $: $>D <$1> <+ Connect> <$1> R $* $@ RELAY R<$* > $* $#TEMP $@ 4.3.0 $: "451 Temporary system failure. Please try again later." R<$*> <$*> $: $2 # turn a canonical address in the form user<@domain> # qualify unqual. addresses with $j SFullAddr R$* <@ $+ . > $1 <@ $2 > R$* <@ $* > $@ $1 <@ $2 > R$+ $@ $1 <@ $j > SDelay_TLS_Clt # authenticated? R$* $: $1 $| $>"tls_client" $&{verify} $| MAIL R$* $| $#$+ $#$2 R$* $| $* $# $1 R$* $# $1 SDelay_TLS_Clt2 # authenticated? R$* $: $1 $| $>"tls_client" $&{verify} $| MAIL R$* $| $#$+ $#$2 R$* $| $* $@ $1 R$* $@ $1 # call all necessary rulesets Scheck_rcpt # R$@ $#error $@ 5.1.3 $: "553 Recipient address required" R$+ $: $1 $| $>checkrcpt $1 R$+ $| $#error $* $#error $2 R$+ $| $#discard $* $#discard $2 R$+ $| $#$* $@ $>"Delay_TLS_Clt" $2 R$+ $| $* $: $>FullAddr $>CanonAddr $1 R $+ < @ $=w > $: <> $1 < @ $2 > $| R $+ < @ $* > $: <> $1 < @ $2 > $| # lookup the addresses only with Spam tag R<> $* $| <$+> $: <@> $1 $| $>SearchList $| <$2> <> R<@> $* $| $* $: $2 $1 reverse result # is the recipient a spam friend? R $+ $@ $>"Delay_TLS_Clt2" SPAMFRIEND R<$*> $+ $: $2 R$* $: $1 $| $>checkmail $&{mail_from} R$* $| $#$* $#$2 R$* $| $* $: $1 $| $>checkrelay $&{client_name} $| $&{client_addr} R$* $| $#$* $#$2 R$* $| $* $: $1 ###################################################################### ### F: LookUpFull -- search for an entry in access database ### ### lookup of full key (which should be an address) and ### variations if +detail exists: +* and without +detail ### ### Parameters: ### <$1> -- key ### <$2> -- default (what to return if not found in db) ### <$3> -- mark (must be <(!|+) single-token>) ### ! does lookup only with tag ### + does lookup with and without tag ### <$4> -- passthru (additional data passed unchanged through) ###################################################################### SF R<$+> <$*> <$- $-> <$*> $: <$(access $4:$1 $: ? $)> <$1> <$2> <$3 $4> <$5> R <$+> <$*> <+ $-> <$*> $: <$(access $1 $: ? $)> <$1> <$2> <+ $3> <$4> R <$+ + $* @ $+> <$*> <$- $-> <$*> $: <$(access $6:$1+*@$3 $: ? $)> <$1+$2@$3> <$4> <$5 $6> <$7> R <$+ + $* @ $+> <$*> <+ $-> <$*> $: <$(access $1+*@$3 $: ? $)> <$1+$2@$3> <$4> <+ $5> <$6> R <$+ + $* @ $+> <$*> <$- $-> <$*> $: <$(access $6:$1@$3 $: ? $)> <$1+$2@$3> <$4> <$5 $6> <$7> R <$+ + $* @ $+> <$*> <+ $-> <$*> $: <$(access $1@$3 $: ? $)> <$1+$2@$3> <$4> <+ $5> <$6> R <$+> <$*> <$- $-> <$*> $@ <$2> <$5> R<$+ > <$*> <$- $-> <$*> $@ <> <$5> R<$+> <$*> <$- $-> <$*> $@ <$1> <$5> ###################################################################### ### E: LookUpExact -- search for an entry in access database ### ### Parameters: ### <$1> -- key ### <$2> -- default (what to return if not found in db) ### <$3> -- mark (must be <(!|+) single-token>) ### ! does lookup only with tag ### + does lookup with and without tag ### <$4> -- passthru (additional data passed unchanged through) ###################################################################### SE R<$*> <$*> <$- $-> <$*> $: <$(access $4:$1 $: ? $)> <$1> <$2> <$3 $4> <$5> R <$+> <$*> <+ $-> <$*> $: <$(access $1 $: ? $)> <$1> <$2> <+ $3> <$4> R <$+> <$*> <$- $-> <$*> $@ <$2> <$5> R<$+ > <$*> <$- $-> <$*> $@ <> <$5> R<$+> <$*> <$- $-> <$*> $@ <$1> <$5> ###################################################################### ### U: LookUpUser -- search for an entry in access database ### ### lookup of key (which should be a local part) and ### variations if +detail exists: +* and without +detail ### ### Parameters: ### <$1> -- key (user@) ### <$2> -- default (what to return if not found in db) ### <$3> -- mark (must be <(!|+) single-token>) ### ! does lookup only with tag ### + does lookup with and without tag ### <$4> -- passthru (additional data passed unchanged through) ###################################################################### SU R<$+> <$*> <$- $-> <$*> $: <$(access $4:$1 $: ? $)> <$1> <$2> <$3 $4> <$5> R <$+> <$*> <+ $-> <$*> $: <$(access $1 $: ? $)> <$1> <$2> <+ $3> <$4> R <$+ + $* @> <$*> <$- $-> <$*> $: <$(access $5:$1+*@ $: ? $)> <$1+$2@> <$3> <$4 $5> <$6> R <$+ + $* @> <$*> <+ $-> <$*> $: <$(access $1+*@ $: ? $)> <$1+$2@> <$3> <+ $4> <$5> R <$+ + $* @> <$*> <$- $-> <$*> $: <$(access $5:$1@ $: ? $)> <$1+$2@> <$3> <$4 $5> <$6> R <$+ + $* @> <$*> <+ $-> <$*> $: <$(access $1@ $: ? $)> <$1+$2@> <$3> <+ $4> <$5> R <$+> <$*> <$- $-> <$*> $@ <$2> <$5> R<$+ > <$*> <$- $-> <$*> $@ <> <$5> R<$+> <$*> <$- $-> <$*> $@ <$1> <$5> ###################################################################### ### SearchList: search a list of items in the access map ### Parameters: ### $| ... <> ### where "exact" is either "+" or "!": ### <+ TAG> lookup with and w/o tag ### lookup with tag ### possible values for "mark" are: ### D: recursive host lookup (LookUpDomain) ### E: exact lookup, no modifications ### F: full lookup, try user+ext@domain and user@domain ### U: user lookup, try user+ext and user (input must have trailing @) ### return: or (not found) ###################################################################### # class with valid marks for SearchList C{Src}E F D U A SSearchList # just call the ruleset with the name of the tag... nice trick... R<$+> $| <$={Src}:$*> <$*> $: <$1> $| <$4> $| $>$2 <$3> <$1> <> R<$+> $| <> $| <> $@ R<$+> $| <$+> $| <> $@ $>SearchList <$1> $| <$2> R<$+> $| <$*> $| <$+> <> $@ <$3> R<$+> $| <$+> $@ <$2> ###################################################################### ### trust_auth: is user trusted to authenticate as someone else? ### ### Parameters: ### $1: AUTH= parameter from MAIL command ###################################################################### SLocal_trust_auth Strust_auth R$* $: $&{auth_type} $| $1 # required by RFC 2554 section 4. R$@ $| $* $#error $@ 5.7.1 $: "550 not authenticated" R$* $| $&{auth_authen} $@ identical R$* $| <$&{auth_authen}> $@ identical R$* $| $* $: $1 $| $>"Local_trust_auth" $2 R$* $| $#$* $#$2 R$* $#error $@ 5.7.1 $: "550 " $&{auth_authen} " not allowed to act as " $&{auth_author} ###################################################################### ### Relay_Auth: allow relaying based on authentication? ### ### Parameters: ### $1: ${auth_type} ###################################################################### SLocal_Relay_Auth ###################################################################### ### srv_features: which features to offer to a client? ### (done in server) ###################################################################### Ssrv_features R$* $: $>D <$&{client_name}> <> R$* $: $>A <$&{client_addr}> <> R$* $: <$(access "Srv_Features": $: ? $)> R$* $@ OK R<$* >$* $#temp R<$+>$* $# $1 ###################################################################### ### try_tls: try to use STARTTLS? ### (done in client) ###################################################################### Stry_tls R$* $: $>D <$&{server_name}> <> R$* $: $>A <$&{server_addr}> <> R$* $: <$(access "Try_TLS": $: ? $)> R$* $@ OK R<$* >$* $#error $@ 4.3.0 $: "451 Temporary system failure. Please try again later." R$* $#error $@ 5.7.1 $: "550 do not try TLS with " $&{server_name} " ["$&{server_addr}"]" ###################################################################### ### tls_rcpt: is connection with server "good" enough? ### (done in client, per recipient) ### ### Parameters: ### $1: recipient ###################################################################### Stls_rcpt R$* $: $(macro {TLS_Name} $@ $&{server_name} $) $1 R$+ $: $>CanonAddr $1 R $+ < @ $+ . > $1 <@ $2 > R $+ < @ $+ > $: $1 <@ $2 > $| R $+ $: $1 $| R$* $| $+ $: $1 $| $>SearchList $| $2 <> R$* $| $@ OK R$* $| <$* > $#error $@ 4.3.0 $: "451 Temporary system failure. Please try again later." R$* $| <$+> $@ $>"TLS_connection" $&{verify} $| <$2> ###################################################################### ### tls_client: is connection with client "good" enough? ### (done in server) ### ### Parameters: ### ${verify} $| (MAIL|STARTTLS) ###################################################################### Stls_client R$* $: $(macro {TLS_Name} $@ $&{client_name} $) $1 R$* $| $* $: $1 $| $>D <$&{client_name}> <> R$* $| $* $: $1 $| $>A <$&{client_addr}> <> R$* $| $* $: $1 $| <$(access "TLS_Clt": $: ? $)> R$* $| <$* > $#error $@ 4.3.0 $: "451 Temporary system failure. Please try again later." R$* $@ $>"TLS_connection" $1 ###################################################################### ### tls_server: is connection with server "good" enough? ### (done in client) ### ### Parameter: ### ${verify} ###################################################################### Stls_server R$* $: $(macro {TLS_Name} $@ $&{server_name} $) $1 R$* $: $1 $| $>D <$&{server_name}> <> R$* $| $* $: $1 $| $>A <$&{server_addr}> <> R$* $| $* $: $1 $| <$(access "TLS_Srv": $: ? $)> R$* $| <$* > $#error $@ 4.3.0 $: "451 Temporary system failure. Please try again later." R$* $@ $>"TLS_connection" $1 ###################################################################### ### TLS_connection: is TLS connection "good" enough? ### ### Parameters: ### ${verify} $| [<>] ### Requirement: RHS from access map, may be ? for none. ###################################################################### STLS_connection R$* $| <$*>$* $: $1 $| <$2> # create the appropriate error codes R$* $| $: $1 $| <503:5.7.0> <$2 $3> R$* $| $: $1 $| <403:4.7.0> <$2 $3> R$* $| <$={Tls} $*> $: $1 $| <403:4.7.0> <$2 $3> # deal with TLS handshake failures: abort RSOFTWARE $| <$-:$+> $* $#error $@ $2 $: $1 " TLS handshake failed." RSOFTWARE $| $* $#error $@ 4.7.0 $: "403 TLS handshake failed." # deal with TLS protocol errors: abort RPROTOCOL $| <$-:$+> $* $#error $@ $2 $: $1 " STARTTLS failed." RPROTOCOL $| $* $#error $@ 4.7.0 $: "403 STARTTLS failed." R$* $| <$*> $: <$2> <> $1 R$* $| <$*> $: <$2> <$3> $1 R$* $| <$*> <$={Tls}:$->$* $: <$2> <$3:$4> <> $1 R$* $| <$*> <$={Tls}:$- + $+>$* $: <$2> <$3:$4> <$5> $1 R$* $| $* $@ OK # authentication required: give appropriate error # other side did authenticate (via STARTTLS) R<$*> <> OK $@ OK R<$*> <$+> OK $: <$1> <$2> R<$*> <$*> OK $: <$1> <$3> R<$*> <$*> $* $: <$1> <$3> R<$-:$+> <$*> $#error $@ $2 $: $1 " authentication required" R<$-:$+> <$*> FAIL $#error $@ $2 $: $1 " authentication failed" R<$-:$+> <$*> NO $#error $@ $2 $: $1 " not authenticated" R<$-:$+> <$*> NOT $#error $@ $2 $: $1 " no authentication requested" R<$-:$+> <$*> NONE $#error $@ $2 $: $1 " other side does not support STARTTLS" R<$-:$+> <$*> $+ $#error $@ $2 $: $1 " authentication failure " $4 R<$*> <$*> $: <$1> <$3> $>max $&{cipher_bits} : $&{auth_ssf} R<$*> <$*> $- $: <$1> <$2:$4> <$3> $(arith l $@ $4 $@ $2 $) R<$-:$+><$-:$-> <$*> TRUE $#error $@ $2 $: $1 " encryption too weak " $4 " less than " $3 R<$-:$+><$-:$-> <$*> $* $: <$1:$2 ++ $5> R<$-:$+ ++ > $@ OK R<$-:$+ ++ $+ > $: <$1:$2> <$3> R<$-:$+> < $+ ++ $+ > <$1:$2> <$3> <$4> R<$-:$+> $+ $@ $>"TLS_req" $3 $| <$1:$2> ###################################################################### ### TLS_req: check additional TLS requirements ### ### Parameters: [ ] $| <$-:$+> ### $-: SMTP reply code ### $+: Enhanced Status Code ###################################################################### STLS_req R $| $+ $@ OK R $* $| <$+> $: $1 $| <$2> R $* $| <$+> $@ $>"TLS_req" $1 $| <$2> R $* $| <$-:$+> $#error $@ $4 $: $3 " CN " $&{cn_subject} " does not match " $1 R $* $| <$+> $@ $>"TLS_req" $1 $| <$2> R $* $| <$-:$+> $#error $@ $4 $: $3 " Cert Subject " $&{cert_subject} " does not match " $1 R $* $| <$+> $@ $>"TLS_req" $1 $| <$2> R $* $| <$-:$+> $#error $@ $4 $: $3 " Cert Issuer " $&{cert_issuer} " does not match " $1 ROK $@ OK ###################################################################### ### max: return the maximum of two values separated by : ### ### Parameters: [$-]:[$-] ###################################################################### Smax R: $: 0 R:$- $: $1 R$-: $: $1 R$-:$- $: $(arith l $@ $1 $@ $2 $) : $1 : $2 RTRUE:$-:$- $: $2 R$-:$-:$- $: $2 ###################################################################### ### RelayTLS: allow relaying based on TLS authentication ### ### Parameters: ### none ###################################################################### SRelayTLS # authenticated? R$* $: $&{verify} R OK $: OK authenticated: continue R $* $@ NO not authenticated R$* $: $&{cert_issuer} R$+ $: $(access CERTISSUER:$1 $) RRELAY $# RELAY RSUBJECT $: <@> $&{cert_subject} R<@> $+ $: <@> $(access CERTSUBJECT:$1 $) R<@> RELAY $# RELAY R$* $: NO ###################################################################### ### authinfo: lookup authinfo in the access map ### ### Parameters: ### $1: {server_name} ### $2: {server_addr} ###################################################################### Sauthinfo R$* $: $1 $| $>D <$&{server_name}> <> R$* $| $* $: $1 $| $>A <$&{server_addr}> <> R$* $| $* $: $1 $| <$(access AuthInfo: $: ? $)> <> R$* $| $* $@ no no authinfo available R$* $| <$*> <> $# $2 ###################################################################### ### RateControl: ### Parameters: ignored ### return: $#error or OK ###################################################################### SRateControl R$* $: R$+ $: $>SearchList $| $1 <> R $@ OK R<$* > $#error $@ 4.3.0 $: "451 Temporary system failure. Please try again later." R<0> $@ OK no limit R<$+> $: <$1> $| $(arith l $@ $1 $@ $&{client_rate} $) R<$+> $| TRUE $#error $@ 4.3.2 $: 421 Connection rate limit exceeded. ###################################################################### ### ConnControl: ### Parameters: ignored ### return: $#error or OK ###################################################################### SConnControl R$* $: R$+ $: $>SearchList $| $1 <> R $@ OK R<$* > $#error $@ 4.3.0 $: "451 Temporary system failure. Please try again later." R<0> $@ OK no limit R<$+> $: <$1> $| $(arith l $@ $1 $@ $&{client_connections} $) R<$+> $| TRUE $#error $@ 4.3.2 $: 421 Too many open connections. ###################################################################### ### greet_pause: lookup pause time before 220 greeting ### ### Parameters: ### $1: {client_name} ### $2: {client_addr} ###################################################################### SLocal_greet_pause Sgreet_pause R$* $: <$1> $| $>"Local_greet_pause" $1 R<$*> $| $#$* $#$2 R<$*> $| $* $: $1 R$+ $| $+ $: $>D < $1 > < $2 > R $| $+ $: $>A < $1 > <> empty client_name R <$+> $: $>A < $1 > <> no: another lookup R <$*> $# 1000 R<$* > <$*> $@ R<$+> <$*> $# $1 #