ldbm_config_directory_set(void *arg, void *value, char *errorbuf, int phase, int apply)
{
    struct ldbminfo *li = (struct ldbminfo *)arg;
    int retval = LDAP_SUCCESS;
    char *val = (char *)value;
    char tmpbuf[BUFSIZ];

    if (errorbuf) {
        errorbuf[0] = '\0';
    }

    if (!apply) {
        /* we should really do some error checking here. */
        return retval;
    }

    if (CONFIG_PHASE_RUNNING == phase) {
        slapi_ch_free((void **)&(li->li_new_directory));
        li->li_new_directory = rel2abspath(val); /* normalize the path;
                                                    strdup'ed in rel2abspath */
        slapi_log_err(SLAPI_LOG_ERR, "ldbm_config_directory_set",
                      "New db directory location will not take affect until the server is restarted\n");
    } else {
        slapi_ch_free((void **)&(li->li_new_directory));
        slapi_ch_free((void **)&(li->li_directory));
        if (NULL == val || '\0' == *val) {
            slapi_log_err(SLAPI_LOG_ERR,
                          "ldbm_config_directory_set", "db directory is not set; check %s in the db config: %s\n",
                          CONFIG_DIRECTORY, CONFIG_LDBM_DN);
            retval = LDAP_PARAM_ERROR;
        } else {
            if (0 == strcmp(val, "get default")) {
                /* We use this funky "get default" string for the caller to
                 * tell us that it has no idea what the db directory should
                 * be.  This code figures it out be reading "cn=config,cn=ldbm
                 * database,cn=plugins,cn=config" entry. */
                Slapi_PBlock *search_pb;
                Slapi_Entry **entries = NULL;
                Slapi_Attr *attr = NULL;
                Slapi_Value *v = NULL;
                const char *s = NULL;
                int res;

                search_pb = slapi_pblock_new();
                slapi_search_internal_set_pb(search_pb, CONFIG_LDBM_DN,
                                             LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, NULL, NULL,
                                             li->li_identity, 0);
                slapi_search_internal_pb(search_pb);
                slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_RESULT, &res);

                if (res != LDAP_SUCCESS) {
                    slapi_log_err(SLAPI_LOG_ERR,
                                  "ldbm_config_directory_set", "ldbm plugin unable to read %s\n",
                                  CONFIG_LDBM_DN);
                    retval = res;
                    goto done;
                }

                slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
                if (NULL == entries) {
                    slapi_log_err(SLAPI_LOG_ERR,
                                  "ldbm_config_directory_set", "ldbm plugin unable to read %s\n",
                                  CONFIG_LDBM_DN);
                    retval = LDAP_OPERATIONS_ERROR;
                    goto done;
                }

                res = slapi_entry_attr_find(entries[0], "nsslapd-directory", &attr);
                if (res != 0 || attr == NULL) {
                    slapi_log_err(SLAPI_LOG_ERR,
                                  "ldbm_config_directory_set", "ldbm plugin unable to read attribute nsslapd-directory from %s\n",
                                  CONFIG_LDBM_DN);
                    retval = LDAP_OPERATIONS_ERROR;
                    goto done;
                }

                if (slapi_attr_first_value(attr, &v) != 0 || (NULL == v) || (NULL == (s = slapi_value_get_string(v)))) {
                    slapi_log_err(SLAPI_LOG_ERR,
                                  "ldbm_config_directory_set", "ldbm plugin unable to read attribute nsslapd-directory from %s\n",
                                  CONFIG_LDBM_DN);
                    retval = LDAP_OPERATIONS_ERROR;
                    goto done;
                }
                slapi_pblock_destroy(search_pb);
                if (NULL == s || '\0' == *s || 0 == PL_strcmp(s, "(null)")) {
                    slapi_log_err(SLAPI_LOG_ERR,
                                  "ldbm_config_directory_set", "db directory is not set; check %s in the db config: %s\n",
                                  CONFIG_DIRECTORY, CONFIG_LDBM_DN);
                    retval = LDAP_PARAM_ERROR;
                    goto done;
                }
                PR_snprintf(tmpbuf, BUFSIZ, "%s", s);
                val = tmpbuf;
            }
            li->li_new_directory = rel2abspath(val); /* normalize the path;
                                                        strdup'ed in
                                                        rel2abspath */
            li->li_directory = rel2abspath(val);     /* ditto */
        }
    }
