+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;
+ }
+}
+
+static bool parseconfigline(char *line)
+{
+ if (line[0] == '#' || line[0] == 0) {
+ /*
+ * Comment line, ignore.
+ */
+ } else if (!strncmp("db_dir ", line, 7)) {
+ config.backend->location = strdup(&line[7]);
+ } else if (!strncmp("debug ", line, 6)) {
+ /*
+ * Not supported yet; ignore for compatibility with
+ * pksd.
+ */
+ } else if (!strncmp("default_language ", line, 17)) {
+ /*
+ * Not supported yet; ignore for compatibility with
+ * pksd.
+ */
+ } else if (!strncmp("mail_delivery_client ", line, 21)) {
+ config.mta = strdup(&line[21]);
+ } else if (!strncmp("maintainer_email ", line, 17)) {
+ config.adminemail = strdup(&line[17]);
+ } else if (!strncmp("mail_intro_file ", line, 16)) {
+ /*
+ * Not supported yet; ignore for compatibility with
+ * pksd.
+ */
+ } else if (!strncmp("help_dir ", line, 9)) {
+ /*
+ * Not supported yet; ignore for compatibility with
+ * pksd.
+ */
+ } else if (!strncmp("max_last ", line, 9)) {
+ /*
+ * Not supported yet; ignore for compatibility with
+ * pksd.
+ */
+ } else if (!strncmp("max_reply_keys ", line, 15)) {
+ config.maxkeys = atoi(&line[15]);
+ } else if (!strncmp("pg_dbhost ", line, 10)) {
+ config.backend->hostname = strdup(&line[10]);
+ } else if (!strncmp("pg_dbname ", line, 10)) {
+ config.backend->location = strdup(&line[10]);
+ } else if (!strncmp("pg_dbuser ", line, 10)) {
+ config.backend->username = strdup(&line[10]);
+ } else if (!strncmp("pg_dbpass ", line, 10)) {
+ config.backend->password = strdup(&line[10]);
+ } else if (!strncmp("syncsite ", line, 9)) {
+ config.syncsites =
+ lladd(config.syncsites, strdup(&line[9]));
+ } else if (!strncmp("logfile ", line, 8)) {
+ config.logfile = strdup(&line[8]);
+ } else if (!strncmp("loglevel ", line, 9)) {
+ setlogthreshold(atoi(&line[9]));
+ } else if (!strncmp("this_site ", line, 10)) {
+ config.thissite = strdup(&line[10]);
+ } else if (!strncmp("socket_name ", line, 12) ||
+ !strncmp("www_port ", line, 9)) {
+ /*
+ * Not applicable; ignored for compatibility with pksd.
+ */
+ } else if (!strncmp("pks_bin_dir ", line, 12)) {
+ config.bin_dir = strdup(&line[12]);
+ } else if (!strncmp("mail_dir ", line, 9)) {
+ config.mail_dir = strdup(&line[9]);
+ } else if (!strncmp("db_backend ", line, 11)) {
+ config.backend->type = strdup(&line[11]);
+ config.backend->name = strdup(&line[11]);
+ config.db_backend = strdup(&line[11]);
+ } else if (!strncmp("backends_dir ", line, 13)) {
+ config.backends_dir = strdup(&line[13]);
+ } else if (!strncmp("use_keyd ", line, 9)) {
+ config.use_keyd = parsebool(&line[9],
+ config.use_keyd);
+ } else if (!strncmp("sock_dir ", line, 9)) {
+ config.sock_dir = strdup(&line[9]);
+ } else if (!strncmp("check_sighash ", line, 9)) {
+ config.check_sighash = parsebool(&line[9],
+ config.check_sighash);
+ } else {
+ return false;
+ }
+
+ return true;
+}
+