krb5_error_code hdb_sqlite_create(krb5_context context, HDB **db, const char *filename) { krb5_error_code ret; hdb_sqlite_db *hsdb; *db = calloc(1, sizeof (**db)); if (*db == NULL) return krb5_enomem(context); (*db)->hdb_name = strdup(filename); if ((*db)->hdb_name == NULL) { free(*db); *db = NULL; return krb5_enomem(context); } hsdb = (hdb_sqlite_db*) calloc(1, sizeof (*hsdb)); if (hsdb == NULL) { free((*db)->hdb_name); free(*db); *db = NULL; return krb5_enomem(context); } (*db)->hdb_db = hsdb; /* XXX make_database should make sure everything else is freed on error */ ret = hdb_sqlite_make_database(context, *db, filename); if (ret) { free((*db)->hdb_db); free(*db); return ret; } (*db)->hdb_master_key_set = 0; (*db)->hdb_openp = 0; (*db)->hdb_capability_flags = 0; (*db)->hdb_open = hdb_sqlite_open; (*db)->hdb_close = hdb_sqlite_close; (*db)->hdb_lock = hdb_sqlite_lock; (*db)->hdb_unlock = hdb_sqlite_unlock; (*db)->hdb_firstkey = hdb_sqlite_firstkey; (*db)->hdb_nextkey = hdb_sqlite_nextkey; (*db)->hdb_fetch_kvno = hdb_sqlite_fetch_kvno; (*db)->hdb_store = hdb_sqlite_store; (*db)->hdb_remove = hdb_sqlite_remove; (*db)->hdb_destroy = hdb_sqlite_destroy; (*db)->hdb_rename = hdb_sqlite_rename; (*db)->hdb__get = NULL; (*db)->hdb__put = NULL; (*db)->hdb__del = NULL; return 0; }
krb5_error_code hdb_sqlite_create(krb5_context context, HDB **db, const char *argument) { krb5_error_code ret; hdb_sqlite_db *hsdb; *db = calloc(1, sizeof (**db)); if (*db == NULL) { krb5_set_error_string(context, "calloc: out of memory"); return ENOMEM; } hsdb = (hdb_sqlite_db*) calloc(1, sizeof (*hsdb)); if (hsdb == NULL) { free(*db); *db = NULL; krb5_set_error_string(context, "malloc: out of memory"); return ENOMEM; } (*db)->hdb_db = hsdb; /* XXX make_database should make sure everything else is freed on error */ ret = hdb_sqlite_make_database(context, *db, argument); if (ret) { free((*db)->hdb_db); free(*db); return ret; } (*db)->hdb_master_key_set = 0; (*db)->hdb_openp = 0; (*db)->hdb_capability_flags = 0; (*db)->hdb_open = hdb_sqlite_open; (*db)->hdb_close = hdb_sqlite_close; (*db)->hdb_lock = hdb_sqlite_lock; (*db)->hdb_unlock = hdb_sqlite_unlock; (*db)->hdb_firstkey = hdb_sqlite_firstkey; (*db)->hdb_nextkey = hdb_sqlite_nextkey; (*db)->hdb_fetch = hdb_sqlite_fetch; (*db)->hdb_store = hdb_sqlite_store; (*db)->hdb_remove = hdb_sqlite_remove; (*db)->hdb_destroy = hdb_sqlite_destroy; (*db)->hdb_rename = hdb_sqlite_rename; (*db)->hdb__get = NULL; (*db)->hdb__put = NULL; (*db)->hdb__del = NULL; return 0; }
/* * Renames the database file. */ static krb5_error_code hdb_sqlite_rename(krb5_context context, HDB *db, const char *new_name) { hdb_sqlite_db *hsdb = (hdb_sqlite_db *) db->hdb_db; int ret; krb5_warnx(context, "hdb_sqlite_rename"); if (strncasecmp(new_name, "sqlite:", 7) == 0) new_name += 7; hdb_sqlite_close_database(context, db); ret = rename(hsdb->db_file, new_name); free(hsdb->db_file); hdb_sqlite_make_database(context, db, new_name); return ret; }
/* * Renames the database file. */ static krb5_error_code hdb_sqlite_rename(krb5_context context, HDB *db, const char *new_name) { krb5_error_code ret, ret2; hdb_sqlite_db *hsdb = (hdb_sqlite_db *) db->hdb_db; krb5_warnx(context, "hdb_sqlite_rename"); if (strncasecmp(new_name, "sqlite:", 7) == 0) new_name += 7; ret = hdb_sqlite_close_database(context, db); if (rename(hsdb->db_file, new_name) == -1) return errno; free(hsdb->db_file); ret2 = hdb_sqlite_make_database(context, db, new_name); return ret ? ret : ret2; }