]> git.sommitrealweird.co.uk Git - onak.git/commitdiff
cscvs to tla changeset 29
authorJonathan McDowell <noodles@earth.li>
Mon, 31 May 2004 23:47:08 +0000 (23:47 +0000)
committerJonathan McDowell <noodles@earth.li>
Mon, 31 May 2004 23:47:08 +0000 (23:47 +0000)
Author: noodles
Date: 2002/11/11 20:34:28
Addition of config file support.

add.c
gpgwww.c
keydb_db2.c
keydb_db3.c
keydb_file.c
lookup.c
maxpath.c
onak-conf.c
onak-conf.h
onak-mail.pl
onak.c

diff --git a/add.c b/add.c
index 80afaddf5ba352615af93f22f7978e54d77214ac..bb12e059beb861d69afde4beea10ee4a65b3b715 100644 (file)
--- a/add.c
+++ b/add.c
@@ -16,6 +16,7 @@
 #include "getcgi.h"
 #include "keydb.h"
 #include "keystructs.h"
 #include "getcgi.h"
 #include "keydb.h"
 #include "keystructs.h"
+#include "onak-conf.h"
 #include "parsekey.h"
 #include "merge.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);
                                        &packets);
                if (packets != NULL) {
                        parse_keys(packets, &keys);
+                       readconfig();
                        initdb();
                        printf("Got %d new keys.\n",
                                        update_keys(&keys, false));
                        initdb();
                        printf("Got %d new keys.\n",
                                        update_keys(&keys, false));
index 75022b86e83b5d74d1312c4fc161fc3968e91d92..bb8a446cd4be840df0be7c8119ae56776478f3cc 100644 (file)
--- a/gpgwww.c
+++ b/gpgwww.c
@@ -54,6 +54,7 @@ int main(int argc, char *argv[])
        }
 
        printf("<P>Looking for path from 0x%llX to 0x%llX</P>\n", from, to);
        }
 
        printf("<P>Looking for path from 0x%llX to 0x%llX</P>\n", from, to);
+       readconfig();
        initdb();
        inithash();
        dofindpath(from, to, true);
        initdb();
        inithash();
        dofindpath(from, to, true);
index a30b62c43ba3b27413263372315641073d491191..1303cd80824312d48f1f628a93056040199331b6 100644 (file)
@@ -78,7 +78,7 @@ void initdb(void)
         */
        db2_env.mp_size = 20 * 1024 * 1024;
 
         */
        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);
                        &db2_env, DB_INIT_MPOOL|DB_INIT_LOCK);
        if (!ret) {
                db2_keydbfiles = (DB **) malloc(sizeof (DB *) * db2_numdb);
index 6ef3473189de8e9060e654f0a3c0eaff2541f7c7..fc203a08d6404515b90caf05439e578b8049c1e2 100644 (file)
@@ -99,7 +99,7 @@ void initdb(void)
        char buf[1024];
        int ret = 0;
 
        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);
        strcat(buf, "/keydb.db");
        
        ret = db_create(&dbconn, NULL, 0);
@@ -116,7 +116,7 @@ void initdb(void)
                exit(1);
        }
 
                exit(1);
        }
 
-       strcpy(buf, config.db2_dbpath);
+       strcpy(buf, config.db_dir);
        strcat(buf, "/worddb");
        
        ret = db_create(&worddb, NULL, 0);
        strcat(buf, "/worddb");
        
        ret = db_create(&worddb, NULL, 0);
index ba8dc2e6bd63798a50eaff83f0d61b4bda71214e..4c1a6a384b199018b37b80c9ef12b0f019b31a70 100644 (file)
@@ -81,7 +81,7 @@ int fetch_key(uint64_t keyid, struct openpgp_publickey **publickey,
        char keyfile[1024];
        int fd = -1;
 
        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);
 
                        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;
 
        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);
 
                        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];
 
 {
        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);
                        keyid & 0xFFFFFFFF);
 
        return unlink(keyfile);
