Resolve and iterate over SRV DNS records correctly.
- Homepage :: https://github.com/javanthropus/resolv-srv
- Source :: https://github.com/javanthropus/resolv-srv.git
This gem patches the Resolv::DNS class in stdlib to include a method to resolve and iterate over SRV records according to their relative priorities and weights.
- Iterate over SRV resources in order by priority and randomly in proportion to weight.
- None so far...
Look up your user information in Active Directory (assumes /etc/ssl/certs
contains the internal CA certificate for the domain and that net-ldap v0.12.0 or
greater is used):
#!/usr/bin/env ruby
require 'net/ldap'
require 'pp'
require 'resolv-srv'
class LDAPServerList
include Enumerable
def initialize(domain)
@domain = domain
end
def each
Resolv::DNS.open do |dns|
dns.each_srv_resource('ldap', 'tcp', @domain) do |srv|
yield(srv.target.to_s, srv.port)
end
end
end
end
def search_ldap(domain, username, password, search_args = {})
base = domain.split('.').map { |n| "dc=#{n}" }.join(',')
Net::LDAP.open(
hosts: LDAPServerList.new(domain),
base: base,
auth: {
method: :simple,
username: username,
password: password,
},
encryption: {
method: :start_tls,
tls_options: { ca_path: '/etc/ssl/certs' }
},
) do |ldap|
return ldap.search(search_args)
end
end
print 'AD Domain: '
domain = gets.chomp
print 'AD Username: '
username = gets.chomp
print "AD Password (#{username}): "
password = ($stdin.tty? ? $stdin.noecho(&:gets) : $stdin.gets).chomp
puts
pp search_ldap(
domain,
"#{username}@#{domain}",
password,
filter: "sAMAccountName=#{username}"
)
None
Contributions for bug fixes, documentation, extensions, tests, etc. are encouraged.
- Clone the repository.
- Fix a bug or add a feature.
- Add tests for the fix or feature.
- Make a pull request.
After checking out the source, run:
$ bundle install
$ bundle exec rake test yard
This will install all dependencies, run the tests/specs, and generate the documentation.
Thanks to all contributors. Without your help this project would not exist.
- Jeremy Bopp :: [email protected]
(The MIT License)
Copyright (c) 2015 Jeremy Bopp
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.