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. 25944b13ecSGary 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> 56*d2a70789SRichard Lowe #include <sys/secflags.h> 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate #include <errno.h> 599acbbeafSnn #include <fcntl.h> 607c478bd9Sstevel@tonic-gate #include <strings.h> 617c478bd9Sstevel@tonic-gate #include <unistd.h> 627c478bd9Sstevel@tonic-gate #include <ctype.h> 637c478bd9Sstevel@tonic-gate #include <stdlib.h> 647c478bd9Sstevel@tonic-gate #include <assert.h> 657c478bd9Sstevel@tonic-gate #include <sys/stat.h> 667c478bd9Sstevel@tonic-gate #include <zone.h> 677c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 687c478bd9Sstevel@tonic-gate #include <netdb.h> 697c478bd9Sstevel@tonic-gate #include <locale.h> 707c478bd9Sstevel@tonic-gate #include <libintl.h> 717c478bd9Sstevel@tonic-gate #include <alloca.h> 727c478bd9Sstevel@tonic-gate #include <signal.h> 739acbbeafSnn #include <wait.h> 747c478bd9Sstevel@tonic-gate #include <libtecla.h> 75fa9e4066Sahrens #include <libzfs.h> 769acbbeafSnn #include <sys/brand.h> 779acbbeafSnn #include <libbrand.h> 785679c89fSjv #include <sys/systeminfo.h> 79c9f134eaSjv #include <libdladm.h> 80c9f134eaSjv #include <libinetutil.h> 81cb8a054bSGlenn Faden #include <pwd.h> 82550b6e40SSowmini Varadhan #include <inet/ip.h> 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate #include <libzonecfg.h> 857c478bd9Sstevel@tonic-gate #include "zonecfg.h" 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) /* should be defined by cc -D */ 887c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */ 897c478bd9Sstevel@tonic-gate #endif 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate #define PAGER "/usr/bin/more" 929acbbeafSnn #define EXEC_PREFIX "exec " 939acbbeafSnn #define EXEC_LEN (strlen(EXEC_PREFIX)) 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate struct help { 967c478bd9Sstevel@tonic-gate uint_t cmd_num; 977c478bd9Sstevel@tonic-gate char *cmd_name; 987c478bd9Sstevel@tonic-gate uint_t flags; 997c478bd9Sstevel@tonic-gate char *short_usage; 1007c478bd9Sstevel@tonic-gate }; 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate extern int yyparse(void); 1037c478bd9Sstevel@tonic-gate extern int lex_lineno; 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate #define MAX_LINE_LEN 1024 1067c478bd9Sstevel@tonic-gate #define MAX_CMD_HIST 1024 1079acbbeafSnn #define MAX_CMD_LEN 1024 1087c478bd9Sstevel@tonic-gate 1090209230bSgjelinek #define ONE_MB 1048576 1100209230bSgjelinek 1117c478bd9Sstevel@tonic-gate /* 1127c478bd9Sstevel@tonic-gate * Each SHELP_ should be a simple string. 1137c478bd9Sstevel@tonic-gate */ 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate #define SHELP_ADD "add <resource-type>\n\t(global scope)\n" \ 1167c478bd9Sstevel@tonic-gate "add <property-name> <property-value>\n\t(resource scope)" 1177c478bd9Sstevel@tonic-gate #define SHELP_CANCEL "cancel" 1180209230bSgjelinek #define SHELP_CLEAR "clear <property-name>" 1197c478bd9Sstevel@tonic-gate #define SHELP_COMMIT "commit" 120ee519a1fSgjelinek #define SHELP_CREATE "create [-F] [ -a <path> | -b | -t <template> ]" 1217c478bd9Sstevel@tonic-gate #define SHELP_DELETE "delete [-F]" 1227c478bd9Sstevel@tonic-gate #define SHELP_END "end" 1237c478bd9Sstevel@tonic-gate #define SHELP_EXIT "exit [-F]" 1247c478bd9Sstevel@tonic-gate #define SHELP_EXPORT "export [-f output-file]" 1257c478bd9Sstevel@tonic-gate #define SHELP_HELP "help [commands] [syntax] [usage] [<command-name>]" 1267c478bd9Sstevel@tonic-gate #define SHELP_INFO "info [<resource-type> [property-name=property-value]*]" 1270209230bSgjelinek #define SHELP_REMOVE "remove [-F] <resource-type> " \ 1280209230bSgjelinek "[ <property-name>=<property-value> ]*\n" \ 1290209230bSgjelinek "\t(global scope)\n" \ 1300209230bSgjelinek "remove <property-name> <property-value>\n" \ 1310209230bSgjelinek "\t(resource scope)" 1327c478bd9Sstevel@tonic-gate #define SHELP_REVERT "revert [-F]" 1337c478bd9Sstevel@tonic-gate #define SHELP_SELECT "select <resource-type> { <property-name>=" \ 1347c478bd9Sstevel@tonic-gate "<property-value> }" 1357c478bd9Sstevel@tonic-gate #define SHELP_SET "set <property-name>=<property-value>" 1367c478bd9Sstevel@tonic-gate #define SHELP_VERIFY "verify" 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate static struct help helptab[] = { 1397c478bd9Sstevel@tonic-gate { CMD_ADD, "add", HELP_RES_PROPS, SHELP_ADD, }, 1407c478bd9Sstevel@tonic-gate { CMD_CANCEL, "cancel", 0, SHELP_CANCEL, }, 1410209230bSgjelinek { CMD_CLEAR, "clear", HELP_PROPS, SHELP_CLEAR, }, 1427c478bd9Sstevel@tonic-gate { CMD_COMMIT, "commit", 0, SHELP_COMMIT, }, 1437c478bd9Sstevel@tonic-gate { CMD_CREATE, "create", 0, SHELP_CREATE, }, 1447c478bd9Sstevel@tonic-gate { CMD_DELETE, "delete", 0, SHELP_DELETE, }, 1457c478bd9Sstevel@tonic-gate { CMD_END, "end", 0, SHELP_END, }, 1467c478bd9Sstevel@tonic-gate { CMD_EXIT, "exit", 0, SHELP_EXIT, }, 1477c478bd9Sstevel@tonic-gate { CMD_EXPORT, "export", 0, SHELP_EXPORT, }, 1487c478bd9Sstevel@tonic-gate { CMD_HELP, "help", 0, SHELP_HELP }, 1497c478bd9Sstevel@tonic-gate { CMD_INFO, "info", HELP_RES_PROPS, SHELP_INFO, }, 1507c478bd9Sstevel@tonic-gate { CMD_REMOVE, "remove", HELP_RES_PROPS, SHELP_REMOVE, }, 1517c478bd9Sstevel@tonic-gate { CMD_REVERT, "revert", 0, SHELP_REVERT, }, 1527c478bd9Sstevel@tonic-gate { CMD_SELECT, "select", HELP_RES_PROPS, SHELP_SELECT, }, 1537c478bd9Sstevel@tonic-gate { CMD_SET, "set", HELP_PROPS, SHELP_SET, }, 1547c478bd9Sstevel@tonic-gate { CMD_VERIFY, "verify", 0, SHELP_VERIFY, }, 1557c478bd9Sstevel@tonic-gate { 0 }, 1567c478bd9Sstevel@tonic-gate }; 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate #define MAX_RT_STRLEN 16 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate /* These *must* match the order of the RT_ define's from zonecfg.h */ 161c94c1ef0Sjv char *res_types[] = { 1627c478bd9Sstevel@tonic-gate "unknown", 163087719fdSdp "zonename", 1647c478bd9Sstevel@tonic-gate "zonepath", 1657c478bd9Sstevel@tonic-gate "autoboot", 1667c478bd9Sstevel@tonic-gate "pool", 1677c478bd9Sstevel@tonic-gate "fs", 1687c478bd9Sstevel@tonic-gate "net", 1697c478bd9Sstevel@tonic-gate "device", 1707c478bd9Sstevel@tonic-gate "rctl", 1717c478bd9Sstevel@tonic-gate "attr", 172fa9e4066Sahrens "dataset", 173ffbafc53Scomay "limitpriv", 1743f2f09c1Sdp "bootargs", 1759acbbeafSnn "brand", 1760209230bSgjelinek "dedicated-cpu", 1770209230bSgjelinek "capped-memory", 1780209230bSgjelinek ALIAS_MAXLWPS, 1790209230bSgjelinek ALIAS_MAXSHMMEM, 1800209230bSgjelinek ALIAS_MAXSHMIDS, 1810209230bSgjelinek ALIAS_MAXMSGIDS, 1820209230bSgjelinek ALIAS_MAXSEMIDS, 1830209230bSgjelinek ALIAS_SHARES, 1840209230bSgjelinek "scheduling-class", 185f4b3ec61Sdh "ip-type", 186c97ad5cdSakolb "capped-cpu", 1875679c89fSjv "hostid", 188cb8a054bSGlenn Faden "admin", 1890fbb751dSJohn Levon "fs-allowed", 190ff19e029SMenno Lageman ALIAS_MAXPROCS, 191*d2a70789SRichard Lowe "security-flags", 1927c478bd9Sstevel@tonic-gate NULL 1937c478bd9Sstevel@tonic-gate }; 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate /* These *must* match the order of the PT_ define's from zonecfg.h */ 196c94c1ef0Sjv char *prop_types[] = { 1977c478bd9Sstevel@tonic-gate "unknown", 198087719fdSdp "zonename", 1997c478bd9Sstevel@tonic-gate "zonepath", 2007c478bd9Sstevel@tonic-gate "autoboot", 2017c478bd9Sstevel@tonic-gate "pool", 2027c478bd9Sstevel@tonic-gate "dir", 2037c478bd9Sstevel@tonic-gate "special", 2047c478bd9Sstevel@tonic-gate "type", 2057c478bd9Sstevel@tonic-gate "options", 2067c478bd9Sstevel@tonic-gate "address", 2077c478bd9Sstevel@tonic-gate "physical", 2087c478bd9Sstevel@tonic-gate "name", 2097c478bd9Sstevel@tonic-gate "value", 2107c478bd9Sstevel@tonic-gate "match", 2117c478bd9Sstevel@tonic-gate "priv", 2127c478bd9Sstevel@tonic-gate "limit", 2137c478bd9Sstevel@tonic-gate "action", 2147c478bd9Sstevel@tonic-gate "raw", 215ffbafc53Scomay "limitpriv", 2163f2f09c1Sdp "bootargs", 2179acbbeafSnn "brand", 2180209230bSgjelinek "ncpus", 2190209230bSgjelinek "importance", 2200209230bSgjelinek "swap", 2210209230bSgjelinek "locked", 2220209230bSgjelinek ALIAS_SHARES, 2230209230bSgjelinek ALIAS_MAXLWPS, 2240209230bSgjelinek ALIAS_MAXSHMMEM, 2250209230bSgjelinek ALIAS_MAXSHMIDS, 2260209230bSgjelinek ALIAS_MAXMSGIDS, 2270209230bSgjelinek ALIAS_MAXSEMIDS, 2280209230bSgjelinek ALIAS_MAXLOCKEDMEM, 2290209230bSgjelinek ALIAS_MAXSWAP, 2300209230bSgjelinek "scheduling-class", 231f4b3ec61Sdh "ip-type", 232de860bd9Sgfaden "defrouter", 2335679c89fSjv "hostid", 234cb8a054bSGlenn Faden "user", 235cb8a054bSGlenn Faden "auths", 2360fbb751dSJohn Levon "fs-allowed", 237ff19e029SMenno Lageman ALIAS_MAXPROCS, 238550b6e40SSowmini Varadhan "allowed-address", 239*d2a70789SRichard Lowe "default", 240*d2a70789SRichard Lowe "lower", 241*d2a70789SRichard Lowe "upper", 2427c478bd9Sstevel@tonic-gate NULL 2437c478bd9Sstevel@tonic-gate }; 2447c478bd9Sstevel@tonic-gate 245ffbafc53Scomay /* These *must* match the order of the PROP_VAL_ define's from zonecfg.h */ 2467c478bd9Sstevel@tonic-gate static char *prop_val_types[] = { 2477c478bd9Sstevel@tonic-gate "simple", 2487c478bd9Sstevel@tonic-gate "complex", 2497c478bd9Sstevel@tonic-gate "list", 2507c478bd9Sstevel@tonic-gate }; 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate /* 2537c478bd9Sstevel@tonic-gate * The various _cmds[] lists below are for command tab-completion. 2547c478bd9Sstevel@tonic-gate */ 2557c478bd9Sstevel@tonic-gate 2567c478bd9Sstevel@tonic-gate /* 2577c478bd9Sstevel@tonic-gate * remove has a space afterwards because it has qualifiers; the other commands 2580209230bSgjelinek * that have qualifiers (add, select, etc.) don't need a space here because 2597c478bd9Sstevel@tonic-gate * they have their own _cmds[] lists below. 2607c478bd9Sstevel@tonic-gate */ 2617c478bd9Sstevel@tonic-gate static const char *global_scope_cmds[] = { 2627c478bd9Sstevel@tonic-gate "add", 2630209230bSgjelinek "clear", 2647c478bd9Sstevel@tonic-gate "commit", 2657c478bd9Sstevel@tonic-gate "create", 2667c478bd9Sstevel@tonic-gate "delete", 2677c478bd9Sstevel@tonic-gate "exit", 2687c478bd9Sstevel@tonic-gate "export", 2697c478bd9Sstevel@tonic-gate "help", 2707c478bd9Sstevel@tonic-gate "info", 2717c478bd9Sstevel@tonic-gate "remove ", 2727c478bd9Sstevel@tonic-gate "revert", 2737c478bd9Sstevel@tonic-gate "select", 2747c478bd9Sstevel@tonic-gate "set", 2757c478bd9Sstevel@tonic-gate "verify", 2767c478bd9Sstevel@tonic-gate NULL 2777c478bd9Sstevel@tonic-gate }; 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate static const char *add_cmds[] = { 2807c478bd9Sstevel@tonic-gate "add fs", 2817c478bd9Sstevel@tonic-gate "add net", 2827c478bd9Sstevel@tonic-gate "add device", 2837c478bd9Sstevel@tonic-gate "add rctl", 2847c478bd9Sstevel@tonic-gate "add attr", 285fa9e4066Sahrens "add dataset", 2860209230bSgjelinek "add dedicated-cpu", 287c97ad5cdSakolb "add capped-cpu", 2880209230bSgjelinek "add capped-memory", 289cb8a054bSGlenn Faden "add admin", 290*d2a70789SRichard Lowe "add security-flags", 2910209230bSgjelinek NULL 2920209230bSgjelinek }; 2930209230bSgjelinek 2940209230bSgjelinek static const char *clear_cmds[] = { 2950209230bSgjelinek "clear autoboot", 2960209230bSgjelinek "clear pool", 2970209230bSgjelinek "clear limitpriv", 2980209230bSgjelinek "clear bootargs", 2990209230bSgjelinek "clear scheduling-class", 300f4b3ec61Sdh "clear ip-type", 3010209230bSgjelinek "clear " ALIAS_MAXLWPS, 3020209230bSgjelinek "clear " ALIAS_MAXSHMMEM, 3030209230bSgjelinek "clear " ALIAS_MAXSHMIDS, 3040209230bSgjelinek "clear " ALIAS_MAXMSGIDS, 3050209230bSgjelinek "clear " ALIAS_MAXSEMIDS, 3060209230bSgjelinek "clear " ALIAS_SHARES, 307ff19e029SMenno Lageman "clear " ALIAS_MAXPROCS, 3087c478bd9Sstevel@tonic-gate NULL 3097c478bd9Sstevel@tonic-gate }; 3107c478bd9Sstevel@tonic-gate 3119e7542f4Sdp static const char *remove_cmds[] = { 3129e7542f4Sdp "remove fs ", 3139e7542f4Sdp "remove net ", 3149e7542f4Sdp "remove device ", 3159e7542f4Sdp "remove rctl ", 3169e7542f4Sdp "remove attr ", 3179e7542f4Sdp "remove dataset ", 3180209230bSgjelinek "remove dedicated-cpu ", 319c97ad5cdSakolb "remove capped-cpu ", 3200209230bSgjelinek "remove capped-memory ", 321cb8a054bSGlenn Faden "remove admin ", 322*d2a70789SRichard Lowe "remove security-flags", 3239e7542f4Sdp NULL 3249e7542f4Sdp }; 3259e7542f4Sdp 3267c478bd9Sstevel@tonic-gate static const char *select_cmds[] = { 327087719fdSdp "select fs ", 328087719fdSdp "select net ", 329087719fdSdp "select device ", 330087719fdSdp "select rctl ", 331087719fdSdp "select attr ", 332fa9e4066Sahrens "select dataset ", 3330209230bSgjelinek "select dedicated-cpu", 334c97ad5cdSakolb "select capped-cpu", 3350209230bSgjelinek "select capped-memory", 336cb8a054bSGlenn Faden "select admin", 337*d2a70789SRichard Lowe "select security-flags", 3387c478bd9Sstevel@tonic-gate NULL 3397c478bd9Sstevel@tonic-gate }; 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gate static const char *set_cmds[] = { 342087719fdSdp "set zonename=", 343087719fdSdp "set zonepath=", 3449acbbeafSnn "set brand=", 345087719fdSdp "set autoboot=", 346087719fdSdp "set pool=", 347ffbafc53Scomay "set limitpriv=", 3483f2f09c1Sdp "set bootargs=", 3490209230bSgjelinek "set scheduling-class=", 350f4b3ec61Sdh "set ip-type=", 3510209230bSgjelinek "set " ALIAS_MAXLWPS "=", 3520209230bSgjelinek "set " ALIAS_MAXSHMMEM "=", 3530209230bSgjelinek "set " ALIAS_MAXSHMIDS "=", 3540209230bSgjelinek "set " ALIAS_MAXMSGIDS "=", 3550209230bSgjelinek "set " ALIAS_MAXSEMIDS "=", 3560209230bSgjelinek "set " ALIAS_SHARES "=", 3575679c89fSjv "set hostid=", 3580fbb751dSJohn Levon "set fs-allowed=", 359ff19e029SMenno Lageman "set " ALIAS_MAXPROCS "=", 3607c478bd9Sstevel@tonic-gate NULL 3617c478bd9Sstevel@tonic-gate }; 3627c478bd9Sstevel@tonic-gate 3639e7542f4Sdp static const char *info_cmds[] = { 3649e7542f4Sdp "info fs ", 3659e7542f4Sdp "info net ", 3669e7542f4Sdp "info device ", 3679e7542f4Sdp "info rctl ", 3689e7542f4Sdp "info attr ", 3699e7542f4Sdp "info dataset ", 3700209230bSgjelinek "info capped-memory", 3710209230bSgjelinek "info dedicated-cpu", 372c97ad5cdSakolb "info capped-cpu", 373*d2a70789SRichard Lowe "info security-flags", 3749e7542f4Sdp "info zonename", 3759e7542f4Sdp "info zonepath", 3769e7542f4Sdp "info autoboot", 3779e7542f4Sdp "info pool", 3789e7542f4Sdp "info limitpriv", 3799e7542f4Sdp "info bootargs", 3800209230bSgjelinek "info brand", 3810209230bSgjelinek "info scheduling-class", 382f4b3ec61Sdh "info ip-type", 3830209230bSgjelinek "info max-lwps", 3840209230bSgjelinek "info max-shm-memory", 3850209230bSgjelinek "info max-shm-ids", 3860209230bSgjelinek "info max-msg-ids", 3870209230bSgjelinek "info max-sem-ids", 3880209230bSgjelinek "info cpu-shares", 3895679c89fSjv "info hostid", 390cb8a054bSGlenn Faden "info admin", 3910fbb751dSJohn Levon "info fs-allowed", 392ff19e029SMenno Lageman "info max-processes", 3939e7542f4Sdp NULL 3949e7542f4Sdp }; 3959e7542f4Sdp 3967c478bd9Sstevel@tonic-gate static const char *fs_res_scope_cmds[] = { 3977c478bd9Sstevel@tonic-gate "add options ", 3987c478bd9Sstevel@tonic-gate "cancel", 3997c478bd9Sstevel@tonic-gate "end", 4007c478bd9Sstevel@tonic-gate "exit", 4017c478bd9Sstevel@tonic-gate "help", 4027c478bd9Sstevel@tonic-gate "info", 403ffbafc53Scomay "remove options ", 4047c478bd9Sstevel@tonic-gate "set dir=", 4057c478bd9Sstevel@tonic-gate "set raw=", 4067c478bd9Sstevel@tonic-gate "set special=", 4077c478bd9Sstevel@tonic-gate "set type=", 4080209230bSgjelinek "clear raw", 4097c478bd9Sstevel@tonic-gate NULL 4107c478bd9Sstevel@tonic-gate }; 4117c478bd9Sstevel@tonic-gate 4127c478bd9Sstevel@tonic-gate static const char *net_res_scope_cmds[] = { 4137c478bd9Sstevel@tonic-gate "cancel", 4147c478bd9Sstevel@tonic-gate "end", 4157c478bd9Sstevel@tonic-gate "exit", 4167c478bd9Sstevel@tonic-gate "help", 4177c478bd9Sstevel@tonic-gate "info", 4187c478bd9Sstevel@tonic-gate "set address=", 4197c478bd9Sstevel@tonic-gate "set physical=", 4201b3281c0SGerald Jelinek "set defrouter=", 4217c478bd9Sstevel@tonic-gate NULL 4227c478bd9Sstevel@tonic-gate }; 4237c478bd9Sstevel@tonic-gate 4247c478bd9Sstevel@tonic-gate static const char *device_res_scope_cmds[] = { 4257c478bd9Sstevel@tonic-gate "cancel", 4267c478bd9Sstevel@tonic-gate "end", 4277c478bd9Sstevel@tonic-gate "exit", 4287c478bd9Sstevel@tonic-gate "help", 4297c478bd9Sstevel@tonic-gate "info", 4307c478bd9Sstevel@tonic-gate "set match=", 4317c478bd9Sstevel@tonic-gate NULL 4327c478bd9Sstevel@tonic-gate }; 4337c478bd9Sstevel@tonic-gate 4347c478bd9Sstevel@tonic-gate static const char *attr_res_scope_cmds[] = { 4357c478bd9Sstevel@tonic-gate "cancel", 4367c478bd9Sstevel@tonic-gate "end", 4377c478bd9Sstevel@tonic-gate "exit", 4387c478bd9Sstevel@tonic-gate "help", 4397c478bd9Sstevel@tonic-gate "info", 4407c478bd9Sstevel@tonic-gate "set name=", 4417c478bd9Sstevel@tonic-gate "set type=", 4427c478bd9Sstevel@tonic-gate "set value=", 4437c478bd9Sstevel@tonic-gate NULL 4447c478bd9Sstevel@tonic-gate }; 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate static const char *rctl_res_scope_cmds[] = { 4477c478bd9Sstevel@tonic-gate "add value ", 4487c478bd9Sstevel@tonic-gate "cancel", 4497c478bd9Sstevel@tonic-gate "end", 4507c478bd9Sstevel@tonic-gate "exit", 4517c478bd9Sstevel@tonic-gate "help", 4527c478bd9Sstevel@tonic-gate "info", 453ffbafc53Scomay "remove value ", 4547c478bd9Sstevel@tonic-gate "set name=", 4557c478bd9Sstevel@tonic-gate NULL 4567c478bd9Sstevel@tonic-gate }; 4577c478bd9Sstevel@tonic-gate 458fa9e4066Sahrens static const char *dataset_res_scope_cmds[] = { 459fa9e4066Sahrens "cancel", 460fa9e4066Sahrens "end", 461fa9e4066Sahrens "exit", 462fa9e4066Sahrens "help", 463fa9e4066Sahrens "info", 464fa9e4066Sahrens "set name=", 465fa9e4066Sahrens NULL 466fa9e4066Sahrens }; 467fa9e4066Sahrens 4680209230bSgjelinek static const char *pset_res_scope_cmds[] = { 4690209230bSgjelinek "cancel", 4700209230bSgjelinek "end", 4710209230bSgjelinek "exit", 4720209230bSgjelinek "help", 4730209230bSgjelinek "info", 4740209230bSgjelinek "set ncpus=", 4750209230bSgjelinek "set importance=", 4760209230bSgjelinek "clear importance", 4770209230bSgjelinek NULL 4780209230bSgjelinek }; 4790209230bSgjelinek 480c97ad5cdSakolb static const char *pcap_res_scope_cmds[] = { 481c97ad5cdSakolb "cancel", 482c97ad5cdSakolb "end", 483c97ad5cdSakolb "exit", 484c97ad5cdSakolb "help", 485c97ad5cdSakolb "info", 486c97ad5cdSakolb "set ncpus=", 487c97ad5cdSakolb NULL 488c97ad5cdSakolb }; 489c97ad5cdSakolb 4900209230bSgjelinek static const char *mcap_res_scope_cmds[] = { 4910209230bSgjelinek "cancel", 4920209230bSgjelinek "end", 4930209230bSgjelinek "exit", 4940209230bSgjelinek "help", 4950209230bSgjelinek "info", 4960209230bSgjelinek "set physical=", 4970209230bSgjelinek "set swap=", 4980209230bSgjelinek "set locked=", 4990209230bSgjelinek "clear physical", 5000209230bSgjelinek "clear swap", 5010209230bSgjelinek "clear locked", 5020209230bSgjelinek NULL 5030209230bSgjelinek }; 5040209230bSgjelinek 505cb8a054bSGlenn Faden static const char *admin_res_scope_cmds[] = { 506cb8a054bSGlenn Faden "cancel", 507cb8a054bSGlenn Faden "end", 508cb8a054bSGlenn Faden "exit", 509cb8a054bSGlenn Faden "help", 510cb8a054bSGlenn Faden "info", 511cb8a054bSGlenn Faden "set user=", 512cb8a054bSGlenn Faden "set auths=", 513cb8a054bSGlenn Faden NULL 514cb8a054bSGlenn Faden }; 515cb8a054bSGlenn Faden 516*d2a70789SRichard Lowe static const char *secflags_res_scope_cmds[] = { 517*d2a70789SRichard Lowe "cancel", 518*d2a70789SRichard Lowe "end", 519*d2a70789SRichard Lowe "exit", 520*d2a70789SRichard Lowe "set default=", 521*d2a70789SRichard Lowe "set lower=", 522*d2a70789SRichard Lowe "set upper=", 523*d2a70789SRichard Lowe NULL 524*d2a70789SRichard Lowe }; 525*d2a70789SRichard Lowe 526550b6e40SSowmini Varadhan struct xif { 527550b6e40SSowmini Varadhan struct xif *xif_next; 528550b6e40SSowmini Varadhan char xif_name[LIFNAMSIZ]; 529550b6e40SSowmini Varadhan boolean_t xif_has_address; 530550b6e40SSowmini Varadhan boolean_t xif_has_defrouter; 531550b6e40SSowmini Varadhan }; 532550b6e40SSowmini Varadhan 5337c478bd9Sstevel@tonic-gate /* Global variables */ 5347c478bd9Sstevel@tonic-gate 535550b6e40SSowmini Varadhan /* list of network interfaces specified for exclusive IP zone */ 536550b6e40SSowmini Varadhan struct xif *xif; 537550b6e40SSowmini Varadhan 5387c478bd9Sstevel@tonic-gate /* set early in main(), never modified thereafter, used all over the place */ 5397c478bd9Sstevel@tonic-gate static char *execname; 5407c478bd9Sstevel@tonic-gate 5417c478bd9Sstevel@tonic-gate /* set in main(), used all over the place */ 5427c478bd9Sstevel@tonic-gate static zone_dochandle_t handle; 5437c478bd9Sstevel@tonic-gate 5447c478bd9Sstevel@tonic-gate /* used all over the place */ 545087719fdSdp static char zone[ZONENAME_MAX]; 546087719fdSdp static char revert_zone[ZONENAME_MAX]; 5477c478bd9Sstevel@tonic-gate 5489acbbeafSnn /* global brand operations */ 549123807fbSedp static brand_handle_t brand; 5509acbbeafSnn 5517c478bd9Sstevel@tonic-gate /* set in modifying functions, checked in read_input() */ 552bbec428eSgjelinek static boolean_t need_to_commit = B_FALSE; 553bbec428eSgjelinek boolean_t saw_error; 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate /* set in yacc parser, checked in read_input() */ 556bbec428eSgjelinek boolean_t newline_terminated; 5577c478bd9Sstevel@tonic-gate 5587c478bd9Sstevel@tonic-gate /* set in main(), checked in lex error handler */ 559bbec428eSgjelinek boolean_t cmd_file_mode; 5607c478bd9Sstevel@tonic-gate 5617c478bd9Sstevel@tonic-gate /* set in exit_func(), checked in read_input() */ 562bbec428eSgjelinek static boolean_t time_to_exit = B_FALSE, force_exit = B_FALSE; 5637c478bd9Sstevel@tonic-gate 5647c478bd9Sstevel@tonic-gate /* used in short_usage() and zerr() */ 5657c478bd9Sstevel@tonic-gate static char *cmd_file_name = NULL; 5667c478bd9Sstevel@tonic-gate 5677c478bd9Sstevel@tonic-gate /* checked in read_input() and other places */ 568bbec428eSgjelinek static boolean_t ok_to_prompt = B_FALSE; 5697c478bd9Sstevel@tonic-gate 5707c478bd9Sstevel@tonic-gate /* set and checked in initialize() */ 571bbec428eSgjelinek static boolean_t got_handle = B_FALSE; 5727c478bd9Sstevel@tonic-gate 5737c478bd9Sstevel@tonic-gate /* initialized in do_interactive(), checked in initialize() */ 574bbec428eSgjelinek static boolean_t interactive_mode; 5757c478bd9Sstevel@tonic-gate 5760209230bSgjelinek /* set if configuring the global zone */ 577bbec428eSgjelinek static boolean_t global_zone = B_FALSE; 5780209230bSgjelinek 5797c478bd9Sstevel@tonic-gate /* set in main(), checked in multiple places */ 580bbec428eSgjelinek static boolean_t read_only_mode; 5817c478bd9Sstevel@tonic-gate 582bbec428eSgjelinek /* scope is outer/global or inner/resource */ 583bbec428eSgjelinek static boolean_t global_scope = B_TRUE; 5847c478bd9Sstevel@tonic-gate static int resource_scope; /* should be in the RT_ list from zonecfg.h */ 5857c478bd9Sstevel@tonic-gate static int end_op = -1; /* operation on end is either add or modify */ 5867c478bd9Sstevel@tonic-gate 5877c478bd9Sstevel@tonic-gate int num_prop_vals; /* for grammar */ 5887c478bd9Sstevel@tonic-gate 5897c478bd9Sstevel@tonic-gate /* 5907c478bd9Sstevel@tonic-gate * These are for keeping track of resources as they are specified as part of 5917c478bd9Sstevel@tonic-gate * the multi-step process. They should be initialized by add_resource() or 5927c478bd9Sstevel@tonic-gate * select_func() and filled in by add_property() or set_func(). 5937c478bd9Sstevel@tonic-gate */ 5947c478bd9Sstevel@tonic-gate static struct zone_fstab old_fstab, in_progress_fstab; 5957c478bd9Sstevel@tonic-gate static struct zone_nwiftab old_nwiftab, in_progress_nwiftab; 5967c478bd9Sstevel@tonic-gate static struct zone_devtab old_devtab, in_progress_devtab; 5977c478bd9Sstevel@tonic-gate static struct zone_rctltab old_rctltab, in_progress_rctltab; 5987c478bd9Sstevel@tonic-gate static struct zone_attrtab old_attrtab, in_progress_attrtab; 599fa9e4066Sahrens static struct zone_dstab old_dstab, in_progress_dstab; 6000209230bSgjelinek static struct zone_psettab old_psettab, in_progress_psettab; 6010209230bSgjelinek static struct zone_mcaptab old_mcaptab, in_progress_mcaptab; 602cb8a054bSGlenn Faden static struct zone_admintab old_admintab, in_progress_admintab; 603*d2a70789SRichard Lowe static struct zone_secflagstab old_secflagstab, in_progress_secflagstab; 6047c478bd9Sstevel@tonic-gate 6057c478bd9Sstevel@tonic-gate static GetLine *gl; /* The gl_get_line() resource object */ 6067c478bd9Sstevel@tonic-gate 6070209230bSgjelinek static void bytes_to_units(char *str, char *buf, int bufsize); 6080209230bSgjelinek 6097c478bd9Sstevel@tonic-gate /* Functions begin here */ 6107c478bd9Sstevel@tonic-gate 611bbec428eSgjelinek static boolean_t 6127c478bd9Sstevel@tonic-gate initial_match(const char *line1, const char *line2, int word_end) 6137c478bd9Sstevel@tonic-gate { 6147c478bd9Sstevel@tonic-gate if (word_end <= 0) 615bbec428eSgjelinek return (B_TRUE); 6167c478bd9Sstevel@tonic-gate return (strncmp(line1, line2, word_end) == 0); 6177c478bd9Sstevel@tonic-gate } 6187c478bd9Sstevel@tonic-gate 6197c478bd9Sstevel@tonic-gate static int 6207c478bd9Sstevel@tonic-gate add_stuff(WordCompletion *cpl, const char *line1, const char **list, 6217c478bd9Sstevel@tonic-gate int word_end) 6227c478bd9Sstevel@tonic-gate { 6237c478bd9Sstevel@tonic-gate int i, err; 6247c478bd9Sstevel@tonic-gate 6257c478bd9Sstevel@tonic-gate for (i = 0; list[i] != NULL; i++) { 6267c478bd9Sstevel@tonic-gate if (initial_match(line1, list[i], word_end)) { 6277c478bd9Sstevel@tonic-gate err = cpl_add_completion(cpl, line1, 0, word_end, 6287c478bd9Sstevel@tonic-gate list[i] + word_end, "", ""); 6297c478bd9Sstevel@tonic-gate if (err != 0) 6307c478bd9Sstevel@tonic-gate return (err); 6317c478bd9Sstevel@tonic-gate } 6327c478bd9Sstevel@tonic-gate } 6337c478bd9Sstevel@tonic-gate return (0); 6347c478bd9Sstevel@tonic-gate } 6357c478bd9Sstevel@tonic-gate 6367c478bd9Sstevel@tonic-gate static 6377c478bd9Sstevel@tonic-gate /* ARGSUSED */ 6387c478bd9Sstevel@tonic-gate CPL_MATCH_FN(cmd_cpl_fn) 6397c478bd9Sstevel@tonic-gate { 6407c478bd9Sstevel@tonic-gate if (global_scope) { 6417c478bd9Sstevel@tonic-gate /* 6427c478bd9Sstevel@tonic-gate * The MAX/MIN tests below are to make sure we have at least 6437c478bd9Sstevel@tonic-gate * enough characters to distinguish from other prefixes (MAX) 6447c478bd9Sstevel@tonic-gate * but only check MIN(what we have, what we're checking). 6457c478bd9Sstevel@tonic-gate */ 6467c478bd9Sstevel@tonic-gate if (strncmp(line, "add ", MAX(MIN(word_end, 4), 1)) == 0) 6477c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, add_cmds, word_end)); 6480209230bSgjelinek if (strncmp(line, "clear ", MAX(MIN(word_end, 6), 2)) == 0) 6490209230bSgjelinek return (add_stuff(cpl, line, clear_cmds, word_end)); 6507c478bd9Sstevel@tonic-gate if (strncmp(line, "select ", MAX(MIN(word_end, 7), 3)) == 0) 6517c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, select_cmds, word_end)); 6527c478bd9Sstevel@tonic-gate if (strncmp(line, "set ", MAX(MIN(word_end, 4), 3)) == 0) 6537c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, set_cmds, word_end)); 6549e7542f4Sdp if (strncmp(line, "remove ", MAX(MIN(word_end, 7), 1)) == 0) 6559e7542f4Sdp return (add_stuff(cpl, line, remove_cmds, word_end)); 6569e7542f4Sdp if (strncmp(line, "info ", MAX(MIN(word_end, 5), 1)) == 0) 6579e7542f4Sdp return (add_stuff(cpl, line, info_cmds, word_end)); 6587c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, global_scope_cmds, word_end)); 6597c478bd9Sstevel@tonic-gate } 6607c478bd9Sstevel@tonic-gate switch (resource_scope) { 6617c478bd9Sstevel@tonic-gate case RT_FS: 6627c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, fs_res_scope_cmds, word_end)); 6637c478bd9Sstevel@tonic-gate case RT_NET: 6647c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, net_res_scope_cmds, word_end)); 6657c478bd9Sstevel@tonic-gate case RT_DEVICE: 6667c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, device_res_scope_cmds, word_end)); 6677c478bd9Sstevel@tonic-gate case RT_RCTL: 6687c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, rctl_res_scope_cmds, word_end)); 6697c478bd9Sstevel@tonic-gate case RT_ATTR: 6707c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, attr_res_scope_cmds, word_end)); 671fa9e4066Sahrens case RT_DATASET: 672fa9e4066Sahrens return (add_stuff(cpl, line, dataset_res_scope_cmds, word_end)); 6730209230bSgjelinek case RT_DCPU: 6740209230bSgjelinek return (add_stuff(cpl, line, pset_res_scope_cmds, word_end)); 675c97ad5cdSakolb case RT_PCAP: 676c97ad5cdSakolb return (add_stuff(cpl, line, pcap_res_scope_cmds, word_end)); 6770209230bSgjelinek case RT_MCAP: 6780209230bSgjelinek return (add_stuff(cpl, line, mcap_res_scope_cmds, word_end)); 679cb8a054bSGlenn Faden case RT_ADMIN: 680cb8a054bSGlenn Faden return (add_stuff(cpl, line, admin_res_scope_cmds, word_end)); 681*d2a70789SRichard Lowe case RT_SECFLAGS: 682*d2a70789SRichard Lowe return (add_stuff(cpl, line, secflags_res_scope_cmds, 683*d2a70789SRichard Lowe word_end)); 684*d2a70789SRichard Lowe 6857c478bd9Sstevel@tonic-gate } 6867c478bd9Sstevel@tonic-gate return (0); 6877c478bd9Sstevel@tonic-gate } 6887c478bd9Sstevel@tonic-gate 6897c478bd9Sstevel@tonic-gate /* 6907c478bd9Sstevel@tonic-gate * For the main CMD_func() functions below, several of them call getopt() 6917c478bd9Sstevel@tonic-gate * then check optind against argc to make sure an extra parameter was not 6927c478bd9Sstevel@tonic-gate * passed in. The reason this is not caught in the grammar is that the 6937c478bd9Sstevel@tonic-gate * grammar just checks for a miscellaneous TOKEN, which is *expected* to 6947c478bd9Sstevel@tonic-gate * be "-F" (for example), but could be anything. So (for example) this 6957c478bd9Sstevel@tonic-gate * check will prevent "create bogus". 6967c478bd9Sstevel@tonic-gate */ 6977c478bd9Sstevel@tonic-gate 6987c478bd9Sstevel@tonic-gate cmd_t * 6997c478bd9Sstevel@tonic-gate alloc_cmd(void) 7007c478bd9Sstevel@tonic-gate { 7017c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (cmd_t))); 7027c478bd9Sstevel@tonic-gate } 7037c478bd9Sstevel@tonic-gate 7047c478bd9Sstevel@tonic-gate void 7057c478bd9Sstevel@tonic-gate free_cmd(cmd_t *cmd) 7067c478bd9Sstevel@tonic-gate { 7077c478bd9Sstevel@tonic-gate int i; 7087c478bd9Sstevel@tonic-gate 7097c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_EQ_PROP_PAIRS; i++) 7107c478bd9Sstevel@tonic-gate if (cmd->cmd_property_ptr[i] != NULL) { 7117c478bd9Sstevel@tonic-gate property_value_ptr_t pp = cmd->cmd_property_ptr[i]; 7127c478bd9Sstevel@tonic-gate 7137c478bd9Sstevel@tonic-gate switch (pp->pv_type) { 7147c478bd9Sstevel@tonic-gate case PROP_VAL_SIMPLE: 7157c478bd9Sstevel@tonic-gate free(pp->pv_simple); 7167c478bd9Sstevel@tonic-gate break; 7177c478bd9Sstevel@tonic-gate case PROP_VAL_COMPLEX: 7187c478bd9Sstevel@tonic-gate free_complex(pp->pv_complex); 7197c478bd9Sstevel@tonic-gate break; 7207c478bd9Sstevel@tonic-gate case PROP_VAL_LIST: 7217c478bd9Sstevel@tonic-gate free_list(pp->pv_list); 7227c478bd9Sstevel@tonic-gate break; 7237c478bd9Sstevel@tonic-gate } 7247c478bd9Sstevel@tonic-gate } 7257c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_argc; i++) 7267c478bd9Sstevel@tonic-gate free(cmd->cmd_argv[i]); 7277c478bd9Sstevel@tonic-gate free(cmd); 7287c478bd9Sstevel@tonic-gate } 7297c478bd9Sstevel@tonic-gate 7307c478bd9Sstevel@tonic-gate complex_property_ptr_t 7317c478bd9Sstevel@tonic-gate alloc_complex(void) 7327c478bd9Sstevel@tonic-gate { 7337c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (complex_property_t))); 7347c478bd9Sstevel@tonic-gate } 7357c478bd9Sstevel@tonic-gate 7367c478bd9Sstevel@tonic-gate void 7377c478bd9Sstevel@tonic-gate free_complex(complex_property_ptr_t complex) 7387c478bd9Sstevel@tonic-gate { 7397c478bd9Sstevel@tonic-gate if (complex == NULL) 7407c478bd9Sstevel@tonic-gate return; 7417c478bd9Sstevel@tonic-gate free_complex(complex->cp_next); 7427c478bd9Sstevel@tonic-gate if (complex->cp_value != NULL) 7437c478bd9Sstevel@tonic-gate free(complex->cp_value); 7447c478bd9Sstevel@tonic-gate free(complex); 7457c478bd9Sstevel@tonic-gate } 7467c478bd9Sstevel@tonic-gate 7477c478bd9Sstevel@tonic-gate list_property_ptr_t 7487c478bd9Sstevel@tonic-gate alloc_list(void) 7497c478bd9Sstevel@tonic-gate { 7507c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (list_property_t))); 7517c478bd9Sstevel@tonic-gate } 7527c478bd9Sstevel@tonic-gate 7537c478bd9Sstevel@tonic-gate void 7547c478bd9Sstevel@tonic-gate free_list(list_property_ptr_t list) 7557c478bd9Sstevel@tonic-gate { 7567c478bd9Sstevel@tonic-gate if (list == NULL) 7577c478bd9Sstevel@tonic-gate return; 7587c478bd9Sstevel@tonic-gate if (list->lp_simple != NULL) 7597c478bd9Sstevel@tonic-gate free(list->lp_simple); 7607c478bd9Sstevel@tonic-gate free_complex(list->lp_complex); 7617c478bd9Sstevel@tonic-gate free_list(list->lp_next); 7627c478bd9Sstevel@tonic-gate free(list); 7637c478bd9Sstevel@tonic-gate } 7647c478bd9Sstevel@tonic-gate 7657c478bd9Sstevel@tonic-gate void 7667c478bd9Sstevel@tonic-gate free_outer_list(list_property_ptr_t list) 7677c478bd9Sstevel@tonic-gate { 7687c478bd9Sstevel@tonic-gate if (list == NULL) 7697c478bd9Sstevel@tonic-gate return; 7707c478bd9Sstevel@tonic-gate free_outer_list(list->lp_next); 7717c478bd9Sstevel@tonic-gate free(list); 7727c478bd9Sstevel@tonic-gate } 7737c478bd9Sstevel@tonic-gate 7747c478bd9Sstevel@tonic-gate static struct zone_rctlvaltab * 7757c478bd9Sstevel@tonic-gate alloc_rctlvaltab(void) 7767c478bd9Sstevel@tonic-gate { 7777c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (struct zone_rctlvaltab))); 7787c478bd9Sstevel@tonic-gate } 7797c478bd9Sstevel@tonic-gate 7807c478bd9Sstevel@tonic-gate static char * 7817c478bd9Sstevel@tonic-gate rt_to_str(int res_type) 7827c478bd9Sstevel@tonic-gate { 7837c478bd9Sstevel@tonic-gate assert(res_type >= RT_MIN && res_type <= RT_MAX); 7847c478bd9Sstevel@tonic-gate return (res_types[res_type]); 7857c478bd9Sstevel@tonic-gate } 7867c478bd9Sstevel@tonic-gate 7877c478bd9Sstevel@tonic-gate static char * 7887c478bd9Sstevel@tonic-gate pt_to_str(int prop_type) 7897c478bd9Sstevel@tonic-gate { 7907c478bd9Sstevel@tonic-gate assert(prop_type >= PT_MIN && prop_type <= PT_MAX); 7917c478bd9Sstevel@tonic-gate return (prop_types[prop_type]); 7927c478bd9Sstevel@tonic-gate } 7937c478bd9Sstevel@tonic-gate 7947c478bd9Sstevel@tonic-gate static char * 7957c478bd9Sstevel@tonic-gate pvt_to_str(int pv_type) 7967c478bd9Sstevel@tonic-gate { 7977c478bd9Sstevel@tonic-gate assert(pv_type >= PROP_VAL_MIN && pv_type <= PROP_VAL_MAX); 7987c478bd9Sstevel@tonic-gate return (prop_val_types[pv_type]); 7997c478bd9Sstevel@tonic-gate } 8007c478bd9Sstevel@tonic-gate 8017c478bd9Sstevel@tonic-gate static char * 8027c478bd9Sstevel@tonic-gate cmd_to_str(int cmd_num) 8037c478bd9Sstevel@tonic-gate { 8047c478bd9Sstevel@tonic-gate assert(cmd_num >= CMD_MIN && cmd_num <= CMD_MAX); 8057c478bd9Sstevel@tonic-gate return (helptab[cmd_num].cmd_name); 8067c478bd9Sstevel@tonic-gate } 8077c478bd9Sstevel@tonic-gate 8083042b8b5Sbatschul /* PRINTFLIKE1 */ 8093042b8b5Sbatschul static void 8103042b8b5Sbatschul zerr(const char *fmt, ...) 8113042b8b5Sbatschul { 8123042b8b5Sbatschul va_list alist; 8133042b8b5Sbatschul static int last_lineno; 8143042b8b5Sbatschul 8153042b8b5Sbatschul /* lex_lineno has already been incremented in the lexer; compensate */ 8163042b8b5Sbatschul if (cmd_file_mode && lex_lineno > last_lineno) { 8173042b8b5Sbatschul if (strcmp(cmd_file_name, "-") == 0) 8183042b8b5Sbatschul (void) fprintf(stderr, gettext("On line %d:\n"), 8193042b8b5Sbatschul lex_lineno - 1); 8203042b8b5Sbatschul else 8213042b8b5Sbatschul (void) fprintf(stderr, gettext("On line %d of %s:\n"), 8223042b8b5Sbatschul lex_lineno - 1, cmd_file_name); 8233042b8b5Sbatschul last_lineno = lex_lineno; 8243042b8b5Sbatschul } 8253042b8b5Sbatschul va_start(alist, fmt); 8263042b8b5Sbatschul (void) vfprintf(stderr, fmt, alist); 8273042b8b5Sbatschul (void) fprintf(stderr, "\n"); 8283042b8b5Sbatschul va_end(alist); 8293042b8b5Sbatschul } 8303042b8b5Sbatschul 8317c478bd9Sstevel@tonic-gate /* 8327c478bd9Sstevel@tonic-gate * This is a separate function rather than a set of define's because of the 8337c478bd9Sstevel@tonic-gate * gettext() wrapping. 8347c478bd9Sstevel@tonic-gate */ 8357c478bd9Sstevel@tonic-gate 8367c478bd9Sstevel@tonic-gate /* 8377c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE 8387c478bd9Sstevel@tonic-gate * Each string below should have \t follow \n whenever needed; the 8397c478bd9Sstevel@tonic-gate * initial \t and the terminal \n will be provided by the calling function. 8407c478bd9Sstevel@tonic-gate */ 8417c478bd9Sstevel@tonic-gate 8427c478bd9Sstevel@tonic-gate static char * 8437c478bd9Sstevel@tonic-gate long_help(int cmd_num) 8447c478bd9Sstevel@tonic-gate { 8457c478bd9Sstevel@tonic-gate static char line[1024]; /* arbitrary large amount */ 8467c478bd9Sstevel@tonic-gate 8477c478bd9Sstevel@tonic-gate assert(cmd_num >= CMD_MIN && cmd_num <= CMD_MAX); 8487c478bd9Sstevel@tonic-gate switch (cmd_num) { 8497c478bd9Sstevel@tonic-gate case CMD_HELP: 8507c478bd9Sstevel@tonic-gate return (gettext("Prints help message.")); 8517c478bd9Sstevel@tonic-gate case CMD_CREATE: 8527c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 8537c478bd9Sstevel@tonic-gate gettext("Creates a configuration for the " 8547c478bd9Sstevel@tonic-gate "specified zone. %s should be\n\tused to " 8557c478bd9Sstevel@tonic-gate "begin configuring a new zone. If overwriting an " 8567c478bd9Sstevel@tonic-gate "existing\n\tconfiguration, the -F flag can be " 8577c478bd9Sstevel@tonic-gate "used to force the action. If\n\t-t template is " 8587c478bd9Sstevel@tonic-gate "given, creates a configuration identical to the\n" 8597c478bd9Sstevel@tonic-gate "\tspecified template, except that the zone name " 8609e518655Sgjelinek "is changed from\n\ttemplate to zonename. '%s -a' " 8619e518655Sgjelinek "creates a configuration from a\n\tdetached " 8629e518655Sgjelinek "zonepath. '%s -b' results in a blank " 8639e518655Sgjelinek "configuration.\n\t'%s' with no arguments applies " 8649e518655Sgjelinek "the Sun default settings."), 8657c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE), cmd_to_str(CMD_CREATE), 8669e518655Sgjelinek cmd_to_str(CMD_CREATE), cmd_to_str(CMD_CREATE)); 8677c478bd9Sstevel@tonic-gate return (line); 8687c478bd9Sstevel@tonic-gate case CMD_EXIT: 8697c478bd9Sstevel@tonic-gate return (gettext("Exits the program. The -F flag can " 8707c478bd9Sstevel@tonic-gate "be used to force the action.")); 8717c478bd9Sstevel@tonic-gate case CMD_EXPORT: 8727c478bd9Sstevel@tonic-gate return (gettext("Prints configuration to standard " 8737c478bd9Sstevel@tonic-gate "output, or to output-file if\n\tspecified, in " 8747c478bd9Sstevel@tonic-gate "a form suitable for use in a command-file.")); 8757c478bd9Sstevel@tonic-gate case CMD_ADD: 8767c478bd9Sstevel@tonic-gate return (gettext("Add specified resource to " 8777c478bd9Sstevel@tonic-gate "configuration.")); 8787c478bd9Sstevel@tonic-gate case CMD_DELETE: 8797c478bd9Sstevel@tonic-gate return (gettext("Deletes the specified zone. The -F " 8807c478bd9Sstevel@tonic-gate "flag can be used to force the\n\taction.")); 8817c478bd9Sstevel@tonic-gate case CMD_REMOVE: 8827c478bd9Sstevel@tonic-gate return (gettext("Remove specified resource from " 8830209230bSgjelinek "configuration. The -F flag can be used\n\tto " 8840209230bSgjelinek "force the action.")); 8857c478bd9Sstevel@tonic-gate case CMD_SELECT: 8867c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 8877c478bd9Sstevel@tonic-gate gettext("Selects a resource to modify. " 8887c478bd9Sstevel@tonic-gate "Resource modification is completed\n\twith the " 8897c478bd9Sstevel@tonic-gate "command \"%s\". The property name/value pairs " 8907c478bd9Sstevel@tonic-gate "must uniquely\n\tidentify a resource. Note that " 8917c478bd9Sstevel@tonic-gate "the curly braces ('{', '}') mean one\n\tor more " 8927c478bd9Sstevel@tonic-gate "of whatever is between them."), 8937c478bd9Sstevel@tonic-gate cmd_to_str(CMD_END)); 8947c478bd9Sstevel@tonic-gate return (line); 8957c478bd9Sstevel@tonic-gate case CMD_SET: 8967c478bd9Sstevel@tonic-gate return (gettext("Sets property values.")); 8970209230bSgjelinek case CMD_CLEAR: 8980209230bSgjelinek return (gettext("Clears property values.")); 8997c478bd9Sstevel@tonic-gate case CMD_INFO: 9007c478bd9Sstevel@tonic-gate return (gettext("Displays information about the " 9017c478bd9Sstevel@tonic-gate "current configuration. If resource\n\ttype is " 9027c478bd9Sstevel@tonic-gate "specified, displays only information about " 9037c478bd9Sstevel@tonic-gate "resources of\n\tthe relevant type. If resource " 9047c478bd9Sstevel@tonic-gate "id is specified, displays only\n\tinformation " 9057c478bd9Sstevel@tonic-gate "about that resource.")); 9067c478bd9Sstevel@tonic-gate case CMD_VERIFY: 9077c478bd9Sstevel@tonic-gate return (gettext("Verifies current configuration " 9087c478bd9Sstevel@tonic-gate "for correctness (some resource types\n\thave " 9097c478bd9Sstevel@tonic-gate "required properties).")); 9107c478bd9Sstevel@tonic-gate case CMD_COMMIT: 9117c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 9127c478bd9Sstevel@tonic-gate gettext("Commits current configuration. " 9137c478bd9Sstevel@tonic-gate "Configuration must be committed to\n\tbe used by " 9147c478bd9Sstevel@tonic-gate "%s. Until the configuration is committed, " 9157c478bd9Sstevel@tonic-gate "changes \n\tcan be removed with the %s " 9167c478bd9Sstevel@tonic-gate "command. This operation is\n\tattempted " 9177c478bd9Sstevel@tonic-gate "automatically upon completion of a %s " 9187c478bd9Sstevel@tonic-gate "session."), "zoneadm", cmd_to_str(CMD_REVERT), 9197c478bd9Sstevel@tonic-gate "zonecfg"); 9207c478bd9Sstevel@tonic-gate return (line); 9217c478bd9Sstevel@tonic-gate case CMD_REVERT: 9227c478bd9Sstevel@tonic-gate return (gettext("Reverts configuration back to the " 9237c478bd9Sstevel@tonic-gate "last committed state. The -F flag\n\tcan be " 9247c478bd9Sstevel@tonic-gate "used to force the action.")); 9257c478bd9Sstevel@tonic-gate case CMD_CANCEL: 9267c478bd9Sstevel@tonic-gate return (gettext("Cancels resource/property " 9277c478bd9Sstevel@tonic-gate "specification.")); 9287c478bd9Sstevel@tonic-gate case CMD_END: 9297c478bd9Sstevel@tonic-gate return (gettext("Ends resource/property " 9307c478bd9Sstevel@tonic-gate "specification.")); 9317c478bd9Sstevel@tonic-gate } 9327c478bd9Sstevel@tonic-gate /* NOTREACHED */ 9337e362f58Scomay return (NULL); 9347c478bd9Sstevel@tonic-gate } 9357c478bd9Sstevel@tonic-gate 936944b13ecSGary Mills /* 937944b13ecSGary Mills * Return the input filename appended to each component of the path 938944b13ecSGary Mills * or the filename itself if it is absolute. 939944b13ecSGary Mills * Parameters: path string, file name, output string. 940944b13ecSGary Mills */ 941944b13ecSGary Mills /* Copied almost verbatim from libtnfctl/prb_findexec.c */ 942944b13ecSGary Mills static const char * 943944b13ecSGary Mills exec_cat(const char *s1, const char *s2, char *si) 944944b13ecSGary Mills { 945944b13ecSGary Mills char *s; 946944b13ecSGary Mills /* Number of remaining characters in s */ 947944b13ecSGary Mills int cnt = PATH_MAX + 1; 948944b13ecSGary Mills 949944b13ecSGary Mills s = si; 950944b13ecSGary Mills while (*s1 && *s1 != ':') { /* Copy first component of path to si */ 951944b13ecSGary Mills if (cnt > 0) { 952944b13ecSGary Mills *s++ = *s1++; 953944b13ecSGary Mills cnt--; 954944b13ecSGary Mills } else { 955944b13ecSGary Mills s1++; 956944b13ecSGary Mills } 957944b13ecSGary Mills } 958944b13ecSGary Mills if (si != s && cnt > 0) { /* Add slash if s2 is not absolute */ 959944b13ecSGary Mills *s++ = '/'; 960944b13ecSGary Mills cnt--; 961944b13ecSGary Mills } 962944b13ecSGary Mills while (*s2 && cnt > 0) { /* Copy s2 to si */ 963944b13ecSGary Mills *s++ = *s2++; 964944b13ecSGary Mills cnt--; 965944b13ecSGary Mills } 966944b13ecSGary Mills *s = '\0'; /* Terminate the output string */ 967944b13ecSGary Mills return (*s1 ? ++s1 : NULL); /* Return next path component or NULL */ 968944b13ecSGary Mills } 969944b13ecSGary Mills 970944b13ecSGary Mills /* Determine that a name exists in PATH */ 971944b13ecSGary Mills /* Copied with changes from libtnfctl/prb_findexec.c */ 972944b13ecSGary Mills static int 973944b13ecSGary Mills path_find(const char *name) 974944b13ecSGary Mills { 975944b13ecSGary Mills const char *pathstr; 976944b13ecSGary Mills char fname[PATH_MAX + 2]; 977944b13ecSGary Mills const char *cp; 978944b13ecSGary Mills struct stat stat_buf; 979944b13ecSGary Mills 980944b13ecSGary Mills if ((pathstr = getenv("PATH")) == NULL) { 981944b13ecSGary Mills if (geteuid() == 0 || getuid() == 0) 982944b13ecSGary Mills pathstr = "/usr/sbin:/usr/bin"; 983944b13ecSGary Mills else 984944b13ecSGary Mills pathstr = "/usr/bin:"; 985944b13ecSGary Mills } 986944b13ecSGary Mills cp = strchr(name, '/') ? (const char *) "" : pathstr; 987944b13ecSGary Mills 988944b13ecSGary Mills do { 989944b13ecSGary Mills cp = exec_cat(cp, name, fname); 990944b13ecSGary Mills if (stat(fname, &stat_buf) != -1) { 991944b13ecSGary Mills /* successful find of the file */ 992944b13ecSGary Mills return (0); 993944b13ecSGary Mills } 994944b13ecSGary Mills } while (cp != NULL); 995944b13ecSGary Mills 996944b13ecSGary Mills return (-1); 997944b13ecSGary Mills } 998944b13ecSGary Mills 999944b13ecSGary Mills static FILE * 1000*d2a70789SRichard Lowe pager_open(void) 1001*d2a70789SRichard Lowe { 1002944b13ecSGary Mills FILE *newfp; 1003944b13ecSGary Mills char *pager, *space; 1004944b13ecSGary Mills 1005944b13ecSGary Mills pager = getenv("PAGER"); 1006944b13ecSGary Mills if (pager == NULL || *pager == '\0') 1007944b13ecSGary Mills pager = PAGER; 1008944b13ecSGary Mills 1009944b13ecSGary Mills space = strchr(pager, ' '); 1010944b13ecSGary Mills if (space) 1011944b13ecSGary Mills *space = '\0'; 1012944b13ecSGary Mills if (path_find(pager) == 0) { 1013944b13ecSGary Mills if (space) 1014944b13ecSGary Mills *space = ' '; 1015944b13ecSGary Mills if ((newfp = popen(pager, "w")) == NULL) 1016944b13ecSGary Mills zerr(gettext("PAGER open failed (%s)."), 1017944b13ecSGary Mills strerror(errno)); 1018944b13ecSGary Mills return (newfp); 1019944b13ecSGary Mills } else { 1020944b13ecSGary Mills zerr(gettext("PAGER %s does not exist (%s)."), 1021944b13ecSGary Mills pager, strerror(errno)); 1022944b13ecSGary Mills } 1023944b13ecSGary Mills return (NULL); 1024944b13ecSGary Mills } 1025944b13ecSGary Mills 1026944b13ecSGary Mills static void 1027*d2a70789SRichard Lowe pager_close(FILE *fp) 1028*d2a70789SRichard Lowe { 1029944b13ecSGary Mills int status; 1030944b13ecSGary Mills 1031944b13ecSGary Mills status = pclose(fp); 1032944b13ecSGary Mills if (status == -1) 1033944b13ecSGary Mills zerr(gettext("PAGER close failed (%s)."), 1034944b13ecSGary Mills strerror(errno)); 1035944b13ecSGary Mills } 1036944b13ecSGary Mills 10377c478bd9Sstevel@tonic-gate /* 10387c478bd9Sstevel@tonic-gate * Called with verbose TRUE when help is explicitly requested, FALSE for 10397c478bd9Sstevel@tonic-gate * unexpected errors. 10407c478bd9Sstevel@tonic-gate */ 10417c478bd9Sstevel@tonic-gate 10427c478bd9Sstevel@tonic-gate void 1043bbec428eSgjelinek usage(boolean_t verbose, uint_t flags) 10447c478bd9Sstevel@tonic-gate { 10453042b8b5Sbatschul FILE *fp = verbose ? stdout : stderr; 10463042b8b5Sbatschul FILE *newfp; 1047bbec428eSgjelinek boolean_t need_to_close = B_FALSE; 10487c478bd9Sstevel@tonic-gate int i; 10497c478bd9Sstevel@tonic-gate 10507c478bd9Sstevel@tonic-gate /* don't page error output */ 10517c478bd9Sstevel@tonic-gate if (verbose && interactive_mode) { 1052944b13ecSGary Mills if ((newfp = pager_open()) != NULL) { 1053944b13ecSGary Mills need_to_close = B_TRUE; 1054944b13ecSGary Mills fp = newfp; 10557c478bd9Sstevel@tonic-gate } 10567c478bd9Sstevel@tonic-gate } 10573042b8b5Sbatschul 10587c478bd9Sstevel@tonic-gate if (flags & HELP_META) { 10597c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("More help is available for the " 10607c478bd9Sstevel@tonic-gate "following:\n")); 10617c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\n\tcommands ('%s commands')\n", 10627c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 10637c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\tsyntax ('%s syntax')\n", 10647c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 10657c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\tusage ('%s usage')\n\n", 10667c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 10677c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("You may also obtain help on any " 10687c478bd9Sstevel@tonic-gate "command by typing '%s <command-name>.'\n"), 10697c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 10707c478bd9Sstevel@tonic-gate } 10717c478bd9Sstevel@tonic-gate if (flags & HELP_RES_SCOPE) { 10727c478bd9Sstevel@tonic-gate switch (resource_scope) { 10737c478bd9Sstevel@tonic-gate case RT_FS: 10747c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 10757c478bd9Sstevel@tonic-gate "used to configure a file-system.\n"), 10767c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 10777c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 10787c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10797c478bd9Sstevel@tonic-gate pt_to_str(PT_DIR), gettext("<path>")); 10807c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10817c478bd9Sstevel@tonic-gate pt_to_str(PT_SPECIAL), gettext("<path>")); 10827c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10837c478bd9Sstevel@tonic-gate pt_to_str(PT_RAW), gettext("<raw-device>")); 10847c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10857c478bd9Sstevel@tonic-gate pt_to_str(PT_TYPE), gettext("<file-system type>")); 10867c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s %s\n", cmd_to_str(CMD_ADD), 10877c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS), 10887c478bd9Sstevel@tonic-gate gettext("<file-system options>")); 1089ffbafc53Scomay (void) fprintf(fp, "\t%s %s %s\n", 1090ffbafc53Scomay cmd_to_str(CMD_REMOVE), pt_to_str(PT_OPTIONS), 1091ffbafc53Scomay gettext("<file-system options>")); 10927c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Consult the file-system " 10937c478bd9Sstevel@tonic-gate "specific manual page, such as mount_ufs(1M), " 10947c478bd9Sstevel@tonic-gate "for\ndetails about file-system options. Note " 10957c478bd9Sstevel@tonic-gate "that any file-system options with an\nembedded " 10967c478bd9Sstevel@tonic-gate "'=' character must be enclosed in double quotes, " 10977c478bd9Sstevel@tonic-gate /*CSTYLED*/ 10987c478bd9Sstevel@tonic-gate "such as \"%s=5\".\n"), MNTOPT_RETRY); 10997c478bd9Sstevel@tonic-gate break; 11007c478bd9Sstevel@tonic-gate case RT_NET: 11017c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 11027c478bd9Sstevel@tonic-gate "used to configure a network interface.\n"), 11037c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 11047c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 11057c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 11067c478bd9Sstevel@tonic-gate pt_to_str(PT_ADDRESS), gettext("<IP-address>")); 1107550b6e40SSowmini Varadhan (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 1108550b6e40SSowmini Varadhan pt_to_str(PT_ALLOWED_ADDRESS), 1109550b6e40SSowmini Varadhan gettext("<IP-address>")); 11107c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 11117c478bd9Sstevel@tonic-gate pt_to_str(PT_PHYSICAL), gettext("<interface>")); 11127c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("See ifconfig(1M) for " 11137c478bd9Sstevel@tonic-gate "details of the <interface> string.\n")); 1114550b6e40SSowmini Varadhan (void) fprintf(fp, gettext("%s %s is valid " 1115550b6e40SSowmini Varadhan "if the %s property is set to %s, otherwise it " 1116de860bd9Sgfaden "must not be set.\n"), 1117f4b3ec61Sdh cmd_to_str(CMD_SET), pt_to_str(PT_ADDRESS), 1118550b6e40SSowmini Varadhan pt_to_str(PT_IPTYPE), gettext("shared")); 1119550b6e40SSowmini Varadhan (void) fprintf(fp, gettext("%s %s is valid " 1120550b6e40SSowmini Varadhan "if the %s property is set to %s, otherwise it " 1121550b6e40SSowmini Varadhan "must not be set.\n"), 1122550b6e40SSowmini Varadhan cmd_to_str(CMD_SET), pt_to_str(PT_ALLOWED_ADDRESS), 1123550b6e40SSowmini Varadhan pt_to_str(PT_IPTYPE), gettext("exclusive")); 1124550b6e40SSowmini Varadhan (void) fprintf(fp, gettext("\t%s %s=%s\n%s %s " 1125550b6e40SSowmini Varadhan "is valid if the %s or %s property is set, " 1126550b6e40SSowmini Varadhan "otherwise it must not be set\n"), 1127550b6e40SSowmini Varadhan cmd_to_str(CMD_SET), 1128550b6e40SSowmini Varadhan pt_to_str(PT_DEFROUTER), gettext("<IP-address>"), 1129de860bd9Sgfaden cmd_to_str(CMD_SET), pt_to_str(PT_DEFROUTER), 1130550b6e40SSowmini Varadhan gettext(pt_to_str(PT_ADDRESS)), 1131550b6e40SSowmini Varadhan gettext(pt_to_str(PT_ALLOWED_ADDRESS))); 11327c478bd9Sstevel@tonic-gate break; 11337c478bd9Sstevel@tonic-gate case RT_DEVICE: 11347c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 11357c478bd9Sstevel@tonic-gate "used to configure a device node.\n"), 11367c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 11377c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 11387c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 11397c478bd9Sstevel@tonic-gate pt_to_str(PT_MATCH), gettext("<device-path>")); 11407c478bd9Sstevel@tonic-gate break; 11417c478bd9Sstevel@tonic-gate case RT_RCTL: 11427c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 11437c478bd9Sstevel@tonic-gate "used to configure a resource control.\n"), 11447c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 11457c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 11467c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 11477c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), gettext("<string>")); 11487c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s (%s=%s,%s=%s,%s=%s)\n", 11497c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), pt_to_str(PT_VALUE), 11507c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV), gettext("<priv-value>"), 11517c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT), gettext("<number>"), 11527c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION), gettext("<action-value>")); 1153ffbafc53Scomay (void) fprintf(fp, "\t%s %s (%s=%s,%s=%s,%s=%s)\n", 1154ffbafc53Scomay cmd_to_str(CMD_REMOVE), pt_to_str(PT_VALUE), 1155ffbafc53Scomay pt_to_str(PT_PRIV), gettext("<priv-value>"), 1156ffbafc53Scomay pt_to_str(PT_LIMIT), gettext("<number>"), 1157ffbafc53Scomay pt_to_str(PT_ACTION), gettext("<action-value>")); 11587c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s\n\t%s := privileged\n" 11597c478bd9Sstevel@tonic-gate "\t%s := none | deny\n", gettext("Where"), 11607c478bd9Sstevel@tonic-gate gettext("<priv-value>"), gettext("<action-value>")); 11617c478bd9Sstevel@tonic-gate break; 11627c478bd9Sstevel@tonic-gate case RT_ATTR: 11637c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 11647c478bd9Sstevel@tonic-gate "used to configure a generic attribute.\n"), 11657c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 11667c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 11677c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 11687c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), gettext("<name>")); 11697c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=boolean\n", 11707c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_TYPE)); 11717c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=true | false\n", 11727c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_VALUE)); 11737c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("or\n")); 11747c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=int\n", cmd_to_str(CMD_SET), 11757c478bd9Sstevel@tonic-gate pt_to_str(PT_TYPE)); 11767c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 11777c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), gettext("<integer>")); 11787c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("or\n")); 11797c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=string\n", 11807c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_TYPE)); 11817c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 11827c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), gettext("<string>")); 11837c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("or\n")); 11847c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=uint\n", 11857c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_TYPE)); 11867c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 11877c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), gettext("<unsigned integer>")); 11887c478bd9Sstevel@tonic-gate break; 1189fa9e4066Sahrens case RT_DATASET: 1190fa9e4066Sahrens (void) fprintf(fp, gettext("The '%s' resource scope is " 1191fa9e4066Sahrens "used to export ZFS datasets.\n"), 1192fa9e4066Sahrens rt_to_str(resource_scope)); 1193fa9e4066Sahrens (void) fprintf(fp, gettext("Valid commands:\n")); 1194fa9e4066Sahrens (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 1195fa9e4066Sahrens pt_to_str(PT_NAME), gettext("<name>")); 1196fa9e4066Sahrens break; 11970209230bSgjelinek case RT_DCPU: 11980209230bSgjelinek (void) fprintf(fp, gettext("The '%s' resource scope " 11990209230bSgjelinek "configures the 'pools' facility to dedicate\na " 12000209230bSgjelinek "subset of the system's processors to this zone " 12010209230bSgjelinek "while it is running.\n"), 12020209230bSgjelinek rt_to_str(resource_scope)); 12030209230bSgjelinek (void) fprintf(fp, gettext("Valid commands:\n")); 12040209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 12050209230bSgjelinek pt_to_str(PT_NCPUS), 12060209230bSgjelinek gettext("<unsigned integer | range>")); 12070209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 12080209230bSgjelinek pt_to_str(PT_IMPORTANCE), 12090209230bSgjelinek gettext("<unsigned integer>")); 12100209230bSgjelinek break; 1211c97ad5cdSakolb case RT_PCAP: 1212c97ad5cdSakolb (void) fprintf(fp, gettext("The '%s' resource scope is " 1213c97ad5cdSakolb "used to set an upper limit (a cap) on the\n" 1214c97ad5cdSakolb "percentage of CPU that can be used by this zone. " 1215c97ad5cdSakolb "A '%s' value of 1\ncorresponds to one cpu. The " 1216c97ad5cdSakolb "value can be set higher than 1, up to the total\n" 1217c97ad5cdSakolb "number of CPUs on the system. The value can " 1218c97ad5cdSakolb "also be less than 1,\nrepresenting a fraction of " 1219c97ad5cdSakolb "a cpu.\n"), 1220c97ad5cdSakolb rt_to_str(resource_scope), pt_to_str(PT_NCPUS)); 1221c97ad5cdSakolb (void) fprintf(fp, gettext("Valid commands:\n")); 1222c97ad5cdSakolb (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 1223c97ad5cdSakolb pt_to_str(PT_NCPUS), gettext("<unsigned decimal>")); 1224c97ad5cdSakolb break; 12250209230bSgjelinek case RT_MCAP: 12260209230bSgjelinek (void) fprintf(fp, gettext("The '%s' resource scope is " 12270209230bSgjelinek "used to set an upper limit (a cap) on the\n" 12280209230bSgjelinek "amount of physical memory, swap space and locked " 12290209230bSgjelinek "memory that can be used by\nthis zone.\n"), 12300209230bSgjelinek rt_to_str(resource_scope)); 12310209230bSgjelinek (void) fprintf(fp, gettext("Valid commands:\n")); 12320209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 12330209230bSgjelinek pt_to_str(PT_PHYSICAL), 12340209230bSgjelinek gettext("<qualified unsigned decimal>")); 12350209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 12360209230bSgjelinek pt_to_str(PT_SWAP), 12370209230bSgjelinek gettext("<qualified unsigned decimal>")); 12380209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 12390209230bSgjelinek pt_to_str(PT_LOCKED), 12400209230bSgjelinek gettext("<qualified unsigned decimal>")); 12410209230bSgjelinek break; 1242cb8a054bSGlenn Faden case RT_ADMIN: 1243cb8a054bSGlenn Faden (void) fprintf(fp, gettext("The '%s' resource scope is " 1244cb8a054bSGlenn Faden "used to delegate specific zone management\n" 1245cb8a054bSGlenn Faden "rights to users and roles. These rights are " 1246cb8a054bSGlenn Faden "only applicable to this zone.\n"), 1247cb8a054bSGlenn Faden rt_to_str(resource_scope)); 1248cb8a054bSGlenn Faden (void) fprintf(fp, gettext("Valid commands:\n")); 1249cb8a054bSGlenn Faden (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 1250cb8a054bSGlenn Faden pt_to_str(PT_USER), 1251cb8a054bSGlenn Faden gettext("<single user or role name>")); 1252cb8a054bSGlenn Faden (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 1253cb8a054bSGlenn Faden pt_to_str(PT_AUTHS), 1254cb8a054bSGlenn Faden gettext("<comma separated list>")); 1255cb8a054bSGlenn Faden break; 1256*d2a70789SRichard Lowe case RT_SECFLAGS: 1257*d2a70789SRichard Lowe (void) fprintf(fp, gettext("The '%s' resource scope is " 1258*d2a70789SRichard Lowe "used to specify the default security-flags\n" 1259*d2a70789SRichard Lowe "of this zone, and their upper and lower bound.\n"), 1260*d2a70789SRichard Lowe rt_to_str(resource_scope)); 1261*d2a70789SRichard Lowe (void) fprintf(fp, "\t%s %s=%s\n", 1262*d2a70789SRichard Lowe cmd_to_str(CMD_SET), pt_to_str(PT_DEFAULT), 1263*d2a70789SRichard Lowe gettext("<security flags>")); 1264*d2a70789SRichard Lowe (void) fprintf(fp, "\t%s %s=%s\n", 1265*d2a70789SRichard Lowe cmd_to_str(CMD_SET), pt_to_str(PT_LOWER), 1266*d2a70789SRichard Lowe gettext("<security flags>")); 1267*d2a70789SRichard Lowe (void) fprintf(fp, "\t%s %s=%s\n", 1268*d2a70789SRichard Lowe cmd_to_str(CMD_SET), pt_to_str(PT_UPPER), 1269*d2a70789SRichard Lowe gettext("<security flags>")); 1270*d2a70789SRichard Lowe break; 12717c478bd9Sstevel@tonic-gate } 12727c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("And from any resource scope, you " 12737c478bd9Sstevel@tonic-gate "can:\n")); 12747c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", cmd_to_str(CMD_END), 12757c478bd9Sstevel@tonic-gate gettext("(to conclude this operation)")); 12767c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", cmd_to_str(CMD_CANCEL), 12777c478bd9Sstevel@tonic-gate gettext("(to cancel this operation)")); 12787c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", cmd_to_str(CMD_EXIT), 12797c478bd9Sstevel@tonic-gate gettext("(to exit the zonecfg utility)")); 12807c478bd9Sstevel@tonic-gate } 12817c478bd9Sstevel@tonic-gate if (flags & HELP_USAGE) { 12827c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\t%s %s\n", gettext("usage"), 12837c478bd9Sstevel@tonic-gate execname, cmd_to_str(CMD_HELP)); 12847c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s -z <zone>\t\t\t(%s)\n", 12857c478bd9Sstevel@tonic-gate execname, gettext("interactive")); 12867c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s -z <zone> <command>\n", execname); 12877c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s -z <zone> -f <command-file>\n", 12887c478bd9Sstevel@tonic-gate execname); 12897c478bd9Sstevel@tonic-gate } 12907c478bd9Sstevel@tonic-gate if (flags & HELP_SUBCMDS) { 12917c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n\n", gettext("Commands")); 12927c478bd9Sstevel@tonic-gate for (i = 0; i <= CMD_MAX; i++) { 12937c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s\n", helptab[i].short_usage); 12947c478bd9Sstevel@tonic-gate if (verbose) 12957c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\n\n", long_help(i)); 12967c478bd9Sstevel@tonic-gate } 12977c478bd9Sstevel@tonic-gate } 12987c478bd9Sstevel@tonic-gate if (flags & HELP_SYNTAX) { 12997c478bd9Sstevel@tonic-gate if (!verbose) 13007c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\n"); 13017c478bd9Sstevel@tonic-gate (void) fprintf(fp, "<zone> := [A-Za-z0-9][A-Za-z0-9_.-]*\n"); 13027c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("\t(except the reserved words " 13037c478bd9Sstevel@tonic-gate "'%s' and anything starting with '%s')\n"), "global", 13047c478bd9Sstevel@tonic-gate "SUNW"); 13057c478bd9Sstevel@tonic-gate (void) fprintf(fp, 13067c478bd9Sstevel@tonic-gate gettext("\tName must be less than %d characters.\n"), 13077c478bd9Sstevel@tonic-gate ZONENAME_MAX); 13087c478bd9Sstevel@tonic-gate if (verbose) 13097c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\n"); 13107c478bd9Sstevel@tonic-gate } 13117c478bd9Sstevel@tonic-gate if (flags & HELP_NETADDR) { 13127c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("\n<net-addr> :=")); 13137c478bd9Sstevel@tonic-gate (void) fprintf(fp, 13147c478bd9Sstevel@tonic-gate gettext("\t<IPv4-address>[/<IPv4-prefix-length>] |\n")); 13157c478bd9Sstevel@tonic-gate (void) fprintf(fp, 13167c478bd9Sstevel@tonic-gate gettext("\t\t<IPv6-address>/<IPv6-prefix-length> |\n")); 13177c478bd9Sstevel@tonic-gate (void) fprintf(fp, 13187c478bd9Sstevel@tonic-gate gettext("\t\t<hostname>[/<IPv4-prefix-length>]\n")); 13197c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("See inet(3SOCKET) for IPv4 and " 13207c478bd9Sstevel@tonic-gate "IPv6 address syntax.\n")); 13217c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("<IPv4-prefix-length> := [0-32]\n")); 13227c478bd9Sstevel@tonic-gate (void) fprintf(fp, 13237c478bd9Sstevel@tonic-gate gettext("<IPv6-prefix-length> := [0-128]\n")); 13247c478bd9Sstevel@tonic-gate (void) fprintf(fp, 13257c478bd9Sstevel@tonic-gate gettext("<hostname> := [A-Za-z0-9][A-Za-z0-9-.]*\n")); 13267c478bd9Sstevel@tonic-gate } 13277c478bd9Sstevel@tonic-gate if (flags & HELP_RESOURCES) { 13286e1ae2a3SGary Pennington (void) fprintf(fp, "<%s> := %s | %s | %s | %s | %s |\n\t" 1329cb8a054bSGlenn Faden "%s | %s | %s | %s | %s\n\n", 13307c478bd9Sstevel@tonic-gate gettext("resource type"), rt_to_str(RT_FS), 13316e1ae2a3SGary Pennington rt_to_str(RT_NET), rt_to_str(RT_DEVICE), 13329e7542f4Sdp rt_to_str(RT_RCTL), rt_to_str(RT_ATTR), 13330209230bSgjelinek rt_to_str(RT_DATASET), rt_to_str(RT_DCPU), 1334cb8a054bSGlenn Faden rt_to_str(RT_PCAP), rt_to_str(RT_MCAP), 1335*d2a70789SRichard Lowe rt_to_str(RT_ADMIN), rt_to_str(RT_SECFLAGS)); 13367c478bd9Sstevel@tonic-gate } 13377c478bd9Sstevel@tonic-gate if (flags & HELP_PROPS) { 13387c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("For resource type ... there are " 13397c478bd9Sstevel@tonic-gate "property types ...:\n")); 1340087719fdSdp (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 1341087719fdSdp pt_to_str(PT_ZONENAME)); 13427c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 13437c478bd9Sstevel@tonic-gate pt_to_str(PT_ZONEPATH)); 13449acbbeafSnn (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 13459acbbeafSnn pt_to_str(PT_BRAND)); 13467c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 13477c478bd9Sstevel@tonic-gate pt_to_str(PT_AUTOBOOT)); 13483f2f09c1Sdp (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 13493f2f09c1Sdp pt_to_str(PT_BOOTARGS)); 13507c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 13517c478bd9Sstevel@tonic-gate pt_to_str(PT_POOL)); 1352ffbafc53Scomay (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 1353ffbafc53Scomay pt_to_str(PT_LIMITPRIV)); 13540209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 13550209230bSgjelinek pt_to_str(PT_SCHED)); 1356f4b3ec61Sdh (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 1357f4b3ec61Sdh pt_to_str(PT_IPTYPE)); 13585679c89fSjv (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 13595679c89fSjv pt_to_str(PT_HOSTID)); 13600fbb751dSJohn Levon (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 13610fbb751dSJohn Levon pt_to_str(PT_FS_ALLOWED)); 13620209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 13630209230bSgjelinek pt_to_str(PT_MAXLWPS)); 1364ff19e029SMenno Lageman (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 1365ff19e029SMenno Lageman pt_to_str(PT_MAXPROCS)); 13660209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 13670209230bSgjelinek pt_to_str(PT_MAXSHMMEM)); 13680209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 13690209230bSgjelinek pt_to_str(PT_MAXSHMIDS)); 13700209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 13710209230bSgjelinek pt_to_str(PT_MAXMSGIDS)); 13720209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 13730209230bSgjelinek pt_to_str(PT_MAXSEMIDS)); 13740209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 13750209230bSgjelinek pt_to_str(PT_SHARES)); 13766d4d1c0dSbatschul (void) fprintf(fp, "\t%s\t\t%s, %s, %s, %s, %s\n", 13776d4d1c0dSbatschul rt_to_str(RT_FS), pt_to_str(PT_DIR), 13786d4d1c0dSbatschul pt_to_str(PT_SPECIAL), pt_to_str(PT_RAW), 13796d4d1c0dSbatschul pt_to_str(PT_TYPE), pt_to_str(PT_OPTIONS)); 1380550b6e40SSowmini Varadhan (void) fprintf(fp, "\t%s\t\t%s, %s, %s|%s\n", rt_to_str(RT_NET), 1381550b6e40SSowmini Varadhan pt_to_str(PT_ADDRESS), pt_to_str(PT_ALLOWED_ADDRESS), 1382550b6e40SSowmini Varadhan pt_to_str(PT_PHYSICAL), pt_to_str(PT_DEFROUTER)); 13837c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s\n", rt_to_str(RT_DEVICE), 13847c478bd9Sstevel@tonic-gate pt_to_str(PT_MATCH)); 13857c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s, %s\n", rt_to_str(RT_RCTL), 13867c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), pt_to_str(PT_VALUE)); 13877c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s, %s, %s\n", rt_to_str(RT_ATTR), 13887c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), pt_to_str(PT_TYPE), 13897c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE)); 1390fa9e4066Sahrens (void) fprintf(fp, "\t%s\t\t%s\n", rt_to_str(RT_DATASET), 1391fa9e4066Sahrens pt_to_str(PT_NAME)); 13920209230bSgjelinek (void) fprintf(fp, "\t%s\t%s, %s\n", rt_to_str(RT_DCPU), 13930209230bSgjelinek pt_to_str(PT_NCPUS), pt_to_str(PT_IMPORTANCE)); 1394c97ad5cdSakolb (void) fprintf(fp, "\t%s\t%s\n", rt_to_str(RT_PCAP), 1395c97ad5cdSakolb pt_to_str(PT_NCPUS)); 13960209230bSgjelinek (void) fprintf(fp, "\t%s\t%s, %s, %s\n", rt_to_str(RT_MCAP), 13970209230bSgjelinek pt_to_str(PT_PHYSICAL), pt_to_str(PT_SWAP), 13980209230bSgjelinek pt_to_str(PT_LOCKED)); 1399cb8a054bSGlenn Faden (void) fprintf(fp, "\t%s\t\t%s, %s\n", rt_to_str(RT_ADMIN), 1400cb8a054bSGlenn Faden pt_to_str(PT_USER), pt_to_str(PT_AUTHS)); 1401*d2a70789SRichard Lowe (void) fprintf(fp, "\t%s\t\t%s, %s, %s\n", 1402*d2a70789SRichard Lowe rt_to_str(RT_SECFLAGS), pt_to_str(PT_DEFAULT), 1403*d2a70789SRichard Lowe pt_to_str(PT_LOWER), pt_to_str(PT_UPPER)); 14047c478bd9Sstevel@tonic-gate } 14057c478bd9Sstevel@tonic-gate if (need_to_close) 1406944b13ecSGary Mills (void) pager_close(fp); 14077c478bd9Sstevel@tonic-gate } 14087c478bd9Sstevel@tonic-gate 14097c478bd9Sstevel@tonic-gate static void 1410bbec428eSgjelinek zone_perror(char *prefix, int err, boolean_t set_saw) 14117c478bd9Sstevel@tonic-gate { 14127c478bd9Sstevel@tonic-gate zerr("%s: %s", prefix, zonecfg_strerror(err)); 14137c478bd9Sstevel@tonic-gate if (set_saw) 1414bbec428eSgjelinek saw_error = B_TRUE; 14157c478bd9Sstevel@tonic-gate } 14167c478bd9Sstevel@tonic-gate 14177c478bd9Sstevel@tonic-gate /* 14187c478bd9Sstevel@tonic-gate * zone_perror() expects a single string, but for remove and select 14197c478bd9Sstevel@tonic-gate * we have both the command and the resource type, so this wrapper 14207c478bd9Sstevel@tonic-gate * function serves the same purpose in a slightly different way. 14217c478bd9Sstevel@tonic-gate */ 14227c478bd9Sstevel@tonic-gate 14237c478bd9Sstevel@tonic-gate static void 1424bbec428eSgjelinek z_cmd_rt_perror(int cmd_num, int res_num, int err, boolean_t set_saw) 14257c478bd9Sstevel@tonic-gate { 14267c478bd9Sstevel@tonic-gate zerr("%s %s: %s", cmd_to_str(cmd_num), rt_to_str(res_num), 14277c478bd9Sstevel@tonic-gate zonecfg_strerror(err)); 14287c478bd9Sstevel@tonic-gate if (set_saw) 1429bbec428eSgjelinek saw_error = B_TRUE; 14307c478bd9Sstevel@tonic-gate } 14317c478bd9Sstevel@tonic-gate 14327c478bd9Sstevel@tonic-gate /* returns Z_OK if successful, Z_foo from <libzonecfg.h> otherwise */ 14337c478bd9Sstevel@tonic-gate static int 1434bbec428eSgjelinek initialize(boolean_t handle_expected) 14357c478bd9Sstevel@tonic-gate { 14367c478bd9Sstevel@tonic-gate int err; 14379acbbeafSnn char brandname[MAXNAMELEN]; 14387c478bd9Sstevel@tonic-gate 14397c478bd9Sstevel@tonic-gate if (zonecfg_check_handle(handle) != Z_OK) { 14407c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_handle(zone, handle)) == Z_OK) { 1441bbec428eSgjelinek got_handle = B_TRUE; 14429acbbeafSnn if (zonecfg_get_brand(handle, brandname, 14439acbbeafSnn sizeof (brandname)) != Z_OK) { 14449acbbeafSnn zerr("Zone %s is inconsistent: missing " 14459acbbeafSnn "brand attribute", zone); 14469acbbeafSnn exit(Z_ERR); 14479acbbeafSnn } 14489acbbeafSnn if ((brand = brand_open(brandname)) == NULL) { 14499acbbeafSnn zerr("Zone %s uses non-existent brand \"%s\"." 14509acbbeafSnn " Unable to continue", zone, brandname); 14519acbbeafSnn exit(Z_ERR); 14529acbbeafSnn } 1453cb8a054bSGlenn Faden /* 1454cb8a054bSGlenn Faden * If the user_attr file is newer than 1455cb8a054bSGlenn Faden * the zone config file, the admins 1456cb8a054bSGlenn Faden * may need to be updated since the 1457cb8a054bSGlenn Faden * RBAC files are authoritative for 1458cb8a054bSGlenn Faden * authorization checks. 1459cb8a054bSGlenn Faden */ 1460cb8a054bSGlenn Faden err = zonecfg_update_userauths(handle, zone); 1461cb8a054bSGlenn Faden if (err == Z_OK) { 1462cb8a054bSGlenn Faden zerr(gettext("The administrative rights " 1463cb8a054bSGlenn Faden "were updated to match " 1464cb8a054bSGlenn Faden "the current RBAC configuration.\n" 1465cb8a054bSGlenn Faden "Use \"info admin\" and \"revert\" to " 1466cb8a054bSGlenn Faden "compare with the previous settings.")); 1467cb8a054bSGlenn Faden need_to_commit = B_TRUE; 1468cb8a054bSGlenn Faden } else if (err != Z_NO_ENTRY) { 1469cb8a054bSGlenn Faden zerr(gettext("failed to update " 1470cb8a054bSGlenn Faden "admin rights.")); 1471cb8a054bSGlenn Faden exit(Z_ERR); 1472cb8a054bSGlenn Faden } else if (need_to_commit) { 1473cb8a054bSGlenn Faden zerr(gettext("admin rights were updated " 1474cb8a054bSGlenn Faden "to match RBAC configuration.")); 1475cb8a054bSGlenn Faden } 1476cb8a054bSGlenn Faden 14770209230bSgjelinek } else if (global_zone && err == Z_NO_ZONE && !got_handle && 14780209230bSgjelinek !read_only_mode) { 14790209230bSgjelinek /* 14800209230bSgjelinek * We implicitly create the global zone config if it 14810209230bSgjelinek * doesn't exist. 14820209230bSgjelinek */ 14830209230bSgjelinek zone_dochandle_t tmphandle; 14840209230bSgjelinek 14850209230bSgjelinek if ((tmphandle = zonecfg_init_handle()) == NULL) { 1486bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 14870209230bSgjelinek exit(Z_ERR); 14880209230bSgjelinek } 14890209230bSgjelinek 14900209230bSgjelinek err = zonecfg_get_template_handle("SUNWblank", zone, 14910209230bSgjelinek tmphandle); 14920209230bSgjelinek 14930209230bSgjelinek if (err != Z_OK) { 14940209230bSgjelinek zonecfg_fini_handle(tmphandle); 1495bbec428eSgjelinek zone_perror("SUNWblank", err, B_TRUE); 14960209230bSgjelinek return (err); 14970209230bSgjelinek } 14980209230bSgjelinek 1499bbec428eSgjelinek need_to_commit = B_TRUE; 15000209230bSgjelinek zonecfg_fini_handle(handle); 15010209230bSgjelinek handle = tmphandle; 1502bbec428eSgjelinek got_handle = B_TRUE; 15030209230bSgjelinek 15047c478bd9Sstevel@tonic-gate } else { 15057c478bd9Sstevel@tonic-gate zone_perror(zone, err, handle_expected || got_handle); 15067c478bd9Sstevel@tonic-gate if (err == Z_NO_ZONE && !got_handle && 15077c478bd9Sstevel@tonic-gate interactive_mode && !read_only_mode) 15087c478bd9Sstevel@tonic-gate (void) printf(gettext("Use '%s' to begin " 15097c478bd9Sstevel@tonic-gate "configuring a new zone.\n"), 15107c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE)); 15117c478bd9Sstevel@tonic-gate return (err); 15127c478bd9Sstevel@tonic-gate } 15137c478bd9Sstevel@tonic-gate } 15147c478bd9Sstevel@tonic-gate return (Z_OK); 15157c478bd9Sstevel@tonic-gate } 15167c478bd9Sstevel@tonic-gate 1517bbec428eSgjelinek static boolean_t 1518087719fdSdp state_atleast(zone_state_t state) 1519087719fdSdp { 1520087719fdSdp zone_state_t state_num; 1521087719fdSdp int err; 1522087719fdSdp 1523087719fdSdp if ((err = zone_get_state(zone, &state_num)) != Z_OK) { 1524087719fdSdp /* all states are greater than "non-existent" */ 1525087719fdSdp if (err == Z_NO_ZONE) 1526087719fdSdp return (B_FALSE); 1527087719fdSdp zerr(gettext("Unexpectedly failed to determine state " 1528087719fdSdp "of zone %s: %s"), zone, zonecfg_strerror(err)); 1529087719fdSdp exit(Z_ERR); 1530087719fdSdp } 1531087719fdSdp return (state_num >= state); 1532087719fdSdp } 1533087719fdSdp 15347c478bd9Sstevel@tonic-gate /* 15357c478bd9Sstevel@tonic-gate * short_usage() is for bad syntax: getopt() issues, too many arguments, etc. 15367c478bd9Sstevel@tonic-gate */ 15377c478bd9Sstevel@tonic-gate 15387c478bd9Sstevel@tonic-gate void 15397c478bd9Sstevel@tonic-gate short_usage(int command) 15407c478bd9Sstevel@tonic-gate { 15417c478bd9Sstevel@tonic-gate /* lex_lineno has already been incremented in the lexer; compensate */ 15427c478bd9Sstevel@tonic-gate if (cmd_file_mode) { 15437c478bd9Sstevel@tonic-gate if (strcmp(cmd_file_name, "-") == 0) 15447c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 15457c478bd9Sstevel@tonic-gate gettext("syntax error on line %d\n"), 15467c478bd9Sstevel@tonic-gate lex_lineno - 1); 15477c478bd9Sstevel@tonic-gate else 15487c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 15497c478bd9Sstevel@tonic-gate gettext("syntax error on line %d of %s\n"), 15507c478bd9Sstevel@tonic-gate lex_lineno - 1, cmd_file_name); 15517c478bd9Sstevel@tonic-gate } 15527c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s:\n%s\n", gettext("usage"), 15537c478bd9Sstevel@tonic-gate helptab[command].short_usage); 1554bbec428eSgjelinek saw_error = B_TRUE; 15557c478bd9Sstevel@tonic-gate } 15567c478bd9Sstevel@tonic-gate 15577c478bd9Sstevel@tonic-gate /* 15587c478bd9Sstevel@tonic-gate * long_usage() is for bad semantics: e.g., wrong property type for a given 15597c478bd9Sstevel@tonic-gate * resource type. It is also used by longer_usage() below. 15607c478bd9Sstevel@tonic-gate */ 15617c478bd9Sstevel@tonic-gate 15627c478bd9Sstevel@tonic-gate void 1563bbec428eSgjelinek long_usage(uint_t cmd_num, boolean_t set_saw) 15647c478bd9Sstevel@tonic-gate { 15657c478bd9Sstevel@tonic-gate (void) fprintf(set_saw ? stderr : stdout, "%s:\n%s\n", gettext("usage"), 15667c478bd9Sstevel@tonic-gate helptab[cmd_num].short_usage); 15677c478bd9Sstevel@tonic-gate (void) fprintf(set_saw ? stderr : stdout, "\t%s\n", long_help(cmd_num)); 15687c478bd9Sstevel@tonic-gate if (set_saw) 1569bbec428eSgjelinek saw_error = B_TRUE; 15707c478bd9Sstevel@tonic-gate } 15717c478bd9Sstevel@tonic-gate 15727c478bd9Sstevel@tonic-gate /* 15737c478bd9Sstevel@tonic-gate * longer_usage() is for 'help foo' and 'foo -?': call long_usage() and also 15747c478bd9Sstevel@tonic-gate * any extra usage() flags as appropriate for whatever command. 15757c478bd9Sstevel@tonic-gate */ 15767c478bd9Sstevel@tonic-gate 15777c478bd9Sstevel@tonic-gate void 15787c478bd9Sstevel@tonic-gate longer_usage(uint_t cmd_num) 15797c478bd9Sstevel@tonic-gate { 1580bbec428eSgjelinek long_usage(cmd_num, B_FALSE); 15817c478bd9Sstevel@tonic-gate if (helptab[cmd_num].flags != 0) { 15827c478bd9Sstevel@tonic-gate (void) printf("\n"); 1583bbec428eSgjelinek usage(B_TRUE, helptab[cmd_num].flags); 15847c478bd9Sstevel@tonic-gate } 15857c478bd9Sstevel@tonic-gate } 15867c478bd9Sstevel@tonic-gate 15877c478bd9Sstevel@tonic-gate /* 15887c478bd9Sstevel@tonic-gate * scope_usage() is simply used when a command is called from the wrong scope. 15897c478bd9Sstevel@tonic-gate */ 15907c478bd9Sstevel@tonic-gate 15917c478bd9Sstevel@tonic-gate static void 15927c478bd9Sstevel@tonic-gate scope_usage(uint_t cmd_num) 15937c478bd9Sstevel@tonic-gate { 15947c478bd9Sstevel@tonic-gate zerr(gettext("The %s command only makes sense in the %s scope."), 15957c478bd9Sstevel@tonic-gate cmd_to_str(cmd_num), 15967c478bd9Sstevel@tonic-gate global_scope ? gettext("resource") : gettext("global")); 1597bbec428eSgjelinek saw_error = B_TRUE; 15987c478bd9Sstevel@tonic-gate } 15997c478bd9Sstevel@tonic-gate 16007c478bd9Sstevel@tonic-gate /* 1601bbec428eSgjelinek * On input, B_TRUE => yes, B_FALSE => no. 1602bbec428eSgjelinek * On return, B_TRUE => 1, B_FALSE => no, could not ask => -1. 16037c478bd9Sstevel@tonic-gate */ 16047c478bd9Sstevel@tonic-gate 16057c478bd9Sstevel@tonic-gate static int 1606bbec428eSgjelinek ask_yesno(boolean_t default_answer, const char *question) 16077c478bd9Sstevel@tonic-gate { 16087c478bd9Sstevel@tonic-gate char line[64]; /* should be enough to answer yes or no */ 16097c478bd9Sstevel@tonic-gate 16107c478bd9Sstevel@tonic-gate if (!ok_to_prompt) { 1611bbec428eSgjelinek saw_error = B_TRUE; 16127c478bd9Sstevel@tonic-gate return (-1); 16137c478bd9Sstevel@tonic-gate } 16147c478bd9Sstevel@tonic-gate for (;;) { 1615087719fdSdp if (printf("%s (%s)? ", question, 1616087719fdSdp default_answer ? "[y]/n" : "y/[n]") < 0) 1617087719fdSdp return (-1); 1618087719fdSdp if (fgets(line, sizeof (line), stdin) == NULL) 1619087719fdSdp return (-1); 1620087719fdSdp 1621087719fdSdp if (line[0] == '\n') 16227c478bd9Sstevel@tonic-gate return (default_answer ? 1 : 0); 16237c478bd9Sstevel@tonic-gate if (tolower(line[0]) == 'y') 16247c478bd9Sstevel@tonic-gate return (1); 16257c478bd9Sstevel@tonic-gate if (tolower(line[0]) == 'n') 16267c478bd9Sstevel@tonic-gate return (0); 16277c478bd9Sstevel@tonic-gate } 16287c478bd9Sstevel@tonic-gate } 16297c478bd9Sstevel@tonic-gate 16307c478bd9Sstevel@tonic-gate /* 16317c478bd9Sstevel@tonic-gate * Prints warning if zone already exists. 16327c478bd9Sstevel@tonic-gate * In interactive mode, prompts if we should continue anyway and returns Z_OK 16337c478bd9Sstevel@tonic-gate * if so, Z_ERR if not. In non-interactive mode, exits with Z_ERR. 16347c478bd9Sstevel@tonic-gate * 16357c478bd9Sstevel@tonic-gate * Note that if a zone exists and its state is >= INSTALLED, an error message 16367c478bd9Sstevel@tonic-gate * will be printed and this function will return Z_ERR regardless of mode. 16377c478bd9Sstevel@tonic-gate */ 16387c478bd9Sstevel@tonic-gate 16397c478bd9Sstevel@tonic-gate static int 1640bbec428eSgjelinek check_if_zone_already_exists(boolean_t force) 16417c478bd9Sstevel@tonic-gate { 16427c478bd9Sstevel@tonic-gate char line[ZONENAME_MAX + 128]; /* enough to ask a question */ 16437c478bd9Sstevel@tonic-gate zone_dochandle_t tmphandle; 16447c478bd9Sstevel@tonic-gate int res, answer; 16457c478bd9Sstevel@tonic-gate 16467c478bd9Sstevel@tonic-gate if ((tmphandle = zonecfg_init_handle()) == NULL) { 1647bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 16487c478bd9Sstevel@tonic-gate exit(Z_ERR); 16497c478bd9Sstevel@tonic-gate } 16507c478bd9Sstevel@tonic-gate res = zonecfg_get_handle(zone, tmphandle); 16517c478bd9Sstevel@tonic-gate zonecfg_fini_handle(tmphandle); 1652087719fdSdp if (res != Z_OK) 16537c478bd9Sstevel@tonic-gate return (Z_OK); 1654087719fdSdp 1655087719fdSdp if (state_atleast(ZONE_STATE_INSTALLED)) { 16567c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s already installed; %s not allowed."), 16577c478bd9Sstevel@tonic-gate zone, cmd_to_str(CMD_CREATE)); 16587c478bd9Sstevel@tonic-gate return (Z_ERR); 16597c478bd9Sstevel@tonic-gate } 16607c478bd9Sstevel@tonic-gate 16617c478bd9Sstevel@tonic-gate if (force) { 16627c478bd9Sstevel@tonic-gate (void) printf(gettext("Zone %s already exists; overwriting.\n"), 16637c478bd9Sstevel@tonic-gate zone); 16647c478bd9Sstevel@tonic-gate return (Z_OK); 16657c478bd9Sstevel@tonic-gate } 16667c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 16677c478bd9Sstevel@tonic-gate gettext("Zone %s already exists; %s anyway"), zone, 16687c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE)); 1669bbec428eSgjelinek if ((answer = ask_yesno(B_FALSE, line)) == -1) { 16707c478bd9Sstevel@tonic-gate zerr(gettext("Zone exists, input not from terminal and -F not " 16717c478bd9Sstevel@tonic-gate "specified:\n%s command ignored, exiting."), 16727c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE)); 16737c478bd9Sstevel@tonic-gate exit(Z_ERR); 16747c478bd9Sstevel@tonic-gate } 16757c478bd9Sstevel@tonic-gate return (answer == 1 ? Z_OK : Z_ERR); 16767c478bd9Sstevel@tonic-gate } 16777c478bd9Sstevel@tonic-gate 1678bbec428eSgjelinek static boolean_t 16797c478bd9Sstevel@tonic-gate zone_is_read_only(int cmd_num) 16807c478bd9Sstevel@tonic-gate { 16817c478bd9Sstevel@tonic-gate if (strncmp(zone, "SUNW", 4) == 0) { 16827c478bd9Sstevel@tonic-gate zerr(gettext("%s: zones beginning with SUNW are read-only."), 16837c478bd9Sstevel@tonic-gate zone); 1684bbec428eSgjelinek saw_error = B_TRUE; 1685bbec428eSgjelinek return (B_TRUE); 16867c478bd9Sstevel@tonic-gate } 16877c478bd9Sstevel@tonic-gate if (read_only_mode) { 16887c478bd9Sstevel@tonic-gate zerr(gettext("%s: cannot %s in read-only mode."), zone, 16897c478bd9Sstevel@tonic-gate cmd_to_str(cmd_num)); 1690bbec428eSgjelinek saw_error = B_TRUE; 1691bbec428eSgjelinek return (B_TRUE); 16927c478bd9Sstevel@tonic-gate } 1693bbec428eSgjelinek return (B_FALSE); 16947c478bd9Sstevel@tonic-gate } 16957c478bd9Sstevel@tonic-gate 16967c478bd9Sstevel@tonic-gate /* 16977c478bd9Sstevel@tonic-gate * Create a new configuration. 16987c478bd9Sstevel@tonic-gate */ 16997c478bd9Sstevel@tonic-gate void 17007c478bd9Sstevel@tonic-gate create_func(cmd_t *cmd) 17017c478bd9Sstevel@tonic-gate { 17027c478bd9Sstevel@tonic-gate int err, arg; 17037c478bd9Sstevel@tonic-gate char zone_template[ZONENAME_MAX]; 1704ee519a1fSgjelinek char attach_path[MAXPATHLEN]; 17057c478bd9Sstevel@tonic-gate zone_dochandle_t tmphandle; 1706bbec428eSgjelinek boolean_t force = B_FALSE; 1707bbec428eSgjelinek boolean_t attach = B_FALSE; 1708bbec428eSgjelinek boolean_t arg_err = B_FALSE; 17097c478bd9Sstevel@tonic-gate 17107c478bd9Sstevel@tonic-gate assert(cmd != NULL); 17117c478bd9Sstevel@tonic-gate 17127c478bd9Sstevel@tonic-gate /* This is the default if no arguments are given. */ 17137c478bd9Sstevel@tonic-gate (void) strlcpy(zone_template, "SUNWdefault", sizeof (zone_template)); 17147c478bd9Sstevel@tonic-gate 17157c478bd9Sstevel@tonic-gate optind = 0; 17169acbbeafSnn while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?a:bFt:")) 17179acbbeafSnn != EOF) { 17187c478bd9Sstevel@tonic-gate switch (arg) { 17197c478bd9Sstevel@tonic-gate case '?': 17207c478bd9Sstevel@tonic-gate if (optopt == '?') 17217c478bd9Sstevel@tonic-gate longer_usage(CMD_CREATE); 17227c478bd9Sstevel@tonic-gate else 17237c478bd9Sstevel@tonic-gate short_usage(CMD_CREATE); 1724bbec428eSgjelinek arg_err = B_TRUE; 17257ec75eb8Sgjelinek break; 1726ee519a1fSgjelinek case 'a': 1727ee519a1fSgjelinek (void) strlcpy(attach_path, optarg, 1728ee519a1fSgjelinek sizeof (attach_path)); 1729bbec428eSgjelinek attach = B_TRUE; 1730ee519a1fSgjelinek break; 17317c478bd9Sstevel@tonic-gate case 'b': 17327c478bd9Sstevel@tonic-gate (void) strlcpy(zone_template, "SUNWblank", 17337c478bd9Sstevel@tonic-gate sizeof (zone_template)); 17347c478bd9Sstevel@tonic-gate break; 17357c478bd9Sstevel@tonic-gate case 'F': 1736bbec428eSgjelinek force = B_TRUE; 17377c478bd9Sstevel@tonic-gate break; 17387c478bd9Sstevel@tonic-gate case 't': 17397c478bd9Sstevel@tonic-gate (void) strlcpy(zone_template, optarg, 17407c478bd9Sstevel@tonic-gate sizeof (zone_template)); 17417c478bd9Sstevel@tonic-gate break; 17427c478bd9Sstevel@tonic-gate default: 17437c478bd9Sstevel@tonic-gate short_usage(CMD_CREATE); 1744bbec428eSgjelinek arg_err = B_TRUE; 17457ec75eb8Sgjelinek break; 17467c478bd9Sstevel@tonic-gate } 17477c478bd9Sstevel@tonic-gate } 17487ec75eb8Sgjelinek if (arg_err) 17497ec75eb8Sgjelinek return; 17507ec75eb8Sgjelinek 17517c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 17527c478bd9Sstevel@tonic-gate short_usage(CMD_CREATE); 17537c478bd9Sstevel@tonic-gate return; 17547c478bd9Sstevel@tonic-gate } 17557c478bd9Sstevel@tonic-gate 17567c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_CREATE)) 17577c478bd9Sstevel@tonic-gate return; 17587c478bd9Sstevel@tonic-gate 17597c478bd9Sstevel@tonic-gate if (check_if_zone_already_exists(force) != Z_OK) 17607c478bd9Sstevel@tonic-gate return; 17617c478bd9Sstevel@tonic-gate 17627c478bd9Sstevel@tonic-gate /* 17637c478bd9Sstevel@tonic-gate * Get a temporary handle first. If that fails, the old handle 17647c478bd9Sstevel@tonic-gate * will not be lost. Then finish whichever one we don't need, 17657c478bd9Sstevel@tonic-gate * to avoid leaks. Then get the handle for zone_template, and 17667c478bd9Sstevel@tonic-gate * set the name to zone: this "copy, rename" method is how 17677c478bd9Sstevel@tonic-gate * create -[b|t] works. 17687c478bd9Sstevel@tonic-gate */ 17697c478bd9Sstevel@tonic-gate if ((tmphandle = zonecfg_init_handle()) == NULL) { 1770bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 17717c478bd9Sstevel@tonic-gate exit(Z_ERR); 17727c478bd9Sstevel@tonic-gate } 1773ee519a1fSgjelinek 1774ee519a1fSgjelinek if (attach) 177516ab8c7bSgjelinek err = zonecfg_get_attach_handle(attach_path, ZONE_DETACHED, 177616ab8c7bSgjelinek zone, B_FALSE, tmphandle); 1777ee519a1fSgjelinek else 1778ee519a1fSgjelinek err = zonecfg_get_template_handle(zone_template, zone, 1779ee519a1fSgjelinek tmphandle); 1780ee519a1fSgjelinek 1781ee519a1fSgjelinek if (err != Z_OK) { 17827c478bd9Sstevel@tonic-gate zonecfg_fini_handle(tmphandle); 1783ee519a1fSgjelinek if (attach && err == Z_NO_ZONE) 1784ee519a1fSgjelinek (void) fprintf(stderr, gettext("invalid path to " 1785ee519a1fSgjelinek "detached zone\n")); 1786ee519a1fSgjelinek else if (attach && err == Z_INVALID_DOCUMENT) 1787ee519a1fSgjelinek (void) fprintf(stderr, gettext("Cannot attach to an " 1788ee519a1fSgjelinek "earlier release of the operating system\n")); 1789ee519a1fSgjelinek else 1790bbec428eSgjelinek zone_perror(zone_template, err, B_TRUE); 17917c478bd9Sstevel@tonic-gate return; 17927c478bd9Sstevel@tonic-gate } 1793087719fdSdp 1794bbec428eSgjelinek need_to_commit = B_TRUE; 17957c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 17967c478bd9Sstevel@tonic-gate handle = tmphandle; 1797bbec428eSgjelinek got_handle = B_TRUE; 17987c478bd9Sstevel@tonic-gate } 17997c478bd9Sstevel@tonic-gate 18007c478bd9Sstevel@tonic-gate /* 18017c478bd9Sstevel@tonic-gate * This malloc()'s memory, which must be freed by the caller. 18027c478bd9Sstevel@tonic-gate */ 18037c478bd9Sstevel@tonic-gate static char * 18047c478bd9Sstevel@tonic-gate quoteit(char *instr) 18057c478bd9Sstevel@tonic-gate { 18067c478bd9Sstevel@tonic-gate char *outstr; 18077c478bd9Sstevel@tonic-gate size_t outstrsize = strlen(instr) + 3; /* 2 quotes + '\0' */ 18087c478bd9Sstevel@tonic-gate 18097c478bd9Sstevel@tonic-gate if ((outstr = malloc(outstrsize)) == NULL) { 1810bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_FALSE); 18117c478bd9Sstevel@tonic-gate exit(Z_ERR); 18127c478bd9Sstevel@tonic-gate } 18137c478bd9Sstevel@tonic-gate if (strchr(instr, ' ') == NULL) { 18147c478bd9Sstevel@tonic-gate (void) strlcpy(outstr, instr, outstrsize); 18157c478bd9Sstevel@tonic-gate return (outstr); 18167c478bd9Sstevel@tonic-gate } 18177c478bd9Sstevel@tonic-gate (void) snprintf(outstr, outstrsize, "\"%s\"", instr); 18187c478bd9Sstevel@tonic-gate return (outstr); 18197c478bd9Sstevel@tonic-gate } 18207c478bd9Sstevel@tonic-gate 18217c478bd9Sstevel@tonic-gate static void 18227c478bd9Sstevel@tonic-gate export_prop(FILE *of, int prop_num, char *prop_id) 18237c478bd9Sstevel@tonic-gate { 18247c478bd9Sstevel@tonic-gate char *quote_str; 18257c478bd9Sstevel@tonic-gate 18267c478bd9Sstevel@tonic-gate if (strlen(prop_id) == 0) 18277c478bd9Sstevel@tonic-gate return; 18287c478bd9Sstevel@tonic-gate quote_str = quoteit(prop_id); 18297c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 18307c478bd9Sstevel@tonic-gate pt_to_str(prop_num), quote_str); 18317c478bd9Sstevel@tonic-gate free(quote_str); 18327c478bd9Sstevel@tonic-gate } 18337c478bd9Sstevel@tonic-gate 18347c478bd9Sstevel@tonic-gate void 18357c478bd9Sstevel@tonic-gate export_func(cmd_t *cmd) 18367c478bd9Sstevel@tonic-gate { 18377c478bd9Sstevel@tonic-gate struct zone_nwiftab nwiftab; 18387c478bd9Sstevel@tonic-gate struct zone_fstab fstab; 18397c478bd9Sstevel@tonic-gate struct zone_devtab devtab; 18407c478bd9Sstevel@tonic-gate struct zone_attrtab attrtab; 18417c478bd9Sstevel@tonic-gate struct zone_rctltab rctltab; 1842fa9e4066Sahrens struct zone_dstab dstab; 18430209230bSgjelinek struct zone_psettab psettab; 18440209230bSgjelinek struct zone_mcaptab mcaptab; 18457c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *valptr; 1846cb8a054bSGlenn Faden struct zone_admintab admintab; 1847*d2a70789SRichard Lowe struct zone_secflagstab secflagstab; 18487c478bd9Sstevel@tonic-gate int err, arg; 18497c478bd9Sstevel@tonic-gate char zonepath[MAXPATHLEN], outfile[MAXPATHLEN], pool[MAXNAMELEN]; 18503f2f09c1Sdp char bootargs[BOOTARGS_MAX]; 18510209230bSgjelinek char sched[MAXNAMELEN]; 18529acbbeafSnn char brand[MAXNAMELEN]; 18535679c89fSjv char hostidp[HW_HOSTID_LEN]; 18540fbb751dSJohn Levon char fsallowedp[ZONE_FS_ALLOWED_MAX]; 1855ffbafc53Scomay char *limitpriv; 18567c478bd9Sstevel@tonic-gate FILE *of; 18577c478bd9Sstevel@tonic-gate boolean_t autoboot; 1858f4b3ec61Sdh zone_iptype_t iptype; 1859bbec428eSgjelinek boolean_t need_to_close = B_FALSE; 1860bbec428eSgjelinek boolean_t arg_err = B_FALSE; 18617c478bd9Sstevel@tonic-gate 18627c478bd9Sstevel@tonic-gate assert(cmd != NULL); 18637c478bd9Sstevel@tonic-gate 18647c478bd9Sstevel@tonic-gate outfile[0] = '\0'; 18657c478bd9Sstevel@tonic-gate optind = 0; 18667c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?f:")) != EOF) { 18677c478bd9Sstevel@tonic-gate switch (arg) { 18687c478bd9Sstevel@tonic-gate case '?': 18697c478bd9Sstevel@tonic-gate if (optopt == '?') 18707c478bd9Sstevel@tonic-gate longer_usage(CMD_EXPORT); 18717c478bd9Sstevel@tonic-gate else 18727c478bd9Sstevel@tonic-gate short_usage(CMD_EXPORT); 1873bbec428eSgjelinek arg_err = B_TRUE; 18747ec75eb8Sgjelinek break; 18757c478bd9Sstevel@tonic-gate case 'f': 18767c478bd9Sstevel@tonic-gate (void) strlcpy(outfile, optarg, sizeof (outfile)); 18777c478bd9Sstevel@tonic-gate break; 18787c478bd9Sstevel@tonic-gate default: 18797c478bd9Sstevel@tonic-gate short_usage(CMD_EXPORT); 1880bbec428eSgjelinek arg_err = B_TRUE; 18817ec75eb8Sgjelinek break; 18827c478bd9Sstevel@tonic-gate } 18837c478bd9Sstevel@tonic-gate } 18847ec75eb8Sgjelinek if (arg_err) 18857ec75eb8Sgjelinek return; 18867ec75eb8Sgjelinek 18877c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 18887c478bd9Sstevel@tonic-gate short_usage(CMD_EXPORT); 18897c478bd9Sstevel@tonic-gate return; 18907c478bd9Sstevel@tonic-gate } 18917c478bd9Sstevel@tonic-gate if (strlen(outfile) == 0) { 18927c478bd9Sstevel@tonic-gate of = stdout; 18937c478bd9Sstevel@tonic-gate } else { 18947c478bd9Sstevel@tonic-gate if ((of = fopen(outfile, "w")) == NULL) { 18957c478bd9Sstevel@tonic-gate zerr(gettext("opening file %s: %s"), 18967c478bd9Sstevel@tonic-gate outfile, strerror(errno)); 18977c478bd9Sstevel@tonic-gate goto done; 18987c478bd9Sstevel@tonic-gate } 18997c478bd9Sstevel@tonic-gate setbuf(of, NULL); 1900bbec428eSgjelinek need_to_close = B_TRUE; 19017c478bd9Sstevel@tonic-gate } 19027c478bd9Sstevel@tonic-gate 1903bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 19047c478bd9Sstevel@tonic-gate goto done; 19057c478bd9Sstevel@tonic-gate 19067c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s -b\n", cmd_to_str(CMD_CREATE)); 19077c478bd9Sstevel@tonic-gate 19087c478bd9Sstevel@tonic-gate if (zonecfg_get_zonepath(handle, zonepath, sizeof (zonepath)) == Z_OK && 19097c478bd9Sstevel@tonic-gate strlen(zonepath) > 0) 19107c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 19117c478bd9Sstevel@tonic-gate pt_to_str(PT_ZONEPATH), zonepath); 19127c478bd9Sstevel@tonic-gate 19139acbbeafSnn if ((zone_get_brand(zone, brand, sizeof (brand)) == Z_OK) && 19149acbbeafSnn (strcmp(brand, NATIVE_BRAND_NAME) != 0)) 19159acbbeafSnn (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 19169acbbeafSnn pt_to_str(PT_BRAND), brand); 19179acbbeafSnn 19187c478bd9Sstevel@tonic-gate if (zonecfg_get_autoboot(handle, &autoboot) == Z_OK) 19197c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 19207c478bd9Sstevel@tonic-gate pt_to_str(PT_AUTOBOOT), autoboot ? "true" : "false"); 19217c478bd9Sstevel@tonic-gate 19223f2f09c1Sdp if (zonecfg_get_bootargs(handle, bootargs, sizeof (bootargs)) == Z_OK && 19233f2f09c1Sdp strlen(bootargs) > 0) { 19243f2f09c1Sdp (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 19253f2f09c1Sdp pt_to_str(PT_BOOTARGS), bootargs); 19263f2f09c1Sdp } 19273f2f09c1Sdp 19287c478bd9Sstevel@tonic-gate if (zonecfg_get_pool(handle, pool, sizeof (pool)) == Z_OK && 19297c478bd9Sstevel@tonic-gate strlen(pool) > 0) 19307c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 19317c478bd9Sstevel@tonic-gate pt_to_str(PT_POOL), pool); 19327c478bd9Sstevel@tonic-gate 1933ffbafc53Scomay if (zonecfg_get_limitpriv(handle, &limitpriv) == Z_OK && 1934ffbafc53Scomay strlen(limitpriv) > 0) { 1935ffbafc53Scomay (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 1936ffbafc53Scomay pt_to_str(PT_LIMITPRIV), limitpriv); 1937ffbafc53Scomay free(limitpriv); 1938ffbafc53Scomay } 1939ffbafc53Scomay 19400209230bSgjelinek if (zonecfg_get_sched_class(handle, sched, sizeof (sched)) == Z_OK && 19410209230bSgjelinek strlen(sched) > 0) 19420209230bSgjelinek (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 19430209230bSgjelinek pt_to_str(PT_SCHED), sched); 19443f2f09c1Sdp 1945f4b3ec61Sdh if (zonecfg_get_iptype(handle, &iptype) == Z_OK) { 1946f4b3ec61Sdh switch (iptype) { 1947f4b3ec61Sdh case ZS_SHARED: 1948f4b3ec61Sdh (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 1949f4b3ec61Sdh pt_to_str(PT_IPTYPE), "shared"); 1950f4b3ec61Sdh break; 1951f4b3ec61Sdh case ZS_EXCLUSIVE: 1952f4b3ec61Sdh (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 1953f4b3ec61Sdh pt_to_str(PT_IPTYPE), "exclusive"); 1954f4b3ec61Sdh break; 1955f4b3ec61Sdh } 1956f4b3ec61Sdh } 1957f4b3ec61Sdh 19585679c89fSjv if (zonecfg_get_hostid(handle, hostidp, sizeof (hostidp)) == Z_OK) { 19595679c89fSjv (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 19605679c89fSjv pt_to_str(PT_HOSTID), hostidp); 19615679c89fSjv } 19625679c89fSjv 19630fbb751dSJohn Levon if (zonecfg_get_fs_allowed(handle, fsallowedp, 19640fbb751dSJohn Levon sizeof (fsallowedp)) == Z_OK) { 19650fbb751dSJohn Levon (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 19660fbb751dSJohn Levon pt_to_str(PT_FS_ALLOWED), fsallowedp); 19670fbb751dSJohn Levon } 19680fbb751dSJohn Levon 19697c478bd9Sstevel@tonic-gate if ((err = zonecfg_setfsent(handle)) != Z_OK) { 1970bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 19717c478bd9Sstevel@tonic-gate goto done; 19727c478bd9Sstevel@tonic-gate } 19737c478bd9Sstevel@tonic-gate while (zonecfg_getfsent(handle, &fstab) == Z_OK) { 19747c478bd9Sstevel@tonic-gate zone_fsopt_t *optptr; 19757c478bd9Sstevel@tonic-gate 19767c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 19777c478bd9Sstevel@tonic-gate rt_to_str(RT_FS)); 19787c478bd9Sstevel@tonic-gate export_prop(of, PT_DIR, fstab.zone_fs_dir); 19797c478bd9Sstevel@tonic-gate export_prop(of, PT_SPECIAL, fstab.zone_fs_special); 19807c478bd9Sstevel@tonic-gate export_prop(of, PT_RAW, fstab.zone_fs_raw); 19817c478bd9Sstevel@tonic-gate export_prop(of, PT_TYPE, fstab.zone_fs_type); 19827c478bd9Sstevel@tonic-gate for (optptr = fstab.zone_fs_options; optptr != NULL; 19837c478bd9Sstevel@tonic-gate optptr = optptr->zone_fsopt_next) { 19847c478bd9Sstevel@tonic-gate /* 19857c478bd9Sstevel@tonic-gate * Simple property values with embedded equal signs 19867c478bd9Sstevel@tonic-gate * need to be quoted to prevent the lexer from 19877c478bd9Sstevel@tonic-gate * mis-parsing them as complex name=value pairs. 19887c478bd9Sstevel@tonic-gate */ 19897c478bd9Sstevel@tonic-gate if (strchr(optptr->zone_fsopt_opt, '=')) 19907c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s \"%s\"\n", 19917c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), 19927c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS), 19937c478bd9Sstevel@tonic-gate optptr->zone_fsopt_opt); 19947c478bd9Sstevel@tonic-gate else 19957c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s %s\n", 19967c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), 19977c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS), 19987c478bd9Sstevel@tonic-gate optptr->zone_fsopt_opt); 19997c478bd9Sstevel@tonic-gate } 20007c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 20017c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(fstab.zone_fs_options); 20027c478bd9Sstevel@tonic-gate } 20037c478bd9Sstevel@tonic-gate (void) zonecfg_endfsent(handle); 20047c478bd9Sstevel@tonic-gate 20057c478bd9Sstevel@tonic-gate if ((err = zonecfg_setnwifent(handle)) != Z_OK) { 2006bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 20077c478bd9Sstevel@tonic-gate goto done; 20087c478bd9Sstevel@tonic-gate } 20097c478bd9Sstevel@tonic-gate while (zonecfg_getnwifent(handle, &nwiftab) == Z_OK) { 20107c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 20117c478bd9Sstevel@tonic-gate rt_to_str(RT_NET)); 20127c478bd9Sstevel@tonic-gate export_prop(of, PT_ADDRESS, nwiftab.zone_nwif_address); 2013550b6e40SSowmini Varadhan export_prop(of, PT_ALLOWED_ADDRESS, 2014550b6e40SSowmini Varadhan nwiftab.zone_nwif_allowed_address); 20157c478bd9Sstevel@tonic-gate export_prop(of, PT_PHYSICAL, nwiftab.zone_nwif_physical); 2016de860bd9Sgfaden export_prop(of, PT_DEFROUTER, nwiftab.zone_nwif_defrouter); 20177c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 20187c478bd9Sstevel@tonic-gate } 20197c478bd9Sstevel@tonic-gate (void) zonecfg_endnwifent(handle); 20207c478bd9Sstevel@tonic-gate 20217c478bd9Sstevel@tonic-gate if ((err = zonecfg_setdevent(handle)) != Z_OK) { 2022bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 20237c478bd9Sstevel@tonic-gate goto done; 20247c478bd9Sstevel@tonic-gate } 20257c478bd9Sstevel@tonic-gate while (zonecfg_getdevent(handle, &devtab) == Z_OK) { 20267c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 20277c478bd9Sstevel@tonic-gate rt_to_str(RT_DEVICE)); 20287c478bd9Sstevel@tonic-gate export_prop(of, PT_MATCH, devtab.zone_dev_match); 20297c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 20307c478bd9Sstevel@tonic-gate } 20317c478bd9Sstevel@tonic-gate (void) zonecfg_enddevent(handle); 20327c478bd9Sstevel@tonic-gate 20331b3281c0SGerald Jelinek if (zonecfg_getmcapent(handle, &mcaptab) == Z_OK) { 20341b3281c0SGerald Jelinek char buf[128]; 20351b3281c0SGerald Jelinek 20361b3281c0SGerald Jelinek (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 20371b3281c0SGerald Jelinek rt_to_str(RT_MCAP)); 20381b3281c0SGerald Jelinek bytes_to_units(mcaptab.zone_physmem_cap, buf, sizeof (buf)); 20391b3281c0SGerald Jelinek (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 20401b3281c0SGerald Jelinek pt_to_str(PT_PHYSICAL), buf); 20411b3281c0SGerald Jelinek (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 20421b3281c0SGerald Jelinek } 20431b3281c0SGerald Jelinek 20447c478bd9Sstevel@tonic-gate if ((err = zonecfg_setrctlent(handle)) != Z_OK) { 2045bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 20467c478bd9Sstevel@tonic-gate goto done; 20477c478bd9Sstevel@tonic-gate } 20487c478bd9Sstevel@tonic-gate while (zonecfg_getrctlent(handle, &rctltab) == Z_OK) { 20497c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s rctl\n", cmd_to_str(CMD_ADD)); 20507c478bd9Sstevel@tonic-gate export_prop(of, PT_NAME, rctltab.zone_rctl_name); 20517c478bd9Sstevel@tonic-gate for (valptr = rctltab.zone_rctl_valptr; valptr != NULL; 20527c478bd9Sstevel@tonic-gate valptr = valptr->zone_rctlval_next) { 20537c478bd9Sstevel@tonic-gate fprintf(of, "%s %s (%s=%s,%s=%s,%s=%s)\n", 20547c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), pt_to_str(PT_VALUE), 20557c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV), valptr->zone_rctlval_priv, 20567c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT), valptr->zone_rctlval_limit, 20577c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION), valptr->zone_rctlval_action); 20587c478bd9Sstevel@tonic-gate } 20597c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 20607c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr); 20617c478bd9Sstevel@tonic-gate } 20627c478bd9Sstevel@tonic-gate (void) zonecfg_endrctlent(handle); 20637c478bd9Sstevel@tonic-gate 20647c478bd9Sstevel@tonic-gate if ((err = zonecfg_setattrent(handle)) != Z_OK) { 2065bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 20667c478bd9Sstevel@tonic-gate goto done; 20677c478bd9Sstevel@tonic-gate } 20687c478bd9Sstevel@tonic-gate while (zonecfg_getattrent(handle, &attrtab) == Z_OK) { 20697c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 20707c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR)); 20717c478bd9Sstevel@tonic-gate export_prop(of, PT_NAME, attrtab.zone_attr_name); 20727c478bd9Sstevel@tonic-gate export_prop(of, PT_TYPE, attrtab.zone_attr_type); 20737c478bd9Sstevel@tonic-gate export_prop(of, PT_VALUE, attrtab.zone_attr_value); 20747c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 20757c478bd9Sstevel@tonic-gate } 20767c478bd9Sstevel@tonic-gate (void) zonecfg_endattrent(handle); 20777c478bd9Sstevel@tonic-gate 2078fa9e4066Sahrens if ((err = zonecfg_setdsent(handle)) != Z_OK) { 2079bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 2080fa9e4066Sahrens goto done; 2081fa9e4066Sahrens } 2082fa9e4066Sahrens while (zonecfg_getdsent(handle, &dstab) == Z_OK) { 2083fa9e4066Sahrens (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 2084fa9e4066Sahrens rt_to_str(RT_DATASET)); 2085fa9e4066Sahrens export_prop(of, PT_NAME, dstab.zone_dataset_name); 2086fa9e4066Sahrens (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 2087fa9e4066Sahrens } 2088fa9e4066Sahrens (void) zonecfg_enddsent(handle); 2089fa9e4066Sahrens 20900209230bSgjelinek if (zonecfg_getpsetent(handle, &psettab) == Z_OK) { 20910209230bSgjelinek (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 20920209230bSgjelinek rt_to_str(RT_DCPU)); 20930209230bSgjelinek if (strcmp(psettab.zone_ncpu_min, psettab.zone_ncpu_max) == 0) 20940209230bSgjelinek (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 20950209230bSgjelinek pt_to_str(PT_NCPUS), psettab.zone_ncpu_max); 20960209230bSgjelinek else 20970209230bSgjelinek (void) fprintf(of, "%s %s=%s-%s\n", cmd_to_str(CMD_SET), 20980209230bSgjelinek pt_to_str(PT_NCPUS), psettab.zone_ncpu_min, 20990209230bSgjelinek psettab.zone_ncpu_max); 21000209230bSgjelinek if (psettab.zone_importance[0] != '\0') 21010209230bSgjelinek (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 21020209230bSgjelinek pt_to_str(PT_IMPORTANCE), psettab.zone_importance); 21030209230bSgjelinek (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 21040209230bSgjelinek } 21050209230bSgjelinek 2106cb8a054bSGlenn Faden if ((err = zonecfg_setadminent(handle)) != Z_OK) { 2107cb8a054bSGlenn Faden zone_perror(zone, err, B_FALSE); 2108cb8a054bSGlenn Faden goto done; 2109cb8a054bSGlenn Faden } 2110cb8a054bSGlenn Faden while (zonecfg_getadminent(handle, &admintab) == Z_OK) { 2111cb8a054bSGlenn Faden (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 2112cb8a054bSGlenn Faden rt_to_str(RT_ADMIN)); 2113cb8a054bSGlenn Faden export_prop(of, PT_USER, admintab.zone_admin_user); 2114cb8a054bSGlenn Faden export_prop(of, PT_AUTHS, admintab.zone_admin_auths); 2115cb8a054bSGlenn Faden (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 2116cb8a054bSGlenn Faden } 2117*d2a70789SRichard Lowe 2118cb8a054bSGlenn Faden (void) zonecfg_endadminent(handle); 2119cb8a054bSGlenn Faden 2120*d2a70789SRichard Lowe if (zonecfg_getsecflagsent(handle, &secflagstab) == Z_OK) { 2121*d2a70789SRichard Lowe (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 2122*d2a70789SRichard Lowe rt_to_str(RT_SECFLAGS)); 2123*d2a70789SRichard Lowe export_prop(of, PT_DEFAULT, secflagstab.zone_secflags_default); 2124*d2a70789SRichard Lowe export_prop(of, PT_LOWER, secflagstab.zone_secflags_lower); 2125*d2a70789SRichard Lowe export_prop(of, PT_UPPER, secflagstab.zone_secflags_upper); 2126*d2a70789SRichard Lowe (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 2127*d2a70789SRichard Lowe } 2128*d2a70789SRichard Lowe 2129c97ad5cdSakolb /* 2130c97ad5cdSakolb * There is nothing to export for pcap since this resource is just 2131c97ad5cdSakolb * a container for an rctl alias. 2132c97ad5cdSakolb */ 2133c97ad5cdSakolb 21347c478bd9Sstevel@tonic-gate done: 21357c478bd9Sstevel@tonic-gate if (need_to_close) 21367c478bd9Sstevel@tonic-gate (void) fclose(of); 21377c478bd9Sstevel@tonic-gate } 21387c478bd9Sstevel@tonic-gate 21397c478bd9Sstevel@tonic-gate void 21407c478bd9Sstevel@tonic-gate exit_func(cmd_t *cmd) 21417c478bd9Sstevel@tonic-gate { 21427c478bd9Sstevel@tonic-gate int arg, answer; 2143bbec428eSgjelinek boolean_t arg_err = B_FALSE; 21447c478bd9Sstevel@tonic-gate 21457c478bd9Sstevel@tonic-gate optind = 0; 21467c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 21477c478bd9Sstevel@tonic-gate switch (arg) { 21487c478bd9Sstevel@tonic-gate case '?': 21497c478bd9Sstevel@tonic-gate longer_usage(CMD_EXIT); 2150bbec428eSgjelinek arg_err = B_TRUE; 21517ec75eb8Sgjelinek break; 21527c478bd9Sstevel@tonic-gate case 'F': 2153bbec428eSgjelinek force_exit = B_TRUE; 21547c478bd9Sstevel@tonic-gate break; 21557c478bd9Sstevel@tonic-gate default: 21567c478bd9Sstevel@tonic-gate short_usage(CMD_EXIT); 2157bbec428eSgjelinek arg_err = B_TRUE; 21587ec75eb8Sgjelinek break; 21597c478bd9Sstevel@tonic-gate } 21607c478bd9Sstevel@tonic-gate } 21617ec75eb8Sgjelinek if (arg_err) 21627ec75eb8Sgjelinek return; 21637ec75eb8Sgjelinek 21647c478bd9Sstevel@tonic-gate if (optind < cmd->cmd_argc) { 21657c478bd9Sstevel@tonic-gate short_usage(CMD_EXIT); 21667c478bd9Sstevel@tonic-gate return; 21677c478bd9Sstevel@tonic-gate } 21687c478bd9Sstevel@tonic-gate 21697c478bd9Sstevel@tonic-gate if (global_scope || force_exit) { 2170bbec428eSgjelinek time_to_exit = B_TRUE; 21717c478bd9Sstevel@tonic-gate return; 21727c478bd9Sstevel@tonic-gate } 21737c478bd9Sstevel@tonic-gate 2174bbec428eSgjelinek answer = ask_yesno(B_FALSE, "Resource incomplete; really quit"); 21757c478bd9Sstevel@tonic-gate if (answer == -1) { 21767c478bd9Sstevel@tonic-gate zerr(gettext("Resource incomplete, input " 21777c478bd9Sstevel@tonic-gate "not from terminal and -F not specified:\n%s command " 21787c478bd9Sstevel@tonic-gate "ignored, but exiting anyway."), cmd_to_str(CMD_EXIT)); 21797c478bd9Sstevel@tonic-gate exit(Z_ERR); 21807c478bd9Sstevel@tonic-gate } else if (answer == 1) { 2181bbec428eSgjelinek time_to_exit = B_TRUE; 21827c478bd9Sstevel@tonic-gate } 21837c478bd9Sstevel@tonic-gate /* (answer == 0) => just return */ 21847c478bd9Sstevel@tonic-gate } 21857c478bd9Sstevel@tonic-gate 21867c478bd9Sstevel@tonic-gate static int 21877c478bd9Sstevel@tonic-gate validate_zonepath_syntax(char *path) 21887c478bd9Sstevel@tonic-gate { 21897c478bd9Sstevel@tonic-gate if (path[0] != '/') { 21907c478bd9Sstevel@tonic-gate zerr(gettext("%s is not an absolute path."), path); 21917c478bd9Sstevel@tonic-gate return (Z_ERR); 21927c478bd9Sstevel@tonic-gate } 21936fb06a2bSSusan Kamm-Worrell /* If path is all slashes, then fail */ 21946fb06a2bSSusan Kamm-Worrell if (strspn(path, "/") == strlen(path)) { 21957c478bd9Sstevel@tonic-gate zerr(gettext("/ is not allowed as a %s."), 21967c478bd9Sstevel@tonic-gate pt_to_str(PT_ZONEPATH)); 21977c478bd9Sstevel@tonic-gate return (Z_ERR); 21987c478bd9Sstevel@tonic-gate } 21997c478bd9Sstevel@tonic-gate return (Z_OK); 22007c478bd9Sstevel@tonic-gate } 22017c478bd9Sstevel@tonic-gate 22027c478bd9Sstevel@tonic-gate static void 22037c478bd9Sstevel@tonic-gate add_resource(cmd_t *cmd) 22047c478bd9Sstevel@tonic-gate { 22057c478bd9Sstevel@tonic-gate int type; 22060209230bSgjelinek struct zone_psettab tmp_psettab; 22070209230bSgjelinek struct zone_mcaptab tmp_mcaptab; 2208*d2a70789SRichard Lowe struct zone_secflagstab tmp_secflagstab; 2209c97ad5cdSakolb uint64_t tmp; 22100209230bSgjelinek uint64_t tmp_mcap; 22110209230bSgjelinek char pool[MAXNAMELEN]; 22127c478bd9Sstevel@tonic-gate 22137c478bd9Sstevel@tonic-gate if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 2214bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 22157c478bd9Sstevel@tonic-gate goto bad; 22167c478bd9Sstevel@tonic-gate } 22177c478bd9Sstevel@tonic-gate 22187c478bd9Sstevel@tonic-gate switch (type) { 22197c478bd9Sstevel@tonic-gate case RT_FS: 22207c478bd9Sstevel@tonic-gate bzero(&in_progress_fstab, sizeof (in_progress_fstab)); 22217c478bd9Sstevel@tonic-gate return; 22227c478bd9Sstevel@tonic-gate case RT_NET: 22237c478bd9Sstevel@tonic-gate bzero(&in_progress_nwiftab, sizeof (in_progress_nwiftab)); 22247c478bd9Sstevel@tonic-gate return; 22257c478bd9Sstevel@tonic-gate case RT_DEVICE: 22267c478bd9Sstevel@tonic-gate bzero(&in_progress_devtab, sizeof (in_progress_devtab)); 22277c478bd9Sstevel@tonic-gate return; 22287c478bd9Sstevel@tonic-gate case RT_RCTL: 22290209230bSgjelinek if (global_zone) 22300209230bSgjelinek zerr(gettext("WARNING: Setting a global zone resource " 22310209230bSgjelinek "control too low could deny\nservice " 22320209230bSgjelinek "to even the root user; " 22330209230bSgjelinek "this could render the system impossible\n" 22340209230bSgjelinek "to administer. Please use caution.")); 22357c478bd9Sstevel@tonic-gate bzero(&in_progress_rctltab, sizeof (in_progress_rctltab)); 22367c478bd9Sstevel@tonic-gate return; 22377c478bd9Sstevel@tonic-gate case RT_ATTR: 22387c478bd9Sstevel@tonic-gate bzero(&in_progress_attrtab, sizeof (in_progress_attrtab)); 22397c478bd9Sstevel@tonic-gate return; 2240fa9e4066Sahrens case RT_DATASET: 2241fa9e4066Sahrens bzero(&in_progress_dstab, sizeof (in_progress_dstab)); 2242fa9e4066Sahrens return; 22430209230bSgjelinek case RT_DCPU: 2244c97ad5cdSakolb /* Make sure there isn't already a cpu-set or cpu-cap entry. */ 22450209230bSgjelinek if (zonecfg_lookup_pset(handle, &tmp_psettab) == Z_OK) { 22460209230bSgjelinek zerr(gettext("The %s resource already exists."), 22470209230bSgjelinek rt_to_str(RT_DCPU)); 22480209230bSgjelinek goto bad; 22490209230bSgjelinek } 2250c97ad5cdSakolb if (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &tmp) != 2251c97ad5cdSakolb Z_NO_ENTRY) { 2252c97ad5cdSakolb zerr(gettext("The %s resource already exists."), 2253c97ad5cdSakolb rt_to_str(RT_PCAP)); 2254c97ad5cdSakolb goto bad; 2255c97ad5cdSakolb } 22560209230bSgjelinek 22570209230bSgjelinek /* Make sure the pool property isn't set. */ 22580209230bSgjelinek if (zonecfg_get_pool(handle, pool, sizeof (pool)) == Z_OK && 22590209230bSgjelinek strlen(pool) > 0) { 22600209230bSgjelinek zerr(gettext("The %s property is already set. " 22610209230bSgjelinek "A persistent pool is incompatible with\nthe %s " 22620209230bSgjelinek "resource."), 22630209230bSgjelinek pt_to_str(PT_POOL), rt_to_str(RT_DCPU)); 22640209230bSgjelinek goto bad; 22650209230bSgjelinek } 22660209230bSgjelinek 22670209230bSgjelinek bzero(&in_progress_psettab, sizeof (in_progress_psettab)); 22680209230bSgjelinek return; 2269c97ad5cdSakolb case RT_PCAP: 2270c97ad5cdSakolb /* 2271c97ad5cdSakolb * Make sure there isn't already a cpu-set or incompatible 2272c97ad5cdSakolb * cpu-cap rctls. 2273c97ad5cdSakolb */ 2274c97ad5cdSakolb if (zonecfg_lookup_pset(handle, &tmp_psettab) == Z_OK) { 2275c97ad5cdSakolb zerr(gettext("The %s resource already exists."), 2276c97ad5cdSakolb rt_to_str(RT_DCPU)); 2277c97ad5cdSakolb goto bad; 2278c97ad5cdSakolb } 2279c97ad5cdSakolb 2280c97ad5cdSakolb switch (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &tmp)) { 2281c97ad5cdSakolb case Z_ALIAS_DISALLOW: 2282c97ad5cdSakolb zone_perror(rt_to_str(RT_PCAP), Z_ALIAS_DISALLOW, 2283bbec428eSgjelinek B_FALSE); 2284c97ad5cdSakolb goto bad; 2285c97ad5cdSakolb 2286c97ad5cdSakolb case Z_OK: 2287c97ad5cdSakolb zerr(gettext("The %s resource already exists."), 2288c97ad5cdSakolb rt_to_str(RT_PCAP)); 2289c97ad5cdSakolb goto bad; 2290c97ad5cdSakolb 2291c97ad5cdSakolb default: 2292c97ad5cdSakolb break; 2293c97ad5cdSakolb } 2294c97ad5cdSakolb return; 22950209230bSgjelinek case RT_MCAP: 22960209230bSgjelinek /* 22970209230bSgjelinek * Make sure there isn't already a mem-cap entry or max-swap 22980209230bSgjelinek * or max-locked rctl. 22990209230bSgjelinek */ 23000209230bSgjelinek if (zonecfg_lookup_mcap(handle, &tmp_mcaptab) == Z_OK || 23010209230bSgjelinek zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, &tmp_mcap) 23020209230bSgjelinek == Z_OK || 23030209230bSgjelinek zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, 23040209230bSgjelinek &tmp_mcap) == Z_OK) { 23050209230bSgjelinek zerr(gettext("The %s resource or a related resource " 23060209230bSgjelinek "control already exists."), rt_to_str(RT_MCAP)); 23070209230bSgjelinek goto bad; 23080209230bSgjelinek } 23090209230bSgjelinek if (global_zone) 23100209230bSgjelinek zerr(gettext("WARNING: Setting a global zone memory " 23110209230bSgjelinek "cap too low could deny\nservice " 23120209230bSgjelinek "to even the root user; " 23130209230bSgjelinek "this could render the system impossible\n" 23140209230bSgjelinek "to administer. Please use caution.")); 23150209230bSgjelinek bzero(&in_progress_mcaptab, sizeof (in_progress_mcaptab)); 23160209230bSgjelinek return; 2317cb8a054bSGlenn Faden case RT_ADMIN: 2318cb8a054bSGlenn Faden bzero(&in_progress_admintab, sizeof (in_progress_admintab)); 2319cb8a054bSGlenn Faden return; 2320*d2a70789SRichard Lowe case RT_SECFLAGS: 2321*d2a70789SRichard Lowe /* Make sure we haven't already set this */ 2322*d2a70789SRichard Lowe if (zonecfg_lookup_secflags(handle, &tmp_secflagstab) == Z_OK) 2323*d2a70789SRichard Lowe zerr(gettext("The %s resource already exists."), 2324*d2a70789SRichard Lowe rt_to_str(RT_SECFLAGS)); 2325*d2a70789SRichard Lowe bzero(&in_progress_secflagstab, 2326*d2a70789SRichard Lowe sizeof (in_progress_secflagstab)); 2327*d2a70789SRichard Lowe return; 23287c478bd9Sstevel@tonic-gate default: 2329bbec428eSgjelinek zone_perror(rt_to_str(type), Z_NO_RESOURCE_TYPE, B_TRUE); 2330bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 2331bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 23327c478bd9Sstevel@tonic-gate } 23337c478bd9Sstevel@tonic-gate bad: 2334bbec428eSgjelinek global_scope = B_TRUE; 23357c478bd9Sstevel@tonic-gate end_op = -1; 23367c478bd9Sstevel@tonic-gate } 23377c478bd9Sstevel@tonic-gate 23387c478bd9Sstevel@tonic-gate static void 23397c478bd9Sstevel@tonic-gate do_complex_rctl_val(complex_property_ptr_t cp) 23407c478bd9Sstevel@tonic-gate { 23417c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *rctlvaltab; 23427c478bd9Sstevel@tonic-gate complex_property_ptr_t cx; 2343bbec428eSgjelinek boolean_t seen_priv = B_FALSE, seen_limit = B_FALSE, 2344bbec428eSgjelinek seen_action = B_FALSE; 23457c478bd9Sstevel@tonic-gate rctlblk_t *rctlblk; 23467c478bd9Sstevel@tonic-gate int err; 23477c478bd9Sstevel@tonic-gate 23487c478bd9Sstevel@tonic-gate if ((rctlvaltab = alloc_rctlvaltab()) == NULL) { 2349bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_TRUE); 23507c478bd9Sstevel@tonic-gate exit(Z_ERR); 23517c478bd9Sstevel@tonic-gate } 23527c478bd9Sstevel@tonic-gate for (cx = cp; cx != NULL; cx = cx->cp_next) { 23537c478bd9Sstevel@tonic-gate switch (cx->cp_type) { 23547c478bd9Sstevel@tonic-gate case PT_PRIV: 23557c478bd9Sstevel@tonic-gate if (seen_priv) { 23567c478bd9Sstevel@tonic-gate zerr(gettext("%s already specified"), 23577c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV)); 23587c478bd9Sstevel@tonic-gate goto bad; 23597c478bd9Sstevel@tonic-gate } 23607c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_priv, 23617c478bd9Sstevel@tonic-gate cx->cp_value, 23627c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_priv)); 2363bbec428eSgjelinek seen_priv = B_TRUE; 23647c478bd9Sstevel@tonic-gate break; 23657c478bd9Sstevel@tonic-gate case PT_LIMIT: 23667c478bd9Sstevel@tonic-gate if (seen_limit) { 23677c478bd9Sstevel@tonic-gate zerr(gettext("%s already specified"), 23687c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT)); 23697c478bd9Sstevel@tonic-gate goto bad; 23707c478bd9Sstevel@tonic-gate } 23717c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_limit, 23727c478bd9Sstevel@tonic-gate cx->cp_value, 23737c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_limit)); 2374bbec428eSgjelinek seen_limit = B_TRUE; 23757c478bd9Sstevel@tonic-gate break; 23767c478bd9Sstevel@tonic-gate case PT_ACTION: 23777c478bd9Sstevel@tonic-gate if (seen_action) { 23787c478bd9Sstevel@tonic-gate zerr(gettext("%s already specified"), 23797c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION)); 23807c478bd9Sstevel@tonic-gate goto bad; 23817c478bd9Sstevel@tonic-gate } 23827c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_action, 23837c478bd9Sstevel@tonic-gate cx->cp_value, 23847c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_action)); 2385bbec428eSgjelinek seen_action = B_TRUE; 23867c478bd9Sstevel@tonic-gate break; 23877c478bd9Sstevel@tonic-gate default: 23887c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(PT_VALUE), 2389bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 2390bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 2391bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 23927c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 23937c478bd9Sstevel@tonic-gate return; 23947c478bd9Sstevel@tonic-gate } 23957c478bd9Sstevel@tonic-gate } 23967c478bd9Sstevel@tonic-gate if (!seen_priv) 23977c478bd9Sstevel@tonic-gate zerr(gettext("%s not specified"), pt_to_str(PT_PRIV)); 23987c478bd9Sstevel@tonic-gate if (!seen_limit) 23997c478bd9Sstevel@tonic-gate zerr(gettext("%s not specified"), pt_to_str(PT_LIMIT)); 24007c478bd9Sstevel@tonic-gate if (!seen_action) 24017c478bd9Sstevel@tonic-gate zerr(gettext("%s not specified"), pt_to_str(PT_ACTION)); 24027c478bd9Sstevel@tonic-gate if (!seen_priv || !seen_limit || !seen_action) 24037c478bd9Sstevel@tonic-gate goto bad; 24047c478bd9Sstevel@tonic-gate rctlvaltab->zone_rctlval_next = NULL; 24057c478bd9Sstevel@tonic-gate rctlblk = alloca(rctlblk_size()); 24067c478bd9Sstevel@tonic-gate /* 24077c478bd9Sstevel@tonic-gate * Make sure the rctl value looks roughly correct; we won't know if 24087c478bd9Sstevel@tonic-gate * it's truly OK until we verify the configuration on the target 24097c478bd9Sstevel@tonic-gate * system. 24107c478bd9Sstevel@tonic-gate */ 24117c478bd9Sstevel@tonic-gate if (zonecfg_construct_rctlblk(rctlvaltab, rctlblk) != Z_OK || 24127c478bd9Sstevel@tonic-gate !zonecfg_valid_rctlblk(rctlblk)) { 24137c478bd9Sstevel@tonic-gate zerr(gettext("Invalid %s %s specification"), rt_to_str(RT_RCTL), 24147c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE)); 24157c478bd9Sstevel@tonic-gate goto bad; 24167c478bd9Sstevel@tonic-gate } 24177c478bd9Sstevel@tonic-gate err = zonecfg_add_rctl_value(&in_progress_rctltab, rctlvaltab); 24187c478bd9Sstevel@tonic-gate if (err != Z_OK) 2419bbec428eSgjelinek zone_perror(pt_to_str(PT_VALUE), err, B_TRUE); 24207c478bd9Sstevel@tonic-gate return; 24217c478bd9Sstevel@tonic-gate 24227c478bd9Sstevel@tonic-gate bad: 24237c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 24247c478bd9Sstevel@tonic-gate } 24257c478bd9Sstevel@tonic-gate 24267c478bd9Sstevel@tonic-gate static void 24277c478bd9Sstevel@tonic-gate add_property(cmd_t *cmd) 24287c478bd9Sstevel@tonic-gate { 24297c478bd9Sstevel@tonic-gate char *prop_id; 24307c478bd9Sstevel@tonic-gate int err, res_type, prop_type; 24317c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 24327c478bd9Sstevel@tonic-gate list_property_ptr_t l; 24337c478bd9Sstevel@tonic-gate 24347c478bd9Sstevel@tonic-gate res_type = resource_scope; 24357c478bd9Sstevel@tonic-gate prop_type = cmd->cmd_prop_name[0]; 24367c478bd9Sstevel@tonic-gate if (res_type == RT_UNKNOWN || prop_type == PT_UNKNOWN) { 2437bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 24387c478bd9Sstevel@tonic-gate return; 24397c478bd9Sstevel@tonic-gate } 24407c478bd9Sstevel@tonic-gate 24417c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs != 1) { 2442bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 24437c478bd9Sstevel@tonic-gate return; 24447c478bd9Sstevel@tonic-gate } 24457c478bd9Sstevel@tonic-gate 2446bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 24477c478bd9Sstevel@tonic-gate return; 24487c478bd9Sstevel@tonic-gate 24497c478bd9Sstevel@tonic-gate switch (res_type) { 24507c478bd9Sstevel@tonic-gate case RT_FS: 24517c478bd9Sstevel@tonic-gate if (prop_type != PT_OPTIONS) { 24527c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 2453bbec428eSgjelinek B_TRUE); 2454bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 2455bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 24567c478bd9Sstevel@tonic-gate return; 24577c478bd9Sstevel@tonic-gate } 24587c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 24597c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE && 24607c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 24617c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected here."), 24627c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_SIMPLE), 24637c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 2464bbec428eSgjelinek saw_error = B_TRUE; 24657c478bd9Sstevel@tonic-gate return; 24667c478bd9Sstevel@tonic-gate } 24677c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_SIMPLE) { 24687c478bd9Sstevel@tonic-gate if (pp->pv_simple == NULL) { 2469bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 24707c478bd9Sstevel@tonic-gate return; 24717c478bd9Sstevel@tonic-gate } 24727c478bd9Sstevel@tonic-gate prop_id = pp->pv_simple; 24737c478bd9Sstevel@tonic-gate err = zonecfg_add_fs_option(&in_progress_fstab, 24747c478bd9Sstevel@tonic-gate prop_id); 24757c478bd9Sstevel@tonic-gate if (err != Z_OK) 2476bbec428eSgjelinek zone_perror(pt_to_str(prop_type), err, B_TRUE); 24777c478bd9Sstevel@tonic-gate } else { 24787c478bd9Sstevel@tonic-gate list_property_ptr_t list; 24797c478bd9Sstevel@tonic-gate 24807c478bd9Sstevel@tonic-gate for (list = pp->pv_list; list != NULL; 24817c478bd9Sstevel@tonic-gate list = list->lp_next) { 24827c478bd9Sstevel@tonic-gate prop_id = list->lp_simple; 24837c478bd9Sstevel@tonic-gate if (prop_id == NULL) 24847c478bd9Sstevel@tonic-gate break; 24857c478bd9Sstevel@tonic-gate err = zonecfg_add_fs_option( 24867c478bd9Sstevel@tonic-gate &in_progress_fstab, prop_id); 24877c478bd9Sstevel@tonic-gate if (err != Z_OK) 24887c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), err, 2489bbec428eSgjelinek B_TRUE); 24907c478bd9Sstevel@tonic-gate } 24917c478bd9Sstevel@tonic-gate } 24927c478bd9Sstevel@tonic-gate return; 24937c478bd9Sstevel@tonic-gate case RT_RCTL: 24947c478bd9Sstevel@tonic-gate if (prop_type != PT_VALUE) { 24957c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 2496bbec428eSgjelinek B_TRUE); 2497bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 2498bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 24997c478bd9Sstevel@tonic-gate return; 25007c478bd9Sstevel@tonic-gate } 25017c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 25027c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_COMPLEX && 25037c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 25047c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected here."), 25057c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_COMPLEX), 25067c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 2507bbec428eSgjelinek saw_error = B_TRUE; 25087c478bd9Sstevel@tonic-gate return; 25097c478bd9Sstevel@tonic-gate } 25107c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_COMPLEX) { 25117c478bd9Sstevel@tonic-gate do_complex_rctl_val(pp->pv_complex); 25127c478bd9Sstevel@tonic-gate return; 25137c478bd9Sstevel@tonic-gate } 25147c478bd9Sstevel@tonic-gate for (l = pp->pv_list; l != NULL; l = l->lp_next) 25157c478bd9Sstevel@tonic-gate do_complex_rctl_val(l->lp_complex); 25167c478bd9Sstevel@tonic-gate return; 25177c478bd9Sstevel@tonic-gate default: 2518bbec428eSgjelinek zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, B_TRUE); 2519bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 2520bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 25217c478bd9Sstevel@tonic-gate return; 25227c478bd9Sstevel@tonic-gate } 25237c478bd9Sstevel@tonic-gate } 25247c478bd9Sstevel@tonic-gate 25250209230bSgjelinek static boolean_t 25260209230bSgjelinek gz_invalid_resource(int type) 25270209230bSgjelinek { 25286e1ae2a3SGary Pennington return (global_zone && (type == RT_FS || 25290209230bSgjelinek type == RT_NET || type == RT_DEVICE || type == RT_ATTR || 25300209230bSgjelinek type == RT_DATASET)); 25310209230bSgjelinek } 25320209230bSgjelinek 25330209230bSgjelinek static boolean_t 25340209230bSgjelinek gz_invalid_rt_property(int type) 25350209230bSgjelinek { 25360209230bSgjelinek return (global_zone && (type == RT_ZONENAME || type == RT_ZONEPATH || 25370209230bSgjelinek type == RT_AUTOBOOT || type == RT_LIMITPRIV || 2538f4b3ec61Sdh type == RT_BOOTARGS || type == RT_BRAND || type == RT_SCHED || 25390fbb751dSJohn Levon type == RT_IPTYPE || type == RT_HOSTID || type == RT_FS_ALLOWED)); 25400209230bSgjelinek } 25410209230bSgjelinek 25420209230bSgjelinek static boolean_t 25430209230bSgjelinek gz_invalid_property(int type) 25440209230bSgjelinek { 25450209230bSgjelinek return (global_zone && (type == PT_ZONENAME || type == PT_ZONEPATH || 25460209230bSgjelinek type == PT_AUTOBOOT || type == PT_LIMITPRIV || 2547f4b3ec61Sdh type == PT_BOOTARGS || type == PT_BRAND || type == PT_SCHED || 25480fbb751dSJohn Levon type == PT_IPTYPE || type == PT_HOSTID || type == PT_FS_ALLOWED)); 25490209230bSgjelinek } 25500209230bSgjelinek 25517c478bd9Sstevel@tonic-gate void 25527c478bd9Sstevel@tonic-gate add_func(cmd_t *cmd) 25537c478bd9Sstevel@tonic-gate { 25547c478bd9Sstevel@tonic-gate int arg; 2555bbec428eSgjelinek boolean_t arg_err = B_FALSE; 25567c478bd9Sstevel@tonic-gate 25577c478bd9Sstevel@tonic-gate assert(cmd != NULL); 25587c478bd9Sstevel@tonic-gate 25597c478bd9Sstevel@tonic-gate optind = 0; 25607ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 25617c478bd9Sstevel@tonic-gate switch (arg) { 25627c478bd9Sstevel@tonic-gate case '?': 25637c478bd9Sstevel@tonic-gate longer_usage(CMD_ADD); 2564bbec428eSgjelinek arg_err = B_TRUE; 25657ec75eb8Sgjelinek break; 25667c478bd9Sstevel@tonic-gate default: 25677c478bd9Sstevel@tonic-gate short_usage(CMD_ADD); 2568bbec428eSgjelinek arg_err = B_TRUE; 25697ec75eb8Sgjelinek break; 25707c478bd9Sstevel@tonic-gate } 25717c478bd9Sstevel@tonic-gate } 25727ec75eb8Sgjelinek if (arg_err) 25737ec75eb8Sgjelinek return; 25747ec75eb8Sgjelinek 25757c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 25767c478bd9Sstevel@tonic-gate short_usage(CMD_ADD); 25777c478bd9Sstevel@tonic-gate return; 25787c478bd9Sstevel@tonic-gate } 25797c478bd9Sstevel@tonic-gate 25807c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_ADD)) 25817c478bd9Sstevel@tonic-gate return; 25827c478bd9Sstevel@tonic-gate 2583bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 25847c478bd9Sstevel@tonic-gate return; 25857c478bd9Sstevel@tonic-gate if (global_scope) { 25860209230bSgjelinek if (gz_invalid_resource(cmd->cmd_res_type)) { 25870209230bSgjelinek zerr(gettext("Cannot add a %s resource to the " 25880209230bSgjelinek "global zone."), rt_to_str(cmd->cmd_res_type)); 2589bbec428eSgjelinek saw_error = B_TRUE; 25900209230bSgjelinek return; 25910209230bSgjelinek } 25920209230bSgjelinek 2593bbec428eSgjelinek global_scope = B_FALSE; 25947c478bd9Sstevel@tonic-gate resource_scope = cmd->cmd_res_type; 25957c478bd9Sstevel@tonic-gate end_op = CMD_ADD; 25967c478bd9Sstevel@tonic-gate add_resource(cmd); 25977c478bd9Sstevel@tonic-gate } else 25987c478bd9Sstevel@tonic-gate add_property(cmd); 25997c478bd9Sstevel@tonic-gate } 26007c478bd9Sstevel@tonic-gate 2601087719fdSdp /* 2602087719fdSdp * This routine has an unusual implementation, because it tries very 2603087719fdSdp * hard to succeed in the face of a variety of failure modes. 2604087719fdSdp * The most common and most vexing occurs when the index file and 2605087719fdSdp * the /etc/zones/<zonename.xml> file are not both present. In 2606087719fdSdp * this case, delete must eradicate as much of the zone state as is left 2607087719fdSdp * so that the user can later create a new zone with the same name. 2608087719fdSdp */ 26097c478bd9Sstevel@tonic-gate void 26107c478bd9Sstevel@tonic-gate delete_func(cmd_t *cmd) 26117c478bd9Sstevel@tonic-gate { 26127c478bd9Sstevel@tonic-gate int err, arg, answer; 26137c478bd9Sstevel@tonic-gate char line[ZONENAME_MAX + 128]; /* enough to ask a question */ 2614bbec428eSgjelinek boolean_t force = B_FALSE; 2615bbec428eSgjelinek boolean_t arg_err = B_FALSE; 26167c478bd9Sstevel@tonic-gate 26177c478bd9Sstevel@tonic-gate optind = 0; 26187c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 26197c478bd9Sstevel@tonic-gate switch (arg) { 26207c478bd9Sstevel@tonic-gate case '?': 26217c478bd9Sstevel@tonic-gate longer_usage(CMD_DELETE); 2622bbec428eSgjelinek arg_err = B_TRUE; 26237ec75eb8Sgjelinek break; 26247c478bd9Sstevel@tonic-gate case 'F': 2625bbec428eSgjelinek force = B_TRUE; 26267c478bd9Sstevel@tonic-gate break; 26277c478bd9Sstevel@tonic-gate default: 26287c478bd9Sstevel@tonic-gate short_usage(CMD_DELETE); 2629bbec428eSgjelinek arg_err = B_TRUE; 26307ec75eb8Sgjelinek break; 26317c478bd9Sstevel@tonic-gate } 26327c478bd9Sstevel@tonic-gate } 26337ec75eb8Sgjelinek if (arg_err) 26347ec75eb8Sgjelinek return; 26357ec75eb8Sgjelinek 26367c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 26377c478bd9Sstevel@tonic-gate short_usage(CMD_DELETE); 26387c478bd9Sstevel@tonic-gate return; 26397c478bd9Sstevel@tonic-gate } 26407c478bd9Sstevel@tonic-gate 26417c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_DELETE)) 26427c478bd9Sstevel@tonic-gate return; 26437c478bd9Sstevel@tonic-gate 26447c478bd9Sstevel@tonic-gate if (!force) { 2645087719fdSdp /* 2646087719fdSdp * Initialize sets up the global called "handle" and warns the 2647087719fdSdp * user if the zone is not configured. In force mode, we don't 2648087719fdSdp * trust that evaluation, and hence skip it. (We don't need the 2649087719fdSdp * handle to be loaded anyway, since zonecfg_destroy is done by 2650cb8a054bSGlenn Faden * zonename). However, we also have to take care to emulate the 2651087719fdSdp * messages spit out by initialize; see below. 2652087719fdSdp */ 2653bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 2654087719fdSdp return; 2655087719fdSdp 26567c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 26577c478bd9Sstevel@tonic-gate gettext("Are you sure you want to delete zone %s"), zone); 2658bbec428eSgjelinek if ((answer = ask_yesno(B_FALSE, line)) == -1) { 2659087719fdSdp zerr(gettext("Input not from terminal and -F not " 2660087719fdSdp "specified:\n%s command ignored, exiting."), 2661087719fdSdp cmd_to_str(CMD_DELETE)); 26627c478bd9Sstevel@tonic-gate exit(Z_ERR); 26637c478bd9Sstevel@tonic-gate } 26647c478bd9Sstevel@tonic-gate if (answer != 1) 26657c478bd9Sstevel@tonic-gate return; 26667c478bd9Sstevel@tonic-gate } 26677c478bd9Sstevel@tonic-gate 2668cb8a054bSGlenn Faden /* 2669cb8a054bSGlenn Faden * This function removes the authorizations from user_attr 2670cb8a054bSGlenn Faden * that correspond to those specified in the configuration 2671cb8a054bSGlenn Faden */ 2672cb8a054bSGlenn Faden if (initialize(B_TRUE) == Z_OK) { 2673cb8a054bSGlenn Faden (void) zonecfg_deauthorize_users(handle, zone); 2674cb8a054bSGlenn Faden } 2675087719fdSdp if ((err = zonecfg_destroy(zone, force)) != Z_OK) { 2676087719fdSdp if ((err == Z_BAD_ZONE_STATE) && !force) { 2677087719fdSdp zerr(gettext("Zone %s not in %s state; %s not " 2678087719fdSdp "allowed. Use -F to force %s."), 2679087719fdSdp zone, zone_state_str(ZONE_STATE_CONFIGURED), 2680087719fdSdp cmd_to_str(CMD_DELETE), cmd_to_str(CMD_DELETE)); 2681087719fdSdp } else { 2682bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 2683087719fdSdp } 26847c478bd9Sstevel@tonic-gate } 2685bbec428eSgjelinek need_to_commit = B_FALSE; 2686087719fdSdp 2687087719fdSdp /* 2688087719fdSdp * Emulate initialize's messaging; if there wasn't a valid handle to 2689087719fdSdp * begin with, then user had typed delete (or delete -F) multiple 2690087719fdSdp * times. So we emit a message. 2691087719fdSdp * 2692087719fdSdp * We only do this in the 'force' case because normally, initialize() 2693087719fdSdp * takes care of this for us. 2694087719fdSdp */ 2695087719fdSdp if (force && zonecfg_check_handle(handle) != Z_OK && interactive_mode) 2696087719fdSdp (void) printf(gettext("Use '%s' to begin " 2697087719fdSdp "configuring a new zone.\n"), cmd_to_str(CMD_CREATE)); 26987c478bd9Sstevel@tonic-gate 26997c478bd9Sstevel@tonic-gate /* 27007c478bd9Sstevel@tonic-gate * Time for a new handle: finish the old one off first 27017c478bd9Sstevel@tonic-gate * then get a new one properly to avoid leaks. 27027c478bd9Sstevel@tonic-gate */ 2703087719fdSdp if (got_handle) { 2704087719fdSdp zonecfg_fini_handle(handle); 2705087719fdSdp if ((handle = zonecfg_init_handle()) == NULL) { 2706bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 2707087719fdSdp exit(Z_ERR); 2708087719fdSdp } 2709087719fdSdp if ((err = zonecfg_get_handle(zone, handle)) != Z_OK) { 2710087719fdSdp /* If there was no zone before, that's OK */ 2711087719fdSdp if (err != Z_NO_ZONE) 2712bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 2713bbec428eSgjelinek got_handle = B_FALSE; 2714087719fdSdp } 27157c478bd9Sstevel@tonic-gate } 27167c478bd9Sstevel@tonic-gate } 27177c478bd9Sstevel@tonic-gate 27187c478bd9Sstevel@tonic-gate static int 2719bbec428eSgjelinek fill_in_fstab(cmd_t *cmd, struct zone_fstab *fstab, boolean_t fill_in_only) 27207c478bd9Sstevel@tonic-gate { 27217c478bd9Sstevel@tonic-gate int err, i; 27227c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 27237c478bd9Sstevel@tonic-gate 2724bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 27257c478bd9Sstevel@tonic-gate return (err); 27267c478bd9Sstevel@tonic-gate 2727e193d1e6Svp bzero(fstab, sizeof (*fstab)); 27287c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 27297c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 27307c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 27317c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2732bbec428eSgjelinek saw_error = B_TRUE; 27337c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 27347c478bd9Sstevel@tonic-gate } 27357c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 27367c478bd9Sstevel@tonic-gate case PT_DIR: 27377c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_dir, pp->pv_simple, 27387c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_dir)); 27397c478bd9Sstevel@tonic-gate break; 27407c478bd9Sstevel@tonic-gate case PT_SPECIAL: 27417c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_special, pp->pv_simple, 27427c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_special)); 27437c478bd9Sstevel@tonic-gate break; 27447c478bd9Sstevel@tonic-gate case PT_RAW: 27457c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_raw, pp->pv_simple, 27467c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_raw)); 27477c478bd9Sstevel@tonic-gate break; 27487c478bd9Sstevel@tonic-gate case PT_TYPE: 27497c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_type, pp->pv_simple, 27507c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_type)); 27517c478bd9Sstevel@tonic-gate break; 27527c478bd9Sstevel@tonic-gate default: 27537c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2754bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 27557c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 27567c478bd9Sstevel@tonic-gate } 27577c478bd9Sstevel@tonic-gate } 27587c478bd9Sstevel@tonic-gate if (fill_in_only) 27597c478bd9Sstevel@tonic-gate return (Z_OK); 27607c478bd9Sstevel@tonic-gate return (zonecfg_lookup_filesystem(handle, fstab)); 27617c478bd9Sstevel@tonic-gate } 27627c478bd9Sstevel@tonic-gate 27637c478bd9Sstevel@tonic-gate static int 2764bbec428eSgjelinek fill_in_nwiftab(cmd_t *cmd, struct zone_nwiftab *nwiftab, 2765bbec428eSgjelinek boolean_t fill_in_only) 27667c478bd9Sstevel@tonic-gate { 27677c478bd9Sstevel@tonic-gate int err, i; 27687c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 27697c478bd9Sstevel@tonic-gate 2770bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 27717c478bd9Sstevel@tonic-gate return (err); 27727c478bd9Sstevel@tonic-gate 2773e193d1e6Svp bzero(nwiftab, sizeof (*nwiftab)); 27747c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 27757c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 27767c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 27777c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2778bbec428eSgjelinek saw_error = B_TRUE; 27797c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 27807c478bd9Sstevel@tonic-gate } 27817c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 27827c478bd9Sstevel@tonic-gate case PT_ADDRESS: 27837c478bd9Sstevel@tonic-gate (void) strlcpy(nwiftab->zone_nwif_address, 27847c478bd9Sstevel@tonic-gate pp->pv_simple, sizeof (nwiftab->zone_nwif_address)); 27857c478bd9Sstevel@tonic-gate break; 2786550b6e40SSowmini Varadhan case PT_ALLOWED_ADDRESS: 2787550b6e40SSowmini Varadhan (void) strlcpy(nwiftab->zone_nwif_allowed_address, 2788550b6e40SSowmini Varadhan pp->pv_simple, 2789550b6e40SSowmini Varadhan sizeof (nwiftab->zone_nwif_allowed_address)); 2790550b6e40SSowmini Varadhan break; 27917c478bd9Sstevel@tonic-gate case PT_PHYSICAL: 27927c478bd9Sstevel@tonic-gate (void) strlcpy(nwiftab->zone_nwif_physical, 27937c478bd9Sstevel@tonic-gate pp->pv_simple, 27947c478bd9Sstevel@tonic-gate sizeof (nwiftab->zone_nwif_physical)); 27957c478bd9Sstevel@tonic-gate break; 2796de860bd9Sgfaden case PT_DEFROUTER: 2797de860bd9Sgfaden (void) strlcpy(nwiftab->zone_nwif_defrouter, 2798de860bd9Sgfaden pp->pv_simple, 2799de860bd9Sgfaden sizeof (nwiftab->zone_nwif_defrouter)); 2800de860bd9Sgfaden break; 28017c478bd9Sstevel@tonic-gate default: 28027c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2803bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 28047c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 28057c478bd9Sstevel@tonic-gate } 28067c478bd9Sstevel@tonic-gate } 28077c478bd9Sstevel@tonic-gate if (fill_in_only) 28087c478bd9Sstevel@tonic-gate return (Z_OK); 28097c478bd9Sstevel@tonic-gate err = zonecfg_lookup_nwif(handle, nwiftab); 28107c478bd9Sstevel@tonic-gate return (err); 28117c478bd9Sstevel@tonic-gate } 28127c478bd9Sstevel@tonic-gate 28137c478bd9Sstevel@tonic-gate static int 2814bbec428eSgjelinek fill_in_devtab(cmd_t *cmd, struct zone_devtab *devtab, boolean_t fill_in_only) 28157c478bd9Sstevel@tonic-gate { 28167c478bd9Sstevel@tonic-gate int err, i; 28177c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 28187c478bd9Sstevel@tonic-gate 2819bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 28207c478bd9Sstevel@tonic-gate return (err); 28217c478bd9Sstevel@tonic-gate 2822e193d1e6Svp bzero(devtab, sizeof (*devtab)); 28237c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 28247c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 28257c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 28267c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2827bbec428eSgjelinek saw_error = B_TRUE; 28287c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 28297c478bd9Sstevel@tonic-gate } 28307c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 28317c478bd9Sstevel@tonic-gate case PT_MATCH: 28327c478bd9Sstevel@tonic-gate (void) strlcpy(devtab->zone_dev_match, pp->pv_simple, 28337c478bd9Sstevel@tonic-gate sizeof (devtab->zone_dev_match)); 28347c478bd9Sstevel@tonic-gate break; 28357c478bd9Sstevel@tonic-gate default: 28367c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2837bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 28387c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 28397c478bd9Sstevel@tonic-gate } 28407c478bd9Sstevel@tonic-gate } 28417c478bd9Sstevel@tonic-gate if (fill_in_only) 28427c478bd9Sstevel@tonic-gate return (Z_OK); 28437c478bd9Sstevel@tonic-gate err = zonecfg_lookup_dev(handle, devtab); 28447c478bd9Sstevel@tonic-gate return (err); 28457c478bd9Sstevel@tonic-gate } 28467c478bd9Sstevel@tonic-gate 28477c478bd9Sstevel@tonic-gate static int 2848bbec428eSgjelinek fill_in_rctltab(cmd_t *cmd, struct zone_rctltab *rctltab, 2849bbec428eSgjelinek boolean_t fill_in_only) 28507c478bd9Sstevel@tonic-gate { 28517c478bd9Sstevel@tonic-gate int err, i; 28527c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 28537c478bd9Sstevel@tonic-gate 2854bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 28557c478bd9Sstevel@tonic-gate return (err); 28567c478bd9Sstevel@tonic-gate 2857e193d1e6Svp bzero(rctltab, sizeof (*rctltab)); 28587c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 28597c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 28607c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 28617c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2862bbec428eSgjelinek saw_error = B_TRUE; 28637c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 28647c478bd9Sstevel@tonic-gate } 28657c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 28667c478bd9Sstevel@tonic-gate case PT_NAME: 28677c478bd9Sstevel@tonic-gate (void) strlcpy(rctltab->zone_rctl_name, pp->pv_simple, 28687c478bd9Sstevel@tonic-gate sizeof (rctltab->zone_rctl_name)); 28697c478bd9Sstevel@tonic-gate break; 28707c478bd9Sstevel@tonic-gate default: 28717c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2872bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 28737c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 28747c478bd9Sstevel@tonic-gate } 28757c478bd9Sstevel@tonic-gate } 28767c478bd9Sstevel@tonic-gate if (fill_in_only) 28777c478bd9Sstevel@tonic-gate return (Z_OK); 28787c478bd9Sstevel@tonic-gate err = zonecfg_lookup_rctl(handle, rctltab); 28797c478bd9Sstevel@tonic-gate return (err); 28807c478bd9Sstevel@tonic-gate } 28817c478bd9Sstevel@tonic-gate 28827c478bd9Sstevel@tonic-gate static int 2883bbec428eSgjelinek fill_in_attrtab(cmd_t *cmd, struct zone_attrtab *attrtab, 2884bbec428eSgjelinek boolean_t fill_in_only) 28857c478bd9Sstevel@tonic-gate { 28867c478bd9Sstevel@tonic-gate int err, i; 28877c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 28887c478bd9Sstevel@tonic-gate 2889bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 28907c478bd9Sstevel@tonic-gate return (err); 28917c478bd9Sstevel@tonic-gate 2892e193d1e6Svp bzero(attrtab, sizeof (*attrtab)); 28937c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 28947c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 28957c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 28967c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2897bbec428eSgjelinek saw_error = B_TRUE; 28987c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 28997c478bd9Sstevel@tonic-gate } 29007c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 29017c478bd9Sstevel@tonic-gate case PT_NAME: 29027c478bd9Sstevel@tonic-gate (void) strlcpy(attrtab->zone_attr_name, pp->pv_simple, 29037c478bd9Sstevel@tonic-gate sizeof (attrtab->zone_attr_name)); 29047c478bd9Sstevel@tonic-gate break; 29057c478bd9Sstevel@tonic-gate case PT_TYPE: 29067c478bd9Sstevel@tonic-gate (void) strlcpy(attrtab->zone_attr_type, pp->pv_simple, 29077c478bd9Sstevel@tonic-gate sizeof (attrtab->zone_attr_type)); 29087c478bd9Sstevel@tonic-gate break; 29097c478bd9Sstevel@tonic-gate case PT_VALUE: 29107c478bd9Sstevel@tonic-gate (void) strlcpy(attrtab->zone_attr_value, pp->pv_simple, 29117c478bd9Sstevel@tonic-gate sizeof (attrtab->zone_attr_value)); 29127c478bd9Sstevel@tonic-gate break; 29137c478bd9Sstevel@tonic-gate default: 29147c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2915bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 29167c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 29177c478bd9Sstevel@tonic-gate } 29187c478bd9Sstevel@tonic-gate } 29197c478bd9Sstevel@tonic-gate if (fill_in_only) 29207c478bd9Sstevel@tonic-gate return (Z_OK); 29217c478bd9Sstevel@tonic-gate err = zonecfg_lookup_attr(handle, attrtab); 29227c478bd9Sstevel@tonic-gate return (err); 29237c478bd9Sstevel@tonic-gate } 29247c478bd9Sstevel@tonic-gate 2925fa9e4066Sahrens static int 2926bbec428eSgjelinek fill_in_dstab(cmd_t *cmd, struct zone_dstab *dstab, boolean_t fill_in_only) 2927fa9e4066Sahrens { 2928fa9e4066Sahrens int err, i; 2929fa9e4066Sahrens property_value_ptr_t pp; 2930fa9e4066Sahrens 2931bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 2932fa9e4066Sahrens return (err); 2933fa9e4066Sahrens 2934fa9e4066Sahrens dstab->zone_dataset_name[0] = '\0'; 2935fa9e4066Sahrens for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 2936fa9e4066Sahrens pp = cmd->cmd_property_ptr[i]; 2937fa9e4066Sahrens if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 2938fa9e4066Sahrens zerr(gettext("A simple value was expected here.")); 2939bbec428eSgjelinek saw_error = B_TRUE; 2940fa9e4066Sahrens return (Z_INSUFFICIENT_SPEC); 2941fa9e4066Sahrens } 2942fa9e4066Sahrens switch (cmd->cmd_prop_name[i]) { 2943fa9e4066Sahrens case PT_NAME: 2944fa9e4066Sahrens (void) strlcpy(dstab->zone_dataset_name, pp->pv_simple, 2945fa9e4066Sahrens sizeof (dstab->zone_dataset_name)); 2946fa9e4066Sahrens break; 2947fa9e4066Sahrens default: 2948fa9e4066Sahrens zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2949bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 2950fa9e4066Sahrens return (Z_INSUFFICIENT_SPEC); 2951fa9e4066Sahrens } 2952fa9e4066Sahrens } 2953fa9e4066Sahrens if (fill_in_only) 2954fa9e4066Sahrens return (Z_OK); 2955fa9e4066Sahrens return (zonecfg_lookup_ds(handle, dstab)); 2956fa9e4066Sahrens } 2957fa9e4066Sahrens 2958cb8a054bSGlenn Faden static int 2959cb8a054bSGlenn Faden fill_in_admintab(cmd_t *cmd, struct zone_admintab *admintab, 2960cb8a054bSGlenn Faden boolean_t fill_in_only) 2961cb8a054bSGlenn Faden { 2962cb8a054bSGlenn Faden int err, i; 2963cb8a054bSGlenn Faden property_value_ptr_t pp; 2964cb8a054bSGlenn Faden 2965cb8a054bSGlenn Faden if ((err = initialize(B_TRUE)) != Z_OK) 2966cb8a054bSGlenn Faden return (err); 2967cb8a054bSGlenn Faden 2968cb8a054bSGlenn Faden bzero(admintab, sizeof (*admintab)); 2969cb8a054bSGlenn Faden for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 2970cb8a054bSGlenn Faden pp = cmd->cmd_property_ptr[i]; 2971cb8a054bSGlenn Faden if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 2972cb8a054bSGlenn Faden zerr(gettext("A simple value was expected here.")); 2973cb8a054bSGlenn Faden saw_error = B_TRUE; 2974cb8a054bSGlenn Faden return (Z_INSUFFICIENT_SPEC); 2975cb8a054bSGlenn Faden } 2976cb8a054bSGlenn Faden switch (cmd->cmd_prop_name[i]) { 2977cb8a054bSGlenn Faden case PT_USER: 2978cb8a054bSGlenn Faden (void) strlcpy(admintab->zone_admin_user, pp->pv_simple, 2979cb8a054bSGlenn Faden sizeof (admintab->zone_admin_user)); 2980cb8a054bSGlenn Faden break; 2981cb8a054bSGlenn Faden case PT_AUTHS: 2982cb8a054bSGlenn Faden (void) strlcpy(admintab->zone_admin_auths, 2983cb8a054bSGlenn Faden pp->pv_simple, sizeof (admintab->zone_admin_auths)); 2984cb8a054bSGlenn Faden break; 2985cb8a054bSGlenn Faden default: 2986cb8a054bSGlenn Faden zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2987cb8a054bSGlenn Faden Z_NO_PROPERTY_TYPE, B_TRUE); 2988cb8a054bSGlenn Faden return (Z_INSUFFICIENT_SPEC); 2989cb8a054bSGlenn Faden } 2990cb8a054bSGlenn Faden } 2991cb8a054bSGlenn Faden if (fill_in_only) 2992cb8a054bSGlenn Faden return (Z_OK); 2993cb8a054bSGlenn Faden err = zonecfg_lookup_admin(handle, admintab); 2994cb8a054bSGlenn Faden return (err); 2995cb8a054bSGlenn Faden } 2996cb8a054bSGlenn Faden 2997*d2a70789SRichard Lowe static int 2998*d2a70789SRichard Lowe fill_in_secflagstab(cmd_t *cmd, struct zone_secflagstab *secflagstab, 2999*d2a70789SRichard Lowe boolean_t fill_in_only) 3000*d2a70789SRichard Lowe { 3001*d2a70789SRichard Lowe int err, i; 3002*d2a70789SRichard Lowe property_value_ptr_t pp; 3003*d2a70789SRichard Lowe 3004*d2a70789SRichard Lowe if ((err = initialize(B_TRUE)) != Z_OK) 3005*d2a70789SRichard Lowe return (err); 3006*d2a70789SRichard Lowe 3007*d2a70789SRichard Lowe bzero(secflagstab, sizeof (*secflagstab)); 3008*d2a70789SRichard Lowe for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 3009*d2a70789SRichard Lowe pp = cmd->cmd_property_ptr[i]; 3010*d2a70789SRichard Lowe if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 3011*d2a70789SRichard Lowe zerr(gettext("A simple value was expected here.")); 3012*d2a70789SRichard Lowe saw_error = B_TRUE; 3013*d2a70789SRichard Lowe return (Z_INSUFFICIENT_SPEC); 3014*d2a70789SRichard Lowe } 3015*d2a70789SRichard Lowe switch (cmd->cmd_prop_name[i]) { 3016*d2a70789SRichard Lowe case PT_DEFAULT: 3017*d2a70789SRichard Lowe (void) strlcpy(secflagstab->zone_secflags_default, 3018*d2a70789SRichard Lowe pp->pv_simple, 3019*d2a70789SRichard Lowe sizeof (secflagstab->zone_secflags_default)); 3020*d2a70789SRichard Lowe break; 3021*d2a70789SRichard Lowe case PT_LOWER: 3022*d2a70789SRichard Lowe (void) strlcpy(secflagstab->zone_secflags_lower, 3023*d2a70789SRichard Lowe pp->pv_simple, 3024*d2a70789SRichard Lowe sizeof (secflagstab->zone_secflags_lower)); 3025*d2a70789SRichard Lowe break; 3026*d2a70789SRichard Lowe case PT_UPPER: 3027*d2a70789SRichard Lowe (void) strlcpy(secflagstab->zone_secflags_upper, 3028*d2a70789SRichard Lowe pp->pv_simple, 3029*d2a70789SRichard Lowe sizeof (secflagstab->zone_secflags_upper)); 3030*d2a70789SRichard Lowe break; 3031*d2a70789SRichard Lowe default: 3032*d2a70789SRichard Lowe zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 3033*d2a70789SRichard Lowe Z_NO_PROPERTY_TYPE, B_TRUE); 3034*d2a70789SRichard Lowe return (Z_INSUFFICIENT_SPEC); 3035*d2a70789SRichard Lowe } 3036*d2a70789SRichard Lowe } 3037*d2a70789SRichard Lowe if (fill_in_only) 3038*d2a70789SRichard Lowe return (Z_OK); 3039*d2a70789SRichard Lowe 3040*d2a70789SRichard Lowe err = zonecfg_lookup_secflags(handle, secflagstab); 3041*d2a70789SRichard Lowe 3042*d2a70789SRichard Lowe return (err); 3043*d2a70789SRichard Lowe } 3044*d2a70789SRichard Lowe 30457c478bd9Sstevel@tonic-gate static void 30460209230bSgjelinek remove_aliased_rctl(int type, char *name) 30477c478bd9Sstevel@tonic-gate { 30480209230bSgjelinek int err; 30490209230bSgjelinek uint64_t tmp; 30507c478bd9Sstevel@tonic-gate 30510209230bSgjelinek if ((err = zonecfg_get_aliased_rctl(handle, name, &tmp)) != Z_OK) { 30520209230bSgjelinek zerr("%s %s: %s", cmd_to_str(CMD_CLEAR), pt_to_str(type), 30530209230bSgjelinek zonecfg_strerror(err)); 3054bbec428eSgjelinek saw_error = B_TRUE; 30557c478bd9Sstevel@tonic-gate return; 30567c478bd9Sstevel@tonic-gate } 30570209230bSgjelinek if ((err = zonecfg_rm_aliased_rctl(handle, name)) != Z_OK) { 30580209230bSgjelinek zerr("%s %s: %s", cmd_to_str(CMD_CLEAR), pt_to_str(type), 30590209230bSgjelinek zonecfg_strerror(err)); 3060bbec428eSgjelinek saw_error = B_TRUE; 30610209230bSgjelinek } else { 3062bbec428eSgjelinek need_to_commit = B_TRUE; 30630209230bSgjelinek } 30640209230bSgjelinek } 30657c478bd9Sstevel@tonic-gate 30660209230bSgjelinek static boolean_t 30670209230bSgjelinek prompt_remove_resource(cmd_t *cmd, char *rsrc) 30680209230bSgjelinek { 30690209230bSgjelinek int num; 30700209230bSgjelinek int answer; 30710209230bSgjelinek int arg; 30720209230bSgjelinek boolean_t force = B_FALSE; 30730209230bSgjelinek char prompt[128]; 3074bbec428eSgjelinek boolean_t arg_err = B_FALSE; 30750209230bSgjelinek 30760209230bSgjelinek optind = 0; 30770209230bSgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "F")) != EOF) { 30780209230bSgjelinek switch (arg) { 30790209230bSgjelinek case 'F': 30800209230bSgjelinek force = B_TRUE; 30810209230bSgjelinek break; 30820209230bSgjelinek default: 3083bbec428eSgjelinek arg_err = B_TRUE; 30847ec75eb8Sgjelinek break; 30850209230bSgjelinek } 30860209230bSgjelinek } 30877ec75eb8Sgjelinek if (arg_err) 30887ec75eb8Sgjelinek return (B_FALSE); 30897ec75eb8Sgjelinek 30900209230bSgjelinek 30910209230bSgjelinek num = zonecfg_num_resources(handle, rsrc); 30920209230bSgjelinek 30930209230bSgjelinek if (num == 0) { 30940209230bSgjelinek z_cmd_rt_perror(CMD_REMOVE, cmd->cmd_res_type, Z_NO_ENTRY, 3095bbec428eSgjelinek B_TRUE); 30960209230bSgjelinek return (B_FALSE); 30970209230bSgjelinek } 30980209230bSgjelinek if (num > 1 && !force) { 30990209230bSgjelinek if (!interactive_mode) { 31000209230bSgjelinek zerr(gettext("There are multiple instances of this " 31010209230bSgjelinek "resource. Either qualify the resource to\n" 31020209230bSgjelinek "remove a single instance or use the -F option to " 31030209230bSgjelinek "remove all instances.")); 3104bbec428eSgjelinek saw_error = B_TRUE; 31050209230bSgjelinek return (B_FALSE); 31060209230bSgjelinek } 31070209230bSgjelinek (void) snprintf(prompt, sizeof (prompt), gettext( 31080209230bSgjelinek "Are you sure you want to remove ALL '%s' resources"), 31090209230bSgjelinek rsrc); 3110bbec428eSgjelinek answer = ask_yesno(B_FALSE, prompt); 31110209230bSgjelinek if (answer == -1) { 31120209230bSgjelinek zerr(gettext("Resource incomplete.")); 31130209230bSgjelinek return (B_FALSE); 31140209230bSgjelinek } 31150209230bSgjelinek if (answer != 1) 31160209230bSgjelinek return (B_FALSE); 31170209230bSgjelinek } 31180209230bSgjelinek return (B_TRUE); 31190209230bSgjelinek } 31200209230bSgjelinek 31210209230bSgjelinek static void 31220209230bSgjelinek remove_fs(cmd_t *cmd) 31230209230bSgjelinek { 31240209230bSgjelinek int err; 31250209230bSgjelinek 31260209230bSgjelinek /* traditional, qualified fs removal */ 31270209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 31280209230bSgjelinek struct zone_fstab fstab; 31297c478bd9Sstevel@tonic-gate 3130bbec428eSgjelinek if ((err = fill_in_fstab(cmd, &fstab, B_FALSE)) != Z_OK) { 3131bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_FS, err, B_TRUE); 31327c478bd9Sstevel@tonic-gate return; 31337c478bd9Sstevel@tonic-gate } 31347c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_filesystem(handle, &fstab)) != Z_OK) 3135bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_FS, err, B_TRUE); 31367c478bd9Sstevel@tonic-gate else 3137bbec428eSgjelinek need_to_commit = B_TRUE; 31387c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(fstab.zone_fs_options); 31397c478bd9Sstevel@tonic-gate return; 31400209230bSgjelinek } 31410209230bSgjelinek 31420209230bSgjelinek /* 31430209230bSgjelinek * unqualified fs removal. remove all fs's but prompt if more 31440209230bSgjelinek * than one. 31450209230bSgjelinek */ 31460209230bSgjelinek if (!prompt_remove_resource(cmd, "fs")) 31470209230bSgjelinek return; 31480209230bSgjelinek 31490209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "fs")) != Z_OK) 3150bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_FS, err, B_TRUE); 31510209230bSgjelinek else 3152bbec428eSgjelinek need_to_commit = B_TRUE; 31530209230bSgjelinek } 31540209230bSgjelinek 31550209230bSgjelinek static void 31560209230bSgjelinek remove_net(cmd_t *cmd) 31570209230bSgjelinek { 31580209230bSgjelinek int err; 31590209230bSgjelinek 31600209230bSgjelinek /* traditional, qualified net removal */ 31610209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 31620209230bSgjelinek struct zone_nwiftab nwiftab; 31630209230bSgjelinek 3164bbec428eSgjelinek if ((err = fill_in_nwiftab(cmd, &nwiftab, B_FALSE)) != Z_OK) { 3165bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_NET, err, B_TRUE); 31667c478bd9Sstevel@tonic-gate return; 31677c478bd9Sstevel@tonic-gate } 31687c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_nwif(handle, &nwiftab)) != Z_OK) 3169bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_NET, err, B_TRUE); 31707c478bd9Sstevel@tonic-gate else 3171bbec428eSgjelinek need_to_commit = B_TRUE; 31727c478bd9Sstevel@tonic-gate return; 31730209230bSgjelinek } 31740209230bSgjelinek 31750209230bSgjelinek /* 31760209230bSgjelinek * unqualified net removal. remove all nets but prompt if more 31770209230bSgjelinek * than one. 31780209230bSgjelinek */ 31790209230bSgjelinek if (!prompt_remove_resource(cmd, "net")) 31800209230bSgjelinek return; 31810209230bSgjelinek 31820209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "net")) != Z_OK) 3183bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_NET, err, B_TRUE); 31840209230bSgjelinek else 3185bbec428eSgjelinek need_to_commit = B_TRUE; 31860209230bSgjelinek } 31870209230bSgjelinek 31880209230bSgjelinek static void 31890209230bSgjelinek remove_device(cmd_t *cmd) 31900209230bSgjelinek { 31910209230bSgjelinek int err; 31920209230bSgjelinek 31930209230bSgjelinek /* traditional, qualified device removal */ 31940209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 31950209230bSgjelinek struct zone_devtab devtab; 31960209230bSgjelinek 3197bbec428eSgjelinek if ((err = fill_in_devtab(cmd, &devtab, B_FALSE)) != Z_OK) { 3198bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DEVICE, err, B_TRUE); 31997c478bd9Sstevel@tonic-gate return; 32007c478bd9Sstevel@tonic-gate } 32017c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_dev(handle, &devtab)) != Z_OK) 3202bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DEVICE, err, B_TRUE); 32037c478bd9Sstevel@tonic-gate else 3204bbec428eSgjelinek need_to_commit = B_TRUE; 32057c478bd9Sstevel@tonic-gate return; 32060209230bSgjelinek } 32070209230bSgjelinek 32080209230bSgjelinek /* 32090209230bSgjelinek * unqualified device removal. remove all devices but prompt if more 32100209230bSgjelinek * than one. 32110209230bSgjelinek */ 32120209230bSgjelinek if (!prompt_remove_resource(cmd, "device")) 32137c478bd9Sstevel@tonic-gate return; 32140209230bSgjelinek 32150209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "device")) != Z_OK) 3216bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DEVICE, err, B_TRUE); 32170209230bSgjelinek else 3218bbec428eSgjelinek need_to_commit = B_TRUE; 32190209230bSgjelinek } 32200209230bSgjelinek 32210209230bSgjelinek static void 32220209230bSgjelinek remove_attr(cmd_t *cmd) 32230209230bSgjelinek { 32240209230bSgjelinek int err; 32250209230bSgjelinek 32260209230bSgjelinek /* traditional, qualified attr removal */ 32270209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 32280209230bSgjelinek struct zone_attrtab attrtab; 32290209230bSgjelinek 3230bbec428eSgjelinek if ((err = fill_in_attrtab(cmd, &attrtab, B_FALSE)) != Z_OK) { 3231bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_ATTR, err, B_TRUE); 32327c478bd9Sstevel@tonic-gate return; 32337c478bd9Sstevel@tonic-gate } 32347c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_attr(handle, &attrtab)) != Z_OK) 3235bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_ATTR, err, B_TRUE); 32367c478bd9Sstevel@tonic-gate else 3237bbec428eSgjelinek need_to_commit = B_TRUE; 32387c478bd9Sstevel@tonic-gate return; 32390209230bSgjelinek } 32400209230bSgjelinek 32410209230bSgjelinek /* 32420209230bSgjelinek * unqualified attr removal. remove all attrs but prompt if more 32430209230bSgjelinek * than one. 32440209230bSgjelinek */ 32450209230bSgjelinek if (!prompt_remove_resource(cmd, "attr")) 32460209230bSgjelinek return; 32470209230bSgjelinek 32480209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "attr")) != Z_OK) 3249bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_ATTR, err, B_TRUE); 32500209230bSgjelinek else 3251bbec428eSgjelinek need_to_commit = B_TRUE; 32520209230bSgjelinek } 32530209230bSgjelinek 32540209230bSgjelinek static void 32550209230bSgjelinek remove_dataset(cmd_t *cmd) 32560209230bSgjelinek { 32570209230bSgjelinek int err; 32580209230bSgjelinek 32590209230bSgjelinek /* traditional, qualified dataset removal */ 32600209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 32610209230bSgjelinek struct zone_dstab dstab; 32620209230bSgjelinek 3263bbec428eSgjelinek if ((err = fill_in_dstab(cmd, &dstab, B_FALSE)) != Z_OK) { 3264bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DATASET, err, B_TRUE); 3265fa9e4066Sahrens return; 3266fa9e4066Sahrens } 3267fa9e4066Sahrens if ((err = zonecfg_delete_ds(handle, &dstab)) != Z_OK) 3268bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DATASET, err, B_TRUE); 3269fa9e4066Sahrens else 3270bbec428eSgjelinek need_to_commit = B_TRUE; 3271fa9e4066Sahrens return; 32727c478bd9Sstevel@tonic-gate } 32730209230bSgjelinek 32740209230bSgjelinek /* 32750209230bSgjelinek * unqualified dataset removal. remove all datasets but prompt if more 32760209230bSgjelinek * than one. 32770209230bSgjelinek */ 32780209230bSgjelinek if (!prompt_remove_resource(cmd, "dataset")) 32790209230bSgjelinek return; 32800209230bSgjelinek 32810209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "dataset")) != Z_OK) 3282bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DATASET, err, B_TRUE); 32830209230bSgjelinek else 3284bbec428eSgjelinek need_to_commit = B_TRUE; 32850209230bSgjelinek } 32860209230bSgjelinek 32870209230bSgjelinek static void 32880209230bSgjelinek remove_rctl(cmd_t *cmd) 32890209230bSgjelinek { 32900209230bSgjelinek int err; 32910209230bSgjelinek 32920209230bSgjelinek /* traditional, qualified rctl removal */ 32930209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 32940209230bSgjelinek struct zone_rctltab rctltab; 32950209230bSgjelinek 3296bbec428eSgjelinek if ((err = fill_in_rctltab(cmd, &rctltab, B_FALSE)) != Z_OK) { 3297bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_RCTL, err, B_TRUE); 32980209230bSgjelinek return; 32990209230bSgjelinek } 33000209230bSgjelinek if ((err = zonecfg_delete_rctl(handle, &rctltab)) != Z_OK) 3301bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_RCTL, err, B_TRUE); 33020209230bSgjelinek else 3303bbec428eSgjelinek need_to_commit = B_TRUE; 33040209230bSgjelinek zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr); 33050209230bSgjelinek return; 33060209230bSgjelinek } 33070209230bSgjelinek 33080209230bSgjelinek /* 33090209230bSgjelinek * unqualified rctl removal. remove all rctls but prompt if more 33100209230bSgjelinek * than one. 33110209230bSgjelinek */ 33120209230bSgjelinek if (!prompt_remove_resource(cmd, "rctl")) 33130209230bSgjelinek return; 33140209230bSgjelinek 33150209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "rctl")) != Z_OK) 3316bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_RCTL, err, B_TRUE); 33170209230bSgjelinek else 3318bbec428eSgjelinek need_to_commit = B_TRUE; 33190209230bSgjelinek } 33200209230bSgjelinek 33210209230bSgjelinek static void 33220209230bSgjelinek remove_pset() 33230209230bSgjelinek { 33240209230bSgjelinek int err; 33250209230bSgjelinek struct zone_psettab psettab; 33260209230bSgjelinek 33270209230bSgjelinek if ((err = zonecfg_lookup_pset(handle, &psettab)) != Z_OK) { 3328bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DCPU, err, B_TRUE); 33290209230bSgjelinek return; 33300209230bSgjelinek } 33310209230bSgjelinek if ((err = zonecfg_delete_pset(handle)) != Z_OK) 3332bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DCPU, err, B_TRUE); 33330209230bSgjelinek else 3334bbec428eSgjelinek need_to_commit = B_TRUE; 33350209230bSgjelinek } 33360209230bSgjelinek 3337c97ad5cdSakolb static void 3338c97ad5cdSakolb remove_pcap() 3339c97ad5cdSakolb { 3340c97ad5cdSakolb int err; 3341c97ad5cdSakolb uint64_t tmp; 3342c97ad5cdSakolb 3343c97ad5cdSakolb if (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &tmp) != Z_OK) { 3344c97ad5cdSakolb zerr("%s %s: %s", cmd_to_str(CMD_REMOVE), rt_to_str(RT_PCAP), 3345c97ad5cdSakolb zonecfg_strerror(Z_NO_RESOURCE_TYPE)); 3346bbec428eSgjelinek saw_error = B_TRUE; 3347c97ad5cdSakolb return; 3348c97ad5cdSakolb } 3349c97ad5cdSakolb 3350c97ad5cdSakolb if ((err = zonecfg_rm_aliased_rctl(handle, ALIAS_CPUCAP)) != Z_OK) 3351bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_PCAP, err, B_TRUE); 3352c97ad5cdSakolb else 3353bbec428eSgjelinek need_to_commit = B_TRUE; 3354c97ad5cdSakolb } 3355c97ad5cdSakolb 33560209230bSgjelinek static void 33570209230bSgjelinek remove_mcap() 33580209230bSgjelinek { 33590209230bSgjelinek int err, res1, res2, res3; 33600209230bSgjelinek uint64_t tmp; 33610209230bSgjelinek struct zone_mcaptab mcaptab; 33620209230bSgjelinek boolean_t revert = B_FALSE; 33630209230bSgjelinek 33640209230bSgjelinek res1 = zonecfg_lookup_mcap(handle, &mcaptab); 33650209230bSgjelinek res2 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, &tmp); 33660209230bSgjelinek res3 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, &tmp); 33670209230bSgjelinek 33680209230bSgjelinek /* if none of these exist, there is no resource to remove */ 33690209230bSgjelinek if (res1 != Z_OK && res2 != Z_OK && res3 != Z_OK) { 33700209230bSgjelinek zerr("%s %s: %s", cmd_to_str(CMD_REMOVE), rt_to_str(RT_MCAP), 33710209230bSgjelinek zonecfg_strerror(Z_NO_RESOURCE_TYPE)); 3372bbec428eSgjelinek saw_error = B_TRUE; 33730209230bSgjelinek return; 33740209230bSgjelinek } 33750209230bSgjelinek if (res1 == Z_OK) { 33760209230bSgjelinek if ((err = zonecfg_delete_mcap(handle)) != Z_OK) { 3377bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_MCAP, err, B_TRUE); 33780209230bSgjelinek revert = B_TRUE; 33790209230bSgjelinek } else { 3380bbec428eSgjelinek need_to_commit = B_TRUE; 33810209230bSgjelinek } 33820209230bSgjelinek } 33830209230bSgjelinek if (res2 == Z_OK) { 33840209230bSgjelinek if ((err = zonecfg_rm_aliased_rctl(handle, ALIAS_MAXSWAP)) 33850209230bSgjelinek != Z_OK) { 3386bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_MCAP, err, B_TRUE); 33870209230bSgjelinek revert = B_TRUE; 33880209230bSgjelinek } else { 3389bbec428eSgjelinek need_to_commit = B_TRUE; 33900209230bSgjelinek } 33910209230bSgjelinek } 33920209230bSgjelinek if (res3 == Z_OK) { 33930209230bSgjelinek if ((err = zonecfg_rm_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM)) 33940209230bSgjelinek != Z_OK) { 3395bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_MCAP, err, B_TRUE); 33960209230bSgjelinek revert = B_TRUE; 33970209230bSgjelinek } else { 3398bbec428eSgjelinek need_to_commit = B_TRUE; 33990209230bSgjelinek } 34000209230bSgjelinek } 34010209230bSgjelinek 34020209230bSgjelinek if (revert) 3403bbec428eSgjelinek need_to_commit = B_FALSE; 34040209230bSgjelinek } 34050209230bSgjelinek 3406cb8a054bSGlenn Faden static void 3407cb8a054bSGlenn Faden remove_admin(cmd_t *cmd) 3408cb8a054bSGlenn Faden { 3409cb8a054bSGlenn Faden int err; 3410cb8a054bSGlenn Faden 3411cb8a054bSGlenn Faden /* traditional, qualified attr removal */ 3412cb8a054bSGlenn Faden if (cmd->cmd_prop_nv_pairs > 0) { 3413cb8a054bSGlenn Faden struct zone_admintab admintab; 3414cb8a054bSGlenn Faden 3415cb8a054bSGlenn Faden if ((err = fill_in_admintab(cmd, &admintab, B_FALSE)) != Z_OK) { 3416cb8a054bSGlenn Faden z_cmd_rt_perror(CMD_REMOVE, RT_ADMIN, 3417cb8a054bSGlenn Faden err, B_TRUE); 3418cb8a054bSGlenn Faden return; 3419cb8a054bSGlenn Faden } 3420cb8a054bSGlenn Faden if ((err = zonecfg_delete_admin(handle, &admintab, 3421cb8a054bSGlenn Faden zone)) 3422cb8a054bSGlenn Faden != Z_OK) 3423cb8a054bSGlenn Faden z_cmd_rt_perror(CMD_REMOVE, RT_ADMIN, 3424cb8a054bSGlenn Faden err, B_TRUE); 3425cb8a054bSGlenn Faden else 3426cb8a054bSGlenn Faden need_to_commit = B_TRUE; 3427cb8a054bSGlenn Faden return; 3428cb8a054bSGlenn Faden } else { 3429cb8a054bSGlenn Faden /* 3430cb8a054bSGlenn Faden * unqualified admin removal. 3431cb8a054bSGlenn Faden * remove all admins but prompt if more 3432cb8a054bSGlenn Faden * than one. 3433cb8a054bSGlenn Faden */ 3434cb8a054bSGlenn Faden if (!prompt_remove_resource(cmd, "admin")) 3435cb8a054bSGlenn Faden return; 3436cb8a054bSGlenn Faden 3437cb8a054bSGlenn Faden if ((err = zonecfg_delete_admins(handle, zone)) 3438cb8a054bSGlenn Faden != Z_OK) 3439cb8a054bSGlenn Faden z_cmd_rt_perror(CMD_REMOVE, RT_ADMIN, 3440cb8a054bSGlenn Faden err, B_TRUE); 3441cb8a054bSGlenn Faden else 3442cb8a054bSGlenn Faden need_to_commit = B_TRUE; 3443cb8a054bSGlenn Faden } 3444cb8a054bSGlenn Faden } 3445cb8a054bSGlenn Faden 3446*d2a70789SRichard Lowe static void 3447*d2a70789SRichard Lowe remove_secflags() 3448*d2a70789SRichard Lowe { 3449*d2a70789SRichard Lowe int err; 3450*d2a70789SRichard Lowe struct zone_secflagstab sectab = { 0 }; 3451*d2a70789SRichard Lowe 3452*d2a70789SRichard Lowe if (zonecfg_lookup_secflags(handle, §ab) != Z_OK) { 3453*d2a70789SRichard Lowe zerr("%s %s: %s", cmd_to_str(CMD_REMOVE), 3454*d2a70789SRichard Lowe rt_to_str(RT_SECFLAGS), 3455*d2a70789SRichard Lowe zonecfg_strerror(Z_NO_RESOURCE_TYPE)); 3456*d2a70789SRichard Lowe return; 3457*d2a70789SRichard Lowe } 3458*d2a70789SRichard Lowe 3459*d2a70789SRichard Lowe if ((err = zonecfg_delete_secflags(handle, §ab)) != Z_OK) { 3460*d2a70789SRichard Lowe z_cmd_rt_perror(CMD_REMOVE, RT_SECFLAGS, err, B_TRUE); 3461*d2a70789SRichard Lowe return; 3462*d2a70789SRichard Lowe } 3463*d2a70789SRichard Lowe 3464*d2a70789SRichard Lowe need_to_commit = B_TRUE; 3465*d2a70789SRichard Lowe } 3466*d2a70789SRichard Lowe 34670209230bSgjelinek static void 34680209230bSgjelinek remove_resource(cmd_t *cmd) 34690209230bSgjelinek { 34700209230bSgjelinek int type; 34710209230bSgjelinek int arg; 3472bbec428eSgjelinek boolean_t arg_err = B_FALSE; 34730209230bSgjelinek 34740209230bSgjelinek if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 3475bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 34760209230bSgjelinek return; 34770209230bSgjelinek } 34780209230bSgjelinek 34790209230bSgjelinek optind = 0; 34800209230bSgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 34810209230bSgjelinek switch (arg) { 34820209230bSgjelinek case '?': 34830209230bSgjelinek longer_usage(CMD_REMOVE); 3484bbec428eSgjelinek arg_err = B_TRUE; 34857ec75eb8Sgjelinek break; 34860209230bSgjelinek case 'F': 34870209230bSgjelinek break; 34880209230bSgjelinek default: 34890209230bSgjelinek short_usage(CMD_REMOVE); 3490bbec428eSgjelinek arg_err = B_TRUE; 34917ec75eb8Sgjelinek break; 34920209230bSgjelinek } 34930209230bSgjelinek } 34947ec75eb8Sgjelinek if (arg_err) 34957ec75eb8Sgjelinek return; 34960209230bSgjelinek 3497bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 34980209230bSgjelinek return; 34990209230bSgjelinek 35000209230bSgjelinek switch (type) { 35010209230bSgjelinek case RT_FS: 35020209230bSgjelinek remove_fs(cmd); 35030209230bSgjelinek return; 35040209230bSgjelinek case RT_NET: 35050209230bSgjelinek remove_net(cmd); 35060209230bSgjelinek return; 35070209230bSgjelinek case RT_DEVICE: 35080209230bSgjelinek remove_device(cmd); 35090209230bSgjelinek return; 35100209230bSgjelinek case RT_RCTL: 35110209230bSgjelinek remove_rctl(cmd); 35120209230bSgjelinek return; 35130209230bSgjelinek case RT_ATTR: 35140209230bSgjelinek remove_attr(cmd); 35150209230bSgjelinek return; 35160209230bSgjelinek case RT_DATASET: 35170209230bSgjelinek remove_dataset(cmd); 35180209230bSgjelinek return; 35190209230bSgjelinek case RT_DCPU: 35200209230bSgjelinek remove_pset(); 35210209230bSgjelinek return; 3522c97ad5cdSakolb case RT_PCAP: 3523c97ad5cdSakolb remove_pcap(); 3524c97ad5cdSakolb return; 35250209230bSgjelinek case RT_MCAP: 35260209230bSgjelinek remove_mcap(); 35270209230bSgjelinek return; 3528cb8a054bSGlenn Faden case RT_ADMIN: 3529cb8a054bSGlenn Faden remove_admin(cmd); 3530cb8a054bSGlenn Faden return; 3531*d2a70789SRichard Lowe case RT_SECFLAGS: 3532*d2a70789SRichard Lowe remove_secflags(); 3533*d2a70789SRichard Lowe return; 35340209230bSgjelinek default: 3535bbec428eSgjelinek zone_perror(rt_to_str(type), Z_NO_RESOURCE_TYPE, B_TRUE); 3536bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 3537bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 35380209230bSgjelinek return; 35390209230bSgjelinek } 35400209230bSgjelinek } 35417c478bd9Sstevel@tonic-gate 35427c478bd9Sstevel@tonic-gate static void 35437c478bd9Sstevel@tonic-gate remove_property(cmd_t *cmd) 35447c478bd9Sstevel@tonic-gate { 35457c478bd9Sstevel@tonic-gate char *prop_id; 35467c478bd9Sstevel@tonic-gate int err, res_type, prop_type; 35477c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 35487c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *rctlvaltab; 35497c478bd9Sstevel@tonic-gate complex_property_ptr_t cx; 35507c478bd9Sstevel@tonic-gate 35517c478bd9Sstevel@tonic-gate res_type = resource_scope; 35527c478bd9Sstevel@tonic-gate prop_type = cmd->cmd_prop_name[0]; 35537c478bd9Sstevel@tonic-gate if (res_type == RT_UNKNOWN || prop_type == PT_UNKNOWN) { 3554bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 35557c478bd9Sstevel@tonic-gate return; 35567c478bd9Sstevel@tonic-gate } 35577c478bd9Sstevel@tonic-gate 35587c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs != 1) { 3559bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 35607c478bd9Sstevel@tonic-gate return; 35617c478bd9Sstevel@tonic-gate } 35627c478bd9Sstevel@tonic-gate 3563bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 35647c478bd9Sstevel@tonic-gate return; 35657c478bd9Sstevel@tonic-gate 35667c478bd9Sstevel@tonic-gate switch (res_type) { 35677c478bd9Sstevel@tonic-gate case RT_FS: 35687c478bd9Sstevel@tonic-gate if (prop_type != PT_OPTIONS) { 35697c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 3570bbec428eSgjelinek B_TRUE); 3571bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 3572bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 35737c478bd9Sstevel@tonic-gate return; 35747c478bd9Sstevel@tonic-gate } 35757c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 35767c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_COMPLEX) { 35777c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected here."), 35787c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_SIMPLE), 35797c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 3580bbec428eSgjelinek saw_error = B_TRUE; 35817c478bd9Sstevel@tonic-gate return; 35827c478bd9Sstevel@tonic-gate } 35837c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_SIMPLE) { 35847c478bd9Sstevel@tonic-gate if (pp->pv_simple == NULL) { 3585bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 35867c478bd9Sstevel@tonic-gate return; 35877c478bd9Sstevel@tonic-gate } 35887c478bd9Sstevel@tonic-gate prop_id = pp->pv_simple; 35897c478bd9Sstevel@tonic-gate err = zonecfg_remove_fs_option(&in_progress_fstab, 35907c478bd9Sstevel@tonic-gate prop_id); 35917c478bd9Sstevel@tonic-gate if (err != Z_OK) 3592bbec428eSgjelinek zone_perror(pt_to_str(prop_type), err, B_TRUE); 35937c478bd9Sstevel@tonic-gate } else { 35947c478bd9Sstevel@tonic-gate list_property_ptr_t list; 35957c478bd9Sstevel@tonic-gate 35967c478bd9Sstevel@tonic-gate for (list = pp->pv_list; list != NULL; 35977c478bd9Sstevel@tonic-gate list = list->lp_next) { 35987c478bd9Sstevel@tonic-gate prop_id = list->lp_simple; 35997c478bd9Sstevel@tonic-gate if (prop_id == NULL) 36007c478bd9Sstevel@tonic-gate break; 36017c478bd9Sstevel@tonic-gate err = zonecfg_remove_fs_option( 36027c478bd9Sstevel@tonic-gate &in_progress_fstab, prop_id); 36037c478bd9Sstevel@tonic-gate if (err != Z_OK) 36047c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), err, 3605bbec428eSgjelinek B_TRUE); 36067c478bd9Sstevel@tonic-gate } 36077c478bd9Sstevel@tonic-gate } 36087c478bd9Sstevel@tonic-gate return; 36097c478bd9Sstevel@tonic-gate case RT_RCTL: 36107c478bd9Sstevel@tonic-gate if (prop_type != PT_VALUE) { 36117c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 3612bbec428eSgjelinek B_TRUE); 3613bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 3614bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 36157c478bd9Sstevel@tonic-gate return; 36167c478bd9Sstevel@tonic-gate } 36177c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 36187c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_COMPLEX) { 36197c478bd9Sstevel@tonic-gate zerr(gettext("A %s value was expected here."), 36207c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_COMPLEX)); 3621bbec428eSgjelinek saw_error = B_TRUE; 36227c478bd9Sstevel@tonic-gate return; 36237c478bd9Sstevel@tonic-gate } 36247c478bd9Sstevel@tonic-gate if ((rctlvaltab = alloc_rctlvaltab()) == NULL) { 3625bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_TRUE); 36267c478bd9Sstevel@tonic-gate exit(Z_ERR); 36277c478bd9Sstevel@tonic-gate } 36287c478bd9Sstevel@tonic-gate for (cx = pp->pv_complex; cx != NULL; cx = cx->cp_next) { 36297c478bd9Sstevel@tonic-gate switch (cx->cp_type) { 36307c478bd9Sstevel@tonic-gate case PT_PRIV: 36317c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_priv, 36327c478bd9Sstevel@tonic-gate cx->cp_value, 36337c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_priv)); 36347c478bd9Sstevel@tonic-gate break; 36357c478bd9Sstevel@tonic-gate case PT_LIMIT: 36367c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_limit, 36377c478bd9Sstevel@tonic-gate cx->cp_value, 36387c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_limit)); 36397c478bd9Sstevel@tonic-gate break; 36407c478bd9Sstevel@tonic-gate case PT_ACTION: 36417c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_action, 36427c478bd9Sstevel@tonic-gate cx->cp_value, 36437c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_action)); 36447c478bd9Sstevel@tonic-gate break; 36457c478bd9Sstevel@tonic-gate default: 36467c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), 3647bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 3648bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 3649bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 36507c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 36517c478bd9Sstevel@tonic-gate return; 36527c478bd9Sstevel@tonic-gate } 36537c478bd9Sstevel@tonic-gate } 36547c478bd9Sstevel@tonic-gate rctlvaltab->zone_rctlval_next = NULL; 36557c478bd9Sstevel@tonic-gate err = zonecfg_remove_rctl_value(&in_progress_rctltab, 36567c478bd9Sstevel@tonic-gate rctlvaltab); 36577c478bd9Sstevel@tonic-gate if (err != Z_OK) 3658bbec428eSgjelinek zone_perror(pt_to_str(prop_type), err, B_TRUE); 36597c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 36607c478bd9Sstevel@tonic-gate return; 3661de860bd9Sgfaden case RT_NET: 3662de860bd9Sgfaden if (prop_type != PT_DEFROUTER) { 3663de860bd9Sgfaden zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 3664bbec428eSgjelinek B_TRUE); 3665bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 3666bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 3667de860bd9Sgfaden return; 3668de860bd9Sgfaden } else { 3669de860bd9Sgfaden bzero(&in_progress_nwiftab.zone_nwif_defrouter, 3670de860bd9Sgfaden sizeof (in_progress_nwiftab.zone_nwif_defrouter)); 3671de860bd9Sgfaden return; 3672de860bd9Sgfaden } 36737c478bd9Sstevel@tonic-gate default: 3674bbec428eSgjelinek zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, B_TRUE); 3675bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 3676bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 36777c478bd9Sstevel@tonic-gate return; 36787c478bd9Sstevel@tonic-gate } 36797c478bd9Sstevel@tonic-gate } 36807c478bd9Sstevel@tonic-gate 36817c478bd9Sstevel@tonic-gate void 36827c478bd9Sstevel@tonic-gate remove_func(cmd_t *cmd) 36837c478bd9Sstevel@tonic-gate { 36847c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_REMOVE)) 36857c478bd9Sstevel@tonic-gate return; 36867c478bd9Sstevel@tonic-gate 36877c478bd9Sstevel@tonic-gate assert(cmd != NULL); 36887c478bd9Sstevel@tonic-gate 36890209230bSgjelinek if (global_scope) { 36900209230bSgjelinek if (gz_invalid_resource(cmd->cmd_res_type)) { 36910209230bSgjelinek zerr(gettext("%s is not a valid resource for the " 36920209230bSgjelinek "global zone."), rt_to_str(cmd->cmd_res_type)); 3693bbec428eSgjelinek saw_error = B_TRUE; 36940209230bSgjelinek return; 36950209230bSgjelinek } 36967c478bd9Sstevel@tonic-gate remove_resource(cmd); 36970209230bSgjelinek } else { 36987c478bd9Sstevel@tonic-gate remove_property(cmd); 36990209230bSgjelinek } 37000209230bSgjelinek } 37010209230bSgjelinek 37020209230bSgjelinek static void 37030209230bSgjelinek clear_property(cmd_t *cmd) 37040209230bSgjelinek { 37050209230bSgjelinek int res_type, prop_type; 37060209230bSgjelinek 37070209230bSgjelinek res_type = resource_scope; 37080209230bSgjelinek prop_type = cmd->cmd_res_type; 37090209230bSgjelinek if (res_type == RT_UNKNOWN || prop_type == PT_UNKNOWN) { 3710bbec428eSgjelinek long_usage(CMD_CLEAR, B_TRUE); 37110209230bSgjelinek return; 37120209230bSgjelinek } 37130209230bSgjelinek 3714bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 37150209230bSgjelinek return; 37160209230bSgjelinek 37170209230bSgjelinek switch (res_type) { 37180209230bSgjelinek case RT_FS: 37190209230bSgjelinek if (prop_type == PT_RAW) { 37200209230bSgjelinek in_progress_fstab.zone_fs_raw[0] = '\0'; 3721bbec428eSgjelinek need_to_commit = B_TRUE; 37220209230bSgjelinek return; 37230209230bSgjelinek } 37240209230bSgjelinek break; 37250209230bSgjelinek case RT_DCPU: 37260209230bSgjelinek if (prop_type == PT_IMPORTANCE) { 37270209230bSgjelinek in_progress_psettab.zone_importance[0] = '\0'; 3728bbec428eSgjelinek need_to_commit = B_TRUE; 37290209230bSgjelinek return; 37300209230bSgjelinek } 37310209230bSgjelinek break; 37320209230bSgjelinek case RT_MCAP: 37330209230bSgjelinek switch (prop_type) { 37340209230bSgjelinek case PT_PHYSICAL: 37350209230bSgjelinek in_progress_mcaptab.zone_physmem_cap[0] = '\0'; 3736bbec428eSgjelinek need_to_commit = B_TRUE; 37370209230bSgjelinek return; 37380209230bSgjelinek case PT_SWAP: 37390209230bSgjelinek remove_aliased_rctl(PT_SWAP, ALIAS_MAXSWAP); 37400209230bSgjelinek return; 37410209230bSgjelinek case PT_LOCKED: 37420209230bSgjelinek remove_aliased_rctl(PT_LOCKED, ALIAS_MAXLOCKEDMEM); 37430209230bSgjelinek return; 37440209230bSgjelinek } 37450209230bSgjelinek break; 3746*d2a70789SRichard Lowe case RT_SECFLAGS: 3747*d2a70789SRichard Lowe switch (prop_type) { 3748*d2a70789SRichard Lowe case PT_LOWER: 3749*d2a70789SRichard Lowe in_progress_secflagstab.zone_secflags_lower[0] = '\0'; 3750*d2a70789SRichard Lowe need_to_commit = B_TRUE; 3751*d2a70789SRichard Lowe return; 3752*d2a70789SRichard Lowe case PT_DEFAULT: 3753*d2a70789SRichard Lowe in_progress_secflagstab.zone_secflags_default[0] = '\0'; 3754*d2a70789SRichard Lowe need_to_commit = B_TRUE; 3755*d2a70789SRichard Lowe return; 3756*d2a70789SRichard Lowe case PT_UPPER: 3757*d2a70789SRichard Lowe in_progress_secflagstab.zone_secflags_upper[0] = '\0'; 3758*d2a70789SRichard Lowe need_to_commit = B_TRUE; 3759*d2a70789SRichard Lowe return; 3760*d2a70789SRichard Lowe } 3761*d2a70789SRichard Lowe break; 37620209230bSgjelinek default: 37630209230bSgjelinek break; 37640209230bSgjelinek } 37650209230bSgjelinek 3766bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_CLEAR_DISALLOW, B_TRUE); 37670209230bSgjelinek } 37680209230bSgjelinek 37690209230bSgjelinek static void 37700209230bSgjelinek clear_global(cmd_t *cmd) 37710209230bSgjelinek { 37720209230bSgjelinek int err, type; 37730209230bSgjelinek 37740209230bSgjelinek if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 3775bbec428eSgjelinek long_usage(CMD_CLEAR, B_TRUE); 37760209230bSgjelinek return; 37770209230bSgjelinek } 37780209230bSgjelinek 3779bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 37800209230bSgjelinek return; 37810209230bSgjelinek 37820209230bSgjelinek switch (type) { 37830209230bSgjelinek case PT_ZONENAME: 37840209230bSgjelinek /* FALLTHRU */ 37850209230bSgjelinek case PT_ZONEPATH: 37860209230bSgjelinek /* FALLTHRU */ 37870209230bSgjelinek case PT_BRAND: 3788bbec428eSgjelinek zone_perror(pt_to_str(type), Z_CLEAR_DISALLOW, B_TRUE); 37890209230bSgjelinek return; 37900209230bSgjelinek case PT_AUTOBOOT: 37910209230bSgjelinek /* false is default; we'll treat as equivalent to clearing */ 37920209230bSgjelinek if ((err = zonecfg_set_autoboot(handle, B_FALSE)) != Z_OK) 3793bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_AUTOBOOT, err, B_TRUE); 37940209230bSgjelinek else 3795bbec428eSgjelinek need_to_commit = B_TRUE; 37960209230bSgjelinek return; 37970209230bSgjelinek case PT_POOL: 37980209230bSgjelinek if ((err = zonecfg_set_pool(handle, NULL)) != Z_OK) 3799bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_POOL, err, B_TRUE); 38000209230bSgjelinek else 3801bbec428eSgjelinek need_to_commit = B_TRUE; 38020209230bSgjelinek return; 38030209230bSgjelinek case PT_LIMITPRIV: 38040209230bSgjelinek if ((err = zonecfg_set_limitpriv(handle, NULL)) != Z_OK) 3805bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_LIMITPRIV, err, B_TRUE); 38060209230bSgjelinek else 3807bbec428eSgjelinek need_to_commit = B_TRUE; 38080209230bSgjelinek return; 38090209230bSgjelinek case PT_BOOTARGS: 38100209230bSgjelinek if ((err = zonecfg_set_bootargs(handle, NULL)) != Z_OK) 3811bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_BOOTARGS, err, B_TRUE); 38120209230bSgjelinek else 3813bbec428eSgjelinek need_to_commit = B_TRUE; 38140209230bSgjelinek return; 38150209230bSgjelinek case PT_SCHED: 38160209230bSgjelinek if ((err = zonecfg_set_sched(handle, NULL)) != Z_OK) 3817bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_SCHED, err, B_TRUE); 38180209230bSgjelinek else 3819bbec428eSgjelinek need_to_commit = B_TRUE; 38200209230bSgjelinek return; 3821f4b3ec61Sdh case PT_IPTYPE: 3822f4b3ec61Sdh /* shared is default; we'll treat as equivalent to clearing */ 3823f4b3ec61Sdh if ((err = zonecfg_set_iptype(handle, ZS_SHARED)) != Z_OK) 3824bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_IPTYPE, err, B_TRUE); 3825f4b3ec61Sdh else 3826bbec428eSgjelinek need_to_commit = B_TRUE; 3827f4b3ec61Sdh return; 38280209230bSgjelinek case PT_MAXLWPS: 38290209230bSgjelinek remove_aliased_rctl(PT_MAXLWPS, ALIAS_MAXLWPS); 38300209230bSgjelinek return; 3831ff19e029SMenno Lageman case PT_MAXPROCS: 3832ff19e029SMenno Lageman remove_aliased_rctl(PT_MAXPROCS, ALIAS_MAXPROCS); 3833ff19e029SMenno Lageman return; 38340209230bSgjelinek case PT_MAXSHMMEM: 38350209230bSgjelinek remove_aliased_rctl(PT_MAXSHMMEM, ALIAS_MAXSHMMEM); 38360209230bSgjelinek return; 38370209230bSgjelinek case PT_MAXSHMIDS: 38380209230bSgjelinek remove_aliased_rctl(PT_MAXSHMIDS, ALIAS_MAXSHMIDS); 38390209230bSgjelinek return; 38400209230bSgjelinek case PT_MAXMSGIDS: 38410209230bSgjelinek remove_aliased_rctl(PT_MAXMSGIDS, ALIAS_MAXMSGIDS); 38420209230bSgjelinek return; 38430209230bSgjelinek case PT_MAXSEMIDS: 38440209230bSgjelinek remove_aliased_rctl(PT_MAXSEMIDS, ALIAS_MAXSEMIDS); 38450209230bSgjelinek return; 38460209230bSgjelinek case PT_SHARES: 38470209230bSgjelinek remove_aliased_rctl(PT_SHARES, ALIAS_SHARES); 38480209230bSgjelinek return; 38495679c89fSjv case PT_HOSTID: 38505679c89fSjv if ((err = zonecfg_set_hostid(handle, NULL)) != Z_OK) 38515679c89fSjv z_cmd_rt_perror(CMD_CLEAR, RT_HOSTID, err, B_TRUE); 38525679c89fSjv else 38535679c89fSjv need_to_commit = B_TRUE; 38545679c89fSjv return; 38550fbb751dSJohn Levon case PT_FS_ALLOWED: 38560fbb751dSJohn Levon if ((err = zonecfg_set_fs_allowed(handle, NULL)) != Z_OK) 38570fbb751dSJohn Levon z_cmd_rt_perror(CMD_CLEAR, RT_FS_ALLOWED, err, B_TRUE); 38580fbb751dSJohn Levon else 38590fbb751dSJohn Levon need_to_commit = B_TRUE; 38600fbb751dSJohn Levon return; 38610209230bSgjelinek default: 3862bbec428eSgjelinek zone_perror(pt_to_str(type), Z_NO_PROPERTY_TYPE, B_TRUE); 3863bbec428eSgjelinek long_usage(CMD_CLEAR, B_TRUE); 3864bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 38650209230bSgjelinek return; 38660209230bSgjelinek } 38670209230bSgjelinek } 38680209230bSgjelinek 38690209230bSgjelinek void 38700209230bSgjelinek clear_func(cmd_t *cmd) 38710209230bSgjelinek { 38720209230bSgjelinek if (zone_is_read_only(CMD_CLEAR)) 38730209230bSgjelinek return; 38740209230bSgjelinek 38750209230bSgjelinek assert(cmd != NULL); 38760209230bSgjelinek 38770209230bSgjelinek if (global_scope) { 38780209230bSgjelinek if (gz_invalid_property(cmd->cmd_res_type)) { 38790209230bSgjelinek zerr(gettext("%s is not a valid property for the " 38800209230bSgjelinek "global zone."), pt_to_str(cmd->cmd_res_type)); 3881bbec428eSgjelinek saw_error = B_TRUE; 38820209230bSgjelinek return; 38830209230bSgjelinek } 38840209230bSgjelinek 38850209230bSgjelinek clear_global(cmd); 38860209230bSgjelinek } else { 38870209230bSgjelinek clear_property(cmd); 38880209230bSgjelinek } 38897c478bd9Sstevel@tonic-gate } 38907c478bd9Sstevel@tonic-gate 38917c478bd9Sstevel@tonic-gate void 38927c478bd9Sstevel@tonic-gate select_func(cmd_t *cmd) 38937c478bd9Sstevel@tonic-gate { 38940209230bSgjelinek int type, err, res; 38950209230bSgjelinek uint64_t limit; 3896c97ad5cdSakolb uint64_t tmp; 38977c478bd9Sstevel@tonic-gate 38987c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_SELECT)) 38997c478bd9Sstevel@tonic-gate return; 39007c478bd9Sstevel@tonic-gate 39017c478bd9Sstevel@tonic-gate assert(cmd != NULL); 39027c478bd9Sstevel@tonic-gate 39037c478bd9Sstevel@tonic-gate if (global_scope) { 3904bbec428eSgjelinek global_scope = B_FALSE; 39057c478bd9Sstevel@tonic-gate resource_scope = cmd->cmd_res_type; 39067c478bd9Sstevel@tonic-gate end_op = CMD_SELECT; 39077c478bd9Sstevel@tonic-gate } else { 39087c478bd9Sstevel@tonic-gate scope_usage(CMD_SELECT); 39097c478bd9Sstevel@tonic-gate return; 39107c478bd9Sstevel@tonic-gate } 39117c478bd9Sstevel@tonic-gate 39127c478bd9Sstevel@tonic-gate if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 3913bbec428eSgjelinek long_usage(CMD_SELECT, B_TRUE); 39147c478bd9Sstevel@tonic-gate return; 39157c478bd9Sstevel@tonic-gate } 39167c478bd9Sstevel@tonic-gate 3917bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 39187c478bd9Sstevel@tonic-gate return; 39197c478bd9Sstevel@tonic-gate 39207c478bd9Sstevel@tonic-gate switch (type) { 39217c478bd9Sstevel@tonic-gate case RT_FS: 3922bbec428eSgjelinek if ((err = fill_in_fstab(cmd, &old_fstab, B_FALSE)) != Z_OK) { 3923bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_FS, err, B_TRUE); 3924bbec428eSgjelinek global_scope = B_TRUE; 39257c478bd9Sstevel@tonic-gate } 39267c478bd9Sstevel@tonic-gate bcopy(&old_fstab, &in_progress_fstab, 39277c478bd9Sstevel@tonic-gate sizeof (struct zone_fstab)); 39287c478bd9Sstevel@tonic-gate return; 39297c478bd9Sstevel@tonic-gate case RT_NET: 3930bbec428eSgjelinek if ((err = fill_in_nwiftab(cmd, &old_nwiftab, B_FALSE)) 3931bbec428eSgjelinek != Z_OK) { 3932bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_NET, err, B_TRUE); 3933bbec428eSgjelinek global_scope = B_TRUE; 39347c478bd9Sstevel@tonic-gate } 39357c478bd9Sstevel@tonic-gate bcopy(&old_nwiftab, &in_progress_nwiftab, 39367c478bd9Sstevel@tonic-gate sizeof (struct zone_nwiftab)); 39377c478bd9Sstevel@tonic-gate return; 39387c478bd9Sstevel@tonic-gate case RT_DEVICE: 3939bbec428eSgjelinek if ((err = fill_in_devtab(cmd, &old_devtab, B_FALSE)) != Z_OK) { 3940bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_DEVICE, err, B_TRUE); 3941bbec428eSgjelinek global_scope = B_TRUE; 39427c478bd9Sstevel@tonic-gate } 39437c478bd9Sstevel@tonic-gate bcopy(&old_devtab, &in_progress_devtab, 39447c478bd9Sstevel@tonic-gate sizeof (struct zone_devtab)); 39457c478bd9Sstevel@tonic-gate return; 39467c478bd9Sstevel@tonic-gate case RT_RCTL: 3947bbec428eSgjelinek if ((err = fill_in_rctltab(cmd, &old_rctltab, B_FALSE)) 3948bbec428eSgjelinek != Z_OK) { 3949bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_RCTL, err, B_TRUE); 3950bbec428eSgjelinek global_scope = B_TRUE; 39517c478bd9Sstevel@tonic-gate } 39527c478bd9Sstevel@tonic-gate bcopy(&old_rctltab, &in_progress_rctltab, 39537c478bd9Sstevel@tonic-gate sizeof (struct zone_rctltab)); 39547c478bd9Sstevel@tonic-gate return; 39557c478bd9Sstevel@tonic-gate case RT_ATTR: 3956bbec428eSgjelinek if ((err = fill_in_attrtab(cmd, &old_attrtab, B_FALSE)) 3957bbec428eSgjelinek != Z_OK) { 3958bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_ATTR, err, B_TRUE); 3959bbec428eSgjelinek global_scope = B_TRUE; 39607c478bd9Sstevel@tonic-gate } 39617c478bd9Sstevel@tonic-gate bcopy(&old_attrtab, &in_progress_attrtab, 39627c478bd9Sstevel@tonic-gate sizeof (struct zone_attrtab)); 39637c478bd9Sstevel@tonic-gate return; 3964fa9e4066Sahrens case RT_DATASET: 3965bbec428eSgjelinek if ((err = fill_in_dstab(cmd, &old_dstab, B_FALSE)) != Z_OK) { 3966bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_DATASET, err, B_TRUE); 3967bbec428eSgjelinek global_scope = B_TRUE; 3968fa9e4066Sahrens } 3969fa9e4066Sahrens bcopy(&old_dstab, &in_progress_dstab, 3970fa9e4066Sahrens sizeof (struct zone_dstab)); 3971fa9e4066Sahrens return; 39720209230bSgjelinek case RT_DCPU: 39730209230bSgjelinek if ((err = zonecfg_lookup_pset(handle, &old_psettab)) != Z_OK) { 3974bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_DCPU, err, B_TRUE); 3975bbec428eSgjelinek global_scope = B_TRUE; 39760209230bSgjelinek } 39770209230bSgjelinek bcopy(&old_psettab, &in_progress_psettab, 39780209230bSgjelinek sizeof (struct zone_psettab)); 39790209230bSgjelinek return; 3980c97ad5cdSakolb case RT_PCAP: 3981c97ad5cdSakolb if ((err = zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &tmp)) 3982c97ad5cdSakolb != Z_OK) { 3983bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_PCAP, err, B_TRUE); 3984bbec428eSgjelinek global_scope = B_TRUE; 3985c97ad5cdSakolb } 3986c97ad5cdSakolb return; 39870209230bSgjelinek case RT_MCAP: 39880209230bSgjelinek /* if none of these exist, there is no resource to select */ 39890209230bSgjelinek if ((res = zonecfg_lookup_mcap(handle, &old_mcaptab)) != Z_OK && 39900209230bSgjelinek zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, &limit) 39910209230bSgjelinek != Z_OK && 39920209230bSgjelinek zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, &limit) 39930209230bSgjelinek != Z_OK) { 39940209230bSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_MCAP, Z_NO_RESOURCE_TYPE, 3995bbec428eSgjelinek B_TRUE); 3996bbec428eSgjelinek global_scope = B_TRUE; 39970209230bSgjelinek } 39980209230bSgjelinek if (res == Z_OK) 39990209230bSgjelinek bcopy(&old_mcaptab, &in_progress_mcaptab, 40000209230bSgjelinek sizeof (struct zone_mcaptab)); 40010209230bSgjelinek else 40020209230bSgjelinek bzero(&in_progress_mcaptab, 40030209230bSgjelinek sizeof (in_progress_mcaptab)); 40040209230bSgjelinek return; 4005cb8a054bSGlenn Faden case RT_ADMIN: 4006cb8a054bSGlenn Faden if ((err = fill_in_admintab(cmd, &old_admintab, B_FALSE)) 4007cb8a054bSGlenn Faden != Z_OK) { 4008cb8a054bSGlenn Faden z_cmd_rt_perror(CMD_SELECT, RT_ADMIN, err, 4009cb8a054bSGlenn Faden B_TRUE); 4010cb8a054bSGlenn Faden global_scope = B_TRUE; 4011cb8a054bSGlenn Faden } 4012cb8a054bSGlenn Faden bcopy(&old_admintab, &in_progress_admintab, 4013cb8a054bSGlenn Faden sizeof (struct zone_admintab)); 4014cb8a054bSGlenn Faden return; 4015*d2a70789SRichard Lowe case RT_SECFLAGS: 4016*d2a70789SRichard Lowe if ((err = fill_in_secflagstab(cmd, &old_secflagstab, B_FALSE)) 4017*d2a70789SRichard Lowe != Z_OK) { 4018*d2a70789SRichard Lowe z_cmd_rt_perror(CMD_SELECT, RT_SECFLAGS, err, 4019*d2a70789SRichard Lowe B_TRUE); 4020*d2a70789SRichard Lowe global_scope = B_TRUE; 4021*d2a70789SRichard Lowe } 4022*d2a70789SRichard Lowe bcopy(&old_secflagstab, &in_progress_secflagstab, 4023*d2a70789SRichard Lowe sizeof (struct zone_secflagstab)); 4024*d2a70789SRichard Lowe return; 40257c478bd9Sstevel@tonic-gate default: 4026bbec428eSgjelinek zone_perror(rt_to_str(type), Z_NO_RESOURCE_TYPE, B_TRUE); 4027bbec428eSgjelinek long_usage(CMD_SELECT, B_TRUE); 4028bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 40297c478bd9Sstevel@tonic-gate return; 40307c478bd9Sstevel@tonic-gate } 40317c478bd9Sstevel@tonic-gate } 40327c478bd9Sstevel@tonic-gate 40337c478bd9Sstevel@tonic-gate /* 40347c478bd9Sstevel@tonic-gate * Network "addresses" can be one of the following forms: 40357c478bd9Sstevel@tonic-gate * <IPv4 address> 40367c478bd9Sstevel@tonic-gate * <IPv4 address>/<prefix length> 40377c478bd9Sstevel@tonic-gate * <IPv6 address>/<prefix length> 40387c478bd9Sstevel@tonic-gate * <host name> 40397c478bd9Sstevel@tonic-gate * <host name>/<prefix length> 40407c478bd9Sstevel@tonic-gate * In other words, the "/" followed by a prefix length is allowed but not 40417c478bd9Sstevel@tonic-gate * required for IPv4 addresses and host names, and required for IPv6 addresses. 40427c478bd9Sstevel@tonic-gate * If a prefix length is given, it must be in the allowable range: 0 to 32 for 40437c478bd9Sstevel@tonic-gate * IPv4 addresses and host names, 0 to 128 for IPv6 addresses. 40447c478bd9Sstevel@tonic-gate * Host names must start with an alpha-numeric character, and all subsequent 40457c478bd9Sstevel@tonic-gate * characters must be either alpha-numeric or "-". 4046550b6e40SSowmini Varadhan * 4047550b6e40SSowmini Varadhan * In some cases, e.g., the nexthop for the defrouter, the context indicates 4048550b6e40SSowmini Varadhan * that this is the IPV4_ABITS or IPV6_ABITS netmask, in which case we don't 4049550b6e40SSowmini Varadhan * require the /<prefix length> (and should ignore it if provided). 40507c478bd9Sstevel@tonic-gate */ 40517c478bd9Sstevel@tonic-gate 40527c478bd9Sstevel@tonic-gate static int 4053550b6e40SSowmini Varadhan validate_net_address_syntax(char *address, boolean_t ishost) 40547c478bd9Sstevel@tonic-gate { 40557c478bd9Sstevel@tonic-gate char *slashp, part1[MAXHOSTNAMELEN]; 40567c478bd9Sstevel@tonic-gate struct in6_addr in6; 40577c478bd9Sstevel@tonic-gate struct in_addr in4; 40587c478bd9Sstevel@tonic-gate int prefixlen, i; 40597c478bd9Sstevel@tonic-gate 40607c478bd9Sstevel@tonic-gate /* 40617c478bd9Sstevel@tonic-gate * Copy the part before any '/' into part1 or copy the whole 40627c478bd9Sstevel@tonic-gate * thing if there is no '/'. 40637c478bd9Sstevel@tonic-gate */ 40647c478bd9Sstevel@tonic-gate if ((slashp = strchr(address, '/')) != NULL) { 40657c478bd9Sstevel@tonic-gate *slashp = '\0'; 40667c478bd9Sstevel@tonic-gate (void) strlcpy(part1, address, sizeof (part1)); 40677c478bd9Sstevel@tonic-gate *slashp = '/'; 40687c478bd9Sstevel@tonic-gate prefixlen = atoi(++slashp); 40697c478bd9Sstevel@tonic-gate } else { 40707c478bd9Sstevel@tonic-gate (void) strlcpy(part1, address, sizeof (part1)); 40717c478bd9Sstevel@tonic-gate } 40727c478bd9Sstevel@tonic-gate 4073550b6e40SSowmini Varadhan if (ishost && slashp != NULL) { 4074550b6e40SSowmini Varadhan zerr(gettext("Warning: prefix length in %s is not required and " 4075550b6e40SSowmini Varadhan "will be ignored. The default host-prefix length " 4076550b6e40SSowmini Varadhan "will be used"), address); 4077550b6e40SSowmini Varadhan } 4078550b6e40SSowmini Varadhan 4079550b6e40SSowmini Varadhan 40807c478bd9Sstevel@tonic-gate if (inet_pton(AF_INET6, part1, &in6) == 1) { 4081550b6e40SSowmini Varadhan if (ishost) { 4082550b6e40SSowmini Varadhan prefixlen = IPV6_ABITS; 4083550b6e40SSowmini Varadhan } else if (slashp == NULL) { 40847c478bd9Sstevel@tonic-gate zerr(gettext("%s: IPv6 addresses " 40857c478bd9Sstevel@tonic-gate "require /prefix-length suffix."), address); 40867c478bd9Sstevel@tonic-gate return (Z_ERR); 40877c478bd9Sstevel@tonic-gate } 40887c478bd9Sstevel@tonic-gate if (prefixlen < 0 || prefixlen > 128) { 40897c478bd9Sstevel@tonic-gate zerr(gettext("%s: IPv6 address " 40907c478bd9Sstevel@tonic-gate "prefix lengths must be 0 - 128."), address); 40917c478bd9Sstevel@tonic-gate return (Z_ERR); 40927c478bd9Sstevel@tonic-gate } 40937c478bd9Sstevel@tonic-gate return (Z_OK); 40947c478bd9Sstevel@tonic-gate } 40957c478bd9Sstevel@tonic-gate 40967c478bd9Sstevel@tonic-gate /* At this point, any /prefix must be for IPv4. */ 4097550b6e40SSowmini Varadhan if (ishost) 4098550b6e40SSowmini Varadhan prefixlen = IPV4_ABITS; 4099550b6e40SSowmini Varadhan else if (slashp != NULL) { 41007c478bd9Sstevel@tonic-gate if (prefixlen < 0 || prefixlen > 32) { 41017c478bd9Sstevel@tonic-gate zerr(gettext("%s: IPv4 address " 41027c478bd9Sstevel@tonic-gate "prefix lengths must be 0 - 32."), address); 41037c478bd9Sstevel@tonic-gate return (Z_ERR); 41047c478bd9Sstevel@tonic-gate } 41057c478bd9Sstevel@tonic-gate } 4106550b6e40SSowmini Varadhan 41077c478bd9Sstevel@tonic-gate if (inet_pton(AF_INET, part1, &in4) == 1) 41087c478bd9Sstevel@tonic-gate return (Z_OK); 41097c478bd9Sstevel@tonic-gate 41107c478bd9Sstevel@tonic-gate /* address may also be a host name */ 41117c478bd9Sstevel@tonic-gate if (!isalnum(part1[0])) { 41127c478bd9Sstevel@tonic-gate zerr(gettext("%s: bogus host name or network address syntax"), 41137c478bd9Sstevel@tonic-gate part1); 4114bbec428eSgjelinek saw_error = B_TRUE; 4115bbec428eSgjelinek usage(B_FALSE, HELP_NETADDR); 41167c478bd9Sstevel@tonic-gate return (Z_ERR); 41177c478bd9Sstevel@tonic-gate } 41187c478bd9Sstevel@tonic-gate for (i = 1; part1[i]; i++) 41197c478bd9Sstevel@tonic-gate if (!isalnum(part1[i]) && part1[i] != '-' && part1[i] != '.') { 41207c478bd9Sstevel@tonic-gate zerr(gettext("%s: bogus host name or " 41217c478bd9Sstevel@tonic-gate "network address syntax"), part1); 4122bbec428eSgjelinek saw_error = B_TRUE; 4123bbec428eSgjelinek usage(B_FALSE, HELP_NETADDR); 41247c478bd9Sstevel@tonic-gate return (Z_ERR); 41257c478bd9Sstevel@tonic-gate } 41267c478bd9Sstevel@tonic-gate return (Z_OK); 41277c478bd9Sstevel@tonic-gate } 41287c478bd9Sstevel@tonic-gate 41297c478bd9Sstevel@tonic-gate static int 4130c9f134eaSjv validate_net_physical_syntax(const char *ifname) 41317c478bd9Sstevel@tonic-gate { 4132c9f134eaSjv ifspec_t ifnameprop; 4133c9f134eaSjv zone_iptype_t iptype; 4134c9f134eaSjv 413537b210dcSjv if (zonecfg_get_iptype(handle, &iptype) != Z_OK) { 4136c9f134eaSjv zerr(gettext("zone configuration has an invalid or nonexistent " 4137c9f134eaSjv "ip-type property")); 4138c9f134eaSjv return (Z_ERR); 4139c9f134eaSjv } 4140c9f134eaSjv switch (iptype) { 4141c9f134eaSjv case ZS_SHARED: 4142c9f134eaSjv if (ifparse_ifspec(ifname, &ifnameprop) == B_FALSE) { 4143c9f134eaSjv zerr(gettext("%s: invalid physical interface name"), 4144c9f134eaSjv ifname); 4145c9f134eaSjv return (Z_ERR); 4146c9f134eaSjv } 4147c9f134eaSjv if (ifnameprop.ifsp_lunvalid) { 4148c9f134eaSjv zerr(gettext("%s: LUNs not allowed in physical " 4149c9f134eaSjv "interface names"), ifname); 4150c9f134eaSjv return (Z_ERR); 4151c9f134eaSjv } 4152c9f134eaSjv break; 4153c9f134eaSjv case ZS_EXCLUSIVE: 4154c9f134eaSjv if (dladm_valid_linkname(ifname) == B_FALSE) { 4155c9f134eaSjv if (strchr(ifname, ':') != NULL) 4156c9f134eaSjv zerr(gettext("%s: physical interface name " 4157c9f134eaSjv "required; logical interface name not " 4158c9f134eaSjv "allowed"), ifname); 4159c9f134eaSjv else 4160c9f134eaSjv zerr(gettext("%s: invalid physical interface " 4161c9f134eaSjv "name"), ifname); 4162c9f134eaSjv return (Z_ERR); 4163c9f134eaSjv } 4164c9f134eaSjv break; 4165c9f134eaSjv } 4166c9f134eaSjv return (Z_OK); 41677c478bd9Sstevel@tonic-gate } 41687c478bd9Sstevel@tonic-gate 41697c478bd9Sstevel@tonic-gate static boolean_t 41707c478bd9Sstevel@tonic-gate valid_fs_type(const char *type) 41717c478bd9Sstevel@tonic-gate { 41727c478bd9Sstevel@tonic-gate /* 41737c478bd9Sstevel@tonic-gate * Is this a valid path component? 41747c478bd9Sstevel@tonic-gate */ 41757c478bd9Sstevel@tonic-gate if (strlen(type) + 1 > MAXNAMELEN) 41767c478bd9Sstevel@tonic-gate return (B_FALSE); 41777c478bd9Sstevel@tonic-gate /* 41787c478bd9Sstevel@tonic-gate * Make sure a bad value for "type" doesn't make 41797c478bd9Sstevel@tonic-gate * /usr/lib/fs/<type>/mount turn into something else. 41807c478bd9Sstevel@tonic-gate */ 41817c478bd9Sstevel@tonic-gate if (strchr(type, '/') != NULL || type[0] == '\0' || 41827c478bd9Sstevel@tonic-gate strcmp(type, ".") == 0 || strcmp(type, "..") == 0) 4183087719fdSdp return (B_FALSE); 41847c478bd9Sstevel@tonic-gate /* 41857c478bd9Sstevel@tonic-gate * More detailed verification happens later by zoneadm(1m). 41867c478bd9Sstevel@tonic-gate */ 41877c478bd9Sstevel@tonic-gate return (B_TRUE); 41887c478bd9Sstevel@tonic-gate } 41897c478bd9Sstevel@tonic-gate 4190f4b3ec61Sdh static boolean_t 4191f4b3ec61Sdh allow_exclusive() 4192f4b3ec61Sdh { 4193f4b3ec61Sdh brand_handle_t bh; 4194f4b3ec61Sdh char brand[MAXNAMELEN]; 4195f4b3ec61Sdh boolean_t ret; 4196f4b3ec61Sdh 4197f4b3ec61Sdh if (zonecfg_get_brand(handle, brand, sizeof (brand)) != Z_OK) { 4198f4b3ec61Sdh zerr("%s: %s\n", zone, gettext("could not get zone brand")); 4199f4b3ec61Sdh return (B_FALSE); 4200f4b3ec61Sdh } 4201f4b3ec61Sdh if ((bh = brand_open(brand)) == NULL) { 4202f4b3ec61Sdh zerr("%s: %s\n", zone, gettext("unknown brand.")); 4203f4b3ec61Sdh return (B_FALSE); 4204f4b3ec61Sdh } 4205f4b3ec61Sdh ret = brand_allow_exclusive_ip(bh); 4206f4b3ec61Sdh brand_close(bh); 4207f4b3ec61Sdh if (!ret) 4208f4b3ec61Sdh zerr(gettext("%s cannot be '%s' when %s is '%s'."), 4209f4b3ec61Sdh pt_to_str(PT_IPTYPE), "exclusive", 4210f4b3ec61Sdh pt_to_str(PT_BRAND), brand); 4211f4b3ec61Sdh return (ret); 4212f4b3ec61Sdh } 4213f4b3ec61Sdh 42140209230bSgjelinek static void 42150209230bSgjelinek set_aliased_rctl(char *alias, int prop_type, char *s) 42160209230bSgjelinek { 42170209230bSgjelinek uint64_t limit; 42180209230bSgjelinek int err; 42190209230bSgjelinek char tmp[128]; 42200209230bSgjelinek 42210209230bSgjelinek if (global_zone && strcmp(alias, ALIAS_SHARES) != 0) 42220209230bSgjelinek zerr(gettext("WARNING: Setting a global zone resource " 42230209230bSgjelinek "control too low could deny\nservice " 42240209230bSgjelinek "to even the root user; " 42250209230bSgjelinek "this could render the system impossible\n" 42260209230bSgjelinek "to administer. Please use caution.")); 42270209230bSgjelinek 42280209230bSgjelinek /* convert memory based properties */ 42290209230bSgjelinek if (prop_type == PT_MAXSHMMEM) { 42300209230bSgjelinek if (!zonecfg_valid_memlimit(s, &limit)) { 42310209230bSgjelinek zerr(gettext("A non-negative number with a required " 42320209230bSgjelinek "scale suffix (K, M, G or T) was expected\nhere.")); 4233bbec428eSgjelinek saw_error = B_TRUE; 42340209230bSgjelinek return; 42350209230bSgjelinek } 42360209230bSgjelinek 42370209230bSgjelinek (void) snprintf(tmp, sizeof (tmp), "%llu", limit); 42380209230bSgjelinek s = tmp; 42390209230bSgjelinek } 42400209230bSgjelinek 42410209230bSgjelinek if (!zonecfg_aliased_rctl_ok(handle, alias)) { 4242bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_ALIAS_DISALLOW, B_FALSE); 4243bbec428eSgjelinek saw_error = B_TRUE; 42440209230bSgjelinek } else if (!zonecfg_valid_alias_limit(alias, s, &limit)) { 42450209230bSgjelinek zerr(gettext("%s property is out of range."), 42460209230bSgjelinek pt_to_str(prop_type)); 4247bbec428eSgjelinek saw_error = B_TRUE; 42480209230bSgjelinek } else if ((err = zonecfg_set_aliased_rctl(handle, alias, limit)) 42490209230bSgjelinek != Z_OK) { 4250bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 4251bbec428eSgjelinek saw_error = B_TRUE; 42520209230bSgjelinek } else { 4253bbec428eSgjelinek need_to_commit = B_TRUE; 42540209230bSgjelinek } 42550209230bSgjelinek } 42560209230bSgjelinek 4257550b6e40SSowmini Varadhan static void 4258550b6e40SSowmini Varadhan set_in_progress_nwiftab_address(char *prop_id, int prop_type) 4259550b6e40SSowmini Varadhan { 4260550b6e40SSowmini Varadhan if (prop_type == PT_ADDRESS) { 4261550b6e40SSowmini Varadhan (void) strlcpy(in_progress_nwiftab.zone_nwif_address, prop_id, 4262550b6e40SSowmini Varadhan sizeof (in_progress_nwiftab.zone_nwif_address)); 4263550b6e40SSowmini Varadhan } else { 4264550b6e40SSowmini Varadhan assert(prop_type == PT_ALLOWED_ADDRESS); 4265550b6e40SSowmini Varadhan (void) strlcpy(in_progress_nwiftab.zone_nwif_allowed_address, 4266550b6e40SSowmini Varadhan prop_id, 4267550b6e40SSowmini Varadhan sizeof (in_progress_nwiftab.zone_nwif_allowed_address)); 4268550b6e40SSowmini Varadhan } 4269550b6e40SSowmini Varadhan } 4270550b6e40SSowmini Varadhan 42717c478bd9Sstevel@tonic-gate void 42727c478bd9Sstevel@tonic-gate set_func(cmd_t *cmd) 42737c478bd9Sstevel@tonic-gate { 42747c478bd9Sstevel@tonic-gate char *prop_id; 4275555afedfScarlsonj int arg, err, res_type, prop_type; 42767c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 42777c478bd9Sstevel@tonic-gate boolean_t autoboot; 4278f4b3ec61Sdh zone_iptype_t iptype; 4279bbec428eSgjelinek boolean_t force_set = B_FALSE; 42800209230bSgjelinek size_t physmem_size = sizeof (in_progress_mcaptab.zone_physmem_cap); 42810209230bSgjelinek uint64_t mem_cap, mem_limit; 4282c97ad5cdSakolb float cap; 4283c97ad5cdSakolb char *unitp; 42840209230bSgjelinek struct zone_psettab tmp_psettab; 4285bbec428eSgjelinek boolean_t arg_err = B_FALSE; 42867c478bd9Sstevel@tonic-gate 42877c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_SET)) 42887c478bd9Sstevel@tonic-gate return; 42897c478bd9Sstevel@tonic-gate 42907c478bd9Sstevel@tonic-gate assert(cmd != NULL); 42917c478bd9Sstevel@tonic-gate 4292555afedfScarlsonj optind = opterr = 0; 4293555afedfScarlsonj while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "F")) != EOF) { 4294555afedfScarlsonj switch (arg) { 4295555afedfScarlsonj case 'F': 4296bbec428eSgjelinek force_set = B_TRUE; 4297555afedfScarlsonj break; 4298555afedfScarlsonj default: 4299555afedfScarlsonj if (optopt == '?') 4300555afedfScarlsonj longer_usage(CMD_SET); 4301555afedfScarlsonj else 4302555afedfScarlsonj short_usage(CMD_SET); 4303bbec428eSgjelinek arg_err = B_TRUE; 43047ec75eb8Sgjelinek break; 4305555afedfScarlsonj } 4306555afedfScarlsonj } 43077ec75eb8Sgjelinek if (arg_err) 43087ec75eb8Sgjelinek return; 4309555afedfScarlsonj 43107c478bd9Sstevel@tonic-gate prop_type = cmd->cmd_prop_name[0]; 43117c478bd9Sstevel@tonic-gate if (global_scope) { 43120209230bSgjelinek if (gz_invalid_property(prop_type)) { 43130209230bSgjelinek zerr(gettext("%s is not a valid property for the " 43140209230bSgjelinek "global zone."), pt_to_str(prop_type)); 4315bbec428eSgjelinek saw_error = B_TRUE; 43160209230bSgjelinek return; 43170209230bSgjelinek } 43180209230bSgjelinek 4319087719fdSdp if (prop_type == PT_ZONENAME) { 4320087719fdSdp res_type = RT_ZONENAME; 4321087719fdSdp } else if (prop_type == PT_ZONEPATH) { 43227c478bd9Sstevel@tonic-gate res_type = RT_ZONEPATH; 43237c478bd9Sstevel@tonic-gate } else if (prop_type == PT_AUTOBOOT) { 43247c478bd9Sstevel@tonic-gate res_type = RT_AUTOBOOT; 43259acbbeafSnn } else if (prop_type == PT_BRAND) { 43269acbbeafSnn res_type = RT_BRAND; 43277c478bd9Sstevel@tonic-gate } else if (prop_type == PT_POOL) { 43287c478bd9Sstevel@tonic-gate res_type = RT_POOL; 4329ffbafc53Scomay } else if (prop_type == PT_LIMITPRIV) { 4330ffbafc53Scomay res_type = RT_LIMITPRIV; 43313f2f09c1Sdp } else if (prop_type == PT_BOOTARGS) { 43323f2f09c1Sdp res_type = RT_BOOTARGS; 43330209230bSgjelinek } else if (prop_type == PT_SCHED) { 43340209230bSgjelinek res_type = RT_SCHED; 4335f4b3ec61Sdh } else if (prop_type == PT_IPTYPE) { 4336f4b3ec61Sdh res_type = RT_IPTYPE; 43370209230bSgjelinek } else if (prop_type == PT_MAXLWPS) { 43380209230bSgjelinek res_type = RT_MAXLWPS; 4339ff19e029SMenno Lageman } else if (prop_type == PT_MAXPROCS) { 4340ff19e029SMenno Lageman res_type = RT_MAXPROCS; 43410209230bSgjelinek } else if (prop_type == PT_MAXSHMMEM) { 43420209230bSgjelinek res_type = RT_MAXSHMMEM; 43430209230bSgjelinek } else if (prop_type == PT_MAXSHMIDS) { 43440209230bSgjelinek res_type = RT_MAXSHMIDS; 43450209230bSgjelinek } else if (prop_type == PT_MAXMSGIDS) { 43460209230bSgjelinek res_type = RT_MAXMSGIDS; 43470209230bSgjelinek } else if (prop_type == PT_MAXSEMIDS) { 43480209230bSgjelinek res_type = RT_MAXSEMIDS; 43490209230bSgjelinek } else if (prop_type == PT_SHARES) { 43500209230bSgjelinek res_type = RT_SHARES; 43515679c89fSjv } else if (prop_type == PT_HOSTID) { 43525679c89fSjv res_type = RT_HOSTID; 43530fbb751dSJohn Levon } else if (prop_type == PT_FS_ALLOWED) { 43540fbb751dSJohn Levon res_type = RT_FS_ALLOWED; 43557c478bd9Sstevel@tonic-gate } else { 43567c478bd9Sstevel@tonic-gate zerr(gettext("Cannot set a resource-specific property " 43577c478bd9Sstevel@tonic-gate "from the global scope.")); 4358bbec428eSgjelinek saw_error = B_TRUE; 43597c478bd9Sstevel@tonic-gate return; 43607c478bd9Sstevel@tonic-gate } 43617c478bd9Sstevel@tonic-gate } else { 43627c478bd9Sstevel@tonic-gate res_type = resource_scope; 43637c478bd9Sstevel@tonic-gate } 43647c478bd9Sstevel@tonic-gate 4365555afedfScarlsonj if (force_set) { 4366555afedfScarlsonj if (res_type != RT_ZONEPATH) { 4367555afedfScarlsonj zerr(gettext("Only zonepath setting can be forced.")); 4368bbec428eSgjelinek saw_error = B_TRUE; 4369555afedfScarlsonj return; 4370555afedfScarlsonj } 4371555afedfScarlsonj if (!zonecfg_in_alt_root()) { 4372555afedfScarlsonj zerr(gettext("Zonepath is changeable only in an " 4373555afedfScarlsonj "alternate root.")); 4374bbec428eSgjelinek saw_error = B_TRUE; 4375555afedfScarlsonj return; 4376555afedfScarlsonj } 4377555afedfScarlsonj } 4378555afedfScarlsonj 43797c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 43807c478bd9Sstevel@tonic-gate /* 43817c478bd9Sstevel@tonic-gate * A nasty expression but not that complicated: 43827c478bd9Sstevel@tonic-gate * 1. fs options are simple or list (tested below) 43837c478bd9Sstevel@tonic-gate * 2. rctl value's are complex or list (tested below) 43847c478bd9Sstevel@tonic-gate * Anything else should be simple. 43857c478bd9Sstevel@tonic-gate */ 43867c478bd9Sstevel@tonic-gate if (!(res_type == RT_FS && prop_type == PT_OPTIONS) && 43877c478bd9Sstevel@tonic-gate !(res_type == RT_RCTL && prop_type == PT_VALUE) && 43887c478bd9Sstevel@tonic-gate (pp->pv_type != PROP_VAL_SIMPLE || 43897c478bd9Sstevel@tonic-gate (prop_id = pp->pv_simple) == NULL)) { 43907c478bd9Sstevel@tonic-gate zerr(gettext("A %s value was expected here."), 43917c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_SIMPLE)); 4392bbec428eSgjelinek saw_error = B_TRUE; 43937c478bd9Sstevel@tonic-gate return; 43947c478bd9Sstevel@tonic-gate } 43957c478bd9Sstevel@tonic-gate if (prop_type == PT_UNKNOWN) { 4396bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 43977c478bd9Sstevel@tonic-gate return; 43987c478bd9Sstevel@tonic-gate } 43997c478bd9Sstevel@tonic-gate 4400087719fdSdp /* 4401087719fdSdp * Special case: the user can change the zone name prior to 'create'; 4402087719fdSdp * if the zone already exists, we fall through letting initialize() 4403087719fdSdp * and the rest of the logic run. 4404087719fdSdp */ 4405bbec428eSgjelinek if (res_type == RT_ZONENAME && got_handle == B_FALSE && 4406087719fdSdp !state_atleast(ZONE_STATE_CONFIGURED)) { 4407fb03efaaSdp if ((err = zonecfg_validate_zonename(prop_id)) != Z_OK) { 4408bbec428eSgjelinek zone_perror(prop_id, err, B_TRUE); 4409bbec428eSgjelinek usage(B_FALSE, HELP_SYNTAX); 4410fb03efaaSdp return; 4411fb03efaaSdp } 4412087719fdSdp (void) strlcpy(zone, prop_id, sizeof (zone)); 4413087719fdSdp return; 4414087719fdSdp } 4415087719fdSdp 4416bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 44177c478bd9Sstevel@tonic-gate return; 44187c478bd9Sstevel@tonic-gate 44197c478bd9Sstevel@tonic-gate switch (res_type) { 4420087719fdSdp case RT_ZONENAME: 4421087719fdSdp if ((err = zonecfg_set_name(handle, prop_id)) != Z_OK) { 4422087719fdSdp /* 4423087719fdSdp * Use prop_id instead of 'zone' here, since we're 4424087719fdSdp * reporting a problem about the *new* zonename. 4425087719fdSdp */ 4426bbec428eSgjelinek zone_perror(prop_id, err, B_TRUE); 4427bbec428eSgjelinek usage(B_FALSE, HELP_SYNTAX); 4428087719fdSdp } else { 4429bbec428eSgjelinek need_to_commit = B_TRUE; 4430087719fdSdp (void) strlcpy(zone, prop_id, sizeof (zone)); 4431087719fdSdp } 4432087719fdSdp return; 44337c478bd9Sstevel@tonic-gate case RT_ZONEPATH: 4434555afedfScarlsonj if (!force_set && state_atleast(ZONE_STATE_INSTALLED)) { 44357c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s already installed; %s %s not " 44367c478bd9Sstevel@tonic-gate "allowed."), zone, cmd_to_str(CMD_SET), 44377c478bd9Sstevel@tonic-gate rt_to_str(RT_ZONEPATH)); 44387c478bd9Sstevel@tonic-gate return; 44397c478bd9Sstevel@tonic-gate } 44407c478bd9Sstevel@tonic-gate if (validate_zonepath_syntax(prop_id) != Z_OK) { 4441bbec428eSgjelinek saw_error = B_TRUE; 44427c478bd9Sstevel@tonic-gate return; 44437c478bd9Sstevel@tonic-gate } 44447c478bd9Sstevel@tonic-gate if ((err = zonecfg_set_zonepath(handle, prop_id)) != Z_OK) 4445bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 44467c478bd9Sstevel@tonic-gate else 4447bbec428eSgjelinek need_to_commit = B_TRUE; 44487c478bd9Sstevel@tonic-gate return; 44499acbbeafSnn case RT_BRAND: 44509acbbeafSnn if (state_atleast(ZONE_STATE_INSTALLED)) { 44519acbbeafSnn zerr(gettext("Zone %s already installed; %s %s not " 44529acbbeafSnn "allowed."), zone, cmd_to_str(CMD_SET), 44539acbbeafSnn rt_to_str(RT_BRAND)); 44549acbbeafSnn return; 44559acbbeafSnn } 44569acbbeafSnn if ((err = zonecfg_set_brand(handle, prop_id)) != Z_OK) 4457bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 44589acbbeafSnn else 4459bbec428eSgjelinek need_to_commit = B_TRUE; 44609acbbeafSnn return; 44617c478bd9Sstevel@tonic-gate case RT_AUTOBOOT: 44627c478bd9Sstevel@tonic-gate if (strcmp(prop_id, "true") == 0) { 44637c478bd9Sstevel@tonic-gate autoboot = B_TRUE; 44647c478bd9Sstevel@tonic-gate } else if (strcmp(prop_id, "false") == 0) { 44657c478bd9Sstevel@tonic-gate autoboot = B_FALSE; 44667c478bd9Sstevel@tonic-gate } else { 44677c478bd9Sstevel@tonic-gate zerr(gettext("%s value must be '%s' or '%s'."), 44687c478bd9Sstevel@tonic-gate pt_to_str(PT_AUTOBOOT), "true", "false"); 4469bbec428eSgjelinek saw_error = B_TRUE; 44707c478bd9Sstevel@tonic-gate return; 44717c478bd9Sstevel@tonic-gate } 44727c478bd9Sstevel@tonic-gate if ((err = zonecfg_set_autoboot(handle, autoboot)) != Z_OK) 4473bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 44747c478bd9Sstevel@tonic-gate else 4475bbec428eSgjelinek need_to_commit = B_TRUE; 44767c478bd9Sstevel@tonic-gate return; 44777c478bd9Sstevel@tonic-gate case RT_POOL: 44780209230bSgjelinek /* don't allow use of the reserved temporary pool names */ 44790209230bSgjelinek if (strncmp("SUNW", prop_id, 4) == 0) { 44800209230bSgjelinek zerr(gettext("pool names starting with SUNW are " 44810209230bSgjelinek "reserved.")); 4482bbec428eSgjelinek saw_error = B_TRUE; 44830209230bSgjelinek return; 44840209230bSgjelinek } 44850209230bSgjelinek 44860209230bSgjelinek /* can't set pool if dedicated-cpu exists */ 44870209230bSgjelinek if (zonecfg_lookup_pset(handle, &tmp_psettab) == Z_OK) { 44880209230bSgjelinek zerr(gettext("The %s resource already exists. " 44890209230bSgjelinek "A persistent pool is incompatible\nwith the %s " 44900209230bSgjelinek "resource."), rt_to_str(RT_DCPU), 44910209230bSgjelinek rt_to_str(RT_DCPU)); 4492bbec428eSgjelinek saw_error = B_TRUE; 44930209230bSgjelinek return; 44940209230bSgjelinek } 44950209230bSgjelinek 44967c478bd9Sstevel@tonic-gate if ((err = zonecfg_set_pool(handle, prop_id)) != Z_OK) 4497bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 44987c478bd9Sstevel@tonic-gate else 4499bbec428eSgjelinek need_to_commit = B_TRUE; 45007c478bd9Sstevel@tonic-gate return; 4501ffbafc53Scomay case RT_LIMITPRIV: 4502ffbafc53Scomay if ((err = zonecfg_set_limitpriv(handle, prop_id)) != Z_OK) 4503bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 4504ffbafc53Scomay else 4505bbec428eSgjelinek need_to_commit = B_TRUE; 4506ffbafc53Scomay return; 45073f2f09c1Sdp case RT_BOOTARGS: 45083f2f09c1Sdp if ((err = zonecfg_set_bootargs(handle, prop_id)) != Z_OK) 4509bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 45103f2f09c1Sdp else 4511bbec428eSgjelinek need_to_commit = B_TRUE; 45123f2f09c1Sdp return; 45130209230bSgjelinek case RT_SCHED: 45140209230bSgjelinek if ((err = zonecfg_set_sched(handle, prop_id)) != Z_OK) 4515bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 45160209230bSgjelinek else 4517bbec428eSgjelinek need_to_commit = B_TRUE; 45180209230bSgjelinek return; 4519f4b3ec61Sdh case RT_IPTYPE: 4520f4b3ec61Sdh if (strcmp(prop_id, "shared") == 0) { 4521f4b3ec61Sdh iptype = ZS_SHARED; 4522f4b3ec61Sdh } else if (strcmp(prop_id, "exclusive") == 0) { 4523f4b3ec61Sdh iptype = ZS_EXCLUSIVE; 4524f4b3ec61Sdh } else { 4525f4b3ec61Sdh zerr(gettext("%s value must be '%s' or '%s'."), 4526f4b3ec61Sdh pt_to_str(PT_IPTYPE), "shared", "exclusive"); 4527bbec428eSgjelinek saw_error = B_TRUE; 4528f4b3ec61Sdh return; 4529f4b3ec61Sdh } 4530f4b3ec61Sdh if (iptype == ZS_EXCLUSIVE && !allow_exclusive()) { 4531bbec428eSgjelinek saw_error = B_TRUE; 4532f4b3ec61Sdh return; 4533f4b3ec61Sdh } 4534f4b3ec61Sdh if ((err = zonecfg_set_iptype(handle, iptype)) != Z_OK) 4535bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 4536f4b3ec61Sdh else 4537bbec428eSgjelinek need_to_commit = B_TRUE; 4538f4b3ec61Sdh return; 45390209230bSgjelinek case RT_MAXLWPS: 45400209230bSgjelinek set_aliased_rctl(ALIAS_MAXLWPS, prop_type, prop_id); 45410209230bSgjelinek return; 4542ff19e029SMenno Lageman case RT_MAXPROCS: 4543ff19e029SMenno Lageman set_aliased_rctl(ALIAS_MAXPROCS, prop_type, prop_id); 4544ff19e029SMenno Lageman return; 45450209230bSgjelinek case RT_MAXSHMMEM: 45460209230bSgjelinek set_aliased_rctl(ALIAS_MAXSHMMEM, prop_type, prop_id); 45470209230bSgjelinek return; 45480209230bSgjelinek case RT_MAXSHMIDS: 45490209230bSgjelinek set_aliased_rctl(ALIAS_MAXSHMIDS, prop_type, prop_id); 45500209230bSgjelinek return; 45510209230bSgjelinek case RT_MAXMSGIDS: 45520209230bSgjelinek set_aliased_rctl(ALIAS_MAXMSGIDS, prop_type, prop_id); 45530209230bSgjelinek return; 45540209230bSgjelinek case RT_MAXSEMIDS: 45550209230bSgjelinek set_aliased_rctl(ALIAS_MAXSEMIDS, prop_type, prop_id); 45560209230bSgjelinek return; 45570209230bSgjelinek case RT_SHARES: 45580209230bSgjelinek set_aliased_rctl(ALIAS_SHARES, prop_type, prop_id); 45590209230bSgjelinek return; 45605679c89fSjv case RT_HOSTID: 45615679c89fSjv if ((err = zonecfg_set_hostid(handle, prop_id)) != Z_OK) { 45625679c89fSjv if (err == Z_TOO_BIG) { 45635679c89fSjv zerr(gettext("hostid string is too large: %s"), 45645679c89fSjv prop_id); 45655679c89fSjv saw_error = B_TRUE; 45665679c89fSjv } else { 45675679c89fSjv zone_perror(pt_to_str(prop_type), err, B_TRUE); 45685679c89fSjv } 45695679c89fSjv return; 45705679c89fSjv } 45715679c89fSjv need_to_commit = B_TRUE; 45725679c89fSjv return; 45730fbb751dSJohn Levon case RT_FS_ALLOWED: 45740fbb751dSJohn Levon if ((err = zonecfg_set_fs_allowed(handle, prop_id)) != Z_OK) 45750fbb751dSJohn Levon zone_perror(zone, err, B_TRUE); 45760fbb751dSJohn Levon else 45770fbb751dSJohn Levon need_to_commit = B_TRUE; 45780fbb751dSJohn Levon return; 45797c478bd9Sstevel@tonic-gate case RT_FS: 45807c478bd9Sstevel@tonic-gate switch (prop_type) { 45817c478bd9Sstevel@tonic-gate case PT_DIR: 45827c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_dir, prop_id, 45837c478bd9Sstevel@tonic-gate sizeof (in_progress_fstab.zone_fs_dir)); 45847c478bd9Sstevel@tonic-gate return; 45857c478bd9Sstevel@tonic-gate case PT_SPECIAL: 45867c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_special, 45877c478bd9Sstevel@tonic-gate prop_id, 45887c478bd9Sstevel@tonic-gate sizeof (in_progress_fstab.zone_fs_special)); 45897c478bd9Sstevel@tonic-gate return; 45907c478bd9Sstevel@tonic-gate case PT_RAW: 45917c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_raw, 45927c478bd9Sstevel@tonic-gate prop_id, sizeof (in_progress_fstab.zone_fs_raw)); 45937c478bd9Sstevel@tonic-gate return; 45947c478bd9Sstevel@tonic-gate case PT_TYPE: 45957c478bd9Sstevel@tonic-gate if (!valid_fs_type(prop_id)) { 45967c478bd9Sstevel@tonic-gate zerr(gettext("\"%s\" is not a valid %s."), 45977c478bd9Sstevel@tonic-gate prop_id, pt_to_str(PT_TYPE)); 4598bbec428eSgjelinek saw_error = B_TRUE; 45997c478bd9Sstevel@tonic-gate return; 46007c478bd9Sstevel@tonic-gate } 46017c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_type, prop_id, 46027c478bd9Sstevel@tonic-gate sizeof (in_progress_fstab.zone_fs_type)); 46037c478bd9Sstevel@tonic-gate return; 46047c478bd9Sstevel@tonic-gate case PT_OPTIONS: 46057c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE && 46067c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 46077c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected " 46087c478bd9Sstevel@tonic-gate "here."), pvt_to_str(PROP_VAL_SIMPLE), 46097c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 4610bbec428eSgjelinek saw_error = B_TRUE; 46117c478bd9Sstevel@tonic-gate return; 46127c478bd9Sstevel@tonic-gate } 46137c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list( 46147c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_options); 46157c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_options = NULL; 46167c478bd9Sstevel@tonic-gate if (!(pp->pv_type == PROP_VAL_LIST && 46177c478bd9Sstevel@tonic-gate pp->pv_list == NULL)) 46187c478bd9Sstevel@tonic-gate add_property(cmd); 46197c478bd9Sstevel@tonic-gate return; 46207c478bd9Sstevel@tonic-gate default: 46217c478bd9Sstevel@tonic-gate break; 46227c478bd9Sstevel@tonic-gate } 4623bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, B_TRUE); 4624bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4625bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 46267c478bd9Sstevel@tonic-gate return; 46277c478bd9Sstevel@tonic-gate case RT_NET: 46287c478bd9Sstevel@tonic-gate switch (prop_type) { 46297c478bd9Sstevel@tonic-gate case PT_ADDRESS: 4630550b6e40SSowmini Varadhan case PT_ALLOWED_ADDRESS: 4631550b6e40SSowmini Varadhan if (validate_net_address_syntax(prop_id, B_FALSE) 4632550b6e40SSowmini Varadhan != Z_OK) { 4633bbec428eSgjelinek saw_error = B_TRUE; 46347c478bd9Sstevel@tonic-gate return; 46357c478bd9Sstevel@tonic-gate } 4636550b6e40SSowmini Varadhan set_in_progress_nwiftab_address(prop_id, prop_type); 46377c478bd9Sstevel@tonic-gate break; 46387c478bd9Sstevel@tonic-gate case PT_PHYSICAL: 46397c478bd9Sstevel@tonic-gate if (validate_net_physical_syntax(prop_id) != Z_OK) { 4640bbec428eSgjelinek saw_error = B_TRUE; 46417c478bd9Sstevel@tonic-gate return; 46427c478bd9Sstevel@tonic-gate } 46437c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_nwiftab.zone_nwif_physical, 46447c478bd9Sstevel@tonic-gate prop_id, 46457c478bd9Sstevel@tonic-gate sizeof (in_progress_nwiftab.zone_nwif_physical)); 46467c478bd9Sstevel@tonic-gate break; 4647de860bd9Sgfaden case PT_DEFROUTER: 4648550b6e40SSowmini Varadhan if (validate_net_address_syntax(prop_id, B_TRUE) 4649550b6e40SSowmini Varadhan != Z_OK) { 4650bbec428eSgjelinek saw_error = B_TRUE; 4651de860bd9Sgfaden return; 4652de860bd9Sgfaden } 4653de860bd9Sgfaden (void) strlcpy(in_progress_nwiftab.zone_nwif_defrouter, 4654de860bd9Sgfaden prop_id, 4655de860bd9Sgfaden sizeof (in_progress_nwiftab.zone_nwif_defrouter)); 4656de860bd9Sgfaden break; 46577c478bd9Sstevel@tonic-gate default: 46587c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4659bbec428eSgjelinek B_TRUE); 4660bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4661bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 46627c478bd9Sstevel@tonic-gate return; 46637c478bd9Sstevel@tonic-gate } 46647c478bd9Sstevel@tonic-gate return; 46657c478bd9Sstevel@tonic-gate case RT_DEVICE: 46667c478bd9Sstevel@tonic-gate switch (prop_type) { 46677c478bd9Sstevel@tonic-gate case PT_MATCH: 46687c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_devtab.zone_dev_match, 46697c478bd9Sstevel@tonic-gate prop_id, 46707c478bd9Sstevel@tonic-gate sizeof (in_progress_devtab.zone_dev_match)); 46717c478bd9Sstevel@tonic-gate break; 46727c478bd9Sstevel@tonic-gate default: 46737c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4674bbec428eSgjelinek B_TRUE); 4675bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4676bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 46777c478bd9Sstevel@tonic-gate return; 46787c478bd9Sstevel@tonic-gate } 46797c478bd9Sstevel@tonic-gate return; 46807c478bd9Sstevel@tonic-gate case RT_RCTL: 46817c478bd9Sstevel@tonic-gate switch (prop_type) { 46827c478bd9Sstevel@tonic-gate case PT_NAME: 46837c478bd9Sstevel@tonic-gate if (!zonecfg_valid_rctlname(prop_id)) { 46847c478bd9Sstevel@tonic-gate zerr(gettext("'%s' is not a valid zone %s " 46857c478bd9Sstevel@tonic-gate "name."), prop_id, rt_to_str(RT_RCTL)); 46867c478bd9Sstevel@tonic-gate return; 46877c478bd9Sstevel@tonic-gate } 46887c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_rctltab.zone_rctl_name, 46897c478bd9Sstevel@tonic-gate prop_id, 46907c478bd9Sstevel@tonic-gate sizeof (in_progress_rctltab.zone_rctl_name)); 46917c478bd9Sstevel@tonic-gate break; 46927c478bd9Sstevel@tonic-gate case PT_VALUE: 46937c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_COMPLEX && 46947c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 46957c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected " 46967c478bd9Sstevel@tonic-gate "here."), pvt_to_str(PROP_VAL_COMPLEX), 46977c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 4698bbec428eSgjelinek saw_error = B_TRUE; 46997c478bd9Sstevel@tonic-gate return; 47007c478bd9Sstevel@tonic-gate } 47017c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list( 47027c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr); 47037c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr = NULL; 47047c478bd9Sstevel@tonic-gate if (!(pp->pv_type == PROP_VAL_LIST && 47057c478bd9Sstevel@tonic-gate pp->pv_list == NULL)) 47067c478bd9Sstevel@tonic-gate add_property(cmd); 47077c478bd9Sstevel@tonic-gate break; 47087c478bd9Sstevel@tonic-gate default: 47097c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4710bbec428eSgjelinek B_TRUE); 4711bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4712bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 47137c478bd9Sstevel@tonic-gate return; 47147c478bd9Sstevel@tonic-gate } 47157c478bd9Sstevel@tonic-gate return; 47167c478bd9Sstevel@tonic-gate case RT_ATTR: 47177c478bd9Sstevel@tonic-gate switch (prop_type) { 47187c478bd9Sstevel@tonic-gate case PT_NAME: 47197c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_attrtab.zone_attr_name, 47207c478bd9Sstevel@tonic-gate prop_id, 47217c478bd9Sstevel@tonic-gate sizeof (in_progress_attrtab.zone_attr_name)); 47227c478bd9Sstevel@tonic-gate break; 47237c478bd9Sstevel@tonic-gate case PT_TYPE: 47247c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_attrtab.zone_attr_type, 47257c478bd9Sstevel@tonic-gate prop_id, 47267c478bd9Sstevel@tonic-gate sizeof (in_progress_attrtab.zone_attr_type)); 47277c478bd9Sstevel@tonic-gate break; 47287c478bd9Sstevel@tonic-gate case PT_VALUE: 47297c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_attrtab.zone_attr_value, 47307c478bd9Sstevel@tonic-gate prop_id, 47317c478bd9Sstevel@tonic-gate sizeof (in_progress_attrtab.zone_attr_value)); 47327c478bd9Sstevel@tonic-gate break; 47337c478bd9Sstevel@tonic-gate default: 47347c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4735bbec428eSgjelinek B_TRUE); 4736bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4737bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 47387c478bd9Sstevel@tonic-gate return; 47397c478bd9Sstevel@tonic-gate } 47407c478bd9Sstevel@tonic-gate return; 4741fa9e4066Sahrens case RT_DATASET: 4742fa9e4066Sahrens switch (prop_type) { 4743fa9e4066Sahrens case PT_NAME: 4744fa9e4066Sahrens (void) strlcpy(in_progress_dstab.zone_dataset_name, 4745fa9e4066Sahrens prop_id, 4746fa9e4066Sahrens sizeof (in_progress_dstab.zone_dataset_name)); 4747fa9e4066Sahrens return; 4748fa9e4066Sahrens default: 4749fa9e4066Sahrens break; 4750fa9e4066Sahrens } 4751bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, B_TRUE); 4752bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4753bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 47540209230bSgjelinek return; 47550209230bSgjelinek case RT_DCPU: 47560209230bSgjelinek switch (prop_type) { 47570209230bSgjelinek char *lowp, *highp; 47580209230bSgjelinek 47590209230bSgjelinek case PT_NCPUS: 47600209230bSgjelinek lowp = prop_id; 47610209230bSgjelinek if ((highp = strchr(prop_id, '-')) != NULL) 47620209230bSgjelinek *highp++ = '\0'; 47630209230bSgjelinek else 47640209230bSgjelinek highp = lowp; 47650209230bSgjelinek 47660209230bSgjelinek /* Make sure the input makes sense. */ 47670209230bSgjelinek if (!zonecfg_valid_ncpus(lowp, highp)) { 47680209230bSgjelinek zerr(gettext("%s property is out of range."), 47690209230bSgjelinek pt_to_str(PT_NCPUS)); 4770bbec428eSgjelinek saw_error = B_TRUE; 47710209230bSgjelinek return; 47720209230bSgjelinek } 47730209230bSgjelinek 47740209230bSgjelinek (void) strlcpy( 47750209230bSgjelinek in_progress_psettab.zone_ncpu_min, lowp, 47760209230bSgjelinek sizeof (in_progress_psettab.zone_ncpu_min)); 47770209230bSgjelinek (void) strlcpy( 47780209230bSgjelinek in_progress_psettab.zone_ncpu_max, highp, 47790209230bSgjelinek sizeof (in_progress_psettab.zone_ncpu_max)); 47800209230bSgjelinek return; 47810209230bSgjelinek case PT_IMPORTANCE: 47820209230bSgjelinek /* Make sure the value makes sense. */ 47830209230bSgjelinek if (!zonecfg_valid_importance(prop_id)) { 47840209230bSgjelinek zerr(gettext("%s property is out of range."), 47850209230bSgjelinek pt_to_str(PT_IMPORTANCE)); 4786bbec428eSgjelinek saw_error = B_TRUE; 47870209230bSgjelinek return; 47880209230bSgjelinek } 47890209230bSgjelinek 47900209230bSgjelinek (void) strlcpy(in_progress_psettab.zone_importance, 47910209230bSgjelinek prop_id, 47920209230bSgjelinek sizeof (in_progress_psettab.zone_importance)); 47930209230bSgjelinek return; 47940209230bSgjelinek default: 47950209230bSgjelinek break; 47960209230bSgjelinek } 4797bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, B_TRUE); 4798bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4799bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 48000209230bSgjelinek return; 4801c97ad5cdSakolb case RT_PCAP: 4802c97ad5cdSakolb if (prop_type != PT_NCPUS) { 4803c97ad5cdSakolb zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4804bbec428eSgjelinek B_TRUE); 4805bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4806bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 4807c97ad5cdSakolb return; 4808c97ad5cdSakolb } 4809c97ad5cdSakolb 4810c97ad5cdSakolb /* 4811c97ad5cdSakolb * We already checked that an rctl alias is allowed in 4812c97ad5cdSakolb * the add_resource() function. 4813c97ad5cdSakolb */ 4814c97ad5cdSakolb 4815c97ad5cdSakolb if ((cap = strtof(prop_id, &unitp)) <= 0 || *unitp != '\0' || 4816c97ad5cdSakolb (int)(cap * 100) < 1) { 4817c97ad5cdSakolb zerr(gettext("%s property is out of range."), 4818c97ad5cdSakolb pt_to_str(PT_NCPUS)); 4819bbec428eSgjelinek saw_error = B_TRUE; 4820c97ad5cdSakolb return; 4821c97ad5cdSakolb } 4822c97ad5cdSakolb 4823c97ad5cdSakolb if ((err = zonecfg_set_aliased_rctl(handle, ALIAS_CPUCAP, 4824c97ad5cdSakolb (int)(cap * 100))) != Z_OK) 4825bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 4826c97ad5cdSakolb else 4827bbec428eSgjelinek need_to_commit = B_TRUE; 4828c97ad5cdSakolb return; 48290209230bSgjelinek case RT_MCAP: 48300209230bSgjelinek switch (prop_type) { 48310209230bSgjelinek case PT_PHYSICAL: 48320209230bSgjelinek if (!zonecfg_valid_memlimit(prop_id, &mem_cap)) { 48330209230bSgjelinek zerr(gettext("A positive number with a " 48340209230bSgjelinek "required scale suffix (K, M, G or T) was " 48350209230bSgjelinek "expected here.")); 4836bbec428eSgjelinek saw_error = B_TRUE; 48370209230bSgjelinek } else if (mem_cap < ONE_MB) { 48380209230bSgjelinek zerr(gettext("%s value is too small. It must " 48390209230bSgjelinek "be at least 1M."), pt_to_str(PT_PHYSICAL)); 4840bbec428eSgjelinek saw_error = B_TRUE; 48410209230bSgjelinek } else { 48420209230bSgjelinek snprintf(in_progress_mcaptab.zone_physmem_cap, 48430209230bSgjelinek physmem_size, "%llu", mem_cap); 48440209230bSgjelinek } 48450209230bSgjelinek break; 48460209230bSgjelinek case PT_SWAP: 48470209230bSgjelinek /* 48480209230bSgjelinek * We have to check if an rctl is allowed here since 48490209230bSgjelinek * there might already be a rctl defined that blocks 48500209230bSgjelinek * the alias. 48510209230bSgjelinek */ 48520209230bSgjelinek if (!zonecfg_aliased_rctl_ok(handle, ALIAS_MAXSWAP)) { 48530209230bSgjelinek zone_perror(pt_to_str(PT_MAXSWAP), 4854bbec428eSgjelinek Z_ALIAS_DISALLOW, B_FALSE); 4855bbec428eSgjelinek saw_error = B_TRUE; 48560209230bSgjelinek return; 48570209230bSgjelinek } 48580209230bSgjelinek 48590209230bSgjelinek if (global_zone) 48600209230bSgjelinek mem_limit = ONE_MB * 100; 48610209230bSgjelinek else 48620209230bSgjelinek mem_limit = ONE_MB * 50; 48630209230bSgjelinek 48640209230bSgjelinek if (!zonecfg_valid_memlimit(prop_id, &mem_cap)) { 48650209230bSgjelinek zerr(gettext("A positive number with a " 48660209230bSgjelinek "required scale suffix (K, M, G or T) was " 48670209230bSgjelinek "expected here.")); 4868bbec428eSgjelinek saw_error = B_TRUE; 48690209230bSgjelinek } else if (mem_cap < mem_limit) { 48700209230bSgjelinek char buf[128]; 48710209230bSgjelinek 48720209230bSgjelinek (void) snprintf(buf, sizeof (buf), "%llu", 48730209230bSgjelinek mem_limit); 48740209230bSgjelinek bytes_to_units(buf, buf, sizeof (buf)); 48750209230bSgjelinek zerr(gettext("%s value is too small. It must " 48760209230bSgjelinek "be at least %s."), pt_to_str(PT_SWAP), 48770209230bSgjelinek buf); 4878bbec428eSgjelinek saw_error = B_TRUE; 48790209230bSgjelinek } else { 48800209230bSgjelinek if ((err = zonecfg_set_aliased_rctl(handle, 48810209230bSgjelinek ALIAS_MAXSWAP, mem_cap)) != Z_OK) 4882bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 48830209230bSgjelinek else 4884bbec428eSgjelinek need_to_commit = B_TRUE; 48850209230bSgjelinek } 48860209230bSgjelinek break; 48870209230bSgjelinek case PT_LOCKED: 48880209230bSgjelinek /* 48890209230bSgjelinek * We have to check if an rctl is allowed here since 48900209230bSgjelinek * there might already be a rctl defined that blocks 48910209230bSgjelinek * the alias. 48920209230bSgjelinek */ 48930209230bSgjelinek if (!zonecfg_aliased_rctl_ok(handle, 48940209230bSgjelinek ALIAS_MAXLOCKEDMEM)) { 48950209230bSgjelinek zone_perror(pt_to_str(PT_LOCKED), 4896bbec428eSgjelinek Z_ALIAS_DISALLOW, B_FALSE); 4897bbec428eSgjelinek saw_error = B_TRUE; 48980209230bSgjelinek return; 48990209230bSgjelinek } 49000209230bSgjelinek 49010209230bSgjelinek if (!zonecfg_valid_memlimit(prop_id, &mem_cap)) { 49020209230bSgjelinek zerr(gettext("A non-negative number with a " 49030209230bSgjelinek "required scale suffix (K, M, G or T) was " 49040209230bSgjelinek "expected\nhere.")); 4905bbec428eSgjelinek saw_error = B_TRUE; 49060209230bSgjelinek } else { 49070209230bSgjelinek if ((err = zonecfg_set_aliased_rctl(handle, 49080209230bSgjelinek ALIAS_MAXLOCKEDMEM, mem_cap)) != Z_OK) 4909bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 49100209230bSgjelinek else 4911bbec428eSgjelinek need_to_commit = B_TRUE; 49120209230bSgjelinek } 49130209230bSgjelinek break; 49140209230bSgjelinek default: 49150209230bSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4916bbec428eSgjelinek B_TRUE); 4917bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4918bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 49190209230bSgjelinek return; 49200209230bSgjelinek } 4921fa9e4066Sahrens return; 4922cb8a054bSGlenn Faden case RT_ADMIN: 4923cb8a054bSGlenn Faden switch (prop_type) { 4924cb8a054bSGlenn Faden case PT_USER: 4925cb8a054bSGlenn Faden (void) strlcpy(in_progress_admintab.zone_admin_user, 4926cb8a054bSGlenn Faden prop_id, 4927cb8a054bSGlenn Faden sizeof (in_progress_admintab.zone_admin_user)); 4928cb8a054bSGlenn Faden return; 4929cb8a054bSGlenn Faden case PT_AUTHS: 4930cb8a054bSGlenn Faden (void) strlcpy(in_progress_admintab.zone_admin_auths, 4931cb8a054bSGlenn Faden prop_id, 4932cb8a054bSGlenn Faden sizeof (in_progress_admintab.zone_admin_auths)); 4933cb8a054bSGlenn Faden return; 4934cb8a054bSGlenn Faden default: 4935cb8a054bSGlenn Faden zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4936cb8a054bSGlenn Faden B_TRUE); 4937cb8a054bSGlenn Faden long_usage(CMD_SET, B_TRUE); 4938cb8a054bSGlenn Faden usage(B_FALSE, HELP_PROPS); 4939cb8a054bSGlenn Faden return; 4940cb8a054bSGlenn Faden } 4941*d2a70789SRichard Lowe case RT_SECFLAGS: { 4942*d2a70789SRichard Lowe char *propstr; 4943*d2a70789SRichard Lowe 4944*d2a70789SRichard Lowe switch (prop_type) { 4945*d2a70789SRichard Lowe case PT_DEFAULT: 4946*d2a70789SRichard Lowe propstr = in_progress_secflagstab.zone_secflags_default; 4947*d2a70789SRichard Lowe break; 4948*d2a70789SRichard Lowe case PT_UPPER: 4949*d2a70789SRichard Lowe propstr = in_progress_secflagstab.zone_secflags_upper; 4950*d2a70789SRichard Lowe break; 4951*d2a70789SRichard Lowe case PT_LOWER: 4952*d2a70789SRichard Lowe propstr = in_progress_secflagstab.zone_secflags_lower; 4953*d2a70789SRichard Lowe break; 4954*d2a70789SRichard Lowe default: 4955*d2a70789SRichard Lowe zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4956*d2a70789SRichard Lowe B_TRUE); 4957*d2a70789SRichard Lowe long_usage(CMD_SET, B_TRUE); 4958*d2a70789SRichard Lowe usage(B_FALSE, HELP_PROPS); 4959*d2a70789SRichard Lowe return; 4960*d2a70789SRichard Lowe } 4961*d2a70789SRichard Lowe (void) strlcpy(propstr, prop_id, ZONECFG_SECFLAGS_MAX); 4962*d2a70789SRichard Lowe return; 4963*d2a70789SRichard Lowe } 49647c478bd9Sstevel@tonic-gate default: 4965bbec428eSgjelinek zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, B_TRUE); 4966bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4967bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 49687c478bd9Sstevel@tonic-gate return; 49697c478bd9Sstevel@tonic-gate } 49707c478bd9Sstevel@tonic-gate } 49717c478bd9Sstevel@tonic-gate 49727c478bd9Sstevel@tonic-gate static void 4973bbec428eSgjelinek output_prop(FILE *fp, int pnum, char *pval, boolean_t print_notspec) 49747c478bd9Sstevel@tonic-gate { 49757c478bd9Sstevel@tonic-gate char *qstr; 49767c478bd9Sstevel@tonic-gate 49777c478bd9Sstevel@tonic-gate if (*pval != '\0') { 49787c478bd9Sstevel@tonic-gate qstr = quoteit(pval); 49790209230bSgjelinek if (pnum == PT_SWAP || pnum == PT_LOCKED) 49800209230bSgjelinek (void) fprintf(fp, "\t[%s: %s]\n", pt_to_str(pnum), 49810209230bSgjelinek qstr); 49820209230bSgjelinek else 49830209230bSgjelinek (void) fprintf(fp, "\t%s: %s\n", pt_to_str(pnum), qstr); 49847c478bd9Sstevel@tonic-gate free(qstr); 49857c478bd9Sstevel@tonic-gate } else if (print_notspec) 4986087719fdSdp (void) fprintf(fp, gettext("\t%s not specified\n"), 4987087719fdSdp pt_to_str(pnum)); 4988087719fdSdp } 4989087719fdSdp 4990087719fdSdp static void 4991087719fdSdp info_zonename(zone_dochandle_t handle, FILE *fp) 4992087719fdSdp { 4993087719fdSdp char zonename[ZONENAME_MAX]; 4994087719fdSdp 4995087719fdSdp if (zonecfg_get_name(handle, zonename, sizeof (zonename)) == Z_OK) 4996087719fdSdp (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_ZONENAME), 4997087719fdSdp zonename); 4998087719fdSdp else 4999087719fdSdp (void) fprintf(fp, gettext("%s not specified\n"), 5000087719fdSdp pt_to_str(PT_ZONENAME)); 50017c478bd9Sstevel@tonic-gate } 50027c478bd9Sstevel@tonic-gate 50037c478bd9Sstevel@tonic-gate static void 50047c478bd9Sstevel@tonic-gate info_zonepath(zone_dochandle_t handle, FILE *fp) 50057c478bd9Sstevel@tonic-gate { 50067c478bd9Sstevel@tonic-gate char zonepath[MAXPATHLEN]; 50077c478bd9Sstevel@tonic-gate 50087c478bd9Sstevel@tonic-gate if (zonecfg_get_zonepath(handle, zonepath, sizeof (zonepath)) == Z_OK) 50097c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_ZONEPATH), 50107c478bd9Sstevel@tonic-gate zonepath); 5011087719fdSdp else { 5012087719fdSdp (void) fprintf(fp, gettext("%s not specified\n"), 5013087719fdSdp pt_to_str(PT_ZONEPATH)); 5014087719fdSdp } 50157c478bd9Sstevel@tonic-gate } 50167c478bd9Sstevel@tonic-gate 50179acbbeafSnn static void 50189acbbeafSnn info_brand(zone_dochandle_t handle, FILE *fp) 50199acbbeafSnn { 50209acbbeafSnn char brand[MAXNAMELEN]; 50219acbbeafSnn 50229acbbeafSnn if (zonecfg_get_brand(handle, brand, sizeof (brand)) == Z_OK) 50239acbbeafSnn (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_BRAND), 50249acbbeafSnn brand); 50259acbbeafSnn else 50269acbbeafSnn (void) fprintf(fp, "%s %s\n", pt_to_str(PT_BRAND), 50279acbbeafSnn gettext("not specified")); 50289acbbeafSnn } 50299acbbeafSnn 50307c478bd9Sstevel@tonic-gate static void 50317c478bd9Sstevel@tonic-gate info_autoboot(zone_dochandle_t handle, FILE *fp) 50327c478bd9Sstevel@tonic-gate { 50337c478bd9Sstevel@tonic-gate boolean_t autoboot; 50347c478bd9Sstevel@tonic-gate int err; 50357c478bd9Sstevel@tonic-gate 50367c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_autoboot(handle, &autoboot)) == Z_OK) 50377c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_AUTOBOOT), 50387c478bd9Sstevel@tonic-gate autoboot ? "true" : "false"); 50397c478bd9Sstevel@tonic-gate else 5040bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 50417c478bd9Sstevel@tonic-gate } 50427c478bd9Sstevel@tonic-gate 50437c478bd9Sstevel@tonic-gate static void 50447c478bd9Sstevel@tonic-gate info_pool(zone_dochandle_t handle, FILE *fp) 50457c478bd9Sstevel@tonic-gate { 50467c478bd9Sstevel@tonic-gate char pool[MAXNAMELEN]; 50477c478bd9Sstevel@tonic-gate int err; 50487c478bd9Sstevel@tonic-gate 50497c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_pool(handle, pool, sizeof (pool))) == Z_OK) 50507c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_POOL), pool); 50517c478bd9Sstevel@tonic-gate else 5052bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 50537c478bd9Sstevel@tonic-gate } 50547c478bd9Sstevel@tonic-gate 5055ffbafc53Scomay static void 5056ffbafc53Scomay info_limitpriv(zone_dochandle_t handle, FILE *fp) 5057ffbafc53Scomay { 5058ffbafc53Scomay char *limitpriv; 5059ffbafc53Scomay int err; 5060ffbafc53Scomay 5061ffbafc53Scomay if ((err = zonecfg_get_limitpriv(handle, &limitpriv)) == Z_OK) { 5062ffbafc53Scomay (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_LIMITPRIV), 5063ffbafc53Scomay limitpriv); 5064ffbafc53Scomay free(limitpriv); 5065ffbafc53Scomay } else { 5066bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 5067ffbafc53Scomay } 5068ffbafc53Scomay } 5069ffbafc53Scomay 50703f2f09c1Sdp static void 50713f2f09c1Sdp info_bootargs(zone_dochandle_t handle, FILE *fp) 50723f2f09c1Sdp { 50733f2f09c1Sdp char bootargs[BOOTARGS_MAX]; 50743f2f09c1Sdp int err; 50753f2f09c1Sdp 50763f2f09c1Sdp if ((err = zonecfg_get_bootargs(handle, bootargs, 50773f2f09c1Sdp sizeof (bootargs))) == Z_OK) { 50783f2f09c1Sdp (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_BOOTARGS), 50793f2f09c1Sdp bootargs); 50803f2f09c1Sdp } else { 5081bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 50823f2f09c1Sdp } 50833f2f09c1Sdp } 50843f2f09c1Sdp 50850209230bSgjelinek static void 50860209230bSgjelinek info_sched(zone_dochandle_t handle, FILE *fp) 50870209230bSgjelinek { 50880209230bSgjelinek char sched[MAXNAMELEN]; 50890209230bSgjelinek int err; 50900209230bSgjelinek 50910209230bSgjelinek if ((err = zonecfg_get_sched_class(handle, sched, sizeof (sched))) 50920209230bSgjelinek == Z_OK) { 50930209230bSgjelinek (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_SCHED), sched); 50940209230bSgjelinek } else { 5095bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 50960209230bSgjelinek } 50970209230bSgjelinek } 50980209230bSgjelinek 5099f4b3ec61Sdh static void 5100f4b3ec61Sdh info_iptype(zone_dochandle_t handle, FILE *fp) 5101f4b3ec61Sdh { 5102f4b3ec61Sdh zone_iptype_t iptype; 5103f4b3ec61Sdh int err; 5104f4b3ec61Sdh 5105f4b3ec61Sdh if ((err = zonecfg_get_iptype(handle, &iptype)) == Z_OK) { 5106f4b3ec61Sdh switch (iptype) { 5107f4b3ec61Sdh case ZS_SHARED: 5108f4b3ec61Sdh (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_IPTYPE), 5109f4b3ec61Sdh "shared"); 5110f4b3ec61Sdh break; 5111f4b3ec61Sdh case ZS_EXCLUSIVE: 5112f4b3ec61Sdh (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_IPTYPE), 5113f4b3ec61Sdh "exclusive"); 5114f4b3ec61Sdh break; 5115f4b3ec61Sdh } 5116f4b3ec61Sdh } else { 5117bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 5118f4b3ec61Sdh } 5119f4b3ec61Sdh } 5120f4b3ec61Sdh 51215679c89fSjv static void 51225679c89fSjv info_hostid(zone_dochandle_t handle, FILE *fp) 51235679c89fSjv { 51245679c89fSjv char hostidp[HW_HOSTID_LEN]; 51250fbb751dSJohn Levon int err; 51265679c89fSjv 51270fbb751dSJohn Levon if ((err = zonecfg_get_hostid(handle, hostidp, 51280fbb751dSJohn Levon sizeof (hostidp))) == Z_OK) { 51290fbb751dSJohn Levon (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_HOSTID), hostidp); 51300fbb751dSJohn Levon } else if (err == Z_BAD_PROPERTY) { 51310fbb751dSJohn Levon (void) fprintf(fp, "%s: \n", pt_to_str(PT_HOSTID)); 51320fbb751dSJohn Levon } else { 51330fbb751dSJohn Levon zone_perror(zone, err, B_TRUE); 51340fbb751dSJohn Levon } 51350fbb751dSJohn Levon } 51360fbb751dSJohn Levon 51370fbb751dSJohn Levon static void 51380fbb751dSJohn Levon info_fs_allowed(zone_dochandle_t handle, FILE *fp) 51390fbb751dSJohn Levon { 51400fbb751dSJohn Levon char fsallowedp[ZONE_FS_ALLOWED_MAX]; 51410fbb751dSJohn Levon int err; 51420fbb751dSJohn Levon 51430fbb751dSJohn Levon if ((err = zonecfg_get_fs_allowed(handle, fsallowedp, 51440fbb751dSJohn Levon sizeof (fsallowedp))) == Z_OK) { 51450fbb751dSJohn Levon (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_FS_ALLOWED), 51460fbb751dSJohn Levon fsallowedp); 51470fbb751dSJohn Levon } else if (err == Z_BAD_PROPERTY) { 51480fbb751dSJohn Levon (void) fprintf(fp, "%s: \n", pt_to_str(PT_FS_ALLOWED)); 51490fbb751dSJohn Levon } else { 51500fbb751dSJohn Levon zone_perror(zone, err, B_TRUE); 51510fbb751dSJohn Levon } 51525679c89fSjv } 51535679c89fSjv 51547c478bd9Sstevel@tonic-gate static void 51557c478bd9Sstevel@tonic-gate output_fs(FILE *fp, struct zone_fstab *fstab) 51567c478bd9Sstevel@tonic-gate { 51577c478bd9Sstevel@tonic-gate zone_fsopt_t *this; 51587c478bd9Sstevel@tonic-gate 51597c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_FS)); 51607c478bd9Sstevel@tonic-gate output_prop(fp, PT_DIR, fstab->zone_fs_dir, B_TRUE); 51617c478bd9Sstevel@tonic-gate output_prop(fp, PT_SPECIAL, fstab->zone_fs_special, B_TRUE); 51627c478bd9Sstevel@tonic-gate output_prop(fp, PT_RAW, fstab->zone_fs_raw, B_TRUE); 51637c478bd9Sstevel@tonic-gate output_prop(fp, PT_TYPE, fstab->zone_fs_type, B_TRUE); 51647c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s: [", pt_to_str(PT_OPTIONS)); 51657c478bd9Sstevel@tonic-gate for (this = fstab->zone_fs_options; this != NULL; 51667c478bd9Sstevel@tonic-gate this = this->zone_fsopt_next) { 51677c478bd9Sstevel@tonic-gate if (strchr(this->zone_fsopt_opt, '=')) 51687c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\"%s\"", this->zone_fsopt_opt); 51697c478bd9Sstevel@tonic-gate else 51707c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s", this->zone_fsopt_opt); 51717c478bd9Sstevel@tonic-gate if (this->zone_fsopt_next != NULL) 51727c478bd9Sstevel@tonic-gate (void) fprintf(fp, ","); 51737c478bd9Sstevel@tonic-gate } 51747c478bd9Sstevel@tonic-gate (void) fprintf(fp, "]\n"); 51757c478bd9Sstevel@tonic-gate } 51767c478bd9Sstevel@tonic-gate 51777c478bd9Sstevel@tonic-gate static void 51787c478bd9Sstevel@tonic-gate info_fs(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 51797c478bd9Sstevel@tonic-gate { 51807c478bd9Sstevel@tonic-gate struct zone_fstab lookup, user; 5181bbec428eSgjelinek boolean_t output = B_FALSE; 51827c478bd9Sstevel@tonic-gate 51837c478bd9Sstevel@tonic-gate if (zonecfg_setfsent(handle) != Z_OK) 51847c478bd9Sstevel@tonic-gate return; 51857c478bd9Sstevel@tonic-gate while (zonecfg_getfsent(handle, &lookup) == Z_OK) { 51867c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 51877c478bd9Sstevel@tonic-gate output_fs(fp, &lookup); 51887c478bd9Sstevel@tonic-gate goto loopend; 51897c478bd9Sstevel@tonic-gate } 5190bbec428eSgjelinek if (fill_in_fstab(cmd, &user, B_TRUE) != Z_OK) 51917c478bd9Sstevel@tonic-gate goto loopend; 51927c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_dir) > 0 && 51937c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_dir, lookup.zone_fs_dir) != 0) 51947c478bd9Sstevel@tonic-gate goto loopend; /* no match */ 51957c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_special) > 0 && 51967c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_special, lookup.zone_fs_special) != 0) 51977c478bd9Sstevel@tonic-gate goto loopend; /* no match */ 51987c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_type) > 0 && 51997c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_type, lookup.zone_fs_type) != 0) 52007c478bd9Sstevel@tonic-gate goto loopend; /* no match */ 52017c478bd9Sstevel@tonic-gate output_fs(fp, &lookup); 5202bbec428eSgjelinek output = B_TRUE; 52037c478bd9Sstevel@tonic-gate loopend: 52047c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(lookup.zone_fs_options); 52057c478bd9Sstevel@tonic-gate } 52067c478bd9Sstevel@tonic-gate (void) zonecfg_endfsent(handle); 52077c478bd9Sstevel@tonic-gate /* 52087c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 52097c478bd9Sstevel@tonic-gate * nothing to output. 52107c478bd9Sstevel@tonic-gate */ 52117c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 52127c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 52137c478bd9Sstevel@tonic-gate rt_to_str(RT_FS)); 52147c478bd9Sstevel@tonic-gate } 52157c478bd9Sstevel@tonic-gate 52167c478bd9Sstevel@tonic-gate static void 52177c478bd9Sstevel@tonic-gate output_net(FILE *fp, struct zone_nwiftab *nwiftab) 52187c478bd9Sstevel@tonic-gate { 52197c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_NET)); 52207c478bd9Sstevel@tonic-gate output_prop(fp, PT_ADDRESS, nwiftab->zone_nwif_address, B_TRUE); 5221550b6e40SSowmini Varadhan output_prop(fp, PT_ALLOWED_ADDRESS, 5222550b6e40SSowmini Varadhan nwiftab->zone_nwif_allowed_address, B_TRUE); 52237c478bd9Sstevel@tonic-gate output_prop(fp, PT_PHYSICAL, nwiftab->zone_nwif_physical, B_TRUE); 5224de860bd9Sgfaden output_prop(fp, PT_DEFROUTER, nwiftab->zone_nwif_defrouter, B_TRUE); 52257c478bd9Sstevel@tonic-gate } 52267c478bd9Sstevel@tonic-gate 52277c478bd9Sstevel@tonic-gate static void 52287c478bd9Sstevel@tonic-gate info_net(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 52297c478bd9Sstevel@tonic-gate { 52307c478bd9Sstevel@tonic-gate struct zone_nwiftab lookup, user; 5231bbec428eSgjelinek boolean_t output = B_FALSE; 52327c478bd9Sstevel@tonic-gate 52337c478bd9Sstevel@tonic-gate if (zonecfg_setnwifent(handle) != Z_OK) 52347c478bd9Sstevel@tonic-gate return; 52357c478bd9Sstevel@tonic-gate while (zonecfg_getnwifent(handle, &lookup) == Z_OK) { 52367c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 52377c478bd9Sstevel@tonic-gate output_net(fp, &lookup); 52387c478bd9Sstevel@tonic-gate continue; 52397c478bd9Sstevel@tonic-gate } 5240bbec428eSgjelinek if (fill_in_nwiftab(cmd, &user, B_TRUE) != Z_OK) 52417c478bd9Sstevel@tonic-gate continue; 52427c478bd9Sstevel@tonic-gate if (strlen(user.zone_nwif_physical) > 0 && 52437c478bd9Sstevel@tonic-gate strcmp(user.zone_nwif_physical, 52447c478bd9Sstevel@tonic-gate lookup.zone_nwif_physical) != 0) 52457c478bd9Sstevel@tonic-gate continue; /* no match */ 5246f4b3ec61Sdh /* If present make sure it matches */ 52477c478bd9Sstevel@tonic-gate if (strlen(user.zone_nwif_address) > 0 && 52487c478bd9Sstevel@tonic-gate !zonecfg_same_net_address(user.zone_nwif_address, 52497c478bd9Sstevel@tonic-gate lookup.zone_nwif_address)) 52507c478bd9Sstevel@tonic-gate continue; /* no match */ 52517c478bd9Sstevel@tonic-gate output_net(fp, &lookup); 5252bbec428eSgjelinek output = B_TRUE; 52537c478bd9Sstevel@tonic-gate } 52547c478bd9Sstevel@tonic-gate (void) zonecfg_endnwifent(handle); 52557c478bd9Sstevel@tonic-gate /* 52567c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 52577c478bd9Sstevel@tonic-gate * nothing to output. 52587c478bd9Sstevel@tonic-gate */ 52597c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 52607c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 52617c478bd9Sstevel@tonic-gate rt_to_str(RT_NET)); 52627c478bd9Sstevel@tonic-gate } 52637c478bd9Sstevel@tonic-gate 52647c478bd9Sstevel@tonic-gate static void 52657c478bd9Sstevel@tonic-gate output_dev(FILE *fp, struct zone_devtab *devtab) 52667c478bd9Sstevel@tonic-gate { 526727e6fb21Sdp (void) fprintf(fp, "%s:\n", rt_to_str(RT_DEVICE)); 52687c478bd9Sstevel@tonic-gate output_prop(fp, PT_MATCH, devtab->zone_dev_match, B_TRUE); 52697c478bd9Sstevel@tonic-gate } 52707c478bd9Sstevel@tonic-gate 52717c478bd9Sstevel@tonic-gate static void 52727c478bd9Sstevel@tonic-gate info_dev(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 52737c478bd9Sstevel@tonic-gate { 52747c478bd9Sstevel@tonic-gate struct zone_devtab lookup, user; 5275bbec428eSgjelinek boolean_t output = B_FALSE; 52767c478bd9Sstevel@tonic-gate 52777c478bd9Sstevel@tonic-gate if (zonecfg_setdevent(handle) != Z_OK) 52787c478bd9Sstevel@tonic-gate return; 52797c478bd9Sstevel@tonic-gate while (zonecfg_getdevent(handle, &lookup) == Z_OK) { 52807c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 52817c478bd9Sstevel@tonic-gate output_dev(fp, &lookup); 52827c478bd9Sstevel@tonic-gate continue; 52837c478bd9Sstevel@tonic-gate } 5284bbec428eSgjelinek if (fill_in_devtab(cmd, &user, B_TRUE) != Z_OK) 52857c478bd9Sstevel@tonic-gate continue; 52867c478bd9Sstevel@tonic-gate if (strlen(user.zone_dev_match) > 0 && 52877c478bd9Sstevel@tonic-gate strcmp(user.zone_dev_match, lookup.zone_dev_match) != 0) 52887c478bd9Sstevel@tonic-gate continue; /* no match */ 52897c478bd9Sstevel@tonic-gate output_dev(fp, &lookup); 5290bbec428eSgjelinek output = B_TRUE; 52917c478bd9Sstevel@tonic-gate } 52927c478bd9Sstevel@tonic-gate (void) zonecfg_enddevent(handle); 52937c478bd9Sstevel@tonic-gate /* 52947c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 52957c478bd9Sstevel@tonic-gate * nothing to output. 52967c478bd9Sstevel@tonic-gate */ 52977c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 52987c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 52997c478bd9Sstevel@tonic-gate rt_to_str(RT_DEVICE)); 53007c478bd9Sstevel@tonic-gate } 53017c478bd9Sstevel@tonic-gate 53027c478bd9Sstevel@tonic-gate static void 53037c478bd9Sstevel@tonic-gate output_rctl(FILE *fp, struct zone_rctltab *rctltab) 53047c478bd9Sstevel@tonic-gate { 53057c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *valptr; 53067c478bd9Sstevel@tonic-gate 53077c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_RCTL)); 53087c478bd9Sstevel@tonic-gate output_prop(fp, PT_NAME, rctltab->zone_rctl_name, B_TRUE); 53097c478bd9Sstevel@tonic-gate for (valptr = rctltab->zone_rctl_valptr; valptr != NULL; 53107c478bd9Sstevel@tonic-gate valptr = valptr->zone_rctlval_next) { 53117c478bd9Sstevel@tonic-gate fprintf(fp, "\t%s: (%s=%s,%s=%s,%s=%s)\n", 53127c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), 53137c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV), valptr->zone_rctlval_priv, 53147c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT), valptr->zone_rctlval_limit, 53157c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION), valptr->zone_rctlval_action); 53167c478bd9Sstevel@tonic-gate } 53177c478bd9Sstevel@tonic-gate } 53187c478bd9Sstevel@tonic-gate 53197c478bd9Sstevel@tonic-gate static void 53207c478bd9Sstevel@tonic-gate info_rctl(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 53217c478bd9Sstevel@tonic-gate { 53227c478bd9Sstevel@tonic-gate struct zone_rctltab lookup, user; 5323bbec428eSgjelinek boolean_t output = B_FALSE; 53247c478bd9Sstevel@tonic-gate 53257c478bd9Sstevel@tonic-gate if (zonecfg_setrctlent(handle) != Z_OK) 53267c478bd9Sstevel@tonic-gate return; 53277c478bd9Sstevel@tonic-gate while (zonecfg_getrctlent(handle, &lookup) == Z_OK) { 53287c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 53297c478bd9Sstevel@tonic-gate output_rctl(fp, &lookup); 5330bbec428eSgjelinek } else if (fill_in_rctltab(cmd, &user, B_TRUE) == Z_OK && 53317c478bd9Sstevel@tonic-gate (strlen(user.zone_rctl_name) == 0 || 53327c478bd9Sstevel@tonic-gate strcmp(user.zone_rctl_name, lookup.zone_rctl_name) == 0)) { 53337c478bd9Sstevel@tonic-gate output_rctl(fp, &lookup); 5334bbec428eSgjelinek output = B_TRUE; 53357c478bd9Sstevel@tonic-gate } 53367c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(lookup.zone_rctl_valptr); 53377c478bd9Sstevel@tonic-gate } 53387c478bd9Sstevel@tonic-gate (void) zonecfg_endrctlent(handle); 53397c478bd9Sstevel@tonic-gate /* 53407c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 53417c478bd9Sstevel@tonic-gate * nothing to output. 53427c478bd9Sstevel@tonic-gate */ 53437c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 53447c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 53457c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL)); 53467c478bd9Sstevel@tonic-gate } 53477c478bd9Sstevel@tonic-gate 53487c478bd9Sstevel@tonic-gate static void 53497c478bd9Sstevel@tonic-gate output_attr(FILE *fp, struct zone_attrtab *attrtab) 53507c478bd9Sstevel@tonic-gate { 53517c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_ATTR)); 53527c478bd9Sstevel@tonic-gate output_prop(fp, PT_NAME, attrtab->zone_attr_name, B_TRUE); 53537c478bd9Sstevel@tonic-gate output_prop(fp, PT_TYPE, attrtab->zone_attr_type, B_TRUE); 53547c478bd9Sstevel@tonic-gate output_prop(fp, PT_VALUE, attrtab->zone_attr_value, B_TRUE); 53557c478bd9Sstevel@tonic-gate } 53567c478bd9Sstevel@tonic-gate 53577c478bd9Sstevel@tonic-gate static void 53587c478bd9Sstevel@tonic-gate info_attr(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 53597c478bd9Sstevel@tonic-gate { 53607c478bd9Sstevel@tonic-gate struct zone_attrtab lookup, user; 5361bbec428eSgjelinek boolean_t output = B_FALSE; 53627c478bd9Sstevel@tonic-gate 53637c478bd9Sstevel@tonic-gate if (zonecfg_setattrent(handle) != Z_OK) 53647c478bd9Sstevel@tonic-gate return; 53657c478bd9Sstevel@tonic-gate while (zonecfg_getattrent(handle, &lookup) == Z_OK) { 53667c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 53677c478bd9Sstevel@tonic-gate output_attr(fp, &lookup); 53687c478bd9Sstevel@tonic-gate continue; 53697c478bd9Sstevel@tonic-gate } 5370bbec428eSgjelinek if (fill_in_attrtab(cmd, &user, B_TRUE) != Z_OK) 53717c478bd9Sstevel@tonic-gate continue; 53727c478bd9Sstevel@tonic-gate if (strlen(user.zone_attr_name) > 0 && 53737c478bd9Sstevel@tonic-gate strcmp(user.zone_attr_name, lookup.zone_attr_name) != 0) 53747c478bd9Sstevel@tonic-gate continue; /* no match */ 53757c478bd9Sstevel@tonic-gate if (strlen(user.zone_attr_type) > 0 && 53767c478bd9Sstevel@tonic-gate strcmp(user.zone_attr_type, lookup.zone_attr_type) != 0) 53777c478bd9Sstevel@tonic-gate continue; /* no match */ 53787c478bd9Sstevel@tonic-gate if (strlen(user.zone_attr_value) > 0 && 53797c478bd9Sstevel@tonic-gate strcmp(user.zone_attr_value, lookup.zone_attr_value) != 0) 53807c478bd9Sstevel@tonic-gate continue; /* no match */ 53817c478bd9Sstevel@tonic-gate output_attr(fp, &lookup); 5382bbec428eSgjelinek output = B_TRUE; 53837c478bd9Sstevel@tonic-gate } 53847c478bd9Sstevel@tonic-gate (void) zonecfg_endattrent(handle); 53857c478bd9Sstevel@tonic-gate /* 53867c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 53877c478bd9Sstevel@tonic-gate * nothing to output. 53887c478bd9Sstevel@tonic-gate */ 53897c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 53907c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 53917c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR)); 53927c478bd9Sstevel@tonic-gate } 53937c478bd9Sstevel@tonic-gate 5394fa9e4066Sahrens static void 5395fa9e4066Sahrens output_ds(FILE *fp, struct zone_dstab *dstab) 5396fa9e4066Sahrens { 5397fa9e4066Sahrens (void) fprintf(fp, "%s:\n", rt_to_str(RT_DATASET)); 5398fa9e4066Sahrens output_prop(fp, PT_NAME, dstab->zone_dataset_name, B_TRUE); 5399fa9e4066Sahrens } 5400fa9e4066Sahrens 5401fa9e4066Sahrens static void 5402fa9e4066Sahrens info_ds(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 5403fa9e4066Sahrens { 5404fa9e4066Sahrens struct zone_dstab lookup, user; 5405bbec428eSgjelinek boolean_t output = B_FALSE; 5406fa9e4066Sahrens 54070209230bSgjelinek if (zonecfg_setdsent(handle) != Z_OK) 5408fa9e4066Sahrens return; 5409fa9e4066Sahrens while (zonecfg_getdsent(handle, &lookup) == Z_OK) { 5410fa9e4066Sahrens if (cmd->cmd_prop_nv_pairs == 0) { 5411fa9e4066Sahrens output_ds(fp, &lookup); 5412fa9e4066Sahrens continue; 5413fa9e4066Sahrens } 5414bbec428eSgjelinek if (fill_in_dstab(cmd, &user, B_TRUE) != Z_OK) 5415fa9e4066Sahrens continue; 5416fa9e4066Sahrens if (strlen(user.zone_dataset_name) > 0 && 5417fa9e4066Sahrens strcmp(user.zone_dataset_name, 5418fa9e4066Sahrens lookup.zone_dataset_name) != 0) 5419fa9e4066Sahrens continue; /* no match */ 5420fa9e4066Sahrens output_ds(fp, &lookup); 5421bbec428eSgjelinek output = B_TRUE; 5422fa9e4066Sahrens } 5423fa9e4066Sahrens (void) zonecfg_enddsent(handle); 5424fa9e4066Sahrens /* 5425fa9e4066Sahrens * If a property n/v pair was specified, warn the user if there was 5426fa9e4066Sahrens * nothing to output. 5427fa9e4066Sahrens */ 5428fa9e4066Sahrens if (!output && cmd->cmd_prop_nv_pairs > 0) 5429fa9e4066Sahrens (void) printf(gettext("No such %s resource.\n"), 5430fa9e4066Sahrens rt_to_str(RT_DATASET)); 5431fa9e4066Sahrens } 5432fa9e4066Sahrens 54330209230bSgjelinek static void 54340209230bSgjelinek output_pset(FILE *fp, struct zone_psettab *psettab) 54350209230bSgjelinek { 54360209230bSgjelinek (void) fprintf(fp, "%s:\n", rt_to_str(RT_DCPU)); 54370209230bSgjelinek if (strcmp(psettab->zone_ncpu_min, psettab->zone_ncpu_max) == 0) 54380209230bSgjelinek (void) fprintf(fp, "\t%s: %s\n", pt_to_str(PT_NCPUS), 54390209230bSgjelinek psettab->zone_ncpu_max); 54400209230bSgjelinek else 54410209230bSgjelinek (void) fprintf(fp, "\t%s: %s-%s\n", pt_to_str(PT_NCPUS), 54420209230bSgjelinek psettab->zone_ncpu_min, psettab->zone_ncpu_max); 54430209230bSgjelinek if (psettab->zone_importance[0] != '\0') 54440209230bSgjelinek (void) fprintf(fp, "\t%s: %s\n", pt_to_str(PT_IMPORTANCE), 54450209230bSgjelinek psettab->zone_importance); 54460209230bSgjelinek } 54470209230bSgjelinek 54480209230bSgjelinek static void 54490209230bSgjelinek info_pset(zone_dochandle_t handle, FILE *fp) 54500209230bSgjelinek { 54510209230bSgjelinek struct zone_psettab lookup; 54520209230bSgjelinek 54530209230bSgjelinek if (zonecfg_getpsetent(handle, &lookup) == Z_OK) 54540209230bSgjelinek output_pset(fp, &lookup); 54550209230bSgjelinek } 54560209230bSgjelinek 5457c97ad5cdSakolb static void 5458c97ad5cdSakolb output_pcap(FILE *fp) 5459c97ad5cdSakolb { 5460c97ad5cdSakolb uint64_t cap; 5461c97ad5cdSakolb 5462c97ad5cdSakolb if (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &cap) == Z_OK) { 5463c97ad5cdSakolb float scaled = (float)cap / 100; 5464c97ad5cdSakolb (void) fprintf(fp, "%s:\n", rt_to_str(RT_PCAP)); 5465c97ad5cdSakolb (void) fprintf(fp, "\t[%s: %.2f]\n", pt_to_str(PT_NCPUS), 5466c97ad5cdSakolb scaled); 5467c97ad5cdSakolb } 5468c97ad5cdSakolb } 5469c97ad5cdSakolb 5470c97ad5cdSakolb static void 5471c97ad5cdSakolb info_pcap(FILE *fp) 5472c97ad5cdSakolb { 5473c97ad5cdSakolb output_pcap(fp); 5474c97ad5cdSakolb } 5475c97ad5cdSakolb 5476c97ad5cdSakolb 54770209230bSgjelinek static void 54780209230bSgjelinek info_aliased_rctl(zone_dochandle_t handle, FILE *fp, char *alias) 54790209230bSgjelinek { 54800209230bSgjelinek uint64_t limit; 54810209230bSgjelinek 54820209230bSgjelinek if (zonecfg_get_aliased_rctl(handle, alias, &limit) == Z_OK) { 54830209230bSgjelinek /* convert memory based properties */ 54840209230bSgjelinek if (strcmp(alias, ALIAS_MAXSHMMEM) == 0) { 54850209230bSgjelinek char buf[128]; 54860209230bSgjelinek 54870209230bSgjelinek (void) snprintf(buf, sizeof (buf), "%llu", limit); 54880209230bSgjelinek bytes_to_units(buf, buf, sizeof (buf)); 54890209230bSgjelinek (void) fprintf(fp, "[%s: %s]\n", alias, buf); 54900209230bSgjelinek return; 54910209230bSgjelinek } 54920209230bSgjelinek 54930209230bSgjelinek (void) fprintf(fp, "[%s: %llu]\n", alias, limit); 54940209230bSgjelinek } 54950209230bSgjelinek } 54960209230bSgjelinek 54970209230bSgjelinek static void 54980209230bSgjelinek bytes_to_units(char *str, char *buf, int bufsize) 54990209230bSgjelinek { 55000209230bSgjelinek unsigned long long num; 55010209230bSgjelinek unsigned long long save = 0; 55020209230bSgjelinek char *units = "BKMGT"; 55030209230bSgjelinek char *up = units; 55040209230bSgjelinek 55050209230bSgjelinek num = strtoll(str, NULL, 10); 55060209230bSgjelinek 55070209230bSgjelinek if (num < 1024) { 55080209230bSgjelinek (void) snprintf(buf, bufsize, "%llu", num); 55090209230bSgjelinek return; 55100209230bSgjelinek } 55110209230bSgjelinek 55120209230bSgjelinek while ((num >= 1024) && (*up != 'T')) { 55130209230bSgjelinek up++; /* next unit of measurement */ 55140209230bSgjelinek save = num; 55150209230bSgjelinek num = (num + 512) >> 10; 55160209230bSgjelinek } 55170209230bSgjelinek 55180209230bSgjelinek /* check if we should output a fraction. snprintf will round for us */ 55190209230bSgjelinek if (save % 1024 != 0 && ((save >> 10) < 10)) 55200209230bSgjelinek (void) snprintf(buf, bufsize, "%2.1f%c", ((float)save / 1024), 55210209230bSgjelinek *up); 55220209230bSgjelinek else 55230209230bSgjelinek (void) snprintf(buf, bufsize, "%llu%c", num, *up); 55240209230bSgjelinek } 55250209230bSgjelinek 55260209230bSgjelinek static void 55270209230bSgjelinek output_mcap(FILE *fp, struct zone_mcaptab *mcaptab, int showswap, 55280209230bSgjelinek uint64_t maxswap, int showlocked, uint64_t maxlocked) 55290209230bSgjelinek { 55300209230bSgjelinek char buf[128]; 55310209230bSgjelinek 55320209230bSgjelinek (void) fprintf(fp, "%s:\n", rt_to_str(RT_MCAP)); 55330209230bSgjelinek if (mcaptab->zone_physmem_cap[0] != '\0') { 55340209230bSgjelinek bytes_to_units(mcaptab->zone_physmem_cap, buf, sizeof (buf)); 55350209230bSgjelinek output_prop(fp, PT_PHYSICAL, buf, B_TRUE); 55360209230bSgjelinek } 55370209230bSgjelinek 55380209230bSgjelinek if (showswap == Z_OK) { 55390209230bSgjelinek (void) snprintf(buf, sizeof (buf), "%llu", maxswap); 55400209230bSgjelinek bytes_to_units(buf, buf, sizeof (buf)); 55410209230bSgjelinek output_prop(fp, PT_SWAP, buf, B_TRUE); 55420209230bSgjelinek } 55430209230bSgjelinek 55440209230bSgjelinek if (showlocked == Z_OK) { 55450209230bSgjelinek (void) snprintf(buf, sizeof (buf), "%llu", maxlocked); 55460209230bSgjelinek bytes_to_units(buf, buf, sizeof (buf)); 55470209230bSgjelinek output_prop(fp, PT_LOCKED, buf, B_TRUE); 55480209230bSgjelinek } 55490209230bSgjelinek } 55500209230bSgjelinek 55510209230bSgjelinek static void 55520209230bSgjelinek info_mcap(zone_dochandle_t handle, FILE *fp) 55530209230bSgjelinek { 55540209230bSgjelinek int res1, res2, res3; 55550209230bSgjelinek uint64_t swap_limit; 55560209230bSgjelinek uint64_t locked_limit; 55570209230bSgjelinek struct zone_mcaptab lookup; 55580209230bSgjelinek 55590209230bSgjelinek bzero(&lookup, sizeof (lookup)); 55600209230bSgjelinek res1 = zonecfg_getmcapent(handle, &lookup); 55610209230bSgjelinek res2 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, &swap_limit); 55620209230bSgjelinek res3 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, 55630209230bSgjelinek &locked_limit); 55640209230bSgjelinek 55650209230bSgjelinek if (res1 == Z_OK || res2 == Z_OK || res3 == Z_OK) 55660209230bSgjelinek output_mcap(fp, &lookup, res2, swap_limit, res3, locked_limit); 55670209230bSgjelinek } 55680209230bSgjelinek 5569cb8a054bSGlenn Faden static void 5570cb8a054bSGlenn Faden output_auth(FILE *fp, struct zone_admintab *admintab) 5571cb8a054bSGlenn Faden { 5572cb8a054bSGlenn Faden (void) fprintf(fp, "%s:\n", rt_to_str(RT_ADMIN)); 5573cb8a054bSGlenn Faden output_prop(fp, PT_USER, admintab->zone_admin_user, B_TRUE); 5574cb8a054bSGlenn Faden output_prop(fp, PT_AUTHS, admintab->zone_admin_auths, B_TRUE); 5575cb8a054bSGlenn Faden } 5576cb8a054bSGlenn Faden 5577*d2a70789SRichard Lowe static void 5578*d2a70789SRichard Lowe output_secflags(FILE *fp, struct zone_secflagstab *sftab) 5579*d2a70789SRichard Lowe { 5580*d2a70789SRichard Lowe (void) fprintf(fp, "%s:\n", rt_to_str(RT_SECFLAGS)); 5581*d2a70789SRichard Lowe output_prop(fp, PT_DEFAULT, sftab->zone_secflags_default, B_TRUE); 5582*d2a70789SRichard Lowe output_prop(fp, PT_LOWER, sftab->zone_secflags_lower, B_TRUE); 5583*d2a70789SRichard Lowe output_prop(fp, PT_UPPER, sftab->zone_secflags_upper, B_TRUE); 5584*d2a70789SRichard Lowe } 5585*d2a70789SRichard Lowe 5586cb8a054bSGlenn Faden static void 5587cb8a054bSGlenn Faden info_auth(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 5588cb8a054bSGlenn Faden { 5589cb8a054bSGlenn Faden struct zone_admintab lookup, user; 5590cb8a054bSGlenn Faden boolean_t output = B_FALSE; 5591cb8a054bSGlenn Faden int err; 5592cb8a054bSGlenn Faden 5593cb8a054bSGlenn Faden if ((err = zonecfg_setadminent(handle)) != Z_OK) { 5594cb8a054bSGlenn Faden zone_perror(zone, err, B_TRUE); 5595cb8a054bSGlenn Faden return; 5596cb8a054bSGlenn Faden } 5597cb8a054bSGlenn Faden while (zonecfg_getadminent(handle, &lookup) == Z_OK) { 5598cb8a054bSGlenn Faden if (cmd->cmd_prop_nv_pairs == 0) { 5599cb8a054bSGlenn Faden output_auth(fp, &lookup); 5600cb8a054bSGlenn Faden continue; 5601cb8a054bSGlenn Faden } 5602cb8a054bSGlenn Faden if (fill_in_admintab(cmd, &user, B_TRUE) != Z_OK) 5603cb8a054bSGlenn Faden continue; 5604cb8a054bSGlenn Faden if (strlen(user.zone_admin_user) > 0 && 5605cb8a054bSGlenn Faden strcmp(user.zone_admin_user, lookup.zone_admin_user) != 0) 5606cb8a054bSGlenn Faden continue; /* no match */ 5607cb8a054bSGlenn Faden output_auth(fp, &lookup); 5608cb8a054bSGlenn Faden output = B_TRUE; 5609cb8a054bSGlenn Faden } 5610cb8a054bSGlenn Faden (void) zonecfg_endadminent(handle); 5611cb8a054bSGlenn Faden /* 5612cb8a054bSGlenn Faden * If a property n/v pair was specified, warn the user if there was 5613cb8a054bSGlenn Faden * nothing to output. 5614cb8a054bSGlenn Faden */ 5615cb8a054bSGlenn Faden if (!output && cmd->cmd_prop_nv_pairs > 0) 5616cb8a054bSGlenn Faden (void) printf(gettext("No such %s resource.\n"), 5617cb8a054bSGlenn Faden rt_to_str(RT_ADMIN)); 5618cb8a054bSGlenn Faden } 5619cb8a054bSGlenn Faden 5620*d2a70789SRichard Lowe static void 5621*d2a70789SRichard Lowe info_secflags(zone_dochandle_t handle, FILE *fp) 5622*d2a70789SRichard Lowe { 5623*d2a70789SRichard Lowe struct zone_secflagstab sftab; 5624*d2a70789SRichard Lowe 5625*d2a70789SRichard Lowe if (zonecfg_lookup_secflags(handle, &sftab) == Z_OK) { 5626*d2a70789SRichard Lowe output_secflags(fp, &sftab); 5627*d2a70789SRichard Lowe } 5628*d2a70789SRichard Lowe } 5629*d2a70789SRichard Lowe 56307c478bd9Sstevel@tonic-gate void 56317c478bd9Sstevel@tonic-gate info_func(cmd_t *cmd) 56327c478bd9Sstevel@tonic-gate { 56337c478bd9Sstevel@tonic-gate FILE *fp = stdout; 5634bbec428eSgjelinek boolean_t need_to_close = B_FALSE; 56350209230bSgjelinek int type; 56360209230bSgjelinek int res1, res2; 56370209230bSgjelinek uint64_t swap_limit; 56380209230bSgjelinek uint64_t locked_limit; 56397c478bd9Sstevel@tonic-gate 56407c478bd9Sstevel@tonic-gate assert(cmd != NULL); 56417c478bd9Sstevel@tonic-gate 5642bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 56437c478bd9Sstevel@tonic-gate return; 56447c478bd9Sstevel@tonic-gate 56457c478bd9Sstevel@tonic-gate /* don't page error output */ 56467c478bd9Sstevel@tonic-gate if (interactive_mode) { 5647944b13ecSGary Mills if ((fp = pager_open()) != NULL) 5648944b13ecSGary Mills need_to_close = B_TRUE; 5649944b13ecSGary Mills else 5650944b13ecSGary Mills fp = stdout; 56513042b8b5Sbatschul 56527c478bd9Sstevel@tonic-gate setbuf(fp, NULL); 56537c478bd9Sstevel@tonic-gate } 56547c478bd9Sstevel@tonic-gate 56557c478bd9Sstevel@tonic-gate if (!global_scope) { 56567c478bd9Sstevel@tonic-gate switch (resource_scope) { 56577c478bd9Sstevel@tonic-gate case RT_FS: 56587c478bd9Sstevel@tonic-gate output_fs(fp, &in_progress_fstab); 56597c478bd9Sstevel@tonic-gate break; 56607c478bd9Sstevel@tonic-gate case RT_NET: 56617c478bd9Sstevel@tonic-gate output_net(fp, &in_progress_nwiftab); 56627c478bd9Sstevel@tonic-gate break; 56637c478bd9Sstevel@tonic-gate case RT_DEVICE: 56647c478bd9Sstevel@tonic-gate output_dev(fp, &in_progress_devtab); 56657c478bd9Sstevel@tonic-gate break; 56667c478bd9Sstevel@tonic-gate case RT_RCTL: 56677c478bd9Sstevel@tonic-gate output_rctl(fp, &in_progress_rctltab); 56687c478bd9Sstevel@tonic-gate break; 56697c478bd9Sstevel@tonic-gate case RT_ATTR: 56707c478bd9Sstevel@tonic-gate output_attr(fp, &in_progress_attrtab); 56717c478bd9Sstevel@tonic-gate break; 5672fa9e4066Sahrens case RT_DATASET: 5673fa9e4066Sahrens output_ds(fp, &in_progress_dstab); 5674fa9e4066Sahrens break; 56750209230bSgjelinek case RT_DCPU: 56760209230bSgjelinek output_pset(fp, &in_progress_psettab); 56770209230bSgjelinek break; 5678c97ad5cdSakolb case RT_PCAP: 5679c97ad5cdSakolb output_pcap(fp); 5680c97ad5cdSakolb break; 56810209230bSgjelinek case RT_MCAP: 56820209230bSgjelinek res1 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, 56830209230bSgjelinek &swap_limit); 56840209230bSgjelinek res2 = zonecfg_get_aliased_rctl(handle, 56850209230bSgjelinek ALIAS_MAXLOCKEDMEM, &locked_limit); 56860209230bSgjelinek output_mcap(fp, &in_progress_mcaptab, res1, swap_limit, 56870209230bSgjelinek res2, locked_limit); 56880209230bSgjelinek break; 5689cb8a054bSGlenn Faden case RT_ADMIN: 5690cb8a054bSGlenn Faden output_auth(fp, &in_progress_admintab); 5691cb8a054bSGlenn Faden break; 5692*d2a70789SRichard Lowe case RT_SECFLAGS: 5693*d2a70789SRichard Lowe output_secflags(fp, &in_progress_secflagstab); 5694*d2a70789SRichard Lowe break; 56957c478bd9Sstevel@tonic-gate } 56967c478bd9Sstevel@tonic-gate goto cleanup; 56977c478bd9Sstevel@tonic-gate } 56987c478bd9Sstevel@tonic-gate 56990209230bSgjelinek type = cmd->cmd_res_type; 57000209230bSgjelinek 57010209230bSgjelinek if (gz_invalid_rt_property(type)) { 57020209230bSgjelinek zerr(gettext("%s is not a valid property for the global zone."), 57030209230bSgjelinek rt_to_str(type)); 57040209230bSgjelinek goto cleanup; 57050209230bSgjelinek } 57060209230bSgjelinek 57070209230bSgjelinek if (gz_invalid_resource(type)) { 57080209230bSgjelinek zerr(gettext("%s is not a valid resource for the global zone."), 57090209230bSgjelinek rt_to_str(type)); 57100209230bSgjelinek goto cleanup; 57110209230bSgjelinek } 57120209230bSgjelinek 57137c478bd9Sstevel@tonic-gate switch (cmd->cmd_res_type) { 57147c478bd9Sstevel@tonic-gate case RT_UNKNOWN: 5715087719fdSdp info_zonename(handle, fp); 57160209230bSgjelinek if (!global_zone) { 57170209230bSgjelinek info_zonepath(handle, fp); 57180209230bSgjelinek info_brand(handle, fp); 57190209230bSgjelinek info_autoboot(handle, fp); 57200209230bSgjelinek info_bootargs(handle, fp); 57210209230bSgjelinek } 57227c478bd9Sstevel@tonic-gate info_pool(handle, fp); 57230209230bSgjelinek if (!global_zone) { 57240209230bSgjelinek info_limitpriv(handle, fp); 57250209230bSgjelinek info_sched(handle, fp); 5726f4b3ec61Sdh info_iptype(handle, fp); 57275679c89fSjv info_hostid(handle, fp); 57280fbb751dSJohn Levon info_fs_allowed(handle, fp); 57290209230bSgjelinek } 57300209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXLWPS); 5731ff19e029SMenno Lageman info_aliased_rctl(handle, fp, ALIAS_MAXPROCS); 57320209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSHMMEM); 57330209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSHMIDS); 57340209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXMSGIDS); 57350209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSEMIDS); 57360209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_SHARES); 57370209230bSgjelinek if (!global_zone) { 57380209230bSgjelinek info_fs(handle, fp, cmd); 57390209230bSgjelinek info_net(handle, fp, cmd); 57400209230bSgjelinek info_dev(handle, fp, cmd); 57410209230bSgjelinek } 57420209230bSgjelinek info_pset(handle, fp); 5743c97ad5cdSakolb info_pcap(fp); 57440209230bSgjelinek info_mcap(handle, fp); 57450209230bSgjelinek if (!global_zone) { 57460209230bSgjelinek info_attr(handle, fp, cmd); 57470209230bSgjelinek info_ds(handle, fp, cmd); 5748cb8a054bSGlenn Faden info_auth(handle, fp, cmd); 57490209230bSgjelinek } 57507c478bd9Sstevel@tonic-gate info_rctl(handle, fp, cmd); 5751*d2a70789SRichard Lowe info_secflags(handle, fp); 57527c478bd9Sstevel@tonic-gate break; 5753087719fdSdp case RT_ZONENAME: 5754087719fdSdp info_zonename(handle, fp); 5755087719fdSdp break; 57567c478bd9Sstevel@tonic-gate case RT_ZONEPATH: 57577c478bd9Sstevel@tonic-gate info_zonepath(handle, fp); 57587c478bd9Sstevel@tonic-gate break; 57599acbbeafSnn case RT_BRAND: 57609acbbeafSnn info_brand(handle, fp); 57619acbbeafSnn break; 57627c478bd9Sstevel@tonic-gate case RT_AUTOBOOT: 57637c478bd9Sstevel@tonic-gate info_autoboot(handle, fp); 57647c478bd9Sstevel@tonic-gate break; 57657c478bd9Sstevel@tonic-gate case RT_POOL: 57667c478bd9Sstevel@tonic-gate info_pool(handle, fp); 57677c478bd9Sstevel@tonic-gate break; 5768ffbafc53Scomay case RT_LIMITPRIV: 5769ffbafc53Scomay info_limitpriv(handle, fp); 5770ffbafc53Scomay break; 57713f2f09c1Sdp case RT_BOOTARGS: 57723f2f09c1Sdp info_bootargs(handle, fp); 57733f2f09c1Sdp break; 57740209230bSgjelinek case RT_SCHED: 57750209230bSgjelinek info_sched(handle, fp); 57760209230bSgjelinek break; 5777f4b3ec61Sdh case RT_IPTYPE: 5778f4b3ec61Sdh info_iptype(handle, fp); 5779f4b3ec61Sdh break; 57800209230bSgjelinek case RT_MAXLWPS: 57810209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXLWPS); 57820209230bSgjelinek break; 5783ff19e029SMenno Lageman case RT_MAXPROCS: 5784ff19e029SMenno Lageman info_aliased_rctl(handle, fp, ALIAS_MAXPROCS); 5785ff19e029SMenno Lageman break; 57860209230bSgjelinek case RT_MAXSHMMEM: 57870209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSHMMEM); 57880209230bSgjelinek break; 57890209230bSgjelinek case RT_MAXSHMIDS: 57900209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSHMIDS); 57910209230bSgjelinek break; 57920209230bSgjelinek case RT_MAXMSGIDS: 57930209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXMSGIDS); 57940209230bSgjelinek break; 57950209230bSgjelinek case RT_MAXSEMIDS: 57960209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSEMIDS); 57970209230bSgjelinek break; 57980209230bSgjelinek case RT_SHARES: 57990209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_SHARES); 58000209230bSgjelinek break; 58017c478bd9Sstevel@tonic-gate case RT_FS: 58027c478bd9Sstevel@tonic-gate info_fs(handle, fp, cmd); 58037c478bd9Sstevel@tonic-gate break; 58047c478bd9Sstevel@tonic-gate case RT_NET: 58057c478bd9Sstevel@tonic-gate info_net(handle, fp, cmd); 58067c478bd9Sstevel@tonic-gate break; 58077c478bd9Sstevel@tonic-gate case RT_DEVICE: 58087c478bd9Sstevel@tonic-gate info_dev(handle, fp, cmd); 58097c478bd9Sstevel@tonic-gate break; 58107c478bd9Sstevel@tonic-gate case RT_RCTL: 58117c478bd9Sstevel@tonic-gate info_rctl(handle, fp, cmd); 58127c478bd9Sstevel@tonic-gate break; 58137c478bd9Sstevel@tonic-gate case RT_ATTR: 58147c478bd9Sstevel@tonic-gate info_attr(handle, fp, cmd); 58157c478bd9Sstevel@tonic-gate break; 5816fa9e4066Sahrens case RT_DATASET: 5817fa9e4066Sahrens info_ds(handle, fp, cmd); 5818fa9e4066Sahrens break; 58190209230bSgjelinek case RT_DCPU: 58200209230bSgjelinek info_pset(handle, fp); 58210209230bSgjelinek break; 5822c97ad5cdSakolb case RT_PCAP: 5823c97ad5cdSakolb info_pcap(fp); 5824c97ad5cdSakolb break; 58250209230bSgjelinek case RT_MCAP: 58260209230bSgjelinek info_mcap(handle, fp); 58270209230bSgjelinek break; 58285679c89fSjv case RT_HOSTID: 58295679c89fSjv info_hostid(handle, fp); 58305679c89fSjv break; 5831cb8a054bSGlenn Faden case RT_ADMIN: 5832cb8a054bSGlenn Faden info_auth(handle, fp, cmd); 5833cb8a054bSGlenn Faden break; 58340fbb751dSJohn Levon case RT_FS_ALLOWED: 58350fbb751dSJohn Levon info_fs_allowed(handle, fp); 58360fbb751dSJohn Levon break; 5837*d2a70789SRichard Lowe case RT_SECFLAGS: 5838*d2a70789SRichard Lowe info_secflags(handle, fp); 5839*d2a70789SRichard Lowe break; 58407c478bd9Sstevel@tonic-gate default: 58417c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(cmd->cmd_res_type), Z_NO_RESOURCE_TYPE, 5842bbec428eSgjelinek B_TRUE); 58437c478bd9Sstevel@tonic-gate } 58447c478bd9Sstevel@tonic-gate 58457c478bd9Sstevel@tonic-gate cleanup: 58467c478bd9Sstevel@tonic-gate if (need_to_close) 5847944b13ecSGary Mills (void) pager_close(fp); 58487c478bd9Sstevel@tonic-gate } 58497c478bd9Sstevel@tonic-gate 5850087719fdSdp /* 5851087719fdSdp * Helper function for verify-- checks that a required string property 5852087719fdSdp * exists. 5853087719fdSdp */ 5854087719fdSdp static void 5855087719fdSdp check_reqd_prop(char *attr, int rt, int pt, int *ret_val) 58567c478bd9Sstevel@tonic-gate { 5857087719fdSdp if (strlen(attr) == 0) { 5858087719fdSdp zerr(gettext("%s: %s not specified"), rt_to_str(rt), 5859087719fdSdp pt_to_str(pt)); 5860bbec428eSgjelinek saw_error = B_TRUE; 5861087719fdSdp if (*ret_val == Z_OK) 5862087719fdSdp *ret_val = Z_REQD_PROPERTY_MISSING; 58637c478bd9Sstevel@tonic-gate } 58647c478bd9Sstevel@tonic-gate } 58657c478bd9Sstevel@tonic-gate 58669acbbeafSnn static int 58679acbbeafSnn do_subproc(char *cmdbuf) 58689acbbeafSnn { 58699acbbeafSnn char inbuf[MAX_CMD_LEN]; 58709acbbeafSnn FILE *file; 58719acbbeafSnn int status; 58729acbbeafSnn 58739acbbeafSnn file = popen(cmdbuf, "r"); 58749acbbeafSnn if (file == NULL) { 58759acbbeafSnn zerr(gettext("Could not launch: %s"), cmdbuf); 58769acbbeafSnn return (-1); 58779acbbeafSnn } 58789acbbeafSnn 58799acbbeafSnn while (fgets(inbuf, sizeof (inbuf), file) != NULL) 58809acbbeafSnn fprintf(stderr, "%s", inbuf); 58819acbbeafSnn status = pclose(file); 58829acbbeafSnn 58839acbbeafSnn if (WIFSIGNALED(status)) { 58849acbbeafSnn zerr(gettext("%s unexpectedly terminated due to signal %d"), 58859acbbeafSnn cmdbuf, WTERMSIG(status)); 58869acbbeafSnn return (-1); 58879acbbeafSnn } 58889acbbeafSnn assert(WIFEXITED(status)); 58899acbbeafSnn return (WEXITSTATUS(status)); 58909acbbeafSnn } 58919acbbeafSnn 58929acbbeafSnn static int 58939acbbeafSnn brand_verify(zone_dochandle_t handle) 58949acbbeafSnn { 58956e65f9afSnn char xml_file[32]; 58969acbbeafSnn char cmdbuf[MAX_CMD_LEN]; 5897123807fbSedp brand_handle_t bh; 58989acbbeafSnn char brand[MAXNAMELEN]; 58999acbbeafSnn int err; 59009acbbeafSnn 59019acbbeafSnn if (zonecfg_get_brand(handle, brand, sizeof (brand)) != Z_OK) { 59029acbbeafSnn zerr("%s: %s\n", zone, gettext("could not get zone brand")); 59039acbbeafSnn return (Z_INVALID_DOCUMENT); 59049acbbeafSnn } 5905123807fbSedp if ((bh = brand_open(brand)) == NULL) { 59069acbbeafSnn zerr("%s: %s\n", zone, gettext("unknown brand.")); 59079acbbeafSnn return (Z_INVALID_DOCUMENT); 59089acbbeafSnn } 59099acbbeafSnn 59109acbbeafSnn /* 59119acbbeafSnn * Fetch the verify command, if any, from the brand configuration 59129acbbeafSnn * and build the command line to execute it. 59139acbbeafSnn */ 59149acbbeafSnn strcpy(cmdbuf, EXEC_PREFIX); 5915123807fbSedp err = brand_get_verify_cfg(bh, cmdbuf + EXEC_LEN, 59169acbbeafSnn sizeof (cmdbuf) - (EXEC_LEN + (strlen(xml_file) + 1))); 5917123807fbSedp brand_close(bh); 59189acbbeafSnn if (err != Z_OK) { 59199acbbeafSnn zerr("%s: %s\n", zone, 59209acbbeafSnn gettext("could not get brand verification command")); 59219acbbeafSnn return (Z_INVALID_DOCUMENT); 59229acbbeafSnn } 59239acbbeafSnn 59249acbbeafSnn /* 59259acbbeafSnn * If the brand doesn't provide a verification routine, we just 59269acbbeafSnn * return success. 59279acbbeafSnn */ 59289acbbeafSnn if (strlen(cmdbuf) == EXEC_LEN) 59299acbbeafSnn return (Z_OK); 59309acbbeafSnn 59319acbbeafSnn /* 59329acbbeafSnn * Dump the current config information for this zone to a file. 59339acbbeafSnn */ 59346e65f9afSnn strcpy(xml_file, "/tmp/zonecfg_verify.XXXXXX"); 59359acbbeafSnn if (mkstemp(xml_file) == NULL) 59369acbbeafSnn return (Z_TEMP_FILE); 59379acbbeafSnn if ((err = zonecfg_verify_save(handle, xml_file)) != Z_OK) { 59389acbbeafSnn (void) unlink(xml_file); 59399acbbeafSnn return (err); 59409acbbeafSnn } 59419acbbeafSnn 59429acbbeafSnn /* 59439acbbeafSnn * Execute the verification command. 59449acbbeafSnn */ 59459acbbeafSnn if ((strlcat(cmdbuf, " ", MAX_CMD_LEN) >= MAX_CMD_LEN) || 59469acbbeafSnn (strlcat(cmdbuf, xml_file, MAX_CMD_LEN) >= MAX_CMD_LEN)) { 59479acbbeafSnn err = Z_BRAND_ERROR; 59489acbbeafSnn } else { 59499acbbeafSnn err = do_subproc(cmdbuf); 59509acbbeafSnn } 59519acbbeafSnn 59529acbbeafSnn (void) unlink(xml_file); 59539acbbeafSnn return ((err == Z_OK) ? Z_OK : Z_BRAND_ERROR); 59549acbbeafSnn } 59559acbbeafSnn 5956550b6e40SSowmini Varadhan /* 5957550b6e40SSowmini Varadhan * Track the network interfaces listed in zonecfg(1m) in a linked list 5958550b6e40SSowmini Varadhan * so that we can later check that defrouter is specified for an exclusive IP 5959550b6e40SSowmini Varadhan * zone if and only if at least one allowed-address has been specified. 5960550b6e40SSowmini Varadhan */ 5961550b6e40SSowmini Varadhan static boolean_t 5962550b6e40SSowmini Varadhan add_nwif(struct zone_nwiftab *nwif) 5963550b6e40SSowmini Varadhan { 5964550b6e40SSowmini Varadhan struct xif *tmp; 5965550b6e40SSowmini Varadhan 5966550b6e40SSowmini Varadhan for (tmp = xif; tmp != NULL; tmp = tmp->xif_next) { 5967550b6e40SSowmini Varadhan if (strcmp(tmp->xif_name, nwif->zone_nwif_physical) == 0) { 5968550b6e40SSowmini Varadhan if (strlen(nwif->zone_nwif_allowed_address) > 0) 5969550b6e40SSowmini Varadhan tmp->xif_has_address = B_TRUE; 5970550b6e40SSowmini Varadhan if (strlen(nwif->zone_nwif_defrouter) > 0) 5971550b6e40SSowmini Varadhan tmp->xif_has_defrouter = B_TRUE; 5972550b6e40SSowmini Varadhan return (B_TRUE); 5973550b6e40SSowmini Varadhan } 5974550b6e40SSowmini Varadhan } 5975550b6e40SSowmini Varadhan 5976550b6e40SSowmini Varadhan tmp = malloc(sizeof (*tmp)); 5977550b6e40SSowmini Varadhan if (tmp == NULL) { 5978550b6e40SSowmini Varadhan zerr(gettext("memory allocation failed for %s"), 5979550b6e40SSowmini Varadhan nwif->zone_nwif_physical); 5980550b6e40SSowmini Varadhan return (B_FALSE); 5981550b6e40SSowmini Varadhan } 5982550b6e40SSowmini Varadhan strlcpy(tmp->xif_name, nwif->zone_nwif_physical, 5983550b6e40SSowmini Varadhan sizeof (tmp->xif_name)); 5984550b6e40SSowmini Varadhan tmp->xif_has_defrouter = (strlen(nwif->zone_nwif_defrouter) > 0); 5985550b6e40SSowmini Varadhan tmp->xif_has_address = (strlen(nwif->zone_nwif_allowed_address) > 0); 5986550b6e40SSowmini Varadhan tmp->xif_next = xif; 5987550b6e40SSowmini Varadhan xif = tmp; 5988550b6e40SSowmini Varadhan return (B_TRUE); 5989550b6e40SSowmini Varadhan } 5990550b6e40SSowmini Varadhan 5991*d2a70789SRichard Lowe boolean_t 5992*d2a70789SRichard Lowe verify_secflags(struct zone_secflagstab *tab) 5993*d2a70789SRichard Lowe { 5994*d2a70789SRichard Lowe secflagdelta_t def = {0}; 5995*d2a70789SRichard Lowe secflagdelta_t upper = {0}; 5996*d2a70789SRichard Lowe secflagdelta_t lower = {0}; 5997*d2a70789SRichard Lowe boolean_t def_set = B_FALSE; 5998*d2a70789SRichard Lowe boolean_t upper_set = B_FALSE; 5999*d2a70789SRichard Lowe boolean_t lower_set = B_FALSE; 6000*d2a70789SRichard Lowe boolean_t ret = B_TRUE; 6001*d2a70789SRichard Lowe 6002*d2a70789SRichard Lowe if (strlen(tab->zone_secflags_default) > 0) { 6003*d2a70789SRichard Lowe def_set = B_TRUE; 6004*d2a70789SRichard Lowe if (secflags_parse(NULL, tab->zone_secflags_default, 6005*d2a70789SRichard Lowe &def) == -1) { 6006*d2a70789SRichard Lowe zerr(gettext("default security flags '%s' are invalid"), 6007*d2a70789SRichard Lowe tab->zone_secflags_default); 6008*d2a70789SRichard Lowe ret = B_FALSE; 6009*d2a70789SRichard Lowe } 6010*d2a70789SRichard Lowe } else { 6011*d2a70789SRichard Lowe secflags_zero(&def.psd_assign); 6012*d2a70789SRichard Lowe def.psd_ass_active = B_TRUE; 6013*d2a70789SRichard Lowe } 6014*d2a70789SRichard Lowe 6015*d2a70789SRichard Lowe if (strlen(tab->zone_secflags_upper) > 0) { 6016*d2a70789SRichard Lowe upper_set = B_TRUE; 6017*d2a70789SRichard Lowe if (secflags_parse(NULL, tab->zone_secflags_upper, 6018*d2a70789SRichard Lowe &upper) == -1) { 6019*d2a70789SRichard Lowe zerr(gettext("upper security flags '%s' are invalid"), 6020*d2a70789SRichard Lowe tab->zone_secflags_upper); 6021*d2a70789SRichard Lowe ret = B_FALSE; 6022*d2a70789SRichard Lowe } 6023*d2a70789SRichard Lowe } else { 6024*d2a70789SRichard Lowe secflags_fullset(&upper.psd_assign); 6025*d2a70789SRichard Lowe upper.psd_ass_active = B_TRUE; 6026*d2a70789SRichard Lowe } 6027*d2a70789SRichard Lowe 6028*d2a70789SRichard Lowe if (strlen(tab->zone_secflags_lower) > 0) { 6029*d2a70789SRichard Lowe lower_set = B_TRUE; 6030*d2a70789SRichard Lowe if (secflags_parse(NULL, tab->zone_secflags_lower, 6031*d2a70789SRichard Lowe &lower) == -1) { 6032*d2a70789SRichard Lowe zerr(gettext("lower security flags '%s' are invalid"), 6033*d2a70789SRichard Lowe tab->zone_secflags_lower); 6034*d2a70789SRichard Lowe ret = B_FALSE; 6035*d2a70789SRichard Lowe } 6036*d2a70789SRichard Lowe } else { 6037*d2a70789SRichard Lowe secflags_zero(&lower.psd_assign); 6038*d2a70789SRichard Lowe lower.psd_ass_active = B_TRUE; 6039*d2a70789SRichard Lowe } 6040*d2a70789SRichard Lowe 6041*d2a70789SRichard Lowe if (def_set && !def.psd_ass_active) { 6042*d2a70789SRichard Lowe zerr(gettext("only assignment of security flags is " 6043*d2a70789SRichard Lowe "allowed (default: %s)"), tab->zone_secflags_default); 6044*d2a70789SRichard Lowe } 6045*d2a70789SRichard Lowe 6046*d2a70789SRichard Lowe if (lower_set && !lower.psd_ass_active) { 6047*d2a70789SRichard Lowe zerr(gettext("only assignment of security flags is " 6048*d2a70789SRichard Lowe "allowed (lower: %s)"), tab->zone_secflags_lower); 6049*d2a70789SRichard Lowe } 6050*d2a70789SRichard Lowe 6051*d2a70789SRichard Lowe if (upper_set && !upper.psd_ass_active) { 6052*d2a70789SRichard Lowe zerr(gettext("only assignment of security flags is " 6053*d2a70789SRichard Lowe "allowed (upper: %s)"), tab->zone_secflags_upper); 6054*d2a70789SRichard Lowe } 6055*d2a70789SRichard Lowe 6056*d2a70789SRichard Lowe if (def.psd_assign & ~upper.psd_assign) { /* In default but not upper */ 6057*d2a70789SRichard Lowe zerr(gettext("default secflags must be within the " 6058*d2a70789SRichard Lowe "upper limit")); 6059*d2a70789SRichard Lowe ret = B_FALSE; 6060*d2a70789SRichard Lowe } 6061*d2a70789SRichard Lowe if (lower.psd_assign & ~def.psd_assign) { /* In lower but not default */ 6062*d2a70789SRichard Lowe zerr(gettext("default secflags must be above the lower limit")); 6063*d2a70789SRichard Lowe ret = B_FALSE; 6064*d2a70789SRichard Lowe } 6065*d2a70789SRichard Lowe if (lower.psd_assign & ~upper.psd_assign) { /* In lower but not upper */ 6066*d2a70789SRichard Lowe zerr(gettext("lower secflags must be within the upper limit")); 6067*d2a70789SRichard Lowe ret = B_FALSE; 6068*d2a70789SRichard Lowe } 6069*d2a70789SRichard Lowe 6070*d2a70789SRichard Lowe return (ret); 6071*d2a70789SRichard Lowe } 6072*d2a70789SRichard Lowe 60737c478bd9Sstevel@tonic-gate /* 60747c478bd9Sstevel@tonic-gate * See the DTD for which attributes are required for which resources. 60757c478bd9Sstevel@tonic-gate * 60767c478bd9Sstevel@tonic-gate * This function can be called by commit_func(), which needs to save things, 60777c478bd9Sstevel@tonic-gate * in addition to the general call from parse_and_run(), which doesn't need 60787c478bd9Sstevel@tonic-gate * things saved. Since the parameters are standardized, we distinguish by 60797c478bd9Sstevel@tonic-gate * having commit_func() call here with cmd->cmd_arg set to "save" to indicate 60807c478bd9Sstevel@tonic-gate * that a save is needed. 60817c478bd9Sstevel@tonic-gate */ 60827c478bd9Sstevel@tonic-gate void 60837c478bd9Sstevel@tonic-gate verify_func(cmd_t *cmd) 60847c478bd9Sstevel@tonic-gate { 60857c478bd9Sstevel@tonic-gate struct zone_nwiftab nwiftab; 60867c478bd9Sstevel@tonic-gate struct zone_fstab fstab; 60877c478bd9Sstevel@tonic-gate struct zone_attrtab attrtab; 60887c478bd9Sstevel@tonic-gate struct zone_rctltab rctltab; 6089fa9e4066Sahrens struct zone_dstab dstab; 60900209230bSgjelinek struct zone_psettab psettab; 6091cb8a054bSGlenn Faden struct zone_admintab admintab; 6092*d2a70789SRichard Lowe struct zone_secflagstab secflagstab; 60937c478bd9Sstevel@tonic-gate char zonepath[MAXPATHLEN]; 60940209230bSgjelinek char sched[MAXNAMELEN]; 60959acbbeafSnn char brand[MAXNAMELEN]; 60965679c89fSjv char hostidp[HW_HOSTID_LEN]; 60970fbb751dSJohn Levon char fsallowedp[ZONE_FS_ALLOWED_MAX]; 6098f93d2c19SAlexander Eremin priv_set_t *privs; 6099f93d2c19SAlexander Eremin char *privname = NULL; 61007c478bd9Sstevel@tonic-gate int err, ret_val = Z_OK, arg; 6101c97ad5cdSakolb int pset_res; 6102bbec428eSgjelinek boolean_t save = B_FALSE; 6103bbec428eSgjelinek boolean_t arg_err = B_FALSE; 6104f4b3ec61Sdh zone_iptype_t iptype; 61050209230bSgjelinek boolean_t has_cpu_shares = B_FALSE; 6106c97ad5cdSakolb boolean_t has_cpu_cap = B_FALSE; 6107550b6e40SSowmini Varadhan struct xif *tmp; 61087c478bd9Sstevel@tonic-gate 61097c478bd9Sstevel@tonic-gate optind = 0; 61107ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 61117c478bd9Sstevel@tonic-gate switch (arg) { 61127c478bd9Sstevel@tonic-gate case '?': 61137c478bd9Sstevel@tonic-gate longer_usage(CMD_VERIFY); 6114bbec428eSgjelinek arg_err = B_TRUE; 61157ec75eb8Sgjelinek break; 61167c478bd9Sstevel@tonic-gate default: 61177c478bd9Sstevel@tonic-gate short_usage(CMD_VERIFY); 6118bbec428eSgjelinek arg_err = B_TRUE; 61197ec75eb8Sgjelinek break; 61207c478bd9Sstevel@tonic-gate } 61217c478bd9Sstevel@tonic-gate } 61227ec75eb8Sgjelinek if (arg_err) 61237ec75eb8Sgjelinek return; 61247ec75eb8Sgjelinek 61257c478bd9Sstevel@tonic-gate if (optind > cmd->cmd_argc) { 61267c478bd9Sstevel@tonic-gate short_usage(CMD_VERIFY); 61277c478bd9Sstevel@tonic-gate return; 61287c478bd9Sstevel@tonic-gate } 61297c478bd9Sstevel@tonic-gate 61307c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_VERIFY)) 61317c478bd9Sstevel@tonic-gate return; 61327c478bd9Sstevel@tonic-gate 61337c478bd9Sstevel@tonic-gate assert(cmd != NULL); 61347c478bd9Sstevel@tonic-gate 61357c478bd9Sstevel@tonic-gate if (cmd->cmd_argc > 0 && (strcmp(cmd->cmd_argv[0], "save") == 0)) 6136bbec428eSgjelinek save = B_TRUE; 6137bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 61387c478bd9Sstevel@tonic-gate return; 61397c478bd9Sstevel@tonic-gate 61400209230bSgjelinek if (zonecfg_get_zonepath(handle, zonepath, sizeof (zonepath)) != Z_OK && 61410209230bSgjelinek !global_zone) { 6142087719fdSdp zerr(gettext("%s not specified"), pt_to_str(PT_ZONEPATH)); 61437c478bd9Sstevel@tonic-gate ret_val = Z_REQD_RESOURCE_MISSING; 6144bbec428eSgjelinek saw_error = B_TRUE; 61457c478bd9Sstevel@tonic-gate } 61460209230bSgjelinek if (strlen(zonepath) == 0 && !global_zone) { 6147087719fdSdp zerr(gettext("%s cannot be empty."), pt_to_str(PT_ZONEPATH)); 61487c478bd9Sstevel@tonic-gate ret_val = Z_REQD_RESOURCE_MISSING; 6149bbec428eSgjelinek saw_error = B_TRUE; 61507c478bd9Sstevel@tonic-gate } 61517c478bd9Sstevel@tonic-gate 61529acbbeafSnn if ((err = zonecfg_get_brand(handle, brand, sizeof (brand))) != Z_OK) { 6153bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 61549acbbeafSnn return; 61559acbbeafSnn } 6156a46da47fSEdward Pilatowicz if ((err = brand_verify(handle)) != Z_OK) { 6157a46da47fSEdward Pilatowicz zone_perror(zone, err, B_TRUE); 6158a46da47fSEdward Pilatowicz return; 61599acbbeafSnn } 61609acbbeafSnn 6161f4b3ec61Sdh if (zonecfg_get_iptype(handle, &iptype) != Z_OK) { 6162f4b3ec61Sdh zerr("%s %s", gettext("cannot get"), pt_to_str(PT_IPTYPE)); 6163f4b3ec61Sdh ret_val = Z_REQD_RESOURCE_MISSING; 6164bbec428eSgjelinek saw_error = B_TRUE; 6165f4b3ec61Sdh } 61667c478bd9Sstevel@tonic-gate 6167f93d2c19SAlexander Eremin if ((privs = priv_allocset()) == NULL) { 6168f93d2c19SAlexander Eremin zerr(gettext("%s: priv_allocset failed"), zone); 6169f93d2c19SAlexander Eremin return; 6170f93d2c19SAlexander Eremin } 6171f93d2c19SAlexander Eremin if (zonecfg_get_privset(handle, privs, &privname) != Z_OK) { 6172f93d2c19SAlexander Eremin zerr(gettext("%s: invalid privilege: %s"), zone, privname); 6173f93d2c19SAlexander Eremin priv_freeset(privs); 6174f93d2c19SAlexander Eremin free(privname); 6175f93d2c19SAlexander Eremin return; 6176f93d2c19SAlexander Eremin } 6177f93d2c19SAlexander Eremin priv_freeset(privs); 6178f93d2c19SAlexander Eremin 61790fbb751dSJohn Levon if (zonecfg_get_hostid(handle, hostidp, 61800fbb751dSJohn Levon sizeof (hostidp)) == Z_INVALID_PROPERTY) { 61810fbb751dSJohn Levon zerr(gettext("%s: invalid hostid: %s"), 61820fbb751dSJohn Levon zone, hostidp); 61830fbb751dSJohn Levon return; 61840fbb751dSJohn Levon } 61850fbb751dSJohn Levon 61860fbb751dSJohn Levon if (zonecfg_get_fs_allowed(handle, fsallowedp, 61870fbb751dSJohn Levon sizeof (fsallowedp)) == Z_INVALID_PROPERTY) { 61880fbb751dSJohn Levon zerr(gettext("%s: invalid fs-allowed: %s"), 61890fbb751dSJohn Levon zone, fsallowedp); 61905679c89fSjv return; 61915679c89fSjv } 61925679c89fSjv 61937c478bd9Sstevel@tonic-gate if ((err = zonecfg_setfsent(handle)) != Z_OK) { 6194bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 61957c478bd9Sstevel@tonic-gate return; 61967c478bd9Sstevel@tonic-gate } 61977c478bd9Sstevel@tonic-gate while (zonecfg_getfsent(handle, &fstab) == Z_OK) { 6198087719fdSdp check_reqd_prop(fstab.zone_fs_dir, RT_FS, PT_DIR, &ret_val); 6199087719fdSdp check_reqd_prop(fstab.zone_fs_special, RT_FS, PT_SPECIAL, 6200087719fdSdp &ret_val); 6201087719fdSdp check_reqd_prop(fstab.zone_fs_type, RT_FS, PT_TYPE, &ret_val); 6202087719fdSdp 62037c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(fstab.zone_fs_options); 62047c478bd9Sstevel@tonic-gate } 62057c478bd9Sstevel@tonic-gate (void) zonecfg_endfsent(handle); 62067c478bd9Sstevel@tonic-gate 62077c478bd9Sstevel@tonic-gate if ((err = zonecfg_setnwifent(handle)) != Z_OK) { 6208bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 62097c478bd9Sstevel@tonic-gate return; 62107c478bd9Sstevel@tonic-gate } 62117c478bd9Sstevel@tonic-gate while (zonecfg_getnwifent(handle, &nwiftab) == Z_OK) { 6212f4b3ec61Sdh /* 6213f4b3ec61Sdh * physical is required in all cases. 6214de860bd9Sgfaden * A shared IP requires an address, 6215de860bd9Sgfaden * and may include a default router, while 6216de860bd9Sgfaden * an exclusive IP must have neither an address 6217de860bd9Sgfaden * nor a default router. 621801b4bc23Sjv * The physical interface name must be valid in all cases. 6219f4b3ec61Sdh */ 6220087719fdSdp check_reqd_prop(nwiftab.zone_nwif_physical, RT_NET, 6221087719fdSdp PT_PHYSICAL, &ret_val); 622201b4bc23Sjv if (validate_net_physical_syntax(nwiftab.zone_nwif_physical) != 622301b4bc23Sjv Z_OK) { 622401b4bc23Sjv saw_error = B_TRUE; 622501b4bc23Sjv if (ret_val == Z_OK) 622601b4bc23Sjv ret_val = Z_INVAL; 622701b4bc23Sjv } 6228f4b3ec61Sdh 6229f4b3ec61Sdh switch (iptype) { 6230f4b3ec61Sdh case ZS_SHARED: 6231f4b3ec61Sdh check_reqd_prop(nwiftab.zone_nwif_address, RT_NET, 6232f4b3ec61Sdh PT_ADDRESS, &ret_val); 6233550b6e40SSowmini Varadhan if (strlen(nwiftab.zone_nwif_allowed_address) > 0) { 6234f4b3ec61Sdh zerr(gettext("%s: %s cannot be specified " 6235550b6e40SSowmini Varadhan "for a shared IP type"), 6236550b6e40SSowmini Varadhan rt_to_str(RT_NET), 6237550b6e40SSowmini Varadhan pt_to_str(PT_ALLOWED_ADDRESS)); 6238bbec428eSgjelinek saw_error = B_TRUE; 6239f4b3ec61Sdh if (ret_val == Z_OK) 6240f4b3ec61Sdh ret_val = Z_INVAL; 6241f4b3ec61Sdh } 6242550b6e40SSowmini Varadhan break; 6243550b6e40SSowmini Varadhan case ZS_EXCLUSIVE: 6244550b6e40SSowmini Varadhan if (strlen(nwiftab.zone_nwif_address) > 0) { 6245de860bd9Sgfaden zerr(gettext("%s: %s cannot be specified " 6246de860bd9Sgfaden "for an exclusive IP type"), 6247550b6e40SSowmini Varadhan rt_to_str(RT_NET), pt_to_str(PT_ADDRESS)); 6248bbec428eSgjelinek saw_error = B_TRUE; 6249de860bd9Sgfaden if (ret_val == Z_OK) 6250de860bd9Sgfaden ret_val = Z_INVAL; 6251550b6e40SSowmini Varadhan } else { 6252550b6e40SSowmini Varadhan if (!add_nwif(&nwiftab)) { 6253550b6e40SSowmini Varadhan saw_error = B_TRUE; 6254550b6e40SSowmini Varadhan if (ret_val == Z_OK) 6255550b6e40SSowmini Varadhan ret_val = Z_INVAL; 6256550b6e40SSowmini Varadhan } 6257de860bd9Sgfaden } 6258f4b3ec61Sdh break; 6259f4b3ec61Sdh } 62607c478bd9Sstevel@tonic-gate } 6261550b6e40SSowmini Varadhan for (tmp = xif; tmp != NULL; tmp = tmp->xif_next) { 6262550b6e40SSowmini Varadhan if (!tmp->xif_has_address && tmp->xif_has_defrouter) { 6263550b6e40SSowmini Varadhan zerr(gettext("%s: %s for %s cannot be specified " 6264550b6e40SSowmini Varadhan "without %s for an exclusive IP type"), 6265550b6e40SSowmini Varadhan rt_to_str(RT_NET), pt_to_str(PT_DEFROUTER), 6266550b6e40SSowmini Varadhan tmp->xif_name, pt_to_str(PT_ALLOWED_ADDRESS)); 6267550b6e40SSowmini Varadhan saw_error = B_TRUE; 6268550b6e40SSowmini Varadhan ret_val = Z_INVAL; 6269550b6e40SSowmini Varadhan } 6270550b6e40SSowmini Varadhan } 6271550b6e40SSowmini Varadhan free(xif); 6272550b6e40SSowmini Varadhan xif = NULL; 62737c478bd9Sstevel@tonic-gate (void) zonecfg_endnwifent(handle); 62747c478bd9Sstevel@tonic-gate 62757c478bd9Sstevel@tonic-gate if ((err = zonecfg_setrctlent(handle)) != Z_OK) { 6276bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 62777c478bd9Sstevel@tonic-gate return; 62787c478bd9Sstevel@tonic-gate } 62797c478bd9Sstevel@tonic-gate while (zonecfg_getrctlent(handle, &rctltab) == Z_OK) { 6280087719fdSdp check_reqd_prop(rctltab.zone_rctl_name, RT_RCTL, PT_NAME, 6281087719fdSdp &ret_val); 6282087719fdSdp 62830209230bSgjelinek if (strcmp(rctltab.zone_rctl_name, "zone.cpu-shares") == 0) 62840209230bSgjelinek has_cpu_shares = B_TRUE; 62850209230bSgjelinek 6286c97ad5cdSakolb if (strcmp(rctltab.zone_rctl_name, "zone.cpu-cap") == 0) 6287c97ad5cdSakolb has_cpu_cap = B_TRUE; 6288c97ad5cdSakolb 62897c478bd9Sstevel@tonic-gate if (rctltab.zone_rctl_valptr == NULL) { 62907c478bd9Sstevel@tonic-gate zerr(gettext("%s: no %s specified"), 62917c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL), pt_to_str(PT_VALUE)); 6292bbec428eSgjelinek saw_error = B_TRUE; 62937c478bd9Sstevel@tonic-gate if (ret_val == Z_OK) 62947c478bd9Sstevel@tonic-gate ret_val = Z_REQD_PROPERTY_MISSING; 62957c478bd9Sstevel@tonic-gate } else { 62967c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr); 62977c478bd9Sstevel@tonic-gate } 62987c478bd9Sstevel@tonic-gate } 62997c478bd9Sstevel@tonic-gate (void) zonecfg_endrctlent(handle); 63007c478bd9Sstevel@tonic-gate 6301c97ad5cdSakolb if ((pset_res = zonecfg_lookup_pset(handle, &psettab)) == Z_OK && 6302c97ad5cdSakolb has_cpu_shares) { 63030209230bSgjelinek zerr(gettext("%s zone.cpu-shares and %s are incompatible."), 63040209230bSgjelinek rt_to_str(RT_RCTL), rt_to_str(RT_DCPU)); 6305bbec428eSgjelinek saw_error = B_TRUE; 63060209230bSgjelinek if (ret_val == Z_OK) 63070209230bSgjelinek ret_val = Z_INCOMPATIBLE; 63080209230bSgjelinek } 63090209230bSgjelinek 63100209230bSgjelinek if (has_cpu_shares && zonecfg_get_sched_class(handle, sched, 63110209230bSgjelinek sizeof (sched)) == Z_OK && strlen(sched) > 0 && 63120209230bSgjelinek strcmp(sched, "FSS") != 0) { 63130209230bSgjelinek zerr(gettext("WARNING: %s zone.cpu-shares and %s=%s are " 63140209230bSgjelinek "incompatible"), 63150209230bSgjelinek rt_to_str(RT_RCTL), rt_to_str(RT_SCHED), sched); 6316bbec428eSgjelinek saw_error = B_TRUE; 63170209230bSgjelinek if (ret_val == Z_OK) 63180209230bSgjelinek ret_val = Z_INCOMPATIBLE; 63190209230bSgjelinek } 63200209230bSgjelinek 6321c97ad5cdSakolb if (pset_res == Z_OK && has_cpu_cap) { 6322c97ad5cdSakolb zerr(gettext("%s zone.cpu-cap and the %s are incompatible."), 6323c97ad5cdSakolb rt_to_str(RT_RCTL), rt_to_str(RT_DCPU)); 6324bbec428eSgjelinek saw_error = B_TRUE; 6325c97ad5cdSakolb if (ret_val == Z_OK) 6326c97ad5cdSakolb ret_val = Z_INCOMPATIBLE; 6327c97ad5cdSakolb } 6328c97ad5cdSakolb 63297c478bd9Sstevel@tonic-gate if ((err = zonecfg_setattrent(handle)) != Z_OK) { 6330bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 63317c478bd9Sstevel@tonic-gate return; 63327c478bd9Sstevel@tonic-gate } 63337c478bd9Sstevel@tonic-gate while (zonecfg_getattrent(handle, &attrtab) == Z_OK) { 6334087719fdSdp check_reqd_prop(attrtab.zone_attr_name, RT_ATTR, PT_NAME, 6335087719fdSdp &ret_val); 6336087719fdSdp check_reqd_prop(attrtab.zone_attr_type, RT_ATTR, PT_TYPE, 6337087719fdSdp &ret_val); 6338087719fdSdp check_reqd_prop(attrtab.zone_attr_value, RT_ATTR, PT_VALUE, 6339087719fdSdp &ret_val); 63407c478bd9Sstevel@tonic-gate } 63417c478bd9Sstevel@tonic-gate (void) zonecfg_endattrent(handle); 63427c478bd9Sstevel@tonic-gate 6343fa9e4066Sahrens if ((err = zonecfg_setdsent(handle)) != Z_OK) { 6344bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 6345fa9e4066Sahrens return; 6346fa9e4066Sahrens } 6347fa9e4066Sahrens while (zonecfg_getdsent(handle, &dstab) == Z_OK) { 6348fa9e4066Sahrens if (strlen(dstab.zone_dataset_name) == 0) { 6349fa9e4066Sahrens zerr("%s: %s %s", rt_to_str(RT_DATASET), 6350fa9e4066Sahrens pt_to_str(PT_NAME), gettext("not specified")); 6351bbec428eSgjelinek saw_error = B_TRUE; 6352fa9e4066Sahrens if (ret_val == Z_OK) 6353fa9e4066Sahrens ret_val = Z_REQD_PROPERTY_MISSING; 6354fa9e4066Sahrens } else if (!zfs_name_valid(dstab.zone_dataset_name, 6355fa9e4066Sahrens ZFS_TYPE_FILESYSTEM)) { 6356fa9e4066Sahrens zerr("%s: %s %s", rt_to_str(RT_DATASET), 6357fa9e4066Sahrens pt_to_str(PT_NAME), gettext("invalid")); 6358bbec428eSgjelinek saw_error = B_TRUE; 6359fa9e4066Sahrens if (ret_val == Z_OK) 6360fa9e4066Sahrens ret_val = Z_BAD_PROPERTY; 6361fa9e4066Sahrens } 6362fa9e4066Sahrens 6363fa9e4066Sahrens } 6364fa9e4066Sahrens (void) zonecfg_enddsent(handle); 6365fa9e4066Sahrens 6366cb8a054bSGlenn Faden if ((err = zonecfg_setadminent(handle)) != Z_OK) { 6367cb8a054bSGlenn Faden zone_perror(zone, err, B_TRUE); 6368cb8a054bSGlenn Faden return; 6369cb8a054bSGlenn Faden } 6370cb8a054bSGlenn Faden while (zonecfg_getadminent(handle, &admintab) == Z_OK) { 6371cb8a054bSGlenn Faden check_reqd_prop(admintab.zone_admin_user, RT_ADMIN, 6372cb8a054bSGlenn Faden PT_USER, &ret_val); 6373cb8a054bSGlenn Faden check_reqd_prop(admintab.zone_admin_auths, RT_ADMIN, 6374cb8a054bSGlenn Faden PT_AUTHS, &ret_val); 6375cb8a054bSGlenn Faden if ((ret_val == Z_OK) && (getpwnam(admintab.zone_admin_user) 6376cb8a054bSGlenn Faden == NULL)) { 6377cb8a054bSGlenn Faden zerr(gettext("%s %s is not a valid username"), 6378cb8a054bSGlenn Faden pt_to_str(PT_USER), 6379cb8a054bSGlenn Faden admintab.zone_admin_user); 6380cb8a054bSGlenn Faden ret_val = Z_BAD_PROPERTY; 6381cb8a054bSGlenn Faden } 6382cb8a054bSGlenn Faden if ((ret_val == Z_OK) && (!zonecfg_valid_auths( 6383cb8a054bSGlenn Faden admintab.zone_admin_auths, zone))) { 6384cb8a054bSGlenn Faden ret_val = Z_BAD_PROPERTY; 6385cb8a054bSGlenn Faden } 6386cb8a054bSGlenn Faden } 6387cb8a054bSGlenn Faden (void) zonecfg_endadminent(handle); 6388cb8a054bSGlenn Faden 6389*d2a70789SRichard Lowe if (zonecfg_getsecflagsent(handle, &secflagstab) == Z_OK) { 6390*d2a70789SRichard Lowe /* 6391*d2a70789SRichard Lowe * No properties are required, but any specified should be 6392*d2a70789SRichard Lowe * valid 6393*d2a70789SRichard Lowe */ 6394*d2a70789SRichard Lowe if (verify_secflags(&secflagstab) != B_TRUE) { 6395*d2a70789SRichard Lowe /* Error is reported from verify_secflags */ 6396*d2a70789SRichard Lowe ret_val = Z_BAD_PROPERTY; 6397*d2a70789SRichard Lowe } 6398*d2a70789SRichard Lowe } 6399*d2a70789SRichard Lowe 64007c478bd9Sstevel@tonic-gate if (!global_scope) { 64017c478bd9Sstevel@tonic-gate zerr(gettext("resource specification incomplete")); 6402bbec428eSgjelinek saw_error = B_TRUE; 64037c478bd9Sstevel@tonic-gate if (ret_val == Z_OK) 64047c478bd9Sstevel@tonic-gate ret_val = Z_INSUFFICIENT_SPEC; 64057c478bd9Sstevel@tonic-gate } 64067c478bd9Sstevel@tonic-gate 64077c478bd9Sstevel@tonic-gate if (save) { 6408087719fdSdp if (ret_val == Z_OK) { 6409087719fdSdp if ((ret_val = zonecfg_save(handle)) == Z_OK) { 6410bbec428eSgjelinek need_to_commit = B_FALSE; 6411087719fdSdp (void) strlcpy(revert_zone, zone, 6412087719fdSdp sizeof (revert_zone)); 6413087719fdSdp } 6414087719fdSdp } else { 6415087719fdSdp zerr(gettext("Zone %s failed to verify"), zone); 6416087719fdSdp } 64177c478bd9Sstevel@tonic-gate } 64187c478bd9Sstevel@tonic-gate if (ret_val != Z_OK) 6419bbec428eSgjelinek zone_perror(zone, ret_val, B_TRUE); 64207c478bd9Sstevel@tonic-gate } 64217c478bd9Sstevel@tonic-gate 64227c478bd9Sstevel@tonic-gate void 64237c478bd9Sstevel@tonic-gate cancel_func(cmd_t *cmd) 64247c478bd9Sstevel@tonic-gate { 64257c478bd9Sstevel@tonic-gate int arg; 6426bbec428eSgjelinek boolean_t arg_err = B_FALSE; 64277c478bd9Sstevel@tonic-gate 64287c478bd9Sstevel@tonic-gate assert(cmd != NULL); 64297c478bd9Sstevel@tonic-gate 64307c478bd9Sstevel@tonic-gate optind = 0; 64317ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 64327c478bd9Sstevel@tonic-gate switch (arg) { 64337c478bd9Sstevel@tonic-gate case '?': 64347c478bd9Sstevel@tonic-gate longer_usage(CMD_CANCEL); 6435bbec428eSgjelinek arg_err = B_TRUE; 64367ec75eb8Sgjelinek break; 64377c478bd9Sstevel@tonic-gate default: 64387c478bd9Sstevel@tonic-gate short_usage(CMD_CANCEL); 6439bbec428eSgjelinek arg_err = B_TRUE; 64407ec75eb8Sgjelinek break; 64417c478bd9Sstevel@tonic-gate } 64427c478bd9Sstevel@tonic-gate } 64437ec75eb8Sgjelinek if (arg_err) 64447ec75eb8Sgjelinek return; 64457ec75eb8Sgjelinek 64467c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 64477c478bd9Sstevel@tonic-gate short_usage(CMD_CANCEL); 64487c478bd9Sstevel@tonic-gate return; 64497c478bd9Sstevel@tonic-gate } 64507c478bd9Sstevel@tonic-gate 64517c478bd9Sstevel@tonic-gate if (global_scope) 64527c478bd9Sstevel@tonic-gate scope_usage(CMD_CANCEL); 6453bbec428eSgjelinek global_scope = B_TRUE; 64547c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(in_progress_fstab.zone_fs_options); 64557c478bd9Sstevel@tonic-gate bzero(&in_progress_fstab, sizeof (in_progress_fstab)); 64567c478bd9Sstevel@tonic-gate bzero(&in_progress_nwiftab, sizeof (in_progress_nwiftab)); 64577c478bd9Sstevel@tonic-gate bzero(&in_progress_devtab, sizeof (in_progress_devtab)); 64587c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(in_progress_rctltab.zone_rctl_valptr); 64597c478bd9Sstevel@tonic-gate bzero(&in_progress_rctltab, sizeof (in_progress_rctltab)); 64607c478bd9Sstevel@tonic-gate bzero(&in_progress_attrtab, sizeof (in_progress_attrtab)); 6461fa9e4066Sahrens bzero(&in_progress_dstab, sizeof (in_progress_dstab)); 64627c478bd9Sstevel@tonic-gate } 64637c478bd9Sstevel@tonic-gate 64647c478bd9Sstevel@tonic-gate static int 64657c478bd9Sstevel@tonic-gate validate_attr_name(char *name) 64667c478bd9Sstevel@tonic-gate { 64677c478bd9Sstevel@tonic-gate int i; 64687c478bd9Sstevel@tonic-gate 64697c478bd9Sstevel@tonic-gate if (!isalnum(name[0])) { 64707c478bd9Sstevel@tonic-gate zerr(gettext("Invalid %s %s %s: must start with an alpha-" 64717c478bd9Sstevel@tonic-gate "numeric character."), rt_to_str(RT_ATTR), 64727c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), name); 64737c478bd9Sstevel@tonic-gate return (Z_INVAL); 64747c478bd9Sstevel@tonic-gate } 64757c478bd9Sstevel@tonic-gate for (i = 1; name[i]; i++) 64767c478bd9Sstevel@tonic-gate if (!isalnum(name[i]) && name[i] != '-' && name[i] != '.') { 64777c478bd9Sstevel@tonic-gate zerr(gettext("Invalid %s %s %s: can only contain " 64787c478bd9Sstevel@tonic-gate "alpha-numeric characters, plus '-' and '.'."), 64797c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_NAME), name); 64807c478bd9Sstevel@tonic-gate return (Z_INVAL); 64817c478bd9Sstevel@tonic-gate } 64827c478bd9Sstevel@tonic-gate return (Z_OK); 64837c478bd9Sstevel@tonic-gate } 64847c478bd9Sstevel@tonic-gate 64857c478bd9Sstevel@tonic-gate static int 64867c478bd9Sstevel@tonic-gate validate_attr_type_val(struct zone_attrtab *attrtab) 64877c478bd9Sstevel@tonic-gate { 64887c478bd9Sstevel@tonic-gate boolean_t boolval; 64897c478bd9Sstevel@tonic-gate int64_t intval; 64907c478bd9Sstevel@tonic-gate char strval[MAXNAMELEN]; 64917c478bd9Sstevel@tonic-gate uint64_t uintval; 64927c478bd9Sstevel@tonic-gate 64937c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "boolean") == 0) { 64947c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_boolean(attrtab, &boolval) == Z_OK) 64957c478bd9Sstevel@tonic-gate return (Z_OK); 64967c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 64977c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "boolean"); 64987c478bd9Sstevel@tonic-gate return (Z_ERR); 64997c478bd9Sstevel@tonic-gate } 65007c478bd9Sstevel@tonic-gate 65017c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "int") == 0) { 65027c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_int(attrtab, &intval) == Z_OK) 65037c478bd9Sstevel@tonic-gate return (Z_OK); 65047c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 65057c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "int"); 65067c478bd9Sstevel@tonic-gate return (Z_ERR); 65077c478bd9Sstevel@tonic-gate } 65087c478bd9Sstevel@tonic-gate 65097c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "string") == 0) { 65107c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_string(attrtab, strval, 65117c478bd9Sstevel@tonic-gate sizeof (strval)) == Z_OK) 65127c478bd9Sstevel@tonic-gate return (Z_OK); 65137c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 65147c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "string"); 65157c478bd9Sstevel@tonic-gate return (Z_ERR); 65167c478bd9Sstevel@tonic-gate } 65177c478bd9Sstevel@tonic-gate 65187c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "uint") == 0) { 65197c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_uint(attrtab, &uintval) == Z_OK) 65207c478bd9Sstevel@tonic-gate return (Z_OK); 65217c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 65227c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "uint"); 65237c478bd9Sstevel@tonic-gate return (Z_ERR); 65247c478bd9Sstevel@tonic-gate } 65257c478bd9Sstevel@tonic-gate 65267c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s %s '%s'"), rt_to_str(RT_ATTR), 65277c478bd9Sstevel@tonic-gate pt_to_str(PT_TYPE), attrtab->zone_attr_type); 65287c478bd9Sstevel@tonic-gate return (Z_ERR); 65297c478bd9Sstevel@tonic-gate } 65307c478bd9Sstevel@tonic-gate 6531087719fdSdp /* 6532087719fdSdp * Helper function for end_func-- checks the existence of a given property 6533087719fdSdp * and emits a message if not specified. 6534087719fdSdp */ 6535087719fdSdp static int 6536bbec428eSgjelinek end_check_reqd(char *attr, int pt, boolean_t *validation_failed) 6537087719fdSdp { 6538087719fdSdp if (strlen(attr) == 0) { 6539bbec428eSgjelinek *validation_failed = B_TRUE; 6540087719fdSdp zerr(gettext("%s not specified"), pt_to_str(pt)); 6541087719fdSdp return (Z_ERR); 6542087719fdSdp } 6543087719fdSdp return (Z_OK); 6544087719fdSdp } 6545087719fdSdp 6546550b6e40SSowmini Varadhan static void 6547550b6e40SSowmini Varadhan net_exists_error(struct zone_nwiftab nwif) 6548550b6e40SSowmini Varadhan { 6549550b6e40SSowmini Varadhan if (strlen(nwif.zone_nwif_address) > 0) { 6550550b6e40SSowmini Varadhan zerr(gettext("A %s resource with the %s '%s', " 6551550b6e40SSowmini Varadhan "and %s '%s' already exists."), 6552550b6e40SSowmini Varadhan rt_to_str(RT_NET), 6553550b6e40SSowmini Varadhan pt_to_str(PT_PHYSICAL), 6554550b6e40SSowmini Varadhan nwif.zone_nwif_physical, 6555550b6e40SSowmini Varadhan pt_to_str(PT_ADDRESS), 6556550b6e40SSowmini Varadhan in_progress_nwiftab.zone_nwif_address); 6557550b6e40SSowmini Varadhan } else { 6558550b6e40SSowmini Varadhan zerr(gettext("A %s resource with the %s '%s', " 6559550b6e40SSowmini Varadhan "and %s '%s' already exists."), 6560550b6e40SSowmini Varadhan rt_to_str(RT_NET), 6561550b6e40SSowmini Varadhan pt_to_str(PT_PHYSICAL), 6562550b6e40SSowmini Varadhan nwif.zone_nwif_physical, 6563550b6e40SSowmini Varadhan pt_to_str(PT_ALLOWED_ADDRESS), 6564550b6e40SSowmini Varadhan nwif.zone_nwif_allowed_address); 6565550b6e40SSowmini Varadhan } 6566550b6e40SSowmini Varadhan } 6567550b6e40SSowmini Varadhan 65687c478bd9Sstevel@tonic-gate void 65697c478bd9Sstevel@tonic-gate end_func(cmd_t *cmd) 65707c478bd9Sstevel@tonic-gate { 6571bbec428eSgjelinek boolean_t validation_failed = B_FALSE; 6572bbec428eSgjelinek boolean_t arg_err = B_FALSE; 65737c478bd9Sstevel@tonic-gate struct zone_fstab tmp_fstab; 65747c478bd9Sstevel@tonic-gate struct zone_nwiftab tmp_nwiftab; 65757c478bd9Sstevel@tonic-gate struct zone_devtab tmp_devtab; 65767c478bd9Sstevel@tonic-gate struct zone_rctltab tmp_rctltab; 65777c478bd9Sstevel@tonic-gate struct zone_attrtab tmp_attrtab; 6578fa9e4066Sahrens struct zone_dstab tmp_dstab; 6579cb8a054bSGlenn Faden struct zone_admintab tmp_admintab; 65800209230bSgjelinek int err, arg, res1, res2, res3; 65810209230bSgjelinek uint64_t swap_limit; 65820209230bSgjelinek uint64_t locked_limit; 6583c97ad5cdSakolb uint64_t proc_cap; 65847c478bd9Sstevel@tonic-gate 65857c478bd9Sstevel@tonic-gate assert(cmd != NULL); 65867c478bd9Sstevel@tonic-gate 65877c478bd9Sstevel@tonic-gate optind = 0; 65887ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 65897c478bd9Sstevel@tonic-gate switch (arg) { 65907c478bd9Sstevel@tonic-gate case '?': 65917c478bd9Sstevel@tonic-gate longer_usage(CMD_END); 6592bbec428eSgjelinek arg_err = B_TRUE; 65937ec75eb8Sgjelinek break; 65947c478bd9Sstevel@tonic-gate default: 65957c478bd9Sstevel@tonic-gate short_usage(CMD_END); 6596bbec428eSgjelinek arg_err = B_TRUE; 65977ec75eb8Sgjelinek break; 65987c478bd9Sstevel@tonic-gate } 65997c478bd9Sstevel@tonic-gate } 66007ec75eb8Sgjelinek if (arg_err) 66017ec75eb8Sgjelinek return; 66027ec75eb8Sgjelinek 66037c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 66047c478bd9Sstevel@tonic-gate short_usage(CMD_END); 66057c478bd9Sstevel@tonic-gate return; 66067c478bd9Sstevel@tonic-gate } 66077c478bd9Sstevel@tonic-gate 66087c478bd9Sstevel@tonic-gate if (global_scope) { 66097c478bd9Sstevel@tonic-gate scope_usage(CMD_END); 66107c478bd9Sstevel@tonic-gate return; 66117c478bd9Sstevel@tonic-gate } 66127c478bd9Sstevel@tonic-gate 66137c478bd9Sstevel@tonic-gate assert(end_op == CMD_ADD || end_op == CMD_SELECT); 66147c478bd9Sstevel@tonic-gate 66157c478bd9Sstevel@tonic-gate switch (resource_scope) { 66167c478bd9Sstevel@tonic-gate case RT_FS: 66177c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 6618087719fdSdp if (end_check_reqd(in_progress_fstab.zone_fs_dir, 6619087719fdSdp PT_DIR, &validation_failed) == Z_OK) { 6620087719fdSdp if (in_progress_fstab.zone_fs_dir[0] != '/') { 6621087719fdSdp zerr(gettext("%s %s is not an absolute path."), 6622087719fdSdp pt_to_str(PT_DIR), 6623087719fdSdp in_progress_fstab.zone_fs_dir); 6624bbec428eSgjelinek validation_failed = B_TRUE; 6625087719fdSdp } 66267c478bd9Sstevel@tonic-gate } 6627087719fdSdp 6628087719fdSdp (void) end_check_reqd(in_progress_fstab.zone_fs_special, 6629087719fdSdp PT_SPECIAL, &validation_failed); 6630087719fdSdp 66317c478bd9Sstevel@tonic-gate if (in_progress_fstab.zone_fs_raw[0] != '\0' && 66327c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_raw[0] != '/') { 6633087719fdSdp zerr(gettext("%s %s is not an absolute path."), 6634087719fdSdp pt_to_str(PT_RAW), 6635087719fdSdp in_progress_fstab.zone_fs_raw); 6636bbec428eSgjelinek validation_failed = B_TRUE; 66377c478bd9Sstevel@tonic-gate } 6638087719fdSdp 6639087719fdSdp (void) end_check_reqd(in_progress_fstab.zone_fs_type, PT_TYPE, 6640087719fdSdp &validation_failed); 6641087719fdSdp 6642087719fdSdp if (validation_failed) { 6643bbec428eSgjelinek saw_error = B_TRUE; 66447c478bd9Sstevel@tonic-gate return; 6645087719fdSdp } 6646087719fdSdp 66477c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 66487c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 66497c478bd9Sstevel@tonic-gate bzero(&tmp_fstab, sizeof (tmp_fstab)); 66507c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_fstab.zone_fs_dir, 66517c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_dir, 66527c478bd9Sstevel@tonic-gate sizeof (tmp_fstab.zone_fs_dir)); 66537c478bd9Sstevel@tonic-gate err = zonecfg_lookup_filesystem(handle, &tmp_fstab); 66547c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(tmp_fstab.zone_fs_options); 66557c478bd9Sstevel@tonic-gate if (err == Z_OK) { 66567c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource " 66577c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 66587c478bd9Sstevel@tonic-gate rt_to_str(RT_FS), pt_to_str(PT_DIR), 66597c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_dir); 6660bbec428eSgjelinek saw_error = B_TRUE; 66617c478bd9Sstevel@tonic-gate return; 66627c478bd9Sstevel@tonic-gate } 66637c478bd9Sstevel@tonic-gate err = zonecfg_add_filesystem(handle, 66647c478bd9Sstevel@tonic-gate &in_progress_fstab); 66657c478bd9Sstevel@tonic-gate } else { 66667c478bd9Sstevel@tonic-gate err = zonecfg_modify_filesystem(handle, &old_fstab, 66677c478bd9Sstevel@tonic-gate &in_progress_fstab); 66687c478bd9Sstevel@tonic-gate } 66697c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(in_progress_fstab.zone_fs_options); 66707c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_options = NULL; 66717c478bd9Sstevel@tonic-gate break; 6672087719fdSdp 66737c478bd9Sstevel@tonic-gate case RT_NET: 6674f4b3ec61Sdh /* 6675f4b3ec61Sdh * First make sure everything was filled in. 6676f4b3ec61Sdh * Since we don't know whether IP will be shared 6677f4b3ec61Sdh * or exclusive here, some checks are deferred until 6678f4b3ec61Sdh * the verify command. 6679f4b3ec61Sdh */ 6680087719fdSdp (void) end_check_reqd(in_progress_nwiftab.zone_nwif_physical, 6681087719fdSdp PT_PHYSICAL, &validation_failed); 6682087719fdSdp 6683087719fdSdp if (validation_failed) { 6684bbec428eSgjelinek saw_error = B_TRUE; 66857c478bd9Sstevel@tonic-gate return; 6686087719fdSdp } 66877c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 66887c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 66897c478bd9Sstevel@tonic-gate bzero(&tmp_nwiftab, sizeof (tmp_nwiftab)); 6690f4b3ec61Sdh (void) strlcpy(tmp_nwiftab.zone_nwif_physical, 6691f4b3ec61Sdh in_progress_nwiftab.zone_nwif_physical, 6692f4b3ec61Sdh sizeof (tmp_nwiftab.zone_nwif_physical)); 66937c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_nwiftab.zone_nwif_address, 66947c478bd9Sstevel@tonic-gate in_progress_nwiftab.zone_nwif_address, 66957c478bd9Sstevel@tonic-gate sizeof (tmp_nwiftab.zone_nwif_address)); 6696550b6e40SSowmini Varadhan (void) strlcpy(tmp_nwiftab.zone_nwif_allowed_address, 6697550b6e40SSowmini Varadhan in_progress_nwiftab.zone_nwif_allowed_address, 6698550b6e40SSowmini Varadhan sizeof (tmp_nwiftab.zone_nwif_allowed_address)); 6699550b6e40SSowmini Varadhan (void) strlcpy(tmp_nwiftab.zone_nwif_defrouter, 6700550b6e40SSowmini Varadhan in_progress_nwiftab.zone_nwif_defrouter, 6701550b6e40SSowmini Varadhan sizeof (tmp_nwiftab.zone_nwif_defrouter)); 67027c478bd9Sstevel@tonic-gate if (zonecfg_lookup_nwif(handle, &tmp_nwiftab) == Z_OK) { 6703550b6e40SSowmini Varadhan net_exists_error(in_progress_nwiftab); 6704bbec428eSgjelinek saw_error = B_TRUE; 67057c478bd9Sstevel@tonic-gate return; 67067c478bd9Sstevel@tonic-gate } 67077c478bd9Sstevel@tonic-gate err = zonecfg_add_nwif(handle, &in_progress_nwiftab); 67087c478bd9Sstevel@tonic-gate } else { 67097c478bd9Sstevel@tonic-gate err = zonecfg_modify_nwif(handle, &old_nwiftab, 67107c478bd9Sstevel@tonic-gate &in_progress_nwiftab); 67117c478bd9Sstevel@tonic-gate } 67127c478bd9Sstevel@tonic-gate break; 6713087719fdSdp 67147c478bd9Sstevel@tonic-gate case RT_DEVICE: 67157c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 6716087719fdSdp (void) end_check_reqd(in_progress_devtab.zone_dev_match, 6717087719fdSdp PT_MATCH, &validation_failed); 6718087719fdSdp 6719087719fdSdp if (validation_failed) { 6720bbec428eSgjelinek saw_error = B_TRUE; 67217c478bd9Sstevel@tonic-gate return; 6722087719fdSdp } 6723087719fdSdp 67247c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 67257c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 67267c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_devtab.zone_dev_match, 67277c478bd9Sstevel@tonic-gate in_progress_devtab.zone_dev_match, 67287c478bd9Sstevel@tonic-gate sizeof (tmp_devtab.zone_dev_match)); 67297c478bd9Sstevel@tonic-gate if (zonecfg_lookup_dev(handle, &tmp_devtab) == Z_OK) { 67307c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource with the %s '%s' " 67317c478bd9Sstevel@tonic-gate "already exists."), rt_to_str(RT_DEVICE), 67327c478bd9Sstevel@tonic-gate pt_to_str(PT_MATCH), 67337c478bd9Sstevel@tonic-gate in_progress_devtab.zone_dev_match); 6734bbec428eSgjelinek saw_error = B_TRUE; 67357c478bd9Sstevel@tonic-gate return; 67367c478bd9Sstevel@tonic-gate } 67377c478bd9Sstevel@tonic-gate err = zonecfg_add_dev(handle, &in_progress_devtab); 67387c478bd9Sstevel@tonic-gate } else { 67397c478bd9Sstevel@tonic-gate err = zonecfg_modify_dev(handle, &old_devtab, 67407c478bd9Sstevel@tonic-gate &in_progress_devtab); 67417c478bd9Sstevel@tonic-gate } 67427c478bd9Sstevel@tonic-gate break; 6743087719fdSdp 67447c478bd9Sstevel@tonic-gate case RT_RCTL: 67457c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 6746087719fdSdp (void) end_check_reqd(in_progress_rctltab.zone_rctl_name, 6747087719fdSdp PT_NAME, &validation_failed); 6748087719fdSdp 67497c478bd9Sstevel@tonic-gate if (in_progress_rctltab.zone_rctl_valptr == NULL) { 67507c478bd9Sstevel@tonic-gate zerr(gettext("no %s specified"), pt_to_str(PT_VALUE)); 6751bbec428eSgjelinek validation_failed = B_TRUE; 67527c478bd9Sstevel@tonic-gate } 6753087719fdSdp 6754087719fdSdp if (validation_failed) { 6755bbec428eSgjelinek saw_error = B_TRUE; 67567c478bd9Sstevel@tonic-gate return; 6757087719fdSdp } 6758087719fdSdp 67597c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 67607c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 67617c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_rctltab.zone_rctl_name, 67627c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_name, 67637c478bd9Sstevel@tonic-gate sizeof (tmp_rctltab.zone_rctl_name)); 67647c478bd9Sstevel@tonic-gate tmp_rctltab.zone_rctl_valptr = NULL; 67657c478bd9Sstevel@tonic-gate err = zonecfg_lookup_rctl(handle, &tmp_rctltab); 67667c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list( 67677c478bd9Sstevel@tonic-gate tmp_rctltab.zone_rctl_valptr); 67687c478bd9Sstevel@tonic-gate if (err == Z_OK) { 67697c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource " 67707c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 67717c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL), pt_to_str(PT_NAME), 67727c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_name); 6773bbec428eSgjelinek saw_error = B_TRUE; 67747c478bd9Sstevel@tonic-gate return; 67757c478bd9Sstevel@tonic-gate } 67767c478bd9Sstevel@tonic-gate err = zonecfg_add_rctl(handle, &in_progress_rctltab); 67777c478bd9Sstevel@tonic-gate } else { 67787c478bd9Sstevel@tonic-gate err = zonecfg_modify_rctl(handle, &old_rctltab, 67797c478bd9Sstevel@tonic-gate &in_progress_rctltab); 67807c478bd9Sstevel@tonic-gate } 67817c478bd9Sstevel@tonic-gate if (err == Z_OK) { 67827c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list( 67837c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr); 67847c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr = NULL; 67857c478bd9Sstevel@tonic-gate } 67867c478bd9Sstevel@tonic-gate break; 6787087719fdSdp 67887c478bd9Sstevel@tonic-gate case RT_ATTR: 67897c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 6790087719fdSdp (void) end_check_reqd(in_progress_attrtab.zone_attr_name, 6791087719fdSdp PT_NAME, &validation_failed); 6792087719fdSdp (void) end_check_reqd(in_progress_attrtab.zone_attr_type, 6793087719fdSdp PT_TYPE, &validation_failed); 6794087719fdSdp (void) end_check_reqd(in_progress_attrtab.zone_attr_value, 6795087719fdSdp PT_VALUE, &validation_failed); 6796087719fdSdp 67977c478bd9Sstevel@tonic-gate if (validate_attr_name(in_progress_attrtab.zone_attr_name) != 6798087719fdSdp Z_OK) 6799bbec428eSgjelinek validation_failed = B_TRUE; 6800087719fdSdp 6801087719fdSdp if (validate_attr_type_val(&in_progress_attrtab) != Z_OK) 6802bbec428eSgjelinek validation_failed = B_TRUE; 6803087719fdSdp 6804087719fdSdp if (validation_failed) { 6805bbec428eSgjelinek saw_error = B_TRUE; 68067c478bd9Sstevel@tonic-gate return; 6807087719fdSdp } 68087c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 68097c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 68107c478bd9Sstevel@tonic-gate bzero(&tmp_attrtab, sizeof (tmp_attrtab)); 68117c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_attrtab.zone_attr_name, 68127c478bd9Sstevel@tonic-gate in_progress_attrtab.zone_attr_name, 68137c478bd9Sstevel@tonic-gate sizeof (tmp_attrtab.zone_attr_name)); 68147c478bd9Sstevel@tonic-gate if (zonecfg_lookup_attr(handle, &tmp_attrtab) == Z_OK) { 68157c478bd9Sstevel@tonic-gate zerr(gettext("An %s resource " 68167c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 68177c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_NAME), 68187c478bd9Sstevel@tonic-gate in_progress_attrtab.zone_attr_name); 6819bbec428eSgjelinek saw_error = B_TRUE; 68207c478bd9Sstevel@tonic-gate return; 68217c478bd9Sstevel@tonic-gate } 68227c478bd9Sstevel@tonic-gate err = zonecfg_add_attr(handle, &in_progress_attrtab); 68237c478bd9Sstevel@tonic-gate } else { 68247c478bd9Sstevel@tonic-gate err = zonecfg_modify_attr(handle, &old_attrtab, 68257c478bd9Sstevel@tonic-gate &in_progress_attrtab); 68267c478bd9Sstevel@tonic-gate } 68277c478bd9Sstevel@tonic-gate break; 6828fa9e4066Sahrens case RT_DATASET: 6829fa9e4066Sahrens /* First make sure everything was filled in. */ 6830fa9e4066Sahrens if (strlen(in_progress_dstab.zone_dataset_name) == 0) { 6831fa9e4066Sahrens zerr("%s %s", pt_to_str(PT_NAME), 6832fa9e4066Sahrens gettext("not specified")); 6833bbec428eSgjelinek saw_error = B_TRUE; 6834bbec428eSgjelinek validation_failed = B_TRUE; 6835fa9e4066Sahrens } 6836fa9e4066Sahrens if (validation_failed) 6837fa9e4066Sahrens return; 6838fa9e4066Sahrens if (end_op == CMD_ADD) { 6839fa9e4066Sahrens /* Make sure there isn't already one like this. */ 6840fa9e4066Sahrens bzero(&tmp_dstab, sizeof (tmp_dstab)); 6841fa9e4066Sahrens (void) strlcpy(tmp_dstab.zone_dataset_name, 6842fa9e4066Sahrens in_progress_dstab.zone_dataset_name, 6843fa9e4066Sahrens sizeof (tmp_dstab.zone_dataset_name)); 6844fa9e4066Sahrens err = zonecfg_lookup_ds(handle, &tmp_dstab); 6845fa9e4066Sahrens if (err == Z_OK) { 6846fa9e4066Sahrens zerr(gettext("A %s resource " 6847fa9e4066Sahrens "with the %s '%s' already exists."), 6848fa9e4066Sahrens rt_to_str(RT_DATASET), pt_to_str(PT_NAME), 6849fa9e4066Sahrens in_progress_dstab.zone_dataset_name); 6850bbec428eSgjelinek saw_error = B_TRUE; 6851fa9e4066Sahrens return; 6852fa9e4066Sahrens } 6853fa9e4066Sahrens err = zonecfg_add_ds(handle, &in_progress_dstab); 6854fa9e4066Sahrens } else { 6855fa9e4066Sahrens err = zonecfg_modify_ds(handle, &old_dstab, 6856fa9e4066Sahrens &in_progress_dstab); 6857fa9e4066Sahrens } 6858fa9e4066Sahrens break; 68590209230bSgjelinek case RT_DCPU: 68600209230bSgjelinek /* Make sure everything was filled in. */ 68610209230bSgjelinek if (end_check_reqd(in_progress_psettab.zone_ncpu_min, 68620209230bSgjelinek PT_NCPUS, &validation_failed) != Z_OK) { 6863bbec428eSgjelinek saw_error = B_TRUE; 68640209230bSgjelinek return; 68650209230bSgjelinek } 68660209230bSgjelinek 68670209230bSgjelinek if (end_op == CMD_ADD) { 68680209230bSgjelinek err = zonecfg_add_pset(handle, &in_progress_psettab); 68690209230bSgjelinek } else { 68700209230bSgjelinek err = zonecfg_modify_pset(handle, &in_progress_psettab); 68710209230bSgjelinek } 68720209230bSgjelinek break; 6873c97ad5cdSakolb case RT_PCAP: 6874c97ad5cdSakolb /* Make sure everything was filled in. */ 6875c97ad5cdSakolb if (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &proc_cap) 6876c97ad5cdSakolb != Z_OK) { 6877c97ad5cdSakolb zerr(gettext("%s not specified"), pt_to_str(PT_NCPUS)); 6878bbec428eSgjelinek saw_error = B_TRUE; 6879bbec428eSgjelinek validation_failed = B_TRUE; 6880c97ad5cdSakolb return; 6881c97ad5cdSakolb } 6882c97ad5cdSakolb err = Z_OK; 6883c97ad5cdSakolb break; 68840209230bSgjelinek case RT_MCAP: 68850209230bSgjelinek /* Make sure everything was filled in. */ 68860209230bSgjelinek res1 = strlen(in_progress_mcaptab.zone_physmem_cap) == 0 ? 68870209230bSgjelinek Z_ERR : Z_OK; 68880209230bSgjelinek res2 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, 68890209230bSgjelinek &swap_limit); 68900209230bSgjelinek res3 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, 68910209230bSgjelinek &locked_limit); 68920209230bSgjelinek 68930209230bSgjelinek if (res1 != Z_OK && res2 != Z_OK && res3 != Z_OK) { 68940209230bSgjelinek zerr(gettext("No property was specified. One of %s, " 68950209230bSgjelinek "%s or %s is required."), pt_to_str(PT_PHYSICAL), 68960209230bSgjelinek pt_to_str(PT_SWAP), pt_to_str(PT_LOCKED)); 6897bbec428eSgjelinek saw_error = B_TRUE; 68980209230bSgjelinek return; 68990209230bSgjelinek } 69000209230bSgjelinek 69010209230bSgjelinek /* if phys & locked are both set, verify locked <= phys */ 69020209230bSgjelinek if (res1 == Z_OK && res3 == Z_OK) { 69030209230bSgjelinek uint64_t phys_limit; 69040209230bSgjelinek char *endp; 69050209230bSgjelinek 69060209230bSgjelinek phys_limit = strtoull( 69070209230bSgjelinek in_progress_mcaptab.zone_physmem_cap, &endp, 10); 69080209230bSgjelinek if (phys_limit < locked_limit) { 69090209230bSgjelinek zerr(gettext("The %s cap must be less than or " 69100209230bSgjelinek "equal to the %s cap."), 69110209230bSgjelinek pt_to_str(PT_LOCKED), 69120209230bSgjelinek pt_to_str(PT_PHYSICAL)); 6913bbec428eSgjelinek saw_error = B_TRUE; 69140209230bSgjelinek return; 69150209230bSgjelinek } 69160209230bSgjelinek } 69170209230bSgjelinek 69180209230bSgjelinek err = Z_OK; 69190209230bSgjelinek if (res1 == Z_OK) { 69200209230bSgjelinek /* 69210209230bSgjelinek * We could be ending from either an add operation 69220209230bSgjelinek * or a select operation. Since all of the properties 69230209230bSgjelinek * within this resource are optional, we always use 69240209230bSgjelinek * modify on the mcap entry. zonecfg_modify_mcap() 69250209230bSgjelinek * will handle both adding and modifying a memory cap. 69260209230bSgjelinek */ 69270209230bSgjelinek err = zonecfg_modify_mcap(handle, &in_progress_mcaptab); 69280209230bSgjelinek } else if (end_op == CMD_SELECT) { 69290209230bSgjelinek /* 69300209230bSgjelinek * If we're ending from a select and the physical 69310209230bSgjelinek * memory cap is empty then the user could have cleared 69320209230bSgjelinek * the physical cap value, so try to delete the entry. 69330209230bSgjelinek */ 69340209230bSgjelinek (void) zonecfg_delete_mcap(handle); 69350209230bSgjelinek } 69360209230bSgjelinek break; 6937cb8a054bSGlenn Faden case RT_ADMIN: 6938cb8a054bSGlenn Faden /* First make sure everything was filled in. */ 6939cb8a054bSGlenn Faden if (end_check_reqd(in_progress_admintab.zone_admin_user, 6940cb8a054bSGlenn Faden PT_USER, &validation_failed) == Z_OK) { 6941cb8a054bSGlenn Faden if (getpwnam(in_progress_admintab.zone_admin_user) 6942cb8a054bSGlenn Faden == NULL) { 6943cb8a054bSGlenn Faden zerr(gettext("%s %s is not a valid username"), 6944cb8a054bSGlenn Faden pt_to_str(PT_USER), 6945cb8a054bSGlenn Faden in_progress_admintab.zone_admin_user); 6946cb8a054bSGlenn Faden validation_failed = B_TRUE; 6947cb8a054bSGlenn Faden } 6948cb8a054bSGlenn Faden } 6949cb8a054bSGlenn Faden 6950cb8a054bSGlenn Faden if (end_check_reqd(in_progress_admintab.zone_admin_auths, 6951cb8a054bSGlenn Faden PT_AUTHS, &validation_failed) == Z_OK) { 6952cb8a054bSGlenn Faden if (!zonecfg_valid_auths( 6953cb8a054bSGlenn Faden in_progress_admintab.zone_admin_auths, 6954cb8a054bSGlenn Faden zone)) { 6955cb8a054bSGlenn Faden validation_failed = B_TRUE; 6956cb8a054bSGlenn Faden } 6957cb8a054bSGlenn Faden } 6958cb8a054bSGlenn Faden 6959cb8a054bSGlenn Faden if (validation_failed) { 6960cb8a054bSGlenn Faden saw_error = B_TRUE; 6961cb8a054bSGlenn Faden return; 6962cb8a054bSGlenn Faden } 6963cb8a054bSGlenn Faden 6964cb8a054bSGlenn Faden if (end_op == CMD_ADD) { 6965cb8a054bSGlenn Faden /* Make sure there isn't already one like this. */ 6966cb8a054bSGlenn Faden bzero(&tmp_admintab, sizeof (tmp_admintab)); 6967cb8a054bSGlenn Faden (void) strlcpy(tmp_admintab.zone_admin_user, 6968cb8a054bSGlenn Faden in_progress_admintab.zone_admin_user, 6969cb8a054bSGlenn Faden sizeof (tmp_admintab.zone_admin_user)); 6970cb8a054bSGlenn Faden err = zonecfg_lookup_admin( 6971cb8a054bSGlenn Faden handle, &tmp_admintab); 6972cb8a054bSGlenn Faden if (err == Z_OK) { 6973cb8a054bSGlenn Faden zerr(gettext("A %s resource " 6974cb8a054bSGlenn Faden "with the %s '%s' already exists."), 6975cb8a054bSGlenn Faden rt_to_str(RT_ADMIN), 6976cb8a054bSGlenn Faden pt_to_str(PT_USER), 6977cb8a054bSGlenn Faden in_progress_admintab.zone_admin_user); 6978cb8a054bSGlenn Faden saw_error = B_TRUE; 6979cb8a054bSGlenn Faden return; 6980cb8a054bSGlenn Faden } 6981cb8a054bSGlenn Faden err = zonecfg_add_admin(handle, 6982cb8a054bSGlenn Faden &in_progress_admintab, zone); 6983cb8a054bSGlenn Faden } else { 6984cb8a054bSGlenn Faden err = zonecfg_modify_admin(handle, 6985cb8a054bSGlenn Faden &old_admintab, &in_progress_admintab, 6986cb8a054bSGlenn Faden zone); 6987cb8a054bSGlenn Faden } 6988cb8a054bSGlenn Faden break; 6989*d2a70789SRichard Lowe case RT_SECFLAGS: 6990*d2a70789SRichard Lowe if (verify_secflags(&in_progress_secflagstab) != B_TRUE) { 6991*d2a70789SRichard Lowe saw_error = B_TRUE; 6992*d2a70789SRichard Lowe return; 6993*d2a70789SRichard Lowe } 6994*d2a70789SRichard Lowe 6995*d2a70789SRichard Lowe if (end_op == CMD_ADD) { 6996*d2a70789SRichard Lowe err = zonecfg_add_secflags(handle, 6997*d2a70789SRichard Lowe &in_progress_secflagstab); 6998*d2a70789SRichard Lowe } else { 6999*d2a70789SRichard Lowe err = zonecfg_modify_secflags(handle, 7000*d2a70789SRichard Lowe &old_secflagstab, &in_progress_secflagstab); 7001*d2a70789SRichard Lowe } 7002*d2a70789SRichard Lowe break; 70037c478bd9Sstevel@tonic-gate default: 70047c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(resource_scope), Z_NO_RESOURCE_TYPE, 7005bbec428eSgjelinek B_TRUE); 7006bbec428eSgjelinek saw_error = B_TRUE; 70077c478bd9Sstevel@tonic-gate return; 70087c478bd9Sstevel@tonic-gate } 70097c478bd9Sstevel@tonic-gate 70107c478bd9Sstevel@tonic-gate if (err != Z_OK) { 7011bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 70127c478bd9Sstevel@tonic-gate } else { 7013bbec428eSgjelinek need_to_commit = B_TRUE; 7014bbec428eSgjelinek global_scope = B_TRUE; 70157c478bd9Sstevel@tonic-gate end_op = -1; 70167c478bd9Sstevel@tonic-gate } 70177c478bd9Sstevel@tonic-gate } 70187c478bd9Sstevel@tonic-gate 70197c478bd9Sstevel@tonic-gate void 70207c478bd9Sstevel@tonic-gate commit_func(cmd_t *cmd) 70217c478bd9Sstevel@tonic-gate { 70227c478bd9Sstevel@tonic-gate int arg; 7023bbec428eSgjelinek boolean_t arg_err = B_FALSE; 70247c478bd9Sstevel@tonic-gate 70257c478bd9Sstevel@tonic-gate optind = 0; 70267ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 70277c478bd9Sstevel@tonic-gate switch (arg) { 70287c478bd9Sstevel@tonic-gate case '?': 70297c478bd9Sstevel@tonic-gate longer_usage(CMD_COMMIT); 7030bbec428eSgjelinek arg_err = B_TRUE; 70317ec75eb8Sgjelinek break; 70327c478bd9Sstevel@tonic-gate default: 70337c478bd9Sstevel@tonic-gate short_usage(CMD_COMMIT); 7034bbec428eSgjelinek arg_err = B_TRUE; 70357ec75eb8Sgjelinek break; 70367c478bd9Sstevel@tonic-gate } 70377c478bd9Sstevel@tonic-gate } 70387ec75eb8Sgjelinek if (arg_err) 70397ec75eb8Sgjelinek return; 70407ec75eb8Sgjelinek 70417c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 70427c478bd9Sstevel@tonic-gate short_usage(CMD_COMMIT); 70437c478bd9Sstevel@tonic-gate return; 70447c478bd9Sstevel@tonic-gate } 70457c478bd9Sstevel@tonic-gate 70467c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_COMMIT)) 70477c478bd9Sstevel@tonic-gate return; 70487c478bd9Sstevel@tonic-gate 70497c478bd9Sstevel@tonic-gate assert(cmd != NULL); 70507c478bd9Sstevel@tonic-gate 70517c478bd9Sstevel@tonic-gate cmd->cmd_argc = 1; 70527c478bd9Sstevel@tonic-gate /* 70537c478bd9Sstevel@tonic-gate * cmd_arg normally comes from a strdup() in the lexer, and the 70547c478bd9Sstevel@tonic-gate * whole cmd structure and its (char *) attributes are freed at 70557c478bd9Sstevel@tonic-gate * the completion of each command, so the strdup() below is needed 70567c478bd9Sstevel@tonic-gate * to match this and prevent a core dump from trying to free() 70577c478bd9Sstevel@tonic-gate * something that can't be. 70587c478bd9Sstevel@tonic-gate */ 70597c478bd9Sstevel@tonic-gate if ((cmd->cmd_argv[0] = strdup("save")) == NULL) { 7060bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_TRUE); 70617c478bd9Sstevel@tonic-gate exit(Z_ERR); 70627c478bd9Sstevel@tonic-gate } 70637c478bd9Sstevel@tonic-gate cmd->cmd_argv[1] = NULL; 70647c478bd9Sstevel@tonic-gate verify_func(cmd); 70657c478bd9Sstevel@tonic-gate } 70667c478bd9Sstevel@tonic-gate 70677c478bd9Sstevel@tonic-gate void 70687c478bd9Sstevel@tonic-gate revert_func(cmd_t *cmd) 70697c478bd9Sstevel@tonic-gate { 70707c478bd9Sstevel@tonic-gate char line[128]; /* enough to ask a question */ 7071bbec428eSgjelinek boolean_t force = B_FALSE; 7072bbec428eSgjelinek boolean_t arg_err = B_FALSE; 70737c478bd9Sstevel@tonic-gate int err, arg, answer; 70747c478bd9Sstevel@tonic-gate 70757c478bd9Sstevel@tonic-gate optind = 0; 70767c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 70777c478bd9Sstevel@tonic-gate switch (arg) { 70787c478bd9Sstevel@tonic-gate case '?': 70797c478bd9Sstevel@tonic-gate longer_usage(CMD_REVERT); 7080bbec428eSgjelinek arg_err = B_TRUE; 70817ec75eb8Sgjelinek break; 70827c478bd9Sstevel@tonic-gate case 'F': 7083bbec428eSgjelinek force = B_TRUE; 70847c478bd9Sstevel@tonic-gate break; 70857c478bd9Sstevel@tonic-gate default: 70867c478bd9Sstevel@tonic-gate short_usage(CMD_REVERT); 7087bbec428eSgjelinek arg_err = B_TRUE; 70887ec75eb8Sgjelinek break; 70897c478bd9Sstevel@tonic-gate } 70907c478bd9Sstevel@tonic-gate } 70917ec75eb8Sgjelinek if (arg_err) 70927ec75eb8Sgjelinek return; 70937ec75eb8Sgjelinek 70947c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 70957c478bd9Sstevel@tonic-gate short_usage(CMD_REVERT); 70967c478bd9Sstevel@tonic-gate return; 70977c478bd9Sstevel@tonic-gate } 70987c478bd9Sstevel@tonic-gate 70997c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_REVERT)) 71007c478bd9Sstevel@tonic-gate return; 71017c478bd9Sstevel@tonic-gate 71025b418297Sjv if (!global_scope) { 71035b418297Sjv zerr(gettext("You can only use %s in the global scope.\nUse" 71045b418297Sjv " '%s' to cancel changes to a resource specification."), 71055b418297Sjv cmd_to_str(CMD_REVERT), cmd_to_str(CMD_CANCEL)); 71065b418297Sjv saw_error = B_TRUE; 71075b418297Sjv return; 71085b418297Sjv } 71095b418297Sjv 71107c478bd9Sstevel@tonic-gate if (zonecfg_check_handle(handle) != Z_OK) { 71117c478bd9Sstevel@tonic-gate zerr(gettext("No changes to revert.")); 7112bbec428eSgjelinek saw_error = B_TRUE; 71137c478bd9Sstevel@tonic-gate return; 71147c478bd9Sstevel@tonic-gate } 71157c478bd9Sstevel@tonic-gate 71167c478bd9Sstevel@tonic-gate if (!force) { 71177c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 71187c478bd9Sstevel@tonic-gate gettext("Are you sure you want to revert")); 7119bbec428eSgjelinek if ((answer = ask_yesno(B_FALSE, line)) == -1) { 71207c478bd9Sstevel@tonic-gate zerr(gettext("Input not from terminal and -F not " 71217c478bd9Sstevel@tonic-gate "specified:\n%s command ignored, exiting."), 71227c478bd9Sstevel@tonic-gate cmd_to_str(CMD_REVERT)); 71237c478bd9Sstevel@tonic-gate exit(Z_ERR); 71247c478bd9Sstevel@tonic-gate } 71257c478bd9Sstevel@tonic-gate if (answer != 1) 71267c478bd9Sstevel@tonic-gate return; 71277c478bd9Sstevel@tonic-gate } 71287c478bd9Sstevel@tonic-gate 7129cb8a054bSGlenn Faden /* 7130cb8a054bSGlenn Faden * Reset any pending admins that were 7131cb8a054bSGlenn Faden * removed from the previous zone 7132cb8a054bSGlenn Faden */ 7133cb8a054bSGlenn Faden zonecfg_remove_userauths(handle, "", zone, B_FALSE); 7134cb8a054bSGlenn Faden 71357c478bd9Sstevel@tonic-gate /* 71367c478bd9Sstevel@tonic-gate * Time for a new handle: finish the old one off first 71377c478bd9Sstevel@tonic-gate * then get a new one properly to avoid leaks. 71387c478bd9Sstevel@tonic-gate */ 71397c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 71407c478bd9Sstevel@tonic-gate if ((handle = zonecfg_init_handle()) == NULL) { 7141bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 71427c478bd9Sstevel@tonic-gate exit(Z_ERR); 71437c478bd9Sstevel@tonic-gate } 7144cb8a054bSGlenn Faden 7145087719fdSdp if ((err = zonecfg_get_handle(revert_zone, handle)) != Z_OK) { 7146bbec428eSgjelinek saw_error = B_TRUE; 7147bbec428eSgjelinek got_handle = B_FALSE; 71487c478bd9Sstevel@tonic-gate if (err == Z_NO_ZONE) 71497c478bd9Sstevel@tonic-gate zerr(gettext("%s: no such saved zone to revert to."), 7150087719fdSdp revert_zone); 71517c478bd9Sstevel@tonic-gate else 7152bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 71537c478bd9Sstevel@tonic-gate } 7154087719fdSdp (void) strlcpy(zone, revert_zone, sizeof (zone)); 71557c478bd9Sstevel@tonic-gate } 71567c478bd9Sstevel@tonic-gate 71577c478bd9Sstevel@tonic-gate void 71587c478bd9Sstevel@tonic-gate help_func(cmd_t *cmd) 71597c478bd9Sstevel@tonic-gate { 71607c478bd9Sstevel@tonic-gate int i; 71617c478bd9Sstevel@tonic-gate 71627c478bd9Sstevel@tonic-gate assert(cmd != NULL); 71637c478bd9Sstevel@tonic-gate 71647c478bd9Sstevel@tonic-gate if (cmd->cmd_argc == 0) { 7165bbec428eSgjelinek usage(B_TRUE, global_scope ? HELP_SUBCMDS : HELP_RES_SCOPE); 71667c478bd9Sstevel@tonic-gate return; 71677c478bd9Sstevel@tonic-gate } 71687c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "usage") == 0) { 7169bbec428eSgjelinek usage(B_TRUE, HELP_USAGE); 71707c478bd9Sstevel@tonic-gate return; 71717c478bd9Sstevel@tonic-gate } 71727c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "commands") == 0) { 7173bbec428eSgjelinek usage(B_TRUE, HELP_SUBCMDS); 71747c478bd9Sstevel@tonic-gate return; 71757c478bd9Sstevel@tonic-gate } 71767c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "syntax") == 0) { 7177bbec428eSgjelinek usage(B_TRUE, HELP_SYNTAX | HELP_RES_PROPS); 71787c478bd9Sstevel@tonic-gate return; 71797c478bd9Sstevel@tonic-gate } 71807c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "-?") == 0) { 71817c478bd9Sstevel@tonic-gate longer_usage(CMD_HELP); 71827c478bd9Sstevel@tonic-gate return; 71837c478bd9Sstevel@tonic-gate } 71847c478bd9Sstevel@tonic-gate 71857c478bd9Sstevel@tonic-gate for (i = 0; i <= CMD_MAX; i++) { 71867c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], cmd_to_str(i)) == 0) { 71877c478bd9Sstevel@tonic-gate longer_usage(i); 71887c478bd9Sstevel@tonic-gate return; 71897c478bd9Sstevel@tonic-gate } 71907c478bd9Sstevel@tonic-gate } 71917c478bd9Sstevel@tonic-gate /* We do not use zerr() here because we do not want its extra \n. */ 71927c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Unknown help subject %s. "), 71937c478bd9Sstevel@tonic-gate cmd->cmd_argv[0]); 7194bbec428eSgjelinek usage(B_FALSE, HELP_META); 71957c478bd9Sstevel@tonic-gate } 71967c478bd9Sstevel@tonic-gate 71977c478bd9Sstevel@tonic-gate static int 71987c478bd9Sstevel@tonic-gate string_to_yyin(char *string) 71997c478bd9Sstevel@tonic-gate { 72007c478bd9Sstevel@tonic-gate if ((yyin = tmpfile()) == NULL) { 7201bbec428eSgjelinek zone_perror(execname, Z_TEMP_FILE, B_TRUE); 72027c478bd9Sstevel@tonic-gate return (Z_ERR); 72037c478bd9Sstevel@tonic-gate } 72047c478bd9Sstevel@tonic-gate if (fwrite(string, strlen(string), 1, yyin) != 1) { 7205bbec428eSgjelinek zone_perror(execname, Z_TEMP_FILE, B_TRUE); 72067c478bd9Sstevel@tonic-gate return (Z_ERR); 72077c478bd9Sstevel@tonic-gate } 72087c478bd9Sstevel@tonic-gate if (fseek(yyin, 0, SEEK_SET) != 0) { 7209bbec428eSgjelinek zone_perror(execname, Z_TEMP_FILE, B_TRUE); 72107c478bd9Sstevel@tonic-gate return (Z_ERR); 72117c478bd9Sstevel@tonic-gate } 72127c478bd9Sstevel@tonic-gate return (Z_OK); 72137c478bd9Sstevel@tonic-gate } 72147c478bd9Sstevel@tonic-gate 72157c478bd9Sstevel@tonic-gate /* This is the back-end helper function for read_input() below. */ 72167c478bd9Sstevel@tonic-gate 72177c478bd9Sstevel@tonic-gate static int 72187c478bd9Sstevel@tonic-gate cleanup() 72197c478bd9Sstevel@tonic-gate { 72207c478bd9Sstevel@tonic-gate int answer; 72217c478bd9Sstevel@tonic-gate cmd_t *cmd; 72227c478bd9Sstevel@tonic-gate 72237c478bd9Sstevel@tonic-gate if (!interactive_mode && !cmd_file_mode) { 72247c478bd9Sstevel@tonic-gate /* 72257c478bd9Sstevel@tonic-gate * If we're not in interactive mode, and we're not in command 72267c478bd9Sstevel@tonic-gate * file mode, then we must be in commands-from-the-command-line 72277c478bd9Sstevel@tonic-gate * mode. As such, we can't loop back and ask for more input. 72287c478bd9Sstevel@tonic-gate * It was OK to prompt for such things as whether or not to 72297c478bd9Sstevel@tonic-gate * really delete a zone in the command handler called from 72307c478bd9Sstevel@tonic-gate * yyparse() above, but "really quit?" makes no sense in this 72317c478bd9Sstevel@tonic-gate * context. So disable prompting. 72327c478bd9Sstevel@tonic-gate */ 7233bbec428eSgjelinek ok_to_prompt = B_FALSE; 72347c478bd9Sstevel@tonic-gate } 72357c478bd9Sstevel@tonic-gate if (!global_scope) { 72367c478bd9Sstevel@tonic-gate if (!time_to_exit) { 72377c478bd9Sstevel@tonic-gate /* 72387c478bd9Sstevel@tonic-gate * Just print a simple error message in the -1 case, 72397c478bd9Sstevel@tonic-gate * since exit_func() already handles that case, and 72407c478bd9Sstevel@tonic-gate * EOF means we are finished anyway. 72417c478bd9Sstevel@tonic-gate */ 7242bbec428eSgjelinek answer = ask_yesno(B_FALSE, 72437c478bd9Sstevel@tonic-gate gettext("Resource incomplete; really quit")); 72447c478bd9Sstevel@tonic-gate if (answer == -1) { 72457c478bd9Sstevel@tonic-gate zerr(gettext("Resource incomplete.")); 72467c478bd9Sstevel@tonic-gate return (Z_ERR); 72477c478bd9Sstevel@tonic-gate } 72487c478bd9Sstevel@tonic-gate if (answer != 1) { 72497c478bd9Sstevel@tonic-gate yyin = stdin; 72507c478bd9Sstevel@tonic-gate return (Z_REPEAT); 72517c478bd9Sstevel@tonic-gate } 72527c478bd9Sstevel@tonic-gate } else { 7253bbec428eSgjelinek saw_error = B_TRUE; 72547c478bd9Sstevel@tonic-gate } 72557c478bd9Sstevel@tonic-gate } 72567c478bd9Sstevel@tonic-gate /* 72577c478bd9Sstevel@tonic-gate * Make sure we tried something and that the handle checks 72587c478bd9Sstevel@tonic-gate * out, or we would get a false error trying to commit. 72597c478bd9Sstevel@tonic-gate */ 72607c478bd9Sstevel@tonic-gate if (need_to_commit && zonecfg_check_handle(handle) == Z_OK) { 72617c478bd9Sstevel@tonic-gate if ((cmd = alloc_cmd()) == NULL) { 7262bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_TRUE); 72637c478bd9Sstevel@tonic-gate return (Z_ERR); 72647c478bd9Sstevel@tonic-gate } 72657c478bd9Sstevel@tonic-gate cmd->cmd_argc = 0; 72667c478bd9Sstevel@tonic-gate cmd->cmd_argv[0] = NULL; 72677c478bd9Sstevel@tonic-gate commit_func(cmd); 72687c478bd9Sstevel@tonic-gate free_cmd(cmd); 72697c478bd9Sstevel@tonic-gate /* 72707c478bd9Sstevel@tonic-gate * need_to_commit will get set back to FALSE if the 72717c478bd9Sstevel@tonic-gate * configuration is saved successfully. 72727c478bd9Sstevel@tonic-gate */ 72737c478bd9Sstevel@tonic-gate if (need_to_commit) { 72747c478bd9Sstevel@tonic-gate if (force_exit) { 72757c478bd9Sstevel@tonic-gate zerr(gettext("Configuration not saved.")); 72767c478bd9Sstevel@tonic-gate return (Z_ERR); 72777c478bd9Sstevel@tonic-gate } 7278bbec428eSgjelinek answer = ask_yesno(B_FALSE, 72797c478bd9Sstevel@tonic-gate gettext("Configuration not saved; really quit")); 72807c478bd9Sstevel@tonic-gate if (answer == -1) { 72817c478bd9Sstevel@tonic-gate zerr(gettext("Configuration not saved.")); 72827c478bd9Sstevel@tonic-gate return (Z_ERR); 72837c478bd9Sstevel@tonic-gate } 72847c478bd9Sstevel@tonic-gate if (answer != 1) { 7285bbec428eSgjelinek time_to_exit = B_FALSE; 72867c478bd9Sstevel@tonic-gate yyin = stdin; 72877c478bd9Sstevel@tonic-gate return (Z_REPEAT); 72887c478bd9Sstevel@tonic-gate } 72897c478bd9Sstevel@tonic-gate } 72907c478bd9Sstevel@tonic-gate } 72917c478bd9Sstevel@tonic-gate return ((need_to_commit || saw_error) ? Z_ERR : Z_OK); 72927c478bd9Sstevel@tonic-gate } 72937c478bd9Sstevel@tonic-gate 72947c478bd9Sstevel@tonic-gate /* 72957c478bd9Sstevel@tonic-gate * read_input() is the driver of this program. It is a wrapper around 72967c478bd9Sstevel@tonic-gate * yyparse(), printing appropriate prompts when needed, checking for 72977c478bd9Sstevel@tonic-gate * exit conditions and reacting appropriately [the latter in its cleanup() 72987c478bd9Sstevel@tonic-gate * helper function]. 72997c478bd9Sstevel@tonic-gate * 73007c478bd9Sstevel@tonic-gate * Like most zonecfg functions, it returns Z_OK or Z_ERR, *or* Z_REPEAT 73017c478bd9Sstevel@tonic-gate * so do_interactive() knows that we are not really done (i.e, we asked 73027c478bd9Sstevel@tonic-gate * the user if we should really quit and the user said no). 73037c478bd9Sstevel@tonic-gate */ 73047c478bd9Sstevel@tonic-gate static int 73057c478bd9Sstevel@tonic-gate read_input() 73067c478bd9Sstevel@tonic-gate { 7307bbec428eSgjelinek boolean_t yyin_is_a_tty = isatty(fileno(yyin)); 73087c478bd9Sstevel@tonic-gate /* 73097c478bd9Sstevel@tonic-gate * The prompt is "e:z> " or "e:z:r> " where e is execname, z is zone 73107c478bd9Sstevel@tonic-gate * and r is resource_scope: 5 is for the two ":"s + "> " + terminator. 73117c478bd9Sstevel@tonic-gate */ 73127c478bd9Sstevel@tonic-gate char prompt[MAXPATHLEN + ZONENAME_MAX + MAX_RT_STRLEN + 5], *line; 73137c478bd9Sstevel@tonic-gate 73147c478bd9Sstevel@tonic-gate /* yyin should have been set to the appropriate (FILE *) if not stdin */ 7315bbec428eSgjelinek newline_terminated = B_TRUE; 73167c478bd9Sstevel@tonic-gate for (;;) { 73177c478bd9Sstevel@tonic-gate if (yyin_is_a_tty) { 73187c478bd9Sstevel@tonic-gate if (newline_terminated) { 73197c478bd9Sstevel@tonic-gate if (global_scope) 73207c478bd9Sstevel@tonic-gate (void) snprintf(prompt, sizeof (prompt), 73217c478bd9Sstevel@tonic-gate "%s:%s> ", execname, zone); 73227c478bd9Sstevel@tonic-gate else 73237c478bd9Sstevel@tonic-gate (void) snprintf(prompt, sizeof (prompt), 73247c478bd9Sstevel@tonic-gate "%s:%s:%s> ", execname, zone, 73257c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 73267c478bd9Sstevel@tonic-gate } 73277c478bd9Sstevel@tonic-gate /* 73287c478bd9Sstevel@tonic-gate * If the user hits ^C then we want to catch it and 73297c478bd9Sstevel@tonic-gate * start over. If the user hits EOF then we want to 73307c478bd9Sstevel@tonic-gate * bail out. 73317c478bd9Sstevel@tonic-gate */ 73327c478bd9Sstevel@tonic-gate line = gl_get_line(gl, prompt, NULL, -1); 73337c478bd9Sstevel@tonic-gate if (gl_return_status(gl) == GLR_SIGNAL) { 73347c478bd9Sstevel@tonic-gate gl_abandon_line(gl); 73357c478bd9Sstevel@tonic-gate continue; 73367c478bd9Sstevel@tonic-gate } 73377c478bd9Sstevel@tonic-gate if (line == NULL) 73387c478bd9Sstevel@tonic-gate break; 73397c478bd9Sstevel@tonic-gate (void) string_to_yyin(line); 73407c478bd9Sstevel@tonic-gate while (!feof(yyin)) 73417c478bd9Sstevel@tonic-gate yyparse(); 73427c478bd9Sstevel@tonic-gate } else { 73437c478bd9Sstevel@tonic-gate yyparse(); 73447c478bd9Sstevel@tonic-gate } 73457c478bd9Sstevel@tonic-gate /* Bail out on an error in command file mode. */ 73467c478bd9Sstevel@tonic-gate if (saw_error && cmd_file_mode && !interactive_mode) 7347bbec428eSgjelinek time_to_exit = B_TRUE; 73487c478bd9Sstevel@tonic-gate if (time_to_exit || (!yyin_is_a_tty && feof(yyin))) 73497c478bd9Sstevel@tonic-gate break; 73507c478bd9Sstevel@tonic-gate } 73517c478bd9Sstevel@tonic-gate return (cleanup()); 73527c478bd9Sstevel@tonic-gate } 73537c478bd9Sstevel@tonic-gate 73547c478bd9Sstevel@tonic-gate /* 73557c478bd9Sstevel@tonic-gate * This function is used in the zonecfg-interactive-mode scenario: it just 73567c478bd9Sstevel@tonic-gate * calls read_input() until we are done. 73577c478bd9Sstevel@tonic-gate */ 73587c478bd9Sstevel@tonic-gate 73597c478bd9Sstevel@tonic-gate static int 73607c478bd9Sstevel@tonic-gate do_interactive(void) 73617c478bd9Sstevel@tonic-gate { 73627c478bd9Sstevel@tonic-gate int err; 73637c478bd9Sstevel@tonic-gate 7364bbec428eSgjelinek interactive_mode = B_TRUE; 73657c478bd9Sstevel@tonic-gate if (!read_only_mode) { 73667c478bd9Sstevel@tonic-gate /* 73677c478bd9Sstevel@tonic-gate * Try to set things up proactively in interactive mode, so 73687c478bd9Sstevel@tonic-gate * that if the zone in question does not exist yet, we can 73697c478bd9Sstevel@tonic-gate * provide the user with a clue. 73707c478bd9Sstevel@tonic-gate */ 7371bbec428eSgjelinek (void) initialize(B_FALSE); 73727c478bd9Sstevel@tonic-gate } 7373087719fdSdp do { 73747c478bd9Sstevel@tonic-gate err = read_input(); 7375087719fdSdp } while (err == Z_REPEAT); 73767c478bd9Sstevel@tonic-gate return (err); 73777c478bd9Sstevel@tonic-gate } 73787c478bd9Sstevel@tonic-gate 73797c478bd9Sstevel@tonic-gate /* 73807c478bd9Sstevel@tonic-gate * cmd_file is slightly more complicated, as it has to open the command file 73817c478bd9Sstevel@tonic-gate * and set yyin appropriately. Once that is done, though, it just calls 73827c478bd9Sstevel@tonic-gate * read_input(), and only once, since prompting is not possible. 73837c478bd9Sstevel@tonic-gate */ 73847c478bd9Sstevel@tonic-gate 73857c478bd9Sstevel@tonic-gate static int 73867c478bd9Sstevel@tonic-gate cmd_file(char *file) 73877c478bd9Sstevel@tonic-gate { 73887c478bd9Sstevel@tonic-gate FILE *infile; 73897c478bd9Sstevel@tonic-gate int err; 73907c478bd9Sstevel@tonic-gate struct stat statbuf; 7391bbec428eSgjelinek boolean_t using_real_file = (strcmp(file, "-") != 0); 73927c478bd9Sstevel@tonic-gate 73937c478bd9Sstevel@tonic-gate if (using_real_file) { 73947c478bd9Sstevel@tonic-gate /* 73957c478bd9Sstevel@tonic-gate * zerr() prints a line number in cmd_file_mode, which we do 73967c478bd9Sstevel@tonic-gate * not want here, so temporarily unset it. 73977c478bd9Sstevel@tonic-gate */ 7398bbec428eSgjelinek cmd_file_mode = B_FALSE; 73997c478bd9Sstevel@tonic-gate if ((infile = fopen(file, "r")) == NULL) { 74007c478bd9Sstevel@tonic-gate zerr(gettext("could not open file %s: %s"), 74017c478bd9Sstevel@tonic-gate file, strerror(errno)); 74027c478bd9Sstevel@tonic-gate return (Z_ERR); 74037c478bd9Sstevel@tonic-gate } 74047c478bd9Sstevel@tonic-gate if ((err = fstat(fileno(infile), &statbuf)) != 0) { 74057c478bd9Sstevel@tonic-gate zerr(gettext("could not stat file %s: %s"), 74067c478bd9Sstevel@tonic-gate file, strerror(errno)); 74077c478bd9Sstevel@tonic-gate err = Z_ERR; 74087c478bd9Sstevel@tonic-gate goto done; 74097c478bd9Sstevel@tonic-gate } 74107c478bd9Sstevel@tonic-gate if (!S_ISREG(statbuf.st_mode)) { 74117c478bd9Sstevel@tonic-gate zerr(gettext("%s is not a regular file."), file); 74127c478bd9Sstevel@tonic-gate err = Z_ERR; 74137c478bd9Sstevel@tonic-gate goto done; 74147c478bd9Sstevel@tonic-gate } 74157c478bd9Sstevel@tonic-gate yyin = infile; 7416bbec428eSgjelinek cmd_file_mode = B_TRUE; 7417bbec428eSgjelinek ok_to_prompt = B_FALSE; 74187c478bd9Sstevel@tonic-gate } else { 74197c478bd9Sstevel@tonic-gate /* 74207c478bd9Sstevel@tonic-gate * "-f -" is essentially the same as interactive mode, 74217c478bd9Sstevel@tonic-gate * so treat it that way. 74227c478bd9Sstevel@tonic-gate */ 7423bbec428eSgjelinek interactive_mode = B_TRUE; 74247c478bd9Sstevel@tonic-gate } 74257c478bd9Sstevel@tonic-gate /* Z_REPEAT is for interactive mode; treat it like Z_ERR here. */ 74267c478bd9Sstevel@tonic-gate if ((err = read_input()) == Z_REPEAT) 74277c478bd9Sstevel@tonic-gate err = Z_ERR; 74287c478bd9Sstevel@tonic-gate done: 74297c478bd9Sstevel@tonic-gate if (using_real_file) 74307c478bd9Sstevel@tonic-gate (void) fclose(infile); 74317c478bd9Sstevel@tonic-gate return (err); 74327c478bd9Sstevel@tonic-gate } 74337c478bd9Sstevel@tonic-gate 74347c478bd9Sstevel@tonic-gate /* 74357c478bd9Sstevel@tonic-gate * Since yacc is based on reading from a (FILE *) whereas what we get from 74367c478bd9Sstevel@tonic-gate * the command line is in argv format, we need to convert when the user 74377c478bd9Sstevel@tonic-gate * gives us commands directly from the command line. That is done here by 74387c478bd9Sstevel@tonic-gate * concatenating the argv list into a space-separated string, writing it 74397c478bd9Sstevel@tonic-gate * to a temp file, and rewinding the file so yyin can be set to it. Then 74407c478bd9Sstevel@tonic-gate * we call read_input(), and only once, since prompting about whether to 74417c478bd9Sstevel@tonic-gate * continue or quit would make no sense in this context. 74427c478bd9Sstevel@tonic-gate */ 74437c478bd9Sstevel@tonic-gate 74447c478bd9Sstevel@tonic-gate static int 74457c478bd9Sstevel@tonic-gate one_command_at_a_time(int argc, char *argv[]) 74467c478bd9Sstevel@tonic-gate { 74477c478bd9Sstevel@tonic-gate char *command; 74487c478bd9Sstevel@tonic-gate size_t len = 2; /* terminal \n\0 */ 74497c478bd9Sstevel@tonic-gate int i, err; 74507c478bd9Sstevel@tonic-gate 74517c478bd9Sstevel@tonic-gate for (i = 0; i < argc; i++) 74527c478bd9Sstevel@tonic-gate len += strlen(argv[i]) + 1; 74537c478bd9Sstevel@tonic-gate if ((command = malloc(len)) == NULL) { 7454bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 74557c478bd9Sstevel@tonic-gate return (Z_ERR); 74567c478bd9Sstevel@tonic-gate } 74577c478bd9Sstevel@tonic-gate (void) strlcpy(command, argv[0], len); 74587c478bd9Sstevel@tonic-gate for (i = 1; i < argc; i++) { 74597c478bd9Sstevel@tonic-gate (void) strlcat(command, " ", len); 74607c478bd9Sstevel@tonic-gate (void) strlcat(command, argv[i], len); 74617c478bd9Sstevel@tonic-gate } 74627c478bd9Sstevel@tonic-gate (void) strlcat(command, "\n", len); 74637c478bd9Sstevel@tonic-gate err = string_to_yyin(command); 74647c478bd9Sstevel@tonic-gate free(command); 74657c478bd9Sstevel@tonic-gate if (err != Z_OK) 74667c478bd9Sstevel@tonic-gate return (err); 74677c478bd9Sstevel@tonic-gate while (!feof(yyin)) 74687c478bd9Sstevel@tonic-gate yyparse(); 74697c478bd9Sstevel@tonic-gate return (cleanup()); 74707c478bd9Sstevel@tonic-gate } 74717c478bd9Sstevel@tonic-gate 74727c478bd9Sstevel@tonic-gate static char * 74737c478bd9Sstevel@tonic-gate get_execbasename(char *execfullname) 74747c478bd9Sstevel@tonic-gate { 74757c478bd9Sstevel@tonic-gate char *last_slash, *execbasename; 74767c478bd9Sstevel@tonic-gate 74777c478bd9Sstevel@tonic-gate /* guard against '/' at end of command invocation */ 74787c478bd9Sstevel@tonic-gate for (;;) { 74797c478bd9Sstevel@tonic-gate last_slash = strrchr(execfullname, '/'); 74807c478bd9Sstevel@tonic-gate if (last_slash == NULL) { 74817c478bd9Sstevel@tonic-gate execbasename = execfullname; 74827c478bd9Sstevel@tonic-gate break; 74837c478bd9Sstevel@tonic-gate } else { 74847c478bd9Sstevel@tonic-gate execbasename = last_slash + 1; 74857c478bd9Sstevel@tonic-gate if (*execbasename == '\0') { 74867c478bd9Sstevel@tonic-gate *last_slash = '\0'; 74877c478bd9Sstevel@tonic-gate continue; 74887c478bd9Sstevel@tonic-gate } 74897c478bd9Sstevel@tonic-gate break; 74907c478bd9Sstevel@tonic-gate } 74917c478bd9Sstevel@tonic-gate } 74927c478bd9Sstevel@tonic-gate return (execbasename); 74937c478bd9Sstevel@tonic-gate } 74947c478bd9Sstevel@tonic-gate 74957c478bd9Sstevel@tonic-gate int 74967c478bd9Sstevel@tonic-gate main(int argc, char *argv[]) 74977c478bd9Sstevel@tonic-gate { 74987c478bd9Sstevel@tonic-gate int err, arg; 7499555afedfScarlsonj struct stat st; 75007c478bd9Sstevel@tonic-gate 75017c478bd9Sstevel@tonic-gate /* This must be before anything goes to stdout. */ 75027c478bd9Sstevel@tonic-gate setbuf(stdout, NULL); 75037c478bd9Sstevel@tonic-gate 7504bbec428eSgjelinek saw_error = B_FALSE; 7505bbec428eSgjelinek cmd_file_mode = B_FALSE; 75067c478bd9Sstevel@tonic-gate execname = get_execbasename(argv[0]); 75077c478bd9Sstevel@tonic-gate 75087c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 75097c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 75107c478bd9Sstevel@tonic-gate 75117c478bd9Sstevel@tonic-gate if (getzoneid() != GLOBAL_ZONEID) { 75127c478bd9Sstevel@tonic-gate zerr(gettext("%s can only be run from the global zone."), 75137c478bd9Sstevel@tonic-gate execname); 75147c478bd9Sstevel@tonic-gate exit(Z_ERR); 75157c478bd9Sstevel@tonic-gate } 75167c478bd9Sstevel@tonic-gate 75177c478bd9Sstevel@tonic-gate if (argc < 2) { 7518bbec428eSgjelinek usage(B_FALSE, HELP_USAGE | HELP_SUBCMDS); 75197c478bd9Sstevel@tonic-gate exit(Z_USAGE); 75207c478bd9Sstevel@tonic-gate } 75217c478bd9Sstevel@tonic-gate if (strcmp(argv[1], cmd_to_str(CMD_HELP)) == 0) { 75227c478bd9Sstevel@tonic-gate (void) one_command_at_a_time(argc - 1, &(argv[1])); 75237c478bd9Sstevel@tonic-gate exit(Z_OK); 75247c478bd9Sstevel@tonic-gate } 75257c478bd9Sstevel@tonic-gate 7526555afedfScarlsonj while ((arg = getopt(argc, argv, "?f:R:z:")) != EOF) { 75277c478bd9Sstevel@tonic-gate switch (arg) { 75287c478bd9Sstevel@tonic-gate case '?': 75297c478bd9Sstevel@tonic-gate if (optopt == '?') 7530bbec428eSgjelinek usage(B_TRUE, HELP_USAGE | HELP_SUBCMDS); 75317c478bd9Sstevel@tonic-gate else 7532bbec428eSgjelinek usage(B_FALSE, HELP_USAGE); 75337c478bd9Sstevel@tonic-gate exit(Z_USAGE); 75347c478bd9Sstevel@tonic-gate /* NOTREACHED */ 75357c478bd9Sstevel@tonic-gate case 'f': 75367c478bd9Sstevel@tonic-gate cmd_file_name = optarg; 7537bbec428eSgjelinek cmd_file_mode = B_TRUE; 75387c478bd9Sstevel@tonic-gate break; 7539555afedfScarlsonj case 'R': 7540555afedfScarlsonj if (*optarg != '/') { 7541555afedfScarlsonj zerr(gettext("root path must be absolute: %s"), 7542555afedfScarlsonj optarg); 7543555afedfScarlsonj exit(Z_USAGE); 7544555afedfScarlsonj } 7545555afedfScarlsonj if (stat(optarg, &st) == -1 || !S_ISDIR(st.st_mode)) { 7546555afedfScarlsonj zerr(gettext( 7547555afedfScarlsonj "root path must be a directory: %s"), 7548555afedfScarlsonj optarg); 7549555afedfScarlsonj exit(Z_USAGE); 7550555afedfScarlsonj } 7551555afedfScarlsonj zonecfg_set_root(optarg); 7552555afedfScarlsonj break; 75537c478bd9Sstevel@tonic-gate case 'z': 75540209230bSgjelinek if (strcmp(optarg, GLOBAL_ZONENAME) == 0) { 7555bbec428eSgjelinek global_zone = B_TRUE; 75560209230bSgjelinek } else if (zonecfg_validate_zonename(optarg) != Z_OK) { 7557bbec428eSgjelinek zone_perror(optarg, Z_BOGUS_ZONE_NAME, B_TRUE); 7558bbec428eSgjelinek usage(B_FALSE, HELP_SYNTAX); 7559087719fdSdp exit(Z_USAGE); 7560087719fdSdp } 7561087719fdSdp (void) strlcpy(zone, optarg, sizeof (zone)); 7562087719fdSdp (void) strlcpy(revert_zone, optarg, sizeof (zone)); 75637c478bd9Sstevel@tonic-gate break; 75647c478bd9Sstevel@tonic-gate default: 7565bbec428eSgjelinek usage(B_FALSE, HELP_USAGE); 75667c478bd9Sstevel@tonic-gate exit(Z_USAGE); 75677c478bd9Sstevel@tonic-gate } 75687c478bd9Sstevel@tonic-gate } 75697c478bd9Sstevel@tonic-gate 7570087719fdSdp if (optind > argc || strcmp(zone, "") == 0) { 7571bbec428eSgjelinek usage(B_FALSE, HELP_USAGE); 75727c478bd9Sstevel@tonic-gate exit(Z_USAGE); 75737c478bd9Sstevel@tonic-gate } 75747c478bd9Sstevel@tonic-gate 7575087719fdSdp if ((err = zonecfg_access(zone, W_OK)) == Z_OK) { 7576bbec428eSgjelinek read_only_mode = B_FALSE; 7577087719fdSdp } else if (err == Z_ACCES) { 7578bbec428eSgjelinek read_only_mode = B_TRUE; 75797c478bd9Sstevel@tonic-gate /* skip this message in one-off from command line mode */ 75807c478bd9Sstevel@tonic-gate if (optind == argc) 75817c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("WARNING: you do not " 75827c478bd9Sstevel@tonic-gate "have write access to this zone's configuration " 75837c478bd9Sstevel@tonic-gate "file;\ngoing into read-only mode.\n")); 7584087719fdSdp } else { 7585087719fdSdp fprintf(stderr, "%s: Could not access zone configuration " 7586087719fdSdp "store: %s\n", execname, zonecfg_strerror(err)); 7587087719fdSdp exit(Z_ERR); 75887c478bd9Sstevel@tonic-gate } 75897c478bd9Sstevel@tonic-gate 75907c478bd9Sstevel@tonic-gate if ((handle = zonecfg_init_handle()) == NULL) { 7591bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 75927c478bd9Sstevel@tonic-gate exit(Z_ERR); 75937c478bd9Sstevel@tonic-gate } 75947c478bd9Sstevel@tonic-gate 75957c478bd9Sstevel@tonic-gate /* 75967c478bd9Sstevel@tonic-gate * This may get set back to FALSE again in cmd_file() if cmd_file_name 75977c478bd9Sstevel@tonic-gate * is a "real" file as opposed to "-" (i.e. meaning use stdin). 75987c478bd9Sstevel@tonic-gate */ 75997c478bd9Sstevel@tonic-gate if (isatty(STDIN_FILENO)) 7600bbec428eSgjelinek ok_to_prompt = B_TRUE; 76017c478bd9Sstevel@tonic-gate if ((gl = new_GetLine(MAX_LINE_LEN, MAX_CMD_HIST)) == NULL) 76027c478bd9Sstevel@tonic-gate exit(Z_ERR); 76037c478bd9Sstevel@tonic-gate if (gl_customize_completion(gl, NULL, cmd_cpl_fn) != 0) 76047c478bd9Sstevel@tonic-gate exit(Z_ERR); 76057c478bd9Sstevel@tonic-gate (void) sigset(SIGINT, SIG_IGN); 76067c478bd9Sstevel@tonic-gate if (optind == argc) { 76077c478bd9Sstevel@tonic-gate if (!cmd_file_mode) 76087c478bd9Sstevel@tonic-gate err = do_interactive(); 76097c478bd9Sstevel@tonic-gate else 76107c478bd9Sstevel@tonic-gate err = cmd_file(cmd_file_name); 76117c478bd9Sstevel@tonic-gate } else { 76127c478bd9Sstevel@tonic-gate err = one_command_at_a_time(argc - optind, &(argv[optind])); 76137c478bd9Sstevel@tonic-gate } 76147c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 76159acbbeafSnn if (brand != NULL) 76169acbbeafSnn brand_close(brand); 76177c478bd9Sstevel@tonic-gate (void) del_GetLine(gl); 76187c478bd9Sstevel@tonic-gate return (err); 76197c478bd9Sstevel@tonic-gate } 7620