]> the.earth.li Git - onak.git/blobdiff - keydctl.c
Add ability to drop overly large packets
[onak.git] / keydctl.c
index b786fea3e9c7f5ae3bb662d53f7dd4f269182da9..a2b312ca985d9f274f4858ebccba6dc239e8b96c 100644 (file)
--- a/keydctl.c
+++ b/keydctl.c
@@ -2,23 +2,36 @@
  * keydctl.c - A simple program to control a running keyd instance
  *
  * Copyright 2011 Jonathan McDowell <noodles@earth.li>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 
-#include "config.h"
 #include "keyd.h"
 #include "onak-conf.h"
+#include "version.h"
 
 /* HACK: We need to stop onak-conf.o requiring this. */
-void *DBFUNCS = NULL;
+void *DBINIT = NULL;
 
 static int keyd_fd = -1;
 static int verbose = 0;
@@ -85,7 +98,7 @@ static void keyd_connect(void)
 
        sock.sun_family = AF_UNIX;
        snprintf(sock.sun_path, sizeof(sock.sun_path) - 1, "%s/%s",
-                       config.db_dir,
+                       config.sock_dir,
                        KEYD_SOCKET);
        if (connect(keyd_fd, (struct sockaddr *) &sock, sizeof(sock)) < 0) {
                if (verbose >= 0) {
@@ -138,18 +151,59 @@ static void keyd_close(void)
 static void keyd_status(void)
 {
        uint32_t reply;
+       struct keyd_stats stats;
 
-       keyd_do_command(KEYD_CMD_VERSION, &reply, sizeof(reply));
+       if (keyd_do_command(KEYD_CMD_VERSION, &reply, sizeof(reply)) == -1) {
+               printf("Got failure asking for keyd version.\n");
+               return;
+       }
        printf("Using keyd protocol version %d.\n", reply);
 
+       if (keyd_do_command(KEYD_CMD_STATS, &stats, sizeof(stats)) == -1) {
+               printf("Got failure asking for keyd statistics.\n");
+               return;
+       }
+
+       printf("keyd running since %s", ctime(&stats.started));
+       printf("%d client connections received\n", stats.connects);
+
+       printf("Command statistics:\n");
+       printf("  Version:          %d\n",
+               stats.command_stats[KEYD_CMD_VERSION]);
+       printf("  Get key by ID:    %d\n",
+               stats.command_stats[KEYD_CMD_GET_ID]);
+       printf("  Get key by FP:    %d\n",
+               stats.command_stats[KEYD_CMD_GET_FP]);
+       printf("  Get key by hash:  %d\n",
+               stats.command_stats[KEYD_CMD_GET_SKSHASH]);
+       printf("  Store key:        %d\n",
+               stats.command_stats[KEYD_CMD_STORE]);
+       printf("  Delete key:       %d\n",
+               stats.command_stats[KEYD_CMD_DELETE]);
+       printf("  Update key:       %d\n",
+               stats.command_stats[KEYD_CMD_UPDATE]);
+       printf("  Search key:       %d\n",
+               stats.command_stats[KEYD_CMD_GET_TEXT]);
+       printf("  Get full keyid:   %d\n",
+               stats.command_stats[KEYD_CMD_GETFULLKEYID]);
+       printf("  Iterate all keys: %d\n",
+               stats.command_stats[KEYD_CMD_KEYITER]);
+       printf("  Close:            %d\n",
+               stats.command_stats[KEYD_CMD_CLOSE]);
+       printf("  Quit:             %d\n", stats.command_stats[KEYD_CMD_QUIT]);
+       printf("  Get statistics:   %d\n",
+               stats.command_stats[KEYD_CMD_STATS]);
+       printf("  Unknown:          %d\n",
+               stats.command_stats[KEYD_CMD_UNKNOWN]);
+
        return;
 }
 
 static void usage(void)
 {
-       puts("keydctl " PACKAGE_VERSION " - control an onak keyd instance.\n");
+       puts("keydctl " ONAK_VERSION " - control an onak keyd instance.\n");
        puts("Usage:\n");
-       puts("\tonak [options] <command> <parameters>\n");
+       puts("\tkeydctl [options] <command> <parameters>\n");
        puts("\tCommands:\n");
        puts("\tcheck    - check if keyd is running");
        puts("\tquit     - request that keyd cleanly shuts down");
@@ -179,6 +233,7 @@ int main(int argc, char *argv[])
        configfile = NULL;
 
        if ((argc - optind) < 1) {
+               cleanupconfig();
                usage();
        } else if (!strcmp("check", argv[optind])) {
                /* Just do the connect and close quietly */
@@ -194,9 +249,11 @@ int main(int argc, char *argv[])
                keyd_do_command(KEYD_CMD_QUIT, NULL, 0);
                keyd_close();
        } else {
+               cleanupconfig();
                usage();
        }
 
+       cleanupconfig();
 
        exit(EXIT_SUCCESS);
 }