andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone

Blame SOURCES/0000-Ticket-49830-Import-fails-if-backend-name-is-default.patch

edc5f2
From da5a1bbb4e4352b8df10c84572441d47217b6c2c Mon Sep 17 00:00:00 2001
edc5f2
From: Mark Reynolds <mreynolds@redhat.com>
edc5f2
Date: Fri, 6 Jul 2018 11:37:56 -0400
edc5f2
Subject: [PATCH] Ticket 49830 - Import fails if backend name is "default"
edc5f2
edc5f2
Bug Description:  The server was previously reserving the backend
edc5f2
                  name "default".  If you tried to import on a
edc5f2
                  backend with this name the import would skip all
edc5f2
                  child entries
edc5f2
edc5f2
Fix Description:  Change the default backend name to something
edc5f2
                  obscure, instead of "default".
edc5f2
edc5f2
                  Also improved lib389's dbgen to generate the
edc5f2
                  correct "dc" attribute value in the root node.
edc5f2
edc5f2
https://pagure.io/389-ds-base/issue/49830
edc5f2
edc5f2
Reviewed by: spichugi(Thanks!)
edc5f2
edc5f2
(cherry picked from commit 8fa838a4ffd4d0c15ae51cb21f246bb1f2dea2a1)
edc5f2
---
edc5f2
 .../tests/suites/import/regression_test.py    | 46 +++++++++++++++++++
edc5f2
 ldap/servers/slapd/defbackend.c               |  4 +-
edc5f2
 ldap/servers/slapd/mapping_tree.c             |  7 ++-
edc5f2
 ldap/servers/slapd/slap.h                     |  3 ++
edc5f2
 src/lib389/lib389/dbgen.py                    | 13 +++++-
edc5f2
 5 files changed, 66 insertions(+), 7 deletions(-)
edc5f2
edc5f2
diff --git a/dirsrvtests/tests/suites/import/regression_test.py b/dirsrvtests/tests/suites/import/regression_test.py
edc5f2
index ad51721a1..d83d00323 100644
edc5f2
--- a/dirsrvtests/tests/suites/import/regression_test.py
edc5f2
+++ b/dirsrvtests/tests/suites/import/regression_test.py
edc5f2
@@ -23,6 +23,52 @@ TEST_SUFFIX1 = "dc=importest1,dc=com"
edc5f2
 TEST_BACKEND1 = "importest1"
edc5f2
 TEST_SUFFIX2 = "dc=importest2,dc=com"
edc5f2
 TEST_BACKEND2 = "importest2"
edc5f2
+TEST_DEFAULT_SUFFIX = "dc=default,dc=com"
edc5f2
+TEST_DEFAULT_NAME = "default"
edc5f2
+
edc5f2
+
edc5f2
+def test_import_be_default(topo):
edc5f2
+    """ Create a backend using the name "default". previously this name was
edc5f2
+    used int
edc5f2
+
edc5f2
+    :id: 8e507beb-e917-4330-8cac-1ff0eee10508
edc5f2
+    :feature: Import
edc5f2
+    :setup: Standalone instance
edc5f2
+    :steps:
edc5f2
+        1. Create a test suffix using the be name of "default"
edc5f2
+        2. Create an ldif for the "default" backend
edc5f2
+        3. Import ldif
edc5f2
+        4. Verify all entries were imported
edc5f2
+    :expectedresults:
edc5f2
+        1. Success
edc5f2
+        2. Success
edc5f2
+        3. Success
edc5f2
+        4. Success
edc5f2
+    """
edc5f2
+    log.info('Adding suffix:{} and backend: {}...'.format(TEST_DEFAULT_SUFFIX,
edc5f2
+                                                          TEST_DEFAULT_NAME))
edc5f2
+    backends = Backends(topo.standalone)
edc5f2
+    backends.create(properties={BACKEND_SUFFIX: TEST_DEFAULT_SUFFIX,
edc5f2
+                                BACKEND_NAME: TEST_DEFAULT_NAME})
edc5f2
+
edc5f2
+    log.info('Create LDIF file and import it...')
edc5f2
+    ldif_dir = topo.standalone.get_ldif_dir()
edc5f2
+    ldif_file = os.path.join(ldif_dir, 'default.ldif')
edc5f2
+    dbgen(topo.standalone, 5, ldif_file, TEST_DEFAULT_SUFFIX)
edc5f2
+
edc5f2
+    log.info('Stopping the server and running offline import...')
edc5f2
+    topo.standalone.stop()
edc5f2
+    assert topo.standalone.ldif2db(TEST_DEFAULT_NAME, None, None,
edc5f2
+                                   None, ldif_file)
edc5f2
+    topo.standalone.start()
edc5f2
+
edc5f2
+    log.info('Verifying entry count after import...')
edc5f2
+    entries = topo.standalone.search_s(TEST_DEFAULT_SUFFIX,
edc5f2
+                                       ldap.SCOPE_SUBTREE,
edc5f2
+                                       "(objectclass=*)")
edc5f2
+    assert len(entries) > 1
edc5f2
+
edc5f2
+    log.info('Test PASSED')
edc5f2
 
