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 5*fb03efaaSdp * Common Development and Distribution License (the "License"). 6*fb03efaaSdp * 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 /* 23*fb03efaaSdp * 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" 1067c478bd9Sstevel@tonic-gate #define SHELP_CREATE "create [-F] [ -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-" \ 1147c478bd9Sstevel@tonic-gate "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", 1577c478bd9Sstevel@tonic-gate NULL 1587c478bd9Sstevel@tonic-gate }; 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate /* These *must* match the order of the PT_ define's from zonecfg.h */ 1617c478bd9Sstevel@tonic-gate static char *prop_types[] = { 1627c478bd9Sstevel@tonic-gate "unknown", 163087719fdSdp "zonename", 1647c478bd9Sstevel@tonic-gate "zonepath", 1657c478bd9Sstevel@tonic-gate "autoboot", 1667c478bd9Sstevel@tonic-gate "pool", 1677c478bd9Sstevel@tonic-gate "dir", 1687c478bd9Sstevel@tonic-gate "special", 1697c478bd9Sstevel@tonic-gate "type", 1707c478bd9Sstevel@tonic-gate "options", 1717c478bd9Sstevel@tonic-gate "address", 1727c478bd9Sstevel@tonic-gate "physical", 1737c478bd9Sstevel@tonic-gate "name", 1747c478bd9Sstevel@tonic-gate "value", 1757c478bd9Sstevel@tonic-gate "match", 1767c478bd9Sstevel@tonic-gate "priv", 1777c478bd9Sstevel@tonic-gate "limit", 1787c478bd9Sstevel@tonic-gate "action", 1797c478bd9Sstevel@tonic-gate "raw", 1807c478bd9Sstevel@tonic-gate NULL 1817c478bd9Sstevel@tonic-gate }; 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate /* These *must* match the order of the PT_ define's from zonecfg.h */ 1847c478bd9Sstevel@tonic-gate static char *prop_val_types[] = { 1857c478bd9Sstevel@tonic-gate "simple", 1867c478bd9Sstevel@tonic-gate "complex", 1877c478bd9Sstevel@tonic-gate "list", 1887c478bd9Sstevel@tonic-gate }; 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate /* 1917c478bd9Sstevel@tonic-gate * The various _cmds[] lists below are for command tab-completion. 1927c478bd9Sstevel@tonic-gate */ 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate /* 1957c478bd9Sstevel@tonic-gate * remove has a space afterwards because it has qualifiers; the other commands 1967c478bd9Sstevel@tonic-gate * that have qualifiers (add, select and set) don't need a space here because 1977c478bd9Sstevel@tonic-gate * they have their own _cmds[] lists below. 1987c478bd9Sstevel@tonic-gate */ 1997c478bd9Sstevel@tonic-gate static const char *global_scope_cmds[] = { 2007c478bd9Sstevel@tonic-gate "add", 2017c478bd9Sstevel@tonic-gate "commit", 2027c478bd9Sstevel@tonic-gate "create", 2037c478bd9Sstevel@tonic-gate "delete", 2047c478bd9Sstevel@tonic-gate "exit", 2057c478bd9Sstevel@tonic-gate "export", 2067c478bd9Sstevel@tonic-gate "help", 2077c478bd9Sstevel@tonic-gate "info", 2087c478bd9Sstevel@tonic-gate "remove ", 2097c478bd9Sstevel@tonic-gate "revert", 2107c478bd9Sstevel@tonic-gate "select", 2117c478bd9Sstevel@tonic-gate "set", 2127c478bd9Sstevel@tonic-gate "verify", 2137c478bd9Sstevel@tonic-gate NULL 2147c478bd9Sstevel@tonic-gate }; 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate static const char *add_cmds[] = { 2177c478bd9Sstevel@tonic-gate "add fs", 2187c478bd9Sstevel@tonic-gate "add inherit-pkg-dir", 2197c478bd9Sstevel@tonic-gate "add net", 2207c478bd9Sstevel@tonic-gate "add device", 2217c478bd9Sstevel@tonic-gate "add rctl", 2227c478bd9Sstevel@tonic-gate "add attr", 223fa9e4066Sahrens "add dataset", 2247c478bd9Sstevel@tonic-gate NULL 2257c478bd9Sstevel@tonic-gate }; 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate static const char *select_cmds[] = { 2287c478bd9Sstevel@tonic-gate "select fs ", 2297c478bd9Sstevel@tonic-gate "select inherit-pkg-dir ", 2307c478bd9Sstevel@tonic-gate "select net ", 2317c478bd9Sstevel@tonic-gate "select device ", 2327c478bd9Sstevel@tonic-gate "select rctl ", 2337c478bd9Sstevel@tonic-gate "select attr ", 234fa9e4066Sahrens "select dataset ", 2357c478bd9Sstevel@tonic-gate NULL 2367c478bd9Sstevel@tonic-gate }; 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate static const char *set_cmds[] = { 239087719fdSdp "set zonename=", 240087719fdSdp "set zonepath=", 241087719fdSdp "set autoboot=", 242087719fdSdp "set pool=", 2437c478bd9Sstevel@tonic-gate NULL 2447c478bd9Sstevel@tonic-gate }; 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate static const char *fs_res_scope_cmds[] = { 2477c478bd9Sstevel@tonic-gate "add options ", 2487c478bd9Sstevel@tonic-gate "cancel", 2497c478bd9Sstevel@tonic-gate "end", 2507c478bd9Sstevel@tonic-gate "exit", 2517c478bd9Sstevel@tonic-gate "help", 2527c478bd9Sstevel@tonic-gate "info", 2537c478bd9Sstevel@tonic-gate "set dir=", 2547c478bd9Sstevel@tonic-gate "set raw=", 2557c478bd9Sstevel@tonic-gate "set special=", 2567c478bd9Sstevel@tonic-gate "set type=", 2577c478bd9Sstevel@tonic-gate NULL 2587c478bd9Sstevel@tonic-gate }; 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate static const char *net_res_scope_cmds[] = { 2617c478bd9Sstevel@tonic-gate "cancel", 2627c478bd9Sstevel@tonic-gate "end", 2637c478bd9Sstevel@tonic-gate "exit", 2647c478bd9Sstevel@tonic-gate "help", 2657c478bd9Sstevel@tonic-gate "info", 2667c478bd9Sstevel@tonic-gate "set address=", 2677c478bd9Sstevel@tonic-gate "set physical=", 2687c478bd9Sstevel@tonic-gate NULL 2697c478bd9Sstevel@tonic-gate }; 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate static const char *ipd_res_scope_cmds[] = { 2727c478bd9Sstevel@tonic-gate "cancel", 2737c478bd9Sstevel@tonic-gate "end", 2747c478bd9Sstevel@tonic-gate "exit", 2757c478bd9Sstevel@tonic-gate "help", 2767c478bd9Sstevel@tonic-gate "info", 2777c478bd9Sstevel@tonic-gate "set dir=", 2787c478bd9Sstevel@tonic-gate NULL 2797c478bd9Sstevel@tonic-gate }; 2807c478bd9Sstevel@tonic-gate 2817c478bd9Sstevel@tonic-gate static const char *device_res_scope_cmds[] = { 2827c478bd9Sstevel@tonic-gate "cancel", 2837c478bd9Sstevel@tonic-gate "end", 2847c478bd9Sstevel@tonic-gate "exit", 2857c478bd9Sstevel@tonic-gate "help", 2867c478bd9Sstevel@tonic-gate "info", 2877c478bd9Sstevel@tonic-gate "set match=", 2887c478bd9Sstevel@tonic-gate NULL 2897c478bd9Sstevel@tonic-gate }; 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate static const char *attr_res_scope_cmds[] = { 2927c478bd9Sstevel@tonic-gate "cancel", 2937c478bd9Sstevel@tonic-gate "end", 2947c478bd9Sstevel@tonic-gate "exit", 2957c478bd9Sstevel@tonic-gate "help", 2967c478bd9Sstevel@tonic-gate "info", 2977c478bd9Sstevel@tonic-gate "set name=", 2987c478bd9Sstevel@tonic-gate "set type=", 2997c478bd9Sstevel@tonic-gate "set value=", 3007c478bd9Sstevel@tonic-gate NULL 3017c478bd9Sstevel@tonic-gate }; 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate static const char *rctl_res_scope_cmds[] = { 3047c478bd9Sstevel@tonic-gate "add value ", 3057c478bd9Sstevel@tonic-gate "cancel", 3067c478bd9Sstevel@tonic-gate "end", 3077c478bd9Sstevel@tonic-gate "exit", 3087c478bd9Sstevel@tonic-gate "help", 3097c478bd9Sstevel@tonic-gate "info", 3107c478bd9Sstevel@tonic-gate "set name=", 3117c478bd9Sstevel@tonic-gate NULL 3127c478bd9Sstevel@tonic-gate }; 3137c478bd9Sstevel@tonic-gate 314fa9e4066Sahrens static const char *dataset_res_scope_cmds[] = { 315fa9e4066Sahrens "cancel", 316fa9e4066Sahrens "end", 317fa9e4066Sahrens "exit", 318fa9e4066Sahrens "help", 319fa9e4066Sahrens "info", 320fa9e4066Sahrens "set name=", 321fa9e4066Sahrens NULL 322fa9e4066Sahrens }; 323fa9e4066Sahrens 3247c478bd9Sstevel@tonic-gate /* Global variables */ 3257c478bd9Sstevel@tonic-gate 3267c478bd9Sstevel@tonic-gate /* set early in main(), never modified thereafter, used all over the place */ 3277c478bd9Sstevel@tonic-gate static char *execname; 3287c478bd9Sstevel@tonic-gate 3297c478bd9Sstevel@tonic-gate /* set in main(), used all over the place */ 3307c478bd9Sstevel@tonic-gate static zone_dochandle_t handle; 3317c478bd9Sstevel@tonic-gate 3327c478bd9Sstevel@tonic-gate /* used all over the place */ 333087719fdSdp static char zone[ZONENAME_MAX]; 334087719fdSdp static char revert_zone[ZONENAME_MAX]; 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate /* set in modifying functions, checked in read_input() */ 3377c478bd9Sstevel@tonic-gate static bool need_to_commit = FALSE; 3387c478bd9Sstevel@tonic-gate bool saw_error; 3397c478bd9Sstevel@tonic-gate 3407c478bd9Sstevel@tonic-gate /* set in yacc parser, checked in read_input() */ 3417c478bd9Sstevel@tonic-gate bool newline_terminated; 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate /* set in main(), checked in lex error handler */ 3447c478bd9Sstevel@tonic-gate bool cmd_file_mode; 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate /* set in exit_func(), checked in read_input() */ 3477c478bd9Sstevel@tonic-gate static bool time_to_exit = FALSE, force_exit = FALSE; 3487c478bd9Sstevel@tonic-gate 3497c478bd9Sstevel@tonic-gate /* used in short_usage() and zerr() */ 3507c478bd9Sstevel@tonic-gate static char *cmd_file_name = NULL; 3517c478bd9Sstevel@tonic-gate 3527c478bd9Sstevel@tonic-gate /* checked in read_input() and other places */ 3537c478bd9Sstevel@tonic-gate static bool ok_to_prompt = FALSE; 3547c478bd9Sstevel@tonic-gate 3557c478bd9Sstevel@tonic-gate /* set and checked in initialize() */ 3567c478bd9Sstevel@tonic-gate static bool got_handle = FALSE; 3577c478bd9Sstevel@tonic-gate 3587c478bd9Sstevel@tonic-gate /* initialized in do_interactive(), checked in initialize() */ 3597c478bd9Sstevel@tonic-gate static bool interactive_mode; 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate /* set in main(), checked in multiple places */ 3627c478bd9Sstevel@tonic-gate static bool read_only_mode; 3637c478bd9Sstevel@tonic-gate 3647c478bd9Sstevel@tonic-gate static bool global_scope = TRUE; /* scope is outer/global or inner/resource */ 3657c478bd9Sstevel@tonic-gate static int resource_scope; /* should be in the RT_ list from zonecfg.h */ 3667c478bd9Sstevel@tonic-gate static int end_op = -1; /* operation on end is either add or modify */ 3677c478bd9Sstevel@tonic-gate 3687c478bd9Sstevel@tonic-gate int num_prop_vals; /* for grammar */ 3697c478bd9Sstevel@tonic-gate 3707c478bd9Sstevel@tonic-gate /* 3717c478bd9Sstevel@tonic-gate * These are for keeping track of resources as they are specified as part of 3727c478bd9Sstevel@tonic-gate * the multi-step process. They should be initialized by add_resource() or 3737c478bd9Sstevel@tonic-gate * select_func() and filled in by add_property() or set_func(). 3747c478bd9Sstevel@tonic-gate */ 3757c478bd9Sstevel@tonic-gate static struct zone_fstab old_fstab, in_progress_fstab; 3767c478bd9Sstevel@tonic-gate static struct zone_fstab old_ipdtab, in_progress_ipdtab; 3777c478bd9Sstevel@tonic-gate static struct zone_nwiftab old_nwiftab, in_progress_nwiftab; 3787c478bd9Sstevel@tonic-gate static struct zone_devtab old_devtab, in_progress_devtab; 3797c478bd9Sstevel@tonic-gate static struct zone_rctltab old_rctltab, in_progress_rctltab; 3807c478bd9Sstevel@tonic-gate static struct zone_attrtab old_attrtab, in_progress_attrtab; 381fa9e4066Sahrens static struct zone_dstab old_dstab, in_progress_dstab; 3827c478bd9Sstevel@tonic-gate 3837c478bd9Sstevel@tonic-gate static GetLine *gl; /* The gl_get_line() resource object */ 3847c478bd9Sstevel@tonic-gate 3857c478bd9Sstevel@tonic-gate /* Functions begin here */ 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate static bool 3887c478bd9Sstevel@tonic-gate initial_match(const char *line1, const char *line2, int word_end) 3897c478bd9Sstevel@tonic-gate { 3907c478bd9Sstevel@tonic-gate if (word_end <= 0) 3917c478bd9Sstevel@tonic-gate return (TRUE); 3927c478bd9Sstevel@tonic-gate return (strncmp(line1, line2, word_end) == 0); 3937c478bd9Sstevel@tonic-gate } 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate static int 3967c478bd9Sstevel@tonic-gate add_stuff(WordCompletion *cpl, const char *line1, const char **list, 3977c478bd9Sstevel@tonic-gate int word_end) 3987c478bd9Sstevel@tonic-gate { 3997c478bd9Sstevel@tonic-gate int i, err; 4007c478bd9Sstevel@tonic-gate 4017c478bd9Sstevel@tonic-gate for (i = 0; list[i] != NULL; i++) { 4027c478bd9Sstevel@tonic-gate if (initial_match(line1, list[i], word_end)) { 4037c478bd9Sstevel@tonic-gate err = cpl_add_completion(cpl, line1, 0, word_end, 4047c478bd9Sstevel@tonic-gate list[i] + word_end, "", ""); 4057c478bd9Sstevel@tonic-gate if (err != 0) 4067c478bd9Sstevel@tonic-gate return (err); 4077c478bd9Sstevel@tonic-gate } 4087c478bd9Sstevel@tonic-gate } 4097c478bd9Sstevel@tonic-gate return (0); 4107c478bd9Sstevel@tonic-gate } 4117c478bd9Sstevel@tonic-gate 4127c478bd9Sstevel@tonic-gate static 4137c478bd9Sstevel@tonic-gate /* ARGSUSED */ 4147c478bd9Sstevel@tonic-gate CPL_MATCH_FN(cmd_cpl_fn) 4157c478bd9Sstevel@tonic-gate { 4167c478bd9Sstevel@tonic-gate if (global_scope) { 4177c478bd9Sstevel@tonic-gate /* 4187c478bd9Sstevel@tonic-gate * The MAX/MIN tests below are to make sure we have at least 4197c478bd9Sstevel@tonic-gate * enough characters to distinguish from other prefixes (MAX) 4207c478bd9Sstevel@tonic-gate * but only check MIN(what we have, what we're checking). 4217c478bd9Sstevel@tonic-gate */ 4227c478bd9Sstevel@tonic-gate if (strncmp(line, "add ", MAX(MIN(word_end, 4), 1)) == 0) 4237c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, add_cmds, word_end)); 4247c478bd9Sstevel@tonic-gate if (strncmp(line, "select ", MAX(MIN(word_end, 7), 3)) == 0) 4257c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, select_cmds, word_end)); 4267c478bd9Sstevel@tonic-gate if (strncmp(line, "set ", MAX(MIN(word_end, 4), 3)) == 0) 4277c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, set_cmds, word_end)); 4287c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, global_scope_cmds, word_end)); 4297c478bd9Sstevel@tonic-gate } 4307c478bd9Sstevel@tonic-gate switch (resource_scope) { 4317c478bd9Sstevel@tonic-gate case RT_FS: 4327c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, fs_res_scope_cmds, word_end)); 4337c478bd9Sstevel@tonic-gate case RT_IPD: 4347c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, ipd_res_scope_cmds, word_end)); 4357c478bd9Sstevel@tonic-gate case RT_NET: 4367c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, net_res_scope_cmds, word_end)); 4377c478bd9Sstevel@tonic-gate case RT_DEVICE: 4387c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, device_res_scope_cmds, word_end)); 4397c478bd9Sstevel@tonic-gate case RT_RCTL: 4407c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, rctl_res_scope_cmds, word_end)); 4417c478bd9Sstevel@tonic-gate case RT_ATTR: 4427c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, attr_res_scope_cmds, word_end)); 443fa9e4066Sahrens case RT_DATASET: 444fa9e4066Sahrens return (add_stuff(cpl, line, dataset_res_scope_cmds, word_end)); 4457c478bd9Sstevel@tonic-gate } 4467c478bd9Sstevel@tonic-gate return (0); 4477c478bd9Sstevel@tonic-gate } 4487c478bd9Sstevel@tonic-gate 4497c478bd9Sstevel@tonic-gate /* 4507c478bd9Sstevel@tonic-gate * For the main CMD_func() functions below, several of them call getopt() 4517c478bd9Sstevel@tonic-gate * then check optind against argc to make sure an extra parameter was not 4527c478bd9Sstevel@tonic-gate * passed in. The reason this is not caught in the grammar is that the 4537c478bd9Sstevel@tonic-gate * grammar just checks for a miscellaneous TOKEN, which is *expected* to 4547c478bd9Sstevel@tonic-gate * be "-F" (for example), but could be anything. So (for example) this 4557c478bd9Sstevel@tonic-gate * check will prevent "create bogus". 4567c478bd9Sstevel@tonic-gate */ 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate cmd_t * 4597c478bd9Sstevel@tonic-gate alloc_cmd(void) 4607c478bd9Sstevel@tonic-gate { 4617c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (cmd_t))); 4627c478bd9Sstevel@tonic-gate } 4637c478bd9Sstevel@tonic-gate 4647c478bd9Sstevel@tonic-gate void 4657c478bd9Sstevel@tonic-gate free_cmd(cmd_t *cmd) 4667c478bd9Sstevel@tonic-gate { 4677c478bd9Sstevel@tonic-gate int i; 4687c478bd9Sstevel@tonic-gate 4697c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_EQ_PROP_PAIRS; i++) 4707c478bd9Sstevel@tonic-gate if (cmd->cmd_property_ptr[i] != NULL) { 4717c478bd9Sstevel@tonic-gate property_value_ptr_t pp = cmd->cmd_property_ptr[i]; 4727c478bd9Sstevel@tonic-gate 4737c478bd9Sstevel@tonic-gate switch (pp->pv_type) { 4747c478bd9Sstevel@tonic-gate case PROP_VAL_SIMPLE: 4757c478bd9Sstevel@tonic-gate free(pp->pv_simple); 4767c478bd9Sstevel@tonic-gate break; 4777c478bd9Sstevel@tonic-gate case PROP_VAL_COMPLEX: 4787c478bd9Sstevel@tonic-gate free_complex(pp->pv_complex); 4797c478bd9Sstevel@tonic-gate break; 4807c478bd9Sstevel@tonic-gate case PROP_VAL_LIST: 4817c478bd9Sstevel@tonic-gate free_list(pp->pv_list); 4827c478bd9Sstevel@tonic-gate break; 4837c478bd9Sstevel@tonic-gate } 4847c478bd9Sstevel@tonic-gate } 4857c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_argc; i++) 4867c478bd9Sstevel@tonic-gate free(cmd->cmd_argv[i]); 4877c478bd9Sstevel@tonic-gate free(cmd); 4887c478bd9Sstevel@tonic-gate } 4897c478bd9Sstevel@tonic-gate 4907c478bd9Sstevel@tonic-gate complex_property_ptr_t 4917c478bd9Sstevel@tonic-gate alloc_complex(void) 4927c478bd9Sstevel@tonic-gate { 4937c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (complex_property_t))); 4947c478bd9Sstevel@tonic-gate } 4957c478bd9Sstevel@tonic-gate 4967c478bd9Sstevel@tonic-gate void 4977c478bd9Sstevel@tonic-gate free_complex(complex_property_ptr_t complex) 4987c478bd9Sstevel@tonic-gate { 4997c478bd9Sstevel@tonic-gate if (complex == NULL) 5007c478bd9Sstevel@tonic-gate return; 5017c478bd9Sstevel@tonic-gate free_complex(complex->cp_next); 5027c478bd9Sstevel@tonic-gate if (complex->cp_value != NULL) 5037c478bd9Sstevel@tonic-gate free(complex->cp_value); 5047c478bd9Sstevel@tonic-gate free(complex); 5057c478bd9Sstevel@tonic-gate } 5067c478bd9Sstevel@tonic-gate 5077c478bd9Sstevel@tonic-gate list_property_ptr_t 5087c478bd9Sstevel@tonic-gate alloc_list(void) 5097c478bd9Sstevel@tonic-gate { 5107c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (list_property_t))); 5117c478bd9Sstevel@tonic-gate } 5127c478bd9Sstevel@tonic-gate 5137c478bd9Sstevel@tonic-gate void 5147c478bd9Sstevel@tonic-gate free_list(list_property_ptr_t list) 5157c478bd9Sstevel@tonic-gate { 5167c478bd9Sstevel@tonic-gate if (list == NULL) 5177c478bd9Sstevel@tonic-gate return; 5187c478bd9Sstevel@tonic-gate if (list->lp_simple != NULL) 5197c478bd9Sstevel@tonic-gate free(list->lp_simple); 5207c478bd9Sstevel@tonic-gate free_complex(list->lp_complex); 5217c478bd9Sstevel@tonic-gate free_list(list->lp_next); 5227c478bd9Sstevel@tonic-gate free(list); 5237c478bd9Sstevel@tonic-gate } 5247c478bd9Sstevel@tonic-gate 5257c478bd9Sstevel@tonic-gate void 5267c478bd9Sstevel@tonic-gate free_outer_list(list_property_ptr_t list) 5277c478bd9Sstevel@tonic-gate { 5287c478bd9Sstevel@tonic-gate if (list == NULL) 5297c478bd9Sstevel@tonic-gate return; 5307c478bd9Sstevel@tonic-gate free_outer_list(list->lp_next); 5317c478bd9Sstevel@tonic-gate free(list); 5327c478bd9Sstevel@tonic-gate } 5337c478bd9Sstevel@tonic-gate 5347c478bd9Sstevel@tonic-gate static struct zone_rctlvaltab * 5357c478bd9Sstevel@tonic-gate alloc_rctlvaltab(void) 5367c478bd9Sstevel@tonic-gate { 5377c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (struct zone_rctlvaltab))); 5387c478bd9Sstevel@tonic-gate } 5397c478bd9Sstevel@tonic-gate 5407c478bd9Sstevel@tonic-gate static char * 5417c478bd9Sstevel@tonic-gate rt_to_str(int res_type) 5427c478bd9Sstevel@tonic-gate { 5437c478bd9Sstevel@tonic-gate assert(res_type >= RT_MIN && res_type <= RT_MAX); 5447c478bd9Sstevel@tonic-gate return (res_types[res_type]); 5457c478bd9Sstevel@tonic-gate } 5467c478bd9Sstevel@tonic-gate 5477c478bd9Sstevel@tonic-gate static char * 5487c478bd9Sstevel@tonic-gate pt_to_str(int prop_type) 5497c478bd9Sstevel@tonic-gate { 5507c478bd9Sstevel@tonic-gate assert(prop_type >= PT_MIN && prop_type <= PT_MAX); 5517c478bd9Sstevel@tonic-gate return (prop_types[prop_type]); 5527c478bd9Sstevel@tonic-gate } 5537c478bd9Sstevel@tonic-gate 5547c478bd9Sstevel@tonic-gate static char * 5557c478bd9Sstevel@tonic-gate pvt_to_str(int pv_type) 5567c478bd9Sstevel@tonic-gate { 5577c478bd9Sstevel@tonic-gate assert(pv_type >= PROP_VAL_MIN && pv_type <= PROP_VAL_MAX); 5587c478bd9Sstevel@tonic-gate return (prop_val_types[pv_type]); 5597c478bd9Sstevel@tonic-gate } 5607c478bd9Sstevel@tonic-gate 5617c478bd9Sstevel@tonic-gate static char * 5627c478bd9Sstevel@tonic-gate cmd_to_str(int cmd_num) 5637c478bd9Sstevel@tonic-gate { 5647c478bd9Sstevel@tonic-gate assert(cmd_num >= CMD_MIN && cmd_num <= CMD_MAX); 5657c478bd9Sstevel@tonic-gate return (helptab[cmd_num].cmd_name); 5667c478bd9Sstevel@tonic-gate } 5677c478bd9Sstevel@tonic-gate 5687c478bd9Sstevel@tonic-gate /* 5697c478bd9Sstevel@tonic-gate * This is a separate function rather than a set of define's because of the 5707c478bd9Sstevel@tonic-gate * gettext() wrapping. 5717c478bd9Sstevel@tonic-gate */ 5727c478bd9Sstevel@tonic-gate 5737c478bd9Sstevel@tonic-gate /* 5747c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE 5757c478bd9Sstevel@tonic-gate * Each string below should have \t follow \n whenever needed; the 5767c478bd9Sstevel@tonic-gate * initial \t and the terminal \n will be provided by the calling function. 5777c478bd9Sstevel@tonic-gate */ 5787c478bd9Sstevel@tonic-gate 5797c478bd9Sstevel@tonic-gate static char * 5807c478bd9Sstevel@tonic-gate long_help(int cmd_num) 5817c478bd9Sstevel@tonic-gate { 5827c478bd9Sstevel@tonic-gate static char line[1024]; /* arbitrary large amount */ 5837c478bd9Sstevel@tonic-gate 5847c478bd9Sstevel@tonic-gate assert(cmd_num >= CMD_MIN && cmd_num <= CMD_MAX); 5857c478bd9Sstevel@tonic-gate switch (cmd_num) { 5867c478bd9Sstevel@tonic-gate case CMD_HELP: 5877c478bd9Sstevel@tonic-gate return (gettext("Prints help message.")); 5887c478bd9Sstevel@tonic-gate case CMD_CREATE: 5897c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 5907c478bd9Sstevel@tonic-gate gettext("Creates a configuration for the " 5917c478bd9Sstevel@tonic-gate "specified zone. %s should be\n\tused to " 5927c478bd9Sstevel@tonic-gate "begin configuring a new zone. If overwriting an " 5937c478bd9Sstevel@tonic-gate "existing\n\tconfiguration, the -F flag can be " 5947c478bd9Sstevel@tonic-gate "used to force the action. If\n\t-t template is " 5957c478bd9Sstevel@tonic-gate "given, creates a configuration identical to the\n" 5967c478bd9Sstevel@tonic-gate "\tspecified template, except that the zone name " 5977c478bd9Sstevel@tonic-gate "is changed from\n\ttemplate to zonename. '%s -b' " 5987c478bd9Sstevel@tonic-gate "results in a blank configuration.\n\t'%s' with no " 5997c478bd9Sstevel@tonic-gate "arguments applies the Sun default settings."), 6007c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE), cmd_to_str(CMD_CREATE), 6017c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE)); 6027c478bd9Sstevel@tonic-gate return (line); 6037c478bd9Sstevel@tonic-gate case CMD_EXIT: 6047c478bd9Sstevel@tonic-gate return (gettext("Exits the program. The -F flag can " 6057c478bd9Sstevel@tonic-gate "be used to force the action.")); 6067c478bd9Sstevel@tonic-gate case CMD_EXPORT: 6077c478bd9Sstevel@tonic-gate return (gettext("Prints configuration to standard " 6087c478bd9Sstevel@tonic-gate "output, or to output-file if\n\tspecified, in " 6097c478bd9Sstevel@tonic-gate "a form suitable for use in a command-file.")); 6107c478bd9Sstevel@tonic-gate case CMD_ADD: 6117c478bd9Sstevel@tonic-gate return (gettext("Add specified resource to " 6127c478bd9Sstevel@tonic-gate "configuration.")); 6137c478bd9Sstevel@tonic-gate case CMD_DELETE: 6147c478bd9Sstevel@tonic-gate return (gettext("Deletes the specified zone. The -F " 6157c478bd9Sstevel@tonic-gate "flag can be used to force the\n\taction.")); 6167c478bd9Sstevel@tonic-gate case CMD_REMOVE: 6177c478bd9Sstevel@tonic-gate return (gettext("Remove specified resource from " 6187c478bd9Sstevel@tonic-gate "configuration. Note that the curly\n\tbraces " 6197c478bd9Sstevel@tonic-gate "('{', '}') mean one or more of whatever " 6207c478bd9Sstevel@tonic-gate "is between them.")); 6217c478bd9Sstevel@tonic-gate case CMD_SELECT: 6227c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 6237c478bd9Sstevel@tonic-gate gettext("Selects a resource to modify. " 6247c478bd9Sstevel@tonic-gate "Resource modification is completed\n\twith the " 6257c478bd9Sstevel@tonic-gate "command \"%s\". The property name/value pairs " 6267c478bd9Sstevel@tonic-gate "must uniquely\n\tidentify a resource. Note that " 6277c478bd9Sstevel@tonic-gate "the curly braces ('{', '}') mean one\n\tor more " 6287c478bd9Sstevel@tonic-gate "of whatever is between them."), 6297c478bd9Sstevel@tonic-gate cmd_to_str(CMD_END)); 6307c478bd9Sstevel@tonic-gate return (line); 6317c478bd9Sstevel@tonic-gate case CMD_SET: 6327c478bd9Sstevel@tonic-gate return (gettext("Sets property values.")); 6337c478bd9Sstevel@tonic-gate case CMD_INFO: 6347c478bd9Sstevel@tonic-gate return (gettext("Displays information about the " 6357c478bd9Sstevel@tonic-gate "current configuration. If resource\n\ttype is " 6367c478bd9Sstevel@tonic-gate "specified, displays only information about " 6377c478bd9Sstevel@tonic-gate "resources of\n\tthe relevant type. If resource " 6387c478bd9Sstevel@tonic-gate "id is specified, displays only\n\tinformation " 6397c478bd9Sstevel@tonic-gate "about that resource.")); 6407c478bd9Sstevel@tonic-gate case CMD_VERIFY: 6417c478bd9Sstevel@tonic-gate return (gettext("Verifies current configuration " 6427c478bd9Sstevel@tonic-gate "for correctness (some resource types\n\thave " 6437c478bd9Sstevel@tonic-gate "required properties).")); 6447c478bd9Sstevel@tonic-gate case CMD_COMMIT: 6457c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 6467c478bd9Sstevel@tonic-gate gettext("Commits current configuration. " 6477c478bd9Sstevel@tonic-gate "Configuration must be committed to\n\tbe used by " 6487c478bd9Sstevel@tonic-gate "%s. Until the configuration is committed, " 6497c478bd9Sstevel@tonic-gate "changes \n\tcan be removed with the %s " 6507c478bd9Sstevel@tonic-gate "command. This operation is\n\tattempted " 6517c478bd9Sstevel@tonic-gate "automatically upon completion of a %s " 6527c478bd9Sstevel@tonic-gate "session."), "zoneadm", cmd_to_str(CMD_REVERT), 6537c478bd9Sstevel@tonic-gate "zonecfg"); 6547c478bd9Sstevel@tonic-gate return (line); 6557c478bd9Sstevel@tonic-gate case CMD_REVERT: 6567c478bd9Sstevel@tonic-gate return (gettext("Reverts configuration back to the " 6577c478bd9Sstevel@tonic-gate "last committed state. The -F flag\n\tcan be " 6587c478bd9Sstevel@tonic-gate "used to force the action.")); 6597c478bd9Sstevel@tonic-gate case CMD_CANCEL: 6607c478bd9Sstevel@tonic-gate return (gettext("Cancels resource/property " 6617c478bd9Sstevel@tonic-gate "specification.")); 6627c478bd9Sstevel@tonic-gate case CMD_END: 6637c478bd9Sstevel@tonic-gate return (gettext("Ends resource/property " 6647c478bd9Sstevel@tonic-gate "specification.")); 6657c478bd9Sstevel@tonic-gate } 6667c478bd9Sstevel@tonic-gate /* NOTREACHED */ 6677e362f58Scomay return (NULL); 6687c478bd9Sstevel@tonic-gate } 6697c478bd9Sstevel@tonic-gate 6707c478bd9Sstevel@tonic-gate /* 6717c478bd9Sstevel@tonic-gate * Called with verbose TRUE when help is explicitly requested, FALSE for 6727c478bd9Sstevel@tonic-gate * unexpected errors. 6737c478bd9Sstevel@tonic-gate */ 6747c478bd9Sstevel@tonic-gate 6757c478bd9Sstevel@tonic-gate void 6767c478bd9Sstevel@tonic-gate usage(bool verbose, uint_t flags) 6777c478bd9Sstevel@tonic-gate { 6787c478bd9Sstevel@tonic-gate FILE *fp = verbose ? stdout : stderr, *newfp; 6797c478bd9Sstevel@tonic-gate bool need_to_close = FALSE; 6807c478bd9Sstevel@tonic-gate char *pager; 6817c478bd9Sstevel@tonic-gate int i; 6827c478bd9Sstevel@tonic-gate 6837c478bd9Sstevel@tonic-gate /* don't page error output */ 6847c478bd9Sstevel@tonic-gate if (verbose && interactive_mode) { 6857c478bd9Sstevel@tonic-gate if ((pager = getenv("PAGER")) == NULL) 6867c478bd9Sstevel@tonic-gate pager = PAGER; 6877c478bd9Sstevel@tonic-gate if ((newfp = popen(pager, "w")) != NULL) { 6887c478bd9Sstevel@tonic-gate need_to_close = TRUE; 6897c478bd9Sstevel@tonic-gate fp = newfp; 6907c478bd9Sstevel@tonic-gate } 6917c478bd9Sstevel@tonic-gate } 6927c478bd9Sstevel@tonic-gate if (flags & HELP_META) { 6937c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("More help is available for the " 6947c478bd9Sstevel@tonic-gate "following:\n")); 6957c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\n\tcommands ('%s commands')\n", 6967c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 6977c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\tsyntax ('%s syntax')\n", 6987c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 6997c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\tusage ('%s usage')\n\n", 7007c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 7017c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("You may also obtain help on any " 7027c478bd9Sstevel@tonic-gate "command by typing '%s <command-name>.'\n"), 7037c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 7047c478bd9Sstevel@tonic-gate } 7057c478bd9Sstevel@tonic-gate if (flags & HELP_RES_SCOPE) { 7067c478bd9Sstevel@tonic-gate switch (resource_scope) { 7077c478bd9Sstevel@tonic-gate case RT_FS: 7087c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 7097c478bd9Sstevel@tonic-gate "used to configure a file-system.\n"), 7107c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 7117c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 7127c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7137c478bd9Sstevel@tonic-gate pt_to_str(PT_DIR), gettext("<path>")); 7147c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7157c478bd9Sstevel@tonic-gate pt_to_str(PT_SPECIAL), gettext("<path>")); 7167c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7177c478bd9Sstevel@tonic-gate pt_to_str(PT_RAW), gettext("<raw-device>")); 7187c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7197c478bd9Sstevel@tonic-gate pt_to_str(PT_TYPE), gettext("<file-system type>")); 7207c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s %s\n", cmd_to_str(CMD_ADD), 7217c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS), 7227c478bd9Sstevel@tonic-gate gettext("<file-system options>")); 7237c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Consult the file-system " 7247c478bd9Sstevel@tonic-gate "specific manual page, such as mount_ufs(1M), " 7257c478bd9Sstevel@tonic-gate "for\ndetails about file-system options. Note " 7267c478bd9Sstevel@tonic-gate "that any file-system options with an\nembedded " 7277c478bd9Sstevel@tonic-gate "'=' character must be enclosed in double quotes, " 7287c478bd9Sstevel@tonic-gate /*CSTYLED*/ 7297c478bd9Sstevel@tonic-gate "such as \"%s=5\".\n"), MNTOPT_RETRY); 7307c478bd9Sstevel@tonic-gate break; 7317c478bd9Sstevel@tonic-gate case RT_IPD: 7327c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 7337c478bd9Sstevel@tonic-gate "used to configure a directory\ninherited from the " 7347c478bd9Sstevel@tonic-gate "global zone into a non-global zone in read-only " 7357c478bd9Sstevel@tonic-gate "mode.\n"), rt_to_str(resource_scope)); 7367c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 7377c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7387c478bd9Sstevel@tonic-gate pt_to_str(PT_DIR), gettext("<path>")); 7397c478bd9Sstevel@tonic-gate break; 7407c478bd9Sstevel@tonic-gate case RT_NET: 7417c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 7427c478bd9Sstevel@tonic-gate "used to configure a network interface.\n"), 7437c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 7447c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 7457c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7467c478bd9Sstevel@tonic-gate pt_to_str(PT_ADDRESS), gettext("<IP-address>")); 7477c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7487c478bd9Sstevel@tonic-gate pt_to_str(PT_PHYSICAL), gettext("<interface>")); 7497c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("See ifconfig(1M) for " 7507c478bd9Sstevel@tonic-gate "details of the <interface> string.\n")); 7517c478bd9Sstevel@tonic-gate break; 7527c478bd9Sstevel@tonic-gate case RT_DEVICE: 7537c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 7547c478bd9Sstevel@tonic-gate "used to configure a device node.\n"), 7557c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 7567c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 7577c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7587c478bd9Sstevel@tonic-gate pt_to_str(PT_MATCH), gettext("<device-path>")); 7597c478bd9Sstevel@tonic-gate break; 7607c478bd9Sstevel@tonic-gate case RT_RCTL: 7617c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 7627c478bd9Sstevel@tonic-gate "used to configure a resource control.\n"), 7637c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 7647c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 7657c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7667c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), gettext("<string>")); 7677c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s (%s=%s,%s=%s,%s=%s)\n", 7687c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), pt_to_str(PT_VALUE), 7697c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV), gettext("<priv-value>"), 7707c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT), gettext("<number>"), 7717c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION), gettext("<action-value>")); 7727c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s\n\t%s := privileged\n" 7737c478bd9Sstevel@tonic-gate "\t%s := none | deny\n", gettext("Where"), 7747c478bd9Sstevel@tonic-gate gettext("<priv-value>"), gettext("<action-value>")); 7757c478bd9Sstevel@tonic-gate break; 7767c478bd9Sstevel@tonic-gate case RT_ATTR: 7777c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 7787c478bd9Sstevel@tonic-gate "used to configure a generic attribute.\n"), 7797c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 7807c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 7817c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7827c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), gettext("<name>")); 7837c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=boolean\n", 7847c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_TYPE)); 7857c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=true | false\n", 7867c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_VALUE)); 7877c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("or\n")); 7887c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=int\n", cmd_to_str(CMD_SET), 7897c478bd9Sstevel@tonic-gate pt_to_str(PT_TYPE)); 7907c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7917c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), gettext("<integer>")); 7927c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("or\n")); 7937c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=string\n", 7947c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_TYPE)); 7957c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 7967c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), gettext("<string>")); 7977c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("or\n")); 7987c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=uint\n", 7997c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_TYPE)); 8007c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 8017c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), gettext("<unsigned integer>")); 8027c478bd9Sstevel@tonic-gate break; 803fa9e4066Sahrens case RT_DATASET: 804fa9e4066Sahrens (void) fprintf(fp, gettext("The '%s' resource scope is " 805fa9e4066Sahrens "used to export ZFS datasets.\n"), 806fa9e4066Sahrens rt_to_str(resource_scope)); 807fa9e4066Sahrens (void) fprintf(fp, gettext("Valid commands:\n")); 808fa9e4066Sahrens (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 809fa9e4066Sahrens pt_to_str(PT_NAME), gettext("<name>")); 810fa9e4066Sahrens break; 8117c478bd9Sstevel@tonic-gate } 8127c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("And from any resource scope, you " 8137c478bd9Sstevel@tonic-gate "can:\n")); 8147c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", cmd_to_str(CMD_END), 8157c478bd9Sstevel@tonic-gate gettext("(to conclude this operation)")); 8167c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", cmd_to_str(CMD_CANCEL), 8177c478bd9Sstevel@tonic-gate gettext("(to cancel this operation)")); 8187c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", cmd_to_str(CMD_EXIT), 8197c478bd9Sstevel@tonic-gate gettext("(to exit the zonecfg utility)")); 8207c478bd9Sstevel@tonic-gate } 8217c478bd9Sstevel@tonic-gate if (flags & HELP_USAGE) { 8227c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\t%s %s\n", gettext("usage"), 8237c478bd9Sstevel@tonic-gate execname, cmd_to_str(CMD_HELP)); 8247c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s -z <zone>\t\t\t(%s)\n", 8257c478bd9Sstevel@tonic-gate execname, gettext("interactive")); 8267c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s -z <zone> <command>\n", execname); 8277c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s -z <zone> -f <command-file>\n", 8287c478bd9Sstevel@tonic-gate execname); 8297c478bd9Sstevel@tonic-gate } 8307c478bd9Sstevel@tonic-gate if (flags & HELP_SUBCMDS) { 8317c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n\n", gettext("Commands")); 8327c478bd9Sstevel@tonic-gate for (i = 0; i <= CMD_MAX; i++) { 8337c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s\n", helptab[i].short_usage); 8347c478bd9Sstevel@tonic-gate if (verbose) 8357c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\n\n", long_help(i)); 8367c478bd9Sstevel@tonic-gate } 8377c478bd9Sstevel@tonic-gate } 8387c478bd9Sstevel@tonic-gate if (flags & HELP_SYNTAX) { 8397c478bd9Sstevel@tonic-gate if (!verbose) 8407c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\n"); 8417c478bd9Sstevel@tonic-gate (void) fprintf(fp, "<zone> := [A-Za-z0-9][A-Za-z0-9_.-]*\n"); 8427c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("\t(except the reserved words " 8437c478bd9Sstevel@tonic-gate "'%s' and anything starting with '%s')\n"), "global", 8447c478bd9Sstevel@tonic-gate "SUNW"); 8457c478bd9Sstevel@tonic-gate (void) fprintf(fp, 8467c478bd9Sstevel@tonic-gate gettext("\tName must be less than %d characters.\n"), 8477c478bd9Sstevel@tonic-gate ZONENAME_MAX); 8487c478bd9Sstevel@tonic-gate if (verbose) 8497c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\n"); 8507c478bd9Sstevel@tonic-gate } 8517c478bd9Sstevel@tonic-gate if (flags & HELP_NETADDR) { 8527c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("\n<net-addr> :=")); 8537c478bd9Sstevel@tonic-gate (void) fprintf(fp, 8547c478bd9Sstevel@tonic-gate gettext("\t<IPv4-address>[/<IPv4-prefix-length>] |\n")); 8557c478bd9Sstevel@tonic-gate (void) fprintf(fp, 8567c478bd9Sstevel@tonic-gate gettext("\t\t<IPv6-address>/<IPv6-prefix-length> |\n")); 8577c478bd9Sstevel@tonic-gate (void) fprintf(fp, 8587c478bd9Sstevel@tonic-gate gettext("\t\t<hostname>[/<IPv4-prefix-length>]\n")); 8597c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("See inet(3SOCKET) for IPv4 and " 8607c478bd9Sstevel@tonic-gate "IPv6 address syntax.\n")); 8617c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("<IPv4-prefix-length> := [0-32]\n")); 8627c478bd9Sstevel@tonic-gate (void) fprintf(fp, 8637c478bd9Sstevel@tonic-gate gettext("<IPv6-prefix-length> := [0-128]\n")); 8647c478bd9Sstevel@tonic-gate (void) fprintf(fp, 8657c478bd9Sstevel@tonic-gate gettext("<hostname> := [A-Za-z0-9][A-Za-z0-9-.]*\n")); 8667c478bd9Sstevel@tonic-gate } 8677c478bd9Sstevel@tonic-gate if (flags & HELP_RESOURCES) { 8687c478bd9Sstevel@tonic-gate (void) fprintf(fp, "<%s> := %s | %s | %s | %s | %s | %s\n\n", 8697c478bd9Sstevel@tonic-gate gettext("resource type"), rt_to_str(RT_FS), 8707c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD), rt_to_str(RT_NET), rt_to_str(RT_DEVICE), 8717c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL), rt_to_str(RT_ATTR)); 8727c478bd9Sstevel@tonic-gate } 8737c478bd9Sstevel@tonic-gate if (flags & HELP_PROPS) { 8747c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("For resource type ... there are " 8757c478bd9Sstevel@tonic-gate "property types ...:\n")); 8767c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 877087719fdSdp pt_to_str(PT_ZONENAME)); 878087719fdSdp (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 8797c478bd9Sstevel@tonic-gate pt_to_str(PT_ZONEPATH)); 8807c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 8817c478bd9Sstevel@tonic-gate pt_to_str(PT_AUTOBOOT)); 8827c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 8837c478bd9Sstevel@tonic-gate pt_to_str(PT_POOL)); 8847c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s, %s, %s, %s\n", rt_to_str(RT_FS), 8857c478bd9Sstevel@tonic-gate pt_to_str(PT_DIR), pt_to_str(PT_SPECIAL), 8867c478bd9Sstevel@tonic-gate pt_to_str(PT_RAW), pt_to_str(PT_TYPE), 8877c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS)); 8887c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", rt_to_str(RT_IPD), 8897c478bd9Sstevel@tonic-gate pt_to_str(PT_DIR)); 8907c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s, %s\n", rt_to_str(RT_NET), 8917c478bd9Sstevel@tonic-gate pt_to_str(PT_ADDRESS), pt_to_str(PT_PHYSICAL)); 8927c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s\n", rt_to_str(RT_DEVICE), 8937c478bd9Sstevel@tonic-gate pt_to_str(PT_MATCH)); 8947c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s, %s\n", rt_to_str(RT_RCTL), 8957c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), pt_to_str(PT_VALUE)); 8967c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s, %s, %s\n", rt_to_str(RT_ATTR), 8977c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), pt_to_str(PT_TYPE), 8987c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE)); 899fa9e4066Sahrens (void) fprintf(fp, "\t%s\t\t%s\n", rt_to_str(RT_DATASET), 900fa9e4066Sahrens pt_to_str(PT_NAME)); 9017c478bd9Sstevel@tonic-gate } 9027c478bd9Sstevel@tonic-gate if (need_to_close) 9037c478bd9Sstevel@tonic-gate (void) pclose(fp); 9047c478bd9Sstevel@tonic-gate } 9057c478bd9Sstevel@tonic-gate 9067c478bd9Sstevel@tonic-gate /* PRINTFLIKE1 */ 9077c478bd9Sstevel@tonic-gate static void 9087c478bd9Sstevel@tonic-gate zerr(const char *fmt, ...) 9097c478bd9Sstevel@tonic-gate { 9107c478bd9Sstevel@tonic-gate va_list alist; 9117c478bd9Sstevel@tonic-gate static int last_lineno; 9127c478bd9Sstevel@tonic-gate 9137c478bd9Sstevel@tonic-gate /* lex_lineno has already been incremented in the lexer; compensate */ 9147c478bd9Sstevel@tonic-gate if (cmd_file_mode && lex_lineno > last_lineno) { 9157c478bd9Sstevel@tonic-gate if (strcmp(cmd_file_name, "-") == 0) 9167c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("On line %d:\n"), 9177c478bd9Sstevel@tonic-gate lex_lineno - 1); 9187c478bd9Sstevel@tonic-gate else 9197c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("On line %d of %s:\n"), 9207c478bd9Sstevel@tonic-gate lex_lineno - 1, cmd_file_name); 9217c478bd9Sstevel@tonic-gate last_lineno = lex_lineno; 9227c478bd9Sstevel@tonic-gate } 9237c478bd9Sstevel@tonic-gate va_start(alist, fmt); 9247c478bd9Sstevel@tonic-gate (void) vfprintf(stderr, fmt, alist); 9257c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\n"); 9267c478bd9Sstevel@tonic-gate va_end(alist); 9277c478bd9Sstevel@tonic-gate } 9287c478bd9Sstevel@tonic-gate 9297c478bd9Sstevel@tonic-gate static void 9307c478bd9Sstevel@tonic-gate zone_perror(char *prefix, int err, bool set_saw) 9317c478bd9Sstevel@tonic-gate { 9327c478bd9Sstevel@tonic-gate zerr("%s: %s", prefix, zonecfg_strerror(err)); 9337c478bd9Sstevel@tonic-gate if (set_saw) 9347c478bd9Sstevel@tonic-gate saw_error = TRUE; 9357c478bd9Sstevel@tonic-gate } 9367c478bd9Sstevel@tonic-gate 9377c478bd9Sstevel@tonic-gate /* 9387c478bd9Sstevel@tonic-gate * zone_perror() expects a single string, but for remove and select 9397c478bd9Sstevel@tonic-gate * we have both the command and the resource type, so this wrapper 9407c478bd9Sstevel@tonic-gate * function serves the same purpose in a slightly different way. 9417c478bd9Sstevel@tonic-gate */ 9427c478bd9Sstevel@tonic-gate 9437c478bd9Sstevel@tonic-gate static void 9447c478bd9Sstevel@tonic-gate z_cmd_rt_perror(int cmd_num, int res_num, int err, bool set_saw) 9457c478bd9Sstevel@tonic-gate { 9467c478bd9Sstevel@tonic-gate zerr("%s %s: %s", cmd_to_str(cmd_num), rt_to_str(res_num), 9477c478bd9Sstevel@tonic-gate zonecfg_strerror(err)); 9487c478bd9Sstevel@tonic-gate if (set_saw) 9497c478bd9Sstevel@tonic-gate saw_error = TRUE; 9507c478bd9Sstevel@tonic-gate } 9517c478bd9Sstevel@tonic-gate 9527c478bd9Sstevel@tonic-gate /* returns Z_OK if successful, Z_foo from <libzonecfg.h> otherwise */ 9537c478bd9Sstevel@tonic-gate static int 9547c478bd9Sstevel@tonic-gate initialize(bool handle_expected) 9557c478bd9Sstevel@tonic-gate { 9567c478bd9Sstevel@tonic-gate int err; 9577c478bd9Sstevel@tonic-gate 9587c478bd9Sstevel@tonic-gate if (zonecfg_check_handle(handle) != Z_OK) { 9597c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_handle(zone, handle)) == Z_OK) { 9607c478bd9Sstevel@tonic-gate got_handle = TRUE; 9617c478bd9Sstevel@tonic-gate } else { 9627c478bd9Sstevel@tonic-gate zone_perror(zone, err, handle_expected || got_handle); 9637c478bd9Sstevel@tonic-gate if (err == Z_NO_ZONE && !got_handle && 9647c478bd9Sstevel@tonic-gate interactive_mode && !read_only_mode) 9657c478bd9Sstevel@tonic-gate (void) printf(gettext("Use '%s' to begin " 9667c478bd9Sstevel@tonic-gate "configuring a new zone.\n"), 9677c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE)); 9687c478bd9Sstevel@tonic-gate return (err); 9697c478bd9Sstevel@tonic-gate } 9707c478bd9Sstevel@tonic-gate } 9717c478bd9Sstevel@tonic-gate return (Z_OK); 9727c478bd9Sstevel@tonic-gate } 9737c478bd9Sstevel@tonic-gate 974087719fdSdp static bool 975087719fdSdp state_atleast(zone_state_t state) 976087719fdSdp { 977087719fdSdp zone_state_t state_num; 978087719fdSdp int err; 979087719fdSdp 980087719fdSdp if ((err = zone_get_state(zone, &state_num)) != Z_OK) { 981087719fdSdp /* all states are greater than "non-existent" */ 982087719fdSdp if (err == Z_NO_ZONE) 983087719fdSdp return (B_FALSE); 984087719fdSdp zerr(gettext("Unexpectedly failed to determine state " 985087719fdSdp "of zone %s: %s"), zone, zonecfg_strerror(err)); 986087719fdSdp exit(Z_ERR); 987087719fdSdp } 988087719fdSdp return (state_num >= state); 989087719fdSdp } 990087719fdSdp 9917c478bd9Sstevel@tonic-gate /* 9927c478bd9Sstevel@tonic-gate * short_usage() is for bad syntax: getopt() issues, too many arguments, etc. 9937c478bd9Sstevel@tonic-gate */ 9947c478bd9Sstevel@tonic-gate 9957c478bd9Sstevel@tonic-gate void 9967c478bd9Sstevel@tonic-gate short_usage(int command) 9977c478bd9Sstevel@tonic-gate { 9987c478bd9Sstevel@tonic-gate /* lex_lineno has already been incremented in the lexer; compensate */ 9997c478bd9Sstevel@tonic-gate if (cmd_file_mode) { 10007c478bd9Sstevel@tonic-gate if (strcmp(cmd_file_name, "-") == 0) 10017c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 10027c478bd9Sstevel@tonic-gate gettext("syntax error on line %d\n"), 10037c478bd9Sstevel@tonic-gate lex_lineno - 1); 10047c478bd9Sstevel@tonic-gate else 10057c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 10067c478bd9Sstevel@tonic-gate gettext("syntax error on line %d of %s\n"), 10077c478bd9Sstevel@tonic-gate lex_lineno - 1, cmd_file_name); 10087c478bd9Sstevel@tonic-gate } 10097c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s:\n%s\n", gettext("usage"), 10107c478bd9Sstevel@tonic-gate helptab[command].short_usage); 10117c478bd9Sstevel@tonic-gate saw_error = TRUE; 10127c478bd9Sstevel@tonic-gate } 10137c478bd9Sstevel@tonic-gate 10147c478bd9Sstevel@tonic-gate /* 10157c478bd9Sstevel@tonic-gate * long_usage() is for bad semantics: e.g., wrong property type for a given 10167c478bd9Sstevel@tonic-gate * resource type. It is also used by longer_usage() below. 10177c478bd9Sstevel@tonic-gate */ 10187c478bd9Sstevel@tonic-gate 10197c478bd9Sstevel@tonic-gate void 10207c478bd9Sstevel@tonic-gate long_usage(uint_t cmd_num, bool set_saw) 10217c478bd9Sstevel@tonic-gate { 10227c478bd9Sstevel@tonic-gate (void) fprintf(set_saw ? stderr : stdout, "%s:\n%s\n", gettext("usage"), 10237c478bd9Sstevel@tonic-gate helptab[cmd_num].short_usage); 10247c478bd9Sstevel@tonic-gate (void) fprintf(set_saw ? stderr : stdout, "\t%s\n", long_help(cmd_num)); 10257c478bd9Sstevel@tonic-gate if (set_saw) 10267c478bd9Sstevel@tonic-gate saw_error = TRUE; 10277c478bd9Sstevel@tonic-gate } 10287c478bd9Sstevel@tonic-gate 10297c478bd9Sstevel@tonic-gate /* 10307c478bd9Sstevel@tonic-gate * longer_usage() is for 'help foo' and 'foo -?': call long_usage() and also 10317c478bd9Sstevel@tonic-gate * any extra usage() flags as appropriate for whatever command. 10327c478bd9Sstevel@tonic-gate */ 10337c478bd9Sstevel@tonic-gate 10347c478bd9Sstevel@tonic-gate void 10357c478bd9Sstevel@tonic-gate longer_usage(uint_t cmd_num) 10367c478bd9Sstevel@tonic-gate { 10377c478bd9Sstevel@tonic-gate long_usage(cmd_num, FALSE); 10387c478bd9Sstevel@tonic-gate if (helptab[cmd_num].flags != 0) { 10397c478bd9Sstevel@tonic-gate (void) printf("\n"); 10407c478bd9Sstevel@tonic-gate usage(TRUE, helptab[cmd_num].flags); 10417c478bd9Sstevel@tonic-gate } 10427c478bd9Sstevel@tonic-gate } 10437c478bd9Sstevel@tonic-gate 10447c478bd9Sstevel@tonic-gate /* 10457c478bd9Sstevel@tonic-gate * scope_usage() is simply used when a command is called from the wrong scope. 10467c478bd9Sstevel@tonic-gate */ 10477c478bd9Sstevel@tonic-gate 10487c478bd9Sstevel@tonic-gate static void 10497c478bd9Sstevel@tonic-gate scope_usage(uint_t cmd_num) 10507c478bd9Sstevel@tonic-gate { 10517c478bd9Sstevel@tonic-gate zerr(gettext("The %s command only makes sense in the %s scope."), 10527c478bd9Sstevel@tonic-gate cmd_to_str(cmd_num), 10537c478bd9Sstevel@tonic-gate global_scope ? gettext("resource") : gettext("global")); 10547c478bd9Sstevel@tonic-gate saw_error = TRUE; 10557c478bd9Sstevel@tonic-gate } 10567c478bd9Sstevel@tonic-gate 10577c478bd9Sstevel@tonic-gate /* 10587c478bd9Sstevel@tonic-gate * On input, TRUE => yes, FALSE => no. 10597c478bd9Sstevel@tonic-gate * On return, TRUE => 1, FALSE => no, could not ask => -1. 10607c478bd9Sstevel@tonic-gate */ 10617c478bd9Sstevel@tonic-gate 10627c478bd9Sstevel@tonic-gate static int 10637c478bd9Sstevel@tonic-gate ask_yesno(bool default_answer, const char *question) 10647c478bd9Sstevel@tonic-gate { 10657c478bd9Sstevel@tonic-gate char line[64]; /* should be enough to answer yes or no */ 10667c478bd9Sstevel@tonic-gate 10677c478bd9Sstevel@tonic-gate if (!ok_to_prompt) { 10687c478bd9Sstevel@tonic-gate saw_error = TRUE; 10697c478bd9Sstevel@tonic-gate return (-1); 10707c478bd9Sstevel@tonic-gate } 10717c478bd9Sstevel@tonic-gate for (;;) { 1072087719fdSdp if (printf("%s (%s)? ", question, 1073087719fdSdp default_answer ? "[y]/n" : "y/[n]") < 0) 1074087719fdSdp return (-1); 1075087719fdSdp if (fgets(line, sizeof (line), stdin) == NULL) 1076087719fdSdp return (-1); 1077087719fdSdp 1078087719fdSdp if (line[0] == '\n') 10797c478bd9Sstevel@tonic-gate return (default_answer ? 1 : 0); 10807c478bd9Sstevel@tonic-gate if (tolower(line[0]) == 'y') 10817c478bd9Sstevel@tonic-gate return (1); 10827c478bd9Sstevel@tonic-gate if (tolower(line[0]) == 'n') 10837c478bd9Sstevel@tonic-gate return (0); 10847c478bd9Sstevel@tonic-gate } 10857c478bd9Sstevel@tonic-gate } 10867c478bd9Sstevel@tonic-gate 10877c478bd9Sstevel@tonic-gate /* 10887c478bd9Sstevel@tonic-gate * Prints warning if zone already exists. 10897c478bd9Sstevel@tonic-gate * In interactive mode, prompts if we should continue anyway and returns Z_OK 10907c478bd9Sstevel@tonic-gate * if so, Z_ERR if not. In non-interactive mode, exits with Z_ERR. 10917c478bd9Sstevel@tonic-gate * 10927c478bd9Sstevel@tonic-gate * Note that if a zone exists and its state is >= INSTALLED, an error message 10937c478bd9Sstevel@tonic-gate * will be printed and this function will return Z_ERR regardless of mode. 10947c478bd9Sstevel@tonic-gate */ 10957c478bd9Sstevel@tonic-gate 10967c478bd9Sstevel@tonic-gate static int 10977c478bd9Sstevel@tonic-gate check_if_zone_already_exists(bool force) 10987c478bd9Sstevel@tonic-gate { 10997c478bd9Sstevel@tonic-gate char line[ZONENAME_MAX + 128]; /* enough to ask a question */ 11007c478bd9Sstevel@tonic-gate zone_dochandle_t tmphandle; 11017c478bd9Sstevel@tonic-gate int res, answer; 11027c478bd9Sstevel@tonic-gate 11037c478bd9Sstevel@tonic-gate if ((tmphandle = zonecfg_init_handle()) == NULL) { 11047c478bd9Sstevel@tonic-gate zone_perror(execname, Z_NOMEM, TRUE); 11057c478bd9Sstevel@tonic-gate exit(Z_ERR); 11067c478bd9Sstevel@tonic-gate } 11077c478bd9Sstevel@tonic-gate res = zonecfg_get_handle(zone, tmphandle); 11087c478bd9Sstevel@tonic-gate zonecfg_fini_handle(tmphandle); 1109087719fdSdp if (res != Z_OK) 11107c478bd9Sstevel@tonic-gate return (Z_OK); 1111087719fdSdp 1112087719fdSdp if (state_atleast(ZONE_STATE_INSTALLED)) { 11137c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s already installed; %s not allowed."), 11147c478bd9Sstevel@tonic-gate zone, cmd_to_str(CMD_CREATE)); 11157c478bd9Sstevel@tonic-gate return (Z_ERR); 11167c478bd9Sstevel@tonic-gate } 11177c478bd9Sstevel@tonic-gate 11187c478bd9Sstevel@tonic-gate if (force) { 11197c478bd9Sstevel@tonic-gate (void) printf(gettext("Zone %s already exists; overwriting.\n"), 11207c478bd9Sstevel@tonic-gate zone); 11217c478bd9Sstevel@tonic-gate return (Z_OK); 11227c478bd9Sstevel@tonic-gate } 11237c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 11247c478bd9Sstevel@tonic-gate gettext("Zone %s already exists; %s anyway"), zone, 11257c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE)); 11267c478bd9Sstevel@tonic-gate if ((answer = ask_yesno(FALSE, line)) == -1) { 11277c478bd9Sstevel@tonic-gate zerr(gettext("Zone exists, input not from terminal and -F not " 11287c478bd9Sstevel@tonic-gate "specified:\n%s command ignored, exiting."), 11297c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE)); 11307c478bd9Sstevel@tonic-gate exit(Z_ERR); 11317c478bd9Sstevel@tonic-gate } 11327c478bd9Sstevel@tonic-gate return (answer == 1 ? Z_OK : Z_ERR); 11337c478bd9Sstevel@tonic-gate } 11347c478bd9Sstevel@tonic-gate 11357c478bd9Sstevel@tonic-gate static bool 11367c478bd9Sstevel@tonic-gate zone_is_read_only(int cmd_num) 11377c478bd9Sstevel@tonic-gate { 11387c478bd9Sstevel@tonic-gate if (strncmp(zone, "SUNW", 4) == 0) { 11397c478bd9Sstevel@tonic-gate zerr(gettext("%s: zones beginning with SUNW are read-only."), 11407c478bd9Sstevel@tonic-gate zone); 11417c478bd9Sstevel@tonic-gate saw_error = TRUE; 11427c478bd9Sstevel@tonic-gate return (TRUE); 11437c478bd9Sstevel@tonic-gate } 11447c478bd9Sstevel@tonic-gate if (read_only_mode) { 11457c478bd9Sstevel@tonic-gate zerr(gettext("%s: cannot %s in read-only mode."), zone, 11467c478bd9Sstevel@tonic-gate cmd_to_str(cmd_num)); 11477c478bd9Sstevel@tonic-gate saw_error = TRUE; 11487c478bd9Sstevel@tonic-gate return (TRUE); 11497c478bd9Sstevel@tonic-gate } 11507c478bd9Sstevel@tonic-gate return (FALSE); 11517c478bd9Sstevel@tonic-gate } 11527c478bd9Sstevel@tonic-gate 11537c478bd9Sstevel@tonic-gate /* 11547c478bd9Sstevel@tonic-gate * Create a new configuration. 11557c478bd9Sstevel@tonic-gate */ 11567c478bd9Sstevel@tonic-gate void 11577c478bd9Sstevel@tonic-gate create_func(cmd_t *cmd) 11587c478bd9Sstevel@tonic-gate { 11597c478bd9Sstevel@tonic-gate int err, arg; 11607c478bd9Sstevel@tonic-gate char zone_template[ZONENAME_MAX]; 11617c478bd9Sstevel@tonic-gate zone_dochandle_t tmphandle; 11627c478bd9Sstevel@tonic-gate bool force = FALSE; 11637c478bd9Sstevel@tonic-gate 11647c478bd9Sstevel@tonic-gate assert(cmd != NULL); 11657c478bd9Sstevel@tonic-gate 11667c478bd9Sstevel@tonic-gate /* This is the default if no arguments are given. */ 11677c478bd9Sstevel@tonic-gate (void) strlcpy(zone_template, "SUNWdefault", sizeof (zone_template)); 11687c478bd9Sstevel@tonic-gate 11697c478bd9Sstevel@tonic-gate optind = 0; 11707c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?bFt:")) != EOF) { 11717c478bd9Sstevel@tonic-gate switch (arg) { 11727c478bd9Sstevel@tonic-gate case '?': 11737c478bd9Sstevel@tonic-gate if (optopt == '?') 11747c478bd9Sstevel@tonic-gate longer_usage(CMD_CREATE); 11757c478bd9Sstevel@tonic-gate else 11767c478bd9Sstevel@tonic-gate short_usage(CMD_CREATE); 11777c478bd9Sstevel@tonic-gate return; 11787c478bd9Sstevel@tonic-gate case 'b': 11797c478bd9Sstevel@tonic-gate (void) strlcpy(zone_template, "SUNWblank", 11807c478bd9Sstevel@tonic-gate sizeof (zone_template)); 11817c478bd9Sstevel@tonic-gate break; 11827c478bd9Sstevel@tonic-gate case 'F': 11837c478bd9Sstevel@tonic-gate force = TRUE; 11847c478bd9Sstevel@tonic-gate break; 11857c478bd9Sstevel@tonic-gate case 't': 11867c478bd9Sstevel@tonic-gate (void) strlcpy(zone_template, optarg, 11877c478bd9Sstevel@tonic-gate sizeof (zone_template)); 11887c478bd9Sstevel@tonic-gate break; 11897c478bd9Sstevel@tonic-gate default: 11907c478bd9Sstevel@tonic-gate short_usage(CMD_CREATE); 11917c478bd9Sstevel@tonic-gate return; 11927c478bd9Sstevel@tonic-gate } 11937c478bd9Sstevel@tonic-gate } 11947c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 11957c478bd9Sstevel@tonic-gate short_usage(CMD_CREATE); 11967c478bd9Sstevel@tonic-gate return; 11977c478bd9Sstevel@tonic-gate } 11987c478bd9Sstevel@tonic-gate 11997c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_CREATE)) 12007c478bd9Sstevel@tonic-gate return; 12017c478bd9Sstevel@tonic-gate 12027c478bd9Sstevel@tonic-gate if (check_if_zone_already_exists(force) != Z_OK) 12037c478bd9Sstevel@tonic-gate return; 12047c478bd9Sstevel@tonic-gate 12057c478bd9Sstevel@tonic-gate /* 12067c478bd9Sstevel@tonic-gate * Get a temporary handle first. If that fails, the old handle 12077c478bd9Sstevel@tonic-gate * will not be lost. Then finish whichever one we don't need, 12087c478bd9Sstevel@tonic-gate * to avoid leaks. Then get the handle for zone_template, and 12097c478bd9Sstevel@tonic-gate * set the name to zone: this "copy, rename" method is how 12107c478bd9Sstevel@tonic-gate * create -[b|t] works. 12117c478bd9Sstevel@tonic-gate */ 12127c478bd9Sstevel@tonic-gate if ((tmphandle = zonecfg_init_handle()) == NULL) { 12137c478bd9Sstevel@tonic-gate zone_perror(execname, Z_NOMEM, TRUE); 12147c478bd9Sstevel@tonic-gate exit(Z_ERR); 12157c478bd9Sstevel@tonic-gate } 1216087719fdSdp if ((err = zonecfg_get_template_handle(zone_template, zone, 1217087719fdSdp tmphandle)) != Z_OK) { 12187c478bd9Sstevel@tonic-gate zonecfg_fini_handle(tmphandle); 12197c478bd9Sstevel@tonic-gate zone_perror(zone_template, err, TRUE); 12207c478bd9Sstevel@tonic-gate return; 12217c478bd9Sstevel@tonic-gate } 1222087719fdSdp 1223087719fdSdp need_to_commit = TRUE; 12247c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 12257c478bd9Sstevel@tonic-gate handle = tmphandle; 1226087719fdSdp got_handle = TRUE; 12277c478bd9Sstevel@tonic-gate } 12287c478bd9Sstevel@tonic-gate 12297c478bd9Sstevel@tonic-gate /* 12307c478bd9Sstevel@tonic-gate * This malloc()'s memory, which must be freed by the caller. 12317c478bd9Sstevel@tonic-gate */ 12327c478bd9Sstevel@tonic-gate static char * 12337c478bd9Sstevel@tonic-gate quoteit(char *instr) 12347c478bd9Sstevel@tonic-gate { 12357c478bd9Sstevel@tonic-gate char *outstr; 12367c478bd9Sstevel@tonic-gate size_t outstrsize = strlen(instr) + 3; /* 2 quotes + '\0' */ 12377c478bd9Sstevel@tonic-gate 12387c478bd9Sstevel@tonic-gate if ((outstr = malloc(outstrsize)) == NULL) { 12397c478bd9Sstevel@tonic-gate zone_perror(zone, Z_NOMEM, FALSE); 12407c478bd9Sstevel@tonic-gate exit(Z_ERR); 12417c478bd9Sstevel@tonic-gate } 12427c478bd9Sstevel@tonic-gate if (strchr(instr, ' ') == NULL) { 12437c478bd9Sstevel@tonic-gate (void) strlcpy(outstr, instr, outstrsize); 12447c478bd9Sstevel@tonic-gate return (outstr); 12457c478bd9Sstevel@tonic-gate } 12467c478bd9Sstevel@tonic-gate (void) snprintf(outstr, outstrsize, "\"%s\"", instr); 12477c478bd9Sstevel@tonic-gate return (outstr); 12487c478bd9Sstevel@tonic-gate } 12497c478bd9Sstevel@tonic-gate 12507c478bd9Sstevel@tonic-gate static void 12517c478bd9Sstevel@tonic-gate export_prop(FILE *of, int prop_num, char *prop_id) 12527c478bd9Sstevel@tonic-gate { 12537c478bd9Sstevel@tonic-gate char *quote_str; 12547c478bd9Sstevel@tonic-gate 12557c478bd9Sstevel@tonic-gate if (strlen(prop_id) == 0) 12567c478bd9Sstevel@tonic-gate return; 12577c478bd9Sstevel@tonic-gate quote_str = quoteit(prop_id); 12587c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 12597c478bd9Sstevel@tonic-gate pt_to_str(prop_num), quote_str); 12607c478bd9Sstevel@tonic-gate free(quote_str); 12617c478bd9Sstevel@tonic-gate } 12627c478bd9Sstevel@tonic-gate 12637c478bd9Sstevel@tonic-gate void 12647c478bd9Sstevel@tonic-gate export_func(cmd_t *cmd) 12657c478bd9Sstevel@tonic-gate { 12667c478bd9Sstevel@tonic-gate struct zone_nwiftab nwiftab; 12677c478bd9Sstevel@tonic-gate struct zone_fstab fstab; 12687c478bd9Sstevel@tonic-gate struct zone_devtab devtab; 12697c478bd9Sstevel@tonic-gate struct zone_attrtab attrtab; 12707c478bd9Sstevel@tonic-gate struct zone_rctltab rctltab; 1271fa9e4066Sahrens struct zone_dstab dstab; 12727c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *valptr; 12737c478bd9Sstevel@tonic-gate int err, arg; 12747c478bd9Sstevel@tonic-gate char zonepath[MAXPATHLEN], outfile[MAXPATHLEN], pool[MAXNAMELEN]; 12757c478bd9Sstevel@tonic-gate FILE *of; 12767c478bd9Sstevel@tonic-gate boolean_t autoboot; 12777c478bd9Sstevel@tonic-gate bool need_to_close = FALSE; 12787c478bd9Sstevel@tonic-gate 12797c478bd9Sstevel@tonic-gate assert(cmd != NULL); 12807c478bd9Sstevel@tonic-gate 12817c478bd9Sstevel@tonic-gate outfile[0] = '\0'; 12827c478bd9Sstevel@tonic-gate optind = 0; 12837c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?f:")) != EOF) { 12847c478bd9Sstevel@tonic-gate switch (arg) { 12857c478bd9Sstevel@tonic-gate case '?': 12867c478bd9Sstevel@tonic-gate if (optopt == '?') 12877c478bd9Sstevel@tonic-gate longer_usage(CMD_EXPORT); 12887c478bd9Sstevel@tonic-gate else 12897c478bd9Sstevel@tonic-gate short_usage(CMD_EXPORT); 12907c478bd9Sstevel@tonic-gate return; 12917c478bd9Sstevel@tonic-gate case 'f': 12927c478bd9Sstevel@tonic-gate (void) strlcpy(outfile, optarg, sizeof (outfile)); 12937c478bd9Sstevel@tonic-gate break; 12947c478bd9Sstevel@tonic-gate default: 12957c478bd9Sstevel@tonic-gate short_usage(CMD_EXPORT); 12967c478bd9Sstevel@tonic-gate return; 12977c478bd9Sstevel@tonic-gate } 12987c478bd9Sstevel@tonic-gate } 12997c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 13007c478bd9Sstevel@tonic-gate short_usage(CMD_EXPORT); 13017c478bd9Sstevel@tonic-gate return; 13027c478bd9Sstevel@tonic-gate } 13037c478bd9Sstevel@tonic-gate if (strlen(outfile) == 0) { 13047c478bd9Sstevel@tonic-gate of = stdout; 13057c478bd9Sstevel@tonic-gate } else { 13067c478bd9Sstevel@tonic-gate if ((of = fopen(outfile, "w")) == NULL) { 13077c478bd9Sstevel@tonic-gate zerr(gettext("opening file %s: %s"), 13087c478bd9Sstevel@tonic-gate outfile, strerror(errno)); 13097c478bd9Sstevel@tonic-gate goto done; 13107c478bd9Sstevel@tonic-gate } 13117c478bd9Sstevel@tonic-gate setbuf(of, NULL); 13127c478bd9Sstevel@tonic-gate need_to_close = TRUE; 13137c478bd9Sstevel@tonic-gate } 13147c478bd9Sstevel@tonic-gate 13157c478bd9Sstevel@tonic-gate if ((err = initialize(TRUE)) != Z_OK) 13167c478bd9Sstevel@tonic-gate goto done; 13177c478bd9Sstevel@tonic-gate 13187c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s -b\n", cmd_to_str(CMD_CREATE)); 13197c478bd9Sstevel@tonic-gate 13207c478bd9Sstevel@tonic-gate if (zonecfg_get_zonepath(handle, zonepath, sizeof (zonepath)) == Z_OK && 13217c478bd9Sstevel@tonic-gate strlen(zonepath) > 0) 13227c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 13237c478bd9Sstevel@tonic-gate pt_to_str(PT_ZONEPATH), zonepath); 13247c478bd9Sstevel@tonic-gate 13257c478bd9Sstevel@tonic-gate if (zonecfg_get_autoboot(handle, &autoboot) == Z_OK) 13267c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 13277c478bd9Sstevel@tonic-gate pt_to_str(PT_AUTOBOOT), autoboot ? "true" : "false"); 13287c478bd9Sstevel@tonic-gate 13297c478bd9Sstevel@tonic-gate if (zonecfg_get_pool(handle, pool, sizeof (pool)) == Z_OK && 13307c478bd9Sstevel@tonic-gate strlen(pool) > 0) 13317c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 13327c478bd9Sstevel@tonic-gate pt_to_str(PT_POOL), pool); 13337c478bd9Sstevel@tonic-gate 13347c478bd9Sstevel@tonic-gate if ((err = zonecfg_setipdent(handle)) != Z_OK) { 13357c478bd9Sstevel@tonic-gate zone_perror(zone, err, FALSE); 13367c478bd9Sstevel@tonic-gate goto done; 13377c478bd9Sstevel@tonic-gate } 13387c478bd9Sstevel@tonic-gate while (zonecfg_getipdent(handle, &fstab) == Z_OK) { 13397c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 13407c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD)); 13417c478bd9Sstevel@tonic-gate export_prop(of, PT_DIR, fstab.zone_fs_dir); 13427c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 13437c478bd9Sstevel@tonic-gate } 13447c478bd9Sstevel@tonic-gate (void) zonecfg_endipdent(handle); 13457c478bd9Sstevel@tonic-gate 13467c478bd9Sstevel@tonic-gate if ((err = zonecfg_setfsent(handle)) != Z_OK) { 13477c478bd9Sstevel@tonic-gate zone_perror(zone, err, FALSE); 13487c478bd9Sstevel@tonic-gate goto done; 13497c478bd9Sstevel@tonic-gate } 13507c478bd9Sstevel@tonic-gate while (zonecfg_getfsent(handle, &fstab) == Z_OK) { 13517c478bd9Sstevel@tonic-gate zone_fsopt_t *optptr; 13527c478bd9Sstevel@tonic-gate 13537c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 13547c478bd9Sstevel@tonic-gate rt_to_str(RT_FS)); 13557c478bd9Sstevel@tonic-gate export_prop(of, PT_DIR, fstab.zone_fs_dir); 13567c478bd9Sstevel@tonic-gate export_prop(of, PT_SPECIAL, fstab.zone_fs_special); 13577c478bd9Sstevel@tonic-gate export_prop(of, PT_RAW, fstab.zone_fs_raw); 13587c478bd9Sstevel@tonic-gate export_prop(of, PT_TYPE, fstab.zone_fs_type); 13597c478bd9Sstevel@tonic-gate for (optptr = fstab.zone_fs_options; optptr != NULL; 13607c478bd9Sstevel@tonic-gate optptr = optptr->zone_fsopt_next) { 13617c478bd9Sstevel@tonic-gate /* 13627c478bd9Sstevel@tonic-gate * Simple property values with embedded equal signs 13637c478bd9Sstevel@tonic-gate * need to be quoted to prevent the lexer from 13647c478bd9Sstevel@tonic-gate * mis-parsing them as complex name=value pairs. 13657c478bd9Sstevel@tonic-gate */ 13667c478bd9Sstevel@tonic-gate if (strchr(optptr->zone_fsopt_opt, '=')) 13677c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s \"%s\"\n", 13687c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), 13697c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS), 13707c478bd9Sstevel@tonic-gate optptr->zone_fsopt_opt); 13717c478bd9Sstevel@tonic-gate else 13727c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s %s\n", 13737c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), 13747c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS), 13757c478bd9Sstevel@tonic-gate optptr->zone_fsopt_opt); 13767c478bd9Sstevel@tonic-gate } 13777c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 13787c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(fstab.zone_fs_options); 13797c478bd9Sstevel@tonic-gate } 13807c478bd9Sstevel@tonic-gate (void) zonecfg_endfsent(handle); 13817c478bd9Sstevel@tonic-gate 13827c478bd9Sstevel@tonic-gate if ((err = zonecfg_setnwifent(handle)) != Z_OK) { 13837c478bd9Sstevel@tonic-gate zone_perror(zone, err, FALSE); 13847c478bd9Sstevel@tonic-gate goto done; 13857c478bd9Sstevel@tonic-gate } 13867c478bd9Sstevel@tonic-gate while (zonecfg_getnwifent(handle, &nwiftab) == Z_OK) { 13877c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 13887c478bd9Sstevel@tonic-gate rt_to_str(RT_NET)); 13897c478bd9Sstevel@tonic-gate export_prop(of, PT_ADDRESS, nwiftab.zone_nwif_address); 13907c478bd9Sstevel@tonic-gate export_prop(of, PT_PHYSICAL, nwiftab.zone_nwif_physical); 13917c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 13927c478bd9Sstevel@tonic-gate } 13937c478bd9Sstevel@tonic-gate (void) zonecfg_endnwifent(handle); 13947c478bd9Sstevel@tonic-gate 13957c478bd9Sstevel@tonic-gate if ((err = zonecfg_setdevent(handle)) != Z_OK) { 13967c478bd9Sstevel@tonic-gate zone_perror(zone, err, FALSE); 13977c478bd9Sstevel@tonic-gate goto done; 13987c478bd9Sstevel@tonic-gate } 13997c478bd9Sstevel@tonic-gate while (zonecfg_getdevent(handle, &devtab) == Z_OK) { 14007c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 14017c478bd9Sstevel@tonic-gate rt_to_str(RT_DEVICE)); 14027c478bd9Sstevel@tonic-gate export_prop(of, PT_MATCH, devtab.zone_dev_match); 14037c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 14047c478bd9Sstevel@tonic-gate } 14057c478bd9Sstevel@tonic-gate (void) zonecfg_enddevent(handle); 14067c478bd9Sstevel@tonic-gate 14077c478bd9Sstevel@tonic-gate if ((err = zonecfg_setrctlent(handle)) != Z_OK) { 14087c478bd9Sstevel@tonic-gate zone_perror(zone, err, FALSE); 14097c478bd9Sstevel@tonic-gate goto done; 14107c478bd9Sstevel@tonic-gate } 14117c478bd9Sstevel@tonic-gate while (zonecfg_getrctlent(handle, &rctltab) == Z_OK) { 14127c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s rctl\n", cmd_to_str(CMD_ADD)); 14137c478bd9Sstevel@tonic-gate export_prop(of, PT_NAME, rctltab.zone_rctl_name); 14147c478bd9Sstevel@tonic-gate for (valptr = rctltab.zone_rctl_valptr; valptr != NULL; 14157c478bd9Sstevel@tonic-gate valptr = valptr->zone_rctlval_next) { 14167c478bd9Sstevel@tonic-gate fprintf(of, "%s %s (%s=%s,%s=%s,%s=%s)\n", 14177c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), pt_to_str(PT_VALUE), 14187c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV), valptr->zone_rctlval_priv, 14197c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT), valptr->zone_rctlval_limit, 14207c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION), valptr->zone_rctlval_action); 14217c478bd9Sstevel@tonic-gate } 14227c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 14237c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr); 14247c478bd9Sstevel@tonic-gate } 14257c478bd9Sstevel@tonic-gate (void) zonecfg_endrctlent(handle); 14267c478bd9Sstevel@tonic-gate 14277c478bd9Sstevel@tonic-gate if ((err = zonecfg_setattrent(handle)) != Z_OK) { 14287c478bd9Sstevel@tonic-gate zone_perror(zone, err, FALSE); 14297c478bd9Sstevel@tonic-gate goto done; 14307c478bd9Sstevel@tonic-gate } 14317c478bd9Sstevel@tonic-gate while (zonecfg_getattrent(handle, &attrtab) == Z_OK) { 14327c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 14337c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR)); 14347c478bd9Sstevel@tonic-gate export_prop(of, PT_NAME, attrtab.zone_attr_name); 14357c478bd9Sstevel@tonic-gate export_prop(of, PT_TYPE, attrtab.zone_attr_type); 14367c478bd9Sstevel@tonic-gate export_prop(of, PT_VALUE, attrtab.zone_attr_value); 14377c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 14387c478bd9Sstevel@tonic-gate } 14397c478bd9Sstevel@tonic-gate (void) zonecfg_endattrent(handle); 14407c478bd9Sstevel@tonic-gate 1441fa9e4066Sahrens if ((err = zonecfg_setdsent(handle)) != Z_OK) { 1442fa9e4066Sahrens zone_perror(zone, err, FALSE); 1443fa9e4066Sahrens goto done; 1444fa9e4066Sahrens } 1445fa9e4066Sahrens while (zonecfg_getdsent(handle, &dstab) == Z_OK) { 1446fa9e4066Sahrens (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 1447fa9e4066Sahrens rt_to_str(RT_DATASET)); 1448fa9e4066Sahrens export_prop(of, PT_NAME, dstab.zone_dataset_name); 1449fa9e4066Sahrens (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 1450fa9e4066Sahrens } 1451fa9e4066Sahrens (void) zonecfg_enddsent(handle); 1452fa9e4066Sahrens 14537c478bd9Sstevel@tonic-gate done: 14547c478bd9Sstevel@tonic-gate if (need_to_close) 14557c478bd9Sstevel@tonic-gate (void) fclose(of); 14567c478bd9Sstevel@tonic-gate } 14577c478bd9Sstevel@tonic-gate 14587c478bd9Sstevel@tonic-gate void 14597c478bd9Sstevel@tonic-gate exit_func(cmd_t *cmd) 14607c478bd9Sstevel@tonic-gate { 14617c478bd9Sstevel@tonic-gate int arg, answer; 14627c478bd9Sstevel@tonic-gate 14637c478bd9Sstevel@tonic-gate optind = 0; 14647c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 14657c478bd9Sstevel@tonic-gate switch (arg) { 14667c478bd9Sstevel@tonic-gate case '?': 14677c478bd9Sstevel@tonic-gate longer_usage(CMD_EXIT); 14687c478bd9Sstevel@tonic-gate return; 14697c478bd9Sstevel@tonic-gate case 'F': 14707c478bd9Sstevel@tonic-gate force_exit = TRUE; 14717c478bd9Sstevel@tonic-gate break; 14727c478bd9Sstevel@tonic-gate default: 14737c478bd9Sstevel@tonic-gate short_usage(CMD_EXIT); 14747c478bd9Sstevel@tonic-gate return; 14757c478bd9Sstevel@tonic-gate } 14767c478bd9Sstevel@tonic-gate } 14777c478bd9Sstevel@tonic-gate if (optind < cmd->cmd_argc) { 14787c478bd9Sstevel@tonic-gate short_usage(CMD_EXIT); 14797c478bd9Sstevel@tonic-gate return; 14807c478bd9Sstevel@tonic-gate } 14817c478bd9Sstevel@tonic-gate 14827c478bd9Sstevel@tonic-gate if (global_scope || force_exit) { 14837c478bd9Sstevel@tonic-gate time_to_exit = TRUE; 14847c478bd9Sstevel@tonic-gate return; 14857c478bd9Sstevel@tonic-gate } 14867c478bd9Sstevel@tonic-gate 14877c478bd9Sstevel@tonic-gate answer = ask_yesno(FALSE, "Resource incomplete; really quit"); 14887c478bd9Sstevel@tonic-gate if (answer == -1) { 14897c478bd9Sstevel@tonic-gate zerr(gettext("Resource incomplete, input " 14907c478bd9Sstevel@tonic-gate "not from terminal and -F not specified:\n%s command " 14917c478bd9Sstevel@tonic-gate "ignored, but exiting anyway."), cmd_to_str(CMD_EXIT)); 14927c478bd9Sstevel@tonic-gate exit(Z_ERR); 14937c478bd9Sstevel@tonic-gate } else if (answer == 1) { 14947c478bd9Sstevel@tonic-gate time_to_exit = TRUE; 14957c478bd9Sstevel@tonic-gate } 14967c478bd9Sstevel@tonic-gate /* (answer == 0) => just return */ 14977c478bd9Sstevel@tonic-gate } 14987c478bd9Sstevel@tonic-gate 14997c478bd9Sstevel@tonic-gate static int 15007c478bd9Sstevel@tonic-gate validate_zonepath_syntax(char *path) 15017c478bd9Sstevel@tonic-gate { 15027c478bd9Sstevel@tonic-gate if (path[0] != '/') { 15037c478bd9Sstevel@tonic-gate zerr(gettext("%s is not an absolute path."), path); 15047c478bd9Sstevel@tonic-gate return (Z_ERR); 15057c478bd9Sstevel@tonic-gate } 15067c478bd9Sstevel@tonic-gate if (strcmp(path, "/") == 0) { 15077c478bd9Sstevel@tonic-gate zerr(gettext("/ is not allowed as a %s."), 15087c478bd9Sstevel@tonic-gate pt_to_str(PT_ZONEPATH)); 15097c478bd9Sstevel@tonic-gate return (Z_ERR); 15107c478bd9Sstevel@tonic-gate } 15117c478bd9Sstevel@tonic-gate return (Z_OK); 15127c478bd9Sstevel@tonic-gate } 15137c478bd9Sstevel@tonic-gate 15147c478bd9Sstevel@tonic-gate static void 15157c478bd9Sstevel@tonic-gate add_resource(cmd_t *cmd) 15167c478bd9Sstevel@tonic-gate { 15177c478bd9Sstevel@tonic-gate int type; 15187c478bd9Sstevel@tonic-gate 15197c478bd9Sstevel@tonic-gate if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 15207c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 15217c478bd9Sstevel@tonic-gate goto bad; 15227c478bd9Sstevel@tonic-gate } 15237c478bd9Sstevel@tonic-gate 15247c478bd9Sstevel@tonic-gate switch (type) { 15257c478bd9Sstevel@tonic-gate case RT_FS: 15267c478bd9Sstevel@tonic-gate bzero(&in_progress_fstab, sizeof (in_progress_fstab)); 15277c478bd9Sstevel@tonic-gate return; 15287c478bd9Sstevel@tonic-gate case RT_IPD: 1529087719fdSdp if (state_atleast(ZONE_STATE_INSTALLED)) { 15307c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s already installed; %s %s not " 15317c478bd9Sstevel@tonic-gate "allowed."), zone, cmd_to_str(CMD_ADD), 15327c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD)); 15337c478bd9Sstevel@tonic-gate goto bad; 15347c478bd9Sstevel@tonic-gate } 15357c478bd9Sstevel@tonic-gate bzero(&in_progress_ipdtab, sizeof (in_progress_ipdtab)); 15367c478bd9Sstevel@tonic-gate return; 15377c478bd9Sstevel@tonic-gate case RT_NET: 15387c478bd9Sstevel@tonic-gate bzero(&in_progress_nwiftab, sizeof (in_progress_nwiftab)); 15397c478bd9Sstevel@tonic-gate return; 15407c478bd9Sstevel@tonic-gate case RT_DEVICE: 15417c478bd9Sstevel@tonic-gate bzero(&in_progress_devtab, sizeof (in_progress_devtab)); 15427c478bd9Sstevel@tonic-gate return; 15437c478bd9Sstevel@tonic-gate case RT_RCTL: 15447c478bd9Sstevel@tonic-gate bzero(&in_progress_rctltab, sizeof (in_progress_rctltab)); 15457c478bd9Sstevel@tonic-gate return; 15467c478bd9Sstevel@tonic-gate case RT_ATTR: 15477c478bd9Sstevel@tonic-gate bzero(&in_progress_attrtab, sizeof (in_progress_attrtab)); 15487c478bd9Sstevel@tonic-gate return; 1549fa9e4066Sahrens case RT_DATASET: 1550fa9e4066Sahrens bzero(&in_progress_dstab, sizeof (in_progress_dstab)); 1551fa9e4066Sahrens return; 15527c478bd9Sstevel@tonic-gate default: 15537c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(type), Z_NO_RESOURCE_TYPE, TRUE); 15547c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 15557c478bd9Sstevel@tonic-gate usage(FALSE, HELP_RESOURCES); 15567c478bd9Sstevel@tonic-gate } 15577c478bd9Sstevel@tonic-gate bad: 15587c478bd9Sstevel@tonic-gate global_scope = TRUE; 15597c478bd9Sstevel@tonic-gate end_op = -1; 15607c478bd9Sstevel@tonic-gate } 15617c478bd9Sstevel@tonic-gate 15627c478bd9Sstevel@tonic-gate static void 15637c478bd9Sstevel@tonic-gate do_complex_rctl_val(complex_property_ptr_t cp) 15647c478bd9Sstevel@tonic-gate { 15657c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *rctlvaltab; 15667c478bd9Sstevel@tonic-gate complex_property_ptr_t cx; 15677c478bd9Sstevel@tonic-gate bool seen_priv = FALSE, seen_limit = FALSE, seen_action = FALSE; 15687c478bd9Sstevel@tonic-gate rctlblk_t *rctlblk; 15697c478bd9Sstevel@tonic-gate int err; 15707c478bd9Sstevel@tonic-gate 15717c478bd9Sstevel@tonic-gate if ((rctlvaltab = alloc_rctlvaltab()) == NULL) { 15727c478bd9Sstevel@tonic-gate zone_perror(zone, Z_NOMEM, TRUE); 15737c478bd9Sstevel@tonic-gate exit(Z_ERR); 15747c478bd9Sstevel@tonic-gate } 15757c478bd9Sstevel@tonic-gate for (cx = cp; cx != NULL; cx = cx->cp_next) { 15767c478bd9Sstevel@tonic-gate switch (cx->cp_type) { 15777c478bd9Sstevel@tonic-gate case PT_PRIV: 15787c478bd9Sstevel@tonic-gate if (seen_priv) { 15797c478bd9Sstevel@tonic-gate zerr(gettext("%s already specified"), 15807c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV)); 15817c478bd9Sstevel@tonic-gate goto bad; 15827c478bd9Sstevel@tonic-gate } 15837c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_priv, 15847c478bd9Sstevel@tonic-gate cx->cp_value, 15857c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_priv)); 15867c478bd9Sstevel@tonic-gate seen_priv = TRUE; 15877c478bd9Sstevel@tonic-gate break; 15887c478bd9Sstevel@tonic-gate case PT_LIMIT: 15897c478bd9Sstevel@tonic-gate if (seen_limit) { 15907c478bd9Sstevel@tonic-gate zerr(gettext("%s already specified"), 15917c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT)); 15927c478bd9Sstevel@tonic-gate goto bad; 15937c478bd9Sstevel@tonic-gate } 15947c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_limit, 15957c478bd9Sstevel@tonic-gate cx->cp_value, 15967c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_limit)); 15977c478bd9Sstevel@tonic-gate seen_limit = TRUE; 15987c478bd9Sstevel@tonic-gate break; 15997c478bd9Sstevel@tonic-gate case PT_ACTION: 16007c478bd9Sstevel@tonic-gate if (seen_action) { 16017c478bd9Sstevel@tonic-gate zerr(gettext("%s already specified"), 16027c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION)); 16037c478bd9Sstevel@tonic-gate goto bad; 16047c478bd9Sstevel@tonic-gate } 16057c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_action, 16067c478bd9Sstevel@tonic-gate cx->cp_value, 16077c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_action)); 16087c478bd9Sstevel@tonic-gate seen_action = TRUE; 16097c478bd9Sstevel@tonic-gate break; 16107c478bd9Sstevel@tonic-gate default: 16117c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(PT_VALUE), 16127c478bd9Sstevel@tonic-gate Z_NO_PROPERTY_TYPE, TRUE); 16137c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 16147c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 16157c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 16167c478bd9Sstevel@tonic-gate return; 16177c478bd9Sstevel@tonic-gate } 16187c478bd9Sstevel@tonic-gate } 16197c478bd9Sstevel@tonic-gate if (!seen_priv) 16207c478bd9Sstevel@tonic-gate zerr(gettext("%s not specified"), pt_to_str(PT_PRIV)); 16217c478bd9Sstevel@tonic-gate if (!seen_limit) 16227c478bd9Sstevel@tonic-gate zerr(gettext("%s not specified"), pt_to_str(PT_LIMIT)); 16237c478bd9Sstevel@tonic-gate if (!seen_action) 16247c478bd9Sstevel@tonic-gate zerr(gettext("%s not specified"), pt_to_str(PT_ACTION)); 16257c478bd9Sstevel@tonic-gate if (!seen_priv || !seen_limit || !seen_action) 16267c478bd9Sstevel@tonic-gate goto bad; 16277c478bd9Sstevel@tonic-gate rctlvaltab->zone_rctlval_next = NULL; 16287c478bd9Sstevel@tonic-gate rctlblk = alloca(rctlblk_size()); 16297c478bd9Sstevel@tonic-gate /* 16307c478bd9Sstevel@tonic-gate * Make sure the rctl value looks roughly correct; we won't know if 16317c478bd9Sstevel@tonic-gate * it's truly OK until we verify the configuration on the target 16327c478bd9Sstevel@tonic-gate * system. 16337c478bd9Sstevel@tonic-gate */ 16347c478bd9Sstevel@tonic-gate if (zonecfg_construct_rctlblk(rctlvaltab, rctlblk) != Z_OK || 16357c478bd9Sstevel@tonic-gate !zonecfg_valid_rctlblk(rctlblk)) { 16367c478bd9Sstevel@tonic-gate zerr(gettext("Invalid %s %s specification"), rt_to_str(RT_RCTL), 16377c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE)); 16387c478bd9Sstevel@tonic-gate goto bad; 16397c478bd9Sstevel@tonic-gate } 16407c478bd9Sstevel@tonic-gate err = zonecfg_add_rctl_value(&in_progress_rctltab, rctlvaltab); 16417c478bd9Sstevel@tonic-gate if (err != Z_OK) 16427c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(PT_VALUE), err, TRUE); 16437c478bd9Sstevel@tonic-gate return; 16447c478bd9Sstevel@tonic-gate 16457c478bd9Sstevel@tonic-gate bad: 16467c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 16477c478bd9Sstevel@tonic-gate } 16487c478bd9Sstevel@tonic-gate 16497c478bd9Sstevel@tonic-gate static void 16507c478bd9Sstevel@tonic-gate add_property(cmd_t *cmd) 16517c478bd9Sstevel@tonic-gate { 16527c478bd9Sstevel@tonic-gate char *prop_id; 16537c478bd9Sstevel@tonic-gate int err, res_type, prop_type; 16547c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 16557c478bd9Sstevel@tonic-gate list_property_ptr_t l; 16567c478bd9Sstevel@tonic-gate 16577c478bd9Sstevel@tonic-gate res_type = resource_scope; 16587c478bd9Sstevel@tonic-gate prop_type = cmd->cmd_prop_name[0]; 16597c478bd9Sstevel@tonic-gate if (res_type == RT_UNKNOWN || prop_type == PT_UNKNOWN) { 16607c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 16617c478bd9Sstevel@tonic-gate return; 16627c478bd9Sstevel@tonic-gate } 16637c478bd9Sstevel@tonic-gate 16647c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs != 1) { 16657c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 16667c478bd9Sstevel@tonic-gate return; 16677c478bd9Sstevel@tonic-gate } 16687c478bd9Sstevel@tonic-gate 16697c478bd9Sstevel@tonic-gate if (initialize(TRUE) != Z_OK) 16707c478bd9Sstevel@tonic-gate return; 16717c478bd9Sstevel@tonic-gate 16727c478bd9Sstevel@tonic-gate switch (res_type) { 16737c478bd9Sstevel@tonic-gate case RT_FS: 16747c478bd9Sstevel@tonic-gate if (prop_type != PT_OPTIONS) { 16757c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 16767c478bd9Sstevel@tonic-gate TRUE); 16777c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 16787c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 16797c478bd9Sstevel@tonic-gate return; 16807c478bd9Sstevel@tonic-gate } 16817c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 16827c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE && 16837c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 16847c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected here."), 16857c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_SIMPLE), 16867c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 16877c478bd9Sstevel@tonic-gate saw_error = TRUE; 16887c478bd9Sstevel@tonic-gate return; 16897c478bd9Sstevel@tonic-gate } 16907c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_SIMPLE) { 16917c478bd9Sstevel@tonic-gate if (pp->pv_simple == NULL) { 16927c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 16937c478bd9Sstevel@tonic-gate return; 16947c478bd9Sstevel@tonic-gate } 16957c478bd9Sstevel@tonic-gate prop_id = pp->pv_simple; 16967c478bd9Sstevel@tonic-gate err = zonecfg_add_fs_option(&in_progress_fstab, 16977c478bd9Sstevel@tonic-gate prop_id); 16987c478bd9Sstevel@tonic-gate if (err != Z_OK) 16997c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), err, TRUE); 17007c478bd9Sstevel@tonic-gate } else { 17017c478bd9Sstevel@tonic-gate list_property_ptr_t list; 17027c478bd9Sstevel@tonic-gate 17037c478bd9Sstevel@tonic-gate for (list = pp->pv_list; list != NULL; 17047c478bd9Sstevel@tonic-gate list = list->lp_next) { 17057c478bd9Sstevel@tonic-gate prop_id = list->lp_simple; 17067c478bd9Sstevel@tonic-gate if (prop_id == NULL) 17077c478bd9Sstevel@tonic-gate break; 17087c478bd9Sstevel@tonic-gate err = zonecfg_add_fs_option( 17097c478bd9Sstevel@tonic-gate &in_progress_fstab, prop_id); 17107c478bd9Sstevel@tonic-gate if (err != Z_OK) 17117c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), err, 17127c478bd9Sstevel@tonic-gate TRUE); 17137c478bd9Sstevel@tonic-gate } 17147c478bd9Sstevel@tonic-gate } 17157c478bd9Sstevel@tonic-gate return; 17167c478bd9Sstevel@tonic-gate case RT_RCTL: 17177c478bd9Sstevel@tonic-gate if (prop_type != PT_VALUE) { 17187c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 17197c478bd9Sstevel@tonic-gate TRUE); 17207c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 17217c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 17227c478bd9Sstevel@tonic-gate return; 17237c478bd9Sstevel@tonic-gate } 17247c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 17257c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_COMPLEX && 17267c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 17277c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected here."), 17287c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_COMPLEX), 17297c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 17307c478bd9Sstevel@tonic-gate saw_error = TRUE; 17317c478bd9Sstevel@tonic-gate return; 17327c478bd9Sstevel@tonic-gate } 17337c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_COMPLEX) { 17347c478bd9Sstevel@tonic-gate do_complex_rctl_val(pp->pv_complex); 17357c478bd9Sstevel@tonic-gate return; 17367c478bd9Sstevel@tonic-gate } 17377c478bd9Sstevel@tonic-gate for (l = pp->pv_list; l != NULL; l = l->lp_next) 17387c478bd9Sstevel@tonic-gate do_complex_rctl_val(l->lp_complex); 17397c478bd9Sstevel@tonic-gate return; 17407c478bd9Sstevel@tonic-gate default: 17417c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, TRUE); 17427c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 17437c478bd9Sstevel@tonic-gate usage(FALSE, HELP_RESOURCES); 17447c478bd9Sstevel@tonic-gate return; 17457c478bd9Sstevel@tonic-gate } 17467c478bd9Sstevel@tonic-gate } 17477c478bd9Sstevel@tonic-gate 17487c478bd9Sstevel@tonic-gate void 17497c478bd9Sstevel@tonic-gate add_func(cmd_t *cmd) 17507c478bd9Sstevel@tonic-gate { 17517c478bd9Sstevel@tonic-gate int arg; 17527c478bd9Sstevel@tonic-gate 17537c478bd9Sstevel@tonic-gate assert(cmd != NULL); 17547c478bd9Sstevel@tonic-gate 17557c478bd9Sstevel@tonic-gate optind = 0; 17567c478bd9Sstevel@tonic-gate if ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 17577c478bd9Sstevel@tonic-gate switch (arg) { 17587c478bd9Sstevel@tonic-gate case '?': 17597c478bd9Sstevel@tonic-gate longer_usage(CMD_ADD); 17607c478bd9Sstevel@tonic-gate return; 17617c478bd9Sstevel@tonic-gate default: 17627c478bd9Sstevel@tonic-gate short_usage(CMD_ADD); 17637c478bd9Sstevel@tonic-gate return; 17647c478bd9Sstevel@tonic-gate } 17657c478bd9Sstevel@tonic-gate } 17667c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 17677c478bd9Sstevel@tonic-gate short_usage(CMD_ADD); 17687c478bd9Sstevel@tonic-gate return; 17697c478bd9Sstevel@tonic-gate } 17707c478bd9Sstevel@tonic-gate 17717c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_ADD)) 17727c478bd9Sstevel@tonic-gate return; 17737c478bd9Sstevel@tonic-gate 17747c478bd9Sstevel@tonic-gate if (initialize(TRUE) != Z_OK) 17757c478bd9Sstevel@tonic-gate return; 17767c478bd9Sstevel@tonic-gate if (global_scope) { 17777c478bd9Sstevel@tonic-gate global_scope = FALSE; 17787c478bd9Sstevel@tonic-gate resource_scope = cmd->cmd_res_type; 17797c478bd9Sstevel@tonic-gate end_op = CMD_ADD; 17807c478bd9Sstevel@tonic-gate add_resource(cmd); 17817c478bd9Sstevel@tonic-gate } else 17827c478bd9Sstevel@tonic-gate add_property(cmd); 17837c478bd9Sstevel@tonic-gate } 17847c478bd9Sstevel@tonic-gate 1785087719fdSdp /* 1786087719fdSdp * This routine has an unusual implementation, because it tries very 1787087719fdSdp * hard to succeed in the face of a variety of failure modes. 1788087719fdSdp * The most common and most vexing occurs when the index file and 1789087719fdSdp * the /etc/zones/<zonename.xml> file are not both present. In 1790087719fdSdp * this case, delete must eradicate as much of the zone state as is left 1791087719fdSdp * so that the user can later create a new zone with the same name. 1792087719fdSdp */ 17937c478bd9Sstevel@tonic-gate void 17947c478bd9Sstevel@tonic-gate delete_func(cmd_t *cmd) 17957c478bd9Sstevel@tonic-gate { 17967c478bd9Sstevel@tonic-gate int err, arg, answer; 17977c478bd9Sstevel@tonic-gate char line[ZONENAME_MAX + 128]; /* enough to ask a question */ 17987c478bd9Sstevel@tonic-gate bool force = FALSE; 17997c478bd9Sstevel@tonic-gate 18007c478bd9Sstevel@tonic-gate optind = 0; 18017c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 18027c478bd9Sstevel@tonic-gate switch (arg) { 18037c478bd9Sstevel@tonic-gate case '?': 18047c478bd9Sstevel@tonic-gate longer_usage(CMD_DELETE); 18057c478bd9Sstevel@tonic-gate return; 18067c478bd9Sstevel@tonic-gate case 'F': 18077c478bd9Sstevel@tonic-gate force = TRUE; 18087c478bd9Sstevel@tonic-gate break; 18097c478bd9Sstevel@tonic-gate default: 18107c478bd9Sstevel@tonic-gate short_usage(CMD_DELETE); 18117c478bd9Sstevel@tonic-gate return; 18127c478bd9Sstevel@tonic-gate } 18137c478bd9Sstevel@tonic-gate } 18147c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 18157c478bd9Sstevel@tonic-gate short_usage(CMD_DELETE); 18167c478bd9Sstevel@tonic-gate return; 18177c478bd9Sstevel@tonic-gate } 18187c478bd9Sstevel@tonic-gate 18197c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_DELETE)) 18207c478bd9Sstevel@tonic-gate return; 18217c478bd9Sstevel@tonic-gate 1822087719fdSdp if (!force) { 1823087719fdSdp /* 1824087719fdSdp * Initialize sets up the global called "handle" and warns the 1825087719fdSdp * user if the zone is not configured. In force mode, we don't 1826087719fdSdp * trust that evaluation, and hence skip it. (We don't need the 1827087719fdSdp * handle to be loaded anyway, since zonecfg_destroy is done by 1828087719fdSdp * zonename). However, we also have to take care to emulate the 1829087719fdSdp * messages spit out by initialize; see below. 1830087719fdSdp */ 18317c478bd9Sstevel@tonic-gate if (initialize(TRUE) != Z_OK) 18327c478bd9Sstevel@tonic-gate return; 18337c478bd9Sstevel@tonic-gate 18347c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 18357c478bd9Sstevel@tonic-gate gettext("Are you sure you want to delete zone %s"), zone); 18367c478bd9Sstevel@tonic-gate if ((answer = ask_yesno(FALSE, line)) == -1) { 1837087719fdSdp zerr(gettext("Input not from terminal and -F not " 1838087719fdSdp "specified:\n%s command ignored, exiting."), 1839087719fdSdp cmd_to_str(CMD_DELETE)); 18407c478bd9Sstevel@tonic-gate exit(Z_ERR); 18417c478bd9Sstevel@tonic-gate } 18427c478bd9Sstevel@tonic-gate if (answer != 1) 18437c478bd9Sstevel@tonic-gate return; 18447c478bd9Sstevel@tonic-gate } 18457c478bd9Sstevel@tonic-gate 1846087719fdSdp if ((err = zonecfg_destroy(zone, force)) != Z_OK) { 1847087719fdSdp if ((err == Z_BAD_ZONE_STATE) && !force) { 1848087719fdSdp zerr(gettext("Zone %s not in %s state; %s not " 1849087719fdSdp "allowed. Use -F to force %s."), 1850087719fdSdp zone, zone_state_str(ZONE_STATE_CONFIGURED), 1851087719fdSdp cmd_to_str(CMD_DELETE), cmd_to_str(CMD_DELETE)); 1852087719fdSdp } else { 18537c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 18547c478bd9Sstevel@tonic-gate } 1855087719fdSdp } 18567c478bd9Sstevel@tonic-gate need_to_commit = FALSE; 1857087719fdSdp 1858087719fdSdp /* 1859087719fdSdp * Emulate initialize's messaging; if there wasn't a valid handle to 1860087719fdSdp * begin with, then user had typed delete (or delete -F) multiple 1861087719fdSdp * times. So we emit a message. 1862087719fdSdp * 1863087719fdSdp * We only do this in the 'force' case because normally, initialize() 1864087719fdSdp * takes care of this for us. 1865087719fdSdp */ 1866087719fdSdp if (force && zonecfg_check_handle(handle) != Z_OK && interactive_mode) 1867087719fdSdp (void) printf(gettext("Use '%s' to begin " 1868087719fdSdp "configuring a new zone.\n"), cmd_to_str(CMD_CREATE)); 18697c478bd9Sstevel@tonic-gate 18707c478bd9Sstevel@tonic-gate /* 18717c478bd9Sstevel@tonic-gate * Time for a new handle: finish the old one off first 18727c478bd9Sstevel@tonic-gate * then get a new one properly to avoid leaks. 18737c478bd9Sstevel@tonic-gate */ 1874087719fdSdp if (got_handle) { 18757c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 18767c478bd9Sstevel@tonic-gate if ((handle = zonecfg_init_handle()) == NULL) { 18777c478bd9Sstevel@tonic-gate zone_perror(execname, Z_NOMEM, TRUE); 18787c478bd9Sstevel@tonic-gate exit(Z_ERR); 18797c478bd9Sstevel@tonic-gate } 18807c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_handle(zone, handle)) != Z_OK) { 18817c478bd9Sstevel@tonic-gate /* If there was no zone before, that's OK */ 18827c478bd9Sstevel@tonic-gate if (err != Z_NO_ZONE) 18837c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 18847c478bd9Sstevel@tonic-gate got_handle = FALSE; 18857c478bd9Sstevel@tonic-gate } 18867c478bd9Sstevel@tonic-gate } 1887087719fdSdp } 18887c478bd9Sstevel@tonic-gate 18897c478bd9Sstevel@tonic-gate static int 18907c478bd9Sstevel@tonic-gate fill_in_fstab(cmd_t *cmd, struct zone_fstab *fstab, bool fill_in_only) 18917c478bd9Sstevel@tonic-gate { 18927c478bd9Sstevel@tonic-gate int err, i; 18937c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 18947c478bd9Sstevel@tonic-gate 18957c478bd9Sstevel@tonic-gate if ((err = initialize(TRUE)) != Z_OK) 18967c478bd9Sstevel@tonic-gate return (err); 18977c478bd9Sstevel@tonic-gate 1898e193d1e6Svp157776 bzero(fstab, sizeof (*fstab)); 18997c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 19007c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 19017c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 19027c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 19037c478bd9Sstevel@tonic-gate saw_error = TRUE; 19047c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 19057c478bd9Sstevel@tonic-gate } 19067c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 19077c478bd9Sstevel@tonic-gate case PT_DIR: 19087c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_dir, pp->pv_simple, 19097c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_dir)); 19107c478bd9Sstevel@tonic-gate break; 19117c478bd9Sstevel@tonic-gate case PT_SPECIAL: 19127c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_special, pp->pv_simple, 19137c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_special)); 19147c478bd9Sstevel@tonic-gate break; 19157c478bd9Sstevel@tonic-gate case PT_RAW: 19167c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_raw, pp->pv_simple, 19177c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_raw)); 19187c478bd9Sstevel@tonic-gate break; 19197c478bd9Sstevel@tonic-gate case PT_TYPE: 19207c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_type, pp->pv_simple, 19217c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_type)); 19227c478bd9Sstevel@tonic-gate break; 19237c478bd9Sstevel@tonic-gate default: 19247c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 19257c478bd9Sstevel@tonic-gate Z_NO_PROPERTY_TYPE, TRUE); 19267c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 19277c478bd9Sstevel@tonic-gate } 19287c478bd9Sstevel@tonic-gate } 19297c478bd9Sstevel@tonic-gate if (fill_in_only) 19307c478bd9Sstevel@tonic-gate return (Z_OK); 19317c478bd9Sstevel@tonic-gate return (zonecfg_lookup_filesystem(handle, fstab)); 19327c478bd9Sstevel@tonic-gate } 19337c478bd9Sstevel@tonic-gate 19347c478bd9Sstevel@tonic-gate static int 19357c478bd9Sstevel@tonic-gate fill_in_ipdtab(cmd_t *cmd, struct zone_fstab *ipdtab, bool fill_in_only) 19367c478bd9Sstevel@tonic-gate { 19377c478bd9Sstevel@tonic-gate int err, i; 19387c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 19397c478bd9Sstevel@tonic-gate 19407c478bd9Sstevel@tonic-gate if ((err = initialize(TRUE)) != Z_OK) 19417c478bd9Sstevel@tonic-gate return (err); 19427c478bd9Sstevel@tonic-gate 1943e193d1e6Svp157776 bzero(ipdtab, sizeof (*ipdtab)); 19447c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 19457c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 19467c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 19477c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 19487c478bd9Sstevel@tonic-gate saw_error = TRUE; 19497c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 19507c478bd9Sstevel@tonic-gate } 19517c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 19527c478bd9Sstevel@tonic-gate case PT_DIR: 19537c478bd9Sstevel@tonic-gate (void) strlcpy(ipdtab->zone_fs_dir, pp->pv_simple, 19547c478bd9Sstevel@tonic-gate sizeof (ipdtab->zone_fs_dir)); 19557c478bd9Sstevel@tonic-gate break; 19567c478bd9Sstevel@tonic-gate default: 19577c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 19587c478bd9Sstevel@tonic-gate Z_NO_PROPERTY_TYPE, TRUE); 19597c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 19607c478bd9Sstevel@tonic-gate } 19617c478bd9Sstevel@tonic-gate } 19627c478bd9Sstevel@tonic-gate if (fill_in_only) 19637c478bd9Sstevel@tonic-gate return (Z_OK); 19647c478bd9Sstevel@tonic-gate return (zonecfg_lookup_ipd(handle, ipdtab)); 19657c478bd9Sstevel@tonic-gate } 19667c478bd9Sstevel@tonic-gate 19677c478bd9Sstevel@tonic-gate static int 19687c478bd9Sstevel@tonic-gate fill_in_nwiftab(cmd_t *cmd, struct zone_nwiftab *nwiftab, bool fill_in_only) 19697c478bd9Sstevel@tonic-gate { 19707c478bd9Sstevel@tonic-gate int err, i; 19717c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 19727c478bd9Sstevel@tonic-gate 19737c478bd9Sstevel@tonic-gate if ((err = initialize(TRUE)) != Z_OK) 19747c478bd9Sstevel@tonic-gate return (err); 19757c478bd9Sstevel@tonic-gate 1976e193d1e6Svp157776 bzero(nwiftab, sizeof (*nwiftab)); 19777c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 19787c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 19797c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 19807c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 19817c478bd9Sstevel@tonic-gate saw_error = TRUE; 19827c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 19837c478bd9Sstevel@tonic-gate } 19847c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 19857c478bd9Sstevel@tonic-gate case PT_ADDRESS: 19867c478bd9Sstevel@tonic-gate (void) strlcpy(nwiftab->zone_nwif_address, 19877c478bd9Sstevel@tonic-gate pp->pv_simple, sizeof (nwiftab->zone_nwif_address)); 19887c478bd9Sstevel@tonic-gate break; 19897c478bd9Sstevel@tonic-gate case PT_PHYSICAL: 19907c478bd9Sstevel@tonic-gate (void) strlcpy(nwiftab->zone_nwif_physical, 19917c478bd9Sstevel@tonic-gate pp->pv_simple, 19927c478bd9Sstevel@tonic-gate sizeof (nwiftab->zone_nwif_physical)); 19937c478bd9Sstevel@tonic-gate break; 19947c478bd9Sstevel@tonic-gate default: 19957c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 19967c478bd9Sstevel@tonic-gate Z_NO_PROPERTY_TYPE, TRUE); 19977c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 19987c478bd9Sstevel@tonic-gate } 19997c478bd9Sstevel@tonic-gate } 20007c478bd9Sstevel@tonic-gate if (fill_in_only) 20017c478bd9Sstevel@tonic-gate return (Z_OK); 20027c478bd9Sstevel@tonic-gate err = zonecfg_lookup_nwif(handle, nwiftab); 20037c478bd9Sstevel@tonic-gate return (err); 20047c478bd9Sstevel@tonic-gate } 20057c478bd9Sstevel@tonic-gate 20067c478bd9Sstevel@tonic-gate static int 20077c478bd9Sstevel@tonic-gate fill_in_devtab(cmd_t *cmd, struct zone_devtab *devtab, bool fill_in_only) 20087c478bd9Sstevel@tonic-gate { 20097c478bd9Sstevel@tonic-gate int err, i; 20107c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 20117c478bd9Sstevel@tonic-gate 20127c478bd9Sstevel@tonic-gate if ((err = initialize(TRUE)) != Z_OK) 20137c478bd9Sstevel@tonic-gate return (err); 20147c478bd9Sstevel@tonic-gate 2015e193d1e6Svp157776 bzero(devtab, sizeof (*devtab)); 20167c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 20177c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 20187c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 20197c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 20207c478bd9Sstevel@tonic-gate saw_error = TRUE; 20217c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 20227c478bd9Sstevel@tonic-gate } 20237c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 20247c478bd9Sstevel@tonic-gate case PT_MATCH: 20257c478bd9Sstevel@tonic-gate (void) strlcpy(devtab->zone_dev_match, pp->pv_simple, 20267c478bd9Sstevel@tonic-gate sizeof (devtab->zone_dev_match)); 20277c478bd9Sstevel@tonic-gate break; 20287c478bd9Sstevel@tonic-gate default: 20297c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 20307c478bd9Sstevel@tonic-gate Z_NO_PROPERTY_TYPE, TRUE); 20317c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 20327c478bd9Sstevel@tonic-gate } 20337c478bd9Sstevel@tonic-gate } 20347c478bd9Sstevel@tonic-gate if (fill_in_only) 20357c478bd9Sstevel@tonic-gate return (Z_OK); 20367c478bd9Sstevel@tonic-gate err = zonecfg_lookup_dev(handle, devtab); 20377c478bd9Sstevel@tonic-gate return (err); 20387c478bd9Sstevel@tonic-gate } 20397c478bd9Sstevel@tonic-gate 20407c478bd9Sstevel@tonic-gate static int 20417c478bd9Sstevel@tonic-gate fill_in_rctltab(cmd_t *cmd, struct zone_rctltab *rctltab, bool fill_in_only) 20427c478bd9Sstevel@tonic-gate { 20437c478bd9Sstevel@tonic-gate int err, i; 20447c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 20457c478bd9Sstevel@tonic-gate 20467c478bd9Sstevel@tonic-gate if ((err = initialize(TRUE)) != Z_OK) 20477c478bd9Sstevel@tonic-gate return (err); 20487c478bd9Sstevel@tonic-gate 2049e193d1e6Svp157776 bzero(rctltab, sizeof (*rctltab)); 20507c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 20517c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 20527c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 20537c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 20547c478bd9Sstevel@tonic-gate saw_error = TRUE; 20557c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 20567c478bd9Sstevel@tonic-gate } 20577c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 20587c478bd9Sstevel@tonic-gate case PT_NAME: 20597c478bd9Sstevel@tonic-gate (void) strlcpy(rctltab->zone_rctl_name, pp->pv_simple, 20607c478bd9Sstevel@tonic-gate sizeof (rctltab->zone_rctl_name)); 20617c478bd9Sstevel@tonic-gate break; 20627c478bd9Sstevel@tonic-gate default: 20637c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 20647c478bd9Sstevel@tonic-gate Z_NO_PROPERTY_TYPE, TRUE); 20657c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 20667c478bd9Sstevel@tonic-gate } 20677c478bd9Sstevel@tonic-gate } 20687c478bd9Sstevel@tonic-gate if (fill_in_only) 20697c478bd9Sstevel@tonic-gate return (Z_OK); 20707c478bd9Sstevel@tonic-gate err = zonecfg_lookup_rctl(handle, rctltab); 20717c478bd9Sstevel@tonic-gate return (err); 20727c478bd9Sstevel@tonic-gate } 20737c478bd9Sstevel@tonic-gate 20747c478bd9Sstevel@tonic-gate static int 20757c478bd9Sstevel@tonic-gate fill_in_attrtab(cmd_t *cmd, struct zone_attrtab *attrtab, bool fill_in_only) 20767c478bd9Sstevel@tonic-gate { 20777c478bd9Sstevel@tonic-gate int err, i; 20787c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 20797c478bd9Sstevel@tonic-gate 20807c478bd9Sstevel@tonic-gate if ((err = initialize(TRUE)) != Z_OK) 20817c478bd9Sstevel@tonic-gate return (err); 20827c478bd9Sstevel@tonic-gate 2083e193d1e6Svp157776 bzero(attrtab, sizeof (*attrtab)); 20847c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 20857c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 20867c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 20877c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 20887c478bd9Sstevel@tonic-gate saw_error = TRUE; 20897c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 20907c478bd9Sstevel@tonic-gate } 20917c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 20927c478bd9Sstevel@tonic-gate case PT_NAME: 20937c478bd9Sstevel@tonic-gate (void) strlcpy(attrtab->zone_attr_name, pp->pv_simple, 20947c478bd9Sstevel@tonic-gate sizeof (attrtab->zone_attr_name)); 20957c478bd9Sstevel@tonic-gate break; 20967c478bd9Sstevel@tonic-gate case PT_TYPE: 20977c478bd9Sstevel@tonic-gate (void) strlcpy(attrtab->zone_attr_type, pp->pv_simple, 20987c478bd9Sstevel@tonic-gate sizeof (attrtab->zone_attr_type)); 20997c478bd9Sstevel@tonic-gate break; 21007c478bd9Sstevel@tonic-gate case PT_VALUE: 21017c478bd9Sstevel@tonic-gate (void) strlcpy(attrtab->zone_attr_value, pp->pv_simple, 21027c478bd9Sstevel@tonic-gate sizeof (attrtab->zone_attr_value)); 21037c478bd9Sstevel@tonic-gate break; 21047c478bd9Sstevel@tonic-gate default: 21057c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 21067c478bd9Sstevel@tonic-gate Z_NO_PROPERTY_TYPE, TRUE); 21077c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 21087c478bd9Sstevel@tonic-gate } 21097c478bd9Sstevel@tonic-gate } 21107c478bd9Sstevel@tonic-gate if (fill_in_only) 21117c478bd9Sstevel@tonic-gate return (Z_OK); 21127c478bd9Sstevel@tonic-gate err = zonecfg_lookup_attr(handle, attrtab); 21137c478bd9Sstevel@tonic-gate return (err); 21147c478bd9Sstevel@tonic-gate } 21157c478bd9Sstevel@tonic-gate 2116fa9e4066Sahrens static int 2117fa9e4066Sahrens fill_in_dstab(cmd_t *cmd, struct zone_dstab *dstab, bool fill_in_only) 2118fa9e4066Sahrens { 2119fa9e4066Sahrens int err, i; 2120fa9e4066Sahrens property_value_ptr_t pp; 2121fa9e4066Sahrens 2122fa9e4066Sahrens if ((err = initialize(TRUE)) != Z_OK) 2123fa9e4066Sahrens return (err); 2124fa9e4066Sahrens 2125fa9e4066Sahrens dstab->zone_dataset_name[0] = '\0'; 2126fa9e4066Sahrens for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 2127fa9e4066Sahrens pp = cmd->cmd_property_ptr[i]; 2128fa9e4066Sahrens if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 2129fa9e4066Sahrens zerr(gettext("A simple value was expected here.")); 2130fa9e4066Sahrens saw_error = TRUE; 2131fa9e4066Sahrens return (Z_INSUFFICIENT_SPEC); 2132fa9e4066Sahrens } 2133fa9e4066Sahrens switch (cmd->cmd_prop_name[i]) { 2134fa9e4066Sahrens case PT_NAME: 2135fa9e4066Sahrens (void) strlcpy(dstab->zone_dataset_name, pp->pv_simple, 2136fa9e4066Sahrens sizeof (dstab->zone_dataset_name)); 2137fa9e4066Sahrens break; 2138fa9e4066Sahrens default: 2139fa9e4066Sahrens zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2140fa9e4066Sahrens Z_NO_PROPERTY_TYPE, TRUE); 2141fa9e4066Sahrens return (Z_INSUFFICIENT_SPEC); 2142fa9e4066Sahrens } 2143fa9e4066Sahrens } 2144fa9e4066Sahrens if (fill_in_only) 2145fa9e4066Sahrens return (Z_OK); 2146fa9e4066Sahrens return (zonecfg_lookup_ds(handle, dstab)); 2147fa9e4066Sahrens } 2148fa9e4066Sahrens 21497c478bd9Sstevel@tonic-gate static void 21507c478bd9Sstevel@tonic-gate remove_resource(cmd_t *cmd) 21517c478bd9Sstevel@tonic-gate { 21527c478bd9Sstevel@tonic-gate int err, type; 21537c478bd9Sstevel@tonic-gate struct zone_fstab fstab; 21547c478bd9Sstevel@tonic-gate struct zone_nwiftab nwiftab; 21557c478bd9Sstevel@tonic-gate struct zone_devtab devtab; 21567c478bd9Sstevel@tonic-gate struct zone_attrtab attrtab; 21577c478bd9Sstevel@tonic-gate struct zone_rctltab rctltab; 2158fa9e4066Sahrens struct zone_dstab dstab; 21597c478bd9Sstevel@tonic-gate 21607c478bd9Sstevel@tonic-gate if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 21617c478bd9Sstevel@tonic-gate long_usage(CMD_REMOVE, TRUE); 21627c478bd9Sstevel@tonic-gate return; 21637c478bd9Sstevel@tonic-gate } 21647c478bd9Sstevel@tonic-gate 21657c478bd9Sstevel@tonic-gate if (initialize(TRUE) != Z_OK) 21667c478bd9Sstevel@tonic-gate return; 21677c478bd9Sstevel@tonic-gate 21687c478bd9Sstevel@tonic-gate switch (type) { 21697c478bd9Sstevel@tonic-gate case RT_FS: 21707c478bd9Sstevel@tonic-gate if ((err = fill_in_fstab(cmd, &fstab, FALSE)) != Z_OK) { 21717c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_FS, err, TRUE); 21727c478bd9Sstevel@tonic-gate return; 21737c478bd9Sstevel@tonic-gate } 21747c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_filesystem(handle, &fstab)) != Z_OK) 21757c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_FS, err, TRUE); 21767c478bd9Sstevel@tonic-gate else 21777c478bd9Sstevel@tonic-gate need_to_commit = TRUE; 21787c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(fstab.zone_fs_options); 21797c478bd9Sstevel@tonic-gate return; 21807c478bd9Sstevel@tonic-gate case RT_IPD: 2181087719fdSdp if (state_atleast(ZONE_STATE_INSTALLED)) { 21827c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s already installed; %s %s not " 21837c478bd9Sstevel@tonic-gate "allowed."), zone, cmd_to_str(CMD_REMOVE), 21847c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD)); 21857c478bd9Sstevel@tonic-gate return; 21867c478bd9Sstevel@tonic-gate } 21877c478bd9Sstevel@tonic-gate if ((err = fill_in_ipdtab(cmd, &fstab, FALSE)) != Z_OK) { 21887c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_IPD, err, TRUE); 21897c478bd9Sstevel@tonic-gate return; 21907c478bd9Sstevel@tonic-gate } 21917c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_ipd(handle, &fstab)) != Z_OK) 21927c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_IPD, err, TRUE); 21937c478bd9Sstevel@tonic-gate else 21947c478bd9Sstevel@tonic-gate need_to_commit = TRUE; 21957c478bd9Sstevel@tonic-gate return; 21967c478bd9Sstevel@tonic-gate case RT_NET: 21977c478bd9Sstevel@tonic-gate if ((err = fill_in_nwiftab(cmd, &nwiftab, FALSE)) != Z_OK) { 21987c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_NET, err, TRUE); 21997c478bd9Sstevel@tonic-gate return; 22007c478bd9Sstevel@tonic-gate } 22017c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_nwif(handle, &nwiftab)) != Z_OK) 22027c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_NET, err, TRUE); 22037c478bd9Sstevel@tonic-gate else 22047c478bd9Sstevel@tonic-gate need_to_commit = TRUE; 22057c478bd9Sstevel@tonic-gate return; 22067c478bd9Sstevel@tonic-gate case RT_DEVICE: 22077c478bd9Sstevel@tonic-gate if ((err = fill_in_devtab(cmd, &devtab, FALSE)) != Z_OK) { 22087c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_DEVICE, err, TRUE); 22097c478bd9Sstevel@tonic-gate return; 22107c478bd9Sstevel@tonic-gate } 22117c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_dev(handle, &devtab)) != Z_OK) 22127c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_DEVICE, err, TRUE); 22137c478bd9Sstevel@tonic-gate else 22147c478bd9Sstevel@tonic-gate need_to_commit = TRUE; 22157c478bd9Sstevel@tonic-gate return; 22167c478bd9Sstevel@tonic-gate case RT_RCTL: 22177c478bd9Sstevel@tonic-gate if ((err = fill_in_rctltab(cmd, &rctltab, FALSE)) != Z_OK) { 22187c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_RCTL, err, TRUE); 22197c478bd9Sstevel@tonic-gate return; 22207c478bd9Sstevel@tonic-gate } 22217c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_rctl(handle, &rctltab)) != Z_OK) 22227c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_RCTL, err, TRUE); 22237c478bd9Sstevel@tonic-gate else 22247c478bd9Sstevel@tonic-gate need_to_commit = TRUE; 22257c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr); 22267c478bd9Sstevel@tonic-gate return; 22277c478bd9Sstevel@tonic-gate case RT_ATTR: 22287c478bd9Sstevel@tonic-gate if ((err = fill_in_attrtab(cmd, &attrtab, FALSE)) != Z_OK) { 22297c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_ATTR, err, TRUE); 22307c478bd9Sstevel@tonic-gate return; 22317c478bd9Sstevel@tonic-gate } 22327c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_attr(handle, &attrtab)) != Z_OK) 22337c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_REMOVE, RT_ATTR, err, TRUE); 22347c478bd9Sstevel@tonic-gate else 22357c478bd9Sstevel@tonic-gate need_to_commit = TRUE; 22367c478bd9Sstevel@tonic-gate return; 2237fa9e4066Sahrens case RT_DATASET: 2238fa9e4066Sahrens if ((err = fill_in_dstab(cmd, &dstab, FALSE)) != Z_OK) { 2239fa9e4066Sahrens z_cmd_rt_perror(CMD_REMOVE, RT_DATASET, err, TRUE); 2240fa9e4066Sahrens return; 2241fa9e4066Sahrens } 2242fa9e4066Sahrens if ((err = zonecfg_delete_ds(handle, &dstab)) != Z_OK) 2243fa9e4066Sahrens z_cmd_rt_perror(CMD_REMOVE, RT_DATASET, err, TRUE); 2244fa9e4066Sahrens else 2245fa9e4066Sahrens need_to_commit = TRUE; 2246fa9e4066Sahrens return; 22477c478bd9Sstevel@tonic-gate default: 22487c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(type), Z_NO_RESOURCE_TYPE, TRUE); 22497c478bd9Sstevel@tonic-gate long_usage(CMD_REMOVE, TRUE); 22507c478bd9Sstevel@tonic-gate usage(FALSE, HELP_RESOURCES); 22517c478bd9Sstevel@tonic-gate return; 22527c478bd9Sstevel@tonic-gate } 22537c478bd9Sstevel@tonic-gate } 22547c478bd9Sstevel@tonic-gate 22557c478bd9Sstevel@tonic-gate static void 22567c478bd9Sstevel@tonic-gate remove_property(cmd_t *cmd) 22577c478bd9Sstevel@tonic-gate { 22587c478bd9Sstevel@tonic-gate char *prop_id; 22597c478bd9Sstevel@tonic-gate int err, res_type, prop_type; 22607c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 22617c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *rctlvaltab; 22627c478bd9Sstevel@tonic-gate complex_property_ptr_t cx; 22637c478bd9Sstevel@tonic-gate 22647c478bd9Sstevel@tonic-gate res_type = resource_scope; 22657c478bd9Sstevel@tonic-gate prop_type = cmd->cmd_prop_name[0]; 22667c478bd9Sstevel@tonic-gate if (res_type == RT_UNKNOWN || prop_type == PT_UNKNOWN) { 22677c478bd9Sstevel@tonic-gate long_usage(CMD_REMOVE, TRUE); 22687c478bd9Sstevel@tonic-gate return; 22697c478bd9Sstevel@tonic-gate } 22707c478bd9Sstevel@tonic-gate 22717c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs != 1) { 22727c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 22737c478bd9Sstevel@tonic-gate return; 22747c478bd9Sstevel@tonic-gate } 22757c478bd9Sstevel@tonic-gate 22767c478bd9Sstevel@tonic-gate if (initialize(TRUE) != Z_OK) 22777c478bd9Sstevel@tonic-gate return; 22787c478bd9Sstevel@tonic-gate 22797c478bd9Sstevel@tonic-gate switch (res_type) { 22807c478bd9Sstevel@tonic-gate case RT_FS: 22817c478bd9Sstevel@tonic-gate if (prop_type != PT_OPTIONS) { 22827c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 22837c478bd9Sstevel@tonic-gate TRUE); 22847c478bd9Sstevel@tonic-gate long_usage(CMD_REMOVE, TRUE); 22857c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 22867c478bd9Sstevel@tonic-gate return; 22877c478bd9Sstevel@tonic-gate } 22887c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 22897c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_COMPLEX) { 22907c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected here."), 22917c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_SIMPLE), 22927c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 22937c478bd9Sstevel@tonic-gate saw_error = TRUE; 22947c478bd9Sstevel@tonic-gate return; 22957c478bd9Sstevel@tonic-gate } 22967c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_SIMPLE) { 22977c478bd9Sstevel@tonic-gate if (pp->pv_simple == NULL) { 22987c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 22997c478bd9Sstevel@tonic-gate return; 23007c478bd9Sstevel@tonic-gate } 23017c478bd9Sstevel@tonic-gate prop_id = pp->pv_simple; 23027c478bd9Sstevel@tonic-gate err = zonecfg_remove_fs_option(&in_progress_fstab, 23037c478bd9Sstevel@tonic-gate prop_id); 23047c478bd9Sstevel@tonic-gate if (err != Z_OK) 23057c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), err, TRUE); 23067c478bd9Sstevel@tonic-gate } else { 23077c478bd9Sstevel@tonic-gate list_property_ptr_t list; 23087c478bd9Sstevel@tonic-gate 23097c478bd9Sstevel@tonic-gate for (list = pp->pv_list; list != NULL; 23107c478bd9Sstevel@tonic-gate list = list->lp_next) { 23117c478bd9Sstevel@tonic-gate prop_id = list->lp_simple; 23127c478bd9Sstevel@tonic-gate if (prop_id == NULL) 23137c478bd9Sstevel@tonic-gate break; 23147c478bd9Sstevel@tonic-gate err = zonecfg_remove_fs_option( 23157c478bd9Sstevel@tonic-gate &in_progress_fstab, prop_id); 23167c478bd9Sstevel@tonic-gate if (err != Z_OK) 23177c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), err, 23187c478bd9Sstevel@tonic-gate TRUE); 23197c478bd9Sstevel@tonic-gate } 23207c478bd9Sstevel@tonic-gate } 23217c478bd9Sstevel@tonic-gate return; 23227c478bd9Sstevel@tonic-gate case RT_RCTL: 23237c478bd9Sstevel@tonic-gate if (prop_type != PT_VALUE) { 23247c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 23257c478bd9Sstevel@tonic-gate TRUE); 23267c478bd9Sstevel@tonic-gate long_usage(CMD_REMOVE, TRUE); 23277c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 23287c478bd9Sstevel@tonic-gate return; 23297c478bd9Sstevel@tonic-gate } 23307c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 23317c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_COMPLEX) { 23327c478bd9Sstevel@tonic-gate zerr(gettext("A %s value was expected here."), 23337c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_COMPLEX)); 23347c478bd9Sstevel@tonic-gate saw_error = TRUE; 23357c478bd9Sstevel@tonic-gate return; 23367c478bd9Sstevel@tonic-gate } 23377c478bd9Sstevel@tonic-gate if ((rctlvaltab = alloc_rctlvaltab()) == NULL) { 23387c478bd9Sstevel@tonic-gate zone_perror(zone, Z_NOMEM, TRUE); 23397c478bd9Sstevel@tonic-gate exit(Z_ERR); 23407c478bd9Sstevel@tonic-gate } 23417c478bd9Sstevel@tonic-gate for (cx = pp->pv_complex; cx != NULL; cx = cx->cp_next) { 23427c478bd9Sstevel@tonic-gate switch (cx->cp_type) { 23437c478bd9Sstevel@tonic-gate case PT_PRIV: 23447c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_priv, 23457c478bd9Sstevel@tonic-gate cx->cp_value, 23467c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_priv)); 23477c478bd9Sstevel@tonic-gate break; 23487c478bd9Sstevel@tonic-gate case PT_LIMIT: 23497c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_limit, 23507c478bd9Sstevel@tonic-gate cx->cp_value, 23517c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_limit)); 23527c478bd9Sstevel@tonic-gate break; 23537c478bd9Sstevel@tonic-gate case PT_ACTION: 23547c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_action, 23557c478bd9Sstevel@tonic-gate cx->cp_value, 23567c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_action)); 23577c478bd9Sstevel@tonic-gate break; 23587c478bd9Sstevel@tonic-gate default: 23597c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), 23607c478bd9Sstevel@tonic-gate Z_NO_PROPERTY_TYPE, TRUE); 23617c478bd9Sstevel@tonic-gate long_usage(CMD_ADD, TRUE); 23627c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 23637c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 23647c478bd9Sstevel@tonic-gate return; 23657c478bd9Sstevel@tonic-gate } 23667c478bd9Sstevel@tonic-gate } 23677c478bd9Sstevel@tonic-gate rctlvaltab->zone_rctlval_next = NULL; 23687c478bd9Sstevel@tonic-gate err = zonecfg_remove_rctl_value(&in_progress_rctltab, 23697c478bd9Sstevel@tonic-gate rctlvaltab); 23707c478bd9Sstevel@tonic-gate if (err != Z_OK) 23717c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), err, TRUE); 23727c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 23737c478bd9Sstevel@tonic-gate return; 23747c478bd9Sstevel@tonic-gate default: 23757c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, TRUE); 23767c478bd9Sstevel@tonic-gate long_usage(CMD_REMOVE, TRUE); 23777c478bd9Sstevel@tonic-gate usage(FALSE, HELP_RESOURCES); 23787c478bd9Sstevel@tonic-gate return; 23797c478bd9Sstevel@tonic-gate } 23807c478bd9Sstevel@tonic-gate } 23817c478bd9Sstevel@tonic-gate 23827c478bd9Sstevel@tonic-gate void 23837c478bd9Sstevel@tonic-gate remove_func(cmd_t *cmd) 23847c478bd9Sstevel@tonic-gate { 23857c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_REMOVE)) 23867c478bd9Sstevel@tonic-gate return; 23877c478bd9Sstevel@tonic-gate 23887c478bd9Sstevel@tonic-gate assert(cmd != NULL); 23897c478bd9Sstevel@tonic-gate 23907c478bd9Sstevel@tonic-gate if (global_scope) 23917c478bd9Sstevel@tonic-gate remove_resource(cmd); 23927c478bd9Sstevel@tonic-gate else 23937c478bd9Sstevel@tonic-gate remove_property(cmd); 23947c478bd9Sstevel@tonic-gate } 23957c478bd9Sstevel@tonic-gate 23967c478bd9Sstevel@tonic-gate void 23977c478bd9Sstevel@tonic-gate select_func(cmd_t *cmd) 23987c478bd9Sstevel@tonic-gate { 23997c478bd9Sstevel@tonic-gate int type, err; 24007c478bd9Sstevel@tonic-gate 24017c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_SELECT)) 24027c478bd9Sstevel@tonic-gate return; 24037c478bd9Sstevel@tonic-gate 24047c478bd9Sstevel@tonic-gate assert(cmd != NULL); 24057c478bd9Sstevel@tonic-gate 24067c478bd9Sstevel@tonic-gate if (global_scope) { 24077c478bd9Sstevel@tonic-gate global_scope = FALSE; 24087c478bd9Sstevel@tonic-gate resource_scope = cmd->cmd_res_type; 24097c478bd9Sstevel@tonic-gate end_op = CMD_SELECT; 24107c478bd9Sstevel@tonic-gate } else { 24117c478bd9Sstevel@tonic-gate scope_usage(CMD_SELECT); 24127c478bd9Sstevel@tonic-gate return; 24137c478bd9Sstevel@tonic-gate } 24147c478bd9Sstevel@tonic-gate 24157c478bd9Sstevel@tonic-gate if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 24167c478bd9Sstevel@tonic-gate long_usage(CMD_SELECT, TRUE); 24177c478bd9Sstevel@tonic-gate return; 24187c478bd9Sstevel@tonic-gate } 24197c478bd9Sstevel@tonic-gate 24207c478bd9Sstevel@tonic-gate if (initialize(TRUE) != Z_OK) 24217c478bd9Sstevel@tonic-gate return; 24227c478bd9Sstevel@tonic-gate 24237c478bd9Sstevel@tonic-gate switch (type) { 24247c478bd9Sstevel@tonic-gate case RT_FS: 24257c478bd9Sstevel@tonic-gate if ((err = fill_in_fstab(cmd, &old_fstab, FALSE)) != Z_OK) { 24267c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_SELECT, RT_FS, err, TRUE); 24277c478bd9Sstevel@tonic-gate global_scope = TRUE; 24287c478bd9Sstevel@tonic-gate } 24297c478bd9Sstevel@tonic-gate bcopy(&old_fstab, &in_progress_fstab, 24307c478bd9Sstevel@tonic-gate sizeof (struct zone_fstab)); 24317c478bd9Sstevel@tonic-gate return; 24327c478bd9Sstevel@tonic-gate case RT_IPD: 2433087719fdSdp if (state_atleast(ZONE_STATE_INCOMPLETE)) { 24347c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s not in %s state; %s %s not " 24357c478bd9Sstevel@tonic-gate "allowed."), zone, 24367c478bd9Sstevel@tonic-gate zone_state_str(ZONE_STATE_CONFIGURED), 24377c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SELECT), rt_to_str(RT_IPD)); 24387c478bd9Sstevel@tonic-gate global_scope = TRUE; 24397c478bd9Sstevel@tonic-gate end_op = -1; 24407c478bd9Sstevel@tonic-gate return; 24417c478bd9Sstevel@tonic-gate } 24427c478bd9Sstevel@tonic-gate if ((err = fill_in_ipdtab(cmd, &old_ipdtab, FALSE)) != Z_OK) { 24437c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_SELECT, RT_IPD, err, TRUE); 24447c478bd9Sstevel@tonic-gate global_scope = TRUE; 24457c478bd9Sstevel@tonic-gate } 24467c478bd9Sstevel@tonic-gate bcopy(&old_ipdtab, &in_progress_ipdtab, 24477c478bd9Sstevel@tonic-gate sizeof (struct zone_fstab)); 24487c478bd9Sstevel@tonic-gate return; 24497c478bd9Sstevel@tonic-gate case RT_NET: 24507c478bd9Sstevel@tonic-gate if ((err = fill_in_nwiftab(cmd, &old_nwiftab, FALSE)) != Z_OK) { 24517c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_SELECT, RT_NET, err, TRUE); 24527c478bd9Sstevel@tonic-gate global_scope = TRUE; 24537c478bd9Sstevel@tonic-gate } 24547c478bd9Sstevel@tonic-gate bcopy(&old_nwiftab, &in_progress_nwiftab, 24557c478bd9Sstevel@tonic-gate sizeof (struct zone_nwiftab)); 24567c478bd9Sstevel@tonic-gate return; 24577c478bd9Sstevel@tonic-gate case RT_DEVICE: 24587c478bd9Sstevel@tonic-gate if ((err = fill_in_devtab(cmd, &old_devtab, FALSE)) != Z_OK) { 24597c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_SELECT, RT_DEVICE, err, TRUE); 24607c478bd9Sstevel@tonic-gate global_scope = TRUE; 24617c478bd9Sstevel@tonic-gate } 24627c478bd9Sstevel@tonic-gate bcopy(&old_devtab, &in_progress_devtab, 24637c478bd9Sstevel@tonic-gate sizeof (struct zone_devtab)); 24647c478bd9Sstevel@tonic-gate return; 24657c478bd9Sstevel@tonic-gate case RT_RCTL: 24667c478bd9Sstevel@tonic-gate if ((err = fill_in_rctltab(cmd, &old_rctltab, FALSE)) != Z_OK) { 24677c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_SELECT, RT_RCTL, err, TRUE); 24687c478bd9Sstevel@tonic-gate global_scope = TRUE; 24697c478bd9Sstevel@tonic-gate } 24707c478bd9Sstevel@tonic-gate bcopy(&old_rctltab, &in_progress_rctltab, 24717c478bd9Sstevel@tonic-gate sizeof (struct zone_rctltab)); 24727c478bd9Sstevel@tonic-gate return; 24737c478bd9Sstevel@tonic-gate case RT_ATTR: 24747c478bd9Sstevel@tonic-gate if ((err = fill_in_attrtab(cmd, &old_attrtab, FALSE)) != Z_OK) { 24757c478bd9Sstevel@tonic-gate z_cmd_rt_perror(CMD_SELECT, RT_ATTR, err, TRUE); 24767c478bd9Sstevel@tonic-gate global_scope = TRUE; 24777c478bd9Sstevel@tonic-gate } 24787c478bd9Sstevel@tonic-gate bcopy(&old_attrtab, &in_progress_attrtab, 24797c478bd9Sstevel@tonic-gate sizeof (struct zone_attrtab)); 24807c478bd9Sstevel@tonic-gate return; 2481fa9e4066Sahrens case RT_DATASET: 2482fa9e4066Sahrens if ((err = fill_in_dstab(cmd, &old_dstab, FALSE)) != Z_OK) { 2483fa9e4066Sahrens z_cmd_rt_perror(CMD_SELECT, RT_DATASET, err, TRUE); 2484fa9e4066Sahrens global_scope = TRUE; 2485fa9e4066Sahrens } 2486fa9e4066Sahrens bcopy(&old_dstab, &in_progress_dstab, 2487fa9e4066Sahrens sizeof (struct zone_dstab)); 2488fa9e4066Sahrens return; 24897c478bd9Sstevel@tonic-gate default: 24907c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(type), Z_NO_RESOURCE_TYPE, TRUE); 24917c478bd9Sstevel@tonic-gate long_usage(CMD_SELECT, TRUE); 24927c478bd9Sstevel@tonic-gate usage(FALSE, HELP_RESOURCES); 24937c478bd9Sstevel@tonic-gate return; 24947c478bd9Sstevel@tonic-gate } 24957c478bd9Sstevel@tonic-gate } 24967c478bd9Sstevel@tonic-gate 24977c478bd9Sstevel@tonic-gate /* 24987c478bd9Sstevel@tonic-gate * Network "addresses" can be one of the following forms: 24997c478bd9Sstevel@tonic-gate * <IPv4 address> 25007c478bd9Sstevel@tonic-gate * <IPv4 address>/<prefix length> 25017c478bd9Sstevel@tonic-gate * <IPv6 address>/<prefix length> 25027c478bd9Sstevel@tonic-gate * <host name> 25037c478bd9Sstevel@tonic-gate * <host name>/<prefix length> 25047c478bd9Sstevel@tonic-gate * In other words, the "/" followed by a prefix length is allowed but not 25057c478bd9Sstevel@tonic-gate * required for IPv4 addresses and host names, and required for IPv6 addresses. 25067c478bd9Sstevel@tonic-gate * If a prefix length is given, it must be in the allowable range: 0 to 32 for 25077c478bd9Sstevel@tonic-gate * IPv4 addresses and host names, 0 to 128 for IPv6 addresses. 25087c478bd9Sstevel@tonic-gate * Host names must start with an alpha-numeric character, and all subsequent 25097c478bd9Sstevel@tonic-gate * characters must be either alpha-numeric or "-". 25107c478bd9Sstevel@tonic-gate */ 25117c478bd9Sstevel@tonic-gate 25127c478bd9Sstevel@tonic-gate static int 25137c478bd9Sstevel@tonic-gate validate_net_address_syntax(char *address) 25147c478bd9Sstevel@tonic-gate { 25157c478bd9Sstevel@tonic-gate char *slashp, part1[MAXHOSTNAMELEN]; 25167c478bd9Sstevel@tonic-gate struct in6_addr in6; 25177c478bd9Sstevel@tonic-gate struct in_addr in4; 25187c478bd9Sstevel@tonic-gate int prefixlen, i; 25197c478bd9Sstevel@tonic-gate 25207c478bd9Sstevel@tonic-gate /* 25217c478bd9Sstevel@tonic-gate * Copy the part before any '/' into part1 or copy the whole 25227c478bd9Sstevel@tonic-gate * thing if there is no '/'. 25237c478bd9Sstevel@tonic-gate */ 25247c478bd9Sstevel@tonic-gate if ((slashp = strchr(address, '/')) != NULL) { 25257c478bd9Sstevel@tonic-gate *slashp = '\0'; 25267c478bd9Sstevel@tonic-gate (void) strlcpy(part1, address, sizeof (part1)); 25277c478bd9Sstevel@tonic-gate *slashp = '/'; 25287c478bd9Sstevel@tonic-gate prefixlen = atoi(++slashp); 25297c478bd9Sstevel@tonic-gate } else { 25307c478bd9Sstevel@tonic-gate (void) strlcpy(part1, address, sizeof (part1)); 25317c478bd9Sstevel@tonic-gate } 25327c478bd9Sstevel@tonic-gate 25337c478bd9Sstevel@tonic-gate if (inet_pton(AF_INET6, part1, &in6) == 1) { 25347c478bd9Sstevel@tonic-gate if (slashp == NULL) { 25357c478bd9Sstevel@tonic-gate zerr(gettext("%s: IPv6 addresses " 25367c478bd9Sstevel@tonic-gate "require /prefix-length suffix."), address); 25377c478bd9Sstevel@tonic-gate return (Z_ERR); 25387c478bd9Sstevel@tonic-gate } 25397c478bd9Sstevel@tonic-gate if (prefixlen < 0 || prefixlen > 128) { 25407c478bd9Sstevel@tonic-gate zerr(gettext("%s: IPv6 address " 25417c478bd9Sstevel@tonic-gate "prefix lengths must be 0 - 128."), address); 25427c478bd9Sstevel@tonic-gate return (Z_ERR); 25437c478bd9Sstevel@tonic-gate } 25447c478bd9Sstevel@tonic-gate return (Z_OK); 25457c478bd9Sstevel@tonic-gate } 25467c478bd9Sstevel@tonic-gate 25477c478bd9Sstevel@tonic-gate /* At this point, any /prefix must be for IPv4. */ 25487c478bd9Sstevel@tonic-gate if (slashp != NULL) { 25497c478bd9Sstevel@tonic-gate if (prefixlen < 0 || prefixlen > 32) { 25507c478bd9Sstevel@tonic-gate zerr(gettext("%s: IPv4 address " 25517c478bd9Sstevel@tonic-gate "prefix lengths must be 0 - 32."), address); 25527c478bd9Sstevel@tonic-gate return (Z_ERR); 25537c478bd9Sstevel@tonic-gate } 25547c478bd9Sstevel@tonic-gate } 25557c478bd9Sstevel@tonic-gate if (inet_pton(AF_INET, part1, &in4) == 1) 25567c478bd9Sstevel@tonic-gate return (Z_OK); 25577c478bd9Sstevel@tonic-gate 25587c478bd9Sstevel@tonic-gate /* address may also be a host name */ 25597c478bd9Sstevel@tonic-gate if (!isalnum(part1[0])) { 25607c478bd9Sstevel@tonic-gate zerr(gettext("%s: bogus host name or network address syntax"), 25617c478bd9Sstevel@tonic-gate part1); 25627c478bd9Sstevel@tonic-gate saw_error = TRUE; 25637c478bd9Sstevel@tonic-gate usage(FALSE, HELP_NETADDR); 25647c478bd9Sstevel@tonic-gate return (Z_ERR); 25657c478bd9Sstevel@tonic-gate } 25667c478bd9Sstevel@tonic-gate for (i = 1; part1[i]; i++) 25677c478bd9Sstevel@tonic-gate if (!isalnum(part1[i]) && part1[i] != '-' && part1[i] != '.') { 25687c478bd9Sstevel@tonic-gate zerr(gettext("%s: bogus host name or " 25697c478bd9Sstevel@tonic-gate "network address syntax"), part1); 25707c478bd9Sstevel@tonic-gate saw_error = TRUE; 25717c478bd9Sstevel@tonic-gate usage(FALSE, HELP_NETADDR); 25727c478bd9Sstevel@tonic-gate return (Z_ERR); 25737c478bd9Sstevel@tonic-gate } 25747c478bd9Sstevel@tonic-gate return (Z_OK); 25757c478bd9Sstevel@tonic-gate } 25767c478bd9Sstevel@tonic-gate 25777c478bd9Sstevel@tonic-gate static int 25787c478bd9Sstevel@tonic-gate validate_net_physical_syntax(char *ifname) 25797c478bd9Sstevel@tonic-gate { 25807c478bd9Sstevel@tonic-gate if (strchr(ifname, ':') == NULL) 25817c478bd9Sstevel@tonic-gate return (Z_OK); 25827c478bd9Sstevel@tonic-gate zerr(gettext("%s: physical interface name required; " 25837c478bd9Sstevel@tonic-gate "logical interface name not allowed"), ifname); 25847c478bd9Sstevel@tonic-gate return (Z_ERR); 25857c478bd9Sstevel@tonic-gate } 25867c478bd9Sstevel@tonic-gate 25877c478bd9Sstevel@tonic-gate static boolean_t 25887c478bd9Sstevel@tonic-gate valid_fs_type(const char *type) 25897c478bd9Sstevel@tonic-gate { 25907c478bd9Sstevel@tonic-gate /* 25917c478bd9Sstevel@tonic-gate * Is this a valid path component? 25927c478bd9Sstevel@tonic-gate */ 25937c478bd9Sstevel@tonic-gate if (strlen(type) + 1 > MAXNAMELEN) 25947c478bd9Sstevel@tonic-gate return (B_FALSE); 25957c478bd9Sstevel@tonic-gate /* 25967c478bd9Sstevel@tonic-gate * Make sure a bad value for "type" doesn't make 25977c478bd9Sstevel@tonic-gate * /usr/lib/fs/<type>/mount turn into something else. 25987c478bd9Sstevel@tonic-gate */ 25997c478bd9Sstevel@tonic-gate if (strchr(type, '/') != NULL || type[0] == '\0' || 26007c478bd9Sstevel@tonic-gate strcmp(type, ".") == 0 || strcmp(type, "..") == 0) 26017c478bd9Sstevel@tonic-gate return (B_FALSE); 26027c478bd9Sstevel@tonic-gate /* 26037c478bd9Sstevel@tonic-gate * More detailed verification happens later by zoneadm(1m). 26047c478bd9Sstevel@tonic-gate */ 26057c478bd9Sstevel@tonic-gate return (B_TRUE); 26067c478bd9Sstevel@tonic-gate } 26077c478bd9Sstevel@tonic-gate 26087c478bd9Sstevel@tonic-gate void 26097c478bd9Sstevel@tonic-gate set_func(cmd_t *cmd) 26107c478bd9Sstevel@tonic-gate { 26117c478bd9Sstevel@tonic-gate char *prop_id; 26127c478bd9Sstevel@tonic-gate int err, res_type, prop_type; 26137c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 26147c478bd9Sstevel@tonic-gate boolean_t autoboot; 26157c478bd9Sstevel@tonic-gate 26167c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_SET)) 26177c478bd9Sstevel@tonic-gate return; 26187c478bd9Sstevel@tonic-gate 26197c478bd9Sstevel@tonic-gate assert(cmd != NULL); 26207c478bd9Sstevel@tonic-gate 26217c478bd9Sstevel@tonic-gate prop_type = cmd->cmd_prop_name[0]; 26227c478bd9Sstevel@tonic-gate if (global_scope) { 2623087719fdSdp if (prop_type == PT_ZONENAME) { 2624087719fdSdp res_type = RT_ZONENAME; 2625087719fdSdp } else if (prop_type == PT_ZONEPATH) { 26267c478bd9Sstevel@tonic-gate res_type = RT_ZONEPATH; 26277c478bd9Sstevel@tonic-gate } else if (prop_type == PT_AUTOBOOT) { 26287c478bd9Sstevel@tonic-gate res_type = RT_AUTOBOOT; 26297c478bd9Sstevel@tonic-gate } else if (prop_type == PT_POOL) { 26307c478bd9Sstevel@tonic-gate res_type = RT_POOL; 26317c478bd9Sstevel@tonic-gate } else { 26327c478bd9Sstevel@tonic-gate zerr(gettext("Cannot set a resource-specific property " 26337c478bd9Sstevel@tonic-gate "from the global scope.")); 26347c478bd9Sstevel@tonic-gate saw_error = TRUE; 26357c478bd9Sstevel@tonic-gate return; 26367c478bd9Sstevel@tonic-gate } 26377c478bd9Sstevel@tonic-gate } else { 26387c478bd9Sstevel@tonic-gate res_type = resource_scope; 26397c478bd9Sstevel@tonic-gate } 26407c478bd9Sstevel@tonic-gate 26417c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 26427c478bd9Sstevel@tonic-gate /* 26437c478bd9Sstevel@tonic-gate * A nasty expression but not that complicated: 26447c478bd9Sstevel@tonic-gate * 1. fs options are simple or list (tested below) 26457c478bd9Sstevel@tonic-gate * 2. rctl value's are complex or list (tested below) 26467c478bd9Sstevel@tonic-gate * Anything else should be simple. 26477c478bd9Sstevel@tonic-gate */ 26487c478bd9Sstevel@tonic-gate if (!(res_type == RT_FS && prop_type == PT_OPTIONS) && 26497c478bd9Sstevel@tonic-gate !(res_type == RT_RCTL && prop_type == PT_VALUE) && 26507c478bd9Sstevel@tonic-gate (pp->pv_type != PROP_VAL_SIMPLE || 26517c478bd9Sstevel@tonic-gate (prop_id = pp->pv_simple) == NULL)) { 26527c478bd9Sstevel@tonic-gate zerr(gettext("A %s value was expected here."), 26537c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_SIMPLE)); 26547c478bd9Sstevel@tonic-gate saw_error = TRUE; 26557c478bd9Sstevel@tonic-gate return; 26567c478bd9Sstevel@tonic-gate } 26577c478bd9Sstevel@tonic-gate if (prop_type == PT_UNKNOWN) { 26587c478bd9Sstevel@tonic-gate long_usage(CMD_SET, TRUE); 26597c478bd9Sstevel@tonic-gate return; 26607c478bd9Sstevel@tonic-gate } 26617c478bd9Sstevel@tonic-gate 2662087719fdSdp /* 2663087719fdSdp * Special case: the user can change the zone name prior to 'create'; 2664087719fdSdp * if the zone already exists, we fall through letting initialize() 2665087719fdSdp * and the rest of the logic run. 2666087719fdSdp */ 2667087719fdSdp if (res_type == RT_ZONENAME && got_handle == FALSE && 2668087719fdSdp !state_atleast(ZONE_STATE_CONFIGURED)) { 2669*fb03efaaSdp if ((err = zonecfg_validate_zonename(prop_id)) != Z_OK) { 2670*fb03efaaSdp zone_perror(prop_id, err, TRUE); 2671*fb03efaaSdp usage(FALSE, HELP_SYNTAX); 2672*fb03efaaSdp return; 2673*fb03efaaSdp } 2674087719fdSdp (void) strlcpy(zone, prop_id, sizeof (zone)); 2675087719fdSdp return; 2676087719fdSdp } 2677087719fdSdp 26787c478bd9Sstevel@tonic-gate if (initialize(TRUE) != Z_OK) 26797c478bd9Sstevel@tonic-gate return; 26807c478bd9Sstevel@tonic-gate 26817c478bd9Sstevel@tonic-gate switch (res_type) { 2682087719fdSdp case RT_ZONENAME: 2683087719fdSdp if ((err = zonecfg_set_name(handle, prop_id)) != Z_OK) { 2684087719fdSdp /* 2685087719fdSdp * Use prop_id instead of 'zone' here, since we're 2686087719fdSdp * reporting a problem about the *new* zonename. 2687087719fdSdp */ 2688087719fdSdp zone_perror(prop_id, err, TRUE); 2689*fb03efaaSdp usage(FALSE, HELP_SYNTAX); 2690087719fdSdp } else { 2691087719fdSdp need_to_commit = TRUE; 2692087719fdSdp (void) strlcpy(zone, prop_id, sizeof (zone)); 2693087719fdSdp } 2694087719fdSdp return; 26957c478bd9Sstevel@tonic-gate case RT_ZONEPATH: 2696087719fdSdp if (state_atleast(ZONE_STATE_INSTALLED)) { 26977c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s already installed; %s %s not " 26987c478bd9Sstevel@tonic-gate "allowed."), zone, cmd_to_str(CMD_SET), 26997c478bd9Sstevel@tonic-gate rt_to_str(RT_ZONEPATH)); 27007c478bd9Sstevel@tonic-gate return; 27017c478bd9Sstevel@tonic-gate } 27027c478bd9Sstevel@tonic-gate if (validate_zonepath_syntax(prop_id) != Z_OK) { 27037c478bd9Sstevel@tonic-gate saw_error = TRUE; 27047c478bd9Sstevel@tonic-gate return; 27057c478bd9Sstevel@tonic-gate } 27067c478bd9Sstevel@tonic-gate if ((err = zonecfg_set_zonepath(handle, prop_id)) != Z_OK) 27077c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 27087c478bd9Sstevel@tonic-gate else 27097c478bd9Sstevel@tonic-gate need_to_commit = TRUE; 27107c478bd9Sstevel@tonic-gate return; 27117c478bd9Sstevel@tonic-gate case RT_AUTOBOOT: 27127c478bd9Sstevel@tonic-gate if (strcmp(prop_id, "true") == 0) { 27137c478bd9Sstevel@tonic-gate autoboot = B_TRUE; 27147c478bd9Sstevel@tonic-gate } else if (strcmp(prop_id, "false") == 0) { 27157c478bd9Sstevel@tonic-gate autoboot = B_FALSE; 27167c478bd9Sstevel@tonic-gate } else { 27177c478bd9Sstevel@tonic-gate zerr(gettext("%s value must be '%s' or '%s'."), 27187c478bd9Sstevel@tonic-gate pt_to_str(PT_AUTOBOOT), "true", "false"); 27197c478bd9Sstevel@tonic-gate saw_error = TRUE; 27207c478bd9Sstevel@tonic-gate return; 27217c478bd9Sstevel@tonic-gate } 27227c478bd9Sstevel@tonic-gate if ((err = zonecfg_set_autoboot(handle, autoboot)) != Z_OK) 27237c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 27247c478bd9Sstevel@tonic-gate else 27257c478bd9Sstevel@tonic-gate need_to_commit = TRUE; 27267c478bd9Sstevel@tonic-gate return; 27277c478bd9Sstevel@tonic-gate case RT_POOL: 27287c478bd9Sstevel@tonic-gate if ((err = zonecfg_set_pool(handle, prop_id)) != Z_OK) 27297c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 27307c478bd9Sstevel@tonic-gate else 27317c478bd9Sstevel@tonic-gate need_to_commit = TRUE; 27327c478bd9Sstevel@tonic-gate return; 27337c478bd9Sstevel@tonic-gate case RT_FS: 27347c478bd9Sstevel@tonic-gate switch (prop_type) { 27357c478bd9Sstevel@tonic-gate case PT_DIR: 27367c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_dir, prop_id, 27377c478bd9Sstevel@tonic-gate sizeof (in_progress_fstab.zone_fs_dir)); 27387c478bd9Sstevel@tonic-gate return; 27397c478bd9Sstevel@tonic-gate case PT_SPECIAL: 27407c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_special, 27417c478bd9Sstevel@tonic-gate prop_id, 27427c478bd9Sstevel@tonic-gate sizeof (in_progress_fstab.zone_fs_special)); 27437c478bd9Sstevel@tonic-gate return; 27447c478bd9Sstevel@tonic-gate case PT_RAW: 27457c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_raw, 27467c478bd9Sstevel@tonic-gate prop_id, sizeof (in_progress_fstab.zone_fs_raw)); 27477c478bd9Sstevel@tonic-gate return; 27487c478bd9Sstevel@tonic-gate case PT_TYPE: 27497c478bd9Sstevel@tonic-gate if (!valid_fs_type(prop_id)) { 27507c478bd9Sstevel@tonic-gate zerr(gettext("\"%s\" is not a valid %s."), 27517c478bd9Sstevel@tonic-gate prop_id, pt_to_str(PT_TYPE)); 27527c478bd9Sstevel@tonic-gate saw_error = TRUE; 27537c478bd9Sstevel@tonic-gate return; 27547c478bd9Sstevel@tonic-gate } 27557c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_type, prop_id, 27567c478bd9Sstevel@tonic-gate sizeof (in_progress_fstab.zone_fs_type)); 27577c478bd9Sstevel@tonic-gate return; 27587c478bd9Sstevel@tonic-gate case PT_OPTIONS: 27597c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE && 27607c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 27617c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected " 27627c478bd9Sstevel@tonic-gate "here."), pvt_to_str(PROP_VAL_SIMPLE), 27637c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 27647c478bd9Sstevel@tonic-gate saw_error = TRUE; 27657c478bd9Sstevel@tonic-gate return; 27667c478bd9Sstevel@tonic-gate } 27677c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list( 27687c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_options); 27697c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_options = NULL; 27707c478bd9Sstevel@tonic-gate if (!(pp->pv_type == PROP_VAL_LIST && 27717c478bd9Sstevel@tonic-gate pp->pv_list == NULL)) 27727c478bd9Sstevel@tonic-gate add_property(cmd); 27737c478bd9Sstevel@tonic-gate return; 27747c478bd9Sstevel@tonic-gate default: 27757c478bd9Sstevel@tonic-gate break; 27767c478bd9Sstevel@tonic-gate } 27777c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, TRUE); 27787c478bd9Sstevel@tonic-gate long_usage(CMD_SET, TRUE); 27797c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 27807c478bd9Sstevel@tonic-gate return; 27817c478bd9Sstevel@tonic-gate case RT_IPD: 27827c478bd9Sstevel@tonic-gate switch (prop_type) { 27837c478bd9Sstevel@tonic-gate case PT_DIR: 27847c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_ipdtab.zone_fs_dir, prop_id, 27857c478bd9Sstevel@tonic-gate sizeof (in_progress_ipdtab.zone_fs_dir)); 27867c478bd9Sstevel@tonic-gate return; 27877c478bd9Sstevel@tonic-gate default: 27887c478bd9Sstevel@tonic-gate break; 27897c478bd9Sstevel@tonic-gate } 27907c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, TRUE); 27917c478bd9Sstevel@tonic-gate long_usage(CMD_SET, TRUE); 27927c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 27937c478bd9Sstevel@tonic-gate return; 27947c478bd9Sstevel@tonic-gate case RT_NET: 27957c478bd9Sstevel@tonic-gate switch (prop_type) { 27967c478bd9Sstevel@tonic-gate case PT_ADDRESS: 27977c478bd9Sstevel@tonic-gate if (validate_net_address_syntax(prop_id) != Z_OK) { 27987c478bd9Sstevel@tonic-gate saw_error = TRUE; 27997c478bd9Sstevel@tonic-gate return; 28007c478bd9Sstevel@tonic-gate } 28017c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_nwiftab.zone_nwif_address, 28027c478bd9Sstevel@tonic-gate prop_id, 28037c478bd9Sstevel@tonic-gate sizeof (in_progress_nwiftab.zone_nwif_address)); 28047c478bd9Sstevel@tonic-gate break; 28057c478bd9Sstevel@tonic-gate case PT_PHYSICAL: 28067c478bd9Sstevel@tonic-gate if (validate_net_physical_syntax(prop_id) != Z_OK) { 28077c478bd9Sstevel@tonic-gate saw_error = TRUE; 28087c478bd9Sstevel@tonic-gate return; 28097c478bd9Sstevel@tonic-gate } 28107c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_nwiftab.zone_nwif_physical, 28117c478bd9Sstevel@tonic-gate prop_id, 28127c478bd9Sstevel@tonic-gate sizeof (in_progress_nwiftab.zone_nwif_physical)); 28137c478bd9Sstevel@tonic-gate break; 28147c478bd9Sstevel@tonic-gate default: 28157c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 28167c478bd9Sstevel@tonic-gate TRUE); 28177c478bd9Sstevel@tonic-gate long_usage(CMD_SET, TRUE); 28187c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 28197c478bd9Sstevel@tonic-gate return; 28207c478bd9Sstevel@tonic-gate } 28217c478bd9Sstevel@tonic-gate return; 28227c478bd9Sstevel@tonic-gate case RT_DEVICE: 28237c478bd9Sstevel@tonic-gate switch (prop_type) { 28247c478bd9Sstevel@tonic-gate case PT_MATCH: 28257c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_devtab.zone_dev_match, 28267c478bd9Sstevel@tonic-gate prop_id, 28277c478bd9Sstevel@tonic-gate sizeof (in_progress_devtab.zone_dev_match)); 28287c478bd9Sstevel@tonic-gate break; 28297c478bd9Sstevel@tonic-gate default: 28307c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 28317c478bd9Sstevel@tonic-gate TRUE); 28327c478bd9Sstevel@tonic-gate long_usage(CMD_SET, TRUE); 28337c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 28347c478bd9Sstevel@tonic-gate return; 28357c478bd9Sstevel@tonic-gate } 28367c478bd9Sstevel@tonic-gate return; 28377c478bd9Sstevel@tonic-gate case RT_RCTL: 28387c478bd9Sstevel@tonic-gate switch (prop_type) { 28397c478bd9Sstevel@tonic-gate case PT_NAME: 28407c478bd9Sstevel@tonic-gate if (!zonecfg_valid_rctlname(prop_id)) { 28417c478bd9Sstevel@tonic-gate zerr(gettext("'%s' is not a valid zone %s " 28427c478bd9Sstevel@tonic-gate "name."), prop_id, rt_to_str(RT_RCTL)); 28437c478bd9Sstevel@tonic-gate return; 28447c478bd9Sstevel@tonic-gate } 28457c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_rctltab.zone_rctl_name, 28467c478bd9Sstevel@tonic-gate prop_id, 28477c478bd9Sstevel@tonic-gate sizeof (in_progress_rctltab.zone_rctl_name)); 28487c478bd9Sstevel@tonic-gate break; 28497c478bd9Sstevel@tonic-gate case PT_VALUE: 28507c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_COMPLEX && 28517c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 28527c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected " 28537c478bd9Sstevel@tonic-gate "here."), pvt_to_str(PROP_VAL_COMPLEX), 28547c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 28557c478bd9Sstevel@tonic-gate saw_error = TRUE; 28567c478bd9Sstevel@tonic-gate return; 28577c478bd9Sstevel@tonic-gate } 28587c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list( 28597c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr); 28607c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr = NULL; 28617c478bd9Sstevel@tonic-gate if (!(pp->pv_type == PROP_VAL_LIST && 28627c478bd9Sstevel@tonic-gate pp->pv_list == NULL)) 28637c478bd9Sstevel@tonic-gate add_property(cmd); 28647c478bd9Sstevel@tonic-gate break; 28657c478bd9Sstevel@tonic-gate default: 28667c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 28677c478bd9Sstevel@tonic-gate TRUE); 28687c478bd9Sstevel@tonic-gate long_usage(CMD_SET, TRUE); 28697c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 28707c478bd9Sstevel@tonic-gate return; 28717c478bd9Sstevel@tonic-gate } 28727c478bd9Sstevel@tonic-gate return; 28737c478bd9Sstevel@tonic-gate case RT_ATTR: 28747c478bd9Sstevel@tonic-gate switch (prop_type) { 28757c478bd9Sstevel@tonic-gate case PT_NAME: 28767c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_attrtab.zone_attr_name, 28777c478bd9Sstevel@tonic-gate prop_id, 28787c478bd9Sstevel@tonic-gate sizeof (in_progress_attrtab.zone_attr_name)); 28797c478bd9Sstevel@tonic-gate break; 28807c478bd9Sstevel@tonic-gate case PT_TYPE: 28817c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_attrtab.zone_attr_type, 28827c478bd9Sstevel@tonic-gate prop_id, 28837c478bd9Sstevel@tonic-gate sizeof (in_progress_attrtab.zone_attr_type)); 28847c478bd9Sstevel@tonic-gate break; 28857c478bd9Sstevel@tonic-gate case PT_VALUE: 28867c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_attrtab.zone_attr_value, 28877c478bd9Sstevel@tonic-gate prop_id, 28887c478bd9Sstevel@tonic-gate sizeof (in_progress_attrtab.zone_attr_value)); 28897c478bd9Sstevel@tonic-gate break; 28907c478bd9Sstevel@tonic-gate default: 28917c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 28927c478bd9Sstevel@tonic-gate TRUE); 28937c478bd9Sstevel@tonic-gate long_usage(CMD_SET, TRUE); 28947c478bd9Sstevel@tonic-gate usage(FALSE, HELP_PROPS); 28957c478bd9Sstevel@tonic-gate return; 28967c478bd9Sstevel@tonic-gate } 28977c478bd9Sstevel@tonic-gate return; 2898fa9e4066Sahrens case RT_DATASET: 2899fa9e4066Sahrens switch (prop_type) { 2900fa9e4066Sahrens case PT_NAME: 2901fa9e4066Sahrens (void) strlcpy(in_progress_dstab.zone_dataset_name, 2902fa9e4066Sahrens prop_id, 2903fa9e4066Sahrens sizeof (in_progress_dstab.zone_dataset_name)); 2904fa9e4066Sahrens return; 2905fa9e4066Sahrens default: 2906fa9e4066Sahrens break; 2907fa9e4066Sahrens } 2908fa9e4066Sahrens zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, TRUE); 2909fa9e4066Sahrens long_usage(CMD_SET, TRUE); 2910fa9e4066Sahrens usage(FALSE, HELP_PROPS); 2911fa9e4066Sahrens return; 29127c478bd9Sstevel@tonic-gate default: 29137c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, TRUE); 29147c478bd9Sstevel@tonic-gate long_usage(CMD_SET, TRUE); 29157c478bd9Sstevel@tonic-gate usage(FALSE, HELP_RESOURCES); 29167c478bd9Sstevel@tonic-gate return; 29177c478bd9Sstevel@tonic-gate } 29187c478bd9Sstevel@tonic-gate } 29197c478bd9Sstevel@tonic-gate 29207c478bd9Sstevel@tonic-gate static void 29217c478bd9Sstevel@tonic-gate output_prop(FILE *fp, int pnum, char *pval, bool print_notspec) 29227c478bd9Sstevel@tonic-gate { 29237c478bd9Sstevel@tonic-gate char *qstr; 29247c478bd9Sstevel@tonic-gate 29257c478bd9Sstevel@tonic-gate if (*pval != '\0') { 29267c478bd9Sstevel@tonic-gate qstr = quoteit(pval); 29277c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s: %s\n", pt_to_str(pnum), qstr); 29287c478bd9Sstevel@tonic-gate free(qstr); 29297c478bd9Sstevel@tonic-gate } else if (print_notspec) 2930087719fdSdp (void) fprintf(fp, gettext("\t%s not specified\n"), 2931087719fdSdp pt_to_str(pnum)); 2932087719fdSdp } 2933087719fdSdp 2934087719fdSdp static void 2935087719fdSdp info_zonename(zone_dochandle_t handle, FILE *fp) 2936087719fdSdp { 2937087719fdSdp char zonename[ZONENAME_MAX]; 2938087719fdSdp 2939087719fdSdp if (zonecfg_get_name(handle, zonename, sizeof (zonename)) == Z_OK) 2940087719fdSdp (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_ZONENAME), 2941087719fdSdp zonename); 2942087719fdSdp else 2943087719fdSdp (void) fprintf(fp, gettext("%s not specified\n"), 2944087719fdSdp pt_to_str(PT_ZONENAME)); 29457c478bd9Sstevel@tonic-gate } 29467c478bd9Sstevel@tonic-gate 29477c478bd9Sstevel@tonic-gate static void 29487c478bd9Sstevel@tonic-gate info_zonepath(zone_dochandle_t handle, FILE *fp) 29497c478bd9Sstevel@tonic-gate { 29507c478bd9Sstevel@tonic-gate char zonepath[MAXPATHLEN]; 29517c478bd9Sstevel@tonic-gate 29527c478bd9Sstevel@tonic-gate if (zonecfg_get_zonepath(handle, zonepath, sizeof (zonepath)) == Z_OK) 29537c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_ZONEPATH), 29547c478bd9Sstevel@tonic-gate zonepath); 2955087719fdSdp else { 2956087719fdSdp (void) fprintf(fp, gettext("%s not specified\n"), 2957087719fdSdp pt_to_str(PT_ZONEPATH)); 2958087719fdSdp } 29597c478bd9Sstevel@tonic-gate } 29607c478bd9Sstevel@tonic-gate 29617c478bd9Sstevel@tonic-gate static void 29627c478bd9Sstevel@tonic-gate info_autoboot(zone_dochandle_t handle, FILE *fp) 29637c478bd9Sstevel@tonic-gate { 29647c478bd9Sstevel@tonic-gate boolean_t autoboot; 29657c478bd9Sstevel@tonic-gate int err; 29667c478bd9Sstevel@tonic-gate 29677c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_autoboot(handle, &autoboot)) == Z_OK) 29687c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_AUTOBOOT), 29697c478bd9Sstevel@tonic-gate autoboot ? "true" : "false"); 29707c478bd9Sstevel@tonic-gate else 29717c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 29727c478bd9Sstevel@tonic-gate } 29737c478bd9Sstevel@tonic-gate 29747c478bd9Sstevel@tonic-gate static void 29757c478bd9Sstevel@tonic-gate info_pool(zone_dochandle_t handle, FILE *fp) 29767c478bd9Sstevel@tonic-gate { 29777c478bd9Sstevel@tonic-gate char pool[MAXNAMELEN]; 29787c478bd9Sstevel@tonic-gate int err; 29797c478bd9Sstevel@tonic-gate 29807c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_pool(handle, pool, sizeof (pool))) == Z_OK) 29817c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_POOL), pool); 29827c478bd9Sstevel@tonic-gate else 29837c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 29847c478bd9Sstevel@tonic-gate } 29857c478bd9Sstevel@tonic-gate 29867c478bd9Sstevel@tonic-gate static void 29877c478bd9Sstevel@tonic-gate output_fs(FILE *fp, struct zone_fstab *fstab) 29887c478bd9Sstevel@tonic-gate { 29897c478bd9Sstevel@tonic-gate zone_fsopt_t *this; 29907c478bd9Sstevel@tonic-gate 29917c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_FS)); 29927c478bd9Sstevel@tonic-gate output_prop(fp, PT_DIR, fstab->zone_fs_dir, B_TRUE); 29937c478bd9Sstevel@tonic-gate output_prop(fp, PT_SPECIAL, fstab->zone_fs_special, B_TRUE); 29947c478bd9Sstevel@tonic-gate output_prop(fp, PT_RAW, fstab->zone_fs_raw, B_TRUE); 29957c478bd9Sstevel@tonic-gate output_prop(fp, PT_TYPE, fstab->zone_fs_type, B_TRUE); 29967c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s: [", pt_to_str(PT_OPTIONS)); 29977c478bd9Sstevel@tonic-gate for (this = fstab->zone_fs_options; this != NULL; 29987c478bd9Sstevel@tonic-gate this = this->zone_fsopt_next) { 29997c478bd9Sstevel@tonic-gate if (strchr(this->zone_fsopt_opt, '=')) 30007c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\"%s\"", this->zone_fsopt_opt); 30017c478bd9Sstevel@tonic-gate else 30027c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s", this->zone_fsopt_opt); 30037c478bd9Sstevel@tonic-gate if (this->zone_fsopt_next != NULL) 30047c478bd9Sstevel@tonic-gate (void) fprintf(fp, ","); 30057c478bd9Sstevel@tonic-gate } 30067c478bd9Sstevel@tonic-gate (void) fprintf(fp, "]\n"); 30077c478bd9Sstevel@tonic-gate } 30087c478bd9Sstevel@tonic-gate 30097c478bd9Sstevel@tonic-gate static void 30107c478bd9Sstevel@tonic-gate output_ipd(FILE *fp, struct zone_fstab *ipdtab) 30117c478bd9Sstevel@tonic-gate { 30127c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_IPD)); 30137c478bd9Sstevel@tonic-gate output_prop(fp, PT_DIR, ipdtab->zone_fs_dir, B_TRUE); 30147c478bd9Sstevel@tonic-gate } 30157c478bd9Sstevel@tonic-gate 30167c478bd9Sstevel@tonic-gate static void 30177c478bd9Sstevel@tonic-gate info_fs(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 30187c478bd9Sstevel@tonic-gate { 30197c478bd9Sstevel@tonic-gate struct zone_fstab lookup, user; 30207c478bd9Sstevel@tonic-gate bool output = FALSE; 30217c478bd9Sstevel@tonic-gate 30227c478bd9Sstevel@tonic-gate if (zonecfg_setfsent(handle) != Z_OK) 30237c478bd9Sstevel@tonic-gate return; 30247c478bd9Sstevel@tonic-gate while (zonecfg_getfsent(handle, &lookup) == Z_OK) { 30257c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 30267c478bd9Sstevel@tonic-gate output_fs(fp, &lookup); 30277c478bd9Sstevel@tonic-gate goto loopend; 30287c478bd9Sstevel@tonic-gate } 30297c478bd9Sstevel@tonic-gate if (fill_in_fstab(cmd, &user, TRUE) != Z_OK) 30307c478bd9Sstevel@tonic-gate goto loopend; 30317c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_dir) > 0 && 30327c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_dir, lookup.zone_fs_dir) != 0) 30337c478bd9Sstevel@tonic-gate goto loopend; /* no match */ 30347c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_special) > 0 && 30357c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_special, lookup.zone_fs_special) != 0) 30367c478bd9Sstevel@tonic-gate goto loopend; /* no match */ 30377c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_type) > 0 && 30387c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_type, lookup.zone_fs_type) != 0) 30397c478bd9Sstevel@tonic-gate goto loopend; /* no match */ 30407c478bd9Sstevel@tonic-gate output_fs(fp, &lookup); 30417c478bd9Sstevel@tonic-gate output = TRUE; 30427c478bd9Sstevel@tonic-gate loopend: 30437c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(lookup.zone_fs_options); 30447c478bd9Sstevel@tonic-gate } 30457c478bd9Sstevel@tonic-gate (void) zonecfg_endfsent(handle); 30467c478bd9Sstevel@tonic-gate /* 30477c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 30487c478bd9Sstevel@tonic-gate * nothing to output. 30497c478bd9Sstevel@tonic-gate */ 30507c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 30517c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 30527c478bd9Sstevel@tonic-gate rt_to_str(RT_FS)); 30537c478bd9Sstevel@tonic-gate } 30547c478bd9Sstevel@tonic-gate 30557c478bd9Sstevel@tonic-gate static void 30567c478bd9Sstevel@tonic-gate info_ipd(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 30577c478bd9Sstevel@tonic-gate { 30587c478bd9Sstevel@tonic-gate struct zone_fstab lookup, user; 30597c478bd9Sstevel@tonic-gate bool output = FALSE; 30607c478bd9Sstevel@tonic-gate 30617c478bd9Sstevel@tonic-gate if (zonecfg_setipdent(handle) != Z_OK) 30627c478bd9Sstevel@tonic-gate return; 30637c478bd9Sstevel@tonic-gate while (zonecfg_getipdent(handle, &lookup) == Z_OK) { 30647c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 30657c478bd9Sstevel@tonic-gate output_ipd(fp, &lookup); 30667c478bd9Sstevel@tonic-gate continue; 30677c478bd9Sstevel@tonic-gate } 30687c478bd9Sstevel@tonic-gate if (fill_in_ipdtab(cmd, &user, TRUE) != Z_OK) 30697c478bd9Sstevel@tonic-gate continue; 30707c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_dir) > 0 && 30717c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_dir, lookup.zone_fs_dir) != 0) 30727c478bd9Sstevel@tonic-gate continue; /* no match */ 30737c478bd9Sstevel@tonic-gate output_ipd(fp, &lookup); 30747c478bd9Sstevel@tonic-gate output = TRUE; 30757c478bd9Sstevel@tonic-gate } 30767c478bd9Sstevel@tonic-gate (void) zonecfg_endipdent(handle); 30777c478bd9Sstevel@tonic-gate /* 30787c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 30797c478bd9Sstevel@tonic-gate * nothing to output. 30807c478bd9Sstevel@tonic-gate */ 30817c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 30827c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 30837c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD)); 30847c478bd9Sstevel@tonic-gate } 30857c478bd9Sstevel@tonic-gate 30867c478bd9Sstevel@tonic-gate static void 30877c478bd9Sstevel@tonic-gate output_net(FILE *fp, struct zone_nwiftab *nwiftab) 30887c478bd9Sstevel@tonic-gate { 30897c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_NET)); 30907c478bd9Sstevel@tonic-gate output_prop(fp, PT_ADDRESS, nwiftab->zone_nwif_address, B_TRUE); 30917c478bd9Sstevel@tonic-gate output_prop(fp, PT_PHYSICAL, nwiftab->zone_nwif_physical, B_TRUE); 30927c478bd9Sstevel@tonic-gate } 30937c478bd9Sstevel@tonic-gate 30947c478bd9Sstevel@tonic-gate static void 30957c478bd9Sstevel@tonic-gate info_net(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 30967c478bd9Sstevel@tonic-gate { 30977c478bd9Sstevel@tonic-gate struct zone_nwiftab lookup, user; 30987c478bd9Sstevel@tonic-gate bool output = FALSE; 30997c478bd9Sstevel@tonic-gate 31007c478bd9Sstevel@tonic-gate if (zonecfg_setnwifent(handle) != Z_OK) 31017c478bd9Sstevel@tonic-gate return; 31027c478bd9Sstevel@tonic-gate while (zonecfg_getnwifent(handle, &lookup) == Z_OK) { 31037c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 31047c478bd9Sstevel@tonic-gate output_net(fp, &lookup); 31057c478bd9Sstevel@tonic-gate continue; 31067c478bd9Sstevel@tonic-gate } 31077c478bd9Sstevel@tonic-gate if (fill_in_nwiftab(cmd, &user, TRUE) != Z_OK) 31087c478bd9Sstevel@tonic-gate continue; 31097c478bd9Sstevel@tonic-gate if (strlen(user.zone_nwif_physical) > 0 && 31107c478bd9Sstevel@tonic-gate strcmp(user.zone_nwif_physical, 31117c478bd9Sstevel@tonic-gate lookup.zone_nwif_physical) != 0) 31127c478bd9Sstevel@tonic-gate continue; /* no match */ 31137c478bd9Sstevel@tonic-gate if (strlen(user.zone_nwif_address) > 0 && 31147c478bd9Sstevel@tonic-gate !zonecfg_same_net_address(user.zone_nwif_address, 31157c478bd9Sstevel@tonic-gate lookup.zone_nwif_address)) 31167c478bd9Sstevel@tonic-gate continue; /* no match */ 31177c478bd9Sstevel@tonic-gate output_net(fp, &lookup); 31187c478bd9Sstevel@tonic-gate output = TRUE; 31197c478bd9Sstevel@tonic-gate } 31207c478bd9Sstevel@tonic-gate (void) zonecfg_endnwifent(handle); 31217c478bd9Sstevel@tonic-gate /* 31227c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 31237c478bd9Sstevel@tonic-gate * nothing to output. 31247c478bd9Sstevel@tonic-gate */ 31257c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 31267c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 31277c478bd9Sstevel@tonic-gate rt_to_str(RT_NET)); 31287c478bd9Sstevel@tonic-gate } 31297c478bd9Sstevel@tonic-gate 31307c478bd9Sstevel@tonic-gate static void 31317c478bd9Sstevel@tonic-gate output_dev(FILE *fp, struct zone_devtab *devtab) 31327c478bd9Sstevel@tonic-gate { 31337c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s\n", rt_to_str(RT_DEVICE)); 31347c478bd9Sstevel@tonic-gate output_prop(fp, PT_MATCH, devtab->zone_dev_match, B_TRUE); 31357c478bd9Sstevel@tonic-gate } 31367c478bd9Sstevel@tonic-gate 31377c478bd9Sstevel@tonic-gate static void 31387c478bd9Sstevel@tonic-gate info_dev(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 31397c478bd9Sstevel@tonic-gate { 31407c478bd9Sstevel@tonic-gate struct zone_devtab lookup, user; 31417c478bd9Sstevel@tonic-gate bool output = FALSE; 31427c478bd9Sstevel@tonic-gate 31437c478bd9Sstevel@tonic-gate if (zonecfg_setdevent(handle) != Z_OK) 31447c478bd9Sstevel@tonic-gate return; 31457c478bd9Sstevel@tonic-gate while (zonecfg_getdevent(handle, &lookup) == Z_OK) { 31467c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 31477c478bd9Sstevel@tonic-gate output_dev(fp, &lookup); 31487c478bd9Sstevel@tonic-gate continue; 31497c478bd9Sstevel@tonic-gate } 31507c478bd9Sstevel@tonic-gate if (fill_in_devtab(cmd, &user, TRUE) != Z_OK) 31517c478bd9Sstevel@tonic-gate continue; 31527c478bd9Sstevel@tonic-gate if (strlen(user.zone_dev_match) > 0 && 31537c478bd9Sstevel@tonic-gate strcmp(user.zone_dev_match, lookup.zone_dev_match) != 0) 31547c478bd9Sstevel@tonic-gate continue; /* no match */ 31557c478bd9Sstevel@tonic-gate output_dev(fp, &lookup); 31567c478bd9Sstevel@tonic-gate output = TRUE; 31577c478bd9Sstevel@tonic-gate } 31587c478bd9Sstevel@tonic-gate (void) zonecfg_enddevent(handle); 31597c478bd9Sstevel@tonic-gate /* 31607c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 31617c478bd9Sstevel@tonic-gate * nothing to output. 31627c478bd9Sstevel@tonic-gate */ 31637c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 31647c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 31657c478bd9Sstevel@tonic-gate rt_to_str(RT_DEVICE)); 31667c478bd9Sstevel@tonic-gate } 31677c478bd9Sstevel@tonic-gate 31687c478bd9Sstevel@tonic-gate static void 31697c478bd9Sstevel@tonic-gate output_rctl(FILE *fp, struct zone_rctltab *rctltab) 31707c478bd9Sstevel@tonic-gate { 31717c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *valptr; 31727c478bd9Sstevel@tonic-gate 31737c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_RCTL)); 31747c478bd9Sstevel@tonic-gate output_prop(fp, PT_NAME, rctltab->zone_rctl_name, B_TRUE); 31757c478bd9Sstevel@tonic-gate for (valptr = rctltab->zone_rctl_valptr; valptr != NULL; 31767c478bd9Sstevel@tonic-gate valptr = valptr->zone_rctlval_next) { 31777c478bd9Sstevel@tonic-gate fprintf(fp, "\t%s: (%s=%s,%s=%s,%s=%s)\n", 31787c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), 31797c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV), valptr->zone_rctlval_priv, 31807c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT), valptr->zone_rctlval_limit, 31817c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION), valptr->zone_rctlval_action); 31827c478bd9Sstevel@tonic-gate } 31837c478bd9Sstevel@tonic-gate } 31847c478bd9Sstevel@tonic-gate 31857c478bd9Sstevel@tonic-gate static void 31867c478bd9Sstevel@tonic-gate info_rctl(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 31877c478bd9Sstevel@tonic-gate { 31887c478bd9Sstevel@tonic-gate struct zone_rctltab lookup, user; 31897c478bd9Sstevel@tonic-gate bool output = FALSE; 31907c478bd9Sstevel@tonic-gate 31917c478bd9Sstevel@tonic-gate if (zonecfg_setrctlent(handle) != Z_OK) 31927c478bd9Sstevel@tonic-gate return; 31937c478bd9Sstevel@tonic-gate while (zonecfg_getrctlent(handle, &lookup) == Z_OK) { 31947c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 31957c478bd9Sstevel@tonic-gate output_rctl(fp, &lookup); 31967c478bd9Sstevel@tonic-gate } else if (fill_in_rctltab(cmd, &user, TRUE) == Z_OK && 31977c478bd9Sstevel@tonic-gate (strlen(user.zone_rctl_name) == 0 || 31987c478bd9Sstevel@tonic-gate strcmp(user.zone_rctl_name, lookup.zone_rctl_name) == 0)) { 31997c478bd9Sstevel@tonic-gate output_rctl(fp, &lookup); 32007c478bd9Sstevel@tonic-gate output = TRUE; 32017c478bd9Sstevel@tonic-gate } 32027c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(lookup.zone_rctl_valptr); 32037c478bd9Sstevel@tonic-gate } 32047c478bd9Sstevel@tonic-gate (void) zonecfg_endrctlent(handle); 32057c478bd9Sstevel@tonic-gate /* 32067c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 32077c478bd9Sstevel@tonic-gate * nothing to output. 32087c478bd9Sstevel@tonic-gate */ 32097c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 32107c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 32117c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL)); 32127c478bd9Sstevel@tonic-gate } 32137c478bd9Sstevel@tonic-gate 32147c478bd9Sstevel@tonic-gate static void 32157c478bd9Sstevel@tonic-gate output_attr(FILE *fp, struct zone_attrtab *attrtab) 32167c478bd9Sstevel@tonic-gate { 32177c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_ATTR)); 32187c478bd9Sstevel@tonic-gate output_prop(fp, PT_NAME, attrtab->zone_attr_name, B_TRUE); 32197c478bd9Sstevel@tonic-gate output_prop(fp, PT_TYPE, attrtab->zone_attr_type, B_TRUE); 32207c478bd9Sstevel@tonic-gate output_prop(fp, PT_VALUE, attrtab->zone_attr_value, B_TRUE); 32217c478bd9Sstevel@tonic-gate } 32227c478bd9Sstevel@tonic-gate 32237c478bd9Sstevel@tonic-gate static void 32247c478bd9Sstevel@tonic-gate info_attr(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 32257c478bd9Sstevel@tonic-gate { 32267c478bd9Sstevel@tonic-gate struct zone_attrtab lookup, user; 32277c478bd9Sstevel@tonic-gate bool output = FALSE; 32287c478bd9Sstevel@tonic-gate 32297c478bd9Sstevel@tonic-gate if (zonecfg_setattrent(handle) != Z_OK) 32307c478bd9Sstevel@tonic-gate return; 32317c478bd9Sstevel@tonic-gate while (zonecfg_getattrent(handle, &lookup) == Z_OK) { 32327c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 32337c478bd9Sstevel@tonic-gate output_attr(fp, &lookup); 32347c478bd9Sstevel@tonic-gate continue; 32357c478bd9Sstevel@tonic-gate } 32367c478bd9Sstevel@tonic-gate if (fill_in_attrtab(cmd, &user, TRUE) != Z_OK) 32377c478bd9Sstevel@tonic-gate continue; 32387c478bd9Sstevel@tonic-gate if (strlen(user.zone_attr_name) > 0 && 32397c478bd9Sstevel@tonic-gate strcmp(user.zone_attr_name, lookup.zone_attr_name) != 0) 32407c478bd9Sstevel@tonic-gate continue; /* no match */ 32417c478bd9Sstevel@tonic-gate if (strlen(user.zone_attr_type) > 0 && 32427c478bd9Sstevel@tonic-gate strcmp(user.zone_attr_type, lookup.zone_attr_type) != 0) 32437c478bd9Sstevel@tonic-gate continue; /* no match */ 32447c478bd9Sstevel@tonic-gate if (strlen(user.zone_attr_value) > 0 && 32457c478bd9Sstevel@tonic-gate strcmp(user.zone_attr_value, lookup.zone_attr_value) != 0) 32467c478bd9Sstevel@tonic-gate continue; /* no match */ 32477c478bd9Sstevel@tonic-gate output_attr(fp, &lookup); 32487c478bd9Sstevel@tonic-gate output = TRUE; 32497c478bd9Sstevel@tonic-gate } 32507c478bd9Sstevel@tonic-gate (void) zonecfg_endattrent(handle); 32517c478bd9Sstevel@tonic-gate /* 32527c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 32537c478bd9Sstevel@tonic-gate * nothing to output. 32547c478bd9Sstevel@tonic-gate */ 32557c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 32567c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 32577c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR)); 32587c478bd9Sstevel@tonic-gate } 32597c478bd9Sstevel@tonic-gate 3260fa9e4066Sahrens static void 3261fa9e4066Sahrens output_ds(FILE *fp, struct zone_dstab *dstab) 3262fa9e4066Sahrens { 3263fa9e4066Sahrens (void) fprintf(fp, "%s:\n", rt_to_str(RT_DATASET)); 3264fa9e4066Sahrens output_prop(fp, PT_NAME, dstab->zone_dataset_name, B_TRUE); 3265fa9e4066Sahrens } 3266fa9e4066Sahrens 3267fa9e4066Sahrens static void 3268fa9e4066Sahrens info_ds(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 3269fa9e4066Sahrens { 3270fa9e4066Sahrens struct zone_dstab lookup, user; 3271fa9e4066Sahrens bool output = FALSE; 3272fa9e4066Sahrens 3273fa9e4066Sahrens if (zonecfg_setdevent(handle) != Z_OK) 3274fa9e4066Sahrens return; 3275fa9e4066Sahrens while (zonecfg_getdsent(handle, &lookup) == Z_OK) { 3276fa9e4066Sahrens if (cmd->cmd_prop_nv_pairs == 0) { 3277fa9e4066Sahrens output_ds(fp, &lookup); 3278fa9e4066Sahrens continue; 3279fa9e4066Sahrens } 3280fa9e4066Sahrens if (fill_in_dstab(cmd, &user, TRUE) != Z_OK) 3281fa9e4066Sahrens continue; 3282fa9e4066Sahrens if (strlen(user.zone_dataset_name) > 0 && 3283fa9e4066Sahrens strcmp(user.zone_dataset_name, 3284fa9e4066Sahrens lookup.zone_dataset_name) != 0) 3285fa9e4066Sahrens continue; /* no match */ 3286fa9e4066Sahrens output_ds(fp, &lookup); 3287fa9e4066Sahrens output = TRUE; 3288fa9e4066Sahrens } 3289fa9e4066Sahrens (void) zonecfg_enddsent(handle); 3290fa9e4066Sahrens /* 3291fa9e4066Sahrens * If a property n/v pair was specified, warn the user if there was 3292fa9e4066Sahrens * nothing to output. 3293fa9e4066Sahrens */ 3294fa9e4066Sahrens if (!output && cmd->cmd_prop_nv_pairs > 0) 3295fa9e4066Sahrens (void) printf(gettext("No such %s resource.\n"), 3296fa9e4066Sahrens rt_to_str(RT_DATASET)); 3297fa9e4066Sahrens } 3298fa9e4066Sahrens 3299fa9e4066Sahrens 33007c478bd9Sstevel@tonic-gate void 33017c478bd9Sstevel@tonic-gate info_func(cmd_t *cmd) 33027c478bd9Sstevel@tonic-gate { 33037c478bd9Sstevel@tonic-gate FILE *fp = stdout; 33047c478bd9Sstevel@tonic-gate bool need_to_close = FALSE; 33057c478bd9Sstevel@tonic-gate char *pager; 33067c478bd9Sstevel@tonic-gate 33077c478bd9Sstevel@tonic-gate assert(cmd != NULL); 33087c478bd9Sstevel@tonic-gate 33097c478bd9Sstevel@tonic-gate if (initialize(TRUE) != Z_OK) 33107c478bd9Sstevel@tonic-gate return; 33117c478bd9Sstevel@tonic-gate 33127c478bd9Sstevel@tonic-gate /* don't page error output */ 33137c478bd9Sstevel@tonic-gate if (interactive_mode) { 33147c478bd9Sstevel@tonic-gate if ((pager = getenv("PAGER")) == NULL) 33157c478bd9Sstevel@tonic-gate pager = PAGER; 33167c478bd9Sstevel@tonic-gate if ((fp = popen(pager, "w")) != NULL) 33177c478bd9Sstevel@tonic-gate need_to_close = TRUE; 33187c478bd9Sstevel@tonic-gate else 33197c478bd9Sstevel@tonic-gate fp = stdout; 33207c478bd9Sstevel@tonic-gate setbuf(fp, NULL); 33217c478bd9Sstevel@tonic-gate } 33227c478bd9Sstevel@tonic-gate 33237c478bd9Sstevel@tonic-gate if (!global_scope) { 33247c478bd9Sstevel@tonic-gate switch (resource_scope) { 33257c478bd9Sstevel@tonic-gate case RT_FS: 33267c478bd9Sstevel@tonic-gate output_fs(fp, &in_progress_fstab); 33277c478bd9Sstevel@tonic-gate break; 33287c478bd9Sstevel@tonic-gate case RT_IPD: 33297c478bd9Sstevel@tonic-gate output_ipd(fp, &in_progress_ipdtab); 33307c478bd9Sstevel@tonic-gate break; 33317c478bd9Sstevel@tonic-gate case RT_NET: 33327c478bd9Sstevel@tonic-gate output_net(fp, &in_progress_nwiftab); 33337c478bd9Sstevel@tonic-gate break; 33347c478bd9Sstevel@tonic-gate case RT_DEVICE: 33357c478bd9Sstevel@tonic-gate output_dev(fp, &in_progress_devtab); 33367c478bd9Sstevel@tonic-gate break; 33377c478bd9Sstevel@tonic-gate case RT_RCTL: 33387c478bd9Sstevel@tonic-gate output_rctl(fp, &in_progress_rctltab); 33397c478bd9Sstevel@tonic-gate break; 33407c478bd9Sstevel@tonic-gate case RT_ATTR: 33417c478bd9Sstevel@tonic-gate output_attr(fp, &in_progress_attrtab); 33427c478bd9Sstevel@tonic-gate break; 3343fa9e4066Sahrens case RT_DATASET: 3344fa9e4066Sahrens output_ds(fp, &in_progress_dstab); 3345fa9e4066Sahrens break; 33467c478bd9Sstevel@tonic-gate } 33477c478bd9Sstevel@tonic-gate goto cleanup; 33487c478bd9Sstevel@tonic-gate } 33497c478bd9Sstevel@tonic-gate 33507c478bd9Sstevel@tonic-gate switch (cmd->cmd_res_type) { 33517c478bd9Sstevel@tonic-gate case RT_UNKNOWN: 3352087719fdSdp info_zonename(handle, fp); 33537c478bd9Sstevel@tonic-gate info_zonepath(handle, fp); 33547c478bd9Sstevel@tonic-gate info_autoboot(handle, fp); 33557c478bd9Sstevel@tonic-gate info_pool(handle, fp); 33567c478bd9Sstevel@tonic-gate info_ipd(handle, fp, cmd); 33577c478bd9Sstevel@tonic-gate info_fs(handle, fp, cmd); 33587c478bd9Sstevel@tonic-gate info_net(handle, fp, cmd); 33597c478bd9Sstevel@tonic-gate info_dev(handle, fp, cmd); 33607c478bd9Sstevel@tonic-gate info_rctl(handle, fp, cmd); 33617c478bd9Sstevel@tonic-gate info_attr(handle, fp, cmd); 3362fa9e4066Sahrens info_ds(handle, fp, cmd); 33637c478bd9Sstevel@tonic-gate break; 3364087719fdSdp case RT_ZONENAME: 3365087719fdSdp info_zonename(handle, fp); 3366087719fdSdp break; 33677c478bd9Sstevel@tonic-gate case RT_ZONEPATH: 33687c478bd9Sstevel@tonic-gate info_zonepath(handle, fp); 33697c478bd9Sstevel@tonic-gate break; 33707c478bd9Sstevel@tonic-gate case RT_AUTOBOOT: 33717c478bd9Sstevel@tonic-gate info_autoboot(handle, fp); 33727c478bd9Sstevel@tonic-gate break; 33737c478bd9Sstevel@tonic-gate case RT_POOL: 33747c478bd9Sstevel@tonic-gate info_pool(handle, fp); 33757c478bd9Sstevel@tonic-gate break; 33767c478bd9Sstevel@tonic-gate case RT_FS: 33777c478bd9Sstevel@tonic-gate info_fs(handle, fp, cmd); 33787c478bd9Sstevel@tonic-gate break; 33797c478bd9Sstevel@tonic-gate case RT_IPD: 33807c478bd9Sstevel@tonic-gate info_ipd(handle, fp, cmd); 33817c478bd9Sstevel@tonic-gate break; 33827c478bd9Sstevel@tonic-gate case RT_NET: 33837c478bd9Sstevel@tonic-gate info_net(handle, fp, cmd); 33847c478bd9Sstevel@tonic-gate break; 33857c478bd9Sstevel@tonic-gate case RT_DEVICE: 33867c478bd9Sstevel@tonic-gate info_dev(handle, fp, cmd); 33877c478bd9Sstevel@tonic-gate break; 33887c478bd9Sstevel@tonic-gate case RT_RCTL: 33897c478bd9Sstevel@tonic-gate info_rctl(handle, fp, cmd); 33907c478bd9Sstevel@tonic-gate break; 33917c478bd9Sstevel@tonic-gate case RT_ATTR: 33927c478bd9Sstevel@tonic-gate info_attr(handle, fp, cmd); 33937c478bd9Sstevel@tonic-gate break; 3394fa9e4066Sahrens case RT_DATASET: 3395fa9e4066Sahrens info_ds(handle, fp, cmd); 3396fa9e4066Sahrens break; 33977c478bd9Sstevel@tonic-gate default: 33987c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(cmd->cmd_res_type), Z_NO_RESOURCE_TYPE, 33997c478bd9Sstevel@tonic-gate TRUE); 34007c478bd9Sstevel@tonic-gate } 34017c478bd9Sstevel@tonic-gate 34027c478bd9Sstevel@tonic-gate cleanup: 34037c478bd9Sstevel@tonic-gate if (need_to_close) 34047c478bd9Sstevel@tonic-gate (void) pclose(fp); 34057c478bd9Sstevel@tonic-gate } 34067c478bd9Sstevel@tonic-gate 3407087719fdSdp /* 3408087719fdSdp * Helper function for verify-- checks that a required string property 3409087719fdSdp * exists. 3410087719fdSdp */ 3411087719fdSdp static void 3412087719fdSdp check_reqd_prop(char *attr, int rt, int pt, int *ret_val) 34137c478bd9Sstevel@tonic-gate { 3414087719fdSdp if (strlen(attr) == 0) { 3415087719fdSdp zerr(gettext("%s: %s not specified"), rt_to_str(rt), 3416087719fdSdp pt_to_str(pt)); 3417087719fdSdp saw_error = TRUE; 3418087719fdSdp if (*ret_val == Z_OK) 3419087719fdSdp *ret_val = Z_REQD_PROPERTY_MISSING; 34207c478bd9Sstevel@tonic-gate } 34217c478bd9Sstevel@tonic-gate } 34227c478bd9Sstevel@tonic-gate 34237c478bd9Sstevel@tonic-gate /* 34247c478bd9Sstevel@tonic-gate * See the DTD for which attributes are required for which resources. 34257c478bd9Sstevel@tonic-gate * 34267c478bd9Sstevel@tonic-gate * This function can be called by commit_func(), which needs to save things, 34277c478bd9Sstevel@tonic-gate * in addition to the general call from parse_and_run(), which doesn't need 34287c478bd9Sstevel@tonic-gate * things saved. Since the parameters are standardized, we distinguish by 34297c478bd9Sstevel@tonic-gate * having commit_func() call here with cmd->cmd_arg set to "save" to indicate 34307c478bd9Sstevel@tonic-gate * that a save is needed. 34317c478bd9Sstevel@tonic-gate */ 34327c478bd9Sstevel@tonic-gate void 34337c478bd9Sstevel@tonic-gate verify_func(cmd_t *cmd) 34347c478bd9Sstevel@tonic-gate { 34357c478bd9Sstevel@tonic-gate struct zone_nwiftab nwiftab; 34367c478bd9Sstevel@tonic-gate struct zone_fstab fstab; 34377c478bd9Sstevel@tonic-gate struct zone_attrtab attrtab; 34387c478bd9Sstevel@tonic-gate struct zone_rctltab rctltab; 3439fa9e4066Sahrens struct zone_dstab dstab; 34407c478bd9Sstevel@tonic-gate char zonepath[MAXPATHLEN]; 34417c478bd9Sstevel@tonic-gate int err, ret_val = Z_OK, arg; 34427c478bd9Sstevel@tonic-gate bool save = FALSE; 34437c478bd9Sstevel@tonic-gate 34447c478bd9Sstevel@tonic-gate optind = 0; 34457c478bd9Sstevel@tonic-gate if ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 34467c478bd9Sstevel@tonic-gate switch (arg) { 34477c478bd9Sstevel@tonic-gate case '?': 34487c478bd9Sstevel@tonic-gate longer_usage(CMD_VERIFY); 34497c478bd9Sstevel@tonic-gate return; 34507c478bd9Sstevel@tonic-gate default: 34517c478bd9Sstevel@tonic-gate short_usage(CMD_VERIFY); 34527c478bd9Sstevel@tonic-gate return; 34537c478bd9Sstevel@tonic-gate } 34547c478bd9Sstevel@tonic-gate } 34557c478bd9Sstevel@tonic-gate if (optind > cmd->cmd_argc) { 34567c478bd9Sstevel@tonic-gate short_usage(CMD_VERIFY); 34577c478bd9Sstevel@tonic-gate return; 34587c478bd9Sstevel@tonic-gate } 34597c478bd9Sstevel@tonic-gate 34607c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_VERIFY)) 34617c478bd9Sstevel@tonic-gate return; 34627c478bd9Sstevel@tonic-gate 34637c478bd9Sstevel@tonic-gate assert(cmd != NULL); 34647c478bd9Sstevel@tonic-gate 34657c478bd9Sstevel@tonic-gate if (cmd->cmd_argc > 0 && (strcmp(cmd->cmd_argv[0], "save") == 0)) 34667c478bd9Sstevel@tonic-gate save = TRUE; 34677c478bd9Sstevel@tonic-gate if (initialize(TRUE) != Z_OK) 34687c478bd9Sstevel@tonic-gate return; 34697c478bd9Sstevel@tonic-gate 34707c478bd9Sstevel@tonic-gate if (zonecfg_get_zonepath(handle, zonepath, sizeof (zonepath)) != Z_OK) { 3471087719fdSdp zerr(gettext("%s not specified"), pt_to_str(PT_ZONEPATH)); 34727c478bd9Sstevel@tonic-gate ret_val = Z_REQD_RESOURCE_MISSING; 34737c478bd9Sstevel@tonic-gate saw_error = TRUE; 34747c478bd9Sstevel@tonic-gate } 34757c478bd9Sstevel@tonic-gate if (strlen(zonepath) == 0) { 3476087719fdSdp zerr(gettext("%s cannot be empty."), pt_to_str(PT_ZONEPATH)); 34777c478bd9Sstevel@tonic-gate ret_val = Z_REQD_RESOURCE_MISSING; 34787c478bd9Sstevel@tonic-gate saw_error = TRUE; 34797c478bd9Sstevel@tonic-gate } 34807c478bd9Sstevel@tonic-gate 34817c478bd9Sstevel@tonic-gate if ((err = zonecfg_setipdent(handle)) != Z_OK) { 34827c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 34837c478bd9Sstevel@tonic-gate return; 34847c478bd9Sstevel@tonic-gate } 34857c478bd9Sstevel@tonic-gate while (zonecfg_getipdent(handle, &fstab) == Z_OK) { 3486087719fdSdp check_reqd_prop(fstab.zone_fs_dir, RT_IPD, PT_DIR, &ret_val); 34877c478bd9Sstevel@tonic-gate } 34887c478bd9Sstevel@tonic-gate (void) zonecfg_endipdent(handle); 34897c478bd9Sstevel@tonic-gate 34907c478bd9Sstevel@tonic-gate if ((err = zonecfg_setfsent(handle)) != Z_OK) { 34917c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 34927c478bd9Sstevel@tonic-gate return; 34937c478bd9Sstevel@tonic-gate } 34947c478bd9Sstevel@tonic-gate while (zonecfg_getfsent(handle, &fstab) == Z_OK) { 3495087719fdSdp check_reqd_prop(fstab.zone_fs_dir, RT_FS, PT_DIR, &ret_val); 3496087719fdSdp check_reqd_prop(fstab.zone_fs_special, RT_FS, PT_SPECIAL, 3497087719fdSdp &ret_val); 3498087719fdSdp check_reqd_prop(fstab.zone_fs_type, RT_FS, PT_TYPE, &ret_val); 3499087719fdSdp 35007c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(fstab.zone_fs_options); 35017c478bd9Sstevel@tonic-gate } 35027c478bd9Sstevel@tonic-gate (void) zonecfg_endfsent(handle); 35037c478bd9Sstevel@tonic-gate 35047c478bd9Sstevel@tonic-gate if ((err = zonecfg_setnwifent(handle)) != Z_OK) { 35057c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 35067c478bd9Sstevel@tonic-gate return; 35077c478bd9Sstevel@tonic-gate } 35087c478bd9Sstevel@tonic-gate while (zonecfg_getnwifent(handle, &nwiftab) == Z_OK) { 3509087719fdSdp check_reqd_prop(nwiftab.zone_nwif_address, RT_NET, 3510087719fdSdp PT_ADDRESS, &ret_val); 3511087719fdSdp check_reqd_prop(nwiftab.zone_nwif_physical, RT_NET, 3512087719fdSdp PT_PHYSICAL, &ret_val); 35137c478bd9Sstevel@tonic-gate } 35147c478bd9Sstevel@tonic-gate (void) zonecfg_endnwifent(handle); 35157c478bd9Sstevel@tonic-gate 35167c478bd9Sstevel@tonic-gate if ((err = zonecfg_setrctlent(handle)) != Z_OK) { 35177c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 35187c478bd9Sstevel@tonic-gate return; 35197c478bd9Sstevel@tonic-gate } 35207c478bd9Sstevel@tonic-gate while (zonecfg_getrctlent(handle, &rctltab) == Z_OK) { 3521087719fdSdp check_reqd_prop(rctltab.zone_rctl_name, RT_RCTL, PT_NAME, 3522087719fdSdp &ret_val); 3523087719fdSdp 35247c478bd9Sstevel@tonic-gate if (rctltab.zone_rctl_valptr == NULL) { 35257c478bd9Sstevel@tonic-gate zerr(gettext("%s: no %s specified"), 35267c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL), pt_to_str(PT_VALUE)); 35277c478bd9Sstevel@tonic-gate saw_error = TRUE; 35287c478bd9Sstevel@tonic-gate if (ret_val == Z_OK) 35297c478bd9Sstevel@tonic-gate ret_val = Z_REQD_PROPERTY_MISSING; 35307c478bd9Sstevel@tonic-gate } else { 35317c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr); 35327c478bd9Sstevel@tonic-gate } 35337c478bd9Sstevel@tonic-gate } 35347c478bd9Sstevel@tonic-gate (void) zonecfg_endrctlent(handle); 35357c478bd9Sstevel@tonic-gate 35367c478bd9Sstevel@tonic-gate if ((err = zonecfg_setattrent(handle)) != Z_OK) { 35377c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 35387c478bd9Sstevel@tonic-gate return; 35397c478bd9Sstevel@tonic-gate } 35407c478bd9Sstevel@tonic-gate while (zonecfg_getattrent(handle, &attrtab) == Z_OK) { 3541087719fdSdp check_reqd_prop(attrtab.zone_attr_name, RT_ATTR, PT_NAME, 3542087719fdSdp &ret_val); 3543087719fdSdp check_reqd_prop(attrtab.zone_attr_type, RT_ATTR, PT_TYPE, 3544087719fdSdp &ret_val); 3545087719fdSdp check_reqd_prop(attrtab.zone_attr_value, RT_ATTR, PT_VALUE, 3546087719fdSdp &ret_val); 35477c478bd9Sstevel@tonic-gate } 35487c478bd9Sstevel@tonic-gate (void) zonecfg_endattrent(handle); 35497c478bd9Sstevel@tonic-gate 3550fa9e4066Sahrens if ((err = zonecfg_setdsent(handle)) != Z_OK) { 3551fa9e4066Sahrens zone_perror(zone, err, TRUE); 3552fa9e4066Sahrens return; 3553fa9e4066Sahrens } 3554fa9e4066Sahrens while (zonecfg_getdsent(handle, &dstab) == Z_OK) { 3555fa9e4066Sahrens if (strlen(dstab.zone_dataset_name) == 0) { 3556fa9e4066Sahrens zerr("%s: %s %s", rt_to_str(RT_DATASET), 3557fa9e4066Sahrens pt_to_str(PT_NAME), gettext("not specified")); 3558fa9e4066Sahrens saw_error = TRUE; 3559fa9e4066Sahrens if (ret_val == Z_OK) 3560fa9e4066Sahrens ret_val = Z_REQD_PROPERTY_MISSING; 3561fa9e4066Sahrens } else if (!zfs_name_valid(dstab.zone_dataset_name, 3562fa9e4066Sahrens ZFS_TYPE_FILESYSTEM)) { 3563fa9e4066Sahrens zerr("%s: %s %s", rt_to_str(RT_DATASET), 3564fa9e4066Sahrens pt_to_str(PT_NAME), gettext("invalid")); 3565fa9e4066Sahrens saw_error = TRUE; 3566fa9e4066Sahrens if (ret_val == Z_OK) 3567fa9e4066Sahrens ret_val = Z_BAD_PROPERTY; 3568fa9e4066Sahrens } 3569fa9e4066Sahrens 3570fa9e4066Sahrens } 3571fa9e4066Sahrens (void) zonecfg_enddsent(handle); 3572fa9e4066Sahrens 35737c478bd9Sstevel@tonic-gate if (!global_scope) { 35747c478bd9Sstevel@tonic-gate zerr(gettext("resource specification incomplete")); 35757c478bd9Sstevel@tonic-gate saw_error = TRUE; 35767c478bd9Sstevel@tonic-gate if (ret_val == Z_OK) 35777c478bd9Sstevel@tonic-gate ret_val = Z_INSUFFICIENT_SPEC; 35787c478bd9Sstevel@tonic-gate } 35797c478bd9Sstevel@tonic-gate 35807c478bd9Sstevel@tonic-gate if (save) { 3581087719fdSdp if (ret_val == Z_OK) { 3582087719fdSdp if ((ret_val = zonecfg_save(handle)) == Z_OK) { 3583087719fdSdp need_to_commit = FALSE; 3584087719fdSdp (void) strlcpy(revert_zone, zone, 3585087719fdSdp sizeof (revert_zone)); 3586087719fdSdp } 3587087719fdSdp } else { 3588087719fdSdp zerr(gettext("Zone %s failed to verify"), zone); 3589087719fdSdp } 35907c478bd9Sstevel@tonic-gate } 35917c478bd9Sstevel@tonic-gate if (ret_val != Z_OK) 35927c478bd9Sstevel@tonic-gate zone_perror(zone, ret_val, TRUE); 35937c478bd9Sstevel@tonic-gate } 35947c478bd9Sstevel@tonic-gate 35957c478bd9Sstevel@tonic-gate void 35967c478bd9Sstevel@tonic-gate cancel_func(cmd_t *cmd) 35977c478bd9Sstevel@tonic-gate { 35987c478bd9Sstevel@tonic-gate int arg; 35997c478bd9Sstevel@tonic-gate 36007c478bd9Sstevel@tonic-gate assert(cmd != NULL); 36017c478bd9Sstevel@tonic-gate 36027c478bd9Sstevel@tonic-gate optind = 0; 36037c478bd9Sstevel@tonic-gate if ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 36047c478bd9Sstevel@tonic-gate switch (arg) { 36057c478bd9Sstevel@tonic-gate case '?': 36067c478bd9Sstevel@tonic-gate longer_usage(CMD_CANCEL); 36077c478bd9Sstevel@tonic-gate return; 36087c478bd9Sstevel@tonic-gate default: 36097c478bd9Sstevel@tonic-gate short_usage(CMD_CANCEL); 36107c478bd9Sstevel@tonic-gate return; 36117c478bd9Sstevel@tonic-gate } 36127c478bd9Sstevel@tonic-gate } 36137c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 36147c478bd9Sstevel@tonic-gate short_usage(CMD_CANCEL); 36157c478bd9Sstevel@tonic-gate return; 36167c478bd9Sstevel@tonic-gate } 36177c478bd9Sstevel@tonic-gate 36187c478bd9Sstevel@tonic-gate if (global_scope) 36197c478bd9Sstevel@tonic-gate scope_usage(CMD_CANCEL); 36207c478bd9Sstevel@tonic-gate global_scope = TRUE; 36217c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(in_progress_fstab.zone_fs_options); 36227c478bd9Sstevel@tonic-gate bzero(&in_progress_fstab, sizeof (in_progress_fstab)); 36237c478bd9Sstevel@tonic-gate bzero(&in_progress_nwiftab, sizeof (in_progress_nwiftab)); 3624fa9e4066Sahrens bzero(&in_progress_ipdtab, sizeof (in_progress_ipdtab)); 36257c478bd9Sstevel@tonic-gate bzero(&in_progress_devtab, sizeof (in_progress_devtab)); 36267c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(in_progress_rctltab.zone_rctl_valptr); 36277c478bd9Sstevel@tonic-gate bzero(&in_progress_rctltab, sizeof (in_progress_rctltab)); 36287c478bd9Sstevel@tonic-gate bzero(&in_progress_attrtab, sizeof (in_progress_attrtab)); 3629fa9e4066Sahrens bzero(&in_progress_dstab, sizeof (in_progress_dstab)); 36307c478bd9Sstevel@tonic-gate } 36317c478bd9Sstevel@tonic-gate 36327c478bd9Sstevel@tonic-gate static int 36337c478bd9Sstevel@tonic-gate validate_attr_name(char *name) 36347c478bd9Sstevel@tonic-gate { 36357c478bd9Sstevel@tonic-gate int i; 36367c478bd9Sstevel@tonic-gate 36377c478bd9Sstevel@tonic-gate if (!isalnum(name[0])) { 36387c478bd9Sstevel@tonic-gate zerr(gettext("Invalid %s %s %s: must start with an alpha-" 36397c478bd9Sstevel@tonic-gate "numeric character."), rt_to_str(RT_ATTR), 36407c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), name); 36417c478bd9Sstevel@tonic-gate return (Z_INVAL); 36427c478bd9Sstevel@tonic-gate } 36437c478bd9Sstevel@tonic-gate for (i = 1; name[i]; i++) 36447c478bd9Sstevel@tonic-gate if (!isalnum(name[i]) && name[i] != '-' && name[i] != '.') { 36457c478bd9Sstevel@tonic-gate zerr(gettext("Invalid %s %s %s: can only contain " 36467c478bd9Sstevel@tonic-gate "alpha-numeric characters, plus '-' and '.'."), 36477c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_NAME), name); 36487c478bd9Sstevel@tonic-gate return (Z_INVAL); 36497c478bd9Sstevel@tonic-gate } 36507c478bd9Sstevel@tonic-gate return (Z_OK); 36517c478bd9Sstevel@tonic-gate } 36527c478bd9Sstevel@tonic-gate 36537c478bd9Sstevel@tonic-gate static int 36547c478bd9Sstevel@tonic-gate validate_attr_type_val(struct zone_attrtab *attrtab) 36557c478bd9Sstevel@tonic-gate { 36567c478bd9Sstevel@tonic-gate boolean_t boolval; 36577c478bd9Sstevel@tonic-gate int64_t intval; 36587c478bd9Sstevel@tonic-gate char strval[MAXNAMELEN]; 36597c478bd9Sstevel@tonic-gate uint64_t uintval; 36607c478bd9Sstevel@tonic-gate 36617c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "boolean") == 0) { 36627c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_boolean(attrtab, &boolval) == Z_OK) 36637c478bd9Sstevel@tonic-gate return (Z_OK); 36647c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 36657c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "boolean"); 36667c478bd9Sstevel@tonic-gate return (Z_ERR); 36677c478bd9Sstevel@tonic-gate } 36687c478bd9Sstevel@tonic-gate 36697c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "int") == 0) { 36707c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_int(attrtab, &intval) == Z_OK) 36717c478bd9Sstevel@tonic-gate return (Z_OK); 36727c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 36737c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "int"); 36747c478bd9Sstevel@tonic-gate return (Z_ERR); 36757c478bd9Sstevel@tonic-gate } 36767c478bd9Sstevel@tonic-gate 36777c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "string") == 0) { 36787c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_string(attrtab, strval, 36797c478bd9Sstevel@tonic-gate sizeof (strval)) == Z_OK) 36807c478bd9Sstevel@tonic-gate return (Z_OK); 36817c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 36827c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "string"); 36837c478bd9Sstevel@tonic-gate return (Z_ERR); 36847c478bd9Sstevel@tonic-gate } 36857c478bd9Sstevel@tonic-gate 36867c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "uint") == 0) { 36877c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_uint(attrtab, &uintval) == Z_OK) 36887c478bd9Sstevel@tonic-gate return (Z_OK); 36897c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 36907c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "uint"); 36917c478bd9Sstevel@tonic-gate return (Z_ERR); 36927c478bd9Sstevel@tonic-gate } 36937c478bd9Sstevel@tonic-gate 36947c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s %s '%s'"), rt_to_str(RT_ATTR), 36957c478bd9Sstevel@tonic-gate pt_to_str(PT_TYPE), attrtab->zone_attr_type); 36967c478bd9Sstevel@tonic-gate return (Z_ERR); 36977c478bd9Sstevel@tonic-gate } 36987c478bd9Sstevel@tonic-gate 3699087719fdSdp /* 3700087719fdSdp * Helper function for end_func-- checks the existence of a given property 3701087719fdSdp * and emits a message if not specified. 3702087719fdSdp */ 3703087719fdSdp static int 3704087719fdSdp end_check_reqd(char *attr, int pt, bool *validation_failed) 3705087719fdSdp { 3706087719fdSdp if (strlen(attr) == 0) { 3707087719fdSdp *validation_failed = TRUE; 3708087719fdSdp zerr(gettext("%s not specified"), pt_to_str(pt)); 3709087719fdSdp return (Z_ERR); 3710087719fdSdp } 3711087719fdSdp return (Z_OK); 3712087719fdSdp } 3713087719fdSdp 37147c478bd9Sstevel@tonic-gate void 37157c478bd9Sstevel@tonic-gate end_func(cmd_t *cmd) 37167c478bd9Sstevel@tonic-gate { 37177c478bd9Sstevel@tonic-gate bool validation_failed = FALSE; 37187c478bd9Sstevel@tonic-gate struct zone_fstab tmp_fstab; 37197c478bd9Sstevel@tonic-gate struct zone_nwiftab tmp_nwiftab; 37207c478bd9Sstevel@tonic-gate struct zone_devtab tmp_devtab; 37217c478bd9Sstevel@tonic-gate struct zone_rctltab tmp_rctltab; 37227c478bd9Sstevel@tonic-gate struct zone_attrtab tmp_attrtab; 3723fa9e4066Sahrens struct zone_dstab tmp_dstab; 37247c478bd9Sstevel@tonic-gate int err, arg; 37257c478bd9Sstevel@tonic-gate 37267c478bd9Sstevel@tonic-gate assert(cmd != NULL); 37277c478bd9Sstevel@tonic-gate 37287c478bd9Sstevel@tonic-gate optind = 0; 37297c478bd9Sstevel@tonic-gate if ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 37307c478bd9Sstevel@tonic-gate switch (arg) { 37317c478bd9Sstevel@tonic-gate case '?': 37327c478bd9Sstevel@tonic-gate longer_usage(CMD_END); 37337c478bd9Sstevel@tonic-gate return; 37347c478bd9Sstevel@tonic-gate default: 37357c478bd9Sstevel@tonic-gate short_usage(CMD_END); 37367c478bd9Sstevel@tonic-gate return; 37377c478bd9Sstevel@tonic-gate } 37387c478bd9Sstevel@tonic-gate } 37397c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 37407c478bd9Sstevel@tonic-gate short_usage(CMD_END); 37417c478bd9Sstevel@tonic-gate return; 37427c478bd9Sstevel@tonic-gate } 37437c478bd9Sstevel@tonic-gate 37447c478bd9Sstevel@tonic-gate if (global_scope) { 37457c478bd9Sstevel@tonic-gate scope_usage(CMD_END); 37467c478bd9Sstevel@tonic-gate return; 37477c478bd9Sstevel@tonic-gate } 37487c478bd9Sstevel@tonic-gate 37497c478bd9Sstevel@tonic-gate assert(end_op == CMD_ADD || end_op == CMD_SELECT); 37507c478bd9Sstevel@tonic-gate 37517c478bd9Sstevel@tonic-gate switch (resource_scope) { 37527c478bd9Sstevel@tonic-gate case RT_FS: 37537c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 3754087719fdSdp if (end_check_reqd(in_progress_fstab.zone_fs_dir, 3755087719fdSdp PT_DIR, &validation_failed) == Z_OK) { 3756087719fdSdp if (in_progress_fstab.zone_fs_dir[0] != '/') { 3757087719fdSdp zerr(gettext("%s %s is not an absolute path."), 3758087719fdSdp pt_to_str(PT_DIR), 3759087719fdSdp in_progress_fstab.zone_fs_dir); 37607c478bd9Sstevel@tonic-gate validation_failed = TRUE; 37617c478bd9Sstevel@tonic-gate } 37627c478bd9Sstevel@tonic-gate } 3763087719fdSdp 3764087719fdSdp (void) end_check_reqd(in_progress_fstab.zone_fs_special, 3765087719fdSdp PT_SPECIAL, &validation_failed); 3766087719fdSdp 37677c478bd9Sstevel@tonic-gate if (in_progress_fstab.zone_fs_raw[0] != '\0' && 37687c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_raw[0] != '/') { 3769087719fdSdp zerr(gettext("%s %s is not an absolute path."), 3770087719fdSdp pt_to_str(PT_RAW), 3771087719fdSdp in_progress_fstab.zone_fs_raw); 37727c478bd9Sstevel@tonic-gate validation_failed = TRUE; 37737c478bd9Sstevel@tonic-gate } 3774087719fdSdp 3775087719fdSdp (void) end_check_reqd(in_progress_fstab.zone_fs_type, PT_TYPE, 3776087719fdSdp &validation_failed); 3777087719fdSdp 3778087719fdSdp if (validation_failed) { 37797c478bd9Sstevel@tonic-gate saw_error = TRUE; 37807c478bd9Sstevel@tonic-gate return; 3781087719fdSdp } 3782087719fdSdp 37837c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 37847c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 37857c478bd9Sstevel@tonic-gate bzero(&tmp_fstab, sizeof (tmp_fstab)); 37867c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_fstab.zone_fs_dir, 37877c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_dir, 37887c478bd9Sstevel@tonic-gate sizeof (tmp_fstab.zone_fs_dir)); 37897c478bd9Sstevel@tonic-gate err = zonecfg_lookup_filesystem(handle, &tmp_fstab); 37907c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(tmp_fstab.zone_fs_options); 37917c478bd9Sstevel@tonic-gate if (err == Z_OK) { 37927c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource " 37937c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 37947c478bd9Sstevel@tonic-gate rt_to_str(RT_FS), pt_to_str(PT_DIR), 37957c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_dir); 37967c478bd9Sstevel@tonic-gate saw_error = TRUE; 37977c478bd9Sstevel@tonic-gate return; 37987c478bd9Sstevel@tonic-gate } 37997c478bd9Sstevel@tonic-gate err = zonecfg_add_filesystem(handle, 38007c478bd9Sstevel@tonic-gate &in_progress_fstab); 38017c478bd9Sstevel@tonic-gate } else { 38027c478bd9Sstevel@tonic-gate err = zonecfg_modify_filesystem(handle, &old_fstab, 38037c478bd9Sstevel@tonic-gate &in_progress_fstab); 38047c478bd9Sstevel@tonic-gate } 38057c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(in_progress_fstab.zone_fs_options); 38067c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_options = NULL; 38077c478bd9Sstevel@tonic-gate break; 3808087719fdSdp 38097c478bd9Sstevel@tonic-gate case RT_IPD: 38107c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 3811087719fdSdp if (end_check_reqd(in_progress_ipdtab.zone_fs_dir, PT_DIR, 3812087719fdSdp &validation_failed) == Z_OK) { 3813087719fdSdp if (in_progress_ipdtab.zone_fs_dir[0] != '/') { 3814087719fdSdp zerr(gettext("%s %s is not an absolute path."), 3815087719fdSdp pt_to_str(PT_DIR), 3816087719fdSdp in_progress_ipdtab.zone_fs_dir); 38177c478bd9Sstevel@tonic-gate validation_failed = TRUE; 38187c478bd9Sstevel@tonic-gate } 3819087719fdSdp } 3820087719fdSdp if (validation_failed) { 3821087719fdSdp saw_error = TRUE; 38227c478bd9Sstevel@tonic-gate return; 3823087719fdSdp } 3824087719fdSdp 38257c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 38267c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 38277c478bd9Sstevel@tonic-gate bzero(&tmp_fstab, sizeof (tmp_fstab)); 38287c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_fstab.zone_fs_dir, 38297c478bd9Sstevel@tonic-gate in_progress_ipdtab.zone_fs_dir, 38307c478bd9Sstevel@tonic-gate sizeof (tmp_fstab.zone_fs_dir)); 38317c478bd9Sstevel@tonic-gate err = zonecfg_lookup_ipd(handle, &tmp_fstab); 38327c478bd9Sstevel@tonic-gate if (err == Z_OK) { 38337c478bd9Sstevel@tonic-gate zerr(gettext("An %s resource " 38347c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 38357c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD), pt_to_str(PT_DIR), 38367c478bd9Sstevel@tonic-gate in_progress_ipdtab.zone_fs_dir); 38377c478bd9Sstevel@tonic-gate saw_error = TRUE; 38387c478bd9Sstevel@tonic-gate return; 38397c478bd9Sstevel@tonic-gate } 38407c478bd9Sstevel@tonic-gate err = zonecfg_add_ipd(handle, &in_progress_ipdtab); 38417c478bd9Sstevel@tonic-gate } else { 38427c478bd9Sstevel@tonic-gate err = zonecfg_modify_ipd(handle, &old_ipdtab, 38437c478bd9Sstevel@tonic-gate &in_progress_ipdtab); 38447c478bd9Sstevel@tonic-gate } 38457c478bd9Sstevel@tonic-gate break; 38467c478bd9Sstevel@tonic-gate case RT_NET: 38477c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 3848087719fdSdp (void) end_check_reqd(in_progress_nwiftab.zone_nwif_physical, 3849087719fdSdp PT_PHYSICAL, &validation_failed); 3850087719fdSdp (void) end_check_reqd(in_progress_nwiftab.zone_nwif_address, 3851087719fdSdp PT_ADDRESS, &validation_failed); 3852087719fdSdp 3853087719fdSdp if (validation_failed) { 38547c478bd9Sstevel@tonic-gate saw_error = TRUE; 38557c478bd9Sstevel@tonic-gate return; 3856087719fdSdp } 3857087719fdSdp 38587c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 38597c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 38607c478bd9Sstevel@tonic-gate bzero(&tmp_nwiftab, sizeof (tmp_nwiftab)); 38617c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_nwiftab.zone_nwif_address, 38627c478bd9Sstevel@tonic-gate in_progress_nwiftab.zone_nwif_address, 38637c478bd9Sstevel@tonic-gate sizeof (tmp_nwiftab.zone_nwif_address)); 38647c478bd9Sstevel@tonic-gate if (zonecfg_lookup_nwif(handle, &tmp_nwiftab) == 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_NET), pt_to_str(PT_ADDRESS), 38687c478bd9Sstevel@tonic-gate in_progress_nwiftab.zone_nwif_address); 38697c478bd9Sstevel@tonic-gate saw_error = TRUE; 38707c478bd9Sstevel@tonic-gate return; 38717c478bd9Sstevel@tonic-gate } 38727c478bd9Sstevel@tonic-gate err = zonecfg_add_nwif(handle, &in_progress_nwiftab); 38737c478bd9Sstevel@tonic-gate } else { 38747c478bd9Sstevel@tonic-gate err = zonecfg_modify_nwif(handle, &old_nwiftab, 38757c478bd9Sstevel@tonic-gate &in_progress_nwiftab); 38767c478bd9Sstevel@tonic-gate } 38777c478bd9Sstevel@tonic-gate break; 3878087719fdSdp 38797c478bd9Sstevel@tonic-gate case RT_DEVICE: 38807c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 3881087719fdSdp (void) end_check_reqd(in_progress_devtab.zone_dev_match, 3882087719fdSdp PT_MATCH, &validation_failed); 3883087719fdSdp 3884087719fdSdp if (validation_failed) { 38857c478bd9Sstevel@tonic-gate saw_error = TRUE; 38867c478bd9Sstevel@tonic-gate return; 3887087719fdSdp } 3888087719fdSdp 38897c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 38907c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 38917c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_devtab.zone_dev_match, 38927c478bd9Sstevel@tonic-gate in_progress_devtab.zone_dev_match, 38937c478bd9Sstevel@tonic-gate sizeof (tmp_devtab.zone_dev_match)); 38947c478bd9Sstevel@tonic-gate if (zonecfg_lookup_dev(handle, &tmp_devtab) == Z_OK) { 38957c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource with the %s '%s' " 38967c478bd9Sstevel@tonic-gate "already exists."), rt_to_str(RT_DEVICE), 38977c478bd9Sstevel@tonic-gate pt_to_str(PT_MATCH), 38987c478bd9Sstevel@tonic-gate in_progress_devtab.zone_dev_match); 38997c478bd9Sstevel@tonic-gate saw_error = TRUE; 39007c478bd9Sstevel@tonic-gate return; 39017c478bd9Sstevel@tonic-gate } 39027c478bd9Sstevel@tonic-gate err = zonecfg_add_dev(handle, &in_progress_devtab); 39037c478bd9Sstevel@tonic-gate } else { 39047c478bd9Sstevel@tonic-gate err = zonecfg_modify_dev(handle, &old_devtab, 39057c478bd9Sstevel@tonic-gate &in_progress_devtab); 39067c478bd9Sstevel@tonic-gate } 39077c478bd9Sstevel@tonic-gate break; 3908087719fdSdp 39097c478bd9Sstevel@tonic-gate case RT_RCTL: 39107c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 3911087719fdSdp (void) end_check_reqd(in_progress_rctltab.zone_rctl_name, 3912087719fdSdp PT_NAME, &validation_failed); 3913087719fdSdp 39147c478bd9Sstevel@tonic-gate if (in_progress_rctltab.zone_rctl_valptr == NULL) { 39157c478bd9Sstevel@tonic-gate zerr(gettext("no %s specified"), pt_to_str(PT_VALUE)); 39167c478bd9Sstevel@tonic-gate validation_failed = TRUE; 39177c478bd9Sstevel@tonic-gate } 3918087719fdSdp 3919087719fdSdp if (validation_failed) { 3920087719fdSdp saw_error = TRUE; 39217c478bd9Sstevel@tonic-gate return; 3922087719fdSdp } 3923087719fdSdp 39247c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 39257c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 39267c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_rctltab.zone_rctl_name, 39277c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_name, 39287c478bd9Sstevel@tonic-gate sizeof (tmp_rctltab.zone_rctl_name)); 39297c478bd9Sstevel@tonic-gate tmp_rctltab.zone_rctl_valptr = NULL; 39307c478bd9Sstevel@tonic-gate err = zonecfg_lookup_rctl(handle, &tmp_rctltab); 39317c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list( 39327c478bd9Sstevel@tonic-gate tmp_rctltab.zone_rctl_valptr); 39337c478bd9Sstevel@tonic-gate if (err == Z_OK) { 39347c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource " 39357c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 39367c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL), pt_to_str(PT_NAME), 39377c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_name); 39387c478bd9Sstevel@tonic-gate saw_error = TRUE; 39397c478bd9Sstevel@tonic-gate return; 39407c478bd9Sstevel@tonic-gate } 39417c478bd9Sstevel@tonic-gate err = zonecfg_add_rctl(handle, &in_progress_rctltab); 39427c478bd9Sstevel@tonic-gate } else { 39437c478bd9Sstevel@tonic-gate err = zonecfg_modify_rctl(handle, &old_rctltab, 39447c478bd9Sstevel@tonic-gate &in_progress_rctltab); 39457c478bd9Sstevel@tonic-gate } 39467c478bd9Sstevel@tonic-gate if (err == Z_OK) { 39477c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list( 39487c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr); 39497c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr = NULL; 39507c478bd9Sstevel@tonic-gate } 39517c478bd9Sstevel@tonic-gate break; 3952087719fdSdp 39537c478bd9Sstevel@tonic-gate case RT_ATTR: 39547c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 3955087719fdSdp (void) end_check_reqd(in_progress_attrtab.zone_attr_name, 3956087719fdSdp PT_NAME, &validation_failed); 3957087719fdSdp (void) end_check_reqd(in_progress_attrtab.zone_attr_type, 3958087719fdSdp PT_TYPE, &validation_failed); 3959087719fdSdp (void) end_check_reqd(in_progress_attrtab.zone_attr_value, 3960087719fdSdp PT_VALUE, &validation_failed); 3961087719fdSdp 39627c478bd9Sstevel@tonic-gate if (validate_attr_name(in_progress_attrtab.zone_attr_name) != 3963087719fdSdp Z_OK) 39647c478bd9Sstevel@tonic-gate validation_failed = TRUE; 3965087719fdSdp 3966087719fdSdp if (validate_attr_type_val(&in_progress_attrtab) != Z_OK) 39677c478bd9Sstevel@tonic-gate validation_failed = TRUE; 3968087719fdSdp 3969087719fdSdp if (validation_failed) { 3970087719fdSdp saw_error = TRUE; 39717c478bd9Sstevel@tonic-gate return; 3972087719fdSdp } 39737c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 39747c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 39757c478bd9Sstevel@tonic-gate bzero(&tmp_attrtab, sizeof (tmp_attrtab)); 39767c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_attrtab.zone_attr_name, 39777c478bd9Sstevel@tonic-gate in_progress_attrtab.zone_attr_name, 39787c478bd9Sstevel@tonic-gate sizeof (tmp_attrtab.zone_attr_name)); 39797c478bd9Sstevel@tonic-gate if (zonecfg_lookup_attr(handle, &tmp_attrtab) == Z_OK) { 39807c478bd9Sstevel@tonic-gate zerr(gettext("An %s resource " 39817c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 39827c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_NAME), 39837c478bd9Sstevel@tonic-gate in_progress_attrtab.zone_attr_name); 39847c478bd9Sstevel@tonic-gate saw_error = TRUE; 39857c478bd9Sstevel@tonic-gate return; 39867c478bd9Sstevel@tonic-gate } 39877c478bd9Sstevel@tonic-gate err = zonecfg_add_attr(handle, &in_progress_attrtab); 39887c478bd9Sstevel@tonic-gate } else { 39897c478bd9Sstevel@tonic-gate err = zonecfg_modify_attr(handle, &old_attrtab, 39907c478bd9Sstevel@tonic-gate &in_progress_attrtab); 39917c478bd9Sstevel@tonic-gate } 39927c478bd9Sstevel@tonic-gate break; 3993fa9e4066Sahrens case RT_DATASET: 3994fa9e4066Sahrens /* First make sure everything was filled in. */ 3995fa9e4066Sahrens if (strlen(in_progress_dstab.zone_dataset_name) == 0) { 3996fa9e4066Sahrens zerr("%s %s", pt_to_str(PT_NAME), 3997fa9e4066Sahrens gettext("not specified")); 3998fa9e4066Sahrens saw_error = TRUE; 3999fa9e4066Sahrens validation_failed = TRUE; 4000fa9e4066Sahrens } 4001fa9e4066Sahrens if (validation_failed) 4002fa9e4066Sahrens return; 4003fa9e4066Sahrens if (end_op == CMD_ADD) { 4004fa9e4066Sahrens /* Make sure there isn't already one like this. */ 4005fa9e4066Sahrens bzero(&tmp_dstab, sizeof (tmp_dstab)); 4006fa9e4066Sahrens (void) strlcpy(tmp_dstab.zone_dataset_name, 4007fa9e4066Sahrens in_progress_dstab.zone_dataset_name, 4008fa9e4066Sahrens sizeof (tmp_dstab.zone_dataset_name)); 4009fa9e4066Sahrens err = zonecfg_lookup_ds(handle, &tmp_dstab); 4010fa9e4066Sahrens if (err == Z_OK) { 4011fa9e4066Sahrens zerr(gettext("A %s resource " 4012fa9e4066Sahrens "with the %s '%s' already exists."), 4013fa9e4066Sahrens rt_to_str(RT_DATASET), pt_to_str(PT_NAME), 4014fa9e4066Sahrens in_progress_dstab.zone_dataset_name); 4015fa9e4066Sahrens saw_error = TRUE; 4016fa9e4066Sahrens return; 4017fa9e4066Sahrens } 4018fa9e4066Sahrens err = zonecfg_add_ds(handle, &in_progress_dstab); 4019fa9e4066Sahrens } else { 4020fa9e4066Sahrens err = zonecfg_modify_ds(handle, &old_dstab, 4021fa9e4066Sahrens &in_progress_dstab); 4022fa9e4066Sahrens } 4023fa9e4066Sahrens break; 40247c478bd9Sstevel@tonic-gate default: 40257c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(resource_scope), Z_NO_RESOURCE_TYPE, 40267c478bd9Sstevel@tonic-gate TRUE); 40277c478bd9Sstevel@tonic-gate saw_error = TRUE; 40287c478bd9Sstevel@tonic-gate return; 40297c478bd9Sstevel@tonic-gate } 40307c478bd9Sstevel@tonic-gate 40317c478bd9Sstevel@tonic-gate if (err != Z_OK) { 40327c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 40337c478bd9Sstevel@tonic-gate } else { 40347c478bd9Sstevel@tonic-gate need_to_commit = TRUE; 40357c478bd9Sstevel@tonic-gate global_scope = TRUE; 40367c478bd9Sstevel@tonic-gate end_op = -1; 40377c478bd9Sstevel@tonic-gate } 40387c478bd9Sstevel@tonic-gate } 40397c478bd9Sstevel@tonic-gate 40407c478bd9Sstevel@tonic-gate void 40417c478bd9Sstevel@tonic-gate commit_func(cmd_t *cmd) 40427c478bd9Sstevel@tonic-gate { 40437c478bd9Sstevel@tonic-gate int arg; 40447c478bd9Sstevel@tonic-gate 40457c478bd9Sstevel@tonic-gate optind = 0; 40467c478bd9Sstevel@tonic-gate if ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 40477c478bd9Sstevel@tonic-gate switch (arg) { 40487c478bd9Sstevel@tonic-gate case '?': 40497c478bd9Sstevel@tonic-gate longer_usage(CMD_COMMIT); 40507c478bd9Sstevel@tonic-gate return; 40517c478bd9Sstevel@tonic-gate default: 40527c478bd9Sstevel@tonic-gate short_usage(CMD_COMMIT); 40537c478bd9Sstevel@tonic-gate return; 40547c478bd9Sstevel@tonic-gate } 40557c478bd9Sstevel@tonic-gate } 40567c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 40577c478bd9Sstevel@tonic-gate short_usage(CMD_COMMIT); 40587c478bd9Sstevel@tonic-gate return; 40597c478bd9Sstevel@tonic-gate } 40607c478bd9Sstevel@tonic-gate 40617c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_COMMIT)) 40627c478bd9Sstevel@tonic-gate return; 40637c478bd9Sstevel@tonic-gate 40647c478bd9Sstevel@tonic-gate assert(cmd != NULL); 40657c478bd9Sstevel@tonic-gate 40667c478bd9Sstevel@tonic-gate cmd->cmd_argc = 1; 40677c478bd9Sstevel@tonic-gate /* 40687c478bd9Sstevel@tonic-gate * cmd_arg normally comes from a strdup() in the lexer, and the 40697c478bd9Sstevel@tonic-gate * whole cmd structure and its (char *) attributes are freed at 40707c478bd9Sstevel@tonic-gate * the completion of each command, so the strdup() below is needed 40717c478bd9Sstevel@tonic-gate * to match this and prevent a core dump from trying to free() 40727c478bd9Sstevel@tonic-gate * something that can't be. 40737c478bd9Sstevel@tonic-gate */ 40747c478bd9Sstevel@tonic-gate if ((cmd->cmd_argv[0] = strdup("save")) == NULL) { 40757c478bd9Sstevel@tonic-gate zone_perror(zone, Z_NOMEM, TRUE); 40767c478bd9Sstevel@tonic-gate exit(Z_ERR); 40777c478bd9Sstevel@tonic-gate } 40787c478bd9Sstevel@tonic-gate cmd->cmd_argv[1] = NULL; 40797c478bd9Sstevel@tonic-gate verify_func(cmd); 40807c478bd9Sstevel@tonic-gate } 40817c478bd9Sstevel@tonic-gate 40827c478bd9Sstevel@tonic-gate void 40837c478bd9Sstevel@tonic-gate revert_func(cmd_t *cmd) 40847c478bd9Sstevel@tonic-gate { 40857c478bd9Sstevel@tonic-gate char line[128]; /* enough to ask a question */ 40867c478bd9Sstevel@tonic-gate bool force = FALSE; 40877c478bd9Sstevel@tonic-gate int err, arg, answer; 40887c478bd9Sstevel@tonic-gate 40897c478bd9Sstevel@tonic-gate optind = 0; 40907c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 40917c478bd9Sstevel@tonic-gate switch (arg) { 40927c478bd9Sstevel@tonic-gate case '?': 40937c478bd9Sstevel@tonic-gate longer_usage(CMD_REVERT); 40947c478bd9Sstevel@tonic-gate return; 40957c478bd9Sstevel@tonic-gate case 'F': 40967c478bd9Sstevel@tonic-gate force = TRUE; 40977c478bd9Sstevel@tonic-gate break; 40987c478bd9Sstevel@tonic-gate default: 40997c478bd9Sstevel@tonic-gate short_usage(CMD_REVERT); 41007c478bd9Sstevel@tonic-gate return; 41017c478bd9Sstevel@tonic-gate } 41027c478bd9Sstevel@tonic-gate } 41037c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 41047c478bd9Sstevel@tonic-gate short_usage(CMD_REVERT); 41057c478bd9Sstevel@tonic-gate return; 41067c478bd9Sstevel@tonic-gate } 41077c478bd9Sstevel@tonic-gate 41087c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_REVERT)) 41097c478bd9Sstevel@tonic-gate return; 41107c478bd9Sstevel@tonic-gate 41117c478bd9Sstevel@tonic-gate if (zonecfg_check_handle(handle) != Z_OK) { 41127c478bd9Sstevel@tonic-gate zerr(gettext("No changes to revert.")); 41137c478bd9Sstevel@tonic-gate saw_error = TRUE; 41147c478bd9Sstevel@tonic-gate return; 41157c478bd9Sstevel@tonic-gate } 41167c478bd9Sstevel@tonic-gate 41177c478bd9Sstevel@tonic-gate if (!force) { 41187c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 41197c478bd9Sstevel@tonic-gate gettext("Are you sure you want to revert")); 41207c478bd9Sstevel@tonic-gate if ((answer = ask_yesno(FALSE, line)) == -1) { 41217c478bd9Sstevel@tonic-gate zerr(gettext("Input not from terminal and -F not " 41227c478bd9Sstevel@tonic-gate "specified:\n%s command ignored, exiting."), 41237c478bd9Sstevel@tonic-gate cmd_to_str(CMD_REVERT)); 41247c478bd9Sstevel@tonic-gate exit(Z_ERR); 41257c478bd9Sstevel@tonic-gate } 41267c478bd9Sstevel@tonic-gate if (answer != 1) 41277c478bd9Sstevel@tonic-gate return; 41287c478bd9Sstevel@tonic-gate } 41297c478bd9Sstevel@tonic-gate 41307c478bd9Sstevel@tonic-gate /* 41317c478bd9Sstevel@tonic-gate * Time for a new handle: finish the old one off first 41327c478bd9Sstevel@tonic-gate * then get a new one properly to avoid leaks. 41337c478bd9Sstevel@tonic-gate */ 41347c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 41357c478bd9Sstevel@tonic-gate if ((handle = zonecfg_init_handle()) == NULL) { 41367c478bd9Sstevel@tonic-gate zone_perror(execname, Z_NOMEM, TRUE); 41377c478bd9Sstevel@tonic-gate exit(Z_ERR); 41387c478bd9Sstevel@tonic-gate } 4139087719fdSdp if ((err = zonecfg_get_handle(revert_zone, handle)) != Z_OK) { 41407c478bd9Sstevel@tonic-gate saw_error = TRUE; 41417c478bd9Sstevel@tonic-gate got_handle = FALSE; 41427c478bd9Sstevel@tonic-gate if (err == Z_NO_ZONE) 41437c478bd9Sstevel@tonic-gate zerr(gettext("%s: no such saved zone to revert to."), 4144087719fdSdp revert_zone); 41457c478bd9Sstevel@tonic-gate else 41467c478bd9Sstevel@tonic-gate zone_perror(zone, err, TRUE); 41477c478bd9Sstevel@tonic-gate } 4148087719fdSdp (void) strlcpy(zone, revert_zone, sizeof (zone)); 41497c478bd9Sstevel@tonic-gate } 41507c478bd9Sstevel@tonic-gate 41517c478bd9Sstevel@tonic-gate void 41527c478bd9Sstevel@tonic-gate help_func(cmd_t *cmd) 41537c478bd9Sstevel@tonic-gate { 41547c478bd9Sstevel@tonic-gate int i; 41557c478bd9Sstevel@tonic-gate 41567c478bd9Sstevel@tonic-gate assert(cmd != NULL); 41577c478bd9Sstevel@tonic-gate 41587c478bd9Sstevel@tonic-gate if (cmd->cmd_argc == 0) { 41597c478bd9Sstevel@tonic-gate usage(TRUE, global_scope ? HELP_SUBCMDS : HELP_RES_SCOPE); 41607c478bd9Sstevel@tonic-gate return; 41617c478bd9Sstevel@tonic-gate } 41627c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "usage") == 0) { 41637c478bd9Sstevel@tonic-gate usage(TRUE, HELP_USAGE); 41647c478bd9Sstevel@tonic-gate return; 41657c478bd9Sstevel@tonic-gate } 41667c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "commands") == 0) { 41677c478bd9Sstevel@tonic-gate usage(TRUE, HELP_SUBCMDS); 41687c478bd9Sstevel@tonic-gate return; 41697c478bd9Sstevel@tonic-gate } 41707c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "syntax") == 0) { 41717c478bd9Sstevel@tonic-gate usage(TRUE, HELP_SYNTAX | HELP_RES_PROPS); 41727c478bd9Sstevel@tonic-gate return; 41737c478bd9Sstevel@tonic-gate } 41747c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "-?") == 0) { 41757c478bd9Sstevel@tonic-gate longer_usage(CMD_HELP); 41767c478bd9Sstevel@tonic-gate return; 41777c478bd9Sstevel@tonic-gate } 41787c478bd9Sstevel@tonic-gate 41797c478bd9Sstevel@tonic-gate for (i = 0; i <= CMD_MAX; i++) { 41807c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], cmd_to_str(i)) == 0) { 41817c478bd9Sstevel@tonic-gate longer_usage(i); 41827c478bd9Sstevel@tonic-gate return; 41837c478bd9Sstevel@tonic-gate } 41847c478bd9Sstevel@tonic-gate } 41857c478bd9Sstevel@tonic-gate /* We do not use zerr() here because we do not want its extra \n. */ 41867c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Unknown help subject %s. "), 41877c478bd9Sstevel@tonic-gate cmd->cmd_argv[0]); 41887c478bd9Sstevel@tonic-gate usage(FALSE, HELP_META); 41897c478bd9Sstevel@tonic-gate } 41907c478bd9Sstevel@tonic-gate 41917c478bd9Sstevel@tonic-gate static int 41927c478bd9Sstevel@tonic-gate string_to_yyin(char *string) 41937c478bd9Sstevel@tonic-gate { 41947c478bd9Sstevel@tonic-gate if ((yyin = tmpfile()) == NULL) { 41957c478bd9Sstevel@tonic-gate zone_perror(execname, Z_TEMP_FILE, TRUE); 41967c478bd9Sstevel@tonic-gate return (Z_ERR); 41977c478bd9Sstevel@tonic-gate } 41987c478bd9Sstevel@tonic-gate if (fwrite(string, strlen(string), 1, yyin) != 1) { 41997c478bd9Sstevel@tonic-gate zone_perror(execname, Z_TEMP_FILE, TRUE); 42007c478bd9Sstevel@tonic-gate return (Z_ERR); 42017c478bd9Sstevel@tonic-gate } 42027c478bd9Sstevel@tonic-gate if (fseek(yyin, 0, SEEK_SET) != 0) { 42037c478bd9Sstevel@tonic-gate zone_perror(execname, Z_TEMP_FILE, TRUE); 42047c478bd9Sstevel@tonic-gate return (Z_ERR); 42057c478bd9Sstevel@tonic-gate } 42067c478bd9Sstevel@tonic-gate return (Z_OK); 42077c478bd9Sstevel@tonic-gate } 42087c478bd9Sstevel@tonic-gate 42097c478bd9Sstevel@tonic-gate /* This is the back-end helper function for read_input() below. */ 42107c478bd9Sstevel@tonic-gate 42117c478bd9Sstevel@tonic-gate static int 42127c478bd9Sstevel@tonic-gate cleanup() 42137c478bd9Sstevel@tonic-gate { 42147c478bd9Sstevel@tonic-gate int answer; 42157c478bd9Sstevel@tonic-gate cmd_t *cmd; 42167c478bd9Sstevel@tonic-gate 42177c478bd9Sstevel@tonic-gate if (!interactive_mode && !cmd_file_mode) { 42187c478bd9Sstevel@tonic-gate /* 42197c478bd9Sstevel@tonic-gate * If we're not in interactive mode, and we're not in command 42207c478bd9Sstevel@tonic-gate * file mode, then we must be in commands-from-the-command-line 42217c478bd9Sstevel@tonic-gate * mode. As such, we can't loop back and ask for more input. 42227c478bd9Sstevel@tonic-gate * It was OK to prompt for such things as whether or not to 42237c478bd9Sstevel@tonic-gate * really delete a zone in the command handler called from 42247c478bd9Sstevel@tonic-gate * yyparse() above, but "really quit?" makes no sense in this 42257c478bd9Sstevel@tonic-gate * context. So disable prompting. 42267c478bd9Sstevel@tonic-gate */ 42277c478bd9Sstevel@tonic-gate ok_to_prompt = FALSE; 42287c478bd9Sstevel@tonic-gate } 42297c478bd9Sstevel@tonic-gate if (!global_scope) { 42307c478bd9Sstevel@tonic-gate if (!time_to_exit) { 42317c478bd9Sstevel@tonic-gate /* 42327c478bd9Sstevel@tonic-gate * Just print a simple error message in the -1 case, 42337c478bd9Sstevel@tonic-gate * since exit_func() already handles that case, and 42347c478bd9Sstevel@tonic-gate * EOF means we are finished anyway. 42357c478bd9Sstevel@tonic-gate */ 42367c478bd9Sstevel@tonic-gate answer = ask_yesno(FALSE, 42377c478bd9Sstevel@tonic-gate gettext("Resource incomplete; really quit")); 42387c478bd9Sstevel@tonic-gate if (answer == -1) { 42397c478bd9Sstevel@tonic-gate zerr(gettext("Resource incomplete.")); 42407c478bd9Sstevel@tonic-gate return (Z_ERR); 42417c478bd9Sstevel@tonic-gate } 42427c478bd9Sstevel@tonic-gate if (answer != 1) { 42437c478bd9Sstevel@tonic-gate yyin = stdin; 42447c478bd9Sstevel@tonic-gate return (Z_REPEAT); 42457c478bd9Sstevel@tonic-gate } 42467c478bd9Sstevel@tonic-gate } else { 42477c478bd9Sstevel@tonic-gate saw_error = TRUE; 42487c478bd9Sstevel@tonic-gate } 42497c478bd9Sstevel@tonic-gate } 42507c478bd9Sstevel@tonic-gate /* 42517c478bd9Sstevel@tonic-gate * Make sure we tried something and that the handle checks 42527c478bd9Sstevel@tonic-gate * out, or we would get a false error trying to commit. 42537c478bd9Sstevel@tonic-gate */ 42547c478bd9Sstevel@tonic-gate if (need_to_commit && zonecfg_check_handle(handle) == Z_OK) { 42557c478bd9Sstevel@tonic-gate if ((cmd = alloc_cmd()) == NULL) { 42567c478bd9Sstevel@tonic-gate zone_perror(zone, Z_NOMEM, TRUE); 42577c478bd9Sstevel@tonic-gate return (Z_ERR); 42587c478bd9Sstevel@tonic-gate } 42597c478bd9Sstevel@tonic-gate cmd->cmd_argc = 0; 42607c478bd9Sstevel@tonic-gate cmd->cmd_argv[0] = NULL; 42617c478bd9Sstevel@tonic-gate commit_func(cmd); 42627c478bd9Sstevel@tonic-gate free_cmd(cmd); 42637c478bd9Sstevel@tonic-gate /* 42647c478bd9Sstevel@tonic-gate * need_to_commit will get set back to FALSE if the 42657c478bd9Sstevel@tonic-gate * configuration is saved successfully. 42667c478bd9Sstevel@tonic-gate */ 42677c478bd9Sstevel@tonic-gate if (need_to_commit) { 42687c478bd9Sstevel@tonic-gate if (force_exit) { 42697c478bd9Sstevel@tonic-gate zerr(gettext("Configuration not saved.")); 42707c478bd9Sstevel@tonic-gate return (Z_ERR); 42717c478bd9Sstevel@tonic-gate } 42727c478bd9Sstevel@tonic-gate answer = ask_yesno(FALSE, 42737c478bd9Sstevel@tonic-gate gettext("Configuration not saved; really quit")); 42747c478bd9Sstevel@tonic-gate if (answer == -1) { 42757c478bd9Sstevel@tonic-gate zerr(gettext("Configuration not saved.")); 42767c478bd9Sstevel@tonic-gate return (Z_ERR); 42777c478bd9Sstevel@tonic-gate } 42787c478bd9Sstevel@tonic-gate if (answer != 1) { 42797c478bd9Sstevel@tonic-gate time_to_exit = FALSE; 42807c478bd9Sstevel@tonic-gate yyin = stdin; 42817c478bd9Sstevel@tonic-gate return (Z_REPEAT); 42827c478bd9Sstevel@tonic-gate } 42837c478bd9Sstevel@tonic-gate } 42847c478bd9Sstevel@tonic-gate } 42857c478bd9Sstevel@tonic-gate return ((need_to_commit || saw_error) ? Z_ERR : Z_OK); 42867c478bd9Sstevel@tonic-gate } 42877c478bd9Sstevel@tonic-gate 42887c478bd9Sstevel@tonic-gate /* 42897c478bd9Sstevel@tonic-gate * read_input() is the driver of this program. It is a wrapper around 42907c478bd9Sstevel@tonic-gate * yyparse(), printing appropriate prompts when needed, checking for 42917c478bd9Sstevel@tonic-gate * exit conditions and reacting appropriately [the latter in its cleanup() 42927c478bd9Sstevel@tonic-gate * helper function]. 42937c478bd9Sstevel@tonic-gate * 42947c478bd9Sstevel@tonic-gate * Like most zonecfg functions, it returns Z_OK or Z_ERR, *or* Z_REPEAT 42957c478bd9Sstevel@tonic-gate * so do_interactive() knows that we are not really done (i.e, we asked 42967c478bd9Sstevel@tonic-gate * the user if we should really quit and the user said no). 42977c478bd9Sstevel@tonic-gate */ 42987c478bd9Sstevel@tonic-gate static int 42997c478bd9Sstevel@tonic-gate read_input() 43007c478bd9Sstevel@tonic-gate { 43017c478bd9Sstevel@tonic-gate bool yyin_is_a_tty = isatty(fileno(yyin)); 43027c478bd9Sstevel@tonic-gate /* 43037c478bd9Sstevel@tonic-gate * The prompt is "e:z> " or "e:z:r> " where e is execname, z is zone 43047c478bd9Sstevel@tonic-gate * and r is resource_scope: 5 is for the two ":"s + "> " + terminator. 43057c478bd9Sstevel@tonic-gate */ 43067c478bd9Sstevel@tonic-gate char prompt[MAXPATHLEN + ZONENAME_MAX + MAX_RT_STRLEN + 5], *line; 43077c478bd9Sstevel@tonic-gate 43087c478bd9Sstevel@tonic-gate /* yyin should have been set to the appropriate (FILE *) if not stdin */ 43097c478bd9Sstevel@tonic-gate newline_terminated = TRUE; 43107c478bd9Sstevel@tonic-gate for (;;) { 43117c478bd9Sstevel@tonic-gate if (yyin_is_a_tty) { 43127c478bd9Sstevel@tonic-gate if (newline_terminated) { 43137c478bd9Sstevel@tonic-gate if (global_scope) 43147c478bd9Sstevel@tonic-gate (void) snprintf(prompt, sizeof (prompt), 43157c478bd9Sstevel@tonic-gate "%s:%s> ", execname, zone); 43167c478bd9Sstevel@tonic-gate else 43177c478bd9Sstevel@tonic-gate (void) snprintf(prompt, sizeof (prompt), 43187c478bd9Sstevel@tonic-gate "%s:%s:%s> ", execname, zone, 43197c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 43207c478bd9Sstevel@tonic-gate } 43217c478bd9Sstevel@tonic-gate /* 43227c478bd9Sstevel@tonic-gate * If the user hits ^C then we want to catch it and 43237c478bd9Sstevel@tonic-gate * start over. If the user hits EOF then we want to 43247c478bd9Sstevel@tonic-gate * bail out. 43257c478bd9Sstevel@tonic-gate */ 43267c478bd9Sstevel@tonic-gate line = gl_get_line(gl, prompt, NULL, -1); 43277c478bd9Sstevel@tonic-gate if (gl_return_status(gl) == GLR_SIGNAL) { 43287c478bd9Sstevel@tonic-gate gl_abandon_line(gl); 43297c478bd9Sstevel@tonic-gate continue; 43307c478bd9Sstevel@tonic-gate } 43317c478bd9Sstevel@tonic-gate if (line == NULL) 43327c478bd9Sstevel@tonic-gate break; 43337c478bd9Sstevel@tonic-gate (void) string_to_yyin(line); 43347c478bd9Sstevel@tonic-gate while (!feof(yyin)) 43357c478bd9Sstevel@tonic-gate yyparse(); 43367c478bd9Sstevel@tonic-gate } else { 43377c478bd9Sstevel@tonic-gate yyparse(); 43387c478bd9Sstevel@tonic-gate } 43397c478bd9Sstevel@tonic-gate /* Bail out on an error in command file mode. */ 43407c478bd9Sstevel@tonic-gate if (saw_error && cmd_file_mode && !interactive_mode) 43417c478bd9Sstevel@tonic-gate time_to_exit = TRUE; 43427c478bd9Sstevel@tonic-gate if (time_to_exit || (!yyin_is_a_tty && feof(yyin))) 43437c478bd9Sstevel@tonic-gate break; 43447c478bd9Sstevel@tonic-gate } 43457c478bd9Sstevel@tonic-gate return (cleanup()); 43467c478bd9Sstevel@tonic-gate } 43477c478bd9Sstevel@tonic-gate 43487c478bd9Sstevel@tonic-gate /* 43497c478bd9Sstevel@tonic-gate * This function is used in the zonecfg-interactive-mode scenario: it just 43507c478bd9Sstevel@tonic-gate * calls read_input() until we are done. 43517c478bd9Sstevel@tonic-gate */ 43527c478bd9Sstevel@tonic-gate 43537c478bd9Sstevel@tonic-gate static int 43547c478bd9Sstevel@tonic-gate do_interactive(void) 43557c478bd9Sstevel@tonic-gate { 43567c478bd9Sstevel@tonic-gate int err; 43577c478bd9Sstevel@tonic-gate 43587c478bd9Sstevel@tonic-gate interactive_mode = TRUE; 43597c478bd9Sstevel@tonic-gate if (!read_only_mode) { 43607c478bd9Sstevel@tonic-gate /* 43617c478bd9Sstevel@tonic-gate * Try to set things up proactively in interactive mode, so 43627c478bd9Sstevel@tonic-gate * that if the zone in question does not exist yet, we can 43637c478bd9Sstevel@tonic-gate * provide the user with a clue. 43647c478bd9Sstevel@tonic-gate */ 43657c478bd9Sstevel@tonic-gate (void) initialize(FALSE); 43667c478bd9Sstevel@tonic-gate } 4367087719fdSdp do { 43687c478bd9Sstevel@tonic-gate err = read_input(); 4369087719fdSdp } while (err == Z_REPEAT); 43707c478bd9Sstevel@tonic-gate return (err); 43717c478bd9Sstevel@tonic-gate } 43727c478bd9Sstevel@tonic-gate 43737c478bd9Sstevel@tonic-gate /* 43747c478bd9Sstevel@tonic-gate * cmd_file is slightly more complicated, as it has to open the command file 43757c478bd9Sstevel@tonic-gate * and set yyin appropriately. Once that is done, though, it just calls 43767c478bd9Sstevel@tonic-gate * read_input(), and only once, since prompting is not possible. 43777c478bd9Sstevel@tonic-gate */ 43787c478bd9Sstevel@tonic-gate 43797c478bd9Sstevel@tonic-gate static int 43807c478bd9Sstevel@tonic-gate cmd_file(char *file) 43817c478bd9Sstevel@tonic-gate { 43827c478bd9Sstevel@tonic-gate FILE *infile; 43837c478bd9Sstevel@tonic-gate int err; 43847c478bd9Sstevel@tonic-gate struct stat statbuf; 43857c478bd9Sstevel@tonic-gate bool using_real_file = (strcmp(file, "-") != 0); 43867c478bd9Sstevel@tonic-gate 43877c478bd9Sstevel@tonic-gate if (using_real_file) { 43887c478bd9Sstevel@tonic-gate /* 43897c478bd9Sstevel@tonic-gate * zerr() prints a line number in cmd_file_mode, which we do 43907c478bd9Sstevel@tonic-gate * not want here, so temporarily unset it. 43917c478bd9Sstevel@tonic-gate */ 43927c478bd9Sstevel@tonic-gate cmd_file_mode = FALSE; 43937c478bd9Sstevel@tonic-gate if ((infile = fopen(file, "r")) == NULL) { 43947c478bd9Sstevel@tonic-gate zerr(gettext("could not open file %s: %s"), 43957c478bd9Sstevel@tonic-gate file, strerror(errno)); 43967c478bd9Sstevel@tonic-gate return (Z_ERR); 43977c478bd9Sstevel@tonic-gate } 43987c478bd9Sstevel@tonic-gate if ((err = fstat(fileno(infile), &statbuf)) != 0) { 43997c478bd9Sstevel@tonic-gate zerr(gettext("could not stat file %s: %s"), 44007c478bd9Sstevel@tonic-gate file, strerror(errno)); 44017c478bd9Sstevel@tonic-gate err = Z_ERR; 44027c478bd9Sstevel@tonic-gate goto done; 44037c478bd9Sstevel@tonic-gate } 44047c478bd9Sstevel@tonic-gate if (!S_ISREG(statbuf.st_mode)) { 44057c478bd9Sstevel@tonic-gate zerr(gettext("%s is not a regular file."), file); 44067c478bd9Sstevel@tonic-gate err = Z_ERR; 44077c478bd9Sstevel@tonic-gate goto done; 44087c478bd9Sstevel@tonic-gate } 44097c478bd9Sstevel@tonic-gate yyin = infile; 44107c478bd9Sstevel@tonic-gate cmd_file_mode = TRUE; 44117c478bd9Sstevel@tonic-gate ok_to_prompt = FALSE; 44127c478bd9Sstevel@tonic-gate } else { 44137c478bd9Sstevel@tonic-gate /* 44147c478bd9Sstevel@tonic-gate * "-f -" is essentially the same as interactive mode, 44157c478bd9Sstevel@tonic-gate * so treat it that way. 44167c478bd9Sstevel@tonic-gate */ 44177c478bd9Sstevel@tonic-gate interactive_mode = TRUE; 44187c478bd9Sstevel@tonic-gate } 44197c478bd9Sstevel@tonic-gate /* Z_REPEAT is for interactive mode; treat it like Z_ERR here. */ 44207c478bd9Sstevel@tonic-gate if ((err = read_input()) == Z_REPEAT) 44217c478bd9Sstevel@tonic-gate err = Z_ERR; 44227c478bd9Sstevel@tonic-gate done: 44237c478bd9Sstevel@tonic-gate if (using_real_file) 44247c478bd9Sstevel@tonic-gate (void) fclose(infile); 44257c478bd9Sstevel@tonic-gate return (err); 44267c478bd9Sstevel@tonic-gate } 44277c478bd9Sstevel@tonic-gate 44287c478bd9Sstevel@tonic-gate /* 44297c478bd9Sstevel@tonic-gate * Since yacc is based on reading from a (FILE *) whereas what we get from 44307c478bd9Sstevel@tonic-gate * the command line is in argv format, we need to convert when the user 44317c478bd9Sstevel@tonic-gate * gives us commands directly from the command line. That is done here by 44327c478bd9Sstevel@tonic-gate * concatenating the argv list into a space-separated string, writing it 44337c478bd9Sstevel@tonic-gate * to a temp file, and rewinding the file so yyin can be set to it. Then 44347c478bd9Sstevel@tonic-gate * we call read_input(), and only once, since prompting about whether to 44357c478bd9Sstevel@tonic-gate * continue or quit would make no sense in this context. 44367c478bd9Sstevel@tonic-gate */ 44377c478bd9Sstevel@tonic-gate 44387c478bd9Sstevel@tonic-gate static int 44397c478bd9Sstevel@tonic-gate one_command_at_a_time(int argc, char *argv[]) 44407c478bd9Sstevel@tonic-gate { 44417c478bd9Sstevel@tonic-gate char *command; 44427c478bd9Sstevel@tonic-gate size_t len = 2; /* terminal \n\0 */ 44437c478bd9Sstevel@tonic-gate int i, err; 44447c478bd9Sstevel@tonic-gate 44457c478bd9Sstevel@tonic-gate for (i = 0; i < argc; i++) 44467c478bd9Sstevel@tonic-gate len += strlen(argv[i]) + 1; 44477c478bd9Sstevel@tonic-gate if ((command = malloc(len)) == NULL) { 44487c478bd9Sstevel@tonic-gate zone_perror(execname, Z_NOMEM, TRUE); 44497c478bd9Sstevel@tonic-gate return (Z_ERR); 44507c478bd9Sstevel@tonic-gate } 44517c478bd9Sstevel@tonic-gate (void) strlcpy(command, argv[0], len); 44527c478bd9Sstevel@tonic-gate for (i = 1; i < argc; i++) { 44537c478bd9Sstevel@tonic-gate (void) strlcat(command, " ", len); 44547c478bd9Sstevel@tonic-gate (void) strlcat(command, argv[i], len); 44557c478bd9Sstevel@tonic-gate } 44567c478bd9Sstevel@tonic-gate (void) strlcat(command, "\n", len); 44577c478bd9Sstevel@tonic-gate err = string_to_yyin(command); 44587c478bd9Sstevel@tonic-gate free(command); 44597c478bd9Sstevel@tonic-gate if (err != Z_OK) 44607c478bd9Sstevel@tonic-gate return (err); 44617c478bd9Sstevel@tonic-gate while (!feof(yyin)) 44627c478bd9Sstevel@tonic-gate yyparse(); 44637c478bd9Sstevel@tonic-gate return (cleanup()); 44647c478bd9Sstevel@tonic-gate } 44657c478bd9Sstevel@tonic-gate 44667c478bd9Sstevel@tonic-gate static char * 44677c478bd9Sstevel@tonic-gate get_execbasename(char *execfullname) 44687c478bd9Sstevel@tonic-gate { 44697c478bd9Sstevel@tonic-gate char *last_slash, *execbasename; 44707c478bd9Sstevel@tonic-gate 44717c478bd9Sstevel@tonic-gate /* guard against '/' at end of command invocation */ 44727c478bd9Sstevel@tonic-gate for (;;) { 44737c478bd9Sstevel@tonic-gate last_slash = strrchr(execfullname, '/'); 44747c478bd9Sstevel@tonic-gate if (last_slash == NULL) { 44757c478bd9Sstevel@tonic-gate execbasename = execfullname; 44767c478bd9Sstevel@tonic-gate break; 44777c478bd9Sstevel@tonic-gate } else { 44787c478bd9Sstevel@tonic-gate execbasename = last_slash + 1; 44797c478bd9Sstevel@tonic-gate if (*execbasename == '\0') { 44807c478bd9Sstevel@tonic-gate *last_slash = '\0'; 44817c478bd9Sstevel@tonic-gate continue; 44827c478bd9Sstevel@tonic-gate } 44837c478bd9Sstevel@tonic-gate break; 44847c478bd9Sstevel@tonic-gate } 44857c478bd9Sstevel@tonic-gate } 44867c478bd9Sstevel@tonic-gate return (execbasename); 44877c478bd9Sstevel@tonic-gate } 44887c478bd9Sstevel@tonic-gate 44897c478bd9Sstevel@tonic-gate int 44907c478bd9Sstevel@tonic-gate main(int argc, char *argv[]) 44917c478bd9Sstevel@tonic-gate { 44927c478bd9Sstevel@tonic-gate int err, arg; 44937c478bd9Sstevel@tonic-gate 44947c478bd9Sstevel@tonic-gate /* This must be before anything goes to stdout. */ 44957c478bd9Sstevel@tonic-gate setbuf(stdout, NULL); 44967c478bd9Sstevel@tonic-gate 44977c478bd9Sstevel@tonic-gate saw_error = FALSE; 44987c478bd9Sstevel@tonic-gate cmd_file_mode = FALSE; 44997c478bd9Sstevel@tonic-gate execname = get_execbasename(argv[0]); 45007c478bd9Sstevel@tonic-gate 45017c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 45027c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 45037c478bd9Sstevel@tonic-gate 45047c478bd9Sstevel@tonic-gate if (getzoneid() != GLOBAL_ZONEID) { 45057c478bd9Sstevel@tonic-gate zerr(gettext("%s can only be run from the global zone."), 45067c478bd9Sstevel@tonic-gate execname); 45077c478bd9Sstevel@tonic-gate exit(Z_ERR); 45087c478bd9Sstevel@tonic-gate } 45097c478bd9Sstevel@tonic-gate 45107c478bd9Sstevel@tonic-gate if (argc < 2) { 45117c478bd9Sstevel@tonic-gate usage(FALSE, HELP_USAGE | HELP_SUBCMDS); 45127c478bd9Sstevel@tonic-gate exit(Z_USAGE); 45137c478bd9Sstevel@tonic-gate } 45147c478bd9Sstevel@tonic-gate if (strcmp(argv[1], cmd_to_str(CMD_HELP)) == 0) { 45157c478bd9Sstevel@tonic-gate (void) one_command_at_a_time(argc - 1, &(argv[1])); 45167c478bd9Sstevel@tonic-gate exit(Z_OK); 45177c478bd9Sstevel@tonic-gate } 45187c478bd9Sstevel@tonic-gate 45197c478bd9Sstevel@tonic-gate while ((arg = getopt(argc, argv, "?f:z:")) != EOF) { 45207c478bd9Sstevel@tonic-gate switch (arg) { 45217c478bd9Sstevel@tonic-gate case '?': 45227c478bd9Sstevel@tonic-gate if (optopt == '?') 45237c478bd9Sstevel@tonic-gate usage(TRUE, HELP_USAGE | HELP_SUBCMDS); 45247c478bd9Sstevel@tonic-gate else 45257c478bd9Sstevel@tonic-gate usage(FALSE, HELP_USAGE); 45267c478bd9Sstevel@tonic-gate exit(Z_USAGE); 45277c478bd9Sstevel@tonic-gate /* NOTREACHED */ 45287c478bd9Sstevel@tonic-gate case 'f': 45297c478bd9Sstevel@tonic-gate cmd_file_name = optarg; 45307c478bd9Sstevel@tonic-gate cmd_file_mode = TRUE; 45317c478bd9Sstevel@tonic-gate break; 45327c478bd9Sstevel@tonic-gate case 'z': 4533087719fdSdp if (zonecfg_validate_zonename(optarg) != Z_OK) { 4534087719fdSdp zone_perror(optarg, Z_BOGUS_ZONE_NAME, TRUE); 4535087719fdSdp usage(FALSE, HELP_SYNTAX); 4536087719fdSdp exit(Z_USAGE); 4537087719fdSdp } 4538087719fdSdp (void) strlcpy(zone, optarg, sizeof (zone)); 4539087719fdSdp (void) strlcpy(revert_zone, optarg, sizeof (zone)); 45407c478bd9Sstevel@tonic-gate break; 45417c478bd9Sstevel@tonic-gate default: 45427c478bd9Sstevel@tonic-gate usage(FALSE, HELP_USAGE); 45437c478bd9Sstevel@tonic-gate exit(Z_USAGE); 45447c478bd9Sstevel@tonic-gate } 45457c478bd9Sstevel@tonic-gate } 45467c478bd9Sstevel@tonic-gate 4547087719fdSdp if (optind > argc || strcmp(zone, "") == 0) { 45487c478bd9Sstevel@tonic-gate usage(FALSE, HELP_USAGE); 45497c478bd9Sstevel@tonic-gate exit(Z_USAGE); 45507c478bd9Sstevel@tonic-gate } 45517c478bd9Sstevel@tonic-gate 4552087719fdSdp if ((err = zonecfg_access(zone, W_OK)) == Z_OK) { 45537c478bd9Sstevel@tonic-gate read_only_mode = FALSE; 4554087719fdSdp } else if (err == Z_ACCES) { 45557c478bd9Sstevel@tonic-gate read_only_mode = TRUE; 45567c478bd9Sstevel@tonic-gate /* skip this message in one-off from command line mode */ 45577c478bd9Sstevel@tonic-gate if (optind == argc) 45587c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("WARNING: you do not " 45597c478bd9Sstevel@tonic-gate "have write access to this zone's configuration " 45607c478bd9Sstevel@tonic-gate "file;\ngoing into read-only mode.\n")); 4561087719fdSdp } else { 4562087719fdSdp fprintf(stderr, "%s: Could not access zone configuration " 4563087719fdSdp "store: %s\n", execname, zonecfg_strerror(err)); 4564087719fdSdp exit(Z_ERR); 45657c478bd9Sstevel@tonic-gate } 45667c478bd9Sstevel@tonic-gate 45677c478bd9Sstevel@tonic-gate if ((handle = zonecfg_init_handle()) == NULL) { 45687c478bd9Sstevel@tonic-gate zone_perror(execname, Z_NOMEM, TRUE); 45697c478bd9Sstevel@tonic-gate exit(Z_ERR); 45707c478bd9Sstevel@tonic-gate } 45717c478bd9Sstevel@tonic-gate 45727c478bd9Sstevel@tonic-gate /* 45737c478bd9Sstevel@tonic-gate * This may get set back to FALSE again in cmd_file() if cmd_file_name 45747c478bd9Sstevel@tonic-gate * is a "real" file as opposed to "-" (i.e. meaning use stdin). 45757c478bd9Sstevel@tonic-gate */ 45767c478bd9Sstevel@tonic-gate if (isatty(STDIN_FILENO)) 45777c478bd9Sstevel@tonic-gate ok_to_prompt = TRUE; 45787c478bd9Sstevel@tonic-gate if ((gl = new_GetLine(MAX_LINE_LEN, MAX_CMD_HIST)) == NULL) 45797c478bd9Sstevel@tonic-gate exit(Z_ERR); 45807c478bd9Sstevel@tonic-gate if (gl_customize_completion(gl, NULL, cmd_cpl_fn) != 0) 45817c478bd9Sstevel@tonic-gate exit(Z_ERR); 45827c478bd9Sstevel@tonic-gate (void) sigset(SIGINT, SIG_IGN); 45837c478bd9Sstevel@tonic-gate if (optind == argc) { 45847c478bd9Sstevel@tonic-gate if (!cmd_file_mode) 45857c478bd9Sstevel@tonic-gate err = do_interactive(); 45867c478bd9Sstevel@tonic-gate else 45877c478bd9Sstevel@tonic-gate err = cmd_file(cmd_file_name); 45887c478bd9Sstevel@tonic-gate } else { 45897c478bd9Sstevel@tonic-gate err = one_command_at_a_time(argc - optind, &(argv[optind])); 45907c478bd9Sstevel@tonic-gate } 45917c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 45927c478bd9Sstevel@tonic-gate (void) del_GetLine(gl); 45937c478bd9Sstevel@tonic-gate return (err); 45947c478bd9Sstevel@tonic-gate } 4595