summaryrefslogtreecommitdiff
path: root/source4/dsdb/samdb
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2009-12-16 10:27:32 +1100
committerAndrew Tridgell <tridge@samba.org>2009-12-16 20:56:20 +1100
commit951592687a29e15304d8e203b2b892aa40d7576f (patch)
tree324f493d026b314fb3f2f4185805ab1c73196cf2 /source4/dsdb/samdb
parent32995e84a2c28d8781a0386906df58b9754af24a (diff)
downloadsamba-951592687a29e15304d8e203b2b892aa40d7576f.tar.gz
samba-951592687a29e15304d8e203b2b892aa40d7576f.tar.bz2
samba-951592687a29e15304d8e203b2b892aa40d7576f.zip
s4-dsdb: added dsdb_module_dn_by_guid()
This finds a DN given a GUID, searching below the current module in the module stack. Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source4/dsdb/samdb')
-rw-r--r--source4/dsdb/samdb/ldb_modules/util.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/util.c b/source4/dsdb/samdb/ldb_modules/util.c
index fe6ddfa9b0..df3b0a9e80 100644
--- a/source4/dsdb/samdb/ldb_modules/util.c
+++ b/source4/dsdb/samdb/ldb_modules/util.c
@@ -205,3 +205,44 @@ int dsdb_module_search(struct ldb_module *module,
return ret;
}
+/*
+ find a DN given a GUID. This searches across all partitions
+ */
+int dsdb_module_dn_by_guid(struct ldb_module *module, TALLOC_CTX *mem_ctx,
+ const struct GUID *guid, struct ldb_dn **dn)
+{
+ struct ldb_result *res;
+ const char *attrs[] = { NULL };
+ char *expression;
+ TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
+ int ret;
+
+ expression = talloc_asprintf(tmp_ctx, "objectGUID=%s", GUID_string(tmp_ctx, guid));
+ if (!expression) {
+ ldb_module_oom(module);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ ret = dsdb_module_search(module, tmp_ctx, &res, NULL, LDB_SCOPE_SUBTREE,
+ attrs, DSDB_SEARCH_SHOW_DELETED | DSDB_SEARCH_SEARCH_ALL_PARTITIONS,
+ expression);
+ if (ret != LDB_SUCCESS) {
+ talloc_free(tmp_ctx);
+ return ret;
+ }
+ if (ret->count == 0) {
+ talloc_free(tmp_ctx);
+ return LDB_ERR_NO_SUCH_OBJECT;
+ }
+ if (res->count != 1) {
+ ldb_asprintf_errstring(ldb_module_get_ctx(module), "More than one object found matching %s\n",
+ expression);
+ talloc_free(tmp_ctx);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ *dn = talloc_steal(mem_ctx, res->msgs[0].dn);
+
+ talloc_free(tmp_ctx);
+ return LDB_SUCCESS;
+}