r9595: Add ldb map module
authorJelmer Vernooij <jelmer@samba.org>
Wed, 24 Aug 2005 22:06:26 +0000 (22:06 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:34:33 +0000 (13:34 -0500)
source/include/structs.h
source/lib/ldb/config.mk
source/lib/ldb/ldb_map/ldb_map.c [new file with mode: 0644]
source/lib/ldb/ldb_map/ldb_map.h
source/lib/samba3/config.mk
source/lib/samba3/ldb_samba3.c [moved from source/lib/ldb/samba/ldb_samba3.c with 67% similarity]

index cac46c030f7d6b4d961702865add7fb0b755039f..047e32e739cfe5d9014ab0b6246a2dbe525d344d 100644 (file)
@@ -280,3 +280,5 @@ struct samba3_policy;
 struct samba3_regdb;
 struct samba3_secrets;
 struct samba3;
+
+struct ldb_map_mappings;
index d3f60b74cae44e16a54a303253ef78069e5c2ded..76059b3b608072cd057e6f8dce045041bc5c360f 100644 (file)
@@ -37,6 +37,14 @@ NOPROTO = YES
 # End MODULE libldb_ildap
 ################################################
 
+################################################
+# Start MODULE libldb_map
+[MODULE::libldb_map]
+SUBSYSTEM = LIBLDB
+INIT_OBJ_FILES = lib/ldb/ldb_map/ldb_map.o
+# End MODULE libldb_map
+################################################
+
 ################################################
 # Start MODULE libldb_sqlite3
 [MODULE::libldb_sqlite3]
diff --git a/source/lib/ldb/ldb_map/ldb_map.c b/source/lib/ldb/ldb_map/ldb_map.c
new file mode 100644 (file)
index 0000000..39bab2c
--- /dev/null
@@ -0,0 +1,238 @@
+/* 
+   ldb database library - map backend
+
+   Copyright (C) Jelmer Vernooij 2005
+
+     ** 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 "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_private.h"
+#include "lib/ldb/ldb_map/ldb_map.h"
+
+struct map_private {
+       struct ldb_map_mappings *mappings;
+};
+
+static struct ldb_dn *ldb_map_dn(struct ldb_module *module, const struct ldb_dn *dn)
+{
+       /* FIXME */
+       return NULL;
+}
+
+static char *ldb_map_expression(struct ldb_module *module, const char *expr)
+{
+       /* FIXME */
+       return NULL;
+}
+
+static const char **ldb_map_attrs(struct ldb_module *module, const char *const attrs[])
+{
+       /* FIXME */
+       return NULL;
+}
+
+static struct ldb_message *ldb_map_message_incoming(struct ldb_module *module, const struct ldb_message *mi)
+{
+       /* FIXME */
+       return NULL;
+}
+
+static struct ldb_message *ldb_map_message_outgoing(struct ldb_module *module, const struct ldb_message *mi)
+{
+       /* FIXME */
+       return NULL;
+}
+
+/*
+  rename a record
+*/
+static int map_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
+{
+       struct ldb_dn *n_olddn, *n_newdn;
+       int ret;
+       
+       n_olddn = ldb_map_dn(module, olddn);
+       n_newdn = ldb_map_dn(module, newdn);
+
+       ret = ldb_next_rename_record(module, n_olddn, n_newdn);
+
+       talloc_free(n_olddn);
+       talloc_free(n_newdn);
+       
+       return ret;
+}
+
+/*
+  delete a record
+*/
+static int map_delete(struct ldb_module *module, const struct ldb_dn *dn)
+{
+       struct ldb_dn *newdn;
+       int ret;
+
+       newdn = ldb_map_dn(module, dn);
+
+       ret = ldb_next_delete_record(module, newdn);
+
+       talloc_free(newdn);
+
+       return ret;
+}
+
+
+/*
+  search for matching records
+*/
+static int map_search(struct ldb_module *module, const struct ldb_dn *base,
+                      enum ldb_scope scope, const char *expression,
+                      const char * const *attrs, struct ldb_message ***res)
+{
+       char *newexpr;
+       int ret;
+       const char **newattrs;
+       struct ldb_dn *new_base;
+       struct ldb_message **newres;
+       int i;
+
+       newexpr = ldb_map_expression(module, expression);
+       newattrs = ldb_map_attrs(module, attrs); 
+       new_base = ldb_map_dn(module, base);
+
+       ret = ldb_next_search(module, new_base, scope, newexpr, newattrs, &newres);
+
+       talloc_free(new_base);
+       talloc_free(newexpr);
+       talloc_free(newattrs);
+
+       for (i = 0; i < ret; i++) {
+               *res[i] = ldb_map_message_incoming(module, newres[i]);
+               talloc_free(newres[i]);
+       }
+
+       return ret;
+}
+
+/*
+  add a record
+*/
+static int map_add(struct ldb_module *module, const struct ldb_message *msg)
+{
+       struct ldb_message *nmsg = ldb_map_message_outgoing(module, msg);
+       int ret;
+
+       ret = ldb_next_add_record(module, nmsg);
+
+       talloc_free(nmsg);
+
+       return ret;
+}
+
+
+/*
+  search for matching records using a ldb_parse_tree
+*/
+static int map_search_bytree(struct ldb_module *module, const struct ldb_dn *base,
+                             enum ldb_scope scope, struct ldb_parse_tree *tree,
+                             const char * const *attrs, struct ldb_message ***res)
+{
+       struct map_private *privdat = module->private_data;
+       char *expression;
+       int ret;
+
+       expression = ldb_filter_from_tree(privdat, tree);
+       if (expression == NULL) {
+               return -1;
+       }
+       ret = map_search(module, base, scope, expression, attrs, res);
+       talloc_free(expression);
+       return ret;
+}
+
+/*
+  modify a record
+*/
+static int map_modify(struct ldb_module *module, const struct ldb_message *msg)
+{
+       struct ldb_message *nmsg = ldb_map_message_outgoing(module, msg);
+       int ret;
+
+       ret = ldb_next_modify_record(module, nmsg);
+
+       talloc_free(nmsg);
+
+       return ret;
+}
+
+static int map_lock(struct ldb_module *module, const char *lockname)
+{
+       return ldb_next_named_lock(module, lockname);
+}
+
+static int map_unlock(struct ldb_module *module, const char *lockname)
+{
+       return ldb_next_named_unlock(module, lockname);
+}
+
+/*
+  return extended error information
+*/
+static const char *map_errstring(struct ldb_module *module)
+{
+       return ldb_next_errstring(module);
+}
+
+static const struct ldb_module_ops map_ops = {
+       .name          = "map",
+       .search        = map_search,
+       .search_bytree = map_search_bytree,
+       .add_record    = map_add,
+       .modify_record = map_modify,
+       .delete_record = map_delete,
+       .rename_record = map_rename,
+       .named_lock    = map_lock,
+       .named_unlock  = map_unlock,
+       .errstring     = map_errstring
+};
+
+/* the init function */
+struct ldb_module *ldb_map_init(struct ldb_context *ldb, struct ldb_map_mappings *mappings, const char *options[])
+{
+       struct ldb_module *ctx;
+       struct map_private *data;
+
+       ctx = talloc(ldb, struct ldb_module);
+       if (!ctx)
+               return NULL;
+
+       data = talloc(ctx, struct map_private);
+       if (!data) {
+               talloc_free(ctx);
+               return NULL;
+       }
+
+       data->mappings = mappings;
+       ctx->private_data = data;
+       ctx->ldb = ldb;
+       ctx->prev = ctx->next = NULL;
+       ctx->ops = &map_ops;
+
+       return ctx;
+}
index 6d6e47873c12a36614c2c0b6b80b8bb4ce811e47..3ebf2fa9d120a75abd611728d7d46af1afd29f5f 100644 (file)
@@ -1,29 +1,33 @@
-struct objectclass_mapping {
-       char *local_name;
-       char *remote_name;
+/* 
+   ldb database library - map backend
 
-       char *key; /* Name of attribute used in rdn */
+   Copyright (C) Jelmer Vernooij 2005
 
-       /* For mapping attributes used in searches */
-       struct local_attribute_mapping {
-               char *local_name;
+     ** 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.
 
-               /* Attributes to request from the server for this attribute, 
-                * needed by generate */
-               char *required_attributes[]; 
+   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.
 
-               /* If not set, the value for the first element of 
-                * required_attributes will simply be used here */
-               struct ldb_message_element *(*generate) (LDAPMessage *msg); 
-       } *local_attribute_mappings;
+   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
+*/
 
-       /* Generate LDAPMod for adds and modifies */
-       LDAPMod *(*generate_mod)(struct ldb_message *);
-}
+#ifndef __LDB_MAP_H__
+#define __LDB_MAP_H__
+
+struct ldb_map_mappings 
+{
 
-struct ldb_map_backend {
-       struct objectclass_mapping *objectclass_mappings;
 };
 
-const char *ldb_map_dn(const char *old);
-const char *ldb_map_rdn(const char *old);
+#endif /* __LDB_MAP_H__ */
index 75073048d0a08436755c3d603084f4d541e00444..b5bf3fadb92f142b1b205f591c8709640a3ab301 100644 (file)
@@ -10,7 +10,8 @@ ADD_OBJ_FILES = \
                lib/samba3/samba3.o \
                lib/samba3/group.o \
                lib/samba3/registry.o \
-               lib/samba3/secrets.o
+               lib/samba3/secrets.o \
+               lib/samba3/ldb_samba3.o
 # End SUBSYSTEM LIBSAMBA3
 ################################################
 
similarity index 67%
rename from source/lib/ldb/samba/ldb_samba3.c
rename to source/lib/samba3/ldb_samba3.c
index 6a7bfc62988a81130e98ef0b01804575400f9c2d..fa13daa611678e71c90a722482bbb6e360f22880 100644 (file)
 #include "ldb/include/ldb.h"
 #include "ldb/include/ldb_private.h"
 
+/* 
+ * sambaGroupMapping -> group
+ *     gidNumber -> ???
+ *     sambaSID -> member
+ *     sambaGroupType -> groupType
+ *     displayName -> name
+ *     description -> description
+ *     sambaSIDList -> member 
+ */
+
+struct ldb_map_mappings samba3_mappings;
+
+/* the init function */
+#ifdef HAVE_DLOPEN_DISABLED
+ struct ldb_module *init_module(struct ldb_context *ldb, const char *options[])
+#else
+struct ldb_module *ldb_samba3_module_init(struct ldb_context *ldb, const char *options[])
+#endif
+{
+       return ldb_map_init(ldb, &samba3_mappings, options);
+}