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 # UID Mapping testing.
  27 
  28 # TESTROOT directory; must be set in the environment already
  29 set TESTROOT $env(TESTROOT)
  30 
  31 source [file join ${TESTROOT} tcl.init]
  32 source [file join ${TESTROOT} testproc]
  33 source [file join ${TESTROOT} lcltools]
  34 
  35 # setting local variables
  36 set TNAME $argv0
  37 
  38 if {[info exists env(DNS_SERVER)] == 1} {
  39         set domain [get_domain $env(SERVER) $env(DNS_SERVER)]
  40 } else {
  41         set domain [get_domain $env(SERVER)]
  42 }
  43 if {$domain == $NULL} {
  44         putmsg stderr 0 "\t$TNAME: unable to determine the domain."
  45         putmsg stderr 0 "\tAssertions won't be executed."
  46         exit $UNINITIATED
  47 }
  48 
  49 # connect to the test server
  50 Connect
  51 
  52 
  53 set attrs {owner owner_group}
  54 
  55 # get file file handle
  56 set tag $TNAME.setup
  57 set TESTFILE [file join $BASEDIR "$TNAME"]
  58 set clientid ""
  59 set stateid ""
  60 set seqid ""
  61 set fh [openv4 $TESTFILE clientid stateid seqid]
  62 if { $fh == $NULL } {
  63         putmsg stderr 0 "\t$TNAME: unable to create temp file."
  64         putmsg stderr 0 "\tAssertions a to d won't be executed."
  65         exit $UNINITIATED
  66 }
  67 
  68 set orig_attr [getfileowner $fh]
  69 if { $orig_attr == $NULL } {
  70         putmsg stderr 0 "$TNAME{all}:"
  71         putmsg stderr 0 "\tTest UNINITIATED: unable to get $TESTFILE attributes"        exit $UNINITIATED
  72 }
  73 
  74 set Oown [lindex $orig_attr 0]
  75 set Ogrp [lindex $orig_attr 1]
  76 
  77 # Start testing
  78 # --------------------------------------------------------------
  79 
  80 # assertions to test PERM errors
  81 #(trying to change owner/group without root access)
  82 
  83 
  84 # a: owner root
  85 set tag $TNAME{a}
  86 set expct "PERM"
  87 set ASSERTION "owner root, no root access, expect $expct"
  88 putmsg stdout 0 "$tag: $ASSERTION"
  89 set owner "root@$domain"
  90 set group ""
  91 set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
  92 ckres "uid_mapping" $st $expct $res $PASS
  93 
  94 
  95 # b: owner id 0
  96 set tag $TNAME{b}
  97 set expct "PERM|BADOWNER"
  98 set ASSERTION "owner id 0, no root access, expect $expct"
  99 putmsg stdout 0 "$tag: $ASSERTION"
 100 set owner 0
 101 set group ""
 102 set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
 103 ckres "uid_mapping" $st $expct $res $PASS
 104 
 105 
 106 # c: group rooc
 107 set tag $TNAME{x}
 108 set expct "PERM"
 109 set ASSERTION "group root, no root access, expect $expct"
 110 putmsg stdout 0 "$tag: $ASSERTION"
 111 set owner ""
 112 set group "root@$domain"
 113 set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
 114 ckres "uid_mapping" $st $expct $res $PASS
 115 
 116 
 117 # d: group id 0
 118 set tag $TNAME{d}
 119 set expct "PERM|BADOWNER"
 120 set ASSERTION "group id 0, no root access, expect $expct"
 121 putmsg stdout 0 "$tag: $ASSERTION"
 122 set owner ""
 123 set group 0
 124 set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
 125 ckres "uid_mapping" $st $expct $res $PASS
 126 
 127 
 128 # xxx: embedded NULL in owner
 129 # xxy: embedded NULL in group
 130 # nfsv4shell reads internally owner and owner_group using strcpy
 131 # so even that "binary format" can created strings with embedded
 132 # NULLs, nfsv4shell will truncate them. XXX future improvement needed.
 133 
 134 
 135 # close file
 136 set tag $TNAME.cleanup
 137 set fh [closev4 $TESTFILE $fh $stateid $seqid]
 138 if { $fh == $NULL } {
 139     putmsg stderr 0 "\tWARNING: unable to close or delete temp file."
 140 }
 141 
 142 # --------------------------------------------------------------
 143 # disconnect and exit
 144 
 145 Disconnect
 146 exit $PASS
 147