Print this page
11894 zonecfg export should quote strings


   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
  25  * Copyright 2014 Gary Mills

  26  */
  27 
  28 /*
  29  * zonecfg is a lex/yacc based command interpreter used to manage zone
  30  * configurations.  The lexer (see zonecfg_lex.l) builds up tokens, which
  31  * the grammar (see zonecfg_grammar.y) builds up into commands, some of
  32  * which takes resources and/or properties as arguments.  See the block
  33  * comments near the end of zonecfg_grammar.y for how the data structures
  34  * which keep track of these resources and properties are built up.
  35  *
  36  * The resource/property data structures are inserted into a command
  37  * structure (see zonecfg.h), which also keeps track of command names,
  38  * miscellaneous arguments, and function handlers.  The grammar selects
  39  * the appropriate function handler, each of which takes a pointer to a
  40  * command structure as its sole argument, and invokes it.  The grammar
  41  * itself is "entered" (a la the Matrix) by yyparse(), which is called
  42  * from read_input(), our main driving function.  That in turn is called
  43  * by one of do_interactive(), cmd_file() or one_command_at_a_time(), each
  44  * of which is called from main() depending on how the program was invoked.
  45  *


1810         if ((outstr = malloc(outstrsize)) == NULL) {
1811                 zone_perror(zone, Z_NOMEM, B_FALSE);
1812                 exit(Z_ERR);
1813         }
1814         if (strchr(instr, ' ') == NULL) {
1815                 (void) strlcpy(outstr, instr, outstrsize);
1816                 return (outstr);
1817         }
1818         (void) snprintf(outstr, outstrsize, "\"%s\"", instr);
1819         return (outstr);
1820 }
1821 
1822 static void
1823 export_prop(FILE *of, int prop_num, char *prop_id)
1824 {
1825         char *quote_str;
1826 
1827         if (strlen(prop_id) == 0)
1828                 return;
1829         quote_str = quoteit(prop_id);
1830         (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET),
1831             pt_to_str(prop_num), quote_str);
1832         free(quote_str);
1833 }
1834 
1835 void
1836 export_func(cmd_t *cmd)
1837 {
1838         struct zone_nwiftab nwiftab;
1839         struct zone_fstab fstab;
1840         struct zone_devtab devtab;
1841         struct zone_attrtab attrtab;
1842         struct zone_rctltab rctltab;
1843         struct zone_dstab dstab;
1844         struct zone_psettab psettab;
1845         struct zone_mcaptab mcaptab;
1846         struct zone_rctlvaltab *valptr;
1847         struct zone_admintab admintab;
1848         struct zone_secflagstab secflagstab;
1849         int err, arg;
1850         char zonepath[MAXPATHLEN], outfile[MAXPATHLEN], pool[MAXNAMELEN];




   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
  25  * Copyright 2014 Gary Mills
  26  * Copyright 2019 Joyent, Inc.
  27  */
  28 
  29 /*
  30  * zonecfg is a lex/yacc based command interpreter used to manage zone
  31  * configurations.  The lexer (see zonecfg_lex.l) builds up tokens, which
  32  * the grammar (see zonecfg_grammar.y) builds up into commands, some of
  33  * which takes resources and/or properties as arguments.  See the block
  34  * comments near the end of zonecfg_grammar.y for how the data structures
  35  * which keep track of these resources and properties are built up.
  36  *
  37  * The resource/property data structures are inserted into a command
  38  * structure (see zonecfg.h), which also keeps track of command names,
  39  * miscellaneous arguments, and function handlers.  The grammar selects
  40  * the appropriate function handler, each of which takes a pointer to a
  41  * command structure as its sole argument, and invokes it.  The grammar
  42  * itself is "entered" (a la the Matrix) by yyparse(), which is called
  43  * from read_input(), our main driving function.  That in turn is called
  44  * by one of do_interactive(), cmd_file() or one_command_at_a_time(), each
  45  * of which is called from main() depending on how the program was invoked.
  46  *


1811         if ((outstr = malloc(outstrsize)) == NULL) {
1812                 zone_perror(zone, Z_NOMEM, B_FALSE);
1813                 exit(Z_ERR);
1814         }
1815         if (strchr(instr, ' ') == NULL) {
1816                 (void) strlcpy(outstr, instr, outstrsize);
1817                 return (outstr);
1818         }
1819         (void) snprintf(outstr, outstrsize, "\"%s\"", instr);
1820         return (outstr);
1821 }
1822 
1823 static void
1824 export_prop(FILE *of, int prop_num, char *prop_id)
1825 {
1826         char *quote_str;
1827 
1828         if (strlen(prop_id) == 0)
1829                 return;
1830         quote_str = quoteit(prop_id);
1831         (void) fprintf(of, "%s %s=\"%s\"\n", cmd_to_str(CMD_SET),
1832             pt_to_str(prop_num), quote_str);
1833         free(quote_str);
1834 }
1835 
1836 void
1837 export_func(cmd_t *cmd)
1838 {
1839         struct zone_nwiftab nwiftab;
1840         struct zone_fstab fstab;
1841         struct zone_devtab devtab;
1842         struct zone_attrtab attrtab;
1843         struct zone_rctltab rctltab;
1844         struct zone_dstab dstab;
1845         struct zone_psettab psettab;
1846         struct zone_mcaptab mcaptab;
1847         struct zone_rctlvaltab *valptr;
1848         struct zone_admintab admintab;
1849         struct zone_secflagstab secflagstab;
1850         int err, arg;
1851         char zonepath[MAXPATHLEN], outfile[MAXPATHLEN], pool[MAXNAMELEN];