s4-dsdb: added dsdb_find_sid_by_dn()
authorAndrew Tridgell <tridge@samba.org>
Wed, 23 Sep 2009 20:52:39 +0000 (13:52 -0700)
committerAndrew Tridgell <tridge@samba.org>
Wed, 23 Sep 2009 21:01:29 +0000 (14:01 -0700)
source4/dsdb/common/util.c

index 126f9fa8292ba44fbac0710a4b7443fe250e8c62..9a49417d91f8e3a002e9e1aa18529b2487a17fea 100644 (file)
@@ -1609,6 +1609,7 @@ int samdb_search_for_parent_domain(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
        if (res->count != 1) {
                *errstring = talloc_asprintf(mem_ctx, "Invalid dn (%s), not child of a domain object",
                                             ldb_dn_get_linearized(dn));
+               DEBUG(0,(__location__ ": %s\n", *errstring));
                talloc_free(local_ctx);
                return LDB_ERR_CONSTRAINT_VIOLATION;
        }
@@ -2205,6 +2206,35 @@ int dsdb_find_guid_by_dn(struct ldb_context *ldb,
        return LDB_SUCCESS;
 }
 
+/*
+  use a DN to find a SID
+ */
+int dsdb_find_sid_by_dn(struct ldb_context *ldb, 
+                       struct ldb_dn *dn, struct dom_sid *sid)
+{
+       int ret;
+       struct ldb_result *res;
+       const char *attrs[] = { "objectSID", NULL };
+       TALLOC_CTX *tmp_ctx = talloc_new(ldb);
+       struct dom_sid *s;
+
+       ZERO_STRUCTP(sid);
+
+       ret = ldb_search(ldb, tmp_ctx, &res, dn, LDB_SCOPE_BASE, attrs, NULL);
+       if (ret != LDB_SUCCESS) {
+               talloc_free(tmp_ctx);
+               return ret;
+       }
+       s = samdb_result_dom_sid(tmp_ctx, res->msgs[0], "objectSID");
+       if (s == NULL) {
+               talloc_free(tmp_ctx);
+               return LDB_ERR_NO_SUCH_OBJECT;
+       }
+       *sid = *s;
+       talloc_free(tmp_ctx);
+       return LDB_SUCCESS;
+}
+
 
 
 /*