done:
    return retval;
}
ldbm_config_directory_set(void *arg, void *value, char *errorbuf, int phase, int apply)
{
    struct ldbminfo *li = (struct ldbminfo *)arg;
    int retval = LDAP_SUCCESS;
    char *val = (char *)value;
    char tmpbuf[BUFSIZ];

    if (errorbuf) {
        errorbuf[0] = '\0';
    }

    if (!apply) {
         
        return retval;
    }

    if (CONFIG_PHASE_RUNNING == phase) {
        slapi_ch_free((void **)&(li->li_new_directory));
        li->li_new_directory = rel2abspath(val);  
        slapi_log_err(SLAPI_LOG_ERR, "ldbm_config_directory_set",
                      "New db directory location will not take affect until the server is restarted\n");
    } else {
        slapi_ch_free((void **)&(li->li_new_directory));
        slapi_ch_free((void **)&(li->li_directory));
        if (NULL == val || '\0' == *val) {
            slapi_log_err(SLAPI_LOG_ERR,
                          "ldbm_config_directory_set", "db directory is not set; check %s in the db config: %s\n",
                          CONFIG_DIRECTORY, CONFIG_LDBM_DN);
            retval = LDAP_PARAM_ERROR;
        } else {
            if (0 == strcmp(val, "get default")) {
                 
                Slapi_PBlock *search_pb;
                Slapi_Entry **entries = NULL;
                Slapi_Attr *attr = NULL;
                Slapi_Value *v = NULL;
                const char *s = NULL;
                int res;

                search_pb = slapi_pblock_new();
                slapi_search_internal_set_pb(search_pb, CONFIG_LDBM_DN,
                                             LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, NULL, NULL,
                                             li->li_identity, 0);
                slapi_search_internal_pb(search_pb);
                slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_RESULT, &res);

                if (res != LDAP_SUCCESS) {
                    slapi_log_err(SLAPI_LOG_ERR,
                                  "ldbm_config_directory_set", "ldbm plugin unable to read %s\n",
                                  CONFIG_LDBM_DN);
                    retval = res;
                    goto done;
                }

                slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
                if (NULL == entries) {
                    slapi_log_err(SLAPI_LOG_ERR,
                                  "ldbm_config_directory_set", "ldbm plugin unable to read %s\n",
                                  CONFIG_LDBM_DN);
                    retval = LDAP_OPERATIONS_ERROR;
                    goto done;
                }

                res = slapi_entry_attr_find(entries[0], "nsslapd-directory", &attr);
                if (res != 0 || attr == NULL) {
                    slapi_log_err(SLAPI_LOG_ERR,
                                  "ldbm_config_directory_set", "ldbm plugin unable to read attribute nsslapd-directory from %s\n",
                                  CONFIG_LDBM_DN);
                    retval = LDAP_OPERATIONS_ERROR;
                    goto done;
                }

                if (slapi_attr_first_value(attr, &v) != 0 || (NULL == v) || (NULL == (s = slapi_value_get_string(v)))) {
                    slapi_log_err(SLAPI_LOG_ERR,
                                  "ldbm_config_directory_set", "ldbm plugin unable to read attribute nsslapd-directory from %s\n",
                                  CONFIG_LDBM_DN);
                    retval = LDAP_OPERATIONS_ERROR;
                    goto done;
                }
                slapi_pblock_destroy(search_pb);
                if (NULL == s || '\0' == *s || 0 == PL_strcmp(s, "(null)")) {
                    slapi_log_err(SLAPI_LOG_ERR,
                                  "ldbm_config_directory_set", "db directory is not set; check %s in the db config: %s\n",
                                  CONFIG_DIRECTORY, CONFIG_LDBM_DN);
                    retval = LDAP_PARAM_ERROR;
                    goto done;
                }
                PR_snprintf(tmpbuf, BUFSIZ, "%s", s);
                val = tmpbuf;
            }
            li->li_new_directory = rel2abspath(val);  
            li->li_directory = rel2abspath(val);      
        }
    }
done:
    return retval;
}