Skip to content

Commit

Permalink
335 service manifest does not support multiple manpage references for…
Browse files Browse the repository at this point in the history
… the same keyword

Reviewed by: Igor Kozhukhov <ikozhukhov@gmail.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Alexander Pyhalov <apyhalov@gmail.com>
Approved by: Dan McDonald <danmcd@omniti.com>
  • Loading branch information
trisk authored and Dan McDonald committed Sep 17, 2015
1 parent 03bad06 commit 67b0e06
Showing 1 changed file with 53 additions and 28 deletions.
81 changes: 53 additions & 28 deletions usr/src/cmd/svc/svccfg/svccfg_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
/*
* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
*/


/*
* XML document manipulation routines
Expand Down Expand Up @@ -580,9 +584,7 @@ lxml_store_value(value_t *v, element_t type, const xmlChar *value)
case SC_USTRING:
scf_type = lxml_element_to_type(type);

if ((v->sc_u.sc_string = strdup((char *)value)) == NULL)
uu_die(gettext("string duplication failed (%s)\n"),
strerror(errno));
v->sc_u.sc_string = safe_strdup((const char *)value);
if (lxml_validate_string_value(scf_type,
v->sc_u.sc_string) != 0)
uu_die(gettext("illegal value \"%s\" for "
Expand Down Expand Up @@ -1370,7 +1372,7 @@ lxml_get_entity_stability(entity_t *entity, xmlNodePtr rstr)
if (((stabval = xmlGetProp(rstr, (xmlChar *)value_attr)) == NULL) ||
(*stabval == 0)) {
uu_warn(gettext("no stability value found\n"));
stabval = (xmlChar *)strdup("External");
stabval = (xmlChar *)safe_strdup("External");
}

pg = internal_pgroup_find_or_create(entity, (char *)scf_pg_general,
Expand Down Expand Up @@ -1438,8 +1440,7 @@ lxml_get_paramval(pgroup_t *pgrp, const char *propname, xmlNodePtr pval)
char *value;
char *prop;

if ((prop = strdup(propname)) == NULL)
uu_die(gettext("Out of memory.\n"));
prop = safe_strdup(propname);

value = (char *)xmlGetProp(pval, (xmlChar *)value_attr);
if (value == NULL || *value == '\0')
Expand All @@ -1455,8 +1456,7 @@ lxml_get_parameter(pgroup_t *pgrp, const char *propname, xmlNodePtr param)
{
property_t *p = internal_property_new();

if ((p->sc_property_name = strdup(propname)) == NULL)
uu_die(gettext("Out of memory.\n"));
p->sc_property_name = safe_strdup(propname);
p->sc_value_type = SCF_TYPE_ASTRING;

(void) lxml_get_value(p, SC_ASTRING, param);
Expand Down Expand Up @@ -1707,8 +1707,7 @@ lxml_get_loctext(entity_t *service, pgroup_t *pg, xmlNodePtr loctext,
/*
* Remove leading and trailing whitespace.
*/
if ((stripped = strdup((const char *)cursor->content)) == NULL)
uu_die(gettext("Out of memory\n"));
stripped = safe_strdup((const char *)cursor->content);

for (; isspace(*stripped); stripped++)
;
Expand Down Expand Up @@ -1944,23 +1943,20 @@ lxml_label_to_groupname(const char *prefix, const char *in)
char *out, *cp;
size_t len, piece_len;

out = uu_zalloc(2 * scf_limit(SCF_LIMIT_MAX_NAME_LENGTH) + 1);
out = uu_zalloc(2 * max_scf_name_len + 1);
if (out == NULL)
return (NULL);

(void) strcpy(out, prefix);
(void) strcat(out, in);
(void) strlcpy(out, prefix, 2 * max_scf_name_len + 1);

len = strlen(out);
len = strlcat(out, in, 2 * max_scf_name_len + 1);
if (len > max_scf_name_len) {
/* Use the first half and the second half. */
piece_len = (max_scf_name_len - 2) / 2;

(void) strncpy(out + piece_len, "..", 2);

(void) strcpy(out + piece_len + 2, out + (len - piece_len));

len = strlen(out);
}

/*
Expand All @@ -1971,8 +1967,6 @@ lxml_label_to_groupname(const char *prefix, const char *in)
*cp = '_';
}

*cp = '\0';

return (out);
}

Expand Down Expand Up @@ -2036,9 +2030,7 @@ seps_to_prop_values(property_t **p, xmlChar *seps)
v->sc_type = (*p)->sc_value_type;
v->sc_free = lxml_free_str;
val_str[0] = *seps;
v->sc_u.sc_string = strdup(val_str);
if (v->sc_u.sc_string == NULL)
uu_die(gettext("Out of memory\n"));
v->sc_u.sc_string = safe_strdup(val_str);
internal_attach_value(*p, v);
}
}
Expand Down Expand Up @@ -2083,19 +2075,48 @@ lxml_get_tm_manpage(entity_t *service, xmlNodePtr manpage)
{
pgroup_t *pg;
char *pgname;
char *name;
xmlChar *title;
xmlChar *section;

/*
* Fetch title attribute, convert to something sanitized, and create
* property group.
* Fetch title and section attributes, convert to something sanitized,
* and create property group.
*/
title = xmlGetProp(manpage, (xmlChar *)title_attr);
pgname = (char *)lxml_label_to_groupname(SCF_PG_TM_MAN_PREFIX,
(const char *)title);
if (title == NULL)
return (-1);
section = xmlGetProp(manpage, (xmlChar *)section_attr);
if (section == NULL) {
xmlFree(title);
return (-1);
}

name = safe_malloc(max_scf_name_len + 1);

/* Find existing property group with underscore separators */
(void) snprintf(name, max_scf_name_len + 1, "%s_%s", title, section);
pgname = lxml_label_to_groupname(SCF_PG_TM_MAN_PREFIX, name);
pg = internal_pgroup_find(service, pgname, SCF_GROUP_TEMPLATE);

uu_free(pgname);
(void) snprintf(name, max_scf_name_len + 1, "%s%s", title, section);
pgname = lxml_label_to_groupname(SCF_PG_TM_MAN_PREFIX, name);

if (pg == NULL) {
pg = internal_pgroup_find_or_create(service, pgname,
SCF_GROUP_TEMPLATE);
} else {
/* Rename property group */
free((char *)pg->sc_pgroup_name);
pg->sc_pgroup_name = safe_strdup(pgname);
}

uu_free(pgname);
free(name);
xmlFree(section);
xmlFree(title);

pg = internal_pgroup_find_or_create(service, pgname,
(char *)SCF_GROUP_TEMPLATE);

/*
* Each attribute is an astring property within the group.
Expand Down Expand Up @@ -2123,12 +2144,16 @@ lxml_get_tm_doclink(entity_t *service, xmlNodePtr doc_link)
* property group.
*/
name = xmlGetProp(doc_link, (xmlChar *)name_attr);
if (name == NULL)
return (-1);

pgname = (char *)lxml_label_to_groupname(SCF_PG_TM_DOC_PREFIX,
(const char *)name);

pg = internal_pgroup_find_or_create(service, pgname,
(char *)SCF_GROUP_TEMPLATE);

uu_free(pgname);
xmlFree(name);

/*
Expand Down Expand Up @@ -3668,7 +3693,7 @@ lxml_get_bundle_file(bundle_t *bundle, const char *filename, svccfg_op_t op)
return (-1);
}

document->name = strdup(filename);
document->name = safe_strdup(filename);

/*
* Verify that this is a document type we understand.
Expand Down

0 comments on commit 67b0e06

Please sign in to comment.