summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-06-13 09:10:17 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:18:06 -0500
commit4b0e5bd75373ffa2d847706a71fd0349dfa15e71 (patch)
tree5911c1b644daa5778fb437c43fbccd2ab416504a /source4/lib/ldb/common
parentd71e1a7a7fe363d27a0e8256ccfb4cec425c13b5 (diff)
downloadsamba-4b0e5bd75373ffa2d847706a71fd0349dfa15e71.tar.gz
samba-4b0e5bd75373ffa2d847706a71fd0349dfa15e71.tar.bz2
samba-4b0e5bd75373ffa2d847706a71fd0349dfa15e71.zip
r7527: - added a ldb_search_bytree() interface, which takes a ldb_parse_tree
instead of a search expression. This allows our ldap server to pass its ASN.1 parsed search expressions straight to ldb, instead of going via strings. - updated all the ldb modules code to handle the new interface - got rid of the separate ldb_parse.h now that the ldb_parse structures are exposed externally - moved to C99 structure initialisation in ldb - switched ldap server to using ldb_search_bytree() (This used to be commit 96620ab2ee5d440bbbc51c1bc0cad9977770f897)
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r--source4/lib/ldb/common/ldb.c17
-rw-r--r--source4/lib/ldb/common/ldb_modules.c20
-rw-r--r--source4/lib/ldb/common/ldb_msg.c3
-rw-r--r--source4/lib/ldb/common/ldb_parse.c47
4 files changed, 57 insertions, 30 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index 649b0a0f24..f5c6d551ea 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/lib/ldb/common/ldb.c
@@ -101,6 +101,23 @@ int ldb_search(struct ldb_context *ldb,
}
/*
+ search the database given a LDAP-like search expression
+
+ return the number of records found, or -1 on error
+
+ Use talloc_free to free the ldb_message returned in 'res'
+
+*/
+int ldb_search_bytree(struct ldb_context *ldb,
+ const char *base,
+ enum ldb_scope scope,
+ struct ldb_parse_tree *tree,
+ const char * const *attrs, struct ldb_message ***res)
+{
+ return ldb->modules->ops->search_bytree(ldb->modules, base, scope, tree, attrs, res);
+}
+
+/*
add a record to the database. Will fail if a record with the given class and key
already exists
*/
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c
index 644154d645..7df9901ae9 100644
--- a/source4/lib/ldb/common/ldb_modules.c
+++ b/source4/lib/ldb/common/ldb_modules.c
@@ -213,10 +213,10 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
*/
int ldb_next_search(struct ldb_module *module,
- const char *base,
- enum ldb_scope scope,
- const char *expression,
- const char * const *attrs, struct ldb_message ***res)
+ const char *base,
+ enum ldb_scope scope,
+ const char *expression,
+ const char * const *attrs, struct ldb_message ***res)
{
if (!module->next) {
return -1;
@@ -224,6 +224,18 @@ int ldb_next_search(struct ldb_module *module,
return module->next->ops->search(module->next, base, scope, expression, attrs, res);
}
+int ldb_next_search_bytree(struct ldb_module *module,
+ const char *base,
+ enum ldb_scope scope,
+ struct ldb_parse_tree *tree,
+ const char * const *attrs, struct ldb_message ***res)
+{
+ if (!module->next) {
+ return -1;
+ }
+ return module->next->ops->search_bytree(module->next, base, scope, tree, attrs, res);
+}
+
int ldb_next_add_record(struct ldb_module *module, const struct ldb_message *message)
{
if (!module->next) {
diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c
index 7a6dea049a..8d921b989b 100644
--- a/source4/lib/ldb/common/ldb_msg.c
+++ b/source4/lib/ldb/common/ldb_msg.c
@@ -95,8 +95,7 @@ struct ldb_val *ldb_msg_find_val(const struct ldb_message_element *el,
/*
duplicate a ldb_val structure
*/
-struct ldb_val ldb_val_dup(TALLOC_CTX *mem_ctx,
- const struct ldb_val *v)
+struct ldb_val ldb_val_dup(void *mem_ctx, const struct ldb_val *v)
{
struct ldb_val v2;
v2.length = v->length;
diff --git a/source4/lib/ldb/common/ldb_parse.c b/source4/lib/ldb/common/ldb_parse.c
index e2eb0f8c78..afcda60e8e 100644
--- a/source4/lib/ldb/common/ldb_parse.c
+++ b/source4/lib/ldb/common/ldb_parse.c
@@ -43,7 +43,6 @@
#include "includes.h"
#include "ldb/include/ldb.h"
-#include "ldb/include/ldb_parse.h"
#include <ctype.h>
@@ -64,7 +63,7 @@ a filter is defined by:
/*
return next token element. Caller frees
*/
-static char *ldb_parse_lex(TALLOC_CTX *ctx, const char **s, const char *sep)
+static char *ldb_parse_lex(void *ctx, const char **s, const char *sep)
{
const char *p = *s;
char *ret;
@@ -130,13 +129,13 @@ static const char *match_brace(const char *s)
decode a RFC2254 binary string representation of a buffer.
Used in LDAP filters.
*/
-struct ldb_val ldb_binary_decode(TALLOC_CTX *ctx, const char *str)
+struct ldb_val ldb_binary_decode(void *mem_ctx, const char *str)
{
int i, j;
struct ldb_val ret;
int slen = str?strlen(str):0;
- ret.data = talloc_size(ctx, slen+1);
+ ret.data = talloc_size(mem_ctx, slen+1);
ret.length = 0;
if (ret.data == NULL) return ret;
@@ -165,7 +164,7 @@ struct ldb_val ldb_binary_decode(TALLOC_CTX *ctx, const char *str)
encode a blob as a RFC2254 binary string, escaping any
non-printable or '\' characters
*/
-char *ldb_binary_encode(TALLOC_CTX *ctx, struct ldb_val val)
+char *ldb_binary_encode(void *mem_ctx, struct ldb_val val)
{
int i;
char *ret;
@@ -177,7 +176,7 @@ char *ldb_binary_encode(TALLOC_CTX *ctx, struct ldb_val val)
len += 2;
}
}
- ret = talloc_array(ctx, char, len+1);
+ ret = talloc_array(mem_ctx, char, len+1);
if (ret == NULL) return NULL;
len = 0;
@@ -195,17 +194,17 @@ char *ldb_binary_encode(TALLOC_CTX *ctx, struct ldb_val val)
return ret;
}
-static struct ldb_parse_tree *ldb_parse_filter(TALLOC_CTX *ctx, const char **s);
+static struct ldb_parse_tree *ldb_parse_filter(void *mem_ctx, const char **s);
/*
<simple> ::= <attributetype> <filtertype> <attributevalue>
*/
-static struct ldb_parse_tree *ldb_parse_simple(TALLOC_CTX *ctx, const char *s)
+static struct ldb_parse_tree *ldb_parse_simple(void *mem_ctx, const char *s)
{
char *eq, *val, *l;
struct ldb_parse_tree *ret;
- ret = talloc(ctx, struct ldb_parse_tree);
+ ret = talloc(mem_ctx, struct ldb_parse_tree);
if (!ret) {
errno = ENOMEM;
return NULL;
@@ -249,12 +248,12 @@ static struct ldb_parse_tree *ldb_parse_simple(TALLOC_CTX *ctx, const char *s)
<or> ::= '|' <filterlist>
<filterlist> ::= <filter> | <filter> <filterlist>
*/
-static struct ldb_parse_tree *ldb_parse_filterlist(TALLOC_CTX *ctx,
+static struct ldb_parse_tree *ldb_parse_filterlist(void *mem_ctx,
enum ldb_parse_op op, const char *s)
{
struct ldb_parse_tree *ret, *next;
- ret = talloc(ctx, struct ldb_parse_tree);
+ ret = talloc(mem_ctx, struct ldb_parse_tree);
if (!ret) {
errno = ENOMEM;
return NULL;
@@ -300,11 +299,11 @@ static struct ldb_parse_tree *ldb_parse_filterlist(TALLOC_CTX *ctx,
/*
<not> ::= '!' <filter>
*/
-static struct ldb_parse_tree *ldb_parse_not(TALLOC_CTX *ctx, const char *s)
+static struct ldb_parse_tree *ldb_parse_not(void *mem_ctx, const char *s)
{
struct ldb_parse_tree *ret;
- ret = talloc(ctx, struct ldb_parse_tree);
+ ret = talloc(mem_ctx, struct ldb_parse_tree);
if (!ret) {
errno = ENOMEM;
return NULL;
@@ -324,39 +323,39 @@ static struct ldb_parse_tree *ldb_parse_not(TALLOC_CTX *ctx, const char *s)
parse a filtercomp
<filtercomp> ::= <and> | <or> | <not> | <simple>
*/
-static struct ldb_parse_tree *ldb_parse_filtercomp(TALLOC_CTX *ctx, const char *s)
+static struct ldb_parse_tree *ldb_parse_filtercomp(void *mem_ctx, const char *s)
{
while (isspace(*s)) s++;
switch (*s) {
case '&':
- return ldb_parse_filterlist(ctx, LDB_OP_AND, s+1);
+ return ldb_parse_filterlist(mem_ctx, LDB_OP_AND, s+1);
case '|':
- return ldb_parse_filterlist(ctx, LDB_OP_OR, s+1);
+ return ldb_parse_filterlist(mem_ctx, LDB_OP_OR, s+1);
case '!':
- return ldb_parse_not(ctx, s+1);
+ return ldb_parse_not(mem_ctx, s+1);
case '(':
case ')':
return NULL;
}
- return ldb_parse_simple(ctx, s);
+ return ldb_parse_simple(mem_ctx, s);
}
/*
<filter> ::= '(' <filtercomp> ')'
*/
-static struct ldb_parse_tree *ldb_parse_filter(TALLOC_CTX *ctx, const char **s)
+static struct ldb_parse_tree *ldb_parse_filter(void *mem_ctx, const char **s)
{
char *l, *s2;
const char *p, *p2;
struct ldb_parse_tree *ret;
- l = ldb_parse_lex(ctx, s, LDB_ALL_SEP);
+ l = ldb_parse_lex(mem_ctx, s, LDB_ALL_SEP);
if (!l) {
return NULL;
}
@@ -373,13 +372,13 @@ static struct ldb_parse_tree *ldb_parse_filter(TALLOC_CTX *ctx, const char **s)
}
p2 = p + 1;
- s2 = talloc_strndup(ctx, *s, p - *s);
+ s2 = talloc_strndup(mem_ctx, *s, p - *s);
if (!s2) {
errno = ENOMEM;
return NULL;
}
- ret = ldb_parse_filtercomp(ctx, s2);
+ ret = ldb_parse_filtercomp(mem_ctx, s2);
talloc_free(s2);
*s = p2;
@@ -393,7 +392,7 @@ static struct ldb_parse_tree *ldb_parse_filter(TALLOC_CTX *ctx, const char **s)
expression ::= <simple> | <filter>
*/
-struct ldb_parse_tree *ldb_parse_tree(TALLOC_CTX *mem_ctx, const char *s)
+struct ldb_parse_tree *ldb_parse_tree(void *mem_ctx, const char *s)
{
while (isspace(*s)) s++;
@@ -408,7 +407,7 @@ struct ldb_parse_tree *ldb_parse_tree(TALLOC_CTX *mem_ctx, const char *s)
/*
construct a ldap parse filter given a parse tree
*/
-char *ldb_filter_from_tree(TALLOC_CTX *mem_ctx, struct ldb_parse_tree *tree)
+char *ldb_filter_from_tree(void *mem_ctx, struct ldb_parse_tree *tree)
{
char *s, *s2, *ret;
int i;