faildns 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/bin/failnamed +203 -0
  2. data/bin/failresolve +37 -0
  3. data/lib/faildns.rb +20 -0
  4. data/lib/faildns/class.rb +96 -0
  5. data/lib/faildns/client.rb +114 -0
  6. data/lib/faildns/common.rb +52 -0
  7. data/lib/faildns/domainname.rb +223 -0
  8. data/lib/faildns/header.rb +254 -0
  9. data/lib/faildns/header/opcode.rb +95 -0
  10. data/lib/faildns/header/status.rb +123 -0
  11. data/lib/faildns/header/type.rb +72 -0
  12. data/lib/faildns/ip.rb +57 -0
  13. data/lib/faildns/message.rb +100 -0
  14. data/lib/faildns/qclass.rb +51 -0
  15. data/lib/faildns/qtype.rb +60 -0
  16. data/lib/faildns/question.rb +101 -0
  17. data/lib/faildns/resourcerecord.rb +140 -0
  18. data/lib/faildns/resourcerecord/IN.rb +29 -0
  19. data/lib/faildns/resourcerecord/IN/A.rb +75 -0
  20. data/lib/faildns/resourcerecord/IN/AAAA.rb +77 -0
  21. data/lib/faildns/resourcerecord/IN/CNAME.rb +70 -0
  22. data/lib/faildns/resourcerecord/IN/HINFO.rb +79 -0
  23. data/lib/faildns/resourcerecord/IN/MX.rb +75 -0
  24. data/lib/faildns/resourcerecord/IN/NS.rb +77 -0
  25. data/lib/faildns/resourcerecord/IN/NULL.rb +66 -0
  26. data/lib/faildns/resourcerecord/IN/PTR.rb +69 -0
  27. data/lib/faildns/resourcerecord/IN/SOA.rb +128 -0
  28. data/lib/faildns/resourcerecord/IN/TXT.rb +63 -0
  29. data/lib/faildns/resourcerecord/data.rb +41 -0
  30. data/lib/faildns/server.rb +71 -0
  31. data/lib/faildns/server/dispatcher.rb +181 -0
  32. data/lib/faildns/server/dispatcher/connectiondispatcher.rb +93 -0
  33. data/lib/faildns/server/dispatcher/event.rb +47 -0
  34. data/lib/faildns/server/dispatcher/eventdispatcher.rb +73 -0
  35. data/lib/faildns/server/dispatcher/socket.rb +93 -0
  36. data/lib/faildns/type.rb +186 -0
  37. metadata +100 -0
