diff options
author | Douglas Bagnall <douglas.bagnall@catalyst.net.nz> | 2019-02-15 10:29:33 +1300 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2019-03-04 21:41:18 +0000 |
commit | bf50324fefdde7120838f17e6aee32ffc1345f22 (patch) | |
tree | 2a46aa4ee63ff390cf1646f72b9687ee0317f8b6 /source4/dsdb/samdb/ldb_modules | |
parent | 7d8cfe02bb4ef30795ccbaee7233e73c29fa9e8c (diff) | |
download | samba-bf50324fefdde7120838f17e6aee32ffc1345f22.tar.gz |
dsdb:replmd: add compatible feature helper function
repl_meta_data.c uses the compatible features attribute of the
"@SAMBA_DSDB" special object to record that linked attributes are
being stored in the database in a sorted order. Soon the
linked_attributes module is going to want to know the same thing, and
in time other modules will want to know about other compatible
features, so we introduce a helper function.
Error checking is slightly improved.
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source4/dsdb/samdb/ldb_modules')
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/repl_meta_data.c | 31 | ||||
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/util.c | 47 |
2 files changed, 56 insertions, 22 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/repl_meta_data.c b/source4/dsdb/samdb/ldb_modules/repl_meta_data.c index 578ffe8a2b5..754f909467a 100644 --- a/source4/dsdb/samdb/ldb_modules/repl_meta_data.c +++ b/source4/dsdb/samdb/ldb_modules/repl_meta_data.c @@ -325,37 +325,24 @@ static int replmd_init(struct ldb_module *module) { struct replmd_private *replmd_private; struct ldb_context *ldb = ldb_module_get_ctx(module); - static const char *samba_dsdb_attrs[] = { SAMBA_COMPATIBLE_FEATURES_ATTR, NULL }; - struct ldb_dn *samba_dsdb_dn; - struct ldb_result *res; int ret; - TALLOC_CTX *frame = talloc_stackframe(); + replmd_private = talloc_zero(module, struct replmd_private); if (replmd_private == NULL) { ldb_oom(ldb); - TALLOC_FREE(frame); return LDB_ERR_OPERATIONS_ERROR; } - ldb_module_set_private(module, replmd_private); - - replmd_private->schema_dn = ldb_get_schema_basedn(ldb); - - samba_dsdb_dn = ldb_dn_new(frame, ldb, "@SAMBA_DSDB"); - if (!samba_dsdb_dn) { - TALLOC_FREE(frame); - return ldb_oom(ldb); - } - ret = dsdb_module_search_dn(module, frame, &res, samba_dsdb_dn, - samba_dsdb_attrs, DSDB_FLAG_NEXT_MODULE, NULL); - if (ret == LDB_SUCCESS) { - replmd_private->sorted_links - = ldb_msg_check_string_attribute(res->msgs[0], - SAMBA_COMPATIBLE_FEATURES_ATTR, - SAMBA_SORTED_LINKS_FEATURE); + ret = dsdb_check_samba_compatible_feature(module, + SAMBA_SORTED_LINKS_FEATURE, + &replmd_private->sorted_links); + if (ret != LDB_SUCCESS) { + talloc_free(replmd_private); + return ret; } - TALLOC_FREE(frame); + replmd_private->schema_dn = ldb_get_schema_basedn(ldb); + ldb_module_set_private(module, replmd_private); return ldb_next_init(module); } diff --git a/source4/dsdb/samdb/ldb_modules/util.c b/source4/dsdb/samdb/ldb_modules/util.c index ba1cfffe574..20c854f0b9a 100644 --- a/source4/dsdb/samdb/ldb_modules/util.c +++ b/source4/dsdb/samdb/ldb_modules/util.c @@ -681,6 +681,53 @@ int dsdb_check_single_valued_link(const struct dsdb_attribute *attr, return LDB_SUCCESS; } + +int dsdb_check_samba_compatible_feature(struct ldb_module *module, + const char *feature, + bool *found) +{ + struct ldb_context *ldb = ldb_module_get_ctx(module); + struct ldb_result *res; + static const char *samba_dsdb_attrs[] = { + SAMBA_COMPATIBLE_FEATURES_ATTR, + NULL + }; + int ret; + struct ldb_dn *samba_dsdb_dn = NULL; + TALLOC_CTX *tmp_ctx = talloc_new(ldb); + if (tmp_ctx == NULL) { + *found = false; + return ldb_oom(ldb); + } + *found = false; + + samba_dsdb_dn = ldb_dn_new(tmp_ctx, ldb, "@SAMBA_DSDB"); + if (samba_dsdb_dn == NULL) { + TALLOC_FREE(tmp_ctx); + return ldb_oom(ldb); + } + + ret = dsdb_module_search_dn(module, + tmp_ctx, + &res, + samba_dsdb_dn, + samba_dsdb_attrs, + DSDB_FLAG_NEXT_MODULE, + NULL); + if (ret == LDB_SUCCESS) { + *found = ldb_msg_check_string_attribute( + res->msgs[0], + SAMBA_COMPATIBLE_FEATURES_ATTR, + feature); + } else if (ret == LDB_ERR_NO_SUCH_OBJECT) { + /* it is not an error not to find it */ + ret = LDB_SUCCESS; + } + TALLOC_FREE(tmp_ctx); + return ret; +} + + /* check if an optional feature is enabled on our own NTDS DN |