A slave uucico emulation as a shell script!

briant at uk.co.spider briant at uk.co.spider
Sat Sep 9 04:37:19 AEST 1989


#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  README Unix.Script uucico.sh
# Wrapped by briant at tarantula on Fri Sep  8 19:05:56 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(1115 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
X Scripts that can be used to hook systems with other kinds of mailers into
Xa uucp based network. 
X These were written to link in a site that was already running an inhouse
Xmail system that also linked into commercial mail systems like compuserve.
XThis system used single user machines (like Macs). It would have unaceptable
Xto have another system running something like uupc, or to alternate between
Xuupc an another mail delivery system. The customisation had to be done on
Xthe unix end and not the Mac end.
X
X  The mail system in question was Quickmail, and I have included a script
Xthat can drive quickmail, in case there are any other quickmail users 
Xthat can utiise this.
X
X  The script for the unix side is generally useful for hooking up non-uucp
Xbased mail systems into the uucp network.
X
X  Yes! I know its a huge hack. I am sure it might be better done in C.
XI hope this is useful.
X
X   Brian Tompsett.   September 1989.
XBritish Computer Society, Edinburgh Branch.
X--
Xbct at tardis.cs.ed.ac.uk   ...!cernvax!tardis.cs.ed.ac.uk!bct
Xbct%tardis.cs.ed.ac.uk at cunyvm.cuny.edu
Xbct%tardis.cs.ed.ac.uk at nfsnet-relay.ac.uk
END_OF_FILE
if test 1115 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'Unix.Script' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Unix.Script'\"
else
echo shar: Extracting \"'Unix.Script'\" \(1655 characters\)
sed "s/^X//" >'Unix.Script' <<'END_OF_FILE'
X* Unix.Script, for QuickMail
X*   Written by Brian Tompsett, 
X*     British Computer Society, Edinburgh Branch. August 1989.
X*	bct at tardis.cs.ed.ac.uk
X*
X*   This simple Script is for logging onto a unix machine that is
X*   running the slave uucico emulation script.
X*   The script at the Unix end is designed to be portable and this
X*   method can be used to hook any unix system to Quickmail!
X*
X*  Note that << represents option-\ and >> represents shift-option-\
X*   characters on the Macintosh
X*
X* This is called to log us in
X:IN
XOOPS 240,FAILURE
XALERT 1,IN1,ogin:
XPAUSE 2
XTYPE ^M
X* Hit CR and LOOP until prompted
XGOTO IN
X*
X:IN1
XALERT 1,,
XTYPE <<LOGID>>^M
XWAIT asswd:
XTYPE <<PASSWORD>>^M
XWAIT Command:
XSUCCESS
X*
X*  This logs us off
X*
X:BYE
XTYPE exit^M
XPAUSE 10
XSUCCESS
X*
X* This is called to send one piece of mail
X*
X:SEND
XOOPS 150,FAILURE
X:S1
XALERT 1,S1,Bad Command!
XTYPE write^M
XWAIT (Name of recipient):
XALERT 1,S2,Bad Address!
XTYPE <<NAME>>^M
XWAIT (Recipients address):
XTYPE <<ADDRESS>>^M
XWAIT (Name of sender):
XTYPE <<FROM>>^M
XWAIT (Senders address):
XTYPE <<FROM>>^M
XWAIT Subject:
XTYPE <<TOPIC>>^M
XALERT 1,S11,ending with ^Z
XALERT 2,S13,ending with ^D
X*  Hmm. Not sure if this works?
XWAIT Command:
XFAILURE
X:S13
XDUMP ^J
XTYPE ^D
XGOTO S12
X:S11
XDUMP ^J
XTYPE ^Z
X:S12
XWAIT Command:
XSUCCESS
X:S2
XERRORINADDRESS
XALERT 1,,
XGOTO S12
X*
X* This is called to receive mail
X*
X:RECEIVE
XOOPS 150,FAILURE
X:R1
XALERT 2,R1,Bad Command!
XTYPE read^M
XWAIT read
XALERT 1,FAILURE,No More Mail!
XBUFFER (This message brought to you by Brian Mail)
XALERT 2,,
XRECEIVE Subject:,Apparently-To:,Apparently-From:,<,>
XWAIT Delete the mail
XTYPE Y^M
XWAIT Command:
XSUCCESS
X*
X* End of Script
X*
END_OF_FILE
if test 1655 -ne `wc -c <'Unix.Script'`; then
    echo shar: \"'Unix.Script'\" unpacked with wrong size!
