resolv 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9229d4fa9f694c44c4442d65a94ee9cf0a0516cd642c34046ea1986eb3f14e47
4
- data.tar.gz: 8d04dbe4055ac5ab5da6a71fad40235914b7931c4ef5245599f3b1cc4075c19a
3
+ metadata.gz: f0831b1c59e6ce967c8d36a7a5ddc962985c81ace17de45165dd7fb420398725
4
+ data.tar.gz: fab3f3c3175d01df8e15383cd83e0b4526e35e21da55fa373bc62419555c66f4
5
5
  SHA512:
6
- metadata.gz: 946a361ded12633ea767ffeb339c28b93bbb29efaaab1c1d6a26b30d151dea6bb10a8246f6b9fa21233f6fb6e0437e4e6a1fbab662bfe74443d24a1b3bffa0ca
7
- data.tar.gz: 64da659522efac0f4cb19fa34c3824e86efa966c8424a90cba358b82a94738186ce51cc3c70d7d5d1a92e0212dc8b7eb6267df1603387457ab38355eec84ee8e
6
+ metadata.gz: cd0445cd68e2cf4cab80734796084377eb151969df16b29a86865602604852c0830ce7cdb28bbaac8aa7f2ce3abb6c55d1fee8145799965aa385b5b522fdbbf6
7
+ data.tar.gz: 4ea52516c3cad7419b6234c6aac594894f7a723fa1e9dacffeb3ccc6d935811a7a27ecbf5db898a467cc4a19acf67866cbe0a17270dd30b830eb28bd6d3820a2
@@ -23,24 +23,24 @@ jobs:
23
23
 
24
24
  steps:
25
25
  - name: Harden Runner
26
- uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
26
+ uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1
27
27
  with:
28
28
  egress-policy: audit
29
29
 
30
- - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
30
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
31
31
 
32
32
  - name: Set up Ruby
33
- uses: ruby/setup-ruby@a6e6f86333f0a2523ece813039b8b4be04560854 # v1.190.0
33
+ uses: ruby/setup-ruby@a4effe49ee8ee5b8b5091268c473a4628afb5651 # v1.245.0
34
34
  with:
35
35
  bundler-cache: true
36
36
  ruby-version: ruby
37
37
 
38
38
  - name: Publish to RubyGems
39
- uses: rubygems/release-gem@9e85cb11501bebc2ae661c1500176316d3987059 # v1.1.0
39
+ uses: rubygems/release-gem@a25424ba2ba8b387abc8ef40807c2c85b96cbe32 # v1.1.1
40
40
 
41
41
  - name: Create GitHub release
42
42
  run: |
43
43
  tag_name="$(git describe --tags --abbrev=0)"
44
44
  gh release create "${tag_name}" --verify-tag --generate-notes
45
45
  env:
46
- GITHUB_TOKEN: ${{ secrets.MATZBOT_GITHUB_WORKFLOW_TOKEN }}
46
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ /.build/
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /_yardoc/
data/README.md CHANGED
@@ -14,15 +14,18 @@ gem 'resolv'
14
14
 
15
15
  And then execute:
16
16
 
17
- $ bundle install
17
+ ```bash
18
+ bundle install
19
+ ```
18
20
 
19
21
  Or install it yourself as:
20
22
 
21
- $ gem install resolv
23
+ ```bash
24
+ gem install resolv
25
+ ```
22
26
 
23
27
  ## Usage
24
28
 
