Skip to content

Commit

Permalink
Prevent deletion of RO leaf-lists
Browse files Browse the repository at this point in the history
The checks that were in the leaf processing code need
to also be in the leaf-list section. That is to check the
access (rw) and also if the leaves are hidden.
If the leaf-list is ro and the user has asked to delete
config-only then we also need to remove the leaves of the
leaf-list from the tree otherwise we end up with a strange
tree with what looks like values on the leaf-list list node.
  • Loading branch information
carlgsmith committed Oct 9, 2024
1 parent be894e3 commit 1ecd80a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
3 changes: 3 additions & 0 deletions models/test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
<NODE name="minutes" mode="r" help="minutes" range="0..59"/>
<NODE name="seconds" mode="r" help="seconds" range="0..59"/>
</NODE>
<NODE name="romembers" help="A read-only leaf-list">
<NODE name="*" mode="r" help="Member of group"/>
</NODE>
</NODE>
<NODE name="animals">
<NODE name="animal" help="This is a list of animals">
Expand Down
36 changes: 32 additions & 4 deletions schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -3301,6 +3301,7 @@ _sch_traverse_nodes (sch_instance * instance, sch_node * schema, GNode * parent,
free ((void *)child->children->data);
free ((void *)child->data);
g_node_destroy (child);
child = NULL;
}
else if (!sch_is_writable (schema))
{
Expand Down Expand Up @@ -3369,8 +3370,10 @@ _sch_traverse_nodes (sch_instance * instance, sch_node * schema, GNode * parent,
}
else if (g_strcmp0 (name, "*") == 0)
{
for (GNode *child = parent->children; child; child = child->next)
child = parent->children;
while (child)
{
GNode *next = child->next;
for (sch_node *s = sch_node_child_first (schema); s; s = sch_node_next_sibling (s))
{
if (flags & SCH_F_FILTER_RDEPTH)
Expand All @@ -3384,6 +3387,13 @@ _sch_traverse_nodes (sch_instance * instance, sch_node * schema, GNode * parent,
if (!rc)
goto exit;
}
if (!child->children)
{
DEBUG (flags, "Throwing away node \"%s\"\n", APTERYX_NAME (child));
free ((void *)child->data);
g_node_destroy (child);
}
child = next;
}
}
else if (sch_is_leaf_list (schema))
Expand All @@ -3392,10 +3402,28 @@ _sch_traverse_nodes (sch_instance * instance, sch_node * schema, GNode * parent,
{
if (!(flags & SCH_F_FILTER_RDEPTH) || (depth >= rdepth))
{
for (GNode *leaf = child->children; leaf; leaf = leaf->next)
/* Access is stored on the * node */
sch_node *lschema = sch_node_child_first (schema);
if (sch_is_hidden (lschema) ||
(flags & SCH_F_CONFIG && !sch_is_writable (lschema)))
{
free (leaf->children->data);
leaf->children->data = g_strdup ("");
DEBUG (flags, "Silently ignoring leaf-list \"%s\"\n", name);
apteryx_free_tree (child);
child = NULL;
}
else if (!sch_is_writable (lschema))
{
ERROR (flags, SCH_E_NOTWRITABLE, "Node not writable \"%s\"\n", name);
rc = false;
goto exit;
}
else
{
for (GNode *leaf = child->children; leaf; leaf = leaf->next)
{
free (leaf->children->data);
leaf->children->data = g_strdup ("");
}
}
}
}
Expand Down

0 comments on commit 1ecd80a

Please sign in to comment.