summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/ldb_tdb
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/ldb/ldb_tdb')
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c76
1 files changed, 5 insertions, 71 deletions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
index f6a23d7433..9c126c1dfd 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -44,78 +44,12 @@
/*
- 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
+ callback function used in call to ldb_dn_fold() for determining whether an
+ attribute type requires case folding.
*/
-static char *ltdb_dn_fold(struct ldb_module *module, const char *dn)
+static int ltdb_case_fold_attr_required(struct ldb_module *module, char *attr)
{
- const char *dn_orig = dn;
- struct ldb_context *ldb = module->ldb;
- TALLOC_CTX *tmp_ctx = talloc_new(ldb);
- 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 flags;
-
- 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;
-
- flags = ltdb_attribute_flags(module, attr);
-
- attr = ldb_casefold(ldb, attr);
- if (attr == NULL) goto failed;
- talloc_steal(tmp_ctx, attr);
-
- if (flags & LTDB_FLAG_CASE_INSENSITIVE) {
- value = ldb_casefold(ldb, 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(ldb, ret);
- talloc_free(tmp_ctx);
- return ret;
-
-failed:
- talloc_free(tmp_ctx);
- return ldb_casefold(ldb, dn_orig);
+ return ltdb_attribute_flags(module, attr) & LTDB_FLAG_CASE_INSENSITIVE;
}
/*
@@ -172,7 +106,7 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn)
}
talloc_free(attr_name);
} else {
- dn_folded = ltdb_dn_fold(module, dn);
+ dn_folded = ldb_dn_fold(module, dn, ltdb_case_fold_attr_required);
}
if (!dn_folded) {