| Current File : //etc/fs/nfs/fedfs_include.sh |
#!/bin/ksh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
#
#
set -o pipefail
LDAPSEARCH='/bin/openldapsearch -x'
#
# Usage: enumerate_ncs nsdb port
# Enumerates naming contexts (DITs) in an LDAP server
#
enumerate_ncs() {
$LDAPSEARCH -h $1 -p $2 -b "" -s base objectClass=\* namingContexts | \
grep namingContexts: | \
sed -e 's/namingContexts: //'
if [ $? != 0 ]; then
exit 1
fi
}
#
# Usage: enumerate_nces nsdb port
# Enumerates NSDB container entries (NCEs) in an LDAP server
#
enumerate_nces() {
enumerate_ncs $1 $2 | while read nc; do
pq=`$LDAPSEARCH -h $1 -p $2 -b $nc \
objectClass=fedfsNsdbContainerInfo fedfsNcePrefix | \
grep fedfsNcePrefix:`
if [ $? != 0 ]; then
exit 1
fi
if [ "$pq" != "" ]; then
prefix=`echo $pq | sed -e 's/fedfsNcePrefix://'`
if [ "$prefix" == "" ]; then
nce=$nc
else
nce=$prefix,$nc
fi
echo $nce
fi
done
}
#
# Usage: enumerate_fsns nsdb port nce
# Enumerates fileset names (FSNs) in an NSDB container entry
#
enumerate_fsns() {
$LDAPSEARCH -h $1 -p $2 -b $3 -LLL objectClass=fedfsfsn | \
grep -i fedfsFsnUuid: | \
sed -e 's/fedfsFsnUuid://'
if [ $? != 0 ]; then
exit 1
fi
}
#
# Usage: fsn_to_fsls nsdb port nce fsn
# Enumerates fileset locations (FSLs) for a fileset name
#
fsn_to_fsls() {
$LDAPSEARCH -h $1 -p $2 -b $3 "fedfsFsnUuid=$4" fedfsfsluuid | \
grep -i fedfsfsluuid: | \
sed -e 's/.*: //'
if [ $? != 0 ]; then
exit 1
fi
}
#
# Usage: fsl_to_path nsdb port nce fsl
# Returns the host:/path information for an FSL
#
fsl_to_path() {
$LDAPSEARCH -t -h $1 -p $2 -b $3 \
"fedfsFslUuid=$4" fedfsfslHost fedfsNfsPath > /tmp/pfile$$
if [ $? != 0 ]; then
rm -f /tmp/pfile$$
exit 1
fi
nhost=`grep -i fedfsFslHost: /tmp/pfile$$ | sed -e 's/fedfsFslHost: //'`
pfile=`grep -i fedfsNfsPath: /tmp/pfile$$ | sed -e 's?.*file://??'`
npath=`xdr2path $pfile`
rm -f /tmp/pfile$$
echo "$nhost:$npath"
}
#
# Set initial defaults
#
nsdb=localhost
port=389
#
# Get system-wide defaults, if set
#
nsdb2=`svcprop -p default/hostname fedfs-client`
if [ "$nsdb2" != "" ]; then
nsdb=$nsdb2
fi
port2=`svcprop -p default/port fedfs-client`
if [ "$port2" != "" ]; then
port=$port2
fi
#
# Load vars from the environment
#
if [ "$FEDFS_NSDB_HOST" != "" ]; then
nsdb=$FEDFS_NSDB_HOST
fi
if [ "$FEDFS_NSDB_PORT" != "" ]; then
port=$FEDFS_NSDB_PORT
fi
if [ "$FEDFS_NSDB_NCE" != "" ]; then
nce=$FEDFS_NSDB_NCE
fi
if [ "$FEDFS_NSDB_ADMIN" != "" ]; then
admin=$FEDFS_NSDB_ADMIN
fi