diff options
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r-- | source4/lib/ldb/common/ldb.c | 2 | ||||
-rw-r--r-- | source4/lib/ldb/common/ldb_msg.c | 47 | ||||
-rw-r--r-- | source4/lib/ldb/common/ldb_parse.c | 18 |
3 files changed, 58 insertions, 9 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c index b8f61e017a..c6e8d37671 100644 --- a/source4/lib/ldb/common/ldb.c +++ b/source4/lib/ldb/common/ldb.c @@ -82,7 +82,7 @@ int ldb_search(struct ldb_context *ldb, const char *base, enum ldb_scope scope, const char *expression, - char * const *attrs, struct ldb_message ***res) + const char * const *attrs, struct ldb_message ***res) { int ret; ret = ldb->ops->search(ldb, base, scope, expression, attrs, res); diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c index 5976db81b6..01f32751e1 100644 --- a/source4/lib/ldb/common/ldb_msg.c +++ b/source4/lib/ldb/common/ldb_msg.c @@ -132,6 +132,53 @@ int ldb_msg_add(struct ldb_context *ldb, } /* + add a value to a message +*/ +int ldb_msg_add_value(struct ldb_context *ldb, + struct ldb_message *msg, + char *attr_name, + struct ldb_val *val) +{ + struct ldb_message_element *el; + struct ldb_val *vals; + + el = ldb_msg_find_element(msg, attr_name); + if (!el) { + ldb_msg_add_empty(ldb, msg, attr_name, 0); + el = ldb_msg_find_element(msg, attr_name); + } + if (!el) { + return -1; + } + + vals = ldb_realloc_p(ldb, el->values, struct ldb_val, el->num_values+1); + if (!vals) { + errno = ENOMEM; + return -1; + } + el->values = vals; + el->values[el->num_values] = *val; + el->num_values++; + + return 0; +} + + +/* + add a string element to a message +*/ +int ldb_msg_add_string(struct ldb_context *ldb, struct ldb_message *msg, + char *attr_name, char *str) +{ + struct ldb_val val; + + val.data = str; + val.length = strlen(str); + + return ldb_msg_add_value(ldb, msg, attr_name, &val); +} + +/* compare two ldb_message_element structures assumes case senistive comparison */ diff --git a/source4/lib/ldb/common/ldb_parse.c b/source4/lib/ldb/common/ldb_parse.c index 75eb44fcc0..5d2a42fd20 100644 --- a/source4/lib/ldb/common/ldb_parse.c +++ b/source4/lib/ldb/common/ldb_parse.c @@ -56,10 +56,12 @@ a filter is defined by: <filtertype> ::= '=' | '~=' | '<=' | '>=' */ +#define LDB_ALL_SEP "()&|=!" + /* return next token element. Caller frees */ -static char *ldb_parse_lex(struct ldb_context *ldb, const char **s) +static char *ldb_parse_lex(struct ldb_context *ldb, const char **s, const char *sep) { const char *p = *s; char *ret; @@ -73,7 +75,7 @@ static char *ldb_parse_lex(struct ldb_context *ldb, const char **s) return NULL; } - if (strchr("()&|=!", *p)) { + if (strchr(sep, *p)) { (*s) = p+1; ret = ldb_strndup(ldb, p, 1); if (!ret) { @@ -82,7 +84,7 @@ static char *ldb_parse_lex(struct ldb_context *ldb, const char **s) return ret; } - while (*p && (isalnum(*p) || !strchr("()&|=!", *p))) { + while (*p && (isalnum(*p) || !strchr(sep, *p))) { p++; } @@ -132,7 +134,7 @@ static struct ldb_parse_tree *ldb_parse_simple(struct ldb_context *ldb, const ch char *eq, *val, *l; struct ldb_parse_tree *ret; - l = ldb_parse_lex(ldb, &s); + l = ldb_parse_lex(ldb, &s, LDB_ALL_SEP); if (!l) { return NULL; } @@ -142,7 +144,7 @@ static struct ldb_parse_tree *ldb_parse_simple(struct ldb_context *ldb, const ch return NULL; } - eq = ldb_parse_lex(ldb, &s); + eq = ldb_parse_lex(ldb, &s, LDB_ALL_SEP); if (!eq || strcmp(eq, "=") != 0) { ldb_free(ldb, l); if (eq) ldb_free(ldb, eq); @@ -150,8 +152,8 @@ static struct ldb_parse_tree *ldb_parse_simple(struct ldb_context *ldb, const ch } ldb_free(ldb, eq); - val = ldb_parse_lex(ldb, &s); - if (val && strchr("()&|=", *val)) { + val = ldb_parse_lex(ldb, &s, ")"); + if (val && strchr("()&|", *val)) { ldb_free(ldb, l); if (val) ldb_free(ldb, val); return NULL; @@ -288,7 +290,7 @@ static struct ldb_parse_tree *ldb_parse_filter(struct ldb_context *ldb, const ch const char *p, *p2; struct ldb_parse_tree *ret; - l = ldb_parse_lex(ldb, s); + l = ldb_parse_lex(ldb, s, LDB_ALL_SEP); if (!l) { return NULL; } |