17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5fb03efaaSdp * Common Development and Distribution License (the "License").
6fb03efaaSdp * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217e362f58Scomay
227c478bd9Sstevel@tonic-gate /*
236d4d1c0dSbatschul * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24f93d2c19SAlexander Eremin * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
25*944b13ecSGary Mills * Copyright 2014 Gary Mills
267c478bd9Sstevel@tonic-gate */
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate * zonecfg is a lex/yacc based command interpreter used to manage zone
307c478bd9Sstevel@tonic-gate * configurations. The lexer (see zonecfg_lex.l) builds up tokens, which
317c478bd9Sstevel@tonic-gate * the grammar (see zonecfg_grammar.y) builds up into commands, some of
327c478bd9Sstevel@tonic-gate * which takes resources and/or properties as arguments. See the block
337c478bd9Sstevel@tonic-gate * comments near the end of zonecfg_grammar.y for how the data structures
347c478bd9Sstevel@tonic-gate * which keep track of these resources and properties are built up.
357c478bd9Sstevel@tonic-gate *
367c478bd9Sstevel@tonic-gate * The resource/property data structures are inserted into a command
377c478bd9Sstevel@tonic-gate * structure (see zonecfg.h), which also keeps track of command names,
387c478bd9Sstevel@tonic-gate * miscellaneous arguments, and function handlers. The grammar selects
397c478bd9Sstevel@tonic-gate * the appropriate function handler, each of which takes a pointer to a
407c478bd9Sstevel@tonic-gate * command structure as its sole argument, and invokes it. The grammar
417c478bd9Sstevel@tonic-gate * itself is "entered" (a la the Matrix) by yyparse(), which is called
427c478bd9Sstevel@tonic-gate * from read_input(), our main driving function. That in turn is called
437c478bd9Sstevel@tonic-gate * by one of do_interactive(), cmd_file() or one_command_at_a_time(), each
447c478bd9Sstevel@tonic-gate * of which is called from main() depending on how the program was invoked.
457c478bd9Sstevel@tonic-gate *
467c478bd9Sstevel@tonic-gate * The rest of this module consists of the various function handlers and
477c478bd9Sstevel@tonic-gate * their helper functions. Some of these functions, particularly the
487c478bd9Sstevel@tonic-gate * X_to_str() functions, which maps command, resource and property numbers
497c478bd9Sstevel@tonic-gate * to strings, are used quite liberally, as doing so results in a better
507c478bd9Sstevel@tonic-gate * program w/rt I18N, reducing the need for translation notes.
517c478bd9Sstevel@tonic-gate */
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate #include <sys/mntent.h>
547c478bd9Sstevel@tonic-gate #include <sys/varargs.h>
557c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate #include <errno.h>
589acbbeafSnn35248 #include <fcntl.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 <signal.h>
729acbbeafSnn35248 #include <wait.h>
737c478bd9Sstevel@tonic-gate #include <libtecla.h>
74fa9e4066Sahrens #include <libzfs.h>
759acbbeafSnn35248 #include <sys/brand.h>
769acbbeafSnn35248 #include <libbrand.h>
775679c89fSjv227347 #include <sys/systeminfo.h>
78c9f134eaSjv227347 #include <libdladm.h>
79c9f134eaSjv227347 #include <libinetutil.h>
80cb8a054bSGlenn Faden #include <pwd.h>
81550b6e40SSowmini Varadhan #include <inet/ip.h>
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate #include <libzonecfg.h>
847c478bd9Sstevel@tonic-gate #include "zonecfg.h"
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) /* should be defined by cc -D */
877c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */
887c478bd9Sstevel@tonic-gate #endif
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate #define PAGER "/usr/bin/more"
919acbbeafSnn35248 #define EXEC_PREFIX "exec "
929acbbeafSnn35248 #define EXEC_LEN (strlen(EXEC_PREFIX))
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate struct help {
957c478bd9Sstevel@tonic-gate uint_t cmd_num;
967c478bd9Sstevel@tonic-gate char *cmd_name;
977c478bd9Sstevel@tonic-gate uint_t flags;
987c478bd9Sstevel@tonic-gate char *short_usage;
997c478bd9Sstevel@tonic-gate };
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate extern int yyparse(void);
1027c478bd9Sstevel@tonic-gate extern int lex_lineno;
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate #define MAX_LINE_LEN 1024
1057c478bd9Sstevel@tonic-gate #define MAX_CMD_HIST 1024
1069acbbeafSnn35248 #define MAX_CMD_LEN 1024
1077c478bd9Sstevel@tonic-gate
1080209230bSgjelinek #define ONE_MB 1048576
1090209230bSgjelinek
1107c478bd9Sstevel@tonic-gate /*
1117c478bd9Sstevel@tonic-gate * Each SHELP_ should be a simple string.
1127c478bd9Sstevel@tonic-gate */
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate #define SHELP_ADD "add <resource-type>\n\t(global scope)\n" \
1157c478bd9Sstevel@tonic-gate "add <property-name> <property-value>\n\t(resource scope)"
1167c478bd9Sstevel@tonic-gate #define SHELP_CANCEL "cancel"
1170209230bSgjelinek #define SHELP_CLEAR "clear <property-name>"
1187c478bd9Sstevel@tonic-gate #define SHELP_COMMIT "commit"
119ee519a1fSgjelinek #define SHELP_CREATE "create [-F] [ -a <path> | -b | -t <template> ]"
1207c478bd9Sstevel@tonic-gate #define SHELP_DELETE "delete [-F]"
1217c478bd9Sstevel@tonic-gate #define SHELP_END "end"
1227c478bd9Sstevel@tonic-gate #define SHELP_EXIT "exit [-F]"
1237c478bd9Sstevel@tonic-gate #define SHELP_EXPORT "export [-f output-file]"
1247c478bd9Sstevel@tonic-gate #define SHELP_HELP "help [commands] [syntax] [usage] [<command-name>]"
1257c478bd9Sstevel@tonic-gate #define SHELP_INFO "info [<resource-type> [property-name=property-value]*]"
1260209230bSgjelinek #define SHELP_REMOVE "remove [-F] <resource-type> " \
1270209230bSgjelinek "[ <property-name>=<property-value> ]*\n" \
1280209230bSgjelinek "\t(global scope)\n" \
1290209230bSgjelinek "remove <property-name> <property-value>\n" \
1300209230bSgjelinek "\t(resource scope)"
1317c478bd9Sstevel@tonic-gate #define SHELP_REVERT "revert [-F]"
1327c478bd9Sstevel@tonic-gate #define SHELP_SELECT "select <resource-type> { <property-name>=" \
1337c478bd9Sstevel@tonic-gate "<property-value> }"
1347c478bd9Sstevel@tonic-gate #define SHELP_SET "set <property-name>=<property-value>"
1357c478bd9Sstevel@tonic-gate #define SHELP_VERIFY "verify"
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate static struct help helptab[] = {
1387c478bd9Sstevel@tonic-gate { CMD_ADD, "add", HELP_RES_PROPS, SHELP_ADD, },
1397c478bd9Sstevel@tonic-gate { CMD_CANCEL, "cancel", 0, SHELP_CANCEL, },
1400209230bSgjelinek { CMD_CLEAR, "clear", HELP_PROPS, SHELP_CLEAR, },
1417c478bd9Sstevel@tonic-gate { CMD_COMMIT, "commit", 0, SHELP_COMMIT, },
1427c478bd9Sstevel@tonic-gate { CMD_CREATE, "create", 0, SHELP_CREATE, },
1437c478bd9Sstevel@tonic-gate { CMD_DELETE, "delete", 0, SHELP_DELETE, },
1447c478bd9Sstevel@tonic-gate { CMD_END, "end", 0, SHELP_END, },
1457c478bd9Sstevel@tonic-gate { CMD_EXIT, "exit", 0, SHELP_EXIT, },
1467c478bd9Sstevel@tonic-gate { CMD_EXPORT, "export", 0, SHELP_EXPORT, },
1477c478bd9Sstevel@tonic-gate { CMD_HELP, "help", 0, SHELP_HELP },
1487c478bd9Sstevel@tonic-gate { CMD_INFO, "info", HELP_RES_PROPS, SHELP_INFO, },
1497c478bd9Sstevel@tonic-gate { CMD_REMOVE, "remove", HELP_RES_PROPS, SHELP_REMOVE, },
1507c478bd9Sstevel@tonic-gate { CMD_REVERT, "revert", 0, SHELP_REVERT, },
1517c478bd9Sstevel@tonic-gate { CMD_SELECT, "select", HELP_RES_PROPS, SHELP_SELECT, },
1527c478bd9Sstevel@tonic-gate { CMD_SET, "set", HELP_PROPS, SHELP_SET, },
1537c478bd9Sstevel@tonic-gate { CMD_VERIFY, "verify", 0, SHELP_VERIFY, },
1547c478bd9Sstevel@tonic-gate { 0 },
1557c478bd9Sstevel@tonic-gate };
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate #define MAX_RT_STRLEN 16
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate /* These *must* match the order of the RT_ define's from zonecfg.h */
160c94c1ef0Sjv227347 char *res_types[] = {
1617c478bd9Sstevel@tonic-gate "unknown",
162087719fdSdp "zonename",
1637c478bd9Sstevel@tonic-gate "zonepath",
1647c478bd9Sstevel@tonic-gate "autoboot",
1657c478bd9Sstevel@tonic-gate "pool",
1667c478bd9Sstevel@tonic-gate "fs",
1677c478bd9Sstevel@tonic-gate "net",
1687c478bd9Sstevel@tonic-gate "device",
1697c478bd9Sstevel@tonic-gate "rctl",
1707c478bd9Sstevel@tonic-gate "attr",
171fa9e4066Sahrens "dataset",
172ffbafc53Scomay "limitpriv",
1733f2f09c1Sdp "bootargs",
1749acbbeafSnn35248 "brand",
1750209230bSgjelinek "dedicated-cpu",
1760209230bSgjelinek "capped-memory",
1770209230bSgjelinek ALIAS_MAXLWPS,
1780209230bSgjelinek ALIAS_MAXSHMMEM,
1790209230bSgjelinek ALIAS_MAXSHMIDS,
1800209230bSgjelinek ALIAS_MAXMSGIDS,
1810209230bSgjelinek ALIAS_MAXSEMIDS,
1820209230bSgjelinek ALIAS_SHARES,
1830209230bSgjelinek "scheduling-class",
184f4b3ec61Sdh155122 "ip-type",
185c97ad5cdSakolb "capped-cpu",
1865679c89fSjv227347 "hostid",
187cb8a054bSGlenn Faden "admin",
1880fbb751dSJohn Levon "fs-allowed",
189ff19e029SMenno Lageman ALIAS_MAXPROCS,
1907c478bd9Sstevel@tonic-gate NULL
1917c478bd9Sstevel@tonic-gate };
1927c478bd9Sstevel@tonic-gate
1937c478bd9Sstevel@tonic-gate /* These *must* match the order of the PT_ define's from zonecfg.h */
194c94c1ef0Sjv227347 char *prop_types[] = {
1957c478bd9Sstevel@tonic-gate "unknown",
196087719fdSdp "zonename",
1977c478bd9Sstevel@tonic-gate "zonepath",
1987c478bd9Sstevel@tonic-gate "autoboot",
1997c478bd9Sstevel@tonic-gate "pool",
2007c478bd9Sstevel@tonic-gate "dir",
2017c478bd9Sstevel@tonic-gate "special",
2027c478bd9Sstevel@tonic-gate "type",
2037c478bd9Sstevel@tonic-gate "options",
2047c478bd9Sstevel@tonic-gate "address",
2057c478bd9Sstevel@tonic-gate "physical",
2067c478bd9Sstevel@tonic-gate "name",
2077c478bd9Sstevel@tonic-gate "value",
2087c478bd9Sstevel@tonic-gate "match",
2097c478bd9Sstevel@tonic-gate "priv",
2107c478bd9Sstevel@tonic-gate "limit",
2117c478bd9Sstevel@tonic-gate "action",
2127c478bd9Sstevel@tonic-gate "raw",
213ffbafc53Scomay "limitpriv",
2143f2f09c1Sdp "bootargs",
2159acbbeafSnn35248 "brand",
2160209230bSgjelinek "ncpus",
2170209230bSgjelinek "importance",
2180209230bSgjelinek "swap",
2190209230bSgjelinek "locked",
2200209230bSgjelinek ALIAS_SHARES,
2210209230bSgjelinek ALIAS_MAXLWPS,
2220209230bSgjelinek ALIAS_MAXSHMMEM,
2230209230bSgjelinek ALIAS_MAXSHMIDS,
2240209230bSgjelinek ALIAS_MAXMSGIDS,
2250209230bSgjelinek ALIAS_MAXSEMIDS,
2260209230bSgjelinek ALIAS_MAXLOCKEDMEM,
2270209230bSgjelinek ALIAS_MAXSWAP,
2280209230bSgjelinek "scheduling-class",
229f4b3ec61Sdh155122 "ip-type",
230de860bd9Sgfaden "defrouter",
2315679c89fSjv227347 "hostid",
232cb8a054bSGlenn Faden "user",
233cb8a054bSGlenn Faden "auths",
2340fbb751dSJohn Levon "fs-allowed",
235ff19e029SMenno Lageman ALIAS_MAXPROCS,
236550b6e40SSowmini Varadhan "allowed-address",
2377c478bd9Sstevel@tonic-gate NULL
2387c478bd9Sstevel@tonic-gate };
2397c478bd9Sstevel@tonic-gate
240ffbafc53Scomay /* These *must* match the order of the PROP_VAL_ define's from zonecfg.h */
2417c478bd9Sstevel@tonic-gate static char *prop_val_types[] = {
2427c478bd9Sstevel@tonic-gate "simple",
2437c478bd9Sstevel@tonic-gate "complex",
2447c478bd9Sstevel@tonic-gate "list",
2457c478bd9Sstevel@tonic-gate };
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gate /*
2487c478bd9Sstevel@tonic-gate * The various _cmds[] lists below are for command tab-completion.
2497c478bd9Sstevel@tonic-gate */
2507c478bd9Sstevel@tonic-gate
2517c478bd9Sstevel@tonic-gate /*
2527c478bd9Sstevel@tonic-gate * remove has a space afterwards because it has qualifiers; the other commands
2530209230bSgjelinek * that have qualifiers (add, select, etc.) don't need a space here because
2547c478bd9Sstevel@tonic-gate * they have their own _cmds[] lists below.
2557c478bd9Sstevel@tonic-gate */
2567c478bd9Sstevel@tonic-gate static const char *global_scope_cmds[] = {
2577c478bd9Sstevel@tonic-gate "add",
2580209230bSgjelinek "clear",
2597c478bd9Sstevel@tonic-gate "commit",
2607c478bd9Sstevel@tonic-gate "create",
2617c478bd9Sstevel@tonic-gate "delete",
2627c478bd9Sstevel@tonic-gate "exit",
2637c478bd9Sstevel@tonic-gate "export",
2647c478bd9Sstevel@tonic-gate "help",
2657c478bd9Sstevel@tonic-gate "info",
2667c478bd9Sstevel@tonic-gate "remove ",
2677c478bd9Sstevel@tonic-gate "revert",
2687c478bd9Sstevel@tonic-gate "select",
2697c478bd9Sstevel@tonic-gate "set",
2707c478bd9Sstevel@tonic-gate "verify",
2717c478bd9Sstevel@tonic-gate NULL
2727c478bd9Sstevel@tonic-gate };
2737c478bd9Sstevel@tonic-gate
2747c478bd9Sstevel@tonic-gate static const char *add_cmds[] = {
2757c478bd9Sstevel@tonic-gate "add fs",
2767c478bd9Sstevel@tonic-gate "add net",
2777c478bd9Sstevel@tonic-gate "add device",
2787c478bd9Sstevel@tonic-gate "add rctl",
2797c478bd9Sstevel@tonic-gate "add attr",
280fa9e4066Sahrens "add dataset",
2810209230bSgjelinek "add dedicated-cpu",
282c97ad5cdSakolb "add capped-cpu",
2830209230bSgjelinek "add capped-memory",
284cb8a054bSGlenn Faden "add admin",
2850209230bSgjelinek NULL
2860209230bSgjelinek };
2870209230bSgjelinek
2880209230bSgjelinek static const char *clear_cmds[] = {
2890209230bSgjelinek "clear autoboot",
2900209230bSgjelinek "clear pool",
2910209230bSgjelinek "clear limitpriv",
2920209230bSgjelinek "clear bootargs",
2930209230bSgjelinek "clear scheduling-class",
294f4b3ec61Sdh155122 "clear ip-type",
2950209230bSgjelinek "clear " ALIAS_MAXLWPS,
2960209230bSgjelinek "clear " ALIAS_MAXSHMMEM,
2970209230bSgjelinek "clear " ALIAS_MAXSHMIDS,
2980209230bSgjelinek "clear " ALIAS_MAXMSGIDS,
2990209230bSgjelinek "clear " ALIAS_MAXSEMIDS,
3000209230bSgjelinek "clear " ALIAS_SHARES,
301ff19e029SMenno Lageman "clear " ALIAS_MAXPROCS,
3027c478bd9Sstevel@tonic-gate NULL
3037c478bd9Sstevel@tonic-gate };
3047c478bd9Sstevel@tonic-gate
3059e7542f4Sdp static const char *remove_cmds[] = {
3069e7542f4Sdp "remove fs ",
3079e7542f4Sdp "remove net ",
3089e7542f4Sdp "remove device ",
3099e7542f4Sdp "remove rctl ",
3109e7542f4Sdp "remove attr ",
3119e7542f4Sdp "remove dataset ",
3120209230bSgjelinek "remove dedicated-cpu ",
313c97ad5cdSakolb "remove capped-cpu ",
3140209230bSgjelinek "remove capped-memory ",
315cb8a054bSGlenn Faden "remove admin ",
3169e7542f4Sdp NULL
3179e7542f4Sdp };
3189e7542f4Sdp
3197c478bd9Sstevel@tonic-gate static const char *select_cmds[] = {
3207c478bd9Sstevel@tonic-gate "select fs ",
3217c478bd9Sstevel@tonic-gate "select net ",
3227c478bd9Sstevel@tonic-gate "select device ",
3237c478bd9Sstevel@tonic-gate "select rctl ",
3247c478bd9Sstevel@tonic-gate "select attr ",
325fa9e4066Sahrens "select dataset ",
3260209230bSgjelinek "select dedicated-cpu",
327c97ad5cdSakolb "select capped-cpu",
3280209230bSgjelinek "select capped-memory",
329cb8a054bSGlenn Faden "select admin",
3307c478bd9Sstevel@tonic-gate NULL
3317c478bd9Sstevel@tonic-gate };
3327c478bd9Sstevel@tonic-gate
3337c478bd9Sstevel@tonic-gate static const char *set_cmds[] = {
334087719fdSdp "set zonename=",
335087719fdSdp "set zonepath=",
3369acbbeafSnn35248 "set brand=",
337087719fdSdp "set autoboot=",
338087719fdSdp "set pool=",
339ffbafc53Scomay "set limitpriv=",
3403f2f09c1Sdp "set bootargs=",
3410209230bSgjelinek "set scheduling-class=",
342f4b3ec61Sdh155122 "set ip-type=",
3430209230bSgjelinek "set " ALIAS_MAXLWPS "=",
3440209230bSgjelinek "set " ALIAS_MAXSHMMEM "=",
3450209230bSgjelinek "set " ALIAS_MAXSHMIDS "=",
3460209230bSgjelinek "set " ALIAS_MAXMSGIDS "=",
3470209230bSgjelinek "set " ALIAS_MAXSEMIDS "=",
3480209230bSgjelinek "set " ALIAS_SHARES "=",
3495679c89fSjv227347 "set hostid=",
3500fbb751dSJohn Levon "set fs-allowed=",
351ff19e029SMenno Lageman "set " ALIAS_MAXPROCS "=",
3527c478bd9Sstevel@tonic-gate NULL
3537c478bd9Sstevel@tonic-gate };
3547c478bd9Sstevel@tonic-gate
3559e7542f4Sdp static const char *info_cmds[] = {
3569e7542f4Sdp "info fs ",
3579e7542f4Sdp "info net ",
3589e7542f4Sdp "info device ",
3599e7542f4Sdp "info rctl ",
3609e7542f4Sdp "info attr ",
3619e7542f4Sdp "info dataset ",
3620209230bSgjelinek "info capped-memory",
3630209230bSgjelinek "info dedicated-cpu",
364c97ad5cdSakolb "info capped-cpu",
3659e7542f4Sdp "info zonename",
3669e7542f4Sdp "info zonepath",
3679e7542f4Sdp "info autoboot",
3689e7542f4Sdp "info pool",
3699e7542f4Sdp "info limitpriv",
3709e7542f4Sdp "info bootargs",
3710209230bSgjelinek "info brand",
3720209230bSgjelinek "info scheduling-class",
373f4b3ec61Sdh155122 "info ip-type",
3740209230bSgjelinek "info max-lwps",
3750209230bSgjelinek "info max-shm-memory",
3760209230bSgjelinek "info max-shm-ids",
3770209230bSgjelinek "info max-msg-ids",
3780209230bSgjelinek "info max-sem-ids",
3790209230bSgjelinek "info cpu-shares",
3805679c89fSjv227347 "info hostid",
381cb8a054bSGlenn Faden "info admin",
3820fbb751dSJohn Levon "info fs-allowed",
383ff19e029SMenno Lageman "info max-processes",
3849e7542f4Sdp NULL
3859e7542f4Sdp };
3869e7542f4Sdp
3877c478bd9Sstevel@tonic-gate static const char *fs_res_scope_cmds[] = {
3887c478bd9Sstevel@tonic-gate "add options ",
3897c478bd9Sstevel@tonic-gate "cancel",
3907c478bd9Sstevel@tonic-gate "end",
3917c478bd9Sstevel@tonic-gate "exit",
3927c478bd9Sstevel@tonic-gate "help",
3937c478bd9Sstevel@tonic-gate "info",
394ffbafc53Scomay "remove options ",
3957c478bd9Sstevel@tonic-gate "set dir=",
3967c478bd9Sstevel@tonic-gate "set raw=",
3977c478bd9Sstevel@tonic-gate "set special=",
3987c478bd9Sstevel@tonic-gate "set type=",
3990209230bSgjelinek "clear raw",
4007c478bd9Sstevel@tonic-gate NULL
4017c478bd9Sstevel@tonic-gate };
4027c478bd9Sstevel@tonic-gate
4037c478bd9Sstevel@tonic-gate static const char *net_res_scope_cmds[] = {
4047c478bd9Sstevel@tonic-gate "cancel",
4057c478bd9Sstevel@tonic-gate "end",
4067c478bd9Sstevel@tonic-gate "exit",
4077c478bd9Sstevel@tonic-gate "help",
4087c478bd9Sstevel@tonic-gate "info",
4097c478bd9Sstevel@tonic-gate "set address=",
4107c478bd9Sstevel@tonic-gate "set physical=",
4111b3281c0SGerald Jelinek "set defrouter=",
4127c478bd9Sstevel@tonic-gate NULL
4137c478bd9Sstevel@tonic-gate };
4147c478bd9Sstevel@tonic-gate
4157c478bd9Sstevel@tonic-gate static const char *device_res_scope_cmds[] = {
4167c478bd9Sstevel@tonic-gate "cancel",
4177c478bd9Sstevel@tonic-gate "end",
4187c478bd9Sstevel@tonic-gate "exit",
4197c478bd9Sstevel@tonic-gate "help",
4207c478bd9Sstevel@tonic-gate "info",
4217c478bd9Sstevel@tonic-gate "set match=",
4227c478bd9Sstevel@tonic-gate NULL
4237c478bd9Sstevel@tonic-gate };
4247c478bd9Sstevel@tonic-gate
4257c478bd9Sstevel@tonic-gate static const char *attr_res_scope_cmds[] = {
4267c478bd9Sstevel@tonic-gate "cancel",
4277c478bd9Sstevel@tonic-gate "end",
4287c478bd9Sstevel@tonic-gate "exit",
4297c478bd9Sstevel@tonic-gate "help",
4307c478bd9Sstevel@tonic-gate "info",
4317c478bd9Sstevel@tonic-gate "set name=",
4327c478bd9Sstevel@tonic-gate "set type=",
4337c478bd9Sstevel@tonic-gate "set value=",
4347c478bd9Sstevel@tonic-gate NULL
4357c478bd9Sstevel@tonic-gate };
4367c478bd9Sstevel@tonic-gate
4377c478bd9Sstevel@tonic-gate static const char *rctl_res_scope_cmds[] = {
4387c478bd9Sstevel@tonic-gate "add value ",
4397c478bd9Sstevel@tonic-gate "cancel",
4407c478bd9Sstevel@tonic-gate "end",
4417c478bd9Sstevel@tonic-gate "exit",
4427c478bd9Sstevel@tonic-gate "help",
4437c478bd9Sstevel@tonic-gate "info",
444ffbafc53Scomay "remove value ",
4457c478bd9Sstevel@tonic-gate "set name=",
4467c478bd9Sstevel@tonic-gate NULL
4477c478bd9Sstevel@tonic-gate };
4487c478bd9Sstevel@tonic-gate
449fa9e4066Sahrens static const char *dataset_res_scope_cmds[] = {
450fa9e4066Sahrens "cancel",
451fa9e4066Sahrens "end",
452fa9e4066Sahrens "exit",
453fa9e4066Sahrens "help",
454fa9e4066Sahrens "info",
455fa9e4066Sahrens "set name=",
456fa9e4066Sahrens NULL
457fa9e4066Sahrens };
458fa9e4066Sahrens
4590209230bSgjelinek static const char *pset_res_scope_cmds[] = {
4600209230bSgjelinek "cancel",
4610209230bSgjelinek "end",
4620209230bSgjelinek "exit",
4630209230bSgjelinek "help",
4640209230bSgjelinek "info",
4650209230bSgjelinek "set ncpus=",
4660209230bSgjelinek "set importance=",
4670209230bSgjelinek "clear importance",
4680209230bSgjelinek NULL
4690209230bSgjelinek };
4700209230bSgjelinek
471c97ad5cdSakolb static const char *pcap_res_scope_cmds[] = {
472c97ad5cdSakolb "cancel",
473c97ad5cdSakolb "end",
474c97ad5cdSakolb "exit",
475c97ad5cdSakolb "help",
476c97ad5cdSakolb "info",
477c97ad5cdSakolb "set ncpus=",
478c97ad5cdSakolb NULL
479c97ad5cdSakolb };
480c97ad5cdSakolb
4810209230bSgjelinek static const char *mcap_res_scope_cmds[] = {
4820209230bSgjelinek "cancel",
4830209230bSgjelinek "end",
4840209230bSgjelinek "exit",
4850209230bSgjelinek "help",
4860209230bSgjelinek "info",
4870209230bSgjelinek "set physical=",
4880209230bSgjelinek "set swap=",
4890209230bSgjelinek "set locked=",
4900209230bSgjelinek "clear physical",
4910209230bSgjelinek "clear swap",
4920209230bSgjelinek "clear locked",
4930209230bSgjelinek NULL
4940209230bSgjelinek };
4950209230bSgjelinek
496cb8a054bSGlenn Faden static const char *admin_res_scope_cmds[] = {
497cb8a054bSGlenn Faden "cancel",
498cb8a054bSGlenn Faden "end",
499cb8a054bSGlenn Faden "exit",
500cb8a054bSGlenn Faden "help",
501cb8a054bSGlenn Faden "info",
502cb8a054bSGlenn Faden "set user=",
503cb8a054bSGlenn Faden "set auths=",
504cb8a054bSGlenn Faden NULL
505cb8a054bSGlenn Faden };
506cb8a054bSGlenn Faden
507550b6e40SSowmini Varadhan struct xif {
508550b6e40SSowmini Varadhan struct xif *xif_next;
509550b6e40SSowmini Varadhan char xif_name[LIFNAMSIZ];
510550b6e40SSowmini Varadhan boolean_t xif_has_address;
511550b6e40SSowmini Varadhan boolean_t xif_has_defrouter;
512550b6e40SSowmini Varadhan };
513550b6e40SSowmini Varadhan
5147c478bd9Sstevel@tonic-gate /* Global variables */
5157c478bd9Sstevel@tonic-gate
516550b6e40SSowmini Varadhan /* list of network interfaces specified for exclusive IP zone */
517550b6e40SSowmini Varadhan struct xif *xif;
518550b6e40SSowmini Varadhan
5197c478bd9Sstevel@tonic-gate /* set early in main(), never modified thereafter, used all over the place */
5207c478bd9Sstevel@tonic-gate static char *execname;
5217c478bd9Sstevel@tonic-gate
5227c478bd9Sstevel@tonic-gate /* set in main(), used all over the place */
5237c478bd9Sstevel@tonic-gate static zone_dochandle_t handle;
5247c478bd9Sstevel@tonic-gate
5257c478bd9Sstevel@tonic-gate /* used all over the place */
526087719fdSdp static char zone[ZONENAME_MAX];
527087719fdSdp static char revert_zone[ZONENAME_MAX];
5287c478bd9Sstevel@tonic-gate
5299acbbeafSnn35248 /* global brand operations */
530123807fbSedp static brand_handle_t brand;
5319acbbeafSnn35248
5327c478bd9Sstevel@tonic-gate /* set in modifying functions, checked in read_input() */
533bbec428eSgjelinek static boolean_t need_to_commit = B_FALSE;
534bbec428eSgjelinek boolean_t saw_error;
5357c478bd9Sstevel@tonic-gate
5367c478bd9Sstevel@tonic-gate /* set in yacc parser, checked in read_input() */
537bbec428eSgjelinek boolean_t newline_terminated;
5387c478bd9Sstevel@tonic-gate
5397c478bd9Sstevel@tonic-gate /* set in main(), checked in lex error handler */
540bbec428eSgjelinek boolean_t cmd_file_mode;
5417c478bd9Sstevel@tonic-gate
5427c478bd9Sstevel@tonic-gate /* set in exit_func(), checked in read_input() */
543bbec428eSgjelinek static boolean_t time_to_exit = B_FALSE, force_exit = B_FALSE;
5447c478bd9Sstevel@tonic-gate
5457c478bd9Sstevel@tonic-gate /* used in short_usage() and zerr() */
5467c478bd9Sstevel@tonic-gate static char *cmd_file_name = NULL;
5477c478bd9Sstevel@tonic-gate
5487c478bd9Sstevel@tonic-gate /* checked in read_input() and other places */
549bbec428eSgjelinek static boolean_t ok_to_prompt = B_FALSE;
5507c478bd9Sstevel@tonic-gate
5517c478bd9Sstevel@tonic-gate /* set and checked in initialize() */
552bbec428eSgjelinek static boolean_t got_handle = B_FALSE;
5537c478bd9Sstevel@tonic-gate
5547c478bd9Sstevel@tonic-gate /* initialized in do_interactive(), checked in initialize() */
555bbec428eSgjelinek static boolean_t interactive_mode;
5567c478bd9Sstevel@tonic-gate
5570209230bSgjelinek /* set if configuring the global zone */
558bbec428eSgjelinek static boolean_t global_zone = B_FALSE;
5590209230bSgjelinek
5607c478bd9Sstevel@tonic-gate /* set in main(), checked in multiple places */
561bbec428eSgjelinek static boolean_t read_only_mode;
5627c478bd9Sstevel@tonic-gate
563bbec428eSgjelinek /* scope is outer/global or inner/resource */
564bbec428eSgjelinek static boolean_t global_scope = B_TRUE;
5657c478bd9Sstevel@tonic-gate static int resource_scope; /* should be in the RT_ list from zonecfg.h */
5667c478bd9Sstevel@tonic-gate static int end_op = -1; /* operation on end is either add or modify */
5677c478bd9Sstevel@tonic-gate
5687c478bd9Sstevel@tonic-gate int num_prop_vals; /* for grammar */
5697c478bd9Sstevel@tonic-gate
5707c478bd9Sstevel@tonic-gate /*
5717c478bd9Sstevel@tonic-gate * These are for keeping track of resources as they are specified as part of
5727c478bd9Sstevel@tonic-gate * the multi-step process. They should be initialized by add_resource() or
5737c478bd9Sstevel@tonic-gate * select_func() and filled in by add_property() or set_func().
5747c478bd9Sstevel@tonic-gate */
5757c478bd9Sstevel@tonic-gate static struct zone_fstab old_fstab, in_progress_fstab;
5767c478bd9Sstevel@tonic-gate static struct zone_nwiftab old_nwiftab, in_progress_nwiftab;
5777c478bd9Sstevel@tonic-gate static struct zone_devtab old_devtab, in_progress_devtab;
5787c478bd9Sstevel@tonic-gate static struct zone_rctltab old_rctltab, in_progress_rctltab;
5797c478bd9Sstevel@tonic-gate static struct zone_attrtab old_attrtab, in_progress_attrtab;
580fa9e4066Sahrens static struct zone_dstab old_dstab, in_progress_dstab;
5810209230bSgjelinek static struct zone_psettab old_psettab, in_progress_psettab;
5820209230bSgjelinek static struct zone_mcaptab old_mcaptab, in_progress_mcaptab;
583cb8a054bSGlenn Faden static struct zone_admintab old_admintab, in_progress_admintab;
5847c478bd9Sstevel@tonic-gate
5857c478bd9Sstevel@tonic-gate static GetLine *gl; /* The gl_get_line() resource object */
5867c478bd9Sstevel@tonic-gate
5870209230bSgjelinek static void bytes_to_units(char *str, char *buf, int bufsize);
5880209230bSgjelinek
5897c478bd9Sstevel@tonic-gate /* Functions begin here */
5907c478bd9Sstevel@tonic-gate
591bbec428eSgjelinek static boolean_t
initial_match(const char * line1,const char * line2,int word_end)5927c478bd9Sstevel@tonic-gate initial_match(const char *line1, const char *line2, int word_end)
5937c478bd9Sstevel@tonic-gate {
5947c478bd9Sstevel@tonic-gate if (word_end <= 0)
595bbec428eSgjelinek return (B_TRUE);
5967c478bd9Sstevel@tonic-gate return (strncmp(line1, line2, word_end) == 0);
5977c478bd9Sstevel@tonic-gate }
5987c478bd9Sstevel@tonic-gate
5997c478bd9Sstevel@tonic-gate static int
add_stuff(WordCompletion * cpl,const char * line1,const char ** list,int word_end)6007c478bd9Sstevel@tonic-gate add_stuff(WordCompletion *cpl, const char *line1, const char **list,
6017c478bd9Sstevel@tonic-gate int word_end)
6027c478bd9Sstevel@tonic-gate {
6037c478bd9Sstevel@tonic-gate int i, err;
6047c478bd9Sstevel@tonic-gate
6057c478bd9Sstevel@tonic-gate for (i = 0; list[i] != NULL; i++) {
6067c478bd9Sstevel@tonic-gate if (initial_match(line1, list[i], word_end)) {
6077c478bd9Sstevel@tonic-gate err = cpl_add_completion(cpl, line1, 0, word_end,
6087c478bd9Sstevel@tonic-gate list[i] + word_end, "", "");
6097c478bd9Sstevel@tonic-gate if (err != 0)
6107c478bd9Sstevel@tonic-gate return (err);
6117c478bd9Sstevel@tonic-gate }
6127c478bd9Sstevel@tonic-gate }
6137c478bd9Sstevel@tonic-gate return (0);
6147c478bd9Sstevel@tonic-gate }
6157c478bd9Sstevel@tonic-gate
6167c478bd9Sstevel@tonic-gate static
6177c478bd9Sstevel@tonic-gate /* ARGSUSED */
CPL_MATCH_FN(cmd_cpl_fn)6187c478bd9Sstevel@tonic-gate CPL_MATCH_FN(cmd_cpl_fn)
6197c478bd9Sstevel@tonic-gate {
6207c478bd9Sstevel@tonic-gate if (global_scope) {
6217c478bd9Sstevel@tonic-gate /*
6227c478bd9Sstevel@tonic-gate * The MAX/MIN tests below are to make sure we have at least
6237c478bd9Sstevel@tonic-gate * enough characters to distinguish from other prefixes (MAX)
6247c478bd9Sstevel@tonic-gate * but only check MIN(what we have, what we're checking).
6257c478bd9Sstevel@tonic-gate */
6267c478bd9Sstevel@tonic-gate if (strncmp(line, "add ", MAX(MIN(word_end, 4), 1)) == 0)
6277c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, add_cmds, word_end));
6280209230bSgjelinek if (strncmp(line, "clear ", MAX(MIN(word_end, 6), 2)) == 0)
6290209230bSgjelinek return (add_stuff(cpl, line, clear_cmds, word_end));
6307c478bd9Sstevel@tonic-gate if (strncmp(line, "select ", MAX(MIN(word_end, 7), 3)) == 0)
6317c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, select_cmds, word_end));
6327c478bd9Sstevel@tonic-gate if (strncmp(line, "set ", MAX(MIN(word_end, 4), 3)) == 0)
6337c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, set_cmds, word_end));
6349e7542f4Sdp if (strncmp(line, "remove ", MAX(MIN(word_end, 7), 1)) == 0)
6359e7542f4Sdp return (add_stuff(cpl, line, remove_cmds, word_end));
6369e7542f4Sdp if (strncmp(line, "info ", MAX(MIN(word_end, 5), 1)) == 0)
6379e7542f4Sdp return (add_stuff(cpl, line, info_cmds, word_end));
6387c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, global_scope_cmds, word_end));
6397c478bd9Sstevel@tonic-gate }
6407c478bd9Sstevel@tonic-gate switch (resource_scope) {
6417c478bd9Sstevel@tonic-gate case RT_FS:
6427c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, fs_res_scope_cmds, word_end));
6437c478bd9Sstevel@tonic-gate case RT_NET:
6447c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, net_res_scope_cmds, word_end));
6457c478bd9Sstevel@tonic-gate case RT_DEVICE:
6467c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, device_res_scope_cmds, word_end));
6477c478bd9Sstevel@tonic-gate case RT_RCTL:
6487c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, rctl_res_scope_cmds, word_end));
6497c478bd9Sstevel@tonic-gate case RT_ATTR:
6507c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, attr_res_scope_cmds, word_end));
651fa9e4066Sahrens case RT_DATASET:
652fa9e4066Sahrens return (add_stuff(cpl, line, dataset_res_scope_cmds, word_end));
6530209230bSgjelinek case RT_DCPU:
6540209230bSgjelinek return (add_stuff(cpl, line, pset_res_scope_cmds, word_end));
655c97ad5cdSakolb case RT_PCAP:
656c97ad5cdSakolb return (add_stuff(cpl, line, pcap_res_scope_cmds, word_end));
6570209230bSgjelinek case RT_MCAP:
6580209230bSgjelinek return (add_stuff(cpl, line, mcap_res_scope_cmds, word_end));
659cb8a054bSGlenn Faden case RT_ADMIN:
660cb8a054bSGlenn Faden return (add_stuff(cpl, line, admin_res_scope_cmds, word_end));
6617c478bd9Sstevel@tonic-gate }
6627c478bd9Sstevel@tonic-gate return (0);
6637c478bd9Sstevel@tonic-gate }
6647c478bd9Sstevel@tonic-gate
6657c478bd9Sstevel@tonic-gate /*
6667c478bd9Sstevel@tonic-gate * For the main CMD_func() functions below, several of them call getopt()
6677c478bd9Sstevel@tonic-gate * then check optind against argc to make sure an extra parameter was not
6687c478bd9Sstevel@tonic-gate * passed in. The reason this is not caught in the grammar is that the
6697c478bd9Sstevel@tonic-gate * grammar just checks for a miscellaneous TOKEN, which is *expected* to
6707c478bd9Sstevel@tonic-gate * be "-F" (for example), but could be anything. So (for example) this
6717c478bd9Sstevel@tonic-gate * check will prevent "create bogus".
6727c478bd9Sstevel@tonic-gate */
6737c478bd9Sstevel@tonic-gate
6747c478bd9Sstevel@tonic-gate cmd_t *
alloc_cmd(void)6757c478bd9Sstevel@tonic-gate alloc_cmd(void)
6767c478bd9Sstevel@tonic-gate {
6777c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (cmd_t)));
6787c478bd9Sstevel@tonic-gate }
6797c478bd9Sstevel@tonic-gate
6807c478bd9Sstevel@tonic-gate void
free_cmd(cmd_t * cmd)6817c478bd9Sstevel@tonic-gate free_cmd(cmd_t *cmd)
6827c478bd9Sstevel@tonic-gate {
6837c478bd9Sstevel@tonic-gate int i;
6847c478bd9Sstevel@tonic-gate
6857c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_EQ_PROP_PAIRS; i++)
6867c478bd9Sstevel@tonic-gate if (cmd->cmd_property_ptr[i] != NULL) {
6877c478bd9Sstevel@tonic-gate property_value_ptr_t pp = cmd->cmd_property_ptr[i];
6887c478bd9Sstevel@tonic-gate
6897c478bd9Sstevel@tonic-gate switch (pp->pv_type) {
6907c478bd9Sstevel@tonic-gate case PROP_VAL_SIMPLE:
6917c478bd9Sstevel@tonic-gate free(pp->pv_simple);
6927c478bd9Sstevel@tonic-gate break;
6937c478bd9Sstevel@tonic-gate case PROP_VAL_COMPLEX:
6947c478bd9Sstevel@tonic-gate free_complex(pp->pv_complex);
6957c478bd9Sstevel@tonic-gate break;
6967c478bd9Sstevel@tonic-gate case PROP_VAL_LIST:
6977c478bd9Sstevel@tonic-gate free_list(pp->pv_list);
6987c478bd9Sstevel@tonic-gate break;
6997c478bd9Sstevel@tonic-gate }
7007c478bd9Sstevel@tonic-gate }
7017c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_argc; i++)
7027c478bd9Sstevel@tonic-gate free(cmd->cmd_argv[i]);
7037c478bd9Sstevel@tonic-gate free(cmd);
7047c478bd9Sstevel@tonic-gate }
7057c478bd9Sstevel@tonic-gate
7067c478bd9Sstevel@tonic-gate complex_property_ptr_t
alloc_complex(void)7077c478bd9Sstevel@tonic-gate alloc_complex(void)
7087c478bd9Sstevel@tonic-gate {
7097c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (complex_property_t)));
7107c478bd9Sstevel@tonic-gate }
7117c478bd9Sstevel@tonic-gate
7127c478bd9Sstevel@tonic-gate void
free_complex(complex_property_ptr_t complex)7137c478bd9Sstevel@tonic-gate free_complex(complex_property_ptr_t complex)
7147c478bd9Sstevel@tonic-gate {
7157c478bd9Sstevel@tonic-gate if (complex == NULL)
7167c478bd9Sstevel@tonic-gate return;
7177c478bd9Sstevel@tonic-gate free_complex(complex->cp_next);
7187c478bd9Sstevel@tonic-gate if (complex->cp_value != NULL)
7197c478bd9Sstevel@tonic-gate free(complex->cp_value);
7207c478bd9Sstevel@tonic-gate free(complex);
7217c478bd9Sstevel@tonic-gate }
7227c478bd9Sstevel@tonic-gate
7237c478bd9Sstevel@tonic-gate list_property_ptr_t
alloc_list(void)7247c478bd9Sstevel@tonic-gate alloc_list(void)
7257c478bd9Sstevel@tonic-gate {
7267c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (list_property_t)));
7277c478bd9Sstevel@tonic-gate }
7287c478bd9Sstevel@tonic-gate
7297c478bd9Sstevel@tonic-gate void
free_list(list_property_ptr_t list)7307c478bd9Sstevel@tonic-gate free_list(list_property_ptr_t list)
7317c478bd9Sstevel@tonic-gate {
7327c478bd9Sstevel@tonic-gate if (list == NULL)
7337c478bd9Sstevel@tonic-gate return;
7347c478bd9Sstevel@tonic-gate if (list->lp_simple != NULL)
7357c478bd9Sstevel@tonic-gate free(list->lp_simple);
7367c478bd9Sstevel@tonic-gate free_complex(list->lp_complex);
7377c478bd9Sstevel@tonic-gate free_list(list->lp_next);
7387c478bd9Sstevel@tonic-gate free(list);
7397c478bd9Sstevel@tonic-gate }
7407c478bd9Sstevel@tonic-gate
7417c478bd9Sstevel@tonic-gate void
free_outer_list(list_property_ptr_t list)7427c478bd9Sstevel@tonic-gate free_outer_list(list_property_ptr_t list)
7437c478bd9Sstevel@tonic-gate {
7447c478bd9Sstevel@tonic-gate if (list == NULL)
7457c478bd9Sstevel@tonic-gate return;
7467c478bd9Sstevel@tonic-gate free_outer_list(list->lp_next);
7477c478bd9Sstevel@tonic-gate free(list);
7487c478bd9Sstevel@tonic-gate }
7497c478bd9Sstevel@tonic-gate
7507c478bd9Sstevel@tonic-gate static struct zone_rctlvaltab *
alloc_rctlvaltab(void)7517c478bd9Sstevel@tonic-gate alloc_rctlvaltab(void)
7527c478bd9Sstevel@tonic-gate {
7537c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (struct zone_rctlvaltab)));
7547c478bd9Sstevel@tonic-gate }
7557c478bd9Sstevel@tonic-gate
7567c478bd9Sstevel@tonic-gate static char *
rt_to_str(int res_type)7577c478bd9Sstevel@tonic-gate rt_to_str(int res_type)
7587c478bd9Sstevel@tonic-gate {
7597c478bd9Sstevel@tonic-gate assert(res_type >= RT_MIN && res_type <= RT_MAX);
7607c478bd9Sstevel@tonic-gate return (res_types[res_type]);
7617c478bd9Sstevel@tonic-gate }
7627c478bd9Sstevel@tonic-gate
7637c478bd9Sstevel@tonic-gate static char *
pt_to_str(int prop_type)7647c478bd9Sstevel@tonic-gate pt_to_str(int prop_type)
7657c478bd9Sstevel@tonic-gate {
7667c478bd9Sstevel@tonic-gate assert(prop_type >= PT_MIN && prop_type <= PT_MAX);
7677c478bd9Sstevel@tonic-gate return (prop_types[prop_type]);
7687c478bd9Sstevel@tonic-gate }
7697c478bd9Sstevel@tonic-gate
7707c478bd9Sstevel@tonic-gate static char *
pvt_to_str(int pv_type)7717c478bd9Sstevel@tonic-gate pvt_to_str(int pv_type)
7727c478bd9Sstevel@tonic-gate {
7737c478bd9Sstevel@tonic-gate assert(pv_type >= PROP_VAL_MIN && pv_type <= PROP_VAL_MAX);
7747c478bd9Sstevel@tonic-gate return (prop_val_types[pv_type]);
7757c478bd9Sstevel@tonic-gate }
7767c478bd9Sstevel@tonic-gate
7777c478bd9Sstevel@tonic-gate static char *
cmd_to_str(int cmd_num)7787c478bd9Sstevel@tonic-gate cmd_to_str(int cmd_num)
7797c478bd9Sstevel@tonic-gate {
7807c478bd9Sstevel@tonic-gate assert(cmd_num >= CMD_MIN && cmd_num <= CMD_MAX);
7817c478bd9Sstevel@tonic-gate return (helptab[cmd_num].cmd_name);
7827c478bd9Sstevel@tonic-gate }
7837c478bd9Sstevel@tonic-gate
7843042b8b5Sbatschul /* PRINTFLIKE1 */
7853042b8b5Sbatschul static void
zerr(const char * fmt,...)7863042b8b5Sbatschul zerr(const char *fmt, ...)
7873042b8b5Sbatschul {
7883042b8b5Sbatschul va_list alist;
7893042b8b5Sbatschul static int last_lineno;
7903042b8b5Sbatschul
7913042b8b5Sbatschul /* lex_lineno has already been incremented in the lexer; compensate */
7923042b8b5Sbatschul if (cmd_file_mode && lex_lineno > last_lineno) {
7933042b8b5Sbatschul if (strcmp(cmd_file_name, "-") == 0)
7943042b8b5Sbatschul (void) fprintf(stderr, gettext("On line %d:\n"),
7953042b8b5Sbatschul lex_lineno - 1);
7963042b8b5Sbatschul else
7973042b8b5Sbatschul (void) fprintf(stderr, gettext("On line %d of %s:\n"),
7983042b8b5Sbatschul lex_lineno - 1, cmd_file_name);
7993042b8b5Sbatschul last_lineno = lex_lineno;
8003042b8b5Sbatschul }
8013042b8b5Sbatschul va_start(alist, fmt);
8023042b8b5Sbatschul (void) vfprintf(stderr, fmt, alist);
8033042b8b5Sbatschul (void) fprintf(stderr, "\n");
8043042b8b5Sbatschul va_end(alist);
8053042b8b5Sbatschul }
8063042b8b5Sbatschul
8077c478bd9Sstevel@tonic-gate /*
8087c478bd9Sstevel@tonic-gate * This is a separate function rather than a set of define's because of the
8097c478bd9Sstevel@tonic-gate * gettext() wrapping.
8107c478bd9Sstevel@tonic-gate */
8117c478bd9Sstevel@tonic-gate
8127c478bd9Sstevel@tonic-gate /*
8137c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE
8147c478bd9Sstevel@tonic-gate * Each string below should have \t follow \n whenever needed; the
8157c478bd9Sstevel@tonic-gate * initial \t and the terminal \n will be provided by the calling function.
8167c478bd9Sstevel@tonic-gate */
8177c478bd9Sstevel@tonic-gate
8187c478bd9Sstevel@tonic-gate static char *
long_help(int cmd_num)8197c478bd9Sstevel@tonic-gate long_help(int cmd_num)
8207c478bd9Sstevel@tonic-gate {
8217c478bd9Sstevel@tonic-gate static char line[1024]; /* arbitrary large amount */
8227c478bd9Sstevel@tonic-gate
8237c478bd9Sstevel@tonic-gate assert(cmd_num >= CMD_MIN && cmd_num <= CMD_MAX);
8247c478bd9Sstevel@tonic-gate switch (cmd_num) {
8257c478bd9Sstevel@tonic-gate case CMD_HELP:
8267c478bd9Sstevel@tonic-gate return (gettext("Prints help message."));
8277c478bd9Sstevel@tonic-gate case CMD_CREATE:
8287c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line),
8297c478bd9Sstevel@tonic-gate gettext("Creates a configuration for the "
8307c478bd9Sstevel@tonic-gate "specified zone. %s should be\n\tused to "
8317c478bd9Sstevel@tonic-gate "begin configuring a new zone. If overwriting an "
8327c478bd9Sstevel@tonic-gate "existing\n\tconfiguration, the -F flag can be "
8337c478bd9Sstevel@tonic-gate "used to force the action. If\n\t-t template is "
8347c478bd9Sstevel@tonic-gate "given, creates a configuration identical to the\n"
8357c478bd9Sstevel@tonic-gate "\tspecified template, except that the zone name "
8369e518655Sgjelinek "is changed from\n\ttemplate to zonename. '%s -a' "
8379e518655Sgjelinek "creates a configuration from a\n\tdetached "
8389e518655Sgjelinek "zonepath. '%s -b' results in a blank "
8399e518655Sgjelinek "configuration.\n\t'%s' with no arguments applies "
8409e518655Sgjelinek "the Sun default settings."),
8417c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE), cmd_to_str(CMD_CREATE),
8429e518655Sgjelinek cmd_to_str(CMD_CREATE), cmd_to_str(CMD_CREATE));
8437c478bd9Sstevel@tonic-gate return (line);
8447c478bd9Sstevel@tonic-gate case CMD_EXIT:
8457c478bd9Sstevel@tonic-gate return (gettext("Exits the program. The -F flag can "
8467c478bd9Sstevel@tonic-gate "be used to force the action."));
8477c478bd9Sstevel@tonic-gate case CMD_EXPORT:
8487c478bd9Sstevel@tonic-gate return (gettext("Prints configuration to standard "
8497c478bd9Sstevel@tonic-gate "output, or to output-file if\n\tspecified, in "
8507c478bd9Sstevel@tonic-gate "a form suitable for use in a command-file."));
8517c478bd9Sstevel@tonic-gate case CMD_ADD:
8527c478bd9Sstevel@tonic-gate return (gettext("Add specified resource to "
8537c478bd9Sstevel@tonic-gate "configuration."));
8547c478bd9Sstevel@tonic-gate case CMD_DELETE:
8557c478bd9Sstevel@tonic-gate return (gettext("Deletes the specified zone. The -F "
8567c478bd9Sstevel@tonic-gate "flag can be used to force the\n\taction."));
8577c478bd9Sstevel@tonic-gate case CMD_REMOVE:
8587c478bd9Sstevel@tonic-gate return (gettext("Remove specified resource from "
8590209230bSgjelinek "configuration. The -F flag can be used\n\tto "
8600209230bSgjelinek "force the action."));
8617c478bd9Sstevel@tonic-gate case CMD_SELECT:
8627c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line),
8637c478bd9Sstevel@tonic-gate gettext("Selects a resource to modify. "
8647c478bd9Sstevel@tonic-gate "Resource modification is completed\n\twith the "
8657c478bd9Sstevel@tonic-gate "command \"%s\". The property name/value pairs "
8667c478bd9Sstevel@tonic-gate "must uniquely\n\tidentify a resource. Note that "
8677c478bd9Sstevel@tonic-gate "the curly braces ('{', '}') mean one\n\tor more "
8687c478bd9Sstevel@tonic-gate "of whatever is between them."),
8697c478bd9Sstevel@tonic-gate cmd_to_str(CMD_END));
8707c478bd9Sstevel@tonic-gate return (line);
8717c478bd9Sstevel@tonic-gate case CMD_SET:
8727c478bd9Sstevel@tonic-gate return (gettext("Sets property values."));
8730209230bSgjelinek case CMD_CLEAR:
8740209230bSgjelinek return (gettext("Clears property values."));
8757c478bd9Sstevel@tonic-gate case CMD_INFO:
8767c478bd9Sstevel@tonic-gate return (gettext("Displays information about the "
8777c478bd9Sstevel@tonic-gate "current configuration. If resource\n\ttype is "
8787c478bd9Sstevel@tonic-gate "specified, displays only information about "
8797c478bd9Sstevel@tonic-gate "resources of\n\tthe relevant type. If resource "
8807c478bd9Sstevel@tonic-gate "id is specified, displays only\n\tinformation "
8817c478bd9Sstevel@tonic-gate "about that resource."));
8827c478bd9Sstevel@tonic-gate case CMD_VERIFY:
8837c478bd9Sstevel@tonic-gate return (gettext("Verifies current configuration "
8847c478bd9Sstevel@tonic-gate "for correctness (some resource types\n\thave "
8857c478bd9Sstevel@tonic-gate "required properties)."));
8867c478bd9Sstevel@tonic-gate case CMD_COMMIT:
8877c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line),
8887c478bd9Sstevel@tonic-gate gettext("Commits current configuration. "
8897c478bd9Sstevel@tonic-gate "Configuration must be committed to\n\tbe used by "
8907c478bd9Sstevel@tonic-gate "%s. Until the configuration is committed, "
8917c478bd9Sstevel@tonic-gate "changes \n\tcan be removed with the %s "
8927c478bd9Sstevel@tonic-gate "command. This operation is\n\tattempted "
8937c478bd9Sstevel@tonic-gate "automatically upon completion of a %s "
8947c478bd9Sstevel@tonic-gate "session."), "zoneadm", cmd_to_str(CMD_REVERT),
8957c478bd9Sstevel@tonic-gate "zonecfg");
8967c478bd9Sstevel@tonic-gate return (line);
8977c478bd9Sstevel@tonic-gate case CMD_REVERT:
8987c478bd9Sstevel@tonic-gate return (gettext("Reverts configuration back to the "
8997c478bd9Sstevel@tonic-gate "last committed state. The -F flag\n\tcan be "
9007c478bd9Sstevel@tonic-gate "used to force the action."));
9017c478bd9Sstevel@tonic-gate case CMD_CANCEL:
9027c478bd9Sstevel@tonic-gate return (gettext("Cancels resource/property "
9037c478bd9Sstevel@tonic-gate "specification."));
9047c478bd9Sstevel@tonic-gate case CMD_END:
9057c478bd9Sstevel@tonic-gate return (gettext("Ends resource/property "
9067c478bd9Sstevel@tonic-gate "specification."));
9077c478bd9Sstevel@tonic-gate }
9087c478bd9Sstevel@tonic-gate /* NOTREACHED */
9097e362f58Scomay return (NULL);
9107c478bd9Sstevel@tonic-gate }
9117c478bd9Sstevel@tonic-gate
9127c478bd9Sstevel@tonic-gate /*
913*944b13ecSGary Mills * Return the input filename appended to each component of the path
914*944b13ecSGary Mills * or the filename itself if it is absolute.
915*944b13ecSGary Mills * Parameters: path string, file name, output string.
916*944b13ecSGary Mills */
917*944b13ecSGary Mills /* Copied almost verbatim from libtnfctl/prb_findexec.c */
918*944b13ecSGary Mills static const char *
exec_cat(const char * s1,const char * s2,char * si)919*944b13ecSGary Mills exec_cat(const char *s1, const char *s2, char *si)
920*944b13ecSGary Mills {
921*944b13ecSGary Mills char *s;
922*944b13ecSGary Mills /* Number of remaining characters in s */
923*944b13ecSGary Mills int cnt = PATH_MAX + 1;
924*944b13ecSGary Mills
925*944b13ecSGary Mills s = si;
926*944b13ecSGary Mills while (*s1 && *s1 != ':') { /* Copy first component of path to si */
927*944b13ecSGary Mills if (cnt > 0) {
928*944b13ecSGary Mills *s++ = *s1++;
929*944b13ecSGary Mills cnt--;
930*944b13ecSGary Mills } else {
931*944b13ecSGary Mills s1++;
932*944b13ecSGary Mills }
933*944b13ecSGary Mills }
934*944b13ecSGary Mills if (si != s && cnt > 0) { /* Add slash if s2 is not absolute */
935*944b13ecSGary Mills *s++ = '/';
936*944b13ecSGary Mills cnt--;
937*944b13ecSGary Mills }
938*944b13ecSGary Mills while (*s2 && cnt > 0) { /* Copy s2 to si */
939*944b13ecSGary Mills *s++ = *s2++;
940*944b13ecSGary Mills cnt--;
941*944b13ecSGary Mills }
942*944b13ecSGary Mills *s = '\0'; /* Terminate the output string */
943*944b13ecSGary Mills return (*s1 ? ++s1 : NULL); /* Return next path component or NULL */
944*944b13ecSGary Mills }
945*944b13ecSGary Mills
946*944b13ecSGary Mills /* Determine that a name exists in PATH */
947*944b13ecSGary Mills /* Copied with changes from libtnfctl/prb_findexec.c */
948*944b13ecSGary Mills static int
path_find(const char * name)949*944b13ecSGary Mills path_find(const char *name)
950*944b13ecSGary Mills {
951*944b13ecSGary Mills const char *pathstr;
952*944b13ecSGary Mills char fname[PATH_MAX + 2];
953*944b13ecSGary Mills const char *cp;
954*944b13ecSGary Mills struct stat stat_buf;
955*944b13ecSGary Mills
956*944b13ecSGary Mills if ((pathstr = getenv("PATH")) == NULL) {
957*944b13ecSGary Mills if (geteuid() == 0 || getuid() == 0)
958*944b13ecSGary Mills pathstr = "/usr/sbin:/usr/bin";
959*944b13ecSGary Mills else
960*944b13ecSGary Mills pathstr = "/usr/bin:";
961*944b13ecSGary Mills }
962*944b13ecSGary Mills cp = strchr(name, '/') ? (const char *) "" : pathstr;
963*944b13ecSGary Mills
964*944b13ecSGary Mills do {
965*944b13ecSGary Mills cp = exec_cat(cp, name, fname);
966*944b13ecSGary Mills if (stat(fname, &stat_buf) != -1) {
967*944b13ecSGary Mills /* successful find of the file */
968*944b13ecSGary Mills return (0);
969*944b13ecSGary Mills }
970*944b13ecSGary Mills } while (cp != NULL);
971*944b13ecSGary Mills
972*944b13ecSGary Mills return (-1);
973*944b13ecSGary Mills }
974*944b13ecSGary Mills
975*944b13ecSGary Mills static FILE *
pager_open(void)976*944b13ecSGary Mills pager_open(void) {
977*944b13ecSGary Mills FILE *newfp;
978*944b13ecSGary Mills char *pager, *space;
979*944b13ecSGary Mills
980*944b13ecSGary Mills pager = getenv("PAGER");
981*944b13ecSGary Mills if (pager == NULL || *pager == '\0')
982*944b13ecSGary Mills pager = PAGER;
983*944b13ecSGary Mills
984*944b13ecSGary Mills space = strchr(pager, ' ');
985*944b13ecSGary Mills if (space)
986*944b13ecSGary Mills *space = '\0';
987*944b13ecSGary Mills if (path_find(pager) == 0) {
988*944b13ecSGary Mills if (space)
989*944b13ecSGary Mills *space = ' ';
990*944b13ecSGary Mills if ((newfp = popen(pager, "w")) == NULL)
991*944b13ecSGary Mills zerr(gettext("PAGER open failed (%s)."),
992*944b13ecSGary Mills strerror(errno));
993*944b13ecSGary Mills return (newfp);
994*944b13ecSGary Mills } else {
995*944b13ecSGary Mills zerr(gettext("PAGER %s does not exist (%s)."),
996*944b13ecSGary Mills pager, strerror(errno));
997*944b13ecSGary Mills }
998*944b13ecSGary Mills return (NULL);
999*944b13ecSGary Mills }
1000*944b13ecSGary Mills
1001*944b13ecSGary Mills static void
pager_close(FILE * fp)1002*944b13ecSGary Mills pager_close(FILE *fp) {
1003*944b13ecSGary Mills int status;
1004*944b13ecSGary Mills
1005*944b13ecSGary Mills status = pclose(fp);
1006*944b13ecSGary Mills if (status == -1)
1007*944b13ecSGary Mills zerr(gettext("PAGER close failed (%s)."),
1008*944b13ecSGary Mills strerror(errno));
1009*944b13ecSGary Mills }
1010*944b13ecSGary Mills
1011*944b13ecSGary Mills /*
10127c478bd9Sstevel@tonic-gate * Called with verbose TRUE when help is explicitly requested, FALSE for
10137c478bd9Sstevel@tonic-gate * unexpected errors.
10147c478bd9Sstevel@tonic-gate */
10157c478bd9Sstevel@tonic-gate
10167c478bd9Sstevel@tonic-gate void
usage(boolean_t verbose,uint_t flags)1017bbec428eSgjelinek usage(boolean_t verbose, uint_t flags)
10187c478bd9Sstevel@tonic-gate {
10193042b8b5Sbatschul FILE *fp = verbose ? stdout : stderr;
10203042b8b5Sbatschul FILE *newfp;
1021bbec428eSgjelinek boolean_t need_to_close = B_FALSE;
10227c478bd9Sstevel@tonic-gate int i;
10237c478bd9Sstevel@tonic-gate
10247c478bd9Sstevel@tonic-gate /* don't page error output */
10257c478bd9Sstevel@tonic-gate if (verbose && interactive_mode) {
1026*944b13ecSGary Mills if ((newfp = pager_open()) != NULL) {
1027bbec428eSgjelinek need_to_close = B_TRUE;
10287c478bd9Sstevel@tonic-gate fp = newfp;
10297c478bd9Sstevel@tonic-gate }
10303042b8b5Sbatschul }
10313042b8b5Sbatschul
10327c478bd9Sstevel@tonic-gate if (flags & HELP_META) {
10337c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("More help is available for the "
10347c478bd9Sstevel@tonic-gate "following:\n"));
10357c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\n\tcommands ('%s commands')\n",
10367c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP));
10377c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\tsyntax ('%s syntax')\n",
10387c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP));
10397c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\tusage ('%s usage')\n\n",
10407c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP));
10417c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("You may also obtain help on any "
10427c478bd9Sstevel@tonic-gate "command by typing '%s <command-name>.'\n"),
10437c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP));
10447c478bd9Sstevel@tonic-gate }
10457c478bd9Sstevel@tonic-gate if (flags & HELP_RES_SCOPE) {
10467c478bd9Sstevel@tonic-gate switch (resource_scope) {
10477c478bd9Sstevel@tonic-gate case RT_FS:
10487c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is "
10497c478bd9Sstevel@tonic-gate "used to configure a file-system.\n"),
10507c478bd9Sstevel@tonic-gate rt_to_str(resource_scope));
10517c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n"));
10527c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
10537c478bd9Sstevel@tonic-gate pt_to_str(PT_DIR), gettext("<path>"));
10547c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
10557c478bd9Sstevel@tonic-gate pt_to_str(PT_SPECIAL), gettext("<path>"));
10567c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
10577c478bd9Sstevel@tonic-gate pt_to_str(PT_RAW), gettext("<raw-device>"));
10587c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
10597c478bd9Sstevel@tonic-gate pt_to_str(PT_TYPE), gettext("<file-system type>"));
10607c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s %s\n", cmd_to_str(CMD_ADD),
10617c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS),
10627c478bd9Sstevel@tonic-gate gettext("<file-system options>"));
1063ffbafc53Scomay (void) fprintf(fp, "\t%s %s %s\n",
1064ffbafc53Scomay cmd_to_str(CMD_REMOVE), pt_to_str(PT_OPTIONS),
1065ffbafc53Scomay gettext("<file-system options>"));
10667c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Consult the file-system "
10677c478bd9Sstevel@tonic-gate "specific manual page, such as mount_ufs(1M), "
10687c478bd9Sstevel@tonic-gate "for\ndetails about file-system options. Note "
10697c478bd9Sstevel@tonic-gate "that any file-system options with an\nembedded "
10707c478bd9Sstevel@tonic-gate "'=' character must be enclosed in double quotes, "
10717c478bd9Sstevel@tonic-gate /*CSTYLED*/
10727c478bd9Sstevel@tonic-gate "such as \"%s=5\".\n"), MNTOPT_RETRY);
10737c478bd9Sstevel@tonic-gate break;
10747c478bd9Sstevel@tonic-gate case RT_NET:
10757c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is "
10767c478bd9Sstevel@tonic-gate "used to configure a network interface.\n"),
10777c478bd9Sstevel@tonic-gate rt_to_str(resource_scope));
10787c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n"));
10797c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
10807c478bd9Sstevel@tonic-gate pt_to_str(PT_ADDRESS), gettext("<IP-address>"));
10817c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
1082550b6e40SSowmini Varadhan pt_to_str(PT_ALLOWED_ADDRESS),
1083550b6e40SSowmini Varadhan gettext("<IP-address>"));
1084550b6e40SSowmini Varadhan (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
10857c478bd9Sstevel@tonic-gate pt_to_str(PT_PHYSICAL), gettext("<interface>"));
10867c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("See ifconfig(1M) for "
10877c478bd9Sstevel@tonic-gate "details of the <interface> string.\n"));
1088550b6e40SSowmini Varadhan (void) fprintf(fp, gettext("%s %s is valid "
1089550b6e40SSowmini Varadhan "if the %s property is set to %s, otherwise it "
1090de860bd9Sgfaden "must not be set.\n"),
1091f4b3ec61Sdh155122 cmd_to_str(CMD_SET), pt_to_str(PT_ADDRESS),
1092550b6e40SSowmini Varadhan pt_to_str(PT_IPTYPE), gettext("shared"));
1093550b6e40SSowmini Varadhan (void) fprintf(fp, gettext("%s %s is valid "
1094550b6e40SSowmini Varadhan "if the %s property is set to %s, otherwise it "
1095550b6e40SSowmini Varadhan "must not be set.\n"),
1096550b6e40SSowmini Varadhan cmd_to_str(CMD_SET), pt_to_str(PT_ALLOWED_ADDRESS),
1097550b6e40SSowmini Varadhan pt_to_str(PT_IPTYPE), gettext("exclusive"));
1098550b6e40SSowmini Varadhan (void) fprintf(fp, gettext("\t%s %s=%s\n%s %s "
1099550b6e40SSowmini Varadhan "is valid if the %s or %s property is set, "
1100550b6e40SSowmini Varadhan "otherwise it must not be set\n"),
1101550b6e40SSowmini Varadhan cmd_to_str(CMD_SET),
1102550b6e40SSowmini Varadhan pt_to_str(PT_DEFROUTER), gettext("<IP-address>"),
1103de860bd9Sgfaden cmd_to_str(CMD_SET), pt_to_str(PT_DEFROUTER),
1104550b6e40SSowmini Varadhan gettext(pt_to_str(PT_ADDRESS)),
1105550b6e40SSowmini Varadhan gettext(pt_to_str(PT_ALLOWED_ADDRESS)));
11067c478bd9Sstevel@tonic-gate break;
11077c478bd9Sstevel@tonic-gate case RT_DEVICE:
11087c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is "
11097c478bd9Sstevel@tonic-gate "used to configure a device node.\n"),
11107c478bd9Sstevel@tonic-gate rt_to_str(resource_scope));
11117c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n"));
11127c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
11137c478bd9Sstevel@tonic-gate pt_to_str(PT_MATCH), gettext("<device-path>"));
11147c478bd9Sstevel@tonic-gate break;
11157c478bd9Sstevel@tonic-gate case RT_RCTL:
11167c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is "
11177c478bd9Sstevel@tonic-gate "used to configure a resource control.\n"),
11187c478bd9Sstevel@tonic-gate rt_to_str(resource_scope));
11197c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n"));
11207c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
11217c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), gettext("<string>"));
11227c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s (%s=%s,%s=%s,%s=%s)\n",
11237c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), pt_to_str(PT_VALUE),
11247c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV), gettext("<priv-value>"),
11257c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT), gettext("<number>"),
11267c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION), gettext("<action-value>"));
1127ffbafc53Scomay (void) fprintf(fp, "\t%s %s (%s=%s,%s=%s,%s=%s)\n",
1128ffbafc53Scomay cmd_to_str(CMD_REMOVE), pt_to_str(PT_VALUE),
1129ffbafc53Scomay pt_to_str(PT_PRIV), gettext("<priv-value>"),
1130ffbafc53Scomay pt_to_str(PT_LIMIT), gettext("<number>"),
1131ffbafc53Scomay pt_to_str(PT_ACTION), gettext("<action-value>"));
11327c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s\n\t%s := privileged\n"
11337c478bd9Sstevel@tonic-gate "\t%s := none | deny\n", gettext("Where"),
11347c478bd9Sstevel@tonic-gate gettext("<priv-value>"), gettext("<action-value>"));
11357c478bd9Sstevel@tonic-gate break;
11367c478bd9Sstevel@tonic-gate case RT_ATTR:
11377c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is "
11387c478bd9Sstevel@tonic-gate "used to configure a generic attribute.\n"),
11397c478bd9Sstevel@tonic-gate rt_to_str(resource_scope));
11407c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n"));
11417c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
11427c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), gettext("<name>"));
11437c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=boolean\n",
11447c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_TYPE));
11457c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=true | false\n",
11467c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_VALUE));
11477c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("or\n"));
11487c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=int\n", cmd_to_str(CMD_SET),
11497c478bd9Sstevel@tonic-gate pt_to_str(PT_TYPE));
11507c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
11517c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), gettext("<integer>"));
11527c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("or\n"));
11537c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=string\n",
11547c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_TYPE));
11557c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
11567c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), gettext("<string>"));
11577c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("or\n"));
11587c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=uint\n",
11597c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_TYPE));
11607c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
11617c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), gettext("<unsigned integer>"));
11627c478bd9Sstevel@tonic-gate break;
1163fa9e4066Sahrens case RT_DATASET:
1164fa9e4066Sahrens (void) fprintf(fp, gettext("The '%s' resource scope is "
1165fa9e4066Sahrens "used to export ZFS datasets.\n"),
1166fa9e4066Sahrens rt_to_str(resource_scope));
1167fa9e4066Sahrens (void) fprintf(fp, gettext("Valid commands:\n"));
1168fa9e4066Sahrens (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
1169fa9e4066Sahrens pt_to_str(PT_NAME), gettext("<name>"));
1170fa9e4066Sahrens break;
11710209230bSgjelinek case RT_DCPU:
11720209230bSgjelinek (void) fprintf(fp, gettext("The '%s' resource scope "
11730209230bSgjelinek "configures the 'pools' facility to dedicate\na "
11740209230bSgjelinek "subset of the system's processors to this zone "
11750209230bSgjelinek "while it is running.\n"),
11760209230bSgjelinek rt_to_str(resource_scope));
11770209230bSgjelinek (void) fprintf(fp, gettext("Valid commands:\n"));
11780209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
11790209230bSgjelinek pt_to_str(PT_NCPUS),
11800209230bSgjelinek gettext("<unsigned integer | range>"));
11810209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
11820209230bSgjelinek pt_to_str(PT_IMPORTANCE),
11830209230bSgjelinek gettext("<unsigned integer>"));
11840209230bSgjelinek break;
1185c97ad5cdSakolb case RT_PCAP:
1186c97ad5cdSakolb (void) fprintf(fp, gettext("The '%s' resource scope is "
1187c97ad5cdSakolb "used to set an upper limit (a cap) on the\n"
1188c97ad5cdSakolb "percentage of CPU that can be used by this zone. "
1189c97ad5cdSakolb "A '%s' value of 1\ncorresponds to one cpu. The "
1190c97ad5cdSakolb "value can be set higher than 1, up to the total\n"
1191c97ad5cdSakolb "number of CPUs on the system. The value can "
1192c97ad5cdSakolb "also be less than 1,\nrepresenting a fraction of "
1193c97ad5cdSakolb "a cpu.\n"),
1194c97ad5cdSakolb rt_to_str(resource_scope), pt_to_str(PT_NCPUS));
1195c97ad5cdSakolb (void) fprintf(fp, gettext("Valid commands:\n"));
1196c97ad5cdSakolb (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
1197c97ad5cdSakolb pt_to_str(PT_NCPUS), gettext("<unsigned decimal>"));
1198c97ad5cdSakolb break;
11990209230bSgjelinek case RT_MCAP:
12000209230bSgjelinek (void) fprintf(fp, gettext("The '%s' resource scope is "
12010209230bSgjelinek "used to set an upper limit (a cap) on the\n"
12020209230bSgjelinek "amount of physical memory, swap space and locked "
12030209230bSgjelinek "memory that can be used by\nthis zone.\n"),
12040209230bSgjelinek rt_to_str(resource_scope));
12050209230bSgjelinek (void) fprintf(fp, gettext("Valid commands:\n"));
12060209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
12070209230bSgjelinek pt_to_str(PT_PHYSICAL),
12080209230bSgjelinek gettext("<qualified unsigned decimal>"));
12090209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
12100209230bSgjelinek pt_to_str(PT_SWAP),
12110209230bSgjelinek gettext("<qualified unsigned decimal>"));
12120209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
12130209230bSgjelinek pt_to_str(PT_LOCKED),
12140209230bSgjelinek gettext("<qualified unsigned decimal>"));
12150209230bSgjelinek break;
1216cb8a054bSGlenn Faden case RT_ADMIN:
1217cb8a054bSGlenn Faden (void) fprintf(fp, gettext("The '%s' resource scope is "
1218cb8a054bSGlenn Faden "used to delegate specific zone management\n"
1219cb8a054bSGlenn Faden "rights to users and roles. These rights are "
1220cb8a054bSGlenn Faden "only applicable to this zone.\n"),
1221cb8a054bSGlenn Faden rt_to_str(resource_scope));
1222cb8a054bSGlenn Faden (void) fprintf(fp, gettext("Valid commands:\n"));
1223cb8a054bSGlenn Faden (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
1224cb8a054bSGlenn Faden pt_to_str(PT_USER),
1225cb8a054bSGlenn Faden gettext("<single user or role name>"));
1226cb8a054bSGlenn Faden (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
1227cb8a054bSGlenn Faden pt_to_str(PT_AUTHS),
1228cb8a054bSGlenn Faden gettext("<comma separated list>"));
1229cb8a054bSGlenn Faden break;
12307c478bd9Sstevel@tonic-gate }
12317c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("And from any resource scope, you "
12327c478bd9Sstevel@tonic-gate "can:\n"));
12337c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", cmd_to_str(CMD_END),
12347c478bd9Sstevel@tonic-gate gettext("(to conclude this operation)"));
12357c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", cmd_to_str(CMD_CANCEL),
12367c478bd9Sstevel@tonic-gate gettext("(to cancel this operation)"));
12377c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", cmd_to_str(CMD_EXIT),
12387c478bd9Sstevel@tonic-gate gettext("(to exit the zonecfg utility)"));
12397c478bd9Sstevel@tonic-gate }
12407c478bd9Sstevel@tonic-gate if (flags & HELP_USAGE) {
12417c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\t%s %s\n", gettext("usage"),
12427c478bd9Sstevel@tonic-gate execname, cmd_to_str(CMD_HELP));
12437c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s -z <zone>\t\t\t(%s)\n",
12447c478bd9Sstevel@tonic-gate execname, gettext("interactive"));
12457c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s -z <zone> <command>\n", execname);
12467c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s -z <zone> -f <command-file>\n",
12477c478bd9Sstevel@tonic-gate execname);
12487c478bd9Sstevel@tonic-gate }
12497c478bd9Sstevel@tonic-gate if (flags & HELP_SUBCMDS) {
12507c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n\n", gettext("Commands"));
12517c478bd9Sstevel@tonic-gate for (i = 0; i <= CMD_MAX; i++) {
12527c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s\n", helptab[i].short_usage);
12537c478bd9Sstevel@tonic-gate if (verbose)
12547c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\n\n", long_help(i));
12557c478bd9Sstevel@tonic-gate }
12567c478bd9Sstevel@tonic-gate }
12577c478bd9Sstevel@tonic-gate if (flags & HELP_SYNTAX) {
12587c478bd9Sstevel@tonic-gate if (!verbose)
12597c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\n");
12607c478bd9Sstevel@tonic-gate (void) fprintf(fp, "<zone> := [A-Za-z0-9][A-Za-z0-9_.-]*\n");
12617c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("\t(except the reserved words "
12627c478bd9Sstevel@tonic-gate "'%s' and anything starting with '%s')\n"), "global",
12637c478bd9Sstevel@tonic-gate "SUNW");
12647c478bd9Sstevel@tonic-gate (void) fprintf(fp,
12657c478bd9Sstevel@tonic-gate gettext("\tName must be less than %d characters.\n"),
12667c478bd9Sstevel@tonic-gate ZONENAME_MAX);
12677c478bd9Sstevel@tonic-gate if (verbose)
12687c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\n");
12697c478bd9Sstevel@tonic-gate }
12707c478bd9Sstevel@tonic-gate if (flags & HELP_NETADDR) {
12717c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("\n<net-addr> :="));
12727c478bd9Sstevel@tonic-gate (void) fprintf(fp,
12737c478bd9Sstevel@tonic-gate gettext("\t<IPv4-address>[/<IPv4-prefix-length>] |\n"));
12747c478bd9Sstevel@tonic-gate (void) fprintf(fp,
12757c478bd9Sstevel@tonic-gate gettext("\t\t<IPv6-address>/<IPv6-prefix-length> |\n"));
12767c478bd9Sstevel@tonic-gate (void) fprintf(fp,
12777c478bd9Sstevel@tonic-gate gettext("\t\t<hostname>[/<IPv4-prefix-length>]\n"));
12787c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("See inet(3SOCKET) for IPv4 and "
12797c478bd9Sstevel@tonic-gate "IPv6 address syntax.\n"));
12807c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("<IPv4-prefix-length> := [0-32]\n"));
12817c478bd9Sstevel@tonic-gate (void) fprintf(fp,
12827c478bd9Sstevel@tonic-gate gettext("<IPv6-prefix-length> := [0-128]\n"));
12837c478bd9Sstevel@tonic-gate (void) fprintf(fp,
12847c478bd9Sstevel@tonic-gate gettext("<hostname> := [A-Za-z0-9][A-Za-z0-9-.]*\n"));
12857c478bd9Sstevel@tonic-gate }
12867c478bd9Sstevel@tonic-gate if (flags & HELP_RESOURCES) {
12876e1ae2a3SGary Pennington (void) fprintf(fp, "<%s> := %s | %s | %s | %s | %s |\n\t"
1288cb8a054bSGlenn Faden "%s | %s | %s | %s | %s\n\n",
12897c478bd9Sstevel@tonic-gate gettext("resource type"), rt_to_str(RT_FS),
12906e1ae2a3SGary Pennington rt_to_str(RT_NET), rt_to_str(RT_DEVICE),
12919e7542f4Sdp rt_to_str(RT_RCTL), rt_to_str(RT_ATTR),
12920209230bSgjelinek rt_to_str(RT_DATASET), rt_to_str(RT_DCPU),
1293cb8a054bSGlenn Faden rt_to_str(RT_PCAP), rt_to_str(RT_MCAP),
1294cb8a054bSGlenn Faden rt_to_str(RT_ADMIN));
12957c478bd9Sstevel@tonic-gate }
12967c478bd9Sstevel@tonic-gate if (flags & HELP_PROPS) {
12977c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("For resource type ... there are "
12987c478bd9Sstevel@tonic-gate "property types ...:\n"));
12997c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
1300087719fdSdp pt_to_str(PT_ZONENAME));
1301087719fdSdp (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
13027c478bd9Sstevel@tonic-gate pt_to_str(PT_ZONEPATH));
13037c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
13049acbbeafSnn35248 pt_to_str(PT_BRAND));
13059acbbeafSnn35248 (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
13067c478bd9Sstevel@tonic-gate pt_to_str(PT_AUTOBOOT));
13077c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
13083f2f09c1Sdp pt_to_str(PT_BOOTARGS));
13093f2f09c1Sdp (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
13107c478bd9Sstevel@tonic-gate pt_to_str(PT_POOL));
1311ffbafc53Scomay (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
1312ffbafc53Scomay pt_to_str(PT_LIMITPRIV));
13130209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
13140209230bSgjelinek pt_to_str(PT_SCHED));
13150209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
1316f4b3ec61Sdh155122 pt_to_str(PT_IPTYPE));
1317f4b3ec61Sdh155122 (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
13185679c89fSjv227347 pt_to_str(PT_HOSTID));
13195679c89fSjv227347 (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
13200fbb751dSJohn Levon pt_to_str(PT_FS_ALLOWED));
13210fbb751dSJohn Levon (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
13220209230bSgjelinek pt_to_str(PT_MAXLWPS));
13230209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
1324ff19e029SMenno Lageman pt_to_str(PT_MAXPROCS));
1325ff19e029SMenno Lageman (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
13260209230bSgjelinek pt_to_str(PT_MAXSHMMEM));
13270209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
13280209230bSgjelinek pt_to_str(PT_MAXSHMIDS));
13290209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
13300209230bSgjelinek pt_to_str(PT_MAXMSGIDS));
13310209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
13320209230bSgjelinek pt_to_str(PT_MAXSEMIDS));
13330209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
13340209230bSgjelinek pt_to_str(PT_SHARES));
13356d4d1c0dSbatschul (void) fprintf(fp, "\t%s\t\t%s, %s, %s, %s, %s\n",
13366d4d1c0dSbatschul rt_to_str(RT_FS), pt_to_str(PT_DIR),
13376d4d1c0dSbatschul pt_to_str(PT_SPECIAL), pt_to_str(PT_RAW),
13386d4d1c0dSbatschul pt_to_str(PT_TYPE), pt_to_str(PT_OPTIONS));
1339550b6e40SSowmini Varadhan (void) fprintf(fp, "\t%s\t\t%s, %s, %s|%s\n", rt_to_str(RT_NET),
1340550b6e40SSowmini Varadhan pt_to_str(PT_ADDRESS), pt_to_str(PT_ALLOWED_ADDRESS),
1341550b6e40SSowmini Varadhan pt_to_str(PT_PHYSICAL), pt_to_str(PT_DEFROUTER));
13427c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s\n", rt_to_str(RT_DEVICE),
13437c478bd9Sstevel@tonic-gate pt_to_str(PT_MATCH));
13447c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s, %s\n", rt_to_str(RT_RCTL),
13457c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), pt_to_str(PT_VALUE));
13467c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s, %s, %s\n", rt_to_str(RT_ATTR),
13477c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), pt_to_str(PT_TYPE),
13487c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE));
1349fa9e4066Sahrens (void) fprintf(fp, "\t%s\t\t%s\n", rt_to_str(RT_DATASET),
1350fa9e4066Sahrens pt_to_str(PT_NAME));
13510209230bSgjelinek (void) fprintf(fp, "\t%s\t%s, %s\n", rt_to_str(RT_DCPU),
13520209230bSgjelinek pt_to_str(PT_NCPUS), pt_to_str(PT_IMPORTANCE));
1353c97ad5cdSakolb (void) fprintf(fp, "\t%s\t%s\n", rt_to_str(RT_PCAP),
1354c97ad5cdSakolb pt_to_str(PT_NCPUS));
13550209230bSgjelinek (void) fprintf(fp, "\t%s\t%s, %s, %s\n", rt_to_str(RT_MCAP),
13560209230bSgjelinek pt_to_str(PT_PHYSICAL), pt_to_str(PT_SWAP),
13570209230bSgjelinek pt_to_str(PT_LOCKED));
1358cb8a054bSGlenn Faden (void) fprintf(fp, "\t%s\t\t%s, %s\n", rt_to_str(RT_ADMIN),
1359cb8a054bSGlenn Faden pt_to_str(PT_USER), pt_to_str(PT_AUTHS));
13607c478bd9Sstevel@tonic-gate }
13617c478bd9Sstevel@tonic-gate if (need_to_close)
1362*944b13ecSGary Mills (void) pager_close(fp);
13637c478bd9Sstevel@tonic-gate }
13647c478bd9Sstevel@tonic-gate
13657c478bd9Sstevel@tonic-gate static void
zone_perror(char * prefix,int err,boolean_t set_saw)1366bbec428eSgjelinek zone_perror(char *prefix, int err, boolean_t set_saw)
13677c478bd9Sstevel@tonic-gate {
13687c478bd9Sstevel@tonic-gate zerr("%s: %s", prefix, zonecfg_strerror(err));
13697c478bd9Sstevel@tonic-gate if (set_saw)
1370bbec428eSgjelinek saw_error = B_TRUE;
13717c478bd9Sstevel@tonic-gate }
13727c478bd9Sstevel@tonic-gate
13737c478bd9Sstevel@tonic-gate /*
13747c478bd9Sstevel@tonic-gate * zone_perror() expects a single string, but for remove and select
13757c478bd9Sstevel@tonic-gate * we have both the command and the resource type, so this wrapper
13767c478bd9Sstevel@tonic-gate * function serves the same purpose in a slightly different way.
13777c478bd9Sstevel@tonic-gate */
13787c478bd9Sstevel@tonic-gate
13797c478bd9Sstevel@tonic-gate static void
z_cmd_rt_perror(int cmd_num,int res_num,int err,boolean_t set_saw)1380bbec428eSgjelinek z_cmd_rt_perror(int cmd_num, int res_num, int err, boolean_t set_saw)
13817c478bd9Sstevel@tonic-gate {
13827c478bd9Sstevel@tonic-gate zerr("%s %s: %s", cmd_to_str(cmd_num), rt_to_str(res_num),
13837c478bd9Sstevel@tonic-gate zonecfg_strerror(err));
13847c478bd9Sstevel@tonic-gate if (set_saw)
1385bbec428eSgjelinek saw_error = B_TRUE;
13867c478bd9Sstevel@tonic-gate }
13877c478bd9Sstevel@tonic-gate
13887c478bd9Sstevel@tonic-gate /* returns Z_OK if successful, Z_foo from <libzonecfg.h> otherwise */
13897c478bd9Sstevel@tonic-gate static int
initialize(boolean_t handle_expected)1390bbec428eSgjelinek initialize(boolean_t handle_expected)
13917c478bd9Sstevel@tonic-gate {
13927c478bd9Sstevel@tonic-gate int err;
13939acbbeafSnn35248 char brandname[MAXNAMELEN];
13947c478bd9Sstevel@tonic-gate
13957c478bd9Sstevel@tonic-gate if (zonecfg_check_handle(handle) != Z_OK) {
13967c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_handle(zone, handle)) == Z_OK) {
1397bbec428eSgjelinek got_handle = B_TRUE;
13989acbbeafSnn35248 if (zonecfg_get_brand(handle, brandname,
13999acbbeafSnn35248 sizeof (brandname)) != Z_OK) {
14009acbbeafSnn35248 zerr("Zone %s is inconsistent: missing "
14019acbbeafSnn35248 "brand attribute", zone);
14029acbbeafSnn35248 exit(Z_ERR);
14039acbbeafSnn35248 }
14049acbbeafSnn35248 if ((brand = brand_open(brandname)) == NULL) {
14059acbbeafSnn35248 zerr("Zone %s uses non-existent brand \"%s\"."
14069acbbeafSnn35248 " Unable to continue", zone, brandname);
14079acbbeafSnn35248 exit(Z_ERR);
14089acbbeafSnn35248 }
1409cb8a054bSGlenn Faden /*
1410cb8a054bSGlenn Faden * If the user_attr file is newer than
1411cb8a054bSGlenn Faden * the zone config file, the admins
1412cb8a054bSGlenn Faden * may need to be updated since the
1413cb8a054bSGlenn Faden * RBAC files are authoritative for
1414cb8a054bSGlenn Faden * authorization checks.
1415cb8a054bSGlenn Faden */
1416cb8a054bSGlenn Faden err = zonecfg_update_userauths(handle, zone);
1417cb8a054bSGlenn Faden if (err == Z_OK) {
1418cb8a054bSGlenn Faden zerr(gettext("The administrative rights "
1419cb8a054bSGlenn Faden "were updated to match "
1420cb8a054bSGlenn Faden "the current RBAC configuration.\n"
1421cb8a054bSGlenn Faden "Use \"info admin\" and \"revert\" to "
1422cb8a054bSGlenn Faden "compare with the previous settings."));
1423cb8a054bSGlenn Faden need_to_commit = B_TRUE;
1424cb8a054bSGlenn Faden } else if (err != Z_NO_ENTRY) {
1425cb8a054bSGlenn Faden zerr(gettext("failed to update "
1426cb8a054bSGlenn Faden "admin rights."));
1427cb8a054bSGlenn Faden exit(Z_ERR);
1428cb8a054bSGlenn Faden } else if (need_to_commit) {
1429cb8a054bSGlenn Faden zerr(gettext("admin rights were updated "
1430cb8a054bSGlenn Faden "to match RBAC configuration."));
1431cb8a054bSGlenn Faden }
1432cb8a054bSGlenn Faden
14330209230bSgjelinek } else if (global_zone && err == Z_NO_ZONE && !got_handle &&
14340209230bSgjelinek !read_only_mode) {
14350209230bSgjelinek /*
14360209230bSgjelinek * We implicitly create the global zone config if it
14370209230bSgjelinek * doesn't exist.
14380209230bSgjelinek */
14390209230bSgjelinek zone_dochandle_t tmphandle;
14400209230bSgjelinek
14410209230bSgjelinek if ((tmphandle = zonecfg_init_handle()) == NULL) {
1442bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE);
14430209230bSgjelinek exit(Z_ERR);
14440209230bSgjelinek }
14450209230bSgjelinek
14460209230bSgjelinek err = zonecfg_get_template_handle("SUNWblank", zone,
14470209230bSgjelinek tmphandle);
14480209230bSgjelinek
14490209230bSgjelinek if (err != Z_OK) {
14500209230bSgjelinek zonecfg_fini_handle(tmphandle);
1451bbec428eSgjelinek zone_perror("SUNWblank", err, B_TRUE);
14520209230bSgjelinek return (err);
14530209230bSgjelinek }
14540209230bSgjelinek
1455bbec428eSgjelinek need_to_commit = B_TRUE;
14560209230bSgjelinek zonecfg_fini_handle(handle);
14570209230bSgjelinek handle = tmphandle;
1458bbec428eSgjelinek got_handle = B_TRUE;
14590209230bSgjelinek
14607c478bd9Sstevel@tonic-gate } else {
14617c478bd9Sstevel@tonic-gate zone_perror(zone, err, handle_expected || got_handle);
14627c478bd9Sstevel@tonic-gate if (err == Z_NO_ZONE && !got_handle &&
14637c478bd9Sstevel@tonic-gate interactive_mode && !read_only_mode)
14647c478bd9Sstevel@tonic-gate (void) printf(gettext("Use '%s' to begin "
14657c478bd9Sstevel@tonic-gate "configuring a new zone.\n"),
14667c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE));
14677c478bd9Sstevel@tonic-gate return (err);
14687c478bd9Sstevel@tonic-gate }
14697c478bd9Sstevel@tonic-gate }
14707c478bd9Sstevel@tonic-gate return (Z_OK);
14717c478bd9Sstevel@tonic-gate }
14727c478bd9Sstevel@tonic-gate
1473bbec428eSgjelinek static boolean_t
state_atleast(zone_state_t state)1474087719fdSdp state_atleast(zone_state_t state)
1475087719fdSdp {
1476087719fdSdp zone_state_t state_num;
1477087719fdSdp int err;
1478087719fdSdp
1479087719fdSdp if ((err = zone_get_state(zone, &state_num)) != Z_OK) {
1480087719fdSdp /* all states are greater than "non-existent" */
1481087719fdSdp if (err == Z_NO_ZONE)
1482087719fdSdp return (B_FALSE);
1483087719fdSdp zerr(gettext("Unexpectedly failed to determine state "
1484087719fdSdp "of zone %s: %s"), zone, zonecfg_strerror(err));
1485087719fdSdp exit(Z_ERR);
1486087719fdSdp }
1487087719fdSdp return (state_num >= state);
1488087719fdSdp }
1489087719fdSdp
14907c478bd9Sstevel@tonic-gate /*
14917c478bd9Sstevel@tonic-gate * short_usage() is for bad syntax: getopt() issues, too many arguments, etc.
14927c478bd9Sstevel@tonic-gate */
14937c478bd9Sstevel@tonic-gate
14947c478bd9Sstevel@tonic-gate void
short_usage(int command)14957c478bd9Sstevel@tonic-gate short_usage(int command)
14967c478bd9Sstevel@tonic-gate {
14977c478bd9Sstevel@tonic-gate /* lex_lineno has already been incremented in the lexer; compensate */
14987c478bd9Sstevel@tonic-gate if (cmd_file_mode) {
14997c478bd9Sstevel@tonic-gate if (strcmp(cmd_file_name, "-") == 0)
15007c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
15017c478bd9Sstevel@tonic-gate gettext("syntax error on line %d\n"),
15027c478bd9Sstevel@tonic-gate lex_lineno - 1);
15037c478bd9Sstevel@tonic-gate else
15047c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
15057c478bd9Sstevel@tonic-gate gettext("syntax error on line %d of %s\n"),
15067c478bd9Sstevel@tonic-gate lex_lineno - 1, cmd_file_name);
15077c478bd9Sstevel@tonic-gate }
15087c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s:\n%s\n", gettext("usage"),
15097c478bd9Sstevel@tonic-gate helptab[command].short_usage);
1510bbec428eSgjelinek saw_error = B_TRUE;
15117c478bd9Sstevel@tonic-gate }
15127c478bd9Sstevel@tonic-gate
15137c478bd9Sstevel@tonic-gate /*
15147c478bd9Sstevel@tonic-gate * long_usage() is for bad semantics: e.g., wrong property type for a given
15157c478bd9Sstevel@tonic-gate * resource type. It is also used by longer_usage() below.
15167c478bd9Sstevel@tonic-gate */
15177c478bd9Sstevel@tonic-gate
15187c478bd9Sstevel@tonic-gate void
long_usage(uint_t cmd_num,boolean_t set_saw)1519bbec428eSgjelinek long_usage(uint_t cmd_num, boolean_t set_saw)
15207c478bd9Sstevel@tonic-gate {
15217c478bd9Sstevel@tonic-gate (void) fprintf(set_saw ? stderr : stdout, "%s:\n%s\n", gettext("usage"),
15227c478bd9Sstevel@tonic-gate helptab[cmd_num].short_usage);
15237c478bd9Sstevel@tonic-gate (void) fprintf(set_saw ? stderr : stdout, "\t%s\n", long_help(cmd_num));
15247c478bd9Sstevel@tonic-gate if (set_saw)
1525bbec428eSgjelinek saw_error = B_TRUE;
15267c478bd9Sstevel@tonic-gate }
15277c478bd9Sstevel@tonic-gate
15287c478bd9Sstevel@tonic-gate /*
15297c478bd9Sstevel@tonic-gate * longer_usage() is for 'help foo' and 'foo -?': call long_usage() and also
15307c478bd9Sstevel@tonic-gate * any extra usage() flags as appropriate for whatever command.
15317c478bd9Sstevel@tonic-gate */
15327c478bd9Sstevel@tonic-gate
15337c478bd9Sstevel@tonic-gate void
longer_usage(uint_t cmd_num)15347c478bd9Sstevel@tonic-gate longer_usage(uint_t cmd_num)
15357c478bd9Sstevel@tonic-gate {
1536bbec428eSgjelinek long_usage(cmd_num, B_FALSE);
15377c478bd9Sstevel@tonic-gate if (helptab[cmd_num].flags != 0) {
15387c478bd9Sstevel@tonic-gate (void) printf("\n");
1539bbec428eSgjelinek usage(B_TRUE, helptab[cmd_num].flags);
15407c478bd9Sstevel@tonic-gate }
15417c478bd9Sstevel@tonic-gate }
15427c478bd9Sstevel@tonic-gate
15437c478bd9Sstevel@tonic-gate /*
15447c478bd9Sstevel@tonic-gate * scope_usage() is simply used when a command is called from the wrong scope.
15457c478bd9Sstevel@tonic-gate */
15467c478bd9Sstevel@tonic-gate
15477c478bd9Sstevel@tonic-gate static void
scope_usage(uint_t cmd_num)15487c478bd9Sstevel@tonic-gate scope_usage(uint_t cmd_num)
15497c478bd9Sstevel@tonic-gate {
15507c478bd9Sstevel@tonic-gate zerr(gettext("The %s command only makes sense in the %s scope."),
15517c478bd9Sstevel@tonic-gate cmd_to_str(cmd_num),
15527c478bd9Sstevel@tonic-gate global_scope ? gettext("resource") : gettext("global"));
1553bbec428eSgjelinek saw_error = B_TRUE;
15547c478bd9Sstevel@tonic-gate }
15557c478bd9Sstevel@tonic-gate
15567c478bd9Sstevel@tonic-gate /*
1557bbec428eSgjelinek * On input, B_TRUE => yes, B_FALSE => no.
1558bbec428eSgjelinek * On return, B_TRUE => 1, B_FALSE => no, could not ask => -1.
15597c478bd9Sstevel@tonic-gate */
15607c478bd9Sstevel@tonic-gate
15617c478bd9Sstevel@tonic-gate static int
ask_yesno(boolean_t default_answer,const char * question)1562bbec428eSgjelinek ask_yesno(boolean_t default_answer, const char *question)
15637c478bd9Sstevel@tonic-gate {
15647c478bd9Sstevel@tonic-gate char line[64]; /* should be enough to answer yes or no */
15657c478bd9Sstevel@tonic-gate
15667c478bd9Sstevel@tonic-gate if (!ok_to_prompt) {
1567bbec428eSgjelinek saw_error = B_TRUE;
15687c478bd9Sstevel@tonic-gate return (-1);
15697c478bd9Sstevel@tonic-gate }
15707c478bd9Sstevel@tonic-gate for (;;) {
1571087719fdSdp if (printf("%s (%s)? ", question,
1572087719fdSdp default_answer ? "[y]/n" : "y/[n]") < 0)
1573087719fdSdp return (-1);
1574087719fdSdp if (fgets(line, sizeof (line), stdin) == NULL)
1575087719fdSdp return (-1);
1576087719fdSdp
1577087719fdSdp if (line[0] == '\n')
15787c478bd9Sstevel@tonic-gate return (default_answer ? 1 : 0);
15797c478bd9Sstevel@tonic-gate if (tolower(line[0]) == 'y')
15807c478bd9Sstevel@tonic-gate return (1);
15817c478bd9Sstevel@tonic-gate if (tolower(line[0]) == 'n')
15827c478bd9Sstevel@tonic-gate return (0);
15837c478bd9Sstevel@tonic-gate }
15847c478bd9Sstevel@tonic-gate }
15857c478bd9Sstevel@tonic-gate
15867c478bd9Sstevel@tonic-gate /*
15877c478bd9Sstevel@tonic-gate * Prints warning if zone already exists.
15887c478bd9Sstevel@tonic-gate * In interactive mode, prompts if we should continue anyway and returns Z_OK
15897c478bd9Sstevel@tonic-gate * if so, Z_ERR if not. In non-interactive mode, exits with Z_ERR.
15907c478bd9Sstevel@tonic-gate *
15917c478bd9Sstevel@tonic-gate * Note that if a zone exists and its state is >= INSTALLED, an error message
15927c478bd9Sstevel@tonic-gate * will be printed and this function will return Z_ERR regardless of mode.
15937c478bd9Sstevel@tonic-gate */
15947c478bd9Sstevel@tonic-gate
15957c478bd9Sstevel@tonic-gate static int
check_if_zone_already_exists(boolean_t force)1596bbec428eSgjelinek check_if_zone_already_exists(boolean_t force)
15977c478bd9Sstevel@tonic-gate {
15987c478bd9Sstevel@tonic-gate char line[ZONENAME_MAX + 128]; /* enough to ask a question */
15997c478bd9Sstevel@tonic-gate zone_dochandle_t tmphandle;
16007c478bd9Sstevel@tonic-gate int res, answer;
16017c478bd9Sstevel@tonic-gate
16027c478bd9Sstevel@tonic-gate if ((tmphandle = zonecfg_init_handle()) == NULL) {
1603bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE);
16047c478bd9Sstevel@tonic-gate exit(Z_ERR);
16057c478bd9Sstevel@tonic-gate }
16067c478bd9Sstevel@tonic-gate res = zonecfg_get_handle(zone, tmphandle);
16077c478bd9Sstevel@tonic-gate zonecfg_fini_handle(tmphandle);
1608087719fdSdp if (res != Z_OK)
16097c478bd9Sstevel@tonic-gate return (Z_OK);
1610087719fdSdp
1611087719fdSdp if (state_atleast(ZONE_STATE_INSTALLED)) {
16127c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s already installed; %s not allowed."),
16137c478bd9Sstevel@tonic-gate zone, cmd_to_str(CMD_CREATE));
16147c478bd9Sstevel@tonic-gate return (Z_ERR);
16157c478bd9Sstevel@tonic-gate }
16167c478bd9Sstevel@tonic-gate
16177c478bd9Sstevel@tonic-gate if (force) {
16187c478bd9Sstevel@tonic-gate (void) printf(gettext("Zone %s already exists; overwriting.\n"),
16197c478bd9Sstevel@tonic-gate zone);
16207c478bd9Sstevel@tonic-gate return (Z_OK);
16217c478bd9Sstevel@tonic-gate }
16227c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line),
16237c478bd9Sstevel@tonic-gate gettext("Zone %s already exists; %s anyway"), zone,
16247c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE));
1625bbec428eSgjelinek if ((answer = ask_yesno(B_FALSE, line)) == -1) {
16267c478bd9Sstevel@tonic-gate zerr(gettext("Zone exists, input not from terminal and -F not "
16277c478bd9Sstevel@tonic-gate "specified:\n%s command ignored, exiting."),
16287c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE));
16297c478bd9Sstevel@tonic-gate exit(Z_ERR);
16307c478bd9Sstevel@tonic-gate }
16317c478bd9Sstevel@tonic-gate return (answer == 1 ? Z_OK : Z_ERR);
16327c478bd9Sstevel@tonic-gate }
16337c478bd9Sstevel@tonic-gate
1634bbec428eSgjelinek static boolean_t
zone_is_read_only(int cmd_num)16357c478bd9Sstevel@tonic-gate zone_is_read_only(int cmd_num)
16367c478bd9Sstevel@tonic-gate {
16377c478bd9Sstevel@tonic-gate if (strncmp(zone, "SUNW", 4) == 0) {
16387c478bd9Sstevel@tonic-gate zerr(gettext("%s: zones beginning with SUNW are read-only."),
16397c478bd9Sstevel@tonic-gate zone);
1640bbec428eSgjelinek saw_error = B_TRUE;
1641bbec428eSgjelinek return (B_TRUE);
16427c478bd9Sstevel@tonic-gate }
16437c478bd9Sstevel@tonic-gate if (read_only_mode) {
16447c478bd9Sstevel@tonic-gate zerr(gettext("%s: cannot %s in read-only mode."), zone,
16457c478bd9Sstevel@tonic-gate cmd_to_str(cmd_num));
1646bbec428eSgjelinek saw_error = B_TRUE;
1647bbec428eSgjelinek return (B_TRUE);
16487c478bd9Sstevel@tonic-gate }
1649bbec428eSgjelinek return (B_FALSE);
16507c478bd9Sstevel@tonic-gate }
16517c478bd9Sstevel@tonic-gate
16527c478bd9Sstevel@tonic-gate /*
16537c478bd9Sstevel@tonic-gate * Create a new configuration.
16547c478bd9Sstevel@tonic-gate */
16557c478bd9Sstevel@tonic-gate void
create_func(cmd_t * cmd)16567c478bd9Sstevel@tonic-gate create_func(cmd_t *cmd)
16577c478bd9Sstevel@tonic-gate {
16587c478bd9Sstevel@tonic-gate int err, arg;
16597c478bd9Sstevel@tonic-gate char zone_template[ZONENAME_MAX];
1660ee519a1fSgjelinek char attach_path[MAXPATHLEN];
16617c478bd9Sstevel@tonic-gate zone_dochandle_t tmphandle;
1662bbec428eSgjelinek boolean_t force = B_FALSE;
1663bbec428eSgjelinek boolean_t attach = B_FALSE;
1664bbec428eSgjelinek boolean_t arg_err = B_FALSE;
16657c478bd9Sstevel@tonic-gate
16667c478bd9Sstevel@tonic-gate assert(cmd != NULL);
16677c478bd9Sstevel@tonic-gate
16687c478bd9Sstevel@tonic-gate /* This is the default if no arguments are given. */
16697c478bd9Sstevel@tonic-gate (void) strlcpy(zone_template, "SUNWdefault", sizeof (zone_template));
16707c478bd9Sstevel@tonic-gate
16717c478bd9Sstevel@tonic-gate optind = 0;
16729acbbeafSnn35248 while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?a:bFt:"))
16739acbbeafSnn35248 != EOF) {
16747c478bd9Sstevel@tonic-gate switch (arg) {
16757c478bd9Sstevel@tonic-gate case '?':
16767c478bd9Sstevel@tonic-gate if (optopt == '?')
16777c478bd9Sstevel@tonic-gate longer_usage(CMD_CREATE);
16787c478bd9Sstevel@tonic-gate else
16797c478bd9Sstevel@tonic-gate short_usage(CMD_CREATE);
1680bbec428eSgjelinek arg_err = B_TRUE;
16817ec75eb8Sgjelinek break;
1682ee519a1fSgjelinek case 'a':
1683ee519a1fSgjelinek (void) strlcpy(attach_path, optarg,
1684ee519a1fSgjelinek sizeof (attach_path));
1685bbec428eSgjelinek attach = B_TRUE;
1686ee519a1fSgjelinek break;
16877c478bd9Sstevel@tonic-gate case 'b':
16887c478bd9Sstevel@tonic-gate (void) strlcpy(zone_template, "SUNWblank",
16897c478bd9Sstevel@tonic-gate sizeof (zone_template));
16907c478bd9Sstevel@tonic-gate break;
16917c478bd9Sstevel@tonic-gate case 'F':
1692bbec428eSgjelinek force = B_TRUE;
16937c478bd9Sstevel@tonic-gate break;
16947c478bd9Sstevel@tonic-gate case 't':
16957c478bd9Sstevel@tonic-gate (void) strlcpy(zone_template, optarg,
16967c478bd9Sstevel@tonic-gate sizeof (zone_template));
16977c478bd9Sstevel@tonic-gate break;
16987c478bd9Sstevel@tonic-gate default:
16997c478bd9Sstevel@tonic-gate short_usage(CMD_CREATE);
1700bbec428eSgjelinek arg_err = B_TRUE;
17017ec75eb8Sgjelinek break;
17027ec75eb8Sgjelinek }
17037ec75eb8Sgjelinek }
17047ec75eb8Sgjelinek if (arg_err)
17057c478bd9Sstevel@tonic-gate return;
17067ec75eb8Sgjelinek
17077c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) {
17087c478bd9Sstevel@tonic-gate short_usage(CMD_CREATE);
17097c478bd9Sstevel@tonic-gate return;
17107c478bd9Sstevel@tonic-gate }
17117c478bd9Sstevel@tonic-gate
17127c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_CREATE))
17137c478bd9Sstevel@tonic-gate return;
17147c478bd9Sstevel@tonic-gate
17157c478bd9Sstevel@tonic-gate if (check_if_zone_already_exists(force) != Z_OK)
17167c478bd9Sstevel@tonic-gate return;
17177c478bd9Sstevel@tonic-gate
17187c478bd9Sstevel@tonic-gate /*
17197c478bd9Sstevel@tonic-gate * Get a temporary handle first. If that fails, the old handle
17207c478bd9Sstevel@tonic-gate * will not be lost. Then finish whichever one we don't need,
17217c478bd9Sstevel@tonic-gate * to avoid leaks. Then get the handle for zone_template, and
17227c478bd9Sstevel@tonic-gate * set the name to zone: this "copy, rename" method is how
17237c478bd9Sstevel@tonic-gate * create -[b|t] works.
17247c478bd9Sstevel@tonic-gate */
17257c478bd9Sstevel@tonic-gate if ((tmphandle = zonecfg_init_handle()) == NULL) {
1726bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE);
17277c478bd9Sstevel@tonic-gate exit(Z_ERR);
17287c478bd9Sstevel@tonic-gate }
1729ee519a1fSgjelinek
1730ee519a1fSgjelinek if (attach)
173116ab8c7bSgjelinek err = zonecfg_get_attach_handle(attach_path, ZONE_DETACHED,
173216ab8c7bSgjelinek zone, B_FALSE, tmphandle);
1733ee519a1fSgjelinek else
1734ee519a1fSgjelinek err = zonecfg_get_template_handle(zone_template, zone,
1735ee519a1fSgjelinek tmphandle);
1736ee519a1fSgjelinek
1737ee519a1fSgjelinek if (err != Z_OK) {
17387c478bd9Sstevel@tonic-gate zonecfg_fini_handle(tmphandle);
1739ee519a1fSgjelinek if (attach && err == Z_NO_ZONE)
1740ee519a1fSgjelinek (void) fprintf(stderr, gettext("invalid path to "
1741ee519a1fSgjelinek "detached zone\n"));
1742ee519a1fSgjelinek else if (attach && err == Z_INVALID_DOCUMENT)
1743ee519a1fSgjelinek (void) fprintf(stderr, gettext("Cannot attach to an "
1744ee519a1fSgjelinek "earlier release of the operating system\n"));
1745ee519a1fSgjelinek else
1746bbec428eSgjelinek zone_perror(zone_template, err, B_TRUE);
17477c478bd9Sstevel@tonic-gate return;
17487c478bd9Sstevel@tonic-gate }
1749087719fdSdp
1750bbec428eSgjelinek need_to_commit = B_TRUE;
17517c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle);
17527c478bd9Sstevel@tonic-gate handle = tmphandle;
1753bbec428eSgjelinek got_handle = B_TRUE;
17547c478bd9Sstevel@tonic-gate }
17557c478bd9Sstevel@tonic-gate
17567c478bd9Sstevel@tonic-gate /*
17577c478bd9Sstevel@tonic-gate * This malloc()'s memory, which must be freed by the caller.
17587c478bd9Sstevel@tonic-gate */
17597c478bd9Sstevel@tonic-gate static char *
quoteit(char * instr)17607c478bd9Sstevel@tonic-gate quoteit(char *instr)
17617c478bd9Sstevel@tonic-gate {
17627c478bd9Sstevel@tonic-gate char *outstr;
17637c478bd9Sstevel@tonic-gate size_t outstrsize = strlen(instr) + 3; /* 2 quotes + '\0' */
17647c478bd9Sstevel@tonic-gate
17657c478bd9Sstevel@tonic-gate if ((outstr = malloc(outstrsize)) == NULL) {
1766bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_FALSE);
17677c478bd9Sstevel@tonic-gate exit(Z_ERR);
17687c478bd9Sstevel@tonic-gate }
17697c478bd9Sstevel@tonic-gate if (strchr(instr, ' ') == NULL) {
17707c478bd9Sstevel@tonic-gate (void) strlcpy(outstr, instr, outstrsize);
17717c478bd9Sstevel@tonic-gate return (outstr);
17727c478bd9Sstevel@tonic-gate }
17737c478bd9Sstevel@tonic-gate (void) snprintf(outstr, outstrsize, "\"%s\"", instr);
17747c478bd9Sstevel@tonic-gate return (outstr);
17757c478bd9Sstevel@tonic-gate }
17767c478bd9Sstevel@tonic-gate
17777c478bd9Sstevel@tonic-gate static void
export_prop(FILE * of,int prop_num,char * prop_id)17787c478bd9Sstevel@tonic-gate export_prop(FILE *of, int prop_num, char *prop_id)
17797c478bd9Sstevel@tonic-gate {
17807c478bd9Sstevel@tonic-gate char *quote_str;
17817c478bd9Sstevel@tonic-gate
17827c478bd9Sstevel@tonic-gate if (strlen(prop_id) == 0)
17837c478bd9Sstevel@tonic-gate return;
17847c478bd9Sstevel@tonic-gate quote_str = quoteit(prop_id);
17857c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET),
17867c478bd9Sstevel@tonic-gate pt_to_str(prop_num), quote_str);
17877c478bd9Sstevel@tonic-gate free(quote_str);
17887c478bd9Sstevel@tonic-gate }
17897c478bd9Sstevel@tonic-gate
17907c478bd9Sstevel@tonic-gate void
export_func(cmd_t * cmd)17917c478bd9Sstevel@tonic-gate export_func(cmd_t *cmd)
17927c478bd9Sstevel@tonic-gate {
17937c478bd9Sstevel@tonic-gate struct zone_nwiftab nwiftab;
17947c478bd9Sstevel@tonic-gate struct zone_fstab fstab;
17957c478bd9Sstevel@tonic-gate struct zone_devtab devtab;
17967c478bd9Sstevel@tonic-gate struct zone_attrtab attrtab;
17977c478bd9Sstevel@tonic-gate struct zone_rctltab rctltab;
1798fa9e4066Sahrens struct zone_dstab dstab;
17990209230bSgjelinek struct zone_psettab psettab;
18000209230bSgjelinek struct zone_mcaptab mcaptab;
18017c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *valptr;
1802cb8a054bSGlenn Faden struct zone_admintab admintab;
18037c478bd9Sstevel@tonic-gate int err, arg;
18047c478bd9Sstevel@tonic-gate char zonepath[MAXPATHLEN], outfile[MAXPATHLEN], pool[MAXNAMELEN];
18053f2f09c1Sdp char bootargs[BOOTARGS_MAX];
18060209230bSgjelinek char sched[MAXNAMELEN];
18079acbbeafSnn35248 char brand[MAXNAMELEN];
18085679c89fSjv227347 char hostidp[HW_HOSTID_LEN];
18090fbb751dSJohn Levon char fsallowedp[ZONE_FS_ALLOWED_MAX];
1810ffbafc53Scomay char *limitpriv;
18117c478bd9Sstevel@tonic-gate FILE *of;
18127c478bd9Sstevel@tonic-gate boolean_t autoboot;
1813f4b3ec61Sdh155122 zone_iptype_t iptype;
1814bbec428eSgjelinek boolean_t need_to_close = B_FALSE;
1815bbec428eSgjelinek boolean_t arg_err = B_FALSE;
18167c478bd9Sstevel@tonic-gate
18177c478bd9Sstevel@tonic-gate assert(cmd != NULL);
18187c478bd9Sstevel@tonic-gate
18197c478bd9Sstevel@tonic-gate outfile[0] = '\0';
18207c478bd9Sstevel@tonic-gate optind = 0;
18217c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?f:")) != EOF) {
18227c478bd9Sstevel@tonic-gate switch (arg) {
18237c478bd9Sstevel@tonic-gate case '?':
18247c478bd9Sstevel@tonic-gate if (optopt == '?')
18257c478bd9Sstevel@tonic-gate longer_usage(CMD_EXPORT);
18267c478bd9Sstevel@tonic-gate else
18277c478bd9Sstevel@tonic-gate short_usage(CMD_EXPORT);
1828bbec428eSgjelinek arg_err = B_TRUE;
18297ec75eb8Sgjelinek break;
18307c478bd9Sstevel@tonic-gate case 'f':
18317c478bd9Sstevel@tonic-gate (void) strlcpy(outfile, optarg, sizeof (outfile));
18327c478bd9Sstevel@tonic-gate break;
18337c478bd9Sstevel@tonic-gate default:
18347c478bd9Sstevel@tonic-gate short_usage(CMD_EXPORT);
1835bbec428eSgjelinek arg_err = B_TRUE;
18367ec75eb8Sgjelinek break;
18377ec75eb8Sgjelinek }
18387ec75eb8Sgjelinek }
18397ec75eb8Sgjelinek if (arg_err)
18407c478bd9Sstevel@tonic-gate return;
18417ec75eb8Sgjelinek
18427c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) {
18437c478bd9Sstevel@tonic-gate short_usage(CMD_EXPORT);
18447c478bd9Sstevel@tonic-gate return;
18457c478bd9Sstevel@tonic-gate }
18467c478bd9Sstevel@tonic-gate if (strlen(outfile) == 0) {
18477c478bd9Sstevel@tonic-gate of = stdout;
18487c478bd9Sstevel@tonic-gate } else {
18497c478bd9Sstevel@tonic-gate if ((of = fopen(outfile, "w")) == NULL) {
18507c478bd9Sstevel@tonic-gate zerr(gettext("opening file %s: %s"),
18517c478bd9Sstevel@tonic-gate outfile, strerror(errno));
18527c478bd9Sstevel@tonic-gate goto done;
18537c478bd9Sstevel@tonic-gate }
18547c478bd9Sstevel@tonic-gate setbuf(of, NULL);
1855bbec428eSgjelinek need_to_close = B_TRUE;
18567c478bd9Sstevel@tonic-gate }
18577c478bd9Sstevel@tonic-gate
1858bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK)
18597c478bd9Sstevel@tonic-gate goto done;
18607c478bd9Sstevel@tonic-gate
18617c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s -b\n", cmd_to_str(CMD_CREATE));
18627c478bd9Sstevel@tonic-gate
18637c478bd9Sstevel@tonic-gate if (zonecfg_get_zonepath(handle, zonepath, sizeof (zonepath)) == Z_OK &&
18647c478bd9Sstevel@tonic-gate strlen(zonepath) > 0)
18657c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET),
18667c478bd9Sstevel@tonic-gate pt_to_str(PT_ZONEPATH), zonepath);
18677c478bd9Sstevel@tonic-gate
18689acbbeafSnn35248 if ((zone_get_brand(zone, brand, sizeof (brand)) == Z_OK) &&
18699acbbeafSnn35248 (strcmp(brand, NATIVE_BRAND_NAME) != 0))
18709acbbeafSnn35248 (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET),
18719acbbeafSnn35248 pt_to_str(PT_BRAND), brand);
18729acbbeafSnn35248
18737c478bd9Sstevel@tonic-gate if (zonecfg_get_autoboot(handle, &autoboot) == Z_OK)
18747c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET),
18757c478bd9Sstevel@tonic-gate pt_to_str(PT_AUTOBOOT), autoboot ? "true" : "false");
18767c478bd9Sstevel@tonic-gate
18773f2f09c1Sdp if (zonecfg_get_bootargs(handle, bootargs, sizeof (bootargs)) == Z_OK &&
18783f2f09c1Sdp strlen(bootargs) > 0) {
18793f2f09c1Sdp (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET),
18803f2f09c1Sdp pt_to_str(PT_BOOTARGS), bootargs);
18813f2f09c1Sdp }
18823f2f09c1Sdp
18837c478bd9Sstevel@tonic-gate if (zonecfg_get_pool(handle, pool, sizeof (pool)) == Z_OK &&
18847c478bd9Sstevel@tonic-gate strlen(pool) > 0)
18857c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET),
18867c478bd9Sstevel@tonic-gate pt_to_str(PT_POOL), pool);
18877c478bd9Sstevel@tonic-gate
1888ffbafc53Scomay if (zonecfg_get_limitpriv(handle, &limitpriv) == Z_OK &&
1889ffbafc53Scomay strlen(limitpriv) > 0) {
1890ffbafc53Scomay (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET),
1891ffbafc53Scomay pt_to_str(PT_LIMITPRIV), limitpriv);
1892ffbafc53Scomay free(limitpriv);
1893ffbafc53Scomay }
1894ffbafc53Scomay
18950209230bSgjelinek if (zonecfg_get_sched_class(handle, sched, sizeof (sched)) == Z_OK &&
18960209230bSgjelinek strlen(sched) > 0)
18970209230bSgjelinek (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET),
18980209230bSgjelinek pt_to_str(PT_SCHED), sched);
18993f2f09c1Sdp
1900f4b3ec61Sdh155122 if (zonecfg_get_iptype(handle, &iptype) == Z_OK) {
1901f4b3ec61Sdh155122 switch (iptype) {
1902f4b3ec61Sdh155122 case ZS_SHARED:
1903f4b3ec61Sdh155122 (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET),
1904f4b3ec61Sdh155122 pt_to_str(PT_IPTYPE), "shared");
1905f4b3ec61Sdh155122 break;
1906f4b3ec61Sdh155122 case ZS_EXCLUSIVE:
1907f4b3ec61Sdh155122 (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET),
1908f4b3ec61Sdh155122 pt_to_str(PT_IPTYPE), "exclusive");
1909f4b3ec61Sdh155122 break;
1910f4b3ec61Sdh155122 }
1911f4b3ec61Sdh155122 }
1912f4b3ec61Sdh155122
19135679c89fSjv227347 if (zonecfg_get_hostid(handle, hostidp, sizeof (hostidp)) == Z_OK) {
19145679c89fSjv227347 (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET),
19155679c89fSjv227347 pt_to_str(PT_HOSTID), hostidp);
19165679c89fSjv227347 }
19175679c89fSjv227347
19180fbb751dSJohn Levon if (zonecfg_get_fs_allowed(handle, fsallowedp,
19190fbb751dSJohn Levon sizeof (fsallowedp)) == Z_OK) {
19200fbb751dSJohn Levon (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET),
19210fbb751dSJohn Levon pt_to_str(PT_FS_ALLOWED), fsallowedp);
19220fbb751dSJohn Levon }
19230fbb751dSJohn Levon
19247c478bd9Sstevel@tonic-gate if ((err = zonecfg_setfsent(handle)) != Z_OK) {
1925bbec428eSgjelinek zone_perror(zone, err, B_FALSE);
19267c478bd9Sstevel@tonic-gate goto done;
19277c478bd9Sstevel@tonic-gate }
19287c478bd9Sstevel@tonic-gate while (zonecfg_getfsent(handle, &fstab) == Z_OK) {
19297c478bd9Sstevel@tonic-gate zone_fsopt_t *optptr;
19307c478bd9Sstevel@tonic-gate
19317c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD),
19327c478bd9Sstevel@tonic-gate rt_to_str(RT_FS));
19337c478bd9Sstevel@tonic-gate export_prop(of, PT_DIR, fstab.zone_fs_dir);
19347c478bd9Sstevel@tonic-gate export_prop(of, PT_SPECIAL, fstab.zone_fs_special);
19357c478bd9Sstevel@tonic-gate export_prop(of, PT_RAW, fstab.zone_fs_raw);
19367c478bd9Sstevel@tonic-gate export_prop(of, PT_TYPE, fstab.zone_fs_type);
19377c478bd9Sstevel@tonic-gate for (optptr = fstab.zone_fs_options; optptr != NULL;
19387c478bd9Sstevel@tonic-gate optptr = optptr->zone_fsopt_next) {
19397c478bd9Sstevel@tonic-gate /*
19407c478bd9Sstevel@tonic-gate * Simple property values with embedded equal signs
19417c478bd9Sstevel@tonic-gate * need to be quoted to prevent the lexer from
19427c478bd9Sstevel@tonic-gate * mis-parsing them as complex name=value pairs.
19437c478bd9Sstevel@tonic-gate */
19447c478bd9Sstevel@tonic-gate if (strchr(optptr->zone_fsopt_opt, '='))
19457c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s \"%s\"\n",
19467c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD),
19477c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS),
19487c478bd9Sstevel@tonic-gate optptr->zone_fsopt_opt);
19497c478bd9Sstevel@tonic-gate else
19507c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s %s\n",
19517c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD),
19527c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS),
19537c478bd9Sstevel@tonic-gate optptr->zone_fsopt_opt);
19547c478bd9Sstevel@tonic-gate }
19557c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END));
19567c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(fstab.zone_fs_options);
19577c478bd9Sstevel@tonic-gate }
19587c478bd9Sstevel@tonic-gate (void) zonecfg_endfsent(handle);
19597c478bd9Sstevel@tonic-gate
19607c478bd9Sstevel@tonic-gate if ((err = zonecfg_setnwifent(handle)) != Z_OK) {
1961bbec428eSgjelinek zone_perror(zone, err, B_FALSE);
19627c478bd9Sstevel@tonic-gate goto done;
19637c478bd9Sstevel@tonic-gate }
19647c478bd9Sstevel@tonic-gate while (zonecfg_getnwifent(handle, &nwiftab) == Z_OK) {
19657c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD),
19667c478bd9Sstevel@tonic-gate rt_to_str(RT_NET));
19677c478bd9Sstevel@tonic-gate export_prop(of, PT_ADDRESS, nwiftab.zone_nwif_address);
1968550b6e40SSowmini Varadhan export_prop(of, PT_ALLOWED_ADDRESS,
1969550b6e40SSowmini Varadhan nwiftab.zone_nwif_allowed_address);
19707c478bd9Sstevel@tonic-gate export_prop(of, PT_PHYSICAL, nwiftab.zone_nwif_physical);
1971de860bd9Sgfaden export_prop(of, PT_DEFROUTER, nwiftab.zone_nwif_defrouter);
19727c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END));
19737c478bd9Sstevel@tonic-gate }
19747c478bd9Sstevel@tonic-gate (void) zonecfg_endnwifent(handle);
19757c478bd9Sstevel@tonic-gate
19767c478bd9Sstevel@tonic-gate if ((err = zonecfg_setdevent(handle)) != Z_OK) {
1977bbec428eSgjelinek zone_perror(zone, err, B_FALSE);
19787c478bd9Sstevel@tonic-gate goto done;
19797c478bd9Sstevel@tonic-gate }
19807c478bd9Sstevel@tonic-gate while (zonecfg_getdevent(handle, &devtab) == Z_OK) {
19817c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD),
19827c478bd9Sstevel@tonic-gate rt_to_str(RT_DEVICE));
19837c478bd9Sstevel@tonic-gate export_prop(of, PT_MATCH, devtab.zone_dev_match);
19847c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END));
19857c478bd9Sstevel@tonic-gate }
19867c478bd9Sstevel@tonic-gate (void) zonecfg_enddevent(handle);
19877c478bd9Sstevel@tonic-gate
19881b3281c0SGerald Jelinek if (zonecfg_getmcapent(handle, &mcaptab) == Z_OK) {
19891b3281c0SGerald Jelinek char buf[128];
19901b3281c0SGerald Jelinek
19911b3281c0SGerald Jelinek (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD),
19921b3281c0SGerald Jelinek rt_to_str(RT_MCAP));
19931b3281c0SGerald Jelinek bytes_to_units(mcaptab.zone_physmem_cap, buf, sizeof (buf));
19941b3281c0SGerald Jelinek (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET),
19951b3281c0SGerald Jelinek pt_to_str(PT_PHYSICAL), buf);
19961b3281c0SGerald Jelinek (void) fprintf(of, "%s\n", cmd_to_str(CMD_END));
19971b3281c0SGerald Jelinek }
19981b3281c0SGerald Jelinek
19997c478bd9Sstevel@tonic-gate if ((err = zonecfg_setrctlent(handle)) != Z_OK) {
2000bbec428eSgjelinek zone_perror(zone, err, B_FALSE);
20017c478bd9Sstevel@tonic-gate goto done;
20027c478bd9Sstevel@tonic-gate }
20037c478bd9Sstevel@tonic-gate while (zonecfg_getrctlent(handle, &rctltab) == Z_OK) {
20047c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s rctl\n", cmd_to_str(CMD_ADD));
20057c478bd9Sstevel@tonic-gate export_prop(of, PT_NAME, rctltab.zone_rctl_name);
20067c478bd9Sstevel@tonic-gate for (valptr = rctltab.zone_rctl_valptr; valptr != NULL;
20077c478bd9Sstevel@tonic-gate valptr = valptr->zone_rctlval_next) {
20087c478bd9Sstevel@tonic-gate fprintf(of, "%s %s (%s=%s,%s=%s,%s=%s)\n",
20097c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), pt_to_str(PT_VALUE),
20107c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV), valptr->zone_rctlval_priv,
20117c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT), valptr->zone_rctlval_limit,
20127c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION), valptr->zone_rctlval_action);
20137c478bd9Sstevel@tonic-gate }
20147c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END));
20157c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr);
20167c478bd9Sstevel@tonic-gate }
20177c478bd9Sstevel@tonic-gate (void) zonecfg_endrctlent(handle);
20187c478bd9Sstevel@tonic-gate
20197c478bd9Sstevel@tonic-gate if ((err = zonecfg_setattrent(handle)) != Z_OK) {
2020bbec428eSgjelinek zone_perror(zone, err, B_FALSE);
20217c478bd9Sstevel@tonic-gate goto done;
20227c478bd9Sstevel@tonic-gate }
20237c478bd9Sstevel@tonic-gate while (zonecfg_getattrent(handle, &attrtab) == Z_OK) {
20247c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD),
20257c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR));
20267c478bd9Sstevel@tonic-gate export_prop(of, PT_NAME, attrtab.zone_attr_name);
20277c478bd9Sstevel@tonic-gate export_prop(of, PT_TYPE, attrtab.zone_attr_type);
20287c478bd9Sstevel@tonic-gate export_prop(of, PT_VALUE, attrtab.zone_attr_value);
20297c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END));
20307c478bd9Sstevel@tonic-gate }
20317c478bd9Sstevel@tonic-gate (void) zonecfg_endattrent(handle);
20327c478bd9Sstevel@tonic-gate
2033fa9e4066Sahrens if ((err = zonecfg_setdsent(handle)) != Z_OK) {
2034bbec428eSgjelinek zone_perror(zone, err, B_FALSE);
2035fa9e4066Sahrens goto done;
2036fa9e4066Sahrens }
2037fa9e4066Sahrens while (zonecfg_getdsent(handle, &dstab) == Z_OK) {
2038fa9e4066Sahrens (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD),
2039fa9e4066Sahrens rt_to_str(RT_DATASET));
2040fa9e4066Sahrens export_prop(of, PT_NAME, dstab.zone_dataset_name);
2041fa9e4066Sahrens (void) fprintf(of, "%s\n", cmd_to_str(CMD_END));
2042fa9e4066Sahrens }
2043fa9e4066Sahrens (void) zonecfg_enddsent(handle);
2044fa9e4066Sahrens
20450209230bSgjelinek if (zonecfg_getpsetent(handle, &psettab) == Z_OK) {
20460209230bSgjelinek (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD),
20470209230bSgjelinek rt_to_str(RT_DCPU));
20480209230bSgjelinek if (strcmp(psettab.zone_ncpu_min, psettab.zone_ncpu_max) == 0)
20490209230bSgjelinek (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET),
20500209230bSgjelinek pt_to_str(PT_NCPUS), psettab.zone_ncpu_max);
20510209230bSgjelinek else
20520209230bSgjelinek (void) fprintf(of, "%s %s=%s-%s\n", cmd_to_str(CMD_SET),
20530209230bSgjelinek pt_to_str(PT_NCPUS), psettab.zone_ncpu_min,
20540209230bSgjelinek psettab.zone_ncpu_max);
20550209230bSgjelinek if (psettab.zone_importance[0] != '\0')
20560209230bSgjelinek (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET),
20570209230bSgjelinek pt_to_str(PT_IMPORTANCE), psettab.zone_importance);
20580209230bSgjelinek (void) fprintf(of, "%s\n", cmd_to_str(CMD_END));
20590209230bSgjelinek }
20600209230bSgjelinek
2061cb8a054bSGlenn Faden if ((err = zonecfg_setadminent(handle)) != Z_OK) {
2062cb8a054bSGlenn Faden zone_perror(zone, err, B_FALSE);
2063cb8a054bSGlenn Faden goto done;
2064cb8a054bSGlenn Faden }
2065cb8a054bSGlenn Faden while (zonecfg_getadminent(handle, &admintab) == Z_OK) {
2066cb8a054bSGlenn Faden (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD),
2067cb8a054bSGlenn Faden rt_to_str(RT_ADMIN));
2068cb8a054bSGlenn Faden export_prop(of, PT_USER, admintab.zone_admin_user);
2069cb8a054bSGlenn Faden export_prop(of, PT_AUTHS, admintab.zone_admin_auths);
2070cb8a054bSGlenn Faden (void) fprintf(of, "%s\n", cmd_to_str(CMD_END));
2071cb8a054bSGlenn Faden }
2072cb8a054bSGlenn Faden (void) zonecfg_endadminent(handle);
2073cb8a054bSGlenn Faden
2074c97ad5cdSakolb /*
2075c97ad5cdSakolb * There is nothing to export for pcap since this resource is just
2076c97ad5cdSakolb * a container for an rctl alias.
2077c97ad5cdSakolb */
2078c97ad5cdSakolb
20797c478bd9Sstevel@tonic-gate done:
20807c478bd9Sstevel@tonic-gate if (need_to_close)
20817c478bd9Sstevel@tonic-gate (void) fclose(of);
20827c478bd9Sstevel@tonic-gate }
20837c478bd9Sstevel@tonic-gate
20847c478bd9Sstevel@tonic-gate void
exit_func(cmd_t * cmd)20857c478bd9Sstevel@tonic-gate exit_func(cmd_t *cmd)
20867c478bd9Sstevel@tonic-gate {
20877c478bd9Sstevel@tonic-gate int arg, answer;
2088bbec428eSgjelinek boolean_t arg_err = B_FALSE;
20897c478bd9Sstevel@tonic-gate
20907c478bd9Sstevel@tonic-gate optind = 0;
20917c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) {
20927c478bd9Sstevel@tonic-gate switch (arg) {
20937c478bd9Sstevel@tonic-gate case '?':
20947c478bd9Sstevel@tonic-gate longer_usage(CMD_EXIT);
2095bbec428eSgjelinek arg_err = B_TRUE;
20967ec75eb8Sgjelinek break;
20977c478bd9Sstevel@tonic-gate case 'F':
2098bbec428eSgjelinek force_exit = B_TRUE;
20997c478bd9Sstevel@tonic-gate break;
21007c478bd9Sstevel@tonic-gate default:
21017c478bd9Sstevel@tonic-gate short_usage(CMD_EXIT);
2102bbec428eSgjelinek arg_err = B_TRUE;
21037ec75eb8Sgjelinek break;
21047ec75eb8Sgjelinek }
21057ec75eb8Sgjelinek }
21067ec75eb8Sgjelinek if (arg_err)
21077c478bd9Sstevel@tonic-gate return;
21087ec75eb8Sgjelinek
21097c478bd9Sstevel@tonic-gate if (optind < cmd->cmd_argc) {
21107c478bd9Sstevel@tonic-gate short_usage(CMD_EXIT);
21117c478bd9Sstevel@tonic-gate return;
21127c478bd9Sstevel@tonic-gate }
21137c478bd9Sstevel@tonic-gate
21147c478bd9Sstevel@tonic-gate if (global_scope || force_exit) {
2115bbec428eSgjelinek time_to_exit = B_TRUE;
21167c478bd9Sstevel@tonic-gate return;
21177c478bd9Sstevel@tonic-gate }
21187c478bd9Sstevel@tonic-gate
2119bbec428eSgjelinek answer = ask_yesno(B_FALSE, "Resource incomplete; really quit");
21207c478bd9Sstevel@tonic-gate if (answer == -1) {
21217c478bd9Sstevel@tonic-gate zerr(gettext("Resource incomplete, input "
21227c478bd9Sstevel@tonic-gate "not from terminal and -F not specified:\n%s command "
21237c478bd9Sstevel@tonic-gate "ignored, but exiting anyway."), cmd_to_str(CMD_EXIT));
21247c478bd9Sstevel@tonic-gate exit(Z_ERR);
21257c478bd9Sstevel@tonic-gate } else if (answer == 1) {
2126bbec428eSgjelinek time_to_exit = B_TRUE;
21277c478bd9Sstevel@tonic-gate }
21287c478bd9Sstevel@tonic-gate /* (answer == 0) => just return */
21297c478bd9Sstevel@tonic-gate }
21307c478bd9Sstevel@tonic-gate
21317c478bd9Sstevel@tonic-gate static int
validate_zonepath_syntax(char * path)21327c478bd9Sstevel@tonic-gate validate_zonepath_syntax(char *path)
21337c478bd9Sstevel@tonic-gate {
21347c478bd9Sstevel@tonic-gate if (path[0] != '/') {
21357c478bd9Sstevel@tonic-gate zerr(gettext("%s is not an absolute path."), path);
21367c478bd9Sstevel@tonic-gate return (Z_ERR);
21377c478bd9Sstevel@tonic-gate }
21386fb06a2bSSusan Kamm-Worrell /* If path is all slashes, then fail */
21396fb06a2bSSusan Kamm-Worrell if (strspn(path, "/") == strlen(path)) {
21407c478bd9Sstevel@tonic-gate zerr(gettext("/ is not allowed as a %s."),
21417c478bd9Sstevel@tonic-gate pt_to_str(PT_ZONEPATH));
21427c478bd9Sstevel@tonic-gate return (Z_ERR);
21437c478bd9Sstevel@tonic-gate }
21447c478bd9Sstevel@tonic-gate return (Z_OK);
21457c478bd9Sstevel@tonic-gate }
21467c478bd9Sstevel@tonic-gate
21477c478bd9Sstevel@tonic-gate static void
add_resource(cmd_t * cmd)21487c478bd9Sstevel@tonic-gate add_resource(cmd_t *cmd)
21497c478bd9Sstevel@tonic-gate {
21507c478bd9Sstevel@tonic-gate int type;
21510209230bSgjelinek struct zone_psettab tmp_psettab;
21520209230bSgjelinek struct zone_mcaptab tmp_mcaptab;
2153c97ad5cdSakolb uint64_t tmp;
21540209230bSgjelinek uint64_t tmp_mcap;
21550209230bSgjelinek char pool[MAXNAMELEN];
21567c478bd9Sstevel@tonic-gate
21577c478bd9Sstevel@tonic-gate if ((type = cmd->cmd_res_type) == RT_UNKNOWN) {
2158bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE);
21597c478bd9Sstevel@tonic-gate goto bad;
21607c478bd9Sstevel@tonic-gate }
21617c478bd9Sstevel@tonic-gate
21627c478bd9Sstevel@tonic-gate switch (type) {
21637c478bd9Sstevel@tonic-gate case RT_FS:
21647c478bd9Sstevel@tonic-gate bzero(&in_progress_fstab, sizeof (in_progress_fstab));
21657c478bd9Sstevel@tonic-gate return;
21667c478bd9Sstevel@tonic-gate case RT_NET:
21677c478bd9Sstevel@tonic-gate bzero(&in_progress_nwiftab, sizeof (in_progress_nwiftab));
21687c478bd9Sstevel@tonic-gate return;
21697c478bd9Sstevel@tonic-gate case RT_DEVICE:
21707c478bd9Sstevel@tonic-gate bzero(&in_progress_devtab, sizeof (in_progress_devtab));
21717c478bd9Sstevel@tonic-gate return;
21727c478bd9Sstevel@tonic-gate case RT_RCTL:
21730209230bSgjelinek if (global_zone)
21740209230bSgjelinek zerr(gettext("WARNING: Setting a global zone resource "
21750209230bSgjelinek "control too low could deny\nservice "
21760209230bSgjelinek "to even the root user; "
21770209230bSgjelinek "this could render the system impossible\n"
21780209230bSgjelinek "to administer. Please use caution."));
21797c478bd9Sstevel@tonic-gate bzero(&in_progress_rctltab, sizeof (in_progress_rctltab));
21807c478bd9Sstevel@tonic-gate return;
21817c478bd9Sstevel@tonic-gate case RT_ATTR:
21827c478bd9Sstevel@tonic-gate bzero(&in_progress_attrtab, sizeof (in_progress_attrtab));
21837c478bd9Sstevel@tonic-gate return;
2184fa9e4066Sahrens case RT_DATASET:
2185fa9e4066Sahrens bzero(&in_progress_dstab, sizeof (in_progress_dstab));
2186fa9e4066Sahrens return;
21870209230bSgjelinek case RT_DCPU:
2188c97ad5cdSakolb /* Make sure there isn't already a cpu-set or cpu-cap entry. */
21890209230bSgjelinek if (zonecfg_lookup_pset(handle, &tmp_psettab) == Z_OK) {
21900209230bSgjelinek zerr(gettext("The %s resource already exists."),
21910209230bSgjelinek rt_to_str(RT_DCPU));
21920209230bSgjelinek goto bad;
21930209230bSgjelinek }
2194c97ad5cdSakolb if (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &tmp) !=
2195c97ad5cdSakolb Z_NO_ENTRY) {
2196c97ad5cdSakolb zerr(gettext("The %s resource already exists."),
2197c97ad5cdSakolb rt_to_str(RT_PCAP));
2198c97ad5cdSakolb goto bad;
2199c97ad5cdSakolb }
22000209230bSgjelinek
22010209230bSgjelinek /* Make sure the pool property isn't set. */
22020209230bSgjelinek if (zonecfg_get_pool(handle, pool, sizeof (pool)) == Z_OK &&
22030209230bSgjelinek strlen(pool) > 0) {
22040209230bSgjelinek zerr(gettext("The %s property is already set. "
22050209230bSgjelinek "A persistent pool is incompatible with\nthe %s "
22060209230bSgjelinek "resource."),
22070209230bSgjelinek pt_to_str(PT_POOL), rt_to_str(RT_DCPU));
22080209230bSgjelinek goto bad;
22090209230bSgjelinek }
22100209230bSgjelinek
22110209230bSgjelinek bzero(&in_progress_psettab, sizeof (in_progress_psettab));
22120209230bSgjelinek return;
2213c97ad5cdSakolb case RT_PCAP:
2214c97ad5cdSakolb /*
2215c97ad5cdSakolb * Make sure there isn't already a cpu-set or incompatible
2216c97ad5cdSakolb * cpu-cap rctls.
2217c97ad5cdSakolb */
2218c97ad5cdSakolb if (zonecfg_lookup_pset(handle, &tmp_psettab) == Z_OK) {
2219c97ad5cdSakolb zerr(gettext("The %s resource already exists."),
2220c97ad5cdSakolb rt_to_str(RT_DCPU));
2221c97ad5cdSakolb goto bad;
2222c97ad5cdSakolb }
2223c97ad5cdSakolb
2224c97ad5cdSakolb switch (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &tmp)) {
2225c97ad5cdSakolb case Z_ALIAS_DISALLOW:
2226c97ad5cdSakolb zone_perror(rt_to_str(RT_PCAP), Z_ALIAS_DISALLOW,
2227bbec428eSgjelinek B_FALSE);
2228c97ad5cdSakolb goto bad;
2229c97ad5cdSakolb
2230c97ad5cdSakolb case Z_OK:
2231c97ad5cdSakolb zerr(gettext("The %s resource already exists."),
2232c97ad5cdSakolb rt_to_str(RT_PCAP));
2233c97ad5cdSakolb goto bad;
2234c97ad5cdSakolb
2235c97ad5cdSakolb default:
2236c97ad5cdSakolb break;
2237c97ad5cdSakolb }
2238c97ad5cdSakolb return;
22390209230bSgjelinek case RT_MCAP:
22400209230bSgjelinek /*
22410209230bSgjelinek * Make sure there isn't already a mem-cap entry or max-swap
22420209230bSgjelinek * or max-locked rctl.
22430209230bSgjelinek */
22440209230bSgjelinek if (zonecfg_lookup_mcap(handle, &tmp_mcaptab) == Z_OK ||
22450209230bSgjelinek zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, &tmp_mcap)
22460209230bSgjelinek == Z_OK ||
22470209230bSgjelinek zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM,
22480209230bSgjelinek &tmp_mcap) == Z_OK) {
22490209230bSgjelinek zerr(gettext("The %s resource or a related resource "
22500209230bSgjelinek "control already exists."), rt_to_str(RT_MCAP));
22510209230bSgjelinek goto bad;
22520209230bSgjelinek }
22530209230bSgjelinek if (global_zone)
22540209230bSgjelinek zerr(gettext("WARNING: Setting a global zone memory "
22550209230bSgjelinek "cap too low could deny\nservice "
22560209230bSgjelinek "to even the root user; "
22570209230bSgjelinek "this could render the system impossible\n"
22580209230bSgjelinek "to administer. Please use caution."));
22590209230bSgjelinek bzero(&in_progress_mcaptab, sizeof (in_progress_mcaptab));
22600209230bSgjelinek return;
2261cb8a054bSGlenn Faden case RT_ADMIN:
2262cb8a054bSGlenn Faden bzero(&in_progress_admintab, sizeof (in_progress_admintab));
2263cb8a054bSGlenn Faden return;
22647c478bd9Sstevel@tonic-gate default:
2265bbec428eSgjelinek zone_perror(rt_to_str(type), Z_NO_RESOURCE_TYPE, B_TRUE);
2266bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE);
2267bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES);
22687c478bd9Sstevel@tonic-gate }
22697c478bd9Sstevel@tonic-gate bad:
2270bbec428eSgjelinek global_scope = B_TRUE;
22717c478bd9Sstevel@tonic-gate end_op = -1;
22727c478bd9Sstevel@tonic-gate }
22737c478bd9Sstevel@tonic-gate
22747c478bd9Sstevel@tonic-gate static void
do_complex_rctl_val(complex_property_ptr_t cp)22757c478bd9Sstevel@tonic-gate do_complex_rctl_val(complex_property_ptr_t cp)
22767c478bd9Sstevel@tonic-gate {
22777c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *rctlvaltab;
22787c478bd9Sstevel@tonic-gate complex_property_ptr_t cx;
2279bbec428eSgjelinek boolean_t seen_priv = B_FALSE, seen_limit = B_FALSE,
2280bbec428eSgjelinek seen_action = B_FALSE;
22817c478bd9Sstevel@tonic-gate rctlblk_t *rctlblk;
22827c478bd9Sstevel@tonic-gate int err;
22837c478bd9Sstevel@tonic-gate
22847c478bd9Sstevel@tonic-gate if ((rctlvaltab = alloc_rctlvaltab()) == NULL) {
2285bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_TRUE);
22867c478bd9Sstevel@tonic-gate exit(Z_ERR);
22877c478bd9Sstevel@tonic-gate }
22887c478bd9Sstevel@tonic-gate for (cx = cp; cx != NULL; cx = cx->cp_next) {
22897c478bd9Sstevel@tonic-gate switch (cx->cp_type) {
22907c478bd9Sstevel@tonic-gate case PT_PRIV:
22917c478bd9Sstevel@tonic-gate if (seen_priv) {
22927c478bd9Sstevel@tonic-gate zerr(gettext("%s already specified"),
22937c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV));
22947c478bd9Sstevel@tonic-gate goto bad;
22957c478bd9Sstevel@tonic-gate }
22967c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_priv,
22977c478bd9Sstevel@tonic-gate cx->cp_value,
22987c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_priv));
2299bbec428eSgjelinek seen_priv = B_TRUE;
23007c478bd9Sstevel@tonic-gate break;
23017c478bd9Sstevel@tonic-gate case PT_LIMIT:
23027c478bd9Sstevel@tonic-gate if (seen_limit) {
23037c478bd9Sstevel@tonic-gate zerr(gettext("%s already specified"),
23047c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT));
23057c478bd9Sstevel@tonic-gate goto bad;
23067c478bd9Sstevel@tonic-gate }
23077c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_limit,
23087c478bd9Sstevel@tonic-gate cx->cp_value,
23097c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_limit));
2310bbec428eSgjelinek seen_limit = B_TRUE;
23117c478bd9Sstevel@tonic-gate break;
23127c478bd9Sstevel@tonic-gate case PT_ACTION:
23137c478bd9Sstevel@tonic-gate if (seen_action) {
23147c478bd9Sstevel@tonic-gate zerr(gettext("%s already specified"),
23157c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION));
23167c478bd9Sstevel@tonic-gate goto bad;
23177c478bd9Sstevel@tonic-gate }
23187c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_action,
23197c478bd9Sstevel@tonic-gate cx->cp_value,
23207c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_action));
2321bbec428eSgjelinek seen_action = B_TRUE;
23227c478bd9Sstevel@tonic-gate break;
23237c478bd9Sstevel@tonic-gate default:
23247c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(PT_VALUE),
2325bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE);
2326bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE);
2327bbec428eSgjelinek usage(B_FALSE, HELP_PROPS);
23287c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab);
23297c478bd9Sstevel@tonic-gate return;
23307c478bd9Sstevel@tonic-gate }
23317c478bd9Sstevel@tonic-gate }
23327c478bd9Sstevel@tonic-gate if (!seen_priv)
23337c478bd9Sstevel@tonic-gate zerr(gettext("%s not specified"), pt_to_str(PT_PRIV));
23347c478bd9Sstevel@tonic-gate if (!seen_limit)
23357c478bd9Sstevel@tonic-gate zerr(gettext("%s not specified"), pt_to_str(PT_LIMIT));
23367c478bd9Sstevel@tonic-gate if (!seen_action)
23377c478bd9Sstevel@tonic-gate zerr(gettext("%s not specified"), pt_to_str(PT_ACTION));
23387c478bd9Sstevel@tonic-gate if (!seen_priv || !seen_limit || !seen_action)
23397c478bd9Sstevel@tonic-gate goto bad;
23407c478bd9Sstevel@tonic-gate rctlvaltab->zone_rctlval_next = NULL;
23417c478bd9Sstevel@tonic-gate rctlblk = alloca(rctlblk_size());
23427c478bd9Sstevel@tonic-gate /*
23437c478bd9Sstevel@tonic-gate * Make sure the rctl value looks roughly correct; we won't know if
23447c478bd9Sstevel@tonic-gate * it's truly OK until we verify the configuration on the target
23457c478bd9Sstevel@tonic-gate * system.
23467c478bd9Sstevel@tonic-gate */
23477c478bd9Sstevel@tonic-gate if (zonecfg_construct_rctlblk(rctlvaltab, rctlblk) != Z_OK ||
23487c478bd9Sstevel@tonic-gate !zonecfg_valid_rctlblk(rctlblk)) {
23497c478bd9Sstevel@tonic-gate zerr(gettext("Invalid %s %s specification"), rt_to_str(RT_RCTL),
23507c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE));
23517c478bd9Sstevel@tonic-gate goto bad;
23527c478bd9Sstevel@tonic-gate }
23537c478bd9Sstevel@tonic-gate err = zonecfg_add_rctl_value(&in_progress_rctltab, rctlvaltab);
23547c478bd9Sstevel@tonic-gate if (err != Z_OK)
2355bbec428eSgjelinek zone_perror(pt_to_str(PT_VALUE), err, B_TRUE);
23567c478bd9Sstevel@tonic-gate return;
23577c478bd9Sstevel@tonic-gate
23587c478bd9Sstevel@tonic-gate bad:
23597c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab);
23607c478bd9Sstevel@tonic-gate }
23617c478bd9Sstevel@tonic-gate
23627c478bd9Sstevel@tonic-gate static void
add_property(cmd_t * cmd)23637c478bd9Sstevel@tonic-gate add_property(cmd_t *cmd)
23647c478bd9Sstevel@tonic-gate {
23657c478bd9Sstevel@tonic-gate char *prop_id;
23667c478bd9Sstevel@tonic-gate int err, res_type, prop_type;
23677c478bd9Sstevel@tonic-gate property_value_ptr_t pp;
23687c478bd9Sstevel@tonic-gate list_property_ptr_t l;
23697c478bd9Sstevel@tonic-gate
23707c478bd9Sstevel@tonic-gate res_type = resource_scope;
23717c478bd9Sstevel@tonic-gate prop_type = cmd->cmd_prop_name[0];
23727c478bd9Sstevel@tonic-gate if (res_type == RT_UNKNOWN || prop_type == PT_UNKNOWN) {
2373bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE);
23747c478bd9Sstevel@tonic-gate return;
23757c478bd9Sstevel@tonic-gate }
23767c478bd9Sstevel@tonic-gate
23777c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs != 1) {
2378bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE);
23797c478bd9Sstevel@tonic-gate return;
23807c478bd9Sstevel@tonic-gate }
23817c478bd9Sstevel@tonic-gate
2382bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK)
23837c478bd9Sstevel@tonic-gate return;
23847c478bd9Sstevel@tonic-gate
23857c478bd9Sstevel@tonic-gate switch (res_type) {
23867c478bd9Sstevel@tonic-gate case RT_FS:
23877c478bd9Sstevel@tonic-gate if (prop_type != PT_OPTIONS) {
23887c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
2389bbec428eSgjelinek B_TRUE);
2390bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE);
2391bbec428eSgjelinek usage(B_FALSE, HELP_PROPS);
23927c478bd9Sstevel@tonic-gate return;
23937c478bd9Sstevel@tonic-gate }
23947c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0];
23957c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE &&
23967c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) {
23977c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected here."),
23987c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_SIMPLE),
23997c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST));
2400bbec428eSgjelinek saw_error = B_TRUE;
24017c478bd9Sstevel@tonic-gate return;
24027c478bd9Sstevel@tonic-gate }
24037c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_SIMPLE) {
24047c478bd9Sstevel@tonic-gate if (pp->pv_simple == NULL) {
2405bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE);
24067c478bd9Sstevel@tonic-gate return;
24077c478bd9Sstevel@tonic-gate }
24087c478bd9Sstevel@tonic-gate prop_id = pp->pv_simple;
24097c478bd9Sstevel@tonic-gate err = zonecfg_add_fs_option(&in_progress_fstab,
24107c478bd9Sstevel@tonic-gate prop_id);
24117c478bd9Sstevel@tonic-gate if (err != Z_OK)
2412bbec428eSgjelinek zone_perror(pt_to_str(prop_type), err, B_TRUE);
24137c478bd9Sstevel@tonic-gate } else {
24147c478bd9Sstevel@tonic-gate list_property_ptr_t list;
24157c478bd9Sstevel@tonic-gate
24167c478bd9Sstevel@tonic-gate for (list = pp->pv_list; list != NULL;
24177c478bd9Sstevel@tonic-gate list = list->lp_next) {
24187c478bd9Sstevel@tonic-gate prop_id = list->lp_simple;
24197c478bd9Sstevel@tonic-gate if (prop_id == NULL)
24207c478bd9Sstevel@tonic-gate break;
24217c478bd9Sstevel@tonic-gate err = zonecfg_add_fs_option(
24227c478bd9Sstevel@tonic-gate &in_progress_fstab, prop_id);
24237c478bd9Sstevel@tonic-gate if (err != Z_OK)
24247c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), err,
2425bbec428eSgjelinek B_TRUE);
24267c478bd9Sstevel@tonic-gate }
24277c478bd9Sstevel@tonic-gate }
24287c478bd9Sstevel@tonic-gate return;
24297c478bd9Sstevel@tonic-gate case RT_RCTL:
24307c478bd9Sstevel@tonic-gate if (prop_type != PT_VALUE) {
24317c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
2432bbec428eSgjelinek B_TRUE);
2433bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE);
2434bbec428eSgjelinek usage(B_FALSE, HELP_PROPS);
24357c478bd9Sstevel@tonic-gate return;
24367c478bd9Sstevel@tonic-gate }
24377c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0];
24387c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_COMPLEX &&
24397c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) {
24407c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected here."),
24417c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_COMPLEX),
24427c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST));
2443bbec428eSgjelinek saw_error = B_TRUE;
24447c478bd9Sstevel@tonic-gate return;
24457c478bd9Sstevel@tonic-gate }
24467c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_COMPLEX) {
24477c478bd9Sstevel@tonic-gate do_complex_rctl_val(pp->pv_complex);
24487c478bd9Sstevel@tonic-gate return;
24497c478bd9Sstevel@tonic-gate }
24507c478bd9Sstevel@tonic-gate for (l = pp->pv_list; l != NULL; l = l->lp_next)
24517c478bd9Sstevel@tonic-gate do_complex_rctl_val(l->lp_complex);
24527c478bd9Sstevel@tonic-gate return;
24537c478bd9Sstevel@tonic-gate default:
2454bbec428eSgjelinek zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, B_TRUE);
2455bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE);
2456bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES);
24577c478bd9Sstevel@tonic-gate return;
24587c478bd9Sstevel@tonic-gate }
24597c478bd9Sstevel@tonic-gate }
24607c478bd9Sstevel@tonic-gate
24610209230bSgjelinek static boolean_t
gz_invalid_resource(int type)24620209230bSgjelinek gz_invalid_resource(int type)
24630209230bSgjelinek {
24646e1ae2a3SGary Pennington return (global_zone && (type == RT_FS ||
24650209230bSgjelinek type == RT_NET || type == RT_DEVICE || type == RT_ATTR ||
24660209230bSgjelinek type == RT_DATASET));
24670209230bSgjelinek }
24680209230bSgjelinek
24690209230bSgjelinek static boolean_t
gz_invalid_rt_property(int type)24700209230bSgjelinek gz_invalid_rt_property(int type)
24710209230bSgjelinek {
24720209230bSgjelinek return (global_zone && (type == RT_ZONENAME || type == RT_ZONEPATH ||
24730209230bSgjelinek type == RT_AUTOBOOT || type == RT_LIMITPRIV ||
2474f4b3ec61Sdh155122 type == RT_BOOTARGS || type == RT_BRAND || type == RT_SCHED ||
24750fbb751dSJohn Levon type == RT_IPTYPE || type == RT_HOSTID || type == RT_FS_ALLOWED));
24760209230bSgjelinek }
24770209230bSgjelinek
24780209230bSgjelinek static boolean_t
gz_invalid_property(int type)24790209230bSgjelinek gz_invalid_property(int type)
24800209230bSgjelinek {
24810209230bSgjelinek return (global_zone && (type == PT_ZONENAME || type == PT_ZONEPATH ||
24820209230bSgjelinek type == PT_AUTOBOOT || type == PT_LIMITPRIV ||
2483f4b3ec61Sdh155122 type == PT_BOOTARGS || type == PT_BRAND || type == PT_SCHED ||
24840fbb751dSJohn Levon type == PT_IPTYPE || type == PT_HOSTID || type == PT_FS_ALLOWED));
24850209230bSgjelinek }
24860209230bSgjelinek
24877c478bd9Sstevel@tonic-gate void
add_func(cmd_t * cmd)24887c478bd9Sstevel@tonic-gate add_func(cmd_t *cmd)
24897c478bd9Sstevel@tonic-gate {
24907c478bd9Sstevel@tonic-gate int arg;
2491bbec428eSgjelinek boolean_t arg_err = B_FALSE;
24927c478bd9Sstevel@tonic-gate
24937c478bd9Sstevel@tonic-gate assert(cmd != NULL);
24947c478bd9Sstevel@tonic-gate
24957c478bd9Sstevel@tonic-gate optind = 0;
24967ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) {
24977c478bd9Sstevel@tonic-gate switch (arg) {
24987c478bd9Sstevel@tonic-gate case '?':
24997c478bd9Sstevel@tonic-gate longer_usage(CMD_ADD);
2500bbec428eSgjelinek arg_err = B_TRUE;
25017ec75eb8Sgjelinek break;
25027c478bd9Sstevel@tonic-gate default:
25037c478bd9Sstevel@tonic-gate short_usage(CMD_ADD);
2504bbec428eSgjelinek arg_err = B_TRUE;
25057ec75eb8Sgjelinek break;
25067ec75eb8Sgjelinek }
25077ec75eb8Sgjelinek }
25087ec75eb8Sgjelinek if (arg_err)
25097c478bd9Sstevel@tonic-gate return;
25107ec75eb8Sgjelinek
25117c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) {
25127c478bd9Sstevel@tonic-gate short_usage(CMD_ADD);
25137c478bd9Sstevel@tonic-gate return;
25147c478bd9Sstevel@tonic-gate }
25157c478bd9Sstevel@tonic-gate
25167c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_ADD))
25177c478bd9Sstevel@tonic-gate return;
25187c478bd9Sstevel@tonic-gate
2519bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK)
25207c478bd9Sstevel@tonic-gate return;
25217c478bd9Sstevel@tonic-gate if (global_scope) {
25220209230bSgjelinek if (gz_invalid_resource(cmd->cmd_res_type)) {
25230209230bSgjelinek zerr(gettext("Cannot add a %s resource to the "
25240209230bSgjelinek "global zone."), rt_to_str(cmd->cmd_res_type));
2525bbec428eSgjelinek saw_error = B_TRUE;
25260209230bSgjelinek return;
25270209230bSgjelinek }
25280209230bSgjelinek
2529bbec428eSgjelinek global_scope = B_FALSE;
25307c478bd9Sstevel@tonic-gate resource_scope = cmd->cmd_res_type;
25317c478bd9Sstevel@tonic-gate end_op = CMD_ADD;
25327c478bd9Sstevel@tonic-gate add_resource(cmd);
25337c478bd9Sstevel@tonic-gate } else
25347c478bd9Sstevel@tonic-gate add_property(cmd);
25357c478bd9Sstevel@tonic-gate }
25367c478bd9Sstevel@tonic-gate
2537087719fdSdp /*
2538087719fdSdp * This routine has an unusual implementation, because it tries very
2539087719fdSdp * hard to succeed in the face of a variety of failure modes.
2540087719fdSdp * The most common and most vexing occurs when the index file and
2541087719fdSdp * the /etc/zones/<zonename.xml> file are not both present. In
2542087719fdSdp * this case, delete must eradicate as much of the zone state as is left
2543087719fdSdp * so that the user can later create a new zone with the same name.
2544087719fdSdp */
25457c478bd9Sstevel@tonic-gate void
delete_func(cmd_t * cmd)25467c478bd9Sstevel@tonic-gate delete_func(cmd_t *cmd)
25477c478bd9Sstevel@tonic-gate {
25487c478bd9Sstevel@tonic-gate int err, arg, answer;
25497c478bd9Sstevel@tonic-gate char line[ZONENAME_MAX + 128]; /* enough to ask a question */
2550bbec428eSgjelinek boolean_t force = B_FALSE;
2551bbec428eSgjelinek boolean_t arg_err = B_FALSE;
25527c478bd9Sstevel@tonic-gate
25537c478bd9Sstevel@tonic-gate optind = 0;
25547c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) {
25557c478bd9Sstevel@tonic-gate switch (arg) {
25567c478bd9Sstevel@tonic-gate case '?':
25577c478bd9Sstevel@tonic-gate longer_usage(CMD_DELETE);
2558bbec428eSgjelinek arg_err = B_TRUE;
25597ec75eb8Sgjelinek break;
25607c478bd9Sstevel@tonic-gate case 'F':
2561bbec428eSgjelinek force = B_TRUE;
25627c478bd9Sstevel@tonic-gate break;
25637c478bd9Sstevel@tonic-gate default:
25647c478bd9Sstevel@tonic-gate short_usage(CMD_DELETE);
2565bbec428eSgjelinek arg_err = B_TRUE;
25667ec75eb8Sgjelinek break;
25677ec75eb8Sgjelinek }
25687ec75eb8Sgjelinek }
25697ec75eb8Sgjelinek if (arg_err)
25707c478bd9Sstevel@tonic-gate return;
25717ec75eb8Sgjelinek
25727c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) {
25737c478bd9Sstevel@tonic-gate short_usage(CMD_DELETE);
25747c478bd9Sstevel@tonic-gate return;
25757c478bd9Sstevel@tonic-gate }
25767c478bd9Sstevel@tonic-gate
25777c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_DELETE))
25787c478bd9Sstevel@tonic-gate return;
25797c478bd9Sstevel@tonic-gate
2580087719fdSdp if (!force) {
2581087719fdSdp /*
2582087719fdSdp * Initialize sets up the global called "handle" and warns the
2583087719fdSdp * user if the zone is not configured. In force mode, we don't
2584087719fdSdp * trust that evaluation, and hence skip it. (We don't need the
2585087719fdSdp * handle to be loaded anyway, since zonecfg_destroy is done by
2586087719fdSdp * zonename). However, we also have to take care to emulate the
2587087719fdSdp * messages spit out by initialize; see below.
2588087719fdSdp */
2589bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK)
25907c478bd9Sstevel@tonic-gate return;
25917c478bd9Sstevel@tonic-gate
25927c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line),
25937c478bd9Sstevel@tonic-gate gettext("Are you sure you want to delete zone %s"), zone);
2594bbec428eSgjelinek if ((answer = ask_yesno(B_FALSE, line)) == -1) {
2595087719fdSdp zerr(gettext("Input not from terminal and -F not "
2596087719fdSdp "specified:\n%s command ignored, exiting."),
2597087719fdSdp cmd_to_str(CMD_DELETE));
25987c478bd9Sstevel@tonic-gate exit(Z_ERR);
25997c478bd9Sstevel@tonic-gate }
26007c478bd9Sstevel@tonic-gate if (answer != 1)
26017c478bd9Sstevel@tonic-gate return;
26027c478bd9Sstevel@tonic-gate }
26037c478bd9Sstevel@tonic-gate
2604cb8a054bSGlenn Faden /*
2605cb8a054bSGlenn Faden * This function removes the authorizations from user_attr
2606cb8a054bSGlenn Faden * that correspond to those specified in the configuration
2607cb8a054bSGlenn Faden */
2608cb8a054bSGlenn Faden if (initialize(B_TRUE) == Z_OK) {
2609cb8a054bSGlenn Faden (void) zonecfg_deauthorize_users(handle, zone);
2610cb8a054bSGlenn Faden }
2611087719fdSdp if ((err = zonecfg_destroy(zone, force)) != Z_OK) {
2612087719fdSdp if ((err == Z_BAD_ZONE_STATE) && !force) {
2613087719fdSdp zerr(gettext("Zone %s not in %s state; %s not "
2614087719fdSdp "allowed. Use -F to force %s."),
2615087719fdSdp zone, zone_state_str(ZONE_STATE_CONFIGURED),
2616087719fdSdp cmd_to_str(CMD_DELETE), cmd_to_str(CMD_DELETE));
2617087719fdSdp } else {
2618bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
26197c478bd9Sstevel@tonic-gate }
2620087719fdSdp }
2621bbec428eSgjelinek need_to_commit = B_FALSE;
2622087719fdSdp
2623087719fdSdp /*
2624087719fdSdp * Emulate initialize's messaging; if there wasn't a valid handle to
2625087719fdSdp * begin with, then user had typed delete (or delete -F) multiple
2626087719fdSdp * times. So we emit a message.
2627087719fdSdp *
2628087719fdSdp * We only do this in the 'force' case because normally, initialize()
2629087719fdSdp * takes care of this for us.
2630087719fdSdp */
2631087719fdSdp if (force && zonecfg_check_handle(handle) != Z_OK && interactive_mode)
2632087719fdSdp (void) printf(gettext("Use '%s' to begin "
2633087719fdSdp "configuring a new zone.\n"), cmd_to_str(CMD_CREATE));
26347c478bd9Sstevel@tonic-gate
26357c478bd9Sstevel@tonic-gate /*
26367c478bd9Sstevel@tonic-gate * Time for a new handle: finish the old one off first
26377c478bd9Sstevel@tonic-gate * then get a new one properly to avoid leaks.
26387c478bd9Sstevel@tonic-gate */
2639087719fdSdp if (got_handle) {
26407c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle);
26417c478bd9Sstevel@tonic-gate if ((handle = zonecfg_init_handle()) == NULL) {
2642bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE);
26437c478bd9Sstevel@tonic-gate exit(Z_ERR);
26447c478bd9Sstevel@tonic-gate }
26457c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_handle(zone, handle)) != Z_OK) {
26467c478bd9Sstevel@tonic-gate /* If there was no zone before, that's OK */
26477c478bd9Sstevel@tonic-gate if (err != Z_NO_ZONE)
2648bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
2649bbec428eSgjelinek got_handle = B_FALSE;
26507c478bd9Sstevel@tonic-gate }
26517c478bd9Sstevel@tonic-gate }
2652087719fdSdp }
26537c478bd9Sstevel@tonic-gate
26547c478bd9Sstevel@tonic-gate static int
fill_in_fstab(cmd_t * cmd,struct zone_fstab * fstab,boolean_t fill_in_only)2655bbec428eSgjelinek fill_in_fstab(cmd_t *cmd, struct zone_fstab *fstab, boolean_t fill_in_only)
26567c478bd9Sstevel@tonic-gate {
26577c478bd9Sstevel@tonic-gate int err, i;
26587c478bd9Sstevel@tonic-gate property_value_ptr_t pp;
26597c478bd9Sstevel@tonic-gate
2660bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK)
26617c478bd9Sstevel@tonic-gate return (err);
26627c478bd9Sstevel@tonic-gate
2663e193d1e6Svp157776 bzero(fstab, sizeof (*fstab));
26647c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) {
26657c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i];
26667c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) {
26677c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here."));
2668bbec428eSgjelinek saw_error = B_TRUE;
26697c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC);
26707c478bd9Sstevel@tonic-gate }
26717c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) {
26727c478bd9Sstevel@tonic-gate case PT_DIR:
26737c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_dir, pp->pv_simple,
26747c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_dir));
26757c478bd9Sstevel@tonic-gate break;
26767c478bd9Sstevel@tonic-gate case PT_SPECIAL:
26777c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_special, pp->pv_simple,
26787c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_special));
26797c478bd9Sstevel@tonic-gate break;
26807c478bd9Sstevel@tonic-gate case PT_RAW:
26817c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_raw, pp->pv_simple,
26827c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_raw));
26837c478bd9Sstevel@tonic-gate break;
26847c478bd9Sstevel@tonic-gate case PT_TYPE:
26857c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_type, pp->pv_simple,
26867c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_type));
26877c478bd9Sstevel@tonic-gate break;
26887c478bd9Sstevel@tonic-gate default:
26897c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]),
2690bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE);
26917c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC);
26927c478bd9Sstevel@tonic-gate }
26937c478bd9Sstevel@tonic-gate }
26947c478bd9Sstevel@tonic-gate if (fill_in_only)
26957c478bd9Sstevel@tonic-gate return (Z_OK);
26967c478bd9Sstevel@tonic-gate return (zonecfg_lookup_filesystem(handle, fstab));
26977c478bd9Sstevel@tonic-gate }
26987c478bd9Sstevel@tonic-gate
26997c478bd9Sstevel@tonic-gate static int
fill_in_nwiftab(cmd_t * cmd,struct zone_nwiftab * nwiftab,boolean_t fill_in_only)2700bbec428eSgjelinek fill_in_nwiftab(cmd_t *cmd, struct zone_nwiftab *nwiftab,
2701bbec428eSgjelinek boolean_t fill_in_only)
27027c478bd9Sstevel@tonic-gate {
27037c478bd9Sstevel@tonic-gate int err, i;
27047c478bd9Sstevel@tonic-gate property_value_ptr_t pp;
27057c478bd9Sstevel@tonic-gate
2706bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK)
27077c478bd9Sstevel@tonic-gate return (err);
27087c478bd9Sstevel@tonic-gate
2709e193d1e6Svp157776 bzero(nwiftab, sizeof (*nwiftab));
27107c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) {
27117c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i];
27127c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) {
27137c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here."));
2714bbec428eSgjelinek saw_error = B_TRUE;
27157c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC);
27167c478bd9Sstevel@tonic-gate }
27177c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) {
27187c478bd9Sstevel@tonic-gate case PT_ADDRESS:
27197c478bd9Sstevel@tonic-gate (void) strlcpy(nwiftab->zone_nwif_address,
27207c478bd9Sstevel@tonic-gate pp->pv_simple, sizeof (nwiftab->zone_nwif_address));
27217c478bd9Sstevel@tonic-gate break;
2722550b6e40SSowmini Varadhan case PT_ALLOWED_ADDRESS:
2723550b6e40SSowmini Varadhan (void) strlcpy(nwiftab->zone_nwif_allowed_address,
2724550b6e40SSowmini Varadhan pp->pv_simple,
2725550b6e40SSowmini Varadhan sizeof (nwiftab->zone_nwif_allowed_address));
2726550b6e40SSowmini Varadhan break;
27277c478bd9Sstevel@tonic-gate case PT_PHYSICAL:
27287c478bd9Sstevel@tonic-gate (void) strlcpy(nwiftab->zone_nwif_physical,
27297c478bd9Sstevel@tonic-gate pp->pv_simple,
27307c478bd9Sstevel@tonic-gate sizeof (nwiftab->zone_nwif_physical));
27317c478bd9Sstevel@tonic-gate break;
2732de860bd9Sgfaden case PT_DEFROUTER:
2733de860bd9Sgfaden (void) strlcpy(nwiftab->zone_nwif_defrouter,
2734de860bd9Sgfaden pp->pv_simple,
2735de860bd9Sgfaden sizeof (nwiftab->zone_nwif_defrouter));
2736de860bd9Sgfaden break;
27377c478bd9Sstevel@tonic-gate default:
27387c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]),
2739bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE);
27407c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC);
27417c478bd9Sstevel@tonic-gate }
27427c478bd9Sstevel@tonic-gate }
27437c478bd9Sstevel@tonic-gate if (fill_in_only)
27447c478bd9Sstevel@tonic-gate return (Z_OK);
27457c478bd9Sstevel@tonic-gate err = zonecfg_lookup_nwif(handle, nwiftab);
27467c478bd9Sstevel@tonic-gate return (err);
27477c478bd9Sstevel@tonic-gate }
27487c478bd9Sstevel@tonic-gate
27497c478bd9Sstevel@tonic-gate static int
fill_in_devtab(cmd_t * cmd,struct zone_devtab * devtab,boolean_t fill_in_only)2750bbec428eSgjelinek fill_in_devtab(cmd_t *cmd, struct zone_devtab *devtab, boolean_t fill_in_only)
27517c478bd9Sstevel@tonic-gate {
27527c478bd9Sstevel@tonic-gate int err, i;
27537c478bd9Sstevel@tonic-gate property_value_ptr_t pp;
27547c478bd9Sstevel@tonic-gate
2755bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK)
27567c478bd9Sstevel@tonic-gate return (err);
27577c478bd9Sstevel@tonic-gate
2758e193d1e6Svp157776 bzero(devtab, sizeof (*devtab));
27597c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) {
27607c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i];
27617c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) {
27627c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here."));
2763bbec428eSgjelinek saw_error = B_TRUE;
27647c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC);
27657c478bd9Sstevel@tonic-gate }
27667c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) {
27677c478bd9Sstevel@tonic-gate case PT_MATCH:
27687c478bd9Sstevel@tonic-gate (void) strlcpy(devtab->zone_dev_match, pp->pv_simple,
27697c478bd9Sstevel@tonic-gate sizeof (devtab->zone_dev_match));
27707c478bd9Sstevel@tonic-gate break;
27717c478bd9Sstevel@tonic-gate default:
27727c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]),
2773bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE);
27747c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC);
27757c478bd9Sstevel@tonic-gate }
27767c478bd9Sstevel@tonic-gate }
27777c478bd9Sstevel@tonic-gate if (fill_in_only)
27787c478bd9Sstevel@tonic-gate return (Z_OK);
27797c478bd9Sstevel@tonic-gate err = zonecfg_lookup_dev(handle, devtab);
27807c478bd9Sstevel@tonic-gate return (err);
27817c478bd9Sstevel@tonic-gate }
27827c478bd9Sstevel@tonic-gate
27837c478bd9Sstevel@tonic-gate static int
fill_in_rctltab(cmd_t * cmd,struct zone_rctltab * rctltab,boolean_t fill_in_only)2784bbec428eSgjelinek fill_in_rctltab(cmd_t *cmd, struct zone_rctltab *rctltab,
2785bbec428eSgjelinek boolean_t fill_in_only)
27867c478bd9Sstevel@tonic-gate {
27877c478bd9Sstevel@tonic-gate int err, i;
27887c478bd9Sstevel@tonic-gate property_value_ptr_t pp;
27897c478bd9Sstevel@tonic-gate
2790bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK)
27917c478bd9Sstevel@tonic-gate return (err);
27927c478bd9Sstevel@tonic-gate
2793e193d1e6Svp157776 bzero(rctltab, sizeof (*rctltab));
27947c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) {
27957c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i];
27967c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) {
27977c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here."));
2798bbec428eSgjelinek saw_error = B_TRUE;
27997c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC);
28007c478bd9Sstevel@tonic-gate }
28017c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) {
28027c478bd9Sstevel@tonic-gate case PT_NAME:
28037c478bd9Sstevel@tonic-gate (void) strlcpy(rctltab->zone_rctl_name, pp->pv_simple,
28047c478bd9Sstevel@tonic-gate sizeof (rctltab->zone_rctl_name));
28057c478bd9Sstevel@tonic-gate break;
28067c478bd9Sstevel@tonic-gate default:
28077c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]),
2808bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE);
28097c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC);
28107c478bd9Sstevel@tonic-gate }
28117c478bd9Sstevel@tonic-gate }
28127c478bd9Sstevel@tonic-gate if (fill_in_only)
28137c478bd9Sstevel@tonic-gate return (Z_OK);
28147c478bd9Sstevel@tonic-gate err = zonecfg_lookup_rctl(handle, rctltab);
28157c478bd9Sstevel@tonic-gate return (err);
28167c478bd9Sstevel@tonic-gate }
28177c478bd9Sstevel@tonic-gate
28187c478bd9Sstevel@tonic-gate static int
fill_in_attrtab(cmd_t * cmd,struct zone_attrtab * attrtab,boolean_t fill_in_only)2819bbec428eSgjelinek fill_in_attrtab(cmd_t *cmd, struct zone_attrtab *attrtab,
2820bbec428eSgjelinek boolean_t fill_in_only)
28217c478bd9Sstevel@tonic-gate {
28227c478bd9Sstevel@tonic-gate int err, i;
28237c478bd9Sstevel@tonic-gate property_value_ptr_t pp;
28247c478bd9Sstevel@tonic-gate
2825bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK)
28267c478bd9Sstevel@tonic-gate return (err);
28277c478bd9Sstevel@tonic-gate
2828e193d1e6Svp157776 bzero(attrtab, sizeof (*attrtab));
28297c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) {
28307c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i];
28317c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) {
28327c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here."));
2833bbec428eSgjelinek saw_error = B_TRUE;
28347c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC);
28357c478bd9Sstevel@tonic-gate }
28367c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) {
28377c478bd9Sstevel@tonic-gate case PT_NAME:
28387c478bd9Sstevel@tonic-gate (void) strlcpy(attrtab->zone_attr_name, pp->pv_simple,
28397c478bd9Sstevel@tonic-gate sizeof (attrtab->zone_attr_name));
28407c478bd9Sstevel@tonic-gate break;
28417c478bd9Sstevel@tonic-gate case PT_TYPE:
28427c478bd9Sstevel@tonic-gate (void) strlcpy(attrtab->zone_attr_type, pp->pv_simple,
28437c478bd9Sstevel@tonic-gate sizeof (attrtab->zone_attr_type));
28447c478bd9Sstevel@tonic-gate break;
28457c478bd9Sstevel@tonic-gate case PT_VALUE:
28467c478bd9Sstevel@tonic-gate (void) strlcpy(attrtab->zone_attr_value, pp->pv_simple,
28477c478bd9Sstevel@tonic-gate sizeof (attrtab->zone_attr_value));
28487c478bd9Sstevel@tonic-gate break;
28497c478bd9Sstevel@tonic-gate default:
28507c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]),
2851bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE);
28527c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC);
28537c478bd9Sstevel@tonic-gate }
28547c478bd9Sstevel@tonic-gate }
28557c478bd9Sstevel@tonic-gate if (fill_in_only)
28567c478bd9Sstevel@tonic-gate return (Z_OK);
28577c478bd9Sstevel@tonic-gate err = zonecfg_lookup_attr(handle, attrtab);
28587c478bd9Sstevel@tonic-gate return (err);
28597c478bd9Sstevel@tonic-gate }
28607c478bd9Sstevel@tonic-gate
2861fa9e4066Sahrens static int
fill_in_dstab(cmd_t * cmd,struct zone_dstab * dstab,boolean_t fill_in_only)2862bbec428eSgjelinek fill_in_dstab(cmd_t *cmd, struct zone_dstab *dstab, boolean_t fill_in_only)
2863fa9e4066Sahrens {
2864fa9e4066Sahrens int err, i;
2865fa9e4066Sahrens property_value_ptr_t pp;
2866fa9e4066Sahrens
2867bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK)
2868fa9e4066Sahrens return (err);
2869fa9e4066Sahrens
2870fa9e4066Sahrens dstab->zone_dataset_name[0] = '\0';
2871fa9e4066Sahrens for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) {
2872fa9e4066Sahrens pp = cmd->cmd_property_ptr[i];
2873fa9e4066Sahrens if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) {
2874fa9e4066Sahrens zerr(gettext("A simple value was expected here."));
2875bbec428eSgjelinek saw_error = B_TRUE;
2876fa9e4066Sahrens return (Z_INSUFFICIENT_SPEC);
2877fa9e4066Sahrens }
2878fa9e4066Sahrens switch (cmd->cmd_prop_name[i]) {
2879fa9e4066Sahrens case PT_NAME:
2880fa9e4066Sahrens (void) strlcpy(dstab->zone_dataset_name, pp->pv_simple,
2881fa9e4066Sahrens sizeof (dstab->zone_dataset_name));
2882fa9e4066Sahrens break;
2883fa9e4066Sahrens default:
2884fa9e4066Sahrens zone_perror(pt_to_str(cmd->cmd_prop_name[i]),
2885bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE);
2886fa9e4066Sahrens return (Z_INSUFFICIENT_SPEC);
2887fa9e4066Sahrens }
2888fa9e4066Sahrens }
2889fa9e4066Sahrens if (fill_in_only)
2890fa9e4066Sahrens return (Z_OK);
2891fa9e4066Sahrens return (zonecfg_lookup_ds(handle, dstab));
2892fa9e4066Sahrens }
2893fa9e4066Sahrens
2894cb8a054bSGlenn Faden static int
fill_in_admintab(cmd_t * cmd,struct zone_admintab * admintab,boolean_t fill_in_only)2895cb8a054bSGlenn Faden fill_in_admintab(cmd_t *cmd, struct zone_admintab *admintab,
2896cb8a054bSGlenn Faden boolean_t fill_in_only)
2897cb8a054bSGlenn Faden {
2898cb8a054bSGlenn Faden int err, i;
2899cb8a054bSGlenn Faden property_value_ptr_t pp;
2900cb8a054bSGlenn Faden
2901cb8a054bSGlenn Faden if ((err = initialize(B_TRUE)) != Z_OK)
2902cb8a054bSGlenn Faden return (err);
2903cb8a054bSGlenn Faden
2904cb8a054bSGlenn Faden bzero(admintab, sizeof (*admintab));
2905cb8a054bSGlenn Faden for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) {
2906cb8a054bSGlenn Faden pp = cmd->cmd_property_ptr[i];
2907cb8a054bSGlenn Faden if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) {
2908cb8a054bSGlenn Faden zerr(gettext("A simple value was expected here."));
2909cb8a054bSGlenn Faden saw_error = B_TRUE;
2910cb8a054bSGlenn Faden return (Z_INSUFFICIENT_SPEC);
2911cb8a054bSGlenn Faden }
2912cb8a054bSGlenn Faden switch (cmd->cmd_prop_name[i]) {
2913cb8a054bSGlenn Faden case PT_USER:
2914cb8a054bSGlenn Faden (void) strlcpy(admintab->zone_admin_user, pp->pv_simple,
2915cb8a054bSGlenn Faden sizeof (admintab->zone_admin_user));
2916cb8a054bSGlenn Faden break;
2917cb8a054bSGlenn Faden case PT_AUTHS:
2918cb8a054bSGlenn Faden (void) strlcpy(admintab->zone_admin_auths,
2919cb8a054bSGlenn Faden pp->pv_simple, sizeof (admintab->zone_admin_auths));
2920cb8a054bSGlenn Faden break;
2921cb8a054bSGlenn Faden default:
2922cb8a054bSGlenn Faden zone_perror(pt_to_str(cmd->cmd_prop_name[i]),
2923cb8a054bSGlenn Faden Z_NO_PROPERTY_TYPE, B_TRUE);
2924cb8a054bSGlenn Faden return (Z_INSUFFICIENT_SPEC);
2925cb8a054bSGlenn Faden }
2926cb8a054bSGlenn Faden }
2927cb8a054bSGlenn Faden if (fill_in_only)
2928cb8a054bSGlenn Faden return (Z_OK);
2929cb8a054bSGlenn Faden err = zonecfg_lookup_admin(handle, admintab);
2930cb8a054bSGlenn Faden return (err);
2931cb8a054bSGlenn Faden }
2932cb8a054bSGlenn Faden
29337c478bd9Sstevel@tonic-gate static void
remove_aliased_rctl(int type,char * name)29340209230bSgjelinek remove_aliased_rctl(int type, char *name)
29357c478bd9Sstevel@tonic-gate {
29360209230bSgjelinek int err;
29370209230bSgjelinek uint64_t tmp;
29387c478bd9Sstevel@tonic-gate
29390209230bSgjelinek if ((err = zonecfg_get_aliased_rctl(handle, name, &tmp)) != Z_OK) {
29400209230bSgjelinek zerr("%s %s: %s", cmd_to_str(CMD_CLEAR), pt_to_str(type),
29410209230bSgjelinek zonecfg_strerror(err));
2942bbec428eSgjelinek saw_error = B_TRUE;
29437c478bd9Sstevel@tonic-gate return;
29447c478bd9Sstevel@tonic-gate }
29450209230bSgjelinek if ((err = zonecfg_rm_aliased_rctl(handle, name)) != Z_OK) {
29460209230bSgjelinek zerr("%s %s: %s", cmd_to_str(CMD_CLEAR), pt_to_str(type),
29470209230bSgjelinek zonecfg_strerror(err));
2948bbec428eSgjelinek saw_error = B_TRUE;
29490209230bSgjelinek } else {
2950bbec428eSgjelinek need_to_commit = B_TRUE;
29510209230bSgjelinek }
29520209230bSgjelinek }
29537c478bd9Sstevel@tonic-gate
29540209230bSgjelinek static boolean_t
prompt_remove_resource(cmd_t * cmd,char * rsrc)29550209230bSgjelinek prompt_remove_resource(cmd_t *cmd, char *rsrc)
29560209230bSgjelinek {
29570209230bSgjelinek int num;
29580209230bSgjelinek int answer;
29590209230bSgjelinek int arg;
29600209230bSgjelinek boolean_t force = B_FALSE;
29610209230bSgjelinek char prompt[128];
2962bbec428eSgjelinek boolean_t arg_err = B_FALSE;
29637c478bd9Sstevel@tonic-gate
29640209230bSgjelinek optind = 0;
29650209230bSgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "F")) != EOF) {
29660209230bSgjelinek switch (arg) {
29670209230bSgjelinek case 'F':
29680209230bSgjelinek force = B_TRUE;
29690209230bSgjelinek break;
29700209230bSgjelinek default:
2971bbec428eSgjelinek arg_err = B_TRUE;
29727ec75eb8Sgjelinek break;
29737ec75eb8Sgjelinek }
29747ec75eb8Sgjelinek }
29757ec75eb8Sgjelinek if (arg_err)
29760209230bSgjelinek return (B_FALSE);
29777ec75eb8Sgjelinek
29780209230bSgjelinek
29790209230bSgjelinek num = zonecfg_num_resources(handle, rsrc);
29800209230bSgjelinek
29810209230bSgjelinek if (num == 0) {
29820209230bSgjelinek z_cmd_rt_perror(CMD_REMOVE, cmd->cmd_res_type, Z_NO_ENTRY,
2983bbec428eSgjelinek B_TRUE);
29840209230bSgjelinek return (B_FALSE);
29850209230bSgjelinek }
29860209230bSgjelinek if (num > 1 && !force) {
29870209230bSgjelinek if (!interactive_mode) {
29880209230bSgjelinek zerr(gettext("There are multiple instances of this "
29890209230bSgjelinek "resource. Either qualify the resource to\n"
29900209230bSgjelinek "remove a single instance or use the -F option to "
29910209230bSgjelinek "remove all instances."));
2992bbec428eSgjelinek saw_error = B_TRUE;
29930209230bSgjelinek return (B_FALSE);
29940209230bSgjelinek }
29950209230bSgjelinek (void) snprintf(prompt, sizeof (prompt), gettext(
29960209230bSgjelinek "Are you sure you want to remove ALL '%s' resources"),
29970209230bSgjelinek rsrc);
2998bbec428eSgjelinek answer = ask_yesno(B_FALSE, prompt);
29990209230bSgjelinek if (answer == -1) {
30000209230bSgjelinek zerr(gettext("Resource incomplete."));
30010209230bSgjelinek return (B_FALSE);
30020209230bSgjelinek }
30030209230bSgjelinek if (answer != 1)
30040209230bSgjelinek return (B_FALSE);
30050209230bSgjelinek }
30060209230bSgjelinek return (B_TRUE);
30070209230bSgjelinek }
30080209230bSgjelinek
30090209230bSgjelinek static void
remove_fs(cmd_t * cmd)30100209230bSgjelinek remove_fs(cmd_t *cmd)
30110209230bSgjelinek {
30120209230bSgjelinek int err;
30130209230bSgjelinek
30140209230bSgjelinek /* traditional, qualified fs removal */
30150209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) {
30160209230bSgjelinek struct zone_fstab fstab;
30170209230bSgjelinek
3018bbec428eSgjelinek if ((err = fill_in_fstab(cmd, &fstab, B_FALSE)) != Z_OK) {
3019bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_FS, err, B_TRUE);
30207c478bd9Sstevel@tonic-gate return;
30217c478bd9Sstevel@tonic-gate }
30227c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_filesystem(handle, &fstab)) != Z_OK)
3023bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_FS, err, B_TRUE);
30247c478bd9Sstevel@tonic-gate else
3025bbec428eSgjelinek need_to_commit = B_TRUE;
30267c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(fstab.zone_fs_options);
30277c478bd9Sstevel@tonic-gate return;
30280209230bSgjelinek }
30290209230bSgjelinek
30300209230bSgjelinek /*
30310209230bSgjelinek * unqualified fs removal. remove all fs's but prompt if more
30320209230bSgjelinek * than one.
30330209230bSgjelinek */
30340209230bSgjelinek if (!prompt_remove_resource(cmd, "fs"))
30350209230bSgjelinek return;
30360209230bSgjelinek
30370209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "fs")) != Z_OK)
3038bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_FS, err, B_TRUE);
30390209230bSgjelinek else
3040bbec428eSgjelinek need_to_commit = B_TRUE;
30410209230bSgjelinek }
30420209230bSgjelinek
30430209230bSgjelinek static void
remove_net(cmd_t * cmd)30440209230bSgjelinek remove_net(cmd_t *cmd)
30450209230bSgjelinek {
30460209230bSgjelinek int err;
30470209230bSgjelinek
30480209230bSgjelinek /* traditional, qualified net removal */
30490209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) {
30500209230bSgjelinek struct zone_nwiftab nwiftab;
30510209230bSgjelinek
3052bbec428eSgjelinek if ((err = fill_in_nwiftab(cmd, &nwiftab, B_FALSE)) != Z_OK) {
3053bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_NET, err, B_TRUE);
30547c478bd9Sstevel@tonic-gate return;
30557c478bd9Sstevel@tonic-gate }
30567c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_nwif(handle, &nwiftab)) != Z_OK)
3057bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_NET, err, B_TRUE);
30587c478bd9Sstevel@tonic-gate else
3059bbec428eSgjelinek need_to_commit = B_TRUE;
30607c478bd9Sstevel@tonic-gate return;
30610209230bSgjelinek }
30620209230bSgjelinek
30630209230bSgjelinek /*
30640209230bSgjelinek * unqualified net removal. remove all nets but prompt if more
30650209230bSgjelinek * than one.
30660209230bSgjelinek */
30670209230bSgjelinek if (!prompt_remove_resource(cmd, "net"))
30680209230bSgjelinek return;
30690209230bSgjelinek
30700209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "net")) != Z_OK)
3071bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_NET, err, B_TRUE);
30720209230bSgjelinek else
3073bbec428eSgjelinek need_to_commit = B_TRUE;
30740209230bSgjelinek }
30750209230bSgjelinek
30760209230bSgjelinek static void
remove_device(cmd_t * cmd)30770209230bSgjelinek remove_device(cmd_t *cmd)
30780209230bSgjelinek {
30790209230bSgjelinek int err;
30800209230bSgjelinek
30810209230bSgjelinek /* traditional, qualified device removal */
30820209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) {
30830209230bSgjelinek struct zone_devtab devtab;
30840209230bSgjelinek
3085bbec428eSgjelinek if ((err = fill_in_devtab(cmd, &devtab, B_FALSE)) != Z_OK) {
3086bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DEVICE, err, B_TRUE);
30877c478bd9Sstevel@tonic-gate return;
30887c478bd9Sstevel@tonic-gate }
30897c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_dev(handle, &devtab)) != Z_OK)
3090bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DEVICE, err, B_TRUE);
30917c478bd9Sstevel@tonic-gate else
3092bbec428eSgjelinek need_to_commit = B_TRUE;
30937c478bd9Sstevel@tonic-gate return;
30940209230bSgjelinek }
30950209230bSgjelinek
30960209230bSgjelinek /*
30970209230bSgjelinek * unqualified device removal. remove all devices but prompt if more
30980209230bSgjelinek * than one.
30990209230bSgjelinek */
31000209230bSgjelinek if (!prompt_remove_resource(cmd, "device"))
31010209230bSgjelinek return;
31020209230bSgjelinek
31030209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "device")) != Z_OK)
3104bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DEVICE, err, B_TRUE);
31050209230bSgjelinek else
3106bbec428eSgjelinek need_to_commit = B_TRUE;
31070209230bSgjelinek }
31080209230bSgjelinek
31090209230bSgjelinek static void
remove_attr(cmd_t * cmd)31100209230bSgjelinek remove_attr(cmd_t *cmd)
31110209230bSgjelinek {
31120209230bSgjelinek int err;
31130209230bSgjelinek
31140209230bSgjelinek /* traditional, qualified attr removal */
31150209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) {
31160209230bSgjelinek struct zone_attrtab attrtab;
31170209230bSgjelinek
3118bbec428eSgjelinek if ((err = fill_in_attrtab(cmd, &attrtab, B_FALSE)) != Z_OK) {
3119bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_ATTR, err, B_TRUE);
31200209230bSgjelinek return;
31210209230bSgjelinek }
31220209230bSgjelinek if ((err = zonecfg_delete_attr(handle, &attrtab)) != Z_OK)
3123bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_ATTR, err, B_TRUE);
31240209230bSgjelinek else
3125bbec428eSgjelinek need_to_commit = B_TRUE;
31260209230bSgjelinek return;
31270209230bSgjelinek }
31280209230bSgjelinek
31290209230bSgjelinek /*
31300209230bSgjelinek * unqualified attr removal. remove all attrs but prompt if more
31310209230bSgjelinek * than one.
31320209230bSgjelinek */
31330209230bSgjelinek if (!prompt_remove_resource(cmd, "attr"))
31340209230bSgjelinek return;
31350209230bSgjelinek
31360209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "attr")) != Z_OK)
3137bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_ATTR, err, B_TRUE);
31380209230bSgjelinek else
3139bbec428eSgjelinek need_to_commit = B_TRUE;
31400209230bSgjelinek }
31410209230bSgjelinek
31420209230bSgjelinek static void
remove_dataset(cmd_t * cmd)31430209230bSgjelinek remove_dataset(cmd_t *cmd)
31440209230bSgjelinek {
31450209230bSgjelinek int err;
31460209230bSgjelinek
31470209230bSgjelinek /* traditional, qualified dataset removal */
31480209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) {
31490209230bSgjelinek struct zone_dstab dstab;
31500209230bSgjelinek
3151bbec428eSgjelinek if ((err = fill_in_dstab(cmd, &dstab, B_FALSE)) != Z_OK) {
3152bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DATASET, err, B_TRUE);
31530209230bSgjelinek return;
31540209230bSgjelinek }
31550209230bSgjelinek if ((err = zonecfg_delete_ds(handle, &dstab)) != Z_OK)
3156bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DATASET, err, B_TRUE);
31570209230bSgjelinek else
3158bbec428eSgjelinek need_to_commit = B_TRUE;
31590209230bSgjelinek return;
31600209230bSgjelinek }
31610209230bSgjelinek
31620209230bSgjelinek /*
31630209230bSgjelinek * unqualified dataset removal. remove all datasets but prompt if more
31640209230bSgjelinek * than one.
31650209230bSgjelinek */
31660209230bSgjelinek if (!prompt_remove_resource(cmd, "dataset"))
31670209230bSgjelinek return;
31680209230bSgjelinek
31690209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "dataset")) != Z_OK)
3170bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DATASET, err, B_TRUE);
31710209230bSgjelinek else
3172bbec428eSgjelinek need_to_commit = B_TRUE;
31730209230bSgjelinek }
31740209230bSgjelinek
31750209230bSgjelinek static void
remove_rctl(cmd_t * cmd)31760209230bSgjelinek remove_rctl(cmd_t *cmd)
31770209230bSgjelinek {
31780209230bSgjelinek int err;
31790209230bSgjelinek
31800209230bSgjelinek /* traditional, qualified rctl removal */
31810209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) {
31820209230bSgjelinek struct zone_rctltab rctltab;
31830209230bSgjelinek
3184bbec428eSgjelinek if ((err = fill_in_rctltab(cmd, &rctltab, B_FALSE)) != Z_OK) {
3185bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_RCTL, err, B_TRUE);
31867c478bd9Sstevel@tonic-gate return;
31877c478bd9Sstevel@tonic-gate }
31887c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_rctl(handle, &rctltab)) != Z_OK)
3189bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_RCTL, err, B_TRUE);
31907c478bd9Sstevel@tonic-gate else
3191bbec428eSgjelinek need_to_commit = B_TRUE;
31927c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr);
31937c478bd9Sstevel@tonic-gate return;
31947c478bd9Sstevel@tonic-gate }
31950209230bSgjelinek
31960209230bSgjelinek /*
31970209230bSgjelinek * unqualified rctl removal. remove all rctls but prompt if more
31980209230bSgjelinek * than one.
31990209230bSgjelinek */
32000209230bSgjelinek if (!prompt_remove_resource(cmd, "rctl"))
32010209230bSgjelinek return;
32020209230bSgjelinek
32030209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "rctl")) != Z_OK)
3204bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_RCTL, err, B_TRUE);
32057c478bd9Sstevel@tonic-gate else
3206bbec428eSgjelinek need_to_commit = B_TRUE;
32070209230bSgjelinek }
32080209230bSgjelinek
32090209230bSgjelinek static void
remove_pset()32100209230bSgjelinek remove_pset()
32110209230bSgjelinek {
32120209230bSgjelinek int err;
32130209230bSgjelinek struct zone_psettab psettab;
32140209230bSgjelinek
32150209230bSgjelinek if ((err = zonecfg_lookup_pset(handle, &psettab)) != Z_OK) {
3216bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DCPU, err, B_TRUE);
32170209230bSgjelinek return;
32180209230bSgjelinek }
32190209230bSgjelinek if ((err = zonecfg_delete_pset(handle)) != Z_OK)
3220bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DCPU, err, B_TRUE);
32210209230bSgjelinek else
3222bbec428eSgjelinek need_to_commit = B_TRUE;
32230209230bSgjelinek }
32240209230bSgjelinek
32250209230bSgjelinek static void
remove_pcap()3226c97ad5cdSakolb remove_pcap()
3227c97ad5cdSakolb {
3228c97ad5cdSakolb int err;
3229c97ad5cdSakolb uint64_t tmp;
3230c97ad5cdSakolb
3231c97ad5cdSakolb if (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &tmp) != Z_OK) {
3232c97ad5cdSakolb zerr("%s %s: %s", cmd_to_str(CMD_REMOVE), rt_to_str(RT_PCAP),
3233c97ad5cdSakolb zonecfg_strerror(Z_NO_RESOURCE_TYPE));
3234bbec428eSgjelinek saw_error = B_TRUE;
3235c97ad5cdSakolb return;
3236c97ad5cdSakolb }
3237c97ad5cdSakolb
3238c97ad5cdSakolb if ((err = zonecfg_rm_aliased_rctl(handle, ALIAS_CPUCAP)) != Z_OK)
3239bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_PCAP, err, B_TRUE);
3240c97ad5cdSakolb else
3241bbec428eSgjelinek need_to_commit = B_TRUE;
3242c97ad5cdSakolb }
3243c97ad5cdSakolb
3244c97ad5cdSakolb static void
remove_mcap()32450209230bSgjelinek remove_mcap()
32460209230bSgjelinek {
32470209230bSgjelinek int err, res1, res2, res3;
32480209230bSgjelinek uint64_t tmp;
32490209230bSgjelinek struct zone_mcaptab mcaptab;
32500209230bSgjelinek boolean_t revert = B_FALSE;
32510209230bSgjelinek
32520209230bSgjelinek res1 = zonecfg_lookup_mcap(handle, &mcaptab);
32530209230bSgjelinek res2 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, &tmp);
32540209230bSgjelinek res3 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, &tmp);
32550209230bSgjelinek
32560209230bSgjelinek /* if none of these exist, there is no resource to remove */
32570209230bSgjelinek if (res1 != Z_OK && res2 != Z_OK && res3 != Z_OK) {
32580209230bSgjelinek zerr("%s %s: %s", cmd_to_str(CMD_REMOVE), rt_to_str(RT_MCAP),
32590209230bSgjelinek zonecfg_strerror(Z_NO_RESOURCE_TYPE));
3260bbec428eSgjelinek saw_error = B_TRUE;
32610209230bSgjelinek return;
32620209230bSgjelinek }
32630209230bSgjelinek if (res1 == Z_OK) {
32640209230bSgjelinek if ((err = zonecfg_delete_mcap(handle)) != Z_OK) {
3265bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_MCAP, err, B_TRUE);
32660209230bSgjelinek revert = B_TRUE;
32670209230bSgjelinek } else {
3268bbec428eSgjelinek need_to_commit = B_TRUE;
32690209230bSgjelinek }
32700209230bSgjelinek }
32710209230bSgjelinek if (res2 == Z_OK) {
32720209230bSgjelinek if ((err = zonecfg_rm_aliased_rctl(handle, ALIAS_MAXSWAP))
32730209230bSgjelinek != Z_OK) {
3274bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_MCAP, err, B_TRUE);
32750209230bSgjelinek revert = B_TRUE;
32760209230bSgjelinek } else {
3277bbec428eSgjelinek need_to_commit = B_TRUE;
32780209230bSgjelinek }
32790209230bSgjelinek }
32800209230bSgjelinek if (res3 == Z_OK) {
32810209230bSgjelinek if ((err = zonecfg_rm_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM))
32820209230bSgjelinek != Z_OK) {
3283bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_MCAP, err, B_TRUE);
32840209230bSgjelinek revert = B_TRUE;
32850209230bSgjelinek } else {
3286bbec428eSgjelinek need_to_commit = B_TRUE;
32870209230bSgjelinek }
32880209230bSgjelinek }
32890209230bSgjelinek
32900209230bSgjelinek if (revert)
3291bbec428eSgjelinek need_to_commit = B_FALSE;
32920209230bSgjelinek }
32930209230bSgjelinek
32940209230bSgjelinek static void
remove_admin(cmd_t * cmd)3295cb8a054bSGlenn Faden remove_admin(cmd_t *cmd)
3296cb8a054bSGlenn Faden {
3297cb8a054bSGlenn Faden int err;
3298cb8a054bSGlenn Faden
3299cb8a054bSGlenn Faden /* traditional, qualified attr removal */
3300cb8a054bSGlenn Faden if (cmd->cmd_prop_nv_pairs > 0) {
3301cb8a054bSGlenn Faden struct zone_admintab admintab;
3302cb8a054bSGlenn Faden
3303cb8a054bSGlenn Faden if ((err = fill_in_admintab(cmd, &admintab, B_FALSE)) != Z_OK) {
3304cb8a054bSGlenn Faden z_cmd_rt_perror(CMD_REMOVE, RT_ADMIN,
3305cb8a054bSGlenn Faden err, B_TRUE);
3306cb8a054bSGlenn Faden return;
3307cb8a054bSGlenn Faden }
3308cb8a054bSGlenn Faden if ((err = zonecfg_delete_admin(handle, &admintab,
3309cb8a054bSGlenn Faden zone))
3310cb8a054bSGlenn Faden != Z_OK)
3311cb8a054bSGlenn Faden z_cmd_rt_perror(CMD_REMOVE, RT_ADMIN,
3312cb8a054bSGlenn Faden err, B_TRUE);
3313cb8a054bSGlenn Faden else
3314cb8a054bSGlenn Faden need_to_commit = B_TRUE;
3315cb8a054bSGlenn Faden return;
3316cb8a054bSGlenn Faden } else {
3317cb8a054bSGlenn Faden /*
3318cb8a054bSGlenn Faden * unqualified admin removal.
3319cb8a054bSGlenn Faden * remove all admins but prompt if more
3320cb8a054bSGlenn Faden * than one.
3321cb8a054bSGlenn Faden */
3322cb8a054bSGlenn Faden if (!prompt_remove_resource(cmd, "admin"))
3323cb8a054bSGlenn Faden return;
3324cb8a054bSGlenn Faden
3325cb8a054bSGlenn Faden if ((err = zonecfg_delete_admins(handle, zone))
3326cb8a054bSGlenn Faden != Z_OK)
3327cb8a054bSGlenn Faden z_cmd_rt_perror(CMD_REMOVE, RT_ADMIN,
3328cb8a054bSGlenn Faden err, B_TRUE);
3329cb8a054bSGlenn Faden else
3330cb8a054bSGlenn Faden need_to_commit = B_TRUE;
3331cb8a054bSGlenn Faden }
3332cb8a054bSGlenn Faden }
3333cb8a054bSGlenn Faden
3334cb8a054bSGlenn Faden static void
remove_resource(cmd_t * cmd)33350209230bSgjelinek remove_resource(cmd_t *cmd)
33360209230bSgjelinek {
33370209230bSgjelinek int type;
33380209230bSgjelinek int arg;
3339bbec428eSgjelinek boolean_t arg_err = B_FALSE;
33400209230bSgjelinek
33410209230bSgjelinek if ((type = cmd->cmd_res_type) == RT_UNKNOWN) {
3342bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE);
33430209230bSgjelinek return;
33440209230bSgjelinek }
33450209230bSgjelinek
33460209230bSgjelinek optind = 0;
33470209230bSgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) {
33480209230bSgjelinek switch (arg) {
33490209230bSgjelinek case '?':
33500209230bSgjelinek longer_usage(CMD_REMOVE);
3351bbec428eSgjelinek arg_err = B_TRUE;
33527ec75eb8Sgjelinek break;
33530209230bSgjelinek case 'F':
33540209230bSgjelinek break;
33550209230bSgjelinek default:
33560209230bSgjelinek short_usage(CMD_REMOVE);
3357bbec428eSgjelinek arg_err = B_TRUE;
33587ec75eb8Sgjelinek break;
33597ec75eb8Sgjelinek }
33607ec75eb8Sgjelinek }
33617ec75eb8Sgjelinek if (arg_err)
33620209230bSgjelinek return;
33630209230bSgjelinek
3364bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK)
33650209230bSgjelinek return;
33660209230bSgjelinek
33670209230bSgjelinek switch (type) {
33680209230bSgjelinek case RT_FS:
33690209230bSgjelinek remove_fs(cmd);
33700209230bSgjelinek return;
33710209230bSgjelinek case RT_NET:
33720209230bSgjelinek remove_net(cmd);
33730209230bSgjelinek return;
33740209230bSgjelinek case RT_DEVICE:
33750209230bSgjelinek remove_device(cmd);
33760209230bSgjelinek return;
33770209230bSgjelinek case RT_RCTL:
33780209230bSgjelinek remove_rctl(cmd);
33790209230bSgjelinek return;
33800209230bSgjelinek case RT_ATTR:
33810209230bSgjelinek remove_attr(cmd);
33827c478bd9Sstevel@tonic-gate return;
3383fa9e4066Sahrens case RT_DATASET:
33840209230bSgjelinek remove_dataset(cmd);
3385fa9e4066Sahrens return;
33860209230bSgjelinek case RT_DCPU:
33870209230bSgjelinek remove_pset();
33880209230bSgjelinek return;
3389c97ad5cdSakolb case RT_PCAP:
3390c97ad5cdSakolb remove_pcap();
3391c97ad5cdSakolb return;
33920209230bSgjelinek case RT_MCAP:
33930209230bSgjelinek remove_mcap();
3394fa9e4066Sahrens return;
3395cb8a054bSGlenn Faden case RT_ADMIN:
3396cb8a054bSGlenn Faden remove_admin(cmd);
3397cb8a054bSGlenn Faden return;
33987c478bd9Sstevel@tonic-gate default:
3399bbec428eSgjelinek zone_perror(rt_to_str(type), Z_NO_RESOURCE_TYPE, B_TRUE);
3400bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE);
3401bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES);
34027c478bd9Sstevel@tonic-gate return;
34037c478bd9Sstevel@tonic-gate }
34047c478bd9Sstevel@tonic-gate }
34057c478bd9Sstevel@tonic-gate
34067c478bd9Sstevel@tonic-gate static void
remove_property(cmd_t * cmd)34077c478bd9Sstevel@tonic-gate remove_property(cmd_t *cmd)
34087c478bd9Sstevel@tonic-gate {
34097c478bd9Sstevel@tonic-gate char *prop_id;
34107c478bd9Sstevel@tonic-gate int err, res_type, prop_type;
34117c478bd9Sstevel@tonic-gate property_value_ptr_t pp;
34127c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *rctlvaltab;
34137c478bd9Sstevel@tonic-gate complex_property_ptr_t cx;
34147c478bd9Sstevel@tonic-gate
34157c478bd9Sstevel@tonic-gate res_type = resource_scope;
34167c478bd9Sstevel@tonic-gate prop_type = cmd->cmd_prop_name[0];
34177c478bd9Sstevel@tonic-gate if (res_type == RT_UNKNOWN || prop_type == PT_UNKNOWN) {
3418bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE);
34197c478bd9Sstevel@tonic-gate return;
34207c478bd9Sstevel@tonic-gate }
34217c478bd9Sstevel@tonic-gate
34227c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs != 1) {
3423bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE);
34247c478bd9Sstevel@tonic-gate return;
34257c478bd9Sstevel@tonic-gate }
34267c478bd9Sstevel@tonic-gate
3427bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK)
34287c478bd9Sstevel@tonic-gate return;
34297c478bd9Sstevel@tonic-gate
34307c478bd9Sstevel@tonic-gate switch (res_type) {
34317c478bd9Sstevel@tonic-gate case RT_FS:
34327c478bd9Sstevel@tonic-gate if (prop_type != PT_OPTIONS) {
34337c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
3434bbec428eSgjelinek B_TRUE);
3435bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE);
3436bbec428eSgjelinek usage(B_FALSE, HELP_PROPS);
34377c478bd9Sstevel@tonic-gate return;
34387c478bd9Sstevel@tonic-gate }
34397c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0];
34407c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_COMPLEX) {
34417c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected here."),
34427c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_SIMPLE),
34437c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST));
3444bbec428eSgjelinek saw_error = B_TRUE;
34457c478bd9Sstevel@tonic-gate return;
34467c478bd9Sstevel@tonic-gate }
34477c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_SIMPLE) {
34487c478bd9Sstevel@tonic-gate if (pp->pv_simple == NULL) {
3449bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE);
34507c478bd9Sstevel@tonic-gate return;
34517c478bd9Sstevel@tonic-gate }
34527c478bd9Sstevel@tonic-gate prop_id = pp->pv_simple;
34537c478bd9Sstevel@tonic-gate err = zonecfg_remove_fs_option(&in_progress_fstab,
34547c478bd9Sstevel@tonic-gate prop_id);
34557c478bd9Sstevel@tonic-gate if (err != Z_OK)
3456bbec428eSgjelinek zone_perror(pt_to_str(prop_type), err, B_TRUE);
34577c478bd9Sstevel@tonic-gate } else {
34587c478bd9Sstevel@tonic-gate list_property_ptr_t list;
34597c478bd9Sstevel@tonic-gate
34607c478bd9Sstevel@tonic-gate for (list = pp->pv_list; list != NULL;
34617c478bd9Sstevel@tonic-gate list = list->lp_next) {
34627c478bd9Sstevel@tonic-gate prop_id = list->lp_simple;
34637c478bd9Sstevel@tonic-gate if (prop_id == NULL)
34647c478bd9Sstevel@tonic-gate break;
34657c478bd9Sstevel@tonic-gate err = zonecfg_remove_fs_option(
34667c478bd9Sstevel@tonic-gate &in_progress_fstab, prop_id);
34677c478bd9Sstevel@tonic-gate if (err != Z_OK)
34687c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), err,
3469bbec428eSgjelinek B_TRUE);
34707c478bd9Sstevel@tonic-gate }
34717c478bd9Sstevel@tonic-gate }
34727c478bd9Sstevel@tonic-gate return;
34737c478bd9Sstevel@tonic-gate case RT_RCTL:
34747c478bd9Sstevel@tonic-gate if (prop_type != PT_VALUE) {
34757c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
3476bbec428eSgjelinek B_TRUE);
3477bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE);
3478bbec428eSgjelinek usage(B_FALSE, HELP_PROPS);
34797c478bd9Sstevel@tonic-gate return;
34807c478bd9Sstevel@tonic-gate }
34817c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0];
34827c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_COMPLEX) {
34837c478bd9Sstevel@tonic-gate zerr(gettext("A %s value was expected here."),
34847c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_COMPLEX));
3485bbec428eSgjelinek saw_error = B_TRUE;
34867c478bd9Sstevel@tonic-gate return;
34877c478bd9Sstevel@tonic-gate }
34887c478bd9Sstevel@tonic-gate if ((rctlvaltab = alloc_rctlvaltab()) == NULL) {
3489bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_TRUE);
34907c478bd9Sstevel@tonic-gate exit(Z_ERR);
34917c478bd9Sstevel@tonic-gate }
34927c478bd9Sstevel@tonic-gate for (cx = pp->pv_complex; cx != NULL; cx = cx->cp_next) {
34937c478bd9Sstevel@tonic-gate switch (cx->cp_type) {
34947c478bd9Sstevel@tonic-gate case PT_PRIV:
34957c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_priv,
34967c478bd9Sstevel@tonic-gate cx->cp_value,
34977c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_priv));
34987c478bd9Sstevel@tonic-gate break;
34997c478bd9Sstevel@tonic-gate case PT_LIMIT:
35007c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_limit,
35017c478bd9Sstevel@tonic-gate cx->cp_value,
35027c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_limit));
35037c478bd9Sstevel@tonic-gate break;
35047c478bd9Sstevel@tonic-gate case PT_ACTION:
35057c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_action,
35067c478bd9Sstevel@tonic-gate cx->cp_value,
35077c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_action));
35087c478bd9Sstevel@tonic-gate break;
35097c478bd9Sstevel@tonic-gate default:
35107c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type),
3511bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE);
3512bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE);
3513bbec428eSgjelinek usage(B_FALSE, HELP_PROPS);
35147c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab);
35157c478bd9Sstevel@tonic-gate return;
35167c478bd9Sstevel@tonic-gate }
35177c478bd9Sstevel@tonic-gate }
35187c478bd9Sstevel@tonic-gate rctlvaltab->zone_rctlval_next = NULL;
35197c478bd9Sstevel@tonic-gate err = zonecfg_remove_rctl_value(&in_progress_rctltab,
35207c478bd9Sstevel@tonic-gate rctlvaltab);
35217c478bd9Sstevel@tonic-gate if (err != Z_OK)
3522bbec428eSgjelinek zone_perror(pt_to_str(prop_type), err, B_TRUE);
35237c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab);
35247c478bd9Sstevel@tonic-gate return;
3525de860bd9Sgfaden case RT_NET:
3526de860bd9Sgfaden if (prop_type != PT_DEFROUTER) {
3527de860bd9Sgfaden zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
3528bbec428eSgjelinek B_TRUE);
3529bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE);
3530bbec428eSgjelinek usage(B_FALSE, HELP_PROPS);
3531de860bd9Sgfaden return;
3532de860bd9Sgfaden } else {
3533de860bd9Sgfaden bzero(&in_progress_nwiftab.zone_nwif_defrouter,
3534de860bd9Sgfaden sizeof (in_progress_nwiftab.zone_nwif_defrouter));
3535de860bd9Sgfaden return;
3536de860bd9Sgfaden }
35377c478bd9Sstevel@tonic-gate default:
3538bbec428eSgjelinek zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, B_TRUE);
3539bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE);
3540bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES);
35417c478bd9Sstevel@tonic-gate return;
35427c478bd9Sstevel@tonic-gate }
35437c478bd9Sstevel@tonic-gate }
35447c478bd9Sstevel@tonic-gate
35457c478bd9Sstevel@tonic-gate void
remove_func(cmd_t * cmd)35467c478bd9Sstevel@tonic-gate remove_func(cmd_t *cmd)
35477c478bd9Sstevel@tonic-gate {
35487c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_REMOVE))
35497c478bd9Sstevel@tonic-gate return;
35507c478bd9Sstevel@tonic-gate
35517c478bd9Sstevel@tonic-gate assert(cmd != NULL);
35527c478bd9Sstevel@tonic-gate
35530209230bSgjelinek if (global_scope) {
35540209230bSgjelinek if (gz_invalid_resource(cmd->cmd_res_type)) {
35550209230bSgjelinek zerr(gettext("%s is not a valid resource for the "
35560209230bSgjelinek "global zone."), rt_to_str(cmd->cmd_res_type));
3557bbec428eSgjelinek saw_error = B_TRUE;
35580209230bSgjelinek return;
35590209230bSgjelinek }
35607c478bd9Sstevel@tonic-gate remove_resource(cmd);
35610209230bSgjelinek } else {
35627c478bd9Sstevel@tonic-gate remove_property(cmd);
35637c478bd9Sstevel@tonic-gate }
35640209230bSgjelinek }
35650209230bSgjelinek
35660209230bSgjelinek static void
clear_property(cmd_t * cmd)35670209230bSgjelinek clear_property(cmd_t *cmd)
35680209230bSgjelinek {
35690209230bSgjelinek int res_type, prop_type;
35700209230bSgjelinek
35710209230bSgjelinek res_type = resource_scope;
35720209230bSgjelinek prop_type = cmd->cmd_res_type;
35730209230bSgjelinek if (res_type == RT_UNKNOWN || prop_type == PT_UNKNOWN) {
3574bbec428eSgjelinek long_usage(CMD_CLEAR, B_TRUE);
35750209230bSgjelinek return;
35760209230bSgjelinek }
35770209230bSgjelinek
3578bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK)
35790209230bSgjelinek return;
35800209230bSgjelinek
35810209230bSgjelinek switch (res_type) {
35820209230bSgjelinek case RT_FS:
35830209230bSgjelinek if (prop_type == PT_RAW) {
35840209230bSgjelinek in_progress_fstab.zone_fs_raw[0] = '\0';
3585bbec428eSgjelinek need_to_commit = B_TRUE;
35860209230bSgjelinek return;
35870209230bSgjelinek }
35880209230bSgjelinek break;
35890209230bSgjelinek case RT_DCPU:
35900209230bSgjelinek if (prop_type == PT_IMPORTANCE) {
35910209230bSgjelinek in_progress_psettab.zone_importance[0] = '\0';
3592bbec428eSgjelinek need_to_commit = B_TRUE;
35930209230bSgjelinek return;
35940209230bSgjelinek }
35950209230bSgjelinek break;
35960209230bSgjelinek case RT_MCAP:
35970209230bSgjelinek switch (prop_type) {
35980209230bSgjelinek case PT_PHYSICAL:
35990209230bSgjelinek in_progress_mcaptab.zone_physmem_cap[0] = '\0';
3600bbec428eSgjelinek need_to_commit = B_TRUE;
36010209230bSgjelinek return;
36020209230bSgjelinek case PT_SWAP:
36030209230bSgjelinek remove_aliased_rctl(PT_SWAP, ALIAS_MAXSWAP);
36040209230bSgjelinek return;
36050209230bSgjelinek case PT_LOCKED:
36060209230bSgjelinek remove_aliased_rctl(PT_LOCKED, ALIAS_MAXLOCKEDMEM);
36070209230bSgjelinek return;
36080209230bSgjelinek }
36090209230bSgjelinek break;
36100209230bSgjelinek default:
36110209230bSgjelinek break;
36120209230bSgjelinek }
36130209230bSgjelinek
3614bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_CLEAR_DISALLOW, B_TRUE);
36150209230bSgjelinek }
36160209230bSgjelinek
36170209230bSgjelinek static void
clear_global(cmd_t * cmd)36180209230bSgjelinek clear_global(cmd_t *cmd)
36190209230bSgjelinek {
36200209230bSgjelinek int err, type;
36210209230bSgjelinek
36220209230bSgjelinek if ((type = cmd->cmd_res_type) == RT_UNKNOWN) {
3623bbec428eSgjelinek long_usage(CMD_CLEAR, B_TRUE);
36240209230bSgjelinek return;
36250209230bSgjelinek }
36260209230bSgjelinek
3627bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK)
36280209230bSgjelinek return;
36290209230bSgjelinek
36300209230bSgjelinek switch (type) {
36310209230bSgjelinek case PT_ZONENAME:
36320209230bSgjelinek /* FALLTHRU */
36330209230bSgjelinek case PT_ZONEPATH:
36340209230bSgjelinek /* FALLTHRU */
36350209230bSgjelinek case PT_BRAND:
3636bbec428eSgjelinek zone_perror(pt_to_str(type), Z_CLEAR_DISALLOW, B_TRUE);
36370209230bSgjelinek return;
36380209230bSgjelinek case PT_AUTOBOOT:
36390209230bSgjelinek /* false is default; we'll treat as equivalent to clearing */
36400209230bSgjelinek if ((err = zonecfg_set_autoboot(handle, B_FALSE)) != Z_OK)
3641bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_AUTOBOOT, err, B_TRUE);
36420209230bSgjelinek else
3643bbec428eSgjelinek need_to_commit = B_TRUE;
36440209230bSgjelinek return;
36450209230bSgjelinek case PT_POOL:
36460209230bSgjelinek if ((err = zonecfg_set_pool(handle, NULL)) != Z_OK)
3647bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_POOL, err, B_TRUE);
36480209230bSgjelinek else
3649bbec428eSgjelinek need_to_commit = B_TRUE;
36500209230bSgjelinek return;
36510209230bSgjelinek case PT_LIMITPRIV:
36520209230bSgjelinek if ((err = zonecfg_set_limitpriv(handle, NULL)) != Z_OK)
3653bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_LIMITPRIV, err, B_TRUE);
36540209230bSgjelinek else
3655bbec428eSgjelinek need_to_commit = B_TRUE;
36560209230bSgjelinek return;
36570209230bSgjelinek case PT_BOOTARGS:
36580209230bSgjelinek if ((err = zonecfg_set_bootargs(handle, NULL)) != Z_OK)
3659bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_BOOTARGS, err, B_TRUE);
36600209230bSgjelinek else
3661bbec428eSgjelinek need_to_commit = B_TRUE;
36620209230bSgjelinek return;
36630209230bSgjelinek case PT_SCHED:
36640209230bSgjelinek if ((err = zonecfg_set_sched(handle, NULL)) != Z_OK)
3665bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_SCHED, err, B_TRUE);
36660209230bSgjelinek else
3667bbec428eSgjelinek need_to_commit = B_TRUE;
36680209230bSgjelinek return;
3669f4b3ec61Sdh155122 case PT_IPTYPE:
3670f4b3ec61Sdh155122 /* shared is default; we'll treat as equivalent to clearing */
3671f4b3ec61Sdh155122 if ((err = zonecfg_set_iptype(handle, ZS_SHARED)) != Z_OK)
3672bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_IPTYPE, err, B_TRUE);
3673f4b3ec61Sdh155122 else
3674bbec428eSgjelinek need_to_commit = B_TRUE;
3675f4b3ec61Sdh155122 return;
36760209230bSgjelinek case PT_MAXLWPS:
36770209230bSgjelinek remove_aliased_rctl(PT_MAXLWPS, ALIAS_MAXLWPS);
36780209230bSgjelinek return;
3679ff19e029SMenno Lageman case PT_MAXPROCS:
3680ff19e029SMenno Lageman remove_aliased_rctl(PT_MAXPROCS, ALIAS_MAXPROCS);
3681ff19e029SMenno Lageman return;
36820209230bSgjelinek case PT_MAXSHMMEM:
36830209230bSgjelinek remove_aliased_rctl(PT_MAXSHMMEM, ALIAS_MAXSHMMEM);
36840209230bSgjelinek return;
36850209230bSgjelinek case PT_MAXSHMIDS:
36860209230bSgjelinek remove_aliased_rctl(PT_MAXSHMIDS, ALIAS_MAXSHMIDS);
36870209230bSgjelinek return;
36880209230bSgjelinek case PT_MAXMSGIDS:
36890209230bSgjelinek remove_aliased_rctl(PT_MAXMSGIDS, ALIAS_MAXMSGIDS);
36900209230bSgjelinek return;
36910209230bSgjelinek case PT_MAXSEMIDS:
36920209230bSgjelinek remove_aliased_rctl(PT_MAXSEMIDS, ALIAS_MAXSEMIDS);
36930209230bSgjelinek return;
36940209230bSgjelinek case PT_SHARES:
36950209230bSgjelinek remove_aliased_rctl(PT_SHARES, ALIAS_SHARES);
36960209230bSgjelinek return;
36975679c89fSjv227347 case PT_HOSTID:
36985679c89fSjv227347 if ((err = zonecfg_set_hostid(handle, NULL)) != Z_OK)
36995679c89fSjv227347 z_cmd_rt_perror(CMD_CLEAR, RT_HOSTID, err, B_TRUE);
37005679c89fSjv227347 else
37015679c89fSjv227347 need_to_commit = B_TRUE;
37025679c89fSjv227347 return;
37030fbb751dSJohn Levon case PT_FS_ALLOWED:
37040fbb751dSJohn Levon if ((err = zonecfg_set_fs_allowed(handle, NULL)) != Z_OK)
37050fbb751dSJohn Levon z_cmd_rt_perror(CMD_CLEAR, RT_FS_ALLOWED, err, B_TRUE);
37060fbb751dSJohn Levon else
37070fbb751dSJohn Levon need_to_commit = B_TRUE;
37080fbb751dSJohn Levon return;
37090209230bSgjelinek default:
3710bbec428eSgjelinek zone_perror(pt_to_str(type), Z_NO_PROPERTY_TYPE, B_TRUE);
3711bbec428eSgjelinek long_usage(CMD_CLEAR, B_TRUE);
3712bbec428eSgjelinek usage(B_FALSE, HELP_PROPS);
37130209230bSgjelinek return;
37140209230bSgjelinek }
37150209230bSgjelinek }
37160209230bSgjelinek
37170209230bSgjelinek void
clear_func(cmd_t * cmd)37180209230bSgjelinek clear_func(cmd_t *cmd)
37190209230bSgjelinek {
37200209230bSgjelinek if (zone_is_read_only(CMD_CLEAR))
37210209230bSgjelinek return;
37220209230bSgjelinek
37230209230bSgjelinek assert(cmd != NULL);
37240209230bSgjelinek
37250209230bSgjelinek if (global_scope) {
37260209230bSgjelinek if (gz_invalid_property(cmd->cmd_res_type)) {
37270209230bSgjelinek zerr(gettext("%s is not a valid property for the "
37280209230bSgjelinek "global zone."), pt_to_str(cmd->cmd_res_type));
3729bbec428eSgjelinek saw_error = B_TRUE;
37300209230bSgjelinek return;
37310209230bSgjelinek }
37320209230bSgjelinek
37330209230bSgjelinek clear_global(cmd);
37340209230bSgjelinek } else {
37350209230bSgjelinek clear_property(cmd);
37360209230bSgjelinek }
37370209230bSgjelinek }
37387c478bd9Sstevel@tonic-gate
37397c478bd9Sstevel@tonic-gate void
select_func(cmd_t * cmd)37407c478bd9Sstevel@tonic-gate select_func(cmd_t *cmd)
37417c478bd9Sstevel@tonic-gate {
37420209230bSgjelinek int type, err, res;
37430209230bSgjelinek uint64_t limit;
3744c97ad5cdSakolb uint64_t tmp;
37457c478bd9Sstevel@tonic-gate
37467c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_SELECT))
37477c478bd9Sstevel@tonic-gate return;
37487c478bd9Sstevel@tonic-gate
37497c478bd9Sstevel@tonic-gate assert(cmd != NULL);
37507c478bd9Sstevel@tonic-gate
37517c478bd9Sstevel@tonic-gate if (global_scope) {
3752bbec428eSgjelinek global_scope = B_FALSE;
37537c478bd9Sstevel@tonic-gate resource_scope = cmd->cmd_res_type;
37547c478bd9Sstevel@tonic-gate end_op = CMD_SELECT;
37557c478bd9Sstevel@tonic-gate } else {
37567c478bd9Sstevel@tonic-gate scope_usage(CMD_SELECT);
37577c478bd9Sstevel@tonic-gate return;
37587c478bd9Sstevel@tonic-gate }
37597c478bd9Sstevel@tonic-gate
37607c478bd9Sstevel@tonic-gate if ((type = cmd->cmd_res_type) == RT_UNKNOWN) {
3761bbec428eSgjelinek long_usage(CMD_SELECT, B_TRUE);
37627c478bd9Sstevel@tonic-gate return;
37637c478bd9Sstevel@tonic-gate }
37647c478bd9Sstevel@tonic-gate
3765bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK)
37667c478bd9Sstevel@tonic-gate return;
37677c478bd9Sstevel@tonic-gate
37687c478bd9Sstevel@tonic-gate switch (type) {
37697c478bd9Sstevel@tonic-gate case RT_FS:
3770bbec428eSgjelinek if ((err = fill_in_fstab(cmd, &old_fstab, B_FALSE)) != Z_OK) {
3771bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_FS, err, B_TRUE);
3772bbec428eSgjelinek global_scope = B_TRUE;
37737c478bd9Sstevel@tonic-gate }
37747c478bd9Sstevel@tonic-gate bcopy(&old_fstab, &in_progress_fstab,
37757c478bd9Sstevel@tonic-gate sizeof (struct zone_fstab));
37767c478bd9Sstevel@tonic-gate return;
37777c478bd9Sstevel@tonic-gate case RT_NET:
3778bbec428eSgjelinek if ((err = fill_in_nwiftab(cmd, &old_nwiftab, B_FALSE))
3779bbec428eSgjelinek != Z_OK) {
3780bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_NET, err, B_TRUE);
3781bbec428eSgjelinek global_scope = B_TRUE;
37827c478bd9Sstevel@tonic-gate }
37837c478bd9Sstevel@tonic-gate bcopy(&old_nwiftab, &in_progress_nwiftab,
37847c478bd9Sstevel@tonic-gate sizeof (struct zone_nwiftab));
37857c478bd9Sstevel@tonic-gate return;
37867c478bd9Sstevel@tonic-gate case RT_DEVICE:
3787bbec428eSgjelinek if ((err = fill_in_devtab(cmd, &old_devtab, B_FALSE)) != Z_OK) {
3788bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_DEVICE, err, B_TRUE);
3789bbec428eSgjelinek global_scope = B_TRUE;
37907c478bd9Sstevel@tonic-gate }
37917c478bd9Sstevel@tonic-gate bcopy(&old_devtab, &in_progress_devtab,
37927c478bd9Sstevel@tonic-gate sizeof (struct zone_devtab));
37937c478bd9Sstevel@tonic-gate return;
37947c478bd9Sstevel@tonic-gate case RT_RCTL:
3795bbec428eSgjelinek if ((err = fill_in_rctltab(cmd, &old_rctltab, B_FALSE))
3796bbec428eSgjelinek != Z_OK) {
3797bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_RCTL, err, B_TRUE);
3798bbec428eSgjelinek global_scope = B_TRUE;
37997c478bd9Sstevel@tonic-gate }
38007c478bd9Sstevel@tonic-gate bcopy(&old_rctltab, &in_progress_rctltab,
38017c478bd9Sstevel@tonic-gate sizeof (struct zone_rctltab));
38027c478bd9Sstevel@tonic-gate return;
38037c478bd9Sstevel@tonic-gate case RT_ATTR:
3804bbec428eSgjelinek if ((err = fill_in_attrtab(cmd, &old_attrtab, B_FALSE))
3805bbec428eSgjelinek != Z_OK) {
3806bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_ATTR, err, B_TRUE);
3807bbec428eSgjelinek global_scope = B_TRUE;
38087c478bd9Sstevel@tonic-gate }
38097c478bd9Sstevel@tonic-gate bcopy(&old_attrtab, &in_progress_attrtab,
38107c478bd9Sstevel@tonic-gate sizeof (struct zone_attrtab));
38117c478bd9Sstevel@tonic-gate return;
3812fa9e4066Sahrens case RT_DATASET:
3813bbec428eSgjelinek if ((err = fill_in_dstab(cmd, &old_dstab, B_FALSE)) != Z_OK) {
3814bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_DATASET, err, B_TRUE);
3815bbec428eSgjelinek global_scope = B_TRUE;
3816fa9e4066Sahrens }
3817fa9e4066Sahrens bcopy(&old_dstab, &in_progress_dstab,
3818fa9e4066Sahrens sizeof (struct zone_dstab));
3819fa9e4066Sahrens return;
38200209230bSgjelinek case RT_DCPU:
38210209230bSgjelinek if ((err = zonecfg_lookup_pset(handle, &old_psettab)) != Z_OK) {
3822bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_DCPU, err, B_TRUE);
3823bbec428eSgjelinek global_scope = B_TRUE;
38240209230bSgjelinek }
38250209230bSgjelinek bcopy(&old_psettab, &in_progress_psettab,
38260209230bSgjelinek sizeof (struct zone_psettab));
38270209230bSgjelinek return;
3828c97ad5cdSakolb case RT_PCAP:
3829c97ad5cdSakolb if ((err = zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &tmp))
3830c97ad5cdSakolb != Z_OK) {
3831bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_PCAP, err, B_TRUE);
3832bbec428eSgjelinek global_scope = B_TRUE;
3833c97ad5cdSakolb }
3834c97ad5cdSakolb return;
38350209230bSgjelinek case RT_MCAP:
38360209230bSgjelinek /* if none of these exist, there is no resource to select */
38370209230bSgjelinek if ((res = zonecfg_lookup_mcap(handle, &old_mcaptab)) != Z_OK &&
38380209230bSgjelinek zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, &limit)
38390209230bSgjelinek != Z_OK &&
38400209230bSgjelinek zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, &limit)
38410209230bSgjelinek != Z_OK) {
38420209230bSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_MCAP, Z_NO_RESOURCE_TYPE,
3843bbec428eSgjelinek B_TRUE);
3844bbec428eSgjelinek global_scope = B_TRUE;
38450209230bSgjelinek }
38460209230bSgjelinek if (res == Z_OK)
38470209230bSgjelinek bcopy(&old_mcaptab, &in_progress_mcaptab,
38480209230bSgjelinek sizeof (struct zone_mcaptab));
38490209230bSgjelinek else
38500209230bSgjelinek bzero(&in_progress_mcaptab,
38510209230bSgjelinek sizeof (in_progress_mcaptab));
38520209230bSgjelinek return;
3853cb8a054bSGlenn Faden case RT_ADMIN:
3854cb8a054bSGlenn Faden if ((err = fill_in_admintab(cmd, &old_admintab, B_FALSE))
3855cb8a054bSGlenn Faden != Z_OK) {
3856cb8a054bSGlenn Faden z_cmd_rt_perror(CMD_SELECT, RT_ADMIN, err,
3857cb8a054bSGlenn Faden B_TRUE);
3858cb8a054bSGlenn Faden global_scope = B_TRUE;
3859cb8a054bSGlenn Faden }
3860cb8a054bSGlenn Faden bcopy(&old_admintab, &in_progress_admintab,
3861cb8a054bSGlenn Faden sizeof (struct zone_admintab));
3862cb8a054bSGlenn Faden return;
38637c478bd9Sstevel@tonic-gate default:
3864bbec428eSgjelinek zone_perror(rt_to_str(type), Z_NO_RESOURCE_TYPE, B_TRUE);
3865bbec428eSgjelinek long_usage(CMD_SELECT, B_TRUE);
3866bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES);
38677c478bd9Sstevel@tonic-gate return;
38687c478bd9Sstevel@tonic-gate }
38697c478bd9Sstevel@tonic-gate }
38707c478bd9Sstevel@tonic-gate
38717c478bd9Sstevel@tonic-gate /*
38727c478bd9Sstevel@tonic-gate * Network "addresses" can be one of the following forms:
38737c478bd9Sstevel@tonic-gate * <IPv4 address>
38747c478bd9Sstevel@tonic-gate * <IPv4 address>/<prefix length>
38757c478bd9Sstevel@tonic-gate * <IPv6 address>/<prefix length>
38767c478bd9Sstevel@tonic-gate * <host name>
38777c478bd9Sstevel@tonic-gate * <host name>/<prefix length>
38787c478bd9Sstevel@tonic-gate * In other words, the "/" followed by a prefix length is allowed but not
38797c478bd9Sstevel@tonic-gate * required for IPv4 addresses and host names, and required for IPv6 addresses.
38807c478bd9Sstevel@tonic-gate * If a prefix length is given, it must be in the allowable range: 0 to 32 for
38817c478bd9Sstevel@tonic-gate * IPv4 addresses and host names, 0 to 128 for IPv6 addresses.
38827c478bd9Sstevel@tonic-gate * Host names must start with an alpha-numeric character, and all subsequent
38837c478bd9Sstevel@tonic-gate * characters must be either alpha-numeric or "-".
3884550b6e40SSowmini Varadhan *
3885550b6e40SSowmini Varadhan * In some cases, e.g., the nexthop for the defrouter, the context indicates
3886550b6e40SSowmini Varadhan * that this is the IPV4_ABITS or IPV6_ABITS netmask, in which case we don't
3887550b6e40SSowmini Varadhan * require the /<prefix length> (and should ignore it if provided).
38887c478bd9Sstevel@tonic-gate */
38897c478bd9Sstevel@tonic-gate
38907c478bd9Sstevel@tonic-gate static int
validate_net_address_syntax(char * address,boolean_t ishost)3891550b6e40SSowmini Varadhan validate_net_address_syntax(char *address, boolean_t ishost)
38927c478bd9Sstevel@tonic-gate {
38937c478bd9Sstevel@tonic-gate char *slashp, part1[MAXHOSTNAMELEN];
38947c478bd9Sstevel@tonic-gate struct in6_addr in6;
38957c478bd9Sstevel@tonic-gate struct in_addr in4;
38967c478bd9Sstevel@tonic-gate int prefixlen, i;
38977c478bd9Sstevel@tonic-gate
38987c478bd9Sstevel@tonic-gate /*
38997c478bd9Sstevel@tonic-gate * Copy the part before any '/' into part1 or copy the whole
39007c478bd9Sstevel@tonic-gate * thing if there is no '/'.
39017c478bd9Sstevel@tonic-gate */
39027c478bd9Sstevel@tonic-gate if ((slashp = strchr(address, '/')) != NULL) {
39037c478bd9Sstevel@tonic-gate *slashp = '\0';
39047c478bd9Sstevel@tonic-gate (void) strlcpy(part1, address, sizeof (part1));
39057c478bd9Sstevel@tonic-gate *slashp = '/';
39067c478bd9Sstevel@tonic-gate prefixlen = atoi(++slashp);
39077c478bd9Sstevel@tonic-gate } else {
39087c478bd9Sstevel@tonic-gate (void) strlcpy(part1, address, sizeof (part1));
39097c478bd9Sstevel@tonic-gate }
39107c478bd9Sstevel@tonic-gate
3911550b6e40SSowmini Varadhan if (ishost && slashp != NULL) {
3912550b6e40SSowmini Varadhan zerr(gettext("Warning: prefix length in %s is not required and "
3913550b6e40SSowmini Varadhan "will be ignored. The default host-prefix length "
3914550b6e40SSowmini Varadhan "will be used"), address);
3915550b6e40SSowmini Varadhan }
3916550b6e40SSowmini Varadhan
3917550b6e40SSowmini Varadhan
39187c478bd9Sstevel@tonic-gate if (inet_pton(AF_INET6, part1, &in6) == 1) {
3919550b6e40SSowmini Varadhan if (ishost) {
3920550b6e40SSowmini Varadhan prefixlen = IPV6_ABITS;
3921550b6e40SSowmini Varadhan } else if (slashp == NULL) {
39227c478bd9Sstevel@tonic-gate zerr(gettext("%s: IPv6 addresses "
39237c478bd9Sstevel@tonic-gate "require /prefix-length suffix."), address);
39247c478bd9Sstevel@tonic-gate return (Z_ERR);
39257c478bd9Sstevel@tonic-gate }
39267c478bd9Sstevel@tonic-gate if (prefixlen < 0 || prefixlen > 128) {
39277c478bd9Sstevel@tonic-gate zerr(gettext("%s: IPv6 address "
39287c478bd9Sstevel@tonic-gate "prefix lengths must be 0 - 128."), address);
39297c478bd9Sstevel@tonic-gate return (Z_ERR);
39307c478bd9Sstevel@tonic-gate }
39317c478bd9Sstevel@tonic-gate return (Z_OK);
39327c478bd9Sstevel@tonic-gate }
39337c478bd9Sstevel@tonic-gate
39347c478bd9Sstevel@tonic-gate /* At this point, any /prefix must be for IPv4. */
3935550b6e40SSowmini Varadhan if (ishost)
3936550b6e40SSowmini Varadhan prefixlen = IPV4_ABITS;
3937550b6e40SSowmini Varadhan else if (slashp != NULL) {
39387c478bd9Sstevel@tonic-gate if (prefixlen < 0 || prefixlen > 32) {
39397c478bd9Sstevel@tonic-gate zerr(gettext("%s: IPv4 address "
39407c478bd9Sstevel@tonic-gate "prefix lengths must be 0 - 32."), address);
39417c478bd9Sstevel@tonic-gate return (Z_ERR);
39427c478bd9Sstevel@tonic-gate }
39437c478bd9Sstevel@tonic-gate }
3944550b6e40SSowmini Varadhan
39457c478bd9Sstevel@tonic-gate if (inet_pton(AF_INET, part1, &in4) == 1)
39467c478bd9Sstevel@tonic-gate return (Z_OK);
39477c478bd9Sstevel@tonic-gate
39487c478bd9Sstevel@tonic-gate /* address may also be a host name */
39497c478bd9Sstevel@tonic-gate if (!isalnum(part1[0])) {
39507c478bd9Sstevel@tonic-gate zerr(gettext("%s: bogus host name or network address syntax"),
39517c478bd9Sstevel@tonic-gate part1);
3952bbec428eSgjelinek saw_error = B_TRUE;
3953bbec428eSgjelinek usage(B_FALSE, HELP_NETADDR);
39547c478bd9Sstevel@tonic-gate return (Z_ERR);
39557c478bd9Sstevel@tonic-gate }
39567c478bd9Sstevel@tonic-gate for (i = 1; part1[i]; i++)
39577c478bd9Sstevel@tonic-gate if (!isalnum(part1[i]) && part1[i] != '-' && part1[i] != '.') {
39587c478bd9Sstevel@tonic-gate zerr(gettext("%s: bogus host name or "
39597c478bd9Sstevel@tonic-gate "network address syntax"), part1);
3960bbec428eSgjelinek saw_error = B_TRUE;
3961bbec428eSgjelinek usage(B_FALSE, HELP_NETADDR);
39627c478bd9Sstevel@tonic-gate return (Z_ERR);
39637c478bd9Sstevel@tonic-gate }
39647c478bd9Sstevel@tonic-gate return (Z_OK);
39657c478bd9Sstevel@tonic-gate }
39667c478bd9Sstevel@tonic-gate
39677c478bd9Sstevel@tonic-gate static int
validate_net_physical_syntax(const char * ifname)3968c9f134eaSjv227347 validate_net_physical_syntax(const char *ifname)
39697c478bd9Sstevel@tonic-gate {
3970c9f134eaSjv227347 ifspec_t ifnameprop;
3971c9f134eaSjv227347 zone_iptype_t iptype;
3972c9f134eaSjv227347
397337b210dcSjv227347 if (zonecfg_get_iptype(handle, &iptype) != Z_OK) {
3974c9f134eaSjv227347 zerr(gettext("zone configuration has an invalid or nonexistent "
3975c9f134eaSjv227347 "ip-type property"));
39767c478bd9Sstevel@tonic-gate return (Z_ERR);
39777c478bd9Sstevel@tonic-gate }
3978c9f134eaSjv227347 switch (iptype) {
3979c9f134eaSjv227347 case ZS_SHARED:
3980c9f134eaSjv227347 if (ifparse_ifspec(ifname, &ifnameprop) == B_FALSE) {
3981c9f134eaSjv227347 zerr(gettext("%s: invalid physical interface name"),
3982c9f134eaSjv227347 ifname);
3983c9f134eaSjv227347 return (Z_ERR);
3984c9f134eaSjv227347 }
3985c9f134eaSjv227347 if (ifnameprop.ifsp_lunvalid) {
3986c9f134eaSjv227347 zerr(gettext("%s: LUNs not allowed in physical "
3987c9f134eaSjv227347 "interface names"), ifname);
3988c9f134eaSjv227347 return (Z_ERR);
3989c9f134eaSjv227347 }
3990c9f134eaSjv227347 break;
3991c9f134eaSjv227347 case ZS_EXCLUSIVE:
3992c9f134eaSjv227347 if (dladm_valid_linkname(ifname) == B_FALSE) {
3993c9f134eaSjv227347 if (strchr(ifname, ':') != NULL)
3994c9f134eaSjv227347 zerr(gettext("%s: physical interface name "
3995c9f134eaSjv227347 "required; logical interface name not "
3996c9f134eaSjv227347 "allowed"), ifname);
3997c9f134eaSjv227347 else
3998c9f134eaSjv227347 zerr(gettext("%s: invalid physical interface "
3999c9f134eaSjv227347 "name"), ifname);
4000c9f134eaSjv227347 return (Z_ERR);
4001c9f134eaSjv227347 }
4002c9f134eaSjv227347 break;
4003c9f134eaSjv227347 }
4004c9f134eaSjv227347 return (Z_OK);
4005c9f134eaSjv227347 }
40067c478bd9Sstevel@tonic-gate
40077c478bd9Sstevel@tonic-gate static boolean_t
valid_fs_type(const char * type)40087c478bd9Sstevel@tonic-gate valid_fs_type(const char *type)
40097c478bd9Sstevel@tonic-gate {
40107c478bd9Sstevel@tonic-gate /*
40117c478bd9Sstevel@tonic-gate * Is this a valid path component?
40127c478bd9Sstevel@tonic-gate */
40137c478bd9Sstevel@tonic-gate if (strlen(type) + 1 > MAXNAMELEN)
40147c478bd9Sstevel@tonic-gate return (B_FALSE);
40157c478bd9Sstevel@tonic-gate /*
40167c478bd9Sstevel@tonic-gate * Make sure a bad value for "type" doesn't make
40177c478bd9Sstevel@tonic-gate * /usr/lib/fs/<type>/mount turn into something else.
40187c478bd9Sstevel@tonic-gate */
40197c478bd9Sstevel@tonic-gate if (strchr(type, '/') != NULL || type[0] == '\0' ||
40207c478bd9Sstevel@tonic-gate strcmp(type, ".") == 0 || strcmp(type, "..") == 0)
40217c478bd9Sstevel@tonic-gate return (B_FALSE);
40227c478bd9Sstevel@tonic-gate /*
40237c478bd9Sstevel@tonic-gate * More detailed verification happens later by zoneadm(1m).
40247c478bd9Sstevel@tonic-gate */
40257c478bd9Sstevel@tonic-gate return (B_TRUE);
40267c478bd9Sstevel@tonic-gate }
40277c478bd9Sstevel@tonic-gate
4028f4b3ec61Sdh155122 static boolean_t
allow_exclusive()4029f4b3ec61Sdh155122 allow_exclusive()
4030f4b3ec61Sdh155122 {
4031f4b3ec61Sdh155122 brand_handle_t bh;
4032f4b3ec61Sdh155122 char brand[MAXNAMELEN];
4033f4b3ec61Sdh155122 boolean_t ret;
4034f4b3ec61Sdh155122
4035f4b3ec61Sdh155122 if (zonecfg_get_brand(handle, brand, sizeof (brand)) != Z_OK) {
4036f4b3ec61Sdh155122 zerr("%s: %s\n", zone, gettext("could not get zone brand"));
4037f4b3ec61Sdh155122 return (B_FALSE);
4038f4b3ec61Sdh155122 }
4039f4b3ec61Sdh155122 if ((bh = brand_open(brand)) == NULL) {
4040f4b3ec61Sdh155122 zerr("%s: %s\n", zone, gettext("unknown brand."));
4041f4b3ec61Sdh155122 return (B_FALSE);
4042f4b3ec61Sdh155122 }
4043f4b3ec61Sdh155122 ret = brand_allow_exclusive_ip(bh);
4044f4b3ec61Sdh155122 brand_close(bh);
4045f4b3ec61Sdh155122 if (!ret)
4046f4b3ec61Sdh155122 zerr(gettext("%s cannot be '%s' when %s is '%s'."),
4047f4b3ec61Sdh155122 pt_to_str(PT_IPTYPE), "exclusive",
4048f4b3ec61Sdh155122 pt_to_str(PT_BRAND), brand);
4049f4b3ec61Sdh155122 return (ret);
4050f4b3ec61Sdh155122 }
4051f4b3ec61Sdh155122
40520209230bSgjelinek static void
set_aliased_rctl(char * alias,int prop_type,char * s)40530209230bSgjelinek set_aliased_rctl(char *alias, int prop_type, char *s)
40540209230bSgjelinek {
40550209230bSgjelinek uint64_t limit;
40560209230bSgjelinek int err;
40570209230bSgjelinek char tmp[128];
40580209230bSgjelinek
40590209230bSgjelinek if (global_zone && strcmp(alias, ALIAS_SHARES) != 0)
40600209230bSgjelinek zerr(gettext("WARNING: Setting a global zone resource "
40610209230bSgjelinek "control too low could deny\nservice "
40620209230bSgjelinek "to even the root user; "
40630209230bSgjelinek "this could render the system impossible\n"
40640209230bSgjelinek "to administer. Please use caution."));
40650209230bSgjelinek
40660209230bSgjelinek /* convert memory based properties */
40670209230bSgjelinek if (prop_type == PT_MAXSHMMEM) {
40680209230bSgjelinek if (!zonecfg_valid_memlimit(s, &limit)) {
40690209230bSgjelinek zerr(gettext("A non-negative number with a required "
40700209230bSgjelinek "scale suffix (K, M, G or T) was expected\nhere."));
4071bbec428eSgjelinek saw_error = B_TRUE;
40720209230bSgjelinek return;
40730209230bSgjelinek }
40740209230bSgjelinek
40750209230bSgjelinek (void) snprintf(tmp, sizeof (tmp), "%llu", limit);
40760209230bSgjelinek s = tmp;
40770209230bSgjelinek }
40780209230bSgjelinek
40790209230bSgjelinek if (!zonecfg_aliased_rctl_ok(handle, alias)) {
4080bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_ALIAS_DISALLOW, B_FALSE);
4081bbec428eSgjelinek saw_error = B_TRUE;
40820209230bSgjelinek } else if (!zonecfg_valid_alias_limit(alias, s, &limit)) {
40830209230bSgjelinek zerr(gettext("%s property is out of range."),
40840209230bSgjelinek pt_to_str(prop_type));
4085bbec428eSgjelinek saw_error = B_TRUE;
40860209230bSgjelinek } else if ((err = zonecfg_set_aliased_rctl(handle, alias, limit))
40870209230bSgjelinek != Z_OK) {
4088bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
4089bbec428eSgjelinek saw_error = B_TRUE;
40900209230bSgjelinek } else {
4091bbec428eSgjelinek need_to_commit = B_TRUE;
40920209230bSgjelinek }
40930209230bSgjelinek }
40940209230bSgjelinek
4095550b6e40SSowmini Varadhan static void
set_in_progress_nwiftab_address(char * prop_id,int prop_type)4096550b6e40SSowmini Varadhan set_in_progress_nwiftab_address(char *prop_id, int prop_type)
4097550b6e40SSowmini Varadhan {
4098550b6e40SSowmini Varadhan if (prop_type == PT_ADDRESS) {
4099550b6e40SSowmini Varadhan (void) strlcpy(in_progress_nwiftab.zone_nwif_address, prop_id,
4100550b6e40SSowmini Varadhan sizeof (in_progress_nwiftab.zone_nwif_address));
4101550b6e40SSowmini Varadhan } else {
4102550b6e40SSowmini Varadhan assert(prop_type == PT_ALLOWED_ADDRESS);
4103550b6e40SSowmini Varadhan (void) strlcpy(in_progress_nwiftab.zone_nwif_allowed_address,
4104550b6e40SSowmini Varadhan prop_id,
4105550b6e40SSowmini Varadhan sizeof (in_progress_nwiftab.zone_nwif_allowed_address));
4106550b6e40SSowmini Varadhan }
4107550b6e40SSowmini Varadhan }
4108550b6e40SSowmini Varadhan
41097c478bd9Sstevel@tonic-gate void
set_func(cmd_t * cmd)41107c478bd9Sstevel@tonic-gate set_func(cmd_t *cmd)
41117c478bd9Sstevel@tonic-gate {
41127c478bd9Sstevel@tonic-gate char *prop_id;
4113555afedfScarlsonj int arg, err, res_type, prop_type;
41147c478bd9Sstevel@tonic-gate property_value_ptr_t pp;
41157c478bd9Sstevel@tonic-gate boolean_t autoboot;
4116f4b3ec61Sdh155122 zone_iptype_t iptype;
4117bbec428eSgjelinek boolean_t force_set = B_FALSE;
41180209230bSgjelinek size_t physmem_size = sizeof (in_progress_mcaptab.zone_physmem_cap);
41190209230bSgjelinek uint64_t mem_cap, mem_limit;
4120c97ad5cdSakolb float cap;
4121c97ad5cdSakolb char *unitp;
41220209230bSgjelinek struct zone_psettab tmp_psettab;
4123bbec428eSgjelinek boolean_t arg_err = B_FALSE;
41247c478bd9Sstevel@tonic-gate
41257c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_SET))
41267c478bd9Sstevel@tonic-gate return;
41277c478bd9Sstevel@tonic-gate
41287c478bd9Sstevel@tonic-gate assert(cmd != NULL);
41297c478bd9Sstevel@tonic-gate
4130555afedfScarlsonj optind = opterr = 0;
4131555afedfScarlsonj while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "F")) != EOF) {
4132555afedfScarlsonj switch (arg) {
4133555afedfScarlsonj case 'F':
4134bbec428eSgjelinek force_set = B_TRUE;
4135555afedfScarlsonj break;
4136555afedfScarlsonj default:
4137555afedfScarlsonj if (optopt == '?')
4138555afedfScarlsonj longer_usage(CMD_SET);
4139555afedfScarlsonj else
4140555afedfScarlsonj short_usage(CMD_SET);
4141bbec428eSgjelinek arg_err = B_TRUE;
41427ec75eb8Sgjelinek break;
41437ec75eb8Sgjelinek }
41447ec75eb8Sgjelinek }
41457ec75eb8Sgjelinek if (arg_err)
4146555afedfScarlsonj return;
4147555afedfScarlsonj
41487c478bd9Sstevel@tonic-gate prop_type = cmd->cmd_prop_name[0];
41497c478bd9Sstevel@tonic-gate if (global_scope) {
41500209230bSgjelinek if (gz_invalid_property(prop_type)) {
41510209230bSgjelinek zerr(gettext("%s is not a valid property for the "
41520209230bSgjelinek "global zone."), pt_to_str(prop_type));
4153bbec428eSgjelinek saw_error = B_TRUE;
41540209230bSgjelinek return;
41550209230bSgjelinek }
41560209230bSgjelinek
4157087719fdSdp if (prop_type == PT_ZONENAME) {
4158087719fdSdp res_type = RT_ZONENAME;
4159087719fdSdp } else if (prop_type == PT_ZONEPATH) {
41607c478bd9Sstevel@tonic-gate res_type = RT_ZONEPATH;
41617c478bd9Sstevel@tonic-gate } else if (prop_type == PT_AUTOBOOT) {
41627c478bd9Sstevel@tonic-gate res_type = RT_AUTOBOOT;
41639acbbeafSnn35248 } else if (prop_type == PT_BRAND) {
41649acbbeafSnn35248 res_type = RT_BRAND;
41657c478bd9Sstevel@tonic-gate } else if (prop_type == PT_POOL) {
41667c478bd9Sstevel@tonic-gate res_type = RT_POOL;
4167ffbafc53Scomay } else if (prop_type == PT_LIMITPRIV) {
4168ffbafc53Scomay res_type = RT_LIMITPRIV;
41693f2f09c1Sdp } else if (prop_type == PT_BOOTARGS) {
41703f2f09c1Sdp res_type = RT_BOOTARGS;
41710209230bSgjelinek } else if (prop_type == PT_SCHED) {
41720209230bSgjelinek res_type = RT_SCHED;
4173f4b3ec61Sdh155122 } else if (prop_type == PT_IPTYPE) {
4174f4b3ec61Sdh155122 res_type = RT_IPTYPE;
41750209230bSgjelinek } else if (prop_type == PT_MAXLWPS) {
41760209230bSgjelinek res_type = RT_MAXLWPS;
4177ff19e029SMenno Lageman } else if (prop_type == PT_MAXPROCS) {
4178ff19e029SMenno Lageman res_type = RT_MAXPROCS;
41790209230bSgjelinek } else if (prop_type == PT_MAXSHMMEM) {
41800209230bSgjelinek res_type = RT_MAXSHMMEM;
41810209230bSgjelinek } else if (prop_type == PT_MAXSHMIDS) {
41820209230bSgjelinek res_type = RT_MAXSHMIDS;
41830209230bSgjelinek } else if (prop_type == PT_MAXMSGIDS) {
41840209230bSgjelinek res_type = RT_MAXMSGIDS;
41850209230bSgjelinek } else if (prop_type == PT_MAXSEMIDS) {
41860209230bSgjelinek res_type = RT_MAXSEMIDS;
41870209230bSgjelinek } else if (prop_type == PT_SHARES) {
41880209230bSgjelinek res_type = RT_SHARES;
41895679c89fSjv227347 } else if (prop_type == PT_HOSTID) {
41905679c89fSjv227347 res_type = RT_HOSTID;
41910fbb751dSJohn Levon } else if (prop_type == PT_FS_ALLOWED) {
41920fbb751dSJohn Levon res_type = RT_FS_ALLOWED;
41937c478bd9Sstevel@tonic-gate } else {
41947c478bd9Sstevel@tonic-gate zerr(gettext("Cannot set a resource-specific property "
41957c478bd9Sstevel@tonic-gate "from the global scope."));
4196bbec428eSgjelinek saw_error = B_TRUE;
41977c478bd9Sstevel@tonic-gate return;
41987c478bd9Sstevel@tonic-gate }
41997c478bd9Sstevel@tonic-gate } else {
42007c478bd9Sstevel@tonic-gate res_type = resource_scope;
42017c478bd9Sstevel@tonic-gate }
42027c478bd9Sstevel@tonic-gate
4203555afedfScarlsonj if (force_set) {
4204555afedfScarlsonj if (res_type != RT_ZONEPATH) {
4205555afedfScarlsonj zerr(gettext("Only zonepath setting can be forced."));
4206bbec428eSgjelinek saw_error = B_TRUE;
4207555afedfScarlsonj return;
4208555afedfScarlsonj }
4209555afedfScarlsonj if (!zonecfg_in_alt_root()) {
4210555afedfScarlsonj zerr(gettext("Zonepath is changeable only in an "
4211555afedfScarlsonj "alternate root."));
4212bbec428eSgjelinek saw_error = B_TRUE;
4213555afedfScarlsonj return;
4214555afedfScarlsonj }
4215555afedfScarlsonj }
4216555afedfScarlsonj
42177c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0];
42187c478bd9Sstevel@tonic-gate /*
42197c478bd9Sstevel@tonic-gate * A nasty expression but not that complicated:
42207c478bd9Sstevel@tonic-gate * 1. fs options are simple or list (tested below)
42217c478bd9Sstevel@tonic-gate * 2. rctl value's are complex or list (tested below)
42227c478bd9Sstevel@tonic-gate * Anything else should be simple.
42237c478bd9Sstevel@tonic-gate */
42247c478bd9Sstevel@tonic-gate if (!(res_type == RT_FS && prop_type == PT_OPTIONS) &&
42257c478bd9Sstevel@tonic-gate !(res_type == RT_RCTL && prop_type == PT_VALUE) &&
42267c478bd9Sstevel@tonic-gate (pp->pv_type != PROP_VAL_SIMPLE ||
42277c478bd9Sstevel@tonic-gate (prop_id = pp->pv_simple) == NULL)) {
42287c478bd9Sstevel@tonic-gate zerr(gettext("A %s value was expected here."),
42297c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_SIMPLE));
4230bbec428eSgjelinek saw_error = B_TRUE;
42317c478bd9Sstevel@tonic-gate return;
42327c478bd9Sstevel@tonic-gate }
42337c478bd9Sstevel@tonic-gate if (prop_type == PT_UNKNOWN) {
4234bbec428eSgjelinek long_usage(CMD_SET, B_TRUE);
42357c478bd9Sstevel@tonic-gate return;
42367c478bd9Sstevel@tonic-gate }
42377c478bd9Sstevel@tonic-gate
4238087719fdSdp /*
4239087719fdSdp * Special case: the user can change the zone name prior to 'create';
4240087719fdSdp * if the zone already exists, we fall through letting initialize()
4241087719fdSdp * and the rest of the logic run.
4242087719fdSdp */
4243bbec428eSgjelinek if (res_type == RT_ZONENAME && got_handle == B_FALSE &&
4244087719fdSdp !state_atleast(ZONE_STATE_CONFIGURED)) {
4245fb03efaaSdp if ((err = zonecfg_validate_zonename(prop_id)) != Z_OK) {
4246bbec428eSgjelinek zone_perror(prop_id, err, B_TRUE);
4247bbec428eSgjelinek usage(B_FALSE, HELP_SYNTAX);
4248fb03efaaSdp return;
4249fb03efaaSdp }
4250087719fdSdp (void) strlcpy(zone, prop_id, sizeof (zone));
4251087719fdSdp return;
4252087719fdSdp }
4253087719fdSdp
4254bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK)
42557c478bd9Sstevel@tonic-gate return;
42567c478bd9Sstevel@tonic-gate
42577c478bd9Sstevel@tonic-gate switch (res_type) {
4258087719fdSdp case RT_ZONENAME:
4259087719fdSdp if ((err = zonecfg_set_name(handle, prop_id)) != Z_OK) {
4260087719fdSdp /*
4261087719fdSdp * Use prop_id instead of 'zone' here, since we're
4262087719fdSdp * reporting a problem about the *new* zonename.
4263087719fdSdp */
4264bbec428eSgjelinek zone_perror(prop_id, err, B_TRUE);
4265bbec428eSgjelinek usage(B_FALSE, HELP_SYNTAX);
4266087719fdSdp } else {
4267bbec428eSgjelinek need_to_commit = B_TRUE;
4268087719fdSdp (void) strlcpy(zone, prop_id, sizeof (zone));
4269087719fdSdp }
4270087719fdSdp return;
42717c478bd9Sstevel@tonic-gate case RT_ZONEPATH:
4272555afedfScarlsonj if (!force_set && state_atleast(ZONE_STATE_INSTALLED)) {
42737c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s already installed; %s %s not "
42747c478bd9Sstevel@tonic-gate "allowed."), zone, cmd_to_str(CMD_SET),
42757c478bd9Sstevel@tonic-gate rt_to_str(RT_ZONEPATH));
42767c478bd9Sstevel@tonic-gate return;
42777c478bd9Sstevel@tonic-gate }
42787c478bd9Sstevel@tonic-gate if (validate_zonepath_syntax(prop_id) != Z_OK) {
4279bbec428eSgjelinek saw_error = B_TRUE;
42807c478bd9Sstevel@tonic-gate return;
42817c478bd9Sstevel@tonic-gate }
42827c478bd9Sstevel@tonic-gate if ((err = zonecfg_set_zonepath(handle, prop_id)) != Z_OK)
4283bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
42847c478bd9Sstevel@tonic-gate else
4285bbec428eSgjelinek need_to_commit = B_TRUE;
42867c478bd9Sstevel@tonic-gate return;
42879acbbeafSnn35248 case RT_BRAND:
42889acbbeafSnn35248 if (state_atleast(ZONE_STATE_INSTALLED)) {
42899acbbeafSnn35248 zerr(gettext("Zone %s already installed; %s %s not "
42909acbbeafSnn35248 "allowed."), zone, cmd_to_str(CMD_SET),
42919acbbeafSnn35248 rt_to_str(RT_BRAND));
42929acbbeafSnn35248 return;
42939acbbeafSnn35248 }
42949acbbeafSnn35248 if ((err = zonecfg_set_brand(handle, prop_id)) != Z_OK)
4295bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
42969acbbeafSnn35248 else
4297bbec428eSgjelinek need_to_commit = B_TRUE;
42989acbbeafSnn35248 return;
42997c478bd9Sstevel@tonic-gate case RT_AUTOBOOT:
43007c478bd9Sstevel@tonic-gate if (strcmp(prop_id, "true") == 0) {
43017c478bd9Sstevel@tonic-gate autoboot = B_TRUE;
43027c478bd9Sstevel@tonic-gate } else if (strcmp(prop_id, "false") == 0) {
43037c478bd9Sstevel@tonic-gate autoboot = B_FALSE;
43047c478bd9Sstevel@tonic-gate } else {
43057c478bd9Sstevel@tonic-gate zerr(gettext("%s value must be '%s' or '%s'."),
43067c478bd9Sstevel@tonic-gate pt_to_str(PT_AUTOBOOT), "true", "false");
4307bbec428eSgjelinek saw_error = B_TRUE;
43087c478bd9Sstevel@tonic-gate return;
43097c478bd9Sstevel@tonic-gate }
43107c478bd9Sstevel@tonic-gate if ((err = zonecfg_set_autoboot(handle, autoboot)) != Z_OK)
4311bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
43127c478bd9Sstevel@tonic-gate else
4313bbec428eSgjelinek need_to_commit = B_TRUE;
43147c478bd9Sstevel@tonic-gate return;
43157c478bd9Sstevel@tonic-gate case RT_POOL:
43160209230bSgjelinek /* don't allow use of the reserved temporary pool names */
43170209230bSgjelinek if (strncmp("SUNW", prop_id, 4) == 0) {
43180209230bSgjelinek zerr(gettext("pool names starting with SUNW are "
43190209230bSgjelinek "reserved."));
4320bbec428eSgjelinek saw_error = B_TRUE;
43210209230bSgjelinek return;
43220209230bSgjelinek }
43230209230bSgjelinek
43240209230bSgjelinek /* can't set pool if dedicated-cpu exists */
43250209230bSgjelinek if (zonecfg_lookup_pset(handle, &tmp_psettab) == Z_OK) {
43260209230bSgjelinek zerr(gettext("The %s resource already exists. "
43270209230bSgjelinek "A persistent pool is incompatible\nwith the %s "
43280209230bSgjelinek "resource."), rt_to_str(RT_DCPU),
43290209230bSgjelinek rt_to_str(RT_DCPU));
4330bbec428eSgjelinek saw_error = B_TRUE;
43310209230bSgjelinek return;
43320209230bSgjelinek }
43330209230bSgjelinek
43347c478bd9Sstevel@tonic-gate if ((err = zonecfg_set_pool(handle, prop_id)) != Z_OK)
4335bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
43367c478bd9Sstevel@tonic-gate else
4337bbec428eSgjelinek need_to_commit = B_TRUE;
43387c478bd9Sstevel@tonic-gate return;
4339ffbafc53Scomay case RT_LIMITPRIV:
4340ffbafc53Scomay if ((err = zonecfg_set_limitpriv(handle, prop_id)) != Z_OK)
4341bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
4342ffbafc53Scomay else
4343bbec428eSgjelinek need_to_commit = B_TRUE;
4344ffbafc53Scomay return;
43453f2f09c1Sdp case RT_BOOTARGS:
43463f2f09c1Sdp if ((err = zonecfg_set_bootargs(handle, prop_id)) != Z_OK)
4347bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
43483f2f09c1Sdp else
4349bbec428eSgjelinek need_to_commit = B_TRUE;
43503f2f09c1Sdp return;
43510209230bSgjelinek case RT_SCHED:
43520209230bSgjelinek if ((err = zonecfg_set_sched(handle, prop_id)) != Z_OK)
4353bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
43540209230bSgjelinek else
4355bbec428eSgjelinek need_to_commit = B_TRUE;
43560209230bSgjelinek return;
4357f4b3ec61Sdh155122 case RT_IPTYPE:
4358f4b3ec61Sdh155122 if (strcmp(prop_id, "shared") == 0) {
4359f4b3ec61Sdh155122 iptype = ZS_SHARED;
4360f4b3ec61Sdh155122 } else if (strcmp(prop_id, "exclusive") == 0) {
4361f4b3ec61Sdh155122 iptype = ZS_EXCLUSIVE;
4362f4b3ec61Sdh155122 } else {
4363f4b3ec61Sdh155122 zerr(gettext("%s value must be '%s' or '%s'."),
4364f4b3ec61Sdh155122 pt_to_str(PT_IPTYPE), "shared", "exclusive");
4365bbec428eSgjelinek saw_error = B_TRUE;
4366f4b3ec61Sdh155122 return;
4367f4b3ec61Sdh155122 }
4368f4b3ec61Sdh155122 if (iptype == ZS_EXCLUSIVE && !allow_exclusive()) {
4369bbec428eSgjelinek saw_error = B_TRUE;
4370f4b3ec61Sdh155122 return;
4371f4b3ec61Sdh155122 }
4372f4b3ec61Sdh155122 if ((err = zonecfg_set_iptype(handle, iptype)) != Z_OK)
4373bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
4374f4b3ec61Sdh155122 else
4375bbec428eSgjelinek need_to_commit = B_TRUE;
4376f4b3ec61Sdh155122 return;
43770209230bSgjelinek case RT_MAXLWPS:
43780209230bSgjelinek set_aliased_rctl(ALIAS_MAXLWPS, prop_type, prop_id);
43790209230bSgjelinek return;
4380ff19e029SMenno Lageman case RT_MAXPROCS:
4381ff19e029SMenno Lageman set_aliased_rctl(ALIAS_MAXPROCS, prop_type, prop_id);
4382ff19e029SMenno Lageman return;
43830209230bSgjelinek case RT_MAXSHMMEM:
43840209230bSgjelinek set_aliased_rctl(ALIAS_MAXSHMMEM, prop_type, prop_id);
43850209230bSgjelinek return;
43860209230bSgjelinek case RT_MAXSHMIDS:
43870209230bSgjelinek set_aliased_rctl(ALIAS_MAXSHMIDS, prop_type, prop_id);
43880209230bSgjelinek return;
43890209230bSgjelinek case RT_MAXMSGIDS:
43900209230bSgjelinek set_aliased_rctl(ALIAS_MAXMSGIDS, prop_type, prop_id);
43910209230bSgjelinek return;
43920209230bSgjelinek case RT_MAXSEMIDS:
43930209230bSgjelinek set_aliased_rctl(ALIAS_MAXSEMIDS, prop_type, prop_id);
43940209230bSgjelinek return;
43950209230bSgjelinek case RT_SHARES:
43960209230bSgjelinek set_aliased_rctl(ALIAS_SHARES, prop_type, prop_id);
43970209230bSgjelinek return;
43985679c89fSjv227347 case RT_HOSTID:
43995679c89fSjv227347 if ((err = zonecfg_set_hostid(handle, prop_id)) != Z_OK) {
44005679c89fSjv227347 if (err == Z_TOO_BIG) {
44015679c89fSjv227347 zerr(gettext("hostid string is too large: %s"),
44025679c89fSjv227347 prop_id);
44035679c89fSjv227347 saw_error = B_TRUE;
44045679c89fSjv227347 } else {
44055679c89fSjv227347 zone_perror(pt_to_str(prop_type), err, B_TRUE);
44065679c89fSjv227347 }
44075679c89fSjv227347 return;
44085679c89fSjv227347 }
44095679c89fSjv227347 need_to_commit = B_TRUE;
44105679c89fSjv227347 return;
44110fbb751dSJohn Levon case RT_FS_ALLOWED:
44120fbb751dSJohn Levon if ((err = zonecfg_set_fs_allowed(handle, prop_id)) != Z_OK)
44130fbb751dSJohn Levon zone_perror(zone, err, B_TRUE);
44140fbb751dSJohn Levon else
44150fbb751dSJohn Levon need_to_commit = B_TRUE;
44160fbb751dSJohn Levon return;
44177c478bd9Sstevel@tonic-gate case RT_FS:
44187c478bd9Sstevel@tonic-gate switch (prop_type) {
44197c478bd9Sstevel@tonic-gate case PT_DIR:
44207c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_dir, prop_id,
44217c478bd9Sstevel@tonic-gate sizeof (in_progress_fstab.zone_fs_dir));
44227c478bd9Sstevel@tonic-gate return;
44237c478bd9Sstevel@tonic-gate case PT_SPECIAL:
44247c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_special,
44257c478bd9Sstevel@tonic-gate prop_id,
44267c478bd9Sstevel@tonic-gate sizeof (in_progress_fstab.zone_fs_special));
44277c478bd9Sstevel@tonic-gate return;
44287c478bd9Sstevel@tonic-gate case PT_RAW:
44297c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_raw,
44307c478bd9Sstevel@tonic-gate prop_id, sizeof (in_progress_fstab.zone_fs_raw));
44317c478bd9Sstevel@tonic-gate return;
44327c478bd9Sstevel@tonic-gate case PT_TYPE:
44337c478bd9Sstevel@tonic-gate if (!valid_fs_type(prop_id)) {
44347c478bd9Sstevel@tonic-gate zerr(gettext("\"%s\" is not a valid %s."),
44357c478bd9Sstevel@tonic-gate prop_id, pt_to_str(PT_TYPE));
4436bbec428eSgjelinek saw_error = B_TRUE;
44377c478bd9Sstevel@tonic-gate return;
44387c478bd9Sstevel@tonic-gate }
44397c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_type, prop_id,
44407c478bd9Sstevel@tonic-gate sizeof (in_progress_fstab.zone_fs_type));
44417c478bd9Sstevel@tonic-gate return;
44427c478bd9Sstevel@tonic-gate case PT_OPTIONS:
44437c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE &&
44447c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) {
44457c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected "
44467c478bd9Sstevel@tonic-gate "here."), pvt_to_str(PROP_VAL_SIMPLE),
44477c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST));
4448bbec428eSgjelinek saw_error = B_TRUE;
44497c478bd9Sstevel@tonic-gate return;
44507c478bd9Sstevel@tonic-gate }
44517c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(
44527c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_options);
44537c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_options = NULL;
44547c478bd9Sstevel@tonic-gate if (!(pp->pv_type == PROP_VAL_LIST &&
44557c478bd9Sstevel@tonic-gate pp->pv_list == NULL))
44567c478bd9Sstevel@tonic-gate add_property(cmd);
44577c478bd9Sstevel@tonic-gate return;
44587c478bd9Sstevel@tonic-gate default:
44597c478bd9Sstevel@tonic-gate break;
44607c478bd9Sstevel@tonic-gate }
4461bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, B_TRUE);
4462bbec428eSgjelinek long_usage(CMD_SET, B_TRUE);
4463bbec428eSgjelinek usage(B_FALSE, HELP_PROPS);
44647c478bd9Sstevel@tonic-gate return;
44657c478bd9Sstevel@tonic-gate case RT_NET:
44667c478bd9Sstevel@tonic-gate switch (prop_type) {
44677c478bd9Sstevel@tonic-gate case PT_ADDRESS:
4468550b6e40SSowmini Varadhan case PT_ALLOWED_ADDRESS:
4469550b6e40SSowmini Varadhan if (validate_net_address_syntax(prop_id, B_FALSE)
4470550b6e40SSowmini Varadhan != Z_OK) {
4471bbec428eSgjelinek saw_error = B_TRUE;
44727c478bd9Sstevel@tonic-gate return;
44737c478bd9Sstevel@tonic-gate }
4474550b6e40SSowmini Varadhan set_in_progress_nwiftab_address(prop_id, prop_type);
44757c478bd9Sstevel@tonic-gate break;
44767c478bd9Sstevel@tonic-gate case PT_PHYSICAL:
44777c478bd9Sstevel@tonic-gate if (validate_net_physical_syntax(prop_id) != Z_OK) {
4478bbec428eSgjelinek saw_error = B_TRUE;
44797c478bd9Sstevel@tonic-gate return;
44807c478bd9Sstevel@tonic-gate }
44817c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_nwiftab.zone_nwif_physical,
44827c478bd9Sstevel@tonic-gate prop_id,
44837c478bd9Sstevel@tonic-gate sizeof (in_progress_nwiftab.zone_nwif_physical));
44847c478bd9Sstevel@tonic-gate break;
4485de860bd9Sgfaden case PT_DEFROUTER:
4486550b6e40SSowmini Varadhan if (validate_net_address_syntax(prop_id, B_TRUE)
4487550b6e40SSowmini Varadhan != Z_OK) {
4488bbec428eSgjelinek saw_error = B_TRUE;
4489de860bd9Sgfaden return;
4490de860bd9Sgfaden }
4491de860bd9Sgfaden (void) strlcpy(in_progress_nwiftab.zone_nwif_defrouter,
4492de860bd9Sgfaden prop_id,
4493de860bd9Sgfaden sizeof (in_progress_nwiftab.zone_nwif_defrouter));
4494de860bd9Sgfaden break;
44957c478bd9Sstevel@tonic-gate default:
44967c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
4497bbec428eSgjelinek B_TRUE);
4498bbec428eSgjelinek long_usage(CMD_SET, B_TRUE);
4499bbec428eSgjelinek usage(B_FALSE, HELP_PROPS);
45007c478bd9Sstevel@tonic-gate return;
45017c478bd9Sstevel@tonic-gate }
45027c478bd9Sstevel@tonic-gate return;
45037c478bd9Sstevel@tonic-gate case RT_DEVICE:
45047c478bd9Sstevel@tonic-gate switch (prop_type) {
45057c478bd9Sstevel@tonic-gate case PT_MATCH:
45067c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_devtab.zone_dev_match,
45077c478bd9Sstevel@tonic-gate prop_id,
45087c478bd9Sstevel@tonic-gate sizeof (in_progress_devtab.zone_dev_match));
45097c478bd9Sstevel@tonic-gate break;
45107c478bd9Sstevel@tonic-gate default:
45117c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
4512bbec428eSgjelinek B_TRUE);
4513bbec428eSgjelinek long_usage(CMD_SET, B_TRUE);
4514bbec428eSgjelinek usage(B_FALSE, HELP_PROPS);
45157c478bd9Sstevel@tonic-gate return;
45167c478bd9Sstevel@tonic-gate }
45177c478bd9Sstevel@tonic-gate return;
45187c478bd9Sstevel@tonic-gate case RT_RCTL:
45197c478bd9Sstevel@tonic-gate switch (prop_type) {
45207c478bd9Sstevel@tonic-gate case PT_NAME:
45217c478bd9Sstevel@tonic-gate if (!zonecfg_valid_rctlname(prop_id)) {
45227c478bd9Sstevel@tonic-gate zerr(gettext("'%s' is not a valid zone %s "
45237c478bd9Sstevel@tonic-gate "name."), prop_id, rt_to_str(RT_RCTL));
45247c478bd9Sstevel@tonic-gate return;
45257c478bd9Sstevel@tonic-gate }
45267c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_rctltab.zone_rctl_name,
45277c478bd9Sstevel@tonic-gate prop_id,
45287c478bd9Sstevel@tonic-gate sizeof (in_progress_rctltab.zone_rctl_name));
45297c478bd9Sstevel@tonic-gate break;
45307c478bd9Sstevel@tonic-gate case PT_VALUE:
45317c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_COMPLEX &&
45327c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) {
45337c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected "
45347c478bd9Sstevel@tonic-gate "here."), pvt_to_str(PROP_VAL_COMPLEX),
45357c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST));
4536bbec428eSgjelinek saw_error = B_TRUE;
45377c478bd9Sstevel@tonic-gate return;
45387c478bd9Sstevel@tonic-gate }
45397c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(
45407c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr);
45417c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr = NULL;
45427c478bd9Sstevel@tonic-gate if (!(pp->pv_type == PROP_VAL_LIST &&
45437c478bd9Sstevel@tonic-gate pp->pv_list == NULL))
45447c478bd9Sstevel@tonic-gate add_property(cmd);
45457c478bd9Sstevel@tonic-gate break;
45467c478bd9Sstevel@tonic-gate default:
45477c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
4548bbec428eSgjelinek B_TRUE);
4549bbec428eSgjelinek long_usage(CMD_SET, B_TRUE);
4550bbec428eSgjelinek usage(B_FALSE, HELP_PROPS);
45517c478bd9Sstevel@tonic-gate return;
45527c478bd9Sstevel@tonic-gate }
45537c478bd9Sstevel@tonic-gate return;
45547c478bd9Sstevel@tonic-gate case RT_ATTR:
45557c478bd9Sstevel@tonic-gate switch (prop_type) {
45567c478bd9Sstevel@tonic-gate case PT_NAME:
45577c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_attrtab.zone_attr_name,
45587c478bd9Sstevel@tonic-gate prop_id,
45597c478bd9Sstevel@tonic-gate sizeof (in_progress_attrtab.zone_attr_name));
45607c478bd9Sstevel@tonic-gate break;
45617c478bd9Sstevel@tonic-gate case PT_TYPE:
45627c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_attrtab.zone_attr_type,
45637c478bd9Sstevel@tonic-gate prop_id,
45647c478bd9Sstevel@tonic-gate sizeof (in_progress_attrtab.zone_attr_type));
45657c478bd9Sstevel@tonic-gate break;
45667c478bd9Sstevel@tonic-gate case PT_VALUE:
45677c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_attrtab.zone_attr_value,
45687c478bd9Sstevel@tonic-gate prop_id,
45697c478bd9Sstevel@tonic-gate sizeof (in_progress_attrtab.zone_attr_value));
45707c478bd9Sstevel@tonic-gate break;
45717c478bd9Sstevel@tonic-gate default:
45727c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
4573bbec428eSgjelinek B_TRUE);
4574bbec428eSgjelinek long_usage(CMD_SET, B_TRUE);
4575bbec428eSgjelinek usage(B_FALSE, HELP_PROPS);
45767c478bd9Sstevel@tonic-gate return;
45777c478bd9Sstevel@tonic-gate }
45787c478bd9Sstevel@tonic-gate return;
4579fa9e4066Sahrens case RT_DATASET:
4580fa9e4066Sahrens switch (prop_type) {
4581fa9e4066Sahrens case PT_NAME:
4582fa9e4066Sahrens (void) strlcpy(in_progress_dstab.zone_dataset_name,
4583fa9e4066Sahrens prop_id,
4584fa9e4066Sahrens sizeof (in_progress_dstab.zone_dataset_name));
4585fa9e4066Sahrens return;
4586fa9e4066Sahrens default:
4587fa9e4066Sahrens break;
4588fa9e4066Sahrens }
4589bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, B_TRUE);
4590bbec428eSgjelinek long_usage(CMD_SET, B_TRUE);
4591bbec428eSgjelinek usage(B_FALSE, HELP_PROPS);
4592fa9e4066Sahrens return;
45930209230bSgjelinek case RT_DCPU:
45940209230bSgjelinek switch (prop_type) {
45950209230bSgjelinek char *lowp, *highp;
45960209230bSgjelinek
45970209230bSgjelinek case PT_NCPUS:
45980209230bSgjelinek lowp = prop_id;
45990209230bSgjelinek if ((highp = strchr(prop_id, '-')) != NULL)
46000209230bSgjelinek *highp++ = '\0';
46010209230bSgjelinek else
46020209230bSgjelinek highp = lowp;
46030209230bSgjelinek
46040209230bSgjelinek /* Make sure the input makes sense. */
46050209230bSgjelinek if (!zonecfg_valid_ncpus(lowp, highp)) {
46060209230bSgjelinek zerr(gettext("%s property is out of range."),
46070209230bSgjelinek pt_to_str(PT_NCPUS));
4608bbec428eSgjelinek saw_error = B_TRUE;
46090209230bSgjelinek return;
46100209230bSgjelinek }
46110209230bSgjelinek
46120209230bSgjelinek (void) strlcpy(
46130209230bSgjelinek in_progress_psettab.zone_ncpu_min, lowp,
46140209230bSgjelinek sizeof (in_progress_psettab.zone_ncpu_min));
46150209230bSgjelinek (void) strlcpy(
46160209230bSgjelinek in_progress_psettab.zone_ncpu_max, highp,
46170209230bSgjelinek sizeof (in_progress_psettab.zone_ncpu_max));
46180209230bSgjelinek return;
46190209230bSgjelinek case PT_IMPORTANCE:
46200209230bSgjelinek /* Make sure the value makes sense. */
46210209230bSgjelinek if (!zonecfg_valid_importance(prop_id)) {
46220209230bSgjelinek zerr(gettext("%s property is out of range."),
46230209230bSgjelinek pt_to_str(PT_IMPORTANCE));
4624bbec428eSgjelinek saw_error = B_TRUE;
46250209230bSgjelinek return;
46260209230bSgjelinek }
46270209230bSgjelinek
46280209230bSgjelinek (void) strlcpy(in_progress_psettab.zone_importance,
46290209230bSgjelinek prop_id,
46300209230bSgjelinek sizeof (in_progress_psettab.zone_importance));
46310209230bSgjelinek return;
46320209230bSgjelinek default:
46330209230bSgjelinek break;
46340209230bSgjelinek }
4635bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, B_TRUE);
4636bbec428eSgjelinek long_usage(CMD_SET, B_TRUE);
4637bbec428eSgjelinek usage(B_FALSE, HELP_PROPS);
46380209230bSgjelinek return;
4639c97ad5cdSakolb case RT_PCAP:
4640c97ad5cdSakolb if (prop_type != PT_NCPUS) {
4641c97ad5cdSakolb zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
4642bbec428eSgjelinek B_TRUE);
4643bbec428eSgjelinek long_usage(CMD_SET, B_TRUE);
4644bbec428eSgjelinek usage(B_FALSE, HELP_PROPS);
4645c97ad5cdSakolb return;
4646c97ad5cdSakolb }
4647c97ad5cdSakolb
4648c97ad5cdSakolb /*
4649c97ad5cdSakolb * We already checked that an rctl alias is allowed in
4650c97ad5cdSakolb * the add_resource() function.
4651c97ad5cdSakolb */
4652c97ad5cdSakolb
4653c97ad5cdSakolb if ((cap = strtof(prop_id, &unitp)) <= 0 || *unitp != '\0' ||
4654c97ad5cdSakolb (int)(cap * 100) < 1) {
4655c97ad5cdSakolb zerr(gettext("%s property is out of range."),
4656c97ad5cdSakolb pt_to_str(PT_NCPUS));
4657bbec428eSgjelinek saw_error = B_TRUE;
4658c97ad5cdSakolb return;
4659c97ad5cdSakolb }
4660c97ad5cdSakolb
4661c97ad5cdSakolb if ((err = zonecfg_set_aliased_rctl(handle, ALIAS_CPUCAP,
4662c97ad5cdSakolb (int)(cap * 100))) != Z_OK)
4663bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
4664c97ad5cdSakolb else
4665bbec428eSgjelinek need_to_commit = B_TRUE;
4666c97ad5cdSakolb return;
46670209230bSgjelinek case RT_MCAP:
46680209230bSgjelinek switch (prop_type) {
46690209230bSgjelinek case PT_PHYSICAL:
46700209230bSgjelinek if (!zonecfg_valid_memlimit(prop_id, &mem_cap)) {
46710209230bSgjelinek zerr(gettext("A positive number with a "
46720209230bSgjelinek "required scale suffix (K, M, G or T) was "
46730209230bSgjelinek "expected here."));
4674bbec428eSgjelinek saw_error = B_TRUE;
46750209230bSgjelinek } else if (mem_cap < ONE_MB) {
46760209230bSgjelinek zerr(gettext("%s value is too small. It must "
46770209230bSgjelinek "be at least 1M."), pt_to_str(PT_PHYSICAL));
4678bbec428eSgjelinek saw_error = B_TRUE;
46790209230bSgjelinek } else {
46800209230bSgjelinek snprintf(in_progress_mcaptab.zone_physmem_cap,
46810209230bSgjelinek physmem_size, "%llu", mem_cap);
46820209230bSgjelinek }
46830209230bSgjelinek break;
46840209230bSgjelinek case PT_SWAP:
46850209230bSgjelinek /*
46860209230bSgjelinek * We have to check if an rctl is allowed here since
46870209230bSgjelinek * there might already be a rctl defined that blocks
46880209230bSgjelinek * the alias.
46890209230bSgjelinek */
46900209230bSgjelinek if (!zonecfg_aliased_rctl_ok(handle, ALIAS_MAXSWAP)) {
46910209230bSgjelinek zone_perror(pt_to_str(PT_MAXSWAP),
4692bbec428eSgjelinek Z_ALIAS_DISALLOW, B_FALSE);
4693bbec428eSgjelinek saw_error = B_TRUE;
46940209230bSgjelinek return;
46950209230bSgjelinek }
46960209230bSgjelinek
46970209230bSgjelinek if (global_zone)
46980209230bSgjelinek mem_limit = ONE_MB * 100;
46990209230bSgjelinek else
47000209230bSgjelinek mem_limit = ONE_MB * 50;
47010209230bSgjelinek
47020209230bSgjelinek if (!zonecfg_valid_memlimit(prop_id, &mem_cap)) {
47030209230bSgjelinek zerr(gettext("A positive number with a "
47040209230bSgjelinek "required scale suffix (K, M, G or T) was "
47050209230bSgjelinek "expected here."));
4706bbec428eSgjelinek saw_error = B_TRUE;
47070209230bSgjelinek } else if (mem_cap < mem_limit) {
47080209230bSgjelinek char buf[128];
47090209230bSgjelinek
47100209230bSgjelinek (void) snprintf(buf, sizeof (buf), "%llu",
47110209230bSgjelinek mem_limit);
47120209230bSgjelinek bytes_to_units(buf, buf, sizeof (buf));
47130209230bSgjelinek zerr(gettext("%s value is too small. It must "
47140209230bSgjelinek "be at least %s."), pt_to_str(PT_SWAP),
47150209230bSgjelinek buf);
4716bbec428eSgjelinek saw_error = B_TRUE;
47170209230bSgjelinek } else {
47180209230bSgjelinek if ((err = zonecfg_set_aliased_rctl(handle,
47190209230bSgjelinek ALIAS_MAXSWAP, mem_cap)) != Z_OK)
4720bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
47210209230bSgjelinek else
4722bbec428eSgjelinek need_to_commit = B_TRUE;
47230209230bSgjelinek }
47240209230bSgjelinek break;
47250209230bSgjelinek case PT_LOCKED:
47260209230bSgjelinek /*
47270209230bSgjelinek * We have to check if an rctl is allowed here since
47280209230bSgjelinek * there might already be a rctl defined that blocks
47290209230bSgjelinek * the alias.
47300209230bSgjelinek */
47310209230bSgjelinek if (!zonecfg_aliased_rctl_ok(handle,
47320209230bSgjelinek ALIAS_MAXLOCKEDMEM)) {
47330209230bSgjelinek zone_perror(pt_to_str(PT_LOCKED),
4734bbec428eSgjelinek Z_ALIAS_DISALLOW, B_FALSE);
4735bbec428eSgjelinek saw_error = B_TRUE;
47360209230bSgjelinek return;
47370209230bSgjelinek }
47380209230bSgjelinek
47390209230bSgjelinek if (!zonecfg_valid_memlimit(prop_id, &mem_cap)) {
47400209230bSgjelinek zerr(gettext("A non-negative number with a "
47410209230bSgjelinek "required scale suffix (K, M, G or T) was "
47420209230bSgjelinek "expected\nhere."));
4743bbec428eSgjelinek saw_error = B_TRUE;
47440209230bSgjelinek } else {
47450209230bSgjelinek if ((err = zonecfg_set_aliased_rctl(handle,
47460209230bSgjelinek ALIAS_MAXLOCKEDMEM, mem_cap)) != Z_OK)
4747bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
47480209230bSgjelinek else
4749bbec428eSgjelinek need_to_commit = B_TRUE;
47500209230bSgjelinek }
47510209230bSgjelinek break;
47520209230bSgjelinek default:
47530209230bSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
4754bbec428eSgjelinek B_TRUE);
4755bbec428eSgjelinek long_usage(CMD_SET, B_TRUE);
4756bbec428eSgjelinek usage(B_FALSE, HELP_PROPS);
47570209230bSgjelinek return;
47580209230bSgjelinek }
47590209230bSgjelinek return;
4760cb8a054bSGlenn Faden case RT_ADMIN:
4761cb8a054bSGlenn Faden switch (prop_type) {
4762cb8a054bSGlenn Faden case PT_USER:
4763cb8a054bSGlenn Faden (void) strlcpy(in_progress_admintab.zone_admin_user,
4764cb8a054bSGlenn Faden prop_id,
4765cb8a054bSGlenn Faden sizeof (in_progress_admintab.zone_admin_user));
4766cb8a054bSGlenn Faden return;
4767cb8a054bSGlenn Faden case PT_AUTHS:
4768cb8a054bSGlenn Faden (void) strlcpy(in_progress_admintab.zone_admin_auths,
4769cb8a054bSGlenn Faden prop_id,
4770cb8a054bSGlenn Faden sizeof (in_progress_admintab.zone_admin_auths));
4771cb8a054bSGlenn Faden return;
4772cb8a054bSGlenn Faden default:
4773cb8a054bSGlenn Faden zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
4774cb8a054bSGlenn Faden B_TRUE);
4775cb8a054bSGlenn Faden long_usage(CMD_SET, B_TRUE);
4776cb8a054bSGlenn Faden usage(B_FALSE, HELP_PROPS);
4777cb8a054bSGlenn Faden return;
4778cb8a054bSGlenn Faden }
47797c478bd9Sstevel@tonic-gate default:
4780bbec428eSgjelinek zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, B_TRUE);
4781bbec428eSgjelinek long_usage(CMD_SET, B_TRUE);
4782bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES);
47837c478bd9Sstevel@tonic-gate return;
47847c478bd9Sstevel@tonic-gate }
47857c478bd9Sstevel@tonic-gate }
47867c478bd9Sstevel@tonic-gate
47877c478bd9Sstevel@tonic-gate static void
output_prop(FILE * fp,int pnum,char * pval,boolean_t print_notspec)4788bbec428eSgjelinek output_prop(FILE *fp, int pnum, char *pval, boolean_t print_notspec)
47897c478bd9Sstevel@tonic-gate {
47907c478bd9Sstevel@tonic-gate char *qstr;
47917c478bd9Sstevel@tonic-gate
47927c478bd9Sstevel@tonic-gate if (*pval != '\0') {
47937c478bd9Sstevel@tonic-gate qstr = quoteit(pval);
47940209230bSgjelinek if (pnum == PT_SWAP || pnum == PT_LOCKED)
47950209230bSgjelinek (void) fprintf(fp, "\t[%s: %s]\n", pt_to_str(pnum),
47960209230bSgjelinek qstr);
47970209230bSgjelinek else
47987c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s: %s\n", pt_to_str(pnum), qstr);
47997c478bd9Sstevel@tonic-gate free(qstr);
48007c478bd9Sstevel@tonic-gate } else if (print_notspec)
4801087719fdSdp (void) fprintf(fp, gettext("\t%s not specified\n"),
4802087719fdSdp pt_to_str(pnum));
4803087719fdSdp }
4804087719fdSdp
4805087719fdSdp static void
info_zonename(zone_dochandle_t handle,FILE * fp)4806087719fdSdp info_zonename(zone_dochandle_t handle, FILE *fp)
4807087719fdSdp {
4808087719fdSdp char zonename[ZONENAME_MAX];
4809087719fdSdp
4810087719fdSdp if (zonecfg_get_name(handle, zonename, sizeof (zonename)) == Z_OK)
4811087719fdSdp (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_ZONENAME),
4812087719fdSdp zonename);
4813087719fdSdp else
4814087719fdSdp (void) fprintf(fp, gettext("%s not specified\n"),
4815087719fdSdp pt_to_str(PT_ZONENAME));
48167c478bd9Sstevel@tonic-gate }
48177c478bd9Sstevel@tonic-gate
48187c478bd9Sstevel@tonic-gate static void
info_zonepath(zone_dochandle_t handle,FILE * fp)48197c478bd9Sstevel@tonic-gate info_zonepath(zone_dochandle_t handle, FILE *fp)
48207c478bd9Sstevel@tonic-gate {
48217c478bd9Sstevel@tonic-gate char zonepath[MAXPATHLEN];
48227c478bd9Sstevel@tonic-gate
48237c478bd9Sstevel@tonic-gate if (zonecfg_get_zonepath(handle, zonepath, sizeof (zonepath)) == Z_OK)
48247c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_ZONEPATH),
48257c478bd9Sstevel@tonic-gate zonepath);
4826087719fdSdp else {
4827087719fdSdp (void) fprintf(fp, gettext("%s not specified\n"),
4828087719fdSdp pt_to_str(PT_ZONEPATH));
4829087719fdSdp }
48307c478bd9Sstevel@tonic-gate }
48317c478bd9Sstevel@tonic-gate
48327c478bd9Sstevel@tonic-gate static void
info_brand(zone_dochandle_t handle,FILE * fp)48339acbbeafSnn35248 info_brand(zone_dochandle_t handle, FILE *fp)
48349acbbeafSnn35248 {
48359acbbeafSnn35248 char brand[MAXNAMELEN];
48369acbbeafSnn35248
48379acbbeafSnn35248 if (zonecfg_get_brand(handle, brand, sizeof (brand)) == Z_OK)
48389acbbeafSnn35248 (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_BRAND),
48399acbbeafSnn35248 brand);
48409acbbeafSnn35248 else
48419acbbeafSnn35248 (void) fprintf(fp, "%s %s\n", pt_to_str(PT_BRAND),
48429acbbeafSnn35248 gettext("not specified"));
48439acbbeafSnn35248 }
48449acbbeafSnn35248
48459acbbeafSnn35248 static void
info_autoboot(zone_dochandle_t handle,FILE * fp)48467c478bd9Sstevel@tonic-gate info_autoboot(zone_dochandle_t handle, FILE *fp)
48477c478bd9Sstevel@tonic-gate {
48487c478bd9Sstevel@tonic-gate boolean_t autoboot;
48497c478bd9Sstevel@tonic-gate int err;
48507c478bd9Sstevel@tonic-gate
48517c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_autoboot(handle, &autoboot)) == Z_OK)
48527c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_AUTOBOOT),
48537c478bd9Sstevel@tonic-gate autoboot ? "true" : "false");
48547c478bd9Sstevel@tonic-gate else
4855bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
48567c478bd9Sstevel@tonic-gate }
48577c478bd9Sstevel@tonic-gate
48587c478bd9Sstevel@tonic-gate static void
info_pool(zone_dochandle_t handle,FILE * fp)48597c478bd9Sstevel@tonic-gate info_pool(zone_dochandle_t handle, FILE *fp)
48607c478bd9Sstevel@tonic-gate {
48617c478bd9Sstevel@tonic-gate char pool[MAXNAMELEN];
48627c478bd9Sstevel@tonic-gate int err;
48637c478bd9Sstevel@tonic-gate
48647c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_pool(handle, pool, sizeof (pool))) == Z_OK)
48657c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_POOL), pool);
48667c478bd9Sstevel@tonic-gate else
4867bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
48687c478bd9Sstevel@tonic-gate }
48697c478bd9Sstevel@tonic-gate
48707c478bd9Sstevel@tonic-gate static void
info_limitpriv(zone_dochandle_t handle,FILE * fp)4871ffbafc53Scomay info_limitpriv(zone_dochandle_t handle, FILE *fp)
4872ffbafc53Scomay {
4873ffbafc53Scomay char *limitpriv;
4874ffbafc53Scomay int err;
4875ffbafc53Scomay
4876ffbafc53Scomay if ((err = zonecfg_get_limitpriv(handle, &limitpriv)) == Z_OK) {
4877ffbafc53Scomay (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_LIMITPRIV),
4878ffbafc53Scomay limitpriv);
4879ffbafc53Scomay free(limitpriv);
4880ffbafc53Scomay } else {
4881bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
4882ffbafc53Scomay }
4883ffbafc53Scomay }
4884ffbafc53Scomay
4885ffbafc53Scomay static void
info_bootargs(zone_dochandle_t handle,FILE * fp)48863f2f09c1Sdp info_bootargs(zone_dochandle_t handle, FILE *fp)
48873f2f09c1Sdp {
48883f2f09c1Sdp char bootargs[BOOTARGS_MAX];
48893f2f09c1Sdp int err;
48903f2f09c1Sdp
48913f2f09c1Sdp if ((err = zonecfg_get_bootargs(handle, bootargs,
48923f2f09c1Sdp sizeof (bootargs))) == Z_OK) {
48933f2f09c1Sdp (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_BOOTARGS),
48943f2f09c1Sdp bootargs);
48953f2f09c1Sdp } else {
4896bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
48973f2f09c1Sdp }
48983f2f09c1Sdp }
48993f2f09c1Sdp
49003f2f09c1Sdp static void
info_sched(zone_dochandle_t handle,FILE * fp)49010209230bSgjelinek info_sched(zone_dochandle_t handle, FILE *fp)
49020209230bSgjelinek {
49030209230bSgjelinek char sched[MAXNAMELEN];
49040209230bSgjelinek int err;
49050209230bSgjelinek
49060209230bSgjelinek if ((err = zonecfg_get_sched_class(handle, sched, sizeof (sched)))
49070209230bSgjelinek == Z_OK) {
49080209230bSgjelinek (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_SCHED), sched);
49090209230bSgjelinek } else {
4910bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
49110209230bSgjelinek }
49120209230bSgjelinek }
49130209230bSgjelinek
49140209230bSgjelinek static void
info_iptype(zone_dochandle_t handle,FILE * fp)4915f4b3ec61Sdh155122 info_iptype(zone_dochandle_t handle, FILE *fp)
4916f4b3ec61Sdh155122 {
4917f4b3ec61Sdh155122 zone_iptype_t iptype;
4918f4b3ec61Sdh155122 int err;
4919f4b3ec61Sdh155122
4920f4b3ec61Sdh155122 if ((err = zonecfg_get_iptype(handle, &iptype)) == Z_OK) {
4921f4b3ec61Sdh155122 switch (iptype) {
4922f4b3ec61Sdh155122 case ZS_SHARED:
4923f4b3ec61Sdh155122 (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_IPTYPE),
4924f4b3ec61Sdh155122 "shared");
4925f4b3ec61Sdh155122 break;
4926f4b3ec61Sdh155122 case ZS_EXCLUSIVE:
4927f4b3ec61Sdh155122 (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_IPTYPE),
4928f4b3ec61Sdh155122 "exclusive");
4929f4b3ec61Sdh155122 break;
4930f4b3ec61Sdh155122 }
4931f4b3ec61Sdh155122 } else {
4932bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
4933f4b3ec61Sdh155122 }
4934f4b3ec61Sdh155122 }
4935f4b3ec61Sdh155122
4936f4b3ec61Sdh155122 static void
info_hostid(zone_dochandle_t handle,FILE * fp)49375679c89fSjv227347 info_hostid(zone_dochandle_t handle, FILE *fp)
49385679c89fSjv227347 {
49395679c89fSjv227347 char hostidp[HW_HOSTID_LEN];
49400fbb751dSJohn Levon int err;
49415679c89fSjv227347
49420fbb751dSJohn Levon if ((err = zonecfg_get_hostid(handle, hostidp,
49430fbb751dSJohn Levon sizeof (hostidp))) == Z_OK) {
49445679c89fSjv227347 (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_HOSTID), hostidp);
49450fbb751dSJohn Levon } else if (err == Z_BAD_PROPERTY) {
49460fbb751dSJohn Levon (void) fprintf(fp, "%s: \n", pt_to_str(PT_HOSTID));
49470fbb751dSJohn Levon } else {
49480fbb751dSJohn Levon zone_perror(zone, err, B_TRUE);
49490fbb751dSJohn Levon }
49500fbb751dSJohn Levon }
49510fbb751dSJohn Levon
49520fbb751dSJohn Levon static void
info_fs_allowed(zone_dochandle_t handle,FILE * fp)49530fbb751dSJohn Levon info_fs_allowed(zone_dochandle_t handle, FILE *fp)
49540fbb751dSJohn Levon {
49550fbb751dSJohn Levon char fsallowedp[ZONE_FS_ALLOWED_MAX];
49560fbb751dSJohn Levon int err;
49570fbb751dSJohn Levon
49580fbb751dSJohn Levon if ((err = zonecfg_get_fs_allowed(handle, fsallowedp,
49590fbb751dSJohn Levon sizeof (fsallowedp))) == Z_OK) {
49600fbb751dSJohn Levon (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_FS_ALLOWED),
49610fbb751dSJohn Levon fsallowedp);
49620fbb751dSJohn Levon } else if (err == Z_BAD_PROPERTY) {
49630fbb751dSJohn Levon (void) fprintf(fp, "%s: \n", pt_to_str(PT_FS_ALLOWED));
49640fbb751dSJohn Levon } else {
49650fbb751dSJohn Levon zone_perror(zone, err, B_TRUE);
49660fbb751dSJohn Levon }
49675679c89fSjv227347 }
49685679c89fSjv227347
49695679c89fSjv227347 static void
output_fs(FILE * fp,struct zone_fstab * fstab)49707c478bd9Sstevel@tonic-gate output_fs(FILE *fp, struct zone_fstab *fstab)
49717c478bd9Sstevel@tonic-gate {
49727c478bd9Sstevel@tonic-gate zone_fsopt_t *this;
49737c478bd9Sstevel@tonic-gate
49747c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_FS));
49757c478bd9Sstevel@tonic-gate output_prop(fp, PT_DIR, fstab->zone_fs_dir, B_TRUE);
49767c478bd9Sstevel@tonic-gate output_prop(fp, PT_SPECIAL, fstab->zone_fs_special, B_TRUE);
49777c478bd9Sstevel@tonic-gate output_prop(fp, PT_RAW, fstab->zone_fs_raw, B_TRUE);
49787c478bd9Sstevel@tonic-gate output_prop(fp, PT_TYPE, fstab->zone_fs_type, B_TRUE);
49797c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s: [", pt_to_str(PT_OPTIONS));
49807c478bd9Sstevel@tonic-gate for (this = fstab->zone_fs_options; this != NULL;
49817c478bd9Sstevel@tonic-gate this = this->zone_fsopt_next) {
49827c478bd9Sstevel@tonic-gate if (strchr(this->zone_fsopt_opt, '='))
49837c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\"%s\"", this->zone_fsopt_opt);
49847c478bd9Sstevel@tonic-gate else
49857c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s", this->zone_fsopt_opt);
49867c478bd9Sstevel@tonic-gate if (this->zone_fsopt_next != NULL)
49877c478bd9Sstevel@tonic-gate (void) fprintf(fp, ",");
49887c478bd9Sstevel@tonic-gate }
49897c478bd9Sstevel@tonic-gate (void) fprintf(fp, "]\n");
49907c478bd9Sstevel@tonic-gate }
49917c478bd9Sstevel@tonic-gate
49927c478bd9Sstevel@tonic-gate static void
info_fs(zone_dochandle_t handle,FILE * fp,cmd_t * cmd)49937c478bd9Sstevel@tonic-gate info_fs(zone_dochandle_t handle, FILE *fp, cmd_t *cmd)
49947c478bd9Sstevel@tonic-gate {
49957c478bd9Sstevel@tonic-gate struct zone_fstab lookup, user;
4996bbec428eSgjelinek boolean_t output = B_FALSE;
49977c478bd9Sstevel@tonic-gate
49987c478bd9Sstevel@tonic-gate if (zonecfg_setfsent(handle) != Z_OK)
49997c478bd9Sstevel@tonic-gate return;
50007c478bd9Sstevel@tonic-gate while (zonecfg_getfsent(handle, &lookup) == Z_OK) {
50017c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) {
50027c478bd9Sstevel@tonic-gate output_fs(fp, &lookup);
50037c478bd9Sstevel@tonic-gate goto loopend;
50047c478bd9Sstevel@tonic-gate }
5005bbec428eSgjelinek if (fill_in_fstab(cmd, &user, B_TRUE) != Z_OK)
50067c478bd9Sstevel@tonic-gate goto loopend;
50077c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_dir) > 0 &&
50087c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_dir, lookup.zone_fs_dir) != 0)
50097c478bd9Sstevel@tonic-gate goto loopend; /* no match */
50107c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_special) > 0 &&
50117c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_special, lookup.zone_fs_special) != 0)
50127c478bd9Sstevel@tonic-gate goto loopend; /* no match */
50137c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_type) > 0 &&
50147c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_type, lookup.zone_fs_type) != 0)
50157c478bd9Sstevel@tonic-gate goto loopend; /* no match */
50167c478bd9Sstevel@tonic-gate output_fs(fp, &lookup);
5017bbec428eSgjelinek output = B_TRUE;
50187c478bd9Sstevel@tonic-gate loopend:
50197c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(lookup.zone_fs_options);
50207c478bd9Sstevel@tonic-gate }
50217c478bd9Sstevel@tonic-gate (void) zonecfg_endfsent(handle);
50227c478bd9Sstevel@tonic-gate /*
50237c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was
50247c478bd9Sstevel@tonic-gate * nothing to output.
50257c478bd9Sstevel@tonic-gate */
50267c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0)
50277c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"),
50287c478bd9Sstevel@tonic-gate rt_to_str(RT_FS));
50297c478bd9Sstevel@tonic-gate }
50307c478bd9Sstevel@tonic-gate
50317c478bd9Sstevel@tonic-gate static void
output_net(FILE * fp,struct zone_nwiftab * nwiftab)50327c478bd9Sstevel@tonic-gate output_net(FILE *fp, struct zone_nwiftab *nwiftab)
50337c478bd9Sstevel@tonic-gate {
50347c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_NET));
50357c478bd9Sstevel@tonic-gate output_prop(fp, PT_ADDRESS, nwiftab->zone_nwif_address, B_TRUE);
5036550b6e40SSowmini Varadhan output_prop(fp, PT_ALLOWED_ADDRESS,
5037550b6e40SSowmini Varadhan nwiftab->zone_nwif_allowed_address, B_TRUE);
50387c478bd9Sstevel@tonic-gate output_prop(fp, PT_PHYSICAL, nwiftab->zone_nwif_physical, B_TRUE);
5039de860bd9Sgfaden output_prop(fp, PT_DEFROUTER, nwiftab->zone_nwif_defrouter, B_TRUE);
50407c478bd9Sstevel@tonic-gate }
50417c478bd9Sstevel@tonic-gate
50427c478bd9Sstevel@tonic-gate static void
info_net(zone_dochandle_t handle,FILE * fp,cmd_t * cmd)50437c478bd9Sstevel@tonic-gate info_net(zone_dochandle_t handle, FILE *fp, cmd_t *cmd)
50447c478bd9Sstevel@tonic-gate {
50457c478bd9Sstevel@tonic-gate struct zone_nwiftab lookup, user;
5046bbec428eSgjelinek boolean_t output = B_FALSE;
50477c478bd9Sstevel@tonic-gate
50487c478bd9Sstevel@tonic-gate if (zonecfg_setnwifent(handle) != Z_OK)
50497c478bd9Sstevel@tonic-gate return;
50507c478bd9Sstevel@tonic-gate while (zonecfg_getnwifent(handle, &lookup) == Z_OK) {
50517c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) {
50527c478bd9Sstevel@tonic-gate output_net(fp, &lookup);
50537c478bd9Sstevel@tonic-gate continue;
50547c478bd9Sstevel@tonic-gate }
5055bbec428eSgjelinek if (fill_in_nwiftab(cmd, &user, B_TRUE) != Z_OK)
50567c478bd9Sstevel@tonic-gate continue;
50577c478bd9Sstevel@tonic-gate if (strlen(user.zone_nwif_physical) > 0 &&
50587c478bd9Sstevel@tonic-gate strcmp(user.zone_nwif_physical,
50597c478bd9Sstevel@tonic-gate lookup.zone_nwif_physical) != 0)
50607c478bd9Sstevel@tonic-gate continue; /* no match */
5061f4b3ec61Sdh155122 /* If present make sure it matches */
50627c478bd9Sstevel@tonic-gate if (strlen(user.zone_nwif_address) > 0 &&
50637c478bd9Sstevel@tonic-gate !zonecfg_same_net_address(user.zone_nwif_address,
50647c478bd9Sstevel@tonic-gate lookup.zone_nwif_address))
50657c478bd9Sstevel@tonic-gate continue; /* no match */
50667c478bd9Sstevel@tonic-gate output_net(fp, &lookup);
5067bbec428eSgjelinek output = B_TRUE;
50687c478bd9Sstevel@tonic-gate }
50697c478bd9Sstevel@tonic-gate (void) zonecfg_endnwifent(handle);
50707c478bd9Sstevel@tonic-gate /*
50717c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was
50727c478bd9Sstevel@tonic-gate * nothing to output.
50737c478bd9Sstevel@tonic-gate */
50747c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0)
50757c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"),
50767c478bd9Sstevel@tonic-gate rt_to_str(RT_NET));
50777c478bd9Sstevel@tonic-gate }
50787c478bd9Sstevel@tonic-gate
50797c478bd9Sstevel@tonic-gate static void
output_dev(FILE * fp,struct zone_devtab * devtab)50807c478bd9Sstevel@tonic-gate output_dev(FILE *fp, struct zone_devtab *devtab)
50817c478bd9Sstevel@tonic-gate {
508227e6fb21Sdp (void) fprintf(fp, "%s:\n", rt_to_str(RT_DEVICE));
50837c478bd9Sstevel@tonic-gate output_prop(fp, PT_MATCH, devtab->zone_dev_match, B_TRUE);
50847c478bd9Sstevel@tonic-gate }
50857c478bd9Sstevel@tonic-gate
50867c478bd9Sstevel@tonic-gate static void
info_dev(zone_dochandle_t handle,FILE * fp,cmd_t * cmd)50877c478bd9Sstevel@tonic-gate info_dev(zone_dochandle_t handle, FILE *fp, cmd_t *cmd)
50887c478bd9Sstevel@tonic-gate {
50897c478bd9Sstevel@tonic-gate struct zone_devtab lookup, user;
5090bbec428eSgjelinek boolean_t output = B_FALSE;
50917c478bd9Sstevel@tonic-gate
50927c478bd9Sstevel@tonic-gate if (zonecfg_setdevent(handle) != Z_OK)
50937c478bd9Sstevel@tonic-gate return;
50947c478bd9Sstevel@tonic-gate while (zonecfg_getdevent(handle, &lookup) == Z_OK) {
50957c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) {
50967c478bd9Sstevel@tonic-gate output_dev(fp, &lookup);
50977c478bd9Sstevel@tonic-gate continue;
50987c478bd9Sstevel@tonic-gate }
5099bbec428eSgjelinek if (fill_in_devtab(cmd, &user, B_TRUE) != Z_OK)
51007c478bd9Sstevel@tonic-gate continue;
51017c478bd9Sstevel@tonic-gate if (strlen(user.zone_dev_match) > 0 &&
51027c478bd9Sstevel@tonic-gate strcmp(user.zone_dev_match, lookup.zone_dev_match) != 0)
51037c478bd9Sstevel@tonic-gate continue; /* no match */
51047c478bd9Sstevel@tonic-gate output_dev(fp, &lookup);
5105bbec428eSgjelinek output = B_TRUE;
51067c478bd9Sstevel@tonic-gate }
51077c478bd9Sstevel@tonic-gate (void) zonecfg_enddevent(handle);
51087c478bd9Sstevel@tonic-gate /*
51097c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was
51107c478bd9Sstevel@tonic-gate * nothing to output.
51117c478bd9Sstevel@tonic-gate */
51127c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0)
51137c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"),
51147c478bd9Sstevel@tonic-gate rt_to_str(RT_DEVICE));
51157c478bd9Sstevel@tonic-gate }
51167c478bd9Sstevel@tonic-gate
51177c478bd9Sstevel@tonic-gate static void
output_rctl(FILE * fp,struct zone_rctltab * rctltab)51187c478bd9Sstevel@tonic-gate output_rctl(FILE *fp, struct zone_rctltab *rctltab)
51197c478bd9Sstevel@tonic-gate {
51207c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *valptr;
51217c478bd9Sstevel@tonic-gate
51227c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_RCTL));
51237c478bd9Sstevel@tonic-gate output_prop(fp, PT_NAME, rctltab->zone_rctl_name, B_TRUE);
51247c478bd9Sstevel@tonic-gate for (valptr = rctltab->zone_rctl_valptr; valptr != NULL;
51257c478bd9Sstevel@tonic-gate valptr = valptr->zone_rctlval_next) {
51267c478bd9Sstevel@tonic-gate fprintf(fp, "\t%s: (%s=%s,%s=%s,%s=%s)\n",
51277c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE),
51287c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV), valptr->zone_rctlval_priv,
51297c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT), valptr->zone_rctlval_limit,
51307c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION), valptr->zone_rctlval_action);
51317c478bd9Sstevel@tonic-gate }
51327c478bd9Sstevel@tonic-gate }
51337c478bd9Sstevel@tonic-gate
51347c478bd9Sstevel@tonic-gate static void
info_rctl(zone_dochandle_t handle,FILE * fp,cmd_t * cmd)51357c478bd9Sstevel@tonic-gate info_rctl(zone_dochandle_t handle, FILE *fp, cmd_t *cmd)
51367c478bd9Sstevel@tonic-gate {
51377c478bd9Sstevel@tonic-gate struct zone_rctltab lookup, user;
5138bbec428eSgjelinek boolean_t output = B_FALSE;
51397c478bd9Sstevel@tonic-gate
51407c478bd9Sstevel@tonic-gate if (zonecfg_setrctlent(handle) != Z_OK)
51417c478bd9Sstevel@tonic-gate return;
51427c478bd9Sstevel@tonic-gate while (zonecfg_getrctlent(handle, &lookup) == Z_OK) {
51437c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) {
51447c478bd9Sstevel@tonic-gate output_rctl(fp, &lookup);
5145bbec428eSgjelinek } else if (fill_in_rctltab(cmd, &user, B_TRUE) == Z_OK &&
51467c478bd9Sstevel@tonic-gate (strlen(user.zone_rctl_name) == 0 ||
51477c478bd9Sstevel@tonic-gate strcmp(user.zone_rctl_name, lookup.zone_rctl_name) == 0)) {
51487c478bd9Sstevel@tonic-gate output_rctl(fp, &lookup);
5149bbec428eSgjelinek output = B_TRUE;
51507c478bd9Sstevel@tonic-gate }
51517c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(lookup.zone_rctl_valptr);
51527c478bd9Sstevel@tonic-gate }
51537c478bd9Sstevel@tonic-gate (void) zonecfg_endrctlent(handle);
51547c478bd9Sstevel@tonic-gate /*
51557c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was
51567c478bd9Sstevel@tonic-gate * nothing to output.
51577c478bd9Sstevel@tonic-gate */
51587c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0)
51597c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"),
51607c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL));
51617c478bd9Sstevel@tonic-gate }
51627c478bd9Sstevel@tonic-gate
51637c478bd9Sstevel@tonic-gate static void
output_attr(FILE * fp,struct zone_attrtab * attrtab)51647c478bd9Sstevel@tonic-gate output_attr(FILE *fp, struct zone_attrtab *attrtab)
51657c478bd9Sstevel@tonic-gate {
51667c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_ATTR));
51677c478bd9Sstevel@tonic-gate output_prop(fp, PT_NAME, attrtab->zone_attr_name, B_TRUE);
51687c478bd9Sstevel@tonic-gate output_prop(fp, PT_TYPE, attrtab->zone_attr_type, B_TRUE);
51697c478bd9Sstevel@tonic-gate output_prop(fp, PT_VALUE, attrtab->zone_attr_value, B_TRUE);
51707c478bd9Sstevel@tonic-gate }
51717c478bd9Sstevel@tonic-gate
51727c478bd9Sstevel@tonic-gate static void
info_attr(zone_dochandle_t handle,FILE * fp,cmd_t * cmd)51737c478bd9Sstevel@tonic-gate info_attr(zone_dochandle_t handle, FILE *fp, cmd_t *cmd)
51747c478bd9Sstevel@tonic-gate {
51757c478bd9Sstevel@tonic-gate struct zone_attrtab lookup, user;
5176bbec428eSgjelinek boolean_t output = B_FALSE;
51777c478bd9Sstevel@tonic-gate
51787c478bd9Sstevel@tonic-gate if (zonecfg_setattrent(handle) != Z_OK)
51797c478bd9Sstevel@tonic-gate return;
51807c478bd9Sstevel@tonic-gate while (zonecfg_getattrent(handle, &lookup) == Z_OK) {
51817c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) {
51827c478bd9Sstevel@tonic-gate output_attr(fp, &lookup);
51837c478bd9Sstevel@tonic-gate continue;
51847c478bd9Sstevel@tonic-gate }
5185bbec428eSgjelinek if (fill_in_attrtab(cmd, &user, B_TRUE) != Z_OK)
51867c478bd9Sstevel@tonic-gate continue;
51877c478bd9Sstevel@tonic-gate if (strlen(user.zone_attr_name) > 0 &&
51887c478bd9Sstevel@tonic-gate strcmp(user.zone_attr_name, lookup.zone_attr_name) != 0)
51897c478bd9Sstevel@tonic-gate continue; /* no match */
51907c478bd9Sstevel@tonic-gate if (strlen(user.zone_attr_type) > 0 &&
51917c478bd9Sstevel@tonic-gate strcmp(user.zone_attr_type, lookup.zone_attr_type) != 0)
51927c478bd9Sstevel@tonic-gate continue; /* no match */
51937c478bd9Sstevel@tonic-gate if (strlen(user.zone_attr_value) > 0 &&
51947c478bd9Sstevel@tonic-gate strcmp(user.zone_attr_value, lookup.zone_attr_value) != 0)
51957c478bd9Sstevel@tonic-gate continue; /* no match */
51967c478bd9Sstevel@tonic-gate output_attr(fp, &lookup);
5197bbec428eSgjelinek output = B_TRUE;
51987c478bd9Sstevel@tonic-gate }
51997c478bd9Sstevel@tonic-gate (void) zonecfg_endattrent(handle);
52007c478bd9Sstevel@tonic-gate /*
52017c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was
52027c478bd9Sstevel@tonic-gate * nothing to output.
52037c478bd9Sstevel@tonic-gate */
52047c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0)
52057c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"),
52067c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR));
52077c478bd9Sstevel@tonic-gate }
52087c478bd9Sstevel@tonic-gate
5209fa9e4066Sahrens static void
output_ds(FILE * fp,struct zone_dstab * dstab)5210fa9e4066Sahrens output_ds(FILE *fp, struct zone_dstab *dstab)
5211fa9e4066Sahrens {
5212fa9e4066Sahrens (void) fprintf(fp, "%s:\n", rt_to_str(RT_DATASET));
5213fa9e4066Sahrens output_prop(fp, PT_NAME, dstab->zone_dataset_name, B_TRUE);
5214fa9e4066Sahrens }
5215fa9e4066Sahrens
5216fa9e4066Sahrens static void
info_ds(zone_dochandle_t handle,FILE * fp,cmd_t * cmd)5217fa9e4066Sahrens info_ds(zone_dochandle_t handle, FILE *fp, cmd_t *cmd)
5218fa9e4066Sahrens {
5219fa9e4066Sahrens struct zone_dstab lookup, user;
5220bbec428eSgjelinek boolean_t output = B_FALSE;
5221fa9e4066Sahrens
52220209230bSgjelinek if (zonecfg_setdsent(handle) != Z_OK)
5223fa9e4066Sahrens return;
5224fa9e4066Sahrens while (zonecfg_getdsent(handle, &lookup) == Z_OK) {
5225fa9e4066Sahrens if (cmd->cmd_prop_nv_pairs == 0) {
5226fa9e4066Sahrens output_ds(fp, &lookup);
5227fa9e4066Sahrens continue;
5228fa9e4066Sahrens }
5229bbec428eSgjelinek if (fill_in_dstab(cmd, &user, B_TRUE) != Z_OK)
5230fa9e4066Sahrens continue;
5231fa9e4066Sahrens if (strlen(user.zone_dataset_name) > 0 &&
5232fa9e4066Sahrens strcmp(user.zone_dataset_name,
5233fa9e4066Sahrens lookup.zone_dataset_name) != 0)
5234fa9e4066Sahrens continue; /* no match */
5235fa9e4066Sahrens output_ds(fp, &lookup);
5236bbec428eSgjelinek output = B_TRUE;
5237fa9e4066Sahrens }
5238fa9e4066Sahrens (void) zonecfg_enddsent(handle);
5239fa9e4066Sahrens /*
5240fa9e4066Sahrens * If a property n/v pair was specified, warn the user if there was
5241fa9e4066Sahrens * nothing to output.
5242fa9e4066Sahrens */
5243fa9e4066Sahrens if (!output && cmd->cmd_prop_nv_pairs > 0)
5244fa9e4066Sahrens (void) printf(gettext("No such %s resource.\n"),
5245fa9e4066Sahrens rt_to_str(RT_DATASET));
5246fa9e4066Sahrens }
5247fa9e4066Sahrens
52480209230bSgjelinek static void
output_pset(FILE * fp,struct zone_psettab * psettab)52490209230bSgjelinek output_pset(FILE *fp, struct zone_psettab *psettab)
52500209230bSgjelinek {
52510209230bSgjelinek (void) fprintf(fp, "%s:\n", rt_to_str(RT_DCPU));
52520209230bSgjelinek if (strcmp(psettab->zone_ncpu_min, psettab->zone_ncpu_max) == 0)
52530209230bSgjelinek (void) fprintf(fp, "\t%s: %s\n", pt_to_str(PT_NCPUS),
52540209230bSgjelinek psettab->zone_ncpu_max);
52550209230bSgjelinek else
52560209230bSgjelinek (void) fprintf(fp, "\t%s: %s-%s\n", pt_to_str(PT_NCPUS),
52570209230bSgjelinek psettab->zone_ncpu_min, psettab->zone_ncpu_max);
52580209230bSgjelinek if (psettab->zone_importance[0] != '\0')
52590209230bSgjelinek (void) fprintf(fp, "\t%s: %s\n", pt_to_str(PT_IMPORTANCE),
52600209230bSgjelinek psettab->zone_importance);
52610209230bSgjelinek }
52620209230bSgjelinek
52630209230bSgjelinek static void
info_pset(zone_dochandle_t handle,FILE * fp)52640209230bSgjelinek info_pset(zone_dochandle_t handle, FILE *fp)
52650209230bSgjelinek {
52660209230bSgjelinek struct zone_psettab lookup;
52670209230bSgjelinek
52680209230bSgjelinek if (zonecfg_getpsetent(handle, &lookup) == Z_OK)
52690209230bSgjelinek output_pset(fp, &lookup);
52700209230bSgjelinek }
52710209230bSgjelinek
52720209230bSgjelinek static void
output_pcap(FILE * fp)5273c97ad5cdSakolb output_pcap(FILE *fp)
5274c97ad5cdSakolb {
5275c97ad5cdSakolb uint64_t cap;
5276c97ad5cdSakolb
5277c97ad5cdSakolb if (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &cap) == Z_OK) {
5278c97ad5cdSakolb float scaled = (float)cap / 100;
5279c97ad5cdSakolb (void) fprintf(fp, "%s:\n", rt_to_str(RT_PCAP));
5280c97ad5cdSakolb (void) fprintf(fp, "\t[%s: %.2f]\n", pt_to_str(PT_NCPUS),
5281c97ad5cdSakolb scaled);
5282c97ad5cdSakolb }
5283c97ad5cdSakolb }
5284c97ad5cdSakolb
5285c97ad5cdSakolb static void
info_pcap(FILE * fp)5286c97ad5cdSakolb info_pcap(FILE *fp)
5287c97ad5cdSakolb {
5288c97ad5cdSakolb output_pcap(fp);
5289c97ad5cdSakolb }
5290c97ad5cdSakolb
5291c97ad5cdSakolb
5292c97ad5cdSakolb static void
info_aliased_rctl(zone_dochandle_t handle,FILE * fp,char * alias)52930209230bSgjelinek info_aliased_rctl(zone_dochandle_t handle, FILE *fp, char *alias)
52940209230bSgjelinek {
52950209230bSgjelinek uint64_t limit;
52960209230bSgjelinek
52970209230bSgjelinek if (zonecfg_get_aliased_rctl(handle, alias, &limit) == Z_OK) {
52980209230bSgjelinek /* convert memory based properties */
52990209230bSgjelinek if (strcmp(alias, ALIAS_MAXSHMMEM) == 0) {
53000209230bSgjelinek char buf[128];
53010209230bSgjelinek
53020209230bSgjelinek (void) snprintf(buf, sizeof (buf), "%llu", limit);
53030209230bSgjelinek bytes_to_units(buf, buf, sizeof (buf));
53040209230bSgjelinek (void) fprintf(fp, "[%s: %s]\n", alias, buf);
53050209230bSgjelinek return;
53060209230bSgjelinek }
53070209230bSgjelinek
53080209230bSgjelinek (void) fprintf(fp, "[%s: %llu]\n", alias, limit);
53090209230bSgjelinek }
53100209230bSgjelinek }
53110209230bSgjelinek
53120209230bSgjelinek static void
bytes_to_units(char * str,char * buf,int bufsize)53130209230bSgjelinek bytes_to_units(char *str, char *buf, int bufsize)
53140209230bSgjelinek {
53150209230bSgjelinek unsigned long long num;
53160209230bSgjelinek unsigned long long save = 0;
53170209230bSgjelinek char *units = "BKMGT";
53180209230bSgjelinek char *up = units;
53190209230bSgjelinek
53200209230bSgjelinek num = strtoll(str, NULL, 10);
53210209230bSgjelinek
53220209230bSgjelinek if (num < 1024) {
53230209230bSgjelinek (void) snprintf(buf, bufsize, "%llu", num);
53240209230bSgjelinek return;
53250209230bSgjelinek }
53260209230bSgjelinek
53270209230bSgjelinek while ((num >= 1024) && (*up != 'T')) {
53280209230bSgjelinek up++; /* next unit of measurement */
53290209230bSgjelinek save = num;
53300209230bSgjelinek num = (num + 512) >> 10;
53310209230bSgjelinek }
53320209230bSgjelinek
53330209230bSgjelinek /* check if we should output a fraction. snprintf will round for us */
53340209230bSgjelinek if (save % 1024 != 0 && ((save >> 10) < 10))
53350209230bSgjelinek (void) snprintf(buf, bufsize, "%2.1f%c", ((float)save / 1024),
53360209230bSgjelinek *up);
53370209230bSgjelinek else
53380209230bSgjelinek (void) snprintf(buf, bufsize, "%llu%c", num, *up);
53390209230bSgjelinek }
53400209230bSgjelinek
53410209230bSgjelinek static void
output_mcap(FILE * fp,struct zone_mcaptab * mcaptab,int showswap,uint64_t maxswap,int showlocked,uint64_t maxlocked)53420209230bSgjelinek output_mcap(FILE *fp, struct zone_mcaptab *mcaptab, int showswap,
53430209230bSgjelinek uint64_t maxswap, int showlocked, uint64_t maxlocked)
53440209230bSgjelinek {
53450209230bSgjelinek char buf[128];
53460209230bSgjelinek
53470209230bSgjelinek (void) fprintf(fp, "%s:\n", rt_to_str(RT_MCAP));
53480209230bSgjelinek if (mcaptab->zone_physmem_cap[0] != '\0') {
53490209230bSgjelinek bytes_to_units(mcaptab->zone_physmem_cap, buf, sizeof (buf));
53500209230bSgjelinek output_prop(fp, PT_PHYSICAL, buf, B_TRUE);
53510209230bSgjelinek }
53520209230bSgjelinek
53530209230bSgjelinek if (showswap == Z_OK) {
53540209230bSgjelinek (void) snprintf(buf, sizeof (buf), "%llu", maxswap);
53550209230bSgjelinek bytes_to_units(buf, buf, sizeof (buf));
53560209230bSgjelinek output_prop(fp, PT_SWAP, buf, B_TRUE);
53570209230bSgjelinek }
53580209230bSgjelinek
53590209230bSgjelinek if (showlocked == Z_OK) {
53600209230bSgjelinek (void) snprintf(buf, sizeof (buf), "%llu", maxlocked);
53610209230bSgjelinek bytes_to_units(buf, buf, sizeof (buf));
53620209230bSgjelinek output_prop(fp, PT_LOCKED, buf, B_TRUE);
53630209230bSgjelinek }
53640209230bSgjelinek }
53650209230bSgjelinek
53660209230bSgjelinek static void
info_mcap(zone_dochandle_t handle,FILE * fp)53670209230bSgjelinek info_mcap(zone_dochandle_t handle, FILE *fp)
53680209230bSgjelinek {
53690209230bSgjelinek int res1, res2, res3;
53700209230bSgjelinek uint64_t swap_limit;
53710209230bSgjelinek uint64_t locked_limit;
53720209230bSgjelinek struct zone_mcaptab lookup;
53730209230bSgjelinek
53740209230bSgjelinek bzero(&lookup, sizeof (lookup));
53750209230bSgjelinek res1 = zonecfg_getmcapent(handle, &lookup);
53760209230bSgjelinek res2 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, &swap_limit);
53770209230bSgjelinek res3 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM,
53780209230bSgjelinek &locked_limit);
53790209230bSgjelinek
53800209230bSgjelinek if (res1 == Z_OK || res2 == Z_OK || res3 == Z_OK)
53810209230bSgjelinek output_mcap(fp, &lookup, res2, swap_limit, res3, locked_limit);
53820209230bSgjelinek }
53830209230bSgjelinek
5384cb8a054bSGlenn Faden static void
output_auth(FILE * fp,struct zone_admintab * admintab)5385cb8a054bSGlenn Faden output_auth(FILE *fp, struct zone_admintab *admintab)
5386cb8a054bSGlenn Faden {
5387cb8a054bSGlenn Faden (void) fprintf(fp, "%s:\n", rt_to_str(RT_ADMIN));
5388cb8a054bSGlenn Faden output_prop(fp, PT_USER, admintab->zone_admin_user, B_TRUE);
5389cb8a054bSGlenn Faden output_prop(fp, PT_AUTHS, admintab->zone_admin_auths, B_TRUE);
5390cb8a054bSGlenn Faden }
5391cb8a054bSGlenn Faden
5392cb8a054bSGlenn Faden static void
info_auth(zone_dochandle_t handle,FILE * fp,cmd_t * cmd)5393cb8a054bSGlenn Faden info_auth(zone_dochandle_t handle, FILE *fp, cmd_t *cmd)
5394cb8a054bSGlenn Faden {
5395cb8a054bSGlenn Faden struct zone_admintab lookup, user;
5396cb8a054bSGlenn Faden boolean_t output = B_FALSE;
5397cb8a054bSGlenn Faden int err;
5398cb8a054bSGlenn Faden
5399cb8a054bSGlenn Faden if ((err = zonecfg_setadminent(handle)) != Z_OK) {
5400cb8a054bSGlenn Faden zone_perror(zone, err, B_TRUE);
5401cb8a054bSGlenn Faden return;
5402cb8a054bSGlenn Faden }
5403cb8a054bSGlenn Faden while (zonecfg_getadminent(handle, &lookup) == Z_OK) {
5404cb8a054bSGlenn Faden if (cmd->cmd_prop_nv_pairs == 0) {
5405cb8a054bSGlenn Faden output_auth(fp, &lookup);
5406cb8a054bSGlenn Faden continue;
5407cb8a054bSGlenn Faden }
5408cb8a054bSGlenn Faden if (fill_in_admintab(cmd, &user, B_TRUE) != Z_OK)
5409cb8a054bSGlenn Faden continue;
5410cb8a054bSGlenn Faden if (strlen(user.zone_admin_user) > 0 &&
5411cb8a054bSGlenn Faden strcmp(user.zone_admin_user, lookup.zone_admin_user) != 0)
5412cb8a054bSGlenn Faden continue; /* no match */
5413cb8a054bSGlenn Faden output_auth(fp, &lookup);
5414cb8a054bSGlenn Faden output = B_TRUE;
5415cb8a054bSGlenn Faden }
5416cb8a054bSGlenn Faden (void) zonecfg_endadminent(handle);
5417cb8a054bSGlenn Faden /*
5418cb8a054bSGlenn Faden * If a property n/v pair was specified, warn the user if there was
5419cb8a054bSGlenn Faden * nothing to output.
5420cb8a054bSGlenn Faden */
5421cb8a054bSGlenn Faden if (!output && cmd->cmd_prop_nv_pairs > 0)
5422cb8a054bSGlenn Faden (void) printf(gettext("No such %s resource.\n"),
5423cb8a054bSGlenn Faden rt_to_str(RT_ADMIN));
5424cb8a054bSGlenn Faden }
5425cb8a054bSGlenn Faden
54267c478bd9Sstevel@tonic-gate void
info_func(cmd_t * cmd)54277c478bd9Sstevel@tonic-gate info_func(cmd_t *cmd)
54287c478bd9Sstevel@tonic-gate {
54297c478bd9Sstevel@tonic-gate FILE *fp = stdout;
5430bbec428eSgjelinek boolean_t need_to_close = B_FALSE;
54310209230bSgjelinek int type;
54320209230bSgjelinek int res1, res2;
54330209230bSgjelinek uint64_t swap_limit;
54340209230bSgjelinek uint64_t locked_limit;
54357c478bd9Sstevel@tonic-gate
54367c478bd9Sstevel@tonic-gate assert(cmd != NULL);
54377c478bd9Sstevel@tonic-gate
5438bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK)
54397c478bd9Sstevel@tonic-gate return;
54407c478bd9Sstevel@tonic-gate
54417c478bd9Sstevel@tonic-gate /* don't page error output */
54427c478bd9Sstevel@tonic-gate if (interactive_mode) {
5443*944b13ecSGary Mills if ((fp = pager_open()) != NULL)
5444bbec428eSgjelinek need_to_close = B_TRUE;
54453042b8b5Sbatschul else
54463042b8b5Sbatschul fp = stdout;
54473042b8b5Sbatschul
54487c478bd9Sstevel@tonic-gate setbuf(fp, NULL);
54497c478bd9Sstevel@tonic-gate }
54507c478bd9Sstevel@tonic-gate
54517c478bd9Sstevel@tonic-gate if (!global_scope) {
54527c478bd9Sstevel@tonic-gate switch (resource_scope) {
54537c478bd9Sstevel@tonic-gate case RT_FS:
54547c478bd9Sstevel@tonic-gate output_fs(fp, &in_progress_fstab);
54557c478bd9Sstevel@tonic-gate break;
54567c478bd9Sstevel@tonic-gate case RT_NET:
54577c478bd9Sstevel@tonic-gate output_net(fp, &in_progress_nwiftab);
54587c478bd9Sstevel@tonic-gate break;
54597c478bd9Sstevel@tonic-gate case RT_DEVICE:
54607c478bd9Sstevel@tonic-gate output_dev(fp, &in_progress_devtab);
54617c478bd9Sstevel@tonic-gate break;
54627c478bd9Sstevel@tonic-gate case RT_RCTL:
54637c478bd9Sstevel@tonic-gate output_rctl(fp, &in_progress_rctltab);
54647c478bd9Sstevel@tonic-gate break;
54657c478bd9Sstevel@tonic-gate case RT_ATTR:
54667c478bd9Sstevel@tonic-gate output_attr(fp, &in_progress_attrtab);
54677c478bd9Sstevel@tonic-gate break;
5468fa9e4066Sahrens case RT_DATASET:
5469fa9e4066Sahrens output_ds(fp, &in_progress_dstab);
5470fa9e4066Sahrens break;
54710209230bSgjelinek case RT_DCPU:
54720209230bSgjelinek output_pset(fp, &in_progress_psettab);
54730209230bSgjelinek break;
5474c97ad5cdSakolb case RT_PCAP:
5475c97ad5cdSakolb output_pcap(fp);
5476c97ad5cdSakolb break;
54770209230bSgjelinek case RT_MCAP:
54780209230bSgjelinek res1 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP,
54790209230bSgjelinek &swap_limit);
54800209230bSgjelinek res2 = zonecfg_get_aliased_rctl(handle,
54810209230bSgjelinek ALIAS_MAXLOCKEDMEM, &locked_limit);
54820209230bSgjelinek output_mcap(fp, &in_progress_mcaptab, res1, swap_limit,
54830209230bSgjelinek res2, locked_limit);
54840209230bSgjelinek break;
5485cb8a054bSGlenn Faden case RT_ADMIN:
5486cb8a054bSGlenn Faden output_auth(fp, &in_progress_admintab);
5487cb8a054bSGlenn Faden break;
54887c478bd9Sstevel@tonic-gate }
54897c478bd9Sstevel@tonic-gate goto cleanup;
54907c478bd9Sstevel@tonic-gate }
54917c478bd9Sstevel@tonic-gate
54920209230bSgjelinek type = cmd->cmd_res_type;
54930209230bSgjelinek
54940209230bSgjelinek if (gz_invalid_rt_property(type)) {
54950209230bSgjelinek zerr(gettext("%s is not a valid property for the global zone."),
54960209230bSgjelinek rt_to_str(type));
54970209230bSgjelinek goto cleanup;
54980209230bSgjelinek }
54990209230bSgjelinek
55000209230bSgjelinek if (gz_invalid_resource(type)) {
55010209230bSgjelinek zerr(gettext("%s is not a valid resource for the global zone."),
55020209230bSgjelinek rt_to_str(type));
55030209230bSgjelinek goto cleanup;
55040209230bSgjelinek }
55050209230bSgjelinek
55067c478bd9Sstevel@tonic-gate switch (cmd->cmd_res_type) {
55077c478bd9Sstevel@tonic-gate case RT_UNKNOWN:
5508087719fdSdp info_zonename(handle, fp);
55090209230bSgjelinek if (!global_zone) {
55107c478bd9Sstevel@tonic-gate info_zonepath(handle, fp);
55119acbbeafSnn35248 info_brand(handle, fp);
55127c478bd9Sstevel@tonic-gate info_autoboot(handle, fp);
55133f2f09c1Sdp info_bootargs(handle, fp);
55140209230bSgjelinek }
55157c478bd9Sstevel@tonic-gate info_pool(handle, fp);
55160209230bSgjelinek if (!global_zone) {
5517ffbafc53Scomay info_limitpriv(handle, fp);
55180209230bSgjelinek info_sched(handle, fp);
5519f4b3ec61Sdh155122 info_iptype(handle, fp);
55205679c89fSjv227347 info_hostid(handle, fp);
55210fbb751dSJohn Levon info_fs_allowed(handle, fp);
55220209230bSgjelinek }
55230209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXLWPS);
5524ff19e029SMenno Lageman info_aliased_rctl(handle, fp, ALIAS_MAXPROCS);
55250209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSHMMEM);
55260209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSHMIDS);
55270209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXMSGIDS);
55280209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSEMIDS);
55290209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_SHARES);
55300209230bSgjelinek if (!global_zone) {
55317c478bd9Sstevel@tonic-gate info_fs(handle, fp, cmd);
55327c478bd9Sstevel@tonic-gate info_net(handle, fp, cmd);
55337c478bd9Sstevel@tonic-gate info_dev(handle, fp, cmd);
55340209230bSgjelinek }
55350209230bSgjelinek info_pset(handle, fp);
5536c97ad5cdSakolb info_pcap(fp);
55370209230bSgjelinek info_mcap(handle, fp);
55380209230bSgjelinek if (!global_zone) {
55397c478bd9Sstevel@tonic-gate info_attr(handle, fp, cmd);
5540fa9e4066Sahrens info_ds(handle, fp, cmd);
5541cb8a054bSGlenn Faden info_auth(handle, fp, cmd);
55420209230bSgjelinek }
55430209230bSgjelinek info_rctl(handle, fp, cmd);
55447c478bd9Sstevel@tonic-gate break;
5545087719fdSdp case RT_ZONENAME:
5546087719fdSdp info_zonename(handle, fp);
5547087719fdSdp break;
55487c478bd9Sstevel@tonic-gate case RT_ZONEPATH:
55497c478bd9Sstevel@tonic-gate info_zonepath(handle, fp);
55507c478bd9Sstevel@tonic-gate break;
55519acbbeafSnn35248 case RT_BRAND:
55529acbbeafSnn35248 info_brand(handle, fp);
55539acbbeafSnn35248 break;
55547c478bd9Sstevel@tonic-gate case RT_AUTOBOOT:
55557c478bd9Sstevel@tonic-gate info_autoboot(handle, fp);
55567c478bd9Sstevel@tonic-gate break;
55577c478bd9Sstevel@tonic-gate case RT_POOL:
55587c478bd9Sstevel@tonic-gate info_pool(handle, fp);
55597c478bd9Sstevel@tonic-gate break;
5560ffbafc53Scomay case RT_LIMITPRIV:
5561ffbafc53Scomay info_limitpriv(handle, fp);
5562ffbafc53Scomay break;
55633f2f09c1Sdp case RT_BOOTARGS:
55643f2f09c1Sdp info_bootargs(handle, fp);
55653f2f09c1Sdp break;
55660209230bSgjelinek case RT_SCHED:
55670209230bSgjelinek info_sched(handle, fp);
55680209230bSgjelinek break;
5569f4b3ec61Sdh155122 case RT_IPTYPE:
5570f4b3ec61Sdh155122 info_iptype(handle, fp);
5571f4b3ec61Sdh155122 break;
55720209230bSgjelinek case RT_MAXLWPS:
55730209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXLWPS);
55740209230bSgjelinek break;
5575ff19e029SMenno Lageman case RT_MAXPROCS:
5576ff19e029SMenno Lageman info_aliased_rctl(handle, fp, ALIAS_MAXPROCS);
5577ff19e029SMenno Lageman break;
55780209230bSgjelinek case RT_MAXSHMMEM:
55790209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSHMMEM);
55800209230bSgjelinek break;
55810209230bSgjelinek case RT_MAXSHMIDS:
55820209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSHMIDS);
55830209230bSgjelinek break;
55840209230bSgjelinek case RT_MAXMSGIDS:
55850209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXMSGIDS);
55860209230bSgjelinek break;
55870209230bSgjelinek case RT_MAXSEMIDS:
55880209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSEMIDS);
55890209230bSgjelinek break;
55900209230bSgjelinek case RT_SHARES:
55910209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_SHARES);
55920209230bSgjelinek break;
55937c478bd9Sstevel@tonic-gate case RT_FS:
55947c478bd9Sstevel@tonic-gate info_fs(handle, fp, cmd);
55957c478bd9Sstevel@tonic-gate break;
55967c478bd9Sstevel@tonic-gate case RT_NET:
55977c478bd9Sstevel@tonic-gate info_net(handle, fp, cmd);
55987c478bd9Sstevel@tonic-gate break;
55997c478bd9Sstevel@tonic-gate case RT_DEVICE:
56007c478bd9Sstevel@tonic-gate info_dev(handle, fp, cmd);
56017c478bd9Sstevel@tonic-gate break;
56027c478bd9Sstevel@tonic-gate case RT_RCTL:
56037c478bd9Sstevel@tonic-gate info_rctl(handle, fp, cmd);
56047c478bd9Sstevel@tonic-gate break;
56057c478bd9Sstevel@tonic-gate case RT_ATTR:
56067c478bd9Sstevel@tonic-gate info_attr(handle, fp, cmd);
56077c478bd9Sstevel@tonic-gate break;
5608fa9e4066Sahrens case RT_DATASET:
5609fa9e4066Sahrens info_ds(handle, fp, cmd);
5610fa9e4066Sahrens break;
56110209230bSgjelinek case RT_DCPU:
56120209230bSgjelinek info_pset(handle, fp);
56130209230bSgjelinek break;
5614c97ad5cdSakolb case RT_PCAP:
5615c97ad5cdSakolb info_pcap(fp);
5616c97ad5cdSakolb break;
56170209230bSgjelinek case RT_MCAP:
56180209230bSgjelinek info_mcap(handle, fp);
56190209230bSgjelinek break;
56205679c89fSjv227347 case RT_HOSTID:
56215679c89fSjv227347 info_hostid(handle, fp);
56225679c89fSjv227347 break;
5623cb8a054bSGlenn Faden case RT_ADMIN:
5624cb8a054bSGlenn Faden info_auth(handle, fp, cmd);
5625cb8a054bSGlenn Faden break;
56260fbb751dSJohn Levon case RT_FS_ALLOWED:
56270fbb751dSJohn Levon info_fs_allowed(handle, fp);
56280fbb751dSJohn Levon break;
56297c478bd9Sstevel@tonic-gate default:
56307c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(cmd->cmd_res_type), Z_NO_RESOURCE_TYPE,
5631bbec428eSgjelinek B_TRUE);
56327c478bd9Sstevel@tonic-gate }
56337c478bd9Sstevel@tonic-gate
56347c478bd9Sstevel@tonic-gate cleanup:
56357c478bd9Sstevel@tonic-gate if (need_to_close)
5636*944b13ecSGary Mills (void) pager_close(fp);
56377c478bd9Sstevel@tonic-gate }
56387c478bd9Sstevel@tonic-gate
5639087719fdSdp /*
5640087719fdSdp * Helper function for verify-- checks that a required string property
5641087719fdSdp * exists.
5642087719fdSdp */
5643087719fdSdp static void
check_reqd_prop(char * attr,int rt,int pt,int * ret_val)5644087719fdSdp check_reqd_prop(char *attr, int rt, int pt, int *ret_val)
56457c478bd9Sstevel@tonic-gate {
5646087719fdSdp if (strlen(attr) == 0) {
5647087719fdSdp zerr(gettext("%s: %s not specified"), rt_to_str(rt),
5648087719fdSdp pt_to_str(pt));
5649bbec428eSgjelinek saw_error = B_TRUE;
5650087719fdSdp if (*ret_val == Z_OK)
5651087719fdSdp *ret_val = Z_REQD_PROPERTY_MISSING;
56527c478bd9Sstevel@tonic-gate }
56537c478bd9Sstevel@tonic-gate }
56547c478bd9Sstevel@tonic-gate
56559acbbeafSnn35248 static int
do_subproc(char * cmdbuf)56569acbbeafSnn35248 do_subproc(char *cmdbuf)
56579acbbeafSnn35248 {
56589acbbeafSnn35248 char inbuf[MAX_CMD_LEN];
56599acbbeafSnn35248 FILE *file;
56609acbbeafSnn35248 int status;
56619acbbeafSnn35248
56629acbbeafSnn35248 file = popen(cmdbuf, "r");
56639acbbeafSnn35248 if (file == NULL) {
56649acbbeafSnn35248 zerr(gettext("Could not launch: %s"), cmdbuf);
56659acbbeafSnn35248 return (-1);
56669acbbeafSnn35248 }
56679acbbeafSnn35248
56689acbbeafSnn35248 while (fgets(inbuf, sizeof (inbuf), file) != NULL)
56699acbbeafSnn35248 fprintf(stderr, "%s", inbuf);
56709acbbeafSnn35248 status = pclose(file);
56719acbbeafSnn35248
56729acbbeafSnn35248 if (WIFSIGNALED(status)) {
56739acbbeafSnn35248 zerr(gettext("%s unexpectedly terminated due to signal %d"),
56749acbbeafSnn35248 cmdbuf, WTERMSIG(status));
56759acbbeafSnn35248 return (-1);
56769acbbeafSnn35248 }
56779acbbeafSnn35248 assert(WIFEXITED(status));
56789acbbeafSnn35248 return (WEXITSTATUS(status));
56799acbbeafSnn35248 }
56809acbbeafSnn35248
56819acbbeafSnn35248 static int
brand_verify(zone_dochandle_t handle)56829acbbeafSnn35248 brand_verify(zone_dochandle_t handle)
56839acbbeafSnn35248 {
56846e65f9afSnn35248 char xml_file[32];
56859acbbeafSnn35248 char cmdbuf[MAX_CMD_LEN];
5686123807fbSedp brand_handle_t bh;
56879acbbeafSnn35248 char brand[MAXNAMELEN];
56889acbbeafSnn35248 int err;
56899acbbeafSnn35248
56909acbbeafSnn35248 if (zonecfg_get_brand(handle, brand, sizeof (brand)) != Z_OK) {
56919acbbeafSnn35248 zerr("%s: %s\n", zone, gettext("could not get zone brand"));
56929acbbeafSnn35248 return (Z_INVALID_DOCUMENT);
56939acbbeafSnn35248 }
5694123807fbSedp if ((bh = brand_open(brand)) == NULL) {
56959acbbeafSnn35248 zerr("%s: %s\n", zone, gettext("unknown brand."));
56969acbbeafSnn35248 return (Z_INVALID_DOCUMENT);
56979acbbeafSnn35248 }
56989acbbeafSnn35248
56999acbbeafSnn35248 /*
57009acbbeafSnn35248 * Fetch the verify command, if any, from the brand configuration
57019acbbeafSnn35248 * and build the command line to execute it.
57029acbbeafSnn35248 */
57039acbbeafSnn35248 strcpy(cmdbuf, EXEC_PREFIX);
5704123807fbSedp err = brand_get_verify_cfg(bh, cmdbuf + EXEC_LEN,
57059acbbeafSnn35248 sizeof (cmdbuf) - (EXEC_LEN + (strlen(xml_file) + 1)));
5706123807fbSedp brand_close(bh);
57079acbbeafSnn35248 if (err != Z_OK) {
57089acbbeafSnn35248 zerr("%s: %s\n", zone,
57099acbbeafSnn35248 gettext("could not get brand verification command"));
57109acbbeafSnn35248 return (Z_INVALID_DOCUMENT);
57119acbbeafSnn35248 }
57129acbbeafSnn35248
57139acbbeafSnn35248 /*
57149acbbeafSnn35248 * If the brand doesn't provide a verification routine, we just
57159acbbeafSnn35248 * return success.
57169acbbeafSnn35248 */
57179acbbeafSnn35248 if (strlen(cmdbuf) == EXEC_LEN)
57189acbbeafSnn35248 return (Z_OK);
57199acbbeafSnn35248
57209acbbeafSnn35248 /*
57219acbbeafSnn35248 * Dump the current config information for this zone to a file.
57229acbbeafSnn35248 */
57236e65f9afSnn35248 strcpy(xml_file, "/tmp/zonecfg_verify.XXXXXX");
57249acbbeafSnn35248 if (mkstemp(xml_file) == NULL)
57259acbbeafSnn35248 return (Z_TEMP_FILE);
57269acbbeafSnn35248 if ((err = zonecfg_verify_save(handle, xml_file)) != Z_OK) {
57279acbbeafSnn35248 (void) unlink(xml_file);
57289acbbeafSnn35248 return (err);
57299acbbeafSnn35248 }
57309acbbeafSnn35248
57319acbbeafSnn35248 /*
57329acbbeafSnn35248 * Execute the verification command.
57339acbbeafSnn35248 */
57349acbbeafSnn35248 if ((strlcat(cmdbuf, " ", MAX_CMD_LEN) >= MAX_CMD_LEN) ||
57359acbbeafSnn35248 (strlcat(cmdbuf, xml_file, MAX_CMD_LEN) >= MAX_CMD_LEN)) {
57369acbbeafSnn35248 err = Z_BRAND_ERROR;
57379acbbeafSnn35248 } else {
57389acbbeafSnn35248 err = do_subproc(cmdbuf);
57399acbbeafSnn35248 }
57409acbbeafSnn35248
57419acbbeafSnn35248 (void) unlink(xml_file);
57429acbbeafSnn35248 return ((err == Z_OK) ? Z_OK : Z_BRAND_ERROR);
57439acbbeafSnn35248 }
57449acbbeafSnn35248
57457c478bd9Sstevel@tonic-gate /*
5746550b6e40SSowmini Varadhan * Track the network interfaces listed in zonecfg(1m) in a linked list
5747550b6e40SSowmini Varadhan * so that we can later check that defrouter is specified for an exclusive IP
5748550b6e40SSowmini Varadhan * zone if and only if at least one allowed-address has been specified.
5749550b6e40SSowmini Varadhan */
5750550b6e40SSowmini Varadhan static boolean_t
add_nwif(struct zone_nwiftab * nwif)5751550b6e40SSowmini Varadhan add_nwif(struct zone_nwiftab *nwif)
5752550b6e40SSowmini Varadhan {
5753550b6e40SSowmini Varadhan struct xif *tmp;
5754550b6e40SSowmini Varadhan
5755550b6e40SSowmini Varadhan for (tmp = xif; tmp != NULL; tmp = tmp->xif_next) {
5756550b6e40SSowmini Varadhan if (strcmp(tmp->xif_name, nwif->zone_nwif_physical) == 0) {
5757550b6e40SSowmini Varadhan if (strlen(nwif->zone_nwif_allowed_address) > 0)
5758550b6e40SSowmini Varadhan tmp->xif_has_address = B_TRUE;
5759550b6e40SSowmini Varadhan if (strlen(nwif->zone_nwif_defrouter) > 0)
5760550b6e40SSowmini Varadhan tmp->xif_has_defrouter = B_TRUE;
5761550b6e40SSowmini Varadhan return (B_TRUE);
5762550b6e40SSowmini Varadhan }
5763550b6e40SSowmini Varadhan }
5764550b6e40SSowmini Varadhan
5765550b6e40SSowmini Varadhan tmp = malloc(sizeof (*tmp));
5766550b6e40SSowmini Varadhan if (tmp == NULL) {
5767550b6e40SSowmini Varadhan zerr(gettext("memory allocation failed for %s"),
5768550b6e40SSowmini Varadhan nwif->zone_nwif_physical);
5769550b6e40SSowmini Varadhan return (B_FALSE);
5770550b6e40SSowmini Varadhan }
5771550b6e40SSowmini Varadhan strlcpy(tmp->xif_name, nwif->zone_nwif_physical,
5772550b6e40SSowmini Varadhan sizeof (tmp->xif_name));
5773550b6e40SSowmini Varadhan tmp->xif_has_defrouter = (strlen(nwif->zone_nwif_defrouter) > 0);
5774550b6e40SSowmini Varadhan tmp->xif_has_address = (strlen(nwif->zone_nwif_allowed_address) > 0);
5775550b6e40SSowmini Varadhan tmp->xif_next = xif;
5776550b6e40SSowmini Varadhan xif = tmp;
5777550b6e40SSowmini Varadhan return (B_TRUE);
5778550b6e40SSowmini Varadhan }
5779550b6e40SSowmini Varadhan
5780550b6e40SSowmini Varadhan /*
57817c478bd9Sstevel@tonic-gate * See the DTD for which attributes are required for which resources.
57827c478bd9Sstevel@tonic-gate *
57837c478bd9Sstevel@tonic-gate * This function can be called by commit_func(), which needs to save things,
57847c478bd9Sstevel@tonic-gate * in addition to the general call from parse_and_run(), which doesn't need
57857c478bd9Sstevel@tonic-gate * things saved. Since the parameters are standardized, we distinguish by
57867c478bd9Sstevel@tonic-gate * having commit_func() call here with cmd->cmd_arg set to "save" to indicate
57877c478bd9Sstevel@tonic-gate * that a save is needed.
57887c478bd9Sstevel@tonic-gate */
57897c478bd9Sstevel@tonic-gate void
verify_func(cmd_t * cmd)57907c478bd9Sstevel@tonic-gate verify_func(cmd_t *cmd)
57917c478bd9Sstevel@tonic-gate {
57927c478bd9Sstevel@tonic-gate struct zone_nwiftab nwiftab;
57937c478bd9Sstevel@tonic-gate struct zone_fstab fstab;
57947c478bd9Sstevel@tonic-gate struct zone_attrtab attrtab;
57957c478bd9Sstevel@tonic-gate struct zone_rctltab rctltab;
5796fa9e4066Sahrens struct zone_dstab dstab;
57970209230bSgjelinek struct zone_psettab psettab;
5798cb8a054bSGlenn Faden struct zone_admintab admintab;
57997c478bd9Sstevel@tonic-gate char zonepath[MAXPATHLEN];
58000209230bSgjelinek char sched[MAXNAMELEN];
58019acbbeafSnn35248 char brand[MAXNAMELEN];
58025679c89fSjv227347 char hostidp[HW_HOSTID_LEN];
58030fbb751dSJohn Levon char fsallowedp[ZONE_FS_ALLOWED_MAX];
5804f93d2c19SAlexander Eremin priv_set_t *privs;
5805f93d2c19SAlexander Eremin char *privname = NULL;
58067c478bd9Sstevel@tonic-gate int err, ret_val = Z_OK, arg;
5807c97ad5cdSakolb int pset_res;
5808bbec428eSgjelinek boolean_t save = B_FALSE;
5809bbec428eSgjelinek boolean_t arg_err = B_FALSE;
5810f4b3ec61Sdh155122 zone_iptype_t iptype;
58110209230bSgjelinek boolean_t has_cpu_shares = B_FALSE;
5812c97ad5cdSakolb boolean_t has_cpu_cap = B_FALSE;
5813550b6e40SSowmini Varadhan struct xif *tmp;
58147c478bd9Sstevel@tonic-gate
58157c478bd9Sstevel@tonic-gate optind = 0;
58167ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) {
58177c478bd9Sstevel@tonic-gate switch (arg) {
58187c478bd9Sstevel@tonic-gate case '?':
58197c478bd9Sstevel@tonic-gate longer_usage(CMD_VERIFY);
5820bbec428eSgjelinek arg_err = B_TRUE;
58217ec75eb8Sgjelinek break;
58227c478bd9Sstevel@tonic-gate default:
58237c478bd9Sstevel@tonic-gate short_usage(CMD_VERIFY);
5824bbec428eSgjelinek arg_err = B_TRUE;
58257ec75eb8Sgjelinek break;
58267ec75eb8Sgjelinek }
58277ec75eb8Sgjelinek }
58287ec75eb8Sgjelinek if (arg_err)
58297c478bd9Sstevel@tonic-gate return;
58307ec75eb8Sgjelinek
58317c478bd9Sstevel@tonic-gate if (optind > cmd->cmd_argc) {
58327c478bd9Sstevel@tonic-gate short_usage(CMD_VERIFY);
58337c478bd9Sstevel@tonic-gate return;
58347c478bd9Sstevel@tonic-gate }
58357c478bd9Sstevel@tonic-gate
58367c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_VERIFY))
58377c478bd9Sstevel@tonic-gate return;
58387c478bd9Sstevel@tonic-gate
58397c478bd9Sstevel@tonic-gate assert(cmd != NULL);
58407c478bd9Sstevel@tonic-gate
58417c478bd9Sstevel@tonic-gate if (cmd->cmd_argc > 0 && (strcmp(cmd->cmd_argv[0], "save") == 0))
5842bbec428eSgjelinek save = B_TRUE;
5843bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK)
58447c478bd9Sstevel@tonic-gate return;
58457c478bd9Sstevel@tonic-gate
58460209230bSgjelinek if (zonecfg_get_zonepath(handle, zonepath, sizeof (zonepath)) != Z_OK &&
58470209230bSgjelinek !global_zone) {
5848087719fdSdp zerr(gettext("%s not specified"), pt_to_str(PT_ZONEPATH));
58497c478bd9Sstevel@tonic-gate ret_val = Z_REQD_RESOURCE_MISSING;
5850bbec428eSgjelinek saw_error = B_TRUE;
58517c478bd9Sstevel@tonic-gate }
58520209230bSgjelinek if (strlen(zonepath) == 0 && !global_zone) {
5853087719fdSdp zerr(gettext("%s cannot be empty."), pt_to_str(PT_ZONEPATH));
58547c478bd9Sstevel@tonic-gate ret_val = Z_REQD_RESOURCE_MISSING;
5855bbec428eSgjelinek saw_error = B_TRUE;
58567c478bd9Sstevel@tonic-gate }
58577c478bd9Sstevel@tonic-gate
58589acbbeafSnn35248 if ((err = zonecfg_get_brand(handle, brand, sizeof (brand))) != Z_OK) {
5859bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
58609acbbeafSnn35248 return;
58619acbbeafSnn35248 }
58629acbbeafSnn35248 if ((err = brand_verify(handle)) != Z_OK) {
5863bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
58649acbbeafSnn35248 return;
58659acbbeafSnn35248 }
58669acbbeafSnn35248
5867f4b3ec61Sdh155122 if (zonecfg_get_iptype(handle, &iptype) != Z_OK) {
5868f4b3ec61Sdh155122 zerr("%s %s", gettext("cannot get"), pt_to_str(PT_IPTYPE));
5869f4b3ec61Sdh155122 ret_val = Z_REQD_RESOURCE_MISSING;
5870bbec428eSgjelinek saw_error = B_TRUE;
5871f4b3ec61Sdh155122 }
58727c478bd9Sstevel@tonic-gate
5873f93d2c19SAlexander Eremin if ((privs = priv_allocset()) == NULL) {
5874f93d2c19SAlexander Eremin zerr(gettext("%s: priv_allocset failed"), zone);
5875f93d2c19SAlexander Eremin return;
5876f93d2c19SAlexander Eremin }
5877f93d2c19SAlexander Eremin if (zonecfg_get_privset(handle, privs, &privname) != Z_OK) {
5878f93d2c19SAlexander Eremin zerr(gettext("%s: invalid privilege: %s"), zone, privname);
5879f93d2c19SAlexander Eremin priv_freeset(privs);
5880f93d2c19SAlexander Eremin free(privname);
5881f93d2c19SAlexander Eremin return;
5882f93d2c19SAlexander Eremin }
5883f93d2c19SAlexander Eremin priv_freeset(privs);
5884f93d2c19SAlexander Eremin
58850fbb751dSJohn Levon if (zonecfg_get_hostid(handle, hostidp,
58860fbb751dSJohn Levon sizeof (hostidp)) == Z_INVALID_PROPERTY) {
58870fbb751dSJohn Levon zerr(gettext("%s: invalid hostid: %s"),
58880fbb751dSJohn Levon zone, hostidp);
58890fbb751dSJohn Levon return;
58900fbb751dSJohn Levon }
58910fbb751dSJohn Levon
58920fbb751dSJohn Levon if (zonecfg_get_fs_allowed(handle, fsallowedp,
58930fbb751dSJohn Levon sizeof (fsallowedp)) == Z_INVALID_PROPERTY) {
58940fbb751dSJohn Levon zerr(gettext("%s: invalid fs-allowed: %s"),
58950fbb751dSJohn Levon zone, fsallowedp);
58965679c89fSjv227347 return;
58975679c89fSjv227347 }
58985679c89fSjv227347
58997c478bd9Sstevel@tonic-gate if ((err = zonecfg_setfsent(handle)) != Z_OK) {
5900bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
59017c478bd9Sstevel@tonic-gate return;
59027c478bd9Sstevel@tonic-gate }
59037c478bd9Sstevel@tonic-gate while (zonecfg_getfsent(handle, &fstab) == Z_OK) {
5904087719fdSdp check_reqd_prop(fstab.zone_fs_dir, RT_FS, PT_DIR, &ret_val);
5905087719fdSdp check_reqd_prop(fstab.zone_fs_special, RT_FS, PT_SPECIAL,
5906087719fdSdp &ret_val);
5907087719fdSdp check_reqd_prop(fstab.zone_fs_type, RT_FS, PT_TYPE, &ret_val);
5908087719fdSdp
59097c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(fstab.zone_fs_options);
59107c478bd9Sstevel@tonic-gate }
59117c478bd9Sstevel@tonic-gate (void) zonecfg_endfsent(handle);
59127c478bd9Sstevel@tonic-gate
59137c478bd9Sstevel@tonic-gate if ((err = zonecfg_setnwifent(handle)) != Z_OK) {
5914bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
59157c478bd9Sstevel@tonic-gate return;
59167c478bd9Sstevel@tonic-gate }
59177c478bd9Sstevel@tonic-gate while (zonecfg_getnwifent(handle, &nwiftab) == Z_OK) {
5918f4b3ec61Sdh155122 /*
5919f4b3ec61Sdh155122 * physical is required in all cases.
5920de860bd9Sgfaden * A shared IP requires an address,
5921de860bd9Sgfaden * and may include a default router, while
5922de860bd9Sgfaden * an exclusive IP must have neither an address
5923de860bd9Sgfaden * nor a default router.
592401b4bc23Sjv227347 * The physical interface name must be valid in all cases.
5925f4b3ec61Sdh155122 */
5926087719fdSdp check_reqd_prop(nwiftab.zone_nwif_physical, RT_NET,
5927087719fdSdp PT_PHYSICAL, &ret_val);
592801b4bc23Sjv227347 if (validate_net_physical_syntax(nwiftab.zone_nwif_physical) !=
592901b4bc23Sjv227347 Z_OK) {
593001b4bc23Sjv227347 saw_error = B_TRUE;
593101b4bc23Sjv227347 if (ret_val == Z_OK)
593201b4bc23Sjv227347 ret_val = Z_INVAL;
593301b4bc23Sjv227347 }
5934f4b3ec61Sdh155122
5935f4b3ec61Sdh155122 switch (iptype) {
5936f4b3ec61Sdh155122 case ZS_SHARED:
5937f4b3ec61Sdh155122 check_reqd_prop(nwiftab.zone_nwif_address, RT_NET,
5938f4b3ec61Sdh155122 PT_ADDRESS, &ret_val);
5939550b6e40SSowmini Varadhan if (strlen(nwiftab.zone_nwif_allowed_address) > 0) {
5940550b6e40SSowmini Varadhan zerr(gettext("%s: %s cannot be specified "
5941550b6e40SSowmini Varadhan "for a shared IP type"),
5942550b6e40SSowmini Varadhan rt_to_str(RT_NET),
5943550b6e40SSowmini Varadhan pt_to_str(PT_ALLOWED_ADDRESS));
5944550b6e40SSowmini Varadhan saw_error = B_TRUE;
5945550b6e40SSowmini Varadhan if (ret_val == Z_OK)
5946550b6e40SSowmini Varadhan ret_val = Z_INVAL;
5947550b6e40SSowmini Varadhan }
5948f4b3ec61Sdh155122 break;
5949f4b3ec61Sdh155122 case ZS_EXCLUSIVE:
5950f4b3ec61Sdh155122 if (strlen(nwiftab.zone_nwif_address) > 0) {
5951f4b3ec61Sdh155122 zerr(gettext("%s: %s cannot be specified "
5952f4b3ec61Sdh155122 "for an exclusive IP type"),
5953f4b3ec61Sdh155122 rt_to_str(RT_NET), pt_to_str(PT_ADDRESS));
5954bbec428eSgjelinek saw_error = B_TRUE;
5955f4b3ec61Sdh155122 if (ret_val == Z_OK)
5956f4b3ec61Sdh155122 ret_val = Z_INVAL;
5957550b6e40SSowmini Varadhan } else {
5958550b6e40SSowmini Varadhan if (!add_nwif(&nwiftab)) {
5959bbec428eSgjelinek saw_error = B_TRUE;
5960de860bd9Sgfaden if (ret_val == Z_OK)
5961de860bd9Sgfaden ret_val = Z_INVAL;
5962de860bd9Sgfaden }
5963550b6e40SSowmini Varadhan }
5964f4b3ec61Sdh155122 break;
5965f4b3ec61Sdh155122 }
59667c478bd9Sstevel@tonic-gate }
5967550b6e40SSowmini Varadhan for (tmp = xif; tmp != NULL; tmp = tmp->xif_next) {
5968550b6e40SSowmini Varadhan if (!tmp->xif_has_address && tmp->xif_has_defrouter) {
5969550b6e40SSowmini Varadhan zerr(gettext("%s: %s for %s cannot be specified "
5970550b6e40SSowmini Varadhan "without %s for an exclusive IP type"),
5971550b6e40SSowmini Varadhan rt_to_str(RT_NET), pt_to_str(PT_DEFROUTER),
5972550b6e40SSowmini Varadhan tmp->xif_name, pt_to_str(PT_ALLOWED_ADDRESS));
5973550b6e40SSowmini Varadhan saw_error = B_TRUE;
5974550b6e40SSowmini Varadhan ret_val = Z_INVAL;
5975550b6e40SSowmini Varadhan }
5976550b6e40SSowmini Varadhan }
5977550b6e40SSowmini Varadhan free(xif);
5978550b6e40SSowmini Varadhan xif = NULL;
59797c478bd9Sstevel@tonic-gate (void) zonecfg_endnwifent(handle);
59807c478bd9Sstevel@tonic-gate
59817c478bd9Sstevel@tonic-gate if ((err = zonecfg_setrctlent(handle)) != Z_OK) {
5982bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
59837c478bd9Sstevel@tonic-gate return;
59847c478bd9Sstevel@tonic-gate }
59857c478bd9Sstevel@tonic-gate while (zonecfg_getrctlent(handle, &rctltab) == Z_OK) {
5986087719fdSdp check_reqd_prop(rctltab.zone_rctl_name, RT_RCTL, PT_NAME,
5987087719fdSdp &ret_val);
5988087719fdSdp
59890209230bSgjelinek if (strcmp(rctltab.zone_rctl_name, "zone.cpu-shares") == 0)
59900209230bSgjelinek has_cpu_shares = B_TRUE;
59910209230bSgjelinek
5992c97ad5cdSakolb if (strcmp(rctltab.zone_rctl_name, "zone.cpu-cap") == 0)
5993c97ad5cdSakolb has_cpu_cap = B_TRUE;
5994c97ad5cdSakolb
59957c478bd9Sstevel@tonic-gate if (rctltab.zone_rctl_valptr == NULL) {
59967c478bd9Sstevel@tonic-gate zerr(gettext("%s: no %s specified"),
59977c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL), pt_to_str(PT_VALUE));
5998bbec428eSgjelinek saw_error = B_TRUE;
59997c478bd9Sstevel@tonic-gate if (ret_val == Z_OK)
60007c478bd9Sstevel@tonic-gate ret_val = Z_REQD_PROPERTY_MISSING;
60017c478bd9Sstevel@tonic-gate } else {
60027c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr);
60037c478bd9Sstevel@tonic-gate }
60047c478bd9Sstevel@tonic-gate }
60057c478bd9Sstevel@tonic-gate (void) zonecfg_endrctlent(handle);
60067c478bd9Sstevel@tonic-gate
6007c97ad5cdSakolb if ((pset_res = zonecfg_lookup_pset(handle, &psettab)) == Z_OK &&
6008c97ad5cdSakolb has_cpu_shares) {
60090209230bSgjelinek zerr(gettext("%s zone.cpu-shares and %s are incompatible."),
60100209230bSgjelinek rt_to_str(RT_RCTL), rt_to_str(RT_DCPU));
6011bbec428eSgjelinek saw_error = B_TRUE;
60120209230bSgjelinek if (ret_val == Z_OK)
60130209230bSgjelinek ret_val = Z_INCOMPATIBLE;
60140209230bSgjelinek }
60150209230bSgjelinek
60160209230bSgjelinek if (has_cpu_shares && zonecfg_get_sched_class(handle, sched,
60170209230bSgjelinek sizeof (sched)) == Z_OK && strlen(sched) > 0 &&
60180209230bSgjelinek strcmp(sched, "FSS") != 0) {
60190209230bSgjelinek zerr(gettext("WARNING: %s zone.cpu-shares and %s=%s are "
60200209230bSgjelinek "incompatible"),
60210209230bSgjelinek rt_to_str(RT_RCTL), rt_to_str(RT_SCHED), sched);
6022bbec428eSgjelinek saw_error = B_TRUE;
60230209230bSgjelinek if (ret_val == Z_OK)
60240209230bSgjelinek ret_val = Z_INCOMPATIBLE;
60250209230bSgjelinek }
60260209230bSgjelinek
6027c97ad5cdSakolb if (pset_res == Z_OK && has_cpu_cap) {
6028c97ad5cdSakolb zerr(gettext("%s zone.cpu-cap and the %s are incompatible."),
6029c97ad5cdSakolb rt_to_str(RT_RCTL), rt_to_str(RT_DCPU));
6030bbec428eSgjelinek saw_error = B_TRUE;
6031c97ad5cdSakolb if (ret_val == Z_OK)
6032c97ad5cdSakolb ret_val = Z_INCOMPATIBLE;
6033c97ad5cdSakolb }
6034c97ad5cdSakolb
60357c478bd9Sstevel@tonic-gate if ((err = zonecfg_setattrent(handle)) != Z_OK) {
6036bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
60377c478bd9Sstevel@tonic-gate return;
60387c478bd9Sstevel@tonic-gate }
60397c478bd9Sstevel@tonic-gate while (zonecfg_getattrent(handle, &attrtab) == Z_OK) {
6040087719fdSdp check_reqd_prop(attrtab.zone_attr_name, RT_ATTR, PT_NAME,
6041087719fdSdp &ret_val);
6042087719fdSdp check_reqd_prop(attrtab.zone_attr_type, RT_ATTR, PT_TYPE,
6043087719fdSdp &ret_val);
6044087719fdSdp check_reqd_prop(attrtab.zone_attr_value, RT_ATTR, PT_VALUE,
6045087719fdSdp &ret_val);
60467c478bd9Sstevel@tonic-gate }
60477c478bd9Sstevel@tonic-gate (void) zonecfg_endattrent(handle);
60487c478bd9Sstevel@tonic-gate
6049fa9e4066Sahrens if ((err = zonecfg_setdsent(handle)) != Z_OK) {
6050bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
6051fa9e4066Sahrens return;
6052fa9e4066Sahrens }
6053fa9e4066Sahrens while (zonecfg_getdsent(handle, &dstab) == Z_OK) {
6054fa9e4066Sahrens if (strlen(dstab.zone_dataset_name) == 0) {
6055fa9e4066Sahrens zerr("%s: %s %s", rt_to_str(RT_DATASET),
6056fa9e4066Sahrens pt_to_str(PT_NAME), gettext("not specified"));
6057bbec428eSgjelinek saw_error = B_TRUE;
6058fa9e4066Sahrens if (ret_val == Z_OK)
6059fa9e4066Sahrens ret_val = Z_REQD_PROPERTY_MISSING;
6060fa9e4066Sahrens } else if (!zfs_name_valid(dstab.zone_dataset_name,
6061fa9e4066Sahrens ZFS_TYPE_FILESYSTEM)) {
6062fa9e4066Sahrens zerr("%s: %s %s", rt_to_str(RT_DATASET),
6063fa9e4066Sahrens pt_to_str(PT_NAME), gettext("invalid"));
6064bbec428eSgjelinek saw_error = B_TRUE;
6065fa9e4066Sahrens if (ret_val == Z_OK)
6066fa9e4066Sahrens ret_val = Z_BAD_PROPERTY;
6067fa9e4066Sahrens }
6068fa9e4066Sahrens
6069fa9e4066Sahrens }
6070fa9e4066Sahrens (void) zonecfg_enddsent(handle);
6071fa9e4066Sahrens
6072cb8a054bSGlenn Faden if ((err = zonecfg_setadminent(handle)) != Z_OK) {
6073cb8a054bSGlenn Faden zone_perror(zone, err, B_TRUE);
6074cb8a054bSGlenn Faden return;
6075cb8a054bSGlenn Faden }
6076cb8a054bSGlenn Faden while (zonecfg_getadminent(handle, &admintab) == Z_OK) {
6077cb8a054bSGlenn Faden check_reqd_prop(admintab.zone_admin_user, RT_ADMIN,
6078cb8a054bSGlenn Faden PT_USER, &ret_val);
6079cb8a054bSGlenn Faden check_reqd_prop(admintab.zone_admin_auths, RT_ADMIN,
6080cb8a054bSGlenn Faden PT_AUTHS, &ret_val);
6081cb8a054bSGlenn Faden if ((ret_val == Z_OK) && (getpwnam(admintab.zone_admin_user)
6082cb8a054bSGlenn Faden == NULL)) {
6083cb8a054bSGlenn Faden zerr(gettext("%s %s is not a valid username"),
6084cb8a054bSGlenn Faden pt_to_str(PT_USER),
6085cb8a054bSGlenn Faden admintab.zone_admin_user);
6086cb8a054bSGlenn Faden ret_val = Z_BAD_PROPERTY;
6087cb8a054bSGlenn Faden }
6088cb8a054bSGlenn Faden if ((ret_val == Z_OK) && (!zonecfg_valid_auths(
6089cb8a054bSGlenn Faden admintab.zone_admin_auths, zone))) {
6090cb8a054bSGlenn Faden ret_val = Z_BAD_PROPERTY;
6091cb8a054bSGlenn Faden }
6092cb8a054bSGlenn Faden }
6093cb8a054bSGlenn Faden (void) zonecfg_endadminent(handle);
6094cb8a054bSGlenn Faden
60957c478bd9Sstevel@tonic-gate if (!global_scope) {
60967c478bd9Sstevel@tonic-gate zerr(gettext("resource specification incomplete"));
6097bbec428eSgjelinek saw_error = B_TRUE;
60987c478bd9Sstevel@tonic-gate if (ret_val == Z_OK)
60997c478bd9Sstevel@tonic-gate ret_val = Z_INSUFFICIENT_SPEC;
61007c478bd9Sstevel@tonic-gate }
61017c478bd9Sstevel@tonic-gate
61027c478bd9Sstevel@tonic-gate if (save) {
6103087719fdSdp if (ret_val == Z_OK) {
6104087719fdSdp if ((ret_val = zonecfg_save(handle)) == Z_OK) {
6105bbec428eSgjelinek need_to_commit = B_FALSE;
6106087719fdSdp (void) strlcpy(revert_zone, zone,
6107087719fdSdp sizeof (revert_zone));
6108087719fdSdp }
6109087719fdSdp } else {
6110087719fdSdp zerr(gettext("Zone %s failed to verify"), zone);
6111087719fdSdp }
61127c478bd9Sstevel@tonic-gate }
61137c478bd9Sstevel@tonic-gate if (ret_val != Z_OK)
6114bbec428eSgjelinek zone_perror(zone, ret_val, B_TRUE);
61157c478bd9Sstevel@tonic-gate }
61167c478bd9Sstevel@tonic-gate
61177c478bd9Sstevel@tonic-gate void
cancel_func(cmd_t * cmd)61187c478bd9Sstevel@tonic-gate cancel_func(cmd_t *cmd)
61197c478bd9Sstevel@tonic-gate {
61207c478bd9Sstevel@tonic-gate int arg;
6121bbec428eSgjelinek boolean_t arg_err = B_FALSE;
61227c478bd9Sstevel@tonic-gate
61237c478bd9Sstevel@tonic-gate assert(cmd != NULL);
61247c478bd9Sstevel@tonic-gate
61257c478bd9Sstevel@tonic-gate optind = 0;
61267ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) {
61277c478bd9Sstevel@tonic-gate switch (arg) {
61287c478bd9Sstevel@tonic-gate case '?':
61297c478bd9Sstevel@tonic-gate longer_usage(CMD_CANCEL);
6130bbec428eSgjelinek arg_err = B_TRUE;
61317ec75eb8Sgjelinek break;
61327c478bd9Sstevel@tonic-gate default:
61337c478bd9Sstevel@tonic-gate short_usage(CMD_CANCEL);
6134bbec428eSgjelinek arg_err = B_TRUE;
61357ec75eb8Sgjelinek break;
61367ec75eb8Sgjelinek }
61377ec75eb8Sgjelinek }
61387ec75eb8Sgjelinek if (arg_err)
61397c478bd9Sstevel@tonic-gate return;
61407ec75eb8Sgjelinek
61417c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) {
61427c478bd9Sstevel@tonic-gate short_usage(CMD_CANCEL);
61437c478bd9Sstevel@tonic-gate return;
61447c478bd9Sstevel@tonic-gate }
61457c478bd9Sstevel@tonic-gate
61467c478bd9Sstevel@tonic-gate if (global_scope)
61477c478bd9Sstevel@tonic-gate scope_usage(CMD_CANCEL);
6148bbec428eSgjelinek global_scope = B_TRUE;
61497c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(in_progress_fstab.zone_fs_options);
61507c478bd9Sstevel@tonic-gate bzero(&in_progress_fstab, sizeof (in_progress_fstab));
61517c478bd9Sstevel@tonic-gate bzero(&in_progress_nwiftab, sizeof (in_progress_nwiftab));
61527c478bd9Sstevel@tonic-gate bzero(&in_progress_devtab, sizeof (in_progress_devtab));
61537c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(in_progress_rctltab.zone_rctl_valptr);
61547c478bd9Sstevel@tonic-gate bzero(&in_progress_rctltab, sizeof (in_progress_rctltab));
61557c478bd9Sstevel@tonic-gate bzero(&in_progress_attrtab, sizeof (in_progress_attrtab));
6156fa9e4066Sahrens bzero(&in_progress_dstab, sizeof (in_progress_dstab));
61577c478bd9Sstevel@tonic-gate }
61587c478bd9Sstevel@tonic-gate
61597c478bd9Sstevel@tonic-gate static int
validate_attr_name(char * name)61607c478bd9Sstevel@tonic-gate validate_attr_name(char *name)
61617c478bd9Sstevel@tonic-gate {
61627c478bd9Sstevel@tonic-gate int i;
61637c478bd9Sstevel@tonic-gate
61647c478bd9Sstevel@tonic-gate if (!isalnum(name[0])) {
61657c478bd9Sstevel@tonic-gate zerr(gettext("Invalid %s %s %s: must start with an alpha-"
61667c478bd9Sstevel@tonic-gate "numeric character."), rt_to_str(RT_ATTR),
61677c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), name);
61687c478bd9Sstevel@tonic-gate return (Z_INVAL);
61697c478bd9Sstevel@tonic-gate }
61707c478bd9Sstevel@tonic-gate for (i = 1; name[i]; i++)
61717c478bd9Sstevel@tonic-gate if (!isalnum(name[i]) && name[i] != '-' && name[i] != '.') {
61727c478bd9Sstevel@tonic-gate zerr(gettext("Invalid %s %s %s: can only contain "
61737c478bd9Sstevel@tonic-gate "alpha-numeric characters, plus '-' and '.'."),
61747c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_NAME), name);
61757c478bd9Sstevel@tonic-gate return (Z_INVAL);
61767c478bd9Sstevel@tonic-gate }
61777c478bd9Sstevel@tonic-gate return (Z_OK);
61787c478bd9Sstevel@tonic-gate }
61797c478bd9Sstevel@tonic-gate
61807c478bd9Sstevel@tonic-gate static int
validate_attr_type_val(struct zone_attrtab * attrtab)61817c478bd9Sstevel@tonic-gate validate_attr_type_val(struct zone_attrtab *attrtab)
61827c478bd9Sstevel@tonic-gate {
61837c478bd9Sstevel@tonic-gate boolean_t boolval;
61847c478bd9Sstevel@tonic-gate int64_t intval;
61857c478bd9Sstevel@tonic-gate char strval[MAXNAMELEN];
61867c478bd9Sstevel@tonic-gate uint64_t uintval;
61877c478bd9Sstevel@tonic-gate
61887c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "boolean") == 0) {
61897c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_boolean(attrtab, &boolval) == Z_OK)
61907c478bd9Sstevel@tonic-gate return (Z_OK);
61917c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"),
61927c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "boolean");
61937c478bd9Sstevel@tonic-gate return (Z_ERR);
61947c478bd9Sstevel@tonic-gate }
61957c478bd9Sstevel@tonic-gate
61967c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "int") == 0) {
61977c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_int(attrtab, &intval) == Z_OK)
61987c478bd9Sstevel@tonic-gate return (Z_OK);
61997c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"),
62007c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "int");
62017c478bd9Sstevel@tonic-gate return (Z_ERR);
62027c478bd9Sstevel@tonic-gate }
62037c478bd9Sstevel@tonic-gate
62047c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "string") == 0) {
62057c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_string(attrtab, strval,
62067c478bd9Sstevel@tonic-gate sizeof (strval)) == Z_OK)
62077c478bd9Sstevel@tonic-gate return (Z_OK);
62087c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"),
62097c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "string");
62107c478bd9Sstevel@tonic-gate return (Z_ERR);
62117c478bd9Sstevel@tonic-gate }
62127c478bd9Sstevel@tonic-gate
62137c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "uint") == 0) {
62147c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_uint(attrtab, &uintval) == Z_OK)
62157c478bd9Sstevel@tonic-gate return (Z_OK);
62167c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"),
62177c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "uint");
62187c478bd9Sstevel@tonic-gate return (Z_ERR);
62197c478bd9Sstevel@tonic-gate }
62207c478bd9Sstevel@tonic-gate
62217c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s %s '%s'"), rt_to_str(RT_ATTR),
62227c478bd9Sstevel@tonic-gate pt_to_str(PT_TYPE), attrtab->zone_attr_type);
62237c478bd9Sstevel@tonic-gate return (Z_ERR);
62247c478bd9Sstevel@tonic-gate }
62257c478bd9Sstevel@tonic-gate
6226087719fdSdp /*
6227087719fdSdp * Helper function for end_func-- checks the existence of a given property
6228087719fdSdp * and emits a message if not specified.
6229087719fdSdp */
6230087719fdSdp static int
end_check_reqd(char * attr,int pt,boolean_t * validation_failed)6231bbec428eSgjelinek end_check_reqd(char *attr, int pt, boolean_t *validation_failed)
6232087719fdSdp {
6233087719fdSdp if (strlen(attr) == 0) {
6234bbec428eSgjelinek *validation_failed = B_TRUE;
6235087719fdSdp zerr(gettext("%s not specified"), pt_to_str(pt));
6236087719fdSdp return (Z_ERR);
6237087719fdSdp }
6238087719fdSdp return (Z_OK);
6239087719fdSdp }
6240087719fdSdp
6241550b6e40SSowmini Varadhan static void
net_exists_error(struct zone_nwiftab nwif)6242550b6e40SSowmini Varadhan net_exists_error(struct zone_nwiftab nwif)
6243550b6e40SSowmini Varadhan {
6244550b6e40SSowmini Varadhan if (strlen(nwif.zone_nwif_address) > 0) {
6245550b6e40SSowmini Varadhan zerr(gettext("A %s resource with the %s '%s', "
6246550b6e40SSowmini Varadhan "and %s '%s' already exists."),
6247550b6e40SSowmini Varadhan rt_to_str(RT_NET),
6248550b6e40SSowmini Varadhan pt_to_str(PT_PHYSICAL),
6249550b6e40SSowmini Varadhan nwif.zone_nwif_physical,
6250550b6e40SSowmini Varadhan pt_to_str(PT_ADDRESS),
6251550b6e40SSowmini Varadhan in_progress_nwiftab.zone_nwif_address);
6252550b6e40SSowmini Varadhan } else {
6253550b6e40SSowmini Varadhan zerr(gettext("A %s resource with the %s '%s', "
6254550b6e40SSowmini Varadhan "and %s '%s' already exists."),
6255550b6e40SSowmini Varadhan rt_to_str(RT_NET),
6256550b6e40SSowmini Varadhan pt_to_str(PT_PHYSICAL),
6257550b6e40SSowmini Varadhan nwif.zone_nwif_physical,
6258550b6e40SSowmini Varadhan pt_to_str(PT_ALLOWED_ADDRESS),
6259550b6e40SSowmini Varadhan nwif.zone_nwif_allowed_address);
6260550b6e40SSowmini Varadhan }
6261550b6e40SSowmini Varadhan }
6262550b6e40SSowmini Varadhan
62637c478bd9Sstevel@tonic-gate void
end_func(cmd_t * cmd)62647c478bd9Sstevel@tonic-gate end_func(cmd_t *cmd)
62657c478bd9Sstevel@tonic-gate {
6266bbec428eSgjelinek boolean_t validation_failed = B_FALSE;
6267bbec428eSgjelinek boolean_t arg_err = B_FALSE;
62687c478bd9Sstevel@tonic-gate struct zone_fstab tmp_fstab;
62697c478bd9Sstevel@tonic-gate struct zone_nwiftab tmp_nwiftab;
62707c478bd9Sstevel@tonic-gate struct zone_devtab tmp_devtab;
62717c478bd9Sstevel@tonic-gate struct zone_rctltab tmp_rctltab;
62727c478bd9Sstevel@tonic-gate struct zone_attrtab tmp_attrtab;
6273fa9e4066Sahrens struct zone_dstab tmp_dstab;
6274cb8a054bSGlenn Faden struct zone_admintab tmp_admintab;
62750209230bSgjelinek int err, arg, res1, res2, res3;
62760209230bSgjelinek uint64_t swap_limit;
62770209230bSgjelinek uint64_t locked_limit;
6278c97ad5cdSakolb uint64_t proc_cap;
62797c478bd9Sstevel@tonic-gate
62807c478bd9Sstevel@tonic-gate assert(cmd != NULL);
62817c478bd9Sstevel@tonic-gate
62827c478bd9Sstevel@tonic-gate optind = 0;
62837ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) {
62847c478bd9Sstevel@tonic-gate switch (arg) {
62857c478bd9Sstevel@tonic-gate case '?':
62867c478bd9Sstevel@tonic-gate longer_usage(CMD_END);
6287bbec428eSgjelinek arg_err = B_TRUE;
62887ec75eb8Sgjelinek break;
62897c478bd9Sstevel@tonic-gate default:
62907c478bd9Sstevel@tonic-gate short_usage(CMD_END);
6291bbec428eSgjelinek arg_err = B_TRUE;
62927ec75eb8Sgjelinek break;
62937ec75eb8Sgjelinek }
62947ec75eb8Sgjelinek }
62957ec75eb8Sgjelinek if (arg_err)
62967c478bd9Sstevel@tonic-gate return;
62977ec75eb8Sgjelinek
62987c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) {
62997c478bd9Sstevel@tonic-gate short_usage(CMD_END);
63007c478bd9Sstevel@tonic-gate return;
63017c478bd9Sstevel@tonic-gate }
63027c478bd9Sstevel@tonic-gate
63037c478bd9Sstevel@tonic-gate if (global_scope) {
63047c478bd9Sstevel@tonic-gate scope_usage(CMD_END);
63057c478bd9Sstevel@tonic-gate return;
63067c478bd9Sstevel@tonic-gate }
63077c478bd9Sstevel@tonic-gate
63087c478bd9Sstevel@tonic-gate assert(end_op == CMD_ADD || end_op == CMD_SELECT);
63097c478bd9Sstevel@tonic-gate
63107c478bd9Sstevel@tonic-gate switch (resource_scope) {
63117c478bd9Sstevel@tonic-gate case RT_FS:
63127c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */
6313087719fdSdp if (end_check_reqd(in_progress_fstab.zone_fs_dir,
6314087719fdSdp PT_DIR, &validation_failed) == Z_OK) {
6315087719fdSdp if (in_progress_fstab.zone_fs_dir[0] != '/') {
6316087719fdSdp zerr(gettext("%s %s is not an absolute path."),
6317087719fdSdp pt_to_str(PT_DIR),
6318087719fdSdp in_progress_fstab.zone_fs_dir);
6319bbec428eSgjelinek validation_failed = B_TRUE;
63207c478bd9Sstevel@tonic-gate }
63217c478bd9Sstevel@tonic-gate }
6322087719fdSdp
6323087719fdSdp (void) end_check_reqd(in_progress_fstab.zone_fs_special,
6324087719fdSdp PT_SPECIAL, &validation_failed);
6325087719fdSdp
63267c478bd9Sstevel@tonic-gate if (in_progress_fstab.zone_fs_raw[0] != '\0' &&
63277c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_raw[0] != '/') {
6328087719fdSdp zerr(gettext("%s %s is not an absolute path."),
6329087719fdSdp pt_to_str(PT_RAW),
6330087719fdSdp in_progress_fstab.zone_fs_raw);
6331bbec428eSgjelinek validation_failed = B_TRUE;
63327c478bd9Sstevel@tonic-gate }
6333087719fdSdp
6334087719fdSdp (void) end_check_reqd(in_progress_fstab.zone_fs_type, PT_TYPE,
6335087719fdSdp &validation_failed);
6336087719fdSdp
6337087719fdSdp if (validation_failed) {
6338bbec428eSgjelinek saw_error = B_TRUE;
63397c478bd9Sstevel@tonic-gate return;
6340087719fdSdp }
6341087719fdSdp
63427c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) {
63437c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */
63447c478bd9Sstevel@tonic-gate bzero(&tmp_fstab, sizeof (tmp_fstab));
63457c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_fstab.zone_fs_dir,
63467c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_dir,
63477c478bd9Sstevel@tonic-gate sizeof (tmp_fstab.zone_fs_dir));
63487c478bd9Sstevel@tonic-gate err = zonecfg_lookup_filesystem(handle, &tmp_fstab);
63497c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(tmp_fstab.zone_fs_options);
63507c478bd9Sstevel@tonic-gate if (err == Z_OK) {
63517c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource "
63527c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."),
63537c478bd9Sstevel@tonic-gate rt_to_str(RT_FS), pt_to_str(PT_DIR),
63547c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_dir);
6355bbec428eSgjelinek saw_error = B_TRUE;
63567c478bd9Sstevel@tonic-gate return;
63577c478bd9Sstevel@tonic-gate }
63587c478bd9Sstevel@tonic-gate err = zonecfg_add_filesystem(handle,
63597c478bd9Sstevel@tonic-gate &in_progress_fstab);
63607c478bd9Sstevel@tonic-gate } else {
63617c478bd9Sstevel@tonic-gate err = zonecfg_modify_filesystem(handle, &old_fstab,
63627c478bd9Sstevel@tonic-gate &in_progress_fstab);
63637c478bd9Sstevel@tonic-gate }
63647c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(in_progress_fstab.zone_fs_options);
63657c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_options = NULL;
63667c478bd9Sstevel@tonic-gate break;
6367087719fdSdp
63687c478bd9Sstevel@tonic-gate case RT_NET:
6369f4b3ec61Sdh155122 /*
6370f4b3ec61Sdh155122 * First make sure everything was filled in.
6371f4b3ec61Sdh155122 * Since we don't know whether IP will be shared
6372f4b3ec61Sdh155122 * or exclusive here, some checks are deferred until
6373f4b3ec61Sdh155122 * the verify command.
6374f4b3ec61Sdh155122 */
6375087719fdSdp (void) end_check_reqd(in_progress_nwiftab.zone_nwif_physical,
6376087719fdSdp PT_PHYSICAL, &validation_failed);
6377087719fdSdp
6378087719fdSdp if (validation_failed) {
6379bbec428eSgjelinek saw_error = B_TRUE;
63807c478bd9Sstevel@tonic-gate return;
6381087719fdSdp }
63827c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) {
63837c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */
63847c478bd9Sstevel@tonic-gate bzero(&tmp_nwiftab, sizeof (tmp_nwiftab));
6385f4b3ec61Sdh155122 (void) strlcpy(tmp_nwiftab.zone_nwif_physical,
6386f4b3ec61Sdh155122 in_progress_nwiftab.zone_nwif_physical,
6387f4b3ec61Sdh155122 sizeof (tmp_nwiftab.zone_nwif_physical));
63887c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_nwiftab.zone_nwif_address,
63897c478bd9Sstevel@tonic-gate in_progress_nwiftab.zone_nwif_address,
63907c478bd9Sstevel@tonic-gate sizeof (tmp_nwiftab.zone_nwif_address));
6391550b6e40SSowmini Varadhan (void) strlcpy(tmp_nwiftab.zone_nwif_allowed_address,
6392550b6e40SSowmini Varadhan in_progress_nwiftab.zone_nwif_allowed_address,
6393550b6e40SSowmini Varadhan sizeof (tmp_nwiftab.zone_nwif_allowed_address));
6394550b6e40SSowmini Varadhan (void) strlcpy(tmp_nwiftab.zone_nwif_defrouter,
6395550b6e40SSowmini Varadhan in_progress_nwiftab.zone_nwif_defrouter,
6396550b6e40SSowmini Varadhan sizeof (tmp_nwiftab.zone_nwif_defrouter));
63977c478bd9Sstevel@tonic-gate if (zonecfg_lookup_nwif(handle, &tmp_nwiftab) == Z_OK) {
6398550b6e40SSowmini Varadhan net_exists_error(in_progress_nwiftab);
6399bbec428eSgjelinek saw_error = B_TRUE;
64007c478bd9Sstevel@tonic-gate return;
64017c478bd9Sstevel@tonic-gate }
64027c478bd9Sstevel@tonic-gate err = zonecfg_add_nwif(handle, &in_progress_nwiftab);
64037c478bd9Sstevel@tonic-gate } else {
64047c478bd9Sstevel@tonic-gate err = zonecfg_modify_nwif(handle, &old_nwiftab,
64057c478bd9Sstevel@tonic-gate &in_progress_nwiftab);
64067c478bd9Sstevel@tonic-gate }
64077c478bd9Sstevel@tonic-gate break;
6408087719fdSdp
64097c478bd9Sstevel@tonic-gate case RT_DEVICE:
64107c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */
6411087719fdSdp (void) end_check_reqd(in_progress_devtab.zone_dev_match,
6412087719fdSdp PT_MATCH, &validation_failed);
6413087719fdSdp
6414087719fdSdp if (validation_failed) {
6415bbec428eSgjelinek saw_error = B_TRUE;
64167c478bd9Sstevel@tonic-gate return;
6417087719fdSdp }
6418087719fdSdp
64197c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) {
64207c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */
64217c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_devtab.zone_dev_match,
64227c478bd9Sstevel@tonic-gate in_progress_devtab.zone_dev_match,
64237c478bd9Sstevel@tonic-gate sizeof (tmp_devtab.zone_dev_match));
64247c478bd9Sstevel@tonic-gate if (zonecfg_lookup_dev(handle, &tmp_devtab) == Z_OK) {
64257c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource with the %s '%s' "
64267c478bd9Sstevel@tonic-gate "already exists."), rt_to_str(RT_DEVICE),
64277c478bd9Sstevel@tonic-gate pt_to_str(PT_MATCH),
64287c478bd9Sstevel@tonic-gate in_progress_devtab.zone_dev_match);
6429bbec428eSgjelinek saw_error = B_TRUE;
64307c478bd9Sstevel@tonic-gate return;
64317c478bd9Sstevel@tonic-gate }
64327c478bd9Sstevel@tonic-gate err = zonecfg_add_dev(handle, &in_progress_devtab);
64337c478bd9Sstevel@tonic-gate } else {
64347c478bd9Sstevel@tonic-gate err = zonecfg_modify_dev(handle, &old_devtab,
64357c478bd9Sstevel@tonic-gate &in_progress_devtab);
64367c478bd9Sstevel@tonic-gate }
64377c478bd9Sstevel@tonic-gate break;
6438087719fdSdp
64397c478bd9Sstevel@tonic-gate case RT_RCTL:
64407c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */
6441087719fdSdp (void) end_check_reqd(in_progress_rctltab.zone_rctl_name,
6442087719fdSdp PT_NAME, &validation_failed);
6443087719fdSdp
64447c478bd9Sstevel@tonic-gate if (in_progress_rctltab.zone_rctl_valptr == NULL) {
64457c478bd9Sstevel@tonic-gate zerr(gettext("no %s specified"), pt_to_str(PT_VALUE));
6446bbec428eSgjelinek validation_failed = B_TRUE;
64477c478bd9Sstevel@tonic-gate }
6448087719fdSdp
6449087719fdSdp if (validation_failed) {
6450bbec428eSgjelinek saw_error = B_TRUE;
64517c478bd9Sstevel@tonic-gate return;
6452087719fdSdp }
6453087719fdSdp
64547c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) {
64557c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */
64567c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_rctltab.zone_rctl_name,
64577c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_name,
64587c478bd9Sstevel@tonic-gate sizeof (tmp_rctltab.zone_rctl_name));
64597c478bd9Sstevel@tonic-gate tmp_rctltab.zone_rctl_valptr = NULL;
64607c478bd9Sstevel@tonic-gate err = zonecfg_lookup_rctl(handle, &tmp_rctltab);
64617c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(
64627c478bd9Sstevel@tonic-gate tmp_rctltab.zone_rctl_valptr);
64637c478bd9Sstevel@tonic-gate if (err == Z_OK) {
64647c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource "
64657c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."),
64667c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL), pt_to_str(PT_NAME),
64677c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_name);
6468bbec428eSgjelinek saw_error = B_TRUE;
64697c478bd9Sstevel@tonic-gate return;
64707c478bd9Sstevel@tonic-gate }
64717c478bd9Sstevel@tonic-gate err = zonecfg_add_rctl(handle, &in_progress_rctltab);
64727c478bd9Sstevel@tonic-gate } else {
64737c478bd9Sstevel@tonic-gate err = zonecfg_modify_rctl(handle, &old_rctltab,
64747c478bd9Sstevel@tonic-gate &in_progress_rctltab);
64757c478bd9Sstevel@tonic-gate }
64767c478bd9Sstevel@tonic-gate if (err == Z_OK) {
64777c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(
64787c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr);
64797c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr = NULL;
64807c478bd9Sstevel@tonic-gate }
64817c478bd9Sstevel@tonic-gate break;
6482087719fdSdp
64837c478bd9Sstevel@tonic-gate case RT_ATTR:
64847c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */
6485087719fdSdp (void) end_check_reqd(in_progress_attrtab.zone_attr_name,
6486087719fdSdp PT_NAME, &validation_failed);
6487087719fdSdp (void) end_check_reqd(in_progress_attrtab.zone_attr_type,
6488087719fdSdp PT_TYPE, &validation_failed);
6489087719fdSdp (void) end_check_reqd(in_progress_attrtab.zone_attr_value,
6490087719fdSdp PT_VALUE, &validation_failed);
6491087719fdSdp
64927c478bd9Sstevel@tonic-gate if (validate_attr_name(in_progress_attrtab.zone_attr_name) !=
6493087719fdSdp Z_OK)
6494bbec428eSgjelinek validation_failed = B_TRUE;
6495087719fdSdp
6496087719fdSdp if (validate_attr_type_val(&in_progress_attrtab) != Z_OK)
6497bbec428eSgjelinek validation_failed = B_TRUE;
6498087719fdSdp
6499087719fdSdp if (validation_failed) {
6500bbec428eSgjelinek saw_error = B_TRUE;
65017c478bd9Sstevel@tonic-gate return;
6502087719fdSdp }
65037c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) {
65047c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */
65057c478bd9Sstevel@tonic-gate bzero(&tmp_attrtab, sizeof (tmp_attrtab));
65067c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_attrtab.zone_attr_name,
65077c478bd9Sstevel@tonic-gate in_progress_attrtab.zone_attr_name,
65087c478bd9Sstevel@tonic-gate sizeof (tmp_attrtab.zone_attr_name));
65097c478bd9Sstevel@tonic-gate if (zonecfg_lookup_attr(handle, &tmp_attrtab) == Z_OK) {
65107c478bd9Sstevel@tonic-gate zerr(gettext("An %s resource "
65117c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."),
65127c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_NAME),
65137c478bd9Sstevel@tonic-gate in_progress_attrtab.zone_attr_name);
6514bbec428eSgjelinek saw_error = B_TRUE;
65157c478bd9Sstevel@tonic-gate return;
65167c478bd9Sstevel@tonic-gate }
65177c478bd9Sstevel@tonic-gate err = zonecfg_add_attr(handle, &in_progress_attrtab);
65187c478bd9Sstevel@tonic-gate } else {
65197c478bd9Sstevel@tonic-gate err = zonecfg_modify_attr(handle, &old_attrtab,
65207c478bd9Sstevel@tonic-gate &in_progress_attrtab);
65217c478bd9Sstevel@tonic-gate }
65227c478bd9Sstevel@tonic-gate break;
6523fa9e4066Sahrens case RT_DATASET:
6524fa9e4066Sahrens /* First make sure everything was filled in. */
6525fa9e4066Sahrens if (strlen(in_progress_dstab.zone_dataset_name) == 0) {
6526fa9e4066Sahrens zerr("%s %s", pt_to_str(PT_NAME),
6527fa9e4066Sahrens gettext("not specified"));
6528bbec428eSgjelinek saw_error = B_TRUE;
6529bbec428eSgjelinek validation_failed = B_TRUE;
6530fa9e4066Sahrens }
6531fa9e4066Sahrens if (validation_failed)
6532fa9e4066Sahrens return;
6533fa9e4066Sahrens if (end_op == CMD_ADD) {
6534fa9e4066Sahrens /* Make sure there isn't already one like this. */
6535fa9e4066Sahrens bzero(&tmp_dstab, sizeof (tmp_dstab));
6536fa9e4066Sahrens (void) strlcpy(tmp_dstab.zone_dataset_name,
6537fa9e4066Sahrens in_progress_dstab.zone_dataset_name,
6538fa9e4066Sahrens sizeof (tmp_dstab.zone_dataset_name));
6539fa9e4066Sahrens err = zonecfg_lookup_ds(handle, &tmp_dstab);
6540fa9e4066Sahrens if (err == Z_OK) {
6541fa9e4066Sahrens zerr(gettext("A %s resource "
6542fa9e4066Sahrens "with the %s '%s' already exists."),
6543fa9e4066Sahrens rt_to_str(RT_DATASET), pt_to_str(PT_NAME),
6544fa9e4066Sahrens in_progress_dstab.zone_dataset_name);
6545bbec428eSgjelinek saw_error = B_TRUE;
6546fa9e4066Sahrens return;
6547fa9e4066Sahrens }
6548fa9e4066Sahrens err = zonecfg_add_ds(handle, &in_progress_dstab);
6549fa9e4066Sahrens } else {
6550fa9e4066Sahrens err = zonecfg_modify_ds(handle, &old_dstab,
6551fa9e4066Sahrens &in_progress_dstab);
6552fa9e4066Sahrens }
6553fa9e4066Sahrens break;
65540209230bSgjelinek case RT_DCPU:
65550209230bSgjelinek /* Make sure everything was filled in. */
65560209230bSgjelinek if (end_check_reqd(in_progress_psettab.zone_ncpu_min,
65570209230bSgjelinek PT_NCPUS, &validation_failed) != Z_OK) {
6558bbec428eSgjelinek saw_error = B_TRUE;
65590209230bSgjelinek return;
65600209230bSgjelinek }
65610209230bSgjelinek
65620209230bSgjelinek if (end_op == CMD_ADD) {
65630209230bSgjelinek err = zonecfg_add_pset(handle, &in_progress_psettab);
65640209230bSgjelinek } else {
65650209230bSgjelinek err = zonecfg_modify_pset(handle, &in_progress_psettab);
65660209230bSgjelinek }
65670209230bSgjelinek break;
6568c97ad5cdSakolb case RT_PCAP:
6569c97ad5cdSakolb /* Make sure everything was filled in. */
6570c97ad5cdSakolb if (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &proc_cap)
6571c97ad5cdSakolb != Z_OK) {
6572c97ad5cdSakolb zerr(gettext("%s not specified"), pt_to_str(PT_NCPUS));
6573bbec428eSgjelinek saw_error = B_TRUE;
6574bbec428eSgjelinek validation_failed = B_TRUE;
6575c97ad5cdSakolb return;
6576c97ad5cdSakolb }
6577c97ad5cdSakolb err = Z_OK;
6578c97ad5cdSakolb break;
65790209230bSgjelinek case RT_MCAP:
65800209230bSgjelinek /* Make sure everything was filled in. */
65810209230bSgjelinek res1 = strlen(in_progress_mcaptab.zone_physmem_cap) == 0 ?
65820209230bSgjelinek Z_ERR : Z_OK;
65830209230bSgjelinek res2 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP,
65840209230bSgjelinek &swap_limit);
65850209230bSgjelinek res3 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM,
65860209230bSgjelinek &locked_limit);
65870209230bSgjelinek
65880209230bSgjelinek if (res1 != Z_OK && res2 != Z_OK && res3 != Z_OK) {
65890209230bSgjelinek zerr(gettext("No property was specified. One of %s, "
65900209230bSgjelinek "%s or %s is required."), pt_to_str(PT_PHYSICAL),
65910209230bSgjelinek pt_to_str(PT_SWAP), pt_to_str(PT_LOCKED));
6592bbec428eSgjelinek saw_error = B_TRUE;
65930209230bSgjelinek return;
65940209230bSgjelinek }
65950209230bSgjelinek
65960209230bSgjelinek /* if phys & locked are both set, verify locked <= phys */
65970209230bSgjelinek if (res1 == Z_OK && res3 == Z_OK) {
65980209230bSgjelinek uint64_t phys_limit;
65990209230bSgjelinek char *endp;
66000209230bSgjelinek
66010209230bSgjelinek phys_limit = strtoull(
66020209230bSgjelinek in_progress_mcaptab.zone_physmem_cap, &endp, 10);
66030209230bSgjelinek if (phys_limit < locked_limit) {
66040209230bSgjelinek zerr(gettext("The %s cap must be less than or "
66050209230bSgjelinek "equal to the %s cap."),
66060209230bSgjelinek pt_to_str(PT_LOCKED),
66070209230bSgjelinek pt_to_str(PT_PHYSICAL));
6608bbec428eSgjelinek saw_error = B_TRUE;
66090209230bSgjelinek return;
66100209230bSgjelinek }
66110209230bSgjelinek }
66120209230bSgjelinek
66130209230bSgjelinek err = Z_OK;
66140209230bSgjelinek if (res1 == Z_OK) {
66150209230bSgjelinek /*
66160209230bSgjelinek * We could be ending from either an add operation
66170209230bSgjelinek * or a select operation. Since all of the properties
66180209230bSgjelinek * within this resource are optional, we always use
66190209230bSgjelinek * modify on the mcap entry. zonecfg_modify_mcap()
66200209230bSgjelinek * will handle both adding and modifying a memory cap.
66210209230bSgjelinek */
66220209230bSgjelinek err = zonecfg_modify_mcap(handle, &in_progress_mcaptab);
66230209230bSgjelinek } else if (end_op == CMD_SELECT) {
66240209230bSgjelinek /*
66250209230bSgjelinek * If we're ending from a select and the physical
66260209230bSgjelinek * memory cap is empty then the user could have cleared
66270209230bSgjelinek * the physical cap value, so try to delete the entry.
66280209230bSgjelinek */
66290209230bSgjelinek (void) zonecfg_delete_mcap(handle);
66300209230bSgjelinek }
66310209230bSgjelinek break;
6632cb8a054bSGlenn Faden case RT_ADMIN:
6633cb8a054bSGlenn Faden /* First make sure everything was filled in. */
6634cb8a054bSGlenn Faden if (end_check_reqd(in_progress_admintab.zone_admin_user,
6635cb8a054bSGlenn Faden PT_USER, &validation_failed) == Z_OK) {
6636cb8a054bSGlenn Faden if (getpwnam(in_progress_admintab.zone_admin_user)
6637cb8a054bSGlenn Faden == NULL) {
6638cb8a054bSGlenn Faden zerr(gettext("%s %s is not a valid username"),
6639cb8a054bSGlenn Faden pt_to_str(PT_USER),
6640cb8a054bSGlenn Faden in_progress_admintab.zone_admin_user);
6641cb8a054bSGlenn Faden validation_failed = B_TRUE;
6642cb8a054bSGlenn Faden }
6643cb8a054bSGlenn Faden }
6644cb8a054bSGlenn Faden
6645cb8a054bSGlenn Faden if (end_check_reqd(in_progress_admintab.zone_admin_auths,
6646cb8a054bSGlenn Faden PT_AUTHS, &validation_failed) == Z_OK) {
6647cb8a054bSGlenn Faden if (!zonecfg_valid_auths(
6648cb8a054bSGlenn Faden in_progress_admintab.zone_admin_auths,
6649cb8a054bSGlenn Faden zone)) {
6650cb8a054bSGlenn Faden validation_failed = B_TRUE;
6651cb8a054bSGlenn Faden }
6652cb8a054bSGlenn Faden }
6653cb8a054bSGlenn Faden
6654cb8a054bSGlenn Faden if (validation_failed) {
6655cb8a054bSGlenn Faden saw_error = B_TRUE;
6656cb8a054bSGlenn Faden return;
6657cb8a054bSGlenn Faden }
6658cb8a054bSGlenn Faden
6659cb8a054bSGlenn Faden if (end_op == CMD_ADD) {
6660cb8a054bSGlenn Faden /* Make sure there isn't already one like this. */
6661cb8a054bSGlenn Faden bzero(&tmp_admintab, sizeof (tmp_admintab));
6662cb8a054bSGlenn Faden (void) strlcpy(tmp_admintab.zone_admin_user,
6663cb8a054bSGlenn Faden in_progress_admintab.zone_admin_user,
6664cb8a054bSGlenn Faden sizeof (tmp_admintab.zone_admin_user));
6665cb8a054bSGlenn Faden err = zonecfg_lookup_admin(
6666cb8a054bSGlenn Faden handle, &tmp_admintab);
6667cb8a054bSGlenn Faden if (err == Z_OK) {
6668cb8a054bSGlenn Faden zerr(gettext("A %s resource "
6669cb8a054bSGlenn Faden "with the %s '%s' already exists."),
6670cb8a054bSGlenn Faden rt_to_str(RT_ADMIN),
6671cb8a054bSGlenn Faden pt_to_str(PT_USER),
6672cb8a054bSGlenn Faden in_progress_admintab.zone_admin_user);
6673cb8a054bSGlenn Faden saw_error = B_TRUE;
6674cb8a054bSGlenn Faden return;
6675cb8a054bSGlenn Faden }
6676cb8a054bSGlenn Faden err = zonecfg_add_admin(handle,
6677cb8a054bSGlenn Faden &in_progress_admintab, zone);
6678cb8a054bSGlenn Faden } else {
6679cb8a054bSGlenn Faden err = zonecfg_modify_admin(handle,
6680cb8a054bSGlenn Faden &old_admintab, &in_progress_admintab,
6681cb8a054bSGlenn Faden zone);
6682cb8a054bSGlenn Faden }
6683cb8a054bSGlenn Faden break;
66847c478bd9Sstevel@tonic-gate default:
66857c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(resource_scope), Z_NO_RESOURCE_TYPE,
6686bbec428eSgjelinek B_TRUE);
6687bbec428eSgjelinek saw_error = B_TRUE;
66887c478bd9Sstevel@tonic-gate return;
66897c478bd9Sstevel@tonic-gate }
66907c478bd9Sstevel@tonic-gate
66917c478bd9Sstevel@tonic-gate if (err != Z_OK) {
6692bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
66937c478bd9Sstevel@tonic-gate } else {
6694bbec428eSgjelinek need_to_commit = B_TRUE;
6695bbec428eSgjelinek global_scope = B_TRUE;
66967c478bd9Sstevel@tonic-gate end_op = -1;
66977c478bd9Sstevel@tonic-gate }
66987c478bd9Sstevel@tonic-gate }
66997c478bd9Sstevel@tonic-gate
67007c478bd9Sstevel@tonic-gate void
commit_func(cmd_t * cmd)67017c478bd9Sstevel@tonic-gate commit_func(cmd_t *cmd)
67027c478bd9Sstevel@tonic-gate {
67037c478bd9Sstevel@tonic-gate int arg;
6704bbec428eSgjelinek boolean_t arg_err = B_FALSE;
67057c478bd9Sstevel@tonic-gate
67067c478bd9Sstevel@tonic-gate optind = 0;
67077ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) {
67087c478bd9Sstevel@tonic-gate switch (arg) {
67097c478bd9Sstevel@tonic-gate case '?':
67107c478bd9Sstevel@tonic-gate longer_usage(CMD_COMMIT);
6711bbec428eSgjelinek arg_err = B_TRUE;
67127ec75eb8Sgjelinek break;
67137c478bd9Sstevel@tonic-gate default:
67147c478bd9Sstevel@tonic-gate short_usage(CMD_COMMIT);
6715bbec428eSgjelinek arg_err = B_TRUE;
67167ec75eb8Sgjelinek break;
67177ec75eb8Sgjelinek }
67187ec75eb8Sgjelinek }
67197ec75eb8Sgjelinek if (arg_err)
67207c478bd9Sstevel@tonic-gate return;
67217ec75eb8Sgjelinek
67227c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) {
67237c478bd9Sstevel@tonic-gate short_usage(CMD_COMMIT);
67247c478bd9Sstevel@tonic-gate return;
67257c478bd9Sstevel@tonic-gate }
67267c478bd9Sstevel@tonic-gate
67277c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_COMMIT))
67287c478bd9Sstevel@tonic-gate return;
67297c478bd9Sstevel@tonic-gate
67307c478bd9Sstevel@tonic-gate assert(cmd != NULL);
67317c478bd9Sstevel@tonic-gate
67327c478bd9Sstevel@tonic-gate cmd->cmd_argc = 1;
67337c478bd9Sstevel@tonic-gate /*
67347c478bd9Sstevel@tonic-gate * cmd_arg normally comes from a strdup() in the lexer, and the
67357c478bd9Sstevel@tonic-gate * whole cmd structure and its (char *) attributes are freed at
67367c478bd9Sstevel@tonic-gate * the completion of each command, so the strdup() below is needed
67377c478bd9Sstevel@tonic-gate * to match this and prevent a core dump from trying to free()
67387c478bd9Sstevel@tonic-gate * something that can't be.
67397c478bd9Sstevel@tonic-gate */
67407c478bd9Sstevel@tonic-gate if ((cmd->cmd_argv[0] = strdup("save")) == NULL) {
6741bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_TRUE);
67427c478bd9Sstevel@tonic-gate exit(Z_ERR);
67437c478bd9Sstevel@tonic-gate }
67447c478bd9Sstevel@tonic-gate cmd->cmd_argv[1] = NULL;
67457c478bd9Sstevel@tonic-gate verify_func(cmd);
67467c478bd9Sstevel@tonic-gate }
67477c478bd9Sstevel@tonic-gate
67487c478bd9Sstevel@tonic-gate void
revert_func(cmd_t * cmd)67497c478bd9Sstevel@tonic-gate revert_func(cmd_t *cmd)
67507c478bd9Sstevel@tonic-gate {
67517c478bd9Sstevel@tonic-gate char line[128]; /* enough to ask a question */
6752bbec428eSgjelinek boolean_t force = B_FALSE;
6753bbec428eSgjelinek boolean_t arg_err = B_FALSE;
67547c478bd9Sstevel@tonic-gate int err, arg, answer;
67557c478bd9Sstevel@tonic-gate
67567c478bd9Sstevel@tonic-gate optind = 0;
67577c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) {
67587c478bd9Sstevel@tonic-gate switch (arg) {
67597c478bd9Sstevel@tonic-gate case '?':
67607c478bd9Sstevel@tonic-gate longer_usage(CMD_REVERT);
6761bbec428eSgjelinek arg_err = B_TRUE;
67627ec75eb8Sgjelinek break;
67637c478bd9Sstevel@tonic-gate case 'F':
6764bbec428eSgjelinek force = B_TRUE;
67657c478bd9Sstevel@tonic-gate break;
67667c478bd9Sstevel@tonic-gate default:
67677c478bd9Sstevel@tonic-gate short_usage(CMD_REVERT);
6768bbec428eSgjelinek arg_err = B_TRUE;
67697ec75eb8Sgjelinek break;
67707ec75eb8Sgjelinek }
67717ec75eb8Sgjelinek }
67727ec75eb8Sgjelinek if (arg_err)
67737c478bd9Sstevel@tonic-gate return;
67747ec75eb8Sgjelinek
67757c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) {
67767c478bd9Sstevel@tonic-gate short_usage(CMD_REVERT);
67777c478bd9Sstevel@tonic-gate return;
67787c478bd9Sstevel@tonic-gate }
67797c478bd9Sstevel@tonic-gate
67807c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_REVERT))
67817c478bd9Sstevel@tonic-gate return;
67827c478bd9Sstevel@tonic-gate
67835b418297Sjv227347 if (!global_scope) {
67845b418297Sjv227347 zerr(gettext("You can only use %s in the global scope.\nUse"
67855b418297Sjv227347 " '%s' to cancel changes to a resource specification."),
67865b418297Sjv227347 cmd_to_str(CMD_REVERT), cmd_to_str(CMD_CANCEL));
67875b418297Sjv227347 saw_error = B_TRUE;
67885b418297Sjv227347 return;
67895b418297Sjv227347 }
67905b418297Sjv227347
67917c478bd9Sstevel@tonic-gate if (zonecfg_check_handle(handle) != Z_OK) {
67927c478bd9Sstevel@tonic-gate zerr(gettext("No changes to revert."));
6793bbec428eSgjelinek saw_error = B_TRUE;
67947c478bd9Sstevel@tonic-gate return;
67957c478bd9Sstevel@tonic-gate }
67967c478bd9Sstevel@tonic-gate
67977c478bd9Sstevel@tonic-gate if (!force) {
67987c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line),
67997c478bd9Sstevel@tonic-gate gettext("Are you sure you want to revert"));
6800bbec428eSgjelinek if ((answer = ask_yesno(B_FALSE, line)) == -1) {
68017c478bd9Sstevel@tonic-gate zerr(gettext("Input not from terminal and -F not "
68027c478bd9Sstevel@tonic-gate "specified:\n%s command ignored, exiting."),
68037c478bd9Sstevel@tonic-gate cmd_to_str(CMD_REVERT));
68047c478bd9Sstevel@tonic-gate exit(Z_ERR);
68057c478bd9Sstevel@tonic-gate }
68067c478bd9Sstevel@tonic-gate if (answer != 1)
68077c478bd9Sstevel@tonic-gate return;
68087c478bd9Sstevel@tonic-gate }
68097c478bd9Sstevel@tonic-gate
68107c478bd9Sstevel@tonic-gate /*
6811cb8a054bSGlenn Faden * Reset any pending admins that were
6812cb8a054bSGlenn Faden * removed from the previous zone
6813cb8a054bSGlenn Faden */
6814cb8a054bSGlenn Faden zonecfg_remove_userauths(handle, "", zone, B_FALSE);
6815cb8a054bSGlenn Faden
6816cb8a054bSGlenn Faden /*
68177c478bd9Sstevel@tonic-gate * Time for a new handle: finish the old one off first
68187c478bd9Sstevel@tonic-gate * then get a new one properly to avoid leaks.
68197c478bd9Sstevel@tonic-gate */
68207c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle);
68217c478bd9Sstevel@tonic-gate if ((handle = zonecfg_init_handle()) == NULL) {
6822bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE);
68237c478bd9Sstevel@tonic-gate exit(Z_ERR);
68247c478bd9Sstevel@tonic-gate }
6825cb8a054bSGlenn Faden
6826087719fdSdp if ((err = zonecfg_get_handle(revert_zone, handle)) != Z_OK) {
6827bbec428eSgjelinek saw_error = B_TRUE;
6828bbec428eSgjelinek got_handle = B_FALSE;
68297c478bd9Sstevel@tonic-gate if (err == Z_NO_ZONE)
68307c478bd9Sstevel@tonic-gate zerr(gettext("%s: no such saved zone to revert to."),
6831087719fdSdp revert_zone);
68327c478bd9Sstevel@tonic-gate else
6833bbec428eSgjelinek zone_perror(zone, err, B_TRUE);
68347c478bd9Sstevel@tonic-gate }
6835087719fdSdp (void) strlcpy(zone, revert_zone, sizeof (zone));
68367c478bd9Sstevel@tonic-gate }
68377c478bd9Sstevel@tonic-gate
68387c478bd9Sstevel@tonic-gate void
help_func(cmd_t * cmd)68397c478bd9Sstevel@tonic-gate help_func(cmd_t *cmd)
68407c478bd9Sstevel@tonic-gate {
68417c478bd9Sstevel@tonic-gate int i;
68427c478bd9Sstevel@tonic-gate
68437c478bd9Sstevel@tonic-gate assert(cmd != NULL);
68447c478bd9Sstevel@tonic-gate
68457c478bd9Sstevel@tonic-gate if (cmd->cmd_argc == 0) {
6846bbec428eSgjelinek usage(B_TRUE, global_scope ? HELP_SUBCMDS : HELP_RES_SCOPE);
68477c478bd9Sstevel@tonic-gate return;
68487c478bd9Sstevel@tonic-gate }
68497c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "usage") == 0) {
6850bbec428eSgjelinek usage(B_TRUE, HELP_USAGE);
68517c478bd9Sstevel@tonic-gate return;
68527c478bd9Sstevel@tonic-gate }
68537c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "commands") == 0) {
6854bbec428eSgjelinek usage(B_TRUE, HELP_SUBCMDS);
68557c478bd9Sstevel@tonic-gate return;
68567c478bd9Sstevel@tonic-gate }
68577c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "syntax") == 0) {
6858bbec428eSgjelinek usage(B_TRUE, HELP_SYNTAX | HELP_RES_PROPS);
68597c478bd9Sstevel@tonic-gate return;
68607c478bd9Sstevel@tonic-gate }
68617c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "-?") == 0) {
68627c478bd9Sstevel@tonic-gate longer_usage(CMD_HELP);
68637c478bd9Sstevel@tonic-gate return;
68647c478bd9Sstevel@tonic-gate }
68657c478bd9Sstevel@tonic-gate
68667c478bd9Sstevel@tonic-gate for (i = 0; i <= CMD_MAX; i++) {
68677c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], cmd_to_str(i)) == 0) {
68687c478bd9Sstevel@tonic-gate longer_usage(i);
68697c478bd9Sstevel@tonic-gate return;
68707c478bd9Sstevel@tonic-gate }
68717c478bd9Sstevel@tonic-gate }
68727c478bd9Sstevel@tonic-gate /* We do not use zerr() here because we do not want its extra \n. */
68737c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Unknown help subject %s. "),
68747c478bd9Sstevel@tonic-gate cmd->cmd_argv[0]);
6875bbec428eSgjelinek usage(B_FALSE, HELP_META);
68767c478bd9Sstevel@tonic-gate }
68777c478bd9Sstevel@tonic-gate
68787c478bd9Sstevel@tonic-gate static int
string_to_yyin(char * string)68797c478bd9Sstevel@tonic-gate string_to_yyin(char *string)
68807c478bd9Sstevel@tonic-gate {
68817c478bd9Sstevel@tonic-gate if ((yyin = tmpfile()) == NULL) {
6882bbec428eSgjelinek zone_perror(execname, Z_TEMP_FILE, B_TRUE);
68837c478bd9Sstevel@tonic-gate return (Z_ERR);
68847c478bd9Sstevel@tonic-gate }
68857c478bd9Sstevel@tonic-gate if (fwrite(string, strlen(string), 1, yyin) != 1) {
6886bbec428eSgjelinek zone_perror(execname, Z_TEMP_FILE, B_TRUE);
68877c478bd9Sstevel@tonic-gate return (Z_ERR);
68887c478bd9Sstevel@tonic-gate }
68897c478bd9Sstevel@tonic-gate if (fseek(yyin, 0, SEEK_SET) != 0) {
6890bbec428eSgjelinek zone_perror(execname, Z_TEMP_FILE, B_TRUE);
68917c478bd9Sstevel@tonic-gate return (Z_ERR);
68927c478bd9Sstevel@tonic-gate }
68937c478bd9Sstevel@tonic-gate return (Z_OK);
68947c478bd9Sstevel@tonic-gate }
68957c478bd9Sstevel@tonic-gate
68967c478bd9Sstevel@tonic-gate /* This is the back-end helper function for read_input() below. */
68977c478bd9Sstevel@tonic-gate
68987c478bd9Sstevel@tonic-gate static int
cleanup()68997c478bd9Sstevel@tonic-gate cleanup()
69007c478bd9Sstevel@tonic-gate {
69017c478bd9Sstevel@tonic-gate int answer;
69027c478bd9Sstevel@tonic-gate cmd_t *cmd;
69037c478bd9Sstevel@tonic-gate
69047c478bd9Sstevel@tonic-gate if (!interactive_mode && !cmd_file_mode) {
69057c478bd9Sstevel@tonic-gate /*
69067c478bd9Sstevel@tonic-gate * If we're not in interactive mode, and we're not in command
69077c478bd9Sstevel@tonic-gate * file mode, then we must be in commands-from-the-command-line
69087c478bd9Sstevel@tonic-gate * mode. As such, we can't loop back and ask for more input.
69097c478bd9Sstevel@tonic-gate * It was OK to prompt for such things as whether or not to
69107c478bd9Sstevel@tonic-gate * really delete a zone in the command handler called from
69117c478bd9Sstevel@tonic-gate * yyparse() above, but "really quit?" makes no sense in this
69127c478bd9Sstevel@tonic-gate * context. So disable prompting.
69137c478bd9Sstevel@tonic-gate */
6914bbec428eSgjelinek ok_to_prompt = B_FALSE;
69157c478bd9Sstevel@tonic-gate }
69167c478bd9Sstevel@tonic-gate if (!global_scope) {
69177c478bd9Sstevel@tonic-gate if (!time_to_exit) {
69187c478bd9Sstevel@tonic-gate /*
69197c478bd9Sstevel@tonic-gate * Just print a simple error message in the -1 case,
69207c478bd9Sstevel@tonic-gate * since exit_func() already handles that case, and
69217c478bd9Sstevel@tonic-gate * EOF means we are finished anyway.
69227c478bd9Sstevel@tonic-gate */
6923bbec428eSgjelinek answer = ask_yesno(B_FALSE,
69247c478bd9Sstevel@tonic-gate gettext("Resource incomplete; really quit"));
69257c478bd9Sstevel@tonic-gate if (answer == -1) {
69267c478bd9Sstevel@tonic-gate zerr(gettext("Resource incomplete."));
69277c478bd9Sstevel@tonic-gate return (Z_ERR);
69287c478bd9Sstevel@tonic-gate }
69297c478bd9Sstevel@tonic-gate if (answer != 1) {
69307c478bd9Sstevel@tonic-gate yyin = stdin;
69317c478bd9Sstevel@tonic-gate return (Z_REPEAT);
69327c478bd9Sstevel@tonic-gate }
69337c478bd9Sstevel@tonic-gate } else {
6934bbec428eSgjelinek saw_error = B_TRUE;
69357c478bd9Sstevel@tonic-gate }
69367c478bd9Sstevel@tonic-gate }
69377c478bd9Sstevel@tonic-gate /*
69387c478bd9Sstevel@tonic-gate * Make sure we tried something and that the handle checks
69397c478bd9Sstevel@tonic-gate * out, or we would get a false error trying to commit.
69407c478bd9Sstevel@tonic-gate */
69417c478bd9Sstevel@tonic-gate if (need_to_commit && zonecfg_check_handle(handle) == Z_OK) {
69427c478bd9Sstevel@tonic-gate if ((cmd = alloc_cmd()) == NULL) {
6943bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_TRUE);
69447c478bd9Sstevel@tonic-gate return (Z_ERR);
69457c478bd9Sstevel@tonic-gate }
69467c478bd9Sstevel@tonic-gate cmd->cmd_argc = 0;
69477c478bd9Sstevel@tonic-gate cmd->cmd_argv[0] = NULL;
69487c478bd9Sstevel@tonic-gate commit_func(cmd);
69497c478bd9Sstevel@tonic-gate free_cmd(cmd);
69507c478bd9Sstevel@tonic-gate /*
69517c478bd9Sstevel@tonic-gate * need_to_commit will get set back to FALSE if the
69527c478bd9Sstevel@tonic-gate * configuration is saved successfully.
69537c478bd9Sstevel@tonic-gate */
69547c478bd9Sstevel@tonic-gate if (need_to_commit) {
69557c478bd9Sstevel@tonic-gate if (force_exit) {
69567c478bd9Sstevel@tonic-gate zerr(gettext("Configuration not saved."));
69577c478bd9Sstevel@tonic-gate return (Z_ERR);
69587c478bd9Sstevel@tonic-gate }
6959bbec428eSgjelinek answer = ask_yesno(B_FALSE,
69607c478bd9Sstevel@tonic-gate gettext("Configuration not saved; really quit"));
69617c478bd9Sstevel@tonic-gate if (answer == -1) {
69627c478bd9Sstevel@tonic-gate zerr(gettext("Configuration not saved."));
69637c478bd9Sstevel@tonic-gate return (Z_ERR);
69647c478bd9Sstevel@tonic-gate }
69657c478bd9Sstevel@tonic-gate if (answer != 1) {
6966bbec428eSgjelinek time_to_exit = B_FALSE;
69677c478bd9Sstevel@tonic-gate yyin = stdin;
69687c478bd9Sstevel@tonic-gate return (Z_REPEAT);
69697c478bd9Sstevel@tonic-gate }
69707c478bd9Sstevel@tonic-gate }
69717c478bd9Sstevel@tonic-gate }
69727c478bd9Sstevel@tonic-gate return ((need_to_commit || saw_error) ? Z_ERR : Z_OK);
69737c478bd9Sstevel@tonic-gate }
69747c478bd9Sstevel@tonic-gate
69757c478bd9Sstevel@tonic-gate /*
69767c478bd9Sstevel@tonic-gate * read_input() is the driver of this program. It is a wrapper around
69777c478bd9Sstevel@tonic-gate * yyparse(), printing appropriate prompts when needed, checking for
69787c478bd9Sstevel@tonic-gate * exit conditions and reacting appropriately [the latter in its cleanup()
69797c478bd9Sstevel@tonic-gate * helper function].
69807c478bd9Sstevel@tonic-gate *
69817c478bd9Sstevel@tonic-gate * Like most zonecfg functions, it returns Z_OK or Z_ERR, *or* Z_REPEAT
69827c478bd9Sstevel@tonic-gate * so do_interactive() knows that we are not really done (i.e, we asked
69837c478bd9Sstevel@tonic-gate * the user if we should really quit and the user said no).
69847c478bd9Sstevel@tonic-gate */
69857c478bd9Sstevel@tonic-gate static int
read_input()69867c478bd9Sstevel@tonic-gate read_input()
69877c478bd9Sstevel@tonic-gate {
6988bbec428eSgjelinek boolean_t yyin_is_a_tty = isatty(fileno(yyin));
69897c478bd9Sstevel@tonic-gate /*
69907c478bd9Sstevel@tonic-gate * The prompt is "e:z> " or "e:z:r> " where e is execname, z is zone
69917c478bd9Sstevel@tonic-gate * and r is resource_scope: 5 is for the two ":"s + "> " + terminator.
69927c478bd9Sstevel@tonic-gate */
69937c478bd9Sstevel@tonic-gate char prompt[MAXPATHLEN + ZONENAME_MAX + MAX_RT_STRLEN + 5], *line;
69947c478bd9Sstevel@tonic-gate
69957c478bd9Sstevel@tonic-gate /* yyin should have been set to the appropriate (FILE *) if not stdin */
6996bbec428eSgjelinek newline_terminated = B_TRUE;
69977c478bd9Sstevel@tonic-gate for (;;) {
69987c478bd9Sstevel@tonic-gate if (yyin_is_a_tty) {
69997c478bd9Sstevel@tonic-gate if (newline_terminated) {
70007c478bd9Sstevel@tonic-gate if (global_scope)
70017c478bd9Sstevel@tonic-gate (void) snprintf(prompt, sizeof (prompt),
70027c478bd9Sstevel@tonic-gate "%s:%s> ", execname, zone);
70037c478bd9Sstevel@tonic-gate else
70047c478bd9Sstevel@tonic-gate (void) snprintf(prompt, sizeof (prompt),
70057c478bd9Sstevel@tonic-gate "%s:%s:%s> ", execname, zone,
70067c478bd9Sstevel@tonic-gate rt_to_str(resource_scope));
70077c478bd9Sstevel@tonic-gate }
70087c478bd9Sstevel@tonic-gate /*
70097c478bd9Sstevel@tonic-gate * If the user hits ^C then we want to catch it and
70107c478bd9Sstevel@tonic-gate * start over. If the user hits EOF then we want to
70117c478bd9Sstevel@tonic-gate * bail out.
70127c478bd9Sstevel@tonic-gate */
70137c478bd9Sstevel@tonic-gate line = gl_get_line(gl, prompt, NULL, -1);
70147c478bd9Sstevel@tonic-gate if (gl_return_status(gl) == GLR_SIGNAL) {
70157c478bd9Sstevel@tonic-gate gl_abandon_line(gl);
70167c478bd9Sstevel@tonic-gate continue;
70177c478bd9Sstevel@tonic-gate }
70187c478bd9Sstevel@tonic-gate if (line == NULL)
70197c478bd9Sstevel@tonic-gate break;
70207c478bd9Sstevel@tonic-gate (void) string_to_yyin(line);
70217c478bd9Sstevel@tonic-gate while (!feof(yyin))
70227c478bd9Sstevel@tonic-gate yyparse();
70237c478bd9Sstevel@tonic-gate } else {
70247c478bd9Sstevel@tonic-gate yyparse();
70257c478bd9Sstevel@tonic-gate }
70267c478bd9Sstevel@tonic-gate /* Bail out on an error in command file mode. */
70277c478bd9Sstevel@tonic-gate if (saw_error && cmd_file_mode && !interactive_mode)
7028bbec428eSgjelinek time_to_exit = B_TRUE;
70297c478bd9Sstevel@tonic-gate if (time_to_exit || (!yyin_is_a_tty && feof(yyin)))
70307c478bd9Sstevel@tonic-gate break;
70317c478bd9Sstevel@tonic-gate }
70327c478bd9Sstevel@tonic-gate return (cleanup());
70337c478bd9Sstevel@tonic-gate }
70347c478bd9Sstevel@tonic-gate
70357c478bd9Sstevel@tonic-gate /*
70367c478bd9Sstevel@tonic-gate * This function is used in the zonecfg-interactive-mode scenario: it just
70377c478bd9Sstevel@tonic-gate * calls read_input() until we are done.
70387c478bd9Sstevel@tonic-gate */
70397c478bd9Sstevel@tonic-gate
70407c478bd9Sstevel@tonic-gate static int
do_interactive(void)70417c478bd9Sstevel@tonic-gate do_interactive(void)
70427c478bd9Sstevel@tonic-gate {
70437c478bd9Sstevel@tonic-gate int err;
70447c478bd9Sstevel@tonic-gate
7045bbec428eSgjelinek interactive_mode = B_TRUE;
70467c478bd9Sstevel@tonic-gate if (!read_only_mode) {
70477c478bd9Sstevel@tonic-gate /*
70487c478bd9Sstevel@tonic-gate * Try to set things up proactively in interactive mode, so
70497c478bd9Sstevel@tonic-gate * that if the zone in question does not exist yet, we can
70507c478bd9Sstevel@tonic-gate * provide the user with a clue.
70517c478bd9Sstevel@tonic-gate */
7052bbec428eSgjelinek (void) initialize(B_FALSE);
70537c478bd9Sstevel@tonic-gate }
7054087719fdSdp do {
70557c478bd9Sstevel@tonic-gate err = read_input();
7056087719fdSdp } while (err == Z_REPEAT);
70577c478bd9Sstevel@tonic-gate return (err);
70587c478bd9Sstevel@tonic-gate }
70597c478bd9Sstevel@tonic-gate
70607c478bd9Sstevel@tonic-gate /*
70617c478bd9Sstevel@tonic-gate * cmd_file is slightly more complicated, as it has to open the command file
70627c478bd9Sstevel@tonic-gate * and set yyin appropriately. Once that is done, though, it just calls
70637c478bd9Sstevel@tonic-gate * read_input(), and only once, since prompting is not possible.
70647c478bd9Sstevel@tonic-gate */
70657c478bd9Sstevel@tonic-gate
70667c478bd9Sstevel@tonic-gate static int
cmd_file(char * file)70677c478bd9Sstevel@tonic-gate cmd_file(char *file)
70687c478bd9Sstevel@tonic-gate {
70697c478bd9Sstevel@tonic-gate FILE *infile;
70707c478bd9Sstevel@tonic-gate int err;
70717c478bd9Sstevel@tonic-gate struct stat statbuf;
7072bbec428eSgjelinek boolean_t using_real_file = (strcmp(file, "-") != 0);
70737c478bd9Sstevel@tonic-gate
70747c478bd9Sstevel@tonic-gate if (using_real_file) {
70757c478bd9Sstevel@tonic-gate /*
70767c478bd9Sstevel@tonic-gate * zerr() prints a line number in cmd_file_mode, which we do
70777c478bd9Sstevel@tonic-gate * not want here, so temporarily unset it.
70787c478bd9Sstevel@tonic-gate */
7079bbec428eSgjelinek cmd_file_mode = B_FALSE;
70807c478bd9Sstevel@tonic-gate if ((infile = fopen(file, "r")) == NULL) {
70817c478bd9Sstevel@tonic-gate zerr(gettext("could not open file %s: %s"),
70827c478bd9Sstevel@tonic-gate file, strerror(errno));
70837c478bd9Sstevel@tonic-gate return (Z_ERR);
70847c478bd9Sstevel@tonic-gate }
70857c478bd9Sstevel@tonic-gate if ((err = fstat(fileno(infile), &statbuf)) != 0) {
70867c478bd9Sstevel@tonic-gate zerr(gettext("could not stat file %s: %s"),
70877c478bd9Sstevel@tonic-gate file, strerror(errno));
70887c478bd9Sstevel@tonic-gate err = Z_ERR;
70897c478bd9Sstevel@tonic-gate goto done;
70907c478bd9Sstevel@tonic-gate }
70917c478bd9Sstevel@tonic-gate if (!S_ISREG(statbuf.st_mode)) {
70927c478bd9Sstevel@tonic-gate zerr(gettext("%s is not a regular file."), file);
70937c478bd9Sstevel@tonic-gate err = Z_ERR;
70947c478bd9Sstevel@tonic-gate goto done;
70957c478bd9Sstevel@tonic-gate }
70967c478bd9Sstevel@tonic-gate yyin = infile;
7097bbec428eSgjelinek cmd_file_mode = B_TRUE;
7098bbec428eSgjelinek ok_to_prompt = B_FALSE;
70997c478bd9Sstevel@tonic-gate } else {
71007c478bd9Sstevel@tonic-gate /*
71017c478bd9Sstevel@tonic-gate * "-f -" is essentially the same as interactive mode,
71027c478bd9Sstevel@tonic-gate * so treat it that way.
71037c478bd9Sstevel@tonic-gate */
7104bbec428eSgjelinek interactive_mode = B_TRUE;
71057c478bd9Sstevel@tonic-gate }
71067c478bd9Sstevel@tonic-gate /* Z_REPEAT is for interactive mode; treat it like Z_ERR here. */
71077c478bd9Sstevel@tonic-gate if ((err = read_input()) == Z_REPEAT)
71087c478bd9Sstevel@tonic-gate err = Z_ERR;
71097c478bd9Sstevel@tonic-gate done:
71107c478bd9Sstevel@tonic-gate if (using_real_file)
71117c478bd9Sstevel@tonic-gate (void) fclose(infile);
71127c478bd9Sstevel@tonic-gate return (err);
71137c478bd9Sstevel@tonic-gate }
71147c478bd9Sstevel@tonic-gate
71157c478bd9Sstevel@tonic-gate /*
71167c478bd9Sstevel@tonic-gate * Since yacc is based on reading from a (FILE *) whereas what we get from
71177c478bd9Sstevel@tonic-gate * the command line is in argv format, we need to convert when the user
71187c478bd9Sstevel@tonic-gate * gives us commands directly from the command line. That is done here by
71197c478bd9Sstevel@tonic-gate * concatenating the argv list into a space-separated string, writing it
71207c478bd9Sstevel@tonic-gate * to a temp file, and rewinding the file so yyin can be set to it. Then
71217c478bd9Sstevel@tonic-gate * we call read_input(), and only once, since prompting about whether to
71227c478bd9Sstevel@tonic-gate * continue or quit would make no sense in this context.
71237c478bd9Sstevel@tonic-gate */
71247c478bd9Sstevel@tonic-gate
71257c478bd9Sstevel@tonic-gate static int
one_command_at_a_time(int argc,char * argv[])71267c478bd9Sstevel@tonic-gate one_command_at_a_time(int argc, char *argv[])
71277c478bd9Sstevel@tonic-gate {
71287c478bd9Sstevel@tonic-gate char *command;
71297c478bd9Sstevel@tonic-gate size_t len = 2; /* terminal \n\0 */
71307c478bd9Sstevel@tonic-gate int i, err;
71317c478bd9Sstevel@tonic-gate
71327c478bd9Sstevel@tonic-gate for (i = 0; i < argc; i++)
71337c478bd9Sstevel@tonic-gate len += strlen(argv[i]) + 1;
71347c478bd9Sstevel@tonic-gate if ((command = malloc(len)) == NULL) {
7135bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE);
71367c478bd9Sstevel@tonic-gate return (Z_ERR);
71377c478bd9Sstevel@tonic-gate }
71387c478bd9Sstevel@tonic-gate (void) strlcpy(command, argv[0], len);
71397c478bd9Sstevel@tonic-gate for (i = 1; i < argc; i++) {
71407c478bd9Sstevel@tonic-gate (void) strlcat(command, " ", len);
71417c478bd9Sstevel@tonic-gate (void) strlcat(command, argv[i], len);
71427c478bd9Sstevel@tonic-gate }
71437c478bd9Sstevel@tonic-gate (void) strlcat(command, "\n", len);
71447c478bd9Sstevel@tonic-gate err = string_to_yyin(command);
71457c478bd9Sstevel@tonic-gate free(command);
71467c478bd9Sstevel@tonic-gate if (err != Z_OK)
71477c478bd9Sstevel@tonic-gate return (err);
71487c478bd9Sstevel@tonic-gate while (!feof(yyin))
71497c478bd9Sstevel@tonic-gate yyparse();
71507c478bd9Sstevel@tonic-gate return (cleanup());
71517c478bd9Sstevel@tonic-gate }
71527c478bd9Sstevel@tonic-gate
71537c478bd9Sstevel@tonic-gate static char *
get_execbasename(char * execfullname)71547c478bd9Sstevel@tonic-gate get_execbasename(char *execfullname)
71557c478bd9Sstevel@tonic-gate {
71567c478bd9Sstevel@tonic-gate char *last_slash, *execbasename;
71577c478bd9Sstevel@tonic-gate
71587c478bd9Sstevel@tonic-gate /* guard against '/' at end of command invocation */
71597c478bd9Sstevel@tonic-gate for (;;) {
71607c478bd9Sstevel@tonic-gate last_slash = strrchr(execfullname, '/');
71617c478bd9Sstevel@tonic-gate if (last_slash == NULL) {
71627c478bd9Sstevel@tonic-gate execbasename = execfullname;
71637c478bd9Sstevel@tonic-gate break;
71647c478bd9Sstevel@tonic-gate } else {
71657c478bd9Sstevel@tonic-gate execbasename = last_slash + 1;
71667c478bd9Sstevel@tonic-gate if (*execbasename == '\0') {
71677c478bd9Sstevel@tonic-gate *last_slash = '\0';
71687c478bd9Sstevel@tonic-gate continue;
71697c478bd9Sstevel@tonic-gate }
71707c478bd9Sstevel@tonic-gate break;
71717c478bd9Sstevel@tonic-gate }
71727c478bd9Sstevel@tonic-gate }
71737c478bd9Sstevel@tonic-gate return (execbasename);
71747c478bd9Sstevel@tonic-gate }
71757c478bd9Sstevel@tonic-gate
71767c478bd9Sstevel@tonic-gate int
main(int argc,char * argv[])71777c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
71787c478bd9Sstevel@tonic-gate {
71797c478bd9Sstevel@tonic-gate int err, arg;
7180555afedfScarlsonj struct stat st;
71817c478bd9Sstevel@tonic-gate
71827c478bd9Sstevel@tonic-gate /* This must be before anything goes to stdout. */
71837c478bd9Sstevel@tonic-gate setbuf(stdout, NULL);
71847c478bd9Sstevel@tonic-gate
7185bbec428eSgjelinek saw_error = B_FALSE;
7186bbec428eSgjelinek cmd_file_mode = B_FALSE;
71877c478bd9Sstevel@tonic-gate execname = get_execbasename(argv[0]);
71887c478bd9Sstevel@tonic-gate
71897c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
71907c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
71917c478bd9Sstevel@tonic-gate
71927c478bd9Sstevel@tonic-gate if (getzoneid() != GLOBAL_ZONEID) {
71937c478bd9Sstevel@tonic-gate zerr(gettext("%s can only be run from the global zone."),
71947c478bd9Sstevel@tonic-gate execname);
71957c478bd9Sstevel@tonic-gate exit(Z_ERR);
71967c478bd9Sstevel@tonic-gate }
71977c478bd9Sstevel@tonic-gate
71987c478bd9Sstevel@tonic-gate if (argc < 2) {
7199bbec428eSgjelinek usage(B_FALSE, HELP_USAGE | HELP_SUBCMDS);
72007c478bd9Sstevel@tonic-gate exit(Z_USAGE);
72017c478bd9Sstevel@tonic-gate }
72027c478bd9Sstevel@tonic-gate if (strcmp(argv[1], cmd_to_str(CMD_HELP)) == 0) {
72037c478bd9Sstevel@tonic-gate (void) one_command_at_a_time(argc - 1, &(argv[1]));
72047c478bd9Sstevel@tonic-gate exit(Z_OK);
72057c478bd9Sstevel@tonic-gate }
72067c478bd9Sstevel@tonic-gate
7207555afedfScarlsonj while ((arg = getopt(argc, argv, "?f:R:z:")) != EOF) {
72087c478bd9Sstevel@tonic-gate switch (arg) {
72097c478bd9Sstevel@tonic-gate case '?':
72107c478bd9Sstevel@tonic-gate if (optopt == '?')
7211bbec428eSgjelinek usage(B_TRUE, HELP_USAGE | HELP_SUBCMDS);
72127c478bd9Sstevel@tonic-gate else
7213bbec428eSgjelinek usage(B_FALSE, HELP_USAGE);
72147c478bd9Sstevel@tonic-gate exit(Z_USAGE);
72157c478bd9Sstevel@tonic-gate /* NOTREACHED */
72167c478bd9Sstevel@tonic-gate case 'f':
72177c478bd9Sstevel@tonic-gate cmd_file_name = optarg;
7218bbec428eSgjelinek cmd_file_mode = B_TRUE;
72197c478bd9Sstevel@tonic-gate break;
7220555afedfScarlsonj case 'R':
7221555afedfScarlsonj if (*optarg != '/') {
7222555afedfScarlsonj zerr(gettext("root path must be absolute: %s"),
7223555afedfScarlsonj optarg);
7224555afedfScarlsonj exit(Z_USAGE);
7225555afedfScarlsonj }
7226555afedfScarlsonj if (stat(optarg, &st) == -1 || !S_ISDIR(st.st_mode)) {
7227555afedfScarlsonj zerr(gettext(
7228555afedfScarlsonj "root path must be a directory: %s"),
7229555afedfScarlsonj optarg);
7230555afedfScarlsonj exit(Z_USAGE);
7231555afedfScarlsonj }
7232555afedfScarlsonj zonecfg_set_root(optarg);
7233555afedfScarlsonj break;
72347c478bd9Sstevel@tonic-gate case 'z':
72350209230bSgjelinek if (strcmp(optarg, GLOBAL_ZONENAME) == 0) {
7236bbec428eSgjelinek global_zone = B_TRUE;
72370209230bSgjelinek } else if (zonecfg_validate_zonename(optarg) != Z_OK) {
7238bbec428eSgjelinek zone_perror(optarg, Z_BOGUS_ZONE_NAME, B_TRUE);
7239bbec428eSgjelinek usage(B_FALSE, HELP_SYNTAX);
7240087719fdSdp exit(Z_USAGE);
7241087719fdSdp }
7242087719fdSdp (void) strlcpy(zone, optarg, sizeof (zone));
7243087719fdSdp (void) strlcpy(revert_zone, optarg, sizeof (zone));
72447c478bd9Sstevel@tonic-gate break;
72457c478bd9Sstevel@tonic-gate default:
7246bbec428eSgjelinek usage(B_FALSE, HELP_USAGE);
72477c478bd9Sstevel@tonic-gate exit(Z_USAGE);
72487c478bd9Sstevel@tonic-gate }
72497c478bd9Sstevel@tonic-gate }
72507c478bd9Sstevel@tonic-gate
7251087719fdSdp if (optind > argc || strcmp(zone, "") == 0) {
7252bbec428eSgjelinek usage(B_FALSE, HELP_USAGE);
72537c478bd9Sstevel@tonic-gate exit(Z_USAGE);
72547c478bd9Sstevel@tonic-gate }
72557c478bd9Sstevel@tonic-gate
7256087719fdSdp if ((err = zonecfg_access(zone, W_OK)) == Z_OK) {
7257bbec428eSgjelinek read_only_mode = B_FALSE;
7258087719fdSdp } else if (err == Z_ACCES) {
7259bbec428eSgjelinek read_only_mode = B_TRUE;
72607c478bd9Sstevel@tonic-gate /* skip this message in one-off from command line mode */
72617c478bd9Sstevel@tonic-gate if (optind == argc)
72627c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("WARNING: you do not "
72637c478bd9Sstevel@tonic-gate "have write access to this zone's configuration "
72647c478bd9Sstevel@tonic-gate "file;\ngoing into read-only mode.\n"));
7265087719fdSdp } else {
7266087719fdSdp fprintf(stderr, "%s: Could not access zone configuration "
7267087719fdSdp "store: %s\n", execname, zonecfg_strerror(err));
7268087719fdSdp exit(Z_ERR);
72697c478bd9Sstevel@tonic-gate }
72707c478bd9Sstevel@tonic-gate
72717c478bd9Sstevel@tonic-gate if ((handle = zonecfg_init_handle()) == NULL) {
7272bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE);
72737c478bd9Sstevel@tonic-gate exit(Z_ERR);
72747c478bd9Sstevel@tonic-gate }
72757c478bd9Sstevel@tonic-gate
72767c478bd9Sstevel@tonic-gate /*
72777c478bd9Sstevel@tonic-gate * This may get set back to FALSE again in cmd_file() if cmd_file_name
72787c478bd9Sstevel@tonic-gate * is a "real" file as opposed to "-" (i.e. meaning use stdin).
72797c478bd9Sstevel@tonic-gate */
72807c478bd9Sstevel@tonic-gate if (isatty(STDIN_FILENO))
7281bbec428eSgjelinek ok_to_prompt = B_TRUE;
72827c478bd9Sstevel@tonic-gate if ((gl = new_GetLine(MAX_LINE_LEN, MAX_CMD_HIST)) == NULL)
72837c478bd9Sstevel@tonic-gate exit(Z_ERR);
72847c478bd9Sstevel@tonic-gate if (gl_customize_completion(gl, NULL, cmd_cpl_fn) != 0)
72857c478bd9Sstevel@tonic-gate exit(Z_ERR);
72867c478bd9Sstevel@tonic-gate (void) sigset(SIGINT, SIG_IGN);
72877c478bd9Sstevel@tonic-gate if (optind == argc) {
72887c478bd9Sstevel@tonic-gate if (!cmd_file_mode)
72897c478bd9Sstevel@tonic-gate err = do_interactive();
72907c478bd9Sstevel@tonic-gate else
72917c478bd9Sstevel@tonic-gate err = cmd_file(cmd_file_name);
72927c478bd9Sstevel@tonic-gate } else {
72937c478bd9Sstevel@tonic-gate err = one_command_at_a_time(argc - optind, &(argv[optind]));
72947c478bd9Sstevel@tonic-gate }
72957c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle);
72969acbbeafSnn35248 if (brand != NULL)
72979acbbeafSnn35248 brand_close(brand);
72987c478bd9Sstevel@tonic-gate (void) del_GetLine(gl);
72997c478bd9Sstevel@tonic-gate return (err);
73007c478bd9Sstevel@tonic-gate }
7301