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
576cf44abSjeanm * Common Development and Distribution License (the "License").
676cf44abSjeanm * 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 */
217c478bd9Sstevel@tonic-gate /*
2285bcc4e5SSean Wilcox * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate */
247c478bd9Sstevel@tonic-gate
257c478bd9Sstevel@tonic-gate /*
267c478bd9Sstevel@tonic-gate * XML document manipulation routines
277c478bd9Sstevel@tonic-gate *
287c478bd9Sstevel@tonic-gate * These routines provide translation to and from the internal representation to
297c478bd9Sstevel@tonic-gate * XML. Directionally-oriented verbs are with respect to the external source,
307c478bd9Sstevel@tonic-gate * so lxml_get_service() fetches a service from the XML file into the
317c478bd9Sstevel@tonic-gate * internal representation.
327c478bd9Sstevel@tonic-gate */
337c478bd9Sstevel@tonic-gate
341f6eb021SLiane Praza #include <libxml/parser.h>
351f6eb021SLiane Praza #include <libxml/xinclude.h>
361f6eb021SLiane Praza
371f6eb021SLiane Praza #include <assert.h>
381f6eb021SLiane Praza #include <ctype.h>
391f6eb021SLiane Praza #include <errno.h>
401f6eb021SLiane Praza #include <libintl.h>
411f6eb021SLiane Praza #include <libscf.h>
421f6eb021SLiane Praza #include <libscf_priv.h>
431f6eb021SLiane Praza #include <libuutil.h>
441f6eb021SLiane Praza #include <sasl/saslutil.h>
451f6eb021SLiane Praza #include <stdlib.h>
461f6eb021SLiane Praza #include <string.h>
4785bcc4e5SSean Wilcox #include <limits.h>
481f6eb021SLiane Praza
491f6eb021SLiane Praza #include <sys/types.h>
501f6eb021SLiane Praza #include <sys/stat.h>
511f6eb021SLiane Praza #include <unistd.h>
521f6eb021SLiane Praza
5323294c7dSSean Wilcox #include <sys/param.h>
5423294c7dSSean Wilcox #include "manifest_hash.h"
5523294c7dSSean Wilcox
561f6eb021SLiane Praza #include "svccfg.h"
57*f6e214c7SGavin Maltby #include "notify_params.h"
581f6eb021SLiane Praza
591f6eb021SLiane Praza /*
601f6eb021SLiane Praza * snprintf(3C) format strings for constructing property names that include
611f6eb021SLiane Praza * the locale designation. Use %s to indicate where the locale should go.
621f6eb021SLiane Praza *
631f6eb021SLiane Praza * The VALUE_* symbols are an exception. The firs %s will be replaced with
641f6eb021SLiane Praza * "value_". The second %s will be replaced by the name of the value and
651f6eb021SLiane Praza * %%s will be replaced by the locale designation. These formats are
661f6eb021SLiane Praza * processed twice by snprintf(3C). The first time captures the value name
671f6eb021SLiane Praza * and the second time captures the locale.
681f6eb021SLiane Praza */
691f6eb021SLiane Praza #define LOCALE_ONLY_FMT ("%s")
701f6eb021SLiane Praza #define COMMON_NAME_FMT ("common_name_%s")
711f6eb021SLiane Praza #define DESCRIPTION_FMT ("description_%s")
721f6eb021SLiane Praza #define UNITS_FMT ("units_%s")
731f6eb021SLiane Praza #define VALUE_COMMON_NAME_FMT ("%s%s_common_name_%%s")
741f6eb021SLiane Praza #define VALUE_DESCRIPTION_FMT ("%s%s_description_%%s")
751f6eb021SLiane Praza
761f6eb021SLiane Praza /* Attribute names */
777c478bd9Sstevel@tonic-gate const char * const delete_attr = "delete";
787c478bd9Sstevel@tonic-gate const char * const enabled_attr = "enabled";
791f6eb021SLiane Praza const char * const lang_attr = "lang";
801f6eb021SLiane Praza const char * const manpath_attr = "manpath";
811f6eb021SLiane Praza const char * const max_attr = "max";
821f6eb021SLiane Praza const char * const min_attr = "min";
837c478bd9Sstevel@tonic-gate const char * const name_attr = "name";
847c478bd9Sstevel@tonic-gate const char * const override_attr = "override";
851f6eb021SLiane Praza const char * const required_attr = "required";
861f6eb021SLiane Praza const char * const section_attr = "section";
871f6eb021SLiane Praza const char * const set_attr = "set";
881f6eb021SLiane Praza const char * const target_attr = "target";
891f6eb021SLiane Praza const char * const timeout_seconds_attr = "timeout_seconds";
901f6eb021SLiane Praza const char * const title_attr = "title";
917c478bd9Sstevel@tonic-gate const char * const type_attr = "type";
921f6eb021SLiane Praza const char * const uri_attr = "uri";
937c478bd9Sstevel@tonic-gate const char * const value_attr = "value";
941f6eb021SLiane Praza const char * const version_attr = "version";
951f6eb021SLiane Praza const char * const xml_lang_attr = "xml:lang";
96*f6e214c7SGavin Maltby const char * const active_attr = "active";
971f6eb021SLiane Praza
981f6eb021SLiane Praza /* Attribute values */
991f6eb021SLiane Praza const char * const all_value = "all";
1001f6eb021SLiane Praza
1017c478bd9Sstevel@tonic-gate const char * const true = "true";
1027c478bd9Sstevel@tonic-gate const char * const false = "false";
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate /*
1057c478bd9Sstevel@tonic-gate * The following list must be kept in the same order as that of
1067c478bd9Sstevel@tonic-gate * element_t array
1077c478bd9Sstevel@tonic-gate */
1087c478bd9Sstevel@tonic-gate static const char *lxml_elements[] = {
1097c478bd9Sstevel@tonic-gate "astring_list", /* SC_ASTRING */
1107c478bd9Sstevel@tonic-gate "boolean_list", /* SC_BOOLEAN */
1111f6eb021SLiane Praza "cardinality", /* SC_CARDINALITY */
1121f6eb021SLiane Praza "choices", /* SC_CHOICES */
1137c478bd9Sstevel@tonic-gate "common_name", /* SC_COMMON_NAME */
1141f6eb021SLiane Praza "constraints", /* SC_CONSTRAINTS */
1157c478bd9Sstevel@tonic-gate "count_list", /* SC_COUNT */
1167c478bd9Sstevel@tonic-gate "create_default_instance", /* SC_INSTANCE_CREATE_DEFAULT */
1177c478bd9Sstevel@tonic-gate "dependency", /* SC_DEPENDENCY */
1187c478bd9Sstevel@tonic-gate "dependent", /* SC_DEPENDENT */
1197c478bd9Sstevel@tonic-gate "description", /* SC_DESCRIPTION */
1207c478bd9Sstevel@tonic-gate "doc_link", /* SC_DOC_LINK */
1217c478bd9Sstevel@tonic-gate "documentation", /* SC_DOCUMENTATION */
1227c478bd9Sstevel@tonic-gate "enabled", /* SC_ENABLED */
123*f6e214c7SGavin Maltby "event", /* SC_EVENT */
1247c478bd9Sstevel@tonic-gate "exec_method", /* SC_EXEC_METHOD */
1257c478bd9Sstevel@tonic-gate "fmri_list", /* SC_FMRI */
1267c478bd9Sstevel@tonic-gate "host_list", /* SC_HOST */
1277c478bd9Sstevel@tonic-gate "hostname_list", /* SC_HOSTNAME */
1281f6eb021SLiane Praza "include_values", /* SC_INCLUDE_VALUES */
1297c478bd9Sstevel@tonic-gate "instance", /* SC_INSTANCE */
1307c478bd9Sstevel@tonic-gate "integer_list", /* SC_INTEGER */
1311f6eb021SLiane Praza "internal_separators", /* SC_INTERNAL_SEPARATORS */
1327c478bd9Sstevel@tonic-gate "loctext", /* SC_LOCTEXT */
1337c478bd9Sstevel@tonic-gate "manpage", /* SC_MANPAGE */
1347c478bd9Sstevel@tonic-gate "method_context", /* SC_METHOD_CONTEXT */
1357c478bd9Sstevel@tonic-gate "method_credential", /* SC_METHOD_CREDENTIAL */
1367c478bd9Sstevel@tonic-gate "method_profile", /* SC_METHOD_PROFILE */
1377c478bd9Sstevel@tonic-gate "method_environment", /* SC_METHOD_ENVIRONMENT */
1387c478bd9Sstevel@tonic-gate "envvar", /* SC_METHOD_ENVVAR */
139f6f041a2SAntonello Cruz "net_address_list", /* SC_NET_ADDR */
1407c478bd9Sstevel@tonic-gate "net_address_v4_list", /* SC_NET_ADDR_V4 */
1417c478bd9Sstevel@tonic-gate "net_address_v6_list", /* SC_NET_ADDR_V6 */
142*f6e214c7SGavin Maltby "notification_parameters", /* SC_NOTIFICATION_PARAMETERS */
1437c478bd9Sstevel@tonic-gate "opaque_list", /* SC_OPAQUE */
144*f6e214c7SGavin Maltby "parameter", /* SC_PARAMETER */
145*f6e214c7SGavin Maltby "paramval", /* SC_PARAMVAL */
1461f6eb021SLiane Praza "pg_pattern", /* SC_PG_PATTERN */
1471f6eb021SLiane Praza "prop_pattern", /* SC_PROP_PATTERN */
1487c478bd9Sstevel@tonic-gate "property", /* SC_PROPERTY */
1497c478bd9Sstevel@tonic-gate "property_group", /* SC_PROPERTY_GROUP */
1507c478bd9Sstevel@tonic-gate "propval", /* SC_PROPVAL */
1511f6eb021SLiane Praza "range", /* SC_RANGE */
1527c478bd9Sstevel@tonic-gate "restarter", /* SC_RESTARTER */
1537c478bd9Sstevel@tonic-gate "service", /* SC_SERVICE */
1547c478bd9Sstevel@tonic-gate "service_bundle", /* SC_SERVICE_BUNDLE */
1557c478bd9Sstevel@tonic-gate "service_fmri", /* SC_SERVICE_FMRI */
1567c478bd9Sstevel@tonic-gate "single_instance", /* SC_INSTANCE_SINGLE */
1577c478bd9Sstevel@tonic-gate "stability", /* SC_STABILITY */
1587c478bd9Sstevel@tonic-gate "template", /* SC_TEMPLATE */
1597c478bd9Sstevel@tonic-gate "time_list", /* SC_TIME */
160*f6e214c7SGavin Maltby "type", /* SC_TYPE */
1611f6eb021SLiane Praza "units", /* SC_UNITS */
1627c478bd9Sstevel@tonic-gate "uri_list", /* SC_URI */
1637c478bd9Sstevel@tonic-gate "ustring_list", /* SC_USTRING */
1641f6eb021SLiane Praza "value", /* SC_VALUE */
1657c478bd9Sstevel@tonic-gate "value_node", /* SC_VALUE_NODE */
1661f6eb021SLiane Praza "values", /* SC_VALUES */
1671f6eb021SLiane Praza "visibility", /* SC_VISIBILITY */
1687c478bd9Sstevel@tonic-gate "xi:fallback", /* SC_XI_FALLBACK */
1697c478bd9Sstevel@tonic-gate "xi:include" /* SC_XI_INCLUDE */
1707c478bd9Sstevel@tonic-gate };
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate /*
1737c478bd9Sstevel@tonic-gate * The following list must be kept in the same order as that of
1747c478bd9Sstevel@tonic-gate * element_t array
1757c478bd9Sstevel@tonic-gate */
1767c478bd9Sstevel@tonic-gate static const char *lxml_prop_types[] = {
1777c478bd9Sstevel@tonic-gate "astring", /* SC_ASTRING */
1787c478bd9Sstevel@tonic-gate "boolean", /* SC_BOOLEAN */
1791f6eb021SLiane Praza "", /* SC_CARDINALITY */
1801f6eb021SLiane Praza "", /* SC_CHOICES */
1817c478bd9Sstevel@tonic-gate "", /* SC_COMMON_NAME */
1821f6eb021SLiane Praza "", /* SC_CONSTRAINTS */
1837c478bd9Sstevel@tonic-gate "count", /* SC_COUNT */
1847c478bd9Sstevel@tonic-gate "", /* SC_INSTANCE_CREATE_DEFAULT */
1857c478bd9Sstevel@tonic-gate "", /* SC_DEPENDENCY */
1867c478bd9Sstevel@tonic-gate "", /* SC_DEPENDENT */
1877c478bd9Sstevel@tonic-gate "", /* SC_DESCRIPTION */
1887c478bd9Sstevel@tonic-gate "", /* SC_DOC_LINK */
1897c478bd9Sstevel@tonic-gate "", /* SC_DOCUMENTATION */
1907c478bd9Sstevel@tonic-gate "", /* SC_ENABLED */
191*f6e214c7SGavin Maltby "", /* SC_EVENT */
1927c478bd9Sstevel@tonic-gate "", /* SC_EXEC_METHOD */
1937c478bd9Sstevel@tonic-gate "fmri", /* SC_FMRI */
1947c478bd9Sstevel@tonic-gate "host", /* SC_HOST */
1957c478bd9Sstevel@tonic-gate "hostname", /* SC_HOSTNAME */
1961f6eb021SLiane Praza "", /* SC_INCLUDE_VALUES */
1977c478bd9Sstevel@tonic-gate "", /* SC_INSTANCE */
1987c478bd9Sstevel@tonic-gate "integer", /* SC_INTEGER */
1991f6eb021SLiane Praza "", /* SC_INTERNAL_SEPARATORS */
2007c478bd9Sstevel@tonic-gate "", /* SC_LOCTEXT */
2017c478bd9Sstevel@tonic-gate "", /* SC_MANPAGE */
2027c478bd9Sstevel@tonic-gate "", /* SC_METHOD_CONTEXT */
2037c478bd9Sstevel@tonic-gate "", /* SC_METHOD_CREDENTIAL */
2047c478bd9Sstevel@tonic-gate "", /* SC_METHOD_PROFILE */
2057c478bd9Sstevel@tonic-gate "", /* SC_METHOD_ENVIRONMENT */
2067c478bd9Sstevel@tonic-gate "", /* SC_METHOD_ENVVAR */
207f6f041a2SAntonello Cruz "net_address", /* SC_NET_ADDR */
2087c478bd9Sstevel@tonic-gate "net_address_v4", /* SC_NET_ADDR_V4 */
2097c478bd9Sstevel@tonic-gate "net_address_v6", /* SC_NET_ADDR_V6 */
210*f6e214c7SGavin Maltby "", /* SC_NOTIFICATION_PARAMETERS */
2117c478bd9Sstevel@tonic-gate "opaque", /* SC_OPAQUE */
212*f6e214c7SGavin Maltby "", /* SC_PARAMETER */
213*f6e214c7SGavin Maltby "", /* SC_PARAMVAL */
2141f6eb021SLiane Praza "", /* SC_PG_PATTERN */
2151f6eb021SLiane Praza "", /* SC_PROP_PATTERN */
2167c478bd9Sstevel@tonic-gate "", /* SC_PROPERTY */
2177c478bd9Sstevel@tonic-gate "", /* SC_PROPERTY_GROUP */
2187c478bd9Sstevel@tonic-gate "", /* SC_PROPVAL */
2191f6eb021SLiane Praza "", /* SC_RANGE */
2207c478bd9Sstevel@tonic-gate "", /* SC_RESTARTER */
2217c478bd9Sstevel@tonic-gate "", /* SC_SERVICE */
2227c478bd9Sstevel@tonic-gate "", /* SC_SERVICE_BUNDLE */
2237c478bd9Sstevel@tonic-gate "", /* SC_SERVICE_FMRI */
2247c478bd9Sstevel@tonic-gate "", /* SC_INSTANCE_SINGLE */
2257c478bd9Sstevel@tonic-gate "", /* SC_STABILITY */
2267c478bd9Sstevel@tonic-gate "", /* SC_TEMPLATE */
2277c478bd9Sstevel@tonic-gate "time", /* SC_TIME */
228*f6e214c7SGavin Maltby "", /* SC_TYPE */
2291f6eb021SLiane Praza "", /* SC_UNITS */
2307c478bd9Sstevel@tonic-gate "uri", /* SC_URI */
2317c478bd9Sstevel@tonic-gate "ustring", /* SC_USTRING */
2321f6eb021SLiane Praza "", /* SC_VALUE */
2331f6eb021SLiane Praza "", /* SC_VALUE_NODE */
2341f6eb021SLiane Praza "", /* SC_VALUES */
2351f6eb021SLiane Praza "", /* SC_VISIBILITY */
2361f6eb021SLiane Praza "", /* SC_XI_FALLBACK */
2377c478bd9Sstevel@tonic-gate "" /* SC_XI_INCLUDE */
2387c478bd9Sstevel@tonic-gate };
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gate int
lxml_init()2417c478bd9Sstevel@tonic-gate lxml_init()
2427c478bd9Sstevel@tonic-gate {
2437c478bd9Sstevel@tonic-gate if (getenv("SVCCFG_NOVALIDATE") == NULL) {
2447c478bd9Sstevel@tonic-gate /*
2457c478bd9Sstevel@tonic-gate * DTD validation, with line numbers.
2467c478bd9Sstevel@tonic-gate */
24780148899SSurya Prakki (void) xmlLineNumbersDefault(1);
2487c478bd9Sstevel@tonic-gate xmlLoadExtDtdDefaultValue |= XML_DETECT_IDS;
2497c478bd9Sstevel@tonic-gate xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS;
2507c478bd9Sstevel@tonic-gate }
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate return (0);
2537c478bd9Sstevel@tonic-gate }
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gate static bundle_type_t
lxml_xlate_bundle_type(xmlChar * type)2567c478bd9Sstevel@tonic-gate lxml_xlate_bundle_type(xmlChar *type)
2577c478bd9Sstevel@tonic-gate {
2587c478bd9Sstevel@tonic-gate if (xmlStrcmp(type, (const xmlChar *)"manifest") == 0)
2597c478bd9Sstevel@tonic-gate return (SVCCFG_MANIFEST);
2607c478bd9Sstevel@tonic-gate
2617c478bd9Sstevel@tonic-gate if (xmlStrcmp(type, (const xmlChar *)"profile") == 0)
2627c478bd9Sstevel@tonic-gate return (SVCCFG_PROFILE);
2637c478bd9Sstevel@tonic-gate
2647c478bd9Sstevel@tonic-gate if (xmlStrcmp(type, (const xmlChar *)"archive") == 0)
2657c478bd9Sstevel@tonic-gate return (SVCCFG_ARCHIVE);
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gate return (SVCCFG_UNKNOWN_BUNDLE);
2687c478bd9Sstevel@tonic-gate }
2697c478bd9Sstevel@tonic-gate
2707c478bd9Sstevel@tonic-gate static service_type_t
lxml_xlate_service_type(xmlChar * type)2717c478bd9Sstevel@tonic-gate lxml_xlate_service_type(xmlChar *type)
2727c478bd9Sstevel@tonic-gate {
2737c478bd9Sstevel@tonic-gate if (xmlStrcmp(type, (const xmlChar *)"service") == 0)
2747c478bd9Sstevel@tonic-gate return (SVCCFG_SERVICE);
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate if (xmlStrcmp(type, (const xmlChar *)"restarter") == 0)
2777c478bd9Sstevel@tonic-gate return (SVCCFG_RESTARTER);
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate if (xmlStrcmp(type, (const xmlChar *)"milestone") == 0)
2807c478bd9Sstevel@tonic-gate return (SVCCFG_MILESTONE);
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate return (SVCCFG_UNKNOWN_SERVICE);
2837c478bd9Sstevel@tonic-gate }
2847c478bd9Sstevel@tonic-gate
2857c478bd9Sstevel@tonic-gate static element_t
lxml_xlate_element(const xmlChar * tag)2867c478bd9Sstevel@tonic-gate lxml_xlate_element(const xmlChar *tag)
2877c478bd9Sstevel@tonic-gate {
2887c478bd9Sstevel@tonic-gate int i;
2897c478bd9Sstevel@tonic-gate
2907c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (lxml_elements) / sizeof (char *); i++)
2917c478bd9Sstevel@tonic-gate if (xmlStrcmp(tag, (const xmlChar *)lxml_elements[i]) == 0)
2927c478bd9Sstevel@tonic-gate return ((element_t)i);
2937c478bd9Sstevel@tonic-gate
2947c478bd9Sstevel@tonic-gate return ((element_t)-1);
2957c478bd9Sstevel@tonic-gate }
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gate static uint_t
lxml_xlate_boolean(const xmlChar * value)2987c478bd9Sstevel@tonic-gate lxml_xlate_boolean(const xmlChar *value)
2997c478bd9Sstevel@tonic-gate {
3007c478bd9Sstevel@tonic-gate if (xmlStrcmp(value, (const xmlChar *)true) == 0)
3017c478bd9Sstevel@tonic-gate return (1);
3027c478bd9Sstevel@tonic-gate
3037c478bd9Sstevel@tonic-gate if (xmlStrcmp(value, (const xmlChar *)false) == 0)
3047c478bd9Sstevel@tonic-gate return (0);
3057c478bd9Sstevel@tonic-gate
3067c478bd9Sstevel@tonic-gate uu_die(gettext("illegal boolean value \"%s\"\n"), value);
3077c478bd9Sstevel@tonic-gate
3087c478bd9Sstevel@tonic-gate /*NOTREACHED*/
3097c478bd9Sstevel@tonic-gate }
3107c478bd9Sstevel@tonic-gate
3117c478bd9Sstevel@tonic-gate static scf_type_t
lxml_element_to_type(element_t type)3127c478bd9Sstevel@tonic-gate lxml_element_to_type(element_t type)
3137c478bd9Sstevel@tonic-gate {
3147c478bd9Sstevel@tonic-gate switch (type) {
3157c478bd9Sstevel@tonic-gate case SC_ASTRING: return (SCF_TYPE_ASTRING);
3167c478bd9Sstevel@tonic-gate case SC_BOOLEAN: return (SCF_TYPE_BOOLEAN);
3177c478bd9Sstevel@tonic-gate case SC_COUNT: return (SCF_TYPE_COUNT);
3187c478bd9Sstevel@tonic-gate case SC_FMRI: return (SCF_TYPE_FMRI);
3197c478bd9Sstevel@tonic-gate case SC_HOST: return (SCF_TYPE_HOST);
3207c478bd9Sstevel@tonic-gate case SC_HOSTNAME: return (SCF_TYPE_HOSTNAME);
3217c478bd9Sstevel@tonic-gate case SC_INTEGER: return (SCF_TYPE_INTEGER);
322f6f041a2SAntonello Cruz case SC_NET_ADDR: return (SCF_TYPE_NET_ADDR);
3237c478bd9Sstevel@tonic-gate case SC_NET_ADDR_V4: return (SCF_TYPE_NET_ADDR_V4);
3247c478bd9Sstevel@tonic-gate case SC_NET_ADDR_V6: return (SCF_TYPE_NET_ADDR_V6);
3257c478bd9Sstevel@tonic-gate case SC_OPAQUE: return (SCF_TYPE_OPAQUE);
3267c478bd9Sstevel@tonic-gate case SC_TIME: return (SCF_TYPE_TIME);
3277c478bd9Sstevel@tonic-gate case SC_URI: return (SCF_TYPE_URI);
3287c478bd9Sstevel@tonic-gate case SC_USTRING: return (SCF_TYPE_USTRING);
3297c478bd9Sstevel@tonic-gate
3307c478bd9Sstevel@tonic-gate default:
3317c478bd9Sstevel@tonic-gate uu_die(gettext("unknown value type (%d)\n"), type);
3327c478bd9Sstevel@tonic-gate }
3337c478bd9Sstevel@tonic-gate
3347c478bd9Sstevel@tonic-gate /* NOTREACHED */
3357c478bd9Sstevel@tonic-gate }
3367c478bd9Sstevel@tonic-gate
337f329b923SSean Wilcox static element_t
lxml_type_to_element(scf_type_t type)338f329b923SSean Wilcox lxml_type_to_element(scf_type_t type)
3397c478bd9Sstevel@tonic-gate {
3407c478bd9Sstevel@tonic-gate switch (type) {
341f329b923SSean Wilcox case SCF_TYPE_ASTRING: return (SC_ASTRING);
342f329b923SSean Wilcox case SCF_TYPE_BOOLEAN: return (SC_BOOLEAN);
343f329b923SSean Wilcox case SCF_TYPE_COUNT: return (SC_COUNT);
344f329b923SSean Wilcox case SCF_TYPE_FMRI: return (SC_FMRI);
345f329b923SSean Wilcox case SCF_TYPE_HOST: return (SC_HOST);
346f329b923SSean Wilcox case SCF_TYPE_HOSTNAME: return (SC_HOSTNAME);
347f329b923SSean Wilcox case SCF_TYPE_INTEGER: return (SC_INTEGER);
348f6f041a2SAntonello Cruz case SCF_TYPE_NET_ADDR: return (SC_NET_ADDR);
349f329b923SSean Wilcox case SCF_TYPE_NET_ADDR_V4: return (SC_NET_ADDR_V4);
350f329b923SSean Wilcox case SCF_TYPE_NET_ADDR_V6: return (SC_NET_ADDR_V6);
351f329b923SSean Wilcox case SCF_TYPE_OPAQUE: return (SC_OPAQUE);
352f329b923SSean Wilcox case SCF_TYPE_TIME: return (SC_TIME);
353f329b923SSean Wilcox case SCF_TYPE_URI: return (SC_URI);
354f329b923SSean Wilcox case SCF_TYPE_USTRING: return (SC_USTRING);
355f329b923SSean Wilcox
3567c478bd9Sstevel@tonic-gate default:
3577c478bd9Sstevel@tonic-gate uu_die(gettext("unknown value type (%d)\n"), type);
3587c478bd9Sstevel@tonic-gate }
3597c478bd9Sstevel@tonic-gate
3607c478bd9Sstevel@tonic-gate /* NOTREACHED */
3617c478bd9Sstevel@tonic-gate }
3627c478bd9Sstevel@tonic-gate
3631f6eb021SLiane Praza /*
3641f6eb021SLiane Praza * Create a SCF_TYPE_BOOLEAN property name pname and attach it to the
3651f6eb021SLiane Praza * property group at pgrp. The value of the property will be set from the
3661f6eb021SLiane Praza * attribute named attr. attr must have a value of 0, 1, true or false.
3671f6eb021SLiane Praza *
3681f6eb021SLiane Praza * Zero is returned on success. An error is indicated by -1. It indicates
3691f6eb021SLiane Praza * that either the attribute had an invalid value or that we could not
3701f6eb021SLiane Praza * attach the property to pgrp. The attribute should not have an invalid
3711f6eb021SLiane Praza * value if the DTD is correctly written.
3721f6eb021SLiane Praza */
3731f6eb021SLiane Praza static int
new_bool_prop_from_attr(pgroup_t * pgrp,const char * pname,xmlNodePtr n,const char * attr)3741f6eb021SLiane Praza new_bool_prop_from_attr(pgroup_t *pgrp, const char *pname, xmlNodePtr n,
3751f6eb021SLiane Praza const char *attr)
3761f6eb021SLiane Praza {
3771f6eb021SLiane Praza uint64_t bool;
3781f6eb021SLiane Praza xmlChar *val;
3791f6eb021SLiane Praza property_t *p;
3801f6eb021SLiane Praza int r;
3811f6eb021SLiane Praza
3821f6eb021SLiane Praza val = xmlGetProp(n, (xmlChar *)attr);
3831f6eb021SLiane Praza if (val == NULL)
3841f6eb021SLiane Praza return (0);
3851f6eb021SLiane Praza
3861f6eb021SLiane Praza if ((xmlStrcmp(val, (xmlChar *)"0") == 0) ||
3871f6eb021SLiane Praza (xmlStrcmp(val, (xmlChar *)"false") == 0)) {
3881f6eb021SLiane Praza bool = 0;
3891f6eb021SLiane Praza } else if ((xmlStrcmp(val, (xmlChar *)"1") == 0) ||
3901f6eb021SLiane Praza (xmlStrcmp(val, (xmlChar *)"true") == 0)) {
3911f6eb021SLiane Praza bool = 1;
3921f6eb021SLiane Praza } else {
3931f6eb021SLiane Praza xmlFree(val);
3941f6eb021SLiane Praza return (-1);
3951f6eb021SLiane Praza }
3961f6eb021SLiane Praza xmlFree(val);
3971f6eb021SLiane Praza p = internal_property_create(pname, SCF_TYPE_BOOLEAN, 1, bool);
3981f6eb021SLiane Praza r = internal_attach_property(pgrp, p);
3991f6eb021SLiane Praza
4001f6eb021SLiane Praza if (r != 0)
4011f6eb021SLiane Praza internal_property_free(p);
4021f6eb021SLiane Praza
4031f6eb021SLiane Praza return (r);
4041f6eb021SLiane Praza }
4051f6eb021SLiane Praza
4067c478bd9Sstevel@tonic-gate static int
new_str_prop_from_attr(pgroup_t * pgrp,const char * pname,scf_type_t ty,xmlNodePtr n,const char * attr)4077c478bd9Sstevel@tonic-gate new_str_prop_from_attr(pgroup_t *pgrp, const char *pname, scf_type_t ty,
4087c478bd9Sstevel@tonic-gate xmlNodePtr n, const char *attr)
4097c478bd9Sstevel@tonic-gate {
4107c478bd9Sstevel@tonic-gate xmlChar *val;
4117c478bd9Sstevel@tonic-gate property_t *p;
4127c478bd9Sstevel@tonic-gate int r;
4137c478bd9Sstevel@tonic-gate
4147c478bd9Sstevel@tonic-gate val = xmlGetProp(n, (xmlChar *)attr);
4157c478bd9Sstevel@tonic-gate
4167c478bd9Sstevel@tonic-gate p = internal_property_create(pname, ty, 1, val);
4177c478bd9Sstevel@tonic-gate r = internal_attach_property(pgrp, p);
4187c478bd9Sstevel@tonic-gate
4197c478bd9Sstevel@tonic-gate if (r != 0)
4207c478bd9Sstevel@tonic-gate internal_property_free(p);
4217c478bd9Sstevel@tonic-gate
4227c478bd9Sstevel@tonic-gate return (r);
4237c478bd9Sstevel@tonic-gate }
4247c478bd9Sstevel@tonic-gate
4257c478bd9Sstevel@tonic-gate static int
new_opt_str_prop_from_attr(pgroup_t * pgrp,const char * pname,scf_type_t ty,xmlNodePtr n,const char * attr,const char * dflt)4261f6eb021SLiane Praza new_opt_str_prop_from_attr(pgroup_t *pgrp, const char *pname, scf_type_t ty,
4271f6eb021SLiane Praza xmlNodePtr n, const char *attr, const char *dflt)
4281f6eb021SLiane Praza {
4291f6eb021SLiane Praza xmlChar *val;
4301f6eb021SLiane Praza property_t *p;
4311f6eb021SLiane Praza int r;
4321f6eb021SLiane Praza
4331f6eb021SLiane Praza val = xmlGetProp(n, (xmlChar *)attr);
4341f6eb021SLiane Praza if (val == NULL) {
4351f6eb021SLiane Praza if (dflt == NULL) {
4361f6eb021SLiane Praza /*
4371f6eb021SLiane Praza * A missing attribute is considered to be a
4381f6eb021SLiane Praza * success in this function, because many of the
4391f6eb021SLiane Praza * attributes are optional. Missing non-optional
4401f6eb021SLiane Praza * attributes will be detected later when template
4411f6eb021SLiane Praza * validation is done.
4421f6eb021SLiane Praza */
4431f6eb021SLiane Praza return (0);
4441f6eb021SLiane Praza } else {
4451f6eb021SLiane Praza val = (xmlChar *)dflt;
4461f6eb021SLiane Praza }
4471f6eb021SLiane Praza }
4481f6eb021SLiane Praza
4491f6eb021SLiane Praza p = internal_property_create(pname, ty, 1, val);
4501f6eb021SLiane Praza r = internal_attach_property(pgrp, p);
4511f6eb021SLiane Praza
4521f6eb021SLiane Praza if (r != 0)
4531f6eb021SLiane Praza internal_property_free(p);
4541f6eb021SLiane Praza
4551f6eb021SLiane Praza return (r);
4561f6eb021SLiane Praza }
4571f6eb021SLiane Praza
4581f6eb021SLiane Praza static int
lxml_ignorable_block(xmlNodePtr n)4597c478bd9Sstevel@tonic-gate lxml_ignorable_block(xmlNodePtr n)
4607c478bd9Sstevel@tonic-gate {
4617c478bd9Sstevel@tonic-gate return ((xmlStrcmp(n->name, (xmlChar *)"text") == 0 ||
4627c478bd9Sstevel@tonic-gate xmlStrcmp(n->name, (xmlChar *)"comment") == 0) ? 1 : 0);
4637c478bd9Sstevel@tonic-gate }
4647c478bd9Sstevel@tonic-gate
465f329b923SSean Wilcox static void
lxml_validate_element(xmlNodePtr n)466f329b923SSean Wilcox lxml_validate_element(xmlNodePtr n)
467f329b923SSean Wilcox {
468f329b923SSean Wilcox xmlValidCtxtPtr vcp;
469f329b923SSean Wilcox
470f329b923SSean Wilcox if (n->doc == NULL)
471f329b923SSean Wilcox uu_die(gettext("Could not validate element\n"));
472f329b923SSean Wilcox
473f329b923SSean Wilcox if (n->doc->extSubset == NULL) {
474f329b923SSean Wilcox xmlDtdPtr dtd;
475f329b923SSean Wilcox dtd = xmlParseDTD(NULL, n->doc->intSubset->SystemID);
476f329b923SSean Wilcox
477f329b923SSean Wilcox if (dtd == NULL) {
478f329b923SSean Wilcox uu_die(gettext("Could not parse DTD \"%s\".\n"),
479f329b923SSean Wilcox n->doc->intSubset->SystemID);
480f329b923SSean Wilcox }
481f329b923SSean Wilcox
482f329b923SSean Wilcox n->doc->extSubset = dtd;
483f329b923SSean Wilcox }
484f329b923SSean Wilcox
485f329b923SSean Wilcox vcp = xmlNewValidCtxt();
486f329b923SSean Wilcox if (vcp == NULL)
487f329b923SSean Wilcox uu_die(gettext("could not allocate memory"));
488f329b923SSean Wilcox
489f329b923SSean Wilcox vcp->warning = xmlParserValidityWarning;
490f329b923SSean Wilcox vcp->error = xmlParserValidityError;
491f329b923SSean Wilcox
492f329b923SSean Wilcox if (xmlValidateElement(vcp, n->doc, n) == 0)
493f329b923SSean Wilcox uu_die(gettext("Document is not valid.\n"));
494f329b923SSean Wilcox
495f329b923SSean Wilcox xmlFreeValidCtxt(vcp);
496f329b923SSean Wilcox }
497f329b923SSean Wilcox
4987c478bd9Sstevel@tonic-gate static int
lxml_validate_string_value(scf_type_t type,const char * v)4997c478bd9Sstevel@tonic-gate lxml_validate_string_value(scf_type_t type, const char *v)
5007c478bd9Sstevel@tonic-gate {
5017c478bd9Sstevel@tonic-gate static scf_value_t *scf_value = NULL;
5027c478bd9Sstevel@tonic-gate static scf_handle_t *scf_hndl = NULL;
5037c478bd9Sstevel@tonic-gate
5047c478bd9Sstevel@tonic-gate if (scf_hndl == NULL && (scf_hndl = scf_handle_create(SCF_VERSION)) ==
5057c478bd9Sstevel@tonic-gate NULL)
5067c478bd9Sstevel@tonic-gate return (-1);
5077c478bd9Sstevel@tonic-gate
5087c478bd9Sstevel@tonic-gate if (scf_value == NULL && (scf_value = scf_value_create(scf_hndl)) ==
5097c478bd9Sstevel@tonic-gate NULL)
5107c478bd9Sstevel@tonic-gate return (-1);
5117c478bd9Sstevel@tonic-gate
5127c478bd9Sstevel@tonic-gate return (scf_value_set_from_string(scf_value, type, v));
5137c478bd9Sstevel@tonic-gate }
5147c478bd9Sstevel@tonic-gate
5157c478bd9Sstevel@tonic-gate static void
lxml_free_str(value_t * val)5167c478bd9Sstevel@tonic-gate lxml_free_str(value_t *val)
5177c478bd9Sstevel@tonic-gate {
5187c478bd9Sstevel@tonic-gate free(val->sc_u.sc_string);
5197c478bd9Sstevel@tonic-gate }
5207c478bd9Sstevel@tonic-gate
521f329b923SSean Wilcox /*
522f329b923SSean Wilcox * Take a value_t structure and a type and value. Based on the type
523f329b923SSean Wilcox * ensure that the value is of that type. If so store the value in
524f329b923SSean Wilcox * the correct location of the value_t structure.
525f329b923SSean Wilcox *
526f329b923SSean Wilcox * If the value is NULL, the value_t structure will have been created
527f329b923SSean Wilcox * and the value would have ultimately been stored as a string value
528f329b923SSean Wilcox * but at the time the type was unknown. Now the type should be known
529f329b923SSean Wilcox * so take the type and value from value_t and validate and store
530f329b923SSean Wilcox * the value correctly if the value is of the stated type.
531f329b923SSean Wilcox */
532f329b923SSean Wilcox void
lxml_store_value(value_t * v,element_t type,const xmlChar * value)533f329b923SSean Wilcox lxml_store_value(value_t *v, element_t type, const xmlChar *value)
5347c478bd9Sstevel@tonic-gate {
5357c478bd9Sstevel@tonic-gate char *endptr;
536f329b923SSean Wilcox int fov = 0;
5377c478bd9Sstevel@tonic-gate scf_type_t scf_type = SCF_TYPE_INVALID;
5387c478bd9Sstevel@tonic-gate
539f329b923SSean Wilcox if (value == NULL) {
540f329b923SSean Wilcox type = lxml_type_to_element(v->sc_type);
541f329b923SSean Wilcox value = (const xmlChar *)v->sc_u.sc_string;
542f329b923SSean Wilcox fov = 1;
543f329b923SSean Wilcox }
5447c478bd9Sstevel@tonic-gate
5457c478bd9Sstevel@tonic-gate switch (type) {
5467c478bd9Sstevel@tonic-gate case SC_COUNT:
5477c478bd9Sstevel@tonic-gate /*
5487c478bd9Sstevel@tonic-gate * Although an SC_COUNT represents a uint64_t the use
5497c478bd9Sstevel@tonic-gate * of a negative value is acceptable due to the usage
5507c478bd9Sstevel@tonic-gate * established by inetd(1M).
5517c478bd9Sstevel@tonic-gate */
5527c478bd9Sstevel@tonic-gate errno = 0;
5537c478bd9Sstevel@tonic-gate v->sc_u.sc_count = strtoull((char *)value, &endptr, 10);
5547c478bd9Sstevel@tonic-gate if (errno != 0 || endptr == (char *)value || *endptr)
5557c478bd9Sstevel@tonic-gate uu_die(gettext("illegal value \"%s\" for "
5567c478bd9Sstevel@tonic-gate "%s (%s)\n"), (char *)value,
5577c478bd9Sstevel@tonic-gate lxml_prop_types[type],
5587c478bd9Sstevel@tonic-gate (errno) ? strerror(errno) :
5597c478bd9Sstevel@tonic-gate gettext("Illegal character"));
5607c478bd9Sstevel@tonic-gate break;
5617c478bd9Sstevel@tonic-gate case SC_INTEGER:
5627c478bd9Sstevel@tonic-gate errno = 0;
5637c478bd9Sstevel@tonic-gate v->sc_u.sc_integer = strtoll((char *)value, &endptr, 10);
5647c478bd9Sstevel@tonic-gate if (errno != 0 || *endptr)
5657c478bd9Sstevel@tonic-gate uu_die(gettext("illegal value \"%s\" for "
5667c478bd9Sstevel@tonic-gate "%s (%s)\n"), (char *)value,
5677c478bd9Sstevel@tonic-gate lxml_prop_types[type],
5687c478bd9Sstevel@tonic-gate (errno) ? strerror(errno) : "Illegal character");
5697c478bd9Sstevel@tonic-gate break;
5707c478bd9Sstevel@tonic-gate case SC_OPAQUE:
5717c478bd9Sstevel@tonic-gate case SC_HOST:
5727c478bd9Sstevel@tonic-gate case SC_HOSTNAME:
573f6f041a2SAntonello Cruz case SC_NET_ADDR:
5747c478bd9Sstevel@tonic-gate case SC_NET_ADDR_V4:
5757c478bd9Sstevel@tonic-gate case SC_NET_ADDR_V6:
5767c478bd9Sstevel@tonic-gate case SC_FMRI:
5777c478bd9Sstevel@tonic-gate case SC_URI:
5787c478bd9Sstevel@tonic-gate case SC_TIME:
5797c478bd9Sstevel@tonic-gate case SC_ASTRING:
5807c478bd9Sstevel@tonic-gate case SC_USTRING:
581f329b923SSean Wilcox scf_type = lxml_element_to_type(type);
5827c478bd9Sstevel@tonic-gate
5837c478bd9Sstevel@tonic-gate if ((v->sc_u.sc_string = strdup((char *)value)) == NULL)
5847c478bd9Sstevel@tonic-gate uu_die(gettext("string duplication failed (%s)\n"),
5857c478bd9Sstevel@tonic-gate strerror(errno));
5867c478bd9Sstevel@tonic-gate if (lxml_validate_string_value(scf_type,
5877c478bd9Sstevel@tonic-gate v->sc_u.sc_string) != 0)
5887c478bd9Sstevel@tonic-gate uu_die(gettext("illegal value \"%s\" for "
5897c478bd9Sstevel@tonic-gate "%s (%s)\n"), (char *)value,
5907c478bd9Sstevel@tonic-gate lxml_prop_types[type],
5917c478bd9Sstevel@tonic-gate (scf_error()) ? scf_strerror(scf_error()) :
5927c478bd9Sstevel@tonic-gate gettext("Illegal format"));
5937c478bd9Sstevel@tonic-gate v->sc_free = lxml_free_str;
5947c478bd9Sstevel@tonic-gate break;
5957c478bd9Sstevel@tonic-gate case SC_BOOLEAN:
5967c478bd9Sstevel@tonic-gate v->sc_u.sc_count = lxml_xlate_boolean(value);
5977c478bd9Sstevel@tonic-gate break;
5987c478bd9Sstevel@tonic-gate default:
5997c478bd9Sstevel@tonic-gate uu_die(gettext("unknown value type (%d)\n"), type);
6007c478bd9Sstevel@tonic-gate break;
6017c478bd9Sstevel@tonic-gate }
6027c478bd9Sstevel@tonic-gate
603f329b923SSean Wilcox /* Free the old value */
604f329b923SSean Wilcox if (fov && v->sc_free != NULL)
605f329b923SSean Wilcox free((char *)value);
606f329b923SSean Wilcox }
607f329b923SSean Wilcox
608f329b923SSean Wilcox static value_t *
lxml_make_value(element_t type,const xmlChar * value)609f329b923SSean Wilcox lxml_make_value(element_t type, const xmlChar *value)
610f329b923SSean Wilcox {
611f329b923SSean Wilcox value_t *v;
612f329b923SSean Wilcox
613f329b923SSean Wilcox v = internal_value_new();
614f329b923SSean Wilcox
615f329b923SSean Wilcox v->sc_type = lxml_element_to_type(type);
616f329b923SSean Wilcox
617f329b923SSean Wilcox lxml_store_value(v, type, value);
618f329b923SSean Wilcox
6197c478bd9Sstevel@tonic-gate return (v);
6207c478bd9Sstevel@tonic-gate }
6217c478bd9Sstevel@tonic-gate
6227c478bd9Sstevel@tonic-gate static int
lxml_get_value(property_t * prop,element_t vtype,xmlNodePtr value)6237c478bd9Sstevel@tonic-gate lxml_get_value(property_t *prop, element_t vtype, xmlNodePtr value)
6247c478bd9Sstevel@tonic-gate {
6257c478bd9Sstevel@tonic-gate xmlNodePtr cursor;
6267c478bd9Sstevel@tonic-gate
6277c478bd9Sstevel@tonic-gate for (cursor = value->xmlChildrenNode; cursor != NULL;
6287c478bd9Sstevel@tonic-gate cursor = cursor->next) {
6297c478bd9Sstevel@tonic-gate xmlChar *assigned_value;
6307c478bd9Sstevel@tonic-gate value_t *v;
6317c478bd9Sstevel@tonic-gate
6327c478bd9Sstevel@tonic-gate if (lxml_ignorable_block(cursor))
6337c478bd9Sstevel@tonic-gate continue;
6347c478bd9Sstevel@tonic-gate
6357c478bd9Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) {
6367c478bd9Sstevel@tonic-gate case SC_VALUE_NODE:
6377c478bd9Sstevel@tonic-gate if ((assigned_value = xmlGetProp(cursor,
6387c478bd9Sstevel@tonic-gate (xmlChar *)value_attr)) == NULL)
6397c478bd9Sstevel@tonic-gate uu_die(gettext("no value on value node?\n"));
6407c478bd9Sstevel@tonic-gate break;
6417c478bd9Sstevel@tonic-gate default:
6427c478bd9Sstevel@tonic-gate uu_die(gettext("value list contains illegal element "
6437c478bd9Sstevel@tonic-gate "\'%s\'\n"), cursor->name);
6447c478bd9Sstevel@tonic-gate break;
6457c478bd9Sstevel@tonic-gate }
6467c478bd9Sstevel@tonic-gate
6477c478bd9Sstevel@tonic-gate v = lxml_make_value(vtype, assigned_value);
6487c478bd9Sstevel@tonic-gate
6497c478bd9Sstevel@tonic-gate xmlFree(assigned_value);
6507c478bd9Sstevel@tonic-gate
6517c478bd9Sstevel@tonic-gate internal_attach_value(prop, v);
6527c478bd9Sstevel@tonic-gate }
6537c478bd9Sstevel@tonic-gate
6547c478bd9Sstevel@tonic-gate return (0);
6557c478bd9Sstevel@tonic-gate }
6567c478bd9Sstevel@tonic-gate
6577c478bd9Sstevel@tonic-gate static int
lxml_get_propval(pgroup_t * pgrp,xmlNodePtr propval)6587c478bd9Sstevel@tonic-gate lxml_get_propval(pgroup_t *pgrp, xmlNodePtr propval)
6597c478bd9Sstevel@tonic-gate {
6607c478bd9Sstevel@tonic-gate property_t *p;
6617c478bd9Sstevel@tonic-gate element_t r;
6627c478bd9Sstevel@tonic-gate value_t *v;
6637c478bd9Sstevel@tonic-gate xmlChar *type, *val, *override;
664f329b923SSean Wilcox int op = pgrp->sc_parent->sc_op;
6657c478bd9Sstevel@tonic-gate
6667c478bd9Sstevel@tonic-gate p = internal_property_new();
6677c478bd9Sstevel@tonic-gate
6687c478bd9Sstevel@tonic-gate p->sc_property_name = (char *)xmlGetProp(propval, (xmlChar *)name_attr);
6691f6eb021SLiane Praza if ((p->sc_property_name == NULL) || (*p->sc_property_name == 0))
6707c478bd9Sstevel@tonic-gate uu_die(gettext("property name missing in group '%s'\n"),
6717c478bd9Sstevel@tonic-gate pgrp->sc_pgroup_name);
6727c478bd9Sstevel@tonic-gate
6737c478bd9Sstevel@tonic-gate type = xmlGetProp(propval, (xmlChar *)type_attr);
674f329b923SSean Wilcox if ((type != NULL) && (*type != 0)) {
675f329b923SSean Wilcox for (r = 0;
676f329b923SSean Wilcox r < sizeof (lxml_prop_types) / sizeof (char *); ++r) {
677f329b923SSean Wilcox if (xmlStrcmp(type,
678f329b923SSean Wilcox (const xmlChar *)lxml_prop_types[r]) == 0)
6797c478bd9Sstevel@tonic-gate break;
6807c478bd9Sstevel@tonic-gate }
681f329b923SSean Wilcox
6827c478bd9Sstevel@tonic-gate if (r >= sizeof (lxml_prop_types) / sizeof (char *))
683f329b923SSean Wilcox uu_die(gettext("property type invalid for "
684f329b923SSean Wilcox "property '%s/%s'\n"), pgrp->sc_pgroup_name,
685f329b923SSean Wilcox p->sc_property_name);
6867c478bd9Sstevel@tonic-gate
6877c478bd9Sstevel@tonic-gate p->sc_value_type = lxml_element_to_type(r);
688f329b923SSean Wilcox } else if (op == SVCCFG_OP_APPLY) {
689f329b923SSean Wilcox /*
690f329b923SSean Wilcox * Store the property type as invalid, and the value
691f329b923SSean Wilcox * as an ASTRING and let the bundle apply code validate
692f329b923SSean Wilcox * the type/value once the type is found.
693f329b923SSean Wilcox */
694f329b923SSean Wilcox est->sc_miss_type = B_TRUE;
695f329b923SSean Wilcox p->sc_value_type = SCF_TYPE_INVALID;
696f329b923SSean Wilcox r = SC_ASTRING;
697f329b923SSean Wilcox } else {
698f329b923SSean Wilcox uu_die(gettext("property type missing for property '%s/%s'\n"),
699f329b923SSean Wilcox pgrp->sc_pgroup_name, p->sc_property_name);
700f329b923SSean Wilcox }
7017c478bd9Sstevel@tonic-gate
7027c478bd9Sstevel@tonic-gate val = xmlGetProp(propval, (xmlChar *)value_attr);
7037c478bd9Sstevel@tonic-gate if (val == NULL)
7047c478bd9Sstevel@tonic-gate uu_die(gettext("property value missing for property '%s/%s'\n"),
7057c478bd9Sstevel@tonic-gate pgrp->sc_pgroup_name, p->sc_property_name);
7067c478bd9Sstevel@tonic-gate
7077c478bd9Sstevel@tonic-gate v = lxml_make_value(r, val);
7081f6eb021SLiane Praza xmlFree(val);
7097c478bd9Sstevel@tonic-gate internal_attach_value(p, v);
7107c478bd9Sstevel@tonic-gate
711f329b923SSean Wilcox xmlFree(type);
712f329b923SSean Wilcox
7137c478bd9Sstevel@tonic-gate override = xmlGetProp(propval, (xmlChar *)override_attr);
7147c478bd9Sstevel@tonic-gate p->sc_property_override = (xmlStrcmp(override, (xmlChar *)true) == 0);
7157c478bd9Sstevel@tonic-gate xmlFree(override);
7167c478bd9Sstevel@tonic-gate
7177c478bd9Sstevel@tonic-gate return (internal_attach_property(pgrp, p));
7187c478bd9Sstevel@tonic-gate }
7197c478bd9Sstevel@tonic-gate
7207c478bd9Sstevel@tonic-gate static int
lxml_get_property(pgroup_t * pgrp,xmlNodePtr property)7217c478bd9Sstevel@tonic-gate lxml_get_property(pgroup_t *pgrp, xmlNodePtr property)
7227c478bd9Sstevel@tonic-gate {
7237c478bd9Sstevel@tonic-gate property_t *p;
7247c478bd9Sstevel@tonic-gate xmlNodePtr cursor;
7257c478bd9Sstevel@tonic-gate element_t r;
7267c478bd9Sstevel@tonic-gate xmlChar *type, *override;
727f329b923SSean Wilcox int op = pgrp->sc_parent->sc_op;
7287c478bd9Sstevel@tonic-gate
7297c478bd9Sstevel@tonic-gate p = internal_property_new();
7307c478bd9Sstevel@tonic-gate
7311f6eb021SLiane Praza if (((p->sc_property_name = (char *)xmlGetProp(property,
7321f6eb021SLiane Praza (xmlChar *)name_attr)) == NULL) || (*p->sc_property_name == 0))
7337c478bd9Sstevel@tonic-gate uu_die(gettext("property name missing in group \'%s\'\n"),
7347c478bd9Sstevel@tonic-gate pgrp->sc_pgroup_name);
7357c478bd9Sstevel@tonic-gate
736f329b923SSean Wilcox type = xmlGetProp(property, (xmlChar *)type_attr);
737f329b923SSean Wilcox if ((type != NULL) && (*type != 0)) {
738f329b923SSean Wilcox for (r = 0;
739f329b923SSean Wilcox r < sizeof (lxml_prop_types) / sizeof (char *); r++) {
740f329b923SSean Wilcox if (xmlStrcmp(type,
741f329b923SSean Wilcox (const xmlChar *)lxml_prop_types[r]) == 0)
742f329b923SSean Wilcox break;
743f329b923SSean Wilcox }
744f329b923SSean Wilcox
745f329b923SSean Wilcox if (r >= sizeof (lxml_prop_types) / sizeof (char *))
746f329b923SSean Wilcox uu_die(gettext("property type invalid for "
747f329b923SSean Wilcox "property '%s/%s'\n"), pgrp->sc_pgroup_name,
748f329b923SSean Wilcox p->sc_property_name);
749f329b923SSean Wilcox
750f329b923SSean Wilcox p->sc_value_type = lxml_element_to_type(r);
751f329b923SSean Wilcox } else if (op == SVCCFG_OP_APPLY) {
752f329b923SSean Wilcox /*
753f329b923SSean Wilcox * Store the property type as invalid, and let the bundle apply
754f329b923SSean Wilcox * code validate the type/value once the type is found.
755f329b923SSean Wilcox */
756f329b923SSean Wilcox p->sc_value_type = SCF_TYPE_INVALID;
757f329b923SSean Wilcox est->sc_miss_type = B_TRUE;
758f329b923SSean Wilcox } else {
7597c478bd9Sstevel@tonic-gate uu_die(gettext("property type missing for "
7607c478bd9Sstevel@tonic-gate "property \'%s/%s\'\n"), pgrp->sc_pgroup_name,
7617c478bd9Sstevel@tonic-gate p->sc_property_name);
7621f6eb021SLiane Praza }
7637c478bd9Sstevel@tonic-gate
7647c478bd9Sstevel@tonic-gate for (cursor = property->xmlChildrenNode; cursor != NULL;
7657c478bd9Sstevel@tonic-gate cursor = cursor->next) {
7667c478bd9Sstevel@tonic-gate if (lxml_ignorable_block(cursor))
7677c478bd9Sstevel@tonic-gate continue;
7687c478bd9Sstevel@tonic-gate
7697c478bd9Sstevel@tonic-gate switch (r = lxml_xlate_element(cursor->name)) {
7707c478bd9Sstevel@tonic-gate case SC_ASTRING:
7717c478bd9Sstevel@tonic-gate case SC_BOOLEAN:
7727c478bd9Sstevel@tonic-gate case SC_COUNT:
7737c478bd9Sstevel@tonic-gate case SC_FMRI:
7747c478bd9Sstevel@tonic-gate case SC_HOST:
7757c478bd9Sstevel@tonic-gate case SC_HOSTNAME:
7767c478bd9Sstevel@tonic-gate case SC_INTEGER:
777f6f041a2SAntonello Cruz case SC_NET_ADDR:
7787c478bd9Sstevel@tonic-gate case SC_NET_ADDR_V4:
7797c478bd9Sstevel@tonic-gate case SC_NET_ADDR_V6:
7807c478bd9Sstevel@tonic-gate case SC_OPAQUE:
7817c478bd9Sstevel@tonic-gate case SC_TIME:
7827c478bd9Sstevel@tonic-gate case SC_URI:
7837c478bd9Sstevel@tonic-gate case SC_USTRING:
784f329b923SSean Wilcox /*
785f329b923SSean Wilcox * If the type is invalid then this is an apply
786f329b923SSean Wilcox * operation and the type can be taken from the
787f329b923SSean Wilcox * value list.
788f329b923SSean Wilcox */
789f329b923SSean Wilcox if (p->sc_value_type == SCF_TYPE_INVALID) {
790f329b923SSean Wilcox p->sc_value_type = lxml_element_to_type(r);
791f329b923SSean Wilcox type = xmlStrdup((const
792f329b923SSean Wilcox xmlChar *)lxml_prop_types[r]);
793f329b923SSean Wilcox
794f329b923SSean Wilcox } else if (strcmp(lxml_prop_types[r],
795f329b923SSean Wilcox (const char *)type) != 0) {
7967c478bd9Sstevel@tonic-gate uu_die(gettext("property \'%s\' "
7977c478bd9Sstevel@tonic-gate "type-to-list mismatch\n"),
7987c478bd9Sstevel@tonic-gate p->sc_property_name);
799f329b923SSean Wilcox }
8007c478bd9Sstevel@tonic-gate
8017c478bd9Sstevel@tonic-gate (void) lxml_get_value(p, r, cursor);
8027c478bd9Sstevel@tonic-gate break;
8037c478bd9Sstevel@tonic-gate default:
8047c478bd9Sstevel@tonic-gate uu_die(gettext("unknown value list type: %s\n"),
8057c478bd9Sstevel@tonic-gate cursor->name);
8067c478bd9Sstevel@tonic-gate break;
8077c478bd9Sstevel@tonic-gate }
8087c478bd9Sstevel@tonic-gate }
8097c478bd9Sstevel@tonic-gate
8107c478bd9Sstevel@tonic-gate xmlFree(type);
8117c478bd9Sstevel@tonic-gate
8127c478bd9Sstevel@tonic-gate override = xmlGetProp(property, (xmlChar *)override_attr);
8137c478bd9Sstevel@tonic-gate p->sc_property_override = (xmlStrcmp(override, (xmlChar *)true) == 0);
8147c478bd9Sstevel@tonic-gate xmlFree(override);
8157c478bd9Sstevel@tonic-gate
8167c478bd9Sstevel@tonic-gate return (internal_attach_property(pgrp, p));
8177c478bd9Sstevel@tonic-gate }
8187c478bd9Sstevel@tonic-gate
8197c478bd9Sstevel@tonic-gate static int
lxml_get_pgroup_stability(pgroup_t * pgrp,xmlNodePtr stab)8207c478bd9Sstevel@tonic-gate lxml_get_pgroup_stability(pgroup_t *pgrp, xmlNodePtr stab)
8217c478bd9Sstevel@tonic-gate {
822f329b923SSean Wilcox if (pgrp->sc_parent->sc_op == SVCCFG_OP_APPLY)
823f329b923SSean Wilcox lxml_validate_element(stab);
824f329b923SSean Wilcox
8257c478bd9Sstevel@tonic-gate return (new_str_prop_from_attr(pgrp, SCF_PROPERTY_STABILITY,
8267c478bd9Sstevel@tonic-gate SCF_TYPE_ASTRING, stab, value_attr));
8277c478bd9Sstevel@tonic-gate }
8287c478bd9Sstevel@tonic-gate
8297c478bd9Sstevel@tonic-gate /*
8307c478bd9Sstevel@tonic-gate * Property groups can go on any of a service, an instance, or a template.
8317c478bd9Sstevel@tonic-gate */
8327c478bd9Sstevel@tonic-gate static int
lxml_get_pgroup(entity_t * entity,xmlNodePtr pgroup)8337c478bd9Sstevel@tonic-gate lxml_get_pgroup(entity_t *entity, xmlNodePtr pgroup)
8347c478bd9Sstevel@tonic-gate {
8357c478bd9Sstevel@tonic-gate pgroup_t *pg;
8367c478bd9Sstevel@tonic-gate xmlNodePtr cursor;
8377c478bd9Sstevel@tonic-gate xmlChar *name, *type, *delete;
8387c478bd9Sstevel@tonic-gate
8397c478bd9Sstevel@tonic-gate /*
8407c478bd9Sstevel@tonic-gate * property group attributes:
8417c478bd9Sstevel@tonic-gate * name: string
8427c478bd9Sstevel@tonic-gate * type: string | framework | application
8437c478bd9Sstevel@tonic-gate */
8447c478bd9Sstevel@tonic-gate name = xmlGetProp(pgroup, (xmlChar *)name_attr);
8457c478bd9Sstevel@tonic-gate type = xmlGetProp(pgroup, (xmlChar *)type_attr);
8467c478bd9Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, (char *)name, (char *)type);
8477c478bd9Sstevel@tonic-gate xmlFree(name);
8487c478bd9Sstevel@tonic-gate xmlFree(type);
8497c478bd9Sstevel@tonic-gate
8507c478bd9Sstevel@tonic-gate /*
8517c478bd9Sstevel@tonic-gate * Walk the children of this lxml_elements, which are a stability
8527c478bd9Sstevel@tonic-gate * element, property elements, or propval elements.
8537c478bd9Sstevel@tonic-gate */
8547c478bd9Sstevel@tonic-gate for (cursor = pgroup->xmlChildrenNode; cursor != NULL;
8557c478bd9Sstevel@tonic-gate cursor = cursor->next) {
8567c478bd9Sstevel@tonic-gate if (lxml_ignorable_block(cursor))
8577c478bd9Sstevel@tonic-gate continue;
8587c478bd9Sstevel@tonic-gate
8597c478bd9Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) {
8607c478bd9Sstevel@tonic-gate case SC_STABILITY:
8617c478bd9Sstevel@tonic-gate (void) lxml_get_pgroup_stability(pg, cursor);
8627c478bd9Sstevel@tonic-gate break;
8637c478bd9Sstevel@tonic-gate case SC_PROPERTY:
8647c478bd9Sstevel@tonic-gate (void) lxml_get_property(pg, cursor);
8657c478bd9Sstevel@tonic-gate break;
8667c478bd9Sstevel@tonic-gate case SC_PROPVAL:
8677c478bd9Sstevel@tonic-gate (void) lxml_get_propval(pg, cursor);
8687c478bd9Sstevel@tonic-gate break;
8697c478bd9Sstevel@tonic-gate default:
8707c478bd9Sstevel@tonic-gate abort();
8717c478bd9Sstevel@tonic-gate break;
8727c478bd9Sstevel@tonic-gate }
8737c478bd9Sstevel@tonic-gate }
8747c478bd9Sstevel@tonic-gate
8757c478bd9Sstevel@tonic-gate delete = xmlGetProp(pgroup, (xmlChar *)delete_attr);
8767c478bd9Sstevel@tonic-gate pg->sc_pgroup_delete = (xmlStrcmp(delete, (xmlChar *)true) == 0);
8777c478bd9Sstevel@tonic-gate xmlFree(delete);
8787c478bd9Sstevel@tonic-gate
8797c478bd9Sstevel@tonic-gate return (0);
8807c478bd9Sstevel@tonic-gate }
8817c478bd9Sstevel@tonic-gate
8827c478bd9Sstevel@tonic-gate
8837c478bd9Sstevel@tonic-gate /*
8847c478bd9Sstevel@tonic-gate * Dependency groups, execution methods can go on either a service or an
8857c478bd9Sstevel@tonic-gate * instance.
8867c478bd9Sstevel@tonic-gate */
8877c478bd9Sstevel@tonic-gate
8887c478bd9Sstevel@tonic-gate static int
lxml_get_method_profile(pgroup_t * pg,xmlNodePtr profile)8897c478bd9Sstevel@tonic-gate lxml_get_method_profile(pgroup_t *pg, xmlNodePtr profile)
8907c478bd9Sstevel@tonic-gate {
8917c478bd9Sstevel@tonic-gate property_t *p;
8927c478bd9Sstevel@tonic-gate
8937c478bd9Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_USE_PROFILE, SCF_TYPE_BOOLEAN,
8947c478bd9Sstevel@tonic-gate 1, (uint64_t)1);
8957c478bd9Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0)
8967c478bd9Sstevel@tonic-gate return (-1);
8977c478bd9Sstevel@tonic-gate
8987c478bd9Sstevel@tonic-gate return (new_str_prop_from_attr(pg, SCF_PROPERTY_PROFILE,
8997c478bd9Sstevel@tonic-gate SCF_TYPE_ASTRING, profile, name_attr));
9007c478bd9Sstevel@tonic-gate }
9017c478bd9Sstevel@tonic-gate
9027c478bd9Sstevel@tonic-gate static int
lxml_get_method_credential(pgroup_t * pg,xmlNodePtr cred)9037c478bd9Sstevel@tonic-gate lxml_get_method_credential(pgroup_t *pg, xmlNodePtr cred)
9047c478bd9Sstevel@tonic-gate {
9057c478bd9Sstevel@tonic-gate property_t *p;
9067c478bd9Sstevel@tonic-gate
9077c478bd9Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_USE_PROFILE, SCF_TYPE_BOOLEAN,
9087c478bd9Sstevel@tonic-gate 1, (uint64_t)0);
9097c478bd9Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0)
9107c478bd9Sstevel@tonic-gate return (-1);
9117c478bd9Sstevel@tonic-gate
91213d8aaa1SSean Wilcox if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_USER, SCF_TYPE_ASTRING,
91313d8aaa1SSean Wilcox cred, "user", NULL) != 0)
9147c478bd9Sstevel@tonic-gate return (-1);
9157c478bd9Sstevel@tonic-gate
91613d8aaa1SSean Wilcox if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_GROUP, SCF_TYPE_ASTRING,
91713d8aaa1SSean Wilcox cred, "group", NULL) != 0)
9187c478bd9Sstevel@tonic-gate return (-1);
9197c478bd9Sstevel@tonic-gate
92013d8aaa1SSean Wilcox if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_SUPP_GROUPS,
92113d8aaa1SSean Wilcox SCF_TYPE_ASTRING, cred, "supp_groups", NULL) != 0)
9227c478bd9Sstevel@tonic-gate return (-1);
9237c478bd9Sstevel@tonic-gate
92413d8aaa1SSean Wilcox if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_PRIVILEGES,
92513d8aaa1SSean Wilcox SCF_TYPE_ASTRING, cred, "privileges", NULL) != 0)
9267c478bd9Sstevel@tonic-gate return (-1);
9277c478bd9Sstevel@tonic-gate
92813d8aaa1SSean Wilcox if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_LIMIT_PRIVILEGES,
92913d8aaa1SSean Wilcox SCF_TYPE_ASTRING, cred, "limit_privileges", NULL) != 0)
9307c478bd9Sstevel@tonic-gate return (-1);
9317c478bd9Sstevel@tonic-gate
9327c478bd9Sstevel@tonic-gate return (0);
9337c478bd9Sstevel@tonic-gate }
9347c478bd9Sstevel@tonic-gate
9357c478bd9Sstevel@tonic-gate static char *
lxml_get_envvar(xmlNodePtr envvar)9367c478bd9Sstevel@tonic-gate lxml_get_envvar(xmlNodePtr envvar)
9377c478bd9Sstevel@tonic-gate {
9387c478bd9Sstevel@tonic-gate char *name;
9397c478bd9Sstevel@tonic-gate char *value;
9407c478bd9Sstevel@tonic-gate char *ret;
9417c478bd9Sstevel@tonic-gate
9421f6eb021SLiane Praza name = (char *)xmlGetProp(envvar, (xmlChar *)name_attr);
9431f6eb021SLiane Praza value = (char *)xmlGetProp(envvar, (xmlChar *)value_attr);
9447c478bd9Sstevel@tonic-gate
9457c478bd9Sstevel@tonic-gate if (strlen(name) == 0 || strchr(name, '=') != NULL)
9467c478bd9Sstevel@tonic-gate uu_die(gettext("Invalid environment variable "
9477c478bd9Sstevel@tonic-gate "\"%s\".\n"), name);
9487c478bd9Sstevel@tonic-gate if (strstr(name, "SMF_") == name)
9497c478bd9Sstevel@tonic-gate uu_die(gettext("Invalid environment variable "
9507c478bd9Sstevel@tonic-gate "\"%s\"; \"SMF_\" prefix is reserved.\n"), name);
9517c478bd9Sstevel@tonic-gate
9527c478bd9Sstevel@tonic-gate ret = uu_msprintf("%s=%s", name, value);
9537c478bd9Sstevel@tonic-gate xmlFree(name);
9547c478bd9Sstevel@tonic-gate xmlFree(value);
9557c478bd9Sstevel@tonic-gate return (ret);
9567c478bd9Sstevel@tonic-gate }
9577c478bd9Sstevel@tonic-gate
9587c478bd9Sstevel@tonic-gate static int
lxml_get_method_environment(pgroup_t * pg,xmlNodePtr environment)9597c478bd9Sstevel@tonic-gate lxml_get_method_environment(pgroup_t *pg, xmlNodePtr environment)
9607c478bd9Sstevel@tonic-gate {
9617c478bd9Sstevel@tonic-gate property_t *p;
9627c478bd9Sstevel@tonic-gate xmlNodePtr cursor;
9637c478bd9Sstevel@tonic-gate value_t *val;
9647c478bd9Sstevel@tonic-gate
9657c478bd9Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_ENVIRONMENT,
9667c478bd9Sstevel@tonic-gate SCF_TYPE_ASTRING, 0);
9677c478bd9Sstevel@tonic-gate
9687c478bd9Sstevel@tonic-gate for (cursor = environment->xmlChildrenNode; cursor != NULL;
9697c478bd9Sstevel@tonic-gate cursor = cursor->next) {
9707c478bd9Sstevel@tonic-gate char *tmp;
9717c478bd9Sstevel@tonic-gate
9727c478bd9Sstevel@tonic-gate if (lxml_ignorable_block(cursor))
9737c478bd9Sstevel@tonic-gate continue;
9747c478bd9Sstevel@tonic-gate
9757c478bd9Sstevel@tonic-gate if (lxml_xlate_element(cursor->name) != SC_METHOD_ENVVAR)
9767c478bd9Sstevel@tonic-gate uu_die(gettext("illegal element \"%s\" on "
9777c478bd9Sstevel@tonic-gate "method environment for \"%s\"\n"),
9787c478bd9Sstevel@tonic-gate cursor->name, pg->sc_pgroup_name);
9797c478bd9Sstevel@tonic-gate
9807c478bd9Sstevel@tonic-gate if ((tmp = lxml_get_envvar(cursor)) == NULL)
9817c478bd9Sstevel@tonic-gate uu_die(gettext("Out of memory\n"));
9827c478bd9Sstevel@tonic-gate
9837c478bd9Sstevel@tonic-gate val = internal_value_new();
9847c478bd9Sstevel@tonic-gate val->sc_u.sc_string = tmp;
9857c478bd9Sstevel@tonic-gate val->sc_type = SCF_TYPE_ASTRING;
9867c478bd9Sstevel@tonic-gate val->sc_free = lxml_free_str;
9877c478bd9Sstevel@tonic-gate internal_attach_value(p, val);
9887c478bd9Sstevel@tonic-gate }
9897c478bd9Sstevel@tonic-gate
9907c478bd9Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0) {
9917c478bd9Sstevel@tonic-gate internal_property_free(p);
9927c478bd9Sstevel@tonic-gate return (-1);
9937c478bd9Sstevel@tonic-gate }
9947c478bd9Sstevel@tonic-gate
9957c478bd9Sstevel@tonic-gate return (0);
9967c478bd9Sstevel@tonic-gate }
9977c478bd9Sstevel@tonic-gate
9987c478bd9Sstevel@tonic-gate static int
lxml_get_method_context(pgroup_t * pg,xmlNodePtr ctx)9997c478bd9Sstevel@tonic-gate lxml_get_method_context(pgroup_t *pg, xmlNodePtr ctx)
10007c478bd9Sstevel@tonic-gate {
10017c478bd9Sstevel@tonic-gate xmlNodePtr cursor;
10027c478bd9Sstevel@tonic-gate
100313d8aaa1SSean Wilcox if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_WORKING_DIRECTORY,
100413d8aaa1SSean Wilcox SCF_TYPE_ASTRING, ctx, "working_directory", NULL) != 0)
10057c478bd9Sstevel@tonic-gate return (-1);
10067c478bd9Sstevel@tonic-gate
100713d8aaa1SSean Wilcox if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_PROJECT,
100813d8aaa1SSean Wilcox SCF_TYPE_ASTRING, ctx, "project", NULL) != 0)
10097c478bd9Sstevel@tonic-gate return (-1);
10107c478bd9Sstevel@tonic-gate
101113d8aaa1SSean Wilcox if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_RESOURCE_POOL,
101213d8aaa1SSean Wilcox SCF_TYPE_ASTRING, ctx, "resource_pool", NULL) != 0)
10137c478bd9Sstevel@tonic-gate return (-1);
10147c478bd9Sstevel@tonic-gate
10157c478bd9Sstevel@tonic-gate for (cursor = ctx->xmlChildrenNode; cursor != NULL;
10167c478bd9Sstevel@tonic-gate cursor = cursor->next) {
10177c478bd9Sstevel@tonic-gate if (lxml_ignorable_block(cursor))
10187c478bd9Sstevel@tonic-gate continue;
10197c478bd9Sstevel@tonic-gate
10207c478bd9Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) {
10217c478bd9Sstevel@tonic-gate case SC_METHOD_CREDENTIAL:
10227c478bd9Sstevel@tonic-gate (void) lxml_get_method_credential(pg, cursor);
10237c478bd9Sstevel@tonic-gate break;
10247c478bd9Sstevel@tonic-gate case SC_METHOD_PROFILE:
10257c478bd9Sstevel@tonic-gate (void) lxml_get_method_profile(pg, cursor);
10267c478bd9Sstevel@tonic-gate break;
10277c478bd9Sstevel@tonic-gate case SC_METHOD_ENVIRONMENT:
10287c478bd9Sstevel@tonic-gate (void) lxml_get_method_environment(pg, cursor);
10297c478bd9Sstevel@tonic-gate break;
10307c478bd9Sstevel@tonic-gate default:
10317c478bd9Sstevel@tonic-gate semerr(gettext("illegal element \'%s\' in method "
10327c478bd9Sstevel@tonic-gate "context\n"), (char *)cursor);
10337c478bd9Sstevel@tonic-gate break;
10347c478bd9Sstevel@tonic-gate }
10357c478bd9Sstevel@tonic-gate }
10367c478bd9Sstevel@tonic-gate
10377c478bd9Sstevel@tonic-gate return (0);
10387c478bd9Sstevel@tonic-gate }
10397c478bd9Sstevel@tonic-gate
10407c478bd9Sstevel@tonic-gate static int
lxml_get_entity_method_context(entity_t * entity,xmlNodePtr ctx)10417c478bd9Sstevel@tonic-gate lxml_get_entity_method_context(entity_t *entity, xmlNodePtr ctx)
10427c478bd9Sstevel@tonic-gate {
10437c478bd9Sstevel@tonic-gate pgroup_t *pg;
10447c478bd9Sstevel@tonic-gate
10457c478bd9Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, SCF_PG_METHOD_CONTEXT,
10467c478bd9Sstevel@tonic-gate (char *)scf_group_framework);
10477c478bd9Sstevel@tonic-gate
10487c478bd9Sstevel@tonic-gate return (lxml_get_method_context(pg, ctx));
10497c478bd9Sstevel@tonic-gate }
10507c478bd9Sstevel@tonic-gate
10517c478bd9Sstevel@tonic-gate static int
lxml_get_exec_method(entity_t * entity,xmlNodePtr emeth)10527c478bd9Sstevel@tonic-gate lxml_get_exec_method(entity_t *entity, xmlNodePtr emeth)
10537c478bd9Sstevel@tonic-gate {
10547c478bd9Sstevel@tonic-gate pgroup_t *pg;
10557c478bd9Sstevel@tonic-gate property_t *p;
10567c478bd9Sstevel@tonic-gate xmlChar *name, *timeout, *delete;
10577c478bd9Sstevel@tonic-gate xmlNodePtr cursor;
10587c478bd9Sstevel@tonic-gate int r = 0;
10597c478bd9Sstevel@tonic-gate
1060f329b923SSean Wilcox if (entity->sc_op == SVCCFG_OP_APPLY)
1061f329b923SSean Wilcox lxml_validate_element(emeth);
1062f329b923SSean Wilcox
10637c478bd9Sstevel@tonic-gate name = xmlGetProp(emeth, (xmlChar *)name_attr);
10647c478bd9Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, (char *)name,
10657c478bd9Sstevel@tonic-gate (char *)SCF_GROUP_METHOD);
10667c478bd9Sstevel@tonic-gate xmlFree(name);
10677c478bd9Sstevel@tonic-gate
10687c478bd9Sstevel@tonic-gate if (new_str_prop_from_attr(pg, SCF_PROPERTY_TYPE, SCF_TYPE_ASTRING,
10697c478bd9Sstevel@tonic-gate emeth, type_attr) != 0 ||
10707c478bd9Sstevel@tonic-gate new_str_prop_from_attr(pg, SCF_PROPERTY_EXEC, SCF_TYPE_ASTRING,
10717c478bd9Sstevel@tonic-gate emeth, "exec") != 0)
10727c478bd9Sstevel@tonic-gate return (-1);
10737c478bd9Sstevel@tonic-gate
10741f6eb021SLiane Praza timeout = xmlGetProp(emeth, (xmlChar *)timeout_seconds_attr);
10757c478bd9Sstevel@tonic-gate if (timeout != NULL) {
10767c478bd9Sstevel@tonic-gate uint64_t u_timeout;
10777c478bd9Sstevel@tonic-gate char *endptr;
10787c478bd9Sstevel@tonic-gate /*
10797c478bd9Sstevel@tonic-gate * Although an SC_COUNT represents a uint64_t the use
10807c478bd9Sstevel@tonic-gate * of a negative value is acceptable due to the usage
10817c478bd9Sstevel@tonic-gate * established by inetd(1M).
10827c478bd9Sstevel@tonic-gate */
10837c478bd9Sstevel@tonic-gate errno = 0;
10847c478bd9Sstevel@tonic-gate u_timeout = strtoull((char *)timeout, &endptr, 10);
10857c478bd9Sstevel@tonic-gate if (errno != 0 || endptr == (char *)timeout || *endptr)
10867c478bd9Sstevel@tonic-gate uu_die(gettext("illegal value \"%s\" for "
10877c478bd9Sstevel@tonic-gate "timeout_seconds (%s)\n"),
10887c478bd9Sstevel@tonic-gate (char *)timeout, (errno) ? strerror(errno):
10897c478bd9Sstevel@tonic-gate gettext("Illegal character"));
10907c478bd9Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_TIMEOUT,
10917c478bd9Sstevel@tonic-gate SCF_TYPE_COUNT, 1, u_timeout);
10927c478bd9Sstevel@tonic-gate r = internal_attach_property(pg, p);
10937c478bd9Sstevel@tonic-gate xmlFree(timeout);
10947c478bd9Sstevel@tonic-gate }
10957c478bd9Sstevel@tonic-gate if (r != 0)
10967c478bd9Sstevel@tonic-gate return (-1);
10977c478bd9Sstevel@tonic-gate
10987c478bd9Sstevel@tonic-gate /*
10997c478bd9Sstevel@tonic-gate * There is a possibility that a method context also exists, in which
11007c478bd9Sstevel@tonic-gate * case the following attributes are defined: project, resource_pool,
11017c478bd9Sstevel@tonic-gate * working_directory, profile, user, group, privileges, limit_privileges
11027c478bd9Sstevel@tonic-gate */
11037c478bd9Sstevel@tonic-gate for (cursor = emeth->xmlChildrenNode; cursor != NULL;
11047c478bd9Sstevel@tonic-gate cursor = cursor->next) {
11057c478bd9Sstevel@tonic-gate if (lxml_ignorable_block(cursor))
11067c478bd9Sstevel@tonic-gate continue;
11077c478bd9Sstevel@tonic-gate
11087c478bd9Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) {
11097c478bd9Sstevel@tonic-gate case SC_STABILITY:
11107c478bd9Sstevel@tonic-gate if (lxml_get_pgroup_stability(pg, cursor) != 0)
11117c478bd9Sstevel@tonic-gate return (-1);
11127c478bd9Sstevel@tonic-gate break;
11137c478bd9Sstevel@tonic-gate
11147c478bd9Sstevel@tonic-gate case SC_METHOD_CONTEXT:
11157c478bd9Sstevel@tonic-gate (void) lxml_get_method_context(pg, cursor);
11167c478bd9Sstevel@tonic-gate break;
11177c478bd9Sstevel@tonic-gate
11187c478bd9Sstevel@tonic-gate case SC_PROPVAL:
11197c478bd9Sstevel@tonic-gate (void) lxml_get_propval(pg, cursor);
11207c478bd9Sstevel@tonic-gate break;
11217c478bd9Sstevel@tonic-gate
11227c478bd9Sstevel@tonic-gate case SC_PROPERTY:
11237c478bd9Sstevel@tonic-gate (void) lxml_get_property(pg, cursor);
11247c478bd9Sstevel@tonic-gate break;
11257c478bd9Sstevel@tonic-gate
11267c478bd9Sstevel@tonic-gate default:
11277c478bd9Sstevel@tonic-gate uu_die(gettext("illegal element \"%s\" on "
11287c478bd9Sstevel@tonic-gate "execution method \"%s\"\n"), cursor->name,
11297c478bd9Sstevel@tonic-gate pg->sc_pgroup_name);
11307c478bd9Sstevel@tonic-gate break;
11317c478bd9Sstevel@tonic-gate }
11327c478bd9Sstevel@tonic-gate }
11337c478bd9Sstevel@tonic-gate
11347c478bd9Sstevel@tonic-gate delete = xmlGetProp(emeth, (xmlChar *)delete_attr);
11357c478bd9Sstevel@tonic-gate pg->sc_pgroup_delete = (xmlStrcmp(delete, (xmlChar *)true) == 0);
11367c478bd9Sstevel@tonic-gate xmlFree(delete);
11377c478bd9Sstevel@tonic-gate
11387c478bd9Sstevel@tonic-gate return (0);
11397c478bd9Sstevel@tonic-gate }
11407c478bd9Sstevel@tonic-gate
11417c478bd9Sstevel@tonic-gate static int
lxml_get_dependency(entity_t * entity,xmlNodePtr dependency)11427c478bd9Sstevel@tonic-gate lxml_get_dependency(entity_t *entity, xmlNodePtr dependency)
11437c478bd9Sstevel@tonic-gate {
11447c478bd9Sstevel@tonic-gate pgroup_t *pg;
11457c478bd9Sstevel@tonic-gate property_t *p;
11467c478bd9Sstevel@tonic-gate xmlNodePtr cursor;
11477c478bd9Sstevel@tonic-gate xmlChar *name;
11487c478bd9Sstevel@tonic-gate xmlChar *delete;
11497c478bd9Sstevel@tonic-gate
11507c478bd9Sstevel@tonic-gate /*
11517c478bd9Sstevel@tonic-gate * dependency attributes:
11527c478bd9Sstevel@tonic-gate * name: string
11537c478bd9Sstevel@tonic-gate * grouping: require_all | require_any | exclude_all | optional_all
11547c478bd9Sstevel@tonic-gate * reset_on: string (error | restart | refresh | none)
11557c478bd9Sstevel@tonic-gate * type: service / path /host
11567c478bd9Sstevel@tonic-gate */
11577c478bd9Sstevel@tonic-gate
1158f329b923SSean Wilcox if (entity->sc_op == SVCCFG_OP_APPLY)
1159f329b923SSean Wilcox lxml_validate_element(dependency);
1160f329b923SSean Wilcox
11617c478bd9Sstevel@tonic-gate name = xmlGetProp(dependency, (xmlChar *)name_attr);
11627c478bd9Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, (char *)name,
11637c478bd9Sstevel@tonic-gate (char *)SCF_GROUP_DEPENDENCY);
11647c478bd9Sstevel@tonic-gate xmlFree(name);
11657c478bd9Sstevel@tonic-gate
11667c478bd9Sstevel@tonic-gate if (new_str_prop_from_attr(pg, SCF_PROPERTY_TYPE, SCF_TYPE_ASTRING,
11677c478bd9Sstevel@tonic-gate dependency, type_attr) != 0)
11687c478bd9Sstevel@tonic-gate return (-1);
11697c478bd9Sstevel@tonic-gate
11707c478bd9Sstevel@tonic-gate if (new_str_prop_from_attr(pg, SCF_PROPERTY_RESTART_ON,
11717c478bd9Sstevel@tonic-gate SCF_TYPE_ASTRING, dependency, "restart_on") != 0)
11727c478bd9Sstevel@tonic-gate return (-1);
11737c478bd9Sstevel@tonic-gate
11747c478bd9Sstevel@tonic-gate if (new_str_prop_from_attr(pg, SCF_PROPERTY_GROUPING, SCF_TYPE_ASTRING,
11757c478bd9Sstevel@tonic-gate dependency, "grouping") != 0)
11767c478bd9Sstevel@tonic-gate return (-1);
11777c478bd9Sstevel@tonic-gate
11787c478bd9Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_ENTITIES, SCF_TYPE_FMRI, 0);
11797c478bd9Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0)
11807c478bd9Sstevel@tonic-gate return (-1);
11817c478bd9Sstevel@tonic-gate
11827c478bd9Sstevel@tonic-gate for (cursor = dependency->xmlChildrenNode; cursor != NULL;
11837c478bd9Sstevel@tonic-gate cursor = cursor->next) {
11847c478bd9Sstevel@tonic-gate xmlChar *value;
11857c478bd9Sstevel@tonic-gate value_t *v;
11867c478bd9Sstevel@tonic-gate
11877c478bd9Sstevel@tonic-gate if (lxml_ignorable_block(cursor))
11887c478bd9Sstevel@tonic-gate continue;
11897c478bd9Sstevel@tonic-gate
11907c478bd9Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) {
11917c478bd9Sstevel@tonic-gate case SC_STABILITY:
11927c478bd9Sstevel@tonic-gate if (lxml_get_pgroup_stability(pg, cursor) != 0)
11937c478bd9Sstevel@tonic-gate return (-1);
11947c478bd9Sstevel@tonic-gate break;
11957c478bd9Sstevel@tonic-gate
11967c478bd9Sstevel@tonic-gate case SC_SERVICE_FMRI:
11977c478bd9Sstevel@tonic-gate value = xmlGetProp(cursor, (xmlChar *)value_attr);
11987c478bd9Sstevel@tonic-gate if (value != NULL) {
11997c478bd9Sstevel@tonic-gate if (lxml_validate_string_value(SCF_TYPE_FMRI,
12007c478bd9Sstevel@tonic-gate (char *)value) != 0)
12017c478bd9Sstevel@tonic-gate uu_die(gettext("illegal value \"%s\" "
12027c478bd9Sstevel@tonic-gate "for %s (%s)\n"), (char *)value,
12037c478bd9Sstevel@tonic-gate lxml_prop_types[SC_FMRI],
12047c478bd9Sstevel@tonic-gate (scf_error()) ?
12057c478bd9Sstevel@tonic-gate scf_strerror(scf_error()) :
12067c478bd9Sstevel@tonic-gate gettext("Illegal format"));
12077c478bd9Sstevel@tonic-gate v = internal_value_new();
12087c478bd9Sstevel@tonic-gate v->sc_type = SCF_TYPE_FMRI;
12097c478bd9Sstevel@tonic-gate v->sc_u.sc_string = (char *)value;
12107c478bd9Sstevel@tonic-gate internal_attach_value(p, v);
12117c478bd9Sstevel@tonic-gate }
12127c478bd9Sstevel@tonic-gate
12137c478bd9Sstevel@tonic-gate break;
12147c478bd9Sstevel@tonic-gate
12157c478bd9Sstevel@tonic-gate case SC_PROPVAL:
12167c478bd9Sstevel@tonic-gate (void) lxml_get_propval(pg, cursor);
12177c478bd9Sstevel@tonic-gate break;
12187c478bd9Sstevel@tonic-gate
12197c478bd9Sstevel@tonic-gate case SC_PROPERTY:
12207c478bd9Sstevel@tonic-gate (void) lxml_get_property(pg, cursor);
12217c478bd9Sstevel@tonic-gate break;
12227c478bd9Sstevel@tonic-gate
12237c478bd9Sstevel@tonic-gate default:
12247c478bd9Sstevel@tonic-gate uu_die(gettext("illegal element \"%s\" on "
12257c478bd9Sstevel@tonic-gate "dependency group \"%s\"\n"), cursor->name, name);
12267c478bd9Sstevel@tonic-gate break;
12277c478bd9Sstevel@tonic-gate }
12287c478bd9Sstevel@tonic-gate }
12297c478bd9Sstevel@tonic-gate
12307c478bd9Sstevel@tonic-gate delete = xmlGetProp(dependency, (xmlChar *)delete_attr);
12317c478bd9Sstevel@tonic-gate pg->sc_pgroup_delete = (xmlStrcmp(delete, (xmlChar *)true) == 0);
12327c478bd9Sstevel@tonic-gate xmlFree(delete);
12337c478bd9Sstevel@tonic-gate
12347c478bd9Sstevel@tonic-gate return (0);
12357c478bd9Sstevel@tonic-gate }
12367c478bd9Sstevel@tonic-gate
12377c478bd9Sstevel@tonic-gate /*
12387c478bd9Sstevel@tonic-gate * Dependents are hairy. They should cause a dependency pg to be created in
12397c478bd9Sstevel@tonic-gate * another service, but we can't do that here; we'll have to wait until the
12407c478bd9Sstevel@tonic-gate * import routines. So for now we'll add the dependency group that should go
12417c478bd9Sstevel@tonic-gate * in the other service to the entity's dependent list.
12427c478bd9Sstevel@tonic-gate */
12437c478bd9Sstevel@tonic-gate static int
lxml_get_dependent(entity_t * entity,xmlNodePtr dependent)12447c478bd9Sstevel@tonic-gate lxml_get_dependent(entity_t *entity, xmlNodePtr dependent)
12457c478bd9Sstevel@tonic-gate {
12467c478bd9Sstevel@tonic-gate xmlChar *name, *or;
12477c478bd9Sstevel@tonic-gate xmlNodePtr sf;
12487c478bd9Sstevel@tonic-gate xmlChar *fmri, *delete;
12497c478bd9Sstevel@tonic-gate pgroup_t *pg;
12507c478bd9Sstevel@tonic-gate property_t *p;
12517c478bd9Sstevel@tonic-gate xmlNodePtr n;
12527c478bd9Sstevel@tonic-gate char *myfmri;
12537c478bd9Sstevel@tonic-gate
1254f329b923SSean Wilcox if (entity->sc_op == SVCCFG_OP_APPLY)
1255f329b923SSean Wilcox lxml_validate_element(dependent);
1256f329b923SSean Wilcox
12577c478bd9Sstevel@tonic-gate name = xmlGetProp(dependent, (xmlChar *)name_attr);
12587c478bd9Sstevel@tonic-gate
12597c478bd9Sstevel@tonic-gate if (internal_pgroup_find(entity, (char *)name, NULL) != NULL) {
12607c478bd9Sstevel@tonic-gate semerr(gettext("Property group and dependent of entity %s "
12617c478bd9Sstevel@tonic-gate "have same name \"%s\".\n"), entity->sc_name, name);
12627c478bd9Sstevel@tonic-gate xmlFree(name);
12637c478bd9Sstevel@tonic-gate return (-1);
12647c478bd9Sstevel@tonic-gate }
12657c478bd9Sstevel@tonic-gate
12667c478bd9Sstevel@tonic-gate or = xmlGetProp(dependent, (xmlChar *)override_attr);
12677c478bd9Sstevel@tonic-gate
12687c478bd9Sstevel@tonic-gate pg = internal_pgroup_new();
12697c478bd9Sstevel@tonic-gate pg->sc_pgroup_name = (char *)name;
12707c478bd9Sstevel@tonic-gate pg->sc_pgroup_type = (char *)SCF_GROUP_DEPENDENCY;
12717c478bd9Sstevel@tonic-gate pg->sc_pgroup_override = (xmlStrcmp(or, (xmlChar *)true) == 0);
12727c478bd9Sstevel@tonic-gate xmlFree(or);
12737c478bd9Sstevel@tonic-gate if (internal_attach_dependent(entity, pg) != 0) {
12747c478bd9Sstevel@tonic-gate xmlFree(name);
12757c478bd9Sstevel@tonic-gate internal_pgroup_free(pg);
12767c478bd9Sstevel@tonic-gate return (-1);
12777c478bd9Sstevel@tonic-gate }
12787c478bd9Sstevel@tonic-gate
12797c478bd9Sstevel@tonic-gate for (sf = dependent->children; sf != NULL; sf = sf->next)
12807c478bd9Sstevel@tonic-gate if (xmlStrcmp(sf->name, (xmlChar *)"service_fmri") == 0)
12817c478bd9Sstevel@tonic-gate break;
12827c478bd9Sstevel@tonic-gate assert(sf != NULL);
12837c478bd9Sstevel@tonic-gate fmri = xmlGetProp(sf, (xmlChar *)value_attr);
12847c478bd9Sstevel@tonic-gate pg->sc_pgroup_fmri = (char *)fmri;
12857c478bd9Sstevel@tonic-gate
12867c478bd9Sstevel@tonic-gate if (new_str_prop_from_attr(pg, SCF_PROPERTY_RESTART_ON,
12877c478bd9Sstevel@tonic-gate SCF_TYPE_ASTRING, dependent, "restart_on") != 0)
12887c478bd9Sstevel@tonic-gate return (-1);
12897c478bd9Sstevel@tonic-gate
12907c478bd9Sstevel@tonic-gate if (new_str_prop_from_attr(pg, SCF_PROPERTY_GROUPING, SCF_TYPE_ASTRING,
12917c478bd9Sstevel@tonic-gate dependent, "grouping") != 0)
12927c478bd9Sstevel@tonic-gate return (-1);
12937c478bd9Sstevel@tonic-gate
12947c478bd9Sstevel@tonic-gate myfmri = safe_malloc(max_scf_fmri_len + 1);
12957c478bd9Sstevel@tonic-gate if (entity->sc_etype == SVCCFG_SERVICE_OBJECT) {
12967c478bd9Sstevel@tonic-gate if (snprintf(myfmri, max_scf_fmri_len + 1, "svc:/%s",
12977c478bd9Sstevel@tonic-gate entity->sc_name) < 0)
12987c478bd9Sstevel@tonic-gate bad_error("snprintf", errno);
12997c478bd9Sstevel@tonic-gate } else {
13007c478bd9Sstevel@tonic-gate assert(entity->sc_etype == SVCCFG_INSTANCE_OBJECT);
13017c478bd9Sstevel@tonic-gate if (snprintf(myfmri, max_scf_fmri_len + 1, "svc:/%s:%s",
13027c478bd9Sstevel@tonic-gate entity->sc_parent->sc_name, entity->sc_name) < 0)
13037c478bd9Sstevel@tonic-gate bad_error("snprintf", errno);
13047c478bd9Sstevel@tonic-gate }
13057c478bd9Sstevel@tonic-gate
13067c478bd9Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_ENTITIES, SCF_TYPE_FMRI, 1,
13077c478bd9Sstevel@tonic-gate myfmri);
13087c478bd9Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0)
13097c478bd9Sstevel@tonic-gate return (-1);
13107c478bd9Sstevel@tonic-gate
13117c478bd9Sstevel@tonic-gate /* Create a property to serve as a do-not-export flag. */
13127c478bd9Sstevel@tonic-gate p = internal_property_create("external", SCF_TYPE_BOOLEAN, 1,
13137c478bd9Sstevel@tonic-gate (uint64_t)1);
13147c478bd9Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0)
13157c478bd9Sstevel@tonic-gate return (-1);
13167c478bd9Sstevel@tonic-gate
13177c478bd9Sstevel@tonic-gate for (n = sf->next; n != NULL; n = n->next) {
13187c478bd9Sstevel@tonic-gate if (lxml_ignorable_block(n))
13197c478bd9Sstevel@tonic-gate continue;
13207c478bd9Sstevel@tonic-gate
13217c478bd9Sstevel@tonic-gate switch (lxml_xlate_element(n->name)) {
13227c478bd9Sstevel@tonic-gate case SC_STABILITY:
13237c478bd9Sstevel@tonic-gate if (new_str_prop_from_attr(pg,
13247c478bd9Sstevel@tonic-gate SCF_PROPERTY_ENTITY_STABILITY, SCF_TYPE_ASTRING, n,
13257c478bd9Sstevel@tonic-gate value_attr) != 0)
13267c478bd9Sstevel@tonic-gate return (-1);
13277c478bd9Sstevel@tonic-gate break;
13287c478bd9Sstevel@tonic-gate
13297c478bd9Sstevel@tonic-gate case SC_PROPVAL:
13307c478bd9Sstevel@tonic-gate (void) lxml_get_propval(pg, n);
13317c478bd9Sstevel@tonic-gate break;
13327c478bd9Sstevel@tonic-gate
13337c478bd9Sstevel@tonic-gate case SC_PROPERTY:
13347c478bd9Sstevel@tonic-gate (void) lxml_get_property(pg, n);
13357c478bd9Sstevel@tonic-gate break;
13367c478bd9Sstevel@tonic-gate
13377c478bd9Sstevel@tonic-gate default:
13387c478bd9Sstevel@tonic-gate uu_die(gettext("unexpected element %s.\n"), n->name);
13397c478bd9Sstevel@tonic-gate }
13407c478bd9Sstevel@tonic-gate }
13417c478bd9Sstevel@tonic-gate
13427c478bd9Sstevel@tonic-gate /* Go back and fill in defaults. */
13437c478bd9Sstevel@tonic-gate if (internal_property_find(pg, SCF_PROPERTY_TYPE) == NULL) {
13447c478bd9Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_TYPE,
13457c478bd9Sstevel@tonic-gate SCF_TYPE_ASTRING, 1, "service");
13467c478bd9Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0)
13477c478bd9Sstevel@tonic-gate return (-1);
13487c478bd9Sstevel@tonic-gate }
13497c478bd9Sstevel@tonic-gate
13507c478bd9Sstevel@tonic-gate delete = xmlGetProp(dependent, (xmlChar *)delete_attr);
13517c478bd9Sstevel@tonic-gate pg->sc_pgroup_delete = (xmlStrcmp(delete, (xmlChar *)true) == 0);
13527c478bd9Sstevel@tonic-gate xmlFree(delete);
13537c478bd9Sstevel@tonic-gate
13547c478bd9Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, "dependents",
13557c478bd9Sstevel@tonic-gate (char *)scf_group_framework);
13569e9ae1fcSbustos p = internal_property_create((char *)name, SCF_TYPE_FMRI, 1, fmri);
13577c478bd9Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0)
13587c478bd9Sstevel@tonic-gate return (-1);
13597c478bd9Sstevel@tonic-gate
13607c478bd9Sstevel@tonic-gate return (0);
13617c478bd9Sstevel@tonic-gate }
13627c478bd9Sstevel@tonic-gate
13637c478bd9Sstevel@tonic-gate static int
lxml_get_entity_stability(entity_t * entity,xmlNodePtr rstr)13647c478bd9Sstevel@tonic-gate lxml_get_entity_stability(entity_t *entity, xmlNodePtr rstr)
13657c478bd9Sstevel@tonic-gate {
13667c478bd9Sstevel@tonic-gate pgroup_t *pg;
13677c478bd9Sstevel@tonic-gate property_t *p;
13687c478bd9Sstevel@tonic-gate xmlChar *stabval;
13697c478bd9Sstevel@tonic-gate
13701f6eb021SLiane Praza if (((stabval = xmlGetProp(rstr, (xmlChar *)value_attr)) == NULL) ||
13711f6eb021SLiane Praza (*stabval == 0)) {
13727c478bd9Sstevel@tonic-gate uu_warn(gettext("no stability value found\n"));
13737c478bd9Sstevel@tonic-gate stabval = (xmlChar *)strdup("External");
13747c478bd9Sstevel@tonic-gate }
13757c478bd9Sstevel@tonic-gate
13767c478bd9Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, (char *)scf_pg_general,
13777c478bd9Sstevel@tonic-gate (char *)scf_group_framework);
13787c478bd9Sstevel@tonic-gate
13797c478bd9Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_ENTITY_STABILITY,
13807c478bd9Sstevel@tonic-gate SCF_TYPE_ASTRING, 1, stabval);
13817c478bd9Sstevel@tonic-gate
13827c478bd9Sstevel@tonic-gate return (internal_attach_property(pg, p));
13837c478bd9Sstevel@tonic-gate }
13847c478bd9Sstevel@tonic-gate
13857c478bd9Sstevel@tonic-gate static int
lxml_get_restarter(entity_t * entity,xmlNodePtr rstr)13867c478bd9Sstevel@tonic-gate lxml_get_restarter(entity_t *entity, xmlNodePtr rstr)
13877c478bd9Sstevel@tonic-gate {
13887c478bd9Sstevel@tonic-gate pgroup_t *pg;
13897c478bd9Sstevel@tonic-gate property_t *p;
13907c478bd9Sstevel@tonic-gate xmlChar *restarter;
13917c478bd9Sstevel@tonic-gate xmlNode *cursor;
13927c478bd9Sstevel@tonic-gate int r;
13937c478bd9Sstevel@tonic-gate
13947c478bd9Sstevel@tonic-gate /*
13957c478bd9Sstevel@tonic-gate * Go find child. Child is a service_fmri element. value attribute
13967c478bd9Sstevel@tonic-gate * contains restarter FMRI.
13977c478bd9Sstevel@tonic-gate */
13987c478bd9Sstevel@tonic-gate
13997c478bd9Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, (char *)scf_pg_general,
14007c478bd9Sstevel@tonic-gate (char *)scf_group_framework);
14017c478bd9Sstevel@tonic-gate
14027c478bd9Sstevel@tonic-gate /*
14037c478bd9Sstevel@tonic-gate * Walk its child elements, as appropriate.
14047c478bd9Sstevel@tonic-gate */
14057c478bd9Sstevel@tonic-gate for (cursor = rstr->xmlChildrenNode; cursor != NULL;
14067c478bd9Sstevel@tonic-gate cursor = cursor->next) {
14077c478bd9Sstevel@tonic-gate if (lxml_ignorable_block(cursor))
14087c478bd9Sstevel@tonic-gate continue;
14097c478bd9Sstevel@tonic-gate
14107c478bd9Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) {
14117c478bd9Sstevel@tonic-gate case SC_SERVICE_FMRI:
14127c478bd9Sstevel@tonic-gate restarter = xmlGetProp(cursor, (xmlChar *)value_attr);
14137c478bd9Sstevel@tonic-gate break;
14147c478bd9Sstevel@tonic-gate default:
14157c478bd9Sstevel@tonic-gate uu_die(gettext("illegal element \"%s\" on restarter "
14167c478bd9Sstevel@tonic-gate "element for \"%s\"\n"), cursor->name,
14177c478bd9Sstevel@tonic-gate entity->sc_name);
14187c478bd9Sstevel@tonic-gate break;
14197c478bd9Sstevel@tonic-gate }
14207c478bd9Sstevel@tonic-gate }
14217c478bd9Sstevel@tonic-gate
14227c478bd9Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_RESTARTER, SCF_TYPE_FMRI, 1,
14237c478bd9Sstevel@tonic-gate restarter);
14247c478bd9Sstevel@tonic-gate
14257c478bd9Sstevel@tonic-gate r = internal_attach_property(pg, p);
14267c478bd9Sstevel@tonic-gate if (r != 0) {
14277c478bd9Sstevel@tonic-gate internal_property_free(p);
14287c478bd9Sstevel@tonic-gate return (-1);
14297c478bd9Sstevel@tonic-gate }
14307c478bd9Sstevel@tonic-gate
14317c478bd9Sstevel@tonic-gate return (0);
14327c478bd9Sstevel@tonic-gate }
14337c478bd9Sstevel@tonic-gate
1434*f6e214c7SGavin Maltby static void
lxml_get_paramval(pgroup_t * pgrp,const char * propname,xmlNodePtr pval)1435*f6e214c7SGavin Maltby lxml_get_paramval(pgroup_t *pgrp, const char *propname, xmlNodePtr pval)
1436*f6e214c7SGavin Maltby {
1437*f6e214c7SGavin Maltby property_t *p;
1438*f6e214c7SGavin Maltby char *value;
1439*f6e214c7SGavin Maltby char *prop;
1440*f6e214c7SGavin Maltby
1441*f6e214c7SGavin Maltby if ((prop = strdup(propname)) == NULL)
1442*f6e214c7SGavin Maltby uu_die(gettext("Out of memory.\n"));
1443*f6e214c7SGavin Maltby
1444*f6e214c7SGavin Maltby value = (char *)xmlGetProp(pval, (xmlChar *)value_attr);
1445*f6e214c7SGavin Maltby if (value == NULL || *value == '\0')
1446*f6e214c7SGavin Maltby uu_die(gettext("property value missing for property '%s/%s'\n"),
1447*f6e214c7SGavin Maltby pgrp->sc_pgroup_name, propname);
1448*f6e214c7SGavin Maltby p = internal_property_create(prop, SCF_TYPE_ASTRING, 1, value);
1449*f6e214c7SGavin Maltby
1450*f6e214c7SGavin Maltby (void) internal_attach_property(pgrp, p);
1451*f6e214c7SGavin Maltby }
1452*f6e214c7SGavin Maltby
1453*f6e214c7SGavin Maltby static void
lxml_get_parameter(pgroup_t * pgrp,const char * propname,xmlNodePtr param)1454*f6e214c7SGavin Maltby lxml_get_parameter(pgroup_t *pgrp, const char *propname, xmlNodePtr param)
1455*f6e214c7SGavin Maltby {
1456*f6e214c7SGavin Maltby property_t *p = internal_property_new();
1457*f6e214c7SGavin Maltby
1458*f6e214c7SGavin Maltby if ((p->sc_property_name = strdup(propname)) == NULL)
1459*f6e214c7SGavin Maltby uu_die(gettext("Out of memory.\n"));
1460*f6e214c7SGavin Maltby p->sc_value_type = SCF_TYPE_ASTRING;
1461*f6e214c7SGavin Maltby
1462*f6e214c7SGavin Maltby (void) lxml_get_value(p, SC_ASTRING, param);
1463*f6e214c7SGavin Maltby
1464*f6e214c7SGavin Maltby (void) internal_attach_property(pgrp, p);
1465*f6e214c7SGavin Maltby }
1466*f6e214c7SGavin Maltby
1467*f6e214c7SGavin Maltby static void
lxml_get_type(pgroup_t * pgrp,xmlNodePtr type)1468*f6e214c7SGavin Maltby lxml_get_type(pgroup_t *pgrp, xmlNodePtr type)
1469*f6e214c7SGavin Maltby {
1470*f6e214c7SGavin Maltby property_t *p;
1471*f6e214c7SGavin Maltby xmlChar *name;
1472*f6e214c7SGavin Maltby xmlChar *active;
1473*f6e214c7SGavin Maltby xmlNodePtr cursor;
1474*f6e214c7SGavin Maltby uint64_t active_val;
1475*f6e214c7SGavin Maltby size_t sz = max_scf_name_len + 1;
1476*f6e214c7SGavin Maltby char *propname = safe_malloc(sz);
1477*f6e214c7SGavin Maltby
1478*f6e214c7SGavin Maltby if (pgrp->sc_parent->sc_op == SVCCFG_OP_APPLY)
1479*f6e214c7SGavin Maltby lxml_validate_element(type);
1480*f6e214c7SGavin Maltby
1481*f6e214c7SGavin Maltby name = xmlGetProp(type, (xmlChar *)name_attr);
1482*f6e214c7SGavin Maltby if (name == NULL || *name == '\0')
1483*f6e214c7SGavin Maltby uu_die(gettext("attribute name missing in element 'type'\n"));
1484*f6e214c7SGavin Maltby
1485*f6e214c7SGavin Maltby for (cursor = type->xmlChildrenNode; cursor != NULL;
1486*f6e214c7SGavin Maltby cursor = cursor->next) {
1487*f6e214c7SGavin Maltby xmlChar *pname;
1488*f6e214c7SGavin Maltby
1489*f6e214c7SGavin Maltby if (lxml_ignorable_block(cursor))
1490*f6e214c7SGavin Maltby continue;
1491*f6e214c7SGavin Maltby
1492*f6e214c7SGavin Maltby pname = xmlGetProp(cursor, (xmlChar *)name_attr);
1493*f6e214c7SGavin Maltby if (pname == NULL || *pname == '\0')
1494*f6e214c7SGavin Maltby uu_die(gettext(
1495*f6e214c7SGavin Maltby "attribute name missing in sub-element of type\n"));
1496*f6e214c7SGavin Maltby
1497*f6e214c7SGavin Maltby if (snprintf(propname, sz, "%s,%s", (char *)name,
1498*f6e214c7SGavin Maltby (char *)pname) >= sz)
1499*f6e214c7SGavin Maltby uu_die(gettext("name '%s,%s' is too long\n"),
1500*f6e214c7SGavin Maltby (char *)name, (char *)pname);
1501*f6e214c7SGavin Maltby xmlFree(pname);
1502*f6e214c7SGavin Maltby
1503*f6e214c7SGavin Maltby switch (lxml_xlate_element(cursor->name)) {
1504*f6e214c7SGavin Maltby case SC_PARAMETER:
1505*f6e214c7SGavin Maltby lxml_get_parameter(pgrp, propname, cursor);
1506*f6e214c7SGavin Maltby break;
1507*f6e214c7SGavin Maltby
1508*f6e214c7SGavin Maltby case SC_PARAMVAL:
1509*f6e214c7SGavin Maltby lxml_get_paramval(pgrp, propname, cursor);
1510*f6e214c7SGavin Maltby break;
1511*f6e214c7SGavin Maltby
1512*f6e214c7SGavin Maltby default:
1513*f6e214c7SGavin Maltby uu_die(gettext("unknown element %s\n"), cursor->name);
1514*f6e214c7SGavin Maltby }
1515*f6e214c7SGavin Maltby }
1516*f6e214c7SGavin Maltby
1517*f6e214c7SGavin Maltby active = xmlGetProp(type, (xmlChar *)active_attr);
1518*f6e214c7SGavin Maltby if (active == NULL || strcmp(true, (const char *)active) == 0)
1519*f6e214c7SGavin Maltby active_val = 1;
1520*f6e214c7SGavin Maltby else
1521*f6e214c7SGavin Maltby active_val = 0;
1522*f6e214c7SGavin Maltby xmlFree(active);
1523*f6e214c7SGavin Maltby
1524*f6e214c7SGavin Maltby if (snprintf(propname, sz, "%s,%s", (char *)name,
1525*f6e214c7SGavin Maltby SCF_PROPERTY_ACTIVE_POSTFIX) >= sz)
1526*f6e214c7SGavin Maltby uu_die(gettext("name '%s,%s' is too long\n"),
1527*f6e214c7SGavin Maltby (char *)name, SCF_PROPERTY_ACTIVE_POSTFIX);
1528*f6e214c7SGavin Maltby
1529*f6e214c7SGavin Maltby p = internal_property_create(propname, SCF_TYPE_BOOLEAN, 1, active_val);
1530*f6e214c7SGavin Maltby
1531*f6e214c7SGavin Maltby (void) internal_attach_property(pgrp, p);
1532*f6e214c7SGavin Maltby
1533*f6e214c7SGavin Maltby xmlFree(name);
1534*f6e214c7SGavin Maltby }
1535*f6e214c7SGavin Maltby
1536*f6e214c7SGavin Maltby static void
lxml_get_event(entity_t * entity,const char * pgname,xmlNodePtr np)1537*f6e214c7SGavin Maltby lxml_get_event(entity_t *entity, const char *pgname, xmlNodePtr np)
1538*f6e214c7SGavin Maltby {
1539*f6e214c7SGavin Maltby xmlNodePtr cursor;
1540*f6e214c7SGavin Maltby pgroup_t *pgrp;
1541*f6e214c7SGavin Maltby
1542*f6e214c7SGavin Maltby pgrp = internal_pgroup_find_or_create(entity, pgname,
1543*f6e214c7SGavin Maltby SCF_NOTIFY_PARAMS_PG_TYPE);
1544*f6e214c7SGavin Maltby for (cursor = np->xmlChildrenNode; cursor != NULL;
1545*f6e214c7SGavin Maltby cursor = cursor->next) {
1546*f6e214c7SGavin Maltby if (lxml_ignorable_block(cursor))
1547*f6e214c7SGavin Maltby continue;
1548*f6e214c7SGavin Maltby
1549*f6e214c7SGavin Maltby switch (lxml_xlate_element(cursor->name)) {
1550*f6e214c7SGavin Maltby case SC_EVENT:
1551*f6e214c7SGavin Maltby continue;
1552*f6e214c7SGavin Maltby
1553*f6e214c7SGavin Maltby case SC_TYPE:
1554*f6e214c7SGavin Maltby lxml_get_type(pgrp, cursor);
1555*f6e214c7SGavin Maltby break;
1556*f6e214c7SGavin Maltby
1557*f6e214c7SGavin Maltby default:
1558*f6e214c7SGavin Maltby uu_warn(gettext("illegal element '%s' on "
1559*f6e214c7SGavin Maltby "notification parameters\n"), cursor->name);
1560*f6e214c7SGavin Maltby }
1561*f6e214c7SGavin Maltby }
1562*f6e214c7SGavin Maltby }
1563*f6e214c7SGavin Maltby
1564*f6e214c7SGavin Maltby static int
lxml_get_notification_parameters(entity_t * entity,xmlNodePtr np)1565*f6e214c7SGavin Maltby lxml_get_notification_parameters(entity_t *entity, xmlNodePtr np)
1566*f6e214c7SGavin Maltby {
1567*f6e214c7SGavin Maltby char *event = NULL;
1568*f6e214c7SGavin Maltby char **pgs = NULL;
1569*f6e214c7SGavin Maltby char **p;
1570*f6e214c7SGavin Maltby char *pgname = NULL;
1571*f6e214c7SGavin Maltby xmlNodePtr cursor;
1572*f6e214c7SGavin Maltby int32_t tset, t;
1573*f6e214c7SGavin Maltby size_t sz = max_scf_name_len + 1;
1574*f6e214c7SGavin Maltby int count;
1575*f6e214c7SGavin Maltby int r = -1;
1576*f6e214c7SGavin Maltby
1577*f6e214c7SGavin Maltby for (count = 0, cursor = np->xmlChildrenNode; cursor != NULL;
1578*f6e214c7SGavin Maltby cursor = cursor->next) {
1579*f6e214c7SGavin Maltby if (lxml_ignorable_block(cursor))
1580*f6e214c7SGavin Maltby continue;
1581*f6e214c7SGavin Maltby
1582*f6e214c7SGavin Maltby if (lxml_xlate_element(cursor->name) == SC_EVENT) {
1583*f6e214c7SGavin Maltby xmlChar *s;
1584*f6e214c7SGavin Maltby
1585*f6e214c7SGavin Maltby count++;
1586*f6e214c7SGavin Maltby if (count > 1)
1587*f6e214c7SGavin Maltby uu_die(gettext("Can't have more than 1 element "
1588*f6e214c7SGavin Maltby "event in a notification parameter\n"));
1589*f6e214c7SGavin Maltby s = xmlGetProp(cursor, (xmlChar *)value_attr);
1590*f6e214c7SGavin Maltby if (s == NULL || (event = strdup((char *)s)) == NULL)
1591*f6e214c7SGavin Maltby uu_die(gettext("couldn't allocate memory"));
1592*f6e214c7SGavin Maltby xmlFree(s);
1593*f6e214c7SGavin Maltby }
1594*f6e214c7SGavin Maltby }
1595*f6e214c7SGavin Maltby
1596*f6e214c7SGavin Maltby pgs = tokenize(event, ",");
1597*f6e214c7SGavin Maltby
1598*f6e214c7SGavin Maltby switch (tset = check_tokens(pgs)) {
1599*f6e214c7SGavin Maltby case INVALID_TOKENS:
1600*f6e214c7SGavin Maltby uu_die(gettext("Invalid input.\n"));
1601*f6e214c7SGavin Maltby /*NOTREACHED*/
1602*f6e214c7SGavin Maltby case MIXED_TOKENS:
1603*f6e214c7SGavin Maltby semerr(gettext("Can't mix SMF and FMA event definitions\n"));
1604*f6e214c7SGavin Maltby goto out;
1605*f6e214c7SGavin Maltby case FMA_TOKENS:
1606*f6e214c7SGavin Maltby /* make sure this is SCF_NOTIFY_PARAMS_INST */
1607*f6e214c7SGavin Maltby if (entity->sc_etype != SVCCFG_INSTANCE_OBJECT ||
1608*f6e214c7SGavin Maltby strcmp(entity->sc_fmri, SCF_NOTIFY_PARAMS_INST) != 0) {
1609*f6e214c7SGavin Maltby semerr(gettext(
1610*f6e214c7SGavin Maltby "Non-SMF transition evenst must go to %s\n"),
1611*f6e214c7SGavin Maltby SCF_NOTIFY_PARAMS_INST);
1612*f6e214c7SGavin Maltby goto out;
1613*f6e214c7SGavin Maltby }
1614*f6e214c7SGavin Maltby pgname = safe_malloc(sz);
1615*f6e214c7SGavin Maltby for (p = pgs; *p; ++p) {
1616*f6e214c7SGavin Maltby if (snprintf(pgname, sz, "%s,%s", de_tag(*p),
1617*f6e214c7SGavin Maltby SCF_NOTIFY_PG_POSTFIX) >= sz)
1618*f6e214c7SGavin Maltby uu_die(gettext("event name too long: %s\n"),
1619*f6e214c7SGavin Maltby *p);
1620*f6e214c7SGavin Maltby
1621*f6e214c7SGavin Maltby lxml_get_event(entity, pgname, np);
1622*f6e214c7SGavin Maltby }
1623*f6e214c7SGavin Maltby
1624*f6e214c7SGavin Maltby default: /* smf state transition tokens */
1625*f6e214c7SGavin Maltby if (entity->sc_etype == SVCCFG_SERVICE_OBJECT &&
1626*f6e214c7SGavin Maltby strcmp(entity->sc_fmri, SCF_SERVICE_GLOBAL) == 0) {
1627*f6e214c7SGavin Maltby semerr(gettext(
1628*f6e214c7SGavin Maltby "Can't set events for global service\n"));
1629*f6e214c7SGavin Maltby goto out;
1630*f6e214c7SGavin Maltby }
1631*f6e214c7SGavin Maltby for (t = 0x1; t < SCF_STATE_ALL; t <<= 1) {
1632*f6e214c7SGavin Maltby if (t & tset) {
1633*f6e214c7SGavin Maltby lxml_get_event(entity, tset_to_string(t), np);
1634*f6e214c7SGavin Maltby }
1635*f6e214c7SGavin Maltby if ((t << 16) & tset) {
1636*f6e214c7SGavin Maltby lxml_get_event(entity, tset_to_string(t << 16),
1637*f6e214c7SGavin Maltby np);
1638*f6e214c7SGavin Maltby }
1639*f6e214c7SGavin Maltby }
1640*f6e214c7SGavin Maltby }
1641*f6e214c7SGavin Maltby
1642*f6e214c7SGavin Maltby r = 0;
1643*f6e214c7SGavin Maltby out:
1644*f6e214c7SGavin Maltby free(pgname);
1645*f6e214c7SGavin Maltby free(pgs);
1646*f6e214c7SGavin Maltby free(event);
1647*f6e214c7SGavin Maltby
1648*f6e214c7SGavin Maltby return (r);
1649*f6e214c7SGavin Maltby }
1650*f6e214c7SGavin Maltby
16511f6eb021SLiane Praza /*
16521f6eb021SLiane Praza * Add a property containing the localized text from the manifest. The
16531f6eb021SLiane Praza * property is added to the property group at pg. The name of the created
16541f6eb021SLiane Praza * property is based on the format at pn_format. This is an snprintf(3C)
16551f6eb021SLiane Praza * format containing a single %s conversion specification. At conversion
16561f6eb021SLiane Praza * time, the %s is replaced by the locale designation.
16571f6eb021SLiane Praza *
16581f6eb021SLiane Praza * source is the source element and it is only used for error messages.
16591f6eb021SLiane Praza */
16607c478bd9Sstevel@tonic-gate static int
lxml_get_loctext(entity_t * service,pgroup_t * pg,xmlNodePtr loctext,const char * pn_format,const char * source)16611f6eb021SLiane Praza lxml_get_loctext(entity_t *service, pgroup_t *pg, xmlNodePtr loctext,
16621f6eb021SLiane Praza const char *pn_format, const char *source)
16637c478bd9Sstevel@tonic-gate {
16641f6eb021SLiane Praza int extra;
16657c478bd9Sstevel@tonic-gate xmlNodePtr cursor;
16667c478bd9Sstevel@tonic-gate xmlChar *val;
16677c478bd9Sstevel@tonic-gate char *stripped, *cp;
16687c478bd9Sstevel@tonic-gate property_t *p;
16691f6eb021SLiane Praza char *prop_name;
16707c478bd9Sstevel@tonic-gate int r;
16717c478bd9Sstevel@tonic-gate
16721f6eb021SLiane Praza if (((val = xmlGetProp(loctext, (xmlChar *)xml_lang_attr)) == NULL) ||
16731f6eb021SLiane Praza (*val == 0)) {
16741f6eb021SLiane Praza if (((val = xmlGetProp(loctext,
16751f6eb021SLiane Praza (xmlChar *)lang_attr)) == NULL) || (*val == 0)) {
16767c478bd9Sstevel@tonic-gate val = (xmlChar *)"unknown";
16771f6eb021SLiane Praza }
16781f6eb021SLiane Praza }
16797c478bd9Sstevel@tonic-gate
16801f6eb021SLiane Praza _scf_sanitize_locale((char *)val);
16811f6eb021SLiane Praza prop_name = safe_malloc(max_scf_name_len + 1);
16821f6eb021SLiane Praza if ((extra = snprintf(prop_name, max_scf_name_len + 1, pn_format,
16831f6eb021SLiane Praza val)) >= max_scf_name_len + 1) {
16841f6eb021SLiane Praza extra -= max_scf_name_len;
16851f6eb021SLiane Praza uu_die(gettext("%s attribute is %d characters too long for "
16861f6eb021SLiane Praza "%s in %s\n"),
16871f6eb021SLiane Praza xml_lang_attr, extra, source, service->sc_name);
16881f6eb021SLiane Praza }
16891f6eb021SLiane Praza xmlFree(val);
16907c478bd9Sstevel@tonic-gate
16917c478bd9Sstevel@tonic-gate for (cursor = loctext->xmlChildrenNode; cursor != NULL;
16927c478bd9Sstevel@tonic-gate cursor = cursor->next) {
16937c478bd9Sstevel@tonic-gate if (strcmp("text", (const char *)cursor->name) == 0) {
16947c478bd9Sstevel@tonic-gate break;
16957c478bd9Sstevel@tonic-gate } else if (strcmp("comment", (const char *)cursor->name) != 0) {
16967c478bd9Sstevel@tonic-gate uu_die(gettext("illegal element \"%s\" on loctext "
16977c478bd9Sstevel@tonic-gate "element for \"%s\"\n"), cursor->name,
16987c478bd9Sstevel@tonic-gate service->sc_name);
16997c478bd9Sstevel@tonic-gate }
17007c478bd9Sstevel@tonic-gate }
17017c478bd9Sstevel@tonic-gate
17027c478bd9Sstevel@tonic-gate if (cursor == NULL) {
17037c478bd9Sstevel@tonic-gate uu_die(gettext("loctext element has no content for \"%s\"\n"),
17047c478bd9Sstevel@tonic-gate service->sc_name);
17057c478bd9Sstevel@tonic-gate }
17067c478bd9Sstevel@tonic-gate
17077c478bd9Sstevel@tonic-gate /*
17087c478bd9Sstevel@tonic-gate * Remove leading and trailing whitespace.
17097c478bd9Sstevel@tonic-gate */
17107c478bd9Sstevel@tonic-gate if ((stripped = strdup((const char *)cursor->content)) == NULL)
17117c478bd9Sstevel@tonic-gate uu_die(gettext("Out of memory\n"));
17127c478bd9Sstevel@tonic-gate
171376cf44abSjeanm for (; isspace(*stripped); stripped++)
171476cf44abSjeanm ;
171576cf44abSjeanm for (cp = stripped + strlen(stripped) - 1; isspace(*cp); cp--)
171676cf44abSjeanm ;
17177c478bd9Sstevel@tonic-gate *(cp + 1) = '\0';
17187c478bd9Sstevel@tonic-gate
17191f6eb021SLiane Praza p = internal_property_create(prop_name, SCF_TYPE_USTRING, 1,
17207c478bd9Sstevel@tonic-gate stripped);
17217c478bd9Sstevel@tonic-gate
17227c478bd9Sstevel@tonic-gate r = internal_attach_property(pg, p);
17231f6eb021SLiane Praza if (r != 0) {
17247c478bd9Sstevel@tonic-gate internal_property_free(p);
17251f6eb021SLiane Praza free(prop_name);
17261f6eb021SLiane Praza }
17277c478bd9Sstevel@tonic-gate
17287c478bd9Sstevel@tonic-gate return (r);
17297c478bd9Sstevel@tonic-gate }
17307c478bd9Sstevel@tonic-gate
17311f6eb021SLiane Praza /*
17321f6eb021SLiane Praza * This function processes all loctext elements in the current XML element
17331f6eb021SLiane Praza * designated by container. A property is created for each loctext element
17341f6eb021SLiane Praza * and added to the property group at pg. The name of the property is
17351f6eb021SLiane Praza * derived from the loctext language designation using the format at
17361f6eb021SLiane Praza * pn_format. pn_format should be an snprintf format string containing one
17371f6eb021SLiane Praza * %s which is replaced by the language designation.
17381f6eb021SLiane Praza *
17391f6eb021SLiane Praza * The function returns 0 on success and -1 if it is unable to attach the
17401f6eb021SLiane Praza * newly created property to pg.
17411f6eb021SLiane Praza */
17421f6eb021SLiane Praza static int
lxml_get_all_loctext(entity_t * service,pgroup_t * pg,xmlNodePtr container,const char * pn_format,const char * source)17431f6eb021SLiane Praza lxml_get_all_loctext(entity_t *service, pgroup_t *pg, xmlNodePtr container,
17441f6eb021SLiane Praza const char *pn_format, const char *source)
17451f6eb021SLiane Praza {
17461f6eb021SLiane Praza xmlNodePtr cursor;
17471f6eb021SLiane Praza
17481f6eb021SLiane Praza /*
17491f6eb021SLiane Praza * Iterate through one or more loctext elements. The locale is
17501f6eb021SLiane Praza * used to generate the property name; the contents are the ustring
17511f6eb021SLiane Praza * value for the property.
17521f6eb021SLiane Praza */
17531f6eb021SLiane Praza for (cursor = container->xmlChildrenNode; cursor != NULL;
17541f6eb021SLiane Praza cursor = cursor->next) {
17551f6eb021SLiane Praza if (lxml_ignorable_block(cursor))
17561f6eb021SLiane Praza continue;
17571f6eb021SLiane Praza
17581f6eb021SLiane Praza switch (lxml_xlate_element(cursor->name)) {
17591f6eb021SLiane Praza case SC_LOCTEXT:
17601f6eb021SLiane Praza if (lxml_get_loctext(service, pg, cursor, pn_format,
17611f6eb021SLiane Praza source))
17621f6eb021SLiane Praza return (-1);
17631f6eb021SLiane Praza break;
17641f6eb021SLiane Praza default:
17651f6eb021SLiane Praza uu_die(gettext("illegal element \"%s\" on %s element "
17661f6eb021SLiane Praza "for \"%s\"\n"), cursor->name, container->name,
17671f6eb021SLiane Praza service->sc_name);
17681f6eb021SLiane Praza break;
17691f6eb021SLiane Praza }
17701f6eb021SLiane Praza }
17711f6eb021SLiane Praza
17721f6eb021SLiane Praza return (0);
17731f6eb021SLiane Praza }
17741f6eb021SLiane Praza
17751f6eb021SLiane Praza /*
17761f6eb021SLiane Praza * Obtain the specified cardinality attribute and place it in a property
17771f6eb021SLiane Praza * named prop_name. The converted attribute is placed at *value, and the
17781f6eb021SLiane Praza * newly created property is returned to propp. NULL is returned to propp
17791f6eb021SLiane Praza * if the attribute is not provided in the manifest.
17801f6eb021SLiane Praza *
17811f6eb021SLiane Praza * 0 is returned upon success, and -1 indicates that the manifest contained
17821f6eb021SLiane Praza * an invalid cardinality value.
17831f6eb021SLiane Praza */
17841f6eb021SLiane Praza static int
lxml_get_cardinality_attribute(entity_t * service,xmlNodePtr cursor,const char * attr_name,const char * prop_name,uint64_t * value,property_t ** propp)17851f6eb021SLiane Praza lxml_get_cardinality_attribute(entity_t *service, xmlNodePtr cursor,
17861f6eb021SLiane Praza const char *attr_name, const char *prop_name, uint64_t *value,
17871f6eb021SLiane Praza property_t **propp)
17881f6eb021SLiane Praza {
17891f6eb021SLiane Praza char *c;
17901f6eb021SLiane Praza property_t *p;
17911f6eb021SLiane Praza xmlChar *val;
17921f6eb021SLiane Praza uint64_t count;
17931f6eb021SLiane Praza char *endptr;
17941f6eb021SLiane Praza
17951f6eb021SLiane Praza *propp = NULL;
17961f6eb021SLiane Praza val = xmlGetProp(cursor, (xmlChar *)attr_name);
17971f6eb021SLiane Praza if (val == NULL)
17981f6eb021SLiane Praza return (0);
17991f6eb021SLiane Praza if (*val == 0) {
18001f6eb021SLiane Praza xmlFree(val);
18011f6eb021SLiane Praza return (0);
18021f6eb021SLiane Praza }
18031f6eb021SLiane Praza
18041f6eb021SLiane Praza /*
18051f6eb021SLiane Praza * Make sure that the string at val doesn't have a leading minus
18061f6eb021SLiane Praza * sign. The strtoull() call below does not catch this problem.
18071f6eb021SLiane Praza */
18081f6eb021SLiane Praza for (c = (char *)val; *c != 0; c++) {
18091f6eb021SLiane Praza if (isspace(*c))
18101f6eb021SLiane Praza continue;
18111f6eb021SLiane Praza if (isdigit(*c))
18121f6eb021SLiane Praza break;
18131f6eb021SLiane Praza semerr(gettext("\"%c\" is not a legal character in the %s "
18141f6eb021SLiane Praza "attribute of the %s element in %s.\n"), *c,
18151f6eb021SLiane Praza attr_name, prop_name, service->sc_name);
18161f6eb021SLiane Praza xmlFree(val);
18171f6eb021SLiane Praza return (-1);
18181f6eb021SLiane Praza }
18191f6eb021SLiane Praza errno = 0;
18201f6eb021SLiane Praza count = strtoull((char *)val, &endptr, 10);
18211f6eb021SLiane Praza if (errno != 0 || endptr == (char *)val || *endptr) {
18221f6eb021SLiane Praza semerr(gettext("\"%s\" is not a legal number for the %s "
18231f6eb021SLiane Praza "attribute of the %s element in %s.\n"), (char *)val,
18241f6eb021SLiane Praza attr_name, prop_name, service->sc_name);
18251f6eb021SLiane Praza xmlFree(val);
18261f6eb021SLiane Praza return (-1);
18271f6eb021SLiane Praza }
18281f6eb021SLiane Praza
18291f6eb021SLiane Praza xmlFree(val);
18301f6eb021SLiane Praza
18311f6eb021SLiane Praza /* Value is valid. Create the property. */
18321f6eb021SLiane Praza p = internal_property_create(prop_name, SCF_TYPE_COUNT, 1, count);
18331f6eb021SLiane Praza *value = count;
18341f6eb021SLiane Praza *propp = p;
18351f6eb021SLiane Praza return (0);
18361f6eb021SLiane Praza }
18371f6eb021SLiane Praza
18381f6eb021SLiane Praza /*
18391f6eb021SLiane Praza * The cardinality is specified by two attributes max and min at cursor.
18401f6eb021SLiane Praza * Both are optional, but if present they must be unsigned integers.
18411f6eb021SLiane Praza */
18421f6eb021SLiane Praza static int
lxml_get_tm_cardinality(entity_t * service,pgroup_t * pg,xmlNodePtr cursor)18431f6eb021SLiane Praza lxml_get_tm_cardinality(entity_t *service, pgroup_t *pg, xmlNodePtr cursor)
18441f6eb021SLiane Praza {
18451f6eb021SLiane Praza int min_attached = 0;
18461f6eb021SLiane Praza int compare = 1;
18471f6eb021SLiane Praza property_t *min_prop;
18481f6eb021SLiane Praza property_t *max_prop;
18491f6eb021SLiane Praza uint64_t max;
18501f6eb021SLiane Praza uint64_t min;
18511f6eb021SLiane Praza int r;
18521f6eb021SLiane Praza
18531f6eb021SLiane Praza r = lxml_get_cardinality_attribute(service, cursor, min_attr,
18541f6eb021SLiane Praza SCF_PROPERTY_TM_CARDINALITY_MIN, &min, &min_prop);
18551f6eb021SLiane Praza if (r != 0)
18561f6eb021SLiane Praza return (r);
18571f6eb021SLiane Praza if (min_prop == NULL)
18581f6eb021SLiane Praza compare = 0;
18591f6eb021SLiane Praza r = lxml_get_cardinality_attribute(service, cursor, max_attr,
18601f6eb021SLiane Praza SCF_PROPERTY_TM_CARDINALITY_MAX, &max, &max_prop);
18611f6eb021SLiane Praza if (r != 0)
18621f6eb021SLiane Praza goto errout;
18631f6eb021SLiane Praza if ((max_prop != NULL) && (compare == 1)) {
18641f6eb021SLiane Praza if (max < min) {
18651f6eb021SLiane Praza semerr(gettext("Cardinality max is less than min for "
18661f6eb021SLiane Praza "the %s element in %s.\n"), pg->sc_pgroup_name,
18671f6eb021SLiane Praza service->sc_fmri);
18681f6eb021SLiane Praza goto errout;
18691f6eb021SLiane Praza }
18701f6eb021SLiane Praza }
18711f6eb021SLiane Praza
18721f6eb021SLiane Praza /* Attach the properties to the property group. */
18731f6eb021SLiane Praza if (min_prop) {
18741f6eb021SLiane Praza if (internal_attach_property(pg, min_prop) == 0) {
18751f6eb021SLiane Praza min_attached = 1;
18761f6eb021SLiane Praza } else {
18771f6eb021SLiane Praza goto errout;
18781f6eb021SLiane Praza }
18791f6eb021SLiane Praza }
18801f6eb021SLiane Praza if (max_prop) {
18811f6eb021SLiane Praza if (internal_attach_property(pg, max_prop) != 0) {
18821f6eb021SLiane Praza if (min_attached)
18831f6eb021SLiane Praza internal_detach_property(pg, min_prop);
18841f6eb021SLiane Praza goto errout;
18851f6eb021SLiane Praza }
18861f6eb021SLiane Praza }
18871f6eb021SLiane Praza return (0);
18881f6eb021SLiane Praza
18891f6eb021SLiane Praza errout:
18901f6eb021SLiane Praza if (min_prop)
18911f6eb021SLiane Praza internal_property_free(min_prop);
18921f6eb021SLiane Praza if (max_prop)
18931f6eb021SLiane Praza internal_property_free(max_prop);
18941f6eb021SLiane Praza return (-1);
18951f6eb021SLiane Praza }
18961f6eb021SLiane Praza
18971f6eb021SLiane Praza /*
18981f6eb021SLiane Praza * Get the common_name which is present as localized text at common_name in
18991f6eb021SLiane Praza * the manifest. The common_name is stored as the value of a property in
19001f6eb021SLiane Praza * the property group whose name is SCF_PG_TM_COMMON_NAME and type is
19011f6eb021SLiane Praza * SCF_GROUP_TEMPLATE. This property group will be created in service if
19021f6eb021SLiane Praza * it is not already there.
19031f6eb021SLiane Praza */
19047c478bd9Sstevel@tonic-gate static int
lxml_get_tm_common_name(entity_t * service,xmlNodePtr common_name)19057c478bd9Sstevel@tonic-gate lxml_get_tm_common_name(entity_t *service, xmlNodePtr common_name)
19067c478bd9Sstevel@tonic-gate {
19077c478bd9Sstevel@tonic-gate pgroup_t *pg;
19087c478bd9Sstevel@tonic-gate
19097c478bd9Sstevel@tonic-gate /*
19107c478bd9Sstevel@tonic-gate * Create the property group, if absent.
19117c478bd9Sstevel@tonic-gate */
19121f6eb021SLiane Praza pg = internal_pgroup_find_or_create(service, SCF_PG_TM_COMMON_NAME,
19131f6eb021SLiane Praza SCF_GROUP_TEMPLATE);
19141f6eb021SLiane Praza
19151f6eb021SLiane Praza return (lxml_get_all_loctext(service, pg, common_name, LOCALE_ONLY_FMT,
19161f6eb021SLiane Praza "common_name"));
19171f6eb021SLiane Praza }
19187c478bd9Sstevel@tonic-gate
19197c478bd9Sstevel@tonic-gate /*
19201f6eb021SLiane Praza * Get the description which is present as localized text at description in
19211f6eb021SLiane Praza * the manifest. The description is stored as the value of a property in
19221f6eb021SLiane Praza * the property group whose name is SCF_PG_TM_DESCRIPTION and type is
19231f6eb021SLiane Praza * SCF_GROUP_TEMPLATE. This property group will be created in service if
19241f6eb021SLiane Praza * it is not already there.
19257c478bd9Sstevel@tonic-gate */
19267c478bd9Sstevel@tonic-gate static int
lxml_get_tm_description(entity_t * service,xmlNodePtr description)19277c478bd9Sstevel@tonic-gate lxml_get_tm_description(entity_t *service, xmlNodePtr description)
19287c478bd9Sstevel@tonic-gate {
19297c478bd9Sstevel@tonic-gate pgroup_t *pg;
19307c478bd9Sstevel@tonic-gate
19317c478bd9Sstevel@tonic-gate /*
19327c478bd9Sstevel@tonic-gate * Create the property group, if absent.
19337c478bd9Sstevel@tonic-gate */
19341f6eb021SLiane Praza pg = internal_pgroup_find_or_create(service, SCF_PG_TM_DESCRIPTION,
19351f6eb021SLiane Praza SCF_GROUP_TEMPLATE);
19367c478bd9Sstevel@tonic-gate
19371f6eb021SLiane Praza return (lxml_get_all_loctext(service, pg, description,
19381f6eb021SLiane Praza LOCALE_ONLY_FMT, "description"));
19397c478bd9Sstevel@tonic-gate }
19407c478bd9Sstevel@tonic-gate
19417c478bd9Sstevel@tonic-gate static char *
lxml_label_to_groupname(const char * prefix,const char * in)19427c478bd9Sstevel@tonic-gate lxml_label_to_groupname(const char *prefix, const char *in)
19437c478bd9Sstevel@tonic-gate {
19447c478bd9Sstevel@tonic-gate char *out, *cp;
19457c478bd9Sstevel@tonic-gate size_t len, piece_len;
19467c478bd9Sstevel@tonic-gate
19477c478bd9Sstevel@tonic-gate out = uu_zalloc(2 * scf_limit(SCF_LIMIT_MAX_NAME_LENGTH) + 1);
19487c478bd9Sstevel@tonic-gate if (out == NULL)
19497c478bd9Sstevel@tonic-gate return (NULL);
19507c478bd9Sstevel@tonic-gate
19517c478bd9Sstevel@tonic-gate (void) strcpy(out, prefix);
19527c478bd9Sstevel@tonic-gate (void) strcat(out, in);
19537c478bd9Sstevel@tonic-gate
19547c478bd9Sstevel@tonic-gate len = strlen(out);
19557c478bd9Sstevel@tonic-gate if (len > max_scf_name_len) {
19567c478bd9Sstevel@tonic-gate /* Use the first half and the second half. */
19577c478bd9Sstevel@tonic-gate piece_len = (max_scf_name_len - 2) / 2;
19587c478bd9Sstevel@tonic-gate
19597c478bd9Sstevel@tonic-gate (void) strncpy(out + piece_len, "..", 2);
19607c478bd9Sstevel@tonic-gate
19617c478bd9Sstevel@tonic-gate (void) strcpy(out + piece_len + 2, out + (len - piece_len));
19627c478bd9Sstevel@tonic-gate
19637c478bd9Sstevel@tonic-gate len = strlen(out);
19647c478bd9Sstevel@tonic-gate }
19657c478bd9Sstevel@tonic-gate
19667c478bd9Sstevel@tonic-gate /*
19677c478bd9Sstevel@tonic-gate * Translate non-property characters to '_'.
19687c478bd9Sstevel@tonic-gate */
19697c478bd9Sstevel@tonic-gate for (cp = out; *cp != '\0'; ++cp) {
19707c478bd9Sstevel@tonic-gate if (!(isalnum(*cp) || *cp == '_' || *cp == '-'))
19717c478bd9Sstevel@tonic-gate *cp = '_';
19727c478bd9Sstevel@tonic-gate }
19737c478bd9Sstevel@tonic-gate
19747c478bd9Sstevel@tonic-gate *cp = '\0';
19757c478bd9Sstevel@tonic-gate
19767c478bd9Sstevel@tonic-gate return (out);
19777c478bd9Sstevel@tonic-gate }
19787c478bd9Sstevel@tonic-gate
19791f6eb021SLiane Praza /*
19801f6eb021SLiane Praza * If *p is NULL, astring_prop_value() first creates a property with the
19811f6eb021SLiane Praza * name specified in prop_name. The address of the newly created property
19821f6eb021SLiane Praza * is placed in *p.
19831f6eb021SLiane Praza *
19841f6eb021SLiane Praza * In either case, newly created property or existing property, a new
19851f6eb021SLiane Praza * SCF_TYPE_ASTRING value will created and attached to the property at *p.
19861f6eb021SLiane Praza * The value of the newly created property is prop_value.
19871f6eb021SLiane Praza *
19881f6eb021SLiane Praza * free_flag is used to indicate whether or not the memory at prop_value
19891f6eb021SLiane Praza * should be freed when the property is freed by a call to
19901f6eb021SLiane Praza * internal_property_free().
19911f6eb021SLiane Praza */
19921f6eb021SLiane Praza static void
astring_prop_value(property_t ** p,const char * prop_name,char * prop_value,boolean_t free_flag)19931f6eb021SLiane Praza astring_prop_value(property_t **p, const char *prop_name, char *prop_value,
19941f6eb021SLiane Praza boolean_t free_flag)
19951f6eb021SLiane Praza {
19961f6eb021SLiane Praza value_t *v;
19971f6eb021SLiane Praza
19981f6eb021SLiane Praza if (*p == NULL) {
19991f6eb021SLiane Praza /* Create the property */
20001f6eb021SLiane Praza *p = internal_property_new();
20011f6eb021SLiane Praza (*p)->sc_property_name = (char *)prop_name;
20021f6eb021SLiane Praza (*p)->sc_value_type = SCF_TYPE_ASTRING;
20031f6eb021SLiane Praza }
20041f6eb021SLiane Praza
20051f6eb021SLiane Praza /* Add the property value to the property's list of values. */
20061f6eb021SLiane Praza v = internal_value_new();
20071f6eb021SLiane Praza v->sc_type = SCF_TYPE_ASTRING;
20081f6eb021SLiane Praza if (free_flag == B_TRUE)
20091f6eb021SLiane Praza v->sc_free = lxml_free_str;
20101f6eb021SLiane Praza v->sc_u.sc_string = prop_value;
20111f6eb021SLiane Praza internal_attach_value(*p, v);
20121f6eb021SLiane Praza }
20131f6eb021SLiane Praza
20141f6eb021SLiane Praza /*
20151f6eb021SLiane Praza * If p points to a null pointer, create an internal_separators property
20161f6eb021SLiane Praza * saving the address at p. For each character at seps create a property
20171f6eb021SLiane Praza * value and attach it to the property at p.
20181f6eb021SLiane Praza */
20191f6eb021SLiane Praza static void
seps_to_prop_values(property_t ** p,xmlChar * seps)20201f6eb021SLiane Praza seps_to_prop_values(property_t **p, xmlChar *seps)
20211f6eb021SLiane Praza {
20221f6eb021SLiane Praza value_t *v;
20231f6eb021SLiane Praza char val_str[2];
20241f6eb021SLiane Praza
20251f6eb021SLiane Praza if (*p == NULL) {
20261f6eb021SLiane Praza *p = internal_property_new();
20271f6eb021SLiane Praza (*p)->sc_property_name =
20281f6eb021SLiane Praza (char *)SCF_PROPERTY_INTERNAL_SEPARATORS;
20291f6eb021SLiane Praza (*p)->sc_value_type = SCF_TYPE_ASTRING;
20301f6eb021SLiane Praza }
20311f6eb021SLiane Praza
20321f6eb021SLiane Praza /* Add the values to the property's list. */
20331f6eb021SLiane Praza val_str[1] = 0; /* Terminate the string. */
20341f6eb021SLiane Praza for (; *seps != 0; seps++) {
20351f6eb021SLiane Praza v = internal_value_new();
20361f6eb021SLiane Praza v->sc_type = (*p)->sc_value_type;
20371f6eb021SLiane Praza v->sc_free = lxml_free_str;
20381f6eb021SLiane Praza val_str[0] = *seps;
20391f6eb021SLiane Praza v->sc_u.sc_string = strdup(val_str);
20401f6eb021SLiane Praza if (v->sc_u.sc_string == NULL)
20411f6eb021SLiane Praza uu_die(gettext("Out of memory\n"));
20421f6eb021SLiane Praza internal_attach_value(*p, v);
20431f6eb021SLiane Praza }
20441f6eb021SLiane Praza }
20451f6eb021SLiane Praza
20461f6eb021SLiane Praza /*
20471f6eb021SLiane Praza * Create an internal_separators property and attach it to the property
20481f6eb021SLiane Praza * group at pg. The separator characters are provided in the text nodes
20491f6eb021SLiane Praza * that are the children of seps. Each separator character is stored as a
20501f6eb021SLiane Praza * property value in the internal_separators property.
20511f6eb021SLiane Praza */
20521f6eb021SLiane Praza static int
lxml_get_tm_internal_seps(entity_t * service,pgroup_t * pg,xmlNodePtr seps)20531f6eb021SLiane Praza lxml_get_tm_internal_seps(entity_t *service, pgroup_t *pg, xmlNodePtr seps)
20541f6eb021SLiane Praza {
20551f6eb021SLiane Praza xmlNodePtr cursor;
20561f6eb021SLiane Praza property_t *prop = NULL;
20571f6eb021SLiane Praza int r;
20581f6eb021SLiane Praza
20591f6eb021SLiane Praza for (cursor = seps->xmlChildrenNode; cursor != NULL;
20601f6eb021SLiane Praza cursor = cursor->next) {
20611f6eb021SLiane Praza if (strcmp("text", (const char *)cursor->name) == 0) {
20621f6eb021SLiane Praza seps_to_prop_values(&prop, cursor->content);
20631f6eb021SLiane Praza } else if (strcmp("comment", (const char *)cursor->name) != 0) {
20641f6eb021SLiane Praza uu_die(gettext("illegal element \"%s\" on %s element "
20651f6eb021SLiane Praza "for \"%s\"\n"), cursor->name, seps->name,
20661f6eb021SLiane Praza service->sc_name);
20671f6eb021SLiane Praza }
20681f6eb021SLiane Praza }
20691f6eb021SLiane Praza if (prop == NULL) {
20701f6eb021SLiane Praza semerr(gettext("The %s element in %s had an empty list of "
20711f6eb021SLiane Praza "separators.\n"), (const char *)seps->name,
20721f6eb021SLiane Praza service->sc_name);
20731f6eb021SLiane Praza return (-1);
20741f6eb021SLiane Praza }
20751f6eb021SLiane Praza r = internal_attach_property(pg, prop);
20761f6eb021SLiane Praza if (r != 0)
20771f6eb021SLiane Praza internal_property_free(prop);
20781f6eb021SLiane Praza return (r);
20791f6eb021SLiane Praza }
20801f6eb021SLiane Praza
20817c478bd9Sstevel@tonic-gate static int
lxml_get_tm_manpage(entity_t * service,xmlNodePtr manpage)20827c478bd9Sstevel@tonic-gate lxml_get_tm_manpage(entity_t *service, xmlNodePtr manpage)
20837c478bd9Sstevel@tonic-gate {
20847c478bd9Sstevel@tonic-gate pgroup_t *pg;
20857c478bd9Sstevel@tonic-gate char *pgname;
20867c478bd9Sstevel@tonic-gate xmlChar *title;
20877c478bd9Sstevel@tonic-gate
20887c478bd9Sstevel@tonic-gate /*
20897c478bd9Sstevel@tonic-gate * Fetch title attribute, convert to something sanitized, and create
20907c478bd9Sstevel@tonic-gate * property group.
20917c478bd9Sstevel@tonic-gate */
20921f6eb021SLiane Praza title = xmlGetProp(manpage, (xmlChar *)title_attr);
20937c478bd9Sstevel@tonic-gate pgname = (char *)lxml_label_to_groupname(SCF_PG_TM_MAN_PREFIX,
20947c478bd9Sstevel@tonic-gate (const char *)title);
20951f6eb021SLiane Praza xmlFree(title);
20967c478bd9Sstevel@tonic-gate
20977c478bd9Sstevel@tonic-gate pg = internal_pgroup_find_or_create(service, pgname,
20987c478bd9Sstevel@tonic-gate (char *)SCF_GROUP_TEMPLATE);
20997c478bd9Sstevel@tonic-gate
21007c478bd9Sstevel@tonic-gate /*
21017c478bd9Sstevel@tonic-gate * Each attribute is an astring property within the group.
21027c478bd9Sstevel@tonic-gate */
21031f6eb021SLiane Praza if (new_str_prop_from_attr(pg, SCF_PROPERTY_TM_TITLE,
21041f6eb021SLiane Praza SCF_TYPE_ASTRING, manpage, title_attr) != 0 ||
21051f6eb021SLiane Praza new_str_prop_from_attr(pg, SCF_PROPERTY_TM_SECTION,
21061f6eb021SLiane Praza SCF_TYPE_ASTRING, manpage, section_attr) != 0 ||
21071f6eb021SLiane Praza new_str_prop_from_attr(pg, SCF_PROPERTY_TM_MANPATH,
21081f6eb021SLiane Praza SCF_TYPE_ASTRING, manpage, manpath_attr) != 0)
21097c478bd9Sstevel@tonic-gate return (-1);
21107c478bd9Sstevel@tonic-gate
21117c478bd9Sstevel@tonic-gate return (0);
21127c478bd9Sstevel@tonic-gate }
21137c478bd9Sstevel@tonic-gate
21147c478bd9Sstevel@tonic-gate static int
lxml_get_tm_doclink(entity_t * service,xmlNodePtr doc_link)21157c478bd9Sstevel@tonic-gate lxml_get_tm_doclink(entity_t *service, xmlNodePtr doc_link)
21167c478bd9Sstevel@tonic-gate {
21177c478bd9Sstevel@tonic-gate pgroup_t *pg;
21187c478bd9Sstevel@tonic-gate char *pgname;
21197c478bd9Sstevel@tonic-gate xmlChar *name;
21207c478bd9Sstevel@tonic-gate
21217c478bd9Sstevel@tonic-gate /*
21227c478bd9Sstevel@tonic-gate * Fetch name attribute, convert name to something sanitized, and create
21237c478bd9Sstevel@tonic-gate * property group.
21247c478bd9Sstevel@tonic-gate */
21251f6eb021SLiane Praza name = xmlGetProp(doc_link, (xmlChar *)name_attr);
21267c478bd9Sstevel@tonic-gate
21277c478bd9Sstevel@tonic-gate pgname = (char *)lxml_label_to_groupname(SCF_PG_TM_DOC_PREFIX,
21287c478bd9Sstevel@tonic-gate (const char *)name);
21297c478bd9Sstevel@tonic-gate
21307c478bd9Sstevel@tonic-gate pg = internal_pgroup_find_or_create(service, pgname,
21317c478bd9Sstevel@tonic-gate (char *)SCF_GROUP_TEMPLATE);
21321f6eb021SLiane Praza xmlFree(name);
21337c478bd9Sstevel@tonic-gate
21347c478bd9Sstevel@tonic-gate /*
21357c478bd9Sstevel@tonic-gate * Each attribute is an astring property within the group.
21367c478bd9Sstevel@tonic-gate */
21371f6eb021SLiane Praza if (new_str_prop_from_attr(pg, SCF_PROPERTY_TM_NAME, SCF_TYPE_ASTRING,
21381f6eb021SLiane Praza doc_link, name_attr) != 0 ||
21391f6eb021SLiane Praza new_str_prop_from_attr(pg, SCF_PROPERTY_TM_URI, SCF_TYPE_ASTRING,
21401f6eb021SLiane Praza doc_link, uri_attr) != 0)
21417c478bd9Sstevel@tonic-gate return (-1);
21427c478bd9Sstevel@tonic-gate
21437c478bd9Sstevel@tonic-gate return (0);
21447c478bd9Sstevel@tonic-gate }
21457c478bd9Sstevel@tonic-gate
21467c478bd9Sstevel@tonic-gate static int
lxml_get_tm_documentation(entity_t * service,xmlNodePtr documentation)21477c478bd9Sstevel@tonic-gate lxml_get_tm_documentation(entity_t *service, xmlNodePtr documentation)
21487c478bd9Sstevel@tonic-gate {
21497c478bd9Sstevel@tonic-gate xmlNodePtr cursor;
21507c478bd9Sstevel@tonic-gate
21517c478bd9Sstevel@tonic-gate for (cursor = documentation->xmlChildrenNode; cursor != NULL;
21527c478bd9Sstevel@tonic-gate cursor = cursor->next) {
21537c478bd9Sstevel@tonic-gate if (lxml_ignorable_block(cursor))
21547c478bd9Sstevel@tonic-gate continue;
21557c478bd9Sstevel@tonic-gate
21567c478bd9Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) {
21577c478bd9Sstevel@tonic-gate case SC_MANPAGE:
21587c478bd9Sstevel@tonic-gate (void) lxml_get_tm_manpage(service, cursor);
21597c478bd9Sstevel@tonic-gate break;
21607c478bd9Sstevel@tonic-gate case SC_DOC_LINK:
21617c478bd9Sstevel@tonic-gate (void) lxml_get_tm_doclink(service, cursor);
21627c478bd9Sstevel@tonic-gate break;
21637c478bd9Sstevel@tonic-gate default:
21647c478bd9Sstevel@tonic-gate uu_die(gettext("illegal element \"%s\" on template "
21657c478bd9Sstevel@tonic-gate "for service \"%s\"\n"),
21667c478bd9Sstevel@tonic-gate cursor->name, service->sc_name);
21677c478bd9Sstevel@tonic-gate }
21687c478bd9Sstevel@tonic-gate }
21697c478bd9Sstevel@tonic-gate
21707c478bd9Sstevel@tonic-gate return (0);
21717c478bd9Sstevel@tonic-gate }
21727c478bd9Sstevel@tonic-gate
21737c478bd9Sstevel@tonic-gate static int
lxml_get_prop_pattern_attributes(pgroup_t * pg,xmlNodePtr cursor)21741f6eb021SLiane Praza lxml_get_prop_pattern_attributes(pgroup_t *pg, xmlNodePtr cursor)
21751f6eb021SLiane Praza {
21761f6eb021SLiane Praza if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_TM_NAME,
21771f6eb021SLiane Praza SCF_TYPE_ASTRING, cursor, name_attr, NULL) != 0) {
21781f6eb021SLiane Praza return (-1);
21791f6eb021SLiane Praza }
21801f6eb021SLiane Praza if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_TM_TYPE,
21811f6eb021SLiane Praza SCF_TYPE_ASTRING, cursor, type_attr, "") != 0) {
21821f6eb021SLiane Praza return (-1);
21831f6eb021SLiane Praza }
21841f6eb021SLiane Praza if (new_bool_prop_from_attr(pg, SCF_PROPERTY_TM_REQUIRED, cursor,
21851f6eb021SLiane Praza required_attr) != 0)
21861f6eb021SLiane Praza return (-1);
21871f6eb021SLiane Praza return (0);
21881f6eb021SLiane Praza }
21891f6eb021SLiane Praza
21901f6eb021SLiane Praza static int
lxml_get_tm_include_values(entity_t * service,pgroup_t * pg,xmlNodePtr include_values,const char * prop_name)21911f6eb021SLiane Praza lxml_get_tm_include_values(entity_t *service, pgroup_t *pg,
21921f6eb021SLiane Praza xmlNodePtr include_values, const char *prop_name)
21931f6eb021SLiane Praza {
21941f6eb021SLiane Praza boolean_t attach_to_pg = B_FALSE;
21951f6eb021SLiane Praza property_t *p;
21961f6eb021SLiane Praza int r = 0;
21971f6eb021SLiane Praza char *type;
21981f6eb021SLiane Praza
21991f6eb021SLiane Praza /* Get the type attribute of the include_values element. */
22001f6eb021SLiane Praza type = (char *)xmlGetProp(include_values, (const xmlChar *)type_attr);
22011f6eb021SLiane Praza if ((type == NULL) || (*type == 0)) {
22021f6eb021SLiane Praza uu_die(gettext("%s element requires a %s attribute in the %s "
22031f6eb021SLiane Praza "service.\n"), include_values->name, type_attr,
22041f6eb021SLiane Praza service->sc_name);
22051f6eb021SLiane Praza }
22061f6eb021SLiane Praza
22071f6eb021SLiane Praza /* Add the type to the values of the prop_name property. */
22081f6eb021SLiane Praza p = internal_property_find(pg, prop_name);
22091f6eb021SLiane Praza if (p == NULL)
22101f6eb021SLiane Praza attach_to_pg = B_TRUE;
22111f6eb021SLiane Praza astring_prop_value(&p, prop_name, type, B_FALSE);
22121f6eb021SLiane Praza if (attach_to_pg == B_TRUE) {
22131f6eb021SLiane Praza r = internal_attach_property(pg, p);
22141f6eb021SLiane Praza if (r != 0)
22151f6eb021SLiane Praza internal_property_free(p);
22161f6eb021SLiane Praza }
22171f6eb021SLiane Praza return (r);
22181f6eb021SLiane Praza }
22191f6eb021SLiane Praza
22201f6eb021SLiane Praza #define RC_MIN 0
22211f6eb021SLiane Praza #define RC_MAX 1
22221f6eb021SLiane Praza #define RC_COUNT 2
22231f6eb021SLiane Praza
22241f6eb021SLiane Praza /*
22251f6eb021SLiane Praza * Verify that the strings at min and max are valid numeric strings. Also
22261f6eb021SLiane Praza * verify that max is numerically >= min.
22271f6eb021SLiane Praza *
22281f6eb021SLiane Praza * 0 is returned if the range is valid, and -1 is returned if it is not.
22291f6eb021SLiane Praza */
22301f6eb021SLiane Praza static int
verify_range(entity_t * service,xmlNodePtr range,char * min,char * max)22311f6eb021SLiane Praza verify_range(entity_t *service, xmlNodePtr range, char *min, char *max)
22321f6eb021SLiane Praza {
22331f6eb021SLiane Praza char *c;
22341f6eb021SLiane Praza int i;
22351f6eb021SLiane Praza int is_signed = 0;
22361f6eb021SLiane Praza int inverted = 0;
22371f6eb021SLiane Praza const char *limit[RC_COUNT];
22381f6eb021SLiane Praza char *strings[RC_COUNT];
22391f6eb021SLiane Praza uint64_t urange[RC_COUNT]; /* unsigned range. */
22401f6eb021SLiane Praza int64_t srange[RC_COUNT]; /* signed range. */
22411f6eb021SLiane Praza
22421f6eb021SLiane Praza strings[RC_MIN] = min;
22431f6eb021SLiane Praza strings[RC_MAX] = max;
22441f6eb021SLiane Praza limit[RC_MIN] = min_attr;
22451f6eb021SLiane Praza limit[RC_MAX] = max_attr;
22461f6eb021SLiane Praza
22471f6eb021SLiane Praza /* See if the range is signed. */
22481f6eb021SLiane Praza for (i = 0; (i < RC_COUNT) && (is_signed == 0); i++) {
22491f6eb021SLiane Praza c = strings[i];
22501f6eb021SLiane Praza while (isspace(*c)) {
22511f6eb021SLiane Praza c++;
22521f6eb021SLiane Praza }
22531f6eb021SLiane Praza if (*c == '-')
22541f6eb021SLiane Praza is_signed = 1;
22551f6eb021SLiane Praza }
22561f6eb021SLiane Praza
22571f6eb021SLiane Praza /* Attempt to convert the strings. */
22581f6eb021SLiane Praza for (i = 0; i < RC_COUNT; i++) {
22591f6eb021SLiane Praza errno = 0;
22601f6eb021SLiane Praza if (is_signed) {
22611f6eb021SLiane Praza srange[i] = strtoll(strings[i], &c, 0);
22621f6eb021SLiane Praza } else {
22631f6eb021SLiane Praza urange[i] = strtoull(strings[i], &c, 0);
22641f6eb021SLiane Praza }
22651f6eb021SLiane Praza if ((errno != 0) || (c == strings[i]) || (*c != 0)) {
22661f6eb021SLiane Praza /* Conversion failed. */
22671f6eb021SLiane Praza uu_die(gettext("Unable to convert %s for the %s "
22681f6eb021SLiane Praza "element in service %s.\n"), limit[i],
22691f6eb021SLiane Praza (char *)range->name, service->sc_name);
22701f6eb021SLiane Praza }
22711f6eb021SLiane Praza }
22721f6eb021SLiane Praza
22731f6eb021SLiane Praza /* Make sure that min is <= max */
22741f6eb021SLiane Praza if (is_signed) {
22751f6eb021SLiane Praza if (srange[RC_MAX] < srange[RC_MIN])
22761f6eb021SLiane Praza inverted = 1;
22771f6eb021SLiane Praza } else {
22781f6eb021SLiane Praza if (urange[RC_MAX] < urange[RC_MIN])
22791f6eb021SLiane Praza inverted = 1;
22801f6eb021SLiane Praza }
22811f6eb021SLiane Praza if (inverted != 0) {
22821f6eb021SLiane Praza semerr(gettext("Maximum less than minimum for the %s element "
22831f6eb021SLiane Praza "in service %s.\n"), (char *)range->name,
22841f6eb021SLiane Praza service->sc_name);
22851f6eb021SLiane Praza return (-1);
22861f6eb021SLiane Praza }
22871f6eb021SLiane Praza
22881f6eb021SLiane Praza return (0);
22891f6eb021SLiane Praza }
22901f6eb021SLiane Praza
22911f6eb021SLiane Praza /*
22921f6eb021SLiane Praza * This, function creates a property named prop_name. The range element
22931f6eb021SLiane Praza * should have two attributes -- min and max. The property value then
22941f6eb021SLiane Praza * becomes the concatenation of their value separated by a comma. The
22951f6eb021SLiane Praza * property is then attached to the property group at pg.
22961f6eb021SLiane Praza *
22971f6eb021SLiane Praza * If pg already contains a property with a name of prop_name, it is only
22981f6eb021SLiane Praza * necessary to create a new value and attach it to the existing property.
22991f6eb021SLiane Praza */
23001f6eb021SLiane Praza static int
lxml_get_tm_range(entity_t * service,pgroup_t * pg,xmlNodePtr range,const char * prop_name)23011f6eb021SLiane Praza lxml_get_tm_range(entity_t *service, pgroup_t *pg, xmlNodePtr range,
23021f6eb021SLiane Praza const char *prop_name)
23031f6eb021SLiane Praza {
23041f6eb021SLiane Praza boolean_t attach_to_pg = B_FALSE;
23051f6eb021SLiane Praza char *max;
23061f6eb021SLiane Praza char *min;
23071f6eb021SLiane Praza property_t *p;
23081f6eb021SLiane Praza char *prop_value;
23091f6eb021SLiane Praza int r = 0;
23101f6eb021SLiane Praza
23111f6eb021SLiane Praza /* Get max and min from the XML description. */
23121f6eb021SLiane Praza max = (char *)xmlGetProp(range, (xmlChar *)max_attr);
23131f6eb021SLiane Praza if ((max == NULL) || (*max == 0)) {
23141f6eb021SLiane Praza uu_die(gettext("%s element is missing the %s attribute in "
23151f6eb021SLiane Praza "service %s.\n"), (char *)range->name, max_attr,
23161f6eb021SLiane Praza service->sc_name);
23171f6eb021SLiane Praza }
23181f6eb021SLiane Praza min = (char *)xmlGetProp(range, (xmlChar *)min_attr);
23191f6eb021SLiane Praza if ((min == NULL) || (*min == 0)) {
23201f6eb021SLiane Praza uu_die(gettext("%s element is missing the %s attribute in "
23211f6eb021SLiane Praza "service %s.\n"), (char *)range->name, min_attr,
23221f6eb021SLiane Praza service->sc_name);
23231f6eb021SLiane Praza }
23241f6eb021SLiane Praza if (verify_range(service, range, min, max) != 0) {
23251f6eb021SLiane Praza xmlFree(min);
23261f6eb021SLiane Praza xmlFree(max);
23271f6eb021SLiane Praza return (-1);
23281f6eb021SLiane Praza }
23291f6eb021SLiane Praza
23301f6eb021SLiane Praza /* Property value is concatenation of min and max. */
23311f6eb021SLiane Praza prop_value = safe_malloc(max_scf_value_len + 1);
23321f6eb021SLiane Praza if (snprintf(prop_value, max_scf_value_len + 1, "%s,%s", min, max) >=
23331f6eb021SLiane Praza max_scf_value_len + 1) {
23341f6eb021SLiane Praza uu_die(gettext("min and max are too long for the %s element "
23351f6eb021SLiane Praza "of %s.\n"), (char *)range->name, service->sc_name);
23361f6eb021SLiane Praza }
23371f6eb021SLiane Praza xmlFree(min);
23381f6eb021SLiane Praza xmlFree(max);
23391f6eb021SLiane Praza
23401f6eb021SLiane Praza /*
23411f6eb021SLiane Praza * If necessary create the property and attach it to the property
23421f6eb021SLiane Praza * group.
23431f6eb021SLiane Praza */
23441f6eb021SLiane Praza p = internal_property_find(pg, prop_name);
23451f6eb021SLiane Praza if (p == NULL)
23461f6eb021SLiane Praza attach_to_pg = B_TRUE;
23471f6eb021SLiane Praza astring_prop_value(&p, prop_name, prop_value, B_TRUE);
23481f6eb021SLiane Praza if (attach_to_pg == B_TRUE) {
23491f6eb021SLiane Praza r = internal_attach_property(pg, p);
23501f6eb021SLiane Praza if (r != 0) {
23511f6eb021SLiane Praza internal_property_free(p);
23521f6eb021SLiane Praza }
23531f6eb021SLiane Praza }
23541f6eb021SLiane Praza return (r);
23551f6eb021SLiane Praza }
23561f6eb021SLiane Praza
23571f6eb021SLiane Praza /*
23581f6eb021SLiane Praza * Determine how many plain characters are represented by count Base32
23591f6eb021SLiane Praza * encoded characters. 5 plain text characters are converted to 8 Base32
23601f6eb021SLiane Praza * characters.
23611f6eb021SLiane Praza */
23621f6eb021SLiane Praza static size_t
encoded_count_to_plain(size_t count)23631f6eb021SLiane Praza encoded_count_to_plain(size_t count)
23641f6eb021SLiane Praza {
23651f6eb021SLiane Praza return (5 * ((count + 7) / 8));
23661f6eb021SLiane Praza }
23671f6eb021SLiane Praza
23681f6eb021SLiane Praza /*
23691f6eb021SLiane Praza * The value element contains 0 or 1 common_name element followed by 0 or 1
23701f6eb021SLiane Praza * description element. It also has a required attribute called "name".
23711f6eb021SLiane Praza * The common_name and description are stored as property values in pg.
23721f6eb021SLiane Praza * The property names are:
23731f6eb021SLiane Praza * value_<name>_common_name_<lang>
23741f6eb021SLiane Praza * value_<name>_description_<lang>
23751f6eb021SLiane Praza *
23761f6eb021SLiane Praza * The <name> portion of the preceeding proper names requires more
23771f6eb021SLiane Praza * explanation. Ideally it would just the name attribute of this value
23781f6eb021SLiane Praza * element. Unfortunately, the name attribute can contain characters that
23791f6eb021SLiane Praza * are not legal in a property name. Thus, we base 32 encode the name
23801f6eb021SLiane Praza * attribute and use that for <name>.
23811f6eb021SLiane Praza *
23821f6eb021SLiane Praza * There are cases where the caller needs to know the name, so it is
23831f6eb021SLiane Praza * returned through the name_value pointer if it is not NULL.
23841f6eb021SLiane Praza *
23851f6eb021SLiane Praza * Parameters:
23861f6eb021SLiane Praza * service - Information about the service that is being
23871f6eb021SLiane Praza * processed. This function only uses this parameter
23881f6eb021SLiane Praza * for producing error messages.
23891f6eb021SLiane Praza *
23901f6eb021SLiane Praza * pg - The property group to receive the newly created
23911f6eb021SLiane Praza * properties.
23921f6eb021SLiane Praza *
23931f6eb021SLiane Praza * value - Pointer to the value element in the XML tree.
23941f6eb021SLiane Praza *
23951f6eb021SLiane Praza * name_value - Address to receive the value of the name attribute.
23961f6eb021SLiane Praza * The caller must free the memory.
23971f6eb021SLiane Praza */
23981f6eb021SLiane Praza static int
lxml_get_tm_value_element(entity_t * service,pgroup_t * pg,xmlNodePtr value,char ** name_value)23991f6eb021SLiane Praza lxml_get_tm_value_element(entity_t *service, pgroup_t *pg, xmlNodePtr value,
24001f6eb021SLiane Praza char **name_value)
24011f6eb021SLiane Praza {
24021f6eb021SLiane Praza char *common_name_fmt;
24031f6eb021SLiane Praza xmlNodePtr cursor;
24041f6eb021SLiane Praza char *description_fmt;
24051f6eb021SLiane Praza char *encoded_value = NULL;
24061f6eb021SLiane Praza size_t extra;
24071f6eb021SLiane Praza char *value_name;
24081f6eb021SLiane Praza int r = 0;
24091f6eb021SLiane Praza
24101f6eb021SLiane Praza common_name_fmt = safe_malloc(max_scf_name_len + 1);
24111f6eb021SLiane Praza description_fmt = safe_malloc(max_scf_name_len + 1);
24121f6eb021SLiane Praza
24131f6eb021SLiane Praza /*
24141f6eb021SLiane Praza * Get the value of our name attribute, so that we can use it to
24151f6eb021SLiane Praza * construct property names.
24161f6eb021SLiane Praza */
24171f6eb021SLiane Praza value_name = (char *)xmlGetProp(value, (xmlChar *)name_attr);
24181f6eb021SLiane Praza /* The value name must be present, but it can be empty. */
24191f6eb021SLiane Praza if (value_name == NULL) {
24201f6eb021SLiane Praza uu_die(gettext("%s element requires a %s attribute in the %s "
24211f6eb021SLiane Praza "service.\n"), (char *)value->name, name_attr,
24221f6eb021SLiane Praza service->sc_name);
24231f6eb021SLiane Praza }
24241f6eb021SLiane Praza
24251f6eb021SLiane Praza /*
24261f6eb021SLiane Praza * The value_name may contain characters that are not valid in in a
24271f6eb021SLiane Praza * property name. So we will encode value_name and then use the
24281f6eb021SLiane Praza * encoded value in the property name.
24291f6eb021SLiane Praza */
24301f6eb021SLiane Praza encoded_value = safe_malloc(max_scf_name_len + 1);
24311f6eb021SLiane Praza if (scf_encode32(value_name, strlen(value_name), encoded_value,
24321f6eb021SLiane Praza max_scf_name_len + 1, &extra, SCF_ENCODE32_PAD) != 0) {
24331f6eb021SLiane Praza extra = encoded_count_to_plain(extra - max_scf_name_len);
24341f6eb021SLiane Praza uu_die(gettext("Constructed property name is %u characters "
24351f6eb021SLiane Praza "too long for value \"%s\" in the %s service.\n"),
24361f6eb021SLiane Praza extra, value_name, service->sc_name);
24371f6eb021SLiane Praza }
24381f6eb021SLiane Praza if ((extra = snprintf(common_name_fmt, max_scf_name_len + 1,
24391f6eb021SLiane Praza VALUE_COMMON_NAME_FMT, SCF_PROPERTY_TM_VALUE_PREFIX,
24401f6eb021SLiane Praza encoded_value)) >= max_scf_name_len + 1) {
24411f6eb021SLiane Praza extra = encoded_count_to_plain(extra - max_scf_name_len);
24421f6eb021SLiane Praza uu_die(gettext("Name attribute is "
24431f6eb021SLiane Praza "%u characters too long for %s in service %s\n"),
24441f6eb021SLiane Praza extra, (char *)value->name, service->sc_name);
24451f6eb021SLiane Praza }
24461f6eb021SLiane Praza if ((extra = snprintf(description_fmt, max_scf_name_len + 1,
24471f6eb021SLiane Praza VALUE_DESCRIPTION_FMT, SCF_PROPERTY_TM_VALUE_PREFIX,
24481f6eb021SLiane Praza encoded_value)) >= max_scf_name_len + 1) {
24491f6eb021SLiane Praza extra = encoded_count_to_plain(extra - max_scf_name_len);
24501f6eb021SLiane Praza uu_die(gettext("Name attribute is "
24511f6eb021SLiane Praza "%u characters too long for %s in service %s\n"),
24521f6eb021SLiane Praza extra, (char *)value->name, service->sc_name);
24531f6eb021SLiane Praza }
24541f6eb021SLiane Praza
24551f6eb021SLiane Praza for (cursor = value->xmlChildrenNode;
24561f6eb021SLiane Praza cursor != NULL;
24571f6eb021SLiane Praza cursor = cursor->next) {
24581f6eb021SLiane Praza if (lxml_ignorable_block(cursor))
24591f6eb021SLiane Praza continue;
24601f6eb021SLiane Praza switch (lxml_xlate_element(cursor->name)) {
24611f6eb021SLiane Praza case SC_COMMON_NAME:
24621f6eb021SLiane Praza r = lxml_get_all_loctext(service, pg, cursor,
24631f6eb021SLiane Praza common_name_fmt, (const char *)cursor->name);
24641f6eb021SLiane Praza break;
24651f6eb021SLiane Praza case SC_DESCRIPTION:
24661f6eb021SLiane Praza r = lxml_get_all_loctext(service, pg, cursor,
24671f6eb021SLiane Praza description_fmt, (const char *)cursor->name);
24681f6eb021SLiane Praza break;
24691f6eb021SLiane Praza default:
24701f6eb021SLiane Praza uu_die(gettext("\"%s\" is an illegal element in %s "
24711f6eb021SLiane Praza "of service %s\n"), (char *)cursor->name,
24721f6eb021SLiane Praza (char *)value->name, service->sc_name);
24731f6eb021SLiane Praza }
24741f6eb021SLiane Praza if (r != 0)
24751f6eb021SLiane Praza break;
24761f6eb021SLiane Praza }
24771f6eb021SLiane Praza
24781f6eb021SLiane Praza free(description_fmt);
24791f6eb021SLiane Praza free(common_name_fmt);
24801f6eb021SLiane Praza if (r == 0) {
24811f6eb021SLiane Praza *name_value = safe_strdup(value_name);
24821f6eb021SLiane Praza }
24831f6eb021SLiane Praza xmlFree(value_name);
24841f6eb021SLiane Praza free(encoded_value);
24851f6eb021SLiane Praza return (r);
24861f6eb021SLiane Praza }
24871f6eb021SLiane Praza
24881f6eb021SLiane Praza static int
lxml_get_tm_choices(entity_t * service,pgroup_t * pg,xmlNodePtr choices)24891f6eb021SLiane Praza lxml_get_tm_choices(entity_t *service, pgroup_t *pg, xmlNodePtr choices)
24901f6eb021SLiane Praza {
24911f6eb021SLiane Praza xmlNodePtr cursor;
24921f6eb021SLiane Praza char *name_value;
24931f6eb021SLiane Praza property_t *name_prop = NULL;
24941f6eb021SLiane Praza int r = 0;
24951f6eb021SLiane Praza
24961f6eb021SLiane Praza for (cursor = choices->xmlChildrenNode;
24971f6eb021SLiane Praza (cursor != NULL) && (r == 0);
24981f6eb021SLiane Praza cursor = cursor->next) {
24991f6eb021SLiane Praza if (lxml_ignorable_block(cursor))
25001f6eb021SLiane Praza continue;
25011f6eb021SLiane Praza switch (lxml_xlate_element(cursor->name)) {
25021f6eb021SLiane Praza case SC_INCLUDE_VALUES:
25031f6eb021SLiane Praza (void) lxml_get_tm_include_values(service, pg, cursor,
25041f6eb021SLiane Praza SCF_PROPERTY_TM_CHOICES_INCLUDE_VALUES);
25051f6eb021SLiane Praza break;
25061f6eb021SLiane Praza case SC_RANGE:
25071f6eb021SLiane Praza r = lxml_get_tm_range(service, pg, cursor,
25081f6eb021SLiane Praza SCF_PROPERTY_TM_CHOICES_RANGE);
25091f6eb021SLiane Praza if (r != 0)
25101f6eb021SLiane Praza goto out;
25111f6eb021SLiane Praza break;
25121f6eb021SLiane Praza case SC_VALUE:
25131f6eb021SLiane Praza r = lxml_get_tm_value_element(service, pg, cursor,
25141f6eb021SLiane Praza &name_value);
25151f6eb021SLiane Praza if (r == 0) {
25161f6eb021SLiane Praza /*
25171f6eb021SLiane Praza * There is no need to free the memory
25181f6eb021SLiane Praza * associated with name_value, because the
25191f6eb021SLiane Praza * property value will end up pointing to
25201f6eb021SLiane Praza * the memory.
25211f6eb021SLiane Praza */
25221f6eb021SLiane Praza astring_prop_value(&name_prop,
25231f6eb021SLiane Praza SCF_PROPERTY_TM_CHOICES_NAME, name_value,
25241f6eb021SLiane Praza B_TRUE);
25251f6eb021SLiane Praza } else {
25261f6eb021SLiane Praza goto out;
25271f6eb021SLiane Praza }
25281f6eb021SLiane Praza break;
25291f6eb021SLiane Praza default:
25301f6eb021SLiane Praza uu_die(gettext("%s is an invalid element of "
25311f6eb021SLiane Praza "choices for service %s.\n"), cursor->name,
25321f6eb021SLiane Praza service->sc_name);
25331f6eb021SLiane Praza }
25341f6eb021SLiane Praza }
25351f6eb021SLiane Praza
25361f6eb021SLiane Praza out:
25371f6eb021SLiane Praza /* Attach the name property if we created one. */
25381f6eb021SLiane Praza if ((r == 0) && (name_prop != NULL)) {
25391f6eb021SLiane Praza r = internal_attach_property(pg, name_prop);
25401f6eb021SLiane Praza }
25411f6eb021SLiane Praza if ((r != 0) && (name_prop != NULL)) {
25421f6eb021SLiane Praza internal_property_free(name_prop);
25431f6eb021SLiane Praza }
25441f6eb021SLiane Praza
25451f6eb021SLiane Praza return (r);
25461f6eb021SLiane Praza }
25471f6eb021SLiane Praza
25481f6eb021SLiane Praza static int
lxml_get_tm_constraints(entity_t * service,pgroup_t * pg,xmlNodePtr constraints)25491f6eb021SLiane Praza lxml_get_tm_constraints(entity_t *service, pgroup_t *pg, xmlNodePtr constraints)
25501f6eb021SLiane Praza {
25511f6eb021SLiane Praza xmlNodePtr cursor;
25521f6eb021SLiane Praza char *name_value;
25531f6eb021SLiane Praza property_t *name_prop = NULL;
25541f6eb021SLiane Praza int r = 0;
25551f6eb021SLiane Praza
25561f6eb021SLiane Praza for (cursor = constraints->xmlChildrenNode;
25571f6eb021SLiane Praza (cursor != NULL) && (r == 0);
25581f6eb021SLiane Praza cursor = cursor->next) {
25591f6eb021SLiane Praza if (lxml_ignorable_block(cursor))
25601f6eb021SLiane Praza continue;
25611f6eb021SLiane Praza switch (lxml_xlate_element(cursor->name)) {
25621f6eb021SLiane Praza case SC_RANGE:
25631f6eb021SLiane Praza r = lxml_get_tm_range(service, pg, cursor,
25641f6eb021SLiane Praza SCF_PROPERTY_TM_CONSTRAINT_RANGE);
25651f6eb021SLiane Praza if (r != 0)
25661f6eb021SLiane Praza goto out;
25671f6eb021SLiane Praza break;
25681f6eb021SLiane Praza case SC_VALUE:
25691f6eb021SLiane Praza r = lxml_get_tm_value_element(service, pg, cursor,
25701f6eb021SLiane Praza &name_value);
25711f6eb021SLiane Praza if (r == 0) {
25721f6eb021SLiane Praza /*
25731f6eb021SLiane Praza * There is no need to free the memory
25741f6eb021SLiane Praza * associated with name_value, because the
25751f6eb021SLiane Praza * property value will end up pointing to
25761f6eb021SLiane Praza * the memory.
25771f6eb021SLiane Praza */
25781f6eb021SLiane Praza astring_prop_value(&name_prop,
25791f6eb021SLiane Praza SCF_PROPERTY_TM_CONSTRAINT_NAME, name_value,
25801f6eb021SLiane Praza B_TRUE);
25811f6eb021SLiane Praza } else {
25821f6eb021SLiane Praza goto out;
25831f6eb021SLiane Praza }
25841f6eb021SLiane Praza break;
25851f6eb021SLiane Praza default:
25861f6eb021SLiane Praza uu_die(gettext("%s is an invalid element of "
25871f6eb021SLiane Praza "constraints for service %s.\n"), cursor->name,
25881f6eb021SLiane Praza service->sc_name);
25891f6eb021SLiane Praza }
25901f6eb021SLiane Praza }
25911f6eb021SLiane Praza
25921f6eb021SLiane Praza out:
25931f6eb021SLiane Praza /* Attach the name property if we created one. */
25941f6eb021SLiane Praza if ((r == 0) && (name_prop != NULL)) {
25951f6eb021SLiane Praza r = internal_attach_property(pg, name_prop);
25961f6eb021SLiane Praza }
25971f6eb021SLiane Praza if ((r != 0) && (name_prop != NULL)) {
25981f6eb021SLiane Praza internal_property_free(name_prop);
25991f6eb021SLiane Praza }
26001f6eb021SLiane Praza
26011f6eb021SLiane Praza return (r);
26021f6eb021SLiane Praza }
26031f6eb021SLiane Praza
26041f6eb021SLiane Praza /*
26051f6eb021SLiane Praza * The values element contains one or more value elements.
26061f6eb021SLiane Praza */
26071f6eb021SLiane Praza static int
lxml_get_tm_values(entity_t * service,pgroup_t * pg,xmlNodePtr values)26081f6eb021SLiane Praza lxml_get_tm_values(entity_t *service, pgroup_t *pg, xmlNodePtr values)
26091f6eb021SLiane Praza {
26101f6eb021SLiane Praza xmlNodePtr cursor;
26111f6eb021SLiane Praza char *name_value;
26121f6eb021SLiane Praza property_t *name_prop = NULL;
26131f6eb021SLiane Praza int r = 0;
26141f6eb021SLiane Praza
26151f6eb021SLiane Praza for (cursor = values->xmlChildrenNode;
26161f6eb021SLiane Praza (cursor != NULL) && (r == 0);
26171f6eb021SLiane Praza cursor = cursor->next) {
26181f6eb021SLiane Praza if (lxml_ignorable_block(cursor))
26191f6eb021SLiane Praza continue;
26201f6eb021SLiane Praza if (lxml_xlate_element(cursor->name) != SC_VALUE) {
26211f6eb021SLiane Praza uu_die(gettext("\"%s\" is an illegal element in the "
26221f6eb021SLiane Praza "%s element of %s\n"), (char *)cursor->name,
26231f6eb021SLiane Praza (char *)values->name, service->sc_name);
26241f6eb021SLiane Praza }
26251f6eb021SLiane Praza r = lxml_get_tm_value_element(service, pg, cursor, &name_value);
26261f6eb021SLiane Praza if (r == 0) {
26271f6eb021SLiane Praza /*
26281f6eb021SLiane Praza * There is no need to free the memory
26291f6eb021SLiane Praza * associated with name_value, because the
26301f6eb021SLiane Praza * property value will end up pointing to
26311f6eb021SLiane Praza * the memory.
26321f6eb021SLiane Praza */
26331f6eb021SLiane Praza astring_prop_value(&name_prop,
26341f6eb021SLiane Praza SCF_PROPERTY_TM_VALUES_NAME, name_value,
26351f6eb021SLiane Praza B_TRUE);
26361f6eb021SLiane Praza }
26371f6eb021SLiane Praza }
26381f6eb021SLiane Praza
26391f6eb021SLiane Praza /* Attach the name property if we created one. */
26401f6eb021SLiane Praza if ((r == 0) && (name_prop != NULL)) {
26411f6eb021SLiane Praza r = internal_attach_property(pg, name_prop);
26421f6eb021SLiane Praza }
26431f6eb021SLiane Praza if ((r != 0) && (name_prop != NULL)) {
26441f6eb021SLiane Praza internal_property_free(name_prop);
26451f6eb021SLiane Praza }
26461f6eb021SLiane Praza
26471f6eb021SLiane Praza return (r);
26481f6eb021SLiane Praza }
26491f6eb021SLiane Praza
26501f6eb021SLiane Praza /*
26511f6eb021SLiane Praza * This function processes a prop_pattern element within a pg_pattern XML
26521f6eb021SLiane Praza * element. First it creates a property group to hold the prop_pattern
26531f6eb021SLiane Praza * information. The name of this property group is the concatenation of:
26541f6eb021SLiane Praza * - SCF_PG_TM_PROP_PATTERN_PREFIX
26551f6eb021SLiane Praza * - The unique part of the property group name of the enclosing
26561f6eb021SLiane Praza * pg_pattern. The property group name of the enclosing pg_pattern
26571f6eb021SLiane Praza * is passed to us in pgpat_name. The unique part, is the part
26581f6eb021SLiane Praza * following SCF_PG_TM_PG_PATTERN_PREFIX.
26591f6eb021SLiane Praza * - The name of this prop_pattern element.
26601f6eb021SLiane Praza *
26611f6eb021SLiane Praza * After creating the property group, the prop_pattern attributes are saved
26621f6eb021SLiane Praza * as properties in the PG. Finally, the prop_pattern elements are
26631f6eb021SLiane Praza * processed and added to the PG.
26641f6eb021SLiane Praza */
26651f6eb021SLiane Praza static int
lxml_get_tm_prop_pattern(entity_t * service,xmlNodePtr prop_pattern,const char * pgpat_name)26661f6eb021SLiane Praza lxml_get_tm_prop_pattern(entity_t *service, xmlNodePtr prop_pattern,
26671f6eb021SLiane Praza const char *pgpat_name)
26681f6eb021SLiane Praza {
26691f6eb021SLiane Praza xmlNodePtr cursor;
26701f6eb021SLiane Praza int extra;
26711f6eb021SLiane Praza pgroup_t *pg;
26721f6eb021SLiane Praza property_t *p;
26731f6eb021SLiane Praza char *pg_name;
26741f6eb021SLiane Praza size_t prefix_len;
26751f6eb021SLiane Praza xmlChar *prop_pattern_name;
26761f6eb021SLiane Praza int r;
26771f6eb021SLiane Praza const char *unique;
26781f6eb021SLiane Praza value_t *v;
26791f6eb021SLiane Praza
26801f6eb021SLiane Praza /* Find the unique part of the pg_pattern property group name. */
26811f6eb021SLiane Praza prefix_len = strlen(SCF_PG_TM_PG_PAT_BASE);
26821f6eb021SLiane Praza assert(strncmp(pgpat_name, SCF_PG_TM_PG_PAT_BASE, prefix_len) == 0);
26831f6eb021SLiane Praza unique = pgpat_name + prefix_len;
26841f6eb021SLiane Praza
26851f6eb021SLiane Praza /*
26861f6eb021SLiane Praza * We need to get the value of the name attribute first. The
26871f6eb021SLiane Praza * prop_pattern name as well as the name of the enclosing
26881f6eb021SLiane Praza * pg_pattern both constitute part of the name of the property
26891f6eb021SLiane Praza * group that we will create.
26901f6eb021SLiane Praza */
26911f6eb021SLiane Praza prop_pattern_name = xmlGetProp(prop_pattern, (xmlChar *)name_attr);
26921f6eb021SLiane Praza if ((prop_pattern_name == NULL) || (*prop_pattern_name == 0)) {
26931f6eb021SLiane Praza semerr(gettext("prop_pattern name is missing for %s\n"),
26941f6eb021SLiane Praza service->sc_name);
26951f6eb021SLiane Praza return (-1);
26961f6eb021SLiane Praza }
26971f6eb021SLiane Praza if (uu_check_name((const char *)prop_pattern_name,
26981f6eb021SLiane Praza UU_NAME_DOMAIN) != 0) {
26991f6eb021SLiane Praza semerr(gettext("prop_pattern name, \"%s\", for %s is not "
27001f6eb021SLiane Praza "valid.\n"), prop_pattern_name, service->sc_name);
27011f6eb021SLiane Praza xmlFree(prop_pattern_name);
27021f6eb021SLiane Praza return (-1);
27031f6eb021SLiane Praza }
27041f6eb021SLiane Praza pg_name = safe_malloc(max_scf_name_len + 1);
27051f6eb021SLiane Praza if ((extra = snprintf(pg_name, max_scf_name_len + 1, "%s%s_%s",
27061f6eb021SLiane Praza SCF_PG_TM_PROP_PATTERN_PREFIX, unique,
27071f6eb021SLiane Praza (char *)prop_pattern_name)) >= max_scf_name_len + 1) {
27081f6eb021SLiane Praza uu_die(gettext("prop_pattern name, \"%s\", for %s is %d "
27091f6eb021SLiane Praza "characters too long\n"), (char *)prop_pattern_name,
27101f6eb021SLiane Praza service->sc_name, extra - max_scf_name_len);
27111f6eb021SLiane Praza }
27121f6eb021SLiane Praza
27131f6eb021SLiane Praza /*
27141f6eb021SLiane Praza * Create the property group, the property referencing the pg_pattern
27151f6eb021SLiane Praza * name, and add the prop_pattern attributes to the property group.
27161f6eb021SLiane Praza */
27171f6eb021SLiane Praza pg = internal_pgroup_create_strict(service, pg_name,
27181f6eb021SLiane Praza SCF_GROUP_TEMPLATE_PROP_PATTERN);
27191f6eb021SLiane Praza if (pg == NULL) {
27201f6eb021SLiane Praza uu_die(gettext("Property group for prop_pattern, \"%s\", "
27211f6eb021SLiane Praza "already exists in %s\n"), prop_pattern_name,
27221f6eb021SLiane Praza service->sc_name);
27231f6eb021SLiane Praza }
27241f6eb021SLiane Praza
27251f6eb021SLiane Praza p = internal_property_create(SCF_PROPERTY_TM_PG_PATTERN,
27261f6eb021SLiane Praza SCF_TYPE_ASTRING, 1, safe_strdup(pgpat_name));
27271f6eb021SLiane Praza /*
27281f6eb021SLiane Praza * Unfortunately, internal_property_create() does not set the free
27291f6eb021SLiane Praza * function for the value, so we'll set it now.
27301f6eb021SLiane Praza */
27311f6eb021SLiane Praza v = uu_list_first(p->sc_property_values);
27321f6eb021SLiane Praza v->sc_free = lxml_free_str;
27331f6eb021SLiane Praza if (internal_attach_property(pg, p) != 0)
27341f6eb021SLiane Praza internal_property_free(p);
27351f6eb021SLiane Praza
27361f6eb021SLiane Praza
27371f6eb021SLiane Praza r = lxml_get_prop_pattern_attributes(pg, prop_pattern);
27381f6eb021SLiane Praza if (r != 0)
27391f6eb021SLiane Praza goto out;
27401f6eb021SLiane Praza
27411f6eb021SLiane Praza /*
27421f6eb021SLiane Praza * Now process the elements of prop_pattern
27431f6eb021SLiane Praza */
27441f6eb021SLiane Praza for (cursor = prop_pattern->xmlChildrenNode;
27451f6eb021SLiane Praza cursor != NULL;
27461f6eb021SLiane Praza cursor = cursor->next) {
27471f6eb021SLiane Praza if (lxml_ignorable_block(cursor))
27481f6eb021SLiane Praza continue;
27491f6eb021SLiane Praza
27501f6eb021SLiane Praza switch (lxml_xlate_element(cursor->name)) {
27511f6eb021SLiane Praza case SC_CARDINALITY:
27521f6eb021SLiane Praza r = lxml_get_tm_cardinality(service, pg, cursor);
27531f6eb021SLiane Praza if (r != 0)
27541f6eb021SLiane Praza goto out;
27551f6eb021SLiane Praza break;
27561f6eb021SLiane Praza case SC_CHOICES:
27571f6eb021SLiane Praza r = lxml_get_tm_choices(service, pg, cursor);
27581f6eb021SLiane Praza if (r != 0)
27591f6eb021SLiane Praza goto out;
27601f6eb021SLiane Praza break;
27611f6eb021SLiane Praza case SC_COMMON_NAME:
27621f6eb021SLiane Praza (void) lxml_get_all_loctext(service, pg, cursor,
27631f6eb021SLiane Praza COMMON_NAME_FMT, (const char *)cursor->name);
27641f6eb021SLiane Praza break;
27651f6eb021SLiane Praza case SC_CONSTRAINTS:
27661f6eb021SLiane Praza r = lxml_get_tm_constraints(service, pg, cursor);
27671f6eb021SLiane Praza if (r != 0)
27681f6eb021SLiane Praza goto out;
27691f6eb021SLiane Praza break;
27701f6eb021SLiane Praza case SC_DESCRIPTION:
27711f6eb021SLiane Praza (void) lxml_get_all_loctext(service, pg, cursor,
27721f6eb021SLiane Praza DESCRIPTION_FMT, (const char *)cursor->name);
27731f6eb021SLiane Praza break;
27741f6eb021SLiane Praza case SC_INTERNAL_SEPARATORS:
27751f6eb021SLiane Praza r = lxml_get_tm_internal_seps(service, pg, cursor);
27761f6eb021SLiane Praza if (r != 0)
27771f6eb021SLiane Praza goto out;
27781f6eb021SLiane Praza break;
27791f6eb021SLiane Praza case SC_UNITS:
27801f6eb021SLiane Praza (void) lxml_get_all_loctext(service, pg, cursor,
27811f6eb021SLiane Praza UNITS_FMT, "units");
27821f6eb021SLiane Praza break;
27831f6eb021SLiane Praza case SC_VALUES:
27841f6eb021SLiane Praza (void) lxml_get_tm_values(service, pg, cursor);
27851f6eb021SLiane Praza break;
27861f6eb021SLiane Praza case SC_VISIBILITY:
27871f6eb021SLiane Praza /*
27881f6eb021SLiane Praza * The visibility element is empty, so we only need
27891f6eb021SLiane Praza * to proccess the value attribute.
27901f6eb021SLiane Praza */
27911f6eb021SLiane Praza (void) new_str_prop_from_attr(pg,
27921f6eb021SLiane Praza SCF_PROPERTY_TM_VISIBILITY, SCF_TYPE_ASTRING,
27931f6eb021SLiane Praza cursor, value_attr);
27941f6eb021SLiane Praza break;
27951f6eb021SLiane Praza default:
27961f6eb021SLiane Praza uu_die(gettext("illegal element \"%s\" in prop_pattern "
27971f6eb021SLiane Praza "for service \"%s\"\n"), cursor->name,
27981f6eb021SLiane Praza service->sc_name);
27991f6eb021SLiane Praza }
28001f6eb021SLiane Praza }
28011f6eb021SLiane Praza
28021f6eb021SLiane Praza out:
28031f6eb021SLiane Praza xmlFree(prop_pattern_name);
28041f6eb021SLiane Praza free(pg_name);
28051f6eb021SLiane Praza return (r);
28061f6eb021SLiane Praza }
28071f6eb021SLiane Praza
28081f6eb021SLiane Praza /*
28091f6eb021SLiane Praza * Get the pg_pattern attributes and save them as properties in the
28101f6eb021SLiane Praza * property group at pg. The pg_pattern element accepts four attributes --
28111f6eb021SLiane Praza * name, type, required and target.
28121f6eb021SLiane Praza */
28131f6eb021SLiane Praza static int
lxml_get_pg_pattern_attributes(pgroup_t * pg,xmlNodePtr cursor)28141f6eb021SLiane Praza lxml_get_pg_pattern_attributes(pgroup_t *pg, xmlNodePtr cursor)
28151f6eb021SLiane Praza {
28161f6eb021SLiane Praza if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_TM_NAME,
28171f6eb021SLiane Praza SCF_TYPE_ASTRING, cursor, name_attr, NULL) != 0) {
28181f6eb021SLiane Praza return (-1);
28191f6eb021SLiane Praza }
28201f6eb021SLiane Praza if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_TM_TYPE,
28211f6eb021SLiane Praza SCF_TYPE_ASTRING, cursor, type_attr, NULL) != 0) {
28221f6eb021SLiane Praza return (-1);
28231f6eb021SLiane Praza }
28241f6eb021SLiane Praza if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_TM_TARGET,
28251f6eb021SLiane Praza SCF_TYPE_ASTRING, cursor, target_attr, NULL) != 0) {
28261f6eb021SLiane Praza return (-1);
28271f6eb021SLiane Praza }
28281f6eb021SLiane Praza if (new_bool_prop_from_attr(pg, SCF_PROPERTY_TM_REQUIRED, cursor,
28291f6eb021SLiane Praza required_attr) != 0)
28301f6eb021SLiane Praza return (-1);
28311f6eb021SLiane Praza return (0);
28321f6eb021SLiane Praza }
28331f6eb021SLiane Praza
28341f6eb021SLiane Praza /*
28351f6eb021SLiane Praza * There are several restrictions on the pg_pattern attributes that cannot
28361f6eb021SLiane Praza * be specifed in the service bundle DTD. This function verifies that
28371f6eb021SLiane Praza * those restrictions have been satisfied. The restrictions are:
28381f6eb021SLiane Praza *
28391f6eb021SLiane Praza * - The target attribute may have a value of "instance" only when the
28401f6eb021SLiane Praza * template block is in a service declaration.
28411f6eb021SLiane Praza *
28421f6eb021SLiane Praza * - The target attribute may have a value of "delegate" only when the
28431f6eb021SLiane Praza * template block applies to a restarter.
28441f6eb021SLiane Praza *
28451f6eb021SLiane Praza * - The target attribute may have a value of "all" only when the
28461f6eb021SLiane Praza * template block applies to the master restarter.
28471f6eb021SLiane Praza *
28481f6eb021SLiane Praza * The function returns 0 on success and -1 on failure.
28491f6eb021SLiane Praza */
28501f6eb021SLiane Praza static int
verify_pg_pattern_attributes(entity_t * s,pgroup_t * pg)28511f6eb021SLiane Praza verify_pg_pattern_attributes(entity_t *s, pgroup_t *pg)
28521f6eb021SLiane Praza {
28531f6eb021SLiane Praza int is_restarter;
28541f6eb021SLiane Praza property_t *target;
28551f6eb021SLiane Praza value_t *v;
28561f6eb021SLiane Praza
28571f6eb021SLiane Praza /* Find the value of the target property. */
28581f6eb021SLiane Praza target = internal_property_find(pg, SCF_PROPERTY_TM_TARGET);
28591f6eb021SLiane Praza if (target == NULL) {
28601f6eb021SLiane Praza uu_die(gettext("pg_pattern is missing the %s attribute "
28611f6eb021SLiane Praza "in %s\n"), target_attr, s->sc_name);
28621f6eb021SLiane Praza return (-1);
28631f6eb021SLiane Praza }
28641f6eb021SLiane Praza v = uu_list_first(target->sc_property_values);
28651f6eb021SLiane Praza assert(v != NULL);
28661f6eb021SLiane Praza assert(v->sc_type == SCF_TYPE_ASTRING);
28671f6eb021SLiane Praza
28681f6eb021SLiane Praza /*
28691f6eb021SLiane Praza * If target has a value of instance, the template must be in a
28701f6eb021SLiane Praza * service object.
28711f6eb021SLiane Praza */
28721f6eb021SLiane Praza if (strcmp(v->sc_u.sc_string, "instance") == 0) {
28731f6eb021SLiane Praza if (s->sc_etype != SVCCFG_SERVICE_OBJECT) {
28741f6eb021SLiane Praza uu_warn(gettext("pg_pattern %s attribute may only "
28751f6eb021SLiane Praza "have a value of \"instance\" when it is in a "
28761f6eb021SLiane Praza "service declaration.\n"), target_attr);
28771f6eb021SLiane Praza return (-1);
28781f6eb021SLiane Praza }
28791f6eb021SLiane Praza }
28801f6eb021SLiane Praza
28811f6eb021SLiane Praza /*
28821f6eb021SLiane Praza * If target has a value of "delegate", the template must be in a
28831f6eb021SLiane Praza * restarter.
28841f6eb021SLiane Praza */
28851f6eb021SLiane Praza if (strcmp(v->sc_u.sc_string, "delegate") == 0) {
28861f6eb021SLiane Praza is_restarter = 0;
28871f6eb021SLiane Praza if ((s->sc_etype == SVCCFG_SERVICE_OBJECT) &&
28881f6eb021SLiane Praza (s->sc_u.sc_service.sc_service_type == SVCCFG_RESTARTER)) {
28891f6eb021SLiane Praza is_restarter = 1;
28901f6eb021SLiane Praza }
28911f6eb021SLiane Praza if ((s->sc_etype == SVCCFG_INSTANCE_OBJECT) &&
28921f6eb021SLiane Praza (s->sc_parent->sc_u.sc_service.sc_service_type ==
28931f6eb021SLiane Praza SVCCFG_RESTARTER)) {
28941f6eb021SLiane Praza is_restarter = 1;
28951f6eb021SLiane Praza }
28961f6eb021SLiane Praza if (is_restarter == 0) {
28971f6eb021SLiane Praza uu_warn(gettext("pg_pattern %s attribute has a "
28981f6eb021SLiane Praza "value of \"delegate\" but is not in a "
28991f6eb021SLiane Praza "restarter service\n"), target_attr);
29001f6eb021SLiane Praza return (-1);
29011f6eb021SLiane Praza }
29021f6eb021SLiane Praza }
29031f6eb021SLiane Praza
29041f6eb021SLiane Praza /*
29051f6eb021SLiane Praza * If target has a value of "all", the template must be in the
29061f6eb021SLiane Praza * global (SCF_SERVICE_GLOBAL) service.
29071f6eb021SLiane Praza */
29081f6eb021SLiane Praza if (strcmp(v->sc_u.sc_string, all_value) == 0) {
29091f6eb021SLiane Praza if (s->sc_etype != SVCCFG_SERVICE_OBJECT) {
29101f6eb021SLiane Praza uu_warn(gettext("pg_pattern %s attribute has a "
29111f6eb021SLiane Praza "value of \"%s\" but is not in a "
29121f6eb021SLiane Praza "service entity.\n"), target_attr, all_value);
29131f6eb021SLiane Praza return (-1);
29141f6eb021SLiane Praza }
29151f6eb021SLiane Praza if (strcmp(s->sc_fmri, SCF_SERVICE_GLOBAL) != 0) {
29161f6eb021SLiane Praza uu_warn(gettext("pg_pattern %s attribute has a "
29171f6eb021SLiane Praza "value of \"%s\" but is in the \"%s\" service. "
29181f6eb021SLiane Praza "pg_patterns with target \"%s\" are only allowed "
29191f6eb021SLiane Praza "in the global service.\n"),
29201f6eb021SLiane Praza target_attr, all_value, s->sc_fmri, all_value);
29211f6eb021SLiane Praza return (-1);
29221f6eb021SLiane Praza }
29231f6eb021SLiane Praza }
29241f6eb021SLiane Praza
29251f6eb021SLiane Praza return (0);
29261f6eb021SLiane Praza }
29271f6eb021SLiane Praza
29281f6eb021SLiane Praza static int
lxml_get_tm_pg_pattern(entity_t * service,xmlNodePtr pg_pattern)29291f6eb021SLiane Praza lxml_get_tm_pg_pattern(entity_t *service, xmlNodePtr pg_pattern)
29301f6eb021SLiane Praza {
29311f6eb021SLiane Praza xmlNodePtr cursor;
29321f6eb021SLiane Praza int out_len;
29331f6eb021SLiane Praza xmlChar *name;
29341f6eb021SLiane Praza pgroup_t *pg = NULL;
29351f6eb021SLiane Praza char *pg_name;
29361f6eb021SLiane Praza int r = -1;
29371f6eb021SLiane Praza xmlChar *type;
29381f6eb021SLiane Praza
29391f6eb021SLiane Praza pg_name = safe_malloc(max_scf_name_len + 1);
29401f6eb021SLiane Praza
29411f6eb021SLiane Praza /*
29421f6eb021SLiane Praza * Get the name and type attributes. Their presence or absence
29431f6eb021SLiane Praza * determines whcih prefix we will use for the property group name.
29441f6eb021SLiane Praza * There are four cases -- neither attribute is present, both are
29451f6eb021SLiane Praza * present, only name is present or only type is present.
29461f6eb021SLiane Praza */
29471f6eb021SLiane Praza name = xmlGetProp(pg_pattern, (xmlChar *)name_attr);
29481f6eb021SLiane Praza type = xmlGetProp(pg_pattern, (xmlChar *)type_attr);
29491f6eb021SLiane Praza if ((name == NULL) || (*name == 0)) {
29501f6eb021SLiane Praza if ((type == NULL) || (*type == 0)) {
29511f6eb021SLiane Praza /* PG name contains only the prefix in this case */
29521f6eb021SLiane Praza if (strlcpy(pg_name, SCF_PG_TM_PG_PATTERN_PREFIX,
29531f6eb021SLiane Praza max_scf_name_len + 1) >= max_scf_name_len + 1) {
29541f6eb021SLiane Praza uu_die(gettext("Unable to create pg_pattern "
29551f6eb021SLiane Praza "property for %s\n"), service->sc_name);
29561f6eb021SLiane Praza }
29571f6eb021SLiane Praza } else {
29581f6eb021SLiane Praza /*
29591f6eb021SLiane Praza * If we have a type and no name, the type becomes
29601f6eb021SLiane Praza * part of the pg_pattern property group name.
29611f6eb021SLiane Praza */
29621f6eb021SLiane Praza if ((out_len = snprintf(pg_name, max_scf_name_len + 1,
29631f6eb021SLiane Praza "%s%s", SCF_PG_TM_PG_PATTERN_T_PREFIX, type)) >=
29641f6eb021SLiane Praza max_scf_name_len + 1) {
29651f6eb021SLiane Praza uu_die(gettext("pg_pattern type is for %s is "
29661f6eb021SLiane Praza "%d bytes too long\n"), service->sc_name,
29671f6eb021SLiane Praza out_len - max_scf_name_len);
29681f6eb021SLiane Praza }
29691f6eb021SLiane Praza }
29701f6eb021SLiane Praza } else {
29711f6eb021SLiane Praza const char *prefix;
29721f6eb021SLiane Praza
29731f6eb021SLiane Praza /* Make sure that the name is valid. */
29741f6eb021SLiane Praza if (uu_check_name((const char *)name, UU_NAME_DOMAIN) != 0) {
29751f6eb021SLiane Praza semerr(gettext("pg_pattern name attribute, \"%s\", "
29761f6eb021SLiane Praza "for %s is invalid\n"), name, service->sc_name);
29771f6eb021SLiane Praza goto out;
29781f6eb021SLiane Praza }
29791f6eb021SLiane Praza
29801f6eb021SLiane Praza /*
29811f6eb021SLiane Praza * As long as the pg_pattern has a name, it becomes part of
29821f6eb021SLiane Praza * the name of the pg_pattern property group name. We
29831f6eb021SLiane Praza * merely need to pick the appropriate prefix.
29841f6eb021SLiane Praza */
29851f6eb021SLiane Praza if ((type == NULL) || (*type == 0)) {
29861f6eb021SLiane Praza prefix = SCF_PG_TM_PG_PATTERN_N_PREFIX;
29871f6eb021SLiane Praza } else {
29881f6eb021SLiane Praza prefix = SCF_PG_TM_PG_PATTERN_NT_PREFIX;
29891f6eb021SLiane Praza }
29901f6eb021SLiane Praza if ((out_len = snprintf(pg_name, max_scf_name_len + 1, "%s%s",
29911f6eb021SLiane Praza prefix, name)) >= max_scf_name_len + 1) {
29921f6eb021SLiane Praza uu_die(gettext("pg_pattern property group name "
29931f6eb021SLiane Praza "for %s is %d bytes too long\n"), service->sc_name,
29941f6eb021SLiane Praza out_len - max_scf_name_len);
29951f6eb021SLiane Praza }
29961f6eb021SLiane Praza }
29971f6eb021SLiane Praza
29981f6eb021SLiane Praza /*
29991f6eb021SLiane Praza * Create the property group for holding this pg_pattern
30001f6eb021SLiane Praza * information, and capture the pg_pattern attributes.
30011f6eb021SLiane Praza */
30021f6eb021SLiane Praza pg = internal_pgroup_create_strict(service, pg_name,
30031f6eb021SLiane Praza SCF_GROUP_TEMPLATE_PG_PATTERN);
30041f6eb021SLiane Praza if (pg == NULL) {
30051f6eb021SLiane Praza if ((name == NULL) || (*name == 0)) {
30061f6eb021SLiane Praza if ((type == NULL) ||(*type == 0)) {
30071f6eb021SLiane Praza semerr(gettext("pg_pattern with empty name and "
30081f6eb021SLiane Praza "type is not unique in %s\n"),
30091f6eb021SLiane Praza service->sc_name);
30101f6eb021SLiane Praza } else {
30111f6eb021SLiane Praza semerr(gettext("pg_pattern with empty name and "
30121f6eb021SLiane Praza "type \"%s\" is not unique in %s\n"),
30131f6eb021SLiane Praza type, service->sc_name);
30141f6eb021SLiane Praza }
30151f6eb021SLiane Praza } else {
30161f6eb021SLiane Praza if ((type == NULL) || (*type == 0)) {
30171f6eb021SLiane Praza semerr(gettext("pg_pattern with name \"%s\" "
30181f6eb021SLiane Praza "and empty type is not unique in %s\n"),
30191f6eb021SLiane Praza name, service->sc_name);
30201f6eb021SLiane Praza } else {
30211f6eb021SLiane Praza semerr(gettext("pg_pattern with name \"%s\" "
30221f6eb021SLiane Praza "and type \"%s\" is not unique in %s\n"),
30231f6eb021SLiane Praza name, type, service->sc_name);
30241f6eb021SLiane Praza }
30251f6eb021SLiane Praza }
30261f6eb021SLiane Praza goto out;
30271f6eb021SLiane Praza }
30281f6eb021SLiane Praza
30291f6eb021SLiane Praza /*
30301f6eb021SLiane Praza * Get the pg_pattern attributes from the manifest and verify
30311f6eb021SLiane Praza * that they satisfy our restrictions.
30321f6eb021SLiane Praza */
30331f6eb021SLiane Praza r = lxml_get_pg_pattern_attributes(pg, pg_pattern);
30341f6eb021SLiane Praza if (r != 0)
30351f6eb021SLiane Praza goto out;
30361f6eb021SLiane Praza if (verify_pg_pattern_attributes(service, pg) != 0) {
30371f6eb021SLiane Praza semerr(gettext("Invalid pg_pattern attributes in %s\n"),
30381f6eb021SLiane Praza service->sc_name);
30391f6eb021SLiane Praza r = -1;
30401f6eb021SLiane Praza goto out;
30411f6eb021SLiane Praza }
30421f6eb021SLiane Praza
30431f6eb021SLiane Praza /*
30441f6eb021SLiane Praza * Now process all of the elements of pg_pattern.
30451f6eb021SLiane Praza */
30461f6eb021SLiane Praza for (cursor = pg_pattern->xmlChildrenNode;
30471f6eb021SLiane Praza cursor != NULL;
30481f6eb021SLiane Praza cursor = cursor->next) {
30491f6eb021SLiane Praza if (lxml_ignorable_block(cursor))
30501f6eb021SLiane Praza continue;
30511f6eb021SLiane Praza
30521f6eb021SLiane Praza switch (lxml_xlate_element(cursor->name)) {
30531f6eb021SLiane Praza case SC_COMMON_NAME:
30541f6eb021SLiane Praza (void) lxml_get_all_loctext(service, pg, cursor,
30551f6eb021SLiane Praza COMMON_NAME_FMT, (const char *)cursor->name);
30561f6eb021SLiane Praza break;
30571f6eb021SLiane Praza case SC_DESCRIPTION:
30581f6eb021SLiane Praza (void) lxml_get_all_loctext(service, pg, cursor,
30591f6eb021SLiane Praza DESCRIPTION_FMT, (const char *)cursor->name);
30601f6eb021SLiane Praza break;
30611f6eb021SLiane Praza case SC_PROP_PATTERN:
30621f6eb021SLiane Praza r = lxml_get_tm_prop_pattern(service, cursor,
30631f6eb021SLiane Praza pg_name);
30641f6eb021SLiane Praza if (r != 0)
30651f6eb021SLiane Praza goto out;
30661f6eb021SLiane Praza break;
30671f6eb021SLiane Praza default:
30681f6eb021SLiane Praza uu_die(gettext("illegal element \"%s\" in pg_pattern "
30691f6eb021SLiane Praza "for service \"%s\"\n"), cursor->name,
30701f6eb021SLiane Praza service->sc_name);
30711f6eb021SLiane Praza }
30721f6eb021SLiane Praza }
30731f6eb021SLiane Praza
30741f6eb021SLiane Praza out:
30751f6eb021SLiane Praza if ((r != 0) && (pg != NULL)) {
30761f6eb021SLiane Praza internal_detach_pgroup(service, pg);
30771f6eb021SLiane Praza internal_pgroup_free(pg);
30781f6eb021SLiane Praza }
30791f6eb021SLiane Praza free(pg_name);
30801f6eb021SLiane Praza xmlFree(name);
30811f6eb021SLiane Praza xmlFree(type);
30821f6eb021SLiane Praza
30831f6eb021SLiane Praza return (r);
30841f6eb021SLiane Praza }
30851f6eb021SLiane Praza
30861f6eb021SLiane Praza static int
lxml_get_template(entity_t * service,xmlNodePtr templ)30877c478bd9Sstevel@tonic-gate lxml_get_template(entity_t *service, xmlNodePtr templ)
30887c478bd9Sstevel@tonic-gate {
30897c478bd9Sstevel@tonic-gate xmlNodePtr cursor;
30907c478bd9Sstevel@tonic-gate
30917c478bd9Sstevel@tonic-gate for (cursor = templ->xmlChildrenNode; cursor != NULL;
30927c478bd9Sstevel@tonic-gate cursor = cursor->next) {
30937c478bd9Sstevel@tonic-gate if (lxml_ignorable_block(cursor))
30947c478bd9Sstevel@tonic-gate continue;
30957c478bd9Sstevel@tonic-gate
30967c478bd9Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) {
30977c478bd9Sstevel@tonic-gate case SC_COMMON_NAME:
30987c478bd9Sstevel@tonic-gate (void) lxml_get_tm_common_name(service, cursor);
30997c478bd9Sstevel@tonic-gate break;
31007c478bd9Sstevel@tonic-gate case SC_DESCRIPTION:
31017c478bd9Sstevel@tonic-gate (void) lxml_get_tm_description(service, cursor);
31027c478bd9Sstevel@tonic-gate break;
31037c478bd9Sstevel@tonic-gate case SC_DOCUMENTATION:
31047c478bd9Sstevel@tonic-gate (void) lxml_get_tm_documentation(service, cursor);
31057c478bd9Sstevel@tonic-gate break;
31061f6eb021SLiane Praza case SC_PG_PATTERN:
31071f6eb021SLiane Praza if (lxml_get_tm_pg_pattern(service, cursor) != 0)
31081f6eb021SLiane Praza return (-1);
31091f6eb021SLiane Praza break;
31107c478bd9Sstevel@tonic-gate default:
31117c478bd9Sstevel@tonic-gate uu_die(gettext("illegal element \"%s\" on template "
31127c478bd9Sstevel@tonic-gate "for service \"%s\"\n"),
31137c478bd9Sstevel@tonic-gate cursor->name, service->sc_name);
31147c478bd9Sstevel@tonic-gate }
31157c478bd9Sstevel@tonic-gate }
31167c478bd9Sstevel@tonic-gate
31177c478bd9Sstevel@tonic-gate return (0);
31187c478bd9Sstevel@tonic-gate }
31197c478bd9Sstevel@tonic-gate
31207c478bd9Sstevel@tonic-gate static int
lxml_get_default_instance(entity_t * service,xmlNodePtr definst)31217c478bd9Sstevel@tonic-gate lxml_get_default_instance(entity_t *service, xmlNodePtr definst)
31227c478bd9Sstevel@tonic-gate {
31237c478bd9Sstevel@tonic-gate entity_t *i;
31247c478bd9Sstevel@tonic-gate xmlChar *enabled;
31257c478bd9Sstevel@tonic-gate pgroup_t *pg;
31267c478bd9Sstevel@tonic-gate property_t *p;
31277c478bd9Sstevel@tonic-gate char *package;
31287c478bd9Sstevel@tonic-gate uint64_t enabled_val = 0;
31297c478bd9Sstevel@tonic-gate
31307c478bd9Sstevel@tonic-gate i = internal_instance_new("default");
31317c478bd9Sstevel@tonic-gate
31327c478bd9Sstevel@tonic-gate if ((enabled = xmlGetProp(definst, (xmlChar *)enabled_attr)) != NULL) {
31337c478bd9Sstevel@tonic-gate enabled_val = (strcmp(true, (const char *)enabled) == 0) ?
31347c478bd9Sstevel@tonic-gate 1 : 0;
31357c478bd9Sstevel@tonic-gate xmlFree(enabled);
31367c478bd9Sstevel@tonic-gate }
31377c478bd9Sstevel@tonic-gate
31387c478bd9Sstevel@tonic-gate /*
31397c478bd9Sstevel@tonic-gate * New general property group with enabled boolean property set.
31407c478bd9Sstevel@tonic-gate */
31417c478bd9Sstevel@tonic-gate
3142f329b923SSean Wilcox i->sc_op = service->sc_op;
31437c478bd9Sstevel@tonic-gate pg = internal_pgroup_new();
31447c478bd9Sstevel@tonic-gate (void) internal_attach_pgroup(i, pg);
31457c478bd9Sstevel@tonic-gate
31467c478bd9Sstevel@tonic-gate pg->sc_pgroup_name = (char *)scf_pg_general;
31477c478bd9Sstevel@tonic-gate pg->sc_pgroup_type = (char *)scf_group_framework;
31487c478bd9Sstevel@tonic-gate pg->sc_pgroup_flags = 0;
31497c478bd9Sstevel@tonic-gate
31507c478bd9Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_ENABLED, SCF_TYPE_BOOLEAN, 1,
31517c478bd9Sstevel@tonic-gate enabled_val);
31527c478bd9Sstevel@tonic-gate
31537c478bd9Sstevel@tonic-gate (void) internal_attach_property(pg, p);
31547c478bd9Sstevel@tonic-gate
31557c478bd9Sstevel@tonic-gate /*
31567c478bd9Sstevel@tonic-gate * Add general/package property if PKGINST is set.
31577c478bd9Sstevel@tonic-gate */
31587c478bd9Sstevel@tonic-gate if ((package = getenv("PKGINST")) != NULL) {
31597c478bd9Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_PACKAGE,
31607c478bd9Sstevel@tonic-gate SCF_TYPE_ASTRING, 1, package);
31617c478bd9Sstevel@tonic-gate
31627c478bd9Sstevel@tonic-gate (void) internal_attach_property(pg, p);
31637c478bd9Sstevel@tonic-gate }
31647c478bd9Sstevel@tonic-gate
31657c478bd9Sstevel@tonic-gate return (internal_attach_entity(service, i));
31667c478bd9Sstevel@tonic-gate }
31677c478bd9Sstevel@tonic-gate
31687c478bd9Sstevel@tonic-gate /*
31697c478bd9Sstevel@tonic-gate * Translate an instance element into an internal property tree, added to
3170687293e1SAntonello Cruz * service. If op is SVCCFG_OP_APPLY (i.e., apply a profile), set the
3171687293e1SAntonello Cruz * enabled property to override.
3172f329b923SSean Wilcox *
3173f329b923SSean Wilcox * If op is SVCCFG_OP_APPLY (i.e., apply a profile), do not allow for
3174f329b923SSean Wilcox * modification of template data.
31757c478bd9Sstevel@tonic-gate */
31767c478bd9Sstevel@tonic-gate static int
lxml_get_instance(entity_t * service,xmlNodePtr inst,bundle_type_t bt,svccfg_op_t op)3177687293e1SAntonello Cruz lxml_get_instance(entity_t *service, xmlNodePtr inst, bundle_type_t bt,
3178687293e1SAntonello Cruz svccfg_op_t op)
31797c478bd9Sstevel@tonic-gate {
31807c478bd9Sstevel@tonic-gate entity_t *i;
31817c478bd9Sstevel@tonic-gate pgroup_t *pg;
31827c478bd9Sstevel@tonic-gate property_t *p;
31837c478bd9Sstevel@tonic-gate xmlNodePtr cursor;
31847c478bd9Sstevel@tonic-gate xmlChar *enabled;
3185687293e1SAntonello Cruz int r, e_val;
31867c478bd9Sstevel@tonic-gate
31877c478bd9Sstevel@tonic-gate /*
31887c478bd9Sstevel@tonic-gate * Fetch its attributes, as appropriate.
31897c478bd9Sstevel@tonic-gate */
31907c478bd9Sstevel@tonic-gate i = internal_instance_new((char *)xmlGetProp(inst,
31917c478bd9Sstevel@tonic-gate (xmlChar *)name_attr));
31927c478bd9Sstevel@tonic-gate
31937c478bd9Sstevel@tonic-gate /*
31947c478bd9Sstevel@tonic-gate * Note that this must be done before walking the children so that
31957c478bd9Sstevel@tonic-gate * sc_fmri is set in case we enter lxml_get_dependent().
31967c478bd9Sstevel@tonic-gate */
31977c478bd9Sstevel@tonic-gate r = internal_attach_entity(service, i);
31987c478bd9Sstevel@tonic-gate if (r != 0)
31997c478bd9Sstevel@tonic-gate return (r);
32007c478bd9Sstevel@tonic-gate
3201f329b923SSean Wilcox i->sc_op = op;
32027c478bd9Sstevel@tonic-gate enabled = xmlGetProp(inst, (xmlChar *)enabled_attr);
32037c478bd9Sstevel@tonic-gate
3204687293e1SAntonello Cruz if (enabled == NULL) {
3205687293e1SAntonello Cruz if (bt == SVCCFG_MANIFEST) {
3206687293e1SAntonello Cruz semerr(gettext("Instance \"%s\" missing attribute "
3207687293e1SAntonello Cruz "\"%s\".\n"), i->sc_name, enabled_attr);
3208687293e1SAntonello Cruz return (-1);
3209687293e1SAntonello Cruz }
3210687293e1SAntonello Cruz } else { /* enabled != NULL */
3211687293e1SAntonello Cruz if (strcmp(true, (const char *)enabled) != 0 &&
3212687293e1SAntonello Cruz strcmp(false, (const char *)enabled) != 0) {
3213687293e1SAntonello Cruz xmlFree(enabled);
3214687293e1SAntonello Cruz semerr(gettext("Invalid enabled value\n"));
3215687293e1SAntonello Cruz return (-1);
3216687293e1SAntonello Cruz }
32177c478bd9Sstevel@tonic-gate pg = internal_pgroup_new();
32187c478bd9Sstevel@tonic-gate (void) internal_attach_pgroup(i, pg);
32197c478bd9Sstevel@tonic-gate
32207c478bd9Sstevel@tonic-gate pg->sc_pgroup_name = (char *)scf_pg_general;
32217c478bd9Sstevel@tonic-gate pg->sc_pgroup_type = (char *)scf_group_framework;
32227c478bd9Sstevel@tonic-gate pg->sc_pgroup_flags = 0;
32237c478bd9Sstevel@tonic-gate
3224687293e1SAntonello Cruz e_val = (strcmp(true, (const char *)enabled) == 0);
3225687293e1SAntonello Cruz p = internal_property_create(SCF_PROPERTY_ENABLED,
3226687293e1SAntonello Cruz SCF_TYPE_BOOLEAN, 1, (uint64_t)e_val);
32277c478bd9Sstevel@tonic-gate
32283eae19d9Swesolows p->sc_property_override = (op == SVCCFG_OP_APPLY);
32297c478bd9Sstevel@tonic-gate
32307c478bd9Sstevel@tonic-gate (void) internal_attach_property(pg, p);
32317c478bd9Sstevel@tonic-gate
32327c478bd9Sstevel@tonic-gate xmlFree(enabled);
3233687293e1SAntonello Cruz }
32347c478bd9Sstevel@tonic-gate
32357c478bd9Sstevel@tonic-gate /*
32367c478bd9Sstevel@tonic-gate * Walk its child elements, as appropriate.
32377c478bd9Sstevel@tonic-gate */
32387c478bd9Sstevel@tonic-gate for (cursor = inst->xmlChildrenNode; cursor != NULL;
32397c478bd9Sstevel@tonic-gate cursor = cursor->next) {
32407c478bd9Sstevel@tonic-gate if (lxml_ignorable_block(cursor))
32417c478bd9Sstevel@tonic-gate continue;
32427c478bd9Sstevel@tonic-gate
32437c478bd9Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) {
32447c478bd9Sstevel@tonic-gate case SC_RESTARTER:
32457c478bd9Sstevel@tonic-gate (void) lxml_get_restarter(i, cursor);
32467c478bd9Sstevel@tonic-gate break;
32477c478bd9Sstevel@tonic-gate case SC_DEPENDENCY:
32487c478bd9Sstevel@tonic-gate (void) lxml_get_dependency(i, cursor);
32497c478bd9Sstevel@tonic-gate break;
32507c478bd9Sstevel@tonic-gate case SC_DEPENDENT:
32517c478bd9Sstevel@tonic-gate (void) lxml_get_dependent(i, cursor);
32527c478bd9Sstevel@tonic-gate break;
32537c478bd9Sstevel@tonic-gate case SC_METHOD_CONTEXT:
32547c478bd9Sstevel@tonic-gate (void) lxml_get_entity_method_context(i, cursor);
32557c478bd9Sstevel@tonic-gate break;
32567c478bd9Sstevel@tonic-gate case SC_EXEC_METHOD:
32577c478bd9Sstevel@tonic-gate (void) lxml_get_exec_method(i, cursor);
32587c478bd9Sstevel@tonic-gate break;
32597c478bd9Sstevel@tonic-gate case SC_PROPERTY_GROUP:
32607c478bd9Sstevel@tonic-gate (void) lxml_get_pgroup(i, cursor);
32617c478bd9Sstevel@tonic-gate break;
32627c478bd9Sstevel@tonic-gate case SC_TEMPLATE:
3263f329b923SSean Wilcox if (op == SVCCFG_OP_APPLY) {
3264f329b923SSean Wilcox semerr(gettext("Template data for \"%s\" may "
3265f329b923SSean Wilcox "not be modified in a profile.\n"),
3266f329b923SSean Wilcox i->sc_name);
3267f329b923SSean Wilcox
3268f329b923SSean Wilcox return (-1);
3269f329b923SSean Wilcox }
3270f329b923SSean Wilcox
32711f6eb021SLiane Praza if (lxml_get_template(i, cursor) != 0)
32721f6eb021SLiane Praza return (-1);
32737c478bd9Sstevel@tonic-gate break;
3274*f6e214c7SGavin Maltby case SC_NOTIFICATION_PARAMETERS:
3275*f6e214c7SGavin Maltby if (lxml_get_notification_parameters(i, cursor) != 0)
3276*f6e214c7SGavin Maltby return (-1);
3277*f6e214c7SGavin Maltby break;
32787c478bd9Sstevel@tonic-gate default:
32797c478bd9Sstevel@tonic-gate uu_die(gettext(
32807c478bd9Sstevel@tonic-gate "illegal element \"%s\" on instance \"%s\"\n"),
32817c478bd9Sstevel@tonic-gate cursor->name, i->sc_name);
32827c478bd9Sstevel@tonic-gate break;
32837c478bd9Sstevel@tonic-gate }
32847c478bd9Sstevel@tonic-gate }
32857c478bd9Sstevel@tonic-gate
32867c478bd9Sstevel@tonic-gate return (0);
32877c478bd9Sstevel@tonic-gate }
32887c478bd9Sstevel@tonic-gate
32897c478bd9Sstevel@tonic-gate /* ARGSUSED1 */
32907c478bd9Sstevel@tonic-gate static int
lxml_get_single_instance(entity_t * entity,xmlNodePtr si)32917c478bd9Sstevel@tonic-gate lxml_get_single_instance(entity_t *entity, xmlNodePtr si)
32927c478bd9Sstevel@tonic-gate {
32937c478bd9Sstevel@tonic-gate pgroup_t *pg;
32947c478bd9Sstevel@tonic-gate property_t *p;
32957c478bd9Sstevel@tonic-gate int r;
32967c478bd9Sstevel@tonic-gate
32977c478bd9Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, (char *)scf_pg_general,
32987c478bd9Sstevel@tonic-gate (char *)scf_group_framework);
32997c478bd9Sstevel@tonic-gate
33007c478bd9Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_SINGLE_INSTANCE,
33017c478bd9Sstevel@tonic-gate SCF_TYPE_BOOLEAN, 1, (uint64_t)1);
33027c478bd9Sstevel@tonic-gate
33037c478bd9Sstevel@tonic-gate r = internal_attach_property(pg, p);
33047c478bd9Sstevel@tonic-gate if (r != 0) {
33057c478bd9Sstevel@tonic-gate internal_property_free(p);
33067c478bd9Sstevel@tonic-gate return (-1);
33077c478bd9Sstevel@tonic-gate }
33087c478bd9Sstevel@tonic-gate
33097c478bd9Sstevel@tonic-gate return (0);
33107c478bd9Sstevel@tonic-gate }
33117c478bd9Sstevel@tonic-gate
33127c478bd9Sstevel@tonic-gate /*
33139444c26fSTom Whitten * Check to see if the service should allow the upgrade
33149444c26fSTom Whitten * process to handle adding of the manifestfiles linkage.
33159444c26fSTom Whitten *
33169444c26fSTom Whitten * If the service exists and does not have a manifestfiles
33179444c26fSTom Whitten * property group then the upgrade process should handle
33189444c26fSTom Whitten * the service.
33199444c26fSTom Whitten *
33209444c26fSTom Whitten * If the service doesn't exist or the service exists
33219444c26fSTom Whitten * and has a manifestfiles property group then the import
33229444c26fSTom Whitten * process can handle the manifestfiles property group
33239444c26fSTom Whitten * work.
33249444c26fSTom Whitten *
33259444c26fSTom Whitten * This prevents potential cleanup of unaccounted for instances
33269444c26fSTom Whitten * in early manifest import due to upgrade process needing
33279444c26fSTom Whitten * information that has not yet been supplied by manifests
33289444c26fSTom Whitten * that are still located in the /var/svc manifests directory.
33299444c26fSTom Whitten */
33309444c26fSTom Whitten static int
lxml_check_upgrade(const char * service)33319444c26fSTom Whitten lxml_check_upgrade(const char *service) {
33329444c26fSTom Whitten scf_handle_t *h = NULL;
33339444c26fSTom Whitten scf_scope_t *sc = NULL;
33349444c26fSTom Whitten scf_service_t *svc = NULL;
33359444c26fSTom Whitten scf_propertygroup_t *pg = NULL;
33369444c26fSTom Whitten int rc = SCF_FAILED;
33379444c26fSTom Whitten
33389444c26fSTom Whitten if ((h = scf_handle_create(SCF_VERSION)) == NULL ||
33399444c26fSTom Whitten (sc = scf_scope_create(h)) == NULL ||
33409444c26fSTom Whitten (svc = scf_service_create(h)) == NULL ||
33419444c26fSTom Whitten (pg = scf_pg_create(h)) == NULL)
33429444c26fSTom Whitten goto out;
33439444c26fSTom Whitten
33449444c26fSTom Whitten if (scf_handle_bind(h) != 0)
33459444c26fSTom Whitten goto out;
33469444c26fSTom Whitten
33479444c26fSTom Whitten if (scf_handle_get_scope(h, SCF_FMRI_LOCAL_SCOPE, sc) == -1)
33489444c26fSTom Whitten goto out;
33499444c26fSTom Whitten
33509444c26fSTom Whitten if (scf_scope_get_service(sc, service, svc) != SCF_SUCCESS) {
33519444c26fSTom Whitten if (scf_error() == SCF_ERROR_NOT_FOUND)
33529444c26fSTom Whitten rc = SCF_SUCCESS;
33539444c26fSTom Whitten
33549444c26fSTom Whitten goto out;
33559444c26fSTom Whitten }
33569444c26fSTom Whitten
33579444c26fSTom Whitten if (scf_service_get_pg(svc, SCF_PG_MANIFESTFILES, pg) != SCF_SUCCESS)
33589444c26fSTom Whitten goto out;
33599444c26fSTom Whitten
33609444c26fSTom Whitten rc = SCF_SUCCESS;
33619444c26fSTom Whitten out:
33629444c26fSTom Whitten scf_pg_destroy(pg);
33639444c26fSTom Whitten scf_service_destroy(svc);
33649444c26fSTom Whitten scf_scope_destroy(sc);
33659444c26fSTom Whitten scf_handle_destroy(h);
33669444c26fSTom Whitten
33679444c26fSTom Whitten return (rc);
33689444c26fSTom Whitten }
33699444c26fSTom Whitten
33709444c26fSTom Whitten /*
33717c478bd9Sstevel@tonic-gate * Translate a service element into an internal instance/property tree, added
3372f329b923SSean Wilcox * to bundle.
3373f329b923SSean Wilcox *
3374f329b923SSean Wilcox * If op is SVCCFG_OP_APPLY (i.e., apply a profile), do not allow for
3375f329b923SSean Wilcox * modification of template data.
33767c478bd9Sstevel@tonic-gate */
33777c478bd9Sstevel@tonic-gate static int
lxml_get_service(bundle_t * bundle,xmlNodePtr svc,svccfg_op_t op)33783eae19d9Swesolows lxml_get_service(bundle_t *bundle, xmlNodePtr svc, svccfg_op_t op)
33797c478bd9Sstevel@tonic-gate {
338023294c7dSSean Wilcox pgroup_t *pg;
338123294c7dSSean Wilcox property_t *p;
33827c478bd9Sstevel@tonic-gate entity_t *s;
33837c478bd9Sstevel@tonic-gate xmlNodePtr cursor;
33847c478bd9Sstevel@tonic-gate xmlChar *type;
33857c478bd9Sstevel@tonic-gate xmlChar *version;
33867c478bd9Sstevel@tonic-gate int e;
33877c478bd9Sstevel@tonic-gate
33887c478bd9Sstevel@tonic-gate /*
33897c478bd9Sstevel@tonic-gate * Fetch attributes, as appropriate.
33907c478bd9Sstevel@tonic-gate */
33917c478bd9Sstevel@tonic-gate s = internal_service_new((char *)xmlGetProp(svc,
33927c478bd9Sstevel@tonic-gate (xmlChar *)name_attr));
33937c478bd9Sstevel@tonic-gate
33941f6eb021SLiane Praza version = xmlGetProp(svc, (xmlChar *)version_attr);
33957c478bd9Sstevel@tonic-gate s->sc_u.sc_service.sc_service_version = atol((const char *)version);
33967c478bd9Sstevel@tonic-gate xmlFree(version);
33977c478bd9Sstevel@tonic-gate
33987c478bd9Sstevel@tonic-gate type = xmlGetProp(svc, (xmlChar *)type_attr);
33997c478bd9Sstevel@tonic-gate s->sc_u.sc_service.sc_service_type = lxml_xlate_service_type(type);
34007c478bd9Sstevel@tonic-gate xmlFree(type);
34017c478bd9Sstevel@tonic-gate
34027c478bd9Sstevel@tonic-gate /*
3403f329b923SSean Wilcox * Set the global missing type to false before processing the service
3404f329b923SSean Wilcox */
3405f329b923SSean Wilcox est->sc_miss_type = B_FALSE;
3406f329b923SSean Wilcox s->sc_op = op;
3407f329b923SSean Wilcox
3408f329b923SSean Wilcox /*
340923294c7dSSean Wilcox * Now that the service is created create the manifest
341023294c7dSSean Wilcox * property group and add the property value of the service.
341123294c7dSSean Wilcox */
34129444c26fSTom Whitten if (lxml_check_upgrade(s->sc_name) == SCF_SUCCESS &&
34139444c26fSTom Whitten svc->doc->name != NULL &&
341423294c7dSSean Wilcox bundle->sc_bundle_type == SVCCFG_MANIFEST) {
341585bcc4e5SSean Wilcox char *buf, *base, *fname, *bname;
341685bcc4e5SSean Wilcox size_t base_sz = 0;
341785bcc4e5SSean Wilcox
341885bcc4e5SSean Wilcox /*
341985bcc4e5SSean Wilcox * Must remove the PKG_INSTALL_ROOT, point to the correct
342085bcc4e5SSean Wilcox * directory after install
342185bcc4e5SSean Wilcox */
342285bcc4e5SSean Wilcox bname = uu_zalloc(PATH_MAX + 1);
342385bcc4e5SSean Wilcox if (realpath(svc->doc->name, bname) == NULL) {
342485bcc4e5SSean Wilcox uu_die(gettext("Unable to create the real path of the "
342585bcc4e5SSean Wilcox "manifest file \"%s\" : %d\n"), svc->doc->name,
342685bcc4e5SSean Wilcox errno);
342785bcc4e5SSean Wilcox }
342885bcc4e5SSean Wilcox
342985bcc4e5SSean Wilcox base = getenv("PKG_INSTALL_ROOT");
343085bcc4e5SSean Wilcox if (base != NULL && strncmp(bname, base, strlen(base)) == 0) {
343185bcc4e5SSean Wilcox base_sz = strlen(base);
343285bcc4e5SSean Wilcox }
343385bcc4e5SSean Wilcox fname = safe_strdup(bname + base_sz);
343485bcc4e5SSean Wilcox
343585bcc4e5SSean Wilcox uu_free(bname);
343685bcc4e5SSean Wilcox buf = mhash_filename_to_propname(svc->doc->name, B_FALSE);
343723294c7dSSean Wilcox
343823294c7dSSean Wilcox pg = internal_pgroup_create_strict(s, SCF_PG_MANIFESTFILES,
343923294c7dSSean Wilcox SCF_GROUP_FRAMEWORK);
344023294c7dSSean Wilcox
344123294c7dSSean Wilcox if (pg == NULL) {
344223294c7dSSean Wilcox uu_die(gettext("Property group for prop_pattern, "
344323294c7dSSean Wilcox "\"%s\", already exists in %s\n"),
344423294c7dSSean Wilcox SCF_PG_MANIFESTFILES, s->sc_name);
344523294c7dSSean Wilcox }
344623294c7dSSean Wilcox
344723294c7dSSean Wilcox p = internal_property_create(buf, SCF_TYPE_ASTRING, 1, fname);
344823294c7dSSean Wilcox
344923294c7dSSean Wilcox (void) internal_attach_property(pg, p);
345023294c7dSSean Wilcox }
345123294c7dSSean Wilcox
345223294c7dSSean Wilcox /*
34537c478bd9Sstevel@tonic-gate * Walk its child elements, as appropriate.
34547c478bd9Sstevel@tonic-gate */
34557c478bd9Sstevel@tonic-gate for (cursor = svc->xmlChildrenNode; cursor != NULL;
34567c478bd9Sstevel@tonic-gate cursor = cursor->next) {
34577c478bd9Sstevel@tonic-gate if (lxml_ignorable_block(cursor))
34587c478bd9Sstevel@tonic-gate continue;
34597c478bd9Sstevel@tonic-gate
34607c478bd9Sstevel@tonic-gate e = lxml_xlate_element(cursor->name);
34617c478bd9Sstevel@tonic-gate
34627c478bd9Sstevel@tonic-gate switch (e) {
34637c478bd9Sstevel@tonic-gate case SC_INSTANCE:
3464687293e1SAntonello Cruz if (lxml_get_instance(s, cursor,
3465687293e1SAntonello Cruz bundle->sc_bundle_type, op) != 0)
34661f6eb021SLiane Praza return (-1);
34677c478bd9Sstevel@tonic-gate break;
34687c478bd9Sstevel@tonic-gate case SC_TEMPLATE:
3469f329b923SSean Wilcox if (op == SVCCFG_OP_APPLY) {
3470f329b923SSean Wilcox semerr(gettext("Template data for \"%s\" may "
3471f329b923SSean Wilcox "not be modified in a profile.\n"),
3472f329b923SSean Wilcox s->sc_name);
3473f329b923SSean Wilcox
3474f329b923SSean Wilcox return (-1);
3475f329b923SSean Wilcox }
3476f329b923SSean Wilcox
34771f6eb021SLiane Praza if (lxml_get_template(s, cursor) != 0)
34781f6eb021SLiane Praza return (-1);
34797c478bd9Sstevel@tonic-gate break;
3480*f6e214c7SGavin Maltby case SC_NOTIFICATION_PARAMETERS:
3481*f6e214c7SGavin Maltby if (lxml_get_notification_parameters(s, cursor) != 0)
3482*f6e214c7SGavin Maltby return (-1);
3483*f6e214c7SGavin Maltby break;
34847c478bd9Sstevel@tonic-gate case SC_STABILITY:
34857c478bd9Sstevel@tonic-gate (void) lxml_get_entity_stability(s, cursor);
34867c478bd9Sstevel@tonic-gate break;
34877c478bd9Sstevel@tonic-gate case SC_DEPENDENCY:
34887c478bd9Sstevel@tonic-gate (void) lxml_get_dependency(s, cursor);
34897c478bd9Sstevel@tonic-gate break;
34907c478bd9Sstevel@tonic-gate case SC_DEPENDENT:
34917c478bd9Sstevel@tonic-gate (void) lxml_get_dependent(s, cursor);
34927c478bd9Sstevel@tonic-gate break;
34937c478bd9Sstevel@tonic-gate case SC_RESTARTER:
34947c478bd9Sstevel@tonic-gate (void) lxml_get_restarter(s, cursor);
34957c478bd9Sstevel@tonic-gate break;
34967c478bd9Sstevel@tonic-gate case SC_EXEC_METHOD:
34977c478bd9Sstevel@tonic-gate (void) lxml_get_exec_method(s, cursor);
34987c478bd9Sstevel@tonic-gate break;
34997c478bd9Sstevel@tonic-gate case SC_METHOD_CONTEXT:
35007c478bd9Sstevel@tonic-gate (void) lxml_get_entity_method_context(s, cursor);
35017c478bd9Sstevel@tonic-gate break;
35027c478bd9Sstevel@tonic-gate case SC_PROPERTY_GROUP:
35037c478bd9Sstevel@tonic-gate (void) lxml_get_pgroup(s, cursor);
35047c478bd9Sstevel@tonic-gate break;
35057c478bd9Sstevel@tonic-gate case SC_INSTANCE_CREATE_DEFAULT:
35067c478bd9Sstevel@tonic-gate (void) lxml_get_default_instance(s, cursor);
35077c478bd9Sstevel@tonic-gate break;
35087c478bd9Sstevel@tonic-gate case SC_INSTANCE_SINGLE:
35097c478bd9Sstevel@tonic-gate (void) lxml_get_single_instance(s, cursor);
35107c478bd9Sstevel@tonic-gate break;
35117c478bd9Sstevel@tonic-gate default:
35127c478bd9Sstevel@tonic-gate uu_die(gettext(
35137c478bd9Sstevel@tonic-gate "illegal element \"%s\" on service \"%s\"\n"),
35147c478bd9Sstevel@tonic-gate cursor->name, s->sc_name);
35157c478bd9Sstevel@tonic-gate break;
35167c478bd9Sstevel@tonic-gate }
35177c478bd9Sstevel@tonic-gate }
35187c478bd9Sstevel@tonic-gate
3519f329b923SSean Wilcox /*
3520f329b923SSean Wilcox * Now that the service has been processed set the missing type
3521f329b923SSean Wilcox * for the service. So that only the services with missing
3522f329b923SSean Wilcox * types are processed.
3523f329b923SSean Wilcox */
3524f329b923SSean Wilcox s->sc_miss_type = est->sc_miss_type;
3525f329b923SSean Wilcox if (est->sc_miss_type)
3526f329b923SSean Wilcox est->sc_miss_type = B_FALSE;
3527f329b923SSean Wilcox
35287c478bd9Sstevel@tonic-gate return (internal_attach_service(bundle, s));
35297c478bd9Sstevel@tonic-gate }
35307c478bd9Sstevel@tonic-gate
35317c478bd9Sstevel@tonic-gate #ifdef DEBUG
35327c478bd9Sstevel@tonic-gate void
lxml_dump(int g,xmlNodePtr p)35337c478bd9Sstevel@tonic-gate lxml_dump(int g, xmlNodePtr p)
35347c478bd9Sstevel@tonic-gate {
35357c478bd9Sstevel@tonic-gate if (p && p->name) {
3536f329b923SSean Wilcox (void) printf("%d %s\n", g, p->name);
35377c478bd9Sstevel@tonic-gate
35387c478bd9Sstevel@tonic-gate for (p = p->xmlChildrenNode; p != NULL; p = p->next)
35397c478bd9Sstevel@tonic-gate lxml_dump(g + 1, p);
35407c478bd9Sstevel@tonic-gate }
35417c478bd9Sstevel@tonic-gate }
35427c478bd9Sstevel@tonic-gate #endif /* DEBUG */
35437c478bd9Sstevel@tonic-gate
35447c478bd9Sstevel@tonic-gate static int
lxml_is_known_dtd(const xmlChar * dtdname)35457c478bd9Sstevel@tonic-gate lxml_is_known_dtd(const xmlChar *dtdname)
35467c478bd9Sstevel@tonic-gate {
35477c478bd9Sstevel@tonic-gate if (dtdname == NULL ||
35487c478bd9Sstevel@tonic-gate strcmp(MANIFEST_DTD_PATH, (const char *)dtdname) != 0)
35497c478bd9Sstevel@tonic-gate return (0);
35507c478bd9Sstevel@tonic-gate
35517c478bd9Sstevel@tonic-gate return (1);
35527c478bd9Sstevel@tonic-gate }
35537c478bd9Sstevel@tonic-gate
35547c478bd9Sstevel@tonic-gate static int
lxml_get_bundle(bundle_t * bundle,bundle_type_t bundle_type,xmlNodePtr subbundle,svccfg_op_t op)35557c478bd9Sstevel@tonic-gate lxml_get_bundle(bundle_t *bundle, bundle_type_t bundle_type,
35563eae19d9Swesolows xmlNodePtr subbundle, svccfg_op_t op)
35577c478bd9Sstevel@tonic-gate {
35587c478bd9Sstevel@tonic-gate xmlNodePtr cursor;
35597c478bd9Sstevel@tonic-gate xmlChar *type;
35607c478bd9Sstevel@tonic-gate int e;
35617c478bd9Sstevel@tonic-gate
35627c478bd9Sstevel@tonic-gate /*
35637c478bd9Sstevel@tonic-gate * 1. Get bundle attributes.
35647c478bd9Sstevel@tonic-gate */
35651f6eb021SLiane Praza type = xmlGetProp(subbundle, (xmlChar *)type_attr);
35667c478bd9Sstevel@tonic-gate bundle->sc_bundle_type = lxml_xlate_bundle_type(type);
35677c478bd9Sstevel@tonic-gate if (bundle->sc_bundle_type != bundle_type &&
35687c478bd9Sstevel@tonic-gate bundle_type != SVCCFG_UNKNOWN_BUNDLE) {
35697c478bd9Sstevel@tonic-gate semerr(gettext("included bundle of different type.\n"));
35707c478bd9Sstevel@tonic-gate return (-1);
35717c478bd9Sstevel@tonic-gate }
35727c478bd9Sstevel@tonic-gate
35737c478bd9Sstevel@tonic-gate xmlFree(type);
35747c478bd9Sstevel@tonic-gate
35753eae19d9Swesolows switch (op) {
35763eae19d9Swesolows case SVCCFG_OP_IMPORT:
35777c478bd9Sstevel@tonic-gate if (bundle->sc_bundle_type != SVCCFG_MANIFEST) {
35787c478bd9Sstevel@tonic-gate semerr(gettext("document is not a manifest.\n"));
35797c478bd9Sstevel@tonic-gate return (-1);
35807c478bd9Sstevel@tonic-gate }
35813eae19d9Swesolows break;
35823eae19d9Swesolows case SVCCFG_OP_APPLY:
35837c478bd9Sstevel@tonic-gate if (bundle->sc_bundle_type != SVCCFG_PROFILE) {
35847c478bd9Sstevel@tonic-gate semerr(gettext("document is not a profile.\n"));
35857c478bd9Sstevel@tonic-gate return (-1);
35867c478bd9Sstevel@tonic-gate }
35873eae19d9Swesolows break;
35883eae19d9Swesolows case SVCCFG_OP_RESTORE:
35893eae19d9Swesolows if (bundle->sc_bundle_type != SVCCFG_ARCHIVE) {
35903eae19d9Swesolows semerr(gettext("document is not an archive.\n"));
35913eae19d9Swesolows return (-1);
35923eae19d9Swesolows }
35933eae19d9Swesolows break;
35947c478bd9Sstevel@tonic-gate }
35957c478bd9Sstevel@tonic-gate
35961f6eb021SLiane Praza if (((bundle->sc_bundle_name = xmlGetProp(subbundle,
35971f6eb021SLiane Praza (xmlChar *)name_attr)) == NULL) || (*bundle->sc_bundle_name == 0)) {
35987c478bd9Sstevel@tonic-gate semerr(gettext("service bundle lacks name attribute\n"));
35997c478bd9Sstevel@tonic-gate return (-1);
36007c478bd9Sstevel@tonic-gate }
36017c478bd9Sstevel@tonic-gate
36027c478bd9Sstevel@tonic-gate /*
36037c478bd9Sstevel@tonic-gate * 2. Get services, descend into each one and build state.
36047c478bd9Sstevel@tonic-gate */
36057c478bd9Sstevel@tonic-gate for (cursor = subbundle->xmlChildrenNode; cursor != NULL;
36067c478bd9Sstevel@tonic-gate cursor = cursor->next) {
36077c478bd9Sstevel@tonic-gate if (lxml_ignorable_block(cursor))
36087c478bd9Sstevel@tonic-gate continue;
36097c478bd9Sstevel@tonic-gate
36107c478bd9Sstevel@tonic-gate e = lxml_xlate_element(cursor->name);
36117c478bd9Sstevel@tonic-gate
36127c478bd9Sstevel@tonic-gate switch (e) {
36137c478bd9Sstevel@tonic-gate case SC_XI_INCLUDE:
36147c478bd9Sstevel@tonic-gate continue;
36157c478bd9Sstevel@tonic-gate
36167c478bd9Sstevel@tonic-gate case SC_SERVICE_BUNDLE:
36173eae19d9Swesolows if (lxml_get_bundle(bundle, bundle_type, cursor, op))
36187c478bd9Sstevel@tonic-gate return (-1);
36197c478bd9Sstevel@tonic-gate break;
36207c478bd9Sstevel@tonic-gate case SC_SERVICE:
36211f6eb021SLiane Praza if (lxml_get_service(bundle, cursor, op) != 0)
36221f6eb021SLiane Praza return (-1);
36237c478bd9Sstevel@tonic-gate break;
36247c478bd9Sstevel@tonic-gate }
36257c478bd9Sstevel@tonic-gate }
36267c478bd9Sstevel@tonic-gate
36277c478bd9Sstevel@tonic-gate return (0);
36287c478bd9Sstevel@tonic-gate }
36297c478bd9Sstevel@tonic-gate
36307c478bd9Sstevel@tonic-gate /*
36317c478bd9Sstevel@tonic-gate * Load an XML tree from filename and translate it into an internal service
36323eae19d9Swesolows * tree bundle. Require that the bundle be of appropriate type for the
36333eae19d9Swesolows * operation: archive for RESTORE, manifest for IMPORT, profile for APPLY.
36347c478bd9Sstevel@tonic-gate */
36357c478bd9Sstevel@tonic-gate int
lxml_get_bundle_file(bundle_t * bundle,const char * filename,svccfg_op_t op)36363eae19d9Swesolows lxml_get_bundle_file(bundle_t *bundle, const char *filename, svccfg_op_t op)
36377c478bd9Sstevel@tonic-gate {
36387c478bd9Sstevel@tonic-gate xmlDocPtr document;
36397c478bd9Sstevel@tonic-gate xmlNodePtr cursor;
36407c478bd9Sstevel@tonic-gate xmlDtdPtr dtd = NULL;
36417c478bd9Sstevel@tonic-gate xmlValidCtxtPtr vcp;
36427c478bd9Sstevel@tonic-gate boolean_t do_validate;
36437c478bd9Sstevel@tonic-gate char *dtdpath = NULL;
36447c478bd9Sstevel@tonic-gate int r;
36457c478bd9Sstevel@tonic-gate
36467c478bd9Sstevel@tonic-gate /*
364776cf44abSjeanm * Verify we can read the file before we try to parse it.
364876cf44abSjeanm */
364976cf44abSjeanm if (access(filename, R_OK | F_OK) == -1) {
365076cf44abSjeanm semerr(gettext("unable to open file: %s\n"), strerror(errno));
365176cf44abSjeanm return (-1);
365276cf44abSjeanm }
365376cf44abSjeanm
365476cf44abSjeanm /*
36557c478bd9Sstevel@tonic-gate * Until libxml2 addresses DTD-based validation with XInclude, we don't
36567c478bd9Sstevel@tonic-gate * validate service profiles (i.e. the apply path).
36577c478bd9Sstevel@tonic-gate */
36583eae19d9Swesolows do_validate = (op != SVCCFG_OP_APPLY) &&
36593eae19d9Swesolows (getenv("SVCCFG_NOVALIDATE") == NULL);
36607c478bd9Sstevel@tonic-gate if (do_validate)
36617c478bd9Sstevel@tonic-gate dtdpath = getenv("SVCCFG_DTD");
36627c478bd9Sstevel@tonic-gate
36637c478bd9Sstevel@tonic-gate if (dtdpath != NULL)
36647c478bd9Sstevel@tonic-gate xmlLoadExtDtdDefaultValue = 0;
36657c478bd9Sstevel@tonic-gate
366676cf44abSjeanm if ((document = xmlReadFile(filename, NULL, 0)) == NULL) {
36677c478bd9Sstevel@tonic-gate semerr(gettext("couldn't parse document\n"));
36687c478bd9Sstevel@tonic-gate return (-1);
36697c478bd9Sstevel@tonic-gate }
36707c478bd9Sstevel@tonic-gate
367123294c7dSSean Wilcox document->name = strdup(filename);
367223294c7dSSean Wilcox
36737c478bd9Sstevel@tonic-gate /*
36747c478bd9Sstevel@tonic-gate * Verify that this is a document type we understand.
36757c478bd9Sstevel@tonic-gate */
36767c478bd9Sstevel@tonic-gate if ((dtd = xmlGetIntSubset(document)) == NULL) {
36777c478bd9Sstevel@tonic-gate semerr(gettext("document has no DTD\n"));
36787c478bd9Sstevel@tonic-gate return (-1);
3679f329b923SSean Wilcox } else if (dtdpath == NULL && !do_validate) {
3680f329b923SSean Wilcox /*
3681f329b923SSean Wilcox * If apply then setup so that some validation
3682f329b923SSean Wilcox * for specific elements can be done.
3683f329b923SSean Wilcox */
3684f329b923SSean Wilcox dtdpath = (char *)document->intSubset->SystemID;
36857c478bd9Sstevel@tonic-gate }
36867c478bd9Sstevel@tonic-gate
36877c478bd9Sstevel@tonic-gate if (!lxml_is_known_dtd(dtd->SystemID)) {
36887c478bd9Sstevel@tonic-gate semerr(gettext("document DTD unknown; not service bundle?\n"));
36897c478bd9Sstevel@tonic-gate return (-1);
36907c478bd9Sstevel@tonic-gate }
36917c478bd9Sstevel@tonic-gate
36927c478bd9Sstevel@tonic-gate if ((cursor = xmlDocGetRootElement(document)) == NULL) {
36937c478bd9Sstevel@tonic-gate semerr(gettext("document is empty\n"));
36947c478bd9Sstevel@tonic-gate xmlFreeDoc(document);
36957c478bd9Sstevel@tonic-gate return (-1);
36967c478bd9Sstevel@tonic-gate }
36977c478bd9Sstevel@tonic-gate
36987c478bd9Sstevel@tonic-gate if (xmlStrcmp(cursor->name, (const xmlChar *)"service_bundle") != 0) {
36997c478bd9Sstevel@tonic-gate semerr(gettext("document is not a service bundle\n"));
37007c478bd9Sstevel@tonic-gate xmlFreeDoc(document);
37017c478bd9Sstevel@tonic-gate return (-1);
37027c478bd9Sstevel@tonic-gate }
37037c478bd9Sstevel@tonic-gate
37047c478bd9Sstevel@tonic-gate
37057c478bd9Sstevel@tonic-gate if (dtdpath != NULL) {
37067c478bd9Sstevel@tonic-gate dtd = xmlParseDTD(NULL, (xmlChar *)dtdpath);
37077c478bd9Sstevel@tonic-gate if (dtd == NULL) {
37087c478bd9Sstevel@tonic-gate semerr(gettext("Could not parse DTD \"%s\".\n"),
37097c478bd9Sstevel@tonic-gate dtdpath);
37107c478bd9Sstevel@tonic-gate return (-1);
37117c478bd9Sstevel@tonic-gate }
37127c478bd9Sstevel@tonic-gate
37137c478bd9Sstevel@tonic-gate if (document->extSubset != NULL)
37147c478bd9Sstevel@tonic-gate xmlFreeDtd(document->extSubset);
37157c478bd9Sstevel@tonic-gate
37167c478bd9Sstevel@tonic-gate document->extSubset = dtd;
37177c478bd9Sstevel@tonic-gate }
37187c478bd9Sstevel@tonic-gate
371976cf44abSjeanm if (xmlXIncludeProcessFlags(document, XML_PARSE_XINCLUDE) == -1) {
37207c478bd9Sstevel@tonic-gate semerr(gettext("couldn't handle XInclude statements "
37217c478bd9Sstevel@tonic-gate "in document\n"));
37227c478bd9Sstevel@tonic-gate return (-1);
37237c478bd9Sstevel@tonic-gate }
37247c478bd9Sstevel@tonic-gate
37257c478bd9Sstevel@tonic-gate if (do_validate) {
37267c478bd9Sstevel@tonic-gate vcp = xmlNewValidCtxt();
37277c478bd9Sstevel@tonic-gate if (vcp == NULL)
37287c478bd9Sstevel@tonic-gate uu_die(gettext("could not allocate memory"));
37297c478bd9Sstevel@tonic-gate vcp->warning = xmlParserValidityWarning;
37307c478bd9Sstevel@tonic-gate vcp->error = xmlParserValidityError;
37317c478bd9Sstevel@tonic-gate
37327c478bd9Sstevel@tonic-gate r = xmlValidateDocument(vcp, document);
37337c478bd9Sstevel@tonic-gate
37347c478bd9Sstevel@tonic-gate xmlFreeValidCtxt(vcp);
37357c478bd9Sstevel@tonic-gate
37367c478bd9Sstevel@tonic-gate if (r == 0) {
37377c478bd9Sstevel@tonic-gate semerr(gettext("Document is not valid.\n"));
37387c478bd9Sstevel@tonic-gate xmlFreeDoc(document);
37397c478bd9Sstevel@tonic-gate return (-1);
37407c478bd9Sstevel@tonic-gate }
37417c478bd9Sstevel@tonic-gate }
37427c478bd9Sstevel@tonic-gate
37437c478bd9Sstevel@tonic-gate #ifdef DEBUG
37447c478bd9Sstevel@tonic-gate lxml_dump(0, cursor);
37457c478bd9Sstevel@tonic-gate #endif /* DEBUG */
37467c478bd9Sstevel@tonic-gate
37473eae19d9Swesolows r = lxml_get_bundle(bundle, SVCCFG_UNKNOWN_BUNDLE, cursor, op);
37487c478bd9Sstevel@tonic-gate
37497c478bd9Sstevel@tonic-gate xmlFreeDoc(document);
37507c478bd9Sstevel@tonic-gate
37517c478bd9Sstevel@tonic-gate return (r);
37527c478bd9Sstevel@tonic-gate }
37537c478bd9Sstevel@tonic-gate
37547c478bd9Sstevel@tonic-gate int
lxml_inventory(const char * filename)37557c478bd9Sstevel@tonic-gate lxml_inventory(const char *filename)
37567c478bd9Sstevel@tonic-gate {
37577c478bd9Sstevel@tonic-gate bundle_t *b;
37587c478bd9Sstevel@tonic-gate uu_list_walk_t *svcs, *insts;
37597c478bd9Sstevel@tonic-gate entity_t *svc, *inst;
37607c478bd9Sstevel@tonic-gate
37617c478bd9Sstevel@tonic-gate b = internal_bundle_new();
37627c478bd9Sstevel@tonic-gate
37633eae19d9Swesolows if (lxml_get_bundle_file(b, filename, SVCCFG_OP_IMPORT) != 0) {
37647c478bd9Sstevel@tonic-gate internal_bundle_free(b);
37657c478bd9Sstevel@tonic-gate return (-1);
37667c478bd9Sstevel@tonic-gate }
37677c478bd9Sstevel@tonic-gate
37687c478bd9Sstevel@tonic-gate svcs = uu_list_walk_start(b->sc_bundle_services, 0);
37697c478bd9Sstevel@tonic-gate if (svcs == NULL)
37707c478bd9Sstevel@tonic-gate uu_die(gettext("Couldn't walk services"));
37717c478bd9Sstevel@tonic-gate
37727c478bd9Sstevel@tonic-gate while ((svc = uu_list_walk_next(svcs)) != NULL) {
37737c478bd9Sstevel@tonic-gate uu_list_t *inst_list;
37747c478bd9Sstevel@tonic-gate
37757c478bd9Sstevel@tonic-gate inst_list = svc->sc_u.sc_service.sc_service_instances;
37767c478bd9Sstevel@tonic-gate insts = uu_list_walk_start(inst_list, 0);
37777c478bd9Sstevel@tonic-gate if (insts == NULL)
37787c478bd9Sstevel@tonic-gate uu_die(gettext("Couldn't walk instances"));
37797c478bd9Sstevel@tonic-gate
37807c478bd9Sstevel@tonic-gate while ((inst = uu_list_walk_next(insts)) != NULL)
37817c478bd9Sstevel@tonic-gate (void) printf("svc:/%s:%s\n", svc->sc_name,
37827c478bd9Sstevel@tonic-gate inst->sc_name);
37837c478bd9Sstevel@tonic-gate
37847c478bd9Sstevel@tonic-gate uu_list_walk_end(insts);
37857c478bd9Sstevel@tonic-gate }
37867c478bd9Sstevel@tonic-gate
37877c478bd9Sstevel@tonic-gate uu_list_walk_end(svcs);
37887c478bd9Sstevel@tonic-gate
37897c478bd9Sstevel@tonic-gate svcs = uu_list_walk_start(b->sc_bundle_services, 0);
37907c478bd9Sstevel@tonic-gate while ((svc = uu_list_walk_next(svcs)) != NULL) {
37917c478bd9Sstevel@tonic-gate (void) fputs("svc:/", stdout);
37927c478bd9Sstevel@tonic-gate (void) puts(svc->sc_name);
37937c478bd9Sstevel@tonic-gate }
37947c478bd9Sstevel@tonic-gate uu_list_walk_end(svcs);
37957c478bd9Sstevel@tonic-gate
37967c478bd9Sstevel@tonic-gate internal_bundle_free(b);
37977c478bd9Sstevel@tonic-gate
37987c478bd9Sstevel@tonic-gate return (0);
37997c478bd9Sstevel@tonic-gate }
3800