Author: mkhl
Date: 2006-07-29 14:01:34 +0000 (Sat, 29 Jul 2006)
New Revision: 17309

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=17309

Log:
Get rid of the macro changing a DNs base, replace it with functions.
Provide a function to remap and rebase a remote DN.

Martin
Modified:
   branches/SOC/mkhl/ldb-map/modules/ldb_map.c


Changeset:
Modified: branches/SOC/mkhl/ldb-map/modules/ldb_map.c
===================================================================
--- branches/SOC/mkhl/ldb-map/modules/ldb_map.c 2006-07-29 12:23:26 UTC (rev 
17308)
+++ branches/SOC/mkhl/ldb-map/modules/ldb_map.c 2006-07-29 14:01:34 UTC (rev 
17309)
@@ -229,8 +229,28 @@
         return new;
 }
 
-#define MAP_DN_REBASE(dn) dn = ldb_dn_rebase(request, dn, data->local_base_dn, 
data->remote_base_dn)
+/* copy DN with the baseDN of the local partition */
+static
+struct ldb_dn *
+ldb_dn_rebase_local(void *mem_ctx,
+                   const struct ldb_map_context *data,
+                   const struct ldb_dn *dn)
+{
+       return ldb_dn_rebase(mem_ctx, dn,
+                            data->remote_base_dn, data->local_base_dn);
+}
 
+/* copy DN with the baseDN of the remote partition */
+static
+struct ldb_dn *
+ldb_dn_rebase_remote(void *mem_ctx,
+                    const struct ldb_map_context *data,
+                    const struct ldb_dn *dn)
+{
+       return ldb_dn_rebase(mem_ctx, dn,
+                            data->local_base_dn, data->remote_base_dn);
+}
+
 /* run request in the remote partition */
 static
 int
@@ -244,33 +264,39 @@
        case LDB_SEARCH:
                /* make sure the request targets the remote partition */
                if (request->op.search.base) {
-                       MAP_DN_REBASE(request->op.search.base);
+                       request->op.search.base
+                               = ldb_dn_rebase_remote(request, data,
+                                                      request->op.search.base);
                } else {
                        request->op.search.base = data->remote_base_dn;
-                       /* TODO: reference/steal? */
                        /* TODO: adjust scope? */
                }
                 break;
 
        case LDB_ADD:
                 msg = ldb_msg_copy_shallow(request, request->op.add.message);
-                MAP_DN_REBASE(msg->dn);
+                msg->dn = ldb_dn_rebase_remote(msg, data, msg->dn);
                 request->op.add.message = msg;
                 break;
 
        case LDB_MODIFY:
                 msg = ldb_msg_copy_shallow(request, request->op.mod.message);
-                MAP_DN_REBASE(msg->dn);
+                msg->dn = ldb_dn_rebase_remote(msg, data, msg->dn);
                 request->op.mod.message = msg;
                 break;
 
        case LDB_DELETE:
-                MAP_DN_REBASE(request->op.del.dn);
+               request->op.del.dn = ldb_dn_rebase_remote(request, data,
+                                                         request->op.del.dn);
                 break;
 
        case LDB_RENAME:
-                MAP_DN_REBASE(request->op.rename.olddn);
-                MAP_DN_REBASE(request->op.rename.newdn);
+               request->op.rename.olddn
+                       = ldb_dn_rebase_remote(request, data,
+                                              request->op.rename.olddn);
+               request->op.rename.newdn
+                       = ldb_dn_rebase_remote(request, data,
+                                              request->op.rename.newdn);
                 break;
 
         default:
@@ -962,19 +988,6 @@
 /* TODO: these functions move a DN from the remote into the local partition.
    The first one keeps the remote schema, the second one uses the local one.
    Neither should be necessary with GUIDs. */
-/* rebased DN -> DN */
-static
-struct ldb_dn *
-map_unrebase_dn(struct ldb_module *module,
-                     void *mem_ctx,
-                     const struct ldb_dn *dn)
-{
-       const struct ldb_map_context *data = map_get_context(module);
-
-       return ldb_dn_rebase(mem_ctx, dn,
-                            data->remote_base_dn, data->local_base_dn);
-}
-
 /* remote rebased DN -> local DN */
 static
 struct ldb_dn *
@@ -982,9 +995,10 @@
                       void *mem_ctx,
                       const struct ldb_dn *dn)
 {
+       const struct ldb_map_context *data = map_get_context(module);
        struct ldb_dn *dn1, *dn2;
 
-       dn1 = map_unrebase_dn(module, mem_ctx, dn);
+       dn1 = ldb_dn_rebase_local(mem_ctx, data, dn);
        dn2 = map_remote_dn(module, mem_ctx, dn1);
 
        talloc_free(dn1);

Reply via email to