summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2010-07-06 15:35:16 +1000
committerAndrew Tridgell <tridge@samba.org>2010-07-07 17:26:03 +1000
commit7f9153f7e8a3a39d23b6b9c1336031f769dce923 (patch)
treef16a27a60dd25fa30cde7c89b5898e9df320acef /source4/lib
parent85504ae6ff72204894ea7a856f0f36b44ad77fe2 (diff)
downloadsamba-7f9153f7e8a3a39d23b6b9c1336031f769dce923.tar.gz
samba-7f9153f7e8a3a39d23b6b9c1336031f769dce923.tar.bz2
samba-7f9153f7e8a3a39d23b6b9c1336031f769dce923.zip
s4-ldb: added ldb_options_find()
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
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/ldb/common/ldb_modules.c8
-rw-r--r--source4/lib/ldb/common/ldb_options.c72
-rw-r--r--source4/lib/ldb/config.mk2
-rw-r--r--source4/lib/ldb/include/ldb_private.h6
-rw-r--r--source4/lib/ldb/ldb.mk2
-rw-r--r--source4/lib/ldb/wscript2
6 files changed, 85 insertions, 7 deletions
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c
index 6e92fc510d..e4e2c1586d 100644
--- a/source4/lib/ldb/common/ldb_modules.c
+++ b/source4/lib/ldb/common/ldb_modules.c
@@ -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
index 0000000000..f806057eb6
--- /dev/null
+++ b/source4/lib/ldb/common/ldb_options.c
@@ -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;
+}
diff --git a/source4/lib/ldb/config.mk b/source4/lib/ldb/config.mk
index 54e1416ed3..dd20e641dd 100644
--- a/source4/lib/ldb/config.mk
+++ b/source4/lib/ldb/config.mk
@@ -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
diff --git a/source4/lib/ldb/include/ldb_private.h b/source4/lib/ldb/include/ldb_private.h
index 0e0a1a206d..aac21c7fe6 100644
--- a/source4/lib/ldb/include/ldb_private.h
+++ b/source4/lib/ldb/include/ldb_private.h
@@ -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
diff --git a/source4/lib/ldb/ldb.mk b/source4/lib/ldb/ldb.mk
index 0c9b115672..ac1a48bad3 100644
--- a/source4/lib/ldb/ldb.mk
+++ b/source4/lib/ldb/ldb.mk
@@ -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
diff --git a/source4/lib/ldb/wscript b/source4/lib/ldb/wscript
index 9de9a5b47e..773925e5c4 100644
--- a/source4/lib/ldb/wscript
+++ b/source4/lib/ldb/wscript
@@ -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: