From 393b8f3c1d2552374bff1c5067bf5f86b09446b1 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 20 Oct 2016 16:01:42 +1300 Subject: [PATCH] ldb: Add helper function ldb_schema_attribute_fill_with_syntax() This will allow us to avoid calling ldb_schema_attribute_add_with_syntax() in a tight loop. Signed-off-by: Andrew Bartlett Reviewed-by: Garming Sam --- lib/ldb/common/ldb_attributes.c | 35 +++++++++++++++++++++++++++++++++ lib/ldb/include/ldb_private.h | 6 ++++++ 2 files changed, 41 insertions(+) diff --git a/lib/ldb/common/ldb_attributes.c b/lib/ldb/common/ldb_attributes.c index ca6707edf65..2021a0bf64a 100644 --- a/lib/ldb/common/ldb_attributes.c +++ b/lib/ldb/common/ldb_attributes.c @@ -31,6 +31,41 @@ #include "ldb_private.h" #include "ldb_handlers.h" +/* + fill in an attribute to the ldb_schema into the supplied buffer + + if flags contains LDB_ATTR_FLAG_ALLOCATED + the attribute name string will be copied using + talloc_strdup(), otherwise it needs to be a static const + string at least with a lifetime longer than the ldb struct! + + the ldb_schema_syntax structure should be a pointer + to a static const struct or at least it needs to be + a struct with a longer lifetime than the ldb context! + +*/ +int ldb_schema_attribute_fill_with_syntax(struct ldb_context *ldb, + TALLOC_CTX *mem_ctx, + const char *attribute, + unsigned flags, + const struct ldb_schema_syntax *syntax, + struct ldb_schema_attribute *a) +{ + a->name = attribute; + a->flags = flags; + a->syntax = syntax; + + if (a->flags & LDB_ATTR_FLAG_ALLOCATED) { + a->name = talloc_strdup(mem_ctx, a->name); + if (a->name == NULL) { + ldb_oom(ldb); + return -1; + } + } + + return 0; +} + /* add a attribute to the ldb_schema diff --git a/lib/ldb/include/ldb_private.h b/lib/ldb/include/ldb_private.h index ef0b6971581..644d49cd23f 100644 --- a/lib/ldb/include/ldb_private.h +++ b/lib/ldb/include/ldb_private.h @@ -169,6 +169,12 @@ int ldb_setup_wellknown_attributes(struct ldb_context *ldb); This is to permit correct reloads */ void ldb_schema_attribute_remove_flagged(struct ldb_context *ldb, unsigned int flag); +int ldb_schema_attribute_fill_with_syntax(struct ldb_context *ldb, + TALLOC_CTX *mem_ctx, + const char *attribute, + unsigned flags, + const struct ldb_schema_syntax *syntax, + struct ldb_schema_attribute *a); const char **ldb_subclass_list(struct ldb_context *ldb, const char *classname); void ldb_subclass_remove(struct ldb_context *ldb, const char *classname);