jtv@kampi.hut.fi (Jukka Virtanen) (07/31/89)
Hello, Some time ago I modified my IDA patched sendmail 5.61 so that sendmail.cf rules can find out if a domain has an MX record. It can be used e.g. in ruleset 0 to find out if we can send the mail with smtp or if we need to do some other alternative approach. I defined new tokens ${ and $} to do MX lookup. They are used like the $[ NAME $: DEFAULT $] construct for hostname lookup. $: is an IDA enchancement for defaults in the lookups. # inside ruleset 0... # # Check if a domain has an MX record, and if so, send mail to the # domain the MX record points to with the original address as recipient # R$+<@$+> $: $1<@$2> ? ${ $2 $: $} Does domain have an MX? R$+<@$+>? $1<@$2> Nothing found, strip ? R$+<@$+>?$+ $#ether $@ $3 $: $1<@$2> Yes, send it with smtp # # otherwise do something else # If there is general interest, I might send diffs somewhere. Juki jtv@hut.fi -- *---------------------------------------------------------------------------* jtv@hut.fi Jukka Virtanen jtv@santra.UUCP (mcvax!santra!jtv) Helsinki University of Technology jtv@fingate.bitnet Computing Centre SF-02150, Espoo, FINLAND tel. +358 0 4514315
kre@cs.mu.oz.au (Robert Elz) (08/03/89)
In article <JTV.89Jul31122531@kampi.hut.fi>, jtv@kampi.hut.fi (Jukka Virtanen) writes: > Some time ago I modified my IDA patched sendmail 5.61 so that > sendmail.cf rules can find out if a domain has an MX record. I have done just the same thing, and (probably not remarkably) ... > I defined new tokens ${ and $} to do MX lookup. they were what I used too. Similarly ... > They are used like the $[ NAME $: DEFAULT $] construct for hostname > lookup. $: is an IDA enchancement for defaults in the lookups. except that $: is overloaded here by the IDA mods, which (related to other changes I've been making) wasn't a great idea, in fact, it was a down right bad idea, so I changed that to $/ However ... > > # inside ruleset 0... > # > # Check if a domain has an MX record, and if so, send mail to the > # domain the MX record points to with the original address as recipient > # > R$+<@$+> $: $1<@$2> ? ${ $2 $: $} Does domain have an MX? > R$+<@$+>? $1<@$2> Nothing found, strip ? > R$+<@$+>?$+ $#ether $@ $3 $: $1<@$2> Yes, send it with smtp This is positively wrong. The "ether" mailer will use the [IPC] mechanism, and that looks up the MX record for the host it is targetted at. That violates the spec for MX's, which prohibits recursive lookups (once you get the host name from an MX lookup, you're supposed to go directly to that host, regardless of where its MX may be pointed - in particular, this allows 2 hosts to swap mail). To handle this, I added a new mailer flag (meaningful only with [IPC] mailers) which means 'send it directly at this host', avoiding any more MX lookups. You have one [IPC] mailer for the cases where you have already done the MX lookup (which has the flag set) and another for other SMTP mail (without the flag). However, while this is legal, it turns out that its not all that great an idea either, as the ${ $} stuff can only ever return a single MX result .. if that host is down the mail will just be queued, rather than being sent off to another of the possible MX destinations. A better way to write the rules then becomes ... R$+<@$+> $: $1<@$2> ? ${ $2 $: $} Does domain have an MX? R$+<@$+>? $1<@$2> Nothing found, strip ? R$+<@$+>?$w $1<@$2> We're the MX - strip it R$+<@$+>?$+ $#ether $@ $2 $: $1<@$2> Yes, send it with smtp This has two enhancements ... first it discovers if the local host is the intended MX destination (which is what I really wanted the ability to do MX lookups in the rulesets for anyway - the usual kludge of building in known local domains just won't work reasonably in this environment), and then if an MX to another host is discovered, it uses SMTP to the host name in the address, rather than to the result of the MX ... when the "ether" mailer sends the mail it will repeat the MX lookup, and try all applicable destination host addresses, as it should. The rulesets I use are actually rather more complicated than that, the case of an MX aimed here, and no MX at all really shouldn't be treated identically, but this suffices for current purposes. I will be making my modified sendmail (5.61 + IDA + my stuff) available sometime soon, there are just a few more (minor) things to add and, of course, the dreaded documentation. Note: sendmail.cf files for my sendmail will (may) be incompatible with those used for IDA sendmail, though they are upwards compatible with standard 5.61 (because of the IDA operator overloading that I have altered). kre