s4-ldb: added ldb_options_find()
authorAndrew Tridgell <tridge@samba.org>
Tue, 6 Jul 2010 05:35:16 +0000 (15:35 +1000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 7 Jul 2010 07:26:03 +0000 (17:26 +1000)
ldb_options_find() allows backends to find options in the options[]
array passed to the connect operation.

This will be used by the ldb_ldap bind code

source4/lib/ldb/common/ldb_modules.c
source4/lib/ldb/common/ldb_options.c [new file with mode: 0644]
source4/lib/ldb/config.mk
source4/lib/ldb/include/ldb_private.h
source4/lib/ldb/ldb.mk
source4/lib/ldb/wscript

index 6e92fc510d7db6096c13b65ba753842635882487..e4e2c1586d4a37ee7f3201ae8c1db5c9fb90453e 100644 (file)
@@ -397,6 +397,7 @@ int ldb_init_module_chain(struct ldb_context *ldb, struct ldb_module *module)
 
 int ldb_load_modules(struct ldb_context *ldb, const char *options[])
 {
+       const char *modules_string;
        const char **modules = NULL;
        unsigned int i;
        int ret;
@@ -409,10 +410,9 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
 
        /* check if we have a custom module list passd as ldb option */
        if (options) {
-               for (i = 0; options[i] != NULL; i++) {
-                       if (strncmp(options[i], LDB_MODULE_PREFIX, LDB_MODULE_PREFIX_LEN) == 0) {
-                               modules = ldb_modules_list_from_string(ldb, mem_ctx, &options[i][LDB_MODULE_PREFIX_LEN]);
-                       }
+               modules_string = ldb_options_find(ldb, options, "modules");
+               if (modules_string) {
+                       modules = ldb_modules_list_from_string(ldb, mem_ctx, modules_string);
                }
        }
 
diff --git a/source4/lib/ldb/common/ldb_options.c b/source4/lib/ldb/common/ldb_options.c
new file mode 100644 (file)
index 0000000..f806057
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+   ldb database library
+
+   Copyright (C) Andrew Tridgell  2010
+
+     ** 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 3 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, see <http://www.gnu.org/licenses/>.
+*/
+
+/*
+ *  Name: ldb
+ *
+ *  Component: ldb options[] handling
+ *
+ *  Author: Andrew Tridgell
+ */
+
+#include "ldb_private.h"
+
+/*
+  find an option within an options array
+
+  accepts the following forms:
+
+     NAME
+     NAME:value
+     NAME=value
+
+  returns a pointer into an element of the options[] array, or NULL is
+  not found.
+
+  For the NAME form, returns a pointer to an empty string (thus
+  allowing for boolean options).
+ */
+_PRIVATE_ const char *ldb_options_find(struct ldb_context *ldb, const char *options[],
+                                      const char *option_name)
+{
+       size_t len = strlen(option_name);
+       int i;
+
+       if (options == NULL) {
+               return NULL;
+       }
+
+       for (i=0; options[i]; i++) {
+               if (strncmp(option_name, options[i], len) != 0) {
+                       continue;
+               }
+               if (options[i][len] == ':' || options[i][len] == '=') {
+                       return &options[i][len+1];
+               }
+               if (options[i][len] == 0) {
+                       return &options[i][len];
+               }
+       }
+
+       return NULL;
+}
index 54e1416ed30fd18f5e0ce929d1a459cd5cfe964f..dd20e641dd1164b0c658c08187ead90811c32bf6 100644 (file)
@@ -130,7 +130,7 @@ PC_FILES += $(ldbsrcdir)/ldb.pc
 LIBLDB_VERSION = 0.0.1
 LIBLDB_SOVERSION = 0
 
-LIBLDB_OBJ_FILES = $(addprefix $(ldbsrcdir)/common/, ldb.o ldb_ldif.o ldb_parse.o ldb_msg.o ldb_utf8.o ldb_debug.o ldb_modules.o ldb_match.o ldb_attributes.o attrib_handlers.o ldb_dn.o ldb_controls.o qsort.o) $(ldb_map_OBJ_FILES)
+LIBLDB_OBJ_FILES = $(addprefix $(ldbsrcdir)/common/, ldb.o ldb_ldif.o ldb_parse.o ldb_msg.o ldb_utf8.o ldb_debug.o ldb_modules.o ldb_options.o ldb_match.o ldb_attributes.o attrib_handlers.o ldb_dn.o ldb_controls.o qsort.o) $(ldb_map_OBJ_FILES)
 
 $(LIBLDB_OBJ_FILES): CFLAGS+=-I$(ldbsrcdir)/include
 
index 0e0a1a206d671137d6e1922daffa1d2d536f7a1a..aac21c7fe651140f4901e4ba9125dc0eb52a09fd 100644 (file)
@@ -171,4 +171,10 @@ int ldb_init_module_chain(struct ldb_context *ldb, struct ldb_module *module);
 
 struct ldb_val ldb_binary_decode(void *mem_ctx, const char *str);
 
+
+/* The following definitions come from lib/ldb/common/ldb_options.c  */
+
+const char *ldb_options_find(struct ldb_context *ldb, const char *options[],
+                            const char *option_name);
+
 #endif
index 0c9b11567245bfb0f12a1caa0d6a4aae934ec7d6..ac1a48bad3519f796a4705bdab47ac1709d799be 100644 (file)
@@ -15,7 +15,7 @@ LDB_MAP_OBJ=$(LDB_MAP_DIR)/ldb_map.o $(LDB_MAP_DIR)/ldb_map_inbound.o \
 COMDIR=common
 COMMON_OBJ=$(COMDIR)/ldb.o $(COMDIR)/ldb_ldif.o \
           $(COMDIR)/ldb_parse.o $(COMDIR)/ldb_msg.o $(COMDIR)/ldb_utf8.o \
-          $(COMDIR)/ldb_debug.o $(COMDIR)/ldb_modules.o \
+          $(COMDIR)/ldb_debug.o $(COMDIR)/ldb_modules.o $(COMDIR)/ldb_options.o \
           $(COMDIR)/ldb_dn.o $(COMDIR)/ldb_match.o $(COMDIR)/ldb_attributes.o \
           $(COMDIR)/attrib_handlers.o $(COMDIR)/ldb_controls.o $(COMDIR)/qsort.o
 
index 9de9a5b47eb041ae22866e5d29d64ebb1a26bcaa..773925e5c45c56bdbf4a77672440f75c70dd3c0c 100644 (file)
@@ -70,7 +70,7 @@ def build(bld):
 
     COMMON_SRC = bld.SUBDIR('common',
                             '''ldb.c ldb_ldif.c ldb_parse.c ldb_msg.c ldb_utf8.c
-                            ldb_debug.c ldb_dn.c ldb_match.c ldb_modules.c
+                            ldb_debug.c ldb_dn.c ldb_match.c ldb_modules.c ldb_options.c
                             ldb_attributes.c attrib_handlers.c ldb_controls.c qsort.c''')
 
     if s4_build: