#include "getcgi.h"
#include "keydb.h"
#include "keystructs.h"
+#include "onak-conf.h"
#include "parsekey.h"
#include "merge.h"
&packets);
if (packets != NULL) {
parse_keys(packets, &keys);
+ readconfig();
initdb();
printf("Got %d new keys.\n",
update_keys(&keys, false));
}
printf("<P>Looking for path from 0x%llX to 0x%llX</P>\n", from, to);
+ readconfig();
initdb();
inithash();
dofindpath(from, to, true);
*/
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);
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);
exit(1);
}
- strcpy(buf, config.db2_dbpath);
+ strcpy(buf, config.db_dir);
strcat(buf, "/worddb");
ret = db_create(&worddb, NULL, 0);
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);
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);
{
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);
} else if (search == NULL) {
puts("Error: No key to search for supplied.");
} else {
+ readconfig();
initdb();
switch (op) {
case OP_GET:
#include "hash.h"
#include "keydb.h"
#include "ll.h"
+#include "onak-conf.h"
#include "stats.h"
void findmaxpath(unsigned long max)
int main(int argc, char *argv[])
{
+ readconfig();
initdb();
inithash();
findmaxpath(30);
* Copyright 2002 Project Purple
*/
+#include <ctype.h>
+#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#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.
*/
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");
+ }
+}
#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.
* 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.
*/
extern struct onak_config config;
+/*
+ * readconfig - read the onak config.
+ */
+void readconfig(void);
+
#endif /* __ONAK_CONF_H_ */
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 (<CONFIG>) {
+ 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
#
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;
$inheader = 1;
$subject = "";
+&readconfig;
while (<>) {
if ($inheader) {
}
}
+ readconfig();
+
if ((argc - optind) < 1) {
usage();
} else if (!strcmp("add", argv[optind])) {