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