:
#      @(#)cf	1.2.1.2 Lachman System V STREAMS TCP  source
#
# Copyrighted as an unpublished work.
# (c) Copyright 1989 INTERACTIVE Systems Corporation
# All rights reserved.
#
#      SCCS IDENTIFICATION
:
#
#	Copyright (C) The Santa Cruz Operation, 1988.
#	This Module contains Proprietary Information of
#	The Santa Cruz Operation, and Lachman Associates Inc. 
#	and should be treated as Confidential.
#
#
# mkcf:  makes sendmail cmnfiguration file "sendmail.cf
#
# initialize variables
PATH=/bin:/usr/bin:/etc
UUNET="n"
INET="n"
UUGW="n"
#
#
# EDUUCP() edit UUCP connections list
eduucp() {
clear
echo "Edit UUCP connections list\n"
echo "If you have a UUCP Gateway on the net, Enter the list manually, and"
echo "include the machines the UUCP Gateway connects to in the list.\n"
echo "	1. Enter list manually"
echo "	2. Get list from UUCP configuration files\n\n"
echo "Enter choice: \c"
read choice
case $choice in
	1)	clear
		echo "Enter UUCP connections list manually\n"
		echo "Enter machine names separated by spaces (i.e. > foo bar uunet ): "
		echo "> \c"
		U=`line` ;;
	2)	echo "Retrieving names using uuname..."
		u=`uuname`
		U=`echo $u` ;;
esac
echo "\n\nYour UUCP connections list looks like this:"
echo $U
echo "\n\n\n\nPlease hit RETURN to continue\c"
read choice
}

eddom() {
clear
echo "Edit DOMAIN \n"
echo "	1. Enter DOMAIN manually"
echo "	2. Get DOMAIN from \"hostname\" utility\n\n"
echo "Enter choice: \c"
read choice
case $choice in
	1)	clear
		echo "Enter DOMAIN manually"
		echo "> \c"
		read D ;;
	2)	echo "Retrieving DOMAIN using hostname..."
		D=`hostname | sed -e "s/[A-Za-z0-9-%]*\.\(.*\)/\1/"` ;;
esac
echo "\n\nYour host's DOMAIN looks like this:"
echo $D
echo "\n\n\n\nPlease hit RETURN to continue\c"
read choice
}
edalt() {
clear
echo "Edit Alternate host names\n"
echo "	1. Enter Alternate host names manually"
echo "	2. Get Alternate host names from \"uname\" \n\n"
echo "Enter choice: \c"
read choice
case $choice in
	1)	clear
		echo "Enter Alternate host names manually"
		echo "> \c"
		read H ;;
	2)	echo "Retrieving Alternate host name using uname..."
		H=`uname -n`
esac
echo "\n\nYour host's Alternate names look like this:"
echo $H
echo "\n\n\n\nPlease hit RETURN to continue\c"
read choice
}
edmis() {
while true
do
clear
echo "Edit Miscellaneous Information\n"
echo "	1. Do you connect via UUCP to uunet? [$UUNET]"
echo "	2. Is there a UUCP gateway on your network? [$UUGW] "
echo "	3. Is this machine on the Internet? [$INET] "
echo "	4. Return to main menu"
echo "\n\nEnter choice: \c"
read choice
case $choice in
	1)	clear
		echo "Do you connect via UUCP to uunet? (y or n) \c"
		getyn
		UUNET=$yn ;;
	2)	clear
		echo "Is there a UUCP gateway (other than this machine) in the net? "
		echo "If so, what is it called? (otherwise enter n) \c"
		read UUGW ;;
	3)	clear
		echo "Is this machine on the Internet? (y or n) \c"
		getyn
		INET=$yn;;
	4)	break ;;
esac
done
}
# prompt for yes or no answer - returns non-zero for no
getyn() {
	while	read yn
	do	case $yn in
		[y])	return 0 			;;
		[n])	return 1			;;
		*)	echo "please enter either y or n" 	;;
		esac
	done
}

