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 OPEN operation test - negative tests
  27 #       Verify server returns correct errors with negative requests.
  28 
  29 # include all test enironment
  30 source OPEN.env
  31 
  32 # connect to the test server
  33 Connect
  34 
  35 # setting local variables
  36 set TNAME $argv0
  37 set bfh [get_fh $BASEDIRS]
  38 set cid [getclientid $TNAME.[pid]]
  39 if {$cid == -1} {
  40         putmsg stdout 0 "$TNAME: test setup - getclientid"
  41         putmsg stderr 0 "\t Test UNRESOLVED: unable to get clientid"
  42         exit $UNRESOLVED
  43 }
  44 set oseqid 1
  45 set owner "$TNAME-OpenOwner"
  46 
  47 
  48 # Start testing
  49 # --------------------------------------------------------------
  50 # a: Open without Putrootfh, expect NOFILEHANDLE
  51 set expcode "NOFILEHANDLE"
  52 set ASSERTION "Open without Putrootfh, expect $expcode"
  53 set tag "$TNAME{a}"
  54 putmsg stdout 0 "$tag: $ASSERTION"
  55 set res [compound {Open $oseqid 3 0 "$cid $owner-a" \
  56         {0 0 {{mode 0644}}} {0 $env(ROFILE)}}]
  57 ckres "Open" $status $expcode $res $PASS
  58 
  59 
  60 # The following assertions testing SHARE_DENIED
  61 # First OPEN/CREATE a file w/SHARE_DENY_BOTH:
  62 putmsg stdout 0 "  ** First OPEN/CREATE a file w/SHARE_DENY_BOTH;"
  63 set expcode "SHARE_DENIED"
  64 set Tfile "$TNAME.[pid]-DenyBoth"
  65 set tag "OPEN-DenyBoth"
  66 set res [compound {Putfh $bfh; Open $oseqid 2 3 "$cid $Tfile" \
  67         {1 0 {{mode 0664}}} {0 "$Tfile"}; Getfh}]
  68 if {$status != "OK"} {
  69         putmsg stderr 0 "\t Setup UNRESOLVED: Open(SHARE_DENY_BOTH) failed"
  70         putmsg stderr 0 "\t\t  Assertions(e, f, g, h) will not run"
  71         putmsg stderr 1 "\t\t  Res=($res)"
  72 } else {
  73   set stateid [lindex [lindex $res 1] 2]
  74   set rflags [lindex [lindex $res 1] 4] 
  75   set nfh [lindex [lindex $res 2] 2]
  76 
  77   set norun 0
  78   # should confirm if needed:
  79   if {[expr $rflags & $OPEN4_RESULT_CONFIRM] == $OPEN4_RESULT_CONFIRM} {
  80         incr oseqid
  81         set res [compound {Putfh $nfh; Open_confirm $stateid $oseqid}]
  82         if {$status != "OK"} {
  83                 putmsg stdout 0 \
  84                     "  Setup UNRESOLVED: Open_confirm failed, status=($status)."
  85                 putmsg stderr 0 "\t\t  Assertions(e, f, g, h) will not run"
  86                 putmsg stderr 1 "\t\t  Res=($res)"
  87                 set norun 1
  88         }
  89         set stateid [lindex [lindex $res 1] 2]
  90   }
  91 
  92   if { $norun == 0} {
  93   # Now run the assertions for SHARE_DENY_BOTH:
  94   putmsg stdout 0 \
  95         "  ** then following assertions(e,f,g,h) testing Open(SHARE_DENIED):"
  96 
  97   # e: Open(NOCREATE) w/accsss=read, deny=both, expect SHARE_DENIED
  98   set ASSERTION "Open(NOCREATE) w/access=read, deny=both, expect $expcode"
  99   set tag "$TNAME{e}"
 100   putmsg stdout 0 "$tag: $ASSERTION"
 101   set res2 [compound {Putfh $bfh; Open 10 1 0 "$cid $tag.1" \
 102         {0 0 {{mode 0644}}} {0 "$Tfile"}; Getfh}]
 103   ckres "Open" $status $expcode $res $PASS
 104 
 105 
 106   # f: Open(NOCREATE) w/accsss=write, deny=none, expect SHARE_DENIED
 107   set ASSERTION "Open(NOCREATE) w/access=write, deny=none, expect $expcode"
 108   set tag "$TNAME{f}"
 109   putmsg stdout 0 "$tag: $ASSERTION"
 110   set res2 [compound {Putfh $bfh; Open 10 2 0 "$cid $tag.2" \
 111         {0 0 {{mode 0644}}} {0 "$Tfile"}; Getfh}]
 112   ckres "Open" $status $expcode $res $PASS
 113 
 114   # g: Open(NOCREATE) w/accsss=both, deny=read, expect SHARE_DENIED
 115   set ASSERTION "Open(NOCREATE) w/access=both, deny=write, expect $expcode"
 116   set tag "$TNAME{g}"
 117   putmsg stdout 0 "$tag: $ASSERTION"
 118   set res2 [compound {Putfh $bfh; Open 10 3 1 "$cid $tag.3" \
 119         {0 0 {{mode 0644}}} {0 "$Tfile"}; Getfh}]
 120   ckres "Open" $status $expcode $res $PASS
 121 
 122   # h: Open(NOCREATE) w/accsss=both, deny=write, expect SHARE_DENIED
 123   set ASSERTION "Open(NOCREATE) w/access=both, deny=read, expect $expcode"
 124   set tag "$TNAME{h}"
 125   putmsg stdout 0 "$tag: $ASSERTION"
 126   set res2 [compound {Putfh $bfh; Open 10 3 2 "$cid $tag.4" \
 127         {0 0 {{mode 0644}}} {0 "$Tfile"}; Getfh}]
 128   ckres "Open" $status $expcode $res $PASS
 129 
 130   # Close the orginal OPEN file
 131   incr oseqid
 132   set res [compound {Putfh $nfh; Close $oseqid "$stateid"}]
 133 
 134   }
 135 }
 136 
 137 
 138 # Now try OPEN/CREATE a file w/SHARE_DENY_WRITE:
 139 putmsg stdout 0 "  ** Now OPEN/CREATE a file w/SHARE_DENY_WRITE;"
 140 putmsg stdout 0 "  ** the assertions(m,n) testing Open(SHARE_DENIED):"
 141 set expcode "SHARE_DENIED"
 142 set Tfile2 "$TNAME.[pid]-DenyWrite"
 143 set res [compound {Putfh $bfh; Open $oseqid 3 2 "$cid $Tfile2" \
 144         {1 0 {{mode 0664}}} {0 "$Tfile2"}; Getfh}]
 145 if {$status != "OK"} {
 146         putmsg stderr 0 "\t Setup UNRESOLVED: Open(SHARE_DENY_WRITE) failed"
 147         putmsg stderr 0 "\t\t  Assertions(m, n) will not run"
 148         putmsg stderr 1 "\t\t  Res=($res)"
 149 } else {
 150   set stateid [lindex [lindex $res 1] 2]
 151   set rflags [lindex [lindex $res 1] 4] 
 152   set nfh [lindex [lindex $res 2] 2]
 153 
 154   set norun 0
 155   # should confirm if needed:
 156   if {[expr $rflags & $OPEN4_RESULT_CONFIRM] == $OPEN4_RESULT_CONFIRM} {
 157         incr oseqid
 158         set res [compound {Putfh $nfh; Open_confirm $stateid $oseqid}]
 159         if {$status != "OK"} {
 160                 putmsg stdout 0 \
 161                     "  Setup UNRESOLVED: Open_confirm failed, status=($status)."
 162                 putmsg stderr 0 "\t\t  Assertions(m, n) will not run"
 163                 putmsg stderr 1 "\t\t  Res=($res)"
 164                 set norun 1
 165         }
 166         set stateid [lindex [lindex $res 1] 2]
 167   }
 168 
 169   if { $norun == 0} {
 170   # Now run the assertions for SHARE_DENY_BOTH:
 171 
 172   # m: Open(NOCREATE) w/accsss=RW, deny=none, expect SHARE_DENIED
 173   set ASSERTION "Open(NOCREATE) w/access=RW, deny=none, expect $expcode"
 174   set tag "$TNAME{m}"
 175   putmsg stdout 0 "$tag: $ASSERTION"
 176   set res2 [compound {Putfh $bfh; Open 20 3 0 "$cid $tag.10" \
 177         {0 0 {{mode 0644}}} {0 "$Tfile2"}; Getfh}]
 178   ckres "Open" $status $expcode $res $PASS
 179 
 180   # n-1: Make the open owner valid (prepare for the replay OPEN op - "n1")
 181   set ASSERTION "Open an existing file (create valid open-owner), expect OK"
 182   set tag "$TNAME{n-1}"
 183   putmsg stdout 0 "$tag: $ASSERTION"
 184   set oowner22 "$TNAME.[pid].22"
 185   set no_n1 0
 186   set fhn_1 \
 187   [basic_open $bfh $env(RWFILE) 0 "$cid $oowner22" osid_n1 oseqid_n1 status] 
 188   if {$fhn_1 == -1} {
 189       putmsg stderr 0 "\t Test UNRESOLVED: basic_open failed, status=($status)"
 190       putmsg stderr 0 "\t      and assertion <n1> below will not be run"
 191       set no_n1 1
 192   } else {
 193       logres "PASS"
 194   }
 195   if {[should_seqid_incr $status] == 1} {
 196       incr oseqid_n1
 197   }
 198 
 199   # n: Open(CREATE/UNCHECKED) w/accsss=W, deny=none, expect SHARE_DENIED
 200   set ASSERTION "Open(CREATE/UNCHECKED) w/access=W, deny=none, expect $expcode"
 201   set tag "$TNAME{n}"
 202   putmsg stdout 0 "$tag: $ASSERTION"
 203   set res2 [compound {Putfh $bfh; Open $oseqid_n1 2 0 "$cid $oowner22" \
 204         {1 0 {{mode 0644}}} {0 "$Tfile2"}; Getfh}]
 205   ckres "Open" $status $expcode $res $PASS
 206 
 207   # Close the orginal OPEN file
 208   incr oseqid
 209   set res [compound {Putfh $nfh; Close $oseqid "$stateid"}]
 210   if {$status != "OK"} {
 211       putmsg stderr 0 "  ** Closing the orginal file for <n1>"
 212       putmsg stderr 0 "\t WARNING: Close failed, status=($status)"
 213       putmsg stderr 0 "\t      and assertion <n1> below will not be run"
 214       set no_n1 1
 215   }
 216 
 217   if {$no_n1 == 0} {
 218       # n1: Replay {n}, open(CREATE/UNCHECKED), expect SHARE_DENIED
 219       set ASSERTION "Replay {n} Open(CREATE/UNCHECKED), expect $expcode"
 220       set tag "$TNAME{n1}"
 221       putmsg stdout 0 "$tag: $ASSERTION"
 222       set res2 [compound {Putfh $bfh; Open $oseqid_n1 2 0 "$cid $oowner22" \
 223             {1 0 {{mode 0644}}} {0 "$Tfile2"}; Getfh}]
 224       ckres "Open-replay" $status $expcode $res2 $PASS
 225 
 226       # now close the dummy fh
 227       incr oseqid_n1
 228       set res3 [compound {Putfh $fhn_1; Close $oseqid_n1 $osid_n1}]
 229       putmsg stdout 1 "Final close on dummy fh, res=($res3)"
 230   }
 231  }
 232 }
 233 
 234 
 235 # Now try OPEN/CREATE a file w/SHARE_DENY_READ:
 236 putmsg stdout 0 "  ** Now OPEN/CREATE a file w/SHARE_DENY_READ;"
 237 putmsg stdout 0 "  ** the assertions(r,s) testing Open(SHARE_DENIED):"
 238 set expcode "SHARE_DENIED"
 239 set Tfile3 "$TNAME.[pid]-DenyRead"
 240 set oseqid 100
 241 set res [compound {Putfh $bfh; Open $oseqid 3 1 "$cid $Tfile3" \
 242         {1 0 {{mode 0664}}} {0 "$Tfile3"}; Getfh}]
 243 if {$status != "OK"} {
 244         putmsg stderr 0 "\t Setup UNRESOLVED: Open(SHARE_DENY_READ) failed"
 245         putmsg stderr 0 "\t\t  Assertions(r, s) will not run"
 246         putmsg stderr 0 "\t\t  Res=($res)"
 247 } else {
 248   set stateid [lindex [lindex $res 1] 2]
 249   set rflags [lindex [lindex $res 1] 4] 
 250   set nfh [lindex [lindex $res 2] 2]
 251   set norun 0
 252   # should confirm if needed:
 253   if {[expr $rflags & $OPEN4_RESULT_CONFIRM] == $OPEN4_RESULT_CONFIRM} {
 254         incr oseqid
 255         set res [compound {Putfh $nfh; Open_confirm $stateid $oseqid}]
 256         if {$status != "OK"} {
 257                 putmsg stdout 0 \
 258                     "  Setup UNRESOLVED: Open_confirm failed, status=($status)."
 259                 putmsg stderr 0 "\t\t  Assertions(r, s) will not run"
 260                 putmsg stderr 1 "\t\t  Res=($res)"
 261                 set norun 1
 262         }
 263         set stateid [lindex [lindex $res 1] 2]
 264   }
 265 
 266   if { $norun == 0} {
 267   # Now run the assertions for SHARE_DENY_BOTH:
 268 
 269   # r: Open(NOCREATE) w/accsss=RW, deny=none, expect SHARE_DENIED
 270   set ASSERTION "Open(NOCREATE) w/access=RW, deny=none, expect $expcode"
 271   set tag "$TNAME{r}"
 272   putmsg stdout 0 "$tag: $ASSERTION"
 273   set res2 [compound {Putfh $bfh; Open 30 3 0 "$cid $tag.01" \
 274         {0 0 {{mode 0644}}} {0 "$Tfile3"}; Getfh}]
 275   ckres "Open" $status $expcode $res $PASS
 276 
 277 
 278   # s: Open(CREATE/UNCHECKED) w/accsss=R, deny=none, expect SHARE_DENIED
 279   set ASSERTION "Open(CREATE/UNCHECKED) w/access=R, deny=none, expect $expcode"
 280   set tag "$TNAME{s}"
 281   putmsg stdout 0 "$tag: $ASSERTION"
 282   set res2 [compound {Putfh $bfh; Open 50 1 0 "$cid $tag.12" \
 283         {0 0 {{mode 0644}}} {0 "$Tfile3"}; Getfh}]
 284   ckres "Open" $status $expcode $res $PASS
 285 
 286   # Close the orginal OPEN file
 287   incr oseqid
 288   set res [compound {Putfh $nfh; Close $oseqid "$stateid"}]
 289   }
 290 }
 291 
 292 # The following assertion test self 'deny'
 293 putmsg stdout 0 "  ** The following assertion test 'self-deny' ..."
 294 set expcode "SHARE_DENIED"
 295 set tag "$TNAME{u}"
 296 set As "Doing the following with same open-owner, expect $expcode\n"
 297 set As "$As\tOPEN(acc=R,deny=N), OPEN(acc=W,deny=N), should get OK\n"
 298 set ASSERTION "$As\tthen OPEN(acc=W,deny=W) should be denied"
 299 putmsg stdout 0 "$tag: $ASSERTION"
 300 set Tfileu "$tag-SelfDeny"
 301 set oou "$Tfileu"
 302 set fh1 [basic_open $bfh $Tfileu 1 "$cid $oou" osid oseqid status \
 303         1 0 0666 0 1 0 0] 
 304 if { $fh1 == -1 } {
 305     putmsg stderr 0 "\t Test UNRESOLVED: "
 306     putmsg stderr 0 "\t   basic_open(acc=R,deny=N) failed, status=($status)"
 307 } else {
 308     incr oseqid
 309     set fh2 [basic_open $bfh $Tfileu 0 "$cid $oou" osid oseqid status \
 310         $oseqid 0 0666 0 2 0 0] 
 311     if { $fh2 == -1 } {
 312         putmsg stderr 0 "\t Test UNRESOLVED: "
 313         putmsg stderr 0 "\t   basic_open(acc=W,deny=N) failed, status=($status)"
 314     } else {
 315         incr oseqid
 316         set fh3 [basic_open $bfh $Tfileu 0 "$cid $oou" osid oseqid status \
 317                 $oseqid 0 0666 0 2 2 0] 
 318         if { $status != $expcode } {
 319                 putmsg stderr 0 "\t Test FAIL: basic_open(acc=W,deny=W) failed"
 320                 putmsg stderr 0 "\t   status=($status), expected=($expcode)"
 321         } else {
 322                 logres "PASS"
 323         }
 324     }
 325 }
 326 
 327 # --------------------------------------------------------------
 328 # Now cleanup, and removed created tmp file
 329 set res [compound {Putfh $bfh; Remove $Tfile; Remove $Tfile2; \
 330         Remove $Tfile3; Remove $Tfileu}]
 331 if {($status != "OK") && ($status != "NOENT")} {
 332         putmsg stderr 0 "\t WARNING: cleanup to remove created tmp file failed"
 333         putmsg stderr 0 "\t          status=$status; please cleanup manually."
 334         putmsg stderr 1 "\t   res=($res)"
 335         putmsg stderr 1 "  "
 336         exit $WARNING
 337 }
 338 
 339 # --------------------------------------------------------------
 340 # disconnect and exit
 341 Disconnect
 342 exit $PASS