25
-
26
29
  ```ruby
27
30
  p Resolv.getaddress "www.ruby-lang.org"
28
31
  p Resolv.getname "210.251.121.214"
@@ -44,4 +47,3 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
44
47
  ## Contributing
45
48
 
46
49
  Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/resolv.
47
-
@@ -4,13 +4,8 @@
4
4
 
5
5
  =end
6
6
 
7
- require 'win32/registry'
8
-
9
7
  module Win32
10
8
  module Resolv
11
- API = Registry::API
12
- Error = Registry::Error
13
-
14
9
  def self.get_hosts_path
15
10
  path = get_hosts_dir
16
11
  path = File.expand_path('hosts', path)
@@ -47,89 +42,103 @@ module Win32
47
42
  # Windows NT
48
43
  #====================================================================
49
44
  module Resolv
50
- module SZ
51
- refine Registry do
52
- # ad hoc workaround for broken registry
53
- def read_s(key)
54
- type, str = read(key)
55
- unless type == Registry::REG_SZ
56
- warn "Broken registry, #{name}\\#{key} was #{Registry.type2name(type)}, ignored"
57
- return String.new
45
+ begin
46
+ require 'win32/registry'
47
+ module SZ
48
+ refine Registry do
49
+ # ad hoc workaround for broken registry
50
+ def read_s(key)
51
+ type, str = read(key)
52
+ unless type == Registry::REG_SZ
53
+ warn "Broken registry, #{name}\\#{key} was #{Registry.type2name(type)}, ignored"
54
+ return String.new
55
+ end
56
+ str
58
57
  end
59
- str
60
58
  end
61
59
  end
60
+ using SZ
61
+ rescue LoadError
62
+ require "open3"
62
63
  end
63
- using SZ
64
64
 
65
65
  TCPIP_NT = 'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters'
66
66
 
67
67
  class << self
68
68
  private
69
69
  def get_hosts_dir
70
- Registry::HKEY_LOCAL_MACHINE.open(TCPIP_NT) do |reg|
71
- reg.read_s_expand('DataBasePath')
72
- end
70
+ get_item_property(TCPIP_NT, 'DataBasePath', expand: true)
73
71
  end
74
72
 
75
73
  def get_info
76
74
  search = nil
77
75
  nameserver = get_dns_server_list
78
- Registry::HKEY_LOCAL_MACHINE.open(TCPIP_NT) do |reg|
79
- begin
80
- slist = reg.read_s('SearchList')
81
- search = slist.split(/,\s*/) unless slist.empty?
82
- rescue Registry::Error
83
- end
84
76
 
85
- if add_search = search.nil?
86
- search = []
87
- begin
88
- nvdom = reg.read_s('NV Domain')
89
- unless nvdom.empty?
90
- @search = [ nvdom ]
91
- if reg.read_i('UseDomainNameDevolution') != 0
92
- if /^\w+\./ =~ nvdom
93
- devo = $'
94
- end
95
- end
77
+ slist = get_item_property(TCPIP_NT, 'SearchList')
78
+ search = slist.split(/,\s*/) unless slist.empty?
79
+
80
+ if add_search = search.nil?
81
+ search = []
82
+ nvdom = get_item_property(TCPIP_NT, 'NV Domain')
83
+
84
+ unless nvdom.empty?
85
+ @search = [ nvdom ]
86
+ udmnd = get_item_property(TCPIP_NT, 'UseDomainNameDevolution').to_i
87
+ if udmnd != 0
88
+ if /^\w+\./ =~ nvdom
89
+ devo = $'
96
90
  end
97
- rescue Registry::Error
98
91
  end
99
92
  end
93
+ end
100
94
 
101
- reg.open('Interfaces') do |h|
102
- h.each_key do |iface, |
103
- h.open(iface) do |regif|
104
- next unless ns = %w[NameServer DhcpNameServer].find do |key|
105
- begin
106
- ns = regif.read_s(key)
107
- rescue Registry::Error
108
- else
109
- break ns.split(/[,\s]\s*/) unless ns.empty?
110
- end
111
- end
112
- next if (nameserver & ns).empty?
113
-
114
- if add_search
115
- begin
116
- [ 'Domain', 'DhcpDomain' ].each do |key|
117
- dom = regif.read_s(key)
118
- unless dom.empty?
119
- search.concat(dom.split(/,\s*/))
120
- break
121
- end
122
- end
123
- rescue Registry::Error
124
- end
95
+ ifs = if defined?(Win32::Registry)
96
+ Registry::HKEY_LOCAL_MACHINE.open(TCPIP_NT + '\Interfaces') do |reg|
97
+ reg.keys
98
+ rescue Registry::Error
99
+ []
125
100
  end
101
+ else
102
+ cmd = "Get-ChildItem 'HKLM:\\#{TCPIP_NT}\\Interfaces' | ForEach-Object { $_.PSChildName }"
103
+ output, _ = Open3.capture2('powershell', '-Command', cmd)
104
+ output.split(/\n+/)
105
+ end
106
+
107
+ ifs.each do |iface|
108
+ next unless ns = %w[NameServer DhcpNameServer].find do |key|
109
+ ns = get_item_property(TCPIP_NT + '\Interfaces' + "\\#{iface}", key)
110
+ break ns.split(/[,\s]\s*/) unless ns.empty?
111
+ end
112
+
113
+ next if (nameserver & ns).empty?
114
+
115
+ if add_search
116
+ [ 'Domain', 'DhcpDomain' ].each do |key|
117
+ dom = get_item_property(TCPIP_NT + '\Interfaces' + "\\#{iface}", key)
118
+ unless dom.empty?
119
+ search.concat(dom.split(/,\s*/))
120
+ break
126
121
  end
127
122
  end
128
123
  end
129
- search << devo if add_search and devo
130
124
  end
125
+ search << devo if add_search and devo
131
126
  [ search.uniq, nameserver.uniq ]
132
127
  end
128
+
129
+ def get_item_property(path, name, expand: false)
130
+ if defined?(Win32::Registry)
131
+ Registry::HKEY_LOCAL_MACHINE.open(path) do |reg|
132
+ expand ? reg.read_s_expand(name) : reg.read_s(name)
133
+ rescue Registry::Error
134
+ ""
135
+ end
136
+ else
137
+ cmd = "Get-ItemProperty -Path 'HKLM:\\#{path}' -Name '#{name}' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty '#{name}'"
138
+ output, _ = Open3.capture2('powershell', '-Command', cmd)
139
+ output.strip
140
+ end
141
+ end
133
142
  end
134
143
  end
135
144
  end
@@ -13,6 +13,8 @@ w32error_make_error(DWORD e)
13
13
  return rb_class_new_instance(1, &code, rb_path2class("Win32::Resolv::Error"));
14
14
  }
15
15
 
16
+ NORETURN(static void w32error_raise(DWORD e));
17
+
16
18
  static void
17
19
  w32error_raise(DWORD e)
18
20
  {
data/lib/resolv.rb CHANGED
@@ -33,7 +33,7 @@ require 'securerandom'
33
33
 
34
34
  class Resolv
35
35
 
36
- VERSION = "0.6.0"
36
+ VERSION = "0.6.1"
37
37
 
38
38
  ##
39
39
  # Looks up the first IP address for +name+.
@@ -173,13 +173,16 @@ class Resolv
173
173
 
174
174
  class ResolvTimeout < Timeout::Error; end
175
175
 
176
+ WINDOWS = /mswin|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM || ::RbConfig::CONFIG['host_os'] =~ /mswin/
177
+ private_constant :WINDOWS
178
+
176
179
  ##
177
180
  # Resolv::Hosts is a hostname resolver that uses the system hosts file.
178
181
 
179
182
  class Hosts
180
- if /mswin|mingw|cygwin/ =~ RUBY_PLATFORM and
183
+ if WINDOWS
181
184
  begin
182
- require 'win32/resolv'
185
+ require 'win32/resolv' unless defined?(Win32::Resolv)
183
186
  DefaultFileName = Win32::Resolv.get_hosts_path || IO::NULL
184
187
  rescue LoadError
185
188
  end
@@ -659,8 +662,20 @@ class Resolv
659
662
  }
660
663
  end
661
664
 
662
- def self.bind_random_port(udpsock, bind_host="0.0.0.0") # :nodoc:
663
- begin
665
+ case RUBY_PLATFORM
666
+ when *[
667
+ # https://www.rfc-editor.org/rfc/rfc6056.txt
668
+ # Appendix A. Survey of the Algorithms in Use by Some Popular Implementations
669
+ /freebsd/, /linux/, /netbsd/, /openbsd/, /solaris/,
670
+ /darwin/, # the same as FreeBSD
671
+ ] then
672
+ def self.bind_random_port(udpsock, bind_host="0.0.0.0") # :nodoc:
673
+ udpsock.bind(bind_host, 0)
674
+ end
675
+ else
676
+ # Sequential port assignment
677
+ def self.bind_random_port(udpsock, bind_host="0.0.0.0") # :nodoc:
678
+ # Ephemeral port number range recommended by RFC 6056
664
679
  port = random(1024..65535)
665
680
  udpsock.bind(bind_host, port)
666
681
  rescue Errno::EADDRINUSE, # POSIX
@@ -983,13 +998,13 @@ class Resolv
983
998
  next unless keyword
984
999
  case keyword
985
1000
  when 'nameserver'
986
- nameserver.concat(args)
1001
+ nameserver.concat(args.each(&:freeze))
987
1002
  when 'domain'
988
1003
  next if args.empty?
989
- search = [args[0]]
1004
+ search = [args[0].freeze]
990
1005
  when 'search'
991
1006
  next if args.empty?
992
- search = args
1007
+ search = args.each(&:freeze)
993
1008
  when 'options'
994
1009
  args.each {|arg|
995
1010
  case arg
@@ -1000,22 +1015,22 @@ class Resolv
1000
1015
  end
1001
1016
  }
1002
1017
  }
1003
- return { :nameserver => nameserver, :search => search, :ndots => ndots }
1018
+ return { :nameserver => nameserver.freeze, :search => search.freeze, :ndots => ndots.freeze }.freeze
1004
1019
  end
1005
1020
 
1006
1021
  def Config.default_config_hash(filename="/etc/resolv.conf")
1007
1022
  if File.exist? filename
1008
- config_hash = Config.parse_resolv_conf(filename)
1023
+ Config.parse_resolv_conf(filename)
1024
+ elsif WINDOWS
1025
+ require 'win32/resolv' unless defined?(Win32::Resolv)
1026
+ search, nameserver = Win32::Resolv.get_resolv_info
1027
+ config_hash = {}
1028
+ config_hash[:nameserver] = nameserver if nameserver
1029
+ config_hash[:search] = [search].flatten if search
1030
+ config_hash
1009
1031
  else
1010
- if /mswin|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM
1011
- require 'win32/resolv'
1012
- search, nameserver = Win32::Resolv.get_resolv_info
1013
- config_hash = {}
1014
- config_hash[:nameserver] = nameserver if nameserver
1015
- config_hash[:search] = [search].flatten if search
1016
- end
1032
+ {}
1017
1033
  end
1018
- config_hash || {}
1019
1034
  end
1020
1035
 
1021
1036
  def lazy_initialize
@@ -2110,7 +2125,14 @@ class Resolv
2110
2125
 
2111
2126
  attr_reader :ttl
2112
2127
 
2113
- ClassHash = {} # :nodoc:
2128
+ ClassHash = Module.new do
2129
+ module_function
2130
+
2131
+ def []=(type_class_value, klass)
2132
+ type_value, class_value = type_class_value
2133
+ Resource.const_set(:"Type#{type_value}_Class#{class_value}", klass)
2134
+ end
2135
+ end
2114
2136
 
2115
2137
  def encode_rdata(msg) # :nodoc:
2116
2138
  raise NotImplementedError.new
@@ -2148,7 +2170,9 @@ class Resolv
2148
2170
  end
2149
2171
 
2150
2172
  def self.get_class(type_value, class_value) # :nodoc:
2151
- return ClassHash[[type_value, class_value]] ||
2173
+ cache = :"Type#{type_value}_Class#{class_value}"
2174
+
2175
+ return (const_defined?(cache) && const_get(cache)) ||
2152
2176
  Generic.create(type_value, class_value)
2153
2177
  end
2154
2178
 
@@ -2577,7 +2601,7 @@ class Resolv
2577
2601
  end
2578
2602
 
2579
2603
  ##
2580
- # Flags for this proprty:
2604
+ # Flags for this property:
2581
2605
  # - Bit 0 : 0 = not critical, 1 = critical
2582
2606
 
2583
2607
  attr_reader :flags
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resolv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tanaka Akira
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-12-13 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: Thread-aware DNS resolver library in Ruby.
14
13
  email:
@@ -42,7 +41,6 @@ licenses:
42
41
  metadata:
43
42
  homepage_uri: https://github.com/ruby/resolv
44
43
  source_code_uri: https://github.com/ruby/resolv
45
- post_install_message:
46
44
  rdoc_options: []
47
45
  require_paths:
48
46
  - lib
@@ -57,8 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
55
  - !ruby/object:Gem::Version
58
56
  version: '0'
59
57
  requirements: []
60
- rubygems_version: 3.5.11
61
- signing_key:
58
+ rubygems_version: 3.6.7
62
59
  specification_version: 4
63
60
  summary: Thread-aware DNS resolver library in Ruby.
64
61
  test_files: []