/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
*/
/*
* XML document manipulation routines
*
* These routines provide translation to and from the internal representation to
* XML. Directionally-oriented verbs are with respect to the external source,
* so lxml_get_service() fetches a service from the XML file into the
* internal representation.
*/
#include <libxml/xinclude.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <libintl.h>
#include <libscf.h>
#include <libscf_priv.h>
#include <libuutil.h>
#include <sasl/saslutil.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <unistd.h>
#include "manifest_hash.h"
#include "svccfg.h"
#include "notify_params.h"
/*
* snprintf(3C) format strings for constructing property names that include
* the locale designation. Use %s to indicate where the locale should go.
*
* The VALUE_* symbols are an exception. The firs %s will be replaced with
* "value_". The second %s will be replaced by the name of the value and
* %%s will be replaced by the locale designation. These formats are
* processed twice by snprintf(3C). The first time captures the value name
* and the second time captures the locale.
*/
/* Attribute names */
/* Attribute values */
const char * const true = "true";
const char * const false = "false";
/*
* The following list must be kept in the same order as that of
* element_t array
*/
static const char *lxml_elements[] = {
"astring_list", /* SC_ASTRING */
"boolean_list", /* SC_BOOLEAN */
"cardinality", /* SC_CARDINALITY */
"choices", /* SC_CHOICES */
"common_name", /* SC_COMMON_NAME */
"constraints", /* SC_CONSTRAINTS */
"count_list", /* SC_COUNT */
"create_default_instance", /* SC_INSTANCE_CREATE_DEFAULT */
"dependency", /* SC_DEPENDENCY */
"dependent", /* SC_DEPENDENT */
"description", /* SC_DESCRIPTION */
"doc_link", /* SC_DOC_LINK */
"documentation", /* SC_DOCUMENTATION */
"enabled", /* SC_ENABLED */
"event", /* SC_EVENT */
"exec_method", /* SC_EXEC_METHOD */
"fmri_list", /* SC_FMRI */
"host_list", /* SC_HOST */
"hostname_list", /* SC_HOSTNAME */
"include_values", /* SC_INCLUDE_VALUES */
"instance", /* SC_INSTANCE */
"integer_list", /* SC_INTEGER */
"internal_separators", /* SC_INTERNAL_SEPARATORS */
"loctext", /* SC_LOCTEXT */
"manpage", /* SC_MANPAGE */
"method_context", /* SC_METHOD_CONTEXT */
"method_credential", /* SC_METHOD_CREDENTIAL */
"method_profile", /* SC_METHOD_PROFILE */
"method_environment", /* SC_METHOD_ENVIRONMENT */
"envvar", /* SC_METHOD_ENVVAR */
"net_address_list", /* SC_NET_ADDR */
"net_address_v4_list", /* SC_NET_ADDR_V4 */
"net_address_v6_list", /* SC_NET_ADDR_V6 */
"notification_parameters", /* SC_NOTIFICATION_PARAMETERS */
"opaque_list", /* SC_OPAQUE */
"parameter", /* SC_PARAMETER */
"paramval", /* SC_PARAMVAL */
"pg_pattern", /* SC_PG_PATTERN */
"prop_pattern", /* SC_PROP_PATTERN */
"property", /* SC_PROPERTY */
"property_group", /* SC_PROPERTY_GROUP */
"propval", /* SC_PROPVAL */
"range", /* SC_RANGE */
"restarter", /* SC_RESTARTER */
"service", /* SC_SERVICE */
"service_bundle", /* SC_SERVICE_BUNDLE */
"service_fmri", /* SC_SERVICE_FMRI */
"single_instance", /* SC_INSTANCE_SINGLE */
"stability", /* SC_STABILITY */
"template", /* SC_TEMPLATE */
"time_list", /* SC_TIME */
"type", /* SC_TYPE */
"units", /* SC_UNITS */
"uri_list", /* SC_URI */
"ustring_list", /* SC_USTRING */
"value", /* SC_VALUE */
"value_node", /* SC_VALUE_NODE */
"values", /* SC_VALUES */
"visibility", /* SC_VISIBILITY */
"xi:fallback", /* SC_XI_FALLBACK */
"xi:include" /* SC_XI_INCLUDE */
};
/*
* The following list must be kept in the same order as that of
* element_t array
*/
static const char *lxml_prop_types[] = {
"astring", /* SC_ASTRING */
"boolean", /* SC_BOOLEAN */
"", /* SC_CARDINALITY */
"", /* SC_CHOICES */
"", /* SC_COMMON_NAME */
"", /* SC_CONSTRAINTS */
"count", /* SC_COUNT */
"", /* SC_INSTANCE_CREATE_DEFAULT */
"", /* SC_DEPENDENCY */
"", /* SC_DEPENDENT */
"", /* SC_DESCRIPTION */
"", /* SC_DOC_LINK */
"", /* SC_DOCUMENTATION */
"", /* SC_ENABLED */
"", /* SC_EVENT */
"", /* SC_EXEC_METHOD */
"fmri", /* SC_FMRI */
"host", /* SC_HOST */
"hostname", /* SC_HOSTNAME */
"", /* SC_INCLUDE_VALUES */
"", /* SC_INSTANCE */
"integer", /* SC_INTEGER */
"", /* SC_INTERNAL_SEPARATORS */
"", /* SC_LOCTEXT */
"", /* SC_MANPAGE */
"", /* SC_METHOD_CONTEXT */
"", /* SC_METHOD_CREDENTIAL */
"", /* SC_METHOD_PROFILE */
"", /* SC_METHOD_ENVIRONMENT */
"", /* SC_METHOD_ENVVAR */
"net_address", /* SC_NET_ADDR */
"net_address_v4", /* SC_NET_ADDR_V4 */
"net_address_v6", /* SC_NET_ADDR_V6 */
"", /* SC_NOTIFICATION_PARAMETERS */
"opaque", /* SC_OPAQUE */
"", /* SC_PARAMETER */
"", /* SC_PARAMVAL */
"", /* SC_PG_PATTERN */
"", /* SC_PROP_PATTERN */
"", /* SC_PROPERTY */
"", /* SC_PROPERTY_GROUP */
"", /* SC_PROPVAL */
"", /* SC_RANGE */
"", /* SC_RESTARTER */
"", /* SC_SERVICE */
"", /* SC_SERVICE_BUNDLE */
"", /* SC_SERVICE_FMRI */
"", /* SC_INSTANCE_SINGLE */
"", /* SC_STABILITY */
"", /* SC_TEMPLATE */
"time", /* SC_TIME */
"", /* SC_TYPE */
"", /* SC_UNITS */
"uri", /* SC_URI */
"ustring", /* SC_USTRING */
"", /* SC_VALUE */
"", /* SC_VALUE_NODE */
"", /* SC_VALUES */
"", /* SC_VISIBILITY */
"", /* SC_XI_FALLBACK */
"" /* SC_XI_INCLUDE */
};
int
{
/*
* DTD validation, with line numbers.
*/
(void) xmlLineNumbersDefault(1);
}
return (0);
}
static bundle_type_t
{
return (SVCCFG_MANIFEST);
return (SVCCFG_PROFILE);
return (SVCCFG_ARCHIVE);
return (SVCCFG_UNKNOWN_BUNDLE);
}
static service_type_t
{
return (SVCCFG_SERVICE);
return (SVCCFG_RESTARTER);
return (SVCCFG_MILESTONE);
return (SVCCFG_UNKNOWN_SERVICE);
}
static element_t
{
int i;
for (i = 0; i < sizeof (lxml_elements) / sizeof (char *); i++)
return ((element_t)i);
return ((element_t)-1);
}
static uint_t
{
return (1);
return (0);
/*NOTREACHED*/
}
static scf_type_t
{
switch (type) {
case SC_ASTRING: return (SCF_TYPE_ASTRING);
case SC_BOOLEAN: return (SCF_TYPE_BOOLEAN);
case SC_COUNT: return (SCF_TYPE_COUNT);
case SC_FMRI: return (SCF_TYPE_FMRI);
case SC_HOST: return (SCF_TYPE_HOST);
case SC_HOSTNAME: return (SCF_TYPE_HOSTNAME);
case SC_INTEGER: return (SCF_TYPE_INTEGER);
case SC_NET_ADDR: return (SCF_TYPE_NET_ADDR);
case SC_NET_ADDR_V4: return (SCF_TYPE_NET_ADDR_V4);
case SC_NET_ADDR_V6: return (SCF_TYPE_NET_ADDR_V6);
case SC_OPAQUE: return (SCF_TYPE_OPAQUE);
case SC_TIME: return (SCF_TYPE_TIME);
case SC_URI: return (SCF_TYPE_URI);
case SC_USTRING: return (SCF_TYPE_USTRING);
default:
}
/* NOTREACHED */
}
static element_t
{
switch (type) {
case SCF_TYPE_ASTRING: return (SC_ASTRING);
case SCF_TYPE_BOOLEAN: return (SC_BOOLEAN);
case SCF_TYPE_COUNT: return (SC_COUNT);
case SCF_TYPE_FMRI: return (SC_FMRI);
case SCF_TYPE_HOST: return (SC_HOST);
case SCF_TYPE_HOSTNAME: return (SC_HOSTNAME);
case SCF_TYPE_INTEGER: return (SC_INTEGER);
case SCF_TYPE_NET_ADDR: return (SC_NET_ADDR);
case SCF_TYPE_NET_ADDR_V4: return (SC_NET_ADDR_V4);
case SCF_TYPE_NET_ADDR_V6: return (SC_NET_ADDR_V6);
case SCF_TYPE_OPAQUE: return (SC_OPAQUE);
case SCF_TYPE_TIME: return (SC_TIME);
case SCF_TYPE_URI: return (SC_URI);
case SCF_TYPE_USTRING: return (SC_USTRING);
default:
}
/* NOTREACHED */
}
/*
* Create a SCF_TYPE_BOOLEAN property name pname and attach it to the
* property group at pgrp. The value of the property will be set from the
* attribute named attr. attr must have a value of 0, 1, true or false.
*
* Zero is returned on success. An error is indicated by -1. It indicates
* that either the attribute had an invalid value or that we could not
* attach the property to pgrp. The attribute should not have an invalid
* value if the DTD is correctly written.
*/
static int
const char *attr)
{
uint64_t bool;
property_t *p;
int r;
return (0);
bool = 0;
bool = 1;
} else {
return (-1);
}
r = internal_attach_property(pgrp, p);
if (r != 0)
return (r);
}
static int
xmlNodePtr n, const char *attr)
{
property_t *p;
int r;
r = internal_attach_property(pgrp, p);
if (r != 0)
return (r);
}
static int
{
property_t *p;
int r;
/*
* A missing attribute is considered to be a
* success in this function, because many of the
* attributes are optional. Missing non-optional
* attributes will be detected later when template
* validation is done.
*/
return (0);
} else {
}
}
r = internal_attach_property(pgrp, p);
if (r != 0)
return (r);
}
static int
{
}
static void
{
}
}
vcp = xmlNewValidCtxt();
}
static int
{
NULL)
return (-1);
NULL)
return (-1);
}
static void
{
}
/*
* Take a value_t structure and a type and value. Based on the type
* ensure that the value is of that type. If so store the value in
* the correct location of the value_t structure.
*
* If the value is NULL, the value_t structure will have been created
* and the value would have ultimately been stored as a string value
* but at the time the type was unknown. Now the type should be known
* so take the type and value from value_t and validate and store
* the value correctly if the value is of the stated type.
*/
void
{
char *endptr;
int fov = 0;
fov = 1;
}
switch (type) {
case SC_COUNT:
/*
* Although an SC_COUNT represents a uint64_t the use
* of a negative value is acceptable due to the usage
* established by inetd(1M).
*/
errno = 0;
"%s (%s)\n"), (char *)value,
gettext("Illegal character"));
break;
case SC_INTEGER:
errno = 0;
"%s (%s)\n"), (char *)value,
break;
case SC_OPAQUE:
case SC_HOST:
case SC_HOSTNAME:
case SC_NET_ADDR:
case SC_NET_ADDR_V4:
case SC_NET_ADDR_V6:
case SC_FMRI:
case SC_URI:
case SC_TIME:
case SC_ASTRING:
case SC_USTRING:
"%s (%s)\n"), (char *)value,
gettext("Illegal format"));
v->sc_free = lxml_free_str;
break;
case SC_BOOLEAN:
break;
default:
break;
}
/* Free the old value */
}
static value_t *
{
value_t *v;
v = internal_value_new();
return (v);
}
static int
{
value_t *v;
if (lxml_ignorable_block(cursor))
continue;
case SC_VALUE_NODE:
break;
default:
break;
}
}
return (0);
}
static int
{
property_t *p;
element_t r;
value_t *v;
p = internal_property_new();
for (r = 0;
r < sizeof (lxml_prop_types) / sizeof (char *); ++r) {
(const xmlChar *)lxml_prop_types[r]) == 0)
break;
}
if (r >= sizeof (lxml_prop_types) / sizeof (char *))
p->sc_property_name);
p->sc_value_type = lxml_element_to_type(r);
} else if (op == SVCCFG_OP_APPLY) {
/*
* Store the property type as invalid, and the value
* as an ASTRING and let the bundle apply code validate
*/
r = SC_ASTRING;
} else {
}
v = lxml_make_value(r, val);
internal_attach_value(p, v);
return (internal_attach_property(pgrp, p));
}
static int
{
property_t *p;
element_t r;
p = internal_property_new();
for (r = 0;
r < sizeof (lxml_prop_types) / sizeof (char *); r++) {
(const xmlChar *)lxml_prop_types[r]) == 0)
break;
}
if (r >= sizeof (lxml_prop_types) / sizeof (char *))
p->sc_property_name);
p->sc_value_type = lxml_element_to_type(r);
} else if (op == SVCCFG_OP_APPLY) {
/*
* Store the property type as invalid, and let the bundle apply
*/
} else {
p->sc_property_name);
}
if (lxml_ignorable_block(cursor))
continue;
case SC_ASTRING:
case SC_BOOLEAN:
case SC_COUNT:
case SC_FMRI:
case SC_HOST:
case SC_HOSTNAME:
case SC_INTEGER:
case SC_NET_ADDR:
case SC_NET_ADDR_V4:
case SC_NET_ADDR_V6:
case SC_OPAQUE:
case SC_TIME:
case SC_URI:
case SC_USTRING:
/*
* If the type is invalid then this is an apply
* operation and the type can be taken from the
* value list.
*/
if (p->sc_value_type == SCF_TYPE_INVALID) {
p->sc_value_type = lxml_element_to_type(r);
xmlChar *)lxml_prop_types[r]);
} else if (strcmp(lxml_prop_types[r],
(const char *)type) != 0) {
"type-to-list mismatch\n"),
p->sc_property_name);
}
(void) lxml_get_value(p, r, cursor);
break;
default:
break;
}
}
return (internal_attach_property(pgrp, p));
}
static int
{
}
/*
* Property groups can go on any of a service, an instance, or a template.
*/
static int
{
/*
* property group attributes:
* name: string
* type: string | framework | application
*/
/*
* Walk the children of this lxml_elements, which are a stability
* element, property elements, or propval elements.
*/
if (lxml_ignorable_block(cursor))
continue;
case SC_STABILITY:
break;
case SC_PROPERTY:
break;
case SC_PROPVAL:
break;
default:
abort();
break;
}
}
return (0);
}
/*
* Dependency groups, execution methods can go on either a service or an
* instance.
*/
static int
{
property_t *p;
if (internal_attach_property(pg, p) != 0)
return (-1);
}
static int
{
property_t *p;
1, (uint64_t)0);
if (internal_attach_property(pg, p) != 0)
return (-1);
return (-1);
return (-1);
return (-1);
return (-1);
return (-1);
return (0);
}
static char *
{
char *name;
char *value;
char *ret;
"\"%s\".\n"), name);
"\"%s\"; \"SMF_\" prefix is reserved.\n"), name);
return (ret);
}
static int
{
property_t *p;
SCF_TYPE_ASTRING, 0);
char *tmp;
if (lxml_ignorable_block(cursor))
continue;
"method environment for \"%s\"\n"),
val = internal_value_new();
internal_attach_value(p, val);
}
if (internal_attach_property(pg, p) != 0) {
return (-1);
}
return (0);
}
static int
{
return (-1);
return (-1);
return (-1);
return (-1);
if (lxml_ignorable_block(cursor))
continue;
case SC_METHOD_CREDENTIAL:
break;
case SC_METHOD_PROFILE:
break;
case SC_METHOD_ENVIRONMENT:
break;
default:
"context\n"), (char *)cursor);
break;
}
}
return (0);
}
static int
{
(char *)scf_group_framework);
}
static int
{
property_t *p;
int r = 0;
(char *)SCF_GROUP_METHOD);
emeth, "exec") != 0)
return (-1);
char *endptr;
/*
* Although an SC_COUNT represents a uint64_t the use
* of a negative value is acceptable due to the usage
* established by inetd(1M).
*/
errno = 0;
"timeout_seconds (%s)\n"),
gettext("Illegal character"));
r = internal_attach_property(pg, p);
}
if (r != 0)
return (-1);
/*
* There is a possibility that a method context also exists, in which
* case the following attributes are defined: project, resource_pool,
* working_directory, profile, user, group, privileges,
* limit_privileges, security_flags
*/
if (lxml_ignorable_block(cursor))
continue;
case SC_STABILITY:
return (-1);
break;
case SC_METHOD_CONTEXT:
break;
case SC_PROPVAL:
break;
case SC_PROPERTY:
break;
default:
pg->sc_pgroup_name);
break;
}
}
return (0);
}
static int
{
property_t *p;
/*
* dependency attributes:
* name: string
* grouping: require_all | require_any | exclude_all | optional_all
* reset_on: string (error | restart | refresh | none)
* type: service / path /host
*/
(char *)SCF_GROUP_DEPENDENCY);
dependency, type_attr) != 0)
return (-1);
return (-1);
dependency, "grouping") != 0)
return (-1);
if (internal_attach_property(pg, p) != 0)
return (-1);
value_t *v;
if (lxml_ignorable_block(cursor))
continue;
case SC_STABILITY:
return (-1);
break;
case SC_SERVICE_FMRI:
(char *)value) != 0)
"for %s (%s)\n"), (char *)value,
(scf_error()) ?
scf_strerror(scf_error()) :
gettext("Illegal format"));
v = internal_value_new();
v->sc_type = SCF_TYPE_FMRI;
internal_attach_value(p, v);
}
break;
case SC_PROPVAL:
break;
case SC_PROPERTY:
break;
default:
break;
}
}
return (0);
}
/*
* Dependents are hairy. They should cause a dependency pg to be created in
* another service, but we can't do that here; we'll have to wait until the
* import routines. So for now we'll add the dependency group that should go
* in the other service to the entity's dependent list.
*/
static int
{
property_t *p;
xmlNodePtr n;
char *myfmri;
return (-1);
}
pg = internal_pgroup_new();
return (-1);
}
break;
return (-1);
dependent, "grouping") != 0)
return (-1);
} else {
}
myfmri);
if (internal_attach_property(pg, p) != 0)
return (-1);
/* Create a property to serve as a do-not-export flag. */
(uint64_t)1);
if (internal_attach_property(pg, p) != 0)
return (-1);
if (lxml_ignorable_block(n))
continue;
switch (lxml_xlate_element(n->name)) {
case SC_STABILITY:
if (new_str_prop_from_attr(pg,
value_attr) != 0)
return (-1);
break;
case SC_PROPVAL:
(void) lxml_get_propval(pg, n);
break;
case SC_PROPERTY:
(void) lxml_get_property(pg, n);
break;
default:
}
}
/* Go back and fill in defaults. */
if (internal_attach_property(pg, p) != 0)
return (-1);
}
(char *)scf_group_framework);
if (internal_attach_property(pg, p) != 0)
return (-1);
return (0);
}
static int
{
property_t *p;
(*stabval == 0)) {
}
(char *)scf_group_framework);
return (internal_attach_property(pg, p));
}
static int
{
property_t *p;
int r;
/*
* Go find child. Child is a service_fmri element. value attribute
* contains restarter FMRI.
*/
(char *)scf_group_framework);
/*
* Walk its child elements, as appropriate.
*/
if (lxml_ignorable_block(cursor))
continue;
case SC_SERVICE_FMRI:
break;
default:
break;
}
}
r = internal_attach_property(pg, p);
if (r != 0) {
return (-1);
}
return (0);
}
static void
{
property_t *p;
char *value;
char *prop;
(void) internal_attach_property(pgrp, p);
}
static void
{
property_t *p = internal_property_new();
(void) internal_attach_property(pgrp, p);
}
static void
{
property_t *p;
if (lxml_ignorable_block(cursor))
continue;
"attribute name missing in sub-element of type\n"));
case SC_PARAMETER:
break;
case SC_PARAMVAL:
break;
default:
}
}
active_val = 1;
else
active_val = 0;
(void) internal_attach_property(pgrp, p);
}
static void
{
if (lxml_ignorable_block(cursor))
continue;
case SC_EVENT:
continue;
case SC_TYPE:
break;
default:
}
}
}
static int
{
char **p;
int count;
int r = -1;
if (lxml_ignorable_block(cursor))
continue;
xmlChar *s;
count++;
if (count > 1)
"event in a notification parameter\n"));
xmlFree(s);
}
}
case INVALID_TOKENS:
/*NOTREACHED*/
case MIXED_TOKENS:
goto out;
case FMA_TOKENS:
/* make sure this is SCF_NOTIFY_PARAMS_INST */
"Non-SMF transition evenst must go to %s\n"),
goto out;
}
for (p = pgs; *p; ++p) {
SCF_NOTIFY_PG_POSTFIX) >= sz)
*p);
}
default: /* smf state transition tokens */
"Can't set events for global service\n"));
goto out;
}
if (t & tset) {
}
if ((t << 16) & tset) {
np);
}
}
}
r = 0;
out:
return (r);
}
/*
* Add a property containing the localized text from the manifest. The
* property is added to the property group at pg. The name of the created
* property is based on the format at pn_format. This is an snprintf(3C)
* format containing a single %s conversion specification. At conversion
* time, the %s is replaced by the locale designation.
*
* source is the source element and it is only used for error messages.
*/
static int
{
int extra;
property_t *p;
char *prop_name;
int r;
(*val == 0)) {
}
}
_scf_sanitize_locale((char *)val);
"%s in %s\n"),
}
break;
}
}
}
/*
* Remove leading and trailing whitespace.
*/
;
;
stripped);
r = internal_attach_property(pg, p);
if (r != 0) {
}
return (r);
}
/*
* This function processes all loctext elements in the current XML element
* designated by container. A property is created for each loctext element
* and added to the property group at pg. The name of the property is
* derived from the loctext language designation using the format at
* pn_format. pn_format should be an snprintf format string containing one
* %s which is replaced by the language designation.
*
* The function returns 0 on success and -1 if it is unable to attach the
* newly created property to pg.
*/
static int
{
/*
* Iterate through one or more loctext elements. The locale is
* used to generate the property name; the contents are the ustring
* value for the property.
*/
if (lxml_ignorable_block(cursor))
continue;
case SC_LOCTEXT:
source))
return (-1);
break;
default:
break;
}
}
return (0);
}
/*
* Obtain the specified cardinality attribute and place it in a property
* named prop_name. The converted attribute is placed at *value, and the
* newly created property is returned to propp. NULL is returned to propp
* if the attribute is not provided in the manifest.
*
* 0 is returned upon success, and -1 indicates that the manifest contained
* an invalid cardinality value.
*/
static int
property_t **propp)
{
char *c;
property_t *p;
char *endptr;
return (0);
if (*val == 0) {
return (0);
}
/*
* Make sure that the string at val doesn't have a leading minus
* sign. The strtoull() call below does not catch this problem.
*/
for (c = (char *)val; *c != 0; c++) {
if (isspace(*c))
continue;
if (isdigit(*c))
break;
"attribute of the %s element in %s.\n"), *c,
return (-1);
}
errno = 0;
"attribute of the %s element in %s.\n"), (char *)val,
return (-1);
}
/* Value is valid. Create the property. */
*propp = p;
return (0);
}
/*
* The cardinality is specified by two attributes max and min at cursor.
* Both are optional, but if present they must be unsigned integers.
*/
static int
{
int min_attached = 0;
int r;
if (r != 0)
return (r);
compare = 0;
if (r != 0)
goto errout;
goto errout;
}
}
/* Attach the properties to the property group. */
if (min_prop) {
min_attached = 1;
} else {
goto errout;
}
}
if (max_prop) {
if (min_attached)
goto errout;
}
}
return (0);
if (min_prop)
if (max_prop)
return (-1);
}
/*
* Get the common_name which is present as localized text at common_name in
* the manifest. The common_name is stored as the value of a property in
* the property group whose name is SCF_PG_TM_COMMON_NAME and type is
* SCF_GROUP_TEMPLATE. This property group will be created in service if
* it is not already there.
*/
static int
{
/*
* Create the property group, if absent.
*/
"common_name"));
}
/*
* Get the description which is present as localized text at description in
* the manifest. The description is stored as the value of a property in
* the property group whose name is SCF_PG_TM_DESCRIPTION and type is
* SCF_GROUP_TEMPLATE. This property group will be created in service if
* it is not already there.
*/
static int
{
/*
* Create the property group, if absent.
*/
LOCALE_ONLY_FMT, "description"));
}
static char *
{
return (NULL);
if (len > max_scf_name_len) {
/* Use the first half and the second half. */
}
/*
* Translate non-property characters to '_'.
*/
*cp = '_';
}
return (out);
}
/*
* If *p is NULL, astring_prop_value() first creates a property with the
* name specified in prop_name. The address of the newly created property
* is placed in *p.
*
* In either case, newly created property or existing property, a new
* SCF_TYPE_ASTRING value will created and attached to the property at *p.
* The value of the newly created property is prop_value.
*
* free_flag is used to indicate whether or not the memory at prop_value
* should be freed when the property is freed by a call to
* internal_property_free().
*/
static void
{
value_t *v;
if (*p == NULL) {
/* Create the property */
*p = internal_property_new();
(*p)->sc_property_name = (char *)prop_name;
(*p)->sc_value_type = SCF_TYPE_ASTRING;
}
/* Add the property value to the property's list of values. */
v = internal_value_new();
v->sc_type = SCF_TYPE_ASTRING;
v->sc_free = lxml_free_str;
internal_attach_value(*p, v);
}
/*
* If p points to a null pointer, create an internal_separators property
* saving the address at p. For each character at seps create a property
* value and attach it to the property at p.
*/
static void
{
value_t *v;
if (*p == NULL) {
*p = internal_property_new();
(*p)->sc_property_name =
(char *)SCF_PROPERTY_INTERNAL_SEPARATORS;
(*p)->sc_value_type = SCF_TYPE_ASTRING;
}
/* Add the values to the property's list. */
v = internal_value_new();
v->sc_type = (*p)->sc_value_type;
v->sc_free = lxml_free_str;
internal_attach_value(*p, v);
}
}
/*
* Create an internal_separators property and attach it to the property
* group at pg. The separator characters are provided in the text nodes
* that are the children of seps. Each separator character is stored as a
* property value in the internal_separators property.
*/
static int
{
int r;
}
}
return (-1);
}
if (r != 0)
return (r);
}
static int
{
char *pgname;
char *name;
/*
* Fetch title and section attributes, convert to something sanitized,
* and create property group.
*/
return (-1);
return (-1);
}
/* Find existing property group with underscore separators */
} else {
/* Rename property group */
}
/*
* Each attribute is an astring property within the group.
*/
return (-1);
return (0);
}
static int
{
char *pgname;
/*
* Fetch name attribute, convert name to something sanitized, and create
* property group.
*/
return (-1);
(const char *)name);
(char *)SCF_GROUP_TEMPLATE);
/*
* Each attribute is an astring property within the group.
*/
return (-1);
return (0);
}
static int
{
if (lxml_ignorable_block(cursor))
continue;
case SC_MANPAGE:
break;
case SC_DOC_LINK:
break;
default:
"for service \"%s\"\n"),
}
}
return (0);
}
static int
{
return (-1);
}
return (-1);
}
required_attr) != 0)
return (-1);
return (0);
}
static int
{
property_t *p;
int r = 0;
char *type;
/* Get the type attribute of the include_values element. */
}
/* Add the type to the values of the prop_name property. */
if (p == NULL)
if (attach_to_pg == B_TRUE) {
r = internal_attach_property(pg, p);
if (r != 0)
}
return (r);
}
#define RC_MIN 0
/*
* Verify that the strings at min and max are valid numeric strings. Also
* verify that max is numerically >= min.
*
* 0 is returned if the range is valid, and -1 is returned if it is not.
*/
static int
{
char *c;
int i;
int is_signed = 0;
int inverted = 0;
/* See if the range is signed. */
c = strings[i];
while (isspace(*c)) {
c++;
}
if (*c == '-')
is_signed = 1;
}
/* Attempt to convert the strings. */
for (i = 0; i < RC_COUNT; i++) {
errno = 0;
if (is_signed) {
} else {
}
/* Conversion failed. */
"element in service %s.\n"), limit[i],
}
}
/* Make sure that min is <= max */
if (is_signed) {
inverted = 1;
} else {
inverted = 1;
}
if (inverted != 0) {
return (-1);
}
return (0);
}
/*
* This, function creates a property named prop_name. The range element
* should have two attributes -- min and max. The property value then
* becomes the concatenation of their value separated by a comma. The
* property is then attached to the property group at pg.
*
* If pg already contains a property with a name of prop_name, it is only
* necessary to create a new value and attach it to the existing property.
*/
static int
const char *prop_name)
{
char *max;
char *min;
property_t *p;
char *prop_value;
int r = 0;
/* Get max and min from the XML description. */
}
}
return (-1);
}
/* Property value is concatenation of min and max. */
max_scf_value_len + 1) {
}
/*
* If necessary create the property and attach it to the property
* group.
*/
if (p == NULL)
if (attach_to_pg == B_TRUE) {
r = internal_attach_property(pg, p);
if (r != 0) {
}
}
return (r);
}
/*
* Determine how many plain characters are represented by count Base32
* encoded characters. 5 plain text characters are converted to 8 Base32
* characters.
*/
static size_t
{
}
/*
* The value element contains 0 or 1 common_name element followed by 0 or 1
* description element. It also has a required attribute called "name".
* The common_name and description are stored as property values in pg.
* The property names are:
* value_<name>_common_name_<lang>
* value_<name>_description_<lang>
*
* The <name> portion of the preceeding proper names requires more
* explanation. Ideally it would just the name attribute of this value
* element. Unfortunately, the name attribute can contain characters that
* are not legal in a property name. Thus, we base 32 encode the name
* attribute and use that for <name>.
*
* There are cases where the caller needs to know the name, so it is
* returned through the name_value pointer if it is not NULL.
*
* Parameters:
* service - Information about the service that is being
* processed. This function only uses this parameter
* for producing error messages.
*
* pg - The property group to receive the newly created
* properties.
*
* value - Pointer to the value element in the XML tree.
*
* name_value - Address to receive the value of the name attribute.
* The caller must free the memory.
*/
static int
char **name_value)
{
char *common_name_fmt;
char *description_fmt;
char *value_name;
int r = 0;
/*
* Get the value of our name attribute, so that we can use it to
* construct property names.
*/
/* The value name must be present, but it can be empty. */
if (value_name == NULL) {
}
/*
* The value_name may contain characters that are not valid in in a
* property name. So we will encode value_name and then use the
* encoded value in the property name.
*/
"too long for value \"%s\" in the %s service.\n"),
}
"%u characters too long for %s in service %s\n"),
}
"%u characters too long for %s in service %s\n"),
}
if (lxml_ignorable_block(cursor))
continue;
case SC_COMMON_NAME:
break;
case SC_DESCRIPTION:
break;
default:
}
if (r != 0)
break;
}
if (r == 0) {
}
return (r);
}
static int
{
char *name_value;
int r = 0;
if (lxml_ignorable_block(cursor))
continue;
case SC_INCLUDE_VALUES:
break;
case SC_RANGE:
if (r != 0)
goto out;
break;
case SC_VALUE:
&name_value);
if (r == 0) {
/*
* There is no need to free the memory
* associated with name_value, because the
* property value will end up pointing to
* the memory.
*/
B_TRUE);
} else {
goto out;
}
break;
default:
}
}
out:
/* Attach the name property if we created one. */
}
}
return (r);
}
static int
{
char *name_value;
int r = 0;
if (lxml_ignorable_block(cursor))
continue;
case SC_RANGE:
if (r != 0)
goto out;
break;
case SC_VALUE:
&name_value);
if (r == 0) {
/*
* There is no need to free the memory
* associated with name_value, because the
* property value will end up pointing to
* the memory.
*/
B_TRUE);
} else {
goto out;
}
break;
default:
}
}
out:
/* Attach the name property if we created one. */
}
}
return (r);
}
/*
* The values element contains one or more value elements.
*/
static int
{
char *name_value;
int r = 0;
if (lxml_ignorable_block(cursor))
continue;
}
if (r == 0) {
/*
* There is no need to free the memory
* associated with name_value, because the
* property value will end up pointing to
* the memory.
*/
B_TRUE);
}
}
/* Attach the name property if we created one. */
}
}
return (r);
}
/*
* This function processes a prop_pattern element within a pg_pattern XML
* element. First it creates a property group to hold the prop_pattern
* information. The name of this property group is the concatenation of:
* - SCF_PG_TM_PROP_PATTERN_PREFIX
* - The unique part of the property group name of the enclosing
* pg_pattern. The property group name of the enclosing pg_pattern
* is passed to us in pgpat_name. The unique part, is the part
* following SCF_PG_TM_PG_PATTERN_PREFIX.
* - The name of this prop_pattern element.
*
* After creating the property group, the prop_pattern attributes are saved
* as properties in the PG. Finally, the prop_pattern elements are
* processed and added to the PG.
*/
static int
const char *pgpat_name)
{
int extra;
property_t *p;
char *pg_name;
int r;
const char *unique;
value_t *v;
/* Find the unique part of the pg_pattern property group name. */
/*
* We need to get the value of the name attribute first. The
* prop_pattern name as well as the name of the enclosing
* pg_pattern both constitute part of the name of the property
* group that we will create.
*/
return (-1);
}
if (uu_check_name((const char *)prop_pattern_name,
UU_NAME_DOMAIN) != 0) {
return (-1);
}
"characters too long\n"), (char *)prop_pattern_name,
}
/*
* Create the property group, the property referencing the pg_pattern
* name, and add the prop_pattern attributes to the property group.
*/
"already exists in %s\n"), prop_pattern_name,
}
/*
* Unfortunately, internal_property_create() does not set the free
* function for the value, so we'll set it now.
*/
v = uu_list_first(p->sc_property_values);
v->sc_free = lxml_free_str;
if (internal_attach_property(pg, p) != 0)
if (r != 0)
goto out;
/*
* Now process the elements of prop_pattern
*/
if (lxml_ignorable_block(cursor))
continue;
case SC_CARDINALITY:
if (r != 0)
goto out;
break;
case SC_CHOICES:
if (r != 0)
goto out;
break;
case SC_COMMON_NAME:
break;
case SC_CONSTRAINTS:
if (r != 0)
goto out;
break;
case SC_DESCRIPTION:
break;
case SC_INTERNAL_SEPARATORS:
if (r != 0)
goto out;
break;
case SC_UNITS:
UNITS_FMT, "units");
break;
case SC_VALUES:
break;
case SC_VISIBILITY:
/*
* The visibility element is empty, so we only need
* to proccess the value attribute.
*/
(void) new_str_prop_from_attr(pg,
cursor, value_attr);
break;
default:
}
}
out:
return (r);
}
/*
* Get the pg_pattern attributes and save them as properties in the
* property group at pg. The pg_pattern element accepts four attributes --
* name, type, required and target.
*/
static int
{
return (-1);
}
return (-1);
}
return (-1);
}
required_attr) != 0)
return (-1);
return (0);
}
/*
* There are several restrictions on the pg_pattern attributes that cannot
* be specifed in the service bundle DTD. This function verifies that
* those restrictions have been satisfied. The restrictions are:
*
* - The target attribute may have a value of "instance" only when the
* template block is in a service declaration.
*
* - The target attribute may have a value of "delegate" only when the
* template block applies to a restarter.
*
* - The target attribute may have a value of "all" only when the
* template block applies to the master restarter.
*
* The function returns 0 on success and -1 on failure.
*/
static int
{
int is_restarter;
value_t *v;
/* Find the value of the target property. */
return (-1);
}
/*
* If target has a value of instance, the template must be in a
* service object.
*/
if (s->sc_etype != SVCCFG_SERVICE_OBJECT) {
"have a value of \"instance\" when it is in a "
"service declaration.\n"), target_attr);
return (-1);
}
}
/*
* If target has a value of "delegate", the template must be in a
* restarter.
*/
is_restarter = 0;
if ((s->sc_etype == SVCCFG_SERVICE_OBJECT) &&
is_restarter = 1;
}
if ((s->sc_etype == SVCCFG_INSTANCE_OBJECT) &&
SVCCFG_RESTARTER)) {
is_restarter = 1;
}
if (is_restarter == 0) {
"value of \"delegate\" but is not in a "
"restarter service\n"), target_attr);
return (-1);
}
}
/*
* If target has a value of "all", the template must be in the
* global (SCF_SERVICE_GLOBAL) service.
*/
if (s->sc_etype != SVCCFG_SERVICE_OBJECT) {
"value of \"%s\" but is not in a "
return (-1);
}
"value of \"%s\" but is in the \"%s\" service. "
"pg_patterns with target \"%s\" are only allowed "
"in the global service.\n"),
return (-1);
}
}
return (0);
}
static int
{
int out_len;
char *pg_name;
int r = -1;
/*
* Get the name and type attributes. Their presence or absence
* determines whcih prefix we will use for the property group name.
* There are four cases -- neither attribute is present, both are
* present, only name is present or only type is present.
*/
/* PG name contains only the prefix in this case */
}
} else {
/*
* If we have a type and no name, the type becomes
* part of the pg_pattern property group name.
*/
max_scf_name_len + 1) {
}
}
} else {
const char *prefix;
/* Make sure that the name is valid. */
goto out;
}
/*
* As long as the pg_pattern has a name, it becomes part of
* the name of the pg_pattern property group name. We
* merely need to pick the appropriate prefix.
*/
} else {
}
}
}
/*
* Create the property group for holding this pg_pattern
* information, and capture the pg_pattern attributes.
*/
"type is not unique in %s\n"),
} else {
"type \"%s\" is not unique in %s\n"),
}
} else {
"and empty type is not unique in %s\n"),
} else {
"and type \"%s\" is not unique in %s\n"),
}
}
goto out;
}
/*
* Get the pg_pattern attributes from the manifest and verify
* that they satisfy our restrictions.
*/
if (r != 0)
goto out;
r = -1;
goto out;
}
/*
* Now process all of the elements of pg_pattern.
*/
if (lxml_ignorable_block(cursor))
continue;
case SC_COMMON_NAME:
break;
case SC_DESCRIPTION:
break;
case SC_PROP_PATTERN:
pg_name);
if (r != 0)
goto out;
break;
default:
}
}
out:
}
return (r);
}
static int
{
if (lxml_ignorable_block(cursor))
continue;
case SC_COMMON_NAME:
break;
case SC_DESCRIPTION:
break;
case SC_DOCUMENTATION:
break;
case SC_PG_PATTERN:
return (-1);
break;
default:
"for service \"%s\"\n"),
}
}
return (0);
}
static int
{
entity_t *i;
property_t *p;
char *package;
i = internal_instance_new("default");
1 : 0;
}
/*
* New general property group with enabled boolean property set.
*/
pg = internal_pgroup_new();
(void) internal_attach_pgroup(i, pg);
pg->sc_pgroup_flags = 0;
(void) internal_attach_property(pg, p);
/*
*/
(void) internal_attach_property(pg, p);
}
return (internal_attach_entity(service, i));
}
/*
* Translate an instance element into an internal property tree, added to
* service. If op is SVCCFG_OP_APPLY (i.e., apply a profile), set the
* enabled property to override.
*
* If op is SVCCFG_OP_APPLY (i.e., apply a profile), do not allow for
* modification of template data.
*/
static int
{
entity_t *i;
property_t *p;
int r, e_val;
/*
* Fetch its attributes, as appropriate.
*/
/*
* Note that this must be done before walking the children so that
* sc_fmri is set in case we enter lxml_get_dependent().
*/
r = internal_attach_entity(service, i);
if (r != 0)
return (r);
if (bt == SVCCFG_MANIFEST) {
return (-1);
}
} else { /* enabled != NULL */
return (-1);
}
pg = internal_pgroup_new();
(void) internal_attach_pgroup(i, pg);
pg->sc_pgroup_flags = 0;
(void) internal_attach_property(pg, p);
}
/*
* Walk its child elements, as appropriate.
*/
if (lxml_ignorable_block(cursor))
continue;
case SC_RESTARTER:
(void) lxml_get_restarter(i, cursor);
break;
case SC_DEPENDENCY:
(void) lxml_get_dependency(i, cursor);
break;
case SC_DEPENDENT:
(void) lxml_get_dependent(i, cursor);
break;
case SC_METHOD_CONTEXT:
(void) lxml_get_entity_method_context(i, cursor);
break;
case SC_EXEC_METHOD:
(void) lxml_get_exec_method(i, cursor);
break;
case SC_PROPERTY_GROUP:
(void) lxml_get_pgroup(i, cursor);
break;
case SC_TEMPLATE:
if (op == SVCCFG_OP_APPLY) {
"not be modified in a profile.\n"),
i->sc_name);
return (-1);
}
if (lxml_get_template(i, cursor) != 0)
return (-1);
break;
if (lxml_get_notification_parameters(i, cursor) != 0)
return (-1);
break;
default:
"illegal element \"%s\" on instance \"%s\"\n"),
break;
}
}
return (0);
}
/* ARGSUSED1 */
static int
{
property_t *p;
int r;
(char *)scf_group_framework);
r = internal_attach_property(pg, p);
if (r != 0) {
return (-1);
}
return (0);
}
/*
* Check to see if the service should allow the upgrade
* process to handle adding of the manifestfiles linkage.
*
* If the service exists and does not have a manifestfiles
* property group then the upgrade process should handle
* the service.
*
* If the service doesn't exist or the service exists
* and has a manifestfiles property group then the import
* process can handle the manifestfiles property group
* work.
*
* This prevents potential cleanup of unaccounted for instances
* in early manifest import due to upgrade process needing
* information that has not yet been supplied by manifests
*/
static int
{
scf_handle_t *h = NULL;
goto out;
if (scf_handle_bind(h) != 0)
goto out;
goto out;
if (scf_error() == SCF_ERROR_NOT_FOUND)
rc = SCF_SUCCESS;
goto out;
}
goto out;
rc = SCF_SUCCESS;
out:
return (rc);
}
/*
* to bundle.
*
* If op is SVCCFG_OP_APPLY (i.e., apply a profile), do not allow for
* modification of template data.
*/
static int
{
property_t *p;
entity_t *s;
int e;
/*
* Fetch attributes, as appropriate.
*/
/*
* Set the global missing type to false before processing the service
*/
/*
* Now that the service is created create the manifest
* property group and add the property value of the service.
*/
/*
* Must remove the PKG_INSTALL_ROOT, point to the correct
* directory after install
*/
errno);
}
}
"\"%s\", already exists in %s\n"),
SCF_PG_MANIFESTFILES, s->sc_name);
}
(void) internal_attach_property(pg, p);
}
/*
* Walk its child elements, as appropriate.
*/
if (lxml_ignorable_block(cursor))
continue;
switch (e) {
case SC_INSTANCE:
if (lxml_get_instance(s, cursor,
return (-1);
break;
case SC_TEMPLATE:
if (op == SVCCFG_OP_APPLY) {
"not be modified in a profile.\n"),
s->sc_name);
return (-1);
}
if (lxml_get_template(s, cursor) != 0)
return (-1);
break;
if (lxml_get_notification_parameters(s, cursor) != 0)
return (-1);
break;
case SC_STABILITY:
(void) lxml_get_entity_stability(s, cursor);
break;
case SC_DEPENDENCY:
(void) lxml_get_dependency(s, cursor);
break;
case SC_DEPENDENT:
(void) lxml_get_dependent(s, cursor);
break;
case SC_RESTARTER:
(void) lxml_get_restarter(s, cursor);
break;
case SC_EXEC_METHOD:
(void) lxml_get_exec_method(s, cursor);
break;
case SC_METHOD_CONTEXT:
(void) lxml_get_entity_method_context(s, cursor);
break;
case SC_PROPERTY_GROUP:
(void) lxml_get_pgroup(s, cursor);
break;
(void) lxml_get_default_instance(s, cursor);
break;
case SC_INSTANCE_SINGLE:
(void) lxml_get_single_instance(s, cursor);
break;
default:
"illegal element \"%s\" on service \"%s\"\n"),
break;
}
}
/*
* Now that the service has been processed set the missing type
* for the service. So that only the services with missing
* types are processed.
*/
if (est->sc_miss_type)
return (internal_attach_service(bundle, s));
}
#ifdef DEBUG
void
{
if (p && p->name) {
lxml_dump(g + 1, p);
}
}
#endif /* DEBUG */
static int
{
return (0);
return (1);
}
static int
{
int e;
/*
* 1. Get bundle attributes.
*/
return (-1);
}
switch (op) {
case SVCCFG_OP_IMPORT:
return (-1);
}
break;
case SVCCFG_OP_APPLY:
return (-1);
}
break;
case SVCCFG_OP_RESTORE:
return (-1);
}
break;
}
return (-1);
}
/*
* 2. Get services, descend into each one and build state.
*/
if (lxml_ignorable_block(cursor))
continue;
switch (e) {
case SC_XI_INCLUDE:
continue;
case SC_SERVICE_BUNDLE:
return (-1);
break;
case SC_SERVICE:
return (-1);
break;
}
}
return (0);
}
/*
* Load an XML tree from filename and translate it into an internal service
* tree bundle. Require that the bundle be of appropriate type for the
* operation: archive for RESTORE, manifest for IMPORT, profile for APPLY.
*/
int
{
int r;
/*
* Verify we can read the file before we try to parse it.
*/
return (-1);
}
/*
* Until libxml2 addresses DTD-based validation with XInclude, we don't
* validate service profiles (i.e. the apply path).
*/
if (do_validate)
return (-1);
}
/*
* Verify that this is a document type we understand.
*/
return (-1);
/*
* If apply then setup so that some validation
* for specific elements can be done.
*/
}
return (-1);
}
return (-1);
}
return (-1);
}
dtdpath);
return (-1);
}
}
"in document\n"));
return (-1);
}
if (do_validate) {
vcp = xmlNewValidCtxt();
if (r == 0) {
return (-1);
}
}
#ifdef DEBUG
#endif /* DEBUG */
return (r);
}
int
{
bundle_t *b;
b = internal_bundle_new();
return (-1);
}
}
}
return (0);
}