/**************************************************************************** Set a profiling level. ****************************************************************************/ void set_profile_level(int level, struct server_id src) { SMB_ASSERT(smbprofile_state.internal.db != NULL); switch (level) { case 0: /* turn off profiling */ smbprofile_state.config.do_count = false; smbprofile_state.config.do_times = false; DEBUG(1,("INFO: Profiling turned OFF from pid %d\n", (int)procid_to_pid(&src))); break; case 1: /* turn on counter profiling only */ smbprofile_state.config.do_count = true; smbprofile_state.config.do_times = false; DEBUG(1,("INFO: Profiling counts turned ON from pid %d\n", (int)procid_to_pid(&src))); break; case 2: /* turn on complete profiling */ smbprofile_state.config.do_count = true; smbprofile_state.config.do_times = true; DEBUG(1,("INFO: Full profiling turned ON from pid %d\n", (int)procid_to_pid(&src))); break; case 3: /* reset profile values */ ZERO_STRUCT(profile_p->values); tdb_wipe_all(smbprofile_state.internal.db->tdb); DEBUG(1,("INFO: Profiling values cleared from pid %d\n", (int)procid_to_pid(&src))); break; } }
static PyObject *obj_clear(PyTdbObject *self) { int ret; PyErr_TDB_RAISE_IF_CLOSED(self); ret = tdb_wipe_all(self->ctx); PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); Py_RETURN_NONE; }
/* load a msg file into the tdb */ static bool load_msg(const char *msg_file) { char **lines; int num_lines, i; char *msgid, *msgstr; TDB_DATA data; lines = file_lines_load(msg_file, &num_lines, 0, NULL); if (!lines) { return False; } if (tdb_lockall(tdb) != 0) { TALLOC_FREE(lines); return False; } /* wipe the db */ tdb_wipe_all(tdb); msgid = NULL; for (i=0;i<num_lines;i++) { if (strncmp(lines[i], "msgid \"", 7) == 0) { msgid = lines[i] + 7; } if (msgid && strncmp(lines[i], "msgstr \"", 8) == 0) { msgstr = lines[i] + 8; trim_char(msgid, '\0', '\"'); trim_char(msgstr, '\0', '\"'); if (*msgstr == 0) { msgstr = msgid; } all_string_sub(msgid, "\\n", "\n", 0); all_string_sub(msgstr, "\\n", "\n", 0); data = string_term_tdb_data(msgstr); tdb_store_bystring(tdb, msgid, data, 0); msgid = NULL; } } TALLOC_FREE(lines); tdb_unlockall(tdb); return True; }
/* wipe a database - only possible when in a frozen transaction */ int32_t ctdb_control_wipe_database(struct ctdb_context *ctdb, TDB_DATA indata) { struct ctdb_transdb w = *(struct ctdb_transdb *)indata.dptr; struct ctdb_db_context *ctdb_db; ctdb_db = find_ctdb_db(ctdb, w.db_id); if (!ctdb_db) { DEBUG(DEBUG_ERR,(__location__ " Unknown db 0x%x\n", w.db_id)); return -1; } if (ctdb_db->freeze_mode != CTDB_FREEZE_FROZEN) { DEBUG(DEBUG_ERR,(__location__ " Failed transaction_start while not frozen\n")); return -1; } if (!ctdb_db->freeze_transaction_started) { DEBUG(DEBUG_ERR,(__location__ " transaction not started\n")); return -1; } if (w.tid != ctdb_db->freeze_transaction_id) { DEBUG(DEBUG_ERR,(__location__ " incorrect transaction id 0x%x in commit\n", w.tid)); return -1; } if (tdb_wipe_all(ctdb_db->ltdb->tdb) != 0) { DEBUG(DEBUG_ERR,(__location__ " Failed to wipe database for db '%s'\n", ctdb_db->db_name)); return -1; } if (!ctdb_db->persistent) { talloc_free(ctdb_db->delete_queue); ctdb_db->delete_queue = trbt_create(ctdb_db, 0); if (ctdb_db->delete_queue == NULL) { DEBUG(DEBUG_ERR, (__location__ " Failed to re-create " "the vacuum tree.\n")); return -1; } } return 0; }
enum TDB_ERROR tdb_repack(struct tdb_context *tdb) { struct tdb_context *tmp_db; struct traverse_state state; state.error = tdb_transaction_start(tdb); if (state.error != TDB_SUCCESS) { return state.error; } tmp_db = tdb_open("tmpdb", TDB_INTERNAL, O_RDWR|O_CREAT, 0, NULL); if (tmp_db == NULL) { state.error = tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR, __location__ " Failed to create tmp_db"); tdb_transaction_cancel(tdb); return tdb->last_error = state.error; } state.dest_db = tmp_db; if (tdb_traverse(tdb, repack_traverse, &state) < 0) { goto fail; } state.error = tdb_wipe_all(tdb); if (state.error != TDB_SUCCESS) { goto fail; } state.dest_db = tdb; if (tdb_traverse(tmp_db, repack_traverse, &state) < 0) { goto fail; } tdb_close(tmp_db); return tdb_transaction_commit(tdb); fail: tdb_transaction_cancel(tdb); tdb_close(tmp_db); return state.error; }
static int db_tdb_wipe(struct db_context *db) { struct db_tdb_ctx *ctx = talloc_get_type_abort( db->private_data, struct db_tdb_ctx); return tdb_wipe_all(ctx->wtdb->tdb); }
/**************************************************************************** Open the group mapping tdb. ****************************************************************************/ static bool init_group_mapping(void) { const char *ldb_path; if (db != NULL) { return true; } db = db_open(NULL, state_path("group_mapping.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600, DBWRAP_LOCK_ORDER_1); if (db == NULL) { DEBUG(0, ("Failed to open group mapping database: %s\n", strerror(errno))); return false; } ldb_path = state_path("group_mapping.ldb"); if (file_exist(ldb_path) && !mapping_switch(ldb_path)) { unlink(state_path("group_mapping.tdb")); return false; } else { /* handle upgrade from old versions of the database */ #if 0 /* -- Needs conversion to dbwrap -- */ const char *vstring = "INFO/version"; int32 vers_id; GROUP_MAP *map_table = NULL; size_t num_entries = 0; /* handle a Samba upgrade */ tdb_lock_bystring(tdb, vstring); /* Cope with byte-reversed older versions of the db. */ vers_id = tdb_fetch_int32(tdb, vstring); if ((vers_id == DATABASE_VERSION_V1) || (IREV(vers_id) == DATABASE_VERSION_V1)) { /* * Written on a bigendian machine with old fetch_int * code. Save as le. */ tdb_store_int32(tdb, vstring, DATABASE_VERSION_V2); vers_id = DATABASE_VERSION_V2; } /* if its an unknown version we remove everthing in the db */ if (vers_id != DATABASE_VERSION_V2) { tdb_wipe_all(tdb); tdb_store_int32(tdb, vstring, DATABASE_VERSION_V2); } tdb_unlock_bystring(tdb, vstring); /* cleanup any map entries with a gid == -1 */ if ( enum_group_mapping( NULL, SID_NAME_UNKNOWN, &map_table, &num_entries, False ) ) { int i; for ( i=0; i<num_entries; i++ ) { if ( map_table[i].gid == -1 ) { group_map_remove( &map_table[i].sid ); } } SAFE_FREE( map_table ); } #endif } return true; }
/**************************************************************************** Open the group mapping tdb. ****************************************************************************/ static bool init_group_mapping(void) { if (db != NULL) { return true; } db = db_open_trans(NULL, state_path("group_mapping.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600); if (db == NULL) { DEBUG(0, ("Failed to open group mapping database: %s\n", strerror(errno))); return false; } #if 0 /* * This code was designed to handle a group mapping version * upgrade. mapping_tdb is not active by default anymore, so ignore * this here. */ { const char *vstring = "INFO/version"; int32 vers_id; GROUP_MAP *map_table = NULL; size_t num_entries = 0; /* handle a Samba upgrade */ tdb_lock_bystring(tdb, vstring); /* Cope with byte-reversed older versions of the db. */ vers_id = tdb_fetch_int32(tdb, vstring); if ((vers_id == DATABASE_VERSION_V1) || (IREV(vers_id) == DATABASE_VERSION_V1)) { /* * Written on a bigendian machine with old fetch_int * code. Save as le. */ tdb_store_int32(tdb, vstring, DATABASE_VERSION_V2); vers_id = DATABASE_VERSION_V2; } /* if its an unknown version we remove everthing in the db */ if (vers_id != DATABASE_VERSION_V2) { tdb_wipe_all(tdb); tdb_store_int32(tdb, vstring, DATABASE_VERSION_V2); } tdb_unlock_bystring(tdb, vstring); /* cleanup any map entries with a gid == -1 */ if ( enum_group_mapping( NULL, SID_NAME_UNKNOWN, &map_table, &num_entries, False ) ) { int i; for ( i=0; i<num_entries; i++ ) { if ( map_table[i].gid == -1 ) { group_map_remove( &map_table[i].sid ); } } SAFE_FREE( map_table ); } } #endif return true; }
int main(int argc, char *argv[]) { unsigned int i, extra_msgs; struct tdb_context *tdb; struct tdb_data key = tdb_mkdata("key", 3); struct tdb_data data = tdb_mkdata("data", 4); int flags[] = { TDB_DEFAULT, TDB_NOMMAP, TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT, TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1, TDB_CONVERT|TDB_VERSION1, TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 }; plan_tests(sizeof(flags) / sizeof(flags[0]) * 48); for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) { /* RW -> R0 */ tdb = tdb_open("run-92-get-set-readonly.tdb", flags[i], O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr); ok1(tdb); ok1(!(tdb_get_flags(tdb) & TDB_RDONLY)); /* TDB1 complains multiple times. */ if (flags[i] & TDB_VERSION1) { extra_msgs = 1; } else { extra_msgs = 0; } ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS); tdb_add_flag(tdb, TDB_RDONLY); ok1(tdb_get_flags(tdb) & TDB_RDONLY); /* Can't store, append, delete. */ ok1(tdb_store(tdb, key, data, TDB_MODIFY) == TDB_ERR_RDONLY); ok1(tap_log_messages == 1); ok1(tdb_append(tdb, key, data) == TDB_ERR_RDONLY); tap_log_messages -= extra_msgs; ok1(tap_log_messages == 2); ok1(tdb_delete(tdb, key) == TDB_ERR_RDONLY); tap_log_messages -= extra_msgs; ok1(tap_log_messages == 3); /* Can't start a transaction, or any write lock. */ ok1(tdb_transaction_start(tdb) == TDB_ERR_RDONLY); ok1(tap_log_messages == 4); ok1(tdb_chainlock(tdb, key) == TDB_ERR_RDONLY); tap_log_messages -= extra_msgs; ok1(tap_log_messages == 5); ok1(tdb_lockall(tdb) == TDB_ERR_RDONLY); ok1(tap_log_messages == 6); ok1(tdb_wipe_all(tdb) == TDB_ERR_RDONLY); ok1(tap_log_messages == 7); /* Back to RW. */ tdb_remove_flag(tdb, TDB_RDONLY); ok1(!(tdb_get_flags(tdb) & TDB_RDONLY)); ok1(tdb_store(tdb, key, data, TDB_MODIFY) == TDB_SUCCESS); ok1(tdb_append(tdb, key, data) == TDB_SUCCESS); ok1(tdb_delete(tdb, key) == TDB_SUCCESS); ok1(tdb_transaction_start(tdb) == TDB_SUCCESS); ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS); ok1(tdb_transaction_commit(tdb) == TDB_SUCCESS); ok1(tdb_chainlock(tdb, key) == TDB_SUCCESS); tdb_chainunlock(tdb, key); ok1(tdb_lockall(tdb) == TDB_SUCCESS); tdb_unlockall(tdb); ok1(tdb_wipe_all(tdb) == TDB_SUCCESS); ok1(tap_log_messages == 7); tdb_close(tdb); /* R0 -> RW */ tdb = tdb_open("run-92-get-set-readonly.tdb", flags[i], O_RDONLY, 0600, &tap_log_attr); ok1(tdb); ok1(tdb_get_flags(tdb) & TDB_RDONLY); /* Can't store, append, delete. */ ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_ERR_RDONLY); ok1(tap_log_messages == 8); ok1(tdb_append(tdb, key, data) == TDB_ERR_RDONLY); tap_log_messages -= extra_msgs; ok1(tap_log_messages == 9); ok1(tdb_delete(tdb, key) == TDB_ERR_RDONLY); tap_log_messages -= extra_msgs; ok1(tap_log_messages == 10); /* Can't start a transaction, or any write lock. */ ok1(tdb_transaction_start(tdb) == TDB_ERR_RDONLY); ok1(tap_log_messages == 11); ok1(tdb_chainlock(tdb, key) == TDB_ERR_RDONLY); tap_log_messages -= extra_msgs; ok1(tap_log_messages == 12); ok1(tdb_lockall(tdb) == TDB_ERR_RDONLY); ok1(tap_log_messages == 13); ok1(tdb_wipe_all(tdb) == TDB_ERR_RDONLY); ok1(tap_log_messages == 14); /* Can't remove TDB_RDONLY since we opened with O_RDONLY */ tdb_remove_flag(tdb, TDB_RDONLY); ok1(tap_log_messages == 15); ok1(tdb_get_flags(tdb) & TDB_RDONLY); tdb_close(tdb); ok1(tap_log_messages == 15); tap_log_messages = 0; } return exit_status(); }
int pa_database_clear(pa_database *db) { pa_assert(db); return tdb_wipe_all(MAKE_TDB_CONTEXT(db)) != 0 ? -1 : 0; }