1#!/usr/local/bin/ksh93 -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# $FreeBSD$ 24 25# 26# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 27# Use is subject to license terms. 28# 29# ident "@(#)pool_names_002_neg.ksh 1.4 08/11/03 SMI" 30# 31 32. $STF_SUITE/include/libtest.kshlib 33 34############################################################################### 35# 36# __stc_assertion_start 37# 38# ID: pool_names_002_neg 39# 40# DESCRIPTION: 41# 42# Ensure that a set of invalid names cannot be used to create pools. 43# 44# STRATEGY: 45# 1) For each invalid character in the character set, try to create 46# and destroy the pool. Verify it fails. 47# 2) Given a list of invalid pool names, ensure the pools are not 48# created. 49# 50# TESTABILITY: explicit 51# 52# TEST_AUTOMATION_LEVEL: automated 53# 54# CODING_STATUS: COMPLETED (2005-11-21) 55# 56# __stc_assertion_end 57# 58################################################################################ 59 60verify_runnable "global" 61 62log_assert "Ensure that a set of invalid names cannot be used to create pools." 63 64# Global variable use to cleanup failures. 65POOLNAME="" 66 67function cleanup 68{ 69 destroy_pool $POOLNAME 70 71 if [[ -d $TESTDIR ]]; then 72 log_must $RM -rf $TESTDIR 73 fi 74} 75 76log_onexit cleanup 77 78if [[ ! -e $TESTDIR ]]; then 79 log_must $MKDIR $TESTDIR 80fi 81 82log_note "Ensure invalid characters fail" 83for POOLNAME in "!" "\"" "#" "$" "%" "&" "'" "(" ")" \ 84 "\*" "+" "," "-" "\." "/" "\\" \ 85 ":" ";" "<" "=" ">" "\?" "@" \ 86 "[" "]" "^" "_" "\`" "{" "|" "}" "~" 87do 88 log_mustnot $ZPOOL create -m $TESTDIR $POOLNAME $DISK 89 if poolexists $POOLNAME; then 90 log_fail "Unexpectedly created pool: '$POOLNAME'" 91 fi 92 93 log_mustnot $ZPOOL destroy $POOLNAME 94done 95 96# poolexists cannot be used to test pools with numeric names, because 97# "zpool list" will interpret the name as a repeat interval and never return. 98log_note "Ensure invalid characters fail" 99for POOLNAME in 0 1 2 3 4 5 6 7 8 9 2222222222222222222 100do 101 log_mustnot $ZPOOL create -m $TESTDIR $POOLNAME $DISK 102 log_mustnot $ZPOOL destroy $POOLNAME 103done 104 105log_note "Check that invalid octal values fail" 106for oct in "\000" "\001" "\002" "\003" "\004" "\005" "\006" "\007" \ 107 "\010" "\011" "\012" "\013" "\014" "\015" "\017" \ 108 "\020" "\021" "\022" "\023" "\024" "\025" "\026" "\027" \ 109 "\030" "\031" "\032" "\033" "\034" "\035" "\036" "\037" \ 110 "\040" "\177" 111do 112 # Be careful not to print the poolname, because it might be a terminal 113 # control character 114 POOLNAME=`eval "print x | tr 'x' '$oct'"` 115 $ZPOOL create -m $TESTDIR $POOLNAME $DISK > /dev/null 2>&1 116 if [ $? = 0 ]; then 117 log_fail "Unexpectedly created pool: \"$oct\"" 118 elif poolexists $POOLNAME; then 119 log_fail "Unexpectedly created pool: \"$oct\"" 120 fi 121 122 $ZPOOL destroy $POOLNAME > /dev/null 2>&1 123 if [ $? = 0 ]; then 124 log_fail "Unexpectedly destroyed pool: \"$oct\"" 125 fi 126done 127 128log_note "Verify invalid pool names fail" 129set -A POOLNAME "c0t0d0s0" "c0t0d0" "c0t0d19" "c0t50000E0108D279d0" \ 130 "mirror" "raidz" ",," ",,,,,,,,,,,,,,,,,,,,,,,,," \ 131 "mirror_pool" "raidz_pool" \ 132 "mirror-pool" "raidz-pool" "spare" "spare_pool" \ 133 "spare-pool" "raidz1-" "raidz2:" ":aaa" "-bbb" "_ccc" ".ddd" 134POOLNAME[${#POOLNAME[@]}]='log' 135typeset -i i=0 136while ((i < ${#POOLNAME[@]})); do 137 log_mustnot $ZPOOL create -m $TESTDIR ${POOLNAME[$i]} $DISK 138 if poolexists ${POOLNAME[$i]}; then 139 log_fail "Unexpectedly created pool: '${POOLNAME[$i]}'" 140 fi 141 142 log_mustnot $ZPOOL destroy ${POOLNAME[$i]} 143 144 ((i += 1)) 145done 146 147log_pass "Invalid names and characters were caught correctly" 148