delkey_test.sh revision 148459
10Sstevel@tonic-gate#!/bin/sh 20Sstevel@tonic-gate# $FreeBSD: head/tools/regression/geom_eli/delkey.t 148459 2005-07-27 22:27:30Z pjd $ 30Sstevel@tonic-gate 40Sstevel@tonic-gatebase=`basename $0` 51253Slq150181no=45 61253Slq150181sectors=100 70Sstevel@tonic-gatekeyfile1=`mktemp /tmp/$base.XXXXXX` || exit 1 80Sstevel@tonic-gatekeyfile2=`mktemp /tmp/$base.XXXXXX` || exit 1 90Sstevel@tonic-gatekeyfile3=`mktemp /tmp/$base.XXXXXX` || exit 1 100Sstevel@tonic-gatekeyfile4=`mktemp /tmp/$base.XXXXXX` || exit 1 110Sstevel@tonic-gatemdconfig -a -t malloc -s `expr $sectors + 1` -u $no || exit 1 120Sstevel@tonic-gate 130Sstevel@tonic-gateecho "1..14" 140Sstevel@tonic-gate 150Sstevel@tonic-gatedd if=/dev/random of=${keyfile1} bs=512 count=16 >/dev/null 2>&1 160Sstevel@tonic-gatedd if=/dev/random of=${keyfile2} bs=512 count=16 >/dev/null 2>&1 170Sstevel@tonic-gatedd if=/dev/random of=${keyfile3} bs=512 count=16 >/dev/null 2>&1 180Sstevel@tonic-gatedd if=/dev/random of=${keyfile4} bs=512 count=16 >/dev/null 2>&1 190Sstevel@tonic-gate 200Sstevel@tonic-gategeli init -P -K $keyfile1 md${no} 211253Slq150181geli attach -p -k $keyfile1 md${no} 220Sstevel@tonic-gategeli setkey -n 1 -P -K $keyfile2 md${no} 2312195SAaron.Zang@Sun.COM 240Sstevel@tonic-gate# Remove key 0 for attached provider. 250Sstevel@tonic-gategeli delkey -n 0 md${no} 260Sstevel@tonic-gateif [ $? -eq 0 ]; then 270Sstevel@tonic-gate echo "ok 1" 280Sstevel@tonic-gateelse 290Sstevel@tonic-gate echo "not ok 1" 300Sstevel@tonic-gatefi 310Sstevel@tonic-gategeli detach md${no} 320Sstevel@tonic-gate 330Sstevel@tonic-gate# We cannot use keyfile1 anymore. 347688SAaron.Zang@Sun.COMgeli attach -p -k $keyfile1 md${no} 2>/dev/null 357688SAaron.Zang@Sun.COMif [ $? -ne 0 ]; then 367688SAaron.Zang@Sun.COM echo "ok 2" 377688SAaron.Zang@Sun.COMelse 387688SAaron.Zang@Sun.COM echo "not ok 2" 397688SAaron.Zang@Sun.COMfi 407688SAaron.Zang@Sun.COM 417688SAaron.Zang@Sun.COM# Attach with key 1. 4212195SAaron.Zang@Sun.COMgeli attach -p -k $keyfile2 md${no} 4312195SAaron.Zang@Sun.COMif [ $? -eq 0 ]; then 4412195SAaron.Zang@Sun.COM echo "ok 3" 457688SAaron.Zang@Sun.COMelse 467688SAaron.Zang@Sun.COM echo "not ok 3" 477688SAaron.Zang@Sun.COMfi 487688SAaron.Zang@Sun.COM 497688SAaron.Zang@Sun.COM# We cannot remove last key without -f option (for attached provider). 507688SAaron.Zang@Sun.COMgeli delkey -n 1 md${no} 2>/dev/null 517688SAaron.Zang@Sun.COMif [ $? -ne 0 ]; then 527688SAaron.Zang@Sun.COM echo "ok 4" 5312195SAaron.Zang@Sun.COMelse 547688SAaron.Zang@Sun.COM echo "not ok 4" 5512195SAaron.Zang@Sun.COMfi 567688SAaron.Zang@Sun.COM 5712195SAaron.Zang@Sun.COM# Remove last key for attached provider. 587688SAaron.Zang@Sun.COMgeli delkey -f -n 1 md${no} 5912195SAaron.Zang@Sun.COMif [ $? -eq 0 ]; then 607688SAaron.Zang@Sun.COM echo "ok 5" 617688SAaron.Zang@Sun.COMelse 627688SAaron.Zang@Sun.COM echo "not ok 5" 637688SAaron.Zang@Sun.COMfi 647688SAaron.Zang@Sun.COM 657688SAaron.Zang@Sun.COM# If there are no valid keys, but provider is attached, we can save situation. 667688SAaron.Zang@Sun.COMgeli setkey -n 0 -P -K $keyfile3 md${no} 677688SAaron.Zang@Sun.COMif [ $? -eq 0 ]; then 687688SAaron.Zang@Sun.COM echo "ok 6" 697688SAaron.Zang@Sun.COMelse 707688SAaron.Zang@Sun.COM echo "not ok 6" 717688SAaron.Zang@Sun.COMfi 727688SAaron.Zang@Sun.COMgeli detach md${no} 737688SAaron.Zang@Sun.COM 747688SAaron.Zang@Sun.COM# We cannot use keyfile2 anymore. 757688SAaron.Zang@Sun.COMgeli attach -p -k $keyfile2 md${no} 2>/dev/null 767688SAaron.Zang@Sun.COMif [ $? -ne 0 ]; then 777688SAaron.Zang@Sun.COM echo "ok 7" 787688SAaron.Zang@Sun.COMelse 797688SAaron.Zang@Sun.COM echo "not ok 7" 807688SAaron.Zang@Sun.COMfi 817688SAaron.Zang@Sun.COM 820Sstevel@tonic-gate# Attach with key 0. 830Sstevel@tonic-gategeli attach -p -k $keyfile3 md${no} 840Sstevel@tonic-gateif [ $? -eq 0 ]; then 850Sstevel@tonic-gate echo "ok 8" 860Sstevel@tonic-gateelse 870Sstevel@tonic-gate echo "not ok 8" 880Sstevel@tonic-gatefi 890Sstevel@tonic-gate 900Sstevel@tonic-gate# Setup key 1. 910Sstevel@tonic-gategeli setkey -n 1 -P -K $keyfile4 md${no} 920Sstevel@tonic-gateif [ $? -eq 0 ]; then 930Sstevel@tonic-gate echo "ok 9" 940Sstevel@tonic-gateelse 950Sstevel@tonic-gate echo "not ok 9" 960Sstevel@tonic-gatefi 977688SAaron.Zang@Sun.COMgeli detach md${no} 987688SAaron.Zang@Sun.COM 997688SAaron.Zang@Sun.COM# Remove key 1 for detached provider. 1007688SAaron.Zang@Sun.COMgeli delkey -n 1 md${no} 1017688SAaron.Zang@Sun.COMif [ $? -eq 0 ]; then 1027688SAaron.Zang@Sun.COM echo "ok 10" 1037688SAaron.Zang@Sun.COMelse 1047688SAaron.Zang@Sun.COM echo "not ok 10" 1050Sstevel@tonic-gatefi 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate# We cannot use keyfile4 anymore. 1080Sstevel@tonic-gategeli attach -p -k $keyfile4 md${no} 2>/dev/null 1090Sstevel@tonic-gateif [ $? -ne 0 ]; then 1100Sstevel@tonic-gate echo "ok 11" 1110Sstevel@tonic-gateelse 1127688SAaron.Zang@Sun.COM echo "not ok 11" 1137688SAaron.Zang@Sun.COMfi 1147688SAaron.Zang@Sun.COM 1157688SAaron.Zang@Sun.COM# We cannot remove last key without -f option (for detached provider). 1167688SAaron.Zang@Sun.COMgeli delkey -n 0 md${no} 2>/dev/null 1177688SAaron.Zang@Sun.COMif [ $? -ne 0 ]; then 1180Sstevel@tonic-gate echo "ok 12" 1190Sstevel@tonic-gateelse 1207688SAaron.Zang@Sun.COM echo "not ok 12" 1217688SAaron.Zang@Sun.COMfi 1227688SAaron.Zang@Sun.COM 1230Sstevel@tonic-gate# Remove last key for detached provider. 1240Sstevel@tonic-gategeli delkey -f -n 0 md${no} 1250Sstevel@tonic-gateif [ $? -eq 0 ]; then 1260Sstevel@tonic-gate echo "ok 13" 1277688SAaron.Zang@Sun.COMelse 1281253Slq150181 echo "not ok 13" 1291253Slq150181fi 1307688SAaron.Zang@Sun.COM 1317688SAaron.Zang@Sun.COM# We cannot use keyfile3 anymore. 1327688SAaron.Zang@Sun.COMgeli attach -p -k $keyfile3 md${no} 2>/dev/null 1337688SAaron.Zang@Sun.COMif [ $? -ne 0 ]; then 1347688SAaron.Zang@Sun.COM echo "ok 14" 1357688SAaron.Zang@Sun.COMelse 1367688SAaron.Zang@Sun.COM echo "not ok 14" 1377688SAaron.Zang@Sun.COMfi 1387688SAaron.Zang@Sun.COM 1390Sstevel@tonic-gatemdconfig -d -u $no 1400Sstevel@tonic-gaterm -f $keyfile1 $keyfile2 $keyfile3 $keyfile4 1410Sstevel@tonic-gate