X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/blobdiff_plain/59e5def499b3e9ae3587ebae2bef8794a1df34ea..0fac914c0876bf3cf78c12ea0b9b44880fbdffa4:/keydb_keyd.c diff --git a/keydb_keyd.c b/keydb_keyd.c index e5d46a3..2a9faaf 100644 --- a/keydb_keyd.c +++ b/keydb_keyd.c @@ -76,18 +76,25 @@ static void keyd_initdb(bool readonly) errno); } else { count = read(keyd_fd, &reply, sizeof(reply)); - if (count == sizeof(reply)) { - if (reply == KEYD_REPLY_OK) { - count = read(keyd_fd, &reply, sizeof(reply)); - logthing(LOGTHING_DEBUG, - "keyd protocol version %d", - reply); - if (reply != keyd_version) { - logthing(LOGTHING_CRITICAL, - "Error! keyd protocol version " - "mismatch. (us = %d, it = %d)", + if (count == sizeof(reply) && reply == KEYD_REPLY_OK) { + count = read(keyd_fd, &reply, sizeof(reply)); + if (count != sizeof(reply) || reply != sizeof(reply)) { + logthing(LOGTHING_CRITICAL, + "Error! Unexpected keyd version " + "length: %d != %d", + reply, sizeof(reply)); + exit(EXIT_FAILURE); + } + + count = read(keyd_fd, &reply, sizeof(reply)); + logthing(LOGTHING_DEBUG, + "keyd protocol version %d", + reply); + if (reply != keyd_version) { + logthing(LOGTHING_CRITICAL, + "Error! keyd protocol version " + "mismatch. (us = %d, it = %d)", keyd_version, reply); - } } } } @@ -111,6 +118,16 @@ static void keyd_cleanupdb(void) strerror(errno), errno); } + + if (read(keyd_fd, &cmd, sizeof(cmd)) != sizeof(cmd)) { + logthing(LOGTHING_CRITICAL, + "Couldn't read close cmd reply: %s (%d)", + strerror(errno), + errno); + } else if (cmd != KEYD_REPLY_OK) { + logthing(LOGTHING_CRITICAL, + "Got bad reply to KEYD_CMD_CLOSE: %d", cmd); + } if (shutdown(keyd_fd, SHUT_RDWR) < 0) { logthing(LOGTHING_NOTICE, "Error shutting down socket: %d", @@ -350,6 +367,10 @@ static uint64_t keyd_getfullkeyid(uint64_t keyid) read(keyd_fd, &cmd, sizeof(cmd)); if (cmd == KEYD_REPLY_OK) { write(keyd_fd, &keyid, sizeof(keyid)); + read(keyd_fd, &cmd, sizeof(cmd)); + if (cmd != sizeof(keyid)) { + return 0; + } read(keyd_fd, &keyid, sizeof(keyid)); }