1 #
2 # CDDL HEADER START
3 #
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
7 #
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
12 #
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
18 #
19 # CDDL HEADER END
20 #
21
22 #
23 # Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
25 #
26 # NFSv4 RENAME operation test - negative tests
27
28 # include all test enironment
29 source RENAME.env
30
31 # connect to the test server
32 Connect
33
34 # setting local variables
35 set TNAME $argv0
36 set bfh [get_fh "$BASEDIRS"]
37
38 # create a tmp file to be rename
39 set tmpf Renm2file.[pid]
40 creatv4_file [file join $BASEDIR $tmpf]
41
42 # Start testing
43 # --------------------------------------------------------------
44 # a: Rename without Putrootfh, expect NOFILEHANDLE
45 set expcode "NOFILEHANDLE"
46 set ASSERTION "Try to Rename with no Putrootfh, expect $expcode"
47 putmsg stdout 0 "$TNAME{a}: $ASSERTION"
48 set res [compound {Rename $tmpf Renm1A.[pid]}]
49 set cont [ckres "Rename" $status $expcode $res $FAIL]
50 # check newname does not exist
51 if {! [string equal $cont "false"]} {
52 set res [compound {Putfh $bfh; Lookup "Renm1A.[pid]"}]
53 if { $status != "NOENT" } {
54 putmsg stderr 0 "\t Test FAIL: newname exists after Rename failed"
55 putmsg stderr 1 "\t res=($res)"
56 } else {
57 logres PASS
58 }
59 }
60
61
62 # b: Rename without SaveFH, expect NOFILEHANDLE
63 set expcode "NOFILEHANDLE"
64 set ASSERTION "Try to Rename with no SaveFH, expect $expcode"
65 putmsg stdout 0 "$TNAME{b}: $ASSERTION"
66 set res [compound {Putfh $bfh; Rename $tmpf Renm1B.[pid]}]
67 set cont [ckres "Rename" $status $expcode $res $FAIL]
68 # check newname does not exist
69 if {! [string equal $cont "false"]} {
70 set res [compound {Putfh $bfh; Lookup "Renm1B.[pid]"}]
71 if { $status != "NOENT" } {
72 putmsg stderr 0 "\t Test FAIL: newname exists after Rename failed"
73 putmsg stderr 1 "\t res=($res)"
74 } else {
75 logres PASS
76 }
77 }
78
79
80 # c: Rename with oldname=file, newname=dir and exist, expect ISDIR
81 set expcode "ISDIR"
82 set ASSERTION "Rename w/oldname=file,newname=dir and exist, expect $expcode"
83 putmsg stdout 0 "$TNAME{c}: $ASSERTION"
84 set res [compound {Putfh $bfh; Savefh;
85 Putfh $bfh; Rename "$env(TEXTFILE)" "$env(DIR0777)"}]
86 set cont [ckres "Rename" $status $expcode $res $FAIL]
87 # check both newname and oldname exist
88 if {! [string equal $cont "false"]} {
89 set res [compound {Putfh $bfh; Lookup $env(TEXTFILE);
90 Putfh $bfh; Lookup $env(DIR0777)}]
91 if { $status == "NOENT" } {
92 putmsg stderr 0 \
93 "\t Test FAIL: old/new name doesn't exist after Rename failed"
94 putmsg stderr 1 "\t res=($res)"
95 } else {
96 logres PASS
97 }
98 }
99
100
101 # d: Rename with oldname=dir, newname=file and exist, expect NOTDIR
102 set expcode "NOTDIR"
103 set ASSERTION "Try to Rename to a directory, expect $expcode"
104 putmsg stdout 0 "$TNAME{d}: $ASSERTION"
105 set res [compound {Putfh $bfh; Getattr type; Savefh;
106 Putfh $bfh; Rename $env(DIR0777) $env(RWFILE)}]
107 set cont [ckres "Rename" $status $expcode $res $FAIL]
108 # check both newname and oldname exist
109 if {! [string equal $cont "false"]} {
110 set res [compound {Putfh $bfh; Lookup $env(RWFILE);
111 Putfh $bfh; Lookup $env(DIR0777)}]
112 if { $status == "NOENT" } {
113 putmsg stderr 0 \
114 "\t Test FAIL: old/new name doesn't exist after Rename failed"
115 putmsg stderr 1 "\t res=($res)"
116 } else {
117 logres PASS
118 }
119 }
120
121
122 # e: Rename with CURRENT_FH is a file, expect NOTDIR
123 set expcode "NOTDIR"
124 set ASSERTION "Rename with CURRENT_FH is a file, expect $expcode"
125 putmsg stdout 0 "$TNAME{e}: $ASSERTION"
126 set res [compound {Putfh $bfh; Lookup $env(RWFILE); Savefh;
127 Rename $tmpf "Ren1E.[pid]"}]
128 set cont [ckres "Rename" $status $expcode $res $FAIL]
129 # check newname does not exist
130 if {! [string equal $cont "false"]} {
131 set res [compound {Putfh $bfh; Lookup "Renm1E.[pid]"}]
132 if { $status != "NOENT" } {
133 putmsg stderr 0 "\t Test FAIL: newname exists after Rename failed"
134 putmsg stderr 1 "\t res=($res)"
135 } else {
136 logres PASS
137 }
138 }
139
140
141 # f: Rename with SAVED_FH is a file, expect NOTDIR
142 set expcode "NOTDIR"
143 set ASSERTION "Rename with SAVED_FH is a file, expect $expcode"
144 putmsg stdout 0 "$TNAME{f}: $ASSERTION"
145 set res [compound {Putfh $bfh; Lookup $env(RWFILE); Savefh;
146 Putfh $bfh; Rename $tmpf "Renm1F.[pid]"}]
147 set cont [ckres "Rename" $status $expcode $res $FAIL]
148 # check oldname still exist
149 if {! [string equal $cont "false"]} {
150 set res [compound {Putfh $bfh; Lookup "$tmpf"}]
151 if { $status == "NOENT" } {
152 putmsg stderr 0 "\t Test FAIL: oldname is gone after Rename failed"
153 putmsg stderr 1 "\t res=($res)"
154 putmsg stderr 1 "\t oldname=($tmpf)"
155 } else {
156 logres PASS
157 }
158 }
159
160
161 # g: Rename with oldname=dir, newname=dir but not empty, expect EXIST
162 set expcode "EXIST"
163 set ASSERTION "Rename w/oldname&newname=dir but not empty, expect $expcode"
164 putmsg stdout 0 "$TNAME{g}: $ASSERTION"
165 set tmpG "RendirG.[pid]"
166 set res [compound {Putfh $bfh; Savefh; Create $tmpG {{mode 0777}} d;
167 Putfh $bfh; Rename "$tmpG" "$env(DIR0777)"}]
168 set cont [ckres "Rename" $status $expcode $res $FAIL]
169 # check oldname still exist
170 if {! [string equal $cont "false"]} {
171 set res [compound {Putfh $bfh; Lookup "$env(DIR0777)"}]
172 if { $status == "NOENT" } {
173 putmsg stderr 0 "\t Test FAIL: newname is gone after Rename failed"
174 putmsg stderr 1 "\t res=($res)"
175 putmsg stderr 1 "\t newname=($env(DIR0777))"
176 } else {
177 logres PASS
178 }
179 }
180
181
182 # h: Rename with WrongSec, expect WRONGSEC
183 set expcode "WRONGSEC"
184 set ASSERTION "Rename with WrongSec, expect $expcode"
185 #putmsg stdout 0 "$TNAME{h}: $ASSERTION"
186 #puts "\t Test UNTESTED: XXX need server to change <cfh> w/KRB5.\n"
187
188
189 # i: XXX how do we simulate some server errors:
190 # NFS4ERR_IO
191 # NFS4ERR_MOVE
192 # NFS4ERR_SERVERFAULT
193 # NFS4ERR_RESOURCE
194
195
196 # m: try to Rename with CFH expired, expect FHEXPIRED
197 set expcode "FHEXPIRED"
198 set ASSERTION "Rename with CFH expired, expect $expcode"
199 #putmsg stdout 0 "$TNAME{m}: $ASSERTION"
200 #puts "\t Test UNTESTED: XXX need hook to get FH expired.\n"
201
202
203 # n: try to Rename with SFH expired, expect FHEXPIRED
204 set expcode "FHEXPIRED"
205 set ASSERTION "Rename with SFH expired, expect $expcode"
206 #putmsg stdout 0 "$TNAME{n}: $ASSERTION"
207 #puts "\t Test UNTESTED: XXX need hook to get FH expired.\n"
208
209
210 # u: try to Rename into noperm_dir, expect ACCESS
211 set expcode "ACCESS"
212 set ASSERTION "try to Rename into noperm_dir, expect $expcode"
213 putmsg stdout 0 "$TNAME{u}: $ASSERTION"
214 set res [compound {Putfh $bfh; Savefh; Lookup "$env(DNOPERM)";
215 Rename $env(ROFILE) "Ren1u.[pid]"}]
216 set cont [ckres "Rename" $status $expcode $res $FAIL]
217 # check newname should not exist
218 if {! [string equal $cont "false"]} {
219 set res [compound {Putfh $bfh; Lookup "en1u.[pid]"}]
220 if { $status == "OK" } {
221 putmsg stderr 0 "\t Test FAIL: newname exists after Rename failed"
222 putmsg stderr 1 "\t res=($res)"
223 } else {
224 logres PASS
225 }
226 }
227
228
229 # v: try to Rename a file from noperm_dir, expect ACCESS
230 set expcode "ACCESS"
231 set ASSERTION "try to Rename a file from noperm_dir, expect $expcode"
232 putmsg stdout 0 "$TNAME{v}: $ASSERTION"
233 set res [compound {Putfh $bfh; Lookup "$env(DNOPERM)"; Savefh;
234 Putfh $bfh; Rename $tmpf "Ren1u.[pid]"}]
235 set cont [ckres "Rename" $status $expcode $res $FAIL]
236 # check oldname still exist
237 if {! [string equal $cont "false"]} {
238 set res [compound {Putfh $bfh; Lookup "$tmpf"}]
239 if { $status == "NOENT" } {
240 putmsg stderr 0 "\t Test FAIL: oldname is gone after Rename failed"
241 putmsg stderr 1 "\t res=($res)"
242 } else {
243 logres PASS
244 }
245 }
246
247
248 # --------------------------------------------------------------
249 # Final cleanup:
250 # remove the created temp files/dirs
251 set res [compound {Putfh $bfh; Remove $tmpf; Remove $tmpG}]
252 if { "$status" != "OK" } {
253 putmsg stderr 0 "\t WARNING: cleanup to remove created files failed"
254 putmsg stderr 0 "\t status=$status; please cleanup manually."
255 putmsg stderr 1 "\t res=($res)"
256 putmsg stderr 1 " "
257 exit $WARNING
258 }
259
260 # disconnect and exit
261 Disconnect
262 exit $PASS