From a06d66a3a669c3a0a0f816438e2b3e91e208f398 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 1 Jul 2005 06:21:26 +0000 Subject: r8037: a fairly major update to the internals of ldb. Changes are: - moved the knowledge of attribute types out of ldb_tdb and into the generic ldb code. This allows the ldb_match() message match logic to be generic, so it can be used by other backend - added the generic ability to load attribute handlers, for canonicalisation, compare, ldif read and ldif write. In the future this will be used by the schema module to allow us to correctly obey the attributetype schema elements - added attribute handlers for some of the core ldap attribute types, Integer, DirectoryString, DN, ObjectClass etc - added automatic registration of attribute handlers for well-known attribute names 'cn', 'dc', 'dn', 'ou' and 'objectClass' - converted the objectSid special handlers for Samba to the new system - added more correct handling of indexing in tdb backend based on the attribute canonicalisation function - added generic support for subclasses, moving it out of the tdb backend. This will be used in future by the schema module - fixed several bugs in the dn_explode code. It still needs more work, but doesn't corrupt ldb dbs any more. (This used to be commit 944c5844ab441b96d8e5d7b2d151982139d1fab9) --- source4/lib/ldb/common/attrib_handlers.c | 335 +++++++++++++++++++++++++++++++ 1 file changed, 335 insertions(+) create mode 100644 source4/lib/ldb/common/attrib_handlers.c (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c new file mode 100644 index 0000000000..fcff4113b4 --- /dev/null +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -0,0 +1,335 @@ +/* + ldb database library + + Copyright (C) Andrew Tridgell 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 +*/ +/* + attribute handlers for well known attribute types, selected by syntax OID + see rfc2252 +*/ + +#include "includes.h" +#include "ldb/include/ldb.h" +#include "ldb/include/ldb_private.h" +#include + +/* + default handler that just copies a ldb_val. +*/ +int ldb_handler_copy(struct ldb_context *ldb, + const struct ldb_val *in, struct ldb_val *out) +{ + *out = ldb_val_dup(ldb, in); + if (out->data == NULL) { + ldb_oom(ldb); + return -1; + } + return 0; +} + +/* + a case folding copy handler, removing leading and trailing spaces and + multiple internal spaces +*/ +static int ldb_handler_fold(struct ldb_context *ldb, + const struct ldb_val *in, struct ldb_val *out) +{ + uint8_t *s1, *s2; + out->data = talloc_size(ldb, strlen(in->data)+1); + if (out->data == NULL) { + ldb_oom(ldb); + return -1; + } + s1 = in->data; + s2 = out->data; + while (*s1 == ' ') s1++; + while (*s1) { + *s2 = toupper(*s1); + if (s1[0] == ' ') { + while (s1[0] == s1[1]) s1++; + } + s2++; s1++; + } + *s2 = 0; + out->length = strlen(out->data); + return 0; +} + + +/* + a case folding copy handler, removing leading and trailing spaces and + multiple internal spaces, and checking for wildcard characters +*/ +static int ldb_handler_fold_wildcard(struct ldb_context *ldb, + const struct ldb_val *in, struct ldb_val *out) +{ + if (strchr(in->data, '*')) { + return -1; + } + return ldb_handler_fold(ldb, in, out); +} + +/* + canonicalise a ldap Integer + rfc2252 specifies it should be in decimal form +*/ +static int ldb_canonicalise_Integer(struct ldb_context *ldb, + const struct ldb_val *in, struct ldb_val *out) +{ + char *end; + long long i = strtoll(in->data, &end, 0); + if (*end != 0) { + return -1; + } + out->data = talloc_asprintf(ldb, "%lld", i); + if (out->data == NULL) { + return -1; + } + out->length = strlen(out->data); + return 0; +} + +/* + compare two Integers +*/ +static int ldb_comparison_Integer(struct ldb_context *ldb, + const struct ldb_val *v1, const struct ldb_val *v2) +{ + return strtoll(v1->data, NULL, 0) - strtoll(v2->data, NULL, 0); +} + +/* + compare two binary blobs +*/ +int ldb_comparison_binary(struct ldb_context *ldb, + const struct ldb_val *v1, const struct ldb_val *v2) +{ + if (v1->length != v2->length) { + return v1->length - v2->length; + } + return memcmp(v1->data, v2->data, v1->length); +} + +/* + compare two case insensitive strings, ignoring multiple whitespace + and leading and trailing whitespace + see rfc2252 section 8.1 +*/ +static int ldb_comparison_fold(struct ldb_context *ldb, + const struct ldb_val *v1, const struct ldb_val *v2) +{ + const char *s1=v1->data, *s2=v2->data; + while (*s1 == ' ') s1++; + while (*s2 == ' ') s2++; + /* TODO: make utf8 safe, possibly with helper function from application */ + while (*s1 && *s2) { + if (toupper(*s1) != toupper(*s2)) break; + if (*s1 == ' ') { + while (s1[0] == s1[1]) s1++; + while (s2[0] == s2[1]) s2++; + } + s1++; s2++; + } + while (*s1 == ' ') s1++; + while (*s2 == ' ') s2++; + return (int)(*s1) - (int)(*s2); +} + +/* + compare two case insensitive strings, ignoring multiple whitespace + and leading and trailing whitespace + see rfc2252 section 8.1 + handles wildcards +*/ +static int ldb_comparison_fold_wildcard(struct ldb_context *ldb, + const struct ldb_val *v1, + const struct ldb_val *v2) +{ + const char *s1=v1->data, *s2=v2->data; + while (*s1 == ' ') s1++; + while (*s2 == ' ') s2++; + /* TODO: make utf8 safe, possibly with helper function from application */ + while (*s1 && *s2) { + if (s1[0] == '*' && s1[1] == 0) { + return 0; + } + if (toupper(*s1) != toupper(*s2)) break; + if (*s1 == ' ') { + while (s1[0] == s1[1]) s1++; + while (s2[0] == s2[1]) s2++; + } + s1++; s2++; + } + while (*s1 == ' ') s1++; + while (*s2 == ' ') s2++; + return (int)(*s1) - (int)(*s2); +} + + +/* + canonicalise a attribute in DN format +*/ +static int ldb_canonicalise_dn(struct ldb_context *ldb, + const struct ldb_val *in, struct ldb_val *out) +{ + struct ldb_dn *dn2=NULL, *dn1 = ldb_dn_explode(ldb, in->data); + out->data = NULL; + if (dn1 == NULL) { + goto failed; + } + dn2 = ldb_dn_casefold(ldb, dn1); + if (dn2 == NULL) goto failed; + + out->data = ldb_dn_linearize(ldb, dn2); + if (out->data == NULL) goto failed; + + talloc_free(dn1); + talloc_free(dn2); + return 0; + +failed: + talloc_free(dn1); + talloc_free(dn2); + return -1; +} + +/* + compare two dns +*/ +static int ldb_comparison_dn(struct ldb_context *ldb, + const struct ldb_val *v1, const struct ldb_val *v2) +{ + struct ldb_val cv1, cv2; + int ret; + if (ldb_canonicalise_dn(ldb, v1, &cv1) != 0 || + ldb_canonicalise_dn(ldb, v2, &cv2) != 0) { + goto failed; + } + ret = strcmp(cv1.data, cv2.data); + talloc_free(cv1.data); + talloc_free(cv2.data); + return ret; +failed: + talloc_free(cv1.data); + talloc_free(cv2.data); + return -1; +} + +/* + compare two objectclasses, looking at subclasses +*/ +static int ldb_comparison_objectclass(struct ldb_context *ldb, + const struct ldb_val *v1, const struct ldb_val *v2) +{ + int ret, i; + const char **subclasses; + ret = ldb_comparison_fold(ldb, v1, v2); + if (ret == 0) { + return 0; + } + fprintf(stderr, "looing for %s %s\n", v1->data, v2->data); + subclasses = ldb_subclass_list(ldb, v1->data); + if (subclasses == NULL) { + return ret; + } + for (i=0;subclasses[i];i++) { + struct ldb_val vs; + vs.data = discard_const(subclasses[i]); + vs.length = strlen(subclasses[i]); + if (ldb_comparison_objectclass(ldb, &vs, v2) == 0) { + return 0; + } + } + return ret; +} + +/* + table of standard attribute handlers +*/ +static const struct ldb_attrib_handler ldb_standard_attribs[] = { + { + .attr = LDB_SYNTAX_INTEGER, + .flags = 0, + .ldif_read_fn = ldb_handler_copy, + .ldif_write_fn = ldb_handler_copy, + .canonicalise_fn = ldb_canonicalise_Integer, + .comparison_fn = ldb_comparison_Integer + }, + { + .attr = LDB_SYNTAX_OCTET_STRING, + .flags = 0, + .ldif_read_fn = ldb_handler_copy, + .ldif_write_fn = ldb_handler_copy, + .canonicalise_fn = ldb_handler_copy, + .comparison_fn = ldb_comparison_binary + }, + { + .attr = LDB_SYNTAX_DIRECTORY_STRING, + .flags = 0, + .ldif_read_fn = ldb_handler_copy, + .ldif_write_fn = ldb_handler_copy, + .canonicalise_fn = ldb_handler_fold, + .comparison_fn = ldb_comparison_fold + }, + { + .attr = LDB_SYNTAX_WILDCARD, + .flags = LDB_ATTR_FLAG_WILDCARD, + .ldif_read_fn = ldb_handler_copy, + .ldif_write_fn = ldb_handler_copy, + .canonicalise_fn = ldb_handler_fold_wildcard, + .comparison_fn = ldb_comparison_fold_wildcard + }, + { + .attr = LDB_SYNTAX_DN, + .flags = 0, + .ldif_read_fn = ldb_handler_copy, + .ldif_write_fn = ldb_handler_copy, + .canonicalise_fn = ldb_canonicalise_dn, + .comparison_fn = ldb_comparison_dn + }, + { + .attr = LDB_SYNTAX_OBJECTCLASS, + .flags = 0, + .ldif_read_fn = ldb_handler_copy, + .ldif_write_fn = ldb_handler_copy, + .canonicalise_fn = ldb_handler_fold, + .comparison_fn = ldb_comparison_objectclass + } +}; + + +/* + return the attribute handlers for a given syntax name +*/ +const struct ldb_attrib_handler *ldb_attrib_handler_syntax(struct ldb_context *ldb, + const char *syntax) +{ + int i; + unsigned num_handlers = sizeof(ldb_standard_attribs)/sizeof(ldb_standard_attribs[0]); + /* TODO: should be replaced with a binary search */ + for (i=0;i Date: Fri, 1 Jul 2005 08:04:48 +0000 Subject: r8041: remove a mis-spelled debug message :-) (This used to be commit 912fa269d293b3b55fc5fa65f9532614fe2e202d) --- source4/lib/ldb/common/attrib_handlers.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index fcff4113b4..6c5692bcbe 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -245,7 +245,6 @@ static int ldb_comparison_objectclass(struct ldb_context *ldb, if (ret == 0) { return 0; } - fprintf(stderr, "looing for %s %s\n", v1->data, v2->data); subclasses = ldb_subclass_list(ldb, v1->data); if (subclasses == NULL) { return ret; -- cgit From 1c5105065a44173667de2a022dd2417e56b527d6 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 2 Jul 2005 17:30:03 +0000 Subject: r8082: large rewite of ldb_dn.c - we do not support multpiple attribute components anymore, makes code a lot easier they will be readded later if we found out they are really used, so far my tests show w2k3 do not handle them as well - fix escaping issues, move component value to be in an ldb_val structure still need to handle binary values case - make cononicalize functions leak less memory by giving a specific memory context - fix tests scripts so that test-ldap can start - make test not delete databases on completion so that I can inspect them (This used to be commit 624a73148d125690ce18515f19231d26df207738) --- source4/lib/ldb/common/attrib_handlers.c | 68 ++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 29 deletions(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index 6c5692bcbe..a35a450670 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -34,10 +34,10 @@ /* default handler that just copies a ldb_val. */ -int ldb_handler_copy(struct ldb_context *ldb, +int ldb_handler_copy(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *in, struct ldb_val *out) { - *out = ldb_val_dup(ldb, in); + *out = ldb_val_dup(mem_ctx, in); if (out->data == NULL) { ldb_oom(ldb); return -1; @@ -49,11 +49,11 @@ int ldb_handler_copy(struct ldb_context *ldb, a case folding copy handler, removing leading and trailing spaces and multiple internal spaces */ -static int ldb_handler_fold(struct ldb_context *ldb, +static int ldb_handler_fold(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *in, struct ldb_val *out) { uint8_t *s1, *s2; - out->data = talloc_size(ldb, strlen(in->data)+1); + out->data = talloc_size(mem_ctx, strlen(in->data)+1); if (out->data == NULL) { ldb_oom(ldb); return -1; @@ -78,20 +78,20 @@ static int ldb_handler_fold(struct ldb_context *ldb, a case folding copy handler, removing leading and trailing spaces and multiple internal spaces, and checking for wildcard characters */ -static int ldb_handler_fold_wildcard(struct ldb_context *ldb, +static int ldb_handler_fold_wildcard(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *in, struct ldb_val *out) { if (strchr(in->data, '*')) { return -1; } - return ldb_handler_fold(ldb, in, out); + return ldb_handler_fold(ldb, mem_ctx, in, out); } /* canonicalise a ldap Integer rfc2252 specifies it should be in decimal form */ -static int ldb_canonicalise_Integer(struct ldb_context *ldb, +static int ldb_canonicalise_Integer(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *in, struct ldb_val *out) { char *end; @@ -99,7 +99,7 @@ static int ldb_canonicalise_Integer(struct ldb_context *ldb, if (*end != 0) { return -1; } - out->data = talloc_asprintf(ldb, "%lld", i); + out->data = talloc_asprintf(mem_ctx, "%lld", i); if (out->data == NULL) { return -1; } @@ -110,7 +110,7 @@ static int ldb_canonicalise_Integer(struct ldb_context *ldb, /* compare two Integers */ -static int ldb_comparison_Integer(struct ldb_context *ldb, +static int ldb_comparison_Integer(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *v1, const struct ldb_val *v2) { return strtoll(v1->data, NULL, 0) - strtoll(v2->data, NULL, 0); @@ -119,7 +119,7 @@ static int ldb_comparison_Integer(struct ldb_context *ldb, /* compare two binary blobs */ -int ldb_comparison_binary(struct ldb_context *ldb, +int ldb_comparison_binary(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *v1, const struct ldb_val *v2) { if (v1->length != v2->length) { @@ -133,7 +133,7 @@ int ldb_comparison_binary(struct ldb_context *ldb, and leading and trailing whitespace see rfc2252 section 8.1 */ -static int ldb_comparison_fold(struct ldb_context *ldb, +static int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *v1, const struct ldb_val *v2) { const char *s1=v1->data, *s2=v2->data; @@ -159,7 +159,8 @@ static int ldb_comparison_fold(struct ldb_context *ldb, see rfc2252 section 8.1 handles wildcards */ -static int ldb_comparison_fold_wildcard(struct ldb_context *ldb, +static int ldb_comparison_fold_wildcard(struct ldb_context *ldb, + void *mem_ctx, const struct ldb_val *v1, const struct ldb_val *v2) { @@ -187,40 +188,49 @@ static int ldb_comparison_fold_wildcard(struct ldb_context *ldb, /* canonicalise a attribute in DN format */ -static int ldb_canonicalise_dn(struct ldb_context *ldb, +static int ldb_canonicalise_dn(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *in, struct ldb_val *out) { - struct ldb_dn *dn2=NULL, *dn1 = ldb_dn_explode(ldb, in->data); + struct ldb_dn *dn1, *dn2; + int ret = -1; + + out->length = 0; out->data = NULL; + + dn1 = ldb_dn_explode(mem_ctx, in->data); if (dn1 == NULL) { - goto failed; + return -1; } dn2 = ldb_dn_casefold(ldb, dn1); - if (dn2 == NULL) goto failed; + if (dn2 == NULL) { + goto done; + } - out->data = ldb_dn_linearize(ldb, dn2); - if (out->data == NULL) goto failed; + out->data = ldb_dn_linearize(mem_ctx, dn2); + if (out->data == NULL) { + goto done; + } + out->length = strlen(out->data); - talloc_free(dn1); - talloc_free(dn2); - return 0; + ret = 0; -failed: +done: talloc_free(dn1); talloc_free(dn2); - return -1; + + return ret; } /* compare two dns */ -static int ldb_comparison_dn(struct ldb_context *ldb, +static int ldb_comparison_dn(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *v1, const struct ldb_val *v2) { struct ldb_val cv1, cv2; int ret; - if (ldb_canonicalise_dn(ldb, v1, &cv1) != 0 || - ldb_canonicalise_dn(ldb, v2, &cv2) != 0) { + if (ldb_canonicalise_dn(ldb, mem_ctx, v1, &cv1) != 0 || + ldb_canonicalise_dn(ldb, mem_ctx, v2, &cv2) != 0) { goto failed; } ret = strcmp(cv1.data, cv2.data); @@ -236,12 +246,12 @@ failed: /* compare two objectclasses, looking at subclasses */ -static int ldb_comparison_objectclass(struct ldb_context *ldb, +static int ldb_comparison_objectclass(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *v1, const struct ldb_val *v2) { int ret, i; const char **subclasses; - ret = ldb_comparison_fold(ldb, v1, v2); + ret = ldb_comparison_fold(ldb, mem_ctx, v1, v2); if (ret == 0) { return 0; } @@ -253,7 +263,7 @@ static int ldb_comparison_objectclass(struct ldb_context *ldb, struct ldb_val vs; vs.data = discard_const(subclasses[i]); vs.length = strlen(subclasses[i]); - if (ldb_comparison_objectclass(ldb, &vs, v2) == 0) { + if (ldb_comparison_objectclass(ldb, mem_ctx, &vs, v2) == 0) { return 0; } } -- cgit From c9b0e86a436b5b169a4c33bd25eac379cb622b17 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 12 Jul 2005 12:04:54 +0000 Subject: r8373: New wildcard matching code. This code applies correct ldap standard wildcard matching code removes WILDCARD matching from tdb @ATTRIBUTES, that's now handled independently adds some more tests for wildcard matching fixes dn comparison code in ldb_match (This used to be commit 4eb5863042011988d85092d7dde3d809aa15bd59) --- source4/lib/ldb/common/attrib_handlers.c | 95 +++++++------------------------- 1 file changed, 20 insertions(+), 75 deletions(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index a35a450670..7f71d3574a 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -74,19 +74,6 @@ static int ldb_handler_fold(struct ldb_context *ldb, void *mem_ctx, } -/* - a case folding copy handler, removing leading and trailing spaces and - multiple internal spaces, and checking for wildcard characters -*/ -static int ldb_handler_fold_wildcard(struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *in, struct ldb_val *out) -{ - if (strchr(in->data, '*')) { - return -1; - } - return ldb_handler_fold(ldb, mem_ctx, in, out); -} - /* canonicalise a ldap Integer rfc2252 specifies it should be in decimal form @@ -153,60 +140,24 @@ static int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, return (int)(*s1) - (int)(*s2); } -/* - compare two case insensitive strings, ignoring multiple whitespace - and leading and trailing whitespace - see rfc2252 section 8.1 - handles wildcards -*/ -static int ldb_comparison_fold_wildcard(struct ldb_context *ldb, - void *mem_ctx, - const struct ldb_val *v1, - const struct ldb_val *v2) -{ - const char *s1=v1->data, *s2=v2->data; - while (*s1 == ' ') s1++; - while (*s2 == ' ') s2++; - /* TODO: make utf8 safe, possibly with helper function from application */ - while (*s1 && *s2) { - if (s1[0] == '*' && s1[1] == 0) { - return 0; - } - if (toupper(*s1) != toupper(*s2)) break; - if (*s1 == ' ') { - while (s1[0] == s1[1]) s1++; - while (s2[0] == s2[1]) s2++; - } - s1++; s2++; - } - while (*s1 == ' ') s1++; - while (*s2 == ' ') s2++; - return (int)(*s1) - (int)(*s2); -} - - /* canonicalise a attribute in DN format */ static int ldb_canonicalise_dn(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *in, struct ldb_val *out) { - struct ldb_dn *dn1, *dn2; + struct ldb_dn *dn; int ret = -1; out->length = 0; out->data = NULL; - dn1 = ldb_dn_explode(mem_ctx, in->data); - if (dn1 == NULL) { + dn = ldb_dn_explode_casefold(ldb, in->data); + if (dn == NULL) { return -1; } - dn2 = ldb_dn_casefold(ldb, dn1); - if (dn2 == NULL) { - goto done; - } - out->data = ldb_dn_linearize(mem_ctx, dn2); + out->data = ldb_dn_linearize(mem_ctx, dn); if (out->data == NULL) { goto done; } @@ -215,8 +166,7 @@ static int ldb_canonicalise_dn(struct ldb_context *ldb, void *mem_ctx, ret = 0; done: - talloc_free(dn1); - talloc_free(dn2); + talloc_free(dn); return ret; } @@ -227,20 +177,23 @@ done: static int ldb_comparison_dn(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *v1, const struct ldb_val *v2) { - struct ldb_val cv1, cv2; + struct ldb_dn *dn1 = NULL, *dn2 = NULL; int ret; - if (ldb_canonicalise_dn(ldb, mem_ctx, v1, &cv1) != 0 || - ldb_canonicalise_dn(ldb, mem_ctx, v2, &cv2) != 0) { - goto failed; - } - ret = strcmp(cv1.data, cv2.data); - talloc_free(cv1.data); - talloc_free(cv2.data); + + dn1 = ldb_dn_explode_casefold(mem_ctx, v1->data); + if (dn1 == NULL) return -1; + + dn2 = ldb_dn_explode_casefold(mem_ctx, v2->data); + if (dn2 == NULL) { + talloc_free(dn1); + return -1; + } + + ret = ldb_dn_compare(ldb, dn1, dn2); + + talloc_free(dn1); + talloc_free(dn2); return ret; -failed: - talloc_free(cv1.data); - talloc_free(cv2.data); - return -1; } /* @@ -298,14 +251,6 @@ static const struct ldb_attrib_handler ldb_standard_attribs[] = { .canonicalise_fn = ldb_handler_fold, .comparison_fn = ldb_comparison_fold }, - { - .attr = LDB_SYNTAX_WILDCARD, - .flags = LDB_ATTR_FLAG_WILDCARD, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_handler_fold_wildcard, - .comparison_fn = ldb_comparison_fold_wildcard - }, { .attr = LDB_SYNTAX_DN, .flags = 0, -- cgit From 61edb97bdfabf1ab313fbec5f47f5e6c8a79da1a Mon Sep 17 00:00:00 2001 From: Love Hörnquist Åstrand Date: Tue, 12 Jul 2005 22:22:59 +0000 Subject: r8394: Make sure the argument to ctype is*(3) macros are unsigned char as required by ISO C99. (This used to be commit 56fd21c806e816cf4c3d23881f26474f858b45e2) --- source4/lib/ldb/common/attrib_handlers.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index 7f71d3574a..da2d945419 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -128,7 +128,8 @@ static int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, while (*s2 == ' ') s2++; /* TODO: make utf8 safe, possibly with helper function from application */ while (*s1 && *s2) { - if (toupper(*s1) != toupper(*s2)) break; + if (toupper((unsigned char)*s1) != toupper((unsigned char)*s2)) + break; if (*s1 == ' ') { while (s1[0] == s1[1]) s1++; while (s2[0] == s2[1]) s2++; -- cgit From fe1ee4494e172ea8045b4847806241e9dfaefeef Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 29 Aug 2005 23:20:40 +0000 Subject: r9766: Prevent erroneous OOM message ldb_dup_val() sets out->data to NULL if in->length == 0 (This used to be commit 7ecb6988e74f4273b2ca3ea76562117e1be54b08) --- source4/lib/ldb/common/attrib_handlers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index da2d945419..412146360c 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -38,7 +38,7 @@ int ldb_handler_copy(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *in, struct ldb_val *out) { *out = ldb_val_dup(mem_ctx, in); - if (out->data == NULL) { + if (in->length > 0 && out->data == NULL) { ldb_oom(ldb); return -1; } -- cgit From 8bfcb31b0e01d42532db5837b1f0a070eb076bb1 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Thu, 15 Sep 2005 23:06:57 +0000 Subject: r10250: the comparison is caseless so we must caseless subtract otherwise we get the wrong result when comparing upper case chars with lower case chars (This used to be commit f6ea6e9382f954be819ec82e28598cdf9cf88661) --- source4/lib/ldb/common/attrib_handlers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index 412146360c..61ca566570 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -138,7 +138,7 @@ static int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, } while (*s1 == ' ') s1++; while (*s2 == ' ') s2++; - return (int)(*s1) - (int)(*s2); + return (int)(toupper(*s1)) - (int)(toupper(*s2)); } /* -- cgit From a599edf04cbdeef9014923ba0d3713b8ff84f266 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 12 Oct 2005 06:10:23 +0000 Subject: r10913: This patch isn't as big as it looks ... most of the changes are fixes to make all the ldb code compile without warnings on gcc4. Unfortunately That required a lot of casts :-( I have also added the start of an 'operational' module, which will replace the timestamp module, plus add support for some other operational attributes In ldb_msg_*() I added some new utility functions to make the operational module sane, and remove the 'ldb' argument from the ldb_msg_add_*() functions. That argument was only needed back in the early days of ldb when we didn't use the hierarchical talloc and thus needed a place to get the allocation function from. Now its just a pain to pass around everywhere. Also added a ldb_debug_set() function that calls ldb_debug() plus sets the result using ldb_set_errstring(). That saves on some awkward coding in a few places. (This used to be commit f6818daecca95760c12f79fd307770cbe3346f57) --- source4/lib/ldb/common/attrib_handlers.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index 61ca566570..d073203b3c 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -53,7 +53,7 @@ static int ldb_handler_fold(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *in, struct ldb_val *out) { uint8_t *s1, *s2; - out->data = talloc_size(mem_ctx, strlen(in->data)+1); + out->data = talloc_size(mem_ctx, strlen((char *)in->data)+1); if (out->data == NULL) { ldb_oom(ldb); return -1; @@ -69,7 +69,7 @@ static int ldb_handler_fold(struct ldb_context *ldb, void *mem_ctx, s2++; s1++; } *s2 = 0; - out->length = strlen(out->data); + out->length = strlen((char *)out->data); return 0; } @@ -82,15 +82,15 @@ static int ldb_canonicalise_Integer(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *in, struct ldb_val *out) { char *end; - long long i = strtoll(in->data, &end, 0); + long long i = strtoll((char *)in->data, &end, 0); if (*end != 0) { return -1; } - out->data = talloc_asprintf(mem_ctx, "%lld", i); + out->data = (uint8_t *)talloc_asprintf(mem_ctx, "%lld", i); if (out->data == NULL) { return -1; } - out->length = strlen(out->data); + out->length = strlen((char *)out->data); return 0; } @@ -100,7 +100,7 @@ static int ldb_canonicalise_Integer(struct ldb_context *ldb, void *mem_ctx, static int ldb_comparison_Integer(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *v1, const struct ldb_val *v2) { - return strtoll(v1->data, NULL, 0) - strtoll(v2->data, NULL, 0); + return strtoll((char *)v1->data, NULL, 0) - strtoll((char *)v2->data, NULL, 0); } /* @@ -123,7 +123,7 @@ int ldb_comparison_binary(struct ldb_context *ldb, void *mem_ctx, static int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *v1, const struct ldb_val *v2) { - const char *s1=v1->data, *s2=v2->data; + const char *s1=(const char *)v1->data, *s2=(const char *)v2->data; while (*s1 == ' ') s1++; while (*s2 == ' ') s2++; /* TODO: make utf8 safe, possibly with helper function from application */ @@ -153,16 +153,16 @@ static int ldb_canonicalise_dn(struct ldb_context *ldb, void *mem_ctx, out->length = 0; out->data = NULL; - dn = ldb_dn_explode_casefold(ldb, in->data); + dn = ldb_dn_explode_casefold(ldb, (char *)in->data); if (dn == NULL) { return -1; } - out->data = ldb_dn_linearize(mem_ctx, dn); + out->data = (uint8_t *)ldb_dn_linearize(mem_ctx, dn); if (out->data == NULL) { goto done; } - out->length = strlen(out->data); + out->length = strlen((char *)out->data); ret = 0; @@ -181,10 +181,10 @@ static int ldb_comparison_dn(struct ldb_context *ldb, void *mem_ctx, struct ldb_dn *dn1 = NULL, *dn2 = NULL; int ret; - dn1 = ldb_dn_explode_casefold(mem_ctx, v1->data); + dn1 = ldb_dn_explode_casefold(mem_ctx, (char *)v1->data); if (dn1 == NULL) return -1; - dn2 = ldb_dn_explode_casefold(mem_ctx, v2->data); + dn2 = ldb_dn_explode_casefold(mem_ctx, (char *)v2->data); if (dn2 == NULL) { talloc_free(dn1); return -1; @@ -209,7 +209,7 @@ static int ldb_comparison_objectclass(struct ldb_context *ldb, void *mem_ctx, if (ret == 0) { return 0; } - subclasses = ldb_subclass_list(ldb, v1->data); + subclasses = ldb_subclass_list(ldb, (char *)v1->data); if (subclasses == NULL) { return ret; } -- cgit From 49cc13a8f0fbc4f68e14720b733329ce45135cec Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 12 Oct 2005 07:54:15 +0000 Subject: r10915: added a standard attribute handler for a ldap UTC time string (This used to be commit efd7dd1a775c06f21924f35760f7768b4e8db449) --- source4/lib/ldb/common/attrib_handlers.c | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index d073203b3c..4a6e3e3c79 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -224,6 +224,33 @@ static int ldb_comparison_objectclass(struct ldb_context *ldb, void *mem_ctx, return ret; } +/* + compare two utc time values. 1 second resolution +*/ +static int ldb_comparison_utctime(struct ldb_context *ldb, void *mem_ctx, + const struct ldb_val *v1, const struct ldb_val *v2) +{ + time_t t1, t2; + t1 = ldb_string_to_time((char *)v1->data); + t1 = ldb_string_to_time((char *)v1->data); + return (int)t2 - (int)t1; +} + +/* + canonicalise a utc time +*/ +static int ldb_canonicalise_utctime(struct ldb_context *ldb, void *mem_ctx, + const struct ldb_val *in, struct ldb_val *out) +{ + time_t t = ldb_string_to_time((char *)in->data); + out->data = (uint8_t *)ldb_timestring(mem_ctx, t); + if (out->data == NULL) { + return -1; + } + out->length = strlen((char *)out->data); + return 0; +} + /* table of standard attribute handlers */ @@ -267,6 +294,14 @@ static const struct ldb_attrib_handler ldb_standard_attribs[] = { .ldif_write_fn = ldb_handler_copy, .canonicalise_fn = ldb_handler_fold, .comparison_fn = ldb_comparison_objectclass + }, + { + .attr = LDB_SYNTAX_UTC_TIME, + .flags = 0, + .ldif_read_fn = ldb_handler_copy, + .ldif_write_fn = ldb_handler_copy, + .canonicalise_fn = ldb_canonicalise_utctime, + .comparison_fn = ldb_comparison_utctime } }; -- cgit From 5a67b508d8f8761f0a73c2f7a116be1693d73395 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 28 Oct 2005 19:14:46 +0000 Subject: r11378: Fix an uninitialized variable warning. Tridge, I'm 99.999% sure this was a simple cut&paste error, but you might recheck this. Volker (This used to be commit 55b5b100e9ef7e04832d5ba4c10c45916be3513e) --- source4/lib/ldb/common/attrib_handlers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index 4a6e3e3c79..4b9d349672 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -232,7 +232,7 @@ static int ldb_comparison_utctime(struct ldb_context *ldb, void *mem_ctx, { time_t t1, t2; t1 = ldb_string_to_time((char *)v1->data); - t1 = ldb_string_to_time((char *)v1->data); + t2 = ldb_string_to_time((char *)v2->data); return (int)t2 - (int)t1; } -- cgit From 428ef08930e06de31919b75ff12b9147aada8a10 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 10 Jan 2006 14:21:24 +0000 Subject: r12827: This was a very well concealed bug. Thank to Andrew Bartlet for finding out a test case that showed it up. Simo. (This used to be commit 72a86d74a95c2b38d25159027f612075c50a1f3c) --- source4/lib/ldb/common/attrib_handlers.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index 4b9d349672..4826ead946 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -136,8 +136,15 @@ static int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, } s1++; s2++; } - while (*s1 == ' ') s1++; - while (*s2 == ' ') s2++; + if (! (*s1 && *s2)) { + /* remove trailing spaces only if one of the pointers + * has reached the end of the strings otherwise we + * can mistakenly match. + * ex. "domain users" <-> "domainUpdates" + */ + while (*s1 == ' ') s1++; + while (*s2 == ' ') s2++; + } return (int)(toupper(*s1)) - (int)(toupper(*s2)); } -- cgit From 4d1c5a023cf6680474bd8d8be73f576d155cfe81 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 10 Jan 2006 16:48:32 +0000 Subject: r12829: fix ldb headers, to not include '<...>' files in .c files this helps in getting symbol -fvisibility=hidden (GCC 4 feature) working later. metze (This used to be commit 380938e97f31c7860aed1e73cc0110c6e17b472e) --- source4/lib/ldb/common/attrib_handlers.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index 4826ead946..2109e9b2da 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -27,9 +27,7 @@ */ #include "includes.h" -#include "ldb/include/ldb.h" -#include "ldb/include/ldb_private.h" -#include +#include "ldb/include/includes.h" /* default handler that just copies a ldb_val. -- cgit From 3ba24e4a35156a36f900cdbdbbef770861e9c7eb Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 4 Feb 2006 07:57:57 +0000 Subject: r13335: Fix the build and add an utf8 safe ldb_hadler_fold function based on ldb_casefold (This used to be commit 6104f900863c688707809d42c5429a42d654d5fb) --- source4/lib/ldb/common/attrib_handlers.c | 56 ++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 14 deletions(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index 2109e9b2da..4b6a7af1ee 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -46,32 +46,60 @@ int ldb_handler_copy(struct ldb_context *ldb, void *mem_ctx, /* a case folding copy handler, removing leading and trailing spaces and multiple internal spaces + + We exploit the fact that utf8 never uses the space octet except for + the space itself */ static int ldb_handler_fold(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *in, struct ldb_val *out) { - uint8_t *s1, *s2; - out->data = talloc_size(mem_ctx, strlen((char *)in->data)+1); + char *s, *t; + int l; + if (!in || !out || !(in->data)) { + return -1; + } + + out->data = (uint8_t *)ldb_casefold(ldb, mem_ctx, (const char *)(in->data)); if (out->data == NULL) { - ldb_oom(ldb); + ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_handler_fold: unable to casefold string [%s]", in->data); return -1; } - s1 = in->data; - s2 = out->data; - while (*s1 == ' ') s1++; - while (*s1) { - *s2 = toupper(*s1); - if (s1[0] == ' ') { - while (s1[0] == s1[1]) s1++; + + s = (char *)(out->data); + + /* remove trailing spaces if any */ + l = strlen(s); + while (s[l - 1] == ' ') l--; + s[l] = '\0'; + + /* remove leading spaces if any */ + if (*s == ' ') { + for (t = s; *s == ' '; s++) ; + + /* remove leading spaces by moving down the string */ + memmove(t, s, l); + + s = t; + } + + /* check middle spaces */ + while ((t = strchr(s, ' ')) != NULL) { + for (s = t; *s == ' '; s++) ; + + if ((s - t) > 1) { + l = strlen(s); + + /* remove all spaces but one by moving down the string */ + memmove(t + 1, s, l); } - s2++; s1++; } - *s2 = 0; + out->length = strlen((char *)out->data); return 0; } + /* canonicalise a ldap Integer rfc2252 specifies it should be in decimal form @@ -114,8 +142,8 @@ int ldb_comparison_binary(struct ldb_context *ldb, void *mem_ctx, } /* - compare two case insensitive strings, ignoring multiple whitespace - and leading and trailing whitespace + compare two case insensitive strings, ignoring multiple whitespaces + and leading and trailing whitespaces see rfc2252 section 8.1 */ static int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, -- cgit From e1e693792c1af66283e869dc427d03c6e9983776 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 4 Feb 2006 16:44:27 +0000 Subject: r13347: - Now we compare values with an optimized utf8 safe function if the user provides an utf8 compliant casefold function to ldb. - Fix toupper_m and tolower_m to not crash if the case tables are not found - Let load_case_table() search into the correct directory in the search tree for the case tables so that we can test utf8 Simo (This used to be commit e12f070958eb3c144beb81c5cb878db122249021) --- source4/lib/ldb/common/attrib_handlers.c | 35 +++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index 4b6a7af1ee..7d1eff6d9a 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -145,15 +145,24 @@ int ldb_comparison_binary(struct ldb_context *ldb, void *mem_ctx, compare two case insensitive strings, ignoring multiple whitespaces and leading and trailing whitespaces see rfc2252 section 8.1 + + try to optimize for the ascii case, + but if we find out an utf8 codepoint revert to slower but correct function */ static int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *v1, const struct ldb_val *v2) { const char *s1=(const char *)v1->data, *s2=(const char *)v2->data; + char *b1, *b2, *u1, *u2; + int ret; while (*s1 == ' ') s1++; while (*s2 == ' ') s2++; /* TODO: make utf8 safe, possibly with helper function from application */ while (*s1 && *s2) { + /* the first 127 (0x7F) chars are ascii and utf8 guarantes they + * never appear in multibyte sequences */ + if (((unsigned char)s1[0]) & 0x80) goto utf8str; + if (((unsigned char)s2[0]) & 0x80) goto utf8str; if (toupper((unsigned char)*s1) != toupper((unsigned char)*s2)) break; if (*s1 == ' ') { @@ -163,7 +172,7 @@ static int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, s1++; s2++; } if (! (*s1 && *s2)) { - /* remove trailing spaces only if one of the pointers + /* check for trailing spaces only if one of the pointers * has reached the end of the strings otherwise we * can mistakenly match. * ex. "domain users" <-> "domainUpdates" @@ -172,6 +181,30 @@ static int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, while (*s2 == ' ') s2++; } return (int)(toupper(*s1)) - (int)(toupper(*s2)); + +utf8str: + /* non need to recheck from the start, just from the first utf8 char found */ + b1 = u1 = ldb_casefold(ldb, mem_ctx, s1); + b2 = u2 = ldb_casefold(ldb, mem_ctx, s2); + + while (*u1 & *u2) { + if (*u1 != *u2) + break; + if (*u1 == ' ') { + while (u1[0] == u1[1]) u1++; + while (u2[0] == u2[1]) u2++; + } + u1++; u2++; + } + if (! (*u1 && *u2)) { + while (*u1 == ' ') u1++; + while (*u2 == ' ') u2++; + } + ret = (int)(*u1 - *u2); + talloc_free(b1); + talloc_free(b2); + + return ret; } /* -- cgit From 5b26ea841cb87500d46cb39ee05000994bcfccbe Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 6 Feb 2006 00:27:02 +0000 Subject: r13359: make sure we don't look at s[-1] metze (This used to be commit 24c6e2f73175befa33f9758634e3ee183916e387) --- source4/lib/ldb/common/attrib_handlers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index 7d1eff6d9a..ec89bdd1c4 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -69,7 +69,7 @@ static int ldb_handler_fold(struct ldb_context *ldb, void *mem_ctx, /* remove trailing spaces if any */ l = strlen(s); - while (s[l - 1] == ' ') l--; + while (l > 0 && s[l - 1] == ' ') l--; s[l] = '\0'; /* remove leading spaces if any */ -- cgit From 014f70008fcfdb631031c48aa9654ad5b42e62f9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 6 Sep 2006 04:58:06 +0000 Subject: r18130: the move to system/ in libreplace broke some things ... should be happier now (This used to be commit 18542f184f75074e56a9793a9e3b6c6d747bb9e6) --- source4/lib/ldb/common/attrib_handlers.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index ec89bdd1c4..8e437964f4 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -28,6 +28,7 @@ #include "includes.h" #include "ldb/include/includes.h" +#include "system/locale.h" /* default handler that just copies a ldb_val. -- cgit From c2a2c2456d807784bdacb9e088044a85fe278315 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 28 Sep 2006 17:06:38 +0000 Subject: r18978: Fix bug found by: http://www.ee.oulu.fi/research/ouspg/protos/testing/c06/ldapv3/ The issue here is that if the UTF8 conversion fails, because this isn't actually UTF8 data, then we need to do a binary compare instead. Andrew Bartlett (This used to be commit a113e47784157ec6086b014c1fc998e8a23e7382) --- source4/lib/ldb/common/attrib_handlers.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index 8e437964f4..df70ca1b51 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -184,10 +184,19 @@ static int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, return (int)(toupper(*s1)) - (int)(toupper(*s2)); utf8str: - /* non need to recheck from the start, just from the first utf8 char found */ + /* no need to recheck from the start, just from the first utf8 char found */ b1 = u1 = ldb_casefold(ldb, mem_ctx, s1); b2 = u2 = ldb_casefold(ldb, mem_ctx, s2); - + + if (u1 && u2) { + /* Both strings converted correctly */ + } else { + /* One of the strings was not UTF8, so we have no options but to do a binary compare */ + + u1 = s1; + u2 = s2; + } + while (*u1 & *u2) { if (*u1 != *u2) break; @@ -202,9 +211,10 @@ utf8str: while (*u2 == ' ') u2++; } ret = (int)(*u1 - *u2); + talloc_free(b1); talloc_free(b2); - + return ret; } -- cgit From bbc056e067e1b721dc2ef6958ab653c1eddec3a1 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 9 Oct 2006 09:56:13 +0000 Subject: r19196: merge from samba3: pass always a mem_ctx to functions and a ldb_context where needed metze (This used to be commit 67a6a41ba3af840cd8226de73576a90ecf602caa) --- source4/lib/ldb/common/attrib_handlers.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index df70ca1b51..07a0ec6eb8 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -230,7 +230,7 @@ static int ldb_canonicalise_dn(struct ldb_context *ldb, void *mem_ctx, out->length = 0; out->data = NULL; - dn = ldb_dn_explode_casefold(ldb, (char *)in->data); + dn = ldb_dn_explode_casefold(ldb, mem_ctx, (char *)in->data); if (dn == NULL) { return -1; } @@ -258,10 +258,10 @@ static int ldb_comparison_dn(struct ldb_context *ldb, void *mem_ctx, struct ldb_dn *dn1 = NULL, *dn2 = NULL; int ret; - dn1 = ldb_dn_explode_casefold(mem_ctx, (char *)v1->data); + dn1 = ldb_dn_explode_casefold(ldb, mem_ctx, (char *)v1->data); if (dn1 == NULL) return -1; - dn2 = ldb_dn_explode_casefold(mem_ctx, (char *)v2->data); + dn2 = ldb_dn_explode_casefold(ldb, mem_ctx, (char *)v2->data); if (dn2 == NULL) { talloc_free(dn1); return -1; -- cgit From 982f7f9b443d6ecaddcbb2e3f79029aced06fdd0 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 16 Nov 2006 11:11:30 +0000 Subject: r19742: fix compiler warnings metze (This used to be commit 4edeef56dcd185869812bf622c5b496360eb6223) --- source4/lib/ldb/common/attrib_handlers.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index 07a0ec6eb8..cb1dfa105f 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -154,7 +154,8 @@ static int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *v1, const struct ldb_val *v2) { const char *s1=(const char *)v1->data, *s2=(const char *)v2->data; - char *b1, *b2, *u1, *u2; + const char *u1, *u2; + char *b1, *b2; int ret; while (*s1 == ' ') s1++; while (*s2 == ' ') s2++; @@ -185,11 +186,14 @@ static int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, utf8str: /* no need to recheck from the start, just from the first utf8 char found */ - b1 = u1 = ldb_casefold(ldb, mem_ctx, s1); - b2 = u2 = ldb_casefold(ldb, mem_ctx, s2); + b1 = ldb_casefold(ldb, mem_ctx, s1); + b2 = ldb_casefold(ldb, mem_ctx, s2); - if (u1 && u2) { + if (b1 && b2) { /* Both strings converted correctly */ + + u1 = b1; + u2 = b2; } else { /* One of the strings was not UTF8, so we have no options but to do a binary compare */ -- cgit From 4889eb9f7aae9349e426d0f6d2217adff67eaebd Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 22 Nov 2006 00:59:34 +0000 Subject: r19831: Big ldb_dn optimization and interfaces enhancement patch This patch changes a lot of the code in ldb_dn.c, and also removes and add a number of manipulation functions around. The aim is to avoid validating a dn if not necessary as the validation code is necessarily slow. This is mainly to speed up internal operations where input is not user generated and so we can assume the DNs need no validation. The code is designed to keep the data as a string if possible. The code is not yet 100% perfect, but pass all the tests so far. A memleak is certainly present, I'll work on that next. Simo. (This used to be commit a580c871d3784602a9cce32d33419e63c8236e63) --- source4/lib/ldb/common/attrib_handlers.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index cb1dfa105f..372793a103 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -234,8 +234,8 @@ static int ldb_canonicalise_dn(struct ldb_context *ldb, void *mem_ctx, out->length = 0; out->data = NULL; - dn = ldb_dn_explode_casefold(ldb, mem_ctx, (char *)in->data); - if (dn == NULL) { + dn = ldb_dn_new(ldb, mem_ctx, (char *)in->data); + if ( ! ldb_dn_validate(dn)) { return -1; } @@ -262,16 +262,16 @@ static int ldb_comparison_dn(struct ldb_context *ldb, void *mem_ctx, struct ldb_dn *dn1 = NULL, *dn2 = NULL; int ret; - dn1 = ldb_dn_explode_casefold(ldb, mem_ctx, (char *)v1->data); - if (dn1 == NULL) return -1; + dn1 = ldb_dn_new(ldb, mem_ctx, (char *)v1->data); + if ( ! ldb_dn_validate(dn1)) return -1; - dn2 = ldb_dn_explode_casefold(ldb, mem_ctx, (char *)v2->data); - if (dn2 == NULL) { + dn2 = ldb_dn_new(ldb, mem_ctx, (char *)v2->data); + if ( ! ldb_dn_validate(dn2)) { talloc_free(dn1); return -1; } - ret = ldb_dn_compare(ldb, dn1, dn2); + ret = ldb_dn_compare(dn1, dn2); talloc_free(dn1); talloc_free(dn2); -- cgit From a9e31b33b55a873c2f01db5e348560176adf863d Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 22 Nov 2006 02:05:19 +0000 Subject: r19832: better prototypes for the linearization functions: - ldb_dn_get_linearized returns a const string - ldb_dn_alloc_linearized allocs astring with the linearized dn (This used to be commit 3929c086d5d0b3f08b1c4f2f3f9602c3f4a9a4bd) --- source4/lib/ldb/common/attrib_handlers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index 372793a103..c50f7ed7b1 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -239,7 +239,7 @@ static int ldb_canonicalise_dn(struct ldb_context *ldb, void *mem_ctx, return -1; } - out->data = (uint8_t *)ldb_dn_linearize(mem_ctx, dn); + out->data = (uint8_t *)ldb_dn_alloc_linearized(mem_ctx, dn); if (out->data == NULL) { goto done; } -- cgit From c05c41d3521e8782be01b0413f3551d10487a1ac Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 25 Nov 2006 15:43:56 +0000 Subject: r19888: make it possible to use default attrib handlers from extensions list more DN attributes as part of samba attribute handlers (nCName moved here) (This used to be commit 627ed8b5165c9a1cc0e2c67329b364f9cd8a1726) --- source4/lib/ldb/common/attrib_handlers.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index c50f7ed7b1..f563865c03 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -29,6 +29,7 @@ #include "includes.h" #include "ldb/include/includes.h" #include "system/locale.h" +#include "ldb/include/ldb_handlers.h" /* default handler that just copies a ldb_val. @@ -51,7 +52,7 @@ int ldb_handler_copy(struct ldb_context *ldb, void *mem_ctx, We exploit the fact that utf8 never uses the space octet except for the space itself */ -static int ldb_handler_fold(struct ldb_context *ldb, void *mem_ctx, +int ldb_handler_fold(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *in, struct ldb_val *out) { char *s, *t; @@ -105,7 +106,7 @@ static int ldb_handler_fold(struct ldb_context *ldb, void *mem_ctx, canonicalise a ldap Integer rfc2252 specifies it should be in decimal form */ -static int ldb_canonicalise_Integer(struct ldb_context *ldb, void *mem_ctx, +int ldb_canonicalise_Integer(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *in, struct ldb_val *out) { char *end; @@ -124,7 +125,7 @@ static int ldb_canonicalise_Integer(struct ldb_context *ldb, void *mem_ctx, /* compare two Integers */ -static int ldb_comparison_Integer(struct ldb_context *ldb, void *mem_ctx, +int ldb_comparison_Integer(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *v1, const struct ldb_val *v2) { return strtoll((char *)v1->data, NULL, 0) - strtoll((char *)v2->data, NULL, 0); @@ -150,7 +151,7 @@ int ldb_comparison_binary(struct ldb_context *ldb, void *mem_ctx, try to optimize for the ascii case, but if we find out an utf8 codepoint revert to slower but correct function */ -static int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, +int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *v1, const struct ldb_val *v2) { const char *s1=(const char *)v1->data, *s2=(const char *)v2->data; @@ -225,7 +226,7 @@ utf8str: /* canonicalise a attribute in DN format */ -static int ldb_canonicalise_dn(struct ldb_context *ldb, void *mem_ctx, +int ldb_canonicalise_dn(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *in, struct ldb_val *out) { struct ldb_dn *dn; @@ -239,7 +240,7 @@ static int ldb_canonicalise_dn(struct ldb_context *ldb, void *mem_ctx, return -1; } - out->data = (uint8_t *)ldb_dn_alloc_linearized(mem_ctx, dn); + out->data = (uint8_t *)ldb_dn_alloc_casefold(mem_ctx, dn); if (out->data == NULL) { goto done; } @@ -256,7 +257,7 @@ done: /* compare two dns */ -static int ldb_comparison_dn(struct ldb_context *ldb, void *mem_ctx, +int ldb_comparison_dn(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *v1, const struct ldb_val *v2) { struct ldb_dn *dn1 = NULL, *dn2 = NULL; @@ -281,7 +282,7 @@ static int ldb_comparison_dn(struct ldb_context *ldb, void *mem_ctx, /* compare two objectclasses, looking at subclasses */ -static int ldb_comparison_objectclass(struct ldb_context *ldb, void *mem_ctx, +int ldb_comparison_objectclass(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *v1, const struct ldb_val *v2) { int ret, i; @@ -308,7 +309,7 @@ static int ldb_comparison_objectclass(struct ldb_context *ldb, void *mem_ctx, /* compare two utc time values. 1 second resolution */ -static int ldb_comparison_utctime(struct ldb_context *ldb, void *mem_ctx, +int ldb_comparison_utctime(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *v1, const struct ldb_val *v2) { time_t t1, t2; @@ -320,7 +321,7 @@ static int ldb_comparison_utctime(struct ldb_context *ldb, void *mem_ctx, /* canonicalise a utc time */ -static int ldb_canonicalise_utctime(struct ldb_context *ldb, void *mem_ctx, +int ldb_canonicalise_utctime(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *in, struct ldb_val *out) { time_t t = ldb_string_to_time((char *)in->data); -- cgit From 6045b6f314be519cfb7faeeef6b3daaac673582f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 30 Nov 2006 10:03:54 +0000 Subject: r19964: make debuging easier and report usefull error messages metze (This used to be commit f129d78256d965d52e80aedfa76c7c079e611c5f) --- source4/lib/ldb/common/attrib_handlers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index f563865c03..7a9fd1f9da 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -237,7 +237,7 @@ int ldb_canonicalise_dn(struct ldb_context *ldb, void *mem_ctx, dn = ldb_dn_new(ldb, mem_ctx, (char *)in->data); if ( ! ldb_dn_validate(dn)) { - return -1; + return LDB_ERR_INVALID_DN_SYNTAX; } out->data = (uint8_t *)ldb_dn_alloc_casefold(mem_ctx, dn); -- cgit From e55ff42229d67c1447f2c811191b79137b1ce8cc Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 14 Dec 2006 10:03:21 +0000 Subject: r20168: start separating attributes and syntaxes metze (This used to be commit 8dda4342f648aa71878ac9eeb7941710e2813aee) --- source4/lib/ldb/common/attrib_handlers.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index 7a9fd1f9da..223f2b5c16 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -336,50 +336,44 @@ int ldb_canonicalise_utctime(struct ldb_context *ldb, void *mem_ctx, /* table of standard attribute handlers */ -static const struct ldb_attrib_handler ldb_standard_attribs[] = { +static const struct ldb_schema_syntax ldb_standard_syntaxes[] = { { - .attr = LDB_SYNTAX_INTEGER, - .flags = 0, + .name = LDB_SYNTAX_INTEGER, .ldif_read_fn = ldb_handler_copy, .ldif_write_fn = ldb_handler_copy, .canonicalise_fn = ldb_canonicalise_Integer, .comparison_fn = ldb_comparison_Integer }, { - .attr = LDB_SYNTAX_OCTET_STRING, - .flags = 0, + .name = LDB_SYNTAX_OCTET_STRING, .ldif_read_fn = ldb_handler_copy, .ldif_write_fn = ldb_handler_copy, .canonicalise_fn = ldb_handler_copy, .comparison_fn = ldb_comparison_binary }, { - .attr = LDB_SYNTAX_DIRECTORY_STRING, - .flags = 0, + .name = LDB_SYNTAX_DIRECTORY_STRING, .ldif_read_fn = ldb_handler_copy, .ldif_write_fn = ldb_handler_copy, .canonicalise_fn = ldb_handler_fold, .comparison_fn = ldb_comparison_fold }, { - .attr = LDB_SYNTAX_DN, - .flags = 0, + .name = LDB_SYNTAX_DN, .ldif_read_fn = ldb_handler_copy, .ldif_write_fn = ldb_handler_copy, .canonicalise_fn = ldb_canonicalise_dn, .comparison_fn = ldb_comparison_dn }, { - .attr = LDB_SYNTAX_OBJECTCLASS, - .flags = 0, + .name = LDB_SYNTAX_OBJECTCLASS, .ldif_read_fn = ldb_handler_copy, .ldif_write_fn = ldb_handler_copy, .canonicalise_fn = ldb_handler_fold, .comparison_fn = ldb_comparison_objectclass }, { - .attr = LDB_SYNTAX_UTC_TIME, - .flags = 0, + .name = LDB_SYNTAX_UTC_TIME, .ldif_read_fn = ldb_handler_copy, .ldif_write_fn = ldb_handler_copy, .canonicalise_fn = ldb_canonicalise_utctime, @@ -391,17 +385,16 @@ static const struct ldb_attrib_handler ldb_standard_attribs[] = { /* return the attribute handlers for a given syntax name */ -const struct ldb_attrib_handler *ldb_attrib_handler_syntax(struct ldb_context *ldb, - const char *syntax) +const struct ldb_schema_syntax *ldb_standard_syntax_by_name(struct ldb_context *ldb, + const char *syntax) { int i; - unsigned num_handlers = sizeof(ldb_standard_attribs)/sizeof(ldb_standard_attribs[0]); + unsigned num_handlers = sizeof(ldb_standard_syntaxes)/sizeof(ldb_standard_syntaxes[0]); /* TODO: should be replaced with a binary search */ for (i=0;i Date: Sat, 5 May 2007 18:50:56 +0000 Subject: r22681: Fix standalone ldb build when parent directory name != ldb. (This used to be commit 1093875d59f1ea9b8bd82277d4f9d8366e584952) --- source4/lib/ldb/common/attrib_handlers.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index 223f2b5c16..2d3b6135c8 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -26,10 +26,9 @@ see rfc2252 */ -#include "includes.h" -#include "ldb/include/includes.h" +#include "ldb_includes.h" #include "system/locale.h" -#include "ldb/include/ldb_handlers.h" +#include "ldb_handlers.h" /* default handler that just copies a ldb_val. -- cgit From b8d69a7ea2505b706ff7c74d7c97bc89d82dfa07 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:46:15 +0000 Subject: r23795: more v2->v3 conversion (This used to be commit 84b468b2f8f2dffda89593f816e8bc6a8b6d42ac) --- source4/lib/ldb/common/attrib_handlers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index 2d3b6135c8..c209285556 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -10,7 +10,7 @@ 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. + 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 -- cgit From 6c973f4e8ccbcb6c9275f8a54e26abb19df7e15a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 03:42:26 +0000 Subject: r23798: updated old Temple Place FSF addresses to new URL (This used to be commit 40c0919aaa9c1b14bbaebb95ecce53eb0380fdbb) --- source4/lib/ldb/common/attrib_handlers.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index c209285556..b8747c3b95 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -18,8 +18,7 @@ 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 + License along with this library; if not, see . */ /* attribute handlers for well known attribute types, selected by syntax OID -- cgit From c64116e158080c7cd7304cdd3b80c8666f78c7c6 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 18 Sep 2007 22:43:06 +0000 Subject: r25218: After discussion with Simo, remove the subclass support from LDB. Subclass support was designed to avoid needing to spell out the full list of objectClasses that an entry was in. However, Samba4 now enforces this restriction in the objectClass module, and the way subclass matching was handled was complex and counter-intuitive in my opinion (and did not match LDAP). Andrew Bartlett (This used to be commit f5ce04b904e14445a2a7e7f92e7e1f64b645c6f2) --- source4/lib/ldb/common/attrib_handlers.c | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index b8747c3b95..8ed2763d4d 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -277,33 +277,6 @@ int ldb_comparison_dn(struct ldb_context *ldb, void *mem_ctx, return ret; } -/* - compare two objectclasses, looking at subclasses -*/ -int ldb_comparison_objectclass(struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *v1, const struct ldb_val *v2) -{ - int ret, i; - const char **subclasses; - ret = ldb_comparison_fold(ldb, mem_ctx, v1, v2); - if (ret == 0) { - return 0; - } - subclasses = ldb_subclass_list(ldb, (char *)v1->data); - if (subclasses == NULL) { - return ret; - } - for (i=0;subclasses[i];i++) { - struct ldb_val vs; - vs.data = discard_const(subclasses[i]); - vs.length = strlen(subclasses[i]); - if (ldb_comparison_objectclass(ldb, mem_ctx, &vs, v2) == 0) { - return 0; - } - } - return ret; -} - /* compare two utc time values. 1 second resolution */ @@ -368,7 +341,7 @@ static const struct ldb_schema_syntax ldb_standard_syntaxes[] = { .ldif_read_fn = ldb_handler_copy, .ldif_write_fn = ldb_handler_copy, .canonicalise_fn = ldb_handler_fold, - .comparison_fn = ldb_comparison_objectclass + .comparison_fn = ldb_comparison_fold }, { .name = LDB_SYNTAX_UTC_TIME, -- cgit From cc43037f19056ed24d7fffa54456d597c63ad105 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 22 Aug 2008 17:36:56 +1000 Subject: fixed a problem with length limited ldap values The core ldb code for string matching assumed NULL terminated strings, whereas the anr module used data_blob_const() to effectively truncate a ldb_val by changing its length. The ldb code is supposed to be based around length limited blobs, not NULL terminated strings, so the correct fix was to change the string comparison functions to be length limited (This used to be commit 26c6aa5a80ffaf06fc33f30a6533f8f16ef538bc) --- source4/lib/ldb/common/attrib_handlers.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'source4/lib/ldb/common/attrib_handlers.c') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index 8ed2763d4d..fb57e2dadc 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -55,11 +55,12 @@ int ldb_handler_fold(struct ldb_context *ldb, void *mem_ctx, { char *s, *t; int l; + if (!in || !out || !(in->data)) { return -1; } - out->data = (uint8_t *)ldb_casefold(ldb, mem_ctx, (const char *)(in->data)); + out->data = (uint8_t *)ldb_casefold(ldb, mem_ctx, (const char *)(in->data), in->length); if (out->data == NULL) { ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_handler_fold: unable to casefold string [%s]", in->data); return -1; @@ -153,13 +154,14 @@ int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *v1, const struct ldb_val *v2) { const char *s1=(const char *)v1->data, *s2=(const char *)v2->data; + size_t n1 = v1->length, n2 = v2->length; const char *u1, *u2; char *b1, *b2; int ret; - while (*s1 == ' ') s1++; - while (*s2 == ' ') s2++; + while (*s1 == ' ' && n1) { s1++; n1--; }; + while (*s2 == ' ' && n2) { s2++; n2--; }; /* TODO: make utf8 safe, possibly with helper function from application */ - while (*s1 && *s2) { + while (*s1 && *s2 && n1 && n2) { /* the first 127 (0x7F) chars are ascii and utf8 guarantes they * never appear in multibyte sequences */ if (((unsigned char)s1[0]) & 0x80) goto utf8str; @@ -167,10 +169,11 @@ int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, if (toupper((unsigned char)*s1) != toupper((unsigned char)*s2)) break; if (*s1 == ' ') { - while (s1[0] == s1[1]) s1++; - while (s2[0] == s2[1]) s2++; + while (s1[0] == s1[1] && n1) { s1++; n1--; } + while (s2[0] == s2[1] && n2) { s2++; n2--; } } s1++; s2++; + n1--; n2--; } if (! (*s1 && *s2)) { /* check for trailing spaces only if one of the pointers @@ -178,15 +181,18 @@ int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, * can mistakenly match. * ex. "domain users" <-> "domainUpdates" */ - while (*s1 == ' ') s1++; - while (*s2 == ' ') s2++; + while (*s1 == ' ') { s1++; n1--; } + while (*s2 == ' ') { s2++; n2--; } + } + if (n1 != n2) { + return n1 - n2; } return (int)(toupper(*s1)) - (int)(toupper(*s2)); utf8str: /* no need to recheck from the start, just from the first utf8 char found */ - b1 = ldb_casefold(ldb, mem_ctx, s1); - b2 = ldb_casefold(ldb, mem_ctx, s2); + b1 = ldb_casefold(ldb, mem_ctx, s1, n1); + b2 = ldb_casefold(ldb, mem_ctx, s2, n2); if (b1 && b2) { /* Both strings converted correctly */ @@ -221,6 +227,7 @@ utf8str: return ret; } + /* canonicalise a attribute in DN format */ -- cgit