fi
# end of 'Unix.Script'
fi
if test -f 'uucico.sh' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'uucico.sh'\"
else
echo shar: Extracting \"'uucico.sh'\" \(23308 characters\)
sed "s/^X//" >'uucico.sh' <<'END_OF_FILE'
X#!/bin/sh
XSIGNALS="1 2 3 4 5 6 7 8 9 10 12 13 14 15 16"
Xtrap exit $SIGNALS
Xreadonly SIGNALS
X#	File: uucico.sh
X#		A mail delivery agent that interfaces between the unix uucp
X#		system and an outside non-unix system. 
X#		The use of this script allows a remote user or site to log in
X#		to transfer mail (both in and out) without having uucp, but to
X#		allow the site to be handled as any other uucp site.
X#		This is achieved to emulating the actions of a slave uucico.
X#       There are some system dependencies that may need altering.
X#
X#	See end of file for full details.
X#
X#	Thrown together by Brian Tompsett,
X#			British Computer Society, Edinburgh Branch.
X#			bct at tardis.cs.ed.ac.uk
X#		July 1989
X#
X#----------------------------------------------------------------------
X# Defaults: 
Xdebugger=SomeUserName	#Put in here your user name if you are debugging
Xdefaultsite=SomeSiteName	#Put in here the name of the remote site
Xcommandtimeout=30	#Number of seconds for a command input timeout
Xfiletimeout=120		#Number of seconds for file input timeout
XLIBDIR=/usr/lib/uucp	# uucp lib directory
XSPOOLDIR=/usr/spool/uucp	# uucp spool directory
XLOGFILE=$SPOOLDIR/LOGFILE	# Location of uucp Logfile
Xmailername=BriansBrilliantMailer	#Name of this mailer to be used in headers
Xdeliveryagent=rmail		# mail delivery agent for remote site mail
X#
Xreadonly debugger defaultsite commandtimeout filetimeout LIBDIR SPOOLDIR \
X LOGFILE mailername deliveryagent
X#----------------------------------------------------------------------
X# Constants
XNL='
X'
Xreadonly NL
X#
X#----------------------------------------------------------------------
X# try to find out who we are logged in as?
X# see if whoami exists?
XUSER=`sh -c whoami 2>&1` 
Xcase "$USER" in
X "sh: whoami: not found" )
X	# It doesnt! Use who instead
X	USER=`who am i | awk '{print \$1;exit}'` 
X	;;
Xesac
Xreadonly USER
X# 
X# Allow a debugging user 
Xcase "$USER" in
X "$debugger" )
X	EXIT=":"
X	trap "" $SIGNALS
X	;;
X *)
X	EXIT=exit
X	;;
Xesac
X#
X# We need to find the uucp name of this site. Done in order:
X#	1. /etc/uucpname
X#	2. /local/uucpname
X#	3. /usr/include/whoami.h (2 formats)
X#	4. uuname -l
X#
Xif test -f /etc/uucpname
X	then
X		ourname=`cat /etc/uucpname`
X	else if test -f /local/uucpname
X	then
X		ourname=`cat /local/uucpname`
X	else if test -f /usr/include/whoami.h
X	then
X		ourname=`awk "/^#define sysname/{print \$3;exit}
X		 		NF == 1 {print \$1;exit}" /usr/include/whoami.h`
X	else
X		ourname=`uuname -l`
X	fi
X	fi
Xfi
Xreadonly ourname
X#
X# Process the arguments to decide if we are a login shell or not.
X# If we are a login shell then the name of the remote site is currently 
X# hardwired in. We should probably ask the remote site for it eventually,
X# or extract it from the name of the script.
X# If we are not a login shell then we can take the site name as an argument.
X# A privileged user may set some options - none exist yet!
X#
X# This part also determines who will be killed when an input timeout happens.
X# If we are a login shell then kill everyone stone dead, for security.
X# If invoked as a subshell just kill `this' shell (default).
Xsite=$defaultsite
Xtimeoutvictims=$$
Xwhile test "$1" != ""
X do
X case "$1" in
X	-* ) 
X		# login shell?
X		case "-`basename $0`" in
X			"$1" )
X				# Looks like we may be login shell
X				#  Set Victims for timeouts to be whole family!
X				timeoutvictims=0
X				break
X				;;
X			*)
X				# might be an option. Are we privileged to do this?
X				case "$USER" in
X					"$debugger" )
X						# Do something with the option?
X						echo "Invalid option: $1"
X						shift
X						continue
X						;;
X					*)
X						# hey! you cant do this.
X						echo "You can't do this!"
X						break
X						;;
X				esac
X		 esac
X		;;
X	[a-z]* | [A-Z]* )
X		# user invokation
X		site="$1"
X		break
X		;;
X	* )
X		echo "Script confused"
X		break
X		;;
X esac
Xdone
Xreadonly site
X#
X# Find out what kind of unix we are running 
X#
Xversion="`sh -c 'uname -r' 2>&1'`"
X#
X# Use the version to set the cancel timeout signal number.
X#  There are probably hundreds of versions in the world, but I have 
X# only tested on these few.
X# 2.1.3 & 2.3.1 = XENIX, 4_0 = UMIPS, 3.2 = SysV3.2, 5.0=CUX1099, 5.3=GEC
X# 4.2 = BSD4.2, Sun, Ultrix, Pyramid
Xcanceltimeoutsignal=0
Xcase "$version" in
X	"2.3.1" | "4_0" | "3.2" | "5.0" ) canceltimeoutsignal=19 ;;
X	"2.1.3" | "5.3" ) canceltimeoutsignal=0 ;; # Stupid GEC unix cant cope!
X	"uname: not found" | "uname: Command not found." | "" ) version=4.2
X		canceltimeoutsignal=16 ;;
X	*) echo Dont know what version of Unix I am!
X		eval $EXIT
Xesac
Xcommandwatchdog=":"
Xfilewatchdog=":"
Xcommandcanicide=":"
Xfilecanicide=":"
Xreadonly version canceltimeoutsignal
X#
X# See if the echo understands -n!
Xcase "`echo -n`" in
X "-n") E1=""   E2="\c" ;;
X   * ) E1="-n" E2=""   ;;
Xesac
Xreadonly E1 E2
X# Based on the version we can find the files we need
X#
X# Look to see if we are running UKuucp and the directories
X#  are redefined.
X# We restrict ourselves to a limited set of possibilities.
X#  These are C. and C.site LCK. and D. and D.site and D.us and D.usX
X# anything else is missed.
X#
XLCKFILE=$SPOOLDIR/LCK..$site
XCMDDIR=$SPOOLDIR
XDATADIR=$SPOOLDIR
XMSGDIR=$SPOOLDIR
XusX=$SPOOLDIR
Xif test -f $LIBDIR/L.dirs
X	then
X	# We are ukuucp. Can we read the dir file?
X	if test ! -r "$LIBDIR/L.dirs"
X		then
X		echo "Not enough privilege!"
X		$EXIT
X	fi
X	eval `awk "/LCK./{print \\"LCKFILE=$SPOOLDIR/\\" \\\$1 \"/LCK..$site\"}
X		/C.[ 	]/{if (c == \\"\\") c=\\\$1}
X		/C.$site[ 	]/{if (c == \\"\\") c=\\\$1}
X		/D.[ 	]/{if (data == \\"\\") data=\\\$1;
X	 			if (msg == \\"\\") msg=\\\$1}
X		/D.$site[ 	]/{if (data == \\"\\") data=\\\$1}
X		/D.$ourname[ 	]/{if (msg == \\"\\") msg=\\\$1}
X		/D.${ourname}X[ 	]/{print \\"usX=$SPOOLDIR/\\" \\\$1}
X		END{if (c != \\"\\") print \\"CMDDIR=$SPOOLDIR/\\" c;
X			if (data != \\"\\") print \\"DATADIR=$SPOOLDIR/\\" data;
X			if (msg != \\"\\") print \\"MSGDIR=$SPOOLDIR/\\" msg}" \
X	$LIBDIR/L.dirs`
Xelse
X	case "$version" in
X		"2.3.1" | "4_0" | "3.2" )
X			CMDDIR=$SPOOLDIR/$site
X			DATADIR=$SPOOLDIR/$site
X			MSGDIR=$SPOOLDIR/$site
X			if test -d /usr/spool/locks
X				then
X				LCKFILE=/usr/spool/locks/LCK..$site
X			fi
X			;;
X		"5.0" | "4.2" )
X			# See if we are Ultrix
X			if test -d $SPOOLDIR/sys/DEFAULT/D.$site
X				then
X				DATADIR=$SPOOLDIR/sys/DEFAULT/D.$site
X			fi
X			CMDDIR=$SPOOLDIR/C.
X			MSGDIR=$SPOOLDIR/D.$ourname
X			;;
X		"5.3" | "2.1.3" ) : Nothing for now ;;
X	esac
Xfi
Xreadonly CMDDIR MSGDIR LCKFILE DATADIR usX
X#
X# Check lock file first...
X#
Xif test -f "$LCKFILE"
X	then
X	echo "I am already talking to $site!"
X	echo "Bye, Bye!"
X	eval $EXIT
Xelse
X	touch $LCKFILE
X	# reset the traps to remove the LCKFILE on abort
X	trap "echo trapped; rm -f $LCKFILE; $EXIT" $SIGNALS
Xfi
X# 
X# Now we know about the lockfile we can set up some variables for
X#  the various wathcdog timers.
X#
Xcase `expr '(' "$commandtimeout" '>' 0 ')' \
X       '&' '(' "$canceltimeoutsignal" ">" 0 ')'` in
X	1 )
X	commandwatchdog="(trap exit $canceltimeoutsignal;\
X	 sleep $commandtimeout;rm -f $LCKFILE;kill -9 $timeoutvictims)&"
X	commandcanicide="kill -$canceltimeoutsignal 0" ;;
Xesac
Xcase `expr '(' "$filetimeout" '>' 0 ')' \
X       '&' '(' "$canceltimeoutsignal" ">" 0 ')'` in
X	1 )
X	filewatchdog="(trap exit $canceltimeoutsignal;\
X	 sleep $filetimeout;rm -f $LCKFILE;kill -9 $timeoutvictims)&"
X	filecanicide="kill -$canceltimeoutsignal 0" ;;
Xesac
Xreadonly commandwatchdog filewatchdog commandcanicide filecanicide
X#
X#
X# Check permissions
X#
X#	do we have a permissions file?
X#		Assume HoneyDanber
Xif test -f $LIBDIR/Permissions
X	then
X	# Is the Permissions file readable by us?
X	if test ! -r "$LIBDIR/Permissions"
X		then
X		# No permissions!
X		perms=""
X	else
X		# check for validate entry for this machine
X		valid=`egrep " VALIDATE=([a-zA-Z]+[a-zA-Z0-9]*:)*$site(:[a-zA-Z]+[a-zA-Z0-9]*)*" \
X			$LIBDIR/Permissions`
X		case "$valid" in
X			"" ) permline="cat '$LIBDIR/Permissions'" ;;
X			*)
X				# we must check login ID in this entry
X				permline="echo '$valid'" ;;
X		esac
X		perms="`eval $permline | grep LOGNAME=$USER`"
X	fi
Xelse
X	# Assume other uucps
X	# test if can access USERFILE?
X	if test -r "$LIBDIR/USERFILE"
X		then
X		perms=`egrep "^($USER,($site)?)|(($USER)?,$site)|, " $LIBDIR/USERFILE`
X	else
X		perms=""
X	fi
Xfi
Xcase "$perms" in
X "" )
X	echo "Dont know you - Permission Check failed.!"
X	eval $EXIT 
X	;;
Xesac
X# 1. Check that this site name is in the list of known Systems
X#	be careful of name subsets i.e.  owl found in fowl.
X#
Xcase "`uuname | fgrep $site`" in
X "$site" ) ;;
X *)
X    # I may have the checking of remote.unknown the wrong way around!
X	case "$version" in
X		"3.2" | "2.3.1" )
X			if test -x $LIBDIR/remote.unknown
X				then $LIBDIR/remote.unknown $site
X				else
X					echo "Dont know you!"
X					eval $EXIT
X			fi
X			;;
X		"4_0" ) if test -x $LIBDIR/rmt.unknown
X				then $LIBDIR/rmt.unknown $site
X				else
X					echo "Dont know you!"
X					eval $EXIT
X			fi ;;
X		*)
X			echo "Dont know you!"
X			eval $EXIT
X			;;
X	esac
X	;;
Xesac
X#
X# find out what the eof character is for use in mail sending.
X#  Loop invariant.
X# decide which kind of stty we have so we can find out the eof char!
X#  The two kinds either look at stdin and send to stdout
X#	or look at stdout and send to stderr
Xif expr "`stty 2>&1`" : "speed 0 baud.*" > /dev/null
X	then
X		STTY="stty > /dev/tty"
X	else
X		STTY="stty"
Xfi
Xeofchar=`(eval $STTY) 2>&1 | awk '/eof =/{len=length; i=1;
X			while (substr($0,i,6) != "eof = ") ++i;
X			eof=substr($0,i+6,2);exit}
X			END{if (eof == "") eof="^D";
X			print eof}'`
X#
X# Save the awk commands to process date to uucp logfile
Xlogdate="{if (\$2 == \"Jan\") m=1
X		else if (\$2 == \"Feb\") m=2
X		else if (\$2 == \"Mar\") m=3
X		else if (\$2 == \"Apr\") m=4
X		else if (\$2 == \"May\") m=5
X		else if (\$2 == \"Jun\") m=6
X		else if (\$2 == \"Jul\") m=7
X		else if (\$2 == \"Aug\") m=8
X		else if (\$2 == \"Sep\") m=9
X		else if (\$2 == \"Oct\") m=10
X		else if (\$2 == \"Nov\") m=11
X		else if (\$2 == \"Dec\") m=12;
X		print m \"/\" \$3 \"-\" substr(\$4,1,5);exit}"
X# Log the connection to remote site and logfile
Xecho Hello $USER of $site welcome to $ourname on `date`
Xif test -w $LOGFILE
X	then
X	# Log the connection
X	echo $USER $site "(`date | awk \"$logdate\"`-$$)" \
X		OK "(startup)" >> $LOGFILE
Xfi
X#
X# Save some loop invariants in variables to save space
Xextractrfc822='len=length; RSTART=0;
X				for(i=1;i<=len;++i){
X					ch=substr($0,i,1);
X					if(ch == left) RSTART=i;
X					else if (RSTART > 0 && ch == right)
X							RLENGTH=i-RSTART;}
X				p1=substr($0,RSTART+1,RLENGTH-1);
X				p2=substr($0,7,RSTART-8)'
X# Set the special trap to enable the parent to ignore a canceltimeout broadcast
Xtrap ":" $canceltimeoutsignal
X#
X# Now go and look for some work to do.
X# The first thing to do is decide if we are sending or receiving!
X#
X# Lets ask the remote site? In a loop. 
X#  First set timeout timer.
Xeval "$commandwatchdog"
Xecho $E1 "Command: $E2"
Xif read command option
X	then :
X	else command=exit
Xfi
X# now cancel timeout
Xeval "$commandcanicide"
Xwhile true
X	do
X	case "$command" in
X		read | send ) 
X			if test \( -f $LIBDIR/Permissions \) -a \
X			 \( "`echo $perms | fgrep SENDFILES=yes`" = "" \)
X			then 
X				echo "Not permitted to send you files!"
X				$EXIT
X			fi
X			for file in $CMDDIR/C.$site*
X			do
X				# Test if this file exists/is readable?
X				if test ! -r "$file"
X					then continue; fi
X				eval `awk "/S D\.[^ ]*[ 	]D\./{print \\"msgfile=\\" \\\$2}
X				 /S D\.[^ ]*[ 	]X\./{print \\"xqtfile=\\" \\\$2}" $file`
X				# Evaluate on the fly which directory the xqtfile is in
X				# as different versions of uucp put these in different places!
X				# Cannot do this statically as there may be no mail when 
X				# we startup.
X				case "$xqtfile" in
X					D.${site}* ) xqtfile=$DATADIR/$xqtfile ;;
X					D.${ourname}X* ) xqtfile=$usX/$xqtfile ;;
X					D.${ourname}* ) xqtfile=$MSGDIR/$xqtfile ;;
X					* ) xqtfile=$SPOOLDIR/$xqtfile ;;
X				esac
X				# Test if this file exists/is readable?
X				if test ! -r "$xqtfile"
X					then continue; fi
X				to="";from=""
X				eval `awk '
X					/^C rmail /{to=$3}
X					# /^R /{errorsto=$2} # This is not used!
X					END {print "to=" to #,"errorsto=" errorsto
X                        }' \
X						$xqtfile`
X				case "$to" in
X					"" ) # No rmail command - not a mail xfer.
X						 # Skip over it. Later we could reject the request
X						continue ;;
X				esac
X				# Xlate underbar to spaces in destination name
X				to=`echo $to | sed -e 's/_/ /g'`
X				# Evaluate pathname on the fly as before
X				case "$msgfile" in
X					D.${site}* ) msgfile=$DATADIR/$msgfile ;;
X					D.${ourname}* ) msgfile=$MSGDIR/$msgfile ;;
X					*) msgfile=$SPOOLDIR/$msgfile ;;
X				esac
X				# Test if this file exists/is readable?
X				if test ! -r "$msgfile"
X					then continue;	fi
X				# Now log the request to transfer
X				if test -w $LOGFILE
X					then
X					S1="$USER $site (`date | awk \"$logdate\"`-$$) REQUEST"
X					echo "$S1" "(`awk '{print $1,$2,$3,$4;exit}' $file`)" \
X							>> $LOGFILE
X					echo "$S1" "(`awk '{print $1,$2,$3,$4}' $file | tail -1`)" \
X							>> $LOGFILE
X				fi
X				# Examine message headers to find RFC822 headers
X				fromuser="";address="";name="";
X				eval `awk "
X					/^From: [^<]* <[^>]*>/{
X						left=\"<\";right=\">\";
X						$extractrfc822;
X						name=p2;address=p1;exit}
X					/^From: [^\(]* \([^\)]*\)/{
X						left=\"(\";right=\")\";
X						$extractrfc822;
X						name=p1;address=p2;exit}
X					/^From .* .*/{path=\\$2;next}
X					NF == 0 {exit} # Blank line marks end of header
X					END{if (name == \"\")
X							# is this a simple name, or a path?
X							# is this a simple name, or a path?
X							if (path ~ /[!@:]/) print \"address='\" path \"'\"
X							else 		print \"fromuser='\" path \"'\"
X						else print \"name='\" name \"';address='\" address \"'\"}" \
X					$msgfile`
X				case "$fromuser" in
X					"") ;;
X					* )	# Need to get name of user from passwd file!
X						name="`awk -F: \"\\$1 == \\\"$fromuser\\\"\
X									{print \\$5;exit}\" /etc/passwd`"
X						address="$fromuser"	;;
X				esac
X				# Now generate some fake headers with all the info in!
X				echo "Apparently-From: $name <$address>"
X				echo "Apparently-To: $to"
X				# Now send the message in one big burst -
X				#  the remote site better cope!
X				cat $msgfile
X				# We need to mark the end of file in some way!
X				# This may be added to the mail message at the remote
X				# end. It is with QuickMail. What String to choose that will be
X				# readable to Humans!
X				echo "(This message brought to you by Brian Mail)"
X				# Now we may wish to delete the message sent, Ask.
X				eval "$commandwatchdog"
X				echo $E1 "Delete the mail (Y or N): $E2"
X				read command
X				eval "$commandcanicide"
X				case "$command" in
X					"Y" | "y" | "yes" | "YES" | "Yes" )
X						rm -f $msgfile $xqtfile $file ;;
X				esac
X				# Now prime for next command in case still mail read
X				while true
X					do
X					eval "$commandwatchdog"
X					echo $E1 "Command: $E2"
X					if read command option
X						then :
X						else command=exit
X					fi
X					eval "$commandcanicide"
X					case "$command" in
X						read | send ) break ;;
X						exit | bye | quit | logout | stop ) break 3 ;;
X						write | receive ) break 2 ;;
X  						"" ) ;;
X						*) echo Bad Command! ;;
X					esac
X				done
X				# cant trust multilevel breaks and continues!
X				case "$command" in
X					exit | bye | quit | logout | stop ) break 2 ;;
X					write | receive ) break ;;
X				esac
X			done
X			# paranoia!
X			case "$command" in
X				read | send ) echo No more mail! ;;
X				exit | bye | quit | logout | stop ) break ;;
X				write | receive ) continue ;;
X			esac
X			;;
X		write | receive )
X			# here we assume that the external mail system does not generate
X			# RFC822 Headers and we must do it for them!
X			#  A bit rash really. We could get the message first and then
X			#  Scan it for headers and prompt if none found - ugh.
X			#  Note that this script will not talk to itself!!
X			rfcdate="`date | awk '{
X				if (NF == 7) y=$7; else y=$6;
X				print $1 ",",$3,$2,substr(y,3,2),$4,$5;exit}'`"
X			eval "$commandwatchdog"
X			echo $E1 "(Name of recipient): $E2"
X			read name
X			eval "$commandcanicide"
X			case "$name" in
X				"" ) name="Unknown Person" ;;
X			esac
X			eval "$commandwatchdog"
X			echo $E1 "(Recipients address): $E2"
X			read address
X			eval "$commandcanicide"
X			# replace spaces by underlines
X			address=`echo $address | sed -e 's/^[ 	]*//' -e 's/[	 ]/_/g'`
X			# At This point we should probably try and validate the destination
X			# particularly if the address is for a local user.
X			#  It could of course be an alias.
X			# network addresses are a bigger problem.
X			# We need to do a minimal validation to ensure the script isnt
X			# messed up by silly things.
X			case "$address" in
X				[A-Za-z]* ) : OK ;;
X				*) echo Bad Address!
X					command=""
X					continue
X					;;
X			esac
X			eval "$commandwatchdog"
X			echo $E1 "(Name of sender): $E2"
X			read from
X			eval "$commandcanicide"
X			case "$from" in
X				"" ) from="Unknown Person" ;;
X			esac
X			eval "$commandwatchdog"
X			echo $E1 "(Senders address): $E2"
X			read fromaddress
X			eval "$commandcanicide"
X			# replace spaces by underlines
X			fromaddress=`echo $fromaddress | \
X				sed -e 's/^[ 	]*//' -e 's/[	 ]/_/g'`
X			case "$fromaddress" in
X				"" ) fromaddress=nobody ;;
X			esac
X			eval "$commandwatchdog"
X			echo $E1 "Subject: $E2"
X			read subject
X			eval "$commandcanicide"
X			# Construct the header
X			header="From $fromaddress `date | \
X				awk '{if (NF == 7) y=$7; else y=$6;
X				if ($3 <= 9) sp=\" \";
X				print $1,$2,sp $3,substr($4,1,5),$5,y;exit}'` remote from $site"
X			header="${header}${NL}Received: from $site by $ourname "
X			header="${header}with ${mailername}; ${rfcdate}${NL}"
X			header="${header}Date: ${rfcdate}${NL}"
X			header="${header}From: $from <$fromaddress@$site>${NL}"
X			header="${header}To: $name <$address>${NL}"
X			case "$subject" in
X				"" ) ;;
X				* )	header="${header}Subject: ${subject}${NL}" ;;
X			esac
X			eval "$filewatchdog"
X			echo Enter message ending with $eofchar
X			{
X				echo "$header";\
X				cat -
X			 } | $deliveryagent "$address"
X			eval "$filecanicide"
X			# Note that at present we pipe the message to rmail.
X			# We could alternatively construct an X. file and pass this to
X			# uuxqt for processing. May wish to do this if uuxqt is setuid
X			# When rmail is not, or when rmail gets the sender messed up.
X			#
X			# Now log the request
X			if test -w $LOGFILE
X				then
X				echo "$USER $site (`date | awk \"$logdate\"`-$$)" \
X					 "$fromaddress XQT (rmail $address )" >> $LOGFILE
X			fi
X			;;
X		exit | bye | quit | logout | stop )
X			break
X			;;
X		"" )
X			;;
X		* )
X			echo Bad Command!
X			;;
X	esac
X	eval "$commandwatchdog"
X	echo $E1 "Command: $E2"
X	if read command option
X		then :
X		else command=exit
X	fi
X	eval "$commandcanicide"
Xdone
X# Remove lock
Xrm -f $LCKFILE
Xif test ! -w $LOGFILE
X	then
X	exit
Xfi
X# Log the disconnection
Xecho $USER $site "(`date | awk \"$logdate\"`-$$)" \
X		OK "(conversation complete)" >> $LOGFILE
Xexit
X#----------------------------------------------------------------------
X# Method:
X#	The remote site dials in and invokes this script. It performs
X#	permission checks in the same way as uucico to ensure that the
X#	site and user are allowed access to the mail queues. It then
X#	allows the remote site to issue textual commands that specify
X#	the if mail is to be read or written.
X#	When Reading mail the outgoing work queues are scanned and
X#	the uucp command files located. These are examined for mail
X#	for the remote site and if mail is found it is extracted.
X#	Correct headers are generated and the message is transmitted
X#	to the remote site in plain text.
X#	When writing mail the remote site is prompted for information
X#	on the recipient, sender and subject and this information is
X#	used to construct headers. The assumption is that the remote
X#	site is not able to build headers.
X#
X#	Knows about Honeydanber uucp and UKuucp.
X#
X#	To Use:
X# 0. Put this shell somewhere sensible like lib/uucp make it owned by uucp
X#    and uucp read/execute.
X# 1. Add an entry for the remote site in the uucp L.sys or Systems file in 
X#    the normal way. Specify "Never" for the connect times as the remote site 
X#    must dial in. We cannot dial out at present.
X# 2. Create a login for the remote site and specify uucppublic as the home
X#    directory and this script as the login shell. Set the uid and gid for
X#    the login to the the same as uucp so that this script has access to
X#    the uucp spool queues.
X# 3. Add entries to lib/uucp/USERFILE or lib/uucp/Permissions as appropriate.
X# 4. Edit this script to specify the remote site name. It is not parametric yet.
X# 5. Send some mail to the remote site and then login as that site and test it!
X#
X#  System Dependencies:
X#		The set of unix versions recognised and the defaults known
X#		 for those versions may need enhancing for your system.
X#		This includes the path names for the uucp directories
X#		and the signal numbers used for timeouts.
X#		The following piece of shell script can be used to find out
X#		the signal numbers for your system!
X#!/bin/sh -xv
X#
X		# Set number of trap for use in inter-process signalling
X		# The number to use varies with the unix version!
X		# Ultrix= {16}, BSD={16}, V.3={18,19}, Bleasdale={19}
Xtickler=${1-16}
X		# set number of seconds for read timeout
Xtimeout=30
X		# set murder victims. 
X		#	If login shell the victim is whole group
X		#  	else victim is parent pid.
Xvictims=$$
X		# Set parents trap to ignore this signal
Xtrap ":" $tickler
X		# Spawn a child that sleeps for timeout period,
X		#    then exits gracefully if tickled
X		#    or murders its parent or whole family for ignoring it.
X(trap exit $tickler;sleep $timeout;kill -9 $victims)&
X		#  Now do the event that needs a timeout
Xecho -n "Please type something within $timeout seconds:"
Xread x
Xecho "Thank you for typing $x"
X		# If this was sucessfull then ask child to go away
X		#  upon waking.
X		#  This involves tickling the whole process group
X		# with a signal. Some will ignore it (we hope).
Xkill -$tickler 0
X		# wait for child to wake.
Xwait
Xexit
X#
X#  Known problems:
X#		Does not log transfers in SYSLOG
X#       Transfers all files in plain text. Could have an kermit/xmodem option.
X#		If your shell cannot handle a script this big you can use the following
X#		commands to remove comments and white space:
X#!/bin/sh 
Xsed -e 's/		//g' -e '/^	/s/^	//' -e '/^[ 	]*#/D' \
X	-e 's/#[ a-xA-Z\!.,]*$//'
Xexit
X#
X# Revision History:
X#	Aug 15, BCT, 1. fixed typo MSGSDIR -> MSGDIR.
X#	Aug 16, BCT, 2. fixed awk commands to scan ukuucp L.dirs
X#		     as the rules for precedence were not correct.
X#		 3. Parameterised trap signals
X#		 4. replaced some if's by cases for efficiency
X#		 5. added some readonly commands for complete paranoia
X#		 6. removed some fixed assumptions about filenameing
X#		 7. added options for hostname determination
X#		 8. Allow tab for field separator in L.dirs
X#		 9. Checked for more patterns in L.dirs
X#       10. get details of eof char from stty
X#		11. Removed loop invariants to make loop smaller for small shells
X#       12. Used tabs throughout to reduce size
X#       13. Added strip instructions for small sites
X# Aug 23, BCT, 14. Added read timeouts
X#		15. Added transfer logging
X#	16. Checked for eof on command input
X# Aug 24, BCT, 17. Added options for MIPS machines
X# Sep 4, BCT 18. Added basic checks on recipient address to protect system.
X#        BCT 19. Added read timeouts to mail input.
X# Sep 5, BCT 20. Made timeouts optional for dumb systems.
X# Sep 7, BCT 21. tested on XENIX
END_OF_FILE
if test 23308 -ne `wc -c <'uucico.sh'`; then
    echo shar: \"'uucico.sh'\" unpacked with wrong size!
fi
chmod +x 'uucico.sh'
# end of 'uucico.sh'
fi
echo shar: End of shell archive.
exit 0



More information about the Alt.sources mailing list