Print this page
XXX Remove nawk(1)


  29 # FMRI consts
  30 AUTOFS_FMRI="svc:/system/filesystem/autofs"
  31 DNS_CLIENT_FMRI="svc:/network/dns/client"
  32 IPSEC_IKE_FMRI="svc:/network/ipsec/ike"
  33 IPSEC_POLICY_FMRI="svc:/network/ipsec/policy"
  34 IPFILTER_FMRI="svc:/network/ipfilter:default"
  35 LDAP_CLIENT_FMRI="svc:/network/ldap/client"
  36 LOCATION_FMRI="svc:/network/location:default"
  37 MAPID_FMRI="svc:/network/nfs/mapid:default"
  38 NIS_CLIENT_FMRI="svc:/network/nis/client"
  39 NWAM_FMRI="svc:/network/physical:nwam"
  40 
  41 # commands
  42 CP=/usr/bin/cp
  43 DHCPINFO=/sbin/dhcpinfo
  44 DOMAINNAME=/usr/bin/domainname
  45 GREP=/usr/bin/grep
  46 LDAPCLIENT=/usr/sbin/ldapclient
  47 MKDIR=/usr/bin/mkdir
  48 MV=/usr/bin/mv
  49 NAWK=/usr/bin/nawk
  50 NWAMADM=/usr/sbin/nwamadm
  51 NWAMCFG=/usr/sbin/nwamcfg
  52 RM=/usr/bin/rm
  53 SED=/usr/bin/sed
  54 SVCADM=/usr/sbin/svcadm
  55 SVCCFG=/usr/sbin/svccfg
  56 SVCPROP=/usr/bin/svcprop
  57 TOUCH=/usr/bin/touch
  58 
  59 # Path to directories
  60 ETC_DEFAULT_DOMAIN=/etc/defaultdomain
  61 NIS_BIND_PATH=/var/yp/binding
  62 LEGACY_LOC_PATH=/etc/nwam/loc/Legacy
  63 USER_LOC_PATH=/etc/nwam/loc/User
  64 SCRIPT_PATH=/etc/svc/volatile/nwam
  65 
  66 #
  67 # echoes DHCP controlled interfaces separated by commas
  68 #
  69 # Don't parse the output of ifconfig(1M) because interfaces that haven't
  70 # acquired a DHCP lease also have the DHCP flag set.
  71 #
  72 get_dhcp_interfaces () {
  73         #
  74         # 1. parse netstat(1M) output for v4 interfaces in BOUND
  75         #    or INFORMATION state
  76         # 2. make a space-separated list of interface names
  77         #
  78         netstat -D -f inet | $NAWK '
  79             $2 ~ /BOUND/ { printf "%s ", $1 }
  80             $2 ~ /INFORMATION/ { printf "%s ", $1 }'
  81 }
  82 
  83 #
  84 # get_dhcpinfo <code/identifier>
  85 #
  86 # echoes the value received through each interface controlled by DHCP;
  87 # multiple values are echoed as a space-separated list
  88 #
  89 # returns:
  90 #       0 => property is set
  91 #       1 => property is not set
  92 #
  93 get_dhcpinfo () {
  94         code=$1
  95 
  96         # Get all interfaces with DHCP control, IFS is " "
  97         interfaces=`get_dhcp_interfaces`
  98 


 198                         fi
 199                         DNS_DOMAIN=`nwam_get_loc_prop $loc \
 200                             dns-nameservice-domain`
 201                         DNS_SEARCH=`nwam_get_loc_list_prop $loc \
 202                             dns-nameservice-search`
 203                         ;;
 204                 'dhcp')
 205                         DNS_SEARCH=`get_dhcpinfo DNSdmain`
 206                         DNS_SERVERS=`get_dhcpinfo DNSserv`
 207                         # Use first search list entry as default domain
 208                         set -- $DNS_SEARCH
 209                         DNS_DOMAIN=$1
 210                         ;;
 211                 '*')
 212                         echo "Unrecognized DNS configsrc ${configsrc}; ignoring"
 213                         ;;
 214                 esac
 215 
 216                 # Write DNS settings
 217                 if [ -n "$DNS_DOMAIN" ]; then
 218                         echo "$DNS_DOMAIN" | $NAWK \
 219                             '{ for (i = 1; i <= NF; i++) \
 220                             print "domain ", $i }' >> $file.$$
 221                 fi
 222                 if [ -n "$DNS_SEARCH" ]; then
 223                         echo "$DNS_SEARCH" | $NAWK \
 224                             '{ printf("search"); \
 225                             for (i = 1; i <= NF; i++) printf(" %s", $i); \
 226                             printf("\n") }' >> $file.$$
 227                 fi
 228                 if [ -n "$DNS_SERVERS" ]; then
 229                         echo "$DNS_SERVERS" | $NAWK \
 230                             '{ for (i = 1; i <= NF; i++) \
 231                             print "nameserver ", $i }' >> $file.$$
 232                 fi
 233         done    
 234 
 235         # Finally, copy our working version to the real thing
 236         $MV -f $file.$$ $file
 237         start_svc $DNS_CLIENT_FMRI
 238 
 239         return 0
 240 }
 241 
 242 #
 243 # do_nis <location>
 244 #
 245 # Installs NIS information on /var/yp/binding/ for location
 246 #
 247 # Returns 0 on success, 1 on failure
 248 #
 249 do_nis () {


 256         fi
 257 
 258         for configsrc in $NIS_CONFIGSRC; do
 259                 case "$configsrc" in
 260                 'manual')
 261                         NIS_SERVERS=`nwam_get_loc_list_prop $loc \
 262                             nis-nameservice-servers`
 263                         DEFAULT_DOMAIN=`nwam_get_loc_prop $loc default-domain`
 264                         # user-specified default-domain always wins
 265                         if [ -n "$DEFAULT_DOMAIN" ]; then
 266                                 $DOMAINNAME $DEFAULT_DOMAIN
 267                                 $DOMAINNAME > $ETC_DEFAULT_DOMAIN
 268                         else
 269                                 echo "'domainname' not set for '$loc'"
 270                                 return 1
 271                         fi
 272                         ;;
 273                 'dhcp')
 274                         # Use only the first name
 275                         DEFAULT_DOMAIN=`get_dhcpinfo NISdmain | \
 276                             $NAWK '{ print $1 }'`
 277                         NIS_SERVERS=`get_dhcpinfo NISservs`
 278                         $DOMAINNAME $DEFAULT_DOMAIN
 279                         $DOMAINNAME > $ETC_DEFAULT_DOMAIN
 280                         ;;
 281                 '*')
 282                         echo "Unrecognized NIS configsrc ${configsrc}; ignoring"
 283                         ;;
 284                 esac
 285 
 286                 # Place NIS settings in appropriate directory/file.
 287                 if [ ! -d "$NIS_BIND_PATH/$DEFAULT_DOMAIN" ]; then
 288                         $MKDIR -p $NIS_BIND_PATH/$DEFAULT_DOMAIN
 289                 fi
 290                 if [ -n "$NIS_SERVERS" ]; then
 291                         echo "$NIS_SERVERS" | $NAWK \
 292                             '{ for (i = 1; i <= NF; i++) print $i }' \
 293                             > $NIS_BIND_PATH/$DEFAULT_DOMAIN/ypservers
 294                 fi
 295         done
 296 
 297         start_svc $NIS_CLIENT_FMRI
 298 
 299         return 0
 300 }
 301 
 302 #
 303 # do_ldap <location>
 304 #
 305 # Installs LDAP information using ldapclient(1M) for location
 306 #
 307 # Returns 0 on success, 1 on failure
 308 #
 309 do_ldap () {
 310         loc=$1
 311 




  29 # FMRI consts
  30 AUTOFS_FMRI="svc:/system/filesystem/autofs"
  31 DNS_CLIENT_FMRI="svc:/network/dns/client"
  32 IPSEC_IKE_FMRI="svc:/network/ipsec/ike"
  33 IPSEC_POLICY_FMRI="svc:/network/ipsec/policy"
  34 IPFILTER_FMRI="svc:/network/ipfilter:default"
  35 LDAP_CLIENT_FMRI="svc:/network/ldap/client"
  36 LOCATION_FMRI="svc:/network/location:default"
  37 MAPID_FMRI="svc:/network/nfs/mapid:default"
  38 NIS_CLIENT_FMRI="svc:/network/nis/client"
  39 NWAM_FMRI="svc:/network/physical:nwam"
  40 
  41 # commands
  42 CP=/usr/bin/cp
  43 DHCPINFO=/sbin/dhcpinfo
  44 DOMAINNAME=/usr/bin/domainname
  45 GREP=/usr/bin/grep
  46 LDAPCLIENT=/usr/sbin/ldapclient
  47 MKDIR=/usr/bin/mkdir
  48 MV=/usr/bin/mv
  49 AWK=/usr/xpg4/bin/awk
  50 NWAMADM=/usr/sbin/nwamadm
  51 NWAMCFG=/usr/sbin/nwamcfg
  52 RM=/usr/bin/rm
  53 SED=/usr/bin/sed
  54 SVCADM=/usr/sbin/svcadm
  55 SVCCFG=/usr/sbin/svccfg
  56 SVCPROP=/usr/bin/svcprop
  57 TOUCH=/usr/bin/touch
  58 
  59 # Path to directories
  60 ETC_DEFAULT_DOMAIN=/etc/defaultdomain
  61 NIS_BIND_PATH=/var/yp/binding
  62 LEGACY_LOC_PATH=/etc/nwam/loc/Legacy
  63 USER_LOC_PATH=/etc/nwam/loc/User
  64 SCRIPT_PATH=/etc/svc/volatile/nwam
  65 
  66 #
  67 # echoes DHCP controlled interfaces separated by commas
  68 #
  69 # Don't parse the output of ifconfig(1M) because interfaces that haven't
  70 # acquired a DHCP lease also have the DHCP flag set.
  71 #
  72 get_dhcp_interfaces () {
  73         #
  74         # 1. parse netstat(1M) output for v4 interfaces in BOUND
  75         #    or INFORMATION state
  76         # 2. make a space-separated list of interface names
  77         #
  78         netstat -D -f inet | $AWK '
  79             $2 ~ /BOUND/ { printf "%s ", $1 }
  80             $2 ~ /INFORMATION/ { printf "%s ", $1 }'
  81 }
  82 
  83 #
  84 # get_dhcpinfo <code/identifier>
  85 #
  86 # echoes the value received through each interface controlled by DHCP;
  87 # multiple values are echoed as a space-separated list
  88 #
  89 # returns:
  90 #       0 => property is set
  91 #       1 => property is not set
  92 #
  93 get_dhcpinfo () {
  94         code=$1
  95 
  96         # Get all interfaces with DHCP control, IFS is " "
  97         interfaces=`get_dhcp_interfaces`
  98 


 198                         fi
 199                         DNS_DOMAIN=`nwam_get_loc_prop $loc \
 200                             dns-nameservice-domain`
 201                         DNS_SEARCH=`nwam_get_loc_list_prop $loc \
 202                             dns-nameservice-search`
 203                         ;;
 204                 'dhcp')
 205                         DNS_SEARCH=`get_dhcpinfo DNSdmain`
 206                         DNS_SERVERS=`get_dhcpinfo DNSserv`
 207                         # Use first search list entry as default domain
 208                         set -- $DNS_SEARCH
 209                         DNS_DOMAIN=$1
 210                         ;;
 211                 '*')
 212                         echo "Unrecognized DNS configsrc ${configsrc}; ignoring"
 213                         ;;
 214                 esac
 215 
 216                 # Write DNS settings
 217                 if [ -n "$DNS_DOMAIN" ]; then
 218                         echo "$DNS_DOMAIN" | $AWK \
 219                             '{ for (i = 1; i <= NF; i++) \
 220                             print "domain ", $i }' >> $file.$$
 221                 fi
 222                 if [ -n "$DNS_SEARCH" ]; then
 223                         echo "$DNS_SEARCH" | $AWK \
 224                             '{ printf("search"); \
 225                             for (i = 1; i <= NF; i++) printf(" %s", $i); \
 226                             printf("\n") }' >> $file.$$
 227                 fi
 228                 if [ -n "$DNS_SERVERS" ]; then
 229                         echo "$DNS_SERVERS" | $AWK \
 230                             '{ for (i = 1; i <= NF; i++) \
 231                             print "nameserver ", $i }' >> $file.$$
 232                 fi
 233         done    
 234 
 235         # Finally, copy our working version to the real thing
 236         $MV -f $file.$$ $file
 237         start_svc $DNS_CLIENT_FMRI
 238 
 239         return 0
 240 }
 241 
 242 #
 243 # do_nis <location>
 244 #
 245 # Installs NIS information on /var/yp/binding/ for location
 246 #
 247 # Returns 0 on success, 1 on failure
 248 #
 249 do_nis () {


 256         fi
 257 
 258         for configsrc in $NIS_CONFIGSRC; do
 259                 case "$configsrc" in
 260                 'manual')
 261                         NIS_SERVERS=`nwam_get_loc_list_prop $loc \
 262                             nis-nameservice-servers`
 263                         DEFAULT_DOMAIN=`nwam_get_loc_prop $loc default-domain`
 264                         # user-specified default-domain always wins
 265                         if [ -n "$DEFAULT_DOMAIN" ]; then
 266                                 $DOMAINNAME $DEFAULT_DOMAIN
 267                                 $DOMAINNAME > $ETC_DEFAULT_DOMAIN
 268                         else
 269                                 echo "'domainname' not set for '$loc'"
 270                                 return 1
 271                         fi
 272                         ;;
 273                 'dhcp')
 274                         # Use only the first name
 275                         DEFAULT_DOMAIN=`get_dhcpinfo NISdmain | \
 276                             $AWK '{ print $1 }'`
 277                         NIS_SERVERS=`get_dhcpinfo NISservs`
 278                         $DOMAINNAME $DEFAULT_DOMAIN
 279                         $DOMAINNAME > $ETC_DEFAULT_DOMAIN
 280                         ;;
 281                 '*')
 282                         echo "Unrecognized NIS configsrc ${configsrc}; ignoring"
 283                         ;;
 284                 esac
 285 
 286                 # Place NIS settings in appropriate directory/file.
 287                 if [ ! -d "$NIS_BIND_PATH/$DEFAULT_DOMAIN" ]; then
 288                         $MKDIR -p $NIS_BIND_PATH/$DEFAULT_DOMAIN
 289                 fi
 290                 if [ -n "$NIS_SERVERS" ]; then
 291                         echo "$NIS_SERVERS" | $AWK \
 292                             '{ for (i = 1; i <= NF; i++) print $i }' \
 293                             > $NIS_BIND_PATH/$DEFAULT_DOMAIN/ypservers
 294                 fi
 295         done
 296 
 297         start_svc $NIS_CLIENT_FMRI
 298 
 299         return 0
 300 }
 301 
 302 #
 303 # do_ldap <location>
 304 #
 305 # Installs LDAP information using ldapclient(1M) for location
 306 #
 307 # Returns 0 on success, 1 on failure
 308 #
 309 do_ldap () {
 310         loc=$1
 311