2011-11-02 23:05:24 +04:00
#!/bin/sh
#
# Test for registry upgrades.
#
# Copyright (C) 2011 Björn Baumbach <bb@sernet.de>
if [ $# -lt 2 ] ; then
echo "Usage: test_registry_upgrade.sh NET DBWRAP_TOOL"
exit 1
fi
SCRIPT_DIR = $( dirname $0 )
BASE_DIR = " ${ SCRIPT_DIR } /../../.. "
NET = " $1 "
2013-01-15 14:22:49 +04:00
DBWRAP_TOOL = " $2 --persistent "
2011-11-02 23:05:24 +04:00
DATADIR = " ${ BASE_DIR } /testdata/samba3 "
WORKSPACE = " ${ PREFIX } /registry_upgrade "
CONFIG_FILE = " ${ WORKSPACE } /smb.conf "
CONFIGURATION = " --configfile= ${ CONFIG_FILE } "
NETCMD = " $NET $CONFIGURATION "
incdir = " ${ BASE_DIR } /testprogs/blackbox "
. $incdir /subunit.sh
failed = 0
REGPATH = "HKLM\Software\Samba"
LOGDIR_PREFIX = "registry_upgrade"
registry_check( )
2012-06-25 23:21:31 +04:00
(
CHECKNO = " $1 "
CHECKDIFF = " $2 "
REGVER = ""
ALLOWEDERR = "INFO: version =|Check database:|overwrite registry format version 0 with 1|no INFO/version found"
2011-11-02 23:05:24 +04:00
test " x $CHECKNO " = "x0" && {
2011-11-04 02:59:55 +04:00
REGVER = "--reg-version=1"
2011-11-02 23:05:24 +04:00
}
2011-11-04 02:59:55 +04:00
echo " Registry check $CHECKNO " | tee -a $LOG
2011-11-02 23:05:24 +04:00
CHECK = " $( $NETCMD registry check $REGVER 2>& 1) "
RC = $?
2011-11-04 02:59:55 +04:00
ERRORSTR = " $( echo " $CHECK " | grep -vE $ALLOWEDERR ) "
2011-11-02 23:05:24 +04:00
test " x $RC " = "x0" || {
2011-11-04 02:59:55 +04:00
echo " upgrade check $CHECKNO failed: " | tee -a $LOG
2011-11-02 23:05:24 +04:00
return 1
}
test " x $ERRORSTR " = "x" || {
2011-11-04 02:59:55 +04:00
echo " upgrade check $CHECKNO failed: " | tee -a $LOG
echo " reason: $CHECK " | tee -a $LOG
return 1
2011-11-02 23:05:24 +04:00
}
test " x $CHECKDIFF " = "xcheckdiff" && {
2011-11-04 02:59:55 +04:00
$NETCMD registry export 'HKLM' $WORKSPACE /export_${ CHECKNO } .reg >> $LOG
test " x $? " = "x0" || {
echo "Error: 'net registry export HKLM' failed" | tee -a $LOG
}
diff -q $WORKSPACE /export_0.reg $WORKSPACE /export_${ CHECKNO } .reg >> $LOG
2011-11-02 23:05:24 +04:00
test " x $? " = "x0" || {
2011-11-04 02:59:55 +04:00
echo " Error: $WORKSPACE /export_0.reg differs from $WORKSPACE /export_ ${ CHECKNO } .reg " | tee -a $LOG
2011-11-02 23:05:24 +04:00
return 1
}
}
return 0
2012-06-25 23:21:31 +04:00
)
2011-11-02 23:05:24 +04:00
registry_upgrade( )
{
2011-11-04 02:59:55 +04:00
echo registry_upgrade $1 | tee -a $LOG
2011-11-02 23:05:24 +04:00
cp -v $DATADIR /registry.tdb $WORKSPACE /registry.tdb >> $LOG 2>& 1
REGISTRY = " ${ WORKSPACE } /registry.tdb "
test -e $REGISTRY || {
2011-11-04 02:59:55 +04:00
echo "Error: Database file not available" | tee -a $LOG
2011-11-02 23:05:24 +04:00
return 1
}
# create config file
echo '[global]' > ${ CONFIG_FILE }
echo " state directory = ${ WORKSPACE } " >> ${ CONFIG_FILE }
2016-11-15 12:58:48 +03:00
echo " private directory = ${ WORKSPACE } " >> ${ CONFIG_FILE }
echo " lock directory = ${ WORKSPACE } " >> ${ CONFIG_FILE }
2011-11-02 23:05:24 +04:00
# set database INFO/version to 1
#$DBWRAP_TOOL $REGISTRY store 'INFO/version' uint32 1
#test "x$?" = "x0" || {
# echo "Error: Can not set INFO/version" >> $LOG
# return 1
#}
# check original registry.tdb
2011-11-04 02:59:55 +04:00
echo " $REGISTRY " | tee -a $LOG
2011-11-02 23:05:24 +04:00
registry_check 0
test " x $? " = "x0" || {
2011-11-04 02:59:55 +04:00
echo "Error: initial 'registry_check 0' failed" | tee -a $LOG
2011-11-02 23:05:24 +04:00
return 1
}
# trigger upgrade
2011-11-04 02:59:55 +04:00
echo " $NETCMD registry enumerate $REGPATH " >> $LOG
$NETCMD registry enumerate $REGPATH >> $LOG
2011-11-02 23:05:24 +04:00
test " x $? " = "x0" || {
2011-11-04 02:59:55 +04:00
echo " Error: 'net registry enumerate $REGPATH ' failed " | tee -a $LOG
2011-11-02 23:05:24 +04:00
return 1
}
# check upgraded database
registry_check 1
test " x $? " = "x0" || {
2011-11-04 02:59:55 +04:00
echo "Error: 'registry_check 1' after upgrade failed" | tee -a $LOG
2011-11-02 23:05:24 +04:00
return 1
}
# export database for diffs
2011-11-04 02:59:55 +04:00
$NETCMD registry export 'HKLM' $WORKSPACE /export_0.reg | tee -a $LOG
test " x $? " = "x0" || {
echo "Error 'net registry export' failed" | tee -a $LOG
return 1
}
2011-11-02 23:05:24 +04:00
# remove version string
2011-11-04 02:59:55 +04:00
$DBWRAP_TOOL $REGISTRY delete INFO/version | tee -a $LOG
2011-11-02 23:05:24 +04:00
test " x $? " = "x0" || {
2011-11-04 02:59:55 +04:00
echo "Error: Can not remove INFO/version key from registry" | tee -a $LOG
2011-11-02 23:05:24 +04:00
return 1
}
# trigger upgrade on upgraded database
2011-11-04 02:59:55 +04:00
echo " $NETCMD registry enumerate $REGPATH " >> $LOG
2011-11-02 23:05:24 +04:00
$NETCMD registry enumerate $REGPATH >> $LOG 2>& 1
test " x $? " = "x0" || {
2011-11-04 02:59:55 +04:00
echo " Error: 'net registry enumerate $REGPATH ' failed " | tee -a $LOG
2011-11-02 23:05:24 +04:00
return 1
}
# check upgraded database again
registry_check 2 checkdiff
test " x $? " = "x0" || {
2011-11-04 02:59:55 +04:00
echo "Error: 'registry_check 2' after upgrade failed" | tee -a $LOG
2011-11-02 23:05:24 +04:00
return 1
}
# set database INFO/version to version 2
$DBWRAP_TOOL $REGISTRY store 'INFO/version' uint32 2
test " x $? " = "x0" || {
2011-11-04 02:59:55 +04:00
echo "Error: Can not set INFO/version" | tee -a $LOG
2011-11-02 23:05:24 +04:00
return 1
}
# trigger upgrade
2011-11-04 02:59:55 +04:00
$NETCMD registry enumerate $REGPATH >> $LOG
2011-11-02 23:05:24 +04:00
test " x $? " = "x0" || {
2011-11-04 02:59:55 +04:00
echo " Error: 'net registry enumerate $REGPATH ' failed " | tee -a $LOG
2011-11-02 23:05:24 +04:00
return 1
}
# check upgraded database again
registry_check 3 checkdiff
test " x $? " = "x0" || {
2011-11-04 02:59:55 +04:00
echo "Error: 'registry_check 3' after upgrade failed" | tee -a $LOG
2011-11-02 23:05:24 +04:00
return 1
}
}
# remove old logs
for OLDDIR in $( find ${ PREFIX } -type d -name " ${ LOGDIR_PREFIX } _* " ) ; do
echo " removing old directory ${ OLDDIR } "
rm -rf ${ OLDDIR }
done
2011-11-04 02:59:55 +04:00
2011-11-02 23:05:24 +04:00
# remove old workspace
rm -rf $WORKSPACE
2011-11-04 02:59:55 +04:00
mkdir $WORKSPACE
DIR = $( mktemp -d ${ PREFIX } /${ LOGDIR_PREFIX } _XXXXXX)
LOG = $DIR /log
2011-11-02 23:05:24 +04:00
testit "registry_upgrade" registry_upgrade || failed = ` expr $failed + 1`
2011-11-04 02:59:55 +04:00
if [ $failed -eq 0 ] ; then
rm -r $DIR
fi
2011-11-02 23:05:24 +04:00
testok $0 $failed