diff options
author | Simo Sorce <idra@samba.org> | 2005-06-26 23:59:22 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:18:52 -0500 |
commit | 1702f52498168c0437416dec1014cedead634774 (patch) | |
tree | 51085d868dd9e562571ccb96dac48a5dd43bd55a /source4/lib/ldb/common | |
parent | 14b0722edf38872ba258c27e27094536ecb93d4f (diff) | |
download | samba-1702f52498168c0437416dec1014cedead634774.tar.gz samba-1702f52498168c0437416dec1014cedead634774.tar.bz2 samba-1702f52498168c0437416dec1014cedead634774.zip |
r7936: new ldb_dn_explode and ldb_dn_casefold functions and co
(This used to be commit 7ccf21ab4eeb9821e457308a239f2103a106fb12)
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r-- | source4/lib/ldb/common/ldb_utf8.c | 80 |
1 files changed, 1 insertions, 79 deletions
diff --git a/source4/lib/ldb/common/ldb_utf8.c b/source4/lib/ldb/common/ldb_utf8.c index ae35ad81b6..0c1ea6ca81 100644 --- a/source4/lib/ldb/common/ldb_utf8.c +++ b/source4/lib/ldb/common/ldb_utf8.c @@ -59,7 +59,7 @@ char *ldb_casefold(void *mem_ctx, const char *s) a caseless compare, optimised for 7 bit TODO: doesn't yet handle UTF8 */ -static int ldb_caseless_cmp(const char *s1, const char *s2) +int ldb_caseless_cmp(const char *s1, const char *s2) { int i; for (i=0;s1[i] != 0;i++) { @@ -89,81 +89,3 @@ int ldb_attr_cmp(const char *dn1, const char *dn2) return ldb_caseless_cmp(dn1, dn2); } - -/* - casefold a dn. We need to uppercase the attribute names, and the - attribute values of case insensitive attributes. We also need to remove - extraneous spaces between elements -*/ -char *ldb_dn_fold(void * mem_ctx, - const char * dn, - void * user_data, - int (* case_fold_attr_fn)(void * user_data, char * attr)) -{ - const char *dn_orig = dn; - TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx); - char *ret; - size_t len; - - ret = talloc_strdup(tmp_ctx, ""); - if (ret == NULL) goto failed; - - while ((len = strcspn(dn, ",")) > 0) { - char *p = strchr(dn, '='); - char *attr, *value; - int case_fold_required; - - if (p == NULL || (p-dn) > len) goto failed; - - attr = talloc_strndup(tmp_ctx, dn, p-dn); - if (attr == NULL) goto failed; - - /* trim spaces from the attribute name */ - while (' ' == *attr) attr++; - while (' ' == attr[strlen(attr)-1]) { - attr[strlen(attr)-1] = 0; - } - if (*attr == 0) goto failed; - - value = talloc_strndup(tmp_ctx, p+1, len-(p+1-dn)); - if (value == NULL) goto failed; - - /* trim spaces from the value */ - while (' ' == *value) value++; - while (' ' == value[strlen(value)-1]) { - value[strlen(value)-1] = 0; - } - if (*value == 0) goto failed; - - case_fold_required = case_fold_attr_fn(user_data, attr); - - attr = ldb_casefold(tmp_ctx, attr); - if (attr == NULL) goto failed; - talloc_steal(tmp_ctx, attr); - - if (case_fold_required) { - value = ldb_casefold(tmp_ctx, value); - if (value == NULL) goto failed; - talloc_steal(tmp_ctx, value); - } - - if (dn[len] == ',') { - ret = talloc_asprintf_append(ret, "%s=%s,", attr, value); - } else { - ret = talloc_asprintf_append(ret, "%s=%s", attr, value); - } - if (ret == NULL) goto failed; - - dn += len; - if (*dn == ',') dn++; - } - - talloc_steal(mem_ctx, ret); - talloc_free(tmp_ctx); - return ret; - -failed: - talloc_free(tmp_ctx); - return ldb_casefold(mem_ctx, dn_orig); -} - |