[net.sources] Full-name database for sendmail from passwd files

andrew@stc.UUCP (Andrew Macpherson) (06/07/85)

This is one of those things which everyone has a go at - making a
full-name / forwarding database to use with sendmail.

The problem:  a multi-host site connected only by UUCP, users ( apart
from the admin group ) on one m/c only.  Requirement, generate an
aliases database to do full name aliasing and forwarding to the
appropriate m/c.

My answer "falias" is enclosed, it assumes BSD "finger" type entries, 
( & is expanded ), also assumes uids in the range 0-9 are for system
admin types who will have their .forwards, or uucp/news type users.

A leading # in the password field indicates a "dead user" as does a
password field of "*".  The first sed script strips out some other
undesirables on my system(s), as well as doing some tidying up.

In use list the sites is the order of precedance, as the users on the
first site will "clobber" those with the same login on the second,
etc.

I hope this saves someone a few hours work, if you like it, let me
know, I also read flames until they become tedious.

-------------------- Cut Here ----------------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	falias
# This archive created: Thu Jun  6 22:57:04 1985
export PATH; PATH=/bin:$PATH
echo shar: extracting "'falias'" '(2844 characters)'
if test -f 'falias'
then
	echo shar: will not over-write existing file "'falias'"
else
sed 's/^	X//' << \SHAR_EOF > 'falias'
	X#!/bin/sh
	X#   Shell script to create a forwarding full name database
	X#   for use with sendmail.
	XALIASES=${ALIASES-/usr/lib/aliases}
	X
	Xif [ $# -lt 1 ]
	Xthen
	X	echo "Usage:	"$0 "files
	X
	X	Where files are passwd files in the current directory
	X	named after their host systems: eg
	X
	X	"$0 `hostname` "host2 host3
	X
	X	where "`hostname`"'s users are prefered to host2's etc
	X"
	X	exit 1
	Xfi
	X
	Xfor i in $*
	Xdo
	X	if [ ! -f $i -o ! -r $i ] 
	X	then
	X		echo ${0}: $i " - no file."
	X		exit 1
	X	fi
	Xdone
	X
	Xif [ ! -w $ALIASES ]
	Xthen
	X	echo ${0}: $ALIASES " - not writable."
	X	exit 1
	Xfi
	X
	Xawk -F: ' BEGIN { sysname = "xxx" ; count = 0 }
	X	( $2 < "#" || $2 >= "$" ) && $7 ~ /sh/ && $2 != "*" {
	X	if ( sysname != FILENAME ) {
	X		sysname = FILENAME
	X		count ++
	X	}
	X	if ( $3 >= 10 || $3 == 2 || $3 == 3 ) {
	X		printf "%s:%d@%s@%s.UUCP\n", $1, count, $1, FILENAME
	X		printf "%s:%s\n", $5, $1 }
	X	}'    $*                         | \
	Xsed -e 's/(.*)//g' \
	X	-e 's/ /./g' \
	X	-e 's/\.\.*/./g' \
	X	-e 's/[\.]*,.*:/:/' \
	X	-e 's/\.\.*:/:/' \
	X	-e '/^:/d' \
	X	-e '/:field/d' \
	X	-e '/[Ff]actory/d' \
	X	-e '/[Ww]ho/d' \
	X	-e '/^field:/d' \
	X	-e '/demosmf/d' \
	X	-e '/games/d' \
	X	-e '/guest/d' \
	X	-e '/hack/d' \
	X	-e '/jes/d' \
	X	-e '/jokes/d' \
	X	-e '/news/d' \
	X	-e '/qman/d' \
	X	-e '/ucdemo/d' \
	X	-e '/updates/d' \
	X	-e '/workshop/d' \
	X	-e s/\'//g          | \
	X	sort -u | \
	Xawk -F: 'BEGIN { last = xxx } 
	X	{ if ( $1 != last && $1 != $2 ) print $0; last = $1 }' | \
	X	tr A-Z a-z > /tmp/nm$$
	X
	X#	We have disposed of duplicates, and unwanted users
	X#	now expand those "&"s in the finger entry
	X
	Xawk -F: ' /&/ { printf "s/%s/%s:%s/\n", $2, $1, $2}' /tmp/nm$$  > /tmp/spt
	Xawk -F: ' /&/ {	print $2 }' /tmp/nm$$ > /tmp/nms
	Xecho "s/ //g" >> /tmp/spt
	Xsed -f /tmp/spt /tmp/nms > /tmp/na$$
	Xgrep -v '&' /tmp/nm$$ >> /tmp/na$$
	Xrm /tmp/spt /tmp/nms /tmp/nm$$
	X
	X#	Now make as many real name entries as we reasonably can
	X
	Xsed -e 's/uucp$/UUCP/' \
	X	-e '/uucp/d' \
	X	-e '/:[ 	]*$/d' \
	X	-e '/^[0-9]*:/d' \
	X	-e '/./p' \
	X	-e 's/^[a-z]\.\([a-z][a-z][a-z]*[\.a-z]*:\)/\1/p' \
	X	-e 's/\..\(\.[^\.]*:\)/\1/p' \
	X	-e 's/\.\([a-z]\)[a-z]*\.\([a-z]*:\)/.\1.\2/p' \
	X	-e 's/\..\(\.[^\.]*:\)/\1/p' \
	X	-e 's/\.\([a-z]\)[a-z]*\.\([^\.]\.[^.]*:\)/.\1.\2/p' \
	X	-e 's/\([a-z]\)[a-z]*\.\(.*:\)/\1.\2/gp' \
	X	-e 's/\..\(\.[^\.]*:\)/\1/p' \
	X	-e 's/\..\(\.[^\.]*:\)/\1/p' \
	X	-e 's/.*\.\(.*:\)/\1/p' -e '/./d' /tmp/na$$ | \
	X	sort -u | \
	X	awk -F: 'BEGIN { last = XXX } 
	X	{ if ( $1 != last && $1 != $2 && $2 >= " " )
	X		printf "%s: %s\n", $1, $2; last = $1 }' | \
	X	sed -e '/: 1@/d' -e 's/: [0-9]*@/: /' -e '/^[0-9]/d' > /tmp/nm$$
	X
	X#	And get rid of the temporary files
	X
	Xrm /tmp/na$$
	X
	X#	Now update $ALIASES
	X
	Xfgrep -s "DO NOT DELETE THIS LINE" $ALIASES || \
	Xecho "# DO NOT DELETE THIS LINE
	X
	X" >> $ALIASES
	X
	Xed - $ALIASES << E-O-F
	X/DO NOT DELETE THIS LINE/+1
	X.,\$d
	X\$r /tmp/nm$$
	Xw
	Xq
	XE-O-F
	X
	Xrm /tmp/nm$$
	Xecho $ALIASES "updated, now rebuilding database, might be slow"
	Xnewaliases
SHAR_EOF
if test 2844 -ne "`wc -c < 'falias'`"
then
	echo shar: error transmitting "'falias'" '(should have been 2844 characters)'
fi
chmod +x 'falias'
fi # end of overwriting check
#	End of shell archive
exit 0
-- 
Regards,
	Andrew Macpherson.	<andrew@stc.UUCP>
	{creed, datlog, idec, iclbra, root44, stl, ukc}!stc!andrew