Full name database from passwd files - update
Andrew Macpherson
andrew at stc.UUCP
Wed Aug 21 20:57:17 AEST 1985
A number of you were kind enough to say you would be using my full name
database generation script. After a some months use, I've found a few
bugs with name collisions, and a few innacuracies in the resolution.
Here then is the updated script.
In my original posting I introduced the script thus:
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: Wed Aug 21 09:53:54 1985
export PATH; PATH=/bin:$PATH
echo shar: extracting "'falias'" '(3379 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
Xif [ $# -ge 16 ]
Xthen
X echo "$0: too many arguments"
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/ || $7 == "" ) && $2 != "*" {
X if ( sysname != FILENAME ) {
X sysname = FILENAME
X count ++
X }
X if ( $3 >= 10 || $3 == 2 || $3 == 3 ) {
X if ( count > 1 ) {
X printf "%s:%x@%s@%s\n", $1, count, $1, FILENAME
X printf "%s:%x@%s@%s\n", $5, count, $1, FILENAME
X } else {
X printf "%s:1@%s\n", $5, $1
X printf "%s:1@%s\n", $1, $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 tr A-Z a-z | \
X sort -u | \
Xawk -F: 'BEGIN { last = xxx }
X { if ( $1 != last ) {
X print $0
X last = $1 } }' > /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/\n", $2, $1, $2}' /tmp/nm$$ | \
X sed -e 's;^[0-9a-f]@;s/;' -e 's;@[^/]*\(/.*/\);\1;' > /tmp/spt
Xawk -F: ' /&/ { print $2 }' /tmp/nm$$ | \
X sed -e 's/^[0-9a-f]@//' -e 's/@.*//' > /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 '/uucp/d' \
X -e '/^[^\"]*\"[^\"]*$/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/\"[^\"]*\"\.*//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 sed -e 's/:[0-9a-f]*@/:/' -e '/^[0-9]/d' | \
X awk -F: 'BEGIN { last = "XXX" ; left = "ERROR" }
X { if ( $1 != last ) {
X if ( left != "ERROR" && right > " " )
X printf "%s: %s\n", left, right;
X left = $1
X right = $2
X }
X if ( $1 == $2 )
X left = "ERROR"
X last = $1 }
X END { if ( left != "ERROR" && right > " " )
X printf "%s: %s\n", left, right;
X }' > /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
Xecho "" >> $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$$
X
Xecho $ALIASES "updated, now rebuilding database, might be slow"
X
Xnewaliases
Xexit 0
SHAR_EOF
if test 3379 -ne "`wc -c < 'falias'`"
then
echo shar: error transmitting "'falias'" '(should have been 3379 characters)'
fi
chmod +x 'falias'
fi # end of overwriting check
# End of shell archive
exit 0
--
Regards,
Andrew Macpherson. <andrew at stc.UUCP>
{creed, datlog, idec, iclbra, iclkid, root44, stl, ukc}!stc!andrew
More information about the Comp.sources.unix
mailing list