Browse Source

Resolves: #474237
Summary: db2ldif -s "suffix" issues confusing warnings when sub suffix exists
[main.c]
* if -s <dn> is passed to db2ldif, the <dn> is used to look up the instance
name the <dn> belongs to with the base dn "cn=mapping tree,cn=config" and the
filter "(&(objectclass=nsmappingtree)(|(cn=*<dn>\")(cn=*<dn>)))". If the <dn>
is not the suffix, but the sub node, it fails to find out the instance which
contains the <dn>. To solve the problem, going upward the DIT until the
instance is found.
* If multiple backends are specified to export, all the names are printed.
[ldif2ldbm.c]
* ldbm_fetch_subtrees: when -s <dn> is passsed to db2ldif, added a logic to
avoid the further process if the <dn> does not belong to the backend.
* When multiple backends are exported, dse was loaded each time. Changed not
to do so.
* Export counter was not decremented when the entry was not to be exported.

Noriko Hosoi 17 years ago
parent
commit
8233e81582
2 changed files with 136 additions and 52 deletions
  1. 70 13
      ldap/servers/slapd/back-ldbm/ldif2ldbm.c
  2. 66 39
      ldap/servers/slapd/main.c

+ 70 - 13
ldap/servers/slapd/back-ldbm/ldif2ldbm.c

@@ -675,9 +675,61 @@ static IDList *ldbm_fetch_subtrees(backend *be, char **include, int *err)
     back_txn *txn = NULL;
     struct berval bv;
 
+    *err = 0;
     /* for each subtree spec... */
     for (i = 0; include[i]; i++) {
         IDList *idl = NULL;
+        char *suffix = slapi_sdn_get_ndn(*be->be_suffix);
+        char *parentdn = slapi_ch_strdup(suffix);
+        char *nextdn = NULL;
+        int matched = 0;
+        int issubsuffix = 0;
+        /*
+         * avoid a case that an include suffix is applied to the backend of 
+         * its sub suffix 
+         * e.g., suffix: dc=example,dc=com (backend userRoot)
+         *       sub suffix: ou=sub,dc=example,dc=com (backend subUserRoot)
+         * When this CLI db2ldif -s "dc=example,dc=com" is executed,
+         * skip checking "dc=example,dc=com" in entrydn of subUserRoot.
+         */
+        while (NULL != parentdn &&
+               NULL != (nextdn = slapi_dn_parent( parentdn ))) {
+            slapi_ch_free_string( &parentdn );
+            if (0 == slapi_utf8casecmp(nextdn, include[i])) {
+                issubsuffix = 1; /* suffix of be is a subsuffix of include[i] */
+                break;
+            }
+            parentdn = nextdn;
+        }
+        slapi_ch_free_string( &parentdn );
+        slapi_ch_free_string( &nextdn );
+        if (issubsuffix) {
+            continue;
+        }
+
+        /*
+         * avoid a case that an include suffix is applied to the unrelated
+         * backend.
+         * e.g., suffix: dc=example,dc=com (backend userRoot)
+         *       suffix: dc=test,dc=com (backend testRoot))
+         * When this CLI db2ldif -s "dc=example,dc=com" is executed,
+         * skip checking "dc=example,dc=com" in entrydn of testRoot.
+         */
+        parentdn = slapi_ch_strdup(include[i]);
+        while (NULL != parentdn &&
+               NULL != (nextdn = slapi_dn_parent( parentdn ))) {
+            slapi_ch_free_string( &parentdn );
+            if (0 == slapi_utf8casecmp(nextdn, suffix)) {
+                matched = 1;
+                break;
+            }
+            parentdn = nextdn;
+        }
+        slapi_ch_free_string( &parentdn );
+        slapi_ch_free_string( &nextdn );
+        if (!matched) {
+            continue;
+        }
 
         /* 
          * First map the suffix to its entry ID.
@@ -689,7 +741,7 @@ static IDList *ldbm_fetch_subtrees(backend *be, char **include, int *err)
         if (idl == NULL) {
             if (DB_NOTFOUND == *err) {
                 LDAPDebug(LDAP_DEBUG_ANY,
-                    "warning: entrydn not indexed on '%s'; "
+                    "info: entrydn not indexed on '%s'; "
                     "entry %s may not be added to the database yet.\n",
                     include[i], include[i], 0);
                 *err = 0; /* not a problem */
@@ -787,6 +839,7 @@ ldbm_back_ldbm2ldif( Slapi_PBlock *pb )
     int              str2entry_options= 0;
     int              retry;
     int              we_start_the_backends = 0;
+    static int       load_dse = 1; /* We'd like to load dse just once. */
     int              server_running;
 
     LDAPDebug( LDAP_DEBUG_TRACE, "=> ldbm_back_ldbm2ldif\n", 0, 0, 0 );
@@ -805,7 +858,7 @@ ldbm_back_ldbm2ldif( Slapi_PBlock *pb )
         }
     }
 
