/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* Module: zones.c
* Group: libinstzones
* Description: Provide "zones" interface for libbe. No new consumers shall
* be added - rather they should use zoneadm(1M) or libzonecfg
* interfaces.
*
* Public Methods:
* z_free_zone_list - free contents of zoneList_t object
* z_get_nonglobal_zone_list_by_brand - return zoneList_t object describing
* all non-global zones matching the list of zone brands passed in.
* z_free_brand_list - free contents of a zoneBrandList_t object
* z_make_brand_list - return a zoneBrandList_t object describing the list
* of all zone brands passed in.
* z_get_zonename - return the name of the current zone
* z_global_only - Determine if the global zone is only zone on the spec list
* z_lock_this_zone - lock this zone
* z_running_in_global_zone - Determine if running in the "global" zone
* z_set_output_functions - Link program specific output functions
* z_set_zone_root - Set root for zones library operations
* z_set_zone_spec - Set list of zones on which actions will be performed
* z_unlock_this_zone - unlock this zone
* z_verify_zone_spec - Verify list of zones on which actions will be performed
* z_zlist_get_current_state - Determine the current kernel state of the
* specified zone
* z_zlist_get_zonename - Determine name of specified zone
* z_zones_are_implemented - Determine if any zone operations can be performed
* z_is_zone_brand_in_list - determine if the zone's brand matches the
* brand list passed in.
* z_brands_are_implemented - determine if branded zones are implemented on
* this system
*/
/*
* System includes
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <ctype.h>
#include <sys/sysmacros.h>
#include <string.h>
#include <strings.h>
#include <stdarg.h>
#include <limits.h>
#include <errno.h>
#include <time.h>
#include <signal.h>
#include <stropts.h>
#include <wait.h>
#include <zone.h>
#include <libintl.h>
#include <locale.h>
#include <libzonecfg.h>
#include <libcontract.h>
#include <assert.h>
#include <dlfcn.h>
#include <link.h>
#include <time.h>
/*
* local includes
*/
/*
* When _INSTZONES_LIB_Z_DEFINE_GLOBAL_DATA is defined,
* instzones_lib.h will define the z_global_data structure.
* Otherwise an extern to the structure is inserted.
*/
#include "instzones_lib.h"
#include "zones_strings.h"
/*
* Private structures
*/
/* maximum number of arguments to exec() call */
/*
* Library Function Prototypes
*/
/*
* Local Function Prototypes
*/
/*
* global internal (private) declarations
*/
/*
* *****************************************************************************
* global external (public) functions
* *****************************************************************************
*/
/*
* Name: z_brands_are_implemented
* Description: Determine if any branded zones may be present
* Arguments: void
* Returns: boolean_t
* == B_TRUE - branded zones are supported
* == B_FALSE - branded zones are not supported
*/
z_brands_are_implemented(void)
{
/* if availability has not been determined, cache it now */
if (!_brandsImplementedDetermined) {
if (_brandsAreImplemented) {
} else {
}
}
/* return cached answer */
return (_brandsAreImplemented);
}
/*
* Name: z_free_zone_list
* Description: free contents of zoneList_t object
* Arguments: a_zlst - handle to zoneList_t object to free
* Returns: void
*/
void
{
int numzones;
/* ignore empty list */
return;
}
/* free each entry in the zone list */
numzones++) {
/* free zone name string */
/* free zonepath string */
}
}
/* free handle to the list */
}
/*
* Name: z_free_brand_list
* Description: Free contents of zoneBrandList_t object
* Arguments: brands - pointer to zoneBrandList_t object to free
* Returns: void
*/
void
{
}
}
/*
* Name: z_make_brand_list
* Description: Given a string with a list of brand name delimited by
* the delimeter passed in, build a zoneBrandList_t structure
* with the list of brand names and return it to the caller.
* Arguments:
* brands - const char pointer to string list of brand names
* delim - const char pointer to string representing the
* delimeter for brands string.
* Returns: zoneBrandList_t *
* == NULL - error, list could not be generated
* != NULL - success, list returned
* NOTE: Any zoneBrandList_t returned is placed in new storage for the
* calling function. The caller must use 'z_free_brand_list' to
* dispose of the storage once the list is no longer needed.
*/
{
return (NULL);
if ((brand = (zoneBrandList_t *)
return (NULL);
}
return (NULL);
}
}
}
return (head);
}
/*
* Name: z_get_nonglobal_zone_list_by_brand
* Description: return zoneList_t object describing all non-global
* zones matching the list of brands passed in.
* Arguments: brands - The list of zone brands to look for.
* Returns: zoneList_t
* == NULL - error, list could not be generated
* != NULL - success, list returned
* NOTE: Any zoneList_t returned is placed in new storage for the
* calling function. The caller must use 'z_free_zone_list' to
* dispose of the storage once the list is no longer needed.
*/
{
int numzones = 0;
/* if zones are not implemented, return empty list */
if (!z_zones_are_implemented()) {
return ((zoneList_t)NULL);
}
/*
* Open the zone index file. Note that getzoneent_private() handles
* NULL.
*/
zoneIndexFP = setzoneent();
/* index file open; scan all zones; see if any are at least installed */
/* skip the global zone */
continue;
}
/*
* skip any zones with brands not on the brand list
*/
continue;
}
/*
* If the user specified an explicit zone list, then ignore any
* zones that aren't on that list.
*/
break;
}
continue;
}
}
/* non-global zone: create entry for this zone */
if (numzones == 0) {
sizeof (zoneListElement_t)*2);
} else {
sizeof (zoneListElement_t)*2);
}
/*
* remember the zone name, zonepath and the current
* zone state of the zone.
*/
/*
* For a scratch zone, we need to know the kernel zone name.
*/
}
numzones++;
}
/* close the index file */
/* return generated list */
return (zlst);
}
/*
* Name: z_get_zonename
* Description: return the name of the current zone
* Arguments: void
* Returns: char *
* - pointer to string representing the name of the current
* zone
* NOTE: Any string returned is placed in new storage for the
* calling function. The caller must use 'Free' to dispose
* of the storage once the string is no longer needed.
*/
char *
z_get_zonename(void)
{
/* if zones are not implemented, return "" */
if (!z_zones_are_implemented()) {
return (_z_strdup(""));
}
/* get the zone i.d. of the current zone */
/* get the name of the current zone */
/* return "" if could not get zonename */
if (zonenameLen < 1) {
return (_z_strdup(""));
}
}
/*
* Name: z_global_only
* Description: Determine if the global zone is only zone on the spec list.
* Arguments: None
* Returns: B_TRUE if global zone is the only zone on the list,
* B_FALSE otherwise.
*/
z_global_only(void)
{
/* return true if zones are not implemented - treate as global zone */
if (!z_zones_are_implemented()) {
return (B_TRUE);
}
/* return true if this is the global zone */
return (B_TRUE);
}
/* return false - not the global zone */
return (B_FALSE);
}
/*
* Name: z_lock_this_zone
* Description: lock this zone
* Arguments: a_lflags - [RO, *RO] - (ZLOCKS_T)
* Flags indicating which locks to acquire
* Returns: boolean_t
* == B_TRUE - success specified locks acquired
* == B_FALSE - failure specified locks not acquired
* NOTE: the lock objects for "this zone" are maintained internally.
*/
{
boolean_t b;
char *zoneName;
/* entry assertions */
/* entry debugging info */
zoneName = z_get_zonename();
/* lock package administration always */
if (a_lflags & ZLOCKS_PKG_ADMIN) {
if (!b) {
(void) z_unlock_this_zone(a_lflags);
return (B_FALSE);
}
}
return (B_TRUE);
}
/*
* Name: z_running_in_global_zone
* Description: Determine if running in the "global" zone
* Arguments: void
* Returns: boolean_t
* == B_TRUE - running in global zone
* == B_FALSE - not running in global zone
*/
z_running_in_global_zone(void)
{
/* if ID has not been determined, cache it now */
if (!_zoneIdDetermined) {
}
return (_zoneIsGlobal);
}
/*
* Name: z_set_output_functions
* Description: Link program specific output functions to this library.
* Arguments: a_echo_fcn - (_z_printf_fcn_t)
* Function to call to cause "normal operation" messages
* a_echo_debug_fcn - (_z_printf_fcn_t)
* Function to call to cause "debugging" messages
* a_progerr_fcn - (_z_printf_fcn_t)
* Function to call to cause "program error" messages
* Returns: void
* NOTE: If NULL is specified for any function, then the functionality
* associated with that function is disabled.
* NOTE: The function pointers provided must call a function that
* takes two arguments:
* function(char *format, char *message)
* Any registered function will be called like:
* function("%s", "message")
*/
void
{
}
/*
* Name: z_set_zone_root
* Description: Set root for zones library operations
* Arguments: Path to root of boot environment containing zone; must be
* absolute.
* Returns: None.
* NOTE: Must be called before performing any zone-related operations.
* (Currently called directly by set_inst_root() during -R
* argument handling.)
*/
void
{
char *rootdir;
/* if zones are not implemented, just return */
if (!z_zones_are_implemented())
return;
/* entry assertions */
rootdir[0] = '\0';
}
/* free any existing cached root path */
}
/* store duplicate of new zone root path */
if (*rootdir != '\0') {
} else {
}
/* set zone root path */
}
/*
* Name: z_set_zone_spec
* Description: Set list of zones on which actions will be performed.
* Arguments: Whitespace-separated list of zone names.
* Returns: 0 on success, -1 on error.
* NOTES: Will call _z_program_error if argument can't be parsed or
* memory not available.
*/
int
{
const char *zend;
/* entry assertions */
/* parse list to zone_spec_t list, store in global data */
for (;;) {
zlist++;
}
if (*zlist == '\0') {
break;
}
break;
}
}
if (zlen >= ZONENAME_MAX) {
return (-1);
}
}
return (-1);
}
return (0);
}
/*
* Name: z_unlock_this_zone
* Description: unlock this zone
* Arguments: a_lflags - [RO, *RO] - (ZLOCKS_T)
* Flags indicating which locks to release
* Returns: boolean_t
* == B_TRUE - success specified locks released
* == B_FALSE - failure specified locks may not be released
* NOTE: the lock objects for "this zone" are maintained internally.
*/
{
boolean_t b;
char *zoneName;
/* entry assertions */
/* entry debugging info */
/* return if no objects locked */
return (B_TRUE);
}
zoneName = z_get_zonename();
/* unlock package administration */
if (a_lflags & ZLOCKS_PKG_ADMIN) {
if (!b) {
}
}
return (!errors);
}
/*
* Name: z_verify_zone_spec
* Description: Verify list of zones on which actions will be performed.
* Arguments: None.
* Returns: 0 on success, -1 on error.
* NOTES: Will call _z_program_error if there are zones on the specified
* list that don't exist on the system. Requires that
* z_set_zone_root is called first (if it is called at all).
*/
int
z_verify_zone_spec(void)
{
if (!z_zones_are_implemented()) {
return (-1);
}
zoneIndexFP = setzoneent();
if (zoneIndexFP == NULL) {
return (-1);
}
break;
}
}
}
}
}
return (errors ? -1 : 0);
}
/*
* Name: z_is_zone_brand_in_list
* Description: Determine whether zone's brand has a match in the list
* brands passed in.
* Arguments: zoneName - name of the zone to check for branding
* list - list of brands to check the zone against
* Returns: boolean_t
* == B_TRUE - zone has a matching brand
* == B_FALSE - zone brand is not in list
*/
{
int err;
return (B_FALSE);
/* if zones are not implemented, return FALSE */
if (!z_zones_are_implemented()) {
return (B_FALSE);
}
/* if brands are not implemented, return FALSE */
if (!z_brands_are_implemented()) {
return (B_FALSE);
}
return (B_FALSE);
}
return (B_TRUE);
}
}
return (B_FALSE);
}
/*
* Name: z_zlist_get_current_state
* Description: Determine the current kernel state of the specified zone
* Arguments: a_zlst - handle to zoneList_t object describing all zones
* a_zoneIndex - index into a_zlst of the zone to return
* Returns: zone_state_t
* The current state of the specified zone is returned
*/
{
int i;
/* ignore empty list */
return (ZONE_STATE_INCOMPLETE);
}
/* find the specified zone in the list */
for (i = 0; (i != a_zoneIndex) &&
;
/* return error if the specified zone does not exist */
return (ZONE_STATE_INCOMPLETE);
}
/* return selected zone's current kernel state */
}
/*
* Name: z_zlist_get_zonename
* Description: Determine name of specified zone
* Arguments: a_zlst - handle to zoneList_t object describing all zones
* a_zoneIndex - index into a_zlst of the zone to return the
* Return: char *
* == NULL - zone name could not be determined
* != NULL - pointer to string representing zone name
* NOTE: Any zoneList_t returned is placed in static storage that must
* NEVER be free()ed by the caller.
*/
char *
{
int i;
/* ignore empty list */
return ((char *)NULL);
}
/* find the specified zone in the list */
for (i = 0; (i != a_zoneIndex) &&
;
/* return error if the specified zone does not exist */
return (NULL);
}
/* return selected zone's name */
}
/*
* Name: z_zlist_get_zonepath
* Description: Determine zonepath of specified zone
* Arguments: a_zlst - handle to zoneList_t object describing all zones
* a_zoneIndex - index into a_zlst of the zone to return
* Return: char *
* == NULL - zonepath could not be determined
* != NULL - pointer to string representing zonepath
* NOTE: Any zoneList_t returned is placed in static storage that must
* NEVER be free()ed by the caller.
*/
char *
{
int i;
/* ignore empty list */
return ((char *)NULL);
}
/* find the specified zone in the list */
for (i = 0; (i != a_zoneIndex) &&
;
/* return error if the specified zone does not exist */
return (NULL);
}
/* return selected zone's zonepath */
}
/*
* Name: z_zones_are_implemented
* Description: Determine if any zone operations can be performed
* Arguments: void
* Returns: boolean_t
* == B_TRUE - zone operations are available
* == B_FALSE - no zone operations can be done
*/
z_zones_are_implemented(void)
{
/* if availability has not been determined, cache it now */
if (!_zonesImplementedDetermined) {
if (!_zonesAreImplemented) {
} else {
}
}
return (_zonesAreImplemented);
}