main.c revision 4656d4747c8743290bfbe910c64cd75eb4e4af8d
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER START
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * The contents of this file are subject to the terms of the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Common Development and Distribution License (the "License").
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * You may not use this file except in compliance with the License.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * or http://www.opensolaris.org/os/licensing.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * See the License for the specific language governing permissions
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * and limitations under the License.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * When distributing Covered Code, include this CDDL HEADER in each
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If applicable, add the following below this CDDL HEADER, with the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * fields enclosed by brackets "[]" replaced with your own identifying
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * information: Portions Copyright [yyyy] [name of copyright owner]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER END
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
6e1ae2a33c618c4c2b14aec7d2f21743ddea5837Gary Pennington * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Program: pkgcond
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Function: Implements the package command suite public utility pkgcond(1M)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Usage: pkgcond [-nv] [-O debug] condition [ argument ]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * command options:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * -n - negate results of condition test
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * -v - verbose output of condition testing
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * <condition> may be any one of:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * can_add_driver [path]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * can_remove_driver [path]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * can_update_driver [path]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is_alternative_root [path]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is_boot_environment [path]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is_diskless_client [path]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is_global_zone [path]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is_mounted_miniroot [path]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is_netinstall_image [path]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is_nonglobal_zone [path]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is_path_writable path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is_running_system [path]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is_what [path]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is_whole_root_nonglobal_zone [path]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * <option(s)> are specific to the condition used
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Input: depends on command
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Output: depends on command
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Exit status: If the -n option is not specified:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 0 - the specified condition is true (or exists).
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 1 - the specified condition is false (or does not exist).
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 2 - command line usage errors (including bad keywords)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 3 - command failed to perform the test due to a fatal error
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If the -n option is specified:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 0 - the specified condition is false (or does not exist).
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 1 - the specified condition is true (or exists).
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 2 - command line usage errors (including bad keywords)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 3 - command failed to perform the test due to a fatal error
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <stdio.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <sys/mnttab.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <sys/mntent.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <stdarg.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <stdlib.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <string.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <strings.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <fcntl.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <ctype.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <sys/types.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <sys/stat.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <unistd.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <locale.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <errno.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <sys/param.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <assert.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <instzones_api.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <pkglib.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <install.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <libinst.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <libadm.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <messages.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include "pkgcond.h"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include "pkgcond_msgs.h"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* Should be defined by cc -D */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#if !defined(TEXT_DOMAIN)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define TEXT_DOMAIN "SYS_TEST"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#endif
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* commands to execute */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define LS_CMD "/usr/bin/ls"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * type definition and "types" for testPath()
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandtypedef enum {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland TEST_EXISTS = 0x01,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland TEST_NOT_EXISTS = 0x02,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland TEST_IS_DIRECTORY = 0x04,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland TEST_IS_FILE = 0x08,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland TEST_NOT_DIRECTORY = 0x10,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland TEST_NOT_FILE = 0x20,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland TEST_IS_SYMBOLIC_LINK = 0x40,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland TEST_NOT_SYMBOLIC_LINK = 0x80,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland TEST_GLOBAL_TOKEN_IN_FILE = 0x100
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland} TEST_TYPES;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* holds file system info */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstruct fsi_t {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *fsi_mntOptions;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *fsi_fsType;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *fsi_mntPoint;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland};
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandtypedef struct fsi_t FSI_T;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* holds parsed global data */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstruct globalData_t {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* initial install: PKG_INIT_INSTALL=true */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland boolean_t gd_initialInstall;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* global zone install: SUNW_PKG_INSTALL_ZONENAME=global */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland boolean_t gd_globalZoneInstall;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* non-global zone install: SUNW_PKG_INSTALL_ZONENAME!=global */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland boolean_t gd_nonglobalZoneInstall;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* non-global zone is in a mounted state */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland boolean_t inMountedState;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* sorted list of all mounted file systems */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland FSI_T *gd_fileSystemConfig;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* number of mounted file systems in list */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland long gd_fileSystemConfigLen;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* current zone name */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *gd_zoneName;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* SUNW_PKGCOND_GLOBAL_DATA:parentZone:zoneName */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *gd_parentZoneName;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* SUNW_PKGCOND_GLOBAL_DATA:parentZone:zoneType */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *gd_parentZoneType;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* root path to target: PKG_INSTALL_ROOT */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *gd_installRoot;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* SUNW_PKGCOND_GLOBAL_DATA:currentZone:zoneName */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *gd_currentZoneName;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* SUNW_PKGCOND_GLOBAL_DATA:currentZone:zoneType */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *gd_currentZoneType;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* path provided on command line */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *gd_cmdline_path;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland};
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandtypedef struct globalData_t GLOBALDATA_T;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* holds subcommands and their definitions */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstruct cmd_t {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *c_name;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *c_args;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int (*c_func)(int argc, char **argv, GLOBALDATA_T *a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland};
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandtypedef struct cmd_t CMD_T;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* Command function prototypes */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int cmd_can_add_driver(int argc, char **argv,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland GLOBALDATA_T *a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int cmd_can_remove_driver(int argc, char **argv,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland GLOBALDATA_T *a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int cmd_can_update_driver(int argc, char **argv,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland GLOBALDATA_T *a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int cmd_is_alternative_root(int argc, char **argv,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland GLOBALDATA_T *a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int cmd_is_boot_environment(int argc, char **argv,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland GLOBALDATA_T *a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int cmd_is_diskless_client(int argc, char **argv,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland GLOBALDATA_T *a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int cmd_is_global_zone(int argc, char **argv,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland GLOBALDATA_T *a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int cmd_is_mounted_miniroot(int argc, char **argv,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland GLOBALDATA_T *a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int cmd_is_netinstall_image(int argc, char **argv,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland GLOBALDATA_T *a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int cmd_is_nonglobal_zone(int argc, char **argv,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland GLOBALDATA_T *a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int cmd_is_path_writable(int argc, char **argv,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland GLOBALDATA_T *a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int cmd_is_running_system(int argc, char **argv,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland GLOBALDATA_T *a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int cmd_is_what(int argc, char **argv,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland GLOBALDATA_T *a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* Utility function Prototypes */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic boolean_t getNegateResults(void);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic boolean_t recursionCheck(int *r_recursion, char *a_function);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int adjustResults(int a_result);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int calculateFileSystemConfig(GLOBALDATA_T *a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int getRootPath(char **r_rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int getZoneName(char **r_zoneName);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int mountOptionPresent(char *a_mntOptions, char *a_opt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int parseGlobalData(char *a_envVar, GLOBALDATA_T **a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int resolvePath(char **r_path);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int setRootPath(char *a_path, char *a_envVar,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland boolean_t a_mustExist);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int testPath(TEST_TYPES a_tt, char *format, ...);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int usage(char *a_format, ...);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int findToken(char *path, char *token);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char *getMountOption(char **p);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic void dumpGlobalData(GLOBALDATA_T *a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic void removeLeadingWhitespace(char **a_str);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic void setNegateResults(boolean_t setting);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic void setVerbose(boolean_t);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic void sortedInsert(FSI_T **r_list, long *a_listSize,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *a_mntPoint, char *a_fsType, char *a_mntOptions);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic void setCmdLinePath(char **a_path, char **args,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int num_args);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* local static data */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic boolean_t _negateResults = B_FALSE;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char *_rootPath = "/";
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* define subcommand data structure */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic CMD_T cmds[] = {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland { "can_add_driver", " [path]",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland cmd_can_add_driver },
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland { "can_remove_driver", " [path]",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland cmd_can_remove_driver },
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland { "can_update_driver", " [path]",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland cmd_can_update_driver },
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland { "is_alternative_root", " [path]",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland cmd_is_alternative_root },
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland { "is_boot_environment", " [path]",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland cmd_is_boot_environment },
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland { "is_diskless_client", " [path]",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland cmd_is_diskless_client },
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland { "is_global_zone", " [path]",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland cmd_is_global_zone },
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland { "is_mounted_miniroot", " [path]",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland cmd_is_mounted_miniroot },
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland { "is_netinstall_image", " [path]",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland cmd_is_netinstall_image },
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland { "is_nonglobal_zone", " [path]",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland cmd_is_nonglobal_zone },
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland { "is_path_writable", " path",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland cmd_is_path_writable },
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland { "is_running_system", " [path]",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland cmd_is_running_system },
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland { "is_what", " [path]",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland cmd_is_what },
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* last one must be all NULLs */
6e1ae2a33c618c4c2b14aec7d2f21743ddea5837Gary Pennington { NULL, NULL, NULL }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland};
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *****************************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * main
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *****************************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: main
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: main processing loop for pkgcond *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Return: 0 - condition is satisfied (true)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * 1 - condition is not satisfied (false)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * 2 - command line usage errors
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * 3 - failure to determine condition
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandint
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandmain(int argc, char **argv)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland GLOBALDATA_T *gdt = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char **newargv;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *p;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int cur_cmd;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int i;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int newargc;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* make standard output non-buffered */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setbuf(stdout, NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* set the default text domain for messaging */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) setlocale(LC_ALL, "");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) textdomain(TEXT_DOMAIN);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* remember command name */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland set_prog_name(argv[0]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* tell spmi zones interface how to access package output functions */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland z_set_output_functions(echo, echoDebug, progerr);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* set verbose mode if appropriate environment variable is set */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (getenv(ENV_VAR_VERBOSE)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* same as -v */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setVerbose(B_TRUE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* set debug mode if appropriate environment variable is set */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (getenv(ENV_VAR_DEBUG)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* same as -O debug */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* set sml tracing (sml.c) */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland smlSetVerbose(B_TRUE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* set log and echo (interactive) message tracing */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setVerbose(B_TRUE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* enable echoDebug debugging messages */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebugSetFlag(B_TRUE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* generate usage if no options or arguments specified */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc <= 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_NO_ARGUMENTS_SPECIFIED);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * process any arguments that can appear before the subcommand
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((i = getopt(argc, argv, ":O:vn?")) != EOF) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (i) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Not a public interface: the -O option allows the behavior
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * of the package tools to be modified. Recognized options:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * -> debug
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * ---> enable debugging output
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case 'O':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (p = strtok(optarg, ","); p != NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland p = strtok(NULL, ",")) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* debug - enable all tracing */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(p, "debug") == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* set sml tracing */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland smlSetVerbose(B_TRUE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* set log/echo tracing */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setVerbose(B_TRUE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* enable debugging messages */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebugSetFlag(B_TRUE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland continue;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland progerr(ERR_INVALID_O_OPTION, p);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (adjustResults(R_USAGE));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Public interface: enable verbose (debug) output.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case 'v': /* verbose mode enabled */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* set command tracing only */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setVerbose(B_TRUE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Public interface: negate output results.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case 'n':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setNegateResults(B_TRUE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * unrecognized option
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '?':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_INVALID_OPTION_SPECIFIED, optopt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * done processing options that can preceed subcommand
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* error if no subcommand specified */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((argc-optind) <= 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_NO_ARGUMENTS_SPECIFIED);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* parse global data if environment variable set */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (parseGlobalData(PKGCOND_GLOBAL_VARIABLE, &gdt) != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_CANNOT_USE_GLOBAL_DATA,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland PKGCOND_GLOBAL_VARIABLE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (setRootPath(gdt->gd_installRoot,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (strcmp(gdt->gd_installRoot, "/") == 0) ? NULL :
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ENV_VAR_SET, B_TRUE) != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_CANNOT_SET_ROOT_PATH,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ENV_VAR_PKGROOT);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* set path provided on the command line */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland setCmdLinePath(&(gdt->gd_cmdline_path), argv, argc);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_CMDLINE_PATH,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland gdt->gd_cmdline_path == NULL ? "" : gdt->gd_cmdline_path);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* determine how file systems are layered in this zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (calculateFileSystemConfig(gdt) != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_CANNOT_CALC_FS_CONFIG);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* dump global data read in (only if debugging) */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland dumpGlobalData(gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* search for specified subcommand and execute if found */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (cur_cmd = 0; cmds[cur_cmd].c_name != NULL; cur_cmd++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (ci_streq(argv[optind], cmds[cur_cmd].c_name)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int result;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* make subcommand the first option */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland newargc = argc - optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland newargv = argv + optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland opterr = optind = 1; optopt = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* call subcommand with its own argc/argv */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland result = cmds[cur_cmd].c_func(newargc, newargv, gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process result code and exit */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland result = adjustResults(result);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_RESULTS, result);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (result);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* subcommand not found - output error message and exit with error */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_BAD_SUB, argv[optind]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_UNRECOGNIZED_CONDITION_SPECIFIED);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *****************************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * command implementation functions
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *****************************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: cmd_is_diskless_client
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: determine if target is a diskless client
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Scope: public
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: argc,argv:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - optional path to target to test
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 0 - success
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * != 0 - failure
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * IMPLEMENTATION:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be initial installation to the install root
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be installation of a zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be a whole root non-global zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be a non-global zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be a mounted mini-root
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be a netinstall image
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be a boot environment
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - The package "SUNWdclnt" must be installed at "/"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - The root path must not be "/"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - The path "/export/exec/Solaris_\*\/usr" must exist at "/"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - The directory "$ROOTDIR/../templates" must exist
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandcmd_is_diskless_client(int argc, char **argv, GLOBALDATA_T *a_gdt)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *rootPath = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char cmd[MAXPATHLEN+1];
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int c;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int r;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int rc;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char *cmdName = "is_diskless_client";
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int recursion = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process any command line options */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((c = getopt(argc, argv, ":")) != EOF) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (c) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '\0': /* prevent end-of-loop not reached warning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '?':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, optopt, cmdName);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* prevent recursion */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (recursionCheck(&recursion, cmdName) == B_FALSE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * a diskless client cannot be any of the following
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
6e1ae2a33c618c4c2b14aec7d2f21743ddea5837Gary Pennington /* cannot be non-global zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
6e1ae2a33c618c4c2b14aec7d2f21743ddea5837Gary Pennington r = cmd_is_nonglobal_zone(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot be mounted miniroot */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_mounted_miniroot(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot be a netinstall image */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_netinstall_image(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot be a boot environment */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_boot_environment(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* no need to guard against recursion any more */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland recursion--;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* return failure if any of the preceeding are true */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (r) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_SUCCESS:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_FAILURE:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_USAGE:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_ERROR:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* normalize argc/argv */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argc -= optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argv += optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* error if more than one argument */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc > 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_UNRECOGNIZED_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process root path if first argument present */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc == 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (setRootPath(argv[0], "argv[0]", B_TRUE) != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get current root path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = getRootPath(&rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* start of command debugging information */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_ROOTPATH_IS, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* SUNWdclnt must be installed */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (pkgTestInstalled("SUNWdclnt", "/") != B_TRUE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IDLC_PKG_NOT_INSTALLED,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "SUNWdclnt", "/");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* - $ROOTDIR must not be "/" */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(rootPath, "/") == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IDLC_ROOTPATH_BAD, rootPath, "/");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* - zone name must be global */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(a_gdt->gd_zoneName, GLOBAL_ZONENAME) != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IDLC_ZONE_BAD, rootPath,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland GLOBAL_ZONENAME);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * /export/exec/Solaris_"*"/usr must exist;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * create ls command to test:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * /usr/bin/ls /export/exec/Solaris_"*"/usr
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) snprintf(cmd, sizeof (cmd), "%s %s >/dev/null 2>&1",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland LS_CMD, "/export/exec/Solaris_*/usr");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* execute command */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rc = system(cmd);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* return error if ls returns something other than "0" */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (rc != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IDLC_PATH_MISSING,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/export/exec/Solaris_*/usr");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * /usr must be empty on a diskless client:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * create ls command to test:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * /usr/bin/ls -d1 $ROOTDIR/usr/\*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) snprintf(cmd, sizeof (cmd), "%s %s %s/%s >/dev/null 2>&1",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland LS_CMD, "-1d", rootPath, "usr/*");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* execute command */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rc = system(cmd);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* return error if ls returns "0" */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (rc == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IDLC_USR_IS_NOT_EMPTY,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* there must be a templates directory at ${ROOTPATH}/../templates */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_EXISTS|TEST_IS_DIRECTORY,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, "../templates");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IDLC_NO_TEMPLATES_PATH,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, rootPath, "../templates");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* must not be initial installation to the install root */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_gdt->gd_initialInstall == B_TRUE) &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (strcmp(a_gdt->gd_installRoot, rootPath) == 0)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* initial install: install root cannot be diskless client */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IDLC_INITIAL_INSTALL, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* must not be installation of a zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_gdt->gd_globalZoneInstall == B_TRUE) ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (a_gdt->gd_nonglobalZoneInstall == B_TRUE)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* initial zone install: no path can be diskless client */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IDLC_ZONE_INSTALL, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* the path is a diskless client */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IDLC_PATH_IS_DISKLESS_CLIENT, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: cmd_is_global_zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: determine if target is a global zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Scope: public
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: argc,argv:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - optional path to target to test
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 0 - success
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * != 0 - failure
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * IMPLEMENTATION:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be initial installation to the install root
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be installation of a non-global zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be a non-global zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be a mounted mini-root
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be a netinstall image
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be a diskless client
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - if $ROOTDIR is "/":
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * -- if zone name is "GLOBAL", then is a global zone;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * -- else not a global zone.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - $ROOTDIR/etc/zones must exist and be a directory
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - $ROOTDIR/.tmp_proto must not exist
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - $ROOTDIR/var must exist and must not be a symbolic link
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandcmd_is_global_zone(int argc, char **argv, GLOBALDATA_T *a_gdt)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *rootPath = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int c;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int r;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char *cmdName = "is_global_zone";
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int recursion = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process any command line options */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((c = getopt(argc, argv, ":")) != EOF) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (c) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '\0': /* prevent end-of-loop not reached warning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '?':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, optopt, cmdName);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* prevent recursion */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (recursionCheck(&recursion, cmdName) == B_FALSE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * a global zone cannot be any of the following
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot be a non-global zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_nonglobal_zone(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot be a mounted miniroot */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_mounted_miniroot(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot be a netinstall image */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_netinstall_image(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot be a diskless client */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_diskless_client(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* no need to guard against recursion any more */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland recursion--;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* return failure if any of the preceeding are true */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (r) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_SUCCESS:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_FAILURE:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_USAGE:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_ERROR:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* normalize argc/argv */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argc -= optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argv += optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* error if more than one argument */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc > 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_UNRECOGNIZED_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process root path if first argument present */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc == 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (setRootPath(argv[0], "argv[0]", B_TRUE) != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get current root path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = getRootPath(&rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* start of command debugging information */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_ROOTPATH_IS, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* must not be initial installation to the install root */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_gdt->gd_initialInstall == B_TRUE) &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (strcmp(a_gdt->gd_installRoot, rootPath) == 0)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* initial install: install root cannot be global zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_ISGZ_INITIAL_INSTALL, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* must not be installation of a non-global zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_gdt->gd_nonglobalZoneInstall == B_TRUE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* initial nonglobal zone install: no path can be global zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_ISGZ_NGZ_ZONE_INSTALL, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* handle if global zone installation to the install root */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_gdt->gd_globalZoneInstall == B_TRUE) &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (strcmp(a_gdt->gd_installRoot, rootPath) == 0)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* the path is a global zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_ISGZ_PATH_IS_GLOBAL_ZONE,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* true if current root is "/" and zone name is GLOBAL_ZONENAME */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(rootPath, "/") == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(a_gdt->gd_zoneName, GLOBAL_ZONENAME) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* the path is a global zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_ISGZ_PATH_IS_GLOBAL_ZONE,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* inside a non-global zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_ISGZ_ZONENAME_ISNT_GLOBAL,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, a_gdt->gd_zoneName);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * current root is not "/" - see if target looks like a global zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - rootpath is not "/"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - and $ROOTDIR/etc/zones exists
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - and $ROOTDIR/.tmp_proto does not exist
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - and $ROOTDIR/var is not a symbolic link
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* not global zone if /etc/zones does not exist */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_EXISTS|TEST_IS_DIRECTORY,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, "/etc/zones");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_ISGZ_PATH_ISNT_DIRECTORY,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/etc/zones");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* .tmp_proto must not exist */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_NOT_EXISTS,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, ".tmp_proto");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_ISGZ_PATH_EXISTS,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/.tmp_proto");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* /var must not be a symbolic link */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_EXISTS|TEST_NOT_SYMBOLIC_LINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, "/var");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_ISGZ_PATH_IS_SYMLINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/var");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* the path is a global zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_ISGZ_PATH_IS_GLOBAL_ZONE, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: cmd_is_netinstall_image
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: determine if target is a net install image
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Scope: public
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: argc,argv:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - optional path to target to test
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 0 - success
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * != 0 - failure
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * IMPLEMENTATION:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be initial installation to the install root
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be installation of a zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be a global zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be a mounted mini-root
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - zone name must be "global"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - $ROOTDIR/.tmp_proto must exist and must be a directory
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - $ROOTDIR/var must exist and must be a symbolic link
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - $ROOTDIR/tmp/kernel must exist and must be a directory
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - $ROOTDIR/.tmp_proto/kernel must exist and must be a symbolic link
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandcmd_is_netinstall_image(int argc, char **argv, GLOBALDATA_T *a_gdt)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *rootPath = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int c;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int r;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char *cmdName = "is_netinstall_image";
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int recursion = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process any command line options */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((c = getopt(argc, argv, ":")) != EOF) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (c) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '\0': /* prevent end-of-loop not reached warning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '?':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, optopt, cmdName);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* prevent recursion */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (recursionCheck(&recursion, cmdName) == B_FALSE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* a netinstall image cannot be a global zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_global_zone(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* no need to guard against recursion any more */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland recursion--;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (r) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_SUCCESS:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_FAILURE:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_USAGE:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_ERROR:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* normalize argc/argv */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argc -= optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argv += optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* error if more than one argument */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc > 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_UNRECOGNIZED_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process root path if first argument present */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc == 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (setRootPath(argv[0], "argv[0]", B_TRUE) != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get current root path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = getRootPath(&rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* start of command debugging information */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_ROOTPATH_IS, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* current zone name must be "global" */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(a_gdt->gd_zoneName, GLOBAL_ZONENAME) != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_INIM_BAD_CURRENT_ZONE,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, GLOBAL_ZONENAME);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot be a mounted_miniroot */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (cmd_is_mounted_miniroot(argc, argv, a_gdt) == R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IMRT_PATH_IS_MOUNTED_MINIROOT,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* $ROOTDIR/.tmp_proto exists */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_EXISTS|TEST_IS_DIRECTORY,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, ".tmp_proto");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_INIM_PATH_ISNT_DIRECTORY,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/.tmp_proto");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* $ROOTDIR/var is a symbolic link */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_IS_SYMBOLIC_LINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, "/var");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_INIM_PATH_ISNT_SYMLINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/var");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* $ROOTDIR/tmp/kernel does exist */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_EXISTS|TEST_IS_DIRECTORY,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, "/tmp/kernel");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_INIM_PATH_ISNT_DIRECTORY,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/tmp/kernel");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* $ROOTDIR/.tmp_proto/kernel is a symbolic link */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_IS_SYMBOLIC_LINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, "/.tmp_proto/kernel");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_INIM_PATH_ISNT_SYMLINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/.tmp_proto/kernel");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* must not be initial installation to the install root */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_gdt->gd_initialInstall == B_TRUE) &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (strcmp(a_gdt->gd_installRoot, rootPath) == 0)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* initial install: install root cannot be netinstall image */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_INIM_INITIAL_INSTALL, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* must not be installation of a zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_gdt->gd_globalZoneInstall == B_TRUE) ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (a_gdt->gd_nonglobalZoneInstall == B_TRUE)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* initial zone install: no path can be netinstall image */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_INIM_ZONE_INSTALL, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* target is a netinstall image */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_INIM_PATH_IS_NETINSTALL_IMAGE, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: cmd_is_mounted_miniroot
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: determine if target is a mounted miniroot image
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Scope: public
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: argc,argv:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - optional path to target to test
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 0 - success
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * != 0 - failure
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * IMPLEMENTATION:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be initial installation to the install root
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be installation of a zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - zone name must be "global"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - $ROOTDIR/tmp/kernel must exist and must be a symbolic link
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - $ROOTDIR/tmp/root/kernel must exist and must be a directory
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandcmd_is_mounted_miniroot(int argc, char **argv, GLOBALDATA_T *a_gdt)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *rootPath = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int c;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int r;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char *cmdName = "is_mounted_miniroot";
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int recursion = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process any command line options */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((c = getopt(argc, argv, ":")) != EOF) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (c) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '\0': /* prevent end-of-loop not reached warning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '?':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, optopt, cmdName);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* prevent recursion */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (recursionCheck(&recursion, cmdName) == B_FALSE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland recursion--;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* normalize argc/argv */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argc -= optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argv += optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* error if more than one argument */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc > 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_UNRECOGNIZED_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process root path if first argument present */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc == 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (setRootPath(argv[0], "argv[0]", B_TRUE) != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get current root path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = getRootPath(&rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* start of command debugging information */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_ROOTPATH_IS, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* current zone name must be "global" */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(a_gdt->gd_zoneName, GLOBAL_ZONENAME) != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IMRT_BAD_CURRENT_ZONE,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, GLOBAL_ZONENAME);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* $ROOTDIR/tmp/kernel is a symbolic link */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_IS_SYMBOLIC_LINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, "/tmp/kernel");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IMRT_PATH_ISNT_SYMLINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/tmp/kernel");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* $ROOTDIR/tmp/root/kernel is a directory */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_EXISTS|TEST_IS_DIRECTORY,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, "/tmp/root/kernel");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IMRT_PATH_ISNT_DIRECTORY,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/tmp/root/kernel");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* must not be initial installation to the install root */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_gdt->gd_initialInstall == B_TRUE) &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (strcmp(a_gdt->gd_installRoot, rootPath) == 0)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* initial install: install root cannot be mounted miniroot */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IMRT_INITIAL_INSTALL, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* must not be installation of a zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_gdt->gd_globalZoneInstall == B_TRUE) ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (a_gdt->gd_nonglobalZoneInstall == B_TRUE)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* initial zone install: no path can be mounted miniroot */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IMRT_ZONE_INSTALL, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* target is a mounted miniroot */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IMRT_PATH_IS_MOUNTED_MINIROOT, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: cmd_is_nonglobal_zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: determine if target is a global zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Scope: public
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: argc,argv:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - optional path to target to test
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 0 - success
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * != 0 - failure
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be initial installation to the install root
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be installation of a global zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - success if installation of a non-global zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandcmd_is_nonglobal_zone(int argc, char **argv, GLOBALDATA_T *a_gdt)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *rootPath = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int c;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int r;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char *cmdName = "is_nonglobal_zone";
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int recursion = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process any command line options */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((c = getopt(argc, argv, ":")) != EOF) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (c) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '\0': /* prevent end-of-loop not reached warning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '?':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, optopt, cmdName);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* prevent recursion */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (recursionCheck(&recursion, cmdName) == B_FALSE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland recursion--;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* normalize argc/argv */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argc -= optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argv += optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* error if more than one argument */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc > 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_UNRECOGNIZED_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process root path if first argument present */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc == 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (setRootPath(argv[0], "argv[0]", B_TRUE) != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get current root path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = getRootPath(&rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* start of command debugging information */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_ROOTPATH_IS, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* handle if non-global zone installation to the install root */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_gdt->gd_nonglobalZoneInstall == B_TRUE) &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (strcmp(a_gdt->gd_installRoot, rootPath) == 0)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_NGZN_INSTALL_ZONENAME_IS_NGZ,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, a_gdt->gd_zoneName);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* must not be initial installation to the install root */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_gdt->gd_initialInstall == B_TRUE) &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (strcmp(a_gdt->gd_installRoot, rootPath) == 0)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* initial install: install root cannot be non-global zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_NGZN_INITIAL_INSTALL, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* must not be installation of a global zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_gdt->gd_globalZoneInstall == B_TRUE) ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (a_gdt->gd_nonglobalZoneInstall == B_TRUE)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* initial global zone install: no path can be nonglobal zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_NGZN_GLOBAL_ZONE_INSTALL, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *********************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if root directory is "/" then the only thing that needs to be done is
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * to test the zone name directly - if the zone name is "global" then
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the target is not a non-global zone; otherwise if the zone name is
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * not "global" then the target IS a non-global zone.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *********************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(rootPath, "/") == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* target is current running root */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(a_gdt->gd_zoneName, GLOBAL_ZONENAME) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* in the global zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_NGZN_ZONENAME_ISNT_NGZ,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, a_gdt->gd_zoneName);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* in a non-global zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_NGZN_ZONENAME_IS_NGZ,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, a_gdt->gd_zoneName);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * $ROOTDIR/etc/zones/index must exist in a global zone. It also
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * exists in a non-global zone after s10u4 but we can't check that
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * since it is undeterministic for all releases so we only check
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * for the global zone here.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_EXISTS, "%s/%s", rootPath, "/etc/zones/index");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r == R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* See if "global" exists in .../etc/zones/index */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (testPath(TEST_GLOBAL_TOKEN_IN_FILE, "%s/%s", rootPath,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "/etc/zones/index") != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_NGZN_ZONENAME_ISNT_NGZ,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, GLOBAL_ZONENAME);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *********************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If the root directory is "/" then you can use only the zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * name to determine if the zone is non-global or not since the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * package is being installed or removed to the current "zone".
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Since the root directory being tested is not "/" then you have to
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * look into the target to try and infer zone type using means other
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * than the zone name only.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *********************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* reject if any items found that cannot be in a non-global zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* .tmp_proto must not exist */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_NOT_EXISTS, "%s/%s", rootPath, ".tmp_proto");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* $R/.tmp_proto cannot exist in a non-global zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_NGZN_PATH_EXISTS,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/.tmp_proto");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* /var must not be a symbolic link */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_EXISTS|TEST_NOT_SYMBOLIC_LINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, "/var");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* $R/var cannot be a symbolic link in a non-global zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_NGZN_PATH_DOES_NOT_EXIST,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/var");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* $ROOTDIR/tmp/root/kernel must not exist */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_NOT_EXISTS,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, "/tmp/root/kernel");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* $R/tmp/root/kernel cannot exist in a non-global zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_NGZN_PATH_EXISTS,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/tmp/root/kernel");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *********************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * no items exist in $ROOTDIR that identify something other than
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * a non-global zone.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if in global zone no more tests possible: is a non-global zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *********************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(a_gdt->gd_zoneName, GLOBAL_ZONENAME) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* in the global zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_NGZN_IN_GZ_IS_NONGLOBAL_ZONE,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *********************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * In non-global zone: interrogate zone name and type.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * The parent zone is the zone that the "pkgadd" or "pkgrm" command was
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * run in. The child zone is the zone that the "pkginstall" or
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * "pkgremove" command was run in.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *********************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If parent zone name and current zone name defined, and
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * both zone names are the same, since pkgcond is running
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * inside of a non-global zone, this is how the scratch
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * zone is implemented, so target is a non-global zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_gdt->gd_parentZoneName != NULL) &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (a_gdt->gd_currentZoneName != NULL) &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (strcmp(a_gdt->gd_parentZoneName,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland a_gdt->gd_currentZoneName) == 0)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* parent and current zone name identical: non-gz */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_NGZN_PARENT_CHILD_SAMEZONE,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, a_gdt->gd_parentZoneName);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
6e1ae2a33c618c4c2b14aec7d2f21743ddea5837Gary Pennington * In non-global zone if zone specific read only FS's exist
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * or it is in a mounted state.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
6e1ae2a33c618c4c2b14aec7d2f21743ddea5837Gary Pennington if (a_gdt->inMountedState) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_NGZN_IS_NONGLOBAL_ZONE, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the parent and current zone name are not the same;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * interrogate the zone types: the parent must be global
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * and the current must be non-global, which would be set
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * when a package command is run in the global zone that in
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * turn runs a package command within the non-global zone.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if defined, parent zone type must be "global" */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_gdt->gd_parentZoneType != NULL) &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (strcmp(a_gdt->gd_parentZoneType, "nonglobal") == 0)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_NGZN_BAD_PARENT_ZONETYPE,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "nonglobal");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if defined, current zone type must be "nonglobal" */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_gdt->gd_currentZoneType != NULL) &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (strcmp(a_gdt->gd_currentZoneType, GLOBAL_ZONENAME) == 0)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_NGZN_BAD_CURRENT_ZONETYPE,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, GLOBAL_ZONENAME);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *********************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * no other tests possible: target is a non-global zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *********************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_NGZN_IS_NONGLOBAL_ZONE, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: cmd_is_running_system
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: determine if target is a global zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Scope: public
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: argc,argv:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - optional path to target to test
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 0 - success
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * != 0 - failure
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * IMPLEMENTATION:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be initial installation to the install root
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be installation of a zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be a diskless client
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - $ROOTDIR must be "/"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - zone name must be "global"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandcmd_is_running_system(int argc, char **argv, GLOBALDATA_T *a_gdt)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *rootPath = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int c;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int r;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char *cmdName = "is_running_system";
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int recursion = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process any command line options */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((c = getopt(argc, argv, ":")) != EOF) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (c) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '\0': /* prevent end-of-loop not reached warning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '?':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, optopt, cmdName);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* prevent recursion */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (recursionCheck(&recursion, cmdName) == B_FALSE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* a running system cannot be a diskless client */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_diskless_client(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* no need to guard against recursion any more */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland recursion--;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (r) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_SUCCESS:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_FAILURE:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_USAGE:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_ERROR:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* normalize argc/argv */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argc -= optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argv += optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* error if more than one argument */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc > 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_UNRECOGNIZED_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process root path if first argument present */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc == 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (setRootPath(argv[0], "argv[0]", B_TRUE) != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get current root path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = getRootPath(&rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* start of command debugging information */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_ROOTPATH_IS, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if root path is "/" then check zone name */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(rootPath, "/") != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IRST_ROOTPATH_BAD, rootPath, "/");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* zone name must be global */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(a_gdt->gd_zoneName, GLOBAL_ZONENAME) != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IRST_ZONE_BAD, rootPath,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland GLOBAL_ZONENAME);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* must not be initial installation to the install root */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_gdt->gd_initialInstall == B_TRUE) &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (strcmp(a_gdt->gd_installRoot, rootPath) == 0)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* initial install: install root cannot be the running system */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IRST_INITIAL_INSTALL, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* must not be installation of a zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_gdt->gd_globalZoneInstall == B_TRUE) ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (a_gdt->gd_nonglobalZoneInstall == B_TRUE)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* initial zone install: no path can be running system */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IRST_ZONE_INSTALL, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* target is a running system */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IRST_PATH_IS_RUNNING_SYSTEM, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: cmd_can_add_driver
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: determine if target is a global zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Scope: public
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: argc,argv:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - optional path to target to test
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 0 - success
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * != 0 - failure
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Implementation:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * A driver can be added to the system if the components of a Solaris
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * instance capable of loading drivers is present and it is not the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * currently running system.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandcmd_can_add_driver(int argc, char **argv, GLOBALDATA_T *a_gdt)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *rootPath = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int c;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int r;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char *cmdName = "can_add_driver";
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int recursion = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process any command line options */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((c = getopt(argc, argv, ":")) != EOF) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (c) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '\0': /* prevent end-of-loop not reached warning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '?':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, optopt, cmdName);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* prevent recursion */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (recursionCheck(&recursion, cmdName) == B_FALSE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* see if this is the current running system */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_running_system(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot be a diskless client */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_diskless_client(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* no need to guard against recursion any more */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland recursion--;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (r) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_SUCCESS:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* is a running system */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_FAILURE:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* not a running syste */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_USAGE:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_ERROR:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot determine if is a running system */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* normalize argc/argv */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argc -= optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argv += optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* error if more than one argument */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc > 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_UNRECOGNIZED_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process root path if first argument present */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc == 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (setRootPath(argv[0], "argv[0]", B_TRUE) != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get current root path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = getRootPath(&rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* start of command debugging information */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_ROOTPATH_IS, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* /etc must exist and must not be a symbolic link */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_EXISTS|TEST_NOT_SYMBOLIC_LINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, "/etc");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_ADDV_PATH_IS_SYMLINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/etc");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* /platform must exist and must not be a symbolic link */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_EXISTS|TEST_NOT_SYMBOLIC_LINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, "/platform");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_ADDV_PATH_IS_SYMLINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/platform");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* /kernel must exist and must not be a symbolic link */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_EXISTS|TEST_NOT_SYMBOLIC_LINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, "/kernel");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_ADDV_PATH_IS_SYMLINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/kernel");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* can add a driver */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_ADDV_YES, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: cmd_can_update_driver
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: determine if target is a global zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Scope: public
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: argc,argv:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - optional path to target to test
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 0 - success
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * != 0 - failure
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Implementation:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * A driver can be added to the system if the components of a Solaris
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * instance capable of loading drivers is present and it is not the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * currently running system.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandcmd_can_update_driver(int argc, char **argv, GLOBALDATA_T *a_gdt)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *rootPath = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int c;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int r;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char *cmdName = "can_update_driver";
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int recursion = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process any command line options */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((c = getopt(argc, argv, ":")) != EOF) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (c) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '\0': /* prevent end-of-loop not reached warning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '?':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, optopt, cmdName);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* prevent recursion */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (recursionCheck(&recursion, cmdName) == B_FALSE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* see if this is the current running system */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_running_system(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot be a diskless client */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_diskless_client(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* no need to guard against recursion any more */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland recursion--;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (r) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_SUCCESS:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* is a running system */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_FAILURE:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* not a running syste */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_USAGE:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_ERROR:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot determine if is a running system */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* normalize argc/argv */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argc -= optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argv += optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* error if more than one argument */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc > 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_UNRECOGNIZED_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process root path if first argument present */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc == 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (setRootPath(argv[0], "argv[0]", B_TRUE) != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get current root path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = getRootPath(&rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* start of command debugging information */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_ROOTPATH_IS, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* /etc must exist and must not be a symbolic link */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_EXISTS|TEST_NOT_SYMBOLIC_LINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, "/etc");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_UPDV_PATH_IS_SYMLINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/etc");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* /platform must exist and must not be a symbolic link */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_EXISTS|TEST_NOT_SYMBOLIC_LINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, "/platform");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_UPDV_PATH_IS_SYMLINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/platform");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* /kernel must exist and must not be a symbolic link */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_EXISTS|TEST_NOT_SYMBOLIC_LINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, "/kernel");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_UPDV_PATH_IS_SYMLINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/kernel");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* can update driver */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_UPDV_YES, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: cmd_can_remove_driver
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: determine if target is a global zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Scope: public
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: argc,argv:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - optional path to target to test
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 0 - success
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * != 0 - failure
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Implementation:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * A driver can be added to the system if the components of a Solaris
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * instance capable of loading drivers is present and it is not the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * currently running system.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandcmd_can_remove_driver(int argc, char **argv, GLOBALDATA_T *a_gdt)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *rootPath = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int c;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int r;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char *cmdName = "can_remove_driver";
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int recursion = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process any command line options */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((c = getopt(argc, argv, ":")) != EOF) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (c) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '\0': /* prevent end-of-loop not reached warning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '?':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, optopt, cmdName);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* prevent recursion */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (recursionCheck(&recursion, cmdName) == B_FALSE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* see if this is the current running system */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_running_system(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot be a diskless client */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_diskless_client(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* no need to guard against recursion any more */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland recursion--;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (r) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_SUCCESS:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* is a running system */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_FAILURE:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* not a running syste */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_USAGE:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_ERROR:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot determine if is a running system */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* normalize argc/argv */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argc -= optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argv += optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* error if more than one argument */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc > 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_UNRECOGNIZED_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process root path if first argument present */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc == 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (setRootPath(argv[0], "argv[0]", B_TRUE) != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get current root path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = getRootPath(&rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* start of command debugging information */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_ROOTPATH_IS, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* /etc must exist and must not be a symbolic link */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_EXISTS|TEST_NOT_SYMBOLIC_LINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, "/etc");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_RMDV_PATH_IS_SYMLINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/etc");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* /platform must exist and must not be a symbolic link */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_EXISTS|TEST_NOT_SYMBOLIC_LINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, "/platform");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_RMDV_PATH_IS_SYMLINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/platform");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* /kernel must exist and must not be a symbolic link */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_EXISTS|TEST_NOT_SYMBOLIC_LINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, "/kernel");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_RMDV_PATH_IS_SYMLINK,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/kernel");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* can remove driver */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_RMDV_YES, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: cmd_is_path_writable
6e1ae2a33c618c4c2b14aec7d2f21743ddea5837Gary Pennington * Description: determine if target path is writable
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Scope: public
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: argc,argv:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - optional path to target to test
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 0 - success
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * != 0 - failure
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * IMPLEMENTATION:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - path must be found in the file systems configured
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - mount options must not include "read only"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandcmd_is_path_writable(int argc, char **argv, GLOBALDATA_T *a_gdt)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland FSI_T *list;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *rootPath = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int c;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int n;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int nn;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int r;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland long listSize;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland long rootPathLen;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char *cmdName = "is_path_writable";
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int recursion = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process any command line options */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((c = getopt(argc, argv, ":")) != EOF) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (c) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '\0': /* prevent end-of-loop not reached warning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '?':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, optopt, cmdName);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* prevent recursion */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (recursionCheck(&recursion, cmdName) == B_FALSE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland recursion--;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* normalize argc/argv */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argc -= optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argv += optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* error if more than one argument */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc > 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_UNRECOGNIZED_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process root path if first argument present */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc != 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(ERR_REQUIRED_ROOTPATH_MISSING, cmdName);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (setRootPath(argv[0], "argv[0]", B_TRUE) != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get current root path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = getRootPath(&rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* start of command debugging information */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_ROOTPATH_IS, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* search file system conf for this path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPathLen = strlen(rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list = a_gdt->gd_fileSystemConfig;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland listSize = a_gdt->gd_fileSystemConfigLen;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (nn = 0, n = 0; n < listSize; n++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland long mplen = strlen(list[n].fsi_mntPoint);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (rootPathLen < mplen) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* root path is longer than target, ignore */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland continue;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strncmp(rootPath, list[n].fsi_mntPoint, mplen) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* remember last partial match */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland nn = n;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_PWRT_INFO,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, list[nn].fsi_mntPoint, list[nn].fsi_fsType,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list[nn].fsi_mntOptions);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * need to determine if the mount point is writeable:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* see if the file system is mounted with the "read only" option */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = mountOptionPresent(list[nn].fsi_mntOptions, MNTOPT_RO);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r == R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_PWRT_READONLY,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, list[nn].fsi_mntOptions);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* target path is writable */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_PWRT_IS, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: cmd_is_alternative_root
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: determine if target is an alternative root
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Scope: public
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: argc,argv:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - optional path to target to test
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 0 - success
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * != 0 - failure
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Implementation:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - success if an initial installation to the install root
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * (an initial install to $PKG_INSTALL_ROOT means that $PKG_INSTALL_ROOT
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * points to an alternative root that is under construction)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be installation of a zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be a boot environment
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be a diskless client
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be a mounted miniroot
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be a netinstall image
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be a nonglobal zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be a running system
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - $ROOTDIR must not be "/"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - $ROOTDIR/var must exist
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandcmd_is_alternative_root(int argc, char **argv, GLOBALDATA_T *a_gdt)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *rootPath = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int c;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int r;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char *cmdName = "is_alternative_root";
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int recursion = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process any command line options */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((c = getopt(argc, argv, ":")) != EOF) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (c) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '\0': /* prevent end-of-loop not reached warning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '?':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, optopt, cmdName);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* prevent recursion */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (recursionCheck(&recursion, cmdName) == B_FALSE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * an alternative root cannot be any of the following
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot be a boot_environment */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_boot_environment(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot be a diskless_client */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_diskless_client(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot be a mounted_miniroot */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_mounted_miniroot(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot be a netinstall_image */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_netinstall_image(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot be a nonglobal_zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_nonglobal_zone(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot be a running_system */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_running_system(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* no need to guard against recursion any more */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland recursion--;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* return failure if any of the preceeding are true */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (r) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_SUCCESS:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_FAILURE:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_USAGE:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_ERROR:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* normalize argc/argv */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argc -= optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argv += optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* error if more than one argument */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc > 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_UNRECOGNIZED_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process root path if first argument present */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc == 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (setRootPath(argv[0], "argv[0]", B_TRUE) != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get current root path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = getRootPath(&rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* start of command debugging information */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_ROOTPATH_IS, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* return success if initial installation */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_gdt->gd_initialInstall == B_TRUE) &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (strcmp(a_gdt->gd_installRoot, rootPath) == 0)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IALR_INITIAL_INSTALL, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* root path must not be "/" */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(rootPath, "/") == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IALR_BAD_ROOTPATH, rootPath, "/");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* /var must exist */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_EXISTS,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, "/var");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IALR_PATH_DOES_NOT_EXIST,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rootPath, "/var");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* must not be installation of a zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_gdt->gd_globalZoneInstall == B_TRUE) ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (a_gdt->gd_nonglobalZoneInstall == B_TRUE)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* initial zone install: no path can be alternative root */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IALR_ZONE_INSTALL, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* target is an alternative root */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_IALR_IS, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: cmd_is_boot_environment
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: determine if target is an alternative, inactive boot environment
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Scope: public
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: argc,argv:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - optional path to target to test
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 0 - success
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * != 0 - failure
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * IMPLEMENTATION:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be initial installation to the install root
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be installation of a zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be a diskless client
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be a netinstall image
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - must not be a mounted miniroot
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - $ROOTDIR must not be "/"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - $ROOTDIR/etc/lutab must exist
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - $ROOTDIR/etc/lu must exist and must be a directory
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandcmd_is_boot_environment(int argc, char **argv, GLOBALDATA_T *a_gdt)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *rootPath = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int c;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int r;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char *cmdName = "is_boot_environment";
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int recursion = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process any command line options */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((c = getopt(argc, argv, ":")) != EOF) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (c) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '\0': /* prevent end-of-loop not reached warning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '?':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, optopt, cmdName);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* prevent recursion */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (recursionCheck(&recursion, cmdName) == B_FALSE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * a boot environment cannot be any of the following
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot be a diskless client */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_diskless_client(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot be a netinstall_image */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_netinstall_image(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* cannot be a mounted_miniroot */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = cmd_is_mounted_miniroot(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* no need to guard against recursion any more */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland recursion--;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* return failure if any of the preceeding are true */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (r) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_SUCCESS:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_FAILURE:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_USAGE:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_ERROR:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* normalize argc/argv */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argc -= optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argv += optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* error if more than one argument */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc > 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_UNRECOGNIZED_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process root path if first argument present */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc == 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (setRootPath(argv[0], "argv[0]", B_TRUE) != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get current root path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = getRootPath(&rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* start of command debugging information */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_ROOTPATH_IS, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* root path must not be "/" */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(rootPath, "/") == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_BENV_BAD_ROOTPATH, rootPath, "/");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* zone name must be global */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(a_gdt->gd_zoneName, GLOBAL_ZONENAME) != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_BENV_BAD_ZONE, rootPath,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland GLOBAL_ZONENAME);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* $ROOTDIR/etc/lutab must exist */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_EXISTS, "%s/%s", rootPath, "/etc/lutab");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_BENV_NO_ETCLUTAB, rootPath,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "/etc/lutab");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* $ROOTDIR/etc/lu must exist */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = testPath(TEST_EXISTS|TEST_IS_DIRECTORY,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s/%s", rootPath, "/etc/lu");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_BENV_NO_ETCLU, rootPath, "/etc/lu");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* must not be initial installation */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_gdt->gd_initialInstall == B_TRUE) &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (strcmp(a_gdt->gd_installRoot, rootPath) == 0)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_BENV_INITIAL_INSTALL, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* must not be installation of a zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_gdt->gd_globalZoneInstall == B_TRUE) ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (a_gdt->gd_nonglobalZoneInstall == B_TRUE)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* initial zone install: no path can be boot environment */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_BENV_ZONE_INSTALL, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* target is a boot environment */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_BENV_IS, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: cmd_is_what
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: determine what the target is
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Scope: public
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: argc,argv:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - optional path to target to test
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == 0 - success
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * != 0 - failure
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandcmd_is_what(int argc, char **argv, GLOBALDATA_T *a_gdt)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *rootPath = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int c;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int cur_cmd;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int r;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char *cmdName = "is_what";
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process any command line options */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((c = getopt(argc, argv, ":")) != EOF) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (c) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '\0': /* prevent end-of-loop not reached warning */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case '?':
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, optopt, cmdName);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* normalize argc/argv */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argc -= optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argv += optind;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* error if more than one argument */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc > 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_UNRECOGNIZED_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) usage(MSG_IS_INVALID_OPTION, argv[1]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_USAGE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process root path if first argument present */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (argc == 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (setRootPath(argv[0], "argv[0]", B_TRUE) != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get current root path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = getRootPath(&rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * construct the command line for all of the packages
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argc = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argv[argc++] = strdup(get_prog_name());
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland argv[argc++] = strdup(rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* start of command debugging information */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_ROOTPATH_IS, rootPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* search for specified subcommand and execute if found */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (cur_cmd = 0; cmds[cur_cmd].c_name != NULL; cur_cmd++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int result;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* do not recursively call this function */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (cmds[cur_cmd].c_func == cmd_is_what) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland continue;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* call subcommand with its own argc/argv */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland result = cmds[cur_cmd].c_func(argc, argv, a_gdt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process result code and exit */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland result = adjustResults(result);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_INFO, MSG_IS_WHAT_RESULT,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland cmds[cur_cmd].c_name, result);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *****************************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * utility support functions
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *****************************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: getMountOption
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: return next mount option in a string
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: p - pointer to string containing mount options
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Output: none
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: char * - pointer to next option in string "p"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Side Effects: advances input "p" and inserts \0 in place of the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * option separator found.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah WaterlandgetMountOption(char **p)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *cp = *p;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *retstr;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* advance past all white space */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while (*cp && isspace(*cp))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland cp++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* remember start of next option */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland retstr = cp;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* advance to end of string or option separator */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while (*cp && *cp != ',')
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland cp++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* replace separator with '\0' if not at end of string */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (*cp) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *cp = '\0';
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland cp++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* reset caller's pointer and return pointer to option */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *p = cp;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (retstr);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: mountOptionPresent
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: determine if specified mount option is present in list
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * of mount point options
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: a_mntOptions - pointer to string containing list of mount
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * point options to search
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * a_opt - pointer to string containing option to search for
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Output: none
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: R_SUCCESS - option is present in list of mount point options
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * R_FAILURE - options is not present
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * R_ERROR - unable to determine if option is present or not
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah WaterlandmountOptionPresent(char *a_mntOptions, char *a_opt)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char tmpopts[MNT_LINE_MAX];
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *f, *opts = tmpopts;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* return false if no mount options present */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_opt == NULL) || (*a_opt == '\0')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* return not present if no list of options to search */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_mntOptions == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* return not present if list of options to search is empty */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (*a_mntOptions == '\0') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* make local copy of option list to search */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strcpy(opts, a_mntOptions);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* scan each option looking for the specified option */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland f = getMountOption(&opts);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (; *f; f = getMountOption(&opts)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* return success if option matches target */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strncmp(a_opt, f, strlen(a_opt)) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* option not found */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: sortedInsert
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: perform an alphabetical sorted insert into a list
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: r_list - pointer to list to insert next entry into
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * a_listSize - pointer to current list size
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * a_mntPoint - mount point to insert (is sort key)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * a_fsType - file system type for mount point
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * a_mntOptions - file syste mount options for mount point
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Output: None
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: None
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic void
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah WaterlandsortedInsert(FSI_T **r_list, long *a_listSize, char *a_mntPoint,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *a_fsType, char *a_mntOptions)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int listSize;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland FSI_T *list;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int n;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* entry assertions */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland assert(a_listSize != (long *)NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland assert(a_mntPoint != NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland assert(a_fsType != NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland assert(a_mntOptions != NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* entry debugging info */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_SINS_ENTRY, a_mntPoint, a_fsType, a_mntOptions);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* localize references to the list and list size */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland listSize = *a_listSize;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list = *r_list;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if list empty insert this entry as the first one in the list
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (listSize == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* allocate new entry for list */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland listSize++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list = (FSI_T *)realloc(list, sizeof (FSI_T)*(listSize+1));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* first entry is data passed to this function */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list[0].fsi_mntPoint = strdup(a_mntPoint);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list[0].fsi_fsType = strdup(a_fsType);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list[0].fsi_mntOptions = strdup(a_mntOptions);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* second entry is all NULL - end of entry marker */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list[1].fsi_mntPoint = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list[1].fsi_fsType = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list[1].fsi_mntOptions = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* restore list and list size references to caller */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *a_listSize = listSize;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *r_list = list;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * list not empty - scan looking for largest match
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (n = 0; n < listSize; n++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int c;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* compare target with current list entry */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland c = strcmp(list[n].fsi_mntPoint, a_mntPoint);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (c == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *me;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland long len;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* entry already in list -- merge entries */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland len = strlen(list[n].fsi_mntOptions) +
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland strlen(a_mntOptions) + 2;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland me = (char *)calloc(1, len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* merge two mount options lists into one */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strlcat(me, list[n].fsi_mntOptions, len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strlcat(me, ",", len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strlcat(me, a_mntOptions, len);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* free old list, replace with merged one */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(list[n].fsi_mntOptions);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list[n].fsi_mntOptions = me;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_SORTEDINS_SKIPPED,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n, list[n].fsi_mntPoint, a_fsType,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list[n].fsi_fsType, a_mntOptions,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list[n].fsi_mntOptions);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland continue;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else if (c < 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* entry before this one - skip */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland continue;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * entry after this one - insert new entry
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* allocate one more entry and make space for new entry */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland listSize++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list = (FSI_T *)realloc(list,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland sizeof (FSI_T)*(listSize+1));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) memmove(&(list[n+1]), &(list[n]),
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland sizeof (FSI_T)*(listSize-n));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* insert this entry into list */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list[n].fsi_mntPoint = strdup(a_mntPoint);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list[n].fsi_fsType = strdup(a_fsType);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list[n].fsi_mntOptions = strdup(a_mntOptions);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* restore list and list size references to caller */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *a_listSize = listSize;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *r_list = list;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * all entries are before this one - append to end of list
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* allocate new entry at end of list */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland listSize++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list = (FSI_T *)realloc(list, sizeof (FSI_T)*(listSize+1));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* append this entry to the end of the list */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list[listSize-1].fsi_mntPoint = strdup(a_mntPoint);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list[listSize-1].fsi_fsType = strdup(a_fsType);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list[listSize-1].fsi_mntOptions = strdup(a_mntOptions);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* restore list and list size references to caller */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *a_listSize = listSize;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *r_list = list;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: calculateFileSystemConfig
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: generate sorted list of all mounted file systems
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: a_gdt - global data structure to place sorted entries into
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Output: None
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: R_SUCCESS - successfully generated mounted file systems list
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * R_FAILURE - options is not present
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * R_ERROR - unable to determine if option is present or not
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah WaterlandcalculateFileSystemConfig(GLOBALDATA_T *a_gdt)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland FILE *fp;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland struct mnttab mntbuf;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland FSI_T *list;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland long listSize;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* entry assetions */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland assert(a_gdt != (GLOBALDATA_T *)NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* allocate a list that has one termination entry */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list = (FSI_T *)calloc(1, sizeof (FSI_T));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list[0].fsi_mntPoint = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list[0].fsi_fsType = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland list[0].fsi_mntOptions = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland listSize = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* open the mount table for reading */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland fp = fopen(MNTTAB, "r");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (fp == (FILE *)NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* debugging info */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_CALCSCFG_MOUNTED);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* go through all the specials looking for the device */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while (getmntent(fp, &mntbuf) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (mntbuf.mnt_mountp[0] == '/') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland sortedInsert(&list, &listSize,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland strdup(mntbuf.mnt_mountp),
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland strdup(mntbuf.mnt_fstype),
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland strdup(mntbuf.mnt_mntopts ? mntbuf.mnt_mntopts : ""));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Set flag if we are in a non-global zone and it is in
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the mounted state.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(mntbuf.mnt_mountp, "/a") == 0 &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland strcmp(mntbuf.mnt_special, "/a") == 0 &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland strcmp(mntbuf.mnt_fstype, "lofs") == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland a_gdt->inMountedState = B_TRUE;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* close mount table file */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) fclose(fp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* store list pointers in global data structure */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland a_gdt->gd_fileSystemConfig = list;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland a_gdt->gd_fileSystemConfigLen = listSize;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: adjustResults
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: adjust output result code before existing
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: a_result - result code to adjust
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: int - adjusted result code
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah WaterlandadjustResults(int a_result)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland boolean_t negate = getNegateResults();
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int realResult;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* adjust code as appropriate */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland switch (a_result) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_SUCCESS: /* condition satisfied */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland realResult = ((negate == B_TRUE) ? 1 : 0);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_FAILURE: /* condition not satisfied */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland realResult = ((negate == B_TRUE) ? 0 : 1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_USAGE: /* usage errors */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland realResult = 2;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland case R_ERROR: /* condition could not be determined */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland default:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland realResult = 3;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* debugging output */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_ADJUST_RESULTS, a_result, negate,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland realResult);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* return results */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (realResult);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: setCmdLinePath
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: set global command line path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: path - path to set from the command line
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * args - command line args
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * num_args - number of command line args
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: R_SUCCESS - root path successfully set
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * R_FAILURE - root path could not be set
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * R_ERROR - fatal error attempting to set root path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic void
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah WaterlandsetCmdLinePath(char **path, char **args, int num_args)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char rp[PATH_MAX] = { '\0' };
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland struct stat statbuf;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (*path != NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If a path "pkgcond is_global_zone [path]" is provided on the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * command line it must be the last argument.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (realpath(args[num_args - 1], rp) != NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (stat(rp, &statbuf) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* make sure the target is a directory */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((statbuf.st_mode & S_IFDIR)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *path = strdup(rp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *path = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: setRootPath
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: set global root path returned by getRootPath
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: a_path - root path to set
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * a_mustExist - B_TRUE if path must exist (else error)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - B_FALSE if path may not exist
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: R_SUCCESS - root path successfully set
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * R_FAILURE - root path could not be set
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * R_ERROR - fatal error attempting to set root path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah WaterlandsetRootPath(char *a_path, char *a_envVar, boolean_t a_mustExist)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char rp[PATH_MAX] = { '\0' };
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland struct stat statbuf;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if no data then issue warning and return success */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a_path == NULL) || (*a_path == '\0')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_NO_DEFAULT_ROOT_PATH_SET);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* path present - resolve to absolute path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (realpath(a_path, rp) == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_mustExist == B_TRUE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* must exist ... error */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_DEFAULT_ROOT_INVALID,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland a_path, strerror(errno));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* may not exist - use path as specified */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strcpy(rp, a_path);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* debugging output */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_DEFAULT_ROOT_PATH_SET, rp, a_envVar ? a_envVar : "");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* validate path existence if it must exist */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_mustExist == B_TRUE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get node status */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (stat(rp, &statbuf) != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_DEFAULT_ROOT_INVALID,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland rp, strerror(errno));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* make sure the target is a directory */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (!(statbuf.st_mode & S_IFDIR)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_DEFAULT_ROOT_NOT_DIR, rp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* target exists and is a directory - set */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_SET_ROOT_PATH_TO, rp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* store copy of resolved root path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland _rootPath = strdup(rp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* success! */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: testPath
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: determine if a path meets the specified conditions
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: a_tt - conditions to test path against
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * a_format - format to use to generate path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * arguments following a_format - as needed for a_format
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: R_SUCCESS - the path meets all of the specified conditions
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * R_FAILURE - the path does not meet all of the conditions
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * R_ERROR - error attempting to test path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*PRINTFLIKE2*/
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah WaterlandtestPath(TEST_TYPES a_tt, char *a_format, ...)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *mbPath; /* copy for the path to be returned */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char bfr[1];
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int r;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland size_t vres = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland struct stat statbuf;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland va_list ap;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int fd;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* entry assertions */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland assert(a_format != NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland assert(*a_format != '\0');
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* determine size of the message in bytes */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland va_start(ap, a_format);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vres = vsnprintf(bfr, 1, a_format, ap);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland va_end(ap);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland assert(vres > 0);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* allocate storage to hold the message */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland mbPath = (char *)calloc(1, vres+2);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland assert(mbPath != NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* generate the results of the printf conversion */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland va_start(ap, a_format);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vres = vsnprintf(mbPath, vres+1, a_format, ap);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland va_end(ap);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland assert(vres > 0);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_TEST_PATH, mbPath, (unsigned long)a_tt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * When a path given to open(2) contains symbolic links, the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * open system call first resolves all symbolic links and then
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * opens that final "resolved" path. As a result, it is not
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * possible to check the result of an fstat(2) against the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * file descriptor returned by open(2) for S_IFLNK (a symbolic
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * link) since all symbolic links are resolved before the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * target is opened.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * When testing the target as being (or not being) a symbolic
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * link, first use lstat(2) against the target to determine
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * whether or not the specified target itself is (or is not) a
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * symbolic link.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_tt & (TEST_IS_SYMBOLIC_LINK|TEST_NOT_SYMBOLIC_LINK)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * testing target is/is not a symbolic link; use lstat
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * to determine the status of the target itself rather
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * than what the target might finally address.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (lstat(mbPath, &statbuf) != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_CANNOT_LSTAT_PATH, mbPath,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland strerror(errno));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* Is the target required to be a symbolic link? */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_tt & TEST_IS_SYMBOLIC_LINK) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* target must be a symbolic link */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (!(statbuf.st_mode & S_IFLNK)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* failure: target is not a symbolic link */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_IS_NOT_A_SYMLINK, mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* success: target is a symbolic link */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_SYMLINK_IS, mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* Is the target required to not be a symbolic link? */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_tt & TEST_NOT_SYMBOLIC_LINK) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* target must not be a symbolic link */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (statbuf.st_mode & S_IFLNK) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* failure: target is a symbolic link */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_IS_A_SYMLINK, mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* success: target is not a symbolic link */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_SYMLINK_NOT, mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if only testing is/is not a symbolic link, then
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * no need to open the target: return success.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (!(a_tt &
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (~(TEST_IS_SYMBOLIC_LINK|TEST_NOT_SYMBOLIC_LINK)))) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* resolve path and remove any whitespace */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = resolvePath(&mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_TEST_PATH_NO_RESOLVE, mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_tt & TEST_NOT_EXISTS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (r);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_TEST_PATH_RESOLVE, mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* open the file - this is the basic existence test */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland fd = open(mbPath, O_RDONLY|O_LARGEFILE, 0);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* existence test failed if file cannot be opened */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (fd < 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * target could not be opened - if testing for non-existence,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * return success, otherwise return failure
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_tt & TEST_NOT_EXISTS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_CANNOT_ACCESS_PATH_OK, mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_CANNOT_ACCESS_PATH_BUT_SHOULD,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland mbPath, strerror(errno));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * target successfully opened - if testing for non-existence,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * return failure, otherwise continue with specified tests
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_tt & TEST_NOT_EXISTS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* testing for non-existence: return failure */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_TEST_EXISTS_SHOULD_NOT, mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) close(fd);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get the file status */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = fstat(fd, &statbuf);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_PATH_DOES_NOT_EXIST, mbPath, strerror(errno));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) close(fd);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* required to be a directory? */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_tt & TEST_IS_DIRECTORY) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (!(statbuf.st_mode & S_IFDIR)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* is not a directory */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_IS_NOT_A_DIRECTORY, mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* a directory */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_DIRECTORY_IS, mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* required to not be a directory? */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_tt & TEST_NOT_DIRECTORY) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (statbuf.st_mode & S_IFDIR) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* is a directory */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_IS_A_DIRECTORY, mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* not a directory */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_DIRECTORY_NOT, mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* required to be a file? */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_tt & TEST_IS_FILE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (!(statbuf.st_mode & S_IFREG)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* is not a regular file */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_IS_NOT_A_FILE, mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* a regular file */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_FILE_IS, mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* required to not be a file? */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_tt & TEST_NOT_FILE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (statbuf.st_mode & S_IFREG) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* is a regular file */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_IS_A_FILE, mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* not a regular file */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_FILE_NOT, mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Find token (global) in file pointed to by mbPath.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * token is only compared to first word in mbPath.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_tt & TEST_GLOBAL_TOKEN_IN_FILE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (!(statbuf.st_mode & S_IFREG)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* is not a regular file */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_IS_NOT_A_FILE, mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* If global exists then we're not in a non-global zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (findToken(mbPath, GLOBAL_ZONENAME) == R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_TOKEN__EXISTS, GLOBAL_ZONENAME, mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) close(fd);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* success! */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_TESTPATH_OK, mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* free up temp storage used to hold path to test */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(mbPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: findToken
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: Find first token in file.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * path - file to search for token
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * token - string to search for
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * R_SUCCESS - the token exists
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * R_FAILURE - the token does not exist
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * R_ERROR - fatal error attempting to find token
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah WaterlandfindToken(char *path, char *token)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland FILE *fp;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *cp;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char line[MAXPATHLEN];
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (path == NULL || token == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((fp = fopen(path, "r")) == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while (fgets(line, sizeof (line), fp) != NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (cp = line; *cp && isspace(*cp); cp++);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* skip comments */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (*cp == '#') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland continue;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (pkgstrContainsToken(cp, token, ":")) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) fclose(fp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) fclose(fp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: resolvePath
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: fully resolve a path to an absolute real path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: r_path - pointer to pointer to malloc()ed storage containing
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the path to resolve - this path may be reallocated
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * as necessary to hold the fully resolved path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Output: r_path - is realloc()ed as necessary
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: R_SUCCESS - the path is fully resolved
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * R_FAILURE - the path could not be resolved
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * R_ERROR - fatal error attempting to resolve path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah WaterlandresolvePath(char **r_path)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int i;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char resolvedPath[MAXPATHLEN+1] = {'\0'};
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland size_t mbPathlen; /* length of multi-byte path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland size_t wcPathlen; /* length of wide-character path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland wchar_t *wcPath; /* wide-character version of the path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland wchar_t *wptr; /* scratch pointer */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* entry assertions */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland assert(r_path != (char **)NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* return error if the path is completely empty */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (*r_path == '\0') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* remove all leading whitespace */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland removeLeadingWhitespace(r_path);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * convert to real path: an absolute pathname that names the same file,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * whose resolution does not involve ".", "..", or symbolic links.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (realpath(*r_path, resolvedPath) != NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(*r_path);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *r_path = strdup(resolvedPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * convert the multi-byte version of the path to a
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * wide-character rendering, for doing our figuring.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland mbPathlen = strlen(*r_path);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((wcPath = (wchar_t *)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland calloc(1, sizeof (wchar_t)*(mbPathlen+1))) == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*LINTED*/
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((wcPathlen = mbstowcs(wcPath, *r_path, mbPathlen)) == -1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(wcPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * remove duplicate slashes first ("//../" -> "/")
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (wptr = wcPath, i = 0; i < wcPathlen; i++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *wptr++ = wcPath[i];
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (wcPath[i] == '/') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland i++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while (wcPath[i] == '/') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland i++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland i--;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *wptr = '\0';
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * now convert back to the multi-byte format.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*LINTED*/
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (wcstombs(*r_path, wcPath, mbPathlen) == -1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(wcPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* at this point have a path */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* free up temporary storage */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(wcPath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: removeLeadingWhitespace
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Synopsis: Remove leading whitespace from string
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: Remove all leading whitespace characters from a string
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: a_str - [RO, *RW] - (char **)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Pointer to handle to string (in allocated storage) to
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * remove all leading whitespace from
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: void
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * The input string is modified as follows:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == NULL:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - input string was NULL
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - input string is all whitespace
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * != NULL:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - copy of input string with leading
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * whitespace removed
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CAUTION: The input string must be allocated space (via malloc() or
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * strdup()) - it must not be a static or inline character string
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * NOTE: The input string a_str will be freed with 'free'
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if it is all whitespace, or if it contains any leading
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * whitespace characters
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * NOTE: Any string returned is placed in new storage for the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * calling method. The caller must use 'free' to dispose
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * of the storage once the string is no longer needed.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Errors: If the string cannot be created, the process exits
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic void
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah WaterlandremoveLeadingWhitespace(char **a_str)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *o_str;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* entry assertions */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland assert(a_str != (char **)NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if string is null, just return */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (*a_str == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland o_str = *a_str;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if string is empty, deallocate and return NULL */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (*o_str == '\0') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* free string */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(*a_str);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *a_str = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if first character is not a space, just return */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (!isspace(*o_str)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* advance past all space characters */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((*o_str != '\0') && (isspace(*o_str))) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland o_str++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if string was all space characters, deallocate and return NULL */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (*o_str == '\0') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* free string */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(*a_str);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *a_str = NULL;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* have non-space/null byte, return dup, deallocate original */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland o_str = strdup(o_str);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free(*a_str);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *a_str = o_str;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: getZoneName
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: get the name of the zone this process is running in
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: r_zoneName - pointer to pointer to receive zone name
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Output: r_zoneName - a pointer to malloc()ed storage containing
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the zone name this process is running in is stored
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * in the location pointed to by r_zoneName
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: R_SUCCESS - the zone name is successfully returned
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * R_FAILURE - the zone name is not successfully returned
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * R_ERROR - error attempting to get the zone name
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah WaterlandgetZoneName(char **r_zoneName)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic char zoneName[ZONENAME_MAX] = { '\0' };
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if zone name not already present, retrieve and cache name */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (zoneName[0] == '\0') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (getzonenamebyid(getzoneid(), zoneName,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland sizeof (zoneName)) < 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_CANNOT_GET_ZONENAME);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* return cached zone name */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *r_zoneName = zoneName;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: getRootPath
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: get the root path being tested by this process
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: r_rootPath - pointer to pointer to receive root path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Output: r_rootPath - a pointer to malloc()ed storage containing
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the root path name this process is testing
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: R_SUCCESS - the root path is successfully returned
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * R_FAILURE - the root path is not successfully returned
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * R_ERROR - error attempting to get the root path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah WaterlandgetRootPath(char **r_rootPath)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *r_rootPath = _rootPath;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: setVerbose
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: Turns on verbose output
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Scope: public
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: verbose = B_TRUE indicates verbose mode
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: none
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic void
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah WaterlandsetVerbose(boolean_t setting)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* set log verbose messages */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_set_verbose(setting);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* set interactive messages */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoSetFlag(setting);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: negate_results
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: control negation of results
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Scope: public
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: setting
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == B_TRUE indicates negated results mode
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * == B_FALSE indicates non-negated results mode
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: none
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic void
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah WaterlandsetNegateResults(boolean_t setting)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_SET_NEGATE_RESULTS,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland _negateResults, setting);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland _negateResults = setting;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: getNegateResults
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: Returns whether or not to results are negated
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Scope: public
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: none
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: B_TRUE - results are negated
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * B_FALSE - results are not negated
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic boolean_t
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah WaterlandgetNegateResults(void)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (_negateResults);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: usage
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: output usage string
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: a_format - format to use to generate message
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * arguments following a_format - as needed for a_format
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Output: Outputs the usage string to stderr.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: R_ERROR
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandusage(char *a_format, ...)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int cur_cmd;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char cmdlst[LINE_MAX+1] = { '\0' };
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *message;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char bfr[1];
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *p = get_prog_name();
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland size_t vres = 0;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland va_list ap;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* entry assertions */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland assert(a_format != NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland assert(*a_format != '\0');
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* determine size of the message in bytes */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland va_start(ap, a_format);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* LINTED warning: variable format specifier to vsnprintf(); */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vres = vsnprintf(bfr, 1, a_format, ap);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland va_end(ap);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland assert(vres > 0);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* allocate storage to hold the message */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland message = (char *)calloc(1, vres+2);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland assert(message != NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* generate the results of the printf conversion */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland va_start(ap, a_format);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* LINTED warning: variable format specifier to vsnprintf(); */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland vres = vsnprintf(message, vres+1, a_format, ap);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland va_end(ap);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland assert(vres > 0);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* generate list of all defined conditions */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (cur_cmd = 0; cmds[cur_cmd].c_name != NULL; cur_cmd++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strlcat(cmdlst, "\t", sizeof (cmdlst));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strlcat(cmdlst, cmds[cur_cmd].c_name, sizeof (cmdlst));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (cmds[cur_cmd].c_args != NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strlcat(cmdlst, cmds[cur_cmd].c_args,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland sizeof (cmdlst));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strlcat(cmdlst, "\n", sizeof (cmdlst));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* output usage with conditions */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_INFO, MSG_USAGE, message, p ? p : "pkgcond", cmdlst);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_ERROR);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: parseGlobalData
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: parse environment global data and store in global data structure
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: a_envVar - pointer to string representing the name of the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * environment variable to get and parse
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * r_gdt - pointer to pointer to global data structure to fill in
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * using the parsed data from a_envVar
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Output: none
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: R_SUCCESS - the global data is successfully parsed
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * R_FAILURE - problem parsing global data
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * R_ERROR - fatal error attempting to parse global data
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah WaterlandparseGlobalData(char *a_envVar, GLOBALDATA_T **r_gdt)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int r;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int n;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *a;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland SML_TAG *tag;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland SML_TAG *ntag;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland assert(r_gdt != (GLOBALDATA_T **)NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * allocate space for global data structure if needed
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (*r_gdt == (GLOBALDATA_T *)NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *r_gdt = (GLOBALDATA_T *)calloc(1, sizeof (GLOBALDATA_T));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * get initial installation indication:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If the initial install variable is set to "true", then an initial
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * installation of Solaris is underway. When this condition is true:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - if the path being checked is the package install root, then
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the path is considered to be an 'alternative root' which is
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * currently being installed.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - if the path being checked is not the package install root, then
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the path needs to be further analyzed to determine what it may
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * be referring to.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland a = getenv(ENV_VAR_INITIAL_INSTALL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a != NULL) && (strcasecmp(a, "true") == 0)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (*r_gdt)->gd_initialInstall = B_TRUE;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get current zone name */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = getZoneName(&(*r_gdt)->gd_zoneName);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (*r_gdt)->gd_zoneName = "";
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * get zone installation status:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - If the package install zone name is not set, then an installation
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * of a global zone, or of a non-global zone, is not underway.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - If the package install zone name is set to "global", then an
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * installation of a global zone is underway. In this case, no path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * can be a netinstall image, diskless client, mounted miniroot,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * non-global zone, the current running system, alternative root,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * or alternative boot environment.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * - If the package install zone name is set to a value other than
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * "global", then an installation of a non-global zone with that name
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is underway. In this case, no path can be a netinstall image,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * diskless client, mounted miniroot, global zone, the current
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * running system, alternative root, or alternative boot environment.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland a = getenv(ENV_VAR_PKGZONENAME);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a == NULL) || (*a == '\0')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* not installing a zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (*r_gdt)->gd_globalZoneInstall = B_FALSE;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (*r_gdt)->gd_nonglobalZoneInstall = B_FALSE;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else if (strcmp(a, GLOBAL_ZONENAME) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* installing a global zone */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (*r_gdt)->gd_globalZoneInstall = B_TRUE;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (*r_gdt)->gd_nonglobalZoneInstall = B_FALSE;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (*r_gdt)->gd_zoneName = a;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* installing a non-global zone by that name */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (*r_gdt)->gd_globalZoneInstall = B_FALSE;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (*r_gdt)->gd_nonglobalZoneInstall = B_TRUE;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (*r_gdt)->gd_zoneName = a;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore * get package install root.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland a = getenv(ENV_VAR_PKGROOT);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a != NULL) && (*a != '\0')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (*r_gdt)->gd_installRoot = a;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore (*r_gdt)->gd_installRoot = "/";
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get the global data environment variable */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland a = getenv(a_envVar);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if no data then issue warning and return success */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((a == NULL) || (*a_envVar == '\0')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_NO_GLOBAL_DATA_AVAILABLE, a_envVar);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* data present - parse into SML structure */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_DEBUG, DBG_PARSE_GLOBAL, a);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = smlConvertStringToTag(&tag, a);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != R_SUCCESS) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_ERR, ERR_CANNOT_PARSE_GLOBAL_DATA, a);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland smlDbgPrintTag(tag, DBG_PARSED_ENVIRONMENT, a_envVar);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* fill in global data structure */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* find the environment condition information structure */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ntag = smlGetTagByName(tag, 0, TAG_COND_TOPLEVEL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (ntag == SML_TAG__NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland log_msg(LOG_MSG_WRN, WRN_PARSED_DATA_MISSING,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland TAG_COND_TOPLEVEL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * data found - extract what we know about
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* parent zone name */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland a = smlGetParamByTag(ntag, 0, TAG_COND_PARENT_ZONE, TAG_COND_ZONE_NAME);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (*r_gdt)->gd_parentZoneName = a;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* parent zone type */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland a = smlGetParamByTag(ntag, 0, TAG_COND_PARENT_ZONE, TAG_COND_ZONE_TYPE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (*r_gdt)->gd_parentZoneType = a;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* current zone name */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland a = smlGetParamByTag(ntag, 0, TAG_COND_CURRENT_ZONE,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland TAG_COND_ZONE_NAME);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (*r_gdt)->gd_currentZoneName = a;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* current zone type */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland a = smlGetParamByTag(ntag, 0, TAG_COND_CURRENT_ZONE,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland TAG_COND_ZONE_TYPE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (*r_gdt)->gd_currentZoneType = a;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (R_SUCCESS);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: dumpGlobalData
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: dump global data structure using echoDebug
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: a_gdt - pointer to global data structure to dump
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Outputs: echoDebug is called to output global data strucutre information
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: void
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic void
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah WaterlanddumpGlobalData(GLOBALDATA_T *a_gdt)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* entry assertions */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland assert(a_gdt != (GLOBALDATA_T *)NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* debugging enabled, dump the global data structure */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_DUMP_GLOBAL_ENTRY);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_DUMP_GLOBAL_PARENT_ZONE,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland a_gdt->gd_parentZoneName ? a_gdt->gd_parentZoneName : "",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland a_gdt->gd_parentZoneType ? a_gdt->gd_parentZoneType : "");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_DUMP_GLOBAL_CURRENT_ZONE,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland a_gdt->gd_currentZoneName ? a_gdt->gd_currentZoneName : "",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland a_gdt->gd_currentZoneType ? a_gdt->gd_currentZoneType : "");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: recursionCheck
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: prevent recursive calling of functions
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: r_recursion - pointer to int recursion counter
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * a_function - pointer to name of function
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: B_TRUE - function is recursively called
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * B_FALSE - function not recursively called
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic boolean_t
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah WaterlandrecursionCheck(int *r_recursion, char *a_function)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* prevent recursion */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (*r_recursion)++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (*r_recursion > 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_RECURSION, a_function, *r_recursion);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (*r_recursion)--;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (B_TRUE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland echoDebug(DBG_NO_RECURSION, a_function);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (B_FALSE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: quit
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: cleanup and exit
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: a_retcode - the code to use to determine final exit status;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if this is NOT "99" and if a "ckreturnFunc" is
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * set, then that function is called with a_retcode
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * to set the final exit status.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Valid values are:
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * 0 - success
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * 1 - package operation failed (fatal error)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * 2 - non-fatal error (warning)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * 3 - user selected quit (operation interrupted)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * 4 - admin settings prevented operation
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * 5 - interaction required and -n (non-interactive) specified
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * "10" is added to indicate "immediate reboot required"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * "20" is be added to indicate "reboot after install required"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * 99 - do not interpret the code - just exit "99"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: <<this function does not return - calls exit()>>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * NOTE: This is needed because libinst functions can call "quit(99)"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * to force an error exit.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandvoid
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandquit(int a_retcode)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* process return code if not quit(99) */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (a_retcode == 99) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland exit(0x7f); /* processing error (127) */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland exit(R_FAILURE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}