summaryrefslogtreecommitdiff
path: root/libcli/security/object_tree.c
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2013-01-03 20:40:32 +1100
committerStefan Metzmacher <metze@samba.org>2013-01-21 16:12:45 +0100
commit5b4e3de2bb25eeb85d72a886386c853cea3e9468 (patch)
treef8dae1c393f8f4f768584d67036e0b15a7ac0e94 /libcli/security/object_tree.c
parenta359aef0837781c42bf9dbcdd069796c72cc94c7 (diff)
downloadsamba-5b4e3de2bb25eeb85d72a886386c853cea3e9468.tar.gz
libcli/security: handle node initialisation in one spot in insert_in_object_tree()
This removes special-case for initalising the children array in insert_in_object_tree(). talloc_realloc() handles the intial allocate case perfectly well, so there is no need to have this duplicated. This also restores having just one place were the rest of the elements are intialised, to ensure uniform behaviour. To do this, we have to rework insert_in_object_tree to have only one output variable, both because having both root and new_node as output variables was too confusing, and because otherwise the two pointers were being allowed to point at the same memory. Andrew Bartlett Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'libcli/security/object_tree.c')
-rw-r--r--libcli/security/object_tree.c67
1 files changed, 33 insertions, 34 deletions
diff --git a/libcli/security/object_tree.c b/libcli/security/object_tree.c
index dcbd310baea..a629177936d 100644
--- a/libcli/security/object_tree.c
+++ b/libcli/security/object_tree.c
@@ -38,52 +38,51 @@
*/
bool insert_in_object_tree(TALLOC_CTX *mem_ctx,
- const struct GUID *guid,
- uint32_t init_access,
- struct object_tree **root,
- struct object_tree **new_node)
+ const struct GUID *guid,
+ uint32_t init_access,
+ struct object_tree *root,
+ struct object_tree **new_node_out)
{
+ struct object_tree *new_node;
+
if (!guid || GUID_all_zero(guid)){
return true;
}
- if (!*root){
- *root = talloc_zero(mem_ctx, struct object_tree);
- if (!*root) {
+ if (!root) {
+ root = talloc_zero(mem_ctx, struct object_tree);
+ if (!root) {
return false;
}
- (*root)->guid = *guid;
- (*root)->remaining_access = init_access;
- *new_node = *root;
- return true;
- }
-
- if (!(*root)->children) {
- (*root)->children = talloc_array(mem_ctx, struct object_tree, 1);
- (*root)->children[0].guid = *guid;
- (*root)->children[0].num_of_children = 0;
- (*root)->children[0].children = NULL;
- (*root)->num_of_children++;
- (*root)->children[0].remaining_access = init_access;
- *new_node = &((*root)->children[0]);
- return true;
- }
- else {
+ new_node = root;
+ } else {
int i;
- for (i = 0; i < (*root)->num_of_children; i++) {
- if (GUID_equal(&((*root)->children[i].guid), guid)) {
- *new_node = &((*root)->children[i]);
+
+ for (i = 0; i < root->num_of_children; i++) {
+ if (GUID_equal(&root->children[i].guid, guid)) {
+ new_node = &root->children[i];
+ *new_node_out = new_node;
return true;
}
}
- (*root)->children = talloc_realloc(mem_ctx, (*root)->children, struct object_tree,
- (*root)->num_of_children +1);
- (*root)->children[(*root)->num_of_children].guid = *guid;
- (*root)->children[(*root)->num_of_children].remaining_access = init_access;
- *new_node = &((*root)->children[(*root)->num_of_children]);
- (*root)->num_of_children++;
- return true;
+
+ root->children = talloc_realloc(mem_ctx, root->children,
+ struct object_tree,
+ root->num_of_children + 1);
+ if (!root->children) {
+ return false;
+ }
+ new_node = &root->children[root->num_of_children];
+ root->num_of_children++;
}
+
+ new_node->children = NULL;
+ new_node->guid = *guid;
+ new_node->remaining_access = init_access;
+ new_node->num_of_children = 0;
+
+ *new_node_out = new_node;
+ return true;
}
/* search by GUID */