Plan 9 from Bell Labs’s /usr/web/sources/contrib/gabidiaz/root/sys/src/cmd/spf/validatesender

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc

rfork en
fn usage{
	echo 'usage: validatesender [-n /net] plan9.bell-labs.com glenda ip' >[1=2]
	exit usage
}

echo $sysname $pid '$' validatesender $* >>/sys/log/smtpd.mx

netroot=/net
if(~ $1 -n){
	shift
	netroot=$1
	shift
}
if(! ~ $#* 3)
	usage

dom=$1
addr=$2

# Cause some problems
if(~ $dom swtch.com && ~ $addr glenda && ! ~ $sysname olive)
	exit 'deferred: always defer this one'

# Sites that we have to special case
# Lucent only - use external network when mail from external domains
# is delivered to us internally.  Assume that local domains are fine.
#netroot=/net
#if(~ $dom *.lucent.com lucent.com *.bell-labs.com bell-labs.com)
#	exit ''
#if(! ~ $sysname ethel)
#	exit ''
#if(~ $sysname ethel){
#	if(! test -d /net.alt/tcp)
#		import outside /net.alt
#	if(test -d /net.alt/tcp)
#		netroot=/net.alt
#}

# test spf
timestamp=`{date}
spfstat=`{upas/spf -u $addr -d $dom -a $3 -l YOURDOM.COM >[2=1]}
echo -n $timestamp >> /sys/log/spf
echo -n '	upas/spf -u '^$addr^' -d '^$dom^' -a '^$3^' -l YOURDOM.COM'  >> /sys/log/spf
echo '	'^$spfstat >> /sys/log/spf

if (~ $spfstat Fail) {
	exit 'rejected: SPF status '^$spfstat^' is not allowed. Please update your DNS spf record'
}

if(x=`{upas/smtp -p $netroot/tcp!$dom /dev/null $addr >[2=1] | 
	tee >{sed 's/^/'$sysname' '$pid' /' >> /sys/log/smtpd.mx} |
	tail -1})
exit ''

smtpstatus=$status
if(~ $#x 0)
	x=$smtpstatus
if(~ $smtpstatus *'Permanent Failure'*)
	exit 'rejected: smtp ping: '^$"x
exit 'deferred: smtp ping: '^$"x



Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.