s4-dsdb: added dsdb_find_guid_attr_by_dn()
authorAndrew Tridgell <tridge@samba.org>
Wed, 6 Jan 2010 03:50:41 +0000 (14:50 +1100)
committerAndrew Tridgell <tridge@samba.org>
Fri, 8 Jan 2010 02:03:00 +0000 (13:03 +1100)
Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

source4/dsdb/common/util.c

index 2b8a68e58f70448bb3e299977282108aae814a57..70750ca141608c90db7b7d9303295f9d9475ce4b 100644 (file)
@@ -2433,16 +2433,20 @@ int dsdb_search_dn_with_deleted(struct ldb_context *ldb,
 
 
 /*
-  use a DN to find a GUID
+  use a DN to find a GUID with a given attribute name
  */
-int dsdb_find_guid_by_dn(struct ldb_context *ldb, 
-                        struct ldb_dn *dn, struct GUID *guid)
+int dsdb_find_guid_attr_by_dn(struct ldb_context *ldb,
+                             struct ldb_dn *dn, const char *attribute,
+                             struct GUID *guid)
 {
        int ret;
        struct ldb_result *res;
-       const char *attrs[] = { "objectGUID", NULL };
+       const char *attrs[2];
        TALLOC_CTX *tmp_ctx = talloc_new(ldb);
 
+       attrs[0] = attribute;
+       attrs[1] = NULL;
+
        ret = dsdb_search_dn_with_deleted(ldb, tmp_ctx, &res, dn, attrs);
        if (ret != LDB_SUCCESS) {
                talloc_free(tmp_ctx);
@@ -2452,11 +2456,20 @@ int dsdb_find_guid_by_dn(struct ldb_context *ldb,
                talloc_free(tmp_ctx);
                return LDB_ERR_NO_SUCH_OBJECT;
        }
-       *guid = samdb_result_guid(res->msgs[0], "objectGUID");
+       *guid = samdb_result_guid(res->msgs[0], attribute);
        talloc_free(tmp_ctx);
        return LDB_SUCCESS;
 }
 
+/*
+  use a DN to find a GUID
+ */
+int dsdb_find_guid_by_dn(struct ldb_context *ldb,
+                        struct ldb_dn *dn, struct GUID *guid)
+{
+       return dsdb_find_guid_attr_by_dn(ldb, dn, "objectGUID", guid);
+}
+
 
 
 /*