]> git.sommitrealweird.co.uk Git - onak.git/blobdiff - keyd.c
"Recognize" some extra subpacket types
[onak.git] / keyd.c
diff --git a/keyd.c b/keyd.c
index 7b6226e3877abbd8c885e3763667f18d72500bba..d6abd32b8a21c462cb9611334c1c9301ff324b7c 100644 (file)
--- a/keyd.c
+++ b/keyd.c
 #include "cleanup.h"
 #include "keyd.h"
 #include "keydb.h"
 #include "cleanup.h"
 #include "keyd.h"
 #include "keydb.h"
+#include "keyid.h"
 #include "keystructs.h"
 #include "log.h"
 #include "mem.h"
 #include "onak-conf.h"
 #include "parsekey.h"
 
 #include "keystructs.h"
 #include "log.h"
 #include "mem.h"
 #include "onak-conf.h"
 #include "parsekey.h"
 
+void iteratefunc(void *ctx, struct openpgp_publickey *key)
+{
+       struct openpgp_packet_list *packets = NULL;
+       struct openpgp_packet_list *list_end = NULL;
+       struct buffer_ctx           storebuf;
+       int                         ret = 0;
+       int                         fd = (int) ctx;
+
+       if (key != NULL) {
+               storebuf.offset = 0;
+               storebuf.size = 8192;
+               storebuf.buffer = malloc(8192);
+
+               logthing(LOGTHING_TRACE,
+                               "Iterating over 0x%016llX.",
+                               get_keyid(key));
+
+               flatten_publickey(key,
+                               &packets,
+                               &list_end);
+               write_openpgp_stream(buffer_putchar,
+                               &storebuf,
+                               packets);
+               logthing(LOGTHING_TRACE,
+                               "Sending %d bytes.",
+                               storebuf.offset);
+               ret = write(fd, &storebuf.offset,
+                       sizeof(storebuf.offset));
+               if (ret != 0) {
+                       write(fd, storebuf.buffer,
+                               storebuf.offset);
+               }
+
+               free(storebuf.buffer);
+               storebuf.buffer = NULL;
+               storebuf.size = storebuf.offset = 0;
+               free_packet_list(packets);
+               packets = list_end = NULL;
+       }
+
+       return;
+}
+
 int sock_init(const char *sockname)
 {
        struct sockaddr_un sock;
 int sock_init(const char *sockname)
 {
        struct sockaddr_un sock;
@@ -93,6 +137,7 @@ int sock_do(int fd)
                                logthing(LOGTHING_INFO,
                                                "Fetching 0x%llX, result: %d",
                                                keyid,
                                logthing(LOGTHING_INFO,
                                                "Fetching 0x%llX, result: %d",
                                                keyid,
+                                               config.dbbackend->
                                                fetch_key(keyid, &key, false));
                                if (key != NULL) {
                                        storebuf.size = 8192;
                                                fetch_key(keyid, &key, false));
                                if (key != NULL) {
                                        storebuf.size = 8192;
@@ -140,6 +185,7 @@ int sock_do(int fd)
                                logthing(LOGTHING_INFO,
                                                "Fetching %s, result: %d",
                                                search,
                                logthing(LOGTHING_INFO,
                                                "Fetching %s, result: %d",
                                                search,
+                                               config.dbbackend->
                                                fetch_key_text(search, &key));
                                if (key != NULL) {
                                        storebuf.size = 8192;
                                                fetch_key_text(search, &key));
                                if (key != NULL) {
                                        storebuf.size = 8192;
@@ -200,7 +246,7 @@ int sock_do(int fd)
                                                &packets,
                                                0);
                                parse_keys(packets, &key);
                                                &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);
                                free_packet_list(packets);
                                packets = NULL;
                                free_publickey(key);
@@ -221,7 +267,8 @@ int sock_do(int fd)
                                logthing(LOGTHING_INFO,
                                                "Deleting 0x%llX, result: %d",
                                                keyid,
                                logthing(LOGTHING_INFO,
                                                "Deleting 0x%llX, result: %d",
                                                keyid,
-                                               delete_key(keyid, false));
+                                               config.dbbackend->delete_key(
+                                                       keyid, false));
                        }
                        break;
                case KEYD_CMD_GETFULLKEYID:
                        }
                        break;
                case KEYD_CMD_GETFULLKEYID:
@@ -232,10 +279,18 @@ int sock_do(int fd)
                                ret = 1;
                        }
                        if (ret == 0) {
                                ret = 1;
                        }
                        if (ret == 0) {
-                               keyid = getfullkeyid(keyid);
+                               keyid = config.dbbackend->getfullkeyid(keyid);
                                write(fd, &keyid, sizeof(keyid));
                        }
                        break;
                                write(fd, &keyid, sizeof(keyid));
                        }
                        break;
+               case KEYD_CMD_KEYITER:
+                       cmd = KEYD_REPLY_OK;
+                       write(fd, &cmd, sizeof(cmd));
+                       config.dbbackend->iterate_keys(iteratefunc,
+                                       (void *) fd);
+                       bytes = 0;
+                       write(fd, &bytes, sizeof(bytes));
+                       break;
                case KEYD_CMD_CLOSE:
                        ret = 1;
                        break;
                case KEYD_CMD_CLOSE:
                        ret = 1;
                        break;
@@ -297,7 +352,7 @@ int main(int argc, char *argv[])
                FD_ZERO(&rfds);
                FD_SET(fd, &rfds);
 
                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) {
 
                logthing(LOGTHING_NOTICE, "Accepting connections.");
                while (!cleanup() && select(fd + 1, &rfds, NULL, NULL, NULL) != -1) {
@@ -305,7 +360,7 @@ int main(int argc, char *argv[])
                        sock_accept(fd);
                        FD_SET(fd, &rfds);
                }
                        sock_accept(fd);
                        FD_SET(fd, &rfds);
                }
-               cleanupdb();
+               config.dbbackend->cleanupdb();
                sock_close(fd);
                unlink(sockname);
        }
                sock_close(fd);
                unlink(sockname);
        }