]> the.earth.li Git - onak.git/blobdiff - keydb_keyd.c
Check return value when writing PID to DB4 upgrade lock file
[onak.git] / keydb_keyd.c
index 5fd084398d048568df01867785f24453c93304a4..d05c7f8998e2008455ce20fa6d27eb717936a075 100644 (file)
@@ -116,7 +116,7 @@ static int keyd_fetch_key_id(struct onak_dbctx *dbctx,
 }
 
 static int keyd_fetch_key_fp(struct onak_dbctx *dbctx,
-               uint8_t *fp, size_t fpsize,
+               struct openpgp_fingerprint *fingerprint,
                struct openpgp_publickey **publickey,
                bool intrans)
 {
@@ -128,16 +128,16 @@ static int keyd_fetch_key_fp(struct onak_dbctx *dbctx,
        ssize_t                     count = 0;
        uint8_t                     size;
 
-       if (fpsize > MAX_FINGERPRINT_LEN) {
+       if (fingerprint->length > MAX_FINGERPRINT_LEN) {
                return 0;
        }
 
        write(keyd_fd, &cmd, sizeof(cmd));
        read(keyd_fd, &cmd, sizeof(cmd));
        if (cmd == KEYD_REPLY_OK) {
-               size = fpsize;
+               size = fingerprint->length;
                write(keyd_fd, &size, sizeof(size));
-               write(keyd_fd, fp, size);
+               write(keyd_fd, fingerprint->fp, size);
                keybuf.offset = 0;
                read(keyd_fd, &keybuf.size, sizeof(keybuf.size));
                if (keybuf.size > 0) {
@@ -489,7 +489,6 @@ static void keyd_cleanupdb(struct onak_dbctx *dbctx)
                logthing(LOGTHING_NOTICE, "Error closing down socket: %d",
                                errno);
        }
-       keyd_fd = -1;
 
        free(dbctx);
 
@@ -559,6 +558,13 @@ struct onak_dbctx *keydb_keyd_init(bool readonly)
                        }
 
                        count = read(keyd_fd, &reply, sizeof(reply));
+                       if (count != sizeof(reply)) {
+                               logthing(LOGTHING_CRITICAL,
+                                       "Error! Unexpected keyd version "
+                                       "length: %d != %d",
+                                       count, sizeof(reply));
+                               exit(EXIT_FAILURE);
+                       }
                        logthing(LOGTHING_DEBUG,
                                        "keyd protocol version %d",
                                        reply);