Sendmail

This solution for obtaining the IP address of the connecting host could be considered to be a bit of a hack, but it works quite reliably. If you're an ordinary user on your system, you won't be able to use this; talk to your system administrator about the possibility of installing the sendmail.cf patch below. Point them at this file as a source of information.

Currently, in your sendmail.cf file, you'll probably have something like:

Mlocal,	P=/bin/mail, F=lsDFMAw5:/|@SnE, S=10/30, R=20/40,
	T=DNS/RFC822/X-Unix,
	A=mail -f $g -d $u

Or, if you're using procmail as the local delivery agent:

Mlocal,	P=/usr/bin/procmail, F=lsDFMAw5:/|@ShPfn, S=10/30, R=20/40,
	T=DNS/RFC822/X-Unix,
	A=procmail -a $h -d $u

This is the local delivery rule used to execute .forward scripts. Your system might use something like rsh or another restricted shell instead of sh for running programs. Don't let that scare you; they all basically work the same.

Change the above lines to look like this (there will also be Mprog lines which look similar; you can modify them in exactly the same manner):

Mlocal,	P=/usr/bin/env, F=lsDFMAw5:/|@SnE, S=10/30, R=20/40,
	T=DNS/RFC822/X-Unix,
	A=env TCPREMOTEIP="${client_addr}" mail -f $g -d $u

(replacing "mail -f $g -d $u" with "procmail -a $h -d $u" appropriately.)

ONLY change the P=... and A=... entries. Most certainly do not mess with F=... unless you know what you are doing.

This will create an environment variable TCPREMOTEIP, which you can now use with rblcheck to determine if the address has been blocked. To test this, set up an alias like:

foo: |mailx -s "$TCPREMOTEIP" user@domain.com

Then, send email to the alias "foo" (or whatever). You should immediately get a piece of email with the IP address which sent the message in the subject line. (Replace mailx with mail on some systems.)

This is about the most efficient means of getting this information to executed programs that I can see with sendmail. What would -really- be nice here would be a way to program how Sendmail sets up the environment before executing an external program, at the point of execution. Bug the Sendmail developers if you agree with me. ;-)