@@ -0,0 +1,77 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org]
3
+ #
4
+ # This file is part of faildns.
5
+ #
6
+ # faildns is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # faildns is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with faildns. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ require 'faildns/resourcerecord/data'
21
+ require 'faildns/ip'
22
+
23
+ module DNS
24
+
25
+ class ResourceRecord
26
+
27
+ module IN
28
+
29
+ #--
30
+ # +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
31
+ # | ADDRESS |
32
+ # +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
33
+ #
34
+ # where:
35
+ #
36
+ # ADDRESS A 128 bit Internet address.
37
+ #
38
+ # Hosts that have multiple Internet addresses will have multiple AAAA
39
+ # records.
40
+ #
41
+ # AAAA records cause no additional section processing. The RDATA section of
42
+ # an AAAA line in a master file is an Internet address expressed as a name in
43
+ # the IP6.ARPA domain by a sequence of nibbles separated by dots with the suffix
44
+ # ".IP6.ARPA". The sequence of nibbles is encoded in reverse order, i.e., the
45
+ # low-order nibble is encoded first, followed by the next low-order
46
+ # nibble and so on. Each nibble is represented by a hexadecimal digit.
47
+ #++
48
+
49
+ class AAAA < Data
50
+ def self._parse (string, original)
51
+ AAAA.new(IP.parse(string))
52
+ end
53
+
54
+ def self.length
55
+ 16
56
+ end
57
+
58
+ attr_reader :ip
59
+
60
+ def initialize (what)
61
+ @ip = IP.new(what)
62
+ end
63
+
64
+ def pack
65
+ @ip.pack
66
+ end
67
+
68
+ def to_s
69
+ @ip.to_s
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ end
76
+
77
+ end
@@ -0,0 +1,70 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org]
3
+ #
4
+ # This file is part of faildns.
5
+ #
6
+ # faildns is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # faildns is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with faildns. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ require 'faildns/resourcerecord/data'
21
+
22
+ require 'faildns/domainname'
23
+
24
+ module DNS
25
+
26
+ class ResourceRecord
27
+
28
+ module IN
29
+
30
+ #--
31
+ # +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
32
+ # / CNAME /
33
+ # / /
34
+ # +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
35
+ #
36
+ # where:
37
+ #
38
+ # CNAME A <domain-name> which specifies the canonical or primary
39
+ # name for the owner. The owner name is an alias.
40
+ #
41
+ # CNAME RRs cause no additional section processing, but name servers may
42
+ # choose to restart the query at the canonical name in certain cases. See
43
+ # the description of name server logic in [RFC-1034] for details.
44
+ #++
45
+
46
+ class CNAME < Data
47
+ def self._parse (string, original)
48
+ CNAME.new(DomainName.parse(string.clone, original))
49
+ end
50
+
51
+ attr_reader :domain
52
+
53
+ def initialize (domain)
54
+ @domain = domain
55
+ end
56
+
57
+ def pack
58
+ @domain.pack
59
+ end
60
+
61
+ def to_s
62
+ @domain.to_s
63
+ end
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+
70
+ end
@@ -0,0 +1,79 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org]
3
+ #
4
+ # This file is part of faildns.
5
+ #
6
+ # faildns is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # faildns is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with faildns. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ require 'faildns/resourcerecord/data'
21
+
22
+ module DNS
23
+
24
+ class ResourceRecord
25
+
26
+ module IN
27
+
28
+ #--
29
+ # +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
30
+ # / CPU /
31
+ # +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
32
+ # / OS /
33
+ # +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
34
+ #
35
+ # where:
36
+ #
37
+ # CPU A <character-string> which specifies the CPU type.
38
+ #
39
+ # OS A <character-string> which specifies the operating
40
+ # system type.
41
+ #
42
+ # Standard values for CPU and OS can be found in [RFC-1010].
43
+ #
44
+ # HINFO records are used to acquire general information about a host. The
45
+ # main use is for protocols such as FTP that can use special procedures
46
+ # when talking between machines or operating systems of the same type.
47
+ #++
48
+
49
+ class HINFO < Data
50
+ def self._parse (string, original)
51
+ string = string.clone
52
+
53
+ cpu = string[1, (tmp = string.unpack('C'))]; string[0, tmp + 1] = ''
54
+ os = string[1, string.unpack('C')]
55
+
56
+ HINFO.new(cpu, os)
57
+ end
58
+
59
+ attr_reader :cpu, :os
60
+
61
+ def initialize (cpu, os)
62
+ @cpu = cpu
63
+ @os = os
64
+ end
65
+
66
+ def pack
67
+ [@cpu.length].unpack('C') + @cpu + [@os.length].unpack('C') + @os
68
+ end
69
+
70
+ def to_s
71
+ "#{@os} on #{@cpu}"
72
+ end
73
+ end
74
+
75
+ end
76
+
77
+ end
78
+
79
+ end
@@ -0,0 +1,75 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org]
3
+ #
4
+ # This file is part of faildns.
5
+ #
6
+ # faildns is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # faildns is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with faildns. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ require 'faildns/resourcerecord/data'
21
+
22
+ module DNS
23
+
24
+ class ResourceRecord
25
+
26
+ module IN
27
+
28
+ #--
29
+ # +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
30
+ # | PREFERENCE |
31
+ # +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
32
+ # / EXCHANGE /
33
+ # / /
34
+ # +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
35
+ #
36
+ # where:
37
+ #
38
+ # PREFERENCE A 16 bit integer which specifies the preference given to
39
+ # this RR among others at the same owner. Lower values
40
+ # are preferred.
41
+ #
42
+ # EXCHANGE A <domain-name> which specifies a host willing to act as
43
+ # a mail exchange for the owner name.
44
+ #
45
+ # MX records cause type A additional section processing for the host
46
+ # specified by EXCHANGE. The use of MX RRs is explained in detail in
47
+ # [RFC-974].
48
+ #++
49
+
50
+ class MX < Data
51
+ def self._parse (string, original)
52
+ MX.new(string.unpack('n'), DomainName.parse(string[2, 255], original))
53
+ end
54
+
55
+ attr_reader :preference, :exchange
56
+
57
+ def initialize (preference, exchange)
58
+ @preference = preference
59
+ @exchange = exchange
60
+ end
61
+
62
+ def pack
63
+ [@preference].pack('n') + @exchange.pack
64
+ end
65
+
66
+ def to_s
67
+ "#{@preference}) #{@exchange}"
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+
75
+ end
@@ -0,0 +1,77 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org]
3
+ #
4
+ # This file is part of faildns.
5
+ #
6
+ # faildns is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # faildns is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with faildns. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ require 'faildns/resourcerecord/data'
21
+
22
+ require 'faildns/domainname'
23
+
24
+ module DNS
25
+
26
+ class ResourceRecord
27
+
28
+ module IN
29
+
30
+ #--
31
+ # +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
32
+ # / NSDNAME /
33
+ # / /
34
+ # +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
35
+ #
36
+ # where:
37
+ #
38
+ # NSDNAME A <domain-name> which specifies a host which should be
39
+ # authoritative for the specified class and domain.
40
+ #
41
+ # NS records cause both the usual additional section processing to locate
42
+ # a type A record, and, when used in a referral, a special search of the
43
+ # zone in which they reside for glue information.
44
+ #
45
+ # The NS RR states that the named host should be expected to have a zone
46
+ # starting at owner name of the specified class. Note that the class may
47
+ # not indicate the protocol family which should be used to communicate
48
+ # with the host, although it is typically a strong hint. For example,
49
+ # hosts which are name servers for either Internet (IN) or Hesiod (HS)
50
+ # class information are normally queried using IN class protocols.
51
+ #++
52
+
53
+ class NS < Data
54
+ def self._parse (string, original)
55
+ NS.new(DomainName.parse(string.clone, original))
56
+ end
57
+
58
+ attr_reader :domain
59
+
60
+ def initialize (domain)
61
+ @domain = domain
62
+ end
63
+
64
+ def pack
65
+ @domain.pack
66
+ end
67
+
68
+ def to_s
69
+ @domain.to_s
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ end
76
+
77
+ end
@@ -0,0 +1,66 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org]
3
+ #
4
+ # This file is part of faildns.
5
+ #
6
+ # faildns is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # faildns is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with faildns. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ require 'faildns/resourcerecord/data'
21
+
22
+ module DNS
23
+
24
+ class ResourceRecord
25
+
26
+ module IN
27
+
28
+ #--
29
+ # +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
30
+ # / <anything> /
31
+ # / /
32
+ # +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
33
+ #
34
+ # Anything at all may be in the RDATA field so long as it is 65535 octets
35
+ # or less.
36
+ #
37
+ # NULL records cause no additional section processing. NULL RRs are not
38
+ # allowed in master files. NULLs are used as placeholders in some
39
+ # experimental extensions of the DNS.
40
+ #++
41
+
42
+ class NULL < Data
43
+ def self._parse (string, original)
44
+ NULL.new(string)
45
+ end
46
+
47
+ attr_reader :raw
48
+
49
+ def initialize (raw)
50
+ @raw = raw
51
+ end
52
+
53
+ def pack
54
+ @raw
55
+ end
56
+
57
+ def to_s
58
+ @raw
59
+ end
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+
66
+ end