mount.cifs: don't allow it to be run as setuid root program
[Samba/nascimento.git] / source3 / script / tests / test_net_registry.sh
blob52a78bc339f9af068770f205b934c222dc9e72f9
1 #!/bin/sh
3 # Tests for the "net registry" and "net rpc registry" commands.
4 # rpc tests are chose by specifying "rpc" as commandline parameter.
6 RPC="$1"
8 NET="$VALGRIND ${NET:-$BINDIR/net} $CONFIGURATION"
10 if test "x${RPC}" = "xrpc" ; then
11 NETREG="${NET} -U${USERNAME}%${PASSWORD} -I ${SERVER_IP} rpc registry"
12 else
13 NETREG="${NET} registry"
16 test x"$TEST_FUNCTIONS_SH" != x"INCLUDED" && {
17 incdir=`dirname $0`
18 . $incdir/test_functions.sh
21 failed=0
23 test_enumerate()
25 KEY="$1"
27 ${NETREG} enumerate ${KEY}
30 test_getsd()
32 KEY="$1"
34 ${NETREG} getsd ${KEY}
37 test_enumerate_nonexisting()
39 KEY="$1"
40 ${NETREG} enumerate ${KEY}
42 if test "x$?" = "x0" ; then
43 echo "ERROR: enumerate succeeded with key '${KEY}'"
44 false
45 else
46 true
50 test_enumerate_no_key()
52 ${NETREG} enumerate
53 if test "x$?" = "x0" ; then
54 echo "ERROR: enumerate succeeded without any key spcified"
55 false
56 else
57 true
61 test_create_existing()
63 KEY="HKLM"
64 EXPECTED="createkey opened existing ${KEY}"
66 OUTPUT=`${NETREG} createkey ${KEY}`
67 if test "x$?" = "x0" ; then
68 if test "$OUTPUT" = "$EXPECTED" ; then
69 true
70 else
71 echo "got '$OUTPUT', expected '$EXPECTED'"
72 false
74 else
75 printf "%s\n" "$OUTPUT"
76 false
80 test_createkey()
82 KEY="$1"
83 BASEKEY=`dirname $KEY`
84 SUBKEY=`basename $KEY`
86 OUTPUT=`${NETREG} createkey ${KEY}`
87 if test "x$?" != "x0" ; then
88 echo "ERROR: createkey ${KEY} failed"
89 echo "output:"
90 printf "%s\n" "$OUTPUT"
91 false
92 return
95 # check enumerate of basekey lists new key:
96 OUTPUT=`${NETREG} enumerate ${BASEKEY}`
97 if test "x$?" != "x0" ; then
98 echo "ERROR: failed to enumerate key '${BASEKEY}'"
99 echo "output:"
100 printf "%s\n" "$OUTPUT"
101 false
102 return
105 EXPECTED="Keyname = ${SUBKEY}"
106 printf "%s\n" "$OUTPUT" | grep '^Keyname' | grep ${SUBKEY}
107 if test "x$?" != "x0" ; then
108 echo "ERROR: did not find expexted '$EXPECTED' in output"
109 echo "output:"
110 printf "%s\n" "$OUTPUT"
111 false
114 # check enumerate of new key works:
115 ${NETREG} enumerate ${KEY}
118 test_deletekey()
120 KEY="$1"
121 BASEKEY=`dirname ${KEY}`
122 SUBKEY=`basename ${KEY}`
124 OUTPUT=`test_createkey "${KEY}"`
125 if test "x$?" != "x0" ; then
126 printf "%s\n" "${OUTPUT}"
127 false
128 return
131 OUTPUT=`${NETREG} deletekey ${KEY}`
132 if test "x$?" != "x0" ; then
133 printf "%s\n" "${OUTPUT}"
134 false
135 return
138 # check enumerate of basekey does not show key anymore:
139 OUTPUT=`${NETREG} enumerate ${BASEKEY}`
140 if test "x$?" != "x0" ; then
141 printf "%s\n" "$OUTPUT"
142 false
143 return
146 UNEXPECTED="Keyname = ${SUBKEY}"
147 printf "%s\n" "$OUTPUT" | 'grep ^Keyname' | grep ${SUBKEY}
148 if test "x$?" = "x0" ; then
149 echo "ERROR: found '$UNEXPECTED' after delete in output"
150 echo "output:"
151 printf "%s\n" "$OUTPUT"
152 false
155 # check enumerate of key itself does not work anymore:
156 ${NETREG} enumerate ${KEY}
157 if test "x$?" = "x0" ; then
158 echo "ERROR: 'enumerate ${KEY}' works after 'deletekey ${KEY}'"
159 false
160 else
161 true
165 test_deletekey_nonexisting()
167 KEY="$1"
169 OUTPUT=`test_deletekey "${KEY}"`
170 if test "x$?" != "x0" ; then
171 printf "%s\n" "${OUTPUT}"
172 false
173 return
176 ${NETREG} deletekey "${KEY}"
177 if test "x$?" = "x0" ; then
178 echo "ERROR: delete after delete succeeded for key '${KEY}'"
179 false
183 test_createkey_with_subkey()
185 KEY="$1"
186 KEY2=`dirname ${KEY}`
187 SUBKEYNAME2=`basename ${KEY}`
188 BASENAME=`dirname ${KEY2}`
189 SUBKEYNAME1=`basename ${KEY2}`
191 OUTPUT=`${NETREG} createkey ${KEY}`
192 if test "x$?" != "x0" ; then
193 echo "ERROR: createkey ${KEY} failed"
194 printf "%s\n" "${OUTPUT}"
195 false
196 return
199 # check we can enumerate to level key
200 OUTPUT=`${NETREG} enumerate ${KEY}`
201 if test "x$?" != "x0" ; then
202 echo "ERROR: failed to enumerate '${KEY}' after creation"
203 printf "%s\n" "${OUTPUT}"
204 false
205 return
208 # clear:
209 ${NETREG} deletekey ${KEY} && ${NETREG} deletekey ${KEY2}
212 test_deletekey_with_subkey()
214 KEY="$1"
215 KEY2=`dirname ${KEY}`
217 OUTPUT=`${NETREG} createkey ${KEY}`
218 if test "x$?" != "x0" ; then
219 printf "%s\n" "${OUTPUT}"
220 false
221 return
224 OUTPUT=`${NETREG} deletekey ${KEY2}`
226 if test "x$?" = "x0" ; then
227 echo "ERROR: delete of key with subkey succeeded"
228 echo "output:"
229 printf "%s\n" "$OUTPUT"
230 false
231 return
234 ${NETREG} deletekey ${KEY} && ${NETREG} deletekey ${KEY2}
237 test_setvalue()
239 KEY="$1"
240 VALNAME="$2"
241 VALTYPE="$3"
242 VALVALUE="$4"
244 OUTPUT=`test_createkey ${KEY}`
245 if test "x$?" != "x0" ; then
246 printf "%s\n" "${OUTPUT}"
247 false
248 return
251 OUTPUT=`${NETREG} setvalue ${KEY} ${VALNAME} ${VALTYPE} ${VALVALUE}`
252 if test "x$?" != "x0" ; then
253 echo "ERROR: failed to set value testval in key ${KEY}"
254 printf "%s\n" "${OUTPUT}"
255 false
256 return
259 OUTPUT=`${NETREG} enumerate ${KEY}`
260 if test "x$?" != "x0" ; then
261 echo "ERROR: failure calling enumerate for key ${KEY}"
262 echo output:
263 printf "%s\n" "${OUTPUT}"
264 false
265 return
268 printf "%s\n" "$OUTPUT" | {
269 FOUND=0
270 while read LINE ; do
271 SEARCH1=`echo $LINE | grep '^Valuename' | grep ${VALNAME}`
272 if test "x$?" = "x0" ; then
273 read LINE
274 read LINE
275 SEARCH2=`echo $LINE | grep '^Value ' | grep ${VALVALUE}`
276 if test "x$?" = "x0" ; then
277 FOUND=1
278 break
281 done
283 if test "x$FOUND" != "x1" ; then
284 echo "ERROR: did not find value '${VALNAME}' with enumerate"
285 echo "enumerate output:"
286 printf "%s\n" "$OUTPUT"
287 false
288 return
293 test_deletevalue()
295 KEY="$1"
296 VALNAME="$2"
298 ${NETREG} deletevalue ${KEY} ${VALNAME}
301 test_deletevalue_nonexisting()
303 KEY="$1"
304 VALNAME="$2"
306 ${NETREG} deletevalue ${KEY} ${VALNAME}
307 if test "x$?" = "x0" ; then
308 echo "ERROR: succeeded deleting value ${VALNAME}"
309 false
310 else
311 true
315 test_setvalue_twice()
317 KEY="$1"
318 VALNAME="$2"
319 VALTYPE1="$3"
320 VALVALUE1="$4"
321 VALTYPE2="$5"
322 VALVALUE2="$6"
324 OUTPUT=`test_setvalue ${KEY} ${VALNAME} ${VALTYPE1} ${VALVALUE1}`
325 if test "x$?" != "x0" ; then
326 echo "ERROR: first setvalue call failed"
327 printf "%s\n" "$OUTPUT"
328 false
329 return
332 ${NETREG} setvalue ${KEY} ${VALNAME} ${VALTYPE2} ${VALVALUE2}
335 give_administrative_rights()
337 bin/net -s $SERVERCONFFILE sam createbuiltingroup Administrators
338 if test "x$?" != "x0" ; then
339 echo "ERROR: creating builtin group Administrators"
340 false
341 return
344 bin/net -s $SERVERCONFFILE sam addmem BUILTIN\\Administrators $USERNAME
345 if test "x$?" != "x0" ; then
346 echo "ERROR: adding user $USERNAME to BUILTIN\\Administrators"
347 false
348 else
349 true
353 take_administrative_rights()
355 bin/net -s $SERVERCONFFILE sam delmem BUILTIN\\Administrators $USERNAME
356 if test "x$?" != "x0" ; then
357 echo "ERROR: removing user $USERNAME from BUILTIN\\Administrators"
358 false
359 else
360 true
364 if test "x${RPC}" = "xrpc" ; then
365 testit "giving user ${USERNAME} administrative rights" \
366 give_administrative_rights
367 if [ "x$?" != "x0" ] ; then
368 failed=`expr $failed + 1`
369 testok $0 $failed
373 testit "enumerate HKLM" \
374 test_enumerate HKLM || \
375 failed=`expr $failed + 1`
377 testit "enumerate nonexisting hive" \
378 test_enumerate_nonexisting XYZ || \
379 failed=`expr $failed + 1`
381 testit "enumerate without key" \
382 test_enumerate_no_key || \
383 failed=`expr $failed + 1`
385 # skip getsd test for registry currently: it fails
386 if test "x${RPC}" != "xrpc" ; then
387 testit "getsd HKLM" \
388 test_getsd HKLM || \
389 failed=`expr $failed + 1`
392 testit "create existing HKLM" \
393 test_create_existing || \
394 failed=`expr $failed + 1`
396 testit "create key" \
397 test_createkey HKLM/testkey || \
398 failed=`expr $failed + 1`
400 testit "delete key" \
401 test_deletekey HKLM/testkey || \
402 failed=`expr $failed + 1`
404 testit "delete^2 key" \
405 test_deletekey_nonexisting HKLM/testkey || \
406 failed=`expr $failed + 1`
408 testit "enumerate nonexisting key" \
409 test_enumerate_nonexisting HKLM/testkey || \
410 failed=`expr $failed + 1`
412 testit "create key with subkey" \
413 test_createkey_with_subkey HKLM/testkey/subkey || \
414 failed=`expr $failed + 1`
416 testit "delete key with subkey" \
417 test_deletekey_with_subkey HKLM/testkey/subkey || \
418 failed=`expr $failed + 1`
420 testit "set value" \
421 test_setvalue HKLM/testkey testval sz moin || \
422 failed=`expr $failed + 1`
424 testit "delete value" \
425 test_deletevalue HKLM/testkey testval || \
426 failed=`expr $failed + 1`
428 testit "delete nonexisting value" \
429 test_deletevalue_nonexisting HKLM/testkey testval || \
430 failed=`expr $failed + 1`
432 testit "set value to different type" \
433 test_setvalue_twice HKLM/testkey testval sz moin dword 42 || \
434 failed=`expr $failed + 1`
436 testit "delete key with value" \
437 test_deletekey HKLM/testkey || \
438 failed=`expr $failed + 1`
440 if test "x${RPC}" = "xrpc" ; then
441 testit "taking administrative rights from user ${USERNAME}" \
442 take_administrative_rights || \
443 failed=`expr $failed + 1`
446 testok $0 $failed