17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5fb03efaaSdp * Common Development and Distribution License (the "License"). 6fb03efaaSdp * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217e362f58Scomay 227c478bd9Sstevel@tonic-gate /* 23fb03efaaSdp * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * zonecfg is a lex/yacc based command interpreter used to manage zone 317c478bd9Sstevel@tonic-gate * configurations. The lexer (see zonecfg_lex.l) builds up tokens, which 327c478bd9Sstevel@tonic-gate * the grammar (see zonecfg_grammar.y) builds up into commands, some of 337c478bd9Sstevel@tonic-gate * which takes resources and/or properties as arguments. See the block 347c478bd9Sstevel@tonic-gate * comments near the end of zonecfg_grammar.y for how the data structures 357c478bd9Sstevel@tonic-gate * which keep track of these resources and properties are built up. 367c478bd9Sstevel@tonic-gate * 377c478bd9Sstevel@tonic-gate * The resource/property data structures are inserted into a command 387c478bd9Sstevel@tonic-gate * structure (see zonecfg.h), which also keeps track of command names, 397c478bd9Sstevel@tonic-gate * miscellaneous arguments, and function handlers. The grammar selects 407c478bd9Sstevel@tonic-gate * the appropriate function handler, each of which takes a pointer to a 417c478bd9Sstevel@tonic-gate * command structure as its sole argument, and invokes it. The grammar 427c478bd9Sstevel@tonic-gate * itself is "entered" (a la the Matrix) by yyparse(), which is called 437c478bd9Sstevel@tonic-gate * from read_input(), our main driving function. That in turn is called 447c478bd9Sstevel@tonic-gate * by one of do_interactive(), cmd_file() or one_command_at_a_time(), each 457c478bd9Sstevel@tonic-gate * of which is called from main() depending on how the program was invoked. 467c478bd9Sstevel@tonic-gate * 477c478bd9Sstevel@tonic-gate * The rest of this module consists of the various function handlers and 487c478bd9Sstevel@tonic-gate * their helper functions. Some of these functions, particularly the 497c478bd9Sstevel@tonic-gate * X_to_str() functions, which maps command, resource and property numbers 507c478bd9Sstevel@tonic-gate * to strings, are used quite liberally, as doing so results in a better 517c478bd9Sstevel@tonic-gate * program w/rt I18N, reducing the need for translation notes. 527c478bd9Sstevel@tonic-gate */ 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate #include <sys/mntent.h> 557c478bd9Sstevel@tonic-gate #include <sys/varargs.h> 567c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate #include <errno.h> 597c478bd9Sstevel@tonic-gate #include <strings.h> 607c478bd9Sstevel@tonic-gate #include <unistd.h> 617c478bd9Sstevel@tonic-gate #include <ctype.h> 627c478bd9Sstevel@tonic-gate #include <stdlib.h> 637c478bd9Sstevel@tonic-gate #include <assert.h> 647c478bd9Sstevel@tonic-gate #include <sys/stat.h> 657c478bd9Sstevel@tonic-gate #include <zone.h> 667c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 677c478bd9Sstevel@tonic-gate #include <netdb.h> 687c478bd9Sstevel@tonic-gate #include <locale.h> 697c478bd9Sstevel@tonic-gate #include <libintl.h> 707c478bd9Sstevel@tonic-gate #include <alloca.h> 717c478bd9Sstevel@tonic-gate #include <regex.h> 727c478bd9Sstevel@tonic-gate #include <signal.h> 737c478bd9Sstevel@tonic-gate #include <libtecla.h> 74fa9e4066Sahrens #include <libzfs.h> 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate #include <libzonecfg.h> 777c478bd9Sstevel@tonic-gate #include "zonecfg.h" 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) /* should be defined by cc -D */ 807c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */ 817c478bd9Sstevel@tonic-gate #endif 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate #define PAGER "/usr/bin/more" 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate struct help { 867c478bd9Sstevel@tonic-gate uint_t cmd_num; 877c478bd9Sstevel@tonic-gate char *cmd_name; 887c478bd9Sstevel@tonic-gate uint_t flags; 897c478bd9Sstevel@tonic-gate char *short_usage; 907c478bd9Sstevel@tonic-gate }; 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate extern int yyparse(void); 937c478bd9Sstevel@tonic-gate extern int lex_lineno; 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate #define MAX_LINE_LEN 1024 967c478bd9Sstevel@tonic-gate #define MAX_CMD_HIST 1024 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate /* 997c478bd9Sstevel@tonic-gate * Each SHELP_ should be a simple string. 1007c478bd9Sstevel@tonic-gate */ 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate #define SHELP_ADD "add <resource-type>\n\t(global scope)\n" \ 1037c478bd9Sstevel@tonic-gate "add <property-name> <property-value>\n\t(resource scope)" 1047c478bd9Sstevel@tonic-gate #define SHELP_CANCEL "cancel" 1057c478bd9Sstevel@tonic-gate #define SHELP_COMMIT "commit" 106ee519a1fSgjelinek #define SHELP_CREATE "create [-F] [ -a <path> | -b | -t <template> ]" 1077c478bd9Sstevel@tonic-gate #define SHELP_DELETE "delete [-F]" 1087c478bd9Sstevel@tonic-gate #define SHELP_END "end" 1097c478bd9Sstevel@tonic-gate #define SHELP_EXIT "exit [-F]" 1107c478bd9Sstevel@tonic-gate #define SHELP_EXPORT "export [-f output-file]" 1117c478bd9Sstevel@tonic-gate #define SHELP_HELP "help [commands] [syntax] [usage] [<command-name>]" 1127c478bd9Sstevel@tonic-gate #define SHELP_INFO "info [<resource-type> [property-name=property-value]*]" 1137c478bd9Sstevel@tonic-gate #define SHELP_REMOVE "remove <resource-type> { <property-name>=<property-" \ 114*ffbafc53Scomay "value> }\n\t(global scope)\nremove <property-name> <property-value>" \ 1157c478bd9Sstevel@tonic-gate "\n\t(resource scope)" 1167c478bd9Sstevel@tonic-gate #define SHELP_REVERT "revert [-F]" 1177c478bd9Sstevel@tonic-gate #define SHELP_SELECT "select <resource-type> { <property-name>=" \ 1187c478bd9Sstevel@tonic-gate "<property-value> }" 1197c478bd9Sstevel@tonic-gate #define SHELP_SET "set <property-name>=<property-value>" 1207c478bd9Sstevel@tonic-gate #define SHELP_VERIFY "verify" 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate static struct help helptab[] = { 1237c478bd9Sstevel@tonic-gate { CMD_ADD, "add", HELP_RES_PROPS, SHELP_ADD, }, 1247c478bd9Sstevel@tonic-gate { CMD_CANCEL, "cancel", 0, SHELP_CANCEL, }, 1257c478bd9Sstevel@tonic-gate { CMD_COMMIT, "commit", 0, SHELP_COMMIT, }, 1267c478bd9Sstevel@tonic-gate { CMD_CREATE, "create", 0, SHELP_CREATE, }, 1277c478bd9Sstevel@tonic-gate { CMD_DELETE, "delete", 0, SHELP_DELETE, }, 1287c478bd9Sstevel@tonic-gate { CMD_END, "end", 0, SHELP_END, }, 1297c478bd9Sstevel@tonic-gate { CMD_EXIT, "exit", 0, SHELP_EXIT, }, 1307c478bd9Sstevel@tonic-gate { CMD_EXPORT, "export", 0, SHELP_EXPORT, }, 1317c478bd9Sstevel@tonic-gate { CMD_HELP, "help", 0, SHELP_HELP }, 1327c478bd9Sstevel@tonic-gate { CMD_INFO, "info", HELP_RES_PROPS, SHELP_INFO, }, 1337c478bd9Sstevel@tonic-gate { CMD_REMOVE, "remove", HELP_RES_PROPS, SHELP_REMOVE, }, 1347c478bd9Sstevel@tonic-gate { CMD_REVERT, "revert", 0, SHELP_REVERT, }, 1357c478bd9Sstevel@tonic-gate { CMD_SELECT, "select", HELP_RES_PROPS, SHELP_SELECT, }, 1367c478bd9Sstevel@tonic-gate { CMD_SET, "set", HELP_PROPS, SHELP_SET, }, 1377c478bd9Sstevel@tonic-gate { CMD_VERIFY, "verify", 0, SHELP_VERIFY, }, 1387c478bd9Sstevel@tonic-gate { 0 }, 1397c478bd9Sstevel@tonic-gate }; 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate #define MAX_RT_STRLEN 16 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate /* These *must* match the order of the RT_ define's from zonecfg.h */ 1447c478bd9Sstevel@tonic-gate static char *res_types[] = { 1457c478bd9Sstevel@tonic-gate "unknown", 146087719fdSdp "zonename", 1477c478bd9Sstevel@tonic-gate "zonepath", 1487c478bd9Sstevel@tonic-gate "autoboot", 1497c478bd9Sstevel@tonic-gate "pool", 1507c478bd9Sstevel@tonic-gate "fs", 1517c478bd9Sstevel@tonic-gate "inherit-pkg-dir", 1527c478bd9Sstevel@tonic-gate "net", 1537c478bd9Sstevel@tonic-gate "device", 1547c478bd9Sstevel@tonic-gate "rctl", 1557c478bd9Sstevel@tonic-gate "attr", 156fa9e4066Sahrens "dataset", 157*ffbafc53Scomay "limitpriv", 1587c478bd9Sstevel@tonic-gate NULL 1597c478bd9Sstevel@tonic-gate }; 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate /* These *must* match the order of the PT_ define's from zonecfg.h */ 1627c478bd9Sstevel@tonic-gate static char *prop_types[] = { 1637c478bd9Sstevel@tonic-gate "unknown", 164087719fdSdp "zonename", 1657c478bd9Sstevel@tonic-gate "zonepath", 1667c478bd9Sstevel@tonic-gate "autoboot", 1677c478bd9Sstevel@tonic-gate "pool", 1687c478bd9Sstevel@tonic-gate "dir", 1697c478bd9Sstevel@tonic-gate "special", 1707c478bd9Sstevel@tonic-gate "type", 1717c478bd9Sstevel@tonic-gate "options", 1727c478bd9Sstevel@tonic-gate "address", 1737c478bd9Sstevel@tonic-gate "physical", 1747c478bd9Sstevel@tonic-gate "name", 1757c478bd9Sstevel@tonic-gate "value", 1767c478bd9Sstevel@tonic-gate "match", 1777c478bd9Sstevel@tonic-gate "priv", 1787c478bd9Sstevel@tonic-gate "limit", 1797c478bd9Sstevel@tonic-gate "action", 1807c478bd9Sstevel@tonic-gate "raw", 181*ffbafc53Scomay "limitpriv", 1827c478bd9Sstevel@tonic-gate NULL 1837c478bd9Sstevel@tonic-gate }; 1847c478bd9Sstevel@tonic-gate 185*ffbafc53Scomay /* These *must* match the order of the PROP_VAL_ define's from zonecfg.h */ 1867c478bd9Sstevel@tonic-gate static char *prop_val_types[] = { 1877c478bd9Sstevel@tonic-gate "simple", 1887c478bd9Sstevel@tonic-gate "complex", 1897c478bd9Sstevel@tonic-gate "list", 1907c478bd9Sstevel@tonic-gate }; 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate /* 1937c478bd9Sstevel@tonic-gate * The various _cmds[] lists below are for command tab-completion. 1947c478bd9Sstevel@tonic-gate */ 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate /* 1977c478bd9Sstevel@tonic-gate * remove has a space afterwards because it has qualifiers; the other commands 1987c478bd9Sstevel@tonic-gate * that have qualifiers (add, select and set) don't need a space here because 1997c478bd9Sstevel@tonic-gate * they have their own _cmds[] lists below. 2007c478bd9Sstevel@tonic-gate */ 2017c478bd9Sstevel@tonic-gate static const char *global_scope_cmds[] = { 2027c478bd9Sstevel@tonic-gate "add", 2037c478bd9Sstevel@tonic-gate "commit", 2047c478bd9Sstevel@tonic-gate "create", 2057c478bd9Sstevel@tonic-gate "delete", 2067c478bd9Sstevel@tonic-gate "exit", 2077c478bd9Sstevel@tonic-gate "export", 2087c478bd9Sstevel@tonic-gate "help", 2097c478bd9Sstevel@tonic-gate "info", 2107c478bd9Sstevel@tonic-gate "remove ", 2117c478bd9Sstevel@tonic-gate "revert", 2127c478bd9Sstevel@tonic-gate "select", 2137c478bd9Sstevel@tonic-gate "set", 2147c478bd9Sstevel@tonic-gate "verify", 2157c478bd9Sstevel@tonic-gate NULL 2167c478bd9Sstevel@tonic-gate }; 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate static const char *add_cmds[] = { 2197c478bd9Sstevel@tonic-gate "add fs", 2207c478bd9Sstevel@tonic-gate "add inherit-pkg-dir", 2217c478bd9Sstevel@tonic-gate "add net", 2227c478bd9Sstevel@tonic-gate "add device", 2237c478bd9Sstevel@tonic-gate "add rctl", 2247c478bd9Sstevel@tonic-gate "add attr", 225fa9e4066Sahrens "add dataset", 2267c478bd9Sstevel@tonic-gate NULL 2277c478bd9Sstevel@tonic-gate }; 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate static const char *select_cmds[] = { 2307c478bd9Sstevel@tonic-gate "select fs ", 2317c478bd9Sstevel@tonic-gate "select inherit-pkg-dir ", 2327c478bd9Sstevel@tonic-gate "select net ", 2337c478bd9Sstevel@tonic-gate "select device ", 2347c478bd9Sstevel@tonic-gate "select rctl ", 2357c478bd9Sstevel@tonic-gate "select attr ", 236fa9e4066Sahrens "select dataset ", 2377c478bd9Sstevel@tonic-gate NULL 2387c478bd9Sstevel@tonic-gate }; 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate static const char *set_cmds[] = { 241087719fdSdp "set zonename=", 242087719fdSdp "set zonepath=", 243087719fdSdp "set autoboot=", 244087719fdSdp "set pool=", 245*ffbafc53Scomay "set limitpriv=", 2467c478bd9Sstevel@tonic-gate NULL 2477c478bd9Sstevel@tonic-gate }; 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate static const char *fs_res_scope_cmds[] = { 2507c478bd9Sstevel@tonic-gate "add options ", 2517c478bd9Sstevel@tonic-gate "cancel", 2527c478bd9Sstevel@tonic-gate "end", 2537c478bd9Sstevel@tonic-gate "exit", 2547c478bd9Sstevel@tonic-gate "help", 2557c478bd9Sstevel@tonic-gate "info", 256*ffbafc53Scomay "remove options ", 2577c478bd9Sstevel@tonic-gate "set dir=", 2587c478bd9Sstevel@tonic-gate "set raw=", 2597c478bd9Sstevel@tonic-gate "set special=", 2607c478bd9Sstevel@tonic-gate "set type=", 2617c478bd9Sstevel@tonic-gate NULL 2627c478bd9Sstevel@tonic-gate }; 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate static const char *net_res_scope_cmds[] = { 2657c478bd9Sstevel@tonic-gate "cancel", 2667c478bd9Sstevel@tonic-gate "end", 2677c478bd9Sstevel@tonic-gate "exit", 2687c478bd9Sstevel@tonic-gate "help", 2697c478bd9Sstevel@tonic-gate "info", 2707c478bd9Sstevel@tonic-gate "set address=", 2717c478bd9Sstevel@tonic-gate "set physical=", 2727c478bd9Sstevel@tonic-gate NULL 2737c478bd9Sstevel@tonic-gate }; 2747c478bd9Sstevel@tonic-gate 2757c478bd9Sstevel@tonic-gate static const char *ipd_res_scope_cmds[] = { 2767c478bd9Sstevel@tonic-gate "cancel", 2777c478bd9Sstevel@tonic-gate "end", 2787c478bd9Sstevel@tonic-gate "exit", 2797c478bd9Sstevel@tonic-gate "help", 2807c478bd9Sstevel@tonic-gate "info", 2817c478bd9Sstevel@tonic-gate "set dir=", 2827c478bd9Sstevel@tonic-gate NULL 2837c478bd9Sstevel@tonic-gate }; 2847c478bd9Sstevel@tonic-gate 2857c478bd9Sstevel@tonic-gate static const char *device_res_scope_cmds[] = { 2867c478bd9Sstevel@tonic-gate "cancel", 2877c478bd9Sstevel@tonic-gate "end", 2887c478bd9Sstevel@tonic-gate "exit", 2897c478bd9Sstevel@tonic-gate "help", 2907c478bd9Sstevel@tonic-gate "info", 2917c478bd9Sstevel@tonic-gate "set match=", 2927c478bd9Sstevel@tonic-gate NULL 2937c478bd9Sstevel@tonic-gate }; 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate static const char *attr_res_scope_cmds[] = { 2967c478bd9Sstevel@tonic-gate "cancel", 2977c478bd9Sstevel@tonic-gate "end", 2987c478bd9Sstevel@tonic-gate "exit", 2997c478bd9Sstevel@tonic-gate "help", 3007c478bd9Sstevel@tonic-gate "info", 3017c478bd9Sstevel@tonic-gate "set name=", 3027c478bd9Sstevel@tonic-gate "set type=", 3037c478bd9Sstevel@tonic-gate "set value=", 3047c478bd9Sstevel@tonic-gate NULL 3057c478bd9Sstevel@tonic-gate }; 3067c478bd9Sstevel@tonic-gate 3077c478bd9Sstevel@tonic-gate static const char *rctl_res_scope_cmds[] = { 3087c478bd9Sstevel@tonic-gate "add value ", 3097c478bd9Sstevel@tonic-gate "cancel", 3107c478bd9Sstevel@tonic-gate "end", 3117c478bd9Sstevel@tonic-gate "exit", 3127c478bd9Sstevel@tonic-gate "help", 3137c478bd9Sstevel@tonic-gate "info", 314*ffbafc53Scomay "remove value ", 3157c478bd9Sstevel@tonic-gate "set name=", 3167c478bd9Sstevel@tonic-gate NULL 3177c478bd9Sstevel@tonic-gate }; 3187c478bd9Sstevel@tonic-gate 319fa9e4066Sahrens static const char *dataset_res_scope_cmds[] = { 320fa9e4066Sahrens "cancel", 321fa9e4066Sahrens "end", 322fa9e4066Sahrens "exit", 323fa9e4066Sahrens "help", 324fa9e4066Sahrens "info", 325fa9e4066Sahrens "set name=", 326fa9e4066Sahrens NULL 327fa9e4066Sahrens }; 328fa9e4066Sahrens 3297c478bd9Sstevel@tonic-gate /* Global variables */ 3307c478bd9Sstevel@tonic-gate 3317c478bd9Sstevel@tonic-gate /* set early in main(), never modified thereafter, used all over the place */ 3327c478bd9Sstevel@tonic-gate static char *execname; 3337c478bd9Sstevel@tonic-gate 3347c478bd9Sstevel@tonic-gate /* set in main(), used all over the place */ 3357c478bd9Sstevel@tonic-gate static zone_dochandle_t handle; 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate /* used all over the place */ 338087719fdSdp static char zone[ZONENAME_MAX]; 339087719fdSdp static char revert_zone[ZONENAME_MAX]; 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gate /* set in modifying functions, checked in read_input() */ 3427c478bd9Sstevel@tonic-gate static bool need_to_commit = FALSE; 3437c478bd9Sstevel@tonic-gate bool saw_error; 3447c478bd9Sstevel@tonic-gate 3457c478bd9Sstevel@tonic-gate /* set in yacc parser, checked in read_input() */ 3467c478bd9Sstevel@tonic-gate bool newline_terminated; 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate /* set in main(), checked in lex error handler */ 3497c478bd9Sstevel@tonic-gate bool cmd_file_mode; 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate /* set in exit_func(), checked in read_input() */ 3527c478bd9Sstevel@tonic-gate static bool time_to_exit = FALSE, force_exit = FALSE; 3537c478bd9Sstevel@tonic-gate 3547c478bd9Sstevel@tonic-gate /* used in short_usage() and zerr() */ 3557c478bd9Sstevel@tonic-gate static char *cmd_file_name = NULL; 3567c478bd9Sstevel@tonic-gate 3577c478bd9Sstevel@tonic-gate /* checked in read_input() and other places */ 3587c478bd9Sstevel@tonic-gate static bool ok_to_prompt = FALSE; 3597c478bd9Sstevel@tonic-gate 3607c478bd9Sstevel@tonic-gate /* set and checked in initialize() */ 3617c478bd9Sstevel@tonic-gate static bool got_handle = FALSE; 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate /* initialized in do_interactive(), checked in initialize() */ 3647c478bd9Sstevel@tonic-gate static bool interactive_mode; 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate /* set in main(), checked in multiple places */ 3677c478bd9Sstevel@tonic-gate static bool read_only_mode; 3687c478bd9Sstevel@tonic-gate 3697c478bd9Sstevel@tonic-gate static bool global_scope = TRUE; /* scope is outer/global or inner/resource */ 3707c478bd9Sstevel@tonic-gate static int resource_scope; /* should be in the RT_ list from zonecfg.h */ 3717c478bd9Sstevel@tonic-gate static int end_op = -1; /* operation on end is either add or modify */ 3727c478bd9Sstevel@tonic-gate 3737c478bd9Sstevel@tonic-gate int num_prop_vals; /* for grammar */ 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gate /* 3767c478bd9Sstevel@tonic-gate * These are for keeping track of resources as they are specified as part of 3777c478bd9Sstevel@tonic-gate * the multi-step process. They should be initialized by add_resource() or 3787c478bd9Sstevel@tonic-gate * select_func() and filled in by add_property() or set_func(). 3797c478bd9Sstevel@tonic-gate */ 3807c478bd9Sstevel@tonic-gate static struct zone_fstab old_fstab, in_progress_fstab; 3817c478bd9Sstevel@tonic-gate static struct zone_fstab old_ipdtab, in_progress_ipdtab; 3827c478bd9Sstevel@tonic-gate static struct zone_nwiftab old_nwiftab, in_progress_nwiftab; 3837c478bd9Sstevel@tonic-gate static struct zone_devtab old_devtab, in_progress_devtab; 3847c478bd9Sstevel@tonic-gate static struct zone_rctltab old_rctltab, in_progress_rctltab; 3857c478bd9Sstevel@tonic-gate static struct zone_attrtab old_attrtab, in_progress_attrtab; 386fa9e4066Sahrens static struct zone_dstab old_dstab, in_progress_dstab; 3877c478bd9Sstevel@tonic-gate 3887c478bd9Sstevel@tonic-gate static GetLine *gl; /* The gl_get_line() resource object */ 3897c478bd9Sstevel@tonic-gate 3907c478bd9Sstevel@tonic-gate /* Functions begin here */ 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate static bool 3937c478bd9Sstevel@tonic-gate initial_match(const char *line1, const char *line2, int word_end) 3947c478bd9Sstevel@tonic-gate { 3957c478bd9Sstevel@tonic-gate if (word_end <= 0) 3967c478bd9Sstevel@tonic-gate return (TRUE); 3977c478bd9Sstevel@tonic-gate return (strncmp(line1, line2, word_end) == 0); 3987c478bd9Sstevel@tonic-gate } 3997c478bd9Sstevel@tonic-gate 4007c478bd9Sstevel@tonic-gate static int 4017c478bd9Sstevel@tonic-gate add_stuff(WordCompletion *cpl, const char *line1, const char **list, 4027c478bd9Sstevel@tonic-gate int word_end) 4037c478bd9Sstevel@tonic-gate { 4047c478bd9Sstevel@tonic-gate int i, err; 4057c478bd9Sstevel@tonic-gate 4067c478bd9Sstevel@tonic-gate for (i = 0; list[i] != NULL; i++) { 4077c478bd9Sstevel@tonic-gate if (initial_match(line1, list[i], word_end)) { 4087c478bd9Sstevel@tonic-gate err = cpl_add_completion(cpl, line1, 0, word_end, 4097c478bd9Sstevel@tonic-gate list[i] + word_end, "", ""); 4107c478bd9Sstevel@tonic-gate if (err != 0) 4117c478bd9Sstevel@tonic-gate return (err); 4127c478bd9Sstevel@tonic-gate } 4137c478bd9Sstevel@tonic-gate } 4147c478bd9Sstevel@tonic-gate return (0); 4157c478bd9Sstevel@tonic-gate } 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate static 4187c478bd9Sstevel@tonic-gate /* ARGSUSED */ 4197c478bd9Sstevel@tonic-gate CPL_MATCH_FN(cmd_cpl_fn) 4207c478bd9Sstevel@tonic-gate { 4217c478bd9Sstevel@tonic-gate if (global_scope) { 4227c478bd9Sstevel@tonic-gate /* 4237c478bd9Sstevel@tonic-gate * The MAX/MIN tests below are to make sure we have at least 4247c478bd9Sstevel@tonic-gate * enough characters to distinguish from other prefixes (MAX) 4257c478bd9Sstevel@tonic-gate * but only check MIN(what we have, what we're checking). 4267c478bd9Sstevel@tonic-gate */ 4277c478bd9Sstevel@tonic-gate if (strncmp(line, "add ", MAX(MIN(word_end, 4), 1)) == 0) 4287c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, add_cmds, word_end)); 4297c478bd9Sstevel@tonic-gate if (strncmp(line, "select ", MAX(MIN(word_end, 7), 3)) == 0) 4307c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, select_cmds, word_end)); 4317c478bd9Sstevel@tonic-gate if (strncmp(line, "set ", MAX(MIN(word_end, 4), 3)) == 0) 4327c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, set_cmds, word_end)); 4337c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, global_scope_cmds, word_end)); 4347c478bd9Sstevel@tonic-gate } 4357c478bd9Sstevel@tonic-gate switch (resource_scope) { 4367c478bd9Sstevel@tonic-gate case RT_FS: 4377c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, fs_res_scope_cmds, word_end)); 4387c478bd9Sstevel@tonic-gate case RT_IPD: 4397c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, ipd_res_scope_cmds, word_end)); 4407c478bd9Sstevel@tonic-gate case RT_NET: 4417c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, net_res_scope_cmds, word_end)); 4427c478bd9Sstevel@tonic-gate case RT_DEVICE: 4437c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, device_res_scope_cmds, word_end)); 4447c478bd9Sstevel@tonic-gate case RT_RCTL: 4457c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, rctl_res_scope_cmds, word_end)); 4467c478bd9Sstevel@tonic-gate case RT_ATTR: 4477c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, attr_res_scope_cmds, word_end)); 448fa9e4066Sahrens case RT_DATASET: 449fa9e4066Sahrens return (add_stuff(cpl, line, dataset_res_scope_cmds, word_end)); 4507c478bd9Sstevel@tonic-gate } 4517c478bd9Sstevel@tonic-gate return (0); 4527c478bd9Sstevel@tonic-gate } 4537c478bd9Sstevel@tonic-gate 4547c478bd9Sstevel@tonic-gate /* 4557c478bd9Sstevel@tonic-gate * For the main CMD_func() functions below, several of them call getopt() 4567c478bd9Sstevel@tonic-gate * then check optind against argc to make sure an extra parameter was not 4577c478bd9Sstevel@tonic-gate * passed in. The reason this is not caught in the grammar is that the 4587c478bd9Sstevel@tonic-gate * grammar just checks for a miscellaneous TOKEN, which is *expected* to 4597c478bd9Sstevel@tonic-gate * be "-F" (for example), but could be anything. So (for example) this 4607c478bd9Sstevel@tonic-gate * check will prevent "create bogus". 4617c478bd9Sstevel@tonic-gate */ 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate cmd_t * 4647c478bd9Sstevel@tonic-gate alloc_cmd(void) 4657c478bd9Sstevel@tonic-gate { 4667c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (cmd_t))); 4677c478bd9Sstevel@tonic-gate } 4687c478bd9Sstevel@tonic-gate 4697c478bd9Sstevel@tonic-gate void 4707c478bd9Sstevel@tonic-gate free_cmd(cmd_t *cmd) 4717c478bd9Sstevel@tonic-gate { 4727c478bd9Sstevel@tonic-gate int i; 4737c478bd9Sstevel@tonic-gate 4747c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_EQ_PROP_PAIRS; i++) 4757c478bd9Sstevel@tonic-gate if (cmd->cmd_property_ptr[i] != NULL) { 4767c478bd9Sstevel@tonic-gate property_value_ptr_t pp = cmd->cmd_property_ptr[i]; 4777c478bd9Sstevel@tonic-gate 4787c478bd9Sstevel@tonic-gate switch (pp->pv_type) { 4797c478bd9Sstevel@tonic-gate case PROP_VAL_SIMPLE: 4807c478bd9Sstevel@tonic-gate free(pp->pv_simple); 4817c478bd9Sstevel@tonic-gate break; 4827c478bd9Sstevel@tonic-gate case PROP_VAL_COMPLEX: 4837c478bd9Sstevel@tonic-gate free_complex(pp->pv_complex); 4847c478bd9Sstevel@tonic-gate break; 4857c478bd9Sstevel@tonic-gate case PROP_VAL_LIST: 4867c478bd9Sstevel@tonic-gate free_list(pp->pv_list); 4877c478bd9Sstevel@tonic-gate break; 4887c478bd9Sstevel@tonic-gate } 4897c478bd9Sstevel@tonic-gate } 4907c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_argc; i++) 4917c478bd9Sstevel@tonic-gate free(cmd->cmd_argv[i]); 4927c478bd9Sstevel@tonic-gate free(cmd); 4937c478bd9Sstevel@tonic-gate } 4947c478bd9Sstevel@tonic-gate 4957c478bd9Sstevel@tonic-gate complex_property_ptr_t 4967c478bd9Sstevel@tonic-gate alloc_complex(void) 4977c478bd9Sstevel@tonic-gate { 4987c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (complex_property_t))); 4997c478bd9Sstevel@tonic-gate } 5007c478bd9Sstevel@tonic-gate 5017c478bd9Sstevel@tonic-gate void 5027c478bd9Sstevel@tonic-gate free_complex(complex_property_ptr_t complex) 5037c478bd9Sstevel@tonic-gate { 5047c478bd9Sstevel@tonic-gate if (complex == NULL) 5057c478bd9Sstevel@tonic-gate return; 5067c478bd9Sstevel@tonic-gate free_complex(complex->cp_next); 5077c478bd9Sstevel@tonic-gate if (complex->cp_value != NULL) 5087c478bd9Sstevel@tonic-gate free(complex->cp_value); 5097c478bd9Sstevel@tonic-gate free(complex); 5107c478bd9Sstevel@tonic-gate } 5117c478bd9Sstevel@tonic-gate 5127c478bd9Sstevel@tonic-gate list_property_ptr_t 5137c478bd9Sstevel@tonic-gate alloc_list(void) 5147c478bd9Sstevel@tonic-gate { 5157c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (list_property_t))); 5167c478bd9Sstevel@tonic-gate } 5177c478bd9Sstevel@tonic-gate 5187c478bd9Sstevel@tonic-gate void 5197c478bd9Sstevel@tonic-gate free_list(list_property_ptr_t list) 5207c478bd9Sstevel@tonic-gate { 5217c478bd9Sstevel@tonic-gate if (list == NULL) 5227c478bd9Sstevel@tonic-gate return; 5237c478bd9Sstevel@tonic-gate if (list->lp_simple != NULL) 5247c478bd9Sstevel@tonic-gate free(list->lp_simple); 5257c478bd9Sstevel@tonic-gate free_complex(list->lp_complex); 5267c478bd9Sstevel@tonic-gate free_list(list->lp_next); 5277c478bd9Sstevel@tonic-gate free(list); 5287c478bd9Sstevel@tonic-gate } 5297c478bd9Sstevel@tonic-gate 5307c478bd9Sstevel@tonic-gate void 5317c478bd9Sstevel@tonic-gate free_outer_list(list_property_ptr_t list) 5327c478bd9Sstevel@tonic-gate { 5337c478bd9Sstevel@tonic-gate if (list == NULL) 5347c478bd9Sstevel@tonic-gate return; 5357c478bd9Sstevel@tonic-gate free_outer_list(list->lp_next); 5367c478bd9Sstevel@tonic-gate free(list); 5377c478bd9Sstevel@tonic-gate } 5387c478bd9Sstevel@tonic-gate 5397c478bd9Sstevel@tonic-gate static struct zone_rctlvaltab * 5407c478bd9Sstevel@tonic-gate alloc_rctlvaltab(void) 5417c478bd9Sstevel@tonic-gate { 5427c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (struct zone_rctlvaltab))); 5437c478bd9Sstevel@tonic-gate } 5447c478bd9Sstevel@tonic-gate 5457c478bd9Sstevel@tonic-gate static char * 5467c478bd9Sstevel@tonic-gate rt_to_str(int res_type) 5477c478bd9Sstevel@tonic-gate { 5487c478bd9Sstevel@tonic-gate assert(res_type >= RT_MIN && res_type <= RT_MAX); 5497c478bd9Sstevel@tonic-gate return (res_types[res_type]); 5507c478bd9Sstevel@tonic-gate } 5517c478bd9Sstevel@tonic-gate 5527c478bd9Sstevel@tonic-gate static char * 5537c478bd9Sstevel@tonic-gate pt_to_str(int prop_type) 5547c478bd9Sstevel@tonic-gate { 5557c478bd9Sstevel@tonic-gate assert(prop_type >= PT_MIN && prop_type <= PT_MAX); 5567c478bd9Sstevel@tonic-gate return (prop_types[prop_type]); 5577c478bd9Sstevel@tonic-gate } 5587c478bd9Sstevel@tonic-gate 5597c478bd9Sstevel@tonic-gate static char * 5607c478bd9Sstevel@tonic-gate pvt_to_str(int pv_type) 5617c478bd9Sstevel@tonic-gate { 5627c478bd9Sstevel@tonic-gate assert(pv_type >= PROP_VAL_MIN && pv_type <= PROP_VAL_MAX); 5637c478bd9Sstevel@tonic-gate return (prop_val_types[pv_type]); 5647c478bd9Sstevel@tonic-gate } 5657c478bd9Sstevel@tonic-gate 5667c478bd9Sstevel@tonic-gate static char * 5677c478bd9Sstevel@tonic-gate cmd_to_str(int cmd_num) 5687c478bd9Sstevel@tonic-gate { 5697c478bd9Sstevel@tonic-gate assert(cmd_num >= CMD_MIN && cmd_num <= CMD_MAX); 5707c478bd9Sstevel@tonic-gate return (helptab[cmd_num].cmd_name); 5717c478bd9Sstevel@tonic-gate } 5727c478bd9Sstevel@tonic-gate 5737c478bd9Sstevel@tonic-gate /* 5747c478bd9Sstevel@tonic-gate * This is a separate function rather than a set of define's because of the 5757c478bd9Sstevel@tonic-gate * gettext() wrapping. 5767c478bd9Sstevel@tonic-gate */ 5777c478bd9Sstevel@tonic-gate 5787c478bd9Sstevel@tonic-gate /* 5797c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE 5807c478bd9Sstevel@tonic-gate * Each string below should have \t follow \n whenever needed; the 5817c478bd9Sstevel@tonic-gate * initial \t and the terminal \n will be provided by the calling function. 5827c478bd9Sstevel@tonic-gate */ 5837c478bd9Sstevel@tonic-gate 5847c478bd9Sstevel@tonic-gate static char * 5857c478bd9Sstevel@tonic-gate long_help(int cmd_num) 5867c478bd9Sstevel@tonic-gate { 5877c478bd9Sstevel@tonic-gate static char line[1024]; /* arbitrary large amount */ 5887c478bd9Sstevel@tonic-gate 5897c478bd9Sstevel@tonic-gate assert(cmd_num >= CMD_MIN && cmd_num <= CMD_MAX); 5907c478bd9Sstevel@tonic-gate switch (cmd_num) { 5917c478bd9Sstevel@tonic-gate case CMD_HELP: 5927c478bd9Sstevel@tonic-gate return (gettext("Prints help message.")); 5937c478bd9Sstevel@tonic-gate case CMD_CREATE: 5947c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 5957c478bd9Sstevel@tonic-gate gettext("Creates a configuration for the " 5967c478bd9Sstevel@tonic-gate "specified zone. %s should be\n\tused to " 5977c478bd9Sstevel@tonic-gate "begin configuring a new zone. If overwriting an " 5987c478bd9Sstevel@tonic-gate "existing\n\tconfiguration, the -F flag can be " 5997c478bd9Sstevel@tonic-gate "used to force the action. If\n\t-t template is " 6007c478bd9Sstevel@tonic-gate "given, creates a configuration identical to the\n" 6017c478bd9Sstevel@tonic-gate "\tspecified template, except that the zone name " 6029e518655Sgjelinek "is changed from\n\ttemplate to zonename. '%s -a' " 6039e518655Sgjelinek "creates a configuration from a\n\tdetached " 6049e518655Sgjelinek "zonepath. '%s -b' results in a blank " 6059e518655Sgjelinek "configuration.\n\t'%s' with no arguments applies " 6069e518655Sgjelinek "the Sun default settings."), 6077c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE), cmd_to_str(CMD_CREATE), 6089e518655Sgjelinek cmd_to_str(CMD_CREATE), cmd_to_str(CMD_CREATE)); 6097c478bd9Sstevel@tonic-gate return (line); 6107c478bd9Sstevel@tonic-gate case CMD_EXIT: 6117c478bd9Sstevel@tonic-gate return (gettext("Exits the program. The -F flag can " 6127c478bd9Sstevel@tonic-gate "be used to force the action.")); 6137c478bd9Sstevel@tonic-gate case CMD_EXPORT: 6147c478bd9Sstevel@tonic-gate return (gettext("Prints configuration to standard " 6157c478bd9Sstevel@tonic-gate "output, or to output-file if\n\tspecified, in " 6167c478bd9Sstevel@tonic-gate "a form suitable for use in a command-file.")); 6177c478bd9Sstevel@tonic-gate case CMD_ADD: 6187c478bd9Sstevel@tonic-gate return (gettext("Add specified resource to " 6197c478bd9Sstevel@tonic-gate "configuration.")); 6207c478bd9Sstevel@tonic-gate case CMD_DELETE: 6217c478bd9Sstevel@tonic-gate return (gettext("Deletes the specified zone. The -F " 6227c478bd9Sstevel@tonic-gate "flag can be used to force the\n\taction.")); 6237c478bd9Sstevel@tonic-gate case CMD_REMOVE: 6247c478bd9Sstevel@tonic-gate return (gettext("Remove specified resource from " 6257c478bd9Sstevel@tonic-gate "configuration. Note that the curly\n\tbraces " 6267c478bd9Sstevel@tonic-gate "('{', '}') mean one or more of whatever " 6277c478bd9Sstevel@tonic-gate "is between them.")); 6287c478bd9Sstevel@tonic-gate case CMD_SELECT: 6297c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 6307c478bd9Sstevel@tonic-gate gettext("Selects a resource to modify. " 6317c478bd9Sstevel@tonic-gate "Resource modification is completed\n\twith the " 6327c478bd9Sstevel@tonic-gate "command \"%s\". The property name/value pairs " 6337c478bd9Sstevel@tonic-gate "must uniquely\n\tidentify a resource. Note that " 6347c478bd9Sstevel@tonic-gate "the curly braces ('{', '}') mean one\n\tor more " 6357c478bd9Sstevel@tonic-gate "of whatever is between them."), 6367c478bd9Sstevel@tonic-gate cmd_to_str(CMD_END)); 6377c478bd9Sstevel@tonic-gate return (line); 6387c478bd9Sstevel@tonic-gate case CMD_SET: 6397c478bd9Sstevel@tonic-gate return (gettext("Sets property values.")); 6407c478bd9Sstevel@tonic-gate case CMD_INFO: 6417c478bd9Sstevel@tonic-gate return (gettext("Displays information about the " 6427c478bd9Sstevel@tonic-gate "current configuration. If resource\n\ttype is " 6437c478bd9Sstevel@tonic-gate "specified, displays only information about " 6447c478bd9Sstevel@tonic-gate "resources of\n\tthe relevant type. If resource " 6457c478bd9Sstevel@tonic-gate "id is specified, displays only\n\tinformation " 6467c478bd9Sstevel@tonic-gate "about that resource.")); 6477c478bd9Sstevel@tonic-gate case CMD_VERIFY: 6487c478bd9Sstevel@tonic-gate return (gettext("Verifies current configuration " 6497c478bd9Sstevel@tonic-gate "for correctness (some resource types\n\thave " 6507c478bd9Sstevel@tonic-gate "required properties).")); 6517c478bd9Sstevel@tonic-gate case CMD_COMMIT: 6527c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 6537c478bd9Sstevel@tonic-gate gettext("Commits current configuration. " 6547c478bd9Sstevel@tonic-gate "Configuration must be committed to\n\tbe used by " 6557c478bd9Sstevel@tonic-gate "%s. Until the configuration is committed, " 6567c478bd9Sstevel@tonic-gate "changes \n\tcan be removed with the %s " 6577c478bd9Sstevel@tonic-gate "command. This operation is\n\tattempted " 6587c478bd9Sstevel@tonic-gate "automatically upon completion of a %s " 6597c478bd9Sstevel@tonic-gate "session."), "zoneadm", cmd_to_str(CMD_REVERT), 6607c478bd9Sstevel@tonic-gate "zonecfg"); 6617c478bd9Sstevel@tonic-gate return (line); 6627c478bd9Sstevel@tonic-gate case CMD_REVERT: 6637c478bd9Sstevel@tonic-gate return (gettext("Reverts configuration back to the " 6647c478bd9Sstevel@tonic-gate "last committed state. The -F flag\n\tcan be " 6657c478bd9Sstevel@tonic-gate "used to force the action.")); 6667c478bd9Sstevel@tonic-gate case CMD_CANCEL: 6677c478bd9Sstevel@tonic-gate return (gettext("Cancels resource/property " 6687c478bd9Sstevel@tonic-gate "specification.")); 6697c478bd9Sstevel@tonic-gate case CMD_END: 6707c478bd9Sstevel@tonic-gate return (gettext("Ends resource/property " 6717c478bd9Sstevel@tonic-gate "specification.")); 6727c478bd9Sstevel@tonic-gate } 6737c478bd9Sstevel@tonic-gate /* NOTREACHED */ 6747e362f58Scomay return (NULL); 6757c478bd9Sstevel@tonic-gate } 6767c478bd9Sstevel@tonic-gate 6777c478bd9Sstevel@tonic-gate /* 6787c478bd9Sstevel@tonic-gate * Called with verbose TRUE when help is explicitly requested, FALSE for 6797c478bd9Sstevel@tonic-gate * unexpected errors. 6807c478bd9Sstevel@tonic-gate */ 6817c478bd9Sstevel@tonic-gate 6827c478bd9Sstevel@tonic-gate void 6837c478bd9Sstevel@tonic-gate usage(bool verbose, uint_t flags) 6847c478bd9Sstevel@tonic-gate { 6857c478bd9Sstevel@tonic-gate FILE *fp = verbose ? stdout : stderr, *newfp; 6867c478bd9Sstevel@tonic-gate bool need_to_close = FALSE; 6877c478bd9Sstevel@tonic-gate char *pager; 6887c478bd9Sstevel@tonic-gate int i; 6897c478bd9Sstevel@tonic-gate 6907c478bd9Sstevel@tonic-gate /* don't page error output */ 6917c478bd9Sstevel@tonic-gate if (verbose && interactive_mode) { 6927c478bd9Sstevel@tonic-gate if ((pager = getenv("PAGER")) == NULL) 6937c478bd9Sstevel@tonic-gate pager = PAGER; 6947c478bd9Sstevel@tonic-gate if ((newfp = popen(pager, "w")) != NULL) { 6957c478bd9Sstevel@tonic-gate need_to_close = TRUE; 6967c478bd9Sstevel@tonic-gate fp = newfp; 6977c478bd9Sstevel@tonic-gate } 6987c478bd9Sstevel@tonic-gate } 6997c478bd9Sstevel@tonic-gate if (flags & HELP_META) { 7007c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("More help is available for the " 7017c478bd9Sstevel@tonic-gate "following:\n")); 7027c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\n\tcommands ('%s commands')\n", 7037c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 7047c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\tsyntax ('%s syntax')\n", 7057c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 7067c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\tusage ('%s usage')\n\n", 7077c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 7087c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("You may also obtain help on any " 7097c478bd9Sstevel@tonic-gate "command by typing '%s <command-name>.'\n"), 7107c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 7117c478bd9Sstevel@tonic-gate } 7127c478bd9Sstevel@tonic-gate if (flags & HELP_RES_SCOPE) { 7137c478bd9Sstevel@tonic-gate switch (resource_scope) { 7147c478bd9Sstevel@tonic-gate case RT_FS: 7157c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 7167c478bd9Sstevel@tonic-gate "used to configure a file-system.\n"), 7177c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 7187c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 7197c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7207c478bd9Sstevel@tonic-gate pt_to_str(PT_DIR), gettext("<path>")); 7217c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7227c478bd9Sstevel@tonic-gate pt_to_str(PT_SPECIAL), gettext("<path>")); 7237c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7247c478bd9Sstevel@tonic-gate pt_to_str(PT_RAW), gettext("<raw-device>")); 7257c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7267c478bd9Sstevel@tonic-gate pt_to_str(PT_TYPE), gettext("<file-system type>")); 7277c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s %s\n", cmd_to_str(CMD_ADD), 7287c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS), 7297c478bd9Sstevel@tonic-gate gettext("<file-system options>")); 730*ffbafc53Scomay (void) fprintf(fp, "\t%s %s %s\n", 731*ffbafc53Scomay cmd_to_str(CMD_REMOVE), pt_to_str(PT_OPTIONS), 732*ffbafc53Scomay gettext("<file-system options>")); 7337c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Consult the file-system " 7347c478bd9Sstevel@tonic-gate "specific manual page, such as mount_ufs(1M), " 7357c478bd9Sstevel@tonic-gate "for\ndetails about file-system options. Note " 7367c478bd9Sstevel@tonic-gate "that any file-system options with an\nembedded " 7377c478bd9Sstevel@tonic-gate "'=' character must be enclosed in double quotes, " 7387c478bd9Sstevel@tonic-gate /*CSTYLED*/ 7397c478bd9Sstevel@tonic-gate "such as \"%s=5\".\n"), MNTOPT_RETRY); 7407c478bd9Sstevel@tonic-gate break; 7417c478bd9Sstevel@tonic-gate case RT_IPD: 7427c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 7437c478bd9Sstevel@tonic-gate "used to configure a directory\ninherited from the " 7447c478bd9Sstevel@tonic-gate "global zone into a non-global zone in read-only " 7457c478bd9Sstevel@tonic-gate "mode.\n"), rt_to_str(resource_scope)); 7467c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 7477c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7487c478bd9Sstevel@tonic-gate pt_to_str(PT_DIR), gettext("<path>")); 7497c478bd9Sstevel@tonic-gate break; 7507c478bd9Sstevel@tonic-gate case RT_NET: 7517c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 7527c478bd9Sstevel@tonic-gate "used to configure a network interface.\n"), 7537c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 7547c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 7557c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7567c478bd9Sstevel@tonic-gate pt_to_str(PT_ADDRESS), gettext("<IP-address>")); 7577c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7587c478bd9Sstevel@tonic-gate pt_to_str(PT_PHYSICAL), gettext("<interface>")); 7597c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("See ifconfig(1M) for " 7607c478bd9Sstevel@tonic-gate "details of the <interface> string.\n")); 7617c478bd9Sstevel@tonic-gate break; 7627c478bd9Sstevel@tonic-gate case RT_DEVICE: 7637c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 7647c478bd9Sstevel@tonic-gate "used to configure a device node.\n"), 7657c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 7667c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 7677c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7687c478bd9Sstevel@tonic-gate pt_to_str(PT_MATCH), gettext("<device-path>")); 7697c478bd9Sstevel@tonic-gate break; 7707c478bd9Sstevel@tonic-gate case RT_RCTL: 7717c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 7727c478bd9Sstevel@tonic-gate "used to configure a resource control.\n"), 7737c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 7747c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 7757c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7767c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), gettext("<string>")); 7777c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s (%s=%s,%s=%s,%s=%s)\n", 7787c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), pt_to_str(PT_VALUE), 7797c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV), gettext("<priv-value>"), 7807c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT), gettext("<number>"), 7817c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION), gettext("<action-value>")); 782*ffbafc53Scomay (void) fprintf(fp, "\t%s %s (%s=%s,%s=%s,%s=%s)\n", 783*ffbafc53Scomay cmd_to_str(CMD_REMOVE), pt_to_str(PT_VALUE), 784*ffbafc53Scomay pt_to_str(PT_PRIV), gettext("<priv-value>"), 785*ffbafc53Scomay pt_to_str(PT_LIMIT), gettext("<number>"), 786*ffbafc53Scomay pt_to_str(PT_ACTION), gettext("<action-value>")); 7877c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s\n\t%s := privileged\n" 7887c478bd9Sstevel@tonic-gate "\t%s := none | deny\n", gettext("Where"), 7897c478bd9Sstevel@tonic-gate gettext("<priv-value>"), gettext("<action-value>")); 7907c478bd9Sstevel@tonic-gate break; 7917c478bd9Sstevel@tonic-gate case RT_ATTR: 7927c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 7937c478bd9Sstevel@tonic-gate "used to configure a generic attribute.\n"), 7947c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 7957c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 7967c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7977c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), gettext("<name>")); 7987c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=boolean\n", 7997c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_TYPE)); 8007c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=true | false\n", 8017c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_VALUE)); 8027c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("or\n")); 8037c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=int\n", cmd_to_str(CMD_SET), 8047c478bd9Sstevel@tonic-gate pt_to_str(PT_TYPE)); 8057c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 8067c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), gettext("<integer>")); 8077c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("or\n")); 8087c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=string\n", 8097c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_TYPE)); 8107c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 8117c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), gettext("<string>")); 8127c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("or\n")); 8137c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=uint\n", 8147c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_TYPE)); 8157c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 8167c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), gettext("<unsigned integer>")); 8177c478bd9Sstevel@tonic-gate break; 818fa9e4066Sahrens case RT_DATASET: 819fa9e4066Sahrens (void) fprintf(fp, gettext("The '%s' resource scope is " 820fa9e4066Sahrens "used to export ZFS datasets.\n"), 821fa9e4066Sahrens rt_to_str(resource_scope)); 822fa9e4066Sahrens (void) fprintf(fp, gettext("Valid commands:\n")); 823fa9e4066Sahrens (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 824fa9e4066Sahrens pt_to_str(PT_NAME), gettext("<name>")); 825fa9e4066Sahrens break; 8267c478bd9Sstevel@tonic-gate } 8277c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("And from any resource scope, you " 8287c478bd9Sstevel@tonic-gate "can:\n")); 8297c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", cmd_to_str(CMD_END), 8307c478bd9Sstevel@tonic-gate gettext("(to conclude this operation)")); 8317c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", cmd_to_str(CMD_CANCEL), 8327c478bd9Sstevel@tonic-gate gettext("(to cancel this operation)")); 8337c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", cmd_to_str(CMD_EXIT), 8347c478bd9Sstevel@tonic-gate gettext("(to exit the zonecfg utility)")); 8357c478bd9Sstevel@tonic-gate } 8367c478bd9Sstevel@tonic-gate if (flags & HELP_USAGE) { 8377c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\t%s %s\n", gettext("usage"), 8387c478bd9Sstevel@tonic-gate execname, cmd_to_str(CMD_HELP)); 8397c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s -z <zone>\t\t\t(%s)\n", 8407c478bd9Sstevel@tonic-gate execname, gettext("interactive")); 8417c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s -z <zone> <command>\n", execname); 8427c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s -z <zone> -f <command-file>\n", 8437c478bd9Sstevel@tonic-gate execname); 8447c478bd9Sstevel@tonic-gate } 8457c478bd9Sstevel@tonic-gate if (flags & HELP_SUBCMDS) { 8467c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n\n", gettext("Commands")); 8477c478bd9Sstevel@tonic-gate for (i = 0; i <= CMD_MAX; i++) { 8487c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s\n", helptab[i].short_usage); 8497c478bd9Sstevel@tonic-gate if (verbose) 8507c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\n\n", long_help(i)); 8517c478bd9Sstevel@tonic-gate } 8527c478bd9Sstevel@tonic-gate } 8537c478bd9Sstevel@tonic-gate if (flags & HELP_SYNTAX) { 8547c478bd9Sstevel@tonic-gate if (!verbose) 8557c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\n"); 8567c478bd9Sstevel@tonic-gate (void) fprintf(fp, "<zone> := [A-Za-z0-9][A-Za-z0-9_.-]*\n"); 8577c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("\t(except the reserved words " 8587c478bd9Sstevel@tonic-gate "'%s' and anything starting with '%s')\n"), "global", 8597c478bd9Sstevel@tonic-gate "SUNW"); 8607c478bd9Sstevel@tonic-gate (void) fprintf(fp, 8617c478bd9Sstevel@tonic-gate gettext("\tName must be less than %d characters.\n"), 8627c478bd9Sstevel@tonic-gate ZONENAME_MAX); 8637c478bd9Sstevel@tonic-gate if (verbose) 8647c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\n"); 8657c478bd9Sstevel@tonic-gate } 8667c478bd9Sstevel@tonic-gate if (flags & HELP_NETADDR) { 8677c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("\n<net-addr> :=")); 8687c478bd9Sstevel@tonic-gate (void) fprintf(fp, 8697c478bd9Sstevel@tonic-gate gettext("\t<IPv4-address>[/<IPv4-prefix-length>] |\n")); 8707c478bd9Sstevel@tonic-gate (void) fprintf(fp, 8717c478bd9Sstevel@tonic-gate gettext("\t\t<IPv6-address>/<IPv6-prefix-length> |\n")); 8727c478bd9Sstevel@tonic-gate (void) fprintf(fp, 8737c478bd9Sstevel@tonic-gate gettext("\t\t<hostname>[/<IPv4-prefix-length>]\n")); 8747c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("See inet(3SOCKET) for IPv4 and " 8757c478bd9Sstevel@tonic-gate "IPv6 address syntax.\n")); 8767c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("<IPv4-prefix-length> := [0-32]\n")); 8777c478bd9Sstevel@tonic-gate (void) fprintf(fp, 8787c478bd9Sstevel@tonic-gate gettext("<IPv6-prefix-length> := [0-128]\n")); 8797c478bd9Sstevel@tonic-gate (void) fprintf(fp, 8807c478bd9Sstevel@tonic-gate gettext("<hostname> := [A-Za-z0-9][A-Za-z0-9-.]*\n")); 8817c478bd9Sstevel@tonic-gate } 8827c478bd9Sstevel@tonic-gate if (flags & HELP_RESOURCES) { 8837c478bd9Sstevel@tonic-gate (void) fprintf(fp, "<%s> := %s | %s | %s | %s | %s | %s\n\n", 8847c478bd9Sstevel@tonic-gate gettext("resource type"), rt_to_str(RT_FS), 8857c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD), rt_to_str(RT_NET), rt_to_str(RT_DEVICE), 8867c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL), rt_to_str(RT_ATTR)); 8877c478bd9Sstevel@tonic-gate } 8887c478bd9Sstevel@tonic-gate if (flags & HELP_PROPS) { 8897c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("For resource type ... there are " 8907c478bd9Sstevel@tonic-gate "property types ...:\n")); 8917c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 892087719fdSdp pt_to_str(PT_ZONENAME)); 893087719fdSdp (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 8947c478bd9Sstevel@tonic-gate pt_to_str(PT_ZONEPATH)); 8957c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 8967c478bd9Sstevel@tonic-gate pt_to_str(PT_AUTOBOOT)); 8977c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 8987c478bd9Sstevel@tonic-gate pt_to_str(PT_POOL)); 899*ffbafc53Scomay (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 900*ffbafc53Scomay pt_to_str(PT_LIMITPRIV)); 9017c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s, %s, %s, %s\n", rt_to_str(RT_FS), 9027c478bd9Sstevel@tonic-gate pt_to_str(PT_DIR), pt_to_str(PT_SPECIAL), 9037c478bd9Sstevel@tonic-gate pt_to_str(PT_RAW), pt_to_str(PT_TYPE), 9047c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS)); 9057c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", rt_to_str(RT_IPD), 9067c478bd9Sstevel@tonic-gate pt_to_str(PT_DIR)); 9077c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s, %s\n", rt_to_str(RT_NET), 9087c478bd9Sstevel@tonic-gate pt_to_str(PT_ADDRESS), pt_to_str(PT_PHYSICAL)); 9097c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s\n", rt_to_str(RT_DEVICE), 9107c478bd9Sstevel@tonic-gate pt_to_str(PT_MATCH)); 9117c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s, %s\n", rt_to_str(RT_RCTL), 9127c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), pt_to_str(PT_VALUE)); 9137c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s, %s, %s\n", rt_to_str(RT_ATTR), 9147c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), pt_to_str(PT_TYPE), 9157c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE)); 916fa9e4066Sahrens (void) fprintf(fp, "\t%s\t\t%s\n", rt_to_str(RT_DATASET), 917fa9e4066Sahrens pt_to_str(PT_NAME)); 9187c478bd9Sstevel@tonic-gate } 9197c478bd9Sstevel@tonic-gate if (need_to_close) 9207c478bd9Sstevel@tonic-gate (void) pclose(fp); 9217c478bd9Sstevel@tonic-gate } 9227c478bd9Sstevel@tonic-gate 9237c478bd9Sstevel@tonic-gate /* PRINTFLIKE1 */ 9247c478bd9Sstevel@tonic-gate static void 9257c478bd9Sstevel@tonic-gate zerr(const char *fmt, ...) 9267c478bd9Sstevel@tonic-gate { 9277c478bd9Sstevel@tonic-gate va_list alist; 9287c478bd9Sstevel@tonic-gate static int last_lineno; 9297c478bd9Sstevel@tonic-gate 9307c478bd9Sstevel@tonic-gate /* lex_lineno has already been incremented in the lexer; compensate */ 9317c478bd9Sstevel@tonic-gate if (cmd_file_mode && lex_lineno > last_lineno) { 9327c478bd9Sstevel@tonic-gate if (strcmp(cmd_file_name, "-") == 0) 9337c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("On line %d:\n"), 9347c478bd9Sstevel@tonic-gate lex_lineno - 1); 9357c478bd9Sstevel@tonic-gate else 9367c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("On line %d of %s:\n"), 9377c478bd9Sstevel@tonic-gate lex_lineno - 1, cmd_file_name); 9387c478bd9Sstevel@tonic-gate last_lineno = lex_lineno; 9397c478bd9Sstevel@tonic-gate } 9407c478bd9Sstevel@tonic-gate va_start(alist, fmt); 9417c478bd9Sstevel@tonic-gate (void) vfprintf(stderr, fmt, alist); 9427c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\n"); 9437c478bd9Sstevel@tonic-gate va_end(alist); 9447c478bd9Sstevel@tonic-gate } 9457c478bd9Sstevel@tonic-gate 9467c478bd9Sstevel@tonic-gate static void 9477c478bd9Sstevel@tonic-gate zone_perror(char *prefix, int err, bool set_saw) 9487c478bd9Sstevel@tonic-gate { 9497c478bd9Sstevel@tonic-gate zerr("%s: %s", prefix, zonecfg_strerror(err)); 9507c478bd9Sstevel@tonic-gate if (set_saw) 9517c478bd9Sstevel@tonic-gate saw_error = TRUE; 9527c478bd9Sstevel@tonic-gate } 9537c478bd9Sstevel@tonic-gate 9547c478bd9Sstevel@tonic-gate /* 9557c478bd9Sstevel@tonic-gate * zone_perror() expects a single string, but for remove and select 9567c478bd9Sstevel@tonic-gate * we have both the command and the resource type, so this wrapper 9577c478bd9Sstevel@tonic-gate * function serves the same purpose in a slightly different way. 9587c478bd9Sstevel@tonic-gate */ 9597c478bd9Sstevel@tonic-gate 9607c478bd9Sstevel@tonic-gate static void 9617c478bd9Sstevel@tonic-gate z_cmd_rt_perror(int cmd_num, int res_num, int err, bool set_saw) 9627c478bd9Sstevel@tonic-gate { 9637c478bd9Sstevel@tonic-gate zerr("%s %s: %s", cmd_to_str(cmd_num), rt_to_str(res_num), 9647c478bd9Sstevel@tonic-gate zonecfg_strerror(err)); 9657c478bd9Sstevel@tonic-gate if (set_saw) 9667c478bd9Sstevel@tonic-gate saw_error = TRUE; 9677c478bd9Sstevel@tonic-gate } 9687c478bd9Sstevel@tonic-gate 9697c478bd9Sstevel@tonic-gate /* returns Z_OK if successful, Z_foo from <libzonecfg.h> otherwise */ 9707c478bd9Sstevel@tonic-gate static int 9717c478bd9Sstevel@tonic-gate initialize(bool handle_expected) 9727c478bd9Sstevel@tonic-gate { 9737c478bd9Sstevel@tonic-gate int err; 9747c478bd9Sstevel@tonic-gate 9757c478bd9Sstevel@tonic-gate if (zonecfg_check_handle(handle) != Z_OK) { 9767c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_handle(zone, handle)) == Z_OK) { 9777c478bd9Sstevel@tonic-gate got_handle = TRUE; 9787c478bd9Sstevel@tonic-gate } else { 9797c478bd9Sstevel@tonic-gate zone_perror(zone, err, handle_expected || got_handle); 9807c478bd9Sstevel@tonic-gate if (err == Z_NO_ZONE && !got_handle && 9817c478bd9Sstevel@tonic-gate interactive_mode && !read_only_mode) 9827c478bd9Sstevel@tonic-gate (void) printf(gettext("Use '%s' to begin " 9837c478bd9Sstevel@tonic-gate "configuring a new zone.\n"), 9847c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE)); 9857c478bd9Sstevel@tonic-gate return (err); 9867c478bd9Sstevel@tonic-gate } 9877c478bd9Sstevel@tonic-gate } 9887c478bd9Sstevel@tonic-gate return (Z_OK); 9897c478bd9Sstevel@tonic-gate } 9907c478bd9Sstevel@tonic-gate 991087719fdSdp static bool 992087719fdSdp state_atleast(zone_state_t state) 993087719fdSdp { 994087719fdSdp zone_state_t state_num; 995087719fdSdp int err; 996087719fdSdp 997087719fdSdp if ((err = zone_get_state(zone, &state_num)) != Z_OK) { 998087719fdSdp /* all states are greater than "non-existent" */ 999087719fdSdp if (err == Z_NO_ZONE) 1000087719fdSdp return (B_FALSE); 1001087719fdSdp zerr(gettext("Unexpectedly failed to determine state " 1002087719fdSdp "of zone %s: %s"), zone, zonecfg_strerror(err)); 1003087719fdSdp exit(Z_ERR); 1004087719fdSdp } 1005087719fdSdp return (state_num >= state); 1006087719fdSdp } 1007087719fdSdp 10087c478bd9Sstevel@tonic-gate /* 10097c478bd9Sstevel@tonic-gate * short_usage() is for bad syntax: getopt() issues, too many arguments, etc. 10107c478bd9Sstevel@tonic-gate */ 10117c478bd9Sstevel@tonic-gate 10127c478bd9Sstevel@tonic-gate void 10137c478bd9Sstevel@tonic-gate short_usage(int command) 10147c478bd9Sstevel@tonic-gate { 10157c478bd9Sstevel@tonic-gate /* lex_lineno has already been incremented in the lexer; compensate */ 10167c478bd9Sstevel@tonic-gate if (cmd_file_mode) { 10177c478bd9Sstevel@tonic-gate if (strcmp(cmd_file_name, "-") == 0) 10187c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 10197c478bd9Sstevel@tonic-gate gettext("syntax error on line %d\n"), 10207c478bd9Sstevel@tonic-gate lex_lineno - 1); 10217c478bd9Sstevel@tonic-gate else 10227c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 10237c478bd9Sstevel@tonic-gate gettext("syntax error on line %d of %s\n"), 10247c478bd9Sstevel@tonic-gate lex_lineno - 1, cmd_file_name); 10257c478bd9Sstevel@tonic-gate } 10267c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s:\n%s\n", gettext("usage"), 10277c478bd9Sstevel@tonic-gate helptab[command].short_usage); 10287c478bd9Sstevel@tonic-gate saw_error = TRUE; 10297c478bd9Sstevel@tonic-gate } 10307c478bd9Sstevel@tonic-gate 10317c478bd9Sstevel@tonic-gate /* 10327c478bd9Sstevel@tonic-gate * long_usage() is for bad semantics: e.g., wrong property type for a given 10337c478bd9Sstevel@tonic-gate * resource type. It is also used by longer_usage() below. 10347c478bd9Sstevel@tonic-gate */ 10357c478bd9Sstevel@tonic-gate 10367c478bd9Sstevel@tonic-gate void 10377c478bd9Sstevel@tonic-gate long_usage(uint_t cmd_num, bool set_saw) 10387c478bd9Sstevel@tonic-gate { 10397c478bd9Sstevel@tonic-gate (void) fprintf(set_saw ? stderr : stdout, "%s:\n%s\n", gettext("usage"), 10407c478bd9Sstevel@tonic-gate helptab[cmd_num].short_usage); 10417c478bd9Sstevel@tonic-gate (void) fprintf(set_saw ? stderr : stdout, "\t%s\n", long_help(cmd_num)); 10427c478bd9Sstevel@tonic-gate if (set_saw) 10437c478bd9Sstevel@tonic-gate saw_error = TRUE; 10447c478bd9Sstevel@tonic-gate } 10457c478bd9Sstevel@tonic-gate 10467c478bd9Sstevel@tonic-gate /* 10477c478bd9Sstevel@tonic-gate * longer_usage() is for 'help foo' and 'foo -?': call long_usage() and also 10487c478bd9Sstevel@tonic-gate * any extra usage() flags as appropriate for whatever command. 10497c478bd9Sstevel@tonic-gate */ 10507c478bd9Sstevel@tonic-gate 10517c478bd9Sstevel@tonic-gate void 10527c478bd9Sstevel@tonic-gate longer_usage(uint_t cmd_num) 10537c478bd9Sstevel@tonic-gate { 10547c478bd9Sstevel@tonic-gate long_usage(cmd_num, FALSE); 10557c478bd9Sstevel@tonic-gate if (helptab[cmd_num].flags != 0) { 10567c478bd9Sstevel@tonic-gate (void) printf("\n"); 10577c478bd9Sstevel@tonic-gate usage(TRUE, helptab[cmd_num].flags); 10587c478bd9Sstevel@tonic-gate } 10597c478bd9Sstevel@tonic-gate } 10607c478bd9Sstevel@tonic-gate 10617c478bd9Sstevel@tonic-gate /* 10627c478bd9Sstevel@tonic-gate * scope_usage() is simply used when a command is called from the wrong scope. 10637c478bd9Sstevel@tonic-gate */ 10647c478bd9Sstevel@tonic-gate 10657c478bd9Sstevel@tonic-gate static void 10667c478bd9Sstevel@tonic-gate scope_usage(uint_t cmd_num) 10677c478bd9Sstevel@tonic-gate { 10687c478bd9Sstevel@tonic-gate zerr(gettext("The %s command only makes sense in the %s scope."), 10697c478bd9Sstevel@tonic-gate cmd_to_str(cmd_num), 10707c478bd9Sstevel@tonic-gate global_scope ? gettext("resource") : gettext("global")); 10717c478bd9Sstevel@tonic-gate saw_error = TRUE; 10727c478bd9Sstevel@tonic-gate } 10737c478bd9Sstevel@tonic-gate 10747c478bd9Sstevel@tonic-gate /* 10757c478bd9Sstevel@tonic-gate * On input, TRUE => yes, FALSE => no. 10767c478bd9Sstevel@tonic-gate * On return, TRUE => 1, FALSE => no, could not ask => -1. 10777c478bd9Sstevel@tonic-gate */ 10787c478bd9Sstevel@tonic-gate 10797c478bd9Sstevel@tonic-gate static int 10807c478bd9Sstevel@tonic-gate ask_yesno(bool default_answer, const char *question) 10817c478bd9Sstevel@tonic-gate { 10827c478bd9Sstevel@tonic-gate char line[64]; /* should be enough to answer yes or no */ 10837c478bd9Sstevel@tonic-gate 10847c478bd9Sstevel@tonic-gate if (!ok_to_prompt) { 10857c478bd9Sstevel@tonic-gate saw_error = TRUE; 10867c478bd9Sstevel@tonic-gate return (-1); 10877c478bd9Sstevel@tonic-gate } 10887c478bd9Sstevel@tonic-gate for (;;) { 1089087719fdSdp if (printf("%s (%s)? ", question, 1090087719fdSdp default_answer ? "[y]/n" : "y/[n]") < 0) 1091087719fdSdp return (-1); 1092087719fdSdp if (fgets(line, sizeof (line), stdin) == NULL) 1093087719fdSdp return (-1); 1094087719fdSdp 1095087719fdSdp if (line[0] == '\n') 10967c478bd9Sstevel@tonic-gate return (default_answer ? 1 : 0); 10977c478bd9Sstevel@tonic-gate if (tolower(line[0]) == 'y') 10987c478bd9Sstevel@tonic-gate return (1); 10997c478bd9Sstevel@tonic-gate if (tolower(line[0]) == 'n') 11007c478bd9Sstevel@tonic-gate return (0); 11017c478bd9Sstevel@tonic-gate } 11027c478bd9Sstevel@tonic-gate } 11037c478bd9Sstevel@tonic-gate 11047c478bd9Sstevel@tonic-gate /* 11057c478bd9Sstevel@tonic-gate * Prints warning if zone already exists. 11067c478bd9Sstevel@tonic-gate * In interactive mode, prompts if we should continue anyway and returns Z_OK 11077c478bd9Sstevel@tonic-gate * if so, Z_ERR if not. In non-interactive mode, exits with Z_ERR. 11087c478bd9Sstevel@tonic-gate * 11097c478bd9Sstevel@tonic-gate * Note that if a zone exists and its state is >= INSTALLED, an error message 11107c478bd9Sstevel@tonic-gate * will be printed and this function will return Z_ERR regardless of mode. 11117c478bd9Sstevel@tonic-gate */ 11127c478bd9Sstevel@tonic-gate 11137c478bd9Sstevel@tonic-gate static int 11147c478bd9Sstevel@tonic-gate check_if_zone_already_exists(bool force) 11157c478bd9Sstevel@tonic-gate { 11167c478bd9Sstevel@tonic-gate char line[ZONENAME_MAX + 128]; /* enough to ask a question */ 11177c478bd9Sstevel@tonic-gate zone_dochandle_t tmphandle; 11187c478bd9Sstevel@tonic-gate int res, answer; 11197c478bd9Sstevel@tonic-gate 11207c478bd9Sstevel@tonic-gate if ((tmphandle = zonecfg_init_handle()) == NULL) { 11217c478bd9Sstevel@tonic-gate zone_perror(execname, Z_NOMEM, TRUE); 11227c478bd9Sstevel@tonic-gate exit(Z_ERR); 11237c478bd9Sstevel@tonic-gate } 11247c478bd9Sstevel@tonic-gate res = zonecfg_get_handle(zone, tmphandle); 11257c478bd9Sstevel@tonic-gate zonecfg_fini_handle(tmphandle); 1126087719fdSdp if (res != Z_OK) 11277c478bd9Sstevel@tonic-gate return (Z_OK); 1128087719fdSdp 1129087719fdSdp if (state_atleast(ZONE_STATE_INSTALLED)) { 11307c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s already installed; %s not allowed."), 11317c478bd9Sstevel@tonic-gate zone, cmd_to_str(CMD_CREATE)); 11327c478bd9Sstevel@tonic-gate return (Z_ERR); 11337c478bd9Sstevel@tonic-gate } 11347c478bd9Sstevel@tonic-gate 11357c478bd9Sstevel@tonic-gate if (force) { 11367c478bd9Sstevel@tonic-gate (void) printf(gettext("Zone %s already exists; overwriting.\n"), 11377c478bd9Sstevel@tonic-gate zone); 11387c478bd9Sstevel@tonic-gate return (Z_OK); 11397c478bd9Sstevel@tonic-gate } 11407c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 11417c478bd9Sstevel@tonic-gate gettext("Zone %s already exists; %s anyway"), zone, 11427c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE)); 11437c478bd9Sstevel@tonic-gate if ((answer = ask_yesno(FALSE, line)) == -1) { 11447c478bd9Sstevel@tonic-gate zerr(gettext("Zone exists, input not from terminal and -F not " 11457c478bd9Sstevel@tonic-gate "specified:\n%s command ignored, exiting."), 11467c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE)); 11477c478bd9Sstevel@tonic-gate exit(Z_ERR); 11487c478bd9Sstevel@tonic-gate } 11497c478bd9Sstevel@tonic-gate return (answer == 1 ? Z_OK : Z_ERR); 11507c478bd9Sstevel@tonic-gate } 11517c478bd9Sstevel@tonic-gate 11527c478bd9Sstevel@tonic-gate static bool 11537c478bd9Sstevel@tonic-gate zone_is_read_only(int cmd_num) 11547c478bd9Sstevel@tonic-gate { 11557c478bd9Sstevel@tonic-gate if (strncmp(zone, "SUNW", 4) == 0) { 11567c478bd9Sstevel@tonic-gate zerr(gettext("%s: zones beginning with SUNW are read-only."), 11577c478bd9Sstevel@tonic-gate zone); 11587c478bd9Sstevel@tonic-gate saw_error = TRUE; 11597c478bd9Sstevel@tonic-gate return (TRUE); 11607c478bd9Sstevel@tonic-gate } 11617c478bd9Sstevel@tonic-gate if (read_only_mode) { 11627c478bd9Sstevel@tonic-gate zerr(gettext("%s: cannot %s in read-only mode."), zone, 11637c478bd9Sstevel@tonic-gate cmd_to_str(cmd_num)); 11647c478bd9Sstevel@tonic-gate saw_error = TRUE; 11657c478bd9Sstevel@tonic-gate return (TRUE); 11667c478bd9Sstevel@tonic-gate } 11677c478bd9Sstevel@tonic-gate return (FALSE); 11687c478bd9Sstevel@tonic-gate } 11697c478bd9Sstevel@tonic-gate 11707c478bd9Sstevel@tonic-gate /* 11717c478bd9Sstevel@tonic-gate * Create a new configuration. 11727c478bd9Sstevel@tonic-gate */ 11737c478bd9Sstevel@tonic-gate void 11747c478bd9Sstevel@tonic-gate create_func(cmd_t *cmd) 11757c478bd9Sstevel@tonic-gate { 11767c478bd9Sstevel@tonic-gate int err, arg; 11777c478bd9Sstevel@tonic-gate char zone_template[ZONENAME_MAX]; 1178ee519a1fSgjelinek char attach_path[MAXPATHLEN]; 11797c478bd9Sstevel@tonic-gate zone_dochandle_t tmphandle; 11807c478bd9Sstevel@tonic-gate bool force = FALSE; 1181ee519a1fSgjelinek bool attach = FALSE; 11827c478bd9Sstevel@tonic-gate 11837c478bd9Sstevel@tonic-gate assert(cmd != NULL); 11847c478bd9Sstevel@tonic-gate 11857c478bd9Sstevel@tonic-gate /* This is the default if no arguments are given. */ 11867c478bd9Sstevel@tonic-gate (void) strlcpy(zone_template, "SUNWdefault", sizeof (zone_template)); 11877c478bd9Sstevel@tonic-gate 11887c478bd9Sstevel@tonic-gate optind = 0; 1189ee519a1fSgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?a:bFt:")) != EOF) { 11907c478bd9Sstevel@tonic-gate switch (arg) { 11917c478bd9Sstevel@tonic-gate case '?': 11927c478bd9Sstevel@tonic-gate if (optopt == '?') 11937c478bd9Sstevel@tonic-gate longer_usage(CMD_CREATE); 11947c478bd9Sstevel@tonic-gate else 11957c478bd9Sstevel@tonic-gate short_usage(CMD_CREATE); 11967c478bd9Sstevel@tonic-gate return; 1197ee519a1fSgjelinek case 'a': 1198ee519a1fSgjelinek (void) strlcpy(attach_path, optarg, 1199ee519a1fSgjelinek sizeof (attach_path)); 1200ee519a1fSgjelinek attach = TRUE; 1201ee519a1fSgjelinek break; 12027c478bd9Sstevel@tonic-gate case 'b': 12037c478bd9Sstevel@tonic-gate (void) strlcpy(zone_template, "SUNWblank", 12047c478bd9Sstevel@tonic-gate sizeof (zone_template)); 12057c478bd9Sstevel@tonic-gate break; 12067c478bd9Sstevel@tonic-gate case 'F': 12077c478bd9Sstevel@tonic-gate force = TRUE; 12087c478bd9Sstevel@tonic-gate break; 12097c478bd9Sstevel@tonic-gate case 't': 12107c478bd9Sstevel@tonic-gate (void) strlcpy(zone_template, optarg, 12117c478bd9Sstevel@tonic-gate sizeof (zone_template)); 12127c478bd9Sstevel@tonic-gate break; 12137c478bd9Sstevel@tonic-gate default: 12147c478bd9Sstevel@tonic-gate short_usage(CMD_CREATE); 12157c478bd9Sstevel@tonic-gate return; 12167c478bd9Sstevel@tonic-gate } 12177c478bd9Sstevel@tonic-gate } 12187c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 12197c478bd9Sstevel@tonic-gate short_usage(CMD_CREATE); 12207c478bd9Sstevel@tonic-gate return; 12217c478bd9Sstevel@tonic-gate } 12227c478bd9Sstevel@tonic-gate 12237c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_CREATE)) 12247c478bd9Sstevel@tonic-gate return; 12257c478bd9Sstevel@tonic-gate 12267c478bd9Sstevel@tonic-gate if (check_if_zone_already_exists(force) != Z_OK) 12277c478bd9Sstevel@tonic-gate return; 12287c478bd9Sstevel@tonic-gate 12297c478bd9Sstevel@tonic-gate /* 12307c478bd9Sstevel@tonic-gate * Get a temporary handle first. If that fails, the old handle 12317c478bd9Sstevel@tonic-gate * will not be lost. Then finish whichever one we don't need, 12327c478bd9Sstevel@tonic-gate * to avoid leaks. Then get the handle for zone_template, and 12337c478bd9Sstevel@tonic-gate * set the name to zone: this "copy, rename" method is how 12347c478bd9Sstevel@tonic-gate * create -[b|t] works. 12357c478bd9Sstevel@tonic-gate */ 12367c478bd9Sstevel@tonic-gate if ((tmphandle = zonecfg_init_handle()) == NULL) { 12377c478bd9Sstevel@tonic-gate zone_perror(execname, Z_NOMEM, TRUE); 12387c478bd9Sstevel@tonic-gate exit(Z_ERR); 12397c478bd9Sstevel@tonic-gate } 1240ee519a1fSgjelinek 1241ee519a1fSgjelinek if (attach) 1242ee519a1fSgjelinek err = zonecfg_get_attach_handle(attach_path, zone, B_FALSE, 1243ee519a1fSgjelinek tmphandle); 1244ee519a1fSgjelinek else 1245ee519a1fSgjelinek err = zonecfg_get_template_handle(zone_template, zone, 1246ee519a1fSgjelinek tmphandle); 1247ee519a1fSgjelinek 1248ee519a1fSgjelinek if (err != Z_OK) { 12497c478bd9Sstevel@tonic-gate zonecfg_fini_handle(tmphandle); 1250ee519a1fSgjelinek if (attach && err == Z_NO_ZONE) 1251ee519a1fSgjelinek (void) fprintf(stderr, gettext("invalid path to " 1252ee519a1fSgjelinek "detached zone\n")); 1253ee519a1fSgjelinek else if (attach && err == Z_INVALID_DOCUMENT) 1254ee519a1fSgjelinek (void) fprintf(stderr, gettext("Cannot attach to an " 1255ee519a1fSgjelinek "earlier release of the operating system\n")); 1256ee519a1fSgjelinek else 12577c478bd9Sstevel@tonic-gate zone_perror(zone_template, err, TRUE); 12587c478bd9Sstevel@tonic-gate return; 12597c478bd9Sstevel@tonic-gate } 1260087719fdSdp 1261087719fdSdp need_to_commit = TRUE; 12627c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 12637c478bd9Sstevel@tonic-gate handle = tmphandle; 1264087719fdSdp got_handle = TRUE; 12657c478bd9Sstevel@tonic-gate } 12667c478bd9Sstevel@tonic-gate 12677c478bd9Sstevel@tonic-gate /* 12687c478bd9Sstevel@tonic-gate * This malloc()'s memory, which must be freed by the caller. 12697c478bd9Sstevel@tonic-gate */ 12707c478bd9Sstevel@tonic-gate static char * 12717c478bd9Sstevel@tonic-gate quoteit(char *instr) 12727c478bd9Sstevel@tonic-gate { 12737c478bd9Sstevel@tonic-gate char *outstr; 12747c478bd9Sstevel@tonic-gate size_t outstrsize = strlen(instr) + 3; /* 2 quotes + '\0' */ 12757c478bd9Sstevel@tonic-gate 12767c478bd9Sstevel@tonic-gate if ((outstr = malloc(outstrsize)) == NULL) { 12777c478bd9Sstevel@tonic-gate zone_perror(zone, Z_NOMEM, FALSE); 12787c478bd9Sstevel@tonic-gate exit(Z_ERR); 12797c478bd9Sstevel@tonic-gate } 12807c478bd9Sstevel@tonic-gate if (strchr(instr, ' ') == NULL) { 12817c478bd9Sstevel@tonic-gate (void) strlcpy(outstr, instr, outstrsize); 12827c478bd9Sstevel@tonic-gate return (outstr); 12837c478bd9Sstevel@tonic-gate } 12847c478bd9Sstevel@tonic-gate (void) snprintf(outstr, outstrsize, "\"%s\"", instr); 12857c478bd9Sstevel@tonic-gate return (outstr); 12867c478bd9Sstevel@tonic-gate } 12877c478bd9Sstevel@tonic-gate 12887c478bd9Sstevel@tonic-gate static void 12897c478bd9Sstevel@tonic-gate export_prop(FILE *of, int prop_num, char *prop_id) 12907c478bd9Sstevel@tonic-gate { 12917c478bd9Sstevel@tonic-gate char *quote_str; 12927c478bd9Sstevel@tonic-gate 12937c478bd9Sstevel@tonic-gate if (strlen(prop_id) == 0) 12947c478bd9Sstevel@tonic-gate return; 12957c478bd9Sstevel@tonic-gate quote_str = quoteit(prop_id); 12967c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 12977c478bd9Sstevel@tonic-gate pt_to_str(prop_num), quote_str); 12987c478bd9Sstevel@tonic-gate free(quote_str); 12997c478bd9Sstevel@tonic-gate } 13007c478bd9Sstevel@tonic-gate 13017c478bd9Sstevel@tonic-gate void 13027c478bd9Sstevel@tonic-gate export_func(cmd_t *cmd) 13037c478bd9Sstevel@tonic-gate { 13047c478bd9Sstevel@tonic-gate struct zone_nwiftab nwiftab; 13057c478bd9Sstevel@tonic-gate struct zone_fstab fstab; 13067c478bd9Sstevel@tonic-gate struct zone_devtab devtab; 13077c478bd9Sstevel@tonic-gate struct zone_attrtab attrtab; 13087c478bd9Sstevel@tonic-gate struct zone_rctltab rctltab; 1309fa9e4066Sahrens struct zone_dstab dstab; 13107c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *valptr; 13117c478bd9Sstevel@tonic-gate int err, arg; 13127c478bd9Sstevel@tonic-gate char zonepath[MAXPATHLEN], outfile[MAXPATHLEN], pool[MAXNAMELEN]; 1313*ffbafc53Scomay char *limitpriv; 13147c478bd9Sstevel@tonic-gate FILE *of; 13157c478bd9Sstevel@tonic-gate boolean_t autoboot; 13167c478bd9Sstevel@tonic-gate bool need_to_close = FALSE; 13177c478bd9Sstevel@tonic-gate 13187c478bd9Sstevel@tonic-gate assert(cmd != NULL); 13197c478bd9Sstevel@tonic-gate 13207c478bd9Sstevel@tonic-gate outfile[0] = '\0'; 13217c478bd9Sstevel@tonic-gate optind = 0; 13227c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?f:")) != EOF) { 13237c478bd9Sstevel@tonic-gate switch (arg) { 13247c478bd9Sstevel@tonic-gate case '?': 13257c478bd9Sstevel@tonic-gate if (optopt == '?') 13267c478bd9Sstevel@tonic-gate longer_usage(CMD_EXPORT); 13277c478bd9Sstevel@tonic-gate else 13287c478bd9Sstevel@tonic-gate short_usage(CMD_EXPORT); 13297c478bd9Sstevel@tonic-gate return; 13307c478bd9Sstevel@tonic-gate case 'f': 13317c478bd9Sstevel@tonic-gate (void) strlcpy(outfile, optarg, sizeof (outfile)); 13327c478bd9Sstevel@tonic-gate break; 13337c478bd9Sstevel@tonic-gate default: 13347c478bd9Sstevel@tonic-gate short_usage(CMD_EXPORT); 13357c478bd9Sstevel@tonic-gate return; 13367c478bd9Sstevel@tonic-gate } 13377c478bd9Sstevel@tonic-gate } 13387c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 13397c478bd9Sstevel@tonic-gate short_usage(CMD_EXPORT); 13407c478bd9Sstevel@tonic-gate return; 13417c478bd9Sstevel@tonic-gate } 13427c478bd9Sstevel@tonic-gate if (strlen(outfile) == 0) { 13437c478bd9Sstevel@tonic-gate of = stdout; 13447c478bd9Sstevel@tonic-gate } else { 13457c478bd9Sstevel@tonic-gate if ((of = fopen(outfile, "w")) == NULL) { 13467c478bd9Sstevel@tonic-gate zerr(gettext("opening file %s: %s"), 13477c478bd9Sstevel@tonic-gate outfile, strerror(errno)); 13487c478bd9Sstevel@tonic-gate goto done; 13497c478bd9Sstevel@tonic-gate } 13507c478bd9Sstevel@tonic-gate setbuf(of, NULL); 13517c478bd9Sstevel@tonic-gate need_to_close = TRUE; 13527c478bd9Sstevel@tonic-gate } 13537c478bd9Sstevel@tonic-gate 13547c478bd9Sstevel@tonic-gate if ((err = initialize(TRUE)) != Z_OK) 13557c478bd9Sstevel@tonic-gate goto done; 13567c478bd9Sstevel@tonic-gate 13577c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s -b\n", cmd_to_str(CMD_CREATE)); 13587c478bd9Sstevel@tonic-gate 13597c478bd9Sstevel@tonic-gate if (zonecfg_get_zonepath(handle, zonepath, sizeof (zonepath)) == Z_OK && 13607c478bd9Sstevel@tonic-gate strlen(zonepath) > 0) 13617c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 13627c478bd9Sstevel@tonic-gate pt_to_str(PT_ZONEPATH), zonepath); 13637c478bd9Sstevel@tonic-gate 13647c478bd9Sstevel@tonic-gate if (zonecfg_get_autoboot(handle, &autoboot) == Z_OK) 13657c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 13667c478bd9Sstevel@tonic-gate pt_to_str(PT_AUTOBOOT), autoboot ? "true" : "false"); 13677c478bd9Sstevel@tonic-gate 13687c478bd9Sstevel@tonic-gate if (zonecfg_get_pool(handle, pool, sizeof (pool)) == Z_OK && 13697c478bd9Sstevel@tonic-gate strlen(pool) > 0) 13707c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 13717c478bd9Sstevel@tonic-gate pt_to_str(PT_POOL), pool); 13727c478bd9Sstevel@tonic-gate 1373*ffbafc53Scomay if (zonecfg_get_limitpriv(handle, &limitpriv) == Z_OK && 1374*ffbafc53Scomay strlen(limitpriv) > 0) { 1375*ffbafc53Scomay (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 1376*ffbafc53Scomay pt_to_str(PT_LIMITPRIV), limitpriv); 1377*ffbafc53Scomay free(limitpriv); 1378*ffbafc53Scomay } 1379*ffbafc53Scomay 13807c478bd9Sstevel@tonic-gate if ((err = zonecfg_setipdent(handle)) != Z_OK) { 13817c478bd9Sstevel@tonic-gate zone_perror(zone, err, FALSE); 13827c478bd9Sstevel@tonic-gate goto done; 13837c478bd9Sstevel@tonic-gate } 13847c478bd9Sstevel@tonic-gate while (zonecfg_getipdent(handle, &fstab) == Z_OK) { 13857c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 13867c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD)); 13877c478bd9Sstevel@tonic-gate export_prop(of, PT_DIR, fstab.zone_fs_dir); 13887c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 13897c478bd9Sstevel@tonic-gate } 13907c478bd9Sstevel@tonic-gate (void) zonecfg_endipdent(handle); 13917c478bd9Sstevel@tonic-gate 13927c478bd9Sstevel@tonic-gate if ((err = zonecfg_setfsent(handle)) != Z_OK) { 13937c478bd9Sstevel@tonic-gate zone_perror(zone, err, FALSE); 13947c478bd9Sstevel@tonic-gate goto done; 13957c478bd9Sstevel@tonic-gate } 13967c478bd9Sstevel@tonic-gate while (zonecfg_getfsent(handle, &fstab) == Z_OK) { 13977c478bd9Sstevel@tonic-gate zone_fsopt_t *optptr; 13987c478bd9Sstevel@tonic-gate 13997c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 14007c478bd9Sstevel@tonic-gate rt_to_str(RT_FS)); 14017c478bd9Sstevel@tonic-gate export_prop(of, PT_DIR, fstab.zone_fs_dir); 14027c478bd9Sstevel@tonic-gate export_prop(of, PT_SPECIAL, fstab.zone_fs_special); 14037c478bd9Sstevel@tonic-gate export_prop(of, PT_RAW, fstab.zone_fs_raw); 14047c478bd9Sstevel@tonic-gate export_prop(of, PT_TYPE, fstab.zone_fs_type); 14057c478bd9Sstevel@tonic-gate for (optptr = fstab.zone_fs_options; optptr != NULL; 14067c478bd9Sstevel@tonic-gate optptr = optptr->zone_fsopt_next) { 14077c478bd9Sstevel@tonic-gate /* 14087c478bd9Sstevel@tonic-gate * Simple property values with embedded equal signs 14097c478bd9Sstevel@tonic-gate * need to be quoted to prevent the lexer from 14107c478bd9Sstevel@tonic-gate * mis-parsing them as complex name=value pairs. 14117c478bd9Sstevel@tonic-gate */ 14127c478bd9Sstevel@tonic-gate if (strchr(optptr->zone_fsopt_opt, '=')) 14137c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s \"%s\"\n", 14147c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), 14157c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS), 14167c478bd9Sstevel@tonic-gate optptr->zone_fsopt_opt); 14177c478bd9Sstevel@tonic-gate else 14187c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s %s\n", 14197c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), 14207c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS), 14217c478bd9Sstevel@tonic-gate optptr->zone_fsopt_opt); 14227c478bd9Sstevel@tonic-gate } 14237c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 14247c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(fstab.zone_fs_options); 14257c478bd9Sstevel@tonic-gate } 14267c478bd9Sstevel@tonic-gate (void) zonecfg_endfsent(handle); 14277c478bd9Sstevel@tonic-gate 14287c478bd9Sstevel@tonic-gate if ((err = zonecfg_setnwifent(handle)) != Z_OK) { 14297c478bd9Sstevel@tonic-gate zone_perror(zone, err, FALSE); 14307c478bd9Sstevel@tonic-gate goto done; 14317c478bd9Sstevel@tonic-gate } 14327c478bd9Sstevel@tonic-gate while (zonecfg_getnwifent(handle, &nwiftab) == Z_OK) { 14337c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 14347c478bd9Sstevel@tonic-gate rt_to_str(RT_NET)); 14357c478bd9Sstevel@tonic-gate export_prop(of, PT_ADDRESS, nwiftab.zone_nwif_address); 14367c478bd9Sstevel@tonic-gate export_prop(of, PT_PHYSICAL, nwiftab.zone_nwif_physical); 14377c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 14387c478bd9Sstevel@tonic-gate } 14397c478bd9Sstevel@tonic-gate (void) zonecfg_endnwifent(handle); 14407c478bd9Sstevel@tonic-gate 14417c478bd9Sstevel@tonic-gate if ((err = zonecfg_setdevent(handle)) != Z_OK) { 14427c478bd9Sstevel@tonic-gate zone_perror(zone, err, FALSE); 14437c478bd9Sstevel@tonic-gate goto done; 14447c478bd9Sstevel@tonic-gate } 14457c478bd9Sstevel@tonic-gate while (zonecfg_getdevent(handle, &devtab) == Z_OK) { 14467c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 14477c478bd9Sstevel@tonic-gate rt_to_str(RT_DEVICE)); 14487c478bd9Sstevel@tonic-gate export_prop(of, PT_MATCH, devtab.zone_dev_match); 14497c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 14507c478bd9Sstevel@tonic-gate } 14517c478bd9Sstevel@tonic-gate (void) zonecfg_enddevent(handle); 14527c478bd9Sstevel@tonic-gate 14537c478bd9Sstevel@tonic-gate if ((err = zonecfg_setrctlent(handle)) != Z_OK) { 14547c478bd9Sstevel@tonic-gate zone_perror(zone, err, FALSE); 14557c478bd9Sstevel@tonic-gate goto done; 14567c478bd9Sstevel@tonic-gate } 14577c478bd9Sstevel@tonic-gate while (zonecfg_getrctlent(handle, &rctltab) == Z_OK) { 14587c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s rctl\n", cmd_to_str(CMD_ADD)); 14597c478bd9Sstevel@tonic-gate export_prop(of, PT_NAME, rctltab.zone_rctl_name); 14607c478bd9Sstevel@tonic-gate for (valptr = rctltab.zone_rctl_valptr; valptr != NULL; 14617c478bd9Sstevel@tonic-gate valptr = valptr->zone_rctlval_next) { 14627c478bd9Sstevel@tonic-gate fprintf(of, "%s %s (%s=%s,%s=%s,%s=%s)\n", 14637c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), pt_to_str(PT_VALUE), 14647c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV), valptr->zone_rctlval_priv, 14657c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT), valptr->zone_rctlval_limit, 14667c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION), valptr->zone_rctlval_action); 14677c478bd9Sstevel@tonic-gate } 14687c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 14697c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr); 14707c478bd9Sstevel@tonic-gate } 14717c478bd9Sstevel@tonic-gate (void) zonecfg_endrctlent(handle); 14727c478bd9Sstevel@tonic-gate 14737c478bd9Sstevel@tonic-gate if ((err = zonecfg_setattrent(handle)) != Z_OK) { 14747c478bd9Sstevel@tonic-gate zone_perror(zone, err, FALSE); 14757c478bd9Sstevel@tonic-gate goto done; 14767c478bd9Sstevel@tonic-gate } 14777c478bd9Sstevel@tonic-gate while (zonecfg_getattrent(handle, &attrtab) == Z_OK) { 14787c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 14797c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR)); 14807c478bd9Sstevel@tonic-gate export_prop(of, PT_NAME, attrtab.zone_attr_name); 14817c478bd9Sstevel@tonic-gate export_prop(of, PT_TYPE, attrtab.zone_attr_type); 14827c478bd9Sstevel@tonic-gate export_prop(of, PT_VALUE, attrtab.zone_attr_value); 14837c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 14847c478bd9Sstevel@tonic-gate } 14857c478bd9Sstevel@tonic-gate (void) zonecfg_endattrent(handle); 14867c478bd9Sstevel@tonic-gate 1487fa9e4066Sahrens if ((err = zonecfg_setdsent(handle)) != Z_OK) { 1488fa9e4066Sahrens zone_perror(zone, err, FALSE); 1489fa9e4066Sahrens goto done; 1490fa9e4066Sahrens } 1491fa9e4066Sahrens while (zonecfg_getdsent(handle, &dstab) == Z_OK) { 1492fa9e4066Sahrens (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 1493fa9e4066Sahrens rt_to_str(RT_DATASET)); 1494fa9e4066Sahrens export_prop(of, PT_NAME, dstab.zone_dataset_name); 1495fa9e4066Sahrens (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 1496fa9e4066Sahrens } 1497fa9e4066Sahrens (void) zonecfg_enddsent(handle); 1498fa9e4066Sahrens 14997c478bd9Sstevel@tonic-gate done: 15007c478bd9Sstevel@tonic-gate if (need_to_close) 15017c478bd9Sstevel@tonic-gate (void) fclose(of); 15027c478bd9Sstevel@tonic-gate } 15037c478bd9Sstevel@tonic-gate 15047c478bd9Sstevel@tonic-gate void 15057c478bd9Sstevel@tonic-gate exit_func(cmd_t *cmd) 15067c478bd9Sstevel@tonic-gate { 15077c478bd9Sstevel@tonic-gate int arg, answer; 15087c478bd9Sstevel@tonic-gate 15097c478bd9Sstevel@tonic-gate optind = 0; 15107c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 15117c478bd9Sstevel@tonic-gate switch (arg) { 15127c478bd9Sstevel@tonic-gate case '?': 15137c478bd9Sstevel@tonic-gate longer_usage(CMD_EXIT); 15147c478bd9Sstevel@tonic-gate return; 15157c478bd9Sstevel@tonic-gate case 'F': 15167c478bd9Sstevel@tonic-gate force_exit = TRUE; 15177c478bd9Sstevel@tonic-gate break; 15187c478bd9Sstevel@tonic-gate default: 15197c478bd9Sstevel@tonic-gate short_usage(CMD_EXIT); 15207c478bd9Sstevel@tonic-gate return; 15217c478bd9Sstevel@tonic-gate } 15227c478bd9Sstevel@tonic-gate } 15237c478bd9Sstevel@tonic-gate if (optind < cmd->cmd_argc) { 15247c478bd9Sstevel@tonic-gate short_usage(CMD_EXIT); 15257c478bd9Sstevel@tonic-gate return; 15267c478bd9Sstevel@tonic-gate } 15277c478bd9Sstevel@tonic-gate 15287c478bd9Sstevel@tonic-gate if (global_scope || force_exit) { 15297c478bd9Sstevel@tonic-gate time_to_exit = TRUE; 15307c478bd9Sstevel@tonic-gate return; 15317c478bd9Sstevel@tonic-gate } 15327c478bd9Sstevel@tonic-gate 15337c478bd9Sstevel@tonic-gate answer = ask_yesno(FALSE, "Resource incomplete; really quit"); 15347c478bd9Sstevel@tonic-gate if (answer == -1) { 15357c478bd9Sstevel@tonic-gate zerr(gettext("Resource incomplete, input " 15367c478bd9Sstevel@tonic-gate "not from terminal and -F not specified:\n%s command " 15377c478bd9Sstevel@tonic-gate "ignored, but exiting anyway."), cmd_to_str(CMD_EXIT)); 15387c478bd9Sstevel@tonic-gate exit(Z_ERR); 15397c478bd9Sstevel@tonic-gate } else if (answer == 1) { 15407c478bd9Sstevel@tonic-gate time_to_exit = TRUE; 15417c478bd9Sstevel@tonic-gate } 15427c478bd9Sstevel@tonic-gate /* (answer == 0) => just return */ 15437c478bd9Sstevel@tonic-gate } 15447c478bd9Sstevel@tonic-gate 15457c478bd9Sstevel@tonic-gate static int 15467c478bd9Sstevel@tonic-gate validate_zonepath_syntax(char *path) 15477c478bd9Sstevel@tonic-gate { 15487c478bd9Sstevel@tonic-gate if (path[0] != '/') { 15497c478bd9Sstevel@tonic-gate zerr(gettext("%s is not an absolute path."), path); 15507c478bd9Sstevel@tonic-gate return (Z_ERR); 15517c478bd9Sstevel@tonic-gate } 15527c478bd9Sstevel@tonic-gate if (strcmp(path, "/") == 0) { 15537c478bd9Sstevel@tonic-gate zerr(gettext("/ is not allowed as a %s."), 15547c478bd9Sstevel@tonic-gate pt_to_str(PT_ZONEPATH)); 15557c478bd9Sstevel@tonic-gate return (Z_ERR); 15567c478bd9Sstevel@tonic-gate } 15577c478bd9Sstevel@tonic-gate return (Z_OK); 15587c478bd9Sstevel@tonic-gate } 15597c478bd9Sstevel@tonic-gate 15607c478bd9Sstevel@tonic-gate static void 15617c478bd9Sstevel@tonic-gate add_resource(cmd_t *cmd) 15627c478bd9Sstevel@tonic-gate { 15637c478bd9Sstevel@tonic-gate int type; 15647c478bd9Sstevel@tonic-gate 15657c478bd9Sstevel@tonic-gate if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 15667c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 15677c478bd9Sstevel@tonic-gate goto bad; 15687c478bd9Sstevel@tonic-gate } 15697c478bd9Sstevel@tonic-gate 15707c478bd9Sstevel@tonic-gate switch (type) { 15717c478bd9Sstevel@tonic-gate case RT_FS: 15727c478bd9Sstevel@tonic-gate bzero(&in_progress_fstab, sizeof (in_progress_fstab)); 15737c478bd9Sstevel@tonic-gate return; 15747c478bd9Sstevel@tonic-gate case RT_IPD: 1575087719fdSdp if (state_atleast(ZONE_STATE_INSTALLED)) { 15767c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s already installed; %s %s not " 15777c478bd9Sstevel@tonic-gate "allowed."), zone, cmd_to_str(CMD_ADD), 15787c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD)); 15797c478bd9Sstevel@tonic-gate goto bad; 15807c478bd9Sstevel@tonic-gate } 15817c478bd9Sstevel@tonic-gate bzero(&in_progress_ipdtab, sizeof (in_progress_ipdtab)); 15827c478bd9Sstevel@tonic-gate return; 15837c478bd9Sstevel@tonic-gate case RT_NET: 15847c478bd9Sstevel@tonic-gate bzero(&in_progress_nwiftab, sizeof (in_progress_nwiftab)); 15857c478bd9Sstevel@tonic-gate return; 15867c478bd9Sstevel@tonic-gate case RT_DEVICE: 15877c478bd9Sstevel@tonic-gate bzero(&in_progress_devtab, sizeof (in_progress_devtab)); 15887c478bd9Sstevel@tonic-gate return; 15897c478bd9Sstevel@tonic-gate case RT_RCTL: 15907c478bd9Sstevel@tonic-gate bzero(&in_progress_rctltab, sizeof (in_progress_rctltab)); 15917c478bd9Sstevel@tonic-gate return; 15927c478bd9Sstevel@tonic-gate case RT_ATTR: 15937c478bd9Sstevel@tonic-gate bzero(&in_progress_attrtab, sizeof (in_progress_attrtab)); 15947c478bd9Sstevel@tonic-gate return; 1595fa9e4066Sahrens case RT_DATASET: 1596fa9e4066Sahrens bzero(&in_progress_dstab, sizeof (in_progress_dstab)); 1597fa9e4066Sahrens return; 15987c478bd9Sstevel@tonic-gate default: 15997c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(type), Z_NO_RESOURCE_TYPE, TRUE); 16007c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 16017c478bd9Sstevel@tonic-gate usage(FALSE, HELP_RESOURCES); 16027c478bd9Sstevel@tonic-gate } 16037c478bd9Sstevel@tonic-gate bad: 16047c478bd9Sstevel@tonic-gate global_scope = TRUE; 16057c478bd9Sstevel@tonic-gate end_op = -1; 16067c478bd9Sstevel@tonic-gate } 16077c478bd9Sstevel@tonic-gate 16087c478bd9Sstevel@tonic-gate static void 16097c478bd9Sstevel@tonic-gate do_complex_rctl_val(complex_property_ptr_t cp) 16107c478bd9Sstevel@tonic-gate { 16117c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *rctlvaltab; 16127c478bd9Sstevel@tonic-gate complex_property_ptr_t cx; 16137c478bd9Sstevel@tonic-gate bool seen_priv = FALSE, seen_limit = FALSE, seen_action = FALSE; 16147c478bd9Sstevel@tonic-gate rctlblk_t *rctlblk; 16157c478bd9Sstevel@tonic-gate int err; 16167c478bd9Sstevel@tonic-gate 16177c478bd9Sstevel@tonic-gate if ((rctlvaltab = alloc_rctlvaltab()) == NULL) { 16187c478bd9Sstevel@tonic-gate zone_perror(zone, Z_NOMEM, TRUE); 16197c478bd9Sstevel@tonic-gate exit(Z_ERR); 16207c478bd9Sstevel@tonic-gate } 16217c478bd9Sstevel@tonic-gate for (cx = cp; cx != NULL; cx = cx->cp_next) { 16227c478bd9Sstevel@tonic-gate switch (cx->cp_type) { 16237c478bd9Sstevel@tonic-gate case PT_PRIV: 16247c478bd9Sstevel@tonic-gate if (seen_priv) { 16257c478bd9Sstevel@tonic-gate zerr(gettext("%s already specified"), 16267c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV)); 16277c478bd9Sstevel@tonic-gate goto bad; 16287c478bd9Sstevel@tonic-gate } 16297c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_priv, 16307c478bd9Sstevel@tonic-gate cx->cp_value, 16317c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_priv)); 16327c478bd9Sstevel@tonic-gate seen_priv = TRUE; 16337c478bd9Sstevel@tonic-gate break; 16347c478bd9Sstevel@tonic-gate case PT_LIMIT: 16357c478bd9Sstevel@tonic-gate if (seen_limit) { 16367c478bd9Sstevel@tonic-gate zerr(gettext("%s already specified"), 16377c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT)); 16387c478bd9Sstevel@tonic-gate goto bad; 16397c478bd9Sstevel@tonic-gate } 16407c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_limit, 16417c478bd9Sstevel@tonic-gate cx->cp_value, 16427c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_limit)); 16437c478bd9Sstevel@tonic-gate seen_limit = TRUE; 16447c478bd9Sstevel@tonic-gate break; 16457c478bd9Sstevel@tonic-gate case PT_ACTION: 16467c478bd9Sstevel@tonic-gate if (seen_action) { 16477c478bd9Sstevel@tonic-gate zerr(gettext("%s already specified"), 16487c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION)); 16497c478bd9Sstevel@tonic-gate goto bad; 16507c478bd9Sstevel@tonic-gate } 16517c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_action, 16527c478bd9Sstevel@tonic-gate cx->cp_value, 16537c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_action)); 16547c478bd9Sstevel@tonic-gate seen_action = TRUE; 16557c478bd9Sstevel@tonic-gate break; 16567c478bd9Sstevel@tonic-gate default: 16577c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(PT_VALUE), 16587c478bd9Sstevel@tonic-gate Z_NO_PROPERTY_TYPE, TRUE); 16597c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 16607c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 16617c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 16627c478bd9Sstevel@tonic-gate return; 16637c478bd9Sstevel@tonic-gate } 16647c478bd9Sstevel@tonic-gate } 16657c478bd9Sstevel@tonic-gate if (!seen_priv) 16667c478bd9Sstevel@tonic-gate zerr(gettext("%s not specified"), pt_to_str(PT_PRIV)); 16677c478bd9Sstevel@tonic-gate if (!seen_limit) 16687c478bd9Sstevel@tonic-gate zerr(gettext("%s not specified"), pt_to_str(PT_LIMIT)); 16697c478bd9Sstevel@tonic-gate if (!seen_action) 16707c478bd9Sstevel@tonic-gate zerr(gettext("%s not specified"), pt_to_str(PT_ACTION)); 16717c478bd9Sstevel@tonic-gate if (!seen_priv || !seen_limit || !seen_action) 16727c478bd9Sstevel@tonic-gate goto bad; 16737c478bd9Sstevel@tonic-gate rctlvaltab->zone_rctlval_next = NULL; 16747c478bd9Sstevel@tonic-gate rctlblk = alloca(rctlblk_size()); 16757c478bd9Sstevel@tonic-gate /* 16767c478bd9Sstevel@tonic-gate * Make sure the rctl value looks roughly correct; we won't know if 16777c478bd9Sstevel@tonic-gate * it's truly OK until we verify the configuration on the target 16787c478bd9Sstevel@tonic-gate * system. 16797c478bd9Sstevel@tonic-gate */ 16807c478bd9Sstevel@tonic-gate if (zonecfg_construct_rctlblk(rctlvaltab, rctlblk) != Z_OK || 16817c478bd9Sstevel@tonic-gate !zonecfg_valid_rctlblk(rctlblk)) { 16827c478bd9Sstevel@tonic-gate zerr(gettext("Invalid %s %s specification"), rt_to_str(RT_RCTL), 16837c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE)); 16847c478bd9Sstevel@tonic-gate goto bad; 16857c478bd9Sstevel@tonic-gate } 16867c478bd9Sstevel@tonic-gate err = zonecfg_add_rctl_value(&in_progress_rctltab, rctlvaltab); 16877c478bd9Sstevel@tonic-gate if (err != Z_OK) 16887c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(PT_VALUE), err, TRUE); 16897c478bd9Sstevel@tonic-gate return; 16907c478bd9Sstevel@tonic-gate 16917c478bd9Sstevel@tonic-gate bad: 16927c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 16937c478bd9Sstevel@tonic-gate } 16947c478bd9Sstevel@tonic-gate 16957c478bd9Sstevel@tonic-gate static void 16967c478bd9Sstevel@tonic-gate add_property(cmd_t *cmd) 16977c478bd9Sstevel@tonic-gate { 16987c478bd9Sstevel@tonic-gate char *prop_id; 16997c478bd9Sstevel@tonic-gate int err, res_type, prop_type; 17007c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 17017c478bd9Sstevel@tonic-gate list_property_ptr_t l; 17027c478bd9Sstevel@tonic-gate 17037c478bd9Sstevel@tonic-gate res_type = resource_scope; 17047c478bd9Sstevel@tonic-gate prop_type = cmd->cmd_prop_name[0]; 17057c478bd9Sstevel@tonic-gate if (res_type == RT_UNKNOWN || prop_type == PT_UNKNOWN) { 17067c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 17077c478bd9Sstevel@tonic-gate return; 17087c478bd9Sstevel@tonic-gate } 17097c478bd9Sstevel@tonic-gate 17107c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs != 1) { 17117c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 17127c478bd9Sstevel@tonic-gate return; 17137c478bd9Sstevel@tonic-gate } 17147c478bd9Sstevel@tonic-gate 17157c478bd9Sstevel@tonic-gate if (initialize(TRUE) != Z_OK) 17167c478bd9Sstevel@tonic-gate return; 17177c478bd9Sstevel@tonic-gate 17187c478bd9Sstevel@tonic-gate switch (res_type) { 17197c478bd9Sstevel@tonic-gate case RT_FS: 17207c478bd9Sstevel@tonic-gate if (prop_type != PT_OPTIONS) { 17217c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 17227c478bd9Sstevel@tonic-gate TRUE); 17237c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 17247c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 17257c478bd9Sstevel@tonic-gate return; 17267c478bd9Sstevel@tonic-gate } 17277c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 17287c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE && 17297c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 17307c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected here."), 17317c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_SIMPLE), 17327c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 17337c478bd9Sstevel@tonic-gate saw_error = TRUE; 17347c478bd9Sstevel@tonic-gate return; 17357c478bd9Sstevel@tonic-gate } 17367c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_SIMPLE) { 17377c478bd9Sstevel@tonic-gate if (pp->pv_simple == NULL) { 17387c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 17397c478bd9Sstevel@tonic-gate return; 17407c478bd9Sstevel@tonic-gate } 17417c478bd9Sstevel@tonic-gate prop_id = pp->pv_simple; 17427c478bd9Sstevel@tonic-gate err = zonecfg_add_fs_option(&in_progress_fstab, 17437c478bd9Sstevel@tonic-gate prop_id); 17447c478bd9Sstevel@tonic-gate if (err != Z_OK) 17457c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), err, TRUE); 17467c478bd9Sstevel@tonic-gate } else { 17477c478bd9Sstevel@tonic-gate list_property_ptr_t list; 17487c478bd9Sstevel@tonic-gate 17497c478bd9Sstevel@tonic-gate for (list = pp->pv_list; list != NULL; 17507c478bd9Sstevel@tonic-gate list = list->lp_next) { 17517c478bd9Sstevel@tonic-gate prop_id = list->lp_simple; 17527c478bd9Sstevel@tonic-gate if (prop_id == NULL) 17537c478bd9Sstevel@tonic-gate break; 17547c478bd9Sstevel@tonic-gate err = zonecfg_add_fs_option( 17557c478bd9Sstevel@tonic-gate &in_progress_fstab, prop_id); 17567c478bd9Sstevel@tonic-gate if (err != Z_OK) 17577c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), err, 17587c478bd9Sstevel@tonic-gate TRUE); 17597c478bd9Sstevel@tonic-gate } 17607c478bd9Sstevel@tonic-gate } 17617c478bd9Sstevel@tonic-gate return; 17627c478bd9Sstevel@tonic-gate case RT_RCTL: 17637c478bd9Sstevel@tonic-gate if (prop_type != PT_VALUE) { 17647c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 17657c478bd9Sstevel@tonic-gate TRUE); 17667c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 17677c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 17687c478bd9Sstevel@tonic-gate return; 17697c478bd9Sstevel@tonic-gate } 17707c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 17717c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_COMPLEX && 17727c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 17737c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected here."), 17747c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_COMPLEX), 17757c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 17767c478bd9Sstevel@tonic-gate saw_error = TRUE; 17777c478bd9Sstevel@tonic-gate return; 17787c478bd9Sstevel@tonic-gate } 17797c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_COMPLEX) { 17807c478bd9Sstevel@tonic-gate do_complex_rctl_val(pp->pv_complex); 17817c478bd9Sstevel@tonic-gate return; 17827c478bd9Sstevel@tonic-gate } 17837c478bd9Sstevel@tonic-gate for (l = pp->pv_list; l != NULL; l = l->lp_next) 17847c478bd9Sstevel@tonic-gate do_complex_rctl_val(l->lp_complex); 17857c478bd9Sstevel@tonic-gate return; 17867c478bd9Sstevel@tonic-gate default: 17877c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, TRUE); 17887c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 17897c478bd9Sstevel@tonic-gate usage(FALSE, HELP_RESOURCES); 17907c478bd9Sstevel@tonic-gate return; 17917c478bd9Sstevel@tonic-gate } 17927c478bd9Sstevel@tonic-gate } 17937c478bd9Sstevel@tonic-gate 17947c478bd9Sstevel@tonic-gate void 17957c478bd9Sstevel@tonic-gate add_func(cmd_t *cmd) 17967c478bd9Sstevel@tonic-gate { 17977c478bd9Sstevel@tonic-gate int arg; 17987c478bd9Sstevel@tonic-gate 17997c478bd9Sstevel@tonic-gate assert(cmd != NULL); 18007c478bd9Sstevel@tonic-gate 18017c478bd9Sstevel@tonic-gate optind = 0; 18027c478bd9Sstevel@tonic-gate if ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 18037c478bd9Sstevel@tonic-gate switch (arg) { 18047c478bd9Sstevel@tonic-gate case '?': 18057c478bd9Sstevel@tonic-gate longer_usage(CMD_ADD); 18067c478bd9Sstevel@tonic-gate return; 18077c478bd9Sstevel@tonic-gate default: 18087c478bd9Sstevel@tonic-gate short_usage(CMD_ADD); 18097c478bd9Sstevel@tonic-gate return; 18107c478bd9Sstevel@tonic-gate } 18117c478bd9Sstevel@tonic-gate } 18127c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 18137c478bd9Sstevel@tonic-gate short_usage(CMD_ADD); 18147c478bd9Sstevel@tonic-gate return; 18157c478bd9Sstevel@tonic-gate } 18167c478bd9Sstevel@tonic-gate 18177c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_ADD)) 18187c478bd9Sstevel@tonic-gate return; 18197c478bd9Sstevel@tonic-gate 18207c478bd9Sstevel@tonic-gate if (initialize(TRUE) != Z_OK) 18217c478bd9Sstevel@tonic-gate return; 18227c478bd9Sstevel@tonic-gate if (global_scope) { 18237c478bd9Sstevel@tonic-gate global_scope = FALSE; 18247c478bd9Sstevel@tonic-gate resource_scope = cmd->cmd_res_type; 18257c478bd9Sstevel@tonic-gate end_op = CMD_ADD; 18267c478bd9Sstevel@tonic-gate add_resource(cmd); 18277c478bd9Sstevel@tonic-gate } else 18287c478bd9Sstevel@tonic-gate add_property(cmd); 18297c478bd9Sstevel@tonic-gate } 18307c478bd9Sstevel@tonic-gate 1831087719fdSdp /* 1832087719fdSdp * This routine has an unusual implementation, because it tries very 1833087719fdSdp * hard to succeed in the face of a variety of failure modes. 1834087719fdSdp * The most common and most vexing occurs when the index file and 1835087719fdSdp * the /etc/zones/<zonename.xml> file are not both present. In 1836087719fdSdp * this case, delete must eradicate as much of the zone state as is left 1837087719fdSdp * so that the user can later create a new zone with the same name. 1838087719fdSdp */ 18397c478bd9Sstevel@tonic-gate void 18407c478bd9Sstevel@tonic-gate delete_func(cmd_t *cmd) 18417c478bd9Sstevel@tonic-gate { 18427c478bd9Sstevel@tonic-gate int err, arg, answer; 18437c478bd9Sstevel@tonic-gate char line[ZONENAME_MAX + 128]; /* enough to ask a question */ 18447c478bd9Sstevel@tonic-gate bool force = FALSE; 18457c478bd9Sstevel@tonic-gate 18467c478bd9Sstevel@tonic-gate optind = 0; 18477c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 18487c478bd9Sstevel@tonic-gate switch (arg) { 18497c478bd9Sstevel@tonic-gate case '?': 18507c478bd9Sstevel@tonic-gate longer_usage(CMD_DELETE); 18517c478bd9Sstevel@tonic-gate return; 18527c478bd9Sstevel@tonic-gate case 'F': 18537c478bd9Sstevel@tonic-gate force = TRUE; 18547c478bd9Sstevel@tonic-gate break; 18557c478bd9Sstevel@tonic-gate default: 18567c478bd9Sstevel@tonic-gate short_usage(CMD_DELETE); 18577c478bd9Sstevel@tonic-gate return; 18587c478bd9Sstevel@tonic-gate } 18597c478bd9Sstevel@tonic-gate } 18607c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 18617c478bd9Sstevel@tonic-gate short_usage(CMD_DELETE); 18627c478bd9Sstevel@tonic-gate return; 18637c478bd9Sstevel@tonic-gate } 18647c478bd9Sstevel@tonic-gate 18657c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_DELETE)) 18667c478bd9Sstevel@tonic-gate return; 18677c478bd9Sstevel@tonic-gate 1868087719fdSdp if (!force) { 1869087719fdSdp /* 1870087719fdSdp * Initialize sets up the global called "handle" and warns the 1871087719fdSdp * user if the zone is not configured. In force mode, we don't 1872087719fdSdp * trust that evaluation, and hence skip it. (We don't need the 1873087719fdSdp * handle to be loaded anyway, since zonecfg_destroy is done by 1874087719fdSdp * zonename). However, we also have to take care to emulate the 1875087719fdSdp * messages spit out by initialize; see below. 1876087719fdSdp */ 18777c478bd9Sstevel@tonic-gate if (initialize(TRUE) != Z_OK) 18787c478bd9Sstevel@tonic-gate return; 18797c478bd9Sstevel@tonic-gate 18807c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 18817c478bd9Sstevel@tonic-gate gettext("Are you sure you want to delete zone %s"), zone); 18827c478bd9Sstevel@tonic-gate if ((answer = ask_yesno(FALSE, line)) == -1) { 1883087719fdSdp zerr(gettext("Input not from terminal and -F not " 1884087719fdSdp "specified:\n%s command ignored, exiting."), 1885087719fdSdp cmd_to_str(CMD_DELETE)); 18867c478bd9Sstevel@tonic-gate exit(Z_ERR); 18877c478bd9Sstevel@tonic-gate } 18887c478bd9Sstevel@tonic-gate if (answer != 1) 18897c478bd9Sstevel@tonic-gate return; 18907c478bd9Sstevel@tonic-gate } 18917c478bd9Sstevel@tonic-gate 1892087719fdSdp if ((err = zonecfg_destroy(zone, force)) != Z_OK) { 1893087719fdSdp if ((err == Z_BAD_ZONE_STATE) && !force) { 1894087719fdSdp zerr(gettext("Zone %s not in %s state; %s not " 1895087719fdSdp "allowed. Use -F to force %s."), 1896087719fdSdp zone, zone_state_str(ZONE_STATE_CONFIGURED), 1897087719fdSdp cmd_to_str(CMD_DELETE), cmd_to_str(CMD_DELETE)); 1898087719fdSdp } else { 18997c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 19007c478bd9Sstevel@tonic-gate } 1901087719fdSdp } 19027c478bd9Sstevel@tonic-gate need_to_commit = FALSE; 1903087719fdSdp 1904087719fdSdp /* 1905087719fdSdp * Emulate initialize's messaging; if there wasn't a valid handle to 1906087719fdSdp * begin with, then user had typed delete (or delete -F) multiple 1907087719fdSdp * times. So we emit a message. 1908087719fdSdp * 1909087719fdSdp * We only do this in the 'force' case because normally, initialize() 1910087719fdSdp * takes care of this for us. 1911087719fdSdp */ 1912087719fdSdp if (force && zonecfg_check_handle(handle) != Z_OK && interactive_mode) 1913087719fdSdp (void) printf(gettext("Use '%s' to begin " 1914087719fdSdp "configuring a new zone.\n"), cmd_to_str(CMD_CREATE)); 19157c478bd9Sstevel@tonic-gate 19167c478bd9Sstevel@tonic-gate /* 19177c478bd9Sstevel@tonic-gate * Time for a new handle: finish the old one off first 19187c478bd9Sstevel@tonic-gate * then get a new one properly to avoid leaks. 19197c478bd9Sstevel@tonic-gate */ 1920087719fdSdp if (got_handle) { 19217c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 19227c478bd9Sstevel@tonic-gate if ((handle = zonecfg_init_handle()) == NULL) { 19237c478bd9Sstevel@tonic-gate zone_perror(execname, Z_NOMEM, TRUE); 19247c478bd9Sstevel@tonic-gate exit(Z_ERR); 19257c478bd9Sstevel@tonic-gate } 19267c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_handle(zone, handle)) != Z_OK) { 19277c478bd9Sstevel@tonic-gate /* If there was no zone before, that's OK */ 19287c478bd9Sstevel@tonic-gate if (err != Z_NO_ZONE) 19297c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 19307c478bd9Sstevel@tonic-gate got_handle = FALSE; 19317c478bd9Sstevel@tonic-gate } 19327c478bd9Sstevel@tonic-gate } 1933087719fdSdp } 19347c478bd9Sstevel@tonic-gate 19357c478bd9Sstevel@tonic-gate static int 19367c478bd9Sstevel@tonic-gate fill_in_fstab(cmd_t *cmd, struct zone_fstab *fstab, bool fill_in_only) 19377c478bd9Sstevel@tonic-gate { 19387c478bd9Sstevel@tonic-gate int err, i; 19397c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 19407c478bd9Sstevel@tonic-gate 19417c478bd9Sstevel@tonic-gate if ((err = initialize(TRUE)) != Z_OK) 19427c478bd9Sstevel@tonic-gate return (err); 19437c478bd9Sstevel@tonic-gate 1944e193d1e6Svp157776 bzero(fstab, sizeof (*fstab)); 19457c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 19467c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 19477c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 19487c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 19497c478bd9Sstevel@tonic-gate saw_error = TRUE; 19507c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 19517c478bd9Sstevel@tonic-gate } 19527c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 19537c478bd9Sstevel@tonic-gate case PT_DIR: 19547c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_dir, pp->pv_simple, 19557c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_dir)); 19567c478bd9Sstevel@tonic-gate break; 19577c478bd9Sstevel@tonic-gate case PT_SPECIAL: 19587c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_special, pp->pv_simple, 19597c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_special)); 19607c478bd9Sstevel@tonic-gate break; 19617c478bd9Sstevel@tonic-gate case PT_RAW: 19627c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_raw, pp->pv_simple, 19637c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_raw)); 19647c478bd9Sstevel@tonic-gate break; 19657c478bd9Sstevel@tonic-gate case PT_TYPE: 19667c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_type, pp->pv_simple, 19677c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_type)); 19687c478bd9Sstevel@tonic-gate break; 19697c478bd9Sstevel@tonic-gate default: 19707c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 19717c478bd9Sstevel@tonic-gate Z_NO_PROPERTY_TYPE, TRUE); 19727c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 19737c478bd9Sstevel@tonic-gate } 19747c478bd9Sstevel@tonic-gate } 19757c478bd9Sstevel@tonic-gate if (fill_in_only) 19767c478bd9Sstevel@tonic-gate return (Z_OK); 19777c478bd9Sstevel@tonic-gate return (zonecfg_lookup_filesystem(handle, fstab)); 19787c478bd9Sstevel@tonic-gate } 19797c478bd9Sstevel@tonic-gate 19807c478bd9Sstevel@tonic-gate static int 19817c478bd9Sstevel@tonic-gate fill_in_ipdtab(cmd_t *cmd, struct zone_fstab *ipdtab, bool fill_in_only) 19827c478bd9Sstevel@tonic-gate { 19837c478bd9Sstevel@tonic-gate int err, i; 19847c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 19857c478bd9Sstevel@tonic-gate 19867c478bd9Sstevel@tonic-gate if ((err = initialize(TRUE)) != Z_OK) 19877c478bd9Sstevel@tonic-gate return (err); 19887c478bd9Sstevel@tonic-gate 1989e193d1e6Svp157776 bzero(ipdtab, sizeof (*ipdtab)); 19907c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 19917c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 19927c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 19937c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 19947c478bd9Sstevel@tonic-gate saw_error = TRUE; 19957c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 19967c478bd9Sstevel@tonic-gate } 19977c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 19987c478bd9Sstevel@tonic-gate case PT_DIR: 19997c478bd9Sstevel@tonic-gate (void) strlcpy(ipdtab->zone_fs_dir, pp->pv_simple, 20007c478bd9Sstevel@tonic-gate sizeof (ipdtab->zone_fs_dir)); 20017c478bd9Sstevel@tonic-gate break; 20027c478bd9Sstevel@tonic-gate default: 20037c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 20047c478bd9Sstevel@tonic-gate Z_NO_PROPERTY_TYPE, TRUE); 20057c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 20067c478bd9Sstevel@tonic-gate } 20077c478bd9Sstevel@tonic-gate } 20087c478bd9Sstevel@tonic-gate if (fill_in_only) 20097c478bd9Sstevel@tonic-gate return (Z_OK); 20107c478bd9Sstevel@tonic-gate return (zonecfg_lookup_ipd(handle, ipdtab)); 20117c478bd9Sstevel@tonic-gate } 20127c478bd9Sstevel@tonic-gate 20137c478bd9Sstevel@tonic-gate static int 20147c478bd9Sstevel@tonic-gate fill_in_nwiftab(cmd_t *cmd, struct zone_nwiftab *nwiftab, bool fill_in_only) 20157c478bd9Sstevel@tonic-gate { 20167c478bd9Sstevel@tonic-gate int err, i; 20177c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 20187c478bd9Sstevel@tonic-gate 20197c478bd9Sstevel@tonic-gate if ((err = initialize(TRUE)) != Z_OK) 20207c478bd9Sstevel@tonic-gate return (err); 20217c478bd9Sstevel@tonic-gate 2022e193d1e6Svp157776 bzero(nwiftab, sizeof (*nwiftab)); 20237c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 20247c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 20257c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 20267c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 20277c478bd9Sstevel@tonic-gate saw_error = TRUE; 20287c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 20297c478bd9Sstevel@tonic-gate } 20307c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 20317c478bd9Sstevel@tonic-gate case PT_ADDRESS: 20327c478bd9Sstevel@tonic-gate (void) strlcpy(nwiftab->zone_nwif_address, 20337c478bd9Sstevel@tonic-gate pp->pv_simple, sizeof (nwiftab->zone_nwif_address)); 20347c478bd9Sstevel@tonic-gate break; 20357c478bd9Sstevel@tonic-gate case PT_PHYSICAL: 20367c478bd9Sstevel@tonic-gate (void) strlcpy(nwiftab->zone_nwif_physical, 20377c478bd9Sstevel@tonic-gate pp->pv_simple, 20387c478bd9Sstevel@tonic-gate sizeof (nwiftab->zone_nwif_physical)); 20397c478bd9Sstevel@tonic-gate break; 20407c478bd9Sstevel@tonic-gate default: 20417c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 20427c478bd9Sstevel@tonic-gate Z_NO_PROPERTY_TYPE, TRUE); 20437c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 20447c478bd9Sstevel@tonic-gate } 20457c478bd9Sstevel@tonic-gate } 20467c478bd9Sstevel@tonic-gate if (fill_in_only) 20477c478bd9Sstevel@tonic-gate return (Z_OK); 20487c478bd9Sstevel@tonic-gate err = zonecfg_lookup_nwif(handle, nwiftab); 20497c478bd9Sstevel@tonic-gate return (err); 20507c478bd9Sstevel@tonic-gate } 20517c478bd9Sstevel@tonic-gate 20527c478bd9Sstevel@tonic-gate static int 20537c478bd9Sstevel@tonic-gate fill_in_devtab(cmd_t *cmd, struct zone_devtab *devtab, bool fill_in_only) 20547c478bd9Sstevel@tonic-gate { 20557c478bd9Sstevel@tonic-gate int err, i; 20567c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 20577c478bd9Sstevel@tonic-gate 20587c478bd9Sstevel@tonic-gate if ((err = initialize(TRUE)) != Z_OK) 20597c478bd9Sstevel@tonic-gate return (err); 20607c478bd9Sstevel@tonic-gate 2061e193d1e6Svp157776 bzero(devtab, sizeof (*devtab)); 20627c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 20637c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 20647c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 20657c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 20667c478bd9Sstevel@tonic-gate saw_error = TRUE; 20677c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 20687c478bd9Sstevel@tonic-gate } 20697c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 20707c478bd9Sstevel@tonic-gate case PT_MATCH: 20717c478bd9Sstevel@tonic-gate (void) strlcpy(devtab->zone_dev_match, pp->pv_simple, 20727c478bd9Sstevel@tonic-gate sizeof (devtab->zone_dev_match)); 20737c478bd9Sstevel@tonic-gate break; 20747c478bd9Sstevel@tonic-gate default: 20757c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 20767c478bd9Sstevel@tonic-gate Z_NO_PROPERTY_TYPE, TRUE); 20777c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 20787c478bd9Sstevel@tonic-gate } 20797c478bd9Sstevel@tonic-gate } 20807c478bd9Sstevel@tonic-gate if (fill_in_only) 20817c478bd9Sstevel@tonic-gate return (Z_OK); 20827c478bd9Sstevel@tonic-gate err = zonecfg_lookup_dev(handle, devtab); 20837c478bd9Sstevel@tonic-gate return (err); 20847c478bd9Sstevel@tonic-gate } 20857c478bd9Sstevel@tonic-gate 20867c478bd9Sstevel@tonic-gate static int 20877c478bd9Sstevel@tonic-gate fill_in_rctltab(cmd_t *cmd, struct zone_rctltab *rctltab, bool fill_in_only) 20887c478bd9Sstevel@tonic-gate { 20897c478bd9Sstevel@tonic-gate int err, i; 20907c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 20917c478bd9Sstevel@tonic-gate 20927c478bd9Sstevel@tonic-gate if ((err = initialize(TRUE)) != Z_OK) 20937c478bd9Sstevel@tonic-gate return (err); 20947c478bd9Sstevel@tonic-gate 2095e193d1e6Svp157776 bzero(rctltab, sizeof (*rctltab)); 20967c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 20977c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 20987c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 20997c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 21007c478bd9Sstevel@tonic-gate saw_error = TRUE; 21017c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 21027c478bd9Sstevel@tonic-gate } 21037c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 21047c478bd9Sstevel@tonic-gate case PT_NAME: 21057c478bd9Sstevel@tonic-gate (void) strlcpy(rctltab->zone_rctl_name, pp->pv_simple, 21067c478bd9Sstevel@tonic-gate sizeof (rctltab->zone_rctl_name)); 21077c478bd9Sstevel@tonic-gate break; 21087c478bd9Sstevel@tonic-gate default: 21097c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 21107c478bd9Sstevel@tonic-gate Z_NO_PROPERTY_TYPE, TRUE); 21117c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 21127c478bd9Sstevel@tonic-gate } 21137c478bd9Sstevel@tonic-gate } 21147c478bd9Sstevel@tonic-gate if (fill_in_only) 21157c478bd9Sstevel@tonic-gate return (Z_OK); 21167c478bd9Sstevel@tonic-gate err = zonecfg_lookup_rctl(handle, rctltab); 21177c478bd9Sstevel@tonic-gate return (err); 21187c478bd9Sstevel@tonic-gate } 21197c478bd9Sstevel@tonic-gate 21207c478bd9Sstevel@tonic-gate static int 21217c478bd9Sstevel@tonic-gate fill_in_attrtab(cmd_t *cmd, struct zone_attrtab *attrtab, bool fill_in_only) 21227c478bd9Sstevel@tonic-gate { 21237c478bd9Sstevel@tonic-gate int err, i; 21247c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 21257c478bd9Sstevel@tonic-gate 21267c478bd9Sstevel@tonic-gate if ((err = initialize(TRUE)) != Z_OK) 21277c478bd9Sstevel@tonic-gate return (err); 21287c478bd9Sstevel@tonic-gate 2129e193d1e6Svp157776 bzero(attrtab, sizeof (*attrtab)); 21307c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 21317c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 21327c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 21337c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 21347c478bd9Sstevel@tonic-gate saw_error = TRUE; 21357c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 21367c478bd9Sstevel@tonic-gate } 21377c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 21387c478bd9Sstevel@tonic-gate case PT_NAME: 21397c478bd9Sstevel@tonic-gate (void) strlcpy(attrtab->zone_attr_name, pp->pv_simple, 21407c478bd9Sstevel@tonic-gate sizeof (attrtab->zone_attr_name)); 21417c478bd9Sstevel@tonic-gate break; 21427c478bd9Sstevel@tonic-gate case PT_TYPE: 21437c478bd9Sstevel@tonic-gate (void) strlcpy(attrtab->zone_attr_type, pp->pv_simple, 21447c478bd9Sstevel@tonic-gate sizeof (attrtab->zone_attr_type)); 21457c478bd9Sstevel@tonic-gate break; 21467c478bd9Sstevel@tonic-gate case PT_VALUE: 21477c478bd9Sstevel@tonic-gate (void) strlcpy(attrtab->zone_attr_value, pp->pv_simple, 21487c478bd9Sstevel@tonic-gate sizeof (attrtab->zone_attr_value)); 21497c478bd9Sstevel@tonic-gate break; 21507c478bd9Sstevel@tonic-gate default: 21517c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 21527c478bd9Sstevel@tonic-gate Z_NO_PROPERTY_TYPE, TRUE); 21537c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 21547c478bd9Sstevel@tonic-gate } 21557c478bd9Sstevel@tonic-gate } 21567c478bd9Sstevel@tonic-gate if (fill_in_only) 21577c478bd9Sstevel@tonic-gate return (Z_OK); 21587c478bd9Sstevel@tonic-gate err = zonecfg_lookup_attr(handle, attrtab); 21597c478bd9Sstevel@tonic-gate return (err); 21607c478bd9Sstevel@tonic-gate } 21617c478bd9Sstevel@tonic-gate 2162fa9e4066Sahrens static int 2163fa9e4066Sahrens fill_in_dstab(cmd_t *cmd, struct zone_dstab *dstab, bool fill_in_only) 2164fa9e4066Sahrens { 2165fa9e4066Sahrens int err, i; 2166fa9e4066Sahrens property_value_ptr_t pp; 2167fa9e4066Sahrens 2168fa9e4066Sahrens if ((err = initialize(TRUE)) != Z_OK) 2169fa9e4066Sahrens return (err); 2170fa9e4066Sahrens 2171fa9e4066Sahrens dstab->zone_dataset_name[0] = '\0'; 2172fa9e4066Sahrens for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 2173fa9e4066Sahrens pp = cmd->cmd_property_ptr[i]; 2174fa9e4066Sahrens if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 2175fa9e4066Sahrens zerr(gettext("A simple value was expected here.")); 2176fa9e4066Sahrens saw_error = TRUE; 2177fa9e4066Sahrens return (Z_INSUFFICIENT_SPEC); 2178fa9e4066Sahrens } 2179fa9e4066Sahrens switch (cmd->cmd_prop_name[i]) { 2180fa9e4066Sahrens case PT_NAME: 2181fa9e4066Sahrens (void) strlcpy(dstab->zone_dataset_name, pp->pv_simple, 2182fa9e4066Sahrens sizeof (dstab->zone_dataset_name)); 2183fa9e4066Sahrens break; 2184fa9e4066Sahrens default: 2185fa9e4066Sahrens zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2186fa9e4066Sahrens Z_NO_PROPERTY_TYPE, TRUE); 2187fa9e4066Sahrens return (Z_INSUFFICIENT_SPEC); 2188fa9e4066Sahrens } 2189fa9e4066Sahrens } 2190fa9e4066Sahrens if (fill_in_only) 2191fa9e4066Sahrens return (Z_OK); 2192fa9e4066Sahrens return (zonecfg_lookup_ds(handle, dstab)); 2193fa9e4066Sahrens } 2194fa9e4066Sahrens 21957c478bd9Sstevel@tonic-gate static void 21967c478bd9Sstevel@tonic-gate remove_resource(cmd_t *cmd) 21977c478bd9Sstevel@tonic-gate { 21987c478bd9Sstevel@tonic-gate int err, type; 21997c478bd9Sstevel@tonic-gate struct zone_fstab fstab; 22007c478bd9Sstevel@tonic-gate struct zone_nwiftab nwiftab; 22017c478bd9Sstevel@tonic-gate struct zone_devtab devtab; 22027c478bd9Sstevel@tonic-gate struct zone_attrtab attrtab; 22037c478bd9Sstevel@tonic-gate struct zone_rctltab rctltab; 2204fa9e4066Sahrens struct zone_dstab dstab; 22057c478bd9Sstevel@tonic-gate 22067c478bd9Sstevel@tonic-gate if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 22077c478bd9Sstevel@tonic-gate long_usage(CMD_REMOVE, TRUE); 22087c478bd9Sstevel@tonic-gate return; 22097c478bd9Sstevel@tonic-gate } 22107c478bd9Sstevel@tonic-gate 22117c478bd9Sstevel@tonic-gate if (initialize(TRUE) != Z_OK) 22127c478bd9Sstevel@tonic-gate return; 22137c478bd9Sstevel@tonic-gate 22147c478bd9Sstevel@tonic-gate switch (type) { 22157c478bd9Sstevel@tonic-gate case RT_FS: 22167c478bd9Sstevel@tonic-gate if ((err = fill_in_fstab(cmd, &fstab, FALSE)) != Z_OK) { 22177c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_FS, err, TRUE); 22187c478bd9Sstevel@tonic-gate return; 22197c478bd9Sstevel@tonic-gate } 22207c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_filesystem(handle, &fstab)) != Z_OK) 22217c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_FS, err, TRUE); 22227c478bd9Sstevel@tonic-gate else 22237c478bd9Sstevel@tonic-gate need_to_commit = TRUE; 22247c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(fstab.zone_fs_options); 22257c478bd9Sstevel@tonic-gate return; 22267c478bd9Sstevel@tonic-gate case RT_IPD: 2227087719fdSdp if (state_atleast(ZONE_STATE_INSTALLED)) { 22287c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s already installed; %s %s not " 22297c478bd9Sstevel@tonic-gate "allowed."), zone, cmd_to_str(CMD_REMOVE), 22307c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD)); 22317c478bd9Sstevel@tonic-gate return; 22327c478bd9Sstevel@tonic-gate } 22337c478bd9Sstevel@tonic-gate if ((err = fill_in_ipdtab(cmd, &fstab, FALSE)) != Z_OK) { 22347c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_IPD, err, TRUE); 22357c478bd9Sstevel@tonic-gate return; 22367c478bd9Sstevel@tonic-gate } 22377c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_ipd(handle, &fstab)) != Z_OK) 22387c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_IPD, err, TRUE); 22397c478bd9Sstevel@tonic-gate else 22407c478bd9Sstevel@tonic-gate need_to_commit = TRUE; 22417c478bd9Sstevel@tonic-gate return; 22427c478bd9Sstevel@tonic-gate case RT_NET: 22437c478bd9Sstevel@tonic-gate if ((err = fill_in_nwiftab(cmd, &nwiftab, FALSE)) != Z_OK) { 22447c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_NET, err, TRUE); 22457c478bd9Sstevel@tonic-gate return; 22467c478bd9Sstevel@tonic-gate } 22477c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_nwif(handle, &nwiftab)) != Z_OK) 22487c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_NET, err, TRUE); 22497c478bd9Sstevel@tonic-gate else 22507c478bd9Sstevel@tonic-gate need_to_commit = TRUE; 22517c478bd9Sstevel@tonic-gate return; 22527c478bd9Sstevel@tonic-gate case RT_DEVICE: 22537c478bd9Sstevel@tonic-gate if ((err = fill_in_devtab(cmd, &devtab, FALSE)) != Z_OK) { 22547c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_DEVICE, err, TRUE); 22557c478bd9Sstevel@tonic-gate return; 22567c478bd9Sstevel@tonic-gate } 22577c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_dev(handle, &devtab)) != Z_OK) 22587c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_DEVICE, err, TRUE); 22597c478bd9Sstevel@tonic-gate else 22607c478bd9Sstevel@tonic-gate need_to_commit = TRUE; 22617c478bd9Sstevel@tonic-gate return; 22627c478bd9Sstevel@tonic-gate case RT_RCTL: 22637c478bd9Sstevel@tonic-gate if ((err = fill_in_rctltab(cmd, &rctltab, FALSE)) != Z_OK) { 22647c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_RCTL, err, TRUE); 22657c478bd9Sstevel@tonic-gate return; 22667c478bd9Sstevel@tonic-gate } 22677c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_rctl(handle, &rctltab)) != Z_OK) 22687c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_RCTL, err, TRUE); 22697c478bd9Sstevel@tonic-gate else 22707c478bd9Sstevel@tonic-gate need_to_commit = TRUE; 22717c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr); 22727c478bd9Sstevel@tonic-gate return; 22737c478bd9Sstevel@tonic-gate case RT_ATTR: 22747c478bd9Sstevel@tonic-gate if ((err = fill_in_attrtab(cmd, &attrtab, FALSE)) != Z_OK) { 22757c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_ATTR, err, TRUE); 22767c478bd9Sstevel@tonic-gate return; 22777c478bd9Sstevel@tonic-gate } 22787c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_attr(handle, &attrtab)) != Z_OK) 22797c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_ATTR, err, TRUE); 22807c478bd9Sstevel@tonic-gate else 22817c478bd9Sstevel@tonic-gate need_to_commit = TRUE; 22827c478bd9Sstevel@tonic-gate return; 2283fa9e4066Sahrens case RT_DATASET: 2284fa9e4066Sahrens if ((err = fill_in_dstab(cmd, &dstab, FALSE)) != Z_OK) { 2285fa9e4066Sahrens z_cmd_rt_perror(CMD_REMOVE, RT_DATASET, err, TRUE); 2286fa9e4066Sahrens return; 2287fa9e4066Sahrens } 2288fa9e4066Sahrens if ((err = zonecfg_delete_ds(handle, &dstab)) != Z_OK) 2289fa9e4066Sahrens z_cmd_rt_perror(CMD_REMOVE, RT_DATASET, err, TRUE); 2290fa9e4066Sahrens else 2291fa9e4066Sahrens need_to_commit = TRUE; 2292fa9e4066Sahrens return; 22937c478bd9Sstevel@tonic-gate default: 22947c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(type), Z_NO_RESOURCE_TYPE, TRUE); 22957c478bd9Sstevel@tonic-gate long_usage(CMD_REMOVE, TRUE); 22967c478bd9Sstevel@tonic-gate usage(FALSE, HELP_RESOURCES); 22977c478bd9Sstevel@tonic-gate return; 22987c478bd9Sstevel@tonic-gate } 22997c478bd9Sstevel@tonic-gate } 23007c478bd9Sstevel@tonic-gate 23017c478bd9Sstevel@tonic-gate static void 23027c478bd9Sstevel@tonic-gate remove_property(cmd_t *cmd) 23037c478bd9Sstevel@tonic-gate { 23047c478bd9Sstevel@tonic-gate char *prop_id; 23057c478bd9Sstevel@tonic-gate int err, res_type, prop_type; 23067c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 23077c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *rctlvaltab; 23087c478bd9Sstevel@tonic-gate complex_property_ptr_t cx; 23097c478bd9Sstevel@tonic-gate 23107c478bd9Sstevel@tonic-gate res_type = resource_scope; 23117c478bd9Sstevel@tonic-gate prop_type = cmd->cmd_prop_name[0]; 23127c478bd9Sstevel@tonic-gate if (res_type == RT_UNKNOWN || prop_type == PT_UNKNOWN) { 23137c478bd9Sstevel@tonic-gate long_usage(CMD_REMOVE, TRUE); 23147c478bd9Sstevel@tonic-gate return; 23157c478bd9Sstevel@tonic-gate } 23167c478bd9Sstevel@tonic-gate 23177c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs != 1) { 23187c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 23197c478bd9Sstevel@tonic-gate return; 23207c478bd9Sstevel@tonic-gate } 23217c478bd9Sstevel@tonic-gate 23227c478bd9Sstevel@tonic-gate if (initialize(TRUE) != Z_OK) 23237c478bd9Sstevel@tonic-gate return; 23247c478bd9Sstevel@tonic-gate 23257c478bd9Sstevel@tonic-gate switch (res_type) { 23267c478bd9Sstevel@tonic-gate case RT_FS: 23277c478bd9Sstevel@tonic-gate if (prop_type != PT_OPTIONS) { 23287c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 23297c478bd9Sstevel@tonic-gate TRUE); 23307c478bd9Sstevel@tonic-gate long_usage(CMD_REMOVE, TRUE); 23317c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 23327c478bd9Sstevel@tonic-gate return; 23337c478bd9Sstevel@tonic-gate } 23347c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 23357c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_COMPLEX) { 23367c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected here."), 23377c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_SIMPLE), 23387c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 23397c478bd9Sstevel@tonic-gate saw_error = TRUE; 23407c478bd9Sstevel@tonic-gate return; 23417c478bd9Sstevel@tonic-gate } 23427c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_SIMPLE) { 23437c478bd9Sstevel@tonic-gate if (pp->pv_simple == NULL) { 23447c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 23457c478bd9Sstevel@tonic-gate return; 23467c478bd9Sstevel@tonic-gate } 23477c478bd9Sstevel@tonic-gate prop_id = pp->pv_simple; 23487c478bd9Sstevel@tonic-gate err = zonecfg_remove_fs_option(&in_progress_fstab, 23497c478bd9Sstevel@tonic-gate prop_id); 23507c478bd9Sstevel@tonic-gate if (err != Z_OK) 23517c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), err, TRUE); 23527c478bd9Sstevel@tonic-gate } else { 23537c478bd9Sstevel@tonic-gate list_property_ptr_t list; 23547c478bd9Sstevel@tonic-gate 23557c478bd9Sstevel@tonic-gate for (list = pp->pv_list; list != NULL; 23567c478bd9Sstevel@tonic-gate list = list->lp_next) { 23577c478bd9Sstevel@tonic-gate prop_id = list->lp_simple; 23587c478bd9Sstevel@tonic-gate if (prop_id == NULL) 23597c478bd9Sstevel@tonic-gate break; 23607c478bd9Sstevel@tonic-gate err = zonecfg_remove_fs_option( 23617c478bd9Sstevel@tonic-gate &in_progress_fstab, prop_id); 23627c478bd9Sstevel@tonic-gate if (err != Z_OK) 23637c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), err, 23647c478bd9Sstevel@tonic-gate TRUE); 23657c478bd9Sstevel@tonic-gate } 23667c478bd9Sstevel@tonic-gate } 23677c478bd9Sstevel@tonic-gate return; 23687c478bd9Sstevel@tonic-gate case RT_RCTL: 23697c478bd9Sstevel@tonic-gate if (prop_type != PT_VALUE) { 23707c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 23717c478bd9Sstevel@tonic-gate TRUE); 23727c478bd9Sstevel@tonic-gate long_usage(CMD_REMOVE, TRUE); 23737c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 23747c478bd9Sstevel@tonic-gate return; 23757c478bd9Sstevel@tonic-gate } 23767c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 23777c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_COMPLEX) { 23787c478bd9Sstevel@tonic-gate zerr(gettext("A %s value was expected here."), 23797c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_COMPLEX)); 23807c478bd9Sstevel@tonic-gate saw_error = TRUE; 23817c478bd9Sstevel@tonic-gate return; 23827c478bd9Sstevel@tonic-gate } 23837c478bd9Sstevel@tonic-gate if ((rctlvaltab = alloc_rctlvaltab()) == NULL) { 23847c478bd9Sstevel@tonic-gate zone_perror(zone, Z_NOMEM, TRUE); 23857c478bd9Sstevel@tonic-gate exit(Z_ERR); 23867c478bd9Sstevel@tonic-gate } 23877c478bd9Sstevel@tonic-gate for (cx = pp->pv_complex; cx != NULL; cx = cx->cp_next) { 23887c478bd9Sstevel@tonic-gate switch (cx->cp_type) { 23897c478bd9Sstevel@tonic-gate case PT_PRIV: 23907c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_priv, 23917c478bd9Sstevel@tonic-gate cx->cp_value, 23927c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_priv)); 23937c478bd9Sstevel@tonic-gate break; 23947c478bd9Sstevel@tonic-gate case PT_LIMIT: 23957c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_limit, 23967c478bd9Sstevel@tonic-gate cx->cp_value, 23977c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_limit)); 23987c478bd9Sstevel@tonic-gate break; 23997c478bd9Sstevel@tonic-gate case PT_ACTION: 24007c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_action, 24017c478bd9Sstevel@tonic-gate cx->cp_value, 24027c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_action)); 24037c478bd9Sstevel@tonic-gate break; 24047c478bd9Sstevel@tonic-gate default: 24057c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), 24067c478bd9Sstevel@tonic-gate Z_NO_PROPERTY_TYPE, TRUE); 24077c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 24087c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 24097c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 24107c478bd9Sstevel@tonic-gate return; 24117c478bd9Sstevel@tonic-gate } 24127c478bd9Sstevel@tonic-gate } 24137c478bd9Sstevel@tonic-gate rctlvaltab->zone_rctlval_next = NULL; 24147c478bd9Sstevel@tonic-gate err = zonecfg_remove_rctl_value(&in_progress_rctltab, 24157c478bd9Sstevel@tonic-gate rctlvaltab); 24167c478bd9Sstevel@tonic-gate if (err != Z_OK) 24177c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), err, TRUE); 24187c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 24197c478bd9Sstevel@tonic-gate return; 24207c478bd9Sstevel@tonic-gate default: 24217c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, TRUE); 24227c478bd9Sstevel@tonic-gate long_usage(CMD_REMOVE, TRUE); 24237c478bd9Sstevel@tonic-gate usage(FALSE, HELP_RESOURCES); 24247c478bd9Sstevel@tonic-gate return; 24257c478bd9Sstevel@tonic-gate } 24267c478bd9Sstevel@tonic-gate } 24277c478bd9Sstevel@tonic-gate 24287c478bd9Sstevel@tonic-gate void 24297c478bd9Sstevel@tonic-gate remove_func(cmd_t *cmd) 24307c478bd9Sstevel@tonic-gate { 24317c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_REMOVE)) 24327c478bd9Sstevel@tonic-gate return; 24337c478bd9Sstevel@tonic-gate 24347c478bd9Sstevel@tonic-gate assert(cmd != NULL); 24357c478bd9Sstevel@tonic-gate 24367c478bd9Sstevel@tonic-gate if (global_scope) 24377c478bd9Sstevel@tonic-gate remove_resource(cmd); 24387c478bd9Sstevel@tonic-gate else 24397c478bd9Sstevel@tonic-gate remove_property(cmd); 24407c478bd9Sstevel@tonic-gate } 24417c478bd9Sstevel@tonic-gate 24427c478bd9Sstevel@tonic-gate void 24437c478bd9Sstevel@tonic-gate select_func(cmd_t *cmd) 24447c478bd9Sstevel@tonic-gate { 24457c478bd9Sstevel@tonic-gate int type, err; 24467c478bd9Sstevel@tonic-gate 24477c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_SELECT)) 24487c478bd9Sstevel@tonic-gate return; 24497c478bd9Sstevel@tonic-gate 24507c478bd9Sstevel@tonic-gate assert(cmd != NULL); 24517c478bd9Sstevel@tonic-gate 24527c478bd9Sstevel@tonic-gate if (global_scope) { 24537c478bd9Sstevel@tonic-gate global_scope = FALSE; 24547c478bd9Sstevel@tonic-gate resource_scope = cmd->cmd_res_type; 24557c478bd9Sstevel@tonic-gate end_op = CMD_SELECT; 24567c478bd9Sstevel@tonic-gate } else { 24577c478bd9Sstevel@tonic-gate scope_usage(CMD_SELECT); 24587c478bd9Sstevel@tonic-gate return; 24597c478bd9Sstevel@tonic-gate } 24607c478bd9Sstevel@tonic-gate 24617c478bd9Sstevel@tonic-gate if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 24627c478bd9Sstevel@tonic-gate long_usage(CMD_SELECT, TRUE); 24637c478bd9Sstevel@tonic-gate return; 24647c478bd9Sstevel@tonic-gate } 24657c478bd9Sstevel@tonic-gate 24667c478bd9Sstevel@tonic-gate if (initialize(TRUE) != Z_OK) 24677c478bd9Sstevel@tonic-gate return; 24687c478bd9Sstevel@tonic-gate 24697c478bd9Sstevel@tonic-gate switch (type) { 24707c478bd9Sstevel@tonic-gate case RT_FS: 24717c478bd9Sstevel@tonic-gate if ((err = fill_in_fstab(cmd, &old_fstab, FALSE)) != Z_OK) { 24727c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_SELECT, RT_FS, err, TRUE); 24737c478bd9Sstevel@tonic-gate global_scope = TRUE; 24747c478bd9Sstevel@tonic-gate } 24757c478bd9Sstevel@tonic-gate bcopy(&old_fstab, &in_progress_fstab, 24767c478bd9Sstevel@tonic-gate sizeof (struct zone_fstab)); 24777c478bd9Sstevel@tonic-gate return; 24787c478bd9Sstevel@tonic-gate case RT_IPD: 2479087719fdSdp if (state_atleast(ZONE_STATE_INCOMPLETE)) { 24807c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s not in %s state; %s %s not " 24817c478bd9Sstevel@tonic-gate "allowed."), zone, 24827c478bd9Sstevel@tonic-gate zone_state_str(ZONE_STATE_CONFIGURED), 24837c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SELECT), rt_to_str(RT_IPD)); 24847c478bd9Sstevel@tonic-gate global_scope = TRUE; 24857c478bd9Sstevel@tonic-gate end_op = -1; 24867c478bd9Sstevel@tonic-gate return; 24877c478bd9Sstevel@tonic-gate } 24887c478bd9Sstevel@tonic-gate if ((err = fill_in_ipdtab(cmd, &old_ipdtab, FALSE)) != Z_OK) { 24897c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_SELECT, RT_IPD, err, TRUE); 24907c478bd9Sstevel@tonic-gate global_scope = TRUE; 24917c478bd9Sstevel@tonic-gate } 24927c478bd9Sstevel@tonic-gate bcopy(&old_ipdtab, &in_progress_ipdtab, 24937c478bd9Sstevel@tonic-gate sizeof (struct zone_fstab)); 24947c478bd9Sstevel@tonic-gate return; 24957c478bd9Sstevel@tonic-gate case RT_NET: 24967c478bd9Sstevel@tonic-gate if ((err = fill_in_nwiftab(cmd, &old_nwiftab, FALSE)) != Z_OK) { 24977c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_SELECT, RT_NET, err, TRUE); 24987c478bd9Sstevel@tonic-gate global_scope = TRUE; 24997c478bd9Sstevel@tonic-gate } 25007c478bd9Sstevel@tonic-gate bcopy(&old_nwiftab, &in_progress_nwiftab, 25017c478bd9Sstevel@tonic-gate sizeof (struct zone_nwiftab)); 25027c478bd9Sstevel@tonic-gate return; 25037c478bd9Sstevel@tonic-gate case RT_DEVICE: 25047c478bd9Sstevel@tonic-gate if ((err = fill_in_devtab(cmd, &old_devtab, FALSE)) != Z_OK) { 25057c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_SELECT, RT_DEVICE, err, TRUE); 25067c478bd9Sstevel@tonic-gate global_scope = TRUE; 25077c478bd9Sstevel@tonic-gate } 25087c478bd9Sstevel@tonic-gate bcopy(&old_devtab, &in_progress_devtab, 25097c478bd9Sstevel@tonic-gate sizeof (struct zone_devtab)); 25107c478bd9Sstevel@tonic-gate return; 25117c478bd9Sstevel@tonic-gate case RT_RCTL: 25127c478bd9Sstevel@tonic-gate if ((err = fill_in_rctltab(cmd, &old_rctltab, FALSE)) != Z_OK) { 25137c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_SELECT, RT_RCTL, err, TRUE); 25147c478bd9Sstevel@tonic-gate global_scope = TRUE; 25157c478bd9Sstevel@tonic-gate } 25167c478bd9Sstevel@tonic-gate bcopy(&old_rctltab, &in_progress_rctltab, 25177c478bd9Sstevel@tonic-gate sizeof (struct zone_rctltab)); 25187c478bd9Sstevel@tonic-gate return; 25197c478bd9Sstevel@tonic-gate case RT_ATTR: 25207c478bd9Sstevel@tonic-gate if ((err = fill_in_attrtab(cmd, &old_attrtab, FALSE)) != Z_OK) { 25217c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_SELECT, RT_ATTR, err, TRUE); 25227c478bd9Sstevel@tonic-gate global_scope = TRUE; 25237c478bd9Sstevel@tonic-gate } 25247c478bd9Sstevel@tonic-gate bcopy(&old_attrtab, &in_progress_attrtab, 25257c478bd9Sstevel@tonic-gate sizeof (struct zone_attrtab)); 25267c478bd9Sstevel@tonic-gate return; 2527fa9e4066Sahrens case RT_DATASET: 2528fa9e4066Sahrens if ((err = fill_in_dstab(cmd, &old_dstab, FALSE)) != Z_OK) { 2529fa9e4066Sahrens z_cmd_rt_perror(CMD_SELECT, RT_DATASET, err, TRUE); 2530fa9e4066Sahrens global_scope = TRUE; 2531fa9e4066Sahrens } 2532fa9e4066Sahrens bcopy(&old_dstab, &in_progress_dstab, 2533fa9e4066Sahrens sizeof (struct zone_dstab)); 2534fa9e4066Sahrens return; 25357c478bd9Sstevel@tonic-gate default: 25367c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(type), Z_NO_RESOURCE_TYPE, TRUE); 25377c478bd9Sstevel@tonic-gate long_usage(CMD_SELECT, TRUE); 25387c478bd9Sstevel@tonic-gate usage(FALSE, HELP_RESOURCES); 25397c478bd9Sstevel@tonic-gate return; 25407c478bd9Sstevel@tonic-gate } 25417c478bd9Sstevel@tonic-gate } 25427c478bd9Sstevel@tonic-gate 25437c478bd9Sstevel@tonic-gate /* 25447c478bd9Sstevel@tonic-gate * Network "addresses" can be one of the following forms: 25457c478bd9Sstevel@tonic-gate * <IPv4 address> 25467c478bd9Sstevel@tonic-gate * <IPv4 address>/<prefix length> 25477c478bd9Sstevel@tonic-gate * <IPv6 address>/<prefix length> 25487c478bd9Sstevel@tonic-gate * <host name> 25497c478bd9Sstevel@tonic-gate * <host name>/<prefix length> 25507c478bd9Sstevel@tonic-gate * In other words, the "/" followed by a prefix length is allowed but not 25517c478bd9Sstevel@tonic-gate * required for IPv4 addresses and host names, and required for IPv6 addresses. 25527c478bd9Sstevel@tonic-gate * If a prefix length is given, it must be in the allowable range: 0 to 32 for 25537c478bd9Sstevel@tonic-gate * IPv4 addresses and host names, 0 to 128 for IPv6 addresses. 25547c478bd9Sstevel@tonic-gate * Host names must start with an alpha-numeric character, and all subsequent 25557c478bd9Sstevel@tonic-gate * characters must be either alpha-numeric or "-". 25567c478bd9Sstevel@tonic-gate */ 25577c478bd9Sstevel@tonic-gate 25587c478bd9Sstevel@tonic-gate static int 25597c478bd9Sstevel@tonic-gate validate_net_address_syntax(char *address) 25607c478bd9Sstevel@tonic-gate { 25617c478bd9Sstevel@tonic-gate char *slashp, part1[MAXHOSTNAMELEN]; 25627c478bd9Sstevel@tonic-gate struct in6_addr in6; 25637c478bd9Sstevel@tonic-gate struct in_addr in4; 25647c478bd9Sstevel@tonic-gate int prefixlen, i; 25657c478bd9Sstevel@tonic-gate 25667c478bd9Sstevel@tonic-gate /* 25677c478bd9Sstevel@tonic-gate * Copy the part before any '/' into part1 or copy the whole 25687c478bd9Sstevel@tonic-gate * thing if there is no '/'. 25697c478bd9Sstevel@tonic-gate */ 25707c478bd9Sstevel@tonic-gate if ((slashp = strchr(address, '/')) != NULL) { 25717c478bd9Sstevel@tonic-gate *slashp = '\0'; 25727c478bd9Sstevel@tonic-gate (void) strlcpy(part1, address, sizeof (part1)); 25737c478bd9Sstevel@tonic-gate *slashp = '/'; 25747c478bd9Sstevel@tonic-gate prefixlen = atoi(++slashp); 25757c478bd9Sstevel@tonic-gate } else { 25767c478bd9Sstevel@tonic-gate (void) strlcpy(part1, address, sizeof (part1)); 25777c478bd9Sstevel@tonic-gate } 25787c478bd9Sstevel@tonic-gate 25797c478bd9Sstevel@tonic-gate if (inet_pton(AF_INET6, part1, &in6) == 1) { 25807c478bd9Sstevel@tonic-gate if (slashp == NULL) { 25817c478bd9Sstevel@tonic-gate zerr(gettext("%s: IPv6 addresses " 25827c478bd9Sstevel@tonic-gate "require /prefix-length suffix."), address); 25837c478bd9Sstevel@tonic-gate return (Z_ERR); 25847c478bd9Sstevel@tonic-gate } 25857c478bd9Sstevel@tonic-gate if (prefixlen < 0 || prefixlen > 128) { 25867c478bd9Sstevel@tonic-gate zerr(gettext("%s: IPv6 address " 25877c478bd9Sstevel@tonic-gate "prefix lengths must be 0 - 128."), address); 25887c478bd9Sstevel@tonic-gate return (Z_ERR); 25897c478bd9Sstevel@tonic-gate } 25907c478bd9Sstevel@tonic-gate return (Z_OK); 25917c478bd9Sstevel@tonic-gate } 25927c478bd9Sstevel@tonic-gate 25937c478bd9Sstevel@tonic-gate /* At this point, any /prefix must be for IPv4. */ 25947c478bd9Sstevel@tonic-gate if (slashp != NULL) { 25957c478bd9Sstevel@tonic-gate if (prefixlen < 0 || prefixlen > 32) { 25967c478bd9Sstevel@tonic-gate zerr(gettext("%s: IPv4 address " 25977c478bd9Sstevel@tonic-gate "prefix lengths must be 0 - 32."), address); 25987c478bd9Sstevel@tonic-gate return (Z_ERR); 25997c478bd9Sstevel@tonic-gate } 26007c478bd9Sstevel@tonic-gate } 26017c478bd9Sstevel@tonic-gate if (inet_pton(AF_INET, part1, &in4) == 1) 26027c478bd9Sstevel@tonic-gate return (Z_OK); 26037c478bd9Sstevel@tonic-gate 26047c478bd9Sstevel@tonic-gate /* address may also be a host name */ 26057c478bd9Sstevel@tonic-gate if (!isalnum(part1[0])) { 26067c478bd9Sstevel@tonic-gate zerr(gettext("%s: bogus host name or network address syntax"), 26077c478bd9Sstevel@tonic-gate part1); 26087c478bd9Sstevel@tonic-gate saw_error = TRUE; 26097c478bd9Sstevel@tonic-gate usage(FALSE, HELP_NETADDR); 26107c478bd9Sstevel@tonic-gate return (Z_ERR); 26117c478bd9Sstevel@tonic-gate } 26127c478bd9Sstevel@tonic-gate for (i = 1; part1[i]; i++) 26137c478bd9Sstevel@tonic-gate if (!isalnum(part1[i]) && part1[i] != '-' && part1[i] != '.') { 26147c478bd9Sstevel@tonic-gate zerr(gettext("%s: bogus host name or " 26157c478bd9Sstevel@tonic-gate "network address syntax"), part1); 26167c478bd9Sstevel@tonic-gate saw_error = TRUE; 26177c478bd9Sstevel@tonic-gate usage(FALSE, HELP_NETADDR); 26187c478bd9Sstevel@tonic-gate return (Z_ERR); 26197c478bd9Sstevel@tonic-gate } 26207c478bd9Sstevel@tonic-gate return (Z_OK); 26217c478bd9Sstevel@tonic-gate } 26227c478bd9Sstevel@tonic-gate 26237c478bd9Sstevel@tonic-gate static int 26247c478bd9Sstevel@tonic-gate validate_net_physical_syntax(char *ifname) 26257c478bd9Sstevel@tonic-gate { 26267c478bd9Sstevel@tonic-gate if (strchr(ifname, ':') == NULL) 26277c478bd9Sstevel@tonic-gate return (Z_OK); 26287c478bd9Sstevel@tonic-gate zerr(gettext("%s: physical interface name required; " 26297c478bd9Sstevel@tonic-gate "logical interface name not allowed"), ifname); 26307c478bd9Sstevel@tonic-gate return (Z_ERR); 26317c478bd9Sstevel@tonic-gate } 26327c478bd9Sstevel@tonic-gate 26337c478bd9Sstevel@tonic-gate static boolean_t 26347c478bd9Sstevel@tonic-gate valid_fs_type(const char *type) 26357c478bd9Sstevel@tonic-gate { 26367c478bd9Sstevel@tonic-gate /* 26377c478bd9Sstevel@tonic-gate * Is this a valid path component? 26387c478bd9Sstevel@tonic-gate */ 26397c478bd9Sstevel@tonic-gate if (strlen(type) + 1 > MAXNAMELEN) 26407c478bd9Sstevel@tonic-gate return (B_FALSE); 26417c478bd9Sstevel@tonic-gate /* 26427c478bd9Sstevel@tonic-gate * Make sure a bad value for "type" doesn't make 26437c478bd9Sstevel@tonic-gate * /usr/lib/fs/<type>/mount turn into something else. 26447c478bd9Sstevel@tonic-gate */ 26457c478bd9Sstevel@tonic-gate if (strchr(type, '/') != NULL || type[0] == '\0' || 26467c478bd9Sstevel@tonic-gate strcmp(type, ".") == 0 || strcmp(type, "..") == 0) 26477c478bd9Sstevel@tonic-gate return (B_FALSE); 26487c478bd9Sstevel@tonic-gate /* 26497c478bd9Sstevel@tonic-gate * More detailed verification happens later by zoneadm(1m). 26507c478bd9Sstevel@tonic-gate */ 26517c478bd9Sstevel@tonic-gate return (B_TRUE); 26527c478bd9Sstevel@tonic-gate } 26537c478bd9Sstevel@tonic-gate 26547c478bd9Sstevel@tonic-gate void 26557c478bd9Sstevel@tonic-gate set_func(cmd_t *cmd) 26567c478bd9Sstevel@tonic-gate { 26577c478bd9Sstevel@tonic-gate char *prop_id; 26587c478bd9Sstevel@tonic-gate int err, res_type, prop_type; 26597c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 26607c478bd9Sstevel@tonic-gate boolean_t autoboot; 26617c478bd9Sstevel@tonic-gate 26627c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_SET)) 26637c478bd9Sstevel@tonic-gate return; 26647c478bd9Sstevel@tonic-gate 26657c478bd9Sstevel@tonic-gate assert(cmd != NULL); 26667c478bd9Sstevel@tonic-gate 26677c478bd9Sstevel@tonic-gate prop_type = cmd->cmd_prop_name[0]; 26687c478bd9Sstevel@tonic-gate if (global_scope) { 2669087719fdSdp if (prop_type == PT_ZONENAME) { 2670087719fdSdp res_type = RT_ZONENAME; 2671087719fdSdp } else if (prop_type == PT_ZONEPATH) { 26727c478bd9Sstevel@tonic-gate res_type = RT_ZONEPATH; 26737c478bd9Sstevel@tonic-gate } else if (prop_type == PT_AUTOBOOT) { 26747c478bd9Sstevel@tonic-gate res_type = RT_AUTOBOOT; 26757c478bd9Sstevel@tonic-gate } else if (prop_type == PT_POOL) { 26767c478bd9Sstevel@tonic-gate res_type = RT_POOL; 2677*ffbafc53Scomay } else if (prop_type == PT_LIMITPRIV) { 2678*ffbafc53Scomay res_type = RT_LIMITPRIV; 26797c478bd9Sstevel@tonic-gate } else { 26807c478bd9Sstevel@tonic-gate zerr(gettext("Cannot set a resource-specific property " 26817c478bd9Sstevel@tonic-gate "from the global scope.")); 26827c478bd9Sstevel@tonic-gate saw_error = TRUE; 26837c478bd9Sstevel@tonic-gate return; 26847c478bd9Sstevel@tonic-gate } 26857c478bd9Sstevel@tonic-gate } else { 26867c478bd9Sstevel@tonic-gate res_type = resource_scope; 26877c478bd9Sstevel@tonic-gate } 26887c478bd9Sstevel@tonic-gate 26897c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 26907c478bd9Sstevel@tonic-gate /* 26917c478bd9Sstevel@tonic-gate * A nasty expression but not that complicated: 26927c478bd9Sstevel@tonic-gate * 1. fs options are simple or list (tested below) 26937c478bd9Sstevel@tonic-gate * 2. rctl value's are complex or list (tested below) 26947c478bd9Sstevel@tonic-gate * Anything else should be simple. 26957c478bd9Sstevel@tonic-gate */ 26967c478bd9Sstevel@tonic-gate if (!(res_type == RT_FS && prop_type == PT_OPTIONS) && 26977c478bd9Sstevel@tonic-gate !(res_type == RT_RCTL && prop_type == PT_VALUE) && 26987c478bd9Sstevel@tonic-gate (pp->pv_type != PROP_VAL_SIMPLE || 26997c478bd9Sstevel@tonic-gate (prop_id = pp->pv_simple) == NULL)) { 27007c478bd9Sstevel@tonic-gate zerr(gettext("A %s value was expected here."), 27017c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_SIMPLE)); 27027c478bd9Sstevel@tonic-gate saw_error = TRUE; 27037c478bd9Sstevel@tonic-gate return; 27047c478bd9Sstevel@tonic-gate } 27057c478bd9Sstevel@tonic-gate if (prop_type == PT_UNKNOWN) { 27067c478bd9Sstevel@tonic-gate long_usage(CMD_SET, TRUE); 27077c478bd9Sstevel@tonic-gate return; 27087c478bd9Sstevel@tonic-gate } 27097c478bd9Sstevel@tonic-gate 2710087719fdSdp /* 2711087719fdSdp * Special case: the user can change the zone name prior to 'create'; 2712087719fdSdp * if the zone already exists, we fall through letting initialize() 2713087719fdSdp * and the rest of the logic run. 2714087719fdSdp */ 2715087719fdSdp if (res_type == RT_ZONENAME && got_handle == FALSE && 2716087719fdSdp !state_atleast(ZONE_STATE_CONFIGURED)) { 2717fb03efaaSdp if ((err = zonecfg_validate_zonename(prop_id)) != Z_OK) { 2718fb03efaaSdp zone_perror(prop_id, err, TRUE); 2719fb03efaaSdp usage(FALSE, HELP_SYNTAX); 2720fb03efaaSdp return; 2721fb03efaaSdp } 2722087719fdSdp (void) strlcpy(zone, prop_id, sizeof (zone)); 2723087719fdSdp return; 2724087719fdSdp } 2725087719fdSdp 27267c478bd9Sstevel@tonic-gate if (initialize(TRUE) != Z_OK) 27277c478bd9Sstevel@tonic-gate return; 27287c478bd9Sstevel@tonic-gate 27297c478bd9Sstevel@tonic-gate switch (res_type) { 2730087719fdSdp case RT_ZONENAME: 2731087719fdSdp if ((err = zonecfg_set_name(handle, prop_id)) != Z_OK) { 2732087719fdSdp /* 2733087719fdSdp * Use prop_id instead of 'zone' here, since we're 2734087719fdSdp * reporting a problem about the *new* zonename. 2735087719fdSdp */ 2736087719fdSdp zone_perror(prop_id, err, TRUE); 2737fb03efaaSdp usage(FALSE, HELP_SYNTAX); 2738087719fdSdp } else { 2739087719fdSdp need_to_commit = TRUE; 2740087719fdSdp (void) strlcpy(zone, prop_id, sizeof (zone)); 2741087719fdSdp } 2742087719fdSdp return; 27437c478bd9Sstevel@tonic-gate case RT_ZONEPATH: 2744087719fdSdp if (state_atleast(ZONE_STATE_INSTALLED)) { 27457c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s already installed; %s %s not " 27467c478bd9Sstevel@tonic-gate "allowed."), zone, cmd_to_str(CMD_SET), 27477c478bd9Sstevel@tonic-gate rt_to_str(RT_ZONEPATH)); 27487c478bd9Sstevel@tonic-gate return; 27497c478bd9Sstevel@tonic-gate } 27507c478bd9Sstevel@tonic-gate if (validate_zonepath_syntax(prop_id) != Z_OK) { 27517c478bd9Sstevel@tonic-gate saw_error = TRUE; 27527c478bd9Sstevel@tonic-gate return; 27537c478bd9Sstevel@tonic-gate } 27547c478bd9Sstevel@tonic-gate if ((err = zonecfg_set_zonepath(handle, prop_id)) != Z_OK) 27557c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 27567c478bd9Sstevel@tonic-gate else 27577c478bd9Sstevel@tonic-gate need_to_commit = TRUE; 27587c478bd9Sstevel@tonic-gate return; 27597c478bd9Sstevel@tonic-gate case RT_AUTOBOOT: 27607c478bd9Sstevel@tonic-gate if (strcmp(prop_id, "true") == 0) { 27617c478bd9Sstevel@tonic-gate autoboot = B_TRUE; 27627c478bd9Sstevel@tonic-gate } else if (strcmp(prop_id, "false") == 0) { 27637c478bd9Sstevel@tonic-gate autoboot = B_FALSE; 27647c478bd9Sstevel@tonic-gate } else { 27657c478bd9Sstevel@tonic-gate zerr(gettext("%s value must be '%s' or '%s'."), 27667c478bd9Sstevel@tonic-gate pt_to_str(PT_AUTOBOOT), "true", "false"); 27677c478bd9Sstevel@tonic-gate saw_error = TRUE; 27687c478bd9Sstevel@tonic-gate return; 27697c478bd9Sstevel@tonic-gate } 27707c478bd9Sstevel@tonic-gate if ((err = zonecfg_set_autoboot(handle, autoboot)) != Z_OK) 27717c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 27727c478bd9Sstevel@tonic-gate else 27737c478bd9Sstevel@tonic-gate need_to_commit = TRUE; 27747c478bd9Sstevel@tonic-gate return; 27757c478bd9Sstevel@tonic-gate case RT_POOL: 27767c478bd9Sstevel@tonic-gate if ((err = zonecfg_set_pool(handle, prop_id)) != Z_OK) 27777c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 27787c478bd9Sstevel@tonic-gate else 27797c478bd9Sstevel@tonic-gate need_to_commit = TRUE; 27807c478bd9Sstevel@tonic-gate return; 2781*ffbafc53Scomay case RT_LIMITPRIV: 2782*ffbafc53Scomay if ((err = zonecfg_set_limitpriv(handle, prop_id)) != Z_OK) 2783*ffbafc53Scomay zone_perror(zone, err, TRUE); 2784*ffbafc53Scomay else 2785*ffbafc53Scomay need_to_commit = TRUE; 2786*ffbafc53Scomay return; 27877c478bd9Sstevel@tonic-gate case RT_FS: 27887c478bd9Sstevel@tonic-gate switch (prop_type) { 27897c478bd9Sstevel@tonic-gate case PT_DIR: 27907c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_dir, prop_id, 27917c478bd9Sstevel@tonic-gate sizeof (in_progress_fstab.zone_fs_dir)); 27927c478bd9Sstevel@tonic-gate return; 27937c478bd9Sstevel@tonic-gate case PT_SPECIAL: 27947c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_special, 27957c478bd9Sstevel@tonic-gate prop_id, 27967c478bd9Sstevel@tonic-gate sizeof (in_progress_fstab.zone_fs_special)); 27977c478bd9Sstevel@tonic-gate return; 27987c478bd9Sstevel@tonic-gate case PT_RAW: 27997c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_raw, 28007c478bd9Sstevel@tonic-gate prop_id, sizeof (in_progress_fstab.zone_fs_raw)); 28017c478bd9Sstevel@tonic-gate return; 28027c478bd9Sstevel@tonic-gate case PT_TYPE: 28037c478bd9Sstevel@tonic-gate if (!valid_fs_type(prop_id)) { 28047c478bd9Sstevel@tonic-gate zerr(gettext("\"%s\" is not a valid %s."), 28057c478bd9Sstevel@tonic-gate prop_id, pt_to_str(PT_TYPE)); 28067c478bd9Sstevel@tonic-gate saw_error = TRUE; 28077c478bd9Sstevel@tonic-gate return; 28087c478bd9Sstevel@tonic-gate } 28097c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_type, prop_id, 28107c478bd9Sstevel@tonic-gate sizeof (in_progress_fstab.zone_fs_type)); 28117c478bd9Sstevel@tonic-gate return; 28127c478bd9Sstevel@tonic-gate case PT_OPTIONS: 28137c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE && 28147c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 28157c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected " 28167c478bd9Sstevel@tonic-gate "here."), pvt_to_str(PROP_VAL_SIMPLE), 28177c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 28187c478bd9Sstevel@tonic-gate saw_error = TRUE; 28197c478bd9Sstevel@tonic-gate return; 28207c478bd9Sstevel@tonic-gate } 28217c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list( 28227c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_options); 28237c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_options = NULL; 28247c478bd9Sstevel@tonic-gate if (!(pp->pv_type == PROP_VAL_LIST && 28257c478bd9Sstevel@tonic-gate pp->pv_list == NULL)) 28267c478bd9Sstevel@tonic-gate add_property(cmd); 28277c478bd9Sstevel@tonic-gate return; 28287c478bd9Sstevel@tonic-gate default: 28297c478bd9Sstevel@tonic-gate break; 28307c478bd9Sstevel@tonic-gate } 28317c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, TRUE); 28327c478bd9Sstevel@tonic-gate long_usage(CMD_SET, TRUE); 28337c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 28347c478bd9Sstevel@tonic-gate return; 28357c478bd9Sstevel@tonic-gate case RT_IPD: 28367c478bd9Sstevel@tonic-gate switch (prop_type) { 28377c478bd9Sstevel@tonic-gate case PT_DIR: 28387c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_ipdtab.zone_fs_dir, prop_id, 28397c478bd9Sstevel@tonic-gate sizeof (in_progress_ipdtab.zone_fs_dir)); 28407c478bd9Sstevel@tonic-gate return; 28417c478bd9Sstevel@tonic-gate default: 28427c478bd9Sstevel@tonic-gate break; 28437c478bd9Sstevel@tonic-gate } 28447c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, TRUE); 28457c478bd9Sstevel@tonic-gate long_usage(CMD_SET, TRUE); 28467c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 28477c478bd9Sstevel@tonic-gate return; 28487c478bd9Sstevel@tonic-gate case RT_NET: 28497c478bd9Sstevel@tonic-gate switch (prop_type) { 28507c478bd9Sstevel@tonic-gate case PT_ADDRESS: 28517c478bd9Sstevel@tonic-gate if (validate_net_address_syntax(prop_id) != Z_OK) { 28527c478bd9Sstevel@tonic-gate saw_error = TRUE; 28537c478bd9Sstevel@tonic-gate return; 28547c478bd9Sstevel@tonic-gate } 28557c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_nwiftab.zone_nwif_address, 28567c478bd9Sstevel@tonic-gate prop_id, 28577c478bd9Sstevel@tonic-gate sizeof (in_progress_nwiftab.zone_nwif_address)); 28587c478bd9Sstevel@tonic-gate break; 28597c478bd9Sstevel@tonic-gate case PT_PHYSICAL: 28607c478bd9Sstevel@tonic-gate if (validate_net_physical_syntax(prop_id) != Z_OK) { 28617c478bd9Sstevel@tonic-gate saw_error = TRUE; 28627c478bd9Sstevel@tonic-gate return; 28637c478bd9Sstevel@tonic-gate } 28647c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_nwiftab.zone_nwif_physical, 28657c478bd9Sstevel@tonic-gate prop_id, 28667c478bd9Sstevel@tonic-gate sizeof (in_progress_nwiftab.zone_nwif_physical)); 28677c478bd9Sstevel@tonic-gate break; 28687c478bd9Sstevel@tonic-gate default: 28697c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 28707c478bd9Sstevel@tonic-gate TRUE); 28717c478bd9Sstevel@tonic-gate long_usage(CMD_SET, TRUE); 28727c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 28737c478bd9Sstevel@tonic-gate return; 28747c478bd9Sstevel@tonic-gate } 28757c478bd9Sstevel@tonic-gate return; 28767c478bd9Sstevel@tonic-gate case RT_DEVICE: 28777c478bd9Sstevel@tonic-gate switch (prop_type) { 28787c478bd9Sstevel@tonic-gate case PT_MATCH: 28797c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_devtab.zone_dev_match, 28807c478bd9Sstevel@tonic-gate prop_id, 28817c478bd9Sstevel@tonic-gate sizeof (in_progress_devtab.zone_dev_match)); 28827c478bd9Sstevel@tonic-gate break; 28837c478bd9Sstevel@tonic-gate default: 28847c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 28857c478bd9Sstevel@tonic-gate TRUE); 28867c478bd9Sstevel@tonic-gate long_usage(CMD_SET, TRUE); 28877c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 28887c478bd9Sstevel@tonic-gate return; 28897c478bd9Sstevel@tonic-gate } 28907c478bd9Sstevel@tonic-gate return; 28917c478bd9Sstevel@tonic-gate case RT_RCTL: 28927c478bd9Sstevel@tonic-gate switch (prop_type) { 28937c478bd9Sstevel@tonic-gate case PT_NAME: 28947c478bd9Sstevel@tonic-gate if (!zonecfg_valid_rctlname(prop_id)) { 28957c478bd9Sstevel@tonic-gate zerr(gettext("'%s' is not a valid zone %s " 28967c478bd9Sstevel@tonic-gate "name."), prop_id, rt_to_str(RT_RCTL)); 28977c478bd9Sstevel@tonic-gate return; 28987c478bd9Sstevel@tonic-gate } 28997c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_rctltab.zone_rctl_name, 29007c478bd9Sstevel@tonic-gate prop_id, 29017c478bd9Sstevel@tonic-gate sizeof (in_progress_rctltab.zone_rctl_name)); 29027c478bd9Sstevel@tonic-gate break; 29037c478bd9Sstevel@tonic-gate case PT_VALUE: 29047c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_COMPLEX && 29057c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 29067c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected " 29077c478bd9Sstevel@tonic-gate "here."), pvt_to_str(PROP_VAL_COMPLEX), 29087c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 29097c478bd9Sstevel@tonic-gate saw_error = TRUE; 29107c478bd9Sstevel@tonic-gate return; 29117c478bd9Sstevel@tonic-gate } 29127c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list( 29137c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr); 29147c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr = NULL; 29157c478bd9Sstevel@tonic-gate if (!(pp->pv_type == PROP_VAL_LIST && 29167c478bd9Sstevel@tonic-gate pp->pv_list == NULL)) 29177c478bd9Sstevel@tonic-gate add_property(cmd); 29187c478bd9Sstevel@tonic-gate break; 29197c478bd9Sstevel@tonic-gate default: 29207c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 29217c478bd9Sstevel@tonic-gate TRUE); 29227c478bd9Sstevel@tonic-gate long_usage(CMD_SET, TRUE); 29237c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 29247c478bd9Sstevel@tonic-gate return; 29257c478bd9Sstevel@tonic-gate } 29267c478bd9Sstevel@tonic-gate return; 29277c478bd9Sstevel@tonic-gate case RT_ATTR: 29287c478bd9Sstevel@tonic-gate switch (prop_type) { 29297c478bd9Sstevel@tonic-gate case PT_NAME: 29307c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_attrtab.zone_attr_name, 29317c478bd9Sstevel@tonic-gate prop_id, 29327c478bd9Sstevel@tonic-gate sizeof (in_progress_attrtab.zone_attr_name)); 29337c478bd9Sstevel@tonic-gate break; 29347c478bd9Sstevel@tonic-gate case PT_TYPE: 29357c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_attrtab.zone_attr_type, 29367c478bd9Sstevel@tonic-gate prop_id, 29377c478bd9Sstevel@tonic-gate sizeof (in_progress_attrtab.zone_attr_type)); 29387c478bd9Sstevel@tonic-gate break; 29397c478bd9Sstevel@tonic-gate case PT_VALUE: 29407c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_attrtab.zone_attr_value, 29417c478bd9Sstevel@tonic-gate prop_id, 29427c478bd9Sstevel@tonic-gate sizeof (in_progress_attrtab.zone_attr_value)); 29437c478bd9Sstevel@tonic-gate break; 29447c478bd9Sstevel@tonic-gate default: 29457c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 29467c478bd9Sstevel@tonic-gate TRUE); 29477c478bd9Sstevel@tonic-gate long_usage(CMD_SET, TRUE); 29487c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 29497c478bd9Sstevel@tonic-gate return; 29507c478bd9Sstevel@tonic-gate } 29517c478bd9Sstevel@tonic-gate return; 2952fa9e4066Sahrens case RT_DATASET: 2953fa9e4066Sahrens switch (prop_type) { 2954fa9e4066Sahrens case PT_NAME: 2955fa9e4066Sahrens (void) strlcpy(in_progress_dstab.zone_dataset_name, 2956fa9e4066Sahrens prop_id, 2957fa9e4066Sahrens sizeof (in_progress_dstab.zone_dataset_name)); 2958fa9e4066Sahrens return; 2959fa9e4066Sahrens default: 2960fa9e4066Sahrens break; 2961fa9e4066Sahrens } 2962fa9e4066Sahrens zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, TRUE); 2963fa9e4066Sahrens long_usage(CMD_SET, TRUE); 2964fa9e4066Sahrens usage(FALSE, HELP_PROPS); 2965fa9e4066Sahrens return; 29667c478bd9Sstevel@tonic-gate default: 29677c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, TRUE); 29687c478bd9Sstevel@tonic-gate long_usage(CMD_SET, TRUE); 29697c478bd9Sstevel@tonic-gate usage(FALSE, HELP_RESOURCES); 29707c478bd9Sstevel@tonic-gate return; 29717c478bd9Sstevel@tonic-gate } 29727c478bd9Sstevel@tonic-gate } 29737c478bd9Sstevel@tonic-gate 29747c478bd9Sstevel@tonic-gate static void 29757c478bd9Sstevel@tonic-gate output_prop(FILE *fp, int pnum, char *pval, bool print_notspec) 29767c478bd9Sstevel@tonic-gate { 29777c478bd9Sstevel@tonic-gate char *qstr; 29787c478bd9Sstevel@tonic-gate 29797c478bd9Sstevel@tonic-gate if (*pval != '\0') { 29807c478bd9Sstevel@tonic-gate qstr = quoteit(pval); 29817c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s: %s\n", pt_to_str(pnum), qstr); 29827c478bd9Sstevel@tonic-gate free(qstr); 29837c478bd9Sstevel@tonic-gate } else if (print_notspec) 2984087719fdSdp (void) fprintf(fp, gettext("\t%s not specified\n"), 2985087719fdSdp pt_to_str(pnum)); 2986087719fdSdp } 2987087719fdSdp 2988087719fdSdp static void 2989087719fdSdp info_zonename(zone_dochandle_t handle, FILE *fp) 2990087719fdSdp { 2991087719fdSdp char zonename[ZONENAME_MAX]; 2992087719fdSdp 2993087719fdSdp if (zonecfg_get_name(handle, zonename, sizeof (zonename)) == Z_OK) 2994087719fdSdp (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_ZONENAME), 2995087719fdSdp zonename); 2996087719fdSdp else 2997087719fdSdp (void) fprintf(fp, gettext("%s not specified\n"), 2998087719fdSdp pt_to_str(PT_ZONENAME)); 29997c478bd9Sstevel@tonic-gate } 30007c478bd9Sstevel@tonic-gate 30017c478bd9Sstevel@tonic-gate static void 30027c478bd9Sstevel@tonic-gate info_zonepath(zone_dochandle_t handle, FILE *fp) 30037c478bd9Sstevel@tonic-gate { 30047c478bd9Sstevel@tonic-gate char zonepath[MAXPATHLEN]; 30057c478bd9Sstevel@tonic-gate 30067c478bd9Sstevel@tonic-gate if (zonecfg_get_zonepath(handle, zonepath, sizeof (zonepath)) == Z_OK) 30077c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_ZONEPATH), 30087c478bd9Sstevel@tonic-gate zonepath); 3009087719fdSdp else { 3010087719fdSdp (void) fprintf(fp, gettext("%s not specified\n"), 3011087719fdSdp pt_to_str(PT_ZONEPATH)); 3012087719fdSdp } 30137c478bd9Sstevel@tonic-gate } 30147c478bd9Sstevel@tonic-gate 30157c478bd9Sstevel@tonic-gate static void 30167c478bd9Sstevel@tonic-gate info_autoboot(zone_dochandle_t handle, FILE *fp) 30177c478bd9Sstevel@tonic-gate { 30187c478bd9Sstevel@tonic-gate boolean_t autoboot; 30197c478bd9Sstevel@tonic-gate int err; 30207c478bd9Sstevel@tonic-gate 30217c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_autoboot(handle, &autoboot)) == Z_OK) 30227c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_AUTOBOOT), 30237c478bd9Sstevel@tonic-gate autoboot ? "true" : "false"); 30247c478bd9Sstevel@tonic-gate else 30257c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 30267c478bd9Sstevel@tonic-gate } 30277c478bd9Sstevel@tonic-gate 30287c478bd9Sstevel@tonic-gate static void 30297c478bd9Sstevel@tonic-gate info_pool(zone_dochandle_t handle, FILE *fp) 30307c478bd9Sstevel@tonic-gate { 30317c478bd9Sstevel@tonic-gate char pool[MAXNAMELEN]; 30327c478bd9Sstevel@tonic-gate int err; 30337c478bd9Sstevel@tonic-gate 30347c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_pool(handle, pool, sizeof (pool))) == Z_OK) 30357c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_POOL), pool); 30367c478bd9Sstevel@tonic-gate else 30377c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 30387c478bd9Sstevel@tonic-gate } 30397c478bd9Sstevel@tonic-gate 30407c478bd9Sstevel@tonic-gate static void 3041*ffbafc53Scomay info_limitpriv(zone_dochandle_t handle, FILE *fp) 3042*ffbafc53Scomay { 3043*ffbafc53Scomay char *limitpriv; 3044*ffbafc53Scomay int err; 3045*ffbafc53Scomay 3046*ffbafc53Scomay if ((err = zonecfg_get_limitpriv(handle, &limitpriv)) == Z_OK) { 3047*ffbafc53Scomay (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_LIMITPRIV), 3048*ffbafc53Scomay limitpriv); 3049*ffbafc53Scomay free(limitpriv); 3050*ffbafc53Scomay } else { 3051*ffbafc53Scomay zone_perror(zone, err, TRUE); 3052*ffbafc53Scomay } 3053*ffbafc53Scomay } 3054*ffbafc53Scomay 3055*ffbafc53Scomay static void 30567c478bd9Sstevel@tonic-gate output_fs(FILE *fp, struct zone_fstab *fstab) 30577c478bd9Sstevel@tonic-gate { 30587c478bd9Sstevel@tonic-gate zone_fsopt_t *this; 30597c478bd9Sstevel@tonic-gate 30607c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_FS)); 30617c478bd9Sstevel@tonic-gate output_prop(fp, PT_DIR, fstab->zone_fs_dir, B_TRUE); 30627c478bd9Sstevel@tonic-gate output_prop(fp, PT_SPECIAL, fstab->zone_fs_special, B_TRUE); 30637c478bd9Sstevel@tonic-gate output_prop(fp, PT_RAW, fstab->zone_fs_raw, B_TRUE); 30647c478bd9Sstevel@tonic-gate output_prop(fp, PT_TYPE, fstab->zone_fs_type, B_TRUE); 30657c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s: [", pt_to_str(PT_OPTIONS)); 30667c478bd9Sstevel@tonic-gate for (this = fstab->zone_fs_options; this != NULL; 30677c478bd9Sstevel@tonic-gate this = this->zone_fsopt_next) { 30687c478bd9Sstevel@tonic-gate if (strchr(this->zone_fsopt_opt, '=')) 30697c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\"%s\"", this->zone_fsopt_opt); 30707c478bd9Sstevel@tonic-gate else 30717c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s", this->zone_fsopt_opt); 30727c478bd9Sstevel@tonic-gate if (this->zone_fsopt_next != NULL) 30737c478bd9Sstevel@tonic-gate (void) fprintf(fp, ","); 30747c478bd9Sstevel@tonic-gate } 30757c478bd9Sstevel@tonic-gate (void) fprintf(fp, "]\n"); 30767c478bd9Sstevel@tonic-gate } 30777c478bd9Sstevel@tonic-gate 30787c478bd9Sstevel@tonic-gate static void 30797c478bd9Sstevel@tonic-gate output_ipd(FILE *fp, struct zone_fstab *ipdtab) 30807c478bd9Sstevel@tonic-gate { 30817c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_IPD)); 30827c478bd9Sstevel@tonic-gate output_prop(fp, PT_DIR, ipdtab->zone_fs_dir, B_TRUE); 30837c478bd9Sstevel@tonic-gate } 30847c478bd9Sstevel@tonic-gate 30857c478bd9Sstevel@tonic-gate static void 30867c478bd9Sstevel@tonic-gate info_fs(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 30877c478bd9Sstevel@tonic-gate { 30887c478bd9Sstevel@tonic-gate struct zone_fstab lookup, user; 30897c478bd9Sstevel@tonic-gate bool output = FALSE; 30907c478bd9Sstevel@tonic-gate 30917c478bd9Sstevel@tonic-gate if (zonecfg_setfsent(handle) != Z_OK) 30927c478bd9Sstevel@tonic-gate return; 30937c478bd9Sstevel@tonic-gate while (zonecfg_getfsent(handle, &lookup) == Z_OK) { 30947c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 30957c478bd9Sstevel@tonic-gate output_fs(fp, &lookup); 30967c478bd9Sstevel@tonic-gate goto loopend; 30977c478bd9Sstevel@tonic-gate } 30987c478bd9Sstevel@tonic-gate if (fill_in_fstab(cmd, &user, TRUE) != Z_OK) 30997c478bd9Sstevel@tonic-gate goto loopend; 31007c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_dir) > 0 && 31017c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_dir, lookup.zone_fs_dir) != 0) 31027c478bd9Sstevel@tonic-gate goto loopend; /* no match */ 31037c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_special) > 0 && 31047c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_special, lookup.zone_fs_special) != 0) 31057c478bd9Sstevel@tonic-gate goto loopend; /* no match */ 31067c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_type) > 0 && 31077c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_type, lookup.zone_fs_type) != 0) 31087c478bd9Sstevel@tonic-gate goto loopend; /* no match */ 31097c478bd9Sstevel@tonic-gate output_fs(fp, &lookup); 31107c478bd9Sstevel@tonic-gate output = TRUE; 31117c478bd9Sstevel@tonic-gate loopend: 31127c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(lookup.zone_fs_options); 31137c478bd9Sstevel@tonic-gate } 31147c478bd9Sstevel@tonic-gate (void) zonecfg_endfsent(handle); 31157c478bd9Sstevel@tonic-gate /* 31167c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 31177c478bd9Sstevel@tonic-gate * nothing to output. 31187c478bd9Sstevel@tonic-gate */ 31197c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 31207c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 31217c478bd9Sstevel@tonic-gate rt_to_str(RT_FS)); 31227c478bd9Sstevel@tonic-gate } 31237c478bd9Sstevel@tonic-gate 31247c478bd9Sstevel@tonic-gate static void 31257c478bd9Sstevel@tonic-gate info_ipd(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 31267c478bd9Sstevel@tonic-gate { 31277c478bd9Sstevel@tonic-gate struct zone_fstab lookup, user; 31287c478bd9Sstevel@tonic-gate bool output = FALSE; 31297c478bd9Sstevel@tonic-gate 31307c478bd9Sstevel@tonic-gate if (zonecfg_setipdent(handle) != Z_OK) 31317c478bd9Sstevel@tonic-gate return; 31327c478bd9Sstevel@tonic-gate while (zonecfg_getipdent(handle, &lookup) == Z_OK) { 31337c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 31347c478bd9Sstevel@tonic-gate output_ipd(fp, &lookup); 31357c478bd9Sstevel@tonic-gate continue; 31367c478bd9Sstevel@tonic-gate } 31377c478bd9Sstevel@tonic-gate if (fill_in_ipdtab(cmd, &user, TRUE) != Z_OK) 31387c478bd9Sstevel@tonic-gate continue; 31397c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_dir) > 0 && 31407c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_dir, lookup.zone_fs_dir) != 0) 31417c478bd9Sstevel@tonic-gate continue; /* no match */ 31427c478bd9Sstevel@tonic-gate output_ipd(fp, &lookup); 31437c478bd9Sstevel@tonic-gate output = TRUE; 31447c478bd9Sstevel@tonic-gate } 31457c478bd9Sstevel@tonic-gate (void) zonecfg_endipdent(handle); 31467c478bd9Sstevel@tonic-gate /* 31477c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 31487c478bd9Sstevel@tonic-gate * nothing to output. 31497c478bd9Sstevel@tonic-gate */ 31507c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 31517c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 31527c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD)); 31537c478bd9Sstevel@tonic-gate } 31547c478bd9Sstevel@tonic-gate 31557c478bd9Sstevel@tonic-gate static void 31567c478bd9Sstevel@tonic-gate output_net(FILE *fp, struct zone_nwiftab *nwiftab) 31577c478bd9Sstevel@tonic-gate { 31587c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_NET)); 31597c478bd9Sstevel@tonic-gate output_prop(fp, PT_ADDRESS, nwiftab->zone_nwif_address, B_TRUE); 31607c478bd9Sstevel@tonic-gate output_prop(fp, PT_PHYSICAL, nwiftab->zone_nwif_physical, B_TRUE); 31617c478bd9Sstevel@tonic-gate } 31627c478bd9Sstevel@tonic-gate 31637c478bd9Sstevel@tonic-gate static void 31647c478bd9Sstevel@tonic-gate info_net(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 31657c478bd9Sstevel@tonic-gate { 31667c478bd9Sstevel@tonic-gate struct zone_nwiftab lookup, user; 31677c478bd9Sstevel@tonic-gate bool output = FALSE; 31687c478bd9Sstevel@tonic-gate 31697c478bd9Sstevel@tonic-gate if (zonecfg_setnwifent(handle) != Z_OK) 31707c478bd9Sstevel@tonic-gate return; 31717c478bd9Sstevel@tonic-gate while (zonecfg_getnwifent(handle, &lookup) == Z_OK) { 31727c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 31737c478bd9Sstevel@tonic-gate output_net(fp, &lookup); 31747c478bd9Sstevel@tonic-gate continue; 31757c478bd9Sstevel@tonic-gate } 31767c478bd9Sstevel@tonic-gate if (fill_in_nwiftab(cmd, &user, TRUE) != Z_OK) 31777c478bd9Sstevel@tonic-gate continue; 31787c478bd9Sstevel@tonic-gate if (strlen(user.zone_nwif_physical) > 0 && 31797c478bd9Sstevel@tonic-gate strcmp(user.zone_nwif_physical, 31807c478bd9Sstevel@tonic-gate lookup.zone_nwif_physical) != 0) 31817c478bd9Sstevel@tonic-gate continue; /* no match */ 31827c478bd9Sstevel@tonic-gate if (strlen(user.zone_nwif_address) > 0 && 31837c478bd9Sstevel@tonic-gate !zonecfg_same_net_address(user.zone_nwif_address, 31847c478bd9Sstevel@tonic-gate lookup.zone_nwif_address)) 31857c478bd9Sstevel@tonic-gate continue; /* no match */ 31867c478bd9Sstevel@tonic-gate output_net(fp, &lookup); 31877c478bd9Sstevel@tonic-gate output = TRUE; 31887c478bd9Sstevel@tonic-gate } 31897c478bd9Sstevel@tonic-gate (void) zonecfg_endnwifent(handle); 31907c478bd9Sstevel@tonic-gate /* 31917c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 31927c478bd9Sstevel@tonic-gate * nothing to output. 31937c478bd9Sstevel@tonic-gate */ 31947c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 31957c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 31967c478bd9Sstevel@tonic-gate rt_to_str(RT_NET)); 31977c478bd9Sstevel@tonic-gate } 31987c478bd9Sstevel@tonic-gate 31997c478bd9Sstevel@tonic-gate static void 32007c478bd9Sstevel@tonic-gate output_dev(FILE *fp, struct zone_devtab *devtab) 32017c478bd9Sstevel@tonic-gate { 32027c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s\n", rt_to_str(RT_DEVICE)); 32037c478bd9Sstevel@tonic-gate output_prop(fp, PT_MATCH, devtab->zone_dev_match, B_TRUE); 32047c478bd9Sstevel@tonic-gate } 32057c478bd9Sstevel@tonic-gate 32067c478bd9Sstevel@tonic-gate static void 32077c478bd9Sstevel@tonic-gate info_dev(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 32087c478bd9Sstevel@tonic-gate { 32097c478bd9Sstevel@tonic-gate struct zone_devtab lookup, user; 32107c478bd9Sstevel@tonic-gate bool output = FALSE; 32117c478bd9Sstevel@tonic-gate 32127c478bd9Sstevel@tonic-gate if (zonecfg_setdevent(handle) != Z_OK) 32137c478bd9Sstevel@tonic-gate return; 32147c478bd9Sstevel@tonic-gate while (zonecfg_getdevent(handle, &lookup) == Z_OK) { 32157c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 32167c478bd9Sstevel@tonic-gate output_dev(fp, &lookup); 32177c478bd9Sstevel@tonic-gate continue; 32187c478bd9Sstevel@tonic-gate } 32197c478bd9Sstevel@tonic-gate if (fill_in_devtab(cmd, &user, TRUE) != Z_OK) 32207c478bd9Sstevel@tonic-gate continue; 32217c478bd9Sstevel@tonic-gate if (strlen(user.zone_dev_match) > 0 && 32227c478bd9Sstevel@tonic-gate strcmp(user.zone_dev_match, lookup.zone_dev_match) != 0) 32237c478bd9Sstevel@tonic-gate continue; /* no match */ 32247c478bd9Sstevel@tonic-gate output_dev(fp, &lookup); 32257c478bd9Sstevel@tonic-gate output = TRUE; 32267c478bd9Sstevel@tonic-gate } 32277c478bd9Sstevel@tonic-gate (void) zonecfg_enddevent(handle); 32287c478bd9Sstevel@tonic-gate /* 32297c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 32307c478bd9Sstevel@tonic-gate * nothing to output. 32317c478bd9Sstevel@tonic-gate */ 32327c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 32337c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 32347c478bd9Sstevel@tonic-gate rt_to_str(RT_DEVICE)); 32357c478bd9Sstevel@tonic-gate } 32367c478bd9Sstevel@tonic-gate 32377c478bd9Sstevel@tonic-gate static void 32387c478bd9Sstevel@tonic-gate output_rctl(FILE *fp, struct zone_rctltab *rctltab) 32397c478bd9Sstevel@tonic-gate { 32407c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *valptr; 32417c478bd9Sstevel@tonic-gate 32427c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_RCTL)); 32437c478bd9Sstevel@tonic-gate output_prop(fp, PT_NAME, rctltab->zone_rctl_name, B_TRUE); 32447c478bd9Sstevel@tonic-gate for (valptr = rctltab->zone_rctl_valptr; valptr != NULL; 32457c478bd9Sstevel@tonic-gate valptr = valptr->zone_rctlval_next) { 32467c478bd9Sstevel@tonic-gate fprintf(fp, "\t%s: (%s=%s,%s=%s,%s=%s)\n", 32477c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), 32487c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV), valptr->zone_rctlval_priv, 32497c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT), valptr->zone_rctlval_limit, 32507c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION), valptr->zone_rctlval_action); 32517c478bd9Sstevel@tonic-gate } 32527c478bd9Sstevel@tonic-gate } 32537c478bd9Sstevel@tonic-gate 32547c478bd9Sstevel@tonic-gate static void 32557c478bd9Sstevel@tonic-gate info_rctl(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 32567c478bd9Sstevel@tonic-gate { 32577c478bd9Sstevel@tonic-gate struct zone_rctltab lookup, user; 32587c478bd9Sstevel@tonic-gate bool output = FALSE; 32597c478bd9Sstevel@tonic-gate 32607c478bd9Sstevel@tonic-gate if (zonecfg_setrctlent(handle) != Z_OK) 32617c478bd9Sstevel@tonic-gate return; 32627c478bd9Sstevel@tonic-gate while (zonecfg_getrctlent(handle, &lookup) == Z_OK) { 32637c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 32647c478bd9Sstevel@tonic-gate output_rctl(fp, &lookup); 32657c478bd9Sstevel@tonic-gate } else if (fill_in_rctltab(cmd, &user, TRUE) == Z_OK && 32667c478bd9Sstevel@tonic-gate (strlen(user.zone_rctl_name) == 0 || 32677c478bd9Sstevel@tonic-gate strcmp(user.zone_rctl_name, lookup.zone_rctl_name) == 0)) { 32687c478bd9Sstevel@tonic-gate output_rctl(fp, &lookup); 32697c478bd9Sstevel@tonic-gate output = TRUE; 32707c478bd9Sstevel@tonic-gate } 32717c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(lookup.zone_rctl_valptr); 32727c478bd9Sstevel@tonic-gate } 32737c478bd9Sstevel@tonic-gate (void) zonecfg_endrctlent(handle); 32747c478bd9Sstevel@tonic-gate /* 32757c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 32767c478bd9Sstevel@tonic-gate * nothing to output. 32777c478bd9Sstevel@tonic-gate */ 32787c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 32797c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 32807c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL)); 32817c478bd9Sstevel@tonic-gate } 32827c478bd9Sstevel@tonic-gate 32837c478bd9Sstevel@tonic-gate static void 32847c478bd9Sstevel@tonic-gate output_attr(FILE *fp, struct zone_attrtab *attrtab) 32857c478bd9Sstevel@tonic-gate { 32867c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_ATTR)); 32877c478bd9Sstevel@tonic-gate output_prop(fp, PT_NAME, attrtab->zone_attr_name, B_TRUE); 32887c478bd9Sstevel@tonic-gate output_prop(fp, PT_TYPE, attrtab->zone_attr_type, B_TRUE); 32897c478bd9Sstevel@tonic-gate output_prop(fp, PT_VALUE, attrtab->zone_attr_value, B_TRUE); 32907c478bd9Sstevel@tonic-gate } 32917c478bd9Sstevel@tonic-gate 32927c478bd9Sstevel@tonic-gate static void 32937c478bd9Sstevel@tonic-gate info_attr(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 32947c478bd9Sstevel@tonic-gate { 32957c478bd9Sstevel@tonic-gate struct zone_attrtab lookup, user; 32967c478bd9Sstevel@tonic-gate bool output = FALSE; 32977c478bd9Sstevel@tonic-gate 32987c478bd9Sstevel@tonic-gate if (zonecfg_setattrent(handle) != Z_OK) 32997c478bd9Sstevel@tonic-gate return; 33007c478bd9Sstevel@tonic-gate while (zonecfg_getattrent(handle, &lookup) == Z_OK) { 33017c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 33027c478bd9Sstevel@tonic-gate output_attr(fp, &lookup); 33037c478bd9Sstevel@tonic-gate continue; 33047c478bd9Sstevel@tonic-gate } 33057c478bd9Sstevel@tonic-gate if (fill_in_attrtab(cmd, &user, TRUE) != Z_OK) 33067c478bd9Sstevel@tonic-gate continue; 33077c478bd9Sstevel@tonic-gate if (strlen(user.zone_attr_name) > 0 && 33087c478bd9Sstevel@tonic-gate strcmp(user.zone_attr_name, lookup.zone_attr_name) != 0) 33097c478bd9Sstevel@tonic-gate continue; /* no match */ 33107c478bd9Sstevel@tonic-gate if (strlen(user.zone_attr_type) > 0 && 33117c478bd9Sstevel@tonic-gate strcmp(user.zone_attr_type, lookup.zone_attr_type) != 0) 33127c478bd9Sstevel@tonic-gate continue; /* no match */ 33137c478bd9Sstevel@tonic-gate if (strlen(user.zone_attr_value) > 0 && 33147c478bd9Sstevel@tonic-gate strcmp(user.zone_attr_value, lookup.zone_attr_value) != 0) 33157c478bd9Sstevel@tonic-gate continue; /* no match */ 33167c478bd9Sstevel@tonic-gate output_attr(fp, &lookup); 33177c478bd9Sstevel@tonic-gate output = TRUE; 33187c478bd9Sstevel@tonic-gate } 33197c478bd9Sstevel@tonic-gate (void) zonecfg_endattrent(handle); 33207c478bd9Sstevel@tonic-gate /* 33217c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 33227c478bd9Sstevel@tonic-gate * nothing to output. 33237c478bd9Sstevel@tonic-gate */ 33247c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 33257c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 33267c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR)); 33277c478bd9Sstevel@tonic-gate } 33287c478bd9Sstevel@tonic-gate 3329fa9e4066Sahrens static void 3330fa9e4066Sahrens output_ds(FILE *fp, struct zone_dstab *dstab) 3331fa9e4066Sahrens { 3332fa9e4066Sahrens (void) fprintf(fp, "%s:\n", rt_to_str(RT_DATASET)); 3333fa9e4066Sahrens output_prop(fp, PT_NAME, dstab->zone_dataset_name, B_TRUE); 3334fa9e4066Sahrens } 3335fa9e4066Sahrens 3336fa9e4066Sahrens static void 3337fa9e4066Sahrens info_ds(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 3338fa9e4066Sahrens { 3339fa9e4066Sahrens struct zone_dstab lookup, user; 3340fa9e4066Sahrens bool output = FALSE; 3341fa9e4066Sahrens 3342fa9e4066Sahrens if (zonecfg_setdevent(handle) != Z_OK) 3343fa9e4066Sahrens return; 3344fa9e4066Sahrens while (zonecfg_getdsent(handle, &lookup) == Z_OK) { 3345fa9e4066Sahrens if (cmd->cmd_prop_nv_pairs == 0) { 3346fa9e4066Sahrens output_ds(fp, &lookup); 3347fa9e4066Sahrens continue; 3348fa9e4066Sahrens } 3349fa9e4066Sahrens if (fill_in_dstab(cmd, &user, TRUE) != Z_OK) 3350fa9e4066Sahrens continue; 3351fa9e4066Sahrens if (strlen(user.zone_dataset_name) > 0 && 3352fa9e4066Sahrens strcmp(user.zone_dataset_name, 3353fa9e4066Sahrens lookup.zone_dataset_name) != 0) 3354fa9e4066Sahrens continue; /* no match */ 3355fa9e4066Sahrens output_ds(fp, &lookup); 3356fa9e4066Sahrens output = TRUE; 3357fa9e4066Sahrens } 3358fa9e4066Sahrens (void) zonecfg_enddsent(handle); 3359fa9e4066Sahrens /* 3360fa9e4066Sahrens * If a property n/v pair was specified, warn the user if there was 3361fa9e4066Sahrens * nothing to output. 3362fa9e4066Sahrens */ 3363fa9e4066Sahrens if (!output && cmd->cmd_prop_nv_pairs > 0) 3364fa9e4066Sahrens (void) printf(gettext("No such %s resource.\n"), 3365fa9e4066Sahrens rt_to_str(RT_DATASET)); 3366fa9e4066Sahrens } 3367fa9e4066Sahrens 3368fa9e4066Sahrens 33697c478bd9Sstevel@tonic-gate void 33707c478bd9Sstevel@tonic-gate info_func(cmd_t *cmd) 33717c478bd9Sstevel@tonic-gate { 33727c478bd9Sstevel@tonic-gate FILE *fp = stdout; 33737c478bd9Sstevel@tonic-gate bool need_to_close = FALSE; 33747c478bd9Sstevel@tonic-gate char *pager; 33757c478bd9Sstevel@tonic-gate 33767c478bd9Sstevel@tonic-gate assert(cmd != NULL); 33777c478bd9Sstevel@tonic-gate 33787c478bd9Sstevel@tonic-gate if (initialize(TRUE) != Z_OK) 33797c478bd9Sstevel@tonic-gate return; 33807c478bd9Sstevel@tonic-gate 33817c478bd9Sstevel@tonic-gate /* don't page error output */ 33827c478bd9Sstevel@tonic-gate if (interactive_mode) { 33837c478bd9Sstevel@tonic-gate if ((pager = getenv("PAGER")) == NULL) 33847c478bd9Sstevel@tonic-gate pager = PAGER; 33857c478bd9Sstevel@tonic-gate if ((fp = popen(pager, "w")) != NULL) 33867c478bd9Sstevel@tonic-gate need_to_close = TRUE; 33877c478bd9Sstevel@tonic-gate else 33887c478bd9Sstevel@tonic-gate fp = stdout; 33897c478bd9Sstevel@tonic-gate setbuf(fp, NULL); 33907c478bd9Sstevel@tonic-gate } 33917c478bd9Sstevel@tonic-gate 33927c478bd9Sstevel@tonic-gate if (!global_scope) { 33937c478bd9Sstevel@tonic-gate switch (resource_scope) { 33947c478bd9Sstevel@tonic-gate case RT_FS: 33957c478bd9Sstevel@tonic-gate output_fs(fp, &in_progress_fstab); 33967c478bd9Sstevel@tonic-gate break; 33977c478bd9Sstevel@tonic-gate case RT_IPD: 33987c478bd9Sstevel@tonic-gate output_ipd(fp, &in_progress_ipdtab); 33997c478bd9Sstevel@tonic-gate break; 34007c478bd9Sstevel@tonic-gate case RT_NET: 34017c478bd9Sstevel@tonic-gate output_net(fp, &in_progress_nwiftab); 34027c478bd9Sstevel@tonic-gate break; 34037c478bd9Sstevel@tonic-gate case RT_DEVICE: 34047c478bd9Sstevel@tonic-gate output_dev(fp, &in_progress_devtab); 34057c478bd9Sstevel@tonic-gate break; 34067c478bd9Sstevel@tonic-gate case RT_RCTL: 34077c478bd9Sstevel@tonic-gate output_rctl(fp, &in_progress_rctltab); 34087c478bd9Sstevel@tonic-gate break; 34097c478bd9Sstevel@tonic-gate case RT_ATTR: 34107c478bd9Sstevel@tonic-gate output_attr(fp, &in_progress_attrtab); 34117c478bd9Sstevel@tonic-gate break; 3412fa9e4066Sahrens case RT_DATASET: 3413fa9e4066Sahrens output_ds(fp, &in_progress_dstab); 3414fa9e4066Sahrens break; 34157c478bd9Sstevel@tonic-gate } 34167c478bd9Sstevel@tonic-gate goto cleanup; 34177c478bd9Sstevel@tonic-gate } 34187c478bd9Sstevel@tonic-gate 34197c478bd9Sstevel@tonic-gate switch (cmd->cmd_res_type) { 34207c478bd9Sstevel@tonic-gate case RT_UNKNOWN: 3421087719fdSdp info_zonename(handle, fp); 34227c478bd9Sstevel@tonic-gate info_zonepath(handle, fp); 34237c478bd9Sstevel@tonic-gate info_autoboot(handle, fp); 34247c478bd9Sstevel@tonic-gate info_pool(handle, fp); 3425*ffbafc53Scomay info_limitpriv(handle, fp); 34267c478bd9Sstevel@tonic-gate info_ipd(handle, fp, cmd); 34277c478bd9Sstevel@tonic-gate info_fs(handle, fp, cmd); 34287c478bd9Sstevel@tonic-gate info_net(handle, fp, cmd); 34297c478bd9Sstevel@tonic-gate info_dev(handle, fp, cmd); 34307c478bd9Sstevel@tonic-gate info_rctl(handle, fp, cmd); 34317c478bd9Sstevel@tonic-gate info_attr(handle, fp, cmd); 3432fa9e4066Sahrens info_ds(handle, fp, cmd); 34337c478bd9Sstevel@tonic-gate break; 3434087719fdSdp case RT_ZONENAME: 3435087719fdSdp info_zonename(handle, fp); 3436087719fdSdp break; 34377c478bd9Sstevel@tonic-gate case RT_ZONEPATH: 34387c478bd9Sstevel@tonic-gate info_zonepath(handle, fp); 34397c478bd9Sstevel@tonic-gate break; 34407c478bd9Sstevel@tonic-gate case RT_AUTOBOOT: 34417c478bd9Sstevel@tonic-gate info_autoboot(handle, fp); 34427c478bd9Sstevel@tonic-gate break; 34437c478bd9Sstevel@tonic-gate case RT_POOL: 34447c478bd9Sstevel@tonic-gate info_pool(handle, fp); 34457c478bd9Sstevel@tonic-gate break; 3446*ffbafc53Scomay case RT_LIMITPRIV: 3447*ffbafc53Scomay info_limitpriv(handle, fp); 3448*ffbafc53Scomay break; 34497c478bd9Sstevel@tonic-gate case RT_FS: 34507c478bd9Sstevel@tonic-gate info_fs(handle, fp, cmd); 34517c478bd9Sstevel@tonic-gate break; 34527c478bd9Sstevel@tonic-gate case RT_IPD: 34537c478bd9Sstevel@tonic-gate info_ipd(handle, fp, cmd); 34547c478bd9Sstevel@tonic-gate break; 34557c478bd9Sstevel@tonic-gate case RT_NET: 34567c478bd9Sstevel@tonic-gate info_net(handle, fp, cmd); 34577c478bd9Sstevel@tonic-gate break; 34587c478bd9Sstevel@tonic-gate case RT_DEVICE: 34597c478bd9Sstevel@tonic-gate info_dev(handle, fp, cmd); 34607c478bd9Sstevel@tonic-gate break; 34617c478bd9Sstevel@tonic-gate case RT_RCTL: 34627c478bd9Sstevel@tonic-gate info_rctl(handle, fp, cmd); 34637c478bd9Sstevel@tonic-gate break; 34647c478bd9Sstevel@tonic-gate case RT_ATTR: 34657c478bd9Sstevel@tonic-gate info_attr(handle, fp, cmd); 34667c478bd9Sstevel@tonic-gate break; 3467fa9e4066Sahrens case RT_DATASET: 3468fa9e4066Sahrens info_ds(handle, fp, cmd); 3469fa9e4066Sahrens break; 34707c478bd9Sstevel@tonic-gate default: 34717c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(cmd->cmd_res_type), Z_NO_RESOURCE_TYPE, 34727c478bd9Sstevel@tonic-gate TRUE); 34737c478bd9Sstevel@tonic-gate } 34747c478bd9Sstevel@tonic-gate 34757c478bd9Sstevel@tonic-gate cleanup: 34767c478bd9Sstevel@tonic-gate if (need_to_close) 34777c478bd9Sstevel@tonic-gate (void) pclose(fp); 34787c478bd9Sstevel@tonic-gate } 34797c478bd9Sstevel@tonic-gate 3480087719fdSdp /* 3481087719fdSdp * Helper function for verify-- checks that a required string property 3482087719fdSdp * exists. 3483087719fdSdp */ 3484087719fdSdp static void 3485087719fdSdp check_reqd_prop(char *attr, int rt, int pt, int *ret_val) 34867c478bd9Sstevel@tonic-gate { 3487087719fdSdp if (strlen(attr) == 0) { 3488087719fdSdp zerr(gettext("%s: %s not specified"), rt_to_str(rt), 3489087719fdSdp pt_to_str(pt)); 3490087719fdSdp saw_error = TRUE; 3491087719fdSdp if (*ret_val == Z_OK) 3492087719fdSdp *ret_val = Z_REQD_PROPERTY_MISSING; 34937c478bd9Sstevel@tonic-gate } 34947c478bd9Sstevel@tonic-gate } 34957c478bd9Sstevel@tonic-gate 34967c478bd9Sstevel@tonic-gate /* 34977c478bd9Sstevel@tonic-gate * See the DTD for which attributes are required for which resources. 34987c478bd9Sstevel@tonic-gate * 34997c478bd9Sstevel@tonic-gate * This function can be called by commit_func(), which needs to save things, 35007c478bd9Sstevel@tonic-gate * in addition to the general call from parse_and_run(), which doesn't need 35017c478bd9Sstevel@tonic-gate * things saved. Since the parameters are standardized, we distinguish by 35027c478bd9Sstevel@tonic-gate * having commit_func() call here with cmd->cmd_arg set to "save" to indicate 35037c478bd9Sstevel@tonic-gate * that a save is needed. 35047c478bd9Sstevel@tonic-gate */ 35057c478bd9Sstevel@tonic-gate void 35067c478bd9Sstevel@tonic-gate verify_func(cmd_t *cmd) 35077c478bd9Sstevel@tonic-gate { 35087c478bd9Sstevel@tonic-gate struct zone_nwiftab nwiftab; 35097c478bd9Sstevel@tonic-gate struct zone_fstab fstab; 35107c478bd9Sstevel@tonic-gate struct zone_attrtab attrtab; 35117c478bd9Sstevel@tonic-gate struct zone_rctltab rctltab; 3512fa9e4066Sahrens struct zone_dstab dstab; 35137c478bd9Sstevel@tonic-gate char zonepath[MAXPATHLEN]; 35147c478bd9Sstevel@tonic-gate int err, ret_val = Z_OK, arg; 35157c478bd9Sstevel@tonic-gate bool save = FALSE; 35167c478bd9Sstevel@tonic-gate 35177c478bd9Sstevel@tonic-gate optind = 0; 35187c478bd9Sstevel@tonic-gate if ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 35197c478bd9Sstevel@tonic-gate switch (arg) { 35207c478bd9Sstevel@tonic-gate case '?': 35217c478bd9Sstevel@tonic-gate longer_usage(CMD_VERIFY); 35227c478bd9Sstevel@tonic-gate return; 35237c478bd9Sstevel@tonic-gate default: 35247c478bd9Sstevel@tonic-gate short_usage(CMD_VERIFY); 35257c478bd9Sstevel@tonic-gate return; 35267c478bd9Sstevel@tonic-gate } 35277c478bd9Sstevel@tonic-gate } 35287c478bd9Sstevel@tonic-gate if (optind > cmd->cmd_argc) { 35297c478bd9Sstevel@tonic-gate short_usage(CMD_VERIFY); 35307c478bd9Sstevel@tonic-gate return; 35317c478bd9Sstevel@tonic-gate } 35327c478bd9Sstevel@tonic-gate 35337c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_VERIFY)) 35347c478bd9Sstevel@tonic-gate return; 35357c478bd9Sstevel@tonic-gate 35367c478bd9Sstevel@tonic-gate assert(cmd != NULL); 35377c478bd9Sstevel@tonic-gate 35387c478bd9Sstevel@tonic-gate if (cmd->cmd_argc > 0 && (strcmp(cmd->cmd_argv[0], "save") == 0)) 35397c478bd9Sstevel@tonic-gate save = TRUE; 35407c478bd9Sstevel@tonic-gate if (initialize(TRUE) != Z_OK) 35417c478bd9Sstevel@tonic-gate return; 35427c478bd9Sstevel@tonic-gate 35437c478bd9Sstevel@tonic-gate if (zonecfg_get_zonepath(handle, zonepath, sizeof (zonepath)) != Z_OK) { 3544087719fdSdp zerr(gettext("%s not specified"), pt_to_str(PT_ZONEPATH)); 35457c478bd9Sstevel@tonic-gate ret_val = Z_REQD_RESOURCE_MISSING; 35467c478bd9Sstevel@tonic-gate saw_error = TRUE; 35477c478bd9Sstevel@tonic-gate } 35487c478bd9Sstevel@tonic-gate if (strlen(zonepath) == 0) { 3549087719fdSdp zerr(gettext("%s cannot be empty."), pt_to_str(PT_ZONEPATH)); 35507c478bd9Sstevel@tonic-gate ret_val = Z_REQD_RESOURCE_MISSING; 35517c478bd9Sstevel@tonic-gate saw_error = TRUE; 35527c478bd9Sstevel@tonic-gate } 35537c478bd9Sstevel@tonic-gate 35547c478bd9Sstevel@tonic-gate if ((err = zonecfg_setipdent(handle)) != Z_OK) { 35557c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 35567c478bd9Sstevel@tonic-gate return; 35577c478bd9Sstevel@tonic-gate } 35587c478bd9Sstevel@tonic-gate while (zonecfg_getipdent(handle, &fstab) == Z_OK) { 3559087719fdSdp check_reqd_prop(fstab.zone_fs_dir, RT_IPD, PT_DIR, &ret_val); 35607c478bd9Sstevel@tonic-gate } 35617c478bd9Sstevel@tonic-gate (void) zonecfg_endipdent(handle); 35627c478bd9Sstevel@tonic-gate 35637c478bd9Sstevel@tonic-gate if ((err = zonecfg_setfsent(handle)) != Z_OK) { 35647c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 35657c478bd9Sstevel@tonic-gate return; 35667c478bd9Sstevel@tonic-gate } 35677c478bd9Sstevel@tonic-gate while (zonecfg_getfsent(handle, &fstab) == Z_OK) { 3568087719fdSdp check_reqd_prop(fstab.zone_fs_dir, RT_FS, PT_DIR, &ret_val); 3569087719fdSdp check_reqd_prop(fstab.zone_fs_special, RT_FS, PT_SPECIAL, 3570087719fdSdp &ret_val); 3571087719fdSdp check_reqd_prop(fstab.zone_fs_type, RT_FS, PT_TYPE, &ret_val); 3572087719fdSdp 35737c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(fstab.zone_fs_options); 35747c478bd9Sstevel@tonic-gate } 35757c478bd9Sstevel@tonic-gate (void) zonecfg_endfsent(handle); 35767c478bd9Sstevel@tonic-gate 35777c478bd9Sstevel@tonic-gate if ((err = zonecfg_setnwifent(handle)) != Z_OK) { 35787c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 35797c478bd9Sstevel@tonic-gate return; 35807c478bd9Sstevel@tonic-gate } 35817c478bd9Sstevel@tonic-gate while (zonecfg_getnwifent(handle, &nwiftab) == Z_OK) { 3582087719fdSdp check_reqd_prop(nwiftab.zone_nwif_address, RT_NET, 3583087719fdSdp PT_ADDRESS, &ret_val); 3584087719fdSdp check_reqd_prop(nwiftab.zone_nwif_physical, RT_NET, 3585087719fdSdp PT_PHYSICAL, &ret_val); 35867c478bd9Sstevel@tonic-gate } 35877c478bd9Sstevel@tonic-gate (void) zonecfg_endnwifent(handle); 35887c478bd9Sstevel@tonic-gate 35897c478bd9Sstevel@tonic-gate if ((err = zonecfg_setrctlent(handle)) != Z_OK) { 35907c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 35917c478bd9Sstevel@tonic-gate return; 35927c478bd9Sstevel@tonic-gate } 35937c478bd9Sstevel@tonic-gate while (zonecfg_getrctlent(handle, &rctltab) == Z_OK) { 3594087719fdSdp check_reqd_prop(rctltab.zone_rctl_name, RT_RCTL, PT_NAME, 3595087719fdSdp &ret_val); 3596087719fdSdp 35977c478bd9Sstevel@tonic-gate if (rctltab.zone_rctl_valptr == NULL) { 35987c478bd9Sstevel@tonic-gate zerr(gettext("%s: no %s specified"), 35997c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL), pt_to_str(PT_VALUE)); 36007c478bd9Sstevel@tonic-gate saw_error = TRUE; 36017c478bd9Sstevel@tonic-gate if (ret_val == Z_OK) 36027c478bd9Sstevel@tonic-gate ret_val = Z_REQD_PROPERTY_MISSING; 36037c478bd9Sstevel@tonic-gate } else { 36047c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr); 36057c478bd9Sstevel@tonic-gate } 36067c478bd9Sstevel@tonic-gate } 36077c478bd9Sstevel@tonic-gate (void) zonecfg_endrctlent(handle); 36087c478bd9Sstevel@tonic-gate 36097c478bd9Sstevel@tonic-gate if ((err = zonecfg_setattrent(handle)) != Z_OK) { 36107c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 36117c478bd9Sstevel@tonic-gate return; 36127c478bd9Sstevel@tonic-gate } 36137c478bd9Sstevel@tonic-gate while (zonecfg_getattrent(handle, &attrtab) == Z_OK) { 3614087719fdSdp check_reqd_prop(attrtab.zone_attr_name, RT_ATTR, PT_NAME, 3615087719fdSdp &ret_val); 3616087719fdSdp check_reqd_prop(attrtab.zone_attr_type, RT_ATTR, PT_TYPE, 3617087719fdSdp &ret_val); 3618087719fdSdp check_reqd_prop(attrtab.zone_attr_value, RT_ATTR, PT_VALUE, 3619087719fdSdp &ret_val); 36207c478bd9Sstevel@tonic-gate } 36217c478bd9Sstevel@tonic-gate (void) zonecfg_endattrent(handle); 36227c478bd9Sstevel@tonic-gate 3623fa9e4066Sahrens if ((err = zonecfg_setdsent(handle)) != Z_OK) { 3624fa9e4066Sahrens zone_perror(zone, err, TRUE); 3625fa9e4066Sahrens return; 3626fa9e4066Sahrens } 3627fa9e4066Sahrens while (zonecfg_getdsent(handle, &dstab) == Z_OK) { 3628fa9e4066Sahrens if (strlen(dstab.zone_dataset_name) == 0) { 3629fa9e4066Sahrens zerr("%s: %s %s", rt_to_str(RT_DATASET), 3630fa9e4066Sahrens pt_to_str(PT_NAME), gettext("not specified")); 3631fa9e4066Sahrens saw_error = TRUE; 3632fa9e4066Sahrens if (ret_val == Z_OK) 3633fa9e4066Sahrens ret_val = Z_REQD_PROPERTY_MISSING; 3634fa9e4066Sahrens } else if (!zfs_name_valid(dstab.zone_dataset_name, 3635fa9e4066Sahrens ZFS_TYPE_FILESYSTEM)) { 3636fa9e4066Sahrens zerr("%s: %s %s", rt_to_str(RT_DATASET), 3637fa9e4066Sahrens pt_to_str(PT_NAME), gettext("invalid")); 3638fa9e4066Sahrens saw_error = TRUE; 3639fa9e4066Sahrens if (ret_val == Z_OK) 3640fa9e4066Sahrens ret_val = Z_BAD_PROPERTY; 3641fa9e4066Sahrens } 3642fa9e4066Sahrens 3643fa9e4066Sahrens } 3644fa9e4066Sahrens (void) zonecfg_enddsent(handle); 3645fa9e4066Sahrens 36467c478bd9Sstevel@tonic-gate if (!global_scope) { 36477c478bd9Sstevel@tonic-gate zerr(gettext("resource specification incomplete")); 36487c478bd9Sstevel@tonic-gate saw_error = TRUE; 36497c478bd9Sstevel@tonic-gate if (ret_val == Z_OK) 36507c478bd9Sstevel@tonic-gate ret_val = Z_INSUFFICIENT_SPEC; 36517c478bd9Sstevel@tonic-gate } 36527c478bd9Sstevel@tonic-gate 36537c478bd9Sstevel@tonic-gate if (save) { 3654087719fdSdp if (ret_val == Z_OK) { 3655087719fdSdp if ((ret_val = zonecfg_save(handle)) == Z_OK) { 3656087719fdSdp need_to_commit = FALSE; 3657087719fdSdp (void) strlcpy(revert_zone, zone, 3658087719fdSdp sizeof (revert_zone)); 3659087719fdSdp } 3660087719fdSdp } else { 3661087719fdSdp zerr(gettext("Zone %s failed to verify"), zone); 3662087719fdSdp } 36637c478bd9Sstevel@tonic-gate } 36647c478bd9Sstevel@tonic-gate if (ret_val != Z_OK) 36657c478bd9Sstevel@tonic-gate zone_perror(zone, ret_val, TRUE); 36667c478bd9Sstevel@tonic-gate } 36677c478bd9Sstevel@tonic-gate 36687c478bd9Sstevel@tonic-gate void 36697c478bd9Sstevel@tonic-gate cancel_func(cmd_t *cmd) 36707c478bd9Sstevel@tonic-gate { 36717c478bd9Sstevel@tonic-gate int arg; 36727c478bd9Sstevel@tonic-gate 36737c478bd9Sstevel@tonic-gate assert(cmd != NULL); 36747c478bd9Sstevel@tonic-gate 36757c478bd9Sstevel@tonic-gate optind = 0; 36767c478bd9Sstevel@tonic-gate if ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 36777c478bd9Sstevel@tonic-gate switch (arg) { 36787c478bd9Sstevel@tonic-gate case '?': 36797c478bd9Sstevel@tonic-gate longer_usage(CMD_CANCEL); 36807c478bd9Sstevel@tonic-gate return; 36817c478bd9Sstevel@tonic-gate default: 36827c478bd9Sstevel@tonic-gate short_usage(CMD_CANCEL); 36837c478bd9Sstevel@tonic-gate return; 36847c478bd9Sstevel@tonic-gate } 36857c478bd9Sstevel@tonic-gate } 36867c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 36877c478bd9Sstevel@tonic-gate short_usage(CMD_CANCEL); 36887c478bd9Sstevel@tonic-gate return; 36897c478bd9Sstevel@tonic-gate } 36907c478bd9Sstevel@tonic-gate 36917c478bd9Sstevel@tonic-gate if (global_scope) 36927c478bd9Sstevel@tonic-gate scope_usage(CMD_CANCEL); 36937c478bd9Sstevel@tonic-gate global_scope = TRUE; 36947c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(in_progress_fstab.zone_fs_options); 36957c478bd9Sstevel@tonic-gate bzero(&in_progress_fstab, sizeof (in_progress_fstab)); 36967c478bd9Sstevel@tonic-gate bzero(&in_progress_nwiftab, sizeof (in_progress_nwiftab)); 3697fa9e4066Sahrens bzero(&in_progress_ipdtab, sizeof (in_progress_ipdtab)); 36987c478bd9Sstevel@tonic-gate bzero(&in_progress_devtab, sizeof (in_progress_devtab)); 36997c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(in_progress_rctltab.zone_rctl_valptr); 37007c478bd9Sstevel@tonic-gate bzero(&in_progress_rctltab, sizeof (in_progress_rctltab)); 37017c478bd9Sstevel@tonic-gate bzero(&in_progress_attrtab, sizeof (in_progress_attrtab)); 3702fa9e4066Sahrens bzero(&in_progress_dstab, sizeof (in_progress_dstab)); 37037c478bd9Sstevel@tonic-gate } 37047c478bd9Sstevel@tonic-gate 37057c478bd9Sstevel@tonic-gate static int 37067c478bd9Sstevel@tonic-gate validate_attr_name(char *name) 37077c478bd9Sstevel@tonic-gate { 37087c478bd9Sstevel@tonic-gate int i; 37097c478bd9Sstevel@tonic-gate 37107c478bd9Sstevel@tonic-gate if (!isalnum(name[0])) { 37117c478bd9Sstevel@tonic-gate zerr(gettext("Invalid %s %s %s: must start with an alpha-" 37127c478bd9Sstevel@tonic-gate "numeric character."), rt_to_str(RT_ATTR), 37137c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), name); 37147c478bd9Sstevel@tonic-gate return (Z_INVAL); 37157c478bd9Sstevel@tonic-gate } 37167c478bd9Sstevel@tonic-gate for (i = 1; name[i]; i++) 37177c478bd9Sstevel@tonic-gate if (!isalnum(name[i]) && name[i] != '-' && name[i] != '.') { 37187c478bd9Sstevel@tonic-gate zerr(gettext("Invalid %s %s %s: can only contain " 37197c478bd9Sstevel@tonic-gate "alpha-numeric characters, plus '-' and '.'."), 37207c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_NAME), name); 37217c478bd9Sstevel@tonic-gate return (Z_INVAL); 37227c478bd9Sstevel@tonic-gate } 37237c478bd9Sstevel@tonic-gate return (Z_OK); 37247c478bd9Sstevel@tonic-gate } 37257c478bd9Sstevel@tonic-gate 37267c478bd9Sstevel@tonic-gate static int 37277c478bd9Sstevel@tonic-gate validate_attr_type_val(struct zone_attrtab *attrtab) 37287c478bd9Sstevel@tonic-gate { 37297c478bd9Sstevel@tonic-gate boolean_t boolval; 37307c478bd9Sstevel@tonic-gate int64_t intval; 37317c478bd9Sstevel@tonic-gate char strval[MAXNAMELEN]; 37327c478bd9Sstevel@tonic-gate uint64_t uintval; 37337c478bd9Sstevel@tonic-gate 37347c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "boolean") == 0) { 37357c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_boolean(attrtab, &boolval) == Z_OK) 37367c478bd9Sstevel@tonic-gate return (Z_OK); 37377c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 37387c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "boolean"); 37397c478bd9Sstevel@tonic-gate return (Z_ERR); 37407c478bd9Sstevel@tonic-gate } 37417c478bd9Sstevel@tonic-gate 37427c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "int") == 0) { 37437c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_int(attrtab, &intval) == Z_OK) 37447c478bd9Sstevel@tonic-gate return (Z_OK); 37457c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 37467c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "int"); 37477c478bd9Sstevel@tonic-gate return (Z_ERR); 37487c478bd9Sstevel@tonic-gate } 37497c478bd9Sstevel@tonic-gate 37507c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "string") == 0) { 37517c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_string(attrtab, strval, 37527c478bd9Sstevel@tonic-gate sizeof (strval)) == Z_OK) 37537c478bd9Sstevel@tonic-gate return (Z_OK); 37547c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 37557c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "string"); 37567c478bd9Sstevel@tonic-gate return (Z_ERR); 37577c478bd9Sstevel@tonic-gate } 37587c478bd9Sstevel@tonic-gate 37597c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "uint") == 0) { 37607c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_uint(attrtab, &uintval) == Z_OK) 37617c478bd9Sstevel@tonic-gate return (Z_OK); 37627c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 37637c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "uint"); 37647c478bd9Sstevel@tonic-gate return (Z_ERR); 37657c478bd9Sstevel@tonic-gate } 37667c478bd9Sstevel@tonic-gate 37677c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s %s '%s'"), rt_to_str(RT_ATTR), 37687c478bd9Sstevel@tonic-gate pt_to_str(PT_TYPE), attrtab->zone_attr_type); 37697c478bd9Sstevel@tonic-gate return (Z_ERR); 37707c478bd9Sstevel@tonic-gate } 37717c478bd9Sstevel@tonic-gate 3772087719fdSdp /* 3773087719fdSdp * Helper function for end_func-- checks the existence of a given property 3774087719fdSdp * and emits a message if not specified. 3775087719fdSdp */ 3776087719fdSdp static int 3777087719fdSdp end_check_reqd(char *attr, int pt, bool *validation_failed) 3778087719fdSdp { 3779087719fdSdp if (strlen(attr) == 0) { 3780087719fdSdp *validation_failed = TRUE; 3781087719fdSdp zerr(gettext("%s not specified"), pt_to_str(pt)); 3782087719fdSdp return (Z_ERR); 3783087719fdSdp } 3784087719fdSdp return (Z_OK); 3785087719fdSdp } 3786087719fdSdp 37877c478bd9Sstevel@tonic-gate void 37887c478bd9Sstevel@tonic-gate end_func(cmd_t *cmd) 37897c478bd9Sstevel@tonic-gate { 37907c478bd9Sstevel@tonic-gate bool validation_failed = FALSE; 37917c478bd9Sstevel@tonic-gate struct zone_fstab tmp_fstab; 37927c478bd9Sstevel@tonic-gate struct zone_nwiftab tmp_nwiftab; 37937c478bd9Sstevel@tonic-gate struct zone_devtab tmp_devtab; 37947c478bd9Sstevel@tonic-gate struct zone_rctltab tmp_rctltab; 37957c478bd9Sstevel@tonic-gate struct zone_attrtab tmp_attrtab; 3796fa9e4066Sahrens struct zone_dstab tmp_dstab; 37977c478bd9Sstevel@tonic-gate int err, arg; 37987c478bd9Sstevel@tonic-gate 37997c478bd9Sstevel@tonic-gate assert(cmd != NULL); 38007c478bd9Sstevel@tonic-gate 38017c478bd9Sstevel@tonic-gate optind = 0; 38027c478bd9Sstevel@tonic-gate if ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 38037c478bd9Sstevel@tonic-gate switch (arg) { 38047c478bd9Sstevel@tonic-gate case '?': 38057c478bd9Sstevel@tonic-gate longer_usage(CMD_END); 38067c478bd9Sstevel@tonic-gate return; 38077c478bd9Sstevel@tonic-gate default: 38087c478bd9Sstevel@tonic-gate short_usage(CMD_END); 38097c478bd9Sstevel@tonic-gate return; 38107c478bd9Sstevel@tonic-gate } 38117c478bd9Sstevel@tonic-gate } 38127c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 38137c478bd9Sstevel@tonic-gate short_usage(CMD_END); 38147c478bd9Sstevel@tonic-gate return; 38157c478bd9Sstevel@tonic-gate } 38167c478bd9Sstevel@tonic-gate 38177c478bd9Sstevel@tonic-gate if (global_scope) { 38187c478bd9Sstevel@tonic-gate scope_usage(CMD_END); 38197c478bd9Sstevel@tonic-gate return; 38207c478bd9Sstevel@tonic-gate } 38217c478bd9Sstevel@tonic-gate 38227c478bd9Sstevel@tonic-gate assert(end_op == CMD_ADD || end_op == CMD_SELECT); 38237c478bd9Sstevel@tonic-gate 38247c478bd9Sstevel@tonic-gate switch (resource_scope) { 38257c478bd9Sstevel@tonic-gate case RT_FS: 38267c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 3827087719fdSdp if (end_check_reqd(in_progress_fstab.zone_fs_dir, 3828087719fdSdp PT_DIR, &validation_failed) == Z_OK) { 3829087719fdSdp if (in_progress_fstab.zone_fs_dir[0] != '/') { 3830087719fdSdp zerr(gettext("%s %s is not an absolute path."), 3831087719fdSdp pt_to_str(PT_DIR), 3832087719fdSdp in_progress_fstab.zone_fs_dir); 38337c478bd9Sstevel@tonic-gate validation_failed = TRUE; 38347c478bd9Sstevel@tonic-gate } 38357c478bd9Sstevel@tonic-gate } 3836087719fdSdp 3837087719fdSdp (void) end_check_reqd(in_progress_fstab.zone_fs_special, 3838087719fdSdp PT_SPECIAL, &validation_failed); 3839087719fdSdp 38407c478bd9Sstevel@tonic-gate if (in_progress_fstab.zone_fs_raw[0] != '\0' && 38417c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_raw[0] != '/') { 3842087719fdSdp zerr(gettext("%s %s is not an absolute path."), 3843087719fdSdp pt_to_str(PT_RAW), 3844087719fdSdp in_progress_fstab.zone_fs_raw); 38457c478bd9Sstevel@tonic-gate validation_failed = TRUE; 38467c478bd9Sstevel@tonic-gate } 3847087719fdSdp 3848087719fdSdp (void) end_check_reqd(in_progress_fstab.zone_fs_type, PT_TYPE, 3849087719fdSdp &validation_failed); 3850087719fdSdp 3851087719fdSdp if (validation_failed) { 38527c478bd9Sstevel@tonic-gate saw_error = TRUE; 38537c478bd9Sstevel@tonic-gate return; 3854087719fdSdp } 3855087719fdSdp 38567c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 38577c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 38587c478bd9Sstevel@tonic-gate bzero(&tmp_fstab, sizeof (tmp_fstab)); 38597c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_fstab.zone_fs_dir, 38607c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_dir, 38617c478bd9Sstevel@tonic-gate sizeof (tmp_fstab.zone_fs_dir)); 38627c478bd9Sstevel@tonic-gate err = zonecfg_lookup_filesystem(handle, &tmp_fstab); 38637c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(tmp_fstab.zone_fs_options); 38647c478bd9Sstevel@tonic-gate if (err == Z_OK) { 38657c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource " 38667c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 38677c478bd9Sstevel@tonic-gate rt_to_str(RT_FS), pt_to_str(PT_DIR), 38687c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_dir); 38697c478bd9Sstevel@tonic-gate saw_error = TRUE; 38707c478bd9Sstevel@tonic-gate return; 38717c478bd9Sstevel@tonic-gate } 38727c478bd9Sstevel@tonic-gate err = zonecfg_add_filesystem(handle, 38737c478bd9Sstevel@tonic-gate &in_progress_fstab); 38747c478bd9Sstevel@tonic-gate } else { 38757c478bd9Sstevel@tonic-gate err = zonecfg_modify_filesystem(handle, &old_fstab, 38767c478bd9Sstevel@tonic-gate &in_progress_fstab); 38777c478bd9Sstevel@tonic-gate } 38787c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(in_progress_fstab.zone_fs_options); 38797c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_options = NULL; 38807c478bd9Sstevel@tonic-gate break; 3881087719fdSdp 38827c478bd9Sstevel@tonic-gate case RT_IPD: 38837c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 3884087719fdSdp if (end_check_reqd(in_progress_ipdtab.zone_fs_dir, PT_DIR, 3885087719fdSdp &validation_failed) == Z_OK) { 3886087719fdSdp if (in_progress_ipdtab.zone_fs_dir[0] != '/') { 3887087719fdSdp zerr(gettext("%s %s is not an absolute path."), 3888087719fdSdp pt_to_str(PT_DIR), 3889087719fdSdp in_progress_ipdtab.zone_fs_dir); 38907c478bd9Sstevel@tonic-gate validation_failed = TRUE; 38917c478bd9Sstevel@tonic-gate } 3892087719fdSdp } 3893087719fdSdp if (validation_failed) { 3894087719fdSdp saw_error = TRUE; 38957c478bd9Sstevel@tonic-gate return; 3896087719fdSdp } 3897087719fdSdp 38987c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 38997c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 39007c478bd9Sstevel@tonic-gate bzero(&tmp_fstab, sizeof (tmp_fstab)); 39017c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_fstab.zone_fs_dir, 39027c478bd9Sstevel@tonic-gate in_progress_ipdtab.zone_fs_dir, 39037c478bd9Sstevel@tonic-gate sizeof (tmp_fstab.zone_fs_dir)); 39047c478bd9Sstevel@tonic-gate err = zonecfg_lookup_ipd(handle, &tmp_fstab); 39057c478bd9Sstevel@tonic-gate if (err == Z_OK) { 39067c478bd9Sstevel@tonic-gate zerr(gettext("An %s resource " 39077c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 39087c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD), pt_to_str(PT_DIR), 39097c478bd9Sstevel@tonic-gate in_progress_ipdtab.zone_fs_dir); 39107c478bd9Sstevel@tonic-gate saw_error = TRUE; 39117c478bd9Sstevel@tonic-gate return; 39127c478bd9Sstevel@tonic-gate } 39137c478bd9Sstevel@tonic-gate err = zonecfg_add_ipd(handle, &in_progress_ipdtab); 39147c478bd9Sstevel@tonic-gate } else { 39157c478bd9Sstevel@tonic-gate err = zonecfg_modify_ipd(handle, &old_ipdtab, 39167c478bd9Sstevel@tonic-gate &in_progress_ipdtab); 39177c478bd9Sstevel@tonic-gate } 39187c478bd9Sstevel@tonic-gate break; 39197c478bd9Sstevel@tonic-gate case RT_NET: 39207c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 3921087719fdSdp (void) end_check_reqd(in_progress_nwiftab.zone_nwif_physical, 3922087719fdSdp PT_PHYSICAL, &validation_failed); 3923087719fdSdp (void) end_check_reqd(in_progress_nwiftab.zone_nwif_address, 3924087719fdSdp PT_ADDRESS, &validation_failed); 3925087719fdSdp 3926087719fdSdp if (validation_failed) { 39277c478bd9Sstevel@tonic-gate saw_error = TRUE; 39287c478bd9Sstevel@tonic-gate return; 3929087719fdSdp } 3930087719fdSdp 39317c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 39327c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 39337c478bd9Sstevel@tonic-gate bzero(&tmp_nwiftab, sizeof (tmp_nwiftab)); 39347c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_nwiftab.zone_nwif_address, 39357c478bd9Sstevel@tonic-gate in_progress_nwiftab.zone_nwif_address, 39367c478bd9Sstevel@tonic-gate sizeof (tmp_nwiftab.zone_nwif_address)); 39377c478bd9Sstevel@tonic-gate if (zonecfg_lookup_nwif(handle, &tmp_nwiftab) == Z_OK) { 39387c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource " 39397c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 39407c478bd9Sstevel@tonic-gate rt_to_str(RT_NET), pt_to_str(PT_ADDRESS), 39417c478bd9Sstevel@tonic-gate in_progress_nwiftab.zone_nwif_address); 39427c478bd9Sstevel@tonic-gate saw_error = TRUE; 39437c478bd9Sstevel@tonic-gate return; 39447c478bd9Sstevel@tonic-gate } 39457c478bd9Sstevel@tonic-gate err = zonecfg_add_nwif(handle, &in_progress_nwiftab); 39467c478bd9Sstevel@tonic-gate } else { 39477c478bd9Sstevel@tonic-gate err = zonecfg_modify_nwif(handle, &old_nwiftab, 39487c478bd9Sstevel@tonic-gate &in_progress_nwiftab); 39497c478bd9Sstevel@tonic-gate } 39507c478bd9Sstevel@tonic-gate break; 3951087719fdSdp 39527c478bd9Sstevel@tonic-gate case RT_DEVICE: 39537c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 3954087719fdSdp (void) end_check_reqd(in_progress_devtab.zone_dev_match, 3955087719fdSdp PT_MATCH, &validation_failed); 3956087719fdSdp 3957087719fdSdp if (validation_failed) { 39587c478bd9Sstevel@tonic-gate saw_error = TRUE; 39597c478bd9Sstevel@tonic-gate return; 3960087719fdSdp } 3961087719fdSdp 39627c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 39637c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 39647c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_devtab.zone_dev_match, 39657c478bd9Sstevel@tonic-gate in_progress_devtab.zone_dev_match, 39667c478bd9Sstevel@tonic-gate sizeof (tmp_devtab.zone_dev_match)); 39677c478bd9Sstevel@tonic-gate if (zonecfg_lookup_dev(handle, &tmp_devtab) == Z_OK) { 39687c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource with the %s '%s' " 39697c478bd9Sstevel@tonic-gate "already exists."), rt_to_str(RT_DEVICE), 39707c478bd9Sstevel@tonic-gate pt_to_str(PT_MATCH), 39717c478bd9Sstevel@tonic-gate in_progress_devtab.zone_dev_match); 39727c478bd9Sstevel@tonic-gate saw_error = TRUE; 39737c478bd9Sstevel@tonic-gate return; 39747c478bd9Sstevel@tonic-gate } 39757c478bd9Sstevel@tonic-gate err = zonecfg_add_dev(handle, &in_progress_devtab); 39767c478bd9Sstevel@tonic-gate } else { 39777c478bd9Sstevel@tonic-gate err = zonecfg_modify_dev(handle, &old_devtab, 39787c478bd9Sstevel@tonic-gate &in_progress_devtab); 39797c478bd9Sstevel@tonic-gate } 39807c478bd9Sstevel@tonic-gate break; 3981087719fdSdp 39827c478bd9Sstevel@tonic-gate case RT_RCTL: 39837c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 3984087719fdSdp (void) end_check_reqd(in_progress_rctltab.zone_rctl_name, 3985087719fdSdp PT_NAME, &validation_failed); 3986087719fdSdp 39877c478bd9Sstevel@tonic-gate if (in_progress_rctltab.zone_rctl_valptr == NULL) { 39887c478bd9Sstevel@tonic-gate zerr(gettext("no %s specified"), pt_to_str(PT_VALUE)); 39897c478bd9Sstevel@tonic-gate validation_failed = TRUE; 39907c478bd9Sstevel@tonic-gate } 3991087719fdSdp 3992087719fdSdp if (validation_failed) { 3993087719fdSdp saw_error = TRUE; 39947c478bd9Sstevel@tonic-gate return; 3995087719fdSdp } 3996087719fdSdp 39977c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 39987c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 39997c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_rctltab.zone_rctl_name, 40007c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_name, 40017c478bd9Sstevel@tonic-gate sizeof (tmp_rctltab.zone_rctl_name)); 40027c478bd9Sstevel@tonic-gate tmp_rctltab.zone_rctl_valptr = NULL; 40037c478bd9Sstevel@tonic-gate err = zonecfg_lookup_rctl(handle, &tmp_rctltab); 40047c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list( 40057c478bd9Sstevel@tonic-gate tmp_rctltab.zone_rctl_valptr); 40067c478bd9Sstevel@tonic-gate if (err == Z_OK) { 40077c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource " 40087c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 40097c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL), pt_to_str(PT_NAME), 40107c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_name); 40117c478bd9Sstevel@tonic-gate saw_error = TRUE; 40127c478bd9Sstevel@tonic-gate return; 40137c478bd9Sstevel@tonic-gate } 40147c478bd9Sstevel@tonic-gate err = zonecfg_add_rctl(handle, &in_progress_rctltab); 40157c478bd9Sstevel@tonic-gate } else { 40167c478bd9Sstevel@tonic-gate err = zonecfg_modify_rctl(handle, &old_rctltab, 40177c478bd9Sstevel@tonic-gate &in_progress_rctltab); 40187c478bd9Sstevel@tonic-gate } 40197c478bd9Sstevel@tonic-gate if (err == Z_OK) { 40207c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list( 40217c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr); 40227c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr = NULL; 40237c478bd9Sstevel@tonic-gate } 40247c478bd9Sstevel@tonic-gate break; 4025087719fdSdp 40267c478bd9Sstevel@tonic-gate case RT_ATTR: 40277c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 4028087719fdSdp (void) end_check_reqd(in_progress_attrtab.zone_attr_name, 4029087719fdSdp PT_NAME, &validation_failed); 4030087719fdSdp (void) end_check_reqd(in_progress_attrtab.zone_attr_type, 4031087719fdSdp PT_TYPE, &validation_failed); 4032087719fdSdp (void) end_check_reqd(in_progress_attrtab.zone_attr_value, 4033087719fdSdp PT_VALUE, &validation_failed); 4034087719fdSdp 40357c478bd9Sstevel@tonic-gate if (validate_attr_name(in_progress_attrtab.zone_attr_name) != 4036087719fdSdp Z_OK) 40377c478bd9Sstevel@tonic-gate validation_failed = TRUE; 4038087719fdSdp 4039087719fdSdp if (validate_attr_type_val(&in_progress_attrtab) != Z_OK) 40407c478bd9Sstevel@tonic-gate validation_failed = TRUE; 4041087719fdSdp 4042087719fdSdp if (validation_failed) { 4043087719fdSdp saw_error = TRUE; 40447c478bd9Sstevel@tonic-gate return; 4045087719fdSdp } 40467c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 40477c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 40487c478bd9Sstevel@tonic-gate bzero(&tmp_attrtab, sizeof (tmp_attrtab)); 40497c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_attrtab.zone_attr_name, 40507c478bd9Sstevel@tonic-gate in_progress_attrtab.zone_attr_name, 40517c478bd9Sstevel@tonic-gate sizeof (tmp_attrtab.zone_attr_name)); 40527c478bd9Sstevel@tonic-gate if (zonecfg_lookup_attr(handle, &tmp_attrtab) == Z_OK) { 40537c478bd9Sstevel@tonic-gate zerr(gettext("An %s resource " 40547c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 40557c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_NAME), 40567c478bd9Sstevel@tonic-gate in_progress_attrtab.zone_attr_name); 40577c478bd9Sstevel@tonic-gate saw_error = TRUE; 40587c478bd9Sstevel@tonic-gate return; 40597c478bd9Sstevel@tonic-gate } 40607c478bd9Sstevel@tonic-gate err = zonecfg_add_attr(handle, &in_progress_attrtab); 40617c478bd9Sstevel@tonic-gate } else { 40627c478bd9Sstevel@tonic-gate err = zonecfg_modify_attr(handle, &old_attrtab, 40637c478bd9Sstevel@tonic-gate &in_progress_attrtab); 40647c478bd9Sstevel@tonic-gate } 40657c478bd9Sstevel@tonic-gate break; 4066fa9e4066Sahrens case RT_DATASET: 4067fa9e4066Sahrens /* First make sure everything was filled in. */ 4068fa9e4066Sahrens if (strlen(in_progress_dstab.zone_dataset_name) == 0) { 4069fa9e4066Sahrens zerr("%s %s", pt_to_str(PT_NAME), 4070fa9e4066Sahrens gettext("not specified")); 4071fa9e4066Sahrens saw_error = TRUE; 4072fa9e4066Sahrens validation_failed = TRUE; 4073fa9e4066Sahrens } 4074fa9e4066Sahrens if (validation_failed) 4075fa9e4066Sahrens return; 4076fa9e4066Sahrens if (end_op == CMD_ADD) { 4077fa9e4066Sahrens /* Make sure there isn't already one like this. */ 4078fa9e4066Sahrens bzero(&tmp_dstab, sizeof (tmp_dstab)); 4079fa9e4066Sahrens (void) strlcpy(tmp_dstab.zone_dataset_name, 4080fa9e4066Sahrens in_progress_dstab.zone_dataset_name, 4081fa9e4066Sahrens sizeof (tmp_dstab.zone_dataset_name)); 4082fa9e4066Sahrens err = zonecfg_lookup_ds(handle, &tmp_dstab); 4083fa9e4066Sahrens if (err == Z_OK) { 4084fa9e4066Sahrens zerr(gettext("A %s resource " 4085fa9e4066Sahrens "with the %s '%s' already exists."), 4086fa9e4066Sahrens rt_to_str(RT_DATASET), pt_to_str(PT_NAME), 4087fa9e4066Sahrens in_progress_dstab.zone_dataset_name); 4088fa9e4066Sahrens saw_error = TRUE; 4089fa9e4066Sahrens return; 4090fa9e4066Sahrens } 4091fa9e4066Sahrens err = zonecfg_add_ds(handle, &in_progress_dstab); 4092fa9e4066Sahrens } else { 4093fa9e4066Sahrens err = zonecfg_modify_ds(handle, &old_dstab, 4094fa9e4066Sahrens &in_progress_dstab); 4095fa9e4066Sahrens } 4096fa9e4066Sahrens break; 40977c478bd9Sstevel@tonic-gate default: 40987c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(resource_scope), Z_NO_RESOURCE_TYPE, 40997c478bd9Sstevel@tonic-gate TRUE); 41007c478bd9Sstevel@tonic-gate saw_error = TRUE; 41017c478bd9Sstevel@tonic-gate return; 41027c478bd9Sstevel@tonic-gate } 41037c478bd9Sstevel@tonic-gate 41047c478bd9Sstevel@tonic-gate if (err != Z_OK) { 41057c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 41067c478bd9Sstevel@tonic-gate } else { 41077c478bd9Sstevel@tonic-gate need_to_commit = TRUE; 41087c478bd9Sstevel@tonic-gate global_scope = TRUE; 41097c478bd9Sstevel@tonic-gate end_op = -1; 41107c478bd9Sstevel@tonic-gate } 41117c478bd9Sstevel@tonic-gate } 41127c478bd9Sstevel@tonic-gate 41137c478bd9Sstevel@tonic-gate void 41147c478bd9Sstevel@tonic-gate commit_func(cmd_t *cmd) 41157c478bd9Sstevel@tonic-gate { 41167c478bd9Sstevel@tonic-gate int arg; 41177c478bd9Sstevel@tonic-gate 41187c478bd9Sstevel@tonic-gate optind = 0; 41197c478bd9Sstevel@tonic-gate if ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 41207c478bd9Sstevel@tonic-gate switch (arg) { 41217c478bd9Sstevel@tonic-gate case '?': 41227c478bd9Sstevel@tonic-gate longer_usage(CMD_COMMIT); 41237c478bd9Sstevel@tonic-gate return; 41247c478bd9Sstevel@tonic-gate default: 41257c478bd9Sstevel@tonic-gate short_usage(CMD_COMMIT); 41267c478bd9Sstevel@tonic-gate return; 41277c478bd9Sstevel@tonic-gate } 41287c478bd9Sstevel@tonic-gate } 41297c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 41307c478bd9Sstevel@tonic-gate short_usage(CMD_COMMIT); 41317c478bd9Sstevel@tonic-gate return; 41327c478bd9Sstevel@tonic-gate } 41337c478bd9Sstevel@tonic-gate 41347c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_COMMIT)) 41357c478bd9Sstevel@tonic-gate return; 41367c478bd9Sstevel@tonic-gate 41377c478bd9Sstevel@tonic-gate assert(cmd != NULL); 41387c478bd9Sstevel@tonic-gate 41397c478bd9Sstevel@tonic-gate cmd->cmd_argc = 1; 41407c478bd9Sstevel@tonic-gate /* 41417c478bd9Sstevel@tonic-gate * cmd_arg normally comes from a strdup() in the lexer, and the 41427c478bd9Sstevel@tonic-gate * whole cmd structure and its (char *) attributes are freed at 41437c478bd9Sstevel@tonic-gate * the completion of each command, so the strdup() below is needed 41447c478bd9Sstevel@tonic-gate * to match this and prevent a core dump from trying to free() 41457c478bd9Sstevel@tonic-gate * something that can't be. 41467c478bd9Sstevel@tonic-gate */ 41477c478bd9Sstevel@tonic-gate if ((cmd->cmd_argv[0] = strdup("save")) == NULL) { 41487c478bd9Sstevel@tonic-gate zone_perror(zone, Z_NOMEM, TRUE); 41497c478bd9Sstevel@tonic-gate exit(Z_ERR); 41507c478bd9Sstevel@tonic-gate } 41517c478bd9Sstevel@tonic-gate cmd->cmd_argv[1] = NULL; 41527c478bd9Sstevel@tonic-gate verify_func(cmd); 41537c478bd9Sstevel@tonic-gate } 41547c478bd9Sstevel@tonic-gate 41557c478bd9Sstevel@tonic-gate void 41567c478bd9Sstevel@tonic-gate revert_func(cmd_t *cmd) 41577c478bd9Sstevel@tonic-gate { 41587c478bd9Sstevel@tonic-gate char line[128]; /* enough to ask a question */ 41597c478bd9Sstevel@tonic-gate bool force = FALSE; 41607c478bd9Sstevel@tonic-gate int err, arg, answer; 41617c478bd9Sstevel@tonic-gate 41627c478bd9Sstevel@tonic-gate optind = 0; 41637c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 41647c478bd9Sstevel@tonic-gate switch (arg) { 41657c478bd9Sstevel@tonic-gate case '?': 41667c478bd9Sstevel@tonic-gate longer_usage(CMD_REVERT); 41677c478bd9Sstevel@tonic-gate return; 41687c478bd9Sstevel@tonic-gate case 'F': 41697c478bd9Sstevel@tonic-gate force = TRUE; 41707c478bd9Sstevel@tonic-gate break; 41717c478bd9Sstevel@tonic-gate default: 41727c478bd9Sstevel@tonic-gate short_usage(CMD_REVERT); 41737c478bd9Sstevel@tonic-gate return; 41747c478bd9Sstevel@tonic-gate } 41757c478bd9Sstevel@tonic-gate } 41767c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 41777c478bd9Sstevel@tonic-gate short_usage(CMD_REVERT); 41787c478bd9Sstevel@tonic-gate return; 41797c478bd9Sstevel@tonic-gate } 41807c478bd9Sstevel@tonic-gate 41817c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_REVERT)) 41827c478bd9Sstevel@tonic-gate return; 41837c478bd9Sstevel@tonic-gate 41847c478bd9Sstevel@tonic-gate if (zonecfg_check_handle(handle) != Z_OK) { 41857c478bd9Sstevel@tonic-gate zerr(gettext("No changes to revert.")); 41867c478bd9Sstevel@tonic-gate saw_error = TRUE; 41877c478bd9Sstevel@tonic-gate return; 41887c478bd9Sstevel@tonic-gate } 41897c478bd9Sstevel@tonic-gate 41907c478bd9Sstevel@tonic-gate if (!force) { 41917c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 41927c478bd9Sstevel@tonic-gate gettext("Are you sure you want to revert")); 41937c478bd9Sstevel@tonic-gate if ((answer = ask_yesno(FALSE, line)) == -1) { 41947c478bd9Sstevel@tonic-gate zerr(gettext("Input not from terminal and -F not " 41957c478bd9Sstevel@tonic-gate "specified:\n%s command ignored, exiting."), 41967c478bd9Sstevel@tonic-gate cmd_to_str(CMD_REVERT)); 41977c478bd9Sstevel@tonic-gate exit(Z_ERR); 41987c478bd9Sstevel@tonic-gate } 41997c478bd9Sstevel@tonic-gate if (answer != 1) 42007c478bd9Sstevel@tonic-gate return; 42017c478bd9Sstevel@tonic-gate } 42027c478bd9Sstevel@tonic-gate 42037c478bd9Sstevel@tonic-gate /* 42047c478bd9Sstevel@tonic-gate * Time for a new handle: finish the old one off first 42057c478bd9Sstevel@tonic-gate * then get a new one properly to avoid leaks. 42067c478bd9Sstevel@tonic-gate */ 42077c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 42087c478bd9Sstevel@tonic-gate if ((handle = zonecfg_init_handle()) == NULL) { 42097c478bd9Sstevel@tonic-gate zone_perror(execname, Z_NOMEM, TRUE); 42107c478bd9Sstevel@tonic-gate exit(Z_ERR); 42117c478bd9Sstevel@tonic-gate } 4212087719fdSdp if ((err = zonecfg_get_handle(revert_zone, handle)) != Z_OK) { 42137c478bd9Sstevel@tonic-gate saw_error = TRUE; 42147c478bd9Sstevel@tonic-gate got_handle = FALSE; 42157c478bd9Sstevel@tonic-gate if (err == Z_NO_ZONE) 42167c478bd9Sstevel@tonic-gate zerr(gettext("%s: no such saved zone to revert to."), 4217087719fdSdp revert_zone); 42187c478bd9Sstevel@tonic-gate else 42197c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 42207c478bd9Sstevel@tonic-gate } 4221087719fdSdp (void) strlcpy(zone, revert_zone, sizeof (zone)); 42227c478bd9Sstevel@tonic-gate } 42237c478bd9Sstevel@tonic-gate 42247c478bd9Sstevel@tonic-gate void 42257c478bd9Sstevel@tonic-gate help_func(cmd_t *cmd) 42267c478bd9Sstevel@tonic-gate { 42277c478bd9Sstevel@tonic-gate int i; 42287c478bd9Sstevel@tonic-gate 42297c478bd9Sstevel@tonic-gate assert(cmd != NULL); 42307c478bd9Sstevel@tonic-gate 42317c478bd9Sstevel@tonic-gate if (cmd->cmd_argc == 0) { 42327c478bd9Sstevel@tonic-gate usage(TRUE, global_scope ? HELP_SUBCMDS : HELP_RES_SCOPE); 42337c478bd9Sstevel@tonic-gate return; 42347c478bd9Sstevel@tonic-gate } 42357c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "usage") == 0) { 42367c478bd9Sstevel@tonic-gate usage(TRUE, HELP_USAGE); 42377c478bd9Sstevel@tonic-gate return; 42387c478bd9Sstevel@tonic-gate } 42397c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "commands") == 0) { 42407c478bd9Sstevel@tonic-gate usage(TRUE, HELP_SUBCMDS); 42417c478bd9Sstevel@tonic-gate return; 42427c478bd9Sstevel@tonic-gate } 42437c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "syntax") == 0) { 42447c478bd9Sstevel@tonic-gate usage(TRUE, HELP_SYNTAX | HELP_RES_PROPS); 42457c478bd9Sstevel@tonic-gate return; 42467c478bd9Sstevel@tonic-gate } 42477c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "-?") == 0) { 42487c478bd9Sstevel@tonic-gate longer_usage(CMD_HELP); 42497c478bd9Sstevel@tonic-gate return; 42507c478bd9Sstevel@tonic-gate } 42517c478bd9Sstevel@tonic-gate 42527c478bd9Sstevel@tonic-gate for (i = 0; i <= CMD_MAX; i++) { 42537c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], cmd_to_str(i)) == 0) { 42547c478bd9Sstevel@tonic-gate longer_usage(i); 42557c478bd9Sstevel@tonic-gate return; 42567c478bd9Sstevel@tonic-gate } 42577c478bd9Sstevel@tonic-gate } 42587c478bd9Sstevel@tonic-gate /* We do not use zerr() here because we do not want its extra \n. */ 42597c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Unknown help subject %s. "), 42607c478bd9Sstevel@tonic-gate cmd->cmd_argv[0]); 42617c478bd9Sstevel@tonic-gate usage(FALSE, HELP_META); 42627c478bd9Sstevel@tonic-gate } 42637c478bd9Sstevel@tonic-gate 42647c478bd9Sstevel@tonic-gate static int 42657c478bd9Sstevel@tonic-gate string_to_yyin(char *string) 42667c478bd9Sstevel@tonic-gate { 42677c478bd9Sstevel@tonic-gate if ((yyin = tmpfile()) == NULL) { 42687c478bd9Sstevel@tonic-gate zone_perror(execname, Z_TEMP_FILE, TRUE); 42697c478bd9Sstevel@tonic-gate return (Z_ERR); 42707c478bd9Sstevel@tonic-gate } 42717c478bd9Sstevel@tonic-gate if (fwrite(string, strlen(string), 1, yyin) != 1) { 42727c478bd9Sstevel@tonic-gate zone_perror(execname, Z_TEMP_FILE, TRUE); 42737c478bd9Sstevel@tonic-gate return (Z_ERR); 42747c478bd9Sstevel@tonic-gate } 42757c478bd9Sstevel@tonic-gate if (fseek(yyin, 0, SEEK_SET) != 0) { 42767c478bd9Sstevel@tonic-gate zone_perror(execname, Z_TEMP_FILE, TRUE); 42777c478bd9Sstevel@tonic-gate return (Z_ERR); 42787c478bd9Sstevel@tonic-gate } 42797c478bd9Sstevel@tonic-gate return (Z_OK); 42807c478bd9Sstevel@tonic-gate } 42817c478bd9Sstevel@tonic-gate 42827c478bd9Sstevel@tonic-gate /* This is the back-end helper function for read_input() below. */ 42837c478bd9Sstevel@tonic-gate 42847c478bd9Sstevel@tonic-gate static int 42857c478bd9Sstevel@tonic-gate cleanup() 42867c478bd9Sstevel@tonic-gate { 42877c478bd9Sstevel@tonic-gate int answer; 42887c478bd9Sstevel@tonic-gate cmd_t *cmd; 42897c478bd9Sstevel@tonic-gate 42907c478bd9Sstevel@tonic-gate if (!interactive_mode && !cmd_file_mode) { 42917c478bd9Sstevel@tonic-gate /* 42927c478bd9Sstevel@tonic-gate * If we're not in interactive mode, and we're not in command 42937c478bd9Sstevel@tonic-gate * file mode, then we must be in commands-from-the-command-line 42947c478bd9Sstevel@tonic-gate * mode. As such, we can't loop back and ask for more input. 42957c478bd9Sstevel@tonic-gate * It was OK to prompt for such things as whether or not to 42967c478bd9Sstevel@tonic-gate * really delete a zone in the command handler called from 42977c478bd9Sstevel@tonic-gate * yyparse() above, but "really quit?" makes no sense in this 42987c478bd9Sstevel@tonic-gate * context. So disable prompting. 42997c478bd9Sstevel@tonic-gate */ 43007c478bd9Sstevel@tonic-gate ok_to_prompt = FALSE; 43017c478bd9Sstevel@tonic-gate } 43027c478bd9Sstevel@tonic-gate if (!global_scope) { 43037c478bd9Sstevel@tonic-gate if (!time_to_exit) { 43047c478bd9Sstevel@tonic-gate /* 43057c478bd9Sstevel@tonic-gate * Just print a simple error message in the -1 case, 43067c478bd9Sstevel@tonic-gate * since exit_func() already handles that case, and 43077c478bd9Sstevel@tonic-gate * EOF means we are finished anyway. 43087c478bd9Sstevel@tonic-gate */ 43097c478bd9Sstevel@tonic-gate answer = ask_yesno(FALSE, 43107c478bd9Sstevel@tonic-gate gettext("Resource incomplete; really quit")); 43117c478bd9Sstevel@tonic-gate if (answer == -1) { 43127c478bd9Sstevel@tonic-gate zerr(gettext("Resource incomplete.")); 43137c478bd9Sstevel@tonic-gate return (Z_ERR); 43147c478bd9Sstevel@tonic-gate } 43157c478bd9Sstevel@tonic-gate if (answer != 1) { 43167c478bd9Sstevel@tonic-gate yyin = stdin; 43177c478bd9Sstevel@tonic-gate return (Z_REPEAT); 43187c478bd9Sstevel@tonic-gate } 43197c478bd9Sstevel@tonic-gate } else { 43207c478bd9Sstevel@tonic-gate saw_error = TRUE; 43217c478bd9Sstevel@tonic-gate } 43227c478bd9Sstevel@tonic-gate } 43237c478bd9Sstevel@tonic-gate /* 43247c478bd9Sstevel@tonic-gate * Make sure we tried something and that the handle checks 43257c478bd9Sstevel@tonic-gate * out, or we would get a false error trying to commit. 43267c478bd9Sstevel@tonic-gate */ 43277c478bd9Sstevel@tonic-gate if (need_to_commit && zonecfg_check_handle(handle) == Z_OK) { 43287c478bd9Sstevel@tonic-gate if ((cmd = alloc_cmd()) == NULL) { 43297c478bd9Sstevel@tonic-gate zone_perror(zone, Z_NOMEM, TRUE); 43307c478bd9Sstevel@tonic-gate return (Z_ERR); 43317c478bd9Sstevel@tonic-gate } 43327c478bd9Sstevel@tonic-gate cmd->cmd_argc = 0; 43337c478bd9Sstevel@tonic-gate cmd->cmd_argv[0] = NULL; 43347c478bd9Sstevel@tonic-gate commit_func(cmd); 43357c478bd9Sstevel@tonic-gate free_cmd(cmd); 43367c478bd9Sstevel@tonic-gate /* 43377c478bd9Sstevel@tonic-gate * need_to_commit will get set back to FALSE if the 43387c478bd9Sstevel@tonic-gate * configuration is saved successfully. 43397c478bd9Sstevel@tonic-gate */ 43407c478bd9Sstevel@tonic-gate if (need_to_commit) { 43417c478bd9Sstevel@tonic-gate if (force_exit) { 43427c478bd9Sstevel@tonic-gate zerr(gettext("Configuration not saved.")); 43437c478bd9Sstevel@tonic-gate return (Z_ERR); 43447c478bd9Sstevel@tonic-gate } 43457c478bd9Sstevel@tonic-gate answer = ask_yesno(FALSE, 43467c478bd9Sstevel@tonic-gate gettext("Configuration not saved; really quit")); 43477c478bd9Sstevel@tonic-gate if (answer == -1) { 43487c478bd9Sstevel@tonic-gate zerr(gettext("Configuration not saved.")); 43497c478bd9Sstevel@tonic-gate return (Z_ERR); 43507c478bd9Sstevel@tonic-gate } 43517c478bd9Sstevel@tonic-gate if (answer != 1) { 43527c478bd9Sstevel@tonic-gate time_to_exit = FALSE; 43537c478bd9Sstevel@tonic-gate yyin = stdin; 43547c478bd9Sstevel@tonic-gate return (Z_REPEAT); 43557c478bd9Sstevel@tonic-gate } 43567c478bd9Sstevel@tonic-gate } 43577c478bd9Sstevel@tonic-gate } 43587c478bd9Sstevel@tonic-gate return ((need_to_commit || saw_error) ? Z_ERR : Z_OK); 43597c478bd9Sstevel@tonic-gate } 43607c478bd9Sstevel@tonic-gate 43617c478bd9Sstevel@tonic-gate /* 43627c478bd9Sstevel@tonic-gate * read_input() is the driver of this program. It is a wrapper around 43637c478bd9Sstevel@tonic-gate * yyparse(), printing appropriate prompts when needed, checking for 43647c478bd9Sstevel@tonic-gate * exit conditions and reacting appropriately [the latter in its cleanup() 43657c478bd9Sstevel@tonic-gate * helper function]. 43667c478bd9Sstevel@tonic-gate * 43677c478bd9Sstevel@tonic-gate * Like most zonecfg functions, it returns Z_OK or Z_ERR, *or* Z_REPEAT 43687c478bd9Sstevel@tonic-gate * so do_interactive() knows that we are not really done (i.e, we asked 43697c478bd9Sstevel@tonic-gate * the user if we should really quit and the user said no). 43707c478bd9Sstevel@tonic-gate */ 43717c478bd9Sstevel@tonic-gate static int 43727c478bd9Sstevel@tonic-gate read_input() 43737c478bd9Sstevel@tonic-gate { 43747c478bd9Sstevel@tonic-gate bool yyin_is_a_tty = isatty(fileno(yyin)); 43757c478bd9Sstevel@tonic-gate /* 43767c478bd9Sstevel@tonic-gate * The prompt is "e:z> " or "e:z:r> " where e is execname, z is zone 43777c478bd9Sstevel@tonic-gate * and r is resource_scope: 5 is for the two ":"s + "> " + terminator. 43787c478bd9Sstevel@tonic-gate */ 43797c478bd9Sstevel@tonic-gate char prompt[MAXPATHLEN + ZONENAME_MAX + MAX_RT_STRLEN + 5], *line; 43807c478bd9Sstevel@tonic-gate 43817c478bd9Sstevel@tonic-gate /* yyin should have been set to the appropriate (FILE *) if not stdin */ 43827c478bd9Sstevel@tonic-gate newline_terminated = TRUE; 43837c478bd9Sstevel@tonic-gate for (;;) { 43847c478bd9Sstevel@tonic-gate if (yyin_is_a_tty) { 43857c478bd9Sstevel@tonic-gate if (newline_terminated) { 43867c478bd9Sstevel@tonic-gate if (global_scope) 43877c478bd9Sstevel@tonic-gate (void) snprintf(prompt, sizeof (prompt), 43887c478bd9Sstevel@tonic-gate "%s:%s> ", execname, zone); 43897c478bd9Sstevel@tonic-gate else 43907c478bd9Sstevel@tonic-gate (void) snprintf(prompt, sizeof (prompt), 43917c478bd9Sstevel@tonic-gate "%s:%s:%s> ", execname, zone, 43927c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 43937c478bd9Sstevel@tonic-gate } 43947c478bd9Sstevel@tonic-gate /* 43957c478bd9Sstevel@tonic-gate * If the user hits ^C then we want to catch it and 43967c478bd9Sstevel@tonic-gate * start over. If the user hits EOF then we want to 43977c478bd9Sstevel@tonic-gate * bail out. 43987c478bd9Sstevel@tonic-gate */ 43997c478bd9Sstevel@tonic-gate line = gl_get_line(gl, prompt, NULL, -1); 44007c478bd9Sstevel@tonic-gate if (gl_return_status(gl) == GLR_SIGNAL) { 44017c478bd9Sstevel@tonic-gate gl_abandon_line(gl); 44027c478bd9Sstevel@tonic-gate continue; 44037c478bd9Sstevel@tonic-gate } 44047c478bd9Sstevel@tonic-gate if (line == NULL) 44057c478bd9Sstevel@tonic-gate break; 44067c478bd9Sstevel@tonic-gate (void) string_to_yyin(line); 44077c478bd9Sstevel@tonic-gate while (!feof(yyin)) 44087c478bd9Sstevel@tonic-gate yyparse(); 44097c478bd9Sstevel@tonic-gate } else { 44107c478bd9Sstevel@tonic-gate yyparse(); 44117c478bd9Sstevel@tonic-gate } 44127c478bd9Sstevel@tonic-gate /* Bail out on an error in command file mode. */ 44137c478bd9Sstevel@tonic-gate if (saw_error && cmd_file_mode && !interactive_mode) 44147c478bd9Sstevel@tonic-gate time_to_exit = TRUE; 44157c478bd9Sstevel@tonic-gate if (time_to_exit || (!yyin_is_a_tty && feof(yyin))) 44167c478bd9Sstevel@tonic-gate break; 44177c478bd9Sstevel@tonic-gate } 44187c478bd9Sstevel@tonic-gate return (cleanup()); 44197c478bd9Sstevel@tonic-gate } 44207c478bd9Sstevel@tonic-gate 44217c478bd9Sstevel@tonic-gate /* 44227c478bd9Sstevel@tonic-gate * This function is used in the zonecfg-interactive-mode scenario: it just 44237c478bd9Sstevel@tonic-gate * calls read_input() until we are done. 44247c478bd9Sstevel@tonic-gate */ 44257c478bd9Sstevel@tonic-gate 44267c478bd9Sstevel@tonic-gate static int 44277c478bd9Sstevel@tonic-gate do_interactive(void) 44287c478bd9Sstevel@tonic-gate { 44297c478bd9Sstevel@tonic-gate int err; 44307c478bd9Sstevel@tonic-gate 44317c478bd9Sstevel@tonic-gate interactive_mode = TRUE; 44327c478bd9Sstevel@tonic-gate if (!read_only_mode) { 44337c478bd9Sstevel@tonic-gate /* 44347c478bd9Sstevel@tonic-gate * Try to set things up proactively in interactive mode, so 44357c478bd9Sstevel@tonic-gate * that if the zone in question does not exist yet, we can 44367c478bd9Sstevel@tonic-gate * provide the user with a clue. 44377c478bd9Sstevel@tonic-gate */ 44387c478bd9Sstevel@tonic-gate (void) initialize(FALSE); 44397c478bd9Sstevel@tonic-gate } 4440087719fdSdp do { 44417c478bd9Sstevel@tonic-gate err = read_input(); 4442087719fdSdp } while (err == Z_REPEAT); 44437c478bd9Sstevel@tonic-gate return (err); 44447c478bd9Sstevel@tonic-gate } 44457c478bd9Sstevel@tonic-gate 44467c478bd9Sstevel@tonic-gate /* 44477c478bd9Sstevel@tonic-gate * cmd_file is slightly more complicated, as it has to open the command file 44487c478bd9Sstevel@tonic-gate * and set yyin appropriately. Once that is done, though, it just calls 44497c478bd9Sstevel@tonic-gate * read_input(), and only once, since prompting is not possible. 44507c478bd9Sstevel@tonic-gate */ 44517c478bd9Sstevel@tonic-gate 44527c478bd9Sstevel@tonic-gate static int 44537c478bd9Sstevel@tonic-gate cmd_file(char *file) 44547c478bd9Sstevel@tonic-gate { 44557c478bd9Sstevel@tonic-gate FILE *infile; 44567c478bd9Sstevel@tonic-gate int err; 44577c478bd9Sstevel@tonic-gate struct stat statbuf; 44587c478bd9Sstevel@tonic-gate bool using_real_file = (strcmp(file, "-") != 0); 44597c478bd9Sstevel@tonic-gate 44607c478bd9Sstevel@tonic-gate if (using_real_file) { 44617c478bd9Sstevel@tonic-gate /* 44627c478bd9Sstevel@tonic-gate * zerr() prints a line number in cmd_file_mode, which we do 44637c478bd9Sstevel@tonic-gate * not want here, so temporarily unset it. 44647c478bd9Sstevel@tonic-gate */ 44657c478bd9Sstevel@tonic-gate cmd_file_mode = FALSE; 44667c478bd9Sstevel@tonic-gate if ((infile = fopen(file, "r")) == NULL) { 44677c478bd9Sstevel@tonic-gate zerr(gettext("could not open file %s: %s"), 44687c478bd9Sstevel@tonic-gate file, strerror(errno)); 44697c478bd9Sstevel@tonic-gate return (Z_ERR); 44707c478bd9Sstevel@tonic-gate } 44717c478bd9Sstevel@tonic-gate if ((err = fstat(fileno(infile), &statbuf)) != 0) { 44727c478bd9Sstevel@tonic-gate zerr(gettext("could not stat file %s: %s"), 44737c478bd9Sstevel@tonic-gate file, strerror(errno)); 44747c478bd9Sstevel@tonic-gate err = Z_ERR; 44757c478bd9Sstevel@tonic-gate goto done; 44767c478bd9Sstevel@tonic-gate } 44777c478bd9Sstevel@tonic-gate if (!S_ISREG(statbuf.st_mode)) { 44787c478bd9Sstevel@tonic-gate zerr(gettext("%s is not a regular file."), file); 44797c478bd9Sstevel@tonic-gate err = Z_ERR; 44807c478bd9Sstevel@tonic-gate goto done; 44817c478bd9Sstevel@tonic-gate } 44827c478bd9Sstevel@tonic-gate yyin = infile; 44837c478bd9Sstevel@tonic-gate cmd_file_mode = TRUE; 44847c478bd9Sstevel@tonic-gate ok_to_prompt = FALSE; 44857c478bd9Sstevel@tonic-gate } else { 44867c478bd9Sstevel@tonic-gate /* 44877c478bd9Sstevel@tonic-gate * "-f -" is essentially the same as interactive mode, 44887c478bd9Sstevel@tonic-gate * so treat it that way. 44897c478bd9Sstevel@tonic-gate */ 44907c478bd9Sstevel@tonic-gate interactive_mode = TRUE; 44917c478bd9Sstevel@tonic-gate } 44927c478bd9Sstevel@tonic-gate /* Z_REPEAT is for interactive mode; treat it like Z_ERR here. */ 44937c478bd9Sstevel@tonic-gate if ((err = read_input()) == Z_REPEAT) 44947c478bd9Sstevel@tonic-gate err = Z_ERR; 44957c478bd9Sstevel@tonic-gate done: 44967c478bd9Sstevel@tonic-gate if (using_real_file) 44977c478bd9Sstevel@tonic-gate (void) fclose(infile); 44987c478bd9Sstevel@tonic-gate return (err); 44997c478bd9Sstevel@tonic-gate } 45007c478bd9Sstevel@tonic-gate 45017c478bd9Sstevel@tonic-gate /* 45027c478bd9Sstevel@tonic-gate * Since yacc is based on reading from a (FILE *) whereas what we get from 45037c478bd9Sstevel@tonic-gate * the command line is in argv format, we need to convert when the user 45047c478bd9Sstevel@tonic-gate * gives us commands directly from the command line. That is done here by 45057c478bd9Sstevel@tonic-gate * concatenating the argv list into a space-separated string, writing it 45067c478bd9Sstevel@tonic-gate * to a temp file, and rewinding the file so yyin can be set to it. Then 45077c478bd9Sstevel@tonic-gate * we call read_input(), and only once, since prompting about whether to 45087c478bd9Sstevel@tonic-gate * continue or quit would make no sense in this context. 45097c478bd9Sstevel@tonic-gate */ 45107c478bd9Sstevel@tonic-gate 45117c478bd9Sstevel@tonic-gate static int 45127c478bd9Sstevel@tonic-gate one_command_at_a_time(int argc, char *argv[]) 45137c478bd9Sstevel@tonic-gate { 45147c478bd9Sstevel@tonic-gate char *command; 45157c478bd9Sstevel@tonic-gate size_t len = 2; /* terminal \n\0 */ 45167c478bd9Sstevel@tonic-gate int i, err; 45177c478bd9Sstevel@tonic-gate 45187c478bd9Sstevel@tonic-gate for (i = 0; i < argc; i++) 45197c478bd9Sstevel@tonic-gate len += strlen(argv[i]) + 1; 45207c478bd9Sstevel@tonic-gate if ((command = malloc(len)) == NULL) { 45217c478bd9Sstevel@tonic-gate zone_perror(execname, Z_NOMEM, TRUE); 45227c478bd9Sstevel@tonic-gate return (Z_ERR); 45237c478bd9Sstevel@tonic-gate } 45247c478bd9Sstevel@tonic-gate (void) strlcpy(command, argv[0], len); 45257c478bd9Sstevel@tonic-gate for (i = 1; i < argc; i++) { 45267c478bd9Sstevel@tonic-gate (void) strlcat(command, " ", len); 45277c478bd9Sstevel@tonic-gate (void) strlcat(command, argv[i], len); 45287c478bd9Sstevel@tonic-gate } 45297c478bd9Sstevel@tonic-gate (void) strlcat(command, "\n", len); 45307c478bd9Sstevel@tonic-gate err = string_to_yyin(command); 45317c478bd9Sstevel@tonic-gate free(command); 45327c478bd9Sstevel@tonic-gate if (err != Z_OK) 45337c478bd9Sstevel@tonic-gate return (err); 45347c478bd9Sstevel@tonic-gate while (!feof(yyin)) 45357c478bd9Sstevel@tonic-gate yyparse(); 45367c478bd9Sstevel@tonic-gate return (cleanup()); 45377c478bd9Sstevel@tonic-gate } 45387c478bd9Sstevel@tonic-gate 45397c478bd9Sstevel@tonic-gate static char * 45407c478bd9Sstevel@tonic-gate get_execbasename(char *execfullname) 45417c478bd9Sstevel@tonic-gate { 45427c478bd9Sstevel@tonic-gate char *last_slash, *execbasename; 45437c478bd9Sstevel@tonic-gate 45447c478bd9Sstevel@tonic-gate /* guard against '/' at end of command invocation */ 45457c478bd9Sstevel@tonic-gate for (;;) { 45467c478bd9Sstevel@tonic-gate last_slash = strrchr(execfullname, '/'); 45477c478bd9Sstevel@tonic-gate if (last_slash == NULL) { 45487c478bd9Sstevel@tonic-gate execbasename = execfullname; 45497c478bd9Sstevel@tonic-gate break; 45507c478bd9Sstevel@tonic-gate } else { 45517c478bd9Sstevel@tonic-gate execbasename = last_slash + 1; 45527c478bd9Sstevel@tonic-gate if (*execbasename == '\0') { 45537c478bd9Sstevel@tonic-gate *last_slash = '\0'; 45547c478bd9Sstevel@tonic-gate continue; 45557c478bd9Sstevel@tonic-gate } 45567c478bd9Sstevel@tonic-gate break; 45577c478bd9Sstevel@tonic-gate } 45587c478bd9Sstevel@tonic-gate } 45597c478bd9Sstevel@tonic-gate return (execbasename); 45607c478bd9Sstevel@tonic-gate } 45617c478bd9Sstevel@tonic-gate 45627c478bd9Sstevel@tonic-gate int 45637c478bd9Sstevel@tonic-gate main(int argc, char *argv[]) 45647c478bd9Sstevel@tonic-gate { 45657c478bd9Sstevel@tonic-gate int err, arg; 45667c478bd9Sstevel@tonic-gate 45677c478bd9Sstevel@tonic-gate /* This must be before anything goes to stdout. */ 45687c478bd9Sstevel@tonic-gate setbuf(stdout, NULL); 45697c478bd9Sstevel@tonic-gate 45707c478bd9Sstevel@tonic-gate saw_error = FALSE; 45717c478bd9Sstevel@tonic-gate cmd_file_mode = FALSE; 45727c478bd9Sstevel@tonic-gate execname = get_execbasename(argv[0]); 45737c478bd9Sstevel@tonic-gate 45747c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 45757c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 45767c478bd9Sstevel@tonic-gate 45777c478bd9Sstevel@tonic-gate if (getzoneid() != GLOBAL_ZONEID) { 45787c478bd9Sstevel@tonic-gate zerr(gettext("%s can only be run from the global zone."), 45797c478bd9Sstevel@tonic-gate execname); 45807c478bd9Sstevel@tonic-gate exit(Z_ERR); 45817c478bd9Sstevel@tonic-gate } 45827c478bd9Sstevel@tonic-gate 45837c478bd9Sstevel@tonic-gate if (argc < 2) { 45847c478bd9Sstevel@tonic-gate usage(FALSE, HELP_USAGE | HELP_SUBCMDS); 45857c478bd9Sstevel@tonic-gate exit(Z_USAGE); 45867c478bd9Sstevel@tonic-gate } 45877c478bd9Sstevel@tonic-gate if (strcmp(argv[1], cmd_to_str(CMD_HELP)) == 0) { 45887c478bd9Sstevel@tonic-gate (void) one_command_at_a_time(argc - 1, &(argv[1])); 45897c478bd9Sstevel@tonic-gate exit(Z_OK); 45907c478bd9Sstevel@tonic-gate } 45917c478bd9Sstevel@tonic-gate 45927c478bd9Sstevel@tonic-gate while ((arg = getopt(argc, argv, "?f:z:")) != EOF) { 45937c478bd9Sstevel@tonic-gate switch (arg) { 45947c478bd9Sstevel@tonic-gate case '?': 45957c478bd9Sstevel@tonic-gate if (optopt == '?') 45967c478bd9Sstevel@tonic-gate usage(TRUE, HELP_USAGE | HELP_SUBCMDS); 45977c478bd9Sstevel@tonic-gate else 45987c478bd9Sstevel@tonic-gate usage(FALSE, HELP_USAGE); 45997c478bd9Sstevel@tonic-gate exit(Z_USAGE); 46007c478bd9Sstevel@tonic-gate /* NOTREACHED */ 46017c478bd9Sstevel@tonic-gate case 'f': 46027c478bd9Sstevel@tonic-gate cmd_file_name = optarg; 46037c478bd9Sstevel@tonic-gate cmd_file_mode = TRUE; 46047c478bd9Sstevel@tonic-gate break; 46057c478bd9Sstevel@tonic-gate case 'z': 4606087719fdSdp if (zonecfg_validate_zonename(optarg) != Z_OK) { 4607087719fdSdp zone_perror(optarg, Z_BOGUS_ZONE_NAME, TRUE); 4608087719fdSdp usage(FALSE, HELP_SYNTAX); 4609087719fdSdp exit(Z_USAGE); 4610087719fdSdp } 4611087719fdSdp (void) strlcpy(zone, optarg, sizeof (zone)); 4612087719fdSdp (void) strlcpy(revert_zone, optarg, sizeof (zone)); 46137c478bd9Sstevel@tonic-gate break; 46147c478bd9Sstevel@tonic-gate default: 46157c478bd9Sstevel@tonic-gate usage(FALSE, HELP_USAGE); 46167c478bd9Sstevel@tonic-gate exit(Z_USAGE); 46177c478bd9Sstevel@tonic-gate } 46187c478bd9Sstevel@tonic-gate } 46197c478bd9Sstevel@tonic-gate 4620087719fdSdp if (optind > argc || strcmp(zone, "") == 0) { 46217c478bd9Sstevel@tonic-gate usage(FALSE, HELP_USAGE); 46227c478bd9Sstevel@tonic-gate exit(Z_USAGE); 46237c478bd9Sstevel@tonic-gate } 46247c478bd9Sstevel@tonic-gate 4625087719fdSdp if ((err = zonecfg_access(zone, W_OK)) == Z_OK) { 46267c478bd9Sstevel@tonic-gate read_only_mode = FALSE; 4627087719fdSdp } else if (err == Z_ACCES) { 46287c478bd9Sstevel@tonic-gate read_only_mode = TRUE; 46297c478bd9Sstevel@tonic-gate /* skip this message in one-off from command line mode */ 46307c478bd9Sstevel@tonic-gate if (optind == argc) 46317c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("WARNING: you do not " 46327c478bd9Sstevel@tonic-gate "have write access to this zone's configuration " 46337c478bd9Sstevel@tonic-gate "file;\ngoing into read-only mode.\n")); 4634087719fdSdp } else { 4635087719fdSdp fprintf(stderr, "%s: Could not access zone configuration " 4636087719fdSdp "store: %s\n", execname, zonecfg_strerror(err)); 4637087719fdSdp exit(Z_ERR); 46387c478bd9Sstevel@tonic-gate } 46397c478bd9Sstevel@tonic-gate 46407c478bd9Sstevel@tonic-gate if ((handle = zonecfg_init_handle()) == NULL) { 46417c478bd9Sstevel@tonic-gate zone_perror(execname, Z_NOMEM, TRUE); 46427c478bd9Sstevel@tonic-gate exit(Z_ERR); 46437c478bd9Sstevel@tonic-gate } 46447c478bd9Sstevel@tonic-gate 46457c478bd9Sstevel@tonic-gate /* 46467c478bd9Sstevel@tonic-gate * This may get set back to FALSE again in cmd_file() if cmd_file_name 46477c478bd9Sstevel@tonic-gate * is a "real" file as opposed to "-" (i.e. meaning use stdin). 46487c478bd9Sstevel@tonic-gate */ 46497c478bd9Sstevel@tonic-gate if (isatty(STDIN_FILENO)) 46507c478bd9Sstevel@tonic-gate ok_to_prompt = TRUE; 46517c478bd9Sstevel@tonic-gate if ((gl = new_GetLine(MAX_LINE_LEN, MAX_CMD_HIST)) == NULL) 46527c478bd9Sstevel@tonic-gate exit(Z_ERR); 46537c478bd9Sstevel@tonic-gate if (gl_customize_completion(gl, NULL, cmd_cpl_fn) != 0) 46547c478bd9Sstevel@tonic-gate exit(Z_ERR); 46557c478bd9Sstevel@tonic-gate (void) sigset(SIGINT, SIG_IGN); 46567c478bd9Sstevel@tonic-gate if (optind == argc) { 46577c478bd9Sstevel@tonic-gate if (!cmd_file_mode) 46587c478bd9Sstevel@tonic-gate err = do_interactive(); 46597c478bd9Sstevel@tonic-gate else 46607c478bd9Sstevel@tonic-gate err = cmd_file(cmd_file_name); 46617c478bd9Sstevel@tonic-gate } else { 46627c478bd9Sstevel@tonic-gate err = one_command_at_a_time(argc - optind, &(argv[optind])); 46637c478bd9Sstevel@tonic-gate } 46647c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 46657c478bd9Sstevel@tonic-gate (void) del_GetLine(gl); 46667c478bd9Sstevel@tonic-gate return (err); 46677c478bd9Sstevel@tonic-gate } 4668