s4-dsdb: added dsdb_wellknown_dn()
authorAndrew Tridgell <tridge@samba.org>
Wed, 16 Dec 2009 02:18:44 +0000 (13:18 +1100)
committerAndrew Tridgell <tridge@samba.org>
Wed, 16 Dec 2009 09:56:22 +0000 (20:56 +1100)
This finds a wellknown object given its GUID

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

source4/dsdb/common/util.c

index 30eb28c69c84c3bd627356b6fca170a947d87a34..1162196843957d2c9de56acb0f7e314e13bef3d0 100644 (file)
@@ -2750,3 +2750,35 @@ bool dsdb_dn_is_deleted_val(struct ldb_val *val)
        }
        return false;
 }
+
+/*
+  return a DN for a wellknown GUID
+ */
+int dsdb_wellknown_dn(struct ldb_context *samdb, TALLOC_CTX *mem_ctx,
+                     struct ldb_dn *nc_root, const char *wk_guid,
+                     struct ldb_dn **wkguid_dn)
+{
+       TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
+       const char *attrs[] = { NULL };
+       int ret;
+       struct ldb_dn *dn;
+       struct ldb_result *res;
+
+       /* construct the magic WKGUID DN */
+       dn = ldb_dn_new_fmt(tmp_ctx, samdb, "<WKGUID=%s,%s>",
+                           wk_guid, ldb_dn_get_linearized(nc_root));
+       if (!wkguid_dn) {
+               talloc_free(tmp_ctx);
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       ret = dsdb_search_dn_with_deleted(samdb, tmp_ctx, &res, dn, attrs);
+       if (ret != LDB_SUCCESS) {
+               talloc_free(tmp_ctx);
+               return ret;
+       }
+
+       (*wkguid_dn) = talloc_steal(mem_ctx, res->msgs[0]->dn);
+       talloc_free(tmp_ctx);
+       return LDB_SUCCESS;
+}