review() {
M=`hostname`
clear
echo "Sendmail configuration information...\n"
echo "  Machine name:			   	${M:-NOT SET}"
echo "  DOMAIN name:			  	${D:-NOT SET}"
echo "  UUCP connections:			${U:-NOT SET}"
echo "  Alternate names:			${H:-NOT SET}"
echo "  Connect to uunet via UUCP?		${UUNET:-NOT SET}"
echo "  Is there a UUCP gateway on the net?	${UUGW:-NOT SET}"
echo "  Are we on Internet? 			${INET:-NOT SET}"
echo "\n\nPlease review this configuration.  If any of the fields above"
echo "are listed as \"NOT SET\", please configure them."
echo "\n\nPlease hit RETURN to continue"
read choice
}
generate() {
	review
        
	echo "Do you wish to change anything? (y/n)\c"
	getyn
	if [ $? -eq 0 ]
	then
		return
	fi

	if [ -f /tmp/sendmail.cf ]
	then 
		rm /tmp/sendmail.cf
	fi

cat > /tmp/sendmail.cf << stop
###############################################################################
###                                                                         ###
###            sendmail configuration for generic complex host              ###
###                with both UUCP and Internet connections                  ###
###                                                                         ###
###            Based upon work by Erik E. Fair <fair@ucbarpa.berkeley.edu>  ###
###	       modified extensively by:                                     ###
###            Ned Hogan <nedh@sco.com>                                     ###
###                                                                         ###
###############################################################################

# Our local domain (\$D is added to \$w [hostname] for official name in base.m4)
stop
/bin/echo "DD$D" >> /tmp/sendmail.cf
cat >> /tmp/sendmail.cf << stop

# All the names we are known by (put all the names & nick names on the next
# line, separated by spaces. If you need another line, begin it with "Cw")
stop
/bin/echo "Dw`uname -n`" >> /tmp/sendmail.cf
/bin/echo "Cw$H" >> /tmp/sendmail.cf
cat >> /tmp/sendmail.cf << stop
# Our UUCP name
DU\$w
stop
if [ $UUGW != "n" ]
then
/bin/echo "# the UUCP gateway class to which we route UUCP mail from leaf nodes" >> /tmp/sendmail.cf
/bin/echo "DG$UUGW" >> /tmp/sendmail.cf
fi
cat >> /tmp/sendmail.cf << stop

# the list of UUCP hosts that we speak to (same rules as Cw, use the
# output of the "uuname" command; also, when you add or delete a host
# from /usr/lib/uucp/Systems, don't forget to add or delete it here)
stop
/bin/echo "CU$U" >> /tmp/sendmail.cf
cat >> /tmp/sendmail.cf << stop
###############################################################################
###   baseline definitions that sendmail needs to operate                   ###
###############################################################################

##########################
###   Special macros   ###
##########################

DV1.2

# my official hostname
Dj\$w.\$D
# my name (the name on mailer bounces)
DnMAILER-DAEMON
# UNIX header format
DlFrom \$g \$d
# delimiter (operator) characters
Do.:%@!^/[]
# format of a total name
Dq\$?x\$x <\$g>\$|\$g\$.
# SMTP login message
De\$j Sendmail \$v/\$V ready at \$b

###################
###   Options   ###
###################

# we have full sendmail support here
Oa
# location of alias file
OA/usr/lib/mail/aliases
# default delivery mode (deliver in background)
Odbackground
# (don't) connect to "expensive" mailers
#Oc
# temporary file mode
OF0600
# default GID
Og12
# location of help file
OH/usr/lib/sendmail.hf
# log level
OL9
# Send to me too (even if I'm in an alias expansion)
Om
# default messages to old style
Oo
# queue directory
OQ/usr/spool/mqueue
# read timeout -- violates protocols (timeout an SMTP idle for 2 hours)
Or2h
# status file
OS/usr/lib/sendmail.st
# queue up everything before starting transmission
Os
# default timeout interval (returns undelivered mail after 3 days)
OT3d
# time zone names (V6 only)
# OtPST,PDT
# default UID
Ou1
# wizard
# OW
# rebuild the aliasfile automagically
#OD
# maximum load average before queueing mail
Ox10
# maximum load average before rejecting connections
OX15

###############################
###   Message precedences   ###
###############################

Pfirst-class=0
Pspecial-delivery=100
Pbulk=-60
Pjunk=-100

#########################
###   Trusted users   ###
#########################

Troot
Tdaemon
Tnews
Tuucp
Tmmdf
Tcron

#############################
###   Format of headers   ###
#############################

HReceived: \$?sfrom \$s\$. by \$j\$?r with \$r\$. (\$v/\$V-eef)
	id \$i; \$b
H?P?Return-Path: <\$g>
H?D?Date: \$a
H?F?From: \$q
H?x?X-Full-Name: \$x
HSubject:
H?F?Resent-From: \$q
H?D?Resent-Date: \$a
H?M?Resent-Message-Id: <\$t.\$i@\$j>
H?M?Message-Id: <\$t.\$i@\$j>


###############################################################################
#		RULESET ZERO PREAMBLE                                         #
###############################################################################

S0
# first make canonical
R\$*<\$*>\$*		\$1\$2\$3				defocus
R\$+			\$:\$>3\$1				make canonical

# handle special cases.....
R@			\$#local\$:\$n			handle <> form
R\$*<@[\$+]>\$*		\$#tcp\$@[\$2]\$:\$1@[\$2]\$3		numeric internet spec

# now delete the local info
R\$*<\$*\$=w.UUCP>\$*	\$1<\$2>\$4			thishost
R\$*<\$*\$=w.\$D>\$*		\$1<\$2>\$4			thishost
R\$*<\$*\$=w>\$*		\$1<\$2>\$4			thishost
R\$*<\$*.>\$*		\$1<\$2>\$3			drop trailing dot
R<@>:\$*			\$@\$>0\$1				retry after route strip
R\$*<@>			\$@\$>0\$1				strip null trash & retry

# return uucp mail that looks like decvax!ittvax!marsvax! since it
# will be rejected at the final site with no username on it
R\$*!<@\$-.UUCP>		\$#error\$:Destination address truncated
R\$*@\$+!\$+		\$#error\$:Illegal Address Format



###############################################################################
###  Machine dependent part of ruleset zero (where we decided what to do)   ###
###############################################################################

stop
if [ $UUGW = "n" ]
then
/bin/echo "# resolve UUCP links to hosts known to this machine" >> /tmp/sendmail.cf
/bin/echo "R\$*<@\$=U>\$*		\$#uucp\$@\$2\$:\$1		resolve local uucp" >> /tmp/sendmail.cf
else 
/bin/echo "# send UUCP mail to hosts known to this machine to Gateway" >> /tmp/sendmail.cf
/bin/echo "R\$*<@\$=U>\$*		\$#tcp\$@\$G\$:\$2!\$1			resolve local uucp" >> /tmp/sendmail.cf
fi
cat >> /tmp/sendmail.cf << stop

# special case violation of RFC822 for hybrid bang/at addresses
stop
if [ $UUGW = "n" ]
then
cat >> /tmp/sendmail.cf << stop
# if uucphost!user@arpahost, forward to uucphost if we speak to it.
R\$=U!\$+<@\$+>\$*		\$#uucp\$@\$1\$:\$2@\$3\$4
R\$=U!\$+			\$#uucp\$@\$1\$:\$2
stop
else
cat >> /tmp/sendmail.cf << stop
# forward uucphost!user@arpahost to uucphost via Gateway if we speak to uucphost
R\$=U!\$+<@\$+>\$*		\$#tcp\$@\$G\$:\$1!\$2@\$3\$4
R\$=U!\$+			\$#tcp\$@\$G\$:\$1!\$2
stop
fi
if [ $UUGW != "n" ]
then
cat >> /tmp/sendmail.cf << stop
# send unknown .UUCP and *.UU.NET stuff to uunet via Gateway
R\$*<@\$+.UUCP>		\$#tcp\$@\$G:uunet!\$2!\$1
R\$*<@\$+.UU.NET>		\$#tcp\$@\$G:uunet!\$2!\$1
R\$*!\$+.UUCP		\$#tcp\$@\$G:uunet!\$1!\$2
R\$*!\$+.UU.NET		\$#tcp\$@\$G:uunet!\$1!\$2
stop
elif [ $UUNET != "n" ]
then
cat >> /tmp/sendmail.cf << stop
# send unknown *.UUCP and *.UU.NET stuff to uunet via UUCP

R\$*<@\$+.UUCP>		\$#uucp\$@uunet:\$2!\$1
R\$*<@\$+.UU.NET>		\$#uucp\$@uunet:\$2!\$1
R\$*!\$+.UUCP		\$#uucp\$@uunet:\$1!\$2
R\$*!\$+.UU.NET		\$#uucp\$@uunet:\$1!\$2

stop
fi
if [ $INET = "y" ]
then
cat >> /tmp/sendmail.cf << stop
# send unknown *.UUCP and *.uu.net stuff to uunet via SMTP 
# for Internet sites

R\$*<@\$+.UUCP>		\$#tcp\$@uunet:\$1@\$2.uu.net
R\$*<@\$+.UU.NET>	\$#tcp\$@uunet:\$1@\$2.uu.net
R\$*!\$+.UUCP		\$#tcp\$@uunet:\$1!\$2.uu.net
R\$*!\$+.UU.NET		\$#tcp\$@uunet:\$1!\$2.uu.net

stop
fi

cat >> /tmp/sendmail.cf << stop

# resolve various and sundry other unofficial networks
R\$*<@\$+.BITNET>\$*	\$#tcp\$@cunyvm.cuny.edu\$:\$1@\$2.BITNET\$3		BITNET
R\$*<@\$+.MFENET>\$*	\$#tcp\$@nmfecc.arpa\$:\$1@\$2.MFENET\$3		MFENET
R\$*<@\$+.CSNET>\$*	\$#tcp\$@relay.cs.net\$:\$1@\$2.CSNET\$3		CSNET

# when all else fails, look up the whole name in the host table
R\$+!\$+<@\$+>\$*		\$#tcp\$@\$[\$3\$]\$:\$1!\$2\$4			a.b!c!d
R\$*<@\$+>\$*		\$#tcp\$@\$[\$2\$]\$:\$1@\$2\$3			user@domain
R\$~U!\$-			\$#tcp\$@\$[\$1\$]\$:\$2@\$1
R\$~U!\$-!\$*		\$#tcp\$@\$[\$1\$]\$:\$2!\$3
R\$~U!\$-.\$+!\$*		\$#tcp\$@\$[\$1\$]\$:\$2.\$3!\$4

# remaining names must be local
R@			\$n					fix magic token
R\$+			\$#local\$:\$1				everything else

###############################################################################
###   End of ruleset zero                                                   ###
###############################################################################

###########################
#  Name Canonicalization  #
###########################

S3
# handle "from:<>" special case
R<>			\$@@				resolve into magic token

# basic textual canonicalization
R\$*<\$*<\$*<\$+>\$*>\$*>\$*	\$4				3-level <> nesting
R\$*<\$*<\$+>\$*>\$*		\$3				2-level <> nesting
R\$*<\$+>\$*		\$2				basic RFC821/822 parsing
R\$+ at \$+		\$1@\$2				"at" -> "@" for RFC 822
R\$*<\$*>\$*		\$1\$2\$3				in case recursive

# make sure <@a,@b,@c:user@d> syntax is easy to parse -- undone later
R@\$+,\$+			@\$1:\$2				change all "," to ":"

# localize and dispose of domain-based addresses
R@\$+:\$+			\$@\$>6<@\$1>:\$2			handle <route-addr>

# more miscellaneous cleanup
R\$+			\$:\$>9\$1				host dependent cleanup
R\$+<@\$+>		\$@\$>6\$1<@\$2>			canonical <a.b!c>
R\$+:\$*;@\$+		\$@\$1:\$2;@\$3			list syntax
R\$+@\$+			\$:\$1<@\$2>			focus on domain
R\$+<\$+@\$+>		\$1\$2<@\$3>			move gaze right
R\$+<@\$+>		\$@\$>6\$1<@\$2>			already canonical

# convert old-style addresses to a domain-based address
R\$+^\$+			\$1!\$2				convert ^ to !
R\$+!\$+			\$@\$>9\$1!\$2			uucp name hackery
R\$+%\$+			\$:\$>5\$1%\$2			user%host%host
R\$+<@\$+>		\$@\$>6\$1<@\$2>			canonical

S5
# Given multiple %'s change rightmost % to @.
R\$*<\$*>\$*		\$1\$2\$3				defocus
R\$*%\$*			\$1@\$2				First make them all @'s.
R\$*@\$*@\$*		\$1%\$2@\$3			Undo all but the last.
R\$*@\$*			\$@\$1<@\$2>			Put back the brackets.

###############################################################################
####   Assorted name hackery to make things simple for people              ####
###############################################################################

# here we look for addresses of the form: user%host.domain@gateway
# and strip off the gateway name (for the ones that we know)

S6
R\$+<@\$=U.\$+>\$*		\$@\$2!\$1		Strip domains for uucp neighbors

# conventional percent format
R\$+%\$+.MFENET<@nmfecc.arpa>		\$>5\$1<%\$2.MFENET>	strip
R\$+%\$+.BITNET<@cunyvm.cuny.edu>		\$>5\$1<%\$2.BITNET>	strip
R\$+%\$+.CSNET<@relay.cs.net>		\$>5\$1<%\$2.CSNET>	strip

# regulation route-addr format
R<@nmfecc.arpa>:\$+@\$+.MFENET		\$1<@\$2.MFENET>		strip
R<@cunyvm.cuny.edu>:\$+@\$+.BITNET	\$1<@\$2.BITNET>		strip
R<@relay.cs.net>:\$+@\$+.CSNET		\$1<@\$2.CSNET>		strip

S7
# mung up names for the outside world - called from tcp mailer
R\$+@\$+.MFENET		\$1%\$2.MFENET@nmfecc.arpa	user@host.MFENET
R\$+@\$+.BITNET		\$1%\$2.BITNET@cunyvm.cuny.edu	user@host.BITNET
R\$+@\$+.CSNET		\$1%\$2.CSNET@relay.cs.net	user@host.CSNET

###############################################################################
####   UUCP address hackery                                                ####
###############################################################################

S9
R\$*\$=w!\$+		\$3				collapse loops
R\$+!\$+@\$+		\$@\$>6\$3!\$1!\$2			a.b!c.d!user
R\$-.\$+!\$+		\$@\$>6\$3<@\$1.\$2>			do.main!user
R\$+@\$=U			\$@\$2!\$1				fix user@UUCPhost
#R\$=U!\$+		\$@\$>6\$2<@\$1>			host!user
R\$=U!\$+			\$@\$>6\$1!\$2			host!user
R\$~U!\$+			\$@\$1!\$2


#R\$-!\$+			\$@\$>6\$2<@\$1>.UUCP		host!user

################################
#  Sender Field Pre-rewriting  #
################################

S1
R\$*<\$*>\$*		\$1\$2\$3				defocus

###################################
#  Recipient Field Pre-rewriting  #
###################################

S2
R\$*<\$*>\$*		\$1\$2\$3				defocus

###################################
#  Final Output Post-rewriting    #
#  Standard Domain-based version  #
###################################

S4
R@			\$n				handle <> error addr

# externalize local domain info
R@\$+:\$+:\$+		\$@@\$1,\$2:\$3			<route-addr> canonical

# UUCP must always be presented in old form
R\$+@\$-.UUCP		\$2!\$1				u@h.UUCP => h!u

###############################################################################
###   Local, and Program Mailer specifications                              ###
###############################################################################

# Nota Bene: what mailer flags you use depends upon what version of /bin/mail
# you have:
#
# 4th Berkeley Software Distribution (4.1 BSD or later)
# Mlocal, P=/usr/bin/lmail, F=SlsDFMPpmnxr, S=10, R=20, A=lmail -d \$u
#
# USG UNIX (System III, System V, Xenix 3.0 or later)
# Mlocal, P=/usr/bin/mail, F=SlsDFMPpmnx, S=10, R=20, A=mail \$u
#
# SCO TCP/IP on SCO Xenix V 2.3
#Mlocal, P=/usr/lib/mail/mail.local, F=UnFDxPlm, S=10, R=20, A=mail.local -r \$g \$u
# SCO TCP/IP on SCO Unix V 3.2
Mlocal, P=/usr/bin/lmail, F=lsFDMPuhCE, S=10, R=20, A=lmail \$u

Mprog,	P=/bin/sh,   F=lsDFMeuP,  S=10, R=20, A=sh -c \$u

S10

S20

###############################################################################
####    IP/TCP/SMTP mailer (going out to internet land)                    ####
###############################################################################

Mtcp,	P=[IPC], F=msDFMuCXP, S=14, R=20, A=IPC \$h, E=\\r\\n

S14
R\$*@[\$+]\$*		\$@\$1@[\$2]\$3		already ok (inet addr spec)
R@\$+@\$+			\$@@\$1@\$2		already ok (route-addr)
R\$+@\$=X.UUCP		\$2!\$1@\$X		fix remote UUCP
R\$+@\$=Y.UUCP		\$2!\$1@\$Y		fix remote UUCP
R\$+@\$=Z.UUCP		\$2!\$1@\$Z		fix remote UUCP
R\$+@\$-.UUCP		\$2!\$1@\$j		undo local UUCP hack
R\$+@\$+			\$@\$>7\$1@\$2		fix up names for the internet
R\$+			\$@\$1@\$j			add our official host name

###############################################################################
####   UUCP mailer (bangland)                                              ####
###############################################################################

# if none of your UUCP neighbors are 4.1 BSD sites, add an "m" after "F="
# this will cause multiple recipients on the same remote host to be done
# in the same uux command (i.e. one letter sent for "n" recipients)
#
# if you want uucico to be invoked immediately after a letter is queued
# (i.e. initiate the phone call immediately) remove the "-r" flag from the
# uux command line.
#
# if you want uux to notify you upon completion of the transfer,
# add a "-z" flag from the uux command line.
# example:
#	A=uux - -z -a\$f -gC \$h!rmail (\$u)

Muucp,	P=/usr/bin/uux, F=DFMhuU, S=13, R=23, M=100000,
	A=uux - -r -a\$f -gC \$h!rmail (\$u)

S13
R\$+@\$-.UUCP		\$2!\$1				u@host.UUCP => host!u
R\$=w!\$+			\$2				zap dups
R@\$+@\$+			\$@\$U!@\$1@\$2			ugh, route-addrs
# unfortunately, I have to resolve route-addrs before this rule, because
# it is so general that it matches them too, with disastrous results. - EEF
R\$+@\$-.\$+		\$2.\$3!\$1			uucpize address
R\$+			\$:\$U!\$1				stick on our host name

S23
# nothing here because bangland mailers are supposed to rewrite these headers
# relative to the sender by themselves anyway.
stop
if [ -f /usr/lib/sendmail.cf ]
then
	/bin/echo " Moving /usr/lib/sendmail.cf to /usr/lib/sendmail.cf-"
	mv /usr/lib/sendmail.cf /usr/lib/sendmail.cf-
	sleep 1
elif [ -f /usr/lib/sendmail.fc ]
then
	/bin/echo " Moving /usr/lib/sendmail.fc to /usr/lib/sendmail.fc-"
	mv /usr/lib/sendmail.fc /usr/lib/sendmail.fc-
	sleep 1
fi
mv /tmp/sendmail.cf /usr/lib/sendmail.cf
chmod 644 /usr/lib/sendmail.cf
/bin/echo "New sendmail.cf installed in /usr/lib\n"
sleep 2
# initialize alias database now that we have a configuration file
if [ ! -f /usr/lib/mail/aliases.dir ]; then
	newaliases > /dev/null 2>&1 &
fi
}
while true
do
	clear
	echo "SCO Sendmail Configuration Utility\n"
	echo "	1. Edit UUCP Connections"
	echo "	2. Edit Domain"
	echo "	3. Edit Alternate Host Names"
	echo "	4. Miscellaneous Stuff"
	echo "	5. Review configuration information"
	echo "	6. Generate sendmail.cf file"
	echo "	7. Quit"
	echo "\n\nEnter choice: \c"
	read choice
	case $choice in
		1)	eduucp  ;;
		2)	eddom   ;;
		3)	edalt	;;
		4)	edmis   ;;
		5)	review  ;;
		6)	generate ;;
		7)	break ;;
	esac
done
exit 0
