dnsruby 1.55 → 1.56.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +96 -0
- data/Rakefile +30 -29
- data/demo/axfr.rb +93 -93
- data/demo/check_soa.rb +99 -99
- data/demo/check_zone.rb +59 -59
- data/demo/digdlv.rb +43 -43
- data/demo/digroot.rb +34 -34
- data/demo/example_recurse.rb +14 -14
- data/demo/mresolv.rb +30 -30
- data/demo/mx.rb +31 -31
- data/demo/rubydig.rb +37 -37
- data/demo/to_resolve.txt +3088 -3088
- data/demo/trace_dns.rb +46 -46
- data/lib/dnsruby.rb +161 -526
- data/lib/dnsruby/DNS.rb +305 -0
- data/lib/{Dnsruby/Cache.rb → dnsruby/cache.rb} +152 -152
- data/lib/{Dnsruby → dnsruby}/code_mapper.rb +48 -52
- data/lib/dnsruby/code_mappers.rb +295 -0
- data/lib/{Dnsruby/Config.rb → dnsruby/config.rb} +454 -454
- data/lib/{Dnsruby → dnsruby}/dnssec.rb +91 -91
- data/lib/{Dnsruby/Hosts.rb → dnsruby/hosts.rb} +125 -125
- data/lib/{Dnsruby → dnsruby}/ipv4.rb +26 -26
- data/lib/{Dnsruby → dnsruby}/ipv6.rb +42 -42
- data/lib/{Dnsruby → dnsruby}/key_cache.rb +29 -29
- data/lib/dnsruby/message/decoder.rb +164 -0
- data/lib/dnsruby/message/encoder.rb +75 -0
- data/lib/dnsruby/message/header.rb +249 -0
- data/lib/dnsruby/message/message.rb +629 -0
- data/lib/dnsruby/message/question.rb +86 -0
- data/lib/dnsruby/message/section.rb +96 -0
- data/lib/{Dnsruby → dnsruby}/name.rb +141 -141
- data/lib/dnsruby/packet_sender.rb +661 -0
- data/lib/{Dnsruby/Recursor.rb → dnsruby/recursor.rb} +235 -233
- data/lib/dnsruby/resolv.rb +113 -0
- data/lib/dnsruby/resolver.rb +1192 -0
- data/lib/dnsruby/resource/A.rb +56 -0
- data/lib/dnsruby/resource/AAAA.rb +54 -0
- data/lib/{Dnsruby → dnsruby}/resource/AFSDB.rb +68 -68
- data/lib/{Dnsruby → dnsruby}/resource/CERT.rb +105 -105
- data/lib/{Dnsruby → dnsruby}/resource/DHCID.rb +54 -54
- data/lib/dnsruby/resource/DLV.rb +27 -0
- data/lib/{Dnsruby → dnsruby}/resource/DNSKEY.rb +372 -372
- data/lib/{Dnsruby → dnsruby}/resource/DS.rb +255 -255
- data/lib/{Dnsruby → dnsruby}/resource/HINFO.rb +71 -71
- data/lib/{Dnsruby → dnsruby}/resource/HIP.rb +29 -29
- data/lib/{Dnsruby → dnsruby}/resource/IN.rb +30 -30
- data/lib/{Dnsruby → dnsruby}/resource/IPSECKEY.rb +31 -31
- data/lib/{Dnsruby → dnsruby}/resource/ISDN.rb +62 -62
- data/lib/{Dnsruby → dnsruby}/resource/KX.rb +65 -65
- data/lib/{Dnsruby → dnsruby}/resource/LOC.rb +263 -263
- data/lib/{Dnsruby → dnsruby}/resource/MINFO.rb +69 -69
- data/lib/{Dnsruby → dnsruby}/resource/MX.rb +65 -65
- data/lib/{Dnsruby → dnsruby}/resource/NAPTR.rb +98 -98
- data/lib/{Dnsruby → dnsruby}/resource/NSAP.rb +171 -171
- data/lib/dnsruby/resource/NSEC.rb +275 -0
- data/lib/dnsruby/resource/NSEC3.rb +332 -0
- data/lib/dnsruby/resource/NSEC3PARAM.rb +135 -0
- data/lib/dnsruby/resource/OPT.rb +272 -0
- data/lib/{Dnsruby → dnsruby}/resource/PX.rb +70 -70
- data/lib/{Dnsruby → dnsruby}/resource/RP.rb +75 -75
- data/lib/dnsruby/resource/RR.rb +421 -0
- data/lib/dnsruby/resource/RRSIG.rb +275 -0
- data/lib/dnsruby/resource/RRSet.rb +190 -0
- data/lib/{Dnsruby → dnsruby}/resource/RT.rb +67 -67
- data/lib/{Dnsruby → dnsruby}/resource/SOA.rb +94 -94
- data/lib/dnsruby/resource/SPF.rb +29 -0
- data/lib/dnsruby/resource/SRV.rb +112 -0
- data/lib/{Dnsruby → dnsruby}/resource/SSHFP.rb +14 -14
- data/lib/dnsruby/resource/TKEY.rb +163 -0
- data/lib/dnsruby/resource/TSIG.rb +593 -0
- data/lib/{Dnsruby → dnsruby}/resource/TXT.rb +191 -191
- data/lib/dnsruby/resource/X25.rb +55 -0
- data/lib/{Dnsruby → dnsruby}/resource/domain_name.rb +25 -25
- data/lib/{Dnsruby → dnsruby}/resource/generic.rb +80 -80
- data/lib/dnsruby/resource/resource.rb +25 -0
- data/lib/{Dnsruby → dnsruby}/select_thread.rb +148 -148
- data/lib/{Dnsruby/SingleResolver.rb → dnsruby/single_resolver.rb} +60 -60
- data/lib/{Dnsruby → dnsruby}/single_verifier.rb +344 -344
- data/lib/dnsruby/the_log.rb +44 -0
- data/lib/dnsruby/update.rb +278 -0
- data/lib/dnsruby/validator_thread.rb +124 -0
- data/lib/dnsruby/version.rb +3 -0
- data/lib/{Dnsruby → dnsruby}/zone_reader.rb +93 -93
- data/lib/{Dnsruby → dnsruby}/zone_transfer.rb +377 -377
- data/test/spec_helper.rb +16 -0
- data/test/tc_axfr.rb +31 -34
- data/test/tc_cache.rb +32 -32
- data/test/tc_dlv.rb +28 -28
- data/test/tc_dns.rb +73 -76
- data/test/tc_dnskey.rb +31 -32
- data/test/tc_dnsruby.rb +50 -44
- data/test/tc_ds.rb +36 -36
- data/test/tc_escapedchars.rb +252 -255
- data/test/tc_hash.rb +17 -21
- data/test/tc_header.rb +48 -57
- data/test/tc_hip.rb +19 -22
- data/test/tc_ipseckey.rb +18 -21
- data/test/tc_keith.rb +300 -0
- data/test/tc_message.rb +87 -0
- data/test/tc_misc.rb +83 -87
- data/test/tc_name.rb +81 -84
- data/test/tc_naptr.rb +18 -21
- data/test/tc_nsec.rb +55 -55
- data/test/tc_nsec3.rb +23 -24
- data/test/tc_nsec3param.rb +20 -21
- data/test/tc_packet.rb +90 -93
- data/test/tc_packet_unique_push.rb +48 -51
- data/test/tc_question.rb +30 -33
- data/test/tc_queue.rb +16 -17
- data/test/tc_recur.rb +16 -17
- data/test/tc_res_config.rb +38 -41
- data/test/tc_res_env.rb +29 -32
- data/test/tc_res_file.rb +26 -29
- data/test/tc_res_opt.rb +62 -65
- data/test/tc_resolver.rb +287 -242
- data/test/tc_rr-opt.rb +70 -63
- data/test/tc_rr-txt.rb +68 -71
- data/test/tc_rr-unknown.rb +45 -48
- data/test/tc_rr.rb +76 -70
- data/test/tc_rrset.rb +21 -22
- data/test/tc_rrsig.rb +19 -20
- data/test/tc_single_resolver.rb +294 -297
- data/test/tc_soak.rb +199 -202
- data/test/tc_soak_base.rb +29 -34
- data/test/tc_sshfp.rb +20 -23
- data/test/tc_tcp.rb +32 -35
- data/test/tc_tkey.rb +41 -44
- data/test/tc_tsig.rb +81 -84
- data/test/tc_update.rb +108 -111
- data/test/tc_validator.rb +29 -29
- data/test/tc_verifier.rb +81 -82
- data/test/ts_dnsruby.rb +16 -15
- data/test/ts_offline.rb +62 -63
- data/test/ts_online.rb +115 -115
- metadata +155 -90
- data/README +0 -59
- data/lib/Dnsruby/DNS.rb +0 -305
- data/lib/Dnsruby/PacketSender.rb +0 -656
- data/lib/Dnsruby/Resolver.rb +0 -1189
- data/lib/Dnsruby/TheLog.rb +0 -44
- data/lib/Dnsruby/message.rb +0 -1230
- data/lib/Dnsruby/resource/A.rb +0 -56
- data/lib/Dnsruby/resource/AAAA.rb +0 -54
- data/lib/Dnsruby/resource/DLV.rb +0 -27
- data/lib/Dnsruby/resource/NSEC.rb +0 -298
- data/lib/Dnsruby/resource/NSEC3.rb +0 -340
- data/lib/Dnsruby/resource/NSEC3PARAM.rb +0 -135
- data/lib/Dnsruby/resource/OPT.rb +0 -213
- data/lib/Dnsruby/resource/RRSIG.rb +0 -275
- data/lib/Dnsruby/resource/SPF.rb +0 -29
- data/lib/Dnsruby/resource/SRV.rb +0 -112
- data/lib/Dnsruby/resource/TKEY.rb +0 -163
- data/lib/Dnsruby/resource/TSIG.rb +0 -593
- data/lib/Dnsruby/resource/X25.rb +0 -55
- data/lib/Dnsruby/resource/resource.rb +0 -678
- data/lib/Dnsruby/update.rb +0 -278
- data/lib/Dnsruby/validator_thread.rb +0 -124
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d4002c20d43d7fa849e81970e596e8b191a9290
|
4
|
+
data.tar.gz: b1ebd40548471fd16a12616d3c834b9c30a8a26e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f3f304b2f3ea1df07a0a24854e20a003f16964840800dae9ad574318369095ebec119ce7f074a3658564c530a84ec2f6a6a9a2b8fa2721aa4e6f329f982d6c3
|
7
|
+
data.tar.gz: ab251ceaffa37db6a13eb2b7064c8cf16babdf15d75ef79d91de1e2140a7552b1759cb34f6d051bc649242396bce9edeadc758f51231a02be69788e55b036b44
|
data/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/alexdalitz/dnsruby.svg?branch=master)](https://travis-ci.org/alexdalitz/dnsruby)
|
2
|
+
[![Coverage Status](https://img.shields.io/coveralls/alexdalitz/dnsruby.svg)](https://coveralls.io/r/alexdalitz/dnsruby?branch=master)
|
3
|
+
|
4
|
+
Dnsruby
|
5
|
+
=======
|
6
|
+
|
7
|
+
Dnsruby is a pure Ruby DNS client library which implements a
|
8
|
+
stub resolver. It aims to comply with all DNS RFCs, including
|
9
|
+
DNSSEC NSEC3 support.
|
10
|
+
|
11
|
+
Dnsruby presents an enhanced API for DNS. It is based on Ruby's core
|
12
|
+
resolv.rb Resolv API, but has been much extended to provide a
|
13
|
+
complete DNS implementation.
|
14
|
+
|
15
|
+
Dnsruby runs a single I/O thread to handle all concurrent
|
16
|
+
queries. It is therefore suitable for high volume DNS applications.
|
17
|
+
|
18
|
+
The following is a (non-exhaustive) list of features :
|
19
|
+
|
20
|
+
- Implemented RRs : A, AAAA, AFSDB, ANY, CERT, CNAME, DNAME,
|
21
|
+
HINFO, ISDN, LOC, MB, MG, MINFO, MR, MX, NAPTR, NS, NSAP,
|
22
|
+
OPT, PTR, PX, RP, RT, SOA, SPF, SRV, TKEY, TSIG, TXT, WKS,
|
23
|
+
X25, DNSKEY, RRSIG, NSEC, NSEC3, NSEC3PARAM, DS, DLV
|
24
|
+
|
25
|
+
- Generic RR types supported (RFC3597)
|
26
|
+
|
27
|
+
- (Signed) Zone transfer (AXFR and IXFR) supported
|
28
|
+
|
29
|
+
- (Signed) Dynamic updates supported
|
30
|
+
|
31
|
+
- DNSSEC validation supported
|
32
|
+
|
33
|
+
Dependencies
|
34
|
+
------------
|
35
|
+
|
36
|
+
Dnsruby can run with no dependencies. However, if you wish to
|
37
|
+
use TSIG or DNSSEC then the OpenSSL library must be available.
|
38
|
+
This is a part of the Ruby standard library, but appears not to
|
39
|
+
be present on all Ruby platforms. If it is not available, then
|
40
|
+
the test code will not run the tests which require it. Code which
|
41
|
+
attempts to use the library (if it is not present) will raise an
|
42
|
+
exception.
|
43
|
+
|
44
|
+
Demo Code
|
45
|
+
---------
|
46
|
+
|
47
|
+
The demo folder contains some example programs using Dnsruby.
|
48
|
+
These examples include a basic dig tool (rubydig) and a tool to
|
49
|
+
concurrently resolve many names, amongst others.
|
50
|
+
|
51
|
+
Unit Tests
|
52
|
+
----------
|
53
|
+
|
54
|
+
Tests require a current version of minitest (see the .gemspec file
|
55
|
+
for which version is required). In order for the tests to run
|
56
|
+
successfully you may need to have the bundler gem installed and
|
57
|
+
run `bundle` or `bundle install` from the project root to install
|
58
|
+
a suitable version of minitest.
|
59
|
+
|
60
|
+
There are "online" and "offline" tests. You can use rake to
|
61
|
+
conveniently run the tests. From the project root you can run:
|
62
|
+
```
|
63
|
+
rake test # run all tests
|
64
|
+
rake test_offline # run only offline tests
|
65
|
+
rake test_online # run only online tests
|
66
|
+
```
|
67
|
+
If you get the following error when running rake test tasks,
|
68
|
+
then you may need to preface the command with bundle exec to
|
69
|
+
ensure that the gem versions specified in Gemfile.lock are used
|
70
|
+
at runtime:
|
71
|
+
|
72
|
+
```
|
73
|
+
bundle exec rake test
|
74
|
+
```
|
75
|
+
|
76
|
+
Nominet operates a test server which the Dnsruby test code queries.
|
77
|
+
If this server is not available then some of the online tests will
|
78
|
+
not be run.
|
79
|
+
|
80
|
+
|
81
|
+
Usage Help
|
82
|
+
----------
|
83
|
+
|
84
|
+
There are a couple of blog articles that might be helpful
|
85
|
+
in understanding how to use Dnsruby:
|
86
|
+
|
87
|
+
* http://blog.nominet.org.uk/tech/2009/05/19/some-examples-of-dnsruby-in-action/
|
88
|
+
* http://blog.nominet.org.uk/tech/2009/05/21/examples-of-using-dnsruby-with-dnssec/
|
89
|
+
|
90
|
+
|
91
|
+
Contact
|
92
|
+
-------
|
93
|
+
|
94
|
+
alex@caerkettontech.com
|
95
|
+
https://github.com/alexdalitz/dnsruby
|
96
|
+
|
data/Rakefile
CHANGED
@@ -1,29 +1,30 @@
|
|
1
|
-
require 'rake/testtask'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
1
|
+
require 'rake/testtask'
|
2
|
+
|
3
|
+
ENV['RUN_EXTRA_TASK'] = 'TRUE' if
|
4
|
+
RUBY_VERSION >= "1.9.3" && defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ruby'
|
5
|
+
|
6
|
+
if ENV['RUN_EXTRA_TASK'] == 'TRUE'
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
Rake::RDocTask.new do |rd|
|
10
|
+
rd.rdoc_files.include("lib/**/*.rb")
|
11
|
+
rd.rdoc_files.exclude("lib/Dnsruby/iana_ports.rb")
|
12
|
+
rd.main = "Dnsruby"
|
13
|
+
# rd.options << "--ri"
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'coveralls/rake/task'
|
17
|
+
Coveralls::RakeTask.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_task(task_name, test_suite_filespec)
|
21
|
+
Rake::TestTask.new do |t|
|
22
|
+
t.name = task_name
|
23
|
+
t.test_files = FileList[test_suite_filespec]
|
24
|
+
t.verbose = true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
create_task(:test, 'test/ts_dnsruby.rb')
|
29
|
+
create_task(:test_offline, 'test/ts_offline.rb')
|
30
|
+
create_task(:test_online, 'test/ts_online.rb')
|
data/demo/axfr.rb
CHANGED
@@ -1,80 +1,80 @@
|
|
1
|
-
|
2
|
-
#Copyright 2007 Nominet UK
|
3
|
-
#
|
4
|
-
#Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
#you may not use this file except in compliance with the License.
|
6
|
-
#You may obtain a copy of the License at
|
7
|
-
#
|
1
|
+
# --
|
2
|
+
# Copyright 2007 Nominet UK
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
8
|
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
#Unless required by applicable law or agreed to in writing, software
|
11
|
-
#distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
#See the License for the specific language governing permissions and
|
14
|
-
#limitations under the License.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
#
|
19
|
-
#axfr - Perform a DNS zone transfer
|
20
|
-
#
|
21
|
-
|
22
|
-
#
|
23
|
-
#axfr [ -fqs ] [ -D directory ] [ @nameserver ] zone
|
24
|
-
#
|
25
|
-
|
26
|
-
#
|
27
|
-
#axfr performs a DNS zone transfer, prints each record to the standard
|
28
|
-
#output, and stores the zone to a file. If the zone has already been
|
29
|
-
#stored in a file, axfr will read the file instead of performing a
|
30
|
-
#zone transfer.
|
31
|
-
#
|
32
|
-
#Zones will be stored in a directory hierarchy. For example, the
|
33
|
-
#zone transfer for foo.bar.com will be stored in the file
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
# ++
|
16
|
+
|
17
|
+
# = NAME
|
18
|
+
#
|
19
|
+
# axfr - Perform a DNS zone transfer
|
20
|
+
#
|
21
|
+
# = SYNOPSIS
|
22
|
+
#
|
23
|
+
# axfr [ -fqs ] [ -D directory ] [ @nameserver ] zone
|
24
|
+
#
|
25
|
+
# = DESCRIPTION
|
26
|
+
#
|
27
|
+
# axfr performs a DNS zone transfer, prints each record to the standard
|
28
|
+
# output, and stores the zone to a file. If the zone has already been
|
29
|
+
# stored in a file, axfr will read the file instead of performing a
|
30
|
+
# zone transfer.
|
31
|
+
#
|
32
|
+
# Zones will be stored in a directory hierarchy. For example, the
|
33
|
+
# zone transfer for foo.bar.com will be stored in the file
|
34
34
|
# HOME/.dns-zones/com/bar/foo/axfr. The directory can be changed
|
35
35
|
# with the B<-D> option.
|
36
|
-
#
|
36
|
+
#
|
37
37
|
# This programs requires that the Storable module be installed.
|
38
|
-
#
|
39
|
-
|
40
|
-
#
|
38
|
+
#
|
39
|
+
# = OPTIONS
|
40
|
+
#
|
41
41
|
# * -f Force a zone transfer, even if the zone has already been stored
|
42
42
|
# in a file.
|
43
|
-
#
|
43
|
+
#
|
44
44
|
# * -q Be quiet -- don't print the records from the zone.
|
45
|
-
#
|
45
|
+
#
|
46
46
|
# * -s Perform a zone transfer if the SOA serial number on the nameserver
|
47
47
|
# is different than the serial number in the zone file.
|
48
|
-
#
|
48
|
+
#
|
49
49
|
# * -D directory Store zone files under I<directory> instead of the default directory (see "FILES")
|
50
|
-
#
|
50
|
+
#
|
51
51
|
# * nameserver Query nameserver instead of the default nameserver.
|
52
|
-
#
|
53
|
-
|
54
|
-
#
|
52
|
+
#
|
53
|
+
# = FILES
|
54
|
+
#
|
55
55
|
# * ${HOME}/.dns-zones Default directory for storing zone files.
|
56
|
-
#
|
57
|
-
|
58
|
-
#
|
56
|
+
#
|
57
|
+
# = AUTHOR
|
58
|
+
#
|
59
59
|
# Michael Fuhr <mike@fuhr.org>
|
60
|
-
#
|
60
|
+
#
|
61
61
|
|
62
62
|
require 'getoptLong'
|
63
63
|
require 'dnsruby'
|
64
64
|
|
65
|
-
|
65
|
+
# ------------------------------------------------------------------------------
|
66
66
|
# Read any command-line options and check syntax.
|
67
|
-
|
67
|
+
# ------------------------------------------------------------------------------
|
68
68
|
|
69
|
-
#getopts("fqsD:");
|
69
|
+
# getopts("fqsD:");
|
70
70
|
opts = GetoptLong.new(["-f", GetoptLong::NO_ARGUMENT],
|
71
71
|
["-q", GetoptLong::NO_ARGUMENT],
|
72
72
|
["-D", GetoptLong::REQUIRED_ARGUMENT],
|
73
73
|
["-s", GetoptLong::NO_ARGUMENT])
|
74
74
|
|
75
75
|
opt_q = false
|
76
|
-
opt_f = false
|
77
|
-
opt_s = false
|
76
|
+
opt_f = false
|
77
|
+
opt_s = false
|
78
78
|
opt_d = nil
|
79
79
|
opts.each do |opt, arg|
|
80
80
|
case opt
|
@@ -90,13 +90,13 @@ opts.each do |opt, arg|
|
|
90
90
|
end
|
91
91
|
|
92
92
|
if (ARGV.length < 1) || (ARGV.length > 2)
|
93
|
-
print "Usage: #{$0} [ -fqs ] [ -D directory ] [ @nameserver ] zone\n"
|
93
|
+
print "Usage: #{$0} [ -fqs ] [ -D directory ] [ @nameserver ] zone\n"
|
94
94
|
else
|
95
|
-
|
96
|
-
#
|
97
|
-
#
|
98
|
-
|
99
|
-
|
95
|
+
# ------------------------------------------------------------------------------
|
96
|
+
# Get the nameserver (if specified) and set up the zone transfer directory
|
97
|
+
# hierarchy.
|
98
|
+
# ------------------------------------------------------------------------------
|
99
|
+
|
100
100
|
nameserver = (ARGV[0] =~ /^@/) ? ARGV.shift : ""
|
101
101
|
nameserver = nameserver.sub(/^@/, "")
|
102
102
|
res = nil
|
@@ -105,18 +105,18 @@ else
|
|
105
105
|
else
|
106
106
|
res = Dnsruby::Resolver.new
|
107
107
|
end
|
108
|
-
|
109
|
-
zone = ARGV.shift
|
108
|
+
|
109
|
+
zone = ARGV.shift
|
110
110
|
basedir = opt_d!=nil ? opt_d : (ENV["HOME"]!=nil ? ENV["HOME"] : "") + "/.dns-zones"
|
111
111
|
zonedir = zone.split(/\./).reverse.join("/")
|
112
112
|
zonefile = basedir + "/" + zonedir + "/axfr"
|
113
|
-
|
114
|
-
#
|
115
|
-
#
|
116
|
-
if !(FileTest.directory?basedir)
|
113
|
+
|
114
|
+
# Don't worry about the 0777 permissions here - the current umask setting
|
115
|
+
# will be applied.
|
116
|
+
if !(FileTest.directory?basedir)
|
117
117
|
Dir.mkdir(basedir, 0777) or raise RuntimeError, "can't mkdir #{basedir}: #{$!}\n"
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
dir = basedir
|
121
121
|
zonedir.split("/").each do |subdir|
|
122
122
|
dir += "/" + subdir
|
@@ -124,26 +124,26 @@ else
|
|
124
124
|
Dir.mkdir(dir, 0777) or raise RuntimeError, "can't mkdir #{dir}: #{$!}\n"
|
125
125
|
end
|
126
126
|
end
|
127
|
-
|
128
|
-
|
129
|
-
#
|
130
|
-
|
131
|
-
|
127
|
+
|
128
|
+
# ------------------------------------------------------------------------------
|
129
|
+
# Get the zone.
|
130
|
+
# ------------------------------------------------------------------------------
|
131
|
+
|
132
132
|
zonearray = nil
|
133
|
-
|
133
|
+
|
134
134
|
if (FileTest.exist?(zonefile) && !opt_f)
|
135
135
|
zoneref = Marshal.load(File.open(zonefile))
|
136
136
|
if (zoneref==nil)
|
137
137
|
raise RuntimeError, "couldn't retrieve zone from #{zonefile}: #{$!}\n"
|
138
138
|
end
|
139
|
-
|
140
|
-
|
141
|
-
#
|
142
|
-
|
143
|
-
|
139
|
+
|
140
|
+
# ----------------------------------------------------------------------
|
141
|
+
# Check the SOA serial number if desired.
|
142
|
+
# ----------------------------------------------------------------------
|
143
|
+
|
144
144
|
if (opt_s)
|
145
145
|
serial_file, serial_zone = nil
|
146
|
-
|
146
|
+
|
147
147
|
zoneref.each do |rr|
|
148
148
|
if (rr.type == "SOA")
|
149
149
|
serial_file = rr.serial
|
@@ -151,48 +151,48 @@ else
|
|
151
151
|
end
|
152
152
|
end
|
153
153
|
if serial_file==nil
|
154
|
-
raise RuntimeError, "no SOA in #{zonefile}\n"
|
154
|
+
raise RuntimeError, "no SOA in #{zonefile}\n"
|
155
155
|
end
|
156
|
-
|
156
|
+
|
157
157
|
soa = res.query(zone, "SOA")
|
158
158
|
if soa==nil
|
159
|
-
raise RuntimeError, "couldn't get SOA for #{zone}: " + res.errorstring + "\n"
|
159
|
+
raise RuntimeError, "couldn't get SOA for #{zone}: " + res.errorstring + "\n"
|
160
160
|
end
|
161
|
-
|
161
|
+
|
162
162
|
soa.answer.each do |rr|
|
163
163
|
if (rr.type == "SOA")
|
164
164
|
serial_zone = rr.serial
|
165
165
|
break
|
166
166
|
end
|
167
167
|
end
|
168
|
-
|
168
|
+
|
169
169
|
if (serial_zone != serial_file)
|
170
170
|
opt_f = true
|
171
171
|
end
|
172
|
-
end
|
172
|
+
end
|
173
173
|
else
|
174
174
|
opt_f = true
|
175
175
|
end
|
176
|
-
|
176
|
+
|
177
177
|
if (opt_f)
|
178
178
|
print "nameserver = #{nameserver}, zone=#{zone}"
|
179
179
|
zt = Dnsruby::ZoneTransfer.new
|
180
180
|
zt.server=(nameserver) if nameserver!=""
|
181
|
-
|
181
|
+
|
182
182
|
zoneref = zt.transfer(zone)
|
183
183
|
if zoneref==nil
|
184
184
|
raise RuntimeError, "couldn't transfer zone\n"
|
185
185
|
end
|
186
186
|
Marshal.dump(zoneref, File.open(zonefile, File::CREAT|File::RDWR))
|
187
187
|
end
|
188
|
-
|
189
|
-
|
190
|
-
#
|
191
|
-
|
192
|
-
|
193
|
-
if (!opt_q)
|
188
|
+
|
189
|
+
# ------------------------------------------------------------------------------
|
190
|
+
# Print the records in the zone.
|
191
|
+
# ------------------------------------------------------------------------------
|
192
|
+
|
193
|
+
if (!opt_q)
|
194
194
|
zoneref.each do |z|
|
195
195
|
print z.to_s + "\n"
|
196
196
|
end
|
197
|
-
end
|
198
|
-
end
|
197
|
+
end
|
198
|
+
end
|