Print this page
patch zone-auto-create-be


   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) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2011, Joyent, Inc. All rights reserved.
  25  * Copyright 2014 Nexenta Systems, Inc. All rights reserved.

  26  */
  27 
  28 #include <assert.h>
  29 #include <dirent.h>
  30 #include <errno.h>
  31 #include <fnmatch.h>
  32 #include <signal.h>
  33 #include <stdlib.h>
  34 #include <unistd.h>
  35 #include <strings.h>
  36 #include <synch.h>
  37 #include <sys/brand.h>
  38 #include <sys/fcntl.h>
  39 #include <sys/param.h>
  40 #include <sys/stat.h>
  41 #include <sys/systeminfo.h>
  42 #include <sys/types.h>
  43 #include <thread.h>
  44 #include <zone.h>
  45 


  68 #define DTD_ELEM_POSTINSTALL    ((const xmlChar *) "postinstall")
  69 #define DTD_ELEM_POSTSNAP       ((const xmlChar *) "postsnap")
  70 #define DTD_ELEM_POSTSTATECHG   ((const xmlChar *) "poststatechange")
  71 #define DTD_ELEM_PREDETACH      ((const xmlChar *) "predetach")
  72 #define DTD_ELEM_PRESNAP        ((const xmlChar *) "presnap")
  73 #define DTD_ELEM_PRESTATECHG    ((const xmlChar *) "prestatechange")
  74 #define DTD_ELEM_PREUNINSTALL   ((const xmlChar *) "preuninstall")
  75 #define DTD_ELEM_PRIVILEGE      ((const xmlChar *) "privilege")
  76 #define DTD_ELEM_QUERY          ((const xmlChar *) "query")
  77 #define DTD_ELEM_SHUTDOWN       ((const xmlChar *) "shutdown")
  78 #define DTD_ELEM_SYMLINK        ((const xmlChar *) "symlink")
  79 #define DTD_ELEM_SYSBOOT        ((const xmlChar *) "sysboot")
  80 #define DTD_ELEM_UNINSTALL      ((const xmlChar *) "uninstall")
  81 #define DTD_ELEM_USER_CMD       ((const xmlChar *) "user_cmd")
  82 #define DTD_ELEM_VALIDSNAP      ((const xmlChar *) "validatesnap")
  83 #define DTD_ELEM_VERIFY_CFG     ((const xmlChar *) "verify_cfg")
  84 #define DTD_ELEM_VERIFY_ADM     ((const xmlChar *) "verify_adm")
  85 
  86 #define DTD_ATTR_ALLOWEXCL      ((const xmlChar *) "allow-exclusive-ip")
  87 #define DTD_ATTR_ARCH           ((const xmlChar *) "arch")

  88 #define DTD_ATTR_DIRECTORY      ((const xmlChar *) "directory")
  89 #define DTD_ATTR_IPTYPE         ((const xmlChar *) "ip-type")
  90 #define DTD_ATTR_MATCH          ((const xmlChar *) "match")
  91 #define DTD_ATTR_MODE           ((const xmlChar *) "mode")
  92 #define DTD_ATTR_NAME           ((const xmlChar *) "name")
  93 #define DTD_ATTR_OPT            ((const xmlChar *) "opt")
  94 #define DTD_ATTR_PATH           ((const xmlChar *) "path")
  95 #define DTD_ATTR_SET            ((const xmlChar *) "set")
  96 #define DTD_ATTR_SOURCE         ((const xmlChar *) "source")
  97 #define DTD_ATTR_SPECIAL        ((const xmlChar *) "special")
  98 #define DTD_ATTR_TARGET         ((const xmlChar *) "target")
  99 #define DTD_ATTR_TYPE           ((const xmlChar *) "type")
 100 
 101 #define DTD_ENTITY_TRUE         "true"

 102 
 103 static volatile boolean_t       libbrand_initialized = B_FALSE;
 104 static char                     i_curr_arch[MAXNAMELEN];
 105 static char                     i_curr_zone[ZONENAME_MAX];
 106 
 107 /*ARGSUSED*/
 108 static void
 109 brand_error_func(void *ctx, const char *msg, ...)
 110 {
 111         /*
 112          * Ignore error messages from libxml
 113          */
 114 }
 115 
 116 static boolean_t
 117 libbrand_initialize()
 118 {
 119         static mutex_t initialize_lock = DEFAULTMUTEX;
 120 
 121         (void) mutex_lock(&initialize_lock);


 733         xmlNodePtr              node;
 734         xmlChar                 *allow_excl;
 735         boolean_t               ret;
 736 
 737         assert(bhp != NULL);
 738 
 739         if ((node = xmlDocGetRootElement(bhp->bh_platform)) == NULL)
 740                 return (B_FALSE);
 741 
 742         allow_excl = xmlGetProp(node, DTD_ATTR_ALLOWEXCL);
 743         if (allow_excl == NULL)
 744                 return (B_FALSE);
 745 
 746         /* Note: only return B_TRUE if it's "true" */
 747         if (strcmp((char *)allow_excl, DTD_ENTITY_TRUE) == 0)
 748                 ret = B_TRUE;
 749         else
 750                 ret = B_FALSE;
 751 
 752         xmlFree(allow_excl);




























 753 
 754         return (ret);
 755 }
 756 
 757 /*
 758  * Iterate over brand privileges
 759  *
 760  * Walks the brand config, searching for <privilege> elements, calling the
 761  * specified callback for each.  Returns 0 on success, or -1 on failure.
 762  */
 763 int
 764 brand_config_iter_privilege(brand_handle_t bh,
 765     int (*func)(void *, priv_iter_t *), void *data)
 766 {
 767         struct brand_handle     *bhp = (struct brand_handle *)bh;
 768         xmlNodePtr              node;
 769         xmlChar                 *name, *set, *iptype;
 770         priv_iter_t             priv_iter;
 771         int                     ret;
 772 




   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) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2011, Joyent, Inc. All rights reserved.
  25  * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
  26  * Copyright 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  27  */
  28 
  29 #include <assert.h>
  30 #include <dirent.h>
  31 #include <errno.h>
  32 #include <fnmatch.h>
  33 #include <signal.h>
  34 #include <stdlib.h>
  35 #include <unistd.h>
  36 #include <strings.h>
  37 #include <synch.h>
  38 #include <sys/brand.h>
  39 #include <sys/fcntl.h>
  40 #include <sys/param.h>
  41 #include <sys/stat.h>
  42 #include <sys/systeminfo.h>
  43 #include <sys/types.h>
  44 #include <thread.h>
  45 #include <zone.h>
  46 


  69 #define DTD_ELEM_POSTINSTALL    ((const xmlChar *) "postinstall")
  70 #define DTD_ELEM_POSTSNAP       ((const xmlChar *) "postsnap")
  71 #define DTD_ELEM_POSTSTATECHG   ((const xmlChar *) "poststatechange")
  72 #define DTD_ELEM_PREDETACH      ((const xmlChar *) "predetach")
  73 #define DTD_ELEM_PRESNAP        ((const xmlChar *) "presnap")
  74 #define DTD_ELEM_PRESTATECHG    ((const xmlChar *) "prestatechange")
  75 #define DTD_ELEM_PREUNINSTALL   ((const xmlChar *) "preuninstall")
  76 #define DTD_ELEM_PRIVILEGE      ((const xmlChar *) "privilege")
  77 #define DTD_ELEM_QUERY          ((const xmlChar *) "query")
  78 #define DTD_ELEM_SHUTDOWN       ((const xmlChar *) "shutdown")
  79 #define DTD_ELEM_SYMLINK        ((const xmlChar *) "symlink")
  80 #define DTD_ELEM_SYSBOOT        ((const xmlChar *) "sysboot")
  81 #define DTD_ELEM_UNINSTALL      ((const xmlChar *) "uninstall")
  82 #define DTD_ELEM_USER_CMD       ((const xmlChar *) "user_cmd")
  83 #define DTD_ELEM_VALIDSNAP      ((const xmlChar *) "validatesnap")
  84 #define DTD_ELEM_VERIFY_CFG     ((const xmlChar *) "verify_cfg")
  85 #define DTD_ELEM_VERIFY_ADM     ((const xmlChar *) "verify_adm")
  86 
  87 #define DTD_ATTR_ALLOWEXCL      ((const xmlChar *) "allow-exclusive-ip")
  88 #define DTD_ATTR_ARCH           ((const xmlChar *) "arch")
  89 #define DTD_ATTR_AUTO_CREATE_BE ((const xmlChar *) "auto-create-be")
  90 #define DTD_ATTR_DIRECTORY      ((const xmlChar *) "directory")
  91 #define DTD_ATTR_IPTYPE         ((const xmlChar *) "ip-type")
  92 #define DTD_ATTR_MATCH          ((const xmlChar *) "match")
  93 #define DTD_ATTR_MODE           ((const xmlChar *) "mode")
  94 #define DTD_ATTR_NAME           ((const xmlChar *) "name")
  95 #define DTD_ATTR_OPT            ((const xmlChar *) "opt")
  96 #define DTD_ATTR_PATH           ((const xmlChar *) "path")
  97 #define DTD_ATTR_SET            ((const xmlChar *) "set")
  98 #define DTD_ATTR_SOURCE         ((const xmlChar *) "source")
  99 #define DTD_ATTR_SPECIAL        ((const xmlChar *) "special")
 100 #define DTD_ATTR_TARGET         ((const xmlChar *) "target")
 101 #define DTD_ATTR_TYPE           ((const xmlChar *) "type")
 102 
 103 #define DTD_ENTITY_TRUE         "true"
 104 #define DTD_ENTITY_FALSE        "false"
 105 
 106 static volatile boolean_t       libbrand_initialized = B_FALSE;
 107 static char                     i_curr_arch[MAXNAMELEN];
 108 static char                     i_curr_zone[ZONENAME_MAX];
 109 
 110 /*ARGSUSED*/
 111 static void
 112 brand_error_func(void *ctx, const char *msg, ...)
 113 {
 114         /*
 115          * Ignore error messages from libxml
 116          */
 117 }
 118 
 119 static boolean_t
 120 libbrand_initialize()
 121 {
 122         static mutex_t initialize_lock = DEFAULTMUTEX;
 123 
 124         (void) mutex_lock(&initialize_lock);


 736         xmlNodePtr              node;
 737         xmlChar                 *allow_excl;
 738         boolean_t               ret;
 739 
 740         assert(bhp != NULL);
 741 
 742         if ((node = xmlDocGetRootElement(bhp->bh_platform)) == NULL)
 743                 return (B_FALSE);
 744 
 745         allow_excl = xmlGetProp(node, DTD_ATTR_ALLOWEXCL);
 746         if (allow_excl == NULL)
 747                 return (B_FALSE);
 748 
 749         /* Note: only return B_TRUE if it's "true" */
 750         if (strcmp((char *)allow_excl, DTD_ENTITY_TRUE) == 0)
 751                 ret = B_TRUE;
 752         else
 753                 ret = B_FALSE;
 754 
 755         xmlFree(allow_excl);
 756 
 757         return (ret);
 758 }
 759 
 760 boolean_t
 761 brand_auto_create_be(brand_handle_t bh)
 762 {
 763         struct brand_handle     *bhp = (struct brand_handle *)bh;
 764         xmlNodePtr              node;
 765         xmlChar                 *auto_create_be;
 766         boolean_t               ret;
 767 
 768         assert(bhp != NULL);
 769 
 770         if ((node = xmlDocGetRootElement(bhp->bh_platform)) == NULL)
 771                 return (B_FALSE);
 772 
 773         auto_create_be = xmlGetProp(node, DTD_ATTR_AUTO_CREATE_BE);
 774         if (auto_create_be == NULL)
 775                 return (B_FALSE);
 776 
 777         /* Note: only return B_FALSE if it's "false" */
 778         if (strcmp((char *)auto_create_be, DTD_ENTITY_FALSE) == 0)
 779                 ret = B_FALSE;
 780         else
 781                 ret = B_TRUE;
 782 
 783         xmlFree(auto_create_be);
 784 
 785         return (ret);
 786 }
 787 
 788 /*
 789  * Iterate over brand privileges
 790  *
 791  * Walks the brand config, searching for <privilege> elements, calling the
 792  * specified callback for each.  Returns 0 on success, or -1 on failure.
 793  */
 794 int
 795 brand_config_iter_privilege(brand_handle_t bh,
 796     int (*func)(void *, priv_iter_t *), void *data)
 797 {
 798         struct brand_handle     *bhp = (struct brand_handle *)bh;
 799         xmlNodePtr              node;
 800         xmlChar                 *name, *set, *iptype;
 801         priv_iter_t             priv_iter;
 802         int                     ret;
 803