line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::DNSServer::ConfParser; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: ConfParser.pm,v 1.1 2001/05/24 04:46:01 rob Exp $ |
4
|
|
|
|
|
|
|
# This module is only used to load and parse configuration files. |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3251
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
71
|
|
7
|
1
|
|
|
1
|
|
19641
|
use IO::File; |
|
1
|
|
|
|
|
15768
|
|
|
1
|
|
|
|
|
207
|
|
8
|
1
|
|
|
1
|
|
14
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8798
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub load_configuration { |
11
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
12
|
0
|
0
|
0
|
|
|
|
unless ($self && |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
13
|
|
|
|
|
|
|
$self -> {opts_callback} && |
14
|
|
|
|
|
|
|
$self -> {zone_callback} && |
15
|
|
|
|
|
|
|
$self -> {conf_file}) { |
16
|
0
|
|
|
|
|
|
croak 'Usage> '.(__PACKAGE__).'::load_configuration {opts_callback => sub { ... }, zone_callback => sub { ... },conf_file => \$conf_file}'; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $opts_callback = $self -> {opts_callback}; |
20
|
0
|
|
|
|
|
|
my $zone_callback = $self -> {zone_callback}; |
21
|
0
|
|
|
|
|
|
my $conf_file; |
22
|
|
|
|
|
|
|
# Taint clean conf_file |
23
|
0
|
0
|
|
|
|
|
if ($self->{conf_file} =~ m%^([\w\-/\.]+)%) { |
24
|
0
|
|
|
|
|
|
$conf_file = $1; |
25
|
|
|
|
|
|
|
} else { |
26
|
0
|
|
|
|
|
|
croak "Dangerous looking configuration [$self->{conf_file}]"; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my $io = new IO::File $conf_file, "r"; |
30
|
0
|
0
|
|
|
|
|
croak "Could not open [$conf_file]" unless $io; |
31
|
0
|
|
|
|
|
|
my $CONTENTS = ""; |
32
|
|
|
|
|
|
|
# Slurp entire contents into memory for fast parsing |
33
|
0
|
|
|
|
|
|
while ($io->read($CONTENTS,4096,length $CONTENTS)) {}; |
34
|
0
|
|
|
|
|
|
$io->close(); |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
print STDERR "DEBUG: Removing comments...\n"; |
37
|
0
|
|
|
|
|
|
$CONTENTS=~s%/\*[\s\S]*?\*/%%gm; # remove /* comments */ |
38
|
0
|
|
|
|
|
|
$CONTENTS=~s%//.*$%%gm; # remove // comments |
39
|
0
|
|
|
|
|
|
$CONTENTS=~s%\#.*$%%gm; # remove # comments |
40
|
0
|
|
|
|
|
|
my %zone=(); |
41
|
0
|
|
|
|
|
|
print STDERR "DEBUG: Scanning CONTENTS...\n"; |
42
|
0
|
|
|
|
|
|
while ($CONTENTS=~/[^{}]*?(\w+.*{[^{}]*(?:{[^{}]*}[^{}]*)*};)/g) { |
43
|
0
|
|
|
|
|
|
my $entry=$1; |
44
|
|
|
|
|
|
|
# print STDERR "DEBUG: entry[$entry]\n"; |
45
|
0
|
0
|
|
|
|
|
if ($entry=~s/^\s*(\w+)\s//) { |
46
|
0
|
|
|
|
|
|
my $tag=$1; |
47
|
0
|
0
|
0
|
|
|
|
if ($tag=~/options/i && |
|
|
0
|
0
|
|
|
|
|
48
|
|
|
|
|
|
|
$entry=~s%^\{(.*)\};$%$1%s) { |
49
|
0
|
|
|
|
|
|
print STDERR "Reading options ...\n"; |
50
|
0
|
|
|
|
|
|
while ($entry=~m%\s*([\w\-]+)\s+([^{};]*?(?:{[^{}]*}[^{};]*?)*);%g) { |
51
|
0
|
|
|
|
|
|
print STDERR " -- Field=[$1] Value=[$2]\n"; |
52
|
0
|
|
|
|
|
|
&{$opts_callback}($1,$2); |
|
0
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} elsif ($tag=~/zone/i && |
55
|
|
|
|
|
|
|
$entry=~s/^\s*"*([\w\-\.]+)"*\s*([A-Z]*)\s+\{(.*)\};$/$3/s) { |
56
|
0
|
|
|
|
|
|
my $this_zone=$1; |
57
|
0
|
|
0
|
|
|
|
my $this_class=$2 || "IN"; |
58
|
0
|
|
|
|
|
|
print STDERR "Reading zone[$this_zone] class[$this_class] ...\n"; |
59
|
0
|
|
|
|
|
|
while ($entry=~m%\s*([\w\-]+)\s+([^{};]*?(?:{[^{}]*}[^{};]*?)*);%g) { |
60
|
0
|
|
|
|
|
|
print STDERR " -- Field=[$1] Value=[$2]\n"; |
61
|
0
|
|
|
|
|
|
&{$zone_callback}($this_zone,$this_class,$1,$2); |
|
0
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} else { |
64
|
0
|
|
|
|
|
|
print STDERR "Unimplemented tag [$tag] for entry:$entry\n"; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} else { |
67
|
0
|
|
|
|
|
|
print STDERR "Unrecognized syntax: $entry\n"; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return 1; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |