Commit 16b06069 authored by Libor Peltan's avatar Libor Peltan

zone purge: add kasp DB eliminating of the zone

parent 5105b56c
......@@ -1017,6 +1017,11 @@ static int zone_purge(zone_t *zone, ctl_args_t *args)
(void)scrape_journal(zone->journal);
}
// Purge KASP DB
if (kasp_db_open(*kaspdb()) == KNOT_EOK) {
(void)kasp_db_delete_all(*kaspdb(), zone->name);
}
return KNOT_EOK;
}
......
......@@ -424,6 +424,47 @@ int kasp_db_delete_key(kasp_db_t *db, const knot_dname_t *zone_name, const char
return ret;
}
int kasp_db_delete_all(kasp_db_t *db, const knot_dname_t *zone_name)
{
list_t allkeys;
init_list(&allkeys);
int r = kasp_db_list_keys(db, zone_name, &allkeys);
if (r != KNOT_EOK) {
return r;
}
with_txn(KEYS_RW, NULL);
ptrnode_t *n;
WALK_LIST(n, allkeys) {
key_params_t *parm = n->d;
knot_db_val_t key = make_key(KASPDBKEY_PARAMS, zone_name, parm->id);
ret = db_api->del(txn, &key);
free_key(&key);
free(parm->id);
free(parm->public_key.data);
memset(parm, 0, sizeof(*parm));
if (ret != KNOT_EOK) {
break;
}
}
ptrlist_deep_free(&allkeys);
if (ret == KNOT_EOK) {
knot_db_val_t key = make_key(KASPDBKEY_NSEC3SALT, zone_name, NULL);
ret = db_api->del(txn, &key);
free_key(&key);
if (ret == KNOT_EOK) {
key = make_key(KASPDBKEY_NSEC3TIME, zone_name, NULL);
ret = db_api->del(txn, &key);
free_key(&key);
}
}
with_txn_end(NULL, NULL);
return ret;
}
int kasp_db_add_key(kasp_db_t *db, const knot_dname_t *zone_name, const key_params_t *params)
{
if (db == NULL || db->keys_db == NULL || zone_name == NULL || params == NULL) {
......
......@@ -91,6 +91,15 @@ int kasp_db_list_keys(kasp_db_t *db, const knot_dname_t *zone_name, list_t *dst)
*/
int kasp_db_delete_key(kasp_db_t *db, const knot_dname_t *zone_name, const char *key_id, bool *still_used);
/*!
* \brief Remove all zone's keys from DB, including nsec3param
* \param db KASP db
* \param zone_name zoen to be removed
*
* \return KNOT_E*
*/
int kasp_db_delete_all(kasp_db_t *db, const knot_dname_t *zone_name);
/*!
* \brief Add a key to the DB (possibly overwrite) and link it to a zone.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment