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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23 # Copyright 2014 Garrett D'Amore
27 # This script provides a simple GUI for managing labeled zones.
28 # It provides contextual menus which provide appropriate choices.
29 # It must be run in the global zone as root.
31 # These arguments are accepted, and will result in non-interactive
34 # txzonemgr [-c | -d[f]]
36 # -c create default zones
37 # -d destroy all zones; prompts for confirmation unless
38 # the -f flag is also specified
42 # DISP - use GUI (otherwise use non-interactive mode)
44 # CREATEDEF - make default zones (non-interactive)
46 # DESTROYZONES - tear down all zones (non-interactive)
52 NSCD_INDICATOR
=/var
/tsol
/doors
/nscd_per_label
53 if [ -f $NSCD_INDICATOR ] ; then
60 TNRHTP
=/etc
/security
/tsol
/tnrhtp
61 TNRHDB
=/etc
/security
/tsol
/tnrhdb
62 TNZONECFG
=/etc
/security
/tsol
/tnzonecfg
66 PATH
=/usr
/bin
:/usr
/sbin
:/usr
/lib
export PATH
67 title
="Labeled Zone Manager 2.1"
69 msg_defzones
=$
(gettext "Create default zones using default settings?")
70 msg_confirmkill
=$
(gettext "OK to destroy all zones?")
71 msg_continue
=$
(gettext "(exit to resume $(basename $0) when ready)")
72 msg_getlabel
=$
(gettext "Select a label for the")
73 msg_getremote
=$
(gettext "Select a remote host or network from the list below:")
74 msg_getnet
=$
(gettext "Select a network configuration for the")
75 msg_getzone
=$
(gettext "Select a zone from the list below:
76 (select global for zone creation and shared settings)")
77 msg_getcmd
=$
(gettext "Select a command from the list below:")
78 msg_inuse
=$
(gettext "That label is already assigned\nto the")
79 msg_getmin
=$
(gettext "Select the minimum network label for the")
80 msg_getmax
=$
(gettext "Select the maximum network label for the")
81 msg_badip
=$
(gettext " is not a valid IP address")
90 while getopts ":$optlist" opt
101 *) gettext "invalid option -$OPTARG\n"
108 if [ $CREATEDEF -eq 1 -a $DESTROYZONES -eq 1 ] ; then
109 gettext "cannot combine options -c and -d\n"
113 if [ $CREATEDEF -eq 1 -a $FORCE -eq 1 ] ; then
114 gettext "option -f not allowed with -c\n"
118 if [ $FORCE -eq 1 -a $CREATEDEF -eq 0 -a $DESTROYZONES -eq 0 ] ; then
119 gettext "option -f specified without any other options\n"
124 shift $
((OPTIND
- 1))
125 if [ "x$1" != "x" ] ; then
134 gettext "usage: $myname [-c | -d[f]]\n"
138 if [ $zonename != global
] ; then
139 zconsole
=$
(pgrep
-f "zlogin -C $zonename")
140 if [ $?
!= 0 ] ; then
141 console
="Zone Console...\n"
147 hexlabel
=$
(grep "^$zonename:" $TNZONECFG|cut
-d : -f2);
148 if [[ $hexlabel ]] ; then
150 if [ $zonename = global
] ; then
152 addcipsohost
="Add Multilevel Access to Remote Host...\n"
153 removecipsohost
="Remove Multilevel Access to Remote Host...\n"
154 setmlps
="Configure Multilevel Ports...\n"
156 template
=${zonename}_unlab
161 net
=$
(zonecfg
-z $zonename info net
)
162 if [[ -n $net ]] ; then
163 setmlps
="Configure Multilevel Ports...\n"
164 elif [ $zonestate = configured
] ; then
165 addnet
="Configure Network Interfaces...\n"
168 addremotehost
="Add Single-level Access to Remote Host...\n"
169 remotes
=$
(grep -v "^#" $TNRHDB|
grep $template)
171 removeremotehost
="Remove Single-level Access to Remote Host...\n"
176 label
="Select Label...\n"
188 for p
in $
(zoneadm list
-ip) ; do
189 z
=$
(echo "$p"|cut
-d : -f2)
190 s
=$
(echo "$p"|cut
-d : -f3)
191 if [ $z = $zonename ] ; then
193 elif [ $s = "installed" ] ; then
194 zonelist
[clone_cnt
]=$z
198 if [ $clone_cnt -gt 0 ] ; then
199 clone
="Clone...\n"; \
204 macstate
=$
(zonecfg
-z $zonename info|
grep win_mac_write
)
205 if [[ -n $macstate ]] ; then
206 permitrelabel
="Deny Relabeling\n"
208 permitrelabel
="Permit Relabeling\n"
213 bootmode
=$
(zonecfg
-z $zonename info autoboot
)
214 if [[ $bootmode == 'autoboot: true' ]] ; then
215 autoboot
="Set Manual Booting\n"
217 autoboot
="Set Automatic Booting\n"
222 if [[ ! -n $zonename ]] ; then
223 zonename
=$
(zenity
--entry \
227 --text="Enter Zone Name: ")
229 if [[ ! -n $zonename ]] ; then
234 zonecfg
-z $zonename "create -t SUNWtsoldef;\
235 set zonepath=/zone/$zonename"
241 zfs list
-H $ZDSET/$zonename 1>/dev
/null
2>&1
243 for zbe
in $
(zfs list
-rHo name
$ZDSET/$zonename|
grep ROOT
/zbe
) ; do
244 zfs destroy
$delopt $zbe
250 if [ $hostType = cipso
] ; then
251 template
=${zonename}_cipso
254 template
=${zonename}_unlab
255 deflabel
="def_label=${hexlabel};"
258 tnzone
=$
(grep "^${template}:" $TNRHTP 2>/dev
/null
)
259 if [ $?
-eq 0 ] ; then
260 sed -e "/^${template}/d" $TNRHTP > $TXTMP/tnrhtp.$$
2>/dev
/null
261 mv $TXTMP/tnrhtp.$$
$TNRHTP
263 print
"${template}:host_type=${hostType};doi=1;min_sl=${minlabel};max_sl=${maxlabel};$deflabel" >> $TNRHTP
268 tnzline
="$zonename:${hexlabel}:0::"
269 grep "^$tnzline" $TNZONECFG 1>/dev
/null
2>&1
270 if [ $?
-eq 1 ] ; then
271 print
"$tnzline" >> $TNZONECFG
275 # Add matching entries in tnrhtp if necessary
287 hexlabel
=$
(tgnome-selectlabel \
289 --text="$msg_getlabel $zonename zone:" \
290 --min="${DEFAULTLABEL}" \
291 --default="${DEFAULTLABEL}" \
292 --max=$
(chk_encodings
-X) \
297 x
=$
(grep -i :{$hexlabel}: $TNZONECFG)
299 z
=$
(print
$x|cut
-d : -f1)
302 --text="$msg_inuse $z zone.")
310 deflabel
=$
(hextoalabel
$hexlabel)
311 minlabel
=$
(tgnome-selectlabel \
313 --text="$msg_getmin $zonename zone:" \
314 --min="${DEFAULTLABEL}" \
316 --default="$hexlabel" \
320 [ $?
!= 0 ] && return
322 maxlabel
=$
(tgnome-selectlabel \
324 --text="$msg_getmax $zonename zone:" \
326 --max=$
(chk_encodings
-X) \
327 --default="$hexlabel" \
331 [ $?
!= 0 ] && return
339 echo $
(zfs get
2>&1 |
grep encryption |
sed -e s
/^.
*YES
// -e s
/\|
//g
)
343 pass1
=$
(zenity
--entry --title="$title" --text="Enter passphrase:" \
344 --width=330 --hide-text)
345 pass2
=$
(zenity
--entry --title="$title" --text="Re-enter passphrase:" \
346 --width=330 --hide-text)
347 if [[ "$pass1" != "$pass2" ]]; then
348 zenity
--error --title="$title" \
349 --text="Passphrases do not match"
353 echo "$pass1" > $file
361 # First check if ZFS encrytption support is available
362 pversion
=$
(zpool list
-H -o version
$pool)
363 cversion
=$
(zpool upgrade
-v |
grep Crypto |
awk '{ print $1 }')
364 if (( cversion
== 0 || pversion
< cversion
)); then
365 zfs create
$options $ZDSET
369 encryption
=$
(zenity
--list --title="$title" --height=320 \
370 --text="Select cipher for encryption of all labels:" \
371 --column="encryption" $
(encryptionValues
))
373 if [[ $?
!= 0 ||
$encryption == "off" ]]; then
374 zfs create
$options $ZDSET
378 format
=$
(zenity
--list --title="$title" \
379 --text "Select encryption key source:" \
380 --column="Key format and location" \
381 "Passphrase" "Generate Key in file")
384 if [[ $format == "Passphrase" ]]; then
385 file=$
(getPassphrase
)
386 if [[ $file == "" ]]; then
389 keysource
="passphrase,file://$file"
391 elif [[ $format == "Generate Key in file" ]]; then
392 file=$
(zenity
--file-selection \
393 --title="$title: Location of key file" \
394 --save --confirm-overwrite)
396 if [[ $encryption == "on" ]]; then
399 t
=${encryption#aes-} && keylen
=${t%%-*}
401 pktool genkey keystore
=file keytype
=aes \
402 keylen
=$keylen outkey
=$file
403 keysource
="raw,file:///$file"
406 options
="$options -o encryption=$encryption -o keysource=$keysource"
407 zfs create
$options $ZDSET
408 if (( removefile
== 1 )); then
409 zfs
set keysource
=passphrase
,prompt
$ZDSET
416 zonepath
=$
(zoneadm
-z $zonename list
-p|cut
-d : -f4)
417 ZONE_ETC_DIR
=$zonepath/root
/etc
418 SYSIDCFG
=${ZONE_ETC_DIR}/sysidcfg
420 if [ -f /var
/ldap
/ldap_client_file
] ; then
421 ldapaddress
=$
(ldapclient list | \
422 grep "^NS_LDAP_SERVERS" | cut
-d " " -f2)
423 print
"name_service=LDAP {" > ${SYSIDCFG}
425 print
"domain_name=$domain" >> ${SYSIDCFG}
426 profName
=$
(ldapclient list | \
427 grep "^NS_LDAP_PROFILE" | cut
-d " " -f2)
428 proxyPwd
=$
(ldapclient list | \
429 grep "^NS_LDAP_BINDPASSWD" | cut
-d " " -f2)
430 proxyDN
=$
(ldapclient list | \
431 grep "^NS_LDAP_BINDDN" | cut
-d " " -f 2)
432 if [ "$proxyDN" ] ; then
433 print
"proxy_dn=\"$proxyDN\"" >> ${SYSIDCFG}
434 print
"proxy_password=\"$proxyPwd\"" >> ${SYSIDCFG}
436 print
"profile=$profName" >> ${SYSIDCFG}
437 print
"profile_server=$ldapaddress }" >> ${SYSIDCFG}
438 cp /etc
/nsswitch.conf
$ZONE_ETC_DIR/nsswitch.ldap
440 print
"name_service=NONE" > ${SYSIDCFG}
442 print
"security_policy=NONE" >> ${SYSIDCFG}
443 locale
=$
(locale|
grep LANG | cut
-d "=" -f2)
444 if [[ -z $locale ]] ; then
447 print
"system_locale=$locale" >> ${SYSIDCFG}
448 timezone
=$
(grep "^TZ" /etc
/default
/init|cut
-d "=" -f2)
449 print
"timezone=$timezone" >> ${SYSIDCFG}
450 print
"terminal=vt100" >> ${SYSIDCFG}
451 rootpwd
=$
(grep "^root:" /etc
/shadow|cut
-d : -f2)
453 # There are two problems with setting the root password:
454 # The zone's shadow file may be read-only
455 # The password contains unparsable characters
456 # so the following line is commented out until this is resolved.
458 #print "root_password=$rootpwd" >> ${SYSIDCFG}
459 print
"nfs4_domain=dynamic" >> ${SYSIDCFG}
460 print
"network_interface=PRIMARY {" >> ${SYSIDCFG}
462 net
=$
(zonecfg
-z $zonename info net
)
463 ipType
=$
(zonecfg
-z $zonename info ip-type|cut
-d" " -f2)
464 if [ $ipType = exclusive
] ; then
465 hostname
=$
(zenity
--entry \
468 --text="${zonename}0: Enter Hostname or dhcp: ")
469 [ $?
!= 0 ] && return
471 if [ $hostname = dhcp
] ; then
472 print
"dhcp" >> ${SYSIDCFG}
474 print
"hostname=$hostname" >> ${SYSIDCFG}
475 ipaddr
=$
(getent hosts
$hostname|cut
-f1)
476 if [ $?
!= 0 ] ; then
477 ipaddr
=$
(zenity
--entry \
479 --text="$nic: Enter IP address: " \
480 --entry-text a.b.c.d
)
481 [ $?
!= 0 ] && return
484 if [[ -z $ipaddr ]] ; then
488 print
"ip_address=$ipaddr" >> ${SYSIDCFG}
490 print
"netmask=$nm" >> ${SYSIDCFG}
491 print
"default_route=none" >> ${SYSIDCFG}
492 template
=${zonename}_cipso
496 elif [[ -n $net ]] ; then
498 hostname
=$
(zenity
--entry \
501 --text="Enter Hostname: " \
502 --entry-text $hostname)
503 [ $?
!= 0 ] && return
505 print
"hostname=$hostname" >> ${SYSIDCFG}
506 ipaddr
=$
(getent hosts
$hostname|cut
-f1)
508 print
"ip_address=$ipaddr" >> ${SYSIDCFG}
512 for i
in ${aznics[*]} ; do
513 ipaddr
=$
(ifconfig
$i|
grep inet|cut
-d " " -f2)
515 print
"hostname=$(hostname)" >> ${SYSIDCFG}
516 print
"ip_address=$ipaddr" >> ${SYSIDCFG}
519 print
"protocol_ipv6=no }" >> ${SYSIDCFG}
520 cp /etc
/default
/nfs
${ZONE_ETC_DIR}/default
/nfs
521 touch ${ZONE_ETC_DIR}/.NFS4inst_state.domain
526 if [[ -z $image ]] ; then
527 msg_clone
=$
(gettext "Clone the $zonename zone using a
528 snapshot of one of the following halted zones:")
529 image
=$
(zenity
--list \
531 --text="$msg_clone" \
534 --column="Installed Zones" ${zonelist[*]})
537 if [[ -n $image ]] ; then
539 zoneadm
-z $zonename clone
$image
541 if [ $NSCD_PER_LABEL = 0 ] ; then
542 sharePasswd
$zonename
544 unsharePasswd
$zonename
547 ipType
=$
(zonecfg
-z $zonename info ip-type|cut
-d" " -f2)
548 if [ $ipType = exclusive
] ; then
549 zoneadm
-z $zonename ready
550 zonepath
=$
(zoneadm
-z $zonename list
-p|cut
-d : -f4)
551 sys-unconfig
-R $zonepath/root
2>/dev
/null
553 zoneadm
-z $zonename halt
560 if [ $DISP -eq 0 ] ; then
561 gettext "installing zone $zonename ...\n"
562 zoneadm
-z $zonename install
564 # sleep is needed here to avoid occasional timing
565 # problem with gnome-terminal display...
568 --title="$title: Installing $zonename zone" \
569 --command "zoneadm -z $zonename install" \
574 zonestate
=$
(zoneadm
-z $zonename list
-p | cut
-d : -f 3)
575 if [ $zonestate != installed
] ; then
576 gettext "error installing zone $zonename.\n"
580 if [ $NSCD_PER_LABEL = 0 ] ; then
581 sharePasswd
$zonename
583 unsharePasswd
$zonename
586 zoneadm
-z $zonename ready
587 zonestate
=$
(zoneadm
-z $zonename list
-p | cut
-d : -f 3)
588 if [ $zonestate != ready
] ; then
589 gettext "error making zone $zonename ready.\n"
594 zoneadm
-z $zonename halt
600 # if there is an entry for this zone in tnzonecfg, remove it
601 # before deleting the zone.
603 tnzone
=$
(grep "^$zonename:" $TNZONECFG 2>/dev
/null
)
604 if [ -n "${tnzone}" ] ; then
605 sed -e "/^$zonename:/d" $TNZONECFG > \
606 $TXTMP/tnzonefg.$$
2>/dev
/null
607 mv $TXTMP/tnzonefg.$$
$TNZONECFG
610 for tnzone
in $
(grep ":${zonename}_unlab" $TNRHDB 2>/dev
/null
) ; do
612 sed -e "/:${zonename}_unlab/d" $TNRHDB > \
613 $TXTMP/tnrhdb.$$
2>/dev
/null
614 mv $TXTMP/tnrhdb.$$
$TNRHDB
617 for tnzone
in $
(grep "^${zonename}_unlab:" $TNRHTP 2>/dev
/null
) ; do
618 tnctl
-dt ${zonename}_unlab
619 sed -e "/^${zonename}_unlab:/d" $TNRHTP > \
620 $TXTMP/tnrhtp.$$
2>/dev
/null
621 mv $TXTMP/tnrhtp.$$
$TNRHTP
624 for tnzone
in $
(grep ":${zonename}_cipso" $TNRHDB 2>/dev
/null
) ; do
626 sed -e "/:${zonename}_cipso/d" $TNRHDB > \
627 $TXTMP/tnrhdb.$$
2>/dev
/null
628 mv $TXTMP/tnrhdb.$$
$TNRHDB
631 for tnzone
in $
(grep "^${zonename}_cipso:" $TNRHTP 2>/dev
/null
) ; do
632 tnctl
-dt ${zonename}_cipso
633 sed -e "/^${zonename}_cipso:/d" $TNRHTP > \
634 $TXTMP/tnrhtp.$$
2>/dev
/null
635 mv $TXTMP/tnrhtp.$$
$TNRHTP
638 zonecfg
-z $zonename delete
-F
640 removeZoneBEs
$delopt
641 for snap
in $
(zfs list
-Ho name
-t snapshot|
grep "\@${zonename}_snap") ; do
651 set -A octets
$ipaddr
653 if [ ${#octets[*]} == 4 ] ; then
654 while (( octet_cnt
< ${#octets[*]} )); do
655 dummy
=${octets[octet_cnt]}
656 if [ $dummy = ${octets[octet_cnt]} ] ; then
657 if (( dummy
>= 0 && \
658 dummy
< 256 )) ; then
665 --text="$ipaddr $msg_badip")
673 --text="$ipaddr $msg_badip")
680 for i
in $
(ifconfig
-a4|
grep "^[a-z].*:")
682 print
"$i" |
grep "^[a-z].*:" >/dev
/null
2>&1
683 [ $?
-eq 1 ] && continue
685 i
=${i%:} # Remove colon after interface name
686 for j
in $
(ifconfig
$i)
700 nm
=$
(zenity
--entry \
703 --text="$ipaddr: Enter netmask: " \
704 --entry-text 255.255.255.0)
705 [ $?
!= 0 ] && return;
707 cidr
=$
(perl
-e 'use Socket; print unpack("%32b*",inet_aton($ARGV[0])), "\n";' $nm)
712 if [[ -z $ipaddr ]] ; then
716 if [[ -z $cidr ]] ; then
719 zonecfg
-z $zonename "add net; \
720 set address=${ipaddr}/${cidr}; \
723 template
=${zonename}_cipso
731 for j
in $
(ifconfig
$nic)
736 all-zones
) zone
=all-zones
;;
746 if [[ $flags == ~
(E
).UP
, ]] ; then
751 if [[ $nic == ~
(E
).
: ]] ; then
754 vnic
=$
(dladm show-vnic
-po link
$nic 2>/dev
/null
)
755 if [[ -n $vnic ]] ; then
761 if [ $ipaddr != 0.0.0.0 ] ; then
762 x
=$
(grep "^${ipaddr}[^0-9]" $TNRHDB)
768 template
=$
(print
"$x"|cut
-d : -f2)
775 deleteTnrhdbEntry
() {
776 remote
=$
(grep "^${ipaddr}[^0-9]" $TNRHDB)
778 ip
=$
(print
$remote|cut
-d "/" -f1)
779 if [[ $remote == ~
(E
).
/ ]] ; then
780 pr=$
(print
$remote|cut
-d "/" -f2)
783 sed -e "/^${remote}/d" $TNRHDB > /tmp
/tnrhdb.$$
2>/dev
/null
784 mv /tmp
/tnrhdb.$$
$TNRHDB
790 if [[ -n $cidr ]] ; then
791 print
"${ipaddr}/$cidr:$template" >> $TNRHDB
792 tnctl
-h ${ipaddr}/$cidr:$template
794 print
"${ipaddr}:$template" >> $TNRHDB
795 tnctl
-h ${ipaddr}:$template
800 hostname
=$
(zenity
--entry \
803 --text="$nic: Enter Hostname: ")
805 [ $?
!= 0 ] && return
807 ipaddr
=$
(getent hosts
$hostname|cut
-f1)
808 if [[ -z $ipaddr ]] ; then
809 ipaddr
=$
(zenity
--entry \
811 --text="$nic: Enter IP address: " \
812 --entry-text a.b.c.d
)
813 [ $?
!= 0 ] && return
821 if [[ -z $ipaddr ]] ; then
824 grep "^${ipaddr}[^0-9]" /etc
/inet
/hosts
>/dev
/null
825 if [ $?
-eq 1 ] ; then
826 print
"$ipaddr\t$hostname" >> /etc
/inet
/hosts
833 ifconfig
$nic $ipaddr netmask
+ broadcast
+
835 # TODO: better integration with nwam
836 # TODO: get/set netmask for IP address
838 print
$hostname > /etc
/hostname.
$nic
842 msg
=$
(ifconfig
$nic addif
0.0.0.0)
846 nic
=$
(print
"$msg"|cut
-d" " -f5)
851 if [ $zonename != global
] ; then
852 vnicname
=${zonename}0
854 vnicname
=$
(zenity
--entry \
858 --text="Enter VNIC Name: ")
860 if [[ ! -n $vnicname ]] ; then
864 x
=$
(dladm show-vnic|
grep "^$vnicname " )
865 if [[ ! -n $x ]] ; then
866 dladm create-vnic
-l $nic $vnicname
868 if [ $zonename = global
] ; then
869 ifconfig
$vnicname plumb
871 zonecfg
-z $zonename "add net; \
872 set physical=$vnicname; \
880 # TODO: better integration with nwam
882 ifconfig
$nic all-zones
;\
883 if_file
=/etc
/hostname.
$nic
884 sed q |
sed -e "s/$/ all-zones/" < $if_file >$TXTMP/txnetmgr.$$
885 mv $TXTMP/txnetmgr.$$
$if_file
890 # TODO: better integration with nwam
892 ifconfig
$nic -zone;\
893 if_file
=/etc
/hostname.
$nic
894 sed q |
sed -e "s/all-zones/ /" < $if_file >$TXTMP/txnetmgr.$$
895 mv $TXTMP/txnetmgr.$$
$if_file
899 ipaddr
=$
(zenity
--entry \
902 --text="Zone:$zonename. Enter IP address of remote host or network: " \
903 --entry-text a.b.c.d
)
904 [ $?
!= 0 ] && return
906 if [[ -z $ipaddr ]] ; then
909 if [ ${octets[3]} = 0 ] ; then
912 if [[ -z $cidr ]] ; then
918 print
"${ipaddr}/$cidr:$template" > $TXTMP/tnrhdb_new.$$
919 x
=$
(tnchkdb
-h $TXTMP/tnrhdb_new.$$
2>$TXTMP/syntax_error.$$
)
923 syntax
=$
(cat $TXTMP/syntax_error.$$
)
928 rm $TXTMP/tnrhdb_new.$$
929 rm $TXTMP/syntax_error.$$
934 remotes
=$
(grep "^[^#][0-9.]" $TNRHDB|
grep ":$template"|cut
-d : -f1-2|
tr : " ")
935 if [ $template = cipso
] ; then
936 templateHeading
="from All Zones":
938 templateHeading
="from this Zone":
940 if [[ -n $remotes ]] ; then
941 ipaddr
=$
(zenity
--list \
943 --text="$msg_getremote" \
946 --column="Remove Access to:" \
947 --column="$templateHeading" \
950 if [[ -n $ipaddr ]] ; then
952 tnctl
-dh ${ip}:$template
963 tnzone
=$
(grep "^$zonename:" $TNZONECFG 2>/dev
/null
)
964 zoneMLPs
=:$
(print
"$tnzone"|cut
-d : -f4)
965 sharedMLPs
=:$
(print
"$tnzone"|cut
-d : -f5)
966 attrs
="Private Interfaces$zoneMLPs\nShared Interfaces$sharedMLPs"
967 ports
=$
(print
"$attrs"|zenity
--list \
971 --text="Zone: $zonename\nClick once to select, twice to edit.\nShift-click to select both rows." \
972 --column="Multilevel Ports (example: 80-81/tcp;111/udp;)" \
977 if [[ -z $ports ]] ; then
981 # getopts needs another a blank and another dash
982 ports
=--$
(print
"$ports"|
sed 's/ //g'|
sed 's/|/ --/g'|
sed 's/Interfaces:/ :/g')
985 while getopts "z:(Private)s:(Shared)" opt
$ports ; do
987 z
) zoneMLPs
=$OPTARG ;;
988 s
) sharedMLPs
=$OPTARG ;;
992 sed -e "/^$zonename:*/d" $TNZONECFG > $TXTMP/tnzonecfg.$$
2>/dev
/null
993 tnzone
=$
(print
"$tnzone"|cut
-d : -f1-3)
994 echo "${tnzone}${zoneMLPs}${sharedMLPs}" >> $TXTMP/tnzonecfg.$$
996 x
=$
(tnchkdb
-z $TXTMP/tnzonecfg.$$
2>$TXTMP/syntax_error.$$
)
999 mv $TXTMP/tnzonecfg.$$
$TNZONECFG
1002 --text="Multilevel ports for the $zonename zone\nwill be interpreted on next reboot."
1003 if [ $zonename != global
] ; then
1007 syntax
=$
(cat $TXTMP/syntax_error.$$
)
1008 x
=$
(zenity
--error \
1011 rm $TXTMP/tnzonecfg.$$
1013 rm $TXTMP/syntax_error.$$
1016 enableAuthentication
() {
1019 zonepath
=$
(zoneadm
-z $1 list
-p|cut
-d : -f4)
1020 ZONE_ETC_DIR
=$zonepath/root
/etc
1022 # If the zone's shadow file was previously read-only
1023 # there may be no root password entry for this zone.
1024 # If so, replace the root password entry with the global zone's.
1026 entry
=$
(grep ^root
:: $ZONE_ETC_DIR/shadow
)
1027 if [ $?
-eq 0 ] ; then
1028 grep ^root
: /etc
/shadow
> $TXTMP/shadow.$$
1029 sed -e "/^root::/d" $ZONE_ETC_DIR/shadow
>> \
1030 $TXTMP/shadow.$$
2>/dev
/null
1031 mv $TXTMP/shadow.$$
$ZONE_ETC_DIR/shadow
1032 chmod 400 $ZONE_ETC_DIR/shadow
1035 if [ $LOGNAME = "root" ]; then
1043 # Add the user who assumed the root role to each installed zone
1045 while (( file_cnt
< ${#file[*]} )); do
1046 exists
=$
(grep "^${LOGNAME}:" \
1047 $ZONE_ETC_DIR/${file[file_cnt]} >/dev
/null
)
1048 if [ $?
-ne 0 ] ; then
1049 entry
=$
(grep "^${LOGNAME}:" \
1050 /etc
/${file[file_cnt]})
1051 if [ $?
-eq 0 ] ; then
1053 $ZONE_ETC_DIR/${file[file_cnt]}
1058 chmod 400 $ZONE_ETC_DIR/shadow
1062 zonecfg
-z $1 remove fs dir
=/etc
/passwd
>/dev
/null
2>&1 |
grep -v such
1063 zonecfg
-z $1 remove fs dir
=/etc
/shadow
>/dev
/null
2>&1 |
grep -v such
1064 zoneadm
-z $1 ready
>/dev
/null
2>&1
1065 if [ $?
-eq 0 ] ; then
1066 enableAuthentication
$1
1067 zoneadm
-z $1 halt
>/dev
/null
2>&1
1074 passwd
=$
(zonecfg
-z $1 info|
grep /etc
/passwd
)
1075 if [ $?
-eq 1 ] ; then
1076 zonecfg
-z $1 "add fs; \
1077 set special=/etc/passwd; \
1078 set dir=/etc/passwd; \
1083 set special=/etc/shadow; \
1084 set dir=/etc/shadow; \
1089 zoneadm
-z $1 halt
>/dev
/null
2>&1
1092 # This routine is a toggle -- if we find it configured for global nscd,
1093 # change to nscd-per-label and vice-versa.
1095 # The user was presented with only the choice to CHANGE the existing
1099 if [ $NSCD_PER_LABEL -eq 0 ] ; then
1100 # this MUST be a regular file for svc-nscd to detect
1101 touch $NSCD_INDICATOR
1102 NSCD_OPT
="Unconfigure per-zone name service"
1104 for i
in $
(zoneadm list
-i |
grep -v global
) ; do
1105 zoneadm
-z $i halt
>/dev
/null
2>&1
1109 rm -f $NSCD_INDICATOR
1110 NSCD_OPT
="Configure per-zone name service"
1112 for i
in $
(zoneadm list
-i |
grep -v global
) ; do
1113 zoneadm
-z $i halt
>/dev
/null
2>&1
1120 ncmds
[0]="Only use all-zones interfaces"
1121 ncmds
[1]="Add a logical interface"
1122 ncmds
[2]="Add a virtual interface (VNIC)"
1124 stacks
[0]="Shared Stack"
1125 stacks
[1]="Exclusive Stack"
1128 netOps
[0]="1\n${ncmds[0]}\nShared Stack\n${aznics[*]}"
1133 set -A nics $
(dladm show-phys|
grep -v LINK|cut
-f1 -d " ")
1135 while (( nic_cnt
< ${#nics[*]} )); do
1136 netOps
[netOp_cnt
- 1]="\n$netOp_cnt\n${ncmds[1]}\n${stacks[0]}\n${nics[nic_cnt]}"
1138 netOps
[netOp_cnt
- 1]="\n$netOp_cnt\n${ncmds[2]}\n${stacks[1]}\n${nics[nic_cnt]}"
1143 netOp
=$
(print
"${netOps[*]}"|zenity
--list \
1145 --text="$msg_getnet $zonename zone:" \
1149 --column="Network Configuration " \
1150 --column="IP Type" \
1151 --column="Available Interfaces" \
1155 # User picked cancel or no selection
1156 if [[ -z $netOp ]] ; then
1160 # All-zones is the default, so just return
1161 if [ $netOp = 1 ] ; then
1165 cmd
=$
(print
"${netOps[$netOp - 1]}"|
tr '\n' ';' |cut
-d';' -f 3)
1166 nic
=$
(print
"${netOps[$netOp - 1]}"|
tr '\n' ';' |cut
-d';' -f 5)
1172 zonecfg
-z $zonename set ip-type
=exclusive
1178 manageInterface
() {
1182 # Clear list of commands
1192 if [ $updown = Down
] ; then
1193 bringup
="Bring Up\n"
1195 bringdown
="Bring Down\n"
1200 newlogical
="Create Logical Interface...\n";
1201 newvnic
="Create Virtual Interface (VNIC)...\n";
1204 unplumb
="Remove Logical Interface\n"
1207 newlogical
="Create Logical Interface...\n";
1208 unplumb
="Remove Virtual Interface\n" ;
1212 if [ $ipaddr = "..." ] ; then
1213 setipaddr
="Set IP address...\n"
1214 elif [ $zone != all-zones
] ; then
1215 share
="Share with Shared-IP Zones\n"
1217 share
="Remove from Shared-IP Zones\n"
1230 --text="Select a command from the list below:" \
1232 --column "Interface: $nic" )
1235 " Create Logical Interface...")
1237 " Create Virtual Interface (VNIC)...")
1239 " Set IP address...")
1242 " Share with Shared-IP Zones")
1244 " Remove from Shared-IP Zones")
1246 " Remove Logical Interface")
1247 ifconfig
$nic unplumb
1248 rm -f /etc
/hostname.
$nic
1250 " Remove Virtual Interface")
1251 ifconfig
$nic unplumb
1252 dladm delete-vnic
$nic
1253 rm -f /etc
/hostname.
$nic
1258 ifconfig
$nic down
;;
1265 set -A ip $
(getent hosts $
(cat /etc
/nodename
))
1266 for i
in $
(ifconfig
-au4|
grep "^[a-z].*:" |
grep -v LOOPBACK
)
1268 print
"$i" |
grep "^[a-z].*:" >/dev
/null
2>&1
1269 [ $?
-eq 1 ] && continue
1271 nic
=${i%:} # Remove colon after interface name
1273 if [ ${ip[0]} = $ipaddr ]; then
1283 for i
in $
(ifconfig
-a4|
grep "^[a-z].*:" |
grep -v LOOPBACK
)
1285 print
"$i" |
grep "^[a-z].*:" >/dev
/null
2>&1
1286 [ $?
-eq 1 ] && continue
1288 nic
=${i%:} # Remove colon after interface name
1290 attrs
="$nic $linktype $zone $ipaddr $template $updown $attrs"
1293 nic
=$
(zenity
--list \
1295 --text="Select an interface from the list below:" \
1298 --column="Interface" \
1300 --column="Zone Name" \
1301 --column="IP Address" \
1302 --column="Template" \
1306 if [[ -z $nic ]] ; then
1313 createLDAPclient
() {
1314 ldaptitle
="$title: Create LDAP Client"
1315 ldapdomain
=$
(zenity
--entry \
1317 --title="$ldaptitle" \
1318 --text="Enter Domain Name: ")
1319 if [[ -n $ldapdomain ]] ; then
1320 ldapserver
=$
(zenity
--entry \
1322 --title="$ldaptitle" \
1323 --text="Enter Hostname of LDAP Server: ")
1327 if [[ -n $ldapserver ]] ; then
1328 ldapserveraddr
=$
(zenity
--entry \
1330 --title="$ldaptitle" \
1331 --text="Enter IP adddress of LDAP Server $ldapserver: ")
1336 while [[ -z ${ldappassword} ||
"x$ldappassword" != "x$ldappasswordconfirm" ]] ; do
1337 ldappassword
=$
(zenity
--entry \
1339 --title="$ldaptitle" \
1341 --text="Enter LDAP Proxy Password:")
1342 ldappasswordconfirm
=$
(zenity
--entry \
1344 --title="$ldaptitle" \
1346 --text="Confirm LDAP Proxy Password:")
1348 ldapprofile
=$
(zenity
--entry \
1350 --title="$ldaptitle" \
1351 --text="Enter LDAP Profile Name: ")
1352 whatnext
=$
(zenity
--list \
1355 --title="$ldaptitle" \
1356 --text="Proceed to create LDAP Client?" \
1357 --column=Parameter
--column=Value \
1358 "Domain Name" "$ldapdomain" \
1359 "Hostname" "$ldapserver" \
1360 "IP Address" "$ldapserveraddr" \
1361 "Password" "$(print "$ldappassword" | sed 's/./*/g')" \
1362 "Profile" "$ldapprofile")
1363 [ $?
!= 0 ] && return
1365 grep "^${ldapserveraddr}[^0-9]" /etc
/hosts
> /dev
/null
1366 if [ $?
-eq 1 ] ; then
1367 print
"$ldapserveraddr $ldapserver" >> /etc
/hosts
1370 grep "${ldapserver}:" $TNRHDB > /dev
/null
1371 if [ $?
-eq 1 ] ; then
1372 print
"# ${ldapserver} - ldap server" \
1374 print
"${ldapserveraddr}:cipso" \
1376 tnctl
-h "${ldapserveraddr}:cipso"
1379 proxyDN
=$
(print
$ldapdomain|
awk -F"." \
1380 "{ ORS = \"\" } { for (i = 1; i < NF; i++) print \"dc=\"\\\$i\",\" }{ print \"dc=\"\\\$NF }")
1383 --title="$ldaptitle" \
1385 --text="global zone will be LDAP client of $ldapserver"
1387 ldapout
=$TXTMP/ldapclient.$$
1389 ldapclient init
-a profileName
="$ldapprofile" \
1390 -a domainName
="$ldapdomain" \
1391 -a proxyDN
"=cn=proxyagent,ou=profile,$proxyDN" \
1392 -a proxyPassword
="$ldappassword" \
1393 "$ldapserveraddr" >$ldapout 2>&1
1395 if [ $?
-eq 0 ] ; then
1401 zenity
--text-info \
1404 --title="$ldaptitle: $ldapstatus" \
1413 if [ $DISP -eq 0 ] ; then
1414 if [ $FORCE -eq 0 ] ; then
1415 gettext "OK to destroy all zones [y|N]? "
1417 printf "%s\n" "$ans" \
1418 |
/usr
/xpg
4/bin
/grep -Eq "$(locale yesexpr)"
1419 if [ $?
-ne 0 ] ; then
1420 gettext "canceled.\n"
1424 gettext "destroying all zones ...\n"
1426 killall
=$
(zenity
--question \
1429 --text="$msg_confirmkill")
1430 if [[ $?
!= 0 ]]; then
1435 for p
in $
(zoneadm list
-cp|
grep -v global
:) ; do
1436 zonename
=$
(echo "$p"|cut
-d : -f2)
1437 if [ $DISP -eq 0 ] ; then
1438 gettext "destroying zone $zonename ...\n"
1440 zoneadm
-z $zonename halt
1>/dev
/null
2>&1
1441 zoneadm
-z $zonename uninstall
-F 1>/dev
/null
2>&1
1447 createDefaultZones
() {
1448 # If GUI display is not used, skip the dialog
1449 if [ $DISP -eq 0 ] ; then
1451 if [ $?
-ne 0 ] ; then
1454 createDefaultInternal
1458 msg_choose1
=$
(gettext "Choose one:")
1459 defpub
=$
(gettext "$PUBZONE zone only")
1460 defboth
=$
(gettext "$PUBZONE and $INTZONE zones")
1461 defskip
=$
(gettext "Main Menu...")
1468 --text="$msg_defzones" \
1469 --column="$msg_choose1" \
1475 createDefaultPublic
;;
1479 if [ $?
-ne 0 ] ; then
1482 createDefaultInternal
;;
1489 createDefaultPublic
() {
1491 if [ $DISP -eq 0 ] ; then
1492 gettext "creating default $zonename zone ...\n"
1496 hexlabel
=$DEFAULTLABEL
1501 if [ $?
-ne 0 ] ; then
1505 if [ $DISP -eq 0 ] ; then
1506 gettext "booting zone $zonename ...\n"
1507 zoneadm
-z $zonename boot
1509 zoneadm
-z $zonename boot
&
1512 --title="Zone Console: $zonename $msg_continue" \
1513 --command "zlogin -C $zonename"
1517 createDefaultInternal
() {
1518 zoneadm
-z $PUBZONE halt
1523 zonecfg
-z $zonename set autoboot
=false
1526 zoneadm
-z $PUBZONE boot
&
1529 if [ $DISP -eq 0 ] ; then
1530 gettext "creating default $zonename zone ...\n"
1536 x
=$
(grep -i :{$hexlabel}: $TNZONECFG)
1537 if [ $?
= 0 ] ; then
1538 z
=$
(print
$x|cut
-d : -f1)
1539 echo "$msg_inuse $z zone."
1545 if [ $DISP -eq 0 ] ; then
1546 gettext "booting zone $zonename ...\n"
1549 --title="Zone Console: $zonename" \
1550 --command "zlogin -C $zonename" &
1552 zoneadm
-z $zonename boot
&
1556 set -A zonelist
"global\nrunning\nADMIN_HIGH"
1559 for p
in $
(zoneadm list
-cp|
grep -v global
:) ; do
1562 if [ $zone_cnt == 1 ] ; then
1565 if [ $zone_cnt == 1 ] ; then
1572 for p
in $
(zoneadm list
-cp|
grep -v global
:) ; do
1573 zonename
=$
(echo "$p"|cut
-d : -f2)
1574 state
=$
(echo "$p"|cut
-d : -f3)
1575 hexlabel
=$
(grep "^$zonename:" $TNZONECFG|cut
-d : -f2)
1576 if [[ $hexlabel ]] ; then
1577 curlabel
=$
(hextoalabel
$hexlabel)
1581 zonelist
[zone_cnt
]="\n$zonename\n$state\n$curlabel"
1584 zonename
=$
(print
"${zonelist[*]}"|zenity
--list \
1586 --text="$msg_getzone" \
1589 --column="Zone Name" \
1591 --column="Sensitivity Label" \
1594 # if the menu choice was a zonename, pop up zone menu
1595 if [[ -n $zonename ]] ; then
1602 # Loop for single-zone menu
1606 # Clear list of commands
1622 if [ $zone_cnt -gt 1 ] ; then
1623 killZones
="Destroy all zones...\n"
1624 xit
="Select another zone..."
1629 if [ $zonename = global
] ; then
1630 ldapClient
="Create LDAP Client...\n"
1631 nscdOpt
="$NSCD_OPT\n"
1632 createZone
="Create a new zone...\n"
1633 addnet
="Configure Network Interfaces...\n"
1642 zonestate
=$
(zoneadm
-z $zonename list
-p | cut
-d : -f 3)
1648 if [ $zonename != global
] ; then
1660 if [[ -z $label ]] ; then
1664 uninstall
="Uninstall\n"
1669 install="Install...\n"
1675 uninstall
="Uninstall\n"
1709 --text="$msg_getcmd" \
1712 --column "Zone: $zonename Status: $zonestate" )
1715 " Create a new zone...")
1722 --title="Zone Console: $zonename" \
1723 --command "zlogin -C $zonename" & ;;
1729 zoneadm
-z $zonename ready
;;
1732 zoneadm
-z $zonename boot
;;
1735 zoneadm
-z $zonename halt
;;
1738 zoneadm
-z $zonename reboot
;;
1747 zoneadm
-z $zonename uninstall
-F;;
1753 " Configure Network Interfaces...")
1754 if [ $zonename = global
] ; then
1760 " Add Single-level Access to Remote Host...")
1763 " Add Multilevel Access to Remote Host...")
1767 " Remove Single-level Access to Remote Host...")
1770 " Remove Multilevel Access to Remote Host...")
1774 " Configure Multilevel Ports...")
1777 " Permit Relabeling")
1778 zonecfg
-z $zonename set limitpriv
=default
,\
1779 win_mac_read
,win_mac_write
,win_selection
,win_dac_read
,win_dac_write
,\
1780 file_downgrade_sl
,file_upgrade_sl
,sys_trans_label
;;
1783 zonecfg
-z $zonename set limitpriv
=default
;;
1785 " Set Automatic Booting")
1786 zonecfg
-z $zonename set autoboot
=true
;;
1788 " Set Manual Booting")
1789 zonecfg
-z $zonename set autoboot
=false
;;
1791 " Create LDAP Client...")
1794 " Configure per-zone name service")
1797 " Unconfigure per-zone name service")
1800 " Destroy all zones...")
1805 if [ $zone_cnt == 1 ] ; then
1815 # Main loop for top-level window
1818 /usr
/bin
/plabel $$
1>/dev
/null
2>&1
1819 if [ $?
!= 0 ] ; then
1820 gettext "$0 : Trusted Extensions must be enabled.\n"
1824 myzone
=$
(/sbin
/zonename
)
1825 if [ $myzone != "global" ] ; then
1826 gettext "$0 : must be in global zone to run.\n"
1831 process_options
"$@" ||
exit
1833 mkdir
$TXTMP 2>/dev
/null
1834 deflabel
=$
(chk_encodings
-a|
grep "Default User Sensitivity"|\
1835 sed 's/= /=/'|
sed 's/"/'''/g|cut
-d"=" -f2)
1836 DEFAULTLABEL
=$
(atohexlabel
${deflabel})
1837 intlabel
=$
(chk_encodings
-a|
grep "Default User Clearance"|\
1838 sed 's/= /=/'|
sed 's/"/'''/g|cut
-d"=" -f2)
1839 INTLABEL
=$
(atohexlabel
-c "${intlabel}")
1841 # are there any zfs pools?
1843 zpool iostat
1>/dev
/null
2>&1
1844 if [ $?
= 0 ] ; then
1845 # is there a zfs pool named "zone"?
1846 zpool list
-H zone
1>/dev
/null
2>&1
1847 if [ $?
= 0 ] ; then
1851 # no, but is there a root pool?
1852 rootfs
=$
(df
-n / |
awk '{print $3}')
1853 if [ $rootfs = "zfs" ] ; then
1855 ZDSET
=$
(zfs list
-Ho name
/ | cut
-d/ -f 1)/zones
1856 zfs list
-H $ZDSET 1>/dev
/null
2>&1
1857 if [ $?
= 1 ] ; then
1858 createZDSET
"-o mountpoint=/zone" $ZDSET
1864 if [ $DISP -eq 0 ] ; then
1865 gettext "non-interactive mode ...\n"
1867 if [ $DESTROYZONES -eq 1 ] ; then
1871 if [ $CREATEDEF -eq 1 ] ; then
1872 if [[ $
(zoneadm list
-c) == global
]] ; then
1875 gettext "cannot create default zones because there are existing zones.\n"
1882 if [ $NSCD_PER_LABEL -eq 0 ] ; then
1883 NSCD_OPT
="Configure per-zone name service"
1885 NSCD_OPT
="Unconfigure per-zone name service"