edc5f2
 
edc5f2
 def test_del_suffix_import(topo):
edc5f2
diff --git a/ldap/servers/slapd/defbackend.c b/ldap/servers/slapd/defbackend.c
edc5f2
index aa709da87..b0465e297 100644
edc5f2
--- a/ldap/servers/slapd/defbackend.c
edc5f2
+++ b/ldap/servers/slapd/defbackend.c
edc5f2
@@ -23,8 +23,6 @@
edc5f2
 /*
edc5f2
  * ---------------- Macros ---------------------------------------------------
edc5f2
  */
edc5f2
-#define DEFBACKEND_TYPE "default"
edc5f2
-
edc5f2
 #define DEFBACKEND_OP_NOT_HANDLED 0
edc5f2
 #define DEFBACKEND_OP_HANDLED 1
edc5f2
 
edc5f2
@@ -65,7 +63,7 @@ defbackend_init(void)
edc5f2
     /*
edc5f2
      * create a new backend
edc5f2
      */
edc5f2
-    defbackend_backend = slapi_be_new(DEFBACKEND_TYPE, DEFBACKEND_TYPE, 1 /* Private */, 0 /* Do Not Log Changes */);
edc5f2
+    defbackend_backend = slapi_be_new(DEFBACKEND_TYPE, DEFBACKEND_NAME, 1 /* Private */, 0 /* Do Not Log Changes */);
edc5f2
     if ((rc = slapi_pblock_set(pb, SLAPI_BACKEND, defbackend_backend)) != 0) {
edc5f2
         errmsg = "slapi_pblock_set SLAPI_BACKEND failed";
edc5f2
         goto cleanup_and_return;
edc5f2
diff --git a/ldap/servers/slapd/mapping_tree.c b/ldap/servers/slapd/mapping_tree.c
edc5f2
index 472a2f6aa..834949a67 100644
edc5f2
--- a/ldap/servers/slapd/mapping_tree.c
edc5f2
+++ b/ldap/servers/slapd/mapping_tree.c
edc5f2
@@ -748,7 +748,7 @@ mapping_tree_entry_add(Slapi_Entry *entry, mapping_tree_node **newnodep)
edc5f2
         be_names = (char **)slapi_ch_calloc(1, sizeof(char *));
edc5f2
         be_states = (int *)slapi_ch_calloc(1, sizeof(int));
edc5f2
 
edc5f2
-        tmp_backend_name = (char *)slapi_ch_strdup("default"); /* "NULL_CONTAINER" */
edc5f2
+        tmp_backend_name = (char *)slapi_ch_strdup(DEFBACKEND_NAME); /* "NULL_CONTAINER" */
edc5f2
         (be_names)[be_list_count] = tmp_backend_name;
edc5f2
 
edc5f2
         /* set backend as started by default */
edc5f2
@@ -2250,7 +2250,10 @@ slapi_mapping_tree_select_all(Slapi_PBlock *pb, Slapi_Backend **be_list, Slapi_E
edc5f2
         if (ret != LDAP_SUCCESS) {
edc5f2
             /* flag we have problems at least on part of the tree */
edc5f2
             flag_partial_result = 1;
edc5f2
-        } else if ((((!slapi_sdn_issuffix(sdn, slapi_mtn_get_dn(node)) && !slapi_sdn_issuffix(slapi_mtn_get_dn(node), sdn))) || ((node_list == mapping_tree_root) && node->mtn_private && (scope != LDAP_SCOPE_BASE))) && (!be || strncmp(be->be_name, "default", 8))) {
edc5f2
+        } else if ((((!slapi_sdn_issuffix(sdn, slapi_mtn_get_dn(node)) && !slapi_sdn_issuffix(slapi_mtn_get_dn(node), sdn))) ||
edc5f2
+                    ((node_list == mapping_tree_root) && node->mtn_private && (scope != LDAP_SCOPE_BASE))) &&
edc5f2
+                    (!be || strncmp(be->be_name, DEFBACKEND_NAME, 8)))
edc5f2
+        {
edc5f2
             if (be && !be_isdeleted(be)) {
edc5f2
                 /* wrong backend or referall, ignore it */
edc5f2
                 slapi_log_err(SLAPI_LOG_ARGS, "slapi_mapping_tree_select_all",
edc5f2
diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h
edc5f2
index 7378c2d2a..eb97cdcc4 100644
edc5f2
--- a/ldap/servers/slapd/slap.h
edc5f2
+++ b/ldap/servers/slapd/slap.h
edc5f2
@@ -45,6 +45,9 @@ static char ptokPBE[34] = "Internal (Software) Token        ";
edc5f2
 #define SLAPD_EXEMODE_DBVERIFY        12
edc5f2
 #define SLAPD_EXEMODE_UPGRADEDNFORMAT 13
edc5f2
 
edc5f2
+#define DEFBACKEND_TYPE "default"
edc5f2
+#define DEFBACKEND_NAME "DirectoryServerDefaultBackend"
edc5f2
+
edc5f2
 #define LDAP_SYSLOG
edc5f2
 #include <syslog.h>
edc5f2
 #define RLIM_TYPE int
edc5f2
diff --git a/src/lib389/lib389/dbgen.py b/src/lib389/lib389/dbgen.py
edc5f2
index a0cda9430..68455b480 100644
edc5f2
--- a/src/lib389/lib389/dbgen.py
edc5f2
+++ b/src/lib389/lib389/dbgen.py
edc5f2
@@ -113,8 +113,13 @@ usercertificate;binary:: MIIBvjCCASegAwIBAgIBAjANBgkqhkiG9w0BAQQFADAnMQ8wDQYD
edc5f2
 DBGEN_HEADER = """dn: {SUFFIX}
edc5f2
 objectClass: top
edc5f2
 objectClass: domain
edc5f2
+<<<<<<< HEAD
edc5f2
 dc: example
edc5f2
 aci: (target=ldap:///{SUFFIX})(targetattr=*)(version 3.0; acl "acl1"; allow(write) userdn = "ldap:///self";) 
edc5f2
+=======
edc5f2
+dc: {RDN}
edc5f2
+aci: (target=ldap:///{SUFFIX})(targetattr=*)(version 3.0; acl "acl1"; allow(write) userdn = "ldap:///self";)
edc5f2
+>>>>>>> 8fa838a4f... Ticket 49830 - Import fails if backend name is "default"
edc5f2
 aci: (target=ldap:///{SUFFIX})(targetattr=*)(version 3.0; acl "acl2"; allow(write) groupdn = "ldap:///cn=Directory Administrators, {SUFFIX}";)
edc5f2
 aci: (target=ldap:///{SUFFIX})(targetattr=*)(version 3.0; acl "acl3"; allow(read, search, compare) userdn = "ldap:///anyone";)
edc5f2
 
edc5f2
@@ -145,7 +150,7 @@ ou: Payroll
edc5f2
 
edc5f2
 """
edc5f2
 
edc5f2
-def dbgen(instance, number, ldif_file, suffix):
edc5f2
+def dbgen(instance, number, ldif_file, suffix, pseudol10n=False):
edc5f2
     familyname_file = os.path.join(instance.ds_paths.data_dir, 'dirsrv/data/dbgen-FamilyNames')
edc5f2
     givename_file = os.path.join(instance.ds_paths.data_dir, 'dirsrv/data/dbgen-GivenNames')
edc5f2
     familynames = []
edc5f2
@@ -156,7 +161,11 @@ def dbgen(instance, number, ldif_file, suffix):
edc5f2
         givennames = [n.strip() for n in f]
edc5f2
 
edc5f2
     with open(ldif_file, 'w') as output:
edc5f2
-        output.write(DBGEN_HEADER.format(SUFFIX=suffix))
edc5f2
+        rdn = suffix.split(",", 1)[0].split("=", 1)[1]
edc5f2
+        output.write(DBGEN_HEADER.format(SUFFIX=suffix, RDN=rdn))
edc5f2
+        for ou in DBGEN_OUS:
edc5f2
+            ou = pseudolocalize(ou) if pseudol10n else ou
edc5f2
+            output.write(DBGEN_OU_TEMPLATE.format(SUFFIX=suffix, OU=ou))
edc5f2
         for i in range(0, number):
edc5f2
             # Pick a random ou
edc5f2
             ou = random.choice(DBGEN_OUS)
edc5f2
-- 
edc5f2
2.17.1
edc5f2