resolv-macos 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9e831d7024ddf352eba750fea85e451304987d39667630f4201652c3f47d9e42
4
+ data.tar.gz: cea3f0850ba7ec3f87cf013341849c184aa0e6f9dc7ddb97375eefbfea114190
5
+ SHA512:
6
+ metadata.gz: '022980eae5bfa0d5db5f01c03761c4c20063ade99384b83146af2f081bacd7349ca556ab2851c3a0f69907b4ddfc2552da6ff63bb22ee8eea6ad12236f5f8f57'
7
+ data.tar.gz: 193101f901f56699a166f398d0b0f4f044c7670b7dce64269ac15a2e27e8cea4be2294d840ab591d3b07f13f5de93c7832abbab69a610064fffcf60f247c2b83
@@ -0,0 +1,21 @@
1
+ name: test
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ name: build (${{ matrix.ruby }} / ${{ matrix.os }})
8
+ strategy:
9
+ matrix:
10
+ ruby: [ '3.0', '2.7', head ]
11
+ os: [ ubuntu-latest, macos-latest ]
12
+ runs-on: ${{ matrix.os }}
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - name: Set up Ruby
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: ${{ matrix.ruby }}
19
+ bundler-cache: true
20
+ - name: Run test
21
+ run: bundle exec rake spec
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in resolv-macos.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,48 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Max Fierke
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
23
+ This software also contains some code from `resolv`, which is licensed under the
24
+ 2-clause BSD license. This license applies to portions of the `parse_resolv_conf`
25
+ method in `lib/resolv/macos.rb`:
26
+
27
+ Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
28
+
29
+ Redistribution and use in source and binary forms, with or without
30
+ modification, are permitted provided that the following conditions
31
+ are met:
32
+ 1. Redistributions of source code must retain the above copyright
33
+ notice, this list of conditions and the following disclaimer.
34
+ 2. Redistributions in binary form must reproduce the above copyright
35
+ notice, this list of conditions and the following disclaimer in the
36
+ documentation and/or other materials provided with the distribution.
37
+
38
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
39
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
42
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
44
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
46
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
47
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48
+ SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # `resolv-macos`
2
+
3
+ On macOS/darwin, `libresolv` supports multiple resolvers. This allows users, VPN
4
+ clients, etc. to delegate queries for certain domains to other resolvers, in
5
+ addition to the "Super Resolver" specified by `/etc/resolv.conf`. An example of
6
+ this would be using something like `dnsmasq` or `launchdns` to resolve a
7
+ [Special Use Domain (described by RFC 6761)](https://datatracker.ietf.org/doc/html/rfc6761)
8
+ for local development like `*.localhost` or `*.test`
9
+
10
+ This is supported transparently via the `gethostbyname` and `getaddrinfo` C
11
+ calls, but when replacing use of those APIs w/ `Resolv`, these resolutions no
12
+ longer happen automatically.
13
+
14
+ This Gem patches the default behavior of the `Resolv` gem to include these
15
+ additional resolvers in the default set, if they exist. (Using public APIs,
16
+ there's no monkey-patching here.)
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem 'resolv-macos'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ bundle install
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install resolv-macos
33
+
34
+ ## Usage
35
+
36
+ No special usage instructions. The Gem will patch `Resolv` to automatically
37
+ provide support for multiple resolvers on macOS, _a la_ the default behavior for
38
+ `getaddrinfo`. On platforms other than macOS, this gem does nothing.
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
43
+ `rake spec` to run the tests. You can also run `bin/console` for an interactive
44
+ prompt that will allow you to experiment.
45
+
46
+ To install this gem onto your local machine, run `bundle exec rake install`. To
47
+ release a new version, update the version number in `version.rb`, and then run
48
+ `bundle exec rake release`, which will create a git tag for the version, push
49
+ git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/IoraHealth/resolv-macos.
54
+
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "resolv/macos"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ class Resolv
2
+ module Macos
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,69 @@
1
+ require "resolv"
2
+ require "resolv/macos/version"
3
+
4
+ class Resolv
5
+ module Macos
6
+ def self.default_resolvers(resolvers_path='/etc/resolver') # :nodoc:
7
+ resolvers = [Hosts.new, DNS.new]
8
+
9
+ # macOS supports multiple DNS resolvers via additional configs
10
+ # (e.g. local domain resolvers, VPNs, etc.)
11
+ # ref: `man 5 resolver` on macOS/darwin
12
+ Dir.each_child(resolvers_path) do |filename|
13
+ resolver = ::Resolv::Macos.parse_resolv_conf(
14
+ File.join(resolvers_path, filename)
15
+ )
16
+ resolver[:search] = [filename] unless resolver[:search]
17
+ resolvers << ::Resolv::DNS.new(resolver)
18
+ end
19
+
20
+ resolvers
21
+ end
22
+
23
+ # Most of this is directly cribbed from Resolv, but with `port` parsing
24
+ # added
25
+ def self.parse_resolv_conf(filename) # :nodoc:
26
+ nameserver = []
27
+ search = nil
28
+ ndots = 1
29
+ port = ::Resolv::DNS::Port
30
+ File.open(filename, 'rb') {|f|
31
+ f.each {|line|
32
+ line.sub!(/[#;].*/, '')
33
+ keyword, *args = line.split(/\s+/)
34
+ next unless keyword
35
+ case keyword
36
+ when 'nameserver'
37
+ nameserver += args
38
+ when 'domain'
39
+ next if args.empty?
40
+ search = [args[0]]
41
+ when 'search'
42
+ next if args.empty?
43
+ search = args
44
+ when 'options'
45
+ args.each {|arg|
46
+ case arg
47
+ when /\Andots:(\d+)\z/
48
+ ndots = $1.to_i
49
+ end
50
+ }
51
+ when 'port'
52
+ next if args.empty?
53
+ port = args[0].to_i
54
+ end
55
+ }
56
+ }
57
+
58
+ return {
59
+ :nameserver_port => nameserver.to_enum(:each_with_index).map { |ns, i| [ns, port] },
60
+ :search => search,
61
+ :ndots => ndots
62
+ }
63
+ end
64
+ end
65
+ end
66
+
67
+ if /darwin/ =~ RUBY_PLATFORM && Dir.exist?('/etc/resolver')
68
+ Resolv::DefaultResolver.replace_resolvers(Resolv::Macos.default_resolvers)
69
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/resolv/macos/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "resolv-macos"
5
+ spec.version = Resolv::Macos::VERSION
6
+ spec.authors = ["Max Fierke"]
7
+ spec.email = ["max.fierke@iorahealth.com"]
8
+
9
+ spec.summary = %q{macOS multiple resolver support for Resolv}
10
+ spec.description = %q{Adds support for macOS's multiple resolver configs to Resolv's default set of resolvers.}
11
+ spec.homepage = "https://github.com/IoraHealth/resolv-macos"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = spec.homepage
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_dependency "resolv"
28
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resolv-macos
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Max Fierke
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-12-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: resolv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Adds support for macOS's multiple resolver configs to Resolv's default
28
+ set of resolvers.
29
+ email:
30
+ - max.fierke@iorahealth.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".github/workflows/test.yml"
36
+ - ".gitignore"
37
+ - ".rspec"
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - bin/console
43
+ - bin/setup
44
+ - lib/resolv/macos.rb
45
+ - lib/resolv/macos/version.rb
46
+ - resolv-macos.gemspec
47
+ homepage: https://github.com/IoraHealth/resolv-macos
48
+ licenses:
49
+ - MIT
50
+ metadata:
51
+ homepage_uri: https://github.com/IoraHealth/resolv-macos
52
+ source_code_uri: https://github.com/IoraHealth/resolv-macos
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 2.3.0
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.1.6
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: macOS multiple resolver support for Resolv
72
+ test_files: []