]> the.earth.li Git - onak.git/blobdiff - keydb/keyd.c
Indicate when we've been started via socket activation
[onak.git] / keydb / keyd.c
index 0df7192bfb6795b35d0d2b85ae8eafb6b699d6d1..5b187854a04b453e0df95631948cce0575cd3ec0 100644 (file)
@@ -52,9 +52,7 @@
 /* Maximum number of clients we're prepared to accept at once */
 #define MAX_CLIENTS 16
 
-#ifdef HAVE_SYSTEMD
 static bool using_socket_activation = false;
-#endif
 
 static struct keyd_stats *stats;
 
@@ -300,6 +298,41 @@ static int sock_do(struct onak_dbctx *dbctx, int fd)
                                }
                        }
                        break;
+               case KEYD_CMD_GET:
+                       if (!keyd_write_reply(fd, KEYD_REPLY_OK)) {
+                               ret = 1;
+                       }
+                       if (ret == 0) {
+                               if ((read(fd, &bytes, 1) != 1) ||
+                                               (bytes > MAX_FINGERPRINT_LEN)) {
+                                       ret = 1;
+                               } else {
+                                       fingerprint.length = bytes;
+                                       bytes = read(fd, fingerprint.fp,
+                                               fingerprint.length);
+                                       if (bytes != fingerprint.length) {
+                                               ret = 1;
+                                       }
+                               }
+                       }
+                       if (ret == 0) {
+                               logthing(LOGTHING_INFO,
+                                               "Fetching by fingerprint"
+                                               ", result: %d",
+                                               dbctx->fetch_key(dbctx,
+                                                       &fingerprint,
+                                                       &key, false));
+                               if (key != NULL) {
+                                       keyd_write_key(fd, key);
+                                       free_publickey(key);
+                                       key = NULL;
+                               } else {
+                                       if (!keyd_write_size(fd, 0)) {
+                                               ret = 1;
+                                       }
+                               }
+                       }
+                       break;
                case KEYD_CMD_GET_ID:
                        if (!keyd_write_reply(fd, KEYD_REPLY_OK)) {
                                ret = 1;
@@ -364,7 +397,6 @@ static int sock_do(struct onak_dbctx *dbctx, int fd)
                                }
                        }
                        break;
-
                case KEYD_CMD_GET_TEXT:
                        if (!keyd_write_reply(fd, KEYD_REPLY_OK)) {
                                ret = 1;
@@ -648,7 +680,8 @@ int main(int argc, char *argv[])
 
                dbctx = config.dbinit(config.backend, false);
 
-               logthing(LOGTHING_NOTICE, "Accepting connections.");
+               logthing(LOGTHING_NOTICE, "Accepting connections%s",
+                       using_socket_activation ? " (via systemd)" : "");
                while (!cleanup() && select(maxfd + 1, &rfds, NULL, NULL, NULL) != -1) {
                        /*
                         * Deal with existing clients first; if we're at our
@@ -707,6 +740,7 @@ int main(int argc, char *argv[])
 
        free(stats);
 
+       logthing(LOGTHING_NOTICE, "Exiting");
        cleanuplogthing();
        cleanupconfig();