X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/blobdiff_plain/6f0d21388eeeb33893728d92dfc0f3a3a6d6aafe..8a1337cda8055ff06e54c1def4b13eea133c7672:/onak-conf.c?ds=sidebyside diff --git a/onak-conf.c b/onak-conf.c index 81d7bdf..5f07e02 100644 --- a/onak-conf.c +++ b/onak-conf.c @@ -17,6 +17,8 @@ #include "log.h" #include "onak-conf.h" +extern struct dbfuncs DBFUNCS; + /* * config - Runtime configuration for onak. * @@ -31,6 +33,8 @@ struct onak_config config = { NULL, /* syncsites */ NULL, /* logfile */ + false, /* use_keyd */ + /* * Options for directory backends. */ @@ -43,8 +47,34 @@ struct onak_config config = { NULL, /* pg_dbname */ NULL, /* pg_dbuser */ NULL, /* pg_dbpass */ + + /* + * Options for dynamic backends. + */ + NULL, /* db_backend */ + NULL, /* backends_dir */ + + &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]; @@ -60,9 +90,11 @@ void readconfig(const char *configfile) { fgets(curline, 1023, conffile); while (!feof(conffile)) { - for (i = strlen(curline) - 1; isspace(curline[i]); i--) { - curline[i] = 0; - } + for (i = strlen(curline) - 1; + i >= 0 && isspace(curline[i]); + i--) { + curline[i] = 0; + } if (curline[0] == '#' || curline[0] == 0) { /* @@ -125,6 +157,13 @@ void readconfig(const char *configfile) { /* * Not applicable; ignored for compatibility with pksd. */ + } else if (!strncmp("db_backend ", curline, 11)) { + 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); @@ -180,4 +219,12 @@ void cleanupconfig(void) { free(config.logfile); config.logfile = NULL; } + if (config.db_backend != NULL) { + free(config.db_backend); + config.db_backend = NULL; + } + if (config.backends_dir != NULL) { + free(config.backends_dir); + config.backends_dir = NULL; + } }