dsdb:replmd: add compatible feature helper function
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 14 Feb 2019 21:29:33 +0000 (10:29 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 4 Mar 2019 21:41:18 +0000 (21:41 +0000)
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>
source4/dsdb/samdb/ldb_modules/repl_meta_data.c
source4/dsdb/samdb/ldb_modules/util.c

index 578ffe8a2b5c3353f63583d28bea18d72eda1963..754f909467a7dba55c9fefc0174b294153266c83 100644 (file)
@@ -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);
 }
 
index ba1cfffe57417aedc1452aade4ef031338f690ea..20c854f0b9ae453379576e0c1d6beb0ffc3f9cad 100644 (file)
@@ -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