2011-02-16 11:52:39 +01: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 16:01:44 +11:00
if [ $# -lt 3 ] ; then
2022-04-22 15:34:09 +02:00
cat <<EOF
2011-09-11 08:16:50 +10:00
Usage: test_net_registry_roundtrip.sh SCRIPTDIR SERVERCONFFILE NET CONFIGURATION RPC
2011-02-21 16:01:44 +11:00
EOF
2022-04-22 15:34:09 +02:00
exit 1
2011-02-21 16:01:44 +11:00
fi
SCRIPTDIR = " $1 "
SERVERCONFFILE = " $2 "
2011-09-11 08:16:50 +10:00
NET = " $3 "
CONFIGURATION = " $4 "
RPC = " $5 "
2011-02-21 16:01:44 +11:00
2011-09-11 08:16:50 +10:00
NET = " $VALGRIND ${ NET } $CONFIGURATION "
2011-02-16 11:52:39 +01:00
2022-04-22 15:34:09 +02:00
if test " x ${ RPC } " = "xrpc" ; then
2011-08-10 11:58:25 +03:00
NETCMD = " ${ NET } -U ${ USERNAME } % ${ PASSWORD } -I ${ SERVER_IP } rpc "
2011-02-16 11:52:39 +01:00
else
2011-08-10 11:58:25 +03:00
NETCMD = " ${ NET } "
2011-02-16 11:52:39 +01:00
fi
2022-04-22 15:34:09 +02:00
incdir = $( dirname $0 ) /../../../testprogs/blackbox
2011-02-16 11:52:39 +01:00
. $incdir /subunit.sh
failed = 0
2013-09-22 03:06:12 +02:00
#
# List of parameters to skip when importing configuration files:
# They are forbidden in the registry and would lead import to fail.
#
2011-02-16 11:52:39 +01:00
SED_INVALID_PARAMS = " {
2013-09-22 03:03:41 +02:00
s/state directory/; & /g
2011-02-16 11:52:39 +01:00
s/lock directory/; & /g
2011-03-05 00:54:28 +01:00
s/lock dir/; & /g
2013-09-22 03:06:12 +02:00
s/config backend/; & /g
s/include/; & /g
2011-02-16 11:52:39 +01:00
} "
REGPATH = "HKLM\Software\Samba"
2022-04-22 15:34:09 +02:00
conf_roundtrip_step( )
{
echo " CMD: $* " >>$LOG
$@ 2>>$LOG
RC = $?
echo " RC: $RC " >>$LOG
test " x $RC " = "x0" || {
echo " ERROR: $@ failed (RC= $RC ) " | tee -a $LOG
}
return $RC
# echo -n .
2011-02-16 11:52:39 +01:00
}
2011-02-21 12:48:15 +01:00
LOGDIR_PREFIX = "conf_roundtrip"
2011-02-16 11:52:39 +01:00
conf_roundtrip( )
2012-06-25 17:12:35 +02:00
(
2022-04-22 15:34:09 +02:00
DIR = $( mktemp -d ${ PREFIX } /${ LOGDIR_PREFIX } _XXXXXX)
LOG = $DIR /log
echo conf_roundtrip $1 >$LOG
sed -e " $SED_INVALID_PARAMS " $1 >$DIR /conf_in
conf_roundtrip_step $NETCMD conf drop
test " x $? " = "x0" || {
return 1
}
test -z " $( $NETCMD conf list) " 2>>$LOG
if [ " $? " = "1" ] ; then
echo "ERROR: conf drop failed" | tee -a $LOG
return 1
fi
conf_roundtrip_step $NETCMD conf import $DIR /conf_in
test " x $? " = "x0" || {
return 1
}
conf_roundtrip_step $NETCMD conf list >$DIR /conf_exp
test " x $? " = "x0" || {
return 1
}
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 $NETCMD -d10 registry export $REGPATH $DIR /conf_exp.reg
test " x $? " = "x0" || {
return 1
}
conf_roundtrip_step $NETCMD conf drop
test " x $? " = "x0" || {
return 1
}
test -z " $( $NETCMD conf list) " 2>>$LOG
if [ " $? " = "1" ] ; then
echo "ERROR: conf drop failed" | tee -a $LOG
return 1
fi
conf_roundtrip_step $NETCMD registry import $DIR /conf_exp.reg
test " x $? " = "x0" || {
return 1
}
conf_roundtrip_step $NETCMD conf list >$DIR /conf_out
test " x $? " = "x0" || {
return 1
}
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 $NETCMD registry export $REGPATH $DIR /conf_out.reg
test " x $? " = "x0" || {
return 1
}
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
2012-06-25 17:12:35 +02:00
)
2011-02-16 11:52:39 +01:00
2011-04-27 20:29:16 +10:00
CONF_FILES = $SERVERCONFFILE
2011-02-16 11:52:39 +01:00
2011-02-21 12:48:15 +01:00
# remove old logs:
2022-04-22 15:34:09 +02:00
for OLDDIR in $( find ${ PREFIX } -type d -name " ${ LOGDIR_PREFIX } _* " ) ; do
2011-02-21 12:48:15 +01:00
echo " removing old directory ${ OLDDIR } "
rm -rf ${ OLDDIR }
done
2022-04-22 15:34:09 +02:00
for conf_file in $CONF_FILES ; do
testit " conf_roundtrip $conf_file " \
conf_roundtrip $conf_file ||
failed = $( expr $failed + 1)
2011-02-16 11:52:39 +01:00
done
testok $0 $failed