zrhoffman / rpms / 389-ds-base

Forked from rpms/389-ds-base 3 years ago
Clone

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

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