| [206] | 1 | #!/bin/sh
|
|---|
| 2 |
|
|---|
| 3 | # Tests for the "net registry" and "net rpc registry" commands.
|
|---|
| 4 | # rpc tests are chose by specifying "rpc" as commandline parameter.
|
|---|
| 5 |
|
|---|
| 6 | RPC="$1"
|
|---|
| 7 |
|
|---|
| 8 | NET="$VALGRIND ${NET:-$BINDIR/net} $CONFIGURATION"
|
|---|
| 9 |
|
|---|
| 10 | if test "x${RPC}" = "xrpc" ; then
|
|---|
| 11 | NETREG="${NET} -U${USERNAME}%${PASSWORD} -I ${SERVER_IP} rpc registry"
|
|---|
| 12 | else
|
|---|
| 13 | NETREG="${NET} registry"
|
|---|
| 14 | fi
|
|---|
| 15 |
|
|---|
| 16 | incdir=`dirname $0`
|
|---|
| 17 | . $incdir/test_functions.sh
|
|---|
| 18 |
|
|---|
| 19 | failed=0
|
|---|
| 20 |
|
|---|
| 21 | test_enumerate()
|
|---|
| 22 | {
|
|---|
| 23 | KEY="$1"
|
|---|
| 24 |
|
|---|
| 25 | ${NETREG} enumerate ${KEY}
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | test_getsd()
|
|---|
| 29 | {
|
|---|
| 30 | KEY="$1"
|
|---|
| 31 |
|
|---|
| 32 | ${NETREG} getsd ${KEY}
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | test_enumerate_nonexisting()
|
|---|
| 36 | {
|
|---|
| 37 | KEY="$1"
|
|---|
| 38 | ${NETREG} enumerate ${KEY}
|
|---|
| 39 |
|
|---|
| 40 | if test "x$?" = "x0" ; then
|
|---|
| 41 | echo "ERROR: enumerate succeeded with key '${KEY}'"
|
|---|
| 42 | false
|
|---|
| 43 | else
|
|---|
| 44 | true
|
|---|
| 45 | fi
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | test_enumerate_no_key()
|
|---|
| 49 | {
|
|---|
| 50 | ${NETREG} enumerate
|
|---|
| 51 | if test "x$?" = "x0" ; then
|
|---|
| 52 | echo "ERROR: enumerate succeeded without any key spcified"
|
|---|
| 53 | false
|
|---|
| 54 | else
|
|---|
| 55 | true
|
|---|
| 56 | fi
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | test_create_existing()
|
|---|
| 60 | {
|
|---|
| 61 | KEY="HKLM"
|
|---|
| 62 | EXPECTED="createkey opened existing ${KEY}"
|
|---|
| 63 |
|
|---|
| 64 | OUTPUT=`${NETREG} createkey ${KEY}`
|
|---|
| 65 | if test "x$?" = "x0" ; then
|
|---|
| 66 | if test "$OUTPUT" = "$EXPECTED" ; then
|
|---|
| 67 | true
|
|---|
| 68 | else
|
|---|
| 69 | echo "got '$OUTPUT', expected '$EXPECTED'"
|
|---|
| 70 | false
|
|---|
| 71 | fi
|
|---|
| 72 | else
|
|---|
| 73 | printf "%s\n" "$OUTPUT"
|
|---|
| 74 | false
|
|---|
| 75 | fi
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | test_createkey()
|
|---|
| 79 | {
|
|---|
| 80 | KEY="$1"
|
|---|
| 81 | BASEKEY=`dirname $KEY`
|
|---|
| 82 | SUBKEY=`basename $KEY`
|
|---|
| 83 |
|
|---|
| 84 | OUTPUT=`${NETREG} createkey ${KEY}`
|
|---|
| 85 | if test "x$?" != "x0" ; then
|
|---|
| 86 | echo "ERROR: createkey ${KEY} failed"
|
|---|
| 87 | echo "output:"
|
|---|
| 88 | printf "%s\n" "$OUTPUT"
|
|---|
| 89 | false
|
|---|
| 90 | return
|
|---|
| 91 | fi
|
|---|
| 92 |
|
|---|
| 93 | # check enumerate of basekey lists new key:
|
|---|
| 94 | OUTPUT=`${NETREG} enumerate ${BASEKEY}`
|
|---|
| 95 | if test "x$?" != "x0" ; then
|
|---|
| 96 | echo "ERROR: failed to enumerate key '${BASEKEY}'"
|
|---|
| 97 | echo "output:"
|
|---|
| 98 | printf "%s\n" "$OUTPUT"
|
|---|
| 99 | false
|
|---|
| 100 | return
|
|---|
| 101 | fi
|
|---|
| 102 |
|
|---|
| 103 | EXPECTED="Keyname = ${SUBKEY}"
|
|---|
| 104 | printf "%s\n" "$OUTPUT" | grep '^Keyname' | grep ${SUBKEY}
|
|---|
| 105 | if test "x$?" != "x0" ; then
|
|---|
| 106 | echo "ERROR: did not find expexted '$EXPECTED' in output"
|
|---|
| 107 | echo "output:"
|
|---|
| 108 | printf "%s\n" "$OUTPUT"
|
|---|
| 109 | false
|
|---|
| 110 | fi
|
|---|
| 111 |
|
|---|
| 112 | # check enumerate of new key works:
|
|---|
| 113 | ${NETREG} enumerate ${KEY}
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | test_deletekey()
|
|---|
| 117 | {
|
|---|
| 118 | KEY="$1"
|
|---|
| 119 | BASEKEY=`dirname ${KEY}`
|
|---|
| 120 | SUBKEY=`basename ${KEY}`
|
|---|
| 121 |
|
|---|
| 122 | OUTPUT=`test_createkey "${KEY}"`
|
|---|
| 123 | if test "x$?" != "x0" ; then
|
|---|
| 124 | printf "%s\n" "${OUTPUT}"
|
|---|
| 125 | false
|
|---|
| 126 | return
|
|---|
| 127 | fi
|
|---|
| 128 |
|
|---|
| 129 | OUTPUT=`${NETREG} deletekey ${KEY}`
|
|---|
| 130 | if test "x$?" != "x0" ; then
|
|---|
| 131 | printf "%s\n" "${OUTPUT}"
|
|---|
| 132 | false
|
|---|
| 133 | return
|
|---|
| 134 | fi
|
|---|
| 135 |
|
|---|
| 136 | # check enumerate of basekey does not show key anymore:
|
|---|
| 137 | OUTPUT=`${NETREG} enumerate ${BASEKEY}`
|
|---|
| 138 | if test "x$?" != "x0" ; then
|
|---|
| 139 | printf "%s\n" "$OUTPUT"
|
|---|
| 140 | false
|
|---|
| 141 | return
|
|---|
| 142 | fi
|
|---|
| 143 |
|
|---|
| 144 | UNEXPECTED="Keyname = ${SUBKEY}"
|
|---|
| 145 | printf "%s\n" "$OUTPUT" | 'grep ^Keyname' | grep ${SUBKEY}
|
|---|
| 146 | if test "x$?" = "x0" ; then
|
|---|
| 147 | echo "ERROR: found '$UNEXPECTED' after delete in output"
|
|---|
| 148 | echo "output:"
|
|---|
| 149 | printf "%s\n" "$OUTPUT"
|
|---|
| 150 | false
|
|---|
| 151 | fi
|
|---|
| 152 |
|
|---|
| 153 | # check enumerate of key itself does not work anymore:
|
|---|
| 154 | ${NETREG} enumerate ${KEY}
|
|---|
| 155 | if test "x$?" = "x0" ; then
|
|---|
| 156 | echo "ERROR: 'enumerate ${KEY}' works after 'deletekey ${KEY}'"
|
|---|
| 157 | false
|
|---|
| 158 | else
|
|---|
| 159 | true
|
|---|
| 160 | fi
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | test_deletekey_nonexisting()
|
|---|
| 164 | {
|
|---|
| 165 | KEY="$1"
|
|---|
| 166 |
|
|---|
| 167 | OUTPUT=`test_deletekey "${KEY}"`
|
|---|
| 168 | if test "x$?" != "x0" ; then
|
|---|
| 169 | printf "%s\n" "${OUTPUT}"
|
|---|
| 170 | false
|
|---|
| 171 | return
|
|---|
| 172 | fi
|
|---|
| 173 |
|
|---|
| 174 | ${NETREG} deletekey "${KEY}"
|
|---|
| 175 | if test "x$?" = "x0" ; then
|
|---|
| 176 | echo "ERROR: delete after delete succeeded for key '${KEY}'"
|
|---|
| 177 | false
|
|---|
| 178 | fi
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | test_createkey_with_subkey()
|
|---|
| 182 | {
|
|---|
| 183 | KEY="$1"
|
|---|
| 184 | KEY2=`dirname ${KEY}`
|
|---|
| 185 | SUBKEYNAME2=`basename ${KEY}`
|
|---|
| 186 | BASENAME=`dirname ${KEY2}`
|
|---|
| 187 | SUBKEYNAME1=`basename ${KEY2}`
|
|---|
| 188 |
|
|---|
| 189 | OUTPUT=`${NETREG} createkey ${KEY}`
|
|---|
| 190 | if test "x$?" != "x0" ; then
|
|---|
| 191 | echo "ERROR: createkey ${KEY} failed"
|
|---|
| 192 | printf "%s\n" "${OUTPUT}"
|
|---|
| 193 | false
|
|---|
| 194 | return
|
|---|
| 195 | fi
|
|---|
| 196 |
|
|---|
| 197 | # check we can enumerate to level key
|
|---|
| 198 | OUTPUT=`${NETREG} enumerate ${KEY}`
|
|---|
| 199 | if test "x$?" != "x0" ; then
|
|---|
| 200 | echo "ERROR: failed to enumerate '${KEY}' after creation"
|
|---|
| 201 | printf "%s\n" "${OUTPUT}"
|
|---|
| 202 | false
|
|---|
| 203 | return
|
|---|
| 204 | fi
|
|---|
| 205 |
|
|---|
| 206 | # clear:
|
|---|
| 207 | ${NETREG} deletekey ${KEY} && ${NETREG} deletekey ${KEY2}
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | test_deletekey_with_subkey()
|
|---|
| 211 | {
|
|---|
| 212 | KEY="$1"
|
|---|
| 213 | KEY2=`dirname ${KEY}`
|
|---|
| 214 |
|
|---|
| 215 | OUTPUT=`${NETREG} createkey ${KEY}`
|
|---|
| 216 | if test "x$?" != "x0" ; then
|
|---|
| 217 | printf "%s\n" "${OUTPUT}"
|
|---|
| 218 | false
|
|---|
| 219 | return
|
|---|
| 220 | fi
|
|---|
| 221 |
|
|---|
| 222 | OUTPUT=`${NETREG} deletekey ${KEY2}`
|
|---|
| 223 |
|
|---|
| 224 | if test "x$?" = "x0" ; then
|
|---|
| 225 | echo "ERROR: delete of key with subkey succeeded"
|
|---|
| 226 | echo "output:"
|
|---|
| 227 | printf "%s\n" "$OUTPUT"
|
|---|
| 228 | false
|
|---|
| 229 | return
|
|---|
| 230 | fi
|
|---|
| 231 |
|
|---|
| 232 | ${NETREG} deletekey ${KEY} && ${NETREG} deletekey ${KEY2}
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | test_setvalue()
|
|---|
| 236 | {
|
|---|
| 237 | KEY="$1"
|
|---|
| 238 | VALNAME="$2"
|
|---|
| 239 | VALTYPE="$3"
|
|---|
| 240 | VALVALUE="$4"
|
|---|
| 241 |
|
|---|
| 242 | OUTPUT=`test_createkey ${KEY}`
|
|---|
| 243 | if test "x$?" != "x0" ; then
|
|---|
| 244 | printf "%s\n" "${OUTPUT}"
|
|---|
| 245 | false
|
|---|
| 246 | return
|
|---|
| 247 | fi
|
|---|
| 248 |
|
|---|
| 249 | OUTPUT=`${NETREG} setvalue ${KEY} ${VALNAME} ${VALTYPE} ${VALVALUE}`
|
|---|
| 250 | if test "x$?" != "x0" ; then
|
|---|
| 251 | echo "ERROR: failed to set value testval in key ${KEY}"
|
|---|
| 252 | printf "%s\n" "${OUTPUT}"
|
|---|
| 253 | false
|
|---|
| 254 | return
|
|---|
| 255 | fi
|
|---|
| 256 |
|
|---|
| 257 | OUTPUT=`${NETREG} enumerate ${KEY}`
|
|---|
| 258 | if test "x$?" != "x0" ; then
|
|---|
| 259 | echo "ERROR: failure calling enumerate for key ${KEY}"
|
|---|
| 260 | echo output:
|
|---|
| 261 | printf "%s\n" "${OUTPUT}"
|
|---|
| 262 | false
|
|---|
| 263 | return
|
|---|
| 264 | fi
|
|---|
| 265 |
|
|---|
| 266 | printf "%s\n" "$OUTPUT" | {
|
|---|
| 267 | FOUND=0
|
|---|
| 268 | while read LINE ; do
|
|---|
| 269 | SEARCH1=`echo $LINE | grep '^Valuename' | grep ${VALNAME}`
|
|---|
| 270 | if test "x$?" = "x0" ; then
|
|---|
| 271 | read LINE
|
|---|
| 272 | read LINE
|
|---|
| 273 | SEARCH2=`echo $LINE | grep '^Value ' | grep ${VALVALUE}`
|
|---|
| 274 | if test "x$?" = "x0" ; then
|
|---|
| 275 | FOUND=1
|
|---|
| 276 | break
|
|---|
| 277 | fi
|
|---|
| 278 | fi
|
|---|
| 279 | done
|
|---|
| 280 |
|
|---|
| 281 | if test "x$FOUND" != "x1" ; then
|
|---|
| 282 | echo "ERROR: did not find value '${VALNAME}' with enumerate"
|
|---|
| 283 | echo "enumerate output:"
|
|---|
| 284 | printf "%s\n" "$OUTPUT"
|
|---|
| 285 | false
|
|---|
| 286 | return
|
|---|
| 287 | fi
|
|---|
| 288 | }
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 | test_deletevalue()
|
|---|
| 292 | {
|
|---|
| 293 | KEY="$1"
|
|---|
| 294 | VALNAME="$2"
|
|---|
| 295 |
|
|---|
| 296 | ${NETREG} deletevalue ${KEY} ${VALNAME}
|
|---|
| 297 | }
|
|---|
| 298 |
|
|---|
| 299 | test_deletevalue_nonexisting()
|
|---|
| 300 | {
|
|---|
| 301 | KEY="$1"
|
|---|
| 302 | VALNAME="$2"
|
|---|
| 303 |
|
|---|
| 304 | ${NETREG} deletevalue ${KEY} ${VALNAME}
|
|---|
| 305 | if test "x$?" = "x0" ; then
|
|---|
| 306 | echo "ERROR: succeeded deleting value ${VALNAME}"
|
|---|
| 307 | false
|
|---|
| 308 | else
|
|---|
| 309 | true
|
|---|
| 310 | fi
|
|---|
| 311 | }
|
|---|
| 312 |
|
|---|
| 313 | test_setvalue_twice()
|
|---|
| 314 | {
|
|---|
| 315 | KEY="$1"
|
|---|
| 316 | VALNAME="$2"
|
|---|
| 317 | VALTYPE1="$3"
|
|---|
| 318 | VALVALUE1="$4"
|
|---|
| 319 | VALTYPE2="$5"
|
|---|
| 320 | VALVALUE2="$6"
|
|---|
| 321 |
|
|---|
| 322 | OUTPUT=`test_setvalue ${KEY} ${VALNAME} ${VALTYPE1} ${VALVALUE1}`
|
|---|
| 323 | if test "x$?" != "x0" ; then
|
|---|
| 324 | echo "ERROR: first setvalue call failed"
|
|---|
| 325 | printf "%s\n" "$OUTPUT"
|
|---|
| 326 | false
|
|---|
| 327 | return
|
|---|
| 328 | fi
|
|---|
| 329 |
|
|---|
| 330 | ${NETREG} setvalue ${KEY} ${VALNAME} ${VALTYPE2} ${VALVALUE2}
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|
| 333 | give_administrative_rights()
|
|---|
| 334 | {
|
|---|
| 335 | bin/net -s $SERVERCONFFILE sam createbuiltingroup Administrators
|
|---|
| 336 | if test "x$?" != "x0" ; then
|
|---|
| 337 | echo "ERROR: creating builtin group Administrators"
|
|---|
| 338 | false
|
|---|
| 339 | return
|
|---|
| 340 | fi
|
|---|
| 341 |
|
|---|
| 342 | bin/net -s $SERVERCONFFILE sam addmem BUILTIN\\Administrators $USERNAME
|
|---|
| 343 | if test "x$?" != "x0" ; then
|
|---|
| 344 | echo "ERROR: adding user $USERNAME to BUILTIN\\Administrators"
|
|---|
| 345 | false
|
|---|
| 346 | else
|
|---|
| 347 | true
|
|---|
| 348 | fi
|
|---|
| 349 | }
|
|---|
| 350 |
|
|---|
| 351 | take_administrative_rights()
|
|---|
| 352 | {
|
|---|
| 353 | bin/net -s $SERVERCONFFILE sam delmem BUILTIN\\Administrators $USERNAME
|
|---|
| 354 | if test "x$?" != "x0" ; then
|
|---|
| 355 | echo "ERROR: removing user $USERNAME from BUILTIN\\Administrators"
|
|---|
| 356 | false
|
|---|
| 357 | else
|
|---|
| 358 | true
|
|---|
| 359 | fi
|
|---|
| 360 | }
|
|---|
| 361 |
|
|---|
| 362 | if test "x${RPC}" = "xrpc" ; then
|
|---|
| 363 | testit "giving user ${USERNAME} administrative rights" \
|
|---|
| 364 | give_administrative_rights || \
|
|---|
| 365 | failed=`expr $failed + 1`
|
|---|
| 366 | fi
|
|---|
| 367 |
|
|---|
| 368 | testit "enumerate HKLM" \
|
|---|
| 369 | test_enumerate HKLM || \
|
|---|
| 370 | failed=`expr $failed + 1`
|
|---|
| 371 |
|
|---|
| 372 | testit "enumerate nonexisting hive" \
|
|---|
| 373 | test_enumerate_nonexisting XYZ || \
|
|---|
| 374 | failed=`expr $failed + 1`
|
|---|
| 375 |
|
|---|
| 376 | testit "enumerate without key" \
|
|---|
| 377 | test_enumerate_no_key || \
|
|---|
| 378 | failed=`expr $failed + 1`
|
|---|
| 379 |
|
|---|
| 380 | # skip getsd test for registry currently: it fails
|
|---|
| 381 | if test "x${RPC}" != "xrpc" ; then
|
|---|
| 382 | testit "getsd HKLM" \
|
|---|
| 383 | test_getsd HKLM || \
|
|---|
| 384 | failed=`expr $failed + 1`
|
|---|
| 385 | fi
|
|---|
| 386 |
|
|---|
| 387 | testit "create existing HKLM" \
|
|---|
| 388 | test_create_existing || \
|
|---|
| 389 | failed=`expr $failed + 1`
|
|---|
| 390 |
|
|---|
| 391 | testit "create key" \
|
|---|
| 392 | test_createkey HKLM/testkey || \
|
|---|
| 393 | failed=`expr $failed + 1`
|
|---|
| 394 |
|
|---|
| 395 | testit "delete key" \
|
|---|
| 396 | test_deletekey HKLM/testkey || \
|
|---|
| 397 | failed=`expr $failed + 1`
|
|---|
| 398 |
|
|---|
| 399 | testit "delete^2 key" \
|
|---|
| 400 | test_deletekey_nonexisting HKLM/testkey || \
|
|---|
| 401 | failed=`expr $failed + 1`
|
|---|
| 402 |
|
|---|
| 403 | testit "enumerate nonexisting key" \
|
|---|
| 404 | test_enumerate_nonexisting HKLM/testkey || \
|
|---|
| 405 | failed=`expr $failed + 1`
|
|---|
| 406 |
|
|---|
| 407 | testit "create key with subkey" \
|
|---|
| 408 | test_createkey_with_subkey HKLM/testkey/subkey || \
|
|---|
| 409 | failed=`expr $failed + 1`
|
|---|
| 410 |
|
|---|
| 411 | testit "delete key with subkey" \
|
|---|
| 412 | test_deletekey_with_subkey HKLM/testkey/subkey || \
|
|---|
| 413 | failed=`expr $failed + 1`
|
|---|
| 414 |
|
|---|
| 415 | testit "set value" \
|
|---|
| 416 | test_setvalue HKLM/testkey testval sz moin || \
|
|---|
| 417 | failed=`expr $failed + 1`
|
|---|
| 418 |
|
|---|
| 419 | testit "delete value" \
|
|---|
| 420 | test_deletevalue HKLM/testkey testval || \
|
|---|
| 421 | failed=`expr $failed + 1`
|
|---|
| 422 |
|
|---|
| 423 | testit "delete nonexisting value" \
|
|---|
| 424 | test_deletevalue_nonexisting HKLM/testkey testval || \
|
|---|
| 425 | failed=`expr $failed + 1`
|
|---|
| 426 |
|
|---|
| 427 | testit "set value to different type" \
|
|---|
| 428 | test_setvalue_twice HKLM/testkey testval sz moin dword 42 || \
|
|---|
| 429 | failed=`expr $failed + 1`
|
|---|
| 430 |
|
|---|
| 431 | testit "delete key with value" \
|
|---|
| 432 | test_deletekey HKLM/testkey || \
|
|---|
| 433 | failed=`expr $failed + 1`
|
|---|
| 434 |
|
|---|
| 435 | if test "x${RPC}" = "xrpc" ; then
|
|---|
| 436 | testit "taking administrative rights from user ${USERNAME}" \
|
|---|
| 437 | take_administrative_rights || \
|
|---|
| 438 | failed=`expr $failed + 1`
|
|---|
| 439 | fi
|
|---|
| 440 |
|
|---|
| 441 | testok $0 $failed
|
|---|
| 442 |
|
|---|