1 #! /usr/bin/ksh -p
   2 #
   3 # CDDL HEADER START
   4 #
   5 # The contents of this file are subject to the terms of the
   6 # Common Development and Distribution License (the "License").
   7 # You may not use this file except in compliance with the License.
   8 #
   9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10 # or http://www.opensolaris.org/os/licensing.
  11 # See the License for the specific language governing permissions
  12 # and limitations under the License.
  13 #
  14 # When distributing Covered Code, include this CDDL HEADER in each
  15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 # If applicable, add the following below this CDDL HEADER, with the
  17 # fields enclosed by brackets "[]" replaced with your own identifying
  18 # information: Portions Copyright [yyyy] [name of copyright owner]
  19 #
  20 # CDDL HEADER END
  21 #
  22 
  23 #
  24 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 # uidmapping_neg04.ksh 
  28 #     This file contains negative testcases for the setup that domains 
  29 #     mismatch. They are:
  30 #
  31 #       {a} - files owner and group are mapped to nobody
  32 #       {b} - chown command failed due to unmappable user string.
  33 #
  34 
  35 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
  36 
  37 trap "cleanup" EXIT
  38 trap "exit 1" HUP INT QUIT PIPE TERM
  39 
  40 NAME=`basename $0`
  41 UIDMAPENV="./uid_proc"
  42 UNINITIATED=6
  43 
  44 # set up script running environment
  45 if [ ! -f $UIDMAPENV ]; then
  46         echo "$NAME: UIDMAPENV[$UIDMAPENV] not found; test UNINITIATED."
  47         exit $UNINITIATED
  48 fi
  49 . $UIDMAPENV
  50 
  51 ASSERTIONS=${ASSERTIONS:-"a b c"}
  52 DESC="client and server domains mismatch, "
  53 
  54 function setup
  55 {
  56         [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
  57 
  58         # run test cases on shared directory
  59         cd $TESTDIR
  60 
  61         # set up client domain
  62         Ndomain="nonexistent.at.all"
  63         set_local_domain $Ndomain 2>$ERRLOG
  64         ckreturn $? "could not set up domain $Ndomain on client" \
  65             $ERRLOG "ERROR" || return 1
  66 }
  67 
  68 function cleanup
  69 {
  70         [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
  71 
  72         # we don't want user can interrupt cleanup procedure
  73         trap '' HUP INT QUIT PIPE TERM
  74 
  75         # remove testfile
  76         rm -f $TESTFILE 2>$ERRLOG
  77         ckreturn $? "could not remove $TESTFILE" $ERRLOG "WARNING"
  78 
  79         # Change to other directory
  80         cd $TESTROOT
  81 
  82         restore_local_domain 2>$ERRLOG
  83         ckreturn $? "could not restore local domain" $ERRLOG "WARNING"
  84 
  85         # remove temporary file
  86         rm -f $ERRLOG
  87         ckreturn $? "could not remove $ERRLOG" /dev/null "WARNING"
  88 }
  89 
  90 # Assertions
  91 
  92 # a: ls -l shows nobody with mismatch mapid domain
  93 function as_a
  94 {
  95         [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
  96 
  97         exp=1
  98         assertion a \
  99             "$DESC""ls -l shows nobody on all files in the test directory" $exp
 100 
 101         # get all files' user and group
 102         ls -l | grep -v total | awk '{print $3, $4}' >$TESTFILE 2>$ERRLOG
 103         ckreturn $? "could not generate $TESTFILE" $ERRLOG "ERROR" || return 1
 104 
 105         # look for mappable user or group. Shouldn't exist
 106         grep -v nobody $TESTFILE 1>/dev/null 2>$ERRLOG
 107         res=$?
 108         rm -f $TESTFILE
 109         ckres2 "ls -l own:grp are nobody" "$res" $exp \
 110             "found mappable user or group"
 111 }
 112 
 113 # b: chown of existing file fails with mismatch mapid domain
 114 function as_b
 115 {
 116         [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
 117 
 118         exp=1
 119         assertion b "$DESC""chown an existing file fails, and file owner doesn't change" $exp
 120 
 121         # prepare test file
 122         touch $TESTFILE 2>$ERRLOG
 123         ckreturn $? "could not genereate $TESTFILE" $ERRLOG "UNINITIATED" \
 124             || return 1
 125 
 126         # get its owner and owner_group
 127         old_attributes=$(execute $SERVER root "ls -l $ROOTDIR/$TESTFILE")
 128         if [ $? -ne 0 ]; then
 129             echo "\t Test UNINITIATED: ls -l $TESTFILE failed on server side"
 130             rm -f $TESTFILE
 131             return $UNINITIATED
 132         fi
 133         old_owner_grp=$(echo $old_attributes | nawk '{print $3, $4}')
 134         
 135         # try to change file owner and owner_group. Should fail
 136         chown bin:staff $TESTFILE 2>$ERRLOG
 137 
 138         # "chown" command failed or not? 
 139         res=$?
 140 
 141         # file owner and owner_group changed or not?
 142         new_attributes=$(execute $SERVER root "ls -l $ROOTDIR/$TESTFILE")
 143         if [ $? -ne 0 ]; then
 144             echo "\t Test UNRESOLVED: ls -l $TESTFILE failed on server side after chown"
 145             rm -f $TESTFILE
 146             return $UNRESOLVED
 147         fi
 148         new_owner_grp=$(echo $new_attributes | nawk '{print $3, $4}')
 149 
 150         # check if the command failed as expected
 151         if [ $exp -ne $res ]; then
 152                 # print error message
 153                 echo "the owner/group of $SERVER:$ROOTDIR/$TESTFILE file" >&2
 154                 echo "--------------------------------------------------" >&2
 155                 echo "before chown command: $old_owner_grp" >&2
 156                 echo "after chown command : $new_owner_grp" >&2
 157                 echo "--------------------------------------------------" >&2
 158 
 159                 ckres2 chown "$res" $exp "chown didn't fail"
 160 
 161                 # clean up and return
 162                 rm -f $TESTFILE
 163                 return $FAIL
 164         fi 
 165 
 166         # check if the server side attributes didn't change
 167         if [ "$old_owner_grp" != "$new_owner_grp" ]; then
 168                 # print error message
 169                 echo "the owner/group of $SERVER:$ROOTDIR/$TESTFILE file" >&2
 170                 echo "--------------------------------------------------" >&2
 171                 echo "before chown command: $old_owner_grp" >&2
 172                 echo "after chown command : $new_owner_grp" >&2
 173                 echo "--------------------------------------------------" >&2
 174 
 175                 ckres2 chown "$new_owner_grp" "$old_owner_grp" \
 176                     "$TESTFILE file owner/group was changed on server side"
 177 
 178                 # clean up and return
 179                 rm -f $TESTFILE
 180                 return $FAIL
 181         fi
 182 
 183         # If it reaches here, the case passes. I call ckres2() below just to
 184         # print out information to tell the user that the case has passed, 
 185         # rather than for really matching $res against $exp, which I have 
 186         # already done above.
 187 
 188         rm -f $TESTFILE
 189         ckres2 chown "$res" $exp 
 190 }
 191 
 192 # c: setfacl fails with mismatch mapid domain
 193 function as_c
 194 {
 195         [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
 196         
 197         uid=0;user=root
 198 
 199         exp=2
 200         desc="$DESC""call setfacl/getfacl to set/get ACL, "
 201         assertion c "$desc" $exp
 202 
 203         setfacl -m user:$uid:rw- $TESTFILE 2>$ERRLOG
 204         ckres2 -s setfacl $? $exp "setfacl should fail" $ERRLOG \
 205             || return $FAIL
 206 
 207         getfacl $TESTFILE 1>/dev/null 2>$ERRLOG
 208         ckres2 getfacl $? $exp "getfacl should fail" $ERRLOG \
 209             || return $FAIL
 210 }
 211 
 212 
 213 # setup
 214 setup || return $UNINITIATED
 215 
 216 # main loop
 217 for i in $ASSERTIONS
 218 do
 219         as_$i || print_state
 220 done