[389-commits] ldap/servers

Nathan Kinder nkinder at fedoraproject.org
Mon May 9 22:17:45 UTC 2011


 ldap/servers/plugins/automember/automember.c |  101 ++++++++++++---------------
 1 file changed, 48 insertions(+), 53 deletions(-)

New commits:
commit aac472b9a288f2b7c50549a7c9b65bb6b41ae9ea
Author: Nathan Kinder <nkinder at redhat.com>
Date:   Mon May 9 14:45:52 2011 -0700

    Bug 703304 - Auto membership alternate config area should override default area
    
    The auto membership plug-in should make the alternate config area
    (specified as nsslapd-pluginConfigArea) override the default config area.
    It currently uses both areas, which could make migrating config from the
    default area to a shared/replicated area more difficult.  I don't see a
    strong need for having 2 config areas in use at once, so an override
    makes sense.
    
    To make the override work, we only need to modify the config loading
    code to load the alternate area if one is configured, otherwise we
    load from the default area.  The helper function that checks if a DN
    is a config entry needs to follow the same logic.

diff --git a/ldap/servers/plugins/automember/automember.c b/ldap/servers/plugins/automember/automember.c
index 670ae64..106cab7 100644
--- a/ldap/servers/plugins/automember/automember.c
+++ b/ldap/servers/plugins/automember/automember.c
@@ -409,17 +409,45 @@ automember_load_config()
                     "automember_load_config: Looking for config entries "
                     "beneath \"%s\".\n", slapi_sdn_get_ndn(automember_get_plugin_sdn()));
 
-    /* Find the config entries beneath our plugin entry. */
     search_pb = slapi_pblock_new();
-    slapi_search_internal_set_pb(search_pb, slapi_sdn_get_ndn(automember_get_plugin_sdn()),
-                                 LDAP_SCOPE_SUBTREE, "objectclass=*",
-                                 NULL, 0, NULL, NULL, automember_get_plugin_id(), 0);
+
+    /* If an alternate config area is configured, find
+     * the config entries that are beneath it, otherwise
+     * we load the entries beneath our top-level plug-in
+     * config entry. */
+    if (automember_get_config_area()) {
+        /* Find the config entries beneath the alternate config area. */
+        slapi_log_error(SLAPI_LOG_PLUGIN, AUTOMEMBER_PLUGIN_SUBSYSTEM,
+                        "automember_load_config: Looking for config entries "
+                        "beneath \"%s\".\n", slapi_sdn_get_ndn(automember_get_config_area()));
+
+        slapi_search_internal_set_pb(search_pb, slapi_sdn_get_ndn(automember_get_config_area()),
+                                     LDAP_SCOPE_SUBTREE, "objectclass=*",
+                                     NULL, 0, NULL, NULL, automember_get_plugin_id(), 0);
+    } else {
+        /* Find the config entries beneath our plugin entry. */
+        slapi_log_error(SLAPI_LOG_PLUGIN, AUTOMEMBER_PLUGIN_SUBSYSTEM,
+                        "automember_load_config: Looking for config entries "
+                        "beneath \"%s\".\n", slapi_sdn_get_ndn(automember_get_plugin_sdn()));
+
+        slapi_search_internal_set_pb(search_pb, slapi_sdn_get_ndn(automember_get_plugin_sdn()),
+                                     LDAP_SCOPE_SUBTREE, "objectclass=*",
+                                     NULL, 0, NULL, NULL, automember_get_plugin_id(), 0);
+    }
+
     slapi_search_internal_pb(search_pb);
     slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
 
     if (LDAP_SUCCESS != result) {
-        status = -1;
-        goto cleanup;
+        if (automember_get_config_area() && (result == LDAP_NO_SUCH_OBJECT)) {
+            slapi_log_error(SLAPI_LOG_PLUGIN, AUTOMEMBER_PLUGIN_SUBSYSTEM,
+                            "automember_load_config: Config container \"%s\" does "
+                            "not exist.\n", slapi_sdn_get_ndn(automember_get_config_area()));
+            goto cleanup;
+        } else {
+            status = -1;
+            goto cleanup;
+        }
     }
 
     slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES,
@@ -436,45 +464,6 @@ automember_load_config()
         automember_parse_config_entry(entries[i], 1);
     }
 
-    /* If an alternate config area is configured, find
-     * the config entries that are beneath it. */
-    if (automember_get_config_area()) {
-        /* Clean up the previous search results
-         * and clear out the pblock for reuse. */
-        slapi_free_search_results_internal(search_pb);
-        slapi_pblock_init(search_pb);
-
-        slapi_log_error(SLAPI_LOG_PLUGIN, AUTOMEMBER_PLUGIN_SUBSYSTEM,
-                        "automember_load_config: Looking for config entries "
-                        "beneath \"%s\".\n", slapi_sdn_get_ndn(automember_get_config_area()));
-
-        slapi_search_internal_set_pb(search_pb, slapi_sdn_get_ndn(automember_get_config_area()),
-                                     LDAP_SCOPE_SUBTREE, "objectclass=*",
-                                     NULL, 0, NULL, NULL, automember_get_plugin_id(), 0);
-        slapi_search_internal_pb(search_pb);
-        slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
-
-        if ((LDAP_SUCCESS != result) && (LDAP_NO_SUCH_OBJECT != result)) {
-            status = -1;
-            goto cleanup;
-        }
-
-        slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES,
-                         &entries);
-
-        /* Loop through all of the entries we found and parse them. */
-        for (i = 0; entries && (entries[i] != NULL); i++) {
-            slapi_log_error(SLAPI_LOG_PLUGIN, AUTOMEMBER_PLUGIN_SUBSYSTEM,
-                            "automember_load_config: parsing config entry "
-                            "\"%s\".\n", slapi_entry_get_dn(entries[i]));
-
-            /* We don't care about the status here because we may have
-             * some invalid config entries, but we just want to continue
-             * looking for valid ones. */
-            automember_parse_config_entry(entries[i], 1);
-        }
-    }
-
   cleanup:
     slapi_free_search_results_internal(search_pb);
     slapi_pblock_destroy(search_pb);
@@ -924,14 +913,20 @@ automember_dn_is_config(char *dn)
 
     sdn = slapi_sdn_new_dn_byref(dn);
 
-    /* Return 1 if the passed in dn is a child of the main
-     * plugin config entry, or if it is a child of the
-     * container defined as a config area. */
-    if ((slapi_sdn_issuffix(sdn, automember_get_plugin_sdn()) &&
-        slapi_sdn_compare(sdn, automember_get_plugin_sdn()))||
-        (automember_get_config_area() && slapi_sdn_issuffix(sdn,
-        automember_get_config_area()))) {
-        ret = 1;
+    /* If an alternate config area is configured, treat it's child
+     * entries as config entries.  If the alternate config area is
+     * not configured, treat children of the top-level plug-in
+     * config entry as our config entries. */
+    if (automember_get_config_area()) {
+        if (slapi_sdn_issuffix(sdn, automember_get_config_area()) &&
+            slapi_sdn_compare(sdn, automember_get_config_area())) {
+            ret = 1;
+        }
+    } else {
+        if (slapi_sdn_issuffix(sdn, automember_get_plugin_sdn()) &&
+            slapi_sdn_compare(sdn, automember_get_plugin_sdn())) {
+            ret = 1;
+        }
     }
 
 bail:




More information about the 389-commits mailing list