xref: /titanic_50/usr/src/cmd/ypcmd/yp.sh (revision 88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98)
1#!/bin/sh
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, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#
24# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27# ident	"%Z%%M%	%I%	%E% SMI"
28
29. /lib/svc/share/smf_include.sh
30
31YPDIR=/usr/lib/netsvc/yp
32
33case $SMF_FMRI in
34	'svc:/network/nis/client:default')
35		domain=`domainname`
36
37		if [ -z "$domain" ]; then
38			echo "$0: domainname not set"
39			exit $SMF_EXIT_ERR_CONFIG
40		fi
41
42		if [ ! -d /var/yp/binding/$domain ]; then
43			echo "$0: /var/yp/binding/$domain is not a directory"
44			exit $SMF_EXIT_ERR_CONFIG
45		fi
46
47		# Since two ypbinds will cause ypwhich to hang...
48		if pgrep -z `/sbin/zonename` ypbind >/dev/null; then
49			echo "$0: ypbind is already running."
50			exit $SMF_EXIT_ERR_CONFIG
51		fi
52
53		if [ -f /var/yp/binding/$domain/ypservers ]; then
54			$YPDIR/ypbind > /dev/null 2>&1
55		else
56			$YPDIR/ypbind -broadcast > /dev/null 2>&1
57		fi
58
59		rc=$?
60		if [ $rc != 0 ]; then
61			echo "$0: ypbind failed with $rc"
62			exit 1
63		fi
64		;;
65
66	'svc:/network/nis/server:default')
67		domain=`domainname`
68
69		if [ -z "$domain" ]; then
70			echo "$0: domainname not set"
71			exit $SMF_EXIT_ERR_CONFIG
72		fi
73
74		if [ ! -d /var/yp/$domain ]; then
75			echo "$0: domain directory missing"
76			exit $SMF_EXIT_ERR_CONFIG
77		fi
78
79		if [ -f /etc/resolv.conf ]; then
80			$YPDIR/ypserv -d
81		else
82			$YPDIR/ypserv
83		fi
84
85		rc=$?
86		if [ $rc != 0 ]; then
87			echo "$0: ypserv failed with $rc"
88			exit 1
89		fi
90		;;
91
92	'svc:/network/nis/passwd:default')
93		PWDIR=`grep "^PWDIR" /var/yp/Makefile 2> /dev/null` \
94		    && PWDIR=`expr "$PWDIR" : '.*=[ 	]*\([^ 	]*\)'`
95		if [ "$PWDIR" ]; then
96			if [ "$PWDIR" = "/etc" ]; then
97				unset PWDIR
98			else
99				PWDIR="-D $PWDIR"
100			fi
101		fi
102		$YPDIR/rpc.yppasswdd $PWDIR -m
103
104		rc=$?
105		if [ $rc != 0 ]; then
106			echo "$0: rpc.yppasswdd failed with $rc"
107			exit 1
108		fi
109		;;
110
111	*)
112		echo "$0: Unknown service \"$SMF_FMRI\"."
113		exit $SMF_EXIT_ERR_CONFIG
114		;;
115esac
116exit $SMF_EXIT_OK
117