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 2006 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 # libmapid01.sh - libmapid tests for the following configuration:
  28 #
  29 #       NFSMAPID_DOMAIN   DNS TXT RR      DNS domain  NIS domain
  30 #       ===============   ==============  ==========  ==========
  31 #       Yes               Yes             Yes         Yes
  32 #
  33 
  34 [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
  35 
  36 # set up script execution environment
  37 . ./dom_env
  38 
  39 # should run as root
  40 is_root "$NAME{setup}:" "All tests for domain affected"
  41 
  42 # assertion list
  43 ASSERTIONS=${ASSERTIONS:-"a b c d e"}
  44 
  45 # generate assertion descriptions
  46 gen_assert_desc $NAME "as_"
  47 
  48 #
  49 # Assertion definition
  50 #
  51 
  52 # as_a: Has domain in /etc/default/nfs, call mapid_get_domain(), get domain
  53 #       from the file 
  54 function as_a {
  55         [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
  56 
  57         exp=$nfsfile_domain
  58         assertion a "$(get_assert_desc a)" $exp
  59 
  60         # Get mapid domain
  61         act=$(./get_domain)
  62         ckreturn $? "get_domain utility failed" /dev/null "UNRESOLVED" \
  63            || return $UNRESOLVED
  64 
  65         # check assertion
  66         ckres2 "get_domain" "$act" "$exp" "domains differ" || return $FAIL
  67 }
  68 
  69 # as_b: Has domain in /etc/default/nfs, call mapid_derive_domain(), get domain
  70 #       from the file
  71 function as_b {
  72         [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
  73 
  74         exp=$nfsfile_domain
  75         assertion b "$(get_assert_desc b)" $exp
  76 
  77         # Get mapid domain
  78         act=$(./derive_domain_dl)
  79         ckreturn $? "derive_domain_dl utility failed" /dev/null "UNRESOLVED" \
  80            || return $UNRESOLVED
  81 
  82         # check assertion
  83         ckres2 "derive_domain_dl" "$act" "$exp" "domains differ" || return $FAIL
  84 }
  85 
  86 # as_c1: Domain string is helloword, call mapid_stdchk_domain() to check it
  87 # as_c2: Domain string is hello.world, call mapid_stdchk_domain() to check it
  88 # as_c3: Domain string has uppercase character, call mapid_stdchk_domain()
  89 #       to check it
  90 # as_c4: Domain string has dash character, and the last character is a number,
  91 #       call mapid_stdchk_domain() to check it
  92 # as_c5: Domain string has 255 characters(max length), call 
  93 #       mapid_stdchk_domain() to check it
  94 # as_c6: Domain string has invalid character(space), call 
  95 #       mapid_stdchk_domain() to check it
  96 # as_c7: Domain string has invalid character(@), call mapid_stdchk_domain()
  97 #       to check it
  98 # as_c8: The first character of domain string is not alphabetic character, call
  99 #       mapid_stdchk_domain() to check it
 100 # as_c9: Domain string has trailing space, call mapid_stdchk_domain() to check
 101 #       it
 102 # as_c10: Domain string has invalid length(256 characters), call 
 103 #       mapid_stdchk_domain() to check it
 104 # as_c11: Domain string has invalid length(null string), call
 105 #       mapid_stdchk_domain() to check it
 106 # as_c12: Domain string is helloword, call mapid_stdchk_domain() to check it
 107 function as_c {
 108         [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
 109 
 110         set -A assertions c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12
 111         
 112         FIFTY_CHARS="x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x."
 113         TWOHUNDRED_CHARS=$FIFTY_CHARS$FIFTY_CHARS$FIFTY_CHARS$FIFTY_CHARS
 114 
 115         set -A dom_strings \
 116                 "helloworld" \
 117                 "hello.world" \
 118                 "HELLO.WORLD" \
 119                 "hello-world.1234" \
 120                 $TWOHUNDRED_CHARS$FIFTY_CHARS"12345" \
 121                 "hello world" \
 122                 "hello@world" \
 123                 "1234.world" \
 124                 "hello.worl-" \
 125                 "hello.world " \
 126                 $TWOHUNDRED_CHARS$FIFTY_CHARS"123456" \
 127                 ""
 128 
 129         set -A exp_results 1 1 1 1 1 0 0 1 0 0 -1 0
 130 
 131         x=0
 132         while (( $x < 12 )); do
 133                 assertion "${assertions[$x]}a" \
 134                     "$(get_assert_desc ${assertions[$x]})" \
 135                     ${exp_results[$x]}
 136                 res=$(./check_domain "${dom_strings[$x]}" ${exp_results[$x]})
 137                 ckres2 "check_domain" $res ${exp_results[$x]} \
 138                    "mapid_stdchk_domain() failed on ${dom_strings[$x]}"
 139 
 140                 assertion "${assertions[$x]}b" \
 141                     "$(get_assert_desc ${assertions[$x]}), using dl_open()" \
 142                     ${exp_results[$x]}
 143                 res=$(./check_domain_dl "${dom_strings[$x]}" ${exp_results[$x]})
 144                 ckres2 "check_domain_dl" $res ${exp_results[$x]} \
 145                    "mapid_stdchk_domain() failed on ${dom_strings[$x]}"
 146 
 147                 x=$((x + 1))
 148         done
 149 }
 150 
 151 # as_d: Has domain in /etc/default/nfs, call mapid_derive_domain() 
 152 #       simultaneously in different threads
 153 function as_d {
 154         [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
 155 
 156         exp=0
 157         assertion d "$(get_assert_desc d)" $exp
 158 
 159         # call mapid_get_domain() simultaneously and check the results
 160         ./get_domain_mt >$LOGFILE 2>&1
 161 
 162         # Check Assertion
 163         ckres2 "get_domain_mt" $? $exp "mapid_get_domain() failed" $LOGFILE \
 164             || return $FAIL
 165 }
 166 
 167 # as_e: Call mapid_stdchk_domain() simultaneously in different threads
 168 function as_e {
 169         [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
 170 
 171         exp=0
 172         assertion e "$(get_assert_desc e)" $exp
 173 
 174         # call mapid_stdchk_domain() simultaneously and check the results
 175         ./check_domain_mt >$LOGFILE 2>&1
 176 
 177         # Check Assertion
 178         ckres2 "reeval_callback" $? $exp "mapid_stdchk_domain() failed" \
 179             $LOGFILE || return $FAIL
 180 }
 181 
 182 #
 183 # Run assertions
 184 #
 185 
 186 echo "\nLIBMAPID01 Starting Assertions\n"
 187 
 188 for i in $ASSERTIONS
 189 do
 190         eval as_${i} || print_state
 191 done
 192 
 193 echo "\nLIBMAPID01 assertions finished!\n"