summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2006-02-04 07:57:57 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:51:45 -0500
commit3ba24e4a35156a36f900cdbdbbef770861e9c7eb (patch)
tree098d33dfd0747d7af8198a7a30a75462975406b7 /source4/lib
parentf2d76bddd5c9d8b02283f66ba0b1f1584d1734be (diff)
downloadsamba-3ba24e4a35156a36f900cdbdbbef770861e9c7eb.tar.gz
samba-3ba24e4a35156a36f900cdbdbbef770861e9c7eb.tar.bz2
samba-3ba24e4a35156a36f900cdbdbbef770861e9c7eb.zip
r13335: Fix the build and add an utf8 safe ldb_hadler_fold function
based on ldb_casefold (This used to be commit 6104f900863c688707809d42c5429a42d654d5fb)
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/db_wrap.c4
-rw-r--r--source4/lib/ldb/common/attrib_handlers.c56
-rw-r--r--source4/lib/ldb/include/ldb.h1
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_index.c2
4 files changed, 46 insertions, 17 deletions
diff --git a/source4/lib/db_wrap.c b/source4/lib/db_wrap.c
index f3358bff98..8524f0da10 100644
--- a/source4/lib/db_wrap.c
+++ b/source4/lib/db_wrap.c
@@ -55,12 +55,12 @@ static void ldb_wrap_debug(void *context, enum ldb_debug_level level,
free(s);
}
-static int wrap_caseless_cmp(void *context, const char *s1, const char *s2)
+int wrap_caseless_cmp(void *context, const char *s1, const char *s2)
{
return strcasecmp_m(s1, s2);
}
-static char *wrap_casefold(void *context, void *mem_ctx, const char *s)
+char *wrap_casefold(void *context, void *mem_ctx, const char *s)
{
return strupper_talloc(mem_ctx, s);
}
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,
diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h
index 7c39aeeeb9..4e457b028f 100644
--- a/source4/lib/ldb/include/ldb.h
+++ b/source4/lib/ldb/include/ldb.h
@@ -970,6 +970,7 @@ int ldb_dn_cmp(struct ldb_context *ldb, const char *dn1, const char *dn2);
case; non-zero if there are any differences
*/
int ldb_attr_cmp(const char *attr1, const char *attr2);
+char *ldb_attr_casefold(void *mem_ctx, const char *s);
int ldb_attr_dn(const char *attr);
char *ldb_dn_escape_value(void *mem_ctx, struct ldb_val value);
diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c
index ac3063ef28..5c601f9ea8 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_index.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_index.c
@@ -106,7 +106,7 @@ static struct ldb_dn *ldb_dn_key(struct ldb_context *ldb,
const struct ldb_attrib_handler *h;
char *attr_folded;
- attr_folded = ldb_attr_casefold(ldb, ldb, attr);
+ attr_folded = ldb_attr_casefold(ldb, attr);
if (!attr_folded) {
return NULL;
}