summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2006-02-04 06:57:28 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:51:45 -0500
commit04396c36d3ee8300b2b73ea8b43a45ea1b250828 (patch)
tree9f48c588c7faf2ace8b1ea0281cd3fd01d10af5f /source4/lib/ldb/common
parent88279373abc07fa50a969135eb5ecf58d6c40cc7 (diff)
downloadsamba-04396c36d3ee8300b2b73ea8b43a45ea1b250828.tar.gz
samba-04396c36d3ee8300b2b73ea8b43a45ea1b250828.tar.bz2
samba-04396c36d3ee8300b2b73ea8b43a45ea1b250828.zip
r13333: revert previous commit I will use ldb_caseless_cmp in attrib_handlers
to correctly support utf8 comparisons add an ldb_attr_Casefold function for attribute names and use it instead of casefold in the right places (This used to be commit 3b4eb2413bbce059dde69f35c03cdc3cc2ba85c5)
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r--source4/lib/ldb/common/ldb_dn.c2
-rw-r--r--source4/lib/ldb/common/ldb_utf8.c37
2 files changed, 36 insertions, 3 deletions
diff --git a/source4/lib/ldb/common/ldb_dn.c b/source4/lib/ldb/common/ldb_dn.c
index bcd5a067a6..9f3374bceb 100644
--- a/source4/lib/ldb/common/ldb_dn.c
+++ b/source4/lib/ldb/common/ldb_dn.c
@@ -581,7 +581,7 @@ struct ldb_dn *ldb_dn_casefold(struct ldb_context *ldb, const struct ldb_dn *edn
struct ldb_dn_component dc;
const struct ldb_attrib_handler *h;
- dc.name = ldb_casefold(ldb, cedn, edn->components[i].name);
+ dc.name = ldb_attr_casefold(cedn, edn->components[i].name);
LDB_DN_NULL_FAILED(dc.name);
h = ldb_attrib_handler(ldb, dc.name);
diff --git a/source4/lib/ldb/common/ldb_utf8.c b/source4/lib/ldb/common/ldb_utf8.c
index 1b7319915b..743e976e84 100644
--- a/source4/lib/ldb/common/ldb_utf8.c
+++ b/source4/lib/ldb/common/ldb_utf8.c
@@ -42,10 +42,13 @@
*/
void ldb_set_utf8_fns(struct ldb_context *ldb,
void *context,
+ int (*cmp)(void *, const char *, const char *),
char *(*casefold)(void *, void *, const char *))
{
if (context)
ldb->utf8_fns.context = context;
+ if (cmp)
+ ldb->utf8_fns.caseless_cmp = cmp;
if (casefold)
ldb->utf8_fns.casefold = casefold;
}
@@ -68,9 +71,19 @@ char *ldb_casefold_default(void *context, void *mem_ctx, const char *s)
return ret;
}
+/*
+ a caseless compare, optimised for 7 bit
+ NOTE: doesn't handle UTF8
+*/
+
+int ldb_caseless_cmp_default(void *context, const char *s1, const char *s2)
+{
+ return strcasecmp(s1,s2);
+}
+
void ldb_set_utf8_default(struct ldb_context *ldb)
{
- ldb_set_utf8_fns(ldb, NULL, ldb_casefold_default);
+ ldb_set_utf8_fns(ldb, NULL, ldb_caseless_cmp_default, ldb_casefold_default);
}
char *ldb_casefold(struct ldb_context *ldb, void *mem_ctx, const char *s)
@@ -78,6 +91,11 @@ char *ldb_casefold(struct ldb_context *ldb, void *mem_ctx, const char *s)
return ldb->utf8_fns.casefold(ldb->utf8_fns.context, mem_ctx, s);
}
+int ldb_caseless_cmp(struct ldb_context *ldb, const char *s1, const char *s2)
+{
+ return ldb->utf8_fns.caseless_cmp(ldb->utf8_fns.context, s1, s2);
+}
+
/*
check the attribute name is valid according to rfc2251
returns 1 if the name is ok
@@ -112,7 +130,8 @@ int ldb_valid_attr_name(const char *s)
/*
compare two attribute names
- attribute names are restricted by rfc2251 so using strcasecmp here is ok.
+ attribute names are restricted by rfc2251 so using
+ strcasecmp and toupper here is ok.
return 0 for match
*/
int ldb_attr_cmp(const char *attr1, const char *attr2)
@@ -120,6 +139,20 @@ int ldb_attr_cmp(const char *attr1, const char *attr2)
return strcasecmp(attr1, attr2);
}
+char *ldb_attr_casefold(void *mem_ctx, const char *s)
+{
+ int i;
+ char *ret = talloc_strdup(mem_ctx, s);
+ if (!s) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ for (i = 0; ret[i]; i++) {
+ ret[i] = toupper((unsigned char)ret[i]);
+ }
+ return ret;
+}
+
/*
we accept either 'dn' or 'distinguishedName' for a distinguishedName
*/