]> the.earth.li Git - onak.git/commitdiff
Add KEYD_CMD_UPDATE to keyd protocol
authorJonathan McDowell <noodles@earth.li>
Mon, 4 Jul 2016 08:07:02 +0000 (10:07 +0200)
committerJonathan McDowell <noodles@earth.li>
Mon, 4 Jul 2016 08:07:02 +0000 (10:07 +0200)
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
keyd.h
keydb_keyd.c
keydctl.c

diff --git a/keyd.c b/keyd.c
index aa58b8a734edd3dc5b83e5e9cbdbb18dd68c821f..c1c2d5080d280d30b3e6f9f83db7a533e5f58d2a 100644 (file)
--- 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 b33cab90984685663afe4975f8cbfb6029fc3ae5..fae46422426c55fb043200547f19684435b8d7b5 100644 (file)
--- 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
index 6836e9a2db02cbbe28d22b1a123a2103ee56da05..7d3754a837693d26e610b3e2150471c9ce06aeae 100644 (file)
@@ -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);
index 25d5f45964fc3b882a5590b60e4cb7e0229441d2..a3176ad8f903358d223c8e1c7273a4b483264b9b 100644 (file)
--- 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",