zoneadm.c revision 3f2f09c1efd66f6d2995998ea72c5df8c70c9a97
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* zoneadm is a command interpreter for zone administration. It is all in
* main() calls parse_and_run() which calls cmd_match(), then invokes the
* appropriate command's handler function. The rest of the program is the
* handler functions and their helper functions.
*
* Some of the helper functions are used largely to simplify I18N: reducing
* the need for translation notes. This is particularly true of many of
* the zerror() calls: doing e.g. zerror(gettext("%s failed"), "foo") rather
* than zerror(gettext("foo failed")) with a translation note indicating
* that "foo" need not be translated.
*/
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <stdarg.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <wait.h>
#include <zone.h>
#include <priv.h>
#include <locale.h>
#include <libintl.h>
#include <libzonecfg.h>
#include <assert.h>
#include <limits.h>
#include <dirent.h>
#include <fcntl.h>
#include <door.h>
#include <macros.h>
#include <libgen.h>
#include <fnmatch.h>
#include <pool.h>
#include "zoneadm.h"
#define MAXARGS 8
/* Reflects kernel zone entries */
typedef struct zone_entry {
char zname[ZONENAME_MAX];
char *zstate_str;
char zroot[MAXPATHLEN];
} zone_entry_t;
static zone_entry_t *zents;
#define LOOPBACK_IF "lo0"
struct net_if {
char *name;
int af;
};
/* 0755 is the default directory mode. */
#define DEFAULT_DIR_MODE \
struct cmd {
char *cmd_name; /* command name */
char *short_usage; /* short form help */
};
#define SHELP_HELP "help"
#define SHELP_BOOT "boot [-- boot_arguments]"
#define SHELP_HALT "halt"
#define SHELP_READY "ready"
#define SHELP_REBOOT "reboot [-- boot_arguments]"
#define SHELP_LIST "list [-cipv]"
#define SHELP_VERIFY "verify"
#define SHELP_INSTALL "install [-x nodataset]"
#define SHELP_UNINSTALL "uninstall [-F]"
#define SHELP_CLONE "clone [-m method] [-s <ZFS snapshot>] zonename"
#define SHELP_MOVE "move zonepath"
#define SHELP_DETACH "detach [-n]"
#define SHELP_ATTACH "attach [-F] [-n <path>]"
static int verify_details(int);
};
/* global variables */
/* set early in main(), never modified thereafter, used all over the place */
static char *execname;
static char *locale;
char *target_zone;
/* used in do_subproc() and signal handler */
static volatile boolean_t child_killed;
char *
cmd_to_str(int cmd_num)
{
}
/* This is a separate function because of gettext() wrapping. */
static char *
{
switch (cmd_num) {
case CMD_HELP:
return (gettext("Print usage message."));
case CMD_BOOT:
return (gettext("Activates (boots) specified zone. See "
"zoneadm(1m) for valid boot\n\targuments."));
case CMD_HALT:
return (gettext("Halts specified zone, bypassing shutdown "
"scripts and removing runtime\n\tresources of the zone."));
case CMD_READY:
return (gettext("Prepares a zone for running applications but "
"does not start any user\n\tprocesses in the zone."));
case CMD_REBOOT:
return (gettext("Restarts the zone (equivalent to a halt / "
"boot sequence).\n\tFails if the zone is not active. "
"See zoneadm(1m) for valid boot\n\targuments."));
case CMD_LIST:
return (gettext("Lists the current zones, or a "
"specific zone if indicated. By default,\n\tall "
"running zones are listed, though this can be "
"expanded to all\n\tinstalled zones with the -i "
"option or all configured zones with the\n\t-c "
"option. When used with the general -z <zone> "
"option, lists only the\n\tspecified zone, but "
"lists it regardless of its state, and the -i "
"and -c\n\toptions are disallowed. The -v option "
"can be used to display verbose\n\tinformation: "
"zone name, id, current state, root directory and "
"options.\n\tThe -p option can be used to request "
"machine-parsable output. The -v\n\tand -p "
"options are mutually exclusive. If neither -v "
"nor -p is used,\n\tjust the zone name is listed."));
case CMD_VERIFY:
return (gettext("Check to make sure the configuration "
"can safely be instantiated\n\ton the machine: "
"physical network interfaces exist, etc."));
case CMD_INSTALL:
return (gettext("Install the configuration on to the system. "
"The -x nodataset option\n\tcan be used to prevent the "
"creation of a new ZFS file system for the\n\tzone "
"(assuming the zonepath is within a ZFS file system)."));
case CMD_UNINSTALL:
return (gettext("Uninstall the configuration from the system. "
"The -F flag can be used\n\tto force the action."));
case CMD_CLONE:
return (gettext("Clone the installation of another zone. "
"The -m option can be used to\n\tspecify 'copy' which "
"forces a copy of the source zone. The -s option\n\t"
"can be used to specify the name of a ZFS snapshot "
"that was taken from\n\ta previous clone command. The "
"snapshot will be used as the source\n\tinstead of "
"creating a new ZFS snapshot."));
case CMD_MOVE:
return (gettext("Move the zone to a new zonepath."));
case CMD_DETACH:
return (gettext("Detach the zone from the system. The zone "
"state is changed to\n\t'configured' (but the files under "
"the zonepath are untouched).\n\tThe zone can subsequently "
"be attached, or can be moved to another\n\tsystem and "
"attached there. The -n option can be used to specify\n\t"
"'no-execute' mode. When -n is used, the information "
"needed to attach\n\tthe zone is sent to standard output "
"but the zone is not actually\n\tdetached."));
case CMD_ATTACH:
return (gettext("Attach the zone to the system. The zone "
"state must be 'configured'\n\tprior to attach; upon "
"successful completion, the zone state will be\n\t"
"'installed'. The system software on the current "
"system must be\n\tcompatible with the software on the "
"zone's original system.\n\tSpecify -F to force the attach "
"and skip software compatibility tests.\n\tThe -n option "
"can be used to specify 'no-execute' mode. When -n is\n\t"
"used, the information needed to attach the zone is read "
"from the\n\tspecified path and the configuration is only "
"validated. The path can\n\tbe '-' to specify standard "
"input."));
default:
return ("");
}
/* NOTREACHED */
return (NULL);
}
/*
* Called with explicit B_TRUE when help is explicitly requested, B_FALSE for
* unexpected errors.
*/
static int
{
int i;
gettext("subcommand"));
continue;
if (explicit)
}
if (!explicit)
return (Z_USAGE);
}
static void
{
}
/*
* zperror() is like perror(3c) except that this also prints the executable
* name at the start of the message, and takes a boolean indicating whether
* to call libc'c strerror() or that from libzonecfg.
*/
void
{
}
/*
* zperror2() is very similar to zperror() above, except it also prints a
* supplied zone name after the executable.
*
* All current consumers of this function want libzonecfg's strerror() rather
* than libc's; if this ever changes, this function can be made more generic
* like zperror() above.
*/
void
{
}
/* PRINTFLIKE1 */
void
{
if (target_zone != NULL)
}
static void *
{
if (r == NULL) {
}
return (r);
}
static void
{
"NAME", "STATUS", "PATH");
}
if (!verbose) {
if (!parsable) {
return;
}
(void) printf("-");
else
return;
}
else
}
}
static int
{
int err;
/*
* For labeled zones which query the zone path of lower-level
* zones, the path needs to be adjusted to drop the final
* "/root" component. This adjusted path is then useful
* for reading down any exported directories from the
* lower-level zone.
*/
gettext("could not get zone path."));
return (Z_ERR);
}
*cp = 0;
} else {
gettext("could not get zone path."));
return (Z_ERR);
}
}
return (Z_ERR);
}
return (Z_OK);
}
/*
* fetch_zents() calls zone_list(2) to find out how many zones are running
* (which is stored in the global nzents), then calls zone_list(2) again
* to fetch the list of running zones (stored in the global zents). This
* function may be called multiple times, so if zents is already set, we
* return immediately to save work.
*/
static int
fetch_zents(void)
{
int i, retv;
if (nzents > 0)
return (Z_OK);
return (Z_ERR);
}
if (nzents == 0)
return (Z_OK);
return (Z_ERR);
}
if (nzents != nzents_saved) {
/* list changed, try again */
goto again;
}
if (inaltroot)
else
for (i = 0; i < nzents; i++) {
char name[ZONENAME_MAX];
char altname[ZONENAME_MAX];
continue;
}
if (zonecfg_is_scratch(name)) {
/* Ignore scratch zones by default */
if (!inaltroot)
continue;
"zone %s"), name);
continue;
}
} else {
/* Ignore non-scratch when in an alternate root */
continue;
}
continue;
}
zentp++;
}
return (retv);
}
static int
{
int i;
char *name;
/*
* First get the list of running zones from the kernel and print them.
* If that is all we need, then return.
*/
if ((i = fetch_zents()) != Z_OK) {
/*
* No need for error messages; fetch_zents() has already taken
* care of this.
*/
return (i);
}
for (i = 0; i < nzents; i++)
if (min_state >= ZONE_STATE_RUNNING)
return (Z_OK);
/*
* Next, get the full list of zones from the configuration, skipping
* any we have already printed.
*/
cookie = setzoneent();
for (i = 0; i < nzents; i++) {
break;
}
if (i < nzents) {
continue;
}
continue;
}
}
return (Z_OK);
}
static zone_entry_t *
lookup_running_zone(char *str)
{
char *cp;
int i;
if (fetch_zents() != Z_OK)
return (NULL);
for (i = 0; i < nzents; i++) {
return (&zents[i]);
}
errno = 0;
return (NULL);
for (i = 0; i < nzents; i++) {
return (&zents[i]);
}
return (NULL);
}
/*
* Check a bit in a mode_t: if on is B_TRUE, that bit should be on; if
* B_FALSE, it should be off. Return B_TRUE if the mode is bad (incorrect).
*/
static boolean_t
{
char *str;
/*
* TRANSLATION_NOTE
* The strings below will be used as part of a larger message,
* either:
* (file name) must be (owner|group|world) (read|writ|execut)able
* or
* (file name) must not be (owner|group|world) (read|writ|execut)able
*/
switch (bit) {
case S_IRUSR:
break;
case S_IWUSR:
break;
case S_IXUSR:
break;
case S_IRGRP:
break;
case S_IWGRP:
break;
case S_IXGRP:
break;
case S_IROTH:
break;
case S_IWOTH:
break;
case S_IXOTH:
break;
}
/*
* TRANSLATION_NOTE
* The first parameter below is a file name; the second
* is one of the "(owner|group|world) (read|writ|execut)able"
* strings from above.
*/
/*
* The code below could be simplified but not in a way
* that would easily translate to non-English locales.
*/
if (on) {
} else {
}
return (B_TRUE);
}
return (B_FALSE);
}
/*
* We want to make sure that no zone has its zone path as a child node
* (in the directory sense) of any other. We do that by comparing this
* zone's path to the path of all other (non-global) zones. The comparison
* in each case is simple: add '/' to the end of the path, then do a
* strncmp() of the two paths, using the length of the shorter one.
*/
static int
crosscheck_zonepaths(char *path)
{
cookie = setzoneent();
/* Skip zones which are not installed. */
continue;
}
/* Skip the global zone and the current target zone. */
continue;
}
/* old index file without path, fall back */
gettext("could not get zone path"));
continue;
}
}
if (res == -1) {
return (Z_ERR);
}
"zonepath", path_copy);
continue;
}
/*
* TRANSLATION_NOTE
* zonepath is a literal that should not be translated.
*/
"%s zonepath (%s) overlap.\n"),
return (Z_ERR);
}
}
return (Z_OK);
}
static int
{
if (path[0] != '/') {
return (Z_ERR);
}
return (Z_ERR);
}
if (cmd_num == CMD_VERIFY) {
/*
* TRANSLATION_NOTE
* zoneadm is a literal that should not be translated.
*/
"exist, so it could not be verified.\nWhen "
"'zoneadm %s' is run, '%s' will try to create\n%s, "
"and '%s' will be tried again,\nbut the '%s' may "
"fail if:\nthe parent directory of %s is group- or "
"other-writable\nor\n%s overlaps with any other "
"installed zones.\n"), path,
return (Z_OK);
}
/*
* The zonepath is supposed to be mode 700 but its
* parent(s) 755. So use 755 on the mkdirp() then
* chmod() the zonepath itself to 700.
*/
return (Z_ERR);
}
/*
* If the chmod() fails, report the error, but might
* as well continue the verify procedure.
*/
/*
* Since the mkdir() succeeded, we should not have to
* worry about a subsequent ENOENT, thus this should
* only recurse once.
*/
}
return (Z_ERR);
}
return (Z_ERR);
}
rpath);
return (Z_ERR);
}
"file system.\n"), rpath);
}
return (Z_ERR);
/*
* Try to collect and report as many minor errors as possible
* before returning, so the user can learn everything that needs
* to be fixed up front.
*/
rpath);
}
return (Z_ERR);
}
return (Z_ERR);
}
/* theoretically impossible */
rppath);
return (Z_ERR);
}
rppath);
}
rppath);
}
return (Z_ERR);
}
/*
* TRANSLATION_NOTE
* Zonepath and NFS are literals that should not be translated.
*/
"mounted file system.\n"
"\tA local file system must be used.\n"), rpath);
return (Z_ERR);
}
/*
* TRANSLATION_NOTE
* Zonepath and nosuid are literals that should not be
* translated.
*/
"file system.\n"), rpath);
return (Z_ERR);
}
return (Z_ERR);
}
/*
* The existence of the root path is only bad in the configured state,
* as it is *supposed* to be there at the installed and later states.
* However, the root path is expected to be there if the zone is
* detached.
*/
sizeof (rootpath)) {
/*
* TRANSLATION_NOTE
* Zonepath is a literal that should not be translated.
*/
return (Z_ERR);
}
if (zonecfg_detached(rpath))
gettext("Cannot %s detached "
"zone.\nUse attach or remove %s "
rpath);
else
gettext("Rootpath %s exists; "
"remove or move aside prior to %s.\n"),
return (Z_ERR);
}
}
}
static void
release_lock_file(int lockfd)
{
}
static int
{
ZONES_TMPDIR) >= sizeof (pathbuf)) {
return (Z_ERR);
}
return (Z_ERR);
}
/*
* One of these lock files is created for each zone (when needed).
* The lock files are not cleaned up (except on system reboot),
* but since there is only one per zone, there is no resource
* starvation issue.
*/
return (Z_ERR);
}
return (Z_ERR);
}
/*
* Lock the file to synchronize with other zoneadmds
*/
return (Z_ERR);
}
return (Z_OK);
}
static boolean_t
{
}
/*
* system daemons are not audited. For the global zone, this occurs
* "naturally" since init is started with the default audit
* characteristics. Since zoneadmd is a system daemon and it starts
* init for a zone, it is necessary to clear out the audit
* characteristics inherited from whomever started zoneadmd. This is
* indicated by the audit id, which is set from the ruid parameter of
* adt_set_user(), below.
*/
static void
{
return;
}
(void) adt_end_session(ah);
return;
}
if (adt_set_proc(ah))
(void) adt_end_session(ah);
}
static int
start_zoneadmd(const char *zone_name)
{
return (Z_ERR);
return (Z_ERR);
/*
* Now that we have the lock, re-confirm that the daemon is
* *not* up and working fine. If it is still down, we have a green
* light to start it.
*/
goto out;
}
} else {
goto out;
}
}
goto out;
} else if (child_pid == 0) {
/* child process */
*ap++ = "zoneadmd";
*ap++ = "-z";
if (zonecfg_in_alt_root()) {
*ap++ = "-R";
*ap++ = zonecfg_get_root();
}
/*
* TRANSLATION_NOTE
* zoneadmd is a literal that should not be translated.
*/
} else {
/* parent process */
int pstatus = 0;
do {
WEXITSTATUS(pstatus) != 0)) {
goto out;
}
}
out:
return (error);
}
static int
ping_zoneadmd(const char *zone_name)
{
int doorfd;
return (Z_ERR);
return (Z_ERR);
}
return (Z_OK);
}
return (Z_ERR);
}
static int
{
rlen = getpagesize();
return (-1);
}
sizeof (uniqid));
}
return (-1);
}
/*
* Loop trying to start zoneadmd; if something goes seriously
* wrong we break out and fail.
*/
for (;;) {
break;
break;
}
/*
* We'll get EBADF if the door has been revoked.
*/
break;
}
continue; /* take another lap */
}
/* Door server is going away; kick it again. */
continue;
}
while (*errbuf != '\0') {
/*
* Remove any newlines since zerror()
* will append one automatically.
*/
*cp = '\0';
break;
}
return (result);
}
return (-1);
}
static int
{
int arg;
if (zonecfg_in_alt_root()) {
return (Z_ERR);
}
optind = 0;
switch (arg) {
case '?':
default:
return (Z_USAGE);
}
}
return (Z_USAGE);
}
return (Z_ERR);
return (Z_ERR);
return (Z_ERR);
}
return (Z_OK);
}
static int
{
int arg;
if (zonecfg_in_alt_root()) {
return (Z_ERR);
}
/*
* The following getopt processes arguments to zone boot; that
* is to say, the [here] portion of the argument string:
*
* zoneadm -z myzone boot [here] -- -v -m verbose
*
* Where [here] can either be nothing, -? (in which case we bail
* and print usage), or -s. Support for -s is vestigal and
* obsolete, but is retained because it was a documented interface
* proper way to specify boot arguments like -s is:
*
* zoneadm -z myzone boot -- -s -v -m verbose.
*/
optind = 0;
switch (arg) {
case '?':
case 's':
break;
default:
return (Z_USAGE);
}
}
return (Z_ERR);
}
return (Z_ERR);
}
}
return (Z_ERR);
return (Z_ERR);
return (Z_ERR);
}
return (Z_OK);
}
static void
{
/*
* Since we're looking up our own (non-global) zone name,
* we can be assured that it will succeed.
*/
if (!is_system_labeled()) {
} else {
}
}
static int
{
if (target_zone == NULL) {
/* all zones: default view to running but allow override */
optind = 0;
switch (arg) {
case '?':
/*
* The 'i' and 'c' options are not mutually
* exclusive so if 'c' is given, then min_state
* is set to 0 (ZONE_STATE_CONFIGURED) which is
* the lowest possible state. If 'i' is given,
* then min_state is set to be the lowest state
* so far.
*/
case 'c':
break;
case 'i':
break;
case 'p':
break;
case 'v':
break;
default:
return (Z_USAGE);
}
}
return (Z_ERR);
}
} else {
}
return (retv);
}
/*
* Specific target zone: disallow -i/-c suboptions.
*/
optind = 0;
switch (arg) {
case '?':
case 'p':
break;
case 'v':
break;
default:
return (Z_USAGE);
}
}
return (Z_ERR);
}
return (Z_USAGE);
}
if (zone_id != GLOBAL_ZONEID) {
/*
* main() will issue a Z_NO_ZONE error if it cannot get an
* id for target_zone, which in a non-global zone should
* happen for any zone name except `zonename`. Thus we
* assert() that here but don't otherwise check.
*/
}
}
static void
{
/*
* Ignore SIG{INT,TERM}, so we don't end up in an infinite loop,
* then propagate the signal to our process group.
*/
}
static int
do_subproc(char *cmdbuf)
{
/*
* We use popen(3c) to launch child processes for [un]install;
* this library call does not return a PID, so we have to kill
* the whole process group. To avoid killing our parent, we
* become a process group leader here. But doing so can wreak
* havoc with reading from stdin when launched by a non-job-control
*/
(void) close(STDIN_FILENO);
(void) setpgid(0, 0);
for (;;) {
break;
}
}
static int
{
if (exit_code == 0)
return (Z_OK);
} else if (WIFSIGNALED(status)) {
char sigstr[SIG2STR_MAX];
sigstr);
} else {
cmd);
}
} else {
}
return (Z_ERR);
}
/*
* Various sanity checks; make sure:
* 1. We're in the global zone.
* 2. The calling user has sufficient privilege.
* 3. The target zone is neither the global zone nor anything starting with
* "SUNW".
* 4a. If we're looking for a 'not running' (i.e., configured or installed)
* zone, the name service knows about it.
* 4b. For some operations which expect a zone not to be running, that it is
* not already running (or ready).
*/
static int
{
char kernzone[ZONENAME_MAX];
if (getzoneid() != GLOBAL_ZONEID) {
switch (cmd_num) {
case CMD_HALT:
break;
case CMD_REBOOT:
break;
default:
break;
}
return (Z_ERR);
}
return (Z_ERR);
}
return (Z_ERR);
}
return (Z_ERR);
}
return (Z_ERR);
}
return (Z_ERR);
}
return (Z_ERR);
}
if (!zonecfg_in_alt_root()) {
} else {
else
}
/*
* Look up from the kernel for 'running' zones.
*/
if (running) {
return (Z_ERR);
}
} else {
int err;
/* check whether the zone is ready or running */
gettext("could not get state"));
/* can't tell, so hedge */
} else {
zent->zstate_str =
}
return (Z_ERR);
}
return (Z_ERR);
}
switch (cmd_num) {
case CMD_UNINSTALL:
if (state == ZONE_STATE_CONFIGURED) {
return (Z_ERR);
}
break;
case CMD_ATTACH:
case CMD_CLONE:
case CMD_INSTALL:
if (state == ZONE_STATE_INSTALLED) {
return (Z_ERR);
} else if (state == ZONE_STATE_INCOMPLETE) {
return (Z_ERR);
}
break;
case CMD_DETACH:
case CMD_MOVE:
case CMD_READY:
case CMD_BOOT:
case CMD_MOUNT:
if (state < ZONE_STATE_INSTALLED) {
return (Z_ERR);
}
break;
case CMD_VERIFY:
if (state == ZONE_STATE_INCOMPLETE) {
return (Z_ERR);
}
break;
case CMD_UNMOUNT:
if (state != ZONE_STATE_MOUNTED) {
return (Z_ERR);
}
break;
}
}
return (Z_OK);
}
static int
{
int arg;
if (zonecfg_in_alt_root()) {
return (Z_ERR);
}
optind = 0;
switch (arg) {
case '?':
default:
return (Z_USAGE);
}
}
return (Z_USAGE);
}
/*
* zoneadmd should be the one to decide whether or not to proceed,
* so even though it seems that the fourth parameter below should
* perhaps be B_TRUE, it really shouldn't be.
*/
return (Z_ERR);
}
static int
{
int arg;
if (zonecfg_in_alt_root()) {
return (Z_ERR);
}
optind = 0;
switch (arg) {
case '?':
default:
return (Z_USAGE);
}
}
return (Z_ERR);
}
return (Z_ERR);
}
}
/*
* zoneadmd should be the one to decide whether or not to proceed,
* so even though it seems that the fourth parameter below should
* perhaps be B_TRUE, it really shouldn't be.
*/
return (Z_ERR);
return (Z_ERR);
}
static int
{
struct zone_rctltab rctltab;
return (Z_NOMEM);
}
return (error);
}
struct zone_rctlvaltab *rctlval;
if (!zonecfg_is_rctl(name)) {
"'%s'."), name);
continue;
}
!= Z_OK) {
"(priv=%s,limit=%s,action%s)"),
goto out;
}
"is not a valid value for rctl '%s'"),
name);
goto out;
}
}
}
out:
(void) zonecfg_endrctlent(handle);
return (error);
}
static int
{
char poolname[MAXPATHLEN];
int status;
int error;
/*
* This ends up being very similar to the check done in zoneadmd.
*/
/*
* No pool specified.
*/
return (0);
}
"configuration"), B_TRUE);
return (error);
}
/*
* Don't do anything if pools aren't enabled.
*/
"zone will not be bound to pool '%s'."), poolname);
return (Z_OK);
}
/*
* Try to provide a sane error message if the requested pool doesn't
* exist. It isn't clear that pools-related failures should
* necessarily translate to a failure to verify the zone configuration,
* hence they are not considered errors.
*/
"using default pool"));
return (Z_OK);
}
PO_SUCCESS) {
"using default pool"));
return (Z_OK);
}
(void) pool_conf_close(poolconf);
"using default pool"), poolname);
}
return (Z_OK);
}
static int
{
int return_code = Z_OK;
struct zone_fstab fstab;
char specdir[MAXPATHLEN];
/*
* TRANSLATION_NOTE
* inherit-pkg-dirs is a literal that should not be translated.
*/
"inherit-pkg-dirs: unable to enumerate mounts\n"));
return (Z_ERR);
}
/*
* Verify fs_dir exists.
*/
/*
* TRANSLATION_NOTE
* inherit-pkg-dir is a literal that should not be
* translated.
*/
"inherit-pkg-dir %s: %s\n"),
return_code = Z_ERR;
}
/*
* TRANSLATION_NOTE
* inherit-pkg-dir and NFS are literals that should
* not be translated.
*/
"inherit-pkg-dir %s: NFS mounted file system.\n"
"\tA local file system must be used.\n"),
return_code = Z_ERR;
}
}
(void) zonecfg_endipdent(handle);
return (return_code);
}
/*
*/
static int
{
return (verify_fs_zfs(fstab));
return (Z_ERR);
}
/*
* TRANSLATION_NOTE
* fs and NFS are literals that should
* not be translated.
*/
"fs %s: NFS mounted file system.\n"
"\tA local file system must be used.\n"),
return (Z_ERR);
}
return (Z_OK);
}
static int
{
int return_code = Z_OK;
struct zone_fstab fstab;
char cmdbuf[MAXPATHLEN];
/*
* No need to verify inherit-pkg-dir fs types, as their type is
* implicitly lofs, which is known. Therefore, the types are only
* verified for regular file systems below.
*
* Since the actual mount point is not known until the dependent mounts
* are performed, we don't attempt any path validation here: that will
* happen later when zoneadmd actually does the mounts.
*/
"unable to enumerate mounts\n"));
return (Z_ERR);
}
return_code = Z_ERR;
goto next_fs;
}
/*
*/
return_code = Z_ERR;
goto next_fs;
}
return_code = Z_ERR;
goto next_fs;
}
"%s: %s is not a regular file\n"),
return_code = Z_ERR;
goto next_fs;
}
/*
* set.
*/
return_code = Z_ERR;
goto next_fs;
}
"%s: must specify 'raw' device for %s "
"file systems\n"),
return_code = Z_ERR;
goto next_fs;
}
"'raw' device specified but "
"no fsck executable exists for %s\n"),
return_code = Z_ERR;
goto next_fs;
}
/* Verify fs_special. */
goto next_fs;
/* Verify fs_raw. */
/*
* TRANSLATION_NOTE
* fs is a literal that should not be translated.
*/
return_code = Z_ERR;
goto next_fs;
}
}
(void) zonecfg_endfsent(handle);
return (return_code);
}
static int
{
int err;
return (Z_NOMEM);
}
switch (err) {
case Z_OK:
break;
case Z_PRIV_PROHIBITED:
"permitted within the zone's privilege set\n"), privname);
break;
case Z_PRIV_REQUIRED:
"missing from the zone's privilege set\n"), privname);
break;
case Z_PRIV_UNKNOWN:
"specified in the zone's privilege set\n"), privname);
break;
default:
gettext("failed to determine the zone's privilege set"),
B_TRUE);
break;
}
return (err);
}
static void
{
int i;
for (i = 0; i < if_cnt; i++) {
}
}
/*
* Get a list of the network interfaces, along with their address families,
* that are plumbed in the global zone. See if_tcp(7p) for a description
* of the ioctls used here.
*/
static int
{
int s;
int i;
int space_needed;
int cnt = 0;
char *if_buf;
*if_cnt = 0;
return (Z_ERR);
/*
* Come back here in the unlikely event that the number of interfaces
* increases between the time we get the count and the time we do the
* SIOCGLIFCONF ioctl.
*/
/* Get the number of interfaces. */
(void) close(s);
return (Z_ERR);
}
/* Get the interface configuration list. */
(void) close(s);
return (Z_ERR);
}
/*
* SIOCGLIFCONF returns EINVAL if the buffer we passed in is
* too small. In this case go back and get the new if cnt.
*/
goto retry;
(void) close(s);
return (Z_ERR);
}
(void) close(s);
/* Get the name and address family for each interface. */
struct net_if **p;
if_reqp++;
continue;
}
SOCK_DGRAM, 0)) == -1) {
break;
}
(void) close(s);
if_reqp++;
continue;
}
break;
}
local_ifs = p;
break;
}
== NULL) {
break;
}
cnt++;
(void) close(s);
if_reqp++;
}
} else {
}
return (res);
}
static char *
{
switch (af) {
case AF_INET:
return ("IPv4");
case AF_INET6:
return ("IPv6");
default:
return ("Unknown");
}
}
/*
* Cross check the network interface name and address family with the
* interfaces that are set up in the global zone so that we can print the
* appropriate error message.
*/
static void
{
int i;
int local_if_cnt = 0;
gettext("could not verify %s %s=%s %s=%s\n\t%s\n"),
return;
}
for (i = 0; i < local_if_cnt; i++) {
break;
}
}
}
if (!found_if) {
gettext("could not verify %s %s=%s\n\t"
"network interface %s is not plumbed in the global zone\n"),
return;
}
/*
* Print this error if we were unable to find the address family
* for this interface. If the af variable is not initialized to
* to something meaningful by the caller (not AF_UNSPEC) then we
* also skip this message since it wouldn't be informative.
*/
gettext("could not verify %s %s=%s %s=%s\n\tthe %s address "
"family is not configured on this interface in the\n\t"
"global zone\n"),
return;
}
gettext("could not verify %s %s=%s %s=%s\n\t%s\n"),
}
static int
{
struct zone_nwiftab nwiftab;
int return_code = Z_OK;
int err;
if (in_alt_root)
goto no_net;
return (Z_ERR);
}
/* skip any loopback interfaces */
continue;
return_code = Z_ERR;
continue;
}
"%s=%s %s=%s: could not get socket: %s\n"), "net",
return_code = Z_ERR;
continue;
}
return_code = Z_ERR;
}
}
(void) zonecfg_endnwifent(handle);
/* verify that lofs has not been excluded from the kernel */
else
return_code = Z_ERR;
}
return_code = Z_ERR;
return_code = Z_ERR;
return_code = Z_ERR;
return_code = Z_ERR;
return_code = Z_ERR;
/*
* or other maintenance processes, the zone's privilege set is not
* checked in this case. Instead, the default, safe set of
* privileges will be used when this zone is created in the
* kernel.
*/
return_code = Z_ERR;
return (return_code);
}
static int
verify_details(int cmd_num)
{
int return_code = Z_OK;
int err;
return (Z_ERR);
}
return (Z_ERR);
}
Z_OK) {
return (Z_ERR);
}
/*
* zonecfg_get_zonepath() gets its data from the XML repository.
* Verify this against the index file, which is checked first by
* zone_get_zonepath(). If they don't match, bail out.
*/
return (Z_ERR);
}
/*
* TRANSLATION_NOTE
* XML and zonepath are literals that should not be translated.
*/
"zonepath '%s',\nbut the index file has zonepath '%s'.\n"
"These must match, so fix the incorrect entry.\n"),
return (Z_ERR);
}
"because of the above errors.\n"), zonepath);
return_code = Z_ERR;
}
return_code = Z_ERR;
if (return_code == Z_ERR)
gettext("%s: zone %s failed to verify\n"),
return (return_code);
}
static int
{
int arg;
optind = 0;
switch (arg) {
case '?':
default:
return (Z_USAGE);
}
}
return (Z_USAGE);
}
return (Z_ERR);
return (verify_details(CMD_VERIFY));
}
#define LUCREATEZONE "/usr/lib/lu/lucreatezone"
static int
{
/* 9: "exec " and " -z " */
int lockfd;
char zonepath[MAXPATHLEN];
int status;
if (zonecfg_in_alt_root()) {
return (Z_ERR);
}
optind = 0;
switch (arg) {
case '?':
case 'x':
return (Z_USAGE);
}
break;
default:
return (Z_USAGE);
}
}
return (Z_USAGE);
}
return (Z_ERR);
return (Z_ERR);
"zoneadm");
return (Z_ERR);
}
goto done;
}
/*
* According to the Application Packaging Developer's Guide, a
* "checkinstall" script when included in a package is executed as
* the user "install", if such a user exists, or by the user
* "nobody". In order to support this dubious behavior, the path
* to the zone being constructed is opened up during the life of
* the command laying down the zone's root file system. Once this
* has completed, regardless of whether it was successful, the
* path to the zone is again restricted.
*/
goto done;
}
if (!nodataset)
goto done;
}
/*
* "exec" the command so that the returned status is that of
* LUCREATEZONE and not the shell.
*/
goto done;
}
goto done;
goto done;
}
done:
}
/*
* Check that the inherited pkg dirs are the same for the clone and its source.
* The easiest way to do that is check that the list of ipds is the same
* by matching each one against the other. This algorithm should be fine since
* the list of ipds should not be that long.
*/
static int
{
int err;
int s_cnt = 0;
int t_cnt = 0;
struct zone_fstab s_fstab;
struct zone_fstab t_fstab;
/*
* First check the source of the clone against the target.
*/
"inherit-pkg-dirs"));
return (Z_ERR);
}
s_cnt++;
"inherit-pkg-dirs"));
(void) zonecfg_endipdent(s_handle);
return (Z_ERR);
}
== 0) {
break;
}
}
(void) zonecfg_endipdent(t_handle);
if (!match) {
"'%s' is not configured in zone %s.\n"),
}
}
(void) zonecfg_endipdent(s_handle);
/* skip the next check if we already have errors */
return (res);
/*
* Now check the number of ipds in the target so we can verify
* that the source is not a subset of the target.
*/
"inherit-pkg-dirs"));
return (Z_ERR);
}
t_cnt++;
(void) zonecfg_endipdent(t_handle);
"with inherit-pkg-dirs that are not configured in zone "
}
return (res);
}
static void
{
int err;
struct zone_devtab s_devtab;
struct zone_devtab t_devtab;
return;
}
gettext("could not enumerate devices"));
(void) zonecfg_enddevent(t_handle);
return;
}
/*
* Use fnmatch to catch the case where wildcards
* were used in one zone and the other has an
*/
gettext("WARNING: device '%s' "
"is configured in both zones.\n"),
break;
}
}
(void) zonecfg_enddevent(s_handle);
}
(void) zonecfg_enddevent(t_handle);
}
/*
* Check if the specified mount option (opt) is contained within the
* options string.
*/
static boolean_t
{
char *p;
char *lastp;
return (B_TRUE);
return (B_TRUE);
}
}
return (B_FALSE);
}
#define RW_LOFS "WARNING: read-write lofs file system on '%s' is configured " \
"in both zones.\n"
static void
{
/*
* It is ok to have shared lofs mounted fs but we want to warn if
* either is rw since this will effect the other zone.
*/
/* The default is rw so no options means rw */
return;
}
return;
}
}
return;
}
}
return;
}
/*
* TRANSLATION_NOTE
* The first variable is the file system type and the second is
* the file system special device. For example,
*/
}
static void
{
int err;
struct zone_fstab s_fstab;
struct zone_fstab t_fstab;
gettext("could not enumerate file systems"));
return;
}
gettext("could not enumerate file systems"));
(void) zonecfg_endfsent(t_handle);
return;
}
s_fstab.zone_fs_special) == 0) {
break;
}
}
(void) zonecfg_endfsent(s_handle);
}
(void) zonecfg_endfsent(t_handle);
}
/*
* We don't catch the case where you used the same IP address but
* it is not an exact string match. For example, 192.9.0.128 vs. 192.09.0.128.
* However, we're not going to worry about that but we will check for
* a possible netmask on one of the addresses (e.g. 10.0.0.1 and 10.0.0.1/24)
* and handle that case as a match.
*/
static void
{
int err;
struct zone_nwiftab s_nwiftab;
struct zone_nwiftab t_nwiftab;
gettext("could not enumerate network interfaces"));
return;
}
char *p;
/* remove an (optional) netmask from the address */
*p = '\0';
gettext("could not enumerate network interfaces"));
(void) zonecfg_endnwifent(t_handle);
return;
}
/* remove an (optional) netmask from the address */
!= NULL)
*p = '\0';
s_nwiftab.zone_nwif_address) == 0) {
gettext("WARNING: network address '%s' "
"is configured in both zones.\n"),
break;
}
}
(void) zonecfg_endnwifent(s_handle);
}
(void) zonecfg_endnwifent(t_handle);
}
static void
{
int err;
struct zone_dstab s_dstab;
struct zone_dstab t_dstab;
return;
}
gettext("could not enumerate datasets"));
(void) zonecfg_enddsent(t_handle);
return;
}
s_dstab.zone_dataset_name) == 0) {
gettext("WARNING: dataset '%s' "
"is configured in both zones.\n"),
break;
}
}
(void) zonecfg_enddsent(s_handle);
}
(void) zonecfg_enddsent(t_handle);
}
static int
{
return (Z_ERR);
}
return (Z_ERR);
}
return (Z_ERR);
}
goto done;
}
/* verify new zone has same inherit-pkg-dirs */
/* warn about imported fs's which are the same */
/* warn about imported IP addresses which are the same */
/* warn about imported devices which are the same */
/* warn about imported datasets which are the same */
done:
}
static int
{
int status;
int err;
char *outfile;
}
/*
* Use find to get the list of files to copy. We need to skip
* files of type "socket" since cpio can't handle those but that
* should be ok since the app will recreate the socket when it runs.
* We also need to filter out anything under the .zfs subdir. Since
* find is running depth-first, we need the extra egrep to filter .zfs.
*/
if (!out_null)
"More information can be found in %s\n"), outfile);
return (err);
}
if (!out_null)
return (Z_OK);
}
/*
* Run sys-unconfig on a zone. This will leave the zone in the installed
* state as long as there were no errors during the sys-unconfig.
*/
static int
unconfigure_zone(char *zonepath)
{
int err;
int status;
struct stat unconfig_buf;
/* The zone has to be installed in order to mount the scratch zone. */
return (Z_ERR);
}
/*
* Trusted Extensions requires that cloned zones use the
* same sysid configuration, so it is not appropriate to
* unconfigure the zone.
*/
if (is_system_labeled())
return (Z_OK);
/*
* Check if the zone is already sys-unconfiged. This saves us
* the work of bringing up the scratch zone so we can unconfigure it.
*/
zonepath);
return (Z_OK);
return (Z_ERR);
}
"/usr/sbin/zlogin -S %s /usr/sbin/sys-unconfig -R /a", target_zone);
}
return (Z_ERR);
}
}
/* ARGSUSED */
static int
zfm_print(const char *p, void *r) {
zerror(" %s\n", p);
return (0);
}
int
{
int err;
/* Don't clone the zone if anything is still mounted there */
"subdirectories of %s.\n"), source_zonepath);
return (Z_ERR);
}
/*
* Attempt to create a ZFS fs for the zonepath. As usual, we don't
* care if this works or not since we always have the default behavior
* of a simple directory for the zonepath.
*/
(void) printf("\n");
return (err);
}
static int
{
char *source_zone = NULL;
int lockfd;
char zonepath[MAXPATHLEN];
char source_zonepath[MAXPATHLEN];
if (zonecfg_in_alt_root()) {
return (Z_ERR);
}
optind = 0;
switch (arg) {
case '?':
case 'm':
break;
case 's':
break;
default:
return (Z_USAGE);
}
}
return (Z_USAGE);
}
return (Z_ERR);
return (Z_ERR);
/*
* We also need to do some extra validation on the source zone.
*/
return (Z_ERR);
}
return (Z_ERR);
}
/* check whether the zone is ready or running */
!= Z_OK) {
/* can't tell, so hedge */
} else {
}
return (Z_ERR);
}
return (Z_ERR);
}
if (state != ZONE_STATE_INSTALLED) {
gettext("%s: zone %s is %s; %s is required.\n"),
return (Z_ERR);
}
/*
* The source zone checks out ok, continue with the clone.
*/
return (Z_ERR);
"zoneadm");
return (Z_ERR);
}
sizeof (source_zonepath))) != Z_OK) {
goto done;
}
!= Z_OK) {
goto done;
}
!= Z_OK) {
goto done;
}
} else {
/*
* We always copy the clone unless the source is ZFS and a
* ZFS clone worked. We fallback to copying if the ZFS clone
* fails for some reason.
*/
}
done:
}
/*
* Used when removing a zonepath after uninstalling or cleaning up after
* the move subcommand. This handles a zonepath that has non-standard
* contents so that we will only cleanup the stuff we know about and leave
* any user data alone.
*
* If the "all" parameter is true then we should remove the whole zonepath
* even if it has non-standard files/directories in it. This can be used when
* we need to cleanup after moving the zonepath across file systems.
*
* We "exec" the RMCOMMAND so that the returned status is that of RMCOMMAND
* and not the shell.
*/
static int
{
int status;
int i;
/* (MAXPATHLEN * 3) is for the 3 std_entries dirs */
/*
* We shouldn't need these checks but lets be paranoid since we
* could blow away the whole system here if we got the wrong zonepath.
*/
return (Z_INVAL);
}
/*
* If the dirpath is already gone (maybe it was manually removed) then
* we just return Z_OK so that the cleanup is successful.
*/
return (Z_OK);
/*
* Look through the zonepath directory to see if there are any
* there but we'll handle ZFS file systems as a special case.
*/
continue;
for (i = 0; std_entries[i] != NULL; i++)
break;
if (std_entries[i] == NULL)
}
/*
* There are extra, non-standard directories/files in the
* zonepath so we don't want to remove the zonepath. We
* just want to remove the standard directories and leave
* the user data alone.
*/
for (i = 0; std_entries[i] != NULL; i++) {
char tmpbuf[MAXPATHLEN];
sizeof (cmdbuf)) {
gettext("path is too long\n"));
return (Z_INVAL);
}
}
"remove %s\nbecause it contains additional user data. "
"Only the standard directory\nentries have been "
"removed.\n"),
zonepath);
}
/*
* There is nothing unexpected in the zonepath, try to get rid of the
* whole zonepath directory.
*
* If the zonepath is its own zfs file system, try to destroy the
* file system. If that fails for some reason (e.g. it has clones)
* then we'll just remove the contents of the zonepath.
*/
if (is_zonepath_zfs(zonepath)) {
return (Z_OK);
" %s/*", zonepath);
}
zonepath);
}
static int
{
char *new_zonepath = NULL;
int lockfd;
char zonepath[MAXPATHLEN];
struct stat zonepath_buf;
struct stat new_zonepath_buf;
if (zonecfg_in_alt_root()) {
return (Z_ERR);
}
optind = 0;
switch (arg) {
case '?':
default:
return (Z_USAGE);
}
}
return (Z_USAGE);
}
return (Z_ERR);
return (Z_ERR);
/*
* Check out the new zonepath. This has the side effect of creating
* a directory for the new zonepath. We depend on this later when we
* stat to see if we are doing a cross file system move or not.
*/
return (Z_ERR);
!= Z_OK) {
return (Z_ERR);
}
return (Z_ERR);
}
return (Z_ERR);
}
/*
* Check if the destination directory is empty.
*/
return (Z_ERR);
}
continue;
break;
}
/* Error if there is anything in the destination directory. */
if (!empty) {
"directory not empty\n"), new_zonepath);
return (Z_ERR);
}
/* Don't move the zone if anything is still mounted there */
"subdirectories of %s.\n"), zonepath);
return (Z_ERR);
}
/*
* Check if we are moving in the same file system and can do a fast
* move or if we are crossing file systems and have to copy the data.
*/
return (Z_ERR);
}
return (Z_ERR);
}
"zoneadm");
return (Z_ERR);
}
/*
* We're making some file system changes now so we have to clean up
* the file system before we are done. This will either clean up the
* new zonepath if the zonecfg update failed or it will clean up the
* old zonepath if everything is ok.
*/
if (is_zonepath_zfs(zonepath) &&
} else if (fast) {
/* same file system, use rename for a quick move */
/*
* Remove the new_zonepath directory that got created above
* during the validation. It gets in the way of the rename.
*/
if (rmdir(new_zonepath) != 0) {
B_FALSE);
return (Z_ERR);
}
/*
* If this fails we don't need to do all of the
* cleanup that happens for the rest of the code
* so just return from this error.
*/
return (Z_ERR);
}
} else {
/*
* Attempt to create a ZFS fs for the new zonepath. As usual,
* we don't care if this works or not since we always have the
* default behavior of a simple directory for the zonepath.
*/
"Moving across file systems; copying zonepath %s..."),
zonepath);
(void) printf("\n");
goto done;
}
goto done;
}
goto done;
}
done:
/*
* Clean up the file system based on how things went. We either
* clean up the new zonepath if the operation failed for some reason
* or we clean up the old zonepath if everything is ok.
*/
if (revert) {
/* The zonecfg update failed, cleanup the new zonepath. */
if (is_zfs) {
"restore zonepath, the zfs mountpoint is "
"set as:\n%s\n"), new_zonepath);
/*
* err is already != Z_OK since we're reverting
*/
}
} else if (fast) {
B_FALSE);
/*
* err is already != Z_OK since we're reverting
*/
}
} else {
(void) printf("\n");
"zonepath"), B_TRUE);
} else {
/*
* Because we're reverting we know the mainline
* code failed but we just reused the err
* variable so we reset it back to Z_ERR.
*/
}
}
} else {
/* The move was successful, cleanup the old zonepath. */
(void) printf(
(void) printf("\n");
B_TRUE);
}
}
}
}
static int
{
int lockfd;
char zonepath[MAXPATHLEN];
if (zonecfg_in_alt_root()) {
return (Z_ERR);
}
optind = 0;
switch (arg) {
case '?':
case 'n':
break;
default:
return (Z_USAGE);
}
}
if (execute) {
!= Z_OK)
return (Z_ERR);
return (Z_ERR);
} else {
/*
* We want a dry-run to work for a non-privileged user so we
* only do minimal validation.
*/
if (getzoneid() != GLOBAL_ZONEID) {
return (Z_ERR);
}
if (target_zone == NULL) {
return (Z_ERR);
}
return (Z_ERR);
}
}
!= Z_OK) {
return (Z_ERR);
}
/* Don't detach the zone if anything is still mounted there */
"subdirectories of %s.\n"), zonepath);
return (Z_ERR);
}
return (Z_ERR);
}
return (Z_ERR);
}
"zoneadm");
return (Z_ERR);
}
B_TRUE);
goto done;
}
!= Z_OK) {
goto done;
}
/*
* Set the zone state back to configured unless we are running with the
* no-execute option.
*/
ZONE_STATE_CONFIGURED)) != Z_OK) {
}
done:
if (execute)
}
/*
* During attach we go through and fix up the /dev entries for the zone
* we are attaching. In order to regenerate /dev with the correct devices,
* the old /dev will be removed, the zone readied (which generates a new
* /dev) then halted, then we use the info from the manifest to update
* the modes, owners, etc. on the new /dev.
*/
static int
{
int res;
int err;
int status;
struct zone_devpermtab devtab;
char devpath[MAXPATHLEN];
/* 6: "exec " and " " */
!= Z_OK)
return (res);
return (Z_TOO_BIG);
/*
* "exec" the command so that the returned status is that of
* RMCOMMAND and not the shell.
*/
devpath);
gettext("could not remove existing /dev\n"));
return (Z_ERR);
}
/* In order to ready the zone, it must be in the installed state */
return (Z_ERR);
}
/* We have to ready the zone to regen the dev tree */
return (Z_ERR);
}
return (Z_ERR);
}
gettext("unable to enumerate device entries\n"));
return (Z_ERR);
}
int err;
}
(void) zonecfg_enddevperment(handle);
return (Z_OK);
}
/*
* Validate attaching a zone but don't actually do the work. The zone
* does not have to exist, so there is some complexity getting a new zone
* configuration set up so that we can perform the validation. This is
* handled within zonecfg_attach_manifest() which returns two handles; one
* for the the full configuration to validate (rem_handle) and the other
* (local_handle) containing only the zone configuration derived from the
* manifest.
*/
static int
dryrun_attach(char *manifest_path)
{
int fd;
int err;
int res;
fd = 0;
return (Z_ERR);
}
goto done;
}
goto done;
}
!= Z_OK) {
if (err == Z_INVALID_DOCUMENT)
"of the operating system"));
else
goto done;
}
/* Get the detach information for the locally defined zone. */
B_TRUE);
} else {
/* sw_cmp prints error msgs as necessary */
}
done:
}
static int
{
int lockfd;
char zonepath[MAXPATHLEN];
char *manifest_path;
if (zonecfg_in_alt_root()) {
return (Z_ERR);
}
optind = 0;
switch (arg) {
case '?':
case 'F':
break;
case 'n':
break;
default:
return (Z_USAGE);
}
}
/*
* If the no-execute option was specified, we need to branch down
* a completely different path since there is no zone required to be
* configured for this option.
*/
if (!execute)
return (dryrun_attach(manifest_path));
return (Z_ERR);
return (Z_ERR);
!= Z_OK) {
return (Z_ERR);
}
return (Z_ERR);
}
return (Z_ERR);
}
"zoneadm");
return (Z_ERR);
}
if (force)
goto forced;
goto done;
}
else if (err == Z_INVALID_DOCUMENT)
"of the operating system"));
else
goto done;
}
/* Get the detach information for the locally defined zone. */
B_TRUE);
goto done;
}
/* sw_cmp prints error msgs as necessary */
goto done;
goto done;
}
done:
}
/*
* On input, TRUE => yes, FALSE => no.
* On return, TRUE => 1, FALSE => 0, could not ask => -1.
*/
static int
{
if (!isatty(STDIN_FILENO))
return (-1);
for (;;) {
line[0] == '\n')
return (default_answer ? 1 : 0);
return (1);
return (0);
}
}
static int
{
if (zonecfg_in_alt_root()) {
return (Z_ERR);
}
optind = 0;
switch (arg) {
case '?':
case 'F':
break;
default:
return (Z_USAGE);
}
}
return (Z_USAGE);
}
return (Z_ERR);
if (!force) {
gettext("Are you sure you want to %s zone %s"),
return (Z_OK);
} else if (answer == -1) {
"not specified: %s not done."),
return (Z_ERR);
}
}
return (Z_ERR);
}
return (Z_ERR);
}
/*
* If there seems to be a zoneadmd running for this zone, call it
* to tell it that an uninstall is happening; if all goes well it
* will then shut itself down.
*/
/* we don't care too much if this fails... just plow on */
}
"zoneadm");
return (Z_ERR);
}
/* Don't uninstall the zone if anything is mounted there */
if (err) {
"subdirectories of %s.\n"), rootpath);
return (Z_ERR);
}
goto bad;
}
goto bad;
}
}
bad:
return (err);
}
/* ARGSUSED */
static int
{
if (argc > 0)
return (Z_USAGE);
return (Z_ERR);
return (Z_ERR);
return (Z_ERR);
}
return (Z_OK);
}
/* ARGSUSED */
static int
{
if (argc > 0)
return (Z_USAGE);
return (Z_ERR);
return (Z_ERR);
}
return (Z_OK);
}
static int
{
if (argc == 0) {
return (Z_OK);
}
optind = 0;
switch (arg) {
case '?':
default:
return (Z_USAGE);
}
}
/* Private commands have NULL short_usage; omit them */
return (Z_USAGE);
}
optind++;
}
return (Z_OK);
}
/*
* Returns: CMD_MIN thru CMD_MAX on success, -1 on error
*/
static int
{
int i;
/* return only if there is an exact match */
}
return (-1);
}
static int
{
if (i < 0)
}
static char *
get_execbasename(char *execfullname)
{
char *last_slash, *execbasename;
/* guard against '/' at end of command invocation */
for (;;) {
if (last_slash == NULL) {
break;
} else {
if (*execbasename == '\0') {
*last_slash = '\0';
continue;
}
break;
}
}
return (execbasename);
}
int
{
int arg;
locale = "C";
(void) textdomain(TEXT_DOMAIN);
target_zone = NULL;
if (chdir("/") != 0) {
}
switch (arg) {
case '?':
case 'z':
break;
if (*optarg != '/') {
}
gettext("root path must be a directory."));
}
break;
default:
}
}
}
}