summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2016-10-20 16:01:42 +1300
committerAndrew Bartlett <abartlet@samba.org>2016-12-01 05:54:23 +0100
commit393b8f3c1d2552374bff1c5067bf5f86b09446b1 (patch)
treea420c95c9a532c3b5cdd7f6cc22921234293f778 /lib
parentd8ee92734b0fdaee52734f4b22315a31d15388ab (diff)
downloadsamba-393b8f3c1d2552374bff1c5067bf5f86b09446b1.tar.gz
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 <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Diffstat (limited to 'lib')
-rw-r--r--lib/ldb/common/ldb_attributes.c35
-rw-r--r--lib/ldb/include/ldb_private.h6
2 files changed, 41 insertions, 0 deletions
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
@@ -32,6 +32,41 @@
#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
if flags contains LDB_ATTR_FLAG_ALLOCATED
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);