]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
CVE-2023-0614 ldb: Add functions for handling inaccessible message elements
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Thu, 26 Jan 2023 19:28:36 +0000 (08:28 +1300)
committerJule Anger <janger@samba.org>
Mon, 20 Mar 2023 09:03:37 +0000 (10:03 +0100)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15270

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/ldb/common/ldb_msg.c
lib/ldb/include/ldb_module.h

index 9cd7998e21ce423e838eb278abd0ff948ff68405..cbc7e32b2ba668390feaebc3c718b0ae0e495d57 100644 (file)
@@ -795,6 +795,32 @@ int ldb_msg_element_compare_name(struct ldb_message_element *el1,
        return ldb_attr_cmp(el1->name, el2->name);
 }
 
+void ldb_msg_element_mark_inaccessible(struct ldb_message_element *el)
+{
+       el->flags |= LDB_FLAG_INTERNAL_INACCESSIBLE_ATTRIBUTE;
+}
+
+bool ldb_msg_element_is_inaccessible(const struct ldb_message_element *el)
+{
+       return (el->flags & LDB_FLAG_INTERNAL_INACCESSIBLE_ATTRIBUTE) != 0;
+}
+
+void ldb_msg_remove_inaccessible(struct ldb_message *msg)
+{
+       unsigned i;
+       unsigned num_del = 0;
+
+       for (i = 0; i < msg->num_elements; ++i) {
+               if (ldb_msg_element_is_inaccessible(&msg->elements[i])) {
+                       ++num_del;
+               } else if (num_del) {
+                       msg->elements[i - num_del] = msg->elements[i];
+               }
+       }
+
+       msg->num_elements -= num_del;
+}
+
 /*
   convenience functions to return common types from a message
   these return the first value if the attribute is multi-valued
index 4c7c85a17f0056fca5967670c88f18846692e5cd..8481fd3991a231835133dd64cf86f6656a2bc8c5 100644 (file)
@@ -513,6 +513,10 @@ struct ldb_extended_match_rule
 int ldb_register_extended_match_rule(struct ldb_context *ldb,
                                     const struct ldb_extended_match_rule *rule);
 
+void ldb_msg_element_mark_inaccessible(struct ldb_message_element *el);
+bool ldb_msg_element_is_inaccessible(const struct ldb_message_element *el);
+void ldb_msg_remove_inaccessible(struct ldb_message *msg);
+
 /*
  * these pack/unpack functions are exposed in the library for use by
  * ldb tools like ldbdump and for use in tests,