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 (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22 #
23 # Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
25 #
26 # Enable appropriate NIS daemons based on the current configuration.
27
28 enable () {
29 /usr/sbin/svcadm enable -t $1
30 [ $? = 0 ] || echo "ypstart: unable to enable $1"
31
32 if [ "`/usr/bin/svcprop -p restarter/state $1`" = "maintenance" ]; then
33 echo "ypstart: unable to enable $1; in maintenance"
34 fi
35 }
36
37
38 domain=`domainname`
39 if [ -z "$domain" ]; then
40 echo "ERROR: Default domain is not defined. \c"
41 echo "Use \"domainname\" to set the domain."
42 exit 1
43 fi
44
45 echo "starting NIS (YP server) services:\c"
46
47 zone=`/sbin/zonename`
48
49 if [ -d /var/yp/$domain ]; then
50 state=`/usr/bin/svcprop -p restarter/state network/nis/server:default`
51
52 [ "$state" = "disabled" ] && if [ -n "`pgrep -z $zone ypserv`" ]; then
53 echo "ypstart: ypserv already running?"
54 fi
55
56 enable svc:/network/nis/server:default && echo " ypserv\c"
57
58 YP_SERVER=TRUE # remember we're a server for later
59
60 # check to see if we are the master
61 if [ -f /var/yp/NISLDAPmapping ]; then
62 passwdfile=/var/yp/$domain/LDAP_passwd.byname
63 else
64 passwdfile=/var/yp/$domain/passwd.byname
65 fi
66 master=`/usr/sbin/makedbm -u $passwdfile | grep YP_MASTER_NAME \
67 | /usr/xpg4/bin/awk '{ print tolower($2) }'`
68 fi
69
70 # Enabling the YP client is not strictly necessary, but it is
71 # traditional.
72 state=`/usr/bin/svcprop -p restarter/state network/nis/client:default`
73
74 [ "$state" = "disabled" ] && if [ -n "`pgrep -z $zone ypbind`" ]; then
75 echo "ypstart: ypbind already running?"
76 fi
77
78 enable svc:/network/nis/client:default && echo " ypbind\c"
79
80 # do a ypwhich to force ypbind to get bound
81 ypwhich > /dev/null 2>&1
82
83 if [ "$YP_SERVER" = TRUE ]; then
84 # Are we the master server? If so, start the
85 # ypxfrd, rpc.yppasswdd and rpc.ypupdated daemons.
86 hostname=`uname -n | tr '[A-Z]' '[a-z]'`
87
88 if [ "$master" = "$hostname" ]; then
89 enable svc:/network/nis/xfr:default && echo " ypxfrd\c"
90 enable svc:/network/nis/passwd:default &&
91 echo " rpc.yppasswdd\c"
92
93 if [ ! -f /var/yp/NISLDAPmapping -a -f /var/yp/updaters ]; then
94 enable svc:/network/nis/update:default &&
95 echo " rpc.ypupdated\c"
96 fi
97 fi
98 fi
99
100 # As this operation is likely configuration changing, restart the
101 # name-services milestone (such that configuration-sensitive services
102 # are in turn restarted).
103 /usr/sbin/svcadm restart milestone/name-services
104
105 echo " done."