krb5_error_code krb5_db2_destroy(krb5_context context, char *conf_section, char **db_args) { krb5_error_code status; krb5_db2_context *dbc; char *dbname = NULL, *lockname = NULL, *polname = NULL, *plockname = NULL; if (inited(context)) { status = krb5_db2_fini(context); if (status != 0) return status; } krb5_clear_error_message(context); status = configure_context(context, conf_section, db_args); if (status != 0) return status; status = check_openable(context); if (status != 0) return status; dbc = context->dal_handle->db_context; status = ctx_allfiles(dbc, &dbname, &lockname, &polname, &plockname); if (status) goto cleanup; status = destroy_file(dbname); if (status) goto cleanup; status = unlink(lockname); if (status) goto cleanup; status = osa_adb_destroy_db(polname, plockname, OSA_ADB_POLICY_DB_MAGIC); if (status) return status; status = krb5_db2_fini(context); cleanup: free(dbname); free(lockname); free(polname); free(plockname); return status; }
/* * Since the destroy operation happens outside the init/fini bracket, we * have some tomfoolery to undergo here. If we're operating under no * database context, then we initialize with the default. If the caller * wishes a different context (e.g. different dispatch table), it's their * responsibility to call kdb5_db_set_dbops() before this call. That will * set up the right dispatch table values (e.g. name extensions). * * Not quite valid due to ripping out of dbops... */ static krb5_error_code destroy_db(krb5_context context, char *dbname) { krb5_error_code retval1, retval2; krb5_boolean tmpcontext; char policy_db_name[1024], policy_lock_name[1024]; tmpcontext = 0; if (!context->dal_handle->db_context) { tmpcontext = 1; if ((retval1 = k5db2_init_context(context))) return (retval1); } retval1 = retval2 = 0; retval1 = destroy_file_suffix(dbname, ""); retval2 = destroy_file_suffix(dbname, KDB2_LOCK_EXT); if (tmpcontext) { k5db2_clear_context(context->dal_handle->db_context); free(context->dal_handle->db_context); context->dal_handle->db_context = NULL; } if (retval1 || retval2) return (retval1 ? retval1 : retval2); snprintf(policy_db_name, sizeof(policy_db_name), "%s.kadm5", dbname); snprintf(policy_lock_name, sizeof(policy_lock_name), "%s.lock", policy_db_name); retval1 = osa_adb_destroy_db(policy_db_name, policy_lock_name, OSA_ADB_POLICY_DB_MAGIC); return retval1; }