Hello
sometime ago I asked about nis+ client support on Tru64 5.0.
It seems is not even planned, so I had to write a small script
to update Tru64 files from nis+ server data:
-8<------------------------------------------------------------------------
#!/bin/ksh
# <spd_at_daphne.cps.unizar.es>
# Thu May 17 12:25:54 MEST 2001
#
# Dump NIS+ entries to Tru64 5.0 C2 databases.
#
# Server: Solaris 8 NIS+ with ssh installed
# Client: Tru64 5.0 with sshd installed
# This script will:
#
# Dump group.org_dir with gid >= 1000 && gid < 60000 to /etc/group
# Dump auto_home.org_dir to /etc/auto_home
# Dump passwd.org_dir with uid >= 1000 && uid < 60000 to /etc/passwd
# Dump passwd.org_dir with uid >= 1000 && uid < 60000 to |edauth
# it will keep "system" and not modified entries
# it won't honour lastchg/min/max/warn/inactive/expire solaris flags
SU=
RSH=ssh
CLIENT=foo.example.com
umask 077
mkdir /root/nis 2>/dev/null
set -e
cd /root/nis
set +e
stripgids()
{
:>$1
:>$2
OIFS="$IFS"
IFS=":"
while read group password gid members
do
if [ "$password" = "" ]
then
password="*"
fi
if [ $gid -ge 1000 ]
then
if [ $gid -lt 60000 ]
then
echo "$group:$password:$gid:$members" >> $2
continue
fi
fi
echo "$group:$password:$gid:$members" >> $1
done
IFS="$OIFS"
}
stripuids()
{
:>$1
:>$2
:>$3
OIFS="$IFS"
IFS=":"
while read uname pass uid gid gcos home shell \
lastchg min max warn inactive expire flag
do
case $pass in
?????????????)
cpass="$pass"
pass='*'
;;
*Nologin)
;;
"*")
;;
*)
# if expr expr "$pass" : '[a-z,A-Z,0-9,\./]\{13\}' >/dev/null 2>&1
# then
# pass='*'
# else
pass='*Nologin'
# fi
;;
esac
if [ $uid -ge 1000 ]
then
if [ $uid -lt 60000 ]
then
echo "$uname:$pass:$uid:$gid:$gcos:$home:$shell" >> $2
echo "$uname:$uid:$cpass" >> $3
continue
fi
fi
echo "$uname:$pass:$uid:$gid:$gcos:$home:$shell" >> $1
done
IFS="$OIFS"
}
# group.org_dir
$SU niscat group.org_dir | sort -t : +2n |\
stripgids group.sys group.nis
$SU $RSH $CLIENT -l root cat /etc/group | sort -t : +2n |\
stripgids group.t64.sys group.t64.nis
# Report
if cmp -s group.nis group.t64.nis
then
echo "#### group is up to date"
else
echo "#### Deleted/Modified groups:"
comm -13 group.nis group.t64.nis
echo "#### New/Modified groups:"
comm -23 group.nis group.t64.nis
#echo "#### Old groups:"
#comm -12 group.nis group.t64.nis
# create new True64 group file:
cat group.t64.sys group.nis | $SU $RSH $CLIENT -l root "cat > /etc/group"
fi
# auto_home
$SU niscat auto_home.org_dir > auto_home.nis
$SU $RSH $CLIENT -l root cat /etc/auto_home > auto_home.t64
if cmp -s auto_home.nis auto_home.t64
then
echo "#### auto_home is up to date"
else
cat auto_home.nis | $SU $RSH $CLIENT -l root "cat > /etc/auto_home"
fi
# passwd
# passwd.org_dir
$SU niscat passwd.org_dir | sort -t : +2n |\
stripuids passwd.sys passwd.nis /dev/null
$SU $RSH $CLIENT -l root cat /etc/passwd | sort -t : +2n |\
stripuids passwd.t64.sys passwd.t64.nis /dev/null
# Report
if cmp -s passwd.nis passwd.t64.nis
then
echo "#### passwd is up to date"
else
echo "#### Deleted/Modified passwd:"
comm -13 passwd.nis passwd.t64.nis
echo "#### New/Modified passwd:"
comm -23 passwd.nis passwd.t64.nis
#echo "#### Old passwd:"
#comm -12 passwd.nis passwd.t64.nis
# create new True64 passwd file:
cat passwd.t64.sys passwd.nis |\
$SU $RSH $CLIENT -l root "
while test -d /etc/ptmp
do
echo password file busy - waiting
sleep 5
done
mkdir /etc/ptmp || ( echo ERROR: lock failed; exit 1) && \
( cat > /etc/passwd
rmdir /etc/ptmp || echo WARNING: rmdir failed )
"
fi
# auth
$SU $RSH $CLIENT -l root /usr/tcb/bin/edauth -g > shadow.t64
perl -pe 's/\\\n//' shadow.t64 |\
sed -e 's/^\([^:]*\):.*:u_id#\([0-9]*\):u_pwd=\([^:]*\):.*$/\1 \2 \3/' |\
while read uname uid pass
do
if [ $uid -ge 1000 ]
then
if [ $uid -lt 60000 ]
then
echo "$uname:$uid:$pass"
fi
fi
done | sort -t : +1n > shadow.t64.nis
# passwd.org_dir
$SU niscat passwd.org_dir | tee passwd.org_dir | sort -t : +2n |\
stripuids passwd.sys passwd.nis shadow.nis
# Report
if cmp -s shadow.nis shadow.t64.nis
then
echo "#### shadow is up to date"
else
echo "#### Deleted/Modified shadow:"
comm -13 shadow.nis shadow.t64.nis
echo "#### New/Modified shadow:"
comm -23 shadow.nis shadow.t64.nis
#echo "#### Old shadow:"
#comm -12 shadow.nis shadow.t64.nis
# create new True64 shadow file:
echo "#### Removing entries"
comm -13 shadow.nis shadow.t64.nis | awk -F: '{print $1}' |\
$SU $RSH $CLIENT -l root xargs /usr/tcb/bin/edauth -vr
echo "#### Adding entries"
comm -23 shadow.nis shadow.t64.nis | awk -F: '{print $1}' |\
while read nuname
do
OIFS="$IFS"
IFS=":"
egrep "^$nuname:" passwd.org_dir |\
while read uname pass uid gid gcos home shell \
lastchg min max warn inactive expire flag
do
echo "$uname:u_name=$uname::u_id#$uid:u_pwd=$pass:u_succhg#`time_t 2>/dev/null`:\\"
echo " :u_pwdict=:u_oldcrypt#2:u_retired_at_:u_lock_at_:\\"
echo " :chkent:"
done |\
$SU $RSH $CLIENT -l root /usr/tcb/bin/edauth -s -v -C -L
IFS="$OIFS"
done
fi
# You may want to remove /root/nis
# rm -rf /root/nis
exit 0
- time_t.c ----------------------------------------------------------------
/*
* time_t.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <time.h>
main(int argc, char **argv)
{
time_t timer;
if ( argc > 1 )
{
timer = strtol( argv[optind], (char **)NULL, 0 );
}
else
{
time(&timer);
}
fprintf(stdout, "%d\n", timer ); fflush(stdout);
fprintf(stderr, "%s", ctime(&timer));
exit(0);
}
---------------------------------------------------------------------------
-8<------------------------------------------------------------------------
comments?
--
finger spd_at_gtc1.cps.unizar.es for PGP / So be easy and free
.mailcap tip of the day: / when you're drinking with me
application/ms-tnef; cat '%s' > /dev/null / I'm a man you don't meet every day
text/x-vcard; cat '%s' > /dev/null / (the pogues)
Received on Fri May 18 2001 - 08:59:17 NZST