winreg: Use the ntstatus return code for client side errors
[Samba/gebeck_regimport.git] / source3 / script / tests / test_net_registry_roundtrip.sh
blob77b261fbbadb74f664c33c290b6479027426740e
1 #!/bin/sh
3 # Blackbox test for net conf/registry roundtrips.
5 # Copyright (C) 2010 Gregor Beck <gbeck@sernet.de>
6 # Copyright (C) 2011 Michael Adam <obnox@samba.org>
8 if [ $# -lt 3 ]; then
9 cat <<EOF
10 Usage: test_net_registry_roundtrip.sh SCRIPTDIR SERVERCONFFILE PREFIX CONFIGURATION
11 EOF
12 exit 1;
15 SCRIPTDIR="$1"
16 SERVERCONFFILE="$2"
17 CONFIGURATION="$3"
19 NET="$VALGRIND ${NET:-$BINDIR/net} $CONFIGURATION"
22 if test "x${RPC}" = "xrpc" ; then
23 NETREG="${NET} -U${USERNAME}%${PASSWORD} -I ${SERVER_IP} rpc registry"
24 else
25 NETREG="${NET} registry"
28 incdir=`dirname $0`/../../../testprogs/blackbox
29 . $incdir/subunit.sh
31 failed=0
33 SED_INVALID_PARAMS="{
34 s/lock directory/;&/g
35 s/lock dir/;&/g
36 s/modules dir/;&/g
37 s/logging/;&/g
38 s/status/;&/g
39 s/logdir/;&/g
40 s/read prediction/;&/g
41 s/mkprofile/;&/g
42 s/valid chars/;&/g
43 s/timesync/;&/g
44 s/sambaconf/;&/g
45 s/logtype/;&/g
46 s/servername/;&/g
47 s/postscript/;&/g
50 REGPATH="HKLM\Software\Samba"
52 conf_roundtrip_step() {
53 echo "CMD: $*" >>$LOG
54 $@ 2>>$LOG
55 RC=$?
56 echo "RC: $RC" >> $LOG
57 test "x$RC" = "x0" || {
58 echo "ERROR: $@ failed (RC=$RC)" | tee -a $LOG
60 return $RC
61 # echo -n .
64 LOGDIR_PREFIX="conf_roundtrip"
66 conf_roundtrip()
68 local DIR=$(mktemp -d ${PREFIX}/${LOGDIR_PREFIX}_XXXXXX)
69 local LOG=$DIR/log
71 echo conf_roundtrip $1 > $LOG
73 sed -e "$SED_INVALID_PARAMS" $1 >$DIR/conf_in
75 conf_roundtrip_step $NET conf drop
76 test "x$?" = "x0" || {
77 return 1
80 test -z "$($NET conf list)" 2>>$LOG
81 if [ "$?" = "1" ]; then
82 echo "ERROR: conf drop failed" | tee -a $LOG
83 return 1
86 conf_roundtrip_step $NET conf import $DIR/conf_in
87 test "x$?" = "x0" || {
88 return 1
91 conf_roundtrip_step $NET conf list > $DIR/conf_exp
92 test "x$?" = "x0" || {
93 return 1
96 grep "\[global\]" $DIR/conf_exp >/dev/null 2>>$LOG
97 if [ "$?" = "1" ]; then
98 echo "ERROR: conf import => conf export failed" | tee -a $LOG
99 return 1
102 conf_roundtrip_step $NET -d10 registry export $REGPATH $DIR/conf_exp.reg
103 test "x$?" = "x0" || {
104 return 1
107 conf_roundtrip_step $NET conf drop
108 test "x$?" = "x0" || {
109 return 1
112 test -z "$($NET conf list)" 2>>$LOG
113 if [ "$?" = "1" ]; then
114 echo "ERROR: conf drop failed" | tee -a $LOG
115 return 1
118 conf_roundtrip_step $NET registry import $DIR/conf_exp.reg
119 test "x$?" = "x0" || {
120 return 1
123 conf_roundtrip_step $NET conf list >$DIR/conf_out
124 test "x$?" = "x0" || {
125 return 1
128 diff -q $DIR/conf_out $DIR/conf_exp >> $LOG
129 if [ "$?" = "1" ]; then
130 echo "ERROR: registry import => conf export failed" | tee -a $LOG
131 return 1
134 conf_roundtrip_step $NET registry export $REGPATH $DIR/conf_out.reg
135 test "x$?" = "x0" || {
136 return 1
139 diff -q $DIR/conf_out.reg $DIR/conf_exp.reg >>$LOG
140 if [ "$?" = "1" ]; then
141 echo "Error: registry import => registry export failed" | tee -a $LOG
142 return 1
144 rm -r $DIR
147 CONF_FILES=$SERVERCONFFILE
149 # remove old logs:
150 for OLDDIR in $(find ${PREFIX} -type d -name "${LOGDIR_PREFIX}_*") ; do
151 echo "removing old directory ${OLDDIR}"
152 rm -rf ${OLDDIR}
153 done
155 for conf_file in $CONF_FILES
157 testit "conf_roundtrip $conf_file" \
158 conf_roundtrip $conf_file \
159 || failed=`expr $failed + 1`
160 done
162 testok $0 $failed