1 # 2 # CDDL HEADER START 3 # 4 # The contents of this file are subject to the terms of the 5 # Common Development and Distribution License (the License). 6 # You may not use this file except in compliance with the License. 7 # 8 # You can obtain a copy of the license at usr/src/CDDL.txt 9 # or http://www.opensolaris.org/os/licensing. 10 # See the License for the specific language governing permissions 11 # and limitations under the License. 12 # 13 # When distributing Covered Code, include this CDDL HEADER in each 14 # file and include the License file at usr/src/CDDL.txt. 15 # If applicable, add the following below this CDDL HEADER, with the 16 # fields enclosed by brackets [] replaced with your own identifying 17 # information: Portions Copyright [yyyy] [name of copyright owner] 18 # 19 # CDDL HEADER END 20 # 21 22 # 23 # Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24 # Use is subject to license terms. 25 # 26 #ident "@(#)functions.ksh 1.11 07/06/06 SMI" 27 # 28 29 PKG=SUNWscsmb 30 MYNAME=`basename $0` 31 MYDIR=`dirname $0` 32 MYTMPDIR=/var/tmp 33 LOGFILE=${MYTMPDIR}/${RESOURCE}_${COMPONENT}_logfile 34 SCLOGGER=/usr/cluster/lib/sc/scds_syslog 35 LOGGER=/usr/bin/logger 36 37 NMBD=${SBINDIR}/nmbd 38 SMBD=${SBINDIR}/smbd 39 NMBLOOKUP=${BINDIR}/nmblookup 40 WINBINDD=${SBINDIR}/winbindd 41 SMBCONF=${CFGDIR}/lib/smb.conf 42 SMBCLIENT=${BINDIR}/smbclient 43 NETBIOSNAME=`basename ${CFGDIR}` 44 NMBDLOCKF=${CFGDIR}/var/locks/nmbd.pid 45 SMBDLOCKF=${CFGDIR}/var/locks/smbd.pid 46 SAMBA_LOGDIR_TEMP=${CFGDIR}/logs 47 WINBINDLOCKF=${CFGDIR}/var/locks/winbindd.pid 48 NSS=/etc/nsswitch.conf 49 NODEID_LOCAL=`/usr/sbin/clinfo -n` 50 STARTWAIT=`expr ${NODEID_LOCAL} \* 2` 51 TMPF=/var/tmp/${NETBIOSNAME}.tmp 52 53 syslog_tag() 54 { 55 ${SET_DEBUG} 56 print "SC[${PKG:-??}.${COMPONENT:-??}.${METHOD:-??}]:${RESOURCEGROUP:-??}:${RESOURCE:-??}" 57 } 58 59 scds_syslog() 60 { 61 if [ -f ${SCLOGGER} ] 62 then 63 ${SCLOGGER} "$@" & 64 else 65 while getopts 'p:t:m' opt 66 do 67 case "${opt}" in 68 t) TAG=${OPTARG};; 69 p) PRI=${OPTARG};; 70 esac 71 done 72 73 shift $((${OPTIND} - 1)) 74 LOG_STRING=`/usr/bin/printf "$@"` 75 ${LOGGER} -p ${PRI} -t ${TAG} ${LOG_STRING} 76 fi 77 } 78 79 debug_message() 80 { 81 if [ "${DEBUG}" = "${RESOURCE}" -o "${DEBUG}" = "ALL" ] 82 then 83 SET_DEBUG="set -x" 84 DEBUG_TEXT=${1} 85 86 scds_syslog -p daemon.debug -t $(syslog_tag) -m \ 87 "%s" "${DEBUG_TEXT}" 88 else 89 SET_DEBUG= 90 fi 91 } 92 93 log_message() 94 { 95 debug_message "Function: log_message - Begin" 96 ${SET_DEBUG} 97 98 if [ -s "${LOGFILE}" ] 99 then 100 PRIORITY=$1 101 HEADER=$2 102 103 strings ${LOGFILE} > ${LOGFILE}.copy 104 105 while read MSG_TXT 106 do 107 scds_syslog -p daemon.${PRIORITY} -t $(syslog_tag) -m \ 108 "%s - %s" \ 109 "${HEADER}" "${MSG_TXT}" 110 done < ${LOGFILE}.copy 111 112 /usr/bin/cat /dev/null > ${LOGFILE} 113 fi 114 } 115 116 stripfunc() 117 { 118 s1=1 119 s2=`echo ${1} | /usr/bin/wc -c` 120 s3="" 121 122 while [ ${s1} -lt ${s2} ] 123 do 124 s4=`/usr/bin/echo ${1} | /usr/bin/cut -c ${s1}` 125 126 if [[ "${s4}" != @([0-9]) ]] 127 then 128 break 129 else 130 s3=${s3}${s4} 131 fi 132 133 s1=$(($s1+1)) 134 done 135 136 /usr/bin/echo ${s3} 137 } 138 139 validate_samba() 140 { 141 debug_message "Function: validate_samba - Begin" 142 ${SET_DEBUG} 143 144 # Validate - Samba log directory ${SAMBA_LOGDIR} exists 145 # Validate - smbd ${SMBD} exists and is executable 146 # Validate - nmbd ${NMBD} exists and is executable 147 # Validate - Faultmonitor resource ${SAMBA_FMRESOURCE} exists 148 # Validate - smbclient ${SMBCLIENT} exists and is executable 149 # Validate - Retrieved faultmonitor-user ${USER} from the nameservice 150 # Validate - RUN_NMBD=${RUN_NMBD 151 152 rc=0 153 154 if [ ! -d "${SAMBA_LOGDIR}" ] 155 then 156 # SCMSGS 157 # @explanation 158 # The Samba log directory does not exist. 159 # @user_action 160 # Check the correct pathname for the Samba log directory was 161 # entered when registering the Samba resource and that the 162 # directory exists. 163 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 164 "Validate - Samba log directory %s does not exist" \ 165 "${SAMBA_LOGDIR}" 166 rc=1 167 else 168 debug_message "Validate - Samba log directory ${SAMBA_LOGDIR} exists" 169 fi 170 171 if [ ! -x "${SMBD}" ] 172 then 173 # SCMSGS 174 # @explanation 175 # The Samba executable smbd either doesn't exist or is not 176 # executable. 177 # @user_action 178 # Check the correct pathname for the Samba (s)bin directory was 179 # entered when registering the resource and that the program exists 180 # and is executable. 181 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 182 "Validate - smbd %s non-existent executable" \ 183 "${SMBD}" 184 rc=1 185 else 186 debug_message "Validate - smbd ${SMBD} exists and is executable" 187 fi 188 189 if [ ! -x "${NMBD}" ] 190 then 191 # SCMSGS 192 # @explanation 193 # The Samba executable nmbd either doesn't exist or is not 194 # executable. 195 # @user_action 196 # Check the correct pathname for the Samba (s)bin directory was 197 # entered when registering the resource and that the program exists 198 # and is executable. 199 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 200 "Validate - nmbd %s non-existent executable" \ 201 "${NMBD}" 202 rc=1 203 else 204 debug_message "Validate - nmbd ${NMBD} exists and is executable" 205 fi 206 207 if [ -z "`/usr/bin/grep '\[' ${SMBCONF} | /usr/bin/cut -d'[' -f2 |\ 208 /usr/bin/cut -d']' -f1 | /usr/bin/grep ${SAMBA_FMRESOURCE}`" ] 209 then 210 # SCMSGS 211 # @explanation 212 # The Samba resource could not validate that the fault monitor 213 # resource exists. 214 # @user_action 215 # Check that the Samba instance's smb.conf file has the fault 216 # monitor resource scmondir defined. Please refer to the data 217 # service documentation to determine how to do this. 218 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 219 "Validate - Faultmonitor-resource <%s> does not exist" \ 220 "${SAMBA_FMRESOURCE}" 221 rc=1 222 else 223 debug_message "Validate - Faultmonitor resource ${SAMBA_FMRESOURCE} exists" 224 fi 225 226 if [ ! -x "${SMBCLIENT}" ] 227 then 228 # SCMSGS 229 # @explanation 230 # The Samba resource tries to validate that the smbclient exists 231 # and is executable. 232 # @user_action 233 # Check the correct pathname for the Samba bin directory was 234 # entered when registering the resource and that the program exists 235 # and is executable. 236 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 237 "Validate - smbclient %s non-existent executable" \ 238 "${SMBCLIENT}" 239 rc=1 240 else 241 debug_message "Validate - smbclient ${SMBCLIENT} exists and is executable" 242 fi 243 244 USER=$(/usr/bin/echo ${SAMBA_FMUSER} | /usr/bin/awk 'BEGIN { FS="\\" } {print $NF}' | /usr/bin/cut -d'%' -f1) 245 246 if [ -z "`/usr/bin/getent passwd ${USER}`" ] 247 then 248 # SCMSGS 249 # @explanation 250 # The Samba resource could not validate that the fault monitor 251 # userid exists. 252 # @user_action 253 # Check that the correct fault monitor userid was used when 254 # registering the Samba resource and that the userid really exists. 255 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 256 "Validate - Couldn't retrieve faultmonitor-user <%s> from the nameservice" \ 257 "${USER}" 258 rc=1 259 else 260 debug_message "Validate - Retrieved faultmonitor-user ${USER} from the nameservice" 261 fi 262 263 RUN_NMBD=`/usr/bin/echo ${RUN_NMBD} | /usr/bin/tr -s '[:lower:]' '[:upper:]'` 264 265 if [ "${RUN_NMBD}" = "YES" -o "${RUN_NMBD}" = "NO" ] 266 then 267 debug_message "Validate - RUN_NMBD=${RUN_NMBD}" 268 else 269 # SCMSGS 270 # @explanation 271 # The Samba resource can run without nmbd, however you must specify 272 # the service when configuring the Samba resource 273 # @user_action 274 # Specify either YES or NO for RUN_NMBD within 275 # /opt/SUNWscsmb/samba/util/samba_config 276 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 277 "Validate - RUN_NMBD=%s is invalid - specify YES or NO" \ 278 "${RUN_NMBD}" 279 rc=1 280 fi 281 282 debug_message "Function: validate_samba - End" 283 return ${rc} 284 } 285 286 validate_winbind() 287 { 288 debug_message "Function: validate_winbind - Begin" 289 ${SET_DEBUG} 290 291 # Validate - winbindd ${WINBINDD} exists and is executable 292 # Validate - winbind defined in ${NSS} in the passwd section 293 # Validate - winbind defined in ${NSS} in the group section 294 295 rc=0 296 297 if [ ! -x "${WINBINDD}" ] 298 then 299 # SCMSGS 300 # @explanation 301 # The Samba executable winbindd either doesn't exist or is not 302 # executable. 303 # @user_action 304 # Check the correct pathname for the Samba (s)bin directory was 305 # entered when registering the resource and that the program exists 306 # and is executable. 307 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 308 "Validate - winbindd %s non-existent executable" \ 309 "${WINBINDD}" 310 rc=1 311 else 312 debug_message "Validate - winbindd ${WINBINDD} exists and is executable" 313 fi 314 315 if [ -z "`/usr/bin/grep passwd: ${NSS} | /usr/bin/grep -v '#' | /usr/bin/grep winbind`" ] 316 then 317 # SCMSGS 318 # @explanation 319 # Winbinbd is missing from the passwd section in /etc/nsswitch.conf 320 # @user_action 321 # Enter winbind within the passwd section in /etc/nsswitch.conf. 322 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 323 "Validate - winbind is not defined in %s in the passwd section" \ 324 "${NSS}" 325 rc=1 326 else 327 debug_message "Validate - winbind defined in ${NSS} in the passwd section" 328 fi 329 330 if [ -z "`/usr/bin/grep group: ${NSS} | /usr/bin/grep -v '#' | /usr/bin/grep winbind`" ] 331 then 332 # SCMSGS 333 # @explanation 334 # Winbinbd is missing from the group section in /etc/nsswitch.conf 335 # @user_action 336 # Enter winbind within the group section in /etc/nsswitch.conf. 337 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 338 "Validate - winbind is not defined in %s in the group section" \ 339 "${NSS}" 340 rc=1 341 else 342 debug_message "Validate - winbind defined in ${NSS} in the group section" 343 fi 344 345 debug_message "Function: validate_winbind - End" 346 return ${rc} 347 } 348 349 validate_common() 350 { 351 debug_message "Function: validate_common - Begin" 352 ${SET_DEBUG} 353 354 # Validate - ${COMPONENT} bin directory ${BINDIR} exists 355 # Validate - ${COMPONENT} sbin directory ${SBINDIR} exists 356 # Validate - ${COMPONENT} configuration directory ${CFGDIR} exists 357 # Validate - smbconf ${SMBCONF} exists 358 # Validate - nmblookup ${NMBLOOKUP} exists and is executable 359 # Validate - Samba version <${SAMBA_VERSION}.${SAMBA_RELEASE}.${SAMBA_UPDATE}> is being used 360 361 rc=0 362 363 if [ ! -d "${BINDIR}" ] 364 then 365 # SCMSGS 366 # @explanation 367 # The Samba bin directory does not exist. 368 # @user_action 369 # Check the correct pathname for the Samba bin directory was 370 # entered when registering the Samba resource and that the 371 # directory exists. 372 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 373 "Validate - %s bin directory %s does not exist" \ 374 "${COMPONENT}" "${BINDIR}" 375 rc=1 376 else 377 debug_message "Validate - ${COMPONENT} bin directory ${BINDIR} exists" 378 fi 379 380 if [ ! -d "${SBINDIR}" ] 381 then 382 # SCMSGS 383 # @explanation 384 # The Samba resource could not validate that Samba sbin directory 385 # exists. 386 # @user_action 387 # Check that the correct pathname for the Samba sbin directory was 388 # entered when registering the Samba resource and that the sbin 389 # directory really exists. 390 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 391 "Validate - %s sbin directory %s does not exist" \ 392 "${COMPONENT}" "${SBINDIR}" 393 rc=1 394 else 395 debug_message "Validate - ${COMPONENT} sbin directory ${SBINDIR} exists" 396 fi 397 398 if [ ! -d "${CFGDIR}" ] 399 then 400 # SCMSGS 401 # @explanation 402 # The Samba resource could not validate that the Samba 403 # configuration directory exists. 404 # @user_action 405 # Check that the correct pathname for the Samba configuration 406 # directory was entered when registering the Samba resource and 407 # that the configuration directory really exists. 408 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 409 "Validate - %s configuration directory %s does not exist" \ 410 "${COMPONENT}" "${CFGDIR}" 411 rc=1 412 else 413 debug_message "Validate - ${COMPONENT} configuration directory ${CFGDIR} exists" 414 fi 415 416 if [ ! -f "${SMBCONF}" ] 417 then 418 # SCMSGS 419 # @explanation 420 # The smb.conf file does not exist. 421 # @user_action 422 # Check the correct pathname for the Samba smb.conf file was 423 # entered when registering the Samba resource and that the smb.conf 424 # file exists. 425 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 426 "Validate - smbconf %s does not exist" \ 427 "${SMBCONF}" 428 rc=1 429 else 430 debug_message "Validate - smbconf ${SMBCONF} exists" 431 fi 432 433 if [ ! -x "${NMBLOOKUP}" ] 434 then 435 # SCMSGS 436 # @explanation 437 # The Samba resource tries to validate that the nmblookup program 438 # exists and is executable. 439 # @user_action 440 # Check the correct pathname for the Samba bin directory was 441 # entered when registering the resource and that the program exists 442 # and is executable. 443 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 444 "Validate - nmblookup %s non-existent executable" \ 445 "${NMBLOOKUP}" 446 rc=1 447 else 448 debug_message "Validate - nmblookup ${NMBLOOKUP} exists and is executable" 449 fi 450 451 # Is 2.2.x being used 452 453 ${NMBLOOKUP} -h >/dev/null 2>&1 454 455 if [ $? -eq 0 ]; then 456 VERSION=`${NMBLOOKUP} -h | /usr/bin/grep 'Version ' | /usr/bin/awk '{print $2}'` 457 else 458 VERSION=`${NMBLOOKUP} -V | /usr/bin/awk '{print $2}'` 459 fi 460 461 SAMBA_VERSION=`/usr/bin/echo ${VERSION} | /usr/bin/cut -d'.' -f1` 462 SAMBA_RELEASE=`/usr/bin/echo ${VERSION} | /usr/bin/cut -d'.' -f2` 463 SAMBA_UPDATE=`/usr/bin/echo ${VERSION} | /usr/bin/cut -d'.' -f3` 464 465 debug_message "Validate - Samba version <${SAMBA_VERSION}.${SAMBA_RELEASE}.${SAMBA_UPDATE}> is being used" 466 467 # Strip off any non-digits 468 469 SAMBA_VERSION=`stripfunc ${SAMBA_VERSION}` 470 SAMBA_RELEASE=`stripfunc ${SAMBA_RELEASE}` 471 SAMBA_UPDATE=`stripfunc ${SAMBA_UPDATE}` 472 473 rc_validate_version=0 474 475 if [ -z "${VERSION}" ] 476 then 477 # SCMSGS 478 # @explanation 479 # The Samba resource tries to validate that an acceptable version 480 # of Samba is being deployed, however it was unable to retrieve the 481 # Samba version number. 482 # @user_action 483 # Check that Samba has been installed correctly 484 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 485 "Validate - Couldn't retrieve Samba version number" 486 rc=1 487 elif [ "${SAMBA_VERSION}" -lt 2 ]; then 488 rc_validate_version=1 489 elif [ "${SAMBA_VERSION}" -eq 2 -a "${SAMBA_RELEASE}" -le 2 -a "${SAMBA_UPDATE}" -lt 2 ]; then 490 rc_validate_version=1 491 fi 492 493 if [ "${rc_validate_version}" -gt 0 ] 494 then 495 # SCMSGS 496 # @explanation 497 # The Samba resource check to see that an appropriate version of 498 # Samba is being deployed. Versions below v2.2.2 will generate this 499 # message. 500 # @user_action 501 # Ensure that the Samba version is equal to or above v2.2.2 502 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 503 "Validate - This version of samba <%s> is not supported with this dataservice" \ 504 `/usr/bin/printf ${SAMBA_VERSION}.${SAMBA_RELEASE}.${SAMBA_UPDATE}` 505 rc=1 506 fi 507 508 debug_message "Function: validate_common - End" 509 return ${rc} 510 } 511 512 query_pids() 513 { 514 debug_message "Function: query_pids - Begin" 515 ${SET_DEBUG} 516 517 # Usage: query_pids "parm1" "parm2" 518 # 519 # If being run on Solaris 10, query_pids() matches the 520 # correct zonename, otherwise zones are ignored for 521 # pre-Solaris 10 systems. 522 523 rc=1 524 PROCESS=$1 525 PATTERN=$2 526 527 if [ -x /sbin/zonename ] 528 then 529 pids=`/usr/bin/ps -u root -o pid,args,zone | /usr/bin/grep " ${ZONENAME}$" | \ 530 /usr/bin/grep "${PROCESS} " | /usr/bin/grep ${PATTERN} | /usr/bin/awk '{print $1}'` 531 else 532 pids=`/usr/bin/ps -u root -o pid,args | \ 533 /usr/bin/grep "${PROCESS} " | /usr/bin/grep ${PATTERN} | /usr/bin/awk '{print $1}'` 534 fi 535 536 [ "${pids}" ] && rc=0 537 538 debug_message "Function: query_pids - End" 539 return ${rc} 540 } 541 542 check_start() 543 { 544 debug_message "Function: check_start - Begin" 545 ${SET_DEBUG} 546 547 # Allow "wait_for_online" to only test after the specified method 548 # for ${RESOURCE} has finished (Note additional winbind check) 549 # 550 # Here $1 is set when check_start is called from within control_samba, e.g. 551 # check_start "start_samba" or check_start "start_winbind" 552 553 component=$1 554 typeset component_running=0 555 556 if [ "${component}" = "start_samba" ] 557 then 558 if [ "${CALLER}" = "GDS" ] 559 then 560 /usr/bin/pgrep -u root -f "${component} .*-R ${RESOURCE} " >/dev/null 2>&1 561 [ "$?" -eq 0 ] && component_running=100 562 else 563 # Here we are being called by SMF where ${component} has already been broken down, 564 # i.e. The SMF start method uses "control_samba start samba ${RESOURCE}" and not 565 # start_samba which is being passed as $1, therefore we need to amend ${component}. 566 # 567 # Note, that ${RESOURCE}, when called by SMF, reflects the FMRI which when using a 568 # failover zone is the same as the Sun Cluster resource name. 569 570 component=`/usr/bin/echo ${component} | /usr/bin/tr "_" " "` 571 /usr/bin/pgrep -u root -f "${component} ${RESOURCE} " >/dev/null 2>&1 572 [ "$?" -eq 0 ] && component_running=100 573 fi 574 else 575 # Here Winbind maybe starting, however we need to make sure that after 576 # winbindd has been started that it is ready to process work. This can 577 # be delayed if caching is on and the winbind cache time is quite high. 578 # 579 # If getent passwd ${SAMBA_FMUSER} is successful then it's okay to let 580 # the winbind probe continue, otherwise if unsuccessful we need to check 581 # if gds_svc_start is still running. If it is then we return 100 which 582 # prevents the winbind probe from running. 583 # 584 # The call sequence is as follows: 585 # 586 # GDS -> /opt/SUNWscsmb/winbind/bin/probe_winbind 587 # | 588 # +-> ../../bin/control_samba 589 # | 590 # +-> probe winbind (case'd) 591 # ^ | 592 # | +-> check_start() 593 # | | 594 # | +-> 0 -> check_winbind() 595 # | +-> 100 | 596 # | | +-> 0|100 597 # | | | 598 # +---------------+---------------+ 599 600 # Note, Winbind's ${SAMBA_FMUSER}=${FMUSER}, see samba_register. 601 if [ "`/usr/bin/getent passwd ${SAMBA_FMUSER}`" ] 602 then 603 component_running=0 604 else 605 # Note, if gds_svc_start is not running component_running=0 is returned 606 /usr/bin/pgrep -u root -f "gds_svc_start .*-R ${RESOURCE} " >/dev/null 2>&1 607 [ "$?" -eq 0 ] && component_running=100 608 debug_message "check_start - getent passwd ${SAMBA_FMUSER} failed" 609 fi 610 fi 611 612 # control_samba() for the probe winbind will not run check_winbind() if this 613 # function returns 100. If 0 is returned then check_winbind() is run. 614 615 debug_message "Function: check_start - End" 616 return ${component_running} 617 } 618 619 start_samba() 620 { 621 debug_message "Function: start_samba - Begin" 622 ${SET_DEBUG} 623 624 # ${SERVICES} contains the Samba service to start, 625 # which is then evaluated to the value of SMBD or NMBD 626 627 SERVICES=`/usr/bin/echo ${SERVICES} | /usr/bin/tr "," " " | /usr/bin/tr -s '[:lower:]' '[:upper:]'` 628 629 for i in ${SERVICES} 630 do 631 eval \${$i} -D -s ${SMBCONF} -l ${SAMBA_LOGDIR} 632 rc=$? 633 634 i=`/usr/bin/echo ${i} | /usr/bin/tr -s '[:upper:]' '[:lower:]'` 635 636 if [ "${rc}" -eq 0 ] 637 then 638 639 debug_message "start_samba - ${i} started" 640 else 641 # SCMSGS 642 # @explanation 643 # The Samba resource could not start the Samba server nmbd 644 # process. 645 # @user_action 646 # The Samba resource will be restarted, however examine the 647 # other syslog messages occurring at the same time on the same 648 # node, to see if the cause of the problem can be identified. 649 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 650 "start_samba - Could not start Samba server %s %s daemon" \ 651 "${NETBIOSNAME}" "${i}" 652 rc_start_samba=1 653 fi 654 done 655 656 debug_message "Function: start_samba - End" 657 return ${rc_start_samba} 658 } 659 660 stop_samba() 661 { 662 debug_message "Function: stop_samba - Begin" 663 ${SET_DEBUG} 664 665 # ${SERVICES} contains the Samba service to stop, 666 # which is the used to evaluate the correct SMBDLOCKF or NMBDLOCKF. 667 # TERM is then sent to the pid within ${LOCKF}, otherwise TERM is 668 # sent to the pids obtained from query_pids. 669 670 SERVICES=`/usr/bin/echo ${SERVICES} | /usr/bin/tr "," " " | /usr/bin/tr -s '[:lower:]' '[:upper:]'` 671 672 for i in ${SERVICES} 673 do 674 LOCKF=LOCKF 675 eval LOCKF=\$$i${LOCKF} 676 677 if [ -f "${LOCKF}" ] 678 then 679 pid=`/usr/bin/cat ${LOCKF}` 680 /usr/bin/kill -TERM ${pid} 2>/dev/null 681 /usr/bin/rm -f ${LOCKF} 682 fi 683 684 process=`/usr/bin/echo ${i} | /usr/bin/tr -s '[:upper:]' '[:lower:]'` 685 686 query_pids ${process} ${SMBCONF} 687 rc=$? 688 [ "${rc}" -eq 0 ] && /usr/bin/kill -TERM ${pids} 2>/dev/null 689 done 690 691 debug_message "Function: stop_samba - End" 692 return 0 693 } 694 695 start_winbind() 696 { 697 debug_message "Function: start_winbind - Begin" 698 ${SET_DEBUG} 699 700 # Wait X seconds to prevent file problems when starting 701 # winbindd with an empty database in scalable mode 702 703 /usr/bin/sleep ${STARTWAIT} 704 705 if [ -z "${WINBIND_DISCACHE}" ]; then 706 WINBIND_DISCACHE="" 707 fi 708 709 if [ -z "${WINBIND_SINGLEMODE}" ]; then 710 WINBIND_SINGLEMODE="" 711 fi 712 713 # Running scalable winbind across non-global zones with the same netbios name causes winbind problems 714 # when retrieving users and groups. To minimize this a scalable winbind resource can set the following 715 # parameter within the smb.conf file. 716 # 717 # netbios name = winbind.%$(CLINFO).%h 718 # 719 # which provides each global and non-global zone to have a unique netbios name, so long as CLINFO 720 # is available when winbind is started. Note that NODEID_LOCAL is defined at the start of this file. 721 # 722 # Finally, even though winbind starts it may still occasionally fail to lookup a user, although having 723 # a unique netbois name usually solves the issue, also setting START_TIMEOUT=60 allows the probe to 724 # to restart winbind after a reasonbale timeout. 725 726 env CLINFO=${NODEID_LOCAL} ${WINBINDD} -s ${SMBCONF} ${WINBIND_DISCACHE} ${WINBIND_SINGLEMODE} 727 rc=$? 728 729 if [ "${rc}" -eq 0 ] 730 then 731 debug_message "start_winbind - winbind started" 732 else 733 # SCMSGS 734 # @explanation 735 # The Winbind could not be started. 736 # @user_action 737 # No user action is needed. The Winbind server will be restarted. 738 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 739 "start_winbind - Could not start winbind" 740 fi 741 742 debug_message "Function: start_winbind - End" 743 return ${rc} 744 } 745 746 stop_winbind() 747 { 748 debug_message "Function: stop_winbind - Begin" 749 ${SET_DEBUG} 750 751 # TERM is then sent to the pid within ${WINBINDLOCKF}, otherwise 752 # TERM is sent to the pids obtained from query_pids. 753 754 if [ -f "${WINBINDLOCKF}" ] 755 then 756 pid=`/usr/bin/cat ${WINBINDLOCKF}` 757 758 debug_message "stop_winbind - winbindd lockfile found send TERM to ${pid} and remove lockfile" 759 760 /usr/bin/kill -TERM ${pid} 761 /usr/bin/rm -f ${WINBINDLOCKF} 762 else 763 debug_message "stop_winbind - winbindd lockfile not found send TERM to winbindd" 764 765 query_pids winbindd ${SMBCONF} 766 rc=$? 767 [ "${rc}" -eq 0 ] && /bin/kill -TERM ${pids} 2>/dev/null 768 fi 769 770 debug_message "Function: stop_winbind - End" 771 return 0 772 } 773 774 check_samba() 775 { 776 debug_message "Function: check_samba - Begin" 777 ${SET_DEBUG} 778 779 # ${SERVICES} contains the Samba service to check 780 781 SERVICES=`/usr/bin/echo ${SERVICES} | /usr/bin/tr "," " " | /usr/bin/tr -s '[:upper:]' '[:lower:]'` 782 rc=0 783 784 for i in ${SERVICES} 785 do 786 check_${i} 787 rc=$? 788 [ ${rc} -ne 0 ] && return 100 789 done 790 791 debug_message "Function: check_samba - End" 792 return ${rc} 793 } 794 795 check_nmbd() 796 { 797 debug_message "Function: check_nmbd - Begin" 798 ${SET_DEBUG} 799 800 rc=0 801 802 if [ "${RUN_NMBD}" = "YES" ] 803 then 804 for lh in ${LHOST} 805 do 806 ${NMBLOOKUP} -s ${SMBCONF} -U ${lh} ${NETBIOSNAME} | \ 807 /usr/xpg4/bin/grep -i -e ERR -e FAIL > ${TMPF} 808 809 if [ -s "${TMPF}" ] 810 then 811 # SCMSGS 812 # @explanation 813 # nmblookup could not be performed. 814 # @user_action 815 # No user action is needed. The Samba server will be 816 # restarted. 817 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 818 "check_nmbd - Nmbd for <%s> is not working, failed to retrieve ipnumber for %s" \ 819 "${NETBIOSNAME}" "${NETBIOSNAME}" 820 rc=1 821 else 822 debug_message "check_nmbd - nmblookup for ${lh} is working" 823 fi 824 done 825 fi 826 827 debug_message "Function: check_nmbd - End" 828 return ${rc} 829 } 830 831 check_smbd() 832 { 833 debug_message "Function: check_smbd - Begin" 834 ${SET_DEBUG} 835 836 rc=0 837 838 # Ask name service if the fault monitor user can be retrieved 839 # Note, Samba can have ${SAMBA_FMUSER}=${FMUSER}%${FMPASS} or 840 # ${SAMBA_FMUSER}=${SAMBA_DOMAIN}'\\\\'${FMUSER}%${FMPASS}, see 841 # samba_register. 842 843 USER=$(/usr/bin/echo ${SAMBA_FMUSER} | /usr/bin/awk 'BEGIN { FS="\\" } {print $NF}' | /usr/bin/cut -d'%' -f1) 844 845 if [ -z "`/usr/bin/getent passwd ${USER}`" ] 846 then 847 # SCMSGS 848 # @explanation 849 # The Samba resource could not validate that the fault monitor 850 # userid exists. 851 # @user_action 852 # Check that the correct fault monitor userid was used when 853 # registering the Samba resource and that the userid really exists. 854 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 855 "check_smbd - Couldn't retrieve faultmonitor-user <%s> from the nameservice" \ 856 "${USER}" 857 return 1 858 fi 859 860 # If smbclient can't connect, there could be network/server issues causing smbclient to fail. 861 # These errors maybe transient and correctable within a few seconds. Therefore before calling 862 # an error (which would result in a restart), we will retry the smbclient request within 85% 863 # of the available Probe_timeout less 15 seconds, which is approximately the timeout for the 864 # first smbclient failure. 865 # 866 # However, doing this is only realistic if Probe_timeout=30 seconds or more. If Probe_timeout 867 # is below 30 seconds then we'll just try smbclient once, which was the previous behaviour. 868 869 if [ "${PROBE_TIMEOUT}" -ge 30 ] 870 then 871 MAX_PROBE_TIMEOUT=`/usr/bin/expr \( ${PROBE_TIMEOUT} \* 85 \/ 100 \) \- 15 ` 872 else 873 MAX_PROBE_TIMEOUT=2 874 fi 875 876 while [ "${MAX_PROBE_TIMEOUT}" -ge 2 ] 877 do 878 if [ "$CALLER" = "GDS" ] 879 then 880 ${SMBCLIENT} '\\'${NETBIOSNAME}'\'${SAMBA_FMRESOURCE} -s ${SMBCONF} -U `/usr/bin/echo ${SAMBA_FMUSER}` \ 881 -c 'pwd;exit' 2>/dev/null | /usr/xpg4/bin/grep -i -e ERR -e FAIL > ${TMPF} 882 else 883 ${SMBCLIENT} '//'${NETBIOSNAME}'/'${SAMBA_FMRESOURCE} -s ${SMBCONF} -U `/usr/bin/echo ${SAMBA_FMUSER}` \ 884 -c 'pwd;exit' 2>/dev/null | /usr/xpg4/bin/grep -i -e ERR -e FAIL > ${TMPF} 885 fi 886 887 if [ -s "${TMPF}" ] 888 then 889 # SCMSGS 890 # @explanation 891 # The Samba resource's fault monitor checks that the Samba 892 # server is working by using the smbclient program. However 893 # this test failed to connect to the Samba server. 894 # @user_action 895 # No user action is needed. The Samba server will be 896 # restarted. However, examine the other syslog messages 897 # occurring at the same time on the same node, to see if the 898 # cause of the problem can be identified. 899 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 900 "check_smbd - Samba server <%s> not working, failed to connect to samba-resource <%s>" \ 901 "${NETBIOSNAME}" "${SAMBA_FMRESOURCE}" 902 rc=1 903 MAX_PROBE_TIMEOUT=`expr ${MAX_PROBE_TIMEOUT} - 2` 904 sleep 1 905 else 906 rc=0 907 MAX_PROBE_TIMEOUT=0 908 debug_message "check_smbd - Samba is working" 909 fi 910 done 911 912 debug_message "Function: check_smbd - End" 913 return ${rc} 914 } 915 916 check_winbind() 917 { 918 debug_message "Function: check_winbind - Begin" 919 ${SET_DEBUG} 920 921 # Ask name service if the fault monitor user can be retrieved 922 # Note, Winbind's ${SAMBA_FMUSER}=${FMUSER}, see samba_register. 923 924 if [ -z "`/usr/bin/getent passwd ${SAMBA_FMUSER}`" ] 925 then 926 # SCMSGS 927 # @explanation 928 # The Winbind userid cannot be retrieved. 929 # @user_action 930 # No user action is needed. The Samba server will be restarted. 931 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 932 "check_winbind - User <%s> can't be retrieved by the nameservice" \ 933 "${SAMBA_FMUSER}" 934 rc=100 935 else 936 debug_message "check_winbind - Winbind is working" 937 rc=0 938 fi 939 940 debug_message "Function: check_winbind - End" 941 return ${rc} 942 } 943