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