diff options
author | Andrew Bartlett <abartlet@samba.org> | 2016-10-20 16:04:04 +1300 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2016-12-01 05:54:23 +0100 |
commit | 604a4fd438200d36c65aec089bdf43dba0b87e6f (patch) | |
tree | eb7104df3f1af9922b5ad184536c7c75aa58f43f /lib | |
parent | 4e1b965005d76b3dc57cb7efbf21591a3cf80688 (diff) | |
download | samba-604a4fd438200d36c65aec089bdf43dba0b87e6f.tar.gz |
ldb: Add helper function ldb_schema_attribute_remove_flagged()
This helps us avoid keeping a list of attributes to later remove on @ATTRIBUTES reload
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ldb/common/ldb_attributes.c | 33 | ||||
-rw-r--r-- | lib/ldb/include/ldb.h | 5 | ||||
-rw-r--r-- | lib/ldb/include/ldb_private.h | 6 |
3 files changed, 44 insertions, 0 deletions
diff --git a/lib/ldb/common/ldb_attributes.c b/lib/ldb/common/ldb_attributes.c index 767f69cdbbc..ca6707edf65 100644 --- a/lib/ldb/common/ldb_attributes.c +++ b/lib/ldb/common/ldb_attributes.c @@ -216,6 +216,39 @@ 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 +*/ +void ldb_schema_attribute_remove_flagged(struct ldb_context *ldb, unsigned int flag) +{ + ptrdiff_t i; + + for (i = 0; i < ldb->schema.num_attributes;) { + const struct ldb_schema_attribute *a + = &ldb->schema.attributes[i]; + /* FIXED attributes are never removed */ + if (a->flags & LDB_ATTR_FLAG_FIXED) { + i++; + continue; + } + if ((a->flags & flag) == 0) { + i++; + continue; + } + if (a->flags & LDB_ATTR_FLAG_ALLOCATED) { + talloc_free(discard_const_p(char, a->name)); + } + if (i < ldb->schema.num_attributes - 1) { + memmove(&ldb->schema.attributes[i], + a+1, sizeof(*a) * (ldb->schema.num_attributes-(i+1))); + } + + ldb->schema.num_attributes--; + } +} + +/* setup a attribute handler using a standard syntax */ int ldb_schema_attribute_add(struct ldb_context *ldb, diff --git a/lib/ldb/include/ldb.h b/lib/ldb/include/ldb.h index ef292302d39..397f9946710 100644 --- a/lib/ldb/include/ldb.h +++ b/lib/ldb/include/ldb.h @@ -427,6 +427,11 @@ const struct ldb_dn_extended_syntax *ldb_dn_extended_syntax_by_name(struct ldb_c */ #define LDB_ATTR_FLAG_FORCE_BASE64_LDIF (1<<5) +/* + * The attribute was loaded from a DB, rather than via the C API + */ +#define LDB_ATTR_FLAG_FROM_DB (1<<6) + /** LDAP attribute syntax for a DN diff --git a/lib/ldb/include/ldb_private.h b/lib/ldb/include/ldb_private.h index 26a9d426afb..ef0b6971581 100644 --- a/lib/ldb/include/ldb_private.h +++ b/lib/ldb/include/ldb_private.h @@ -163,6 +163,12 @@ extern const struct ldb_backend_ops ldb_ldapi_backend_ops; extern const struct ldb_backend_ops ldb_ldaps_backend_ops; int ldb_setup_wellknown_attributes(struct ldb_context *ldb); +/* + remove attributes with a specified flag (eg LDB_ATTR_FLAG_FROM_DB) for this ldb context + + This is to permit correct reloads +*/ +void ldb_schema_attribute_remove_flagged(struct ldb_context *ldb, unsigned int flag); const char **ldb_subclass_list(struct ldb_context *ldb, const char *classname); void ldb_subclass_remove(struct ldb_context *ldb, const char *classname); |