summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common
diff options
context:
space:
mode:
authorDerrell Lipman <derrell@samba.org>2005-06-04 17:13:43 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:17:35 -0500
commita1ba224107fbcf6f8a9a3091f42cde2a0c47f85e (patch)
tree0d29cea6db75b6318f9645def992a7a840a369bf /source4/lib/ldb/common
parent5296bd1b5107f321de0dc9b3a9c3f6ac5a4861f0 (diff)
downloadsamba-a1ba224107fbcf6f8a9a3091f42cde2a0c47f85e.tar.gz
samba-a1ba224107fbcf6f8a9a3091f42cde2a0c47f85e.tar.bz2
samba-a1ba224107fbcf6f8a9a3091f42cde2a0c47f85e.zip
r7276: - moved static tdb function ltdb_dn_fold() into common/ so that it can be
called from multiple backends. (ldb_sqlite3 needs it too.) Added parameter for a callback function that determines whether an attribute needs case folding. - begin to prepare for sqlite3 in build process - work-in-progress updates, on ldb_sqlite3 (This used to be commit a80bced0b96ffb655559a43cf7f4d7a34deb5a7d)
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r--source4/lib/ldb/common/ldb.c6
-rw-r--r--source4/lib/ldb/common/ldb_utf8.c77
2 files changed, 83 insertions, 0 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index 600c7063f0..649b0a0f24 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/lib/ldb/common/ldb.c
@@ -62,6 +62,12 @@ struct ldb_context *ldb_connect(const char *url, unsigned int flags,
}
#endif
+#if HAVE_SQLITE3
+ if (strncmp(url, "sqlite:", 7) == 0) {
+ ldb_ctx = lsqlite3_connect(url, flags, options);
+ }
+#endif
+
if (!ldb_ctx) {
errno = EINVAL;
diff --git a/source4/lib/ldb/common/ldb_utf8.c b/source4/lib/ldb/common/ldb_utf8.c
index 577766d9f7..9cbb5646dd 100644
--- a/source4/lib/ldb/common/ldb_utf8.c
+++ b/source4/lib/ldb/common/ldb_utf8.c
@@ -88,3 +88,80 @@ 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(struct ldb_module *module, const char *dn, int (*case_fold_attr_fn)(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 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)(module, attr);
+
+ attr = ldb_casefold(ldb, attr);
+ if (attr == NULL) goto failed;
+ talloc_steal(tmp_ctx, attr);
+
+ if (case_fold_required) {
+ 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);
+}
+