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 # TCL procedure for CREATE operation testing
  27 
  28 #--------------------------------------------------------------------
  29 # uid_creat()
  30 #       Wrap for testing Create (type fifo) assertions for BADOWNER and
  31 #               verifying with getattr op.
  32 #       Returns  OK if success, else the status code of the operation.
  33 #               parameters Aown Aowngrp are set to final attrs of file
  34 #
  35 
  36 proc uid_creat {dfh name Aown Aowngrp Ares {Eown ""} {Egrp ""} {type f}} {
  37         # initialize attributes parameter
  38         upvar 1 $Aown own
  39         upvar 1 $Aowngrp owngrp
  40         upvar 1 $Ares res
  41         set status "UNRESOLVED"
  42         putmsg stdout 1 "\n"
  43         putmsg stdout 1 \
  44 "uid_creat $dfh $name $Aown $Aowngrp $Ares \"$Eown\" \"$Egrp\" \"$type\""
  45         putmsg stdout 1 "status = $status"
  46 
  47         global PASS FAIL OTHER
  48         set attrib {}
  49         set attrs {}
  50         set O 0
  51         set G 0
  52 
  53         # pass tag if exists as global
  54         if {[info vars ::tag] != ""} {
  55                 upvar 1 tag tag
  56         }
  57 
  58         if {[string length $own] > 0}  {
  59                 lappend attrib "owner $own"
  60                 lappend attrs "owner"
  61                 set O 1
  62         }
  63         if {[string length $owngrp] > 0} {
  64                 lappend attrib "owner_group $owngrp"
  65                 lappend attrs "owner_group"
  66                 set G 1
  67         }
  68         putmsg stdout 1 "attrib = <$attrib>"
  69         putmsg stdout 1 "attrs = <$attrs>"
  70 
  71         set orig_owner ""
  72         set orig_owner_group ""
  73         set Sstatus "OK"
  74         # Generate a compound request to test the attributes
  75         set st [catch {compound {Putfh $dfh; Create $name {$attrib} $type; \
  76                 Getfh}} res]
  77         putmsg stdout 1 "compound{Putfh $dfh;"
  78         putmsg stdout 1 "\tCreate $name {$attrib} $type; Getfh}"
  79         putmsg stdout 1 "res: <$res>"
  80         if {$status != "OK"} {
  81                 putmsg stdout 1 "Create return status=$status"
  82                 putmsg stdout 1 "catch result = $st"
  83                 return $status
  84         }
  85         set ufh [lindex [lindex $res 2] 2]
  86         putmsg stdout 1 "new filehandle = $ufh"
  87 
  88         #verify the change in attribute
  89         set st2 [catch {compound {Putfh $ufh; Getattr $attrs}} res2]
  90         putmsg stdout 1 "compound{Putfh $ufh;\n\tGetattr $attrs}"
  91         putmsg stdout 1 "res: <$res2>"
  92         if {$status != "OK"} {
  93                 putmsg stdout 0 "\twarning: Getattr failed ($status)."
  94                 putmsg stdout 1 "return status=$status"
  95                 putmsg stdout 1 "catch result = $st2"
  96                 return $status
  97         } else {
  98                 set rattrs [lindex [lindex $res2 1] 2]
  99                 set owner ""
 100                 set owner_group ""
 101                 putmsg stdout 1 "returned attrs = $rattrs"
 102                 foreach attr $rattrs {
 103                         set name [ lindex $attr 0]
 104                         set val  [ lindex $attr 1]
 105 
 106                         switch $name {
 107                                 owner   { 
 108                                         set owner $val
 109                                 }
 110                                 owner_group     {
 111                                         set owner_group $val
 112                                 }
 113                                 default {}
 114                         }
 115                 }
 116                 putmsg stdout 1 "owner = $owner\nowner_group = $owner_group"
 117         }
 118 
 119         set Cstatus ""
 120         # if expected value different than value used
 121         if {$Eown != ""} {
 122                 set own $Eown
 123         }
 124         if {$Egrp != ""} {
 125                 set owngrp $Egrp
 126         }
 127         # compare to requested values
 128         # XXX should we enhance to ignore the case of the domain?
 129         if {$O == 1 && [string equal $own $owner] != 1} {
 130                 putmsg stdout 1 "owner set to $own, but is $owner"
 131                 set own $owner
 132                 set Cstatus "${Cstatus}OwnerMismatch"
 133         }
 134         if {$G == 1 && [string equal $owngrp $owner_group] != 1} {
 135                 putmsg stdout 1\
 136                         "group set to $owngrp, but is $owner_group"
 137                 set Cstatus "${Cstatus}GroupMismatch"
 138         }
 139 
 140         if {$Cstatus != ""} {
 141                 set status $Cstatus
 142         }
 143 
 144         putmsg stdout 1 "return $status"
 145         return $status
 146 }