diff options
author | Simo Sorce <idra@samba.org> | 2006-02-04 07:57:57 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:51:45 -0500 |
commit | 3ba24e4a35156a36f900cdbdbbef770861e9c7eb (patch) | |
tree | 098d33dfd0747d7af8198a7a30a75462975406b7 /source4/lib/ldb/common | |
parent | f2d76bddd5c9d8b02283f66ba0b1f1584d1734be (diff) | |
download | samba-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/ldb/common')
-rw-r--r-- | source4/lib/ldb/common/attrib_handlers.c | 56 |
1 files changed, 42 insertions, 14 deletions
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, |