ldb 1.3.2 fails some tests

Douglas Bagnall douglas.bagnall at catalyst.net.nz
Thu Mar 8 01:18:31 UTC 2018


On 08/03/18 14:10, Andrew Bartlett wrote:

> +			 */
> +			if (flags & LDB_ATTR_FLAG_DEFUALT) {

and

> + * remove attributes with any of the specified flags 
> + * (eg LDB_ATTR_FLAG_FROM_DB|LDB_ATTR_FLAG_DEFAULT)

and

> +		ret = ldb_schema_attribute_add(ldb,
> +					       wellknown[i].attr,
> +					       LDB_ATTR_FLAG_DEFUALT,

and

> + * The attribute was loaded from the defaults
> + */
> +#define LDB_ATTR_FLAG_DEFUALT      (1<<8)

etc.

> +					    |LDB_ATTR_FLAG_DEFUALT);


I've manually edited the patch the settle on the conventional DEFAULT
spelling.

Douglas
-------------- next part --------------
From 48b3a517560acb0d8d1d5e16d50a01bfc2ad0728 Mon Sep 17 00:00:00 2001
From: Andrew Bartlett <abartlet at samba.org>
Date: Thu, 8 Mar 2018 10:44:46 +1300
Subject: [PATCH] ldb: Rework default attribute handling

The previous code did not override the old default attributes, but left
them in the list.  By chance this did not matter most of the time.

Signed-off-by: Andrew Bartlett <abartlet at samba.org>
---
 lib/ldb/common/ldb_attributes.c | 21 ++++++++++++++++-----
 lib/ldb/include/ldb.h           |  7 ++++++-
 lib/ldb/ldb_tdb/ldb_cache.c     | 12 +++++++++---
 3 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/lib/ldb/common/ldb_attributes.c b/lib/ldb/common/ldb_attributes.c
index 32f25fd0fe8..2b7a2a79cf5 100644
--- a/lib/ldb/common/ldb_attributes.c
+++ b/lib/ldb/common/ldb_attributes.c
@@ -108,6 +108,13 @@ int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb,
 			if (a[i].flags & LDB_ATTR_FLAG_FIXED) {
 				return 0;
 			}
+			/*
+			 * Silently ignore attempts to add a default
+			 * if there is already one with this name.
+			 */
+			if (flags & LDB_ATTR_FLAG_DEFAULT) {
+				return 0;
+			}
 			if (a[i].flags & LDB_ATTR_FLAG_ALLOCATED) {
 				talloc_free(discard_const_p(char, a[i].name));
 			}
@@ -251,10 +258,12 @@ void ldb_schema_attribute_remove(struct ldb_context *ldb, const char *name)
 }
 
 /*
-  remove attributes with a specified flag (eg LDB_ATTR_FLAG_FROM_DB) for this ldb context
-
-  This is to permit correct reloads
-*/
+ * remove attributes with any of the specified flags 
+ * (eg LDB_ATTR_FLAG_FROM_DB|LDB_ATTR_FLAG_DEFAULT)
+ * for this ldb context
+ *
+ * This is to permit correct reloads
+ */
 void ldb_schema_attribute_remove_flagged(struct ldb_context *ldb, unsigned int flag)
 {
 	ptrdiff_t i;
@@ -315,7 +324,9 @@ int ldb_setup_wellknown_attributes(struct ldb_context *ldb)
 	int ret;
 
 	for (i=0;i<ARRAY_SIZE(wellknown);i++) {
-		ret = ldb_schema_attribute_add(ldb, wellknown[i].attr, 0,
+		ret = ldb_schema_attribute_add(ldb,
+					       wellknown[i].attr,
+					       LDB_ATTR_FLAG_DEFAULT,
 					       wellknown[i].syntax);
 		if (ret != LDB_SUCCESS) {
 			return ret;
diff --git a/lib/ldb/include/ldb.h b/lib/ldb/include/ldb.h
index 9918b4e69d9..54b1c651992 100644
--- a/lib/ldb/include/ldb.h
+++ b/lib/ldb/include/ldb.h
@@ -442,10 +442,15 @@ const struct ldb_dn_extended_syntax *ldb_dn_extended_syntax_by_name(struct ldb_c
 #define LDB_ATTR_FLAG_FROM_DB      (1<<6)
 
 /*
- * The attribute was loaded from a DB, rather than via the C API
+ * The attribute is indexed
  */
 #define LDB_ATTR_FLAG_INDEXED      (1<<7)
 
+/*
+ * The attribute was loaded from the defaults
+ */
+#define LDB_ATTR_FLAG_DEFAULT      (1<<8)
+
 /**
   LDAP attribute syntax for a DN
 
diff --git a/lib/ldb/ldb_tdb/ldb_cache.c b/lib/ldb/ldb_tdb/ldb_cache.c
index 4790bcd7e53..ff6d57f3dca 100644
--- a/lib/ldb/ldb_tdb/ldb_cache.c
+++ b/lib/ldb/ldb_tdb/ldb_cache.c
@@ -59,7 +59,9 @@ static void ltdb_attributes_unload(struct ldb_module *module)
 {
 	struct ldb_context *ldb = ldb_module_get_ctx(module);
 
-	ldb_schema_attribute_remove_flagged(ldb, LDB_ATTR_FLAG_FROM_DB);
+	ldb_schema_attribute_remove_flagged(ldb,
+					    LDB_ATTR_FLAG_FROM_DB
+					    |LDB_ATTR_FLAG_DEFAULT);
 
 }
 
@@ -133,7 +135,9 @@ static int ltdb_attributes_load(struct ldb_module *module)
 	}
 	if (r == LDB_ERR_NO_SUCH_OBJECT || attrs_msg->num_elements == 0) {
 		TALLOC_FREE(attrs_msg);
-		return 0;
+		
+		/* Now put back the defaults */
+		return ldb_setup_wellknown_attributes(ldb);
 	}
 
 	attrs = talloc_array(attrs_msg,
@@ -224,7 +228,9 @@ static int ltdb_attributes_load(struct ldb_module *module)
 	ldb->schema.num_attributes = num_loaded_attrs + ldb->schema.num_attributes;
 	TALLOC_FREE(attrs_msg);
 
-	return 0;
+	/* Now put back any defaults that have not been overridden */
+	return ldb_setup_wellknown_attributes(ldb);
+
 failed:
 	TALLOC_FREE(attrs_msg);
 	return -1;
-- 
2.11.0



More information about the samba-technical mailing list