- const SecurityDescriptor *sd = (const SecurityDescriptor*)p;
- u8 revision = sd->revision;
- u16 control = le16_to_cpu(sd->security_descriptor_control);
- u32 owner_offset = le32_to_cpu(sd->owner_offset);
- u32 group_offset = le32_to_cpu(sd->group_offset);
- u32 sacl_offset = le32_to_cpu(sd->sacl_offset);
- u32 dacl_offset = le32_to_cpu(sd->dacl_offset);
- printf("Revision = %u\n", revision);
- printf("Security Descriptor Control = %#x\n", control);
- printf("Owner offset = %u\n", owner_offset);
- printf("Group offset = %u\n", group_offset);
- printf("System ACL offset = %u\n", sacl_offset);
- printf("Discretionary ACL offset = %u\n", dacl_offset);
-
- if (sd->owner_offset != 0)
- print_sid(p + owner_offset, "Owner");
- if (sd->group_offset != 0)
- print_sid(p + group_offset, "Group");
- if (sd->sacl_offset != 0)
- print_acl(p + sacl_offset, "System");
- if (sd->dacl_offset != 0)
- print_acl(p + dacl_offset, "Discretionary");
+ free_sd_tree(sd_set->root);
+}
+
+static int
+_avl_cmp_nodes_by_hash(const struct avl_tree_node *n1,
+ const struct avl_tree_node *n2)
+{
+ return hashes_cmp(SD_NODE(n1)->hash, SD_NODE(n2)->hash);
+}
+
+/* Inserts a new node into the security descriptor index tree. Returns true
+ * if successful (not a duplicate). */
+static bool
+insert_sd_node(struct wim_sd_set *set, struct sd_node *new)
+{
+ return NULL == avl_tree_insert(&set->root, &new->index_node,
+ _avl_cmp_nodes_by_hash);
+}
+
+/* Returns the index of the security descriptor having a SHA1 message digest of
+ * @hash. If not found, return -1. */
+static int32_t
+lookup_sd(struct wim_sd_set *set, const u8 hash[SHA1_HASH_SIZE])
+{
+ struct avl_tree_node *res;
+ struct sd_node dummy;
+
+ copy_hash(dummy.hash, hash);
+ res = avl_tree_lookup_node(set->root, &dummy.index_node,
+ _avl_cmp_nodes_by_hash);
+ if (!res)
+ return -1;
+ return SD_NODE(res)->security_id;