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 2009 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 # uidmapping_neg03.ksh 
  28 #     This file contains negative testcases for the setup that both server
  29 #     and client have the same domain. The testcases are:
  30 #
  31 #       {a} - change owner to user known only to client
  32 #       {b} - change owner to user known only to client but who has a valid 
  33 #             id on server
  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"}
  52 DESC="client and server have the same mapid domain, "
  53 
  54 function setup
  55 {
  56         [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
  57 
  58         # change to shared directory
  59         cd $TESTDIR
  60 
  61         if [ "$Sdomain" != "$Cdomain" ]; then
  62                 # set up client domain
  63                 set_local_domain $Sdomain 2>$ERRLOG
  64                 ckreturn $? "could not set up domain $Sdomain on client" \
  65                         $ERRLOG "ERROR" || return 1
  66         fi
  67 
  68         # create temporary file for testing
  69         touch $TESTFILE 2>$ERRLOG 
  70         ckreturn $? "could not create $TESTFILE" $ERRLOG "ERROR" || return 1
  71 
  72         # make sure nobody issue not found
  73         typeset ug=$(/bin/ls -l $TESTFILE | awk '{print $3,$4}')
  74         if [ "$ug" == "nobody nobody" ]; then
  75                 echo "something is wrong on nfs/mapid, nobody issue found"
  76                 print_state
  77                 return 1
  78         fi
  79 }
  80 
  81 function cleanup
  82 {
  83         [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
  84 
  85         # we don't want cleanup procedure to be interruptable
  86         trap '' HUP INT QUIT PIPE TERM
  87 
  88         # remove testfile
  89         rm -f $TESTFILE 2>$ERRLOG
  90         ckreturn $? "could not remove $TESTFILE" $ERRLOG "WARNING"
  91 
  92         # Change to other directory
  93         cd $TESTROOT
  94 
  95         restore_local_domain 2>$ERRLOG
  96         ckreturn $? "could not restore local domain" $ERRLOG "WARNING"
  97 
  98         # remove temporary file
  99         rm -f $ERRLOG
 100         ckreturn $? "could not remove $ERRLOG" /dev/null "WARNING"
 101 }
 102 
 103 # Assertions 
 104 
 105 function as_a
 106 {
 107         [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
 108 
 109         exp=1
 110         desc="$DESC""user known only to client: $TUSERC, "
 111         desc="$desc""chown fails and file owner doesn't change"
 112         assertion a "$desc" $exp
 113 
 114         prev=$(get_val $OWN $TESTFILE)
 115         chown $TUSERC $TESTFILE 2>$ERRLOG
 116         st=$?
 117 
 118         # check if the command failed as expected
 119         if [ $exp -ne $st ]; then
 120                 # print error message
 121                 ckres2 uidmapping "$st" $exp "command should fail"
 122         else
 123                 # check if the server side setting didn't change
 124                 res=$(get_val $OWN $TESTFILE)
 125                 ckres2 uidmapping "$res" $prev "file owner was changed"
 126         fi
 127 }
 128 
 129 function as_b
 130 {
 131         [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
 132 
 133         exp=1
 134         desc="$DESC""user known only to client with common user id: $TUSERC2, "
 135         desc="$desc""chown fails and file owner doesn't change"
 136         assertion b "$desc" $exp
 137 
 138         prev=$(get_val $OWN $TESTFILE)
 139         chown $TUSERC2 $TESTFILE 2>$ERRLOG
 140         st=$?
 141 
 142         # check if the command failed as expected
 143         if [ $exp -ne $st ]; then
 144                 # print error message
 145                 ckres2 uidmapping "$st" $exp "command should fail"
 146         else
 147                 # check if the server side setting didn't change
 148                 res=$(get_val $OWN $TESTFILE)
 149                 ckres2 uidmapping "$res" $prev "file owner was changed"
 150         fi
 151 }
 152 
 153 # set up test environment
 154 setup || exit $UNINITIATED
 155 
 156 # main loop
 157 for i in $ASSERTIONS
 158 do
 159         as_$i || print_state
 160 done