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 2009 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:  zpool_set_002_neg
34#
35# DESCRIPTION:
36#
37# Malformed zpool set commands are rejected
38#
39# STRATEGY:
40#	1. Create an array of many different malformed zfs set arguments
41#	2. Run zpool set for each arg checking each will exit with status code 1
42#
43#
44# TESTABILITY: explicit
45#
46# TEST_AUTOMATION_LEVEL: automated
47#
48# CODING_STATUS: COMPLETED (2007-03-05)
49#
50# __stc_assertion_end
51#
52################################################################################
53
54verify_runnable "global"
55
56# note to self - need to make sure there isn't a pool called bootfs
57# before running this test...
58function cleanup {
59	destroy_pool bootfs
60	$RM $TMPDIR/zpool_set_002.${TESTCASE_ID}.dat
61}
62
63$ZPOOL upgrade -v 2>&1 | $GREP "bootfs pool property" > /dev/null
64if [ $? -ne 0 ]
65then
66	log_unsupported "Pool properties not supported on this release."
67fi
68
69
70log_assert "Malformed zpool set commands are rejected"
71
72if poolexists bootfs
73then
74	log_unsupported "Unable to run test on a machine with a pool called \
75 bootfs"
76fi
77
78log_onexit cleanup
79
80# build up an array of bad arguments.
81set -A arguments "rubbish " \
82		"foo@bar= " \
83		"@@@= +pool " \
84		"zpool bootfs " \
85		"bootfs " \
86		"bootfs +" \
87		"bootfs=bootfs/123 " \
88		"bootfs=bootfs@val " \
89		"Bootfs=bootfs " \
90		"- " \
91		"== " \
92		"set " \
93		"@@ " \
94		"12345 " \
95		"€にほんご " \
96		"/ " \
97		"bootfs=bootfs /" \
98		"bootfs=a%d%s "
99
100
101# here, we build up a large string.
102# a word to the ksh-wary, ${#array[@]} gives you the
103# total number of entries in an array, so array[${#array[@]}]
104# will index the last entry+1, ksh arrays start at index 0.
105COUNT=0
106while [ $COUNT -le 1025 ]
107do
108	bigname="${bigname}o"
109	COUNT=$(( $COUNT + 1 ))
110done
111
112# add an argument of maximum length property name
113arguments[${#arguments[@]}]="$bigname=value"
114
115# add an argument of maximum length property value
116arguments[${#arguments[@]}]="bootfs=$bigname"
117
118# Create a pool called bootfs (so-called, so as to trip any clashes between
119# property name, and pool name)
120# Also create a filesystem in this pool
121VDEV=$TMPDIR/zpool_set_002.${TESTCASE_ID}.vdev
122log_must create_vdevs $VDEV
123log_must $ZPOOL create bootfs $VDEV
124log_must $ZFS create bootfs/root
125
126typeset -i i=0;
127while [ $i -lt "${#arguments[@]}" ]
128do
129	log_mustnot eval "$ZPOOL set ${arguments[$i]} > /dev/null 2>&1"
130
131	# now also try with a valid pool in the argument list
132	log_mustnot eval "$ZPOOL set ${arguments[$i]}bootfs > /dev/null 2>&1"
133
134	# now also try with two valid pools in the argument list
135	log_mustnot eval "$ZPOOL set ${arguments[$i]}bootfs bootfs > /dev/null"
136	i=$(( $i + 1))
137done
138
139log_pass "Malformed zpool set commands are rejected"
140