|
| 1 | +$NetBSD: patch-ext_win32_lib_win32_resolv.rb,v 1.1.2.2 2025/07/17 02:45:42 maya Exp $ |
| 2 | + |
| 3 | +Update resolv gem to 0.6.2. |
| 4 | + |
| 5 | +--- ext/win32/lib/win32/resolv.rb.orig 2025-05-14 03:11:06.000000000 +0000 |
| 6 | ++++ ext/win32/lib/win32/resolv.rb |
| 7 | +@@ -4,13 +4,8 @@ |
| 8 | + |
| 9 | + =end |
| 10 | + |
| 11 | +-require 'win32/registry' |
| 12 | +- |
| 13 | + module Win32 |
| 14 | + module Resolv |
| 15 | +- API = Registry::API |
| 16 | +- Error = Registry::Error |
| 17 | +- |
| 18 | + def self.get_hosts_path |
| 19 | + path = get_hosts_dir |
| 20 | + path = File.expand_path('hosts', path) |
| 21 | +@@ -47,89 +42,103 @@ module Win32 |
| 22 | + # Windows NT |
| 23 | + #==================================================================== |
| 24 | + module Resolv |
| 25 | +- module SZ |
| 26 | +- refine Registry do |
| 27 | +- # ad hoc workaround for broken registry |
| 28 | +- def read_s(key) |
| 29 | +- type, str = read(key) |
| 30 | +- unless type == Registry::REG_SZ |
| 31 | +- warn "Broken registry, #{name}\\#{key} was #{Registry.type2name(type)}, ignored" |
| 32 | +- return String.new |
| 33 | ++ begin |
| 34 | ++ require 'win32/registry' |
| 35 | ++ module SZ |
| 36 | ++ refine Registry do |
| 37 | ++ # ad hoc workaround for broken registry |
| 38 | ++ def read_s(key) |
| 39 | ++ type, str = read(key) |
| 40 | ++ unless type == Registry::REG_SZ |
| 41 | ++ warn "Broken registry, #{name}\\#{key} was #{Registry.type2name(type)}, ignored" |
| 42 | ++ return String.new |
| 43 | ++ end |
| 44 | ++ str |
| 45 | + end |
| 46 | +- str |
| 47 | + end |
| 48 | + end |
| 49 | ++ using SZ |
| 50 | ++ rescue LoadError |
| 51 | ++ require "open3" |
| 52 | + end |
| 53 | +- using SZ |
| 54 | + |
| 55 | + TCPIP_NT = 'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters' |
| 56 | + |
| 57 | + class << self |
| 58 | + private |
| 59 | + def get_hosts_dir |
| 60 | +- Registry::HKEY_LOCAL_MACHINE.open(TCPIP_NT) do |reg| |
| 61 | +- reg.read_s_expand('DataBasePath') |
| 62 | +- end |
| 63 | ++ get_item_property(TCPIP_NT, 'DataBasePath', expand: true) |
| 64 | + end |
| 65 | + |
| 66 | + def get_info |
| 67 | + search = nil |
| 68 | + nameserver = get_dns_server_list |
| 69 | +- Registry::HKEY_LOCAL_MACHINE.open(TCPIP_NT) do |reg| |
| 70 | +- begin |
| 71 | +- slist = reg.read_s('SearchList') |
| 72 | +- search = slist.split(/,\s*/) unless slist.empty? |
| 73 | +- rescue Registry::Error |
| 74 | +- end |
| 75 | + |
| 76 | +- if add_search = search.nil? |
| 77 | +- search = [] |
| 78 | +- begin |
| 79 | +- nvdom = reg.read_s('NV Domain') |
| 80 | +- unless nvdom.empty? |
| 81 | +- @search = [ nvdom ] |
| 82 | +- if reg.read_i('UseDomainNameDevolution') != 0 |
| 83 | +- if /^\w+\./ =~ nvdom |
| 84 | +- devo = $' |
| 85 | +- end |
| 86 | +- end |
| 87 | ++ slist = get_item_property(TCPIP_NT, 'SearchList') |
| 88 | ++ search = slist.split(/,\s*/) unless slist.empty? |
| 89 | ++ |
| 90 | ++ if add_search = search.nil? |
| 91 | ++ search = [] |
| 92 | ++ nvdom = get_item_property(TCPIP_NT, 'NV Domain') |
| 93 | ++ |
| 94 | ++ unless nvdom.empty? |
| 95 | ++ @search = [ nvdom ] |
| 96 | ++ udmnd = get_item_property(TCPIP_NT, 'UseDomainNameDevolution').to_i |
| 97 | ++ if udmnd != 0 |
| 98 | ++ if /^\w+\./ =~ nvdom |
| 99 | ++ devo = $' |
| 100 | + end |
| 101 | +- rescue Registry::Error |
| 102 | + end |
| 103 | + end |
| 104 | ++ end |
| 105 | + |
| 106 | +- reg.open('Interfaces') do |h| |
| 107 | +- h.each_key do |iface, | |
| 108 | +- h.open(iface) do |regif| |
| 109 | +- next unless ns = %w[NameServer DhcpNameServer].find do |key| |
| 110 | +- begin |
| 111 | +- ns = regif.read_s(key) |
| 112 | +- rescue Registry::Error |
| 113 | +- else |
| 114 | +- break ns.split(/[,\s]\s*/) unless ns.empty? |
| 115 | +- end |
| 116 | ++ ifs = if defined?(Win32::Registry) |
| 117 | ++ Registry::HKEY_LOCAL_MACHINE.open(TCPIP_NT + '\Interfaces') do |reg| |
| 118 | ++ reg.keys |
| 119 | ++ rescue Registry::Error |
| 120 | ++ [] |
| 121 | + end |
| 122 | +- next if (nameserver & ns).empty? |
| 123 | ++ else |
| 124 | ++ cmd = "Get-ChildItem 'HKLM:\\#{TCPIP_NT}\\Interfaces' | ForEach-Object { $_.PSChildName }" |
| 125 | ++ output, _ = Open3.capture2('powershell', '-Command', cmd) |
| 126 | ++ output.split(/\n+/) |
| 127 | ++ end |
| 128 | + |
| 129 | +- if add_search |
| 130 | +- begin |
| 131 | +- [ 'Domain', 'DhcpDomain' ].each do |key| |
| 132 | +- dom = regif.read_s(key) |
| 133 | +- unless dom.empty? |
| 134 | +- search.concat(dom.split(/,\s*/)) |
| 135 | +- break |
| 136 | +- end |
| 137 | +- end |
| 138 | +- rescue Registry::Error |
| 139 | +- end |
| 140 | +- end |
| 141 | ++ ifs.each do |iface| |
| 142 | ++ next unless ns = %w[NameServer DhcpNameServer].find do |key| |
| 143 | ++ ns = get_item_property(TCPIP_NT + '\Interfaces' + "\\#{iface}", key) |
| 144 | ++ break ns.split(/[,\s]\s*/) unless ns.empty? |
| 145 | ++ end |
| 146 | ++ |
| 147 | ++ next if (nameserver & ns).empty? |
| 148 | ++ |
| 149 | ++ if add_search |
| 150 | ++ [ 'Domain', 'DhcpDomain' ].each do |key| |
| 151 | ++ dom = get_item_property(TCPIP_NT + '\Interfaces' + "\\#{iface}", key) |
| 152 | ++ unless dom.empty? |
| 153 | ++ search.concat(dom.split(/,\s*/)) |
| 154 | ++ break |
| 155 | + end |
| 156 | + end |
| 157 | + end |
| 158 | +- search << devo if add_search and devo |
| 159 | + end |
| 160 | ++ search << devo if add_search and devo |
| 161 | + [ search.uniq, nameserver.uniq ] |
| 162 | + end |
| 163 | ++ |
| 164 | ++ def get_item_property(path, name, expand: false) |
| 165 | ++ if defined?(Win32::Registry) |
| 166 | ++ Registry::HKEY_LOCAL_MACHINE.open(path) do |reg| |
| 167 | ++ expand ? reg.read_s_expand(name) : reg.read_s(name) |
| 168 | ++ rescue Registry::Error |
| 169 | ++ "" |
| 170 | ++ end |
| 171 | ++ else |
| 172 | ++ cmd = "Get-ItemProperty -Path 'HKLM:\\#{path}' -Name '#{name}' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty '#{name}'" |
| 173 | ++ output, _ = Open3.capture2('powershell', '-Command', cmd) |
| 174 | ++ output.strip |
| 175 | ++ end |
| 176 | ++ end |
| 177 | + end |
| 178 | + end |
| 179 | + end |
0 commit comments