svn commit: samba r16107 - in branches/SOC/mkhl: .
mkhl at samba.org
mkhl at samba.org
Thu Jun 8 21:53:48 GMT 2006
Author: mkhl
Date: 2006-06-08 21:53:47 +0000 (Thu, 08 Jun 2006)
New Revision: 16107
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=16107
Log:
Experiment with ways to use special DNs with LDAP without breaking too
many things.
* ,,ldb_ildap.c-unspecial-DNs.patch:
Remap incoming special DNs to "normal" DNs before processing.
* ,,ldb-unspecial.c-remap-special-DNs.patch:
Ditto, but in a module instead of a backend.
TODO:
- Search.
- Bootstrap -- after loading this module via @MODULES, the
original record won't be accessible anymore.
(The commas are a habit from previous tla exposure, I'll get over
it... someday... I hope...)
Martin
Added:
branches/SOC/mkhl/,,ldb-unspecial.c-remap-special-DNs.patch
branches/SOC/mkhl/,,ldb_ildap.c-unspecial-DNs.patch
Changeset:
Added: branches/SOC/mkhl/,,ldb-unspecial.c-remap-special-DNs.patch
===================================================================
--- branches/SOC/mkhl/,,ldb-unspecial.c-remap-special-DNs.patch 2006-06-08 21:44:22 UTC (rev 16106)
+++ branches/SOC/mkhl/,,ldb-unspecial.c-remap-special-DNs.patch 2006-06-08 21:53:47 UTC (rev 16107)
@@ -0,0 +1,243 @@
+Index: source/lib/ldb/modules/unspecial.c
+===================================================================
+--- source/lib/ldb/modules/unspecial.c (revision 0)
++++ source/lib/ldb/modules/unspecial.c (revision 0)
+@@ -0,0 +1,218 @@
++/*
++ special DN remapping ldb module
++
++ Copyright (C) Martin Kuehl 2006
++
++ ** NOTE! The following LGPL license applies to the ldb
++ ** library. This does NOT imply that all of Samba is released
++ ** under the LGPL
++
++ This library is free software; you can redistribute it and/or
++ modify it under the terms of the GNU Lesser General Public
++ License as published by the Free Software Foundation; either
++ version 2 of the License, or (at your option) any later version.
++
++ This library is distributed in the hope that it will be useful,
++ but WITHOUT ANY WARRANTY; without even the implied warranty of
++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
++ Lesser General Public License for more details.
++
++ You should have received a copy of the GNU Lesser General Public
++ License along with this library; if not, write to the Free Software
++ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
++*/
++
++#include "includes.h"
++#include "ldb/include/includes.h"
++
++struct unspecial_async_context {
++ struct ldb_module *module;
++
++ /* TODO: Add async stuff */
++};
++
++/*
++ Convert a special DN to a DN suitable for LDAP.
++*/
++static struct ldb_dn *unspecial_remap_special_dn(void *mem_ctx,
++ struct ldb_dn *special_dn)
++{
++ char *dn;
++
++ /*
++ if (!ldb_dn_is_special(special_dn))
++ return special_dn;
++ */
++
++ dn = talloc_asprintf(mem_ctx, "CN=%s,CN=SPECIAL",
++ ((char *)special_dn->components[0].value.data)+1);
++ return ldb_dn_explode_or_special(mem_ctx, dn);
++}
++
++static struct ldb_message *unspecial_msg_copy_with_dn(void *mem_ctx,
++ const struct ldb_message *oldmsg,
++ struct ldb_dn *dn)
++{
++ struct ldb_message *msg;
++ int i;
++
++ msg = ldb_msg_new(mem_ctx);
++ if (msg == NULL)
++ return NULL;
++
++ msg->dn = dn;
++ msg->private_data = NULL;
++
++ msg->num_elements = oldmsg->num_elements;
++
++ msg->elements = talloc_array(msg, struct ldb_message_element, msg->num_elements);
++ if (msg->elements == NULL)
++ goto failed;
++
++ for (i = 0; i < msg->num_elements; i++)
++ msg->elements[i] = oldmsg->elements[i];
++
++failed:
++ talloc_free(msg);
++ return NULL;
++}
++
++/* search */
++static int unspecial_search(struct ldb_module *module, struct ldb_request *req)
++{
++ /* TODO: Hmm, what to do here? */
++ return ldb_next_request(module, req);
++}
++
++/* add */
++static int unspecial_add(struct ldb_module *module, struct ldb_request *req)
++{
++ struct ldb_request *down_req;
++ struct ldb_message *msg;
++ /* const struct ldb_dn *dn; */
++ int ret;
++
++ if (!ldb_dn_is_special(req->op.add.message->dn))
++ return ldb_next_request(module, req);
++
++ down_req = talloc_zero(module, struct ldb_request);
++ if (down_req == NULL)
++ return LDB_ERR_OPERATIONS_ERROR;
++
++ msg = unspecial_msg_copy_with_dn(down_req, req->op.add.message,
++ unspecial_remap_special_dn(down_req, req->op.add.message->dn));
++ if (msg == NULL) {
++ talloc_free(down_req);
++ return LDB_ERR_OPERATIONS_ERROR;
++ }
++
++ *down_req = *req;
++ down_req->op.mod.message = msg;
++
++ ret = ldb_next_request(module, down_req);
++
++ if (ret == LDB_SUCCESS)
++ req->async.handle = down_req->async.handle;
++
++ return ret;
++}
++
++/* modify */
++static int unspecial_modify(struct ldb_module *module, struct ldb_request *req)
++{
++ struct ldb_request *down_req;
++ struct ldb_message *msg;
++ /* const struct ldb_dn *dn; */
++ int ret;
++
++ if (!ldb_dn_is_special(req->op.mod.message->dn))
++ return ldb_next_request(module, req);
++
++ down_req = talloc_zero(module, struct ldb_request);
++ if (down_req == NULL)
++ return LDB_ERR_OPERATIONS_ERROR;
++
++ msg = unspecial_msg_copy_with_dn(down_req, req->op.mod.message,
++ unspecial_remap_special_dn(down_req, req->op.mod.message->dn));
++ if (msg == NULL) {
++ talloc_free(down_req);
++ return LDB_ERR_OPERATIONS_ERROR;
++ }
++
++ *down_req = *req;
++ down_req->op.mod.message = msg;
++
++ ret = ldb_next_request(module, down_req);
++
++ if (ret == LDB_SUCCESS)
++ req->async.handle = down_req->async.handle;
++
++ return ret;
++}
++
++/* delete */
++static int unspecial_delete(struct ldb_module *module, struct ldb_request *req)
++{
++ struct ldb_request *down_req;
++ /* const struct ldb_dn *dn; */
++ int ret;
++
++ if (!ldb_dn_is_special(req->op.del.dn))
++ return ldb_next_request(module, req);
++
++ down_req = talloc_zero(module, struct ldb_request);
++ if (down_req == NULL)
++ return LDB_ERR_OPERATIONS_ERROR;
++ *down_req = *req;
++
++ down_req->op.del.dn = unspecial_remap_special_dn(down_req, req->op.del.dn);
++
++ ret = ldb_next_request(module, down_req);
++
++ if (ret == LDB_SUCCESS)
++ req->async.handle = down_req->async.handle;
++
++ return ret;
++}
++
++/* rename */
++static int unspecial_rename(struct ldb_module *module, struct ldb_request *req)
++{
++ struct ldb_request *down_req;
++ /* const struct ldb_dn *olddn, *newdn; */
++ int ret;
++
++ if (!(ldb_dn_is_special(req->op.rename.olddn) ||
++ ldb_dn_is_special(req->op.rename.newdn)))
++ return ldb_next_request(module, req);
++
++ down_req = talloc_zero(module, struct ldb_request);
++ if (down_req == NULL)
++ return LDB_ERR_OPERATIONS_ERROR;
++ *down_req = *req;
++
++ down_req->op.rename.olddn = unspecial_remap_special_dn(down_req, req->op.rename.olddn);
++ down_req->op.rename.newdn = unspecial_remap_special_dn(down_req, req->op.rename.newdn);
++
++ ret = ldb_next_request(module, down_req);
++
++ if (ret == LDB_SUCCESS)
++ req->async.handle = down_req->async.handle;
++
++ return ret;
++}
++
++static const struct ldb_module_ops unspecial_ops = {
++ .name = "unspecial",
++ .search = unspecial_search,
++ .add = unspecial_add,
++ .modify = unspecial_modify,
++ .del = unspecial_delete,
++ .rename = unspecial_rename,
++ /* .async_wait = unspecial_async_wait */
++};
++
++int ldb_unspecial_init(void)
++{
++ return ldb_register_module(&unspecial_ops);
++}
+Index: source/lib/ldb/config.mk
+===================================================================
+--- source/lib/ldb/config.mk (revision 16096)
++++ source/lib/ldb/config.mk (working copy)
+@@ -127,6 +127,15 @@
+ # End MODULE ldb_tdb
+ ################################################
+
++################################################
++# Start MODULE ldb_unspecial
++[MODULE::ldb_unspecial]
++SUBSYSTEM = ldb
++INIT_FUNCTION = ldb_unspecial_init
++OBJ_FILES = modules/unspecial.o
++# End MODULE ldb_unspecial
++################################################
++
+ ./lib/ldb/common/ldb_modules.o: lib/ldb/common/ldb_modules.c Makefile
+ @echo Compiling $<
+ @$(CC) $(CFLAGS) $(PICFLAG) -DMODULESDIR=\"$(MODULESDIR)/ldb\" -DSHLIBEXT=\"$(SHLIBEXT)\" -c $< -o $@
Added: branches/SOC/mkhl/,,ldb_ildap.c-unspecial-DNs.patch
===================================================================
--- branches/SOC/mkhl/,,ldb_ildap.c-unspecial-DNs.patch 2006-06-08 21:44:22 UTC (rev 16106)
+++ branches/SOC/mkhl/,,ldb_ildap.c-unspecial-DNs.patch 2006-06-08 21:53:47 UTC (rev 16107)
@@ -0,0 +1,111 @@
+Index: source/lib/ldb/ldb_ildap/ldb_ildap.c
+===================================================================
+--- source/lib/ldb/ldb_ildap/ldb_ildap.c (revision 16096)
++++ source/lib/ldb/ldb_ildap/ldb_ildap.c (working copy)
+@@ -118,6 +118,22 @@
+
+
+ /*
++ Convert a special DN to a DN suitable for LDAP.
++ */
++static struct ldb_dn *ildb_unspecial_dn(void *mem_ctx, struct ldb_dn *special_dn)
++{
++ char *dn;
++
++ if (!ldb_dn_is_special(special_dn))
++ return special_dn;
++
++ dn = talloc_asprintf(mem_ctx, "CN=%s,CN=SPECIAL",
++ ((char *)special_dn->components[0].value.data)+1);
++ return ldb_dn_explode_or_special(mem_ctx, dn);
++}
++
++
++/*
+ map an ildap NTSTATUS to a ldb error code
+ */
+ static int ildb_map_error(struct ildb_private *ildb, NTSTATUS status)
+@@ -460,9 +476,11 @@
+ req->async.handle = NULL;
+
+ /* ignore ltdb specials */
++ /*
+ if (ldb_dn_is_special(req->op.add.message->dn)) {
+ return LDB_SUCCESS;
+ }
++ */
+
+ msg = new_ldap_message(ildb->ldap);
+ if (msg == NULL) {
+@@ -471,7 +489,7 @@
+
+ msg->type = LDAP_TAG_AddRequest;
+
+- msg->r.AddRequest.dn = ldb_dn_linearize(msg, req->op.add.message->dn);
++ msg->r.AddRequest.dn = ldb_dn_linearize(msg, ildb_unspecial_dn(msg, req->op.add.message->dn));
+ if (msg->r.AddRequest.dn == NULL) {
+ talloc_free(msg);
+ return LDB_ERR_INVALID_DN_SYNTAX;
+@@ -510,9 +528,11 @@
+ req->async.handle = NULL;
+
+ /* ignore ltdb specials */
++ /*
+ if (ldb_dn_is_special(req->op.mod.message->dn)) {
+ return LDB_SUCCESS;
+ }
++ */
+
+ msg = new_ldap_message(ildb->ldap);
+ if (msg == NULL) {
+@@ -521,7 +541,7 @@
+
+ msg->type = LDAP_TAG_ModifyRequest;
+
+- msg->r.ModifyRequest.dn = ldb_dn_linearize(msg, req->op.mod.message->dn);
++ msg->r.ModifyRequest.dn = ldb_dn_linearize(msg, ildb_unspecial_dn(msg, req->op.mod.message->dn));
+ if (msg->r.ModifyRequest.dn == NULL) {
+ talloc_free(msg);
+ return LDB_ERR_INVALID_DN_SYNTAX;
+@@ -562,9 +582,11 @@
+ req->async.handle = NULL;
+
+ /* ignore ltdb specials */
++ /*
+ if (ldb_dn_is_special(req->op.del.dn)) {
+ return LDB_SUCCESS;
+ }
++ */
+
+ msg = new_ldap_message(ildb->ldap);
+ if (msg == NULL) {
+@@ -573,7 +595,7 @@
+
+ msg->type = LDAP_TAG_DelRequest;
+
+- msg->r.DelRequest.dn = ldb_dn_linearize(msg, req->op.del.dn);
++ msg->r.DelRequest.dn = ldb_dn_linearize(msg, ildb_unspecial_dn(msg, req->op.del.dn));
+ if (msg->r.DelRequest.dn == NULL) {
+ talloc_free(msg);
+ return LDB_ERR_INVALID_DN_SYNTAX;
+@@ -597,9 +619,11 @@
+ req->async.handle = NULL;
+
+ /* ignore ltdb specials */
++ /*
+ if (ldb_dn_is_special(req->op.rename.olddn) || ldb_dn_is_special(req->op.rename.newdn)) {
+ return LDB_SUCCESS;
+ }
++ */
+
+ msg = new_ldap_message(ildb->ldap);
+ if (msg == NULL) {
+@@ -607,7 +631,7 @@
+ }
+
+ msg->type = LDAP_TAG_ModifyDNRequest;
+- msg->r.ModifyDNRequest.dn = ldb_dn_linearize(msg, req->op.rename.olddn);
++ msg->r.ModifyDNRequest.dn = ldb_dn_linearize(msg, ildb_unspecial_dn(msg, req->op.rename.olddn));
+ if (msg->r.ModifyDNRequest.dn == NULL) {
+ talloc_free(msg);
+ return LDB_ERR_INVALID_DN_SYNTAX;
More information about the samba-cvs
mailing list