1 #!/usr/bin/ksh 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/CDDL.txt 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/CDDL.txt. 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 #ident "@(#)samba_register.ksh 1.9 07/06/06 SMI" 28 # 29 30 SMBDIR=/opt/SUNWscsmb 31 MYNAME=`basename $0` 32 rc=0 33 34 TMP_WORK_CONFIG=/opt/SUNWscsmb/util/.tmp_work_config 35 typeset opt 36 37 while getopts 'f:' opt 38 do 39 case "$opt" in 40 f) MYCONFIG=${OPTARG};; 41 *) /usr/bin/echo "ERROR: ${MYNAME} Option ${OPTARG} unknown" 42 /usr/bin/echo "Usage: ${MYNAME} -f <config file>" 43 exit 1;; 44 esac 45 done 46 47 [ -z "${MYCONFIG}" ] && MYCONFIG=/opt/SUNWscsmb/util/samba_config 48 49 /usr/bin/cp ${MYCONFIG} ${TMP_WORK_CONFIG} 50 . ${TMP_WORK_CONFIG} 51 52 if [ ${SERVICES} ] 53 then 54 SERVICES=`/usr/bin/echo ${SERVICES} | /usr/bin/tr -d " " | /usr/bin/tr "," " "` 55 56 case ${SERVICES} in 57 smbd|"smbd nmbd") COMPONENT=samba;; 58 winbindd) COMPONENT=winbind;; 59 *) /usr/bin/printf "${MYCONFIG} SERVICES parameter incorrect\n" 60 exit 1;; 61 esac 62 else 63 /usr/bin/printf "${MYCONFIG} requires SERVICES to be set\n" 64 exit 1 65 fi 66 67 case ${COMPONENT} in 68 samba) 69 # Ensure all the required parameters are set 70 71 for i in RS RG SERVICES BINDIR SBINDIR CFGDIR LDPATH FMUSER \ 72 SAMBA_LOGDIR SAMBA_FMPASS 73 do 74 if eval [ -z \$$i ]; then 75 /usr/bin/printf "${SMBDIR}/util/samba_register script requires the following parameter, but it is not set $i=\n" 76 rc=1 77 fi 78 done 79 80 [ "${rc}" -ne 0 ] && exit 1 81 82 if [ "${SAMBA_FMDOMAIN}" ]; then 83 FMUSER=${SAMBA_FMDOMAIN}'\\\\'${FMUSER}%${SAMBA_FMPASS} 84 else 85 FMUSER=${FMUSER}%${SAMBA_FMPASS} 86 fi 87 ;; 88 winbind) 89 # Ensure all the required parameters are set 90 91 for i in RS RG SERVICES BINDIR SBINDIR CFGDIR LDPATH FMUSER \ 92 WINBIND_DISCACHE WINBIND_SINGLEMODE 93 do 94 if eval [ -z \$$i ]; then 95 /usr/bin/printf "${SMBDIR}/util/samba_register requires the following parameter, but it is not set $i=\n" 96 rc=1 97 fi 98 done 99 100 # If amending WINBIND_DISCACHE or WINBIND_SINGLEMODE, check samba_smf_register 101 # Note, samba_register has WINBIND_DISCACHE="-N" 102 # and samba_smf_register has WINBIND_DISCACHE="-n" 103 104 WINBIND_DISCACHE=`/usr/bin/echo ${WINBIND_DISCACHE} | /usr/bin/tr -s '[:lower:]' '[:upper:]'` 105 WINBIND_SINGLEMODE=`/usr/bin/echo ${WINBIND_SINGLEMODE} | /usr/bin/tr -s '[:lower:]' '[:upper:]'` 106 107 if [ "${WINBIND_DISCACHE}" = "TRUE" ] 108 then 109 WINBIND_DISCACHE="-N" 110 else 111 WINBIND_DISCACHE="" 112 fi 113 114 if [ "${WINBIND_SINGLEMODE}" = "TRUE" ] 115 then 116 WINBIND_SINGLEMODE="-Y" 117 else 118 WINBIND_SINGLEMODE="" 119 fi 120 121 [ "${rc}" -ne 0 ] && exit 1 122 ;; 123 *) /usr/bin/printf "Unexpected error SERVICES=${SERVICES} COMPONENT=${COMPONENT}\n" 124 exit 1 125 ;; 126 esac 127 128 if [ -z ${RS_ZONE} ] 129 then 130 ### Process pre-S10, S10 global zone and S10 integrated zone registration ### 131 ### All parameter values get stored within the CCR ### 132 133 if [ "${COMPONENT}" = "samba" ] 134 then 135 136 /usr/cluster/bin/scrgadm -a -j ${RS} -g ${RG} -t SUNW.gds \ 137 -x Start_command="/opt/SUNWscsmb/samba/bin/start_samba \ 138 -R '${RS}' -G '${RG}' -X '${SERVICES}' -B '${BINDIR}' -S '${SBINDIR}' -C '${CFGDIR}' \ 139 -L '${SAMBA_LOGDIR}' -U ${FMUSER} -M 'scmondir' -P '${LDPATH}' -H %HOSTNAMES " \ 140 -x Stop_command="/opt/SUNWscsmb/samba/bin/stop_samba \ 141 -R '${RS}' -G '${RG}' -X '${SERVICES}' -B '${BINDIR}' -S '${SBINDIR}' -C '${CFGDIR}' \ 142 -L '${SAMBA_LOGDIR}' -U ${FMUSER} -M 'scmondir' -P '${LDPATH}' -H %HOSTNAMES " \ 143 -x Probe_command="/opt/SUNWscsmb/samba/bin/probe_samba \ 144 -R '${RS}' -G '${RG}' -X '${SERVICES}' -B '${BINDIR}' -S '${SBINDIR}' -C '${CFGDIR}' \ 145 -L '${SAMBA_LOGDIR}' -U ${FMUSER} -M 'scmondir' -P '${LDPATH}' -H %HOSTNAMES " \ 146 -y Port_list=23/tcp -y Network_resources_used=${RS_LH} \ 147 -x Stop_signal=9 \ 148 -y Resource_dependencies_restart=${RS_LH},${RS_HAS} 149 150 else 151 152 /usr/cluster/bin/scrgadm -a -j ${RS} -g ${RG} -t SUNW.gds \ 153 -x Start_command="/opt/SUNWscsmb/winbind/bin/start_winbind \ 154 -R '${RS}' -G '${RG}' -X '${SERVICES}' -B '${BINDIR}' -S '${SBINDIR}' -C '${CFGDIR}' \ 155 -U ${FMUSER} -P '${LDPATH}' ${WINBIND_DISCACHE} ${WINBIND_SINGLEMODE} " \ 156 -x Stop_command="/opt/SUNWscsmb/winbind/bin/stop_winbind \ 157 -R '${RS}' -G '${RG}' -X '${SERVICES}' -B '${BINDIR}' -S '${SBINDIR}' -C '${CFGDIR}' \ 158 -U ${FMUSER} -P '${LDPATH}' ${WINBIND_DISCACHE} ${WINBIND_SINGLEMODE} " \ 159 -x Probe_command="/opt/SUNWscsmb/winbind/bin/probe_winbind \ 160 -R '${RS}' -G '${RG}' -X '${SERVICES}' -B '${BINDIR}' -S '${SBINDIR}' -C '${CFGDIR}' \ 161 -U ${FMUSER} -P '${LDPATH}' ${WINBIND_DISCACHE} ${WINBIND_SINGLEMODE} " \ 162 -y Port_list=23/tcp -y Network_resources_used=${RS_LH} \ 163 -x Stop_signal=9 \ 164 -y Resource_dependencies_restart=${RS_LH},${RS_HAS} 165 166 fi 167 else 168 ### Process S10 non-global (failover) zone registration ### 169 ### All parameter values get stored within the SMF repository ### 170 171 ### 1. Validate ${TIMEOUT} is an integer, greater than or equal to 0 ### 172 ### 2. Get the failover zone's pfile and determine failover zone name ### 173 ### 3. Build a temporary sczsmf_config file (i.e. /tmp/${RS}_smf_config) ### 174 ### 4. zlogin to the failover zone execute mqr_smf_register ### 175 ### - Creates the SMF manifest using parameter values ### 176 ### - Validate and import the SMF manifest into the SMF repository ### 177 ### 5. Register a SC sczsmf resource to enable/disable the SMF instance ### 178 179 RS_STATE=`/usr/cluster/bin/scha_resource_get -O status -R ${RS}` 180 rc=$? 181 182 if [ "${rc}" -eq 0 ] 183 then 184 /usr/bin/printf "Sun Cluster resource ${RS} already exists\n" 185 exit 1 186 fi 187 188 if ! [ "${TIMEOUT}" -ge 0 ] 2> /dev/null 189 then 190 /usr/bin/printf "TIMEOUT value is not an integer\n" 191 exit 1 192 fi 193 194 ZONEPFILE=`/usr/cluster/bin/scrgadm -pvv -j ${RS_ZONE} | /usr/bin/grep -w Start_command | \ 195 /usr/bin/grep -w value | /usr/bin/awk '{ if ($10 == "-P") print $11 }'` 196 197 if [ ! -d "${ZONEPFILE}" ] 198 then 199 /usr/bin/printf "Unable to retrieve zone parameter file directory\n" 200 exit 1 201 else 202 ZONE=`/usr/bin/grep Zonename= ${ZONEPFILE}/sczbt_${RS_ZONE} | /usr/bin/awk -F= '{print $2}'` 203 fi 204 205 SERVICE_TAG=svc:/application/sczone-agents:${RS} 206 207 /usr/bin/cat > /tmp/${RS}_smf_config <<-EOF 208 RS=${RS} 209 RG=${RG} 210 SCZBT_RS=${RS_ZONE} 211 ZONE=${ZONE} 212 SERVICE=${SERVICE_TAG} 213 RECURSIVE=true 214 STATE=true 215 SERVICE_PROBE="/opt/SUNWscsmb/bin/control_samba probe ${COMPONENT} ${SERVICE_TAG}" 216 EOF 217 218 # Remove an existing FMRI in the zone if it already exists 219 ${SMBDIR}/util/samba_smf_remove -z ${ZONE} -f ${SERVICE_TAG} 2>/dev/null 220 221 if /usr/sbin/zlogin ${ZONE} ${SMBDIR}/util/samba_smf_register ${TMP_WORK_CONFIG} ${COMPONENT} 222 then 223 if RS_STATE=`/usr/cluster/bin/scha_resource_get -O status -R ${RS}` 224 then 225 RS_STATE=`/usr/bin/echo ${RS_STATE} | /usr/bin/awk '{print $1}'` 226 227 if [ "${RS_STATE}" = "OFFLINE" ] 228 then 229 /usr/bin/printf "${RS} already registered, but Offline\n" 230 if /usr/cluster/bin/scrgadm -r -j ${RS} 231 then 232 /usr/bin/printf "${RS} removed\n" 233 else 234 /usr/bin/printf "Fix or cleanup resources before retrying\n" 235 exit 1 236 fi 237 else 238 /usr/bin/printf "${RS} already registered and is ${RS_STATE}\n" 239 /usr/bin/printf "Registration of ${RS} failed\n" 240 exit 1 241 fi 242 fi 243 244 if /opt/SUNWsczone/sczsmf/util/sczsmf_register -f /tmp/${RS}_smf_config 245 then 246 /usr/bin/printf "Registration of ${RS} succeeded\n" 247 else 248 /usr/bin/printf "Registration of ${RS} failed\n" 249 exit 1 250 fi 251 fi 252 253 /usr/bin/rm ${TMP_WORK_CONFIG} 254 fi 255 256 exit 0 257