Add use_keyd config file option to select keyd as the backend
authorJonathan McDowell <noodles@earth.li>
Wed, 16 Mar 2011 03:40:44 +0000 (03:40 +0000)
committerJonathan McDowell <noodles@earth.li>
Wed, 16 Mar 2011 03:40:44 +0000 (03:40 +0000)
  We want to be able to use a common config file across the various
  tools, so add a config variable to indicate that we're using keyd.
  This allows keyd to override the option and then get the configured
  backend, while everything else knows to use keyd.

keyd.c
keydb_dynamic.c
onak-conf.c
onak-conf.h
onak.conf.in

diff --git a/keyd.c b/keyd.c
index 18d09bf515fd5533c74a52e9f59e62042d45a094..c802264fb332882ef523173a5ddd8c9a12da6270 100644 (file)
--- a/keyd.c
+++ b/keyd.c
@@ -388,6 +388,7 @@ int main(int argc, char *argv[])
        free(configfile);
        configfile = NULL;
        initlogthing("keyd", config.logfile);
+       config.use_keyd = false;
 
        if (!foreground) {
                daemonize();
index 503f1bfef0433d818c1af37c7cd965c3de297aff..e22b00db30156e084505a3ec9a748a45c0c910e7 100644 (file)
@@ -45,6 +45,11 @@ static bool load_backend(void)
                loaded_backend = NULL;
        }
 
+       if (config.use_keyd) {
+               free(config.db_backend);
+               config.db_backend = strdup("keyd");
+       }
+
        if (!config.db_backend) {
                logthing(LOGTHING_CRITICAL, "No database backend defined.");
                exit(EXIT_FAILURE);
index 70990f87b174ab5565be42d9cf54088265bae512..5f07e02426e25b22594e6eb2f7da74263fe6dc31 100644 (file)
@@ -33,6 +33,8 @@ struct onak_config config = {
        NULL,                   /* syncsites */
        NULL,                   /* logfile */
 
+       false,                  /* use_keyd */
+
        /*
         * Options for directory backends.
         */
@@ -55,6 +57,24 @@ struct onak_config config = {
        &DBFUNCS,               /* Default dbfuncs struct */
 };
 
+bool parsebool(char *str, bool fallback)
+{
+       if (!strcasecmp(str, "false") || !strcasecmp(str, "no") ||
+                       !strcasecmp(str, "0")) {
+               return false;
+       } else if (!strcasecmp(str, "true") || !strcasecmp(str, "yes") ||
+                       !strcasecmp(str, "1")) {
+               return true;
+       } else {
+               logthing(LOGTHING_CRITICAL,
+                       "Couldn't parse %s as a boolean config variable, "
+                       "returning fallback of '%s'.",
+                       str,
+                       fallback ? "true" : "false");
+               return fallback;
+       }
+}
+
 void readconfig(const char *configfile) {
        FILE *conffile;
        char  curline[1024];
@@ -141,6 +161,9 @@ void readconfig(const char *configfile) {
                        config.db_backend = strdup(&curline[11]);
                } else if (!strncmp("backends_dir ", curline, 13)) {
                        config.backends_dir = strdup(&curline[13]);
+               } else if (!strncmp("use_keyd ", curline, 9)) {
+                       config.use_keyd = parsebool(&curline[9],
+                                               config.use_keyd);
                } else {
                        logthing(LOGTHING_ERROR,
                                "Unknown config line: %s", curline);
index 11bdbdb5bae189f683c80c77a82817b559fd2373..16763c6d1d8ff3fc6de91a1f1a8c8159abf8069b 100644 (file)
@@ -40,6 +40,11 @@ struct onak_config {
        struct ll *syncsites;
        char *logfile;
 
+       /*
+        * Set if we're using keyd as the backend.
+        */
+       bool use_keyd;
+
        /*
         * Options for any database backend that needs a directory, be it the
         * file, db2 or db3 options.
index e1b2c4f8ba071329c8f414517e734947a1164318..2ee3eb4b1da250d77db1dbae9656d9aa14bd2914 100644 (file)
@@ -10,6 +10,9 @@ logfile @STATEDIR@/log/onak.log
 # Loglevel : 0 is highest debug, default is 3, nothing is 7+
 loglevel 3
 
+# Should we use the keyd backend?
+use_keyd false
+
 ### Set www_port to the port on which HTTP requests should be accepted.
 ### If you do not want to process HTTP requests, set this to 0.