]> the.earth.li Git - onak.git/commitdiff
Fix deletion of keys with PostgreSQL backend
authorJonathan McDowell <noodles@earth.li>
Sun, 3 Jul 2022 10:16:14 +0000 (11:16 +0100)
committerJonathan McDowell <noodles@earth.li>
Sun, 3 Jul 2022 10:16:14 +0000 (11:16 +0100)
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

index 52d27fc538220b1c3c4661d5e952430b2e690067..1b58c1a5f27c71f1788c1e7783e70aa60df7b77a 100644 (file)
@@ -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) {