s4-dsdb: added dsdb_get_extended_dn_sid()
authorAndrew Tridgell <tridge@samba.org>
Thu, 22 Apr 2010 04:53:53 +0000 (14:53 +1000)
committerAndrew Tridgell <tridge@samba.org>
Thu, 22 Apr 2010 09:36:15 +0000 (19:36 +1000)
This will be used by the RODC code

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

source4/dsdb/common/util.c
source4/dsdb/schema/schema_syntax.c

index e395ea540b446e30be64701958e881427ac5c23f..22100c973541a47010238563666b2d7345bb0c16 100644 (file)
@@ -2886,6 +2886,35 @@ NTSTATUS dsdb_get_extended_dn_uint32(struct ldb_dn *dn, uint32_t *val, const cha
        return NT_STATUS_OK;
 }
 
+/*
+  return a dom_sid from a extended DN structure
+ */
+NTSTATUS dsdb_get_extended_dn_sid(struct ldb_dn *dn, struct dom_sid *sid, const char *component_name)
+{
+       const struct ldb_val *sid_blob;
+       struct TALLOC_CTX *tmp_ctx;
+       enum ndr_err_code ndr_err;
+
+       sid_blob = ldb_dn_get_extended_component(dn, "SID");
+       if (!sid_blob) {
+               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+       }
+
+       tmp_ctx = talloc_new(NULL);
+
+       ndr_err = ndr_pull_struct_blob_all(sid_blob, tmp_ctx, NULL, sid,
+                                          (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               NTSTATUS status = ndr_map_error2ntstatus(ndr_err);
+               talloc_free(tmp_ctx);
+               return status;
+       }
+
+       talloc_free(tmp_ctx);
+       return NT_STATUS_OK;
+}
+
+
 /*
   return RMD_FLAGS directly from a ldb_dn
   returns 0 if not found
index 000473fd00837b0627782e6eb5191ed3438438f4..a0eed3d7c0d26295a8e35d8b3e25062ac9fd3efe 100644 (file)
@@ -1614,7 +1614,6 @@ static WERROR dsdb_syntax_DN_ldb_to_drsuapi(struct ldb_context *ldb,
        for (i=0; i < in->num_values; i++) {
                struct drsuapi_DsReplicaObjectIdentifier3 id3;
                enum ndr_err_code ndr_err;
-               const DATA_BLOB *sid_blob;
                struct ldb_dn *dn;
                TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
                NTSTATUS status;
@@ -1636,17 +1635,11 @@ static WERROR dsdb_syntax_DN_ldb_to_drsuapi(struct ldb_context *ldb,
                        return ntstatus_to_werror(status);
                }
 
-               sid_blob = ldb_dn_get_extended_component(dn, "SID");
-               if (sid_blob) {
-                       
-                       ndr_err = ndr_pull_struct_blob_all(sid_blob, 
-                                                          tmp_ctx, schema->iconv_convenience, &id3.sid,
-                                                          (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
-                       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-                               status = ndr_map_error2ntstatus(ndr_err);
-                               talloc_free(tmp_ctx);
-                               return ntstatus_to_werror(status);
-                       }
+               status = dsdb_get_extended_dn_sid(dn, &id3.sid, "SID");
+               if (!NT_STATUS_IS_OK(status) &&
+                   !NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
+                       talloc_free(tmp_ctx);
+                       return ntstatus_to_werror(status);
                }
 
                id3.dn = ldb_dn_get_linearized(dn);