4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
25 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
30 * XML document manipulation routines
32 * These routines provide translation to and from the internal representation to
33 * XML. Directionally-oriented verbs are with respect to the external source,
34 * so lxml_get_service() fetches a service from the XML file into the
35 * internal representation.
38 #include <libxml/parser.h>
39 #include <libxml/xinclude.h>
46 #include <libscf_priv.h>
48 #include <sasl/saslutil.h>
53 #include <sys/types.h>
57 #include <sys/param.h>
58 #include "manifest_hash.h"
61 #include "notify_params.h"
64 * snprintf(3C) format strings for constructing property names that include
65 * the locale designation. Use %s to indicate where the locale should go.
67 * The VALUE_* symbols are an exception. The firs %s will be replaced with
68 * "value_". The second %s will be replaced by the name of the value and
69 * %%s will be replaced by the locale designation. These formats are
70 * processed twice by snprintf(3C). The first time captures the value name
71 * and the second time captures the locale.
73 #define LOCALE_ONLY_FMT ("%s")
74 #define COMMON_NAME_FMT ("common_name_%s")
75 #define DESCRIPTION_FMT ("description_%s")
76 #define UNITS_FMT ("units_%s")
77 #define VALUE_COMMON_NAME_FMT ("%s%s_common_name_%%s")
78 #define VALUE_DESCRIPTION_FMT ("%s%s_description_%%s")
81 const char * const delete_attr
= "delete";
82 const char * const enabled_attr
= "enabled";
83 const char * const lang_attr
= "lang";
84 const char * const manpath_attr
= "manpath";
85 const char * const max_attr
= "max";
86 const char * const min_attr
= "min";
87 const char * const name_attr
= "name";
88 const char * const override_attr
= "override";
89 const char * const required_attr
= "required";
90 const char * const section_attr
= "section";
91 const char * const set_attr
= "set";
92 const char * const target_attr
= "target";
93 const char * const timeout_seconds_attr
= "timeout_seconds";
94 const char * const title_attr
= "title";
95 const char * const type_attr
= "type";
96 const char * const uri_attr
= "uri";
97 const char * const value_attr
= "value";
98 const char * const version_attr
= "version";
99 const char * const xml_lang_attr
= "xml:lang";
100 const char * const active_attr
= "active";
102 /* Attribute values */
103 const char * const all_value
= "all";
105 const char * const true = "true";
106 const char * const false = "false";
109 * The following list must be kept in the same order as that of
112 static const char *lxml_elements
[] = {
113 "astring_list", /* SC_ASTRING */
114 "boolean_list", /* SC_BOOLEAN */
115 "cardinality", /* SC_CARDINALITY */
116 "choices", /* SC_CHOICES */
117 "common_name", /* SC_COMMON_NAME */
118 "constraints", /* SC_CONSTRAINTS */
119 "count_list", /* SC_COUNT */
120 "create_default_instance", /* SC_INSTANCE_CREATE_DEFAULT */
121 "dependency", /* SC_DEPENDENCY */
122 "dependent", /* SC_DEPENDENT */
123 "description", /* SC_DESCRIPTION */
124 "doc_link", /* SC_DOC_LINK */
125 "documentation", /* SC_DOCUMENTATION */
126 "enabled", /* SC_ENABLED */
127 "event", /* SC_EVENT */
128 "exec_method", /* SC_EXEC_METHOD */
129 "fmri_list", /* SC_FMRI */
130 "host_list", /* SC_HOST */
131 "hostname_list", /* SC_HOSTNAME */
132 "include_values", /* SC_INCLUDE_VALUES */
133 "instance", /* SC_INSTANCE */
134 "integer_list", /* SC_INTEGER */
135 "internal_separators", /* SC_INTERNAL_SEPARATORS */
136 "loctext", /* SC_LOCTEXT */
137 "manpage", /* SC_MANPAGE */
138 "method_context", /* SC_METHOD_CONTEXT */
139 "method_credential", /* SC_METHOD_CREDENTIAL */
140 "method_profile", /* SC_METHOD_PROFILE */
141 "method_environment", /* SC_METHOD_ENVIRONMENT */
142 "envvar", /* SC_METHOD_ENVVAR */
143 "net_address_list", /* SC_NET_ADDR */
144 "net_address_v4_list", /* SC_NET_ADDR_V4 */
145 "net_address_v6_list", /* SC_NET_ADDR_V6 */
146 "notification_parameters", /* SC_NOTIFICATION_PARAMETERS */
147 "opaque_list", /* SC_OPAQUE */
148 "parameter", /* SC_PARAMETER */
149 "paramval", /* SC_PARAMVAL */
150 "pg_pattern", /* SC_PG_PATTERN */
151 "prop_pattern", /* SC_PROP_PATTERN */
152 "property", /* SC_PROPERTY */
153 "property_group", /* SC_PROPERTY_GROUP */
154 "propval", /* SC_PROPVAL */
155 "range", /* SC_RANGE */
156 "restarter", /* SC_RESTARTER */
157 "service", /* SC_SERVICE */
158 "service_bundle", /* SC_SERVICE_BUNDLE */
159 "service_fmri", /* SC_SERVICE_FMRI */
160 "single_instance", /* SC_INSTANCE_SINGLE */
161 "stability", /* SC_STABILITY */
162 "template", /* SC_TEMPLATE */
163 "time_list", /* SC_TIME */
164 "type", /* SC_TYPE */
165 "units", /* SC_UNITS */
166 "uri_list", /* SC_URI */
167 "ustring_list", /* SC_USTRING */
168 "value", /* SC_VALUE */
169 "value_node", /* SC_VALUE_NODE */
170 "values", /* SC_VALUES */
171 "visibility", /* SC_VISIBILITY */
172 "xi:fallback", /* SC_XI_FALLBACK */
173 "xi:include" /* SC_XI_INCLUDE */
177 * The following list must be kept in the same order as that of
180 static const char *lxml_prop_types
[] = {
181 "astring", /* SC_ASTRING */
182 "boolean", /* SC_BOOLEAN */
183 "", /* SC_CARDINALITY */
185 "", /* SC_COMMON_NAME */
186 "", /* SC_CONSTRAINTS */
187 "count", /* SC_COUNT */
188 "", /* SC_INSTANCE_CREATE_DEFAULT */
189 "", /* SC_DEPENDENCY */
190 "", /* SC_DEPENDENT */
191 "", /* SC_DESCRIPTION */
192 "", /* SC_DOC_LINK */
193 "", /* SC_DOCUMENTATION */
196 "", /* SC_EXEC_METHOD */
197 "fmri", /* SC_FMRI */
198 "host", /* SC_HOST */
199 "hostname", /* SC_HOSTNAME */
200 "", /* SC_INCLUDE_VALUES */
201 "", /* SC_INSTANCE */
202 "integer", /* SC_INTEGER */
203 "", /* SC_INTERNAL_SEPARATORS */
206 "", /* SC_METHOD_CONTEXT */
207 "", /* SC_METHOD_CREDENTIAL */
208 "", /* SC_METHOD_PROFILE */
209 "", /* SC_METHOD_ENVIRONMENT */
210 "", /* SC_METHOD_ENVVAR */
211 "net_address", /* SC_NET_ADDR */
212 "net_address_v4", /* SC_NET_ADDR_V4 */
213 "net_address_v6", /* SC_NET_ADDR_V6 */
214 "", /* SC_NOTIFICATION_PARAMETERS */
215 "opaque", /* SC_OPAQUE */
216 "", /* SC_PARAMETER */
217 "", /* SC_PARAMVAL */
218 "", /* SC_PG_PATTERN */
219 "", /* SC_PROP_PATTERN */
220 "", /* SC_PROPERTY */
221 "", /* SC_PROPERTY_GROUP */
224 "", /* SC_RESTARTER */
226 "", /* SC_SERVICE_BUNDLE */
227 "", /* SC_SERVICE_FMRI */
228 "", /* SC_INSTANCE_SINGLE */
229 "", /* SC_STABILITY */
230 "", /* SC_TEMPLATE */
231 "time", /* SC_TIME */
235 "ustring", /* SC_USTRING */
237 "", /* SC_VALUE_NODE */
239 "", /* SC_VISIBILITY */
240 "", /* SC_XI_FALLBACK */
241 "" /* SC_XI_INCLUDE */
247 if (getenv("SVCCFG_NOVALIDATE") == NULL
) {
249 * DTD validation, with line numbers.
251 (void) xmlLineNumbersDefault(1);
252 xmlLoadExtDtdDefaultValue
|= XML_DETECT_IDS
;
253 xmlLoadExtDtdDefaultValue
|= XML_COMPLETE_ATTRS
;
260 lxml_xlate_bundle_type(xmlChar
*type
)
262 if (xmlStrcmp(type
, (const xmlChar
*)"manifest") == 0)
263 return (SVCCFG_MANIFEST
);
265 if (xmlStrcmp(type
, (const xmlChar
*)"profile") == 0)
266 return (SVCCFG_PROFILE
);
268 if (xmlStrcmp(type
, (const xmlChar
*)"archive") == 0)
269 return (SVCCFG_ARCHIVE
);
271 return (SVCCFG_UNKNOWN_BUNDLE
);
274 static service_type_t
275 lxml_xlate_service_type(xmlChar
*type
)
277 if (xmlStrcmp(type
, (const xmlChar
*)"service") == 0)
278 return (SVCCFG_SERVICE
);
280 if (xmlStrcmp(type
, (const xmlChar
*)"restarter") == 0)
281 return (SVCCFG_RESTARTER
);
283 if (xmlStrcmp(type
, (const xmlChar
*)"milestone") == 0)
284 return (SVCCFG_MILESTONE
);
286 return (SVCCFG_UNKNOWN_SERVICE
);
290 lxml_xlate_element(const xmlChar
*tag
)
294 for (i
= 0; i
< sizeof (lxml_elements
) / sizeof (char *); i
++)
295 if (xmlStrcmp(tag
, (const xmlChar
*)lxml_elements
[i
]) == 0)
296 return ((element_t
)i
);
298 return ((element_t
)-1);
302 lxml_xlate_boolean(const xmlChar
*value
)
304 if (xmlStrcmp(value
, (const xmlChar
*)true) == 0)
307 if (xmlStrcmp(value
, (const xmlChar
*)false) == 0)
310 uu_die(gettext("illegal boolean value \"%s\"\n"), value
);
316 lxml_element_to_type(element_t type
)
319 case SC_ASTRING
: return (SCF_TYPE_ASTRING
);
320 case SC_BOOLEAN
: return (SCF_TYPE_BOOLEAN
);
321 case SC_COUNT
: return (SCF_TYPE_COUNT
);
322 case SC_FMRI
: return (SCF_TYPE_FMRI
);
323 case SC_HOST
: return (SCF_TYPE_HOST
);
324 case SC_HOSTNAME
: return (SCF_TYPE_HOSTNAME
);
325 case SC_INTEGER
: return (SCF_TYPE_INTEGER
);
326 case SC_NET_ADDR
: return (SCF_TYPE_NET_ADDR
);
327 case SC_NET_ADDR_V4
: return (SCF_TYPE_NET_ADDR_V4
);
328 case SC_NET_ADDR_V6
: return (SCF_TYPE_NET_ADDR_V6
);
329 case SC_OPAQUE
: return (SCF_TYPE_OPAQUE
);
330 case SC_TIME
: return (SCF_TYPE_TIME
);
331 case SC_URI
: return (SCF_TYPE_URI
);
332 case SC_USTRING
: return (SCF_TYPE_USTRING
);
335 uu_die(gettext("unknown value type (%d)\n"), type
);
342 lxml_type_to_element(scf_type_t type
)
345 case SCF_TYPE_ASTRING
: return (SC_ASTRING
);
346 case SCF_TYPE_BOOLEAN
: return (SC_BOOLEAN
);
347 case SCF_TYPE_COUNT
: return (SC_COUNT
);
348 case SCF_TYPE_FMRI
: return (SC_FMRI
);
349 case SCF_TYPE_HOST
: return (SC_HOST
);
350 case SCF_TYPE_HOSTNAME
: return (SC_HOSTNAME
);
351 case SCF_TYPE_INTEGER
: return (SC_INTEGER
);
352 case SCF_TYPE_NET_ADDR
: return (SC_NET_ADDR
);
353 case SCF_TYPE_NET_ADDR_V4
: return (SC_NET_ADDR_V4
);
354 case SCF_TYPE_NET_ADDR_V6
: return (SC_NET_ADDR_V6
);
355 case SCF_TYPE_OPAQUE
: return (SC_OPAQUE
);
356 case SCF_TYPE_TIME
: return (SC_TIME
);
357 case SCF_TYPE_URI
: return (SC_URI
);
358 case SCF_TYPE_USTRING
: return (SC_USTRING
);
361 uu_die(gettext("unknown value type (%d)\n"), type
);
368 * Create a SCF_TYPE_BOOLEAN property name pname and attach it to the
369 * property group at pgrp. The value of the property will be set from the
370 * attribute named attr. attr must have a value of 0, 1, true or false.
372 * Zero is returned on success. An error is indicated by -1. It indicates
373 * that either the attribute had an invalid value or that we could not
374 * attach the property to pgrp. The attribute should not have an invalid
375 * value if the DTD is correctly written.
378 new_bool_prop_from_attr(pgroup_t
*pgrp
, const char *pname
, xmlNodePtr n
,
386 val
= xmlGetProp(n
, (xmlChar
*)attr
);
390 if ((xmlStrcmp(val
, (xmlChar
*)"0") == 0) ||
391 (xmlStrcmp(val
, (xmlChar
*)"false") == 0)) {
393 } else if ((xmlStrcmp(val
, (xmlChar
*)"1") == 0) ||
394 (xmlStrcmp(val
, (xmlChar
*)"true") == 0)) {
401 p
= internal_property_create(pname
, SCF_TYPE_BOOLEAN
, 1, bool);
402 r
= internal_attach_property(pgrp
, p
);
405 internal_property_free(p
);
411 new_str_prop_from_attr(pgroup_t
*pgrp
, const char *pname
, scf_type_t ty
,
412 xmlNodePtr n
, const char *attr
)
418 val
= xmlGetProp(n
, (xmlChar
*)attr
);
420 p
= internal_property_create(pname
, ty
, 1, val
);
421 r
= internal_attach_property(pgrp
, p
);
424 internal_property_free(p
);
430 new_opt_str_prop_from_attr(pgroup_t
*pgrp
, const char *pname
, scf_type_t ty
,
431 xmlNodePtr n
, const char *attr
, const char *dflt
)
437 val
= xmlGetProp(n
, (xmlChar
*)attr
);
441 * A missing attribute is considered to be a
442 * success in this function, because many of the
443 * attributes are optional. Missing non-optional
444 * attributes will be detected later when template
445 * validation is done.
449 val
= (xmlChar
*)dflt
;
453 p
= internal_property_create(pname
, ty
, 1, val
);
454 r
= internal_attach_property(pgrp
, p
);
457 internal_property_free(p
);
463 lxml_ignorable_block(xmlNodePtr n
)
465 return ((xmlStrcmp(n
->name
, (xmlChar
*)"text") == 0 ||
466 xmlStrcmp(n
->name
, (xmlChar
*)"comment") == 0) ? 1 : 0);
470 lxml_validate_element(xmlNodePtr n
)
475 uu_die(gettext("Could not validate element\n"));
477 if (n
->doc
->extSubset
== NULL
) {
479 dtd
= xmlParseDTD(NULL
, n
->doc
->intSubset
->SystemID
);
482 uu_die(gettext("Could not parse DTD \"%s\".\n"),
483 n
->doc
->intSubset
->SystemID
);
486 n
->doc
->extSubset
= dtd
;
489 vcp
= xmlNewValidCtxt();
491 uu_die(gettext("could not allocate memory"));
493 vcp
->warning
= xmlParserValidityWarning
;
494 vcp
->error
= xmlParserValidityError
;
496 if (xmlValidateElement(vcp
, n
->doc
, n
) == 0)
497 uu_die(gettext("Document is not valid.\n"));
499 xmlFreeValidCtxt(vcp
);
503 lxml_validate_string_value(scf_type_t type
, const char *v
)
505 static scf_value_t
*scf_value
= NULL
;
506 static scf_handle_t
*scf_hndl
= NULL
;
508 if (scf_hndl
== NULL
&& (scf_hndl
= scf_handle_create(SCF_VERSION
)) ==
512 if (scf_value
== NULL
&& (scf_value
= scf_value_create(scf_hndl
)) ==
516 return (scf_value_set_from_string(scf_value
, type
, v
));
520 lxml_free_str(value_t
*val
)
522 free(val
->sc_u
.sc_string
);
526 * Take a value_t structure and a type and value. Based on the type
527 * ensure that the value is of that type. If so store the value in
528 * the correct location of the value_t structure.
530 * If the value is NULL, the value_t structure will have been created
531 * and the value would have ultimately been stored as a string value
532 * but at the time the type was unknown. Now the type should be known
533 * so take the type and value from value_t and validate and store
534 * the value correctly if the value is of the stated type.
537 lxml_store_value(value_t
*v
, element_t type
, const xmlChar
*value
)
541 scf_type_t scf_type
= SCF_TYPE_INVALID
;
544 type
= lxml_type_to_element(v
->sc_type
);
545 value
= (const xmlChar
*)v
->sc_u
.sc_string
;
552 * Although an SC_COUNT represents a uint64_t the use
553 * of a negative value is acceptable due to the usage
554 * established by inetd(1M).
557 v
->sc_u
.sc_count
= strtoull((char *)value
, &endptr
, 10);
558 if (errno
!= 0 || endptr
== (char *)value
|| *endptr
)
559 uu_die(gettext("illegal value \"%s\" for "
560 "%s (%s)\n"), (char *)value
,
561 lxml_prop_types
[type
],
562 (errno
) ? strerror(errno
) :
563 gettext("Illegal character"));
567 v
->sc_u
.sc_integer
= strtoll((char *)value
, &endptr
, 10);
568 if (errno
!= 0 || *endptr
)
569 uu_die(gettext("illegal value \"%s\" for "
570 "%s (%s)\n"), (char *)value
,
571 lxml_prop_types
[type
],
572 (errno
) ? strerror(errno
) : "Illegal character");
585 scf_type
= lxml_element_to_type(type
);
587 v
->sc_u
.sc_string
= safe_strdup((const char *)value
);
588 if (lxml_validate_string_value(scf_type
,
589 v
->sc_u
.sc_string
) != 0)
590 uu_die(gettext("illegal value \"%s\" for "
591 "%s (%s)\n"), (char *)value
,
592 lxml_prop_types
[type
],
593 (scf_error()) ? scf_strerror(scf_error()) :
594 gettext("Illegal format"));
595 v
->sc_free
= lxml_free_str
;
598 v
->sc_u
.sc_count
= lxml_xlate_boolean(value
);
601 uu_die(gettext("unknown value type (%d)\n"), type
);
605 /* Free the old value */
606 if (fov
&& v
->sc_free
!= NULL
)
611 lxml_make_value(element_t type
, const xmlChar
*value
)
615 v
= internal_value_new();
617 v
->sc_type
= lxml_element_to_type(type
);
619 lxml_store_value(v
, type
, value
);
625 lxml_get_value(property_t
*prop
, element_t vtype
, xmlNodePtr value
)
629 for (cursor
= value
->xmlChildrenNode
; cursor
!= NULL
;
630 cursor
= cursor
->next
) {
631 xmlChar
*assigned_value
;
634 if (lxml_ignorable_block(cursor
))
637 switch (lxml_xlate_element(cursor
->name
)) {
639 if ((assigned_value
= xmlGetProp(cursor
,
640 (xmlChar
*)value_attr
)) == NULL
)
641 uu_die(gettext("no value on value node?\n"));
644 uu_die(gettext("value list contains illegal element "
645 "\'%s\'\n"), cursor
->name
);
649 v
= lxml_make_value(vtype
, assigned_value
);
651 xmlFree(assigned_value
);
653 internal_attach_value(prop
, v
);
660 lxml_get_propval(pgroup_t
*pgrp
, xmlNodePtr propval
)
665 xmlChar
*type
, *val
, *override
;
666 int op
= pgrp
->sc_parent
->sc_op
;
668 p
= internal_property_new();
670 p
->sc_property_name
= (char *)xmlGetProp(propval
, (xmlChar
*)name_attr
);
671 if ((p
->sc_property_name
== NULL
) || (*p
->sc_property_name
== 0))
672 uu_die(gettext("property name missing in group '%s'\n"),
673 pgrp
->sc_pgroup_name
);
675 type
= xmlGetProp(propval
, (xmlChar
*)type_attr
);
676 if ((type
!= NULL
) && (*type
!= 0)) {
678 r
< sizeof (lxml_prop_types
) / sizeof (char *); ++r
) {
680 (const xmlChar
*)lxml_prop_types
[r
]) == 0)
684 if (r
>= sizeof (lxml_prop_types
) / sizeof (char *))
685 uu_die(gettext("property type invalid for "
686 "property '%s/%s'\n"), pgrp
->sc_pgroup_name
,
687 p
->sc_property_name
);
689 p
->sc_value_type
= lxml_element_to_type(r
);
690 } else if (op
== SVCCFG_OP_APPLY
) {
692 * Store the property type as invalid, and the value
693 * as an ASTRING and let the bundle apply code validate
694 * the type/value once the type is found.
696 est
->sc_miss_type
= B_TRUE
;
697 p
->sc_value_type
= SCF_TYPE_INVALID
;
700 uu_die(gettext("property type missing for property '%s/%s'\n"),
701 pgrp
->sc_pgroup_name
, p
->sc_property_name
);
704 val
= xmlGetProp(propval
, (xmlChar
*)value_attr
);
706 uu_die(gettext("property value missing for property '%s/%s'\n"),
707 pgrp
->sc_pgroup_name
, p
->sc_property_name
);
709 v
= lxml_make_value(r
, val
);
711 internal_attach_value(p
, v
);
715 override
= xmlGetProp(propval
, (xmlChar
*)override_attr
);
716 p
->sc_property_override
= (xmlStrcmp(override
, (xmlChar
*)true) == 0);
719 return (internal_attach_property(pgrp
, p
));
723 lxml_get_property(pgroup_t
*pgrp
, xmlNodePtr property
)
728 xmlChar
*type
, *override
;
729 int op
= pgrp
->sc_parent
->sc_op
;
731 p
= internal_property_new();
733 if (((p
->sc_property_name
= (char *)xmlGetProp(property
,
734 (xmlChar
*)name_attr
)) == NULL
) || (*p
->sc_property_name
== 0))
735 uu_die(gettext("property name missing in group \'%s\'\n"),
736 pgrp
->sc_pgroup_name
);
738 type
= xmlGetProp(property
, (xmlChar
*)type_attr
);
739 if ((type
!= NULL
) && (*type
!= 0)) {
741 r
< sizeof (lxml_prop_types
) / sizeof (char *); r
++) {
743 (const xmlChar
*)lxml_prop_types
[r
]) == 0)
747 if (r
>= sizeof (lxml_prop_types
) / sizeof (char *))
748 uu_die(gettext("property type invalid for "
749 "property '%s/%s'\n"), pgrp
->sc_pgroup_name
,
750 p
->sc_property_name
);
752 p
->sc_value_type
= lxml_element_to_type(r
);
753 } else if (op
== SVCCFG_OP_APPLY
) {
755 * Store the property type as invalid, and let the bundle apply
756 * code validate the type/value once the type is found.
758 p
->sc_value_type
= SCF_TYPE_INVALID
;
759 est
->sc_miss_type
= B_TRUE
;
761 uu_die(gettext("property type missing for "
762 "property \'%s/%s\'\n"), pgrp
->sc_pgroup_name
,
763 p
->sc_property_name
);
766 for (cursor
= property
->xmlChildrenNode
; cursor
!= NULL
;
767 cursor
= cursor
->next
) {
768 if (lxml_ignorable_block(cursor
))
771 switch (r
= lxml_xlate_element(cursor
->name
)) {
787 * If the type is invalid then this is an apply
788 * operation and the type can be taken from the
791 if (p
->sc_value_type
== SCF_TYPE_INVALID
) {
792 p
->sc_value_type
= lxml_element_to_type(r
);
793 type
= xmlStrdup((const
794 xmlChar
*)lxml_prop_types
[r
]);
796 } else if (strcmp(lxml_prop_types
[r
],
797 (const char *)type
) != 0) {
798 uu_die(gettext("property \'%s\' "
799 "type-to-list mismatch\n"),
800 p
->sc_property_name
);
803 (void) lxml_get_value(p
, r
, cursor
);
806 uu_die(gettext("unknown value list type: %s\n"),
814 override
= xmlGetProp(property
, (xmlChar
*)override_attr
);
815 p
->sc_property_override
= (xmlStrcmp(override
, (xmlChar
*)true) == 0);
818 return (internal_attach_property(pgrp
, p
));
822 lxml_get_pgroup_stability(pgroup_t
*pgrp
, xmlNodePtr stab
)
824 if (pgrp
->sc_parent
->sc_op
== SVCCFG_OP_APPLY
)
825 lxml_validate_element(stab
);
827 return (new_str_prop_from_attr(pgrp
, SCF_PROPERTY_STABILITY
,
828 SCF_TYPE_ASTRING
, stab
, value_attr
));
832 * Property groups can go on any of a service, an instance, or a template.
835 lxml_get_pgroup(entity_t
*entity
, xmlNodePtr pgroup
)
839 xmlChar
*name
, *type
, *delete;
842 * property group attributes:
844 * type: string | framework | application
846 name
= xmlGetProp(pgroup
, (xmlChar
*)name_attr
);
847 type
= xmlGetProp(pgroup
, (xmlChar
*)type_attr
);
848 pg
= internal_pgroup_find_or_create(entity
, (char *)name
, (char *)type
);
853 * Walk the children of this lxml_elements, which are a stability
854 * element, property elements, or propval elements.
856 for (cursor
= pgroup
->xmlChildrenNode
; cursor
!= NULL
;
857 cursor
= cursor
->next
) {
858 if (lxml_ignorable_block(cursor
))
861 switch (lxml_xlate_element(cursor
->name
)) {
863 (void) lxml_get_pgroup_stability(pg
, cursor
);
866 (void) lxml_get_property(pg
, cursor
);
869 (void) lxml_get_propval(pg
, cursor
);
877 delete = xmlGetProp(pgroup
, (xmlChar
*)delete_attr
);
878 pg
->sc_pgroup_delete
= (xmlStrcmp(delete, (xmlChar
*)true) == 0);
886 * Dependency groups, execution methods can go on either a service or an
891 lxml_get_method_profile(pgroup_t
*pg
, xmlNodePtr profile
)
895 p
= internal_property_create(SCF_PROPERTY_USE_PROFILE
, SCF_TYPE_BOOLEAN
,
897 if (internal_attach_property(pg
, p
) != 0)
900 return (new_str_prop_from_attr(pg
, SCF_PROPERTY_PROFILE
,
901 SCF_TYPE_ASTRING
, profile
, name_attr
));
905 lxml_get_method_credential(pgroup_t
*pg
, xmlNodePtr cred
)
909 p
= internal_property_create(SCF_PROPERTY_USE_PROFILE
, SCF_TYPE_BOOLEAN
,
911 if (internal_attach_property(pg
, p
) != 0)
914 if (new_opt_str_prop_from_attr(pg
, SCF_PROPERTY_USER
, SCF_TYPE_ASTRING
,
915 cred
, "user", NULL
) != 0)
918 if (new_opt_str_prop_from_attr(pg
, SCF_PROPERTY_GROUP
, SCF_TYPE_ASTRING
,
919 cred
, "group", NULL
) != 0)
922 if (new_opt_str_prop_from_attr(pg
, SCF_PROPERTY_SUPP_GROUPS
,
923 SCF_TYPE_ASTRING
, cred
, "supp_groups", NULL
) != 0)
926 if (new_opt_str_prop_from_attr(pg
, SCF_PROPERTY_PRIVILEGES
,
927 SCF_TYPE_ASTRING
, cred
, "privileges", NULL
) != 0)
930 if (new_opt_str_prop_from_attr(pg
, SCF_PROPERTY_LIMIT_PRIVILEGES
,
931 SCF_TYPE_ASTRING
, cred
, "limit_privileges", NULL
) != 0)
938 lxml_get_envvar(xmlNodePtr envvar
)
944 name
= (char *)xmlGetProp(envvar
, (xmlChar
*)name_attr
);
945 value
= (char *)xmlGetProp(envvar
, (xmlChar
*)value_attr
);
947 if (strlen(name
) == 0 || strchr(name
, '=') != NULL
)
948 uu_die(gettext("Invalid environment variable "
950 if (strstr(name
, "SMF_") == name
)
951 uu_die(gettext("Invalid environment variable "
952 "\"%s\"; \"SMF_\" prefix is reserved.\n"), name
);
954 ret
= uu_msprintf("%s=%s", name
, value
);
961 lxml_get_method_environment(pgroup_t
*pg
, xmlNodePtr environment
)
967 p
= internal_property_create(SCF_PROPERTY_ENVIRONMENT
,
968 SCF_TYPE_ASTRING
, 0);
970 for (cursor
= environment
->xmlChildrenNode
; cursor
!= NULL
;
971 cursor
= cursor
->next
) {
974 if (lxml_ignorable_block(cursor
))
977 if (lxml_xlate_element(cursor
->name
) != SC_METHOD_ENVVAR
)
978 uu_die(gettext("illegal element \"%s\" on "
979 "method environment for \"%s\"\n"),
980 cursor
->name
, pg
->sc_pgroup_name
);
982 if ((tmp
= lxml_get_envvar(cursor
)) == NULL
)
983 uu_die(gettext("Out of memory\n"));
985 val
= internal_value_new();
986 val
->sc_u
.sc_string
= tmp
;
987 val
->sc_type
= SCF_TYPE_ASTRING
;
988 val
->sc_free
= lxml_free_str
;
989 internal_attach_value(p
, val
);
992 if (internal_attach_property(pg
, p
) != 0) {
993 internal_property_free(p
);
1001 lxml_get_method_context(pgroup_t
*pg
, xmlNodePtr ctx
)
1005 if (new_opt_str_prop_from_attr(pg
, SCF_PROPERTY_WORKING_DIRECTORY
,
1006 SCF_TYPE_ASTRING
, ctx
, "working_directory", NULL
) != 0)
1009 if (new_opt_str_prop_from_attr(pg
, SCF_PROPERTY_PROJECT
,
1010 SCF_TYPE_ASTRING
, ctx
, "project", NULL
) != 0)
1013 if (new_opt_str_prop_from_attr(pg
, SCF_PROPERTY_RESOURCE_POOL
,
1014 SCF_TYPE_ASTRING
, ctx
, "resource_pool", NULL
) != 0)
1017 if (new_opt_str_prop_from_attr(pg
, SCF_PROPERTY_SECFLAGS
,
1018 SCF_TYPE_ASTRING
, ctx
, "security_flags", NULL
) != 0)
1021 for (cursor
= ctx
->xmlChildrenNode
; cursor
!= NULL
;
1022 cursor
= cursor
->next
) {
1023 if (lxml_ignorable_block(cursor
))
1026 switch (lxml_xlate_element(cursor
->name
)) {
1027 case SC_METHOD_CREDENTIAL
:
1028 (void) lxml_get_method_credential(pg
, cursor
);
1030 case SC_METHOD_PROFILE
:
1031 (void) lxml_get_method_profile(pg
, cursor
);
1033 case SC_METHOD_ENVIRONMENT
:
1034 (void) lxml_get_method_environment(pg
, cursor
);
1037 semerr(gettext("illegal element \'%s\' in method "
1038 "context\n"), (char *)cursor
);
1047 lxml_get_entity_method_context(entity_t
*entity
, xmlNodePtr ctx
)
1051 pg
= internal_pgroup_find_or_create(entity
, SCF_PG_METHOD_CONTEXT
,
1052 (char *)scf_group_framework
);
1054 return (lxml_get_method_context(pg
, ctx
));
1058 lxml_get_exec_method(entity_t
*entity
, xmlNodePtr emeth
)
1062 xmlChar
*name
, *timeout
, *delete;
1066 if (entity
->sc_op
== SVCCFG_OP_APPLY
)
1067 lxml_validate_element(emeth
);
1069 name
= xmlGetProp(emeth
, (xmlChar
*)name_attr
);
1070 pg
= internal_pgroup_find_or_create(entity
, (char *)name
,
1071 (char *)SCF_GROUP_METHOD
);
1074 if (new_str_prop_from_attr(pg
, SCF_PROPERTY_TYPE
, SCF_TYPE_ASTRING
,
1075 emeth
, type_attr
) != 0 ||
1076 new_str_prop_from_attr(pg
, SCF_PROPERTY_EXEC
, SCF_TYPE_ASTRING
,
1077 emeth
, "exec") != 0)
1080 timeout
= xmlGetProp(emeth
, (xmlChar
*)timeout_seconds_attr
);
1081 if (timeout
!= NULL
) {
1085 * Although an SC_COUNT represents a uint64_t the use
1086 * of a negative value is acceptable due to the usage
1087 * established by inetd(1M).
1090 u_timeout
= strtoull((char *)timeout
, &endptr
, 10);
1091 if (errno
!= 0 || endptr
== (char *)timeout
|| *endptr
)
1092 uu_die(gettext("illegal value \"%s\" for "
1093 "timeout_seconds (%s)\n"),
1094 (char *)timeout
, (errno
) ? strerror(errno
):
1095 gettext("Illegal character"));
1096 p
= internal_property_create(SCF_PROPERTY_TIMEOUT
,
1097 SCF_TYPE_COUNT
, 1, u_timeout
);
1098 r
= internal_attach_property(pg
, p
);
1105 * There is a possibility that a method context also exists, in which
1106 * case the following attributes are defined: project, resource_pool,
1107 * working_directory, profile, user, group, privileges,
1108 * limit_privileges, security_flags
1110 for (cursor
= emeth
->xmlChildrenNode
; cursor
!= NULL
;
1111 cursor
= cursor
->next
) {
1112 if (lxml_ignorable_block(cursor
))
1115 switch (lxml_xlate_element(cursor
->name
)) {
1117 if (lxml_get_pgroup_stability(pg
, cursor
) != 0)
1121 case SC_METHOD_CONTEXT
:
1122 (void) lxml_get_method_context(pg
, cursor
);
1126 (void) lxml_get_propval(pg
, cursor
);
1130 (void) lxml_get_property(pg
, cursor
);
1134 uu_die(gettext("illegal element \"%s\" on "
1135 "execution method \"%s\"\n"), cursor
->name
,
1136 pg
->sc_pgroup_name
);
1141 delete = xmlGetProp(emeth
, (xmlChar
*)delete_attr
);
1142 pg
->sc_pgroup_delete
= (xmlStrcmp(delete, (xmlChar
*)true) == 0);
1149 lxml_get_dependency(entity_t
*entity
, xmlNodePtr dependency
)
1158 * dependency attributes:
1160 * grouping: require_all | require_any | exclude_all | optional_all
1161 * reset_on: string (error | restart | refresh | none)
1162 * type: service / path /host
1165 if (entity
->sc_op
== SVCCFG_OP_APPLY
)
1166 lxml_validate_element(dependency
);
1168 name
= xmlGetProp(dependency
, (xmlChar
*)name_attr
);
1169 pg
= internal_pgroup_find_or_create(entity
, (char *)name
,
1170 (char *)SCF_GROUP_DEPENDENCY
);
1173 if (new_str_prop_from_attr(pg
, SCF_PROPERTY_TYPE
, SCF_TYPE_ASTRING
,
1174 dependency
, type_attr
) != 0)
1177 if (new_str_prop_from_attr(pg
, SCF_PROPERTY_RESTART_ON
,
1178 SCF_TYPE_ASTRING
, dependency
, "restart_on") != 0)
1181 if (new_str_prop_from_attr(pg
, SCF_PROPERTY_GROUPING
, SCF_TYPE_ASTRING
,
1182 dependency
, "grouping") != 0)
1185 p
= internal_property_create(SCF_PROPERTY_ENTITIES
, SCF_TYPE_FMRI
, 0);
1186 if (internal_attach_property(pg
, p
) != 0)
1189 for (cursor
= dependency
->xmlChildrenNode
; cursor
!= NULL
;
1190 cursor
= cursor
->next
) {
1194 if (lxml_ignorable_block(cursor
))
1197 switch (lxml_xlate_element(cursor
->name
)) {
1199 if (lxml_get_pgroup_stability(pg
, cursor
) != 0)
1203 case SC_SERVICE_FMRI
:
1204 value
= xmlGetProp(cursor
, (xmlChar
*)value_attr
);
1205 if (value
!= NULL
) {
1206 if (lxml_validate_string_value(SCF_TYPE_FMRI
,
1207 (char *)value
) != 0)
1208 uu_die(gettext("illegal value \"%s\" "
1209 "for %s (%s)\n"), (char *)value
,
1210 lxml_prop_types
[SC_FMRI
],
1212 scf_strerror(scf_error()) :
1213 gettext("Illegal format"));
1214 v
= internal_value_new();
1215 v
->sc_type
= SCF_TYPE_FMRI
;
1216 v
->sc_u
.sc_string
= (char *)value
;
1217 internal_attach_value(p
, v
);
1223 (void) lxml_get_propval(pg
, cursor
);
1227 (void) lxml_get_property(pg
, cursor
);
1231 uu_die(gettext("illegal element \"%s\" on "
1232 "dependency group \"%s\"\n"), cursor
->name
, name
);
1237 delete = xmlGetProp(dependency
, (xmlChar
*)delete_attr
);
1238 pg
->sc_pgroup_delete
= (xmlStrcmp(delete, (xmlChar
*)true) == 0);
1245 * Dependents are hairy. They should cause a dependency pg to be created in
1246 * another service, but we can't do that here; we'll have to wait until the
1247 * import routines. So for now we'll add the dependency group that should go
1248 * in the other service to the entity's dependent list.
1251 lxml_get_dependent(entity_t
*entity
, xmlNodePtr dependent
)
1255 xmlChar
*fmri
, *delete;
1261 if (entity
->sc_op
== SVCCFG_OP_APPLY
)
1262 lxml_validate_element(dependent
);
1264 name
= xmlGetProp(dependent
, (xmlChar
*)name_attr
);
1266 if (internal_pgroup_find(entity
, (char *)name
, NULL
) != NULL
) {
1267 semerr(gettext("Property group and dependent of entity %s "
1268 "have same name \"%s\".\n"), entity
->sc_name
, name
);
1273 or = xmlGetProp(dependent
, (xmlChar
*)override_attr
);
1275 pg
= internal_pgroup_new();
1276 pg
->sc_pgroup_name
= (char *)name
;
1277 pg
->sc_pgroup_type
= (char *)SCF_GROUP_DEPENDENCY
;
1278 pg
->sc_pgroup_override
= (xmlStrcmp(or, (xmlChar
*)true) == 0);
1280 if (internal_attach_dependent(entity
, pg
) != 0) {
1282 internal_pgroup_free(pg
);
1286 for (sf
= dependent
->children
; sf
!= NULL
; sf
= sf
->next
)
1287 if (xmlStrcmp(sf
->name
, (xmlChar
*)"service_fmri") == 0)
1290 fmri
= xmlGetProp(sf
, (xmlChar
*)value_attr
);
1291 pg
->sc_pgroup_fmri
= (char *)fmri
;
1293 if (new_str_prop_from_attr(pg
, SCF_PROPERTY_RESTART_ON
,
1294 SCF_TYPE_ASTRING
, dependent
, "restart_on") != 0)
1297 if (new_str_prop_from_attr(pg
, SCF_PROPERTY_GROUPING
, SCF_TYPE_ASTRING
,
1298 dependent
, "grouping") != 0)
1301 myfmri
= safe_malloc(max_scf_fmri_len
+ 1);
1302 if (entity
->sc_etype
== SVCCFG_SERVICE_OBJECT
) {
1303 if (snprintf(myfmri
, max_scf_fmri_len
+ 1, "svc:/%s",
1304 entity
->sc_name
) < 0)
1305 bad_error("snprintf", errno
);
1307 assert(entity
->sc_etype
== SVCCFG_INSTANCE_OBJECT
);
1308 if (snprintf(myfmri
, max_scf_fmri_len
+ 1, "svc:/%s:%s",
1309 entity
->sc_parent
->sc_name
, entity
->sc_name
) < 0)
1310 bad_error("snprintf", errno
);
1313 p
= internal_property_create(SCF_PROPERTY_ENTITIES
, SCF_TYPE_FMRI
, 1,
1315 if (internal_attach_property(pg
, p
) != 0)
1318 /* Create a property to serve as a do-not-export flag. */
1319 p
= internal_property_create("external", SCF_TYPE_BOOLEAN
, 1,
1321 if (internal_attach_property(pg
, p
) != 0)
1324 for (n
= sf
->next
; n
!= NULL
; n
= n
->next
) {
1325 if (lxml_ignorable_block(n
))
1328 switch (lxml_xlate_element(n
->name
)) {
1330 if (new_str_prop_from_attr(pg
,
1331 SCF_PROPERTY_ENTITY_STABILITY
, SCF_TYPE_ASTRING
, n
,
1337 (void) lxml_get_propval(pg
, n
);
1341 (void) lxml_get_property(pg
, n
);
1345 uu_die(gettext("unexpected element %s.\n"), n
->name
);
1349 /* Go back and fill in defaults. */
1350 if (internal_property_find(pg
, SCF_PROPERTY_TYPE
) == NULL
) {
1351 p
= internal_property_create(SCF_PROPERTY_TYPE
,
1352 SCF_TYPE_ASTRING
, 1, "service");
1353 if (internal_attach_property(pg
, p
) != 0)
1357 delete = xmlGetProp(dependent
, (xmlChar
*)delete_attr
);
1358 pg
->sc_pgroup_delete
= (xmlStrcmp(delete, (xmlChar
*)true) == 0);
1361 pg
= internal_pgroup_find_or_create(entity
, "dependents",
1362 (char *)scf_group_framework
);
1363 p
= internal_property_create((char *)name
, SCF_TYPE_FMRI
, 1, fmri
);
1364 if (internal_attach_property(pg
, p
) != 0)
1371 lxml_get_entity_stability(entity_t
*entity
, xmlNodePtr rstr
)
1377 if (((stabval
= xmlGetProp(rstr
, (xmlChar
*)value_attr
)) == NULL
) ||
1379 uu_warn(gettext("no stability value found\n"));
1380 stabval
= (xmlChar
*)safe_strdup("External");
1383 pg
= internal_pgroup_find_or_create(entity
, (char *)scf_pg_general
,
1384 (char *)scf_group_framework
);
1386 p
= internal_property_create(SCF_PROPERTY_ENTITY_STABILITY
,
1387 SCF_TYPE_ASTRING
, 1, stabval
);
1389 return (internal_attach_property(pg
, p
));
1393 lxml_get_restarter(entity_t
*entity
, xmlNodePtr rstr
)
1402 * Go find child. Child is a service_fmri element. value attribute
1403 * contains restarter FMRI.
1406 pg
= internal_pgroup_find_or_create(entity
, (char *)scf_pg_general
,
1407 (char *)scf_group_framework
);
1410 * Walk its child elements, as appropriate.
1412 for (cursor
= rstr
->xmlChildrenNode
; cursor
!= NULL
;
1413 cursor
= cursor
->next
) {
1414 if (lxml_ignorable_block(cursor
))
1417 switch (lxml_xlate_element(cursor
->name
)) {
1418 case SC_SERVICE_FMRI
:
1419 restarter
= xmlGetProp(cursor
, (xmlChar
*)value_attr
);
1422 uu_die(gettext("illegal element \"%s\" on restarter "
1423 "element for \"%s\"\n"), cursor
->name
,
1429 p
= internal_property_create(SCF_PROPERTY_RESTARTER
, SCF_TYPE_FMRI
, 1,
1432 r
= internal_attach_property(pg
, p
);
1434 internal_property_free(p
);
1442 lxml_get_paramval(pgroup_t
*pgrp
, const char *propname
, xmlNodePtr pval
)
1448 prop
= safe_strdup(propname
);
1450 value
= (char *)xmlGetProp(pval
, (xmlChar
*)value_attr
);
1451 if (value
== NULL
|| *value
== '\0')
1452 uu_die(gettext("property value missing for property '%s/%s'\n"),
1453 pgrp
->sc_pgroup_name
, propname
);
1454 p
= internal_property_create(prop
, SCF_TYPE_ASTRING
, 1, value
);
1456 (void) internal_attach_property(pgrp
, p
);
1460 lxml_get_parameter(pgroup_t
*pgrp
, const char *propname
, xmlNodePtr param
)
1462 property_t
*p
= internal_property_new();
1464 p
->sc_property_name
= safe_strdup(propname
);
1465 p
->sc_value_type
= SCF_TYPE_ASTRING
;
1467 (void) lxml_get_value(p
, SC_ASTRING
, param
);
1469 (void) internal_attach_property(pgrp
, p
);
1473 lxml_get_type(pgroup_t
*pgrp
, xmlNodePtr type
)
1479 uint64_t active_val
;
1480 size_t sz
= max_scf_name_len
+ 1;
1481 char *propname
= safe_malloc(sz
);
1483 if (pgrp
->sc_parent
->sc_op
== SVCCFG_OP_APPLY
)
1484 lxml_validate_element(type
);
1486 name
= xmlGetProp(type
, (xmlChar
*)name_attr
);
1487 if (name
== NULL
|| *name
== '\0')
1488 uu_die(gettext("attribute name missing in element 'type'\n"));
1490 for (cursor
= type
->xmlChildrenNode
; cursor
!= NULL
;
1491 cursor
= cursor
->next
) {
1494 if (lxml_ignorable_block(cursor
))
1497 pname
= xmlGetProp(cursor
, (xmlChar
*)name_attr
);
1498 if (pname
== NULL
|| *pname
== '\0')
1500 "attribute name missing in sub-element of type\n"));
1502 if (snprintf(propname
, sz
, "%s,%s", (char *)name
,
1503 (char *)pname
) >= sz
)
1504 uu_die(gettext("name '%s,%s' is too long\n"),
1505 (char *)name
, (char *)pname
);
1508 switch (lxml_xlate_element(cursor
->name
)) {
1510 lxml_get_parameter(pgrp
, propname
, cursor
);
1514 lxml_get_paramval(pgrp
, propname
, cursor
);
1518 uu_die(gettext("unknown element %s\n"), cursor
->name
);
1522 active
= xmlGetProp(type
, (xmlChar
*)active_attr
);
1523 if (active
== NULL
|| strcmp(true, (const char *)active
) == 0)
1529 if (snprintf(propname
, sz
, "%s,%s", (char *)name
,
1530 SCF_PROPERTY_ACTIVE_POSTFIX
) >= sz
)
1531 uu_die(gettext("name '%s,%s' is too long\n"),
1532 (char *)name
, SCF_PROPERTY_ACTIVE_POSTFIX
);
1534 p
= internal_property_create(propname
, SCF_TYPE_BOOLEAN
, 1, active_val
);
1536 (void) internal_attach_property(pgrp
, p
);
1542 lxml_get_event(entity_t
*entity
, const char *pgname
, xmlNodePtr np
)
1547 pgrp
= internal_pgroup_find_or_create(entity
, pgname
,
1548 SCF_NOTIFY_PARAMS_PG_TYPE
);
1549 for (cursor
= np
->xmlChildrenNode
; cursor
!= NULL
;
1550 cursor
= cursor
->next
) {
1551 if (lxml_ignorable_block(cursor
))
1554 switch (lxml_xlate_element(cursor
->name
)) {
1559 lxml_get_type(pgrp
, cursor
);
1563 uu_warn(gettext("illegal element '%s' on "
1564 "notification parameters\n"), cursor
->name
);
1570 lxml_get_notification_parameters(entity_t
*entity
, xmlNodePtr np
)
1575 char *pgname
= NULL
;
1578 size_t sz
= max_scf_name_len
+ 1;
1582 for (count
= 0, cursor
= np
->xmlChildrenNode
; cursor
!= NULL
;
1583 cursor
= cursor
->next
) {
1584 if (lxml_ignorable_block(cursor
))
1587 if (lxml_xlate_element(cursor
->name
) == SC_EVENT
) {
1592 uu_die(gettext("Can't have more than 1 element "
1593 "event in a notification parameter\n"));
1594 s
= xmlGetProp(cursor
, (xmlChar
*)value_attr
);
1595 if (s
== NULL
|| (event
= strdup((char *)s
)) == NULL
)
1596 uu_die(gettext("couldn't allocate memory"));
1601 pgs
= tokenize(event
, ",");
1603 switch (tset
= check_tokens(pgs
)) {
1604 case INVALID_TOKENS
:
1605 uu_die(gettext("Invalid input.\n"));
1608 semerr(gettext("Can't mix SMF and FMA event definitions\n"));
1611 /* make sure this is SCF_NOTIFY_PARAMS_INST */
1612 if (entity
->sc_etype
!= SVCCFG_INSTANCE_OBJECT
||
1613 strcmp(entity
->sc_fmri
, SCF_NOTIFY_PARAMS_INST
) != 0) {
1615 "Non-SMF transition evenst must go to %s\n"),
1616 SCF_NOTIFY_PARAMS_INST
);
1619 pgname
= safe_malloc(sz
);
1620 for (p
= pgs
; *p
; ++p
) {
1621 if (snprintf(pgname
, sz
, "%s,%s", de_tag(*p
),
1622 SCF_NOTIFY_PG_POSTFIX
) >= sz
)
1623 uu_die(gettext("event name too long: %s\n"),
1626 lxml_get_event(entity
, pgname
, np
);
1629 default: /* smf state transition tokens */
1630 if (entity
->sc_etype
== SVCCFG_SERVICE_OBJECT
&&
1631 strcmp(entity
->sc_fmri
, SCF_SERVICE_GLOBAL
) == 0) {
1633 "Can't set events for global service\n"));
1636 for (t
= 0x1; t
< SCF_STATE_ALL
; t
<<= 1) {
1638 lxml_get_event(entity
, tset_to_string(t
), np
);
1640 if ((t
<< 16) & tset
) {
1641 lxml_get_event(entity
, tset_to_string(t
<< 16),
1657 * Add a property containing the localized text from the manifest. The
1658 * property is added to the property group at pg. The name of the created
1659 * property is based on the format at pn_format. This is an snprintf(3C)
1660 * format containing a single %s conversion specification. At conversion
1661 * time, the %s is replaced by the locale designation.
1663 * source is the source element and it is only used for error messages.
1666 lxml_get_loctext(entity_t
*service
, pgroup_t
*pg
, xmlNodePtr loctext
,
1667 const char *pn_format
, const char *source
)
1672 char *stripped
, *cp
;
1677 if (((val
= xmlGetProp(loctext
, (xmlChar
*)xml_lang_attr
)) == NULL
) ||
1679 if (((val
= xmlGetProp(loctext
,
1680 (xmlChar
*)lang_attr
)) == NULL
) || (*val
== 0)) {
1681 val
= (xmlChar
*)"unknown";
1685 _scf_sanitize_locale((char *)val
);
1686 prop_name
= safe_malloc(max_scf_name_len
+ 1);
1687 if ((extra
= snprintf(prop_name
, max_scf_name_len
+ 1, pn_format
,
1688 val
)) >= max_scf_name_len
+ 1) {
1689 extra
-= max_scf_name_len
;
1690 uu_die(gettext("%s attribute is %d characters too long for "
1692 xml_lang_attr
, extra
, source
, service
->sc_name
);
1696 for (cursor
= loctext
->xmlChildrenNode
; cursor
!= NULL
;
1697 cursor
= cursor
->next
) {
1698 if (strcmp("text", (const char *)cursor
->name
) == 0) {
1700 } else if (strcmp("comment", (const char *)cursor
->name
) != 0) {
1701 uu_die(gettext("illegal element \"%s\" on loctext "
1702 "element for \"%s\"\n"), cursor
->name
,
1707 if (cursor
== NULL
) {
1708 uu_die(gettext("loctext element has no content for \"%s\"\n"),
1713 * Remove leading and trailing whitespace.
1715 stripped
= safe_strdup((const char *)cursor
->content
);
1717 for (; isspace(*stripped
); stripped
++)
1719 for (cp
= stripped
+ strlen(stripped
) - 1; isspace(*cp
); cp
--)
1723 p
= internal_property_create(prop_name
, SCF_TYPE_USTRING
, 1,
1726 r
= internal_attach_property(pg
, p
);
1728 internal_property_free(p
);
1736 * This function processes all loctext elements in the current XML element
1737 * designated by container. A property is created for each loctext element
1738 * and added to the property group at pg. The name of the property is
1739 * derived from the loctext language designation using the format at
1740 * pn_format. pn_format should be an snprintf format string containing one
1741 * %s which is replaced by the language designation.
1743 * The function returns 0 on success and -1 if it is unable to attach the
1744 * newly created property to pg.
1747 lxml_get_all_loctext(entity_t
*service
, pgroup_t
*pg
, xmlNodePtr container
,
1748 const char *pn_format
, const char *source
)
1753 * Iterate through one or more loctext elements. The locale is
1754 * used to generate the property name; the contents are the ustring
1755 * value for the property.
1757 for (cursor
= container
->xmlChildrenNode
; cursor
!= NULL
;
1758 cursor
= cursor
->next
) {
1759 if (lxml_ignorable_block(cursor
))
1762 switch (lxml_xlate_element(cursor
->name
)) {
1764 if (lxml_get_loctext(service
, pg
, cursor
, pn_format
,
1769 uu_die(gettext("illegal element \"%s\" on %s element "
1770 "for \"%s\"\n"), cursor
->name
, container
->name
,
1780 * Obtain the specified cardinality attribute and place it in a property
1781 * named prop_name. The converted attribute is placed at *value, and the
1782 * newly created property is returned to propp. NULL is returned to propp
1783 * if the attribute is not provided in the manifest.
1785 * 0 is returned upon success, and -1 indicates that the manifest contained
1786 * an invalid cardinality value.
1789 lxml_get_cardinality_attribute(entity_t
*service
, xmlNodePtr cursor
,
1790 const char *attr_name
, const char *prop_name
, uint64_t *value
,
1800 val
= xmlGetProp(cursor
, (xmlChar
*)attr_name
);
1809 * Make sure that the string at val doesn't have a leading minus
1810 * sign. The strtoull() call below does not catch this problem.
1812 for (c
= (char *)val
; *c
!= 0; c
++) {
1817 semerr(gettext("\"%c\" is not a legal character in the %s "
1818 "attribute of the %s element in %s.\n"), *c
,
1819 attr_name
, prop_name
, service
->sc_name
);
1824 count
= strtoull((char *)val
, &endptr
, 10);
1825 if (errno
!= 0 || endptr
== (char *)val
|| *endptr
) {
1826 semerr(gettext("\"%s\" is not a legal number for the %s "
1827 "attribute of the %s element in %s.\n"), (char *)val
,
1828 attr_name
, prop_name
, service
->sc_name
);
1835 /* Value is valid. Create the property. */
1836 p
= internal_property_create(prop_name
, SCF_TYPE_COUNT
, 1, count
);
1843 * The cardinality is specified by two attributes max and min at cursor.
1844 * Both are optional, but if present they must be unsigned integers.
1847 lxml_get_tm_cardinality(entity_t
*service
, pgroup_t
*pg
, xmlNodePtr cursor
)
1849 int min_attached
= 0;
1851 property_t
*min_prop
;
1852 property_t
*max_prop
;
1857 r
= lxml_get_cardinality_attribute(service
, cursor
, min_attr
,
1858 SCF_PROPERTY_TM_CARDINALITY_MIN
, &min
, &min_prop
);
1861 if (min_prop
== NULL
)
1863 r
= lxml_get_cardinality_attribute(service
, cursor
, max_attr
,
1864 SCF_PROPERTY_TM_CARDINALITY_MAX
, &max
, &max_prop
);
1867 if ((max_prop
!= NULL
) && (compare
== 1)) {
1869 semerr(gettext("Cardinality max is less than min for "
1870 "the %s element in %s.\n"), pg
->sc_pgroup_name
,
1876 /* Attach the properties to the property group. */
1878 if (internal_attach_property(pg
, min_prop
) == 0) {
1885 if (internal_attach_property(pg
, max_prop
) != 0) {
1887 internal_detach_property(pg
, min_prop
);
1895 internal_property_free(min_prop
);
1897 internal_property_free(max_prop
);
1902 * Get the common_name which is present as localized text at common_name in
1903 * the manifest. The common_name is stored as the value of a property in
1904 * the property group whose name is SCF_PG_TM_COMMON_NAME and type is
1905 * SCF_GROUP_TEMPLATE. This property group will be created in service if
1906 * it is not already there.
1909 lxml_get_tm_common_name(entity_t
*service
, xmlNodePtr common_name
)
1914 * Create the property group, if absent.
1916 pg
= internal_pgroup_find_or_create(service
, SCF_PG_TM_COMMON_NAME
,
1917 SCF_GROUP_TEMPLATE
);
1919 return (lxml_get_all_loctext(service
, pg
, common_name
, LOCALE_ONLY_FMT
,
1924 * Get the description which is present as localized text at description in
1925 * the manifest. The description is stored as the value of a property in
1926 * the property group whose name is SCF_PG_TM_DESCRIPTION and type is
1927 * SCF_GROUP_TEMPLATE. This property group will be created in service if
1928 * it is not already there.
1931 lxml_get_tm_description(entity_t
*service
, xmlNodePtr description
)
1936 * Create the property group, if absent.
1938 pg
= internal_pgroup_find_or_create(service
, SCF_PG_TM_DESCRIPTION
,
1939 SCF_GROUP_TEMPLATE
);
1941 return (lxml_get_all_loctext(service
, pg
, description
,
1942 LOCALE_ONLY_FMT
, "description"));
1946 lxml_label_to_groupname(const char *prefix
, const char *in
)
1949 size_t len
, piece_len
;
1951 out
= uu_zalloc(2 * max_scf_name_len
+ 1);
1955 (void) strlcpy(out
, prefix
, 2 * max_scf_name_len
+ 1);
1957 len
= strlcat(out
, in
, 2 * max_scf_name_len
+ 1);
1958 if (len
> max_scf_name_len
) {
1959 /* Use the first half and the second half. */
1960 piece_len
= (max_scf_name_len
- 2) / 2;
1962 (void) strncpy(out
+ piece_len
, "..", 2);
1964 (void) strcpy(out
+ piece_len
+ 2, out
+ (len
- piece_len
));
1968 * Translate non-property characters to '_'.
1970 for (cp
= out
; *cp
!= '\0'; ++cp
) {
1971 if (!(isalnum(*cp
) || *cp
== '_' || *cp
== '-'))
1979 * If *p is NULL, astring_prop_value() first creates a property with the
1980 * name specified in prop_name. The address of the newly created property
1983 * In either case, newly created property or existing property, a new
1984 * SCF_TYPE_ASTRING value will created and attached to the property at *p.
1985 * The value of the newly created property is prop_value.
1987 * free_flag is used to indicate whether or not the memory at prop_value
1988 * should be freed when the property is freed by a call to
1989 * internal_property_free().
1992 astring_prop_value(property_t
**p
, const char *prop_name
, char *prop_value
,
1993 boolean_t free_flag
)
1998 /* Create the property */
1999 *p
= internal_property_new();
2000 (*p
)->sc_property_name
= (char *)prop_name
;
2001 (*p
)->sc_value_type
= SCF_TYPE_ASTRING
;
2004 /* Add the property value to the property's list of values. */
2005 v
= internal_value_new();
2006 v
->sc_type
= SCF_TYPE_ASTRING
;
2007 if (free_flag
== B_TRUE
)
2008 v
->sc_free
= lxml_free_str
;
2009 v
->sc_u
.sc_string
= prop_value
;
2010 internal_attach_value(*p
, v
);
2014 * If p points to a null pointer, create an internal_separators property
2015 * saving the address at p. For each character at seps create a property
2016 * value and attach it to the property at p.
2019 seps_to_prop_values(property_t
**p
, xmlChar
*seps
)
2025 *p
= internal_property_new();
2026 (*p
)->sc_property_name
=
2027 (char *)SCF_PROPERTY_INTERNAL_SEPARATORS
;
2028 (*p
)->sc_value_type
= SCF_TYPE_ASTRING
;
2031 /* Add the values to the property's list. */
2032 val_str
[1] = 0; /* Terminate the string. */
2033 for (; *seps
!= 0; seps
++) {
2034 v
= internal_value_new();
2035 v
->sc_type
= (*p
)->sc_value_type
;
2036 v
->sc_free
= lxml_free_str
;
2038 v
->sc_u
.sc_string
= safe_strdup(val_str
);
2039 internal_attach_value(*p
, v
);
2044 * Create an internal_separators property and attach it to the property
2045 * group at pg. The separator characters are provided in the text nodes
2046 * that are the children of seps. Each separator character is stored as a
2047 * property value in the internal_separators property.
2050 lxml_get_tm_internal_seps(entity_t
*service
, pgroup_t
*pg
, xmlNodePtr seps
)
2053 property_t
*prop
= NULL
;
2056 for (cursor
= seps
->xmlChildrenNode
; cursor
!= NULL
;
2057 cursor
= cursor
->next
) {
2058 if (strcmp("text", (const char *)cursor
->name
) == 0) {
2059 seps_to_prop_values(&prop
, cursor
->content
);
2060 } else if (strcmp("comment", (const char *)cursor
->name
) != 0) {
2061 uu_die(gettext("illegal element \"%s\" on %s element "
2062 "for \"%s\"\n"), cursor
->name
, seps
->name
,
2067 semerr(gettext("The %s element in %s had an empty list of "
2068 "separators.\n"), (const char *)seps
->name
,
2072 r
= internal_attach_property(pg
, prop
);
2074 internal_property_free(prop
);
2079 lxml_get_tm_manpage(entity_t
*service
, xmlNodePtr manpage
)
2088 * Fetch title and section attributes, convert to something sanitized,
2089 * and create property group.
2091 title
= xmlGetProp(manpage
, (xmlChar
*)title_attr
);
2094 section
= xmlGetProp(manpage
, (xmlChar
*)section_attr
);
2095 if (section
== NULL
) {
2100 name
= safe_malloc(max_scf_name_len
+ 1);
2102 /* Find existing property group with underscore separators */
2103 (void) snprintf(name
, max_scf_name_len
+ 1, "%s_%s", title
, section
);
2104 pgname
= lxml_label_to_groupname(SCF_PG_TM_MAN_PREFIX
, name
);
2105 pg
= internal_pgroup_find(service
, pgname
, SCF_GROUP_TEMPLATE
);
2108 (void) snprintf(name
, max_scf_name_len
+ 1, "%s%s", title
, section
);
2109 pgname
= lxml_label_to_groupname(SCF_PG_TM_MAN_PREFIX
, name
);
2112 pg
= internal_pgroup_find_or_create(service
, pgname
,
2113 SCF_GROUP_TEMPLATE
);
2115 /* Rename property group */
2116 free((char *)pg
->sc_pgroup_name
);
2117 pg
->sc_pgroup_name
= safe_strdup(pgname
);
2127 * Each attribute is an astring property within the group.
2129 if (new_str_prop_from_attr(pg
, SCF_PROPERTY_TM_TITLE
,
2130 SCF_TYPE_ASTRING
, manpage
, title_attr
) != 0 ||
2131 new_str_prop_from_attr(pg
, SCF_PROPERTY_TM_SECTION
,
2132 SCF_TYPE_ASTRING
, manpage
, section_attr
) != 0 ||
2133 new_str_prop_from_attr(pg
, SCF_PROPERTY_TM_MANPATH
,
2134 SCF_TYPE_ASTRING
, manpage
, manpath_attr
) != 0)
2141 lxml_get_tm_doclink(entity_t
*service
, xmlNodePtr doc_link
)
2148 * Fetch name attribute, convert name to something sanitized, and create
2151 name
= xmlGetProp(doc_link
, (xmlChar
*)name_attr
);
2155 pgname
= (char *)lxml_label_to_groupname(SCF_PG_TM_DOC_PREFIX
,
2156 (const char *)name
);
2158 pg
= internal_pgroup_find_or_create(service
, pgname
,
2159 (char *)SCF_GROUP_TEMPLATE
);
2165 * Each attribute is an astring property within the group.
2167 if (new_str_prop_from_attr(pg
, SCF_PROPERTY_TM_NAME
, SCF_TYPE_ASTRING
,
2168 doc_link
, name_attr
) != 0 ||
2169 new_str_prop_from_attr(pg
, SCF_PROPERTY_TM_URI
, SCF_TYPE_ASTRING
,
2170 doc_link
, uri_attr
) != 0)
2177 lxml_get_tm_documentation(entity_t
*service
, xmlNodePtr documentation
)
2181 for (cursor
= documentation
->xmlChildrenNode
; cursor
!= NULL
;
2182 cursor
= cursor
->next
) {
2183 if (lxml_ignorable_block(cursor
))
2186 switch (lxml_xlate_element(cursor
->name
)) {
2188 (void) lxml_get_tm_manpage(service
, cursor
);
2191 (void) lxml_get_tm_doclink(service
, cursor
);
2194 uu_die(gettext("illegal element \"%s\" on template "
2195 "for service \"%s\"\n"),
2196 cursor
->name
, service
->sc_name
);
2204 lxml_get_prop_pattern_attributes(pgroup_t
*pg
, xmlNodePtr cursor
)
2206 if (new_opt_str_prop_from_attr(pg
, SCF_PROPERTY_TM_NAME
,
2207 SCF_TYPE_ASTRING
, cursor
, name_attr
, NULL
) != 0) {
2210 if (new_opt_str_prop_from_attr(pg
, SCF_PROPERTY_TM_TYPE
,
2211 SCF_TYPE_ASTRING
, cursor
, type_attr
, "") != 0) {
2214 if (new_bool_prop_from_attr(pg
, SCF_PROPERTY_TM_REQUIRED
, cursor
,
2215 required_attr
) != 0)
2221 lxml_get_tm_include_values(entity_t
*service
, pgroup_t
*pg
,
2222 xmlNodePtr include_values
, const char *prop_name
)
2224 boolean_t attach_to_pg
= B_FALSE
;
2229 /* Get the type attribute of the include_values element. */
2230 type
= (char *)xmlGetProp(include_values
, (const xmlChar
*)type_attr
);
2231 if ((type
== NULL
) || (*type
== 0)) {
2232 uu_die(gettext("%s element requires a %s attribute in the %s "
2233 "service.\n"), include_values
->name
, type_attr
,
2237 /* Add the type to the values of the prop_name property. */
2238 p
= internal_property_find(pg
, prop_name
);
2240 attach_to_pg
= B_TRUE
;
2241 astring_prop_value(&p
, prop_name
, type
, B_FALSE
);
2242 if (attach_to_pg
== B_TRUE
) {
2243 r
= internal_attach_property(pg
, p
);
2245 internal_property_free(p
);
2255 * Verify that the strings at min and max are valid numeric strings. Also
2256 * verify that max is numerically >= min.
2258 * 0 is returned if the range is valid, and -1 is returned if it is not.
2261 verify_range(entity_t
*service
, xmlNodePtr range
, char *min
, char *max
)
2267 const char *limit
[RC_COUNT
];
2268 char *strings
[RC_COUNT
];
2269 uint64_t urange
[RC_COUNT
]; /* unsigned range. */
2270 int64_t srange
[RC_COUNT
]; /* signed range. */
2272 strings
[RC_MIN
] = min
;
2273 strings
[RC_MAX
] = max
;
2274 limit
[RC_MIN
] = min_attr
;
2275 limit
[RC_MAX
] = max_attr
;
2277 /* See if the range is signed. */
2278 for (i
= 0; (i
< RC_COUNT
) && (is_signed
== 0); i
++) {
2280 while (isspace(*c
)) {
2287 /* Attempt to convert the strings. */
2288 for (i
= 0; i
< RC_COUNT
; i
++) {
2291 srange
[i
] = strtoll(strings
[i
], &c
, 0);
2293 urange
[i
] = strtoull(strings
[i
], &c
, 0);
2295 if ((errno
!= 0) || (c
== strings
[i
]) || (*c
!= 0)) {
2296 /* Conversion failed. */
2297 uu_die(gettext("Unable to convert %s for the %s "
2298 "element in service %s.\n"), limit
[i
],
2299 (char *)range
->name
, service
->sc_name
);
2303 /* Make sure that min is <= max */
2305 if (srange
[RC_MAX
] < srange
[RC_MIN
])
2308 if (urange
[RC_MAX
] < urange
[RC_MIN
])
2311 if (inverted
!= 0) {
2312 semerr(gettext("Maximum less than minimum for the %s element "
2313 "in service %s.\n"), (char *)range
->name
,
2322 * This, function creates a property named prop_name. The range element
2323 * should have two attributes -- min and max. The property value then
2324 * becomes the concatenation of their value separated by a comma. The
2325 * property is then attached to the property group at pg.
2327 * If pg already contains a property with a name of prop_name, it is only
2328 * necessary to create a new value and attach it to the existing property.
2331 lxml_get_tm_range(entity_t
*service
, pgroup_t
*pg
, xmlNodePtr range
,
2332 const char *prop_name
)
2334 boolean_t attach_to_pg
= B_FALSE
;
2341 /* Get max and min from the XML description. */
2342 max
= (char *)xmlGetProp(range
, (xmlChar
*)max_attr
);
2343 if ((max
== NULL
) || (*max
== 0)) {
2344 uu_die(gettext("%s element is missing the %s attribute in "
2345 "service %s.\n"), (char *)range
->name
, max_attr
,
2348 min
= (char *)xmlGetProp(range
, (xmlChar
*)min_attr
);
2349 if ((min
== NULL
) || (*min
== 0)) {
2350 uu_die(gettext("%s element is missing the %s attribute in "
2351 "service %s.\n"), (char *)range
->name
, min_attr
,
2354 if (verify_range(service
, range
, min
, max
) != 0) {
2360 /* Property value is concatenation of min and max. */
2361 prop_value
= safe_malloc(max_scf_value_len
+ 1);
2362 if (snprintf(prop_value
, max_scf_value_len
+ 1, "%s,%s", min
, max
) >=
2363 max_scf_value_len
+ 1) {
2364 uu_die(gettext("min and max are too long for the %s element "
2365 "of %s.\n"), (char *)range
->name
, service
->sc_name
);
2371 * If necessary create the property and attach it to the property
2374 p
= internal_property_find(pg
, prop_name
);
2376 attach_to_pg
= B_TRUE
;
2377 astring_prop_value(&p
, prop_name
, prop_value
, B_TRUE
);
2378 if (attach_to_pg
== B_TRUE
) {
2379 r
= internal_attach_property(pg
, p
);
2381 internal_property_free(p
);
2388 * Determine how many plain characters are represented by count Base32
2389 * encoded characters. 5 plain text characters are converted to 8 Base32
2393 encoded_count_to_plain(size_t count
)
2395 return (5 * ((count
+ 7) / 8));
2399 * The value element contains 0 or 1 common_name element followed by 0 or 1
2400 * description element. It also has a required attribute called "name".
2401 * The common_name and description are stored as property values in pg.
2402 * The property names are:
2403 * value_<name>_common_name_<lang>
2404 * value_<name>_description_<lang>
2406 * The <name> portion of the preceeding proper names requires more
2407 * explanation. Ideally it would just the name attribute of this value
2408 * element. Unfortunately, the name attribute can contain characters that
2409 * are not legal in a property name. Thus, we base 32 encode the name
2410 * attribute and use that for <name>.
2412 * There are cases where the caller needs to know the name, so it is
2413 * returned through the name_value pointer if it is not NULL.
2416 * service - Information about the service that is being
2417 * processed. This function only uses this parameter
2418 * for producing error messages.
2420 * pg - The property group to receive the newly created
2423 * value - Pointer to the value element in the XML tree.
2425 * name_value - Address to receive the value of the name attribute.
2426 * The caller must free the memory.
2429 lxml_get_tm_value_element(entity_t
*service
, pgroup_t
*pg
, xmlNodePtr value
,
2432 char *common_name_fmt
;
2434 char *description_fmt
;
2435 char *encoded_value
= NULL
;
2440 common_name_fmt
= safe_malloc(max_scf_name_len
+ 1);
2441 description_fmt
= safe_malloc(max_scf_name_len
+ 1);
2444 * Get the value of our name attribute, so that we can use it to
2445 * construct property names.
2447 value_name
= (char *)xmlGetProp(value
, (xmlChar
*)name_attr
);
2448 /* The value name must be present, but it can be empty. */
2449 if (value_name
== NULL
) {
2450 uu_die(gettext("%s element requires a %s attribute in the %s "
2451 "service.\n"), (char *)value
->name
, name_attr
,
2456 * The value_name may contain characters that are not valid in in a
2457 * property name. So we will encode value_name and then use the
2458 * encoded value in the property name.
2460 encoded_value
= safe_malloc(max_scf_name_len
+ 1);
2461 if (scf_encode32(value_name
, strlen(value_name
), encoded_value
,
2462 max_scf_name_len
+ 1, &extra
, SCF_ENCODE32_PAD
) != 0) {
2463 extra
= encoded_count_to_plain(extra
- max_scf_name_len
);
2464 uu_die(gettext("Constructed property name is %u characters "
2465 "too long for value \"%s\" in the %s service.\n"),
2466 extra
, value_name
, service
->sc_name
);
2468 if ((extra
= snprintf(common_name_fmt
, max_scf_name_len
+ 1,
2469 VALUE_COMMON_NAME_FMT
, SCF_PROPERTY_TM_VALUE_PREFIX
,
2470 encoded_value
)) >= max_scf_name_len
+ 1) {
2471 extra
= encoded_count_to_plain(extra
- max_scf_name_len
);
2472 uu_die(gettext("Name attribute is "
2473 "%u characters too long for %s in service %s\n"),
2474 extra
, (char *)value
->name
, service
->sc_name
);
2476 if ((extra
= snprintf(description_fmt
, max_scf_name_len
+ 1,
2477 VALUE_DESCRIPTION_FMT
, SCF_PROPERTY_TM_VALUE_PREFIX
,
2478 encoded_value
)) >= max_scf_name_len
+ 1) {
2479 extra
= encoded_count_to_plain(extra
- max_scf_name_len
);
2480 uu_die(gettext("Name attribute is "
2481 "%u characters too long for %s in service %s\n"),
2482 extra
, (char *)value
->name
, service
->sc_name
);
2485 for (cursor
= value
->xmlChildrenNode
;
2487 cursor
= cursor
->next
) {
2488 if (lxml_ignorable_block(cursor
))
2490 switch (lxml_xlate_element(cursor
->name
)) {
2491 case SC_COMMON_NAME
:
2492 r
= lxml_get_all_loctext(service
, pg
, cursor
,
2493 common_name_fmt
, (const char *)cursor
->name
);
2495 case SC_DESCRIPTION
:
2496 r
= lxml_get_all_loctext(service
, pg
, cursor
,
2497 description_fmt
, (const char *)cursor
->name
);
2500 uu_die(gettext("\"%s\" is an illegal element in %s "
2501 "of service %s\n"), (char *)cursor
->name
,
2502 (char *)value
->name
, service
->sc_name
);
2508 free(description_fmt
);
2509 free(common_name_fmt
);
2511 *name_value
= safe_strdup(value_name
);
2513 xmlFree(value_name
);
2514 free(encoded_value
);
2519 lxml_get_tm_choices(entity_t
*service
, pgroup_t
*pg
, xmlNodePtr choices
)
2523 property_t
*name_prop
= NULL
;
2526 for (cursor
= choices
->xmlChildrenNode
;
2527 (cursor
!= NULL
) && (r
== 0);
2528 cursor
= cursor
->next
) {
2529 if (lxml_ignorable_block(cursor
))
2531 switch (lxml_xlate_element(cursor
->name
)) {
2532 case SC_INCLUDE_VALUES
:
2533 (void) lxml_get_tm_include_values(service
, pg
, cursor
,
2534 SCF_PROPERTY_TM_CHOICES_INCLUDE_VALUES
);
2537 r
= lxml_get_tm_range(service
, pg
, cursor
,
2538 SCF_PROPERTY_TM_CHOICES_RANGE
);
2543 r
= lxml_get_tm_value_element(service
, pg
, cursor
,
2547 * There is no need to free the memory
2548 * associated with name_value, because the
2549 * property value will end up pointing to
2552 astring_prop_value(&name_prop
,
2553 SCF_PROPERTY_TM_CHOICES_NAME
, name_value
,
2560 uu_die(gettext("%s is an invalid element of "
2561 "choices for service %s.\n"), cursor
->name
,
2567 /* Attach the name property if we created one. */
2568 if ((r
== 0) && (name_prop
!= NULL
)) {
2569 r
= internal_attach_property(pg
, name_prop
);
2571 if ((r
!= 0) && (name_prop
!= NULL
)) {
2572 internal_property_free(name_prop
);
2579 lxml_get_tm_constraints(entity_t
*service
, pgroup_t
*pg
, xmlNodePtr constraints
)
2583 property_t
*name_prop
= NULL
;
2586 for (cursor
= constraints
->xmlChildrenNode
;
2587 (cursor
!= NULL
) && (r
== 0);
2588 cursor
= cursor
->next
) {
2589 if (lxml_ignorable_block(cursor
))
2591 switch (lxml_xlate_element(cursor
->name
)) {
2593 r
= lxml_get_tm_range(service
, pg
, cursor
,
2594 SCF_PROPERTY_TM_CONSTRAINT_RANGE
);
2599 r
= lxml_get_tm_value_element(service
, pg
, cursor
,
2603 * There is no need to free the memory
2604 * associated with name_value, because the
2605 * property value will end up pointing to
2608 astring_prop_value(&name_prop
,
2609 SCF_PROPERTY_TM_CONSTRAINT_NAME
, name_value
,
2616 uu_die(gettext("%s is an invalid element of "
2617 "constraints for service %s.\n"), cursor
->name
,
2623 /* Attach the name property if we created one. */
2624 if ((r
== 0) && (name_prop
!= NULL
)) {
2625 r
= internal_attach_property(pg
, name_prop
);
2627 if ((r
!= 0) && (name_prop
!= NULL
)) {
2628 internal_property_free(name_prop
);
2635 * The values element contains one or more value elements.
2638 lxml_get_tm_values(entity_t
*service
, pgroup_t
*pg
, xmlNodePtr values
)
2642 property_t
*name_prop
= NULL
;
2645 for (cursor
= values
->xmlChildrenNode
;
2646 (cursor
!= NULL
) && (r
== 0);
2647 cursor
= cursor
->next
) {
2648 if (lxml_ignorable_block(cursor
))
2650 if (lxml_xlate_element(cursor
->name
) != SC_VALUE
) {
2651 uu_die(gettext("\"%s\" is an illegal element in the "
2652 "%s element of %s\n"), (char *)cursor
->name
,
2653 (char *)values
->name
, service
->sc_name
);
2655 r
= lxml_get_tm_value_element(service
, pg
, cursor
, &name_value
);
2658 * There is no need to free the memory
2659 * associated with name_value, because the
2660 * property value will end up pointing to
2663 astring_prop_value(&name_prop
,
2664 SCF_PROPERTY_TM_VALUES_NAME
, name_value
,
2669 /* Attach the name property if we created one. */
2670 if ((r
== 0) && (name_prop
!= NULL
)) {
2671 r
= internal_attach_property(pg
, name_prop
);
2673 if ((r
!= 0) && (name_prop
!= NULL
)) {
2674 internal_property_free(name_prop
);
2681 * This function processes a prop_pattern element within a pg_pattern XML
2682 * element. First it creates a property group to hold the prop_pattern
2683 * information. The name of this property group is the concatenation of:
2684 * - SCF_PG_TM_PROP_PATTERN_PREFIX
2685 * - The unique part of the property group name of the enclosing
2686 * pg_pattern. The property group name of the enclosing pg_pattern
2687 * is passed to us in pgpat_name. The unique part, is the part
2688 * following SCF_PG_TM_PG_PATTERN_PREFIX.
2689 * - The name of this prop_pattern element.
2691 * After creating the property group, the prop_pattern attributes are saved
2692 * as properties in the PG. Finally, the prop_pattern elements are
2693 * processed and added to the PG.
2696 lxml_get_tm_prop_pattern(entity_t
*service
, xmlNodePtr prop_pattern
,
2697 const char *pgpat_name
)
2705 xmlChar
*prop_pattern_name
;
2710 /* Find the unique part of the pg_pattern property group name. */
2711 prefix_len
= strlen(SCF_PG_TM_PG_PAT_BASE
);
2712 assert(strncmp(pgpat_name
, SCF_PG_TM_PG_PAT_BASE
, prefix_len
) == 0);
2713 unique
= pgpat_name
+ prefix_len
;
2716 * We need to get the value of the name attribute first. The
2717 * prop_pattern name as well as the name of the enclosing
2718 * pg_pattern both constitute part of the name of the property
2719 * group that we will create.
2721 prop_pattern_name
= xmlGetProp(prop_pattern
, (xmlChar
*)name_attr
);
2722 if ((prop_pattern_name
== NULL
) || (*prop_pattern_name
== 0)) {
2723 semerr(gettext("prop_pattern name is missing for %s\n"),
2727 if (uu_check_name((const char *)prop_pattern_name
,
2728 UU_NAME_DOMAIN
) != 0) {
2729 semerr(gettext("prop_pattern name, \"%s\", for %s is not "
2730 "valid.\n"), prop_pattern_name
, service
->sc_name
);
2731 xmlFree(prop_pattern_name
);
2734 pg_name
= safe_malloc(max_scf_name_len
+ 1);
2735 if ((extra
= snprintf(pg_name
, max_scf_name_len
+ 1, "%s%s_%s",
2736 SCF_PG_TM_PROP_PATTERN_PREFIX
, unique
,
2737 (char *)prop_pattern_name
)) >= max_scf_name_len
+ 1) {
2738 uu_die(gettext("prop_pattern name, \"%s\", for %s is %d "
2739 "characters too long\n"), (char *)prop_pattern_name
,
2740 service
->sc_name
, extra
- max_scf_name_len
);
2744 * Create the property group, the property referencing the pg_pattern
2745 * name, and add the prop_pattern attributes to the property group.
2747 pg
= internal_pgroup_create_strict(service
, pg_name
,
2748 SCF_GROUP_TEMPLATE_PROP_PATTERN
);
2750 uu_die(gettext("Property group for prop_pattern, \"%s\", "
2751 "already exists in %s\n"), prop_pattern_name
,
2755 p
= internal_property_create(SCF_PROPERTY_TM_PG_PATTERN
,
2756 SCF_TYPE_ASTRING
, 1, safe_strdup(pgpat_name
));
2758 * Unfortunately, internal_property_create() does not set the free
2759 * function for the value, so we'll set it now.
2761 v
= uu_list_first(p
->sc_property_values
);
2762 v
->sc_free
= lxml_free_str
;
2763 if (internal_attach_property(pg
, p
) != 0)
2764 internal_property_free(p
);
2767 r
= lxml_get_prop_pattern_attributes(pg
, prop_pattern
);
2772 * Now process the elements of prop_pattern
2774 for (cursor
= prop_pattern
->xmlChildrenNode
;
2776 cursor
= cursor
->next
) {
2777 if (lxml_ignorable_block(cursor
))
2780 switch (lxml_xlate_element(cursor
->name
)) {
2781 case SC_CARDINALITY
:
2782 r
= lxml_get_tm_cardinality(service
, pg
, cursor
);
2787 r
= lxml_get_tm_choices(service
, pg
, cursor
);
2791 case SC_COMMON_NAME
:
2792 (void) lxml_get_all_loctext(service
, pg
, cursor
,
2793 COMMON_NAME_FMT
, (const char *)cursor
->name
);
2795 case SC_CONSTRAINTS
:
2796 r
= lxml_get_tm_constraints(service
, pg
, cursor
);
2800 case SC_DESCRIPTION
:
2801 (void) lxml_get_all_loctext(service
, pg
, cursor
,
2802 DESCRIPTION_FMT
, (const char *)cursor
->name
);
2804 case SC_INTERNAL_SEPARATORS
:
2805 r
= lxml_get_tm_internal_seps(service
, pg
, cursor
);
2810 (void) lxml_get_all_loctext(service
, pg
, cursor
,
2811 UNITS_FMT
, "units");
2814 (void) lxml_get_tm_values(service
, pg
, cursor
);
2818 * The visibility element is empty, so we only need
2819 * to proccess the value attribute.
2821 (void) new_str_prop_from_attr(pg
,
2822 SCF_PROPERTY_TM_VISIBILITY
, SCF_TYPE_ASTRING
,
2823 cursor
, value_attr
);
2826 uu_die(gettext("illegal element \"%s\" in prop_pattern "
2827 "for service \"%s\"\n"), cursor
->name
,
2833 xmlFree(prop_pattern_name
);
2839 * Get the pg_pattern attributes and save them as properties in the
2840 * property group at pg. The pg_pattern element accepts four attributes --
2841 * name, type, required and target.
2844 lxml_get_pg_pattern_attributes(pgroup_t
*pg
, xmlNodePtr cursor
)
2846 if (new_opt_str_prop_from_attr(pg
, SCF_PROPERTY_TM_NAME
,
2847 SCF_TYPE_ASTRING
, cursor
, name_attr
, NULL
) != 0) {
2850 if (new_opt_str_prop_from_attr(pg
, SCF_PROPERTY_TM_TYPE
,
2851 SCF_TYPE_ASTRING
, cursor
, type_attr
, NULL
) != 0) {
2854 if (new_opt_str_prop_from_attr(pg
, SCF_PROPERTY_TM_TARGET
,
2855 SCF_TYPE_ASTRING
, cursor
, target_attr
, NULL
) != 0) {
2858 if (new_bool_prop_from_attr(pg
, SCF_PROPERTY_TM_REQUIRED
, cursor
,
2859 required_attr
) != 0)
2865 * There are several restrictions on the pg_pattern attributes that cannot
2866 * be specifed in the service bundle DTD. This function verifies that
2867 * those restrictions have been satisfied. The restrictions are:
2869 * - The target attribute may have a value of "instance" only when the
2870 * template block is in a service declaration.
2872 * - The target attribute may have a value of "delegate" only when the
2873 * template block applies to a restarter.
2875 * - The target attribute may have a value of "all" only when the
2876 * template block applies to the master restarter.
2878 * The function returns 0 on success and -1 on failure.
2881 verify_pg_pattern_attributes(entity_t
*s
, pgroup_t
*pg
)
2887 /* Find the value of the target property. */
2888 target
= internal_property_find(pg
, SCF_PROPERTY_TM_TARGET
);
2889 if (target
== NULL
) {
2890 uu_die(gettext("pg_pattern is missing the %s attribute "
2891 "in %s\n"), target_attr
, s
->sc_name
);
2894 v
= uu_list_first(target
->sc_property_values
);
2896 assert(v
->sc_type
== SCF_TYPE_ASTRING
);
2899 * If target has a value of instance, the template must be in a
2902 if (strcmp(v
->sc_u
.sc_string
, "instance") == 0) {
2903 if (s
->sc_etype
!= SVCCFG_SERVICE_OBJECT
) {
2904 uu_warn(gettext("pg_pattern %s attribute may only "
2905 "have a value of \"instance\" when it is in a "
2906 "service declaration.\n"), target_attr
);
2912 * If target has a value of "delegate", the template must be in a
2915 if (strcmp(v
->sc_u
.sc_string
, "delegate") == 0) {
2917 if ((s
->sc_etype
== SVCCFG_SERVICE_OBJECT
) &&
2918 (s
->sc_u
.sc_service
.sc_service_type
== SVCCFG_RESTARTER
)) {
2921 if ((s
->sc_etype
== SVCCFG_INSTANCE_OBJECT
) &&
2922 (s
->sc_parent
->sc_u
.sc_service
.sc_service_type
==
2923 SVCCFG_RESTARTER
)) {
2926 if (is_restarter
== 0) {
2927 uu_warn(gettext("pg_pattern %s attribute has a "
2928 "value of \"delegate\" but is not in a "
2929 "restarter service\n"), target_attr
);
2935 * If target has a value of "all", the template must be in the
2936 * global (SCF_SERVICE_GLOBAL) service.
2938 if (strcmp(v
->sc_u
.sc_string
, all_value
) == 0) {
2939 if (s
->sc_etype
!= SVCCFG_SERVICE_OBJECT
) {
2940 uu_warn(gettext("pg_pattern %s attribute has a "
2941 "value of \"%s\" but is not in a "
2942 "service entity.\n"), target_attr
, all_value
);
2945 if (strcmp(s
->sc_fmri
, SCF_SERVICE_GLOBAL
) != 0) {
2946 uu_warn(gettext("pg_pattern %s attribute has a "
2947 "value of \"%s\" but is in the \"%s\" service. "
2948 "pg_patterns with target \"%s\" are only allowed "
2949 "in the global service.\n"),
2950 target_attr
, all_value
, s
->sc_fmri
, all_value
);
2959 lxml_get_tm_pg_pattern(entity_t
*service
, xmlNodePtr pg_pattern
)
2964 pgroup_t
*pg
= NULL
;
2969 pg_name
= safe_malloc(max_scf_name_len
+ 1);
2972 * Get the name and type attributes. Their presence or absence
2973 * determines whcih prefix we will use for the property group name.
2974 * There are four cases -- neither attribute is present, both are
2975 * present, only name is present or only type is present.
2977 name
= xmlGetProp(pg_pattern
, (xmlChar
*)name_attr
);
2978 type
= xmlGetProp(pg_pattern
, (xmlChar
*)type_attr
);
2979 if ((name
== NULL
) || (*name
== 0)) {
2980 if ((type
== NULL
) || (*type
== 0)) {
2981 /* PG name contains only the prefix in this case */
2982 if (strlcpy(pg_name
, SCF_PG_TM_PG_PATTERN_PREFIX
,
2983 max_scf_name_len
+ 1) >= max_scf_name_len
+ 1) {
2984 uu_die(gettext("Unable to create pg_pattern "
2985 "property for %s\n"), service
->sc_name
);
2989 * If we have a type and no name, the type becomes
2990 * part of the pg_pattern property group name.
2992 if ((out_len
= snprintf(pg_name
, max_scf_name_len
+ 1,
2993 "%s%s", SCF_PG_TM_PG_PATTERN_T_PREFIX
, type
)) >=
2994 max_scf_name_len
+ 1) {
2995 uu_die(gettext("pg_pattern type is for %s is "
2996 "%d bytes too long\n"), service
->sc_name
,
2997 out_len
- max_scf_name_len
);
3003 /* Make sure that the name is valid. */
3004 if (uu_check_name((const char *)name
, UU_NAME_DOMAIN
) != 0) {
3005 semerr(gettext("pg_pattern name attribute, \"%s\", "
3006 "for %s is invalid\n"), name
, service
->sc_name
);
3011 * As long as the pg_pattern has a name, it becomes part of
3012 * the name of the pg_pattern property group name. We
3013 * merely need to pick the appropriate prefix.
3015 if ((type
== NULL
) || (*type
== 0)) {
3016 prefix
= SCF_PG_TM_PG_PATTERN_N_PREFIX
;
3018 prefix
= SCF_PG_TM_PG_PATTERN_NT_PREFIX
;
3020 if ((out_len
= snprintf(pg_name
, max_scf_name_len
+ 1, "%s%s",
3021 prefix
, name
)) >= max_scf_name_len
+ 1) {
3022 uu_die(gettext("pg_pattern property group name "
3023 "for %s is %d bytes too long\n"), service
->sc_name
,
3024 out_len
- max_scf_name_len
);
3029 * Create the property group for holding this pg_pattern
3030 * information, and capture the pg_pattern attributes.
3032 pg
= internal_pgroup_create_strict(service
, pg_name
,
3033 SCF_GROUP_TEMPLATE_PG_PATTERN
);
3035 if ((name
== NULL
) || (*name
== 0)) {
3036 if ((type
== NULL
) ||(*type
== 0)) {
3037 semerr(gettext("pg_pattern with empty name and "
3038 "type is not unique in %s\n"),
3041 semerr(gettext("pg_pattern with empty name and "
3042 "type \"%s\" is not unique in %s\n"),
3043 type
, service
->sc_name
);
3046 if ((type
== NULL
) || (*type
== 0)) {
3047 semerr(gettext("pg_pattern with name \"%s\" "
3048 "and empty type is not unique in %s\n"),
3049 name
, service
->sc_name
);
3051 semerr(gettext("pg_pattern with name \"%s\" "
3052 "and type \"%s\" is not unique in %s\n"),
3053 name
, type
, service
->sc_name
);
3060 * Get the pg_pattern attributes from the manifest and verify
3061 * that they satisfy our restrictions.
3063 r
= lxml_get_pg_pattern_attributes(pg
, pg_pattern
);
3066 if (verify_pg_pattern_attributes(service
, pg
) != 0) {
3067 semerr(gettext("Invalid pg_pattern attributes in %s\n"),
3074 * Now process all of the elements of pg_pattern.
3076 for (cursor
= pg_pattern
->xmlChildrenNode
;
3078 cursor
= cursor
->next
) {
3079 if (lxml_ignorable_block(cursor
))
3082 switch (lxml_xlate_element(cursor
->name
)) {
3083 case SC_COMMON_NAME
:
3084 (void) lxml_get_all_loctext(service
, pg
, cursor
,
3085 COMMON_NAME_FMT
, (const char *)cursor
->name
);
3087 case SC_DESCRIPTION
:
3088 (void) lxml_get_all_loctext(service
, pg
, cursor
,
3089 DESCRIPTION_FMT
, (const char *)cursor
->name
);
3091 case SC_PROP_PATTERN
:
3092 r
= lxml_get_tm_prop_pattern(service
, cursor
,
3098 uu_die(gettext("illegal element \"%s\" in pg_pattern "
3099 "for service \"%s\"\n"), cursor
->name
,
3105 if ((r
!= 0) && (pg
!= NULL
)) {
3106 internal_detach_pgroup(service
, pg
);
3107 internal_pgroup_free(pg
);
3117 lxml_get_template(entity_t
*service
, xmlNodePtr templ
)
3121 for (cursor
= templ
->xmlChildrenNode
; cursor
!= NULL
;
3122 cursor
= cursor
->next
) {
3123 if (lxml_ignorable_block(cursor
))
3126 switch (lxml_xlate_element(cursor
->name
)) {
3127 case SC_COMMON_NAME
:
3128 (void) lxml_get_tm_common_name(service
, cursor
);
3130 case SC_DESCRIPTION
:
3131 (void) lxml_get_tm_description(service
, cursor
);
3133 case SC_DOCUMENTATION
:
3134 (void) lxml_get_tm_documentation(service
, cursor
);
3137 if (lxml_get_tm_pg_pattern(service
, cursor
) != 0)
3141 uu_die(gettext("illegal element \"%s\" on template "
3142 "for service \"%s\"\n"),
3143 cursor
->name
, service
->sc_name
);
3151 lxml_get_default_instance(entity_t
*service
, xmlNodePtr definst
)
3158 uint64_t enabled_val
= 0;
3160 i
= internal_instance_new("default");
3162 if ((enabled
= xmlGetProp(definst
, (xmlChar
*)enabled_attr
)) != NULL
) {
3163 enabled_val
= (strcmp(true, (const char *)enabled
) == 0) ?
3169 * New general property group with enabled boolean property set.
3172 i
->sc_op
= service
->sc_op
;
3173 pg
= internal_pgroup_new();
3174 (void) internal_attach_pgroup(i
, pg
);
3176 pg
->sc_pgroup_name
= (char *)scf_pg_general
;
3177 pg
->sc_pgroup_type
= (char *)scf_group_framework
;
3178 pg
->sc_pgroup_flags
= 0;
3180 p
= internal_property_create(SCF_PROPERTY_ENABLED
, SCF_TYPE_BOOLEAN
, 1,
3183 (void) internal_attach_property(pg
, p
);
3186 * Add general/package property if PKGINST is set.
3188 if ((package
= getenv("PKGINST")) != NULL
) {
3189 p
= internal_property_create(SCF_PROPERTY_PACKAGE
,
3190 SCF_TYPE_ASTRING
, 1, package
);
3192 (void) internal_attach_property(pg
, p
);
3195 return (internal_attach_entity(service
, i
));
3199 * Translate an instance element into an internal property tree, added to
3200 * service. If op is SVCCFG_OP_APPLY (i.e., apply a profile), set the
3201 * enabled property to override.
3203 * If op is SVCCFG_OP_APPLY (i.e., apply a profile), do not allow for
3204 * modification of template data.
3207 lxml_get_instance(entity_t
*service
, xmlNodePtr inst
, bundle_type_t bt
,
3218 * Fetch its attributes, as appropriate.
3220 i
= internal_instance_new((char *)xmlGetProp(inst
,
3221 (xmlChar
*)name_attr
));
3224 * Note that this must be done before walking the children so that
3225 * sc_fmri is set in case we enter lxml_get_dependent().
3227 r
= internal_attach_entity(service
, i
);
3232 enabled
= xmlGetProp(inst
, (xmlChar
*)enabled_attr
);
3234 if (enabled
== NULL
) {
3235 if (bt
== SVCCFG_MANIFEST
) {
3236 semerr(gettext("Instance \"%s\" missing attribute "
3237 "\"%s\".\n"), i
->sc_name
, enabled_attr
);
3240 } else { /* enabled != NULL */
3241 if (strcmp(true, (const char *)enabled
) != 0 &&
3242 strcmp(false, (const char *)enabled
) != 0) {
3244 semerr(gettext("Invalid enabled value\n"));
3247 pg
= internal_pgroup_new();
3248 (void) internal_attach_pgroup(i
, pg
);
3250 pg
->sc_pgroup_name
= (char *)scf_pg_general
;
3251 pg
->sc_pgroup_type
= (char *)scf_group_framework
;
3252 pg
->sc_pgroup_flags
= 0;
3254 e_val
= (strcmp(true, (const char *)enabled
) == 0);
3255 p
= internal_property_create(SCF_PROPERTY_ENABLED
,
3256 SCF_TYPE_BOOLEAN
, 1, (uint64_t)e_val
);
3258 p
->sc_property_override
= (op
== SVCCFG_OP_APPLY
);
3260 (void) internal_attach_property(pg
, p
);
3266 * Walk its child elements, as appropriate.
3268 for (cursor
= inst
->xmlChildrenNode
; cursor
!= NULL
;
3269 cursor
= cursor
->next
) {
3270 if (lxml_ignorable_block(cursor
))
3273 switch (lxml_xlate_element(cursor
->name
)) {
3275 (void) lxml_get_restarter(i
, cursor
);
3278 (void) lxml_get_dependency(i
, cursor
);
3281 (void) lxml_get_dependent(i
, cursor
);
3283 case SC_METHOD_CONTEXT
:
3284 (void) lxml_get_entity_method_context(i
, cursor
);
3286 case SC_EXEC_METHOD
:
3287 (void) lxml_get_exec_method(i
, cursor
);
3289 case SC_PROPERTY_GROUP
:
3290 (void) lxml_get_pgroup(i
, cursor
);
3293 if (op
== SVCCFG_OP_APPLY
) {
3294 semerr(gettext("Template data for \"%s\" may "
3295 "not be modified in a profile.\n"),
3301 if (lxml_get_template(i
, cursor
) != 0)
3304 case SC_NOTIFICATION_PARAMETERS
:
3305 if (lxml_get_notification_parameters(i
, cursor
) != 0)
3310 "illegal element \"%s\" on instance \"%s\"\n"),
3311 cursor
->name
, i
->sc_name
);
3321 lxml_get_single_instance(entity_t
*entity
, xmlNodePtr si
)
3327 pg
= internal_pgroup_find_or_create(entity
, (char *)scf_pg_general
,
3328 (char *)scf_group_framework
);
3330 p
= internal_property_create(SCF_PROPERTY_SINGLE_INSTANCE
,
3331 SCF_TYPE_BOOLEAN
, 1, (uint64_t)1);
3333 r
= internal_attach_property(pg
, p
);
3335 internal_property_free(p
);
3343 * Check to see if the service should allow the upgrade
3344 * process to handle adding of the manifestfiles linkage.
3346 * If the service exists and does not have a manifestfiles
3347 * property group then the upgrade process should handle
3350 * If the service doesn't exist or the service exists
3351 * and has a manifestfiles property group then the import
3352 * process can handle the manifestfiles property group
3355 * This prevents potential cleanup of unaccounted for instances
3356 * in early manifest import due to upgrade process needing
3357 * information that has not yet been supplied by manifests
3358 * that are still located in the /var/svc manifests directory.
3361 lxml_check_upgrade(const char *service
)
3363 scf_handle_t
*h
= NULL
;
3364 scf_scope_t
*sc
= NULL
;
3365 scf_service_t
*svc
= NULL
;
3366 scf_propertygroup_t
*pg
= NULL
;
3367 int rc
= SCF_FAILED
;
3369 if ((h
= scf_handle_create(SCF_VERSION
)) == NULL
||
3370 (sc
= scf_scope_create(h
)) == NULL
||
3371 (svc
= scf_service_create(h
)) == NULL
||
3372 (pg
= scf_pg_create(h
)) == NULL
)
3375 if (scf_handle_bind(h
) != 0)
3378 if (scf_handle_get_scope(h
, SCF_FMRI_LOCAL_SCOPE
, sc
) == -1)
3381 if (scf_scope_get_service(sc
, service
, svc
) != SCF_SUCCESS
) {
3382 if (scf_error() == SCF_ERROR_NOT_FOUND
)
3388 if (scf_service_get_pg(svc
, SCF_PG_MANIFESTFILES
, pg
) != SCF_SUCCESS
)
3394 scf_service_destroy(svc
);
3395 scf_scope_destroy(sc
);
3396 scf_handle_destroy(h
);
3402 * Translate a service element into an internal instance/property tree, added
3405 * If op is SVCCFG_OP_APPLY (i.e., apply a profile), do not allow for
3406 * modification of template data.
3409 lxml_get_service(bundle_t
*bundle
, xmlNodePtr svc
, svccfg_op_t op
)
3420 * Fetch attributes, as appropriate.
3422 s
= internal_service_new((char *)xmlGetProp(svc
,
3423 (xmlChar
*)name_attr
));
3425 version
= xmlGetProp(svc
, (xmlChar
*)version_attr
);
3426 s
->sc_u
.sc_service
.sc_service_version
= atol((const char *)version
);
3429 type
= xmlGetProp(svc
, (xmlChar
*)type_attr
);
3430 s
->sc_u
.sc_service
.sc_service_type
= lxml_xlate_service_type(type
);
3434 * Set the global missing type to false before processing the service
3436 est
->sc_miss_type
= B_FALSE
;
3440 * Now that the service is created create the manifest
3441 * property group and add the property value of the service.
3443 if (lxml_check_upgrade(s
->sc_name
) == SCF_SUCCESS
&&
3444 svc
->doc
->name
!= NULL
&&
3445 bundle
->sc_bundle_type
== SVCCFG_MANIFEST
) {
3446 char *buf
, *base
, *fname
, *bname
;
3450 * Must remove the PKG_INSTALL_ROOT, point to the correct
3451 * directory after install
3453 bname
= uu_zalloc(PATH_MAX
+ 1);
3454 if (realpath(svc
->doc
->name
, bname
) == NULL
) {
3455 uu_die(gettext("Unable to create the real path of the "
3456 "manifest file \"%s\" : %d\n"), svc
->doc
->name
,
3460 base
= getenv("PKG_INSTALL_ROOT");
3461 if (base
!= NULL
&& strncmp(bname
, base
, strlen(base
)) == 0) {
3462 base_sz
= strlen(base
);
3464 fname
= safe_strdup(bname
+ base_sz
);
3467 buf
= mhash_filename_to_propname(svc
->doc
->name
, B_FALSE
);
3469 pg
= internal_pgroup_create_strict(s
, SCF_PG_MANIFESTFILES
,
3470 SCF_GROUP_FRAMEWORK
);
3473 uu_die(gettext("Property group for prop_pattern, "
3474 "\"%s\", already exists in %s\n"),
3475 SCF_PG_MANIFESTFILES
, s
->sc_name
);
3478 p
= internal_property_create(buf
, SCF_TYPE_ASTRING
, 1, fname
);
3480 (void) internal_attach_property(pg
, p
);
3484 * Walk its child elements, as appropriate.
3486 for (cursor
= svc
->xmlChildrenNode
; cursor
!= NULL
;
3487 cursor
= cursor
->next
) {
3488 if (lxml_ignorable_block(cursor
))
3491 e
= lxml_xlate_element(cursor
->name
);
3495 if (lxml_get_instance(s
, cursor
,
3496 bundle
->sc_bundle_type
, op
) != 0)
3500 if (op
== SVCCFG_OP_APPLY
) {
3501 semerr(gettext("Template data for \"%s\" may "
3502 "not be modified in a profile.\n"),
3508 if (lxml_get_template(s
, cursor
) != 0)
3511 case SC_NOTIFICATION_PARAMETERS
:
3512 if (lxml_get_notification_parameters(s
, cursor
) != 0)
3516 (void) lxml_get_entity_stability(s
, cursor
);
3519 (void) lxml_get_dependency(s
, cursor
);
3522 (void) lxml_get_dependent(s
, cursor
);
3525 (void) lxml_get_restarter(s
, cursor
);
3527 case SC_EXEC_METHOD
:
3528 (void) lxml_get_exec_method(s
, cursor
);
3530 case SC_METHOD_CONTEXT
:
3531 (void) lxml_get_entity_method_context(s
, cursor
);
3533 case SC_PROPERTY_GROUP
:
3534 (void) lxml_get_pgroup(s
, cursor
);
3536 case SC_INSTANCE_CREATE_DEFAULT
:
3537 (void) lxml_get_default_instance(s
, cursor
);
3539 case SC_INSTANCE_SINGLE
:
3540 (void) lxml_get_single_instance(s
, cursor
);
3544 "illegal element \"%s\" on service \"%s\"\n"),
3545 cursor
->name
, s
->sc_name
);
3551 * Now that the service has been processed set the missing type
3552 * for the service. So that only the services with missing
3553 * types are processed.
3555 s
->sc_miss_type
= est
->sc_miss_type
;
3556 if (est
->sc_miss_type
)
3557 est
->sc_miss_type
= B_FALSE
;
3559 return (internal_attach_service(bundle
, s
));
3564 lxml_dump(int g
, xmlNodePtr p
)
3567 (void) printf("%d %s\n", g
, p
->name
);
3569 for (p
= p
->xmlChildrenNode
; p
!= NULL
; p
= p
->next
)
3570 lxml_dump(g
+ 1, p
);
3576 lxml_is_known_dtd(const xmlChar
*dtdname
)
3578 if (dtdname
== NULL
||
3579 strcmp(MANIFEST_DTD_PATH
, (const char *)dtdname
) != 0)
3586 lxml_get_bundle(bundle_t
*bundle
, bundle_type_t bundle_type
,
3587 xmlNodePtr subbundle
, svccfg_op_t op
)
3594 * 1. Get bundle attributes.
3596 type
= xmlGetProp(subbundle
, (xmlChar
*)type_attr
);
3597 bundle
->sc_bundle_type
= lxml_xlate_bundle_type(type
);
3598 if (bundle
->sc_bundle_type
!= bundle_type
&&
3599 bundle_type
!= SVCCFG_UNKNOWN_BUNDLE
) {
3600 semerr(gettext("included bundle of different type.\n"));
3607 case SVCCFG_OP_IMPORT
:
3608 if (bundle
->sc_bundle_type
!= SVCCFG_MANIFEST
) {
3609 semerr(gettext("document is not a manifest.\n"));
3613 case SVCCFG_OP_APPLY
:
3614 if (bundle
->sc_bundle_type
!= SVCCFG_PROFILE
) {
3615 semerr(gettext("document is not a profile.\n"));
3619 case SVCCFG_OP_RESTORE
:
3620 if (bundle
->sc_bundle_type
!= SVCCFG_ARCHIVE
) {
3621 semerr(gettext("document is not an archive.\n"));
3627 if (((bundle
->sc_bundle_name
= xmlGetProp(subbundle
,
3628 (xmlChar
*)name_attr
)) == NULL
) || (*bundle
->sc_bundle_name
== 0)) {
3629 semerr(gettext("service bundle lacks name attribute\n"));
3634 * 2. Get services, descend into each one and build state.
3636 for (cursor
= subbundle
->xmlChildrenNode
; cursor
!= NULL
;
3637 cursor
= cursor
->next
) {
3638 if (lxml_ignorable_block(cursor
))
3641 e
= lxml_xlate_element(cursor
->name
);
3647 case SC_SERVICE_BUNDLE
:
3648 if (lxml_get_bundle(bundle
, bundle_type
, cursor
, op
))
3652 if (lxml_get_service(bundle
, cursor
, op
) != 0)
3662 * Load an XML tree from filename and translate it into an internal service
3663 * tree bundle. Require that the bundle be of appropriate type for the
3664 * operation: archive for RESTORE, manifest for IMPORT, profile for APPLY.
3667 lxml_get_bundle_file(bundle_t
*bundle
, const char *filename
, svccfg_op_t op
)
3671 xmlDtdPtr dtd
= NULL
;
3672 xmlValidCtxtPtr vcp
;
3673 boolean_t do_validate
;
3674 char *dtdpath
= NULL
;
3678 * Verify we can read the file before we try to parse it.
3680 if (access(filename
, R_OK
| F_OK
) == -1) {
3681 semerr(gettext("unable to open file: %s\n"), strerror(errno
));
3686 * Until libxml2 addresses DTD-based validation with XInclude, we don't
3687 * validate service profiles (i.e. the apply path).
3689 do_validate
= (op
!= SVCCFG_OP_APPLY
) &&
3690 (getenv("SVCCFG_NOVALIDATE") == NULL
);
3692 dtdpath
= getenv("SVCCFG_DTD");
3694 if (dtdpath
!= NULL
)
3695 xmlLoadExtDtdDefaultValue
= 0;
3697 if ((document
= xmlReadFile(filename
, NULL
, 0)) == NULL
) {
3698 semerr(gettext("couldn't parse document\n"));
3702 document
->name
= safe_strdup(filename
);
3705 * Verify that this is a document type we understand.
3707 if ((dtd
= xmlGetIntSubset(document
)) == NULL
) {
3708 semerr(gettext("document has no DTD\n"));
3710 } else if (dtdpath
== NULL
&& !do_validate
) {
3712 * If apply then setup so that some validation
3713 * for specific elements can be done.
3715 dtdpath
= (char *)document
->intSubset
->SystemID
;
3718 if (!lxml_is_known_dtd(dtd
->SystemID
)) {
3719 semerr(gettext("document DTD unknown; not service bundle?\n"));
3723 if ((cursor
= xmlDocGetRootElement(document
)) == NULL
) {
3724 semerr(gettext("document is empty\n"));
3725 xmlFreeDoc(document
);
3729 if (xmlStrcmp(cursor
->name
, (const xmlChar
*)"service_bundle") != 0) {
3730 semerr(gettext("document is not a service bundle\n"));
3731 xmlFreeDoc(document
);
3736 if (dtdpath
!= NULL
) {
3737 dtd
= xmlParseDTD(NULL
, (xmlChar
*)dtdpath
);
3739 semerr(gettext("Could not parse DTD \"%s\".\n"),
3744 if (document
->extSubset
!= NULL
)
3745 xmlFreeDtd(document
->extSubset
);
3747 document
->extSubset
= dtd
;
3750 if (xmlXIncludeProcessFlags(document
, XML_PARSE_XINCLUDE
) == -1) {
3751 semerr(gettext("couldn't handle XInclude statements "
3757 vcp
= xmlNewValidCtxt();
3759 uu_die(gettext("could not allocate memory"));
3760 vcp
->warning
= xmlParserValidityWarning
;
3761 vcp
->error
= xmlParserValidityError
;
3763 r
= xmlValidateDocument(vcp
, document
);
3765 xmlFreeValidCtxt(vcp
);
3768 semerr(gettext("Document is not valid.\n"));
3769 xmlFreeDoc(document
);
3775 lxml_dump(0, cursor
);
3778 r
= lxml_get_bundle(bundle
, SVCCFG_UNKNOWN_BUNDLE
, cursor
, op
);
3780 xmlFreeDoc(document
);
3786 lxml_inventory(const char *filename
)
3789 uu_list_walk_t
*svcs
, *insts
;
3790 entity_t
*svc
, *inst
;
3792 b
= internal_bundle_new();
3794 if (lxml_get_bundle_file(b
, filename
, SVCCFG_OP_IMPORT
) != 0) {
3795 internal_bundle_free(b
);
3799 svcs
= uu_list_walk_start(b
->sc_bundle_services
, 0);
3801 uu_die(gettext("Couldn't walk services"));
3803 while ((svc
= uu_list_walk_next(svcs
)) != NULL
) {
3804 uu_list_t
*inst_list
;
3806 inst_list
= svc
->sc_u
.sc_service
.sc_service_instances
;
3807 insts
= uu_list_walk_start(inst_list
, 0);
3809 uu_die(gettext("Couldn't walk instances"));
3811 while ((inst
= uu_list_walk_next(insts
)) != NULL
)
3812 (void) printf("svc:/%s:%s\n", svc
->sc_name
,
3815 uu_list_walk_end(insts
);
3818 uu_list_walk_end(svcs
);
3820 svcs
= uu_list_walk_start(b
->sc_bundle_services
, 0);
3821 while ((svc
= uu_list_walk_next(svcs
)) != NULL
) {
3822 (void) fputs("svc:/", stdout
);
3823 (void) puts(svc
->sc_name
);
3825 uu_list_walk_end(svcs
);
3827 internal_bundle_free(b
);