From 42bcfe2cae29f375af4cf2cd3ccfa196b77a3946 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Mon, 31 May 2004 23:47:08 +0000 Subject: [PATCH] cscvs to tla changeset 29 Author: noodles Date: 2002/11/11 20:34:28 Addition of config file support. --- add.c | 2 + gpgwww.c | 1 + keydb_db2.c | 2 +- keydb_db3.c | 4 +- keydb_file.c | 6 +-- lookup.c | 1 + maxpath.c | 2 + onak-conf.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++----- onak-conf.h | 29 +++++++++----- onak-mail.pl | 36 +++++++++++++++++- onak.c | 2 + 11 files changed, 165 insertions(+), 25 deletions(-) diff --git a/add.c b/add.c index 80afadd..bb12e05 100644 --- a/add.c +++ b/add.c @@ -16,6 +16,7 @@ #include "getcgi.h" #include "keydb.h" #include "keystructs.h" +#include "onak-conf.h" #include "parsekey.h" #include "merge.h" @@ -55,6 +56,7 @@ int main(int argc, char *argv[]) &packets); if (packets != NULL) { parse_keys(packets, &keys); + readconfig(); initdb(); printf("Got %d new keys.\n", update_keys(&keys, false)); diff --git a/gpgwww.c b/gpgwww.c index 75022b8..bb8a446 100644 --- a/gpgwww.c +++ b/gpgwww.c @@ -54,6 +54,7 @@ int main(int argc, char *argv[]) } printf("

Looking for path from 0x%llX to 0x%llX

