zoneadm.c revision ad02e316a67d13beb1097678544eef2a6757fb75
/*
* 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
*/
/*
*/
/*
* 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 <libbrand.h>
#include <libscf.h>
#include <procfs.h>
#include <strings.h>
#include <pool.h>
#include <sys/priocntl.h>
#include <sys/fsspriocntl.h>
#include <libdladm.h>
#include <libdllink.h>
#include "zoneadm.h"
#define MAXARGS 8
/* Reflects kernel zone entries */
typedef struct zone_entry {
char zname[ZONENAME_MAX];
char *zstate_str;
char zbrand[MAXNAMELEN];
char zroot[MAXPATHLEN];
} zone_entry_t;
#define CLUSTER_BRAND_NAME "cluster"
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 [brand-specific args]"
#define SHELP_UNINSTALL "uninstall [-F] [brand-specific args]"
#define SHELP_CLONE "clone [-m method] [-s <ZFS snapshot>] "\
"[brand-specific args] zonename"
#define SHELP_MOVE "move zonepath"
#define SHELP_DETACH "detach [-n] [brand-specific args]"
#define SHELP_ATTACH "attach [-F] [-n <path>] [brand-specific args]"
#define SHELP_MARK "mark incomplete"
#define EXEC_PREFIX "exec "
static int cleanup_zonepath(char *, boolean_t);
static int verify_details(int, char *argv[]);
static int invoke_brand_handler(int, char *argv[]);
};
/* global variables */
/* set early in main(), never modified thereafter, used all over the place */
static char *execname;
static char target_brand[MAXNAMELEN];
static char default_brand[MAXPATHLEN];
static char *locale;
char *target_zone;
static char *target_uuid;
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 "
"<uuid-match>\n\toptions, lists only the specified "
"matching zone, but lists it\n\tregardless of its state, "
"and the -i and -c options are disallowed. The\n\t-v "
"option can be used to display verbose information: zone "
"name, id,\n\tcurrent state, root directory and options. "
"The -p option can be used\n\tto request machine-parsable "
"output. The -v and -p options are mutually\n\texclusive."
" If neither -v nor -p is used, just 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. "
"All arguments are passed to the brand installation "
"function;\n\tsee brands(5) for more information."));
case CMD_UNINSTALL:
return (gettext("Uninstall the configuration from the system. "
"The -F flag can be used\n\tto force the action. All "
"other arguments are passed to the brand\n\tuninstall "
"function; see brands(5) for more information."));
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. All other arguments are "
"passed\n\tto the brand clone function; see "
"brands(5) for more information."));
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. All other "
"arguments are passed to the brand detach function;\n\tsee "
"brands(5) for more information."));
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\tused, 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. The -F and -n "
"options are mutually\n\texclusive. All other arguments "
"are passed to the brand attach\n\tfunction; see "
"brands(5) for more information."));
case CMD_MARK:
return (gettext("Set the state of the zone. This can be used "
"to force the zone\n\tstate to 'incomplete' "
"administratively if some activity has rendered\n\tthe "
"zone permanently unusable. The only valid state that "
"may be\n\tspecified is 'incomplete'."));
default:
return ("");
}
/* NOTREACHED */
return (NULL);
}
/*
* Called with explicit B_TRUE when help is explicitly requested, B_FALSE for
* unexpected errors.
*/
static int
{
int i;
execname);
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
{
char *ip_type_str;
/* Skip a zone that shutdown while we were collecting data. */
return;
ip_type_str = "excl";
else
ip_type_str = "shared";
(void) printf("%*s %-16s %-10s %-30s %-8s %-6s\n",
"IP");
}
if (!verbose) {
if (!parsable) {
return;
}
(void) printf("-");
else
}
return;
}
else
}
}
static int
{
int err;
!uuid_is_null(uuid))
else
/*
* 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);
}
/*
* A zone's brand is only available in the .xml file describing it,
* which is only visible to the global zone. This causes
* zone_get_brand() to fail when called from within a non-global
* zone. Fortunately we only do this on labeled systems, where we
* know all zones are native.
*/
if (getzoneid() != GLOBAL_ZONEID) {
assert(is_system_labeled() != 0);
return (Z_ERR);
}
/*
* Get ip type of the zone.
* Note for global zone, ZS_SHARED is set always.
*/
if (zid == GLOBAL_ZONEID) {
return (Z_OK);
}
/*
* There is a race condition where the zone could boot while
* we're walking the index file. In this case the zone state
* could be seen as running from the call above, but the zoneid
* would be undefined.
*
* There is also a race condition where the zone could shutdown after
* we got its running state above. This is also not an error and
* we fall back to getting the ziptype from the zone configuration.
*/
zid != ZONE_ID_UNDEFINED) {
sizeof (flags)) >= 0) {
if (flags & ZF_NET_EXCL)
else
return (Z_OK);
}
}
return (Z_ERR);
}
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.
*
* Note that the data about running zones can change while this function
* is running, so its possible that the list of zones will have empty slots
* at the end.
*/
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];
/*
* There is a race condition where the zone may have
* shutdown since we retrieved the number of running
* zones above. This is not an error, there will be
* an empty slot at the end of the list.
*/
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;
}
/*
* There is a race condition where the zone may have
* shutdown since we retrieved the number of running
* zones above. This is not an error, there will be
* an empty slot at the end of the list.
*/
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);
}
/*
* Retrieve a zone entry by name. Returns NULL if no such zone exists.
*/
static zone_entry_t *
lookup_running_zone(const char *str)
{
int i;
if (fetch_zents() != Z_OK)
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);
return (Z_ERR);
}
/* Not detached, check if it really looks ok. */
"directory.\n"), rootpath);
return (Z_ERR);
}
"owned by root.\n"), rootpath);
return (Z_ERR);
}
"0755.\n"), rootpath);
return (Z_ERR);
}
}
}
}
static int
{
int err;
return (Z_ERR);
}
return (Z_ERR);
}
return (Z_ERR);
}
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);
}
!= Z_OK)
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), -f (a private option to indicate that the
* boot operation should be 'forced'), or -s. Support for -s is
* vestigal and obsolete, but is retained because it was a
* documented interface and there are known consumers including
* is:
*
* zoneadm -z myzone boot -- -s -v -m verbose.
*/
optind = 0;
switch (arg) {
case '?':
case 's':
break;
case 'f':
break;
default:
return (Z_USAGE);
}
}
return (Z_ERR);
}
return (Z_ERR);
}
}
!= Z_OK)
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 {
}
!uuid_is_null(uuid))
}
if (flags & ZF_NET_EXCL)
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);
}
/*
* 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.
*/
}
/*
* Invoke brand-specific handler. Note that we do this
* only if we're in the global zone, and target_zone is specified
* and it is not the global zone.
*/
return (Z_ERR);
}
int
do_subproc(char *cmdbuf)
{
void (*saveint)(int);
void (*saveterm)(int);
void (*savequit)(int);
void (*savehup)(int);
}
if (child == -1)
return (-1);
;
}
int
{
return (exit_code);
} else if (WIFSIGNALED(status)) {
char sigstr[SIG2STR_MAX];
sigstr);
} else {
cmd);
}
} else {
}
/*
* Assume a subprocess that died due to a signal or an unknown error
* should be considered an exit code of ZONE_SUBPROC_FATAL, as the
* user will likely need to do some manual cleanup.
*/
return (ZONE_SUBPROC_FATAL);
}
/*
* 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.
*/
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:
if (state == ZONE_STATE_INSTALLED) {
return (Z_ERR);
return (Z_ERR);
}
break;
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:
case CMD_MARK:
else
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;
case CMD_SYSBOOT:
if (state != ZONE_STATE_INSTALLED) {
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.
*/
!= Z_OK)
return (Z_ERR);
/*
* Invoke brand-specific handler.
*/
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.
*/
!= Z_OK)
return (Z_ERR);
return (Z_ERR);
}
static int
{
return (Z_ERR);
return (Z_ERR);
cmd[0] = '\0';
return (Z_OK);
}
static int
{
char cmdbuf[MAXPATHLEN];
int err;
char zonepath[MAXPATHLEN];
int status, i;
/*
* Fetch the verify command from the brand configuration.
* "exec" the command so that the returned status is that of
* the command and not the shell.
*/
return (Z_ERR);
}
return (Z_ERR);
}
/*
* If the brand has its own verification routine, execute it now.
* The verification routine validates the intended zoneadm
* operation for the specific brand. The zoneadm subcommand and
* all its arguments are passed to the routine.
*/
return (Z_BRAND_ERROR);
if (cmdbuf[0] == '\0')
return (Z_OK);
return (Z_ERR);
/* Build the argv string */
i = 0;
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
{
/*
* This validation is really intended for standard zone administration.
* If we are in a mini-root or some other upgrade situation where
* we are using the scratch zone, just by-pass this.
*/
if (zonecfg_in_alt_root())
return (Z_OK);
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
{
return (-1);
}
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;
}
/*
* If zone_fs_raw is set, verify that there's an fsck
* binary for it. If zone_fs_raw is not set, and it's
* not a regular file (lofi mount), and there's an fsck
* binary for it, complain.
*/
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;
"%s: must specify 'raw' device for %s "
"file systems\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 network interface in "
"the\n\tglobal 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;
char errmsg[DLADM_STRSIZE];
if (in_alt_root)
goto no_net;
return (Z_ERR);
}
return (Z_ERR);
}
char dl_owner_zname[ZONENAME_MAX];
int res;
/* skip any loopback interfaces */
continue;
switch (iptype) {
case ZS_SHARED:
if ((res = zonecfg_valid_net_address(
return_code = Z_ERR;
continue;
}
if (!zonecfg_ifname_exists(af,
/*
* The interface failed to come up. We continue
* on anyway for the sake of consistency: a
* zone is not shut down if the interface fails
* any time after boot, nor does the global zone
* fail to boot if an interface fails.
*/
gettext("WARNING: skipping network "
"interface '%s' which may not be "
"zone.\n"),
}
break;
case ZS_EXCLUSIVE:
/* Warning if it exists for either IPv4 or IPv6 */
gettext("WARNING: skipping network "
"interface '%s' which is used in the "
"global zone.\n"),
break;
}
/*
* Verify that the datalink exists and that it isn't
* already assigned to a zone.
*/
}
if (status != DLADM_STATUS_OK) {
gettext("WARNING: skipping network "
"interface '%s': %s\n"),
break;
}
break;
/*
* If the zone being verified is
* running and owns the interface
*/
if (target_zid == dl_owner_zid)
break;
/* Zone id match failed, use name to check */
ZONENAME_MAX) < 0) {
/* No name, show ID instead */
"<%d>", dl_owner_zid);
break;
/*
* Note here we only report a warning that
* the interface is already in use by another
* running zone, and the verify process just
* goes on, if the interface is still in use
* when this zone really boots up, zoneadmd
* will find it. If the name of the zone which
* owns this interface cannot be determined,
* then it is not possible to determine if there
* is a conflict so just report it as a warning.
*/
gettext("WARNING: skipping network interface "
"'%s' which is used by the non-global zone "
break;
}
}
(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;
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
{
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);
}
if (cmd_num != CMD_ATTACH &&
"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);
}
!= Z_OK)
return (Z_ERR);
}
static int
{
int i = 0;
if (buf[0] == '\0')
return (Z_OK);
zerror("Command line too long");
return (Z_ERR);
}
}
return (Z_OK);
}
static int
{
char optstring[4];
if (opt > 0)
else
return (Z_ERR);
return (Z_ERR);
return (Z_OK);
}
/* ARGSUSED */
static int
{
char cmdbuf[MAXPATHLEN];
char postcmdbuf[MAXPATHLEN];
int lockfd;
char zonepath[MAXPATHLEN];
int status;
char opts[128];
if (target_zone == NULL) {
return (Z_USAGE);
}
if (zonecfg_in_alt_root()) {
return (Z_ERR);
}
return (Z_ERR);
}
/* Fetch the install command from the brand configuration. */
return (Z_ERR);
}
zerror("invalid brand configuration: missing install resource");
return (Z_ERR);
}
zerror("invalid brand configuration: missing postinstall "
"resource");
return (Z_ERR);
}
if (postcmdbuf[0] != '\0')
/*
* Fetch the list of recognized command-line options from
* the brand configuration file.
*/
zerror("invalid brand configuration: missing "
"install options resource");
return (Z_ERR);
}
if (cmdbuf[0] == '\0') {
zerror("Missing brand install command");
return (Z_ERR);
}
/* Check the argv string for args we handle internally */
optind = 0;
opterr = 0;
switch (arg) {
case '?':
if (optopt == '?') {
brand_help = B_TRUE;
}
/* Ignore unknown options - may be brand specific. */
break;
default:
/* Ignore unknown options - may be brand specific. */
break;
}
/*
* Append the option to the command line passed to the
* brand-specific install and postinstall routines.
*/
zerror("Install command line too long");
return (Z_ERR);
}
!= Z_OK) {
zerror("Post-Install command line too long");
return (Z_ERR);
}
}
zerror("Install command line too long");
return (Z_ERR);
}
!= Z_OK) {
zerror("Post-Install command line too long");
return (Z_ERR);
}
}
if (!brand_help) {
return (Z_ERR);
return (Z_ERR);
"progress."), "zoneadm");
return (Z_ERR);
}
goto done;
}
}
if ((subproc_err =
B_FALSE)) != ZONE_SUBPROC_OK) {
return (Z_ERR);
}
errno = subproc_err;
goto done;
}
if (brand_help)
return (Z_OK);
goto done;
}
if (do_postinstall) {
if ((subproc_err =
errno = subproc_err;
(void) zone_set_state(target_zone,
}
}
done:
/*
* If the install script exited with ZONE_SUBPROC_NOTCOMPLETE, try to
* clean up the zone and leave the zone in the CONFIGURED state so that
* another install can be attempted without requiring an uninstall
* first.
*/
if (subproc_err == ZONE_SUBPROC_NOTCOMPLETE) {
int temp_err;
gettext("cleaning up zonepath failed"));
ZONE_STATE_CONFIGURED)) != Z_OK) {
}
}
if (!brand_help)
}
/*
* 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';
/* For exclusive-IP zones, address is not specified. */
continue;
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) {
"is configured in both zones.\n"),
break;
}
}
(void) zonecfg_enddsent(s_handle);
}
(void) zonecfg_enddsent(t_handle);
}
/*
* Check that the clone and its source have the same brand type.
*/
static int
{
char source_brand[MAXNAMELEN];
sizeof (source_brand))) != Z_OK) {
return (Z_ERR);
}
gettext("%s: Zones '%s' and '%s' have different brand "
return (Z_ERR);
}
return (Z_ERR);
}
return (Z_OK);
}
static int
{
return (Z_ERR);
}
return (Z_ERR);
}
return (Z_ERR);
}
goto done;
}
/* verify new zone has same brand type */
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;
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 (Z_ERR);
}
if (!out_null)
return (Z_OK);
}
/* ARGSUSED */
int
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];
char cmdbuf[MAXPATHLEN];
char postcmdbuf[MAXPATHLEN];
char presnapbuf[MAXPATHLEN];
char postsnapbuf[MAXPATHLEN];
char validsnapbuf[MAXPATHLEN];
int status;
if (zonecfg_in_alt_root()) {
return (Z_ERR);
}
/* Check the argv string for args we handle internally */
optind = 0;
opterr = 0;
switch (arg) {
case '?':
if (optopt == '?') {
brand_help = B_TRUE;
}
/* Ignore unknown options - may be brand specific. */
break;
case 'm':
break;
case 's':
break;
default:
/* Ignore unknown options - may be brand specific. */
break;
}
}
return (Z_USAGE);
}
if (!brand_help) {
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 */
"state"));
/* can't tell, so hedge */
} else {
zent->zstate_str =
}
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);
"progress."), "zoneadm");
return (Z_ERR);
}
}
sizeof (source_zonepath))) != Z_OK) {
goto done;
}
!= Z_OK) {
goto done;
}
/*
* Fetch the clone and postclone hooks from the brand configuration.
*/
goto done;
}
zerror("invalid brand configuration: missing clone resource");
goto done;
}
zerror("invalid brand configuration: missing postclone "
"resource");
goto done;
}
zerror("invalid brand configuration: missing presnap "
"resource");
goto done;
}
zerror("invalid brand configuration: missing postsnap "
"resource");
goto done;
}
zerror("invalid brand configuration: missing validatesnap "
"resource");
goto done;
}
/* Append all options to clone hook. */
goto done;
}
/* Append all options to postclone hook. */
goto done;
}
if (!brand_help) {
!= Z_OK) {
goto done;
}
}
/*
* The clone hook is optional. If it exists, use the hook for
* cloning, otherwise use the built-in clone support
*/
if (cmdbuf[0] != '\0') {
/* Run the clone hook */
goto done;
}
if (brand_help)
return (Z_OK);
} else {
/* If just help, we're done since there is no brand help. */
if (brand_help)
return (Z_OK);
/* Run the built-in clone support. */
/* The only explicit built-in method is "copy". */
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.
*/
}
}
!= ZONE_SUBPROC_OK) {
}
}
done:
/*
* If everything went well, we mark the zone as installed.
*/
}
}
if (!brand_help)
}
/*
* 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;
/*
* The SUNWattached.xml file is expected since it might
* exist if the zone was force-attached after a
* migration.
*/
"SUNWattached.xml", NULL};
/* (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);
}
!= Z_OK)
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);
}
/*
* Collect information about mounts within the zone's zonepath.
* Overlay mounts on the zone's root directory are erroneous.
* Bail if we encounter any unexpected mounts.
*/
return (Z_ERR);
if (mounts.num_root_overlay_mounts != 0) {
goto err_and_mounts_destroy;
}
if (mounts.num_unexpected_mounts != 0)
goto err_and_mounts_destroy;
/*
* 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.
*/
goto err_and_mounts_destroy;
}
goto err_and_fini_handle;
}
"zoneadm");
goto err_and_fini_handle;
}
/*
* Unmount the zone's root filesystem before we move the zone's
* zonepath.
*/
goto err_and_rele_lockfile;
/*
* 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);
goto err_and_rele_lockfile;
}
/*
* 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.
*/
goto err_and_rele_lockfile;
}
} 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;
}
/*
* Mount the zone's root filesystem in the new zonepath if there was
* a root mount prior to the move.
*/
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) {
/*
* Check for the unlikely scenario in which the zone's
* zonepath and its root file system moved but libzonecfg
* couldn't save the new zonepath to the zone's configuration
* file. The mounted root filesystem must be unmounted before
* zoneadm restores the zone's zonepath.
*/
new_zonepath, B_TRUE) != 0) {
/*
* We can't forcibly unmount the zone's root file system
* from the new zonepath. Bail!
*/
goto err_and_mounts_destroy;
}
/* 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 {
}
} else if (fast) {
B_FALSE);
/*
* err is already != Z_OK since we're reverting
*/
} else {
}
} 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);
}
}
}
return (Z_ERR);
}
/* ARGSUSED */
static int
{
int lockfd = -1;
char zonepath[MAXPATHLEN];
char cmdbuf[MAXPATHLEN];
char precmdbuf[MAXPATHLEN];
int status;
if (zonecfg_in_alt_root()) {
return (Z_ERR);
}
/* Check the argv string for args we handle internally */
optind = 0;
opterr = 0;
switch (arg) {
case '?':
if (optopt == '?') {
brand_help = B_TRUE;
}
/* Ignore unknown options - may be brand specific. */
break;
case 'n':
break;
default:
/* Ignore unknown options - may be brand specific. */
break;
}
}
if (brand_help)
if (execute) {
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 (target_zone == NULL) {
return (Z_ERR);
}
return (Z_ERR);
}
}
!= Z_OK) {
return (Z_ERR);
}
/* Fetch the detach and predetach hooks from the brand configuration. */
return (Z_ERR);
}
zerror("invalid brand configuration: missing detach resource");
return (Z_ERR);
}
zerror("invalid brand configuration: missing predetach "
"resource");
return (Z_ERR);
}
/* Append all options to predetach hook. */
return (Z_ERR);
/* Append all options to detach hook. */
return (Z_ERR);
"zoneadm");
return (Z_ERR);
}
/* If we have a brand predetach hook, run it. */
if (execute) {
lockfd = -1;
}
return (Z_ERR);
}
}
if (cmdbuf[0] != '\0') {
/* Run the detach hook */
if (execute) {
lockfd = -1;
}
return (Z_ERR);
}
} else {
/* If just help, we're done since there is no brand help. */
if (brand_help) {
return (Z_OK);
}
/*
* Run the built-in detach support. Just generate a simple
* zone definition XML file and detach.
*/
/* Don't detach the zone if anything is still mounted there */
"mounted on subdirectories of %s.\n"), zonepath);
goto done;
}
goto done;
}
B_TRUE);
}
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) {
lockfd = -1;
}
}
/*
* Determine the brand when doing a dry-run attach. The zone does not have to
* exist, so we have to read the incoming manifest to determine the zone's
* brand.
*
* Because the manifest has to be processed twice; once to determine the brand
* and once to do the brand-specific attach logic, we always read it into a tmp
* file. This handles the manifest coming from stdin or a regular file. The
* tmpname parameter returns the name of the temporary file that the manifest
* was read into.
*/
static int
{
int fd;
int err;
int len;
int ofd;
char buf[512];
fd = STDIN_FILENO;
} else {
return (Z_ERR);
}
}
return (Z_ERR);
}
return (Z_ERR);
}
}
return (Z_ERR);
}
return (Z_ERR);
}
goto done;
}
goto done;
}
!= Z_OK) {
if (err == Z_INVALID_DOCUMENT) {
char buf[6];
"file"));
goto done;
}
goto done;
}
else
"release of the operating system"));
} else {
}
goto done;
}
/* Retrieve remote handle brand type. */
!= Z_OK) {
}
done:
}
/* ARGSUSED */
static int
{
int lockfd = -1;
char zonepath[MAXPATHLEN];
char cmdbuf[MAXPATHLEN];
char postcmdbuf[MAXPATHLEN];
char *manifest_path;
char tmpmanifest[80];
int manifest_pos;
int status;
int last_index = 0;
int offset;
char *up;
if (zonecfg_in_alt_root()) {
return (Z_ERR);
}
/* Check the argv string for args we handle internally */
optind = 0;
opterr = 0;
switch (arg) {
case '?':
if (optopt == '?') {
brand_help = B_TRUE;
}
/* Ignore unknown options - may be brand specific. */
break;
case 'F':
break;
case 'n':
break;
case 'U':
/*
* Undocumented 'force update' option for p2v update on
* attach when zone is in the incomplete state. Change
* the option back to 'u' and set forced_update flag.
*/
if (optind == last_index)
else
*up = 'u';
break;
default:
/* Ignore unknown options - may be brand specific. */
break;
}
last_index = optind;
}
if (brand_help) {
}
/* dry-run and force flags are mutually exclusive */
return (Z_ERR);
}
/*
* If the no-execute option was specified, we don't do validation and
* need to figure out the brand, since there is no zone required to be
* configured for this option.
*/
if (execute) {
if (!brand_help) {
return (Z_ERR);
return (Z_ERR);
}
gettext("could not get zone path"));
return (Z_ERR);
}
} else {
sizeof (tmpmanifest)) != Z_OK)
return (Z_ERR);
target_zone = "-";
/* Run the brand's verify_adm hook. */
return (Z_ERR);
}
/*
* Fetch the attach and postattach hooks from the brand configuration.
*/
return (Z_ERR);
}
zerror("invalid brand configuration: missing attach resource");
return (Z_ERR);
}
zerror("invalid brand configuration: missing postattach "
"resource");
return (Z_ERR);
}
/* Append all options to attach hook. */
return (Z_ERR);
/* Append all options to postattach hook. */
return (Z_ERR);
if (execute && !brand_help) {
"progress."), "zoneadm");
return (Z_ERR);
}
}
if (!force) {
/*
* Not a force-attach, so we need to actually do the work.
*/
if (cmdbuf[0] != '\0') {
/* Run the attach hook */
if (execute && !brand_help) {
lockfd);
lockfd = -1;
}
return (Z_ERR);
}
}
/*
* Else run the built-in attach support.
* This is a no-op since there is nothing to validate.
*/
/* If dry-run or help, then we're done. */
if (!execute || brand_help) {
if (!execute)
(void) unlink(tmpmanifest);
return (Z_OK);
}
}
/* Now we can validate that the zonepath exists. */
"because of the above errors.\n"), zonepath);
return (Z_ERR);
}
} else {
}
}
lockfd = -1;
/* If we have a brand postattach hook, run it. */
ZONE_STATE_CONFIGURED)) != Z_OK) {
B_TRUE);
}
}
}
}
/*
* 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);
}
}
/* ARGSUSED */
static int
{
char cmdbuf[MAXPATHLEN];
char precmdbuf[MAXPATHLEN];
int status;
if (zonecfg_in_alt_root()) {
return (Z_ERR);
}
/* Check the argv string for args we handle internally */
optind = 0;
opterr = 0;
switch (arg) {
case '?':
if (optopt == '?') {
brand_help = B_TRUE;
}
/* Ignore unknown options - may be brand specific. */
break;
case 'F':
break;
default:
/* Ignore unknown options - may be brand specific. */
break;
}
}
if (!brand_help) {
return (Z_ERR);
/*
* Invoke brand-specific handler.
*/
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);
}
/*
* Fetch the uninstall and preuninstall hooks from the brand
* configuration.
*/
return (Z_ERR);
}
zerror("invalid brand configuration: missing uninstall "
"resource");
return (Z_ERR);
}
zerror("invalid brand configuration: missing preuninstall "
"resource");
return (Z_ERR);
}
/* Append all options to preuninstall hook. */
return (Z_ERR);
/* Append all options to uninstall hook. */
return (Z_ERR);
if (!brand_help) {
"path"));
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 */
B_TRUE);
}
"progress."), "zoneadm");
return (Z_ERR);
}
/* Don't uninstall the zone if anything is mounted there */
if (err) {
"subdirectories of %s.\n"), rootpath);
return (Z_ERR);
}
}
/* If we have a brand preuninstall hook, run it. */
return (Z_ERR);
}
}
if (!brand_help) {
goto bad;
}
}
/*
* If there is a brand uninstall hook, use it, otherwise use the
* built-in uninstall code.
*/
if (cmdbuf[0] != '\0') {
/* Run the uninstall hook */
if (!brand_help)
return (Z_ERR);
}
if (brand_help)
return (Z_OK);
} else {
/* If just help, we're done since there is no brand help. */
if (brand_help)
return (Z_OK);
/* Run the built-in uninstall support. */
"failed"));
goto bad;
}
}
}
bad:
return (err);
}
/* ARGSUSED */
static int
{
int arg;
/*
* The only supported subargument to the "mount" subcommand is
* "-f", which forces us to mount a zone in the INCOMPLETE state.
*/
optind = 0;
switch (arg) {
case 'f':
break;
default:
return (Z_USAGE);
}
}
return (Z_USAGE);
!= Z_OK)
return (Z_ERR);
return (Z_ERR);
return (Z_ERR);
}
return (Z_OK);
}
/* ARGSUSED */
static int
{
if (argc > 0)
return (Z_USAGE);
!= Z_OK)
return (Z_ERR);
return (Z_ERR);
}
return (Z_OK);
}
static int
{
int arg;
int state;
optind = 0;
opterr = 0;
switch (arg) {
case 'F':
break;
default:
return (Z_USAGE);
}
}
return (Z_USAGE);
else
return (Z_USAGE);
return (Z_USAGE);
!= Z_OK)
return (Z_ERR);
/*
* Invoke brand-specific handler.
*/
return (Z_ERR);
"zoneadm");
return (Z_ERR);
}
}
return (err);
}
/*
* Check what scheduling class we're running under and print a warning if
* we're not using FSS.
*/
static int
{
char class_name[PC_CLNMSZ];
sizeof (class_name)) != Z_OK) {
"scheduling class"));
"FSS is not the default scheduling class for this zone. "
"FSS will be\nused for processes in the zone but to get "
"the full benefit of FSS,\nit should be the default "
"scheduling class. See dispadmin(1M) for\nmore details."));
return (Z_SYSTEM);
}
return (Z_OK);
}
static int
{
int err;
struct zone_rctltab rctl;
return (err);
}
break;
}
}
(void) zonecfg_endrctlent(handle);
return (res);
}
/*
* Check if there is a mix of processes running in different pools within the
* zone. This is currently only going to be called for the global zone from
* apply_func but that could be generalized in the future.
*/
static boolean_t
{
poolid_t last_poolid = 0;
return (B_FALSE);
}
int procfd;
char procpath[MAXPATHLEN];
continue;
continue;
/* skip processes in other zones and system processes */
continue;
}
if (poolid_set) {
} else {
poolid_set = B_TRUE;
}
}
if (mixed)
break;
}
return (mixed);
}
/*
* Check if a persistent or temporary pool is configured for the zone.
* This is currently only going to be called for the global zone from
* apply_func but that could be generalized in the future.
*/
static boolean_t
{
struct zone_psettab pset_tab;
char poolname[MAXPATHLEN];
if (err1 == Z_NO_ENTRY &&
return (B_FALSE);
return (B_TRUE);
}
/*
* This is an undocumented interface which is currently only used to apply
* the global zone resource management settings when the system boots.
* This function does not yet properly handle updating a running system so
* any projects running in the zone would be trashed if this function
* were to run after the zone had booted. It also does not reset any
* rctl settings that were removed from zonecfg. There is still work to be
* done before we can properly support dynamically updating the resource
* management settings for a running zone (global or non-global). Thus, this
* functionality is undocumented for now.
*/
/* ARGSUSED */
static int
{
int err;
struct zone_mcaptab mcap;
char pool_err[128];
return (Z_ERR);
}
return (Z_ERR);
}
return (Z_ERR);
}
return (Z_ERR);
}
return (Z_ERR);
}
/* specific error msgs are printed within apply_rctls */
}
if (pool_configured(handle)) {
if (mixed_pools(zoneid)) {
"pools. The pool\nconfiguration cannot be "
"applied without rebooting."));
} else {
/*
* The next two blocks of code attempt to set up
* temporary pools as well as persistent pools. In
* both cases we call the functions unconditionally.
* Within each funtion the code will check if the zone
* is actually configured for a temporary pool or
* persistent pool and just return if there is nothing
* to do.
*/
err == Z_POOL_BIND)
pool_err);
else
"temporary pool: %s"),
}
pool_err);
else
}
}
}
/*
* If a memory cap is configured, set the cap in the kernel using
* zone_setattr() and make sure the rcapd SMF service is enabled.
*/
char smf_err[128];
}
"%s"), smf_err);
}
}
return (res);
}
/*
* This is an undocumented interface that is invoked by the zones SMF service
* for installed zones that won't automatically boot.
*/
/* ARGSUSED */
static int
{
int err;
char cmdbuf[MAXPATHLEN];
char zonepath[MAXPATHLEN];
/*
* This subcommand can only be executed in the global zone on non-global
* zones.
*/
if (zonecfg_in_alt_root())
Z_OK)
return (Z_ERR);
/*
* Fetch the sysboot hook from the target zone's brand.
*/
return (Z_ERR);
}
return (Z_ERR);
}
return (Z_ERR);
}
return (Z_ERR);
}
return (Z_ERR);
}
/*
* If the hook wasn't defined (which is OK), then indicate success and
* return. Otherwise, execute the hook.
*/
if (cmdbuf[0] != '\0')
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;
char *zone_lock_env;
int err;
locale = "C";
(void) textdomain(TEXT_DOMAIN);
target_zone = NULL;
if (chdir("/") != 0) {
}
/*
* Use the default system mask rather than anything that may have been
* set by the caller.
*/
switch (arg) {
case '?':
case 'u':
break;
case 'z':
break;
if (*optarg != '/') {
}
gettext("root path must be a directory."));
}
break;
default:
}
}
static char newtarget[ZONENAME_MAX];
}
}
}
/*
* See if we have inherited the right to manipulate this zone from
* a zoneadm instance in our ancestry. If so, set zone_lock_cnt to
* indicate it. If not, make that explicit in our environment.
*/
/* Figure out what the system's default brand is */
sizeof (default_brand)) != Z_OK) {
return (Z_ERR);
}
/*
* If we are going to be operating on a single zone, retrieve its
* brand type and determine whether it is native or not.
*/
if ((target_zone != NULL) &&
sizeof (target_brand)) != Z_OK) {
}
/*
* In the alternate root environment, the only supported
* operations are mount and unmount. In this case, just treat
* the zone as native if it is cluster. Cluster zones can be
* native for the purpose of LU or upgrade, and the cluster
* brand may not exist in the miniroot (such as in net install
* upgrade).
*/
if (zonecfg_in_alt_root()) {
sizeof (target_brand));
}
}
}
return (err);
}