int ldbm_instance_add_instance_entry_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg) { char *instance_name; struct ldbm_instance *inst= NULL; struct ldbminfo *li= (struct ldbminfo *) arg; int rc = 0; parse_ldbm_instance_entry(entryBefore, &instance_name); /* Make sure we don't create two instances with the same name. */ inst = ldbm_instance_find_by_name(li, instance_name); if (inst != NULL) { LDAPDebug(LDAP_DEBUG_ANY, "WARNING: ldbm instance %s already exists\n", instance_name, 0, 0); if (returntext != NULL) PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "An ldbm instance with the name %s already exists\n", instance_name); if (returncode != NULL) *returncode = LDAP_UNWILLING_TO_PERFORM; slapi_ch_free((void **)&instance_name); return SLAPI_DSE_CALLBACK_ERROR; } if (pb == NULL) { /* called during startup -- do the rest now */ rc = ldbm_instance_generate(li, instance_name, NULL); if (!rc) { inst = ldbm_instance_find_by_name(li, instance_name); rc = ldbm_instance_create_default_user_indexes(inst); } } /* if called during a normal ADD operation, the postadd callback * will do the rest. */ slapi_ch_free((void **)&instance_name); return (rc == 0) ? SLAPI_DSE_CALLBACK_OK : SLAPI_DSE_CALLBACK_ERROR; }
int ldbm_instance_delete_instance_entry_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg) { char *instance_name; struct ldbminfo *li = (struct ldbminfo *)arg; struct ldbm_instance *inst = NULL; parse_ldbm_instance_entry(entryBefore, &instance_name); inst = ldbm_instance_find_by_name(li, instance_name); if (inst == NULL) { LDAPDebug(LDAP_DEBUG_ANY, "ldbm: instance '%s' does not exist!\n", instance_name, 0, 0); if (returntext) { PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "No ldbm instance exists with the name '%s'\n", instance_name); } if (returncode) { *returncode = LDAP_UNWILLING_TO_PERFORM; } slapi_ch_free((void **)&instance_name); return SLAPI_DSE_CALLBACK_ERROR; } /* check if some online task is happening */ if ((instance_set_busy(inst) != 0) || (slapi_counter_get_value(inst->inst_ref_count) > 0)) { LDAPDebug(LDAP_DEBUG_ANY, "ldbm: '%s' is in the middle of a task. " "Cancel the task or wait for it to finish, " "then try again.\n", instance_name, 0, 0); if (returntext) { PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "ldbm instance '%s' is in the middle of a " "task. Cancel the task or wait for it to finish, " "then try again.\n", instance_name); } if (returncode) { *returncode = LDAP_UNWILLING_TO_PERFORM; } slapi_ch_free((void **)&instance_name); return SLAPI_DSE_CALLBACK_ERROR; } /* okay, we're gonna delete this database instance. take it offline. */ LDAPDebug(LDAP_DEBUG_ANY, "ldbm: Bringing %s offline...\n", instance_name, 0, 0); slapi_mtn_be_stopping(inst->inst_be); dblayer_instance_close(inst->inst_be); slapi_ch_free((void **)&instance_name); return SLAPI_DSE_CALLBACK_OK; }
int ldbm_instance_postadd_instance_entry_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg) { backend *be = NULL; struct ldbm_instance *inst; char *instance_name; struct ldbminfo *li = (struct ldbminfo *)arg; int rval = 0; parse_ldbm_instance_entry(entryBefore, &instance_name); rval = ldbm_instance_generate(li, instance_name, &be); if (rval) { LDAPDebug(LDAP_DEBUG_ANY, "ldbm_instance_postadd_instance_entry_callback: " "ldbm_instance_generate (%s) failed (%d)\n", instance_name, rval, 0); } inst = ldbm_instance_find_by_name(li, instance_name); /* Add default indexes */ ldbm_instance_create_default_user_indexes(inst); /* Initialize and register callbacks for VLV indexes */ vlv_init(inst); /* this is an ACTUAL ADD being done while the server is running! * start up the appropriate backend... */ rval = ldbm_instance_start(be); if (0 != rval) { LDAPDebug(LDAP_DEBUG_ANY, "ldbm_instance_postadd_instance_entry_callback: " "ldbm_instnace_start (%s) failed (%d)\n", instance_name, rval, 0); } slapi_ch_free((void **)&instance_name); /* instance must be fully ready before we call this */ slapi_mtn_be_started(be); return SLAPI_DSE_CALLBACK_OK; }
int ldbm_instance_post_delete_instance_entry_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg) { char *instance_name; struct ldbminfo *li = (struct ldbminfo *)arg; struct ldbm_instance *inst = NULL; parse_ldbm_instance_entry(entryBefore, &instance_name); inst = ldbm_instance_find_by_name(li, instance_name); if (inst == NULL) { LDAPDebug(LDAP_DEBUG_ANY, "ldbm: instance '%s' does not exist! (2)\n", instance_name, 0, 0); if (returntext) { PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "No ldbm instance exists with the name '%s' (2)\n", instance_name); } if (returncode) { *returncode = LDAP_UNWILLING_TO_PERFORM; } slapi_ch_free((void **)&instance_name); return SLAPI_DSE_CALLBACK_ERROR; } LDAPDebug(LDAP_DEBUG_ANY, "ldbm: removing '%s'.\n", instance_name, 0, 0); cache_destroy_please(&inst->inst_cache, CACHE_TYPE_ENTRY); if (entryrdn_get_switch()) { /* subtree-rename: on */ cache_destroy_please(&inst->inst_dncache, CACHE_TYPE_DN); } { struct ldbminfo *li = (struct ldbminfo *) inst->inst_be->be_database->plg_private; dblayer_private *priv = (dblayer_private*) li->li_dblayer_private; struct dblayer_private_env *pEnv = priv->dblayer_env; if(pEnv) { PRDir *dirhandle = NULL; char inst_dir[MAXPATHLEN*2]; char *inst_dirp = NULL; if (inst->inst_dir_name == NULL){ dblayer_get_instance_data_dir(inst->inst_be); } inst_dirp = dblayer_get_full_inst_dir(li, inst, inst_dir, MAXPATHLEN*2); if (NULL != inst_dirp) { dirhandle = PR_OpenDir(inst_dirp); /* the db dir instance may have been removed already */ if (dirhandle) { PRDirEntry *direntry = NULL; char *dbp = NULL; char *p = NULL; while (NULL != (direntry = PR_ReadDir(dirhandle, PR_SKIP_DOT|PR_SKIP_DOT_DOT))) { int rc; if (!direntry->name) break; dbp = PR_smprintf("%s/%s", inst_dirp, direntry->name); if (NULL == dbp) { LDAPDebug (LDAP_DEBUG_ANY, "ldbm_instance_post_delete_instance_entry_callback:" " failed to generate db path: %s/%s\n", inst_dirp, direntry->name, 0); break; } p = strstr(dbp, LDBM_FILENAME_SUFFIX); if (NULL != p && strlen(p) == strlen(LDBM_FILENAME_SUFFIX)) { rc = dblayer_db_remove(pEnv, dbp, 0); } else { rc = PR_Delete(dbp); } PR_ASSERT(rc == 0); PR_smprintf_free(dbp); } PR_CloseDir(dirhandle); } /* * When a backend was removed, the db instance directory * was removed as well (See also bz463774). * In case DB_RECOVER_FATAL is set in the DB open after * the removal (e.g., in restore), the logs in the transaction * logs are replayed and compared with the contents of the DB * files. At that time, if the db instance directory does not * exist, libdb returns FATAL error. To prevent the problem, * we have to leave the empty directory. (bz597375) * * PR_RmDir(inst_dirp); */ } /* non-null dirhandle */ if (inst_dirp != inst_dir) { slapi_ch_free_string(&inst_dirp); } } /* non-null pEnv */ } ldbm_instance_unregister_callbacks(inst); slapi_be_free(&inst->inst_be); ldbm_instance_destroy(inst); slapi_ch_free((void **)&instance_name); return SLAPI_DSE_CALLBACK_OK; }
int ldbm_back_dbverify( Slapi_PBlock *pb ) { struct ldbminfo *li = NULL; Object *inst_obj = NULL; ldbm_instance *inst = NULL; int verbose = 0; int rval = 1; int rval_main = 0; char **instance_names = NULL; char *dbdir = NULL; slapi_log_err(SLAPI_LOG_TRACE, "ldbm_back_dbverify", "Verifying db files...\n"); slapi_pblock_get(pb, SLAPI_BACKEND_INSTANCE_NAME, &instance_names); slapi_pblock_get(pb, SLAPI_SEQ_TYPE, &verbose); slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &li); slapi_pblock_get(pb, SLAPI_DBVERIFY_DBDIR, &dbdir); ldbm_config_load_dse_info(li); ldbm_config_internal_set(li, CONFIG_DB_TRANSACTION_LOGGING, "off"); /* no write needed; choose EXPORT MODE */ if (0 != dblayer_start(li, DBLAYER_EXPORT_MODE)) { slapi_log_err(SLAPI_LOG_ERR, "ldbm_back_dbverify", "dbverify: Failed to init database\n"); return rval; } /* server is up */ slapi_log_err(SLAPI_LOG_TRACE, "ldbm_back_dbverify", "server is up\n"); if (instance_names) /* instance is specified */ { char **inp = NULL; for (inp = instance_names; inp && *inp; inp++) { inst = ldbm_instance_find_by_name(li, *inp); if (inst) { if (dbdir){ /* verifying backup */ slapi_ch_free_string(&inst->inst_parent_dir_name); inst->inst_parent_dir_name = slapi_ch_strdup(dbdir); } rval_main |= dbverify_ext(inst, verbose); } else { rval_main |= 1; /* no such instance */ } } } else /* all instances */ { for (inst_obj = objset_first_obj(li->li_instance_set); inst_obj; inst_obj = objset_next_obj(li->li_instance_set, inst_obj)) { inst = (ldbm_instance *)object_get_data(inst_obj); /* check if an import/restore is already ongoing... */ if (instance_set_busy(inst) != 0) { /* standalone, only. never happens */ slapi_log_err(SLAPI_LOG_WARNING, "ldbm_back_dbverify", "Backend '%s' is already in the middle of " "another task and cannot be disturbed.\n", inst->inst_name); continue; /* skip this instance and go to the next*/ } if (dbdir){ /* verifying backup */ slapi_ch_free_string(&inst->inst_parent_dir_name); inst->inst_parent_dir_name = slapi_ch_strdup(dbdir); } rval_main |= dbverify_ext(inst, verbose); } } /* close the database down again */ rval = dblayer_post_close(li, DBLAYER_EXPORT_MODE); if (0 != rval) { slapi_log_err(SLAPI_LOG_ERR, "ldbm_back_dbverify", "Failed to close database\n"); } return rval_main; }