\n", from, to); + readconfig(); initdb(); inithash(); dofindpath(from, to, true); diff --git a/keydb_db2.c b/keydb_db2.c index a30b62c..1303cd8 100644 --- a/keydb_db2.c +++ b/keydb_db2.c @@ -78,7 +78,7 @@ void initdb(void) */ db2_env.mp_size = 20 * 1024 * 1024; - ret = db_appinit(config.db2_dbpath, NULL, + ret = db_appinit(config.db_dir, NULL, &db2_env, DB_INIT_MPOOL|DB_INIT_LOCK); if (!ret) { db2_keydbfiles = (DB **) malloc(sizeof (DB *) * db2_numdb); diff --git a/keydb_db3.c b/keydb_db3.c index 6ef3473..fc203a0 100644 --- a/keydb_db3.c +++ b/keydb_db3.c @@ -99,7 +99,7 @@ void initdb(void) char buf[1024]; int ret = 0; - strcpy(buf, config.db2_dbpath); + strcpy(buf, config.db_dir); strcat(buf, "/keydb.db"); ret = db_create(&dbconn, NULL, 0); @@ -116,7 +116,7 @@ void initdb(void) exit(1); } - strcpy(buf, config.db2_dbpath); + strcpy(buf, config.db_dir); strcat(buf, "/worddb"); ret = db_create(&worddb, NULL, 0); diff --git a/keydb_file.c b/keydb_file.c index ba8dc2e..4c1a6a3 100644 --- a/keydb_file.c +++ b/keydb_file.c @@ -81,7 +81,7 @@ int fetch_key(uint64_t keyid, struct openpgp_publickey **publickey, char keyfile[1024]; int fd = -1; - snprintf(keyfile, 1023, "%s/0x%llX", config.file_dbpath, + snprintf(keyfile, 1023, "%s/0x%llX", config.db_dir, keyid & 0xFFFFFFFF); fd = open(keyfile, O_RDONLY); // | O_SHLOCK); @@ -113,7 +113,7 @@ int store_key(struct openpgp_publickey *publickey, bool intrans, bool update) char keyfile[1024]; int fd = -1; - snprintf(keyfile, 1023, "%s/0x%llX", config.file_dbpath, + snprintf(keyfile, 1023, "%s/0x%llX", config.db_dir, get_keyid(publickey) & 0xFFFFFFFF); fd = open(keyfile, O_WRONLY | O_CREAT, 0664); // | O_EXLOCK); @@ -142,7 +142,7 @@ int delete_key(uint64_t keyid, bool intrans) { char keyfile[1024]; - snprintf(keyfile, 1023, "%s/0x%llX", config.file_dbpath, + snprintf(keyfile, 1023, "%s/0x%llX", config.db_dir, keyid & 0xFFFFFFFF); return unlink(keyfile); diff --git a/lookup.c b/lookup.c index e4ac9ce..95ab6af 100644 --- a/lookup.c +++ b/lookup.c @@ -119,6 +119,7 @@ int main(int argc, char *argv[]) } else if (search == NULL) { puts("Error: No key to search for supplied."); } else { + readconfig(); initdb(); switch (op) { case OP_GET: diff --git a/maxpath.c b/maxpath.c index 8c22b4a..ffa230f 100644 --- a/maxpath.c +++ b/maxpath.c @@ -13,6 +13,7 @@ #include "hash.h" #include "keydb.h" #include "ll.h" +#include "onak-conf.h" #include "stats.h" void findmaxpath(unsigned long max) @@ -55,6 +56,7 @@ void findmaxpath(unsigned long max) int main(int argc, char *argv[]) { + readconfig(); initdb(); inithash(); findmaxpath(30); diff --git a/onak-conf.c b/onak-conf.c index ef811ce..126bd56 100644 --- a/onak-conf.c +++ b/onak-conf.c @@ -6,29 +6,32 @@ * Copyright 2002 Project Purple */ +#include +#include #include +#include +#include "ll.h" #include "onak-conf.h" /* * config - Runtime configuration for onak. * - * Currently this is all hardcoded, but only needs changed here. In future - * it'll be read from a config file. + * This is the default config; normally overridden with values from the + * config file. */ struct onak_config config = { 128, /* maxkeys */ + NULL, /* thissite */ + NULL, /* adminemail */ + NULL, /* mta */ + NULL, /* syncsites */ /* - * Options for the db2 file backend. + * Options for directory backends. */ - "/home/noodles/onak-db", /* db2_dbpath */ + "/home/noodles/onak-db", /* db_dir */ - /* - * Options for the file backend. - */ - "/home/noodles/projects/onak/db", /* file_dbpath */ - /* * Options for the Postgres backend. */ @@ -37,3 +40,87 @@ struct onak_config config = { NULL, /* pg_dbuser */ NULL, /* pg_dbpass */ }; + +void readconfig(void) { + FILE *conffile; + char curline[1024]; + int i; + + curline[1023] = 0; + conffile = fopen(CONFIGFILE, "r"); + if (conffile != NULL) { + fgets(curline, 1023, conffile); + + while (!feof(conffile)) { + for (i = strlen(curline) - 1; isspace(curline[i]); i--) { + curline[i] = 0; + } + + if (curline[0] == '#' || curline[0] == 0) { + /* + * Comment line, ignore. + */ + } else if (!strncmp("db_dir ", curline, 7)) { + config.db_dir = strdup(&curline[7]); + } else if (!strncmp("debug ", curline, 6)) { + /* + * Not supported yet; ignore for compatibility with + * pksd. + */ + } else if (!strncmp("default_language ", curline, 17)) { + /* + * Not supported yet; ignore for compatibility with + * pksd. + */ + } else if (!strncmp("mail_delivery_client ", curline, 21)) { + config.mta = strdup(&curline[21]); + } else if (!strncmp("maintainer_email ", curline, 17)) { + config.adminemail = strdup(&curline[17]); + } else if (!strncmp("mail_intro_file ", curline, 16)) { + /* + * Not supported yet; ignore for compatibility with + * pksd. + */ + } else if (!strncmp("help_dir ", curline, 9)) { + /* + * Not supported yet; ignore for compatibility with + * pksd. + */ + } else if (!strncmp("max_last ", curline, 9)) { + /* + * Not supported yet; ignore for compatibility with + * pksd. + */ + } else if (!strncmp("max_reply_keys ", curline, 15)) { + config.maxkeys = atoi(&curline[15]); + } else if (!strncmp("pg_dbhost ", curline, 10)) { + config.pg_dbhost = strdup(&curline[10]); + } else if (!strncmp("pg_dbname ", curline, 10)) { + config.pg_dbname = strdup(&curline[10]); + } else if (!strncmp("pg_dbuser ", curline, 10)) { + config.pg_dbuser = strdup(&curline[10]); + } else if (!strncmp("pg_dbpass ", curline, 10)) { + config.pg_dbpass = strdup(&curline[10]); + } else if (!strncmp("syncsite ", curline, 9)) { + config.syncsites = + lladd(config.syncsites, strdup(&curline[9])); + } else if (!strncmp("this_site ", curline, 10)) { + config.thissite = strdup(&curline[10]); + } else if (!strncmp("socket_name ", curline, 12) || + !strncmp("pks_bin_dir ", curline, 12) || + !strncmp("mail_dir ", curline, 9) || + !strncmp("www_port ", curline, 9)) { + /* + * Not applicable; ignored for compatibility with pksd. + */ + } else { + fprintf(stderr, "Unknown config line: %s\n", curline); + } + + fgets(curline, 1023, conffile); + } + fclose(conffile); + } else { + fprintf(stderr, "Couldn't open config file; using defaults.\n"); + } +} diff --git a/onak-conf.h b/onak-conf.h index f91057e..1145818 100644 --- a/onak-conf.h +++ b/onak-conf.h @@ -10,15 +10,18 @@ #define __ONAK_CONF_H_ #define VERSION "0.0.4" +#define CONFIGFILE "/home/noodles/projects/onak/onak.conf" /* * struct onak_config - Runtime configuration for onak. * @maxkeys: The maximum number of keys a query should return. + * @thissite: Our email address that servers sync with. + * @adminemail: The email address of the server admin. + * @mta: The mta to invoke to send sync mails. + * @syncsites: A linked list of sites we sync with. * - * @db2_dbpath: The path to the directory containing the db2 files. + * @db_dir: The path to the directory containing the database files. * - * @file_dbpath: The path to the flat file DB directory. - * * @pg_dbhost: The host that Postgres is running on. * @pg_dbname: The database name. * @pg_dbuser: The user we should connect as. @@ -28,17 +31,20 @@ * will eventually be populated from the config file. */ struct onak_config { - int maxkeys; - /* - * Options for the db2 file backend. + * Generic options. */ - char *db2_dbpath; + int maxkeys; + char *thissite; + char *adminemail; + char *mta; + struct ll *syncsites; /* - * Options for the file backend. + * Options for any database backend that needs a directory, be it the + * file, db2 or db3 options. */ - char *file_dbpath; + char *db_dir; /* * Options for the Postgres backend. @@ -54,4 +60,9 @@ struct onak_config { */ extern struct onak_config config; +/* + * readconfig - read the onak config. + */ +void readconfig(void); + #endif /* __ONAK_CONF_H_ */ diff --git a/onak-mail.pl b/onak-mail.pl index 0f108f4..0e3c2b5 100755 --- a/onak-mail.pl +++ b/onak-mail.pl @@ -11,6 +11,38 @@ use strict; use IPC::Open3; +my %config; + +# +# readconfig +# +# Reads in our config file. Ignores any command it doesn't understand rather +# than having to list all the ones that are of no interest to us. +# +sub readconfig { + + open(CONFIG, "/home/noodles/projects/onak/onak.conf") or + die "Can't read config file: $!"; + + while () { + if (/^#/ or /^$/) { + # Ignore; comment line. + } elsif (/^this_site (.*)/) { + $config{'thissite'} = $1; + } elsif (/^maintainer_email (.*)/) { + $config{'adminemail'} = $1; + } elsif (/^mail_delivery_client (.*)/) { + $config{'mta'} = $1; + } elsif (/^syncsite (.*)/) { + push @{$config{'syncsites'}}, $1; + } + } + + close(CONFIG); + + return; +} + # # submitupdate # @@ -22,7 +54,8 @@ sub submitupdate { my @data = @_; my (@errors, @mergedata); - open3(\*MERGEIN, \*MERGEOUT, \*MERGEERR, "/home/noodles/onak-0.0.3/onak", "add"); + open3(\*MERGEIN, \*MERGEOUT, \*MERGEERR, + "/home/noodles/onak-0.0.3/onak", "add"); print MERGEIN @data; close MERGEIN; @@ -40,6 +73,7 @@ my ($inheader, %syncsites, $subject, $from, $replyto, @body, @syncmail); $inheader = 1; $subject = ""; +&readconfig; while (<>) { if ($inheader) { diff --git a/onak.c b/onak.c index 87b65e8..8eccc9c 100644 --- a/onak.c +++ b/onak.c @@ -107,6 +107,8 @@ int main(int argc, char *argv[]) } } + readconfig(); + if ((argc - optind) < 1) { usage(); } else if (!strcmp("add", argv[optind])) { -- 2.30.2