summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2023-01-25 15:17:44 +1300
committerJule Anger <janger@samba.org>2023-02-03 09:35:08 +0000
commitbcb89bd81d4e51fbd06e205816e0b891dc0c1889 (patch)
treee3812c83ac3190832c75403eea9ad04b7fd5a943
parenta78c2094ff503b775688dd46dc48ccf8f0934f09 (diff)
downloadsamba-bcb89bd81d4e51fbd06e205816e0b891dc0c1889.tar.gz
s4-dsdb: Split samdb_get_ntds_obj_by_guid() out of samdb_is_rodc()
This will allow the logic here to be tighened up and shared in the next few commits. BUG: https://bugzilla.samba.org/show_bug.cgi?id=10635 Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> (cherry picked from commit d5a2af3feae98057ba29de444d308d499d633941)
-rw-r--r--source4/dsdb/common/util.c59
1 files changed, 47 insertions, 12 deletions
diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c
index 029a7d69bf3..43fa670006d 100644
--- a/source4/dsdb/common/util.c
+++ b/source4/dsdb/common/util.c
@@ -3550,9 +3550,49 @@ int drsuapi_DsReplicaCursor_compare(const struct drsuapi_DsReplicaCursor *c1,
return GUID_compare(&c1->source_dsa_invocation_id, &c2->source_dsa_invocation_id);
}
+/*
+ * Return the NTDS object for a GUID, confirming it is in the
+ * configuration partition and a nTDSDSA object
+ */
+int samdb_get_ntds_obj_by_guid(TALLOC_CTX *mem_ctx,
+ struct ldb_context *sam_ctx,
+ const struct GUID *objectGUID,
+ const char **attrs,
+ struct ldb_message **msg)
+{
+ int ret;
+ struct ldb_result *res;
+ struct GUID_txt_buf guid_buf;
+ char *guid_str = GUID_buf_string(objectGUID, &guid_buf);
+ struct ldb_dn *config_dn = NULL;
+
+ config_dn = ldb_get_config_basedn(sam_ctx);
+ if (config_dn == NULL) {
+ return ldb_operr(sam_ctx);
+ }
+
+ ret = dsdb_search(sam_ctx,
+ mem_ctx,
+ &res,
+ config_dn,
+ LDB_SCOPE_SUBTREE,
+ attrs,
+ DSDB_SEARCH_ONE_ONLY,
+ "objectGUID=%s",
+ guid_str);
+ if (ret != LDB_SUCCESS) {
+ return ret;
+ }
+ if (msg) {
+ *msg = talloc_steal(mem_ctx, res->msgs[0]);
+ }
+ TALLOC_FREE(res);
+ return ret;
+}
+
/*
- see if a computer identified by its invocationId is a RODC
+ see if a computer identified by its objectGUID is a RODC
*/
int samdb_is_rodc(struct ldb_context *sam_ctx, const struct GUID *objectGUID, bool *is_rodc)
{
@@ -3561,20 +3601,15 @@ int samdb_is_rodc(struct ldb_context *sam_ctx, const struct GUID *objectGUID, bo
3) if not present then not a RODC
4) if present and TRUE then is a RODC
*/
- struct ldb_dn *config_dn;
const char *attrs[] = { "msDS-isRODC", NULL };
int ret;
- struct ldb_result *res;
+ struct ldb_message *msg;
TALLOC_CTX *tmp_ctx = talloc_new(sam_ctx);
- config_dn = ldb_get_config_basedn(sam_ctx);
- if (!config_dn) {
- talloc_free(tmp_ctx);
- return ldb_operr(sam_ctx);
- }
-
- ret = dsdb_search(sam_ctx, tmp_ctx, &res, config_dn, LDB_SCOPE_SUBTREE, attrs,
- DSDB_SEARCH_ONE_ONLY, "objectGUID=%s", GUID_string(tmp_ctx, objectGUID));
+ ret = samdb_get_ntds_obj_by_guid(tmp_ctx,
+ sam_ctx,
+ objectGUID,
+ attrs, &msg);
if (ret == LDB_ERR_NO_SUCH_OBJECT) {
*is_rodc = false;
@@ -3590,7 +3625,7 @@ int samdb_is_rodc(struct ldb_context *sam_ctx, const struct GUID *objectGUID, bo
return ret;
}
- ret = ldb_msg_find_attr_as_bool(res->msgs[0], "msDS-isRODC", 0);
+ ret = ldb_msg_find_attr_as_bool(msg, "msDS-isRODC", 0);
*is_rodc = (ret == 1);
talloc_free(tmp_ctx);