2011-02-16 13:52:39 +03:00
#!/bin/sh
#
# Blackbox test for net conf/registry roundtrips.
#
# Copyright (C) 2010 Gregor Beck <gbeck@sernet.de>
# Copyright (C) 2011 Michael Adam <obnox@samba.org>
2011-02-21 08:01:44 +03:00
if [ $# -lt 3 ] ; then
cat <<EOF
Usage: test_net_registry_roundtrip.sh SCRIPTDIR SERVERCONFFILE CONFIGURATION
EOF
exit 1;
fi
SCRIPTDIR = " $1 "
SERVERCONFFILE = " $2 "
CONFIGURATION = " $3 "
2011-02-16 13:52:39 +03:00
NET = " $VALGRIND ${ NET :- $BINDIR /net } $CONFIGURATION "
if test " x ${ RPC } " = "xrpc" ; then
NETREG = " ${ NET } -U ${ USERNAME } % ${ PASSWORD } -I ${ SERVER_IP } rpc registry "
else
NETREG = " ${ NET } registry "
fi
incdir = ` dirname $0 ` /../../../testprogs/blackbox
. $incdir /subunit.sh
failed = 0
SED_INVALID_PARAMS = " {
s/lock directory/; & /g
2011-03-05 02:54:28 +03:00
s/lock dir/; & /g
2011-02-16 13:52:39 +03:00
s/modules dir/; & /g
s/logging/; & /g
s/status/; & /g
s/logdir/; & /g
s/read prediction/; & /g
s/mkprofile/; & /g
s/valid chars/; & /g
s/timesync/; & /g
s/sambaconf/; & /g
s/logtype/; & /g
s/servername/; & /g
2011-03-05 02:55:27 +03:00
s/postscript/; & /g
2011-02-16 13:52:39 +03:00
} "
REGPATH = "HKLM\Software\Samba"
conf_roundtrip_step( ) {
2011-03-05 01:12:08 +03:00
echo " CMD: $* " >>$LOG
2011-02-16 13:52:39 +03:00
$@ 2>>$LOG
2011-03-05 01:12:08 +03:00
RC = $?
echo " RC: $RC " >> $LOG
test " x $RC " = "x0" || {
echo " ERROR: $@ failed (RC= $RC ) " | tee -a $LOG
}
return $RC
2011-02-16 13:52:39 +03:00
# echo -n .
}
2011-02-21 14:48:15 +03:00
LOGDIR_PREFIX = "conf_roundtrip"
2011-02-16 13:52:39 +03:00
conf_roundtrip( )
{
2011-02-28 19:06:01 +03:00
local DIR = $( mktemp -d ${ PREFIX } /${ LOGDIR_PREFIX } _XXXX)
2011-02-16 13:52:39 +03:00
local LOG = $DIR /log
echo conf_roundtrip $1 > $LOG
sed -e " $SED_INVALID_PARAMS " $1 >$DIR /conf_in
conf_roundtrip_step $NET conf drop
2011-03-05 01:17:02 +03:00
test " x $? " = "x0" || {
return 1
}
2011-02-16 13:52:39 +03:00
test -z " $( $NET conf list) " 2>>$LOG
if [ " $? " = "1" ] ; then
echo "ERROR: conf drop failed" | tee -a $LOG
return 1
fi
conf_roundtrip_step $NET conf import $DIR /conf_in
2011-03-05 01:17:02 +03:00
test " x $? " = "x0" || {
return 1
}
2011-02-16 13:52:39 +03:00
conf_roundtrip_step $NET conf list > $DIR /conf_exp
2011-03-05 01:17:02 +03:00
test " x $? " = "x0" || {
return 1
}
2011-02-16 13:52:39 +03:00
grep "\[global\]" $DIR /conf_exp >/dev/null 2>>$LOG
if [ " $? " = "1" ] ; then
echo "ERROR: conf import => conf export failed" | tee -a $LOG
return 1
fi
conf_roundtrip_step $NET -d10 registry export $REGPATH $DIR /conf_exp.reg
2011-03-05 01:17:02 +03:00
test " x $? " = "x0" || {
return 1
}
2011-02-16 13:52:39 +03:00
conf_roundtrip_step $NET conf drop
2011-03-05 01:17:02 +03:00
test " x $? " = "x0" || {
return 1
}
2011-02-16 13:52:39 +03:00
test -z " $( $NET conf list) " 2>>$LOG
if [ " $? " = "1" ] ; then
echo "ERROR: conf drop failed" | tee -a $LOG
return 1
fi
conf_roundtrip_step $NET registry import $DIR /conf_exp.reg
2011-03-05 01:17:02 +03:00
test " x $? " = "x0" || {
return 1
}
2011-02-16 13:52:39 +03:00
conf_roundtrip_step $NET conf list >$DIR /conf_out
2011-03-05 01:17:02 +03:00
test " x $? " = "x0" || {
return 1
}
2011-02-16 13:52:39 +03:00
diff -q $DIR /conf_out $DIR /conf_exp >> $LOG
if [ " $? " = "1" ] ; then
echo "ERROR: registry import => conf export failed" | tee -a $LOG
return 1
fi
conf_roundtrip_step $NET registry export $REGPATH $DIR /conf_out.reg
2011-03-05 01:17:02 +03:00
test " x $? " = "x0" || {
return 1
}
2011-02-16 13:52:39 +03:00
diff -q $DIR /conf_out.reg $DIR /conf_exp.reg >>$LOG
if [ " $? " = "1" ] ; then
echo "Error: registry import => registry export failed" | tee -a $LOG
return 1
fi
rm -r $DIR
}
2011-03-05 02:50:21 +03:00
CONF_FILES = ${ CONF_FILES :- $( find $SRCDIR / -name '*.conf' | grep -v examples/logon | xargs grep -l "\[global\]" ) }
2011-02-16 13:52:39 +03:00
2011-02-21 14:48:15 +03:00
# remove old logs:
for OLDDIR in $( find ${ PREFIX } -type d -name " ${ LOGDIR_PREFIX } _* " ) ; do
echo " removing old directory ${ OLDDIR } "
rm -rf ${ OLDDIR }
done
2011-02-16 13:52:39 +03:00
for conf_file in $CONF_FILES
do
testit " conf_roundtrip $conf_file " \
conf_roundtrip $conf_file \
|| failed = ` expr $failed + 1`
done
testok $0 $failed