svn commit: samba r5374 - in branches/SAMBA_4_0/source/lib/ldb:
include ldb_tdb tests
tridge at samba.org
tridge at samba.org
Sun Feb 13 12:27:57 GMT 2005
Author: tridge
Date: 2005-02-13 12:27:57 +0000 (Sun, 13 Feb 2005)
New Revision: 5374
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=5374
Log:
- changed the dn key code in the ldb tdb backend to correctly honor
the case sensitive/insensitive flags on sections of a dn. So if a dn
is made up of 4 attributes, and 2 of those are case insensitive and 2
are case sensitive, then all the attribute names are uppercases, but
only the values of the case insensitive attributes are uppercased when
forming the tdb key.
- added code to canonicalise the dn, removing leading and trailing
spaces from attribute names and values
- when the @ATTRIBUTES record changes, fix the dn keys of any records that should now have new
dn keys due to changes in the case sensitivity of the record
I really did this to allow me to make the WINS database properly case
insensitive, but it is also the correct general fix for ldb, as it
matches the LDAP specification (and w2k LDAP server behaviour)
Modified:
branches/SAMBA_4_0/source/lib/ldb/include/ldb.h
branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_index.c
branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c
branches/SAMBA_4_0/source/lib/ldb/tests/test-attribs.ldif
Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/include/ldb.h
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/include/ldb.h 2005-02-13 11:32:11 UTC (rev 5373)
+++ branches/SAMBA_4_0/source/lib/ldb/include/ldb.h 2005-02-13 12:27:57 UTC (rev 5374)
@@ -140,6 +140,11 @@
#define LDB_FLG_RDONLY 1
+#ifndef PRINTF_ATTRIBUTE
+#define PRINTF_ATTRIBUTE(a,b)
+#endif
+
+
/*
connect to a database. The URL can either be one of the following forms
ldb://path
@@ -302,10 +307,6 @@
struct ldb_val ldb_val_dup(void *mem_ctx, const struct ldb_val *v);
-#ifndef PRINTF_ATTRIBUTE
-#define PRINTF_ATTRIBUTE(a,b)
-#endif
-
/*
this allows the user to set a debug function for error reporting
*/
Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_index.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_index.c 2005-02-13 11:32:11 UTC (rev 5373)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_index.c 2005-02-13 12:27:57 UTC (rev 5374)
@@ -935,6 +935,7 @@
struct ldb_module *module = state;
struct ldb_message *msg;
int ret;
+ TDB_DATA key2;
if (strncmp(key.dptr, "DN=@", 4) == 0 ||
strncmp(key.dptr, "DN=", 3) != 0) {
@@ -952,6 +953,15 @@
return -1;
}
+ /* check if the DN key has changed, perhaps due to the
+ case insensitivity of an element changing */
+ key2 = ltdb_key(module, msg->dn);
+ if (strcmp(key2.dptr, key.dptr) != 0) {
+ tdb_delete(tdb, key);
+ tdb_store(tdb, key2, data, 0);
+ }
+ talloc_free(key2.dptr);
+
if (!msg->dn) {
msg->dn = key.dptr+3;
}
Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c 2005-02-13 11:32:11 UTC (rev 5373)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c 2005-02-13 12:27:57 UTC (rev 5374)
@@ -42,7 +42,83 @@
#define LDBLOCK "INT_LDBLOCK"
+
/*
+ 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
+*/
+static char *ltdb_dn_fold(struct ldb_module *module, const char *dn)
+{
+ 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);
+}
+
+/*
form a TDB_DATA for a record key
caller frees
@@ -65,7 +141,8 @@
there are 3 cases dealt with in this code:
- 1) if the dn doesn't start with @INDEX: then uppercase whole dn
+ 1) if the dn doesn't start with @INDEX: then uppercase the attribute
+ names and the attributes values of case insensitive attributes
2) if the dn starts with @INDEX:attr and 'attr' is a case insensitive
attribute then uppercase whole dn
3) if the dn starts with @INDEX:attr and 'attr' is a case sensitive
@@ -95,7 +172,7 @@
}
talloc_free(attr_name);
} else {
- dn_folded = ldb_casefold(ldb, dn);
+ dn_folded = ltdb_dn_fold(module, dn);
}
if (!dn_folded) {
Modified: branches/SAMBA_4_0/source/lib/ldb/tests/test-attribs.ldif
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/tests/test-attribs.ldif 2005-02-13 11:32:11 UTC (rev 5373)
+++ branches/SAMBA_4_0/source/lib/ldb/tests/test-attribs.ldif 2005-02-13 12:27:57 UTC (rev 5374)
@@ -1,5 +1,7 @@
dn: @ATTRIBUTES
uid: CASE_INSENSITIVE WILDCARD
+cn: CASE_INSENSITIVE
+ou: CASE_INSENSITIVE
dn: CASE_INSENSITIVE
dn: @SUBCLASSES
More information about the samba-cvs
mailing list