Changeset 400 for trunk


Ignore:
Timestamp:
10/03/12 18:02:56 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Normalize calling convention in loadConfig() and cfgload() to
prepare for updates in dns-rpc.cgi. (Good thing nothing else
has needed to pass any arguments to it yet.)
Extend configuration parser to support rpc* options such as rpc_iplist
to restrict which IPs can make RPC calls for which calling serivce.
See #43.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r399 r400  
    11981198# Load the minimum required initial state (DB connect info) from a config file
    11991199# Load misc other bits while we're at it.
    1200 # Takes an optional basename and config path to look for
     1200# Takes an optional hash that may contain:
     1201#  - basename and config path to look for
     1202#  - RPC flag (saves parsing the more complex RPC bits if not needed)
    12011203# Populates the %config and %def hashes
    12021204sub loadConfig {
    1203   my $basename = shift || '';   # this will work OK
    1204 ##fixme  $basename isn't doing what I think I thought I was trying to do.
     1205  my %args = @_;
     1206  $args{basename} = '' if !$args{basename};
     1207  $args{rpcflag} = '' if !$args{rpcflag};
     1208##fixme  $args{basename} isn't doing what I think I thought I was trying to do.
    12051209
    12061210  my $deferr = '';      # place to put error from default config file in case we can't find either one
    12071211
    12081212  my $configroot = "/etc/dnsdb";        ##CFG_LEAF##
    1209   $configroot = '' if $basename =~ m|^/|;
    1210   $basename .= ".conf" if $basename !~ /\.conf$/;
     1213  $configroot = '' if $args{basename} =~ m|^/|;
     1214  $args{basename} .= ".conf" if $args{basename} !~ /\.conf$/;
    12111215  my $defconfig = "$configroot/dnsdb.conf";
    1212   my $siteconfig = "$configroot/$basename";
     1216  my $siteconfig = "$configroot/$args{basename}";
    12131217
    12141218  # System defaults
    1215   __cfgload("$defconfig") or $deferr = $errstr;
     1219  __cfgload("$defconfig", $args{rpcflag}) or $deferr = $errstr;
    12161220
    12171221  # Per-site-ish settings.
    1218   if ($basename ne '.conf') {
    1219     unless (__cfgload("$siteconfig")) {
     1222  if ($args{basename} ne '.conf') {
     1223    unless (__cfgload("$siteconfig"), $args{rpcflag}) {
    12201224      $errstr = ($deferr ? "Error opening default config file $defconfig: $deferr\n" : '').
    12211225        "Error opening site config file $siteconfig";
     
    12531257  $errstr = '';
    12541258  my $cfgfile = shift;
     1259  my $rpcflag = shift;
    12551260
    12561261  if (open CFG, "<$cfgfile") {
     
    12901295      $config{perpage}          = $1 if /^perpage\s*=\s*(\d+)/i;
    12911296      $config{exportcache}      = $1 if m{^exportcache\s*=\s*([a-z0-9/_.-]+)}i;
     1297      # RPC options
     1298      if ($rpcflag && /^rpc/) {
     1299        if (my ($tmp) = /^rpc_iplist\s*=\s*(.+)/i) {
     1300          my @ips = split /[,\s]+/, $tmp;
     1301          my $rpcsys = shift @ips;
     1302          push @{$config{rpcacl}{$rpcsys}}, @ips;
     1303        }
     1304      }
    12921305    }
    12931306    close CFG;
Note: See TracChangeset for help on using the changeset viewer.