s4-drs: moved the drs_ObjectIdentifier handling to dsdb_dn.c
authorAndrew Tridgell <tridge@samba.org>
Tue, 28 Sep 2010 17:39:52 +0000 (10:39 -0700)
committerAndrew Tridgell <tridge@samba.org>
Tue, 28 Sep 2010 18:36:40 +0000 (11:36 -0700)
this will be used outside of the drs server.

This also fixes the handling of the ndr_size elements of the
drs_ObjectIdentifier

source4/dsdb/common/dsdb_dn.c
source4/rpc_server/drsuapi/drsutil.c

index cb9cb299ce3296bfa4ff8da3c1f2f0fd74c84c7c..85ba9b760597804c457e67bdee8d19bd2caea7a3 100644 (file)
@@ -22,6 +22,8 @@
 #include "includes.h"
 #include "dsdb/samdb/samdb.h"
 #include "lib/ldb/include/ldb_module.h"
+#include "librpc/ndr/libndr.h"
+#include "libcli/security/dom_sid.h"
 
 enum dsdb_dn_format dsdb_dn_oid_to_format(const char *oid) 
 {
@@ -402,3 +404,43 @@ WERROR dsdb_dn_la_from_blob(struct ldb_context *sam_ctx,
 
        return WERR_OK;
 }
+
+
+/*
+  format a drsuapi_DsReplicaObjectIdentifier naming context as a string
+ */
+char *drs_ObjectIdentifier_to_string(TALLOC_CTX *mem_ctx,
+                                    struct drsuapi_DsReplicaObjectIdentifier *nc)
+{
+       char *ret = NULL;
+       TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
+       if (!GUID_all_zero(&nc->guid)) {
+               char *guid = GUID_string(tmp_ctx, &nc->guid);
+               if (guid) {
+                       ret = talloc_asprintf_append(ret, "<GUID=%s>;", guid);
+               }
+       }
+       if (nc->__ndr_size_sid != 0 && nc->sid.sid_rev_num != 0) {
+               const char *sid = dom_sid_string(tmp_ctx, &nc->sid);
+               if (sid) {
+                       ret = talloc_asprintf_append(ret, "<SID=%s>;", sid);
+               }
+       }
+       if (nc->__ndr_size_dn != 0 && nc->dn) {
+               ret = talloc_asprintf_append(ret, "%s", nc->dn);
+       }
+       talloc_free(tmp_ctx);
+       talloc_steal(mem_ctx, ret);
+       return ret;
+}
+
+struct ldb_dn *drs_ObjectIdentifier_to_dn(TALLOC_CTX *mem_ctx,
+                                         struct ldb_context *ldb,
+                                         struct drsuapi_DsReplicaObjectIdentifier *nc)
+{
+       char *dn_string = drs_ObjectIdentifier_to_string(mem_ctx, nc);
+       struct ldb_dn *new_dn;
+       new_dn = ldb_dn_new(mem_ctx, ldb, dn_string);
+       talloc_free(dn_string);
+       return new_dn;
+}
index 5b5e14aea425a7c815ac49d6ff139af1beab129f..f88af93354df9f649ccddb4a7e358f807e4a33b0 100644 (file)
 #include "param/param.h"
 #include "auth/session.h"
 
-/*
-  format a drsuapi_DsReplicaObjectIdentifier naming context as a string
- */
-char *drs_ObjectIdentifier_to_string(TALLOC_CTX *mem_ctx,
-                                    struct drsuapi_DsReplicaObjectIdentifier *nc)
-{
-       char *guid, *sid, *ret;
-       guid = GUID_string(mem_ctx, &nc->guid);
-       sid  = dom_sid_string(mem_ctx, &nc->sid);
-       ret = talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s",
-                             guid, sid, nc->dn);
-       talloc_free(guid);
-       talloc_free(sid);
-       return ret;
-}
-
-struct ldb_dn *drs_ObjectIdentifier_to_dn(TALLOC_CTX *mem_ctx,
-                                         struct ldb_context *ldb,
-                                         struct drsuapi_DsReplicaObjectIdentifier *nc)
-{
-       char *guid = NULL, *sid = NULL, *ret = NULL;
-       struct ldb_dn *new_dn;
-       if (!GUID_all_zero(&nc->guid)) {
-               guid = GUID_string(mem_ctx, &nc->guid);
-               if (guid) {
-                       ret = talloc_asprintf_append(mem_ctx, "<GUID=%s>;", guid);
-               }
-       }
-       if (nc->sid.sid_rev_num != 0) {
-               sid = dom_sid_string(mem_ctx, &nc->sid);
-               if (sid) {
-                       ret = talloc_asprintf_append(ret, "<SID=%s>;", sid);
-               }
-       }
-       if (nc->dn) {
-               ret = talloc_asprintf_append(ret, "%s", nc->dn);
-       }
-       new_dn = ldb_dn_new(mem_ctx, ldb, ret);
-       talloc_free(guid);
-       talloc_free(sid);
-       talloc_free(ret);
-       return new_dn;
-}
-
 int drsuapi_search_with_extended_dn(struct ldb_context *ldb,
                                    TALLOC_CTX *mem_ctx,
                                    struct ldb_result **_res,