[Fedora-directory-commits] ldapserver/ldap/servers/slapd main.c, 1.27, 1.28

Noriko Hosoi nhosoi at fedoraproject.org
Thu Dec 4 00:50:20 UTC 2008


Author: nhosoi

Update of /cvs/dirsec/ldapserver/ldap/servers/slapd
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv18184

Modified Files:
	main.c 
Log Message:
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.



Index: main.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/main.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- main.c	24 Oct 2008 22:36:58 -0000	1.27
+++ main.c	4 Dec 2008 00:50:18 -0000	1.28
@@ -1839,56 +1839,81 @@
 
 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);
-
-    slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rval);
-    if (rval != LDAP_SUCCESS)
-		goto done;
+    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_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 @@
 					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 {




More information about the Fedora-directory-commits mailing list