1 #!/bin/ksh -p 2 # 3 # CDDL HEADER START 4 # 5 # The contents of this file are subject to the terms of the 6 # Common Development and Distribution License (the "License"). 7 # You may not use this file except in compliance with the License. 8 # 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 # or http://www.opensolaris.org/os/licensing. 11 # See the License for the specific language governing permissions 12 # and limitations under the License. 13 # 14 # When distributing Covered Code, include this CDDL HEADER in each 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 # If applicable, add the following below this CDDL HEADER, with the 17 # fields enclosed by brackets "[]" replaced with your own identifying 18 # information: Portions Copyright [yyyy] [name of copyright owner] 19 # 20 # CDDL HEADER END 21 # 22 23 # 24 # Copyright 2008 Sun Microsystems, Inc. All rights reserved. 25 # Use is subject to license terms. 26 # 27 28 # 29 # Copyright (c) 2013 by Delphix. All rights reserved. 30 # 31 32 . $STF_SUITE/include/libtest.shlib 33 34 # 35 # DESCRIPTION: 36 # 37 # Ensure that a set of invalid names cannot be used to create pools. 38 # 39 # STRATEGY: 40 # 1) For each invalid character in the character set, try to create 41 # and destroy the pool. Verify it fails. 42 # 2) Given a list of invalid pool names, ensure the pools are not 43 # created. 44 # 45 46 verify_runnable "global" 47 48 log_assert "Ensure that a set of invalid names cannot be used to create pools." 49 50 # Global variable use to cleanup failures. 51 POOLNAME="" 52 53 function cleanup 54 { 55 if poolexists $POOLNAME; then 56 log_must $ZPOOL destroy $POOLNAME 57 fi 58 59 if [[ -d $TESTDIR ]]; then 60 log_must $RM -rf $TESTDIR 61 fi 62 } 63 64 log_onexit cleanup 65 66 typeset exclude=`eval $ECHO \"'(${KEEP})'\"` 67 for pool in $($ZPOOL list -H -o name | \ 68 $EGREP -v "$exclude" | \ 69 $GREP -v "$TESTPOOL" | \ 70 $EGREP -v "$NO_POOLS"); do 71 log_must $ZPOOL destroy $pool 72 done 73 74 DISK=${DISKS%% *} 75 if [[ ! -e $TESTDIR ]]; then 76 log_must $MKDIR $TESTDIR 77 fi 78 79 log_note "Ensure invalid characters fail" 80 for POOLNAME in "!" "\"" "#" "$" "%" "&" "'" "(" ")" \ 81 "\*" "+" "," "-" "\." "/" "\\" \ 82 0 1 2 3 4 5 6 7 8 9 \ 83 ":" ";" "<" "=" ">" "\?" "@" \ 84 "[" "]" "^" "_" "\`" "{" "|" "}" "~" 85 do 86 log_mustnot $ZPOOL create -m $TESTDIR $POOLNAME $DISK 87 if poolexists $POOLNAME; then 88 log_fail "Unexpectedly created pool: '$POOLNAME'" 89 fi 90 91 log_mustnot $ZPOOL destroy $POOLNAME 92 done 93 94 log_note "Check that invalid octal values fail" 95 for oct in "\000" "\001" "\002" "\003" "\004" "\005" "\006" "\007" \ 96 "\010" "\011" "\012" "\013" "\014" "\015" "\017" \ 97 "\020" "\021" "\022" "\023" "\024" "\025" "\026" "\027" \ 98 "\030" "\031" "\032" "\033" "\034" "\035" "\036" "\037" \ 99 "\040" "\177" 100 do 101 POOLNAME=`eval "echo x | tr 'x' '$oct'"` 102 log_mustnot $ZPOOL create -m $TESTDIR $POOLNAME $DISK 103 if poolexists $POOLNAME; then 104 log_fail "Unexpectedly created pool: '$POOLNAME'" 105 fi 106 107 log_mustnot $ZPOOL destroy $POOLNAME 108 done 109 110 log_note "Verify invalid pool names fail" 111 set -A POOLNAME "c0t0d0s0" "c0t0d0" "c0t0d19" "c0t50000E0108D279d0" \ 112 "mirror" "raidz" ",," ",,,,,,,,,,,,,,,,,,,,,,,,," \ 113 "2222222222222222222" "mirror_pool" "raidz_pool" \ 114 "mirror-pool" "raidz-pool" "spare" "spare_pool" \ 115 "spare-pool" "raidz1-" "raidz2:" ":aaa" "-bbb" "_ccc" ".ddd" 116 if verify_slog_support ; then 117 POOLNAME[${#POOLNAME[@]}]='log' 118 fi 119 typeset -i i=0 120 while ((i < ${#POOLNAME[@]})); do 121 log_mustnot $ZPOOL create -m $TESTDIR ${POOLNAME[$i]} $DISK 122 if poolexists ${POOLNAME[$i]}; then 123 log_fail "Unexpectedly created pool: '${POOLNAME[$i]}'" 124 fi 125 126 log_mustnot $ZPOOL destroy ${POOLNAME[$i]} 127 128 ((i += 1)) 129 done 130 131 log_pass "Invalid names and characters were caught correctly"