#!/usr/sbin/sh # # Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. # . /lib/svc/share/smf_include.sh . /lib/svc/share/ipf_include.sh # Routine to generate IPfilter rules for SMB server create_ipf_rules() { FMRI=$1 file=`fmri_to_file $FMRI $IPF_SUFFIX` ip=any policy=`get_policy ${FMRI}` iana_names="microsoft-ds netbios-ns netbios-dgm netbios-ssn" # # Enforce policy on each port # echo "# $FMRI" >$file for name in $iana_names; do port=`$SERVINFO -p -s $name 2>/dev/null` if [ -z "$port" ]; then continue; fi generate_rules $FMRI $policy "tcp" $ip $port $file generate_rules $FMRI $policy "udp" $ip $port $file done } # Routine to handle errors on SQLite database migration. die() { echo "$0: $1 Migration to SQLite3 database failed." >&2 if [ -n "$2" ]; then echo "$2" >&2 fi exit $SMF_EXIT_ERR_FATAL } # Routine to migrate SQLite2 database to SQLite3 database. migrate_to_sqlite3_db() { SQLITE2_DB=${1}.db NEW_DB_NAME=${1}_v3.db SQLITE2_CMD=/lib/svc/bin/sqlite SQLITE3_CMD=/usr/bin/sqlite3 # Verify the presence of SQLite3 database file. if [ -f $NEW_DB_NAME ]; then return; fi if [ -f $SQLITE2_DB ]; then # Verify the presence of SQLite2 command. if [ ! -f $SQLITE2_CMD ]; then die "$SQLITE2_CMD not found." fi # Verify the presence of SQLite3 command. if [ ! -f $SQLITE3_CMD ]; then die "$0: $SQLITE3_CMD not found." fi # Integrity check of SQLite2 database. Integrity check also # verifies the version of SQLite2 database file. chkresults=`$SQLITE2_CMD $SQLITE2_DB 'PRAGMA integrity_check' \ 2>&1 >/dev/null` if [ $? != 0 ]; then die "$SQLITE2_DB: integrity check failed." "$chkresults" fi # Verify dump of SQLite2 database. dumpmsg=`$SQLITE2_CMD $SQLITE2_DB .dump 2>&1 >/dev/null` rc=$? if [ $rc != 0 ]; then die "SQLite2 database dump failed($rc)." "$dumpmsg" fi # Migrate to SQLite3 database $SQLITE2_CMD $SQLITE2_DB .dump | $SQLITE3_CMD $NEW_DB_NAME if [ $? != 0 ]; then die "SQLite3 database creation failed($rc)." fi fi } case "$1" in 'start') LGRP_DB_NAME=/var/smb/smbgroup NIC_DB_NAME=/var/smb/smbhosts migrate_to_sqlite3_db $LGRP_DB_NAME migrate_to_sqlite3_db $NIC_DB_NAME exec /usr/lib/smbd ;; 'ipfilter') create_ipf_rules $2 ;; *) echo "Usage: $0 { start }" exit 1 ;; esac exit 0