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 # 
  25 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  26 # Use is subject to license terms.
  27 #
  28 
  29 ###############################################################################
  30 # start __stf_assertion__
  31 #
  32 # ASSERTION: svcadm_delegate_002
  33 #
  34 # DESCRIPTION:
  35 #       svcadm  delegate <invalid-fmri> <invalid-fmri> should fail with exit 1
  36 #       svcadm  delegate <invalid-fmri> <valid-fmri> should fail with exit 1
  37 #       svcadm  delegate <valid-fmri> <invalid-fmri> should fail with exit 1
  38 #       svcadm  delegate <invalid name> <invalid-name> should fail with exit 1
  39 #       svcadm  delegate <valid-name> <invalid-name> should fail with exit 1
  40 #       svcadm  delegate <invalid-name> <valid-name> should fail with exit 1
  41 # STRATEGY:
  42 #               Assertion says all.
  43 # COMMANDS: svcadm(1)
  44 #
  45 # end __stf_assertion__
  46 ################################################################################
  47 
  48 # First load up definitions of STF result variables like STF_PASS etc.
  49 . ${STF_TOOLS}/include/stf.kshlib
  50 
  51 # Load up definitions of shell functionality common to all smf sub-suites.
  52 . ${STF_SUITE}/include/gltest.kshlib
  53 
  54 # Define Variables
  55 readonly assertion=svcadm_delegate_002
  56 readonly invalid_fmri="foo$$"
  57 readonly valid_fmri="svc:/system/svc/restarter:default"
  58 readonly invalid_name=100
  59 readonly valid_name="svc:/system/svc/restarter:default"
  60 readonly ME=$(whence -p ${0})
  61 readonly MYLOC=$(dirname ${ME})
  62 
  63 # gltest.kshlib functions to extract and print assertion information
  64 # from this source script.
  65 extract_assertion_info $ME
  66 
  67 # Initialize test result to pass.
  68 typeset -i RESULT=${STF_PASS}
  69 
  70 # Exit code for individual commands.
  71 typeset -i tmp_rc=0
  72 
  73 # Make sure we run as root
  74 if ! /usr/bin/id | grep "uid=0(root)" > /dev/null 2>&1
  75 then
  76         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  77         echo "--DIAG: [$assertion]
  78         This test must be run from root."
  79         print_result $RESULT
  80         exit $RESULT
  81 fi
  82 
  83 
  84 # Execute environmental sanity checks.
  85 check_gl_env
  86 tmp_rc=$?
  87 if [[ $tmp_rc -ne 0 ]]
  88 then
  89     RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  90     echo "--DIAG: [$assertion]
  91         Invalid smf environment, quitting."
  92     print_result $RESULT
  93     exit $RESULT
  94 fi
  95 
  96 echo "--INFO: [${assertion}]
  97         Call svcadm  delegate $invalid_fmri $invalid_fmri"
  98 
  99 svcadm -v delegate $invalid_fmri $invalid_fmri >/dev/null 2>&1
 100 ret=$?
 101 if [ $ret -ne 2 ]; then
 102     RESULT=$(update_result $STF_FAIL $RESULT)
 103     echo "--DIAG: [$assertion]
 104         EXPECTED: svcadm  delegate $invalid_fmri $invalid_fmri should exit 1
 105         ACTUAL: svcadm  delegate $invalid_fmri $invalid_fmri exits with 
 106                 status $ret"
 107     print_result $RESULT
 108     exit $RESULT
 109 fi
 110 
 111 echo "--INFO: [${assertion}]
 112         Call svcadm -v delegate $valid_fmri $invalid_fmri"
 113 
 114 svcadm -v delegate $valid_fmri $invalid_fmri >/dev/null 2>&1
 115 ret=$?
 116 if [ $ret -ne 2 ]; then
 117     RESULT=$(update_result $STF_FAIL $RESULT)
 118     echo "--DIAG: [$assertion]
 119         EXPECTED: svcadm  delegate $valid_fmri $invalid_fmri should exit 1
 120         ACTUAL: svcadm  delegate $valid_fmri $invalid_fmri exits with 
 121                 status $ret"
 122     print_result $RESULT
 123     exit $RESULT
 124 fi
 125 
 126 echo "--INFO: [${assertion}]
 127         Call svcadm -v delegate $invalid_fmri $valid_fmri"
 128 
 129 svcadm -v delegate $invalid_fmri $valid_fmri >/dev/null 2>&1
 130 ret=$?
 131 if [ $ret -ne 2 ]; then
 132     RESULT=$(update_result $STF_FAIL $RESULT)
 133     echo "--DIAG: [$assertion]
 134         EXPECTED: svcadm  delegate $invalid_fmri $valid_fmri should exit 1
 135         ACTUAL: svcadm  delegate $invalid_fmri $valid_fmri exits with 
 136                 status $ret"
 137     print_result $RESULT
 138     exit $RESULT
 139 fi
 140 
 141 echo "--INFO: [${assertion}]
 142         Call svcadm -v delegate $invalid_name $valid_name"
 143 
 144 svcadm -v delegate $invalid_name $valid_name >/dev/null 2>&1
 145 ret=$?
 146 if [ $ret -ne 2 ]; then
 147     RESULT=$(update_result $STF_FAIL $RESULT)
 148     echo "--DIAG: [$assertion]
 149         EXPECTED: svcadm  delegate $invalid_name $valid_name should exit 1
 150         ACTUAL: svcadm  delegate $invalid_name $valid_name exits with 
 151                 status $ret"
 152     print_result $RESULT
 153     exit $RESULT
 154 fi
 155 
 156 echo "--INFO: [${assertion}]
 157         Call svcadm -v delegate $valid_name $invalid_name"
 158 
 159 svcadm -v delegate $valid_name $invalid_name >/dev/null 2>&1
 160 ret=$?
 161 if [ $ret -ne 2 ]; then
 162     RESULT=$(update_result $STF_FAIL $RESULT)
 163     echo "--DIAG: [$assertion]
 164         EXPECTED: svcadm  delegate $valid_name $invalid_name should exit 1
 165         ACTUAL: svcadm  delegate $valid_name $invalid_name exits with 
 166                 status $ret"
 167     print_result $RESULT
 168     exit $RESULT
 169 fi
 170 
 171 echo "--INFO: [${assertion}]
 172         Call svcadm -v delegate $invalid_name $invalid_name"
 173 
 174 svcadm -v delegate $invalid_name $invalid_name >/dev/null 2>&1
 175 ret=$?
 176 if [ $ret -ne 2 ]; then
 177     RESULT=$(update_result $STF_FAIL $RESULT)
 178     echo "--DIAG: [$assertion]
 179         EXPECTED: svcadm  delegate $invalid_name $invalid_name should exit 1
 180         ACTUAL: svcadm  delegate $invalid_name $invalid_name exits with 
 181                 status $ret"
 182     print_result $RESULT
 183     exit $RESULT
 184 fi
 185 
 186 print_result $RESULT
 187 exit $RESULT