10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 54740Sjeanm * Common Development and Distribution License (the "License"). 64740Sjeanm * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*12172SSean.Wilcox@Sun.COM * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate */ 240Sstevel@tonic-gate 257887SLiane.Praza@Sun.COM /* 267887SLiane.Praza@Sun.COM * XML document manipulation routines 277887SLiane.Praza@Sun.COM * 287887SLiane.Praza@Sun.COM * These routines provide translation to and from the internal representation to 297887SLiane.Praza@Sun.COM * XML. Directionally-oriented verbs are with respect to the external source, 307887SLiane.Praza@Sun.COM * so lxml_get_service() fetches a service from the XML file into the 317887SLiane.Praza@Sun.COM * internal representation. 327887SLiane.Praza@Sun.COM */ 330Sstevel@tonic-gate 340Sstevel@tonic-gate #include <libxml/parser.h> 350Sstevel@tonic-gate #include <libxml/xinclude.h> 360Sstevel@tonic-gate 370Sstevel@tonic-gate #include <assert.h> 380Sstevel@tonic-gate #include <ctype.h> 390Sstevel@tonic-gate #include <errno.h> 400Sstevel@tonic-gate #include <libintl.h> 417887SLiane.Praza@Sun.COM #include <libscf.h> 427887SLiane.Praza@Sun.COM #include <libscf_priv.h> 430Sstevel@tonic-gate #include <libuutil.h> 447887SLiane.Praza@Sun.COM #include <sasl/saslutil.h> 450Sstevel@tonic-gate #include <stdlib.h> 460Sstevel@tonic-gate #include <string.h> 47*12172SSean.Wilcox@Sun.COM #include <limits.h> 480Sstevel@tonic-gate 494740Sjeanm #include <sys/types.h> 504740Sjeanm #include <sys/stat.h> 514740Sjeanm #include <unistd.h> 524740Sjeanm 5310461SSean.Wilcox@Sun.COM #include <sys/param.h> 5410461SSean.Wilcox@Sun.COM #include "manifest_hash.h" 5510461SSean.Wilcox@Sun.COM 560Sstevel@tonic-gate #include "svccfg.h" 570Sstevel@tonic-gate 580Sstevel@tonic-gate /* 597887SLiane.Praza@Sun.COM * snprintf(3C) format strings for constructing property names that include 607887SLiane.Praza@Sun.COM * the locale designation. Use %s to indicate where the locale should go. 610Sstevel@tonic-gate * 627887SLiane.Praza@Sun.COM * The VALUE_* symbols are an exception. The firs %s will be replaced with 637887SLiane.Praza@Sun.COM * "value_". The second %s will be replaced by the name of the value and 647887SLiane.Praza@Sun.COM * %%s will be replaced by the locale designation. These formats are 657887SLiane.Praza@Sun.COM * processed twice by snprintf(3C). The first time captures the value name 667887SLiane.Praza@Sun.COM * and the second time captures the locale. 670Sstevel@tonic-gate */ 687887SLiane.Praza@Sun.COM #define LOCALE_ONLY_FMT ("%s") 697887SLiane.Praza@Sun.COM #define COMMON_NAME_FMT ("common_name_%s") 707887SLiane.Praza@Sun.COM #define DESCRIPTION_FMT ("description_%s") 717887SLiane.Praza@Sun.COM #define UNITS_FMT ("units_%s") 727887SLiane.Praza@Sun.COM #define VALUE_COMMON_NAME_FMT ("%s%s_common_name_%%s") 737887SLiane.Praza@Sun.COM #define VALUE_DESCRIPTION_FMT ("%s%s_description_%%s") 747887SLiane.Praza@Sun.COM 757887SLiane.Praza@Sun.COM /* Attribute names */ 760Sstevel@tonic-gate const char * const delete_attr = "delete"; 770Sstevel@tonic-gate const char * const enabled_attr = "enabled"; 787887SLiane.Praza@Sun.COM const char * const lang_attr = "lang"; 797887SLiane.Praza@Sun.COM const char * const manpath_attr = "manpath"; 807887SLiane.Praza@Sun.COM const char * const max_attr = "max"; 817887SLiane.Praza@Sun.COM const char * const min_attr = "min"; 820Sstevel@tonic-gate const char * const name_attr = "name"; 830Sstevel@tonic-gate const char * const override_attr = "override"; 847887SLiane.Praza@Sun.COM const char * const required_attr = "required"; 857887SLiane.Praza@Sun.COM const char * const section_attr = "section"; 867887SLiane.Praza@Sun.COM const char * const set_attr = "set"; 877887SLiane.Praza@Sun.COM const char * const target_attr = "target"; 887887SLiane.Praza@Sun.COM const char * const timeout_seconds_attr = "timeout_seconds"; 897887SLiane.Praza@Sun.COM const char * const title_attr = "title"; 900Sstevel@tonic-gate const char * const type_attr = "type"; 917887SLiane.Praza@Sun.COM const char * const uri_attr = "uri"; 920Sstevel@tonic-gate const char * const value_attr = "value"; 937887SLiane.Praza@Sun.COM const char * const version_attr = "version"; 947887SLiane.Praza@Sun.COM const char * const xml_lang_attr = "xml:lang"; 957887SLiane.Praza@Sun.COM 967887SLiane.Praza@Sun.COM /* Attribute values */ 977887SLiane.Praza@Sun.COM const char * const all_value = "all"; 987887SLiane.Praza@Sun.COM 990Sstevel@tonic-gate const char * const true = "true"; 1000Sstevel@tonic-gate const char * const false = "false"; 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate /* 1030Sstevel@tonic-gate * The following list must be kept in the same order as that of 1040Sstevel@tonic-gate * element_t array 1050Sstevel@tonic-gate */ 1060Sstevel@tonic-gate static const char *lxml_elements[] = { 1070Sstevel@tonic-gate "astring_list", /* SC_ASTRING */ 1080Sstevel@tonic-gate "boolean_list", /* SC_BOOLEAN */ 1097887SLiane.Praza@Sun.COM "cardinality", /* SC_CARDINALITY */ 1107887SLiane.Praza@Sun.COM "choices", /* SC_CHOICES */ 1110Sstevel@tonic-gate "common_name", /* SC_COMMON_NAME */ 1127887SLiane.Praza@Sun.COM "constraints", /* SC_CONSTRAINTS */ 1130Sstevel@tonic-gate "count_list", /* SC_COUNT */ 1140Sstevel@tonic-gate "create_default_instance", /* SC_INSTANCE_CREATE_DEFAULT */ 1150Sstevel@tonic-gate "dependency", /* SC_DEPENDENCY */ 1160Sstevel@tonic-gate "dependent", /* SC_DEPENDENT */ 1170Sstevel@tonic-gate "description", /* SC_DESCRIPTION */ 1180Sstevel@tonic-gate "doc_link", /* SC_DOC_LINK */ 1190Sstevel@tonic-gate "documentation", /* SC_DOCUMENTATION */ 1200Sstevel@tonic-gate "enabled", /* SC_ENABLED */ 1210Sstevel@tonic-gate "exec_method", /* SC_EXEC_METHOD */ 1220Sstevel@tonic-gate "fmri_list", /* SC_FMRI */ 1230Sstevel@tonic-gate "host_list", /* SC_HOST */ 1240Sstevel@tonic-gate "hostname_list", /* SC_HOSTNAME */ 1257887SLiane.Praza@Sun.COM "include_values", /* SC_INCLUDE_VALUES */ 1260Sstevel@tonic-gate "instance", /* SC_INSTANCE */ 1270Sstevel@tonic-gate "integer_list", /* SC_INTEGER */ 1287887SLiane.Praza@Sun.COM "internal_separators", /* SC_INTERNAL_SEPARATORS */ 1290Sstevel@tonic-gate "loctext", /* SC_LOCTEXT */ 1300Sstevel@tonic-gate "manpage", /* SC_MANPAGE */ 1310Sstevel@tonic-gate "method_context", /* SC_METHOD_CONTEXT */ 1320Sstevel@tonic-gate "method_credential", /* SC_METHOD_CREDENTIAL */ 1330Sstevel@tonic-gate "method_profile", /* SC_METHOD_PROFILE */ 1340Sstevel@tonic-gate "method_environment", /* SC_METHOD_ENVIRONMENT */ 1350Sstevel@tonic-gate "envvar", /* SC_METHOD_ENVVAR */ 1360Sstevel@tonic-gate "net_address_v4_list", /* SC_NET_ADDR_V4 */ 1370Sstevel@tonic-gate "net_address_v6_list", /* SC_NET_ADDR_V6 */ 1380Sstevel@tonic-gate "opaque_list", /* SC_OPAQUE */ 1397887SLiane.Praza@Sun.COM "pg_pattern", /* SC_PG_PATTERN */ 1407887SLiane.Praza@Sun.COM "prop_pattern", /* SC_PROP_PATTERN */ 1410Sstevel@tonic-gate "property", /* SC_PROPERTY */ 1420Sstevel@tonic-gate "property_group", /* SC_PROPERTY_GROUP */ 1430Sstevel@tonic-gate "propval", /* SC_PROPVAL */ 1447887SLiane.Praza@Sun.COM "range", /* SC_RANGE */ 1450Sstevel@tonic-gate "restarter", /* SC_RESTARTER */ 1460Sstevel@tonic-gate "service", /* SC_SERVICE */ 1470Sstevel@tonic-gate "service_bundle", /* SC_SERVICE_BUNDLE */ 1480Sstevel@tonic-gate "service_fmri", /* SC_SERVICE_FMRI */ 1490Sstevel@tonic-gate "single_instance", /* SC_INSTANCE_SINGLE */ 1500Sstevel@tonic-gate "stability", /* SC_STABILITY */ 1510Sstevel@tonic-gate "template", /* SC_TEMPLATE */ 1520Sstevel@tonic-gate "time_list", /* SC_TIME */ 1537887SLiane.Praza@Sun.COM "units", /* SC_UNITS */ 1540Sstevel@tonic-gate "uri_list", /* SC_URI */ 1550Sstevel@tonic-gate "ustring_list", /* SC_USTRING */ 1567887SLiane.Praza@Sun.COM "value", /* SC_VALUE */ 1570Sstevel@tonic-gate "value_node", /* SC_VALUE_NODE */ 1587887SLiane.Praza@Sun.COM "values", /* SC_VALUES */ 1597887SLiane.Praza@Sun.COM "visibility", /* SC_VISIBILITY */ 1600Sstevel@tonic-gate "xi:fallback", /* SC_XI_FALLBACK */ 1610Sstevel@tonic-gate "xi:include" /* SC_XI_INCLUDE */ 1620Sstevel@tonic-gate }; 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate /* 1650Sstevel@tonic-gate * The following list must be kept in the same order as that of 1660Sstevel@tonic-gate * element_t array 1670Sstevel@tonic-gate */ 1680Sstevel@tonic-gate static const char *lxml_prop_types[] = { 1690Sstevel@tonic-gate "astring", /* SC_ASTRING */ 1700Sstevel@tonic-gate "boolean", /* SC_BOOLEAN */ 1717887SLiane.Praza@Sun.COM "", /* SC_CARDINALITY */ 1727887SLiane.Praza@Sun.COM "", /* SC_CHOICES */ 1730Sstevel@tonic-gate "", /* SC_COMMON_NAME */ 1747887SLiane.Praza@Sun.COM "", /* SC_CONSTRAINTS */ 1750Sstevel@tonic-gate "count", /* SC_COUNT */ 1760Sstevel@tonic-gate "", /* SC_INSTANCE_CREATE_DEFAULT */ 1770Sstevel@tonic-gate "", /* SC_DEPENDENCY */ 1780Sstevel@tonic-gate "", /* SC_DEPENDENT */ 1790Sstevel@tonic-gate "", /* SC_DESCRIPTION */ 1800Sstevel@tonic-gate "", /* SC_DOC_LINK */ 1810Sstevel@tonic-gate "", /* SC_DOCUMENTATION */ 1820Sstevel@tonic-gate "", /* SC_ENABLED */ 1830Sstevel@tonic-gate "", /* SC_EXEC_METHOD */ 1840Sstevel@tonic-gate "fmri", /* SC_FMRI */ 1850Sstevel@tonic-gate "host", /* SC_HOST */ 1860Sstevel@tonic-gate "hostname", /* SC_HOSTNAME */ 1877887SLiane.Praza@Sun.COM "", /* SC_INCLUDE_VALUES */ 1880Sstevel@tonic-gate "", /* SC_INSTANCE */ 1890Sstevel@tonic-gate "integer", /* SC_INTEGER */ 1907887SLiane.Praza@Sun.COM "", /* SC_INTERNAL_SEPARATORS */ 1910Sstevel@tonic-gate "", /* SC_LOCTEXT */ 1920Sstevel@tonic-gate "", /* SC_MANPAGE */ 1930Sstevel@tonic-gate "", /* SC_METHOD_CONTEXT */ 1940Sstevel@tonic-gate "", /* SC_METHOD_CREDENTIAL */ 1950Sstevel@tonic-gate "", /* SC_METHOD_PROFILE */ 1960Sstevel@tonic-gate "", /* SC_METHOD_ENVIRONMENT */ 1970Sstevel@tonic-gate "", /* SC_METHOD_ENVVAR */ 1980Sstevel@tonic-gate "net_address_v4", /* SC_NET_ADDR_V4 */ 1990Sstevel@tonic-gate "net_address_v6", /* SC_NET_ADDR_V6 */ 2000Sstevel@tonic-gate "opaque", /* SC_OPAQUE */ 2017887SLiane.Praza@Sun.COM "", /* SC_PG_PATTERN */ 2027887SLiane.Praza@Sun.COM "", /* SC_PROP_PATTERN */ 2030Sstevel@tonic-gate "", /* SC_PROPERTY */ 2040Sstevel@tonic-gate "", /* SC_PROPERTY_GROUP */ 2050Sstevel@tonic-gate "", /* SC_PROPVAL */ 2067887SLiane.Praza@Sun.COM "", /* SC_RANGE */ 2070Sstevel@tonic-gate "", /* SC_RESTARTER */ 2080Sstevel@tonic-gate "", /* SC_SERVICE */ 2090Sstevel@tonic-gate "", /* SC_SERVICE_BUNDLE */ 2100Sstevel@tonic-gate "", /* SC_SERVICE_FMRI */ 2110Sstevel@tonic-gate "", /* SC_INSTANCE_SINGLE */ 2120Sstevel@tonic-gate "", /* SC_STABILITY */ 2130Sstevel@tonic-gate "", /* SC_TEMPLATE */ 2140Sstevel@tonic-gate "time", /* SC_TIME */ 2157887SLiane.Praza@Sun.COM "", /* SC_UNITS */ 2160Sstevel@tonic-gate "uri", /* SC_URI */ 2170Sstevel@tonic-gate "ustring", /* SC_USTRING */ 2187887SLiane.Praza@Sun.COM "", /* SC_VALUE */ 2197887SLiane.Praza@Sun.COM "", /* SC_VALUE_NODE */ 2207887SLiane.Praza@Sun.COM "", /* SC_VALUES */ 2217887SLiane.Praza@Sun.COM "", /* SC_VISIBILITY */ 2227887SLiane.Praza@Sun.COM "", /* SC_XI_FALLBACK */ 2230Sstevel@tonic-gate "" /* SC_XI_INCLUDE */ 2240Sstevel@tonic-gate }; 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate int 2270Sstevel@tonic-gate lxml_init() 2280Sstevel@tonic-gate { 2290Sstevel@tonic-gate if (getenv("SVCCFG_NOVALIDATE") == NULL) { 2300Sstevel@tonic-gate /* 2310Sstevel@tonic-gate * DTD validation, with line numbers. 2320Sstevel@tonic-gate */ 23311053SSurya.Prakki@Sun.COM (void) xmlLineNumbersDefault(1); 2340Sstevel@tonic-gate xmlLoadExtDtdDefaultValue |= XML_DETECT_IDS; 2350Sstevel@tonic-gate xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS; 2360Sstevel@tonic-gate } 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate return (0); 2390Sstevel@tonic-gate } 2400Sstevel@tonic-gate 2410Sstevel@tonic-gate static bundle_type_t 2420Sstevel@tonic-gate lxml_xlate_bundle_type(xmlChar *type) 2430Sstevel@tonic-gate { 2440Sstevel@tonic-gate if (xmlStrcmp(type, (const xmlChar *)"manifest") == 0) 2450Sstevel@tonic-gate return (SVCCFG_MANIFEST); 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate if (xmlStrcmp(type, (const xmlChar *)"profile") == 0) 2480Sstevel@tonic-gate return (SVCCFG_PROFILE); 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate if (xmlStrcmp(type, (const xmlChar *)"archive") == 0) 2510Sstevel@tonic-gate return (SVCCFG_ARCHIVE); 2520Sstevel@tonic-gate 2530Sstevel@tonic-gate return (SVCCFG_UNKNOWN_BUNDLE); 2540Sstevel@tonic-gate } 2550Sstevel@tonic-gate 2560Sstevel@tonic-gate static service_type_t 2570Sstevel@tonic-gate lxml_xlate_service_type(xmlChar *type) 2580Sstevel@tonic-gate { 2590Sstevel@tonic-gate if (xmlStrcmp(type, (const xmlChar *)"service") == 0) 2600Sstevel@tonic-gate return (SVCCFG_SERVICE); 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate if (xmlStrcmp(type, (const xmlChar *)"restarter") == 0) 2630Sstevel@tonic-gate return (SVCCFG_RESTARTER); 2640Sstevel@tonic-gate 2650Sstevel@tonic-gate if (xmlStrcmp(type, (const xmlChar *)"milestone") == 0) 2660Sstevel@tonic-gate return (SVCCFG_MILESTONE); 2670Sstevel@tonic-gate 2680Sstevel@tonic-gate return (SVCCFG_UNKNOWN_SERVICE); 2690Sstevel@tonic-gate } 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate static element_t 2720Sstevel@tonic-gate lxml_xlate_element(const xmlChar *tag) 2730Sstevel@tonic-gate { 2740Sstevel@tonic-gate int i; 2750Sstevel@tonic-gate 2760Sstevel@tonic-gate for (i = 0; i < sizeof (lxml_elements) / sizeof (char *); i++) 2770Sstevel@tonic-gate if (xmlStrcmp(tag, (const xmlChar *)lxml_elements[i]) == 0) 2780Sstevel@tonic-gate return ((element_t)i); 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate return ((element_t)-1); 2810Sstevel@tonic-gate } 2820Sstevel@tonic-gate 2830Sstevel@tonic-gate static uint_t 2840Sstevel@tonic-gate lxml_xlate_boolean(const xmlChar *value) 2850Sstevel@tonic-gate { 2860Sstevel@tonic-gate if (xmlStrcmp(value, (const xmlChar *)true) == 0) 2870Sstevel@tonic-gate return (1); 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate if (xmlStrcmp(value, (const xmlChar *)false) == 0) 2900Sstevel@tonic-gate return (0); 2910Sstevel@tonic-gate 2920Sstevel@tonic-gate uu_die(gettext("illegal boolean value \"%s\"\n"), value); 2930Sstevel@tonic-gate 2940Sstevel@tonic-gate /*NOTREACHED*/ 2950Sstevel@tonic-gate } 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate static scf_type_t 2980Sstevel@tonic-gate lxml_element_to_type(element_t type) 2990Sstevel@tonic-gate { 3000Sstevel@tonic-gate switch (type) { 3010Sstevel@tonic-gate case SC_ASTRING: return (SCF_TYPE_ASTRING); 3020Sstevel@tonic-gate case SC_BOOLEAN: return (SCF_TYPE_BOOLEAN); 3030Sstevel@tonic-gate case SC_COUNT: return (SCF_TYPE_COUNT); 3040Sstevel@tonic-gate case SC_FMRI: return (SCF_TYPE_FMRI); 3050Sstevel@tonic-gate case SC_HOST: return (SCF_TYPE_HOST); 3060Sstevel@tonic-gate case SC_HOSTNAME: return (SCF_TYPE_HOSTNAME); 3070Sstevel@tonic-gate case SC_INTEGER: return (SCF_TYPE_INTEGER); 3080Sstevel@tonic-gate case SC_NET_ADDR_V4: return (SCF_TYPE_NET_ADDR_V4); 3090Sstevel@tonic-gate case SC_NET_ADDR_V6: return (SCF_TYPE_NET_ADDR_V6); 3100Sstevel@tonic-gate case SC_OPAQUE: return (SCF_TYPE_OPAQUE); 3110Sstevel@tonic-gate case SC_TIME: return (SCF_TYPE_TIME); 3120Sstevel@tonic-gate case SC_URI: return (SCF_TYPE_URI); 3130Sstevel@tonic-gate case SC_USTRING: return (SCF_TYPE_USTRING); 3140Sstevel@tonic-gate 3150Sstevel@tonic-gate default: 3160Sstevel@tonic-gate uu_die(gettext("unknown value type (%d)\n"), type); 3170Sstevel@tonic-gate } 3180Sstevel@tonic-gate 3190Sstevel@tonic-gate /* NOTREACHED */ 3200Sstevel@tonic-gate } 3210Sstevel@tonic-gate 3220Sstevel@tonic-gate static scf_type_t 3230Sstevel@tonic-gate lxml_element_to_scf_type(element_t type) 3240Sstevel@tonic-gate { 3250Sstevel@tonic-gate switch (type) { 3260Sstevel@tonic-gate case SC_ASTRING: return (SCF_TYPE_ASTRING); 3270Sstevel@tonic-gate case SC_BOOLEAN: return (SCF_TYPE_BOOLEAN); 3280Sstevel@tonic-gate case SC_COUNT: return (SCF_TYPE_COUNT); 3290Sstevel@tonic-gate case SC_FMRI: return (SCF_TYPE_FMRI); 3300Sstevel@tonic-gate case SC_HOST: return (SCF_TYPE_HOST); 3310Sstevel@tonic-gate case SC_HOSTNAME: return (SCF_TYPE_HOSTNAME); 3320Sstevel@tonic-gate case SC_INTEGER: return (SCF_TYPE_INTEGER); 3330Sstevel@tonic-gate case SC_NET_ADDR_V4: return (SCF_TYPE_NET_ADDR_V4); 3340Sstevel@tonic-gate case SC_NET_ADDR_V6: return (SCF_TYPE_NET_ADDR_V6); 3350Sstevel@tonic-gate case SC_OPAQUE: return (SCF_TYPE_OPAQUE); 3360Sstevel@tonic-gate case SC_TIME: return (SCF_TYPE_TIME); 3370Sstevel@tonic-gate case SC_URI: return (SCF_TYPE_URI); 3380Sstevel@tonic-gate case SC_USTRING: return (SCF_TYPE_USTRING); 3390Sstevel@tonic-gate default: 3400Sstevel@tonic-gate uu_die(gettext("unknown value type (%d)\n"), type); 3410Sstevel@tonic-gate } 3420Sstevel@tonic-gate 3430Sstevel@tonic-gate /* NOTREACHED */ 3440Sstevel@tonic-gate } 3450Sstevel@tonic-gate 3467887SLiane.Praza@Sun.COM /* 3477887SLiane.Praza@Sun.COM * Create a SCF_TYPE_BOOLEAN property name pname and attach it to the 3487887SLiane.Praza@Sun.COM * property group at pgrp. The value of the property will be set from the 3497887SLiane.Praza@Sun.COM * attribute named attr. attr must have a value of 0, 1, true or false. 3507887SLiane.Praza@Sun.COM * 3517887SLiane.Praza@Sun.COM * Zero is returned on success. An error is indicated by -1. It indicates 3527887SLiane.Praza@Sun.COM * that either the attribute had an invalid value or that we could not 3537887SLiane.Praza@Sun.COM * attach the property to pgrp. The attribute should not have an invalid 3547887SLiane.Praza@Sun.COM * value if the DTD is correctly written. 3557887SLiane.Praza@Sun.COM */ 3567887SLiane.Praza@Sun.COM static int 3577887SLiane.Praza@Sun.COM new_bool_prop_from_attr(pgroup_t *pgrp, const char *pname, xmlNodePtr n, 3587887SLiane.Praza@Sun.COM const char *attr) 3597887SLiane.Praza@Sun.COM { 3607887SLiane.Praza@Sun.COM uint64_t bool; 3617887SLiane.Praza@Sun.COM xmlChar *val; 3627887SLiane.Praza@Sun.COM property_t *p; 3637887SLiane.Praza@Sun.COM int r; 3647887SLiane.Praza@Sun.COM 3657887SLiane.Praza@Sun.COM val = xmlGetProp(n, (xmlChar *)attr); 3667887SLiane.Praza@Sun.COM if (val == NULL) 3677887SLiane.Praza@Sun.COM return (0); 3687887SLiane.Praza@Sun.COM 3697887SLiane.Praza@Sun.COM if ((xmlStrcmp(val, (xmlChar *)"0") == 0) || 3707887SLiane.Praza@Sun.COM (xmlStrcmp(val, (xmlChar *)"false") == 0)) { 3717887SLiane.Praza@Sun.COM bool = 0; 3727887SLiane.Praza@Sun.COM } else if ((xmlStrcmp(val, (xmlChar *)"1") == 0) || 3737887SLiane.Praza@Sun.COM (xmlStrcmp(val, (xmlChar *)"true") == 0)) { 3747887SLiane.Praza@Sun.COM bool = 1; 3757887SLiane.Praza@Sun.COM } else { 3767887SLiane.Praza@Sun.COM xmlFree(val); 3777887SLiane.Praza@Sun.COM return (-1); 3787887SLiane.Praza@Sun.COM } 3797887SLiane.Praza@Sun.COM xmlFree(val); 3807887SLiane.Praza@Sun.COM p = internal_property_create(pname, SCF_TYPE_BOOLEAN, 1, bool); 3817887SLiane.Praza@Sun.COM r = internal_attach_property(pgrp, p); 3827887SLiane.Praza@Sun.COM 3837887SLiane.Praza@Sun.COM if (r != 0) 3847887SLiane.Praza@Sun.COM internal_property_free(p); 3857887SLiane.Praza@Sun.COM 3867887SLiane.Praza@Sun.COM return (r); 3877887SLiane.Praza@Sun.COM } 3887887SLiane.Praza@Sun.COM 3890Sstevel@tonic-gate static int 3900Sstevel@tonic-gate new_str_prop_from_attr(pgroup_t *pgrp, const char *pname, scf_type_t ty, 3910Sstevel@tonic-gate xmlNodePtr n, const char *attr) 3920Sstevel@tonic-gate { 3930Sstevel@tonic-gate xmlChar *val; 3940Sstevel@tonic-gate property_t *p; 3950Sstevel@tonic-gate int r; 3960Sstevel@tonic-gate 3970Sstevel@tonic-gate val = xmlGetProp(n, (xmlChar *)attr); 3980Sstevel@tonic-gate 3990Sstevel@tonic-gate p = internal_property_create(pname, ty, 1, val); 4000Sstevel@tonic-gate r = internal_attach_property(pgrp, p); 4010Sstevel@tonic-gate 4020Sstevel@tonic-gate if (r != 0) 4030Sstevel@tonic-gate internal_property_free(p); 4040Sstevel@tonic-gate 4050Sstevel@tonic-gate return (r); 4060Sstevel@tonic-gate } 4070Sstevel@tonic-gate 4080Sstevel@tonic-gate static int 4097887SLiane.Praza@Sun.COM new_opt_str_prop_from_attr(pgroup_t *pgrp, const char *pname, scf_type_t ty, 4107887SLiane.Praza@Sun.COM xmlNodePtr n, const char *attr, const char *dflt) 4117887SLiane.Praza@Sun.COM { 4127887SLiane.Praza@Sun.COM xmlChar *val; 4137887SLiane.Praza@Sun.COM property_t *p; 4147887SLiane.Praza@Sun.COM int r; 4157887SLiane.Praza@Sun.COM 4167887SLiane.Praza@Sun.COM val = xmlGetProp(n, (xmlChar *)attr); 4177887SLiane.Praza@Sun.COM if (val == NULL) { 4187887SLiane.Praza@Sun.COM if (dflt == NULL) { 4197887SLiane.Praza@Sun.COM /* 4207887SLiane.Praza@Sun.COM * A missing attribute is considered to be a 4217887SLiane.Praza@Sun.COM * success in this function, because many of the 4227887SLiane.Praza@Sun.COM * attributes are optional. Missing non-optional 4237887SLiane.Praza@Sun.COM * attributes will be detected later when template 4247887SLiane.Praza@Sun.COM * validation is done. 4257887SLiane.Praza@Sun.COM */ 4267887SLiane.Praza@Sun.COM return (0); 4277887SLiane.Praza@Sun.COM } else { 4287887SLiane.Praza@Sun.COM val = (xmlChar *)dflt; 4297887SLiane.Praza@Sun.COM } 4307887SLiane.Praza@Sun.COM } 4317887SLiane.Praza@Sun.COM 4327887SLiane.Praza@Sun.COM p = internal_property_create(pname, ty, 1, val); 4337887SLiane.Praza@Sun.COM r = internal_attach_property(pgrp, p); 4347887SLiane.Praza@Sun.COM 4357887SLiane.Praza@Sun.COM if (r != 0) 4367887SLiane.Praza@Sun.COM internal_property_free(p); 4377887SLiane.Praza@Sun.COM 4387887SLiane.Praza@Sun.COM return (r); 4397887SLiane.Praza@Sun.COM } 4407887SLiane.Praza@Sun.COM 4417887SLiane.Praza@Sun.COM static int 4420Sstevel@tonic-gate lxml_ignorable_block(xmlNodePtr n) 4430Sstevel@tonic-gate { 4440Sstevel@tonic-gate return ((xmlStrcmp(n->name, (xmlChar *)"text") == 0 || 4450Sstevel@tonic-gate xmlStrcmp(n->name, (xmlChar *)"comment") == 0) ? 1 : 0); 4460Sstevel@tonic-gate } 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate static int 4490Sstevel@tonic-gate lxml_validate_string_value(scf_type_t type, const char *v) 4500Sstevel@tonic-gate { 4510Sstevel@tonic-gate static scf_value_t *scf_value = NULL; 4520Sstevel@tonic-gate static scf_handle_t *scf_hndl = NULL; 4530Sstevel@tonic-gate 4540Sstevel@tonic-gate if (scf_hndl == NULL && (scf_hndl = scf_handle_create(SCF_VERSION)) == 4550Sstevel@tonic-gate NULL) 4560Sstevel@tonic-gate return (-1); 4570Sstevel@tonic-gate 4580Sstevel@tonic-gate if (scf_value == NULL && (scf_value = scf_value_create(scf_hndl)) == 4590Sstevel@tonic-gate NULL) 4600Sstevel@tonic-gate return (-1); 4610Sstevel@tonic-gate 4620Sstevel@tonic-gate return (scf_value_set_from_string(scf_value, type, v)); 4630Sstevel@tonic-gate } 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate static void 4660Sstevel@tonic-gate lxml_free_str(value_t *val) 4670Sstevel@tonic-gate { 4680Sstevel@tonic-gate free(val->sc_u.sc_string); 4690Sstevel@tonic-gate } 4700Sstevel@tonic-gate 4710Sstevel@tonic-gate static value_t * 4720Sstevel@tonic-gate lxml_make_value(element_t type, const xmlChar *value) 4730Sstevel@tonic-gate { 4740Sstevel@tonic-gate value_t *v; 4750Sstevel@tonic-gate char *endptr; 4760Sstevel@tonic-gate scf_type_t scf_type = SCF_TYPE_INVALID; 4770Sstevel@tonic-gate 4780Sstevel@tonic-gate v = internal_value_new(); 4790Sstevel@tonic-gate 4800Sstevel@tonic-gate v->sc_type = lxml_element_to_type(type); 4810Sstevel@tonic-gate 4820Sstevel@tonic-gate switch (type) { 4830Sstevel@tonic-gate case SC_COUNT: 4840Sstevel@tonic-gate /* 4850Sstevel@tonic-gate * Although an SC_COUNT represents a uint64_t the use 4860Sstevel@tonic-gate * of a negative value is acceptable due to the usage 4870Sstevel@tonic-gate * established by inetd(1M). 4880Sstevel@tonic-gate */ 4890Sstevel@tonic-gate errno = 0; 4900Sstevel@tonic-gate v->sc_u.sc_count = strtoull((char *)value, &endptr, 10); 4910Sstevel@tonic-gate if (errno != 0 || endptr == (char *)value || *endptr) 4920Sstevel@tonic-gate uu_die(gettext("illegal value \"%s\" for " 4930Sstevel@tonic-gate "%s (%s)\n"), (char *)value, 4940Sstevel@tonic-gate lxml_prop_types[type], 4950Sstevel@tonic-gate (errno) ? strerror(errno) : 4960Sstevel@tonic-gate gettext("Illegal character")); 4970Sstevel@tonic-gate break; 4980Sstevel@tonic-gate case SC_INTEGER: 4990Sstevel@tonic-gate errno = 0; 5000Sstevel@tonic-gate v->sc_u.sc_integer = strtoll((char *)value, &endptr, 10); 5010Sstevel@tonic-gate if (errno != 0 || *endptr) 5020Sstevel@tonic-gate uu_die(gettext("illegal value \"%s\" for " 5030Sstevel@tonic-gate "%s (%s)\n"), (char *)value, 5040Sstevel@tonic-gate lxml_prop_types[type], 5050Sstevel@tonic-gate (errno) ? strerror(errno) : "Illegal character"); 5060Sstevel@tonic-gate break; 5070Sstevel@tonic-gate case SC_OPAQUE: 5080Sstevel@tonic-gate case SC_HOST: 5090Sstevel@tonic-gate case SC_HOSTNAME: 5100Sstevel@tonic-gate case SC_NET_ADDR_V4: 5110Sstevel@tonic-gate case SC_NET_ADDR_V6: 5120Sstevel@tonic-gate case SC_FMRI: 5130Sstevel@tonic-gate case SC_URI: 5140Sstevel@tonic-gate case SC_TIME: 5150Sstevel@tonic-gate case SC_ASTRING: 5160Sstevel@tonic-gate case SC_USTRING: 5170Sstevel@tonic-gate scf_type = lxml_element_to_scf_type(type); 5180Sstevel@tonic-gate 5190Sstevel@tonic-gate if ((v->sc_u.sc_string = strdup((char *)value)) == NULL) 5200Sstevel@tonic-gate uu_die(gettext("string duplication failed (%s)\n"), 5210Sstevel@tonic-gate strerror(errno)); 5220Sstevel@tonic-gate if (lxml_validate_string_value(scf_type, 5230Sstevel@tonic-gate v->sc_u.sc_string) != 0) 5240Sstevel@tonic-gate uu_die(gettext("illegal value \"%s\" for " 5250Sstevel@tonic-gate "%s (%s)\n"), (char *)value, 5260Sstevel@tonic-gate lxml_prop_types[type], 5270Sstevel@tonic-gate (scf_error()) ? scf_strerror(scf_error()) : 5280Sstevel@tonic-gate gettext("Illegal format")); 5290Sstevel@tonic-gate v->sc_free = lxml_free_str; 5300Sstevel@tonic-gate break; 5310Sstevel@tonic-gate case SC_BOOLEAN: 5320Sstevel@tonic-gate v->sc_u.sc_count = lxml_xlate_boolean(value); 5330Sstevel@tonic-gate break; 5340Sstevel@tonic-gate default: 5350Sstevel@tonic-gate uu_die(gettext("unknown value type (%d)\n"), type); 5360Sstevel@tonic-gate break; 5370Sstevel@tonic-gate } 5380Sstevel@tonic-gate 5390Sstevel@tonic-gate return (v); 5400Sstevel@tonic-gate } 5410Sstevel@tonic-gate 5420Sstevel@tonic-gate static int 5430Sstevel@tonic-gate lxml_get_value(property_t *prop, element_t vtype, xmlNodePtr value) 5440Sstevel@tonic-gate { 5450Sstevel@tonic-gate xmlNodePtr cursor; 5460Sstevel@tonic-gate 5470Sstevel@tonic-gate for (cursor = value->xmlChildrenNode; cursor != NULL; 5480Sstevel@tonic-gate cursor = cursor->next) { 5490Sstevel@tonic-gate xmlChar *assigned_value; 5500Sstevel@tonic-gate value_t *v; 5510Sstevel@tonic-gate 5520Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 5530Sstevel@tonic-gate continue; 5540Sstevel@tonic-gate 5550Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) { 5560Sstevel@tonic-gate case SC_VALUE_NODE: 5570Sstevel@tonic-gate if ((assigned_value = xmlGetProp(cursor, 5580Sstevel@tonic-gate (xmlChar *)value_attr)) == NULL) 5590Sstevel@tonic-gate uu_die(gettext("no value on value node?\n")); 5600Sstevel@tonic-gate break; 5610Sstevel@tonic-gate default: 5620Sstevel@tonic-gate uu_die(gettext("value list contains illegal element " 5630Sstevel@tonic-gate "\'%s\'\n"), cursor->name); 5640Sstevel@tonic-gate break; 5650Sstevel@tonic-gate } 5660Sstevel@tonic-gate 5670Sstevel@tonic-gate v = lxml_make_value(vtype, assigned_value); 5680Sstevel@tonic-gate 5690Sstevel@tonic-gate xmlFree(assigned_value); 5700Sstevel@tonic-gate 5710Sstevel@tonic-gate internal_attach_value(prop, v); 5720Sstevel@tonic-gate } 5730Sstevel@tonic-gate 5740Sstevel@tonic-gate return (0); 5750Sstevel@tonic-gate } 5760Sstevel@tonic-gate 5770Sstevel@tonic-gate static int 5780Sstevel@tonic-gate lxml_get_propval(pgroup_t *pgrp, xmlNodePtr propval) 5790Sstevel@tonic-gate { 5800Sstevel@tonic-gate property_t *p; 5810Sstevel@tonic-gate element_t r; 5820Sstevel@tonic-gate value_t *v; 5830Sstevel@tonic-gate xmlChar *type, *val, *override; 5840Sstevel@tonic-gate 5850Sstevel@tonic-gate p = internal_property_new(); 5860Sstevel@tonic-gate 5870Sstevel@tonic-gate p->sc_property_name = (char *)xmlGetProp(propval, (xmlChar *)name_attr); 5887887SLiane.Praza@Sun.COM if ((p->sc_property_name == NULL) || (*p->sc_property_name == 0)) 5890Sstevel@tonic-gate uu_die(gettext("property name missing in group '%s'\n"), 5900Sstevel@tonic-gate pgrp->sc_pgroup_name); 5910Sstevel@tonic-gate 5920Sstevel@tonic-gate type = xmlGetProp(propval, (xmlChar *)type_attr); 5937887SLiane.Praza@Sun.COM if ((type == NULL) || (*type == 0)) 5940Sstevel@tonic-gate uu_die(gettext("property type missing for property '%s/%s'\n"), 5950Sstevel@tonic-gate pgrp->sc_pgroup_name, p->sc_property_name); 5960Sstevel@tonic-gate 5970Sstevel@tonic-gate for (r = 0; r < sizeof (lxml_prop_types) / sizeof (char *); ++r) { 5980Sstevel@tonic-gate if (xmlStrcmp(type, (const xmlChar *)lxml_prop_types[r]) == 0) 5990Sstevel@tonic-gate break; 6000Sstevel@tonic-gate } 6017887SLiane.Praza@Sun.COM xmlFree(type); 6020Sstevel@tonic-gate if (r >= sizeof (lxml_prop_types) / sizeof (char *)) 6030Sstevel@tonic-gate uu_die(gettext("property type invalid for property '%s/%s'\n"), 6040Sstevel@tonic-gate pgrp->sc_pgroup_name, p->sc_property_name); 6050Sstevel@tonic-gate 6060Sstevel@tonic-gate p->sc_value_type = lxml_element_to_type(r); 6070Sstevel@tonic-gate 6080Sstevel@tonic-gate val = xmlGetProp(propval, (xmlChar *)value_attr); 6090Sstevel@tonic-gate if (val == NULL) 6100Sstevel@tonic-gate uu_die(gettext("property value missing for property '%s/%s'\n"), 6110Sstevel@tonic-gate pgrp->sc_pgroup_name, p->sc_property_name); 6120Sstevel@tonic-gate 6130Sstevel@tonic-gate v = lxml_make_value(r, val); 6147887SLiane.Praza@Sun.COM xmlFree(val); 6150Sstevel@tonic-gate internal_attach_value(p, v); 6160Sstevel@tonic-gate 6170Sstevel@tonic-gate override = xmlGetProp(propval, (xmlChar *)override_attr); 6180Sstevel@tonic-gate p->sc_property_override = (xmlStrcmp(override, (xmlChar *)true) == 0); 6190Sstevel@tonic-gate xmlFree(override); 6200Sstevel@tonic-gate 6210Sstevel@tonic-gate return (internal_attach_property(pgrp, p)); 6220Sstevel@tonic-gate } 6230Sstevel@tonic-gate 6240Sstevel@tonic-gate static int 6250Sstevel@tonic-gate lxml_get_property(pgroup_t *pgrp, xmlNodePtr property) 6260Sstevel@tonic-gate { 6270Sstevel@tonic-gate property_t *p; 6280Sstevel@tonic-gate xmlNodePtr cursor; 6290Sstevel@tonic-gate element_t r; 6300Sstevel@tonic-gate xmlChar *type, *override; 6310Sstevel@tonic-gate 6320Sstevel@tonic-gate p = internal_property_new(); 6330Sstevel@tonic-gate 6347887SLiane.Praza@Sun.COM if (((p->sc_property_name = (char *)xmlGetProp(property, 6357887SLiane.Praza@Sun.COM (xmlChar *)name_attr)) == NULL) || (*p->sc_property_name == 0)) 6360Sstevel@tonic-gate uu_die(gettext("property name missing in group \'%s\'\n"), 6370Sstevel@tonic-gate pgrp->sc_pgroup_name); 6380Sstevel@tonic-gate 6397887SLiane.Praza@Sun.COM if (((type = xmlGetProp(property, (xmlChar *)type_attr)) == NULL) || 6407887SLiane.Praza@Sun.COM (*type == 0)) { 6410Sstevel@tonic-gate uu_die(gettext("property type missing for " 6420Sstevel@tonic-gate "property \'%s/%s\'\n"), pgrp->sc_pgroup_name, 6430Sstevel@tonic-gate p->sc_property_name); 6447887SLiane.Praza@Sun.COM } 6450Sstevel@tonic-gate 6465040Swesolows for (r = 0; r < sizeof (lxml_prop_types) / sizeof (char *); r++) { 6475040Swesolows if (xmlStrcmp(type, (const xmlChar *)lxml_prop_types[r]) == 0) 6485040Swesolows break; 6495040Swesolows } 6505040Swesolows 6515040Swesolows if (r >= sizeof (lxml_prop_types) / sizeof (char *)) { 6525040Swesolows uu_die(gettext("property type invalid for property '%s/%s'\n"), 6535040Swesolows pgrp->sc_pgroup_name, p->sc_property_name); 6545040Swesolows } 6555040Swesolows 6565040Swesolows p->sc_value_type = lxml_element_to_type(r); 6575040Swesolows 6580Sstevel@tonic-gate for (cursor = property->xmlChildrenNode; cursor != NULL; 6590Sstevel@tonic-gate cursor = cursor->next) { 6600Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 6610Sstevel@tonic-gate continue; 6620Sstevel@tonic-gate 6630Sstevel@tonic-gate switch (r = lxml_xlate_element(cursor->name)) { 6640Sstevel@tonic-gate case SC_ASTRING: 6650Sstevel@tonic-gate case SC_BOOLEAN: 6660Sstevel@tonic-gate case SC_COUNT: 6670Sstevel@tonic-gate case SC_FMRI: 6680Sstevel@tonic-gate case SC_HOST: 6690Sstevel@tonic-gate case SC_HOSTNAME: 6700Sstevel@tonic-gate case SC_INTEGER: 6710Sstevel@tonic-gate case SC_NET_ADDR_V4: 6720Sstevel@tonic-gate case SC_NET_ADDR_V6: 6730Sstevel@tonic-gate case SC_OPAQUE: 6740Sstevel@tonic-gate case SC_TIME: 6750Sstevel@tonic-gate case SC_URI: 6760Sstevel@tonic-gate case SC_USTRING: 6770Sstevel@tonic-gate if (strcmp(lxml_prop_types[r], (const char *)type) != 0) 6780Sstevel@tonic-gate uu_die(gettext("property \'%s\' " 6790Sstevel@tonic-gate "type-to-list mismatch\n"), 6800Sstevel@tonic-gate p->sc_property_name); 6810Sstevel@tonic-gate 6820Sstevel@tonic-gate (void) lxml_get_value(p, r, cursor); 6830Sstevel@tonic-gate break; 6840Sstevel@tonic-gate default: 6850Sstevel@tonic-gate uu_die(gettext("unknown value list type: %s\n"), 6860Sstevel@tonic-gate cursor->name); 6870Sstevel@tonic-gate break; 6880Sstevel@tonic-gate } 6890Sstevel@tonic-gate } 6900Sstevel@tonic-gate 6910Sstevel@tonic-gate xmlFree(type); 6920Sstevel@tonic-gate 6930Sstevel@tonic-gate override = xmlGetProp(property, (xmlChar *)override_attr); 6940Sstevel@tonic-gate p->sc_property_override = (xmlStrcmp(override, (xmlChar *)true) == 0); 6950Sstevel@tonic-gate xmlFree(override); 6960Sstevel@tonic-gate 6970Sstevel@tonic-gate return (internal_attach_property(pgrp, p)); 6980Sstevel@tonic-gate } 6990Sstevel@tonic-gate 7000Sstevel@tonic-gate static int 7010Sstevel@tonic-gate lxml_get_pgroup_stability(pgroup_t *pgrp, xmlNodePtr stab) 7020Sstevel@tonic-gate { 7030Sstevel@tonic-gate return (new_str_prop_from_attr(pgrp, SCF_PROPERTY_STABILITY, 7040Sstevel@tonic-gate SCF_TYPE_ASTRING, stab, value_attr)); 7050Sstevel@tonic-gate } 7060Sstevel@tonic-gate 7070Sstevel@tonic-gate /* 7080Sstevel@tonic-gate * Property groups can go on any of a service, an instance, or a template. 7090Sstevel@tonic-gate */ 7100Sstevel@tonic-gate static int 7110Sstevel@tonic-gate lxml_get_pgroup(entity_t *entity, xmlNodePtr pgroup) 7120Sstevel@tonic-gate { 7130Sstevel@tonic-gate pgroup_t *pg; 7140Sstevel@tonic-gate xmlNodePtr cursor; 7150Sstevel@tonic-gate xmlChar *name, *type, *delete; 7160Sstevel@tonic-gate 7170Sstevel@tonic-gate /* 7180Sstevel@tonic-gate * property group attributes: 7190Sstevel@tonic-gate * name: string 7200Sstevel@tonic-gate * type: string | framework | application 7210Sstevel@tonic-gate */ 7220Sstevel@tonic-gate name = xmlGetProp(pgroup, (xmlChar *)name_attr); 7230Sstevel@tonic-gate type = xmlGetProp(pgroup, (xmlChar *)type_attr); 7240Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, (char *)name, (char *)type); 7250Sstevel@tonic-gate xmlFree(name); 7260Sstevel@tonic-gate xmlFree(type); 7270Sstevel@tonic-gate 7280Sstevel@tonic-gate /* 7290Sstevel@tonic-gate * Walk the children of this lxml_elements, which are a stability 7300Sstevel@tonic-gate * element, property elements, or propval elements. 7310Sstevel@tonic-gate */ 7320Sstevel@tonic-gate for (cursor = pgroup->xmlChildrenNode; cursor != NULL; 7330Sstevel@tonic-gate cursor = cursor->next) { 7340Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 7350Sstevel@tonic-gate continue; 7360Sstevel@tonic-gate 7370Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) { 7380Sstevel@tonic-gate case SC_STABILITY: 7390Sstevel@tonic-gate (void) lxml_get_pgroup_stability(pg, cursor); 7400Sstevel@tonic-gate break; 7410Sstevel@tonic-gate case SC_PROPERTY: 7420Sstevel@tonic-gate (void) lxml_get_property(pg, cursor); 7430Sstevel@tonic-gate break; 7440Sstevel@tonic-gate case SC_PROPVAL: 7450Sstevel@tonic-gate (void) lxml_get_propval(pg, cursor); 7460Sstevel@tonic-gate break; 7470Sstevel@tonic-gate default: 7480Sstevel@tonic-gate abort(); 7490Sstevel@tonic-gate break; 7500Sstevel@tonic-gate } 7510Sstevel@tonic-gate } 7520Sstevel@tonic-gate 7530Sstevel@tonic-gate delete = xmlGetProp(pgroup, (xmlChar *)delete_attr); 7540Sstevel@tonic-gate pg->sc_pgroup_delete = (xmlStrcmp(delete, (xmlChar *)true) == 0); 7550Sstevel@tonic-gate xmlFree(delete); 7560Sstevel@tonic-gate 7570Sstevel@tonic-gate return (0); 7580Sstevel@tonic-gate } 7590Sstevel@tonic-gate 7600Sstevel@tonic-gate 7610Sstevel@tonic-gate /* 7620Sstevel@tonic-gate * Dependency groups, execution methods can go on either a service or an 7630Sstevel@tonic-gate * instance. 7640Sstevel@tonic-gate */ 7650Sstevel@tonic-gate 7660Sstevel@tonic-gate static int 7670Sstevel@tonic-gate lxml_get_method_profile(pgroup_t *pg, xmlNodePtr profile) 7680Sstevel@tonic-gate { 7690Sstevel@tonic-gate property_t *p; 7700Sstevel@tonic-gate 7710Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_USE_PROFILE, SCF_TYPE_BOOLEAN, 7720Sstevel@tonic-gate 1, (uint64_t)1); 7730Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0) 7740Sstevel@tonic-gate return (-1); 7750Sstevel@tonic-gate 7760Sstevel@tonic-gate return (new_str_prop_from_attr(pg, SCF_PROPERTY_PROFILE, 7770Sstevel@tonic-gate SCF_TYPE_ASTRING, profile, name_attr)); 7780Sstevel@tonic-gate } 7790Sstevel@tonic-gate 7800Sstevel@tonic-gate static int 7810Sstevel@tonic-gate lxml_get_method_credential(pgroup_t *pg, xmlNodePtr cred) 7820Sstevel@tonic-gate { 7830Sstevel@tonic-gate property_t *p; 7840Sstevel@tonic-gate 7850Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_USE_PROFILE, SCF_TYPE_BOOLEAN, 7860Sstevel@tonic-gate 1, (uint64_t)0); 7870Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0) 7880Sstevel@tonic-gate return (-1); 7890Sstevel@tonic-gate 7909263SSean.Wilcox@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_USER, SCF_TYPE_ASTRING, 7919263SSean.Wilcox@Sun.COM cred, "user", NULL) != 0) 7920Sstevel@tonic-gate return (-1); 7930Sstevel@tonic-gate 7949263SSean.Wilcox@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_GROUP, SCF_TYPE_ASTRING, 7959263SSean.Wilcox@Sun.COM cred, "group", NULL) != 0) 7960Sstevel@tonic-gate return (-1); 7970Sstevel@tonic-gate 7989263SSean.Wilcox@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_SUPP_GROUPS, 7999263SSean.Wilcox@Sun.COM SCF_TYPE_ASTRING, cred, "supp_groups", NULL) != 0) 8000Sstevel@tonic-gate return (-1); 8010Sstevel@tonic-gate 8029263SSean.Wilcox@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_PRIVILEGES, 8039263SSean.Wilcox@Sun.COM SCF_TYPE_ASTRING, cred, "privileges", NULL) != 0) 8040Sstevel@tonic-gate return (-1); 8050Sstevel@tonic-gate 8069263SSean.Wilcox@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_LIMIT_PRIVILEGES, 8079263SSean.Wilcox@Sun.COM SCF_TYPE_ASTRING, cred, "limit_privileges", NULL) != 0) 8080Sstevel@tonic-gate return (-1); 8090Sstevel@tonic-gate 8100Sstevel@tonic-gate return (0); 8110Sstevel@tonic-gate } 8120Sstevel@tonic-gate 8130Sstevel@tonic-gate static char * 8140Sstevel@tonic-gate lxml_get_envvar(xmlNodePtr envvar) 8150Sstevel@tonic-gate { 8160Sstevel@tonic-gate char *name; 8170Sstevel@tonic-gate char *value; 8180Sstevel@tonic-gate char *ret; 8190Sstevel@tonic-gate 8207887SLiane.Praza@Sun.COM name = (char *)xmlGetProp(envvar, (xmlChar *)name_attr); 8217887SLiane.Praza@Sun.COM value = (char *)xmlGetProp(envvar, (xmlChar *)value_attr); 8220Sstevel@tonic-gate 8230Sstevel@tonic-gate if (strlen(name) == 0 || strchr(name, '=') != NULL) 8240Sstevel@tonic-gate uu_die(gettext("Invalid environment variable " 8250Sstevel@tonic-gate "\"%s\".\n"), name); 8260Sstevel@tonic-gate if (strstr(name, "SMF_") == name) 8270Sstevel@tonic-gate uu_die(gettext("Invalid environment variable " 8280Sstevel@tonic-gate "\"%s\"; \"SMF_\" prefix is reserved.\n"), name); 8290Sstevel@tonic-gate 8300Sstevel@tonic-gate ret = uu_msprintf("%s=%s", name, value); 8310Sstevel@tonic-gate xmlFree(name); 8320Sstevel@tonic-gate xmlFree(value); 8330Sstevel@tonic-gate return (ret); 8340Sstevel@tonic-gate } 8350Sstevel@tonic-gate 8360Sstevel@tonic-gate static int 8370Sstevel@tonic-gate lxml_get_method_environment(pgroup_t *pg, xmlNodePtr environment) 8380Sstevel@tonic-gate { 8390Sstevel@tonic-gate property_t *p; 8400Sstevel@tonic-gate xmlNodePtr cursor; 8410Sstevel@tonic-gate value_t *val; 8420Sstevel@tonic-gate 8430Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_ENVIRONMENT, 8440Sstevel@tonic-gate SCF_TYPE_ASTRING, 0); 8450Sstevel@tonic-gate 8460Sstevel@tonic-gate for (cursor = environment->xmlChildrenNode; cursor != NULL; 8470Sstevel@tonic-gate cursor = cursor->next) { 8480Sstevel@tonic-gate char *tmp; 8490Sstevel@tonic-gate 8500Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 8510Sstevel@tonic-gate continue; 8520Sstevel@tonic-gate 8530Sstevel@tonic-gate if (lxml_xlate_element(cursor->name) != SC_METHOD_ENVVAR) 8540Sstevel@tonic-gate uu_die(gettext("illegal element \"%s\" on " 8550Sstevel@tonic-gate "method environment for \"%s\"\n"), 8560Sstevel@tonic-gate cursor->name, pg->sc_pgroup_name); 8570Sstevel@tonic-gate 8580Sstevel@tonic-gate if ((tmp = lxml_get_envvar(cursor)) == NULL) 8590Sstevel@tonic-gate uu_die(gettext("Out of memory\n")); 8600Sstevel@tonic-gate 8610Sstevel@tonic-gate val = internal_value_new(); 8620Sstevel@tonic-gate val->sc_u.sc_string = tmp; 8630Sstevel@tonic-gate val->sc_type = SCF_TYPE_ASTRING; 8640Sstevel@tonic-gate val->sc_free = lxml_free_str; 8650Sstevel@tonic-gate internal_attach_value(p, val); 8660Sstevel@tonic-gate } 8670Sstevel@tonic-gate 8680Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0) { 8690Sstevel@tonic-gate internal_property_free(p); 8700Sstevel@tonic-gate return (-1); 8710Sstevel@tonic-gate } 8720Sstevel@tonic-gate 8730Sstevel@tonic-gate return (0); 8740Sstevel@tonic-gate } 8750Sstevel@tonic-gate 8760Sstevel@tonic-gate static int 8770Sstevel@tonic-gate lxml_get_method_context(pgroup_t *pg, xmlNodePtr ctx) 8780Sstevel@tonic-gate { 8790Sstevel@tonic-gate xmlNodePtr cursor; 8800Sstevel@tonic-gate 8819263SSean.Wilcox@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_WORKING_DIRECTORY, 8829263SSean.Wilcox@Sun.COM SCF_TYPE_ASTRING, ctx, "working_directory", NULL) != 0) 8830Sstevel@tonic-gate return (-1); 8840Sstevel@tonic-gate 8859263SSean.Wilcox@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_PROJECT, 8869263SSean.Wilcox@Sun.COM SCF_TYPE_ASTRING, ctx, "project", NULL) != 0) 8870Sstevel@tonic-gate return (-1); 8880Sstevel@tonic-gate 8899263SSean.Wilcox@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_RESOURCE_POOL, 8909263SSean.Wilcox@Sun.COM SCF_TYPE_ASTRING, ctx, "resource_pool", NULL) != 0) 8910Sstevel@tonic-gate return (-1); 8920Sstevel@tonic-gate 8930Sstevel@tonic-gate for (cursor = ctx->xmlChildrenNode; cursor != NULL; 8940Sstevel@tonic-gate cursor = cursor->next) { 8950Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 8960Sstevel@tonic-gate continue; 8970Sstevel@tonic-gate 8980Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) { 8990Sstevel@tonic-gate case SC_METHOD_CREDENTIAL: 9000Sstevel@tonic-gate (void) lxml_get_method_credential(pg, cursor); 9010Sstevel@tonic-gate break; 9020Sstevel@tonic-gate case SC_METHOD_PROFILE: 9030Sstevel@tonic-gate (void) lxml_get_method_profile(pg, cursor); 9040Sstevel@tonic-gate break; 9050Sstevel@tonic-gate case SC_METHOD_ENVIRONMENT: 9060Sstevel@tonic-gate (void) lxml_get_method_environment(pg, cursor); 9070Sstevel@tonic-gate break; 9080Sstevel@tonic-gate default: 9090Sstevel@tonic-gate semerr(gettext("illegal element \'%s\' in method " 9100Sstevel@tonic-gate "context\n"), (char *)cursor); 9110Sstevel@tonic-gate break; 9120Sstevel@tonic-gate } 9130Sstevel@tonic-gate } 9140Sstevel@tonic-gate 9150Sstevel@tonic-gate return (0); 9160Sstevel@tonic-gate } 9170Sstevel@tonic-gate 9180Sstevel@tonic-gate static int 9190Sstevel@tonic-gate lxml_get_entity_method_context(entity_t *entity, xmlNodePtr ctx) 9200Sstevel@tonic-gate { 9210Sstevel@tonic-gate pgroup_t *pg; 9220Sstevel@tonic-gate 9230Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, SCF_PG_METHOD_CONTEXT, 9240Sstevel@tonic-gate (char *)scf_group_framework); 9250Sstevel@tonic-gate 9260Sstevel@tonic-gate return (lxml_get_method_context(pg, ctx)); 9270Sstevel@tonic-gate } 9280Sstevel@tonic-gate 9290Sstevel@tonic-gate static int 9300Sstevel@tonic-gate lxml_get_exec_method(entity_t *entity, xmlNodePtr emeth) 9310Sstevel@tonic-gate { 9320Sstevel@tonic-gate pgroup_t *pg; 9330Sstevel@tonic-gate property_t *p; 9340Sstevel@tonic-gate xmlChar *name, *timeout, *delete; 9350Sstevel@tonic-gate xmlNodePtr cursor; 9360Sstevel@tonic-gate int r = 0; 9370Sstevel@tonic-gate 9380Sstevel@tonic-gate name = xmlGetProp(emeth, (xmlChar *)name_attr); 9390Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, (char *)name, 9400Sstevel@tonic-gate (char *)SCF_GROUP_METHOD); 9410Sstevel@tonic-gate xmlFree(name); 9420Sstevel@tonic-gate 9430Sstevel@tonic-gate if (new_str_prop_from_attr(pg, SCF_PROPERTY_TYPE, SCF_TYPE_ASTRING, 9440Sstevel@tonic-gate emeth, type_attr) != 0 || 9450Sstevel@tonic-gate new_str_prop_from_attr(pg, SCF_PROPERTY_EXEC, SCF_TYPE_ASTRING, 9460Sstevel@tonic-gate emeth, "exec") != 0) 9470Sstevel@tonic-gate return (-1); 9480Sstevel@tonic-gate 9497887SLiane.Praza@Sun.COM timeout = xmlGetProp(emeth, (xmlChar *)timeout_seconds_attr); 9500Sstevel@tonic-gate if (timeout != NULL) { 9510Sstevel@tonic-gate uint64_t u_timeout; 9520Sstevel@tonic-gate char *endptr; 9530Sstevel@tonic-gate /* 9540Sstevel@tonic-gate * Although an SC_COUNT represents a uint64_t the use 9550Sstevel@tonic-gate * of a negative value is acceptable due to the usage 9560Sstevel@tonic-gate * established by inetd(1M). 9570Sstevel@tonic-gate */ 9580Sstevel@tonic-gate errno = 0; 9590Sstevel@tonic-gate u_timeout = strtoull((char *)timeout, &endptr, 10); 9600Sstevel@tonic-gate if (errno != 0 || endptr == (char *)timeout || *endptr) 9610Sstevel@tonic-gate uu_die(gettext("illegal value \"%s\" for " 9620Sstevel@tonic-gate "timeout_seconds (%s)\n"), 9630Sstevel@tonic-gate (char *)timeout, (errno) ? strerror(errno): 9640Sstevel@tonic-gate gettext("Illegal character")); 9650Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_TIMEOUT, 9660Sstevel@tonic-gate SCF_TYPE_COUNT, 1, u_timeout); 9670Sstevel@tonic-gate r = internal_attach_property(pg, p); 9680Sstevel@tonic-gate xmlFree(timeout); 9690Sstevel@tonic-gate } 9700Sstevel@tonic-gate if (r != 0) 9710Sstevel@tonic-gate return (-1); 9720Sstevel@tonic-gate 9730Sstevel@tonic-gate /* 9740Sstevel@tonic-gate * There is a possibility that a method context also exists, in which 9750Sstevel@tonic-gate * case the following attributes are defined: project, resource_pool, 9760Sstevel@tonic-gate * working_directory, profile, user, group, privileges, limit_privileges 9770Sstevel@tonic-gate */ 9780Sstevel@tonic-gate for (cursor = emeth->xmlChildrenNode; cursor != NULL; 9790Sstevel@tonic-gate cursor = cursor->next) { 9800Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 9810Sstevel@tonic-gate continue; 9820Sstevel@tonic-gate 9830Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) { 9840Sstevel@tonic-gate case SC_STABILITY: 9850Sstevel@tonic-gate if (lxml_get_pgroup_stability(pg, cursor) != 0) 9860Sstevel@tonic-gate return (-1); 9870Sstevel@tonic-gate break; 9880Sstevel@tonic-gate 9890Sstevel@tonic-gate case SC_METHOD_CONTEXT: 9900Sstevel@tonic-gate (void) lxml_get_method_context(pg, cursor); 9910Sstevel@tonic-gate break; 9920Sstevel@tonic-gate 9930Sstevel@tonic-gate case SC_PROPVAL: 9940Sstevel@tonic-gate (void) lxml_get_propval(pg, cursor); 9950Sstevel@tonic-gate break; 9960Sstevel@tonic-gate 9970Sstevel@tonic-gate case SC_PROPERTY: 9980Sstevel@tonic-gate (void) lxml_get_property(pg, cursor); 9990Sstevel@tonic-gate break; 10000Sstevel@tonic-gate 10010Sstevel@tonic-gate default: 10020Sstevel@tonic-gate uu_die(gettext("illegal element \"%s\" on " 10030Sstevel@tonic-gate "execution method \"%s\"\n"), cursor->name, 10040Sstevel@tonic-gate pg->sc_pgroup_name); 10050Sstevel@tonic-gate break; 10060Sstevel@tonic-gate } 10070Sstevel@tonic-gate } 10080Sstevel@tonic-gate 10090Sstevel@tonic-gate delete = xmlGetProp(emeth, (xmlChar *)delete_attr); 10100Sstevel@tonic-gate pg->sc_pgroup_delete = (xmlStrcmp(delete, (xmlChar *)true) == 0); 10110Sstevel@tonic-gate xmlFree(delete); 10120Sstevel@tonic-gate 10130Sstevel@tonic-gate return (0); 10140Sstevel@tonic-gate } 10150Sstevel@tonic-gate 10160Sstevel@tonic-gate static int 10170Sstevel@tonic-gate lxml_get_dependency(entity_t *entity, xmlNodePtr dependency) 10180Sstevel@tonic-gate { 10190Sstevel@tonic-gate pgroup_t *pg; 10200Sstevel@tonic-gate property_t *p; 10210Sstevel@tonic-gate xmlNodePtr cursor; 10220Sstevel@tonic-gate xmlChar *name; 10230Sstevel@tonic-gate xmlChar *delete; 10240Sstevel@tonic-gate 10250Sstevel@tonic-gate /* 10260Sstevel@tonic-gate * dependency attributes: 10270Sstevel@tonic-gate * name: string 10280Sstevel@tonic-gate * grouping: require_all | require_any | exclude_all | optional_all 10290Sstevel@tonic-gate * reset_on: string (error | restart | refresh | none) 10300Sstevel@tonic-gate * type: service / path /host 10310Sstevel@tonic-gate */ 10320Sstevel@tonic-gate 10330Sstevel@tonic-gate name = xmlGetProp(dependency, (xmlChar *)name_attr); 10340Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, (char *)name, 10350Sstevel@tonic-gate (char *)SCF_GROUP_DEPENDENCY); 10360Sstevel@tonic-gate xmlFree(name); 10370Sstevel@tonic-gate 10380Sstevel@tonic-gate if (new_str_prop_from_attr(pg, SCF_PROPERTY_TYPE, SCF_TYPE_ASTRING, 10390Sstevel@tonic-gate dependency, type_attr) != 0) 10400Sstevel@tonic-gate return (-1); 10410Sstevel@tonic-gate 10420Sstevel@tonic-gate if (new_str_prop_from_attr(pg, SCF_PROPERTY_RESTART_ON, 10430Sstevel@tonic-gate SCF_TYPE_ASTRING, dependency, "restart_on") != 0) 10440Sstevel@tonic-gate return (-1); 10450Sstevel@tonic-gate 10460Sstevel@tonic-gate if (new_str_prop_from_attr(pg, SCF_PROPERTY_GROUPING, SCF_TYPE_ASTRING, 10470Sstevel@tonic-gate dependency, "grouping") != 0) 10480Sstevel@tonic-gate return (-1); 10490Sstevel@tonic-gate 10500Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_ENTITIES, SCF_TYPE_FMRI, 0); 10510Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0) 10520Sstevel@tonic-gate return (-1); 10530Sstevel@tonic-gate 10540Sstevel@tonic-gate for (cursor = dependency->xmlChildrenNode; cursor != NULL; 10550Sstevel@tonic-gate cursor = cursor->next) { 10560Sstevel@tonic-gate xmlChar *value; 10570Sstevel@tonic-gate value_t *v; 10580Sstevel@tonic-gate 10590Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 10600Sstevel@tonic-gate continue; 10610Sstevel@tonic-gate 10620Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) { 10630Sstevel@tonic-gate case SC_STABILITY: 10640Sstevel@tonic-gate if (lxml_get_pgroup_stability(pg, cursor) != 0) 10650Sstevel@tonic-gate return (-1); 10660Sstevel@tonic-gate break; 10670Sstevel@tonic-gate 10680Sstevel@tonic-gate case SC_SERVICE_FMRI: 10690Sstevel@tonic-gate value = xmlGetProp(cursor, (xmlChar *)value_attr); 10700Sstevel@tonic-gate if (value != NULL) { 10710Sstevel@tonic-gate if (lxml_validate_string_value(SCF_TYPE_FMRI, 10720Sstevel@tonic-gate (char *)value) != 0) 10730Sstevel@tonic-gate uu_die(gettext("illegal value \"%s\" " 10740Sstevel@tonic-gate "for %s (%s)\n"), (char *)value, 10750Sstevel@tonic-gate lxml_prop_types[SC_FMRI], 10760Sstevel@tonic-gate (scf_error()) ? 10770Sstevel@tonic-gate scf_strerror(scf_error()) : 10780Sstevel@tonic-gate gettext("Illegal format")); 10790Sstevel@tonic-gate v = internal_value_new(); 10800Sstevel@tonic-gate v->sc_type = SCF_TYPE_FMRI; 10810Sstevel@tonic-gate v->sc_u.sc_string = (char *)value; 10820Sstevel@tonic-gate internal_attach_value(p, v); 10830Sstevel@tonic-gate } 10840Sstevel@tonic-gate 10850Sstevel@tonic-gate break; 10860Sstevel@tonic-gate 10870Sstevel@tonic-gate case SC_PROPVAL: 10880Sstevel@tonic-gate (void) lxml_get_propval(pg, cursor); 10890Sstevel@tonic-gate break; 10900Sstevel@tonic-gate 10910Sstevel@tonic-gate case SC_PROPERTY: 10920Sstevel@tonic-gate (void) lxml_get_property(pg, cursor); 10930Sstevel@tonic-gate break; 10940Sstevel@tonic-gate 10950Sstevel@tonic-gate default: 10960Sstevel@tonic-gate uu_die(gettext("illegal element \"%s\" on " 10970Sstevel@tonic-gate "dependency group \"%s\"\n"), cursor->name, name); 10980Sstevel@tonic-gate break; 10990Sstevel@tonic-gate } 11000Sstevel@tonic-gate } 11010Sstevel@tonic-gate 11020Sstevel@tonic-gate delete = xmlGetProp(dependency, (xmlChar *)delete_attr); 11030Sstevel@tonic-gate pg->sc_pgroup_delete = (xmlStrcmp(delete, (xmlChar *)true) == 0); 11040Sstevel@tonic-gate xmlFree(delete); 11050Sstevel@tonic-gate 11060Sstevel@tonic-gate return (0); 11070Sstevel@tonic-gate } 11080Sstevel@tonic-gate 11090Sstevel@tonic-gate /* 11100Sstevel@tonic-gate * Dependents are hairy. They should cause a dependency pg to be created in 11110Sstevel@tonic-gate * another service, but we can't do that here; we'll have to wait until the 11120Sstevel@tonic-gate * import routines. So for now we'll add the dependency group that should go 11130Sstevel@tonic-gate * in the other service to the entity's dependent list. 11140Sstevel@tonic-gate */ 11150Sstevel@tonic-gate static int 11160Sstevel@tonic-gate lxml_get_dependent(entity_t *entity, xmlNodePtr dependent) 11170Sstevel@tonic-gate { 11180Sstevel@tonic-gate xmlChar *name, *or; 11190Sstevel@tonic-gate xmlNodePtr sf; 11200Sstevel@tonic-gate xmlChar *fmri, *delete; 11210Sstevel@tonic-gate pgroup_t *pg; 11220Sstevel@tonic-gate property_t *p; 11230Sstevel@tonic-gate xmlNodePtr n; 11240Sstevel@tonic-gate char *myfmri; 11250Sstevel@tonic-gate 11260Sstevel@tonic-gate name = xmlGetProp(dependent, (xmlChar *)name_attr); 11270Sstevel@tonic-gate 11280Sstevel@tonic-gate if (internal_pgroup_find(entity, (char *)name, NULL) != NULL) { 11290Sstevel@tonic-gate semerr(gettext("Property group and dependent of entity %s " 11300Sstevel@tonic-gate "have same name \"%s\".\n"), entity->sc_name, name); 11310Sstevel@tonic-gate xmlFree(name); 11320Sstevel@tonic-gate return (-1); 11330Sstevel@tonic-gate } 11340Sstevel@tonic-gate 11350Sstevel@tonic-gate or = xmlGetProp(dependent, (xmlChar *)override_attr); 11360Sstevel@tonic-gate 11370Sstevel@tonic-gate pg = internal_pgroup_new(); 11380Sstevel@tonic-gate pg->sc_pgroup_name = (char *)name; 11390Sstevel@tonic-gate pg->sc_pgroup_type = (char *)SCF_GROUP_DEPENDENCY; 11400Sstevel@tonic-gate pg->sc_pgroup_override = (xmlStrcmp(or, (xmlChar *)true) == 0); 11410Sstevel@tonic-gate xmlFree(or); 11420Sstevel@tonic-gate if (internal_attach_dependent(entity, pg) != 0) { 11430Sstevel@tonic-gate xmlFree(name); 11440Sstevel@tonic-gate internal_pgroup_free(pg); 11450Sstevel@tonic-gate return (-1); 11460Sstevel@tonic-gate } 11470Sstevel@tonic-gate 11480Sstevel@tonic-gate for (sf = dependent->children; sf != NULL; sf = sf->next) 11490Sstevel@tonic-gate if (xmlStrcmp(sf->name, (xmlChar *)"service_fmri") == 0) 11500Sstevel@tonic-gate break; 11510Sstevel@tonic-gate assert(sf != NULL); 11520Sstevel@tonic-gate fmri = xmlGetProp(sf, (xmlChar *)value_attr); 11530Sstevel@tonic-gate pg->sc_pgroup_fmri = (char *)fmri; 11540Sstevel@tonic-gate 11550Sstevel@tonic-gate if (new_str_prop_from_attr(pg, SCF_PROPERTY_RESTART_ON, 11560Sstevel@tonic-gate SCF_TYPE_ASTRING, dependent, "restart_on") != 0) 11570Sstevel@tonic-gate return (-1); 11580Sstevel@tonic-gate 11590Sstevel@tonic-gate if (new_str_prop_from_attr(pg, SCF_PROPERTY_GROUPING, SCF_TYPE_ASTRING, 11600Sstevel@tonic-gate dependent, "grouping") != 0) 11610Sstevel@tonic-gate return (-1); 11620Sstevel@tonic-gate 11630Sstevel@tonic-gate myfmri = safe_malloc(max_scf_fmri_len + 1); 11640Sstevel@tonic-gate if (entity->sc_etype == SVCCFG_SERVICE_OBJECT) { 11650Sstevel@tonic-gate if (snprintf(myfmri, max_scf_fmri_len + 1, "svc:/%s", 11660Sstevel@tonic-gate entity->sc_name) < 0) 11670Sstevel@tonic-gate bad_error("snprintf", errno); 11680Sstevel@tonic-gate } else { 11690Sstevel@tonic-gate assert(entity->sc_etype == SVCCFG_INSTANCE_OBJECT); 11700Sstevel@tonic-gate if (snprintf(myfmri, max_scf_fmri_len + 1, "svc:/%s:%s", 11710Sstevel@tonic-gate entity->sc_parent->sc_name, entity->sc_name) < 0) 11720Sstevel@tonic-gate bad_error("snprintf", errno); 11730Sstevel@tonic-gate } 11740Sstevel@tonic-gate 11750Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_ENTITIES, SCF_TYPE_FMRI, 1, 11760Sstevel@tonic-gate myfmri); 11770Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0) 11780Sstevel@tonic-gate return (-1); 11790Sstevel@tonic-gate 11800Sstevel@tonic-gate /* Create a property to serve as a do-not-export flag. */ 11810Sstevel@tonic-gate p = internal_property_create("external", SCF_TYPE_BOOLEAN, 1, 11820Sstevel@tonic-gate (uint64_t)1); 11830Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0) 11840Sstevel@tonic-gate return (-1); 11850Sstevel@tonic-gate 11860Sstevel@tonic-gate for (n = sf->next; n != NULL; n = n->next) { 11870Sstevel@tonic-gate if (lxml_ignorable_block(n)) 11880Sstevel@tonic-gate continue; 11890Sstevel@tonic-gate 11900Sstevel@tonic-gate switch (lxml_xlate_element(n->name)) { 11910Sstevel@tonic-gate case SC_STABILITY: 11920Sstevel@tonic-gate if (new_str_prop_from_attr(pg, 11930Sstevel@tonic-gate SCF_PROPERTY_ENTITY_STABILITY, SCF_TYPE_ASTRING, n, 11940Sstevel@tonic-gate value_attr) != 0) 11950Sstevel@tonic-gate return (-1); 11960Sstevel@tonic-gate break; 11970Sstevel@tonic-gate 11980Sstevel@tonic-gate case SC_PROPVAL: 11990Sstevel@tonic-gate (void) lxml_get_propval(pg, n); 12000Sstevel@tonic-gate break; 12010Sstevel@tonic-gate 12020Sstevel@tonic-gate case SC_PROPERTY: 12030Sstevel@tonic-gate (void) lxml_get_property(pg, n); 12040Sstevel@tonic-gate break; 12050Sstevel@tonic-gate 12060Sstevel@tonic-gate default: 12070Sstevel@tonic-gate uu_die(gettext("unexpected element %s.\n"), n->name); 12080Sstevel@tonic-gate } 12090Sstevel@tonic-gate } 12100Sstevel@tonic-gate 12110Sstevel@tonic-gate /* Go back and fill in defaults. */ 12120Sstevel@tonic-gate if (internal_property_find(pg, SCF_PROPERTY_TYPE) == NULL) { 12130Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_TYPE, 12140Sstevel@tonic-gate SCF_TYPE_ASTRING, 1, "service"); 12150Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0) 12160Sstevel@tonic-gate return (-1); 12170Sstevel@tonic-gate } 12180Sstevel@tonic-gate 12190Sstevel@tonic-gate delete = xmlGetProp(dependent, (xmlChar *)delete_attr); 12200Sstevel@tonic-gate pg->sc_pgroup_delete = (xmlStrcmp(delete, (xmlChar *)true) == 0); 12210Sstevel@tonic-gate xmlFree(delete); 12220Sstevel@tonic-gate 12230Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, "dependents", 12240Sstevel@tonic-gate (char *)scf_group_framework); 1225306Sbustos p = internal_property_create((char *)name, SCF_TYPE_FMRI, 1, fmri); 12260Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0) 12270Sstevel@tonic-gate return (-1); 12280Sstevel@tonic-gate 12290Sstevel@tonic-gate return (0); 12300Sstevel@tonic-gate } 12310Sstevel@tonic-gate 12320Sstevel@tonic-gate static int 12330Sstevel@tonic-gate lxml_get_entity_stability(entity_t *entity, xmlNodePtr rstr) 12340Sstevel@tonic-gate { 12350Sstevel@tonic-gate pgroup_t *pg; 12360Sstevel@tonic-gate property_t *p; 12370Sstevel@tonic-gate xmlChar *stabval; 12380Sstevel@tonic-gate 12397887SLiane.Praza@Sun.COM if (((stabval = xmlGetProp(rstr, (xmlChar *)value_attr)) == NULL) || 12407887SLiane.Praza@Sun.COM (*stabval == 0)) { 12410Sstevel@tonic-gate uu_warn(gettext("no stability value found\n")); 12420Sstevel@tonic-gate stabval = (xmlChar *)strdup("External"); 12430Sstevel@tonic-gate } 12440Sstevel@tonic-gate 12450Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, (char *)scf_pg_general, 12460Sstevel@tonic-gate (char *)scf_group_framework); 12470Sstevel@tonic-gate 12480Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_ENTITY_STABILITY, 12490Sstevel@tonic-gate SCF_TYPE_ASTRING, 1, stabval); 12500Sstevel@tonic-gate 12510Sstevel@tonic-gate return (internal_attach_property(pg, p)); 12520Sstevel@tonic-gate } 12530Sstevel@tonic-gate 12540Sstevel@tonic-gate static int 12550Sstevel@tonic-gate lxml_get_restarter(entity_t *entity, xmlNodePtr rstr) 12560Sstevel@tonic-gate { 12570Sstevel@tonic-gate pgroup_t *pg; 12580Sstevel@tonic-gate property_t *p; 12590Sstevel@tonic-gate xmlChar *restarter; 12600Sstevel@tonic-gate xmlNode *cursor; 12610Sstevel@tonic-gate int r; 12620Sstevel@tonic-gate 12630Sstevel@tonic-gate /* 12640Sstevel@tonic-gate * Go find child. Child is a service_fmri element. value attribute 12650Sstevel@tonic-gate * contains restarter FMRI. 12660Sstevel@tonic-gate */ 12670Sstevel@tonic-gate 12680Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, (char *)scf_pg_general, 12690Sstevel@tonic-gate (char *)scf_group_framework); 12700Sstevel@tonic-gate 12710Sstevel@tonic-gate /* 12720Sstevel@tonic-gate * Walk its child elements, as appropriate. 12730Sstevel@tonic-gate */ 12740Sstevel@tonic-gate for (cursor = rstr->xmlChildrenNode; cursor != NULL; 12750Sstevel@tonic-gate cursor = cursor->next) { 12760Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 12770Sstevel@tonic-gate continue; 12780Sstevel@tonic-gate 12790Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) { 12800Sstevel@tonic-gate case SC_SERVICE_FMRI: 12810Sstevel@tonic-gate restarter = xmlGetProp(cursor, (xmlChar *)value_attr); 12820Sstevel@tonic-gate break; 12830Sstevel@tonic-gate default: 12840Sstevel@tonic-gate uu_die(gettext("illegal element \"%s\" on restarter " 12850Sstevel@tonic-gate "element for \"%s\"\n"), cursor->name, 12860Sstevel@tonic-gate entity->sc_name); 12870Sstevel@tonic-gate break; 12880Sstevel@tonic-gate } 12890Sstevel@tonic-gate } 12900Sstevel@tonic-gate 12910Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_RESTARTER, SCF_TYPE_FMRI, 1, 12920Sstevel@tonic-gate restarter); 12930Sstevel@tonic-gate 12940Sstevel@tonic-gate r = internal_attach_property(pg, p); 12950Sstevel@tonic-gate if (r != 0) { 12960Sstevel@tonic-gate internal_property_free(p); 12970Sstevel@tonic-gate return (-1); 12980Sstevel@tonic-gate } 12990Sstevel@tonic-gate 13000Sstevel@tonic-gate return (0); 13010Sstevel@tonic-gate } 13020Sstevel@tonic-gate 13037887SLiane.Praza@Sun.COM /* 13047887SLiane.Praza@Sun.COM * Add a property containing the localized text from the manifest. The 13057887SLiane.Praza@Sun.COM * property is added to the property group at pg. The name of the created 13067887SLiane.Praza@Sun.COM * property is based on the format at pn_format. This is an snprintf(3C) 13077887SLiane.Praza@Sun.COM * format containing a single %s conversion specification. At conversion 13087887SLiane.Praza@Sun.COM * time, the %s is replaced by the locale designation. 13097887SLiane.Praza@Sun.COM * 13107887SLiane.Praza@Sun.COM * source is the source element and it is only used for error messages. 13117887SLiane.Praza@Sun.COM */ 13127887SLiane.Praza@Sun.COM static int 13137887SLiane.Praza@Sun.COM lxml_get_loctext(entity_t *service, pgroup_t *pg, xmlNodePtr loctext, 13147887SLiane.Praza@Sun.COM const char *pn_format, const char *source) 13150Sstevel@tonic-gate { 13167887SLiane.Praza@Sun.COM int extra; 13170Sstevel@tonic-gate xmlNodePtr cursor; 13180Sstevel@tonic-gate xmlChar *val; 13190Sstevel@tonic-gate char *stripped, *cp; 13200Sstevel@tonic-gate property_t *p; 13217887SLiane.Praza@Sun.COM char *prop_name; 13220Sstevel@tonic-gate int r; 13230Sstevel@tonic-gate 13247887SLiane.Praza@Sun.COM if (((val = xmlGetProp(loctext, (xmlChar *)xml_lang_attr)) == NULL) || 13257887SLiane.Praza@Sun.COM (*val == 0)) { 13267887SLiane.Praza@Sun.COM if (((val = xmlGetProp(loctext, 13277887SLiane.Praza@Sun.COM (xmlChar *)lang_attr)) == NULL) || (*val == 0)) { 13280Sstevel@tonic-gate val = (xmlChar *)"unknown"; 13297887SLiane.Praza@Sun.COM } 13307887SLiane.Praza@Sun.COM } 13317887SLiane.Praza@Sun.COM 13327887SLiane.Praza@Sun.COM _scf_sanitize_locale((char *)val); 13337887SLiane.Praza@Sun.COM prop_name = safe_malloc(max_scf_name_len + 1); 13347887SLiane.Praza@Sun.COM if ((extra = snprintf(prop_name, max_scf_name_len + 1, pn_format, 13357887SLiane.Praza@Sun.COM val)) >= max_scf_name_len + 1) { 13367887SLiane.Praza@Sun.COM extra -= max_scf_name_len; 13377887SLiane.Praza@Sun.COM uu_die(gettext("%s attribute is %d characters too long for " 13387887SLiane.Praza@Sun.COM "%s in %s\n"), 13397887SLiane.Praza@Sun.COM xml_lang_attr, extra, source, service->sc_name); 13407887SLiane.Praza@Sun.COM } 13417887SLiane.Praza@Sun.COM xmlFree(val); 13420Sstevel@tonic-gate 13430Sstevel@tonic-gate for (cursor = loctext->xmlChildrenNode; cursor != NULL; 13440Sstevel@tonic-gate cursor = cursor->next) { 13450Sstevel@tonic-gate if (strcmp("text", (const char *)cursor->name) == 0) { 13460Sstevel@tonic-gate break; 13470Sstevel@tonic-gate } else if (strcmp("comment", (const char *)cursor->name) != 0) { 13480Sstevel@tonic-gate uu_die(gettext("illegal element \"%s\" on loctext " 13490Sstevel@tonic-gate "element for \"%s\"\n"), cursor->name, 13500Sstevel@tonic-gate service->sc_name); 13510Sstevel@tonic-gate } 13520Sstevel@tonic-gate } 13530Sstevel@tonic-gate 13540Sstevel@tonic-gate if (cursor == NULL) { 13550Sstevel@tonic-gate uu_die(gettext("loctext element has no content for \"%s\"\n"), 13560Sstevel@tonic-gate service->sc_name); 13570Sstevel@tonic-gate } 13580Sstevel@tonic-gate 13590Sstevel@tonic-gate /* 13600Sstevel@tonic-gate * Remove leading and trailing whitespace. 13610Sstevel@tonic-gate */ 13620Sstevel@tonic-gate if ((stripped = strdup((const char *)cursor->content)) == NULL) 13630Sstevel@tonic-gate uu_die(gettext("Out of memory\n")); 13640Sstevel@tonic-gate 13654740Sjeanm for (; isspace(*stripped); stripped++) 13664740Sjeanm ; 13674740Sjeanm for (cp = stripped + strlen(stripped) - 1; isspace(*cp); cp--) 13684740Sjeanm ; 13690Sstevel@tonic-gate *(cp + 1) = '\0'; 13700Sstevel@tonic-gate 13717887SLiane.Praza@Sun.COM p = internal_property_create(prop_name, SCF_TYPE_USTRING, 1, 13720Sstevel@tonic-gate stripped); 13730Sstevel@tonic-gate 13740Sstevel@tonic-gate r = internal_attach_property(pg, p); 13757887SLiane.Praza@Sun.COM if (r != 0) { 13760Sstevel@tonic-gate internal_property_free(p); 13777887SLiane.Praza@Sun.COM free(prop_name); 13787887SLiane.Praza@Sun.COM } 13790Sstevel@tonic-gate 13800Sstevel@tonic-gate return (r); 13810Sstevel@tonic-gate } 13820Sstevel@tonic-gate 13837887SLiane.Praza@Sun.COM /* 13847887SLiane.Praza@Sun.COM * This function processes all loctext elements in the current XML element 13857887SLiane.Praza@Sun.COM * designated by container. A property is created for each loctext element 13867887SLiane.Praza@Sun.COM * and added to the property group at pg. The name of the property is 13877887SLiane.Praza@Sun.COM * derived from the loctext language designation using the format at 13887887SLiane.Praza@Sun.COM * pn_format. pn_format should be an snprintf format string containing one 13897887SLiane.Praza@Sun.COM * %s which is replaced by the language designation. 13907887SLiane.Praza@Sun.COM * 13917887SLiane.Praza@Sun.COM * The function returns 0 on success and -1 if it is unable to attach the 13927887SLiane.Praza@Sun.COM * newly created property to pg. 13937887SLiane.Praza@Sun.COM */ 13940Sstevel@tonic-gate static int 13957887SLiane.Praza@Sun.COM lxml_get_all_loctext(entity_t *service, pgroup_t *pg, xmlNodePtr container, 13967887SLiane.Praza@Sun.COM const char *pn_format, const char *source) 13970Sstevel@tonic-gate { 13980Sstevel@tonic-gate xmlNodePtr cursor; 13990Sstevel@tonic-gate 14000Sstevel@tonic-gate /* 14017887SLiane.Praza@Sun.COM * Iterate through one or more loctext elements. The locale is 14027887SLiane.Praza@Sun.COM * used to generate the property name; the contents are the ustring 14037887SLiane.Praza@Sun.COM * value for the property. 14040Sstevel@tonic-gate */ 14057887SLiane.Praza@Sun.COM for (cursor = container->xmlChildrenNode; cursor != NULL; 14060Sstevel@tonic-gate cursor = cursor->next) { 14070Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 14080Sstevel@tonic-gate continue; 14090Sstevel@tonic-gate 14100Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) { 14110Sstevel@tonic-gate case SC_LOCTEXT: 14127887SLiane.Praza@Sun.COM if (lxml_get_loctext(service, pg, cursor, pn_format, 14137887SLiane.Praza@Sun.COM source)) 14140Sstevel@tonic-gate return (-1); 14150Sstevel@tonic-gate break; 14160Sstevel@tonic-gate default: 14177887SLiane.Praza@Sun.COM uu_die(gettext("illegal element \"%s\" on %s element " 14187887SLiane.Praza@Sun.COM "for \"%s\"\n"), cursor->name, container->name, 14190Sstevel@tonic-gate service->sc_name); 14200Sstevel@tonic-gate break; 14210Sstevel@tonic-gate } 14220Sstevel@tonic-gate } 14230Sstevel@tonic-gate 14240Sstevel@tonic-gate return (0); 14250Sstevel@tonic-gate } 14260Sstevel@tonic-gate 14277887SLiane.Praza@Sun.COM /* 14287887SLiane.Praza@Sun.COM * Obtain the specified cardinality attribute and place it in a property 14297887SLiane.Praza@Sun.COM * named prop_name. The converted attribute is placed at *value, and the 14307887SLiane.Praza@Sun.COM * newly created property is returned to propp. NULL is returned to propp 14317887SLiane.Praza@Sun.COM * if the attribute is not provided in the manifest. 14327887SLiane.Praza@Sun.COM * 14337887SLiane.Praza@Sun.COM * 0 is returned upon success, and -1 indicates that the manifest contained 14347887SLiane.Praza@Sun.COM * an invalid cardinality value. 14357887SLiane.Praza@Sun.COM */ 14360Sstevel@tonic-gate static int 14377887SLiane.Praza@Sun.COM lxml_get_cardinality_attribute(entity_t *service, xmlNodePtr cursor, 14387887SLiane.Praza@Sun.COM const char *attr_name, const char *prop_name, uint64_t *value, 14397887SLiane.Praza@Sun.COM property_t **propp) 14407887SLiane.Praza@Sun.COM { 14417887SLiane.Praza@Sun.COM char *c; 14427887SLiane.Praza@Sun.COM property_t *p; 14437887SLiane.Praza@Sun.COM xmlChar *val; 14447887SLiane.Praza@Sun.COM uint64_t count; 14457887SLiane.Praza@Sun.COM char *endptr; 14467887SLiane.Praza@Sun.COM 14477887SLiane.Praza@Sun.COM *propp = NULL; 14487887SLiane.Praza@Sun.COM val = xmlGetProp(cursor, (xmlChar *)attr_name); 14497887SLiane.Praza@Sun.COM if (val == NULL) 14507887SLiane.Praza@Sun.COM return (0); 14517887SLiane.Praza@Sun.COM if (*val == 0) { 14527887SLiane.Praza@Sun.COM xmlFree(val); 14537887SLiane.Praza@Sun.COM return (0); 14547887SLiane.Praza@Sun.COM } 14557887SLiane.Praza@Sun.COM 14567887SLiane.Praza@Sun.COM /* 14577887SLiane.Praza@Sun.COM * Make sure that the string at val doesn't have a leading minus 14587887SLiane.Praza@Sun.COM * sign. The strtoull() call below does not catch this problem. 14597887SLiane.Praza@Sun.COM */ 14607887SLiane.Praza@Sun.COM for (c = (char *)val; *c != 0; c++) { 14617887SLiane.Praza@Sun.COM if (isspace(*c)) 14627887SLiane.Praza@Sun.COM continue; 14637887SLiane.Praza@Sun.COM if (isdigit(*c)) 14647887SLiane.Praza@Sun.COM break; 14657887SLiane.Praza@Sun.COM semerr(gettext("\"%c\" is not a legal character in the %s " 14667887SLiane.Praza@Sun.COM "attribute of the %s element in %s.\n"), *c, 14677887SLiane.Praza@Sun.COM attr_name, prop_name, service->sc_name); 14687887SLiane.Praza@Sun.COM xmlFree(val); 14697887SLiane.Praza@Sun.COM return (-1); 14707887SLiane.Praza@Sun.COM } 14717887SLiane.Praza@Sun.COM errno = 0; 14727887SLiane.Praza@Sun.COM count = strtoull((char *)val, &endptr, 10); 14737887SLiane.Praza@Sun.COM if (errno != 0 || endptr == (char *)val || *endptr) { 14747887SLiane.Praza@Sun.COM semerr(gettext("\"%s\" is not a legal number for the %s " 14757887SLiane.Praza@Sun.COM "attribute of the %s element in %s.\n"), (char *)val, 14767887SLiane.Praza@Sun.COM attr_name, prop_name, service->sc_name); 14777887SLiane.Praza@Sun.COM xmlFree(val); 14787887SLiane.Praza@Sun.COM return (-1); 14797887SLiane.Praza@Sun.COM } 14807887SLiane.Praza@Sun.COM 14817887SLiane.Praza@Sun.COM xmlFree(val); 14827887SLiane.Praza@Sun.COM 14837887SLiane.Praza@Sun.COM /* Value is valid. Create the property. */ 14847887SLiane.Praza@Sun.COM p = internal_property_create(prop_name, SCF_TYPE_COUNT, 1, count); 14857887SLiane.Praza@Sun.COM *value = count; 14867887SLiane.Praza@Sun.COM *propp = p; 14877887SLiane.Praza@Sun.COM return (0); 14887887SLiane.Praza@Sun.COM } 14897887SLiane.Praza@Sun.COM 14907887SLiane.Praza@Sun.COM /* 14917887SLiane.Praza@Sun.COM * The cardinality is specified by two attributes max and min at cursor. 14927887SLiane.Praza@Sun.COM * Both are optional, but if present they must be unsigned integers. 14937887SLiane.Praza@Sun.COM */ 14947887SLiane.Praza@Sun.COM static int 14957887SLiane.Praza@Sun.COM lxml_get_tm_cardinality(entity_t *service, pgroup_t *pg, xmlNodePtr cursor) 14960Sstevel@tonic-gate { 14977887SLiane.Praza@Sun.COM int min_attached = 0; 14987887SLiane.Praza@Sun.COM int compare = 1; 14997887SLiane.Praza@Sun.COM property_t *min_prop; 15007887SLiane.Praza@Sun.COM property_t *max_prop; 15017887SLiane.Praza@Sun.COM uint64_t max; 15027887SLiane.Praza@Sun.COM uint64_t min; 15037887SLiane.Praza@Sun.COM int r; 15047887SLiane.Praza@Sun.COM 15057887SLiane.Praza@Sun.COM r = lxml_get_cardinality_attribute(service, cursor, min_attr, 15067887SLiane.Praza@Sun.COM SCF_PROPERTY_TM_CARDINALITY_MIN, &min, &min_prop); 15077887SLiane.Praza@Sun.COM if (r != 0) 15087887SLiane.Praza@Sun.COM return (r); 15097887SLiane.Praza@Sun.COM if (min_prop == NULL) 15107887SLiane.Praza@Sun.COM compare = 0; 15117887SLiane.Praza@Sun.COM r = lxml_get_cardinality_attribute(service, cursor, max_attr, 15127887SLiane.Praza@Sun.COM SCF_PROPERTY_TM_CARDINALITY_MAX, &max, &max_prop); 15137887SLiane.Praza@Sun.COM if (r != 0) 15147887SLiane.Praza@Sun.COM goto errout; 15157887SLiane.Praza@Sun.COM if ((max_prop != NULL) && (compare == 1)) { 15167887SLiane.Praza@Sun.COM if (max < min) { 15177887SLiane.Praza@Sun.COM semerr(gettext("Cardinality max is less than min for " 15187887SLiane.Praza@Sun.COM "the %s element in %s.\n"), pg->sc_pgroup_name, 15197887SLiane.Praza@Sun.COM service->sc_fmri); 15207887SLiane.Praza@Sun.COM goto errout; 15217887SLiane.Praza@Sun.COM } 15227887SLiane.Praza@Sun.COM } 15237887SLiane.Praza@Sun.COM 15247887SLiane.Praza@Sun.COM /* Attach the properties to the property group. */ 15257887SLiane.Praza@Sun.COM if (min_prop) { 15267887SLiane.Praza@Sun.COM if (internal_attach_property(pg, min_prop) == 0) { 15277887SLiane.Praza@Sun.COM min_attached = 1; 15287887SLiane.Praza@Sun.COM } else { 15297887SLiane.Praza@Sun.COM goto errout; 15307887SLiane.Praza@Sun.COM } 15317887SLiane.Praza@Sun.COM } 15327887SLiane.Praza@Sun.COM if (max_prop) { 15337887SLiane.Praza@Sun.COM if (internal_attach_property(pg, max_prop) != 0) { 15347887SLiane.Praza@Sun.COM if (min_attached) 15357887SLiane.Praza@Sun.COM internal_detach_property(pg, min_prop); 15367887SLiane.Praza@Sun.COM goto errout; 15377887SLiane.Praza@Sun.COM } 15387887SLiane.Praza@Sun.COM } 15397887SLiane.Praza@Sun.COM return (0); 15407887SLiane.Praza@Sun.COM 15417887SLiane.Praza@Sun.COM errout: 15427887SLiane.Praza@Sun.COM if (min_prop) 15437887SLiane.Praza@Sun.COM internal_property_free(min_prop); 15447887SLiane.Praza@Sun.COM if (max_prop) 15457887SLiane.Praza@Sun.COM internal_property_free(max_prop); 15467887SLiane.Praza@Sun.COM return (-1); 15477887SLiane.Praza@Sun.COM } 15487887SLiane.Praza@Sun.COM 15497887SLiane.Praza@Sun.COM /* 15507887SLiane.Praza@Sun.COM * Get the common_name which is present as localized text at common_name in 15517887SLiane.Praza@Sun.COM * the manifest. The common_name is stored as the value of a property in 15527887SLiane.Praza@Sun.COM * the property group whose name is SCF_PG_TM_COMMON_NAME and type is 15537887SLiane.Praza@Sun.COM * SCF_GROUP_TEMPLATE. This property group will be created in service if 15547887SLiane.Praza@Sun.COM * it is not already there. 15557887SLiane.Praza@Sun.COM */ 15567887SLiane.Praza@Sun.COM static int 15577887SLiane.Praza@Sun.COM lxml_get_tm_common_name(entity_t *service, xmlNodePtr common_name) 15587887SLiane.Praza@Sun.COM { 15590Sstevel@tonic-gate pgroup_t *pg; 15600Sstevel@tonic-gate 15610Sstevel@tonic-gate /* 15620Sstevel@tonic-gate * Create the property group, if absent. 15630Sstevel@tonic-gate */ 15647887SLiane.Praza@Sun.COM pg = internal_pgroup_find_or_create(service, SCF_PG_TM_COMMON_NAME, 15657887SLiane.Praza@Sun.COM SCF_GROUP_TEMPLATE); 15667887SLiane.Praza@Sun.COM 15677887SLiane.Praza@Sun.COM return (lxml_get_all_loctext(service, pg, common_name, LOCALE_ONLY_FMT, 15687887SLiane.Praza@Sun.COM "common_name")); 15697887SLiane.Praza@Sun.COM } 15707887SLiane.Praza@Sun.COM 15717887SLiane.Praza@Sun.COM /* 15727887SLiane.Praza@Sun.COM * Get the description which is present as localized text at description in 15737887SLiane.Praza@Sun.COM * the manifest. The description is stored as the value of a property in 15747887SLiane.Praza@Sun.COM * the property group whose name is SCF_PG_TM_DESCRIPTION and type is 15757887SLiane.Praza@Sun.COM * SCF_GROUP_TEMPLATE. This property group will be created in service if 15767887SLiane.Praza@Sun.COM * it is not already there. 15777887SLiane.Praza@Sun.COM */ 15787887SLiane.Praza@Sun.COM static int 15797887SLiane.Praza@Sun.COM lxml_get_tm_description(entity_t *service, xmlNodePtr description) 15807887SLiane.Praza@Sun.COM { 15817887SLiane.Praza@Sun.COM pgroup_t *pg; 15820Sstevel@tonic-gate 15830Sstevel@tonic-gate /* 15847887SLiane.Praza@Sun.COM * Create the property group, if absent. 15850Sstevel@tonic-gate */ 15867887SLiane.Praza@Sun.COM pg = internal_pgroup_find_or_create(service, SCF_PG_TM_DESCRIPTION, 15877887SLiane.Praza@Sun.COM SCF_GROUP_TEMPLATE); 15887887SLiane.Praza@Sun.COM 15897887SLiane.Praza@Sun.COM return (lxml_get_all_loctext(service, pg, description, 15907887SLiane.Praza@Sun.COM LOCALE_ONLY_FMT, "description")); 15910Sstevel@tonic-gate } 15920Sstevel@tonic-gate 15930Sstevel@tonic-gate static char * 15940Sstevel@tonic-gate lxml_label_to_groupname(const char *prefix, const char *in) 15950Sstevel@tonic-gate { 15960Sstevel@tonic-gate char *out, *cp; 15970Sstevel@tonic-gate size_t len, piece_len; 15980Sstevel@tonic-gate 15990Sstevel@tonic-gate out = uu_zalloc(2 * scf_limit(SCF_LIMIT_MAX_NAME_LENGTH) + 1); 16000Sstevel@tonic-gate if (out == NULL) 16010Sstevel@tonic-gate return (NULL); 16020Sstevel@tonic-gate 16030Sstevel@tonic-gate (void) strcpy(out, prefix); 16040Sstevel@tonic-gate (void) strcat(out, in); 16050Sstevel@tonic-gate 16060Sstevel@tonic-gate len = strlen(out); 16070Sstevel@tonic-gate if (len > max_scf_name_len) { 16080Sstevel@tonic-gate /* Use the first half and the second half. */ 16090Sstevel@tonic-gate piece_len = (max_scf_name_len - 2) / 2; 16100Sstevel@tonic-gate 16110Sstevel@tonic-gate (void) strncpy(out + piece_len, "..", 2); 16120Sstevel@tonic-gate 16130Sstevel@tonic-gate (void) strcpy(out + piece_len + 2, out + (len - piece_len)); 16140Sstevel@tonic-gate 16150Sstevel@tonic-gate len = strlen(out); 16160Sstevel@tonic-gate } 16170Sstevel@tonic-gate 16180Sstevel@tonic-gate /* 16190Sstevel@tonic-gate * Translate non-property characters to '_'. 16200Sstevel@tonic-gate */ 16210Sstevel@tonic-gate for (cp = out; *cp != '\0'; ++cp) { 16220Sstevel@tonic-gate if (!(isalnum(*cp) || *cp == '_' || *cp == '-')) 16230Sstevel@tonic-gate *cp = '_'; 16240Sstevel@tonic-gate } 16250Sstevel@tonic-gate 16260Sstevel@tonic-gate *cp = '\0'; 16270Sstevel@tonic-gate 16280Sstevel@tonic-gate return (out); 16290Sstevel@tonic-gate } 16300Sstevel@tonic-gate 16317887SLiane.Praza@Sun.COM /* 16327887SLiane.Praza@Sun.COM * If *p is NULL, astring_prop_value() first creates a property with the 16337887SLiane.Praza@Sun.COM * name specified in prop_name. The address of the newly created property 16347887SLiane.Praza@Sun.COM * is placed in *p. 16357887SLiane.Praza@Sun.COM * 16367887SLiane.Praza@Sun.COM * In either case, newly created property or existing property, a new 16377887SLiane.Praza@Sun.COM * SCF_TYPE_ASTRING value will created and attached to the property at *p. 16387887SLiane.Praza@Sun.COM * The value of the newly created property is prop_value. 16397887SLiane.Praza@Sun.COM * 16407887SLiane.Praza@Sun.COM * free_flag is used to indicate whether or not the memory at prop_value 16417887SLiane.Praza@Sun.COM * should be freed when the property is freed by a call to 16427887SLiane.Praza@Sun.COM * internal_property_free(). 16437887SLiane.Praza@Sun.COM */ 16447887SLiane.Praza@Sun.COM static void 16457887SLiane.Praza@Sun.COM astring_prop_value(property_t **p, const char *prop_name, char *prop_value, 16467887SLiane.Praza@Sun.COM boolean_t free_flag) 16477887SLiane.Praza@Sun.COM { 16487887SLiane.Praza@Sun.COM value_t *v; 16497887SLiane.Praza@Sun.COM 16507887SLiane.Praza@Sun.COM if (*p == NULL) { 16517887SLiane.Praza@Sun.COM /* Create the property */ 16527887SLiane.Praza@Sun.COM *p = internal_property_new(); 16537887SLiane.Praza@Sun.COM (*p)->sc_property_name = (char *)prop_name; 16547887SLiane.Praza@Sun.COM (*p)->sc_value_type = SCF_TYPE_ASTRING; 16557887SLiane.Praza@Sun.COM } 16567887SLiane.Praza@Sun.COM 16577887SLiane.Praza@Sun.COM /* Add the property value to the property's list of values. */ 16587887SLiane.Praza@Sun.COM v = internal_value_new(); 16597887SLiane.Praza@Sun.COM v->sc_type = SCF_TYPE_ASTRING; 16607887SLiane.Praza@Sun.COM if (free_flag == B_TRUE) 16617887SLiane.Praza@Sun.COM v->sc_free = lxml_free_str; 16627887SLiane.Praza@Sun.COM v->sc_u.sc_string = prop_value; 16637887SLiane.Praza@Sun.COM internal_attach_value(*p, v); 16647887SLiane.Praza@Sun.COM } 16657887SLiane.Praza@Sun.COM 16667887SLiane.Praza@Sun.COM /* 16677887SLiane.Praza@Sun.COM * If p points to a null pointer, create an internal_separators property 16687887SLiane.Praza@Sun.COM * saving the address at p. For each character at seps create a property 16697887SLiane.Praza@Sun.COM * value and attach it to the property at p. 16707887SLiane.Praza@Sun.COM */ 16717887SLiane.Praza@Sun.COM static void 16727887SLiane.Praza@Sun.COM seps_to_prop_values(property_t **p, xmlChar *seps) 16737887SLiane.Praza@Sun.COM { 16747887SLiane.Praza@Sun.COM value_t *v; 16757887SLiane.Praza@Sun.COM char val_str[2]; 16767887SLiane.Praza@Sun.COM 16777887SLiane.Praza@Sun.COM if (*p == NULL) { 16787887SLiane.Praza@Sun.COM *p = internal_property_new(); 16797887SLiane.Praza@Sun.COM (*p)->sc_property_name = 16807887SLiane.Praza@Sun.COM (char *)SCF_PROPERTY_INTERNAL_SEPARATORS; 16817887SLiane.Praza@Sun.COM (*p)->sc_value_type = SCF_TYPE_ASTRING; 16827887SLiane.Praza@Sun.COM } 16837887SLiane.Praza@Sun.COM 16847887SLiane.Praza@Sun.COM /* Add the values to the property's list. */ 16857887SLiane.Praza@Sun.COM val_str[1] = 0; /* Terminate the string. */ 16867887SLiane.Praza@Sun.COM for (; *seps != 0; seps++) { 16877887SLiane.Praza@Sun.COM v = internal_value_new(); 16887887SLiane.Praza@Sun.COM v->sc_type = (*p)->sc_value_type; 16897887SLiane.Praza@Sun.COM v->sc_free = lxml_free_str; 16907887SLiane.Praza@Sun.COM val_str[0] = *seps; 16917887SLiane.Praza@Sun.COM v->sc_u.sc_string = strdup(val_str); 16927887SLiane.Praza@Sun.COM if (v->sc_u.sc_string == NULL) 16937887SLiane.Praza@Sun.COM uu_die(gettext("Out of memory\n")); 16947887SLiane.Praza@Sun.COM internal_attach_value(*p, v); 16957887SLiane.Praza@Sun.COM } 16967887SLiane.Praza@Sun.COM } 16977887SLiane.Praza@Sun.COM 16987887SLiane.Praza@Sun.COM /* 16997887SLiane.Praza@Sun.COM * Create an internal_separators property and attach it to the property 17007887SLiane.Praza@Sun.COM * group at pg. The separator characters are provided in the text nodes 17017887SLiane.Praza@Sun.COM * that are the children of seps. Each separator character is stored as a 17027887SLiane.Praza@Sun.COM * property value in the internal_separators property. 17037887SLiane.Praza@Sun.COM */ 17047887SLiane.Praza@Sun.COM static int 17057887SLiane.Praza@Sun.COM lxml_get_tm_internal_seps(entity_t *service, pgroup_t *pg, xmlNodePtr seps) 17067887SLiane.Praza@Sun.COM { 17077887SLiane.Praza@Sun.COM xmlNodePtr cursor; 17087887SLiane.Praza@Sun.COM property_t *prop = NULL; 17097887SLiane.Praza@Sun.COM int r; 17107887SLiane.Praza@Sun.COM 17117887SLiane.Praza@Sun.COM for (cursor = seps->xmlChildrenNode; cursor != NULL; 17127887SLiane.Praza@Sun.COM cursor = cursor->next) { 17137887SLiane.Praza@Sun.COM if (strcmp("text", (const char *)cursor->name) == 0) { 17147887SLiane.Praza@Sun.COM seps_to_prop_values(&prop, cursor->content); 17157887SLiane.Praza@Sun.COM } else if (strcmp("comment", (const char *)cursor->name) != 0) { 17167887SLiane.Praza@Sun.COM uu_die(gettext("illegal element \"%s\" on %s element " 17177887SLiane.Praza@Sun.COM "for \"%s\"\n"), cursor->name, seps->name, 17187887SLiane.Praza@Sun.COM service->sc_name); 17197887SLiane.Praza@Sun.COM } 17207887SLiane.Praza@Sun.COM } 17217887SLiane.Praza@Sun.COM if (prop == NULL) { 17227887SLiane.Praza@Sun.COM semerr(gettext("The %s element in %s had an empty list of " 17237887SLiane.Praza@Sun.COM "separators.\n"), (const char *)seps->name, 17247887SLiane.Praza@Sun.COM service->sc_name); 17257887SLiane.Praza@Sun.COM return (-1); 17267887SLiane.Praza@Sun.COM } 17277887SLiane.Praza@Sun.COM r = internal_attach_property(pg, prop); 17287887SLiane.Praza@Sun.COM if (r != 0) 17297887SLiane.Praza@Sun.COM internal_property_free(prop); 17307887SLiane.Praza@Sun.COM return (r); 17317887SLiane.Praza@Sun.COM } 17327887SLiane.Praza@Sun.COM 17330Sstevel@tonic-gate static int 17340Sstevel@tonic-gate lxml_get_tm_manpage(entity_t *service, xmlNodePtr manpage) 17350Sstevel@tonic-gate { 17360Sstevel@tonic-gate pgroup_t *pg; 17370Sstevel@tonic-gate char *pgname; 17380Sstevel@tonic-gate xmlChar *title; 17390Sstevel@tonic-gate 17400Sstevel@tonic-gate /* 17410Sstevel@tonic-gate * Fetch title attribute, convert to something sanitized, and create 17420Sstevel@tonic-gate * property group. 17430Sstevel@tonic-gate */ 17447887SLiane.Praza@Sun.COM title = xmlGetProp(manpage, (xmlChar *)title_attr); 17450Sstevel@tonic-gate pgname = (char *)lxml_label_to_groupname(SCF_PG_TM_MAN_PREFIX, 17460Sstevel@tonic-gate (const char *)title); 17477887SLiane.Praza@Sun.COM xmlFree(title); 17480Sstevel@tonic-gate 17490Sstevel@tonic-gate pg = internal_pgroup_find_or_create(service, pgname, 17500Sstevel@tonic-gate (char *)SCF_GROUP_TEMPLATE); 17510Sstevel@tonic-gate 17520Sstevel@tonic-gate /* 17530Sstevel@tonic-gate * Each attribute is an astring property within the group. 17540Sstevel@tonic-gate */ 17557887SLiane.Praza@Sun.COM if (new_str_prop_from_attr(pg, SCF_PROPERTY_TM_TITLE, 17567887SLiane.Praza@Sun.COM SCF_TYPE_ASTRING, manpage, title_attr) != 0 || 17577887SLiane.Praza@Sun.COM new_str_prop_from_attr(pg, SCF_PROPERTY_TM_SECTION, 17587887SLiane.Praza@Sun.COM SCF_TYPE_ASTRING, manpage, section_attr) != 0 || 17597887SLiane.Praza@Sun.COM new_str_prop_from_attr(pg, SCF_PROPERTY_TM_MANPATH, 17607887SLiane.Praza@Sun.COM SCF_TYPE_ASTRING, manpage, manpath_attr) != 0) 17610Sstevel@tonic-gate return (-1); 17620Sstevel@tonic-gate 17630Sstevel@tonic-gate return (0); 17640Sstevel@tonic-gate } 17650Sstevel@tonic-gate 17660Sstevel@tonic-gate static int 17670Sstevel@tonic-gate lxml_get_tm_doclink(entity_t *service, xmlNodePtr doc_link) 17680Sstevel@tonic-gate { 17690Sstevel@tonic-gate pgroup_t *pg; 17700Sstevel@tonic-gate char *pgname; 17710Sstevel@tonic-gate xmlChar *name; 17720Sstevel@tonic-gate 17730Sstevel@tonic-gate /* 17740Sstevel@tonic-gate * Fetch name attribute, convert name to something sanitized, and create 17750Sstevel@tonic-gate * property group. 17760Sstevel@tonic-gate */ 17777887SLiane.Praza@Sun.COM name = xmlGetProp(doc_link, (xmlChar *)name_attr); 17780Sstevel@tonic-gate 17790Sstevel@tonic-gate pgname = (char *)lxml_label_to_groupname(SCF_PG_TM_DOC_PREFIX, 17800Sstevel@tonic-gate (const char *)name); 17810Sstevel@tonic-gate 17820Sstevel@tonic-gate pg = internal_pgroup_find_or_create(service, pgname, 17830Sstevel@tonic-gate (char *)SCF_GROUP_TEMPLATE); 17847887SLiane.Praza@Sun.COM xmlFree(name); 17850Sstevel@tonic-gate 17860Sstevel@tonic-gate /* 17870Sstevel@tonic-gate * Each attribute is an astring property within the group. 17880Sstevel@tonic-gate */ 17897887SLiane.Praza@Sun.COM if (new_str_prop_from_attr(pg, SCF_PROPERTY_TM_NAME, SCF_TYPE_ASTRING, 17907887SLiane.Praza@Sun.COM doc_link, name_attr) != 0 || 17917887SLiane.Praza@Sun.COM new_str_prop_from_attr(pg, SCF_PROPERTY_TM_URI, SCF_TYPE_ASTRING, 17927887SLiane.Praza@Sun.COM doc_link, uri_attr) != 0) 17930Sstevel@tonic-gate return (-1); 17940Sstevel@tonic-gate 17950Sstevel@tonic-gate return (0); 17960Sstevel@tonic-gate } 17970Sstevel@tonic-gate 17980Sstevel@tonic-gate static int 17990Sstevel@tonic-gate lxml_get_tm_documentation(entity_t *service, xmlNodePtr documentation) 18000Sstevel@tonic-gate { 18010Sstevel@tonic-gate xmlNodePtr cursor; 18020Sstevel@tonic-gate 18030Sstevel@tonic-gate for (cursor = documentation->xmlChildrenNode; cursor != NULL; 18040Sstevel@tonic-gate cursor = cursor->next) { 18050Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 18060Sstevel@tonic-gate continue; 18070Sstevel@tonic-gate 18080Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) { 18090Sstevel@tonic-gate case SC_MANPAGE: 18100Sstevel@tonic-gate (void) lxml_get_tm_manpage(service, cursor); 18110Sstevel@tonic-gate break; 18120Sstevel@tonic-gate case SC_DOC_LINK: 18130Sstevel@tonic-gate (void) lxml_get_tm_doclink(service, cursor); 18140Sstevel@tonic-gate break; 18150Sstevel@tonic-gate default: 18160Sstevel@tonic-gate uu_die(gettext("illegal element \"%s\" on template " 18170Sstevel@tonic-gate "for service \"%s\"\n"), 18180Sstevel@tonic-gate cursor->name, service->sc_name); 18190Sstevel@tonic-gate } 18200Sstevel@tonic-gate } 18210Sstevel@tonic-gate 18220Sstevel@tonic-gate return (0); 18230Sstevel@tonic-gate } 18240Sstevel@tonic-gate 18250Sstevel@tonic-gate static int 18267887SLiane.Praza@Sun.COM lxml_get_prop_pattern_attributes(pgroup_t *pg, xmlNodePtr cursor) 18277887SLiane.Praza@Sun.COM { 18287887SLiane.Praza@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_TM_NAME, 18297887SLiane.Praza@Sun.COM SCF_TYPE_ASTRING, cursor, name_attr, NULL) != 0) { 18307887SLiane.Praza@Sun.COM return (-1); 18317887SLiane.Praza@Sun.COM } 18327887SLiane.Praza@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_TM_TYPE, 18337887SLiane.Praza@Sun.COM SCF_TYPE_ASTRING, cursor, type_attr, "") != 0) { 18347887SLiane.Praza@Sun.COM return (-1); 18357887SLiane.Praza@Sun.COM } 18367887SLiane.Praza@Sun.COM if (new_bool_prop_from_attr(pg, SCF_PROPERTY_TM_REQUIRED, cursor, 18377887SLiane.Praza@Sun.COM required_attr) != 0) 18387887SLiane.Praza@Sun.COM return (-1); 18397887SLiane.Praza@Sun.COM return (0); 18407887SLiane.Praza@Sun.COM } 18417887SLiane.Praza@Sun.COM 18427887SLiane.Praza@Sun.COM static int 18437887SLiane.Praza@Sun.COM lxml_get_tm_include_values(entity_t *service, pgroup_t *pg, 18447887SLiane.Praza@Sun.COM xmlNodePtr include_values, const char *prop_name) 18457887SLiane.Praza@Sun.COM { 18467887SLiane.Praza@Sun.COM boolean_t attach_to_pg = B_FALSE; 18477887SLiane.Praza@Sun.COM property_t *p; 18487887SLiane.Praza@Sun.COM int r = 0; 18497887SLiane.Praza@Sun.COM char *type; 18507887SLiane.Praza@Sun.COM 18517887SLiane.Praza@Sun.COM /* Get the type attribute of the include_values element. */ 18527887SLiane.Praza@Sun.COM type = (char *)xmlGetProp(include_values, (const xmlChar *)type_attr); 18537887SLiane.Praza@Sun.COM if ((type == NULL) || (*type == 0)) { 18547887SLiane.Praza@Sun.COM uu_die(gettext("%s element requires a %s attribute in the %s " 18557887SLiane.Praza@Sun.COM "service.\n"), include_values->name, type_attr, 18567887SLiane.Praza@Sun.COM service->sc_name); 18577887SLiane.Praza@Sun.COM } 18587887SLiane.Praza@Sun.COM 18597887SLiane.Praza@Sun.COM /* Add the type to the values of the prop_name property. */ 18607887SLiane.Praza@Sun.COM p = internal_property_find(pg, prop_name); 18617887SLiane.Praza@Sun.COM if (p == NULL) 18627887SLiane.Praza@Sun.COM attach_to_pg = B_TRUE; 18637887SLiane.Praza@Sun.COM astring_prop_value(&p, prop_name, type, B_FALSE); 18647887SLiane.Praza@Sun.COM if (attach_to_pg == B_TRUE) { 18657887SLiane.Praza@Sun.COM r = internal_attach_property(pg, p); 18667887SLiane.Praza@Sun.COM if (r != 0) 18677887SLiane.Praza@Sun.COM internal_property_free(p); 18687887SLiane.Praza@Sun.COM } 18697887SLiane.Praza@Sun.COM return (r); 18707887SLiane.Praza@Sun.COM } 18717887SLiane.Praza@Sun.COM 18727887SLiane.Praza@Sun.COM #define RC_MIN 0 18737887SLiane.Praza@Sun.COM #define RC_MAX 1 18747887SLiane.Praza@Sun.COM #define RC_COUNT 2 18757887SLiane.Praza@Sun.COM 18767887SLiane.Praza@Sun.COM /* 18777887SLiane.Praza@Sun.COM * Verify that the strings at min and max are valid numeric strings. Also 18787887SLiane.Praza@Sun.COM * verify that max is numerically >= min. 18797887SLiane.Praza@Sun.COM * 18807887SLiane.Praza@Sun.COM * 0 is returned if the range is valid, and -1 is returned if it is not. 18817887SLiane.Praza@Sun.COM */ 18827887SLiane.Praza@Sun.COM static int 18837887SLiane.Praza@Sun.COM verify_range(entity_t *service, xmlNodePtr range, char *min, char *max) 18847887SLiane.Praza@Sun.COM { 18857887SLiane.Praza@Sun.COM char *c; 18867887SLiane.Praza@Sun.COM int i; 18877887SLiane.Praza@Sun.COM int is_signed = 0; 18887887SLiane.Praza@Sun.COM int inverted = 0; 18897887SLiane.Praza@Sun.COM const char *limit[RC_COUNT]; 18907887SLiane.Praza@Sun.COM char *strings[RC_COUNT]; 18917887SLiane.Praza@Sun.COM uint64_t urange[RC_COUNT]; /* unsigned range. */ 18927887SLiane.Praza@Sun.COM int64_t srange[RC_COUNT]; /* signed range. */ 18937887SLiane.Praza@Sun.COM 18947887SLiane.Praza@Sun.COM strings[RC_MIN] = min; 18957887SLiane.Praza@Sun.COM strings[RC_MAX] = max; 18967887SLiane.Praza@Sun.COM limit[RC_MIN] = min_attr; 18977887SLiane.Praza@Sun.COM limit[RC_MAX] = max_attr; 18987887SLiane.Praza@Sun.COM 18997887SLiane.Praza@Sun.COM /* See if the range is signed. */ 19007887SLiane.Praza@Sun.COM for (i = 0; (i < RC_COUNT) && (is_signed == 0); i++) { 19017887SLiane.Praza@Sun.COM c = strings[i]; 19027887SLiane.Praza@Sun.COM while (isspace(*c)) { 19037887SLiane.Praza@Sun.COM c++; 19047887SLiane.Praza@Sun.COM } 19057887SLiane.Praza@Sun.COM if (*c == '-') 19067887SLiane.Praza@Sun.COM is_signed = 1; 19077887SLiane.Praza@Sun.COM } 19087887SLiane.Praza@Sun.COM 19097887SLiane.Praza@Sun.COM /* Attempt to convert the strings. */ 19107887SLiane.Praza@Sun.COM for (i = 0; i < RC_COUNT; i++) { 19117887SLiane.Praza@Sun.COM errno = 0; 19127887SLiane.Praza@Sun.COM if (is_signed) { 19137887SLiane.Praza@Sun.COM srange[i] = strtoll(strings[i], &c, 0); 19147887SLiane.Praza@Sun.COM } else { 19157887SLiane.Praza@Sun.COM urange[i] = strtoull(strings[i], &c, 0); 19167887SLiane.Praza@Sun.COM } 19177887SLiane.Praza@Sun.COM if ((errno != 0) || (c == strings[i]) || (*c != 0)) { 19187887SLiane.Praza@Sun.COM /* Conversion failed. */ 19197887SLiane.Praza@Sun.COM uu_die(gettext("Unable to convert %s for the %s " 19207887SLiane.Praza@Sun.COM "element in service %s.\n"), limit[i], 19217887SLiane.Praza@Sun.COM (char *)range->name, service->sc_name); 19227887SLiane.Praza@Sun.COM } 19237887SLiane.Praza@Sun.COM } 19247887SLiane.Praza@Sun.COM 19257887SLiane.Praza@Sun.COM /* Make sure that min is <= max */ 19267887SLiane.Praza@Sun.COM if (is_signed) { 19277887SLiane.Praza@Sun.COM if (srange[RC_MAX] < srange[RC_MIN]) 19287887SLiane.Praza@Sun.COM inverted = 1; 19297887SLiane.Praza@Sun.COM } else { 19307887SLiane.Praza@Sun.COM if (urange[RC_MAX] < urange[RC_MIN]) 19317887SLiane.Praza@Sun.COM inverted = 1; 19327887SLiane.Praza@Sun.COM } 19337887SLiane.Praza@Sun.COM if (inverted != 0) { 19347887SLiane.Praza@Sun.COM semerr(gettext("Maximum less than minimum for the %s element " 19357887SLiane.Praza@Sun.COM "in service %s.\n"), (char *)range->name, 19367887SLiane.Praza@Sun.COM service->sc_name); 19377887SLiane.Praza@Sun.COM return (-1); 19387887SLiane.Praza@Sun.COM } 19397887SLiane.Praza@Sun.COM 19407887SLiane.Praza@Sun.COM return (0); 19417887SLiane.Praza@Sun.COM } 19427887SLiane.Praza@Sun.COM 19437887SLiane.Praza@Sun.COM /* 19447887SLiane.Praza@Sun.COM * This, function creates a property named prop_name. The range element 19457887SLiane.Praza@Sun.COM * should have two attributes -- min and max. The property value then 19467887SLiane.Praza@Sun.COM * becomes the concatenation of their value separated by a comma. The 19477887SLiane.Praza@Sun.COM * property is then attached to the property group at pg. 19487887SLiane.Praza@Sun.COM * 19497887SLiane.Praza@Sun.COM * If pg already contains a property with a name of prop_name, it is only 19507887SLiane.Praza@Sun.COM * necessary to create a new value and attach it to the existing property. 19517887SLiane.Praza@Sun.COM */ 19527887SLiane.Praza@Sun.COM static int 19537887SLiane.Praza@Sun.COM lxml_get_tm_range(entity_t *service, pgroup_t *pg, xmlNodePtr range, 19547887SLiane.Praza@Sun.COM const char *prop_name) 19557887SLiane.Praza@Sun.COM { 19567887SLiane.Praza@Sun.COM boolean_t attach_to_pg = B_FALSE; 19577887SLiane.Praza@Sun.COM char *max; 19587887SLiane.Praza@Sun.COM char *min; 19597887SLiane.Praza@Sun.COM property_t *p; 19607887SLiane.Praza@Sun.COM char *prop_value; 19617887SLiane.Praza@Sun.COM int r = 0; 19627887SLiane.Praza@Sun.COM 19637887SLiane.Praza@Sun.COM /* Get max and min from the XML description. */ 19647887SLiane.Praza@Sun.COM max = (char *)xmlGetProp(range, (xmlChar *)max_attr); 19657887SLiane.Praza@Sun.COM if ((max == NULL) || (*max == 0)) { 19667887SLiane.Praza@Sun.COM uu_die(gettext("%s element is missing the %s attribute in " 19677887SLiane.Praza@Sun.COM "service %s.\n"), (char *)range->name, max_attr, 19687887SLiane.Praza@Sun.COM service->sc_name); 19697887SLiane.Praza@Sun.COM } 19707887SLiane.Praza@Sun.COM min = (char *)xmlGetProp(range, (xmlChar *)min_attr); 19717887SLiane.Praza@Sun.COM if ((min == NULL) || (*min == 0)) { 19727887SLiane.Praza@Sun.COM uu_die(gettext("%s element is missing the %s attribute in " 19737887SLiane.Praza@Sun.COM "service %s.\n"), (char *)range->name, min_attr, 19747887SLiane.Praza@Sun.COM service->sc_name); 19757887SLiane.Praza@Sun.COM } 19767887SLiane.Praza@Sun.COM if (verify_range(service, range, min, max) != 0) { 19777887SLiane.Praza@Sun.COM xmlFree(min); 19787887SLiane.Praza@Sun.COM xmlFree(max); 19797887SLiane.Praza@Sun.COM return (-1); 19807887SLiane.Praza@Sun.COM } 19817887SLiane.Praza@Sun.COM 19827887SLiane.Praza@Sun.COM /* Property value is concatenation of min and max. */ 19837887SLiane.Praza@Sun.COM prop_value = safe_malloc(max_scf_value_len + 1); 19847887SLiane.Praza@Sun.COM if (snprintf(prop_value, max_scf_value_len + 1, "%s,%s", min, max) >= 19857887SLiane.Praza@Sun.COM max_scf_value_len + 1) { 19867887SLiane.Praza@Sun.COM uu_die(gettext("min and max are too long for the %s element " 19877887SLiane.Praza@Sun.COM "of %s.\n"), (char *)range->name, service->sc_name); 19887887SLiane.Praza@Sun.COM } 19897887SLiane.Praza@Sun.COM xmlFree(min); 19907887SLiane.Praza@Sun.COM xmlFree(max); 19917887SLiane.Praza@Sun.COM 19927887SLiane.Praza@Sun.COM /* 19937887SLiane.Praza@Sun.COM * If necessary create the property and attach it to the property 19947887SLiane.Praza@Sun.COM * group. 19957887SLiane.Praza@Sun.COM */ 19967887SLiane.Praza@Sun.COM p = internal_property_find(pg, prop_name); 19977887SLiane.Praza@Sun.COM if (p == NULL) 19987887SLiane.Praza@Sun.COM attach_to_pg = B_TRUE; 19997887SLiane.Praza@Sun.COM astring_prop_value(&p, prop_name, prop_value, B_TRUE); 20007887SLiane.Praza@Sun.COM if (attach_to_pg == B_TRUE) { 20017887SLiane.Praza@Sun.COM r = internal_attach_property(pg, p); 20027887SLiane.Praza@Sun.COM if (r != 0) { 20037887SLiane.Praza@Sun.COM internal_property_free(p); 20047887SLiane.Praza@Sun.COM } 20057887SLiane.Praza@Sun.COM } 20067887SLiane.Praza@Sun.COM return (r); 20077887SLiane.Praza@Sun.COM } 20087887SLiane.Praza@Sun.COM 20097887SLiane.Praza@Sun.COM /* 20107887SLiane.Praza@Sun.COM * Determine how many plain characters are represented by count Base32 20117887SLiane.Praza@Sun.COM * encoded characters. 5 plain text characters are converted to 8 Base32 20127887SLiane.Praza@Sun.COM * characters. 20137887SLiane.Praza@Sun.COM */ 20147887SLiane.Praza@Sun.COM static size_t 20157887SLiane.Praza@Sun.COM encoded_count_to_plain(size_t count) 20167887SLiane.Praza@Sun.COM { 20177887SLiane.Praza@Sun.COM return (5 * ((count + 7) / 8)); 20187887SLiane.Praza@Sun.COM } 20197887SLiane.Praza@Sun.COM 20207887SLiane.Praza@Sun.COM /* 20217887SLiane.Praza@Sun.COM * The value element contains 0 or 1 common_name element followed by 0 or 1 20227887SLiane.Praza@Sun.COM * description element. It also has a required attribute called "name". 20237887SLiane.Praza@Sun.COM * The common_name and description are stored as property values in pg. 20247887SLiane.Praza@Sun.COM * The property names are: 20257887SLiane.Praza@Sun.COM * value_<name>_common_name_<lang> 20267887SLiane.Praza@Sun.COM * value_<name>_description_<lang> 20277887SLiane.Praza@Sun.COM * 20287887SLiane.Praza@Sun.COM * The <name> portion of the preceeding proper names requires more 20297887SLiane.Praza@Sun.COM * explanation. Ideally it would just the name attribute of this value 20307887SLiane.Praza@Sun.COM * element. Unfortunately, the name attribute can contain characters that 20317887SLiane.Praza@Sun.COM * are not legal in a property name. Thus, we base 32 encode the name 20327887SLiane.Praza@Sun.COM * attribute and use that for <name>. 20337887SLiane.Praza@Sun.COM * 20347887SLiane.Praza@Sun.COM * There are cases where the caller needs to know the name, so it is 20357887SLiane.Praza@Sun.COM * returned through the name_value pointer if it is not NULL. 20367887SLiane.Praza@Sun.COM * 20377887SLiane.Praza@Sun.COM * Parameters: 20387887SLiane.Praza@Sun.COM * service - Information about the service that is being 20397887SLiane.Praza@Sun.COM * processed. This function only uses this parameter 20407887SLiane.Praza@Sun.COM * for producing error messages. 20417887SLiane.Praza@Sun.COM * 20427887SLiane.Praza@Sun.COM * pg - The property group to receive the newly created 20437887SLiane.Praza@Sun.COM * properties. 20447887SLiane.Praza@Sun.COM * 20457887SLiane.Praza@Sun.COM * value - Pointer to the value element in the XML tree. 20467887SLiane.Praza@Sun.COM * 20477887SLiane.Praza@Sun.COM * name_value - Address to receive the value of the name attribute. 20487887SLiane.Praza@Sun.COM * The caller must free the memory. 20497887SLiane.Praza@Sun.COM */ 20507887SLiane.Praza@Sun.COM static int 20517887SLiane.Praza@Sun.COM lxml_get_tm_value_element(entity_t *service, pgroup_t *pg, xmlNodePtr value, 20527887SLiane.Praza@Sun.COM char **name_value) 20537887SLiane.Praza@Sun.COM { 20547887SLiane.Praza@Sun.COM char *common_name_fmt; 20557887SLiane.Praza@Sun.COM xmlNodePtr cursor; 20567887SLiane.Praza@Sun.COM char *description_fmt; 20577887SLiane.Praza@Sun.COM char *encoded_value = NULL; 20587887SLiane.Praza@Sun.COM size_t extra; 20597887SLiane.Praza@Sun.COM char *value_name; 20607887SLiane.Praza@Sun.COM int r = 0; 20617887SLiane.Praza@Sun.COM 20627887SLiane.Praza@Sun.COM common_name_fmt = safe_malloc(max_scf_name_len + 1); 20637887SLiane.Praza@Sun.COM description_fmt = safe_malloc(max_scf_name_len + 1); 20647887SLiane.Praza@Sun.COM 20657887SLiane.Praza@Sun.COM /* 20667887SLiane.Praza@Sun.COM * Get the value of our name attribute, so that we can use it to 20677887SLiane.Praza@Sun.COM * construct property names. 20687887SLiane.Praza@Sun.COM */ 20697887SLiane.Praza@Sun.COM value_name = (char *)xmlGetProp(value, (xmlChar *)name_attr); 20707887SLiane.Praza@Sun.COM /* The value name must be present, but it can be empty. */ 20717887SLiane.Praza@Sun.COM if (value_name == NULL) { 20727887SLiane.Praza@Sun.COM uu_die(gettext("%s element requires a %s attribute in the %s " 20737887SLiane.Praza@Sun.COM "service.\n"), (char *)value->name, name_attr, 20747887SLiane.Praza@Sun.COM service->sc_name); 20757887SLiane.Praza@Sun.COM } 20767887SLiane.Praza@Sun.COM 20777887SLiane.Praza@Sun.COM /* 20787887SLiane.Praza@Sun.COM * The value_name may contain characters that are not valid in in a 20797887SLiane.Praza@Sun.COM * property name. So we will encode value_name and then use the 20807887SLiane.Praza@Sun.COM * encoded value in the property name. 20817887SLiane.Praza@Sun.COM */ 20827887SLiane.Praza@Sun.COM encoded_value = safe_malloc(max_scf_name_len + 1); 20837887SLiane.Praza@Sun.COM if (scf_encode32(value_name, strlen(value_name), encoded_value, 20847887SLiane.Praza@Sun.COM max_scf_name_len + 1, &extra, SCF_ENCODE32_PAD) != 0) { 20857887SLiane.Praza@Sun.COM extra = encoded_count_to_plain(extra - max_scf_name_len); 20867887SLiane.Praza@Sun.COM uu_die(gettext("Constructed property name is %u characters " 20877887SLiane.Praza@Sun.COM "too long for value \"%s\" in the %s service.\n"), 20887887SLiane.Praza@Sun.COM extra, value_name, service->sc_name); 20897887SLiane.Praza@Sun.COM } 20907887SLiane.Praza@Sun.COM if ((extra = snprintf(common_name_fmt, max_scf_name_len + 1, 20917887SLiane.Praza@Sun.COM VALUE_COMMON_NAME_FMT, SCF_PROPERTY_TM_VALUE_PREFIX, 20927887SLiane.Praza@Sun.COM encoded_value)) >= max_scf_name_len + 1) { 20937887SLiane.Praza@Sun.COM extra = encoded_count_to_plain(extra - max_scf_name_len); 20947887SLiane.Praza@Sun.COM uu_die(gettext("Name attribute is " 20957887SLiane.Praza@Sun.COM "%u characters too long for %s in service %s\n"), 20967887SLiane.Praza@Sun.COM extra, (char *)value->name, service->sc_name); 20977887SLiane.Praza@Sun.COM } 20987887SLiane.Praza@Sun.COM if ((extra = snprintf(description_fmt, max_scf_name_len + 1, 20997887SLiane.Praza@Sun.COM VALUE_DESCRIPTION_FMT, SCF_PROPERTY_TM_VALUE_PREFIX, 21007887SLiane.Praza@Sun.COM encoded_value)) >= max_scf_name_len + 1) { 21017887SLiane.Praza@Sun.COM extra = encoded_count_to_plain(extra - max_scf_name_len); 21027887SLiane.Praza@Sun.COM uu_die(gettext("Name attribute is " 21037887SLiane.Praza@Sun.COM "%u characters too long for %s in service %s\n"), 21047887SLiane.Praza@Sun.COM extra, (char *)value->name, service->sc_name); 21057887SLiane.Praza@Sun.COM } 21067887SLiane.Praza@Sun.COM 21077887SLiane.Praza@Sun.COM for (cursor = value->xmlChildrenNode; 21087887SLiane.Praza@Sun.COM cursor != NULL; 21097887SLiane.Praza@Sun.COM cursor = cursor->next) { 21107887SLiane.Praza@Sun.COM if (lxml_ignorable_block(cursor)) 21117887SLiane.Praza@Sun.COM continue; 21127887SLiane.Praza@Sun.COM switch (lxml_xlate_element(cursor->name)) { 21137887SLiane.Praza@Sun.COM case SC_COMMON_NAME: 21147887SLiane.Praza@Sun.COM r = lxml_get_all_loctext(service, pg, cursor, 21157887SLiane.Praza@Sun.COM common_name_fmt, (const char *)cursor->name); 21167887SLiane.Praza@Sun.COM break; 21177887SLiane.Praza@Sun.COM case SC_DESCRIPTION: 21187887SLiane.Praza@Sun.COM r = lxml_get_all_loctext(service, pg, cursor, 21197887SLiane.Praza@Sun.COM description_fmt, (const char *)cursor->name); 21207887SLiane.Praza@Sun.COM break; 21217887SLiane.Praza@Sun.COM default: 21227887SLiane.Praza@Sun.COM uu_die(gettext("\"%s\" is an illegal element in %s " 21237887SLiane.Praza@Sun.COM "of service %s\n"), (char *)cursor->name, 21247887SLiane.Praza@Sun.COM (char *)value->name, service->sc_name); 21257887SLiane.Praza@Sun.COM } 21267887SLiane.Praza@Sun.COM if (r != 0) 21277887SLiane.Praza@Sun.COM break; 21287887SLiane.Praza@Sun.COM } 21297887SLiane.Praza@Sun.COM 21307887SLiane.Praza@Sun.COM free(description_fmt); 21317887SLiane.Praza@Sun.COM free(common_name_fmt); 21327887SLiane.Praza@Sun.COM if (r == 0) { 21337887SLiane.Praza@Sun.COM *name_value = safe_strdup(value_name); 21347887SLiane.Praza@Sun.COM } 21357887SLiane.Praza@Sun.COM xmlFree(value_name); 21367887SLiane.Praza@Sun.COM free(encoded_value); 21377887SLiane.Praza@Sun.COM return (r); 21387887SLiane.Praza@Sun.COM } 21397887SLiane.Praza@Sun.COM 21407887SLiane.Praza@Sun.COM static int 21417887SLiane.Praza@Sun.COM lxml_get_tm_choices(entity_t *service, pgroup_t *pg, xmlNodePtr choices) 21427887SLiane.Praza@Sun.COM { 21437887SLiane.Praza@Sun.COM xmlNodePtr cursor; 21447887SLiane.Praza@Sun.COM char *name_value; 21457887SLiane.Praza@Sun.COM property_t *name_prop = NULL; 21467887SLiane.Praza@Sun.COM int r = 0; 21477887SLiane.Praza@Sun.COM 21487887SLiane.Praza@Sun.COM for (cursor = choices->xmlChildrenNode; 21497887SLiane.Praza@Sun.COM (cursor != NULL) && (r == 0); 21507887SLiane.Praza@Sun.COM cursor = cursor->next) { 21517887SLiane.Praza@Sun.COM if (lxml_ignorable_block(cursor)) 21527887SLiane.Praza@Sun.COM continue; 21537887SLiane.Praza@Sun.COM switch (lxml_xlate_element(cursor->name)) { 21547887SLiane.Praza@Sun.COM case SC_INCLUDE_VALUES: 21557887SLiane.Praza@Sun.COM (void) lxml_get_tm_include_values(service, pg, cursor, 21567887SLiane.Praza@Sun.COM SCF_PROPERTY_TM_CHOICES_INCLUDE_VALUES); 21577887SLiane.Praza@Sun.COM break; 21587887SLiane.Praza@Sun.COM case SC_RANGE: 21597887SLiane.Praza@Sun.COM r = lxml_get_tm_range(service, pg, cursor, 21607887SLiane.Praza@Sun.COM SCF_PROPERTY_TM_CHOICES_RANGE); 21617887SLiane.Praza@Sun.COM if (r != 0) 21627887SLiane.Praza@Sun.COM goto out; 21637887SLiane.Praza@Sun.COM break; 21647887SLiane.Praza@Sun.COM case SC_VALUE: 21657887SLiane.Praza@Sun.COM r = lxml_get_tm_value_element(service, pg, cursor, 21667887SLiane.Praza@Sun.COM &name_value); 21677887SLiane.Praza@Sun.COM if (r == 0) { 21687887SLiane.Praza@Sun.COM /* 21697887SLiane.Praza@Sun.COM * There is no need to free the memory 21707887SLiane.Praza@Sun.COM * associated with name_value, because the 21717887SLiane.Praza@Sun.COM * property value will end up pointing to 21727887SLiane.Praza@Sun.COM * the memory. 21737887SLiane.Praza@Sun.COM */ 21747887SLiane.Praza@Sun.COM astring_prop_value(&name_prop, 21757887SLiane.Praza@Sun.COM SCF_PROPERTY_TM_CHOICES_NAME, name_value, 21767887SLiane.Praza@Sun.COM B_TRUE); 21777887SLiane.Praza@Sun.COM } else { 21787887SLiane.Praza@Sun.COM goto out; 21797887SLiane.Praza@Sun.COM } 21807887SLiane.Praza@Sun.COM break; 21817887SLiane.Praza@Sun.COM default: 21827887SLiane.Praza@Sun.COM uu_die(gettext("%s is an invalid element of " 21837887SLiane.Praza@Sun.COM "choices for service %s.\n"), cursor->name, 21847887SLiane.Praza@Sun.COM service->sc_name); 21857887SLiane.Praza@Sun.COM } 21867887SLiane.Praza@Sun.COM } 21877887SLiane.Praza@Sun.COM 21887887SLiane.Praza@Sun.COM out: 21897887SLiane.Praza@Sun.COM /* Attach the name property if we created one. */ 21907887SLiane.Praza@Sun.COM if ((r == 0) && (name_prop != NULL)) { 21917887SLiane.Praza@Sun.COM r = internal_attach_property(pg, name_prop); 21927887SLiane.Praza@Sun.COM } 21937887SLiane.Praza@Sun.COM if ((r != 0) && (name_prop != NULL)) { 21947887SLiane.Praza@Sun.COM internal_property_free(name_prop); 21957887SLiane.Praza@Sun.COM } 21967887SLiane.Praza@Sun.COM 21977887SLiane.Praza@Sun.COM return (r); 21987887SLiane.Praza@Sun.COM } 21997887SLiane.Praza@Sun.COM 22007887SLiane.Praza@Sun.COM static int 22017887SLiane.Praza@Sun.COM lxml_get_tm_constraints(entity_t *service, pgroup_t *pg, xmlNodePtr constraints) 22027887SLiane.Praza@Sun.COM { 22037887SLiane.Praza@Sun.COM xmlNodePtr cursor; 22047887SLiane.Praza@Sun.COM char *name_value; 22057887SLiane.Praza@Sun.COM property_t *name_prop = NULL; 22067887SLiane.Praza@Sun.COM int r = 0; 22077887SLiane.Praza@Sun.COM 22087887SLiane.Praza@Sun.COM for (cursor = constraints->xmlChildrenNode; 22097887SLiane.Praza@Sun.COM (cursor != NULL) && (r == 0); 22107887SLiane.Praza@Sun.COM cursor = cursor->next) { 22117887SLiane.Praza@Sun.COM if (lxml_ignorable_block(cursor)) 22127887SLiane.Praza@Sun.COM continue; 22137887SLiane.Praza@Sun.COM switch (lxml_xlate_element(cursor->name)) { 22147887SLiane.Praza@Sun.COM case SC_RANGE: 22157887SLiane.Praza@Sun.COM r = lxml_get_tm_range(service, pg, cursor, 22167887SLiane.Praza@Sun.COM SCF_PROPERTY_TM_CONSTRAINT_RANGE); 22177887SLiane.Praza@Sun.COM if (r != 0) 22187887SLiane.Praza@Sun.COM goto out; 22197887SLiane.Praza@Sun.COM break; 22207887SLiane.Praza@Sun.COM case SC_VALUE: 22217887SLiane.Praza@Sun.COM r = lxml_get_tm_value_element(service, pg, cursor, 22227887SLiane.Praza@Sun.COM &name_value); 22237887SLiane.Praza@Sun.COM if (r == 0) { 22247887SLiane.Praza@Sun.COM /* 22257887SLiane.Praza@Sun.COM * There is no need to free the memory 22267887SLiane.Praza@Sun.COM * associated with name_value, because the 22277887SLiane.Praza@Sun.COM * property value will end up pointing to 22287887SLiane.Praza@Sun.COM * the memory. 22297887SLiane.Praza@Sun.COM */ 22307887SLiane.Praza@Sun.COM astring_prop_value(&name_prop, 22317887SLiane.Praza@Sun.COM SCF_PROPERTY_TM_CONSTRAINT_NAME, name_value, 22327887SLiane.Praza@Sun.COM B_TRUE); 22337887SLiane.Praza@Sun.COM } else { 22347887SLiane.Praza@Sun.COM goto out; 22357887SLiane.Praza@Sun.COM } 22367887SLiane.Praza@Sun.COM break; 22377887SLiane.Praza@Sun.COM default: 22387887SLiane.Praza@Sun.COM uu_die(gettext("%s is an invalid element of " 22397887SLiane.Praza@Sun.COM "constraints for service %s.\n"), cursor->name, 22407887SLiane.Praza@Sun.COM service->sc_name); 22417887SLiane.Praza@Sun.COM } 22427887SLiane.Praza@Sun.COM } 22437887SLiane.Praza@Sun.COM 22447887SLiane.Praza@Sun.COM out: 22457887SLiane.Praza@Sun.COM /* Attach the name property if we created one. */ 22467887SLiane.Praza@Sun.COM if ((r == 0) && (name_prop != NULL)) { 22477887SLiane.Praza@Sun.COM r = internal_attach_property(pg, name_prop); 22487887SLiane.Praza@Sun.COM } 22497887SLiane.Praza@Sun.COM if ((r != 0) && (name_prop != NULL)) { 22507887SLiane.Praza@Sun.COM internal_property_free(name_prop); 22517887SLiane.Praza@Sun.COM } 22527887SLiane.Praza@Sun.COM 22537887SLiane.Praza@Sun.COM return (r); 22547887SLiane.Praza@Sun.COM } 22557887SLiane.Praza@Sun.COM 22567887SLiane.Praza@Sun.COM /* 22577887SLiane.Praza@Sun.COM * The values element contains one or more value elements. 22587887SLiane.Praza@Sun.COM */ 22597887SLiane.Praza@Sun.COM static int 22607887SLiane.Praza@Sun.COM lxml_get_tm_values(entity_t *service, pgroup_t *pg, xmlNodePtr values) 22617887SLiane.Praza@Sun.COM { 22627887SLiane.Praza@Sun.COM xmlNodePtr cursor; 22637887SLiane.Praza@Sun.COM char *name_value; 22647887SLiane.Praza@Sun.COM property_t *name_prop = NULL; 22657887SLiane.Praza@Sun.COM int r = 0; 22667887SLiane.Praza@Sun.COM 22677887SLiane.Praza@Sun.COM for (cursor = values->xmlChildrenNode; 22687887SLiane.Praza@Sun.COM (cursor != NULL) && (r == 0); 22697887SLiane.Praza@Sun.COM cursor = cursor->next) { 22707887SLiane.Praza@Sun.COM if (lxml_ignorable_block(cursor)) 22717887SLiane.Praza@Sun.COM continue; 22727887SLiane.Praza@Sun.COM if (lxml_xlate_element(cursor->name) != SC_VALUE) { 22737887SLiane.Praza@Sun.COM uu_die(gettext("\"%s\" is an illegal element in the " 22747887SLiane.Praza@Sun.COM "%s element of %s\n"), (char *)cursor->name, 22757887SLiane.Praza@Sun.COM (char *)values->name, service->sc_name); 22767887SLiane.Praza@Sun.COM } 22777887SLiane.Praza@Sun.COM r = lxml_get_tm_value_element(service, pg, cursor, &name_value); 22787887SLiane.Praza@Sun.COM if (r == 0) { 22797887SLiane.Praza@Sun.COM /* 22807887SLiane.Praza@Sun.COM * There is no need to free the memory 22817887SLiane.Praza@Sun.COM * associated with name_value, because the 22827887SLiane.Praza@Sun.COM * property value will end up pointing to 22837887SLiane.Praza@Sun.COM * the memory. 22847887SLiane.Praza@Sun.COM */ 22857887SLiane.Praza@Sun.COM astring_prop_value(&name_prop, 22867887SLiane.Praza@Sun.COM SCF_PROPERTY_TM_VALUES_NAME, name_value, 22877887SLiane.Praza@Sun.COM B_TRUE); 22887887SLiane.Praza@Sun.COM } 22897887SLiane.Praza@Sun.COM } 22907887SLiane.Praza@Sun.COM 22917887SLiane.Praza@Sun.COM /* Attach the name property if we created one. */ 22927887SLiane.Praza@Sun.COM if ((r == 0) && (name_prop != NULL)) { 22937887SLiane.Praza@Sun.COM r = internal_attach_property(pg, name_prop); 22947887SLiane.Praza@Sun.COM } 22957887SLiane.Praza@Sun.COM if ((r != 0) && (name_prop != NULL)) { 22967887SLiane.Praza@Sun.COM internal_property_free(name_prop); 22977887SLiane.Praza@Sun.COM } 22987887SLiane.Praza@Sun.COM 22997887SLiane.Praza@Sun.COM return (r); 23007887SLiane.Praza@Sun.COM } 23017887SLiane.Praza@Sun.COM 23027887SLiane.Praza@Sun.COM /* 23037887SLiane.Praza@Sun.COM * This function processes a prop_pattern element within a pg_pattern XML 23047887SLiane.Praza@Sun.COM * element. First it creates a property group to hold the prop_pattern 23057887SLiane.Praza@Sun.COM * information. The name of this property group is the concatenation of: 23067887SLiane.Praza@Sun.COM * - SCF_PG_TM_PROP_PATTERN_PREFIX 23077887SLiane.Praza@Sun.COM * - The unique part of the property group name of the enclosing 23087887SLiane.Praza@Sun.COM * pg_pattern. The property group name of the enclosing pg_pattern 23097887SLiane.Praza@Sun.COM * is passed to us in pgpat_name. The unique part, is the part 23107887SLiane.Praza@Sun.COM * following SCF_PG_TM_PG_PATTERN_PREFIX. 23117887SLiane.Praza@Sun.COM * - The name of this prop_pattern element. 23127887SLiane.Praza@Sun.COM * 23137887SLiane.Praza@Sun.COM * After creating the property group, the prop_pattern attributes are saved 23147887SLiane.Praza@Sun.COM * as properties in the PG. Finally, the prop_pattern elements are 23157887SLiane.Praza@Sun.COM * processed and added to the PG. 23167887SLiane.Praza@Sun.COM */ 23177887SLiane.Praza@Sun.COM static int 23187887SLiane.Praza@Sun.COM lxml_get_tm_prop_pattern(entity_t *service, xmlNodePtr prop_pattern, 23197887SLiane.Praza@Sun.COM const char *pgpat_name) 23207887SLiane.Praza@Sun.COM { 23217887SLiane.Praza@Sun.COM xmlNodePtr cursor; 23227887SLiane.Praza@Sun.COM int extra; 23237887SLiane.Praza@Sun.COM pgroup_t *pg; 23247887SLiane.Praza@Sun.COM property_t *p; 23257887SLiane.Praza@Sun.COM char *pg_name; 23267887SLiane.Praza@Sun.COM size_t prefix_len; 23277887SLiane.Praza@Sun.COM xmlChar *prop_pattern_name; 23287887SLiane.Praza@Sun.COM int r; 23297887SLiane.Praza@Sun.COM const char *unique; 23307887SLiane.Praza@Sun.COM value_t *v; 23317887SLiane.Praza@Sun.COM 23327887SLiane.Praza@Sun.COM /* Find the unique part of the pg_pattern property group name. */ 23337887SLiane.Praza@Sun.COM prefix_len = strlen(SCF_PG_TM_PG_PAT_BASE); 23347887SLiane.Praza@Sun.COM assert(strncmp(pgpat_name, SCF_PG_TM_PG_PAT_BASE, prefix_len) == 0); 23357887SLiane.Praza@Sun.COM unique = pgpat_name + prefix_len; 23367887SLiane.Praza@Sun.COM 23377887SLiane.Praza@Sun.COM /* 23387887SLiane.Praza@Sun.COM * We need to get the value of the name attribute first. The 23397887SLiane.Praza@Sun.COM * prop_pattern name as well as the name of the enclosing 23407887SLiane.Praza@Sun.COM * pg_pattern both constitute part of the name of the property 23417887SLiane.Praza@Sun.COM * group that we will create. 23427887SLiane.Praza@Sun.COM */ 23437887SLiane.Praza@Sun.COM prop_pattern_name = xmlGetProp(prop_pattern, (xmlChar *)name_attr); 23447887SLiane.Praza@Sun.COM if ((prop_pattern_name == NULL) || (*prop_pattern_name == 0)) { 23457887SLiane.Praza@Sun.COM semerr(gettext("prop_pattern name is missing for %s\n"), 23467887SLiane.Praza@Sun.COM service->sc_name); 23477887SLiane.Praza@Sun.COM return (-1); 23487887SLiane.Praza@Sun.COM } 23497887SLiane.Praza@Sun.COM if (uu_check_name((const char *)prop_pattern_name, 23507887SLiane.Praza@Sun.COM UU_NAME_DOMAIN) != 0) { 23517887SLiane.Praza@Sun.COM semerr(gettext("prop_pattern name, \"%s\", for %s is not " 23527887SLiane.Praza@Sun.COM "valid.\n"), prop_pattern_name, service->sc_name); 23537887SLiane.Praza@Sun.COM xmlFree(prop_pattern_name); 23547887SLiane.Praza@Sun.COM return (-1); 23557887SLiane.Praza@Sun.COM } 23567887SLiane.Praza@Sun.COM pg_name = safe_malloc(max_scf_name_len + 1); 23577887SLiane.Praza@Sun.COM if ((extra = snprintf(pg_name, max_scf_name_len + 1, "%s%s_%s", 23587887SLiane.Praza@Sun.COM SCF_PG_TM_PROP_PATTERN_PREFIX, unique, 23597887SLiane.Praza@Sun.COM (char *)prop_pattern_name)) >= max_scf_name_len + 1) { 23607887SLiane.Praza@Sun.COM uu_die(gettext("prop_pattern name, \"%s\", for %s is %d " 23617887SLiane.Praza@Sun.COM "characters too long\n"), (char *)prop_pattern_name, 23627887SLiane.Praza@Sun.COM service->sc_name, extra - max_scf_name_len); 23637887SLiane.Praza@Sun.COM } 23647887SLiane.Praza@Sun.COM 23657887SLiane.Praza@Sun.COM /* 23667887SLiane.Praza@Sun.COM * Create the property group, the property referencing the pg_pattern 23677887SLiane.Praza@Sun.COM * name, and add the prop_pattern attributes to the property group. 23687887SLiane.Praza@Sun.COM */ 23697887SLiane.Praza@Sun.COM pg = internal_pgroup_create_strict(service, pg_name, 23707887SLiane.Praza@Sun.COM SCF_GROUP_TEMPLATE_PROP_PATTERN); 23717887SLiane.Praza@Sun.COM if (pg == NULL) { 23727887SLiane.Praza@Sun.COM uu_die(gettext("Property group for prop_pattern, \"%s\", " 23737887SLiane.Praza@Sun.COM "already exists in %s\n"), prop_pattern_name, 23747887SLiane.Praza@Sun.COM service->sc_name); 23757887SLiane.Praza@Sun.COM } 23767887SLiane.Praza@Sun.COM 23777887SLiane.Praza@Sun.COM p = internal_property_create(SCF_PROPERTY_TM_PG_PATTERN, 23787887SLiane.Praza@Sun.COM SCF_TYPE_ASTRING, 1, safe_strdup(pgpat_name)); 23797887SLiane.Praza@Sun.COM /* 23807887SLiane.Praza@Sun.COM * Unfortunately, internal_property_create() does not set the free 23817887SLiane.Praza@Sun.COM * function for the value, so we'll set it now. 23827887SLiane.Praza@Sun.COM */ 23837887SLiane.Praza@Sun.COM v = uu_list_first(p->sc_property_values); 23847887SLiane.Praza@Sun.COM v->sc_free = lxml_free_str; 23857887SLiane.Praza@Sun.COM if (internal_attach_property(pg, p) != 0) 23867887SLiane.Praza@Sun.COM internal_property_free(p); 23877887SLiane.Praza@Sun.COM 23887887SLiane.Praza@Sun.COM 23897887SLiane.Praza@Sun.COM r = lxml_get_prop_pattern_attributes(pg, prop_pattern); 23907887SLiane.Praza@Sun.COM if (r != 0) 23917887SLiane.Praza@Sun.COM goto out; 23927887SLiane.Praza@Sun.COM 23937887SLiane.Praza@Sun.COM /* 23947887SLiane.Praza@Sun.COM * Now process the elements of prop_pattern 23957887SLiane.Praza@Sun.COM */ 23967887SLiane.Praza@Sun.COM for (cursor = prop_pattern->xmlChildrenNode; 23977887SLiane.Praza@Sun.COM cursor != NULL; 23987887SLiane.Praza@Sun.COM cursor = cursor->next) { 23997887SLiane.Praza@Sun.COM if (lxml_ignorable_block(cursor)) 24007887SLiane.Praza@Sun.COM continue; 24017887SLiane.Praza@Sun.COM 24027887SLiane.Praza@Sun.COM switch (lxml_xlate_element(cursor->name)) { 24037887SLiane.Praza@Sun.COM case SC_CARDINALITY: 24047887SLiane.Praza@Sun.COM r = lxml_get_tm_cardinality(service, pg, cursor); 24057887SLiane.Praza@Sun.COM if (r != 0) 24067887SLiane.Praza@Sun.COM goto out; 24077887SLiane.Praza@Sun.COM break; 24087887SLiane.Praza@Sun.COM case SC_CHOICES: 24097887SLiane.Praza@Sun.COM r = lxml_get_tm_choices(service, pg, cursor); 24107887SLiane.Praza@Sun.COM if (r != 0) 24117887SLiane.Praza@Sun.COM goto out; 24127887SLiane.Praza@Sun.COM break; 24137887SLiane.Praza@Sun.COM case SC_COMMON_NAME: 24147887SLiane.Praza@Sun.COM (void) lxml_get_all_loctext(service, pg, cursor, 24157887SLiane.Praza@Sun.COM COMMON_NAME_FMT, (const char *)cursor->name); 24167887SLiane.Praza@Sun.COM break; 24177887SLiane.Praza@Sun.COM case SC_CONSTRAINTS: 24187887SLiane.Praza@Sun.COM r = lxml_get_tm_constraints(service, pg, cursor); 24197887SLiane.Praza@Sun.COM if (r != 0) 24207887SLiane.Praza@Sun.COM goto out; 24217887SLiane.Praza@Sun.COM break; 24227887SLiane.Praza@Sun.COM case SC_DESCRIPTION: 24237887SLiane.Praza@Sun.COM (void) lxml_get_all_loctext(service, pg, cursor, 24247887SLiane.Praza@Sun.COM DESCRIPTION_FMT, (const char *)cursor->name); 24257887SLiane.Praza@Sun.COM break; 24267887SLiane.Praza@Sun.COM case SC_INTERNAL_SEPARATORS: 24277887SLiane.Praza@Sun.COM r = lxml_get_tm_internal_seps(service, pg, cursor); 24287887SLiane.Praza@Sun.COM if (r != 0) 24297887SLiane.Praza@Sun.COM goto out; 24307887SLiane.Praza@Sun.COM break; 24317887SLiane.Praza@Sun.COM case SC_UNITS: 24327887SLiane.Praza@Sun.COM (void) lxml_get_all_loctext(service, pg, cursor, 24337887SLiane.Praza@Sun.COM UNITS_FMT, "units"); 24347887SLiane.Praza@Sun.COM break; 24357887SLiane.Praza@Sun.COM case SC_VALUES: 24367887SLiane.Praza@Sun.COM (void) lxml_get_tm_values(service, pg, cursor); 24377887SLiane.Praza@Sun.COM break; 24387887SLiane.Praza@Sun.COM case SC_VISIBILITY: 24397887SLiane.Praza@Sun.COM /* 24407887SLiane.Praza@Sun.COM * The visibility element is empty, so we only need 24417887SLiane.Praza@Sun.COM * to proccess the value attribute. 24427887SLiane.Praza@Sun.COM */ 24437887SLiane.Praza@Sun.COM (void) new_str_prop_from_attr(pg, 24447887SLiane.Praza@Sun.COM SCF_PROPERTY_TM_VISIBILITY, SCF_TYPE_ASTRING, 24457887SLiane.Praza@Sun.COM cursor, value_attr); 24467887SLiane.Praza@Sun.COM break; 24477887SLiane.Praza@Sun.COM default: 24487887SLiane.Praza@Sun.COM uu_die(gettext("illegal element \"%s\" in prop_pattern " 24497887SLiane.Praza@Sun.COM "for service \"%s\"\n"), cursor->name, 24507887SLiane.Praza@Sun.COM service->sc_name); 24517887SLiane.Praza@Sun.COM } 24527887SLiane.Praza@Sun.COM } 24537887SLiane.Praza@Sun.COM 24547887SLiane.Praza@Sun.COM out: 24557887SLiane.Praza@Sun.COM xmlFree(prop_pattern_name); 24567887SLiane.Praza@Sun.COM free(pg_name); 24577887SLiane.Praza@Sun.COM return (r); 24587887SLiane.Praza@Sun.COM } 24597887SLiane.Praza@Sun.COM 24607887SLiane.Praza@Sun.COM /* 24617887SLiane.Praza@Sun.COM * Get the pg_pattern attributes and save them as properties in the 24627887SLiane.Praza@Sun.COM * property group at pg. The pg_pattern element accepts four attributes -- 24637887SLiane.Praza@Sun.COM * name, type, required and target. 24647887SLiane.Praza@Sun.COM */ 24657887SLiane.Praza@Sun.COM static int 24667887SLiane.Praza@Sun.COM lxml_get_pg_pattern_attributes(pgroup_t *pg, xmlNodePtr cursor) 24677887SLiane.Praza@Sun.COM { 24687887SLiane.Praza@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_TM_NAME, 24697887SLiane.Praza@Sun.COM SCF_TYPE_ASTRING, cursor, name_attr, NULL) != 0) { 24707887SLiane.Praza@Sun.COM return (-1); 24717887SLiane.Praza@Sun.COM } 24727887SLiane.Praza@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_TM_TYPE, 24737887SLiane.Praza@Sun.COM SCF_TYPE_ASTRING, cursor, type_attr, NULL) != 0) { 24747887SLiane.Praza@Sun.COM return (-1); 24757887SLiane.Praza@Sun.COM } 24767887SLiane.Praza@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_TM_TARGET, 24777887SLiane.Praza@Sun.COM SCF_TYPE_ASTRING, cursor, target_attr, NULL) != 0) { 24787887SLiane.Praza@Sun.COM return (-1); 24797887SLiane.Praza@Sun.COM } 24807887SLiane.Praza@Sun.COM if (new_bool_prop_from_attr(pg, SCF_PROPERTY_TM_REQUIRED, cursor, 24817887SLiane.Praza@Sun.COM required_attr) != 0) 24827887SLiane.Praza@Sun.COM return (-1); 24837887SLiane.Praza@Sun.COM return (0); 24847887SLiane.Praza@Sun.COM } 24857887SLiane.Praza@Sun.COM 24867887SLiane.Praza@Sun.COM /* 24877887SLiane.Praza@Sun.COM * There are several restrictions on the pg_pattern attributes that cannot 24887887SLiane.Praza@Sun.COM * be specifed in the service bundle DTD. This function verifies that 24897887SLiane.Praza@Sun.COM * those restrictions have been satisfied. The restrictions are: 24907887SLiane.Praza@Sun.COM * 24917887SLiane.Praza@Sun.COM * - The target attribute may have a value of "instance" only when the 24927887SLiane.Praza@Sun.COM * template block is in a service declaration. 24937887SLiane.Praza@Sun.COM * 24947887SLiane.Praza@Sun.COM * - The target attribute may have a value of "delegate" only when the 24957887SLiane.Praza@Sun.COM * template block applies to a restarter. 24967887SLiane.Praza@Sun.COM * 24977887SLiane.Praza@Sun.COM * - The target attribute may have a value of "all" only when the 24987887SLiane.Praza@Sun.COM * template block applies to the master restarter. 24997887SLiane.Praza@Sun.COM * 25007887SLiane.Praza@Sun.COM * The function returns 0 on success and -1 on failure. 25017887SLiane.Praza@Sun.COM */ 25027887SLiane.Praza@Sun.COM static int 25037887SLiane.Praza@Sun.COM verify_pg_pattern_attributes(entity_t *s, pgroup_t *pg) 25047887SLiane.Praza@Sun.COM { 25057887SLiane.Praza@Sun.COM int is_restarter; 25067887SLiane.Praza@Sun.COM property_t *target; 25077887SLiane.Praza@Sun.COM value_t *v; 25087887SLiane.Praza@Sun.COM 25097887SLiane.Praza@Sun.COM /* Find the value of the target property. */ 25107887SLiane.Praza@Sun.COM target = internal_property_find(pg, SCF_PROPERTY_TM_TARGET); 25117887SLiane.Praza@Sun.COM if (target == NULL) { 25127887SLiane.Praza@Sun.COM uu_die(gettext("pg_pattern is missing the %s attribute " 25137887SLiane.Praza@Sun.COM "in %s\n"), target_attr, s->sc_name); 25147887SLiane.Praza@Sun.COM return (-1); 25157887SLiane.Praza@Sun.COM } 25167887SLiane.Praza@Sun.COM v = uu_list_first(target->sc_property_values); 25177887SLiane.Praza@Sun.COM assert(v != NULL); 25187887SLiane.Praza@Sun.COM assert(v->sc_type == SCF_TYPE_ASTRING); 25197887SLiane.Praza@Sun.COM 25207887SLiane.Praza@Sun.COM /* 25217887SLiane.Praza@Sun.COM * If target has a value of instance, the template must be in a 25227887SLiane.Praza@Sun.COM * service object. 25237887SLiane.Praza@Sun.COM */ 25247887SLiane.Praza@Sun.COM if (strcmp(v->sc_u.sc_string, "instance") == 0) { 25257887SLiane.Praza@Sun.COM if (s->sc_etype != SVCCFG_SERVICE_OBJECT) { 25267887SLiane.Praza@Sun.COM uu_warn(gettext("pg_pattern %s attribute may only " 25277887SLiane.Praza@Sun.COM "have a value of \"instance\" when it is in a " 25287887SLiane.Praza@Sun.COM "service declaration.\n"), target_attr); 25297887SLiane.Praza@Sun.COM return (-1); 25307887SLiane.Praza@Sun.COM } 25317887SLiane.Praza@Sun.COM } 25327887SLiane.Praza@Sun.COM 25337887SLiane.Praza@Sun.COM /* 25347887SLiane.Praza@Sun.COM * If target has a value of "delegate", the template must be in a 25357887SLiane.Praza@Sun.COM * restarter. 25367887SLiane.Praza@Sun.COM */ 25377887SLiane.Praza@Sun.COM if (strcmp(v->sc_u.sc_string, "delegate") == 0) { 25387887SLiane.Praza@Sun.COM is_restarter = 0; 25397887SLiane.Praza@Sun.COM if ((s->sc_etype == SVCCFG_SERVICE_OBJECT) && 25407887SLiane.Praza@Sun.COM (s->sc_u.sc_service.sc_service_type == SVCCFG_RESTARTER)) { 25417887SLiane.Praza@Sun.COM is_restarter = 1; 25427887SLiane.Praza@Sun.COM } 25437887SLiane.Praza@Sun.COM if ((s->sc_etype == SVCCFG_INSTANCE_OBJECT) && 25447887SLiane.Praza@Sun.COM (s->sc_parent->sc_u.sc_service.sc_service_type == 25457887SLiane.Praza@Sun.COM SVCCFG_RESTARTER)) { 25467887SLiane.Praza@Sun.COM is_restarter = 1; 25477887SLiane.Praza@Sun.COM } 25487887SLiane.Praza@Sun.COM if (is_restarter == 0) { 25497887SLiane.Praza@Sun.COM uu_warn(gettext("pg_pattern %s attribute has a " 25507887SLiane.Praza@Sun.COM "value of \"delegate\" but is not in a " 25517887SLiane.Praza@Sun.COM "restarter service\n"), target_attr); 25527887SLiane.Praza@Sun.COM return (-1); 25537887SLiane.Praza@Sun.COM } 25547887SLiane.Praza@Sun.COM } 25557887SLiane.Praza@Sun.COM 25567887SLiane.Praza@Sun.COM /* 25577887SLiane.Praza@Sun.COM * If target has a value of "all", the template must be in the 25587887SLiane.Praza@Sun.COM * global (SCF_SERVICE_GLOBAL) service. 25597887SLiane.Praza@Sun.COM */ 25607887SLiane.Praza@Sun.COM if (strcmp(v->sc_u.sc_string, all_value) == 0) { 25617887SLiane.Praza@Sun.COM if (s->sc_etype != SVCCFG_SERVICE_OBJECT) { 25627887SLiane.Praza@Sun.COM uu_warn(gettext("pg_pattern %s attribute has a " 25637887SLiane.Praza@Sun.COM "value of \"%s\" but is not in a " 25647887SLiane.Praza@Sun.COM "service entity.\n"), target_attr, all_value); 25657887SLiane.Praza@Sun.COM return (-1); 25667887SLiane.Praza@Sun.COM } 25677887SLiane.Praza@Sun.COM if (strcmp(s->sc_fmri, SCF_SERVICE_GLOBAL) != 0) { 25687887SLiane.Praza@Sun.COM uu_warn(gettext("pg_pattern %s attribute has a " 25697887SLiane.Praza@Sun.COM "value of \"%s\" but is in the \"%s\" service. " 25707887SLiane.Praza@Sun.COM "pg_patterns with target \"%s\" are only allowed " 25717887SLiane.Praza@Sun.COM "in the global service.\n"), 25727887SLiane.Praza@Sun.COM target_attr, all_value, s->sc_fmri, all_value); 25737887SLiane.Praza@Sun.COM return (-1); 25747887SLiane.Praza@Sun.COM } 25757887SLiane.Praza@Sun.COM } 25767887SLiane.Praza@Sun.COM 25777887SLiane.Praza@Sun.COM return (0); 25787887SLiane.Praza@Sun.COM } 25797887SLiane.Praza@Sun.COM 25807887SLiane.Praza@Sun.COM static int 25817887SLiane.Praza@Sun.COM lxml_get_tm_pg_pattern(entity_t *service, xmlNodePtr pg_pattern) 25827887SLiane.Praza@Sun.COM { 25837887SLiane.Praza@Sun.COM xmlNodePtr cursor; 25847887SLiane.Praza@Sun.COM int out_len; 25857887SLiane.Praza@Sun.COM xmlChar *name; 25867887SLiane.Praza@Sun.COM pgroup_t *pg = NULL; 25877887SLiane.Praza@Sun.COM char *pg_name; 25887887SLiane.Praza@Sun.COM int r = -1; 25897887SLiane.Praza@Sun.COM xmlChar *type; 25907887SLiane.Praza@Sun.COM 25917887SLiane.Praza@Sun.COM pg_name = safe_malloc(max_scf_name_len + 1); 25927887SLiane.Praza@Sun.COM 25937887SLiane.Praza@Sun.COM /* 25947887SLiane.Praza@Sun.COM * Get the name and type attributes. Their presence or absence 25957887SLiane.Praza@Sun.COM * determines whcih prefix we will use for the property group name. 25967887SLiane.Praza@Sun.COM * There are four cases -- neither attribute is present, both are 25977887SLiane.Praza@Sun.COM * present, only name is present or only type is present. 25987887SLiane.Praza@Sun.COM */ 25997887SLiane.Praza@Sun.COM name = xmlGetProp(pg_pattern, (xmlChar *)name_attr); 26007887SLiane.Praza@Sun.COM type = xmlGetProp(pg_pattern, (xmlChar *)type_attr); 26017887SLiane.Praza@Sun.COM if ((name == NULL) || (*name == 0)) { 26027887SLiane.Praza@Sun.COM if ((type == NULL) || (*type == 0)) { 26037887SLiane.Praza@Sun.COM /* PG name contains only the prefix in this case */ 26047887SLiane.Praza@Sun.COM if (strlcpy(pg_name, SCF_PG_TM_PG_PATTERN_PREFIX, 26057887SLiane.Praza@Sun.COM max_scf_name_len + 1) >= max_scf_name_len + 1) { 26067887SLiane.Praza@Sun.COM uu_die(gettext("Unable to create pg_pattern " 26077887SLiane.Praza@Sun.COM "property for %s\n"), service->sc_name); 26087887SLiane.Praza@Sun.COM } 26097887SLiane.Praza@Sun.COM } else { 26107887SLiane.Praza@Sun.COM /* 26117887SLiane.Praza@Sun.COM * If we have a type and no name, the type becomes 26127887SLiane.Praza@Sun.COM * part of the pg_pattern property group name. 26137887SLiane.Praza@Sun.COM */ 26147887SLiane.Praza@Sun.COM if ((out_len = snprintf(pg_name, max_scf_name_len + 1, 26157887SLiane.Praza@Sun.COM "%s%s", SCF_PG_TM_PG_PATTERN_T_PREFIX, type)) >= 26167887SLiane.Praza@Sun.COM max_scf_name_len + 1) { 26177887SLiane.Praza@Sun.COM uu_die(gettext("pg_pattern type is for %s is " 26187887SLiane.Praza@Sun.COM "%d bytes too long\n"), service->sc_name, 26197887SLiane.Praza@Sun.COM out_len - max_scf_name_len); 26207887SLiane.Praza@Sun.COM } 26217887SLiane.Praza@Sun.COM } 26227887SLiane.Praza@Sun.COM } else { 26237887SLiane.Praza@Sun.COM const char *prefix; 26247887SLiane.Praza@Sun.COM 26257887SLiane.Praza@Sun.COM /* Make sure that the name is valid. */ 26267887SLiane.Praza@Sun.COM if (uu_check_name((const char *)name, UU_NAME_DOMAIN) != 0) { 26277887SLiane.Praza@Sun.COM semerr(gettext("pg_pattern name attribute, \"%s\", " 26287887SLiane.Praza@Sun.COM "for %s is invalid\n"), name, service->sc_name); 26297887SLiane.Praza@Sun.COM goto out; 26307887SLiane.Praza@Sun.COM } 26317887SLiane.Praza@Sun.COM 26327887SLiane.Praza@Sun.COM /* 26337887SLiane.Praza@Sun.COM * As long as the pg_pattern has a name, it becomes part of 26347887SLiane.Praza@Sun.COM * the name of the pg_pattern property group name. We 26357887SLiane.Praza@Sun.COM * merely need to pick the appropriate prefix. 26367887SLiane.Praza@Sun.COM */ 26377887SLiane.Praza@Sun.COM if ((type == NULL) || (*type == 0)) { 26387887SLiane.Praza@Sun.COM prefix = SCF_PG_TM_PG_PATTERN_N_PREFIX; 26397887SLiane.Praza@Sun.COM } else { 26407887SLiane.Praza@Sun.COM prefix = SCF_PG_TM_PG_PATTERN_NT_PREFIX; 26417887SLiane.Praza@Sun.COM } 26427887SLiane.Praza@Sun.COM if ((out_len = snprintf(pg_name, max_scf_name_len + 1, "%s%s", 26437887SLiane.Praza@Sun.COM prefix, name)) >= max_scf_name_len + 1) { 26447887SLiane.Praza@Sun.COM uu_die(gettext("pg_pattern property group name " 26457887SLiane.Praza@Sun.COM "for %s is %d bytes too long\n"), service->sc_name, 26467887SLiane.Praza@Sun.COM out_len - max_scf_name_len); 26477887SLiane.Praza@Sun.COM } 26487887SLiane.Praza@Sun.COM } 26497887SLiane.Praza@Sun.COM 26507887SLiane.Praza@Sun.COM /* 26517887SLiane.Praza@Sun.COM * Create the property group for holding this pg_pattern 26527887SLiane.Praza@Sun.COM * information, and capture the pg_pattern attributes. 26537887SLiane.Praza@Sun.COM */ 26547887SLiane.Praza@Sun.COM pg = internal_pgroup_create_strict(service, pg_name, 26557887SLiane.Praza@Sun.COM SCF_GROUP_TEMPLATE_PG_PATTERN); 26567887SLiane.Praza@Sun.COM if (pg == NULL) { 26577887SLiane.Praza@Sun.COM if ((name == NULL) || (*name == 0)) { 26587887SLiane.Praza@Sun.COM if ((type == NULL) ||(*type == 0)) { 26597887SLiane.Praza@Sun.COM semerr(gettext("pg_pattern with empty name and " 26607887SLiane.Praza@Sun.COM "type is not unique in %s\n"), 26617887SLiane.Praza@Sun.COM service->sc_name); 26627887SLiane.Praza@Sun.COM } else { 26637887SLiane.Praza@Sun.COM semerr(gettext("pg_pattern with empty name and " 26647887SLiane.Praza@Sun.COM "type \"%s\" is not unique in %s\n"), 26657887SLiane.Praza@Sun.COM type, service->sc_name); 26667887SLiane.Praza@Sun.COM } 26677887SLiane.Praza@Sun.COM } else { 26687887SLiane.Praza@Sun.COM if ((type == NULL) || (*type == 0)) { 26697887SLiane.Praza@Sun.COM semerr(gettext("pg_pattern with name \"%s\" " 26707887SLiane.Praza@Sun.COM "and empty type is not unique in %s\n"), 26717887SLiane.Praza@Sun.COM name, service->sc_name); 26727887SLiane.Praza@Sun.COM } else { 26737887SLiane.Praza@Sun.COM semerr(gettext("pg_pattern with name \"%s\" " 26747887SLiane.Praza@Sun.COM "and type \"%s\" is not unique in %s\n"), 26757887SLiane.Praza@Sun.COM name, type, service->sc_name); 26767887SLiane.Praza@Sun.COM } 26777887SLiane.Praza@Sun.COM } 26787887SLiane.Praza@Sun.COM goto out; 26797887SLiane.Praza@Sun.COM } 26807887SLiane.Praza@Sun.COM 26817887SLiane.Praza@Sun.COM /* 26827887SLiane.Praza@Sun.COM * Get the pg_pattern attributes from the manifest and verify 26837887SLiane.Praza@Sun.COM * that they satisfy our restrictions. 26847887SLiane.Praza@Sun.COM */ 26857887SLiane.Praza@Sun.COM r = lxml_get_pg_pattern_attributes(pg, pg_pattern); 26867887SLiane.Praza@Sun.COM if (r != 0) 26877887SLiane.Praza@Sun.COM goto out; 26887887SLiane.Praza@Sun.COM if (verify_pg_pattern_attributes(service, pg) != 0) { 26897887SLiane.Praza@Sun.COM semerr(gettext("Invalid pg_pattern attributes in %s\n"), 26907887SLiane.Praza@Sun.COM service->sc_name); 26917887SLiane.Praza@Sun.COM r = -1; 26927887SLiane.Praza@Sun.COM goto out; 26937887SLiane.Praza@Sun.COM } 26947887SLiane.Praza@Sun.COM 26957887SLiane.Praza@Sun.COM /* 26967887SLiane.Praza@Sun.COM * Now process all of the elements of pg_pattern. 26977887SLiane.Praza@Sun.COM */ 26987887SLiane.Praza@Sun.COM for (cursor = pg_pattern->xmlChildrenNode; 26997887SLiane.Praza@Sun.COM cursor != NULL; 27007887SLiane.Praza@Sun.COM cursor = cursor->next) { 27017887SLiane.Praza@Sun.COM if (lxml_ignorable_block(cursor)) 27027887SLiane.Praza@Sun.COM continue; 27037887SLiane.Praza@Sun.COM 27047887SLiane.Praza@Sun.COM switch (lxml_xlate_element(cursor->name)) { 27057887SLiane.Praza@Sun.COM case SC_COMMON_NAME: 27067887SLiane.Praza@Sun.COM (void) lxml_get_all_loctext(service, pg, cursor, 27077887SLiane.Praza@Sun.COM COMMON_NAME_FMT, (const char *)cursor->name); 27087887SLiane.Praza@Sun.COM break; 27097887SLiane.Praza@Sun.COM case SC_DESCRIPTION: 27107887SLiane.Praza@Sun.COM (void) lxml_get_all_loctext(service, pg, cursor, 27117887SLiane.Praza@Sun.COM DESCRIPTION_FMT, (const char *)cursor->name); 27127887SLiane.Praza@Sun.COM break; 27137887SLiane.Praza@Sun.COM case SC_PROP_PATTERN: 27147887SLiane.Praza@Sun.COM r = lxml_get_tm_prop_pattern(service, cursor, 27157887SLiane.Praza@Sun.COM pg_name); 27167887SLiane.Praza@Sun.COM if (r != 0) 27177887SLiane.Praza@Sun.COM goto out; 27187887SLiane.Praza@Sun.COM break; 27197887SLiane.Praza@Sun.COM default: 27207887SLiane.Praza@Sun.COM uu_die(gettext("illegal element \"%s\" in pg_pattern " 27217887SLiane.Praza@Sun.COM "for service \"%s\"\n"), cursor->name, 27227887SLiane.Praza@Sun.COM service->sc_name); 27237887SLiane.Praza@Sun.COM } 27247887SLiane.Praza@Sun.COM } 27257887SLiane.Praza@Sun.COM 27267887SLiane.Praza@Sun.COM out: 27277887SLiane.Praza@Sun.COM if ((r != 0) && (pg != NULL)) { 27287887SLiane.Praza@Sun.COM internal_detach_pgroup(service, pg); 27297887SLiane.Praza@Sun.COM internal_pgroup_free(pg); 27307887SLiane.Praza@Sun.COM } 27317887SLiane.Praza@Sun.COM free(pg_name); 27327887SLiane.Praza@Sun.COM xmlFree(name); 27337887SLiane.Praza@Sun.COM xmlFree(type); 27347887SLiane.Praza@Sun.COM 27357887SLiane.Praza@Sun.COM return (r); 27367887SLiane.Praza@Sun.COM } 27377887SLiane.Praza@Sun.COM 27387887SLiane.Praza@Sun.COM static int 27390Sstevel@tonic-gate lxml_get_template(entity_t *service, xmlNodePtr templ) 27400Sstevel@tonic-gate { 27410Sstevel@tonic-gate xmlNodePtr cursor; 27420Sstevel@tonic-gate 27430Sstevel@tonic-gate for (cursor = templ->xmlChildrenNode; cursor != NULL; 27440Sstevel@tonic-gate cursor = cursor->next) { 27450Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 27460Sstevel@tonic-gate continue; 27470Sstevel@tonic-gate 27480Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) { 27490Sstevel@tonic-gate case SC_COMMON_NAME: 27500Sstevel@tonic-gate (void) lxml_get_tm_common_name(service, cursor); 27510Sstevel@tonic-gate break; 27520Sstevel@tonic-gate case SC_DESCRIPTION: 27530Sstevel@tonic-gate (void) lxml_get_tm_description(service, cursor); 27540Sstevel@tonic-gate break; 27550Sstevel@tonic-gate case SC_DOCUMENTATION: 27560Sstevel@tonic-gate (void) lxml_get_tm_documentation(service, cursor); 27570Sstevel@tonic-gate break; 27587887SLiane.Praza@Sun.COM case SC_PG_PATTERN: 27597887SLiane.Praza@Sun.COM if (lxml_get_tm_pg_pattern(service, cursor) != 0) 27607887SLiane.Praza@Sun.COM return (-1); 27617887SLiane.Praza@Sun.COM break; 27620Sstevel@tonic-gate default: 27630Sstevel@tonic-gate uu_die(gettext("illegal element \"%s\" on template " 27640Sstevel@tonic-gate "for service \"%s\"\n"), 27650Sstevel@tonic-gate cursor->name, service->sc_name); 27660Sstevel@tonic-gate } 27670Sstevel@tonic-gate } 27680Sstevel@tonic-gate 27690Sstevel@tonic-gate return (0); 27700Sstevel@tonic-gate } 27710Sstevel@tonic-gate 27720Sstevel@tonic-gate static int 27730Sstevel@tonic-gate lxml_get_default_instance(entity_t *service, xmlNodePtr definst) 27740Sstevel@tonic-gate { 27750Sstevel@tonic-gate entity_t *i; 27760Sstevel@tonic-gate xmlChar *enabled; 27770Sstevel@tonic-gate pgroup_t *pg; 27780Sstevel@tonic-gate property_t *p; 27790Sstevel@tonic-gate char *package; 27800Sstevel@tonic-gate uint64_t enabled_val = 0; 27810Sstevel@tonic-gate 27820Sstevel@tonic-gate i = internal_instance_new("default"); 27830Sstevel@tonic-gate 27840Sstevel@tonic-gate if ((enabled = xmlGetProp(definst, (xmlChar *)enabled_attr)) != NULL) { 27850Sstevel@tonic-gate enabled_val = (strcmp(true, (const char *)enabled) == 0) ? 27860Sstevel@tonic-gate 1 : 0; 27870Sstevel@tonic-gate xmlFree(enabled); 27880Sstevel@tonic-gate } 27890Sstevel@tonic-gate 27900Sstevel@tonic-gate /* 27910Sstevel@tonic-gate * New general property group with enabled boolean property set. 27920Sstevel@tonic-gate */ 27930Sstevel@tonic-gate 27940Sstevel@tonic-gate pg = internal_pgroup_new(); 27950Sstevel@tonic-gate (void) internal_attach_pgroup(i, pg); 27960Sstevel@tonic-gate 27970Sstevel@tonic-gate pg->sc_pgroup_name = (char *)scf_pg_general; 27980Sstevel@tonic-gate pg->sc_pgroup_type = (char *)scf_group_framework; 27990Sstevel@tonic-gate pg->sc_pgroup_flags = 0; 28000Sstevel@tonic-gate 28010Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_ENABLED, SCF_TYPE_BOOLEAN, 1, 28020Sstevel@tonic-gate enabled_val); 28030Sstevel@tonic-gate 28040Sstevel@tonic-gate (void) internal_attach_property(pg, p); 28050Sstevel@tonic-gate 28060Sstevel@tonic-gate /* 28070Sstevel@tonic-gate * Add general/package property if PKGINST is set. 28080Sstevel@tonic-gate */ 28090Sstevel@tonic-gate if ((package = getenv("PKGINST")) != NULL) { 28100Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_PACKAGE, 28110Sstevel@tonic-gate SCF_TYPE_ASTRING, 1, package); 28120Sstevel@tonic-gate 28130Sstevel@tonic-gate (void) internal_attach_property(pg, p); 28140Sstevel@tonic-gate } 28150Sstevel@tonic-gate 28160Sstevel@tonic-gate return (internal_attach_entity(service, i)); 28170Sstevel@tonic-gate } 28180Sstevel@tonic-gate 28190Sstevel@tonic-gate /* 28200Sstevel@tonic-gate * Translate an instance element into an internal property tree, added to 282110029SAntonello.Cruz@Sun.COM * service. If op is SVCCFG_OP_APPLY (i.e., apply a profile), set the 282210029SAntonello.Cruz@Sun.COM * enabled property to override. 28230Sstevel@tonic-gate */ 28240Sstevel@tonic-gate static int 282510029SAntonello.Cruz@Sun.COM lxml_get_instance(entity_t *service, xmlNodePtr inst, bundle_type_t bt, 282610029SAntonello.Cruz@Sun.COM svccfg_op_t op) 28270Sstevel@tonic-gate { 28280Sstevel@tonic-gate entity_t *i; 28290Sstevel@tonic-gate pgroup_t *pg; 28300Sstevel@tonic-gate property_t *p; 28310Sstevel@tonic-gate xmlNodePtr cursor; 28320Sstevel@tonic-gate xmlChar *enabled; 283310029SAntonello.Cruz@Sun.COM int r, e_val; 28340Sstevel@tonic-gate 28350Sstevel@tonic-gate /* 28360Sstevel@tonic-gate * Fetch its attributes, as appropriate. 28370Sstevel@tonic-gate */ 28380Sstevel@tonic-gate i = internal_instance_new((char *)xmlGetProp(inst, 28390Sstevel@tonic-gate (xmlChar *)name_attr)); 28400Sstevel@tonic-gate 28410Sstevel@tonic-gate /* 28420Sstevel@tonic-gate * Note that this must be done before walking the children so that 28430Sstevel@tonic-gate * sc_fmri is set in case we enter lxml_get_dependent(). 28440Sstevel@tonic-gate */ 28450Sstevel@tonic-gate r = internal_attach_entity(service, i); 28460Sstevel@tonic-gate if (r != 0) 28470Sstevel@tonic-gate return (r); 28480Sstevel@tonic-gate 28490Sstevel@tonic-gate enabled = xmlGetProp(inst, (xmlChar *)enabled_attr); 28500Sstevel@tonic-gate 285110029SAntonello.Cruz@Sun.COM if (enabled == NULL) { 285210029SAntonello.Cruz@Sun.COM if (bt == SVCCFG_MANIFEST) { 285310029SAntonello.Cruz@Sun.COM semerr(gettext("Instance \"%s\" missing attribute " 285410029SAntonello.Cruz@Sun.COM "\"%s\".\n"), i->sc_name, enabled_attr); 285510029SAntonello.Cruz@Sun.COM return (-1); 285610029SAntonello.Cruz@Sun.COM } 285710029SAntonello.Cruz@Sun.COM } else { /* enabled != NULL */ 285810029SAntonello.Cruz@Sun.COM if (strcmp(true, (const char *)enabled) != 0 && 285910029SAntonello.Cruz@Sun.COM strcmp(false, (const char *)enabled) != 0) { 286010029SAntonello.Cruz@Sun.COM xmlFree(enabled); 286110029SAntonello.Cruz@Sun.COM semerr(gettext("Invalid enabled value\n")); 286210029SAntonello.Cruz@Sun.COM return (-1); 286310029SAntonello.Cruz@Sun.COM } 286410029SAntonello.Cruz@Sun.COM pg = internal_pgroup_new(); 286510029SAntonello.Cruz@Sun.COM (void) internal_attach_pgroup(i, pg); 286610029SAntonello.Cruz@Sun.COM 286710029SAntonello.Cruz@Sun.COM pg->sc_pgroup_name = (char *)scf_pg_general; 286810029SAntonello.Cruz@Sun.COM pg->sc_pgroup_type = (char *)scf_group_framework; 286910029SAntonello.Cruz@Sun.COM pg->sc_pgroup_flags = 0; 287010029SAntonello.Cruz@Sun.COM 287110029SAntonello.Cruz@Sun.COM e_val = (strcmp(true, (const char *)enabled) == 0); 287210029SAntonello.Cruz@Sun.COM p = internal_property_create(SCF_PROPERTY_ENABLED, 287310029SAntonello.Cruz@Sun.COM SCF_TYPE_BOOLEAN, 1, (uint64_t)e_val); 287410029SAntonello.Cruz@Sun.COM 287510029SAntonello.Cruz@Sun.COM p->sc_property_override = (op == SVCCFG_OP_APPLY); 287610029SAntonello.Cruz@Sun.COM 287710029SAntonello.Cruz@Sun.COM (void) internal_attach_property(pg, p); 287810029SAntonello.Cruz@Sun.COM 287910029SAntonello.Cruz@Sun.COM xmlFree(enabled); 288010029SAntonello.Cruz@Sun.COM } 28810Sstevel@tonic-gate 28820Sstevel@tonic-gate /* 28830Sstevel@tonic-gate * Walk its child elements, as appropriate. 28840Sstevel@tonic-gate */ 28850Sstevel@tonic-gate for (cursor = inst->xmlChildrenNode; cursor != NULL; 28860Sstevel@tonic-gate cursor = cursor->next) { 28870Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 28880Sstevel@tonic-gate continue; 28890Sstevel@tonic-gate 28900Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) { 28910Sstevel@tonic-gate case SC_RESTARTER: 28920Sstevel@tonic-gate (void) lxml_get_restarter(i, cursor); 28930Sstevel@tonic-gate break; 28940Sstevel@tonic-gate case SC_DEPENDENCY: 28950Sstevel@tonic-gate (void) lxml_get_dependency(i, cursor); 28960Sstevel@tonic-gate break; 28970Sstevel@tonic-gate case SC_DEPENDENT: 28980Sstevel@tonic-gate (void) lxml_get_dependent(i, cursor); 28990Sstevel@tonic-gate break; 29000Sstevel@tonic-gate case SC_METHOD_CONTEXT: 29010Sstevel@tonic-gate (void) lxml_get_entity_method_context(i, cursor); 29020Sstevel@tonic-gate break; 29030Sstevel@tonic-gate case SC_EXEC_METHOD: 29040Sstevel@tonic-gate (void) lxml_get_exec_method(i, cursor); 29050Sstevel@tonic-gate break; 29060Sstevel@tonic-gate case SC_PROPERTY_GROUP: 29070Sstevel@tonic-gate (void) lxml_get_pgroup(i, cursor); 29080Sstevel@tonic-gate break; 29090Sstevel@tonic-gate case SC_TEMPLATE: 29107887SLiane.Praza@Sun.COM if (lxml_get_template(i, cursor) != 0) 29117887SLiane.Praza@Sun.COM return (-1); 29120Sstevel@tonic-gate break; 29130Sstevel@tonic-gate default: 29140Sstevel@tonic-gate uu_die(gettext( 29150Sstevel@tonic-gate "illegal element \"%s\" on instance \"%s\"\n"), 29160Sstevel@tonic-gate cursor->name, i->sc_name); 29170Sstevel@tonic-gate break; 29180Sstevel@tonic-gate } 29190Sstevel@tonic-gate } 29200Sstevel@tonic-gate 29210Sstevel@tonic-gate return (0); 29220Sstevel@tonic-gate } 29230Sstevel@tonic-gate 29240Sstevel@tonic-gate /* ARGSUSED1 */ 29250Sstevel@tonic-gate static int 29260Sstevel@tonic-gate lxml_get_single_instance(entity_t *entity, xmlNodePtr si) 29270Sstevel@tonic-gate { 29280Sstevel@tonic-gate pgroup_t *pg; 29290Sstevel@tonic-gate property_t *p; 29300Sstevel@tonic-gate int r; 29310Sstevel@tonic-gate 29320Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, (char *)scf_pg_general, 29330Sstevel@tonic-gate (char *)scf_group_framework); 29340Sstevel@tonic-gate 29350Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_SINGLE_INSTANCE, 29360Sstevel@tonic-gate SCF_TYPE_BOOLEAN, 1, (uint64_t)1); 29370Sstevel@tonic-gate 29380Sstevel@tonic-gate r = internal_attach_property(pg, p); 29390Sstevel@tonic-gate if (r != 0) { 29400Sstevel@tonic-gate internal_property_free(p); 29410Sstevel@tonic-gate return (-1); 29420Sstevel@tonic-gate } 29430Sstevel@tonic-gate 29440Sstevel@tonic-gate return (0); 29450Sstevel@tonic-gate } 29460Sstevel@tonic-gate 29470Sstevel@tonic-gate /* 294811996SThomas.Whitten@Sun.COM * Check to see if the service should allow the upgrade 294911996SThomas.Whitten@Sun.COM * process to handle adding of the manifestfiles linkage. 295011996SThomas.Whitten@Sun.COM * 295111996SThomas.Whitten@Sun.COM * If the service exists and does not have a manifestfiles 295211996SThomas.Whitten@Sun.COM * property group then the upgrade process should handle 295311996SThomas.Whitten@Sun.COM * the service. 295411996SThomas.Whitten@Sun.COM * 295511996SThomas.Whitten@Sun.COM * If the service doesn't exist or the service exists 295611996SThomas.Whitten@Sun.COM * and has a manifestfiles property group then the import 295711996SThomas.Whitten@Sun.COM * process can handle the manifestfiles property group 295811996SThomas.Whitten@Sun.COM * work. 295911996SThomas.Whitten@Sun.COM * 296011996SThomas.Whitten@Sun.COM * This prevents potential cleanup of unaccounted for instances 296111996SThomas.Whitten@Sun.COM * in early manifest import due to upgrade process needing 296211996SThomas.Whitten@Sun.COM * information that has not yet been supplied by manifests 296311996SThomas.Whitten@Sun.COM * that are still located in the /var/svc manifests directory. 296411996SThomas.Whitten@Sun.COM */ 296511996SThomas.Whitten@Sun.COM static int 296611996SThomas.Whitten@Sun.COM lxml_check_upgrade(const char *service) { 296711996SThomas.Whitten@Sun.COM scf_handle_t *h = NULL; 296811996SThomas.Whitten@Sun.COM scf_scope_t *sc = NULL; 296911996SThomas.Whitten@Sun.COM scf_service_t *svc = NULL; 297011996SThomas.Whitten@Sun.COM scf_propertygroup_t *pg = NULL; 297111996SThomas.Whitten@Sun.COM int rc = SCF_FAILED; 297211996SThomas.Whitten@Sun.COM 297311996SThomas.Whitten@Sun.COM if ((h = scf_handle_create(SCF_VERSION)) == NULL || 297411996SThomas.Whitten@Sun.COM (sc = scf_scope_create(h)) == NULL || 297511996SThomas.Whitten@Sun.COM (svc = scf_service_create(h)) == NULL || 297611996SThomas.Whitten@Sun.COM (pg = scf_pg_create(h)) == NULL) 297711996SThomas.Whitten@Sun.COM goto out; 297811996SThomas.Whitten@Sun.COM 297911996SThomas.Whitten@Sun.COM if (scf_handle_bind(h) != 0) 298011996SThomas.Whitten@Sun.COM goto out; 298111996SThomas.Whitten@Sun.COM 298211996SThomas.Whitten@Sun.COM if (scf_handle_get_scope(h, SCF_FMRI_LOCAL_SCOPE, sc) == -1) 298311996SThomas.Whitten@Sun.COM goto out; 298411996SThomas.Whitten@Sun.COM 298511996SThomas.Whitten@Sun.COM if (scf_scope_get_service(sc, service, svc) != SCF_SUCCESS) { 298611996SThomas.Whitten@Sun.COM if (scf_error() == SCF_ERROR_NOT_FOUND) 298711996SThomas.Whitten@Sun.COM rc = SCF_SUCCESS; 298811996SThomas.Whitten@Sun.COM 298911996SThomas.Whitten@Sun.COM goto out; 299011996SThomas.Whitten@Sun.COM } 299111996SThomas.Whitten@Sun.COM 299211996SThomas.Whitten@Sun.COM if (scf_service_get_pg(svc, SCF_PG_MANIFESTFILES, pg) != SCF_SUCCESS) 299311996SThomas.Whitten@Sun.COM goto out; 299411996SThomas.Whitten@Sun.COM 299511996SThomas.Whitten@Sun.COM rc = SCF_SUCCESS; 299611996SThomas.Whitten@Sun.COM out: 299711996SThomas.Whitten@Sun.COM scf_pg_destroy(pg); 299811996SThomas.Whitten@Sun.COM scf_service_destroy(svc); 299911996SThomas.Whitten@Sun.COM scf_scope_destroy(sc); 300011996SThomas.Whitten@Sun.COM scf_handle_destroy(h); 300111996SThomas.Whitten@Sun.COM 300211996SThomas.Whitten@Sun.COM return (rc); 300311996SThomas.Whitten@Sun.COM } 300411996SThomas.Whitten@Sun.COM 300511996SThomas.Whitten@Sun.COM /* 30060Sstevel@tonic-gate * Translate a service element into an internal instance/property tree, added 30075040Swesolows * to bundle. If op is SVCCFG_OP_APPLY, allow only instance subelements. 30080Sstevel@tonic-gate */ 30090Sstevel@tonic-gate static int 30105040Swesolows lxml_get_service(bundle_t *bundle, xmlNodePtr svc, svccfg_op_t op) 30110Sstevel@tonic-gate { 301210461SSean.Wilcox@Sun.COM pgroup_t *pg; 301310461SSean.Wilcox@Sun.COM property_t *p; 30140Sstevel@tonic-gate entity_t *s; 30150Sstevel@tonic-gate xmlNodePtr cursor; 30160Sstevel@tonic-gate xmlChar *type; 30170Sstevel@tonic-gate xmlChar *version; 30180Sstevel@tonic-gate int e; 30190Sstevel@tonic-gate 30200Sstevel@tonic-gate /* 30210Sstevel@tonic-gate * Fetch attributes, as appropriate. 30220Sstevel@tonic-gate */ 30230Sstevel@tonic-gate s = internal_service_new((char *)xmlGetProp(svc, 30240Sstevel@tonic-gate (xmlChar *)name_attr)); 30250Sstevel@tonic-gate 30267887SLiane.Praza@Sun.COM version = xmlGetProp(svc, (xmlChar *)version_attr); 30270Sstevel@tonic-gate s->sc_u.sc_service.sc_service_version = atol((const char *)version); 30280Sstevel@tonic-gate xmlFree(version); 30290Sstevel@tonic-gate 30300Sstevel@tonic-gate type = xmlGetProp(svc, (xmlChar *)type_attr); 30310Sstevel@tonic-gate s->sc_u.sc_service.sc_service_type = lxml_xlate_service_type(type); 30320Sstevel@tonic-gate xmlFree(type); 30330Sstevel@tonic-gate 30340Sstevel@tonic-gate /* 303510461SSean.Wilcox@Sun.COM * Now that the service is created create the manifest 303610461SSean.Wilcox@Sun.COM * property group and add the property value of the service. 303710461SSean.Wilcox@Sun.COM */ 303811996SThomas.Whitten@Sun.COM if (lxml_check_upgrade(s->sc_name) == SCF_SUCCESS && 303911996SThomas.Whitten@Sun.COM svc->doc->name != NULL && 304010461SSean.Wilcox@Sun.COM bundle->sc_bundle_type == SVCCFG_MANIFEST) { 3041*12172SSean.Wilcox@Sun.COM char *buf, *base, *fname, *bname; 3042*12172SSean.Wilcox@Sun.COM size_t base_sz = 0; 3043*12172SSean.Wilcox@Sun.COM 3044*12172SSean.Wilcox@Sun.COM /* 3045*12172SSean.Wilcox@Sun.COM * Must remove the PKG_INSTALL_ROOT, point to the correct 3046*12172SSean.Wilcox@Sun.COM * directory after install 3047*12172SSean.Wilcox@Sun.COM */ 3048*12172SSean.Wilcox@Sun.COM bname = uu_zalloc(PATH_MAX + 1); 3049*12172SSean.Wilcox@Sun.COM if (realpath(svc->doc->name, bname) == NULL) { 3050*12172SSean.Wilcox@Sun.COM uu_die(gettext("Unable to create the real path of the " 3051*12172SSean.Wilcox@Sun.COM "manifest file \"%s\" : %d\n"), svc->doc->name, 3052*12172SSean.Wilcox@Sun.COM errno); 3053*12172SSean.Wilcox@Sun.COM } 3054*12172SSean.Wilcox@Sun.COM 3055*12172SSean.Wilcox@Sun.COM base = getenv("PKG_INSTALL_ROOT"); 3056*12172SSean.Wilcox@Sun.COM if (base != NULL && strncmp(bname, base, strlen(base)) == 0) { 3057*12172SSean.Wilcox@Sun.COM base_sz = strlen(base); 3058*12172SSean.Wilcox@Sun.COM } 3059*12172SSean.Wilcox@Sun.COM fname = safe_strdup(bname + base_sz); 3060*12172SSean.Wilcox@Sun.COM 3061*12172SSean.Wilcox@Sun.COM uu_free(bname); 3062*12172SSean.Wilcox@Sun.COM buf = mhash_filename_to_propname(svc->doc->name, B_FALSE); 306310461SSean.Wilcox@Sun.COM 306410461SSean.Wilcox@Sun.COM pg = internal_pgroup_create_strict(s, SCF_PG_MANIFESTFILES, 306510461SSean.Wilcox@Sun.COM SCF_GROUP_FRAMEWORK); 306610461SSean.Wilcox@Sun.COM 306710461SSean.Wilcox@Sun.COM if (pg == NULL) { 306810461SSean.Wilcox@Sun.COM uu_die(gettext("Property group for prop_pattern, " 306910461SSean.Wilcox@Sun.COM "\"%s\", already exists in %s\n"), 307010461SSean.Wilcox@Sun.COM SCF_PG_MANIFESTFILES, s->sc_name); 307110461SSean.Wilcox@Sun.COM } 307210461SSean.Wilcox@Sun.COM 307310461SSean.Wilcox@Sun.COM p = internal_property_create(buf, SCF_TYPE_ASTRING, 1, fname); 307410461SSean.Wilcox@Sun.COM 307510461SSean.Wilcox@Sun.COM (void) internal_attach_property(pg, p); 307610461SSean.Wilcox@Sun.COM } 307710461SSean.Wilcox@Sun.COM 307810461SSean.Wilcox@Sun.COM /* 30790Sstevel@tonic-gate * Walk its child elements, as appropriate. 30800Sstevel@tonic-gate */ 30810Sstevel@tonic-gate for (cursor = svc->xmlChildrenNode; cursor != NULL; 30820Sstevel@tonic-gate cursor = cursor->next) { 30830Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 30840Sstevel@tonic-gate continue; 30850Sstevel@tonic-gate 30860Sstevel@tonic-gate e = lxml_xlate_element(cursor->name); 30870Sstevel@tonic-gate 30880Sstevel@tonic-gate switch (e) { 30890Sstevel@tonic-gate case SC_INSTANCE: 309010029SAntonello.Cruz@Sun.COM if (lxml_get_instance(s, cursor, 309110029SAntonello.Cruz@Sun.COM bundle->sc_bundle_type, op) != 0) 30927887SLiane.Praza@Sun.COM return (-1); 30930Sstevel@tonic-gate break; 30940Sstevel@tonic-gate case SC_TEMPLATE: 30957887SLiane.Praza@Sun.COM if (lxml_get_template(s, cursor) != 0) 30967887SLiane.Praza@Sun.COM return (-1); 30970Sstevel@tonic-gate break; 30980Sstevel@tonic-gate case SC_STABILITY: 30990Sstevel@tonic-gate (void) lxml_get_entity_stability(s, cursor); 31000Sstevel@tonic-gate break; 31010Sstevel@tonic-gate case SC_DEPENDENCY: 31020Sstevel@tonic-gate (void) lxml_get_dependency(s, cursor); 31030Sstevel@tonic-gate break; 31040Sstevel@tonic-gate case SC_DEPENDENT: 31050Sstevel@tonic-gate (void) lxml_get_dependent(s, cursor); 31060Sstevel@tonic-gate break; 31070Sstevel@tonic-gate case SC_RESTARTER: 31080Sstevel@tonic-gate (void) lxml_get_restarter(s, cursor); 31090Sstevel@tonic-gate break; 31100Sstevel@tonic-gate case SC_EXEC_METHOD: 31110Sstevel@tonic-gate (void) lxml_get_exec_method(s, cursor); 31120Sstevel@tonic-gate break; 31130Sstevel@tonic-gate case SC_METHOD_CONTEXT: 31140Sstevel@tonic-gate (void) lxml_get_entity_method_context(s, cursor); 31150Sstevel@tonic-gate break; 31160Sstevel@tonic-gate case SC_PROPERTY_GROUP: 31170Sstevel@tonic-gate (void) lxml_get_pgroup(s, cursor); 31180Sstevel@tonic-gate break; 31190Sstevel@tonic-gate case SC_INSTANCE_CREATE_DEFAULT: 31200Sstevel@tonic-gate (void) lxml_get_default_instance(s, cursor); 31210Sstevel@tonic-gate break; 31220Sstevel@tonic-gate case SC_INSTANCE_SINGLE: 31230Sstevel@tonic-gate (void) lxml_get_single_instance(s, cursor); 31240Sstevel@tonic-gate break; 31250Sstevel@tonic-gate default: 31260Sstevel@tonic-gate uu_die(gettext( 31270Sstevel@tonic-gate "illegal element \"%s\" on service \"%s\"\n"), 31280Sstevel@tonic-gate cursor->name, s->sc_name); 31290Sstevel@tonic-gate break; 31300Sstevel@tonic-gate } 31310Sstevel@tonic-gate } 31320Sstevel@tonic-gate 31330Sstevel@tonic-gate return (internal_attach_service(bundle, s)); 31340Sstevel@tonic-gate } 31350Sstevel@tonic-gate 31360Sstevel@tonic-gate #ifdef DEBUG 31370Sstevel@tonic-gate void 31380Sstevel@tonic-gate lxml_dump(int g, xmlNodePtr p) 31390Sstevel@tonic-gate { 31400Sstevel@tonic-gate if (p && p->name) { 31410Sstevel@tonic-gate printf("%d %s\n", g, p->name); 31420Sstevel@tonic-gate 31430Sstevel@tonic-gate for (p = p->xmlChildrenNode; p != NULL; p = p->next) 31440Sstevel@tonic-gate lxml_dump(g + 1, p); 31450Sstevel@tonic-gate } 31460Sstevel@tonic-gate } 31470Sstevel@tonic-gate #endif /* DEBUG */ 31480Sstevel@tonic-gate 31490Sstevel@tonic-gate static int 31500Sstevel@tonic-gate lxml_is_known_dtd(const xmlChar *dtdname) 31510Sstevel@tonic-gate { 31520Sstevel@tonic-gate if (dtdname == NULL || 31530Sstevel@tonic-gate strcmp(MANIFEST_DTD_PATH, (const char *)dtdname) != 0) 31540Sstevel@tonic-gate return (0); 31550Sstevel@tonic-gate 31560Sstevel@tonic-gate return (1); 31570Sstevel@tonic-gate } 31580Sstevel@tonic-gate 31590Sstevel@tonic-gate static int 31600Sstevel@tonic-gate lxml_get_bundle(bundle_t *bundle, bundle_type_t bundle_type, 31615040Swesolows xmlNodePtr subbundle, svccfg_op_t op) 31620Sstevel@tonic-gate { 31630Sstevel@tonic-gate xmlNodePtr cursor; 31640Sstevel@tonic-gate xmlChar *type; 31650Sstevel@tonic-gate int e; 31660Sstevel@tonic-gate 31670Sstevel@tonic-gate /* 31680Sstevel@tonic-gate * 1. Get bundle attributes. 31690Sstevel@tonic-gate */ 31707887SLiane.Praza@Sun.COM type = xmlGetProp(subbundle, (xmlChar *)type_attr); 31710Sstevel@tonic-gate bundle->sc_bundle_type = lxml_xlate_bundle_type(type); 31720Sstevel@tonic-gate if (bundle->sc_bundle_type != bundle_type && 31730Sstevel@tonic-gate bundle_type != SVCCFG_UNKNOWN_BUNDLE) { 31740Sstevel@tonic-gate semerr(gettext("included bundle of different type.\n")); 31750Sstevel@tonic-gate return (-1); 31760Sstevel@tonic-gate } 31770Sstevel@tonic-gate 31780Sstevel@tonic-gate xmlFree(type); 31790Sstevel@tonic-gate 31805040Swesolows switch (op) { 31815040Swesolows case SVCCFG_OP_IMPORT: 31820Sstevel@tonic-gate if (bundle->sc_bundle_type != SVCCFG_MANIFEST) { 31830Sstevel@tonic-gate semerr(gettext("document is not a manifest.\n")); 31840Sstevel@tonic-gate return (-1); 31850Sstevel@tonic-gate } 31865040Swesolows break; 31875040Swesolows case SVCCFG_OP_APPLY: 31880Sstevel@tonic-gate if (bundle->sc_bundle_type != SVCCFG_PROFILE) { 31890Sstevel@tonic-gate semerr(gettext("document is not a profile.\n")); 31900Sstevel@tonic-gate return (-1); 31910Sstevel@tonic-gate } 31925040Swesolows break; 31935040Swesolows case SVCCFG_OP_RESTORE: 31945040Swesolows if (bundle->sc_bundle_type != SVCCFG_ARCHIVE) { 31955040Swesolows semerr(gettext("document is not an archive.\n")); 31965040Swesolows return (-1); 31975040Swesolows } 31985040Swesolows break; 31990Sstevel@tonic-gate } 32000Sstevel@tonic-gate 32017887SLiane.Praza@Sun.COM if (((bundle->sc_bundle_name = xmlGetProp(subbundle, 32027887SLiane.Praza@Sun.COM (xmlChar *)name_attr)) == NULL) || (*bundle->sc_bundle_name == 0)) { 32030Sstevel@tonic-gate semerr(gettext("service bundle lacks name attribute\n")); 32040Sstevel@tonic-gate return (-1); 32050Sstevel@tonic-gate } 32060Sstevel@tonic-gate 32070Sstevel@tonic-gate /* 32080Sstevel@tonic-gate * 2. Get services, descend into each one and build state. 32090Sstevel@tonic-gate */ 32100Sstevel@tonic-gate for (cursor = subbundle->xmlChildrenNode; cursor != NULL; 32110Sstevel@tonic-gate cursor = cursor->next) { 32120Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 32130Sstevel@tonic-gate continue; 32140Sstevel@tonic-gate 32150Sstevel@tonic-gate e = lxml_xlate_element(cursor->name); 32160Sstevel@tonic-gate 32170Sstevel@tonic-gate switch (e) { 32180Sstevel@tonic-gate case SC_XI_INCLUDE: 32190Sstevel@tonic-gate continue; 32200Sstevel@tonic-gate 32210Sstevel@tonic-gate case SC_SERVICE_BUNDLE: 32225040Swesolows if (lxml_get_bundle(bundle, bundle_type, cursor, op)) 32230Sstevel@tonic-gate return (-1); 32240Sstevel@tonic-gate break; 32250Sstevel@tonic-gate case SC_SERVICE: 32267887SLiane.Praza@Sun.COM if (lxml_get_service(bundle, cursor, op) != 0) 32277887SLiane.Praza@Sun.COM return (-1); 32280Sstevel@tonic-gate break; 32290Sstevel@tonic-gate } 32300Sstevel@tonic-gate } 32310Sstevel@tonic-gate 32320Sstevel@tonic-gate return (0); 32330Sstevel@tonic-gate } 32340Sstevel@tonic-gate 32350Sstevel@tonic-gate /* 32360Sstevel@tonic-gate * Load an XML tree from filename and translate it into an internal service 32375040Swesolows * tree bundle. Require that the bundle be of appropriate type for the 32385040Swesolows * operation: archive for RESTORE, manifest for IMPORT, profile for APPLY. 32390Sstevel@tonic-gate */ 32400Sstevel@tonic-gate int 32415040Swesolows lxml_get_bundle_file(bundle_t *bundle, const char *filename, svccfg_op_t op) 32420Sstevel@tonic-gate { 32430Sstevel@tonic-gate xmlDocPtr document; 32440Sstevel@tonic-gate xmlNodePtr cursor; 32450Sstevel@tonic-gate xmlDtdPtr dtd = NULL; 32460Sstevel@tonic-gate xmlValidCtxtPtr vcp; 32470Sstevel@tonic-gate boolean_t do_validate; 32480Sstevel@tonic-gate char *dtdpath = NULL; 32490Sstevel@tonic-gate int r; 32500Sstevel@tonic-gate 32510Sstevel@tonic-gate /* 32524740Sjeanm * Verify we can read the file before we try to parse it. 32534740Sjeanm */ 32544740Sjeanm if (access(filename, R_OK | F_OK) == -1) { 32554740Sjeanm semerr(gettext("unable to open file: %s\n"), strerror(errno)); 32564740Sjeanm return (-1); 32574740Sjeanm } 32584740Sjeanm 32594740Sjeanm /* 32600Sstevel@tonic-gate * Until libxml2 addresses DTD-based validation with XInclude, we don't 32610Sstevel@tonic-gate * validate service profiles (i.e. the apply path). 32620Sstevel@tonic-gate */ 32635040Swesolows do_validate = (op != SVCCFG_OP_APPLY) && 32645040Swesolows (getenv("SVCCFG_NOVALIDATE") == NULL); 32650Sstevel@tonic-gate if (do_validate) 32660Sstevel@tonic-gate dtdpath = getenv("SVCCFG_DTD"); 32670Sstevel@tonic-gate 32680Sstevel@tonic-gate if (dtdpath != NULL) 32690Sstevel@tonic-gate xmlLoadExtDtdDefaultValue = 0; 32700Sstevel@tonic-gate 32714740Sjeanm if ((document = xmlReadFile(filename, NULL, 0)) == NULL) { 32720Sstevel@tonic-gate semerr(gettext("couldn't parse document\n")); 32730Sstevel@tonic-gate return (-1); 32740Sstevel@tonic-gate } 32750Sstevel@tonic-gate 327610461SSean.Wilcox@Sun.COM document->name = strdup(filename); 327710461SSean.Wilcox@Sun.COM 32780Sstevel@tonic-gate /* 32790Sstevel@tonic-gate * Verify that this is a document type we understand. 32800Sstevel@tonic-gate */ 32810Sstevel@tonic-gate if ((dtd = xmlGetIntSubset(document)) == NULL) { 32820Sstevel@tonic-gate semerr(gettext("document has no DTD\n")); 32830Sstevel@tonic-gate return (-1); 32840Sstevel@tonic-gate } 32850Sstevel@tonic-gate 32860Sstevel@tonic-gate if (!lxml_is_known_dtd(dtd->SystemID)) { 32870Sstevel@tonic-gate semerr(gettext("document DTD unknown; not service bundle?\n")); 32880Sstevel@tonic-gate return (-1); 32890Sstevel@tonic-gate } 32900Sstevel@tonic-gate 32910Sstevel@tonic-gate if ((cursor = xmlDocGetRootElement(document)) == NULL) { 32920Sstevel@tonic-gate semerr(gettext("document is empty\n")); 32930Sstevel@tonic-gate xmlFreeDoc(document); 32940Sstevel@tonic-gate return (-1); 32950Sstevel@tonic-gate } 32960Sstevel@tonic-gate 32970Sstevel@tonic-gate if (xmlStrcmp(cursor->name, (const xmlChar *)"service_bundle") != 0) { 32980Sstevel@tonic-gate semerr(gettext("document is not a service bundle\n")); 32990Sstevel@tonic-gate xmlFreeDoc(document); 33000Sstevel@tonic-gate return (-1); 33010Sstevel@tonic-gate } 33020Sstevel@tonic-gate 33030Sstevel@tonic-gate 33040Sstevel@tonic-gate if (dtdpath != NULL) { 33050Sstevel@tonic-gate dtd = xmlParseDTD(NULL, (xmlChar *)dtdpath); 33060Sstevel@tonic-gate if (dtd == NULL) { 33070Sstevel@tonic-gate semerr(gettext("Could not parse DTD \"%s\".\n"), 33080Sstevel@tonic-gate dtdpath); 33090Sstevel@tonic-gate return (-1); 33100Sstevel@tonic-gate } 33110Sstevel@tonic-gate 33120Sstevel@tonic-gate if (document->extSubset != NULL) 33130Sstevel@tonic-gate xmlFreeDtd(document->extSubset); 33140Sstevel@tonic-gate 33150Sstevel@tonic-gate document->extSubset = dtd; 33160Sstevel@tonic-gate } 33170Sstevel@tonic-gate 33184740Sjeanm if (xmlXIncludeProcessFlags(document, XML_PARSE_XINCLUDE) == -1) { 33190Sstevel@tonic-gate semerr(gettext("couldn't handle XInclude statements " 33204740Sjeanm "in document\n")); 33210Sstevel@tonic-gate return (-1); 33220Sstevel@tonic-gate } 33230Sstevel@tonic-gate 33240Sstevel@tonic-gate if (do_validate) { 33250Sstevel@tonic-gate vcp = xmlNewValidCtxt(); 33260Sstevel@tonic-gate if (vcp == NULL) 33270Sstevel@tonic-gate uu_die(gettext("could not allocate memory")); 33280Sstevel@tonic-gate vcp->warning = xmlParserValidityWarning; 33290Sstevel@tonic-gate vcp->error = xmlParserValidityError; 33300Sstevel@tonic-gate 33310Sstevel@tonic-gate r = xmlValidateDocument(vcp, document); 33320Sstevel@tonic-gate 33330Sstevel@tonic-gate xmlFreeValidCtxt(vcp); 33340Sstevel@tonic-gate 33350Sstevel@tonic-gate if (r == 0) { 33360Sstevel@tonic-gate semerr(gettext("Document is not valid.\n")); 33370Sstevel@tonic-gate xmlFreeDoc(document); 33380Sstevel@tonic-gate return (-1); 33390Sstevel@tonic-gate } 33400Sstevel@tonic-gate } 33410Sstevel@tonic-gate 33420Sstevel@tonic-gate 33430Sstevel@tonic-gate #ifdef DEBUG 33440Sstevel@tonic-gate lxml_dump(0, cursor); 33450Sstevel@tonic-gate #endif /* DEBUG */ 33460Sstevel@tonic-gate 33475040Swesolows r = lxml_get_bundle(bundle, SVCCFG_UNKNOWN_BUNDLE, cursor, op); 33480Sstevel@tonic-gate 33490Sstevel@tonic-gate xmlFreeDoc(document); 33500Sstevel@tonic-gate 33510Sstevel@tonic-gate return (r); 33520Sstevel@tonic-gate } 33530Sstevel@tonic-gate 33540Sstevel@tonic-gate int 33550Sstevel@tonic-gate lxml_inventory(const char *filename) 33560Sstevel@tonic-gate { 33570Sstevel@tonic-gate bundle_t *b; 33580Sstevel@tonic-gate uu_list_walk_t *svcs, *insts; 33590Sstevel@tonic-gate entity_t *svc, *inst; 33600Sstevel@tonic-gate 33610Sstevel@tonic-gate b = internal_bundle_new(); 33620Sstevel@tonic-gate 33635040Swesolows if (lxml_get_bundle_file(b, filename, SVCCFG_OP_IMPORT) != 0) { 33640Sstevel@tonic-gate internal_bundle_free(b); 33650Sstevel@tonic-gate return (-1); 33660Sstevel@tonic-gate } 33670Sstevel@tonic-gate 33680Sstevel@tonic-gate svcs = uu_list_walk_start(b->sc_bundle_services, 0); 33690Sstevel@tonic-gate if (svcs == NULL) 33700Sstevel@tonic-gate uu_die(gettext("Couldn't walk services")); 33710Sstevel@tonic-gate 33720Sstevel@tonic-gate while ((svc = uu_list_walk_next(svcs)) != NULL) { 33730Sstevel@tonic-gate uu_list_t *inst_list; 33740Sstevel@tonic-gate 33750Sstevel@tonic-gate inst_list = svc->sc_u.sc_service.sc_service_instances; 33760Sstevel@tonic-gate insts = uu_list_walk_start(inst_list, 0); 33770Sstevel@tonic-gate if (insts == NULL) 33780Sstevel@tonic-gate uu_die(gettext("Couldn't walk instances")); 33790Sstevel@tonic-gate 33800Sstevel@tonic-gate while ((inst = uu_list_walk_next(insts)) != NULL) 33810Sstevel@tonic-gate (void) printf("svc:/%s:%s\n", svc->sc_name, 33820Sstevel@tonic-gate inst->sc_name); 33830Sstevel@tonic-gate 33840Sstevel@tonic-gate uu_list_walk_end(insts); 33850Sstevel@tonic-gate } 33860Sstevel@tonic-gate 33870Sstevel@tonic-gate uu_list_walk_end(svcs); 33880Sstevel@tonic-gate 33890Sstevel@tonic-gate svcs = uu_list_walk_start(b->sc_bundle_services, 0); 33900Sstevel@tonic-gate while ((svc = uu_list_walk_next(svcs)) != NULL) { 33910Sstevel@tonic-gate (void) fputs("svc:/", stdout); 33920Sstevel@tonic-gate (void) puts(svc->sc_name); 33930Sstevel@tonic-gate } 33940Sstevel@tonic-gate uu_list_walk_end(svcs); 33950Sstevel@tonic-gate 33960Sstevel@tonic-gate internal_bundle_free(b); 33970Sstevel@tonic-gate 33980Sstevel@tonic-gate return (0); 33990Sstevel@tonic-gate } 3400