Home | History | Annotate | Download | only in smb
      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	"@(#)control_samba.ksh	1.9	07/06/06 SMI"
     28 #
     29 # Usage GDS: <options> <parameter1> <parameter2>
     30 # 
     31 # Usage SMF: <parameter1> <parameter2> <parameter3>
     32 # 
     33 #       <options>: -R <resource> -G <resourcegroup> etc.
     34 #	parameter1: start | stop | probe
     35 #	parameter2: samba | winbindd
     36 #	parameter3: <FMRI>
     37 
     38 MYNAME=`basename $0`
     39 MYDIR=`dirname $0`
     40 
     41 typeset opt
     42 
     43 while getopts 'R:G:X:B:S:C:U:M:L:H:P:N:Y' opt
     44 do
     45         case "${opt}" in
     46 		R)      RESOURCE=${OPTARG};;
     47 		G)      RESOURCEGROUP=${OPTARG};;
     48 		X)      SERVICES=${OPTARG};;
     49 		N)	# To provide backward agent support, Samba can now optionally run nmbd using
     50 			# option -N 'YES|NO'. Winbind also has an option -n to disable caching. So, 
     51 			# to accomodate Samba and Winbind using the same control_samba file, we need 
     52 			# to determine if we need to set RUN_NMBD or WINBIND_DISCACHE based on the
     53 			# option -N and it's ${OPTARG} values.
     54 			#	
     55 			# Possible combinations are :
     56 			# -N -Y			(Winbind disable caching and running as a single daemon)
     57 			# -N start|stop|probe	(Winbind disable caching)
     58 			# -N YES|NO		(Samba using nmbd or not)
     59 
     60 			if [ "${OPTARG}" ]
     61 			then
     62 			   case ${OPTARG} in
     63 				"-Y")   WINBIND_DISCACHE="-n"
     64 					WINBIND_SINGLEMODE="-Y"
     65 					;;
     66 				start|stop|probe)
     67 					WINBIND_DISCACHE="-n"
     68 					SHIFT=-2
     69 					;;
     70 				*)	RUN_NMBD=${OPTARG}
     71 					RUN_NMBD=`/usr/bin/echo ${RUN_NMBD} | /usr/bin/tr -s '[:lower:]' '[:upper:]'`
     72 					;;
     73 			   esac
     74 			else
     75 			   WINBIND_DISCACHE="-n"
     76 			fi;;
     77 		B)      BINDIR=${OPTARG};;
     78 		S)      SBINDIR=${OPTARG};;
     79 		C)      CFGDIR=${OPTARG};;
     80 		U)      SAMBA_FMUSER=${OPTARG};;
     81 		M)      SAMBA_FMRESOURCE=${OPTARG};;
     82 		L)      SAMBA_LOGDIR=${OPTARG};;
     83 		H)	LHOST=${OPTARG};;
     84 		P)      LDPATH=${OPTARG}
     85 			export LD_LIBRARY_PATH=${LDPATH};;
     86 		N)      WINBIND_DISCACHE="-n";;
     87 		Y)      WINBIND_SINGLEMODE="-Y";;
     88 
     89 		*)      exit 1;;
     90 	esac
     91 done
     92 
     93 if [ "${OPTIND}" -gt 1 ]
     94 then
     95 	# Called by GDS
     96 	CALLER=GDS
     97 
     98 	if [ "${SHIFT}" ]
     99 	then
    100 	   shift $(($OPTIND ${SHIFT}))
    101 	else
    102 	   shift $(($OPTIND -1))
    103 	fi
    104 else
    105 	# Called by SMF
    106 	CALLER=SMF
    107 
    108 	. /lib/svc/share/smf_include.sh
    109 
    110 	SMF_FMRI=${3}
    111 fi
    112 
    113 METHOD=${1}
    114 COMPONENT=${2}
    115 
    116 if [ "${CALLER}" = "GDS" ]
    117 then
    118 	# Setting RUN_NMBD provides backward agent support
    119 	if [ "${COMPONENT}" = "samba" ]
    120 	then
    121 	   if [ -z "${SERVICES}" ]
    122 	   then
    123 		[ -z "${RUN_NMBD}" ] && RUN_NMBD=YES
    124 
    125 		if [ "${RUN_NMBD}" = "YES" ]
    126 		then
    127 		   SERVICES="nmbd smbd"
    128 		else
    129 		   SERVICES=smbd
    130 		fi
    131 	   else
    132 		if /usr/bin/echo ${SERVICES} | /usr/bin/grep nmbd > /dev/null
    133 		then
    134 		   RUN_NMBD=YES
    135 		else
    136 		   RUN_NMBD=NO
    137 		fi
    138 	   fi
    139 	fi
    140 
    141 	# Perform all scha* calls
    142 	if [ "${METHOD}" = "probe" -a "${COMPONENT}" = "samba" ]
    143 	then
    144 	   PROBE_TIMEOUT=`/usr/cluster/bin/scha_resource_get -O Extension \
    145 	      -R ${RESOURCE} -G ${RESOURCEGROUP} Probe_timeout`
    146 
    147            PROBE_TIMEOUT=`/usr/bin/echo ${PROBE_TIMEOUT} | /usr/bin/awk '{print $2}'`
    148 	
    149 	   if [ "${RUN_NMBD}" = "YES" ]
    150 	   then
    151 		if [ -z "${LHOST}" ]
    152 		then
    153 		   SCLH=`/usr/cluster/bin/scha_resource_get -O Network_resources_used \
    154 		      -R ${RESOURCE} -G ${RESOURCEGROUP}`
    155 
    156 		   LHOST=`/usr/cluster/bin/scrgadm -pvv -j ${SCLH} | /usr/bin/grep HostnameList | \
    157         		/usr/bin/grep value: | /usr/bin/awk -F: '{print $4}'`
    158 		fi
    159 	   fi
    160 	fi
    161 else
    162 	if [ "${COMPONENT}" = "samba" ]
    163 	then
    164 	   ### Samba properties are stored within the failover zone's SMF repository ###
    165 	   for i in RESOURCE RESOURCEGROUP SERVICES BINDIR SBINDIR CFGDIR \
    166 		   SAMBA_FMUSER SAMBA_FMPASS SAMBA_FMDOMAIN SAMBA_FMRESOURCE SAMBA_LOGDIR \
    167 		   LDPATH LHOST PROBE_TIMEOUT
    168 	   do
    169 	      export $i=`/usr/bin/svcprop -p parameters/$i ${SMF_FMRI}`
    170 	   done
    171 
    172 	   if [ "${SAMBA_FMDOMAIN}" = '""' ]; then
    173 		SAMBA_FMUSER=${SAMBA_FMUSER}%${SAMBA_FMPASS}
    174 	   else
    175 		SAMBA_FMUSER=${SAMBA_FMDOMAIN}'\\\\'${SAMBA_FMUSER}%${SAMBA_FMPASS}
    176 	   fi
    177 	else
    178 	   ### Winbind properties are stored within the failover zone's SMF repository ###
    179 	   for i in RESOURCE RESOURCEGROUP SERVICES BINDIR SBINDIR CFGDIR \
    180 		   SAMBA_FMUSER LDPATH WINBIND_DISCACHE WINBIND_SINGLEMODE 
    181 	   do
    182 	      export $i=`/usr/bin/svcprop -p parameters/$i ${SMF_FMRI}`
    183 	   done
    184 	fi
    185 
    186 	SERVICES=`/usr/bin/echo ${SERVICES} | /usr/bin/tr "_"  " "`
    187 
    188 	# Setting RUN_NMBD provides backward agent support
    189 	if /usr/bin/echo ${SERVICES} | /usr/bin/grep nmbd > /dev/null
    190 	then
    191 	   RUN_NMBD=YES
    192 	else
    193 	   RUN_NMBD=NO
    194 	fi
    195 fi
    196 
    197 . ${MYDIR}/../${COMPONENT}/etc/config
    198 . ${MYDIR}/functions
    199 
    200 [ -x /sbin/zonename ] && ZONENAME=`/sbin/zonename`
    201 
    202 debug_message "Method: ${MYNAME} - Begin"
    203 ${SET_DEBUG}
    204 
    205 case "${METHOD}" in
    206 	start)
    207 		case "${COMPONENT}" in
    208 		   samba)	validate_common
    209 				rc1=$?
    210 				validate_samba
    211 				rc2=$?
    212 				rc=1; [ "${rc1}" -eq 0 -a "${rc2}" -eq 0 ] && rc=0
    213 				[ "${rc}" -eq 0 ] && start_samba
    214 				rc=$?
    215 				;;
    216 		   winbind)	validate_common
    217 				rc1=$?
    218 				validate_winbind
    219 				rc2=$?
    220 				rc=1; [ "${rc1}" -eq 0 -a "${rc2}" -eq 0 ] && rc=0
    221 				[ "${rc}" -eq 0 ] && start_winbind
    222 				rc=$?
    223 				;;
    224 		esac
    225 		;;
    226 	stop)
    227 		case "${COMPONENT}" in
    228 		   samba)	stop_samba
    229 				rc=$?
    230 				;;
    231 		   winbind)	stop_winbind
    232 				rc=$?
    233 				;;
    234 		esac
    235 		;;
    236 
    237 
    238 	probe)
    239 		case "${COMPONENT}" in
    240 		   samba)	check_start "start_samba"
    241 				rc=$?
    242 				[ "${rc}" -eq 100 ] && return ${rc}
    243 				check_samba
    244 				rc=$?
    245 				;;
    246 		   winbind)	check_start "start_winbind"
    247 				rc=$?
    248 				[ "${rc}" -eq 100 ] && return ${rc}
    249 				check_winbind
    250 				rc=$?
    251 				;;
    252 		esac
    253 		;;
    254 esac
    255 
    256 exit ${rc}
    257