/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2014 Nexenta Systems, Inc. All rights reserved. * Copyright 2014 Gary Mills */ /* * zonecfg is a lex/yacc based command interpreter used to manage zone * configurations. The lexer (see zonecfg_lex.l) builds up tokens, which * the grammar (see zonecfg_grammar.y) builds up into commands, some of * which takes resources and/or properties as arguments. See the block * comments near the end of zonecfg_grammar.y for how the data structures * which keep track of these resources and properties are built up. * * The resource/property data structures are inserted into a command * structure (see zonecfg.h), which also keeps track of command names, * miscellaneous arguments, and function handlers. The grammar selects * the appropriate function handler, each of which takes a pointer to a * command structure as its sole argument, and invokes it. The grammar * itself is "entered" (a la the Matrix) by yyparse(), which is called * from read_input(), our main driving function. That in turn is called * by one of do_interactive(), cmd_file() or one_command_at_a_time(), each * of which is called from main() depending on how the program was invoked. * * The rest of this module consists of the various function handlers and * their helper functions. Some of these functions, particularly the * X_to_str() functions, which maps command, resource and property numbers * to strings, are used quite liberally, as doing so results in a better * program w/rt I18N, reducing the need for translation notes. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "zonecfg.h" #if !defined(TEXT_DOMAIN) /* should be defined by cc -D */ #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */ #endif #define PAGER "/usr/bin/more" #define EXEC_PREFIX "exec " #define EXEC_LEN (strlen(EXEC_PREFIX)) struct help { uint_t cmd_num; char *cmd_name; uint_t flags; char *short_usage; }; extern int yyparse(void); extern int lex_lineno; #define MAX_LINE_LEN 1024 #define MAX_CMD_HIST 1024 #define MAX_CMD_LEN 1024 #define ONE_MB 1048576 /* * Each SHELP_ should be a simple string. */ #define SHELP_ADD "add \n\t(global scope)\n" \ "add \n\t(resource scope)" #define SHELP_CANCEL "cancel" #define SHELP_CLEAR "clear " #define SHELP_COMMIT "commit" #define SHELP_CREATE "create [-F] [ -a | -b | -t