ldb: binding ordered indexes to GUID indexing
authorAaron Haslett <aaronhaslett@catalyst.net.nz>
Wed, 22 May 2019 02:07:19 +0000 (14:07 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 29 May 2019 04:41:24 +0000 (04:41 +0000)
To reduce the number of potential combinations of database features in
ldb, we want to link all new database features since 4.7. GUID indexing,
ordered integers, and pack format changes will all upgrade together.
This patch makes ordered integers only function if GUID indexing is
enabled. If GUID indexing is disabled, ORDERED_INTEGER will not be
written to @ATTRIBUTES and a syntax's index_format_fn will never be
used.

Signed-off-by: Aaron Haslett <aaronhaslett@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
source4/dsdb/schema/schema_set.c

index b7043bd22caa5a7bd39170191b473d001585b3aa..19beec561a4938d7e2a7321afaece44e751bf5a5 100644 (file)
@@ -73,11 +73,22 @@ int dsdb_schema_set_indices_and_attributes(struct ldb_context *ldb,
        struct loadparm_context *lp_ctx =
                talloc_get_type(ldb_get_opaque(ldb, "loadparm"),
                                struct loadparm_context);
+       bool guid_indexing = true;
+       if (lp_ctx != NULL) {
+               /*
+                * GUID indexing is wanted by Samba by default.  This allows
+                * an override in a specific case for downgrades.
+                */
+               guid_indexing = lpcfg_parm_bool(lp_ctx,
+                                               NULL,
+                                               "dsdb",
+                                               "guid index",
+                                               true);
+       }
        /* setup our own attribute name to schema handler */
        ldb_schema_attribute_set_override_handler(ldb, dsdb_attribute_handler_override, schema);
        ldb_schema_set_override_indexlist(ldb, true);
-       if (lp_ctx == NULL ||
-           lpcfg_parm_bool(lp_ctx, NULL, "dsdb", "guid index", true)) {
+       if (guid_indexing) {
                ldb_schema_set_override_GUID_index(ldb, "objectGUID", "GUID");
        }
 
@@ -116,8 +127,7 @@ int dsdb_schema_set_indices_and_attributes(struct ldb_context *ldb,
                goto op_error;
        }
 
-       if (lp_ctx == NULL ||
-           lpcfg_parm_bool(lp_ctx, NULL, "dsdb", "guid index", true)) {
+       if (guid_indexing) {
                ret = ldb_msg_add_string(msg_idx, "@IDXGUID", "objectGUID");
                if (ret != LDB_SUCCESS) {
                        goto op_error;
@@ -148,12 +158,25 @@ int dsdb_schema_set_indices_and_attributes(struct ldb_context *ldb,
 
                /*
                 * Write out a rough approximation of the schema
-                * as an @ATTRIBUTES value, for bootstrapping
+                * as an @ATTRIBUTES value, for bootstrapping.
+                * Only write ORDERED_INTEGER if we're using GUID indexes,
                 */
                if (strcmp(syntax, LDB_SYNTAX_INTEGER) == 0) {
                        ret = ldb_msg_add_string(msg, attr->lDAPDisplayName, "INTEGER");
                } else if (strcmp(syntax, LDB_SYNTAX_ORDERED_INTEGER) == 0) {
-                       ret = ldb_msg_add_string(msg, attr->lDAPDisplayName, "ORDERED_INTEGER");
+                       /*
+                        * When preparing to downgrade Samba, we need to write
+                        * out an LDB without the new key word ORDERED_INTEGER.
+                        */
+                       if (guid_indexing) {
+                               ret = ldb_msg_add_string(msg,
+                                                        attr->lDAPDisplayName,
+                                                        "ORDERED_INTEGER");
+                       } else {
+                               ret = ldb_msg_add_string(msg,
+                                                        attr->lDAPDisplayName,
+                                                        "INTEGER");
+                       }
                } else if (strcmp(syntax, LDB_SYNTAX_DIRECTORY_STRING) == 0) {
                        ret = ldb_msg_add_string(msg, attr->lDAPDisplayName, "CASE_INSENSITIVE");
                }