aboutsummaryrefslogtreecommitdiff
path: root/rpkid/rpki
diff options
context:
space:
mode:
Diffstat (limited to 'rpkid/rpki')
-rw-r--r--rpkid/rpki/__doc__.py.in26
-rw-r--r--rpkid/rpki/config.py59
-rw-r--r--rpkid/rpki/irdbd.py4
-rw-r--r--rpkid/rpki/myrpki.py8
-rw-r--r--rpkid/rpki/pubd.py4
-rw-r--r--rpkid/rpki/rootd.py4
-rw-r--r--rpkid/rpki/rpkid.py4
7 files changed, 70 insertions, 39 deletions
diff --git a/rpkid/rpki/__doc__.py.in b/rpkid/rpki/__doc__.py.in
index 7b2b280b..9576acd7 100644
--- a/rpkid/rpki/__doc__.py.in
+++ b/rpkid/rpki/__doc__.py.in
@@ -169,8 +169,8 @@
# At present the daemon programs all run in foreground, that is, the
# daemons themselves make no attempt to put themselves in background.
# The easiest way to run the servers is to run the @c start_servers
-# script, which examines your @c myrpki.conf file and starts the
-# appropriate servers in background using @c myrpki.conf as the
+# script, which examines your @c rpki.conf file and starts the
+# appropriate servers in background using @c rpki.conf as the
# configuration file for each server as well.
#
# If you prefer, you can run each server by hand instead of using the
@@ -534,18 +534,18 @@
# to the value of the @c baz variable from section @c bar. The section
# name @c ENV is special: it refers to environment variables.
#
-# @section myrpkiconf myrpki.conf
+# @section rpkiconf rpki.conf
#
-# The default name for the shared configuration file is @c myrpki.conf.
+# The default name for the shared configuration file is @c rpki.conf.
# Unless you really know what you're doing, you should start by
-# copying the @c $top/myrpki.conf from the @c rpkid/examples directory and
+# copying the @c rpki.conf from the @c rpkid/examples directory and
# modifying it, as the sample configuration file already includes all
# the additional settings necessary to use the simplified configuration.
#
-# @dontinclude myrpki.conf
+# @dontinclude rpki.conf
# @skipline [myrpki]
#
-# The @c [myrpki] section of @c myrpki.conf contains all the
+# The @c [myrpki] section of @c rpki.conf contains all the
# parameters that you really need to configure.
#
# @skip #
@@ -621,7 +621,7 @@
# underneath that name. In most cases @c publication_rsync_server
# should be the same as @c publication_rsync_server, which is what the
# macro invocation in the default setting does. @c
-# publication_base_directory, like other pathnames in @c myrpki.conf,
+# publication_base_directory, like other pathnames in @c rpki.conf,
# can be either a relative or absolute pathname; if relative, it's
# interpreted with respect to the directory in which the programs in
# question were started. In this specific case, it's probably better
@@ -664,13 +664,13 @@
# @section otherconf Other configuration files and options
#
# In most cases the simplified configuration in the @c [myrpki]
-# section of @c myrpki.conf should suffice, but in case you need to
+# section of @c rpki.conf should suffice, but in case you need to
# tinker, here are details on the the rest of the configuration
# options. In most cases the default name of the configuration file
# for a program is the name of the program followed by @c ".conf", and
# the section name is also named for the program, so that you can
# combine sections into a single configuration file as shown with @c
-# myrpki.conf.
+# rpki.conf.
#
# @li @subpage CommonOptions "Common configuration options"
#
@@ -705,7 +705,7 @@
# set up the MySQL databases they use. You can do this by hand, or
# you can use the @c sql-setup.py script, which prompts you for your
# MySQL root password then attempts to do everything else
-# automatically using values from myrpki.conf.
+# automatically using values from rpki.conf.
#
# Using the script is simple:
#
@@ -860,7 +860,7 @@
# Keep reading, and don't panic.
#
# The default configuration file name for @c myrpki is
-# @ref Configuration "@c myrpki.conf".
+# @ref Configuration "@c rpki.conf".
# You can change this using the "-c" option when invoking myrpki, or
# by setting the environment variable MYRPKI_CONF.
#
@@ -888,7 +888,7 @@
#
# The steps needed during setup phase are:
#
-# @li Write a configuration file (copy $top/rpkid/examples/myrpki.conf
+# @li Write a configuration file (copy $top/rpkid/examples/rpki.conf
# and edit as needed). You need to configure the @c [myrpki] section;
# in theory, the rest of the file should be ok as it is, at least for
# simple use. You also need to create (either by hand or by dumping
diff --git a/rpkid/rpki/config.py b/rpkid/rpki/config.py
index 2bdc160c..59ac6efd 100644
--- a/rpkid/rpki/config.py
+++ b/rpkid/rpki/config.py
@@ -35,6 +35,23 @@ PERFORMANCE OF THIS SOFTWARE.
import ConfigParser, os, re
+## @var default_filename
+# Default name of config file if caller doesn't specify one explictly.
+
+default_filename = "rpki.conf"
+
+## @var default_dirname
+# Default name of directory to check for global config file, or None
+# if no global config file. Autoconf-generated code may set this to a
+# non-None value during script startup.
+
+default_dirname = None
+
+## @var default_envname
+# Name of environment variable containing config file name.
+
+default_envname = "RPKI_CONF"
+
class parser(object):
"""
Extensions to stock Python ConfigParser:
@@ -45,22 +62,44 @@ class parser(object):
OpenSSL-style indirect variable references (${section::option}).
get-methods with default values and default section name.
+
+ If no filename is given to the constructor (filename = None), we
+ check for an environment variable naming the config file, then we
+ check for a default filename in the current directory, then finally
+ we check for a global config file if autoconf provided a directory
+ name to check.
"""
- def __init__(self, filename, section = None, allow_missing = False):
- """
- Initialize this parser.
- """
+ def __init__(self, filename = None, section = None, allow_missing = False):
- self.filename = filename
self.cfg = ConfigParser.RawConfigParser()
- try:
- self.cfg.readfp(open(filename), filename)
- except IOError:
- if not allow_missing:
- raise
self.default_section = section
+ filenames = []
+ if filename is not None:
+ filenames.append(filename)
+ else:
+ if default_envname in os.environ:
+ filenames.append(os.environ[default_envname])
+ filenames.append(default_filename)
+ if default_dirname is not None:
+ filenames.append("%s/%s" % (default_dirname, default_filename))
+
+ for fn in filenames:
+ try:
+ f = open(fn)
+ break
+ except IOError:
+ f = None
+
+ if f is not None:
+ self.filename = fn
+ self.cfg.readfp(f, fn)
+ elif allow_missing:
+ self.filename = None
+ else:
+ raise
+
def has_section(self, section):
"""
Test whether a section exists.
diff --git a/rpkid/rpki/irdbd.py b/rpkid/rpki/irdbd.py
index a90f71ce..b5edf70e 100644
--- a/rpkid/rpki/irdbd.py
+++ b/rpkid/rpki/irdbd.py
@@ -3,8 +3,6 @@ IR database daemon.
Usage: python irdbd.py [ { -c | --config } configfile ] [ { -h | --help } ]
-Default configuration file is irdbd.conf, override with --config option.
-
$Id$
Copyright (C) 2009--2010 Internet Systems Consortium ("ISC")
@@ -175,7 +173,7 @@ class main(object):
os.environ["TZ"] = "UTC"
time.tzset()
- cfg_file = "irdbd.conf"
+ cfg_file = None
opts, argv = getopt.getopt(sys.argv[1:], "c:dh?", ["config=", "debug", "help"])
for o, a in opts:
diff --git a/rpkid/rpki/myrpki.py b/rpkid/rpki/myrpki.py
index 136a41d1..dc375357 100644
--- a/rpkid/rpki/myrpki.py
+++ b/rpkid/rpki/myrpki.py
@@ -899,7 +899,7 @@ class main(rpki.cli.Cmd):
rpki.log.use_syslog = False
- self.cfg_file = os.getenv("MYRPKI_CONF", "myrpki.conf")
+ self.cfg_file = None
opts, argv = getopt.getopt(sys.argv[1:], "c:h?", ["config=", "help"])
for o, a in opts:
@@ -950,9 +950,9 @@ class main(rpki.cli.Cmd):
if self.run_rootd and (not self.run_pubd or not self.run_rpkid):
raise RuntimeError, "Can't run rootd unless also running rpkid and pubd"
- self.bpki_resources = CA(self.cfg_file, self.cfg.get("bpki_resources_directory"))
+ self.bpki_resources = CA(self.cfg.filename, self.cfg.get("bpki_resources_directory"))
if self.run_rpkid or self.run_pubd or self.run_rootd:
- self.bpki_servers = CA(self.cfg_file, self.cfg.get("bpki_servers_directory"))
+ self.bpki_servers = CA(self.cfg.filename, self.cfg.get("bpki_servers_directory"))
self.pubd_contact_info = self.cfg.get("pubd_contact_info", "")
@@ -1560,7 +1560,7 @@ class main(rpki.cli.Cmd):
action = "set",
bpki_crl = rpki.x509.CRL(PEM_file = self.bpki_servers.crl)))
- irdbd_cfg = rpki.config.parser(self.cfg.get("irdbd_conf", self.cfg_file), "irdbd")
+ irdbd_cfg = rpki.config.parser(self.cfg.get("irdbd_conf", self.cfg.filename), "irdbd")
db = MySQLdb.connect(user = irdbd_cfg.get("sql-username"),
db = irdbd_cfg.get("sql-database"),
diff --git a/rpkid/rpki/pubd.py b/rpkid/rpki/pubd.py
index c842b6c6..0fd4b713 100644
--- a/rpkid/rpki/pubd.py
+++ b/rpkid/rpki/pubd.py
@@ -5,8 +5,6 @@ Usage: python pubd.py [ { -c | --config } configfile ]
[ { -h | --help } ]
[ { -p | --profile } outputfile ]
-Default configuration file is pubd.conf, override with --config option.
-
$Id$
Copyright (C) 2009--2010 Internet Systems Consortium ("ISC")
@@ -53,7 +51,7 @@ class main(object):
os.environ["TZ"] = "UTC"
time.tzset()
- self.cfg_file = "pubd.conf"
+ self.cfg_file = None
self.profile = False
opts, argv = getopt.getopt(sys.argv[1:], "c:dhp:?", ["config=", "debug", "help"])
diff --git a/rpkid/rpki/rootd.py b/rpkid/rpki/rootd.py
index 74674b57..9a8620a1 100644
--- a/rpkid/rpki/rootd.py
+++ b/rpkid/rpki/rootd.py
@@ -5,8 +5,6 @@ rpki.* classes in order to reuse as much code as possible.
Usage: python rootd.py [ { -c | --config } configfile ] [ { -h | --help } ]
-Default configuration file is rootd.conf, override with --config option.
-
$Id$
Copyright (C) 2009--2010 Internet Systems Consortium ("ISC")
@@ -269,7 +267,7 @@ class main(object):
os.environ["TZ"] = "UTC"
time.tzset()
- self.cfg_file = "rootd.conf"
+ self.cfg_file = None
opts, argv = getopt.getopt(sys.argv[1:], "c:dh?", ["config=", "debug", "help"])
for o, a in opts:
diff --git a/rpkid/rpki/rpkid.py b/rpkid/rpki/rpkid.py
index 927e1456..f36e3ee1 100644
--- a/rpkid/rpki/rpkid.py
+++ b/rpkid/rpki/rpkid.py
@@ -5,8 +5,6 @@ Usage: python rpkid.py [ { -c | --config } configfile ]
[ { -h | --help } ]
[ { -p | --profile } outputfile ]
-Default configuration file is rpkid.conf, override with --config option.
-
$Id$
Copyright (C) 2009--2010 Internet Systems Consortium ("ISC")
@@ -56,7 +54,7 @@ class main(object):
os.environ["TZ"] = "UTC"
time.tzset()
- self.cfg_file = "rpkid.conf"
+ self.cfg_file = None
self.profile = None
opts, argv = getopt.getopt(sys.argv[1:], "c:dhp:?", ["config=", "debug", "help", "profile="])