index e4ac9cefaecbe36fdbfbb7ba815d3de916e63940..95ab6af01f2f54454474e87c4143bcdfb29f4e6f 100644 (file)
--- 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 {
        } else if (search == NULL) {
                puts("Error: No key to search for supplied.");
        } else {
+               readconfig();
                initdb();
                switch (op) {
                case OP_GET:
                initdb();
                switch (op) {
                case OP_GET:
index 8c22b4a3a8ad86390f1cbf9a511064ba67639972..ffa230fd2c1e557ed83fa8d269b48376a28a472e 100644 (file)
--- a/maxpath.c
+++ b/maxpath.c
@@ -13,6 +13,7 @@
 #include "hash.h"
 #include "keydb.h"
 #include "ll.h"
 #include "hash.h"
 #include "keydb.h"
 #include "ll.h"
+#include "onak-conf.h"
 #include "stats.h"
 
 void findmaxpath(unsigned long max)
 #include "stats.h"
 
 void findmaxpath(unsigned long max)
@@ -55,6 +56,7 @@ void findmaxpath(unsigned long max)
 
 int main(int argc, char *argv[])
 {
 
 int main(int argc, char *argv[])
 {
+       readconfig();
        initdb();
        inithash();
        findmaxpath(30);
        initdb();
        inithash();
        findmaxpath(30);
index ef811ce30a7572a700ed0108851f1d818d3cb145..126bd565d4409515bf2f084333e8f27244791283 100644 (file)
@@ -6,29 +6,32 @@
  * Copyright 2002 Project Purple
  */
 
  * Copyright 2002 Project Purple
  */
 
+#include <ctype.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
+#include <string.h>
 
 
+#include "ll.h"
 #include "onak-conf.h"
 
 /*
  *     config - Runtime configuration for onak.
  *
 #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 */
  */
 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.
         */
        /*
         * Options for the Postgres backend.
         */
@@ -37,3 +40,87 @@ struct onak_config config = {
        NULL,                   /* pg_dbuser */
        NULL,                   /* pg_dbpass */
 };
        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");
+       }
+}
index f91057e321a67b2c11292864d578a049b32f4f68..11458187fad6dcf259407976419ff5e294316b85 100644 (file)
 #define __ONAK_CONF_H_
 
 #define VERSION "0.0.4"
 #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.
 
 /*
  *     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.
  *     @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 {
  *     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.
        
        /*
         * Options for the Postgres backend.
@@ -54,4 +60,9 @@ struct onak_config {
  */
 extern struct onak_config config;
 
  */
 extern struct onak_config config;
 
+/*
+ *     readconfig - read the onak config.
+ */
+void readconfig(void);
+
 #endif /* __ONAK_CONF_H_ */
 #endif /* __ONAK_CONF_H_ */
index 0f108f45e48f3fa1d7f980990724d843e399818b..0e3c2b5b46ba359eb778452339143e21543a160a 100755 (executable)
 use strict;
 use IPC::Open3;
 
 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
 #
 #
 # submitupdate
 #
@@ -22,7 +54,8 @@ sub submitupdate {
        my @data = @_;
        my (@errors, @mergedata);
 
        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;
 
        print MERGEIN @data;
        close MERGEIN;
@@ -40,6 +73,7 @@ my ($inheader, %syncsites, $subject, $from, $replyto, @body, @syncmail);
 
 $inheader = 1;
 $subject = "";
 
 $inheader = 1;
 $subject = "";
+&readconfig;
 
 while (<>) {
        if ($inheader) {
 
 while (<>) {
        if ($inheader) {
diff --git a/onak.c b/onak.c
index 87b65e806ade99f0bc3cfb94dedfad709333070e..8eccc9ce4472a75a07db4e4fe7f8f152234e7b1b 100644 (file)
--- 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])) {
        if ((argc - optind) < 1) {
                usage();
        } else if (!strcmp("add", argv[optind])) {