From 1dc5e75218e57fc410773161ab6431db33cd4b27 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 18 Aug 2008 20:21:31 +1000 Subject: Allow attributes to be overwritten, not just added to (This used to be commit 0aebae91be0fba7ffa94d73946a94aea930a252a) --- source4/lib/ldb/common/ldb_attributes.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index effd93ae26..ab6aa0b734 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -62,11 +62,20 @@ int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb, ldb->schema.attributes = a; for (i = 0; i < ldb->schema.num_attributes; i++) { - if (ldb_attr_cmp(attribute, a[i].name) < 0) { + int cmp = ldb_attr_cmp(attribute, a[i].name); + if (cmp == 0) { + if (a[i].flags & LDB_ATTR_FLAG_ALLOCATED) { + talloc_free(discard_const_p(char, a[i].name)); + } + /* To cancel out increment below */ + ldb->schema.num_attributes--; + break; + } else if (cmp < 0) { memmove(a+i+1, a+i, sizeof(*a) * (ldb->schema.num_attributes-i)); break; } } + ldb->schema.num_attributes++; a[i].name = attribute; a[i].flags = flags; @@ -80,7 +89,6 @@ int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb, } } - ldb->schema.num_attributes++; return 0; } @@ -145,7 +153,7 @@ void ldb_schema_attribute_remove(struct ldb_context *ldb, const char *name) int i; a = ldb_schema_attribute_by_name(ldb, name); - if (a == NULL) { + if (a == NULL || a->name == NULL) { return; } -- cgit From 7e1c62f8b64c9e42018bea33557af31fb7fa7414 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 20 Aug 2008 15:46:58 +1000 Subject: added a LDB_ATTR_FLAG_FIXED so the schema module can mark attributes as never to be removed. (This used to be commit 9dce558206a2ce70c69b9b6c5c3c9c58ee165b1d) --- source4/lib/ldb/common/ldb_attributes.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index effd93ae26..81aab52a08 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -149,6 +149,11 @@ void ldb_schema_attribute_remove(struct ldb_context *ldb, const char *name) return; } + /* FIXED attributes are never removed */ + if (a->flags & LDB_ATTR_FLAG_FIXED) { + return; + } + if (a->flags & LDB_ATTR_FLAG_ALLOCATED) { talloc_free(discard_const_p(char, a->name)); } -- cgit From 9dffeab5a8770de7c97e1b4e88fda372e5760147 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 20 Aug 2008 16:00:54 +1000 Subject: don't overwrite fixed attributes with @ATTRIBUTES (This used to be commit e860fc171fd127d73df23336089c1479911953da) --- source4/lib/ldb/common/ldb_attributes.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index 1e69f412df..3b9d01682c 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -64,6 +64,10 @@ int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb, for (i = 0; i < ldb->schema.num_attributes; i++) { int cmp = ldb_attr_cmp(attribute, a[i].name); if (cmp == 0) { + /* silently ignore attempts to overwrite fixed attributes */ + if (a[i].flags & LDB_ATTR_FLAG_FIXED) { + return 0; + } if (a[i].flags & LDB_ATTR_FLAG_ALLOCATED) { talloc_free(discard_const_p(char, a[i].name)); } -- cgit From 4016cfcab7bfb3ffd48a7592fa16952688525493 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 21 Aug 2008 12:51:06 +1000 Subject: Don't allow a NULL syntax (This used to be commit 505a0c2b702b696b91dab683626bb25b14a49c38) --- source4/lib/ldb/common/ldb_attributes.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index 3b9d01682c..747f241781 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -51,6 +51,10 @@ int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb, int i, n; struct ldb_schema_attribute *a; + if (!syntax) { + return LDB_ERR_OPERATIONS_ERROR; + } + n = ldb->schema.num_attributes + 1; a = talloc_realloc(ldb, ldb->schema.attributes, -- cgit