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.
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.
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]
22 # Copyright 2014 Nexenta Systems, Inc. All rights reserved.
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
27 # Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
30 # Portions of this source code were derived from Berkeley 4.3 BSD
31 # under license from the Regents of the University of California.
34 YPXFR
=/usr
/lib
/netsvc
/yp
/ypxfr
36 maps
="publickey publickey.byname"
38 yproot_exe
=/usr
/sbin
/yp
39 hf
=/var
/run
/ypservers.$$
43 hosts6_file
=/etc
/inet
/ipnodes
57 /usr
/sbin
/svcadm disable
-t $1
58 [ $?
= 0 ] ||
echo "ypinit: unable to temporarily disable $1"
59 /usr
/sbin
/svccfg
-s $1 \
60 setprop general
/enabled
= true
61 [ $?
= 0 ] ||
echo "ypinit: unable to enable $1 for next boot"
65 /usr
/sbin
/svcadm
enable $1
66 [ $?
= 0 ] ||
echo "ypinit: unable to enable $1"
70 test -n "`echo $1 | awk 'NF != 1 {exit} \
71 $1 !~ /[0-9]/ || /[;-~]/ || /!--/ || /\// {exit} \
72 $1 !~ /\./ {exit} {print}'`" || \
73 test -n "`echo $1 | awk 'NF != 1 {exit} \
74 ($1 !~ /[0-9]/ && $1 !~ /[A-F]/ && \
76 /[;-@]/ || /[G-\`]/ || /[g-~]/ || /!--/ || \
78 $1 !~ /:/ {exit} {print}'`"
81 PATH
=/bin
:/usr
/bin
:/usr
/etc
:/usr
/sbin
:$yproot_exe:$MAKEPATH:$PATH
85 trap '/usr/bin/rm -f $hf' 0 1 2 3 15
87 # Check out total number of arguments
93 echo ' ypinit -c [server_name...]'
95 echo ' ypinit -s master_server'
98 where -c is used to set up a yp client, -m is used to build a master "
100 yp server data base, and -s is used for a slave data base."
102 master_server must be an existing reachable yp server."
107 -s) slavep
=T
; master
=$2;
108 if ( grep $master $hosts_file $hosts6_file > /dev
/null
)
112 echo "server not found in $hosts_file or $hosts6_file"
116 # the case with more than one argument with the '-c' option
117 # is a subject to enter non-interactive mode
118 -c) clientp
=T
; non_interactive
=T
;
121 echo ' ypinit -c [server_name...]'
123 echo ' ypinit -s master_server'
126 where -c is used to set up a yp client, -m is used to build a master "
128 yp server data base, and -s is used for a slave data base."
130 master_server must be an existing reachable yp server."
135 # the case with more than one argument with the '-c' option
136 # is a subject to enter non-interactive mode
137 -c) clientp
=T
; non_interactive
=T
;
140 echo ' ypinit -c [server_name...]'
142 echo ' ypinit -s master_server'
145 where -c is used to set up a yp client, -m is used to build a master "
147 yp server data base, and -s is used for a slave data base."
149 master_server must be an existing reachable yp server."
157 \aYou have to be the superuser to run this. Please log in as root."
165 echo "\aCan't get local host's name. Please check your path."
171 echo "\aThe local host's name hasn't been set. Please set it."
179 echo "\aCan't get local host's domain name. Please check your path."
185 echo "\aThe local host's domain name hasn't been set. Please set it."
190 real_def_dom
=$def_dom
191 #def_dom=`ypalias -d $def_dom`
192 ypservers_map
=`ypalias ypservers`
193 domain_dir
="$yproot_dir""/""$def_dom"
194 binding_dir
="$yproot_dir""/binding/""$def_dom"
195 binding_file
="$yproot_dir""/binding/""$def_dom""/ypservers"
197 if [ ! -d $yproot_dir -o -f $yproot_dir ]
200 \aThe directory $yproot_dir doesn't exist. Restore it from the distribution."
204 # add domainname and ypservers aliases to aliases file
205 echo ypservers
$ypservers_map >> $yproot_dir/aliases
206 echo $real_def_dom $def_dom >> $yproot_dir/aliases
207 sort $yproot_dir/aliases |
uniq > /var
/run
/.ypaliases
; mv /var
/run
/.ypaliases
$yproot_dir/aliases
209 if [ ! -d "$yproot_dir"/binding
]
211 mkdir
"$yproot_dir"/binding
214 if [ ! -d $binding_dir ]
221 if [ $non_interactive = F
]
223 while [ $got_host_list = F
]; do
224 touch $hf # make sure file exists
227 In order for NIS to operate sucessfully, we have to construct a list of the "
229 NIS servers. Please continue to add the names for YP servers in order of"
231 preference, one per line. When you are done with the list, type a <control D>"
233 or a return on a line by itself."
237 echo "\tnext host to add: $host"
238 elif [ -f $binding_file ]
240 if [ $first_time = T
]
242 for h
in `cat $binding_file`
245 echo "\tnext host to add: $h"
250 echo "\tnext host to add: \c"
252 while read h
; test -n "$h"
255 # Host should be in the v4 or v6 hosts file or
256 # reasonably resemble an IP address. We'll do a
257 # sanity check that a v4 addr is one word consisting
258 # of only numbers and the "." character,
259 # which should guard against fully qualified
260 # hostnames and most malformed entries. IPv6
261 # addresses can be numbers, hex letters, and have
262 # at least one ":" character and possibly one or
263 # more "." characters for embedded v4 addresses
265 if ( grep $h $hosts_file $hosts6_file > /dev
/null
) || \
266 ( test $clientp = T
&& `is_valid_ipaddr $h` )
269 echo "\tnext host to add: \c"
271 echo "host $h not found in $hosts_file or" \
272 "$hosts6_file.\nNot added to the list."
274 echo "Do you wish to abort [y/n: y] \c"
278 n
*) echo "\tnext host to add: \c";;
279 N
*) echo "\tnext host to add: \c";;
288 echo "The current list of yp servers looks like this:"
292 echo "Is this correct? [y/n: y] \c"
294 echo "You have not added any server information."
296 echo "Do you still wish to exit? [y/n: y] \c"
305 echo "Let's try the whole thing again...";;
309 echo "Let's try the whole thing again...";;
316 while [[ $# > 0 ]]; do
317 if ( grep $1 $hosts_file $hosts6_file > /dev
/null
) || \
318 ( `is_valid_ipaddr $1` )
322 echo "host $1 not found in $hosts_file or" \
323 "$hosts6_file.\nNot added to the list."
337 # Start client service on next boot, unless we're establishing a slave
338 # server, in which case the binding is needed now (or should be
343 enable_this_boot network
/nis
/client
:default
345 enable_next_boot network
/nis
/client
:default
349 # As a client, our configuration is correct once a binding file is
350 # established, and so we can exit (making sure we're no longer a server,
356 /usr
/sbin
/svcadm disable network
/nis
/server
:default
357 /usr
/sbin
/svcadm disable network
/nis
/xfr
:default
358 /usr
/sbin
/svcadm disable network
/nis
/passwd
:default
359 /usr
/sbin
/svcadm disable network
/nis
/update
:default
365 if [ $host = $master ]
368 \aThe host specified should be a running master yp server, not this machine."
372 maps
=`ypwhich -m | egrep $master$| awk '{ printf("%s ",$1) }' -`
375 echo "\aCan't enumerate maps from $master. Please check that it is running."
382 echo "Installing the YP database will require that you answer a few questions."
383 echo "Questions will all be asked at the beginning of the procedure."
385 echo "Do you want this procedure to quit on non-fatal errors? [y/n: n] \c"
389 y
*) exit_on_error
=T
;;
390 Y
*) exit_on_error
=T
;;
392 OK, please remember to go back and redo manually whatever fails. If you"
394 don't, some part of the system (perhaps the yp itself) won't work.";;
397 echo "The yp domain directory is $yproot_dir""/""$def_dom"
399 for dir
in $yproot_dir/$def_dom
403 echo "Can we destroy the existing $dir and its contents? [y/n: n] \c"
406 case $kill_old_dir in
411 echo "\aCan't clean up old directory $dir. Fatal error."
419 echo "\aCan't clean up old directory $dir. Fatal error."
423 *) echo "OK, please clean it up by hand and start again. Bye"
432 echo "\aCan't make new directory $dir. Fatal error."
441 There will be no further questions. The remainder of the procedure should take"
442 echo "a few minutes, to copy the data bases from $master."
444 for dom
in $real_def_dom
448 echo "Transferring $map..."
449 $XFR -h $master -c -d $dom $map
455 if [ $exit_on_error = T
]
464 echo "${host}'s nis data base has been set up\n"
466 if [ $errors_in_setup = T
]
468 echo " with errors. Please remember"
469 echo "to figure out what went wrong, and fix it."
471 echo " without any errors."
474 # enable slave services
475 enable_this_boot network
/nis
/server
:default
477 enable_this_boot network
/nis
/client
:default
482 rm -f $yproot_dir/*.
time
485 There will be no further questions. The remainder of the procedure should take"
486 echo "5 to 10 minutes."
488 echo "Building $yproot_dir/$def_dom/ypservers..."
489 makedbm
$hf $yproot_dir/$def_dom/$ypservers_map
494 \aCouldn't build yp data base $yproot_dir/$def_dom/$ypservers_map."
497 if [ $exit_on_error = T
]
508 echo $yproot_dir "\c"
515 \aError running Makefile."
518 if [ $exit_on_error = T
]
527 $host has been set up as a yp master server\c"
529 if [ $errors_in_setup = T
]
531 echo " with errors. Please remember"
532 echo "to figure out what went wrong, and fix it."
534 echo " without any errors."
539 If there are running slave yp servers, run yppush now for any data bases"
541 which have been changed. If there are no running slaves, run ypinit on"
543 those hosts which are to be slave servers."
545 # enable master services
546 enable_this_boot network
/nis
/server
:default
547 enable_this_boot network
/nis
/xfr
:default
548 enable_this_boot network
/nis
/passwd
:default
549 enable_this_boot network
/nis
/update
:default
551 enable_this_boot network
/nis
/client
:default