From 0e9ae75e964c98041e5d8279efacd96282c703ac Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Mon, 4 Jul 2016 10:07:02 +0200 Subject: [PATCH] Add KEYD_CMD_UPDATE to keyd protocol When a key was being updated over keyd it would do a delete and then a store, which ended up being outside a transaction. Add an update command so that the backend can do the update fully itself. --- keyd.c | 4 +++- keyd.h | 3 ++- keydb_keyd.c | 5 +++-- keydctl.c | 2 ++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/keyd.c b/keyd.c index aa58b8a..c1c2d50 100644 --- a/keyd.c +++ b/keyd.c @@ -397,6 +397,7 @@ static int sock_do(struct onak_dbctx *dbctx, int fd) } break; case KEYD_CMD_STORE: + case KEYD_CMD_UPDATE: if (!keyd_write_reply(fd, KEYD_REPLY_OK)) { ret = 1; } @@ -427,7 +428,8 @@ static int sock_do(struct onak_dbctx *dbctx, int fd) &packets, 0); parse_keys(packets, &key); - dbctx->store_key(dbctx, key, false, false); + dbctx->store_key(dbctx, key, false, + (cmd == KEYD_CMD_UPDATE)); free_packet_list(packets); packets = NULL; free_publickey(key); diff --git a/keyd.h b/keyd.h index b33cab9..fae4642 100644 --- a/keyd.h +++ b/keyd.h @@ -45,6 +45,7 @@ enum keyd_ops { KEYD_CMD_STATS, KEYD_CMD_GET_SKSHASH, KEYD_CMD_GET_FP, + KEYD_CMD_UPDATE, KEYD_CMD_LAST /* Placeholder */ }; @@ -59,7 +60,7 @@ enum keyd_reply { /** * @brief Version of the keyd protocol currently supported */ -static const uint32_t keyd_version = 4; +static const uint32_t keyd_version = 5; /** * @brief Response structure for the @a KEYD_CMD_STATS response diff --git a/keydb_keyd.c b/keydb_keyd.c index 6836e9a..7d3754a 100644 --- a/keydb_keyd.c +++ b/keydb_keyd.c @@ -227,6 +227,7 @@ static int keyd_store_key(struct onak_dbctx *dbctx, struct openpgp_packet_list *list_end = NULL; struct openpgp_publickey *next = NULL; uint64_t keyid; + enum keyd_ops cmd = KEYD_CMD_STORE; if (get_keyid(publickey, &keyid) != ONAK_E_OK) { logthing(LOGTHING_ERROR, "Couldn't find key ID for key."); @@ -234,10 +235,10 @@ static int keyd_store_key(struct onak_dbctx *dbctx, } if (update) { - keyd_delete_key(dbctx, keyid, false); + cmd = KEYD_CMD_UPDATE; } - if (keyd_send_cmd(keyd_fd, KEYD_CMD_STORE)) { + if (keyd_send_cmd(keyd_fd, cmd)) { keybuf.offset = 0; keybuf.size = 8192; keybuf.buffer = malloc(keybuf.size); diff --git a/keydctl.c b/keydctl.c index 25d5f45..a3176ad 100644 --- a/keydctl.c +++ b/keydctl.c @@ -181,6 +181,8 @@ static void keyd_status(void) stats.command_stats[KEYD_CMD_STORE]); printf(" Delete key: %d\n", stats.command_stats[KEYD_CMD_DELETE]); + printf(" Update key: %d\n", + stats.command_stats[KEYD_CMD_UPDATE]); printf(" Search key: %d\n", stats.command_stats[KEYD_CMD_GET_TEXT]); printf(" Get full keyid: %d\n", -- 2.39.5