summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2009-09-24 07:05:07 -0700
committerAndrew Tridgell <tridge@samba.org>2009-09-24 10:35:32 -0700
commit1fa735cc86cc4f05a6e53bf0ef17bd8562a94d00 (patch)
tree859345f6a72dae2a9d81cca94366081f957c6c04
parenta9188f7e10dffc9ad7c30b0b51a45d21b633417d (diff)
downloadsamba-1fa735cc86cc4f05a6e53bf0ef17bd8562a94d00.tar.gz
samba-1fa735cc86cc4f05a6e53bf0ef17bd8562a94d00.tar.bz2
samba-1fa735cc86cc4f05a6e53bf0ef17bd8562a94d00.zip
s4-drs: add SHOW_DELETED control on dsdb utility calls
The dsdb_find_dn_by_guid() and dsdb_find_sid_by_dn() are using by the DRS server call getncchanges on objects that may be deleted.
-rw-r--r--source4/dsdb/common/util.c62
1 files changed, 60 insertions, 2 deletions
diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c
index 9a49417d91..52ba40b02f 100644
--- a/source4/dsdb/common/util.c
+++ b/source4/dsdb/common/util.c
@@ -2184,6 +2184,56 @@ int dsdb_find_dn_by_guid(struct ldb_context *ldb,
return LDB_SUCCESS;
}
+/*
+ search for attrs on one DN, allowing for deleted objects
+ */
+static int dsdb_search_dn_with_deleted(struct ldb_context *ldb,
+ TALLOC_CTX *mem_ctx,
+ struct ldb_result **_res,
+ struct ldb_dn *basedn,
+ const char * const *attrs)
+{
+ int ret;
+ struct ldb_request *req;
+ TALLOC_CTX *tmp_ctx;
+ struct ldb_result *res;
+
+ tmp_ctx = talloc_new(mem_ctx);
+
+ res = talloc_zero(tmp_ctx, struct ldb_result);
+ if (!res) {
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ ret = ldb_build_search_req(&req, ldb, tmp_ctx,
+ basedn,
+ LDB_SCOPE_BASE,
+ NULL,
+ attrs,
+ NULL,
+ res,
+ ldb_search_default_callback,
+ NULL);
+ if (ret != LDB_SUCCESS) {
+ talloc_free(tmp_ctx);
+ return ret;
+ }
+
+ ret = ldb_request_add_control(req, LDB_CONTROL_SHOW_DELETED_OID, true, NULL);
+ if (ret != LDB_SUCCESS) {
+ return ret;
+ }
+
+ ret = ldb_request(ldb, req);
+ if (ret == LDB_SUCCESS) {
+ ret = ldb_wait(req->handle, LDB_WAIT_ALL);
+ }
+
+ talloc_free(req);
+ *_res = talloc_steal(mem_ctx, res);
+ return ret;
+}
+
/*
use a DN to find a GUID
@@ -2196,11 +2246,15 @@ int dsdb_find_guid_by_dn(struct ldb_context *ldb,
const char *attrs[] = { "objectGUID", NULL };
TALLOC_CTX *tmp_ctx = talloc_new(ldb);
- ret = ldb_search(ldb, tmp_ctx, &res, dn, LDB_SCOPE_BASE, attrs, NULL);
+ ret = dsdb_search_dn_with_deleted(ldb, tmp_ctx, &res, dn, attrs);
if (ret != LDB_SUCCESS) {
talloc_free(tmp_ctx);
return ret;
}
+ if (res->count < 1) {
+ talloc_free(tmp_ctx);
+ return LDB_ERR_NO_SUCH_OBJECT;
+ }
*guid = samdb_result_guid(res->msgs[0], "objectGUID");
talloc_free(tmp_ctx);
return LDB_SUCCESS;
@@ -2220,11 +2274,15 @@ int dsdb_find_sid_by_dn(struct ldb_context *ldb,
ZERO_STRUCTP(sid);
- ret = ldb_search(ldb, tmp_ctx, &res, dn, LDB_SCOPE_BASE, attrs, NULL);
+ ret = dsdb_search_dn_with_deleted(ldb, tmp_ctx, &res, dn, attrs);
if (ret != LDB_SUCCESS) {
talloc_free(tmp_ctx);
return ret;
}
+ if (res->count < 1) {
+ talloc_free(tmp_ctx);
+ return LDB_ERR_NO_SUCH_OBJECT;
+ }
s = samdb_result_dom_sid(tmp_ctx, res->msgs[0], "objectSID");
if (s == NULL) {
talloc_free(tmp_ctx);