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; }
void lily_value_destroy(lily_value *v) { int class_id = v->class_id; if (class_id == LILY_LIST_ID || class_id == LILY_TUPLE_ID) destroy_list(v); else if (v->flags & (VAL_IS_INSTANCE | VAL_IS_ENUM)) destroy_instance(v); else if (class_id == LILY_STRING_ID || class_id == LILY_BYTESTRING_ID) destroy_string(v); else if (class_id == LILY_FUNCTION_ID) destroy_function(v); else if (class_id == LILY_HASH_ID) lily_destroy_hash(v); else if (class_id == LILY_DYNAMIC_ID) destroy_dynamic(v); else if (class_id == LILY_FILE_ID) destroy_file(v); else if (v->flags & VAL_IS_FOREIGN) v->value.foreign->destroy_func(v->value.generic); }
int main(int argc, char **argv) { optparse(argc, argv); /* set g_conf options */ if (isatty(STDIN_FILENO)) watch_user_input(); update_status(FCOPY_START); init_file(g_conf.infile_name, g_conf.outfile_name); config(); /* configure g_conf options */ init_hmap(g_conf.hmap_size); update_status(TAGDUP_START); tag_duplicates(); destroy_hmap(); update_status(FCLEAN_START); remove_duplicates(); destroy_file(); return (0); }
/* Initialize dbc by locking and creating the DB. If the DB already exists, * clear it out if dbc->tempdb is set; otherwise return EEXIST. */ static krb5_error_code ctx_create_db(krb5_context context, krb5_db2_context *dbc) { krb5_error_code retval = 0; char *dbname = NULL, *polname = NULL, *plockname = NULL; retval = ctx_allfiles(dbc, &dbname, &dbc->db_lf_name, &polname, &plockname); if (retval) return retval; dbc->db_lf_file = open(dbc->db_lf_name, O_CREAT | O_RDWR | O_TRUNC, 0600); if (dbc->db_lf_file < 0) { retval = errno; goto cleanup; } retval = krb5_lock_file(context, dbc->db_lf_file, KRB5_LOCKMODE_EXCLUSIVE | KRB5_LOCKMODE_DONTBLOCK); if (retval != 0) goto cleanup; set_cloexec_fd(dbc->db_lf_file); dbc->db_lock_mode = KRB5_LOCKMODE_EXCLUSIVE; dbc->db_locks_held = 1; if (dbc->tempdb) { /* Temporary DBs are locked for their whole lifetime. Since we have * the lock, any remnant files can be safely destroyed. */ (void) destroy_file(dbname); (void) unlink(polname); (void) unlink(plockname); } dbc->db = open_db(dbc, O_RDWR | O_CREAT | O_EXCL, 0600); if (dbc->db == NULL) { retval = errno; goto cleanup; } /* Create the policy database, initialize a handle to it, and lock it. */ retval = osa_adb_create_db(polname, plockname, OSA_ADB_POLICY_DB_MAGIC); if (retval) goto cleanup; retval = osa_adb_init_db(&dbc->policy_db, polname, plockname, OSA_ADB_POLICY_DB_MAGIC); if (retval) goto cleanup; retval = osa_adb_get_lock(dbc->policy_db, KRB5_DB_LOCKMODE_EXCLUSIVE); if (retval) goto cleanup; dbc->db_inited = 1; cleanup: if (retval) { if (dbc->db != NULL) dbc->db->close(dbc->db); if (dbc->db_locks_held > 0) { (void) krb5_lock_file(context, dbc->db_lf_file, KRB5_LOCKMODE_UNLOCK); } if (dbc->db_lf_file >= 0) close(dbc->db_lf_file); ctx_clear(dbc); } free(dbname); free(polname); free(plockname); return retval; }