]> the.earth.li Git - onak.git/blobdiff - keydb_keyd.c
Add sanity check for PGP packet version
[onak.git] / keydb_keyd.c
index 33d2c21b4d15eac23e918073f2ca7399c037607e..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);
@@ -502,7 +503,7 @@ static void keyd_cleanupdb(struct onak_dbctx *dbctx)
  *     this file are called in order to allow the DB to be initialized ready
  *     for access.
  */
-struct onak_dbctx *keydb_keyd_init(bool readonly)
+struct onak_dbctx *keydb_keyd_init(struct onak_db_config *dbcfg, bool readonly)
 {
        struct sockaddr_un sock;
        uint32_t           cmd = KEYD_CMD_UNKNOWN;
@@ -515,6 +516,7 @@ struct onak_dbctx *keydb_keyd_init(bool readonly)
        if (dbctx == NULL) {
                return NULL;
        }
+       dbctx->config = dbcfg;
 
        keyd_fd = socket(PF_UNIX, SOCK_STREAM, 0);
        if (keyd_fd < 0) {