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 numbered attributes:
  27 #
  28 # a: Test get attr FATTR4_OWNER stringname of a file, expect OK 
  29 # b: Test get/set attr FATTR4_OWNER_GROUP stringname of file, expect OK
  30 #
  31 
  32 set TESTROOT $env(TESTROOT)
  33 set delm $env(DELM)
  34 
  35 # include common code and init section
  36 source ${TESTROOT}${delm}tcl.init
  37 source ${TESTROOT}${delm}testproc
  38 
  39 # connect to the test server
  40 Connect
  41 
  42 # setting local variables
  43 set TNAME $argv0
  44 set expcode "OK"
  45 
  46 # Get testfile pathname
  47 set filename "newfile.[pid]"
  48 set bfh [get_fh "$BASEDIRS"]
  49 set tfile "[creatv4_file "$BASEDIR/$filename" 777]"
  50 
  51 # Start testing
  52 # ---------------------------------------------------------------
  53 # a: Test get attr FATTR4_OWNER of a file object, expect OK
  54 
  55 set ASSERTION "Test get attr FATTR4_OWNER of a file object, expect OK"
  56 putmsg stdout 0 "$TNAME{a}: $ASSERTION"
  57 
  58 # Setup testfile for attribute purposes
  59 set attr {owner}
  60 #Get the filehandle of the test file 
  61 set res [compound {
  62         Putfh $bfh;
  63         Lookup $filename;
  64         Getfh;
  65         Getattr $attr
  66 }]
  67 set cont [ckres "Getattr" $status $expcode $res $FAIL]
  68 
  69 if { ![string equal $cont "false"] } {
  70 
  71 # Get the Getattr value returned by op
  72 set attrval [ extract_attr [lindex [lindex $res 3] 2] $attr ]
  73 
  74 # Extract the owner name string returned from Getattr
  75 set newstr [ lindex $attrval 0 ]
  76 putmsg stdout 1 "newstr is $newstr"
  77 set strindex [string first @ $newstr]
  78 if {$strindex == -1} {
  79         set getattr_str $newstr
  80 } else {
  81         set getattr_str [string range $newstr 0 [expr $strindex-1]]
  82 }
  83 putmsg stdout 1 "strindex is $strindex"
  84 
  85 # Get the TCL command unix version of the file owner
  86 set attrs [file attributes $MNTPTR${delm}$filename]
  87 set expval [lindex $attrs 3]
  88 
  89 # Compare these strings
  90 if {[string equal $expval $getattr_str]} {
  91         prn_attrs [lindex [lindex $res 3] 2]
  92         putmsg stdout 0 "\t Test PASS"
  93 } else {
  94         putmsg stderr 0 "\t Test FAIL"
  95         putmsg stderr 0 "\t   Getattr val($getattr_str) != expval($expval)"
  96 }
  97 
  98 }
  99 
 100 # ---------------------------------------------------------------
 101 # b: Test get attr FATTR4_OWNER_GROUP of a file object, expect OK
 102 
 103 set ASSERTION "Test get attr FATTR4_OWNER_GROUP of a file object, expect OK"
 104 putmsg stdout 0 "$TNAME{b}: $ASSERTION"
 105 
 106 # Setup testfile for attribute purposes
 107 set attr {owner_group}
 108 #Get the filehandle of the test file
 109 set res [compound {
 110         Putfh $bfh;
 111         Lookup $filename;
 112         Getfh;
 113         Getattr $attr
 114 }]
 115 set cont [ckres "Getattr" $status $expcode $res $FAIL]
 116 
 117 if { ![string equal $cont "false"] } {
 118 
 119 # Get the Getattr value returned by op
 120 set attrval [ extract_attr [lindex [lindex $res 3] 2] $attr ]
 121 
 122 # Extract the owner name string returned from Getattr
 123 set newstr [ lindex $attrval 0 ]
 124 putmsg stdout 1 "newstr is $newstr"
 125 set strindex [string first @ $newstr]
 126 if {$strindex == -1} {
 127         set getattr_str $newstr
 128 } else {
 129         set getattr_str [string range $newstr 0 [expr $strindex-1]]
 130 }
 131 putmsg stdout 1 "strindex is $strindex"
 132 
 133 # Get the TCL command unix version of the file owner_group
 134 set attrs [file attributes $MNTPTR${delm}$filename]
 135 set expval [lindex $attrs 1]
 136 
 137 # Compare these strings
 138 if {[string equal $getattr_str $expval]} {
 139         prn_attrs [lindex [lindex $res 3] 2]
 140         putmsg stdout 0 "\t Test PASS"
 141 } else {
 142         putmsg stderr 0 "\t Test FAIL"
 143         putmsg stderr 0 "\t   Getattr val($getattr_str) != expval($expval)"
 144 }
 145 
 146 }
 147 
 148 # Final cleanup
 149 # --------------------------------------------------------------
 150 # Final cleanup
 151 # - remove the created dir
 152 set res [compound {Putfh $bfh; Remove $filename;}]
 153 if { "$status" != "OK" } {
 154         putmsg stderr 0 "\t WARNING: cleanup to remove created file failed"
 155         putmsg stderr 0 "\t          status=$status; please cleanup manually."
 156         putmsg stderr 1 "\t   res=($res)"
 157         putmsg stderr 1 "  "
 158         exit $WARNING
 159 }
 160 
 161 
 162 Disconnect 
 163 exit $PASS