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*9263SSean.Wilcox@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 267887SLiane.Praza@Sun.COM /* 277887SLiane.Praza@Sun.COM * XML document manipulation routines 287887SLiane.Praza@Sun.COM * 297887SLiane.Praza@Sun.COM * These routines provide translation to and from the internal representation to 307887SLiane.Praza@Sun.COM * XML. Directionally-oriented verbs are with respect to the external source, 317887SLiane.Praza@Sun.COM * so lxml_get_service() fetches a service from the XML file into the 327887SLiane.Praza@Sun.COM * internal representation. 337887SLiane.Praza@Sun.COM */ 340Sstevel@tonic-gate 350Sstevel@tonic-gate #include <libxml/parser.h> 360Sstevel@tonic-gate #include <libxml/xinclude.h> 370Sstevel@tonic-gate 380Sstevel@tonic-gate #include <assert.h> 390Sstevel@tonic-gate #include <ctype.h> 400Sstevel@tonic-gate #include <errno.h> 410Sstevel@tonic-gate #include <libintl.h> 427887SLiane.Praza@Sun.COM #include <libscf.h> 437887SLiane.Praza@Sun.COM #include <libscf_priv.h> 440Sstevel@tonic-gate #include <libuutil.h> 457887SLiane.Praza@Sun.COM #include <sasl/saslutil.h> 460Sstevel@tonic-gate #include <stdlib.h> 470Sstevel@tonic-gate #include <string.h> 480Sstevel@tonic-gate 494740Sjeanm #include <sys/types.h> 504740Sjeanm #include <sys/stat.h> 514740Sjeanm #include <unistd.h> 524740Sjeanm 530Sstevel@tonic-gate #include "svccfg.h" 540Sstevel@tonic-gate 550Sstevel@tonic-gate /* 567887SLiane.Praza@Sun.COM * snprintf(3C) format strings for constructing property names that include 577887SLiane.Praza@Sun.COM * the locale designation. Use %s to indicate where the locale should go. 580Sstevel@tonic-gate * 597887SLiane.Praza@Sun.COM * The VALUE_* symbols are an exception. The firs %s will be replaced with 607887SLiane.Praza@Sun.COM * "value_". The second %s will be replaced by the name of the value and 617887SLiane.Praza@Sun.COM * %%s will be replaced by the locale designation. These formats are 627887SLiane.Praza@Sun.COM * processed twice by snprintf(3C). The first time captures the value name 637887SLiane.Praza@Sun.COM * and the second time captures the locale. 640Sstevel@tonic-gate */ 657887SLiane.Praza@Sun.COM #define LOCALE_ONLY_FMT ("%s") 667887SLiane.Praza@Sun.COM #define COMMON_NAME_FMT ("common_name_%s") 677887SLiane.Praza@Sun.COM #define DESCRIPTION_FMT ("description_%s") 687887SLiane.Praza@Sun.COM #define UNITS_FMT ("units_%s") 697887SLiane.Praza@Sun.COM #define VALUE_COMMON_NAME_FMT ("%s%s_common_name_%%s") 707887SLiane.Praza@Sun.COM #define VALUE_DESCRIPTION_FMT ("%s%s_description_%%s") 717887SLiane.Praza@Sun.COM 727887SLiane.Praza@Sun.COM /* Attribute names */ 730Sstevel@tonic-gate const char * const delete_attr = "delete"; 740Sstevel@tonic-gate const char * const enabled_attr = "enabled"; 757887SLiane.Praza@Sun.COM const char * const lang_attr = "lang"; 767887SLiane.Praza@Sun.COM const char * const manpath_attr = "manpath"; 777887SLiane.Praza@Sun.COM const char * const max_attr = "max"; 787887SLiane.Praza@Sun.COM const char * const min_attr = "min"; 790Sstevel@tonic-gate const char * const name_attr = "name"; 800Sstevel@tonic-gate const char * const override_attr = "override"; 817887SLiane.Praza@Sun.COM const char * const required_attr = "required"; 827887SLiane.Praza@Sun.COM const char * const section_attr = "section"; 837887SLiane.Praza@Sun.COM const char * const set_attr = "set"; 847887SLiane.Praza@Sun.COM const char * const target_attr = "target"; 857887SLiane.Praza@Sun.COM const char * const timeout_seconds_attr = "timeout_seconds"; 867887SLiane.Praza@Sun.COM const char * const title_attr = "title"; 870Sstevel@tonic-gate const char * const type_attr = "type"; 887887SLiane.Praza@Sun.COM const char * const uri_attr = "uri"; 890Sstevel@tonic-gate const char * const value_attr = "value"; 907887SLiane.Praza@Sun.COM const char * const version_attr = "version"; 917887SLiane.Praza@Sun.COM const char * const xml_lang_attr = "xml:lang"; 927887SLiane.Praza@Sun.COM 937887SLiane.Praza@Sun.COM /* Attribute values */ 947887SLiane.Praza@Sun.COM const char * const all_value = "all"; 957887SLiane.Praza@Sun.COM 960Sstevel@tonic-gate const char * const true = "true"; 970Sstevel@tonic-gate const char * const false = "false"; 980Sstevel@tonic-gate 990Sstevel@tonic-gate /* 1000Sstevel@tonic-gate * The following list must be kept in the same order as that of 1010Sstevel@tonic-gate * element_t array 1020Sstevel@tonic-gate */ 1030Sstevel@tonic-gate static const char *lxml_elements[] = { 1040Sstevel@tonic-gate "astring_list", /* SC_ASTRING */ 1050Sstevel@tonic-gate "boolean_list", /* SC_BOOLEAN */ 1067887SLiane.Praza@Sun.COM "cardinality", /* SC_CARDINALITY */ 1077887SLiane.Praza@Sun.COM "choices", /* SC_CHOICES */ 1080Sstevel@tonic-gate "common_name", /* SC_COMMON_NAME */ 1097887SLiane.Praza@Sun.COM "constraints", /* SC_CONSTRAINTS */ 1100Sstevel@tonic-gate "count_list", /* SC_COUNT */ 1110Sstevel@tonic-gate "create_default_instance", /* SC_INSTANCE_CREATE_DEFAULT */ 1120Sstevel@tonic-gate "dependency", /* SC_DEPENDENCY */ 1130Sstevel@tonic-gate "dependent", /* SC_DEPENDENT */ 1140Sstevel@tonic-gate "description", /* SC_DESCRIPTION */ 1150Sstevel@tonic-gate "doc_link", /* SC_DOC_LINK */ 1160Sstevel@tonic-gate "documentation", /* SC_DOCUMENTATION */ 1170Sstevel@tonic-gate "enabled", /* SC_ENABLED */ 1180Sstevel@tonic-gate "exec_method", /* SC_EXEC_METHOD */ 1190Sstevel@tonic-gate "fmri_list", /* SC_FMRI */ 1200Sstevel@tonic-gate "host_list", /* SC_HOST */ 1210Sstevel@tonic-gate "hostname_list", /* SC_HOSTNAME */ 1227887SLiane.Praza@Sun.COM "include_values", /* SC_INCLUDE_VALUES */ 1230Sstevel@tonic-gate "instance", /* SC_INSTANCE */ 1240Sstevel@tonic-gate "integer_list", /* SC_INTEGER */ 1257887SLiane.Praza@Sun.COM "internal_separators", /* SC_INTERNAL_SEPARATORS */ 1260Sstevel@tonic-gate "loctext", /* SC_LOCTEXT */ 1270Sstevel@tonic-gate "manpage", /* SC_MANPAGE */ 1280Sstevel@tonic-gate "method_context", /* SC_METHOD_CONTEXT */ 1290Sstevel@tonic-gate "method_credential", /* SC_METHOD_CREDENTIAL */ 1300Sstevel@tonic-gate "method_profile", /* SC_METHOD_PROFILE */ 1310Sstevel@tonic-gate "method_environment", /* SC_METHOD_ENVIRONMENT */ 1320Sstevel@tonic-gate "envvar", /* SC_METHOD_ENVVAR */ 1330Sstevel@tonic-gate "net_address_v4_list", /* SC_NET_ADDR_V4 */ 1340Sstevel@tonic-gate "net_address_v6_list", /* SC_NET_ADDR_V6 */ 1350Sstevel@tonic-gate "opaque_list", /* SC_OPAQUE */ 1367887SLiane.Praza@Sun.COM "pg_pattern", /* SC_PG_PATTERN */ 1377887SLiane.Praza@Sun.COM "prop_pattern", /* SC_PROP_PATTERN */ 1380Sstevel@tonic-gate "property", /* SC_PROPERTY */ 1390Sstevel@tonic-gate "property_group", /* SC_PROPERTY_GROUP */ 1400Sstevel@tonic-gate "propval", /* SC_PROPVAL */ 1417887SLiane.Praza@Sun.COM "range", /* SC_RANGE */ 1420Sstevel@tonic-gate "restarter", /* SC_RESTARTER */ 1430Sstevel@tonic-gate "service", /* SC_SERVICE */ 1440Sstevel@tonic-gate "service_bundle", /* SC_SERVICE_BUNDLE */ 1450Sstevel@tonic-gate "service_fmri", /* SC_SERVICE_FMRI */ 1460Sstevel@tonic-gate "single_instance", /* SC_INSTANCE_SINGLE */ 1470Sstevel@tonic-gate "stability", /* SC_STABILITY */ 1480Sstevel@tonic-gate "template", /* SC_TEMPLATE */ 1490Sstevel@tonic-gate "time_list", /* SC_TIME */ 1507887SLiane.Praza@Sun.COM "units", /* SC_UNITS */ 1510Sstevel@tonic-gate "uri_list", /* SC_URI */ 1520Sstevel@tonic-gate "ustring_list", /* SC_USTRING */ 1537887SLiane.Praza@Sun.COM "value", /* SC_VALUE */ 1540Sstevel@tonic-gate "value_node", /* SC_VALUE_NODE */ 1557887SLiane.Praza@Sun.COM "values", /* SC_VALUES */ 1567887SLiane.Praza@Sun.COM "visibility", /* SC_VISIBILITY */ 1570Sstevel@tonic-gate "xi:fallback", /* SC_XI_FALLBACK */ 1580Sstevel@tonic-gate "xi:include" /* SC_XI_INCLUDE */ 1590Sstevel@tonic-gate }; 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate /* 1620Sstevel@tonic-gate * The following list must be kept in the same order as that of 1630Sstevel@tonic-gate * element_t array 1640Sstevel@tonic-gate */ 1650Sstevel@tonic-gate static const char *lxml_prop_types[] = { 1660Sstevel@tonic-gate "astring", /* SC_ASTRING */ 1670Sstevel@tonic-gate "boolean", /* SC_BOOLEAN */ 1687887SLiane.Praza@Sun.COM "", /* SC_CARDINALITY */ 1697887SLiane.Praza@Sun.COM "", /* SC_CHOICES */ 1700Sstevel@tonic-gate "", /* SC_COMMON_NAME */ 1717887SLiane.Praza@Sun.COM "", /* SC_CONSTRAINTS */ 1720Sstevel@tonic-gate "count", /* SC_COUNT */ 1730Sstevel@tonic-gate "", /* SC_INSTANCE_CREATE_DEFAULT */ 1740Sstevel@tonic-gate "", /* SC_DEPENDENCY */ 1750Sstevel@tonic-gate "", /* SC_DEPENDENT */ 1760Sstevel@tonic-gate "", /* SC_DESCRIPTION */ 1770Sstevel@tonic-gate "", /* SC_DOC_LINK */ 1780Sstevel@tonic-gate "", /* SC_DOCUMENTATION */ 1790Sstevel@tonic-gate "", /* SC_ENABLED */ 1800Sstevel@tonic-gate "", /* SC_EXEC_METHOD */ 1810Sstevel@tonic-gate "fmri", /* SC_FMRI */ 1820Sstevel@tonic-gate "host", /* SC_HOST */ 1830Sstevel@tonic-gate "hostname", /* SC_HOSTNAME */ 1847887SLiane.Praza@Sun.COM "", /* SC_INCLUDE_VALUES */ 1850Sstevel@tonic-gate "", /* SC_INSTANCE */ 1860Sstevel@tonic-gate "integer", /* SC_INTEGER */ 1877887SLiane.Praza@Sun.COM "", /* SC_INTERNAL_SEPARATORS */ 1880Sstevel@tonic-gate "", /* SC_LOCTEXT */ 1890Sstevel@tonic-gate "", /* SC_MANPAGE */ 1900Sstevel@tonic-gate "", /* SC_METHOD_CONTEXT */ 1910Sstevel@tonic-gate "", /* SC_METHOD_CREDENTIAL */ 1920Sstevel@tonic-gate "", /* SC_METHOD_PROFILE */ 1930Sstevel@tonic-gate "", /* SC_METHOD_ENVIRONMENT */ 1940Sstevel@tonic-gate "", /* SC_METHOD_ENVVAR */ 1950Sstevel@tonic-gate "net_address_v4", /* SC_NET_ADDR_V4 */ 1960Sstevel@tonic-gate "net_address_v6", /* SC_NET_ADDR_V6 */ 1970Sstevel@tonic-gate "opaque", /* SC_OPAQUE */ 1987887SLiane.Praza@Sun.COM "", /* SC_PG_PATTERN */ 1997887SLiane.Praza@Sun.COM "", /* SC_PROP_PATTERN */ 2000Sstevel@tonic-gate "", /* SC_PROPERTY */ 2010Sstevel@tonic-gate "", /* SC_PROPERTY_GROUP */ 2020Sstevel@tonic-gate "", /* SC_PROPVAL */ 2037887SLiane.Praza@Sun.COM "", /* SC_RANGE */ 2040Sstevel@tonic-gate "", /* SC_RESTARTER */ 2050Sstevel@tonic-gate "", /* SC_SERVICE */ 2060Sstevel@tonic-gate "", /* SC_SERVICE_BUNDLE */ 2070Sstevel@tonic-gate "", /* SC_SERVICE_FMRI */ 2080Sstevel@tonic-gate "", /* SC_INSTANCE_SINGLE */ 2090Sstevel@tonic-gate "", /* SC_STABILITY */ 2100Sstevel@tonic-gate "", /* SC_TEMPLATE */ 2110Sstevel@tonic-gate "time", /* SC_TIME */ 2127887SLiane.Praza@Sun.COM "", /* SC_UNITS */ 2130Sstevel@tonic-gate "uri", /* SC_URI */ 2140Sstevel@tonic-gate "ustring", /* SC_USTRING */ 2157887SLiane.Praza@Sun.COM "", /* SC_VALUE */ 2167887SLiane.Praza@Sun.COM "", /* SC_VALUE_NODE */ 2177887SLiane.Praza@Sun.COM "", /* SC_VALUES */ 2187887SLiane.Praza@Sun.COM "", /* SC_VISIBILITY */ 2197887SLiane.Praza@Sun.COM "", /* SC_XI_FALLBACK */ 2200Sstevel@tonic-gate "" /* SC_XI_INCLUDE */ 2210Sstevel@tonic-gate }; 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate int 2240Sstevel@tonic-gate lxml_init() 2250Sstevel@tonic-gate { 2260Sstevel@tonic-gate if (getenv("SVCCFG_NOVALIDATE") == NULL) { 2270Sstevel@tonic-gate /* 2280Sstevel@tonic-gate * DTD validation, with line numbers. 2290Sstevel@tonic-gate */ 2300Sstevel@tonic-gate xmlLineNumbersDefault(1); 2310Sstevel@tonic-gate xmlLoadExtDtdDefaultValue |= XML_DETECT_IDS; 2320Sstevel@tonic-gate xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS; 2330Sstevel@tonic-gate } 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate return (0); 2360Sstevel@tonic-gate } 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate static bundle_type_t 2390Sstevel@tonic-gate lxml_xlate_bundle_type(xmlChar *type) 2400Sstevel@tonic-gate { 2410Sstevel@tonic-gate if (xmlStrcmp(type, (const xmlChar *)"manifest") == 0) 2420Sstevel@tonic-gate return (SVCCFG_MANIFEST); 2430Sstevel@tonic-gate 2440Sstevel@tonic-gate if (xmlStrcmp(type, (const xmlChar *)"profile") == 0) 2450Sstevel@tonic-gate return (SVCCFG_PROFILE); 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate if (xmlStrcmp(type, (const xmlChar *)"archive") == 0) 2480Sstevel@tonic-gate return (SVCCFG_ARCHIVE); 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate return (SVCCFG_UNKNOWN_BUNDLE); 2510Sstevel@tonic-gate } 2520Sstevel@tonic-gate 2530Sstevel@tonic-gate static service_type_t 2540Sstevel@tonic-gate lxml_xlate_service_type(xmlChar *type) 2550Sstevel@tonic-gate { 2560Sstevel@tonic-gate if (xmlStrcmp(type, (const xmlChar *)"service") == 0) 2570Sstevel@tonic-gate return (SVCCFG_SERVICE); 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate if (xmlStrcmp(type, (const xmlChar *)"restarter") == 0) 2600Sstevel@tonic-gate return (SVCCFG_RESTARTER); 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate if (xmlStrcmp(type, (const xmlChar *)"milestone") == 0) 2630Sstevel@tonic-gate return (SVCCFG_MILESTONE); 2640Sstevel@tonic-gate 2650Sstevel@tonic-gate return (SVCCFG_UNKNOWN_SERVICE); 2660Sstevel@tonic-gate } 2670Sstevel@tonic-gate 2680Sstevel@tonic-gate static element_t 2690Sstevel@tonic-gate lxml_xlate_element(const xmlChar *tag) 2700Sstevel@tonic-gate { 2710Sstevel@tonic-gate int i; 2720Sstevel@tonic-gate 2730Sstevel@tonic-gate for (i = 0; i < sizeof (lxml_elements) / sizeof (char *); i++) 2740Sstevel@tonic-gate if (xmlStrcmp(tag, (const xmlChar *)lxml_elements[i]) == 0) 2750Sstevel@tonic-gate return ((element_t)i); 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate return ((element_t)-1); 2780Sstevel@tonic-gate } 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate static uint_t 2810Sstevel@tonic-gate lxml_xlate_boolean(const xmlChar *value) 2820Sstevel@tonic-gate { 2830Sstevel@tonic-gate if (xmlStrcmp(value, (const xmlChar *)true) == 0) 2840Sstevel@tonic-gate return (1); 2850Sstevel@tonic-gate 2860Sstevel@tonic-gate if (xmlStrcmp(value, (const xmlChar *)false) == 0) 2870Sstevel@tonic-gate return (0); 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate uu_die(gettext("illegal boolean value \"%s\"\n"), value); 2900Sstevel@tonic-gate 2910Sstevel@tonic-gate /*NOTREACHED*/ 2920Sstevel@tonic-gate } 2930Sstevel@tonic-gate 2940Sstevel@tonic-gate static scf_type_t 2950Sstevel@tonic-gate lxml_element_to_type(element_t type) 2960Sstevel@tonic-gate { 2970Sstevel@tonic-gate switch (type) { 2980Sstevel@tonic-gate case SC_ASTRING: return (SCF_TYPE_ASTRING); 2990Sstevel@tonic-gate case SC_BOOLEAN: return (SCF_TYPE_BOOLEAN); 3000Sstevel@tonic-gate case SC_COUNT: return (SCF_TYPE_COUNT); 3010Sstevel@tonic-gate case SC_FMRI: return (SCF_TYPE_FMRI); 3020Sstevel@tonic-gate case SC_HOST: return (SCF_TYPE_HOST); 3030Sstevel@tonic-gate case SC_HOSTNAME: return (SCF_TYPE_HOSTNAME); 3040Sstevel@tonic-gate case SC_INTEGER: return (SCF_TYPE_INTEGER); 3050Sstevel@tonic-gate case SC_NET_ADDR_V4: return (SCF_TYPE_NET_ADDR_V4); 3060Sstevel@tonic-gate case SC_NET_ADDR_V6: return (SCF_TYPE_NET_ADDR_V6); 3070Sstevel@tonic-gate case SC_OPAQUE: return (SCF_TYPE_OPAQUE); 3080Sstevel@tonic-gate case SC_TIME: return (SCF_TYPE_TIME); 3090Sstevel@tonic-gate case SC_URI: return (SCF_TYPE_URI); 3100Sstevel@tonic-gate case SC_USTRING: return (SCF_TYPE_USTRING); 3110Sstevel@tonic-gate 3120Sstevel@tonic-gate default: 3130Sstevel@tonic-gate uu_die(gettext("unknown value type (%d)\n"), type); 3140Sstevel@tonic-gate } 3150Sstevel@tonic-gate 3160Sstevel@tonic-gate /* NOTREACHED */ 3170Sstevel@tonic-gate } 3180Sstevel@tonic-gate 3190Sstevel@tonic-gate static scf_type_t 3200Sstevel@tonic-gate lxml_element_to_scf_type(element_t type) 3210Sstevel@tonic-gate { 3220Sstevel@tonic-gate switch (type) { 3230Sstevel@tonic-gate case SC_ASTRING: return (SCF_TYPE_ASTRING); 3240Sstevel@tonic-gate case SC_BOOLEAN: return (SCF_TYPE_BOOLEAN); 3250Sstevel@tonic-gate case SC_COUNT: return (SCF_TYPE_COUNT); 3260Sstevel@tonic-gate case SC_FMRI: return (SCF_TYPE_FMRI); 3270Sstevel@tonic-gate case SC_HOST: return (SCF_TYPE_HOST); 3280Sstevel@tonic-gate case SC_HOSTNAME: return (SCF_TYPE_HOSTNAME); 3290Sstevel@tonic-gate case SC_INTEGER: return (SCF_TYPE_INTEGER); 3300Sstevel@tonic-gate case SC_NET_ADDR_V4: return (SCF_TYPE_NET_ADDR_V4); 3310Sstevel@tonic-gate case SC_NET_ADDR_V6: return (SCF_TYPE_NET_ADDR_V6); 3320Sstevel@tonic-gate case SC_OPAQUE: return (SCF_TYPE_OPAQUE); 3330Sstevel@tonic-gate case SC_TIME: return (SCF_TYPE_TIME); 3340Sstevel@tonic-gate case SC_URI: return (SCF_TYPE_URI); 3350Sstevel@tonic-gate case SC_USTRING: return (SCF_TYPE_USTRING); 3360Sstevel@tonic-gate default: 3370Sstevel@tonic-gate uu_die(gettext("unknown value type (%d)\n"), type); 3380Sstevel@tonic-gate } 3390Sstevel@tonic-gate 3400Sstevel@tonic-gate /* NOTREACHED */ 3410Sstevel@tonic-gate } 3420Sstevel@tonic-gate 3437887SLiane.Praza@Sun.COM /* 3447887SLiane.Praza@Sun.COM * Create a SCF_TYPE_BOOLEAN property name pname and attach it to the 3457887SLiane.Praza@Sun.COM * property group at pgrp. The value of the property will be set from the 3467887SLiane.Praza@Sun.COM * attribute named attr. attr must have a value of 0, 1, true or false. 3477887SLiane.Praza@Sun.COM * 3487887SLiane.Praza@Sun.COM * Zero is returned on success. An error is indicated by -1. It indicates 3497887SLiane.Praza@Sun.COM * that either the attribute had an invalid value or that we could not 3507887SLiane.Praza@Sun.COM * attach the property to pgrp. The attribute should not have an invalid 3517887SLiane.Praza@Sun.COM * value if the DTD is correctly written. 3527887SLiane.Praza@Sun.COM */ 3537887SLiane.Praza@Sun.COM static int 3547887SLiane.Praza@Sun.COM new_bool_prop_from_attr(pgroup_t *pgrp, const char *pname, xmlNodePtr n, 3557887SLiane.Praza@Sun.COM const char *attr) 3567887SLiane.Praza@Sun.COM { 3577887SLiane.Praza@Sun.COM uint64_t bool; 3587887SLiane.Praza@Sun.COM xmlChar *val; 3597887SLiane.Praza@Sun.COM property_t *p; 3607887SLiane.Praza@Sun.COM int r; 3617887SLiane.Praza@Sun.COM 3627887SLiane.Praza@Sun.COM val = xmlGetProp(n, (xmlChar *)attr); 3637887SLiane.Praza@Sun.COM if (val == NULL) 3647887SLiane.Praza@Sun.COM return (0); 3657887SLiane.Praza@Sun.COM 3667887SLiane.Praza@Sun.COM if ((xmlStrcmp(val, (xmlChar *)"0") == 0) || 3677887SLiane.Praza@Sun.COM (xmlStrcmp(val, (xmlChar *)"false") == 0)) { 3687887SLiane.Praza@Sun.COM bool = 0; 3697887SLiane.Praza@Sun.COM } else if ((xmlStrcmp(val, (xmlChar *)"1") == 0) || 3707887SLiane.Praza@Sun.COM (xmlStrcmp(val, (xmlChar *)"true") == 0)) { 3717887SLiane.Praza@Sun.COM bool = 1; 3727887SLiane.Praza@Sun.COM } else { 3737887SLiane.Praza@Sun.COM xmlFree(val); 3747887SLiane.Praza@Sun.COM return (-1); 3757887SLiane.Praza@Sun.COM } 3767887SLiane.Praza@Sun.COM xmlFree(val); 3777887SLiane.Praza@Sun.COM p = internal_property_create(pname, SCF_TYPE_BOOLEAN, 1, bool); 3787887SLiane.Praza@Sun.COM r = internal_attach_property(pgrp, p); 3797887SLiane.Praza@Sun.COM 3807887SLiane.Praza@Sun.COM if (r != 0) 3817887SLiane.Praza@Sun.COM internal_property_free(p); 3827887SLiane.Praza@Sun.COM 3837887SLiane.Praza@Sun.COM return (r); 3847887SLiane.Praza@Sun.COM } 3857887SLiane.Praza@Sun.COM 3860Sstevel@tonic-gate static int 3870Sstevel@tonic-gate new_str_prop_from_attr(pgroup_t *pgrp, const char *pname, scf_type_t ty, 3880Sstevel@tonic-gate xmlNodePtr n, const char *attr) 3890Sstevel@tonic-gate { 3900Sstevel@tonic-gate xmlChar *val; 3910Sstevel@tonic-gate property_t *p; 3920Sstevel@tonic-gate int r; 3930Sstevel@tonic-gate 3940Sstevel@tonic-gate val = xmlGetProp(n, (xmlChar *)attr); 3950Sstevel@tonic-gate 3960Sstevel@tonic-gate p = internal_property_create(pname, ty, 1, val); 3970Sstevel@tonic-gate r = internal_attach_property(pgrp, p); 3980Sstevel@tonic-gate 3990Sstevel@tonic-gate if (r != 0) 4000Sstevel@tonic-gate internal_property_free(p); 4010Sstevel@tonic-gate 4020Sstevel@tonic-gate return (r); 4030Sstevel@tonic-gate } 4040Sstevel@tonic-gate 4050Sstevel@tonic-gate static int 4067887SLiane.Praza@Sun.COM new_opt_str_prop_from_attr(pgroup_t *pgrp, const char *pname, scf_type_t ty, 4077887SLiane.Praza@Sun.COM xmlNodePtr n, const char *attr, const char *dflt) 4087887SLiane.Praza@Sun.COM { 4097887SLiane.Praza@Sun.COM xmlChar *val; 4107887SLiane.Praza@Sun.COM property_t *p; 4117887SLiane.Praza@Sun.COM int r; 4127887SLiane.Praza@Sun.COM 4137887SLiane.Praza@Sun.COM val = xmlGetProp(n, (xmlChar *)attr); 4147887SLiane.Praza@Sun.COM if (val == NULL) { 4157887SLiane.Praza@Sun.COM if (dflt == NULL) { 4167887SLiane.Praza@Sun.COM /* 4177887SLiane.Praza@Sun.COM * A missing attribute is considered to be a 4187887SLiane.Praza@Sun.COM * success in this function, because many of the 4197887SLiane.Praza@Sun.COM * attributes are optional. Missing non-optional 4207887SLiane.Praza@Sun.COM * attributes will be detected later when template 4217887SLiane.Praza@Sun.COM * validation is done. 4227887SLiane.Praza@Sun.COM */ 4237887SLiane.Praza@Sun.COM return (0); 4247887SLiane.Praza@Sun.COM } else { 4257887SLiane.Praza@Sun.COM val = (xmlChar *)dflt; 4267887SLiane.Praza@Sun.COM } 4277887SLiane.Praza@Sun.COM } 4287887SLiane.Praza@Sun.COM 4297887SLiane.Praza@Sun.COM p = internal_property_create(pname, ty, 1, val); 4307887SLiane.Praza@Sun.COM r = internal_attach_property(pgrp, p); 4317887SLiane.Praza@Sun.COM 4327887SLiane.Praza@Sun.COM if (r != 0) 4337887SLiane.Praza@Sun.COM internal_property_free(p); 4347887SLiane.Praza@Sun.COM 4357887SLiane.Praza@Sun.COM return (r); 4367887SLiane.Praza@Sun.COM } 4377887SLiane.Praza@Sun.COM 4387887SLiane.Praza@Sun.COM static int 4390Sstevel@tonic-gate lxml_ignorable_block(xmlNodePtr n) 4400Sstevel@tonic-gate { 4410Sstevel@tonic-gate return ((xmlStrcmp(n->name, (xmlChar *)"text") == 0 || 4420Sstevel@tonic-gate xmlStrcmp(n->name, (xmlChar *)"comment") == 0) ? 1 : 0); 4430Sstevel@tonic-gate } 4440Sstevel@tonic-gate 4450Sstevel@tonic-gate static int 4460Sstevel@tonic-gate lxml_validate_string_value(scf_type_t type, const char *v) 4470Sstevel@tonic-gate { 4480Sstevel@tonic-gate static scf_value_t *scf_value = NULL; 4490Sstevel@tonic-gate static scf_handle_t *scf_hndl = NULL; 4500Sstevel@tonic-gate 4510Sstevel@tonic-gate if (scf_hndl == NULL && (scf_hndl = scf_handle_create(SCF_VERSION)) == 4520Sstevel@tonic-gate NULL) 4530Sstevel@tonic-gate return (-1); 4540Sstevel@tonic-gate 4550Sstevel@tonic-gate if (scf_value == NULL && (scf_value = scf_value_create(scf_hndl)) == 4560Sstevel@tonic-gate NULL) 4570Sstevel@tonic-gate return (-1); 4580Sstevel@tonic-gate 4590Sstevel@tonic-gate return (scf_value_set_from_string(scf_value, type, v)); 4600Sstevel@tonic-gate } 4610Sstevel@tonic-gate 4620Sstevel@tonic-gate static void 4630Sstevel@tonic-gate lxml_free_str(value_t *val) 4640Sstevel@tonic-gate { 4650Sstevel@tonic-gate free(val->sc_u.sc_string); 4660Sstevel@tonic-gate } 4670Sstevel@tonic-gate 4680Sstevel@tonic-gate static value_t * 4690Sstevel@tonic-gate lxml_make_value(element_t type, const xmlChar *value) 4700Sstevel@tonic-gate { 4710Sstevel@tonic-gate value_t *v; 4720Sstevel@tonic-gate char *endptr; 4730Sstevel@tonic-gate scf_type_t scf_type = SCF_TYPE_INVALID; 4740Sstevel@tonic-gate 4750Sstevel@tonic-gate v = internal_value_new(); 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate v->sc_type = lxml_element_to_type(type); 4780Sstevel@tonic-gate 4790Sstevel@tonic-gate switch (type) { 4800Sstevel@tonic-gate case SC_COUNT: 4810Sstevel@tonic-gate /* 4820Sstevel@tonic-gate * Although an SC_COUNT represents a uint64_t the use 4830Sstevel@tonic-gate * of a negative value is acceptable due to the usage 4840Sstevel@tonic-gate * established by inetd(1M). 4850Sstevel@tonic-gate */ 4860Sstevel@tonic-gate errno = 0; 4870Sstevel@tonic-gate v->sc_u.sc_count = strtoull((char *)value, &endptr, 10); 4880Sstevel@tonic-gate if (errno != 0 || endptr == (char *)value || *endptr) 4890Sstevel@tonic-gate uu_die(gettext("illegal value \"%s\" for " 4900Sstevel@tonic-gate "%s (%s)\n"), (char *)value, 4910Sstevel@tonic-gate lxml_prop_types[type], 4920Sstevel@tonic-gate (errno) ? strerror(errno) : 4930Sstevel@tonic-gate gettext("Illegal character")); 4940Sstevel@tonic-gate break; 4950Sstevel@tonic-gate case SC_INTEGER: 4960Sstevel@tonic-gate errno = 0; 4970Sstevel@tonic-gate v->sc_u.sc_integer = strtoll((char *)value, &endptr, 10); 4980Sstevel@tonic-gate if (errno != 0 || *endptr) 4990Sstevel@tonic-gate uu_die(gettext("illegal value \"%s\" for " 5000Sstevel@tonic-gate "%s (%s)\n"), (char *)value, 5010Sstevel@tonic-gate lxml_prop_types[type], 5020Sstevel@tonic-gate (errno) ? strerror(errno) : "Illegal character"); 5030Sstevel@tonic-gate break; 5040Sstevel@tonic-gate case SC_OPAQUE: 5050Sstevel@tonic-gate case SC_HOST: 5060Sstevel@tonic-gate case SC_HOSTNAME: 5070Sstevel@tonic-gate case SC_NET_ADDR_V4: 5080Sstevel@tonic-gate case SC_NET_ADDR_V6: 5090Sstevel@tonic-gate case SC_FMRI: 5100Sstevel@tonic-gate case SC_URI: 5110Sstevel@tonic-gate case SC_TIME: 5120Sstevel@tonic-gate case SC_ASTRING: 5130Sstevel@tonic-gate case SC_USTRING: 5140Sstevel@tonic-gate scf_type = lxml_element_to_scf_type(type); 5150Sstevel@tonic-gate 5160Sstevel@tonic-gate if ((v->sc_u.sc_string = strdup((char *)value)) == NULL) 5170Sstevel@tonic-gate uu_die(gettext("string duplication failed (%s)\n"), 5180Sstevel@tonic-gate strerror(errno)); 5190Sstevel@tonic-gate if (lxml_validate_string_value(scf_type, 5200Sstevel@tonic-gate v->sc_u.sc_string) != 0) 5210Sstevel@tonic-gate uu_die(gettext("illegal value \"%s\" for " 5220Sstevel@tonic-gate "%s (%s)\n"), (char *)value, 5230Sstevel@tonic-gate lxml_prop_types[type], 5240Sstevel@tonic-gate (scf_error()) ? scf_strerror(scf_error()) : 5250Sstevel@tonic-gate gettext("Illegal format")); 5260Sstevel@tonic-gate v->sc_free = lxml_free_str; 5270Sstevel@tonic-gate break; 5280Sstevel@tonic-gate case SC_BOOLEAN: 5290Sstevel@tonic-gate v->sc_u.sc_count = lxml_xlate_boolean(value); 5300Sstevel@tonic-gate break; 5310Sstevel@tonic-gate default: 5320Sstevel@tonic-gate uu_die(gettext("unknown value type (%d)\n"), type); 5330Sstevel@tonic-gate break; 5340Sstevel@tonic-gate } 5350Sstevel@tonic-gate 5360Sstevel@tonic-gate return (v); 5370Sstevel@tonic-gate } 5380Sstevel@tonic-gate 5390Sstevel@tonic-gate static int 5400Sstevel@tonic-gate lxml_get_value(property_t *prop, element_t vtype, xmlNodePtr value) 5410Sstevel@tonic-gate { 5420Sstevel@tonic-gate xmlNodePtr cursor; 5430Sstevel@tonic-gate 5440Sstevel@tonic-gate for (cursor = value->xmlChildrenNode; cursor != NULL; 5450Sstevel@tonic-gate cursor = cursor->next) { 5460Sstevel@tonic-gate xmlChar *assigned_value; 5470Sstevel@tonic-gate value_t *v; 5480Sstevel@tonic-gate 5490Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 5500Sstevel@tonic-gate continue; 5510Sstevel@tonic-gate 5520Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) { 5530Sstevel@tonic-gate case SC_VALUE_NODE: 5540Sstevel@tonic-gate if ((assigned_value = xmlGetProp(cursor, 5550Sstevel@tonic-gate (xmlChar *)value_attr)) == NULL) 5560Sstevel@tonic-gate uu_die(gettext("no value on value node?\n")); 5570Sstevel@tonic-gate break; 5580Sstevel@tonic-gate default: 5590Sstevel@tonic-gate uu_die(gettext("value list contains illegal element " 5600Sstevel@tonic-gate "\'%s\'\n"), cursor->name); 5610Sstevel@tonic-gate break; 5620Sstevel@tonic-gate } 5630Sstevel@tonic-gate 5640Sstevel@tonic-gate v = lxml_make_value(vtype, assigned_value); 5650Sstevel@tonic-gate 5660Sstevel@tonic-gate xmlFree(assigned_value); 5670Sstevel@tonic-gate 5680Sstevel@tonic-gate internal_attach_value(prop, v); 5690Sstevel@tonic-gate } 5700Sstevel@tonic-gate 5710Sstevel@tonic-gate return (0); 5720Sstevel@tonic-gate } 5730Sstevel@tonic-gate 5740Sstevel@tonic-gate static int 5750Sstevel@tonic-gate lxml_get_propval(pgroup_t *pgrp, xmlNodePtr propval) 5760Sstevel@tonic-gate { 5770Sstevel@tonic-gate property_t *p; 5780Sstevel@tonic-gate element_t r; 5790Sstevel@tonic-gate value_t *v; 5800Sstevel@tonic-gate xmlChar *type, *val, *override; 5810Sstevel@tonic-gate 5820Sstevel@tonic-gate p = internal_property_new(); 5830Sstevel@tonic-gate 5840Sstevel@tonic-gate p->sc_property_name = (char *)xmlGetProp(propval, (xmlChar *)name_attr); 5857887SLiane.Praza@Sun.COM if ((p->sc_property_name == NULL) || (*p->sc_property_name == 0)) 5860Sstevel@tonic-gate uu_die(gettext("property name missing in group '%s'\n"), 5870Sstevel@tonic-gate pgrp->sc_pgroup_name); 5880Sstevel@tonic-gate 5890Sstevel@tonic-gate type = xmlGetProp(propval, (xmlChar *)type_attr); 5907887SLiane.Praza@Sun.COM if ((type == NULL) || (*type == 0)) 5910Sstevel@tonic-gate uu_die(gettext("property type missing for property '%s/%s'\n"), 5920Sstevel@tonic-gate pgrp->sc_pgroup_name, p->sc_property_name); 5930Sstevel@tonic-gate 5940Sstevel@tonic-gate for (r = 0; r < sizeof (lxml_prop_types) / sizeof (char *); ++r) { 5950Sstevel@tonic-gate if (xmlStrcmp(type, (const xmlChar *)lxml_prop_types[r]) == 0) 5960Sstevel@tonic-gate break; 5970Sstevel@tonic-gate } 5987887SLiane.Praza@Sun.COM xmlFree(type); 5990Sstevel@tonic-gate if (r >= sizeof (lxml_prop_types) / sizeof (char *)) 6000Sstevel@tonic-gate uu_die(gettext("property type invalid for property '%s/%s'\n"), 6010Sstevel@tonic-gate pgrp->sc_pgroup_name, p->sc_property_name); 6020Sstevel@tonic-gate 6030Sstevel@tonic-gate p->sc_value_type = lxml_element_to_type(r); 6040Sstevel@tonic-gate 6050Sstevel@tonic-gate val = xmlGetProp(propval, (xmlChar *)value_attr); 6060Sstevel@tonic-gate if (val == NULL) 6070Sstevel@tonic-gate uu_die(gettext("property value missing for property '%s/%s'\n"), 6080Sstevel@tonic-gate pgrp->sc_pgroup_name, p->sc_property_name); 6090Sstevel@tonic-gate 6100Sstevel@tonic-gate v = lxml_make_value(r, val); 6117887SLiane.Praza@Sun.COM xmlFree(val); 6120Sstevel@tonic-gate internal_attach_value(p, v); 6130Sstevel@tonic-gate 6140Sstevel@tonic-gate override = xmlGetProp(propval, (xmlChar *)override_attr); 6150Sstevel@tonic-gate p->sc_property_override = (xmlStrcmp(override, (xmlChar *)true) == 0); 6160Sstevel@tonic-gate xmlFree(override); 6170Sstevel@tonic-gate 6180Sstevel@tonic-gate return (internal_attach_property(pgrp, p)); 6190Sstevel@tonic-gate } 6200Sstevel@tonic-gate 6210Sstevel@tonic-gate static int 6220Sstevel@tonic-gate lxml_get_property(pgroup_t *pgrp, xmlNodePtr property) 6230Sstevel@tonic-gate { 6240Sstevel@tonic-gate property_t *p; 6250Sstevel@tonic-gate xmlNodePtr cursor; 6260Sstevel@tonic-gate element_t r; 6270Sstevel@tonic-gate xmlChar *type, *override; 6280Sstevel@tonic-gate 6290Sstevel@tonic-gate p = internal_property_new(); 6300Sstevel@tonic-gate 6317887SLiane.Praza@Sun.COM if (((p->sc_property_name = (char *)xmlGetProp(property, 6327887SLiane.Praza@Sun.COM (xmlChar *)name_attr)) == NULL) || (*p->sc_property_name == 0)) 6330Sstevel@tonic-gate uu_die(gettext("property name missing in group \'%s\'\n"), 6340Sstevel@tonic-gate pgrp->sc_pgroup_name); 6350Sstevel@tonic-gate 6367887SLiane.Praza@Sun.COM if (((type = xmlGetProp(property, (xmlChar *)type_attr)) == NULL) || 6377887SLiane.Praza@Sun.COM (*type == 0)) { 6380Sstevel@tonic-gate uu_die(gettext("property type missing for " 6390Sstevel@tonic-gate "property \'%s/%s\'\n"), pgrp->sc_pgroup_name, 6400Sstevel@tonic-gate p->sc_property_name); 6417887SLiane.Praza@Sun.COM } 6420Sstevel@tonic-gate 6435040Swesolows for (r = 0; r < sizeof (lxml_prop_types) / sizeof (char *); r++) { 6445040Swesolows if (xmlStrcmp(type, (const xmlChar *)lxml_prop_types[r]) == 0) 6455040Swesolows break; 6465040Swesolows } 6475040Swesolows 6485040Swesolows if (r >= sizeof (lxml_prop_types) / sizeof (char *)) { 6495040Swesolows uu_die(gettext("property type invalid for property '%s/%s'\n"), 6505040Swesolows pgrp->sc_pgroup_name, p->sc_property_name); 6515040Swesolows } 6525040Swesolows 6535040Swesolows p->sc_value_type = lxml_element_to_type(r); 6545040Swesolows 6550Sstevel@tonic-gate for (cursor = property->xmlChildrenNode; cursor != NULL; 6560Sstevel@tonic-gate cursor = cursor->next) { 6570Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 6580Sstevel@tonic-gate continue; 6590Sstevel@tonic-gate 6600Sstevel@tonic-gate switch (r = lxml_xlate_element(cursor->name)) { 6610Sstevel@tonic-gate case SC_ASTRING: 6620Sstevel@tonic-gate case SC_BOOLEAN: 6630Sstevel@tonic-gate case SC_COUNT: 6640Sstevel@tonic-gate case SC_FMRI: 6650Sstevel@tonic-gate case SC_HOST: 6660Sstevel@tonic-gate case SC_HOSTNAME: 6670Sstevel@tonic-gate case SC_INTEGER: 6680Sstevel@tonic-gate case SC_NET_ADDR_V4: 6690Sstevel@tonic-gate case SC_NET_ADDR_V6: 6700Sstevel@tonic-gate case SC_OPAQUE: 6710Sstevel@tonic-gate case SC_TIME: 6720Sstevel@tonic-gate case SC_URI: 6730Sstevel@tonic-gate case SC_USTRING: 6740Sstevel@tonic-gate if (strcmp(lxml_prop_types[r], (const char *)type) != 0) 6750Sstevel@tonic-gate uu_die(gettext("property \'%s\' " 6760Sstevel@tonic-gate "type-to-list mismatch\n"), 6770Sstevel@tonic-gate p->sc_property_name); 6780Sstevel@tonic-gate 6790Sstevel@tonic-gate (void) lxml_get_value(p, r, cursor); 6800Sstevel@tonic-gate break; 6810Sstevel@tonic-gate default: 6820Sstevel@tonic-gate uu_die(gettext("unknown value list type: %s\n"), 6830Sstevel@tonic-gate cursor->name); 6840Sstevel@tonic-gate break; 6850Sstevel@tonic-gate } 6860Sstevel@tonic-gate } 6870Sstevel@tonic-gate 6880Sstevel@tonic-gate xmlFree(type); 6890Sstevel@tonic-gate 6900Sstevel@tonic-gate override = xmlGetProp(property, (xmlChar *)override_attr); 6910Sstevel@tonic-gate p->sc_property_override = (xmlStrcmp(override, (xmlChar *)true) == 0); 6920Sstevel@tonic-gate xmlFree(override); 6930Sstevel@tonic-gate 6940Sstevel@tonic-gate return (internal_attach_property(pgrp, p)); 6950Sstevel@tonic-gate } 6960Sstevel@tonic-gate 6970Sstevel@tonic-gate static int 6980Sstevel@tonic-gate lxml_get_pgroup_stability(pgroup_t *pgrp, xmlNodePtr stab) 6990Sstevel@tonic-gate { 7000Sstevel@tonic-gate return (new_str_prop_from_attr(pgrp, SCF_PROPERTY_STABILITY, 7010Sstevel@tonic-gate SCF_TYPE_ASTRING, stab, value_attr)); 7020Sstevel@tonic-gate } 7030Sstevel@tonic-gate 7040Sstevel@tonic-gate /* 7050Sstevel@tonic-gate * Property groups can go on any of a service, an instance, or a template. 7060Sstevel@tonic-gate */ 7070Sstevel@tonic-gate static int 7080Sstevel@tonic-gate lxml_get_pgroup(entity_t *entity, xmlNodePtr pgroup) 7090Sstevel@tonic-gate { 7100Sstevel@tonic-gate pgroup_t *pg; 7110Sstevel@tonic-gate xmlNodePtr cursor; 7120Sstevel@tonic-gate xmlChar *name, *type, *delete; 7130Sstevel@tonic-gate 7140Sstevel@tonic-gate /* 7150Sstevel@tonic-gate * property group attributes: 7160Sstevel@tonic-gate * name: string 7170Sstevel@tonic-gate * type: string | framework | application 7180Sstevel@tonic-gate */ 7190Sstevel@tonic-gate name = xmlGetProp(pgroup, (xmlChar *)name_attr); 7200Sstevel@tonic-gate type = xmlGetProp(pgroup, (xmlChar *)type_attr); 7210Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, (char *)name, (char *)type); 7220Sstevel@tonic-gate xmlFree(name); 7230Sstevel@tonic-gate xmlFree(type); 7240Sstevel@tonic-gate 7250Sstevel@tonic-gate /* 7260Sstevel@tonic-gate * Walk the children of this lxml_elements, which are a stability 7270Sstevel@tonic-gate * element, property elements, or propval elements. 7280Sstevel@tonic-gate */ 7290Sstevel@tonic-gate for (cursor = pgroup->xmlChildrenNode; cursor != NULL; 7300Sstevel@tonic-gate cursor = cursor->next) { 7310Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 7320Sstevel@tonic-gate continue; 7330Sstevel@tonic-gate 7340Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) { 7350Sstevel@tonic-gate case SC_STABILITY: 7360Sstevel@tonic-gate (void) lxml_get_pgroup_stability(pg, cursor); 7370Sstevel@tonic-gate break; 7380Sstevel@tonic-gate case SC_PROPERTY: 7390Sstevel@tonic-gate (void) lxml_get_property(pg, cursor); 7400Sstevel@tonic-gate break; 7410Sstevel@tonic-gate case SC_PROPVAL: 7420Sstevel@tonic-gate (void) lxml_get_propval(pg, cursor); 7430Sstevel@tonic-gate break; 7440Sstevel@tonic-gate default: 7450Sstevel@tonic-gate abort(); 7460Sstevel@tonic-gate break; 7470Sstevel@tonic-gate } 7480Sstevel@tonic-gate } 7490Sstevel@tonic-gate 7500Sstevel@tonic-gate delete = xmlGetProp(pgroup, (xmlChar *)delete_attr); 7510Sstevel@tonic-gate pg->sc_pgroup_delete = (xmlStrcmp(delete, (xmlChar *)true) == 0); 7520Sstevel@tonic-gate xmlFree(delete); 7530Sstevel@tonic-gate 7540Sstevel@tonic-gate return (0); 7550Sstevel@tonic-gate } 7560Sstevel@tonic-gate 7570Sstevel@tonic-gate 7580Sstevel@tonic-gate /* 7590Sstevel@tonic-gate * Dependency groups, execution methods can go on either a service or an 7600Sstevel@tonic-gate * instance. 7610Sstevel@tonic-gate */ 7620Sstevel@tonic-gate 7630Sstevel@tonic-gate static int 7640Sstevel@tonic-gate lxml_get_method_profile(pgroup_t *pg, xmlNodePtr profile) 7650Sstevel@tonic-gate { 7660Sstevel@tonic-gate property_t *p; 7670Sstevel@tonic-gate 7680Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_USE_PROFILE, SCF_TYPE_BOOLEAN, 7690Sstevel@tonic-gate 1, (uint64_t)1); 7700Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0) 7710Sstevel@tonic-gate return (-1); 7720Sstevel@tonic-gate 7730Sstevel@tonic-gate return (new_str_prop_from_attr(pg, SCF_PROPERTY_PROFILE, 7740Sstevel@tonic-gate SCF_TYPE_ASTRING, profile, name_attr)); 7750Sstevel@tonic-gate } 7760Sstevel@tonic-gate 7770Sstevel@tonic-gate static int 7780Sstevel@tonic-gate lxml_get_method_credential(pgroup_t *pg, xmlNodePtr cred) 7790Sstevel@tonic-gate { 7800Sstevel@tonic-gate property_t *p; 7810Sstevel@tonic-gate 7820Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_USE_PROFILE, SCF_TYPE_BOOLEAN, 7830Sstevel@tonic-gate 1, (uint64_t)0); 7840Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0) 7850Sstevel@tonic-gate return (-1); 7860Sstevel@tonic-gate 787*9263SSean.Wilcox@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_USER, SCF_TYPE_ASTRING, 788*9263SSean.Wilcox@Sun.COM cred, "user", NULL) != 0) 7890Sstevel@tonic-gate return (-1); 7900Sstevel@tonic-gate 791*9263SSean.Wilcox@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_GROUP, SCF_TYPE_ASTRING, 792*9263SSean.Wilcox@Sun.COM cred, "group", NULL) != 0) 7930Sstevel@tonic-gate return (-1); 7940Sstevel@tonic-gate 795*9263SSean.Wilcox@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_SUPP_GROUPS, 796*9263SSean.Wilcox@Sun.COM SCF_TYPE_ASTRING, cred, "supp_groups", NULL) != 0) 7970Sstevel@tonic-gate return (-1); 7980Sstevel@tonic-gate 799*9263SSean.Wilcox@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_PRIVILEGES, 800*9263SSean.Wilcox@Sun.COM SCF_TYPE_ASTRING, cred, "privileges", NULL) != 0) 8010Sstevel@tonic-gate return (-1); 8020Sstevel@tonic-gate 803*9263SSean.Wilcox@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_LIMIT_PRIVILEGES, 804*9263SSean.Wilcox@Sun.COM SCF_TYPE_ASTRING, cred, "limit_privileges", NULL) != 0) 8050Sstevel@tonic-gate return (-1); 8060Sstevel@tonic-gate 8070Sstevel@tonic-gate return (0); 8080Sstevel@tonic-gate } 8090Sstevel@tonic-gate 8100Sstevel@tonic-gate static char * 8110Sstevel@tonic-gate lxml_get_envvar(xmlNodePtr envvar) 8120Sstevel@tonic-gate { 8130Sstevel@tonic-gate char *name; 8140Sstevel@tonic-gate char *value; 8150Sstevel@tonic-gate char *ret; 8160Sstevel@tonic-gate 8177887SLiane.Praza@Sun.COM name = (char *)xmlGetProp(envvar, (xmlChar *)name_attr); 8187887SLiane.Praza@Sun.COM value = (char *)xmlGetProp(envvar, (xmlChar *)value_attr); 8190Sstevel@tonic-gate 8200Sstevel@tonic-gate if (strlen(name) == 0 || strchr(name, '=') != NULL) 8210Sstevel@tonic-gate uu_die(gettext("Invalid environment variable " 8220Sstevel@tonic-gate "\"%s\".\n"), name); 8230Sstevel@tonic-gate if (strstr(name, "SMF_") == name) 8240Sstevel@tonic-gate uu_die(gettext("Invalid environment variable " 8250Sstevel@tonic-gate "\"%s\"; \"SMF_\" prefix is reserved.\n"), name); 8260Sstevel@tonic-gate 8270Sstevel@tonic-gate ret = uu_msprintf("%s=%s", name, value); 8280Sstevel@tonic-gate xmlFree(name); 8290Sstevel@tonic-gate xmlFree(value); 8300Sstevel@tonic-gate return (ret); 8310Sstevel@tonic-gate } 8320Sstevel@tonic-gate 8330Sstevel@tonic-gate static int 8340Sstevel@tonic-gate lxml_get_method_environment(pgroup_t *pg, xmlNodePtr environment) 8350Sstevel@tonic-gate { 8360Sstevel@tonic-gate property_t *p; 8370Sstevel@tonic-gate xmlNodePtr cursor; 8380Sstevel@tonic-gate value_t *val; 8390Sstevel@tonic-gate 8400Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_ENVIRONMENT, 8410Sstevel@tonic-gate SCF_TYPE_ASTRING, 0); 8420Sstevel@tonic-gate 8430Sstevel@tonic-gate for (cursor = environment->xmlChildrenNode; cursor != NULL; 8440Sstevel@tonic-gate cursor = cursor->next) { 8450Sstevel@tonic-gate char *tmp; 8460Sstevel@tonic-gate 8470Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 8480Sstevel@tonic-gate continue; 8490Sstevel@tonic-gate 8500Sstevel@tonic-gate if (lxml_xlate_element(cursor->name) != SC_METHOD_ENVVAR) 8510Sstevel@tonic-gate uu_die(gettext("illegal element \"%s\" on " 8520Sstevel@tonic-gate "method environment for \"%s\"\n"), 8530Sstevel@tonic-gate cursor->name, pg->sc_pgroup_name); 8540Sstevel@tonic-gate 8550Sstevel@tonic-gate if ((tmp = lxml_get_envvar(cursor)) == NULL) 8560Sstevel@tonic-gate uu_die(gettext("Out of memory\n")); 8570Sstevel@tonic-gate 8580Sstevel@tonic-gate val = internal_value_new(); 8590Sstevel@tonic-gate val->sc_u.sc_string = tmp; 8600Sstevel@tonic-gate val->sc_type = SCF_TYPE_ASTRING; 8610Sstevel@tonic-gate val->sc_free = lxml_free_str; 8620Sstevel@tonic-gate internal_attach_value(p, val); 8630Sstevel@tonic-gate } 8640Sstevel@tonic-gate 8650Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0) { 8660Sstevel@tonic-gate internal_property_free(p); 8670Sstevel@tonic-gate return (-1); 8680Sstevel@tonic-gate } 8690Sstevel@tonic-gate 8700Sstevel@tonic-gate return (0); 8710Sstevel@tonic-gate } 8720Sstevel@tonic-gate 8730Sstevel@tonic-gate static int 8740Sstevel@tonic-gate lxml_get_method_context(pgroup_t *pg, xmlNodePtr ctx) 8750Sstevel@tonic-gate { 8760Sstevel@tonic-gate xmlNodePtr cursor; 8770Sstevel@tonic-gate 878*9263SSean.Wilcox@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_WORKING_DIRECTORY, 879*9263SSean.Wilcox@Sun.COM SCF_TYPE_ASTRING, ctx, "working_directory", NULL) != 0) 8800Sstevel@tonic-gate return (-1); 8810Sstevel@tonic-gate 882*9263SSean.Wilcox@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_PROJECT, 883*9263SSean.Wilcox@Sun.COM SCF_TYPE_ASTRING, ctx, "project", NULL) != 0) 8840Sstevel@tonic-gate return (-1); 8850Sstevel@tonic-gate 886*9263SSean.Wilcox@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_RESOURCE_POOL, 887*9263SSean.Wilcox@Sun.COM SCF_TYPE_ASTRING, ctx, "resource_pool", NULL) != 0) 8880Sstevel@tonic-gate return (-1); 8890Sstevel@tonic-gate 8900Sstevel@tonic-gate for (cursor = ctx->xmlChildrenNode; cursor != NULL; 8910Sstevel@tonic-gate cursor = cursor->next) { 8920Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 8930Sstevel@tonic-gate continue; 8940Sstevel@tonic-gate 8950Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) { 8960Sstevel@tonic-gate case SC_METHOD_CREDENTIAL: 8970Sstevel@tonic-gate (void) lxml_get_method_credential(pg, cursor); 8980Sstevel@tonic-gate break; 8990Sstevel@tonic-gate case SC_METHOD_PROFILE: 9000Sstevel@tonic-gate (void) lxml_get_method_profile(pg, cursor); 9010Sstevel@tonic-gate break; 9020Sstevel@tonic-gate case SC_METHOD_ENVIRONMENT: 9030Sstevel@tonic-gate (void) lxml_get_method_environment(pg, cursor); 9040Sstevel@tonic-gate break; 9050Sstevel@tonic-gate default: 9060Sstevel@tonic-gate semerr(gettext("illegal element \'%s\' in method " 9070Sstevel@tonic-gate "context\n"), (char *)cursor); 9080Sstevel@tonic-gate break; 9090Sstevel@tonic-gate } 9100Sstevel@tonic-gate } 9110Sstevel@tonic-gate 9120Sstevel@tonic-gate return (0); 9130Sstevel@tonic-gate } 9140Sstevel@tonic-gate 9150Sstevel@tonic-gate static int 9160Sstevel@tonic-gate lxml_get_entity_method_context(entity_t *entity, xmlNodePtr ctx) 9170Sstevel@tonic-gate { 9180Sstevel@tonic-gate pgroup_t *pg; 9190Sstevel@tonic-gate 9200Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, SCF_PG_METHOD_CONTEXT, 9210Sstevel@tonic-gate (char *)scf_group_framework); 9220Sstevel@tonic-gate 9230Sstevel@tonic-gate return (lxml_get_method_context(pg, ctx)); 9240Sstevel@tonic-gate } 9250Sstevel@tonic-gate 9260Sstevel@tonic-gate static int 9270Sstevel@tonic-gate lxml_get_exec_method(entity_t *entity, xmlNodePtr emeth) 9280Sstevel@tonic-gate { 9290Sstevel@tonic-gate pgroup_t *pg; 9300Sstevel@tonic-gate property_t *p; 9310Sstevel@tonic-gate xmlChar *name, *timeout, *delete; 9320Sstevel@tonic-gate xmlNodePtr cursor; 9330Sstevel@tonic-gate int r = 0; 9340Sstevel@tonic-gate 9350Sstevel@tonic-gate name = xmlGetProp(emeth, (xmlChar *)name_attr); 9360Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, (char *)name, 9370Sstevel@tonic-gate (char *)SCF_GROUP_METHOD); 9380Sstevel@tonic-gate xmlFree(name); 9390Sstevel@tonic-gate 9400Sstevel@tonic-gate if (new_str_prop_from_attr(pg, SCF_PROPERTY_TYPE, SCF_TYPE_ASTRING, 9410Sstevel@tonic-gate emeth, type_attr) != 0 || 9420Sstevel@tonic-gate new_str_prop_from_attr(pg, SCF_PROPERTY_EXEC, SCF_TYPE_ASTRING, 9430Sstevel@tonic-gate emeth, "exec") != 0) 9440Sstevel@tonic-gate return (-1); 9450Sstevel@tonic-gate 9467887SLiane.Praza@Sun.COM timeout = xmlGetProp(emeth, (xmlChar *)timeout_seconds_attr); 9470Sstevel@tonic-gate if (timeout != NULL) { 9480Sstevel@tonic-gate uint64_t u_timeout; 9490Sstevel@tonic-gate char *endptr; 9500Sstevel@tonic-gate /* 9510Sstevel@tonic-gate * Although an SC_COUNT represents a uint64_t the use 9520Sstevel@tonic-gate * of a negative value is acceptable due to the usage 9530Sstevel@tonic-gate * established by inetd(1M). 9540Sstevel@tonic-gate */ 9550Sstevel@tonic-gate errno = 0; 9560Sstevel@tonic-gate u_timeout = strtoull((char *)timeout, &endptr, 10); 9570Sstevel@tonic-gate if (errno != 0 || endptr == (char *)timeout || *endptr) 9580Sstevel@tonic-gate uu_die(gettext("illegal value \"%s\" for " 9590Sstevel@tonic-gate "timeout_seconds (%s)\n"), 9600Sstevel@tonic-gate (char *)timeout, (errno) ? strerror(errno): 9610Sstevel@tonic-gate gettext("Illegal character")); 9620Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_TIMEOUT, 9630Sstevel@tonic-gate SCF_TYPE_COUNT, 1, u_timeout); 9640Sstevel@tonic-gate r = internal_attach_property(pg, p); 9650Sstevel@tonic-gate xmlFree(timeout); 9660Sstevel@tonic-gate } 9670Sstevel@tonic-gate if (r != 0) 9680Sstevel@tonic-gate return (-1); 9690Sstevel@tonic-gate 9700Sstevel@tonic-gate /* 9710Sstevel@tonic-gate * There is a possibility that a method context also exists, in which 9720Sstevel@tonic-gate * case the following attributes are defined: project, resource_pool, 9730Sstevel@tonic-gate * working_directory, profile, user, group, privileges, limit_privileges 9740Sstevel@tonic-gate */ 9750Sstevel@tonic-gate for (cursor = emeth->xmlChildrenNode; cursor != NULL; 9760Sstevel@tonic-gate cursor = cursor->next) { 9770Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 9780Sstevel@tonic-gate continue; 9790Sstevel@tonic-gate 9800Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) { 9810Sstevel@tonic-gate case SC_STABILITY: 9820Sstevel@tonic-gate if (lxml_get_pgroup_stability(pg, cursor) != 0) 9830Sstevel@tonic-gate return (-1); 9840Sstevel@tonic-gate break; 9850Sstevel@tonic-gate 9860Sstevel@tonic-gate case SC_METHOD_CONTEXT: 9870Sstevel@tonic-gate (void) lxml_get_method_context(pg, cursor); 9880Sstevel@tonic-gate break; 9890Sstevel@tonic-gate 9900Sstevel@tonic-gate case SC_PROPVAL: 9910Sstevel@tonic-gate (void) lxml_get_propval(pg, cursor); 9920Sstevel@tonic-gate break; 9930Sstevel@tonic-gate 9940Sstevel@tonic-gate case SC_PROPERTY: 9950Sstevel@tonic-gate (void) lxml_get_property(pg, cursor); 9960Sstevel@tonic-gate break; 9970Sstevel@tonic-gate 9980Sstevel@tonic-gate default: 9990Sstevel@tonic-gate uu_die(gettext("illegal element \"%s\" on " 10000Sstevel@tonic-gate "execution method \"%s\"\n"), cursor->name, 10010Sstevel@tonic-gate pg->sc_pgroup_name); 10020Sstevel@tonic-gate break; 10030Sstevel@tonic-gate } 10040Sstevel@tonic-gate } 10050Sstevel@tonic-gate 10060Sstevel@tonic-gate delete = xmlGetProp(emeth, (xmlChar *)delete_attr); 10070Sstevel@tonic-gate pg->sc_pgroup_delete = (xmlStrcmp(delete, (xmlChar *)true) == 0); 10080Sstevel@tonic-gate xmlFree(delete); 10090Sstevel@tonic-gate 10100Sstevel@tonic-gate return (0); 10110Sstevel@tonic-gate } 10120Sstevel@tonic-gate 10130Sstevel@tonic-gate static int 10140Sstevel@tonic-gate lxml_get_dependency(entity_t *entity, xmlNodePtr dependency) 10150Sstevel@tonic-gate { 10160Sstevel@tonic-gate pgroup_t *pg; 10170Sstevel@tonic-gate property_t *p; 10180Sstevel@tonic-gate xmlNodePtr cursor; 10190Sstevel@tonic-gate xmlChar *name; 10200Sstevel@tonic-gate xmlChar *delete; 10210Sstevel@tonic-gate 10220Sstevel@tonic-gate /* 10230Sstevel@tonic-gate * dependency attributes: 10240Sstevel@tonic-gate * name: string 10250Sstevel@tonic-gate * grouping: require_all | require_any | exclude_all | optional_all 10260Sstevel@tonic-gate * reset_on: string (error | restart | refresh | none) 10270Sstevel@tonic-gate * type: service / path /host 10280Sstevel@tonic-gate */ 10290Sstevel@tonic-gate 10300Sstevel@tonic-gate name = xmlGetProp(dependency, (xmlChar *)name_attr); 10310Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, (char *)name, 10320Sstevel@tonic-gate (char *)SCF_GROUP_DEPENDENCY); 10330Sstevel@tonic-gate xmlFree(name); 10340Sstevel@tonic-gate 10350Sstevel@tonic-gate if (new_str_prop_from_attr(pg, SCF_PROPERTY_TYPE, SCF_TYPE_ASTRING, 10360Sstevel@tonic-gate dependency, type_attr) != 0) 10370Sstevel@tonic-gate return (-1); 10380Sstevel@tonic-gate 10390Sstevel@tonic-gate if (new_str_prop_from_attr(pg, SCF_PROPERTY_RESTART_ON, 10400Sstevel@tonic-gate SCF_TYPE_ASTRING, dependency, "restart_on") != 0) 10410Sstevel@tonic-gate return (-1); 10420Sstevel@tonic-gate 10430Sstevel@tonic-gate if (new_str_prop_from_attr(pg, SCF_PROPERTY_GROUPING, SCF_TYPE_ASTRING, 10440Sstevel@tonic-gate dependency, "grouping") != 0) 10450Sstevel@tonic-gate return (-1); 10460Sstevel@tonic-gate 10470Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_ENTITIES, SCF_TYPE_FMRI, 0); 10480Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0) 10490Sstevel@tonic-gate return (-1); 10500Sstevel@tonic-gate 10510Sstevel@tonic-gate for (cursor = dependency->xmlChildrenNode; cursor != NULL; 10520Sstevel@tonic-gate cursor = cursor->next) { 10530Sstevel@tonic-gate xmlChar *value; 10540Sstevel@tonic-gate value_t *v; 10550Sstevel@tonic-gate 10560Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 10570Sstevel@tonic-gate continue; 10580Sstevel@tonic-gate 10590Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) { 10600Sstevel@tonic-gate case SC_STABILITY: 10610Sstevel@tonic-gate if (lxml_get_pgroup_stability(pg, cursor) != 0) 10620Sstevel@tonic-gate return (-1); 10630Sstevel@tonic-gate break; 10640Sstevel@tonic-gate 10650Sstevel@tonic-gate case SC_SERVICE_FMRI: 10660Sstevel@tonic-gate value = xmlGetProp(cursor, (xmlChar *)value_attr); 10670Sstevel@tonic-gate if (value != NULL) { 10680Sstevel@tonic-gate if (lxml_validate_string_value(SCF_TYPE_FMRI, 10690Sstevel@tonic-gate (char *)value) != 0) 10700Sstevel@tonic-gate uu_die(gettext("illegal value \"%s\" " 10710Sstevel@tonic-gate "for %s (%s)\n"), (char *)value, 10720Sstevel@tonic-gate lxml_prop_types[SC_FMRI], 10730Sstevel@tonic-gate (scf_error()) ? 10740Sstevel@tonic-gate scf_strerror(scf_error()) : 10750Sstevel@tonic-gate gettext("Illegal format")); 10760Sstevel@tonic-gate v = internal_value_new(); 10770Sstevel@tonic-gate v->sc_type = SCF_TYPE_FMRI; 10780Sstevel@tonic-gate v->sc_u.sc_string = (char *)value; 10790Sstevel@tonic-gate internal_attach_value(p, v); 10800Sstevel@tonic-gate } 10810Sstevel@tonic-gate 10820Sstevel@tonic-gate break; 10830Sstevel@tonic-gate 10840Sstevel@tonic-gate case SC_PROPVAL: 10850Sstevel@tonic-gate (void) lxml_get_propval(pg, cursor); 10860Sstevel@tonic-gate break; 10870Sstevel@tonic-gate 10880Sstevel@tonic-gate case SC_PROPERTY: 10890Sstevel@tonic-gate (void) lxml_get_property(pg, cursor); 10900Sstevel@tonic-gate break; 10910Sstevel@tonic-gate 10920Sstevel@tonic-gate default: 10930Sstevel@tonic-gate uu_die(gettext("illegal element \"%s\" on " 10940Sstevel@tonic-gate "dependency group \"%s\"\n"), cursor->name, name); 10950Sstevel@tonic-gate break; 10960Sstevel@tonic-gate } 10970Sstevel@tonic-gate } 10980Sstevel@tonic-gate 10990Sstevel@tonic-gate delete = xmlGetProp(dependency, (xmlChar *)delete_attr); 11000Sstevel@tonic-gate pg->sc_pgroup_delete = (xmlStrcmp(delete, (xmlChar *)true) == 0); 11010Sstevel@tonic-gate xmlFree(delete); 11020Sstevel@tonic-gate 11030Sstevel@tonic-gate return (0); 11040Sstevel@tonic-gate } 11050Sstevel@tonic-gate 11060Sstevel@tonic-gate /* 11070Sstevel@tonic-gate * Dependents are hairy. They should cause a dependency pg to be created in 11080Sstevel@tonic-gate * another service, but we can't do that here; we'll have to wait until the 11090Sstevel@tonic-gate * import routines. So for now we'll add the dependency group that should go 11100Sstevel@tonic-gate * in the other service to the entity's dependent list. 11110Sstevel@tonic-gate */ 11120Sstevel@tonic-gate static int 11130Sstevel@tonic-gate lxml_get_dependent(entity_t *entity, xmlNodePtr dependent) 11140Sstevel@tonic-gate { 11150Sstevel@tonic-gate xmlChar *name, *or; 11160Sstevel@tonic-gate xmlNodePtr sf; 11170Sstevel@tonic-gate xmlChar *fmri, *delete; 11180Sstevel@tonic-gate pgroup_t *pg; 11190Sstevel@tonic-gate property_t *p; 11200Sstevel@tonic-gate xmlNodePtr n; 11210Sstevel@tonic-gate char *myfmri; 11220Sstevel@tonic-gate 11230Sstevel@tonic-gate name = xmlGetProp(dependent, (xmlChar *)name_attr); 11240Sstevel@tonic-gate 11250Sstevel@tonic-gate if (internal_pgroup_find(entity, (char *)name, NULL) != NULL) { 11260Sstevel@tonic-gate semerr(gettext("Property group and dependent of entity %s " 11270Sstevel@tonic-gate "have same name \"%s\".\n"), entity->sc_name, name); 11280Sstevel@tonic-gate xmlFree(name); 11290Sstevel@tonic-gate return (-1); 11300Sstevel@tonic-gate } 11310Sstevel@tonic-gate 11320Sstevel@tonic-gate or = xmlGetProp(dependent, (xmlChar *)override_attr); 11330Sstevel@tonic-gate 11340Sstevel@tonic-gate pg = internal_pgroup_new(); 11350Sstevel@tonic-gate pg->sc_pgroup_name = (char *)name; 11360Sstevel@tonic-gate pg->sc_pgroup_type = (char *)SCF_GROUP_DEPENDENCY; 11370Sstevel@tonic-gate pg->sc_pgroup_override = (xmlStrcmp(or, (xmlChar *)true) == 0); 11380Sstevel@tonic-gate xmlFree(or); 11390Sstevel@tonic-gate if (internal_attach_dependent(entity, pg) != 0) { 11400Sstevel@tonic-gate xmlFree(name); 11410Sstevel@tonic-gate internal_pgroup_free(pg); 11420Sstevel@tonic-gate return (-1); 11430Sstevel@tonic-gate } 11440Sstevel@tonic-gate 11450Sstevel@tonic-gate for (sf = dependent->children; sf != NULL; sf = sf->next) 11460Sstevel@tonic-gate if (xmlStrcmp(sf->name, (xmlChar *)"service_fmri") == 0) 11470Sstevel@tonic-gate break; 11480Sstevel@tonic-gate assert(sf != NULL); 11490Sstevel@tonic-gate fmri = xmlGetProp(sf, (xmlChar *)value_attr); 11500Sstevel@tonic-gate pg->sc_pgroup_fmri = (char *)fmri; 11510Sstevel@tonic-gate 11520Sstevel@tonic-gate if (new_str_prop_from_attr(pg, SCF_PROPERTY_RESTART_ON, 11530Sstevel@tonic-gate SCF_TYPE_ASTRING, dependent, "restart_on") != 0) 11540Sstevel@tonic-gate return (-1); 11550Sstevel@tonic-gate 11560Sstevel@tonic-gate if (new_str_prop_from_attr(pg, SCF_PROPERTY_GROUPING, SCF_TYPE_ASTRING, 11570Sstevel@tonic-gate dependent, "grouping") != 0) 11580Sstevel@tonic-gate return (-1); 11590Sstevel@tonic-gate 11600Sstevel@tonic-gate myfmri = safe_malloc(max_scf_fmri_len + 1); 11610Sstevel@tonic-gate if (entity->sc_etype == SVCCFG_SERVICE_OBJECT) { 11620Sstevel@tonic-gate if (snprintf(myfmri, max_scf_fmri_len + 1, "svc:/%s", 11630Sstevel@tonic-gate entity->sc_name) < 0) 11640Sstevel@tonic-gate bad_error("snprintf", errno); 11650Sstevel@tonic-gate } else { 11660Sstevel@tonic-gate assert(entity->sc_etype == SVCCFG_INSTANCE_OBJECT); 11670Sstevel@tonic-gate if (snprintf(myfmri, max_scf_fmri_len + 1, "svc:/%s:%s", 11680Sstevel@tonic-gate entity->sc_parent->sc_name, entity->sc_name) < 0) 11690Sstevel@tonic-gate bad_error("snprintf", errno); 11700Sstevel@tonic-gate } 11710Sstevel@tonic-gate 11720Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_ENTITIES, SCF_TYPE_FMRI, 1, 11730Sstevel@tonic-gate myfmri); 11740Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0) 11750Sstevel@tonic-gate return (-1); 11760Sstevel@tonic-gate 11770Sstevel@tonic-gate /* Create a property to serve as a do-not-export flag. */ 11780Sstevel@tonic-gate p = internal_property_create("external", SCF_TYPE_BOOLEAN, 1, 11790Sstevel@tonic-gate (uint64_t)1); 11800Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0) 11810Sstevel@tonic-gate return (-1); 11820Sstevel@tonic-gate 11830Sstevel@tonic-gate for (n = sf->next; n != NULL; n = n->next) { 11840Sstevel@tonic-gate if (lxml_ignorable_block(n)) 11850Sstevel@tonic-gate continue; 11860Sstevel@tonic-gate 11870Sstevel@tonic-gate switch (lxml_xlate_element(n->name)) { 11880Sstevel@tonic-gate case SC_STABILITY: 11890Sstevel@tonic-gate if (new_str_prop_from_attr(pg, 11900Sstevel@tonic-gate SCF_PROPERTY_ENTITY_STABILITY, SCF_TYPE_ASTRING, n, 11910Sstevel@tonic-gate value_attr) != 0) 11920Sstevel@tonic-gate return (-1); 11930Sstevel@tonic-gate break; 11940Sstevel@tonic-gate 11950Sstevel@tonic-gate case SC_PROPVAL: 11960Sstevel@tonic-gate (void) lxml_get_propval(pg, n); 11970Sstevel@tonic-gate break; 11980Sstevel@tonic-gate 11990Sstevel@tonic-gate case SC_PROPERTY: 12000Sstevel@tonic-gate (void) lxml_get_property(pg, n); 12010Sstevel@tonic-gate break; 12020Sstevel@tonic-gate 12030Sstevel@tonic-gate default: 12040Sstevel@tonic-gate uu_die(gettext("unexpected element %s.\n"), n->name); 12050Sstevel@tonic-gate } 12060Sstevel@tonic-gate } 12070Sstevel@tonic-gate 12080Sstevel@tonic-gate /* Go back and fill in defaults. */ 12090Sstevel@tonic-gate if (internal_property_find(pg, SCF_PROPERTY_TYPE) == NULL) { 12100Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_TYPE, 12110Sstevel@tonic-gate SCF_TYPE_ASTRING, 1, "service"); 12120Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0) 12130Sstevel@tonic-gate return (-1); 12140Sstevel@tonic-gate } 12150Sstevel@tonic-gate 12160Sstevel@tonic-gate delete = xmlGetProp(dependent, (xmlChar *)delete_attr); 12170Sstevel@tonic-gate pg->sc_pgroup_delete = (xmlStrcmp(delete, (xmlChar *)true) == 0); 12180Sstevel@tonic-gate xmlFree(delete); 12190Sstevel@tonic-gate 12200Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, "dependents", 12210Sstevel@tonic-gate (char *)scf_group_framework); 1222306Sbustos p = internal_property_create((char *)name, SCF_TYPE_FMRI, 1, fmri); 12230Sstevel@tonic-gate if (internal_attach_property(pg, p) != 0) 12240Sstevel@tonic-gate return (-1); 12250Sstevel@tonic-gate 12260Sstevel@tonic-gate return (0); 12270Sstevel@tonic-gate } 12280Sstevel@tonic-gate 12290Sstevel@tonic-gate static int 12300Sstevel@tonic-gate lxml_get_entity_stability(entity_t *entity, xmlNodePtr rstr) 12310Sstevel@tonic-gate { 12320Sstevel@tonic-gate pgroup_t *pg; 12330Sstevel@tonic-gate property_t *p; 12340Sstevel@tonic-gate xmlChar *stabval; 12350Sstevel@tonic-gate 12367887SLiane.Praza@Sun.COM if (((stabval = xmlGetProp(rstr, (xmlChar *)value_attr)) == NULL) || 12377887SLiane.Praza@Sun.COM (*stabval == 0)) { 12380Sstevel@tonic-gate uu_warn(gettext("no stability value found\n")); 12390Sstevel@tonic-gate stabval = (xmlChar *)strdup("External"); 12400Sstevel@tonic-gate } 12410Sstevel@tonic-gate 12420Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, (char *)scf_pg_general, 12430Sstevel@tonic-gate (char *)scf_group_framework); 12440Sstevel@tonic-gate 12450Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_ENTITY_STABILITY, 12460Sstevel@tonic-gate SCF_TYPE_ASTRING, 1, stabval); 12470Sstevel@tonic-gate 12480Sstevel@tonic-gate return (internal_attach_property(pg, p)); 12490Sstevel@tonic-gate } 12500Sstevel@tonic-gate 12510Sstevel@tonic-gate static int 12520Sstevel@tonic-gate lxml_get_restarter(entity_t *entity, xmlNodePtr rstr) 12530Sstevel@tonic-gate { 12540Sstevel@tonic-gate pgroup_t *pg; 12550Sstevel@tonic-gate property_t *p; 12560Sstevel@tonic-gate xmlChar *restarter; 12570Sstevel@tonic-gate xmlNode *cursor; 12580Sstevel@tonic-gate int r; 12590Sstevel@tonic-gate 12600Sstevel@tonic-gate /* 12610Sstevel@tonic-gate * Go find child. Child is a service_fmri element. value attribute 12620Sstevel@tonic-gate * contains restarter FMRI. 12630Sstevel@tonic-gate */ 12640Sstevel@tonic-gate 12650Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, (char *)scf_pg_general, 12660Sstevel@tonic-gate (char *)scf_group_framework); 12670Sstevel@tonic-gate 12680Sstevel@tonic-gate /* 12690Sstevel@tonic-gate * Walk its child elements, as appropriate. 12700Sstevel@tonic-gate */ 12710Sstevel@tonic-gate for (cursor = rstr->xmlChildrenNode; cursor != NULL; 12720Sstevel@tonic-gate cursor = cursor->next) { 12730Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 12740Sstevel@tonic-gate continue; 12750Sstevel@tonic-gate 12760Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) { 12770Sstevel@tonic-gate case SC_SERVICE_FMRI: 12780Sstevel@tonic-gate restarter = xmlGetProp(cursor, (xmlChar *)value_attr); 12790Sstevel@tonic-gate break; 12800Sstevel@tonic-gate default: 12810Sstevel@tonic-gate uu_die(gettext("illegal element \"%s\" on restarter " 12820Sstevel@tonic-gate "element for \"%s\"\n"), cursor->name, 12830Sstevel@tonic-gate entity->sc_name); 12840Sstevel@tonic-gate break; 12850Sstevel@tonic-gate } 12860Sstevel@tonic-gate } 12870Sstevel@tonic-gate 12880Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_RESTARTER, SCF_TYPE_FMRI, 1, 12890Sstevel@tonic-gate restarter); 12900Sstevel@tonic-gate 12910Sstevel@tonic-gate r = internal_attach_property(pg, p); 12920Sstevel@tonic-gate if (r != 0) { 12930Sstevel@tonic-gate internal_property_free(p); 12940Sstevel@tonic-gate return (-1); 12950Sstevel@tonic-gate } 12960Sstevel@tonic-gate 12970Sstevel@tonic-gate return (0); 12980Sstevel@tonic-gate } 12990Sstevel@tonic-gate 13007887SLiane.Praza@Sun.COM /* 13017887SLiane.Praza@Sun.COM * Add a property containing the localized text from the manifest. The 13027887SLiane.Praza@Sun.COM * property is added to the property group at pg. The name of the created 13037887SLiane.Praza@Sun.COM * property is based on the format at pn_format. This is an snprintf(3C) 13047887SLiane.Praza@Sun.COM * format containing a single %s conversion specification. At conversion 13057887SLiane.Praza@Sun.COM * time, the %s is replaced by the locale designation. 13067887SLiane.Praza@Sun.COM * 13077887SLiane.Praza@Sun.COM * source is the source element and it is only used for error messages. 13087887SLiane.Praza@Sun.COM */ 13097887SLiane.Praza@Sun.COM static int 13107887SLiane.Praza@Sun.COM lxml_get_loctext(entity_t *service, pgroup_t *pg, xmlNodePtr loctext, 13117887SLiane.Praza@Sun.COM const char *pn_format, const char *source) 13120Sstevel@tonic-gate { 13137887SLiane.Praza@Sun.COM int extra; 13140Sstevel@tonic-gate xmlNodePtr cursor; 13150Sstevel@tonic-gate xmlChar *val; 13160Sstevel@tonic-gate char *stripped, *cp; 13170Sstevel@tonic-gate property_t *p; 13187887SLiane.Praza@Sun.COM char *prop_name; 13190Sstevel@tonic-gate int r; 13200Sstevel@tonic-gate 13217887SLiane.Praza@Sun.COM if (((val = xmlGetProp(loctext, (xmlChar *)xml_lang_attr)) == NULL) || 13227887SLiane.Praza@Sun.COM (*val == 0)) { 13237887SLiane.Praza@Sun.COM if (((val = xmlGetProp(loctext, 13247887SLiane.Praza@Sun.COM (xmlChar *)lang_attr)) == NULL) || (*val == 0)) { 13250Sstevel@tonic-gate val = (xmlChar *)"unknown"; 13267887SLiane.Praza@Sun.COM } 13277887SLiane.Praza@Sun.COM } 13287887SLiane.Praza@Sun.COM 13297887SLiane.Praza@Sun.COM _scf_sanitize_locale((char *)val); 13307887SLiane.Praza@Sun.COM prop_name = safe_malloc(max_scf_name_len + 1); 13317887SLiane.Praza@Sun.COM if ((extra = snprintf(prop_name, max_scf_name_len + 1, pn_format, 13327887SLiane.Praza@Sun.COM val)) >= max_scf_name_len + 1) { 13337887SLiane.Praza@Sun.COM extra -= max_scf_name_len; 13347887SLiane.Praza@Sun.COM uu_die(gettext("%s attribute is %d characters too long for " 13357887SLiane.Praza@Sun.COM "%s in %s\n"), 13367887SLiane.Praza@Sun.COM xml_lang_attr, extra, source, service->sc_name); 13377887SLiane.Praza@Sun.COM } 13387887SLiane.Praza@Sun.COM xmlFree(val); 13390Sstevel@tonic-gate 13400Sstevel@tonic-gate for (cursor = loctext->xmlChildrenNode; cursor != NULL; 13410Sstevel@tonic-gate cursor = cursor->next) { 13420Sstevel@tonic-gate if (strcmp("text", (const char *)cursor->name) == 0) { 13430Sstevel@tonic-gate break; 13440Sstevel@tonic-gate } else if (strcmp("comment", (const char *)cursor->name) != 0) { 13450Sstevel@tonic-gate uu_die(gettext("illegal element \"%s\" on loctext " 13460Sstevel@tonic-gate "element for \"%s\"\n"), cursor->name, 13470Sstevel@tonic-gate service->sc_name); 13480Sstevel@tonic-gate } 13490Sstevel@tonic-gate } 13500Sstevel@tonic-gate 13510Sstevel@tonic-gate if (cursor == NULL) { 13520Sstevel@tonic-gate uu_die(gettext("loctext element has no content for \"%s\"\n"), 13530Sstevel@tonic-gate service->sc_name); 13540Sstevel@tonic-gate } 13550Sstevel@tonic-gate 13560Sstevel@tonic-gate /* 13570Sstevel@tonic-gate * Remove leading and trailing whitespace. 13580Sstevel@tonic-gate */ 13590Sstevel@tonic-gate if ((stripped = strdup((const char *)cursor->content)) == NULL) 13600Sstevel@tonic-gate uu_die(gettext("Out of memory\n")); 13610Sstevel@tonic-gate 13624740Sjeanm for (; isspace(*stripped); stripped++) 13634740Sjeanm ; 13644740Sjeanm for (cp = stripped + strlen(stripped) - 1; isspace(*cp); cp--) 13654740Sjeanm ; 13660Sstevel@tonic-gate *(cp + 1) = '\0'; 13670Sstevel@tonic-gate 13687887SLiane.Praza@Sun.COM p = internal_property_create(prop_name, SCF_TYPE_USTRING, 1, 13690Sstevel@tonic-gate stripped); 13700Sstevel@tonic-gate 13710Sstevel@tonic-gate r = internal_attach_property(pg, p); 13727887SLiane.Praza@Sun.COM if (r != 0) { 13730Sstevel@tonic-gate internal_property_free(p); 13747887SLiane.Praza@Sun.COM free(prop_name); 13757887SLiane.Praza@Sun.COM } 13760Sstevel@tonic-gate 13770Sstevel@tonic-gate return (r); 13780Sstevel@tonic-gate } 13790Sstevel@tonic-gate 13807887SLiane.Praza@Sun.COM /* 13817887SLiane.Praza@Sun.COM * This function processes all loctext elements in the current XML element 13827887SLiane.Praza@Sun.COM * designated by container. A property is created for each loctext element 13837887SLiane.Praza@Sun.COM * and added to the property group at pg. The name of the property is 13847887SLiane.Praza@Sun.COM * derived from the loctext language designation using the format at 13857887SLiane.Praza@Sun.COM * pn_format. pn_format should be an snprintf format string containing one 13867887SLiane.Praza@Sun.COM * %s which is replaced by the language designation. 13877887SLiane.Praza@Sun.COM * 13887887SLiane.Praza@Sun.COM * The function returns 0 on success and -1 if it is unable to attach the 13897887SLiane.Praza@Sun.COM * newly created property to pg. 13907887SLiane.Praza@Sun.COM */ 13910Sstevel@tonic-gate static int 13927887SLiane.Praza@Sun.COM lxml_get_all_loctext(entity_t *service, pgroup_t *pg, xmlNodePtr container, 13937887SLiane.Praza@Sun.COM const char *pn_format, const char *source) 13940Sstevel@tonic-gate { 13950Sstevel@tonic-gate xmlNodePtr cursor; 13960Sstevel@tonic-gate 13970Sstevel@tonic-gate /* 13987887SLiane.Praza@Sun.COM * Iterate through one or more loctext elements. The locale is 13997887SLiane.Praza@Sun.COM * used to generate the property name; the contents are the ustring 14007887SLiane.Praza@Sun.COM * value for the property. 14010Sstevel@tonic-gate */ 14027887SLiane.Praza@Sun.COM for (cursor = container->xmlChildrenNode; cursor != NULL; 14030Sstevel@tonic-gate cursor = cursor->next) { 14040Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 14050Sstevel@tonic-gate continue; 14060Sstevel@tonic-gate 14070Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) { 14080Sstevel@tonic-gate case SC_LOCTEXT: 14097887SLiane.Praza@Sun.COM if (lxml_get_loctext(service, pg, cursor, pn_format, 14107887SLiane.Praza@Sun.COM source)) 14110Sstevel@tonic-gate return (-1); 14120Sstevel@tonic-gate break; 14130Sstevel@tonic-gate default: 14147887SLiane.Praza@Sun.COM uu_die(gettext("illegal element \"%s\" on %s element " 14157887SLiane.Praza@Sun.COM "for \"%s\"\n"), cursor->name, container->name, 14160Sstevel@tonic-gate service->sc_name); 14170Sstevel@tonic-gate break; 14180Sstevel@tonic-gate } 14190Sstevel@tonic-gate } 14200Sstevel@tonic-gate 14210Sstevel@tonic-gate return (0); 14220Sstevel@tonic-gate } 14230Sstevel@tonic-gate 14247887SLiane.Praza@Sun.COM /* 14257887SLiane.Praza@Sun.COM * Obtain the specified cardinality attribute and place it in a property 14267887SLiane.Praza@Sun.COM * named prop_name. The converted attribute is placed at *value, and the 14277887SLiane.Praza@Sun.COM * newly created property is returned to propp. NULL is returned to propp 14287887SLiane.Praza@Sun.COM * if the attribute is not provided in the manifest. 14297887SLiane.Praza@Sun.COM * 14307887SLiane.Praza@Sun.COM * 0 is returned upon success, and -1 indicates that the manifest contained 14317887SLiane.Praza@Sun.COM * an invalid cardinality value. 14327887SLiane.Praza@Sun.COM */ 14330Sstevel@tonic-gate static int 14347887SLiane.Praza@Sun.COM lxml_get_cardinality_attribute(entity_t *service, xmlNodePtr cursor, 14357887SLiane.Praza@Sun.COM const char *attr_name, const char *prop_name, uint64_t *value, 14367887SLiane.Praza@Sun.COM property_t **propp) 14377887SLiane.Praza@Sun.COM { 14387887SLiane.Praza@Sun.COM char *c; 14397887SLiane.Praza@Sun.COM property_t *p; 14407887SLiane.Praza@Sun.COM xmlChar *val; 14417887SLiane.Praza@Sun.COM uint64_t count; 14427887SLiane.Praza@Sun.COM char *endptr; 14437887SLiane.Praza@Sun.COM 14447887SLiane.Praza@Sun.COM *propp = NULL; 14457887SLiane.Praza@Sun.COM val = xmlGetProp(cursor, (xmlChar *)attr_name); 14467887SLiane.Praza@Sun.COM if (val == NULL) 14477887SLiane.Praza@Sun.COM return (0); 14487887SLiane.Praza@Sun.COM if (*val == 0) { 14497887SLiane.Praza@Sun.COM xmlFree(val); 14507887SLiane.Praza@Sun.COM return (0); 14517887SLiane.Praza@Sun.COM } 14527887SLiane.Praza@Sun.COM 14537887SLiane.Praza@Sun.COM /* 14547887SLiane.Praza@Sun.COM * Make sure that the string at val doesn't have a leading minus 14557887SLiane.Praza@Sun.COM * sign. The strtoull() call below does not catch this problem. 14567887SLiane.Praza@Sun.COM */ 14577887SLiane.Praza@Sun.COM for (c = (char *)val; *c != 0; c++) { 14587887SLiane.Praza@Sun.COM if (isspace(*c)) 14597887SLiane.Praza@Sun.COM continue; 14607887SLiane.Praza@Sun.COM if (isdigit(*c)) 14617887SLiane.Praza@Sun.COM break; 14627887SLiane.Praza@Sun.COM semerr(gettext("\"%c\" is not a legal character in the %s " 14637887SLiane.Praza@Sun.COM "attribute of the %s element in %s.\n"), *c, 14647887SLiane.Praza@Sun.COM attr_name, prop_name, service->sc_name); 14657887SLiane.Praza@Sun.COM xmlFree(val); 14667887SLiane.Praza@Sun.COM return (-1); 14677887SLiane.Praza@Sun.COM } 14687887SLiane.Praza@Sun.COM errno = 0; 14697887SLiane.Praza@Sun.COM count = strtoull((char *)val, &endptr, 10); 14707887SLiane.Praza@Sun.COM if (errno != 0 || endptr == (char *)val || *endptr) { 14717887SLiane.Praza@Sun.COM semerr(gettext("\"%s\" is not a legal number for the %s " 14727887SLiane.Praza@Sun.COM "attribute of the %s element in %s.\n"), (char *)val, 14737887SLiane.Praza@Sun.COM attr_name, prop_name, service->sc_name); 14747887SLiane.Praza@Sun.COM xmlFree(val); 14757887SLiane.Praza@Sun.COM return (-1); 14767887SLiane.Praza@Sun.COM } 14777887SLiane.Praza@Sun.COM 14787887SLiane.Praza@Sun.COM xmlFree(val); 14797887SLiane.Praza@Sun.COM 14807887SLiane.Praza@Sun.COM /* Value is valid. Create the property. */ 14817887SLiane.Praza@Sun.COM p = internal_property_create(prop_name, SCF_TYPE_COUNT, 1, count); 14827887SLiane.Praza@Sun.COM *value = count; 14837887SLiane.Praza@Sun.COM *propp = p; 14847887SLiane.Praza@Sun.COM return (0); 14857887SLiane.Praza@Sun.COM } 14867887SLiane.Praza@Sun.COM 14877887SLiane.Praza@Sun.COM /* 14887887SLiane.Praza@Sun.COM * The cardinality is specified by two attributes max and min at cursor. 14897887SLiane.Praza@Sun.COM * Both are optional, but if present they must be unsigned integers. 14907887SLiane.Praza@Sun.COM */ 14917887SLiane.Praza@Sun.COM static int 14927887SLiane.Praza@Sun.COM lxml_get_tm_cardinality(entity_t *service, pgroup_t *pg, xmlNodePtr cursor) 14930Sstevel@tonic-gate { 14947887SLiane.Praza@Sun.COM int min_attached = 0; 14957887SLiane.Praza@Sun.COM int compare = 1; 14967887SLiane.Praza@Sun.COM property_t *min_prop; 14977887SLiane.Praza@Sun.COM property_t *max_prop; 14987887SLiane.Praza@Sun.COM uint64_t max; 14997887SLiane.Praza@Sun.COM uint64_t min; 15007887SLiane.Praza@Sun.COM int r; 15017887SLiane.Praza@Sun.COM 15027887SLiane.Praza@Sun.COM r = lxml_get_cardinality_attribute(service, cursor, min_attr, 15037887SLiane.Praza@Sun.COM SCF_PROPERTY_TM_CARDINALITY_MIN, &min, &min_prop); 15047887SLiane.Praza@Sun.COM if (r != 0) 15057887SLiane.Praza@Sun.COM return (r); 15067887SLiane.Praza@Sun.COM if (min_prop == NULL) 15077887SLiane.Praza@Sun.COM compare = 0; 15087887SLiane.Praza@Sun.COM r = lxml_get_cardinality_attribute(service, cursor, max_attr, 15097887SLiane.Praza@Sun.COM SCF_PROPERTY_TM_CARDINALITY_MAX, &max, &max_prop); 15107887SLiane.Praza@Sun.COM if (r != 0) 15117887SLiane.Praza@Sun.COM goto errout; 15127887SLiane.Praza@Sun.COM if ((max_prop != NULL) && (compare == 1)) { 15137887SLiane.Praza@Sun.COM if (max < min) { 15147887SLiane.Praza@Sun.COM semerr(gettext("Cardinality max is less than min for " 15157887SLiane.Praza@Sun.COM "the %s element in %s.\n"), pg->sc_pgroup_name, 15167887SLiane.Praza@Sun.COM service->sc_fmri); 15177887SLiane.Praza@Sun.COM goto errout; 15187887SLiane.Praza@Sun.COM } 15197887SLiane.Praza@Sun.COM } 15207887SLiane.Praza@Sun.COM 15217887SLiane.Praza@Sun.COM /* Attach the properties to the property group. */ 15227887SLiane.Praza@Sun.COM if (min_prop) { 15237887SLiane.Praza@Sun.COM if (internal_attach_property(pg, min_prop) == 0) { 15247887SLiane.Praza@Sun.COM min_attached = 1; 15257887SLiane.Praza@Sun.COM } else { 15267887SLiane.Praza@Sun.COM goto errout; 15277887SLiane.Praza@Sun.COM } 15287887SLiane.Praza@Sun.COM } 15297887SLiane.Praza@Sun.COM if (max_prop) { 15307887SLiane.Praza@Sun.COM if (internal_attach_property(pg, max_prop) != 0) { 15317887SLiane.Praza@Sun.COM if (min_attached) 15327887SLiane.Praza@Sun.COM internal_detach_property(pg, min_prop); 15337887SLiane.Praza@Sun.COM goto errout; 15347887SLiane.Praza@Sun.COM } 15357887SLiane.Praza@Sun.COM } 15367887SLiane.Praza@Sun.COM return (0); 15377887SLiane.Praza@Sun.COM 15387887SLiane.Praza@Sun.COM errout: 15397887SLiane.Praza@Sun.COM if (min_prop) 15407887SLiane.Praza@Sun.COM internal_property_free(min_prop); 15417887SLiane.Praza@Sun.COM if (max_prop) 15427887SLiane.Praza@Sun.COM internal_property_free(max_prop); 15437887SLiane.Praza@Sun.COM return (-1); 15447887SLiane.Praza@Sun.COM } 15457887SLiane.Praza@Sun.COM 15467887SLiane.Praza@Sun.COM /* 15477887SLiane.Praza@Sun.COM * Get the common_name which is present as localized text at common_name in 15487887SLiane.Praza@Sun.COM * the manifest. The common_name is stored as the value of a property in 15497887SLiane.Praza@Sun.COM * the property group whose name is SCF_PG_TM_COMMON_NAME and type is 15507887SLiane.Praza@Sun.COM * SCF_GROUP_TEMPLATE. This property group will be created in service if 15517887SLiane.Praza@Sun.COM * it is not already there. 15527887SLiane.Praza@Sun.COM */ 15537887SLiane.Praza@Sun.COM static int 15547887SLiane.Praza@Sun.COM lxml_get_tm_common_name(entity_t *service, xmlNodePtr common_name) 15557887SLiane.Praza@Sun.COM { 15560Sstevel@tonic-gate pgroup_t *pg; 15570Sstevel@tonic-gate 15580Sstevel@tonic-gate /* 15590Sstevel@tonic-gate * Create the property group, if absent. 15600Sstevel@tonic-gate */ 15617887SLiane.Praza@Sun.COM pg = internal_pgroup_find_or_create(service, SCF_PG_TM_COMMON_NAME, 15627887SLiane.Praza@Sun.COM SCF_GROUP_TEMPLATE); 15637887SLiane.Praza@Sun.COM 15647887SLiane.Praza@Sun.COM return (lxml_get_all_loctext(service, pg, common_name, LOCALE_ONLY_FMT, 15657887SLiane.Praza@Sun.COM "common_name")); 15667887SLiane.Praza@Sun.COM } 15677887SLiane.Praza@Sun.COM 15687887SLiane.Praza@Sun.COM /* 15697887SLiane.Praza@Sun.COM * Get the description which is present as localized text at description in 15707887SLiane.Praza@Sun.COM * the manifest. The description is stored as the value of a property in 15717887SLiane.Praza@Sun.COM * the property group whose name is SCF_PG_TM_DESCRIPTION and type is 15727887SLiane.Praza@Sun.COM * SCF_GROUP_TEMPLATE. This property group will be created in service if 15737887SLiane.Praza@Sun.COM * it is not already there. 15747887SLiane.Praza@Sun.COM */ 15757887SLiane.Praza@Sun.COM static int 15767887SLiane.Praza@Sun.COM lxml_get_tm_description(entity_t *service, xmlNodePtr description) 15777887SLiane.Praza@Sun.COM { 15787887SLiane.Praza@Sun.COM pgroup_t *pg; 15790Sstevel@tonic-gate 15800Sstevel@tonic-gate /* 15817887SLiane.Praza@Sun.COM * Create the property group, if absent. 15820Sstevel@tonic-gate */ 15837887SLiane.Praza@Sun.COM pg = internal_pgroup_find_or_create(service, SCF_PG_TM_DESCRIPTION, 15847887SLiane.Praza@Sun.COM SCF_GROUP_TEMPLATE); 15857887SLiane.Praza@Sun.COM 15867887SLiane.Praza@Sun.COM return (lxml_get_all_loctext(service, pg, description, 15877887SLiane.Praza@Sun.COM LOCALE_ONLY_FMT, "description")); 15880Sstevel@tonic-gate } 15890Sstevel@tonic-gate 15900Sstevel@tonic-gate static char * 15910Sstevel@tonic-gate lxml_label_to_groupname(const char *prefix, const char *in) 15920Sstevel@tonic-gate { 15930Sstevel@tonic-gate char *out, *cp; 15940Sstevel@tonic-gate size_t len, piece_len; 15950Sstevel@tonic-gate 15960Sstevel@tonic-gate out = uu_zalloc(2 * scf_limit(SCF_LIMIT_MAX_NAME_LENGTH) + 1); 15970Sstevel@tonic-gate if (out == NULL) 15980Sstevel@tonic-gate return (NULL); 15990Sstevel@tonic-gate 16000Sstevel@tonic-gate (void) strcpy(out, prefix); 16010Sstevel@tonic-gate (void) strcat(out, in); 16020Sstevel@tonic-gate 16030Sstevel@tonic-gate len = strlen(out); 16040Sstevel@tonic-gate if (len > max_scf_name_len) { 16050Sstevel@tonic-gate /* Use the first half and the second half. */ 16060Sstevel@tonic-gate piece_len = (max_scf_name_len - 2) / 2; 16070Sstevel@tonic-gate 16080Sstevel@tonic-gate (void) strncpy(out + piece_len, "..", 2); 16090Sstevel@tonic-gate 16100Sstevel@tonic-gate (void) strcpy(out + piece_len + 2, out + (len - piece_len)); 16110Sstevel@tonic-gate 16120Sstevel@tonic-gate len = strlen(out); 16130Sstevel@tonic-gate } 16140Sstevel@tonic-gate 16150Sstevel@tonic-gate /* 16160Sstevel@tonic-gate * Translate non-property characters to '_'. 16170Sstevel@tonic-gate */ 16180Sstevel@tonic-gate for (cp = out; *cp != '\0'; ++cp) { 16190Sstevel@tonic-gate if (!(isalnum(*cp) || *cp == '_' || *cp == '-')) 16200Sstevel@tonic-gate *cp = '_'; 16210Sstevel@tonic-gate } 16220Sstevel@tonic-gate 16230Sstevel@tonic-gate *cp = '\0'; 16240Sstevel@tonic-gate 16250Sstevel@tonic-gate return (out); 16260Sstevel@tonic-gate } 16270Sstevel@tonic-gate 16287887SLiane.Praza@Sun.COM /* 16297887SLiane.Praza@Sun.COM * If *p is NULL, astring_prop_value() first creates a property with the 16307887SLiane.Praza@Sun.COM * name specified in prop_name. The address of the newly created property 16317887SLiane.Praza@Sun.COM * is placed in *p. 16327887SLiane.Praza@Sun.COM * 16337887SLiane.Praza@Sun.COM * In either case, newly created property or existing property, a new 16347887SLiane.Praza@Sun.COM * SCF_TYPE_ASTRING value will created and attached to the property at *p. 16357887SLiane.Praza@Sun.COM * The value of the newly created property is prop_value. 16367887SLiane.Praza@Sun.COM * 16377887SLiane.Praza@Sun.COM * free_flag is used to indicate whether or not the memory at prop_value 16387887SLiane.Praza@Sun.COM * should be freed when the property is freed by a call to 16397887SLiane.Praza@Sun.COM * internal_property_free(). 16407887SLiane.Praza@Sun.COM */ 16417887SLiane.Praza@Sun.COM static void 16427887SLiane.Praza@Sun.COM astring_prop_value(property_t **p, const char *prop_name, char *prop_value, 16437887SLiane.Praza@Sun.COM boolean_t free_flag) 16447887SLiane.Praza@Sun.COM { 16457887SLiane.Praza@Sun.COM value_t *v; 16467887SLiane.Praza@Sun.COM 16477887SLiane.Praza@Sun.COM if (*p == NULL) { 16487887SLiane.Praza@Sun.COM /* Create the property */ 16497887SLiane.Praza@Sun.COM *p = internal_property_new(); 16507887SLiane.Praza@Sun.COM (*p)->sc_property_name = (char *)prop_name; 16517887SLiane.Praza@Sun.COM (*p)->sc_value_type = SCF_TYPE_ASTRING; 16527887SLiane.Praza@Sun.COM } 16537887SLiane.Praza@Sun.COM 16547887SLiane.Praza@Sun.COM /* Add the property value to the property's list of values. */ 16557887SLiane.Praza@Sun.COM v = internal_value_new(); 16567887SLiane.Praza@Sun.COM v->sc_type = SCF_TYPE_ASTRING; 16577887SLiane.Praza@Sun.COM if (free_flag == B_TRUE) 16587887SLiane.Praza@Sun.COM v->sc_free = lxml_free_str; 16597887SLiane.Praza@Sun.COM v->sc_u.sc_string = prop_value; 16607887SLiane.Praza@Sun.COM internal_attach_value(*p, v); 16617887SLiane.Praza@Sun.COM } 16627887SLiane.Praza@Sun.COM 16637887SLiane.Praza@Sun.COM /* 16647887SLiane.Praza@Sun.COM * If p points to a null pointer, create an internal_separators property 16657887SLiane.Praza@Sun.COM * saving the address at p. For each character at seps create a property 16667887SLiane.Praza@Sun.COM * value and attach it to the property at p. 16677887SLiane.Praza@Sun.COM */ 16687887SLiane.Praza@Sun.COM static void 16697887SLiane.Praza@Sun.COM seps_to_prop_values(property_t **p, xmlChar *seps) 16707887SLiane.Praza@Sun.COM { 16717887SLiane.Praza@Sun.COM value_t *v; 16727887SLiane.Praza@Sun.COM char val_str[2]; 16737887SLiane.Praza@Sun.COM 16747887SLiane.Praza@Sun.COM if (*p == NULL) { 16757887SLiane.Praza@Sun.COM *p = internal_property_new(); 16767887SLiane.Praza@Sun.COM (*p)->sc_property_name = 16777887SLiane.Praza@Sun.COM (char *)SCF_PROPERTY_INTERNAL_SEPARATORS; 16787887SLiane.Praza@Sun.COM (*p)->sc_value_type = SCF_TYPE_ASTRING; 16797887SLiane.Praza@Sun.COM } 16807887SLiane.Praza@Sun.COM 16817887SLiane.Praza@Sun.COM /* Add the values to the property's list. */ 16827887SLiane.Praza@Sun.COM val_str[1] = 0; /* Terminate the string. */ 16837887SLiane.Praza@Sun.COM for (; *seps != 0; seps++) { 16847887SLiane.Praza@Sun.COM v = internal_value_new(); 16857887SLiane.Praza@Sun.COM v->sc_type = (*p)->sc_value_type; 16867887SLiane.Praza@Sun.COM v->sc_free = lxml_free_str; 16877887SLiane.Praza@Sun.COM val_str[0] = *seps; 16887887SLiane.Praza@Sun.COM v->sc_u.sc_string = strdup(val_str); 16897887SLiane.Praza@Sun.COM if (v->sc_u.sc_string == NULL) 16907887SLiane.Praza@Sun.COM uu_die(gettext("Out of memory\n")); 16917887SLiane.Praza@Sun.COM internal_attach_value(*p, v); 16927887SLiane.Praza@Sun.COM } 16937887SLiane.Praza@Sun.COM } 16947887SLiane.Praza@Sun.COM 16957887SLiane.Praza@Sun.COM /* 16967887SLiane.Praza@Sun.COM * Create an internal_separators property and attach it to the property 16977887SLiane.Praza@Sun.COM * group at pg. The separator characters are provided in the text nodes 16987887SLiane.Praza@Sun.COM * that are the children of seps. Each separator character is stored as a 16997887SLiane.Praza@Sun.COM * property value in the internal_separators property. 17007887SLiane.Praza@Sun.COM */ 17017887SLiane.Praza@Sun.COM static int 17027887SLiane.Praza@Sun.COM lxml_get_tm_internal_seps(entity_t *service, pgroup_t *pg, xmlNodePtr seps) 17037887SLiane.Praza@Sun.COM { 17047887SLiane.Praza@Sun.COM xmlNodePtr cursor; 17057887SLiane.Praza@Sun.COM property_t *prop = NULL; 17067887SLiane.Praza@Sun.COM int r; 17077887SLiane.Praza@Sun.COM 17087887SLiane.Praza@Sun.COM for (cursor = seps->xmlChildrenNode; cursor != NULL; 17097887SLiane.Praza@Sun.COM cursor = cursor->next) { 17107887SLiane.Praza@Sun.COM if (strcmp("text", (const char *)cursor->name) == 0) { 17117887SLiane.Praza@Sun.COM seps_to_prop_values(&prop, cursor->content); 17127887SLiane.Praza@Sun.COM } else if (strcmp("comment", (const char *)cursor->name) != 0) { 17137887SLiane.Praza@Sun.COM uu_die(gettext("illegal element \"%s\" on %s element " 17147887SLiane.Praza@Sun.COM "for \"%s\"\n"), cursor->name, seps->name, 17157887SLiane.Praza@Sun.COM service->sc_name); 17167887SLiane.Praza@Sun.COM } 17177887SLiane.Praza@Sun.COM } 17187887SLiane.Praza@Sun.COM if (prop == NULL) { 17197887SLiane.Praza@Sun.COM semerr(gettext("The %s element in %s had an empty list of " 17207887SLiane.Praza@Sun.COM "separators.\n"), (const char *)seps->name, 17217887SLiane.Praza@Sun.COM service->sc_name); 17227887SLiane.Praza@Sun.COM return (-1); 17237887SLiane.Praza@Sun.COM } 17247887SLiane.Praza@Sun.COM r = internal_attach_property(pg, prop); 17257887SLiane.Praza@Sun.COM if (r != 0) 17267887SLiane.Praza@Sun.COM internal_property_free(prop); 17277887SLiane.Praza@Sun.COM return (r); 17287887SLiane.Praza@Sun.COM } 17297887SLiane.Praza@Sun.COM 17300Sstevel@tonic-gate static int 17310Sstevel@tonic-gate lxml_get_tm_manpage(entity_t *service, xmlNodePtr manpage) 17320Sstevel@tonic-gate { 17330Sstevel@tonic-gate pgroup_t *pg; 17340Sstevel@tonic-gate char *pgname; 17350Sstevel@tonic-gate xmlChar *title; 17360Sstevel@tonic-gate 17370Sstevel@tonic-gate /* 17380Sstevel@tonic-gate * Fetch title attribute, convert to something sanitized, and create 17390Sstevel@tonic-gate * property group. 17400Sstevel@tonic-gate */ 17417887SLiane.Praza@Sun.COM title = xmlGetProp(manpage, (xmlChar *)title_attr); 17420Sstevel@tonic-gate pgname = (char *)lxml_label_to_groupname(SCF_PG_TM_MAN_PREFIX, 17430Sstevel@tonic-gate (const char *)title); 17447887SLiane.Praza@Sun.COM xmlFree(title); 17450Sstevel@tonic-gate 17460Sstevel@tonic-gate pg = internal_pgroup_find_or_create(service, pgname, 17470Sstevel@tonic-gate (char *)SCF_GROUP_TEMPLATE); 17480Sstevel@tonic-gate 17490Sstevel@tonic-gate /* 17500Sstevel@tonic-gate * Each attribute is an astring property within the group. 17510Sstevel@tonic-gate */ 17527887SLiane.Praza@Sun.COM if (new_str_prop_from_attr(pg, SCF_PROPERTY_TM_TITLE, 17537887SLiane.Praza@Sun.COM SCF_TYPE_ASTRING, manpage, title_attr) != 0 || 17547887SLiane.Praza@Sun.COM new_str_prop_from_attr(pg, SCF_PROPERTY_TM_SECTION, 17557887SLiane.Praza@Sun.COM SCF_TYPE_ASTRING, manpage, section_attr) != 0 || 17567887SLiane.Praza@Sun.COM new_str_prop_from_attr(pg, SCF_PROPERTY_TM_MANPATH, 17577887SLiane.Praza@Sun.COM SCF_TYPE_ASTRING, manpage, manpath_attr) != 0) 17580Sstevel@tonic-gate return (-1); 17590Sstevel@tonic-gate 17600Sstevel@tonic-gate return (0); 17610Sstevel@tonic-gate } 17620Sstevel@tonic-gate 17630Sstevel@tonic-gate static int 17640Sstevel@tonic-gate lxml_get_tm_doclink(entity_t *service, xmlNodePtr doc_link) 17650Sstevel@tonic-gate { 17660Sstevel@tonic-gate pgroup_t *pg; 17670Sstevel@tonic-gate char *pgname; 17680Sstevel@tonic-gate xmlChar *name; 17690Sstevel@tonic-gate 17700Sstevel@tonic-gate /* 17710Sstevel@tonic-gate * Fetch name attribute, convert name to something sanitized, and create 17720Sstevel@tonic-gate * property group. 17730Sstevel@tonic-gate */ 17747887SLiane.Praza@Sun.COM name = xmlGetProp(doc_link, (xmlChar *)name_attr); 17750Sstevel@tonic-gate 17760Sstevel@tonic-gate pgname = (char *)lxml_label_to_groupname(SCF_PG_TM_DOC_PREFIX, 17770Sstevel@tonic-gate (const char *)name); 17780Sstevel@tonic-gate 17790Sstevel@tonic-gate pg = internal_pgroup_find_or_create(service, pgname, 17800Sstevel@tonic-gate (char *)SCF_GROUP_TEMPLATE); 17817887SLiane.Praza@Sun.COM xmlFree(name); 17820Sstevel@tonic-gate 17830Sstevel@tonic-gate /* 17840Sstevel@tonic-gate * Each attribute is an astring property within the group. 17850Sstevel@tonic-gate */ 17867887SLiane.Praza@Sun.COM if (new_str_prop_from_attr(pg, SCF_PROPERTY_TM_NAME, SCF_TYPE_ASTRING, 17877887SLiane.Praza@Sun.COM doc_link, name_attr) != 0 || 17887887SLiane.Praza@Sun.COM new_str_prop_from_attr(pg, SCF_PROPERTY_TM_URI, SCF_TYPE_ASTRING, 17897887SLiane.Praza@Sun.COM doc_link, uri_attr) != 0) 17900Sstevel@tonic-gate return (-1); 17910Sstevel@tonic-gate 17920Sstevel@tonic-gate return (0); 17930Sstevel@tonic-gate } 17940Sstevel@tonic-gate 17950Sstevel@tonic-gate static int 17960Sstevel@tonic-gate lxml_get_tm_documentation(entity_t *service, xmlNodePtr documentation) 17970Sstevel@tonic-gate { 17980Sstevel@tonic-gate xmlNodePtr cursor; 17990Sstevel@tonic-gate 18000Sstevel@tonic-gate for (cursor = documentation->xmlChildrenNode; cursor != NULL; 18010Sstevel@tonic-gate cursor = cursor->next) { 18020Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 18030Sstevel@tonic-gate continue; 18040Sstevel@tonic-gate 18050Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) { 18060Sstevel@tonic-gate case SC_MANPAGE: 18070Sstevel@tonic-gate (void) lxml_get_tm_manpage(service, cursor); 18080Sstevel@tonic-gate break; 18090Sstevel@tonic-gate case SC_DOC_LINK: 18100Sstevel@tonic-gate (void) lxml_get_tm_doclink(service, cursor); 18110Sstevel@tonic-gate break; 18120Sstevel@tonic-gate default: 18130Sstevel@tonic-gate uu_die(gettext("illegal element \"%s\" on template " 18140Sstevel@tonic-gate "for service \"%s\"\n"), 18150Sstevel@tonic-gate cursor->name, service->sc_name); 18160Sstevel@tonic-gate } 18170Sstevel@tonic-gate } 18180Sstevel@tonic-gate 18190Sstevel@tonic-gate return (0); 18200Sstevel@tonic-gate } 18210Sstevel@tonic-gate 18220Sstevel@tonic-gate static int 18237887SLiane.Praza@Sun.COM lxml_get_prop_pattern_attributes(pgroup_t *pg, xmlNodePtr cursor) 18247887SLiane.Praza@Sun.COM { 18257887SLiane.Praza@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_TM_NAME, 18267887SLiane.Praza@Sun.COM SCF_TYPE_ASTRING, cursor, name_attr, NULL) != 0) { 18277887SLiane.Praza@Sun.COM return (-1); 18287887SLiane.Praza@Sun.COM } 18297887SLiane.Praza@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_TM_TYPE, 18307887SLiane.Praza@Sun.COM SCF_TYPE_ASTRING, cursor, type_attr, "") != 0) { 18317887SLiane.Praza@Sun.COM return (-1); 18327887SLiane.Praza@Sun.COM } 18337887SLiane.Praza@Sun.COM if (new_bool_prop_from_attr(pg, SCF_PROPERTY_TM_REQUIRED, cursor, 18347887SLiane.Praza@Sun.COM required_attr) != 0) 18357887SLiane.Praza@Sun.COM return (-1); 18367887SLiane.Praza@Sun.COM return (0); 18377887SLiane.Praza@Sun.COM } 18387887SLiane.Praza@Sun.COM 18397887SLiane.Praza@Sun.COM static int 18407887SLiane.Praza@Sun.COM lxml_get_tm_include_values(entity_t *service, pgroup_t *pg, 18417887SLiane.Praza@Sun.COM xmlNodePtr include_values, const char *prop_name) 18427887SLiane.Praza@Sun.COM { 18437887SLiane.Praza@Sun.COM boolean_t attach_to_pg = B_FALSE; 18447887SLiane.Praza@Sun.COM property_t *p; 18457887SLiane.Praza@Sun.COM int r = 0; 18467887SLiane.Praza@Sun.COM char *type; 18477887SLiane.Praza@Sun.COM 18487887SLiane.Praza@Sun.COM /* Get the type attribute of the include_values element. */ 18497887SLiane.Praza@Sun.COM type = (char *)xmlGetProp(include_values, (const xmlChar *)type_attr); 18507887SLiane.Praza@Sun.COM if ((type == NULL) || (*type == 0)) { 18517887SLiane.Praza@Sun.COM uu_die(gettext("%s element requires a %s attribute in the %s " 18527887SLiane.Praza@Sun.COM "service.\n"), include_values->name, type_attr, 18537887SLiane.Praza@Sun.COM service->sc_name); 18547887SLiane.Praza@Sun.COM } 18557887SLiane.Praza@Sun.COM 18567887SLiane.Praza@Sun.COM /* Add the type to the values of the prop_name property. */ 18577887SLiane.Praza@Sun.COM p = internal_property_find(pg, prop_name); 18587887SLiane.Praza@Sun.COM if (p == NULL) 18597887SLiane.Praza@Sun.COM attach_to_pg = B_TRUE; 18607887SLiane.Praza@Sun.COM astring_prop_value(&p, prop_name, type, B_FALSE); 18617887SLiane.Praza@Sun.COM if (attach_to_pg == B_TRUE) { 18627887SLiane.Praza@Sun.COM r = internal_attach_property(pg, p); 18637887SLiane.Praza@Sun.COM if (r != 0) 18647887SLiane.Praza@Sun.COM internal_property_free(p); 18657887SLiane.Praza@Sun.COM } 18667887SLiane.Praza@Sun.COM return (r); 18677887SLiane.Praza@Sun.COM } 18687887SLiane.Praza@Sun.COM 18697887SLiane.Praza@Sun.COM #define RC_MIN 0 18707887SLiane.Praza@Sun.COM #define RC_MAX 1 18717887SLiane.Praza@Sun.COM #define RC_COUNT 2 18727887SLiane.Praza@Sun.COM 18737887SLiane.Praza@Sun.COM /* 18747887SLiane.Praza@Sun.COM * Verify that the strings at min and max are valid numeric strings. Also 18757887SLiane.Praza@Sun.COM * verify that max is numerically >= min. 18767887SLiane.Praza@Sun.COM * 18777887SLiane.Praza@Sun.COM * 0 is returned if the range is valid, and -1 is returned if it is not. 18787887SLiane.Praza@Sun.COM */ 18797887SLiane.Praza@Sun.COM static int 18807887SLiane.Praza@Sun.COM verify_range(entity_t *service, xmlNodePtr range, char *min, char *max) 18817887SLiane.Praza@Sun.COM { 18827887SLiane.Praza@Sun.COM char *c; 18837887SLiane.Praza@Sun.COM int i; 18847887SLiane.Praza@Sun.COM int is_signed = 0; 18857887SLiane.Praza@Sun.COM int inverted = 0; 18867887SLiane.Praza@Sun.COM const char *limit[RC_COUNT]; 18877887SLiane.Praza@Sun.COM char *strings[RC_COUNT]; 18887887SLiane.Praza@Sun.COM uint64_t urange[RC_COUNT]; /* unsigned range. */ 18897887SLiane.Praza@Sun.COM int64_t srange[RC_COUNT]; /* signed range. */ 18907887SLiane.Praza@Sun.COM 18917887SLiane.Praza@Sun.COM strings[RC_MIN] = min; 18927887SLiane.Praza@Sun.COM strings[RC_MAX] = max; 18937887SLiane.Praza@Sun.COM limit[RC_MIN] = min_attr; 18947887SLiane.Praza@Sun.COM limit[RC_MAX] = max_attr; 18957887SLiane.Praza@Sun.COM 18967887SLiane.Praza@Sun.COM /* See if the range is signed. */ 18977887SLiane.Praza@Sun.COM for (i = 0; (i < RC_COUNT) && (is_signed == 0); i++) { 18987887SLiane.Praza@Sun.COM c = strings[i]; 18997887SLiane.Praza@Sun.COM while (isspace(*c)) { 19007887SLiane.Praza@Sun.COM c++; 19017887SLiane.Praza@Sun.COM } 19027887SLiane.Praza@Sun.COM if (*c == '-') 19037887SLiane.Praza@Sun.COM is_signed = 1; 19047887SLiane.Praza@Sun.COM } 19057887SLiane.Praza@Sun.COM 19067887SLiane.Praza@Sun.COM /* Attempt to convert the strings. */ 19077887SLiane.Praza@Sun.COM for (i = 0; i < RC_COUNT; i++) { 19087887SLiane.Praza@Sun.COM errno = 0; 19097887SLiane.Praza@Sun.COM if (is_signed) { 19107887SLiane.Praza@Sun.COM srange[i] = strtoll(strings[i], &c, 0); 19117887SLiane.Praza@Sun.COM } else { 19127887SLiane.Praza@Sun.COM urange[i] = strtoull(strings[i], &c, 0); 19137887SLiane.Praza@Sun.COM } 19147887SLiane.Praza@Sun.COM if ((errno != 0) || (c == strings[i]) || (*c != 0)) { 19157887SLiane.Praza@Sun.COM /* Conversion failed. */ 19167887SLiane.Praza@Sun.COM uu_die(gettext("Unable to convert %s for the %s " 19177887SLiane.Praza@Sun.COM "element in service %s.\n"), limit[i], 19187887SLiane.Praza@Sun.COM (char *)range->name, service->sc_name); 19197887SLiane.Praza@Sun.COM } 19207887SLiane.Praza@Sun.COM } 19217887SLiane.Praza@Sun.COM 19227887SLiane.Praza@Sun.COM /* Make sure that min is <= max */ 19237887SLiane.Praza@Sun.COM if (is_signed) { 19247887SLiane.Praza@Sun.COM if (srange[RC_MAX] < srange[RC_MIN]) 19257887SLiane.Praza@Sun.COM inverted = 1; 19267887SLiane.Praza@Sun.COM } else { 19277887SLiane.Praza@Sun.COM if (urange[RC_MAX] < urange[RC_MIN]) 19287887SLiane.Praza@Sun.COM inverted = 1; 19297887SLiane.Praza@Sun.COM } 19307887SLiane.Praza@Sun.COM if (inverted != 0) { 19317887SLiane.Praza@Sun.COM semerr(gettext("Maximum less than minimum for the %s element " 19327887SLiane.Praza@Sun.COM "in service %s.\n"), (char *)range->name, 19337887SLiane.Praza@Sun.COM service->sc_name); 19347887SLiane.Praza@Sun.COM return (-1); 19357887SLiane.Praza@Sun.COM } 19367887SLiane.Praza@Sun.COM 19377887SLiane.Praza@Sun.COM return (0); 19387887SLiane.Praza@Sun.COM } 19397887SLiane.Praza@Sun.COM 19407887SLiane.Praza@Sun.COM /* 19417887SLiane.Praza@Sun.COM * This, function creates a property named prop_name. The range element 19427887SLiane.Praza@Sun.COM * should have two attributes -- min and max. The property value then 19437887SLiane.Praza@Sun.COM * becomes the concatenation of their value separated by a comma. The 19447887SLiane.Praza@Sun.COM * property is then attached to the property group at pg. 19457887SLiane.Praza@Sun.COM * 19467887SLiane.Praza@Sun.COM * If pg already contains a property with a name of prop_name, it is only 19477887SLiane.Praza@Sun.COM * necessary to create a new value and attach it to the existing property. 19487887SLiane.Praza@Sun.COM */ 19497887SLiane.Praza@Sun.COM static int 19507887SLiane.Praza@Sun.COM lxml_get_tm_range(entity_t *service, pgroup_t *pg, xmlNodePtr range, 19517887SLiane.Praza@Sun.COM const char *prop_name) 19527887SLiane.Praza@Sun.COM { 19537887SLiane.Praza@Sun.COM boolean_t attach_to_pg = B_FALSE; 19547887SLiane.Praza@Sun.COM char *max; 19557887SLiane.Praza@Sun.COM char *min; 19567887SLiane.Praza@Sun.COM property_t *p; 19577887SLiane.Praza@Sun.COM char *prop_value; 19587887SLiane.Praza@Sun.COM int r = 0; 19597887SLiane.Praza@Sun.COM 19607887SLiane.Praza@Sun.COM /* Get max and min from the XML description. */ 19617887SLiane.Praza@Sun.COM max = (char *)xmlGetProp(range, (xmlChar *)max_attr); 19627887SLiane.Praza@Sun.COM if ((max == NULL) || (*max == 0)) { 19637887SLiane.Praza@Sun.COM uu_die(gettext("%s element is missing the %s attribute in " 19647887SLiane.Praza@Sun.COM "service %s.\n"), (char *)range->name, max_attr, 19657887SLiane.Praza@Sun.COM service->sc_name); 19667887SLiane.Praza@Sun.COM } 19677887SLiane.Praza@Sun.COM min = (char *)xmlGetProp(range, (xmlChar *)min_attr); 19687887SLiane.Praza@Sun.COM if ((min == NULL) || (*min == 0)) { 19697887SLiane.Praza@Sun.COM uu_die(gettext("%s element is missing the %s attribute in " 19707887SLiane.Praza@Sun.COM "service %s.\n"), (char *)range->name, min_attr, 19717887SLiane.Praza@Sun.COM service->sc_name); 19727887SLiane.Praza@Sun.COM } 19737887SLiane.Praza@Sun.COM if (verify_range(service, range, min, max) != 0) { 19747887SLiane.Praza@Sun.COM xmlFree(min); 19757887SLiane.Praza@Sun.COM xmlFree(max); 19767887SLiane.Praza@Sun.COM return (-1); 19777887SLiane.Praza@Sun.COM } 19787887SLiane.Praza@Sun.COM 19797887SLiane.Praza@Sun.COM /* Property value is concatenation of min and max. */ 19807887SLiane.Praza@Sun.COM prop_value = safe_malloc(max_scf_value_len + 1); 19817887SLiane.Praza@Sun.COM if (snprintf(prop_value, max_scf_value_len + 1, "%s,%s", min, max) >= 19827887SLiane.Praza@Sun.COM max_scf_value_len + 1) { 19837887SLiane.Praza@Sun.COM uu_die(gettext("min and max are too long for the %s element " 19847887SLiane.Praza@Sun.COM "of %s.\n"), (char *)range->name, service->sc_name); 19857887SLiane.Praza@Sun.COM } 19867887SLiane.Praza@Sun.COM xmlFree(min); 19877887SLiane.Praza@Sun.COM xmlFree(max); 19887887SLiane.Praza@Sun.COM 19897887SLiane.Praza@Sun.COM /* 19907887SLiane.Praza@Sun.COM * If necessary create the property and attach it to the property 19917887SLiane.Praza@Sun.COM * group. 19927887SLiane.Praza@Sun.COM */ 19937887SLiane.Praza@Sun.COM p = internal_property_find(pg, prop_name); 19947887SLiane.Praza@Sun.COM if (p == NULL) 19957887SLiane.Praza@Sun.COM attach_to_pg = B_TRUE; 19967887SLiane.Praza@Sun.COM astring_prop_value(&p, prop_name, prop_value, B_TRUE); 19977887SLiane.Praza@Sun.COM if (attach_to_pg == B_TRUE) { 19987887SLiane.Praza@Sun.COM r = internal_attach_property(pg, p); 19997887SLiane.Praza@Sun.COM if (r != 0) { 20007887SLiane.Praza@Sun.COM internal_property_free(p); 20017887SLiane.Praza@Sun.COM } 20027887SLiane.Praza@Sun.COM } 20037887SLiane.Praza@Sun.COM return (r); 20047887SLiane.Praza@Sun.COM } 20057887SLiane.Praza@Sun.COM 20067887SLiane.Praza@Sun.COM /* 20077887SLiane.Praza@Sun.COM * Determine how many plain characters are represented by count Base32 20087887SLiane.Praza@Sun.COM * encoded characters. 5 plain text characters are converted to 8 Base32 20097887SLiane.Praza@Sun.COM * characters. 20107887SLiane.Praza@Sun.COM */ 20117887SLiane.Praza@Sun.COM static size_t 20127887SLiane.Praza@Sun.COM encoded_count_to_plain(size_t count) 20137887SLiane.Praza@Sun.COM { 20147887SLiane.Praza@Sun.COM return (5 * ((count + 7) / 8)); 20157887SLiane.Praza@Sun.COM } 20167887SLiane.Praza@Sun.COM 20177887SLiane.Praza@Sun.COM /* 20187887SLiane.Praza@Sun.COM * The value element contains 0 or 1 common_name element followed by 0 or 1 20197887SLiane.Praza@Sun.COM * description element. It also has a required attribute called "name". 20207887SLiane.Praza@Sun.COM * The common_name and description are stored as property values in pg. 20217887SLiane.Praza@Sun.COM * The property names are: 20227887SLiane.Praza@Sun.COM * value_<name>_common_name_<lang> 20237887SLiane.Praza@Sun.COM * value_<name>_description_<lang> 20247887SLiane.Praza@Sun.COM * 20257887SLiane.Praza@Sun.COM * The <name> portion of the preceeding proper names requires more 20267887SLiane.Praza@Sun.COM * explanation. Ideally it would just the name attribute of this value 20277887SLiane.Praza@Sun.COM * element. Unfortunately, the name attribute can contain characters that 20287887SLiane.Praza@Sun.COM * are not legal in a property name. Thus, we base 32 encode the name 20297887SLiane.Praza@Sun.COM * attribute and use that for <name>. 20307887SLiane.Praza@Sun.COM * 20317887SLiane.Praza@Sun.COM * There are cases where the caller needs to know the name, so it is 20327887SLiane.Praza@Sun.COM * returned through the name_value pointer if it is not NULL. 20337887SLiane.Praza@Sun.COM * 20347887SLiane.Praza@Sun.COM * Parameters: 20357887SLiane.Praza@Sun.COM * service - Information about the service that is being 20367887SLiane.Praza@Sun.COM * processed. This function only uses this parameter 20377887SLiane.Praza@Sun.COM * for producing error messages. 20387887SLiane.Praza@Sun.COM * 20397887SLiane.Praza@Sun.COM * pg - The property group to receive the newly created 20407887SLiane.Praza@Sun.COM * properties. 20417887SLiane.Praza@Sun.COM * 20427887SLiane.Praza@Sun.COM * value - Pointer to the value element in the XML tree. 20437887SLiane.Praza@Sun.COM * 20447887SLiane.Praza@Sun.COM * name_value - Address to receive the value of the name attribute. 20457887SLiane.Praza@Sun.COM * The caller must free the memory. 20467887SLiane.Praza@Sun.COM */ 20477887SLiane.Praza@Sun.COM static int 20487887SLiane.Praza@Sun.COM lxml_get_tm_value_element(entity_t *service, pgroup_t *pg, xmlNodePtr value, 20497887SLiane.Praza@Sun.COM char **name_value) 20507887SLiane.Praza@Sun.COM { 20517887SLiane.Praza@Sun.COM char *common_name_fmt; 20527887SLiane.Praza@Sun.COM xmlNodePtr cursor; 20537887SLiane.Praza@Sun.COM char *description_fmt; 20547887SLiane.Praza@Sun.COM char *encoded_value = NULL; 20557887SLiane.Praza@Sun.COM size_t extra; 20567887SLiane.Praza@Sun.COM char *value_name; 20577887SLiane.Praza@Sun.COM int r = 0; 20587887SLiane.Praza@Sun.COM 20597887SLiane.Praza@Sun.COM common_name_fmt = safe_malloc(max_scf_name_len + 1); 20607887SLiane.Praza@Sun.COM description_fmt = safe_malloc(max_scf_name_len + 1); 20617887SLiane.Praza@Sun.COM 20627887SLiane.Praza@Sun.COM /* 20637887SLiane.Praza@Sun.COM * Get the value of our name attribute, so that we can use it to 20647887SLiane.Praza@Sun.COM * construct property names. 20657887SLiane.Praza@Sun.COM */ 20667887SLiane.Praza@Sun.COM value_name = (char *)xmlGetProp(value, (xmlChar *)name_attr); 20677887SLiane.Praza@Sun.COM /* The value name must be present, but it can be empty. */ 20687887SLiane.Praza@Sun.COM if (value_name == NULL) { 20697887SLiane.Praza@Sun.COM uu_die(gettext("%s element requires a %s attribute in the %s " 20707887SLiane.Praza@Sun.COM "service.\n"), (char *)value->name, name_attr, 20717887SLiane.Praza@Sun.COM service->sc_name); 20727887SLiane.Praza@Sun.COM } 20737887SLiane.Praza@Sun.COM 20747887SLiane.Praza@Sun.COM /* 20757887SLiane.Praza@Sun.COM * The value_name may contain characters that are not valid in in a 20767887SLiane.Praza@Sun.COM * property name. So we will encode value_name and then use the 20777887SLiane.Praza@Sun.COM * encoded value in the property name. 20787887SLiane.Praza@Sun.COM */ 20797887SLiane.Praza@Sun.COM encoded_value = safe_malloc(max_scf_name_len + 1); 20807887SLiane.Praza@Sun.COM if (scf_encode32(value_name, strlen(value_name), encoded_value, 20817887SLiane.Praza@Sun.COM max_scf_name_len + 1, &extra, SCF_ENCODE32_PAD) != 0) { 20827887SLiane.Praza@Sun.COM extra = encoded_count_to_plain(extra - max_scf_name_len); 20837887SLiane.Praza@Sun.COM uu_die(gettext("Constructed property name is %u characters " 20847887SLiane.Praza@Sun.COM "too long for value \"%s\" in the %s service.\n"), 20857887SLiane.Praza@Sun.COM extra, value_name, service->sc_name); 20867887SLiane.Praza@Sun.COM } 20877887SLiane.Praza@Sun.COM if ((extra = snprintf(common_name_fmt, max_scf_name_len + 1, 20887887SLiane.Praza@Sun.COM VALUE_COMMON_NAME_FMT, SCF_PROPERTY_TM_VALUE_PREFIX, 20897887SLiane.Praza@Sun.COM encoded_value)) >= max_scf_name_len + 1) { 20907887SLiane.Praza@Sun.COM extra = encoded_count_to_plain(extra - max_scf_name_len); 20917887SLiane.Praza@Sun.COM uu_die(gettext("Name attribute is " 20927887SLiane.Praza@Sun.COM "%u characters too long for %s in service %s\n"), 20937887SLiane.Praza@Sun.COM extra, (char *)value->name, service->sc_name); 20947887SLiane.Praza@Sun.COM } 20957887SLiane.Praza@Sun.COM if ((extra = snprintf(description_fmt, max_scf_name_len + 1, 20967887SLiane.Praza@Sun.COM VALUE_DESCRIPTION_FMT, SCF_PROPERTY_TM_VALUE_PREFIX, 20977887SLiane.Praza@Sun.COM encoded_value)) >= max_scf_name_len + 1) { 20987887SLiane.Praza@Sun.COM extra = encoded_count_to_plain(extra - max_scf_name_len); 20997887SLiane.Praza@Sun.COM uu_die(gettext("Name attribute is " 21007887SLiane.Praza@Sun.COM "%u characters too long for %s in service %s\n"), 21017887SLiane.Praza@Sun.COM extra, (char *)value->name, service->sc_name); 21027887SLiane.Praza@Sun.COM } 21037887SLiane.Praza@Sun.COM 21047887SLiane.Praza@Sun.COM for (cursor = value->xmlChildrenNode; 21057887SLiane.Praza@Sun.COM cursor != NULL; 21067887SLiane.Praza@Sun.COM cursor = cursor->next) { 21077887SLiane.Praza@Sun.COM if (lxml_ignorable_block(cursor)) 21087887SLiane.Praza@Sun.COM continue; 21097887SLiane.Praza@Sun.COM switch (lxml_xlate_element(cursor->name)) { 21107887SLiane.Praza@Sun.COM case SC_COMMON_NAME: 21117887SLiane.Praza@Sun.COM r = lxml_get_all_loctext(service, pg, cursor, 21127887SLiane.Praza@Sun.COM common_name_fmt, (const char *)cursor->name); 21137887SLiane.Praza@Sun.COM break; 21147887SLiane.Praza@Sun.COM case SC_DESCRIPTION: 21157887SLiane.Praza@Sun.COM r = lxml_get_all_loctext(service, pg, cursor, 21167887SLiane.Praza@Sun.COM description_fmt, (const char *)cursor->name); 21177887SLiane.Praza@Sun.COM break; 21187887SLiane.Praza@Sun.COM default: 21197887SLiane.Praza@Sun.COM uu_die(gettext("\"%s\" is an illegal element in %s " 21207887SLiane.Praza@Sun.COM "of service %s\n"), (char *)cursor->name, 21217887SLiane.Praza@Sun.COM (char *)value->name, service->sc_name); 21227887SLiane.Praza@Sun.COM } 21237887SLiane.Praza@Sun.COM if (r != 0) 21247887SLiane.Praza@Sun.COM break; 21257887SLiane.Praza@Sun.COM } 21267887SLiane.Praza@Sun.COM 21277887SLiane.Praza@Sun.COM free(description_fmt); 21287887SLiane.Praza@Sun.COM free(common_name_fmt); 21297887SLiane.Praza@Sun.COM if (r == 0) { 21307887SLiane.Praza@Sun.COM *name_value = safe_strdup(value_name); 21317887SLiane.Praza@Sun.COM } 21327887SLiane.Praza@Sun.COM xmlFree(value_name); 21337887SLiane.Praza@Sun.COM free(encoded_value); 21347887SLiane.Praza@Sun.COM return (r); 21357887SLiane.Praza@Sun.COM } 21367887SLiane.Praza@Sun.COM 21377887SLiane.Praza@Sun.COM static int 21387887SLiane.Praza@Sun.COM lxml_get_tm_choices(entity_t *service, pgroup_t *pg, xmlNodePtr choices) 21397887SLiane.Praza@Sun.COM { 21407887SLiane.Praza@Sun.COM xmlNodePtr cursor; 21417887SLiane.Praza@Sun.COM char *name_value; 21427887SLiane.Praza@Sun.COM property_t *name_prop = NULL; 21437887SLiane.Praza@Sun.COM int r = 0; 21447887SLiane.Praza@Sun.COM 21457887SLiane.Praza@Sun.COM for (cursor = choices->xmlChildrenNode; 21467887SLiane.Praza@Sun.COM (cursor != NULL) && (r == 0); 21477887SLiane.Praza@Sun.COM cursor = cursor->next) { 21487887SLiane.Praza@Sun.COM if (lxml_ignorable_block(cursor)) 21497887SLiane.Praza@Sun.COM continue; 21507887SLiane.Praza@Sun.COM switch (lxml_xlate_element(cursor->name)) { 21517887SLiane.Praza@Sun.COM case SC_INCLUDE_VALUES: 21527887SLiane.Praza@Sun.COM (void) lxml_get_tm_include_values(service, pg, cursor, 21537887SLiane.Praza@Sun.COM SCF_PROPERTY_TM_CHOICES_INCLUDE_VALUES); 21547887SLiane.Praza@Sun.COM break; 21557887SLiane.Praza@Sun.COM case SC_RANGE: 21567887SLiane.Praza@Sun.COM r = lxml_get_tm_range(service, pg, cursor, 21577887SLiane.Praza@Sun.COM SCF_PROPERTY_TM_CHOICES_RANGE); 21587887SLiane.Praza@Sun.COM if (r != 0) 21597887SLiane.Praza@Sun.COM goto out; 21607887SLiane.Praza@Sun.COM break; 21617887SLiane.Praza@Sun.COM case SC_VALUE: 21627887SLiane.Praza@Sun.COM r = lxml_get_tm_value_element(service, pg, cursor, 21637887SLiane.Praza@Sun.COM &name_value); 21647887SLiane.Praza@Sun.COM if (r == 0) { 21657887SLiane.Praza@Sun.COM /* 21667887SLiane.Praza@Sun.COM * There is no need to free the memory 21677887SLiane.Praza@Sun.COM * associated with name_value, because the 21687887SLiane.Praza@Sun.COM * property value will end up pointing to 21697887SLiane.Praza@Sun.COM * the memory. 21707887SLiane.Praza@Sun.COM */ 21717887SLiane.Praza@Sun.COM astring_prop_value(&name_prop, 21727887SLiane.Praza@Sun.COM SCF_PROPERTY_TM_CHOICES_NAME, name_value, 21737887SLiane.Praza@Sun.COM B_TRUE); 21747887SLiane.Praza@Sun.COM } else { 21757887SLiane.Praza@Sun.COM goto out; 21767887SLiane.Praza@Sun.COM } 21777887SLiane.Praza@Sun.COM break; 21787887SLiane.Praza@Sun.COM default: 21797887SLiane.Praza@Sun.COM uu_die(gettext("%s is an invalid element of " 21807887SLiane.Praza@Sun.COM "choices for service %s.\n"), cursor->name, 21817887SLiane.Praza@Sun.COM service->sc_name); 21827887SLiane.Praza@Sun.COM } 21837887SLiane.Praza@Sun.COM } 21847887SLiane.Praza@Sun.COM 21857887SLiane.Praza@Sun.COM out: 21867887SLiane.Praza@Sun.COM /* Attach the name property if we created one. */ 21877887SLiane.Praza@Sun.COM if ((r == 0) && (name_prop != NULL)) { 21887887SLiane.Praza@Sun.COM r = internal_attach_property(pg, name_prop); 21897887SLiane.Praza@Sun.COM } 21907887SLiane.Praza@Sun.COM if ((r != 0) && (name_prop != NULL)) { 21917887SLiane.Praza@Sun.COM internal_property_free(name_prop); 21927887SLiane.Praza@Sun.COM } 21937887SLiane.Praza@Sun.COM 21947887SLiane.Praza@Sun.COM return (r); 21957887SLiane.Praza@Sun.COM } 21967887SLiane.Praza@Sun.COM 21977887SLiane.Praza@Sun.COM static int 21987887SLiane.Praza@Sun.COM lxml_get_tm_constraints(entity_t *service, pgroup_t *pg, xmlNodePtr constraints) 21997887SLiane.Praza@Sun.COM { 22007887SLiane.Praza@Sun.COM xmlNodePtr cursor; 22017887SLiane.Praza@Sun.COM char *name_value; 22027887SLiane.Praza@Sun.COM property_t *name_prop = NULL; 22037887SLiane.Praza@Sun.COM int r = 0; 22047887SLiane.Praza@Sun.COM 22057887SLiane.Praza@Sun.COM for (cursor = constraints->xmlChildrenNode; 22067887SLiane.Praza@Sun.COM (cursor != NULL) && (r == 0); 22077887SLiane.Praza@Sun.COM cursor = cursor->next) { 22087887SLiane.Praza@Sun.COM if (lxml_ignorable_block(cursor)) 22097887SLiane.Praza@Sun.COM continue; 22107887SLiane.Praza@Sun.COM switch (lxml_xlate_element(cursor->name)) { 22117887SLiane.Praza@Sun.COM case SC_RANGE: 22127887SLiane.Praza@Sun.COM r = lxml_get_tm_range(service, pg, cursor, 22137887SLiane.Praza@Sun.COM SCF_PROPERTY_TM_CONSTRAINT_RANGE); 22147887SLiane.Praza@Sun.COM if (r != 0) 22157887SLiane.Praza@Sun.COM goto out; 22167887SLiane.Praza@Sun.COM break; 22177887SLiane.Praza@Sun.COM case SC_VALUE: 22187887SLiane.Praza@Sun.COM r = lxml_get_tm_value_element(service, pg, cursor, 22197887SLiane.Praza@Sun.COM &name_value); 22207887SLiane.Praza@Sun.COM if (r == 0) { 22217887SLiane.Praza@Sun.COM /* 22227887SLiane.Praza@Sun.COM * There is no need to free the memory 22237887SLiane.Praza@Sun.COM * associated with name_value, because the 22247887SLiane.Praza@Sun.COM * property value will end up pointing to 22257887SLiane.Praza@Sun.COM * the memory. 22267887SLiane.Praza@Sun.COM */ 22277887SLiane.Praza@Sun.COM astring_prop_value(&name_prop, 22287887SLiane.Praza@Sun.COM SCF_PROPERTY_TM_CONSTRAINT_NAME, name_value, 22297887SLiane.Praza@Sun.COM B_TRUE); 22307887SLiane.Praza@Sun.COM } else { 22317887SLiane.Praza@Sun.COM goto out; 22327887SLiane.Praza@Sun.COM } 22337887SLiane.Praza@Sun.COM break; 22347887SLiane.Praza@Sun.COM default: 22357887SLiane.Praza@Sun.COM uu_die(gettext("%s is an invalid element of " 22367887SLiane.Praza@Sun.COM "constraints for service %s.\n"), cursor->name, 22377887SLiane.Praza@Sun.COM service->sc_name); 22387887SLiane.Praza@Sun.COM } 22397887SLiane.Praza@Sun.COM } 22407887SLiane.Praza@Sun.COM 22417887SLiane.Praza@Sun.COM out: 22427887SLiane.Praza@Sun.COM /* Attach the name property if we created one. */ 22437887SLiane.Praza@Sun.COM if ((r == 0) && (name_prop != NULL)) { 22447887SLiane.Praza@Sun.COM r = internal_attach_property(pg, name_prop); 22457887SLiane.Praza@Sun.COM } 22467887SLiane.Praza@Sun.COM if ((r != 0) && (name_prop != NULL)) { 22477887SLiane.Praza@Sun.COM internal_property_free(name_prop); 22487887SLiane.Praza@Sun.COM } 22497887SLiane.Praza@Sun.COM 22507887SLiane.Praza@Sun.COM return (r); 22517887SLiane.Praza@Sun.COM } 22527887SLiane.Praza@Sun.COM 22537887SLiane.Praza@Sun.COM /* 22547887SLiane.Praza@Sun.COM * The values element contains one or more value elements. 22557887SLiane.Praza@Sun.COM */ 22567887SLiane.Praza@Sun.COM static int 22577887SLiane.Praza@Sun.COM lxml_get_tm_values(entity_t *service, pgroup_t *pg, xmlNodePtr values) 22587887SLiane.Praza@Sun.COM { 22597887SLiane.Praza@Sun.COM xmlNodePtr cursor; 22607887SLiane.Praza@Sun.COM char *name_value; 22617887SLiane.Praza@Sun.COM property_t *name_prop = NULL; 22627887SLiane.Praza@Sun.COM int r = 0; 22637887SLiane.Praza@Sun.COM 22647887SLiane.Praza@Sun.COM for (cursor = values->xmlChildrenNode; 22657887SLiane.Praza@Sun.COM (cursor != NULL) && (r == 0); 22667887SLiane.Praza@Sun.COM cursor = cursor->next) { 22677887SLiane.Praza@Sun.COM if (lxml_ignorable_block(cursor)) 22687887SLiane.Praza@Sun.COM continue; 22697887SLiane.Praza@Sun.COM if (lxml_xlate_element(cursor->name) != SC_VALUE) { 22707887SLiane.Praza@Sun.COM uu_die(gettext("\"%s\" is an illegal element in the " 22717887SLiane.Praza@Sun.COM "%s element of %s\n"), (char *)cursor->name, 22727887SLiane.Praza@Sun.COM (char *)values->name, service->sc_name); 22737887SLiane.Praza@Sun.COM } 22747887SLiane.Praza@Sun.COM r = lxml_get_tm_value_element(service, pg, cursor, &name_value); 22757887SLiane.Praza@Sun.COM if (r == 0) { 22767887SLiane.Praza@Sun.COM /* 22777887SLiane.Praza@Sun.COM * There is no need to free the memory 22787887SLiane.Praza@Sun.COM * associated with name_value, because the 22797887SLiane.Praza@Sun.COM * property value will end up pointing to 22807887SLiane.Praza@Sun.COM * the memory. 22817887SLiane.Praza@Sun.COM */ 22827887SLiane.Praza@Sun.COM astring_prop_value(&name_prop, 22837887SLiane.Praza@Sun.COM SCF_PROPERTY_TM_VALUES_NAME, name_value, 22847887SLiane.Praza@Sun.COM B_TRUE); 22857887SLiane.Praza@Sun.COM } 22867887SLiane.Praza@Sun.COM } 22877887SLiane.Praza@Sun.COM 22887887SLiane.Praza@Sun.COM /* Attach the name property if we created one. */ 22897887SLiane.Praza@Sun.COM if ((r == 0) && (name_prop != NULL)) { 22907887SLiane.Praza@Sun.COM r = internal_attach_property(pg, name_prop); 22917887SLiane.Praza@Sun.COM } 22927887SLiane.Praza@Sun.COM if ((r != 0) && (name_prop != NULL)) { 22937887SLiane.Praza@Sun.COM internal_property_free(name_prop); 22947887SLiane.Praza@Sun.COM } 22957887SLiane.Praza@Sun.COM 22967887SLiane.Praza@Sun.COM return (r); 22977887SLiane.Praza@Sun.COM } 22987887SLiane.Praza@Sun.COM 22997887SLiane.Praza@Sun.COM /* 23007887SLiane.Praza@Sun.COM * This function processes a prop_pattern element within a pg_pattern XML 23017887SLiane.Praza@Sun.COM * element. First it creates a property group to hold the prop_pattern 23027887SLiane.Praza@Sun.COM * information. The name of this property group is the concatenation of: 23037887SLiane.Praza@Sun.COM * - SCF_PG_TM_PROP_PATTERN_PREFIX 23047887SLiane.Praza@Sun.COM * - The unique part of the property group name of the enclosing 23057887SLiane.Praza@Sun.COM * pg_pattern. The property group name of the enclosing pg_pattern 23067887SLiane.Praza@Sun.COM * is passed to us in pgpat_name. The unique part, is the part 23077887SLiane.Praza@Sun.COM * following SCF_PG_TM_PG_PATTERN_PREFIX. 23087887SLiane.Praza@Sun.COM * - The name of this prop_pattern element. 23097887SLiane.Praza@Sun.COM * 23107887SLiane.Praza@Sun.COM * After creating the property group, the prop_pattern attributes are saved 23117887SLiane.Praza@Sun.COM * as properties in the PG. Finally, the prop_pattern elements are 23127887SLiane.Praza@Sun.COM * processed and added to the PG. 23137887SLiane.Praza@Sun.COM */ 23147887SLiane.Praza@Sun.COM static int 23157887SLiane.Praza@Sun.COM lxml_get_tm_prop_pattern(entity_t *service, xmlNodePtr prop_pattern, 23167887SLiane.Praza@Sun.COM const char *pgpat_name) 23177887SLiane.Praza@Sun.COM { 23187887SLiane.Praza@Sun.COM xmlNodePtr cursor; 23197887SLiane.Praza@Sun.COM int extra; 23207887SLiane.Praza@Sun.COM pgroup_t *pg; 23217887SLiane.Praza@Sun.COM property_t *p; 23227887SLiane.Praza@Sun.COM char *pg_name; 23237887SLiane.Praza@Sun.COM size_t prefix_len; 23247887SLiane.Praza@Sun.COM xmlChar *prop_pattern_name; 23257887SLiane.Praza@Sun.COM int r; 23267887SLiane.Praza@Sun.COM const char *unique; 23277887SLiane.Praza@Sun.COM value_t *v; 23287887SLiane.Praza@Sun.COM 23297887SLiane.Praza@Sun.COM /* Find the unique part of the pg_pattern property group name. */ 23307887SLiane.Praza@Sun.COM prefix_len = strlen(SCF_PG_TM_PG_PAT_BASE); 23317887SLiane.Praza@Sun.COM assert(strncmp(pgpat_name, SCF_PG_TM_PG_PAT_BASE, prefix_len) == 0); 23327887SLiane.Praza@Sun.COM unique = pgpat_name + prefix_len; 23337887SLiane.Praza@Sun.COM 23347887SLiane.Praza@Sun.COM /* 23357887SLiane.Praza@Sun.COM * We need to get the value of the name attribute first. The 23367887SLiane.Praza@Sun.COM * prop_pattern name as well as the name of the enclosing 23377887SLiane.Praza@Sun.COM * pg_pattern both constitute part of the name of the property 23387887SLiane.Praza@Sun.COM * group that we will create. 23397887SLiane.Praza@Sun.COM */ 23407887SLiane.Praza@Sun.COM prop_pattern_name = xmlGetProp(prop_pattern, (xmlChar *)name_attr); 23417887SLiane.Praza@Sun.COM if ((prop_pattern_name == NULL) || (*prop_pattern_name == 0)) { 23427887SLiane.Praza@Sun.COM semerr(gettext("prop_pattern name is missing for %s\n"), 23437887SLiane.Praza@Sun.COM service->sc_name); 23447887SLiane.Praza@Sun.COM return (-1); 23457887SLiane.Praza@Sun.COM } 23467887SLiane.Praza@Sun.COM if (uu_check_name((const char *)prop_pattern_name, 23477887SLiane.Praza@Sun.COM UU_NAME_DOMAIN) != 0) { 23487887SLiane.Praza@Sun.COM semerr(gettext("prop_pattern name, \"%s\", for %s is not " 23497887SLiane.Praza@Sun.COM "valid.\n"), prop_pattern_name, service->sc_name); 23507887SLiane.Praza@Sun.COM xmlFree(prop_pattern_name); 23517887SLiane.Praza@Sun.COM return (-1); 23527887SLiane.Praza@Sun.COM } 23537887SLiane.Praza@Sun.COM pg_name = safe_malloc(max_scf_name_len + 1); 23547887SLiane.Praza@Sun.COM if ((extra = snprintf(pg_name, max_scf_name_len + 1, "%s%s_%s", 23557887SLiane.Praza@Sun.COM SCF_PG_TM_PROP_PATTERN_PREFIX, unique, 23567887SLiane.Praza@Sun.COM (char *)prop_pattern_name)) >= max_scf_name_len + 1) { 23577887SLiane.Praza@Sun.COM uu_die(gettext("prop_pattern name, \"%s\", for %s is %d " 23587887SLiane.Praza@Sun.COM "characters too long\n"), (char *)prop_pattern_name, 23597887SLiane.Praza@Sun.COM service->sc_name, extra - max_scf_name_len); 23607887SLiane.Praza@Sun.COM } 23617887SLiane.Praza@Sun.COM 23627887SLiane.Praza@Sun.COM /* 23637887SLiane.Praza@Sun.COM * Create the property group, the property referencing the pg_pattern 23647887SLiane.Praza@Sun.COM * name, and add the prop_pattern attributes to the property group. 23657887SLiane.Praza@Sun.COM */ 23667887SLiane.Praza@Sun.COM pg = internal_pgroup_create_strict(service, pg_name, 23677887SLiane.Praza@Sun.COM SCF_GROUP_TEMPLATE_PROP_PATTERN); 23687887SLiane.Praza@Sun.COM if (pg == NULL) { 23697887SLiane.Praza@Sun.COM uu_die(gettext("Property group for prop_pattern, \"%s\", " 23707887SLiane.Praza@Sun.COM "already exists in %s\n"), prop_pattern_name, 23717887SLiane.Praza@Sun.COM service->sc_name); 23727887SLiane.Praza@Sun.COM } 23737887SLiane.Praza@Sun.COM 23747887SLiane.Praza@Sun.COM p = internal_property_create(SCF_PROPERTY_TM_PG_PATTERN, 23757887SLiane.Praza@Sun.COM SCF_TYPE_ASTRING, 1, safe_strdup(pgpat_name)); 23767887SLiane.Praza@Sun.COM /* 23777887SLiane.Praza@Sun.COM * Unfortunately, internal_property_create() does not set the free 23787887SLiane.Praza@Sun.COM * function for the value, so we'll set it now. 23797887SLiane.Praza@Sun.COM */ 23807887SLiane.Praza@Sun.COM v = uu_list_first(p->sc_property_values); 23817887SLiane.Praza@Sun.COM v->sc_free = lxml_free_str; 23827887SLiane.Praza@Sun.COM if (internal_attach_property(pg, p) != 0) 23837887SLiane.Praza@Sun.COM internal_property_free(p); 23847887SLiane.Praza@Sun.COM 23857887SLiane.Praza@Sun.COM 23867887SLiane.Praza@Sun.COM r = lxml_get_prop_pattern_attributes(pg, prop_pattern); 23877887SLiane.Praza@Sun.COM if (r != 0) 23887887SLiane.Praza@Sun.COM goto out; 23897887SLiane.Praza@Sun.COM 23907887SLiane.Praza@Sun.COM /* 23917887SLiane.Praza@Sun.COM * Now process the elements of prop_pattern 23927887SLiane.Praza@Sun.COM */ 23937887SLiane.Praza@Sun.COM for (cursor = prop_pattern->xmlChildrenNode; 23947887SLiane.Praza@Sun.COM cursor != NULL; 23957887SLiane.Praza@Sun.COM cursor = cursor->next) { 23967887SLiane.Praza@Sun.COM if (lxml_ignorable_block(cursor)) 23977887SLiane.Praza@Sun.COM continue; 23987887SLiane.Praza@Sun.COM 23997887SLiane.Praza@Sun.COM switch (lxml_xlate_element(cursor->name)) { 24007887SLiane.Praza@Sun.COM case SC_CARDINALITY: 24017887SLiane.Praza@Sun.COM r = lxml_get_tm_cardinality(service, pg, cursor); 24027887SLiane.Praza@Sun.COM if (r != 0) 24037887SLiane.Praza@Sun.COM goto out; 24047887SLiane.Praza@Sun.COM break; 24057887SLiane.Praza@Sun.COM case SC_CHOICES: 24067887SLiane.Praza@Sun.COM r = lxml_get_tm_choices(service, pg, cursor); 24077887SLiane.Praza@Sun.COM if (r != 0) 24087887SLiane.Praza@Sun.COM goto out; 24097887SLiane.Praza@Sun.COM break; 24107887SLiane.Praza@Sun.COM case SC_COMMON_NAME: 24117887SLiane.Praza@Sun.COM (void) lxml_get_all_loctext(service, pg, cursor, 24127887SLiane.Praza@Sun.COM COMMON_NAME_FMT, (const char *)cursor->name); 24137887SLiane.Praza@Sun.COM break; 24147887SLiane.Praza@Sun.COM case SC_CONSTRAINTS: 24157887SLiane.Praza@Sun.COM r = lxml_get_tm_constraints(service, pg, cursor); 24167887SLiane.Praza@Sun.COM if (r != 0) 24177887SLiane.Praza@Sun.COM goto out; 24187887SLiane.Praza@Sun.COM break; 24197887SLiane.Praza@Sun.COM case SC_DESCRIPTION: 24207887SLiane.Praza@Sun.COM (void) lxml_get_all_loctext(service, pg, cursor, 24217887SLiane.Praza@Sun.COM DESCRIPTION_FMT, (const char *)cursor->name); 24227887SLiane.Praza@Sun.COM break; 24237887SLiane.Praza@Sun.COM case SC_INTERNAL_SEPARATORS: 24247887SLiane.Praza@Sun.COM r = lxml_get_tm_internal_seps(service, pg, cursor); 24257887SLiane.Praza@Sun.COM if (r != 0) 24267887SLiane.Praza@Sun.COM goto out; 24277887SLiane.Praza@Sun.COM break; 24287887SLiane.Praza@Sun.COM case SC_UNITS: 24297887SLiane.Praza@Sun.COM (void) lxml_get_all_loctext(service, pg, cursor, 24307887SLiane.Praza@Sun.COM UNITS_FMT, "units"); 24317887SLiane.Praza@Sun.COM break; 24327887SLiane.Praza@Sun.COM case SC_VALUES: 24337887SLiane.Praza@Sun.COM (void) lxml_get_tm_values(service, pg, cursor); 24347887SLiane.Praza@Sun.COM break; 24357887SLiane.Praza@Sun.COM case SC_VISIBILITY: 24367887SLiane.Praza@Sun.COM /* 24377887SLiane.Praza@Sun.COM * The visibility element is empty, so we only need 24387887SLiane.Praza@Sun.COM * to proccess the value attribute. 24397887SLiane.Praza@Sun.COM */ 24407887SLiane.Praza@Sun.COM (void) new_str_prop_from_attr(pg, 24417887SLiane.Praza@Sun.COM SCF_PROPERTY_TM_VISIBILITY, SCF_TYPE_ASTRING, 24427887SLiane.Praza@Sun.COM cursor, value_attr); 24437887SLiane.Praza@Sun.COM break; 24447887SLiane.Praza@Sun.COM default: 24457887SLiane.Praza@Sun.COM uu_die(gettext("illegal element \"%s\" in prop_pattern " 24467887SLiane.Praza@Sun.COM "for service \"%s\"\n"), cursor->name, 24477887SLiane.Praza@Sun.COM service->sc_name); 24487887SLiane.Praza@Sun.COM } 24497887SLiane.Praza@Sun.COM } 24507887SLiane.Praza@Sun.COM 24517887SLiane.Praza@Sun.COM out: 24527887SLiane.Praza@Sun.COM xmlFree(prop_pattern_name); 24537887SLiane.Praza@Sun.COM free(pg_name); 24547887SLiane.Praza@Sun.COM return (r); 24557887SLiane.Praza@Sun.COM } 24567887SLiane.Praza@Sun.COM 24577887SLiane.Praza@Sun.COM /* 24587887SLiane.Praza@Sun.COM * Get the pg_pattern attributes and save them as properties in the 24597887SLiane.Praza@Sun.COM * property group at pg. The pg_pattern element accepts four attributes -- 24607887SLiane.Praza@Sun.COM * name, type, required and target. 24617887SLiane.Praza@Sun.COM */ 24627887SLiane.Praza@Sun.COM static int 24637887SLiane.Praza@Sun.COM lxml_get_pg_pattern_attributes(pgroup_t *pg, xmlNodePtr cursor) 24647887SLiane.Praza@Sun.COM { 24657887SLiane.Praza@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_TM_NAME, 24667887SLiane.Praza@Sun.COM SCF_TYPE_ASTRING, cursor, name_attr, NULL) != 0) { 24677887SLiane.Praza@Sun.COM return (-1); 24687887SLiane.Praza@Sun.COM } 24697887SLiane.Praza@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_TM_TYPE, 24707887SLiane.Praza@Sun.COM SCF_TYPE_ASTRING, cursor, type_attr, NULL) != 0) { 24717887SLiane.Praza@Sun.COM return (-1); 24727887SLiane.Praza@Sun.COM } 24737887SLiane.Praza@Sun.COM if (new_opt_str_prop_from_attr(pg, SCF_PROPERTY_TM_TARGET, 24747887SLiane.Praza@Sun.COM SCF_TYPE_ASTRING, cursor, target_attr, NULL) != 0) { 24757887SLiane.Praza@Sun.COM return (-1); 24767887SLiane.Praza@Sun.COM } 24777887SLiane.Praza@Sun.COM if (new_bool_prop_from_attr(pg, SCF_PROPERTY_TM_REQUIRED, cursor, 24787887SLiane.Praza@Sun.COM required_attr) != 0) 24797887SLiane.Praza@Sun.COM return (-1); 24807887SLiane.Praza@Sun.COM return (0); 24817887SLiane.Praza@Sun.COM } 24827887SLiane.Praza@Sun.COM 24837887SLiane.Praza@Sun.COM /* 24847887SLiane.Praza@Sun.COM * There are several restrictions on the pg_pattern attributes that cannot 24857887SLiane.Praza@Sun.COM * be specifed in the service bundle DTD. This function verifies that 24867887SLiane.Praza@Sun.COM * those restrictions have been satisfied. The restrictions are: 24877887SLiane.Praza@Sun.COM * 24887887SLiane.Praza@Sun.COM * - The target attribute may have a value of "instance" only when the 24897887SLiane.Praza@Sun.COM * template block is in a service declaration. 24907887SLiane.Praza@Sun.COM * 24917887SLiane.Praza@Sun.COM * - The target attribute may have a value of "delegate" only when the 24927887SLiane.Praza@Sun.COM * template block applies to a restarter. 24937887SLiane.Praza@Sun.COM * 24947887SLiane.Praza@Sun.COM * - The target attribute may have a value of "all" only when the 24957887SLiane.Praza@Sun.COM * template block applies to the master restarter. 24967887SLiane.Praza@Sun.COM * 24977887SLiane.Praza@Sun.COM * The function returns 0 on success and -1 on failure. 24987887SLiane.Praza@Sun.COM */ 24997887SLiane.Praza@Sun.COM static int 25007887SLiane.Praza@Sun.COM verify_pg_pattern_attributes(entity_t *s, pgroup_t *pg) 25017887SLiane.Praza@Sun.COM { 25027887SLiane.Praza@Sun.COM int is_restarter; 25037887SLiane.Praza@Sun.COM property_t *target; 25047887SLiane.Praza@Sun.COM value_t *v; 25057887SLiane.Praza@Sun.COM 25067887SLiane.Praza@Sun.COM /* Find the value of the target property. */ 25077887SLiane.Praza@Sun.COM target = internal_property_find(pg, SCF_PROPERTY_TM_TARGET); 25087887SLiane.Praza@Sun.COM if (target == NULL) { 25097887SLiane.Praza@Sun.COM uu_die(gettext("pg_pattern is missing the %s attribute " 25107887SLiane.Praza@Sun.COM "in %s\n"), target_attr, s->sc_name); 25117887SLiane.Praza@Sun.COM return (-1); 25127887SLiane.Praza@Sun.COM } 25137887SLiane.Praza@Sun.COM v = uu_list_first(target->sc_property_values); 25147887SLiane.Praza@Sun.COM assert(v != NULL); 25157887SLiane.Praza@Sun.COM assert(v->sc_type == SCF_TYPE_ASTRING); 25167887SLiane.Praza@Sun.COM 25177887SLiane.Praza@Sun.COM /* 25187887SLiane.Praza@Sun.COM * If target has a value of instance, the template must be in a 25197887SLiane.Praza@Sun.COM * service object. 25207887SLiane.Praza@Sun.COM */ 25217887SLiane.Praza@Sun.COM if (strcmp(v->sc_u.sc_string, "instance") == 0) { 25227887SLiane.Praza@Sun.COM if (s->sc_etype != SVCCFG_SERVICE_OBJECT) { 25237887SLiane.Praza@Sun.COM uu_warn(gettext("pg_pattern %s attribute may only " 25247887SLiane.Praza@Sun.COM "have a value of \"instance\" when it is in a " 25257887SLiane.Praza@Sun.COM "service declaration.\n"), target_attr); 25267887SLiane.Praza@Sun.COM return (-1); 25277887SLiane.Praza@Sun.COM } 25287887SLiane.Praza@Sun.COM } 25297887SLiane.Praza@Sun.COM 25307887SLiane.Praza@Sun.COM /* 25317887SLiane.Praza@Sun.COM * If target has a value of "delegate", the template must be in a 25327887SLiane.Praza@Sun.COM * restarter. 25337887SLiane.Praza@Sun.COM */ 25347887SLiane.Praza@Sun.COM if (strcmp(v->sc_u.sc_string, "delegate") == 0) { 25357887SLiane.Praza@Sun.COM is_restarter = 0; 25367887SLiane.Praza@Sun.COM if ((s->sc_etype == SVCCFG_SERVICE_OBJECT) && 25377887SLiane.Praza@Sun.COM (s->sc_u.sc_service.sc_service_type == SVCCFG_RESTARTER)) { 25387887SLiane.Praza@Sun.COM is_restarter = 1; 25397887SLiane.Praza@Sun.COM } 25407887SLiane.Praza@Sun.COM if ((s->sc_etype == SVCCFG_INSTANCE_OBJECT) && 25417887SLiane.Praza@Sun.COM (s->sc_parent->sc_u.sc_service.sc_service_type == 25427887SLiane.Praza@Sun.COM SVCCFG_RESTARTER)) { 25437887SLiane.Praza@Sun.COM is_restarter = 1; 25447887SLiane.Praza@Sun.COM } 25457887SLiane.Praza@Sun.COM if (is_restarter == 0) { 25467887SLiane.Praza@Sun.COM uu_warn(gettext("pg_pattern %s attribute has a " 25477887SLiane.Praza@Sun.COM "value of \"delegate\" but is not in a " 25487887SLiane.Praza@Sun.COM "restarter service\n"), target_attr); 25497887SLiane.Praza@Sun.COM return (-1); 25507887SLiane.Praza@Sun.COM } 25517887SLiane.Praza@Sun.COM } 25527887SLiane.Praza@Sun.COM 25537887SLiane.Praza@Sun.COM /* 25547887SLiane.Praza@Sun.COM * If target has a value of "all", the template must be in the 25557887SLiane.Praza@Sun.COM * global (SCF_SERVICE_GLOBAL) service. 25567887SLiane.Praza@Sun.COM */ 25577887SLiane.Praza@Sun.COM if (strcmp(v->sc_u.sc_string, all_value) == 0) { 25587887SLiane.Praza@Sun.COM if (s->sc_etype != SVCCFG_SERVICE_OBJECT) { 25597887SLiane.Praza@Sun.COM uu_warn(gettext("pg_pattern %s attribute has a " 25607887SLiane.Praza@Sun.COM "value of \"%s\" but is not in a " 25617887SLiane.Praza@Sun.COM "service entity.\n"), target_attr, all_value); 25627887SLiane.Praza@Sun.COM return (-1); 25637887SLiane.Praza@Sun.COM } 25647887SLiane.Praza@Sun.COM if (strcmp(s->sc_fmri, SCF_SERVICE_GLOBAL) != 0) { 25657887SLiane.Praza@Sun.COM uu_warn(gettext("pg_pattern %s attribute has a " 25667887SLiane.Praza@Sun.COM "value of \"%s\" but is in the \"%s\" service. " 25677887SLiane.Praza@Sun.COM "pg_patterns with target \"%s\" are only allowed " 25687887SLiane.Praza@Sun.COM "in the global service.\n"), 25697887SLiane.Praza@Sun.COM target_attr, all_value, s->sc_fmri, all_value); 25707887SLiane.Praza@Sun.COM return (-1); 25717887SLiane.Praza@Sun.COM } 25727887SLiane.Praza@Sun.COM } 25737887SLiane.Praza@Sun.COM 25747887SLiane.Praza@Sun.COM return (0); 25757887SLiane.Praza@Sun.COM } 25767887SLiane.Praza@Sun.COM 25777887SLiane.Praza@Sun.COM static int 25787887SLiane.Praza@Sun.COM lxml_get_tm_pg_pattern(entity_t *service, xmlNodePtr pg_pattern) 25797887SLiane.Praza@Sun.COM { 25807887SLiane.Praza@Sun.COM xmlNodePtr cursor; 25817887SLiane.Praza@Sun.COM int out_len; 25827887SLiane.Praza@Sun.COM xmlChar *name; 25837887SLiane.Praza@Sun.COM pgroup_t *pg = NULL; 25847887SLiane.Praza@Sun.COM char *pg_name; 25857887SLiane.Praza@Sun.COM int r = -1; 25867887SLiane.Praza@Sun.COM xmlChar *type; 25877887SLiane.Praza@Sun.COM 25887887SLiane.Praza@Sun.COM pg_name = safe_malloc(max_scf_name_len + 1); 25897887SLiane.Praza@Sun.COM 25907887SLiane.Praza@Sun.COM /* 25917887SLiane.Praza@Sun.COM * Get the name and type attributes. Their presence or absence 25927887SLiane.Praza@Sun.COM * determines whcih prefix we will use for the property group name. 25937887SLiane.Praza@Sun.COM * There are four cases -- neither attribute is present, both are 25947887SLiane.Praza@Sun.COM * present, only name is present or only type is present. 25957887SLiane.Praza@Sun.COM */ 25967887SLiane.Praza@Sun.COM name = xmlGetProp(pg_pattern, (xmlChar *)name_attr); 25977887SLiane.Praza@Sun.COM type = xmlGetProp(pg_pattern, (xmlChar *)type_attr); 25987887SLiane.Praza@Sun.COM if ((name == NULL) || (*name == 0)) { 25997887SLiane.Praza@Sun.COM if ((type == NULL) || (*type == 0)) { 26007887SLiane.Praza@Sun.COM /* PG name contains only the prefix in this case */ 26017887SLiane.Praza@Sun.COM if (strlcpy(pg_name, SCF_PG_TM_PG_PATTERN_PREFIX, 26027887SLiane.Praza@Sun.COM max_scf_name_len + 1) >= max_scf_name_len + 1) { 26037887SLiane.Praza@Sun.COM uu_die(gettext("Unable to create pg_pattern " 26047887SLiane.Praza@Sun.COM "property for %s\n"), service->sc_name); 26057887SLiane.Praza@Sun.COM } 26067887SLiane.Praza@Sun.COM } else { 26077887SLiane.Praza@Sun.COM /* 26087887SLiane.Praza@Sun.COM * If we have a type and no name, the type becomes 26097887SLiane.Praza@Sun.COM * part of the pg_pattern property group name. 26107887SLiane.Praza@Sun.COM */ 26117887SLiane.Praza@Sun.COM if ((out_len = snprintf(pg_name, max_scf_name_len + 1, 26127887SLiane.Praza@Sun.COM "%s%s", SCF_PG_TM_PG_PATTERN_T_PREFIX, type)) >= 26137887SLiane.Praza@Sun.COM max_scf_name_len + 1) { 26147887SLiane.Praza@Sun.COM uu_die(gettext("pg_pattern type is for %s is " 26157887SLiane.Praza@Sun.COM "%d bytes too long\n"), service->sc_name, 26167887SLiane.Praza@Sun.COM out_len - max_scf_name_len); 26177887SLiane.Praza@Sun.COM } 26187887SLiane.Praza@Sun.COM } 26197887SLiane.Praza@Sun.COM } else { 26207887SLiane.Praza@Sun.COM const char *prefix; 26217887SLiane.Praza@Sun.COM 26227887SLiane.Praza@Sun.COM /* Make sure that the name is valid. */ 26237887SLiane.Praza@Sun.COM if (uu_check_name((const char *)name, UU_NAME_DOMAIN) != 0) { 26247887SLiane.Praza@Sun.COM semerr(gettext("pg_pattern name attribute, \"%s\", " 26257887SLiane.Praza@Sun.COM "for %s is invalid\n"), name, service->sc_name); 26267887SLiane.Praza@Sun.COM goto out; 26277887SLiane.Praza@Sun.COM } 26287887SLiane.Praza@Sun.COM 26297887SLiane.Praza@Sun.COM /* 26307887SLiane.Praza@Sun.COM * As long as the pg_pattern has a name, it becomes part of 26317887SLiane.Praza@Sun.COM * the name of the pg_pattern property group name. We 26327887SLiane.Praza@Sun.COM * merely need to pick the appropriate prefix. 26337887SLiane.Praza@Sun.COM */ 26347887SLiane.Praza@Sun.COM if ((type == NULL) || (*type == 0)) { 26357887SLiane.Praza@Sun.COM prefix = SCF_PG_TM_PG_PATTERN_N_PREFIX; 26367887SLiane.Praza@Sun.COM } else { 26377887SLiane.Praza@Sun.COM prefix = SCF_PG_TM_PG_PATTERN_NT_PREFIX; 26387887SLiane.Praza@Sun.COM } 26397887SLiane.Praza@Sun.COM if ((out_len = snprintf(pg_name, max_scf_name_len + 1, "%s%s", 26407887SLiane.Praza@Sun.COM prefix, name)) >= max_scf_name_len + 1) { 26417887SLiane.Praza@Sun.COM uu_die(gettext("pg_pattern property group name " 26427887SLiane.Praza@Sun.COM "for %s is %d bytes too long\n"), service->sc_name, 26437887SLiane.Praza@Sun.COM out_len - max_scf_name_len); 26447887SLiane.Praza@Sun.COM } 26457887SLiane.Praza@Sun.COM } 26467887SLiane.Praza@Sun.COM 26477887SLiane.Praza@Sun.COM /* 26487887SLiane.Praza@Sun.COM * Create the property group for holding this pg_pattern 26497887SLiane.Praza@Sun.COM * information, and capture the pg_pattern attributes. 26507887SLiane.Praza@Sun.COM */ 26517887SLiane.Praza@Sun.COM pg = internal_pgroup_create_strict(service, pg_name, 26527887SLiane.Praza@Sun.COM SCF_GROUP_TEMPLATE_PG_PATTERN); 26537887SLiane.Praza@Sun.COM if (pg == NULL) { 26547887SLiane.Praza@Sun.COM if ((name == NULL) || (*name == 0)) { 26557887SLiane.Praza@Sun.COM if ((type == NULL) ||(*type == 0)) { 26567887SLiane.Praza@Sun.COM semerr(gettext("pg_pattern with empty name and " 26577887SLiane.Praza@Sun.COM "type is not unique in %s\n"), 26587887SLiane.Praza@Sun.COM service->sc_name); 26597887SLiane.Praza@Sun.COM } else { 26607887SLiane.Praza@Sun.COM semerr(gettext("pg_pattern with empty name and " 26617887SLiane.Praza@Sun.COM "type \"%s\" is not unique in %s\n"), 26627887SLiane.Praza@Sun.COM type, service->sc_name); 26637887SLiane.Praza@Sun.COM } 26647887SLiane.Praza@Sun.COM } else { 26657887SLiane.Praza@Sun.COM if ((type == NULL) || (*type == 0)) { 26667887SLiane.Praza@Sun.COM semerr(gettext("pg_pattern with name \"%s\" " 26677887SLiane.Praza@Sun.COM "and empty type is not unique in %s\n"), 26687887SLiane.Praza@Sun.COM name, service->sc_name); 26697887SLiane.Praza@Sun.COM } else { 26707887SLiane.Praza@Sun.COM semerr(gettext("pg_pattern with name \"%s\" " 26717887SLiane.Praza@Sun.COM "and type \"%s\" is not unique in %s\n"), 26727887SLiane.Praza@Sun.COM name, type, service->sc_name); 26737887SLiane.Praza@Sun.COM } 26747887SLiane.Praza@Sun.COM } 26757887SLiane.Praza@Sun.COM goto out; 26767887SLiane.Praza@Sun.COM } 26777887SLiane.Praza@Sun.COM 26787887SLiane.Praza@Sun.COM /* 26797887SLiane.Praza@Sun.COM * Get the pg_pattern attributes from the manifest and verify 26807887SLiane.Praza@Sun.COM * that they satisfy our restrictions. 26817887SLiane.Praza@Sun.COM */ 26827887SLiane.Praza@Sun.COM r = lxml_get_pg_pattern_attributes(pg, pg_pattern); 26837887SLiane.Praza@Sun.COM if (r != 0) 26847887SLiane.Praza@Sun.COM goto out; 26857887SLiane.Praza@Sun.COM if (verify_pg_pattern_attributes(service, pg) != 0) { 26867887SLiane.Praza@Sun.COM semerr(gettext("Invalid pg_pattern attributes in %s\n"), 26877887SLiane.Praza@Sun.COM service->sc_name); 26887887SLiane.Praza@Sun.COM r = -1; 26897887SLiane.Praza@Sun.COM goto out; 26907887SLiane.Praza@Sun.COM } 26917887SLiane.Praza@Sun.COM 26927887SLiane.Praza@Sun.COM /* 26937887SLiane.Praza@Sun.COM * Now process all of the elements of pg_pattern. 26947887SLiane.Praza@Sun.COM */ 26957887SLiane.Praza@Sun.COM for (cursor = pg_pattern->xmlChildrenNode; 26967887SLiane.Praza@Sun.COM cursor != NULL; 26977887SLiane.Praza@Sun.COM cursor = cursor->next) { 26987887SLiane.Praza@Sun.COM if (lxml_ignorable_block(cursor)) 26997887SLiane.Praza@Sun.COM continue; 27007887SLiane.Praza@Sun.COM 27017887SLiane.Praza@Sun.COM switch (lxml_xlate_element(cursor->name)) { 27027887SLiane.Praza@Sun.COM case SC_COMMON_NAME: 27037887SLiane.Praza@Sun.COM (void) lxml_get_all_loctext(service, pg, cursor, 27047887SLiane.Praza@Sun.COM COMMON_NAME_FMT, (const char *)cursor->name); 27057887SLiane.Praza@Sun.COM break; 27067887SLiane.Praza@Sun.COM case SC_DESCRIPTION: 27077887SLiane.Praza@Sun.COM (void) lxml_get_all_loctext(service, pg, cursor, 27087887SLiane.Praza@Sun.COM DESCRIPTION_FMT, (const char *)cursor->name); 27097887SLiane.Praza@Sun.COM break; 27107887SLiane.Praza@Sun.COM case SC_PROP_PATTERN: 27117887SLiane.Praza@Sun.COM r = lxml_get_tm_prop_pattern(service, cursor, 27127887SLiane.Praza@Sun.COM pg_name); 27137887SLiane.Praza@Sun.COM if (r != 0) 27147887SLiane.Praza@Sun.COM goto out; 27157887SLiane.Praza@Sun.COM break; 27167887SLiane.Praza@Sun.COM default: 27177887SLiane.Praza@Sun.COM uu_die(gettext("illegal element \"%s\" in pg_pattern " 27187887SLiane.Praza@Sun.COM "for service \"%s\"\n"), cursor->name, 27197887SLiane.Praza@Sun.COM service->sc_name); 27207887SLiane.Praza@Sun.COM } 27217887SLiane.Praza@Sun.COM } 27227887SLiane.Praza@Sun.COM 27237887SLiane.Praza@Sun.COM out: 27247887SLiane.Praza@Sun.COM if ((r != 0) && (pg != NULL)) { 27257887SLiane.Praza@Sun.COM internal_detach_pgroup(service, pg); 27267887SLiane.Praza@Sun.COM internal_pgroup_free(pg); 27277887SLiane.Praza@Sun.COM } 27287887SLiane.Praza@Sun.COM free(pg_name); 27297887SLiane.Praza@Sun.COM xmlFree(name); 27307887SLiane.Praza@Sun.COM xmlFree(type); 27317887SLiane.Praza@Sun.COM 27327887SLiane.Praza@Sun.COM return (r); 27337887SLiane.Praza@Sun.COM } 27347887SLiane.Praza@Sun.COM 27357887SLiane.Praza@Sun.COM static int 27360Sstevel@tonic-gate lxml_get_template(entity_t *service, xmlNodePtr templ) 27370Sstevel@tonic-gate { 27380Sstevel@tonic-gate xmlNodePtr cursor; 27390Sstevel@tonic-gate 27400Sstevel@tonic-gate for (cursor = templ->xmlChildrenNode; cursor != NULL; 27410Sstevel@tonic-gate cursor = cursor->next) { 27420Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 27430Sstevel@tonic-gate continue; 27440Sstevel@tonic-gate 27450Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) { 27460Sstevel@tonic-gate case SC_COMMON_NAME: 27470Sstevel@tonic-gate (void) lxml_get_tm_common_name(service, cursor); 27480Sstevel@tonic-gate break; 27490Sstevel@tonic-gate case SC_DESCRIPTION: 27500Sstevel@tonic-gate (void) lxml_get_tm_description(service, cursor); 27510Sstevel@tonic-gate break; 27520Sstevel@tonic-gate case SC_DOCUMENTATION: 27530Sstevel@tonic-gate (void) lxml_get_tm_documentation(service, cursor); 27540Sstevel@tonic-gate break; 27557887SLiane.Praza@Sun.COM case SC_PG_PATTERN: 27567887SLiane.Praza@Sun.COM if (lxml_get_tm_pg_pattern(service, cursor) != 0) 27577887SLiane.Praza@Sun.COM return (-1); 27587887SLiane.Praza@Sun.COM break; 27590Sstevel@tonic-gate default: 27600Sstevel@tonic-gate uu_die(gettext("illegal element \"%s\" on template " 27610Sstevel@tonic-gate "for service \"%s\"\n"), 27620Sstevel@tonic-gate cursor->name, service->sc_name); 27630Sstevel@tonic-gate } 27640Sstevel@tonic-gate } 27650Sstevel@tonic-gate 27660Sstevel@tonic-gate return (0); 27670Sstevel@tonic-gate } 27680Sstevel@tonic-gate 27690Sstevel@tonic-gate static int 27700Sstevel@tonic-gate lxml_get_default_instance(entity_t *service, xmlNodePtr definst) 27710Sstevel@tonic-gate { 27720Sstevel@tonic-gate entity_t *i; 27730Sstevel@tonic-gate xmlChar *enabled; 27740Sstevel@tonic-gate pgroup_t *pg; 27750Sstevel@tonic-gate property_t *p; 27760Sstevel@tonic-gate char *package; 27770Sstevel@tonic-gate uint64_t enabled_val = 0; 27780Sstevel@tonic-gate 27790Sstevel@tonic-gate i = internal_instance_new("default"); 27800Sstevel@tonic-gate 27810Sstevel@tonic-gate if ((enabled = xmlGetProp(definst, (xmlChar *)enabled_attr)) != NULL) { 27820Sstevel@tonic-gate enabled_val = (strcmp(true, (const char *)enabled) == 0) ? 27830Sstevel@tonic-gate 1 : 0; 27840Sstevel@tonic-gate xmlFree(enabled); 27850Sstevel@tonic-gate } 27860Sstevel@tonic-gate 27870Sstevel@tonic-gate /* 27880Sstevel@tonic-gate * New general property group with enabled boolean property set. 27890Sstevel@tonic-gate */ 27900Sstevel@tonic-gate 27910Sstevel@tonic-gate pg = internal_pgroup_new(); 27920Sstevel@tonic-gate (void) internal_attach_pgroup(i, pg); 27930Sstevel@tonic-gate 27940Sstevel@tonic-gate pg->sc_pgroup_name = (char *)scf_pg_general; 27950Sstevel@tonic-gate pg->sc_pgroup_type = (char *)scf_group_framework; 27960Sstevel@tonic-gate pg->sc_pgroup_flags = 0; 27970Sstevel@tonic-gate 27980Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_ENABLED, SCF_TYPE_BOOLEAN, 1, 27990Sstevel@tonic-gate enabled_val); 28000Sstevel@tonic-gate 28010Sstevel@tonic-gate (void) internal_attach_property(pg, p); 28020Sstevel@tonic-gate 28030Sstevel@tonic-gate /* 28040Sstevel@tonic-gate * Add general/package property if PKGINST is set. 28050Sstevel@tonic-gate */ 28060Sstevel@tonic-gate if ((package = getenv("PKGINST")) != NULL) { 28070Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_PACKAGE, 28080Sstevel@tonic-gate SCF_TYPE_ASTRING, 1, package); 28090Sstevel@tonic-gate 28100Sstevel@tonic-gate (void) internal_attach_property(pg, p); 28110Sstevel@tonic-gate } 28120Sstevel@tonic-gate 28130Sstevel@tonic-gate return (internal_attach_entity(service, i)); 28140Sstevel@tonic-gate } 28150Sstevel@tonic-gate 28160Sstevel@tonic-gate /* 28170Sstevel@tonic-gate * Translate an instance element into an internal property tree, added to 28185040Swesolows * service. If op is SVCCFG_OP_APPLY (i.e., apply a profile), forbid 28195040Swesolows * subelements and set the enabled property to override. 28200Sstevel@tonic-gate */ 28210Sstevel@tonic-gate static int 28225040Swesolows lxml_get_instance(entity_t *service, xmlNodePtr inst, svccfg_op_t op) 28230Sstevel@tonic-gate { 28240Sstevel@tonic-gate entity_t *i; 28250Sstevel@tonic-gate pgroup_t *pg; 28260Sstevel@tonic-gate property_t *p; 28270Sstevel@tonic-gate xmlNodePtr cursor; 28280Sstevel@tonic-gate xmlChar *enabled; 28290Sstevel@tonic-gate int r; 28300Sstevel@tonic-gate 28310Sstevel@tonic-gate /* 28320Sstevel@tonic-gate * Fetch its attributes, as appropriate. 28330Sstevel@tonic-gate */ 28340Sstevel@tonic-gate i = internal_instance_new((char *)xmlGetProp(inst, 28350Sstevel@tonic-gate (xmlChar *)name_attr)); 28360Sstevel@tonic-gate 28370Sstevel@tonic-gate /* 28380Sstevel@tonic-gate * Note that this must be done before walking the children so that 28390Sstevel@tonic-gate * sc_fmri is set in case we enter lxml_get_dependent(). 28400Sstevel@tonic-gate */ 28410Sstevel@tonic-gate r = internal_attach_entity(service, i); 28420Sstevel@tonic-gate if (r != 0) 28430Sstevel@tonic-gate return (r); 28440Sstevel@tonic-gate 28450Sstevel@tonic-gate enabled = xmlGetProp(inst, (xmlChar *)enabled_attr); 28460Sstevel@tonic-gate 28470Sstevel@tonic-gate /* 28480Sstevel@tonic-gate * New general property group with enabled boolean property set. 28490Sstevel@tonic-gate */ 28500Sstevel@tonic-gate pg = internal_pgroup_new(); 28510Sstevel@tonic-gate (void) internal_attach_pgroup(i, pg); 28520Sstevel@tonic-gate 28530Sstevel@tonic-gate pg->sc_pgroup_name = (char *)scf_pg_general; 28540Sstevel@tonic-gate pg->sc_pgroup_type = (char *)scf_group_framework; 28550Sstevel@tonic-gate pg->sc_pgroup_flags = 0; 28560Sstevel@tonic-gate 28570Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_ENABLED, SCF_TYPE_BOOLEAN, 1, 28580Sstevel@tonic-gate (uint64_t)(strcmp(true, (const char *)enabled) == 0 ? 1 : 0)); 28590Sstevel@tonic-gate 28605040Swesolows p->sc_property_override = (op == SVCCFG_OP_APPLY); 28610Sstevel@tonic-gate 28620Sstevel@tonic-gate (void) internal_attach_property(pg, p); 28630Sstevel@tonic-gate 28640Sstevel@tonic-gate xmlFree(enabled); 28650Sstevel@tonic-gate 28660Sstevel@tonic-gate /* 28670Sstevel@tonic-gate * Walk its child elements, as appropriate. 28680Sstevel@tonic-gate */ 28690Sstevel@tonic-gate for (cursor = inst->xmlChildrenNode; cursor != NULL; 28700Sstevel@tonic-gate cursor = cursor->next) { 28710Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 28720Sstevel@tonic-gate continue; 28730Sstevel@tonic-gate 28745040Swesolows if (op == SVCCFG_OP_APPLY) { 28750Sstevel@tonic-gate semerr(gettext("Instance \"%s\" may not contain " 28760Sstevel@tonic-gate "elements in profiles.\n"), i->sc_name, 28770Sstevel@tonic-gate cursor->name); 28780Sstevel@tonic-gate return (-1); 28790Sstevel@tonic-gate } 28800Sstevel@tonic-gate 28810Sstevel@tonic-gate switch (lxml_xlate_element(cursor->name)) { 28820Sstevel@tonic-gate case SC_RESTARTER: 28830Sstevel@tonic-gate (void) lxml_get_restarter(i, cursor); 28840Sstevel@tonic-gate break; 28850Sstevel@tonic-gate case SC_DEPENDENCY: 28860Sstevel@tonic-gate (void) lxml_get_dependency(i, cursor); 28870Sstevel@tonic-gate break; 28880Sstevel@tonic-gate case SC_DEPENDENT: 28890Sstevel@tonic-gate (void) lxml_get_dependent(i, cursor); 28900Sstevel@tonic-gate break; 28910Sstevel@tonic-gate case SC_METHOD_CONTEXT: 28920Sstevel@tonic-gate (void) lxml_get_entity_method_context(i, cursor); 28930Sstevel@tonic-gate break; 28940Sstevel@tonic-gate case SC_EXEC_METHOD: 28950Sstevel@tonic-gate (void) lxml_get_exec_method(i, cursor); 28960Sstevel@tonic-gate break; 28970Sstevel@tonic-gate case SC_PROPERTY_GROUP: 28980Sstevel@tonic-gate (void) lxml_get_pgroup(i, cursor); 28990Sstevel@tonic-gate break; 29000Sstevel@tonic-gate case SC_TEMPLATE: 29017887SLiane.Praza@Sun.COM if (lxml_get_template(i, cursor) != 0) 29027887SLiane.Praza@Sun.COM return (-1); 29030Sstevel@tonic-gate break; 29040Sstevel@tonic-gate default: 29050Sstevel@tonic-gate uu_die(gettext( 29060Sstevel@tonic-gate "illegal element \"%s\" on instance \"%s\"\n"), 29070Sstevel@tonic-gate cursor->name, i->sc_name); 29080Sstevel@tonic-gate break; 29090Sstevel@tonic-gate } 29100Sstevel@tonic-gate } 29110Sstevel@tonic-gate 29120Sstevel@tonic-gate return (0); 29130Sstevel@tonic-gate } 29140Sstevel@tonic-gate 29150Sstevel@tonic-gate /* ARGSUSED1 */ 29160Sstevel@tonic-gate static int 29170Sstevel@tonic-gate lxml_get_single_instance(entity_t *entity, xmlNodePtr si) 29180Sstevel@tonic-gate { 29190Sstevel@tonic-gate pgroup_t *pg; 29200Sstevel@tonic-gate property_t *p; 29210Sstevel@tonic-gate int r; 29220Sstevel@tonic-gate 29230Sstevel@tonic-gate pg = internal_pgroup_find_or_create(entity, (char *)scf_pg_general, 29240Sstevel@tonic-gate (char *)scf_group_framework); 29250Sstevel@tonic-gate 29260Sstevel@tonic-gate p = internal_property_create(SCF_PROPERTY_SINGLE_INSTANCE, 29270Sstevel@tonic-gate SCF_TYPE_BOOLEAN, 1, (uint64_t)1); 29280Sstevel@tonic-gate 29290Sstevel@tonic-gate r = internal_attach_property(pg, p); 29300Sstevel@tonic-gate if (r != 0) { 29310Sstevel@tonic-gate internal_property_free(p); 29320Sstevel@tonic-gate return (-1); 29330Sstevel@tonic-gate } 29340Sstevel@tonic-gate 29350Sstevel@tonic-gate return (0); 29360Sstevel@tonic-gate } 29370Sstevel@tonic-gate 29380Sstevel@tonic-gate /* 29390Sstevel@tonic-gate * Translate a service element into an internal instance/property tree, added 29405040Swesolows * to bundle. If op is SVCCFG_OP_APPLY, allow only instance subelements. 29410Sstevel@tonic-gate */ 29420Sstevel@tonic-gate static int 29435040Swesolows lxml_get_service(bundle_t *bundle, xmlNodePtr svc, svccfg_op_t op) 29440Sstevel@tonic-gate { 29450Sstevel@tonic-gate entity_t *s; 29460Sstevel@tonic-gate xmlNodePtr cursor; 29470Sstevel@tonic-gate xmlChar *type; 29480Sstevel@tonic-gate xmlChar *version; 29490Sstevel@tonic-gate int e; 29500Sstevel@tonic-gate 29510Sstevel@tonic-gate /* 29520Sstevel@tonic-gate * Fetch attributes, as appropriate. 29530Sstevel@tonic-gate */ 29540Sstevel@tonic-gate s = internal_service_new((char *)xmlGetProp(svc, 29550Sstevel@tonic-gate (xmlChar *)name_attr)); 29560Sstevel@tonic-gate 29577887SLiane.Praza@Sun.COM version = xmlGetProp(svc, (xmlChar *)version_attr); 29580Sstevel@tonic-gate s->sc_u.sc_service.sc_service_version = atol((const char *)version); 29590Sstevel@tonic-gate xmlFree(version); 29600Sstevel@tonic-gate 29610Sstevel@tonic-gate type = xmlGetProp(svc, (xmlChar *)type_attr); 29620Sstevel@tonic-gate s->sc_u.sc_service.sc_service_type = lxml_xlate_service_type(type); 29630Sstevel@tonic-gate xmlFree(type); 29640Sstevel@tonic-gate 29650Sstevel@tonic-gate /* 29660Sstevel@tonic-gate * Walk its child elements, as appropriate. 29670Sstevel@tonic-gate */ 29680Sstevel@tonic-gate for (cursor = svc->xmlChildrenNode; cursor != NULL; 29690Sstevel@tonic-gate cursor = cursor->next) { 29700Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 29710Sstevel@tonic-gate continue; 29720Sstevel@tonic-gate 29730Sstevel@tonic-gate e = lxml_xlate_element(cursor->name); 29740Sstevel@tonic-gate 29755040Swesolows if (op == SVCCFG_OP_APPLY && e != SC_INSTANCE) { 29760Sstevel@tonic-gate semerr(gettext("Service \"%s\" may not contain the " 29770Sstevel@tonic-gate "non-instance element \"%s\" in a profile.\n"), 29780Sstevel@tonic-gate s->sc_name, cursor->name); 29790Sstevel@tonic-gate 29800Sstevel@tonic-gate return (-1); 29810Sstevel@tonic-gate } 29820Sstevel@tonic-gate 29830Sstevel@tonic-gate switch (e) { 29840Sstevel@tonic-gate case SC_INSTANCE: 29857887SLiane.Praza@Sun.COM if (lxml_get_instance(s, cursor, op) != 0) 29867887SLiane.Praza@Sun.COM return (-1); 29870Sstevel@tonic-gate break; 29880Sstevel@tonic-gate case SC_TEMPLATE: 29897887SLiane.Praza@Sun.COM if (lxml_get_template(s, cursor) != 0) 29907887SLiane.Praza@Sun.COM return (-1); 29910Sstevel@tonic-gate break; 29920Sstevel@tonic-gate case SC_STABILITY: 29930Sstevel@tonic-gate (void) lxml_get_entity_stability(s, cursor); 29940Sstevel@tonic-gate break; 29950Sstevel@tonic-gate case SC_DEPENDENCY: 29960Sstevel@tonic-gate (void) lxml_get_dependency(s, cursor); 29970Sstevel@tonic-gate break; 29980Sstevel@tonic-gate case SC_DEPENDENT: 29990Sstevel@tonic-gate (void) lxml_get_dependent(s, cursor); 30000Sstevel@tonic-gate break; 30010Sstevel@tonic-gate case SC_RESTARTER: 30020Sstevel@tonic-gate (void) lxml_get_restarter(s, cursor); 30030Sstevel@tonic-gate break; 30040Sstevel@tonic-gate case SC_EXEC_METHOD: 30050Sstevel@tonic-gate (void) lxml_get_exec_method(s, cursor); 30060Sstevel@tonic-gate break; 30070Sstevel@tonic-gate case SC_METHOD_CONTEXT: 30080Sstevel@tonic-gate (void) lxml_get_entity_method_context(s, cursor); 30090Sstevel@tonic-gate break; 30100Sstevel@tonic-gate case SC_PROPERTY_GROUP: 30110Sstevel@tonic-gate (void) lxml_get_pgroup(s, cursor); 30120Sstevel@tonic-gate break; 30130Sstevel@tonic-gate case SC_INSTANCE_CREATE_DEFAULT: 30140Sstevel@tonic-gate (void) lxml_get_default_instance(s, cursor); 30150Sstevel@tonic-gate break; 30160Sstevel@tonic-gate case SC_INSTANCE_SINGLE: 30170Sstevel@tonic-gate (void) lxml_get_single_instance(s, cursor); 30180Sstevel@tonic-gate break; 30190Sstevel@tonic-gate default: 30200Sstevel@tonic-gate uu_die(gettext( 30210Sstevel@tonic-gate "illegal element \"%s\" on service \"%s\"\n"), 30220Sstevel@tonic-gate cursor->name, s->sc_name); 30230Sstevel@tonic-gate break; 30240Sstevel@tonic-gate } 30250Sstevel@tonic-gate } 30260Sstevel@tonic-gate 30270Sstevel@tonic-gate return (internal_attach_service(bundle, s)); 30280Sstevel@tonic-gate } 30290Sstevel@tonic-gate 30300Sstevel@tonic-gate #ifdef DEBUG 30310Sstevel@tonic-gate void 30320Sstevel@tonic-gate lxml_dump(int g, xmlNodePtr p) 30330Sstevel@tonic-gate { 30340Sstevel@tonic-gate if (p && p->name) { 30350Sstevel@tonic-gate printf("%d %s\n", g, p->name); 30360Sstevel@tonic-gate 30370Sstevel@tonic-gate for (p = p->xmlChildrenNode; p != NULL; p = p->next) 30380Sstevel@tonic-gate lxml_dump(g + 1, p); 30390Sstevel@tonic-gate } 30400Sstevel@tonic-gate } 30410Sstevel@tonic-gate #endif /* DEBUG */ 30420Sstevel@tonic-gate 30430Sstevel@tonic-gate static int 30440Sstevel@tonic-gate lxml_is_known_dtd(const xmlChar *dtdname) 30450Sstevel@tonic-gate { 30460Sstevel@tonic-gate if (dtdname == NULL || 30470Sstevel@tonic-gate strcmp(MANIFEST_DTD_PATH, (const char *)dtdname) != 0) 30480Sstevel@tonic-gate return (0); 30490Sstevel@tonic-gate 30500Sstevel@tonic-gate return (1); 30510Sstevel@tonic-gate } 30520Sstevel@tonic-gate 30530Sstevel@tonic-gate static int 30540Sstevel@tonic-gate lxml_get_bundle(bundle_t *bundle, bundle_type_t bundle_type, 30555040Swesolows xmlNodePtr subbundle, svccfg_op_t op) 30560Sstevel@tonic-gate { 30570Sstevel@tonic-gate xmlNodePtr cursor; 30580Sstevel@tonic-gate xmlChar *type; 30590Sstevel@tonic-gate int e; 30600Sstevel@tonic-gate 30610Sstevel@tonic-gate /* 30620Sstevel@tonic-gate * 1. Get bundle attributes. 30630Sstevel@tonic-gate */ 30647887SLiane.Praza@Sun.COM type = xmlGetProp(subbundle, (xmlChar *)type_attr); 30650Sstevel@tonic-gate bundle->sc_bundle_type = lxml_xlate_bundle_type(type); 30660Sstevel@tonic-gate if (bundle->sc_bundle_type != bundle_type && 30670Sstevel@tonic-gate bundle_type != SVCCFG_UNKNOWN_BUNDLE) { 30680Sstevel@tonic-gate semerr(gettext("included bundle of different type.\n")); 30690Sstevel@tonic-gate return (-1); 30700Sstevel@tonic-gate } 30710Sstevel@tonic-gate 30720Sstevel@tonic-gate xmlFree(type); 30730Sstevel@tonic-gate 30745040Swesolows switch (op) { 30755040Swesolows case SVCCFG_OP_IMPORT: 30760Sstevel@tonic-gate if (bundle->sc_bundle_type != SVCCFG_MANIFEST) { 30770Sstevel@tonic-gate semerr(gettext("document is not a manifest.\n")); 30780Sstevel@tonic-gate return (-1); 30790Sstevel@tonic-gate } 30805040Swesolows break; 30815040Swesolows case SVCCFG_OP_APPLY: 30820Sstevel@tonic-gate if (bundle->sc_bundle_type != SVCCFG_PROFILE) { 30830Sstevel@tonic-gate semerr(gettext("document is not a profile.\n")); 30840Sstevel@tonic-gate return (-1); 30850Sstevel@tonic-gate } 30865040Swesolows break; 30875040Swesolows case SVCCFG_OP_RESTORE: 30885040Swesolows if (bundle->sc_bundle_type != SVCCFG_ARCHIVE) { 30895040Swesolows semerr(gettext("document is not an archive.\n")); 30905040Swesolows return (-1); 30915040Swesolows } 30925040Swesolows break; 30930Sstevel@tonic-gate } 30940Sstevel@tonic-gate 30957887SLiane.Praza@Sun.COM if (((bundle->sc_bundle_name = xmlGetProp(subbundle, 30967887SLiane.Praza@Sun.COM (xmlChar *)name_attr)) == NULL) || (*bundle->sc_bundle_name == 0)) { 30970Sstevel@tonic-gate semerr(gettext("service bundle lacks name attribute\n")); 30980Sstevel@tonic-gate return (-1); 30990Sstevel@tonic-gate } 31000Sstevel@tonic-gate 31010Sstevel@tonic-gate /* 31020Sstevel@tonic-gate * 2. Get services, descend into each one and build state. 31030Sstevel@tonic-gate */ 31040Sstevel@tonic-gate for (cursor = subbundle->xmlChildrenNode; cursor != NULL; 31050Sstevel@tonic-gate cursor = cursor->next) { 31060Sstevel@tonic-gate if (lxml_ignorable_block(cursor)) 31070Sstevel@tonic-gate continue; 31080Sstevel@tonic-gate 31090Sstevel@tonic-gate e = lxml_xlate_element(cursor->name); 31100Sstevel@tonic-gate 31110Sstevel@tonic-gate switch (e) { 31120Sstevel@tonic-gate case SC_XI_INCLUDE: 31130Sstevel@tonic-gate continue; 31140Sstevel@tonic-gate 31150Sstevel@tonic-gate case SC_SERVICE_BUNDLE: 31165040Swesolows if (lxml_get_bundle(bundle, bundle_type, cursor, op)) 31170Sstevel@tonic-gate return (-1); 31180Sstevel@tonic-gate break; 31190Sstevel@tonic-gate case SC_SERVICE: 31207887SLiane.Praza@Sun.COM if (lxml_get_service(bundle, cursor, op) != 0) 31217887SLiane.Praza@Sun.COM return (-1); 31220Sstevel@tonic-gate break; 31230Sstevel@tonic-gate } 31240Sstevel@tonic-gate } 31250Sstevel@tonic-gate 31260Sstevel@tonic-gate return (0); 31270Sstevel@tonic-gate } 31280Sstevel@tonic-gate 31290Sstevel@tonic-gate /* 31300Sstevel@tonic-gate * Load an XML tree from filename and translate it into an internal service 31315040Swesolows * tree bundle. Require that the bundle be of appropriate type for the 31325040Swesolows * operation: archive for RESTORE, manifest for IMPORT, profile for APPLY. 31330Sstevel@tonic-gate */ 31340Sstevel@tonic-gate int 31355040Swesolows lxml_get_bundle_file(bundle_t *bundle, const char *filename, svccfg_op_t op) 31360Sstevel@tonic-gate { 31370Sstevel@tonic-gate xmlDocPtr document; 31380Sstevel@tonic-gate xmlNodePtr cursor; 31390Sstevel@tonic-gate xmlDtdPtr dtd = NULL; 31400Sstevel@tonic-gate xmlValidCtxtPtr vcp; 31410Sstevel@tonic-gate boolean_t do_validate; 31420Sstevel@tonic-gate char *dtdpath = NULL; 31430Sstevel@tonic-gate int r; 31440Sstevel@tonic-gate 31450Sstevel@tonic-gate /* 31464740Sjeanm * Verify we can read the file before we try to parse it. 31474740Sjeanm */ 31484740Sjeanm if (access(filename, R_OK | F_OK) == -1) { 31494740Sjeanm semerr(gettext("unable to open file: %s\n"), strerror(errno)); 31504740Sjeanm return (-1); 31514740Sjeanm } 31524740Sjeanm 31534740Sjeanm /* 31540Sstevel@tonic-gate * Until libxml2 addresses DTD-based validation with XInclude, we don't 31550Sstevel@tonic-gate * validate service profiles (i.e. the apply path). 31560Sstevel@tonic-gate */ 31575040Swesolows do_validate = (op != SVCCFG_OP_APPLY) && 31585040Swesolows (getenv("SVCCFG_NOVALIDATE") == NULL); 31590Sstevel@tonic-gate if (do_validate) 31600Sstevel@tonic-gate dtdpath = getenv("SVCCFG_DTD"); 31610Sstevel@tonic-gate 31620Sstevel@tonic-gate if (dtdpath != NULL) 31630Sstevel@tonic-gate xmlLoadExtDtdDefaultValue = 0; 31640Sstevel@tonic-gate 31654740Sjeanm if ((document = xmlReadFile(filename, NULL, 0)) == NULL) { 31660Sstevel@tonic-gate semerr(gettext("couldn't parse document\n")); 31670Sstevel@tonic-gate return (-1); 31680Sstevel@tonic-gate } 31690Sstevel@tonic-gate 31700Sstevel@tonic-gate /* 31710Sstevel@tonic-gate * Verify that this is a document type we understand. 31720Sstevel@tonic-gate */ 31730Sstevel@tonic-gate if ((dtd = xmlGetIntSubset(document)) == NULL) { 31740Sstevel@tonic-gate semerr(gettext("document has no DTD\n")); 31750Sstevel@tonic-gate return (-1); 31760Sstevel@tonic-gate } 31770Sstevel@tonic-gate 31780Sstevel@tonic-gate if (!lxml_is_known_dtd(dtd->SystemID)) { 31790Sstevel@tonic-gate semerr(gettext("document DTD unknown; not service bundle?\n")); 31800Sstevel@tonic-gate return (-1); 31810Sstevel@tonic-gate } 31820Sstevel@tonic-gate 31830Sstevel@tonic-gate if ((cursor = xmlDocGetRootElement(document)) == NULL) { 31840Sstevel@tonic-gate semerr(gettext("document is empty\n")); 31850Sstevel@tonic-gate xmlFreeDoc(document); 31860Sstevel@tonic-gate return (-1); 31870Sstevel@tonic-gate } 31880Sstevel@tonic-gate 31890Sstevel@tonic-gate if (xmlStrcmp(cursor->name, (const xmlChar *)"service_bundle") != 0) { 31900Sstevel@tonic-gate semerr(gettext("document is not a service bundle\n")); 31910Sstevel@tonic-gate xmlFreeDoc(document); 31920Sstevel@tonic-gate return (-1); 31930Sstevel@tonic-gate } 31940Sstevel@tonic-gate 31950Sstevel@tonic-gate 31960Sstevel@tonic-gate if (dtdpath != NULL) { 31970Sstevel@tonic-gate dtd = xmlParseDTD(NULL, (xmlChar *)dtdpath); 31980Sstevel@tonic-gate if (dtd == NULL) { 31990Sstevel@tonic-gate semerr(gettext("Could not parse DTD \"%s\".\n"), 32000Sstevel@tonic-gate dtdpath); 32010Sstevel@tonic-gate return (-1); 32020Sstevel@tonic-gate } 32030Sstevel@tonic-gate 32040Sstevel@tonic-gate if (document->extSubset != NULL) 32050Sstevel@tonic-gate xmlFreeDtd(document->extSubset); 32060Sstevel@tonic-gate 32070Sstevel@tonic-gate document->extSubset = dtd; 32080Sstevel@tonic-gate } 32090Sstevel@tonic-gate 32104740Sjeanm if (xmlXIncludeProcessFlags(document, XML_PARSE_XINCLUDE) == -1) { 32110Sstevel@tonic-gate semerr(gettext("couldn't handle XInclude statements " 32124740Sjeanm "in document\n")); 32130Sstevel@tonic-gate return (-1); 32140Sstevel@tonic-gate } 32150Sstevel@tonic-gate 32160Sstevel@tonic-gate if (do_validate) { 32170Sstevel@tonic-gate vcp = xmlNewValidCtxt(); 32180Sstevel@tonic-gate if (vcp == NULL) 32190Sstevel@tonic-gate uu_die(gettext("could not allocate memory")); 32200Sstevel@tonic-gate vcp->warning = xmlParserValidityWarning; 32210Sstevel@tonic-gate vcp->error = xmlParserValidityError; 32220Sstevel@tonic-gate 32230Sstevel@tonic-gate r = xmlValidateDocument(vcp, document); 32240Sstevel@tonic-gate 32250Sstevel@tonic-gate xmlFreeValidCtxt(vcp); 32260Sstevel@tonic-gate 32270Sstevel@tonic-gate if (r == 0) { 32280Sstevel@tonic-gate semerr(gettext("Document is not valid.\n")); 32290Sstevel@tonic-gate xmlFreeDoc(document); 32300Sstevel@tonic-gate return (-1); 32310Sstevel@tonic-gate } 32320Sstevel@tonic-gate } 32330Sstevel@tonic-gate 32340Sstevel@tonic-gate 32350Sstevel@tonic-gate #ifdef DEBUG 32360Sstevel@tonic-gate lxml_dump(0, cursor); 32370Sstevel@tonic-gate #endif /* DEBUG */ 32380Sstevel@tonic-gate 32395040Swesolows r = lxml_get_bundle(bundle, SVCCFG_UNKNOWN_BUNDLE, cursor, op); 32400Sstevel@tonic-gate 32410Sstevel@tonic-gate xmlFreeDoc(document); 32420Sstevel@tonic-gate 32430Sstevel@tonic-gate return (r); 32440Sstevel@tonic-gate } 32450Sstevel@tonic-gate 32460Sstevel@tonic-gate int 32470Sstevel@tonic-gate lxml_inventory(const char *filename) 32480Sstevel@tonic-gate { 32490Sstevel@tonic-gate bundle_t *b; 32500Sstevel@tonic-gate uu_list_walk_t *svcs, *insts; 32510Sstevel@tonic-gate entity_t *svc, *inst; 32520Sstevel@tonic-gate 32530Sstevel@tonic-gate b = internal_bundle_new(); 32540Sstevel@tonic-gate 32555040Swesolows if (lxml_get_bundle_file(b, filename, SVCCFG_OP_IMPORT) != 0) { 32560Sstevel@tonic-gate internal_bundle_free(b); 32570Sstevel@tonic-gate return (-1); 32580Sstevel@tonic-gate } 32590Sstevel@tonic-gate 32600Sstevel@tonic-gate svcs = uu_list_walk_start(b->sc_bundle_services, 0); 32610Sstevel@tonic-gate if (svcs == NULL) 32620Sstevel@tonic-gate uu_die(gettext("Couldn't walk services")); 32630Sstevel@tonic-gate 32640Sstevel@tonic-gate while ((svc = uu_list_walk_next(svcs)) != NULL) { 32650Sstevel@tonic-gate uu_list_t *inst_list; 32660Sstevel@tonic-gate 32670Sstevel@tonic-gate inst_list = svc->sc_u.sc_service.sc_service_instances; 32680Sstevel@tonic-gate insts = uu_list_walk_start(inst_list, 0); 32690Sstevel@tonic-gate if (insts == NULL) 32700Sstevel@tonic-gate uu_die(gettext("Couldn't walk instances")); 32710Sstevel@tonic-gate 32720Sstevel@tonic-gate while ((inst = uu_list_walk_next(insts)) != NULL) 32730Sstevel@tonic-gate (void) printf("svc:/%s:%s\n", svc->sc_name, 32740Sstevel@tonic-gate inst->sc_name); 32750Sstevel@tonic-gate 32760Sstevel@tonic-gate uu_list_walk_end(insts); 32770Sstevel@tonic-gate } 32780Sstevel@tonic-gate 32790Sstevel@tonic-gate uu_list_walk_end(svcs); 32800Sstevel@tonic-gate 32810Sstevel@tonic-gate svcs = uu_list_walk_start(b->sc_bundle_services, 0); 32820Sstevel@tonic-gate while ((svc = uu_list_walk_next(svcs)) != NULL) { 32830Sstevel@tonic-gate (void) fputs("svc:/", stdout); 32840Sstevel@tonic-gate (void) puts(svc->sc_name); 32850Sstevel@tonic-gate } 32860Sstevel@tonic-gate uu_list_walk_end(svcs); 32870Sstevel@tonic-gate 32880Sstevel@tonic-gate internal_bundle_free(b); 32890Sstevel@tonic-gate 32900Sstevel@tonic-gate return (0); 32910Sstevel@tonic-gate } 3292