CVE-2023-0614 s4-dsdb: Add samdb_result_dom_sid_buf()
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Sun, 26 Feb 2023 23:19:08 +0000 (12:19 +1300)
committerJule Anger <janger@samba.org>
Mon, 20 Mar 2023 09:03:38 +0000 (10:03 +0100)
This function parses a SID from an ldb_message, similar to
samdb_result_dom_sid(), but does it without allocating anything.

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>
[abartlet@samba.org Adapted for simple conflicts due to
 56297449f9c2e94505a72a70a3a3c5990d00d37f trimming
 trailing whitespace]

source4/dsdb/common/util.c

index 02472f8a89c557fb63599d1734625fe1a84e9a95..1436cd7bfecb0146265f5a237e2344dbcd527f66 100644 (file)
@@ -366,7 +366,27 @@ struct dom_sid *samdb_result_dom_sid(TALLOC_CTX *mem_ctx, const struct ldb_messa
 }
 
 /*
-  pull a guid structure from a objectGUID in a result set. 
+  pull a dom_sid structure from a objectSid in a result set.
+*/
+int samdb_result_dom_sid_buf(const struct ldb_message *msg,
+                            const char *attr,
+                            struct dom_sid *sid)
+{
+       ssize_t ret;
+       const struct ldb_val *v = NULL;
+       v = ldb_msg_find_ldb_val(msg, attr);
+       if (v == NULL) {
+               return LDB_ERR_NO_SUCH_ATTRIBUTE;
+       }
+       ret = sid_parse(v->data, v->length, sid);
+       if (ret == -1) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+       return LDB_SUCCESS;
+}
+
+/*
+  pull a guid structure from a objectGUID in a result set.
 */
 struct GUID samdb_result_guid(const struct ldb_message *msg, const char *attr)
 {