15c51f12Moriah Waterland/*
25c51f12Moriah Waterland * CDDL HEADER START
35c51f12Moriah Waterland *
45c51f12Moriah Waterland * The contents of this file are subject to the terms of the
55c51f12Moriah Waterland * Common Development and Distribution License (the "License").
65c51f12Moriah Waterland * You may not use this file except in compliance with the License.
75c51f12Moriah Waterland *
85c51f12Moriah Waterland * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95c51f12Moriah Waterland * or http://www.opensolaris.org/os/licensing.
105c51f12Moriah Waterland * See the License for the specific language governing permissions
115c51f12Moriah Waterland * and limitations under the License.
125c51f12Moriah Waterland *
135c51f12Moriah Waterland * When distributing Covered Code, include this CDDL HEADER in each
145c51f12Moriah Waterland * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155c51f12Moriah Waterland * If applicable, add the following below this CDDL HEADER, with the
165c51f12Moriah Waterland * fields enclosed by brackets "[]" replaced with your own identifying
175c51f12Moriah Waterland * information: Portions Copyright [yyyy] [name of copyright owner]
185c51f12Moriah Waterland *
195c51f12Moriah Waterland * CDDL HEADER END
205c51f12Moriah Waterland */
215c51f12Moriah Waterland
225c51f12Moriah Waterland/*
236e1ae2aGary Pennington * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
245c51f12Moriah Waterland */
255c51f12Moriah Waterland
265c51f12Moriah Waterland
275c51f12Moriah Waterland/*
285c51f12Moriah Waterland * Module:	zones.c
295c51f12Moriah Waterland * Group:	libinstzones
305c51f12Moriah Waterland * Description:	Provide "zones" interface for install consolidation code
315c51f12Moriah Waterland *
325c51f12Moriah Waterland * Public Methods:
335c51f12Moriah Waterland *  z_create_zone_admin_file - Given a location to create the file, and
345c51f12Moriah Waterland *	optionally an existing administration file, generate an
355c51f12Moriah Waterland *	administration file that can be used to perform "non-interactive"
365c51f12Moriah Waterland *	operations in a non-global zone.
375c51f12Moriah Waterland *  z_free_zone_list - free contents of zoneList_t object
385c51f12Moriah Waterland *  z_get_nonglobal_zone_list - return zoneList_t object describing all
395c51f12Moriah Waterland *	non-global native zones
405c51f12Moriah Waterland *  z_get_nonglobal_zone_list_by_brand - return zoneList_t object describing
415c51f12Moriah Waterland *      all non-global zones matching the list of zone brands passed in.
425c51f12Moriah Waterland *  z_free_brand_list - free contents of a zoneBrandList_t object
435c51f12Moriah Waterland *  z_make_brand_list - return a zoneBrandList_t object describing the list
445c51f12Moriah Waterland *	of all zone brands passed in.
455c51f12Moriah Waterland *  z_get_zonename - return the name of the current zone
465c51f12Moriah Waterland *  z_global_only - Determine if the global zone is only zone on the spec list
475c51f12Moriah Waterland *  z_lock_this_zone - lock this zone
485c51f12Moriah Waterland *  z_lock_zones - lock specified zones
495c51f12Moriah Waterland *  z_mount_in_lz - Mount global zone directory in specified zone's root file
505c51f12Moriah Waterland *	system
515c51f12Moriah Waterland *  z_non_global_zones_exist - Determine if any non-global native zones exist
525c51f12Moriah Waterland *  z_on_zone_spec - Determine if named zone is on the zone_spec list
535c51f12Moriah Waterland *  z_running_in_global_zone - Determine if running in the "global" zone
545c51f12Moriah Waterland *  z_set_output_functions - Link program specific output functions
555c51f12Moriah Waterland *  z_set_zone_root - Set root for zones library operations
565c51f12Moriah Waterland *  z_set_zone_spec - Set list of zones on which actions will be performed
575c51f12Moriah Waterland *  z_umount_lz_mount - Unmount directory mounted with z_mount_in_lz
585c51f12Moriah Waterland *  z_unlock_this_zone - unlock this zone
595c51f12Moriah Waterland *  z_unlock_zones - unlock specified zones
605c51f12Moriah Waterland *  z_verify_zone_spec - Verify list of zones on which actions will be performed
615c51f12Moriah Waterland *  z_zlist_change_zone_state - Change the current state of the specified zone
625c51f12Moriah Waterland *  z_zlist_get_current_state - Determine the current kernel state of the
635c51f12Moriah Waterland *	specified zone
645c51f12Moriah Waterland *  z_zlist_get_original_state - Return the original kernal state of the
655c51f12Moriah Waterland *	specified zone
665c51f12Moriah Waterland *  z_zlist_get_scratch - Determine name of scratch zone
675c51f12Moriah Waterland *  z_zlist_get_zonename - Determine name of specified zone
685c51f12Moriah Waterland *  z_zlist_get_zonepath - Determine zonepath of specified zone
695c51f12Moriah Waterland *  z_zlist_restore_zone_state - Return the zone to the state it was originally
705c51f12Moriah Waterland *	in
715c51f12Moriah Waterland *  z_zone_exec - Execute a Unix command in a specified zone and return results
725c51f12Moriah Waterland *  z_zones_are_implemented - Determine if any zone operations can be performed
735c51f12Moriah Waterland *  z_is_zone_branded - determine if zone has a non-native brand
745c51f12Moriah Waterland *  z_is_zone_brand_in_list - determine if the zone's brand matches the
755c51f12Moriah Waterland *      brand list passed in.
765c51f12Moriah Waterland *  z_brands_are_implemented - determine if branded zones are implemented on
775c51f12Moriah Waterland *			this system
785c51f12Moriah Waterland */
795c51f12Moriah Waterland
805c51f12Moriah Waterland/*
815c51f12Moriah Waterland * System includes
825c51f12Moriah Waterland */
835c51f12Moriah Waterland
845c51f12Moriah Waterland#include <stdio.h>
855c51f12Moriah Waterland#include <stdlib.h>
865c51f12Moriah Waterland#include <unistd.h>
875c51f12Moriah Waterland#include <fcntl.h>
885c51f12Moriah Waterland#include <ctype.h>
895c51f12Moriah Waterland#include <sys/types.h>
905c51f12Moriah Waterland#include <sys/param.h>
915c51f12Moriah Waterland#include <sys/sysmacros.h>
925c51f12Moriah Waterland#include <string.h>
935c51f12Moriah Waterland#include <strings.h>
945c51f12Moriah Waterland#include <sys/stat.h>
955c51f12Moriah Waterland#include <stdarg.h>
965c51f12Moriah Waterland#include <limits.h>
975c51f12Moriah Waterland#include <errno.h>
985c51f12Moriah Waterland#include <time.h>
995c51f12Moriah Waterland#include <signal.h>
1005c51f12Moriah Waterland#include <stropts.h>
1015c51f12Moriah Waterland#include <wait.h>
1025c51f12Moriah Waterland#include <zone.h>
1035c51f12Moriah Waterland#include <sys/brand.h>
1045c51f12Moriah Waterland#include <libintl.h>
1055c51f12Moriah Waterland#include <locale.h>
1065c51f12Moriah Waterland#include <libzonecfg.h>
1075c51f12Moriah Waterland#include <libcontract.h>
1085c51f12Moriah Waterland#include <sys/contract/process.h>
1095c51f12Moriah Waterland#include <sys/ctfs.h>
1105c51f12Moriah Waterland#include <assert.h>
1115c51f12Moriah Waterland#include <dlfcn.h>
1125c51f12Moriah Waterland#include <link.h>
1135c51f12Moriah Waterland#include <time.h>
1145c51f12Moriah Waterland
1155c51f12Moriah Waterland/*
1165c51f12Moriah Waterland * local includes
1175c51f12Moriah Waterland */
1185c51f12Moriah Waterland
1195c51f12Moriah Waterland/*
1205c51f12Moriah Waterland * When _INSTZONES_LIB_Z_DEFINE_GLOBAL_DATA is defined,
1215c51f12Moriah Waterland * instzones_lib.h will define the z_global_data structure.
1225c51f12Moriah Waterland * Otherwise an extern to the structure is inserted.
1235c51f12Moriah Waterland */
1245c51f12Moriah Waterland
1255c51f12Moriah Waterland#define	_INSTZONES_LIB_Z_DEFINE_GLOBAL_DATA
1265c51f12Moriah Waterland#include "instzones_lib.h"
1275c51f12Moriah Waterland#include "zones_strings.h"
1285c51f12Moriah Waterland
1295c51f12Moriah Waterland/*
1305c51f12Moriah Waterland * Private structures
1315c51f12Moriah Waterland */
1325c51f12Moriah Waterland
1335c51f12Moriah Waterland#define	CLUSTER_BRAND_NAME	"cluster"
1345c51f12Moriah Waterland
1355c51f12Moriah Waterland/* maximum number of arguments to exec() call */
1365c51f12Moriah Waterland
1375c51f12Moriah Waterland#define	UUID_FORMAT	"%02d%02d%02d%03d-%02d%02d%02d%d-%016llx"
1385c51f12Moriah Waterland
1395c51f12Moriah Waterland/*
1405c51f12Moriah Waterland * Library Function Prototypes
1415c51f12Moriah Waterland */
1425c51f12Moriah Waterland
1435c51f12Moriah Waterland#define	streq(a, b) (strcmp((a), (b)) == 0)
1445c51f12Moriah Waterland
1455c51f12Moriah Waterland/*
1465c51f12Moriah Waterland * Local Function Prototypes
1475c51f12Moriah Waterland */
1485c51f12Moriah Waterland
1495c51f12Moriah Waterland/*
1505c51f12Moriah Waterland * global internal (private) declarations
1515c51f12Moriah Waterland */
1525c51f12Moriah Waterland
1535c51f12Moriah Waterland/*
1545c51f12Moriah Waterland * *****************************************************************************
1555c51f12Moriah Waterland * global external (public) functions
1565c51f12Moriah Waterland * *****************************************************************************
1575c51f12Moriah Waterland */
1585c51f12Moriah Waterland
1595c51f12Moriah Waterland/*
1605c51f12Moriah Waterland * Name:	z_create_zone_admin_file
1615c51f12Moriah Waterland * Description:	Given a location to create the file, and optionally an existing
1625c51f12Moriah Waterland *		administration file, generate an administration file that
1635c51f12Moriah Waterland *		can be used to perform "non-interactive" operations in a
1645c51f12Moriah Waterland *		non-global zone.
1655c51f12Moriah Waterland * Arguments:	a_zoneAdminFilename - pointer to string representing the
1665c51f12Moriah Waterland *			full path of zone admin file to create
1675c51f12Moriah Waterland *		a_userAdminFilename - pointer to string representing the path
1685c51f12Moriah Waterland *			to an existing "user" administration file - the
1695c51f12Moriah Waterland *			administration file created will contain the
1705c51f12Moriah Waterland *			settings contained in this file, modified as
1715c51f12Moriah Waterland *			appropriate to supress any interaction;
1725c51f12Moriah Waterland *			If this is == NULL then the administration file
1735c51f12Moriah Waterland *			created will not contain any extra settings
1745c51f12Moriah Waterland * Returns:	boolean_t
1755c51f12Moriah Waterland *			== B_TRUE - admin file created
1765c51f12Moriah Waterland *			== B_FALSE - failed to create admin file
1775c51f12Moriah Waterland */
1785c51f12Moriah Waterland
1795c51f12Moriah Waterlandboolean_t
1805c51f12Moriah Waterlandz_create_zone_admin_file(char *a_zoneAdminFilename, char *a_userAdminFilename)
1815c51f12Moriah Waterland{
1825c51f12Moriah Waterland	FILE	*zFp;
1835c51f12Moriah Waterland	FILE	*uFp = (FILE *)NULL;
1845c51f12Moriah Waterland
1855c51f12Moriah Waterland	/* entry assertions */
1865c51f12Moriah Waterland
1875c51f12Moriah Waterland	assert(a_zoneAdminFilename != NULL);
1885c51f12Moriah Waterland	assert(*a_zoneAdminFilename != '\0');
1895c51f12Moriah Waterland
1905c51f12Moriah Waterland	/* create temporary zone admin file */
1915c51f12Moriah Waterland
1925c51f12Moriah Waterland	zFp = fopen(a_zoneAdminFilename, "w");
1935c51f12Moriah Waterland	if (zFp == (FILE *)NULL) {
1945c51f12Moriah Waterland		return (B_FALSE);
1955c51f12Moriah Waterland	}
1965c51f12Moriah Waterland
1975c51f12Moriah Waterland	/* open user admin file if specified */
1985c51f12Moriah Waterland
1995c51f12Moriah Waterland	if (a_userAdminFilename != (char *)NULL) {
2005c51f12Moriah Waterland		uFp = fopen(a_userAdminFilename, "r");
2015c51f12Moriah Waterland	}
2025c51f12Moriah Waterland
2035c51f12Moriah Waterland	/* create default admin file for zone pkg ops if no user admin file */
2045c51f12Moriah Waterland
2055c51f12Moriah Waterland	if (uFp == (FILE *)NULL) {
2065c51f12Moriah Waterland		/* create default admin file */
2075c51f12Moriah Waterland		(void) fprintf(zFp, "action=nocheck\nauthentication=nocheck\n"
2085c51f12Moriah Waterland		    "basedir=default\nconflict=nocheck\nidepend=nocheck\n"
2095c51f12Moriah Waterland		    "instance=unique\npartial=nocheck\nrdepend=nocheck\n"
2105c51f12Moriah Waterland		    "runlevel=nocheck\nsetuid=nocheck\nspace=nocheck\n"
2115c51f12Moriah Waterland		    "mail=\n");
2125c51f12Moriah Waterland	} else for (;;) {
2135c51f12Moriah Waterland		/* copy user admin file substitute/change appropriate entries */
2145c51f12Moriah Waterland		char	buf[LINE_MAX+1];
2155c51f12Moriah Waterland		char	*p;
2165c51f12Moriah Waterland
2175c51f12Moriah Waterland		/* read next line of user admin file */
2185c51f12Moriah Waterland
2195c51f12Moriah Waterland		p = fgets(buf, sizeof (buf), uFp);
2205c51f12Moriah Waterland		if (p == (char *)NULL) {
2215c51f12Moriah Waterland			(void) fclose(uFp);
2225c51f12Moriah Waterland			break;
2235c51f12Moriah Waterland		}
2245c51f12Moriah Waterland
2255c51f12Moriah Waterland		/* modify / replace / accept as appropriate */
2265c51f12Moriah Waterland
2275c51f12Moriah Waterland		if (strncmp(buf, "instance=quit", 13) == 0) {
2285c51f12Moriah Waterland			(void) fprintf(zFp, "%s", "instance=unique\n");
2295c51f12Moriah Waterland			/*LINTED*/
2305c51f12Moriah Waterland		} else if (strncmp(buf, "keystore=", 9) == 0) {
2315c51f12Moriah Waterland		} else if (strncmp(buf, "action=", 7) == 0) {
2325c51f12Moriah Waterland			(void) fprintf(zFp, "action=nocheck\n");
2335c51f12Moriah Waterland		} else if (strncmp(buf, "authentication=", 15) == 0) {
2345c51f12Moriah Waterland			(void) fprintf(zFp, "authentication=nocheck\n");
2355c51f12Moriah Waterland		} else if (strncmp(buf, "conflict=", 9) == 0) {
2365c51f12Moriah Waterland			(void) fprintf(zFp, "conflict=nocheck\n");
2375c51f12Moriah Waterland		} else if (strncmp(buf, "idepend=", 8) == 0) {
2385c51f12Moriah Waterland			(void) fprintf(zFp, "idepend=nocheck\n");
2395c51f12Moriah Waterland		} else if (strncmp(buf, "mail=", 5) == 0) {
2405c51f12Moriah Waterland			(void) fprintf(zFp, "mail=\n");
2415c51f12Moriah Waterland		} else if (strncmp(buf, "partial=", 8) == 0) {
2425c51f12Moriah Waterland			(void) fprintf(zFp, "partial=nocheck\n");
2435c51f12Moriah Waterland		} else if (strncmp(buf, "rdepend=", 8) == 0) {
2445c51f12Moriah Waterland			(void) fprintf(zFp, "rdepend=nocheck\n");
2455c51f12Moriah Waterland		} else if (strncmp(buf, "runlevel=", 9) == 0) {
2465c51f12Moriah Waterland			(void) fprintf(zFp, "runlevel=nocheck\n");
2475c51f12Moriah Waterland		} else if (strncmp(buf, "setuid=", 7) == 0) {
2485c51f12Moriah Waterland			(void) fprintf(zFp, "setuid=nocheck\n");
2495c51f12Moriah Waterland		} else if (strncmp(buf, "space=", 6) == 0) {
2505c51f12Moriah Waterland			(void) fprintf(zFp, "space=nocheck\n");
2515c51f12Moriah Waterland		} else {
2525c51f12Moriah Waterland			(void) fprintf(zFp, "%s", buf);
2535c51f12Moriah Waterland		}
2545c51f12Moriah Waterland	}
2555c51f12Moriah Waterland
2565c51f12Moriah Waterland	/* close admin file and return success */
2575c51f12Moriah Waterland
2585c51f12Moriah Waterland	(void) fclose(zFp);
2595c51f12Moriah Waterland	return (B_TRUE);
2605c51f12Moriah Waterland}
2615c51f12Moriah Waterland
2625c51f12Moriah Waterland/*
2635c51f12Moriah Waterland * Name:	z_brands_are_implemented
2645c51f12Moriah Waterland * Description:	Determine if any branded zones may be present
2655c51f12Moriah Waterland * Arguments:	void
2665c51f12Moriah Waterland * Returns:	boolean_t
2675c51f12Moriah Waterland *			== B_TRUE - branded zones are supported
2685c51f12Moriah Waterland *			== B_FALSE - branded zones are not supported
2695c51f12Moriah Waterland */
2705c51f12Moriah Waterland
2715c51f12Moriah Waterlandboolean_t
2725c51f12Moriah Waterlandz_brands_are_implemented(void)
2735c51f12Moriah Waterland{
2745c51f12Moriah Waterlandstatic	boolean_t	_brandsImplementedDetermined = B_FALSE;
2755c51f12Moriah Waterlandstatic	boolean_t	_brandsAreImplemented = B_FALSE;
2765c51f12Moriah Waterland
2775c51f12Moriah Waterland	/* if availability has not been determined, cache it now */
2785c51f12Moriah Waterland
2795c51f12Moriah Waterland	if (!_brandsImplementedDetermined) {
2805c51f12Moriah Waterland		_brandsImplementedDetermined = B_TRUE;
2815c51f12Moriah Waterland		_brandsAreImplemented = _z_brands_are_implemented();
2825c51f12Moriah Waterland		if (_brandsAreImplemented) {
2835c51f12Moriah Waterland			_z_echoDebug(DBG_BRANDS_ARE_IMPLEMENTED);
2845c51f12Moriah Waterland		} else {
2855c51f12Moriah Waterland			_z_echoDebug(DBG_BRANDS_NOT_IMPLEMENTED);
2865c51f12Moriah Waterland		}
2875c51f12Moriah Waterland	}
2885c51f12Moriah Waterland
2895c51f12Moriah Waterland	/* return cached answer */
2905c51f12Moriah Waterland
2915c51f12Moriah Waterland	return (_brandsAreImplemented);
2925c51f12Moriah Waterland}
2935c51f12Moriah Waterland
2945c51f12Moriah Waterland/*
2955c51f12Moriah Waterland * Name:	z_free_zone_list
2965c51f12Moriah Waterland * Description:	free contents of zoneList_t object
2975c51f12Moriah Waterland * Arguments:	a_zlst - handle to zoneList_t object to free
2985c51f12Moriah Waterland * Returns:	void
2995c51f12Moriah Waterland */
3005c51f12Moriah Waterland
3015c51f12Moriah Waterlandvoid
3025c51f12Moriah Waterlandz_free_zone_list(zoneList_t a_zlst)
3035c51f12Moriah Waterland{
3045c51f12Moriah Waterland	int	numzones;
3055c51f12Moriah Waterland
3065c51f12Moriah Waterland	/* ignore empty list */
3075c51f12Moriah Waterland
3085c51f12Moriah Waterland	if (a_zlst == (zoneList_t)NULL) {
3095c51f12Moriah Waterland		return;
3105c51f12Moriah Waterland	}
3115c51f12Moriah Waterland
3125c51f12Moriah Waterland	/* free each entry in the zone list */
3135c51f12Moriah Waterland
3145c51f12Moriah Waterland	for (numzones = 0; a_zlst[numzones]._zlName != (char *)NULL;
3155c51f12Moriah Waterland	    numzones++) {
3165c51f12Moriah Waterland		zoneListElement_t *zelm = &a_zlst[numzones];
3175c51f12Moriah Waterland
3185c51f12Moriah Waterland		/* free zone name string */
3195c51f12Moriah Waterland
3205c51f12Moriah Waterland		free(zelm->_zlName);
3215c51f12Moriah Waterland
3225c51f12Moriah Waterland		/* free zonepath string */
3235c51f12Moriah Waterland
3245c51f12Moriah Waterland		if (zelm->_zlPath != (char *)NULL) {
3255c51f12Moriah Waterland			free(zelm->_zlPath);
3265c51f12Moriah Waterland		}
3275c51f12Moriah Waterland
3285c51f12Moriah Waterland	}
3295c51f12Moriah Waterland
3305c51f12Moriah Waterland	/* free handle to the list */
3315c51f12Moriah Waterland
3325c51f12Moriah Waterland	free(a_zlst);
3335c51f12Moriah Waterland}
3345c51f12Moriah Waterland
3355c51f12Moriah Waterland/*
3365c51f12Moriah Waterland * Name:	z_get_nonglobal_zone_list
3375c51f12Moriah Waterland * Description: return zoneList_t object describing all non-global
3385c51f12Moriah Waterland *              native zones - branded zones are not included in list
3395c51f12Moriah Waterland * Arguments:	None.
3405c51f12Moriah Waterland * Returns:	zoneList_t
3415c51f12Moriah Waterland *			== NULL - error, list could not be generated
3425c51f12Moriah Waterland *			!= NULL - success, list returned
3435c51f12Moriah Waterland * NOTE:    	Any zoneList_t returned is placed in new storage for the
3445c51f12Moriah Waterland *		calling function. The caller must use 'z_free_zone_list' to
3455c51f12Moriah Waterland *		dispose of the storage once the list is no longer needed.
3465c51f12Moriah Waterland */
3475c51f12Moriah Waterland
3485c51f12Moriah WaterlandzoneList_t
3495c51f12Moriah Waterlandz_get_nonglobal_zone_list(void)
3505c51f12Moriah Waterland{
3515c51f12Moriah Waterland	zoneList_t zones;
3525c51f12Moriah Waterland	zoneBrandList_t *brands = NULL;
3535c51f12Moriah Waterland
3545c51f12Moriah Waterland	if ((brands = z_make_brand_list("native cluster", " ")) == NULL)
3555c51f12Moriah Waterland		return (NULL);
3565c51f12Moriah Waterland
3575c51f12Moriah Waterland	zones = z_get_nonglobal_zone_list_by_brand(brands);
3585c51f12Moriah Waterland
3595c51f12Moriah Waterland	z_free_brand_list(brands);
3605c51f12Moriah Waterland
3615c51f12Moriah Waterland	return (zones);
3625c51f12Moriah Waterland}
3635c51f12Moriah Waterland
3645c51f12Moriah Waterland/*
3655c51f12Moriah Waterland * Name:	z_free_brand_list
3665c51f12Moriah Waterland * Description: Free contents of zoneBrandList_t object
3675c51f12Moriah Waterland * Arguments:	brands - pointer to zoneBrandList_t object to free
3685c51f12Moriah Waterland * Returns: 	void
3695c51f12Moriah Waterland */
3705c51f12Moriah Waterlandvoid
3715c51f12Moriah Waterlandz_free_brand_list(zoneBrandList_t *brands)
3725c51f12Moriah Waterland{
3735c51f12Moriah Waterland	while (brands != NULL) {
3745c51f12Moriah Waterland		zoneBrandList_t *temp = brands;
3755c51f12Moriah Waterland		free(brands->string_ptr);
3765c51f12Moriah Waterland		brands = brands->next;
3775c51f12Moriah Waterland		free(temp);
3785c51f12Moriah Waterland	}
3795c51f12Moriah Waterland}
3805c51f12Moriah Waterland
3815c51f12Moriah Waterland/*
3825c51f12Moriah Waterland * Name:	z_make_brand_list
3835c51f12Moriah Waterland * Description:	Given a string with a list of brand name delimited by
3845c51f12Moriah Waterland *		the delimeter passed in, build a zoneBrandList_t structure
3855c51f12Moriah Waterland *		with the list of brand names and return it to the caller.
3865c51f12Moriah Waterland * Arguments:
3875c51f12Moriah Waterland *		brands - const char pointer to string list of brand names
3885c51f12Moriah Waterland *		delim - const char pointer to string representing the
3895c51f12Moriah Waterland *			delimeter for brands string.
3905c51f12Moriah Waterland * Returns:	zoneBrandList_t *
3915c51f12Moriah Waterland *			== NULL - error, list could not be generated
3925c51f12Moriah Waterland *			!= NULL - success, list returned
3935c51f12Moriah Waterland * NOTE:	Any zoneBrandList_t returned is placed in new storage for the
3945c51f12Moriah Waterland *		calling function.  The caller must use 'z_free_brand_list' to
3955c51f12Moriah Waterland *		dispose of the storage once the list is no longer needed.
3965c51f12Moriah Waterland */
3975c51f12Moriah WaterlandzoneBrandList_t *
3985c51f12Moriah Waterlandz_make_brand_list(const char *brands, const char *delim)
3995c51f12Moriah Waterland{
4005c51f12Moriah Waterland	zoneBrandList_t *brand = NULL, *head = NULL;
4015c51f12Moriah Waterland	char		*blist = NULL;
4025c51f12Moriah Waterland	char		*str = NULL;
4035c51f12Moriah Waterland
4045c51f12Moriah Waterland	if ((blist = strdup(brands)) == NULL)
4055c51f12Moriah Waterland		return (NULL);
4065c51f12Moriah Waterland
4075c51f12Moriah Waterland	if ((str = strtok(blist, delim)) != NULL) {
4085c51f12Moriah Waterland		if ((brand = (zoneBrandList_t *)
4095c51f12Moriah Waterland		    malloc(sizeof (struct _zoneBrandList))) == NULL) {
4105c51f12Moriah Waterland			return (NULL);
4115c51f12Moriah Waterland		}
4125c51f12Moriah Waterland
4135c51f12Moriah Waterland		head = brand;
4145c51f12Moriah Waterland		brand->string_ptr = strdup(str);
4155c51f12Moriah Waterland		brand->next = NULL;
4165c51f12Moriah Waterland
4175c51f12Moriah Waterland		while ((str = strtok(NULL, delim)) != NULL) {
4185c51f12Moriah Waterland			if ((brand->next = (zoneBrandList_t *)
4195c51f12Moriah Waterland			    malloc(sizeof (struct _zoneBrandList))) == NULL) {
4205c51f12Moriah Waterland				return (NULL);
4215c51f12Moriah Waterland			}
4225c51f12Moriah Waterland
4235c51f12Moriah Waterland			brand = brand->next;
4245c51f12Moriah Waterland			brand->string_ptr = strdup(str);
4255c51f12Moriah Waterland			brand->next = NULL;
4265c51f12Moriah Waterland		}
4275c51f12Moriah Waterland	}
4285c51f12Moriah Waterland
4295c51f12Moriah Waterland	free(blist);
4305c51f12Moriah Waterland	return (head);
4315c51f12Moriah Waterland}
4325c51f12Moriah Waterland
4335c51f12Moriah Waterland/*
4345c51f12Moriah Waterland * Name:	z_get_nonglobal_zone_list_by_brand
4355c51f12Moriah Waterland * Description: return zoneList_t object describing all non-global
4365c51f12Moriah Waterland *              zones matching the list of brands passed in.
4375c51f12Moriah Waterland * Arguments:	brands - The list of zone brands to look for.
4385c51f12Moriah Waterland * Returns:	zoneList_t
4395c51f12Moriah Waterland *			== NULL - error, list could not be generated
4405c51f12Moriah Waterland *			!= NULL - success, list returned
4415c51f12Moriah Waterland * NOTE:    	Any zoneList_t returned is placed in new storage for the
4425c51f12Moriah Waterland *		calling function. The caller must use 'z_free_zone_list' to
4435c51f12Moriah Waterland *		dispose of the storage once the list is no longer needed.
4445c51f12Moriah Waterland */
4455c51f12Moriah WaterlandzoneList_t
4465c51f12Moriah Waterlandz_get_nonglobal_zone_list_by_brand(zoneBrandList_t *brands)
4475c51f12Moriah Waterland{
4485c51f12Moriah Waterland	FILE		*zoneIndexFP;
4495c51f12Moriah Waterland	int		numzones = 0;
4505c51f12Moriah Waterland	struct zoneent	*ze;
4515c51f12Moriah Waterland	zoneList_t	zlst = NULL;
4525c51f12Moriah Waterland	FILE		*mapFP;
4535c51f12Moriah Waterland	char		zonename[ZONENAME_MAX];
4545c51f12Moriah Waterland	zone_spec_t	*zent;
4555c51f12Moriah Waterland
4565c51f12Moriah Waterland	/* if zones are not implemented, return empty list */
4575c51f12Moriah Waterland
4585c51f12Moriah Waterland	if (!z_zones_are_implemented()) {
4595c51f12Moriah Waterland		return ((zoneList_t)NULL);
4605c51f12Moriah Waterland	}
4615c51f12Moriah Waterland
4625c51f12Moriah Waterland	/*
4635c51f12Moriah Waterland	 * Open the zone index file.  Note that getzoneent_private() handles
4645c51f12Moriah Waterland	 * NULL.
4655c51f12Moriah Waterland	 */
4665c51f12Moriah Waterland	zoneIndexFP = setzoneent();
4675c51f12Moriah Waterland
4685c51f12Moriah Waterland	mapFP = zonecfg_open_scratch("", B_FALSE);
4695c51f12Moriah Waterland
4705c51f12Moriah Waterland	/* index file open; scan all zones; see if any are at least installed */
4715c51f12Moriah Waterland
4725c51f12Moriah Waterland	while ((ze = getzoneent_private(zoneIndexFP)) != NULL) {
4735c51f12Moriah Waterland		zone_state_t	st;
4745c51f12Moriah Waterland
4755c51f12Moriah Waterland		/* skip the global zone */
4765c51f12Moriah Waterland
4775c51f12Moriah Waterland		if (strcmp(ze->zone_name, GLOBAL_ZONENAME) == 0) {
4785c51f12Moriah Waterland			free(ze);
4795c51f12Moriah Waterland			continue;
4805c51f12Moriah Waterland		}
4815c51f12Moriah Waterland
4825c51f12Moriah Waterland		/*
4835c51f12Moriah Waterland		 * skip any zones with brands not on the brand list
4845c51f12Moriah Waterland		 */
4855c51f12Moriah Waterland		if (!z_is_zone_brand_in_list(ze->zone_name, brands)) {
4865c51f12Moriah Waterland			free(ze);
4875c51f12Moriah Waterland			continue;
4885c51f12Moriah Waterland		}
4895c51f12Moriah Waterland
4905c51f12Moriah Waterland		/*
4915c51f12Moriah Waterland		 * If the user specified an explicit zone list, then ignore any
4925c51f12Moriah Waterland		 * zones that aren't on that list.
4935c51f12Moriah Waterland		 */
4945c51f12Moriah Waterland		if ((zent = _z_global_data._zone_spec) != NULL) {
4955c51f12Moriah Waterland			while (zent != NULL) {
4965c51f12Moriah Waterland				if (strcmp(zent->zl_name, ze->zone_name) == 0)
4975c51f12Moriah Waterland					break;
4985c51f12Moriah Waterland				zent = zent->zl_next;
4995c51f12Moriah Waterland			}
5005c51f12Moriah Waterland			if (zent == NULL) {
5015c51f12Moriah Waterland				free(ze);
5025c51f12Moriah Waterland				continue;
5035c51f12Moriah Waterland			}
5045c51f12Moriah Waterland		}
5055c51f12Moriah Waterland
5065c51f12Moriah Waterland		/* non-global zone: create entry for this zone */
5075c51f12Moriah Waterland
5085c51f12Moriah Waterland		if (numzones == 0) {
5095c51f12Moriah Waterland			zlst = (zoneList_t)_z_calloc(
5105c51f12Moriah Waterland			    sizeof (zoneListElement_t)*2);
5115c51f12Moriah Waterland		} else {
5125c51f12Moriah Waterland			zlst = (zoneList_t)_z_realloc(zlst,
5135c51f12Moriah Waterland			    sizeof (zoneListElement_t)*(numzones+2));
5145c51f12Moriah Waterland			(void) memset(&zlst[numzones], 0L,
5155c51f12Moriah Waterland			    sizeof (zoneListElement_t)*2);
5165c51f12Moriah Waterland		}
5175c51f12Moriah Waterland
5185c51f12Moriah Waterland		/*
5195c51f12Moriah Waterland		 * remember the zone name, zonepath and the current
5205c51f12Moriah Waterland		 * zone state of the zone.
5215c51f12Moriah Waterland		 */
5225c51f12Moriah Waterland		zlst[numzones]._zlName = _z_strdup(ze->zone_name);
5235c51f12Moriah Waterland		zlst[numzones]._zlPath = _z_strdup(ze->zone_path);
5245c51f12Moriah Waterland		zlst[numzones]._zlOrigInstallState = ze->zone_state;
5255c51f12Moriah Waterland		zlst[numzones]._zlCurrInstallState = ze->zone_state;
5265c51f12Moriah Waterland
5275c51f12Moriah Waterland		/* get the zone kernel status */
5285c51f12Moriah Waterland
5295c51f12Moriah Waterland		if (zone_get_state(ze->zone_name, &st) != Z_OK) {
5305c51f12Moriah Waterland			st = ZONE_STATE_INCOMPLETE;
5315c51f12Moriah Waterland		}
5325c51f12Moriah Waterland
5335c51f12Moriah Waterland		_z_echoDebug(DBG_ZONES_NGZ_LIST_STATES,
5345c51f12Moriah Waterland		    ze->zone_name, ze->zone_state, st);
5355c51f12Moriah Waterland
5365c51f12Moriah Waterland		/*
5375c51f12Moriah Waterland		 * For a scratch zone, we need to know the kernel zone name.
5385c51f12Moriah Waterland		 */
5395c51f12Moriah Waterland		if (zonecfg_in_alt_root() && mapFP != NULL &&
5405c51f12Moriah Waterland		    zonecfg_find_scratch(mapFP, ze->zone_name,
5415c51f12Moriah Waterland		    zonecfg_get_root(), zonename, sizeof (zonename)) != -1) {
5425c51f12Moriah Waterland			free(zlst[numzones]._zlScratchName);
5435c51f12Moriah Waterland			zlst[numzones]._zlScratchName = _z_strdup(zonename);
5445c51f12Moriah Waterland		}
5455c51f12Moriah Waterland
5465c51f12Moriah Waterland		/*
5475c51f12Moriah Waterland		 * remember the current kernel status of the zone.
5485c51f12Moriah Waterland		 */
5495c51f12Moriah Waterland
5505c51f12Moriah Waterland		zlst[numzones]._zlOrigKernelStatus = st;
5515c51f12Moriah Waterland		zlst[numzones]._zlCurrKernelStatus = st;
5525c51f12Moriah Waterland
5535c51f12Moriah Waterland		numzones++;
5545c51f12Moriah Waterland		free(ze);
5555c51f12Moriah Waterland	}
5565c51f12Moriah Waterland
5575c51f12Moriah Waterland	/* close the index file */
5585c51f12Moriah Waterland	endzoneent(zoneIndexFP);
5595c51f12Moriah Waterland
5605c51f12Moriah Waterland	if (mapFP != NULL)
5615c51f12Moriah Waterland		zonecfg_close_scratch(mapFP);
5625c51f12Moriah Waterland
5635c51f12Moriah Waterland	/* return generated list */
5645c51f12Moriah Waterland
5655c51f12Moriah Waterland	return (zlst);
5665c51f12Moriah Waterland}
5675c51f12Moriah Waterland
5685c51f12Moriah Waterland/*
5695c51f12Moriah Waterland * Name:	z_get_zonename
5705c51f12Moriah Waterland * Description:	return the name of the current zone
5715c51f12Moriah Waterland * Arguments:	void
5725c51f12Moriah Waterland * Returns:	char *
5735c51f12Moriah Waterland *			- pointer to string representing the name of the current
5745c51f12Moriah Waterland *			zone
5755c51f12Moriah Waterland * NOTE:    	Any string returned is placed in new storage for the
5765c51f12Moriah Waterland *		calling function. The caller must use 'Free' to dispose
5775c51f12Moriah Waterland *		of the storage once the string is no longer needed.
5785c51f12Moriah Waterland */
5795c51f12Moriah Waterland
5805c51f12Moriah Waterlandchar *
5815c51f12Moriah Waterlandz_get_zonename(void)
5825c51f12Moriah Waterland{
5835c51f12Moriah Waterland	ssize_t		zonenameLen;
5845c51f12Moriah Waterland	char		zonename[ZONENAME_MAX];
5855c51f12Moriah Waterland	zoneid_t	zoneid = (zoneid_t)-1;
5865c51f12Moriah Waterland
5875c51f12Moriah Waterland	/* if zones are not implemented, return "" */
5885c51f12Moriah Waterland
5895c51f12Moriah Waterland	if (!z_zones_are_implemented()) {
5905c51f12Moriah Waterland		return (_z_strdup(""));
5915c51f12Moriah Waterland	}
5925c51f12Moriah Waterland
5935c51f12Moriah Waterland	/* get the zone i.d. of the current zone */
5945c51f12Moriah Waterland
5955c51f12Moriah Waterland	zoneid = getzoneid();
5965c51f12Moriah Waterland
5975c51f12Moriah Waterland	/* get the name of the current zone */
5985c51f12Moriah Waterland
5995c51f12Moriah Waterland	zonenameLen = getzonenamebyid(zoneid, zonename, sizeof (zonename));
6005c51f12Moriah Waterland
6015c51f12Moriah Waterland	/* return "" if could not get zonename */
6025c51f12Moriah Waterland
6035c51f12Moriah Waterland	if (zonenameLen < 1) {
6045c51f12Moriah Waterland		return (_z_strdup(""));
6055c51f12Moriah Waterland	}
6065c51f12Moriah Waterland
6075c51f12Moriah Waterland	return (_z_strdup(zonename));
6085c51f12Moriah Waterland}
6095c51f12Moriah Waterland
6105c51f12Moriah Waterland/*
6115c51f12Moriah Waterland * Name:	z_global_only
6125c51f12Moriah Waterland * Description:	Determine if the global zone is only zone on the spec list.
6135c51f12Moriah Waterland * Arguments:	None
6145c51f12Moriah Waterland * Returns:	B_TRUE if global zone is the only zone on the list,
6155c51f12Moriah Waterland *		B_FALSE otherwise.
6165c51f12Moriah Waterland */
6175c51f12Moriah Waterland
6185c51f12Moriah Waterlandboolean_t
6195c51f12Moriah Waterlandz_global_only(void)
6205c51f12Moriah Waterland{
6215c51f12Moriah Waterland	/* return true if zones are not implemented - treate as global zone */
6225c51f12Moriah Waterland
6235c51f12Moriah Waterland	if (!z_zones_are_implemented()) {
6245c51f12Moriah Waterland		return (B_TRUE);
6255c51f12Moriah Waterland	}
6265c51f12Moriah Waterland
6275c51f12Moriah Waterland	/* return true if this is the global zone */
6285c51f12Moriah Waterland
6295c51f12Moriah Waterland	if (_z_global_data._zone_spec != NULL &&
6305c51f12Moriah Waterland	    _z_global_data._zone_spec->zl_next == NULL &&
6315c51f12Moriah Waterland	    strcmp(_z_global_data._zone_spec->zl_name, GLOBAL_ZONENAME) == 0) {
6325c51f12Moriah Waterland		return (B_TRUE);
6335c51f12Moriah Waterland	}
6345c51f12Moriah Waterland
6355c51f12Moriah Waterland	/* return false - not the global zone */
6365c51f12Moriah Waterland
6375c51f12Moriah Waterland	return (B_FALSE);
6385c51f12Moriah Waterland}
6395c51f12Moriah Waterland
6405c51f12Moriah Waterland/*
6415c51f12Moriah Waterland * Name:	z_lock_this_zone
6425c51f12Moriah Waterland * Description:	lock this zone
6435c51f12Moriah Waterland * Arguments:	a_lflags - [RO, *RO] - (ZLOCKS_T)
6445c51f12Moriah Waterland *			Flags indicating which locks to acquire
6455c51f12Moriah Waterland * Returns:	boolean_t
6465c51f12Moriah Waterland *			== B_TRUE - success specified locks acquired
6475c51f12Moriah Waterland *			== B_FALSE - failure specified locks not acquired
6485c51f12Moriah Waterland * NOTE: the lock objects for "this zone" are maintained internally.
6495c51f12Moriah Waterland */
6505c51f12Moriah Waterland
6515c51f12Moriah Waterlandboolean_t
6525c51f12Moriah Waterlandz_lock_this_zone(ZLOCKS_T a_lflags)
6535c51f12Moriah Waterland{
6545c51f12Moriah Waterland	boolean_t	b;
6555c51f12Moriah Waterland	char		*zoneName;
6565c51f12Moriah Waterland	pid_t		pid = (pid_t)0;
6575c51f12Moriah Waterland
6585c51f12Moriah Waterland	/* entry assertions */
6595c51f12Moriah Waterland
6605c51f12Moriah Waterland	assert(a_lflags != ZLOCKS_NONE);
6615c51f12Moriah Waterland
6625c51f12Moriah Waterland	/* entry debugging info */
6635c51f12Moriah Waterland
6645c51f12Moriah Waterland	_z_echoDebug(DBG_ZONES_LCK_THIS, a_lflags);
6655c51f12Moriah Waterland
6665c51f12Moriah Waterland	zoneName = z_get_zonename();
6675c51f12Moriah Waterland	pid = getpid();
6685c51f12Moriah Waterland
6695c51f12Moriah Waterland	/* lock zone administration */
6705c51f12Moriah Waterland
6715c51f12Moriah Waterland	if (a_lflags & ZLOCKS_ZONE_ADMIN) {
6725c51f12Moriah Waterland		b = _z_lock_zone_object(&_z_global_data._z_ObjectLocks,
6735c51f12Moriah Waterland		    zoneName, LOBJ_ZONEADMIN, pid,
6745c51f12Moriah Waterland		    MSG_ZONES_LCK_THIS_ZONEADM,
6755c51f12Moriah Waterland		    ERR_ZONES_LCK_THIS_ZONEADM);
6765c51f12Moriah Waterland		if (!b) {
6775c51f12Moriah Waterland			(void) free(zoneName);
6785c51f12Moriah Waterland			return (B_FALSE);
6795c51f12Moriah Waterland		}
6805c51f12Moriah Waterland	}
6815c51f12Moriah Waterland
6825c51f12Moriah Waterland	/* lock package administration always */
6835c51f12Moriah Waterland
6845c51f12Moriah Waterland	if (a_lflags & ZLOCKS_PKG_ADMIN) {
6855c51f12Moriah Waterland		b = _z_lock_zone_object(&_z_global_data._z_ObjectLocks,
6865c51f12Moriah Waterland		    zoneName, LOBJ_PKGADMIN, pid,
6875c51f12Moriah Waterland		    MSG_ZONES_LCK_THIS_PKGADM,
6885c51f12Moriah Waterland		    ERR_ZONES_LCK_THIS_PKGADM);
6895c51f12Moriah Waterland		if (!b) {
6905c51f12Moriah Waterland			(void) z_unlock_this_zone(a_lflags);
6915c51f12Moriah Waterland			(void) free(zoneName);
6925c51f12Moriah Waterland			return (B_FALSE);
6935c51f12Moriah Waterland		}
6945c51f12Moriah Waterland	}
6955c51f12Moriah Waterland
6965c51f12Moriah Waterland	(void) free(zoneName);
6975c51f12Moriah Waterland
6985c51f12Moriah Waterland	return (B_TRUE);
6995c51f12Moriah Waterland}
7005c51f12Moriah Waterland
7015c51f12Moriah Waterland/*
7025c51f12Moriah Waterland * Name:	z_lock_zones
7035c51f12Moriah Waterland * Description:	lock specified zones
7045c51f12Moriah Waterland * Arguments:	a_zlst - zoneList_t object describing zones to lock
7055c51f12Moriah Waterland *		a_lflags - [RO, *RO] - (ZLOCKS_T)
7065c51f12Moriah Waterland *			Flags indicating which locks to acquire
7075c51f12Moriah Waterland * Returns:	boolean_t
7085c51f12Moriah Waterland *			== B_TRUE - success, zones locked
7095c51f12Moriah Waterland *			== B_FALSE - failure, zones not locked
7105c51f12Moriah Waterland */
7115c51f12Moriah Waterland
7125c51f12Moriah Waterlandboolean_t
7135c51f12Moriah Waterlandz_lock_zones(zoneList_t a_zlst, ZLOCKS_T a_lflags)
7145c51f12Moriah Waterland{
7155c51f12Moriah Waterland	boolean_t	b;
7165c51f12Moriah Waterland	int		i;
7175c51f12Moriah Waterland
7185c51f12Moriah Waterland	/* entry assertions */
7195c51f12Moriah Waterland
7205c51f12Moriah Waterland	assert(a_lflags != ZLOCKS_NONE);
7215c51f12Moriah Waterland
7225c51f12Moriah Waterland	/* entry debugging info */
7235c51f12Moriah Waterland
7245c51f12Moriah Waterland	_z_echoDebug(DBG_ZONES_LCK_ZONES, a_lflags);
7255c51f12Moriah Waterland
7265c51f12Moriah Waterland	/* if zones are not implemented, return TRUE */
7275c51f12Moriah Waterland
7285c51f12Moriah Waterland	if (z_zones_are_implemented() == B_FALSE) {
7295c51f12Moriah Waterland		_z_echoDebug(DBG_ZONES_LCK_ZONES_UNIMP);
7305c51f12Moriah Waterland		return (B_TRUE);
7315c51f12Moriah Waterland	}
7325c51f12Moriah Waterland
7335c51f12Moriah Waterland	/* lock this zone first before locking other zones */
7345c51f12Moriah Waterland
7355c51f12Moriah Waterland	b = z_lock_this_zone(a_lflags);
7365c51f12Moriah Waterland	if (b == B_FALSE) {
7375c51f12Moriah Waterland		return (b);
7385c51f12Moriah Waterland	}
7395c51f12Moriah Waterland
7405c51f12Moriah Waterland	/* ignore empty list */
7415c51f12Moriah Waterland
7425c51f12Moriah Waterland	if (a_zlst == (zoneList_t)NULL) {
7435c51f12Moriah Waterland		_z_echoDebug(DBG_ZONES_LCK_ZONES_NOZONES);
7445c51f12Moriah Waterland		return (B_FALSE);
7455c51f12Moriah Waterland	}
7465c51f12Moriah Waterland
7475c51f12Moriah Waterland	/* zones exist */
7485c51f12Moriah Waterland
7495c51f12Moriah Waterland	_z_echoDebug(DBG_ZONES_LCK_ZONES_EXIST);
7505c51f12Moriah Waterland
7515c51f12Moriah Waterland	/*
7525c51f12Moriah Waterland	 * lock each listed zone that is currently running
7535c51f12Moriah Waterland	 */
7545c51f12Moriah Waterland
7555c51f12Moriah Waterland	for (i = 0; (a_zlst[i]._zlName != (char *)NULL); i++) {
7565c51f12Moriah Waterland		/* ignore zone if already locked */
7575c51f12Moriah Waterland		if (a_zlst[i]._zlStatus & ZST_LOCKED) {
7585c51f12Moriah Waterland			continue;
7595c51f12Moriah Waterland		}
7605c51f12Moriah Waterland
7615c51f12Moriah Waterland		/* ignore zone if not running */
7625c51f12Moriah Waterland		if (a_zlst[i]._zlCurrKernelStatus != ZONE_STATE_RUNNING &&
7635c51f12Moriah Waterland		    a_zlst[i]._zlCurrKernelStatus != ZONE_STATE_MOUNTED) {
7645c51f12Moriah Waterland			continue;
7655c51f12Moriah Waterland		}
7665c51f12Moriah Waterland
7675c51f12Moriah Waterland		/*
7685c51f12Moriah Waterland		 * mark zone locked - if interrupted out during lock, an attempt
7695c51f12Moriah Waterland		 * will be made to release the lock
7705c51f12Moriah Waterland		 */
7715c51f12Moriah Waterland		a_zlst[i]._zlStatus |= ZST_LOCKED;
7725c51f12Moriah Waterland
7735c51f12Moriah Waterland		/* lock this zone */
7745c51f12Moriah Waterland		b = _z_lock_zone(&a_zlst[i], a_lflags);
7755c51f12Moriah Waterland
7765c51f12Moriah Waterland		/* on failure unlock all zones and return error */
7775c51f12Moriah Waterland		if (b != B_TRUE) {
7785c51f12Moriah Waterland			_z_program_error(ERR_ZONES_LCK_ZONES_FAILED,
7795c51f12Moriah Waterland			    a_zlst[i]._zlName);
7805c51f12Moriah Waterland			(void) z_unlock_zones(a_zlst, a_lflags);
7815c51f12Moriah Waterland			return (B_FALSE);
7825c51f12Moriah Waterland		}
7835c51f12Moriah Waterland	}
7845c51f12Moriah Waterland
7855c51f12Moriah Waterland	/* success */
7865c51f12Moriah Waterland
7875c51f12Moriah Waterland	return (B_TRUE);
7885c51f12Moriah Waterland}
7895c51f12Moriah Waterland
7905c51f12Moriah Waterland/*
7915c51f12Moriah Waterland * Name:	z_mount_in_lz
7925c51f12Moriah Waterland * Description:	Mount global zone directory in specified zone's root file system
7935c51f12Moriah Waterland * Arguments:	r_lzMountPoint - pointer to handle to string - on success, the
7945c51f12Moriah Waterland *			full path to the mount point relative to the global zone
7955c51f12Moriah Waterland *			root file system is returned here - this is needed to
7965c51f12Moriah Waterland *			unmount the directory when it is no longer needed
7975c51f12Moriah Waterland *		r_lzRootPath - pointer to handle to string - on success, the
7985c51f12Moriah Waterland *			full path to the mount point relative to the specified
7995c51f12Moriah Waterland *			zone's root file system is returned here - this is
8005c51f12Moriah Waterland *			passed to any command executing in the specified zone to
8015c51f12Moriah Waterland *			access the directory mounted
8025c51f12Moriah Waterland *		a_zoneName - pointer to string representing the name of the zone
8035c51f12Moriah Waterland *			to mount the specified global zone directory in
8045c51f12Moriah Waterland *		a_gzPath - pointer to string representing the full absolute path
8055c51f12Moriah Waterland *			of the global zone directory to LOFS mount inside of the
8065c51f12Moriah Waterland *			specified non-global zone
8075c51f12Moriah Waterland *		a_mountPointPrefix - pointer to string representing the prefix
8085c51f12Moriah Waterland *			to be used when creating the mount point name in the
8095c51f12Moriah Waterland *			specified zone's root directory
8105c51f12Moriah Waterland * Returns:	boolean_t
8115c51f12Moriah Waterland *			== B_TRUE - global zone directory mounted successfully
8125c51f12Moriah Waterland *			== B_FALSE - failed to mount directory in specified zone
8135c51f12Moriah Waterland * NOTE:    	Any strings returned is placed in new storage for the
8145c51f12Moriah Waterland *		calling function. The caller must use 'Free' to dispose
8155c51f12Moriah Waterland *		of the storage once the strings are no longer needed.
8165c51f12Moriah Waterland */
8175c51f12Moriah Waterland
8185c51f12Moriah Waterlandboolean_t
8195c51f12Moriah Waterlandz_mount_in_lz(char **r_lzMountPoint, char **r_lzRootPath, char *a_zoneName,
8205c51f12Moriah Waterland	char *a_gzPath, char *a_mountPointPrefix)
8215c51f12Moriah Waterland{
8225c51f12Moriah Waterland	char		lzRootPath[MAXPATHLEN] = {'\0'};
8235c51f12Moriah Waterland	char		uuid[MAXPATHLEN] = {'\0'};
8245c51f12Moriah Waterland	char		gzMountPoint[MAXPATHLEN] = {'\0'};
8255c51f12Moriah Waterland	char		lzMountPoint[MAXPATHLEN] = {'\0'};
8265c51f12Moriah Waterland	hrtime_t	hretime;
8275c51f12Moriah Waterland	int		err;
8285c51f12Moriah Waterland	int		slen;
8295c51f12Moriah Waterland	struct tm	tstruct;
8305c51f12Moriah Waterland	time_t		thetime;
8315c51f12Moriah Waterland	zoneid_t	zid;
8325c51f12Moriah Waterland
8335c51f12Moriah Waterland	/* entry assertions */
8345c51f12Moriah Waterland
8355c51f12Moriah Waterland	assert(a_zoneName != (char *)NULL);
8365c51f12Moriah Waterland	assert(*a_zoneName != '\0');
8375c51f12Moriah Waterland	assert(a_gzPath != (char *)NULL);
8385c51f12Moriah Waterland	assert(*a_gzPath != '\0');
8395c51f12Moriah Waterland	assert(r_lzMountPoint != (char **)NULL);
8405c51f12Moriah Waterland	assert(r_lzRootPath != (char **)NULL);
8415c51f12Moriah Waterland
8425c51f12Moriah Waterland	/* entry debugging info */
8435c51f12Moriah Waterland
8445c51f12Moriah Waterland	_z_echoDebug(DBG_ZONES_MOUNT_IN_LZ_ENTRY, a_zoneName, a_gzPath);
8455c51f12Moriah Waterland
8465c51f12Moriah Waterland	/* reset returned non-global zone mount point path handle */
8475c51f12Moriah Waterland
8485c51f12Moriah Waterland	*r_lzMountPoint = (char *)NULL;
8495c51f12Moriah Waterland	*r_lzRootPath = (char *)NULL;
8505c51f12Moriah Waterland
8515c51f12Moriah Waterland	/* if zones are not implemented, return FALSE */
8525c51f12Moriah Waterland
8535c51f12Moriah Waterland	if (z_zones_are_implemented() == B_FALSE) {
8545c51f12Moriah Waterland		return (B_FALSE);
8555c51f12Moriah Waterland	}
8565c51f12Moriah Waterland
8575c51f12Moriah Waterland	/* error if global zone path is not absolute */
8585c51f12Moriah Waterland
8595c51f12Moriah Waterland	if (*a_gzPath != '/') {
8605c51f12Moriah Waterland		_z_program_error(ERR_GZPATH_NOT_ABSOLUTE, a_gzPath);
8615c51f12Moriah Waterland		return (B_FALSE);
8625c51f12Moriah Waterland	}
8635c51f12Moriah Waterland
8645c51f12Moriah Waterland	/* error if global zone path does not exist */
8655c51f12Moriah Waterland
8665c51f12Moriah Waterland	if (_z_is_directory(a_gzPath) != 0) {
8675c51f12Moriah Waterland		_z_program_error(ERR_GZPATH_NOT_DIR, a_gzPath, strerror(errno));
8685c51f12Moriah Waterland		return (B_FALSE);
8695c51f12Moriah Waterland	}
8705c51f12Moriah Waterland
8715c51f12Moriah Waterland	/* verify that specified non-global zone exists */
8725c51f12Moriah Waterland
8735c51f12Moriah Waterland	err = zone_get_id(a_zoneName, &zid);
8745c51f12Moriah Waterland	if (err != Z_OK) {
8755c51f12Moriah Waterland		_z_program_error(ERR_GET_ZONEID, a_zoneName,
8765c51f12Moriah Waterland		    zonecfg_strerror(err));
8775c51f12Moriah Waterland		return (B_FALSE);
8785c51f12Moriah Waterland	}
8795c51f12Moriah Waterland
8805c51f12Moriah Waterland	/* obtain global zone path to non-global zones root file system */
8815c51f12Moriah Waterland
8825c51f12Moriah Waterland	err = zone_get_rootpath(a_zoneName, lzRootPath, sizeof (lzRootPath));
8835c51f12Moriah Waterland	if (err != Z_OK) {
8845c51f12Moriah Waterland		_z_program_error(ERR_NO_ZONE_ROOTPATH, a_zoneName,
8855c51f12Moriah Waterland		    zonecfg_strerror(err));
8865c51f12Moriah Waterland		return (B_FALSE);
8875c51f12Moriah Waterland	}
8885c51f12Moriah Waterland
8895c51f12Moriah Waterland	if (lzRootPath[0] == '\0') {
8905c51f12Moriah Waterland		_z_program_error(ERR_ROOTPATH_EMPTY, a_zoneName);
8915c51f12Moriah Waterland		return (B_FALSE);
8925c51f12Moriah Waterland	}
8935c51f12Moriah Waterland
8945c51f12Moriah Waterland	/*
8955c51f12Moriah Waterland	 * lofs resolve the non-global zone's root path first in case
8965c51f12Moriah Waterland	 * its in a path that's been lofs mounted read-only.
8975c51f12Moriah Waterland	 */
8985c51f12Moriah Waterland	z_resolve_lofs(lzRootPath, sizeof (lzRootPath));
8995c51f12Moriah Waterland
9005c51f12Moriah Waterland	/* verify that the root path exists */
9015c51f12Moriah Waterland
9025c51f12Moriah Waterland	if (_z_is_directory(lzRootPath) != 0) {
9035c51f12Moriah Waterland		_z_program_error(ERR_LZROOT_NOTDIR, lzRootPath,
9045c51f12Moriah Waterland		    strerror(errno));
9055c51f12Moriah Waterland		return (B_FALSE);
9065c51f12Moriah Waterland	}
9075c51f12Moriah Waterland
9085c51f12Moriah Waterland	/*
9095c51f12Moriah Waterland	 * generate a unique key - the key is the same length as unique uid
9105c51f12Moriah Waterland	 * but contains different information that is as unique as can be made;
9115c51f12Moriah Waterland	 * include current hires time (nanosecond real timer). Such a unique
9125c51f12Moriah Waterland	 * i.d. will look like:
9135c51f12Moriah Waterland	 *		0203104092-1145345-0004e94d6af481a0
9145c51f12Moriah Waterland	 */
9155c51f12Moriah Waterland
9165c51f12Moriah Waterland	hretime = gethrtime();
9175c51f12Moriah Waterland
9185c51f12Moriah Waterland	thetime = time((time_t *)NULL);
9195c51f12Moriah Waterland	(void) localtime_r(&thetime, &tstruct);
9205c51f12Moriah Waterland
9215c51f12Moriah Waterland	slen = snprintf(uuid, sizeof (uuid),
9225c51f12Moriah Waterland	    UUID_FORMAT,
9235c51f12Moriah Waterland	    tstruct.tm_mday, tstruct.tm_mon, tstruct.tm_year,
9245c51f12Moriah Waterland	    tstruct.tm_yday, tstruct.tm_hour, tstruct.tm_min,
9255c51f12Moriah Waterland	    tstruct.tm_sec,	tstruct.tm_wday, hretime);
9265c51f12Moriah Waterland	if (slen > sizeof (uuid)) {
9275c51f12Moriah Waterland		_z_program_error(ERR_GZMOUNT_SNPRINTFUUID_FAILED,
9285c51f12Moriah Waterland		    UUID_FORMAT, sizeof (uuid));
9295c51f12Moriah Waterland		return (B_FALSE);
9305c51f12Moriah Waterland	}
9315c51f12Moriah Waterland
9325c51f12Moriah Waterland	/* create the global zone mount point */
9335c51f12Moriah Waterland
9345c51f12Moriah Waterland	slen = snprintf(gzMountPoint, sizeof (gzMountPoint), "%s/.SUNW_%s_%s",
9355c51f12Moriah Waterland	    lzRootPath,
9365c51f12Moriah Waterland	    a_mountPointPrefix ? a_mountPointPrefix : "zones", uuid);
9375c51f12Moriah Waterland	if (slen > sizeof (gzMountPoint)) {
9385c51f12Moriah Waterland		_z_program_error(ERR_GZMOUNT_SNPRINTFGMP_FAILED,
9395c51f12Moriah Waterland		    "%s/.SUNW_%s_%s", lzRootPath,
9405c51f12Moriah Waterland		    a_mountPointPrefix ? a_mountPointPrefix : "zones",
9415c51f12Moriah Waterland		    uuid, sizeof (gzMountPoint));
9425c51f12Moriah Waterland		return (B_FALSE);
9435c51f12Moriah Waterland	}
9445c51f12Moriah Waterland
9455c51f12Moriah Waterland	slen = snprintf(lzMountPoint, sizeof (lzMountPoint), "%s",
9465c51f12Moriah Waterland	    gzMountPoint+strlen(lzRootPath));
9475c51f12Moriah Waterland	if (slen > sizeof (lzMountPoint)) {
9485c51f12Moriah Waterland		_z_program_error(ERR_GZMOUNT_SNPRINTFLMP_FAILED,
9495c51f12Moriah Waterland		    "%s", gzMountPoint+strlen(lzRootPath),
9505c51f12Moriah Waterland		    sizeof (lzMountPoint));
9515c51f12Moriah Waterland		return (B_FALSE);
9525c51f12Moriah Waterland	}
9535c51f12Moriah Waterland
9545c51f12Moriah Waterland	_z_echoDebug(DBG_MNTPT_NAMES, a_gzPath, a_zoneName, gzMountPoint,
9555c51f12Moriah Waterland	    lzMountPoint);
9565c51f12Moriah Waterland
9575c51f12Moriah Waterland	/* error if the mount point already exists */
9585c51f12Moriah Waterland
9595c51f12Moriah Waterland	if (_z_is_directory(gzMountPoint) == 0) {
9605c51f12Moriah Waterland		_z_program_error(ERR_ZONEROOT_NOTDIR, gzMountPoint,
9615c51f12Moriah Waterland		    a_zoneName, strerror(errno));
9625c51f12Moriah Waterland		return (B_FALSE);
9635c51f12Moriah Waterland	}
9645c51f12Moriah Waterland
9655c51f12Moriah Waterland	/* create the temporary mount point */
9665c51f12Moriah Waterland
9675c51f12Moriah Waterland	if (mkdir(gzMountPoint, 0600) != 0) {
9685c51f12Moriah Waterland		_z_program_error(ERR_MNTPT_MKDIR, gzMountPoint, a_zoneName,
9695c51f12Moriah Waterland		    strerror(errno));
9705c51f12Moriah Waterland		return (B_FALSE);
9715c51f12Moriah Waterland	}
9725c51f12Moriah Waterland
9735c51f12Moriah Waterland	/* mount the global zone path on the non-global zone root file system */
9745c51f12Moriah Waterland
9755c51f12Moriah Waterland	err = mount(a_gzPath, gzMountPoint, MS_RDONLY|MS_DATA, "lofs",
9765c51f12Moriah Waterland	    (char *)NULL, 0, (char *)NULL, 0);
9775c51f12Moriah Waterland	if (err != 0) {
9785c51f12Moriah Waterland		_z_program_error(ERR_GZMOUNT_FAILED, a_gzPath,
9795c51f12Moriah Waterland		    gzMountPoint, a_zoneName, strerror(errno));
9805c51f12Moriah Waterland		return (B_FALSE);
9815c51f12Moriah Waterland	}
9825c51f12Moriah Waterland
9835c51f12Moriah Waterland	/* success - return both mountpoints to caller */
9845c51f12Moriah Waterland
9855c51f12Moriah Waterland	*r_lzMountPoint = _z_strdup(gzMountPoint);
9865c51f12Moriah Waterland
9875c51f12Moriah Waterland	*r_lzRootPath = _z_strdup(lzMountPoint);
9885c51f12Moriah Waterland
9895c51f12Moriah Waterland	/* return success */
9905c51f12Moriah Waterland
9915c51f12Moriah Waterland	return (B_TRUE);
9925c51f12Moriah Waterland}
9935c51f12Moriah Waterland
9945c51f12Moriah Waterland/*
9955c51f12Moriah Waterland * Name:	z_non_global_zones_exist
9965c51f12Moriah Waterland * Description:	Determine if any non-global native zones exist
9975c51f12Moriah Waterland * Arguments:	None.
9985c51f12Moriah Waterland * Returns:	boolean_t
9995c51f12Moriah Waterland *	== B_TRUE - at least one non-global native zone exists
10005c51f12Moriah Waterland *	== B_FALSE - no non-global native zone exists
10015c51f12Moriah Waterland */
10025c51f12Moriah Waterland
10035c51f12Moriah Waterlandboolean_t
10045c51f12Moriah Waterlandz_non_global_zones_exist(void)
10055c51f12Moriah Waterland{
10065c51f12Moriah Waterland	FILE		*zoneIndexFP;
10075c51f12Moriah Waterland	boolean_t	anyExist = B_FALSE;
10085c51f12Moriah Waterland	struct zoneent	*ze;
10095c51f12Moriah Waterland	zone_spec_t	*zent;
10105c51f12Moriah Waterland
10115c51f12Moriah Waterland	/* if zones are not implemented, return FALSE */
10125c51f12Moriah Waterland
10135c51f12Moriah Waterland	if (z_zones_are_implemented() == B_FALSE) {
10145c51f12Moriah Waterland		return (B_FALSE);
10155c51f12Moriah Waterland	}
10165c51f12Moriah Waterland
10175c51f12Moriah Waterland	/* determine if any zones are configured */
10185c51f12Moriah Waterland	zoneIndexFP = setzoneent();
10195c51f12Moriah Waterland	if (zoneIndexFP == NULL) {
10205c51f12Moriah Waterland		return (B_FALSE);
10215c51f12Moriah Waterland	}
10225c51f12Moriah Waterland
10235c51f12Moriah Waterland	/* index file open; scan all zones; see if any are at least installed */
10245c51f12Moriah Waterland
10255c51f12Moriah Waterland	while ((ze = getzoneent_private(zoneIndexFP)) != NULL) {
10265c51f12Moriah Waterland		/*
10275c51f12Moriah Waterland		 * If the user specified an explicit zone list, then ignore any
10285c51f12Moriah Waterland		 * zones that aren't on that list.
10295c51f12Moriah Waterland		 */
10305c51f12Moriah Waterland		if ((zent = _z_global_data._zone_spec) != NULL) {
10315c51f12Moriah Waterland			while (zent != NULL) {
10325c51f12Moriah Waterland				if (strcmp(zent->zl_name, ze->zone_name) == 0)
10335c51f12Moriah Waterland					break;
10345c51f12Moriah Waterland				zent = zent->zl_next;
10355c51f12Moriah Waterland			}
10365c51f12Moriah Waterland			if (zent == NULL) {
10375c51f12Moriah Waterland				free(ze);
10385c51f12Moriah Waterland				continue;
10395c51f12Moriah Waterland			}
10405c51f12Moriah Waterland		}
10415c51f12Moriah Waterland
10425c51f12Moriah Waterland		/* skip the global zone */
10435c51f12Moriah Waterland		if (strcmp(ze->zone_name, GLOBAL_ZONENAME) == 0) {
10445c51f12Moriah Waterland			free(ze);
10455c51f12Moriah Waterland			continue;
10465c51f12Moriah Waterland		}
10475c51f12Moriah Waterland
10485c51f12Moriah Waterland		/* skip any branded zones */
10495c51f12Moriah Waterland		if (z_is_zone_branded(ze->zone_name)) {
10505c51f12Moriah Waterland			free(ze);
10515c51f12Moriah Waterland			continue;
10525c51f12Moriah Waterland		}
10535c51f12Moriah Waterland
10545c51f12Moriah Waterland		/* is this zone installed? */
10555c51f12Moriah Waterland		if (ze->zone_state >= ZONE_STATE_INSTALLED) {
10565c51f12Moriah Waterland			free(ze);
10575c51f12Moriah Waterland			anyExist = B_TRUE;
10585c51f12Moriah Waterland			break;
10595c51f12Moriah Waterland		}
10605c51f12Moriah Waterland		free(ze);
10615c51f12Moriah Waterland	}
10625c51f12Moriah Waterland
10635c51f12Moriah Waterland	/* close the index file */
10645c51f12Moriah Waterland
10655c51f12Moriah Waterland	endzoneent(zoneIndexFP);
10665c51f12Moriah Waterland
10675c51f12Moriah Waterland	/* return results */
10685c51f12Moriah Waterland
10695c51f12Moriah Waterland	return (anyExist);
10705c51f12Moriah Waterland}
10715c51f12Moriah Waterland
10725c51f12Moriah Waterland/*
10735c51f12Moriah Waterland * Name:	z_on_zone_spec
10745c51f12Moriah Waterland * Description:	Determine if named zone is on the zone_spec list.
10755c51f12Moriah Waterland * Arguments:	Pointer to name to test.
10765c51f12Moriah Waterland * Returns:	B_TRUE if named zone is on the list or if the user specified
10775c51f12Moriah Waterland *		no list at all (all zones is the default), B_FALSE otherwise.
10785c51f12Moriah Waterland */
10795c51f12Moriah Waterland
10805c51f12Moriah Waterlandboolean_t
10815c51f12Moriah Waterlandz_on_zone_spec(const char *zonename)
10825c51f12Moriah Waterland{
10835c51f12Moriah Waterland	zone_spec_t	*zent;
10845c51f12Moriah Waterland
10855c51f12Moriah Waterland	/* entry assertions */
10865c51f12Moriah Waterland
10875c51f12Moriah Waterland	assert(zonename != NULL);
10885c51f12Moriah Waterland	assert(*zonename != '\0');
10895c51f12Moriah Waterland
10905c51f12Moriah Waterland	/* return true if zones not implemented or no zone spec list defined */
10915c51f12Moriah Waterland
10925c51f12Moriah Waterland	if (!z_zones_are_implemented() || _z_global_data._zone_spec == NULL) {
10935c51f12Moriah Waterland		return (B_TRUE);
10945c51f12Moriah Waterland	}
10955c51f12Moriah Waterland
10965c51f12Moriah Waterland	/* return true if named zone is on the zone spec list */
10975c51f12Moriah Waterland
10985c51f12Moriah Waterland	for (zent = _z_global_data._zone_spec;
10995c51f12Moriah Waterland	    zent != NULL; zent = zent->zl_next) {
11005c51f12Moriah Waterland		if (strcmp(zent->zl_name, zonename) == 0)
11015c51f12Moriah Waterland			return (B_TRUE);
11025c51f12Moriah Waterland	}
11035c51f12Moriah Waterland
11045c51f12Moriah Waterland	/* named zone is not on the zone spec list */
11055c51f12Moriah Waterland
11065c51f12Moriah Waterland	return (B_FALSE);
11075c51f12Moriah Waterland}
11085c51f12Moriah Waterland
11095c51f12Moriah Waterland/*
11105c51f12Moriah Waterland * Name:	z_running_in_global_zone
11115c51f12Moriah Waterland * Description:	Determine if running in the "global" zone
11125c51f12Moriah Waterland * Arguments:	void
11135c51f12Moriah Waterland * Returns:	boolean_t
11145c51f12Moriah Waterland *			== B_TRUE - running in global zone
11155c51f12Moriah Waterland *			== B_FALSE - not running in global zone
11165c51f12Moriah Waterland */
11175c51f12Moriah Waterland
11185c51f12Moriah Waterlandboolean_t
11195c51f12Moriah Waterlandz_running_in_global_zone(void)
11205c51f12Moriah Waterland{
11215c51f12Moriah Waterland	static	boolean_t	_zoneIdDetermined = B_FALSE;
11225c51f12Moriah Waterland	static	boolean_t	_zoneIsGlobal = B_FALSE;
11235c51f12Moriah Waterland
11245c51f12Moriah Waterland	/* if ID has not been determined, cache it now */
11255c51f12Moriah Waterland
11265c51f12Moriah Waterland	if (!_zoneIdDetermined) {
11275c51f12Moriah Waterland		_zoneIdDetermined = B_TRUE;
11285c51f12Moriah Waterland		_zoneIsGlobal = _z_running_in_global_zone();
11295c51f12Moriah Waterland	}
11305c51f12Moriah Waterland
11315c51f12Moriah Waterland	return (_zoneIsGlobal);
11325c51f12Moriah Waterland}
11335c51f12Moriah Waterland
11345c51f12Moriah Waterland/*
11355c51f12Moriah Waterland * Name:	z_set_output_functions
11365c51f12Moriah Waterland * Description:	Link program specific output functions to this library.
11375c51f12Moriah Waterland * Arguments:	a_echo_fcn - (_z_printf_fcn_t)
11385c51f12Moriah Waterland *			Function to call to cause "normal operation" messages
11395c51f12Moriah Waterland *			to be output/displayed
11405c51f12Moriah Waterland *		a_echo_debug_fcn - (_z_printf_fcn_t)
11415c51f12Moriah Waterland *			Function to call to cause "debugging" messages
11425c51f12Moriah Waterland *			to be output/displayed
11435c51f12Moriah Waterland *		a_progerr_fcn - (_z_printf_fcn_t)
11445c51f12Moriah Waterland *			Function to call to cause "program error" messages
11455c51f12Moriah Waterland *			to be output/displayed
11465c51f12Moriah Waterland * Returns:	void
11475c51f12Moriah Waterland * NOTE:	If NULL is specified for any function, then the functionality
11485c51f12Moriah Waterland *		associated with that function is disabled.
11495c51f12Moriah Waterland * NOTE:	The function pointers provided must call a function that
11505c51f12Moriah Waterland *		takes two arguments:
11515c51f12Moriah Waterland *			function(char *format, char *message)
11525c51f12Moriah Waterland *		Any registered function will be called like:
11535c51f12Moriah Waterland *			function("%s", "message")
11545c51f12Moriah Waterland */
11555c51f12Moriah Waterland
11565c51f12Moriah Waterlandvoid
11575c51f12Moriah Waterlandz_set_output_functions(_z_printf_fcn_t a_echo_fcn,
11585c51f12Moriah Waterland    _z_printf_fcn_t a_echo_debug_fcn,
11595c51f12Moriah Waterland    _z_printf_fcn_t a_progerr_fcn)
11605c51f12Moriah Waterland{
11615c51f12Moriah Waterland	_z_global_data._z_echo = a_echo_fcn;
11625c51f12Moriah Waterland	_z_global_data._z_echo_debug = a_echo_debug_fcn;
11635c51f12Moriah Waterland	_z_global_data._z_progerr = a_progerr_fcn;
11645c51f12Moriah Waterland}
11655c51f12Moriah Waterland
11665c51f12Moriah Waterland/*
11675c51f12Moriah Waterland * Name:	z_set_zone_root
11685c51f12Moriah Waterland * Description:	Set root for zones library operations
11695c51f12Moriah Waterland * Arguments:	Path to root of boot environment containing zone; must be
11705c51f12Moriah Waterland *		absolute.
11715c51f12Moriah Waterland * Returns:	None.
11725c51f12Moriah Waterland * NOTE:	Must be called before performing any zone-related operations.
11735c51f12Moriah Waterland *		(Currently called directly by set_inst_root() during -R
11745c51f12Moriah Waterland *		argument handling.)
11755c51f12Moriah Waterland */
11765c51f12Moriah Waterland
11775c51f12Moriah Waterlandvoid
11785c51f12Moriah Waterlandz_set_zone_root(const char *zroot)
11795c51f12Moriah Waterland{
11805c51f12Moriah Waterland	char *rootdir;
11815c51f12Moriah Waterland
11825c51f12Moriah Waterland	/* if zones are not implemented, just return */
11835c51f12Moriah Waterland
11845c51f12Moriah Waterland	if (!z_zones_are_implemented())
11855c51f12Moriah Waterland		return;
11865c51f12Moriah Waterland
11875c51f12Moriah Waterland	/* entry assertions */
11885c51f12Moriah Waterland
11895c51f12Moriah Waterland	assert(zroot != NULL);
11905c51f12Moriah Waterland
11915c51f12Moriah Waterland	rootdir = _z_strdup((char *)zroot);
11925c51f12Moriah Waterland	z_canoninplace(rootdir);
11935c51f12Moriah Waterland
11945c51f12Moriah Waterland	if (strcmp(rootdir, "/") == 0) {
11955c51f12Moriah Waterland		rootdir[0] = '\0';
11965c51f12Moriah Waterland	}
11975c51f12Moriah Waterland
11985c51f12Moriah Waterland	/* free any existing cached root path */
11995c51f12Moriah Waterland	if (*_z_global_data._z_root_dir != '\0') {
12005c51f12Moriah Waterland		free(_z_global_data._z_root_dir);
120194a65b2Abhinandan Ekande		_z_global_data._z_root_dir = NULL;
12025c51f12Moriah Waterland	}
12035c51f12Moriah Waterland
12045c51f12Moriah Waterland	/* store duplicate of new zone root path */
12055c51f12Moriah Waterland
12065c51f12Moriah Waterland	if (*rootdir != '\0') {
12075c51f12Moriah Waterland		_z_global_data._z_root_dir = _z_strdup(rootdir);
12085c51f12Moriah Waterland	} else {
120994a65b2Abhinandan Ekande		_z_global_data._z_root_dir = "";
12105c51f12Moriah Waterland	}
12115c51f12Moriah Waterland
12125c51f12Moriah Waterland	/* set zone root path */
12135c51f12Moriah Waterland
12145c51f12Moriah Waterland	zonecfg_set_root(rootdir);
12155c51f12Moriah Waterland
12165c51f12Moriah Waterland	free(rootdir);
12175c51f12Moriah Waterland}
12185c51f12Moriah Waterland
12195c51f12Moriah Waterland/*
12205c51f12Moriah Waterland * Name:	z_set_zone_spec
12215c51f12Moriah Waterland * Description:	Set list of zones on which actions will be performed.
12225c51f12Moriah Waterland * Arguments:	Whitespace-separated list of zone names.
12235c51f12Moriah Waterland * Returns:	0 on success, -1 on error.
12245c51f12Moriah Waterland * NOTES:	Will call _z_program_error if argument can't be parsed or
12255c51f12Moriah Waterland *		memory not available.
12265c51f12Moriah Waterland */
12275c51f12Moriah Waterland
12285c51f12Moriah Waterlandint
12295c51f12Moriah Waterlandz_set_zone_spec(const char *zlist)
12305c51f12Moriah Waterland{
12315c51f12Moriah Waterland	const char	*zend;
12325c51f12Moriah Waterland	ptrdiff_t	zlen;
12335c51f12Moriah Waterland	zone_spec_t	*zent;
12345c51f12Moriah Waterland	zone_spec_t	*zhead;
12355c51f12Moriah Waterland	zone_spec_t	**znextp = &zhead;
12365c51f12Moriah Waterland
12375c51f12Moriah Waterland	/* entry assertions */
12385c51f12Moriah Waterland
12395c51f12Moriah Waterland	assert(zlist != NULL);
12405c51f12Moriah Waterland
12415c51f12Moriah Waterland	/* parse list to zone_spec_t list, store in global data */
12425c51f12Moriah Waterland
12435c51f12Moriah Waterland	for (;;) {
12445c51f12Moriah Waterland		while (isspace(*zlist)) {
12455c51f12Moriah Waterland			zlist++;
12465c51f12Moriah Waterland		}
12475c51f12Moriah Waterland		if (*zlist == '\0') {
12485c51f12Moriah Waterland			break;
12495c51f12Moriah Waterland		}
12505c51f12Moriah Waterland		for (zend = zlist; *zend != '\0'; zend++) {
12515c51f12Moriah Waterland			if (isspace(*zend)) {
12525c51f12Moriah Waterland				break;
12535c51f12Moriah Waterland			}
12545c51f12Moriah Waterland		}
12555c51f12Moriah Waterland		zlen = ((ptrdiff_t)zend) - ((ptrdiff_t)zlist);
12565c51f12Moriah Waterland		if (zlen >= ZONENAME_MAX) {
12575c51f12Moriah Waterland			_z_program_error(ERR_ZONE_NAME_ILLEGAL, zlen, zlist);
12585c51f12Moriah Waterland			return (-1);
12595c51f12Moriah Waterland		}
12605c51f12Moriah Waterland		zent = _z_malloc(sizeof (*zent));
12615c51f12Moriah Waterland		(void) memcpy(zent->zl_name, zlist, zlen);
12625c51f12Moriah Waterland		zent->zl_name[zlen] = '\0';
12635c51f12Moriah Waterland		zent->zl_used = B_FALSE;
12645c51f12Moriah Waterland		*znextp = zent;
12655c51f12Moriah Waterland		znextp = &zent->zl_next;
12665c51f12Moriah Waterland		zlist = zend;
12675c51f12Moriah Waterland	}
12685c51f12Moriah Waterland	*znextp = NULL;
12695c51f12Moriah Waterland
12705c51f12Moriah Waterland	if (zhead == NULL) {
12715c51f12Moriah Waterland		_z_program_error(ERR_ZONE_LIST_EMPTY);
12725c51f12Moriah Waterland		return (-1);
12735c51f12Moriah Waterland	}
12745c51f12Moriah Waterland
12755c51f12Moriah Waterland	_z_global_data._zone_spec = zhead;
12765c51f12Moriah Waterland	return (0);
12775c51f12Moriah Waterland}
12785c51f12Moriah Waterland
12795c51f12Moriah Waterland/*
12805c51f12Moriah Waterland * Name:	z_umount_lz_mount
12815c51f12Moriah Waterland * Description:	Unmount directory mounted with z_mount_in_lz
12825c51f12Moriah Waterland * Arguments:	a_lzMountPointer - pointer to string returned by z_mount_in_lz
12835c51f12Moriah Waterland * Returns:	boolean_t
12845c51f12Moriah Waterland *			== B_TRUE - successfully unmounted directory
12855c51f12Moriah Waterland *			== B_FALSE - failed to unmount directory
12865c51f12Moriah Waterland */
12875c51f12Moriah Waterland
12885c51f12Moriah Waterlandboolean_t
12895c51f12Moriah Waterlandz_umount_lz_mount(char *a_lzMountPoint)
12905c51f12Moriah Waterland{
12915c51f12Moriah Waterland	int	err;
12925c51f12Moriah Waterland
12935c51f12Moriah Waterland	/* entry assertions */
12945c51f12Moriah Waterland
12955c51f12Moriah Waterland	assert(a_lzMountPoint != (char *)NULL);
12965c51f12Moriah Waterland	assert(*a_lzMountPoint != '\0');
12975c51f12Moriah Waterland
12985c51f12Moriah Waterland	/* entry debugging info */
12995c51f12Moriah Waterland
13005c51f12Moriah Waterland	_z_echoDebug(DBG_ZONES_UNMOUNT_FROM_LZ_ENTRY, a_lzMountPoint);
13015c51f12Moriah Waterland
13025c51f12Moriah Waterland	/* if zones are not implemented, return TRUE */
13035c51f12Moriah Waterland
13045c51f12Moriah Waterland	if (z_zones_are_implemented() == B_FALSE) {
13055c51f12Moriah Waterland		return (B_FALSE);
13065c51f12Moriah Waterland	}
13075c51f12Moriah Waterland
13085c51f12Moriah Waterland	/* error if global zone path is not absolute */
13095c51f12Moriah Waterland
13105c51f12Moriah Waterland	if (*a_lzMountPoint != '/') {
13115c51f12Moriah Waterland		_z_program_error(ERR_LZMNTPT_NOT_ABSOLUTE, a_lzMountPoint);
13125c51f12Moriah Waterland		return (B_FALSE);
13135c51f12Moriah Waterland	}
13145c51f12Moriah Waterland
13155c51f12Moriah Waterland	/* verify mount point exists */
13165c51f12Moriah Waterland
13175c51f12Moriah Waterland	if (_z_is_directory(a_lzMountPoint) != 0) {
13185c51f12Moriah Waterland		_z_program_error(ERR_LZMNTPT_NOTDIR, a_lzMountPoint,
13195c51f12Moriah Waterland		    strerror(errno));
13205c51f12Moriah Waterland		return (B_FALSE);
13215c51f12Moriah Waterland	}
13225c51f12Moriah Waterland
13235c51f12Moriah Waterland	/* unmount */
13245c51f12Moriah Waterland
13255c51f12Moriah Waterland	err = umount2(a_lzMountPoint, 0);
13265c51f12Moriah Waterland	if (err != 0) {
13275c51f12Moriah Waterland		_z_program_error(ERR_GZUMOUNT_FAILED, a_lzMountPoint,
13285c51f12Moriah Waterland		    strerror(errno));
13295c51f12Moriah Waterland		return (B_FALSE);
13305c51f12Moriah Waterland	}
13315c51f12Moriah Waterland
13325c51f12Moriah Waterland	/* remove the mount point */
13335c51f12Moriah Waterland
13345c51f12Moriah Waterland	(void) remove(a_lzMountPoint);
13355c51f12Moriah Waterland
13365c51f12Moriah Waterland	/* return success */
13375c51f12Moriah Waterland
13385c51f12Moriah Waterland	return (B_TRUE);
13395c51f12Moriah Waterland}
13405c51f12Moriah Waterland
13415c51f12Moriah Waterland/*
13425c51f12Moriah Waterland * Name:	z_unlock_this_zone
13435c51f12Moriah Waterland * Description:	unlock this zone
13445c51f12Moriah Waterland * Arguments:	a_lflags - [RO, *RO] - (ZLOCKS_T)
13455c51f12Moriah Waterland *			Flags indicating which locks to release
13465c51f12Moriah Waterland * Returns:	boolean_t
13475c51f12Moriah Waterland *			== B_TRUE - success specified locks released
13485c51f12Moriah Waterland *			== B_FALSE - failure specified locks may not be released
13495c51f12Moriah Waterland * NOTE: the lock objects for "this zone" are maintained internally.
13505c51f12Moriah Waterland */
13515c51f12Moriah Waterland
13525c51f12Moriah Waterlandboolean_t
13535c51f12Moriah Waterlandz_unlock_this_zone(ZLOCKS_T a_lflags)
13545c51f12Moriah Waterland{
13555c51f12Moriah Waterland	boolean_t	b;
13565c51f12Moriah Waterland	boolean_t	errors = B_FALSE;
13575c51f12Moriah Waterland	char		*zoneName;
13585c51f12Moriah Waterland
13595c51f12Moriah Waterland	/* entry assertions */
13605c51f12Moriah Waterland
13615c51f12Moriah Waterland	assert(a_lflags != ZLOCKS_NONE);
13625c51f12Moriah Waterland
13635c51f12Moriah Waterland	/* entry debugging info */
13645c51f12Moriah Waterland
13655c51f12Moriah Waterland	_z_echoDebug(DBG_ZONES_ULK_THIS, a_lflags);
13665c51f12Moriah Waterland
13675c51f12Moriah Waterland	/* return if no objects locked */
13685c51f12Moriah Waterland
13695c51f12Moriah Waterland	if ((_z_global_data._z_ObjectLocks == (char *)NULL) ||
13705c51f12Moriah Waterland	    (*_z_global_data._z_ObjectLocks == '\0')) {
13715c51f12Moriah Waterland		return (B_TRUE);
13725c51f12Moriah Waterland	}
13735c51f12Moriah Waterland
13745c51f12Moriah Waterland	zoneName = z_get_zonename();
13755c51f12Moriah Waterland
13765c51f12Moriah Waterland	/* unlock package administration */
13775c51f12Moriah Waterland
13785c51f12Moriah Waterland	if (a_lflags & ZLOCKS_PKG_ADMIN) {
13795c51f12Moriah Waterland		b = _z_unlock_zone_object(&_z_global_data._z_ObjectLocks,
13805c51f12Moriah Waterland		    zoneName, LOBJ_PKGADMIN, ERR_ZONES_ULK_THIS_PACKAGE);
13815c51f12Moriah Waterland		if (!b) {
13825c51f12Moriah Waterland			errors = B_TRUE;
13835c51f12Moriah Waterland		}
13845c51f12Moriah Waterland	}
13855c51f12Moriah Waterland
13865c51f12Moriah Waterland	/* unlock zone administration */
13875c51f12Moriah Waterland
13885c51f12Moriah Waterland	if (a_lflags & ZLOCKS_ZONE_ADMIN) {
13895c51f12Moriah Waterland		b = _z_unlock_zone_object(&_z_global_data._z_ObjectLocks,
13905c51f12Moriah Waterland		    zoneName, LOBJ_ZONEADMIN, ERR_ZONES_ULK_THIS_ZONES);
13915c51f12Moriah Waterland		if (!b) {
13925c51f12Moriah Waterland			errors = B_TRUE;
13935c51f12Moriah Waterland		}
13945c51f12Moriah Waterland	}
13955c51f12Moriah Waterland
13965c51f12Moriah Waterland	(void) free(zoneName);
13975c51f12Moriah Waterland	return (!errors);
13985c51f12Moriah Waterland}
13995c51f12Moriah Waterland
14005c51f12Moriah Waterland/*
14015c51f12Moriah Waterland * Name:	z_unlock_zones
14025c51f12Moriah Waterland * Description:	unlock specified zones
14035c51f12Moriah Waterland * Arguments:	a_zlst - zoneList_t object describing zones to unlock
14045c51f12Moriah Waterland *		a_lflags - [RO, *RO] - (ZLOCKS_T)
14055c51f12Moriah Waterland *			Flags indicating which locks to release
14065c51f12Moriah Waterland * Returns:	boolean_t
14075c51f12Moriah Waterland *			== B_TRUE - success, zones unlocked
14085c51f12Moriah Waterland *			== B_FALSE - failure, zones not unlocked
14095c51f12Moriah Waterland */
14105c51f12Moriah Waterland
14115c51f12Moriah Waterlandboolean_t
14125c51f12Moriah Waterlandz_unlock_zones(zoneList_t a_zlst, ZLOCKS_T a_lflags)
14135c51f12Moriah Waterland{
14145c51f12Moriah Waterland	boolean_t	b;
14155c51f12Moriah Waterland	boolean_t	errors = B_FALSE;
14165c51f12Moriah Waterland	int		i;
14175c51f12Moriah Waterland
14185c51f12Moriah Waterland	/* entry assertions */
14195c51f12Moriah Waterland
14205c51f12Moriah Waterland	assert(a_lflags != ZLOCKS_NONE);
14215c51f12Moriah Waterland
14225c51f12Moriah Waterland	/* entry debugging info */
14235c51f12Moriah Waterland
14245c51f12Moriah Waterland	_z_echoDebug(DBG_ZONES_ULK_ZONES, a_lflags);
14255c51f12Moriah Waterland
14265c51f12Moriah Waterland	/* if zones are not implemented, return TRUE */
14275c51f12Moriah Waterland
14285c51f12Moriah Waterland	if (z_zones_are_implemented() == B_FALSE) {
14295c51f12Moriah Waterland		_z_echoDebug(DBG_ZONES_ULK_ZONES_UNIMP);
14305c51f12Moriah Waterland		return (B_TRUE);
14315c51f12Moriah Waterland	}
14325c51f12Moriah Waterland
14335c51f12Moriah Waterland	/* ignore empty list */
14345c51f12Moriah Waterland
14355c51f12Moriah Waterland	if (a_zlst == (zoneList_t)NULL) {
14365c51f12Moriah Waterland		_z_echoDebug(DBG_ZONES_ULK_ZONES_NOZONES);
14375c51f12Moriah Waterland		/* unlock this zone before returning */
14385c51f12Moriah Waterland		return (z_unlock_this_zone(a_lflags));
14395c51f12Moriah Waterland	}
14405c51f12Moriah Waterland
14415c51f12Moriah Waterland	/* zones exist */
14425c51f12Moriah Waterland
14435c51f12Moriah Waterland	_z_echoDebug(DBG_ZONES_ULK_ZONES_EXIST);
14445c51f12Moriah Waterland
14455c51f12Moriah Waterland	/*
14465c51f12Moriah Waterland	 * unlock each listed zone that is currently running
14475c51f12Moriah Waterland	 */
14485c51f12Moriah Waterland
14495c51f12Moriah Waterland	for (i = 0; (a_zlst[i]._zlName != (char *)NULL); i++) {
14505c51f12Moriah Waterland		/* ignore zone if not locked */
14515c51f12Moriah Waterland		if (!(a_zlst[i]._zlStatus & ZST_LOCKED)) {
14525c51f12Moriah Waterland			continue;
14535c51f12Moriah Waterland		}
14545c51f12Moriah Waterland
14555c51f12Moriah Waterland		/* ignore zone if not running */
14565c51f12Moriah Waterland		if (a_zlst[i]._zlCurrKernelStatus != ZONE_STATE_RUNNING &&
14575c51f12Moriah Waterland		    a_zlst[i]._zlCurrKernelStatus != ZONE_STATE_MOUNTED) {
14585c51f12Moriah Waterland			continue;
14595c51f12Moriah Waterland		}
14605c51f12Moriah Waterland
14615c51f12Moriah Waterland		/* unlock this zone */
14625c51f12Moriah Waterland		b = _z_unlock_zone(&a_zlst[i], a_lflags);
14635c51f12Moriah Waterland
14645c51f12Moriah Waterland		if (b != B_TRUE) {
14655c51f12Moriah Waterland			errors = B_TRUE;
14665c51f12Moriah Waterland		} else {
14675c51f12Moriah Waterland			/* mark zone as unlocked */
14685c51f12Moriah Waterland			a_zlst[i]._zlStatus &= ~ZST_LOCKED;
14695c51f12Moriah Waterland		}
14705c51f12Moriah Waterland	}
14715c51f12Moriah Waterland
14725c51f12Moriah Waterland	/* unlock this zone */
14735c51f12Moriah Waterland
14745c51f12Moriah Waterland	if (z_unlock_this_zone(a_lflags) != B_TRUE) {
14755c51f12Moriah Waterland		errors = B_TRUE;
14765c51f12Moriah Waterland	}
14775c51f12Moriah Waterland
14785c51f12Moriah Waterland	return (errors);
14795c51f12Moriah Waterland}
14805c51f12Moriah Waterland
14815c51f12Moriah Waterland/*
14825c51f12Moriah Waterland * Name:	z_verify_zone_spec
14835c51f12Moriah Waterland * Description:	Verify list of zones on which actions will be performed.
14845c51f12Moriah Waterland * Arguments:	None.
14855c51f12Moriah Waterland * Returns:	0 on success, -1 on error.
14865c51f12Moriah Waterland * NOTES:	Will call _z_program_error if there are zones on the specified
14875c51f12Moriah Waterland *		list that don't exist on the system. Requires that
14885c51f12Moriah Waterland *		z_set_zone_root is called first (if it is called at all).
14895c51f12Moriah Waterland */
14905c51f12Moriah Waterland
14915c51f12Moriah Waterlandint
14925c51f12Moriah Waterlandz_verify_zone_spec(void)
14935c51f12Moriah Waterland{
14945c51f12Moriah Waterland	FILE		*zoneIndexFP;
14955c51f12Moriah Waterland	boolean_t	errors;
14965c51f12Moriah Waterland	char		zoneIndexPath[MAXPATHLEN];
14975c51f12Moriah Waterland	struct zoneent	*ze;
14985c51f12Moriah Waterland	zone_spec_t	*zent;
14995c51f12Moriah Waterland
15005c51f12Moriah Waterland	if (!z_zones_are_implemented()) {
15015c51f12Moriah Waterland		_z_program_error(ERR_ZONES_NOT_IMPLEMENTED);
15025c51f12Moriah Waterland		return (-1);
15035c51f12Moriah Waterland	}
15045c51f12Moriah Waterland
15055c51f12Moriah Waterland	zoneIndexFP = setzoneent();
15065c51f12Moriah Waterland	if (zoneIndexFP == NULL) {
15075c51f12Moriah Waterland		_z_program_error(ERR_ZONEINDEX_OPEN, zoneIndexPath,
15085c51f12Moriah Waterland		    strerror(errno));
15095c51f12Moriah Waterland		return (-1);
15105c51f12Moriah Waterland	}
15115c51f12Moriah Waterland
15125c51f12Moriah Waterland	while ((ze = getzoneent_private(zoneIndexFP)) != NULL) {
15135c51f12Moriah Waterland		for (zent = _z_global_data._zone_spec;
15145c51f12Moriah Waterland		    zent != NULL; zent = zent->zl_next) {
15155c51f12Moriah Waterland			if (strcmp(zent->zl_name, ze->zone_name) == 0) {
15165c51f12Moriah Waterland				zent->zl_used = B_TRUE;
15175c51f12Moriah Waterland				break;
15185c51f12Moriah Waterland			}
15195c51f12Moriah Waterland		}
15205c51f12Moriah Waterland		free(ze);
15215c51f12Moriah Waterland	}
15225c51f12Moriah Waterland	endzoneent(zoneIndexFP);
15235c51f12Moriah Waterland
15245c51f12Moriah Waterland	errors = B_FALSE;
15255c51f12Moriah Waterland	for (zent = _z_global_data._zone_spec;
15265c51f12Moriah Waterland	    zent != NULL; zent = zent->zl_next) {
15275c51f12Moriah Waterland		if (!zent->zl_used) {
15285c51f12Moriah Waterland			_z_program_error(ERR_ZONE_NONEXISTENT, zent->zl_name);
15295c51f12Moriah Waterland			errors = B_TRUE;
15305c51f12Moriah Waterland		}
15315c51f12Moriah Waterland	}
15325c51f12Moriah Waterland	return (errors ? -1 : 0);
15335c51f12Moriah Waterland}
15345c51f12Moriah Waterland
15355c51f12Moriah Waterland/*
15365c51f12Moriah Waterland * Name:	z_zlist_change_zone_state
15375c51f12Moriah Waterland * Description:	Change the current state of the specified zone
15385c51f12Moriah Waterland * Arguments:	a_zlst - handle to zoneList_t object describing all zones
15395c51f12Moriah Waterland *		a_zoneIndex - index into a_zlst of the zone to return the
15405c51f12Moriah Waterland *		a_newState - the state to put the specified zone in
15415c51f12Moriah Waterland * Returns:	boolean_t
15425c51f12Moriah Waterland *			== B_TRUE - the zone is in the new state
15435c51f12Moriah Waterland *			== B_FALSE - unable to transition the zone to the
15445c51f12Moriah Waterland *				specified state
15455c51f12Moriah Waterland * NOTE:	This changes the "current kernel" state of the specified
15465c51f12Moriah Waterland *		zone. For example, to boot the zone, change the state
15475c51f12Moriah Waterland *		to "ZONE_STATE_RUNNING". To halt the zone, change the
15485c51f12Moriah Waterland *		state to "ZONE_STATE_INSTALLED".
15495c51f12Moriah Waterland */
15505c51f12Moriah Waterland
15515c51f12Moriah Waterlandboolean_t
15525c51f12Moriah Waterlandz_zlist_change_zone_state(zoneList_t a_zlst, int a_zoneIndex,
15535c51f12Moriah Waterland	zone_state_t a_newState)
15545c51f12Moriah Waterland{
15555c51f12Moriah Waterland	int	i;