]> git.sommitrealweird.co.uk Git - onak.git/blobdiff - keyd.c
Only seed database for Debian install if we're using default config
[onak.git] / keyd.c
diff --git a/keyd.c b/keyd.c
index f8f5d4a50abd8f98bf2c053443c85f270af791b6..33af8ea0e3935768e75a021d9c2bd781db163383 100644 (file)
--- a/keyd.c
+++ b/keyd.c
@@ -10,6 +10,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/select.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <sys/un.h>
@@ -32,7 +33,7 @@ void iteratefunc(void *ctx, struct openpgp_publickey *key)
        struct openpgp_packet_list *list_end = NULL;
        struct buffer_ctx           storebuf;
        int                         ret = 0;
-       int                         fd = (int) ctx;
+       int                         *fd = (int *) ctx;
 
        if (key != NULL) {
                storebuf.offset = 0;
@@ -52,10 +53,10 @@ void iteratefunc(void *ctx, struct openpgp_publickey *key)
                logthing(LOGTHING_TRACE,
                                "Sending %d bytes.",
                                storebuf.offset);
-               ret = write(fd, &storebuf.offset,
+               ret = write(*fd, &storebuf.offset,
                        sizeof(storebuf.offset));
                if (ret != 0) {
-                       write(fd, storebuf.buffer,
+                       write(*fd, storebuf.buffer,
                                storebuf.offset);
                }
 
@@ -137,6 +138,7 @@ int sock_do(int fd)
                                logthing(LOGTHING_INFO,
                                                "Fetching 0x%llX, result: %d",
                                                keyid,
+                                               config.dbbackend->
                                                fetch_key(keyid, &key, false));
                                if (key != NULL) {
                                        storebuf.size = 8192;
@@ -184,6 +186,7 @@ int sock_do(int fd)
                                logthing(LOGTHING_INFO,
                                                "Fetching %s, result: %d",
                                                search,
+                                               config.dbbackend->
                                                fetch_key_text(search, &key));
                                if (key != NULL) {
                                        storebuf.size = 8192;
@@ -244,7 +247,7 @@ int sock_do(int fd)
                                                &packets,
                                                0);
                                parse_keys(packets, &key);
-                               store_key(key, false, false);
+                               config.dbbackend->store_key(key, false, false);
                                free_packet_list(packets);
                                packets = NULL;
                                free_publickey(key);
@@ -265,7 +268,8 @@ int sock_do(int fd)
                                logthing(LOGTHING_INFO,
                                                "Deleting 0x%llX, result: %d",
                                                keyid,
-                                               delete_key(keyid, false));
+                                               config.dbbackend->delete_key(
+                                                       keyid, false));
                        }
                        break;
                case KEYD_CMD_GETFULLKEYID:
@@ -276,14 +280,15 @@ int sock_do(int fd)
                                ret = 1;
                        }
                        if (ret == 0) {
-                               keyid = getfullkeyid(keyid);
+                               keyid = config.dbbackend->getfullkeyid(keyid);
                                write(fd, &keyid, sizeof(keyid));
                        }
                        break;
                case KEYD_CMD_KEYITER:
                        cmd = KEYD_REPLY_OK;
                        write(fd, &cmd, sizeof(cmd));
-                       iterate_keys(iteratefunc, (void *) fd);
+                       config.dbbackend->iterate_keys(iteratefunc,
+                                       &fd);
                        bytes = 0;
                        write(fd, &bytes, sizeof(bytes));
                        break;
@@ -306,7 +311,8 @@ int sock_do(int fd)
 
 int sock_close(int fd)
 {
-       return shutdown(fd, SHUT_RDWR);
+       shutdown(fd, SHUT_RDWR);
+       return close(fd);
 }
 
 int sock_accept(int fd)
@@ -348,7 +354,7 @@ int main(int argc, char *argv[])
                FD_ZERO(&rfds);
                FD_SET(fd, &rfds);
 
-               initdb(false);
+               config.dbbackend->initdb(false);
 
                logthing(LOGTHING_NOTICE, "Accepting connections.");
                while (!cleanup() && select(fd + 1, &rfds, NULL, NULL, NULL) != -1) {
@@ -356,7 +362,7 @@ int main(int argc, char *argv[])
                        sock_accept(fd);
                        FD_SET(fd, &rfds);
                }
-               cleanupdb();
+               config.dbbackend->cleanupdb();
                sock_close(fd);
                unlink(sockname);
        }