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 # nfsmapid02.sh - nfsmapid tests for the following configuration:
  28 #
  29 #       NFSMAPID_DOMAIN   DNS TXT RR      DNS domain  NIS domain
  30 #       ===============   ==============  ==========  ==========
  31 #       No                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 # get timeout value nfsmapid uses for domain checking
  43 nfsdomain_tmout=$(get_nfsmapid_domain_tout_wrapper)
  44 
  45 # comment out NFSMAPID_DOMAIN string in /etc/default/nfs
  46 comm_domain_default_nfs
  47 
  48 # refresh nfsmapid
  49 mapid_service refresh $TIMEOUT "failed to refresh mapid service" \
  50     "ERROR" || exit $UNINITIATED
  51 
  52 # assertion list
  53 ASSERTIONS=${ASSERTIONS:-"a b c d e"}
  54 
  55 # generate assertion descriptions
  56 gen_assert_desc $NAME "as_"
  57 
  58 #
  59 # Assertion definition
  60 #
  61 
  62 # as_a: No domain in /etc/default/nfs, DNS up, TXT RR present, use TXT RR
  63 function as_a {
  64         [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
  65 
  66         exp=$txt_rr
  67         assertion a "$(get_assert_desc a)" $exp
  68 
  69         # Get mapid domain
  70         mapid_service refresh $TIMEOUT "failed to refresh mapid service" \
  71             "UNRESOLVED" || return $UNRESOLVED
  72         act=$(get_nfsmapid_domain)
  73 
  74         # Check Assertion
  75         ckres2 "get_nfsmapid_domain" "$act" "$exp" "domains differ"
  76 }
  77 
  78 # as_b1: Current domain is TXT RR, then DNS down. After nfscfg_domain_tmout
  79 #       timer expires, cache is on and domain is still TXT RR
  80 # as_b2: DNS still down. After nfscfg_domain_tmout timer expires, cache is
  81 #       still on and domain is still TXT RR
  82 function as_b {
  83         [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
  84         
  85         #
  86         # Assertion b1
  87         #
  88 
  89         exp=1
  90         assertion b1 "$(get_assert_desc b1)" $exp
  91 
  92         # Setup: disable DNS server
  93         dns_service disable $TIMEOUT "failed to disable dns service" \
  94             "UNRESOLVED" || return $UNRESOLVED
  95 
  96         # Wait for timeout and then get cache flag
  97         sleep $nfsdomain_tmout
  98         domain=$(get_nfsmapid_domain)
  99         act=$(get_dns_txt_cache_flag)
 100 
 101         # First check cache
 102         ckres2 -s "get_dns_txt_cache_flag" "$act" "$exp" \
 103             "cache should be on; $NAME{b2} skipped" || return $FAIL
 104         
 105         # Then check domain
 106         ckres2 "get_nfsmapid_domain" "$domain" "$txt_rr" \
 107             "domains differ; $NAME{b2} skipped" || return $FAIL
 108 
 109         #
 110         # Assertion b2
 111         #
 112         exp=1
 113         assertion b2 "$(get_assert_desc b2)" $exp
 114 
 115         # Wait for timeout and then get cache flag
 116         sleep $nfsdomain_tmout
 117         domain=$(get_nfsmapid_domain)
 118         act=$(get_dns_txt_cache_flag)
 119 
 120         # First check cache
 121         ckres2 -s "get_dns_txt_cache_flag" "$act" "$exp" "cache should be off" \
 122             || return $FAIL
 123         
 124         # Then check domain
 125         ckres2 "get_nfsmapid_domain" "$domain" "$txt_rr" "domains differ" \
 126             || return $FAIL
 127 }
 128 
 129 # as_c: Current domain is TXT RR, then DNS down, refresh nfsmapid, cache is
 130 #       off and and get domain from DNS domain
 131 function as_c {
 132         [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
 133 
 134         exp=0
 135         assertion c "$(get_assert_desc c)" $exp
 136 
 137         # Setup: disable DNS server
 138         dns_service disable $TIMEOUT "failed to disable dns service" \
 139             "UNRESOLVED" || return $UNRESOLVED
 140 
 141         # Refresh nfsmapid and then get cache flag
 142         mapid_service refresh $timeout "failed to refresh mapid service" \
 143             "UNRESOLVED" || return $UNRESOLVED
 144         domain=$(get_nfsmapid_domain)
 145         act=$(get_dns_txt_cache_flag)
 146 
 147         # First check cache
 148         ckres2 -s "get_dns_txt_cache_flag" "$act" "$exp" "cache should be off" \
 149             || return $FAIL
 150         
 151         # Then check domain
 152         ckres2 "get_nfsmapid_domain" "$domain" "$dns_domain" "domains differ" \
 153             || return $FAIL
 154 }
 155 
 156 # as_d: Current domain is TXT RR, DNS up, remove /etc/resolv.conf. After
 157 #       nfscfg_domain_tmout timer expires, cache is off and get domain from NIS
 158 function as_d {
 159         [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
 160 
 161         exp=0
 162         assertion d "$(get_assert_desc d)" $exp
 163 
 164         # Setup: remove /etc/resolv.conf file
 165         rm -f /etc/resolv.conf
 166 
 167         # Wait for timeout and then get cache flag
 168         sleep $nfsdomain_tmout
 169         domain=$(get_nfsmapid_domain)
 170         act=$(get_dns_txt_cache_flag)
 171         
 172         # First check cache
 173         ckres2 -s "get_dns_txt_cache_flag" "$act" "$exp" "cache should be off" \
 174             || return $FAIL
 175         
 176         # Then check domain
 177         ckres2 "get_nfsmapid_domain" "$domain" "$nis_domain" "domains differ" \
 178             || return $FAIL
 179 }
 180 
 181 # as_e: Current domain is TXT RR, DNS up, modify /etc/resolv.conf to set an
 182 #       invalid domain. After nfscfg_domain_tmout timer expires, cache is off
 183 #       and domain is the new DNS domain
 184 function as_e {
 185         [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
 186 
 187         exp=0
 188         assertion e "$(get_assert_desc e)" $exp
 189 
 190         # Setup: modify /etc/resolv.conf to set an invalid domain
 191         new_dom_dns="x.y.z"
 192         chg_domain_dns $new_dom_dns
 193 
 194         # Wait for timeout and then get cache flag
 195         sleep $nfsdomain_tmout
 196         domain=$(get_nfsmapid_domain)
 197         act=$(get_dns_txt_cache_flag)
 198 
 199         # First check cache
 200         ckres2 -s "get_dns_txt_cache_flag" "$act" "$exp" "cache should be on" \
 201             || return $FAIL
 202         
 203         # Then check domain
 204         ckres2 "get_nfsmapid_domain" "$domain" "$new_dom_dns" "domains differ" \
 205             || return $FAIL
 206 }
 207 
 208 #
 209 # Run assertions
 210 #
 211 
 212 save_state STATE_NFSMAPID02
 213 
 214 echo "\nNFSMAPID02 Starting Assertions\n"
 215 
 216 for i in $ASSERTIONS
 217 do
 218         eval as_${i} || print_state
 219         restore_state STATE_NFSMAPID02
 220 done
 221 
 222 clear_state STATE_NFSMAPID02
 223 
 224 echo "\nNFSMAPID02 assertions finished!\n"