From 67f26da9c26e544b723ac73ac67383519c873e30 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Sun, 3 Jul 2022 11:16:14 +0100 Subject: [PATCH] Fix deletion of keys with PostgreSQL backend In pg_delete_key() we deleted the key from onak_keys as the first action, which would fail because the other tables had a reference to that object via a foreign key relation. The correct approach is to delete the key itself last, after the signature and UID tables have had their entries deleted. --- keydb/keydb_pg.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/keydb/keydb_pg.c b/keydb/keydb_pg.c index 52d27fc..1b58c1a 100644 --- a/keydb/keydb_pg.c +++ b/keydb/keydb_pg.c @@ -290,19 +290,19 @@ static int pg_delete_key(struct onak_dbctx *dbctx, PQclear(result); snprintf(statement, 1023, - "DELETE FROM onak_keys WHERE keyid = '%" PRIX64 "'", + "DELETE FROM onak_sigs WHERE signee = '%" PRIX64 "'", keyid); result = PQexec(dbconn, statement); PQclear(result); snprintf(statement, 1023, - "DELETE FROM onak_sigs WHERE signee = '%" PRIX64 "'", + "DELETE FROM onak_uids WHERE keyid = '%" PRIX64 "'", keyid); result = PQexec(dbconn, statement); PQclear(result); snprintf(statement, 1023, - "DELETE FROM onak_uids WHERE keyid = '%" PRIX64 "'", + "DELETE FROM onak_keys WHERE keyid = '%" PRIX64 "'", keyid); result = PQexec(dbconn, statement); } else if (PQresultStatus(result) != PGRES_TUPLES_OK) { -- 2.39.5