summaryrefslogtreecommitdiff
path: root/source3/script/tests/test_registry_upgrade.sh
blob: 4e97153fec1f483b4ba835c82352d69cee298277 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/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"
DBWRAP_TOOL="$2"
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()
(
    CHECKNO="$1"
    CHECKDIFF="$2"
    REGVER=""
    ALLOWEDERR="INFO: version =|Check database:|overwrite registry format version 0 with 1|no INFO/version found"

    test "x$CHECKNO" = "x0" && {
        REGVER="--reg-version=1"
    }

    echo "Registry check $CHECKNO" | tee -a $LOG
    CHECK="$($NETCMD registry check $REGVER 2>&1)"
    RC=$?

    ERRORSTR="$(echo "$CHECK" | grep -vE $ALLOWEDERR )"
    test "x$RC" = "x0" || {
        echo "upgrade check $CHECKNO failed:" | tee -a $LOG
        return 1
    }

    test "x$ERRORSTR" = "x" || {
        echo "upgrade check $CHECKNO failed:" | tee -a $LOG
        echo "reason: $CHECK" | tee -a $LOG
        return 1
    }

    test "x$CHECKDIFF" = "xcheckdiff" && {
        $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
        test "x$?" = "x0" || {
            echo "Error: $WORKSPACE/export_0.reg differs from $WORKSPACE/export_${CHECKNO}.reg" | tee -a  $LOG
            return 1
        }
    }

    return 0
)

registry_upgrade()
{
    echo registry_upgrade $1 | tee -a $LOG

    cp -v $DATADIR/registry.tdb $WORKSPACE/registry.tdb >> $LOG 2>&1

    REGISTRY="${WORKSPACE}/registry.tdb"

    test -e $REGISTRY || {
        echo "Error: Database file not available" | tee -a $LOG
        return 1
    }

    # create config file
    echo '[global]' > ${CONFIG_FILE}
    echo "	state directory = ${WORKSPACE}" >> ${CONFIG_FILE}

    # 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
    echo "$REGISTRY" | tee -a $LOG
    registry_check 0
    test "x$?" = "x0" || {
        echo "Error: initial 'registry_check 0' failed" | tee -a $LOG
        return 1
    }

    # trigger upgrade
    echo "$NETCMD registry enumerate $REGPATH" >> $LOG
    $NETCMD registry enumerate $REGPATH >> $LOG
    test "x$?" = "x0" || {
        echo "Error: 'net registry enumerate $REGPATH' failed" | tee -a $LOG
        return 1
    }

    # check upgraded database
    registry_check 1
    test "x$?" = "x0" || {
        echo "Error: 'registry_check 1' after upgrade failed" | tee -a $LOG
        return 1
    }

    # export database for diffs
    $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
    }

    # remove version string
    $DBWRAP_TOOL $REGISTRY delete INFO/version | tee -a $LOG
    test "x$?" = "x0" || {
        echo "Error: Can not remove INFO/version key from registry" | tee -a $LOG
        return 1
    }

    # trigger upgrade on upgraded database
    echo "$NETCMD registry enumerate $REGPATH" >> $LOG
    $NETCMD registry enumerate $REGPATH >> $LOG 2>&1
    test "x$?" = "x0" || {
        echo "Error: 'net registry enumerate $REGPATH' failed" | tee -a $LOG
        return 1
    }

    # check upgraded database again
    registry_check 2 checkdiff
    test "x$?" = "x0" || {
        echo "Error: 'registry_check 2' after upgrade failed" | tee -a $LOG
        return 1
    }

    # set database INFO/version to version 2
    $DBWRAP_TOOL $REGISTRY store 'INFO/version' uint32 2
    test "x$?" = "x0" || {
        echo "Error: Can not set INFO/version" | tee -a $LOG
        return 1
    }

    # trigger upgrade
    $NETCMD registry enumerate $REGPATH >> $LOG
    test "x$?" = "x0" || {
        echo "Error: 'net registry enumerate $REGPATH' failed" | tee -a $LOG
        return 1
    }

    # check upgraded database again
    registry_check 3 checkdiff
    test "x$?" = "x0" || {
        echo "Error: 'registry_check 3' after upgrade failed" | tee -a $LOG
        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

# remove old workspace
rm -rf $WORKSPACE

mkdir $WORKSPACE

DIR=$(mktemp -d ${PREFIX}/${LOGDIR_PREFIX}_XXXXXX)
LOG=$DIR/log

testit "registry_upgrade" registry_upgrade || failed=`expr $failed + 1`

if [ $failed -eq 0 ]; then
    rm -r $DIR
fi

testok $0 $failed