]> the.earth.li Git - onak.git/blobdiff - keyd.c
Fix issue with looking up keys by fingerprint via HKP interface
[onak.git] / keyd.c
diff --git a/keyd.c b/keyd.c
index f3966db96dcdbafde6b92b341566b1199da791a7..b8b8ad37e6bf1eff136eb089807687cc51650958 100644 (file)
--- a/keyd.c
+++ b/keyd.c
@@ -65,7 +65,7 @@ void daemonize(void)
                exit(EXIT_SUCCESS);
        }
 
-       pid = setsid();
+       setsid();
 
        freopen("/dev/null", "r", stdin);
        freopen("/dev/null", "w", stdout);
@@ -139,8 +139,12 @@ int sock_init(const char *sockname)
 
        if (ret != -1) {
                ret = listen(fd, 5);
+               if (ret == -1) {
+                       close(fd);
+                       fd = -1;
+               }
        }
-       
+
        return fd;
 }
 
@@ -151,13 +155,13 @@ int sock_do(struct onak_dbctx *dbctx, int fd)
        ssize_t  count = 0;
        int      ret = 0;
        uint64_t keyid = 0;
-       uint8_t  fp[MAX_FINGERPRINT_LEN];
        char     *search = NULL;
        struct openpgp_publickey *key = NULL;
        struct openpgp_packet_list *packets = NULL;
        struct openpgp_packet_list *list_end = NULL;
        struct buffer_ctx storebuf;
        struct skshash hash;
+       struct openpgp_fingerprint fingerprint;
 
        /*
         * Get the command from the client.
@@ -238,7 +242,8 @@ int sock_do(struct onak_dbctx *dbctx, int fd)
                        if (bytes > MAX_FINGERPRINT_LEN) {
                                ret = 1;
                        } else {
-                               read(fd, fp, bytes);
+                               fingerprint.length = bytes;
+                               read(fd, fingerprint.fp, bytes);
                        }
                        storebuf.offset = 0;
                        if (ret == 0) {
@@ -246,7 +251,7 @@ int sock_do(struct onak_dbctx *dbctx, int fd)
                                                "Fetching by fingerprint"
                                                ", result: %d",
                                                dbctx->fetch_key_fp(dbctx,
-                                                       fp, bytes,
+                                                       &fingerprint,
                                                        &key, false));
                                if (key != NULL) {
                                        storebuf.size = 8192;
@@ -535,6 +540,9 @@ int main(int argc, char *argv[])
        while ((optchar = getopt(argc, argv, "c:fh")) != -1 ) {
                switch (optchar) {
                case 'c':
+                       if (configfile != NULL) {
+                               free(configfile);
+                       }
                        configfile = strdup(optarg);
                        break;
                case 'f':