-    if (we_start_the_backends) {
+    if (we_start_the_backends && load_dse) {
         /* No ldbm be's exist until we process the config information. */
 
         /*
@@ -815,6 +868,7 @@ ldbm_back_ldbm2ldif( Slapi_PBlock *pb )
          *   WARNING: ldbm instance userRoot already exists
          */
         ldbm_config_load_dse_info(li);
+        load_dse = 0;
     }
 
     if (run_from_cmdline && li->li_dblayer_private->dblayer_private_mem
@@ -1004,17 +1058,19 @@ ldbm_back_ldbm2ldif( Slapi_PBlock *pb )
         int err;
 
         idl = ldbm_fetch_subtrees(be, include_suffix, &err);
-        if (! idl) {
-            /* most likely, indexes are bad. */
-            LDAPDebug(LDAP_DEBUG_ANY,
-                  "Failed to fetch subtree lists (error %d) %s\n",
-                  err, dblayer_strerror(err), 0);
-            LDAPDebug(LDAP_DEBUG_ANY,
-                  "Possibly the entrydn or ancestorid index is corrupted or "
-                  "does not exist.\n", 0, 0, 0);
-            LDAPDebug(LDAP_DEBUG_ANY,
-                  "Attempting direct unindexed export instead.\n",
-                  0, 0, 0);
+        if (NULL == idl) {
+            if (err) {
+                /* most likely, indexes are bad. */
+                LDAPDebug(LDAP_DEBUG_ANY,
+                      "Failed to fetch subtree lists (error %d) %s\n",
+                      err, dblayer_strerror(err), 0);
+                LDAPDebug(LDAP_DEBUG_ANY,
+                      "Possibly the entrydn or ancestorid index is corrupted "
+                      "or does not exist.\n", 0, 0, 0);
+                LDAPDebug(LDAP_DEBUG_ANY,
+                      "Attempting direct unindexed export instead.\n",
+                      0, 0, 0);
+            }
             ok_index = 0;
             idl = NULL;
         } else if (ALLIDS(idl)) {
@@ -1122,6 +1178,7 @@ ldbm_back_ldbm2ldif( Slapi_PBlock *pb )
         if (!ldbm_back_ok_to_dump(backentry_get_ndn(ep), include_suffix,
                       exclude_suffix)) {
             backentry_free( &ep );
+            cnt--;
             continue;
         }
         if(!dump_replica && slapi_entry_flag_is_set(ep->ep_entry, SLAPI_ENTRY_FLAG_TOMBSTONE))

+ 66 - 39
ldap/servers/slapd/main.c

@@ -1839,56 +1839,81 @@ process_command_line(int argc, char **argv, char *myname,
 
 static int
 lookup_instance_name_by_suffix(char *suffix,
-							   char ***suffixes, char ***instances, int isexact)
+                               char ***suffixes, char ***instances, int isexact)
 {
     Slapi_PBlock *pb = slapi_pblock_new();
     Slapi_Entry **entries = NULL, **ep;
     char *query;
-	char *backend;
-	char *fullsuffix;
-	int rval = -1;
+    char *backend;
+    char *fullsuffix;
+    int rval = -1;
 
     if (pb == NULL)
         goto done;
 
-	if (isexact)
-    	query = slapi_ch_smprintf("(&(objectclass=nsmappingtree)(|(cn=\"%s\")(cn=%s)))", suffix, suffix);
-	else
-    	query = slapi_ch_smprintf("(&(objectclass=nsmappingtree)(|(cn=*%s\")(cn=*%s)))", suffix, suffix);
-
-    if (query == NULL)
-		goto done;
-
-    slapi_search_internal_set_pb(pb, "cn=mapping tree,cn=config",
-        LDAP_SCOPE_SUBTREE, query, NULL, 0, NULL, NULL,
-        (void *)plugin_get_default_component_id(), 0);
-    slapi_search_internal_pb(pb);
-    slapi_ch_free((void **)&query);
+    if (isexact) {
+        query = slapi_ch_smprintf("(&(objectclass=nsmappingtree)(|(cn=\"%s\")(cn=%s)))", suffix, suffix);
+        if (query == NULL)
+            goto done;
+    
+        slapi_search_internal_set_pb(pb, "cn=mapping tree,cn=config",
+            LDAP_SCOPE_SUBTREE, query, NULL, 0, NULL, NULL,
+            (void *)plugin_get_default_component_id(), 0);
+        slapi_search_internal_pb(pb);
+        slapi_ch_free((void **)&query);
+    
+        slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rval);
+        if (rval != LDAP_SUCCESS)
+            goto done;
 
-    slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rval);
-    if (rval != LDAP_SUCCESS)
-		goto done;
+        slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
+        if ((entries == NULL) || (entries[0] == NULL))
+            goto done;
 
-    slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
-    if ((entries == NULL) || (entries[0] == NULL))
-		goto done;
+    } else {
+        char *suffixp = suffix;
+        while (NULL != suffixp && strlen(suffixp) > 0) {
+            query = slapi_ch_smprintf("(&(objectclass=nsmappingtree)(|(cn=*%s\")(cn=*%s)))", suffixp, suffixp);
+            if (query == NULL)
+                goto done;
+            slapi_search_internal_set_pb(pb, "cn=mapping tree,cn=config",
+                LDAP_SCOPE_SUBTREE, query, NULL, 0, NULL, NULL,
+                (void *)plugin_get_default_component_id(), 0);
+            slapi_search_internal_pb(pb);
+            slapi_ch_free((void **)&query);
+
+            slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rval);
+            if (rval != LDAP_SUCCESS)
+                goto done;
+
+            slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
+            if ((entries == NULL) || (entries[0] == NULL)) {
+                suffixp = strchr(suffixp, ',');    /* get a parent dn */
+                if (NULL != suffixp) {
+                    suffixp++;
+                }
+            } else {
+                break;    /* found backend entries */
+            }
+        }
+    }
 
-	rval = 0;
-	for (ep = entries; *ep; ep++) {
-		backend = slapi_entry_attr_get_charptr(*ep, "nsslapd-backend");
-		if (backend) {
-			charray_add(instances, backend);
-			if (suffixes) {
-				fullsuffix = slapi_entry_attr_get_charptr(*ep, "cn");
-				charray_add(suffixes, fullsuffix);	/* NULL is ok */
-			}
-		}
-	}
+    rval = 0;
+    for (ep = entries; *ep; ep++) {
+        backend = slapi_entry_attr_get_charptr(*ep, "nsslapd-backend");
+        if (backend) {
+            charray_add(instances, backend);
+            if (suffixes) {
+                fullsuffix = slapi_entry_attr_get_charptr(*ep, "cn");
+                charray_add(suffixes, fullsuffix);    /* NULL is ok */
+            }
+        }
+    }
 
 done:
-	slapi_free_search_results_internal(pb);
-	slapi_pblock_destroy(pb);
-	return rval;
+    slapi_free_search_results_internal(pb);
+    slapi_pblock_destroy(pb);
+    return rval;
 }
 
 int
@@ -2167,8 +2192,10 @@ slapd_exemode_db2ldif(int argc, char** argv)
 					0, 0, 0);
 				exit(1);
 			} else {
-				LDAPDebug(LDAP_DEBUG_ANY, "Backend Instance: %s\n",
-					*instances, 0, 0);
+				LDAPDebug(LDAP_DEBUG_ANY, "Backend Instance(s): \n", 0, 0, 0);
+				for (ip = instances, counter = 0; ip && *ip; ip++, counter++) {
+					LDAPDebug(LDAP_DEBUG_ANY, "\t%s\n", *ip, 0, 0);
+				}
 				cmd_line_instance_names = instances;
 			}
 		} else {